Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove bindings defined in blockScope when wrapped in closure
- Loading branch information
Showing
4 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-10339/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const code = multiline([ | ||
"for (const {foo, ...bar} of { bar: [] }) {", | ||
"() => foo;", | ||
"const [qux] = bar;", | ||
"try {} catch (e) {", | ||
"let quux = qux;", | ||
"}", | ||
"}" | ||
]); | ||
|
||
transform(code, { | ||
configFile: false, | ||
plugins: [ | ||
"../../../../lib", | ||
{ | ||
post({ path }) { | ||
path.traverse({ | ||
Program(path) { | ||
expect(Object.keys(path.scope.bindings)).toEqual(["foo", "bar"]); | ||
}, | ||
ForOfStatement(path) { | ||
// for declarations should be transformed to for bindings | ||
expect(path.scope.bindings).toEqual({}); | ||
// The body should be wrapped into closure | ||
expect(path.get("body").scope.bindings).toEqual({}); | ||
}, | ||
FunctionExpression(path) { | ||
expect(Object.keys(path.scope.bindings)).toEqual(["foo", "bar", "qux", "quux"]); | ||
} | ||
}) | ||
} | ||
} | ||
] | ||
}); |
5 changes: 4 additions & 1 deletion
5
packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-10339/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
for (const {foo, ...bar} of {}) { | ||
() => foo; | ||
bar; | ||
const [qux] = bar; | ||
try {} catch (e) { | ||
const quux = qux; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters