forked from swc-project/swc
-
Notifications
You must be signed in to change notification settings - Fork 4
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): Detect TypeScript enum initialization pattern (swc…
…-project#8986) **Description:** We can optimize ```js var Foo; Foo || Foo = {}; ``` This code looks strange, but ```ts enum Foo { a = 1, b = 2, } ``` transpiles to ```js var Foo; (function(Foo) { Foo[Foo["a"] = 1] = "a"; Foo[Foo["b"] = 2] = "b"; })(Foo || (Foo = {})); ``` and after minification it becomes ```js var Foo, Foo1; (Foo1 = Foo || (Foo = {}))[Foo1.a = 1] = "a", Foo1[Foo1.b = 2] = "b"; ```
- Loading branch information
Showing
384 changed files
with
885 additions
and
1,049 deletions.
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
...sts/tsc-references/AmbientModuleAndNonAmbientClassWithSameNameAndCommonRoot.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,5 @@ | ||
//// [module.d.ts] | ||
//// [classPoint.ts] | ||
var A; | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
(A || (A = {})).Point = function Point(x, y) { | ||
_class_call_check(this, Point), this.x = x, this.y = y; | ||
}; | ||
//// [test.ts] | ||
A.Point.Origin, new A.Point(0, 0); |
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
4 changes: 2 additions & 2 deletions
4
...ences/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.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
4 changes: 2 additions & 2 deletions
4
...es/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.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
8 changes: 4 additions & 4 deletions
8
crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRoot.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
8 changes: 4 additions & 4 deletions
8
crates/swc/tests/tsc-references/ClassAndModuleWithSameNameAndCommonRootES6.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
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/ES5SymbolProperty2.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
6 changes: 3 additions & 3 deletions
6
...c/tests/tsc-references/ExportClassWhichExtendsInterfaceWithInaccessibleType.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,11 +1,11 @@ | ||
//// [ExportClassWhichExtendsInterfaceWithInaccessibleType.ts] | ||
var A, A1, Point2d; | ||
var A, Point2d; | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
A1 = A || (A = {}), Point2d = function() { | ||
A = {}, Point2d = function() { | ||
function Point2d(x, y) { | ||
_class_call_check(this, Point2d), this.x = x, this.y = y; | ||
} | ||
return Point2d.prototype.fromOrigin = function(p) { | ||
return 1; | ||
}, Point2d; | ||
}(), A1.Point2d = Point2d; | ||
}(), A.Point2d = Point2d; |
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
...ests/tsc-references/ExportClassWithInaccessibleTypeInIndexerTypeAnnotations.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 @@ | ||
//// [ExportClassWithInaccessibleTypeInIndexerTypeAnnotations.ts] | ||
var A; | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
(A || (A = {})).points = function points() { | ||
_class_call_check(this, points); | ||
}; |
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: 3 additions & 3 deletions
6
...erences/ExportFunctionWithAccessibleTypesInParameterAndReturnTypeAnnotation.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
6 changes: 3 additions & 3 deletions
6
...tsc-references/ExportFunctionWithInaccessibleTypesInParameterTypeAnnotation.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
6 changes: 3 additions & 3 deletions
6
...ts/tsc-references/ExportFunctionWithInaccessibleTypesInReturnTypeAnnotation.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
6 changes: 3 additions & 3 deletions
6
...ssibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations.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
6 changes: 3 additions & 3 deletions
6
...tsc-references/ExportInterfaceWithInaccessibleTypeInTypeParameterConstraint.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
6 changes: 3 additions & 3 deletions
6
...wc/tests/tsc-references/ExportModuleWithAccessibleTypesOnItsExportedMembers.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
8 changes: 4 additions & 4 deletions
8
...ObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInMemberTypeAnnotations.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,12 +1,12 @@ | ||
//// [ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInMemberTypeAnnotations.ts] | ||
var A, A1, Point; | ||
var A, Point; | ||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check"; | ||
A1 = A || (A = {}), Point = function Point(x, y) { | ||
A = {}, Point = function Point(x, y) { | ||
_class_call_check(this, Point), this.x = x, this.y = y; | ||
}, A1.Origin = { | ||
}, A.Origin = { | ||
x: 0, | ||
y: 0 | ||
}, A1.Unity = { | ||
}, A.Unity = { | ||
start: new Point(0, 0), | ||
end: new Point(1, 0) | ||
}; |
2 changes: 0 additions & 2 deletions
2
...LiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.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,4 +1,2 @@ | ||
//// [ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.ts] | ||
var A; | ||
import "@swc/helpers/_/_class_call_check"; | ||
(A || (A = {})).UnitSquare = null; |
2 changes: 0 additions & 2 deletions
2
...sc-references/ExportVariableOfGenericTypeWithInaccessibleTypeAsTypeArgument.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,4 +1,2 @@ | ||
//// [ExportVariableOfGenericTypeWithInaccessibleTypeAsTypeArgument.ts] | ||
var A; | ||
import "@swc/helpers/_/_class_call_check"; | ||
(A || (A = {})).beez2 = []; |
5 changes: 0 additions & 5 deletions
5
...s/swc/tests/tsc-references/ExportVariableWithAccessibleTypeInTypeAnnotation.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 @@ | ||
//// [ExportVariableWithAccessibleTypeInTypeAnnotation.ts] | ||
var A; | ||
(A || (A = {})).Origin = { | ||
x: 0, | ||
y: 0 | ||
}; |
6 changes: 3 additions & 3 deletions
6
...swc/tests/tsc-references/ExportVariableWithInaccessibleTypeInTypeAnnotation.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
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
11 changes: 2 additions & 9 deletions
11
...wc/tests/tsc-references/FunctionAndModuleWithSameNameAndDifferentCommonRoot.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
8 changes: 4 additions & 4 deletions
8
crates/swc/tests/tsc-references/ModuleAndClassWithSameNameAndCommonRoot.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
Oops, something went wrong.