From d24f3fdad919cd261b9d7daec985f5c28639674c Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Fri, 3 Mar 2023 17:33:44 +0000 Subject: [PATCH] [test] Add failing test of incorrect typing of captured ref The typer doesn't understand that it needs to ignore captured references ("read" refs are ok, but not "mutated" refs) to be conservative. --- ...capturing-reference-changes-type.expect.md | 31 +++++++++++++++++++ .../_bug.capturing-reference-changes-type.js | 9 ++++++ 2 files changed, 40 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.js diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.expect.md new file mode 100644 index 0000000000..40ca099123 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.expect.md @@ -0,0 +1,31 @@ + +## Input + +```javascript +function component(a) { + let x = { a }; + let y = 1; + (function () { + y = x; + })(); + mutate(y); + return y; +} + +``` + +## Code + +```javascript +function component(a) { + const x = { a: a }; + + (function () { + y = x; + })(); + mutate(1); + return 1; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.js b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.js new file mode 100644 index 0000000000..7c56dde4be --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.capturing-reference-changes-type.js @@ -0,0 +1,9 @@ +function component(a) { + let x = { a }; + let y = 1; + (function () { + y = x; + })(); + mutate(y); + return y; +}