diff --git a/crates/swc/src/builder.rs b/crates/swc/src/builder.rs index c3f6329016aa..617b4c42fb28 100644 --- a/crates/swc/src/builder.rs +++ b/crates/swc/src/builder.rs @@ -183,16 +183,18 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { self.top_level_mark, comments, env, + self.assumptions, )) } else { + let assumptions = self.assumptions; Either::Right(chain!( Optional::new( compat::es2022::es2022(compat::es2022::Config { class_properties: compat::es2022::class_properties::Config { - private_as_properties: self.loose, - constant_super: self.loose, - set_public_fields: self.loose, - no_document_all: self.loose + private_as_properties: assumptions.private_fields_as_properties, + constant_super: assumptions.constant_super, + set_public_fields: assumptions.set_public_class_fields, + no_document_all: assumptions.no_document_all } }), should_enable(self.target, EsVersion::Es2022) @@ -204,11 +206,11 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { Optional::new( compat::es2020::es2020(compat::es2020::Config { nullish_coalescing: compat::es2020::nullish_coalescing::Config { - no_document_all: self.loose + no_document_all: assumptions.no_document_all }, optional_chaining: compat::es2020::opt_chaining::Config { - no_document_all: self.loose, - pure_getter: self.loose + no_document_all: assumptions.no_document_all, + pure_getter: assumptions.pure_getters } }), should_enable(self.target, EsVersion::Es2020) @@ -220,8 +222,8 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { Optional::new( compat::es2018(compat::es2018::Config { object_rest_spread: compat::es2018::object_rest_spread::Config { - no_symbol: self.loose, - set_property: self.loose + no_symbol: assumptions.object_rest_no_symbols, + set_property: assumptions.set_spread_properties } }), should_enable(self.target, EsVersion::Es2018) @@ -240,10 +242,11 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { comments, compat::es2015::Config { classes: compat::es2015::classes::Config { - constant_super: self.loose, - no_class_calls: self.loose, - set_class_methods: self.loose, - super_is_callable_constructor: self.loose + constant_super: assumptions.constant_super, + no_class_calls: assumptions.no_class_calls, + set_class_methods: assumptions.set_class_methods, + super_is_callable_constructor: assumptions + .super_is_callable_constructor }, computed_props: compat::es2015::computed_props::Config { loose: self.loose @@ -257,11 +260,11 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> { }, regenerator: self.regenerator, template_literal: compat::es2015::template_literal::Config { - ignore_to_primitive: self.loose, - mutable_template: self.loose + ignore_to_primitive: assumptions.ignore_to_primitive_hint, + mutable_template: assumptions.mutable_template_object }, parameters: compat::es2015::parameters::Config { - ignore_function_length: self.loose, + ignore_function_length: assumptions.ignore_function_length, }, typescript: syntax.typescript() } diff --git a/crates/swc/src/config/mod.rs b/crates/swc/src/config/mod.rs index 51d18454f3c4..71b797411a31 100644 --- a/crates/swc/src/config/mod.rs +++ b/crates/swc/src/config/mod.rs @@ -299,7 +299,7 @@ impl Options { .. } = config.jsc; - let assumptions = assumptions.unwrap_or_else(|| { + let mut assumptions = assumptions.unwrap_or_else(|| { if loose { Assumptions::all() } else { @@ -317,18 +317,21 @@ impl Options { let mut program = parse(syntax, es_version, is_module)?; + let mut transform = transform.unwrap_or_default(); + // Do a resolver pass before everything. // // We do this before creating custom passses, so custom passses can use the // variable management system based on the syntax contexts. if syntax.typescript() { + // assumptions.set_class_methods = !transform.use_define_for_class_fields; + assumptions.set_public_class_fields = !transform.use_define_for_class_fields; + program.visit_mut_with(&mut ts_resolver(top_level_mark)); } else { program.visit_mut_with(&mut resolver_with_mark(top_level_mark)); } - let mut transform = transform.unwrap_or_default(); - if program.is_module() { js_minify = js_minify.map(|c| { let compress = c @@ -477,6 +480,7 @@ impl Options { treat_const_enum_as_enum: transform.treat_const_enum_as_enum, ts_enum_is_readonly: assumptions.ts_enum_is_readonly, }, + use_define_for_class_fields: !assumptions.set_public_class_fields, ..Default::default() }, comments, @@ -1186,6 +1190,9 @@ pub struct TransformConfig { #[serde(default)] pub treat_const_enum_as_enum: bool, + + #[serde(default)] + pub use_define_for_class_fields: bool, } #[derive(Debug, Default, Clone, Serialize, Deserialize)] diff --git a/crates/swc/tests/fixture/issue-1505/case2/output/index.ts b/crates/swc/tests/fixture/issue-1505/case2/output/index.ts index 6fcbb1c852a2..ef3dd832fd46 100644 --- a/crates/swc/tests/fixture/issue-1505/case2/output/index.ts +++ b/crates/swc/tests/fixture/issue-1505/case2/output/index.ts @@ -74,7 +74,7 @@ var MyClass = function MyClass() { _classCallCheck(this, MyClass); }; export var fn = function() { - var _class = /*#__PURE__*/ function(MyClass) { + return /*#__PURE__*/ (function(MyClass) { "use strict"; _inherits(_class, MyClass); var _super = _createSuper(_class); @@ -83,6 +83,5 @@ export var fn = function() { return _super.apply(this, arguments); } return _class; - }(MyClass); - return _class; + })(MyClass); }; diff --git a/crates/swc/tests/fixture/issue-1505/tsx-default/output/index.ts b/crates/swc/tests/fixture/issue-1505/tsx-default/output/index.ts index 6fcbb1c852a2..ef3dd832fd46 100644 --- a/crates/swc/tests/fixture/issue-1505/tsx-default/output/index.ts +++ b/crates/swc/tests/fixture/issue-1505/tsx-default/output/index.ts @@ -74,7 +74,7 @@ var MyClass = function MyClass() { _classCallCheck(this, MyClass); }; export var fn = function() { - var _class = /*#__PURE__*/ function(MyClass) { + return /*#__PURE__*/ (function(MyClass) { "use strict"; _inherits(_class, MyClass); var _super = _createSuper(_class); @@ -83,6 +83,5 @@ export var fn = function() { return _super.apply(this, arguments); } return _class; - }(MyClass); - return _class; + })(MyClass); }; diff --git a/crates/swc/tests/fixture/issue-1729/case1/output/index.ts b/crates/swc/tests/fixture/issue-1729/case1/output/index.ts index 3e13cdb6f4e8..13ecb7147f23 100644 --- a/crates/swc/tests/fixture/issue-1729/case1/output/index.ts +++ b/crates/swc/tests/fixture/issue-1729/case1/output/index.ts @@ -76,10 +76,9 @@ function createConstructor(callback) { }; } var constructor = createConstructor(function() { - var _class = function _class() { + return function _class() { "use strict"; _classCallCheck(this, _class); }; - return _class; }); console.log(constructor()); diff --git a/crates/swc/tests/fixture/issue-1729/case4/output/index.ts b/crates/swc/tests/fixture/issue-1729/case4/output/index.ts index 27235c024c23..f9ad4d6b99cb 100644 --- a/crates/swc/tests/fixture/issue-1729/case4/output/index.ts +++ b/crates/swc/tests/fixture/issue-1729/case4/output/index.ts @@ -7,9 +7,7 @@ function createConstructor(callback) { return new klass(...args); }; } -const constructor = createConstructor(()=>{ - class _class { +const constructor = createConstructor(()=>class { } - return _class; -}); +); console.log(constructor()); diff --git a/crates/swc/tests/fixture/issue-1869/decorator/output/index.ts b/crates/swc/tests/fixture/issue-1869/decorator/output/index.ts index b822f3ebf752..61587ff7af24 100644 --- a/crates/swc/tests/fixture/issue-1869/decorator/output/index.ts +++ b/crates/swc/tests/fixture/issue-1869/decorator/output/index.ts @@ -3,14 +3,14 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +var _TestClass; var _class; -var _class1; -var TestClass = _class1 = someClassDecorator((_class1 = (_class = function TestClass() { +var TestClass = _class = someClassDecorator((_class = (_TestClass = function TestClass() { "use strict"; _classCallCheck(this, TestClass); -}, _class.Something = 'hello', _class.SomeProperties = { - firstProp: _class.Something -}, _class)) || _class1) || _class1; +}, _TestClass.Something = 'hello', _TestClass.SomeProperties = { + firstProp: _TestClass.Something +}, _TestClass)) || _class) || _class; function someClassDecorator(c) { return c; } diff --git a/crates/swc/tests/fixture/issue-2086/output/index.ts b/crates/swc/tests/fixture/issue-2086/output/index.ts index 1cd5854d63c6..90a441689595 100644 --- a/crates/swc/tests/fixture/issue-2086/output/index.ts +++ b/crates/swc/tests/fixture/issue-2086/output/index.ts @@ -1 +1 @@ -class a{#a;constructor(a){this.#a=a} #b(){setTimeout(()=>{this.#a.textContent="TESTED"},1e3)}run(){this.#b()}}export{a as default} +export default class a{#a;constructor(a){this.#a=a} #b(){setTimeout(()=>{this.#a.textContent="TESTED"},1e3)}run(){this.#b()}} diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.1.normal.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.1.normal.js index 04195570fd9d..32c6dfccf386 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.1.normal.js @@ -19,11 +19,11 @@ var A; this.y = y; } } - A1.Point = Point2; Point2.Origin = { x: 0, y: 0 }; + A1.Point = Point2; (function(Point3) { var Origin = Point3.Origin = ""; })(Point2 = A1.Point || (A1.Point = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.2.minified.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.2.minified.js index ed847449a733..5f9d2eee2b39 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es2015.2.minified.js @@ -13,8 +13,8 @@ Point.Origin = { this.x = x, this.y = y; } } - A1.Point = Point1, Point1.Origin = { + Point1.Origin = { x: 0, y: 0 - }, (Point1 = A1.Point || (A1.Point = {})).Origin = ""; + }, A1.Point = Point1, (Point1 = A1.Point || (A1.Point = {})).Origin = ""; })(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.1.normal.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.1.normal.js index 7af69c574f76..72ebb475e108 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.1.normal.js @@ -24,11 +24,11 @@ var A; this.x = x; this.y = y; }; - A1.Point = Point; Point.Origin = { x: 0, y: 0 }; + A1.Point = Point; (function(Point) { var Origin = Point.Origin = ""; })(Point = A1.Point || (A1.Point = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.2.minified.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.2.minified.js index 2565f3861428..3af6e2d3286d 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName_es5.2.minified.js @@ -13,8 +13,8 @@ Point.Origin = { "use strict"; _classCallCheck(this, Point1), this.x = x, this.y = y; }; - A1.Point = Point1, Point1.Origin = { + Point1.Origin = { x: 0, y: 0 - }, (Point1 = A1.Point || (A1.Point = {})).Origin = ""; + }, A1.Point = Point1, (Point1 = A1.Point || (A1.Point = {})).Origin = ""; })(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.1.normal.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.1.normal.js index da13f2eb2171..8988ca0ecd47 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.1.normal.js @@ -19,11 +19,11 @@ var A; this.y = y; } } - A1.Point = Point1; Point1.Origin = { x: 0, y: 0 }; + A1.Point = Point1; (function(Point) { var Origin = ""; // not an error since not exported })(Point1 = A1.Point || (A1.Point = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.2.minified.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.2.minified.js index 15786a38c4aa..7befc9332771 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es2015.2.minified.js @@ -12,8 +12,8 @@ var A; this.x = x, this.y = y; } } - A1.Point = Point, Point.Origin = { + Point.Origin = { x: 0, y: 0 - }; + }, A1.Point = Point; })(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.1.normal.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.1.normal.js index 441d273f1ae9..572bc60ea523 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.1.normal.js @@ -24,11 +24,11 @@ var A; this.x = x; this.y = y; }; - A1.Point = Point; Point.Origin = { x: 0, y: 0 }; + A1.Point = Point; (function(Point) { var Origin = ""; // not an error since not exported })(Point = A1.Point || (A1.Point = {})); diff --git a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.2.minified.js b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.2.minified.js index 3873eaf2c350..0d72a62a5a20 100644 --- a/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName_es5.2.minified.js @@ -13,8 +13,8 @@ Point.Origin = { "use strict"; _classCallCheck(this, Point1), this.x = x, this.y = y; }; - A1.Point = Point1, Point1.Origin = { + Point1.Origin = { x: 0, y: 0 - }; + }, A1.Point = Point1; })(A || (A = {})); diff --git a/crates/swc/tests/tsc-references/accessorsOverrideProperty2_es5.1.normal.js b/crates/swc/tests/tsc-references/accessorsOverrideProperty2_es5.1.normal.js index 0c71b1c57973..b457b7344291 100644 --- a/crates/swc/tests/tsc-references/accessorsOverrideProperty2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/accessorsOverrideProperty2_es5.1.normal.js @@ -86,8 +86,6 @@ function _createSuper(Derived1) { var Base = function Base() { "use strict"; _classCallCheck(this, Base); - // @target: esnext - // @useDefineForClassFields: true this.x = 1; }; var Derived = /*#__PURE__*/ function(Base) { diff --git a/crates/swc/tests/tsc-references/accessorsOverrideProperty6_es5.1.normal.js b/crates/swc/tests/tsc-references/accessorsOverrideProperty6_es5.1.normal.js index c000990a280d..eceaa62af8aa 100644 --- a/crates/swc/tests/tsc-references/accessorsOverrideProperty6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/accessorsOverrideProperty6_es5.1.normal.js @@ -86,8 +86,6 @@ function _createSuper(Derived) { var A = function A() { "use strict"; _classCallCheck(this, A); - // @target: esnext - // @useDefineForClassFields: false this.p = 'yep'; }; var B = /*#__PURE__*/ function(A) { diff --git a/crates/swc/tests/tsc-references/accessorsOverrideProperty_es5.1.normal.js b/crates/swc/tests/tsc-references/accessorsOverrideProperty_es5.1.normal.js index 3b7c7717d431..eceaa62af8aa 100644 --- a/crates/swc/tests/tsc-references/accessorsOverrideProperty_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/accessorsOverrideProperty_es5.1.normal.js @@ -86,8 +86,6 @@ function _createSuper(Derived) { var A = function A() { "use strict"; _classCallCheck(this, A); - // @target: esnext - // @useDefineForClassFields: true this.p = 'yep'; }; var B = /*#__PURE__*/ function(A) { diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.1.normal.js index 8bc96a01e600..1160bb56c3e5 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.1.normal.js @@ -1,8 +1,7 @@ -class _class { -} // @target: ES6 // @module: amd // @filename: a.ts -export { _class as default }; +export default class { +}; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.2.minified.js index d042b835304b..2cd6c004999c 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es2015.2.minified.js @@ -1,4 +1,3 @@ -class _class { -} +export default class { +}; export default function() {}; -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.1.normal.js index 37b7259bf4ae..c8817ce55a4e 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.1.normal.js @@ -3,13 +3,10 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _class = function _class() { +var _default = function _default() { "use strict"; - _classCallCheck(this, _class); + _classCallCheck(this, _default); }; -// @target: ES6 -// @module: amd -// @filename: a.ts -export { _class as default }; +export { _default as default }; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.2.minified.js index b943888e32f4..7d61f5364bd0 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsAmd_es5.2.minified.js @@ -1,8 +1,8 @@ -var _class = function() { +var _default = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, _class); + }(this, _default); }; export default function() {}; -export { _class as default }; +export { _default as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.1.normal.js index 4f02ce3726b6..1aa3ec3ce887 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.1.normal.js @@ -1,8 +1,7 @@ -class _class { -} // @target: ES6 // @module: commonjs // @filename: a.ts -export { _class as default }; +export default class { +}; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.2.minified.js index d042b835304b..2cd6c004999c 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es2015.2.minified.js @@ -1,4 +1,3 @@ -class _class { -} +export default class { +}; export default function() {}; -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.1.normal.js index 679fb54e5582..c8817ce55a4e 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.1.normal.js @@ -3,13 +3,10 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _class = function _class() { +var _default = function _default() { "use strict"; - _classCallCheck(this, _class); + _classCallCheck(this, _default); }; -// @target: ES6 -// @module: commonjs -// @filename: a.ts -export { _class as default }; +export { _default as default }; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.2.minified.js index b943888e32f4..7d61f5364bd0 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsCommonjs_es5.2.minified.js @@ -1,8 +1,8 @@ -var _class = function() { +var _default = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, _class); + }(this, _default); }; export default function() {}; -export { _class as default }; +export { _default as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.1.normal.js index b485f0a92029..ce97f127eecd 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.1.normal.js @@ -1,8 +1,7 @@ -class _class { -} // @target: ES6 // @module: system // @filename: a.ts -export { _class as default }; +export default class { +}; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.2.minified.js index d042b835304b..2cd6c004999c 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es2015.2.minified.js @@ -1,4 +1,3 @@ -class _class { -} +export default class { +}; export default function() {}; -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.1.normal.js index e8c083ea29b4..c8817ce55a4e 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.1.normal.js @@ -3,13 +3,10 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _class = function _class() { +var _default = function _default() { "use strict"; - _classCallCheck(this, _class); + _classCallCheck(this, _default); }; -// @target: ES6 -// @module: system -// @filename: a.ts -export { _class as default }; +export { _default as default }; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.2.minified.js index b943888e32f4..7d61f5364bd0 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsSystem_es5.2.minified.js @@ -1,8 +1,8 @@ -var _class = function() { +var _default = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, _class); + }(this, _default); }; export default function() {}; -export { _class as default }; +export { _default as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.1.normal.js index 9f3bff7885b8..510c5bba6a85 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.1.normal.js @@ -1,8 +1,7 @@ -class _class { -} // @target: ES6 // @module: umd // @filename: a.ts -export { _class as default }; +export default class { +}; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.2.minified.js index d042b835304b..2cd6c004999c 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es2015.2.minified.js @@ -1,4 +1,3 @@ -class _class { -} +export default class { +}; export default function() {}; -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.1.normal.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.1.normal.js index aeca6e97d9ac..c8817ce55a4e 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.1.normal.js @@ -3,13 +3,10 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _class = function _class() { +var _default = function _default() { "use strict"; - _classCallCheck(this, _class); + _classCallCheck(this, _default); }; -// @target: ES6 -// @module: umd -// @filename: a.ts -export { _class as default }; +export { _default as default }; // @filename: b.ts export default function() {}; diff --git a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.2.minified.js b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.2.minified.js index b943888e32f4..7d61f5364bd0 100644 --- a/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/anonymousDefaultExportsUmd_es5.2.minified.js @@ -1,8 +1,8 @@ -var _class = function() { +var _default = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, _class); + }(this, _default); }; export default function() {}; -export { _class as default }; +export { _default as default }; diff --git a/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es2015.1.normal.js b/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es2015.1.normal.js index d69fa6f20df6..005357c2d8ee 100644 --- a/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es2015.1.normal.js @@ -11,37 +11,35 @@ class C { } constructor(foo){ this.foo = foo; - this.qux // should error - = this.bar; - this.bar // should error - = this.foo; - this.quiz // ok - = this.bar; - this.quench // ok - = this.m1(); - this.quanch // should error - = this.m3(); + this.qux = this.bar // should error + ; + this.bar = this.foo // should error + ; + this.quiz = this.bar // ok + ; + this.quench = this.m1() // ok + ; + this.quanch = this.m3() // should error + ; this.m3 = function() {}; - this.quim // should error - = this.baz; - this.baz // should error - = this.foo; - this.quid // ok - = this.baz; + this.quim = this.baz // should error + ; + this.baz = this.foo; + this.quid = this.baz // ok + ; } } class D extends C { constructor(...args){ super(...args); - this.quill // ok - = this.foo; + this.quill = this.foo // ok + ; } } class E { constructor(foo2){ this.foo2 = foo2; - this.bar // both ok - = ()=>this.foo1 + this.foo2 + this.bar = ()=>this.foo1 + this.foo2 ; this.foo1 = ''; } diff --git a/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es5.1.normal.js b/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es5.1.normal.js index 16c6623e69ca..314cc61191b9 100644 --- a/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext_es5.1.normal.js @@ -90,23 +90,22 @@ var C = // @useDefineForClassFields: true function C(foo) { _classCallCheck(this, C); this.foo = foo; - this.qux // should error - = this.bar; - this.bar // should error - = this.foo; - this.quiz // ok - = this.bar; - this.quench // ok - = this.m1(); - this.quanch // should error - = this.m3(); + this.qux = this.bar // should error + ; + this.bar = this.foo // should error + ; + this.quiz = this.bar // ok + ; + this.quench = this.m1() // ok + ; + this.quanch = this.m3() // should error + ; this.m3 = function() {}; - this.quim // should error - = this.baz; - this.baz // should error - = this.foo; - this.quid // ok - = this.baz; + this.quim = this.baz // should error + ; + this.baz = this.foo; + this.quid = this.baz // ok + ; } _createClass(C, [ { @@ -134,8 +133,8 @@ var D = /*#__PURE__*/ function(C) { _classCallCheck(this, D); var _this; _this = _super.apply(this, arguments); - _this.quill // ok - = _this.foo; + _this.quill = _this.foo // ok + ; return _this; } return D; @@ -145,8 +144,7 @@ var E = function E(foo2) { var _this = this; _classCallCheck(this, E); this.foo2 = foo2; - this.bar // both ok - = function() { + this.bar = function() { return _this.foo1 + _this.foo2; }; this.foo1 = ''; diff --git a/crates/swc/tests/tsc-references/asyncArrowFunction11_es5_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncArrowFunction11_es5_es5.1.normal.js index da93e54a3f56..ef3f3b8e1e89 100644 --- a/crates/swc/tests/tsc-references/asyncArrowFunction11_es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncArrowFunction11_es5_es5.1.normal.js @@ -50,10 +50,6 @@ var A = function A() { "use strict"; _classCallCheck(this, A); var _this = this; - // @target: es5 - // @lib: esnext, dom - // @downlevelIteration: true - // https://github.com/Microsoft/TypeScript/issues/24722 this.b = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var _len, args, _key, obj, _args = arguments; return regeneratorRuntime.wrap(function _callee$(_ctx) { diff --git a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.1.normal.js index d39da8d16c70..423018351140 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.1.normal.js @@ -27,24 +27,24 @@ function _asyncToGenerator(fn) { }); }; } -var _class; +var _B; // @target: ES5 // @lib: es5,es2015.promise // @noEmitHelpers: true // https://github.com/Microsoft/TypeScript/issues/20744 class A { } -A.B = (_class = class B { +A.B = (_B = class B { static func2() { return new Promise((resolve)=>{ resolve(null); }); } -}, _class.C = class C { +}, _B.C = class C { static func() { return _asyncToGenerator(function*() { - yield _class.func2(); + yield _B.func2(); })(); } -}, _class); +}, _B); A.B.C.func(); diff --git a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.2.minified.js b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.2.minified.js index 99cbd28b80e1..c83b14c7e6b8 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es2015.2.minified.js @@ -1,4 +1,4 @@ -var _class; +var _B; function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg), value = info.value; @@ -10,7 +10,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { } class A { } -(_class = class { +(_B = class { static func2() { return new Promise((resolve)=>{ resolve(null); @@ -33,7 +33,7 @@ class A { }); }; })(function*() { - yield _class.func2(); + yield _B.func2(); })(); } -}, A.B = _class, A.B.C.func(); +}, A.B = _B, A.B.C.func(); diff --git a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.1.normal.js index 1e4b7a222a30..55a272c192f8 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.1.normal.js @@ -47,12 +47,12 @@ function _createClass(Constructor, protoProps, staticProps) { return Constructor; } import regeneratorRuntime from "regenerator-runtime"; -var _class; +var _B; var A = function A() { "use strict"; _classCallCheck(this, A); }; -A.B = (_class = /*#__PURE__*/ (function() { +A.B = (_B = /*#__PURE__*/ (function() { "use strict"; function B() { _classCallCheck(this, B); @@ -68,7 +68,7 @@ A.B = (_class = /*#__PURE__*/ (function() { } ]); return B; -})(), _class.C = /*#__PURE__*/ (function() { +})(), _B.C = /*#__PURE__*/ (function() { "use strict"; function C() { _classCallCheck(this, C); @@ -82,7 +82,7 @@ A.B = (_class = /*#__PURE__*/ (function() { while(1)switch(_ctx.prev = _ctx.next){ case 0: _ctx.next = 2; - return _class.func2(); + return _B.func2(); case 2: case "end": return _ctx.stop(); @@ -93,5 +93,5 @@ A.B = (_class = /*#__PURE__*/ (function() { } ]); return C; -})(), _class); +})(), _B); A.B.C.func(); diff --git a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.2.minified.js index 899cffcf6cee..33faa276ad33 100644 --- a/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncAwaitNestedClasses_es5_es5.2.minified.js @@ -20,11 +20,11 @@ function _createClass(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } import regeneratorRuntime from "regenerator-runtime"; -var _class, A = function() { +var _B, A = function() { "use strict"; _classCallCheck(this, A); }; -(_class = (function() { +(_B = (function() { "use strict"; function B() { _classCallCheck(this, B); @@ -53,7 +53,7 @@ var _class, A = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.next = 2, _class.func2(); + return _ctx.next = 2, _B.func2(); case 2: case "end": return _ctx.stop(); @@ -75,4 +75,4 @@ var _class, A = function() { } } ]), C; -})(), A.B = _class, A.B.C.func(); +})(), A.B = _B, A.B.C.func(); diff --git a/crates/swc/tests/tsc-references/classStaticBlock18_es2015.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18_es2015.1.normal.js index 59b73d54f8b6..a94ad0bc7685 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18_es2015.1.normal.js @@ -1,19 +1,18 @@ -var _class, _class1; // @target: esnext, es2022, es2015, es5 function foo() { - var _class2, __1; - return _class1 = (_class2 = class { - }, __1 = { + var _class1, __1; + return _class1 = class { + }, _class1.foo = 1, __1 = { writable: true, value: (()=>{ - var _class3, __; - const c = (_class = (_class3 = class { - }, __ = { + var _class, __; + const c = (_class = class { + }, _class.bar = 2, __ = { writable: true, value: (()=>{ // do })() - }, _class3), _class.bar = 2, _class); + }, _class); })() - }, _class2), _class1.foo = 1, _class1; + }, _class1; } diff --git a/crates/swc/tests/tsc-references/classStaticBlock18_es5.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock18_es5.1.normal.js index e8c3a58976a8..3ab3411c22f1 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock18_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock18_es5.1.normal.js @@ -3,26 +3,25 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _class, _class1; // @target: esnext, es2022, es2015, es5 function foo() { - var _class2, __1; - return _class1 = (_class2 = function _class3() { + var _class1, __1; + return _class1 = function _class() { "use strict"; - _classCallCheck(this, _class3); - }, __1 = { + _classCallCheck(this, _class); + }, _class1.foo = 1, __1 = { writable: true, value: (function() { - var _class4, __; - var c = (_class = (_class4 = function _class3() { + var _class2, __; + var c = (_class2 = function _class() { "use strict"; - _classCallCheck(this, _class3); - }, __ = { + _classCallCheck(this, _class); + }, _class2.bar = 2, __ = { writable: true, value: function() { // do }() - }, _class4), _class.bar = 2, _class); + }, _class2); })() - }, _class2), _class1.foo = 1, _class1; + }, _class1; } diff --git a/crates/swc/tests/tsc-references/classStaticBlock27_es2015.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock27_es2015.1.normal.js index 1741d2d84bf2..ebaa49c4606a 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock27_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock27_es2015.1.normal.js @@ -1,8 +1,7 @@ var _Foo, __, __1, __2; -var _class; // https://github.com/microsoft/TypeScript/issues/44872 -void (_class = (_Foo = class Foo { -}, __ = { +void (_Foo = class Foo { +}, _Foo.prop = 1, __ = { writable: true, value: (()=>{ console.log(_Foo.prop); @@ -20,4 +19,4 @@ void (_class = (_Foo = class Foo { console.log(_Foo.prop); _Foo.prop++; })() -}, _Foo), _class.prop = 1, _class); +}, _Foo); diff --git a/crates/swc/tests/tsc-references/classStaticBlock27_es2015.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock27_es2015.2.minified.js index 688ac58020be..8799177a8ca6 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock27_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock27_es2015.2.minified.js @@ -1,3 +1,3 @@ var _Foo; (_Foo = class { -}, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++, _Foo).prop = 1; +}).prop = 1, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++; diff --git a/crates/swc/tests/tsc-references/classStaticBlock27_es5.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock27_es5.1.normal.js index 20d3ac786d18..9b27cd225c13 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock27_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock27_es5.1.normal.js @@ -4,12 +4,11 @@ function _classCallCheck(instance, Constructor) { } } var _Foo, __, __1, __2; -var _class; // https://github.com/microsoft/TypeScript/issues/44872 -void (_class = (_Foo = function Foo() { +void (_Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); -}, __ = { +}, _Foo.prop = 1, __ = { writable: true, value: function() { console.log(_Foo.prop); @@ -27,4 +26,4 @@ void (_class = (_Foo = function Foo() { console.log(_Foo.prop); _Foo.prop++; }() -}, _Foo), _class.prop = 1, _class); +}, _Foo); diff --git a/crates/swc/tests/tsc-references/classStaticBlock27_es5.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock27_es5.2.minified.js index ee29165bc551..90293997175c 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock27_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock27_es5.2.minified.js @@ -4,4 +4,4 @@ var _Foo; (function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); })(this, Foo); -}, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++, _Foo).prop = 1; +}).prop = 1, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++, console.log(_Foo.prop), _Foo.prop++; diff --git a/crates/swc/tests/tsc-references/classStaticBlock3_es2015.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock3_es2015.1.normal.js index e8b21906db96..db12a833004c 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock3_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock3_es2015.1.normal.js @@ -2,18 +2,18 @@ const a = 1; class C { } +C.f1 = 1; var __ = { writable: true, value: (()=>{ console.log(C.f1, C.f2, C.f3); })() }; +C.f2 = 2; var __1 = { writable: true, value: (()=>{ console.log(C.f1, C.f2, C.f3); })() }; -C.f1 = 1; -C.f2 = 2; C.f3 = 3; diff --git a/crates/swc/tests/tsc-references/classStaticBlock3_es2015.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock3_es2015.2.minified.js index 82114a325b10..8cb4ff4ed20a 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock3_es2015.2.minified.js @@ -1,3 +1,3 @@ class C { } -console.log(C.f1, C.f2, C.f3), console.log(C.f1, C.f2, C.f3), C.f1 = 1, C.f2 = 2, C.f3 = 3; +C.f1 = 1, console.log(C.f1, C.f2, C.f3), C.f2 = 2, console.log(C.f1, C.f2, C.f3), C.f3 = 3; diff --git a/crates/swc/tests/tsc-references/classStaticBlock3_es5.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock3_es5.1.normal.js index 0fd10a2b0b3f..20367fe10a4f 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock3_es5.1.normal.js @@ -9,18 +9,18 @@ var C = function C() { "use strict"; _classCallCheck(this, C); }; +C.f1 = 1; var __ = { writable: true, value: function() { console.log(C.f1, C.f2, C.f3); }() }; +C.f2 = 2; var __1 = { writable: true, value: function() { console.log(C.f1, C.f2, C.f3); }() }; -C.f1 = 1; -C.f2 = 2; C.f3 = 3; diff --git a/crates/swc/tests/tsc-references/classStaticBlock3_es5.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock3_es5.2.minified.js index 2998bddcdd4b..1965396a54b1 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock3_es5.2.minified.js @@ -4,4 +4,4 @@ var C = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -console.log(C.f1, C.f2, C.f3), console.log(C.f1, C.f2, C.f3), C.f1 = 1, C.f2 = 2, C.f3 = 3; +C.f1 = 1, console.log(C.f1, C.f2, C.f3), C.f2 = 2, console.log(C.f1, C.f2, C.f3), C.f3 = 3; diff --git a/crates/swc/tests/tsc-references/classStaticBlock4_es2015.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock4_es2015.1.normal.js index 9acee2872425..503596b12ae9 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock4_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock4_es2015.1.normal.js @@ -1,6 +1,7 @@ // @target: esnext, es2022 class C { } +C.s1 = 1; var __ = { writable: true, value: (()=>{ @@ -10,6 +11,5 @@ var __ = { C.s2; })() }; -C.s1 = 1; C.s2 = 2; C.ss2 = C.s1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock4_es2015.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock4_es2015.2.minified.js index 4b62096904b6..b79ab250c365 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock4_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock4_es2015.2.minified.js @@ -1,3 +1,3 @@ class C { } -C.s1, C.s1, C.s2, C.s2, C.s1 = 1, C.s2 = 2, C.ss2 = C.s1; +C.s1 = 1, C.s1, C.s1, C.s2, C.s2, C.s2 = 2, C.ss2 = C.s1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock4_es5.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock4_es5.1.normal.js index 3cf52f64adf5..5ed75c72d31e 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock4_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock4_es5.1.normal.js @@ -7,6 +7,7 @@ var C = function C() { "use strict"; _classCallCheck(this, C); }; +C.s1 = 1; var __ = { writable: true, value: function() { @@ -16,6 +17,5 @@ var __ = { C.s2; }() }; -C.s1 = 1; C.s2 = 2; C.ss2 = C.s1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock4_es5.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock4_es5.2.minified.js index 07c40be9ad65..76b237c4e950 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock4_es5.2.minified.js @@ -4,4 +4,4 @@ var C = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -C.s1, C.s1, C.s2, C.s2, C.s1 = 1, C.s2 = 2, C.ss2 = C.s1; +C.s1 = 1, C.s1, C.s1, C.s2, C.s2, C.s2 = 2, C.ss2 = C.s1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock5_es2015.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5_es2015.1.normal.js index ae4dd21036cc..5eeb7e8f0d39 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} // @target: esnext, es2022, es2015, es5 class B { } @@ -5,6 +34,8 @@ B.a = 1; B.b = 2; class C extends B { } +C.b = 3; +C.c = _get(_getPrototypeOf(C), "a", C); var __ = { writable: true, value: (()=>{ @@ -13,5 +44,3 @@ var __ = { super.a; })() }; -C.b = 3; -C.c = super.a; diff --git a/crates/swc/tests/tsc-references/classStaticBlock5_es2015.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock5_es2015.2.minified.js index 1233254d1565..1c9de2e41c19 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5_es2015.2.minified.js @@ -1,6 +1,24 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class B { } B.a = 1, B.b = 2; class C extends B { } -C.b, super.b, super.a, C.b = 3, C.c = super.a; +C.b = 3, C.c = _get(_getPrototypeOf(C), "a", C), C.b, super.b, super.a; diff --git a/crates/swc/tests/tsc-references/classStaticBlock5_es5.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock5_es5.1.normal.js index 0fab8c05255e..5d5e75e28bf3 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5_es5.1.normal.js @@ -9,6 +9,22 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -41,6 +57,13 @@ function _setPrototypeOf(o, p) { }; return _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; @@ -88,6 +111,8 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); +C.b = 3; +C.c = _get(_getPrototypeOf(C), "a", C); var __ = { writable: true, value: function() { @@ -96,5 +121,3 @@ var __ = { _superprop_get_a(); }() }; -C.b = 3; -C.c = super.a; diff --git a/crates/swc/tests/tsc-references/classStaticBlock5_es5.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock5_es5.2.minified.js index 6668b7b4fadf..3445c75dfbb8 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock5_es5.2.minified.js @@ -1,6 +1,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} function _getPrototypeOf(o) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -11,6 +20,10 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} var B = function() { "use strict"; _classCallCheck(this, B); @@ -53,4 +66,4 @@ var C = function(B1) { } return C; }(B); -C.b, super.b, super.a, C.b = 3, C.c = super.a; +C.b = 3, C.c = _get(_getPrototypeOf(C), "a", C), C.b, super.b, super.a; diff --git a/crates/swc/tests/tsc-references/classStaticBlock9_es2015.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9_es2015.1.normal.js index d2163d3e0c59..4d34d0453fd1 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9_es2015.1.normal.js @@ -1,11 +1,11 @@ // @target: esnext, es2022, es2015, es5 class A { } +A.bar = A.foo + 1; var __ = { writable: true, value: (()=>{ A.foo + 2; })() }; -A.bar = A.foo + 1; A.foo = 1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock9_es2015.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock9_es2015.2.minified.js index d8080ddf736a..3f0f9192a424 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9_es2015.2.minified.js @@ -1,3 +1,3 @@ class A { } -A.foo, A.bar = A.foo + 1, A.foo = 1; +A.bar = A.foo + 1, A.foo, A.foo = 1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock9_es5.1.normal.js b/crates/swc/tests/tsc-references/classStaticBlock9_es5.1.normal.js index e85e04e22a87..4e3222e270c7 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9_es5.1.normal.js @@ -7,11 +7,11 @@ var A = function A() { "use strict"; _classCallCheck(this, A); }; +A.bar = A.foo + 1; var __ = { writable: true, value: function() { A.foo + 2; }() }; -A.bar = A.foo + 1; A.foo = 1; diff --git a/crates/swc/tests/tsc-references/classStaticBlock9_es5.2.minified.js b/crates/swc/tests/tsc-references/classStaticBlock9_es5.2.minified.js index b6fe3c999b96..8b856529feb5 100644 --- a/crates/swc/tests/tsc-references/classStaticBlock9_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/classStaticBlock9_es5.2.minified.js @@ -4,4 +4,4 @@ var A = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, A); }; -A.foo, A.bar = A.foo + 1, A.foo = 1; +A.bar = A.foo + 1, A.foo, A.foo = 1; diff --git a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es2015.1.normal.js b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es2015.1.normal.js index 26938911125d..95e6dfcef2c2 100644 --- a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es2015.1.normal.js @@ -12,21 +12,21 @@ var x = 1; class C { constructor(x1){ - this.b // ok - = x; + this.b = x // ok + ; } } var y = 1; class D { constructor(x){ - this.b // ok - = y; + this.b = y // ok + ; var y1 = ""; } } class E { constructor(z1){ - this.b // not ok - = z; + this.b = z // not ok + ; } } diff --git a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es5.1.normal.js b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es5.1.normal.js index 2b08202622be..3cb7b0d1aec4 100644 --- a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes2_es5.1.normal.js @@ -18,20 +18,20 @@ var x = 1; var C = function C(x1) { "use strict"; _classCallCheck(this, C); - this.b // ok - = x; + this.b = x // ok + ; }; var y = 1; var D = function D(x) { "use strict"; _classCallCheck(this, D); - this.b // ok - = y; + this.b = y // ok + ; var y1 = ""; }; var E = function E(z1) { "use strict"; _classCallCheck(this, E); - this.b // not ok - = z; + this.b = z // not ok + ; }; diff --git a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es2015.1.normal.js b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es2015.1.normal.js index 530bd8729f13..8b8683a704a3 100644 --- a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es2015.1.normal.js @@ -5,16 +5,16 @@ var x = 1; class C { constructor(x1){ - this.b // error, evaluated in scope of constructor, cannot reference x - = x; + this.b = x // error, evaluated in scope of constructor, cannot reference x + ; x1 = 2; // error, x is string } } var y = 1; class D { constructor(x){ - this.b // error, evaluated in scope of constructor, cannot reference y - = y; + this.b = y // error, evaluated in scope of constructor, cannot reference y + ; var y1 = ""; } } diff --git a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es5.1.normal.js b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es5.1.normal.js index 36966011370b..77b54efd6239 100644 --- a/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/constructorParameterShadowsOuterScopes_es5.1.normal.js @@ -11,15 +11,15 @@ var x = 1; var C = function C(x1) { "use strict"; _classCallCheck(this, C); - this.b // error, evaluated in scope of constructor, cannot reference x - = x; + this.b = x // error, evaluated in scope of constructor, cannot reference x + ; x1 = 2; // error, x is string }; var y = 1; var D = function D(x) { "use strict"; _classCallCheck(this, D); - this.b // error, evaluated in scope of constructor, cannot reference y - = y; + this.b = y // error, evaluated in scope of constructor, cannot reference y + ; var y1 = ""; }; diff --git a/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es2015.1.normal.js b/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es2015.1.normal.js index 3e5306a69161..bcf80f7c61aa 100644 --- a/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es2015.1.normal.js @@ -1,4 +1,3 @@ -var _class, _class1; function getFoo1() { return class { static method1(arg) { @@ -10,6 +9,7 @@ function getFoo1() { }; } function getFoo2() { + var _class; return _class = class { }, _class.method1 = (arg)=>{ arg.numProp = 10; @@ -18,10 +18,11 @@ function getFoo2() { }, _class; } function getFoo3() { - return _class1 = class { - }, _class1.method1 = function(arg) { + var _class; + return _class = class { + }, _class.method1 = function(arg) { arg.numProp = 10; - }, _class1.method2 = function(arg) { + }, _class.method2 = function(arg) { arg.strProp = "hello"; - }, _class1; + }, _class; } diff --git a/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es5.1.normal.js b/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es5.1.normal.js index 7dab3ad2ef22..72824112b35f 100644 --- a/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/contextuallyTypedClassExpressionMethodDeclaration01_es5.1.normal.js @@ -17,14 +17,13 @@ function _createClass(Constructor, protoProps, staticProps) { if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var _class, _class1; function getFoo1() { return /*#__PURE__*/ (function() { "use strict"; - function _class2() { - _classCallCheck(this, _class2); + function _class() { + _classCallCheck(this, _class); } - _createClass(_class2, null, [ + _createClass(_class, null, [ { key: "method1", value: function method1(arg) { @@ -38,26 +37,28 @@ function getFoo1() { } } ]); - return _class2; + return _class; })(); } function getFoo2() { - return _class = function _class2() { + var _class1; + return _class1 = function _class() { "use strict"; - _classCallCheck(this, _class2); - }, _class.method1 = function(arg) { + _classCallCheck(this, _class); + }, _class1.method1 = function(arg) { arg.numProp = 10; - }, _class.method2 = function(arg) { + }, _class1.method2 = function(arg) { arg.strProp = "hello"; - }, _class; + }, _class1; } function getFoo3() { - return _class1 = function _class2() { + var _class2; + return _class2 = function _class() { "use strict"; - _classCallCheck(this, _class2); - }, _class1.method1 = function(arg) { + _classCallCheck(this, _class); + }, _class2.method1 = function(arg) { arg.numProp = 10; - }, _class1.method2 = function(arg) { + }, _class2.method2 = function(arg) { arg.strProp = "hello"; - }, _class1; + }, _class2; } diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.1.normal.js index f04983d9bd9f..8fa136fd6049 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.1.normal.js @@ -1,11 +1,10 @@ // @filename: m2.ts import Entity from "m1"; -class Decl { -} // @module: commonjs // @target: ES5 // @filename: m1.ts -export { Decl as default }; +export default class Decl { +}; Entity(); var x; var y; diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.2.minified.js index 0069d4119e5c..ef8e1cb3ef5a 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es2015.2.minified.js @@ -1,7 +1,6 @@ import Entity from "m1"; -class Decl { -} +export default class Decl { +}; Entity(); var z = new Entity(); z.p1 + z.p2; -export { Decl as default }; diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es5.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es5.1.normal.js index b11483970c8c..ce7dd29562a8 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge02_es5.1.normal.js @@ -9,9 +9,6 @@ var Decl = function Decl() { "use strict"; _classCallCheck(this, Decl); }; -// @module: commonjs -// @target: ES5 -// @filename: m1.ts export { Decl as default }; Entity(); var x; diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.1.normal.js index f04983d9bd9f..8fa136fd6049 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.1.normal.js @@ -1,11 +1,10 @@ // @filename: m2.ts import Entity from "m1"; -class Decl { -} // @module: commonjs // @target: ES5 // @filename: m1.ts -export { Decl as default }; +export default class Decl { +}; Entity(); var x; var y; diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.2.minified.js index 0069d4119e5c..ef8e1cb3ef5a 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es2015.2.minified.js @@ -1,7 +1,6 @@ import Entity from "m1"; -class Decl { -} +export default class Decl { +}; Entity(); var z = new Entity(); z.p1 + z.p2; -export { Decl as default }; diff --git a/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es5.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es5.1.normal.js index b11483970c8c..ce7dd29562a8 100644 --- a/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsCannotMerge03_es5.1.normal.js @@ -9,9 +9,6 @@ var Decl = function Decl() { "use strict"; _classCallCheck(this, Decl); }; -// @module: commonjs -// @target: ES5 -// @filename: m1.ts export { Decl as default }; Entity(); var x; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.1.normal.js index 98b59a8492b3..afe60379836f 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.1.normal.js @@ -1,8 +1,7 @@ -class Foo { -} // @target: ES6 // @module: amd // @filename: a.ts -export { Foo as default }; +export default class Foo { +}; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.2.minified.js index 3fd9a1625f84..7dd083068ced 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es2015.2.minified.js @@ -1,4 +1,3 @@ -class Foo { -} +export default class Foo { +}; export default function foo() {}; -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es5.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es5.1.normal.js index fee454c4c1e5..38998e873f76 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedAmd_es5.1.normal.js @@ -7,9 +7,6 @@ var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); }; -// @target: ES6 -// @module: amd -// @filename: a.ts export { Foo as default }; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.1.normal.js index 1e8e537b861e..19959600f725 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.1.normal.js @@ -1,8 +1,7 @@ -class Foo { -} // @target: ES6 // @module: commonjs // @filename: a.ts -export { Foo as default }; +export default class Foo { +}; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.2.minified.js index 3fd9a1625f84..7dd083068ced 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es2015.2.minified.js @@ -1,4 +1,3 @@ -class Foo { -} +export default class Foo { +}; export default function foo() {}; -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es5.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es5.1.normal.js index a5aa1e20070c..38998e873f76 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedCommonjs_es5.1.normal.js @@ -7,9 +7,6 @@ var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); }; -// @target: ES6 -// @module: commonjs -// @filename: a.ts export { Foo as default }; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.1.normal.js index 8a01105aeb56..ba5730909bd0 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.1.normal.js @@ -1,8 +1,7 @@ -class Foo { -} // @target: ES6 // @module: system // @filename: a.ts -export { Foo as default }; +export default class Foo { +}; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.2.minified.js index 3fd9a1625f84..7dd083068ced 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es2015.2.minified.js @@ -1,4 +1,3 @@ -class Foo { -} +export default class Foo { +}; export default function foo() {}; -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es5.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es5.1.normal.js index 4179b14e6011..38998e873f76 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedSystem_es5.1.normal.js @@ -7,9 +7,6 @@ var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); }; -// @target: ES6 -// @module: system -// @filename: a.ts export { Foo as default }; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.1.normal.js index ce67b4941a65..c0fd8428b602 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.1.normal.js @@ -1,8 +1,7 @@ -class Foo { -} // @target: ES6 // @module: umd // @filename: a.ts -export { Foo as default }; +export default class Foo { +}; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.2.minified.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.2.minified.js index 3fd9a1625f84..7dd083068ced 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es2015.2.minified.js @@ -1,4 +1,3 @@ -class Foo { -} +export default class Foo { +}; export default function foo() {}; -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es5.1.normal.js b/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es5.1.normal.js index ae2a41343383..38998e873f76 100644 --- a/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defaultExportsGetExportedUmd_es5.1.normal.js @@ -7,9 +7,6 @@ var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); }; -// @target: ES6 -// @module: umd -// @filename: a.ts export { Foo as default }; // @filename: b.ts export default function foo() {}; diff --git a/crates/swc/tests/tsc-references/definePropertyOutputES3_es5.1.normal.js b/crates/swc/tests/tsc-references/definePropertyOutputES3_es5.1.normal.js index 33eb6adee152..0d242ff331f4 100644 --- a/crates/swc/tests/tsc-references/definePropertyOutputES3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/definePropertyOutputES3_es5.1.normal.js @@ -6,7 +6,5 @@ function _classCallCheck(instance, Constructor) { var A = function A() { "use strict"; _classCallCheck(this, A); - // @target: es3 - // @useDefineForClassFields: true this.a = 12; }; diff --git a/crates/swc/tests/tsc-references/defineProperty_es2015.1.normal.js b/crates/swc/tests/tsc-references/defineProperty_es2015.1.normal.js index cf56ccf70a36..dd1659207493 100644 --- a/crates/swc/tests/tsc-references/defineProperty_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/defineProperty_es2015.1.normal.js @@ -1,19 +1,17 @@ -var _key, _key1; // @target: es5, esnext // @useDefineForClassFields: true var x = "p"; +let _x = x; class A { m() {} constructor(y){ this.y = y; this.a = this.y; - this[_key] = 13; - this[_key1] = 14; + this["computed"] = 13; + this[_x] = 14; this.z = this.y; } } -_key = "computed"; -_key1 = x; class B { } class C extends B { diff --git a/crates/swc/tests/tsc-references/defineProperty_es2015.2.minified.js b/crates/swc/tests/tsc-references/defineProperty_es2015.2.minified.js index 06614f294b68..e69de29bb2d1 100644 --- a/crates/swc/tests/tsc-references/defineProperty_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/defineProperty_es2015.2.minified.js @@ -1,2 +0,0 @@ -var _key, _key1; -_key = "computed", _key1 = "p"; diff --git a/crates/swc/tests/tsc-references/defineProperty_es5.1.normal.js b/crates/swc/tests/tsc-references/defineProperty_es5.1.normal.js index 7ef14c0226a6..f805f08c68d8 100644 --- a/crates/swc/tests/tsc-references/defineProperty_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/defineProperty_es5.1.normal.js @@ -83,18 +83,18 @@ function _createSuper(Derived) { return _possibleConstructorReturn(this, result); }; } -var _key, _key1; // @target: es5, esnext // @useDefineForClassFields: true var x = "p"; +var _x = x; var A = /*#__PURE__*/ function() { "use strict"; function A(y) { _classCallCheck(this, A); this.y = y; this.a = this.y; - this[_key] = 13; - this[_key1] = 14; + this["computed"] = 13; + this[_x] = 14; this.z = this.y; } _createClass(A, [ @@ -105,8 +105,6 @@ var A = /*#__PURE__*/ function() { ]); return A; }(); -_key = "computed"; -_key1 = x; var B = function B() { "use strict"; _classCallCheck(this, B); diff --git a/crates/swc/tests/tsc-references/defineProperty_es5.2.minified.js b/crates/swc/tests/tsc-references/defineProperty_es5.2.minified.js index 21ba89712dc4..b813a5321606 100644 --- a/crates/swc/tests/tsc-references/defineProperty_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/defineProperty_es5.2.minified.js @@ -17,11 +17,11 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } -var _key, _key1, A = function() { +var A = function() { "use strict"; var Constructor, protoProps, staticProps; function A(y) { - _classCallCheck(this, A), this.y = y, this.a = this.y, this[_key] = 13, this[_key1] = 14, this.z = this.y; + _classCallCheck(this, A), this.y = y, this.a = this.y, this.computed = 13, this.p = 14, this.z = this.y; } return protoProps = [ { @@ -29,9 +29,7 @@ var _key, _key1, A = function() { value: function() {} } ], _defineProperties((Constructor = A).prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), A; -}(); -_key = "computed", _key1 = "p"; -var B = function() { +}(), B = function() { "use strict"; _classCallCheck(this, B); }, C = function(B1) { diff --git a/crates/swc/tests/tsc-references/derivedClassWithoutExplicitConstructor3_es5.1.normal.js b/crates/swc/tests/tsc-references/derivedClassWithoutExplicitConstructor3_es5.1.normal.js index a45968c382ed..f964fd57b037 100644 --- a/crates/swc/tests/tsc-references/derivedClassWithoutExplicitConstructor3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/derivedClassWithoutExplicitConstructor3_es5.1.normal.js @@ -72,7 +72,6 @@ function _createSuper(Derived1) { var Base = function Base(x) { "use strict"; _classCallCheck(this, Base); - // automatic constructors with a class hieararchy of depth > 2 this.a = 1; this.a = x; }; diff --git a/crates/swc/tests/tsc-references/emitClassDeclarationWithPropertyAssignmentInES6_es5.1.normal.js b/crates/swc/tests/tsc-references/emitClassDeclarationWithPropertyAssignmentInES6_es5.1.normal.js index dd23208befbe..83118aef4e36 100644 --- a/crates/swc/tests/tsc-references/emitClassDeclarationWithPropertyAssignmentInES6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitClassDeclarationWithPropertyAssignmentInES6_es5.1.normal.js @@ -72,7 +72,6 @@ function _createSuper(Derived) { var C = function C() { "use strict"; _classCallCheck(this, C); - // @target:es6 this.x = "Hello world"; }; var D = function D() { diff --git a/crates/swc/tests/tsc-references/exportAssignmentTopLevelClodule_es5.1.normal.js b/crates/swc/tests/tsc-references/exportAssignmentTopLevelClodule_es5.1.normal.js index 2390d40d6738..628aa7057af5 100644 --- a/crates/swc/tests/tsc-references/exportAssignmentTopLevelClodule_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/exportAssignmentTopLevelClodule_es5.1.normal.js @@ -6,8 +6,6 @@ function _classCallCheck(instance, Constructor) { var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - // @module: amd - // @Filename: foo_0.ts this.test = "test"; }; (function(Foo) { @@ -19,4 +17,6 @@ var foo = require("./foo_0"); if (foo.answer === 42) { var x = new foo(); } +// @module: amd +// @Filename: foo_0.ts export { }; diff --git a/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.1.normal.js b/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.1.normal.js index 07ea2c761749..c63750206632 100644 --- a/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.1.normal.js @@ -1,4 +1,3 @@ -class Object { -} // @target: ES5 -export { Object as default }; +export default class Object { +}; diff --git a/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.2.minified.js b/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.2.minified.js index 2ce2fd32c53a..f6b60eb71adf 100644 --- a/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es2015.2.minified.js @@ -1,3 +1,2 @@ -class Object { -} -export { Object as default }; +export default class Object { +}; diff --git a/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es5.1.normal.js b/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es5.1.normal.js index 802b162975d1..9d7782b5e530 100644 --- a/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/exportDefaultClassNameWithObject_es5.1.normal.js @@ -7,5 +7,4 @@ var Object = function Object() { "use strict"; _classCallCheck(this, Object); }; -// @target: ES5 export { Object as default }; diff --git a/crates/swc/tests/tsc-references/importClause_default_es2015.1.normal.js b/crates/swc/tests/tsc-references/importClause_default_es2015.1.normal.js index 9d510d9cee40..d5f7dcecec19 100644 --- a/crates/swc/tests/tsc-references/importClause_default_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importClause_default_es2015.1.normal.js @@ -1,7 +1,6 @@ -class A { -} // @Filename: /a.ts -export { A as default }; +export default class A { +}; new A(); let a = { a: '' diff --git a/crates/swc/tests/tsc-references/importClause_default_es2015.2.minified.js b/crates/swc/tests/tsc-references/importClause_default_es2015.2.minified.js index 9804d6c9c22d..cbb702cdcc7f 100644 --- a/crates/swc/tests/tsc-references/importClause_default_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importClause_default_es2015.2.minified.js @@ -1,4 +1,3 @@ -class A { -} +export default class A { +}; new A(); -export { A as default }; diff --git a/crates/swc/tests/tsc-references/importClause_default_es5.1.normal.js b/crates/swc/tests/tsc-references/importClause_default_es5.1.normal.js index 67df7204c367..74d355c42b64 100644 --- a/crates/swc/tests/tsc-references/importClause_default_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importClause_default_es5.1.normal.js @@ -7,7 +7,6 @@ var A = function A() { "use strict"; _classCallCheck(this, A); }; -// @Filename: /a.ts export { A as default }; new A(); var a = { diff --git a/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.1.normal.js b/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.1.normal.js index b77bebe395d5..07c42e41d5f6 100644 --- a/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.1.normal.js @@ -1,4 +1,3 @@ -class A { -} // @Filename: /a.ts -export { A as default }; +export default class A { +}; diff --git a/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.2.minified.js b/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.2.minified.js index 1c229e229f63..95220774f32a 100644 --- a/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importDefaultNamedType_es2015.2.minified.js @@ -1,3 +1,2 @@ -class A { -} -export { A as default }; +export default class A { +}; diff --git a/crates/swc/tests/tsc-references/importDefaultNamedType_es5.1.normal.js b/crates/swc/tests/tsc-references/importDefaultNamedType_es5.1.normal.js index 6e6b6303ab45..8b219ed9c25f 100644 --- a/crates/swc/tests/tsc-references/importDefaultNamedType_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importDefaultNamedType_es5.1.normal.js @@ -7,5 +7,4 @@ var A = function A() { "use strict"; _classCallCheck(this, A); }; -// @Filename: /a.ts export { A as default }; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js index dae3e7618bd1..fb8632f0d9a6 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.1.normal.js @@ -1,9 +1,8 @@ -class _class { -} // @importsNotUsedAsValues: error // @noUnusedLocals: true // @Filename: /a.ts -export { _class as default }; +export default class { +}; export class A { } export var C; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js index 1998a928ab63..9e86bfb809e0 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es2015.2.minified.js @@ -1,6 +1,6 @@ var C, K; -class _class { -} +export default class { +}; export class A { } !function(C) { @@ -23,4 +23,3 @@ const H = require("./h"); K[K.One = 0] = "One", K[K.Two = 1] = "Two"; }(K || (K = {})), module.exports = K; const K = require("./k"); -export { _class as default }; diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js index 899a60faf323..24b735a9426b 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.1.normal.js @@ -3,14 +3,11 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _class = function _class() { +var _default = function _default() { "use strict"; - _classCallCheck(this, _class); + _classCallCheck(this, _default); }; -// @importsNotUsedAsValues: error -// @noUnusedLocals: true -// @Filename: /a.ts -export { _class as default }; +export { _default as default }; export var A = function A() { "use strict"; _classCallCheck(this, A); diff --git a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js index 35bf31415d01..4d7d96d25654 100644 --- a/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/importsNotUsedAsValues_error_es5.2.minified.js @@ -1,9 +1,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } -var C, a, b, a, b, b, c, d, K, _class = function() { +var C, a, b, a, b, b, c, d, K, _default = function() { "use strict"; - _classCallCheck(this, _class); + _classCallCheck(this, _default); }; export var A = function() { "use strict"; @@ -28,4 +28,4 @@ var H = require("./h"); K[K.One = 0] = "One", K[K.Two = 1] = "Two"; }(K || (K = {})), module.exports = K; var K = require("./k"); -export { _class as default }; +export { _default as default }; diff --git a/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es2015.1.normal.js b/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es2015.1.normal.js index c968e2f95b6d..56d41c5c619b 100644 --- a/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es2015.1.normal.js @@ -1,19 +1,19 @@ // Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. class C { constructor(x){ - this.a // error - = z; - this.c // error - = this.z; + this.a = z // error + ; + this.c = this.z // error + ; z = 1; } } class D { constructor(x){ - this.a // error - = z; - this.c // error - = this.z; + this.a = z // error + ; + this.c = this.z // error + ; z = 1; } } diff --git a/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es5.1.normal.js b/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es5.1.normal.js index 43a8a6ac0e2d..6c4bae01955e 100644 --- a/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/initializerReferencingConstructorLocals_es5.1.normal.js @@ -6,19 +6,18 @@ function _classCallCheck(instance, Constructor) { var C = function C(x) { "use strict"; _classCallCheck(this, C); - // Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. - this.a // error - = z; - this.c // error - = this.z; + this.a = z // error + ; + this.c = this.z // error + ; z = 1; }; var D = function D(x) { "use strict"; _classCallCheck(this, D); - this.a // error - = z; - this.c // error - = this.z; + this.a = z // error + ; + this.c = this.z // error + ; z = 1; }; diff --git a/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es2015.1.normal.js b/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es2015.1.normal.js index 78bd601ec7fc..4df73843bc53 100644 --- a/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es2015.1.normal.js @@ -1,30 +1,26 @@ // Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. class C { constructor(x1){ - this.a // error - = x; + this.a = x // error + ; } } class D { constructor(x2){ this.x = x2; - this.a // error - = x; + this.a = x; } } class E { constructor(x){ this.x = x; - this.a // ok - = this.x; + this.a = this.x; } } class F { constructor(x3){ this.x = x3; - this.a // ok - = this.x; - this.b // error - = x; + this.a = this.x; + this.b = x; } } diff --git a/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es5.1.normal.js b/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es5.1.normal.js index fb01ef4234fb..1e2e2ecab9a1 100644 --- a/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/initializerReferencingConstructorParameters_es5.1.normal.js @@ -6,30 +6,25 @@ function _classCallCheck(instance, Constructor) { var C = function C(x1) { "use strict"; _classCallCheck(this, C); - // Initializer expressions for instance member variables are evaluated in the scope of the class constructor body but are not permitted to reference parameters or local variables of the constructor. - this.a // error - = x; + this.a = x // error + ; }; var D = function D(x2) { "use strict"; _classCallCheck(this, D); this.x = x2; - this.a // error - = x; + this.a = x; }; var E = function E(x) { "use strict"; _classCallCheck(this, E); this.x = x; - this.a // ok - = this.x; + this.a = this.x; }; var F = function F(x3) { "use strict"; _classCallCheck(this, F); this.x = x3; - this.a // ok - = this.x; - this.b // error - = x; + this.a = this.x; + this.b = x; }; diff --git a/crates/swc/tests/tsc-references/instanceMemberInitialization_es5.1.normal.js b/crates/swc/tests/tsc-references/instanceMemberInitialization_es5.1.normal.js index 898e82eb4503..c13f0d29b5fa 100644 --- a/crates/swc/tests/tsc-references/instanceMemberInitialization_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/instanceMemberInitialization_es5.1.normal.js @@ -16,6 +16,5 @@ var MyMap = function MyMap(Map_) { "use strict"; _classCallCheck(this, MyMap); this.Map_ = Map_; - // #31792 this.store = new this.Map_(); }; diff --git a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.1.normal.js b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.1.normal.js index cd46fd2958de..1b0dca2c5dac 100644 --- a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.1.normal.js @@ -1,14 +1,13 @@ // https://github.com/microsoft/TypeScript/issues/30953 "use strict"; -var _key; const x = 1; +let _x = x; class C { constructor(){ - this[_key] = true; + this[_x] = true; const { a , b } = { a: 1, b: 2 }; } } -_key = x; diff --git a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.2.minified.js b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.2.minified.js index b87ca4059ac5..3918c74e4463 100644 --- a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es2015.2.minified.js @@ -1,3 +1 @@ "use strict"; -var _key; -_key = 1; diff --git a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.1.normal.js b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.1.normal.js index 38523ada818c..1a0ff315d8cf 100644 --- a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.1.normal.js @@ -5,14 +5,13 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _key; var x = 1; +var _x = x; var C = function C() { _classCallCheck(this, C); - this[_key] = true; + this[_x] = true; var ref = { a: 1, b: 2 }, a = ref.a, b = ref.b; }; -_key = x; diff --git a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.2.minified.js b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.2.minified.js index b01169019e20..54e93eaff2c7 100644 --- a/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/instanceMemberWithComputedPropertyName_es5.2.minified.js @@ -1,12 +1,11 @@ "use strict"; -var _key, C = function() { +var C = function() { !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), this[_key] = !0; + }(this, C), this[1] = !0; var ref = { a: 1, b: 2 }; ref.a, ref.b; }; -_key = 1; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.1.normal.js index 4c82c9845e9f..ff212ca9153c 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.1.normal.js @@ -1,4 +1,3 @@ -var _key, _key1; // @allowJs: true // @checkJs: true // @target: es5 @@ -21,14 +20,13 @@ module.exports = { // @filename: index2.js const TopLevelSym = Symbol(); const InnerSym = Symbol(); +let _InnerSym = InnerSym; export class MyClass { /** * @param {typeof TopLevelSym | typeof InnerSym} _p */ constructor(_p = InnerSym){ - this[_key1] = "ok"; + this[_InnerSym] = "ok"; // switch on _p } } -_key = TopLevelSym; -_key1 = InnerSym; -MyClass[_key] = 12; +MyClass[TopLevelSym] = 12; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.2.minified.js index b472fb63e7ec..6ac2b6910ae8 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es2015.2.minified.js @@ -1,4 +1,3 @@ -var _key, _key1; const TopLevelSym = Symbol(), InnerSym = Symbol(); module.exports = { [TopLevelSym] (x = 12) { @@ -11,9 +10,10 @@ module.exports = { } }; const TopLevelSym = Symbol(), InnerSym = Symbol(); +let _InnerSym = InnerSym; export class MyClass { constructor(_p = InnerSym){ - this[_key1] = "ok"; + this[_InnerSym] = "ok"; } } -_key = TopLevelSym, _key1 = InnerSym, MyClass[_key] = 12; +MyClass[TopLevelSym] = 12; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.1.normal.js index 913dd8051687..3c8da991a5dd 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.1.normal.js @@ -16,7 +16,6 @@ function _defineProperty(obj, key, value) { } return obj; } -var _key, _key1; // @allowJs: true // @checkJs: true // @target: es5 @@ -39,12 +38,11 @@ module.exports = (_obj = {}, _defineProperty(_obj, TopLevelSym, function() { // @filename: index2.js var TopLevelSym = Symbol(); var InnerSym = Symbol(); +var _InnerSym = InnerSym; export var MyClass = function MyClass() { "use strict"; var _p = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : InnerSym; _classCallCheck(this, MyClass); - this[_key1] = "ok"; + this[_InnerSym] = "ok"; }; -_key = TopLevelSym; -_key1 = InnerSym; -MyClass[_key] = 12; +MyClass[TopLevelSym] = 12; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.2.minified.js index abcb473bc825..06920571fc7c 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsComputedNames_es5.2.minified.js @@ -6,7 +6,7 @@ function _defineProperty(obj, key, value) { writable: !0 }) : obj[key] = value, obj; } -var _key, _key1, _obj, TopLevelSym = Symbol(), InnerSym = Symbol(); +var _obj, TopLevelSym = Symbol(), InnerSym = Symbol(); module.exports = (_defineProperty(_obj = {}, TopLevelSym, function() { var x = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 12; return x; @@ -16,11 +16,11 @@ module.exports = (_defineProperty(_obj = {}, TopLevelSym, function() { }; return arg.x; })), _obj); -var TopLevelSym = Symbol(), InnerSym = Symbol(); +var TopLevelSym = Symbol(), InnerSym = Symbol(), _InnerSym = InnerSym; export var MyClass = function() { "use strict"; arguments.length > 0 && void 0 !== arguments[0] && arguments[0], (function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - })(this, MyClass), this[_key1] = "ok"; + })(this, MyClass), this[_InnerSym] = "ok"; }; -_key = TopLevelSym, _key1 = InnerSym, MyClass[_key] = 12; +MyClass[TopLevelSym] = 12; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr_es5.1.normal.js index 8a2ebcd4123b..059522587d73 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsDefaultsErr_es5.1.normal.js @@ -6,13 +6,6 @@ function _classCallCheck(instance, Constructor) { var Cls = function Cls() { "use strict"; _classCallCheck(this, Cls); - // @allowJs: true - // @checkJs: true - // @target: es5 - // @outDir: ./out - // @declaration: true - // @filename: index1.js - // merge type alias and alias (should error, see #32367) this.x = 12; }; Cls.y = "ok"; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassExpressionShadowing_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassExpressionShadowing_es5.1.normal.js index c81702bcfe72..c7105f065498 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassExpressionShadowing_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassExpressionShadowing_es5.1.normal.js @@ -6,12 +6,6 @@ function _classCallCheck(instance, Constructor) { var A = function A() { "use strict"; _classCallCheck(this, A); - // @allowJs: true - // @checkJs: true - // @target: es5 - // @outDir: ./out - // @declaration: true - // @filename: index.js this.member = new Q(); }; var Q = function Q() { diff --git a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2_es5.1.normal.js index 76c3531bcb56..44afad1a0393 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance2_es5.1.normal.js @@ -6,12 +6,6 @@ function _classCallCheck(instance, Constructor) { var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - // @allowJs: true - // @checkJs: true - // @target: es5 - // @outDir: ./out - // @declaration: true - // @filename: index.js this.member = 10; }; Foo.stat = 10; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3_es5.1.normal.js index 3d670d085138..a014751e0984 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsExportAssignedClassInstance3_es5.1.normal.js @@ -6,12 +6,6 @@ function _classCallCheck(instance, Constructor) { var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - // @allowJs: true - // @checkJs: true - // @target: es5 - // @outDir: ./out - // @declaration: true - // @filename: index.js this.member = 10; }; Foo.stat = 10; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.1.normal.js index fda3e1c5ec2a..cd6bc85f9995 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.1.normal.js @@ -1,13 +1,12 @@ // @filename: usage.js import { default as Fooa } from "./cls"; -class Foo { -} // @allowJs: true // @checkJs: true // @target: es5 // @outDir: ./out // @declaration: true // @filename: cls.js -export { Foo as default }; +export default class Foo { +}; export const x = new Fooa(); export { default as Foob } from "./cls"; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.2.minified.js index fa67269832ab..716f2d8a99ea 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es2015.2.minified.js @@ -1,6 +1,5 @@ import { default as Fooa } from "./cls"; -class Foo { -} +export default class Foo { +}; export const x = new Fooa(); export { default as Foob } from "./cls"; -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es5.1.normal.js index 4f03f06abc7d..b9900100440b 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsReexportAliases_es5.1.normal.js @@ -9,12 +9,6 @@ var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); }; -// @allowJs: true -// @checkJs: true -// @target: es5 -// @outDir: ./out -// @declaration: true -// @filename: cls.js export { Foo as default }; export var x = new Fooa(); export { default as Foob } from "./cls"; diff --git a/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations_es5.1.normal.js index 2087178aea11..d915d65f94fb 100644 --- a/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/jsDeclarationsReusesExistingTypeAnnotations_es5.1.normal.js @@ -20,14 +20,7 @@ function _createClass(Constructor, protoProps, staticProps) { var С1 = function С1() { "use strict"; _classCallCheck(this, С1); - /** @type {string=} */ // @allowJs: true - // @checkJs: true - // @target: esnext - // @strict: true - // @declaration: true - // @filename: index.js - // @outDir: /out - this.p1 = undefined; + /** @type {string=} */ this.p1 = undefined; /** @type {string | undefined} */ this.p2 = undefined; /** @type {?string} */ this.p3 = null; /** @type {string | null} */ this.p4 = null; diff --git a/crates/swc/tests/tsc-references/mappedTypesAndObjects_es5.1.normal.js b/crates/swc/tests/tsc-references/mappedTypesAndObjects_es5.1.normal.js index 7004f899be7a..e11fd85d1e8b 100644 --- a/crates/swc/tests/tsc-references/mappedTypesAndObjects_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/mappedTypesAndObjects_es5.1.normal.js @@ -21,6 +21,5 @@ function f3(x) { var Form = function Form() { "use strict"; _classCallCheck(this, Form); - // Repro from #13747 this.values = {}; }; diff --git a/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es2015.1.normal.js b/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es2015.1.normal.js index 87bf7a1ef9c9..642b5197bf48 100644 --- a/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es2015.1.normal.js @@ -1,11 +1,11 @@ -var _class; // @declaration: true // @declaration: true function g() { - var x = (_class = class C { + var _C; + var x = (_C = class C { foo() {} constructor(){ this.prop1 = 1; } - }, _class.prop2 = 43, _class); + }, _C.prop2 = 43, _C); } diff --git a/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es5.1.normal.js b/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es5.1.normal.js index 4ced496164cb..6f90d0c97218 100644 --- a/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/modifierOnClassExpressionMemberInFunction_es5.1.normal.js @@ -17,11 +17,11 @@ function _createClass(Constructor, protoProps, staticProps) { if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var _class; // @declaration: true // @declaration: true function g() { - var x = (_class = /*#__PURE__*/ function() { + var _C; + var x = (_C = /*#__PURE__*/ function() { "use strict"; function C() { _classCallCheck(this, C); @@ -34,5 +34,5 @@ function g() { } ]); return C; - }(), _class.prop2 = 43, _class); + }(), _C.prop2 = 43, _C); } diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.1.normal.js b/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.1.normal.js index 1c2b8e111708..4e03569ba711 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.1.normal.js @@ -1,11 +1,10 @@ // @filename: m2.ts import Entity from "./m1"; -class foo { -} // @module: commonjs // @target: ES5 // @filename: m1.ts -export { foo as default }; +export default class foo { +}; export default function bar() {}; var x = 10; export default x; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.2.minified.js b/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.2.minified.js index a638f4304977..0f95ff27221f 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports01_es2015.2.minified.js @@ -1,7 +1,6 @@ import Entity from "./m1"; -class foo { -} +export default class foo { +}; export default function bar() {}; export default 10; Entity(); -export { foo as default }; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports01_es5.1.normal.js b/crates/swc/tests/tsc-references/multipleDefaultExports01_es5.1.normal.js index d3c4684acb92..ddd395bd57ee 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports01_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports01_es5.1.normal.js @@ -9,9 +9,6 @@ var foo = function foo() { "use strict"; _classCallCheck(this, foo); }; -// @module: commonjs -// @target: ES5 -// @filename: m1.ts export { foo as default }; export default function bar() {}; var x = 10; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.1.normal.js b/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.1.normal.js index be1b21cf8896..618c485e6dff 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.1.normal.js @@ -1,8 +1,6 @@ -class C { -} // @module: commonjs // @target: ES5 -export { C as default }; -class C { -} -export { C as default }; +export default class C { +}; +export default class C { +}; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.2.minified.js b/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.2.minified.js index d1f623662fbc..9ebc72efc8f3 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports03_es2015.2.minified.js @@ -1,5 +1,4 @@ -class C { -} -class C { -} -export { C as default, C as default }; +export default class C { +}; +export default class C { +}; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports03_es5.1.normal.js b/crates/swc/tests/tsc-references/multipleDefaultExports03_es5.1.normal.js index c57997d5c351..993a2ba95917 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports03_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports03_es5.1.normal.js @@ -7,8 +7,6 @@ var C = function C() { "use strict"; _classCallCheck(this, C); }; -// @module: commonjs -// @target: ES5 export { C as default }; var C = function C() { "use strict"; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.1.normal.js b/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.1.normal.js index a0aa72714a44..3202eba2fb79 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.1.normal.js @@ -1,11 +1,8 @@ -class AA1 { -} // @module: commonjs // @target: ES5 -export { AA1 as default }; -class BB1 { -} -export { BB1 as default }; -class CC1 { -} -export { CC1 as default }; +export default class AA1 { +}; +export default class BB1 { +}; +export default class CC1 { +}; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.2.minified.js b/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.2.minified.js index 7bd25e29d64a..47840ba12789 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports05_es2015.2.minified.js @@ -1,7 +1,6 @@ -class AA1 { -} -class BB1 { -} -class CC1 { -} -export { AA1 as default, BB1 as default, CC1 as default }; +export default class AA1 { +}; +export default class BB1 { +}; +export default class CC1 { +}; diff --git a/crates/swc/tests/tsc-references/multipleDefaultExports05_es5.1.normal.js b/crates/swc/tests/tsc-references/multipleDefaultExports05_es5.1.normal.js index aab0041f6746..94201dd4ad55 100644 --- a/crates/swc/tests/tsc-references/multipleDefaultExports05_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleDefaultExports05_es5.1.normal.js @@ -7,8 +7,6 @@ var AA1 = function AA1() { "use strict"; _classCallCheck(this, AA1); }; -// @module: commonjs -// @target: ES5 export { AA1 as default }; var BB1 = function BB1() { "use strict"; diff --git a/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.1.normal.js b/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.1.normal.js index 91246f116c5c..e854b44be4ea 100644 --- a/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.1.normal.js @@ -1,6 +1,5 @@ export default { uhoh: "another default" }; -class C { -} -export { C as default }; +export default class C { +}; diff --git a/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.2.minified.js b/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.2.minified.js index 91246f116c5c..e854b44be4ea 100644 --- a/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/multipleExportDefault3_es2015.2.minified.js @@ -1,6 +1,5 @@ export default { uhoh: "another default" }; -class C { -} -export { C as default }; +export default class C { +}; diff --git a/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.1.normal.js b/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.1.normal.js index 8a189d12c7d6..1f0c8731ca31 100644 --- a/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.1.normal.js @@ -1,6 +1,5 @@ -class C { -} -export { C as default }; +export default class C { +}; export default { uhoh: "another default" }; diff --git a/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.2.minified.js b/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.2.minified.js index 50f714a66827..1f0c8731ca31 100644 --- a/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/multipleExportDefault4_es2015.2.minified.js @@ -1,6 +1,5 @@ -class C { -} +export default class C { +}; export default { uhoh: "another default" }; -export { C as default }; diff --git a/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.1.normal.js b/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.1.normal.js index fec952a5444b..0e7967e58ca3 100644 --- a/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.1.normal.js @@ -1,4 +1,3 @@ export default function bar() {}; -class C { -} -export { C as default }; +export default class C { +}; diff --git a/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.2.minified.js b/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.2.minified.js index fec952a5444b..0e7967e58ca3 100644 --- a/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/multipleExportDefault5_es2015.2.minified.js @@ -1,4 +1,3 @@ export default function bar() {}; -class C { -} -export { C as default }; +export default class C { +}; diff --git a/crates/swc/tests/tsc-references/newTarget.es5_es5.1.normal.js b/crates/swc/tests/tsc-references/newTarget.es5_es5.1.normal.js index b512d03d1a59..424b54d8b6a6 100644 --- a/crates/swc/tests/tsc-references/newTarget.es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/newTarget.es5_es5.1.normal.js @@ -80,7 +80,6 @@ var A = function A() { "use strict"; var _newtarget = _instanceof(this, A) ? this.constructor : void 0; _classCallCheck(this, A); - // @target: es5 this.d = function _target() { return _instanceof(this, _target) ? this.constructor : void 0; }; diff --git a/crates/swc/tests/tsc-references/newTarget.es6_es5.1.normal.js b/crates/swc/tests/tsc-references/newTarget.es6_es5.1.normal.js index 2331a27f7e64..424b54d8b6a6 100644 --- a/crates/swc/tests/tsc-references/newTarget.es6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/newTarget.es6_es5.1.normal.js @@ -80,7 +80,6 @@ var A = function A() { "use strict"; var _newtarget = _instanceof(this, A) ? this.constructor : void 0; _classCallCheck(this, A); - // @target: es6 this.d = function _target() { return _instanceof(this, _target) ? this.constructor : void 0; }; diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.1.normal.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.1.normal.js index 31c16364746b..ad68fba8d7e0 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.1.normal.js @@ -4,9 +4,10 @@ // @outFile: output.js // @filename: src/a.ts import foo from "./b"; -class Foo { -} -export { Foo as default }; +// @filename: src/b.ts +import Foo from "./a"; +export default class Foo { +}; foo(); export default function foo() { new Foo(); diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.2.minified.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.2.minified.js index cbf25eac2d57..77df5494ce1b 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es2015.2.minified.js @@ -1,9 +1,9 @@ import foo from "./b"; -class Foo { -} +import Foo from "./a"; +export default class Foo { +}; foo(); export default function foo() { new Foo(); }; import("./a"); -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.1.normal.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.1.normal.js index a370d567afb4..ecf090e8c43f 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.1.normal.js @@ -9,6 +9,8 @@ function _classCallCheck(instance, Constructor) { // @outFile: output.js // @filename: src/a.ts import foo from "./b"; +// @filename: src/b.ts +import Foo from "./a"; var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.2.minified.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.2.minified.js index 16483ed8acaf..51054b40ae86 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesAmd_es5.2.minified.js @@ -1,5 +1,6 @@ import foo from "./b"; -var Foo = function() { +import Foo from "./a"; +var Foo = function Foo() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.1.normal.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.1.normal.js index b703cb425567..3e3435405339 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.1.normal.js @@ -4,9 +4,10 @@ // @outFile: output.js // @filename: src/a.ts import foo from "./b"; -class Foo { -} -export { Foo as default }; +// @filename: src/b.ts +import Foo from "./a"; +export default class Foo { +}; foo(); export default function foo() { new Foo(); diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.2.minified.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.2.minified.js index cbf25eac2d57..77df5494ce1b 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es2015.2.minified.js @@ -1,9 +1,9 @@ import foo from "./b"; -class Foo { -} +import Foo from "./a"; +export default class Foo { +}; foo(); export default function foo() { new Foo(); }; import("./a"); -export { Foo as default }; diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.1.normal.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.1.normal.js index 87d6295feffd..80ba80a9b771 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.1.normal.js @@ -9,6 +9,8 @@ function _classCallCheck(instance, Constructor) { // @outFile: output.js // @filename: src/a.ts import foo from "./b"; +// @filename: src/b.ts +import Foo from "./a"; var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); diff --git a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.2.minified.js b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.2.minified.js index 16483ed8acaf..51054b40ae86 100644 --- a/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/outFilerootDirModuleNamesSystem_es5.2.minified.js @@ -1,5 +1,6 @@ import foo from "./b"; -var Foo = function() { +import Foo from "./a"; +var Foo = function Foo() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); diff --git a/crates/swc/tests/tsc-references/override13_es5.1.normal.js b/crates/swc/tests/tsc-references/override13_es5.1.normal.js index dbe03e322af6..ab9a695498ed 100644 --- a/crates/swc/tests/tsc-references/override13_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/override13_es5.1.normal.js @@ -72,8 +72,6 @@ function _createSuper(Derived1) { var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - // @noImplicitOverride: true - // @target: esnext this.property = 1; }; Foo.staticProperty = 2; diff --git a/crates/swc/tests/tsc-references/override14_es5.1.normal.js b/crates/swc/tests/tsc-references/override14_es5.1.normal.js index 2954785f4329..e43d7313bf64 100644 --- a/crates/swc/tests/tsc-references/override14_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/override14_es5.1.normal.js @@ -72,8 +72,6 @@ function _createSuper(Derived) { var Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - // @noImplicitOverride: true - // @target: esnext this.property = 1; }; var SubFoo = /*#__PURE__*/ function(Foo) { diff --git a/crates/swc/tests/tsc-references/override6_es5.1.normal.js b/crates/swc/tests/tsc-references/override6_es5.1.normal.js index 902cca3e46a3..adf78a43bb69 100644 --- a/crates/swc/tests/tsc-references/override6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/override6_es5.1.normal.js @@ -74,8 +74,6 @@ var B = function B(foo, bar) { _classCallCheck(this, B); this.foo = foo; this.bar = bar; - // @declaration: true - // @noImplicitOverride: true this.baz = 1; }; var D = /*#__PURE__*/ function(B) { diff --git a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.1.normal.js index 27b968fb409a..4a1913fe72ba 100644 --- a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.1.normal.js @@ -1,8 +1,7 @@ -var _key; +let _toStringTag = Symbol.toStringTag; //@target: ES5 class C { constructor(){ - this[_key] = ""; + this[_toStringTag] = ""; } } -_key = Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.2.minified.js index bd03ef2d4bce..c562216962fc 100644 --- a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es2015.2.minified.js @@ -1,2 +1 @@ -var _key; -_key = Symbol.toStringTag; +Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.1.normal.js b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.1.normal.js index 7a9733703e10..344d5ba5344f 100644 --- a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.1.normal.js @@ -3,11 +3,9 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _key; +var _toStringTag = Symbol.toStringTag; var C = function C() { "use strict"; _classCallCheck(this, C); - //@target: ES5 - this[_key] = ""; + this[_toStringTag] = ""; }; -_key = Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.2.minified.js b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.2.minified.js index f23b96525d86..cad96f9bdab3 100644 --- a/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserES5SymbolProperty6_es5.2.minified.js @@ -1,7 +1,6 @@ -var _key, C = function() { +var _toStringTag = Symbol.toStringTag, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), this[_key] = ""; + }(this, C), this[_toStringTag] = ""; }; -_key = Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.1.normal.js index b84ced025e09..1a92d1f7d262 100644 --- a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.1.normal.js @@ -12,8 +12,9 @@ var Shapes; this.y = y; } } - Shapes1.Point = Point; + // Static member Point.origin = new Point(0, 0); + Shapes1.Point = Point; })(Shapes || (Shapes = {})); // Local variables var p = new Shapes.Point(3, 4); diff --git a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.2.minified.js index 200f90fafdc5..51191db34c74 100644 --- a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es2015.2.minified.js @@ -8,5 +8,5 @@ var Shapes; this.x = x, this.y = y; } } - Shapes1.Point = Point, Point.origin = new Point(0, 0); + Point.origin = new Point(0, 0), Shapes1.Point = Point; }(Shapes || (Shapes = {})), new Shapes.Point(3, 4).getDist(); diff --git a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.1.normal.js b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.1.normal.js index fde92414f567..8370de553c99 100644 --- a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.1.normal.js @@ -38,8 +38,9 @@ var Shapes; ]); return Point; }(); - Shapes1.Point = Point; + // Static member Point.origin = new Point(0, 0); + Shapes1.Point = Point; })(Shapes || (Shapes = {})); // Local variables var p = new Shapes.Point(3, 4); diff --git a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.2.minified.js b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.2.minified.js index 74214f6888ac..5d0f8775256f 100644 --- a/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserErrorRecovery_IncompleteMemberVariable1_es5.2.minified.js @@ -23,5 +23,5 @@ function _defineProperties(target, props) { } ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Point; }(); - Shapes1.Point = Point, Point.origin = new Point(0, 0); + Point.origin = new Point(0, 0), Shapes1.Point = Point; }(Shapes || (Shapes = {})), new Shapes.Point(3, 4).getDist(); diff --git a/crates/swc/tests/tsc-references/parserRealSource12_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserRealSource12_es2015.1.normal.js index 84cb0306afd0..367ec03d1798 100644 --- a/crates/swc/tests/tsc-references/parserRealSource12_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserRealSource12_es2015.1.normal.js @@ -11,8 +11,8 @@ var TypeScript; constructor(){ this.goChildren = true; this.goNextSibling = true; - this.reverseSiblings // visit siblings in reverse execution order - = false; + this.reverseSiblings = false // visit siblings in reverse execution order + ; } } TypeScript1.AstWalkOptions = AstWalkOptions; diff --git a/crates/swc/tests/tsc-references/parserRealSource12_es5.1.normal.js b/crates/swc/tests/tsc-references/parserRealSource12_es5.1.normal.js index 7de0b5d80cf4..abfc708f5867 100644 --- a/crates/swc/tests/tsc-references/parserRealSource12_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserRealSource12_es5.1.normal.js @@ -34,8 +34,8 @@ var TypeScript; _classCallCheck(this, AstWalkOptions); this.goChildren = true; this.goNextSibling = true; - this.reverseSiblings // visit siblings in reverse execution order - = false; + this.reverseSiblings = false // visit siblings in reverse execution order + ; } _createClass(AstWalkOptions, [ { diff --git a/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.1.normal.js index c7425099b6e3..2edc41e8895c 100644 --- a/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.1.normal.js @@ -1,8 +1,7 @@ -var _key; +let _toStringTag = Symbol.toStringTag; //@target: ES6 class C { constructor(){ - this[_key] = ""; + this[_toStringTag] = ""; } } -_key = Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.2.minified.js index bd03ef2d4bce..c562216962fc 100644 --- a/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserSymbolProperty6_es2015.2.minified.js @@ -1,2 +1 @@ -var _key; -_key = Symbol.toStringTag; +Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.1.normal.js b/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.1.normal.js index a56269eb39e0..344d5ba5344f 100644 --- a/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.1.normal.js @@ -3,11 +3,9 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _key; +var _toStringTag = Symbol.toStringTag; var C = function C() { "use strict"; _classCallCheck(this, C); - //@target: ES6 - this[_key] = ""; + this[_toStringTag] = ""; }; -_key = Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.2.minified.js b/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.2.minified.js index f23b96525d86..cad96f9bdab3 100644 --- a/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserSymbolProperty6_es5.2.minified.js @@ -1,7 +1,6 @@ -var _key, C = function() { +var _toStringTag = Symbol.toStringTag, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), this[_key] = ""; + }(this, C), this[_toStringTag] = ""; }; -_key = Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.1.normal.js index c52bbe0f5213..22da0789ed16 100644 --- a/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.1.normal.js @@ -23,7 +23,6 @@ function _classPrivateFieldInit(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } -var _key; var _foo = new WeakMap(), _bar = new WeakMap(); // @strict: true // @target: es6 @@ -37,8 +36,7 @@ class A { writable: true, value: _classPrivateFieldGet(this, _foo) }); - this[_key] // Error (should *not* be private name error) - = this["#baz"]; + this["#baz"] = this["#baz"] // Error (should *not* be private name error) + ; } } -_key = "#baz"; diff --git a/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.2.minified.js index 6d7520cbe6d0..ed16f482a760 100644 --- a/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameCircularReference_es2015.2.minified.js @@ -1,2 +1 @@ -var _key; -new WeakMap(), new WeakMap(), _key = "#baz"; +new WeakMap(), new WeakMap(); diff --git a/crates/swc/tests/tsc-references/privateNameCircularReference_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameCircularReference_es5.1.normal.js index a48b310c78ff..630b753d6024 100644 --- a/crates/swc/tests/tsc-references/privateNameCircularReference_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameCircularReference_es5.1.normal.js @@ -28,7 +28,6 @@ function _classPrivateFieldInit(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } -var _key; var _foo = new WeakMap(), _bar = new WeakMap(); var A = function A() { "use strict"; @@ -41,9 +40,6 @@ var A = function A() { writable: true, value: _classPrivateFieldGet(this, _foo) }); - // @strict: true - // @target: es6 - this[_key] // Error (should *not* be private name error) - = this["#baz"]; + this["#baz"] = this["#baz"] // Error (should *not* be private name error) + ; }; -_key = "#baz"; diff --git a/crates/swc/tests/tsc-references/privateNameCircularReference_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameCircularReference_es5.2.minified.js index 9e8c257a4e9c..c41c0365173b 100644 --- a/crates/swc/tests/tsc-references/privateNameCircularReference_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameCircularReference_es5.2.minified.js @@ -10,7 +10,7 @@ function _classPrivateFieldInit(obj, privateMap, value) { if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }(obj, privateMap), privateMap.set(obj, value); } -var _key, _foo = new WeakMap(), _bar = new WeakMap(), A = function() { +var _foo = new WeakMap(), _bar = new WeakMap(), A = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); @@ -20,6 +20,5 @@ var _key, _foo = new WeakMap(), _bar = new WeakMap(), A = function() { }), _classPrivateFieldInit(this, _bar, { writable: !0, value: _classPrivateFieldGet(this, _foo) - }), this[_key] = this["#baz"]; + }), this["#baz"] = this["#baz"]; }; -_key = "#baz"; diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.1.normal.js index 41cff458c66b..d4e33f2cbdbd 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.1.normal.js @@ -1,4 +1,3 @@ -var _key; // @target: esnext, es2022, es2015 // @useDefineForClassFields: true // @noTypesAndSymbols: true @@ -23,5 +22,4 @@ var _qux2 = { writable: true, value: 42 }; -_key = "bar"; -C3[_key] = "test"; +C3["bar"] = "test"; diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.2.minified.js index 7e7e0edb8a00..38c9ff32e504 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es2015.2.minified.js @@ -1,3 +1,2 @@ -var _key; -_key = "bar", (class { -})[_key] = "test"; +(class { +}).bar = "test"; diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.1.normal.js index 600903b7eb20..9e2dead096b4 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.1.normal.js @@ -17,7 +17,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var _key; var C1 = // @target: esnext, es2022, es2015 // @useDefineForClassFields: true // @noTypesAndSymbols: true @@ -64,5 +63,4 @@ var _qux2 = { writable: true, value: 42 }; -_key = "bar"; -C3[_key] = "test"; +C3["bar"] = "test"; diff --git a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.2.minified.js index 2cda8506961d..6c2772e17bdf 100644 --- a/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameComputedPropertyName4_es5.2.minified.js @@ -10,7 +10,7 @@ function _defineProperties(target, props) { function _createClass(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } -var _key, C1 = function() { +var C1 = function() { "use strict"; function C1() { _classCallCheck(this, C1); @@ -36,4 +36,4 @@ var _key, C1 = function() { "use strict"; _classCallCheck(this, C3); }; -C3[_key = "bar"] = "test"; +C3.bar = "test"; diff --git a/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es2015.1.normal.js index 51ba343f4a96..eb1e0d77a91c 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es2015.1.normal.js @@ -7,7 +7,7 @@ function _classPrivateFieldInit(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } -var _class, _class1; +var _class, _Foo; var _foo = new WeakMap(), _foo2 = new WeakMap(); // @target: es2015 class B { @@ -22,8 +22,8 @@ class B { }); _classPrivateFieldInit(this, _foo2, { writable: true, - value: (_class1 = class Foo { - }, _class1.otherClass = 123, _class1) + value: (_Foo = class Foo { + }, _Foo.otherClass = 123, _Foo) }); } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.1.normal.js index b1de7936af11..b32660f0b04e 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.1.normal.js @@ -12,22 +12,22 @@ function _classPrivateFieldInit(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } -var _class, _class1; +var _class, _Foo; var _foo = new WeakMap(), _foo2 = new WeakMap(); var B = function B() { "use strict"; _classCallCheck(this, B); _classPrivateFieldInit(this, _foo, { writable: true, - value: (_class = function _class2() { - _classCallCheck(this, _class2); + value: (_class = function _class1() { + _classCallCheck(this, _class1); console.log("hello"); }, _class.test = 123, _class) }); _classPrivateFieldInit(this, _foo2, { writable: true, - value: (_class1 = function Foo() { + value: (_Foo = function Foo() { _classCallCheck(this, Foo); - }, _class1.otherClass = 123, _class1) + }, _Foo.otherClass = 123, _Foo) }); }; diff --git a/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.2.minified.js index 8b83e960bc55..9859f2eccba8 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldClassExpression_es5.2.minified.js @@ -6,17 +6,17 @@ function _classPrivateFieldInit(obj, privateMap, value) { if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }(obj, privateMap), privateMap.set(obj, value); } -var _class, _class1, _foo = new WeakMap(), _foo2 = new WeakMap(), B = function() { +var _class, _Foo, _foo = new WeakMap(), _foo2 = new WeakMap(), B = function() { "use strict"; _classCallCheck(this, B), _classPrivateFieldInit(this, _foo, { writable: !0, - value: ((_class = function _class2() { - _classCallCheck(this, _class2), console.log("hello"); + value: ((_class = function _class1() { + _classCallCheck(this, _class1), console.log("hello"); }).test = 123, _class) }), _classPrivateFieldInit(this, _foo2, { writable: !0, - value: ((_class1 = function Foo() { + value: ((_Foo = function Foo() { _classCallCheck(this, Foo); - }).otherClass = 123, _class1) + }).otherClass = 123, _Foo) }); }; diff --git a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.1.normal.js index 0326f3313ad9..217c3882efd9 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.1.normal.js @@ -73,10 +73,12 @@ class C { console.log(_classStaticPrivateFieldSpecSet(this, C, _x, "test")); } constructor(){ + this.a = 123; _classPrivateFieldInit(this, _a, { writable: true, value: 10 }); + this.c = "hello"; _classPrivateFieldInit(this, _b, { writable: true, value: void 0 @@ -85,8 +87,6 @@ class C { writable: true, value: ()=>1234 }); - this.a = 123; - this.c = "hello"; } } var _m = { diff --git a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.2.minified.js index 6a37c01f5073..3fce677c0c8f 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es2015.2.minified.js @@ -38,16 +38,16 @@ class C { console.log((receiver = this, classConstructor = C, descriptor = _m, _classCheckPrivateStaticAccess(receiver, classConstructor), _classCheckPrivateStaticFieldDescriptor(descriptor, "get"), _classApplyDescriptorGet(receiver, descriptor))), console.log((receiver = this, classConstructor = C, descriptor = _x, value = "test", _classCheckPrivateStaticAccess(receiver, classConstructor), _classCheckPrivateStaticFieldDescriptor(descriptor, "set"), _classApplyDescriptorSet(receiver, descriptor, value), value)); } constructor(){ - _classPrivateFieldInit(this, _a, { + this.a = 123, _classPrivateFieldInit(this, _a, { writable: !0, value: 10 - }), _classPrivateFieldInit(this, _b, { + }), this.c = "hello", _classPrivateFieldInit(this, _b, { writable: !0, value: void 0 }), _classPrivateFieldInit(this, _something, { writable: !0, value: ()=>1234 - }), this.a = 123, this.c = "hello"; + }); } } var _m = { diff --git a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.1.normal.js index df7ff69f8c22..bc5a850ee096 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.1.normal.js @@ -85,10 +85,12 @@ var C = // @target: esnext, es2022 "use strict"; function C() { _classCallCheck(this, C); + this.a = 123; _classPrivateFieldInit(this, _a, { writable: true, value: 10 }); + this.c = "hello"; _classPrivateFieldInit(this, _b, { writable: true, value: void 0 @@ -99,8 +101,6 @@ var C = // @target: esnext, es2022 return 1234; } }); - this.a = 123; - this.c = "hello"; } _createClass(C, [ { diff --git a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.2.minified.js index 5b86ca81cb06..c4f7ad0e5670 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldsESNext_es5.2.minified.js @@ -39,10 +39,10 @@ var _a = new WeakMap(), _b = new WeakMap(), _something = new WeakMap(), C = func function C() { !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), _classPrivateFieldInit(this, _a, { + }(this, C), this.a = 123, _classPrivateFieldInit(this, _a, { writable: !0, value: 10 - }), _classPrivateFieldInit(this, _b, { + }), this.c = "hello", _classPrivateFieldInit(this, _b, { writable: !0, value: void 0 }), _classPrivateFieldInit(this, _something, { @@ -50,7 +50,7 @@ var _a = new WeakMap(), _b = new WeakMap(), _something = new WeakMap(), C = func value: function() { return 1234; } - }), this.a = 123, this.c = "hello"; + }); } return Constructor = C, protoProps = [ { diff --git a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.1.normal.js index 321e439dbd42..b8f99f29ee86 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.1.normal.js @@ -3,19 +3,25 @@ function _checkPrivateRedeclaration(obj, privateCollection) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } +function _classPrivateMethodGet(receiver, privateSet, fn) { + if (!privateSet.has(receiver)) { + throw new TypeError("attempted to get private field on non-instance"); + } + return fn; +} function _classPrivateMethodInit(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); } -var _method = new WeakSet(); +var _ref, _method = new WeakSet(); // @target: es2015 class C { constructor(){ _classPrivateMethodInit(this, _method); } } +C.s = _classPrivateMethodGet(_ref = new C(), _method, method).call(_ref); function method() { return 42; } -C.s = new C().#method(); console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.2.minified.js index bf7fd7ab0cd0..28d5c419181f 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es2015.2.minified.js @@ -1,4 +1,4 @@ -var _method = new WeakSet(); +var _ref, _method = new WeakSet(); class C { constructor(){ !function(obj, privateSet) { @@ -8,4 +8,9 @@ class C { }(this, _method); } } -C.s = new C().#method(), console.log(C.s); +C.s = (function(receiver, privateSet, fn) { + if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance"); + return fn; +})(_ref = new C(), _method, function() { + return 42; +}).call(_ref), console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.1.normal.js index 59cfb80afe91..387d779c03d1 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.1.normal.js @@ -8,18 +8,24 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _classPrivateMethodGet(receiver, privateSet, fn) { + if (!privateSet.has(receiver)) { + throw new TypeError("attempted to get private field on non-instance"); + } + return fn; +} function _classPrivateMethodInit(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); } -var _method = new WeakSet(); +var _ref, _method = new WeakSet(); var C = function C() { "use strict"; _classCallCheck(this, C); _classPrivateMethodInit(this, _method); }; +C.s = _classPrivateMethodGet(_ref = new C(), _method, method).call(_ref); function method() { return 42; } -C.s = new C().#method(); console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.2.minified.js index 201e05bf4faa..39707f362700 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameMethodInStaticFieldInit_es5.2.minified.js @@ -1,4 +1,4 @@ -var _method = new WeakSet(), C = function() { +var _ref, _method = new WeakSet(), C = function() { "use strict"; var obj, privateSet; !function(instance, Constructor) { @@ -7,4 +7,9 @@ var _method = new WeakSet(), C = function() { if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object"); })(obj, privateSet = _method), privateSet.add(obj); }; -C.s = new C().#method(), console.log(C.s); +C.s = (function(receiver, privateSet, fn) { + if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance"); + return fn; +})(_ref = new C(), _method, function() { + return 42; +}).call(_ref), console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.1.normal.js index 7e0e1c5fbd32..f776391cd8c4 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.1.normal.js @@ -19,7 +19,7 @@ function _classCheckPrivateStaticAccess(receiver, classConstructor) { throw new TypeError("Private static access of wrong provenance"); } } -var _class, _class1; +var _class, _Foo; // @target: es2015 class B { m() { @@ -40,6 +40,6 @@ var _foo = { }; var _foo2 = { writable: true, - value: (_class1 = class Foo { - }, _class1.otherClass = 123, _class1) + value: (_Foo = class Foo { + }, _Foo.otherClass = 123, _Foo) }; diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.2.minified.js index 488aee21cf43..a0f616cfce78 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es2015.2.minified.js @@ -12,7 +12,7 @@ class B { console.log(_classStaticPrivateFieldSpecGet(B, B, _foo).test), _classStaticPrivateFieldSpecGet(B, B, _foo).test = 10, new (_classStaticPrivateFieldSpecGet(B, B, _foo))().field; } } -var _class, _class1, _foo = { +var _class, _Foo, _foo = { writable: !0, value: ((_class = class { constructor(){ @@ -21,6 +21,6 @@ var _class, _class1, _foo = { }).test = 123, _class) }, _foo2 = { writable: !0, - value: ((_class1 = class { - }).otherClass = 123, _class1) + value: ((_Foo = class { + }).otherClass = 123, _Foo) }; diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.1.normal.js index 2a37251adce1..c2ac910b2bd6 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.1.normal.js @@ -38,7 +38,7 @@ function _classCheckPrivateStaticAccess(receiver, classConstructor) { throw new TypeError("Private static access of wrong provenance"); } } -var _class, _class1; +var _class, _Foo; var B = // @target: es2015 /*#__PURE__*/ function() { "use strict"; @@ -59,9 +59,9 @@ var B = // @target: es2015 }(); var _foo = { writable: true, - value: (_class = function _class2() { + value: (_class = function _class1() { "use strict"; - _classCallCheck(this, _class2); + _classCallCheck(this, _class1); this.field = 10; console.log("hello"); new (_classStaticPrivateFieldSpecGet(B, B, _foo2))(); @@ -69,8 +69,8 @@ var _foo = { }; var _foo2 = { writable: true, - value: (_class1 = function Foo() { + value: (_Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - }, _class1.otherClass = 123, _class1) + }, _Foo.otherClass = 123, _Foo) }; diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.2.minified.js index c183cf3a2d5b..f059c55e28ab 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldClassExpression_es5.2.minified.js @@ -16,7 +16,7 @@ function _defineProperties(target, props) { function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) throw new TypeError("Private static access of wrong provenance"); } -var _class, _class1, B = function() { +var _class, _Foo, B = function() { "use strict"; var Constructor, protoProps, staticProps; function B() { @@ -32,14 +32,14 @@ var _class, _class1, B = function() { ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), B; }(), _foo = { writable: !0, - value: ((_class = function _class2() { + value: ((_class = function _class1() { "use strict"; - _classCallCheck(this, _class2), this.field = 10, console.log("hello"), new (_classStaticPrivateFieldSpecGet(B, B, _foo2))(); + _classCallCheck(this, _class1), this.field = 10, console.log("hello"), new (_classStaticPrivateFieldSpecGet(B, B, _foo2))(); }).test = 123, _class) }, _foo2 = { writable: !0, - value: ((_class1 = function Foo() { + value: ((_Foo = function Foo() { "use strict"; _classCallCheck(this, Foo); - }).otherClass = 123, _class1) + }).otherClass = 123, _Foo) }; diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es2015.1.normal.js index f93a380495d8..eea5c42eb0f1 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es2015.1.normal.js @@ -30,8 +30,8 @@ class AA { return AA; } } +AA.x = 1; function method() { this.x = 10; } function method2(a, ...b) {} -AA.x = 1; diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es5.1.normal.js index 6deb811a0adf..a710c09752f8 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodCallExpression_es5.1.normal.js @@ -185,6 +185,7 @@ var AA = // @target: es2015 ]); return AA; }(); +AA.x = 1; function method() { this.x = 10; } @@ -193,4 +194,3 @@ function method2(a) { b[_key - 1] = arguments[_key]; } } -AA.x = 1; diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.1.normal.js index e5828ee0efa7..21cd29888665 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.1.normal.js @@ -1,8 +1,17 @@ +function _classStaticPrivateMethodGet(receiver, classConstructor, method1) { + _classCheckPrivateStaticAccess(receiver, classConstructor); + return method1; +} +function _classCheckPrivateStaticAccess(receiver, classConstructor) { + if (receiver !== classConstructor) { + throw new TypeError("Private static access of wrong provenance"); + } +} // @target: es2015 class C { } +C.s = _classStaticPrivateMethodGet(C, C, method).call(C); function method() { return 42; } -C.s = C.#method(); console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.2.minified.js index c96c514ac153..c037f5a18716 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es2015.2.minified.js @@ -1,3 +1,9 @@ class C { } -C.s = C.#method(), console.log(C.s); +C.s = (function(receiver, classConstructor, method) { + return (function(receiver, classConstructor) { + if (receiver !== classConstructor) throw new TypeError("Private static access of wrong provenance"); + })(receiver, classConstructor), method; +})(C, C, function() { + return 42; +}).call(C), console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.1.normal.js index f16a7a19d536..8930296ede51 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.1.normal.js @@ -3,12 +3,21 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _classStaticPrivateMethodGet(receiver, classConstructor, method1) { + _classCheckPrivateStaticAccess(receiver, classConstructor); + return method1; +} +function _classCheckPrivateStaticAccess(receiver, classConstructor) { + if (receiver !== classConstructor) { + throw new TypeError("Private static access of wrong provenance"); + } +} var C = function C() { "use strict"; _classCallCheck(this, C); }; +C.s = _classStaticPrivateMethodGet(C, C, method).call(C); function method() { return 42; } -C.s = C.#method(); console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.2.minified.js index 3b8d1414eee4..7da7257bf1f8 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodInStaticFieldInit_es5.2.minified.js @@ -4,4 +4,10 @@ var C = function() { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); }(this, C); }; -C.s = C.#method(), console.log(C.s); +C.s = (function(receiver, classConstructor, method) { + return (function(receiver, classConstructor) { + if (receiver !== classConstructor) throw new TypeError("Private static access of wrong provenance"); + })(receiver, classConstructor), method; +})(C, C, function() { + return 42; +}).call(C), console.log(C.s); diff --git a/crates/swc/tests/tsc-references/privateNamesAndkeyof_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAndkeyof_es5.1.normal.js index e5b593dbcd29..42ec40abb228 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndkeyof_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAndkeyof_es5.1.normal.js @@ -29,8 +29,6 @@ var A = function A() { writable: true, value: 3 }); - // @strict: true - // @target: es6 this.bar = 3; this.baz = 3; }; diff --git a/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es2015.1.normal.js index db94554c5da4..0962ca6c15ad 100644 --- a/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es2015.1.normal.js @@ -3,9 +3,10 @@ class Base { class Derived extends Base { constructor(...args){ super(...args); - this.bing // error - = ()=>Base.foo + this.bing = ()=>Base.foo + // error ; } } -Derived.bar = Base.foo; +Derived.bar = Base.foo // error +; diff --git a/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es5.1.normal.js b/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es5.1.normal.js index 5d4c41fb5e65..ce271384ae1b 100644 --- a/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateStaticMemberAccessibility_es5.1.normal.js @@ -81,12 +81,13 @@ var Derived = /*#__PURE__*/ function(Base1) { _classCallCheck(this, Derived); var _this; _this = _super.apply(this, arguments); - _this.bing // error - = function() { + _this.bing = function() { return Base.foo; - }; + } // error + ; return _this; } return Derived; }(Base); -Derived.bar = Base.foo; +Derived.bar = Base.foo // error +; diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es2015.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es2015.1.normal.js index e8fb3cf7d5bb..051d9872d02f 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es2015.1.normal.js @@ -20,8 +20,8 @@ a.makeSound() // 'rustling noise in the bushes' class Lion extends Animal { constructor(...args){ super(...args); - this.sound // error here - = 'RAWR!'; + this.sound = 'RAWR!' // error here + ; } } const lion = new Lion; diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es5.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es5.1.normal.js index cbf24374c807..23a787d38660 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors3_es5.1.normal.js @@ -121,8 +121,8 @@ var Lion = /*#__PURE__*/ function(Animal) { _classCallCheck(this, Lion); var _this; _this = _super.apply(this, arguments); - _this.sound // error here - = 'RAWR!'; + _this.sound = 'RAWR!' // error here + ; return _this; } return Lion; diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es2015.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es2015.1.normal.js index cb5671143e07..9fb0ba6bb127 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es2015.1.normal.js @@ -1,7 +1,7 @@ class Lion extends Animal { constructor(...args){ super(...args); - this.sound // error here - = 'RAWR!'; + this.sound = 'RAWR!' // error here + ; } } diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es5.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es5.1.normal.js index 88b8916069a2..186c792d9660 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors4_es5.1.normal.js @@ -77,8 +77,8 @@ var Lion = /*#__PURE__*/ function(Animal) { _classCallCheck(this, Lion); var _this; _this = _super.apply(this, arguments); - _this.sound // error here - = 'RAWR!'; + _this.sound = 'RAWR!' // error here + ; return _this; } return Lion; diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors_es2015.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors_es2015.1.normal.js index 4beac2c5c2ed..0f466d99065c 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors_es2015.1.normal.js @@ -8,8 +8,8 @@ class A { class B extends A { constructor(...args){ super(...args); - this.p // error - = 'yep'; + this.p = 'yep' // error + ; } } class C { @@ -26,7 +26,7 @@ class C { class D extends C { constructor(...args){ super(...args); - this.p // error - = 101; + this.p = 101 // error + ; } } diff --git a/crates/swc/tests/tsc-references/propertyOverridesAccessors_es5.1.normal.js b/crates/swc/tests/tsc-references/propertyOverridesAccessors_es5.1.normal.js index dc1bfdb9368b..3a3029f70ea5 100644 --- a/crates/swc/tests/tsc-references/propertyOverridesAccessors_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/propertyOverridesAccessors_es5.1.normal.js @@ -108,8 +108,8 @@ var B = /*#__PURE__*/ function(A) { _classCallCheck(this, B); var _this; _this = _super.apply(this, arguments); - _this.p // error - = 'yep'; + _this.p = 'yep' // error + ; return _this; } return B; @@ -141,8 +141,8 @@ var D = /*#__PURE__*/ function(C) { _classCallCheck(this, D); var _this; _this = _super.apply(this, arguments); - _this.p // error - = 101; + _this.p = 101 // error + ; return _this; } return D; diff --git a/crates/swc/tests/tsc-references/redeclaredProperty_es5.1.normal.js b/crates/swc/tests/tsc-references/redeclaredProperty_es5.1.normal.js index 491a7b04c9e8..76bbde8fdb6c 100644 --- a/crates/swc/tests/tsc-references/redeclaredProperty_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/redeclaredProperty_es5.1.normal.js @@ -72,10 +72,6 @@ function _createSuper(Derived1) { var Base = function Base() { "use strict"; _classCallCheck(this, Base); - // @noTypesAndSymbols: true - // @strictNullChecks: true - // @target: esnext - // @useDefineForClassFields: true this.b = 1; }; var Derived = /*#__PURE__*/ function(Base) { diff --git a/crates/swc/tests/tsc-references/redefinedPararameterProperty_es5.1.normal.js b/crates/swc/tests/tsc-references/redefinedPararameterProperty_es5.1.normal.js index 775ac944c95f..0eb47a7a7075 100644 --- a/crates/swc/tests/tsc-references/redefinedPararameterProperty_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/redefinedPararameterProperty_es5.1.normal.js @@ -72,10 +72,6 @@ function _createSuper(Derived1) { var Base = function Base() { "use strict"; _classCallCheck(this, Base); - // @noTypesAndSymbols: true - // @strictNullChecks: true - // @target: esnext - // @useDefineForClassFields: true this.a = 1; }; var Derived = /*#__PURE__*/ function(Base) { diff --git a/crates/swc/tests/tsc-references/staticIndexSignature7_es2015.1.normal.js b/crates/swc/tests/tsc-references/staticIndexSignature7_es2015.1.normal.js index 39a0fdb4776f..850a77947927 100644 --- a/crates/swc/tests/tsc-references/staticIndexSignature7_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/staticIndexSignature7_es2015.1.normal.js @@ -1,7 +1,8 @@ // @strict: true class X { } -X.x = 12; +X.x = 12 // Should error, incompatible with index signature +; class Y { static foo() {} } diff --git a/crates/swc/tests/tsc-references/staticIndexSignature7_es5.1.normal.js b/crates/swc/tests/tsc-references/staticIndexSignature7_es5.1.normal.js index 4ace8f5c34e7..65995ef15567 100644 --- a/crates/swc/tests/tsc-references/staticIndexSignature7_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/staticIndexSignature7_es5.1.normal.js @@ -21,7 +21,8 @@ var X = function X() { "use strict"; _classCallCheck(this, X); }; -X.x = 12; +X.x = 12 // Should error, incompatible with index signature +; var Y = /*#__PURE__*/ function() { "use strict"; function Y() { diff --git a/crates/swc/tests/tsc-references/strictPropertyInitialization_es2015.1.normal.js b/crates/swc/tests/tsc-references/strictPropertyInitialization_es2015.1.normal.js index 2766d2efef12..e7a57a45a7ed 100644 --- a/crates/swc/tests/tsc-references/strictPropertyInitialization_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/strictPropertyInitialization_es2015.1.normal.js @@ -70,6 +70,9 @@ var _d = new WeakMap(), _e = new WeakMap(), _f1 = new WeakMap(); // Initializer satisfies strict initialization check class C4 { constructor(){ + this.a = 0; + this.b = 0; + this.c = "abc"; _classPrivateFieldInit(this, _d, { writable: true, value: 0 @@ -82,9 +85,6 @@ class C4 { writable: true, value: "abc" }); - this.a = 0; - this.b = 0; - this.c = "abc"; } } var _b = new WeakMap(); diff --git a/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.1.normal.js b/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.1.normal.js index 88d6a0e0aa80..463348f9b359 100644 --- a/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.1.normal.js @@ -72,6 +72,9 @@ var _d = new WeakMap(), _e = new WeakMap(), _f1 = new WeakMap(); var C4 = function C4() { "use strict"; _classCallCheck(this, C4); + this.a = 0; + this.b = 0; + this.c = "abc"; _classPrivateFieldInit(this, _d, { writable: true, value: 0 @@ -84,10 +87,6 @@ var C4 = function C4() { writable: true, value: "abc" }); - // Initializer satisfies strict initialization check - this.a = 0; - this.b = 0; - this.c = "abc"; }; var _b = new WeakMap(); var C5 = function C5() { diff --git a/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.2.minified.js b/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.2.minified.js index 392634a5b692..f60570d2e78a 100644 --- a/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/strictPropertyInitialization_es5.2.minified.js @@ -40,7 +40,7 @@ var _f = new WeakMap(), _g = new WeakMap(), _h = new WeakMap(), _i = new WeakMap _classCallCheck(this, C3); }, _d = new WeakMap(), _e = new WeakMap(), _f1 = new WeakMap(), C4 = function() { "use strict"; - _classCallCheck(this, C4), _classPrivateFieldInit(this, _d, { + _classCallCheck(this, C4), this.a = 0, this.b = 0, this.c = "abc", _classPrivateFieldInit(this, _d, { writable: !0, value: 0 }), _classPrivateFieldInit(this, _e, { @@ -49,7 +49,7 @@ var _f = new WeakMap(), _g = new WeakMap(), _h = new WeakMap(), _i = new WeakMap }), _classPrivateFieldInit(this, _f1, { writable: !0, value: "abc" - }), this.a = 0, this.b = 0, this.c = "abc"; + }); }, _b = new WeakMap(), C5 = function() { "use strict"; _classCallCheck(this, C5), _classPrivateFieldInit(this, _b, { diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.1.normal.js index 34af2e57d184..3c103b19df04 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} class Reflect1 { } // @target: es5, es2015, es2021, es2022, esnext @@ -11,6 +40,60 @@ class _class { export { _class as default }; class C extends B { } +C._ = [ + (()=>{ + var Reflect; // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + var { Reflect } = { + Reflect: null + }; // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + var [Reflect] = [ + null + ]; // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + class Reflect { + } // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + function Reflect() {} // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + let Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + (class Reflect { + }); // no collision + _get(_getPrototypeOf(C), "w", C).call(C); + })(), + (()=>{ + (function Reflect() {}); // no collision + _get(_getPrototypeOf(C), "w", C).call(C); + })(), +]; var __32 = { writable: true, value: (()=>{ @@ -98,76 +181,22 @@ var __10 = { super.w(); })() }; -C._ = [ - (()=>{ - var Reflect; // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - var { Reflect } = { - Reflect: null - }; // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - var [Reflect] = [ - null - ]; // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - class Reflect { - } // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - function Reflect() {} // collision (es2015-es2021 only) - super.w(); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - super.w(); - })(), - (()=>{ - let Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - super.w(); - })(), - (()=>{ - super.w(); - })(), - (()=>{ - super.w(); - })(), - (()=>{ - (class Reflect { - }); // no collision - super.w(); - })(), - (()=>{ - (function Reflect() {}); // no collision - super.w(); - })(), -]; var Reflect1 = null; // collision (es2015-es2021 only) class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var { Reflect: Reflect1 } = { Reflect: null }; // collision (es2015-es2021 only) class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var [Reflect1] = [ null ]; // collision (es2015-es2021 only) class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = null; // collision (es2015-es2021 only) class C extends B { } @@ -203,7 +232,7 @@ class Reflect1 { } // collision (es2015-es2021 only) class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class Reflect1 { } // collision (es2015-es2021 only) class C extends B { @@ -217,7 +246,7 @@ var __14 = { function Reflect1() {} // collision (es2015-es2021 only) class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); function Reflect1() {} // collision (es2015-es2021 only) class C extends B { } @@ -229,7 +258,7 @@ var __15 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __16 = { @@ -241,7 +270,7 @@ var __16 = { (function(Reflect1) {})(Reflect1 || (Reflect1 = {})); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function(Reflect1) {})(Reflect1 || (Reflect1 = {})); class C extends B { } @@ -254,7 +283,7 @@ var __17 = { (function(Reflect1) {})(Reflect1 || (Reflect1 = {})); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function(Reflect1) {})(Reflect1 || (Reflect1 = {})); class C extends B { } @@ -266,7 +295,7 @@ var __18 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __19 = { @@ -277,7 +306,7 @@ var __19 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __20 = { @@ -288,7 +317,7 @@ var __20 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __21 = { @@ -299,7 +328,7 @@ var __21 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __22 = { @@ -310,7 +339,7 @@ var __22 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __23 = { @@ -321,7 +350,7 @@ var __23 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __24 = { @@ -332,7 +361,7 @@ var __24 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __25 = { @@ -343,7 +372,7 @@ var __25 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __26 = { @@ -354,7 +383,7 @@ var __26 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __27 = { @@ -365,7 +394,7 @@ var __27 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __28 = { @@ -376,7 +405,7 @@ var __28 = { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } var __29 = { @@ -389,7 +418,7 @@ var __29 = { }); // no collision class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (class Reflect { }); // no collision class C extends B { @@ -406,7 +435,7 @@ _Reflect = class Reflect { value: (()=>{ class C1 extends B { } - C1._ = super.w(); + C1._ = _get(_getPrototypeOf(C1), "w", C1).call(C1); })() }, _Reflect; _Reflect = class Reflect { @@ -427,7 +456,7 @@ _Reflect = class Reflect { (function Reflect() {}); // no collision class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function Reflect() {}); // no collision class C extends B { } @@ -438,15 +467,15 @@ var __31 = { })() }; (function Reflect() { + var _Reflect, __; class C2 extends B { } - C2._ = super.w(); + C2._ = _get(_getPrototypeOf(C2), "w", C2).call(C2); }); (function Reflect() { - var _Reflect, __; class C extends B { } - var __34 = { + var __ = { writable: true, value: (()=>{ super.w(); diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.2.minified.js b/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.2.minified.js index 4a4c975f9773..ed548d2859a5 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1_es2015.2.minified.js @@ -1,68 +1,87 @@ -export class Reflect { -} +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} +class Reflect1 { +} +export { Reflect1 as Reflect }; export var Baz; class _class { } class C extends B { } -(()=>{ - var { Reflect } = { - Reflect: null - }; - super.w(); -})(), (()=>{ - var [Reflect] = [ - null - ]; - super.w(); -})(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), C._ = [ - void super.w(), +C._ = [ + void _get(_getPrototypeOf(C), "w", C).call(C), (()=>{ var { Reflect } = { Reflect: null }; - super.w(); + _get(_getPrototypeOf(C), "w", C).call(C); })(), (()=>{ var [Reflect] = [ null ]; - super.w(); + _get(_getPrototypeOf(C), "w", C).call(C); })(), - void super.w(), - void super.w(), - void super.w(), - void super.w(), - void super.w(), - void super.w(), - void super.w(), - void super.w(), -]; + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), +], (()=>{ + var { Reflect } = { + Reflect: null + }; + super.w(); +})(), (()=>{ + var [Reflect] = [ + null + ]; + super.w(); +})(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(), super.w(); class C extends B { } -C._ = super.w(); -var { Reflect } = { +C._ = _get(_getPrototypeOf(C), "w", C).call(C); +var { Reflect: Reflect1 } = { Reflect: null }; class C extends B { } -C._ = super.w(); -var [Reflect] = [ +C._ = _get(_getPrototypeOf(C), "w", C).call(C); +var [Reflect1] = [ null ]; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); -var { Reflect } = { +var { Reflect: Reflect1 } = { Reflect: null }; class C extends B { } super.w(); -var [Reflect] = [ +var [Reflect1] = [ null ]; class C extends B { @@ -70,110 +89,113 @@ class C extends B { super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(), _Reflect = class { }, __ = { writable: !0, - value: void ((class extends B { - })._ = super.w()) + value: (()=>{ + class C1 extends B { + } + C1._ = _get(_getPrototypeOf(C1), "w", C1).call(C1); + })() }, _Reflect = class { }, __ = { writable: !0, @@ -184,7 +206,7 @@ super.w(), _Reflect = class { }; class C extends B { } -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); class C extends B { } super.w(); diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1_es5.1.normal.js b/crates/swc/tests/tsc-references/superInStaticMembers1_es5.1.normal.js index bc0793f1056f..00ce642a96f2 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1_es5.1.normal.js @@ -9,6 +9,22 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -41,6 +57,13 @@ function _setPrototypeOf(o, p) { }; return _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; @@ -96,6 +119,63 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); +C._ = [ + function() { + var Reflect; // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + var Reflect = { + Reflect: null + }.Reflect; // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + var Reflect = null; // collision (es2015-es2021 only) + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + var Reflect = function Reflect() { + "use strict"; + _classCallCheck(this, Reflect); + }; + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + var Reflect = function Reflect() {} // collision (es2015-es2021 only) + ; + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + var Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + var Reflect// collision (es2015-es2021 only) + ; + (function(Reflect) {})(Reflect || (Reflect = {})); + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + (function Reflect() { + "use strict"; + _classCallCheck(this, Reflect); + }); // no collision + _get(_getPrototypeOf(C), "w", C).call(C); + }(), + function() { + (function Reflect() {}); // no collision + _get(_getPrototypeOf(C), "w", C).call(C); + }(), +]; var _$__22 = { writable: true, value: function() { @@ -186,63 +266,6 @@ var __10 = { _superprop_get_w().call(_this); }() }; -C._ = [ - function() { - var Reflect; // collision (es2015-es2021 only) - _superprop_get_w().call(_this); - }(), - function() { - var Reflect = { - Reflect: null - }.Reflect; // collision (es2015-es2021 only) - _superprop_get_w().call(_this); - }(), - function() { - var Reflect = null; // collision (es2015-es2021 only) - _superprop_get_w().call(_this); - }(), - function() { - var Reflect = function Reflect() { - "use strict"; - _classCallCheck(this, Reflect); - }; - _superprop_get_w().call(_this); - }(), - function() { - var Reflect = function Reflect() {} // collision (es2015-es2021 only) - ; - _superprop_get_w().call(_this); - }(), - function() { - var Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _superprop_get_w().call(_this); - }(), - function() { - var Reflect// collision (es2015-es2021 only) - ; - (function(Reflect) {})(Reflect || (Reflect = {})); - _superprop_get_w().call(_this); - }(), - function() { - _superprop_get_w().call(_this); - }(), - function() { - _superprop_get_w().call(_this); - }(), - function() { - (function Reflect() { - "use strict"; - _classCallCheck(this, Reflect); - }); // no collision - _superprop_get_w().call(_this); - }(), - function() { - (function Reflect() {}); // no collision - _superprop_get_w().call(_this); - }(), -]; var Reflect1 = null; // collision (es2015-es2021 only) var C = /*#__PURE__*/ function(B) { "use strict"; @@ -254,7 +277,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = { Reflect: null }.Reflect; // collision (es2015-es2021 only) @@ -268,7 +291,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = null; // collision (es2015-es2021 only) var C = /*#__PURE__*/ function(B) { "use strict"; @@ -280,7 +303,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = null; // collision (es2015-es2021 only) var C = /*#__PURE__*/ function(B) { "use strict"; @@ -348,7 +371,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = function Reflect1() { "use strict"; _classCallCheck(this, Reflect1); @@ -380,7 +403,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); function Reflect1() {} // collision (es2015-es2021 only) var C = /*#__PURE__*/ function(B) { "use strict"; @@ -408,7 +431,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -436,7 +459,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function(Reflect1) {})(Reflect1 || (Reflect1 = {})); var C = /*#__PURE__*/ function(B) { "use strict"; @@ -465,7 +488,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function(Reflect1) {})(Reflect1 || (Reflect1 = {})); var C = /*#__PURE__*/ function(B) { "use strict"; @@ -493,7 +516,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -520,7 +543,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -547,7 +570,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -574,7 +597,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -601,7 +624,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -628,7 +651,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -655,7 +678,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -682,7 +705,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -709,7 +732,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -736,7 +759,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -763,7 +786,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -794,7 +817,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function Reflect() { "use strict"; _classCallCheck(this, Reflect); @@ -831,7 +854,7 @@ _$_Reflect = function Reflect() { } return C; }(B); - C._ = _superprop_get_w().call(_this); + C._ = _get(_getPrototypeOf(C), "w", C).call(C); })() }, _$_Reflect; _$_Reflect = function Reflect() { @@ -872,7 +895,7 @@ var C = /*#__PURE__*/ function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); (function Reflect() {}); // no collision var C = /*#__PURE__*/ function(B) { "use strict"; @@ -891,6 +914,7 @@ var _$__21 = { }() }; (function Reflect() { + var _$_Reflect, _$__; var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -901,12 +925,11 @@ var _$__21 = { } return C; }(B); - C._ = super.w(); + C._ = _get(_getPrototypeOf(C), "w", C).call(C); }); (function Reflect() { var _this2 = this, _superprop_get_w2 = ()=>super.w ; - var _$_Reflect, _$__; var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -917,7 +940,7 @@ var _$__21 = { } return C; }(B); - var _$__24 = { + var _$__ = { writable: true, value: function() { _superprop_get_w2().call(_this2); diff --git a/crates/swc/tests/tsc-references/superInStaticMembers1_es5.2.minified.js b/crates/swc/tests/tsc-references/superInStaticMembers1_es5.2.minified.js index a46e7055be60..aa911a16ac88 100644 --- a/crates/swc/tests/tsc-references/superInStaticMembers1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/superInStaticMembers1_es5.2.minified.js @@ -1,6 +1,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} function _getPrototypeOf(o) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -21,6 +30,10 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} function _createSuper(Derived) { var hasNativeReflectConstruct = function() { if ("undefined" == typeof Reflect || !Reflect.construct) return !1; @@ -64,31 +77,31 @@ var C = function(B) { } return C; }(B); -_superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), (function() { - var Reflect = function() { - "use strict"; - _classCallCheck(this, Reflect); - }; - _superprop_get_w().call(_this); -})(), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), C._ = [ - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), +C._ = [ + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), function() { var Reflect = function() { "use strict"; _classCallCheck(this, Reflect); }; - _superprop_get_w().call(_this); + _get(_getPrototypeOf(C), "w", C).call(C); }(), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), - void _superprop_get_w().call(_this), -]; + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), + void _get(_getPrototypeOf(C), "w", C).call(C), +], _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), (function() { + var Reflect = function() { + "use strict"; + _classCallCheck(this, Reflect); + }; + _superprop_get_w().call(_this); +})(), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this), _superprop_get_w().call(_this); var Reflect1 = null, C = function(B) { "use strict"; _inherits(C, B); @@ -98,7 +111,7 @@ var Reflect1 = null, C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = null, C = function(B) { "use strict"; _inherits(C, B); @@ -108,7 +121,7 @@ var Reflect1 = null, C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = null, C = function(B) { "use strict"; _inherits(C, B); @@ -118,7 +131,7 @@ var Reflect1 = null, C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = null, C = function(B) { "use strict"; _inherits(C, B); @@ -161,7 +174,7 @@ var Reflect1 = function() { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var Reflect1 = function() { "use strict"; _classCallCheck(this, Reflect1); @@ -186,7 +199,7 @@ var C = function(B) { return C; }(B); function Reflect1() {} -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -206,7 +219,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -226,7 +239,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -246,7 +259,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -266,7 +279,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -286,7 +299,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -306,7 +319,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -326,7 +339,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -346,7 +359,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -366,7 +379,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -386,7 +399,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -406,7 +419,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -426,7 +439,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -446,7 +459,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -466,7 +479,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -486,7 +499,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); @@ -511,7 +524,7 @@ _superprop_get_w().call(_this), _$_Reflect = function Reflect() { } return C; }(B); - C._ = _superprop_get_w().call(_this); + C._ = _get(_getPrototypeOf(C), "w", C).call(C); })() }, _$_Reflect = function Reflect() { "use strict"; @@ -540,7 +553,7 @@ var C = function(B) { } return C; }(B); -C._ = super.w(); +C._ = _get(_getPrototypeOf(C), "w", C).call(C); var C = function(B) { "use strict"; _inherits(C, B); diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.1.normal.js index f6b06db7c901..4c2c74e960d9 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.1.normal.js @@ -1,12 +1,11 @@ -var _key; -let tmp = (_key = Symbol.iterator, Symbol.isConcatSpreadable), _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive; +let _iterator = Symbol.iterator, _isConcatSpreadable = Symbol.isConcatSpreadable, _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive; //@target: ES6 //@declaration: true class C { - static [tmp]() {} + static [_isConcatSpreadable]() {} static get [_toPrimitive]() { return ""; } static set [_toPrimitive1](x) {} } -C[_key] = 0; +C[_iterator] = 0; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.2.minified.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.2.minified.js index 82aa0625a05a..cd97cf95fe69 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es2015.2.minified.js @@ -1,9 +1,8 @@ -var _key; -let tmp = (_key = Symbol.iterator, Symbol.isConcatSpreadable), _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive; +let _iterator = Symbol.iterator, _isConcatSpreadable = Symbol.isConcatSpreadable, _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive; (class { - static [tmp]() {} + static [_isConcatSpreadable]() {} static get [_toPrimitive]() { return ""; } static set [_toPrimitive1](x) {} -})[_key] = 0; +})[_iterator] = 0; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.1.normal.js index e3ae152053f9..86e644d3ea9f 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.1.normal.js @@ -17,8 +17,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var _key; -var tmp = (_key = Symbol.iterator, Symbol.isConcatSpreadable), _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive; +var _iterator = Symbol.iterator, _isConcatSpreadable = Symbol.isConcatSpreadable, _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive; var C = //@target: ES6 //@declaration: true /*#__PURE__*/ function() { @@ -28,7 +27,7 @@ var C = //@target: ES6 } _createClass(C, null, [ { - key: tmp, + key: _isConcatSpreadable, value: function value() {} }, { @@ -44,4 +43,4 @@ var C = //@target: ES6 ]); return C; }(); -C[_key] = 0; +C[_iterator] = 0; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.2.minified.js index a1fe60c1c9fd..19358979dcc0 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit11_es5.2.minified.js @@ -4,7 +4,7 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var _key, tmp = (_key = Symbol.iterator, Symbol.isConcatSpreadable), _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive, C = function() { +var _iterator = Symbol.iterator, _isConcatSpreadable = Symbol.isConcatSpreadable, _toPrimitive = Symbol.toPrimitive, _toPrimitive1 = Symbol.toPrimitive, C = function() { "use strict"; var Constructor, protoProps, staticProps; function C() { @@ -14,7 +14,7 @@ var _key, tmp = (_key = Symbol.iterator, Symbol.isConcatSpreadable), _toPrimitiv } return Constructor = C, protoProps = null, staticProps = [ { - key: tmp, + key: _isConcatSpreadable, value: function() {} }, { @@ -29,4 +29,4 @@ var _key, tmp = (_key = Symbol.iterator, Symbol.isConcatSpreadable), _toPrimitiv } ], protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; }(); -C[_key] = 0; +C[_iterator] = 0; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.1.normal.js index 69de5eb4a300..a0e87dee76b6 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.1.normal.js @@ -1,9 +1,8 @@ -var _key; +let _toPrimitive = Symbol.toPrimitive; //@target: ES6 //@declaration: true class C { constructor(){ - this[_key] = ""; + this[_toPrimitive] = ""; } } -_key = Symbol.toPrimitive; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.2.minified.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.2.minified.js index 0209e68be63c..e648971c4786 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es2015.2.minified.js @@ -1,2 +1 @@ -var _key; -_key = Symbol.toPrimitive; +Symbol.toPrimitive; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.1.normal.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.1.normal.js index 9f945a7d3dec..001ef2aeed20 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.1.normal.js @@ -3,12 +3,9 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } -var _key; +var _toPrimitive = Symbol.toPrimitive; var C = function C() { "use strict"; _classCallCheck(this, C); - //@target: ES6 - //@declaration: true - this[_key] = ""; + this[_toPrimitive] = ""; }; -_key = Symbol.toPrimitive; diff --git a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.2.minified.js index 6fc26017be33..87c5e5297914 100644 --- a/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolDeclarationEmit2_es5.2.minified.js @@ -1,7 +1,6 @@ -var _key, C = function() { +var _toPrimitive = Symbol.toPrimitive, C = function() { "use strict"; !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), this[_key] = ""; + }(this, C), this[_toPrimitive] = ""; }; -_key = Symbol.toPrimitive; diff --git a/crates/swc/tests/tsc-references/symbolProperty6_es2015.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty6_es2015.1.normal.js index 5658569e753e..6a10aaf63f74 100644 --- a/crates/swc/tests/tsc-references/symbolProperty6_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty6_es2015.1.normal.js @@ -1,12 +1,11 @@ -var _key; -let tmp = (_key = Symbol.iterator, Symbol.toPrimitive), _toStringTag = Symbol.toStringTag; +let _iterator = Symbol.iterator, _toPrimitive = Symbol.toPrimitive, _toStringTag = Symbol.toStringTag; //@target: ES6 class C { - [tmp]() {} + [_toPrimitive]() {} get [_toStringTag]() { return 0; } constructor(){ - this[_key] = 0; + this[_iterator] = 0; } } diff --git a/crates/swc/tests/tsc-references/symbolProperty6_es2015.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty6_es2015.2.minified.js index 8fbb2f5eae1f..b9802cab444f 100644 --- a/crates/swc/tests/tsc-references/symbolProperty6_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty6_es2015.2.minified.js @@ -1,2 +1 @@ -var _key; -_key = Symbol.iterator, Symbol.toPrimitive, Symbol.toStringTag; +Symbol.iterator, Symbol.toPrimitive, Symbol.toStringTag; diff --git a/crates/swc/tests/tsc-references/symbolProperty6_es5.1.normal.js b/crates/swc/tests/tsc-references/symbolProperty6_es5.1.normal.js index bb75e353cbfa..64883606400e 100644 --- a/crates/swc/tests/tsc-references/symbolProperty6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/symbolProperty6_es5.1.normal.js @@ -17,18 +17,17 @@ function _createClass(Constructor, protoProps, staticProps) { if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } -var _key; -var tmp = (_key = Symbol.iterator, Symbol.toPrimitive), _toStringTag = Symbol.toStringTag; +var _iterator = Symbol.iterator, _toPrimitive = Symbol.toPrimitive, _toStringTag = Symbol.toStringTag; var C = //@target: ES6 /*#__PURE__*/ function() { "use strict"; function C() { _classCallCheck(this, C); - this[_key] = 0; + this[_iterator] = 0; } _createClass(C, [ { - key: tmp, + key: _toPrimitive, value: function value() {} }, { diff --git a/crates/swc/tests/tsc-references/symbolProperty6_es5.2.minified.js b/crates/swc/tests/tsc-references/symbolProperty6_es5.2.minified.js index 1769ca284892..58389e69bb5d 100644 --- a/crates/swc/tests/tsc-references/symbolProperty6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/symbolProperty6_es5.2.minified.js @@ -4,17 +4,17 @@ function _defineProperties(target, props) { descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } -var _key, tmp = (_key = Symbol.iterator, Symbol.toPrimitive), _toStringTag = Symbol.toStringTag, C = function() { +var _iterator = Symbol.iterator, _toPrimitive = Symbol.toPrimitive, _toStringTag = Symbol.toStringTag, C = function() { "use strict"; var Constructor, protoProps, staticProps; function C() { !function(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C), this[_key] = 0; + }(this, C), this[_iterator] = 0; } return Constructor = C, protoProps = [ { - key: tmp, + key: _toPrimitive, value: function() {} }, { diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.1.normal.js index af7fc7638c97..b9acbcabd0b8 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.1.normal.js @@ -1,3 +1,16 @@ +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function _extends() { _extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ @@ -12,6 +25,74 @@ function _extends() { }; return _extends.apply(this, arguments); } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function set(target, property, value, receiver) { + if (typeof Reflect !== "undefined" && Reflect.set) { + set = Reflect.set; + } else { + set = function set(target, property, value, receiver) { + var base = _superPropBase(target, property); + var desc; + if (base) { + desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.set) { + desc.set.call(receiver, value); + return true; + } else if (!desc.writable) { + return false; + } + } + desc = Object.getOwnPropertyDescriptor(receiver, property); + if (desc) { + if (!desc.writable) { + return false; + } + desc.value = value; + Object.defineProperty(receiver, property, desc); + } else { + _defineProperty(receiver, property, value); + } + return true; + }; + } + return set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + var s = set(target, property, value, receiver || target); + if (!s && isStrict) { + throw new Error("failed to set property"); + } + return value; +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} +var _ref, _super_a; class C extends B { constructor(...args){ super(...args); @@ -27,36 +108,36 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z1 = super.a; -C.z2 = super["a"]; -C.z3 = super.f(); -C.z4 = super["f"](); -C.z5 = super.a = 0; -C.z6 = super.a += 1; +C.z1 = _get(_getPrototypeOf(C), "a", C); +C.z2 = _get(_getPrototypeOf(C), "a", C); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, true); +C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); C.z7 = (()=>{ - super.a = 0; + _set(_getPrototypeOf(C.prototype), "a", 0, C, true); })(); -C.z8 = [super.a] = [ +C.z8 = [_get(_getPrototypeOf(C), "a", C)] = [ 0 ]; -C.z9 = [super.a = 0] = [ +C.z9 = [_get(_getPrototypeOf(C), "a", C) = 0] = [ 0 ]; -C.z10 = [...super.a] = [ +C.z10 = [..._get(_getPrototypeOf(C), "a", C)] = [ 0 ]; -C.z11 = { x: super.a } = { +C.z11 = { x: _get(_getPrototypeOf(C), "a", C) } = { x: 0 }; -C.z12 = { x: super.a = 0 } = { +C.z12 = { x: _get(_getPrototypeOf(C), "a", C) = 0 } = { x: 0 }; var _tmp; C.z13 = (_tmp = { x: 0 -}, super.a = _extends({}, _tmp), _tmp); -C.z14 = ++super.a; -C.z15 = --super.a; -C.z16 = ++super["a"]; -C.z17 = super.a++; -C.z18 = super.a``; +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), _tmp); +C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); +C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, true); +C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, true); +C.z17 = (_set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, true), _super_a); +C.z18 = _get(_getPrototypeOf(C), "a", C)``; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.2.minified.js index 03d7f7bee1a4..dac708d26017 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es2015.2.minified.js @@ -1,4 +1,4 @@ -var _tmp; +var _ref, _super_a, _tmp; function _extends() { return (_extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ @@ -8,21 +8,62 @@ function _extends() { return target; }).apply(this, arguments); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function set(target, property, value, receiver) { + return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function set(target, property, value, receiver) { + var obj, key, value, desc, base = _superPropBase(target, property); + if (base) { + if ((desc = Object.getOwnPropertyDescriptor(base, property)).set) return desc.set.call(receiver, value), !0; + if (!desc.writable) return !1; + } + if (desc = Object.getOwnPropertyDescriptor(receiver, property)) { + if (!desc.writable) return !1; + desc.value = value, Object.defineProperty(receiver, property, desc); + } else obj = receiver, (key = property) in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; + return !0; + }, set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + if (!set(target, property, value, receiver || target) && isStrict) throw new Error("failed to set property"); + return value; +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C extends B { constructor(...args){ super(...args), this.x = 1, this.y = this.x, this.z = super.f(); } } -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = super.a, C.z2 = super.a, C.z3 = super.f(), C.z4 = super.f(), C.z5 = super.a = 0, C.z6 = super.a += 1, C.z7 = void (super.a = 0), C.z8 = [super.a] = [ +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = _get(_getPrototypeOf(C), "a", C), C.z2 = _get(_getPrototypeOf(C), "a", C), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C), C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z7 = void _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), C.z8 = [_get(_getPrototypeOf(C), "a", C)] = [ 0 -], C.z9 = [super.a = 0] = [ +], C.z9 = [_get(_getPrototypeOf(C), "a", C) = 0] = [ 0 -], C.z10 = [...super.a] = [ +], C.z10 = [..._get(_getPrototypeOf(C), "a", C)] = [ 0 -], C.z11 = { x: super.a } = { +], C.z11 = { x: _get(_getPrototypeOf(C), "a", C) } = { x: 0 -}, C.z12 = { x: super.a = 0 } = { +}, C.z12 = { x: _get(_getPrototypeOf(C), "a", C) = 0 } = { x: 0 }, _tmp = { x: 0 -}, super.a = _extends({}, _tmp), C.z13 = _tmp, C.z14 = ++super.a, C.z15 = --super.a, C.z16 = ++super.a, C.z17 = super.a++, C.z18 = super.a``; +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), C.z13 = _tmp, C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, !0), C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, !0), _set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, !0), C.z17 = _super_a, C.z18 = _get(_getPrototypeOf(C), "a", C)``; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.1.normal.js index 4b2123ecb2b2..3a02f94baf59 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.1.normal.js @@ -9,6 +9,19 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function _extends() { _extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ @@ -64,6 +77,44 @@ function _possibleConstructorReturn(self, call) { } return _assertThisInitialized(self); } +function set(target, property, value, receiver) { + if (typeof Reflect !== "undefined" && Reflect.set) { + set = Reflect.set; + } else { + set = function set(target, property, value, receiver) { + var base = _superPropBase(target, property); + var desc; + if (base) { + desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.set) { + desc.set.call(receiver, value); + return true; + } else if (!desc.writable) { + return false; + } + } + desc = Object.getOwnPropertyDescriptor(receiver, property); + if (desc) { + if (!desc.writable) { + return false; + } + desc.value = value; + Object.defineProperty(receiver, property, desc); + } else { + _defineProperty(receiver, property, value); + } + return true; + }; + } + return set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + var s = set(target, property, value, receiver || target); + if (!s && isStrict) { + throw new Error("failed to set property"); + } + return value; +} function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; @@ -116,8 +167,6 @@ function _createSuper(Derived) { return _possibleConstructorReturn(this, result); }; } -var _superprop_set_a = (_value)=>super.a = _value -; function _templateObject() { var data = _taggedTemplateLiteral([ "" @@ -127,6 +176,7 @@ function _templateObject() { }; return data; } +var _ref, _super_a; var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -149,41 +199,41 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z1 = super.a; -C.z2 = super["a"]; -C.z3 = super.f(); -C.z4 = super["f"](); -C.z5 = super.a = 0; -C.z6 = super.a += 1; +C.z1 = _get(_getPrototypeOf(C), "a", C); +C.z2 = _get(_getPrototypeOf(C), "a", C); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, true); +C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); C.z7 = (function() { - _superprop_set_a(0); + _set(_getPrototypeOf(C.prototype), "a", 0, C, true); })(); var ref; C.z8 = (ref = [ 0 -], super.a = ref[0], ref); +], _get(_getPrototypeOf(C), "a", C) = ref[0], ref); var ref1, ref2; C.z9 = (ref1 = [ 0 -], ref2 = ref1[0], super.a = ref2 === void 0 ? 0 : ref2, ref1); +], ref2 = ref1[0], _get(_getPrototypeOf(C), "a", C) = ref2 === void 0 ? 0 : ref2, ref1); var ref3; C.z10 = (ref3 = [ 0 -], super.a = ref3.slice(0), ref3); +], _get(_getPrototypeOf(C), "a", C) = ref3.slice(0), ref3); var ref4; C.z11 = (ref4 = { x: 0 -}, super.a = ref4.x, ref4); +}, _get(_getPrototypeOf(C), "a", C) = ref4.x, ref4); var ref5, ref6; C.z12 = (ref5 = { x: 0 -}, ref6 = ref5.x, super.a = ref6 === void 0 ? 0 : ref6, ref5); +}, ref6 = ref5.x, _get(_getPrototypeOf(C), "a", C) = ref6 === void 0 ? 0 : ref6, ref5); var _tmp; C.z13 = (_tmp = { x: 0 -}, super.a = _extends({}, _tmp), _tmp); -C.z14 = ++super.a; -C.z15 = --super.a; -C.z16 = ++super["a"]; -C.z17 = super.a++; -C.z18 = super.a(_templateObject()); +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), _tmp); +C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); +C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, true); +C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, true); +C.z17 = (_set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, true), _super_a); +C.z18 = _get(_getPrototypeOf(C), "a", C)(_templateObject()); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.2.minified.js index 288b6b76554d..f636ac69e232 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers1_es5.2.minified.js @@ -25,6 +25,29 @@ function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }, _getPrototypeOf(o); } +function set(target, property, value, receiver) { + return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function set(target, property, value, receiver) { + var obj, key, value, desc, base = _superPropBase(target, property); + if (base) { + if ((desc = Object.getOwnPropertyDescriptor(base, property)).set) return desc.set.call(receiver, value), !0; + if (!desc.writable) return !1; + } + if (desc = Object.getOwnPropertyDescriptor(receiver, property)) { + if (!desc.writable) return !1; + desc.value = value, Object.defineProperty(receiver, property, desc); + } else obj = receiver, (key = property) in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; + return !0; + }, set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + if (!set(target, property, value, receiver || target) && isStrict) throw new Error("failed to set property"); + return value; +} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -34,6 +57,9 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } +var _ref, _super_a, ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, _typeof = function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +}; function _templateObject() { var strings, raw, data = (strings = [ "" @@ -46,7 +72,7 @@ function _templateObject() { return data; }, data; } -var ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, C = function(B) { +var C = function(B) { "use strict"; !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); @@ -68,12 +94,12 @@ var ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, C = function(B) { return !1; } }(), function() { - var obj, self, call, result, Super = _getPrototypeOf(Derived); + var self, call, result, Super = _getPrototypeOf(Derived); if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else result = Super.apply(this, arguments); - return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : _assertThisInitialized(self); }); function C() { var _this; @@ -83,16 +109,16 @@ var ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, C = function(B) { } return C; }(B); -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = super.a, C.z2 = super.a, C.z3 = super.f(), C.z4 = super.f(), C.z5 = super.a = 0, C.z6 = super.a += 1, C.z7 = void (super.a = 0), ref = [ +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = _get(_getPrototypeOf(C), "a", C), C.z2 = _get(_getPrototypeOf(C), "a", C), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C), C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z7 = void _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), ref = [ 0 -], super.a = ref[0], C.z8 = ref, ref2 = (ref1 = [ +], _get(_getPrototypeOf(C), "a", C) = ref[0], C.z8 = ref, ref2 = (ref1 = [ 0 -])[0], super.a = void 0 === ref2 ? 0 : ref2, C.z9 = ref1, ref3 = [ +])[0], _get(_getPrototypeOf(C), "a", C) = void 0 === ref2 ? 0 : ref2, C.z9 = ref1, ref3 = [ 0 -], super.a = ref3.slice(0), C.z10 = ref3, ref4 = { +], _get(_getPrototypeOf(C), "a", C) = ref3.slice(0), C.z10 = ref3, ref4 = { x: 0 -}, super.a = ref4.x, C.z11 = ref4, ref6 = (ref5 = { +}, _get(_getPrototypeOf(C), "a", C) = ref4.x, C.z11 = ref4, ref6 = (ref5 = { x: 0 -}).x, super.a = void 0 === ref6 ? 0 : ref6, C.z12 = ref5, _tmp = { +}).x, _get(_getPrototypeOf(C), "a", C) = void 0 === ref6 ? 0 : ref6, C.z12 = ref5, _tmp = { x: 0 -}, super.a = _extends({}, _tmp), C.z13 = _tmp, C.z14 = ++super.a, C.z15 = --super.a, C.z16 = ++super.a, C.z17 = super.a++, C.z18 = super.a(_templateObject()); +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), C.z13 = _tmp, C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, !0), C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, !0), _set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, !0), C.z17 = _super_a, C.z18 = _get(_getPrototypeOf(C), "a", C)(_templateObject()); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.1.normal.js index af7fc7638c97..b9acbcabd0b8 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.1.normal.js @@ -1,3 +1,16 @@ +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function _extends() { _extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ @@ -12,6 +25,74 @@ function _extends() { }; return _extends.apply(this, arguments); } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function set(target, property, value, receiver) { + if (typeof Reflect !== "undefined" && Reflect.set) { + set = Reflect.set; + } else { + set = function set(target, property, value, receiver) { + var base = _superPropBase(target, property); + var desc; + if (base) { + desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.set) { + desc.set.call(receiver, value); + return true; + } else if (!desc.writable) { + return false; + } + } + desc = Object.getOwnPropertyDescriptor(receiver, property); + if (desc) { + if (!desc.writable) { + return false; + } + desc.value = value; + Object.defineProperty(receiver, property, desc); + } else { + _defineProperty(receiver, property, value); + } + return true; + }; + } + return set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + var s = set(target, property, value, receiver || target); + if (!s && isStrict) { + throw new Error("failed to set property"); + } + return value; +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} +var _ref, _super_a; class C extends B { constructor(...args){ super(...args); @@ -27,36 +108,36 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z1 = super.a; -C.z2 = super["a"]; -C.z3 = super.f(); -C.z4 = super["f"](); -C.z5 = super.a = 0; -C.z6 = super.a += 1; +C.z1 = _get(_getPrototypeOf(C), "a", C); +C.z2 = _get(_getPrototypeOf(C), "a", C); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, true); +C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); C.z7 = (()=>{ - super.a = 0; + _set(_getPrototypeOf(C.prototype), "a", 0, C, true); })(); -C.z8 = [super.a] = [ +C.z8 = [_get(_getPrototypeOf(C), "a", C)] = [ 0 ]; -C.z9 = [super.a = 0] = [ +C.z9 = [_get(_getPrototypeOf(C), "a", C) = 0] = [ 0 ]; -C.z10 = [...super.a] = [ +C.z10 = [..._get(_getPrototypeOf(C), "a", C)] = [ 0 ]; -C.z11 = { x: super.a } = { +C.z11 = { x: _get(_getPrototypeOf(C), "a", C) } = { x: 0 }; -C.z12 = { x: super.a = 0 } = { +C.z12 = { x: _get(_getPrototypeOf(C), "a", C) = 0 } = { x: 0 }; var _tmp; C.z13 = (_tmp = { x: 0 -}, super.a = _extends({}, _tmp), _tmp); -C.z14 = ++super.a; -C.z15 = --super.a; -C.z16 = ++super["a"]; -C.z17 = super.a++; -C.z18 = super.a``; +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), _tmp); +C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); +C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, true); +C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, true); +C.z17 = (_set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, true), _super_a); +C.z18 = _get(_getPrototypeOf(C), "a", C)``; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.2.minified.js index 03d7f7bee1a4..dac708d26017 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es2015.2.minified.js @@ -1,4 +1,4 @@ -var _tmp; +var _ref, _super_a, _tmp; function _extends() { return (_extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ @@ -8,21 +8,62 @@ function _extends() { return target; }).apply(this, arguments); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function set(target, property, value, receiver) { + return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function set(target, property, value, receiver) { + var obj, key, value, desc, base = _superPropBase(target, property); + if (base) { + if ((desc = Object.getOwnPropertyDescriptor(base, property)).set) return desc.set.call(receiver, value), !0; + if (!desc.writable) return !1; + } + if (desc = Object.getOwnPropertyDescriptor(receiver, property)) { + if (!desc.writable) return !1; + desc.value = value, Object.defineProperty(receiver, property, desc); + } else obj = receiver, (key = property) in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; + return !0; + }, set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + if (!set(target, property, value, receiver || target) && isStrict) throw new Error("failed to set property"); + return value; +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C extends B { constructor(...args){ super(...args), this.x = 1, this.y = this.x, this.z = super.f(); } } -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = super.a, C.z2 = super.a, C.z3 = super.f(), C.z4 = super.f(), C.z5 = super.a = 0, C.z6 = super.a += 1, C.z7 = void (super.a = 0), C.z8 = [super.a] = [ +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = _get(_getPrototypeOf(C), "a", C), C.z2 = _get(_getPrototypeOf(C), "a", C), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C), C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z7 = void _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), C.z8 = [_get(_getPrototypeOf(C), "a", C)] = [ 0 -], C.z9 = [super.a = 0] = [ +], C.z9 = [_get(_getPrototypeOf(C), "a", C) = 0] = [ 0 -], C.z10 = [...super.a] = [ +], C.z10 = [..._get(_getPrototypeOf(C), "a", C)] = [ 0 -], C.z11 = { x: super.a } = { +], C.z11 = { x: _get(_getPrototypeOf(C), "a", C) } = { x: 0 -}, C.z12 = { x: super.a = 0 } = { +}, C.z12 = { x: _get(_getPrototypeOf(C), "a", C) = 0 } = { x: 0 }, _tmp = { x: 0 -}, super.a = _extends({}, _tmp), C.z13 = _tmp, C.z14 = ++super.a, C.z15 = --super.a, C.z16 = ++super.a, C.z17 = super.a++, C.z18 = super.a``; +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), C.z13 = _tmp, C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, !0), C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, !0), _set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, !0), C.z17 = _super_a, C.z18 = _get(_getPrototypeOf(C), "a", C)``; diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.1.normal.js index 4b2123ecb2b2..3a02f94baf59 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.1.normal.js @@ -9,6 +9,19 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; +} function _extends() { _extends = Object.assign || function(target) { for(var i = 1; i < arguments.length; i++){ @@ -64,6 +77,44 @@ function _possibleConstructorReturn(self, call) { } return _assertThisInitialized(self); } +function set(target, property, value, receiver) { + if (typeof Reflect !== "undefined" && Reflect.set) { + set = Reflect.set; + } else { + set = function set(target, property, value, receiver) { + var base = _superPropBase(target, property); + var desc; + if (base) { + desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.set) { + desc.set.call(receiver, value); + return true; + } else if (!desc.writable) { + return false; + } + } + desc = Object.getOwnPropertyDescriptor(receiver, property); + if (desc) { + if (!desc.writable) { + return false; + } + desc.value = value; + Object.defineProperty(receiver, property, desc); + } else { + _defineProperty(receiver, property, value); + } + return true; + }; + } + return set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + var s = set(target, property, value, receiver || target); + if (!s && isStrict) { + throw new Error("failed to set property"); + } + return value; +} function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; @@ -116,8 +167,6 @@ function _createSuper(Derived) { return _possibleConstructorReturn(this, result); }; } -var _superprop_set_a = (_value)=>super.a = _value -; function _templateObject() { var data = _taggedTemplateLiteral([ "" @@ -127,6 +176,7 @@ function _templateObject() { }; return data; } +var _ref, _super_a; var C = /*#__PURE__*/ function(B) { "use strict"; _inherits(C, B); @@ -149,41 +199,41 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z1 = super.a; -C.z2 = super["a"]; -C.z3 = super.f(); -C.z4 = super["f"](); -C.z5 = super.a = 0; -C.z6 = super.a += 1; +C.z1 = _get(_getPrototypeOf(C), "a", C); +C.z2 = _get(_getPrototypeOf(C), "a", C); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, true); +C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); C.z7 = (function() { - _superprop_set_a(0); + _set(_getPrototypeOf(C.prototype), "a", 0, C, true); })(); var ref; C.z8 = (ref = [ 0 -], super.a = ref[0], ref); +], _get(_getPrototypeOf(C), "a", C) = ref[0], ref); var ref1, ref2; C.z9 = (ref1 = [ 0 -], ref2 = ref1[0], super.a = ref2 === void 0 ? 0 : ref2, ref1); +], ref2 = ref1[0], _get(_getPrototypeOf(C), "a", C) = ref2 === void 0 ? 0 : ref2, ref1); var ref3; C.z10 = (ref3 = [ 0 -], super.a = ref3.slice(0), ref3); +], _get(_getPrototypeOf(C), "a", C) = ref3.slice(0), ref3); var ref4; C.z11 = (ref4 = { x: 0 -}, super.a = ref4.x, ref4); +}, _get(_getPrototypeOf(C), "a", C) = ref4.x, ref4); var ref5, ref6; C.z12 = (ref5 = { x: 0 -}, ref6 = ref5.x, super.a = ref6 === void 0 ? 0 : ref6, ref5); +}, ref6 = ref5.x, _get(_getPrototypeOf(C), "a", C) = ref6 === void 0 ? 0 : ref6, ref5); var _tmp; C.z13 = (_tmp = { x: 0 -}, super.a = _extends({}, _tmp), _tmp); -C.z14 = ++super.a; -C.z15 = --super.a; -C.z16 = ++super["a"]; -C.z17 = super.a++; -C.z18 = super.a(_templateObject()); +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), _tmp); +C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, true); +C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, true); +C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, true); +C.z17 = (_set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, true), _super_a); +C.z18 = _get(_getPrototypeOf(C), "a", C)(_templateObject()); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.2.minified.js index 288b6b76554d..f636ac69e232 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers2_es5.2.minified.js @@ -25,6 +25,29 @@ function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }, _getPrototypeOf(o); } +function set(target, property, value, receiver) { + return set = "undefined" != typeof Reflect && Reflect.set ? Reflect.set : function set(target, property, value, receiver) { + var obj, key, value, desc, base = _superPropBase(target, property); + if (base) { + if ((desc = Object.getOwnPropertyDescriptor(base, property)).set) return desc.set.call(receiver, value), !0; + if (!desc.writable) return !1; + } + if (desc = Object.getOwnPropertyDescriptor(receiver, property)) { + if (!desc.writable) return !1; + desc.value = value, Object.defineProperty(receiver, property, desc); + } else obj = receiver, (key = property) in obj ? Object.defineProperty(obj, key, { + value: value, + enumerable: !0, + configurable: !0, + writable: !0 + }) : obj[key] = value; + return !0; + }, set(target, property, value, receiver); +} +function _set(target, property, value, receiver, isStrict) { + if (!set(target, property, value, receiver || target) && isStrict) throw new Error("failed to set property"); + return value; +} function _setPrototypeOf(o, p) { return _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { return o.__proto__ = p, o; @@ -34,6 +57,9 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } +var _ref, _super_a, ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, _typeof = function(obj) { + return obj && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj; +}; function _templateObject() { var strings, raw, data = (strings = [ "" @@ -46,7 +72,7 @@ function _templateObject() { return data; }, data; } -var ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, C = function(B) { +var C = function(B) { "use strict"; !function(subClass, superClass) { if ("function" != typeof superClass && null !== superClass) throw new TypeError("Super expression must either be null or a function"); @@ -68,12 +94,12 @@ var ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, C = function(B) { return !1; } }(), function() { - var obj, self, call, result, Super = _getPrototypeOf(Derived); + var self, call, result, Super = _getPrototypeOf(Derived); if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else result = Super.apply(this, arguments); - return self = this, (call = result) && ("object" == ((obj = call) && "undefined" != typeof Symbol && obj.constructor === Symbol ? "symbol" : typeof obj) || "function" == typeof call) ? call : _assertThisInitialized(self); + return self = this, (call = result) && ("object" === _typeof(call) || "function" == typeof call) ? call : _assertThisInitialized(self); }); function C() { var _this; @@ -83,16 +109,16 @@ var ref, ref1, ref2, ref3, ref4, ref5, ref6, _tmp, C = function(B) { } return C; }(B); -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = super.a, C.z2 = super.a, C.z3 = super.f(), C.z4 = super.f(), C.z5 = super.a = 0, C.z6 = super.a += 1, C.z7 = void (super.a = 0), ref = [ +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z1 = _get(_getPrototypeOf(C), "a", C), C.z2 = _get(_getPrototypeOf(C), "a", C), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C), C.z5 = _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), C.z6 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z7 = void _set(_getPrototypeOf(C.prototype), "a", 0, C, !0), ref = [ 0 -], super.a = ref[0], C.z8 = ref, ref2 = (ref1 = [ +], _get(_getPrototypeOf(C), "a", C) = ref[0], C.z8 = ref, ref2 = (ref1 = [ 0 -])[0], super.a = void 0 === ref2 ? 0 : ref2, C.z9 = ref1, ref3 = [ +])[0], _get(_getPrototypeOf(C), "a", C) = void 0 === ref2 ? 0 : ref2, C.z9 = ref1, ref3 = [ 0 -], super.a = ref3.slice(0), C.z10 = ref3, ref4 = { +], _get(_getPrototypeOf(C), "a", C) = ref3.slice(0), C.z10 = ref3, ref4 = { x: 0 -}, super.a = ref4.x, C.z11 = ref4, ref6 = (ref5 = { +}, _get(_getPrototypeOf(C), "a", C) = ref4.x, C.z11 = ref4, ref6 = (ref5 = { x: 0 -}).x, super.a = void 0 === ref6 ? 0 : ref6, C.z12 = ref5, _tmp = { +}).x, _get(_getPrototypeOf(C), "a", C) = void 0 === ref6 ? 0 : ref6, C.z12 = ref5, _tmp = { x: 0 -}, super.a = _extends({}, _tmp), C.z13 = _tmp, C.z14 = ++super.a, C.z15 = --super.a, C.z16 = ++super.a, C.z17 = super.a++, C.z18 = super.a(_templateObject()); +}, _get(_getPrototypeOf(C), "a", C) = _extends({}, _tmp), C.z13 = _tmp, C.z14 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) + 1, C, !0), C.z15 = _set(_getPrototypeOf(C.prototype), "a", _get(_getPrototypeOf(C), "a", C) - 1, C, !0), C.z16 = _set(_getPrototypeOf(C.prototype), _ref = "a", _get(_getPrototypeOf(C), _ref, C) + 1, C, !0), _set(_getPrototypeOf(C.prototype), "a", (_super_a = +_get(_getPrototypeOf(C), "a", C)) + 1, C, !0), C.z17 = _super_a, C.z18 = _get(_getPrototypeOf(C), "a", C)(_templateObject()); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.1.normal.js index 6e281a0b01ab..de45f04d2a17 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} class C extends B { constructor(...args){ super(...args); @@ -13,5 +42,5 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z3 = super.f(); -C.z4 = super["f"](); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.2.minified.js index 5a616047c443..845b1597fbe9 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es2015.2.minified.js @@ -1,6 +1,24 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C extends B { constructor(...args){ super(...args), this.x = 1, this.y = this.x, this.z = super.f(); } } -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = super.f(), C.z4 = super.f(); +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.1.normal.js index 2ed46c5c1874..9b6aa1e3c0a6 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.1.normal.js @@ -114,5 +114,5 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z3 = super.f(); -C.z4 = super["f"](); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.2.minified.js index 45e25382ca3c..e7fb735b2390 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers3_es5.2.minified.js @@ -62,4 +62,4 @@ var C = function(B) { } return C; }(B); -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = super.f(), C.z4 = super.f(); +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.1.normal.js index 6e281a0b01ab..de45f04d2a17 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} class C extends B { constructor(...args){ super(...args); @@ -13,5 +42,5 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z3 = super.f(); -C.z4 = super["f"](); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.2.minified.js index 5a616047c443..845b1597fbe9 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es2015.2.minified.js @@ -1,6 +1,24 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C extends B { constructor(...args){ super(...args), this.x = 1, this.y = this.x, this.z = super.f(); } } -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = super.f(), C.z4 = super.f(); +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.1.normal.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.1.normal.js index 2ed46c5c1874..9b6aa1e3c0a6 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.1.normal.js @@ -114,5 +114,5 @@ C.y2 = C.x(); C.y3 = C === null || C === void 0 ? void 0 : C.x(); C.y4 = C["x"](); C.y5 = C === null || C === void 0 ? void 0 : C["x"](); -C.z3 = super.f(); -C.z4 = super["f"](); +C.z3 = _get(_getPrototypeOf(C), "f", C).call(C); +C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.2.minified.js b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.2.minified.js index 45e25382ca3c..e7fb735b2390 100644 --- a/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/thisAndSuperInStaticMembers4_es5.2.minified.js @@ -62,4 +62,4 @@ var C = function(B) { } return C; }(B); -C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = super.f(), C.z4 = super.f(); +C.x = void 0, C.y1 = C.x, C.y2 = C.x(), C.y3 = null == C ? void 0 : C.x(), C.y4 = C.x(), C.y5 = null == C ? void 0 : C.x(), C.z3 = _get(_getPrototypeOf(C), "f", C).call(C), C.z4 = _get(_getPrototypeOf(C), "f", C).call(C); diff --git a/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es2015.1.normal.js b/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es2015.1.normal.js index 23d5448e3920..9870225f084d 100644 --- a/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es2015.1.normal.js @@ -4,7 +4,7 @@ export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment export class Bet { constructor(){ - this.q // And so will this implements error - = "lol"; + this.q = "lol" // And so will this implements error + ; } } diff --git a/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es5.1.normal.js b/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es5.1.normal.js index 62255ac236b9..e074bf39e0df 100644 --- a/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/tsNoCheckForTypescript_es5.1.normal.js @@ -10,6 +10,6 @@ export var a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied export var Bet = function Bet() { "use strict"; _classCallCheck(this, Bet); - this.q // And so will this implements error - = "lol"; + this.q = "lol" // And so will this implements error + ; }; diff --git a/crates/swc/tests/tsc-references/typeFromPropertyAssignment29_es5.1.normal.js b/crates/swc/tests/tsc-references/typeFromPropertyAssignment29_es5.1.normal.js index 7b32dd187217..7771a6c8e74d 100644 --- a/crates/swc/tests/tsc-references/typeFromPropertyAssignment29_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeFromPropertyAssignment29_es5.1.normal.js @@ -72,7 +72,6 @@ var n = ExpandoExpr2.prop + ExpandoExpr2.m(12) + ExpandoExpr2(101).length; var ExpandoClass = function ExpandoClass() { "use strict"; _classCallCheck(this, ExpandoClass); - // Should not work in typescript -- classes already have statics this.n = 1001; }; ExpandoClass.prop = 2; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es2015.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es2015.1.normal.js index d10566ae4aea..402c4dbf23e7 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es2015.1.normal.js @@ -1,6 +1,8 @@ class C { } -C.foo = C; +C.foo = C // ok +; class C2 { } -C2.foo = C2; +C2.foo = C2 // ok +; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es5.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es5.1.normal.js index 5904413151bf..77270ca707db 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers2_es5.1.normal.js @@ -7,9 +7,11 @@ var C = function C() { "use strict"; _classCallCheck(this, C); }; -C.foo = C; +C.foo = C // ok +; var C2 = function C2() { "use strict"; _classCallCheck(this, C2); }; -C2.foo = C2; +C2.foo = C2 // ok +; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.1.normal.js index fbedcc5c766e..aef83f95a35d 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} // @target: esnext, es2022, es6, es5 // @useDefineForClassFields: false class C { @@ -8,4 +37,4 @@ class D extends C { } D.c = 2; D.d = D.c + 1; -D.e = super.a + D.c + 1; +D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.2.minified.js index 104ea17fe6dd..6cd4e0f7c7ac 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es2015.2.minified.js @@ -1,6 +1,24 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C { } C.a = 1, C.b = C.a + 1; class D extends C { } -D.c = 2, D.d = D.c + 1, D.e = super.a + D.c + 1; +D.c = 2, D.d = D.c + 1, D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.1.normal.js index 353ead89be2b..61f2d62bb534 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.1.normal.js @@ -9,6 +9,22 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -41,6 +57,13 @@ function _setPrototypeOf(o, p) { }; return _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; @@ -87,4 +110,4 @@ var D = /*#__PURE__*/ function(C) { }(C); D.c = 2; D.d = D.c + 1; -D.e = super.a + D.c + 1; +D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.2.minified.js index 5b72214d500f..2a14c434a2cc 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers3_es5.2.minified.js @@ -1,6 +1,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} function _getPrototypeOf(o) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -11,6 +20,10 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} var C = function() { "use strict"; _classCallCheck(this, C); @@ -53,4 +66,4 @@ var D = function(C1) { } return D; }(C); -D.c = 2, D.d = D.c + 1, D.e = super.a + D.c + 1; +D.c = 2, D.d = D.c + 1, D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.1.normal.js index 7cbded60e8cc..976ff2f9b124 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} // @target: esnext, es2022, es6, es5 // @useDefineForClassFields: true class C { @@ -8,4 +37,4 @@ class D extends C { } D.c = 2; D.d = D.c + 1; -D.e = super.a + D.c + 1; +D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.2.minified.js index 104ea17fe6dd..6cd4e0f7c7ac 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es2015.2.minified.js @@ -1,6 +1,24 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C { } C.a = 1, C.b = C.a + 1; class D extends C { } -D.c = 2, D.d = D.c + 1, D.e = super.a + D.c + 1; +D.c = 2, D.d = D.c + 1, D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.1.normal.js index 353ead89be2b..61f2d62bb534 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.1.normal.js @@ -9,6 +9,22 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -41,6 +57,13 @@ function _setPrototypeOf(o, p) { }; return _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; @@ -87,4 +110,4 @@ var D = /*#__PURE__*/ function(C) { }(C); D.c = 2; D.d = D.c + 1; -D.e = super.a + D.c + 1; +D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.2.minified.js index 5b72214d500f..2a14c434a2cc 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers4_es5.2.minified.js @@ -1,6 +1,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} function _getPrototypeOf(o) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -11,6 +20,10 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} var C = function() { "use strict"; _classCallCheck(this, C); @@ -53,4 +66,4 @@ var D = function(C1) { } return D; }(C); -D.c = 2, D.d = D.c + 1, D.e = super.a + D.c + 1; +D.c = 2, D.d = D.c + 1, D.e = _get(_getPrototypeOf(D), "a", D) + D.c + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.1.normal.js index a5cfc6424f15..2580b2f35220 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.1.normal.js @@ -1,3 +1,32 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} // @target: esnext, es2022, es6, es5 class C { } @@ -7,4 +36,4 @@ class D extends C { } D.c = 2; D.d = D.c + 1; -D.e = 1 + super.a + (D.c + 1) + 1; +D.e = 1 + _get(_getPrototypeOf(D), "a", D) + (D.c + 1) + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.2.minified.js index dbc0b624e225..2cef66f39fec 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es2015.2.minified.js @@ -1,6 +1,24 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C { } C.a = 1, C.b = C.a + 1; class D extends C { } -D.c = 2, D.d = D.c + 1, D.e = 1 + super.a + (D.c + 1) + 1; +D.c = 2, D.d = D.c + 1, D.e = 1 + _get(_getPrototypeOf(D), "a", D) + (D.c + 1) + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.1.normal.js index d7a3b44f2419..87646c6083b2 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.1.normal.js @@ -9,6 +9,22 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -41,6 +57,13 @@ function _setPrototypeOf(o, p) { }; return _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; @@ -87,4 +110,4 @@ var D = /*#__PURE__*/ function(C) { }(C); D.c = 2; D.d = D.c + 1; -D.e = 1 + super.a + (D.c + 1) + 1; +D.e = 1 + _get(_getPrototypeOf(D), "a", D) + (D.c + 1) + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.2.minified.js index 88c932cd78bd..24c1306f758f 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers7_es5.2.minified.js @@ -1,6 +1,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} function _getPrototypeOf(o) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -11,6 +20,10 @@ function _setPrototypeOf(o, p) { return o.__proto__ = p, o; }, _setPrototypeOf(o, p); } +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} var C = function() { "use strict"; _classCallCheck(this, C); @@ -53,4 +66,4 @@ var D = function(C1) { } return D; }(C); -D.c = 2, D.d = D.c + 1, D.e = 1 + super.a + (D.c + 1) + 1; +D.c = 2, D.d = D.c + 1, D.e = 1 + _get(_getPrototypeOf(D), "a", D) + (D.c + 1) + 1; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.1.normal.js index 1ddbcc065497..0388482bd6e9 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.1.normal.js @@ -1,13 +1,42 @@ +function _get(target, property, receiver) { + if (typeof Reflect !== "undefined" && Reflect.get) { + _get = Reflect.get; + } else { + _get = function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (!base) return; + var desc = Object.getOwnPropertyDescriptor(base, property); + if (desc.get) { + return desc.get.call(receiver); + } + return desc.value; + }; + } + return _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); +} +function _superPropBase(object, property) { + while(!Object.prototype.hasOwnProperty.call(object, property)){ + object = _getPrototypeOf(object); + if (object === null) break; + } + return object; +} // @target: esnext, es2022, es6, es5 class C { } C.f = 1; class D extends C { } -D.arrowFunctionBoundary = ()=>super.f + 1 +D.arrowFunctionBoundary = ()=>_get(_getPrototypeOf(D), "f", D) + 1 ; D.functionExprBoundary = function() { - return super.f + 2; + return _get(_getPrototypeOf(D), "f", this) + 2; }; D.classExprBoundary = class { constructor(){ @@ -16,7 +45,7 @@ D.classExprBoundary = class { }; D.functionAndClassDeclBoundary = (()=>{ function foo() { - return super.f + 4; + return _get(_getPrototypeOf(D), "f", this) + 4; } class C { method() { diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.2.minified.js index 68811be3b883..c0258398e30d 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es2015.2.minified.js @@ -1,11 +1,29 @@ +function _get(target, property, receiver) { + return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { + var base = _superPropBase(target, property); + if (base) { + var desc = Object.getOwnPropertyDescriptor(base, property); + return desc.get ? desc.get.call(receiver) : desc.value; + } + }, _get(target, property, receiver || target); +} +function _getPrototypeOf(o) { + return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }, _getPrototypeOf(o); +} +function _superPropBase(object, property) { + for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); + return object; +} class C { } C.f = 1; class D extends C { } -D.arrowFunctionBoundary = ()=>super.f + 1 +D.arrowFunctionBoundary = ()=>_get(_getPrototypeOf(D), "f", D) + 1 , D.functionExprBoundary = function() { - return super.f + 2; + return _get(_getPrototypeOf(D), "f", this) + 2; }, D.classExprBoundary = class { constructor(){ this.a = super.f + 3; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.1.normal.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.1.normal.js index c162e23e39fb..bb989844b0b7 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.1.normal.js @@ -106,8 +106,6 @@ function _createSuper(Derived) { return _possibleConstructorReturn(this, result); }; } -var _superprop_get_f = ()=>super.f -; var C = function C() { "use strict"; _classCallCheck(this, C); @@ -124,10 +122,10 @@ var D = /*#__PURE__*/ function(C) { return D; }(C); D.arrowFunctionBoundary = function() { - return _superprop_get_f() + 1; + return _get(_getPrototypeOf(D), "f", D) + 1; }; D.functionExprBoundary = function() { - return super.f + 2; + return _get(_getPrototypeOf(D), "f", this) + 2; }; D.classExprBoundary = function _class() { "use strict"; @@ -136,7 +134,7 @@ D.classExprBoundary = function _class() { }; D.functionAndClassDeclBoundary = (function() { var foo = function foo() { - return super.f + 4; + return _get(_getPrototypeOf(D), "f", this) + 4; }; var C = /*#__PURE__*/ function() { "use strict"; diff --git a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.2.minified.js b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.2.minified.js index f627533486c4..fe2f9ef7e51b 100644 --- a/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeOfThisInStaticMembers9_es5.2.minified.js @@ -30,8 +30,7 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var _superprop_get_f = ()=>super.f -, C = function() { +var C = function() { "use strict"; _classCallCheck(this, C); }; @@ -74,9 +73,9 @@ var D = function(C1) { return D; }(C); D.arrowFunctionBoundary = function() { - return _superprop_get_f() + 1; + return _get(_getPrototypeOf(D), "f", D) + 1; }, D.functionExprBoundary = function() { - return super.f + 2; + return _get(_getPrototypeOf(D), "f", this) + 2; }, D.classExprBoundary = function _class() { "use strict"; _classCallCheck(this, _class), this.a = _get(_getPrototypeOf(_class.prototype), "f", this) + 3; diff --git a/crates/swc/tests/tsc-references/typeofThis_es2015.1.normal.js b/crates/swc/tests/tsc-references/typeofThis_es2015.1.normal.js index 239ed3b3e613..e1e56a76c809 100644 --- a/crates/swc/tests/tsc-references/typeofThis_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/typeofThis_es2015.1.normal.js @@ -1,4 +1,3 @@ -var _key; // @noImplicitThis: true // @strict: true class Test { @@ -12,7 +11,7 @@ class Test1 { this.data = { foo: '' }; - this[_key] = ''; + this['this'] = ''; var copy = { foo: '' }; @@ -22,7 +21,6 @@ class Test1 { var str = ''; } } -_key = 'this'; function Test2() { let x = 1; } diff --git a/crates/swc/tests/tsc-references/typeofThis_es2015.2.minified.js b/crates/swc/tests/tsc-references/typeofThis_es2015.2.minified.js index de819fcaf3d7..f1300e6383d9 100644 --- a/crates/swc/tests/tsc-references/typeofThis_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofThis_es2015.2.minified.js @@ -1,2 +1,2 @@ -var _key, Test6, Test7; -_key = "this", (Test6 || (Test6 = {})).f = ()=>{}, (Test7 || (Test7 = {})).f = ()=>{}, ()=>{}; +var Test6, Test7; +(Test6 || (Test6 = {})).f = ()=>{}, (Test7 || (Test7 = {})).f = ()=>{}, ()=>{}; diff --git a/crates/swc/tests/tsc-references/typeofThis_es5.1.normal.js b/crates/swc/tests/tsc-references/typeofThis_es5.1.normal.js index a72b016b4bea..a7b16f6bc1e2 100644 --- a/crates/swc/tests/tsc-references/typeofThis_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/typeofThis_es5.1.normal.js @@ -24,12 +24,9 @@ function _instanceof(left, right) { return left instanceof right; } } -var _key; var Test = function Test() { "use strict"; _classCallCheck(this, Test); - // @noImplicitThis: true - // @strict: true this.data = {}; var copy = {}; }; @@ -39,7 +36,7 @@ var Test1 = function Test1() { this.data = { foo: '' }; - this[_key] = ''; + this['this'] = ''; var copy = { foo: '' }; @@ -48,7 +45,6 @@ var Test1 = function Test1() { self.data; var str = ''; }; -_key = 'this'; function Test2() { var x = 1; } diff --git a/crates/swc/tests/tsc-references/typeofThis_es5.2.minified.js b/crates/swc/tests/tsc-references/typeofThis_es5.2.minified.js index 2f49fabb1bf1..ecfd5fe95c4c 100644 --- a/crates/swc/tests/tsc-references/typeofThis_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/typeofThis_es5.2.minified.js @@ -13,19 +13,15 @@ function _createClass(Constructor, protoProps, staticProps) { function _instanceof(left, right) { return null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right; } -var _key, Test6, Test7, Test = function() { +var Test6, Test7, Test = function() { "use strict"; _classCallCheck(this, Test), this.data = {}; }, Test1 = function() { "use strict"; _classCallCheck(this, Test1), this.data = { foo: "" - }, this[_key] = ""; - var self = this; - self.data; -}; -_key = "this"; -var Test5 = function() { + }, this.this = "", this.data; +}, Test5 = function() { "use strict"; _classCallCheck(this, Test5), this.no = 1, this.f = function() {}; }; diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es2015.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es2015.1.normal.js index 858cb60926e1..b153849d1d14 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es2015.1.normal.js @@ -15,6 +15,11 @@ class C { this.readwriteCall = Symbol(); } } -C.readonlyStaticCall = Symbol(); -C.readonlyStaticTypeAndCall = Symbol(); +/** + * @readonly + */ C.readonlyStaticCall = Symbol(); +/** + * @type {unique symbol} + * @readonly + */ C.readonlyStaticTypeAndCall = Symbol(); C.readwriteStaticCall = Symbol(); diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es5.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es5.1.normal.js index 95cccbd7e122..fa32b7acce4b 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarationsInJs_es5.1.normal.js @@ -8,18 +8,14 @@ var C = function C() { _classCallCheck(this, C); /** * @readonly - */ // @target: esnext - // @lib: esnext - // @declaration: true - // @allowJs: true - // @checkJs: true - // @filename: uniqueSymbolsDeclarationsInJs.js - // @out: uniqueSymbolsDeclarationsInJs-out.js - // @useDefineForClassFields: false - // classes - this.readonlyCall = Symbol(); + */ this.readonlyCall = Symbol(); this.readwriteCall = Symbol(); }; -C.readonlyStaticCall = Symbol(); -C.readonlyStaticTypeAndCall = Symbol(); +/** + * @readonly + */ C.readonlyStaticCall = Symbol(); +/** + * @type {unique symbol} + * @readonly + */ C.readonlyStaticTypeAndCall = Symbol(); C.readwriteStaticCall = Symbol(); diff --git a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations_es5.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations_es5.1.normal.js index 33e0183493d4..b5d200549c15 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbolsDeclarations_es5.1.normal.js @@ -353,7 +353,6 @@ function _asyncGenFuncYieldVarCall() { var C = function C() { "use strict"; _classCallCheck(this, C); - // classes this.readonlyCall = Symbol(); this.readwriteCall = Symbol(); }; diff --git a/crates/swc/tests/tsc-references/uniqueSymbols_es5.1.normal.js b/crates/swc/tests/tsc-references/uniqueSymbols_es5.1.normal.js index d757aa9ade17..e42b4aa68b12 100644 --- a/crates/swc/tests/tsc-references/uniqueSymbols_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/uniqueSymbols_es5.1.normal.js @@ -356,7 +356,6 @@ function _asyncGenFuncYieldVarCall() { var C = function C() { "use strict"; _classCallCheck(this, C); - // classes this.readonlyCall = Symbol(); this.readwriteCall = Symbol(); }; diff --git a/crates/swc/tests/tsc-references/witness_es2015.1.normal.js b/crates/swc/tests/tsc-references/witness_es2015.1.normal.js index 05e9ae1150e0..723ee031cf2a 100644 --- a/crates/swc/tests/tsc-references/witness_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/witness_es2015.1.normal.js @@ -105,8 +105,8 @@ var M2; // Property access of class instance type class C2 { constructor(){ - this.n // n: any - = this.n; + this.n = this.n // n: any + ; } } var c2inst = new C2().n; diff --git a/crates/swc/tests/tsc-references/witness_es5.1.normal.js b/crates/swc/tests/tsc-references/witness_es5.1.normal.js index 040d642a8b6f..7cd4eecbd4c7 100644 --- a/crates/swc/tests/tsc-references/witness_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/witness_es5.1.normal.js @@ -149,9 +149,8 @@ var M2; var C2 = function C2() { "use strict"; _classCallCheck(this, C2); - // Property access of class instance type - this.n // n: any - = this.n; + this.n = this.n // n: any + ; }; var c2inst = new C2().n; var c2inst; diff --git a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts index 5e8f20fd9915..9925a2121815 100644 --- a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.inlined.ts @@ -1838,19 +1838,19 @@ class BufferFullError extends Error { } } class PartialReadError extends Deno.errors.UnexpectedEof { + name = "PartialReadError"; constructor(){ super("Encountered UnexpectedEof, data only partially read"); - this.name = "PartialReadError"; } } class BufReader { + r = 0; + w = 0; + eof = false; static create(r, size = 4096) { return r instanceof BufReader ? r : new BufReader(r, size); } constructor(rd, size = 4096){ - this.r = 0; - this.w = 0; - this.eof = false; if (size < 16) { size = MIN_BUF_SIZE; } @@ -2053,6 +2053,8 @@ class BufReader { } } class AbstractBufBase { + usedBufferBytes = 0; + err = null; size() { return this.buf.byteLength; } @@ -2062,10 +2064,6 @@ class AbstractBufBase { buffered() { return this.usedBufferBytes; } - constructor(){ - this.usedBufferBytes = 0; - this.err = null; - } } class BufWriter extends AbstractBufBase { static create(writer, size = 4096) { @@ -2236,11 +2234,11 @@ class WriterHandler extends BaseHandler { #encoder = new TextEncoder(); } class FileHandler extends WriterHandler { + _encoder = new TextEncoder(); #unloadCallback = ()=>this.destroy() ; constructor(levelName, options){ super(levelName, options); - this._encoder = new TextEncoder(); this._filename = options.filename; this._mode = options.mode ? options.mode : "a"; this._openOptions = { @@ -5839,10 +5837,10 @@ class ADLMap { } } class TaskManifest { + lastExecution = null; + trackedFiles = new ADLMap([], (k1, k2)=>k1 === k2 + ); constructor(data){ - this.lastExecution = null; - this.trackedFiles = new ADLMap([], (k1, k2)=>k1 === k2 - ); this.trackedFiles = new ADLMap(data.trackedFiles, (k1, k2)=>k1 === k2 ); this.lastExecution = data.lastExecution; @@ -5896,8 +5894,8 @@ async function statPath(path36) { } } class Task { + taskManifest = null; constructor(taskParams){ - this.taskManifest = null; this.name = taskParams.name; this.action = taskParams.action; this.description = taskParams.description; @@ -6024,11 +6022,11 @@ class Task { } } class TrackedFile { + path = ""; #getHash; #getTimestamp; + fromTask = null; constructor(fileParams){ - this.path = ""; - this.fromTask = null; this.path = mod3.posix.resolve(fileParams.path); this.#getHash = fileParams.getHash || getFileSha1Sum; this.#getTimestamp = fileParams.getTimestamp || getFileTimestamp; diff --git a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts index da32d10577ce..d6a180462958 100644 --- a/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/deno-9591/output/entry.ts @@ -1849,19 +1849,19 @@ class BufferFullError extends Error { } } class PartialReadError extends Deno.errors.UnexpectedEof { + name = "PartialReadError"; constructor(){ super("Encountered UnexpectedEof, data only partially read"); - this.name = "PartialReadError"; } } class BufReader { + r = 0; + w = 0; + eof = false; static create(r, size = DEFAULT_BUF_SIZE) { return r instanceof BufReader ? r : new BufReader(r, size); } constructor(rd, size = DEFAULT_BUF_SIZE){ - this.r = 0; - this.w = 0; - this.eof = false; if (size < MIN_BUF_SIZE) { size = MIN_BUF_SIZE; } @@ -2064,6 +2064,8 @@ class BufReader { } } class AbstractBufBase { + usedBufferBytes = 0; + err = null; size() { return this.buf.byteLength; } @@ -2073,10 +2075,6 @@ class AbstractBufBase { buffered() { return this.usedBufferBytes; } - constructor(){ - this.usedBufferBytes = 0; - this.err = null; - } } class BufWriter extends AbstractBufBase { static create(writer, size = DEFAULT_BUF_SIZE) { @@ -2247,11 +2245,11 @@ class WriterHandler extends BaseHandler { #encoder = new TextEncoder(); } class FileHandler extends WriterHandler { + _encoder = new TextEncoder(); #unloadCallback = ()=>this.destroy() ; constructor(levelName, options){ super(levelName, options); - this._encoder = new TextEncoder(); this._filename = options.filename; this._mode = options.mode ? options.mode : "a"; this._openOptions = { @@ -5851,10 +5849,10 @@ class ADLMap { } } class TaskManifest { + lastExecution = null; + trackedFiles = new ADLMap([], (k1, k2)=>k1 === k2 + ); constructor(data){ - this.lastExecution = null; - this.trackedFiles = new ADLMap([], (k1, k2)=>k1 === k2 - ); this.trackedFiles = new ADLMap(data.trackedFiles, (k1, k2)=>k1 === k2 ); this.lastExecution = data.lastExecution; @@ -5908,8 +5906,8 @@ async function statPath(path36) { } } class Task { + taskManifest = null; constructor(taskParams){ - this.taskManifest = null; this.name = taskParams.name; this.action = taskParams.action; this.description = taskParams.description; @@ -6036,11 +6034,11 @@ class Task { } } class TrackedFile { + path = ""; #getHash; #getTimestamp; + fromTask = null; constructor(fileParams){ - this.path = ""; - this.fromTask = null; this.path = mod3.posix.resolve(fileParams.path); this.#getHash = fileParams.getHash || getFileSha1Sum; this.#getTimestamp = fileParams.getTimestamp || getFileTimestamp; diff --git a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts index fb8e1517e1e3..0cd13a982fe3 100644 --- a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.inlined.ts @@ -127,8 +127,8 @@ class StringReader extends Deno.Buffer { } } class MultiReader { + currentIndex = 0; constructor(...readers){ - this.currentIndex = 0; this.readers = readers; } async read(p) { @@ -1208,19 +1208,19 @@ class BufferFullError extends Error { } } class PartialReadError extends Deno.errors.UnexpectedEof { + name = "PartialReadError"; constructor(){ super("Encountered UnexpectedEof, data only partially read"); - this.name = "PartialReadError"; } } class BufReader { + r = 0; + w = 0; + eof = false; static create(r, size = 4096) { return r instanceof BufReader ? r : new BufReader(r, size); } constructor(rd, size = 4096){ - this.r = 0; - this.w = 0; - this.eof = false; if (size < 16) { size = MIN_BUF_SIZE; } @@ -1423,6 +1423,8 @@ class BufReader { } } class AbstractBufBase { + usedBufferBytes = 0; + err = null; size() { return this.buf.byteLength; } @@ -1432,10 +1434,6 @@ class AbstractBufBase { buffered() { return this.usedBufferBytes; } - constructor(){ - this.usedBufferBytes = 0; - this.err = null; - } } class BufWriter extends AbstractBufBase { static create(writer, size = 4096) { diff --git a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts index 8002f59aa4a8..bbb9a7e91c10 100644 --- a/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/deno-9620/case1/output/entry.ts @@ -127,8 +127,8 @@ class StringReader extends Deno.Buffer { } } class MultiReader { + currentIndex = 0; constructor(...readers){ - this.currentIndex = 0; this.readers = readers; } async read(p) { @@ -1217,19 +1217,19 @@ class BufferFullError extends Error { } } class PartialReadError extends Deno.errors.UnexpectedEof { + name = "PartialReadError"; constructor(){ super("Encountered UnexpectedEof, data only partially read"); - this.name = "PartialReadError"; } } class BufReader { + r = 0; + w = 0; + eof = false; static create(r, size = DEFAULT_BUF_SIZE) { return r instanceof BufReader ? r : new BufReader(r, size); } constructor(rd, size = DEFAULT_BUF_SIZE){ - this.r = 0; - this.w = 0; - this.eof = false; if (size < MIN_BUF_SIZE) { size = MIN_BUF_SIZE; } @@ -1432,6 +1432,8 @@ class BufReader { } } class AbstractBufBase { + usedBufferBytes = 0; + err = null; size() { return this.buf.byteLength; } @@ -1441,10 +1443,6 @@ class AbstractBufBase { buffered() { return this.usedBufferBytes; } - constructor(){ - this.usedBufferBytes = 0; - this.err = null; - } } class BufWriter extends AbstractBufBase { static create(writer, size = DEFAULT_BUF_SIZE) { diff --git a/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.inlined.ts index 0bff4b5c9fa3..409e58e27b21 100644 --- a/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.inlined.ts @@ -9,14 +9,12 @@ function d() { return Object.assign(promise, methods); } class A { + s = d(); a() { this.s.resolve(); } b() { this.s = d(); } - constructor(){ - this.s = d(); - } } new A(); diff --git a/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.ts b/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.ts index 0bff4b5c9fa3..409e58e27b21 100644 --- a/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/issue-1156-1/output/entry.ts @@ -9,14 +9,12 @@ function d() { return Object.assign(promise, methods); } class A { + s = d(); a() { this.s.resolve(); } b() { this.s = d(); } - constructor(){ - this.s = d(); - } } new A(); diff --git a/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.inlined.ts index 2c511528011b..1c7a8c99197e 100644 --- a/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.inlined.ts +++ b/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.inlined.ts @@ -9,11 +9,9 @@ function d() { return Object.assign(promise, methods); } class A { + s = d(); a() { this.s.resolve(); } - constructor(){ - this.s = d(); - } } new A(); diff --git a/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.ts b/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.ts index 2c511528011b..1c7a8c99197e 100644 --- a/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.ts +++ b/crates/swc_bundler/tests/fixture/issue-1156-2/output/entry.ts @@ -9,11 +9,9 @@ function d() { return Object.assign(promise, methods); } class A { + s = d(); a() { this.s.resolve(); } - constructor(){ - this.s = d(); - } } new A(); diff --git a/crates/swc_ecma_preset_env/benches/polyfills.rs b/crates/swc_ecma_preset_env/benches/polyfills.rs index 46003595bd0d..2636ec01d12a 100644 --- a/crates/swc_ecma_preset_env/benches/polyfills.rs +++ b/crates/swc_ecma_preset_env/benches/polyfills.rs @@ -27,6 +27,7 @@ fn run(b: &mut Bencher, src: &str, config: Config) { Mark::fresh(Mark::root()), Some(SingleThreadedComments::default()), config, + Default::default(), ); b.iter(|| test::black_box(module.clone().fold_with(&mut folder))); diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 24d03a605cd7..fe6ef8701c88 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -13,6 +13,7 @@ use swc_ecma_ast::*; use swc_ecma_transforms::{ compat::{bugfixes, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es3}, pass::{noop, Optional}, + Assumptions, }; use swc_ecma_utils::prepend_stmts; use swc_ecma_visit::{Fold, FoldWith, VisitWith}; @@ -26,7 +27,12 @@ mod corejs3; mod regenerator; mod transform_data; -pub fn preset_env(global_mark: Mark, comments: Option, c: Config) -> impl Fold +pub fn preset_env( + global_mark: Mark, + comments: Option, + c: Config, + assumptions: Assumptions, +) -> impl Fold where C: Comments, { @@ -93,10 +99,10 @@ where pass, ClassProperties, es2022::class_properties(es2022::class_properties::Config { - private_as_properties: loose, - set_public_fields: loose, - constant_super: loose, - no_document_all: loose + private_as_properties: loose || assumptions.private_fields_as_properties, + set_public_fields: loose || assumptions.set_public_class_fields, + constant_super: loose || assumptions.constant_super, + no_document_all: loose || assumptions.no_document_all }) ); let pass = add!(pass, PrivatePropertyInObject, es2022::private_in_object()); @@ -115,7 +121,7 @@ where pass, NullishCoalescing, es2020::nullish_coalescing(es2020::nullish_coalescing::Config { - no_document_all: loose + no_document_all: loose || assumptions.no_document_all }) ); @@ -123,8 +129,8 @@ where pass, OptionalChaining, es2020::optional_chaining(es2020::opt_chaining::Config { - no_document_all: loose, - pure_getter: loose + no_document_all: loose || assumptions.no_document_all, + pure_getter: loose || assumptions.pure_getters }) ); @@ -136,8 +142,8 @@ where pass, ObjectRestSpread, es2018::object_rest_spread(es2018::object_rest_spread::Config { - no_symbol: loose, - set_property: loose + no_symbol: loose || assumptions.object_rest_no_symbols, + set_property: loose || assumptions.set_spread_properties }) ); @@ -153,8 +159,8 @@ where pass, TemplateLiterals, es2015::template_literal(es2015::template_literal::Config { - ignore_to_primitive: loose, - mutable_template: loose + ignore_to_primitive: loose || assumptions.ignore_to_primitive_hint, + mutable_template: loose || assumptions.mutable_template_object }), true ); @@ -164,10 +170,10 @@ where es2015::classes( comments, es2015::classes::Config { - constant_super: loose, - no_class_calls: loose, - set_class_methods: loose, - super_is_callable_constructor: loose, + constant_super: loose || assumptions.constant_super, + no_class_calls: loose || assumptions.no_class_calls, + set_class_methods: loose || assumptions.set_class_methods, + super_is_callable_constructor: loose || assumptions.super_is_callable_constructor, } ) ); @@ -188,14 +194,14 @@ where pass, Parameters, es2015::parameters(es2015::parameters::Config { - ignore_function_length: loose + ignore_function_length: loose || assumptions.ignore_function_length }) ); let pass = add!( pass, ForOf, es2015::for_of(es2015::for_of::Config { - assume_array: loose + assume_array: loose || assumptions.iterable_is_array }), true ); diff --git a/crates/swc_ecma_preset_env/tests/test.rs b/crates/swc_ecma_preset_env/tests/test.rs index b482a1ee33af..e18455b691cb 100644 --- a/crates/swc_ecma_preset_env/tests/test.rs +++ b/crates/swc_ecma_preset_env/tests/test.rs @@ -149,6 +149,7 @@ fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { targets: c.targets, path: std::env::current_dir().unwrap(), }, + Default::default() ), fixer(None) ); diff --git a/crates/swc_ecma_transforms/tests/decorators.rs b/crates/swc_ecma_transforms/tests/decorators.rs index 89ad022d1be8..4f1cda5d415d 100644 --- a/crates/swc_ecma_transforms/tests/decorators.rs +++ b/crates/swc_ecma_transforms/tests/decorators.rs @@ -63,6 +63,10 @@ fn simple_strip(config: Config) -> impl Fold { }, mark ), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }) ) } @@ -4309,17 +4313,17 @@ class Person { const p = new Person(); p.save();", - "var _class; -var _class1, _dec; + "var _Person; +var _class, _dec; import { Debounce } from 'lodash-decorators'; -let Person = ((_class1 = (_class = class Person { +let Person = ((_class = (_Person = class Person { save() { console.log('Hello World!'); } -}, _class.debounceTime = 500, _class)) || _class1, _dec = Debounce(_class1.debounceTime), \ - _applyDecoratedDescriptor(_class1.prototype, 'save', [ +}, _Person.debounceTime = 500, _Person)) || _class, _dec = Debounce(_class.debounceTime), \ + _applyDecoratedDescriptor(_class.prototype, 'save', [ _dec -], Object.getOwnPropertyDescriptor(_class1.prototype, 'save'), _class1.prototype), _class1); +], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _class); const p = new Person(); p.save();" ); @@ -4349,17 +4353,17 @@ class Person { const p = new Person(); p.save();", - "var _class; -var _class1, _dec; + "var _Person; +var _class, _dec; import { Debounce } from 'lodash-decorators'; -let Person = ((_class1 = (_class = class Person { +let Person = ((_class = (_Person = class Person { save() { console.log('Hello World!'); } -}, _class.debounceTime = 500, _class)) || _class1, _dec = Debounce(_class1.debounceTime), \ - _applyDecoratedDescriptor(_class1.prototype, 'save', [ +}, _Person.debounceTime = 500, _Person)) || _class, _dec = Debounce(_class.debounceTime), \ + _applyDecoratedDescriptor(_class.prototype, 'save', [ _dec -], Object.getOwnPropertyDescriptor(_class1.prototype, 'save'), _class1.prototype), _class1); +], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _class); const p = new Person(); p.save(); " @@ -4390,10 +4394,10 @@ class Person { const p = new Person(); p.save();", - "var _class; -var _class1, _dec; + "var _Person; +var _class, _dec; import { Debounce } from 'lodash-decorators'; -let Person = ((_class1 = (_class = function() { +let Person = ((_class = (_Person = function() { 'use strict'; function Person1() { _classCallCheck(this, Person1); @@ -4407,10 +4411,10 @@ let Person = ((_class1 = (_class = function() { } ]); return Person1; -}(), _class.debounceTime = 500, _class)) || _class1, _dec = Debounce(_class1.debounceTime), \ - _applyDecoratedDescriptor(_class1.prototype, 'save', [ +}(), _Person.debounceTime = 500, _Person)) || _class, _dec = Debounce(_class.debounceTime), \ + _applyDecoratedDescriptor(_class.prototype, 'save', [ _dec -], Object.getOwnPropertyDescriptor(_class1.prototype, 'save'), _class1.prototype), _class1); +], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _class); const p = new Person(); p.save();" ); diff --git a/crates/swc_ecma_transforms_base/src/assumptions.rs b/crates/swc_ecma_transforms_base/src/assumptions.rs index b4eaea0a5379..d66128f30343 100644 --- a/crates/swc_ecma_transforms_base/src/assumptions.rs +++ b/crates/swc_ecma_transforms_base/src/assumptions.rs @@ -10,67 +10,90 @@ use serde::{Deserialize, Serialize}; #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct Assumptions { /// https://babeljs.io/docs/en/assumptions#arraylikeisiterable + #[serde(default)] pub array_like_is_iterable: bool, /// https://babeljs.io/docs/en/assumptions#constantreexports + #[serde(default)] pub constant_reexports: bool, /// https://babeljs.io/docs/en/assumptions#constantsuper + #[serde(default)] pub constant_super: bool, /// https://babeljs.io/docs/en/assumptions#enumerablemodulemeta + #[serde(default)] pub enumerable_module_meta: bool, /// https://babeljs.io/docs/en/assumptions#ignorefunctionlength + #[serde(default)] pub ignore_function_length: bool, /// https://babeljs.io/docs/en/assumptions#ignoretoprimitivehint + #[serde(default)] pub ignore_to_primitive_hint: bool, /// https://babeljs.io/docs/en/assumptions#iterableisarray + #[serde(default)] pub iterable_is_array: bool, /// https://babeljs.io/docs/en/assumptions#mutabletemplateobject + #[serde(default)] pub mutable_template_object: bool, /// https://babeljs.io/docs/en/assumptions#noclasscalls + #[serde(default)] pub no_class_calls: bool, /// https://babeljs.io/docs/en/assumptions#nodocumentall + #[serde(default)] pub no_document_all: bool, /// https://babeljs.io/docs/en/assumptions#noincompletensimportdetection + #[serde(default)] pub no_incomplete_ns_import_detection: bool, /// https://babeljs.io/docs/en/assumptions#nonewarrows + #[serde(default)] pub no_new_arrows: bool, + /// https://babeljs.io/docs/en/assumptions#objectrestnosymbols + #[serde(default)] pub object_rest_no_symbols: bool, /// https://babeljs.io/docs/en/assumptions#privatefieldsasproperties + #[serde(default)] pub private_fields_as_properties: bool, /// https://babeljs.io/docs/en/assumptions#puregetters + #[serde(default)] pub pure_getters: bool, /// https://babeljs.io/docs/en/assumptions#setclassmethods + #[serde(default)] pub set_class_methods: bool, /// https://babeljs.io/docs/en/assumptions#setcomputedproperties + #[serde(default)] pub set_computed_properties: bool, /// https://babeljs.io/docs/en/assumptions#setpublicclassfields + #[serde(default)] pub set_public_class_fields: bool, /// https://babeljs.io/docs/en/assumptions#setspreadproperties + #[serde(default)] pub set_spread_properties: bool, /// https://babeljs.io/docs/en/assumptions#skipforofiteratorclosing + #[serde(default)] pub skip_for_of_iterator_closing: bool, /// https://babeljs.io/docs/en/assumptions#superiscallableconstructor + #[serde(default)] pub super_is_callable_constructor: bool, + #[serde(default)] pub ts_enum_is_readonly: bool, } diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs index afbefd6381eb..6bd181518076 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs @@ -147,20 +147,6 @@ impl Take for ClassExtra { impl VisitMut for ClassProperties { noop_visit_mut_type!(); - fn visit_mut_ident(&mut self, i: &mut Ident) { - i.optional = false; - } - - fn visit_mut_array_pat(&mut self, p: &mut ArrayPat) { - p.visit_mut_children_with(self); - p.optional = false; - } - - fn visit_mut_object_pat(&mut self, p: &mut ObjectPat) { - p.visit_mut_children_with(self); - p.optional = false; - } - fn visit_mut_module_items(&mut self, n: &mut Vec) { self.visit_mut_stmt_like(n); @@ -174,8 +160,6 @@ impl VisitMut for ClassProperties { } fn visit_mut_block_stmt_or_expr(&mut self, body: &mut BlockStmtOrExpr) { - let span = body.span(); - match body { BlockStmtOrExpr::Expr(expr) if expr.is_class() => { let ClassExpr { ident, class } = expr.take().class().unwrap(); @@ -191,7 +175,10 @@ impl VisitMut for ClassProperties { arg: Some(Box::new(Expr::Ident(ident))), })); - *body = BlockStmtOrExpr::BlockStmt(BlockStmt { span, stmts }); + *body = BlockStmtOrExpr::BlockStmt(BlockStmt { + span: DUMMY_SP, + stmts, + }); } _ => body.visit_mut_children_with(self), }; @@ -974,24 +961,6 @@ struct ShouldWork { impl Visit for ShouldWork { noop_visit_type!(); - fn visit_ident(&mut self, n: &Ident) { - if n.optional { - self.found = true; - } - } - - fn visit_array_pat(&mut self, n: &ArrayPat) { - if n.optional { - self.found = true; - } - } - - fn visit_object_pat(&mut self, n: &ObjectPat) { - if n.optional { - self.found = true; - } - } - fn visit_class_method(&mut self, _: &ClassMethod) { self.found = true; } diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs index d0c605edbc8c..321f3865cbbc 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs @@ -3,7 +3,7 @@ use std::{fs::read_to_string, path::PathBuf}; use swc_common::chain; -use swc_ecma_parser::{EsConfig, Syntax, TsConfig}; +use swc_ecma_parser::{EsConfig, Syntax}; use swc_ecma_transforms_base::resolver::resolver; use swc_ecma_transforms_compat::{ es2015::{arrow, block_scoping, classes, function_name, template_literal}, @@ -15,12 +15,6 @@ use swc_ecma_transforms_compat::{ use swc_ecma_transforms_testing::{compare_stdout, test, test_exec, Tester}; use swc_ecma_visit::Fold; -fn ts() -> Syntax { - Syntax::Typescript(TsConfig { - ..Default::default() - }) -} - fn syntax() -> Syntax { Syntax::Es(EsConfig { ..Default::default() @@ -4839,36 +4833,6 @@ expect(foo.y).toBe('bar'); "# ); -test!( - ts(), - |_| chain!(resolver(), class_properties(Default::default())), - issue_890_1, - "const DURATION = 1000 - -export class HygieneTest { - private readonly duration: number = DURATION - - constructor(duration?: number) { - this.duration = duration ?? DURATION - } - - getDuration() { - return this.duration - } -}", - "const DURATION = 1000; -export class HygieneTest { - getDuration() { - return this.duration; - } - constructor(duration: number){ - _defineProperty(this, 'duration', DURATION); - this.duration = duration ?? DURATION; - } -}", - ok_if_code_eq -); - test!( syntax(), |_| class_properties(Default::default()), diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify.rs b/crates/swc_ecma_transforms_optimization/tests/simplify.rs index 5f574c775079..587cfafc0c2d 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify.rs @@ -478,6 +478,10 @@ test!( chain!( resolver_with_mark(mark), strip(mark), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }), dce(Default::default()), inlining(Default::default()) ) diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs index 5cf6928c13dc..371254997ca9 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_dce.rs @@ -1,6 +1,7 @@ use swc_common::{chain, pass::Repeat, Mark}; use swc_ecma_parser::{EsConfig, Syntax, TsConfig}; use swc_ecma_transforms_base::resolver::{resolver, resolver_with_mark}; +use swc_ecma_transforms_compat::es2022::class_properties; use swc_ecma_transforms_optimization::simplify::dce::dce; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::test; @@ -542,7 +543,15 @@ test!( }), |_| { let mark = Mark::fresh(Mark::root()); - chain!(resolver_with_mark(mark), strip(mark), tr()) + chain!( + resolver_with_mark(mark), + strip(mark), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }), + tr() + ) }, issue_1156_1, " @@ -580,7 +589,15 @@ test!( }), |_| { let mark = Mark::fresh(Mark::root()); - chain!(resolver_with_mark(mark), strip(mark), tr(),) + chain!( + resolver_with_mark(mark), + strip(mark), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }), + tr(), + ) }, issue_1156_2, " @@ -680,7 +697,15 @@ test!( }), |_| { let mark = Mark::fresh(Mark::root()); - chain!(resolver_with_mark(mark), strip(mark), tr(),) + chain!( + resolver_with_mark(mark), + strip(mark), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }), + tr(), + ) }, issue_1156_4, " diff --git a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs index 0884b24c575c..569ee4f36043 100644 --- a/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs +++ b/crates/swc_ecma_transforms_optimization/tests/simplify_inlining.rs @@ -3,6 +3,7 @@ use swc_common::{chain, Mark}; use swc_ecma_parser::{Syntax, TsConfig}; use swc_ecma_transforms_base::resolver::{resolver, resolver_with_mark}; +use swc_ecma_transforms_compat::es2022::class_properties; use swc_ecma_transforms_optimization::simplify::inlining::inlining; use swc_ecma_transforms_testing::test; use swc_ecma_transforms_typescript::strip; @@ -2158,6 +2159,10 @@ test!( chain!( resolver_with_mark(mark), simple_strip(mark), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }), inlining(Default::default()) ) }, @@ -2200,6 +2205,10 @@ test!( chain!( resolver_with_mark(mark), simple_strip(mark), + class_properties(class_properties::Config { + set_public_fields: true, + ..Default::default() + }), inlining(Default::default()) ) }, diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index de2160b80dad..e865fc4e6639 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -13,9 +13,8 @@ use swc_common::{ use swc_ecma_ast::*; use swc_ecma_transforms_react::{parse_expr_for_jsx, JsxDirectives}; use swc_ecma_utils::{ - constructor::inject_after_super, default_constructor, ident::IdentLike, member_expr, prepend, - private_ident, quote_ident, replace_ident, var::VarCollector, ExprFactory, Id, ModuleItemLike, - StmtLike, + alias_ident_for, constructor::inject_after_super, ident::IdentLike, is_literal, member_expr, + prepend, private_ident, prop_name_to_expr, quote_ident, var::VarCollector, ExprFactory, Id, }; use swc_ecma_visit::{ as_folder, noop_visit_mut_type, visit_obj_and_computed, Fold, Visit, VisitMut, VisitMutWith, @@ -128,6 +127,7 @@ pub fn strip_with_config(config: Config, top_level_mark: Mark) -> impl Fold + Vi uninitialized_vars: Default::default(), decl_names: Default::default(), in_var_pat: Default::default(), + keys: Default::default() }), inline_enum(ts_enum_lit, ts_enum_config) ) @@ -198,6 +198,7 @@ where uninitialized_vars: Default::default(), decl_names: Default::default(), in_var_pat: Default::default(), + keys: Default::default(), }), inline_enum(ts_enum_lit, ts_enum_config) ) @@ -253,6 +254,8 @@ where /// This field is filled by [Visit] impl and [VisitMut] impl. decl_names: AHashSet, in_var_pat: bool, + + keys: Vec, } impl Strip @@ -395,387 +398,8 @@ impl Strip where C: Comments, { - fn fold_class_as_decl( - &mut self, - ident: Ident, - orig_ident: Option, - mut class: Class, - ) -> (Decl, Vec>) { - class.is_abstract = false; - class.type_params = None; - class.super_type_params = None; - class.implements = Default::default(); - - class.body.retain(|c| { - !matches!( - c, - ClassMember::Constructor(Constructor { body: None, .. }) - | ClassMember::ClassProp(ClassProp { declare: true, .. }) - ) - }); - - let mut extra_exprs = vec![]; - if self.config.use_define_for_class_fields { - let mut param_class_fields = vec![]; - for member in &class.body { - if let ClassMember::Constructor(constructor) = member { - for param in &constructor.params { - if let ParamOrTsParamProp::TsParamProp(param_prop) = param { - let ident = match ¶m_prop.param { - TsParamPropParam::Ident(ident) => ident.id.clone(), - TsParamPropParam::Assign(pat) => { - pat.clone().left.ident().unwrap().id - } - }; - let param_class_field = ClassMember::ClassProp(ClassProp { - span: class.span, - key: PropName::Ident(ident), - value: None, - type_ann: None, - is_static: false, - decorators: param_prop.decorators.clone(), - accessibility: param_prop.accessibility, - is_abstract: false, - is_optional: false, - is_override: param_prop.is_override, - readonly: param_prop.readonly, - declare: false, - definite: false, - }); - param_class_fields.push(param_class_field); - } - } - break; - } - } - if !param_class_fields.is_empty() { - param_class_fields.append(&mut class.body.take()); - class.body = param_class_fields; - } - } else { - for m in class.body.iter_mut() { - if let ClassMember::ClassProp(m) = m { - if m.is_static { - if let Some(orig_ident) = &orig_ident { - replace_ident(&mut m.value, orig_ident.to_id(), &ident) - } - } - } - } - - let mut key_computations = vec![]; - let mut assign_exprs = vec![]; - let mut new_body = vec![]; - for member in take(&mut class.body) { - match member { - ClassMember::ClassProp(mut class_field) - if !class_field.is_static && class_field.decorators.is_empty() => - { - if let Some(value) = class_field.value.take() { - let prop = match class_field.key.take() { - PropName::Computed(key) => { - let ident = private_ident!("_key"); - self.uninitialized_vars.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: None, - definite: false, - }); - let assign_lhs = - PatOrExpr::Expr(Box::new(Expr::Ident(ident.clone()))); - let assign_expr = Box::new(Expr::Assign(AssignExpr { - span: class_field.span, - op: op!("="), - left: assign_lhs, - right: key.expr, - })); - key_computations.push(assign_expr); - MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Ident(ident)), - span: DUMMY_SP, - }) - } - PropName::Ident(id) => MemberProp::Ident(id), - PropName::Str(s) => MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Lit(Lit::Str(s))), - span: DUMMY_SP, - }), - PropName::Num(num) => MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Lit(Lit::Num(num))), - span: DUMMY_SP, - }), - PropName::BigInt(big_int) => { - MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Lit(Lit::BigInt(big_int))), - span: DUMMY_SP, - }) - } - }; - let assign_lhs = PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { - span: class_field.span, - obj: Box::new(Expr::This(ThisExpr { span: class.span })), - prop, - }))); - let assign_expr = Box::new(Expr::Assign(AssignExpr { - span: class_field.span, - op: op!("="), - left: assign_lhs, - right: value, - })); - assign_exprs.push(assign_expr); - } - } - ClassMember::ClassProp(mut class_field) - if class_field.is_static && class_field.decorators.is_empty() => - { - if let Some(mut value) = class_field.value.take() { - let prop = match class_field.key.take() { - // make an prop_name_to_member - PropName::Computed(key) => { - let ident = private_ident!("_key"); - self.uninitialized_vars.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: None, - definite: false, - }); - let assign_lhs = - PatOrExpr::Expr(Box::new(Expr::Ident(ident.clone()))); - let assign_expr = Box::new(Expr::Assign(AssignExpr { - span: class_field.span, - op: op!("="), - left: assign_lhs, - right: key.expr, - })); - key_computations.push(assign_expr); - MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Ident(ident)), - span: DUMMY_SP, - }) - } - PropName::Ident(id) => MemberProp::Ident(id), - PropName::Str(s) => MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Lit(Lit::Str(s))), - span: DUMMY_SP, - }), - PropName::Num(num) => MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Lit(Lit::Num(num))), - span: DUMMY_SP, - }), - PropName::BigInt(big_int) => { - MemberProp::Computed(ComputedPropName { - expr: Box::new(Expr::Lit(Lit::BigInt(big_int))), - span: DUMMY_SP, - }) - } - }; - let assign_lhs = PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { - span: DUMMY_SP, - obj: Box::new(Expr::Ident(ident.clone())), - prop, - }))); - - value.visit_mut_with(&mut ThisInStaticFolder { - ident: ident.clone(), - }); - - extra_exprs.push(Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: assign_lhs, - right: value, - }))); - } - } - ClassMember::Method(mut method) => { - if !key_computations.is_empty() { - if let PropName::Computed(name) = &mut method.key { - // If a computed method name is encountered, dump the other key - // assignments before it in a sequence expression. Note how this - // always preserves the order of key computations. This - // behavior is taken from TSC output. - key_computations.push(name.expr.take()); - name.expr = Box::new(Expr::Seq(SeqExpr { - span: name.span, - exprs: take(&mut key_computations), - })); - } - } - new_body.push(ClassMember::Method(method)); - } - _ => { - new_body.push(member); - } - } - } - if !assign_exprs.is_empty() { - for member in &mut new_body { - if let ClassMember::Constructor(constructor) = member { - inject_after_super(constructor, take(&mut assign_exprs)); - break; - } - } - if !assign_exprs.is_empty() { - let mut constructor = default_constructor(class.super_class.is_some()); - inject_after_super(&mut constructor, assign_exprs); - new_body.push(ClassMember::Constructor(constructor)); - } - } - class.body = new_body; - key_computations.append(&mut extra_exprs); - extra_exprs = key_computations; - } - - class.decorators.visit_mut_with(self); - class.body.visit_mut_with(self); - class.super_class.visit_mut_with(self); - extra_exprs.visit_mut_with(self); - ( - Decl::Class(ClassDecl { - ident, - declare: false, - class, - }), - extra_exprs, - ) - } - - fn visit_mut_stmt_like(&mut self, stmts: &mut Vec) - where - T: StmtLike + ModuleItemLike + VisitMutWith, - { - for stmt in take(stmts) { - match T::try_into_stmt(stmt) { - Ok(stmt) => match stmt { - Stmt::Decl(Decl::Class(ClassDecl { - ident, - declare: false, - class, - })) => { - let orig_ident = ident.clone(); - let (decl, extra_exprs) = - self.fold_class_as_decl(ident, Some(orig_ident), class); - stmts.push(T::from_stmt(Stmt::Decl(decl))); - stmts.extend(extra_exprs.into_iter().map(|e| T::from_stmt(e.into_stmt()))); - } - _ => stmts.push(T::from_stmt(stmt)), - }, - Err(node) => { - match node.try_into_module_decl() { - Ok(decl) => match decl { - ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { - span, - decl: DefaultDecl::Class(ClassExpr { ident, class }), - .. - }) => { - let orig_ident = ident.clone(); - let ident = ident.unwrap_or_else(|| private_ident!("_class")); - let (decl, extra_exprs) = - self.fold_class_as_decl(ident.clone(), orig_ident, class); - stmts.push(T::from_stmt(Stmt::Decl(decl))); - stmts.extend( - extra_exprs.into_iter().map(|e| T::from_stmt(e.into_stmt())), - ); - stmts.push( - match T::try_from_module_decl(ModuleDecl::ExportNamed( - NamedExport { - span, - specifiers: vec![ExportNamedSpecifier { - span: DUMMY_SP, - orig: ModuleExportName::Ident(ident), - exported: Some(ModuleExportName::Ident( - Ident::new(js_word!("default"), DUMMY_SP), - )), - is_type_only: false, - } - .into()], - src: None, - type_only: false, - asserts: None, - }, - )) { - Ok(t) => t, - Err(..) => unreachable!(), - }, - ); - } - ModuleDecl::ExportDecl(ExportDecl { - span, - decl: - Decl::Class(ClassDecl { - ident, - declare: false, - class, - }), - .. - }) => { - let orig_ident = ident.clone(); - let (decl, extra_exprs) = - self.fold_class_as_decl(ident, Some(orig_ident), class); - stmts.push( - match T::try_from_module_decl(ModuleDecl::ExportDecl( - ExportDecl { span, decl }, - )) { - Ok(t) => t, - Err(..) => unreachable!(), - }, - ); - stmts.extend( - extra_exprs.into_iter().map(|e| T::from_stmt(e.into_stmt())), - ); - } - _ => stmts.push(match T::try_from_module_decl(decl) { - Ok(t) => t, - Err(..) => unreachable!(), - }), - }, - Err(_) => unreachable!(), - } - } - } - } - } - /// Returns [Some] if the method should be called again. fn handle_expr<'a>(&mut self, n: &'a mut Expr) -> Vec<&'a mut Expr> { - if n.is_class() { - let ClassExpr { - ident: old_ident, - class, - } = n.take().class().unwrap(); - let ident = private_ident!("_class"); - let (decl, extra_exprs) = - self.fold_class_as_decl(ident.clone(), old_ident.clone(), class); - let class_expr = Box::new(Expr::Class(ClassExpr { - ident: old_ident, - class: decl.class().unwrap().class, - })); - if extra_exprs.is_empty() { - *n = *class_expr; - } else { - self.uninitialized_vars.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: None, - definite: false, - }); - let assign_lhs = PatOrExpr::Pat(ident.clone().into()); - let assign_expr = Box::new(Expr::Assign(AssignExpr { - span: n.span(), - op: op!("="), - left: assign_lhs, - right: class_expr, - })); - let mut exprs = vec![assign_expr]; - exprs.extend(extra_exprs); - exprs.push(Box::new(Expr::Ident(ident))); - *n = Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs, - }); - } - return vec![]; - } match n { Expr::Bin(BinExpr { left, right, .. }) => return vec![&mut **left, &mut **right], @@ -805,6 +429,36 @@ where SuperProp::Computed(c) => c.visit_mut_with(self), }, + Expr::Class(class) => { + let key_len = self.keys.len(); + class.visit_mut_with(self); + + let mut exprs: Vec> = self + .keys + .iter_mut() + .skip(key_len) + .map(|key| { + let value = key.init.take().unwrap(); + let key = key.name.clone(); + Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Pat(key.into()), + op: op!("="), + right: value, + })) + }) + .collect(); + + if !exprs.is_empty() { + exprs.push(Box::new(Expr::Class(class.take()))); + + *n = Expr::Seq(SeqExpr { + span: DUMMY_SP, + exprs, + }) + } + } + _ => { n.visit_mut_children_with(self); } @@ -1305,12 +959,11 @@ where fn handle_module_items( &mut self, - mut items: Vec, + items: Vec, parent_module_name: Option<&Ident>, ) -> Vec { let mut delayed_vars = vec![]; - self.visit_mut_stmt_like(&mut items); items.visit_with(self); let mut stmts = Vec::with_capacity(items.len()); @@ -1971,6 +1624,12 @@ where } } + fn visit_class(&mut self, c: &Class) { + c.decorators.visit_with(self); + c.super_class.visit_with(self); + c.body.visit_with(self); + } + fn visit_ts_import_equals_decl(&mut self, n: &TsImportEqualsDecl) { match &n.module_ref { TsModuleRef::TsEntityName(name) => { @@ -2025,33 +1684,192 @@ where n.optional = false; } - fn visit_mut_block_stmt_or_expr(&mut self, n: &mut BlockStmtOrExpr) { - match n { - BlockStmtOrExpr::Expr(expr) if expr.is_class() => { - let span = expr.span(); - - let ClassExpr { ident, class } = expr.take().class().unwrap(); - let orig_ident = ident.clone(); - let ident = ident.unwrap_or_else(|| private_ident!("_class")); - let (decl, extra_exprs) = self.fold_class_as_decl(ident.clone(), orig_ident, class); - let mut stmts = vec![Stmt::Decl(decl)]; - stmts.extend( - extra_exprs - .into_iter() - .map(|e| e.into_stmt()) - .collect::>(), - ); - stmts.push(Stmt::Return(ReturnStmt { - span, - arg: Some(Box::new(Expr::Ident(ident))), - })); - *n = BlockStmtOrExpr::BlockStmt(BlockStmt { - span: n.span(), - stmts, - }); + // TODO: review this after https://github.com/microsoft/TypeScript/issues/45995 + // is resolved + fn visit_mut_class(&mut self, class: &mut Class) { + enum PropInit<'a> { + Public(&'a mut PropName, &'a mut Option>), + Private(&'a PrivateName, &'a mut Option>), + } + let mut prop_init = Vec::new(); + let mut constructor = None; + for member in class.body.iter_mut() { + match member { + ClassMember::Constructor(c @ Constructor { body: Some(..), .. }) + if c.params.iter().any(|param| param.is_ts_param_prop()) => + { + constructor = Some(c) + } + + ClassMember::ClassProp(ClassProp { + declare: false, + is_abstract: false, + is_static: false, + value: value @ Some(..), + key, + .. + }) => prop_init.push(PropInit::Public(key, value)), + ClassMember::PrivateProp(PrivateProp { + is_static: false, + value: value @ Some(..), + key, + .. + }) => prop_init.push(PropInit::Private(key, value)), + + _ => (), } - _ => n.visit_mut_children_with(self), - }; + } + if let Some(c) = constructor { + let mut assign_exprs = vec![]; + let mut extra_props = vec![]; + + c.params.map_with_mut(|params| { + params.move_map(|param| match param { + ParamOrTsParamProp::Param(..) => param, + ParamOrTsParamProp::TsParamProp(param) => { + let (ident, param) = match param.param { + TsParamPropParam::Ident(i) => ( + i.clone(), + Param { + span: DUMMY_SP, + decorators: Default::default(), + pat: Pat::Ident(i), + }, + ), + TsParamPropParam::Assign(AssignPat { + span, left, right, .. + }) if left.is_ident() => { + let i = left.ident().unwrap(); + + ( + i.clone(), + Param { + span: DUMMY_SP, + decorators: Default::default(), + pat: Pat::Assign(AssignPat { + span, + left: i.into(), + right, + type_ann: None, + }), + }, + ) + } + _ => unreachable!("destructuring pattern inside TsParameterProperty"), + }; + if self.config.use_define_for_class_fields { + extra_props.push(ident.id.clone()); + } + let assign_expr = Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Expr(Box::new( + ThisExpr { span: DUMMY_SP }.make_member(ident.id.clone()), + )), + op: op!("="), + right: Box::new(Expr::Ident(ident.id)), + })); + assign_exprs.push(assign_expr); + + ParamOrTsParamProp::Param(param) + } + }) + }); + + assign_exprs.extend(prop_init.into_iter().map(|prop| { + let this = Box::new(Expr::This(ThisExpr { span: DUMMY_SP })); + match prop { + PropInit::Private(key, value) => { + let value = value.take().unwrap(); + Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Expr( + Expr::Member(MemberExpr { + span: DUMMY_SP, + obj: this, + prop: MemberProp::PrivateName(key.clone()), + }) + .into(), + ), + op: op!("="), + right: value, + })) + } + PropInit::Public(key, value) => { + let value = value.take().unwrap(); + let key = match key { + PropName::Computed(ComputedPropName { span: c_span, expr }) + if !is_literal(&*expr) => + { + let ident = alias_ident_for(&*expr, "_key"); + // Handle computed property + self.keys.push(VarDeclarator { + span: DUMMY_SP, + name: ident.clone().into(), + init: Some(expr.take()), + definite: false, + }); + // We use computed because `classes` pass converts PropName::Ident + // to string. + **expr = Expr::Ident(ident.clone()); + PropName::Computed(ComputedPropName { + span: *c_span, + expr: Box::new(Expr::Ident(ident)), + }) + } + _ => key.clone(), + }; + Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Expr( + Expr::Member(MemberExpr { + span: DUMMY_SP, + obj: this, + prop: if let PropName::Ident(id) = key { + MemberProp::Ident(id) + } else { + MemberProp::Computed(ComputedPropName { + span: key.span(), + expr: prop_name_to_expr(key).into(), + }) + }, + }) + .into(), + ), + op: op!("="), + right: value, + })) + } + } + })); + + inject_after_super(c, assign_exprs); + + if !extra_props.is_empty() { + class.body.extend(extra_props.into_iter().map(|prop| { + ClassMember::ClassProp(ClassProp { + key: PropName::Ident(prop), + value: None, + decorators: Vec::new(), + is_static: false, + type_ann: None, + span: DUMMY_SP, + accessibility: None, + is_abstract: false, + is_optional: false, + is_override: false, + readonly: false, + declare: false, + definite: false, + }) + })) + } + } + + class.is_abstract = false; + class.type_params = None; + class.super_type_params = None; + class.implements = Default::default(); + class.visit_mut_children_with(self) } fn visit_mut_class_members(&mut self, members: &mut Vec) { @@ -2072,6 +1890,7 @@ where function: Function { body: None, .. }, .. }) => false, + ClassMember::ClassProp(ClassProp { declare: true, .. }) => false, ClassMember::ClassProp(ClassProp { value: None, ref decorators, @@ -2089,63 +1908,6 @@ where prop.readonly = false; } - fn visit_mut_constructor(&mut self, n: &mut Constructor) { - n.visit_mut_children_with(self); - - let mut assign_exprs = vec![]; - - n.params.map_with_mut(|params| { - params.move_map(|param| match param { - ParamOrTsParamProp::Param(..) => param, - ParamOrTsParamProp::TsParamProp(param) => { - let (ident, param) = match param.param { - TsParamPropParam::Ident(i) => ( - i.clone(), - Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: Pat::Ident(i), - }, - ), - TsParamPropParam::Assign(AssignPat { - span, left, right, .. - }) if left.is_ident() => { - let i = left.ident().unwrap(); - - ( - i.clone(), - Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: Pat::Assign(AssignPat { - span, - left: i.into(), - right, - type_ann: None, - }), - }, - ) - } - _ => unreachable!("destructuring pattern inside TsParameterProperty"), - }; - let assign_expr = Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - ThisExpr { span: DUMMY_SP }.make_member(ident.id.clone()), - )), - op: op!("="), - right: Box::new(Expr::Ident(ident.id)), - })); - assign_exprs.push(assign_expr); - - ParamOrTsParamProp::Param(param) - } - }) - }); - - inject_after_super(n, assign_exprs); - } - fn visit_mut_expr(&mut self, n: &mut Expr) { let mut stack = vec![n]; loop { @@ -2279,7 +2041,7 @@ where } fn visit_mut_module_items(&mut self, items: &mut Vec) { - self.visit_mut_stmt_like(items); + let orig_keys = self.keys.take(); items.visit_with(self); let mut stmts = Vec::with_capacity(items.len()); @@ -2364,6 +2126,31 @@ where continue } + ModuleItem::Stmt(Stmt::Decl(Decl::Class(..))) + | ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { + decl: Decl::Class(..), + .. + })) + | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { + decl: DefaultDecl::Class(..), + .. + })) => { + item.visit_mut_children_with(self); + if !self.keys.is_empty() { + stmts.push( + Stmt::Decl(Decl::Var(VarDecl { + span: DUMMY_SP, + declare: false, + decls: self.keys.take(), + kind: VarDeclKind::Let, + })) + .into(), + ) + } + + stmts.push(item); + } + ModuleItem::ModuleDecl(ModuleDecl::TsImportEquals(TsImportEqualsDecl { span, declare: false, @@ -2539,6 +2326,21 @@ where }; } + if !self.keys.is_empty() { + prepend( + &mut stmts, + Stmt::Decl(Decl::Var(VarDecl { + span: DUMMY_SP, + declare: false, + decls: self.keys.take(), + kind: VarDeclKind::Let, + })) + .into(), + ) + } + + self.keys = orig_keys; + *items = stmts; *items = self.handle_module_items(take(items), None); } @@ -2640,8 +2442,8 @@ where } fn visit_mut_stmts(&mut self, orig: &mut Vec) { - self.visit_mut_stmt_like(orig); - // Second pass + let orig_keys = self.keys.take(); + let mut stmts = Vec::with_capacity(orig.len()); for mut item in take(orig) { self.is_side_effect_import = false; @@ -2670,6 +2472,20 @@ where })) | Stmt::Decl(Decl::TsTypeAlias(..)) => continue, + Stmt::Decl(Decl::Class(mut class)) => { + class.visit_mut_with(self); + if !self.keys.is_empty() { + stmts.push(Stmt::Decl(Decl::Var(VarDecl { + span: DUMMY_SP, + declare: false, + decls: self.keys.take(), + kind: VarDeclKind::Let, + }))) + } + + stmts.push(Stmt::Decl(Decl::Class(class))); + } + _ => { item.visit_mut_with(self); stmts.push(item); @@ -2677,6 +2493,20 @@ where }; } + if !self.keys.is_empty() { + prepend( + &mut stmts, + Stmt::Decl(Decl::Var(VarDecl { + span: DUMMY_SP, + declare: false, + decls: self.keys.take(), + kind: VarDeclKind::Let, + })), + ) + } + + self.keys = orig_keys; + *orig = stmts } @@ -2797,27 +2627,3 @@ impl VisitMut for EnumValuesVisitor<'_> { } } } - -pub(super) struct ThisInStaticFolder { - pub ident: Ident, -} - -impl VisitMut for ThisInStaticFolder { - noop_visit_mut_type!(); - - fn visit_mut_constructor(&mut self, _: &mut Constructor) {} - - fn visit_mut_class_decl(&mut self, _: &mut ClassDecl) {} - - fn visit_mut_class_expr(&mut self, _: &mut ClassExpr) {} - - fn visit_mut_expr(&mut self, e: &mut Expr) { - e.visit_mut_children_with(self); - - if let Expr::This(..) = e { - *e = Expr::Ident(self.ident.clone()) - } - } - - fn visit_mut_function(&mut self, _: &mut Function) {} -} diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js index 103748903982..689f63a25431 100644 --- a/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/next/server/render/1/output.js @@ -28,21 +28,6 @@ function noRouter() { throw new Error(message); } class ServerRouter { - constructor(pathname, query, as, { isFallback }, isReady, basePath, locale, locales, defaultLocale, domainLocales, isPreview, isLocaleDomain){ - this.route = pathname.replace(/\/$/, "") || "/"; - this.pathname = pathname; - this.query = query; - this.asPath = as; - this.isFallback = isFallback; - this.basePath = basePath; - this.locale = locale; - this.locales = locales; - this.defaultLocale = defaultLocale; - this.isReady = isReady; - this.domainLocales = domainLocales; - this.isPreview = !!isPreview; - this.isLocaleDomain = !!isLocaleDomain; - } push() { noRouter(); } @@ -61,6 +46,21 @@ class ServerRouter { beforePopState() { noRouter(); } + constructor(pathname, query, as, { isFallback }, isReady, basePath, locale, locales, defaultLocale, domainLocales, isPreview, isLocaleDomain){ + this.route = pathname.replace(/\/$/, "") || "/"; + this.pathname = pathname; + this.query = query; + this.asPath = as; + this.isFallback = isFallback; + this.basePath = basePath; + this.locale = locale; + this.locales = locales; + this.defaultLocale = defaultLocale; + this.isReady = isReady; + this.domainLocales = domainLocales; + this.isPreview = !!isPreview; + this.isLocaleDomain = !!isLocaleDomain; + } } function enhanceComponents(options, App, Component) { if (typeof options === "function") { diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index f0ffbe210c26..e0561eb7ba10 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -7,6 +7,7 @@ use swc_ecma_transforms_compat::{ es2015::{block_scoping, destructuring, parameters}, es2017::async_to_generator, es2020::{nullish_coalescing, optional_chaining}, + es2022::class_properties, }; use swc_ecma_transforms_proposal::decorators; use swc_ecma_transforms_testing::{test, test_exec, test_fixture}; @@ -37,6 +38,13 @@ fn tr_config( ) } +fn properties(loose: bool) -> impl Fold { + class_properties(class_properties::Config { + set_public_fields: loose, + ..Default::default() + }) +} + macro_rules! to { ($name:ident, $from:expr, $to:expr) => { test!( @@ -44,7 +52,7 @@ macro_rules! to { decorators: true, ..Default::default() }), - |_| tr(), + |_| chain!(tr(), properties(true)), $name, $from, $to, @@ -125,10 +133,14 @@ to!( abstract #test(); }", - "class test { - #test() { + "var _test = new WeakSet(); + class test { + constructor(){ + _classPrivateMethodInit(this, _test); + } } -}" + function test1() {} +" ); to!(export_import, "export import A = B", "export var A = B;"); @@ -727,15 +739,26 @@ to!( this.#handlers = options.handlers || []; } }", - "export class Logger { - #level; - #handlers; - #loggerName; + " + var _level = new WeakMap(), _handlers = new WeakMap(), _loggerName = new WeakMap(); + export class Logger { constructor(loggerName, levelName, options = { }){ - this.#loggerName = loggerName; - this.#level = getLevelByName(levelName); - this.#handlers = options.handlers || []; + _classPrivateFieldInit(this, _level, { + writable: true, + value: void 0 + }); + _classPrivateFieldInit(this, _handlers, { + writable: true, + value: void 0 + }); + _classPrivateFieldInit(this, _loggerName, { + writable: true, + value: void 0 + }); + _classPrivateFieldSet(this, _loggerName, loggerName); + _classPrivateFieldSet(this, _level, getLevelByName(levelName)); + _classPrivateFieldSet(this, _handlers, options.handlers || []); } }" ); @@ -832,7 +855,7 @@ test!( test!( ::swc_ecma_parser::Syntax::Typescript(Default::default()), - |_| tr(), + |_| chain!(tr(), properties(true)), issue_930_static, "class A { static b = 'foo'; @@ -848,7 +871,7 @@ test!( test!( ::swc_ecma_parser::Syntax::Typescript(Default::default()), - |_| tr(), + |_| chain!(tr(), properties(true)), typescript_001, "class A { foo = new Subject() @@ -3725,12 +3748,13 @@ test_with_config!( ", " class A extends Object { - b; - a = 1; + a; constructor(b = 2){ super(); this.b = b; + this.a = 1; } + b; } " ); @@ -3770,15 +3794,13 @@ to!( } ", " - var _key, _key1; + let _ref = (console.log(1), 'a'), _ref1 = (console.log(2), 'b'); class A { constructor() { - this[_key] = 1; + this[_ref] = 1; } } - _key = (console.log(1), 'a'); - _key1 = (console.log(2), 'b'); - A[_key1] = 2; + A[_ref1] = 2; " ); @@ -3792,14 +3814,14 @@ to!( } ", " - var _key, _key1; + let _ref = (console.log(1), 'a'), _ref1 = (console.log(2), 'b'), tmp = (console.log(3), 'c'); class A { - [(_key = (console.log(1), 'a'), _key1 = (console.log(2), 'b'), console.log(3), 'c')]() {} + [tmp]() {} constructor() { - this[_key] = 1; + this[_ref] = 1; } } - A[_key1] = 2; + A[_ref1] = 2; " ); @@ -4134,15 +4156,22 @@ to!( } }", " + var _store = new WeakMap(), _body = new WeakMap(); export class Context { - #store; - #body; constructor(optionsOrContext){ this.response = { headers: new Headers() }; this.params = { }; + _classPrivateFieldInit(this, _store, { + writable: true, + value: void 0 + }); + _classPrivateFieldInit(this, _body, { + writable: true, + value: void 0 + }); if (optionsOrContext instanceof Context) { Object.assign(this, optionsOrContext); this.customContext = this; @@ -4235,12 +4264,12 @@ to!( } ", " + var _TestClass; var _class; - var _class1; - let TestClass = _class1 = someClassDecorator((_class1 = (_class = class TestClass { - }, _class.Something = 'hello', _class.SomeProperties = { - firstProp: _class.Something - }, _class)) || _class1) || _class1; + let TestClass = _class = someClassDecorator((_class = (_TestClass = class TestClass { + }, _TestClass.Something = 'hello', _TestClass.SomeProperties = { + firstProp: _TestClass.Something + }, _TestClass)) || _class) || _class; function someClassDecorator(c) { return c; } @@ -4475,8 +4504,39 @@ fn exec(input: PathBuf) { tsx: input.to_string_lossy().ends_with(".tsx"), ..Default::default() }), - &|_| tr(), + &|_| chain!(tr(), properties(true)), &input, &output, ); } + +to!( + parameter_properties_with_computed, + " +class A { + [console.log(123)] = 456 + constructor(public a = 1) {} +} + +let b = class { + [console.log(456)] = 123 + constructor(public a = 1) {} +} + ", + " +let _key; +let _key1 = console.log(123); +class A { + constructor(a = 1){ + this.a = a; + this[_key1] = 456; + } +} +let b = (_key = console.log(456), class { + constructor(a = 1){ + this.a = a; + this[_key] = 123; + } +}); +" +); diff --git a/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js index b6e4f1644c76..d083f75d4068 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/full/output/entry.js @@ -33,19 +33,19 @@ class BufferFullError extends Error { } } class PartialReadError extends Deno.errors.UnexpectedEof { + name = "PartialReadError"; constructor(){ super("Encountered UnexpectedEof, data only partially read"); - this.name = "PartialReadError"; } } class BufReader { + r = 0; + w = 0; + eof = false; static create(r, size = DEFAULT_BUF_SIZE) { return r instanceof BufReader ? r : new BufReader(r, size); } constructor(rd, size = DEFAULT_BUF_SIZE){ - this.r = 0; - this.w = 0; - this.eof = false; if (size < MIN_BUF_SIZE) size = MIN_BUF_SIZE; this._reset(new Uint8Array(size), rd); } @@ -219,6 +219,8 @@ class BufReader { } } class AbstractBufBase { + usedBufferBytes = 0; + err = null; size() { return this.buf.byteLength; } @@ -228,10 +230,6 @@ class AbstractBufBase { buffered() { return this.usedBufferBytes; } - constructor(){ - this.usedBufferBytes = 0; - this.err = null; - } } class BufWriter extends AbstractBufBase { static create(writer, size = DEFAULT_BUF_SIZE) { @@ -430,6 +428,10 @@ function deferred() { return Object.assign(promise, methods); } class MuxAsyncIterator { + iteratorCount = 0; + yields = []; + throws = []; + signal = deferred(); add(iterator) { ++this.iteratorCount; this.callIteratorNext(iterator); @@ -466,12 +468,6 @@ class MuxAsyncIterator { [Symbol.asyncIterator]() { return this.iterate(); } - constructor(){ - this.iteratorCount = 0; - this.yields = []; - this.throws = []; - this.signal = deferred(); - } } function emptyReader() { return { @@ -666,6 +662,8 @@ async function writeResponse(w, r) { await writer.flush(); } class ServerRequest { + done = deferred(); + _contentLength = undefined; get contentLength() { if (this._contentLength === undefined) { const cl = this.headers.get("content-length"); @@ -676,6 +674,7 @@ class ServerRequest { } return this._contentLength; } + _body = null; get body() { if (!this._body) { if (this.contentLength != null) this._body = bodyReader(this.contentLength, this.r); @@ -704,6 +703,7 @@ class ServerRequest { this.done.resolve(err); if (err) throw err; } + finalized = false; async finalize() { if (this.finalized) return; const body = this.body; @@ -711,12 +711,6 @@ class ServerRequest { while(await body.read(buf) !== null); this.finalized = true; } - constructor(){ - this.done = deferred(); - this._contentLength = undefined; - this._body = null; - this.finalized = false; - } } function parseHTTPVersion(vers) { switch(vers){ diff --git a/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js b/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js index 673b759e1223..97fda2734645 100644 --- a/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js +++ b/crates/swc_node_bundler/tests/pass/deno-001/simple-1/output/entry.js @@ -9,6 +9,10 @@ function deferred() { return Object.assign(promise, methods); } class MuxAsyncIterator { + iteratorCount = 0; + yields = []; + throws = []; + signal = deferred(); add(iterator) { ++this.iteratorCount; this.callIteratorNext(iterator); @@ -45,12 +49,6 @@ class MuxAsyncIterator { [Symbol.asyncIterator]() { return this.iterate(); } - constructor(){ - this.iteratorCount = 0; - this.yields = []; - this.throws = []; - this.signal = deferred(); - } } function emptyReader() { return { @@ -245,6 +243,8 @@ async function writeResponse(w, r) { await writer.flush(); } class ServerRequest { + done = deferred(); + _contentLength = undefined; get contentLength() { if (this._contentLength === undefined) { const cl = this.headers.get("content-length"); @@ -255,6 +255,7 @@ class ServerRequest { } return this._contentLength; } + _body = null; get body() { if (!this._body) { if (this.contentLength != null) this._body = bodyReader(this.contentLength, this.r); @@ -283,6 +284,7 @@ class ServerRequest { this.done.resolve(err); if (err) throw err; } + finalized = false; async finalize() { if (this.finalized) return; const body = this.body; @@ -290,12 +292,6 @@ class ServerRequest { while(await body.read(buf) !== null); this.finalized = true; } - constructor(){ - this.done = deferred(); - this._contentLength = undefined; - this._body = null; - this.finalized = false; - } } function parseHTTPVersion(vers) { switch(vers){ diff --git a/node-swc/src/types.ts b/node-swc/src/types.ts index ab0ef1fed749..1989b2600052 100644 --- a/node-swc/src/types.ts +++ b/node-swc/src/types.ts @@ -642,6 +642,8 @@ export interface TransformConfig { decoratorMetadata?: boolean; treatConstEnumAsEnum?: boolean; + + useDefineForClassFields?: boolean; } export interface ReactConfig {