-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/compat): Handle label block in constructor (#9528)
**Related issue:** - Closes #9527
- Loading branch information
1 parent
8513816
commit c43dbad
Showing
44 changed files
with
468 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "ecmascript" | ||
}, | ||
"externalHelpers": false, | ||
"target": "es5" | ||
}, | ||
"isModule": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "ecmascript" | ||
}, | ||
"externalHelpers": false, | ||
"target": "es5" | ||
}, | ||
"isModule": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Bar { } | ||
class Foo extends Bar { | ||
constructor() { | ||
switch (0) { | ||
case 0: | ||
break; | ||
default: | ||
super(); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
new Foo(); | ||
} catch { | ||
console.log("catched"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Bar { } | ||
class Foo extends Bar { | ||
constructor() { | ||
x: { | ||
break x; | ||
super(); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
new Foo(); | ||
} catch { | ||
console.log("catched"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 changes: 124 additions & 0 deletions
124
crates/swc/tests/fixture/issues-9xxx/9527/output/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"); | ||
} |
Oops, something went wrong.