1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Keep unicode code point escapes as is when possible (#4520)

This commit is contained in:
Julian Rosse 2017-04-25 12:15:08 -05:00 committed by Simon Lydell
parent 07ae1edb44
commit 7ef5cb4a1f
4 changed files with 37 additions and 23 deletions

View file

@ -1,11 +1,11 @@
// Generated by CoffeeScript 2.0.0-beta1
(function() {
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, HERE_JSTOKEN, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, Rewriter, SHIFT, SIMPLE_STRING_OMIT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, UNICODE_CODE_POINT_ESCAPE, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, isForFrom, isUnassignable, key, locationDataToString, repeat, starts, throwSyntaxError,
var BOM, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HERECOMMENT_ILLEGAL, HEREDOC_DOUBLE, HEREDOC_INDENT, HEREDOC_SINGLE, HEREGEX, HEREGEX_OMIT, HERE_JSTOKEN, IDENTIFIER, INDENTABLE_CLOSERS, INDEXABLE, INVERSES, JSTOKEN, JS_KEYWORDS, LEADING_BLANK_LINE, LINE_BREAK, LINE_CONTINUER, Lexer, MATH, MULTI_DENT, NOT_REGEX, NUMBER, OPERATOR, POSSIBLY_DIVISION, REGEX, REGEX_FLAGS, REGEX_ILLEGAL, REGEX_INVALID_ESCAPE, RELATION, RESERVED, Rewriter, SHIFT, SIMPLE_STRING_OMIT, STRICT_PROSCRIBED, STRING_DOUBLE, STRING_INVALID_ESCAPE, STRING_OMIT, STRING_SINGLE, STRING_START, TRAILING_BLANK_LINE, TRAILING_SPACES, UNARY, UNARY_MATH, UNICODE_CODE_POINT_ESCAPE, VALID_FLAGS, WHITESPACE, compact, count, invertLiterate, isForFrom, isUnassignable, key, locationDataToString, merge, repeat, starts, throwSyntaxError,
indexOf = [].indexOf;
({Rewriter, INVERSES} = require('./rewriter'));
({count, starts, compact, repeat, invertLiterate, locationDataToString, throwSyntaxError} = require('./helpers'));
({count, starts, compact, repeat, invertLiterate, merge, locationDataToString, throwSyntaxError} = require('./helpers'));
exports.Lexer = Lexer = class Lexer {
tokenize(code, opts = {}) {
@ -366,9 +366,6 @@
isRegex: true,
offsetInChunk: 1
});
body = this.formatRegex(body, {
delimiter: '/'
});
index = regex.length;
prev = this.prev();
if (prev) {
@ -398,8 +395,13 @@
});
break;
case !(regex || tokens.length === 1):
if (body == null) {
body = this.formatHeregex(tokens[0][1]);
if (body) {
body = this.formatRegex(body, {
flags,
delimiter: '/'
});
} else {
body = this.formatHeregex(tokens[0][1], {flags});
}
this.token('REGEX', `${this.makeDelimitedLiteral(body, {
delimiter: '/'
@ -412,7 +414,9 @@
this.mergeInterpolationTokens(tokens, {
delimiter: '"',
double: true
}, this.formatHeregex);
}, (str) => {
return this.formatHeregex(str, {flags});
});
if (flags) {
this.token(',', ',', index - 1, 0);
this.token('STRING', '"' + flags + '"', index - 1, flags.length);
@ -893,10 +897,10 @@
return this.replaceUnicodeCodePointEscapes(str.replace(STRING_OMIT, '$1'), options);
}
formatHeregex(str) {
return this.formatRegex(str.replace(HEREGEX_OMIT, '$1$2'), {
formatHeregex(str, options) {
return this.formatRegex(str.replace(HEREGEX_OMIT, '$1$2'), merge(options, {
delimiter: '///'
});
}));
}
formatRegex(str, options) {
@ -919,6 +923,8 @@
}
replaceUnicodeCodePointEscapes(str, options) {
var shouldReplace;
shouldReplace = (options.flags != null) && indexOf.call(options.flags, 'u') < 0;
return str.replace(UNICODE_CODE_POINT_ESCAPE, (match, escapedBackslash, codePointHex, offset) => {
var codePointDecimal;
if (escapedBackslash) {
@ -931,6 +937,9 @@
length: codePointHex.length + 4
});
}
if (!shouldReplace) {
return match;
}
return this.unicodeCodePointToUnicodeEscapes(codePointDecimal);
});
}