Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit ac0c95d

Browse files
JamesHenrynzakas
authored andcommitted
Fix: Prefix function declarations in TS namespaces (fixes #78) (#82)
* Fix: Prefix function declarations in TS namespaces (fixes #78) * Improve the new type namespaces
1 parent 7cc865e commit ac0c95d

File tree

3 files changed

+611
-1
lines changed

3 files changed

+611
-1
lines changed

lib/ast-converter.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,18 @@ function fixExports(node, result, ast) {
215215
result.range[0] = varToken.getStart();
216216
result.loc = getLocFor(result.range[0], result.range[1], ast);
217217

218+
var declarationType = declarationIsDefault ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
219+
220+
/**
221+
* Prefix exports from TypeScript namespaces with "TS" to distinguish
222+
* them from ES2015 exports
223+
*/
224+
if (node.parent && node.parent.kind === SyntaxKind.ModuleBlock) {
225+
declarationType = "TSNamespaceExportDeclaration";
226+
}
227+
218228
var newResult = {
219-
type: declarationIsDefault ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
229+
type: declarationType,
220230
declaration: result,
221231
range: [ exportKeyword.getStart(), result.range[1] ],
222232
loc: getLocFor(exportKeyword.getStart(), result.range[1], ast)
@@ -776,6 +786,13 @@ module.exports = function(ast, extra) {
776786
}
777787
}
778788

789+
/**
790+
* Prefix FunctionDeclarations within TypeScript namespaces with "TS"
791+
*/
792+
if (node.parent && node.parent.kind === SyntaxKind.ModuleBlock) {
793+
functionDeclarationType = "TSNamespaceFunctionDeclaration";
794+
}
795+
779796
assign(result, {
780797
type: functionDeclarationType,
781798
id: convertChild(node.name),

0 commit comments

Comments
 (0)