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,58 +117,64 @@ function parseChildren(
const s = context.source const s = context.source
let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined let node: TemplateChildNode | TemplateChildNode[] | undefined = undefined
if (!context.inPre && startsWith(s, context.options.delimiters[0])) { if (mode === TextModes.DATA) {
// '{{' if (!context.inPre && startsWith(s, context.options.delimiters[0])) {
node = parseInterpolation(context, mode) // '{{'
} else if (mode === TextModes.DATA && s[0] === '<') { node = parseInterpolation(context, mode)
// https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state } else if (s[0] === '<') {
if (s.length === 1) { // https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state
emitError(context, ErrorCodes.EOF_BEFORE_TAG_NAME, 1) if (s.length === 1) {
} else if (s[1] === '!') { emitError(context, ErrorCodes.EOF_BEFORE_TAG_NAME, 1)
// https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state } else if (s[1] === '!') {
if (startsWith(s, '<!--')) { // https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state
node = parseComment(context) if (startsWith(s, '<!--')) {
} else if (startsWith(s, '<!DOCTYPE')) { node = parseComment(context)
// Ignore DOCTYPE by a limitation. } else if (startsWith(s, '<!DOCTYPE')) {
node = parseBogusComment(context) // Ignore DOCTYPE by a limitation.
} else if (startsWith(s, '<![CDATA[')) { node = parseBogusComment(context)
if (ns !== Namespaces.HTML) { } else if (startsWith(s, '<![CDATA[')) {
node = parseCDATA(context, ancestors) if (ns !== Namespaces.HTML) {
node = parseCDATA(context, ancestors)
} else {
emitError(context, ErrorCodes.CDATA_IN_HTML_CONTENT)
node = parseBogusComment(context)
}
} else { } else {
emitError(context, ErrorCodes.CDATA_IN_HTML_CONTENT) emitError(context, ErrorCodes.INCORRECTLY_OPENED_COMMENT)
node = parseBogusComment(context) node = parseBogusComment(context)
} }
} else { } else if (s[1] === '/') {
emitError(context, ErrorCodes.INCORRECTLY_OPENED_COMMENT) // https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
if (s.length === 2) {
emitError(context, ErrorCodes.EOF_BEFORE_TAG_NAME, 2)
} else if (s[2] === '>') {
emitError(context, ErrorCodes.MISSING_END_TAG_NAME, 2)
advanceBy(context, 3)
continue
} else if (/[a-z]/i.test(s[2])) {
emitError(context, ErrorCodes.X_INVALID_END_TAG)
parseTag(context, TagType.End, parent)
continue
} else {
emitError(
context,
ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME,
2
)
node = parseBogusComment(context)
}
} else if (/[a-z]/i.test(s[1])) {
node = parseElement(context, ancestors)
} else if (s[1] === '?') {
emitError(
context,
ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME,
1
)
node = parseBogusComment(context) node = parseBogusComment(context)
}
} else if (s[1] === '/') {
// https://html.spec.whatwg.org/multipage/parsing.html#end-tag-open-state
if (s.length === 2) {
emitError(context, ErrorCodes.EOF_BEFORE_TAG_NAME, 2)
} else if (s[2] === '>') {
emitError(context, ErrorCodes.MISSING_END_TAG_NAME, 2)
advanceBy(context, 3)
continue
} else if (/[a-z]/i.test(s[2])) {
emitError(context, ErrorCodes.X_INVALID_END_TAG)
parseTag(context, TagType.End, parent)
continue
} else { } else {
emitError(context, ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME, 2) emitError(context, ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME, 1)
node = parseBogusComment(context)
} }
} else if (/[a-z]/i.test(s[1])) {
node = parseElement(context, ancestors)
} else if (s[1] === '?') {
emitError(
context,
ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME,
1
)
node = parseBogusComment(context)
} else {
emitError(context, ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME, 1)
} }
} }
if (!node) { if (!node) {