-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Refactor default import interop #20364
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Copilot <[email protected]>
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.
Pull Request Overview
Refactors the JavaScript module import system to improve overlay locality by making getImportedModuleNode()
local while keeping getImportedModule()
global. This enables better handling of non-standard default import semantics.
- Introduces
isDefaultImport()
andgetImportedModuleNodeIfUnambiguous()
predicates for better default import handling - Refactors
getImportedModuleNode()
to be overlay-local compatible - Updates API graph logic to use the unambiguous variant where needed
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
javascript/ql/lib/semmle/javascript/Modules.qll | Adds new predicates and refactors getImportedModuleNode() documentation and signature |
javascript/ql/lib/semmle/javascript/ES2015Modules.qll | Implements default import detection and updates module node resolution logic |
javascript/ql/lib/semmle/javascript/ApiGraphs.qll | Updates API graph tracking to use unambiguous module node resolution |
pragma[nomagic] | ||
final DataFlow::Node getImportedModuleNodeIfUnambiguous() { | ||
result = this.getImportedModuleNode() and | ||
not ( | ||
this.isDefaultImport() and | ||
this.getImportedModule().(ES2015Module).hasBothNamedAndDefaultExports() | ||
) | ||
} |
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.
[nitpick] The getImportedModuleNodeIfUnambiguous()
method lacks documentation explaining the pragma[nomagic]
directive and why it's necessary for this predicate.
Copilot uses AI. Check for mistakes.
For overlay locality, we want
Import.getImportedModuleNode()
to be local, without necessarily makingImport.getImportedModule()
local.This means
getImportedModuleNode()
shouldn't depend ongetImportedModule()
, but currently some logic for dealing with non-standarddefault
import semantics relies on it.This PR refactors
getImportedModuleNode()
so it can beoverlay[local]
, and introducesgetImportedModuleNodeIfUnambiguous()
which isoverlay[global]
and performs some extra checks to avoid incorrect data flow. Most use-cases can just continue usinggetImportedModuleNode()
.