diff --git a/lib/ast-converter.js b/lib/ast-converter.js index dbd2dd5..aeaa88d 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -676,6 +676,25 @@ module.exports = function(ast, extra) { return classImplementsNode; } + /** + * Converts a child into a interface heritage node. + * @param {TSNode} child The TypeScript AST node to convert. + * @returns {ESTreeNode} The type annotation node. + */ + function convertInterfaceHeritageClause(child) { + var id = convertChild(child.expression); + var classImplementsNode = { + type: "TSInterfaceHeritage", + loc: id.loc, + range: id.range, + id: id + }; + if (child.typeArguments && child.typeArguments.length) { + classImplementsNode.typeParameters = convertTypeArgumentsToTypeParameters(child.typeArguments); + } + return classImplementsNode; + } + /** * For nodes that are copied directly from the TypeScript AST into * ESTree mostly as-is. The only difference is the addition of a type @@ -2079,6 +2098,38 @@ module.exports = function(ast, extra) { break; + case SyntaxKind.InterfaceDeclaration: + var interfaceHeritageClauses = node.heritageClauses || []; + var interfaceLastClassToken = interfaceHeritageClauses.length ? interfaceHeritageClauses[interfaceHeritageClauses.length - 1] : node.name; + + if (node.typeParameters && node.typeParameters.length) { + var interfaceLastTypeParameter = node.typeParameters[node.typeParameters.length - 1]; + if (!interfaceLastClassToken || interfaceLastTypeParameter.pos > interfaceLastClassToken.pos) { + interfaceLastClassToken = ts.findNextToken(interfaceLastTypeParameter, ast); + } + result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters); + } + + var hasImplementsClause = interfaceHeritageClauses.length > 0; + var interfaceOpenBrace = ts.findNextToken(interfaceLastClassToken, ast); + + var interfaceBody = { + type: "TSInterfaceBody", + body: node.members.map(function(member) { + return convertChild(member); + }), + range: [ interfaceOpenBrace.getStart(), result.range[1] ], + loc: getLocFor(interfaceOpenBrace.getStart(), node.end, ast) + }; + + assign(result, { + type: "TSInterfaceDeclaration", + body: interfaceBody, + id: convertChild(node.name), + heritage: hasImplementsClause ? interfaceHeritageClauses[0].types.map(convertInterfaceHeritageClause) : [] + }); + break; + default: deeplyCopy(); } diff --git a/tests/fixtures/typescript/basics/class-with-mixin.result.js b/tests/fixtures/typescript/basics/class-with-mixin.result.js index a0a35c2..8d4522c 100644 --- a/tests/fixtures/typescript/basics/class-with-mixin.result.js +++ b/tests/fixtures/typescript/basics/class-with-mixin.result.js @@ -598,7 +598,25 @@ module.exports = { "column": 15 } }, - "name": { + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 154, + 157 + ], + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 15 + } + } + }, + "id": { "type": "Identifier", "range": [ 152, @@ -616,7 +634,7 @@ module.exports = { }, "name": "I" }, - "members": [] + "heritage": [] }, { "type": "VariableDeclaration", @@ -2024,4 +2042,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 new file mode 100644 index 0000000..ba61eda --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-extends-multiple.result.js @@ -0,0 +1,291 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 30, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "Foo" + }, + "heritage": [ + { + "type": "TSInterfaceHeritage", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 22, + 25 + ], + "id": { + "type": "Identifier", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": "Bar" + } + }, + { + "type": "TSInterfaceHeritage", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "range": [ + 26, + 29 + ], + "id": { + "type": "Identifier", + "range": [ + 26, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "name": "Baz" + } + } + ] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "interface", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "Bar", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + { + "type": "Identifier", + "value": "Baz", + "range": [ + 26, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/interface-extends-multiple.src.ts b/tests/fixtures/typescript/basics/interface-extends-multiple.src.ts new file mode 100644 index 0000000..e3b6466 --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-extends-multiple.src.ts @@ -0,0 +1,3 @@ +interface Foo extends Bar,Baz { + +} diff --git a/tests/fixtures/typescript/basics/interface-extends.result.js b/tests/fixtures/typescript/basics/interface-extends.result.js new file mode 100644 index 0000000..b09ee67 --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-extends.result.js @@ -0,0 +1,220 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 26, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "Foo" + }, + "heritage": [ + { + "type": "TSInterfaceHeritage", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "range": [ + 22, + 25 + ], + "id": { + "type": "Identifier", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": "Bar" + } + } + ] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "interface", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 14, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "Bar", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/interface-extends.src.ts b/tests/fixtures/typescript/basics/interface-extends.src.ts new file mode 100644 index 0000000..1cc0e41 --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-extends.src.ts @@ -0,0 +1,3 @@ +interface Foo extends Bar { + +} diff --git a/tests/fixtures/typescript/basics/interface-type-parameters.result.js b/tests/fixtures/typescript/basics/interface-type-parameters.result.js new file mode 100644 index 0000000..0e29b4a --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-type-parameters.result.js @@ -0,0 +1,240 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "range": [ + 13, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "params": [ + { + "type": "TypeParameter", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "T", + "constraint": null + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 17, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "Foo" + }, + "heritage": [] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "interface", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/interface-type-parameters.src.ts b/tests/fixtures/typescript/basics/interface-type-parameters.src.ts new file mode 100644 index 0000000..d2c9ee3 --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-type-parameters.src.ts @@ -0,0 +1,3 @@ +interface Foo { + +} 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 bf1db35..5416b11 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 @@ -1,386 +1,404 @@ module.exports = { + "type": "Program", + "range": [ + 0, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, "body": [ { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 49 + ], "loc": { - "end": { - "column": 1, - "line": 3 - }, "start": { - "column": 0, - "line": 1 + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 } }, - "members": [ - { - "loc": { - "end": { - "column": 30, - "line": 2 - }, - "start": { - "column": 4, - "line": 2 - } - }, - "parameters": [ - { - "accessibility": "public", - "isReadonly": false, - "loc": { - "end": { - "column": 17, - "line": 2 - }, - "start": { - "column": 9, - "line": 2 - } + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSConstructSignature", + "range": [ + 21, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 4 }, - "parameter": { - "loc": { - "end": { - "column": 17, - "line": 2 - }, - "start": { - "column": 16, - "line": 2 - } - }, - "name": "x", + "end": { + "line": 2, + "column": 30 + } + }, + "parameters": [ + { + "type": "TSParameterProperty", "range": [ - 33, + 26, 34 ], - "type": "Identifier" - }, - "range": [ - 26, - 34 - ], - "type": "TSParameterProperty" - }, - { - "accessibility": "private", - "isReadonly": false, - "loc": { - "end": { - "column": 28, - "line": 2 - }, - "start": { - "column": 19, - "line": 2 - } - }, - "parameter": { "loc": { - "end": { - "column": 28, - "line": 2 - }, "start": { - "column": 27, - "line": 2 + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 17 } }, - "name": "y", + "accessibility": "public", + "isReadonly": false, + "parameter": { + "type": "Identifier", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "name": "x" + } + }, + { + "type": "TSParameterProperty", "range": [ - 44, + 36, 45 ], - "type": "Identifier" - }, - "range": [ - 36, - 45 - ], - "type": "TSParameterProperty" - } - ], - "range": [ - 21, - 47 - ], - "type": "TSConstructSignature" - } - ], - "name": { + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "accessibility": "private", + "isReadonly": false, + "parameter": { + "type": "Identifier", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "name": "y" + } + } + ] + } + ], + "range": [ + 15, + 49 + ], "loc": { - "end": { - "column": 14, - "line": 1 - }, "start": { - "column": 10, - "line": 1 + "line": 1, + "column": 15 + }, + "end": { + "line": 3, + "column": 1 } - }, - "name": "Test", + } + }, + "id": { + "type": "Identifier", "range": [ 10, 14 ], - "type": "Identifier" + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "Test" }, - "range": [ - 0, - 49 - ], - "type": "TSInterfaceDeclaration" + "heritage": [] } ], - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 0, - "line": 1 - } - }, - "range": [ - 0, - 49 - ], "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": 16, - "line": 1 - }, "start": { - "column": 15, - "line": 1 + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 } - }, + } + }, + { + "type": "Punctuator", + "value": "{", "range": [ 15, 16 ], - "type": "Punctuator", - "value": "{" - }, - { "loc": { - "end": { - "column": 7, - "line": 2 - }, "start": { - "column": 4, - "line": 2 + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 } - }, + } + }, + { + "type": "Keyword", + "value": "new", "range": [ 21, 24 ], - "type": "Keyword", - "value": "new" - }, - { "loc": { - "end": { - "column": 9, - "line": 2 - }, "start": { - "column": 8, - "line": 2 + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 } - }, + } + }, + { + "type": "Punctuator", + "value": "(", "range": [ 25, 26 ], - "type": "Punctuator", - "value": "(" - }, - { "loc": { - "end": { - "column": 15, - "line": 2 - }, "start": { - "column": 9, - "line": 2 + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 } - }, + } + }, + { + "type": "Keyword", + "value": "public", "range": [ 26, 32 ], - "type": "Keyword", - "value": "public" - }, - { "loc": { - "end": { - "column": 17, - "line": 2 - }, "start": { - "column": 16, - "line": 2 + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 15 } - }, + } + }, + { + "type": "Identifier", + "value": "x", "range": [ 33, 34 ], - "type": "Identifier", - "value": "x" - }, - { "loc": { - "end": { - "column": 18, - "line": 2 - }, "start": { - "column": 17, - "line": 2 + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 } - }, + } + }, + { + "type": "Punctuator", + "value": ",", "range": [ 34, 35 ], - "type": "Punctuator", - "value": "," - }, - { "loc": { - "end": { - "column": 26, - "line": 2 - }, "start": { - "column": 19, - "line": 2 + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 } - }, + } + }, + { + "type": "Keyword", + "value": "private", "range": [ 36, 43 ], - "type": "Keyword", - "value": "private" - }, - { "loc": { - "end": { - "column": 28, - "line": 2 - }, "start": { - "column": 27, - "line": 2 + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 26 } - }, + } + }, + { + "type": "Identifier", + "value": "y", "range": [ 44, 45 ], - "type": "Identifier", - "value": "y" - }, - { "loc": { - "end": { - "column": 29, - "line": 2 - }, "start": { - "column": 28, - "line": 2 + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 } - }, + } + }, + { + "type": "Punctuator", + "value": ")", "range": [ 45, 46 ], - "type": "Punctuator", - "value": ")" - }, - { "loc": { - "end": { - "column": 30, - "line": 2 - }, "start": { - "column": 29, - "line": 2 + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 } - }, + } + }, + { + "type": "Punctuator", + "value": ";", "range": [ 46, 47 ], - "type": "Punctuator", - "value": ";" - }, - { "loc": { - "end": { - "column": 1, - "line": 3 - }, "start": { - "column": 0, - "line": 3 + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 } - }, + } + }, + { + "type": "Punctuator", + "value": "}", "range": [ 48, 49 ], - "type": "Punctuator", - "value": "}" + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } } - ], - "type": "Program" + ] }; 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 new file mode 100644 index 0000000..59505ce --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.result.js @@ -0,0 +1,421 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 36 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 36 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "range": [ + 13, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "params": [ + { + "type": "TypeParameter", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "T", + "constraint": null + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "body": [], + "range": [ + 32, + 36 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + "id": { + "type": "Identifier", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "Foo" + }, + "heritage": [ + { + "type": "TSInterfaceHeritage", + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "range": [ + 25, + 28 + ], + "id": { + "type": "Identifier", + "range": [ + 25, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": "Bar" + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "range": [ + 28, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": "J" + }, + "typeParameters": null + } + ] + } + } + ] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "interface", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 17, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + { + "type": "Identifier", + "value": "Bar", + "range": [ + 25, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "Identifier", + "value": "J", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + } + ] +}; diff --git a/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.src.ts b/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.src.ts new file mode 100644 index 0000000..5387a76 --- /dev/null +++ b/tests/fixtures/typescript/basics/interface-with-extends-type-parameters.src.ts @@ -0,0 +1,3 @@ +interface Foo extends Bar { + +} diff --git a/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js b/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js index fc134d4..c94201a 100644 --- a/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js +++ b/tests/fixtures/typescript/basics/interface-with-jsdoc.result.js @@ -31,46 +31,14 @@ module.exports = { "column": 1 } }, - "name": { - "type": "Identifier", - "range": [ - 10, - 14 - ], - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "name": "Test" - }, - "members": [ - { - "type": "TSMethodSignature", - "range": [ - 76, - 85 - ], - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 13 - } - }, - "name": { - "type": "Identifier", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", "range": [ 76, - 79 + 85 ], "loc": { "start": { @@ -79,33 +47,83 @@ module.exports = { }, "end": { "line": 6, - "column": 7 + "column": 13 } }, - "name": "foo" - }, - "parameters": [ - { + "name": { "type": "Identifier", "range": [ - 80, - 83 + 76, + 79 ], "loc": { "start": { "line": 6, - "column": 8 + "column": 4 }, "end": { "line": 6, - "column": 11 + "column": 7 } }, - "name": "bar" - } - ] + "name": "foo" + }, + "parameters": [ + { + "type": "Identifier", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "name": "bar" + } + ] + } + ], + "range": [ + 15, + 87 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 7, + "column": 1 + } } - ] + }, + "id": { + "type": "Identifier", + "range": [ + 10, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "Test" + }, + "heritage": [] } ], "sourceType": "script", 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 346edb1..bdf5fa6 100644 --- a/tests/fixtures/typescript/basics/interface-with-optional-properties.result.js +++ b/tests/fixtures/typescript/basics/interface-with-optional-properties.result.js @@ -1,813 +1,831 @@ module.exports = { + "type": "Program", + "range": [ + 0, + 81 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, "body": [ { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 81 + ], "loc": { - "end": { - "column": 1, - "line": 5 - }, "start": { - "column": 0, - "line": 1 + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 } }, - "members": [ - { - "loc": { - "end": { - "column": 9, - "line": 2 - }, - "start": { - "column": 4, - "line": 2 - } - }, - "name": { - "loc": { - "end": { - "column": 7, - "line": 2 - }, - "start": { - "column": 4, - "line": 2 - } - }, - "name": "foo", - "optional": true, + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSPropertySignature", "range": [ 21, - 24 + 26 ], - "type": "Identifier" - }, - "questionToken": { "loc": { - "end": { - "column": 8, - "line": 2 - }, "start": { - "column": 7, - "line": 2 + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 } }, - "range": [ - 24, - 25 - ], - "type": "TSQuestionToken" - }, - "range": [ - 21, - 26 - ], - "type": "TSPropertySignature", - "typeAnnotation": null - }, - { - "loc": { - "end": { - "column": 17, - "line": 3 - }, - "start": { - "column": 4, - "line": 3 - } - }, - "name": { - "loc": { - "end": { - "column": 7, - "line": 3 + "name": { + "type": "Identifier", + "range": [ + 21, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } }, - "start": { - "column": 4, - "line": 3 + "name": "foo", + "optional": true + }, + "questionToken": { + "type": "TSQuestionToken", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } } }, - "name": "bar", - "optional": true, + "typeAnnotation": null + }, + { + "type": "TSPropertySignature", "range": [ 31, - 34 + 44 ], - "type": "Identifier" - }, - "questionToken": { "loc": { - "end": { - "column": 8, - "line": 3 - }, "start": { - "column": 7, - "line": 3 + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 17 } }, - "range": [ - 34, - 35 - ], - "type": "TSQuestionToken" - }, - "range": [ - 31, - 44 - ], - "type": "TSPropertySignature", - "typeAnnotation": { - "loc": { - "end": { - "column": 16, - "line": 3 + "name": { + "type": "Identifier", + "range": [ + 31, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } }, - "start": { - "column": 10, - "line": 3 + "name": "bar", + "optional": true + }, + "questionToken": { + "type": "TSQuestionToken", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } } }, - "range": [ - 37, - 43 - ], - "type": "TypeAnnotation", "typeAnnotation": { + "type": "TypeAnnotation", "loc": { - "end": { - "column": 16, - "line": 3 - }, "start": { - "column": 10, - "line": 3 + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 16 } }, "range": [ 37, 43 ], - "type": "TSStringKeyword" - } - } - }, - { - "loc": { - "end": { - "column": 34, - "line": 4 - }, - "start": { - "column": 4, - "line": 4 + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 37, + 43 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 16 + } + } + } } }, - "name": { + { + "type": "TSMethodSignature", + "range": [ + 49, + 79 + ], "loc": { - "end": { - "column": 7, - "line": 4 - }, "start": { - "column": 4, - "line": 4 + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 34 } }, - "name": "baz", - "optional": true, - "range": [ - 49, - 52 - ], - "type": "Identifier" - }, - "parameters": [ - { + "name": { + "type": "Identifier", + "range": [ + 49, + 52 + ], "loc": { - "end": { - "column": 12, - "line": 4 - }, "start": { - "column": 9, - "line": 4 + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 } }, - "name": "foo", + "name": "baz", + "optional": true + }, + "questionToken": { + "type": "TSQuestionToken", "range": [ - 54, - 57 + 52, + 53 ], - "type": "Identifier" - }, - { "loc": { - "end": { - "column": 17, - "line": 4 - }, "start": { - "column": 14, - "line": 4 + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 } - }, - "name": "bar", - "optional": true, - "range": [ - 59, - 62 - ], - "type": "Identifier", - "typeAnnotation": { + } + }, + "parameters": [ + { + "type": "Identifier", + "range": [ + 54, + 57 + ], "loc": { - "end": { - "column": 26, - "line": 4 - }, "start": { - "column": 20, - "line": 4 + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 12 } }, + "name": "foo" + }, + { + "type": "Identifier", "range": [ - 65, - 71 + 59, + 62 ], - "type": "TypeAnnotation", + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "name": "bar", + "optional": true, "typeAnnotation": { + "type": "TypeAnnotation", "loc": { - "end": { - "column": 26, - "line": 4 - }, "start": { - "column": 20, - "line": 4 + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 26 } }, "range": [ 65, 71 ], - "type": "TSStringKeyword" - } - } - }, - { - "loc": { - "end": { - "column": 31, - "line": 4 - }, - "start": { - "column": 28, - "line": 4 + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 65, + 71 + ], + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 26 + } + } + } } }, - "name": "baz", - "optional": true, - "range": [ - 73, - 76 - ], - "type": "Identifier" - } - ], - "questionToken": { - "loc": { - "end": { - "column": 8, - "line": 4 - }, - "start": { - "column": 7, - "line": 4 + { + "type": "Identifier", + "range": [ + 73, + 76 + ], + "loc": { + "start": { + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 31 + } + }, + "name": "baz", + "optional": true } - }, - "range": [ - 52, - 53 - ], - "type": "TSQuestionToken" - }, - "range": [ - 49, - 79 - ], - "type": "TSMethodSignature" - } - ], - "name": { + ] + } + ], + "range": [ + 15, + 81 + ], "loc": { - "end": { - "column": 14, - "line": 1 - }, "start": { - "column": 10, - "line": 1 + "line": 1, + "column": 15 + }, + "end": { + "line": 5, + "column": 1 } - }, - "name": "test", + } + }, + "id": { + "type": "Identifier", "range": [ 10, 14 ], - "type": "Identifier" + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "test" }, - "range": [ - 0, - 81 - ], - "type": "TSInterfaceDeclaration" - } - ], - "loc": { - "end": { - "column": 1, - "line": 5 - }, - "start": { - "column": 0, - "line": 1 + "heritage": [] } - }, - "range": [ - 0, - 81 ], "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": 16, - "line": 1 - }, "start": { - "column": 15, - "line": 1 + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 } - }, + } + }, + { + "type": "Punctuator", + "value": "{", "range": [ 15, 16 ], - "type": "Punctuator", - "value": "{" - }, - { "loc": { - "end": { - "column": 7, - "line": 2 - }, "start": { - "column": 4, - "line": 2 + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 } - }, + } + }, + { + "type": "Identifier", + "value": "foo", "range": [ 21, 24 ], - "type": "Identifier", - "value": "foo" - }, - { "loc": { - "end": { - "column": 8, - "line": 2 - }, "start": { - "column": 7, - "line": 2 + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 } - }, + } + }, + { + "type": "Punctuator", + "value": "?", "range": [ 24, 25 ], - "type": "Punctuator", - "value": "?" - }, - { "loc": { - "end": { - "column": 9, - "line": 2 - }, "start": { - "column": 8, - "line": 2 + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 } - }, + } + }, + { + "type": "Punctuator", + "value": ";", "range": [ 25, 26 ], - "type": "Punctuator", - "value": ";" - }, - { "loc": { - "end": { - "column": 7, - "line": 3 - }, "start": { - "column": 4, - "line": 3 + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 } - }, + } + }, + { + "type": "Identifier", + "value": "bar", "range": [ 31, 34 ], - "type": "Identifier", - "value": "bar" - }, - { "loc": { - "end": { - "column": 8, - "line": 3 - }, "start": { - "column": 7, - "line": 3 + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 } - }, + } + }, + { + "type": "Punctuator", + "value": "?", "range": [ 34, 35 ], - "type": "Punctuator", - "value": "?" - }, - { "loc": { - "end": { - "column": 9, - "line": 3 - }, "start": { - "column": 8, - "line": 3 + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 } - }, + } + }, + { + "type": "Punctuator", + "value": ":", "range": [ 35, 36 ], - "type": "Punctuator", - "value": ":" - }, - { "loc": { - "end": { - "column": 16, - "line": 3 - }, "start": { - "column": 10, - "line": 3 + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 } - }, + } + }, + { + "type": "Identifier", + "value": "string", "range": [ 37, 43 ], - "type": "Identifier", - "value": "string" - }, - { "loc": { - "end": { - "column": 17, - "line": 3 - }, "start": { - "column": 16, - "line": 3 + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 16 } - }, + } + }, + { + "type": "Punctuator", + "value": ";", "range": [ 43, 44 ], - "type": "Punctuator", - "value": ";" - }, - { "loc": { - "end": { - "column": 7, - "line": 4 - }, "start": { - "column": 4, - "line": 4 + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 } - }, + } + }, + { + "type": "Identifier", + "value": "baz", "range": [ 49, 52 ], - "type": "Identifier", - "value": "baz" - }, - { "loc": { - "end": { - "column": 8, - "line": 4 - }, "start": { - "column": 7, - "line": 4 + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 7 } - }, + } + }, + { + "type": "Punctuator", + "value": "?", "range": [ 52, 53 ], - "type": "Punctuator", - "value": "?" - }, - { "loc": { - "end": { - "column": 9, - "line": 4 - }, "start": { - "column": 8, - "line": 4 + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 } - }, + } + }, + { + "type": "Punctuator", + "value": "(", "range": [ 53, 54 ], - "type": "Punctuator", - "value": "(" - }, - { "loc": { - "end": { - "column": 12, - "line": 4 - }, "start": { - "column": 9, - "line": 4 + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 } - }, + } + }, + { + "type": "Identifier", + "value": "foo", "range": [ 54, 57 ], - "type": "Identifier", - "value": "foo" - }, - { "loc": { - "end": { - "column": 13, - "line": 4 - }, "start": { - "column": 12, - "line": 4 + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 12 } - }, + } + }, + { + "type": "Punctuator", + "value": ",", "range": [ 57, 58 ], - "type": "Punctuator", - "value": "," - }, - { "loc": { - "end": { - "column": 17, - "line": 4 - }, "start": { - "column": 14, - "line": 4 + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 } - }, + } + }, + { + "type": "Identifier", + "value": "bar", "range": [ 59, 62 ], - "type": "Identifier", - "value": "bar" - }, - { "loc": { - "end": { - "column": 18, - "line": 4 - }, "start": { - "column": 17, - "line": 4 + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 17 } - }, + } + }, + { + "type": "Punctuator", + "value": "?", "range": [ 62, 63 ], - "type": "Punctuator", - "value": "?" - }, - { "loc": { - "end": { - "column": 19, - "line": 4 - }, "start": { - "column": 18, - "line": 4 + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 } - }, + } + }, + { + "type": "Punctuator", + "value": ":", "range": [ 63, 64 ], - "type": "Punctuator", - "value": ":" - }, - { "loc": { - "end": { - "column": 26, - "line": 4 - }, "start": { - "column": 20, - "line": 4 + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 19 } - }, + } + }, + { + "type": "Identifier", + "value": "string", "range": [ 65, 71 ], - "type": "Identifier", - "value": "string" - }, - { "loc": { - "end": { - "column": 27, - "line": 4 - }, "start": { - "column": 26, - "line": 4 + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 26 } - }, + } + }, + { + "type": "Punctuator", + "value": ",", "range": [ 71, 72 ], - "type": "Punctuator", - "value": "," - }, - { "loc": { - "end": { - "column": 31, - "line": 4 - }, "start": { - "column": 28, - "line": 4 + "line": 4, + "column": 26 + }, + "end": { + "line": 4, + "column": 27 } - }, + } + }, + { + "type": "Identifier", + "value": "baz", "range": [ 73, 76 ], - "type": "Identifier", - "value": "baz" - }, - { "loc": { - "end": { - "column": 32, - "line": 4 - }, "start": { - "column": 31, - "line": 4 + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 31 } - }, + } + }, + { + "type": "Punctuator", + "value": "?", "range": [ 76, 77 ], - "type": "Punctuator", - "value": "?" - }, - { "loc": { - "end": { - "column": 33, - "line": 4 - }, "start": { - "column": 32, - "line": 4 + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 32 } - }, + } + }, + { + "type": "Punctuator", + "value": ")", "range": [ 77, 78 ], - "type": "Punctuator", - "value": ")" - }, - { "loc": { - "end": { - "column": 34, - "line": 4 - }, "start": { - "column": 33, - "line": 4 + "line": 4, + "column": 32 + }, + "end": { + "line": 4, + "column": 33 } - }, + } + }, + { + "type": "Punctuator", + "value": ";", "range": [ 78, 79 ], - "type": "Punctuator", - "value": ";" - }, - { "loc": { - "end": { - "column": 1, - "line": 5 - }, "start": { - "column": 0, - "line": 5 + "line": 4, + "column": 33 + }, + "end": { + "line": 4, + "column": 34 } - }, + } + }, + { + "type": "Punctuator", + "value": "}", "range": [ 80, 81 ], - "type": "Punctuator", - "value": "}" + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } } - ], - "type": "Program" + ] }; 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 40c8fbc..83f82de 100644 --- a/tests/fixtures/typescript/basics/interface-without-type-annotation.result.js +++ b/tests/fixtures/typescript/basics/interface-without-type-annotation.result.js @@ -31,7 +31,62 @@ module.exports = { "column": 1 } }, - "name": { + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSPropertySignature", + "range": [ + 21, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "name": { + "type": "Identifier", + "range": [ + 21, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "name": "foo" + }, + "typeAnnotation": null + } + ], + "range": [ + 15, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + "id": { "type": "Identifier", "range": [ 10, @@ -49,44 +104,7 @@ module.exports = { }, "name": "test" }, - "members": [ - { - "type": "TSPropertySignature", - "range": [ - 21, - 25 - ], - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "name": { - "type": "Identifier", - "range": [ - 21, - 24 - ], - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "name": "foo" - }, - "typeAnnotation": null - } - ] + "heritage": [] } ], "sourceType": "script", diff --git a/tests/fixtures/typescript/basics/typed-this.result.js b/tests/fixtures/typescript/basics/typed-this.result.js index 3414d4c..e975638 100644 --- a/tests/fixtures/typescript/basics/typed-this.result.js +++ b/tests/fixtures/typescript/basics/typed-this.result.js @@ -31,46 +31,14 @@ module.exports = { "column": 1 } }, - "name": { - "type": "Identifier", - "range": [ - 10, - 19 - ], - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "name": "UIElement" - }, - "members": [ - { - "type": "TSMethodSignature", - "range": [ - 23, - 87 - ], - "loc": { - "start": { - "line": 2, - "column": 1 - }, - "end": { - "line": 2, - "column": 65 - } - }, - "name": { - "type": "Identifier", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", "range": [ 23, - 39 + 87 ], "loc": { "start": { @@ -79,51 +47,47 @@ module.exports = { }, "end": { "line": 2, - "column": 17 + "column": 65 } }, - "name": "addClickListener" - }, - "parameters": [ - { + "name": { "type": "Identifier", "range": [ - 40, - 47 + 23, + 39 ], "loc": { "start": { "line": 2, - "column": 18 + "column": 1 }, "end": { "line": 2, - "column": 25 + "column": 17 } }, - "name": "onclick", - "typeAnnotation": { - "type": "TypeAnnotation", + "name": "addClickListener" + }, + "parameters": [ + { + "type": "Identifier", + "range": [ + 40, + 47 + ], "loc": { "start": { "line": 2, - "column": 27 + "column": 18 }, "end": { "line": 2, - "column": 57 + "column": 25 } }, - "range": [ - 49, - 79 - ], + "name": "onclick", "typeAnnotation": { - "type": "TSFunctionType", - "range": [ - 49, - 79 - ], + "type": "TypeAnnotation", "loc": { "start": { "line": 2, @@ -134,46 +98,46 @@ module.exports = { "column": 57 } }, - "parameters": [ - { - "type": "Identifier", - "range": [ - 50, - 54 - ], - "loc": { - "start": { - "line": 2, - "column": 28 - }, - "end": { - "line": 2, - "column": 32 - } + "range": [ + 49, + 79 + ], + "typeAnnotation": { + "type": "TSFunctionType", + "range": [ + 49, + 79 + ], + "loc": { + "start": { + "line": 2, + "column": 27 }, - "name": "this", - "typeAnnotation": { - "type": "TypeAnnotation", + "end": { + "line": 2, + "column": 57 + } + }, + "parameters": [ + { + "type": "Identifier", + "range": [ + 50, + 54 + ], "loc": { "start": { "line": 2, - "column": 34 + "column": 28 }, "end": { "line": 2, - "column": 38 + "column": 32 } }, - "range": [ - 56, - 60 - ], + "name": "this", "typeAnnotation": { - "type": "TSVoidKeyword", - "range": [ - 56, - 60 - ], + "type": "TypeAnnotation", "loc": { "start": { "line": 2, @@ -183,49 +147,49 @@ module.exports = { "line": 2, "column": 38 } + }, + "range": [ + 56, + 60 + ], + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 56, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 38 + } + } } } - } - }, - { - "type": "Identifier", - "range": [ - 62, - 63 - ], - "loc": { - "start": { - "line": 2, - "column": 40 - }, - "end": { - "line": 2, - "column": 41 - } }, - "name": "e", - "typeAnnotation": { - "type": "TypeAnnotation", + { + "type": "Identifier", + "range": [ + 62, + 63 + ], "loc": { "start": { "line": 2, - "column": 43 + "column": 40 }, "end": { "line": 2, - "column": 48 + "column": 41 } }, - "range": [ - 65, - 70 - ], + "name": "e", "typeAnnotation": { - "type": "TSTypeReference", - "range": [ - 65, - 70 - ], + "type": "TypeAnnotation", "loc": { "start": { "line": 2, @@ -236,8 +200,12 @@ module.exports = { "column": 48 } }, - "typeName": { - "type": "Identifier", + "range": [ + 65, + 70 + ], + "typeAnnotation": { + "type": "TSTypeReference", "range": [ 65, 70 @@ -252,34 +220,30 @@ module.exports = { "column": 48 } }, - "name": "Event" + "typeName": { + "type": "Identifier", + "range": [ + 65, + 70 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "name": "Event" + } } } } - } - ], - "typeAnnotation": { - "type": "TypeAnnotation", - "loc": { - "start": { - "line": 2, - "column": 53 - }, - "end": { - "line": 2, - "column": 57 - } - }, - "range": [ - 75, - 79 ], "typeAnnotation": { - "type": "TSVoidKeyword", - "range": [ - 75, - 79 - ], + "type": "TypeAnnotation", "loc": { "start": { "line": 2, @@ -289,35 +253,35 @@ module.exports = { "line": 2, "column": 57 } + }, + "range": [ + 75, + 79 + ], + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 75, + 79 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 57 + } + } } } } } } - } - ], - "typeAnnotation": { - "type": "TypeAnnotation", - "loc": { - "start": { - "line": 2, - "column": 60 - }, - "end": { - "line": 2, - "column": 64 - } - }, - "range": [ - 82, - 86 ], "typeAnnotation": { - "type": "TSVoidKeyword", - "range": [ - 82, - 86 - ], + "type": "TypeAnnotation", "loc": { "start": { "line": 2, @@ -327,11 +291,65 @@ module.exports = { "line": 2, "column": 64 } + }, + "range": [ + 82, + 86 + ], + "typeAnnotation": { + "type": "TSVoidKeyword", + "range": [ + 82, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 60 + }, + "end": { + "line": 2, + "column": 64 + } + } } } } + ], + "range": [ + 20, + 89 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 3, + "column": 1 + } } - ] + }, + "id": { + "type": "Identifier", + "range": [ + 10, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "UIElement" + }, + "heritage": [] } ], "sourceType": "script", @@ -751,4 +769,4 @@ module.exports = { } } ] -}; \ No newline at end of file +};