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

Fix: Prefix function declarations in TS namespaces (fixes #78) #82

Merged
merged 2 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,18 @@ function fixExports(node, result, ast) {
result.range[0] = varToken.getStart();
result.loc = getLocFor(result.range[0], result.range[1], ast);

var declarationType = declarationIsDefault ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";

/**
* Prefix exports from TypeScript namespaces with "TS" to distinguish
* them from ES2015 exports
*/
if (node.parent && node.parent.kind === SyntaxKind.ModuleBlock) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should be more specific with these names.

TSNamespaceExportDeclaration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

declarationType = "TSNamespaceExportDeclaration";
}

var newResult = {
type: declarationIsDefault ? "ExportDefaultDeclaration" : "ExportNamedDeclaration",
type: declarationType,
declaration: result,
range: [ exportKeyword.getStart(), result.range[1] ],
loc: getLocFor(exportKeyword.getStart(), result.range[1], ast)
Expand Down Expand Up @@ -776,6 +786,13 @@ module.exports = function(ast, extra) {
}
}

/**
* Prefix FunctionDeclarations within TypeScript namespaces with "TS"
*/
if (node.parent && node.parent.kind === SyntaxKind.ModuleBlock) {
functionDeclarationType = "TSNamespaceFunctionDeclaration";
}

assign(result, {
type: functionDeclarationType,
id: convertChild(node.name),
Expand Down
Loading