-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Disallow uninitialised property overrides #33423
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
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ac96739
Disallow uninitialised property overrides
sandersn 70a15bd
Need to add a couple of errors and squash one
sandersn feb0fb6
Everything works so far
sandersn 8686242
Check for constructor initialisation
sandersn 2916c29
change error wording
sandersn 2e5f57c
Improve error wording
sandersn f11f2be
Add codefix to add missing 'declare'
sandersn a8f4610
Merge branch 'master' into disallow-uninitialised-property-override
sandersn fcf0ff1
Allow 'declare' on any uninitialised property decl
sandersn 810f923
Undo code moves
sandersn 6408d7a
Let sleeping dogs lie
sandersn 5ee3271
Correctly set NodeFlags.Ambient
sandersn e0ddced
Remove more unneeded code
sandersn 6a066b9
Update baselines
sandersn a645ca9
Do not error when base parent is interface
sandersn 030c768
Fix base interface check
sandersn 003d041
Add missed baselines
sandersn 1c5f699
Fix new errors in services
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* @internal */ | ||
namespace ts.codefix { | ||
const fixId = "addMissingDeclareProperty"; | ||
const errorCodes = [ | ||
Diagnostics.Property_0_will_overwrite_the_base_property_in_1_Add_a_declare_modifier_or_an_initializer_to_avoid_this.code, | ||
]; | ||
|
||
registerCodeFix({ | ||
errorCodes, | ||
getCodeActions: (context) => { | ||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start)); | ||
if (changes.length > 0) { | ||
return [createCodeFixAction(fixId, changes, Diagnostics.Prefix_with_declare, fixId, Diagnostics.Prefix_all_incorrect_property_declarations_with_declare)]; | ||
} | ||
}, | ||
fixIds: [fixId], | ||
getAllCodeActions: context => { | ||
const fixedNodes = new NodeSet(); | ||
return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start, fixedNodes)); | ||
}, | ||
}); | ||
|
||
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number, fixedNodes?: NodeSet<Node>) { | ||
const token = getTokenAtPosition(sourceFile, pos); | ||
if (!isIdentifier(token)) { | ||
return; | ||
} | ||
const declaration = token.parent; | ||
if (declaration.kind === SyntaxKind.PropertyDeclaration && | ||
(!fixedNodes || fixedNodes.tryAdd(declaration))) { | ||
changeTracker.insertModifierBefore(sourceFile, SyntaxKind.DeclareKeyword, declaration); | ||
} | ||
} | ||
} |
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
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
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
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
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
6 changes: 3 additions & 3 deletions
6
tests/baselines/reference/classExpressionPropertyModifiers.errors.txt
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
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
Oops, something went wrong.
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.
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.
do not require
!
ondeclare x: number
(since it is in fact not even allowed)