Skip to content

Commit

Permalink
feat(typescript-estree): support short-circuiting assignment operators (
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Jul 19, 2020
1 parent b5afe9c commit 2c90d9f
Show file tree
Hide file tree
Showing 10 changed files with 862 additions and 7 deletions.
318 changes: 318 additions & 0 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Expand Up @@ -31910,6 +31910,324 @@ Object {
}
`;

exports[`typescript fixtures/basics/short-circuiting-assignment-and-and.src 1`] = `
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
9,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
9,
],
"type": "Program",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [
Object {
"$id": 0,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "a",
"range": Array [
0,
1,
],
"type": "Identifier",
},
"kind": "rw",
"resolved": null,
"writeExpr": Object {
"name": "b",
"range": Array [
6,
7,
],
"type": "Identifier",
},
},
Object {
"$id": 1,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "b",
"range": Array [
6,
7,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "module",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {},
"variableScope": Object {
"$ref": 2,
},
"variables": Array [],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/basics/short-circuiting-assignment-or-or.src 1`] = `
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
9,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
9,
],
"type": "Program",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [
Object {
"$id": 0,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "a",
"range": Array [
0,
1,
],
"type": "Identifier",
},
"kind": "rw",
"resolved": null,
"writeExpr": Object {
"name": "b",
"range": Array [
6,
7,
],
"type": "Identifier",
},
},
Object {
"$id": 1,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "b",
"range": Array [
6,
7,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "module",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {},
"variableScope": Object {
"$ref": 2,
},
"variables": Array [],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/basics/short-circuiting-assignment-question-question.src 1`] = `
Object {
"$id": 3,
"block": Object {
"range": Array [
0,
9,
],
"type": "Program",
},
"childScopes": Array [
Object {
"$id": 2,
"block": Object {
"range": Array [
0,
9,
],
"type": "Program",
},
"childScopes": Array [],
"functionExpressionScope": false,
"isStrict": true,
"references": Array [
Object {
"$id": 0,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "a",
"range": Array [
0,
1,
],
"type": "Identifier",
},
"kind": "rw",
"resolved": null,
"writeExpr": Object {
"name": "b",
"range": Array [
6,
7,
],
"type": "Identifier",
},
},
Object {
"$id": 1,
"from": Object {
"$ref": 2,
},
"identifier": Object {
"name": "b",
"range": Array [
6,
7,
],
"type": "Identifier",
},
"kind": "r",
"resolved": null,
"writeExpr": undefined,
},
],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "module",
"upperScope": Object {
"$ref": 3,
},
"variableMap": Object {},
"variableScope": Object {
"$ref": 2,
},
"variables": Array [],
},
],
"functionExpressionScope": false,
"isStrict": false,
"references": Array [],
"throughReferences": Array [
Object {
"$ref": 0,
},
Object {
"$ref": 1,
},
],
"type": "global",
"upperScope": null,
"variableMap": Object {},
"variableScope": Object {
"$ref": 3,
},
"variables": Array [],
}
`;

exports[`typescript fixtures/basics/symbol-type-param.src 1`] = `
Object {
"$id": 5,
Expand Down
@@ -0,0 +1 @@
a ||= b;
@@ -0,0 +1 @@
a &&= b;
@@ -0,0 +1 @@
a ??= b;
17 changes: 17 additions & 0 deletions packages/types/src/ts-estree.ts
Expand Up @@ -764,6 +764,23 @@ export interface ArrowFunctionExpression extends BaseNode {

export interface AssignmentExpression extends BinaryExpressionBase {
type: AST_NODE_TYPES.AssignmentExpression;
operator:
| '-='
| '??='
| '**='
| '*='
| '/='
| '&&='
| '&='
| '%='
| '^='
| '+='
| '<<='
| '='
| '>>='
| '>>>='
| '|='
| '||=';
}

export interface AssignmentPattern extends BaseNode {
Expand Down
15 changes: 8 additions & 7 deletions packages/typescript-estree/tests/ast-alignment/parse.ts
Expand Up @@ -21,18 +21,19 @@ function createError(
function parseWithBabelParser(text: string, jsx = true): any {
const babel = require('@babel/parser');
const plugins: ParserPlugin[] = [
'typescript',
'objectRestSpread',
'decorators-legacy',
'classProperties',
'asyncGenerators',
'bigInt',
'classProperties',
'decorators-legacy',
'dynamicImport',
'estree',
'bigInt',
'numericSeparator',
'importMeta',
'optionalChaining',
'logicalAssignment',
'nullishCoalescingOperator',
'numericSeparator',
'objectRestSpread',
'optionalChaining',
'typescript',
];
if (jsx) {
plugins.push('jsx');
Expand Down
Expand Up @@ -2038,6 +2038,12 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/readonly-tuples.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/short-circuiting-assignment-and-and.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/short-circuiting-assignment-or-or.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/short-circuiting-assignment-question-question.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/symbol-type-param.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/type-alias-declaration.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down

0 comments on commit 2c90d9f

Please sign in to comment.