From 40f1c671619bb5f5a664d455060aea8d8368b2ab Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 21 Aug 2014 18:12:04 +0200 Subject: [PATCH] Remove trailing whitespace from acorn.js --- acorn.js | 56 ++++++++++++++++++++++---------------------- index.html | 69 ++++++++++++++++++++++++++---------------------------- 2 files changed, 61 insertions(+), 64 deletions(-) diff --git a/acorn.js b/acorn.js index fc7aeafd3d..acf76f6a6c 100644 --- a/acorn.js +++ b/acorn.js @@ -763,7 +763,7 @@ case 125: ++tokPos; return finishToken(_braceR); case 58: ++tokPos; return finishToken(_colon); case 63: ++tokPos; return finishToken(_question); - + case 96: // '`' if (options.ecmaVersion >= 6) { ++tokPos; @@ -944,7 +944,7 @@ function readCodePoint() { var ch = input.charCodeAt(tokPos), code; - + if (ch === 123) { if (options.ecmaVersion < 6) unexpected(); ++tokPos; @@ -1159,7 +1159,7 @@ this.start = tokStart; this.end = null; } - + exports.Node = Node; function SourceLocation() { @@ -1267,7 +1267,7 @@ switch (node.type) { case "Identifier": case "MemberExpression": - break; + break; case "ObjectExpression": node.type = "ObjectPattern"; @@ -1374,7 +1374,7 @@ : "Assigning to " + expr.name + " in strict mode" ); break; - + case "MemberExpression": if (!isBinding) break; @@ -1474,7 +1474,7 @@ else return parseExpressionStatement(node, expr); } } - + function parseBreakContinueStatement(node, keyword) { var isBreak = keyword == "break"; next(); @@ -1497,13 +1497,13 @@ if (i === labels.length) raise(node.start, "Unsyntactic " + keyword); return finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); } - + function parseDebuggerStatement(node) { next(); semicolon(); return finishNode(node, "DebuggerStatement"); } - + function parseDoStatement(node) { next(); labels.push(loopLabel); @@ -1514,7 +1514,7 @@ semicolon(); return finishNode(node, "DoWhileStatement"); } - + // Disambiguating between a `for` and a `for`/`in` or `for`/`of` // loop is non-trivial. Basically, we have to parse the init `var` // statement or expression, disallowing the `in` operator (see @@ -1522,7 +1522,7 @@ // whether the next token is `in` or `of`. When there is no init // part (semicolon immediately after the opening parenthesis), it // is a regular `for` loop. - + function parseForStatement(node) { next(); labels.push(loopLabel); @@ -1545,12 +1545,12 @@ } return parseFor(node, init); } - + function parseFunctionStatement(node) { next(); return parseFunction(node, true); } - + function parseIfStatement(node) { next(); node.test = parseParenExpression(); @@ -1558,7 +1558,7 @@ node.alternate = eat(_else) ? parseStatement() : null; return finishNode(node, "IfStatement"); } - + function parseReturnStatement(node) { if (!inFunction && !options.allowReturnOutsideFunction) raise(tokStart, "'return' outside of function"); @@ -1572,7 +1572,7 @@ else { node.argument = parseExpression(); semicolon(); } return finishNode(node, "ReturnStatement"); } - + function parseSwitchStatement(node) { next(); node.discriminant = parseParenExpression(); @@ -1607,7 +1607,7 @@ labels.pop(); return finishNode(node, "SwitchStatement"); } - + function parseThrowStatement(node) { next(); if (newline.test(input.slice(lastEnd, tokStart))) @@ -1616,7 +1616,7 @@ semicolon(); return finishNode(node, "ThrowStatement"); } - + function parseTryStatement(node) { next(); node.block = parseBlock(); @@ -1639,14 +1639,14 @@ raise(node.start, "Missing catch or finally clause"); return finishNode(node, "TryStatement"); } - + function parseVarStatement(node, kind) { next(); parseVar(node, false, kind); semicolon(); return finishNode(node, "VariableDeclaration"); } - + function parseWhileStatement(node) { next(); node.test = parseParenExpression(); @@ -1655,7 +1655,7 @@ labels.pop(); return finishNode(node, "WhileStatement"); } - + function parseWithStatement(node) { if (strict) raise(tokStart, "'with' in strict mode"); next(); @@ -1663,12 +1663,12 @@ node.body = parseStatement(); return finishNode(node, "WithStatement"); } - + function parseEmptyStatement(node) { next(); return finishNode(node, "EmptyStatement"); } - + function parseLabeledStatement(node, maybeName, expr) { for (var i = 0; i < labels.length; ++i) if (labels[i].name === maybeName) raise(expr.start, "Label '" + maybeName + "' is already declared"); @@ -1679,7 +1679,7 @@ node.label = expr; return finishNode(node, "LabeledStatement"); } - + function parseExpressionStatement(node, expr) { node.expression = expr; semicolon(); @@ -1920,7 +1920,7 @@ var node = startNode(); next(); return finishNode(node, "ThisExpression"); - + case _yield: if (inGenerator) return parseYield(); @@ -1930,7 +1930,7 @@ return parseArrowExpression(startNodeFrom(id), [id]); } return id; - + case _num: case _string: case _regexp: var node = startNode(); node.value = tokVal; @@ -2179,7 +2179,7 @@ initFunction(node); var defaults = node.defaults, hasDefaults = false; - + for (var i = 0, lastI = params.length - 1; i <= lastI; i++) { var param = params[i]; @@ -2209,7 +2209,7 @@ function parseFunctionParams(node) { var defaults = [], hasDefaults = false; - + expect(_parenL); for (;;) { if (eat(_parenR)) { @@ -2240,7 +2240,7 @@ function parseFunctionBody(node, allowExpression) { var isExpression = allowExpression && tokType !== _braceL; - + if (isExpression) { node.body = parseExpression(true); node.expression = true; @@ -2270,7 +2270,7 @@ // Parse a class declaration or literal (depending on the // `isStatement` parameter). - + function parseClass(node, isStatement) { next(); node.id = tokType === _name ? parseIdent() : isStatement ? unexpected() : null; diff --git a/index.html b/index.html index 08470b09f3..bfdc2e1c12 100644 --- a/index.html +++ b/index.html @@ -526,7 +526,7 @@ by a digit or another two dots.

