Skip to content

Fix code that should have used IsRequireCall #1195

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

Merged
merged 3 commits into from
Jun 16, 2025

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Jun 16, 2025

IsVariableDeclarationInitializedToRequire is not an equivalent replacement for IsRequireCall. They have differing behavior.

Noticed some of this in looking at new errors exposed by #1189.

Best to filter this PR to just diffs.

@jakebailey jakebailey requested review from sandersn and Copilot June 16, 2025 02:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR corrects module resolution by using IsRequireCall instead of IsVariableDeclarationInitializedToRequire, ensuring that all require(...) calls are properly recognized rather than only those in variable declarations.

  • Replace IsVariableDeclarationInitializedToRequire checks with IsRequireCall in utilities, binder, and checker.
  • Refine resolveExternalModule to detect require calls via initializer on variable declarations.
  • Update baselines to reflect the new symbol and error expectations for JSON and module imports.

Reviewed Changes

Copilot reviewed 92 out of 92 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/ls/utilities.go Use IsRequireCall to detect require calls in JS files
internal/checker/checker.go Swap out variable-init checks for IsRequireCall and IsInJSFile
internal/binder/nameresolver.go Refactor require detection to use IsRequireCall
internal/binder/binder.go Mark CommonJS modules on raw require calls, not var inits
testdata/.../requireOfJsonFileInJsFile.* Update baselines for JSON require behavior
testdata/.../modulePreserve4.* Update baselines for module preserve output
testdata/.../jsExportMemberMerged...* Refresh symbol and error baselines for exports
testdata/.../importNonExportedMember12.* Reflect updated import baselines for require calls

->require("./something").o : Symbol(o, Decl(something.ts, 0, 12))
->require : Symbol(require)
>require("./something").o : Symbol(o, Decl(something.ts, 0, 12))
>require : Symbol(require)
->"./something" : Symbol("something", Decl(something.ts, 0, 0))
Copy link
Member Author

Choose a reason for hiding this comment

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

Still missing something here, as this is mad about the actual string not having resolved to the other module (which would break something like go to def).

Copy link
Member

@weswigham weswigham Jun 16, 2025

Choose a reason for hiding this comment

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

It's probably still missing because getSymbolAtLocation doesn't support js declaration lookups yet (since it's bound entirely differently), or something similar.

-/main3.cjs(17,8): error TS1293: ESM syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
-
-
+/main3.cjs(1,13): error TS1293: ESM syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is probably a piece of the checker that hasn't been updated to ignore reparsed exports.

->require("./something").o : Symbol(o, Decl(something.ts, 0, 12))
->require : Symbol(require)
>require("./something").o : Symbol(o, Decl(something.ts, 0, 12))
>require : Symbol(require)
->"./something" : Symbol("something", Decl(something.ts, 0, 0))
Copy link
Member

@weswigham weswigham Jun 16, 2025

Choose a reason for hiding this comment

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

It's probably still missing because getSymbolAtLocation doesn't support js declaration lookups yet (since it's bound entirely differently), or something similar.

@jakebailey jakebailey added this pull request to the merge queue Jun 16, 2025
Merged via the queue into main with commit 06b2c40 Jun 16, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/fix-is-require-callers branch June 16, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants