fix(compiler-sfc): fix import usage check for last expression
This commit is contained in:
parent
c9c7030041
commit
1e1682f060
@ -206,7 +206,7 @@ return { x }
|
|||||||
|
|
||||||
exports[`SFC compile <script setup> imports imports not used in <template> should not be exposed 1`] = `
|
exports[`SFC compile <script setup> imports imports not used in <template> should not be exposed 1`] = `
|
||||||
"import { defineComponent as _defineComponent } from 'vue'
|
"import { defineComponent as _defineComponent } from 'vue'
|
||||||
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y } from './x'
|
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y, Last } from './x'
|
||||||
|
|
||||||
export default _defineComponent({
|
export default _defineComponent({
|
||||||
setup(__props, { expose }) {
|
setup(__props, { expose }) {
|
||||||
@ -214,7 +214,7 @@ export default _defineComponent({
|
|||||||
|
|
||||||
const fooBar: FooBar = 1
|
const fooBar: FooBar = 1
|
||||||
|
|
||||||
return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y }
|
return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y, Last }
|
||||||
}
|
}
|
||||||
|
|
||||||
})"
|
})"
|
||||||
|
@ -213,13 +213,14 @@ defineExpose({ foo: 123 })
|
|||||||
test('imports not used in <template> should not be exposed', () => {
|
test('imports not used in <template> should not be exposed', () => {
|
||||||
const { content } = compile(`
|
const { content } = compile(`
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y } from './x'
|
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y, Last } from './x'
|
||||||
const fooBar: FooBar = 1
|
const fooBar: FooBar = 1
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<FooBaz v-my-dir>{{ x }} {{ yy }} {{ x$y }}</FooBaz>
|
<FooBaz v-my-dir>{{ x }} {{ yy }} {{ x$y }}</FooBaz>
|
||||||
<foo-qux/>
|
<foo-qux/>
|
||||||
<div :id="z + 'y'">FooBar</div>
|
<div :id="z + 'y'">FooBar</div>
|
||||||
|
<Last/>
|
||||||
</template>
|
</template>
|
||||||
`)
|
`)
|
||||||
assertCode(content)
|
assertCode(content)
|
||||||
@ -231,7 +232,7 @@ defineExpose({ foo: 123 })
|
|||||||
// y: should not be matched by {{ yy }} or 'y' in binding exps
|
// y: should not be matched by {{ yy }} or 'y' in binding exps
|
||||||
// x$y: #4274 should escape special chars when creating Regex
|
// x$y: #4274 should escape special chars when creating Regex
|
||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y }`
|
`return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y, Last }`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -2220,6 +2220,7 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
code += ';'
|
||||||
templateUsageCheckCache.set(content, code)
|
templateUsageCheckCache.set(content, code)
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user