Skip to content

Commit 1e1682f

Browse files
committed
fix(compiler-sfc): fix import usage check for last expression
1 parent c9c7030 commit 1e1682f

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ return { x }
206206
207207
exports[`SFC compile <script setup> imports imports not used in <template> should not be exposed 1`] = `
208208
"import { defineComponent as _defineComponent } from 'vue'
209-
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y } from './x'
209+
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y, Last } from './x'
210210
211211
export default _defineComponent({
212212
setup(__props, { expose }) {
213213
expose()
214214
215215
const fooBar: FooBar = 1
216216
217-
return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y }
217+
return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y, Last }
218218
}
219219
220220
})"

packages/compiler-sfc/__tests__/compileScript.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,14 @@ defineExpose({ foo: 123 })
213213
test('imports not used in <template> should not be exposed', () => {
214214
const { content } = compile(`
215215
<script setup lang="ts">
216-
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y } from './x'
216+
import { FooBar, FooBaz, FooQux, vMyDir, x, y, z, x$y, Last } from './x'
217217
const fooBar: FooBar = 1
218218
</script>
219219
<template>
220220
<FooBaz v-my-dir>{{ x }} {{ yy }} {{ x$y }}</FooBaz>
221221
<foo-qux/>
222222
<div :id="z + 'y'">FooBar</div>
223+
<Last/>
223224
</template>
224225
`)
225226
assertCode(content)
@@ -231,7 +232,7 @@ defineExpose({ foo: 123 })
231232
// y: should not be matched by {{ yy }} or 'y' in binding exps
232233
// x$y: #4274 should escape special chars when creating Regex
233234
expect(content).toMatch(
234-
`return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y }`
235+
`return { fooBar, FooBaz, FooQux, vMyDir, x, z, x$y, Last }`
235236
)
236237
})
237238
})

packages/compiler-sfc/src/compileScript.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,7 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
22202220
]
22212221
})
22222222

2223+
code += ';'
22232224
templateUsageCheckCache.set(content, code)
22242225
return code
22252226
}

0 commit comments

Comments
 (0)