TypeScript: Allow non-null and type assertions as lvalues. (Fixes #7638) (#7888)

This commit is contained in:
Michael Mantel
2018-05-09 14:45:50 -07:00
committed by Brian Ng
parent 0d9eef4750
commit 84e76e2d49
11 changed files with 265 additions and 0 deletions

View File

@@ -0,0 +1 @@
(x as number) += 1;

View File

@@ -0,0 +1 @@
x! += 1;

View File

@@ -0,0 +1 @@
x += 1;

View File

@@ -0,0 +1 @@
(<number> x) += 1;

View File

@@ -1941,6 +1941,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
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<Parser>): Class<Parser> =>
);
return;
case "TSAsExpression":
case "TSNonNullExpression":
case "TSTypeAssertion":
this.checkLVal(
expr.expression,
isBinding,

View File

@@ -0,0 +1 @@
x! += 1;

View File

@@ -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": []
}
}

View File

@@ -0,0 +1 @@
(<number> x) += 1;

View File

@@ -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": []
}
}