Skip to content

Commit 3bca0ba

Browse files
committed
build artefacts
1 parent ed97a7d commit 3bca0ba

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

commonjs/compose-regexp.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
const stringNormalizerMatcher = /[.?*+^$[\]\\(){}|]/g;
104104

105105

106-
const suffixMatcher = /^(?:[+*?]|\{(?=((\d+)))\1,?(\d*)\})\??$/;
106+
const suffixMatcher = /^(?:[+*?]|\{(\d+)(?:,(\d*))?\})\??$/;
107107

108108

109109
const tokenMatcher = /(\\.)|[-()|\[\]]((?=\?<?[=!]))?/g;
@@ -287,6 +287,24 @@
287287
return hasRefs
288288
});
289289

290+
const finalQuantifierMatcher = /\\\\|\\\{|(\{\d+(?:,\d*)?\}$)/g;
291+
const badQuantifierMatcher = /^\d*(?:,\d*)?\}/;
292+
293+
function combinesAsQuantfier(x1, x2) {
294+
// first look for a bad start in x2 since this is fast
295+
const badStart = x2.source.match(badQuantifierMatcher);
296+
if (badStart == null) return false
297+
// Now scan the combination looking for a newly formed quantifier
298+
const haystack = x1.source + badStart[0];
299+
let result;
300+
finalQuantifierMatcher.lastIndex = 0;
301+
while (result = finalQuantifierMatcher.exec(haystack)) {
302+
if (result[1] != null) return true
303+
}
304+
return false
305+
}
306+
307+
290308
// When composing expressions into a sequence, regexps that have a top-level
291309
// choice operator must be wrapped in a non-capturing group. This function
292310
// detects whether the group is needed or not.
@@ -517,10 +535,10 @@
517535
&& hasRefs(x1)
518536
&& metadata.get(x1.key, 'hasFinalRef')
519537
&& (/^\d/.test(x2.source))
538+
|| combinesAsQuantfier(x1, x2)
520539
? '(?:)'
521540
: ''
522541
) + x2.source;
523-
524542
return x2
525543
}
526544
}
@@ -721,7 +739,7 @@
721739
function suffix(quantifier, ...args) {
722740
if (typeof quantifier !== 'string') quantifier = '{' + String(quantifier) + '}';
723741
const match = quantifier.match(suffixMatcher);
724-
if (!match || match[3] && Number(match[3]) < Number(match[2])) throw new SyntaxError("Invalid suffix '" + quantifier+ "'.")
742+
if (!match || match[2] && Number(match[2]) < Number(match[1])) throw new SyntaxError("Invalid suffix '" + quantifier+ "'.")
725743
return args.length === 0
726744
? _suffix.bind(null, quantifier)
727745
: _suffix(quantifier, ...args)

0 commit comments

Comments
 (0)