Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tdz checks in transform-block-scoping plugin (#9498)
* Better tdz tests - Use jest's expect.toThrow/expect.not.toThrow - Add input/output tests * Fix basic tdz (a = 2; let a) Fixes #6848 * Make _guessExecutionStatusRelativeTo more robust * Add tests * Return less "unkown" execution status * "function" execution status does not exist * Fix recursive functions * Update helper version * "finally" blocks are always executed * Typo
- Loading branch information
1 parent
9bc9571
commit fced5ce
Showing
65 changed files
with
507 additions
and
122 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
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
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
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
6 changes: 4 additions & 2 deletions
6
...es/babel-plugin-transform-block-scoping/test/fixtures/tdz/block-ref-function-call/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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
f(); | ||
expect(() => { | ||
f(); | ||
|
||
const f = function f() {} | ||
const f = function f() {} | ||
}).toThrow(ReferenceError); |
3 changes: 3 additions & 0 deletions
3
...s/babel-plugin-transform-block-scoping/test/fixtures/tdz/block-ref-function-call/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,3 @@ | ||
f(); | ||
|
||
const f = function f() {} |
3 changes: 0 additions & 3 deletions
3
...bel-plugin-transform-block-scoping/test/fixtures/tdz/block-ref-function-call/options.json
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
.../babel-plugin-transform-block-scoping/test/fixtures/tdz/block-ref-function-call/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,3 @@ | ||
babelHelpers.tdz("f")(); | ||
|
||
var f = function f() {}; |
4 changes: 3 additions & 1 deletion
4
...abel-plugin-transform-block-scoping/test/fixtures/tdz/destructured-self-reference/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 |
---|---|---|
@@ -1 +1,3 @@ | ||
let { b: d } = { d } | ||
expect(() => { | ||
let { b: d } = { d } | ||
}).toThrow(ReferenceError); |
1 change: 1 addition & 0 deletions
1
...bel-plugin-transform-block-scoping/test/fixtures/tdz/destructured-self-reference/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 @@ | ||
let { b: d } = { d } |
3 changes: 0 additions & 3 deletions
3
...plugin-transform-block-scoping/test/fixtures/tdz/destructured-self-reference/options.json
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...el-plugin-transform-block-scoping/test/fixtures/tdz/destructured-self-reference/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,5 @@ | ||
var { | ||
b: d | ||
} = { | ||
d: babelHelpers.tdz("d") | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-after/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,7 @@ | ||
expect(() => { | ||
function f() { | ||
x; | ||
} | ||
let x; | ||
f(); | ||
}).not.toThrow(); |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
...ages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-after/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,6 @@ | ||
function f() { | ||
x; | ||
} | ||
|
||
var x; | ||
f(); |
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-before/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,7 @@ | ||
expect(() => { | ||
function f() { | ||
x; | ||
} | ||
f(); | ||
let x; | ||
}).toThrow(ReferenceError); |
5 changes: 5 additions & 0 deletions
5
...ages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-before/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,5 @@ | ||
function f() { | ||
x; | ||
} | ||
f(); | ||
let x; |
6 changes: 6 additions & 0 deletions
6
...ges/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-before/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,6 @@ | ||
function f() { | ||
babelHelpers.tdz("x"); | ||
} | ||
|
||
f(); | ||
var x; |
6 changes: 6 additions & 0 deletions
6
...l-plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe-real-after/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,6 @@ | ||
expect(() => { | ||
function f() { x } | ||
Math.random() === 2 && f(); | ||
let x; | ||
f(); | ||
}).not.toThrow(); |
4 changes: 4 additions & 0 deletions
4
...-plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe-real-after/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,4 @@ | ||
function f() { x } | ||
Math.random() === 2 && f(); | ||
let x; | ||
f(); |
9 changes: 9 additions & 0 deletions
9
...plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe-real-after/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,9 @@ | ||
var x = babelHelpers.temporalUndefined; | ||
|
||
function f() { | ||
babelHelpers.temporalRef(x, "x"); | ||
} | ||
|
||
Math.random() === 2 && f(); | ||
x = void 0; | ||
f(); |
5 changes: 5 additions & 0 deletions
5
...plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe-value-assign/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,5 @@ | ||
function f() { x } | ||
Math.random() === 2 && f(); | ||
let x = 3; | ||
|
||
expect(x).toBe(3); |
5 changes: 5 additions & 0 deletions
5
...lugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe-value-assign/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,5 @@ | ||
function f() { x } | ||
Math.random() === 2 && f(); | ||
let x = 3; | ||
|
||
expect(x).toBe(3); |
9 changes: 9 additions & 0 deletions
9
...ugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe-value-assign/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,9 @@ | ||
var x = babelHelpers.temporalUndefined; | ||
|
||
function f() { | ||
babelHelpers.temporalRef(x, "x"); | ||
} | ||
|
||
Math.random() === 2 && f(); | ||
x = 3; | ||
expect(x).toBe(3); |
29 changes: 29 additions & 0 deletions
29
packages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe/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,29 @@ | ||
// "random" :) | ||
let random = (i => { | ||
const vals = [0, 0, 1, 1]; | ||
return () => vals[i++]; | ||
})(0); | ||
|
||
expect(() => { | ||
function f() { x } | ||
random() && f(); | ||
let x; | ||
}).not.toThrow(); | ||
|
||
expect(() => { | ||
function f() { x } | ||
random() || f(); | ||
let x; | ||
}).toThrow(ReferenceError); | ||
|
||
expect(() => { | ||
function f() { x } | ||
random() && f(); | ||
let x; | ||
}).toThrow(ReferenceError); | ||
|
||
expect(() => { | ||
function f() { x } | ||
random() || f(); | ||
let x; | ||
}).not.toThrow(); |
3 changes: 3 additions & 0 deletions
3
packages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe/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,3 @@ | ||
function f() { x } | ||
Math.random() && f(); | ||
let x; |
9 changes: 9 additions & 0 deletions
9
...ages/babel-plugin-transform-block-scoping/test/fixtures/tdz/function-call-maybe/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,9 @@ | ||
var x = babelHelpers.temporalUndefined; | ||
|
||
function f() { | ||
babelHelpers.temporalRef(x, "x"); | ||
} | ||
|
||
Math.random() && f(); | ||
x = void 0; | ||
void 0; |
17 changes: 17 additions & 0 deletions
17
...el-plugin-transform-block-scoping/test/fixtures/tdz/function-call-nested-function/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,17 @@ | ||
expect(() => { | ||
function f() { | ||
return function() { x }; | ||
} | ||
let g = f(); | ||
let x; | ||
g(); | ||
}).not.toThrow(); | ||
|
||
expect(() => { | ||
function f() { | ||
return function() { x }; | ||
} | ||
let g = f(); | ||
g(); | ||
let x; | ||
}).toThrow(ReferenceError); |
5 changes: 5 additions & 0 deletions
5
...l-plugin-transform-block-scoping/test/fixtures/tdz/function-call-nested-function/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,5 @@ | ||
function f() { | ||
return function() { x }; | ||
} | ||
f(); | ||
let x; |
11 changes: 11 additions & 0 deletions
11
...-plugin-transform-block-scoping/test/fixtures/tdz/function-call-nested-function/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,11 @@ | ||
var x = babelHelpers.temporalUndefined; | ||
|
||
function f() { | ||
return function () { | ||
babelHelpers.temporalRef(x, "x"); | ||
}; | ||
} | ||
|
||
f(); | ||
x = void 0; | ||
void 0; |
9 changes: 9 additions & 0 deletions
9
...el-plugin-transform-block-scoping/test/fixtures/tdz/function-call-recursive-after/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,9 @@ | ||
expect(() => { | ||
function f(i) { | ||
if (i) f(i - 1); | ||
x; | ||
} | ||
|
||
let x; | ||
f(3); | ||
}).not.toThrow(); |
7 changes: 7 additions & 0 deletions
7
...l-plugin-transform-block-scoping/test/fixtures/tdz/function-call-recursive-after/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,7 @@ | ||
function f(i) { | ||
if (i) f(i - 1); | ||
x; | ||
} | ||
|
||
let x; | ||
f(3); |
7 changes: 7 additions & 0 deletions
7
...-plugin-transform-block-scoping/test/fixtures/tdz/function-call-recursive-after/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,7 @@ | ||
function f(i) { | ||
if (i) f(i - 1); | ||
x; | ||
} | ||
|
||
var x; | ||
f(3); |
Oops, something went wrong.