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

feat(es/helpers): Import only used helpers #4767

Merged
merged 30 commits into from
May 24, 2022
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
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as swcHelpers from "@swc/helpers";
import _to_consumable_array from "@swc/helpers/lib/_to_consumable_array.js";
function a(param) {
var _b = param.b, b = _b === void 0 ? [] : _b;
var t = useMemo(function() {
return(// Cmt1
swcHelpers.toConsumableArray(a.slice(0, 1)).concat(// Cmt2
swcHelpers.toConsumableArray(b), // Cmt3
swcHelpers.toConsumableArray(c.slice(1))));
_to_consumable_array(a.slice(0, 1)).concat(// Cmt2
_to_consumable_array(b), // Cmt3
_to_consumable_array(c.slice(1))));
}, [
frameworks
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";
var swcHelpers = require("@swc/helpers");
var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
(async function() {
const { displayA } = await Promise.resolve().then(function() {
return swcHelpers.interopRequireWildcard(require("../packages/a/src/index"));
return _interop_require_wildcard(require("../packages/a/src/index"));
});
console.log(displayA());
})();
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as swcHelpers from "@swc/helpers";
import _type_of from "@swc/helpers/lib/_type_of.js";
var window = "foo";
console.log(typeof window === "undefined" ? "undefined" : swcHelpers.typeOf(window));
console.log(typeof window === "undefined" ? "undefined" : _type_of(window));
24 changes: 15 additions & 9 deletions crates/swc/tests/fixture/issues-0xxx/846/case1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import * as swcHelpers from "@swc/helpers";
var SomeClass = swcHelpers.decorate([], function(_initialize) {
import _assert_this_initialized from "@swc/helpers/lib/_assert_this_initialized.js";
import _class_call_check from "@swc/helpers/lib/_class_call_check.js";
import _decorate from "@swc/helpers/lib/_decorate.js";
import _get from "@swc/helpers/lib/_get.js";
import _get_prototype_of from "@swc/helpers/lib/_get_prototype_of.js";
import _inherits from "@swc/helpers/lib/_inherits.js";
import _create_super from "@swc/helpers/lib/_create_super.js";
var SomeClass = _decorate([], function(_initialize) {
var SomeClass = function SomeClass() {
"use strict";
swcHelpers.classCallCheck(this, SomeClass);
_class_call_check(this, SomeClass);
_initialize(this);
};
return {
Expand All @@ -19,16 +25,16 @@ var SomeClass = swcHelpers.decorate([], function(_initialize) {
]
};
});
var OtherClass = swcHelpers.decorate([], function(_initialize, _SomeClass1) {
var OtherClass = _decorate([], function(_initialize, _SomeClass1) {
var OtherClass = /*#__PURE__*/ function(_SomeClass) {
"use strict";
swcHelpers.inherits(OtherClass, _SomeClass);
var _super = swcHelpers.createSuper(OtherClass);
_inherits(OtherClass, _SomeClass);
var _super = _create_super(OtherClass);
function OtherClass() {
swcHelpers.classCallCheck(this, OtherClass);
_class_call_check(this, OtherClass);
var _this;
_this = _super.apply(this, arguments);
_initialize(swcHelpers.assertThisInitialized(_this));
_initialize(_assert_this_initialized(_this));
return _this;
}
return OtherClass;
Expand All @@ -43,7 +49,7 @@ var OtherClass = swcHelpers.decorate([], function(_initialize, _SomeClass1) {
],
key: "anotherMethod",
value: function anotherMethod() {
swcHelpers.get(swcHelpers.getPrototypeOf(OtherClass.prototype), "someMethod", this).call(this);
_get(_get_prototype_of(OtherClass.prototype), "someMethod", this).call(this);
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions crates/swc/tests/fixture/issues-1xxx/1107/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as swcHelpers from "@swc/helpers";
import _class_call_check from "@swc/helpers/lib/_class_call_check.js";
export var Class1 = function Class1(param) {
"use strict";
var _name = param.name, name = _name === void 0 ? "" : _name;
swcHelpers.classCallCheck(this, Class1);
_class_call_check(this, Class1);
console.log(name);
};
export var Class2 = function Class2(param) {
"use strict";
var _name = param.name, name = _name === void 0 ? "" : _name;
swcHelpers.classCallCheck(this, Class2);
_class_call_check(this, Class2);
console.log(name);
};
7 changes: 4 additions & 3 deletions crates/swc/tests/fixture/issues-1xxx/1160/output/entry.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"use strict";
var swcHelpers = require("@swc/helpers");
var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default;
var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default;
var MyEnum;
(function(MyEnum) {
MyEnum["x"] = "xxx";
MyEnum["y"] = "yyy";
})(MyEnum || (MyEnum = {}));
class Xpto {
}
swcHelpers.__decorate([
_ts_decorate([
Decorator(),
swcHelpers.__metadata("design:type", String)
_ts_metadata("design:type", String)
], Xpto.prototype, "value", void 0);
function Decorator() {
return function(...args) {};
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-1xxx/1213/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var swcHelpers = require("@swc/helpers");
var _foo = swcHelpers.interopRequireDefault(require("foo"));
var _interop_require_default = require("@swc/helpers/lib/_interop_require_default.js").default;
var _foo = _interop_require_default(require("foo"));
class NotOK {
constructor(){
console.log(_foo.default);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as swcHelpers from "@swc/helpers";
import _async_to_generator from "@swc/helpers/lib/_async_to_generator.js";
import regeneratorRuntime from "regenerator-runtime";
var source = Math.random() < 2 ? "matilda" : "fred";
var details = {
Expand All @@ -8,7 +8,7 @@ function request(path) {
return _request.apply(this, arguments);
}
function _request() {
_request = swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee(path) {
_request = _async_to_generator(regeneratorRuntime.mark(function _callee(path) {
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
Expand All @@ -21,7 +21,7 @@ function _request() {
}));
return _request.apply(this, arguments);
}
swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
_async_to_generator(regeneratorRuntime.mark(function _callee() {
var obj;
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as swcHelpers from "@swc/helpers";
import _async_to_generator from "@swc/helpers/lib/_async_to_generator.js";
import regeneratorRuntime from "regenerator-runtime";
var source = Math.random() < 2 ? "matilda" : "fred";
var details = {
Expand All @@ -8,7 +8,7 @@ function request(path) {
return _request.apply(this, arguments);
}
function _request() {
_request = swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee(path) {
_request = _async_to_generator(regeneratorRuntime.mark(function _callee(path) {
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
Expand All @@ -21,7 +21,7 @@ function _request() {
}));
return _request.apply(this, arguments);
}
swcHelpers.asyncToGenerator(regeneratorRuntime.mark(function _callee() {
_async_to_generator(regeneratorRuntime.mark(function _callee() {
var obj;
return regeneratorRuntime.wrap(function _callee$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
var swcHelpers = require("@swc/helpers");
var action = swcHelpers.interopRequireWildcard(require("./actions"));
var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
var action = _interop_require_wildcard(require("./actions"));
console.log(action);
console.log(action.foo);
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-1xxx/1259/output/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var swcHelpers = require("@swc/helpers");
var _tagged_template_literal = require("@swc/helpers/lib/_tagged_template_literal.js").default;
function _templateObject() {
var data = swcHelpers.taggedTemplateLiteral([
var data = _tagged_template_literal([
"'#ERROR'"
]);
_templateObject = function _templateObject() {
Expand Down
7 changes: 4 additions & 3 deletions crates/swc/tests/fixture/issues-1xxx/1278/output/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
var swcHelpers = require("@swc/helpers");
var _ts_decorate = require("@swc/helpers/lib/_ts_decorate.js").default;
var _ts_metadata = require("@swc/helpers/lib/_ts_metadata.js").default;
function MyDecorator(klass) {
return ()=>{
// do something
Expand All @@ -8,8 +9,8 @@ function MyDecorator(klass) {
}
class MyClass {
}
swcHelpers.__decorate([
_ts_decorate([
MyDecorator(MyClass),
swcHelpers.__metadata("design:type", String)
_ts_metadata("design:type", String)
], MyClass.prototype, "prop", void 0);
console.log(new MyClass());
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as swcHelpers from "@swc/helpers";
import _define_property from "@swc/helpers/lib/_define_property.js";
export class Foo {
nested() {
let Foo1 = class Foo {
};
swcHelpers.defineProperty(Foo1, "foo", "foo");
swcHelpers.defineProperty(Foo1, "bar", Foo1.foo);
_define_property(Foo1, "foo", "foo");
_define_property(Foo1, "bar", Foo1.foo);
return new Foo1();
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as swcHelpers from "@swc/helpers";
import _class_call_check from "@swc/helpers/lib/_class_call_check.js";
import _class_private_field_get from "@swc/helpers/lib/_class_private_field_get.js";
import _class_private_field_init from "@swc/helpers/lib/_class_private_field_init.js";
import _class_private_field_set from "@swc/helpers/lib/_class_private_field_set.js";
var _name = /*#__PURE__*/ new WeakMap();
var Animal = /*#__PURE__*/ function() {
"use strict";
function Animal(name) {
swcHelpers.classCallCheck(this, Animal);
swcHelpers.classPrivateFieldInit(this, _name, {
_class_call_check(this, Animal);
_class_private_field_init(this, _name, {
writable: true,
value: void 0
});
swcHelpers.classPrivateFieldSet(this, _name, name);
_class_private_field_set(this, _name, name);
}
var _proto = Animal.prototype;
_proto.noise = function noise() {
return swcHelpers.classPrivateFieldGet(this, _name).toUpperCase();
return _class_private_field_get(this, _name).toUpperCase();
};
return Animal;
}();
16 changes: 10 additions & 6 deletions crates/swc/tests/fixture/issues-1xxx/1306/case2/output/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import * as swcHelpers from "@swc/helpers";
import _class_call_check from "@swc/helpers/lib/_class_call_check.js";
import _class_private_field_get from "@swc/helpers/lib/_class_private_field_get.js";
import _class_private_field_init from "@swc/helpers/lib/_class_private_field_init.js";
import _class_private_field_set from "@swc/helpers/lib/_class_private_field_set.js";
import _create_class from "@swc/helpers/lib/_create_class.js";
var _name = /*#__PURE__*/ new WeakMap();
var Animal = /*#__PURE__*/ function() {
"use strict";
function Animal(name) {
swcHelpers.classCallCheck(this, Animal);
swcHelpers.classPrivateFieldInit(this, _name, {
_class_call_check(this, Animal);
_class_private_field_init(this, _name, {
writable: true,
value: void 0
});
swcHelpers.classPrivateFieldSet(this, _name, name);
_class_private_field_set(this, _name, name);
}
swcHelpers.createClass(Animal, [
_create_class(Animal, [
{
key: "noise",
value: function noise() {
return swcHelpers.classPrivateFieldGet(this, _name).toUpperCase();
return _class_private_field_get(this, _name).toUpperCase();
}
}
]);
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issues-1xxx/1307/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.foo = void 0;
var swcHelpers = require("@swc/helpers");
var _foo = swcHelpers.interopRequireWildcard(require("./foo"));
var _interop_require_wildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
var _foo = _interop_require_wildcard(require("./foo"));
exports.foo = _foo;
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"use strict";
var swcHelpers = require("@swc/helpers");
var _class_private_field_get = require("@swc/helpers/lib/_class_private_field_get.js").default;
var _class_private_field_init = require("@swc/helpers/lib/_class_private_field_init.js").default;
var _ws = /*#__PURE__*/ new WeakMap(), _ws2 = /*#__PURE__*/ new WeakMap();
class Foo {
get connected() {
return swcHelpers.classPrivateFieldGet(this, _ws2) && swcHelpers.classPrivateFieldGet(this, _ws).readyState === _ws1.default.OPEN;
return _class_private_field_get(this, _ws2) && _class_private_field_get(this, _ws).readyState === _ws1.default.OPEN;
}
constructor(){
swcHelpers.classPrivateFieldInit(this, _ws, {
_class_private_field_init(this, _ws, {
writable: true,
value: void 0
});
swcHelpers.classPrivateFieldInit(this, _ws2, {
_class_private_field_init(this, _ws2, {
writable: true,
value: void 0
});
Expand Down
Loading