test/dummy/node_modules/regjsgen/regjsgen.js in disco_app-0.18.1 vs test/dummy/node_modules/regjsgen/regjsgen.js in disco_app-0.18.2

- old
+ new

@@ -1,9 +1,9 @@ /*! - * regjsgen 0.5.2 - * Copyright 2014-2020 Benjamin Tan <https://ofcr.se/> - * Available under the MIT license <https://github.com/bnjmnt4n/regjsgen/blob/master/LICENSE-MIT.txt> + * regjsgen 0.5.1 + * Copyright 2014-2019 Benjamin Tan <https://bnjmnt4n.now.sh/> + * Available under MIT license <https://github.com/bnjmnt4n/regjsgen/blob/master/LICENSE> */ ;(function() { 'use strict'; // Used to determine if values are of the language type `Object`. @@ -94,49 +94,27 @@ } throw Error('Invalid node type: ' + type); } - // Constructs a string by concatentating the output of each term. - function generateSequence(generator, terms) { - var i = -1, - length = terms.length, - result = '', - term; + /*--------------------------------------------------------------------------*/ - while (++i < length) { - term = terms[i]; + function generateAlternative(node) { + assertType(node.type, 'alternative'); - // Ensure that `\0` null escapes followed by number symbols are not - // treated as backreferences. - if ( - i + 1 < length && - terms[i].type == 'value' && - terms[i].kind == 'null' && - terms[i + 1].type == 'value' && - terms[i + 1].kind == 'symbol' && - terms[i + 1].codePoint >= 48 && - terms[i + 1].codePoint <= 57 - ) { - result += '\\000'; - continue; - } + var terms = node.body, + i = -1, + length = terms.length, + result = ''; - result += generator(term); + while (++i < length) { + result += generateTerm(terms[i]); } return result; } - /*--------------------------------------------------------------------------*/ - - function generateAlternative(node) { - assertType(node.type, 'alternative'); - - return generateSequence(generateTerm, node.body); - } - function generateAnchor(node) { assertType(node.type, 'anchor'); switch (node.kind) { case 'start': @@ -159,22 +137,38 @@ } function generateCharacterClass(node) { assertType(node.type, 'characterClass'); - return '[' + - (node.negative ? '^' : '') + - generateSequence(generateClassAtom, node.body) + - ']'; + var classRanges = node.body, + i = -1, + length = classRanges.length, + result = ''; + + if (node.negative) { + result += '^'; + } + + while (++i < length) { + result += generateClassAtom(classRanges[i]); + } + + return '[' + result + ']'; } function generateCharacterClassEscape(node) { assertType(node.type, 'characterClassEscape'); return '\\' + node.value; } + function generateUnicodePropertyEscape(node) { + assertType(node.type, 'unicodePropertyEscape'); + + return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}'; + } + function generateCharacterClassRange(node) { assertType(node.type, 'characterClassRange'); var min = node.min, max = node.max; @@ -244,12 +238,18 @@ break; default: throw Error('Invalid behaviour: ' + node.behaviour); } - result += generateSequence(generate, node.body); + var body = node.body, + i = -1, + length = body.length; + while (++i < length) { + result += generate(body[i]); + } + return '(' + result + ')'; } function generateIdentifier(node) { assertType(node.type, 'identifier'); @@ -304,16 +304,10 @@ assertType(node.type, 'anchor|characterClass|characterClassEscape|empty|group|quantifier|reference|unicodePropertyEscape|value|dot'); return generate(node); } - function generateUnicodePropertyEscape(node) { - assertType(node.type, 'unicodePropertyEscape'); - - return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}'; - } - function generateValue(node) { assertType(node.type, 'value'); var kind = node.kind, codePoint = node.codePoint; @@ -330,11 +324,11 @@ case 'identifier': return '\\' + fromCodePoint(codePoint); case 'null': return '\\' + codePoint; case 'octal': - return '\\' + ('000' + codePoint.toString(8)).slice(-3); + return '\\' + codePoint.toString(8); case 'singleEscape': switch (codePoint) { case 0x0008: return '\\b'; case 0x0009: @@ -345,12 +339,10 @@ return '\\v'; case 0x000C: return '\\f'; case 0x000D: return '\\r'; - case 0x002D: - return '\\-'; default: throw Error('Invalid code point: ' + codePoint); } case 'symbol': return fromCodePoint(codePoint); @@ -370,15 +362,15 @@ 'alternative': generateAlternative, 'anchor': generateAnchor, 'characterClass': generateCharacterClass, 'characterClassEscape': generateCharacterClassEscape, 'characterClassRange': generateCharacterClassRange, + 'unicodePropertyEscape': generateUnicodePropertyEscape, 'disjunction': generateDisjunction, 'dot': generateDot, 'group': generateGroup, 'quantifier': generateQuantifier, 'reference': generateReference, - 'unicodePropertyEscape': generateUnicodePropertyEscape, 'value': generateValue }; /*--------------------------------------------------------------------------*/