[Pkg-javascript-commits] [node-acorn-jsx] 128/484: [loose parser] Refine closing heuristic for expression lists

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit 2372b12df71a34c1f4abff89b0473fa6c2e7126d
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Mon Jun 10 18:02:17 2013 +0200

    [loose parser] Refine closing heuristic for expression lists
    
    Issue marijnh/tern#171
---
 acorn_loose.js | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index d01b6e6..8b3ea85 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -181,10 +181,10 @@
     }
   }
 
-  function closesBlock(closeTok, indent, line) {
+  function closes(closeTok, indent, line, blockHeuristic) {
     if (token.type === closeTok || token.type === tt.eof) return true;
     if (line != curLineStart && curIndent < indent && tokenStartsLine() &&
-        (nextLineStart >= input.length ||
+        (!blockHeuristic || nextLineStart >= input.length ||
          indentationAfter(nextLineStart) < indent)) return true;
     return false;
   }
@@ -352,7 +352,7 @@
       pushCx();
       expect(tt.braceL);
 
-      for (var cur; !closesBlock(tt.braceR, blockIndent, line);) {
+      for (var cur; !closes(tt.braceR, blockIndent, line, true);) {
         if (token.type === tt._case || token.type === tt._default) {
           var isCase = token.type === tt._case;
           if (cur) finishNode(cur, "SwitchCase");
@@ -449,7 +449,7 @@
     expect(tt.braceL);
     var blockIndent = curIndent, line = curLineStart;
     node.body = [];
-    while (!closesBlock(tt.braceR, blockIndent, line))
+    while (!closes(tt.braceR, blockIndent, line, true))
       node.body.push(parseStatement());
     popCx();
     eat(tt.braceR);
@@ -698,7 +698,7 @@
     pushCx();
     next();
     var propIndent = curIndent, line = curLineStart;
-    while (!closesBlock(tt.braceR, propIndent, line)) {
+    while (!closes(tt.braceR, propIndent, line)) {
       var name = parsePropertyName();
       if (!name) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; }
       var prop = {key: name}, isGetSet = false, kind;
@@ -755,12 +755,12 @@
   }
 
   function parseExprList(close) {
-    var indent = curIndent, line = curLineStart, elts = [];
+    var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart;
     next(); // Opening bracket
-    while (!closesBlock(close, indent, line)) {
+    while (!closes(close, indent + (curLineStart <= continuedLine ? 1 : 0), line)) {
       var elt = parseExpression(true);
       if (isDummy(elt)) {
-        if (closesBlock(close, indent, line)) break;
+        if (closes(close, indent, line)) break;
         next();
       } else {
         elts.push(elt);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list