{"id":16270,"library":"vscode-regexpp","title":"ECMAScript Regular Expression Parser","description":"`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.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/mysticatea/regexpp","tags":["javascript","regexp","regular","expression","parser","validator","ast","abstract","syntax"],"install":[{"cmd":"npm install vscode-regexpp","lang":"bash","label":"npm"},{"cmd":"yarn add vscode-regexpp","lang":"bash","label":"yarn"},{"cmd":"pnpm add vscode-regexpp","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses ES Modules. For CommonJS, bundlers like Webpack or Rollup are recommended, or use dynamic import.","wrong":"const { parseRegExpLiteral } = require('regexpp')","symbol":"parseRegExpLiteral","correct":"import { parseRegExpLiteral } from 'regexpp'"},{"note":"This is a named export, not a default export.","wrong":"import RegExpParser from 'regexpp'","symbol":"RegExpParser","correct":"import { RegExpParser } from 'regexpp'"},{"note":"Import the `AST` namespace as a type for robust type-checking when working with parsed nodes.","symbol":"AST","correct":"import type { AST } from 'regexpp'"},{"note":"ES Modules are the standard import mechanism for this library.","wrong":"const visitRegExpAST = require('regexpp').visitRegExpAST","symbol":"visitRegExpAST","correct":"import { visitRegExpAST } from 'regexpp'"}],"quickstart":{"code":"import { parseRegExpLiteral, visitRegExpAST, RegExpValidator } from 'regexpp';\n\nconst regexSource = '/^(hello|world)\\s+\\d{4}$/ui';\n\ntry {\n  // Parse the regular expression literal\n  const ast = parseRegExpLiteral(regexSource, { ecmaVersion: 2021 });\n  console.log('Successfully parsed regex:', regexSource);\n  console.log('Pattern body:', ast.pattern.raw);\n  console.log('Flags:', ast.flags.raw);\n\n  // Validate the regular expression\n  const validator = new RegExpValidator({ ecmaVersion: 2021 });\n  validator.validateLiteral(regexSource);\n  console.log('Successfully validated regex:', regexSource);\n\n  // Visit the AST nodes\n  console.log('\\nTraversing AST:');\n  visitRegExpAST(ast, {\n    onPatternEnter(node) { console.log(`  Entering Pattern: ${node.raw}`); },\n    onGroupEnter(node) { console.log(`  Entering Group: ${node.raw}`); },\n    onCharacterEnter(node) { console.log(`  Entering Character: ${node.raw}`); },\n    onQuantifierEnter(node) { console.log(`  Entering Quantifier: ${node.raw}`); }\n  });\n\n} catch (error) {\n  console.error('Error processing regex:', error.message);\n}","lang":"typescript","description":"Demonstrates parsing a regular expression literal, validating it, and then traversing its Abstract Syntax Tree (AST) using the visitor pattern."},"warnings":[{"fix":"Upgrade Node.js to version 8 or newer.","message":"Node.js 6.x is no longer supported; the minimum required Node.js version is now 8.x.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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`).","message":"The 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`.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"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.","message":"Regular 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.","severity":"gotcha","affected_versions":">=2.0.1"},{"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.","message":"Unicode 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.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"The input string contains a syntax error in the regular expression or is not compatible with the configured `ecmaVersion`.","error":"Parsing error: Invalid regular expression pattern."},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'alternatives')"},{"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`.","cause":"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.","error":"ReferenceError: require is not defined"},{"fix":"Upgrade Node.js to version 8 or newer to meet the minimum engine requirements for `regexpp` v3.x.","cause":"Running `regexpp` v3.0.0+ on an unsupported Node.js version (specifically, older than 8.x).","error":"Error: Node.js v6.x is no longer supported"}],"ecosystem":"npm"}