Skip to content

Commit

Permalink
fix(es/minifier): Do not drop used properties (swc-project#7702)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes swc-project#7700.
 - Closes swc-project#7710.
  • Loading branch information
kdy1 committed Aug 15, 2023
1 parent 566265c commit ba03e80
Show file tree
Hide file tree
Showing 60 changed files with 1,214 additions and 61,563 deletions.
63 changes: 63 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {}
},
"target": "esnext",
"loose": true,
"minify": {
"compress": {
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"unsafe": false,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_Function": false,
"unsafe_math": false,
"unsafe_symbols": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"const_to_let": true,
"pristine_globals": true
}
},
},
"isModule": true,
"minify": false
}
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const positions = {
top: 1,
left: 2,
right: 3,
bottom: 4,
}

const rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4,
}

export function PositionRender({ isRtl, position }) {

const display = (isRtl === 'fe-fe-fe' ? rtlPositions : positions)[position];

return <h1>
PositionRender: {display}
</h1>
}
23 changes: 23 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/input/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

const positions = {
top: 1,
left: 2,
right: 3,
bottom: 4,
}

const rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4,
}

export function PositionRender({ isRtl, position }) {

const display = (isRtl === 'fe-fe-fe' ? [rtlPositions] : { positions })[position];

return <h1>
PositionRender: {display}
</h1>
}
23 changes: 23 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/input/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

const positions = {
top: 1,
left: 2,
right: 3,
bottom: 4,
}

const rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4,
}

export function PositionRender({ isRtl, position }) {

const display = (isRtl === 'fe-fe-fe' ? [rtlPositions ?? 1] : { positions })[position];

return <h1>
PositionRender: {display}
</h1>
}
23 changes: 23 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/input/4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

const positions = {
top: 1,
left: 2,
right: 3,
bottom: 4,
}

const rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4,
}

export function PositionRender({ isRtl, position }) {

const display = (isRtl === 'fe-fe-fe' ? rtlPositions : { a: positions })[position];

return <h1>
PositionRender: {display}
</h1>
}
23 changes: 23 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/input/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

const positions = {
top: 1,
left: 2,
right: 3,
bottom: 4,
}

const rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4,
}

export function PositionRender({ isRtl, position }) {

const display = (isRtl === 'fe-fe-fe' ? rtlPositions : { a: [positions] })[position];

return <h1>
PositionRender: {display}
</h1>
}
15 changes: 15 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let positions = {
top: 1,
left: 2,
right: 3,
bottom: 4
}, rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4
};
export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? rtlPositions : positions)[position];
return React.createElement("h1", null, "PositionRender: ", display);
}
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/output/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let positions = {
top: 1,
left: 2,
right: 3,
bottom: 4
}, rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4
};
export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? [
rtlPositions
] : {
positions
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
}
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/output/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let positions = {
top: 1,
left: 2,
right: 3,
bottom: 4
}, rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4
};
export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? [
rtlPositions ?? 1
] : {
positions
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
}
17 changes: 17 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/output/4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let positions = {
top: 1,
left: 2,
right: 3,
bottom: 4
}, rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4
};
export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? rtlPositions : {
a: positions
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
}
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7700/output/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let positions = {
top: 1,
left: 2,
right: 3,
bottom: 4
}, rtlPositions = {
top: 1,
right: 2,
left: 3,
bottom: 4
};
export function PositionRender({ isRtl, position }) {
let display = ('fe-fe-fe' === isRtl ? rtlPositions : {
a: [
positions
]
})[position];
return React.createElement("h1", null, "PositionRender: ", display);
}
14 changes: 14 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7710/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"loose": false,
"minify": {
"compress": {
"hoist_props": true
}
},
"target": "es2022"
}
}
10 changes: 10 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7710/input/export-class-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export class Foo {
[obj] = 1;
};
10 changes: 10 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7710/input/export-class-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export class Foo {
foo = obj;
};
10 changes: 10 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7710/input/export-class-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export class Foo {
foo = obj ?? 1;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export default class {
[obj] = 1;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export default class {
[obj ?? 1] = 1;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export default class {
foo = obj ?? 1;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export default class {
foo = obj;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const obj = {
foo: 1,
bar: 2,
};

console.log(obj.bar);

export default class Foo {
foo = obj ?? 1;
};
Loading

0 comments on commit ba03e80

Please sign in to comment.