diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/as-expression/input.js b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/as-expression/input.js new file mode 100644 index 0000000000..595ffcebf8 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/as-expression/input.js @@ -0,0 +1 @@ +(x as number) += 1; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/as-expression/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/as-expression/output.js new file mode 100644 index 0000000000..7150d6e7aa --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/as-expression/output.js @@ -0,0 +1 @@ +x += 1; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/non-null/input.js b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/non-null/input.js new file mode 100644 index 0000000000..da07f8efdb --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/non-null/input.js @@ -0,0 +1 @@ +x! += 1; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/non-null/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/non-null/output.js new file mode 100644 index 0000000000..7150d6e7aa --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/non-null/output.js @@ -0,0 +1 @@ +x += 1; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/type-assertion/input.js b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/type-assertion/input.js new file mode 100644 index 0000000000..25af225794 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/type-assertion/input.js @@ -0,0 +1 @@ +( x) += 1; diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/type-assertion/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/type-assertion/output.js new file mode 100644 index 0000000000..7150d6e7aa --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/lvalues/type-assertion/output.js @@ -0,0 +1 @@ +x += 1; diff --git a/packages/babylon/src/plugins/typescript.js b/packages/babylon/src/plugins/typescript.js index f1473c5d72..e5494e92bd 100644 --- a/packages/babylon/src/plugins/typescript.js +++ b/packages/babylon/src/plugins/typescript.js @@ -1941,6 +1941,8 @@ export default (superClass: Class): Class => case "TSParameterProperty": return super.toAssignable(node, isBinding, contextDescription); case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": node.expression = this.toAssignable( node.expression, isBinding, @@ -1973,6 +1975,8 @@ export default (superClass: Class): Class => ); return; case "TSAsExpression": + case "TSNonNullExpression": + case "TSTypeAssertion": this.checkLVal( expr.expression, isBinding, diff --git a/packages/babylon/test/fixtures/typescript/cast/null-assertion-and-assign/input.js b/packages/babylon/test/fixtures/typescript/cast/null-assertion-and-assign/input.js new file mode 100644 index 0000000000..da07f8efdb --- /dev/null +++ b/packages/babylon/test/fixtures/typescript/cast/null-assertion-and-assign/input.js @@ -0,0 +1 @@ +x! += 1; diff --git a/packages/babylon/test/fixtures/typescript/cast/null-assertion-and-assign/output.json b/packages/babylon/test/fixtures/typescript/cast/null-assertion-and-assign/output.json new file mode 100644 index 0000000000..01c14c609d --- /dev/null +++ b/packages/babylon/test/fixtures/typescript/cast/null-assertion-and-assign/output.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "operator": "+=", + "left": { + "type": "TSNonNullExpression", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + } + }, + "expression": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "right": { + "type": "NumericLiteral", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "directives": [] + } +} diff --git a/packages/babylon/test/fixtures/typescript/cast/type-assertion-and-assign/input.js b/packages/babylon/test/fixtures/typescript/cast/type-assertion-and-assign/input.js new file mode 100644 index 0000000000..25af225794 --- /dev/null +++ b/packages/babylon/test/fixtures/typescript/cast/type-assertion-and-assign/input.js @@ -0,0 +1 @@ +( x) += 1; diff --git a/packages/babylon/test/fixtures/typescript/cast/type-assertion-and-assign/output.json b/packages/babylon/test/fixtures/typescript/cast/type-assertion-and-assign/output.json new file mode 100644 index 0000000000..944c081bdc --- /dev/null +++ b/packages/babylon/test/fixtures/typescript/cast/type-assertion-and-assign/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "operator": "+=", + "left": { + "type": "TSTypeAssertion", + "start": 2, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start": 2, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + }, + "right": { + "type": "NumericLiteral", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "directives": [] + } +}