Improved handling of escape sequences
This commit is contained in:
parent
2a6e78d67b
commit
48afa46adc
@ -65,7 +65,16 @@ export class TokenStream {
|
||||
// Skip shebang (can be used to execute templates directly with an
|
||||
// interpreter that first builds the template and then executes)
|
||||
this._skipShebang();
|
||||
} else if (this._cs.isNext(TokenStream.ESCAPE)) {
|
||||
} else if (this._isNextEscapedTag([
|
||||
// Allow escaping of open and full-line tags
|
||||
TokenStream.OPEN_STATEMENT,
|
||||
TokenStream.OPEN_INLINE,
|
||||
TokenStream.OPEN_INLINE_UNESCAPED,
|
||||
TokenStream.OPEN_INLINE_STATEMENT,
|
||||
TokenStream.OPEN_INLINE_STATEMENT_UNESCAPED,
|
||||
TokenStream.STATEMENT,
|
||||
TokenStream.COMMENT
|
||||
])) {
|
||||
// Skip escape
|
||||
this._cs.next(TokenStream.ESCAPE.length);
|
||||
// Treat everything as raw until next space
|
||||
@ -132,7 +141,7 @@ export class TokenStream {
|
||||
let value = '';
|
||||
while (!this._cs.eof() && !this._cs.isNext(closeTag)) {
|
||||
// Handle any escaped closing tag
|
||||
if (this._cs.isNext(TokenStream.ESCAPE)) {
|
||||
if (this._isNextEscapedTag([closeTag])) {
|
||||
// Skip escape
|
||||
this._cs.next(TokenStream.ESCAPE.length);
|
||||
|
||||
@ -243,4 +252,12 @@ export class TokenStream {
|
||||
_isSpace(c) {
|
||||
return /[^\S\r\n]/.test(c);
|
||||
}
|
||||
|
||||
_isNextEscapedTag(possibleTags=[]) {
|
||||
if (!this._cs.isNext(TokenStream.ESCAPE)) return false;
|
||||
|
||||
return !!possibleTags.find(tag =>
|
||||
this._cs.isNext(TokenStream.ESCAPE + tag)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user