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

Fix: Label Functions and Methods declartions as Ambient (fixes #162) #163

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 14 additions & 2 deletions lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ module.exports = function(ast, extra) {
return modifier.kind === ts.SyntaxKind.DeclareKeyword;
});
if (isDeclareFunction) {
functionDeclarationType = "DeclareFunction";
functionDeclarationType = "TSAmbientFunctionDeclaration";
}
}

Expand Down Expand Up @@ -1074,6 +1074,7 @@ module.exports = function(ast, extra) {
// TODO: double-check that these positions are correct
var methodLoc = ast.getLineAndCharacterOfPosition(node.name.end + 1),
nodeIsMethod = (node.kind === SyntaxKind.MethodDeclaration),
isAmbient = ts.isInAmbientContext(node),
method = {
type: "FunctionExpression",
id: null,
Expand Down Expand Up @@ -1136,6 +1137,10 @@ module.exports = function(ast, extra) {
methodDefinitionType = "TSAbstractMethodDefinition";
}
}
if (isAmbient) {
methodDefinitionType = "TSAmbientMethodDefinition";
method.type = "TSAmbientFunctionExpression";
}

assign(result, {
type: methodDefinitionType,
Expand Down Expand Up @@ -1167,6 +1172,7 @@ module.exports = function(ast, extra) {
var constructorIsStatic = Boolean(node.flags & ts.NodeFlags.Static),
firstConstructorToken = constructorIsStatic ? ts.findNextToken(node.getFirstToken(), ast) : node.getFirstToken(),
constructorLoc = ast.getLineAndCharacterOfPosition(node.parameters.pos - 1),
constructorIsAmbient = ts.isInAmbientContext(node),
constructor = {
type: "FunctionExpression",
id: null,
Expand Down Expand Up @@ -1230,8 +1236,14 @@ module.exports = function(ast, extra) {
};
}

var constructorMethodDefinitionType = "MethodDefinition";
if (constructorIsAmbient) {
constructorMethodDefinitionType = "TSAmbientMethodDefinition";
constructor.type = "TSAmbientFunctionExpression";
}

assign(result, {
type: "MethodDefinition",
type: constructorMethodDefinitionType,
key: constructorKey,
value: constructor,
computed: constructorIsComputed,
Expand Down
Loading