Skip to content

Commit 858eadf

Browse files
authored
Run prettier on all JS code under tools/. NFC (#19252)
1 parent 67ebee3 commit 858eadf

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"scripts": {
2020
"lint": "eslint .",
21-
"fmt": "prettier --write tools/acorn-optimizer.js",
22-
"check": "prettier --check tools/acorn-optimizer.js"
21+
"fmt": "prettier --write tools/*.js",
22+
"check": "prettier --check tools/*.js"
2323
}
2424
}

tools/lz4-compress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function load(f) {
3939
globalEval(read(f));
4040
}
4141

42-
global.assert = function(x, message) {
42+
global.assert = (x, message) => {
4343
if (!x) throw new Error(message);
4444
};
4545

tools/preprocessor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ global.vm = require('vm');
2121
const arguments_ = process.argv.slice(2);
2222
const debug = false;
2323

24-
global.print = function(x) {
24+
global.print = (x) => {
2525
process.stdout.write(x + '\n');
2626
};
27-
global.printErr = function(x) {
27+
global.printErr = (x) => {
2828
process.stderr.write(x + '\n');
2929
};
3030

@@ -41,12 +41,12 @@ function find(filename) {
4141
return filename;
4242
}
4343

44-
global.read = function(filename) {
44+
global.read = (filename) => {
4545
const absolute = find(filename);
4646
return fs.readFileSync(absolute).toString();
4747
};
4848

49-
global.load = function(f) {
49+
global.load = (f) => {
5050
(0, eval)(read(f) + '//# sourceURL=' + find(f));
5151
};
5252

tools/unsafe_optimizations.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ function optPassSimplifyModularizeFunction(ast) {
4545
if (node.params.length == 1 && node.params[0].name == 'Module') {
4646
const body = node.body.body;
4747
// Nuke 'Module = Module || {};'
48-
if (body[0].type == 'ExpressionStatement' && body[0].expression.type == 'AssignmentExpression' && body[0].expression.left.name == 'Module') {
48+
if (
49+
body[0].type == 'ExpressionStatement' &&
50+
body[0].expression.type == 'AssignmentExpression' &&
51+
body[0].expression.left.name == 'Module'
52+
) {
4953
body.splice(0, 1);
5054
}
5155
// Replace 'function(Module) {var f = Module;' -> 'function(f) {'
52-
if (body[0].type == 'VariableDeclaration' && body[0].declarations[0]?.init?.name == 'Module') {
56+
if (
57+
body[0].type == 'VariableDeclaration' &&
58+
body[0].declarations[0]?.init?.name == 'Module'
59+
) {
5360
node.params[0].name = body[0].declarations[0].id.name;
5461
body[0].declarations.splice(0, 1);
5562
if (body[0].declarations.length == 0) {
@@ -66,8 +73,13 @@ function optPassSimplifyModularizeFunction(ast) {
6673
function optPassSimplifyModuleInitialization(ast) {
6774
visitNodes(ast, ['BlockStatement', 'Program'], (node) => {
6875
for (const n of node.body) {
69-
if (n.type == 'ExpressionStatement' && n.expression.type == 'LogicalExpression' && n.expression.operator == '||' &&
70-
n.expression.left.name === n.expression.right.left?.name && n.expression.right.right.name == 'Module') {
76+
if (
77+
n.type == 'ExpressionStatement' &&
78+
n.expression.type == 'LogicalExpression' &&
79+
n.expression.operator == '||' &&
80+
n.expression.left.name === n.expression.right.left?.name &&
81+
n.expression.right.right.name == 'Module'
82+
) {
7183
// Clear out the logical operator.
7284
n.expression = n.expression.right;
7385
// There is only one Module assignment, so can finish the pass here.
@@ -169,7 +181,11 @@ function optPassMergeVarInitializationAssignments(ast) {
169181
const name = nodeArray[i].expression.left.name;
170182
for (let j = i - 1; j >= 0; --j) {
171183
const n = nodeArray[j];
172-
if (n.type == 'ExpressionStatement' && n.expression.type == 'AssignmentExpression' && n.expression.left.name == name) {
184+
if (
185+
n.type == 'ExpressionStatement' &&
186+
n.expression.type == 'AssignmentExpression' &&
187+
n.expression.left.name == name
188+
) {
173189
return [null, null];
174190
}
175191
if (n.type == 'VariableDeclaration') {
@@ -248,7 +264,10 @@ function test(input, expected) {
248264

249265
function runTests() {
250266
// optPassSimplifyModularizeFunction:
251-
test('var Module = function(Module) {Module = Module || {};var f = Module;}', 'var Module=function(f){};');
267+
test(
268+
'var Module = function(Module) {Module = Module || {};var f = Module;}',
269+
'var Module=function(f){};'
270+
);
252271

253272
// optPassSimplifyModuleInitialization:
254273
test('b || (b = Module);', 'b=Module;');
@@ -258,7 +277,10 @@ function runTests() {
258277
test('new Uint16Array(a);', '');
259278
test('new Uint16Array(a),new Uint16Array(a);', ';');
260279
test("new function(a) {new TextDecoder(a);}('utf8');", '');
261-
test('WebAssembly.instantiate(c.wasm,{}).then(function(a){new Int8Array(b);});', 'WebAssembly.instantiate(c.wasm,{}).then(function(a){});');
280+
test(
281+
'WebAssembly.instantiate(c.wasm,{}).then(function(a){new Int8Array(b);});',
282+
'WebAssembly.instantiate(c.wasm,{}).then(function(a){});'
283+
);
262284
test('let x=new Uint16Array(a);', 'let x=new Uint16Array(a);');
263285

264286
// optPassMergeVarDeclarations:
@@ -271,7 +293,10 @@ function runTests() {
271293
test('var a = 1, b; ++a; var c;', 'var a=1,b,c;++a;');
272294

273295
// Interaction between multiple passes:
274-
test('var d, f; f = new Uint8Array(16); var h = f.buffer; d = new Uint8Array(h);', 'var f=new Uint8Array(16),h=f.buffer,d=new Uint8Array(h);');
296+
test(
297+
'var d, f; f = new Uint8Array(16); var h = f.buffer; d = new Uint8Array(h);',
298+
'var f=new Uint8Array(16),h=f.buffer,d=new Uint8Array(h);'
299+
);
275300

276301
// Older versions of terser would produce sub-optimal output for this.
277302
// We keep this test around to prevent regression.

0 commit comments

Comments
 (0)