diff --git a/packages/compiler-core/src/babelUtils.ts b/packages/compiler-core/src/babelUtils.ts index e773015f90f..5ddbc1ea412 100644 --- a/packages/compiler-core/src/babelUtils.ts +++ b/packages/compiler-core/src/babelUtils.ts @@ -38,9 +38,7 @@ export function walkIdentifiers( if ( parent && parent.type.startsWith('TS') && - parent.type !== 'TSAsExpression' && - parent.type !== 'TSNonNullExpression' && - parent.type !== 'TSTypeAssertion' + !TS_NODE_TYPES.includes(parent.type) ) { return this.skip() } @@ -422,3 +420,18 @@ function isReferenced(node: Node, parent: Node, grandparent?: Node): boolean { return true } + +export const TS_NODE_TYPES = [ + 'TSAsExpression', // foo as number + 'TSTypeAssertion', // (foo) + 'TSNonNullExpression', // foo! + 'TSInstantiationExpression', // foo + 'TSSatisfiesExpression' // foo satisfies T +] +export function unwrapTSNode(node: Node): Node { + if (TS_NODE_TYPES.includes(node.type)) { + return unwrapTSNode((node as any).expression) + } else { + return node + } +} diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 473ebd4e0b9..2748840cc5e 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1486,6 +1486,22 @@ return { emit } })" `; +exports[`SFC compile + `) + expect(content).toMatch(`props: ['foo']`) + assertCode(content) + expect(bindings).toStrictEqual({ + foo: BindingTypes.PROPS + }) + }) + test('withDefaults (static)', () => { const { content, bindings } = compile(`