Registry / serialization / vscode-regexpp

vscode-regexpp

JSON →
library3.1.0jsnpmunverified

`regexpp` is a specialized library for parsing and validating ECMAScript regular expressions, generating an Abstract Syntax Tree (AST) that precisely conforms to the ECMAScript specification. It provides robust tools for static analysis of regex patterns, including a parser (`RegExpParser`), a validator (`RegExpValidator`), and a visitor pattern (`RegExpVisitor`) for AST traversal. The current stable version, 3.2.0, actively receives updates to support the latest ECMAScript features and Unicode versions. This package differentiates itself by offering fine-grained control over the parsing process, allowing specification of ECMAScript version targets and Unicode flags, making it invaluable for linters, code transformers, and tools that require a deep, standards-compliant understanding and manipulation of regular expressions. Its release cadence is active, with significant updates roughly yearly for major versions and minor releases as needed to keep pace with spec changes and bug fixes.

npm install vscode-regexpp
INSTALL
IMPORT
SIG · VSCODE-REGEXPP
V
vscode-regexpp
serializationjavascriptv3.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseRegExpLiteral
✓ import { parseRegExpLiteral } from 'regexpp'
✗ const { parseRegExpLiteral } = require('regexpp')
The library primarily uses ES Modules. For CommonJS, bundlers like Webpack or Rollup are recommended, or use dynamic import.
RegExpParser
✓ import { RegExpParser } from 'regexpp'
✗ import RegExpParser from 'regexpp'
This is a named export, not a default export.
AST
✓ import type { AST } from 'regexpp'
Import the `AST` namespace as a type for robust type-checking when working with parsed nodes.
visitRegExpAST
✓ import { visitRegExpAST } from 'regexpp'
✗ const visitRegExpAST = require('regexpp').visitRegExpAST
ES Modules are the standard import mechanism for this library.

Demonstrates parsing a regular expression literal, validating it, and then traversing its Abstract Syntax Tree (AST) using the visitor pattern.

import { parseRegExpLiteral, visitRegExpAST, RegExpValidator } from 'regexpp'; const regexSource = '/^(hello|world)\s+\d{4}$/ui'; try { // Parse the regular expression literal const ast = parseRegExpLiteral(regexSource, { ecmaVersion: 2021 }); console.log('Successfully parsed regex:', regexSource); console.log('Pattern body:', ast.pattern.raw); console.log('Flags:', ast.flags.raw); // Validate the regular expression const validator = new RegExpValidator({ ecmaVersion: 2021 }); validator.validateLiteral(regexSource); console.log('Successfully validated regex:', regexSource); // Visit the AST nodes console.log('\nTraversing AST:'); visitRegExpAST(ast, { onPatternEnter(node) { console.log(` Entering Pattern: ${node.raw}`); }, onGroupEnter(node) { console.log(` Entering Group: ${node.raw}`); }, onCharacterEnter(node) { console.log(` Entering Character: ${node.raw}`); }, onQuantifierEnter(node) { console.log(` Entering Quantifier: ${node.raw}`); } }); } catch (error) { console.error('Error processing regex:', error.message); }
Debug
Known issues
breakingNode.js 6.x is no longer supported; the minimum required Node.js version is now 8.x.
fix
Upgrade Node.js to version 8 or newer.
affects: >=3.0.0
breakingThe default ECMAScript version for parsing and validation changed to ES2020. This might cause previously valid regular expressions to be parsed differently or throw errors if they rely on older ECMAScript semantics without explicit version options.
fix
Explicitly pass `ecmaVersion` in parser/validator options (e.g., `{ ecmaVersion: 2018 }`) if compatibility with older ECMAScript versions is required, or update regex patterns to conform to ES2020.
affects: >=3.0.0
breakingThe Abstract Syntax Tree (AST) shape underwent significant changes. The `Disjunction` node type was removed, an `Alternative` node type was added, and the `elements` property on `Pattern`, `Group`, `CapturingGroup`, and `Assertion` nodes was renamed to `alternatives`.
fix
Update any code that directly traverses or manipulates the AST to reflect the new node types and property names (e.g., use `node.alternatives` instead of `node.elements`).
affects: >=2.0.0 <3.0.0
gotchaRegular expression patterns ending with an unescaped backslash (`\`) are now disallowed to align with ECMAScript spec updates. Such patterns will throw a syntax error during parsing or validation.
fix
Ensure regular expression patterns do not end with an unescaped backslash. Correct the pattern to escape the backslash (`\\`) if it's intended as a literal, or remove it if it's an incomplete escape sequence.
affects: >=2.0.1
gotchaUnicode version updates in various releases (e.g., 2.0.0, 3.0.0, 3.1.0) mean that behavior of Unicode property escapes or character classes might subtly change if existing code relied on very specific, older Unicode versions. Always parse with the `u` flag for proper Unicode handling.
fix
Verify that regular expressions using Unicode features behave as expected after upgrading. Explicitly set `ecmaVersion` and `unicode` (if applicable) in parser options for consistent behavior if precise historical Unicode conformance is critical.
affects: >=2.0.0
Errors
Common errors & fixes
Parsing error: Invalid regular expression pattern.
The input string contains a syntax error in the regular expression or is not compatible with the configured `ecmaVersion`.
fix
Review the regular expression pattern for syntax errors. When using `RegExpParser` or `parseRegExpLiteral`, ensure the `ecmaVersion` option matches the target ECMAScript standard for the regex.
TypeError: Cannot read properties of undefined (reading 'alternatives')
Code is attempting to access AST properties like `elements` or node types like `Disjunction` that were renamed or removed in `regexpp` v2.0.0 or later.
fix
Update AST traversal or manipulation logic to use the new property names (e.g., `alternatives` instead of `elements`) and current node types as defined in `regexpp` v2.0.0 and above.
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax directly in an ES Module context, or an incorrect import path/symbol for `regexpp` which is primarily an ESM library.
fix
Use ES Module `import` syntax (`import { parseRegExpLiteral } from 'regexpp'`) in modern Node.js environments or with a bundler. Ensure your project is configured for ESM by using `.mjs` files or `"type": "module"` in `package.json`.
Error: Node.js v6.x is no longer supported
Running `regexpp` v3.0.0+ on an unsupported Node.js version (specifically, older than 8.x).
fix
Upgrade Node.js to version 8 or newer to meet the minimum engine requirements for `regexpp` v3.x.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vscode-regexpp — npm install vscode-regexpp · libregistry