Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check shadow variable to identifier in default parameters (#10053)
When there is a variable declaration inside the function body, which shares its name to a referenced identifier in default parameter expression, the function body should be wrapped into iife, otherwise the binding in default parameter scope will be shadowed by function body.
- Loading branch information
1 parent
0b3f883
commit bffa415
Showing
3 changed files
with
24 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
6 changes: 6 additions & 0 deletions
6
...ges/babel-plugin-transform-parameters/test/fixtures/parameters/default-iife-9947/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,6 @@ | ||
let x = "outside"; | ||
function outer(a = () => x) { | ||
let x = "inside"; | ||
return a(); | ||
} | ||
outer(); |
13 changes: 13 additions & 0 deletions
13
...es/babel-plugin-transform-parameters/test/fixtures/parameters/default-iife-9947/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,13 @@ | ||
var x = "outside"; | ||
|
||
function outer() { | ||
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { | ||
return x; | ||
}; | ||
return function () { | ||
var x = "inside"; | ||
return a(); | ||
}(); | ||
} | ||
|
||
outer(); |