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
2
votes
0 answers

Refactor Javascript objects and properties

I have some code I may want to refactor many times. Imagine, something like this: Namespace.CustomObject = function(name,type){ this.name = name; this.type = type; }; Namespace.CustomObject.prototype = { writeName: function(){ …
2
votes
0 answers

Programmatically insert a line in a JS file

I want to write a program that will add a line to JS within an existing HTML file. I thought I would use node.js as it's the same language. I have looked at a number of projects, esprima, acorn, rocambole, falafel, escodegen etc. but I can't seem to…
Stev_k
  • 2,118
  • 3
  • 22
  • 36
2
votes
1 answer

Developing a parser in JavaScript(Esprima.JS) that parses Haskell Language in Mozilla AST format

Currently i am working on developing a parser in JavaScript that parses Haskell Language.I am studying Esprima.JS and will like to build on top of it that will parse Haskell Language.As per my understanding i need to start with a basic parts such…
Sant14
  • 302
  • 1
  • 13
1
vote
1 answer

Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition

I'm receiving this error: Uncaught TypeError: Cannot set property 'esprima' of undefined at webpackUniversalModuleDefinition (esprima.js:11) at esprima.js:12 When trying to load a web app: The error happens here: (function…
Megidd
  • 7,089
  • 6
  • 65
  • 142
1
vote
1 answer

Esprima error 404 Not Found in npm install

I'm trying to install all dependencies in my react project, but when I run npm install I'm getting some errors related to esprima: npm ERR! 404 Not Found - GET https://codeload.github.com/ariya/esprima/legacy.tar.gz/master npm ERR! npm ERR! 404 npm…
Caíque de Paula
  • 424
  • 5
  • 17
1
vote
0 answers

How to generate all the leaf to leaf path in an AST?

Given a JS snippet, how to generate all the leaf-to-leaf path from the AST? Let’s say the code snippet is: var answer = 6 * 7; Example AST: https://esprima.org/demo/parse.html For this code snippet, I have to generate all the paths from leaf to…
Exploring
  • 2,493
  • 11
  • 56
  • 97
1
vote
0 answers

How to add a custom operator to Javascript or node.js with BabelJS?

I would like to add custom operators, keywords, and syntax to Javascript. Someone asked for help with this many years ago and got some great instructions: How would I extend the JavaScript language to support a new operator? Implemented…
abalter
  • 9,663
  • 17
  • 90
  • 145
1
vote
0 answers

extracting specific function calls from javascript

I want to extract function calls from javascript files. For example: ........... ........... ........... function moveEvent(event, dayDelta, minuteDelta, allDay){ jQuery.ajax({ data: 'id=' + event.id + '&title=' + event.title +…
Exploring
  • 2,493
  • 11
  • 56
  • 97
1
vote
1 answer

How to insert one node into an abstract syntax tree by javascript (esprima)

there is a question about esprima and inserting an ast node. I try to generate one ast node to replace other node with new node , (node = newNode) , but It does't work. estraverse.traverse(tree, { enter(node, parent) { try { if (node.type…
DeeLMind
  • 31
  • 3
1
vote
1 answer

Await not parsed in esprima 4.0.1

Can't get the esprima 4.0.1 parser to work with 'await'. Having difficult times to find the relevant options that can be passed into the parse function for 'await', if that is possible. Steps to reproduce const esprima =…
Stan Wiechers
  • 1,962
  • 27
  • 45
1
vote
2 answers

What's the safest way to allow JavaScript written on the client, to be executed on the server?

I would like to allow our users to write string parsing logic in JavaScript, that would then be executed on the server. Edit (more info): Regex is not an option as they will need if, else, switch etc I would like to avoid creating a custom…
John Doherty
  • 3,669
  • 36
  • 38
1
vote
1 answer

Unable to parse function with Esprima/Acorn: unexpected token '('

I am able to parse arrow functions using Esprima and Acorn, but using normal functions gives an error: const esprima = require('esprima'); const acorn = require('acorn'); console.log(esprima.parseScript(` () => { console.log('Test')}`));…
amp
  • 109
  • 1
  • 1
  • 9
1
vote
3 answers

How to use acorn.js or similar library to add a new node to the ast tree?

I was trying to use acorn.js along with yeoman to add code to existing js files .I have tried to work with esprima and acorn to do this job but I cannot find any documentation about adding node to the AST.
Xiaofeng Xie
  • 145
  • 9
1
vote
1 answer

How can I add a new semantics on esprima parser?

I want to use esprima parser to parse mongo shell scripts. Basically mongo shell is using javascript syntax but with some additional commands. For example, use test is one statement on mongo shell to switch to the test database. If I put this string…
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
1
vote
2 answers

Error generating code with escodegen after node removal

First I created an esprima AST, then I want to remove a node using estraverse and finally regenerate the code with escodegen. But I get an error. The code I'm trying is: var esprima = require('esprima'); var estraverse = require('estraverse'); var…
fonkap
  • 2,469
  • 1
  • 14
  • 30