case 125: ++tokPos; return finishToken(_braceR); case 58: ++tokPos; return finishToken(_colon); case 63: ++tokPos; return finishToken(_question); - + case 96: // '`' if (options.ecmaVersion >= 6) { ++tokPos; @@ -675,7 +675,7 @@ will return null unless the integer has exactly len di return finishToken(_num, val); }

Read a string value, interpreting backslash-escapes.

  function readCodePoint() {
     var ch = input.charCodeAt(tokPos), code;
-    
+
     if (ch === 123) {
       if (options.ecmaVersion < 6) unexpected();
       ++tokPos;
@@ -847,7 +847,7 @@ tests ("use strict"; 010; -- should fail).

this.start = tokStart; this.end = null; } - + exports.Node = Node; function SourceLocation() { @@ -916,7 +916,7 @@ if possible.

< switch (node.type) { case "Identifier": case "MemberExpression": - break; + break; case "ObjectExpression": node.type = "ObjectPattern"; @@ -1007,7 +1007,7 @@ to.

: "Assigning to " + expr.name + " in strict mode" ); break; - + case "MemberExpression": if (!isBinding) break; @@ -1090,7 +1090,7 @@ Identifier node, we switch to interpreting it as a label.

else return parseExpressionStatement(node, expr); } } - + function parseBreakContinueStatement(node, keyword) { var isBreak = keyword == "break"; next(); @@ -1110,13 +1110,13 @@ continue to.

< if (i === labels.length) raise(node.start, "Unsyntactic " + keyword); return finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); } - + function parseDebuggerStatement(node) { next(); semicolon(); return finishNode(node, "DebuggerStatement"); } - + function parseDoStatement(node) { next(); labels.push(loopLabel); @@ -1126,15 +1126,13 @@ continue to.

< node.test = parseParenExpression(); semicolon(); return finishNode(node, "DoWhileStatement"); - } -

Disambiguating between a for and a for/in or for/of + }

