-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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(es/decorators): Fix a regression about class expressions #8102
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
32d5211
Add a test
kdy1 775122c
Split
kdy1 54c60b5
fix
kdy1 2769652
fix panic
kdy1 9a0afb6
Update test refs
kdy1 1479e99
fix
kdy1 12feaea
export
kdy1 1617507
Update test refs
kdy1 8f1aa90
fix regression
kdy1 2cdddf2
declare
kdy1 33bbc24
Update test refs
kdy1 b95bbf0
Rename
kdy1 c6b8419
Updatet test refs
kdy1 95bf5ee
_$class
kdy1 fcd2a45
Updatet test refs
kdy1 a316193
Update test refs
kdy1 16dc6a7
Merge branch 'main' into issue-8095
kdy1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default class t{#t;constructor(t){this.#t=t}#e(){setTimeout(()=>{this.#t.textContent="TESTED"},1e3)}run(){this.#e()}} | ||
var t;t=class{#t;constructor(t){this.#t=t}#e(){setTimeout(()=>{this.#t.textContent="TESTED"},1e3)}run(){this.#e()}};export{t as default}; |
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
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 |
---|---|---|
|
@@ -5,13 +5,14 @@ import { _ as _ts_metadata } from "@swc/helpers/_/_ts_metadata"; | |
function Prop() { | ||
return function() {}; | ||
} | ||
var Example = function Example() { | ||
var Example; | ||
Example = function Example() { | ||
"use strict"; | ||
_class_call_check(this, Example); | ||
_define_property(this, "prop", void 0); | ||
}; | ||
export { Example as default }; | ||
_ts_decorate([ | ||
Prop(), | ||
_ts_metadata("design:type", typeof BigInt === "undefined" ? Object : BigInt) | ||
], Example.prototype, "prop", void 0); | ||
export { Example as default }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bugfix |
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
20 changes: 20 additions & 0 deletions
20
crates/swc/tests/fixture/issues-8xxx/8095/es2020/input/.swcrc
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 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": false, | ||
"decorators": true | ||
}, | ||
"target": "es2020", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const foo = class { @foo foo(v) { return v } } |
10 changes: 10 additions & 0 deletions
10
crates/swc/tests/fixture/issues-8xxx/8095/es2020/output/1.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,10 @@ | ||
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; | ||
var _class; | ||
const foo = _class = class _$class { | ||
foo(v) { | ||
return v; | ||
} | ||
}; | ||
_ts_decorate([ | ||
foo | ||
], _class.prototype, "foo", null); |
20 changes: 20 additions & 0 deletions
20
crates/swc/tests/fixture/issues-8xxx/8095/es2022/input/.swcrc
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 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": false, | ||
"decorators": true | ||
}, | ||
"target": "es2022", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const foo = class { @foo foo(v) { return v } } |
10 changes: 10 additions & 0 deletions
10
crates/swc/tests/fixture/issues-8xxx/8095/es2022/output/1.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,10 @@ | ||
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; | ||
var _class; | ||
const foo = _class = class _$class { | ||
foo(v) { | ||
return v; | ||
} | ||
}; | ||
_ts_decorate([ | ||
foo | ||
], _class.prototype, "foo", null); |
20 changes: 20 additions & 0 deletions
20
crates/swc/tests/fixture/issues-8xxx/8095/es5/input/.swcrc
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 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": false, | ||
"decorators": true | ||
}, | ||
"target": "es5", | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
} | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const foo = class { @foo foo(v) { return v } } |
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,22 @@ | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
import { _ as _create_class } from "@swc/helpers/_/_create_class"; | ||
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate"; | ||
var _class; | ||
var foo = _class = /*#__PURE__*/ function() { | ||
"use strict"; | ||
function _$class() { | ||
_class_call_check(this, _$class); | ||
} | ||
_create_class(_$class, [ | ||
{ | ||
key: "foo", | ||
value: function foo(v) { | ||
return v; | ||
} | ||
} | ||
]); | ||
return _$class; | ||
}(); | ||
_ts_decorate([ | ||
foo | ||
], _class.prototype, "foo", null); |
3 changes: 2 additions & 1 deletion
3
...c_ecma_transforms/tests/fixture/legacy-only/decl-to-expression/class-decorators/output.ts
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,4 +1,5 @@ | ||
let A = class A { | ||
var A; | ||
A = class A { | ||
}; | ||
A = _ts_decorate([ | ||
dec | ||
|
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: 4 additions & 2 deletions
6
crates/swc_ecma_transforms/tests/fixture/legacy-only/issues/879/1/output.ts
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,8 @@ | ||
export default class X { | ||
var X; | ||
X = class X { | ||
prop: string = ""; | ||
} | ||
}; | ||
_ts_decorate([ | ||
networked | ||
], X.prototype, "prop", void 0); | ||
export { X as default }; |
3 changes: 2 additions & 1 deletion
3
crates/swc_ecma_transforms/tests/fixture/legacy-only/regression-10264/output.ts
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: 4 additions & 2 deletions
6
crates/swc_ecma_transforms/tests/fixture/legacy-only/regression-8041/output.ts
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,8 @@ | ||
export default class _class { | ||
var _class; | ||
_class = class _$class { | ||
bar() {} | ||
} | ||
}; | ||
_ts_decorate([ | ||
foo | ||
], _class.prototype, "bar", null); | ||
export { _class as default }; |
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
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.
Minifier will be able to merge these, so I think this change is fine.