fix: Inconsistencies in ESM-style imports of accessibility-modified proper...#63518
Closed
arnavnagzirkar wants to merge 2 commits into
Closed
fix: Inconsistencies in ESM-style imports of accessibility-modified proper...#63518arnavnagzirkar wants to merge 2 commits into
arnavnagzirkar wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds an accessibility check for named imports from CommonJS export = modules when the export is a class and the imported names map to static class members.
Changes:
- Introduces a new compiler test covering named imports from
export =class modules with differing member visibility. - Updates the checker to validate accessibility for
import { … } from "./cjsExportEqualsClass"when those names resolve to class members.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/cases/compiler/namedImportFromCjsClassExportAccessibility.ts | Adds a regression test for importing static class members (public/protected/private) from a CJS export = class. |
| src/compiler/checker.ts | Adds an accessibility check when resolving named imports against export = module exports that are class members. |
Comments suppressed due to low confidence (3)
src/compiler/checker.ts:1
checkPropertyAccessibilityAtLocationreports diagnostics as a side effect. Calling it from this symbol-resolution path can produce duplicate diagnostics or diagnostics in contexts that only intended to query symbols (e.g., language service queries that reuse checker helpers). Prefer moving the accessibility diagnostic emission into the dedicated import-checking path (where other import diagnostics are produced) and keep this helper focused on returning/resolving symbols.
src/compiler/checker.ts:1- The diagnostic location is currently the whole
ImportSpecifiernode (specifier). To make the error squiggle more precise (and consistent with other property-accessibility errors), pass the imported name node (e.g.,name/specifier.nameas appropriate) as the location argument so the diagnostic points at the specific inaccessible import (b/c) rather than the entire specifier.
src/compiler/checker.ts:1 getTypeOfSymbol(targetSymbol)is called multiple times in this block (also at line 4083). Consider storing it in a local (e.g.,const targetType = getTypeOfSymbol(targetSymbol);) and reusing it for bothgetPropertyOfType(...)andcheckPropertyAccessibilityAtLocation(...)to avoid repeated work in hot paths.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix for issue #62519.
Issue
Fixes #62519
Issue URL: #62519
Changes
Testing
Agent ran relevant tests during development
Linting checks passed
Changes are minimal and focused on the issue