[Pkg-javascript-commits] [node-acorn-jsx] 94/484: Fix bug in expression-terminating heuristic

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:09 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 82980794a995ae0e25fa4e03228fa0ecf12bf734
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Tue Feb 5 13:49:51 2013 +0100

    Fix bug in expression-terminating heuristic
    
    Dedented tokens should only end an expression if they are actually the first
    token on the line.
    
    This to prevent code like this from going wrong:
    
        x = (function(..) {
          blah();
        })(); // <-- indented same as start of expression
---
 acorn_loose.js | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index bcbd1ff..94eb76d 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -160,12 +160,20 @@
 
   function closesBlock(closeTok, indent, line) {
     if (token.type === closeTok || token.type === tt.eof) return true;
-    if (line != curLineStart && curIndent < indent &&
+    if (line != curLineStart && curIndent < indent && tokenStartsLine() &&
         (nextLineStart >= input.length ||
          indentationAfter(nextLineStart) < indent)) return true;
     return false;
   }
 
+  function tokenStartsLine() {
+    for (var p = token.start - 1; p > curLineStart; --p) {
+      var ch = input.charCodeAt(p);
+      if (ch !== 9 && ch !== 32) return false;
+    }
+    return true;
+  }
+
   function node_t(start) {
     this.type = null;
     this.start = start;
@@ -483,7 +491,7 @@
   }
 
   function parseExprOp(left, minPrec, noIn, indent, line) {
-    if (curLineStart != line && curIndent < indent) return left;
+    if (curLineStart != line && curIndent < indent && tokenStartsLine()) return left;
     var prec = token.type.binop;
     if (prec != null && (!noIn || token.type !== tt.in)) {
       if (prec > minPrec) {
@@ -491,7 +499,7 @@
         node.left = left;
         node.operator = token.value;
         next();
-        if (curLineStart != line && curIndent < indent)
+        if (curLineStart != line && curIndent < indent && tokenStartsLine())
           node.right = dummyIdent();
         else
           node.right = parseExprOp(parseMaybeUnary(noIn), prec, noIn, indent, line);
@@ -531,7 +539,7 @@
 
   function parseSubscripts(base, noCalls, startIndent, line) {
     for (;;) {
-      if (curLineStart != line && curIndent <= startIndent) {
+      if (curLineStart != line && curIndent <= startIndent && tokenStartsLine()) {
         if (token.type == tt.dot && curIndent == startIndent)
           --startIndent;
         else
@@ -541,7 +549,7 @@
       if (eat(tt.dot)) {
         var node = startNodeFrom(base);
         node.object = base;
-        if (curLineStart != line && curIndent <= startIndent)
+        if (curLineStart != line && curIndent <= startIndent && tokenStartsLine())
           node.property = dummyIdent();
         else
           node.property = parsePropertyName() || dummyIdent();

-- 
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