-
-
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
Differing transpilation than tsc for constructor parameter properties #7574
Comments
@magic-akari AFAIK, Implicit class properties in typescript have no specification about execution order, right? |
tsc input: class Foo {
constructor(readonly game: string) {}
x = this.game.toUpperCase();
} tsc output: "use strict";
// @target: es2022
// @useDefineForClassFields: true
class Foo {
game;
constructor(game) {
this.game = game;
}
x = this.game.toUpperCase();
}
"use strict";
// @target: es6
// @useDefineForClassFields: true
class Foo {
constructor(game) {
Object.defineProperty(this, "game", {
enumerable: true,
configurable: true,
writable: true,
value: game
});
Object.defineProperty(this, "x", {
enumerable: true,
configurable: true,
writable: true,
value: this.game.toUpperCase()
});
}
}
"use strict";
// @target: es2022
// @useDefineForClassFields: false
class Foo {
constructor(game) {
this.game = game;
this.x = this.game.toUpperCase();
}
}
"use strict";
// @target: es6
// @useDefineForClassFields: false
class Foo {
constructor(game) {
this.game = game;
this.x = this.game.toUpperCase();
}
} For more details: #7055 (comment) |
Thank you! |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
swc results in different runtime behaviour than tsc for constructor(readonly x) {}. This is not related to #7435.
Input code
Config
swc --config jsc.target=es2022
Playground link
https://play.swc.rs/?version=1.3.61&code=H4sIAAAAAAAAA0vOSSwuVnDLz1eo5uJMzs8rLikqTS7JL9IoSk1Myc%2FLqVRIT8xNtVIAimfmpWsqVNdycXFWKNgqlGRkFuuB5PRK8kMLClKLnBOLUzU0rblquQCXZn2sVAAAAA%3D%3D&config=H4sIAAAAAAAAA1VPOw7DIAzdOQXy3KFi6NA79BCIOhERAYQdqSjK3QsJpM1mv4%2Ff8yqkhIkMPOVaxrJEnQjTuReEsmf9KQhwjkgm2chw6yxTpQbtCHdoOxhgnUbk6kJSd6WaA1wIhN3RsNl6O%2BT%2FTBPmmJDoKqxS7UeH10TRUmEO72Un2y%2B179HgAT9RDzsPg6VXd3JaUGxfBMLf3xcBAAA%3D
Expected behavior
tsc outputs the following:
this code is broken because the this.game assignment happens after the x assignment.
Actual behavior
this code works because the assignment of x is moved into the constructor by swc.
Version
1.3.66
Additional context
No response
The text was updated successfully, but these errors were encountered: