-
-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transformer): exponentiation transform: do not replace object whe…
…n private property (#6313) Fix exponentiation operator transform to bail out early if a private class property. We can't transform this: ```js class C { #p; method() { this.#p **= 2; } } ``` But we should at least leave it alone. Previously `get_obj_ref` called `ast.move_expression(expr)` on the member expression's object before bailing out, so example above was transformed to: ```js class C { #p; method() { null.#p **= 2; // <-- `null` } } ``` This PR makes it spot this case early and bail out *before* calling `ast.move_expression(expr)`.
- Loading branch information
1 parent
fe25b65
commit ccb7bdc
Showing
4 changed files
with
34 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
commit: 3bcfee23 | ||
|
||
Passed: 56/65 | ||
Passed: 57/66 | ||
|
||
# All Passed: | ||
* babel-plugin-transform-nullish-coalescing-operator | ||
|
9 changes: 9 additions & 0 deletions
9
...l-plugin-transform-exponentiation-operator/test/fixtures/bail-private-properties/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,9 @@ | ||
class C { | ||
#p = 1; | ||
|
||
method(obj) { | ||
obj.x **= 2; // Transform | ||
obj['y'] **= 3; // Transform | ||
obj.#p **= 4; // Bail | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...-plugin-transform-exponentiation-operator/test/fixtures/bail-private-properties/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 @@ | ||
class C { | ||
#p = 1; | ||
|
||
method(obj) { | ||
obj["x"] = Math.pow(obj["x"], 2); | ||
obj["y"] = Math.pow(obj["y"], 3); | ||
obj.#p **= 4; | ||
} | ||
} |