fix(parser): handle empty maybeAlias#161
Conversation
|
Do you have a test case for reproduction? Or could you give a small example? I'm not sure which test it failed on in the |
|
google/zx@2dbf8e8 Seems it fails on any attempt to load a test. Any test. So it's hard to say what exaclty is broken. |
|
Weird. And does this fixing Though |
|
I've checked this point too. Then found this: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const maybeAlias = checker.getSymbolAtLocation(expression);
console.log('!!!', maybeAlias) members: Map(4) {
'__new' => [SymbolObject],
'__call' => [SymbolObject],
'isArray' => [Circular *1],
'prototype' => [SymbolObject]
},
parent: undefined,
mergeId: 7
},
id: 48790
}
!!! undefined
Cannot read properties of undefined (reading 'flags') |
|
Right then, guess it is that. @sindresorhus I assumed here that since we have a valid I'm not sure how to reproduce when the const maybeAlias = checker.getSymbolAtLocation(expression)
if (maybeAlias) {
// ...
} |
|
My first thought was to add fail-fast. But it's not clear to me: should it be just if (!maybeAlias) {
// ...
} |
|
I suppose a const maybeSymbol = checker.getSymbolAtLocation(expression);
if (maybeSymbol) {
const symbol = maybeSymbol.flags & SymbolFlags.Alias ?
checker.getAliasedSymbol(maybeSymbol) :
maybeSymbol;
// ...
} |
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| const maybeAlias = checker.getSymbolAtLocation(expression)!; |
There was a problem hiding this comment.
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | |
| const maybeAlias = checker.getSymbolAtLocation(expression)!; | |
| const maybeAlias = checker.getSymbolAtLocation(expression); |
|
Looks good to me. Leaving a suggestion here for future refactoring: function handleNode(node: CallExpression) {
// ...
const maybeSymbol = checker.getSymbolAtLocation(expression);
if (!maybeSymbol) {
return;
}
// ...
}
function walkNodes(node: Node) {
if (isCallExpression(node)) {
handleNode(node);
}
forEachChild(node, walkNodes);
} |
closes #160