简体   繁体   English

为什么 esprima 在在线浏览器演示中运行良好,但在本地失败

[英]why esprima works fine in online browser demo, but failed locally

When I try to parse a snippet of code with the following script, it failed (using esprima@4.0.1).当我尝试使用以下脚本解析一段代码时,它失败了(使用 esprima@4.0.1)。 However it works fine in the esprima online browser demo, shown in the screenshot below.然而,它在 esprima 在线浏览器演示中运行良好,如下面的屏幕截图所示。

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, () => {});

在此处输入图像描述

The output error message is as follows: output错误信息如下:

/usr/lib/nodejs/esprima/dist/error-handler.js:17
            throw error;
            ^
Error: Line 1: Unexpected token
    at ErrorHandler.constructError (/usr/lib/nodejs/esprima/dist/error-handler.js:21:21)
    at ErrorHandler.createError (/usr/lib/nodejs/esprima/dist/error-handler.js:37:26)
    at Parser.unexpectedTokenError (/usr/lib/nodejs/esprima/dist/parser.js:162:38)
    at Parser.tolerateUnexpectedToken (/usr/lib/nodejs/esprima/dist/parser.js:175:41)
    at Parser.parseStatementListItem (/usr/lib/nodejs/esprima/dist/parser.js:1542:30)
    at Parser.parseScript (/usr/lib/nodejs/esprima/dist/parser.js:2900:28)
    at parse (/usr/lib/nodejs/esprima/dist/esprima.js:63:60)
    at Object.parseScript (/usr/lib/nodejs/esprima/dist/esprima.js:86:12)
    at Object.<anonymous> (/home/bob/Desktop/js_ast/esprima-ast-visitor-1.0.0/ast_gen.js:6:37)
    at Module._compile (internal/modules/cjs/loader.js:778:30)

I solved my problem by changing esprima.parseScript to esprima.parseModule我通过将 esprima.parseScript 更改为 esprima.parseModule 解决了我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在本地工作,但不在线 - Works locally but not online 我的JavaScript代码无法在本地运行,但可以在jsfiddle上正常工作,为什么? - My JavaScript code is not working locally, but works fine on jsfiddle, why? 为什么 javascript 在 RN webview 中不起作用,但桌面浏览器工作正常? - Why does javascript not work in RN webview but desktop browser works fine? PNG的在线AlphaImageLoader修复程序,但本地不修复 - AlphaImageLoader fix for PNG's works online but not locally 为什么我的 Post Request 在部署到 Google 的 GAE 时失败,但在本地运行良好? - Why does my Post Request fail when deployed on Google's GAE, but works fine locally? 为什么我的 function 在我的本地主机中无法正常运行,但在在线 web 编辑器中运行良好? - Why is my function not running properly in my local host but works perfectly fine in an online web editor? jQuery在Drupal平台上不起作用,但在本地运行良好 - Jquery not working on Drupal platform but works fine locally 模态不适用于heroku; 但在本地工作正常 - modal not working on heroku; but works fine locally 脚本可以在浏览器控制台中正常运行,但不能在线运行 - Script runs fine in the browser console, but not online 模式选择Java脚本为什么不能在chrome的Mozilla浏览器中正常工作? - Pattern selection Java Script Why Does it not work in Mozilla browser in chrome it just works fine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM