Skip to content

Comments

JS: Refactor default import interop#20364

Closed
asgerf wants to merge 4 commits intogithub:mainfrom
asgerf:js/default-interop
Closed

JS: Refactor default import interop#20364
asgerf wants to merge 4 commits intogithub:mainfrom
asgerf:js/default-interop

Conversation

@asgerf
Copy link
Contributor

@asgerf asgerf commented Sep 4, 2025

For overlay locality, we want Import.getImportedModuleNode() to be local, without necessarily making Import.getImportedModule() local.

This means getImportedModuleNode() shouldn't depend on getImportedModule(), but currently some logic for dealing with non-standard default import semantics relies on it.

This PR refactors getImportedModuleNode() so it can be overlay[local], and introduces getImportedModuleNodeIfUnambiguous() which is overlay[global] and performs some extra checks to avoid incorrect data flow. Most use-cases can just continue using getImportedModuleNode().

Copilot AI review requested due to automatic review settings September 4, 2025 11:53
@asgerf asgerf added the no-change-note-required This PR does not need a change note label Sep 4, 2025
@github-actions github-actions bot added the JS label Sep 4, 2025

This comment was marked as outdated.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 4, 2025 12:02
Copy link
Contributor

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

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() and getImportedModuleNodeIfUnambiguous() 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

Comment on lines +228 to +235
pragma[nomagic]
final DataFlow::Node getImportedModuleNodeIfUnambiguous() {
result = this.getImportedModuleNode() and
not (
this.isDefaultImport() and
this.getImportedModule().(ES2015Module).hasBothNamedAndDefaultExports()
)
}
Copy link

Copilot AI Sep 4, 2025

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.
@asgerf asgerf closed this Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JS no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant