mirror of
https://github.com/swc-project/swc.git
synced 2024-11-29 11:47:21 +03:00
fix(es/compat): Handle label block in constructor (#9528)
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
**Related issue:** - Closes https://github.com/swc-project/swc/issues/9527
This commit is contained in:
parent
8513816139
commit
c43dbad028
7
.changeset/popular-fireants-hang.md
Normal file
7
.changeset/popular-fireants-hang.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
swc_ecma_compat_es2015: patch
|
||||
swc_ecma_transforms_compat: patch
|
||||
swc_core: patch
|
||||
---
|
||||
|
||||
fix(es/compat): Handle label block in constructor
|
10
crates/swc/tests/exec/issues-9xxx/9527/.swcrc
Normal file
10
crates/swc/tests/exec/issues-9xxx/9527/.swcrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"externalHelpers": false,
|
||||
"target": "es5"
|
||||
},
|
||||
"isModule": true
|
||||
}
|
50
crates/swc/tests/exec/issues-9xxx/9527/1/exec.js
Normal file
50
crates/swc/tests/exec/issues-9xxx/9527/1/exec.js
Normal file
@ -0,0 +1,50 @@
|
||||
class Base { };
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
x: { break x; super(); }
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
try { } catch { super(); }
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
try { throw 0; super(); } catch { }
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
true || super();
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
({}) ?? super();
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
false && super();
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
null?.(super());
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
null?.[super()];
|
||||
}
|
||||
}).toThrow();
|
10
crates/swc/tests/fixture/issues-9xxx/9527/input/.swcrc
Normal file
10
crates/swc/tests/fixture/issues-9xxx/9527/input/.swcrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"externalHelpers": false,
|
||||
"target": "es5"
|
||||
},
|
||||
"isModule": true
|
||||
}
|
17
crates/swc/tests/fixture/issues-9xxx/9527/input/2.js
Normal file
17
crates/swc/tests/fixture/issues-9xxx/9527/input/2.js
Normal file
@ -0,0 +1,17 @@
|
||||
class Bar { }
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
switch (0) {
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new Foo();
|
||||
} catch {
|
||||
console.log("catched");
|
||||
}
|
50
crates/swc/tests/fixture/issues-9xxx/9527/input/exec.js
Normal file
50
crates/swc/tests/fixture/issues-9xxx/9527/input/exec.js
Normal file
@ -0,0 +1,50 @@
|
||||
class Base { };
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
x: { break x; super(); }
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
try { } catch { super(); }
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
try { throw 0; super(); } catch { }
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
true || super();
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
({}) ?? super();
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
false && super();
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
null?.(super());
|
||||
}
|
||||
}).toThrow();
|
||||
|
||||
|
||||
expect(() => new class extends Base {
|
||||
constructor() {
|
||||
null?.[super()];
|
||||
}
|
||||
}).toThrow();
|
15
crates/swc/tests/fixture/issues-9xxx/9527/input/index.js
Normal file
15
crates/swc/tests/fixture/issues-9xxx/9527/input/index.js
Normal file
@ -0,0 +1,15 @@
|
||||
class Bar { }
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
x: {
|
||||
break x;
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new Foo();
|
||||
} catch {
|
||||
console.log("catched");
|
||||
}
|
25
crates/swc/tests/fixture/issues-9xxx/9527/input/test.js
Normal file
25
crates/swc/tests/fixture/issues-9xxx/9527/input/test.js
Normal file
@ -0,0 +1,25 @@
|
||||
class Base { };
|
||||
|
||||
new class extends Base {
|
||||
constructor() {
|
||||
super() || null;
|
||||
}
|
||||
}
|
||||
|
||||
new class extends Base {
|
||||
constructor() {
|
||||
super()?.();
|
||||
}
|
||||
}
|
||||
|
||||
new class extends Base {
|
||||
constructor() {
|
||||
super()?.[null];
|
||||
}
|
||||
}
|
||||
|
||||
new class extends Base {
|
||||
constructor() {
|
||||
1 + super();
|
||||
}
|
||||
}
|
29
crates/swc/tests/fixture/issues-9xxx/9527/output/2.js
Normal file
29
crates/swc/tests/fixture/issues-9xxx/9527/output/2.js
Normal file
@ -0,0 +1,29 @@
|
||||
var _assert_this_initialized = require("@swc/helpers/_/_assert_this_initialized");
|
||||
var _call_super = require("@swc/helpers/_/_call_super");
|
||||
var _class_call_check = require("@swc/helpers/_/_class_call_check");
|
||||
var _inherits = require("@swc/helpers/_/_inherits");
|
||||
var Bar = function Bar() {
|
||||
"use strict";
|
||||
_class_call_check._(this, Bar);
|
||||
};
|
||||
var Foo = /*#__PURE__*/ function(Bar) {
|
||||
"use strict";
|
||||
_inherits._(Foo, Bar);
|
||||
function Foo() {
|
||||
_class_call_check._(this, Foo);
|
||||
var _this;
|
||||
switch(0){
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
_this = _call_super._(this, Foo);
|
||||
}
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
try {
|
||||
new Foo();
|
||||
} catch (e) {
|
||||
console.log("catched");
|
||||
}
|
124
crates/swc/tests/fixture/issues-9xxx/9527/output/exec.js
Normal file
124
crates/swc/tests/fixture/issues-9xxx/9527/output/exec.js
Normal file
@ -0,0 +1,124 @@
|
||||
var _assert_this_initialized = require("@swc/helpers/_/_assert_this_initialized");
|
||||
var _call_super = require("@swc/helpers/_/_call_super");
|
||||
var _class_call_check = require("@swc/helpers/_/_class_call_check");
|
||||
var _inherits = require("@swc/helpers/_/_inherits");
|
||||
var Base = function Base() {
|
||||
"use strict";
|
||||
_class_call_check._(this, Base);
|
||||
};
|
||||
;
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
x: {
|
||||
break x;
|
||||
_this = _call_super._(this, _class);
|
||||
}
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
try {} catch (e) {
|
||||
_this = _call_super._(this, _class);
|
||||
}
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
try {
|
||||
throw 0;
|
||||
_this = _call_super._(this, _class);
|
||||
} catch (e) {}
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
true || (_this = _call_super._(this, _class));
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
var _ref;
|
||||
(_ref = {}) !== null && _ref !== void 0 ? _ref : _this = _call_super._(this, _class);
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
false && (_this = _call_super._(this, _class));
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
var _this1;
|
||||
(_this1 = null) === null || _this1 === void 0 ? void 0 : _this1(_this = _call_super._(this, _class));
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
||||
expect(function() {
|
||||
return new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
var _this1;
|
||||
(_this1 = null) === null || _this1 === void 0 ? void 0 : _this1[_this = _call_super._(this, _class)];
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
}).toThrow();
|
27
crates/swc/tests/fixture/issues-9xxx/9527/output/index.js
Normal file
27
crates/swc/tests/fixture/issues-9xxx/9527/output/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
var _assert_this_initialized = require("@swc/helpers/_/_assert_this_initialized");
|
||||
var _call_super = require("@swc/helpers/_/_call_super");
|
||||
var _class_call_check = require("@swc/helpers/_/_class_call_check");
|
||||
var _inherits = require("@swc/helpers/_/_inherits");
|
||||
var Bar = function Bar() {
|
||||
"use strict";
|
||||
_class_call_check._(this, Bar);
|
||||
};
|
||||
var Foo = /*#__PURE__*/ function(Bar) {
|
||||
"use strict";
|
||||
_inherits._(Foo, Bar);
|
||||
function Foo() {
|
||||
_class_call_check._(this, Foo);
|
||||
var _this;
|
||||
x: {
|
||||
break x;
|
||||
_this = _call_super._(this, Foo);
|
||||
}
|
||||
return _assert_this_initialized._(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
try {
|
||||
new Foo();
|
||||
} catch (e) {
|
||||
console.log("catched");
|
||||
}
|
54
crates/swc/tests/fixture/issues-9xxx/9527/output/test.js
Normal file
54
crates/swc/tests/fixture/issues-9xxx/9527/output/test.js
Normal file
@ -0,0 +1,54 @@
|
||||
var _call_super = require("@swc/helpers/_/_call_super");
|
||||
var _class_call_check = require("@swc/helpers/_/_class_call_check");
|
||||
var _inherits = require("@swc/helpers/_/_inherits");
|
||||
var Base = function Base() {
|
||||
"use strict";
|
||||
_class_call_check._(this, Base);
|
||||
};
|
||||
;
|
||||
new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
(_this = _call_super._(this, _class)) || null;
|
||||
return _this;
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
var _this1;
|
||||
(_this1 = _this = _call_super._(this, _class)) === null || _this1 === void 0 ? void 0 : _this1();
|
||||
return _this;
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
var _this1;
|
||||
(_this1 = _this = _call_super._(this, _class)) === null || _this1 === void 0 ? void 0 : _this1[null];
|
||||
return _this;
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
||||
new /*#__PURE__*/ (function(Base) {
|
||||
"use strict";
|
||||
_inherits._(_class, Base);
|
||||
function _class() {
|
||||
_class_call_check._(this, _class);
|
||||
var _this;
|
||||
1 + (_this = _call_super._(this, _class));
|
||||
return _this;
|
||||
}
|
||||
return _class;
|
||||
}(Base));
|
@ -29,7 +29,6 @@ var Derived2 = /*#__PURE__*/ function(Base) {
|
||||
x
|
||||
]);
|
||||
return _possible_constructor_return(_this, 1);
|
||||
return _this;
|
||||
}
|
||||
return Derived2;
|
||||
}(Base);
|
||||
|
@ -1,9 +1,9 @@
|
||||
//// [derivedClassConstructorWithoutSuperCall.ts]
|
||||
// derived class constructors must contain a super call
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
var Base = function Base() {
|
||||
"use strict";
|
||||
_class_call_check(this, Base);
|
||||
@ -13,7 +13,7 @@ var Derived = /*#__PURE__*/ function(Base) {
|
||||
_inherits(Derived, Base);
|
||||
function Derived() {
|
||||
_class_call_check(this, Derived);
|
||||
return _possible_constructor_return(void 0);
|
||||
return _assert_this_initialized(void 0);
|
||||
}
|
||||
return Derived;
|
||||
}(Base);
|
||||
@ -31,7 +31,7 @@ var Derived2 = /*#__PURE__*/ function(Base2) {
|
||||
var r2 = function() {
|
||||
return _this1 = _call_super(_this, Derived2);
|
||||
}; // error for misplaced super call (nested function)
|
||||
return _possible_constructor_return(_this1);
|
||||
return _assert_this_initialized(_this1);
|
||||
}
|
||||
return Derived2;
|
||||
}(Base2);
|
||||
@ -44,7 +44,7 @@ var Derived3 = /*#__PURE__*/ function(Base2) {
|
||||
super();
|
||||
} // error
|
||||
;
|
||||
return _possible_constructor_return(void 0);
|
||||
return _assert_this_initialized(void 0);
|
||||
}
|
||||
return Derived3;
|
||||
}(Base2);
|
||||
|
@ -1,5 +1,5 @@
|
||||
//// [derivedClassConstructorWithoutSuperCall.ts]
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
|
@ -4,7 +4,6 @@ import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
export var A = function A() {
|
||||
"use strict";
|
||||
_class_call_check(this, A);
|
||||
@ -155,7 +154,7 @@ export var M = /*#__PURE__*/ function(_superClass) {
|
||||
_class_call_check(this, M);
|
||||
var _this;
|
||||
_assert_this_initialized(_this).prop = 12;
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return M;
|
||||
}(null);
|
||||
|
@ -4,7 +4,6 @@ import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
export var A = function A() {
|
||||
_class_call_check(this, A);
|
||||
};
|
||||
@ -101,7 +100,7 @@ export var L = /*#__PURE__*/ function(K) {
|
||||
export var M = /*#__PURE__*/ function(_superClass) {
|
||||
function M() {
|
||||
var _this;
|
||||
return _class_call_check(this, M), _assert_this_initialized(_this).prop = 12, _possible_constructor_return(_this);
|
||||
return _class_call_check(this, M), _assert_this_initialized(_this).prop = 12, _assert_this_initialized(_this);
|
||||
}
|
||||
return _inherits(M, null), M;
|
||||
}(0);
|
||||
|
@ -2,7 +2,6 @@
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
var D = /*#__PURE__*/ function(_superClass) {
|
||||
"use strict";
|
||||
_inherits(D, _superClass);
|
||||
@ -10,7 +9,7 @@ var D = /*#__PURE__*/ function(_superClass) {
|
||||
_class_call_check(this, D);
|
||||
var _this;
|
||||
_assert_this_initialized(_this)._t; // No error
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return D;
|
||||
}(null);
|
||||
|
@ -2,4 +2,3 @@
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
|
@ -1,4 +1,5 @@
|
||||
//// [usingDeclarations.1.ts]
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
||||
import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator";
|
||||
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
@ -6,7 +7,6 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
||||
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator";
|
||||
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
||||
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
|
||||
@ -396,7 +396,7 @@ try {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C2;
|
||||
}(C1);
|
||||
@ -415,7 +415,7 @@ try {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C3;
|
||||
}(C1);
|
||||
|
@ -1,4 +1,5 @@
|
||||
//// [usingDeclarations.1.ts]
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
||||
import { _ as _await_async_generator } from "@swc/helpers/_/_await_async_generator";
|
||||
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
@ -6,7 +7,6 @@ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
||||
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
import { _ as _wrap_async_generator } from "@swc/helpers/_/_wrap_async_generator";
|
||||
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
||||
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
|
||||
|
@ -1,8 +1,8 @@
|
||||
//// [usingDeclarations.11.ts]
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
|
||||
var A = function A() {
|
||||
"use strict";
|
||||
@ -23,7 +23,7 @@ var C1 = /*#__PURE__*/ function(A) {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C1;
|
||||
}(A);
|
||||
@ -42,7 +42,7 @@ var C2 = /*#__PURE__*/ function(A) {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C2;
|
||||
}(A);
|
||||
@ -61,7 +61,7 @@ var C3 = /*#__PURE__*/ function(A) {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C3;
|
||||
}(A);
|
||||
@ -80,7 +80,7 @@ var C4 = /*#__PURE__*/ function(A) {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C4;
|
||||
}(A);
|
||||
@ -99,7 +99,7 @@ var C5 = /*#__PURE__*/ function(A) {
|
||||
} finally{
|
||||
_usingCtx.d();
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return C5;
|
||||
}(A);
|
||||
|
@ -1,6 +1,6 @@
|
||||
//// [usingDeclarations.11.ts]
|
||||
import { _ as _assert_this_initialized } from "@swc/helpers/_/_assert_this_initialized";
|
||||
import { _ as _call_super } from "@swc/helpers/_/_call_super";
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
||||
import { _ as _possible_constructor_return } from "@swc/helpers/_/_possible_constructor_return";
|
||||
import { _ as _using_ctx } from "@swc/helpers/_/_using_ctx";
|
||||
|
@ -58,6 +58,7 @@ pub(super) fn fold_constructor(
|
||||
let mut body = constructor.body.take().unwrap();
|
||||
if let Some(class_super_name) = class_super_name {
|
||||
let is_last_super = (&*body.stmts).is_super_last_call();
|
||||
let is_last_return = body.stmts.last().map_or(false, Stmt::is_return_stmt);
|
||||
|
||||
let mut constructor_folder = ConstructorFolder {
|
||||
class_key_init: vec![],
|
||||
@ -134,7 +135,7 @@ pub(super) fn fold_constructor(
|
||||
stmts.push(var.into());
|
||||
}
|
||||
|
||||
if !is_last_super {
|
||||
if !is_last_super && !is_last_return {
|
||||
let this = if constructor_folder.super_found {
|
||||
Expr::Ident(constructor_folder.this.unwrap())
|
||||
} else {
|
||||
@ -142,7 +143,7 @@ pub(super) fn fold_constructor(
|
||||
.this
|
||||
.map_or_else(|| Expr::undefined(DUMMY_SP).as_arg(), |this| this.as_arg());
|
||||
|
||||
helper_expr!(possible_constructor_return).as_call(DUMMY_SP, vec![this])
|
||||
helper_expr!(assert_this_initialized).as_call(DUMMY_SP, vec![this])
|
||||
};
|
||||
|
||||
let return_this = ReturnStmt {
|
||||
@ -303,6 +304,13 @@ impl VisitMut for ConstructorFolder {
|
||||
self.super_found = super_found;
|
||||
}
|
||||
|
||||
fn visit_mut_switch_stmt(&mut self, node: &mut SwitchStmt) {
|
||||
node.discriminant.visit_mut_with(self);
|
||||
let super_found = self.super_found;
|
||||
node.cases.visit_mut_with(self);
|
||||
self.super_found = super_found;
|
||||
}
|
||||
|
||||
fn visit_mut_try_stmt(&mut self, node: &mut TryStmt) {
|
||||
let super_found = self.super_found;
|
||||
node.block.visit_mut_with(self);
|
||||
@ -311,6 +319,16 @@ impl VisitMut for ConstructorFolder {
|
||||
node.finalizer.visit_mut_with(self);
|
||||
}
|
||||
|
||||
fn visit_mut_labeled_stmt(&mut self, node: &mut LabeledStmt) {
|
||||
if node.body.is_block() {
|
||||
let super_found = self.super_found;
|
||||
node.body.visit_mut_with(self);
|
||||
self.super_found = super_found;
|
||||
} else {
|
||||
node.body.visit_mut_with(self);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_bin_expr(&mut self, node: &mut BinExpr) {
|
||||
match node.op {
|
||||
op!("&&") | op!("||") => {
|
||||
|
@ -8,7 +8,7 @@ let A = /*#__PURE__*/ function(B) {
|
||||
_update(A.prototype, "bar", _this, true)._ += 123;
|
||||
_update(A.prototype, baz, _this, true)._--;
|
||||
_update(A.prototype, quz, _this, true)._ -= 456;
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return A;
|
||||
}(B);
|
||||
|
@ -8,7 +8,7 @@ let A = /*#__PURE__*/ function(B) {
|
||||
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), "bar", _this, true)._ += 123;
|
||||
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), baz, _this, true)._--;
|
||||
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), quz, _this, true)._ -= 456;
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return A;
|
||||
}(B);
|
||||
|
@ -5,7 +5,7 @@ let Foo = /*#__PURE__*/ function(Bar1) {
|
||||
_class_call_check(this, Foo);
|
||||
var Foo1 = 123;
|
||||
console.log(Foo1);
|
||||
return _possible_constructor_return(void 0);
|
||||
return _assert_this_initialized(void 0);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -22,7 +22,6 @@ let Outer = /*#__PURE__*/ function(B) {
|
||||
return this;
|
||||
}
|
||||
return _possible_constructor_return(_this, new Inner());
|
||||
return _possible_constructor_return(_this);
|
||||
}
|
||||
return Outer;
|
||||
}(B);
|
||||
|
@ -10,7 +10,7 @@ let A = /*#__PURE__*/ function(B) {
|
||||
track
|
||||
]);
|
||||
else _this = _call_super(this, A);
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return A;
|
||||
}(B);
|
||||
|
@ -3,7 +3,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
_inherits(Foo, Bar1);
|
||||
function Foo() {
|
||||
_class_call_check(this, Foo);
|
||||
return _possible_constructor_return(void 0);
|
||||
return _assert_this_initialized(void 0);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -5,7 +5,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
_class_call_check(this, Foo);
|
||||
var _this;
|
||||
if (eval("false")) _this = _call_super(this, Foo);
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -6,7 +6,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
var _this;
|
||||
var fn = ()=>_this = _call_super(this, Foo);
|
||||
fn();
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -5,7 +5,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
_class_call_check(this, Foo);
|
||||
var _this;
|
||||
var fn = ()=>_this = _call_super(this, Foo);
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -5,7 +5,6 @@ var Child = /*#__PURE__*/ function(Base1) {
|
||||
_class_call_check(this, Child);
|
||||
var _this;
|
||||
return _possible_constructor_return(_this, false);
|
||||
return _possible_constructor_return(_this);
|
||||
}
|
||||
return Child;
|
||||
}(Base);
|
||||
|
@ -5,7 +5,6 @@ var Child = /*#__PURE__*/ function(Base1) {
|
||||
_class_call_check(this, Child);
|
||||
var _this;
|
||||
return _possible_constructor_return(_this, {});
|
||||
return _possible_constructor_return(_this);
|
||||
}
|
||||
return Child;
|
||||
}(Base);
|
||||
|
@ -29,7 +29,6 @@ var Outer = /*#__PURE__*/ function(Hello) {
|
||||
return Inner;
|
||||
}();
|
||||
return _possible_constructor_return(_this, new Inner());
|
||||
return _this;
|
||||
}
|
||||
return Outer;
|
||||
}(Hello);
|
||||
|
@ -35,7 +35,6 @@ var Outer = /*#__PURE__*/ function(Hello) {
|
||||
return Inner;
|
||||
}();
|
||||
return _possible_constructor_return(_this, new Inner());
|
||||
return _this;
|
||||
}
|
||||
return Outer;
|
||||
}(Hello);
|
||||
|
@ -19,7 +19,6 @@ var Outer = /*#__PURE__*/ function(Hello) {
|
||||
}
|
||||
};
|
||||
return _possible_constructor_return(_this, Inner);
|
||||
return _this;
|
||||
}
|
||||
return Outer;
|
||||
}(Hello);
|
||||
|
@ -26,7 +26,6 @@ var Outer = /*#__PURE__*/ function(Hello) {
|
||||
}
|
||||
};
|
||||
return _possible_constructor_return(_this, Inner);
|
||||
return _this;
|
||||
}
|
||||
return Outer;
|
||||
}(Hello);
|
||||
|
@ -5,7 +5,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
_class_call_check(this, Foo);
|
||||
var _this;
|
||||
Foo[_assert_this_initialized(_this)];
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -19,7 +19,6 @@ var Outer = /*#__PURE__*/ function(Hello) {
|
||||
_define_property(this, _ref, "hello");
|
||||
};
|
||||
return _possible_constructor_return(_this, new Inner());
|
||||
return _this;
|
||||
}
|
||||
return Outer;
|
||||
}(Hello);
|
||||
|
@ -26,7 +26,6 @@ var Outer = /*#__PURE__*/ function(Hello) {
|
||||
_define_property(this, _super_toString, 'hello');
|
||||
};
|
||||
return _possible_constructor_return(_this, new Inner());
|
||||
return _this;
|
||||
}
|
||||
return Outer;
|
||||
}(Hello);
|
||||
|
@ -16,7 +16,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
value: "foo"
|
||||
});
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
@ -9,7 +9,7 @@ var Foo = /*#__PURE__*/ function(Bar1) {
|
||||
} else {
|
||||
_this = _call_super(this, Foo), _define_property(_this, "bar", "foo");
|
||||
}
|
||||
return _possible_constructor_return(_this);
|
||||
return _assert_this_initialized(_this);
|
||||
}
|
||||
return Foo;
|
||||
}(Bar);
|
||||
|
Loading…
Reference in New Issue
Block a user