Skip to content

Commit c5a0244

Browse files
committed
fix(compiler-sfc): resolve template literals without expressions as string literals
1 parent 45547e6 commit c5a0244

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ describe('resolveType', () => {
2020
foo: number // property
2121
bar(): void // method
2222
'baz': string // string literal key
23+
[\`qux\`]: boolean // template literal key
2324
(e: 'foo'): void // call signature
2425
(e: 'bar'): void
2526
}>()`)
2627
expect(props).toStrictEqual({
2728
foo: ['Number'],
2829
bar: ['Function'],
2930
baz: ['String'],
31+
qux: ['Boolean'],
3032
})
3133
expect(calls?.length).toBe(2)
3234
})
@@ -195,7 +197,7 @@ describe('resolveType', () => {
195197
type T = 'foo' | 'bar'
196198
type S = 'x' | 'y'
197199
defineProps<{
198-
[\`_\${T}_\${S}_\`]: string
200+
[K in \`_\${T}_\${S}_\`]: string
199201
}>()
200202
`).props,
201203
).toStrictEqual({

packages/compiler-sfc/src/script/resolveType.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,8 @@ function typeElementsToMap(
337337
}
338338
;(e as MaybeWithScope)._ownerScope = scope
339339
const name = getId(e.key)
340-
if (name && !e.computed) {
340+
if (name !== null) {
341341
res.props[name] = e as ResolvedElements['props'][string]
342-
} else if (e.key.type === 'TemplateLiteral') {
343-
for (const key of resolveTemplateKeys(ctx, e.key, scope)) {
344-
res.props[key] = e as ResolvedElements['props'][string]
345-
}
346342
} else {
347343
ctx.error(
348344
`Unsupported computed key in type referenced by a macro`,

packages/compiler-sfc/src/script/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export function getId(node: Expression) {
7676
? node.name
7777
: node.type === 'StringLiteral'
7878
? node.value
79-
: null
79+
: node.type === 'TemplateLiteral' && !node.expressions.length
80+
? node.quasis.map(q => q.value.cooked).join('')
81+
: null
8082
}
8183

8284
const identity = (str: string) => str

0 commit comments

Comments
 (0)