[Pkg-mozext-commits] [adblock-plus] 289/464: Made sure that if/for/while body is always wrapped in a block, makes resulting code easier to read
David Prévot
taffit at moszumanska.debian.org
Tue Jul 22 20:44:26 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit e16a2903f615286f8ec47af4516ec2f63f630ff7
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon Aug 27 19:42:30 2012 +0200
Made sure that if/for/while body is always wrapped in a block, makes resulting code easier to read
---
autotest/abprewrite_source.js | 20 +++++++++++++++
autotest/test_abprewrite.js.expected | 28 +++++++++++++++++++++
autotest/test_abprewrite_module.js.expected | 28 +++++++++++++++++++++
scripts/abprewrite.js | 38 ++++++++++++++++++++++++++---
4 files changed, 111 insertions(+), 3 deletions(-)
diff --git a/autotest/abprewrite_source.js b/autotest/abprewrite_source.js
index 56f5e16..978926c 100644
--- a/autotest/abprewrite_source.js
+++ b/autotest/abprewrite_source.js
@@ -39,6 +39,26 @@ let b = {
get foo() 1
};
+if (a == b)
+ foo();
+else if (a == c)
+ bar();
+else
+ bas();
+if (a == b);
+
+for (var a = 0; a < b.length; a++)
+ foo();
+for (var a = 0; a < b.length; a++);
+
+for (var a in b)
+ foo();
+for (var a in b);
+
+while (a==b)
+ foo();
+while (a==b);
+
function genFunc()
{
for (var i = 0; i < 10; i++)
diff --git a/autotest/test_abprewrite.js.expected b/autotest/test_abprewrite.js.expected
index 5188531..06d9810 100644
--- a/autotest/test_abprewrite.js.expected
+++ b/autotest/test_abprewrite.js.expected
@@ -66,6 +66,34 @@ var b =
return 1;
}
};
+if (a == b)
+{
+ foo();
+}
+else if (a == c)
+{
+ bar();
+}
+else
+{
+ bas();
+}
+if (a == b){}
+for (var a = 0; a < b.length; a++)
+{
+ foo();
+}
+for (var a = 0; a < b.length; a++){}
+for (var a in b)
+{
+ foo();
+}
+for (var a in b){}
+while (a==b)
+{
+ foo();
+}
+while (a==b){}
function genFunc()
{
diff --git a/autotest/test_abprewrite_module.js.expected b/autotest/test_abprewrite_module.js.expected
index 5bf48cb..55ef609 100644
--- a/autotest/test_abprewrite_module.js.expected
+++ b/autotest/test_abprewrite_module.js.expected
@@ -69,6 +69,34 @@ require.scopes["abprewrite_source"] = (function()
return 1;
}
};
+ if (a == b)
+ {
+ foo();
+ }
+ else if (a == c)
+ {
+ bar();
+ }
+ else
+ {
+ bas();
+ }
+ if (a == b){}
+ for (var a = 0; a < b.length; a++)
+ {
+ foo();
+ }
+ for (var a = 0; a < b.length; a++){}
+ for (var a in b)
+ {
+ foo();
+ }
+ for (var a in b){}
+ while (a==b)
+ {
+ foo();
+ }
+ while (a==b){}
function genFunc()
{
diff --git a/scripts/abprewrite.js b/scripts/abprewrite.js
index fc0c851..20bb18a 100644
--- a/scripts/abprewrite.js
+++ b/scripts/abprewrite.js
@@ -130,6 +130,14 @@ function IncExpression(variable)
};
}
+function ensureBlock(ast)
+{
+ if (ast.type == "BlockStatement")
+ return ast;
+ else
+ return {type: "BlockStatement", body: (ast.type == "EmptyStatement" ? [] : [ast])};
+}
+
function modifyAST(ast)
{
// Do the necessary modifications
@@ -300,6 +308,29 @@ function modifyVariableDeclaration(ast)
return ast;
}
+function modifyForStatement(ast)
+{
+ // Make sure that the loop body is always wrapped in a block
+ ast.body = ensureBlock(ast.body);
+ return ast;
+}
+
+function modifyWhileStatement(ast)
+{
+ // Make sure that the loop body is always wrapped in a block
+ ast.body = ensureBlock(ast.body);
+ return ast;
+}
+
+function modifyIfStatement(ast)
+{
+ // Make sure that the statements are always wrapped in a block
+ ast.consequent = ensureBlock(ast.consequent);
+ if (ast.alternate && ast.alternate.type != "IfStatement")
+ ast.alternate = ensureBlock(ast.alternate);
+ return ast;
+}
+
function modifyForInStatement(ast)
{
if (ast.each)
@@ -318,9 +349,7 @@ function modifyForInStatement(ast)
// }
let loopIndex = Identifier("_loopIndex" + options.varIndex++);
- let block = ast.body;
- if (block.type != "BlockStatement")
- block = {type: "BlockStatement", body: (block.type == "EmptyStatement" ? [] : [block])};
+ let block = ensureBlock(ast.body);
if (ast.left.type == "VariableDeclaration")
block.body.unshift(VariableDeclaration(ast.left.declarations[0].id, Member(ast.right, loopIndex, true)));
else
@@ -335,6 +364,9 @@ function modifyForInStatement(ast)
};
}
+ // Make sure that the loop body is always wrapped in a block
+ ast.body = ensureBlock(ast.body);
+
return ast;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list