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
1
vote
1 answer

Extend Javascript Syntax to Add Typing

I'd like to extend javascript to add custom type checking. e.g. function test(welcome:string, num:integer:non-zero) { console.log(welcome + num) } which would compile into: function test(welcome, num) { …
Tony J Watson
  • 629
  • 2
  • 9
  • 20
1
vote
0 answers

Turn multiple calls into one call chain

I'm making a library which exports one function (make) on global namespace (app) for defining a module or referencing it, similar to what angular.module does. When I call it, I make sure to not store any reference to the make(name, [deps]) call so…
1
vote
0 answers

escodegen's verbatim option

I'm stumped by the escodegen verbatim option. It claims that the value of options.verbatim should be a string which is taken to be a property name which, if present on any expression node (using type="Literal" in my tests) the value of that property…
1
vote
1 answer

`esprima` AST Tree: How to easily detect and add function parens?

TL;DR: i want to do same thing as there https://github.com/nolanlawson/optimize-js but with esprima when i traverse through AST tree with estraverse. ESPrima gives same output nodes for following code: !function (){}() and !(function…
1
vote
0 answers

Unexpected token ILLEGAL in reactjs - jest eventhough component renders correctly

I was trying to do unit testing for a react component. But when I tried to render it using TestUtils.renderIntoDocument() method jest throws an error Error: Line 1: Unexpected token ILLEGAL at constructError…
P-RAD
  • 1,293
  • 2
  • 15
  • 36
1
vote
1 answer

How it works that Javascript parser is itself written in javascript like ESPRIMA ? Then who parses the javascript of ESPRIMA

What i understand is that "In computer technology, a parser is a program, usually part of a compiler, that receives input in the form of sequential source program instructions, interactive online commands, markup tags, or some other defined…
1
vote
1 answer

How to find a JavaScript variable's transitive usage through function calls?

Suppose I have access to the full set of source that could potentially be using a JavaScript variable foo. Some of the source code looks like this: foo.bar = 'baz'; (function(a, b, c) { a(); b.bar = 'whee'; c(); }(fn, foo, fn)); Are…
Chris
  • 9,994
  • 3
  • 29
  • 31
1
vote
1 answer

Need regex to accomplish basic recursive feature of language parsers (or help making Babel plugin)

I have the following regex: /(?:this\.(\w+)\(([\s\S]*?)\))/g it is used to take code like this: this.doSomething(foo, bar) and replace it with: this.lookup('doSomething', [foo, bar]) for that use use case (which is the most common) it works…
faceyspacey.com
  • 2,510
  • 2
  • 20
  • 29
1
vote
0 answers

Detecting native API calls in javascript for Object

I am trying to build an analysis program for static analysis on the java script file provided to the program using esprima and estraverse. I want to make out and differentiate between the local functions defined by user and calls to the native…
1
vote
0 answers

Best way to find a expression in esprima

I need to check a code and find if there's the use of timer expressions in a esprima tree. Do you know the best way to do this? thanks
R01010010
  • 5,670
  • 11
  • 47
  • 77
1
vote
0 answers

Merge js files regardless formatting. ex. merging esprima ast's

Do you know any tool for merging a js file into an other but keep the formatting? ex., merge x({a: 5, b: 6}); into x({ a: 1, b: 2, }); and the resoult would be x({ a: 5, b: 6, }); instead of merging conflict I think a tool which can…
mantramantramantra
  • 663
  • 1
  • 5
  • 8
1
vote
1 answer

Trouble installing js-yaml NPM package dependancies on Ubuntu 64 bits

I am trying to get my own project written on OSX to build on Ubuntu. It uses several npm packages to build itself. A few of them depend on the npm package js-yaml, which in it's turn depends on a package called 'esprima'. A fresh Ubuntu 14.04…
Michahell
  • 4,905
  • 5
  • 29
  • 45
0
votes
1 answer

How can I know when the scope changes within an abstract syntax tree?

Can someone help me with figuring out how to know when the scope changing while traversing the ast tree? I am using the esprima parser and I know that babel does this but I want to create my own to understand how it works and help increase my…
jjboi8708
  • 65
  • 1
  • 7
0
votes
0 answers

How to format source in code playground to show proper line numbers?

I'm working on Code playground and I have loops protection inspired by CodePen. When I have code like this: function draw() { for (let i = 0; i < 1; ++i) { console.log(x()); } } it's transformed into: function draw() { for (let…
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
0 answers

The output from Esprima.parse() is incomplete

When I used the Esprima function in javascript to build the AST tree, the output was different from Esprima, not showing the full details of the online site This is my code below ` var esprima = require("esprima") script = "answer = 42" var…