Skip to content

Commit 00210e8

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 b5c0180 commit 00210e8

7 files changed

+1438
-3
lines changed

lib/ast-converter.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,10 @@ module.exports = function(ast, extra) {
10871087
// TODO: double-check that these positions are correct
10881088
var methodLoc = ast.getLineAndCharacterOfPosition(node.name.end + 1),
10891089
nodeIsMethod = (node.kind === SyntaxKind.MethodDeclaration),
1090+
isAmbient = ts.isInAmbientContext(node),
1091+
type = (!isAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
10901092
method = {
1091-
type: "FunctionExpression",
1093+
type: type,
10921094
id: null,
10931095
generator: false,
10941096
expression: false,
@@ -1149,6 +1151,9 @@ module.exports = function(ast, extra) {
11491151
methodDefinitionType = "TSAbstractMethodDefinition";
11501152
}
11511153
}
1154+
if (isAmbient) {
1155+
methodDefinitionType = "TSAmbientMethodDefinition";
1156+
}
11521157

11531158
assign(result, {
11541159
type: methodDefinitionType,
@@ -1180,8 +1185,10 @@ module.exports = function(ast, extra) {
11801185
var constructorIsStatic = Boolean(ts.getModifierFlags(node) & ts.ModifierFlags.Static),
11811186
firstConstructorToken = constructorIsStatic ? ts.findNextToken(node.getFirstToken(), ast) : node.getFirstToken(),
11821187
constructorLoc = ast.getLineAndCharacterOfPosition(node.parameters.pos - 1),
1188+
constructorIsAmbient = ts.isInAmbientContext(node),
1189+
constructorType = (!constructorIsAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
11831190
constructor = {
1184-
type: "FunctionExpression",
1191+
type: constructorType,
11851192
id: null,
11861193
params: node.parameters.map(function(param) {
11871194
var convertedParam = convertChild(param);
@@ -1244,7 +1251,7 @@ module.exports = function(ast, extra) {
12441251
}
12451252

12461253
assign(result, {
1247-
type: "MethodDefinition",
1254+
type: (!constructorIsAmbient) ? "MethodDefinition" : "TSAmbientMethodDefintion",
12481255
key: constructorKey,
12491256
value: constructor,
12501257
computed: constructorIsComputed,

0 commit comments

Comments
 (0)