New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tdz checks in transform-block-scoping plugin #9498
Merged
+507
−122
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
354c9bb
Better tdz tests
nicolo-ribaudo 731ffe9
Fix basic tdz (a = 2; let a)
nicolo-ribaudo 3987597
Make _guessExecutionStatusRelativeTo more robust
nicolo-ribaudo 3e8bf10
Add tests
nicolo-ribaudo 768c7f9
Return less "unkown" execution status
nicolo-ribaudo 056486d
"function" execution status does not exist
nicolo-ribaudo 95bb850
Fix recursive functions
nicolo-ribaudo 8ab5b1b
Update helper version
nicolo-ribaudo 2f1c6d4
"finally" blocks are always executed
nicolo-ribaudo f398d1e
Typo
nicolo-ribaudo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that "inside" and "outside" were swapped? To me "inside" means "inside the temporal dead zone", so "the lexical declaration is after the reference".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looking at the code it seems that "inside" was meant as "inside valid Zone". It is easier to understand for me now after swapping.