Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): parses correctly when inline mode is off #8337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -804,6 +804,25 @@ describe('SFC compile <script setup>', () => {
expect(content).toMatch(`"--${mockId}-count": (count.value)`)
assertCode(content)
})

test('the v-for wrapped in parentheses can be correctly parsed & inline is false', () => {
expect(() =>
compile(
`
<script setup lang="ts">
import { ref } from 'vue'
const stacks = ref([])
</script>
<template>
<div v-for="({ file: efile }) of stacks"></div>
</template>
`,
{
inlineTemplate: false
}
)
).not.toThrowError()
})
})

describe('with TypeScript', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/script/importUsageCheck.ts
Expand Up @@ -83,7 +83,9 @@ function processExp(exp: string, dir?: string): string {
} else if (dir === 'for') {
const inMatch = exp.match(forAliasRE)
if (inMatch) {
const [, LHS, RHS] = inMatch
let [, LHS, RHS] = inMatch
// #6088
LHS = LHS.trim().replace(/^\(|\)$/g, '')
return processExp(`(${LHS})=>{}`) + processExp(RHS)
}
}
Expand Down