Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
Alias for commonjs require in JS#39770
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4f9ccd0d692387277d52abcdc2e420aa6edf213707122babdf32ec4ee1e32af4ddb3d058a0b65d885b675a0b09264c8c8655a13b77ce7c8cca5a57be9a355dfebcf0e3ee9b6fa671b456dfbec30c92277dee0561e32df83f4b5124a8419880694890781bec22bfeeeb0ba0d9062e5b182679b0303fb2d47aeb306d2c0b3c9d2ce87283a5206c7897eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -34,9 +34,7 @@ namespace ts.GoToDefinition { | ||
| const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration); | ||
| // For a function, if this is the original function definition, return just sigInfo. | ||
| // If this is the original constructor definition, parent is the class. | ||
| if (typeChecker.getRootSymbols(symbol).some(s => symbolMatchesSignature(s, calledDeclaration)) || | ||
| // TODO: GH#25533 Following check shouldn't be necessary if 'require' is an alias | ||
| symbol.declarations && symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))) { | ||
| if (typeChecker.getRootSymbols(symbol).some(s => symbolMatchesSignature(s, calledDeclaration))) { | ||
| return [sigInfo]; | ||
| } | ||
| else { | ||
| @@ -210,15 +208,6 @@ namespace ts.GoToDefinition { | ||
| return aliased; | ||
| } | ||
| } | ||
| if (symbol && isInJSFile(node)) { | ||
| const requireCall = forEach(symbol.declarations, d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ true) ? d.initializer : undefined); | ||
| if (requireCall) { | ||
| const moduleSymbol = checker.getSymbolAtLocation(requireCall.arguments[0]); | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this ad-hoc code has been replaced by the call to checker.getAliasedSymbol. I just had to add | ||
| if (moduleSymbol) { | ||
| return checker.resolveExternalModuleSymbol(moduleSymbol); | ||
| } | ||
| } | ||
| } | ||
| return symbol; | ||
| } | ||
| @@ -240,6 +229,9 @@ namespace ts.GoToDefinition { | ||
| return true; | ||
| case SyntaxKind.ImportSpecifier: | ||
| return declaration.parent.kind === SyntaxKind.NamedImports; | ||
| case SyntaxKind.BindingElement: | ||
| case SyntaxKind.VariableDeclaration: | ||
| return isInJSFile(declaration) && isRequireVariableDeclaration(declaration, /*requireStringLiteralLikeArgument*/ true); | ||
| default: | ||
| return false; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
note that once this works well enough, we could turn it on in TS as well, which would be pretty great.