Skip to content

Commit 5adb9ad

Browse files
committed
Fix: Use TSAbsractMethodDefinition for abstract constructor (fixes eslint#228)
1 parent 9397c5c commit 5adb9ad

File tree

3 files changed

+376
-9
lines changed

3 files changed

+376
-9
lines changed

lib/ast-converter.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ function isAsyncFunction(node) {
116116
});
117117
}
118118

119+
/**
120+
* Returns true if the given TSNode has the AbstractKeyword modifier.
121+
* @param {TSNode} node TypeScript AST node
122+
* @returns {boolean} has abstract modifier
123+
*/
124+
function isAbstract(node) {
125+
return !!node.modifiers && node.modifiers.some(function(modifier) {
126+
return modifier.kind === ts.SyntaxKind.AbstractKeyword;
127+
});
128+
}
129+
119130
/**
120131
* Returns true if the given TSToken is a comma
121132
* @param {TSToken} token the TypeScript token
@@ -1164,10 +1175,7 @@ module.exports = function(ast, extra) {
11641175
*/
11651176
var methodDefinitionType = "MethodDefinition";
11661177
if (node.modifiers && node.modifiers.length) {
1167-
var isAbstractMethod = node.modifiers.some(function(modifier) {
1168-
return modifier.kind === ts.SyntaxKind.AbstractKeyword;
1169-
});
1170-
if (isAbstractMethod) {
1178+
if (isAbstract(node)) {
11711179
methodDefinitionType = "TSAbstractMethodDefinition";
11721180
}
11731181
}
@@ -1206,6 +1214,7 @@ module.exports = function(ast, extra) {
12061214
case SyntaxKind.Constructor:
12071215

12081216
var constructorIsStatic = Boolean(ts.getModifierFlags(node) & ts.ModifierFlags.Static),
1217+
constructorIsAbstract = isAbstract(node),
12091218
firstConstructorToken = constructorIsStatic ? ts.findNextToken(node.getFirstToken(), ast) : node.getFirstToken(),
12101219
constructorLoc = ast.getLineAndCharacterOfPosition(node.parameters.pos - 1),
12111220
constructor = {
@@ -1275,7 +1284,7 @@ module.exports = function(ast, extra) {
12751284
}
12761285

12771286
assign(result, {
1278-
type: "MethodDefinition",
1287+
type: constructorIsAbstract ? "TSAbstractMethodDefinition" : "MethodDefinition",
12791288
key: constructorKey,
12801289
value: constructor,
12811290
computed: constructorIsComputed,
@@ -1533,10 +1542,7 @@ module.exports = function(ast, extra) {
15331542
* TypeScript class declarations can be defined as "abstract"
15341543
*/
15351544
if (node.kind === SyntaxKind.ClassDeclaration) {
1536-
var isAbstractClass = node.modifiers.some(function(modifier) {
1537-
return modifier.kind === ts.SyntaxKind.AbstractKeyword;
1538-
});
1539-
if (isAbstractClass) {
1545+
if (isAbstract(node)) {
15401546
classNodeType = "TSAbstract" + classNodeType;
15411547
}
15421548
}

0 commit comments

Comments
 (0)