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): Handle empty strings during template usage analysis of setup bindings. (fix #4599) #4608

Merged
merged 2 commits into from Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -202,6 +202,22 @@ return { props, a, emit }
}"
`;

exports[`SFC compile <script setup> dev mode import usage check attribute expressions 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { bar, baz } from './x'

export default /*#__PURE__*/_defineComponent({
setup(__props, { expose }) {
expose()

const cond = true

return { cond, bar, baz }
}

})"
`;

exports[`SFC compile <script setup> dev mode import usage check components 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
import { FooBar, FooBaz, FooQux, foo } from './x'
Expand Down
15 changes: 15 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -342,6 +342,21 @@ defineExpose({ foo: 123 })
assertCode(content)
})

// https://github.com/vuejs/vue-next/issues/4599
test('attribute expressions', () => {
const { content } = compile(`
<script setup lang="ts">
import { bar, baz } from './x'
const cond = true
</script>
<template>
<div :class="[cond ? '' ? bar() : 'default']" :style="baz"></div>
LinusBorg marked this conversation as resolved.
Show resolved Hide resolved
</template>
`)
expect(content).toMatch(`return { cond, bar, baz }`)
assertCode(content)
})

test('vue interpolations', () => {
const { content } = compile(`
<script setup lang="ts">
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -1823,7 +1823,7 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {

function stripStrings(exp: string) {
return exp
.replace(/'[^']+'|"[^"]+"/g, '')
.replace(/'[^']*'|"[^"]*"/g, '')
.replace(/`[^`]+`/g, stripTemplateString)
}

Expand Down