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

Commit

Permalink
Fix: Label Functions and Methods declartions as Ambient (fixes #162)
Browse files Browse the repository at this point in the history
Ambient functions do not have a body and will cuase rules to throw
an excpetion. We use the types TSAmbientFunctionExpression and
TSAmbientMethoDeclaration.
  • Loading branch information
soda0289 committed Feb 20, 2017
1 parent 76c33f8 commit da6769e
Show file tree
Hide file tree
Showing 8 changed files with 1,441 additions and 6 deletions.
15 changes: 11 additions & 4 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,8 +1074,10 @@ 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),
type = (!isAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
method = {
type: "FunctionExpression",
type: type,
id: null,
generator: false,
expression: false,
Expand Down Expand Up @@ -1136,6 +1138,9 @@ module.exports = function(ast, extra) {
methodDefinitionType = "TSAbstractMethodDefinition";
}
}
if (isAmbient) {
methodDefinitionType = "TSAmbientMethodDefinition";
}

assign(result, {
type: methodDefinitionType,
Expand Down Expand Up @@ -1167,8 +1172,10 @@ 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),
constructorType = (!constructorIsAmbient) ? "FunctionExpression" : "TSAmbientFunctionExpression",
constructor = {
type: "FunctionExpression",
type: constructorType,
id: null,
params: node.parameters.map(function(param) {
var convertedParam = convertChild(param);
Expand Down Expand Up @@ -1231,7 +1238,7 @@ module.exports = function(ast, extra) {
}

assign(result, {
type: "MethodDefinition",
type: (!constructorIsAmbient) ? "MethodDefinition" : "TSAmbientMethodDefintion",
key: constructorKey,
value: constructor,
computed: constructorIsComputed,
Expand Down
Loading

0 comments on commit da6769e

Please sign in to comment.