Repository navigation
Check super() placement for parameter properties with native class fields - #65420
Open
墨梓柒 (DrSmoothl) wants to merge 1 commit into
Open
墨梓柒 (DrSmoothl) wants to merge 1 commit into
墨梓柒 (DrSmoothl) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change enforcing root-level super() calls for parameter properties.
No open issues 🎉
What changed in this PR
Fixes #54445 by enforcing root-level super() calls for parameter properties even when the compiler emits native class fields. The existing class-field checks remain conditional on downlevel emit.
Changes:
- Separates parameter-property checks from the native-class-field guard.
- Adds seven constructor scenarios across six compiler configurations.
- Adds diagnostic and JavaScript baselines covering invalid placement, valid calls, and access to
thisbeforesuper().
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/parameterPropertiesRequireRootLevelSuper.ts |
Adds regression coverage across targets and field modes. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=esnext,usedefineforclassfields=true).js |
Records ESNext native-field emit. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=esnext,usedefineforclassfields=true).errors.txt |
Records ESNext native-field diagnostics. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=esnext,usedefineforclassfields=false).js |
Records ESNext assignment-based emit. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=esnext,usedefineforclassfields=false).errors.txt |
Records ESNext assignment-mode diagnostics. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2022,usedefineforclassfields=true).js |
Records ES2022 native-field emit. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2022,usedefineforclassfields=true).errors.txt |
Records ES2022 native-field diagnostics. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2022,usedefineforclassfields=false).js |
Records ES2022 assignment-based emit. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2022,usedefineforclassfields=false).errors.txt |
Records ES2022 assignment-mode diagnostics. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2021,usedefineforclassfields=true).js |
Records ES2021 property-definition emit. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2021,usedefineforclassfields=true).errors.txt |
Records ES2021 property-definition diagnostics. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2021,usedefineforclassfields=false).js |
Records ES2021 assignment-based emit. |
tsc/testdata/baselines/reference/compiler/parameterPropertiesRequireRootLevelSuper(target=es2021,usedefineforclassfields=false).errors.txt |
Records ES2021 assignment-mode diagnostics. |
tsc/internal/checker/checker.go |
Applies parameter-property placement checks independently of field emit mode and clarifies the comment. |
Review effort: Balanced
This branch has not been deployed
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.
Fixes #54445.
Related prior work: #54475.
Analysis
In
checkConstructorDeclaration,emitStandardClassFieldscurrently gates both the class-field and parameter-property checks. With native class fields, this skips the placement check forsuper()even though parameter-property initialization still accessesthis. A constructor can therefore compile without TS2401 and throw at runtime because that initialization precedes a non-root-levelsuper()call.Fix
Check parameter properties independently of
emitStandardClassFields, retaining the existing guard for class fields. The Boolean structure becomes:Add seven constructor scenarios across ES2021, ES2022, and ESNext, with
useDefineForClassFieldsboth enabled and disabled. They cover conditional, return-expression, and block-nestedsuper()calls, valid root-level calls, ordinary parameters, field initializers, andthisaccess beforesuper(). The last case also verifies the existing TS2376 check now applies to parameter properties with native fields.Use
@noTypesAndSymbols: trueto focus the baselines on diagnostics and JavaScript emit. The six configurations produce twelve baseline files.Validation
The regression test fails with the original checker in the ES2022/ESNext configurations with
useDefineForClassFields: true; all six configurations pass with the fix.npx hereby validate --allnpx hereby tidynpx hereby check:formatAI assistance
I used OpenAI Codex to investigate this issue and write the tests.