diff --git a/README.md b/README.md index 82d513c..fa661d8 100644 --- a/README.md +++ b/README.md @@ -140,13 +140,7 @@ These options can be set to `false` or `'transform'`. When using `'transform'`, // → '(?:(?![f-h])[\s\S])' (to be used without /u) ``` -#### Experimental regular expression features - -These options can be set to `false`, `'parse'` and `'transform'`. When using `'transform'`, the corresponding features are compiled to older syntax that can run in older browsers. When using `'parse'`, they are parsed and left as-is in the output pattern. When using `false` (the default), they result in a syntax error if used. - -Once these features become stable (when the proposals are accepted as part of ECMAScript), they will be parsed by default and thus `'parse'` will behave like `false`. - -- `modifiers` - [Inline `m`/`s`/`i` modifiers](https://github.com/tc39/proposal-regexp-modifiers) +- `modifiers` - [Inline `i`/`m`/`s` modifiers](https://github.com/tc39/proposal-regexp-modifiers) ```js rewritePattern('(?i:[a-z])[a-z]', '', { @@ -155,6 +149,12 @@ Once these features become stable (when the proposals are accepted as part of EC // → '(?:[a-zA-Z])([a-z])' ``` +#### Experimental regular expression features + +These options can be set to `false`, `'parse'` and `'transform'`. When using `'transform'`, the corresponding features are compiled to older syntax that can run in older browsers. When using `'parse'`, they are parsed and left as-is in the output pattern. When using `false` (the default), they result in a syntax error if used. + +Once these features become stable (when the proposals are accepted as part of ECMAScript), they will be parsed by default and thus `'parse'` will behave like `false`. + #### Miscellaneous options - `onNamedGroup` diff --git a/rewrite-pattern.js b/rewrite-pattern.js index e23f688..32bd5f5 100644 --- a/rewrite-pattern.js +++ b/rewrite-pattern.js @@ -822,6 +822,7 @@ const validateOptions = (options) => { throw new Error(`.${key} must be false (default) or 'transform'.`); } break; + // todo: remove modifiers: 'parse' in regexpu-core v7 case 'modifiers': if (value != null && value !== false && value !== 'parse' && value !== 'transform') { throw new Error(`.${key} must be false (default), 'parse' or 'transform'.`); @@ -867,9 +868,8 @@ const rewritePattern = (pattern, flags, options) => { config.modifiersData.m = undefined; const regjsparserFeatures = { - 'modifiers': Boolean(options && options.modifiers), - // Enable every stable RegExp feature by default + 'modifiers': true, 'unicodePropertyEscape': true, 'unicodeSet': true, 'namedGroups': true, diff --git a/tests/fixtures/modifiers.js b/tests/fixtures/modifiers.js index 2dc4c26..50407cf 100644 --- a/tests/fixtures/modifiers.js +++ b/tests/fixtures/modifiers.js @@ -60,7 +60,7 @@ const modifiersFixtures = [ { 'pattern': '(?i:[\\q{ab|cd|abc}--\\q{abc}--\\q{cd}])', 'flags': 'v', - 'options': { unicodeSetsFlag: 'transform', modifiers: 'parse' }, + 'options': { unicodeSetsFlag: 'transform', modifiers: false }, 'expected': '(?i:(?:ab))', 'expectedFlags': 'u', }, { @@ -200,7 +200,7 @@ const modifiersFixtures = [ { 'pattern': '(?-i:[\\q{ab|cd|abc}--\\q{abc}--\\q{cd}])', 'flags': 'iv', - 'options': { unicodeSetsFlag: 'transform', modifiers: 'parse' }, + 'options': { unicodeSetsFlag: 'transform', modifiers: false }, 'expected': '(?-i:(?:ab))', 'expectedFlags': 'iu', }, { @@ -314,6 +314,13 @@ const modifiersFixtures = [ 'expected': '(?:(?:^|(?<=[\\n\\r\\u2028\\u2029]))[A-Za-z])', 'expectedFlags': '', }, + { + 'pattern': '(?ims:^[a-z])', + 'flags': '', + 'expected': '(?ims:^[a-z])', + 'expectedFlags': '', + 'options': { 'modifiers': false } + }, // -ims { 'pattern': '(?-ims:^[a-z].)(^[a-z].)', @@ -326,6 +333,12 @@ const modifiersFixtures = [ 'expected': '(?:^[a-z].)(^[a-z].)', 'expectedFlags': '', }, + { + 'pattern': '(?-ims:^[a-z].)(^[a-z].)', + 'expected': '(?-ims:^[a-z].)(^[a-z].)', + 'expectedFlags': '', + 'options': { 'modifiers': false } + }, ].filter(Boolean); exports.modifiersFixtures = modifiersFixtures; diff --git a/tests/tests.js b/tests/tests.js index 0ce7530..91f20c7 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -401,11 +401,5 @@ describe('modifiers', () => { } }); } - - it('No `modifiers:"transform"`', () => { - assert.throws(() => { - rewritePattern('(?i:a)', ''); - }); - }) });