From 3ca3aa5a25f77f2a73b8cf4cb30c2b9d922462b4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 10 Jun 2013 16:52:22 +0200 Subject: [PATCH] Run a lint pass, clean up lots of small issues --- acorn.js | 22 +++++++++++----------- acorn_loose.js | 4 ++-- index.html | 26 +++++++++++--------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/acorn.js b/acorn.js index 00c4e47148..a61ccb28b7 100644 --- a/acorn.js +++ b/acorn.js @@ -588,14 +588,14 @@ function readToken_caret() { // '^' var next = input.charCodeAt(tokPos+1); if (next === 61) return finishOp(_assign, 2); - return finishOp(_bin4, 1); + return finishOp(_bin4, 1); } function readToken_plus_min(code) { // '+-' var next = input.charCodeAt(tokPos+1); if (next === code) return finishOp(_incdec, 2); if (next === 61) return finishOp(_assign, 2); - return finishOp(_plusmin, 1); + return finishOp(_plusmin, 1); } function readToken_lt_gt(code) { // '<>' @@ -610,7 +610,7 @@ size = input.charCodeAt(tokPos+2) === 61 ? 3 : 2; return finishOp(_bin7, size); } - + function readToken_eq_excl(code) { // '=!' var next = input.charCodeAt(tokPos+1); if (next === 61) return finishOp(_bin6, input.charCodeAt(tokPos+2) === 61 ? 3 : 2); @@ -693,7 +693,7 @@ // Identifier or keyword. '\uXXXX' sequences are allowed in // identifiers, so '\' also dispatches to that. if (isIdentifierStart(code) || code === 92 /* '\' */) return readWord(); - + var tok = getTokenFromCode(code); if (tok === false) { @@ -702,7 +702,7 @@ var ch = String.fromCharCode(code); if (ch === "\\" || nonASCIIidentifierStart.test(ch)) return readWord(); raise(tokPos, "Unexpected character '" + ch + "'"); - } + } return tok; } @@ -768,7 +768,7 @@ } // Read an integer, octal integer, or floating-point number. - + function readNumber(startsWithDot) { var start = tokPos, isFloat = false, octal = input.charCodeAt(tokPos) === 48; if (!startsWithDot && readInt(10) === null) raise(start, "Invalid number"); @@ -781,7 +781,7 @@ if (next === 69 || next === 101) { // 'eE' next = input.charCodeAt(++tokPos); if (next === 43 || next === 45) ++tokPos; // '+-' - if (readInt(10) === null) raise(start, "Invalid number") + if (readInt(10) === null) raise(start, "Invalid number"); isFloat = true; } if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number"); @@ -931,7 +931,7 @@ // ### Parser utilities // Continue to the next token. - + function next() { lastStart = tokStart; lastEnd = tokEnd; @@ -1185,7 +1185,7 @@ // In `return` (and `break`/`continue`), the keywords with // optional arguments, we eagerly look for a semicolon or the // possibility to insert one. - + if (eat(_semi) || canInsertSemicolon()) node.argument = null; else { node.argument = parseExpression(); semicolon(); } return finishNode(node, "ReturnStatement"); @@ -1200,7 +1200,7 @@ // Statements under must be grouped (by label) in SwitchCase // nodes. `cur` is used to keep the node that we are currently // adding statements to. - + for (var cur, sawDefault; tokType != _braceR;) { if (tokType === _case || tokType === _default) { var isCase = tokType === _case; @@ -1586,7 +1586,7 @@ // New's precedence is slightly tricky. It must allow its argument // to be a `[]` or dot subscript expression, but not a call — at - // least, not without wrapping it in parentheses. Thus, it uses the + // least, not without wrapping it in parentheses. Thus, it uses the function parseNew() { var node = startNode(); diff --git a/acorn_loose.js b/acorn_loose.js index a1ee6d92c3..d01b6e61a7 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -213,7 +213,7 @@ var node = new node_t(token.start); if (options.locations) node.loc = new node_loc_t(); - return node + return node; } function startNodeFrom(other) { @@ -644,7 +644,7 @@ case tt._null: case tt._true: case tt._false: var node = startNode(); node.value = token.type.atomValue; - node.raw = token.type.keyword + node.raw = token.type.keyword; next(); return finishNode(node, "Literal"); diff --git a/index.html b/index.html index 27f80412b7..7ce460e229 100644 --- a/index.html +++ b/index.html @@ -390,14 +390,14 @@ into it.

function readToken_caret() { // '^' var next = input.charCodeAt(tokPos+1); if (next === 61) return finishOp(_assign, 2); - return finishOp(_bin4, 1); + return finishOp(_bin4, 1); } function readToken_plus_min(code) { // '+-' var next = input.charCodeAt(tokPos+1); if (next === code) return finishOp(_incdec, 2); if (next === 61) return finishOp(_assign, 2); - return finishOp(_plusmin, 1); + return finishOp(_plusmin, 1); } function readToken_lt_gt(code) { // '<>' @@ -412,7 +412,7 @@ into it.

size = input.charCodeAt(tokPos+2) === 61 ? 3 : 2; return finishOp(_bin7, size); } - + function readToken_eq_excl(code) { // '=!' var next = input.charCodeAt(tokPos+1); if (next === 61) return finishOp(_bin6, input.charCodeAt(tokPos+2) === 61 ? 3 : 2); @@ -476,14 +476,14 @@ of the type given by its first argument.

var code = input.charCodeAt(tokPos);

Identifier or keyword. '\uXXXX' sequences are allowed in identifiers, so '\' also dispatches to that.

    if (isIdentifierStart(code) || code === 92 /* '\' */) return readWord();
-    
+
     var tok = getTokenFromCode(code);
 
     if (tok === false) {

If we are here, we either found a non-ASCII identifier character, or something that's entirely disallowed.

      var ch = String.fromCharCode(code);
       if (ch === "\\" || nonASCIIidentifierStart.test(ch)) return readWord();
       raise(tokPos, "Unexpected character '" + ch + "'");
-    } 
+    }
     return tok;
   }
 
