Skip to content

Commit 18bdf7b

Browse files
committed
feat(1534): add sealed keyword
1 parent ba3645e commit 18bdf7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1104
-525
lines changed

src/compiler/checker.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12315,6 +12315,7 @@ namespace ts {
1231512315
checkFlags |= (!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) |
1231612316
(modifiers & ModifierFlags.Protected ? CheckFlags.ContainsProtected : 0) |
1231712317
(modifiers & ModifierFlags.Private ? CheckFlags.ContainsPrivate : 0) |
12318+
(modifiers & ModifierFlags.Sealed ? CheckFlags.ContainsSealed : 0) |
1231812319
(modifiers & ModifierFlags.Static ? CheckFlags.ContainsStatic : 0);
1231912320
if (!isPrototypeProperty(prop)) {
1232012321
syntheticFlag = CheckFlags.SyntheticProperty;
@@ -19916,6 +19917,13 @@ namespace ts {
1991619917
return Ternary.False;
1991719918
}
1991819919
}
19920+
else if (targetPropFlags & ModifierFlags.Sealed) {
19921+
if (reportErrors) {
19922+
reportError(Diagnostics.Property_0_is_sealed_in_type_1_that_cannot_be_overridden_in_type_2, symbolToString(targetProp),
19923+
typeToString(target), typeToString(source));
19924+
}
19925+
return Ternary.False;
19926+
}
1991919927
else if (targetPropFlags & ModifierFlags.Protected) {
1992019928
if (!isValidOverrideOf(sourceProp, targetProp)) {
1992119929
if (reportErrors) {
@@ -43123,7 +43131,7 @@ namespace ts {
4312343131
return quickResult;
4312443132
}
4312543133

43126-
let lastStatic: Node | undefined, lastDeclare: Node | undefined, lastAsync: Node | undefined, lastOverride: Node | undefined;
43134+
let lastStatic: Node | undefined, lastDeclare: Node | undefined, lastAsync: Node | undefined, lastOverride: Node | undefined, lastSealed: Node | undefined;
4312743135
let flags = ModifierFlags.None;
4312843136
for (const modifier of node.modifiers!) {
4312943137
if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
@@ -43269,6 +43277,19 @@ namespace ts {
4326943277

4327043278
flags |= ModifierFlags.Default;
4327143279
break;
43280+
case SyntaxKind.SealedKeyword:
43281+
if (flags & ModifierFlags.Sealed) {
43282+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "sealed");
43283+
}
43284+
if (flags & ModifierFlags.Private) {
43285+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "sealed", "private");
43286+
}
43287+
if (flags & ModifierFlags.Abstract) {
43288+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "sealed", "abstract");
43289+
}
43290+
flags |= ModifierFlags.Sealed;
43291+
lastSealed = modifier;
43292+
break;
4327243293
case SyntaxKind.DeclareKeyword:
4327343294
if (flags & ModifierFlags.Ambient) {
4327443295
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "declare");
@@ -43376,6 +43397,9 @@ namespace ts {
4337643397
if (flags & ModifierFlags.Async) {
4337743398
return grammarErrorOnNode(lastAsync!, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
4337843399
}
43400+
if (flags & ModifierFlags.Sealed) {
43401+
return grammarErrorOnNode(lastSealed!, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "sealed");
43402+
}
4337943403
return false;
4338043404
}
4338143405
else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && flags & ModifierFlags.Ambient) {

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,10 @@
34293429
"category": "Error",
34303430
"code": 2837
34313431
},
3432+
"Property '{0}' is sealed in type '{1}' that cannot be overridden in type '{2}'.": {
3433+
"category": "Error",
3434+
"code": 2838
3435+
},
34323436

34333437
"Import declaration '{0}' is using private name '{1}'.": {
34343438
"category": "Error",

src/compiler/factory/nodeFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ namespace ts {
989989
case SyntaxKind.PublicKeyword:
990990
case SyntaxKind.PrivateKeyword:
991991
case SyntaxKind.ProtectedKeyword:
992+
case SyntaxKind.SealedKeyword:
992993
case SyntaxKind.ReadonlyKeyword:
993994
case SyntaxKind.AbstractKeyword:
994995
case SyntaxKind.DeclareKeyword:
@@ -1074,6 +1075,7 @@ namespace ts {
10741075
if (flags & ModifierFlags.Public) result.push(createModifier(SyntaxKind.PublicKeyword));
10751076
if (flags & ModifierFlags.Private) result.push(createModifier(SyntaxKind.PrivateKeyword));
10761077
if (flags & ModifierFlags.Protected) result.push(createModifier(SyntaxKind.ProtectedKeyword));
1078+
if (flags & ModifierFlags.Sealed) result.push(createModifier(SyntaxKind.SealedKeyword));
10771079
if (flags & ModifierFlags.Abstract) result.push(createModifier(SyntaxKind.AbstractKeyword));
10781080
if (flags & ModifierFlags.Static) result.push(createModifier(SyntaxKind.StaticKeyword));
10791081
if (flags & ModifierFlags.Override) result.push(createModifier(SyntaxKind.OverrideKeyword));

src/compiler/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,7 @@ namespace ts {
24102410
case SyntaxKind.PublicKeyword:
24112411
case SyntaxKind.PrivateKeyword:
24122412
case SyntaxKind.ProtectedKeyword:
2413+
case SyntaxKind.SealedKeyword:
24132414
case SyntaxKind.ReadonlyKeyword:
24142415
case SyntaxKind.DeclareKeyword:
24152416
case SyntaxKind.AbstractKeyword:

src/compiler/scanner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ namespace ts {
130130
private: SyntaxKind.PrivateKeyword,
131131
protected: SyntaxKind.ProtectedKeyword,
132132
public: SyntaxKind.PublicKeyword,
133+
sealed: SyntaxKind.SealedKeyword,
133134
override: SyntaxKind.OverrideKeyword,
134135
out: SyntaxKind.OutKeyword,
135136
readonly: SyntaxKind.ReadonlyKeyword,

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ namespace ts {
368368
case SyntaxKind.PublicKeyword:
369369
case SyntaxKind.PrivateKeyword:
370370
case SyntaxKind.ProtectedKeyword:
371+
case SyntaxKind.SealedKeyword:
371372
case SyntaxKind.AbstractKeyword:
372373
case SyntaxKind.OverrideKeyword:
373374
case SyntaxKind.ConstKeyword:

src/compiler/types.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ namespace ts {
156156
ProtectedKeyword,
157157
PublicKeyword,
158158
StaticKeyword,
159+
SealedKeyword,
159160
YieldKeyword,
160161
// Contextual keywords
161162
AbstractKeyword,
@@ -602,6 +603,7 @@ namespace ts {
602603
| SyntaxKind.PrivateKeyword
603604
| SyntaxKind.ProtectedKeyword
604605
| SyntaxKind.PublicKeyword
606+
| SyntaxKind.SealedKeyword
605607
| SyntaxKind.ReadonlyKeyword
606608
| SyntaxKind.OutKeyword
607609
| SyntaxKind.OverrideKeyword
@@ -640,6 +642,7 @@ namespace ts {
640642
| SyntaxKind.PrivateKeyword
641643
| SyntaxKind.ProtectedKeyword
642644
| SyntaxKind.PublicKeyword
645+
| SyntaxKind.SealedKeyword
643646
| SyntaxKind.ReadonlyKeyword
644647
| SyntaxKind.OutKeyword
645648
| SyntaxKind.OverrideKeyword
@@ -813,9 +816,10 @@ namespace ts {
813816
Protected = 1 << 4, // Property/Method
814817
Static = 1 << 5, // Property/Method
815818
Readonly = 1 << 6, // Property/Method
816-
Abstract = 1 << 7, // Class/Method/ConstructSignature
817-
Async = 1 << 8, // Property/Method/Function
818-
Default = 1 << 9, // Function/Class (export default declaration)
819+
Sealed = 1 << 7, // Property/Method
820+
Abstract = 1 << 8, // Class/Method/ConstructSignature
821+
Async = 1 << 9, // Property/Method/Function
822+
Default = 1 << 10, // Function/Class (export default declaration)
819823
Const = 1 << 11, // Const enum
820824
HasComputedJSDocModifiers = 1 << 12, // Indicates the computed modifier flags include modifiers from JSDoc.
821825

@@ -830,9 +834,9 @@ namespace ts {
830834
ParameterPropertyModifier = AccessibilityModifier | Readonly | Override,
831835
NonPublicAccessibilityModifier = Private | Protected,
832836

833-
TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override | In | Out,
837+
TypeScriptModifier = Ambient | Public | Private | Protected | Sealed | Readonly | Abstract | Const | Override | In | Out,
834838
ExportDefault = Export | Default,
835-
All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated | Override | In | Out
839+
All = Export | Ambient | Public | Private | Protected | Sealed | Static | Readonly | Abstract | Async | Default | Const | Deprecated | Override | In | Out
836840
}
837841

838842
export const enum JsxFlags {
@@ -1076,6 +1080,7 @@ namespace ts {
10761080
export type PrivateKeyword = ModifierToken<SyntaxKind.PrivateKeyword>;
10771081
export type ProtectedKeyword = ModifierToken<SyntaxKind.ProtectedKeyword>;
10781082
export type PublicKeyword = ModifierToken<SyntaxKind.PublicKeyword>;
1083+
export type SealedKeyword = ModifierToken<SyntaxKind.SealedKeyword>;
10791084
export type ReadonlyKeyword = ModifierToken<SyntaxKind.ReadonlyKeyword>;
10801085
export type OutKeyword = ModifierToken<SyntaxKind.OutKeyword>;
10811086
export type OverrideKeyword = ModifierToken<SyntaxKind.OverrideKeyword>;
@@ -1096,6 +1101,7 @@ namespace ts {
10961101
| ProtectedKeyword
10971102
| PublicKeyword
10981103
| OutKeyword
1104+
| SealedKeyword
10991105
| OverrideKeyword
11001106
| ReadonlyKeyword
11011107
| StaticKeyword
@@ -5009,15 +5015,17 @@ namespace ts {
50095015
ContainsProtected = 1 << 9, // Synthetic property with protected constituent(s)
50105016
ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s)
50115017
ContainsStatic = 1 << 11, // Synthetic property with static constituent(s)
5012-
Late = 1 << 12, // Late-bound symbol for a computed property with a dynamic name
5013-
ReverseMapped = 1 << 13, // Property of reverse-inferred homomorphic mapped type
5014-
OptionalParameter = 1 << 14, // Optional parameter
5015-
RestParameter = 1 << 15, // Rest parameter
5016-
DeferredType = 1 << 16, // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType`
5017-
HasNeverType = 1 << 17, // Synthetic property with at least one never type in constituents
5018-
Mapped = 1 << 18, // Property of mapped type
5019-
StripOptional = 1 << 19, // Strip optionality in mapped property
5020-
Unresolved = 1 << 20, // Unresolved type alias symbol
5018+
ContainsSealed = 1 << 12,
5019+
5020+
Late = 1 << 13, // Late-bound symbol for a computed property with a dynamic name
5021+
ReverseMapped = 1 << 14, // Property of reverse-inferred homomorphic mapped type
5022+
OptionalParameter = 1 << 15, // Optional parameter
5023+
RestParameter = 1 << 16, // Rest parameter
5024+
DeferredType = 1 << 17, // Calculation of the type of this symbol is deferred due to processing costs, should be fetched with `getTypeOfSymbolWithDeferredType`
5025+
HasNeverType = 1 << 18, // Synthetic property with at least one never type in constituents
5026+
Mapped = 1 << 19, // Property of mapped type
5027+
StripOptional = 1 << 20, // Strip optionality in mapped property
5028+
Unresolved = 1 << 21, // Unresolved type alias symbol
50215029
Synthetic = SyntheticProperty | SyntheticMethod,
50225030
Discriminant = HasNonUniformType | HasLiteralType,
50235031
Partial = ReadPartial | WritePartial

src/compiler/utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4995,6 +4995,7 @@ namespace ts {
49954995
case SyntaxKind.PublicKeyword: return ModifierFlags.Public;
49964996
case SyntaxKind.ProtectedKeyword: return ModifierFlags.Protected;
49974997
case SyntaxKind.PrivateKeyword: return ModifierFlags.Private;
4998+
case SyntaxKind.SealedKeyword: return ModifierFlags.Sealed;
49984999
case SyntaxKind.AbstractKeyword: return ModifierFlags.Abstract;
49995000
case SyntaxKind.ExportKeyword: return ModifierFlags.Export;
50005001
case SyntaxKind.DeclareKeyword: return ModifierFlags.Ambient;
@@ -5535,6 +5536,7 @@ namespace ts {
55355536
const checkFlags = (s as TransientSymbol).checkFlags;
55365537
const accessModifier = checkFlags & CheckFlags.ContainsPrivate ? ModifierFlags.Private :
55375538
checkFlags & CheckFlags.ContainsPublic ? ModifierFlags.Public :
5539+
checkFlags & CheckFlags.ContainsSealed ? ModifierFlags.Sealed :
55385540
ModifierFlags.Protected;
55395541
const staticModifier = checkFlags & CheckFlags.ContainsStatic ? ModifierFlags.Static : 0;
55405542
return accessModifier | staticModifier;

src/compiler/utilitiesPublic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ namespace ts {
11911191
case SyntaxKind.PublicKeyword:
11921192
case SyntaxKind.PrivateKeyword:
11931193
case SyntaxKind.ProtectedKeyword:
1194+
case SyntaxKind.SealedKeyword:
11941195
case SyntaxKind.ReadonlyKeyword:
11951196
case SyntaxKind.StaticKeyword:
11961197
case SyntaxKind.OutKeyword:
@@ -1207,7 +1208,7 @@ namespace ts {
12071208

12081209
/* @internal */
12091210
export function isClassMemberModifier(idToken: SyntaxKind): boolean {
1210-
return isParameterPropertyModifier(idToken) || idToken === SyntaxKind.StaticKeyword || idToken === SyntaxKind.OverrideKeyword;
1211+
return isParameterPropertyModifier(idToken) || idToken === SyntaxKind.SealedKeyword || idToken === SyntaxKind.StaticKeyword || idToken === SyntaxKind.OverrideKeyword;
12111212
}
12121213

12131214
export function isModifier(node: Node): node is Modifier {

src/harness/fourslashInterfaceImpl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ namespace FourSlashInterface {
11991199
case "private":
12001200
case "protected":
12011201
case "public":
1202+
case "sealed":
12021203
case "abstract":
12031204
case "any":
12041205
case "boolean":
@@ -1238,6 +1239,7 @@ namespace FourSlashInterface {
12381239
"protected",
12391240
"public",
12401241
"readonly",
1242+
"sealed",
12411243
"set",
12421244
"static",
12431245
].map(keywordEntry);

src/services/completions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,6 +2938,9 @@ namespace ts.Completions {
29382938
case "private":
29392939
classElementModifierFlags = classElementModifierFlags | ModifierFlags.Private;
29402940
break;
2941+
case "sealed":
2942+
classElementModifierFlags = classElementModifierFlags | ModifierFlags.Sealed;
2943+
break;
29412944
case "static":
29422945
classElementModifierFlags = classElementModifierFlags | ModifierFlags.Static;
29432946
break;
@@ -2951,7 +2954,7 @@ namespace ts.Completions {
29512954
}
29522955

29532956
// No member list for private methods
2954-
if (!(classElementModifierFlags & ModifierFlags.Private)) {
2957+
if (!(classElementModifierFlags & (ModifierFlags.Private | ModifierFlags.Sealed))) {
29552958
// List of property symbols of base type that are not private and already implemented
29562959
const baseTypeNodes = isClassLike(decl) && classElementModifierFlags & ModifierFlags.Override ? singleElementArray(getEffectiveBaseTypeNode(decl)) : getAllSuperTypeNodes(decl);
29572960
const baseSymbols = flatMap(baseTypeNodes, baseTypeNode => {
@@ -3226,6 +3229,7 @@ namespace ts.Completions {
32263229
case SyntaxKind.InterfaceKeyword:
32273230
case SyntaxKind.LetKeyword:
32283231
case SyntaxKind.PrivateKeyword:
3232+
case SyntaxKind.SealedKeyword:
32293233
case SyntaxKind.ProtectedKeyword:
32303234
case SyntaxKind.PublicKeyword:
32313235
case SyntaxKind.StaticKeyword:
@@ -3618,6 +3622,7 @@ namespace ts.Completions {
36183622
case SyntaxKind.PrivateKeyword:
36193623
case SyntaxKind.ProtectedKeyword:
36203624
case SyntaxKind.PublicKeyword:
3625+
case SyntaxKind.SealedKeyword:
36213626
case SyntaxKind.ReadonlyKeyword:
36223627
case SyntaxKind.StringKeyword:
36233628
case SyntaxKind.SymbolKeyword:

0 commit comments

Comments
 (0)