Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@lezer/javascript
Advanced tools
@lezer/javascript is a parser for JavaScript written using the Lezer parser system. It provides a way to parse JavaScript code into a syntax tree, which can be used for various purposes such as syntax highlighting, code analysis, and transformation.
Parsing JavaScript Code
This feature allows you to parse JavaScript code into a syntax tree. The code sample demonstrates how to parse a simple JavaScript statement and print the resulting syntax tree.
const {parser} = require('@lezer/javascript');
const input = 'const x = 10;';
const tree = parser.parse(input);
console.log(tree.toString());
Syntax Tree Traversal
This feature allows you to traverse the syntax tree. The code sample shows how to use a TreeCursor to iterate over the nodes in the syntax tree and print their types.
const {parser} = require('@lezer/javascript');
const {TreeCursor} = require('@lezer/common');
const input = 'const x = 10;';
const tree = parser.parse(input);
let cursor = tree.cursor();
do {
console.log(cursor.node.type.name);
} while (cursor.next());
Custom Syntax Highlighting
This feature allows you to apply custom syntax highlighting to JavaScript code. The code sample demonstrates how to define a highlighting style and apply it to a parsed syntax tree.
const {parser} = require('@lezer/javascript');
const {highlightTree} = require('@lezer/highlight');
const {styleTags, tags} = require('@lezer/highlight');
const input = 'const x = 10;';
const tree = parser.parse(input);
const highlightStyle = styleTags({
'VariableName': tags.variableName,
'Keyword': tags.keyword,
'Number': tags.number
});
let highlighted = '';
highlightTree(tree, highlightStyle, (from, to, classes) => {
highlighted += input.slice(from, to) + ' [' + classes + '] ';
});
console.log(highlighted);
Acorn is a small, fast, JavaScript-based JavaScript parser. It is designed to be modular and can be extended with plugins. Compared to @lezer/javascript, Acorn is more widely used and has a larger community, but it may not integrate as seamlessly with the Lezer ecosystem.
Esprima is a high-performance, standard-compliant ECMAScript parser written in JavaScript. It is known for its speed and accuracy. While Esprima is similar to @lezer/javascript in terms of functionality, it is more mature and has been used in many production environments.
This is a JavaScript grammar for the lezer parser system.
It parses ES2020, and supports a "ts"
dialect to parse
TypeScript, and a "jsx"
dialect to parse JSX.
The code is licensed under an MIT license.
0.15.3 (2022-01-26)
Support missing values in array pattern syntax.
Support quoted module export names.
Template string interpolations now get their own nodes in the syntax tree.
FAQs
lezer-based JavaScript grammar
The npm package @lezer/javascript receives a total of 581,111 weekly downloads. As such, @lezer/javascript popularity was classified as popular.
We found that @lezer/javascript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.