Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scope of computed method keys (#12812)
* Fix scope of computed method keys * Test for nested computed keys * Fix scope.rename with computed method keys * Optional chaining tests
- Loading branch information
1 parent
a940c09
commit 792672e
Showing
41 changed files
with
391 additions
and
2 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...abel-plugin-proposal-optional-chaining/test/fixtures/general/in-method-key-loose/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 @@ | ||
let x; | ||
const a = { | ||
[x.y?.z]() {} | ||
}; |
3 changes: 3 additions & 0 deletions
3
...-plugin-proposal-optional-chaining/test/fixtures/general/in-method-key-loose/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": [["proposal-optional-chaining", { "loose": true }]] | ||
} |
7 changes: 7 additions & 0 deletions
7
...bel-plugin-proposal-optional-chaining/test/fixtures/general/in-method-key-loose/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 @@ | ||
var _x$y; | ||
|
||
let x; | ||
const a = { | ||
[(_x$y = x.y) == null ? void 0 : _x$y.z]() {} | ||
|
||
}; |
4 changes: 4 additions & 0 deletions
4
...ages/babel-plugin-proposal-optional-chaining/test/fixtures/general/in-method-key/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 @@ | ||
let x; | ||
const a = { | ||
[x.y?.z]() {} | ||
}; |
7 changes: 7 additions & 0 deletions
7
...ges/babel-plugin-proposal-optional-chaining/test/fixtures/general/in-method-key/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 @@ | ||
var _x$y; | ||
|
||
let x; | ||
const a = { | ||
[(_x$y = x.y) === null || _x$y === void 0 ? void 0 : _x$y.z]() {} | ||
|
||
}; |
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
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-1/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,8 @@ | ||
let a = "outside"; | ||
|
||
const obj = { | ||
[a]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-1/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": ["./plugin"] | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-1/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,8 @@ | ||
let z = "outside"; | ||
const obj = { | ||
[z]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
|
||
}; |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-1/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-2/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,8 @@ | ||
let a = "outside"; | ||
|
||
class C { | ||
[a]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-2/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": ["./plugin"] | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-2/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 @@ | ||
let z = "outside"; | ||
|
||
class C { | ||
[z]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-2/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/babel-traverse/test/fixtures/rename/method-computed-key-3/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 @@ | ||
let a = "outside"; | ||
|
||
const obj = { | ||
[a](a = "inside") { | ||
return a; | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-3/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": ["./plugin"] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/babel-traverse/test/fixtures/rename/method-computed-key-3/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 @@ | ||
let z = "outside"; | ||
const obj = { | ||
[z](a = "inside") { | ||
return a; | ||
} | ||
|
||
}; |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-3/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/babel-traverse/test/fixtures/rename/method-computed-key-4/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 @@ | ||
let a = "outside"; | ||
|
||
class C { | ||
[a](a = "inside") { | ||
return a; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-4/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": ["./plugin"] | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-4/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,8 @@ | ||
let z = "outside"; | ||
|
||
class C { | ||
[z](a = "inside") { | ||
return a; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-4/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-5/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,8 @@ | ||
let a = "outside"; | ||
|
||
const obj = { | ||
[(() => a)()]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-5/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": ["./plugin"] | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-5/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,8 @@ | ||
let z = "outside"; | ||
const obj = { | ||
[(() => z)()]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
|
||
}; |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-5/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/babel-traverse/test/fixtures/rename/method-computed-key-6/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,8 @@ | ||
let a = "outside"; | ||
|
||
class C { | ||
[(() => a)()]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-6/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": ["./plugin"] | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-6/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 @@ | ||
let z = "outside"; | ||
|
||
class C { | ||
[(() => z)()]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-6/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/babel-traverse/test/fixtures/rename/method-computed-key-7/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,15 @@ | ||
let a = "outside"; | ||
|
||
const obj = { | ||
get [ | ||
{ | ||
get [a]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
}.outside | ||
]() { | ||
let a = "middle"; | ||
return a; | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-7/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": ["./plugin"] | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/babel-traverse/test/fixtures/rename/method-computed-key-7/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,14 @@ | ||
let z = "outside"; | ||
const obj = { | ||
get [{ | ||
get [z]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
|
||
}.outside]() { | ||
let a = "middle"; | ||
return a; | ||
} | ||
|
||
}; |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-7/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/babel-traverse/test/fixtures/rename/method-computed-key-8/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,15 @@ | ||
let a = "outside"; | ||
|
||
class C { | ||
static get [ | ||
class D { | ||
static get [a]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
}.outside | ||
]() { | ||
let a = "middle"; | ||
return a; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-traverse/test/fixtures/rename/method-computed-key-8/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": ["./plugin"] | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/babel-traverse/test/fixtures/rename/method-computed-key-8/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,15 @@ | ||
let z = "outside"; | ||
|
||
class C { | ||
static get [class D { | ||
static get [z]() { | ||
let a = "inside"; | ||
return a; | ||
} | ||
|
||
}.outside]() { | ||
let a = "middle"; | ||
return a; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-traverse/test/fixtures/rename/method-computed-key-8/plugin.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 @@ | ||
module.exports = function() { | ||
return { | ||
visitor: { | ||
Program(path) { | ||
path.scope.rename("a", "z"); | ||
} | ||
} | ||
}; | ||
}; |
Oops, something went wrong.