Disambiguating between a for and a for/in or for/of loop is non-trivial. Basically, we have to parse the init var statement or expression, disallowing the in operator (see the second parameter to parseExpression), and then check whether the next token is in or of. When there is no init part (semicolon immediately after the opening parenthesis), it -is a regular for loop.

  
-  function parseForStatement(node) {
+is a regular for loop.

  function parseForStatement(node) {
     next();
     labels.push(loopLabel);
     expect(_parenL);
@@ -1156,12 +1154,12 @@ is a regular for loop.

} return parseFor(node, init); } - + function parseFunctionStatement(node) { next(); return parseFunction(node, true); } - + function parseIfStatement(node) { next(); node.test = parseParenExpression(); @@ -1169,7 +1167,7 @@ is a regular for loop.

node.alternate = eat(_else) ? parseStatement() : null; return finishNode(node, "IfStatement"); } - + function parseReturnStatement(node) { if (!inFunction && !options.allowReturnOutsideFunction) raise(tokStart, "'return' outside of function"); @@ -1179,7 +1177,7 @@ possibility to insert one.

else { node.argument = parseExpression(); semicolon(); } return finishNode(node, "ReturnStatement"); } - + function parseSwitchStatement(node) { next(); node.discriminant = parseParenExpression(); @@ -1210,7 +1208,7 @@ adding statements to.

labels.pop(); return finishNode(node, "SwitchStatement"); } - + function parseThrowStatement(node) { next(); if (newline.test(input.slice(lastEnd, tokStart))) @@ -1219,7 +1217,7 @@ adding statements to.

semicolon(); return finishNode(node, "ThrowStatement"); } - + function parseTryStatement(node) { next(); node.block = parseBlock(); @@ -1242,14 +1240,14 @@ adding statements to.

raise(node.start, "Missing catch or finally clause"); return finishNode(node, "TryStatement"); } - + function parseVarStatement(node, kind) { next(); parseVar(node, false, kind); semicolon(); return finishNode(node, "VariableDeclaration"); } - + function parseWhileStatement(node) { next(); node.test = parseParenExpression(); @@ -1258,7 +1256,7 @@ adding statements to.

labels.pop(); return finishNode(node, "WhileStatement"); } - + function parseWithStatement(node) { if (strict) raise(tokStart, "'with' in strict mode"); next(); @@ -1266,12 +1264,12 @@ adding statements to.

node.body = parseStatement(); return finishNode(node, "WithStatement"); } - + function parseEmptyStatement(node) { next(); return finishNode(node, "EmptyStatement"); } - + function parseLabeledStatement(node, maybeName, expr) { for (var i = 0; i < labels.length; ++i) if (labels[i].name === maybeName) raise(expr.start, "Label '" + maybeName + "' is already declared"); @@ -1282,7 +1280,7 @@ adding statements to.

node.label = expr; return finishNode(node, "LabeledStatement"); } - + function parseExpressionStatement(node, expr) { node.expression = expr; semicolon(); @@ -1467,7 +1465,7 @@ or {}.

var node = startNode(); next(); return finishNode(node, "ThisExpression"); - + case _yield: if (inGenerator) return parseYield(); @@ -1477,7 +1475,7 @@ or {}.

return parseArrowExpression(startNodeFrom(id), [id]); } return id; - + case _num: case _string: case _regexp: var node = startNode(); node.value = tokVal; @@ -1603,7 +1601,7 @@ least, not without wrapping it in parentheses. Thus, it uses the

if (options.allowTrailingCommas && eat(_braceR)) break; } else first = false; - var prop = startNode(), kind, isGenerator; + var prop = startNode(), isGenerator; if (options.ecmaVersion >= 6) { prop.method = false; prop.shorthand = false; @@ -1612,19 +1610,19 @@ least, not without wrapping it in parentheses. Thus, it uses the

parsePropertyName(prop); if (eat(_colon)) { prop.value = parseExpression(true); - kind = prop.kind = "init"; + prop.kind = "init"; } else if (options.ecmaVersion >= 6 && tokType === _parenL) { - kind = prop.kind = "init"; + prop.kind = "init"; prop.method = true; prop.value = parseMethod(isGenerator); } else if (options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set")) { if (isGenerator) unexpected(); - kind = prop.kind = prop.key.name; + prop.kind = prop.key.name; parsePropertyName(prop); prop.value = parseMethod(false); } else if (options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { - kind = prop.kind = "init"; + prop.kind = "init"; prop.value = prop.key; prop.shorthand = true; } else unexpected(); @@ -1684,7 +1682,7 @@ least, not without wrapping it in parentheses. Thus, it uses the

initFunction(node); var defaults = node.defaults, hasDefaults = false; - + for (var i = 0, lastI = params.length - 1; i <= lastI; i++) { var param = params[i]; @@ -1710,7 +1708,7 @@ least, not without wrapping it in parentheses. Thus, it uses the

return finishNode(node, "ArrowFunctionExpression"); }

Parse function parameters.

  function parseFunctionParams(node) {
     var defaults = [], hasDefaults = false;
-    
+
     expect(_parenL);
     for (;;) {
       if (eat(_parenR)) {
@@ -1737,7 +1735,7 @@ least, not without wrapping it in parentheses. Thus, it uses the

if (hasDefaults) node.defaults = defaults; }

Parse function body and check parameters.

  function parseFunctionBody(node, allowExpression) {
     var isExpression = allowExpression && tokType !== _braceL;
-    
+
     if (isExpression) {
       node.body = parseExpression(true);
       node.expression = true;
@@ -1759,8 +1757,7 @@ or arguments.

checkFunctionParam(node.rest, nameHash); } }

Parse a class declaration or literal (depending on the -isStatement parameter).

  
-  function parseClass(node, isStatement) {
+isStatement parameter).

  function parseClass(node, isStatement) {
     next();
     node.id = tokType === _name ? parseIdent() : isStatement ? unexpected() : null;
     node.superClass = eat(_extends) ? parseExpression() : null;