fix(compiler-core): should only parse interpolations in DATA text mode

This commit is contained in:
Evan You 2019-12-10 15:30:17 -05:00
parent 5cd1495767
commit 95b2cb6fd2

View File

@ -117,10 +117,11 @@ function parseChildren(
const s = context.source const s = context.source
let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined
if (mode === TextModes.DATA) {
if (!context.inPre && startsWith(s, context.options.delimiters[0])) { if (!context.inPre && startsWith(s, context.options.delimiters[0])) {
// '{{' // '{{'
node = parseInterpolation(context, mode) node = parseInterpolation(context, mode)
} else if (mode === TextModes.DATA && s[0] === '<') { } else if (s[0] === '<') {
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
if (s.length === 1) { if (s.length === 1) {
emitError(context, ErrorCodes.EOF_BEFORE_TAG_NAME, 1) emitError(context, ErrorCodes.EOF_BEFORE_TAG_NAME, 1)
@ -155,7 +156,11 @@ function parseChildren(
parseTag(context, TagType.End, parent) parseTag(context, TagType.End, parent)
continue continue
} else { } else {
emitError(context, ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME, 2) emitError(
context,
ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME,
2
)
node = parseBogusComment(context) node = parseBogusComment(context)
} }
} else if (/[a-z]/i.test(s[1])) { } else if (/[a-z]/i.test(s[1])) {
@ -171,6 +176,7 @@ function parseChildren(
emitError(context, ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME, 1) emitError(context, ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME, 1)
} }
} }
}
if (!node) { if (!node) {
node = parseText(context, mode) node = parseText(context, mode)
} }