-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(builtins): run builtins transform on multi pass (#859)
Co-authored-by: Boopathi Rajaa <me@boopathi.in> * perf(builtins): run builtins transform on multi pass * don't evaluate in minify-builtins * fix cases where Math is already found in scope * add comments * add test * bail out for already transformed ones
- Loading branch information
1 parent
5dbc73f
commit 01eac1c
Showing
7 changed files
with
109 additions
and
47 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
packages/babel-plugin-minify-builtins/__tests__/fixtures/builtin-methods/expected.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,7 @@ | ||
function c() { | ||
var _Mathmax = Math.max; | ||
let a = 10; | ||
const d = false; | ||
const d = Number.isNaN(a); | ||
_Mathmax(a, b) + _Mathmax(b, a); | ||
return d && true; | ||
return d && Number.isFinite(a); | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/babel-plugin-minify-builtins/__tests__/fixtures/evaluate-builtins/expected.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,4 @@ | ||
const a = 5; | ||
const a = Math.max(Math.floor(2), 5); | ||
let b = 1.8; | ||
let x = 5; | ||
let x = Math.floor(Math.max(a, b)); | ||
foo(x); |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ var a = () => { | |
c: () => { | ||
_Mathfloor(d); | ||
|
||
2; | ||
Math.max(2, 1); | ||
}; | ||
}; | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
packages/babel-plugin-minify-builtins/__tests__/fixtures/local-binding/actual.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function wow() { | ||
var Math = foo; | ||
|
||
var nativeMin = Math.min; | ||
|
||
var xMin = Math.min; | ||
var yMin = Math.min; | ||
|
||
return { | ||
baseInRange: Math.min(foo), | ||
min: nativeMin(bar), | ||
x: xMin(x), | ||
y: yMin(y), | ||
xMin, | ||
yMin, | ||
nativeMin | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/babel-plugin-minify-builtins/__tests__/fixtures/local-binding/expected.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function wow() { | ||
var _Mathmin = (0, eval)("this").Math.min; | ||
var Math = foo; | ||
var nativeMin = _Mathmin; | ||
var xMin = _Mathmin; | ||
var yMin = _Mathmin; | ||
return { | ||
baseInRange: _Mathmin(foo), | ||
min: nativeMin(bar), | ||
x: xMin(x), | ||
y: yMin(y), | ||
xMin, | ||
yMin, | ||
nativeMin | ||
}; | ||
} |
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