-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transformer/class-properties): use UID for
args
in created clas…
…s constructor (#7866) When creating class constructor for a class which has super class, use UID `_args` for temp var (rather than `args`). This avoids shadowing a var called `args` used in an instance property initializer. This diverges from Babel. Babel uses `args` unless it finds a var called `args` in an instance property initializer. But searching the AST of initializers can be fairly expensive, so it's better to skip it. The overrides for test fixtures included in this PR are just to account for that difference.
- Loading branch information
1 parent
0b67b37
commit c0576fa
Showing
14 changed files
with
125 additions
and
19 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: 6 additions & 0 deletions
6
...ransform-class-properties/test/fixtures/assumption-constantSuper/instance-field/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 A extends B { | ||
constructor(..._args) { | ||
super(..._args); | ||
babelHelpers.defineProperty(this, "foo", super.bar); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ransform-class-properties/test/fixtures/assumption-setPublicClassFields/derived/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 Foo extends Bar { | ||
constructor(..._args) { | ||
super(..._args); | ||
this.bar = "foo"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sform-class-properties/test/fixtures/assumption-setPublicClassFields/super-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,11 @@ | ||
class A { | ||
foo() { | ||
return "bar"; | ||
} | ||
} | ||
class B extends A { | ||
constructor(..._args) { | ||
super(..._args); | ||
this.foo = super.foo(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...des/babel-plugin-transform-class-properties/test/fixtures/private-loose/derived/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,19 @@ | ||
var _prop = babelHelpers.classPrivateFieldLooseKey("prop"); | ||
class Foo { | ||
constructor() { | ||
Object.defineProperty(this, _prop, { | ||
writable: true, | ||
value: "foo" | ||
}); | ||
} | ||
} | ||
var _prop2 = babelHelpers.classPrivateFieldLooseKey("prop"); | ||
class Bar extends Foo { | ||
constructor(..._args) { | ||
super(..._args); | ||
Object.defineProperty(this, _prop2, { | ||
writable: true, | ||
value: "bar" | ||
}); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...overrides/babel-plugin-transform-class-properties/test/fixtures/private/derived/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 _prop = new WeakMap(); | ||
class Foo { | ||
constructor() { | ||
babelHelpers.classPrivateFieldInitSpec(this, _prop, "foo"); | ||
} | ||
} | ||
var _prop2 = new WeakMap(); | ||
class Bar extends Foo { | ||
constructor(..._args) { | ||
super(..._args); | ||
babelHelpers.classPrivateFieldInitSpec(this, _prop2, "bar"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...rrides/babel-plugin-transform-class-properties/test/fixtures/private/super-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,12 @@ | ||
class A { | ||
foo() { | ||
return "bar"; | ||
} | ||
} | ||
var _foo = new WeakMap(); | ||
class B extends A { | ||
constructor(..._args) { | ||
super(..._args); | ||
babelHelpers.classPrivateFieldInitSpec(this, _foo, super.foo()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ides/babel-plugin-transform-class-properties/test/fixtures/public-loose/derived/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 Foo extends Bar { | ||
constructor(..._args) { | ||
super(..._args); | ||
this.bar = "foo"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...s/babel-plugin-transform-class-properties/test/fixtures/public-loose/super-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,11 @@ | ||
class A { | ||
foo() { | ||
return "bar"; | ||
} | ||
} | ||
class B extends A { | ||
constructor(..._args) { | ||
super(..._args); | ||
this.foo = super.foo(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../overrides/babel-plugin-transform-class-properties/test/fixtures/public/derived/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 Foo extends Bar { | ||
constructor(..._args) { | ||
super(..._args); | ||
babelHelpers.defineProperty(this, "bar", "foo"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...errides/babel-plugin-transform-class-properties/test/fixtures/public/super-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,11 @@ | ||
class A { | ||
foo() { | ||
return "bar"; | ||
} | ||
} | ||
class B extends A { | ||
constructor(..._args) { | ||
super(..._args); | ||
babelHelpers.defineProperty(this, "foo", super.foo()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...overrides/babel-plugin-transform-class-properties/test/fixtures/regression/6154/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 @@ | ||
class Test { | ||
constructor() { | ||
var _Other; | ||
class Other extends Test { | ||
constructor(..._args) { | ||
super(..._args); | ||
babelHelpers.defineProperty(this, "a", () => super.test); | ||
} | ||
} | ||
_Other = Other; | ||
babelHelpers.defineProperty(Other, "a", () => babelHelpers.superPropGet(_Other, "test", _Other)); | ||
} | ||
} |
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