diff --git a/lib/ast-converter.js b/lib/ast-converter.js index 76805fc..7cc35a6 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -1087,8 +1087,10 @@ module.exports = function(ast, extra) { break; case SyntaxKind.PropertyDeclaration: + var isAbstract = hasModifier(SyntaxKind.AbstractKeyword, node); + assign(result, { - type: "ClassProperty", + type: (isAbstract) ? "TSAbstractClassProperty" : "ClassProperty", key: convertChild(node.name), value: convertChild(node.initializer), computed: (node.name.kind === SyntaxKind.ComputedPropertyName), diff --git a/tests/fixtures/typescript/basics/abstract-class-with-abstract-properties.result.js b/tests/fixtures/typescript/basics/abstract-class-with-abstract-properties.result.js new file mode 100644 index 0000000..d5b3cbc --- /dev/null +++ b/tests/fixtures/typescript/basics/abstract-class-with-abstract-properties.result.js @@ -0,0 +1,413 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 62 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "TSAbstractClassDeclaration", + "range": [ + 0, + 62 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "Foo" + }, + "body": { + "type": "ClassBody", + "body": [ + { + "type": "TSAbstractClassProperty", + "range": [ + 25, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "key": { + "type": "Identifier", + "range": [ + 34, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "name": "bar" + }, + "value": null, + "computed": false, + "static": false, + "accessibility": null, + "decorators": [], + "typeAnnotation": null + }, + { + "type": "TSAbstractClassProperty", + "range": [ + 43, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "key": { + "type": "Identifier", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "name": "baz" + }, + "value": { + "type": "Literal", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "value": 3, + "raw": "3" + }, + "computed": false, + "static": false, + "accessibility": null, + "decorators": [], + "typeAnnotation": null + } + ], + "range": [ + 19, + 62 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "decorators": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "abstract", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "class", + "range": [ + 9, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "abstract", + "range": [ + 25, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 34, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "abstract", + "range": [ + 43, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "baz", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Numeric", + "value": "3", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/abstract-class-with-abstract-properties.src.ts b/tests/fixtures/typescript/basics/abstract-class-with-abstract-properties.src.ts new file mode 100644 index 0000000..4212895 --- /dev/null +++ b/tests/fixtures/typescript/basics/abstract-class-with-abstract-properties.src.ts @@ -0,0 +1,4 @@ +abstract class Foo { + abstract bar; + abstract baz = 3; +}