summaryrefslogtreecommitdiff
path: root/tools/ts_library_builder/ast_util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ts_library_builder/ast_util.ts')
-rw-r--r--tools/ts_library_builder/ast_util.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/tools/ts_library_builder/ast_util.ts b/tools/ts_library_builder/ast_util.ts
index c13195b08..4590dcea5 100644
--- a/tools/ts_library_builder/ast_util.ts
+++ b/tools/ts_library_builder/ast_util.ts
@@ -47,12 +47,14 @@ export function addVariableDeclaration(
node: StatementedNode,
name: string,
type: string,
+ hasDeclareKeyword?: boolean,
jsdocs?: JSDoc[]
): VariableStatement {
return node.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
declarations: [{ name, type }],
- docs: jsdocs && jsdocs.map(jsdoc => jsdoc.getText())
+ docs: jsdocs && jsdocs.map(jsdoc => jsdoc.getText()),
+ hasDeclareKeyword
});
}
@@ -281,8 +283,17 @@ export function namespaceSourceFile(
}
});
+ // TODO need to properly unwrap this
const globalNamespace = sourceFile.getNamespace("global");
- const globalNamespaceText = globalNamespace && globalNamespace.print();
+ let globalNamespaceText = "";
+ if (globalNamespace) {
+ const structure = globalNamespace.getStructure();
+ if (structure.bodyText && typeof structure.bodyText === "string") {
+ globalNamespaceText = structure.bodyText;
+ } else {
+ throw new TypeError("Unexpected global declaration structure.");
+ }
+ }
if (globalNamespace) {
globalNamespace.remove();
}
@@ -319,7 +330,8 @@ export function namespaceSourceFile(
return `${output}
${globalNamespaceText || ""}
- namespace ${namespace} {
+
+ declare namespace ${namespace} {
${debug ? getSourceComment(sourceFile, rootPath) : ""}
${sourceFile.getText()}
}`;