Better method name and fixed regexps for IE

This commit is contained in:
xixixao 2013-11-18 15:13:40 +00:00
parent efe8c68c75
commit 073d025fac
2 changed files with 10 additions and 10 deletions

View File

@ -173,7 +173,7 @@
return 0;
}
string = match[0];
this.token('STRING', this.trimAndEscapeLines(string), 0, string.length);
this.token('STRING', this.removeNewlines(string), 0, string.length);
break;
case '"':
if (!(string = this.balancedString(this.chunk, '"'))) {
@ -185,7 +185,7 @@
lexedLength: string.length
});
} else {
this.token('STRING', this.trimAndEscapeLines(string), 0, string.length);
this.token('STRING', this.removeNewlines(string), 0, string.length);
}
break;
default:
@ -762,7 +762,7 @@
return LINE_CONTINUER.test(this.chunk) || ((_ref2 = this.tag()) === '\\' || _ref2 === '.' || _ref2 === '?.' || _ref2 === '?::' || _ref2 === 'UNARY' || _ref2 === 'MATH' || _ref2 === '+' || _ref2 === '-' || _ref2 === 'SHIFT' || _ref2 === 'RELATION' || _ref2 === 'COMPARE' || _ref2 === 'LOGIC' || _ref2 === 'THROW' || _ref2 === 'EXTENDS');
};
Lexer.prototype.trimAndEscapeLines = function(str) {
Lexer.prototype.removeNewlines = function(str) {
return this.escapeLines(str.replace(/^(.)\s*\n\s*/, '$1').replace(/\s*\n\s*(.)$/, '$1'));
};
@ -778,7 +778,7 @@
if (!body) {
return quote + quote;
}
body = body.replace(/\\([^])/g, function(match, contents) {
body = body.replace(/\\([\s\S])/g, function(match, contents) {
if (contents === quote || heredoc && contents === '\n') {
return contents;
} else {
@ -860,7 +860,7 @@
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
SIMPLESTR = /^'[^\\']*(?:\\[^][^\\']*)*'/;
SIMPLESTR = /^'[^\\']*(?:\\[\s\S][^\\']*)*'/;
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;

View File

@ -190,13 +190,13 @@ exports.Lexer = class Lexer
when "'"
return 0 unless match = SIMPLESTR.exec @chunk
string = match[0]
@token 'STRING', @trimAndEscapeLines(string), 0, string.length
@token 'STRING', @removeNewlines(string), 0, string.length
when '"'
return 0 unless string = @balancedString @chunk, '"'
if 0 < string.indexOf '#{', 1
@interpolateString string[1...-1], strOffset: 1, lexedLength: string.length
else
@token 'STRING', @trimAndEscapeLines(string), 0, string.length
@token 'STRING', @removeNewlines(string), 0, string.length
else
return 0
if octalEsc = /^(?:\\.|[^\\])*\\(?:0[0-7]|[1-7])/.test string
@ -686,7 +686,7 @@ exports.Lexer = class Lexer
# Remove newlines from beginning and end of string literals.
# `str` includes quotes.
trimAndEscapeLines: (str) ->
removeNewlines: (str) ->
@escapeLines str.replace(/^(.)\s*\n\s*/, '$1').replace(/\s*\n\s*(.)$/, '$1')
# Converts newlines for string literals.
@ -699,7 +699,7 @@ exports.Lexer = class Lexer
# Constructs a string token by escaping quotes and newlines.
makeString: (body, quote, heredoc) ->
return quote + quote unless body
body = body.replace /\\([^])/g, (match, contents) ->
body = body.replace /\\([\s\S])/g, (match, contents) ->
if contents is quote or heredoc and contents is '\n' then contents else match
body = body.replace /// #{quote} ///g, '\\$&'
quote + @escapeLines(body, heredoc) + quote
@ -795,7 +795,7 @@ CODE = /^[-=]>/
MULTI_DENT = /^(?:\n[^\n\S]*)+/
SIMPLESTR = /^'[^\\']*(?:\\[^][^\\']*)*'/
SIMPLESTR = /^'[^\\']*(?:\\[\s\S][^\\']*)*'/
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/