Visitar URL original
fix(fake-js): support sub-namespaces · sxzz/rolldown-plugin-dts@14bcec1 · GitHub
Skip to content

Commit 14bcec1

Browse files
committed
fix(fake-js): support sub-namespaces
closes rolldown/tsdown#723
1 parent fa4282e commit 14bcec1

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎src/fake-js.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,18 @@ export function createFakeJsPlugin({
200200
)
201201
} else if ('id' in decl && decl.id) {
202202
let binding = decl.id
203+
if (binding.type === 'TSQualifiedName') {
204+
binding = getIdFromTSEntityName(binding)
205+
}
206+
203207
binding = sideEffect
204208
? t.identifier(`_${getIdentifierIndex('')}`)
205-
: (binding as t.Identifier)
209+
: binding
210+
211+
if (binding.type !== 'Identifier') {
212+
throw new Error(`Unexpected ${binding.type} declaration id`)
213+
}
214+
206215
bindings.push(binding)
207216
} else {
208217
const binding = t.identifier('export_default')

‎tests/__snapshots__/index.test.ts.snap‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,16 @@ declare global {
381381
}"
382382
`;
383383
384+
exports[`sub namespace 1`] = `
385+
"// sub-namespace.d.ts
386+
//#region tests/fixtures/sub-namespace.d.ts
387+
declare namespace Foo.Bar {
388+
export {};
389+
}
390+
//#endregion
391+
export { Foo };"
392+
`;
393+
384394
exports[`tree-shaking 1`] = `
385395
"// index.d.ts
386396
//#region tests/fixtures/tree-shaking/mod.d.ts

‎tests/fixtures/sub-namespace.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export namespace Foo.Bar {}

‎tests/index.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,11 @@ test('tsgo with custom path', async () => {
528528
)
529529
expect(snapshot).toMatchSnapshot()
530530
})
531+
532+
test('sub namespace', async () => {
533+
const { snapshot } = await rolldownBuild(
534+
path.resolve(dirname, 'fixtures/sub-namespace.ts'),
535+
[dts({ emitDtsOnly: true })],
536+
)
537+
expect(snapshot).toMatchSnapshot()
538+
})

0 commit comments

Comments
 (0)