diff --git a/lib/ast-converter.js b/lib/ast-converter.js index 437f0ec..f0ded24 100644 --- a/lib/ast-converter.js +++ b/lib/ast-converter.js @@ -244,6 +244,34 @@ function fixExports(node, result, ast) { return result; } +/** + * Returns true if a given TSNode is a JSX token + * @param {TSNode} node TSNode to be checked + * @returns {boolean} is a JSX token + */ +function isJSXToken(node) { + return ( + node.kind >= SyntaxKind.JsxElement + && node.kind <= SyntaxKind.JsxAttribute + ); +} + +/** + * Returns true if a given TSNode has a JSX token within its hierarchy + * @param {TSNode} node TSNode to be checked + * @returns {boolean} has JSX ancestor + */ +function hasJSXAncestor(node) { + while (node) { + if (isJSXToken(node)) { + return true; + } + node = node.parent; + } + return false; +} + + /** * Extends and formats a given error object * @param {Object} error the error object @@ -331,12 +359,12 @@ function getTokenType(token) { // Some JSX tokens have to be determined based on their parent if (token.parent) { - if (token.kind === SyntaxKind.Identifier && token.parent.kind === SyntaxKind.FirstNode) { + if (token.kind === SyntaxKind.Identifier && token.parent.kind === SyntaxKind.PropertyAccessExpression && hasJSXAncestor(token)) { return "JSXIdentifier"; } - if (token.parent.kind >= SyntaxKind.JsxElement && token.parent.kind <= SyntaxKind.JsxAttribute) { - if (token.kind === SyntaxKind.FirstNode) { + if (isJSXToken(token.parent)) { + if (token.kind === SyntaxKind.PropertyAccessExpression) { return "JSXMemberExpression"; } @@ -616,12 +644,12 @@ module.exports = function(ast, extra) { if (tagNameToken.type === "JSXMemberExpression") { - var isNestedMemberExpression = (node.tagName.left.kind === SyntaxKind.FirstNode); + var isNestedMemberExpression = (node.tagName.expression.kind === SyntaxKind.PropertyAccessExpression); // Convert TSNode left and right objects into ESTreeNode object // and property objects - tagNameToken.object = convertChild(node.tagName.left); - tagNameToken.property = convertChild(node.tagName.right); + tagNameToken.object = convertChild(node.tagName.expression); + tagNameToken.property = convertChild(node.tagName.name); // Assign the appropriate types tagNameToken.object.type = (isNestedMemberExpression) ? "JSXMemberExpression" : "JSXIdentifier"; @@ -1061,7 +1089,7 @@ module.exports = function(ast, extra) { } else { // class /** - * Unlinke in object literal methods, class method params can have decorators + * Unlike in object literal methods, class method params can have decorators */ method.params = node.parameters.map(function(param) { var convertedParam = convertChild(param); @@ -1380,7 +1408,11 @@ module.exports = function(ast, extra) { right: convertChild(node.initializer) }); } else { - return convert(node.name, parent); + var convertedParameter = convert(node.name, parent); + if (node.type) { + convertedParameter.typeAnnotation = convertTypeAnnotation(node.type); + } + return convertedParameter; } break; @@ -1626,12 +1658,24 @@ module.exports = function(ast, extra) { break; case SyntaxKind.PropertyAccessExpression: - assign(result, { - type: "MemberExpression", - object: convertChild(node.expression), - property: convertChild(node.name), - computed: false - }); + if (isJSXToken(parent)) { + var jsxMemberExpression = { + type: "MemberExpression", + object: convertChild(node.expression), + property: convertChild(node.name) + }; + var isNestedMemberExpression = (node.expression.kind === SyntaxKind.PropertyAccessExpression); + jsxMemberExpression.object.type = (isNestedMemberExpression) ? "MemberExpression" : "JSXIdentifier"; + jsxMemberExpression.property.type = "JSXIdentifier"; + assign(result, jsxMemberExpression); + } else { + assign(result, { + type: "MemberExpression", + object: convertChild(node.expression), + property: convertChild(node.name), + computed: false + }); + } break; case SyntaxKind.ElementAccessExpression: diff --git a/package.json b/package.json index f14c32f..018ac6b 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,6 @@ "object-assign": "^4.0.1" }, "peerDependencies": { - "typescript": "^1.7.3" + "typescript": "^2.0.3" } } diff --git a/tests/fixtures/typescript/basics/arrow-function-with-type-parameters.result.js b/tests/fixtures/typescript/basics/arrow-function-with-type-parameters.result.js index e1363c7..c481ca8 100644 --- a/tests/fixtures/typescript/basics/arrow-function-with-type-parameters.result.js +++ b/tests/fixtures/typescript/basics/arrow-function-with-type-parameters.result.js @@ -1,510 +1,562 @@ module.exports = { + "type": "Program", + "range": [ + 0, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, "body": [ { + "type": "ExpressionStatement", + "range": [ + 0, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, "expression": { - "body": { - "body": [ - { - "argument": { - "loc": { - "end": { - "column": 12, - "line": 2 - }, - "start": { - "column": 11, - "line": 2 - } - }, - "name": "b", - "range": [ - 29, - 30 - ], - "type": "Identifier" + "type": "ArrowFunctionExpression", + "range": [ + 0, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 }, + "end": { + "line": 1, + "column": 5 + } + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", "loc": { - "end": { - "column": 13, - "line": 2 - }, "start": { - "column": 4, - "line": 2 + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 } }, "range": [ - 22, - 31 + 7, + 8 ], - "type": "ReturnStatement" - } - ], - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 16, - "line": 1 + "typeAnnotation": { + "type": "TSTypeReference", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "typeName": { + "type": "Identifier", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "name": "X" + } + } } - }, + } + ], + "body": { + "type": "BlockStatement", "range": [ 16, 33 ], - "type": "BlockStatement" - }, - "expression": false, - "generator": false, - "id": null, - "loc": { - "end": { - "column": 1, - "line": 3 + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 3, + "column": 1 + } }, - "start": { - "column": 0, - "line": 1 - } - }, - "params": [ - { - "loc": { - "end": { - "column": 5, - "line": 1 + "body": [ + { + "type": "ReturnStatement", + "range": [ + 22, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 + } }, - "start": { - "column": 4, - "line": 1 + "argument": { + "type": "Identifier", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "name": "b" } - }, - "name": "b", - "range": [ - 4, - 5 - ], - "type": "Identifier" - } - ], - "range": [ - 0, - 33 - ], + } + ] + }, + "expression": false, "returnType": { + "type": "TypeAnnotation", "loc": { - "end": { - "column": 12, - "line": 1 - }, "start": { - "column": 11, - "line": 1 + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 } }, "range": [ 11, 12 ], - "type": "TypeAnnotation", "typeAnnotation": { - "loc": { - "end": { - "column": 12, - "line": 1 - }, - "start": { - "column": 11, - "line": 1 - } - }, + "type": "TSTypeReference", "range": [ 11, 12 ], - "type": "TSTypeReference", - "typeName": { - "loc": { - "end": { - "column": 12, - "line": 1 - }, - "start": { - "column": 11, - "line": 1 - } + "loc": { + "start": { + "line": 1, + "column": 11 }, - "name": "X", + "end": { + "line": 1, + "column": 12 + } + }, + "typeName": { + "type": "Identifier", "range": [ 11, 12 ], - "type": "Identifier" + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "X" } } }, - "type": "ArrowFunctionExpression", "typeParameters": { + "type": "TypeParameterDeclaration", + "range": [ + 0, + 3 + ], "loc": { - "end": { - "column": 3, - "line": 1 - }, "start": { - "column": 0, - "line": 1 + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 } }, "params": [ { - "loc": { - "end": { - "column": 2, - "line": 1 - }, - "start": { - "column": 1, - "line": 1 - } - }, - "name": "X", + "type": "TypeParameter", "range": [ 1, 2 ], - "type": "TypeParameter" + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "name": "X" } - ], - "range": [ - 0, - 3 - ], - "type": "TypeParameterDeclaration" + ] } - }, - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 0, - "line": 1 - } - }, - "range": [ - 0, - 33 - ], - "type": "ExpressionStatement" + } } ], - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 0, - "line": 1 - } - }, - "range": [ - 0, - 33 - ], "sourceType": "script", "tokens": [ { - "loc": { - "end": { - "column": 1, - "line": 1 - }, - "start": { - "column": 0, - "line": 1 - } - }, + "type": "Punctuator", + "value": "<", "range": [ 0, 1 ], - "type": "Punctuator", - "value": "<" - }, - { "loc": { - "end": { - "column": 2, - "line": 1 - }, "start": { - "column": 1, - "line": 1 + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 } - }, + } + }, + { + "type": "Identifier", + "value": "X", "range": [ 1, 2 ], - "type": "Identifier", - "value": "X" - }, - { "loc": { - "end": { - "column": 3, - "line": 1 - }, "start": { - "column": 2, - "line": 1 + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 } - }, + } + }, + { + "type": "Punctuator", + "value": ">", "range": [ 2, 3 ], - "type": "Punctuator", - "value": ">" - }, - { "loc": { - "end": { - "column": 4, - "line": 1 - }, "start": { - "column": 3, - "line": 1 + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 3 } - }, + } + }, + { + "type": "Punctuator", + "value": "(", "range": [ 3, 4 ], - "type": "Punctuator", - "value": "(" - }, - { "loc": { - "end": { - "column": 5, - "line": 1 - }, "start": { - "column": 4, - "line": 1 + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 } - }, + } + }, + { + "type": "Identifier", + "value": "b", "range": [ 4, 5 ], - "type": "Identifier", - "value": "b" - }, - { "loc": { - "end": { - "column": 6, - "line": 1 - }, "start": { - "column": 5, - "line": 1 + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 } - }, + } + }, + { + "type": "Punctuator", + "value": ":", "range": [ 5, 6 ], - "type": "Punctuator", - "value": ":" - }, - { "loc": { - "end": { - "column": 8, - "line": 1 - }, "start": { - "column": 7, - "line": 1 + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 } - }, + } + }, + { + "type": "Identifier", + "value": "X", "range": [ 7, 8 ], - "type": "Identifier", - "value": "X" - }, - { "loc": { - "end": { - "column": 9, - "line": 1 - }, "start": { - "column": 8, - "line": 1 + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 } - }, + } + }, + { + "type": "Punctuator", + "value": ")", "range": [ 8, 9 ], - "type": "Punctuator", - "value": ")" - }, - { "loc": { - "end": { - "column": 10, - "line": 1 - }, "start": { - "column": 9, - "line": 1 + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 } - }, + } + }, + { + "type": "Punctuator", + "value": ":", "range": [ 9, 10 ], - "type": "Punctuator", - "value": ":" - }, - { "loc": { - "end": { - "column": 12, - "line": 1 - }, "start": { - "column": 11, - "line": 1 + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 } - }, + } + }, + { + "type": "Identifier", + "value": "X", "range": [ 11, 12 ], - "type": "Identifier", - "value": "X" - }, - { "loc": { - "end": { - "column": 15, - "line": 1 - }, "start": { - "column": 13, - "line": 1 + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 } - }, + } + }, + { + "type": "Punctuator", + "value": "=>", "range": [ 13, 15 ], - "type": "Punctuator", - "value": "=>" - }, - { "loc": { - "end": { - "column": 17, - "line": 1 - }, "start": { - "column": 16, - "line": 1 + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 } - }, + } + }, + { + "type": "Punctuator", + "value": "{", "range": [ 16, 17 ], - "type": "Punctuator", - "value": "{" - }, - { "loc": { - "end": { - "column": 10, - "line": 2 - }, "start": { - "column": 4, - "line": 2 + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 } - }, + } + }, + { + "type": "Keyword", + "value": "return", "range": [ 22, 28 ], - "type": "Keyword", - "value": "return" - }, - { "loc": { - "end": { - "column": 12, - "line": 2 - }, "start": { - "column": 11, - "line": 2 + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 } - }, + } + }, + { + "type": "Identifier", + "value": "b", "range": [ 29, 30 ], - "type": "Identifier", - "value": "b" - }, - { "loc": { - "end": { - "column": 13, - "line": 2 - }, "start": { - "column": 12, - "line": 2 + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 } - }, + } + }, + { + "type": "Punctuator", + "value": ";", "range": [ 30, 31 ], - "type": "Punctuator", - "value": ";" - }, - { "loc": { - "end": { - "column": 1, - "line": 3 - }, "start": { - "column": 0, - "line": 3 + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 } - }, + } + }, + { + "type": "Punctuator", + "value": "}", "range": [ 32, 33 ], - "type": "Punctuator", - "value": "}" + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } } - ], - "type": "Program" -}; + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-accessibility-modifiers.result.js b/tests/fixtures/typescript/basics/class-with-accessibility-modifiers.result.js index 354e018..b79e78f 100644 --- a/tests/fixtures/typescript/basics/class-with-accessibility-modifiers.result.js +++ b/tests/fixtures/typescript/basics/class-with-accessibility-modifiers.result.js @@ -478,6 +478,40 @@ module.exports = { } }, "name": "bar", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "range": [ + 138, + 144 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 138, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 32 + } + } + } + }, "decorators": [] } ] diff --git a/tests/fixtures/typescript/basics/class-with-implements-generic-multiple.result.js b/tests/fixtures/typescript/basics/class-with-implements-generic-multiple.result.js index f19424b..8669c88 100644 --- a/tests/fixtures/typescript/basics/class-with-implements-generic-multiple.result.js +++ b/tests/fixtures/typescript/basics/class-with-implements-generic-multiple.result.js @@ -31,7 +31,6 @@ module.exports = { "column": 1 } }, - "decorators": [], "id": { "type": "Identifier", "range": [ @@ -194,7 +193,8 @@ module.exports = { ] } } - ] + ], + "decorators": [] } ], "sourceType": "script", @@ -398,4 +398,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-implements-generic.result.js b/tests/fixtures/typescript/basics/class-with-implements-generic.result.js index a368696..69b3e69 100644 --- a/tests/fixtures/typescript/basics/class-with-implements-generic.result.js +++ b/tests/fixtures/typescript/basics/class-with-implements-generic.result.js @@ -31,7 +31,6 @@ module.exports = { "column": 1 } }, - "decorators": [], "id": { "type": "Identifier", "range": [ @@ -159,7 +158,8 @@ module.exports = { ] } } - ] + ], + "decorators": [] } ], "sourceType": "script", @@ -327,4 +327,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/class-with-implements.result.js b/tests/fixtures/typescript/basics/class-with-implements.result.js index 83739b6..5388d10 100644 --- a/tests/fixtures/typescript/basics/class-with-implements.result.js +++ b/tests/fixtures/typescript/basics/class-with-implements.result.js @@ -31,7 +31,6 @@ module.exports = { "column": 1 } }, - "decorators": [], "id": { "type": "Identifier", "range": [ @@ -105,7 +104,8 @@ module.exports = { "name": "Bar" } } - ] + ], + "decorators": [] } ], "sourceType": "script", @@ -219,4 +219,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/declare-function.result.js b/tests/fixtures/typescript/basics/declare-function.result.js index 2677738..9add748 100644 --- a/tests/fixtures/typescript/basics/declare-function.result.js +++ b/tests/fixtures/typescript/basics/declare-function.result.js @@ -68,7 +68,41 @@ module.exports = { "column": 24 } }, - "name": "bar" + "name": "bar", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "range": [ + 26, + 32 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 26, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + } + } + } } ], "body": null, @@ -309,4 +343,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/function-with-type-parameters.result.js b/tests/fixtures/typescript/basics/function-with-type-parameters.result.js index 4d3ae3e..30d7d28 100644 --- a/tests/fixtures/typescript/basics/function-with-type-parameters.result.js +++ b/tests/fixtures/typescript/basics/function-with-type-parameters.result.js @@ -1,528 +1,580 @@ module.exports = { + "type": "Program", + "range": [ + 0, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, "body": [ { "type": "FunctionDeclaration", - "body": { - "body": [ - { - "argument": { - "loc": { - "end": { - "column": 12, - "line": 2 - }, - "start": { - "column": 11, - "line": 2 - } - }, - "name": "b", - "range": [ - 36, - 37 - ], - "type": "Identifier" - }, - "loc": { - "end": { - "column": 13, - "line": 2 - }, - "start": { - "column": 4, - "line": 2 - } - }, - "range": [ - 29, - 38 - ], - "type": "ReturnStatement" - } - ], - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 23, - "line": 1 - } + "range": [ + 0, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 0 }, - "range": [ - 23, - 40 - ], - "type": "BlockStatement" + "end": { + "line": 3, + "column": 1 + } }, - "expression": false, - "generator": false, "id": { - "loc": { - "end": { - "column": 10, - "line": 1 - }, - "start": { - "column": 9, - "line": 1 - } - }, - "name": "a", + "type": "Identifier", "range": [ 9, 10 ], - "type": "Identifier" - }, - "loc": { - "end": { - "column": 1, - "line": 3 + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } }, - "start": { - "column": 0, - "line": 1 - } + "name": "a" }, + "generator": false, + "expression": false, "params": [ { + "type": "Identifier", + "range": [ + 14, + 15 + ], "loc": { - "end": { - "column": 15, - "line": 1 - }, "start": { - "column": 14, - "line": 1 + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 } }, "name": "b", - "range": [ - 14, - 15 - ], - "type": "Identifier" + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "range": [ + 17, + 18 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "typeName": { + "type": "Identifier", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "X" + } + } + } } ], - "range": [ - 0, - 40 - ], - "typeParameters": { + "body": { + "type": "BlockStatement", + "range": [ + 23, + 40 + ], "loc": { - "end": { - "column": 13, - "line": 1 - }, "start": { - "column": 10, - "line": 1 + "line": 1, + "column": 23 + }, + "end": { + "line": 3, + "column": 1 } }, - "params": [ + "body": [ { + "type": "ReturnStatement", + "range": [ + 29, + 38 + ], "loc": { - "end": { - "column": 12, - "line": 1 - }, "start": { - "column": 11, - "line": 1 + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 13 } }, - "name": "X", - "range": [ - 11, - 12 - ], - "type": "TypeParameter" + "argument": { + "type": "Identifier", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "name": "b" + } } - ], - "range": [ - 10, - 13 - ], - "type": "TypeParameterDeclaration" + ] }, "returnType": { + "type": "TypeAnnotation", "loc": { - "end": { - "column": 22, - "line": 1 - }, "start": { - "column": 21, - "line": 1 + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 } }, "range": [ 21, 22 ], - "type": "TypeAnnotation", "typeAnnotation": { - "loc": { - "end": { - "column": 22, - "line": 1 - }, - "start": { - "column": 21, - "line": 1 - } - }, + "type": "TSTypeReference", "range": [ 21, 22 ], - "type": "TSTypeReference", + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, "typeName": { + "type": "Identifier", + "range": [ + 21, + 22 + ], "loc": { - "end": { - "column": 22, - "line": 1 - }, "start": { - "column": 21, - "line": 1 + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 } }, - "name": "X", + "name": "X" + } + } + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "params": [ + { + "type": "TypeParameter", "range": [ - 21, - 22 + 11, + 12 ], - "type": "Identifier" + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "X" } - } + ] } } ], - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 0, - "line": 1 - } - }, - "range": [ - 0, - 40 - ], "sourceType": "script", "tokens": [ { - "loc": { - "end": { - "column": 8, - "line": 1 - }, - "start": { - "column": 0, - "line": 1 - } - }, + "type": "Keyword", + "value": "function", "range": [ 0, 8 ], - "type": "Keyword", - "value": "function" - }, - { "loc": { - "end": { - "column": 10, - "line": 1 - }, "start": { - "column": 9, - "line": 1 + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 } - }, + } + }, + { + "type": "Identifier", + "value": "a", "range": [ 9, 10 ], - "type": "Identifier", - "value": "a" - }, - { "loc": { - "end": { - "column": 11, - "line": 1 - }, "start": { - "column": 10, - "line": 1 + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 } - }, + } + }, + { + "type": "Punctuator", + "value": "<", "range": [ 10, 11 ], - "type": "Punctuator", - "value": "<" - }, - { "loc": { - "end": { - "column": 12, - "line": 1 - }, "start": { - "column": 11, - "line": 1 + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 } - }, + } + }, + { + "type": "Identifier", + "value": "X", "range": [ 11, 12 ], - "type": "Identifier", - "value": "X" - }, - { "loc": { - "end": { - "column": 13, - "line": 1 - }, "start": { - "column": 12, - "line": 1 + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 } - }, + } + }, + { + "type": "Punctuator", + "value": ">", "range": [ 12, 13 ], - "type": "Punctuator", - "value": ">" - }, - { "loc": { - "end": { - "column": 14, - "line": 1 - }, "start": { - "column": 13, - "line": 1 + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 } - }, + } + }, + { + "type": "Punctuator", + "value": "(", "range": [ 13, 14 ], - "type": "Punctuator", - "value": "(" - }, - { "loc": { - "end": { - "column": 15, - "line": 1 - }, "start": { - "column": 14, - "line": 1 + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 } - }, + } + }, + { + "type": "Identifier", + "value": "b", "range": [ 14, 15 ], - "type": "Identifier", - "value": "b" - }, - { "loc": { - "end": { - "column": 16, - "line": 1 - }, "start": { - "column": 15, - "line": 1 + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 } - }, + } + }, + { + "type": "Punctuator", + "value": ":", "range": [ 15, 16 ], - "type": "Punctuator", - "value": ":" - }, - { "loc": { - "end": { - "column": 18, - "line": 1 - }, "start": { - "column": 17, - "line": 1 + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 } - }, + } + }, + { + "type": "Identifier", + "value": "X", "range": [ 17, 18 ], - "type": "Identifier", - "value": "X" - }, - { "loc": { - "end": { - "column": 19, - "line": 1 - }, "start": { - "column": 18, - "line": 1 + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 } - }, + } + }, + { + "type": "Punctuator", + "value": ")", "range": [ 18, 19 ], - "type": "Punctuator", - "value": ")" - }, - { "loc": { - "end": { - "column": 20, - "line": 1 - }, "start": { - "column": 19, - "line": 1 + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 } - }, + } + }, + { + "type": "Punctuator", + "value": ":", "range": [ 19, 20 ], - "type": "Punctuator", - "value": ":" - }, - { "loc": { - "end": { - "column": 22, - "line": 1 - }, "start": { - "column": 21, - "line": 1 + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 } - }, + } + }, + { + "type": "Identifier", + "value": "X", "range": [ 21, 22 ], - "type": "Identifier", - "value": "X" - }, - { "loc": { - "end": { - "column": 24, - "line": 1 - }, "start": { - "column": 23, - "line": 1 + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 } - }, + } + }, + { + "type": "Punctuator", + "value": "{", "range": [ 23, 24 ], - "type": "Punctuator", - "value": "{" - }, - { "loc": { - "end": { - "column": 10, - "line": 2 - }, "start": { - "column": 4, - "line": 2 + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 } - }, + } + }, + { + "type": "Keyword", + "value": "return", "range": [ 29, 35 ], - "type": "Keyword", - "value": "return" - }, - { "loc": { - "end": { - "column": 12, - "line": 2 - }, "start": { - "column": 11, - "line": 2 + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 10 } - }, + } + }, + { + "type": "Identifier", + "value": "b", "range": [ 36, 37 ], - "type": "Identifier", - "value": "b" - }, - { "loc": { - "end": { - "column": 13, - "line": 2 - }, "start": { - "column": 12, - "line": 2 + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 } - }, + } + }, + { + "type": "Punctuator", + "value": ";", "range": [ 37, 38 ], - "type": "Punctuator", - "value": ";" - }, - { "loc": { - "end": { - "column": 1, - "line": 3 - }, "start": { - "column": 0, - "line": 3 + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 } - }, + } + }, + { + "type": "Punctuator", + "value": "}", "range": [ 39, 40 ], - "type": "Punctuator", - "value": "}" + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } } - ], - "type": "Program" -}; + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/function-with-types.result.js b/tests/fixtures/typescript/basics/function-with-types.result.js index 013a16a..ed35825 100644 --- a/tests/fixtures/typescript/basics/function-with-types.result.js +++ b/tests/fixtures/typescript/basics/function-with-types.result.js @@ -68,7 +68,41 @@ module.exports = { "column": 21 } }, - "name": "name" + "name": "name", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "range": [ + 22, + 28 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 22, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + } } ], "body": { diff --git a/tests/fixtures/typescript/basics/non-null-assertion-operator.result.js b/tests/fixtures/typescript/basics/non-null-assertion-operator.result.js new file mode 100644 index 0000000..fba26ae --- /dev/null +++ b/tests/fixtures/typescript/basics/non-null-assertion-operator.result.js @@ -0,0 +1,762 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "FunctionDeclaration", + "range": [ + 0, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "range": [ + 9, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "name": "processEntity" + }, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "e", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "range": [ + 27, + 33 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "range": [ + 27, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "typeName": { + "type": "Identifier", + "range": [ + 27, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "name": "Entity" + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "range": [ + 35, + 82 + ], + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "range": [ + 41, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "expression": { + "type": "CallExpression", + "range": [ + 41, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "callee": { + "type": "Identifier", + "range": [ + 41, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "validateEntity" + }, + "arguments": [ + { + "type": "Identifier", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "name": "e" + } + ] + } + }, + { + "type": "VariableDeclaration", + "range": [ + 64, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "range": [ + 68, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "id": { + "type": "Identifier", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "name": "s" + }, + "init": { + "type": "MemberExpression", + "range": [ + 72, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "object": { + "type": "TSNonNullExpression", + "range": [ + 72, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "expression": { + "type": "Identifier", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "name": "e" + } + }, + "property": { + "type": "Identifier", + "range": [ + 75, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "name": "name" + }, + "computed": false + } + } + ], + "kind": "let" + } + ] + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "function", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "processEntity", + "range": [ + 9, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "?", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "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": "Entity", + "range": [ + 27, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 34 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 36 + } + } + }, + { + "type": "Identifier", + "value": "validateEntity", + "range": [ + 41, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 64, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "s", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "!", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Identifier", + "value": "name", + "range": [ + 75, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/non-null-assertion-operator.src.ts b/tests/fixtures/typescript/basics/non-null-assertion-operator.src.ts new file mode 100644 index 0000000..18e7385 --- /dev/null +++ b/tests/fixtures/typescript/basics/non-null-assertion-operator.src.ts @@ -0,0 +1,4 @@ +function processEntity(e?: Entity) { + validateEntity(e); + let s = e!.name; +} \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/type-alias-declaration.result.js b/tests/fixtures/typescript/basics/type-alias-declaration.result.js index a3e1830..6e2b01e 100644 --- a/tests/fixtures/typescript/basics/type-alias-declaration.result.js +++ b/tests/fixtures/typescript/basics/type-alias-declaration.result.js @@ -17,23 +17,23 @@ module.exports = { "body": [ { "type": "VariableDeclaration", + "range": [ + 0, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, "kind": "type", "declarations": [ { - "loc": { - "end": { - "column": 37, - "line": 1 - }, - "start": { - "column": 5, - "line": 1 - } - }, - "range": [ - 5, - 37 - ], "type": "VariableDeclarator", "id": { "type": "Identifier", @@ -53,185 +53,185 @@ module.exports = { }, "name": "Result" }, - "typeParameters": { - "loc": { - "end": { - "column": 14, - "line": 1 - }, - "start": { - "column": 11, - "line": 1 - } - }, - "params": [ - { - "loc": { - "end": { - "column": 13, - "line": 1 - }, - "start": { - "column": 12, - "line": 1 - } - }, - "name": "T", - "range": [ - 12, - 13 - ], - "type": "TypeParameter" - } - ], + "init": { + "type": "TSUnionType", "range": [ - 11, - 14 + 17, + 37 ], - "type": "TypeParameterDeclaration" - }, - "init": { "loc": { - "end": { - "column": 37, - "line": 1 - }, "start": { - "column": 17, - "line": 1 + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 37 } }, - "range": [ - 17, - 37 - ], - "type": "TSUnionType", "types": [ { - "loc": { - "end": { - "column": 27, - "line": 1 - }, - "start": { - "column": 17, - "line": 1 - } - }, + "type": "TSTypeReference", "range": [ 17, 27 ], - "type": "TSTypeReference", + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "typeName": { + "type": "Identifier", + "range": [ + 17, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "Success" + }, "typeArguments": [ { - "loc": { - "end": { - "column": 26, - "line": 1 - }, - "start": { - "column": 25, - "line": 1 - } - }, + "type": "TSTypeReference", "range": [ 25, 26 ], - "type": "TSTypeReference", - "typeName": { - "loc": { - "end": { - "column": 26, - "line": 1 - }, - "start": { - "column": 25, - "line": 1 - } + "loc": { + "start": { + "line": 1, + "column": 25 }, - "name": "T", + "end": { + "line": 1, + "column": 26 + } + }, + "typeName": { + "type": "Identifier", "range": [ 25, 26 ], - "type": "Identifier" + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "T" } } + ] + }, + { + "type": "TSTypeReference", + "range": [ + 30, + 37 ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 37 + } + }, "typeName": { + "type": "Identifier", + "range": [ + 30, + 37 + ], "loc": { - "end": { - "column": 24, - "line": 1 - }, "start": { - "column": 17, - "line": 1 + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 37 } }, - "name": "Success", - "range": [ - 17, - 24 - ], - "type": "Identifier" + "name": "Failure" } + } + ] + }, + "range": [ + 5, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "range": [ + 11, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 11 }, + "end": { + "line": 1, + "column": 14 + } + }, + "params": [ { + "type": "TypeParameter", + "range": [ + 12, + 13 + ], "loc": { - "end": { - "column": 37, - "line": 1 - }, "start": { - "column": 30, - "line": 1 + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 } }, - "range": [ - 30, - 37 - ], - "type": "TSTypeReference", - "typeName": { - "loc": { - "end": { - "column": 37, - "line": 1 - }, - "start": { - "column": 30, - "line": 1 - } - }, - "name": "Failure", - "range": [ - 30, - 37 - ], - "type": "Identifier" - } + "name": "T" } ] } } - ], - "range": [ - 0, - 37 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 37 - } - } + ] } ], "sourceType": "script", @@ -453,4 +453,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 new file mode 100644 index 0000000..3414d4c --- /dev/null +++ b/tests/fixtures/typescript/basics/typed-this.result.js @@ -0,0 +1,754 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 89 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "TSInterfaceDeclaration", + "range": [ + 0, + 89 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "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", + "range": [ + 23, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "name": "addClickListener" + }, + "parameters": [ + { + "type": "Identifier", + "range": [ + 40, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "name": "onclick", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 57 + } + }, + "range": [ + 49, + 79 + ], + "typeAnnotation": { + "type": "TSFunctionType", + "range": [ + 49, + 79 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 57 + } + }, + "parameters": [ + { + "type": "Identifier", + "range": [ + 50, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "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", + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 65, + 70 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "range": [ + 65, + 70 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "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 + ], + "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 + ], + "loc": { + "start": { + "line": 2, + "column": 60 + }, + "end": { + "line": 2, + "column": 64 + } + } + } + } + } + ] + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Keyword", + "value": "interface", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "UIElement", + "range": [ + 10, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "addClickListener", + "range": [ + 23, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "onclick", + "range": [ + 40, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "Keyword", + "value": "this", + "range": [ + 50, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + { + "type": "Keyword", + "value": "void", + "range": [ + 56, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + } + } + }, + { + "type": "Identifier", + "value": "e", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + } + } + }, + { + "type": "Identifier", + "value": "Event", + "range": [ + 65, + 70 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 48 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 72, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 52 + } + } + }, + { + "type": "Keyword", + "value": "void", + "range": [ + 75, + 79 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 57 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 2, + "column": 57 + }, + "end": { + "line": 2, + "column": 58 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 2, + "column": 58 + }, + "end": { + "line": 2, + "column": 59 + } + } + }, + { + "type": "Keyword", + "value": "void", + "range": [ + 82, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 60 + }, + "end": { + "line": 2, + "column": 64 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 2, + "column": 64 + }, + "end": { + "line": 2, + "column": 65 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/typed-this.src.ts b/tests/fixtures/typescript/basics/typed-this.src.ts new file mode 100644 index 0000000..3987757 --- /dev/null +++ b/tests/fixtures/typescript/basics/typed-this.src.ts @@ -0,0 +1,3 @@ +interface UIElement { + addClickListener(onclick: (this: void, e: Event) => void): void; +} diff --git a/tests/fixtures/typescript/decorators/class-decorators/class-decorator-factory.result.js b/tests/fixtures/typescript/decorators/class-decorators/class-decorator-factory.result.js index e99d4c2..af4fb36 100644 --- a/tests/fixtures/typescript/decorators/class-decorators/class-decorator-factory.result.js +++ b/tests/fixtures/typescript/decorators/class-decorators/class-decorator-factory.result.js @@ -31,122 +31,6 @@ module.exports = { "column": 21 } }, - "decorators": [ - { - "arguments": [ - { - "loc": { - "end": { - "column": 1, - "line": 3 - }, - "start": { - "column": 11, - "line": 1 - } - }, - "properties": [ - { - "computed": false, - "key": { - "loc": { - "end": { - "column": 12, - "line": 2 - }, - "start": { - "column": 4, - "line": 2 - } - }, - "name": "selector", - "range": [ - 17, - 25 - ], - "type": "Identifier" - }, - "kind": "init", - "loc": { - "end": { - "column": 19, - "line": 2 - }, - "start": { - "column": 4, - "line": 2 - } - }, - "method": false, - "range": [ - 17, - 32 - ], - "shorthand": false, - "type": "Property", - "value": { - "loc": { - "end": { - "column": 19, - "line": 2 - }, - "start": { - "column": 14, - "line": 2 - } - }, - "range": [ - 27, - 32 - ], - "raw": "'foo'", - "type": "Literal", - "value": "foo" - } - } - ], - "range": [ - 11, - 35 - ], - "type": "ObjectExpression" - } - ], - "callee": { - "loc": { - "end": { - "column": 10, - "line": 1 - }, - "start": { - "column": 1, - "line": 1 - } - }, - "name": "Component", - "range": [ - 1, - 10 - ], - "type": "Identifier" - }, - "loc": { - "end": { - "column": 2, - "line": 3 - }, - "start": { - "column": 1, - "line": 1 - } - }, - "range": [ - 1, - 36 - ], - "type": "CallExpression" - } - ], "id": { "type": "Identifier", "range": [ @@ -184,7 +68,123 @@ module.exports = { } }, "superClass": null, - "implements": [] + "implements": [], + "decorators": [ + { + "type": "CallExpression", + "range": [ + 1, + 36 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "range": [ + 1, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": "Component" + }, + "arguments": [ + { + "type": "ObjectExpression", + "range": [ + 11, + 35 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "properties": [ + { + "type": "Property", + "range": [ + 17, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "key": { + "type": "Identifier", + "range": [ + 17, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "name": "selector" + }, + "value": { + "type": "Literal", + "range": [ + 27, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "foo", + "raw": "'foo'" + }, + "computed": false, + "method": false, + "shorthand": false, + "kind": "init" + } + ] + } + ] + } + ] } ], "sourceType": "script", @@ -442,4 +442,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/decorators/class-decorators/class-decorator.result.js b/tests/fixtures/typescript/decorators/class-decorators/class-decorator.result.js index 5216798..c05b767 100644 --- a/tests/fixtures/typescript/decorators/class-decorators/class-decorator.result.js +++ b/tests/fixtures/typescript/decorators/class-decorators/class-decorator.result.js @@ -31,26 +31,6 @@ module.exports = { "column": 12 } }, - "decorators": [ - { - "loc": { - "end": { - "column": 7, - "line": 1 - }, - "start": { - "column": 1, - "line": 1 - } - }, - "name": "sealed", - "range": [ - 1, - 7 - ], - "type": "Identifier" - } - ], "id": { "type": "Identifier", "range": [ @@ -88,7 +68,27 @@ module.exports = { } }, "superClass": null, - "implements": [] + "implements": [], + "decorators": [ + { + "type": "Identifier", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": "sealed" + } + ] } ], "sourceType": "script", @@ -202,4 +202,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-constructor.result.js b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-constructor.result.js index 868671a..8ce99fe 100644 --- a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-constructor.result.js +++ b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-constructor.result.js @@ -17,7 +17,6 @@ module.exports = { "body": [ { "type": "ClassDeclaration", - "decorators": [], "range": [ 0, 115 @@ -108,61 +107,113 @@ module.exports = { } }, "name": "config", - "decorators": [ - { - "arguments": [ - { - "loc": { - "end": { - "column": 34, - "line": 2 - }, - "start": { - "column": 24, - "line": 2 - } - }, - "name": "APP_CONFIG", - "range": [ - 40, - 50 - ], - "type": "Identifier" - } + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "range": [ + 60, + 69 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "range": [ + 60, + 69 ], - "callee": { + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "typeName": { + "type": "Identifier", + "range": [ + 60, + 69 + ], "loc": { - "end": { - "column": 23, - "line": 2 - }, "start": { - "column": 17, - "line": 2 + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 53 } }, - "name": "Inject", + "name": "AppConfig" + } + } + }, + "decorators": [ + { + "type": "CallExpression", + "range": [ + 33, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "callee": { + "type": "Identifier", "range": [ 33, 39 ], - "type": "Identifier" - }, - "loc": { - "end": { - "column": 35, - "line": 2 + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 23 + } }, - "start": { - "column": 17, - "line": 2 - } + "name": "Inject" }, - "range": [ - 33, - 51 - ], - "type": "CallExpression" + "arguments": [ + { + "type": "Identifier", + "range": [ + 40, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "name": "APP_CONFIG" + } + ] } ] } @@ -345,8 +396,8 @@ module.exports = { } } }, - "accessibility": null, "computed": false, + "accessibility": null, "static": false, "kind": "constructor" } @@ -367,7 +418,8 @@ module.exports = { } }, "superClass": null, - "implements": [] + "implements": [], + "decorators": [] } ], "sourceType": "script", @@ -823,4 +875,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.result.js b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.result.js index 7bd76ba..1195e1b 100644 --- a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.result.js +++ b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-instance-member.result.js @@ -141,6 +141,40 @@ module.exports = { } }, "name": "baz", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 40, + 46 + ], + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 40, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 34 + } + } + } + }, "decorators": [ { "type": "CallExpression", diff --git a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-static-member.result.js b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-static-member.result.js index 133ff68..052a238 100644 --- a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-static-member.result.js +++ b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-decorator-static-member.result.js @@ -141,6 +141,40 @@ module.exports = { } }, "name": "baz", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 53, + 59 + ], + "typeAnnotation": { + "type": "TSNumberKeyword", + "range": [ + 53, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + } + }, "decorators": [ { "type": "CallExpression", diff --git a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-instance-member.result.js b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-instance-member.result.js index fe8711c..4737dab 100644 --- a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-instance-member.result.js +++ b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-instance-member.result.js @@ -251,6 +251,40 @@ module.exports = { } }, "name": "name", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 42, + 48 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 42, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + } + } + }, "decorators": [ { "type": "Identifier", diff --git a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-static-member.result.js b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-static-member.result.js index 9804895..552b0c1 100644 --- a/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-static-member.result.js +++ b/tests/fixtures/typescript/decorators/parameter-decorators/parameter-decorator-static-member.result.js @@ -251,6 +251,40 @@ module.exports = { } }, "name": "name", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "range": [ + 55, + 61 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 55, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 39 + } + } + } + }, "decorators": [ { "type": "Identifier", diff --git a/tests/fixtures/typescript/basics/declare-namespace-with-exported-function.result.js b/tests/fixtures/typescript/namespaces-and-modules/declare-namespace-with-exported-function.result.js similarity index 89% rename from tests/fixtures/typescript/basics/declare-namespace-with-exported-function.result.js rename to tests/fixtures/typescript/namespaces-and-modules/declare-namespace-with-exported-function.result.js index c8de4ab..9768931 100644 --- a/tests/fixtures/typescript/basics/declare-namespace-with-exported-function.result.js +++ b/tests/fixtures/typescript/namespaces-and-modules/declare-namespace-with-exported-function.result.js @@ -140,7 +140,41 @@ module.exports = { "column": 33 } }, - "name": "selector" + "name": "selector", + "typeAnnotation": { + "type": "TypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 58, + 64 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 58, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 41 + } + } + } + } } ], "body": null, @@ -582,4 +616,4 @@ module.exports = { } } ] -}; +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/basics/declare-namespace-with-exported-function.src.ts b/tests/fixtures/typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts similarity index 100% rename from tests/fixtures/typescript/basics/declare-namespace-with-exported-function.src.ts rename to tests/fixtures/typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts diff --git a/tests/fixtures/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.result.js b/tests/fixtures/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.result.js new file mode 100644 index 0000000..1321865 --- /dev/null +++ b/tests/fixtures/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.result.js @@ -0,0 +1,149 @@ +module.exports = { + "type": "Program", + "range": [ + 0, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "body": [ + { + "type": "TSModuleDeclaration", + "range": [ + 0, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "modifiers": [ + { + "type": "TSDeclareKeyword", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + } + ], + "name": { + "type": "Literal", + "range": [ + 15, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "value": "hot-new-module", + "raw": "\"hot-new-module\"" + } + } + ], + "sourceType": "script", + "tokens": [ + { + "type": "Identifier", + "value": "declare", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "module", + "range": [ + 8, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + { + "type": "String", + "value": "\"hot-new-module\"", + "range": [ + 15, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + } + } + ] +}; \ No newline at end of file diff --git a/tests/fixtures/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts b/tests/fixtures/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts new file mode 100644 index 0000000..b8df95b --- /dev/null +++ b/tests/fixtures/typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts @@ -0,0 +1 @@ +declare module "hot-new-module";