diff --git a/README.md b/README.md index c8ef5cf..86a4e32 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ function toRegExp( type OnigurumaToEsOptions = { accuracy?: 'strict' | 'default' | 'loose'; avoidSubclass?: boolean; - flags?: OnigurumaFlags; + flags?: string; global?: boolean; hasIndices?: boolean; maxRecursionDepth?: number | null; @@ -111,7 +111,7 @@ Returns an Oniguruma AST generated from an Oniguruma pattern. function toOnigurumaAst( pattern: string, options?: { - flags?: OnigurumaFlags; + flags?: string; } ): OnigurumaAst; ``` diff --git a/scripts/onig-match.js b/scripts/onig-match.js index 7322314..108e6b5 100644 --- a/scripts/onig-match.js +++ b/scripts/onig-match.js @@ -1,5 +1,10 @@ import {areMatchDetailsEqual, color, cp, err, ok, onigurumaResult, r, transpiledRegExpResult, value} from './utils.js'; +// To run this script: +// - npm run onig:match '\w' 'a' +// - npm run onig:match '\n' '\u{A}' +// Don't use pnpm because it auto-escapes backslashes in string args + exec(process.argv.slice(2)); // Basic Oniguruma tester for the console; also reports a comparison with Oniguruma-to-ES diff --git a/src/index.js b/src/index.js index ee06b6b..c14b876 100644 --- a/src/index.js +++ b/src/index.js @@ -24,7 +24,7 @@ import {recursion} from 'regex-recursion'; @typedef {{ accuracy?: keyof Accuracy; avoidSubclass?: boolean; - flags?: import('./tokenize.js').OnigurumaFlags; + flags?: string; global?: boolean; hasIndices?: boolean; maxRecursionDepth?: number | null; @@ -78,7 +78,7 @@ function toDetails(pattern, options) { Returns an Oniguruma AST generated from an Oniguruma pattern. @param {string} pattern Oniguruma regex pattern. @param {{ - flags?: import('./tokenize.js').OnigurumaFlags; + flags?: string; }} [options] @returns {import('./parse.js').OnigurumaAst} */ diff --git a/src/tokenize.js b/src/tokenize.js index 9b32108..9f69ec6 100644 --- a/src/tokenize.js +++ b/src/tokenize.js @@ -113,10 +113,6 @@ const charClassTokenRe = new RegExp(r` `.replace(/\s+/g, ''), 'gsu'); /** -@typedef {'i' | ''} FlagI -@typedef {'m' | ''} FlagM -@typedef {'x' | ''} FlagX -@typedef {`${FlagI}${FlagM}${FlagX}` | `${FlagI}${FlagX}${FlagM}` | `${FlagM}${FlagI}${FlagX}` | `${FlagM}${FlagX}${FlagI}` | `${FlagX}${FlagI}${FlagM}` | `${FlagX}${FlagM}${FlagI}`} OnigurumaFlags @typedef {{ type: keyof TokenTypes; raw: string; @@ -133,7 +129,7 @@ const charClassTokenRe = new RegExp(r` */ /** @param {string} pattern -@param {OnigurumaFlags} [flags] Oniguruma flags. Flag `m` is equivalent to JS flag `s`. +@param {string} [flags] Oniguruma flags. Flag `m` is equivalent to JS flag `s`. @returns {TokenizerResult} */ function tokenize(pattern, flags = '') {