diff --git a/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/input.js b/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/input.js index 360d80c719..f5f2dc3a49 100644 --- a/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/input.js +++ b/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/input.js @@ -1,10 +1 @@ -interface ResponseBody { - name: string - age: number -} - -let response; -(response as ResponseBody) = { - name: 'Alice', - age: 23, -} \ No newline at end of file +(a as number) = 42; \ No newline at end of file diff --git a/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/output.json b/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/output.json index 50b878eb59..7935c94d65 100644 --- a/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/output.json +++ b/packages/babylon/test/fixtures/typescript/cast/assert-and-assign/output.json @@ -1,482 +1,132 @@ { "type": "File", "start": 0, - "end": 131, + "end": 19, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 10, - "column": 1 + "line": 1, + "column": 19 } }, "program": { "type": "Program", "start": 0, - "end": 131, + "end": 19, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 10, - "column": 1 + "line": 1, + "column": 19 } }, "sourceType": "module", "body": [ { - "type": "TSInterfaceDeclaration", + "type": "ExpressionStatement", "start": 0, - "end": 55, + "end": 19, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 10, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 22 - }, - "identifierName": "ResponseBody" - }, - "name": "ResponseBody" - }, - "body": { - "type": "TSInterfaceBody", - "start": 23, - "end": 55, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "TSPropertySignature", - "start": 27, - "end": 39, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 14 - } - }, - "key": { - "type": "Identifier", - "start": 27, - "end": 31, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "name" - }, - "name": "name" - }, - "computed": false, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start": 31, - "end": 39, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 14 - } - }, - "typeAnnotation": { - "type": "TSStringKeyword", - "start": 33, - "end": 39, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 14 - } - } - } - } - }, - { - "type": "TSPropertySignature", - "start": 42, - "end": 53, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 13 - } - }, - "key": { - "type": "Identifier", - "start": 42, - "end": 45, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 5 - }, - "identifierName": "age" - }, - "name": "age" - }, - "computed": false, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start": 45, - "end": 53, - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 13 - } - }, - "typeAnnotation": { - "type": "TSNumberKeyword", - "start": 47, - "end": 53, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 13 - } - } - } - } - } - ] - } - }, - { - "type": "VariableDeclaration", - "start": 57, - "end": 70, - "loc": { - "start": { - "line": 6, - "column": 0 - }, - "end": { - "line": 6, - "column": 13 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 61, - "end": 69, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 12 - } - }, - "id": { - "type": "Identifier", - "start": 61, - "end": 69, - "loc": { - "start": { - "line": 6, - "column": 4 - }, - "end": { - "line": 6, - "column": 12 - }, - "identifierName": "response" - }, - "name": "response" - }, - "init": null - } - ], - "kind": "let" - }, - { - "type": "ExpressionStatement", - "start": 71, - "end": 131, - "loc": { - "start": { - "line": 7, - "column": 0 - }, - "end": { - "line": 10, - "column": 1 + "line": 1, + "column": 19 } }, "expression": { "type": "AssignmentExpression", - "start": 71, - "end": 131, + "start": 0, + "end": 18, "loc": { "start": { - "line": 7, + "line": 1, "column": 0 }, "end": { - "line": 10, - "column": 1 + "line": 1, + "column": 18 } }, "operator": "=", "left": { "type": "TSAsExpression", - "start": 72, - "end": 96, + "start": 1, + "end": 12, "loc": { "start": { - "line": 7, + "line": 1, "column": 1 }, "end": { - "line": 7, - "column": 25 + "line": 1, + "column": 12 } }, "expression": { "type": "Identifier", - "start": 72, - "end": 80, + "start": 1, + "end": 2, "loc": { "start": { - "line": 7, + "line": 1, "column": 1 }, "end": { - "line": 7, - "column": 9 + "line": 1, + "column": 2 }, - "identifierName": "response" + "identifierName": "a" }, - "name": "response" + "name": "a" }, "typeAnnotation": { - "type": "TSTypeReference", - "start": 84, - "end": 96, + "type": "TSNumberKeyword", + "start": 6, + "end": 12, "loc": { "start": { - "line": 7, - "column": 13 + "line": 1, + "column": 6 }, "end": { - "line": 7, - "column": 25 + "line": 1, + "column": 12 } - }, - "typeName": { - "type": "Identifier", - "start": 84, - "end": 96, - "loc": { - "start": { - "line": 7, - "column": 13 - }, - "end": { - "line": 7, - "column": 25 - }, - "identifierName": "ResponseBody" - }, - "name": "ResponseBody" } }, "extra": { "parenthesized": true, - "parenStart": 71 + "parenStart": 0 } }, "right": { - "type": "ObjectExpression", - "start": 100, - "end": 131, + "type": "NumericLiteral", + "start": 16, + "end": 18, "loc": { "start": { - "line": 7, - "column": 29 + "line": 1, + "column": 16 }, "end": { - "line": 10, - "column": 1 + "line": 1, + "column": 18 } }, - "properties": [ - { - "type": "ObjectProperty", - "start": 104, - "end": 117, - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "method": false, - "key": { - "type": "Identifier", - "start": 104, - "end": 108, - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 6 - }, - "identifierName": "name" - }, - "name": "name" - }, - "computed": false, - "shorthand": false, - "value": { - "type": "StringLiteral", - "start": 110, - "end": 117, - "loc": { - "start": { - "line": 8, - "column": 8 - }, - "end": { - "line": 8, - "column": 15 - } - }, - "extra": { - "rawValue": "Alice", - "raw": "'Alice'" - }, - "value": "Alice" - } - }, - { - "type": "ObjectProperty", - "start": 121, - "end": 128, - "loc": { - "start": { - "line": 9, - "column": 2 - }, - "end": { - "line": 9, - "column": 9 - } - }, - "method": false, - "key": { - "type": "Identifier", - "start": 121, - "end": 124, - "loc": { - "start": { - "line": 9, - "column": 2 - }, - "end": { - "line": 9, - "column": 5 - }, - "identifierName": "age" - }, - "name": "age" - }, - "computed": false, - "shorthand": false, - "value": { - "type": "NumericLiteral", - "start": 126, - "end": 128, - "loc": { - "start": { - "line": 9, - "column": 7 - }, - "end": { - "line": 9, - "column": 9 - } - }, - "extra": { - "rawValue": 23, - "raw": "23" - }, - "value": 23 - } - } - ] + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 } } } diff --git a/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/input.js b/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/input.js index 05b1ed46f4..c35da37ddf 100644 --- a/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/input.js +++ b/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/input.js @@ -1,11 +1 @@ -interface A { - name: string -} -interface B extends A { - age: number -} -let a; -(a as A as B) = { - name: 'Alice', - age: 23 -} \ No newline at end of file +(a as number as any) = 42; \ No newline at end of file diff --git a/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/output.json b/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/output.json index 20dd72836a..1548c2f075 100644 --- a/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/output.json +++ b/packages/babylon/test/fixtures/typescript/cast/multiple-assert-and-assign/output.json @@ -1,410 +1,101 @@ { "type": "File", "start": 0, - "end": 124, + "end": 26, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 11, - "column": 1 + "line": 1, + "column": 26 } }, "program": { "type": "Program", "start": 0, - "end": 124, + "end": 26, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 11, - "column": 1 + "line": 1, + "column": 26 } }, "sourceType": "module", "body": [ { - "type": "TSInterfaceDeclaration", + "type": "ExpressionStatement", "start": 0, - "end": 30, + "end": 26, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 3, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 10, - "end": 11, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 11 - }, - "identifierName": "A" - }, - "name": "A" - }, - "body": { - "type": "TSInterfaceBody", - "start": 12, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [ - { - "type": "TSPropertySignature", - "start": 16, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 14 - } - }, - "key": { - "type": "Identifier", - "start": 16, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 6 - }, - "identifierName": "name" - }, - "name": "name" - }, - "computed": false, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start": 20, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 14 - } - }, - "typeAnnotation": { - "type": "TSStringKeyword", - "start": 22, - "end": 28, - "loc": { - "start": { - "line": 2, - "column": 8 - }, - "end": { - "line": 2, - "column": 14 - } - } - } - } - } - ] - } - }, - { - "type": "TSInterfaceDeclaration", - "start": 31, - "end": 70, - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 41, - "end": 42, - "loc": { - "start": { - "line": 4, - "column": 10 - }, - "end": { - "line": 4, - "column": 11 - }, - "identifierName": "B" - }, - "name": "B" - }, - "extends": [ - { - "type": "TSExpressionWithTypeArguments", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 4, - "column": 20 - }, - "end": { - "line": 4, - "column": 21 - } - }, - "expression": { - "type": "Identifier", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 4, - "column": 20 - }, - "end": { - "line": 4, - "column": 21 - }, - "identifierName": "A" - }, - "name": "A" - } - } - ], - "body": { - "type": "TSInterfaceBody", - "start": 53, - "end": 70, - "loc": { - "start": { - "line": 4, - "column": 22 - }, - "end": { - "line": 6, - "column": 1 - } - }, - "body": [ - { - "type": "TSPropertySignature", - "start": 57, - "end": 68, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 13 - } - }, - "key": { - "type": "Identifier", - "start": 57, - "end": 60, - "loc": { - "start": { - "line": 5, - "column": 2 - }, - "end": { - "line": 5, - "column": 5 - }, - "identifierName": "age" - }, - "name": "age" - }, - "computed": false, - "typeAnnotation": { - "type": "TSTypeAnnotation", - "start": 60, - "end": 68, - "loc": { - "start": { - "line": 5, - "column": 5 - }, - "end": { - "line": 5, - "column": 13 - } - }, - "typeAnnotation": { - "type": "TSNumberKeyword", - "start": 62, - "end": 68, - "loc": { - "start": { - "line": 5, - "column": 7 - }, - "end": { - "line": 5, - "column": 13 - } - } - } - } - } - ] - } - }, - { - "type": "VariableDeclaration", - "start": 71, - "end": 77, - "loc": { - "start": { - "line": 7, - "column": 0 - }, - "end": { - "line": 7, - "column": 6 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 75, - "end": 76, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 5 - } - }, - "id": { - "type": "Identifier", - "start": 75, - "end": 76, - "loc": { - "start": { - "line": 7, - "column": 4 - }, - "end": { - "line": 7, - "column": 5 - }, - "identifierName": "a" - }, - "name": "a" - }, - "init": null - } - ], - "kind": "let" - }, - { - "type": "ExpressionStatement", - "start": 78, - "end": 124, - "loc": { - "start": { - "line": 8, - "column": 0 - }, - "end": { - "line": 11, - "column": 1 + "line": 1, + "column": 26 } }, "expression": { "type": "AssignmentExpression", - "start": 78, - "end": 124, + "start": 0, + "end": 25, "loc": { "start": { - "line": 8, + "line": 1, "column": 0 }, "end": { - "line": 11, - "column": 1 + "line": 1, + "column": 25 } }, "operator": "=", "left": { "type": "TSAsExpression", - "start": 79, - "end": 90, + "start": 1, + "end": 19, "loc": { "start": { - "line": 8, + "line": 1, "column": 1 }, "end": { - "line": 8, - "column": 12 + "line": 1, + "column": 19 } }, "expression": { "type": "TSAsExpression", - "start": 79, - "end": 85, + "start": 1, + "end": 12, "loc": { "start": { - "line": 8, + "line": 1, "column": 1 }, "end": { - "line": 8, - "column": 7 + "line": 1, + "column": 12 } }, "expression": { "type": "Identifier", - "start": 79, - "end": 80, + "start": 1, + "end": 2, "loc": { "start": { - "line": 8, + "line": 1, "column": 1 }, "end": { - "line": 8, + "line": 1, "column": 2 }, "identifierName": "a" @@ -412,201 +103,60 @@ "name": "a" }, "typeAnnotation": { - "type": "TSTypeReference", - "start": 84, - "end": 85, + "type": "TSNumberKeyword", + "start": 6, + "end": 12, "loc": { "start": { - "line": 8, + "line": 1, "column": 6 }, "end": { - "line": 8, - "column": 7 + "line": 1, + "column": 12 } - }, - "typeName": { - "type": "Identifier", - "start": 84, - "end": 85, - "loc": { - "start": { - "line": 8, - "column": 6 - }, - "end": { - "line": 8, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" } } }, "typeAnnotation": { - "type": "TSTypeReference", - "start": 89, - "end": 90, + "type": "TSAnyKeyword", + "start": 16, + "end": 19, "loc": { "start": { - "line": 8, - "column": 11 + "line": 1, + "column": 16 }, "end": { - "line": 8, - "column": 12 + "line": 1, + "column": 19 } - }, - "typeName": { - "type": "Identifier", - "start": 89, - "end": 90, - "loc": { - "start": { - "line": 8, - "column": 11 - }, - "end": { - "line": 8, - "column": 12 - }, - "identifierName": "B" - }, - "name": "B" } }, "extra": { "parenthesized": true, - "parenStart": 78 + "parenStart": 0 } }, "right": { - "type": "ObjectExpression", - "start": 94, - "end": 124, + "type": "NumericLiteral", + "start": 23, + "end": 25, "loc": { "start": { - "line": 8, - "column": 16 + "line": 1, + "column": 23 }, "end": { - "line": 11, - "column": 1 + "line": 1, + "column": 25 } }, - "properties": [ - { - "type": "ObjectProperty", - "start": 98, - "end": 111, - "loc": { - "start": { - "line": 9, - "column": 2 - }, - "end": { - "line": 9, - "column": 15 - } - }, - "method": false, - "key": { - "type": "Identifier", - "start": 98, - "end": 102, - "loc": { - "start": { - "line": 9, - "column": 2 - }, - "end": { - "line": 9, - "column": 6 - }, - "identifierName": "name" - }, - "name": "name" - }, - "computed": false, - "shorthand": false, - "value": { - "type": "StringLiteral", - "start": 104, - "end": 111, - "loc": { - "start": { - "line": 9, - "column": 8 - }, - "end": { - "line": 9, - "column": 15 - } - }, - "extra": { - "rawValue": "Alice", - "raw": "'Alice'" - }, - "value": "Alice" - } - }, - { - "type": "ObjectProperty", - "start": 115, - "end": 122, - "loc": { - "start": { - "line": 10, - "column": 2 - }, - "end": { - "line": 10, - "column": 9 - } - }, - "method": false, - "key": { - "type": "Identifier", - "start": 115, - "end": 118, - "loc": { - "start": { - "line": 10, - "column": 2 - }, - "end": { - "line": 10, - "column": 5 - }, - "identifierName": "age" - }, - "name": "age" - }, - "computed": false, - "shorthand": false, - "value": { - "type": "NumericLiteral", - "start": 120, - "end": 122, - "loc": { - "start": { - "line": 10, - "column": 7 - }, - "end": { - "line": 10, - "column": 9 - } - }, - "extra": { - "rawValue": 23, - "raw": "23" - }, - "value": 23 - } - } - ] + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 } } }