Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Cherow is a very fast, standard-compliant ECMAScript parser written in ECMAScript.
It strictly follows the ECMAScript® 2018 Language Specification and should parse acc. these specifications
It's safe to use in production even I'm not done with this parser. I'm finishing the parser in the dev branch.
Stage 3
features support. This need to be enabled with the next
option
DotAll
flagnext
- Enables ECMAScript Next
support and let you use proposals at stage 3
or higher such as Dynamic Import
.directives
- Enables support for directive nodesraw
- Enables the raw property on literal nodes (Esprima and Acorn feature)comments
- Enables option to collect comments. Optional; Either array or function. Works like Acorn onComment.tokens
- If enabled each found token will be returned as either an function or an array (work in progres)ranges
- Enables the start and characters offsets on the AST node.locations
- Enables location tracking. (4 min fix, but on hold for now)jsx
- Enables JSXCherow can be used to perform syntactic analysis of Javascript program, or lexical analysis (tokenization).
// Parsing script
cherow.parseScript('const fooBar = 123;');
// Parsing module code
cherow.parseModule('const fooBar = 123;');
// Parsing script
cherow.parseScript('const fooBar = 123;', { ranges: true, raw: true, next: true});
Collecting comments works just the same way as for Acorn
// Function
cherow.parseScript('// foo',
{
comments: function(type, comment, start, end) {}
}
);
// Array
const commentArray = [];
cherow.parseScript('// foo',
{
comments: commentArray
}
);
If you prefer Acorn, you can use some of the options to let Cherow parse and give you the same output as you would do with Acorn. Same for Esprima.
Here is how you do it:
Acorn
cherow.parseScript('{ a: b}', { raw: true, ranges: true });
Esprima
cherow.parseScript('{ a: b}', { raw: true, directives: true });
See the benchmarks here
Cherow outputs a sensible syntax tree format as standardized by ESTree project, and does not add any "extra" properties to any of it's node like Esprima.
However. There is a small difference from other parsers because Cherow outputs a await
property on the ForStatement
node.
This because of the support of For Await
and Async Generators
.
You are welcome to contribute. As a golden rule - always run benchmarks to verify that you haven't created any bottlenecks or did something that you shouldn't.
Terms of contribution:
FAQs
Fast and lightweight, standard-compliant javascript parser written in ECMAScript
The npm package cherow receives a total of 9,429 weekly downloads. As such, cherow popularity was classified as popular.
We found that cherow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.