npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ecma-parser

v0.0.3

Published

Ecmascript Parser

Downloads

12

Readme

Ecmascript Parser

Ecmascript instruction parser. Tested on popular Javascript modules (i.e. JQuery)

How it works

  • Download JXcore
  • type jx install ecma-parser or npm install ecma-parser

Sample Code:

var parser = require('ecma-parser');

var js_code = "\
  var x = 1;\
  var y = 2;\
  console.log(x + y);\
";

var bl = parser.parse("test.js", js_code);
parser.printBlocks(bl);

Output:

---> ROOT { x: {}, y: {} }
SPACE (1:1)
SET_VARIABLE 1:3
SPACE (1:6)
WORD: x (new_variable) (1:7)
SPACE (1:8)
EQUALS (1:9)
SPACE (1:10)
WORD: 1 (number) (1:11)
SEMI_COLON (1:12)
SPACE (1:13)
SET_VARIABLE 1:15
SPACE (1:18)
WORD: y (new_variable) (1:19)
SPACE (1:20)
EQUALS (1:21)
SPACE (1:22)
WORD: 2 (number) (1:23)
SEMI_COLON (1:24)
SPACE (1:25)
WORD: console (1:27)
DOT (1:34)
WORD: log (1:35)
PTS_OPEN (1:38)
WORD: x (1:39)
SPACE (1:40)
PLUS (1:41)
SPACE (1:42)
WORD: y (1:43)
PTS_CLOSE (1:44)
SEMI_COLON (1:45)

API

.parse (string filename, string source_code)

Parse Javascript code and return instruction blocks

.printBlocks (blocks)

Print instruction blocks on console

.blockToCode (blocks, [optional] filename)

Return source code for the instruction block

Blocks

.variables : Scope variables
.subs : Array of sub instructions or blocks
.type : Instruction type
.index : Instruction start index
.length : Length of instruction
.repeats : If true, delimiter should repeat on output .length times
.delimiter : Instruction identifier
.dataType : Data type of the instruction block
.rowIndex : Row index of the instruction
.columnIndex : Column index of the instruction
.getData() : Get the string data from the instruction (name of the variable for WORDs)
.isNewDefinition() : Is this block represents a new named definition?
.isProperty() : Is this block represents an Object property ?
.updateName(name) : Update the variable name (only for the current instance)
.getPreviousBlock(noskip) : Returns previous instruction block (None space, comment, new line or semi colon)
.getNextBlock(noskip) : Returns previous instruction block (None space, comment, new line or semi colon)

  • set noskip = true to get next or previous block regardless from it's type

Samples

Visit samples folder. i.e Use parse_folder.js under samples folder. (*nix only)

jx samples/parse_folder.js jquery.1.1.min.x.js

License

The MIT License (MIT)

Copyright (c) 2015 Oguz Bastemur

Contribution

This particular project is intended to parse EcmaScript 6 compliant Javascript code. Feel free to contribute under the MIT and intention of this project.