[Pkg-javascript-commits] [node-acorn-jsx] 181/484: [loose parser] Fix interpretation of `f."`

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:23 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 2de16b8cb0bec3eeb57881581f2a7dc43f5e2e2e
Author: Conrad Irwin <conrad.irwin at gmail.com>
Date:   Thu Apr 17 12:16:29 2014 -0700

    [loose parser] Fix interpretation of `f."`
    
    Before this the ast produced by parse_dammit crashed in the following
    code, as Uglify correctly noticed that f."" is invalid.
    
        sample = 'f."';
    
        loose = require('acorn/acorn_loose');
        uglify = require('uglify-js');
    
        out = new uglify.OutputStream();
        ast = loose.parse_dammit(sample);
        ast = uglify.AST_Node.from_mozilla_ast(ast);
        ast.print(out);
        // TypeError: Cannot call method 'toString' of undefined
        // member_exp.computed = false && member_exp.property == ""
    
        console.log(out.toString());
    
    After this the round-tripped AST looks like: `t.✖;"";`, which is
    consistent with how `foo.{` is parsed.
    
    I also considered making it parse as t[""], but as this only turns up in
    the wild when people try to use multiline strings, I felt it was better
    to be obviously wrong.
---
 acorn_loose.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/acorn_loose.js b/acorn_loose.js
index 1c6fb46..b7bc56d 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -606,7 +606,7 @@
         if (curLineStart != line && curIndent <= startIndent && tokenStartsLine())
           node.property = dummyIdent();
         else
-          node.property = parsePropertyName() || dummyIdent();
+          node.property = parsePropertyAccessor() || dummyIdent();
         node.computed = false;
         base = finishNode(node, "MemberExpression");
       } else if (token.type == tt.bracketL) {
@@ -735,6 +735,10 @@
     if (token.type === tt.name || token.type.keyword) return parseIdent();
   }
 
+  function parsePropertyAccessor() {
+    if (token.type === tt.name || token.type.keyword) return parseIdent();
+  }
+
   function parseIdent() {
     var node = startNode();
     node.name = token.type === tt.name ? token.value : token.type.keyword;

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