fix(compiler-sfc): handle empty strings during template usage analysis of setup bindings (#4608)
fix #4599
This commit is contained in:
parent
fcd5422b4a
commit
bdb1a7958b
@ -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`] = `
|
exports[`SFC compile <script setup> dev mode import usage check components 1`] = `
|
||||||
"import { defineComponent as _defineComponent } from 'vue'
|
"import { defineComponent as _defineComponent } from 'vue'
|
||||||
import { FooBar, FooBaz, FooQux, foo } from './x'
|
import { FooBar, FooBaz, FooQux, foo } from './x'
|
||||||
|
@ -342,6 +342,21 @@ defineExpose({ foo: 123 })
|
|||||||
assertCode(content)
|
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>
|
||||||
|
</template>
|
||||||
|
`)
|
||||||
|
expect(content).toMatch(`return { cond, bar, baz }`)
|
||||||
|
assertCode(content)
|
||||||
|
})
|
||||||
|
|
||||||
test('vue interpolations', () => {
|
test('vue interpolations', () => {
|
||||||
const { content } = compile(`
|
const { content } = compile(`
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
@ -1826,7 +1826,7 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
|
|||||||
|
|
||||||
function stripStrings(exp: string) {
|
function stripStrings(exp: string) {
|
||||||
return exp
|
return exp
|
||||||
.replace(/'[^']+'|"[^"]+"/g, '')
|
.replace(/'[^']*'|"[^"]*"/g, '')
|
||||||
.replace(/`[^`]+`/g, stripTemplateString)
|
.replace(/`[^`]+`/g, stripTemplateString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user