Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix destructuring with holes in assign pattern (#14240)
- Loading branch information
1 parent
e06c099
commit 6b4d466
Showing
5 changed files
with
151 additions
and
1 deletion.
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
45 changes: 45 additions & 0 deletions
45
packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/init-hole/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,45 @@ | ||
let [x = 23] = [,]; | ||
expect(x).toEqual(23); | ||
|
||
const [y = 24, z] = [, 42]; | ||
expect(y).toEqual(24); | ||
expect(z).toEqual(42); | ||
|
||
function* foo() { | ||
yield 1; | ||
yield 2; | ||
} | ||
|
||
let bar = foo(); | ||
|
||
const [a = bar.next().value, b] = [, bar.next().value]; | ||
|
||
expect(a).toEqual(2); | ||
expect(b).toEqual(1); | ||
|
||
const arr = [c = 42] = [,]; | ||
expect(c).toEqual(42); | ||
expect(arr).toEqual([,]); | ||
|
||
var iterCount = 0; | ||
|
||
for (const [x = 23] = [,]; iterCount < 1; ) { | ||
expect(x).toEqual(23); | ||
// another statement | ||
|
||
iterCount += 1; | ||
} | ||
|
||
expect(iterCount).toEqual(1); | ||
|
||
const [...d] = [,]; | ||
const [...{ 0: e }] = [,]; | ||
|
||
expect(d).toEqual([,]); | ||
expect(e).toEqual(undefined); | ||
|
||
const [f] = [,]; | ||
expect(f).toEqual(undefined); | ||
|
||
let [g] = [,]; | ||
expect(g).toEqual(undefined); |
45 changes: 45 additions & 0 deletions
45
packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/init-hole/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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
let [x = 23] = [,]; | ||
expect(x).toEqual(23); | ||
|
||
const [y = 24, z] = [, 42]; | ||
expect(y).toEqual(24); | ||
expect(z).toEqual(42); | ||
|
||
function* foo() { | ||
yield 1; | ||
yield 2; | ||
} | ||
|
||
let bar = foo(); | ||
|
||
const [a = bar.next().value, b] = [, bar.next().value]; | ||
|
||
expect(a).toEqual(2); | ||
expect(b).toEqual(1); | ||
|
||
const arr = [c = 42] = [,]; | ||
expect(c).toEqual(42); | ||
expect(arr).toEqual([,]); | ||
|
||
var iterCount = 0; | ||
|
||
for (const [x = 23] = [,]; iterCount < 1; ) { | ||
expect(x).toEqual(23); | ||
// another statement | ||
|
||
iterCount += 1; | ||
} | ||
|
||
expect(iterCount).toEqual(1); | ||
|
||
const [...d] = [,]; | ||
const [...{ 0: e }] = [,]; | ||
|
||
expect(d).toEqual([,]); | ||
expect(e).toEqual(undefined); | ||
|
||
const [f] = [,]; | ||
expect(f).toEqual(undefined); | ||
|
||
let [g] = [,]; | ||
expect(g).toEqual(undefined); |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-transform-destructuring/test/fixtures/destructuring/init-hole/options.json
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,3 @@ | ||
{ | ||
"plugins": ["transform-destructuring"] | ||
} |
41 changes: 41 additions & 0 deletions
41
...ages/babel-plugin-transform-destructuring/test/fixtures/destructuring/init-hole/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,41 @@ | ||
var _ref2, _ref2$; | ||
|
||
let x = 23; | ||
expect(x).toEqual(23); | ||
const y = 24, | ||
z = 42; | ||
expect(y).toEqual(24); | ||
expect(z).toEqual(42); | ||
|
||
function* foo() { | ||
yield 1; | ||
yield 2; | ||
} | ||
|
||
let bar = foo(); | ||
const _ref = [, bar.next().value], | ||
_ref$ = _ref[0], | ||
a = _ref$ === void 0 ? bar.next().value : _ref$, | ||
b = _ref[1]; | ||
expect(a).toEqual(2); | ||
expect(b).toEqual(1); | ||
const arr = (_ref2 = [,], _ref2$ = _ref2[0], c = _ref2$ === void 0 ? 42 : _ref2$, _ref2); | ||
expect(c).toEqual(42); | ||
expect(arr).toEqual([,]); | ||
var iterCount = 0; | ||
|
||
for (const x = 23; iterCount < 1;) { | ||
expect(x).toEqual(23); // another statement | ||
|
||
iterCount += 1; | ||
} | ||
|
||
expect(iterCount).toEqual(1); | ||
const d = [,]; | ||
const e = [,][0]; | ||
expect(d).toEqual([,]); | ||
expect(e).toEqual(undefined); | ||
const f = void 0; | ||
expect(f).toEqual(undefined); | ||
let g; | ||
expect(g).toEqual(undefined); |