MCPcopy Index your code
hub / github.com/reactjs/react-rails / testRegExp

Function testRegExp

lib/assets/javascripts/JSXTransformer.js:3736–3774  ·  view source on GitHub ↗
(pattern, flags)

Source from the content-addressed store, hash-verified

3734 }
3735
3736 function testRegExp(pattern, flags) {
3737 var tmp = pattern,
3738 value;
3739
3740 if (flags.indexOf('u') >= 0) {
3741 // Replace each astral symbol and every Unicode code point
3742 // escape sequence with a single ASCII symbol to avoid throwing on
3743 // regular expressions that are only valid in combination with the
3744 // `/u` flag.
3745 // Note: replacing with the ASCII symbol `x` might cause false
3746 // negatives in unlikely scenarios. For example, `[\u{61}-b]` is a
3747 // perfectly valid pattern that is equivalent to `[a-b]`, but it
3748 // would be replaced by `[x-b]` which throws an error.
3749 tmp = tmp
3750 .replace(/\\u\{([0-9a-fA-F]+)\}/g, function ($0, $1) {
3751 if (parseInt($1, 16) <= 0x10FFFF) {
3752 return 'x';
3753 }
3754 throwError({}, Messages.InvalidRegExp);
3755 })
3756 .replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 'x');
3757 }
3758
3759 // First, detect invalid regular expressions.
3760 try {
3761 value = new RegExp(tmp);
3762 } catch (e) {
3763 throwError({}, Messages.InvalidRegExp);
3764 }
3765
3766 // Return a regular expression object for this pattern-flag pair, or
3767 // `null` in case the current environment doesn't support the flags it
3768 // uses.
3769 try {
3770 return new RegExp(pattern, flags);
3771 } catch (exception) {
3772 return null;
3773 }
3774 }
3775
3776 function scanRegExpBody() {
3777 var ch, str, classMarker, terminated, body;

Callers 1

scanRegExpFunction · 0.85

Calls 1

throwErrorFunction · 0.85

Tested by

no test coverage detected