Skip to content

Commit

Permalink
fix(compiler-sfc): fix parsing error when lang="" is used on plain …
Browse files Browse the repository at this point in the history
…element (#2569)

fix #2566
  • Loading branch information
edison1105 authored Nov 30, 2020
1 parent bf16a57 commit 5f2a853
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 12 additions & 0 deletions packages/compiler-sfc/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ h1 { color: red }
expect(descriptor.template!.content).toBe(content)
})

//#2566
test('div lang should not be treated as plain text', () => {
const { errors } = parse(`
<template lang="pug">
<div lang="">
<div></div>
</div>
</template>
`)
expect(errors.length).toBe(0)
})

test('error tolerance', () => {
const { errors } = parse(`<template>`)
expect(errors.length).toBe(1)
Expand Down
15 changes: 8 additions & 7 deletions packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ export function parse(
if (
(!parent && tag !== 'template') ||
// <template lang="xxx"> should also be treated as raw text
props.some(
p =>
p.type === NodeTypes.ATTRIBUTE &&
p.name === 'lang' &&
p.value &&
p.value.content !== 'html'
)
(tag === 'template' &&
props.some(
p =>
p.type === NodeTypes.ATTRIBUTE &&
p.name === 'lang' &&
p.value &&
p.value.content !== 'html'
))
) {
return TextModes.RAWTEXT
} else {
Expand Down

0 comments on commit 5f2a853

Please sign in to comment.