@@ -536,8 +536,7 @@ will return null unless the integer has exactly len di
     if (val == null) raise(tokStart + 2, "Expected hexadecimal number");
     if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number");
     return finishToken(_num, val);
-  }

Read an integer, octal integer, or floating-point number.

  
-  function readNumber(startsWithDot) {
+  }

Read an integer, octal integer, or floating-point number.

  function readNumber(startsWithDot) {
     var start = tokPos, isFloat = false, octal = input.charCodeAt(tokPos) === 48;
     if (!startsWithDot && readInt(10) === null) raise(start, "Invalid number");
     if (input.charCodeAt(tokPos) === 46) {
@@ -549,7 +548,7 @@ will return null unless the integer has exactly len di
     if (next === 69 || next === 101) { // 'eE'
       next = input.charCodeAt(++tokPos);
       if (next === 43 || next === 45) ++tokPos; // '+-'
-      if (readInt(10) === null) raise(start, "Invalid number")
+      if (readInt(10) === null) raise(start, "Invalid number");
       isFloat = true;
     }
     if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number");
@@ -668,8 +667,7 @@ way, it'll receive the node for x[1] already parsed, and wraps
 operator precedence, because it is much more compact than using
 the technique outlined above, which uses different, nesting
 functions to specify precedence, for all of the ten binary
-precedence levels that JavaScript defines.

Parser utilities

Continue to the next token.

  
-  function next() {
+precedence levels that JavaScript defines.

Parser utilities

Continue to the next token.

  function next() {
     lastStart = tokStart;
     lastEnd = tokEnd;
     lastEndLoc = tokEndLoc;
@@ -854,8 +852,7 @@ a regular for loop.

if (!inFunction) raise(tokStart, "'return' outside of function"); next();

In return (and break/continue), the keywords with optional arguments, we eagerly look for a semicolon or the -possibility to insert one.

      
-      if (eat(_semi) || canInsertSemicolon()) node.argument = null;
+possibility to insert one.

      if (eat(_semi) || canInsertSemicolon()) node.argument = null;
       else { node.argument = parseExpression(); semicolon(); }
       return finishNode(node, "ReturnStatement");
 
@@ -866,8 +863,7 @@ possibility to insert one.

expect(_braceL); labels.push(switchLabel);

Statements under must be grouped (by label) in SwitchCase nodes. cur is used to keep the node that we are currently -adding statements to.

      
-      for (var cur, sawDefault; tokType != _braceR;) {
+adding statements to.

      for (var cur, sawDefault; tokType != _braceR;) {
         if (tokType === _case || tokType === _default) {
           var isCase = tokType === _case;
           if (cur) finishNode(cur, "SwitchCase");
@@ -1190,7 +1186,7 @@ or {}.

} }

New's precedence is slightly tricky. It must allow its argument to be a [] or dot subscript expression, but not a call — at -least, not without wrapping it in parentheses. Thus, it uses the

  function parseNew() {
+least, not without wrapping it in parentheses. Thus, it uses the

  function parseNew() {
     var node = startNode();
     next();
     node.callee = parseSubscripts(parseExprAtom(), true);