Questions tagged [esprima]

Esprima is a high performance, standard-compliant JavaScript parser written in JavaScript.

Distributed under the BSD licence, Esprima features full support for JavaScript 5.1 and will run on many browsers and other JavaScript platforms such as Rhino and Node.js.

73 questions
101
votes
4 answers

How to use npm module in DENO?

Deno is super cool. I saw it in the morning and want to migrate to deno now. I was trying to move my existing nodejs script to deno. Can any one help me on how to use npm modules in deno. I need esprima module. This one has the package…
Vinod Sai
  • 1,956
  • 3
  • 13
  • 23
13
votes
1 answer

TypeScript -> AST -> TypeScript

Is there a way to parse a TypeScript file to an AST, modify the AST, and parse it then back to TypeScript as the tools Esprima + Escodegen are able to? Important is that I do NOT want to compile/transpile the TypeScript code first into JavaScript.
cape
  • 171
  • 1
  • 9
12
votes
2 answers

How can I transform a custom AST into JS code

I am currently generating a custom AST from a new language specification I have designed. This custom AST contains different nodes that I have designed with all the information I need in order to now generate JavaScript code. For example: Say I have…
11
votes
2 answers

How to identify the following code patterns

I have a pattern of js promises that I want to identify for several keywords For example if I put code like: var deferred = Q.defer(); And in the file I have also the following respective value deferred.reject(err); deferred.resolve(); return…
user4445419
11
votes
1 answer

ES6 Module export default syntax

I'm using the es6-module-transpiler, esprima and JSHint with esnext: true options. JSHint complains when I put: export default = { some: 'thing', other: 'thing' }; But esprima complains when I use export default { some: 'thing', other: 'thing'…
Jacob
  • 3,629
  • 3
  • 36
  • 44
6
votes
1 answer

Failed to Parse error : Unexpected token on "import" with Istanbul

I am using Istanbul for code coverage of Protractor Tests. In the process of Instrumenting the source Code I am getting a "Failed to parse, Unexpected Token" error, and after going through the error it is found that the "import" token is creating…
DK818
  • 135
  • 6
5
votes
1 answer

Why does escodegen and esprima generate a parenthesis wrapper on my source code?

I am using escodegen to add an ending code on my statement as below. In the leave method, I append a .toArray() call on the end of the statement. const esprima = require('esprima'); const estraverse = require('estraverse'); const escodegen =…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
4
votes
1 answer

How to generate a JavaScript sourcemap based on an AST transform?

Suppose I AST transform the content of a JavaScript file from state A to state B. How might I make an accompanying sourcemap? I'm using esprima and estravese (estraverse.replace) to traverse an AST (I have the sourcemap corresponding to the initial…
trusktr
  • 44,284
  • 53
  • 191
  • 263
3
votes
1 answer

how to use estraverse js library on client-side?

I was able to get estraverse via npm and get it work on a node app. But when when i tried to install it via bower for client side usage, the install failed saying "optionator package is not found". And when i tried to load the js file directly, it…
3
votes
0 answers

What characters can be operators in JavaScript using Esprima?

From the previous question I learned how to extend JavaScript language to support more operators (created by me). There @Benjamin used Esprima and created # operator. Using Esprima we can do the following: esprima.parse("10 # 2") That returns this…
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
3
votes
2 answers

Cannot find module 'esprima'

I'm trying to develop an Abstract Syntax Tree program in JavaScript. I'm using Jet brains IDE for development. When I run the program, i get the error Cannot find module esprima. The nodejs settings are perfect and, I don't think there is any…
user2464884
2
votes
1 answer

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). However it works fine in the esprima online browser demo, shown in the screenshot below. var esprima = require('esprima'); var fs =…
Bob Li
  • 43
  • 5
2
votes
1 answer

Infinite loop protection

I'm working on JavaScript code editor where users can write their own JavaScript code in the browser and run it. I need to find a way to break out of infinite loops. When I am given the code: while (1) { doSomething(); } I want to transform the…
summerjacket
  • 31
  • 1
  • 7
2
votes
1 answer

EOENT esprima esparse Windows symlinks invalid directory file not found

I'm taking over an outdated electron-webpack + react app, and my build is always getting this error: Cannot read file C:\Users\baz\Desktop\foo-bar-app\node_modules\esprima\.bin\esparse: Error: ENOENT: no such file or directory, open…
Novaterata
  • 4,356
  • 3
  • 29
  • 51
2
votes
0 answers

Sources and sinks of firefox os application

I am developing a tool for Firefox OS application analysis. The tool uses static code analysis for source and sink identification. Then dynamic analysis to taint data from source to sink. I used Esprima to parse the JavaScript code and used the…
Shahanas
  • 71
  • 7
1
2 3 4 5