esprima
esprima copied to clipboard
Missing Spreadoperator compliance in dict
Running a dict containing a Spreadoperator gives an error:
babel/parser.parse() on this : const a = {'a':'b','b':'b','c':'c'}; const b = {'z':'z'}; const y = {...a,...b};
gives Following error:
Error: Line 3: Unexpected token ... at ErrorHandler.constructError (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:5012:22) at ErrorHandler.createError (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:5028:27) at Parser.unexpectedTokenError (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:1985:39) at Parser.throwUnexpectedToken (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:1995:21) at Parser.parseObjectPropertyKey (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:2499:33) at Parser.parseObjectProperty (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:2534:25) at Parser.parseObjectInitializer (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:2602:35) at Parser.inheritCoverGrammar (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:2285:37) at Parser.parsePrimaryExpression (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:2354:38) at Parser.inheritCoverGrammar (/Users/anton/Documents/firebase/NodeJs/node_modules/.pnpm/[email protected]/node_modules/esprima/dist/esprima.js:2285:37) { index: 69, lineNumber: 3, description: 'Unexpected token ...' }
I am getting the same error. Is this library still being maintained at all?
@mmiscool try here https://github.com/node-projects/esprima-next
I´m using acorn now
import * as acorn_walk from 'acorn-walk'; import { ancestor } from 'acorn-walk'; function findNodeByValue(ast, value) { let path = []; let callback = function(){} let functionBase = {...acorn_walk.base}; functionBase.Literal = function(node,_state,ancestor){ count++; if (node.value==value) { path.push({"node":node,"ancestor":ancestor}) } } acorn_walk.fullAncestor(ast,function(a,b,c){},functionBase );//node, callback, baseVisitor, state, override
return path;
} ast = acorn.parse(strings,{ // parse in strict mode and allow module declarations sourceType: "script", ecmaVersion : 12,
plugins: [ // enable jsx and flow syntax "jsx", "flow", ], })
@mmiscool try here https://github.com/node-projects/esprima-next
This package worked perfectly for me. Thanks for pointing it out.