diff --git a/packages/compiler-sfc/__tests__/parse.spec.ts b/packages/compiler-sfc/__tests__/parse.spec.ts
index ddd6570de9a..d7d8ca6b2e8 100644
--- a/packages/compiler-sfc/__tests__/parse.spec.ts
+++ b/packages/compiler-sfc/__tests__/parse.spec.ts
@@ -106,6 +106,16 @@ h1 { color: red }
expect(descriptor.template!.content).toBe(content)
})
+ // #1120
+ test('alternative template lang should be treated as plain text', () => {
+ const content = `p(v-if="1 < 2") test`
+ const { descriptor, errors } = parse(
+ `` + content + ``
+ )
+ expect(errors.length).toBe(0)
+ expect(descriptor.template!.content).toBe(content)
+ })
+
test('error tolerance', () => {
const { errors } = parse(``)
expect(errors.length).toBe(1)
diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts
index ce466ba6728..2e8bd719eb6 100644
--- a/packages/compiler-sfc/src/parse.ts
+++ b/packages/compiler-sfc/src/parse.ts
@@ -96,10 +96,20 @@ export function parse(
isNativeTag: () => true,
// preserve all whitespaces
isPreTag: () => true,
- getTextMode: ({ tag }, parent) => {
+ getTextMode: ({ tag, props }, parent) => {
// all top level elements except are parsed as raw text
// containers
- if (!parent && tag !== 'template') {
+ if (
+ (!parent && tag !== 'template') ||
+ // should also be treated as raw text
+ props.some(
+ p =>
+ p.type === NodeTypes.ATTRIBUTE &&
+ p.name === 'lang' &&
+ p.value &&
+ p.value.content !== 'html'
+ )
+ ) {
return TextModes.RAWTEXT
} else {
return TextModes.DATA