Skip to content

Commit f745fbe

Browse files
authored
always enable modifiers parsing (#98)
1 parent 5cfd6b9 commit f745fbe

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,7 @@ These options can be set to `false` or `'transform'`. When using `'transform'`,
140140
// → '(?:(?![f-h])[\s\S])' (to be used without /u)
141141
```
142142

143-
#### Experimental regular expression features
144-
145-
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.
146-
147-
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`.
148-
149-
- `modifiers` - [Inline `m`/`s`/`i` modifiers](https://github.com/tc39/proposal-regexp-modifiers)
143+
- `modifiers` - [Inline `i`/`m`/`s` modifiers](https://github.com/tc39/proposal-regexp-modifiers)
150144

151145
```js
152146
rewritePattern('(?i:[a-z])[a-z]', '', {
@@ -155,6 +149,12 @@ Once these features become stable (when the proposals are accepted as part of EC
155149
// → '(?:[a-zA-Z])([a-z])'
156150
```
157151

152+
#### Experimental regular expression features
153+
154+
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.
155+
156+
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`.
157+
158158
#### Miscellaneous options
159159

160160
- `onNamedGroup`

rewrite-pattern.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ const validateOptions = (options) => {
822822
throw new Error(`.${key} must be false (default) or 'transform'.`);
823823
}
824824
break;
825+
// todo: remove modifiers: 'parse' in regexpu-core v7
825826
case 'modifiers':
826827
if (value != null && value !== false && value !== 'parse' && value !== 'transform') {
827828
throw new Error(`.${key} must be false (default), 'parse' or 'transform'.`);
@@ -867,9 +868,8 @@ const rewritePattern = (pattern, flags, options) => {
867868
config.modifiersData.m = undefined;
868869

869870
const regjsparserFeatures = {
870-
'modifiers': Boolean(options && options.modifiers),
871-
872871
// Enable every stable RegExp feature by default
872+
'modifiers': true,
873873
'unicodePropertyEscape': true,
874874
'unicodeSet': true,
875875
'namedGroups': true,

tests/fixtures/modifiers.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const modifiersFixtures = [
6060
{
6161
'pattern': '(?i:[\\q{ab|cd|abc}--\\q{abc}--\\q{cd}])',
6262
'flags': 'v',
63-
'options': { unicodeSetsFlag: 'transform', modifiers: 'parse' },
63+
'options': { unicodeSetsFlag: 'transform', modifiers: false },
6464
'expected': '(?i:(?:ab))',
6565
'expectedFlags': 'u',
6666
}, {
@@ -200,7 +200,7 @@ const modifiersFixtures = [
200200
{
201201
'pattern': '(?-i:[\\q{ab|cd|abc}--\\q{abc}--\\q{cd}])',
202202
'flags': 'iv',
203-
'options': { unicodeSetsFlag: 'transform', modifiers: 'parse' },
203+
'options': { unicodeSetsFlag: 'transform', modifiers: false },
204204
'expected': '(?-i:(?:ab))',
205205
'expectedFlags': 'iu',
206206
}, {
@@ -314,6 +314,13 @@ const modifiersFixtures = [
314314
'expected': '(?:(?:^|(?<=[\\n\\r\\u2028\\u2029]))[A-Za-z])',
315315
'expectedFlags': '',
316316
},
317+
{
318+
'pattern': '(?ims:^[a-z])',
319+
'flags': '',
320+
'expected': '(?ims:^[a-z])',
321+
'expectedFlags': '',
322+
'options': { 'modifiers': false }
323+
},
317324
// -ims
318325
{
319326
'pattern': '(?-ims:^[a-z].)(^[a-z].)',
@@ -326,6 +333,12 @@ const modifiersFixtures = [
326333
'expected': '(?:^[a-z].)(^[a-z].)',
327334
'expectedFlags': '',
328335
},
336+
{
337+
'pattern': '(?-ims:^[a-z].)(^[a-z].)',
338+
'expected': '(?-ims:^[a-z].)(^[a-z].)',
339+
'expectedFlags': '',
340+
'options': { 'modifiers': false }
341+
},
329342
].filter(Boolean);
330343

331344
exports.modifiersFixtures = modifiersFixtures;

tests/tests.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,5 @@ describe('modifiers', () => {
401401
}
402402
});
403403
}
404-
405-
it('No `modifiers:"transform"`', () => {
406-
assert.throws(() => {
407-
rewritePattern('(?i:a)', '');
408-
});
409-
})
410404
});
411405

0 commit comments

Comments
 (0)