jquery / esprima

ECMAScript parsing infrastructure for multipurpose analysis
http://esprima.org
BSD 2-Clause "Simplified" License
7.04k stars 786 forks source link

esprima works fine in online browser demo, but failed locally #2064

Closed unclebob7 closed 3 years ago

unclebob7 commented 3 years ago

Steps to reproduce

When I try to parse a snippet of code with the following script, it failed. However it works fine in the esprima online browser demo, shown in the screenshot below.

var esprima = require('esprima');
var fs = require('fs');

const raw_string = String.raw`export { AppCache , addOrReplaceCacheableGroup , findCacheableGroup , CacheTimeoutData } from 's' ; export { AppCacheAction , AppCacheActionType , CacheGroupAction , AddToCacheAction } from 's' ; export { cacheGroup , addToCache } from 's' ; export { appCacheReducer } from 's' ;`;

ast_string = JSON.stringify(esprima.parseScript(raw_string, { range: true }), null, 2);
fs.writeFile('./ast_data/test.json', ast_string, () => {});

image

Actual output

The error msg is as follows: image

Relevant references