Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build(deps): Bump @typescript-eslint/typescript-estree from 3.10.1 to 4.0.1 #9119

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@babel/parser": "7.11.2",
"@glimmer/syntax": "0.60.0",
"@iarna/toml": "2.2.5",
"@typescript-eslint/typescript-estree": "3.10.1",
"@typescript-eslint/typescript-estree": "4.0.1",
"angular-estree-parser": "2.2.0",
"angular-html-parser": "1.7.1",
"camelcase": "6.0.0",
Expand Down
20 changes: 20 additions & 0 deletions src/language-js/postprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function postprocess(ast, options) {

ast = visitNode(ast, (node) => {
switch (node.type) {
case "ChainExpression": {
return transformChainExpression(node.expression);
}
case "LogicalExpression": {
// We remove unneeded parens around same-operator LogicalExpressions
if (isUnbalancedLogicalTree(node)) {
Expand Down Expand Up @@ -188,4 +191,21 @@ function includeShebang(ast, options) {
}
}

// This is a workaround to transform `ChainExpression` from `typescript-estree` into
// `babel` shape AST, we should do the opposite, since `ChainExpression` is the
// standard `estree` AST for `optional chaining`
// https://github.com/estree/estree/blob/master/es2020.md
function transformChainExpression(node) {
if (node.type === "CallExpression") {
node.type = "OptionalCallExpression";
node.callee = transformChainExpression(node.callee);
} else if (node.type === "MemberExpression") {
node.type = "OptionalMemberExpression";
node.object = transformChainExpression(node.object);
} else if (node.type === "TSNonNullExpression") {
node.expression = transformChainExpression(node.expression);
}
Comment on lines +205 to +207
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with typescript, but is it possible to have other types inside ChainExpression?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering is this a mistake in parser? ChainExpression should be the root of optional chaining.

Shouldn't it be TSNonNullExpression > ChainExpression?

Copy link
Member

@fisker fisker Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradzacher

What should this c?.d! be? The estree says

The ChainExpression node contains one or more ChainElement nodes that are optional:true.

https://github.com/estree/estree/blob/master/es2020.md#chainexpression

But in this case TSNonNullExpression is not ChainElement.

I'm not familiar with typescript, is this c?.d! mean d is non-null, and (c?.d)! mean c.d is non-null?

If it's correct, shouldn't TSNonNullExpression be the MemberExpression.property?


Update: as I see on prettier playground, (a?.b!).c (a?.b)!.c are the same, so I think the AST should be TSNonNullExpression > ChainExpression

Copy link

@bradzacher bradzacher Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mirrored babel's (v7.11.3) implementation here.
This is the same AST they produce. typescript-eslint/typescript-eslint#2380


input code:

(a?.b!).c;
(a?.b)!.c;
`@babel/parser` @ `7.11.3`
{
  "type": "Program",
  "start": 0,
  "end": 21,
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 2,
      "column": 10
    }
  },
  "sourceType": "module",
  "interpreter": null,
  "body": [
    {
      "type": "ExpressionStatement",
      "start": 0,
      "end": 10,
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 10
        }
      },
      "expression": {
        "type": "MemberExpression",
        "start": 0,
        "end": 9,
        "loc": {
          "start": {
            "line": 1,
            "column": 0
          },
          "end": {
            "line": 1,
            "column": 9
          }
        },
        "object": {
          "type": "ChainExpression",
          "start": 1,
          "end": 6,
          "loc": {
            "start": {
              "line": 1,
              "column": 1
            },
            "end": {
              "line": 1,
              "column": 6
            }
          },
          "expression": {
            "type": "TSNonNullExpression",
            "start": 1,
            "end": 6,
            "loc": {
              "start": {
                "line": 1,
                "column": 1
              },
              "end": {
                "line": 1,
                "column": 6
              }
            },
            "expression": {
              "type": "MemberExpression",
              "start": 1,
              "end": 5,
              "loc": {
                "start": {
                  "line": 1,
                  "column": 1
                },
                "end": {
                  "line": 1,
                  "column": 5
                }
              },
              "object": {
                "type": "Identifier",
                "start": 1,
                "end": 2,
                "loc": {
                  "start": {
                    "line": 1,
                    "column": 1
                  },
                  "end": {
                    "line": 1,
                    "column": 2
                  },
                  "identifierName": "a"
                },
                "name": "a"
              },
              "computed": false,
              "property": {
                "type": "Identifier",
                "start": 4,
                "end": 5,
                "loc": {
                  "start": {
                    "line": 1,
                    "column": 4
                  },
                  "end": {
                    "line": 1,
                    "column": 5
                  },
                  "identifierName": "b"
                },
                "name": "b"
              },
              "optional": true
            }
          },
          "extra": {
            "parenthesized": true,
            "parenStart": 0
          }
        },
        "computed": false,
        "property": {
          "type": "Identifier",
          "start": 8,
          "end": 9,
          "loc": {
            "start": {
              "line": 1,
              "column": 8
            },
            "end": {
              "line": 1,
              "column": 9
            },
            "identifierName": "c"
          },
          "name": "c"
        },
        "optional": false
      }
    },
    {
      "type": "ExpressionStatement",
      "start": 11,
      "end": 21,
      "loc": {
        "start": {
          "line": 2,
          "column": 0
        },
        "end": {
          "line": 2,
          "column": 10
        }
      },
      "expression": {
        "type": "MemberExpression",
        "start": 11,
        "end": 20,
        "loc": {
          "start": {
            "line": 2,
            "column": 0
          },
          "end": {
            "line": 2,
            "column": 9
          }
        },
        "object": {
          "type": "TSNonNullExpression",
          "start": 11,
          "end": 18,
          "loc": {
            "start": {
              "line": 2,
              "column": 0
            },
            "end": {
              "line": 2,
              "column": 7
            }
          },
          "expression": {
            "type": "ChainExpression",
            "start": 12,
            "end": 16,
            "loc": {
              "start": {
                "line": 2,
                "column": 1
              },
              "end": {
                "line": 2,
                "column": 5
              }
            },
            "expression": {
              "type": "MemberExpression",
              "start": 12,
              "end": 16,
              "loc": {
                "start": {
                  "line": 2,
                  "column": 1
                },
                "end": {
                  "line": 2,
                  "column": 5
                }
              },
              "object": {
                "type": "Identifier",
                "start": 12,
                "end": 13,
                "loc": {
                  "start": {
                    "line": 2,
                    "column": 1
                  },
                  "end": {
                    "line": 2,
                    "column": 2
                  },
                  "identifierName": "a"
                },
                "name": "a"
              },
              "computed": false,
              "property": {
                "type": "Identifier",
                "start": 15,
                "end": 16,
                "loc": {
                  "start": {
                    "line": 2,
                    "column": 4
                  },
                  "end": {
                    "line": 2,
                    "column": 5
                  },
                  "identifierName": "b"
                },
                "name": "b"
              },
              "optional": true
            },
            "extra": {
              "parenthesized": true,
              "parenStart": 11
            }
          }
        },
        "computed": false,
        "property": {
          "type": "Identifier",
          "start": 19,
          "end": 20,
          "loc": {
            "start": {
              "line": 2,
              "column": 8
            },
            "end": {
              "line": 2,
              "column": 9
            },
            "identifierName": "c"
          },
          "name": "c"
        },
        "optional": false
      }
    }
  ]
}
`@typescript-eslint/typescript-estree` @ `4.0.1`
{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "MemberExpression",
        "object": {
          "type": "ChainExpression",
          "expression": {
            "type": "TSNonNullExpression",
            "expression": {
              "type": "MemberExpression",
              "object": {
                "type": "Identifier",
                "name": "a",
                "range": [
                  1,
                  2
                ]
              },
              "property": {
                "type": "Identifier",
                "name": "b",
                "range": [
                  4,
                  5
                ]
              },
              "computed": false,
              "optional": true,
              "range": [
                1,
                5
              ]
            },
            "range": [
              1,
              6
            ]
          },
          "range": [
            1,
            6
          ]
        },
        "property": {
          "type": "Identifier",
          "name": "c",
          "range": [
            8,
            9
          ]
        },
        "computed": false,
        "optional": false,
        "range": [
          0,
          9
        ]
      },
      "range": [
        0,
        10
      ]
    },
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "MemberExpression",
        "object": {
          "type": "TSNonNullExpression",
          "expression": {
            "type": "ChainExpression",
            "expression": {
              "type": "MemberExpression",
              "object": {
                "type": "Identifier",
                "name": "a",
                "range": [
                  12,
                  13
                ]
              },
              "property": {
                "type": "Identifier",
                "name": "b",
                "range": [
                  15,
                  16
                ]
              },
              "computed": false,
              "optional": true,
              "range": [
                12,
                16
              ]
            },
            "range": [
              12,
              16
            ]
          },
          "range": [
            11,
            18
          ]
        },
        "property": {
          "type": "Identifier",
          "name": "c",
          "range": [
            19,
            20
          ]
        },
        "computed": false,
        "optional": false,
        "range": [
          11,
          20
        ]
      },
      "range": [
        11,
        21
      ]
    }
  ],
  "sourceType": "script",
  "range": [
    0,
    21
  ]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the information, I'll take a deep look

