Skip to content

Commit 5f2a853

Browse files
authored
fix(compiler-sfc): fix parsing error when lang="" is used on plain element (#2569)
fix #2566
1 parent bf16a57 commit 5f2a853

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/compiler-sfc/__tests__/parse.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ h1 { color: red }
144144
expect(descriptor.template!.content).toBe(content)
145145
})
146146

147+
//#2566
148+
test('div lang should not be treated as plain text', () => {
149+
const { errors } = parse(`
150+
<template lang="pug">
151+
<div lang="">
152+
<div></div>
153+
</div>
154+
</template>
155+
`)
156+
expect(errors.length).toBe(0)
157+
})
158+
147159
test('error tolerance', () => {
148160
const { errors } = parse(`<template>`)
149161
expect(errors.length).toBe(1)

packages/compiler-sfc/src/parse.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ export function parse(
115115
if (
116116
(!parent && tag !== 'template') ||
117117
// <template lang="xxx"> should also be treated as raw text
118-
props.some(
119-
p =>
120-
p.type === NodeTypes.ATTRIBUTE &&
121-
p.name === 'lang' &&
122-
p.value &&
123-
p.value.content !== 'html'
124-
)
118+
(tag === 'template' &&
119+
props.some(
120+
p =>
121+
p.type === NodeTypes.ATTRIBUTE &&
122+
p.name === 'lang' &&
123+
p.value &&
124+
p.value.content !== 'html'
125+
))
125126
) {
126127
return TextModes.RAWTEXT
127128
} else {

0 commit comments

Comments
 (0)