Skip to content

Commit 673d42e

Browse files
committed
Fix: Label Function and Method declartions as Ambient (fixes eslint#162)
1 parent 1b1dd88 commit 673d42e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/ast-converter.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,10 @@ module.exports = function(ast, extra) {
10981098
// TODO: double-check that these positions are correct
10991099
var methodLoc = ast.getLineAndCharacterOfPosition(node.name.end + 1),
11001100
nodeIsMethod = (node.kind === SyntaxKind.MethodDeclaration),
1101+
isAmbient = ts.isInAmbientContext(node),
1102+
type = (!isAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
11011103
method = {
1102-
type: "FunctionExpression",
1104+
type: type,
11031105
id: null,
11041106
generator: false,
11051107
expression: false,
@@ -1160,6 +1162,9 @@ module.exports = function(ast, extra) {
11601162
methodDefinitionType = "TSAbstractMethodDefinition";
11611163
}
11621164
}
1165+
if (isAmbient) {
1166+
methodDefinitionType = "TSAmbientMethodDefinition";
1167+
}
11631168

11641169
assign(result, {
11651170
type: methodDefinitionType,
@@ -1191,8 +1196,10 @@ module.exports = function(ast, extra) {
11911196
var constructorIsStatic = Boolean(ts.getModifierFlags(node) & ts.ModifierFlags.Static),
11921197
firstConstructorToken = constructorIsStatic ? ts.findNextToken(node.getFirstToken(), ast) : node.getFirstToken(),
11931198
constructorLoc = ast.getLineAndCharacterOfPosition(node.parameters.pos - 1),
1199+
constructorIsAmbient = ts.isInAmbientContext(node),
1200+
constructorType = (!constructorIsAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
11941201
constructor = {
1195-
type: "FunctionExpression",
1202+
type: constructorType,
11961203
id: null,
11971204
params: node.parameters.map(function(param) {
11981205
var convertedParam = convertChild(param);
@@ -1255,7 +1262,7 @@ module.exports = function(ast, extra) {
12551262
}
12561263

12571264
assign(result, {
1258-
type: "MethodDefinition",
1265+
type: (!constructorIsAmbient) ? "MethodDefinition" : "TSAmbientMethodDefintion",
12591266
key: constructorKey,
12601267
value: constructor,
12611268
computed: constructorIsComputed,

0 commit comments

Comments
 (0)