forked from mozilla/pdf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the webpack+acorn transform with a Babel plugin
This commit converts the pdfjsdev-loader transform into a Babel plugin, to skip a AST->string->AST round-trip. Before this commit, the webpack build process was: 1. Babel parses the code 2. Babel transforms the AST 3. Babel generates the code 4. Acorn parses the code 5. pdfjsdev-loader transforms the AST 6. @javascript-obfuscator/escodegen generates the code 7. Webpack parses the file 8. Webpack concatenates the files After this commit, it is reduced to: 1. Babel parses the code 2. Babel transforms the AST 3. babel-plugin-pdfjs-preprocessor transforms the AST 4. Babel generates the code 5. Webpack parses the file 6. Webpack concatenates the files This change improves the build time by ~25% (tested on MacBook Air M2): - `gulp lib`: 3.4s to 2.6s - `gulp dist`: 36s to 29s - `gulp generic`: 5.5s to 4.0s - `gulp mozcentral`: 4.7s to 3.2s The new Babel plugin doesn't support the `saveComments` option of pdfjsdev-loader, and it just always discards comments. Even though pdfjsdev-loader supported multiple values for that option, it was effectively ignored due to `acorn` dropping comments by default.
- Loading branch information
1 parent
f5bb9bc
commit f724ae9
Showing
16 changed files
with
282 additions
and
474 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,10 +1,10 @@ | ||
function test() { | ||
"test"; | ||
"1"; | ||
"2"; | ||
"3"; | ||
if ("test") { | ||
"5"; | ||
} | ||
"4"; | ||
"test"; | ||
"1"; | ||
"2"; | ||
"3"; | ||
if ("test") { | ||
"5"; | ||
} | ||
"4"; | ||
} |
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,17 @@ | ||
function f1() { | ||
"1"; | ||
"2"; | ||
"1"; | ||
"2"; | ||
} | ||
function f2() { | ||
"1"; | ||
"2"; | ||
"1"; | ||
"2"; | ||
} | ||
function f3() { | ||
if ("1") { | ||
"1"; | ||
} | ||
"2"; | ||
if ("3") { | ||
"4"; | ||
} | ||
if ("1") { | ||
"1"; | ||
} | ||
"2"; | ||
if ("3") { | ||
"4"; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
function f1() { | ||
} | ||
function f1() {} | ||
function f2() { | ||
return 1; | ||
return 1; | ||
} | ||
function f3() { | ||
var i = 0; | ||
throw "test"; | ||
var i = 0; | ||
throw "test"; | ||
} | ||
function f4() { | ||
var i = 0; | ||
var i = 0; | ||
} | ||
var obj = { | ||
method1() {}, | ||
method2() {} | ||
}; | ||
class C { | ||
method1() {} | ||
method2() {} | ||
} | ||
|
||
var arrow1 = () => {}; | ||
var arrow2 = () => {}; |
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
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 +1 @@ | ||
{ 'test': 'test' } | ||
{ "test": "test" } |
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,17 @@ | ||
if ('test') { | ||
"1"; | ||
"1"; | ||
} | ||
{ | ||
"1"; | ||
"1"; | ||
} | ||
{ | ||
"1"; | ||
"1"; | ||
} | ||
; | ||
{ | ||
"2"; | ||
"2"; | ||
} | ||
; | ||
if ('1') { | ||
"1"; | ||
"1"; | ||
} |
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,5 @@ | ||
import { Test } from 'import-name'; | ||
import { Test } from "import-name"; | ||
import { Test2 } from './non-alias'; | ||
export { | ||
Test3 | ||
} from 'import-name'; | ||
var Imp = require('import-name'); | ||
export { Test3 } from "import-name"; | ||
var Imp = require("import-name"); | ||
var Imp2 = require('./non-alias'); |
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
This file was deleted.
Oops, something went wrong.
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.