-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/minifier): Implement correct
hoist_props
(#8593)
**Description:** - The option `hoist_props` now does what it's supposed to do. - Dropping of unused properties now does not drop properties too aggressively. - The initializer of a dropped variable declaration is now properly visited. - Indexing with string literals is not marked as a dynamic index anymore. This is required to handle codes like https://github.com/swc-project/swc/blob/c3f67ceb1eb0cab9ef4a47c321acf90684bf216a/crates/swc_ecma_minifier/tests/terser/compress/hoist_props/name_collision_1/input.js#L1-L7.
- Loading branch information
Showing
59 changed files
with
1,162 additions
and
1,250 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
//// [/a.js] | ||
var p = { | ||
a: 0, | ||
b: "hello" | ||
b: "hello", | ||
x: 8 | ||
}; | ||
p.a.toFixed(), p.b.substring(1), p.d; |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
//// [/a.js] | ||
var p = { | ||
a: 0, | ||
b: "hello" | ||
b: "hello", | ||
x: 8 | ||
}; | ||
p.a.toFixed(), p.b.substring(1), p.d; |
15 changes: 0 additions & 15 deletions
15
crates/swc/tests/tsc-references/checkJsdocTypeTagOnObjectProperty2.2.minified.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 |
---|---|---|
@@ -1,17 +1,2 @@ | ||
//// [checkJsdocTypeTagOnObjectProperty2.ts] | ||
//// [0.js] | ||
var lol, obj = { | ||
bar: 42, | ||
method1: function(n1) { | ||
return "42"; | ||
}, | ||
method2: function(n1) { | ||
return "lol"; | ||
}, | ||
arrowFunc: function() { | ||
var num = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "0"; | ||
return num + 42; | ||
}, | ||
lol: lol | ||
}; | ||
lol = "string", obj.method1(0), obj.method2("0"); |
9 changes: 3 additions & 6 deletions
9
...c-references/destructuringObjectBindingPatternAndAssignment8(target=es2022).2.minified.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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
//// [destructuringObjectBindingPatternAndAssignment8.ts] | ||
const K = { | ||
a: "a", | ||
b: "b" | ||
}, { [K.a]: aVal, [K.b]: bVal } = { | ||
[K.a]: 1, | ||
[K.b]: 1 | ||
const { a: aVal, b: bVal } = { | ||
a: 1, | ||
b: 1 | ||
}; | ||
console.log(aVal, bVal); |
7 changes: 2 additions & 5 deletions
7
.../tsc-references/destructuringObjectBindingPatternAndAssignment8(target=es5).2.minified.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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
//// [destructuringObjectBindingPatternAndAssignment8.ts] | ||
import { _ as _define_property } from "@swc/helpers/_/_define_property"; | ||
var _obj, K = { | ||
a: "a", | ||
b: "b" | ||
}, _ref = (_define_property(_obj = {}, K.a, 1), _define_property(_obj, K.b, 1), _obj); | ||
console.log(_ref[K.a], _ref[K.b]); | ||
var _obj, _ref = (_define_property(_obj = {}, "a", 1), _define_property(_obj, "b", 1), _obj); | ||
console.log(_ref.a, _ref.b); |
5 changes: 0 additions & 5 deletions
5
crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5.2.minified.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
5 changes: 0 additions & 5 deletions
5
crates/swc/tests/tsc-references/destructuringVariableDeclaration1ES5iterable.2.minified.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
5 changes: 0 additions & 5 deletions
5
crates/swc/tests/tsc-references/destructuringVariableDeclaration2.2.minified.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 |
---|---|---|
@@ -1,9 +1,4 @@ | ||
//// [destructuringVariableDeclaration2.ts] | ||
var _ref = { | ||
a1: !0, | ||
a2: 1 | ||
}; | ||
_ref.a1, _ref.a2; | ||
var _ref1 = [ | ||
1, | ||
2, | ||
|
7 changes: 2 additions & 5 deletions
7
crates/swc/tests/tsc-references/logicalNotOperatorWithAnyOtherType.2.minified.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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
//// [logicalNotOperatorWithAnyOtherType.ts] | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
var M, obj1 = { | ||
x: "", | ||
y: function() {} | ||
}, A = function() { | ||
var M, A = function() { | ||
function A() { | ||
_class_call_check(this, A); | ||
} | ||
return A.foo = function() {}, A; | ||
}(); | ||
M || (M = {}); | ||
var objA = new A(); | ||
obj1.x, obj1.y, objA.a, M.n, A.foo(), objA.a, M.n; | ||
objA.a, M.n, A.foo(), objA.a, M.n; |
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
6 changes: 1 addition & 5 deletions
6
crates/swc/tests/tsc-references/parserNotHexLiteral1.2.minified.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 |
---|---|---|
@@ -1,6 +1,2 @@ | ||
//// [parserNotHexLiteral1.ts] | ||
var x = { | ||
e0: "cat", | ||
x0: "dog" | ||
}; | ||
console.info(x.x0), console.info(x.e0); | ||
console.info("dog"), console.info("cat"); |
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
4 changes: 0 additions & 4 deletions
4
crates/swc/tests/tsc-references/stringLiteralTypesAsTags01.2.minified.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 |
---|---|---|
@@ -1,5 +1 @@ | ||
//// [stringLiteralTypesAsTags01.ts] | ||
var x = { | ||
kind: "A" | ||
}; | ||
x.kind, x.kind; |
4 changes: 0 additions & 4 deletions
4
crates/swc/tests/tsc-references/stringLiteralTypesAsTags02.2.minified.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 |
---|---|---|
@@ -1,5 +1 @@ | ||
//// [stringLiteralTypesAsTags02.ts] | ||
var x = { | ||
kind: "A" | ||
}; | ||
x.kind, x.kind; |
4 changes: 0 additions & 4 deletions
4
crates/swc/tests/tsc-references/stringLiteralTypesAsTags03.2.minified.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 |
---|---|---|
@@ -1,5 +1 @@ | ||
//// [stringLiteralTypesAsTags03.ts] | ||
var x = { | ||
kind: "A" | ||
}; | ||
x.kind, x.kind; |
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
7 changes: 0 additions & 7 deletions
7
crates/swc/tests/tsc-references/typeTagOnPropertyAssignment.2.minified.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 |
---|---|---|
@@ -1,8 +1 @@ | ||
//// [typeTagOnPropertyAssignment.js] | ||
var o = { | ||
a: "a", | ||
n: function() { | ||
return "b"; | ||
} | ||
}; | ||
o.a, o.n; |
4 changes: 3 additions & 1 deletion
4
crates/swc/tests/tsc-references/typedefTagExtraneousProperty.2.minified.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//// [typedefTagExtraneousProperty.js] | ||
var y = {}; | ||
var y = { | ||
bye: "no" | ||
}; | ||
y.ignoreMe = "ok but just because of the index signature", y.hi = "yes"; |
6 changes: 0 additions & 6 deletions
6
crates/swc/tests/tsc-references/typedefTagNested.2.minified.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 |
---|---|---|
@@ -1,7 +1 @@ | ||
//// [a.js] | ||
var sala = { | ||
name: "uppsala", | ||
not: 0, | ||
nested: "ok" | ||
}; | ||
sala.name, sala.not, sala.nested; |
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
7 changes: 2 additions & 5 deletions
7
crates/swc/tests/tsc-references/voidOperatorWithAnyOtherType.2.minified.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 |
---|---|---|
@@ -1,14 +1,11 @@ | ||
//// [voidOperatorWithAnyOtherType.ts] | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
var M, obj1 = { | ||
x: "", | ||
y: 1 | ||
}, A = function() { | ||
var M, A = function() { | ||
function A() { | ||
_class_call_check(this, A); | ||
} | ||
return A.foo = function() {}, A; | ||
}(); | ||
M || (M = {}); | ||
var objA = new A(); | ||
obj1.x, obj1.y, objA.a, M.n, A.foo(), objA.a, M.n; | ||
objA.a, M.n, A.foo(), objA.a, M.n; |
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
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
Oops, something went wrong.