mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): support global augments with named exports (#13789)
This commit is contained in:
parent
8f6b505051
commit
35da3c6dcb
|
@ -1342,6 +1342,33 @@ describe('resolveType', () => {
|
||||||
expect(deps && [...deps]).toStrictEqual(Object.keys(files))
|
expect(deps && [...deps]).toStrictEqual(Object.keys(files))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('global types with named exports', () => {
|
||||||
|
const files = {
|
||||||
|
'/global.d.ts': `
|
||||||
|
declare global {
|
||||||
|
export interface ExportedInterface { foo: number }
|
||||||
|
export type ExportedType = { bar: boolean }
|
||||||
|
}
|
||||||
|
export {}
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalTypeFiles = { globalTypeFiles: Object.keys(files) }
|
||||||
|
|
||||||
|
expect(
|
||||||
|
resolve(`defineProps<ExportedInterface>()`, files, globalTypeFiles)
|
||||||
|
.props,
|
||||||
|
).toStrictEqual({
|
||||||
|
foo: ['Number'],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(
|
||||||
|
resolve(`defineProps<ExportedType>()`, files, globalTypeFiles).props,
|
||||||
|
).toStrictEqual({
|
||||||
|
bar: ['Boolean'],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('global types with ambient references', () => {
|
test('global types with ambient references', () => {
|
||||||
const files = {
|
const files = {
|
||||||
// with references
|
// with references
|
||||||
|
|
|
@ -1296,7 +1296,12 @@ function recordTypes(
|
||||||
}
|
}
|
||||||
} else if (stmt.type === 'TSModuleDeclaration' && stmt.global) {
|
} else if (stmt.type === 'TSModuleDeclaration' && stmt.global) {
|
||||||
for (const s of (stmt.body as TSModuleBlock).body) {
|
for (const s of (stmt.body as TSModuleBlock).body) {
|
||||||
recordType(s, types, declares)
|
if (s.type === 'ExportNamedDeclaration' && s.declaration) {
|
||||||
|
// Handle export declarations inside declare global
|
||||||
|
recordType(s.declaration, types, declares)
|
||||||
|
} else {
|
||||||
|
recordType(s, types, declares)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue