Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(es/compat): Reimplement constructor transform #9519

Merged
merged 7 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/nasty-students-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_ecma_transforms_base: minor
---

perf(es/compat): Reimplement constructor transform
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
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 _decorate = require("@swc/helpers/_/_decorate");
var _get = require("@swc/helpers/_/_get");
var _get_prototype_of = require("@swc/helpers/_/_get_prototype_of");
var _inherits = require("@swc/helpers/_/_inherits");
var _create_super = require("@swc/helpers/_/_create_super");
var SomeClass = _decorate._([], function(_initialize) {
"use strict";
var SomeClass = function SomeClass() {
Expand All @@ -31,12 +30,11 @@ var OtherClass = _decorate._([], function(_initialize, _SomeClass) {
var OtherClass = /*#__PURE__*/ function(_SomeClass) {
"use strict";
_inherits._(OtherClass, _SomeClass);
var _super = _create_super._(OtherClass);
function OtherClass() {
_class_call_check._(this, OtherClass);
var _this;
_this = _super.apply(this, arguments);
_initialize(_assert_this_initialized._(_this));
_this = _call_super._(this, OtherClass, arguments);
_initialize(_this);
return _this;
}
return OtherClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
var _call_super = require("@swc/helpers/_/_call_super");
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _create_class = require("@swc/helpers/_/_create_class");
var _get = require("@swc/helpers/_/_get");
var _get_prototype_of = require("@swc/helpers/_/_get_prototype_of");
var _inherits = require("@swc/helpers/_/_inherits");
var _create_super = require("@swc/helpers/_/_create_super");
var ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement1) {
"use strict";
_inherits._(ColouredCanvasElement, CanvasElement1);
var _super = _create_super._(ColouredCanvasElement);
function ColouredCanvasElement() {
_class_call_check._(this, ColouredCanvasElement);
return _super.apply(this, arguments);
return _call_super._(this, ColouredCanvasElement, arguments);
}
_create_class._(ColouredCanvasElement, [
{
Expand Down
11 changes: 4 additions & 7 deletions crates/swc/tests/fixture/issues-1xxx/1490/full/output/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";
var _call_super = require("@swc/helpers/_/_call_super");
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _create_class = require("@swc/helpers/_/_create_class");
var _get = require("@swc/helpers/_/_get");
var _get_prototype_of = require("@swc/helpers/_/_get_prototype_of");
var _inherits = require("@swc/helpers/_/_inherits");
var _wrap_native_super = require("@swc/helpers/_/_wrap_native_super");
var _create_super = require("@swc/helpers/_/_create_super");
var Element = /*#__PURE__*/ function() {
function Element() {
_class_call_check._(this, Element);
Expand All @@ -22,10 +22,9 @@ var Element = /*#__PURE__*/ function() {
}();
var CanvasElement = /*#__PURE__*/ function(Element) {
_inherits._(CanvasElement, Element);
var _super = _create_super._(CanvasElement);
function CanvasElement() {
_class_call_check._(this, CanvasElement);
return _super.apply(this, arguments);
return _call_super._(this, CanvasElement, arguments);
}
_create_class._(CanvasElement, [
{
Expand All @@ -40,10 +39,9 @@ var CanvasElement = /*#__PURE__*/ function(Element) {
}(_wrap_native_super._(Element));
var ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement) {
_inherits._(ColouredCanvasElement, CanvasElement);
var _super = _create_super._(ColouredCanvasElement);
function ColouredCanvasElement() {
_class_call_check._(this, ColouredCanvasElement);
return _super.apply(this, arguments);
return _call_super._(this, ColouredCanvasElement, arguments);
}
_create_class._(ColouredCanvasElement, [
{
Expand All @@ -58,10 +56,9 @@ var ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement) {
}(CanvasElement);
var ColouredSquare = /*#__PURE__*/ function(ColouredCanvasElement) {
_inherits._(ColouredSquare, ColouredCanvasElement);
var _super = _create_super._(ColouredSquare);
function ColouredSquare() {
_class_call_check._(this, ColouredSquare);
return _super.apply(this, arguments);
return _call_super._(this, ColouredSquare, arguments);
}
return ColouredSquare;
}(ColouredCanvasElement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { _ as _call_super } from "@swc/helpers/_/_call_super";
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _inherits } from "@swc/helpers/_/_inherits";
import { _ as _create_super } from "@swc/helpers/_/_create_super";
var MyClass = function MyClass() {
"use strict";
_class_call_check(this, MyClass);
Expand All @@ -10,10 +10,9 @@ export var fn = function() {
var _class = /*#__PURE__*/ function(MyClass) {
"use strict";
_inherits(_class, MyClass);
var _super = _create_super(_class);
function _class() {
_class_call_check(this, _class);
return _super.apply(this, arguments);
return _call_super(this, _class, arguments);
}
return _class;
}(MyClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 _create_super } from "@swc/helpers/_/_create_super";
var MyClass = function MyClass() {
"use strict";
_class_call_check(this, MyClass);
Expand All @@ -9,10 +9,9 @@ export var fn = function() {
return /*#__PURE__*/ function(MyClass) {
"use strict";
_inherits(_class, MyClass);
var _super = _create_super(_class);
function _class() {
_class_call_check(this, _class);
return _super.apply(this, arguments);
return _call_super(this, _class, arguments);
}
return _class;
}(MyClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var _call_super = require("@swc/helpers/_/_call_super");
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _define_property = require("@swc/helpers/_/_define_property");
var _inherits = require("@swc/helpers/_/_inherits");
var _create_super = require("@swc/helpers/_/_create_super");
var Component = function Component() {
"use strict";
_class_call_check._(this, Component);
Expand All @@ -14,10 +14,9 @@ var withTeamsForUser = function(_WrappedComponent) {
var _class = /*#__PURE__*/ function(Component) {
"use strict";
_inherits._(_class, Component);
var _super = _create_super._(_class);
function _class() {
_class_call_check._(this, _class);
return _super.apply(this, arguments);
return _call_super._(this, _class, arguments);
}
return _class;
}(Component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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 _create_super } from "@swc/helpers/_/_create_super";
export var a = /*#__PURE__*/ function(Component1) {
"use strict";
_inherits(a, Component1);
var _super = _create_super(a);
function a() {
_class_call_check(this, a);
return _super.apply(this, arguments);
return _call_super(this, a, arguments);
}
return a;
}(Component);
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
var _call_super = require("@swc/helpers/_/_call_super");
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _define_property = require("@swc/helpers/_/_define_property");
var _inherits = require("@swc/helpers/_/_inherits");
var _create_super = require("@swc/helpers/_/_create_super");
var withTeamsForUser = function() {
var _class = /*#__PURE__*/ function(Component1) {
"use strict";
_inherits._(_class, Component1);
var _super = _create_super._(_class);
function _class() {
_class_call_check._(this, _class);
return _super.apply(this, arguments);
return _call_super._(this, _class, arguments);
}
return _class;
}(Component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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 _create_super } from "@swc/helpers/_/_create_super";
var MyClass = function MyClass() {
"use strict";
_class_call_check(this, MyClass);
Expand All @@ -9,10 +9,9 @@ export var fn = function() {
return /*#__PURE__*/ function(MyClass) {
"use strict";
_inherits(_class, MyClass);
var _super = _create_super(_class);
function _class() {
_class_call_check(this, _class);
return _super.apply(this, arguments);
return _call_super(this, _class, arguments);
}
return _class;
}(MyClass);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAD,AAAL;;gBAAMA;iCAAAA;aAAAA;kCAAAA;;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAD,AAAL;;gBAAMA;aAAAA;kCAAAA;mCAAAA;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
"names": [
"Foo",
"bar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ Object.defineProperty(exports, "Foo", {
return Foo;
}
});
var _call_super = require("@swc/helpers/_/_call_super");
var _class_call_check = require("@swc/helpers/_/_class_call_check");
var _create_class = require("@swc/helpers/_/_create_class");
var _inherits = require("@swc/helpers/_/_inherits");
var _create_super = require("@swc/helpers/_/_create_super");
var _base = require("../b/base");
var Foo = /*#__PURE__*/ function(Base) {
"use strict";
_inherits._(Foo, Base);
var _super = _create_super._(Foo);
function Foo() {
_class_call_check._(this, Foo);
return _super.apply(this, arguments);
return _call_super._(this, Foo, arguments);
}
_create_class._(Foo, [
{
Expand Down
5 changes: 2 additions & 3 deletions crates/swc/tests/fixture/issues-6xxx/6984/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
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 _create_super } from "@swc/helpers/_/_create_super";
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
import React from 'react';
import { withRouter } from 'react-router-dom';
var App = /*#__PURE__*/ function(_React_Component) {
"use strict";
_inherits(App, _React_Component);
var _super = _create_super(App);
function App() {
_class_call_check(this, App);
return _super.apply(this, arguments);
return _call_super(this, App, arguments);
}
_create_class(App, [
{
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-7xxx/7546/output/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
"use strict";
_inherits(ClassName1, ClassName);
function ClassName1() {
return ClassName.call(this);
return ClassName.call(this) || this;
}
return ClassName1;
}(ClassName)
Expand Down
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9494/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"externalHelpers": false,
"target": "es5"
}
}
17 changes: 17 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9494/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Foo1 extends Bar {
constructor() {
super(); // ok
}
}

class Foo2 extends Bar {
constructor() {
0, super(); // ?
}
}

class Foo3 extends Bar {
constructor() {
[super()]; // ?
}
}
35 changes: 35 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9494/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 Foo1 = /*#__PURE__*/ function(Bar1) {
"use strict";
_inherits._(Foo1, Bar1);
function Foo1() {
_class_call_check._(this, Foo1);
return _call_super._(this, Foo1); // ok
}
return Foo1;
}(Bar);
var Foo2 = /*#__PURE__*/ function(Bar1) {
"use strict";
_inherits._(Foo2, Bar1);
function Foo2() {
_class_call_check._(this, Foo2);
var _this;
return 0, _this = _call_super._(this, Foo2); // ?
}
return Foo2;
}(Bar);
var Foo3 = /*#__PURE__*/ function(Bar1) {
"use strict";
_inherits._(Foo3, Bar1);
function Foo3() {
_class_call_check._(this, Foo3);
var _this;
[
_this = _call_super._(this, Foo3)
]; // ?
return _this;
}
return Foo3;
}(Bar);
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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 _create_super } from "@swc/helpers/_/_create_super";
import { PartialType } from "@nestjs/mapped-types";
import { CreateUserDto } from "./create-user.dto";
export var UpdateUserDto = /*#__PURE__*/ function(_PartialType) {
"use strict";
_inherits(UpdateUserDto, _PartialType);
var _super = _create_super(UpdateUserDto);
function UpdateUserDto() {
_class_call_check(this, UpdateUserDto);
return _super.apply(this, arguments);
return _call_super(this, UpdateUserDto, arguments);
}
return UpdateUserDto;
}(PartialType(CreateUserDto));
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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 _create_super } from "@swc/helpers/_/_create_super";
import { PartialType } from "@nestjs/mapped-types";
import { CreateUserDto } from "./create-user.dto";
export var UpdateUserDto = /*#__PURE__*/ function(_PartialType) {
"use strict";
_inherits(UpdateUserDto, _PartialType);
var _super = _create_super(UpdateUserDto);
function UpdateUserDto() {
_class_call_check(this, UpdateUserDto);
return _super.apply(this, arguments);
return _call_super(this, UpdateUserDto, arguments);
}
return UpdateUserDto;
}(PartialType(CreateUserDto));
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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 _instanceof = require("@swc/helpers/_/_instanceof");
var _wrap_native_super = require("@swc/helpers/_/_wrap_native_super");
var _create_super = require("@swc/helpers/_/_create_super");
var CustomError = /*#__PURE__*/ function _target(Error1) {
"use strict";
_inherits._(CustomError, Error1);
var _super = _create_super._(CustomError);
function CustomError(message) {
_class_call_check._(this, CustomError);
var _this;
_this = _super.call(this, message); // 'Error' breaks prototype chain here
Object.setPrototypeOf(_assert_this_initialized._(_this), (_instanceof._(this, CustomError) ? this.constructor : void 0).prototype); // restore prototype chain
_this = _call_super._(this, CustomError, [
message
]); // 'Error' breaks prototype chain here
Object.setPrototypeOf(_this, (_instanceof._(this, CustomError) ? this.constructor : void 0).prototype); // restore prototype chain
return _this;
}
return CustomError;
Expand Down
Loading
Loading