Skip to content

Commit

Permalink
fix(es/minifier): Enable seq inliner for const declarations (#8255)
Browse files Browse the repository at this point in the history
  • Loading branch information
Austaras authored Nov 13, 2023
1 parent 001fe85 commit ebcd825
Show file tree
Hide file tree
Showing 61 changed files with 546 additions and 862 deletions.
3 changes: 1 addition & 2 deletions crates/swc/tests/fixture/issues-5xxx/5112/output/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function c(r, n) {
let e = new Uint8Array(4 * r * r);
return {
e,
e: new Uint8Array(4 * r * r),
s: Math.sqrt(1.25),
c: (r - n) / 2
};
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issues-5xxx/5865/output/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var a;v=(a=r,b=>{let n=a.map(t=>{if(t)return t.foo});return n});
var a;v=(a=r,b=>a.map(t=>{if(t)return t.foo}));
5 changes: 1 addition & 4 deletions crates/swc/tests/fixture/issues-7xxx/7241/output/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
!function() {
let o = something();
console.log(o);
}();
console.log(something());
Original file line number Diff line number Diff line change
@@ -1 +1 @@
!function(){let r=(console.log("REQUIRE"),1);console.log(r)}();
console.log((console.log("REQUIRE"),1));
3 changes: 1 addition & 2 deletions crates/swc/tests/fixture/issues-8xxx/8155/1/output/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ let someFn = (xx, x, y)=>[
2,
3
], goodFunction = (_ref = _async_to_generator(function*() {
let rb = yield getArray(), rc = yield getArray();
console.log(someFn(1, rb, rc));
console.log(someFn(1, (yield getArray()), (yield getArray())));
}), function() {
return _ref.apply(this, arguments);
}), badFunction = (_ref1 = _async_to_generator(function*() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
class Base {
x = 1;
}
const obj = new class extends Base {
console.log(new class extends Base {
get x() {
return 2;
}
set x(value) {
console.log(`x was set to ${value}`);
}
}();
console.log(obj.x);
}().x);
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const Base = classWithProperties({
},
y: 'string'
}, class {
}), mine = new class extends Base {
});
new class extends Base {
get x() {
return !1;
}
get y() {
return 'hi';
}
}();
mine.x;
}().x;
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ global = this, factory = function(exports1) {
return _default;
}
});
let x = new Promise((resolve, reject)=>{
let _default = new Promise((resolve, reject)=>{
resolve({});
}), _default = x;
});
}, "object" == typeof module && "object" == typeof module.exports ? factory(exports) : "function" == typeof define && define.amd ? define([
"exports"
], factory) : (global = "undefined" != typeof globalThis ? globalThis : global || self) && factory(global.aTs = {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Object.defineProperty(exports, "__esModule", {
return _default;
}
});
const x = new Promise((resolve, reject)=>{
const _default = new Promise((resolve, reject)=>{
resolve({});
}), _default = x;
});
//// [b.ts]
Object.defineProperty(exports, "__esModule", {
value: !0
});
const _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _interop_require_default = require("@swc/helpers/_/_interop_require_default"), _a = _interop_require_default._(require("./a"));
const _async_to_generator = require("@swc/helpers/_/_async_to_generator"), _a = require("@swc/helpers/_/_interop_require_default")._(require("./a"));
_async_to_generator._(function*() {
yield _a.default;
})();
6 changes: 2 additions & 4 deletions crates/swc/tests/tsc-references/es2020IntlAPIs.2.minified.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ log("en-US"), log("de-DE");
const rtf1 = new Intl.RelativeTimeFormat('en', {
style: 'narrow'
});
console.log(rtf1.format(3, 'quarter')), console.log(rtf1.format(-1, 'day'));
const rtf2 = new Intl.RelativeTimeFormat('es', {
console.log(rtf1.format(3, 'quarter')), console.log(rtf1.format(-1, 'day')), console.log(new Intl.RelativeTimeFormat('es', {
numeric: 'auto'
});
console.log(rtf2.format(2, 'day'));
}).format(2, 'day'));
const regionNamesInEnglish = new Intl.DisplayNames([
'en'
], {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// [es2022SharedMemory.ts]
const sab = new SharedArrayBuffer(1024 * Int32Array.BYTES_PER_ELEMENT), int32 = new Int32Array(sab), sab64 = new SharedArrayBuffer(1024 * BigInt64Array.BYTES_PER_ELEMENT), int64 = new BigInt64Array(sab64);
Atomics.wait(int32, 0, 0);
const { async, value } = Atomics.waitAsync(int32, 0, 0), { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0)), main = async ()=>{
const { async, value } = Atomics.waitAsync(int32, 0, 0), { async: async64, value: value64 } = Atomics.waitAsync(int64, 0, BigInt(0));
(async ()=>{
async && await value, async64 && await value64;
};
main();
})();
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//// [main.ts]
Object.defineProperty(exports, "__esModule", {
value: !0
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default"), _a = _interop_require_default._(require("a"));
(0, _a.default)();
}), (0, require("@swc/helpers/_/_interop_require_default")._(require("a")).default)();
//// [external.d.ts]
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const _default = "hello";
Object.defineProperty(exports, "__esModule", {
value: !0
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _t1 = _interop_require_wildcard._(require("./t1")), a = require("./t1");
a.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default;
const _t1 = require("@swc/helpers/_/_interop_require_wildcard")._(require("./t1"));
require("./t1").default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default;
//// [t3.ts]
Object.defineProperty(exports, "__esModule", {
value: !0
Expand Down Expand Up @@ -49,5 +49,5 @@ Object.defineProperty(exports, "__esModule", {
return _t1.default;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _t1 = _interop_require_wildcard._(require("./t1")), a = require("./t1");
const _t1 = require("@swc/helpers/_/_interop_require_wildcard")._(require("./t1")), a = require("./t1");
a.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default, _t1.default;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Object.defineProperty(exports, "__esModule", {
return _0;
}
});
const _export_star = require("@swc/helpers/_/_export_star"), _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), _0 = _interop_require_wildcard._(_export_star._(require("./0"), exports));
const _export_star = require("@swc/helpers/_/_export_star"), _0 = require("@swc/helpers/_/_interop_require_wildcard")._(_export_star._(require("./0"), exports));
//// [2.ts]
Object.defineProperty(exports, "__esModule", {
value: !0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ export function backup() {
return "backup";
}
//// [2.ts]
const specify = bar() ? "./0" : void 0;
import(specify), import(void 0), import(bar() ? "./1" : null), import(null);
import(bar() ? "./0" : void 0), import(void 0), import(bar() ? "./1" : null), import(null);
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ export function backup() {
return "backup";
}
//// [2.ts]
const specify = bar() ? "./0" : void 0;
import(specify), import(void 0), import(bar() ? "./1" : null), import(null);
import(bar() ? "./0" : void 0), import(void 0), import(bar() ? "./1" : null), import(null);
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ Object.defineProperty(exports, "__esModule", {
value: !0
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"), intersectDictionaries = (d1, d2)=>Object.assign({}, d1, d2), testDictionary = (_value)=>{}, d1 = {};
testDictionary(d1);
const d2 = intersectDictionaries(d1, d1);
testDictionary(d2);
testDictionary(d1), testDictionary(intersectDictionaries(d1, d1));
const d3 = {
s: ''
};
testDictionary(d3);
const d4 = intersectDictionaries(d1, d3);
testDictionary(d4);
const d5 = intersectDictionaries(d3, d1);
testDictionary(d5);
const d6 = intersectDictionaries(d3, d3);
testDictionary(d6), mock(Promise.resolve().then(()=>_interop_require_wildcard._(require("./ex"))));
testDictionary(d3), testDictionary(intersectDictionaries(d1, d3)), testDictionary(intersectDictionaries(d3, d1)), testDictionary(intersectDictionaries(d3, d3)), mock(Promise.resolve().then(()=>_interop_require_wildcard._(require("./ex"))));
//// [ex.d.ts]
Object.defineProperty(exports, "__esModule", {
value: !0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//// [mixinAbstractClasses.2.ts]
var baseClass;
const MixedBase = (baseClass = class {
new (baseClass = class {
}, class extends baseClass {
mixinMethod() {}
});
new MixedBase();
})();
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//// [numberFormatCurrencySignResolved.ts]
const options = new Intl.NumberFormat('en-NZ', {
new Intl.NumberFormat('en-NZ', {
style: 'currency',
currency: 'NZD',
currencySign: 'accounting'
}).resolvedOptions();
options.currencySign;
}).resolvedOptions().currencySign;
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
var _bar, _baz, _qux;
import { _ as _class_private_method_get } from "@swc/helpers/_/_class_private_method_get";
import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_method_init";
let C = (_bar = new WeakSet(), _baz = new WeakSet(), _qux = new WeakSet(), class {
async foo() {
let b = await _class_private_method_get(this, _bar, bar).call(this);
return b + (_class_private_method_get(this, _baz, baz).call(this).next().value || 0) + ((await _class_private_method_get(this, _qux, qux).call(this).next()).value || 0);
}
constructor(){
_class_private_method_init(this, _bar), _class_private_method_init(this, _baz), _class_private_method_init(this, _qux);
}
});
async function bar() {
return await Promise.resolve(42);
}
Expand All @@ -20,4 +11,11 @@ function* baz() {
async function* qux() {
yield await Promise.resolve(42);
}
new C().foo().then(console.log);
new (_bar = new WeakSet(), _baz = new WeakSet(), _qux = new WeakSet(), class {
async foo() {
return await _class_private_method_get(this, _bar, bar).call(this) + (_class_private_method_get(this, _baz, baz).call(this).next().value || 0) + ((await _class_private_method_get(this, _qux, qux).call(this).next()).value || 0);
}
constructor(){
_class_private_method_init(this, _bar), _class_private_method_init(this, _baz), _class_private_method_init(this, _qux);
}
})().foo().then(console.log);
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
var _bar;
import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_method_init";
import { _ as _read_only_error } from "@swc/helpers/_/_read_only_error";
let C = (_bar = new WeakSet(), class {
console.log(new (_bar = new WeakSet(), class {
foo() {
console.log("should log this then throw"), _read_only_error("#bar");
}
constructor(){
_class_private_method_init(this, _bar);
}
});
console.log(new C().foo());
})().foo());
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var _x;
import { _ as _class_private_field_init } from "@swc/helpers/_/_class_private_field_init";
import { _ as _class_private_field_set } from "@swc/helpers/_/_class_private_field_set";
import { _ as _write_only_error } from "@swc/helpers/_/_write_only_error";
let C = (_x = new WeakMap(), class {
function set_x(x) {}
console.log(new (_x = new WeakMap(), class {
m() {
_class_private_field_set(this, _x, _write_only_error("#x") + 2);
}
Expand All @@ -13,6 +14,4 @@ let C = (_x = new WeakMap(), class {
set: set_x
});
}
});
function set_x(x) {}
console.log(new C().m());
})().m());
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { _ as _class_static_private_field_spec_get } from "@swc/helpers/_/_class
import { _ as _class_static_private_field_spec_set } from "@swc/helpers/_/_class_static_private_field_spec_set";
class A {
static test() {
_class_static_private_field_spec_get(this, A, _fieldFunc).call(A);
let func = _class_static_private_field_spec_get(this, A, _fieldFunc);
func(), new (_class_static_private_field_spec_get(this, A, _fieldFunc))();
_class_static_private_field_spec_get(this, A, _fieldFunc).call(A), _class_static_private_field_spec_get(this, A, _fieldFunc)(), new (_class_static_private_field_spec_get(this, A, _fieldFunc))();
let arr = [
1,
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import { _ as _class_static_private_method_get } from "@swc/helpers/_/_class_static_private_method_get";
class AA {
test() {
_class_static_private_method_get(AA, AA, method).call(AA);
let func = _class_static_private_method_get(AA, AA, method);
func(), new (_class_static_private_method_get(AA, AA, method))();
_class_static_private_method_get(AA, AA, method).call(AA), _class_static_private_method_get(AA, AA, method)(), new (_class_static_private_method_get(AA, AA, method))();
let arr = [
1,
2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Base {
console.log(`x was set to ${value}`);
}
}
const obj = new class extends Base {
console.log(new class extends Base {
x = 1;
}();
console.log(obj.x);
}().x);
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class Animal {
console.log(this._sound);
}
}
const a = new Animal;
a.makeSound();
const lion = new class extends Animal {
(new Animal).makeSound(), (new class extends Animal {
sound = 'RAWR!';
};
lion.makeSound();
}).makeSound();
Loading

0 comments on commit ebcd825

Please sign in to comment.