Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parenthesize non-simple decorator expression (#14378)
- Loading branch information
Showing
28 changed files
with
560 additions
and
25 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
6 changes: 5 additions & 1 deletion
6
...generator/test/fixtures/decorators-legacy/ts-class-modifier-with-retainlines/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 |
---|---|---|
@@ -1 +1,5 @@ | ||
{ "plugins": ["classProperties", "decorators-legacy", "typescript"], "decoratorsBeforeExport": true, "retainLines": true } | ||
{ | ||
"plugins": ["decorators-legacy", "typescript"], | ||
"decoratorsBeforeExport": true, | ||
"retainLines": true | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-generator/test/fixtures/decorators/decorator-call-expression/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 @@ | ||
class C { | ||
@dec(0) | ||
@globalThis.dec(0) | ||
@(globalThis["dec"])(0) | ||
p | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-generator/test/fixtures/decorators/decorator-call-expression/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 @@ | ||
class C { | ||
@dec(0) | ||
@globalThis.dec(0) | ||
@(globalThis["dec"](0)) | ||
p; | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-generator/test/fixtures/decorators/decorator-member-expression/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 @@ | ||
class C { | ||
@dec | ||
@globalThis.dec | ||
@globalThis.self.dec | ||
p | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-generator/test/fixtures/decorators/decorator-member-expression/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 @@ | ||
class C { | ||
@dec | ||
@globalThis.dec | ||
@globalThis.self.dec | ||
p; | ||
} |
30 changes: 30 additions & 0 deletions
30
...ures/decorators/decorator-parenthesized-expression-createParenthesizedExpression/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,30 @@ | ||
class C extends class {} { | ||
#x; | ||
constructor() { | ||
class ShouldPreserveParens { | ||
@(decs[0]) | ||
@(decs`1`) | ||
@(this?.two) | ||
@(self.#x) | ||
@(this.dec) | ||
@(super.dec) | ||
@(new DecFactory) | ||
@(decs[three])() | ||
p; | ||
} | ||
|
||
class ShouldNotAddParens { | ||
@decs | ||
@decs.one | ||
@decs.two() | ||
p; | ||
} | ||
|
||
class WillPreserveParens { | ||
@(decs) | ||
@(decs.one) | ||
@(decs.two()) | ||
p; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
.../decorators/decorator-parenthesized-expression-createParenthesizedExpression/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,5 @@ | ||
{ | ||
"plugins": [["decorators", { "decoratorsBeforeExport": false }]], | ||
"decoratorsBeforeExport": true, | ||
"parserOpts": { "createParenthesizedExpressions": true } | ||
} |
32 changes: 32 additions & 0 deletions
32
...res/decorators/decorator-parenthesized-expression-createParenthesizedExpression/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,32 @@ | ||
class C extends class {} { | ||
#x; | ||
|
||
constructor() { | ||
class ShouldPreserveParens { | ||
@(decs[0]) | ||
@(decs`1`) | ||
@(this?.two) | ||
@(self.#x) | ||
@(this.dec) | ||
@(super.dec) | ||
@(new DecFactory()) | ||
@(decs[three])() | ||
p; | ||
} | ||
|
||
class ShouldNotAddParens { | ||
@decs | ||
@decs.one | ||
@decs.two() | ||
p; | ||
} | ||
|
||
class WillPreserveParens { | ||
@(decs) | ||
@(decs.one) | ||
@(decs.two()) | ||
p; | ||
} | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...ages/babel-generator/test/fixtures/decorators/decorator-parenthesized-expression/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,34 @@ | ||
class C extends class {} { | ||
#x; | ||
constructor() { | ||
class ShouldPreserveParens { | ||
@(decs[0]) | ||
@(decs`1`) | ||
@(this?.two) | ||
@(self.#x) | ||
@(this.dec) | ||
@(super.dec) | ||
@(new DecFactory) | ||
p; | ||
} | ||
|
||
class ShouldNotAddParens { | ||
@decs | ||
@decs.one | ||
@decs.two() | ||
p; | ||
} | ||
|
||
class ShouldAddParens { | ||
@(decs[three])() | ||
p; | ||
} | ||
|
||
class ShouldRemoveParens { | ||
@(decs) | ||
@(decs.one) | ||
@(decs.two()) | ||
p; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ges/babel-generator/test/fixtures/decorators/decorator-parenthesized-expression/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,36 @@ | ||
class C extends class {} { | ||
#x; | ||
|
||
constructor() { | ||
class ShouldPreserveParens { | ||
@(decs[0]) | ||
@(decs`1`) | ||
@(this?.two) | ||
@(self.#x) | ||
@(this.dec) | ||
@(super.dec) | ||
@(new DecFactory()) | ||
p; | ||
} | ||
|
||
class ShouldNotAddParens { | ||
@decs | ||
@decs.one | ||
@decs.two() | ||
p; | ||
} | ||
|
||
class ShouldAddParens { | ||
@(decs[three]()) | ||
p; | ||
} | ||
|
||
class ShouldRemoveParens { | ||
@decs | ||
@decs.one | ||
@decs.two() | ||
p; | ||
} | ||
} | ||
|
||
} |
7 changes: 1 addition & 6 deletions
7
packages/babel-generator/test/fixtures/decorators/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 |
---|---|---|
@@ -1,9 +1,4 @@ | ||
{ | ||
"plugins": [ | ||
["decorators", { "decoratorsBeforeExport": false }], | ||
"classProperties", | ||
"classPrivateProperties", | ||
"classPrivateMethods" | ||
], | ||
"plugins": [["decorators", { "decoratorsBeforeExport": false }]], | ||
"decoratorsBeforeExport": true | ||
} |
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
3 changes: 3 additions & 0 deletions
3
...bel-parser/test/fixtures/experimental/decorators-2/invalid-unparenthesized-arrow/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 @@ | ||
class Foo { | ||
@() => () => "bar" p; | ||
} |
3 changes: 3 additions & 0 deletions
3
...parser/test/fixtures/experimental/decorators-2/invalid-unparenthesized-arrow/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 @@ | ||
{ | ||
"throws": "Unexpected token (2:4)" | ||
} |
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 |
---|---|---|
|
@@ -56,7 +56,11 @@ | |
} | ||
} | ||
} | ||
] | ||
], | ||
"extra": { | ||
"parenthesized": true, | ||
"parenStart": 1 | ||
} | ||
} | ||
} | ||
], | ||
|
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 |
---|---|---|
|
@@ -81,6 +81,10 @@ | |
} | ||
} | ||
] | ||
}, | ||
"extra": { | ||
"parenthesized": true, | ||
"parenStart": 14 | ||
} | ||
} | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
.../fixtures/experimental/decorators-2/parenthesized-createParenthesizedExpressions/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 @@ | ||
@(foo().bar) | ||
class Foo { | ||
@(member[expression]) method() {} | ||
|
||
@(foo + bar) method2() {} | ||
|
||
@(this.foo)(bar) method3() {} | ||
} |
4 changes: 4 additions & 0 deletions
4
...tures/experimental/decorators-2/parenthesized-createParenthesizedExpressions/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,4 @@ | ||
{ | ||
"plugins": [["decorators", { "decoratorsBeforeExport": false }]], | ||
"createParenthesizedExpressions": true | ||
} |
Oops, something went wrong.