`regexpp` is a JavaScript library engineered for parsing and validating ECMAScript regular expressions, generating a detailed Abstract Syntax Tree (AST) that precisely reflects the regex's structure. The current stable version, 3.2.0, actively tracks and incorporates the latest updates from the ECMAScript specification, supporting features up to ES2022, such as new Unicode property escapes and the 'd' flag. Its release cadence is primarily tied to ECMAScript standard updates and Node.js LTS cycles, with minor versions typically introducing new specification features and major versions often signifying breaking changes like Node.js version deprecations or significant AST structure adjustments. Key differentiators include strict adherence to ECMAScript syntax, robust validation capabilities, and a comprehensive visitor pattern for AST traversal, making it an indispensable tool for linters, static analysis utilities, and code transformation projects.
npm install regexppVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing regular expression literals and patterns, specifying ECMAScript versions, and traversing the generated AST using the visitor pattern to identify specific node types, along with basic validation.
Upgrade your Node.js runtime to version 8.x or a later LTS release.
If your regex is valid in an older ES version (e.g., ES2019), explicitly set the `ecmaVersion` option when initializing `RegExpParser` or `RegExpValidator`: `new RegExpParser({ ecmaVersion: 2019 }).parseLiteral(...)`.Review and update any existing code that directly processes or traverses the AST to reflect the new node types and property names (e.g., use `alternatives` instead of `elements`).
Ensure your regular expression patterns do not end with an unescaped backslash. If a literal backslash is intended at the end, it must be escaped (e.g., `\\`).
Verify the JavaScript engine version (Node.js, browser) where your regexes will run to confirm compatibility with ES2021/ES2022 regular expression features.
For CommonJS, try `const { parseRegExpLiteral } = require('regexpp');`. For ESM, ensure you use `import { ... } from 'regexpp';` and that your Node.js environment is configured for ESM (e.g., Node.js >=12, or appropriate `package.json` `"type": "module"`). Ensure TypeScript `moduleResolution` is set correctly (e.g., `"node16"` or `"bundler"`).Correct the regular expression syntax (e.g., change `[b-a]` to `[a-b]`). If the regex is valid in an older ECMAScript version, explicitly set the `ecmaVersion` option in the parser or validator options (e.g., `new RegExpParser({ ecmaVersion: 2018 })`).Update your code to use the `alternatives` property instead of `elements` when traversing `Pattern`, `Group`, `CapturingGroup`, and `Assertion` nodes in the AST.
No dependency data recorded yet.