Skip to content

Commit 34aea67

Browse files
author
Alexander Gräfenstein
committed
generate default export
1 parent 8cae5d5 commit 34aea67

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ interface btDbvtBroadphase: btBroadphaseInterface {
104104
Its basically the following wrapper
105105

106106
```.ts
107-
declate function Ammo(): Promise<void>
108-
declare module Ammo {
107+
export default Ammo;
108+
export declate function Ammo(): Promise<void>
109+
export declare module Ammo {
109110
function destroy(value: any): void;
110111

111112
// ... generated from IDL

ammo/ammo.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
declare function Ammo(): Promise<void>;
2-
declare module Ammo {
1+
export default Ammo;
2+
export declare function Ammo(): Promise<void>;
3+
export declare module Ammo {
34
function destroy(obj: any): void;
45
class btIDebugDraw {
56
drawLine(from: btVector3, to: btVector3, color: btVector3): void;

lib/converter.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ export function convertIDL(rootTypes: webidl2.IDLRootType[]) {
1919
}
2020
}
2121

22-
// declare function Ammo(): Promise<void>;
22+
const ammoDefault = ts.createExportAssignment([], [], false, ts.createIdentifier('Ammo'))
23+
// export declare function Ammo(): Promise<void>;
2324
const ammoPromise = ts.createFunctionDeclaration(
2425
/* decorators */[],
25-
/* modifiers */[ts.createModifier(ts.SyntaxKind.DeclareKeyword)],
26+
/* modifiers */[ts.createModifier(ts.SyntaxKind.ExportKeyword), ts.createModifier(ts.SyntaxKind.DeclareKeyword)],
2627
/* asteriskToken */ undefined,
2728
/* name */ 'Ammo',
2829
/* typeParameters */[],
@@ -41,15 +42,18 @@ export function convertIDL(rootTypes: webidl2.IDLRootType[]) {
4142
/* type */ ts.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),
4243
/* body */ undefined
4344
)
44-
// declare module Ammo { ... }
45-
const ammo = ts.createModuleDeclaration(
45+
// export declare module Ammo { ... }
46+
const ammoModule = ts.createModuleDeclaration(
4647
/* decorators */[],
47-
/* modifiers */[ts.createModifier(ts.SyntaxKind.DeclareKeyword)],
48+
/* modifiers */[ts.createModifier(ts.SyntaxKind.ExportKeyword), ts.createModifier(ts.SyntaxKind.DeclareKeyword)],
4849
/* name */ ts.createIdentifier('Ammo'),
4950
/* body */ ts.createModuleBlock([ammoDestroy, ...nodes])
5051
)
5152

52-
return [printer.printNode(ts.EmitHint.Unspecified, ammoPromise, file), printer.printNode(ts.EmitHint.Unspecified, ammo, file)].join('\n')
53+
return [
54+
printer.printNode(ts.EmitHint.Unspecified, ammoDefault, file),
55+
printer.printNode(ts.EmitHint.Unspecified, ammoPromise, file),
56+
printer.printNode(ts.EmitHint.Unspecified, ammoModule, file)].join('\n')
5357
}
5458

5559
function convertInterface(idl: webidl2.InterfaceType) {

0 commit comments

Comments
 (0)