From 1607ef8782cdec82ef17021ab8aebb7f31c3e1d9 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Sun, 13 Dec 2015 17:40:06 +0200 Subject: [PATCH] refactor(HtmlLexer): process carriage returns in one pass Closes #5867 --- modules/angular2/src/compiler/html_lexer.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/angular2/src/compiler/html_lexer.ts b/modules/angular2/src/compiler/html_lexer.ts index f410fbdb73..2420e9d60c 100644 --- a/modules/angular2/src/compiler/html_lexer.ts +++ b/modules/angular2/src/compiler/html_lexer.ts @@ -84,8 +84,7 @@ const $x = 120; const $NBSP = 160; -var CRLF_REGEXP = /\r\n/g; -var CR_REGEXP = /\r/g; +var CR_OR_CRLF_REGEXP = /\r\n?/g; function unexpectedCharacterErrorMsg(charCode: number): string { var char = charCode === $EOF ? 'EOF' : StringWrapper.fromCharCode(charCode); @@ -127,8 +126,7 @@ class _HtmlTokenizer { // http://www.w3.org/TR/html5/syntax.html#preprocessing-the-input-stream // In order to keep the original position in the source, we can not pre-process it. // Instead CRs are processed right before instantiating the tokens. - content = StringWrapper.replaceAll(content, CRLF_REGEXP, '\r'); - return StringWrapper.replaceAll(content, CR_REGEXP, '\n'); + return StringWrapper.replaceAll(content, CR_OR_CRLF_REGEXP, '\n'); } tokenize(): HtmlTokenizeResult {