New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(class-properties): replace new.target
in static properties with undefined
#13560
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
30e10b8
fix(class-properties): replace `new.target` in static properties with…
colinaaa b8cfb73
Update packages/babel-helper-create-class-features-plugin/src/fields.ts
colinaaa ebcf56f
fix: add loose test case and fix replace condition
colinaaa 828285e
test: add new.target tests for static block
colinaaa 9925cbc
feat: move new-target replace into thisContextVisitor
colinaaa 8210c00
feat: simplify thisContextVisitor
colinaaa f5cbf58
test: remove unused fixme comments
colinaaa File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
...s/babel-plugin-proposal-class-static-block/test/fixtures/integration/new-target/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 Base { | ||
constructor() { | ||
var _class, _temp; | ||
|
||
this.Foo = (_temp = _class = class {}, (() => { | ||
// fixme: new.target should be undefined after transformed | ||
_class.foo = void 0; | ||
})(), _temp); | ||
} | ||
|
||
} | ||
|
||
expect(new Base().Foo.foo).toBe(undefined); |
9 changes: 9 additions & 0 deletions
9
...es/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/exec.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 Foo { | ||
constructor() { | ||
this.Bar = class { | ||
static p = new.target | ||
} | ||
} | ||
} | ||
|
||
expect((new Foo).Bar.p).toBeUndefined() |
20 changes: 20 additions & 0 deletions
20
...s/babel-plugin-transform-new-target/test/fixtures/general/class-properties-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,20 @@ | ||
class Foo { | ||
constructor() { | ||
this.Bar = class { | ||
static p = new.target | ||
static p1 = class { constructor() { new.target } } // should not replace | ||
static p2 = new function () { new.target } // should not replace | ||
static p3 = () => { new.target } // should replace | ||
static p4 = function () { new.target } // should not replace | ||
q = new.target // should not replace | ||
} | ||
} | ||
|
||
test = function() { | ||
new.target; | ||
}; | ||
|
||
test2 = () => { | ||
new.target; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...bel-plugin-transform-new-target/test/fixtures/general/class-properties-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,7 @@ | ||
{ | ||
"plugins": [ | ||
"transform-new-target", | ||
"transform-arrow-functions", | ||
["proposal-class-properties", { "loose": true }] | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
.../babel-plugin-transform-new-target/test/fixtures/general/class-properties-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,35 @@ | ||
class Foo { | ||
constructor() { | ||
var _newtarget = this.constructor, | ||
_class, | ||
_temp; | ||
|
||
this.test = function _target() { | ||
this instanceof _target ? this.constructor : void 0; | ||
}; | ||
|
||
this.test2 = function () { | ||
_newtarget; | ||
}; | ||
|
||
this.Bar = (_temp = _class = class _target2 { | ||
constructor() { | ||
this.q = this.constructor; | ||
} // should not replace | ||
|
||
|
||
}, _class.p = void 0, _class.p1 = class _target3 { | ||
constructor() { | ||
this.constructor; | ||
} | ||
|
||
}, _class.p2 = new function _target4() { | ||
this instanceof _target4 ? this.constructor : void 0; | ||
}(), _class.p3 = function () { | ||
void 0; | ||
}, _class.p4 = function _target5() { | ||
this instanceof _target5 ? this.constructor : void 0; | ||
}, _temp); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/exec.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 Foo { | ||
constructor() { | ||
this.Bar = class { | ||
static p = new.target | ||
} | ||
} | ||
} | ||
|
||
expect((new Foo).Bar.p).toBeUndefined() |
11 changes: 11 additions & 0 deletions
11
packages/babel-plugin-transform-new-target/test/fixtures/general/class-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
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
31 changes: 25 additions & 6 deletions
31
packages/babel-plugin-transform-new-target/test/fixtures/general/class-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 |
---|---|---|
@@ -1,14 +1,33 @@ | ||
class Foo { | ||
constructor() { | ||
var _newtarget = this.constructor; | ||
var _newtarget = this.constructor, | ||
_class, | ||
_temp; | ||
|
||
this.test = function _target() { | ||
babelHelpers.defineProperty(this, "test", function _target() { | ||
this instanceof _target ? this.constructor : void 0; | ||
}; | ||
|
||
this.test2 = function () { | ||
}); | ||
babelHelpers.defineProperty(this, "test2", function () { | ||
_newtarget; | ||
}; | ||
}); | ||
this.Bar = (_temp = _class = class _target2 { | ||
constructor() { | ||
babelHelpers.defineProperty(this, "q", this.constructor); | ||
} // should not replace | ||
|
||
|
||
}, babelHelpers.defineProperty(_class, "p", void 0), babelHelpers.defineProperty(_class, "p1", class _target3 { | ||
constructor() { | ||
this.constructor; | ||
} | ||
|
||
}), babelHelpers.defineProperty(_class, "p2", new function _target4() { | ||
this instanceof _target4 ? this.constructor : void 0; | ||
}()), babelHelpers.defineProperty(_class, "p3", function () { | ||
void 0; | ||
}), babelHelpers.defineProperty(_class, "p4", function _target5() { | ||
this instanceof _target5 ? this.constructor : void 0; | ||
}), _temp); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you can delete this comment from
input.js