diff --git a/lib/convert.js b/lib/convert.js index ce4ffa9..083c278 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1703,6 +1703,7 @@ module.exports = function convert(config) { } const hasImplementsClause = interfaceHeritageClauses.length > 0; + const hasAbstractKeyword = nodeUtils.hasModifier(SyntaxKind.AbstractKeyword, node); const interfaceOpenBrace = nodeUtils.findNextToken(interfaceLastClassToken, ast); const interfaceBody = { @@ -1713,11 +1714,16 @@ module.exports = function convert(config) { }; Object.assign(result, { + abstract: hasAbstractKeyword, type: AST_NODE_TYPES.TSInterfaceDeclaration, body: interfaceBody, id: convertChild(node.name), heritage: hasImplementsClause ? interfaceHeritageClauses[0].types.map(convertInterfaceHeritageClause) : [] }); + + // check for exports + result = nodeUtils.fixExports(node, result, ast); + break; } diff --git a/tests/fixtures/typescript/basics/abstract-interface.result.js b/tests/fixtures/typescript/basics/abstract-interface.result.js new file mode 100644 index 0000000..e7576a7 --- /dev/null +++ b/tests/fixtures/typescript/basics/abstract-interface.result.js @@ -0,0 +1,204 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "body": [ + { + "type": "ExportNamedDeclaration", + "declaration": { + "type": "TSInterfaceDeclaration", + "range": [ + 16, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "abstract": true, + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 28, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "name": "I" + }, + "heritage": [] + }, + "range": [ + 0, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + }, + "specifiers": [], + "source": null + } + ], + "sourceType": "module", + "tokens": [ + { + "type": "Keyword", + "value": "export", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "abstract", + "range": [ + 7, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "Keyword", + "value": "interface", + "range": [ + 16, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "I", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/abstract-interface.src.ts b/tests/fixtures/typescript/basics/abstract-interface.src.ts new file mode 100644 index 0000000..8fafeca --- /dev/null +++ b/tests/fixtures/typescript/basics/abstract-interface.src.ts @@ -0,0 +1,2 @@ +export abstract interface I { +} \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-mixin.result.js b/tests/fixtures/typescript/basics/class-with-mixin.result.js index c5864a6..02b1f01 100644 --- a/tests/fixtures/typescript/basics/class-with-mixin.result.js +++ b/tests/fixtures/typescript/basics/class-with-mixin.result.js @@ -301,59 +301,59 @@ module.exports = { "name": "Constructor" }, "typeParameters": { + "type": "TypeParameterInstantiation", + "range": [ + 32, + 36 + ], "loc": { - "end": { - "column": 36, - "line": 1 - }, "start": { - "column": 32, - "line": 1 + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 36 } }, "params": [ { - "id": { - "loc": { - "end": { - "column": 35, - "line": 1 - }, - "start": { - "column": 33, - "line": 1 - } + "type": "GenericTypeAnnotation", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 33 }, - "members": [], + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "TSTypeLiteral", "range": [ 33, 35 ], - "type": "TSTypeLiteral" - }, - "loc": { - "end": { - "column": 35, - "line": 1 + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } }, - "start": { - "column": 33, - "line": 1 - } + "members": [] }, - "range": [ - 33, - 35 - ], - "type": "GenericTypeAnnotation", "typeParameters": null } - ], - "range": [ - 32, - 36 - ], - "type": "TypeParameterInstantiation" + ] } } } @@ -633,6 +633,7 @@ module.exports = { "column": 15 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [], @@ -691,7 +692,6 @@ module.exports = { "declarations": [ { "type": "VariableDeclarator", - "typeParameters": null, "id": { "type": "Identifier", "range": [ @@ -726,6 +726,7 @@ module.exports = { "column": 47 } }, + "typeParameters": null, "parameters": [ { "type": "RestElement", @@ -814,7 +815,6 @@ module.exports = { } } ], - "typeParameters": null, "typeAnnotation": { "type": "TypeAnnotation", "loc": { @@ -2079,4 +2079,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-extends-multiple.result.js b/tests/fixtures/typescript/basics/interface-extends-multiple.result.js index ba61eda..0ea4e1e 100644 --- a/tests/fixtures/typescript/basics/interface-extends-multiple.result.js +++ b/tests/fixtures/typescript/basics/interface-extends-multiple.result.js @@ -31,6 +31,7 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [], @@ -288,4 +289,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-extends.result.js b/tests/fixtures/typescript/basics/interface-extends.result.js index b09ee67..b898968 100644 --- a/tests/fixtures/typescript/basics/interface-extends.result.js +++ b/tests/fixtures/typescript/basics/interface-extends.result.js @@ -31,6 +31,7 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [], @@ -217,4 +218,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-type-parameters.result.js b/tests/fixtures/typescript/basics/interface-type-parameters.result.js index 0e29b4a..fd51c55 100644 --- a/tests/fixtures/typescript/basics/interface-type-parameters.result.js +++ b/tests/fixtures/typescript/basics/interface-type-parameters.result.js @@ -69,6 +69,7 @@ module.exports = { } ] }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [], @@ -237,4 +238,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js b/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js index 657caa5..bbf54d5 100644 --- a/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js +++ b/tests/fixtures/typescript/basics/interface-with-construct-signature-with-parameter-accessibility.result.js @@ -31,12 +31,12 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [ { "type": "TSConstructSignature", - "typeParameters": null, "range": [ 21, 47 @@ -51,6 +51,7 @@ module.exports = { "column": 30 } }, + "typeParameters": null, "parameters": [ { "type": "TSParameterProperty", @@ -402,4 +403,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.result.js b/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.result.js index 59505ce..6f09883 100644 --- a/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.result.js +++ b/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.result.js @@ -69,6 +69,7 @@ module.exports = { } ] }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [], @@ -418,4 +419,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-with-generic.result.js b/tests/fixtures/typescript/basics/interface-with-generic.result.js index 55d39eb..ab72816 100644 --- a/tests/fixtures/typescript/basics/interface-with-generic.result.js +++ b/tests/fixtures/typescript/basics/interface-with-generic.result.js @@ -1,240 +1,241 @@ module.exports = { + "type": "Program", + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + }, "body": [ { - "body": { - "body": [], - "loc": { - "end": { - "column": 1, - "line": 2 - }, - "start": { - "column": 18, - "line": 1 - } - }, - "range": [ - 18, - 21 - ], - "type": "TSInterfaceBody" - }, - "heritage": [], - "id": { - "loc": { - "end": { - "column": 14, - "line": 1 - }, - "start": { - "column": 10, - "line": 1 - } - }, - "name": "Test", - "range": [ - 10, - 14 - ], - "type": "Identifier" - }, - "loc": { - "end": { - "column": 1, - "line": 2 - }, - "start": { - "column": 0, - "line": 1 - } - }, + "type": "TSInterfaceDeclaration", "range": [ 0, 21 ], - "type": "TSInterfaceDeclaration", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + }, "typeParameters": { + "type": "TypeParameterDeclaration", + "range": [ + 14, + 17 + ], "loc": { - "end": { - "column": 17, - "line": 1 - }, "start": { - "column": 14, - "line": 1 + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 } }, "params": [ { - "constraint": null, + "type": "TypeParameter", + "range": [ + 15, + 16 + ], "loc": { - "end": { - "column": 16, - "line": 1 - }, "start": { - "column": 15, - "line": 1 + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 } }, "name": "T", - "range": [ - 15, - 16 - ], - "type": "TypeParameter" + "constraint": null } + ] + }, + "abstract": false, + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 18, + 21 ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", "range": [ - 14, - 17 + 10, + 14 ], - "type": "TypeParameterDeclaration" - } - } - ], - "loc": { - "end": { - "column": 1, - "line": 2 - }, - "start": { - "column": 0, - "line": 1 + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "Test" + }, + "heritage": [] } - }, - "range": [ - 0, - 21 ], "sourceType": "script", "tokens": [ { - "loc": { - "end": { - "column": 9, - "line": 1 - }, - "start": { - "column": 0, - "line": 1 - } - }, + "type": "Keyword", + "value": "interface", "range": [ 0, 9 ], - "type": "Keyword", - "value": "interface" - }, - { "loc": { - "end": { - "column": 14, - "line": 1 - }, "start": { - "column": 10, - "line": 1 + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 } - }, + } + }, + { + "type": "Identifier", + "value": "Test", "range": [ 10, 14 ], - "type": "Identifier", - "value": "Test" - }, - { "loc": { - "end": { - "column": 15, - "line": 1 - }, "start": { - "column": 14, - "line": 1 + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 } - }, + } + }, + { + "type": "Punctuator", + "value": "<", "range": [ 14, 15 ], - "type": "Punctuator", - "value": "<" - }, - { "loc": { - "end": { - "column": 16, - "line": 1 - }, "start": { - "column": 15, - "line": 1 + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 } - }, + } + }, + { + "type": "Identifier", + "value": "T", "range": [ 15, 16 ], - "type": "Identifier", - "value": "T" - }, - { "loc": { - "end": { - "column": 17, - "line": 1 - }, "start": { - "column": 16, - "line": 1 + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 } - }, + } + }, + { + "type": "Punctuator", + "value": ">", "range": [ 16, 17 ], - "type": "Punctuator", - "value": ">" - }, - { "loc": { - "end": { - "column": 19, - "line": 1 - }, "start": { - "column": 18, - "line": 1 + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 } - }, + } + }, + { + "type": "Punctuator", + "value": "{", "range": [ 18, 19 ], - "type": "Punctuator", - "value": "{" - }, - { "loc": { - "end": { - "column": 1, - "line": 2 - }, "start": { - "column": 0, - "line": 2 + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 } - }, + } + }, + { + "type": "Punctuator", + "value": "}", "range": [ 20, 21 ], - "type": "Punctuator", - "value": "}" + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } } - ], - "type": "Program" -}; + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js b/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js index 0732fc5..b86ccc5 100644 --- a/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js +++ b/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js @@ -31,12 +31,12 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [ { "type": "TSMethodSignature", - "typeParameters": null, "range": [ 76, 85 @@ -69,6 +69,7 @@ module.exports = { }, "name": "foo" }, + "typeParameters": null, "parameters": [ { "type": "Identifier", @@ -670,4 +671,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-with-optional-properties.result.js b/tests/fixtures/typescript/basics/interface-with-optional-properties.result.js index 46c4fcf..8944766 100644 --- a/tests/fixtures/typescript/basics/interface-with-optional-properties.result.js +++ b/tests/fixtures/typescript/basics/interface-with-optional-properties.result.js @@ -31,6 +31,7 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [ @@ -177,7 +178,6 @@ module.exports = { }, { "type": "TSMethodSignature", - "typeParameters": null, "range": [ 49, 79 @@ -228,6 +228,7 @@ module.exports = { } } }, + "typeParameters": null, "parameters": [ { "type": "Identifier", @@ -829,4 +830,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/interface-without-type-annotation.result.js b/tests/fixtures/typescript/basics/interface-without-type-annotation.result.js index 83f82de..1d48625 100644 --- a/tests/fixtures/typescript/basics/interface-without-type-annotation.result.js +++ b/tests/fixtures/typescript/basics/interface-without-type-annotation.result.js @@ -31,6 +31,7 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [ @@ -218,4 +219,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/typed-this.result.js b/tests/fixtures/typescript/basics/typed-this.result.js index 74a7d17..4bfa9e8 100644 --- a/tests/fixtures/typescript/basics/typed-this.result.js +++ b/tests/fixtures/typescript/basics/typed-this.result.js @@ -31,6 +31,7 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [ @@ -68,6 +69,7 @@ module.exports = { }, "name": "addClickListener" }, + "typeParameters": null, "parameters": [ { "type": "Identifier", @@ -118,6 +120,7 @@ module.exports = { "column": 57 } }, + "typeParameters": null, "parameters": [ { "type": "Identifier", @@ -275,8 +278,7 @@ module.exports = { } } } - }, - "typeParameters": null + } } } } @@ -314,8 +316,7 @@ module.exports = { } } } - }, - "typeParameters": null + } } ], "range": [ @@ -771,4 +772,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/errorRecovery/interface-empty-extends.result.js b/tests/fixtures/typescript/errorRecovery/interface-empty-extends.result.js index 2561f9e..9481511 100644 --- a/tests/fixtures/typescript/errorRecovery/interface-empty-extends.result.js +++ b/tests/fixtures/typescript/errorRecovery/interface-empty-extends.result.js @@ -31,6 +31,7 @@ module.exports = { "column": 1 } }, + "abstract": false, "body": { "type": "TSInterfaceBody", "body": [], @@ -163,4 +164,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tools/update-typescript-tests.js b/tools/update-typescript-tests.js index 618002a..e8c620f 100644 --- a/tools/update-typescript-tests.js +++ b/tools/update-typescript-tests.js @@ -17,6 +17,7 @@ var shelljs = require("shelljs"), parser = require("../parser"), + tester = require("../tests/lib/tester"), path = require("path"); //------------------------------------------------------------------------------ @@ -35,7 +36,7 @@ function getRaw(ast) { function getExpectedResult(code, config) { try { - return getRaw(parser.parse(code, config)); + return tester.getRaw(parser.parse(code, config)); } catch (ex) { var raw = getRaw(ex); raw.message = ex.message; @@ -52,7 +53,7 @@ function getTestFilenames(directory) { } function outputResult(result, testResultFilename) { - ("module.exports = " + JSON.stringify(result, null, " ") + ";").to(testResultFilename); + shelljs.echo("module.exports = " + JSON.stringify(result, null, " ") + ";").to(testResultFilename); } //------------------------------------------------------------------------------ @@ -72,7 +73,9 @@ testFiles.forEach(function(filename) { config = { loc: true, range: true, - tokens: true + tokens: true, + ecmaFeatures: {}, + errorOnUnknownASTType: true }; var testResultFilename = path.resolve(__dirname, "..", FIXTURES_DIR, filename) + ".result.js";