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

Commit da6769e

Browse files
committed
Fix: Label Functions and Methods declartions as Ambient (fixes #162)
Ambient functions do not have a body and will cuase rules to throw an excpetion. We use the types TSAmbientFunctionExpression and TSAmbientMethoDeclaration.
1 parent 76c33f8 commit da6769e

8 files changed

+1441
-6
lines changed

lib/ast-converter.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ module.exports = function(ast, extra) {
875875
return modifier.kind === ts.SyntaxKind.DeclareKeyword;
876876
});
877877
if (isDeclareFunction) {
878-
functionDeclarationType = "DeclareFunction";
878+
functionDeclarationType = "TSAmbientFunctionDeclaration";
879879
}
880880
}
881881

@@ -1074,8 +1074,10 @@ module.exports = function(ast, extra) {
10741074
// TODO: double-check that these positions are correct
10751075
var methodLoc = ast.getLineAndCharacterOfPosition(node.name.end + 1),
10761076
nodeIsMethod = (node.kind === SyntaxKind.MethodDeclaration),
1077+
isAmbient = ts.isInAmbientContext(node),
1078+
type = (!isAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
10771079
method = {
1078-
type: "FunctionExpression",
1080+
type: type,
10791081
id: null,
10801082
generator: false,
10811083
expression: false,
@@ -1136,6 +1138,9 @@ module.exports = function(ast, extra) {
11361138
methodDefinitionType = "TSAbstractMethodDefinition";
11371139
}
11381140
}
1141+
if (isAmbient) {
1142+
methodDefinitionType = "TSAmbientMethodDefinition";
1143+
}
11391144

11401145
assign(result, {
11411146
type: methodDefinitionType,
@@ -1167,8 +1172,10 @@ module.exports = function(ast, extra) {
11671172
var constructorIsStatic = Boolean(node.flags & ts.NodeFlags.Static),
11681173
firstConstructorToken = constructorIsStatic ? ts.findNextToken(node.getFirstToken(), ast) : node.getFirstToken(),
11691174
constructorLoc = ast.getLineAndCharacterOfPosition(node.parameters.pos - 1),
1175+
constructorIsAmbient = ts.isInAmbientContext(node),
1176+
constructorType = (!constructorIsAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
11701177
constructor = {
1171-
type: "FunctionExpression",
1178+
type: constructorType,
11721179
id: null,
11731180
params: node.parameters.map(function(param) {
11741181
var convertedParam = convertChild(param);
@@ -1231,7 +1238,7 @@ module.exports = function(ast, extra) {
12311238
}
12321239

12331240
assign(result, {
1234-
type: "MethodDefinition",
1241+
type: (!constructorIsAmbient) ? "MethodDefinition" : "TSAmbientMethodDefintion",
12351242
key: constructorKey,
12361243
value: constructor,
12371244
computed: constructorIsComputed,

0 commit comments

Comments
 (0)