-
-
Notifications
You must be signed in to change notification settings - Fork 66
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(parser): handle empty maybeAlias #161
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;
// ...
} |
source/lib/parser.ts
Outdated
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const maybeAlias = checker.getSymbolAtLocation(expression)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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