Skip to content

Commit 8923062

Browse files
committed
Fix: Label Functions and Methods declartions as Ambient (fixes eslint#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 8923062

7 files changed

+1438
-3
lines changed

lib/ast-converter.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -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)