return node;
}

module.exports = postprocess;
37 changes: 24 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,11 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.10.1.tgz#1d7463fa7c32d8a23ab508a803ca2fe26e758727"
integrity sha512-+3+FCUJIahE9q0lDi1WleYzjCwJs5hIsbugIgnbB+dSCYUxl8L6PwmsyOPFZde2hc1DlTo/xnkOgiTLSyAbHiQ==

"@typescript-eslint/types@4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.0.1.tgz#1cf72582f764931f085cb8230ff215980fe467b2"
integrity sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg==

"@typescript-eslint/typescript-estree@2.34.0":
version "2.34.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz#14aeb6353b39ef0732cc7f1b8285294937cf37d5"
Expand All @@ -1444,26 +1449,27 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/typescript-estree@3.10.1":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.10.1.tgz#fd0061cc38add4fad45136d654408569f365b853"
integrity sha512-QbcXOuq6WYvnB3XPsZpIwztBoquEYLXh2MtwVU+kO8jgYCiv4G5xrSP/1wg4tkvrEE+esZVquIPX/dxPlePk1w==
"@typescript-eslint/typescript-estree@4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.0.1.tgz#29a43c7060641ec51c902d9f50ac7c5866ec479f"
integrity sha512-zGzleORFXrRWRJAMLTB2iJD1IZbCPkg4hsI8mGdpYlKaqzvKYSEWVAYh14eauaR+qIoZVWrXgYSXqLtTlxotiw==
dependencies:
"@typescript-eslint/types" "3.10.1"
"@typescript-eslint/visitor-keys" "3.10.1"
"@typescript-eslint/types" "4.0.1"
"@typescript-eslint/visitor-keys" "4.0.1"
debug "^4.1.1"
glob "^7.1.6"
globby "^11.0.1"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/visitor-keys@3.10.1":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.10.1.tgz#cd4274773e3eb63b2e870ac602274487ecd1e931"
integrity sha512-9JgC82AaQeglebjZMgYR5wgmfUdUc+EitGUUMW8u2nDckaeimzW+VsoLV6FoimPv2id3VQzfjwBxEMVz08ameQ==
"@typescript-eslint/visitor-keys@4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.0.1.tgz#d4e8de62775f2a6db71c7e8539633680039fdd6c"
integrity sha512-yBSqd6FjnTzbg5RUy9J+9kJEyQjTI34JdGMJz+9ttlJzLCnGkBikxw+N5n2VDcc3CesbIEJ0MnZc5uRYnrEnCw==
dependencies:
eslint-visitor-keys "^1.1.0"
"@typescript-eslint/types" "4.0.1"
eslint-visitor-keys "^2.0.0"

"@webassemblyjs/ast@1.9.0":
version "1.9.0"
Expand Down Expand Up @@ -3476,6 +3482,11 @@ eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint-visitor-keys@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8"
integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==

eslint@7.7.0:
version "7.7.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.7.0.tgz#18beba51411927c4b64da0a8ceadefe4030d6073"
Expand Down Expand Up @@ -4049,7 +4060,7 @@ globals@^12.1.0:
dependencies:
type-fest "^0.8.1"

globby@11.0.1:
globby@11.0.1, globby@^11.0.1:
version "11.0.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.1.tgz#9a2bf107a068f3ffeabc49ad702c79ede8cfd357"
integrity sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ==
Expand Down