Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix export bindings not updated by 'for...in' and 'for...of' (#11074)
* Correctly transpile export bindings for some for-of loops * Correctly transform non-destructured for of loops to update exported variables * Add tests * Don't replace entire for of loop * Correctly transform destructured for-of/for-in exports * Update exported variables in array pattern and more fixes * Refresh test output * Update tests and rebase on master * Refactor ForOf|ForIn visitor * Don't transform re-declared exported vars * Generate better name for loop id Co-Authored-By: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> * Idiomatically generate UidIdentifier * Update scope after replacing loop declaration Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
5aa368c
commit dadba01
Showing
3 changed files
with
123 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
...ges/babel-plugin-transform-modules-commonjs/test/fixtures/misc/for-of-in-export/input.mjs
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,22 @@ | ||
export let foo; | ||
export {foo as bar} | ||
|
||
for (foo of []) {} | ||
for (foo in []) {} | ||
for (foo of []) { | ||
let foo; | ||
} | ||
for ({foo} of []) {} | ||
for ({foo} of []) { | ||
let foo; | ||
} | ||
for ({test: {foo}} of []) {} | ||
for ([foo, [...foo]] of []) {} | ||
for ([foo, [...foo]] of []) { | ||
let foo; | ||
} | ||
|
||
{ | ||
let foo; | ||
for(foo of []) {} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ges/babel-plugin-transform-modules-commonjs/test/fixtures/misc/for-of-in-export/output.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,65 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.bar = exports.foo = void 0; | ||
let foo; | ||
exports.bar = exports.foo = foo; | ||
|
||
for (let _foo of []) { | ||
exports.bar = exports.foo = foo = _foo; | ||
} | ||
|
||
for (let _foo2 in []) { | ||
exports.bar = exports.foo = foo = _foo2; | ||
} | ||
|
||
for (let _foo4 of []) { | ||
exports.bar = exports.foo = foo = _foo4; | ||
|
||
let _foo3; | ||
} | ||
|
||
for (let _foo5 of []) { | ||
({ | ||
foo | ||
} = _foo5); | ||
exports.bar = exports.foo = foo; | ||
} | ||
|
||
for (let _foo7 of []) { | ||
({ | ||
foo | ||
} = _foo7); | ||
exports.bar = exports.foo = foo; | ||
|
||
let _foo6; | ||
} | ||
|
||
for (let _test of []) { | ||
({ | ||
test: { | ||
foo | ||
} | ||
} = _test); | ||
exports.bar = exports.foo = foo; | ||
} | ||
|
||
for (let _ref of []) { | ||
[foo, [...foo]] = _ref; | ||
exports.bar = exports.foo = foo; | ||
} | ||
|
||
for (let _ref2 of []) { | ||
[foo, [...foo]] = _ref2; | ||
exports.bar = exports.foo = foo; | ||
|
||
let _foo8; | ||
} | ||
|
||
{ | ||
let foo; | ||
|
||
for (foo of []) {} | ||
} |