diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 56ee20ad70021..c474370d6fa9e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -36618,7 +36618,8 @@ namespace ts { checkClassForDuplicateDeclarations(node); // Only check for reserved static identifiers on non-ambient context. - if (!(node.flags & NodeFlags.Ambient)) { + const nodeInAmbientContext = !!(node.flags & NodeFlags.Ambient); + if (!nodeInAmbientContext) { checkClassForStaticPropertyNameConflicts(node); } @@ -36682,6 +36683,8 @@ namespace ts { } } + checkMembersForMissingOverrideModifier(node, type, typeWithThis); + const implementedTypeNodes = getEffectiveImplementsTypeNodes(node); if (implementedTypeNodes) { for (const typeRefNode of implementedTypeNodes) { @@ -36716,6 +36719,60 @@ namespace ts { } } + function checkMembersForMissingOverrideModifier(node: ClassLikeDeclaration, type: InterfaceType, typeWithThis: Type) { + const nodeInAmbientContext = !!(node.flags & NodeFlags.Ambient); + const baseTypeNode = getEffectiveBaseTypeNode(node); + const baseTypes = baseTypeNode && getBaseTypes(type); + const baseWithThis = baseTypes?.length ? getTypeWithThisArgument(first(baseTypes), type.thisType) : undefined; + + for (const member of node.members) { + if (isConstructorDeclaration(member)) { + forEach(member.parameters, param => { + if (isParameterPropertyDeclaration(param, member)) { + checkClassMember(param, /*memberIsParameterProperty*/ true); + } + }); + } + checkClassMember(member); + } + function checkClassMember(member: ClassElement | ParameterPropertyDeclaration, memberIsParameterProperty?: boolean) { + const hasOverride = hasOverrideModifier(member); + if (baseWithThis && (hasOverride || compilerOptions.noImplicitOverride)) { + const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member); + if (!declaredProp) { + return; + } + + const baseClassName = typeToString(baseWithThis); + const prop = getPropertyOfType(typeWithThis, declaredProp.escapedName); + const baseProp = getPropertyOfType(baseWithThis, declaredProp.escapedName); + if (prop && !baseProp && hasOverride) { + error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0, baseClassName); + } + else if (prop && baseProp?.valueDeclaration && compilerOptions.noImplicitOverride && !nodeInAmbientContext) { + const baseHasAbstract = hasAbstractModifier(baseProp.valueDeclaration); + if (hasOverride) { + return; + } + + if (!baseHasAbstract) { + const diag = memberIsParameterProperty ? + Diagnostics.This_parameter_property_must_be_rewritten_as_a_property_declaration_with_an_override_modifier_because_it_overrides_a_member_in_base_class_0 : + Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0; + error(member, diag, baseClassName); + } + else if (hasAbstractModifier(member) && baseHasAbstract) { + error(member, Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0, baseClassName); + } + } + } + else if (hasOverride) { + const className = typeToString(type); + error(member, Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class, className); + } + } + } + function issueMemberSpecificError(node: ClassLikeDeclaration, typeWithThis: Type, baseWithThis: Type, broadDiag: DiagnosticMessage) { // iterate over all implemented properties and issue errors on each one which isn't compatible, rather than the class as a whole, if possible let issuedMemberError = false; @@ -40090,7 +40147,7 @@ namespace ts { return quickResult; } - let lastStatic: Node | undefined, lastDeclare: Node | undefined, lastAsync: Node | undefined, lastReadonly: Node | undefined; + let lastStatic: Node | undefined, lastDeclare: Node | undefined, lastAsync: Node | undefined, lastReadonly: Node | undefined, lastOverride: Node | undefined; let flags = ModifierFlags.None; for (const modifier of node.modifiers!) { if (modifier.kind !== SyntaxKind.ReadonlyKeyword) { @@ -40107,6 +40164,23 @@ namespace ts { return grammarErrorOnNode(node, Diagnostics.A_class_member_cannot_have_the_0_keyword, tokenToString(SyntaxKind.ConstKeyword)); } break; + case SyntaxKind.OverrideKeyword: + if (flags & ModifierFlags.Override) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "override"); + } + else if (flags & ModifierFlags.Ambient) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "override", "declare"); + } + else if (flags & ModifierFlags.Static) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "override"); + } + if (node.kind === SyntaxKind.Parameter) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "override"); + } + flags |= ModifierFlags.Override; + lastOverride = modifier; + break; + case SyntaxKind.PublicKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PrivateKeyword: @@ -40115,6 +40189,9 @@ namespace ts { if (flags & ModifierFlags.AccessibilityModifier) { return grammarErrorOnNode(modifier, Diagnostics.Accessibility_modifier_already_seen); } + else if (compilerOptions.noImplicitOverride && flags & ModifierFlags.Override) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "override"); + } else if (flags & ModifierFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } @@ -40148,6 +40225,9 @@ namespace ts { else if (flags & ModifierFlags.Readonly) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "readonly"); } + else if (compilerOptions.noImplicitOverride && flags & ModifierFlags.Override) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "override"); + } else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } @@ -40212,6 +40292,9 @@ namespace ts { else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async"); } + else if (compilerOptions.noImplicitOverride && flags & ModifierFlags.Override) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "override"); + } else if (isClassLike(node.parent) && !isPropertyDeclaration(node)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_class_elements_of_this_kind, "declare"); } @@ -40286,6 +40369,9 @@ namespace ts { if (flags & ModifierFlags.Abstract) { return grammarErrorOnNode(lastStatic!, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); // TODO: GH#18217 } + if (compilerOptions.noImplicitOverride && flags & ModifierFlags.Override) { + return grammarErrorOnNode(lastOverride!, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "override"); // TODO: GH#18217 + } else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(lastAsync!, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async"); } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 266fad21549fe..ac2d9d4acbce3 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -675,6 +675,14 @@ namespace ts { category: Diagnostics.Additional_Checks, description: Diagnostics.Include_undefined_in_index_signature_results }, + { + name: "noImplicitOverride", + type: "boolean", + affectsSemanticDiagnostics: true, + showInSimplifiedHelpView: false, + category: Diagnostics.Additional_Checks, + description: Diagnostics.Ensure_overriding_members_in_derived_classes_are_marked_with_an_override_modifier + }, { name: "noPropertyAccessFromIndexSignature", type: "boolean", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e204c9ee09720..b3d1b4d1f3c7f 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3685,6 +3685,26 @@ "category": "Error", "code": 4111 }, + "This member cannot have an 'override' modifier because its containing class '{0}' does not extend another class.": { + "category": "Error", + "code": 4112 + }, + "This member cannot have an 'override' modifier because it is not declared in the base class '{0}'.": { + "category": "Error", + "code": 4113 + }, + "This member must have an 'override' modifier because it overrides a member in the base class '{0}'.": { + "category": "Error", + "code": 4114 + }, + "This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class '{0}'.": { + "category": "Error", + "code": 4115 + }, + "This member must have an 'override' modifier because it overrides an abstract method that is declared in the base class '{0}'.": { + "category": "Error", + "code": 4116 + }, "The current host does not support the '{0}' option.": { "category": "Error", @@ -5018,15 +5038,19 @@ "category": "Message", "code": 6505 }, - "Require undeclared properties from index signatures to use element accesses.": { - "category": "Error", - "code": 6803 - }, "Include 'undefined' in index signature results": { "category": "Message", "code": 6800 }, + "Ensure overriding members in derived classes are marked with an 'override' modifier.": { + "category": "Message", + "code": 6801 + }, + "Require undeclared properties from index signatures to use element accesses.": { + "category": "Message", + "code": 6802 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", @@ -6301,6 +6325,22 @@ "category": "Message", "code": 95159 }, + "Add 'override' modifier": { + "category": "Message", + "code": 95160 + }, + "Remove 'override' modifier": { + "category": "Message", + "code": 95161 + }, + "Add all missing 'override' modifiers": { + "category": "Message", + "code": 95162 + }, + "Remove all unnecessary 'override' modifiers": { + "category": "Message", + "code": 95163 + }, "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index d7f3c1aeb672c..e443d4d0bdafb 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -368,6 +368,8 @@ namespace ts { get updateJSDocProtectedTag() { return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocProtectedTag); }, get createJSDocReadonlyTag() { return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocReadonlyTag); }, get updateJSDocReadonlyTag() { return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocReadonlyTag); }, + get createJSDocOverrideTag() { return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocOverrideTag); }, + get updateJSDocOverrideTag() { return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocOverrideTag); }, get createJSDocDeprecatedTag() { return getJSDocSimpleTagCreateFunction(SyntaxKind.JSDocDeprecatedTag); }, get updateJSDocDeprecatedTag() { return getJSDocSimpleTagUpdateFunction(SyntaxKind.JSDocDeprecatedTag); }, createJSDocUnknownTag, @@ -1041,6 +1043,7 @@ namespace ts { if (flags & ModifierFlags.Static) { result.push(createModifier(SyntaxKind.StaticKeyword)); } if (flags & ModifierFlags.Readonly) { result.push(createModifier(SyntaxKind.ReadonlyKeyword)); } if (flags & ModifierFlags.Async) { result.push(createModifier(SyntaxKind.AsyncKeyword)); } + if (flags & ModifierFlags.Override) { result.push(createModifier(SyntaxKind.OverrideKeyword)); } return result; } @@ -5934,6 +5937,7 @@ namespace ts { case SyntaxKind.JSDocPrivateTag: return "private"; case SyntaxKind.JSDocProtectedTag: return "protected"; case SyntaxKind.JSDocReadonlyTag: return "readonly"; + case SyntaxKind.JSDocOverrideTag: return "override"; case SyntaxKind.JSDocTemplateTag: return "template"; case SyntaxKind.JSDocTypedefTag: return "typedef"; case SyntaxKind.JSDocParameterTag: return "param"; diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index 06757ab363ed8..64a88d32d099e 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -852,6 +852,10 @@ namespace ts { return node.kind === SyntaxKind.JSDocReadonlyTag; } + export function isJSDocOverrideTag(node: Node): node is JSDocOverrideTag { + return node.kind === SyntaxKind.JSDocOverrideTag; + } + export function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag { return node.kind === SyntaxKind.JSDocDeprecatedTag; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a3d069cdad931..42023a26078c8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7542,6 +7542,9 @@ namespace ts { case "readonly": tag = parseSimpleTag(start, factory.createJSDocReadonlyTag, tagName, margin, indentText); break; + case "override": + tag = parseSimpleTag(start, factory.createJSDocOverrideTag, tagName, margin, indentText); + break; case "deprecated": hasDeprecatedTag = true; tag = parseSimpleTag(start, factory.createJSDocDeprecatedTag, tagName, margin, indentText); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8fd327d74ac7a..65e5549c2649d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2138,6 +2138,7 @@ namespace ts { case SyntaxKind.ReadonlyKeyword: case SyntaxKind.DeclareKeyword: case SyntaxKind.AbstractKeyword: + case SyntaxKind.OverrideKeyword: diagnostics.push(createDiagnosticForNode(modifier, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, tokenToString(modifier.kind))); break; diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index ca3290b25e198..79b414d3d4c09 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -127,6 +127,7 @@ namespace ts { private: SyntaxKind.PrivateKeyword, protected: SyntaxKind.ProtectedKeyword, public: SyntaxKind.PublicKeyword, + override: SyntaxKind.OverrideKeyword, readonly: SyntaxKind.ReadonlyKeyword, require: SyntaxKind.RequireKeyword, global: SyntaxKind.GlobalKeyword, diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 849dfcc5ee1f2..260da092081a7 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1540,7 +1540,7 @@ namespace ts { } function ensureModifierFlags(node: Node): ModifierFlags { - let mask = ModifierFlags.All ^ (ModifierFlags.Public | ModifierFlags.Async); // No async modifiers in declaration files + let mask = ModifierFlags.All ^ (ModifierFlags.Public | ModifierFlags.Async | ModifierFlags.Override); // No async and override modifiers in declaration files let additions = (needsDeclare && !isAlwaysType(node)) ? ModifierFlags.Ambient : ModifierFlags.None; const parentIsFile = node.parent.kind === SyntaxKind.SourceFile; if (!parentIsFile || (isBundledEmit && parentIsFile && isExternalModule(node.parent as SourceFile))) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a3afdfbf77c32..c3e24f3d1a1f7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -187,6 +187,7 @@ namespace ts { FromKeyword, GlobalKeyword, BigIntKeyword, + OverrideKeyword, OfKeyword, // LastKeyword and LastToken and LastContextualKeyword // Parse tree nodes @@ -384,6 +385,7 @@ namespace ts { JSDocPrivateTag, JSDocProtectedTag, JSDocReadonlyTag, + JSDocOverrideTag, JSDocCallbackTag, JSDocEnumTag, JSDocParameterTag, @@ -586,6 +588,7 @@ namespace ts { | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword + | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword @@ -621,6 +624,7 @@ namespace ts { | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword + | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword ; @@ -797,6 +801,7 @@ namespace ts { HasComputedJSDocModifiers = 1 << 12, // Indicates the computed modifier flags include modifiers from JSDoc. Deprecated = 1 << 13, // Deprecated tag. + Override = 1 << 14, // Override method. HasComputedFlags = 1 << 29, // Modifier flags have been computed AccessibilityModifier = Public | Private | Protected, @@ -804,9 +809,9 @@ namespace ts { ParameterPropertyModifier = AccessibilityModifier | Readonly, NonPublicAccessibilityModifier = Private | Protected, - TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const, + TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override, ExportDefault = Export | Default, - All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated + All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated | Override } export const enum JsxFlags { @@ -1027,6 +1032,7 @@ namespace ts { export type ProtectedKeyword = ModifierToken; export type PublicKeyword = ModifierToken; export type ReadonlyKeyword = ModifierToken; + export type OverrideKeyword = ModifierToken; export type StaticKeyword = ModifierToken; /** @deprecated Use `ReadonlyKeyword` instead. */ @@ -1042,6 +1048,7 @@ namespace ts { | PrivateKeyword | ProtectedKeyword | PublicKeyword + | OverrideKeyword | ReadonlyKeyword | StaticKeyword ; @@ -3221,6 +3228,10 @@ namespace ts { readonly kind: SyntaxKind.JSDocReadonlyTag; } + export interface JSDocOverrideTag extends JSDocTag { + readonly kind: SyntaxKind.JSDocOverrideTag; + } + export interface JSDocEnumTag extends JSDocTag, Declaration { readonly kind: SyntaxKind.JSDocEnumTag; readonly parent: JSDoc; @@ -5927,6 +5938,7 @@ namespace ts { /*@internal*/ pathsBasePath?: string; /*@internal*/ plugins?: PluginImport[]; preserveConstEnums?: boolean; + noImplicitOverride?: boolean; preserveSymlinks?: boolean; /* @internal */ preserveWatchOutput?: boolean; project?: string; @@ -7244,6 +7256,8 @@ namespace ts { updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray | undefined): JSDocUnknownTag; createJSDocDeprecatedTag(tagName: Identifier, comment?: string | NodeArray): JSDocDeprecatedTag; updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier, comment?: string | NodeArray): JSDocDeprecatedTag; + createJSDocOverrideTag(tagName: Identifier, comment?: string | NodeArray): JSDocOverrideTag; + updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier, comment?: string | NodeArray): JSDocOverrideTag; createJSDocText(text: string): JSDocText; updateJSDocText(node: JSDocText, text: string): JSDocText; createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined): JSDoc; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 49daa87158674..d721a590419db 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4655,6 +4655,18 @@ namespace ts { return hasSyntacticModifier(node, ModifierFlags.Static); } + export function hasOverrideModifier(node: Node): boolean { + return hasEffectiveModifier(node, ModifierFlags.Override); + } + + export function hasAbstractModifier(node: Node): boolean { + return hasSyntacticModifier(node, ModifierFlags.Abstract); + } + + export function hasAmbientModifier(node: Node): boolean { + return hasSyntacticModifier(node, ModifierFlags.Ambient); + } + export function hasEffectiveReadonlyModifier(node: Node): boolean { return hasEffectiveModifier(node, ModifierFlags.Readonly); } @@ -4713,6 +4725,7 @@ namespace ts { if (getJSDocPrivateTagNoCache(node)) flags |= ModifierFlags.Private; if (getJSDocProtectedTagNoCache(node)) flags |= ModifierFlags.Protected; if (getJSDocReadonlyTagNoCache(node)) flags |= ModifierFlags.Readonly; + if (getJSDocOverrideTagNoCache(node)) flags |= ModifierFlags.Override; } if (getJSDocDeprecatedTagNoCache(node)) flags |= ModifierFlags.Deprecated; } @@ -4765,10 +4778,15 @@ namespace ts { case SyntaxKind.DefaultKeyword: return ModifierFlags.Default; case SyntaxKind.AsyncKeyword: return ModifierFlags.Async; case SyntaxKind.ReadonlyKeyword: return ModifierFlags.Readonly; + case SyntaxKind.OverrideKeyword: return ModifierFlags.Override; } return ModifierFlags.None; } + export function createModifiers(modifierFlags: ModifierFlags): ModifiersArray | undefined { + return modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : undefined; + } + export function isLogicalOperator(token: SyntaxKind): boolean { return token === SyntaxKind.BarBarToken || token === SyntaxKind.AmpersandAmpersandToken diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 8285699d08753..6bec2e5f07e86 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -773,6 +773,10 @@ namespace ts { return getFirstJSDocTag(node, isJSDocReadonlyTag, /*noCache*/ true); } + export function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined { + return getFirstJSDocTag(node, isJSDocOverrideTag, /*noCache*/ true); + } + /** Gets the JSDoc deprecated tag for the node if present */ export function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined { return getFirstJSDocTag(node, isJSDocDeprecatedTag); @@ -1174,6 +1178,7 @@ namespace ts { case SyntaxKind.ProtectedKeyword: case SyntaxKind.ReadonlyKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.OverrideKeyword: return true; } return false; @@ -1186,7 +1191,7 @@ namespace ts { /* @internal */ export function isClassMemberModifier(idToken: SyntaxKind): boolean { - return isParameterPropertyModifier(idToken) || idToken === SyntaxKind.StaticKeyword; + return isParameterPropertyModifier(idToken) || idToken === SyntaxKind.StaticKeyword || idToken === SyntaxKind.OverrideKeyword; } export function isModifier(node: Node): node is Modifier { diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 67da4ae6fe3cd..5b0a8e19073f6 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1158,6 +1158,7 @@ namespace FourSlashInterface { case "symbol": case "type": case "unique": + case "override": case "unknown": case "global": case "bigint": @@ -1169,7 +1170,7 @@ namespace FourSlashInterface { } export const classElementKeywords: readonly ExpectedCompletionEntryObject[] = - ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set"].map(keywordEntry); + ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set", "override"].map(keywordEntry); export const classElementInJsKeywords = getInJsKeywords(classElementKeywords); diff --git a/src/services/codeFixProvider.ts b/src/services/codeFixProvider.ts index aee5a199fad5b..5baf4734002fc 100644 --- a/src/services/codeFixProvider.ts +++ b/src/services/codeFixProvider.ts @@ -18,6 +18,10 @@ namespace ts.codefix { return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, diagnosticToString(fixAllDescription), command); } + export function createCodeFixActionMaybeFixAll(fixName: string, changes: FileTextChanges[], description: DiagnosticAndArguments, fixId?: {}, fixAllDescription?: DiagnosticAndArguments, command?: CodeActionCommand) { + return createCodeFixActionWorker(fixName, diagnosticToString(description), changes, fixId, fixAllDescription && diagnosticToString(fixAllDescription), command); + } + function createCodeFixActionWorker(fixName: string, description: string, changes: FileTextChanges[], fixId?: {}, fixAllDescription?: string, command?: CodeActionCommand): CodeFixAction { return { fixName, description, changes, fixId, fixAllDescription, commands: command ? [command] : undefined }; } diff --git a/src/services/codefixes/fixOverrideModifier.ts b/src/services/codefixes/fixOverrideModifier.ts new file mode 100644 index 0000000000000..7ebe1eeb9c936 --- /dev/null +++ b/src/services/codefixes/fixOverrideModifier.ts @@ -0,0 +1,119 @@ +/* @internal */ +namespace ts.codefix { + const fixName = "fixOverrideModifier"; + const fixAddOverrideId = "fixAddOverrideModifier"; + const fixRemoveOverrideId = "fixRemoveOverrideModifier"; + + type ClassElementHasJSDoc = + | ConstructorDeclaration + | PropertyDeclaration + | MethodDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration; + + const errorCodes = [ + Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0.code, + Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code, + Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code, + Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code + ]; + + const errorCodeFixIdMap: Record = { + [Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code]: [ + Diagnostics.Add_override_modifier, fixAddOverrideId, Diagnostics.Add_all_missing_override_modifiers, + ], + [Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code]: [ + Diagnostics.Remove_override_modifier, fixRemoveOverrideId, Diagnostics.Remove_all_unnecessary_override_modifiers + ], + [Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code]: [ + Diagnostics.Add_override_modifier, fixAddOverrideId, Diagnostics.Remove_all_unnecessary_override_modifiers + ], + [Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0.code]: [ + Diagnostics.Remove_override_modifier, fixRemoveOverrideId, Diagnostics.Remove_all_unnecessary_override_modifiers + ] + }; + + registerCodeFix({ + errorCodes, + getCodeActions: context => { + const { errorCode, span, sourceFile } = context; + + const info = errorCodeFixIdMap[errorCode]; + if (!info) return emptyArray; + + const [ descriptions, fixId, fixAllDescriptions ] = info; + if (isSourceFileJS(sourceFile)) return emptyArray; + const changes = textChanges.ChangeTracker.with(context, changes => dispatchChanges(changes, context, errorCode, span.start)); + + return [ + createCodeFixActionMaybeFixAll(fixName, changes, descriptions, fixId, fixAllDescriptions) + ]; + }, + fixIds: [fixName, fixAddOverrideId, fixRemoveOverrideId], + getAllCodeActions: context => + codeFixAll(context, errorCodes, (changes, diag) => { + const { code, start, file } = diag; + const info = errorCodeFixIdMap[code]; + if (!info || info[1] !== context.fixId || isSourceFileJS(file)) { + return; + } + + dispatchChanges(changes, context, code, start); + }) + }); + + function dispatchChanges( + changeTracker: textChanges.ChangeTracker, + context: CodeFixContext | CodeFixAllContext, + errorCode: number, + pos: number) { + switch (errorCode) { + case Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_a_member_in_the_base_class_0.code: + case Diagnostics.This_member_must_have_an_override_modifier_because_it_overrides_an_abstract_method_that_is_declared_in_the_base_class_0.code: + return doAddOverrideModifierChange(changeTracker, context.sourceFile, pos); + case Diagnostics.This_member_cannot_have_an_override_modifier_because_it_is_not_declared_in_the_base_class_0.code: + case Diagnostics.This_member_cannot_have_an_override_modifier_because_its_containing_class_0_does_not_extend_another_class.code: + return doRemoveOverrideModifierChange(changeTracker, context.sourceFile, pos); + default: + Debug.fail("Unexpected error code: " + errorCode); + } + } + + function doAddOverrideModifierChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) { + const classElement = findContainerClassElement(sourceFile, pos); + changeTracker.insertModifierBefore(sourceFile, SyntaxKind.OverrideKeyword, classElement); + } + + function doRemoveOverrideModifierChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) { + const classElement = findContainerClassElement(sourceFile, pos); + const overrideModifier = classElement.modifiers && find(classElement.modifiers, modifier => modifier.kind === SyntaxKind.OverrideKeyword); + Debug.assertIsDefined(overrideModifier); + + changeTracker.deleteModifier(sourceFile, overrideModifier); + } + + function isClassElementHasJSDoc(node: Node): node is ClassElementHasJSDoc { + switch (node.kind) { + case SyntaxKind.Constructor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return true; + default: + return false; + } + } + + function findContainerClassElement(sourceFile: SourceFile, pos: number) { + const token = getTokenAtPosition(sourceFile, pos); + const classElement = findAncestor(token, node => { + if (isClassLike(node)) return "quit"; + return isClassElementHasJSDoc(node); + }); + + Debug.assert(classElement && isClassElementHasJSDoc(classElement)); + return classElement; + } +} + diff --git a/src/services/codefixes/generateAccessors.ts b/src/services/codefixes/generateAccessors.ts index fbcfd1b6943aa..d51d30abda789 100644 --- a/src/services/codefixes/generateAccessors.ts +++ b/src/services/codefixes/generateAccessors.ts @@ -83,10 +83,6 @@ namespace ts.codefix { return isIdentifier(fieldName) ? factory.createPropertyAccessExpression(leftHead, fieldName) : factory.createElementAccessExpression(leftHead, factory.createStringLiteralFromNode(fieldName)); } - function createModifiers(modifierFlags: ModifierFlags): ModifiersArray | undefined { - return modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : undefined; - } - function prepareModifierFlagsForAccessor(modifierFlags: ModifierFlags): ModifierFlags { modifierFlags &= ~ModifierFlags.Readonly; // avoid Readonly modifier because it will convert to get accessor modifierFlags &= ~ModifierFlags.Private; diff --git a/src/services/completions.ts b/src/services/completions.ts index 8cd4600674112..9862c027c0f98 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2116,13 +2116,17 @@ namespace ts.Completions { case "static": classElementModifierFlags = classElementModifierFlags | ModifierFlags.Static; break; + case "override": + classElementModifierFlags = classElementModifierFlags | ModifierFlags.Override; + break; } } // No member list for private methods if (!(classElementModifierFlags & ModifierFlags.Private)) { // List of property symbols of base type that are not private and already implemented - const baseSymbols = flatMap(getAllSuperTypeNodes(decl), baseTypeNode => { + const baseTypeNodes = isClassLike(decl) && classElementModifierFlags & ModifierFlags.Override ? singleElementArray(getEffectiveBaseTypeNode(decl)) : getAllSuperTypeNodes(decl); + const baseSymbols = flatMap(baseTypeNodes, baseTypeNode => { const type = typeChecker.getTypeAtLocation(baseTypeNode); return classElementModifierFlags & ModifierFlags.Static ? type?.symbol && typeChecker.getPropertiesOfType(typeChecker.getTypeOfSymbolAtLocation(type.symbol, decl)) : @@ -2705,6 +2709,7 @@ namespace ts.Completions { case SyntaxKind.NeverKeyword: case SyntaxKind.NumberKeyword: case SyntaxKind.ObjectKeyword: + case SyntaxKind.OverrideKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: @@ -2732,6 +2737,7 @@ namespace ts.Completions { case SyntaxKind.SetKeyword: case SyntaxKind.AsyncKeyword: case SyntaxKind.DeclareKeyword: + case SyntaxKind.OverrideKeyword: return true; default: return isClassMemberModifier(kind); diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 91e2fa4d78064..ca4e016e21bc6 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -505,6 +505,16 @@ namespace ts.textChanges { } } + public insertNodeAtConstructorStartAfterSuperCall(sourceFile: SourceFile, ctr: ConstructorDeclaration, newStatement: Statement): void { + const superCallStatement = find(ctr.body!.statements, stmt => isExpressionStatement(stmt) && isSuperCall(stmt.expression)); + if (!superCallStatement || !ctr.body!.multiLine) { + this.replaceConstructorBody(sourceFile, ctr, [...ctr.body!.statements, newStatement]); + } + else { + this.insertNodeAfter(sourceFile, superCallStatement, newStatement); + } + } + public insertNodeAtConstructorEnd(sourceFile: SourceFile, ctr: ConstructorDeclaration, newStatement: Statement): void { const lastStatement = lastOrUndefined(ctr.body!.statements); if (!lastStatement || !ctr.body!.multiLine) { diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 0140929340340..1e846b9214d16 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -65,6 +65,7 @@ "codefixes/convertLiteralTypeToMappedType.ts", "codefixes/fixClassIncorrectlyImplementsInterface.ts", "codefixes/importFixes.ts", + "codefixes/fixOverrideModifier.ts", "codefixes/fixNoPropertyAccessFromIndexSignature.ts", "codefixes/fixImplicitThis.ts", "codefixes/fixIncorrectNamedTupleSyntax.ts", diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 9137dc54f3a9b..4b8cb206eae3e 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -260,194 +260,196 @@ declare namespace ts { FromKeyword = 153, GlobalKeyword = 154, BigIntKeyword = 155, - OfKeyword = 156, - QualifiedName = 157, - ComputedPropertyName = 158, - TypeParameter = 159, - Parameter = 160, - Decorator = 161, - PropertySignature = 162, - PropertyDeclaration = 163, - MethodSignature = 164, - MethodDeclaration = 165, - Constructor = 166, - GetAccessor = 167, - SetAccessor = 168, - CallSignature = 169, - ConstructSignature = 170, - IndexSignature = 171, - TypePredicate = 172, - TypeReference = 173, - FunctionType = 174, - ConstructorType = 175, - TypeQuery = 176, - TypeLiteral = 177, - ArrayType = 178, - TupleType = 179, - OptionalType = 180, - RestType = 181, - UnionType = 182, - IntersectionType = 183, - ConditionalType = 184, - InferType = 185, - ParenthesizedType = 186, - ThisType = 187, - TypeOperator = 188, - IndexedAccessType = 189, - MappedType = 190, - LiteralType = 191, - NamedTupleMember = 192, - TemplateLiteralType = 193, - TemplateLiteralTypeSpan = 194, - ImportType = 195, - ObjectBindingPattern = 196, - ArrayBindingPattern = 197, - BindingElement = 198, - ArrayLiteralExpression = 199, - ObjectLiteralExpression = 200, - PropertyAccessExpression = 201, - ElementAccessExpression = 202, - CallExpression = 203, - NewExpression = 204, - TaggedTemplateExpression = 205, - TypeAssertionExpression = 206, - ParenthesizedExpression = 207, - FunctionExpression = 208, - ArrowFunction = 209, - DeleteExpression = 210, - TypeOfExpression = 211, - VoidExpression = 212, - AwaitExpression = 213, - PrefixUnaryExpression = 214, - PostfixUnaryExpression = 215, - BinaryExpression = 216, - ConditionalExpression = 217, - TemplateExpression = 218, - YieldExpression = 219, - SpreadElement = 220, - ClassExpression = 221, - OmittedExpression = 222, - ExpressionWithTypeArguments = 223, - AsExpression = 224, - NonNullExpression = 225, - MetaProperty = 226, - SyntheticExpression = 227, - TemplateSpan = 228, - SemicolonClassElement = 229, - Block = 230, - EmptyStatement = 231, - VariableStatement = 232, - ExpressionStatement = 233, - IfStatement = 234, - DoStatement = 235, - WhileStatement = 236, - ForStatement = 237, - ForInStatement = 238, - ForOfStatement = 239, - ContinueStatement = 240, - BreakStatement = 241, - ReturnStatement = 242, - WithStatement = 243, - SwitchStatement = 244, - LabeledStatement = 245, - ThrowStatement = 246, - TryStatement = 247, - DebuggerStatement = 248, - VariableDeclaration = 249, - VariableDeclarationList = 250, - FunctionDeclaration = 251, - ClassDeclaration = 252, - InterfaceDeclaration = 253, - TypeAliasDeclaration = 254, - EnumDeclaration = 255, - ModuleDeclaration = 256, - ModuleBlock = 257, - CaseBlock = 258, - NamespaceExportDeclaration = 259, - ImportEqualsDeclaration = 260, - ImportDeclaration = 261, - ImportClause = 262, - NamespaceImport = 263, - NamedImports = 264, - ImportSpecifier = 265, - ExportAssignment = 266, - ExportDeclaration = 267, - NamedExports = 268, - NamespaceExport = 269, - ExportSpecifier = 270, - MissingDeclaration = 271, - ExternalModuleReference = 272, - JsxElement = 273, - JsxSelfClosingElement = 274, - JsxOpeningElement = 275, - JsxClosingElement = 276, - JsxFragment = 277, - JsxOpeningFragment = 278, - JsxClosingFragment = 279, - JsxAttribute = 280, - JsxAttributes = 281, - JsxSpreadAttribute = 282, - JsxExpression = 283, - CaseClause = 284, - DefaultClause = 285, - HeritageClause = 286, - CatchClause = 287, - PropertyAssignment = 288, - ShorthandPropertyAssignment = 289, - SpreadAssignment = 290, - EnumMember = 291, - UnparsedPrologue = 292, - UnparsedPrepend = 293, - UnparsedText = 294, - UnparsedInternalText = 295, - UnparsedSyntheticReference = 296, - SourceFile = 297, - Bundle = 298, - UnparsedSource = 299, - InputFiles = 300, - JSDocTypeExpression = 301, - JSDocNameReference = 302, - JSDocAllType = 303, - JSDocUnknownType = 304, - JSDocNullableType = 305, - JSDocNonNullableType = 306, - JSDocOptionalType = 307, - JSDocFunctionType = 308, - JSDocVariadicType = 309, - JSDocNamepathType = 310, - JSDocComment = 311, - JSDocText = 312, - JSDocTypeLiteral = 313, - JSDocSignature = 314, - JSDocLink = 315, - JSDocTag = 316, - JSDocAugmentsTag = 317, - JSDocImplementsTag = 318, - JSDocAuthorTag = 319, - JSDocDeprecatedTag = 320, - JSDocClassTag = 321, - JSDocPublicTag = 322, - JSDocPrivateTag = 323, - JSDocProtectedTag = 324, - JSDocReadonlyTag = 325, - JSDocCallbackTag = 326, - JSDocEnumTag = 327, - JSDocParameterTag = 328, - JSDocReturnTag = 329, - JSDocThisTag = 330, - JSDocTypeTag = 331, - JSDocTemplateTag = 332, - JSDocTypedefTag = 333, - JSDocSeeTag = 334, - JSDocPropertyTag = 335, - SyntaxList = 336, - NotEmittedStatement = 337, - PartiallyEmittedExpression = 338, - CommaListExpression = 339, - MergeDeclarationMarker = 340, - EndOfDeclarationMarker = 341, - SyntheticReferenceExpression = 342, - Count = 343, + OverrideKeyword = 156, + OfKeyword = 157, + QualifiedName = 158, + ComputedPropertyName = 159, + TypeParameter = 160, + Parameter = 161, + Decorator = 162, + PropertySignature = 163, + PropertyDeclaration = 164, + MethodSignature = 165, + MethodDeclaration = 166, + Constructor = 167, + GetAccessor = 168, + SetAccessor = 169, + CallSignature = 170, + ConstructSignature = 171, + IndexSignature = 172, + TypePredicate = 173, + TypeReference = 174, + FunctionType = 175, + ConstructorType = 176, + TypeQuery = 177, + TypeLiteral = 178, + ArrayType = 179, + TupleType = 180, + OptionalType = 181, + RestType = 182, + UnionType = 183, + IntersectionType = 184, + ConditionalType = 185, + InferType = 186, + ParenthesizedType = 187, + ThisType = 188, + TypeOperator = 189, + IndexedAccessType = 190, + MappedType = 191, + LiteralType = 192, + NamedTupleMember = 193, + TemplateLiteralType = 194, + TemplateLiteralTypeSpan = 195, + ImportType = 196, + ObjectBindingPattern = 197, + ArrayBindingPattern = 198, + BindingElement = 199, + ArrayLiteralExpression = 200, + ObjectLiteralExpression = 201, + PropertyAccessExpression = 202, + ElementAccessExpression = 203, + CallExpression = 204, + NewExpression = 205, + TaggedTemplateExpression = 206, + TypeAssertionExpression = 207, + ParenthesizedExpression = 208, + FunctionExpression = 209, + ArrowFunction = 210, + DeleteExpression = 211, + TypeOfExpression = 212, + VoidExpression = 213, + AwaitExpression = 214, + PrefixUnaryExpression = 215, + PostfixUnaryExpression = 216, + BinaryExpression = 217, + ConditionalExpression = 218, + TemplateExpression = 219, + YieldExpression = 220, + SpreadElement = 221, + ClassExpression = 222, + OmittedExpression = 223, + ExpressionWithTypeArguments = 224, + AsExpression = 225, + NonNullExpression = 226, + MetaProperty = 227, + SyntheticExpression = 228, + TemplateSpan = 229, + SemicolonClassElement = 230, + Block = 231, + EmptyStatement = 232, + VariableStatement = 233, + ExpressionStatement = 234, + IfStatement = 235, + DoStatement = 236, + WhileStatement = 237, + ForStatement = 238, + ForInStatement = 239, + ForOfStatement = 240, + ContinueStatement = 241, + BreakStatement = 242, + ReturnStatement = 243, + WithStatement = 244, + SwitchStatement = 245, + LabeledStatement = 246, + ThrowStatement = 247, + TryStatement = 248, + DebuggerStatement = 249, + VariableDeclaration = 250, + VariableDeclarationList = 251, + FunctionDeclaration = 252, + ClassDeclaration = 253, + InterfaceDeclaration = 254, + TypeAliasDeclaration = 255, + EnumDeclaration = 256, + ModuleDeclaration = 257, + ModuleBlock = 258, + CaseBlock = 259, + NamespaceExportDeclaration = 260, + ImportEqualsDeclaration = 261, + ImportDeclaration = 262, + ImportClause = 263, + NamespaceImport = 264, + NamedImports = 265, + ImportSpecifier = 266, + ExportAssignment = 267, + ExportDeclaration = 268, + NamedExports = 269, + NamespaceExport = 270, + ExportSpecifier = 271, + MissingDeclaration = 272, + ExternalModuleReference = 273, + JsxElement = 274, + JsxSelfClosingElement = 275, + JsxOpeningElement = 276, + JsxClosingElement = 277, + JsxFragment = 278, + JsxOpeningFragment = 279, + JsxClosingFragment = 280, + JsxAttribute = 281, + JsxAttributes = 282, + JsxSpreadAttribute = 283, + JsxExpression = 284, + CaseClause = 285, + DefaultClause = 286, + HeritageClause = 287, + CatchClause = 288, + PropertyAssignment = 289, + ShorthandPropertyAssignment = 290, + SpreadAssignment = 291, + EnumMember = 292, + UnparsedPrologue = 293, + UnparsedPrepend = 294, + UnparsedText = 295, + UnparsedInternalText = 296, + UnparsedSyntheticReference = 297, + SourceFile = 298, + Bundle = 299, + UnparsedSource = 300, + InputFiles = 301, + JSDocTypeExpression = 302, + JSDocNameReference = 303, + JSDocAllType = 304, + JSDocUnknownType = 305, + JSDocNullableType = 306, + JSDocNonNullableType = 307, + JSDocOptionalType = 308, + JSDocFunctionType = 309, + JSDocVariadicType = 310, + JSDocNamepathType = 311, + JSDocComment = 312, + JSDocText = 313, + JSDocTypeLiteral = 314, + JSDocSignature = 315, + JSDocLink = 316, + JSDocTag = 317, + JSDocAugmentsTag = 318, + JSDocImplementsTag = 319, + JSDocAuthorTag = 320, + JSDocDeprecatedTag = 321, + JSDocClassTag = 322, + JSDocPublicTag = 323, + JSDocPrivateTag = 324, + JSDocProtectedTag = 325, + JSDocReadonlyTag = 326, + JSDocOverrideTag = 327, + JSDocCallbackTag = 328, + JSDocEnumTag = 329, + JSDocParameterTag = 330, + JSDocReturnTag = 331, + JSDocThisTag = 332, + JSDocTypeTag = 333, + JSDocTemplateTag = 334, + JSDocTypedefTag = 335, + JSDocSeeTag = 336, + JSDocPropertyTag = 337, + SyntaxList = 338, + NotEmittedStatement = 339, + PartiallyEmittedExpression = 340, + CommaListExpression = 341, + MergeDeclarationMarker = 342, + EndOfDeclarationMarker = 343, + SyntheticReferenceExpression = 344, + Count = 345, FirstAssignment = 62, LastAssignment = 77, FirstCompoundAssignment = 63, @@ -455,15 +457,15 @@ declare namespace ts { FirstReservedWord = 80, LastReservedWord = 115, FirstKeyword = 80, - LastKeyword = 156, + LastKeyword = 157, FirstFutureReservedWord = 116, LastFutureReservedWord = 124, - FirstTypeNode = 172, - LastTypeNode = 195, + FirstTypeNode = 173, + LastTypeNode = 196, FirstPunctuation = 18, LastPunctuation = 77, FirstToken = 0, - LastToken = 156, + LastToken = 157, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -472,20 +474,20 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 77, - FirstStatement = 232, - LastStatement = 248, - FirstNode = 157, - FirstJSDocNode = 301, - LastJSDocNode = 335, - FirstJSDocTagNode = 316, - LastJSDocTagNode = 335, + FirstStatement = 233, + LastStatement = 249, + FirstNode = 158, + FirstJSDocNode = 302, + LastJSDocNode = 337, + FirstJSDocTagNode = 317, + LastJSDocTagNode = 337, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; export type PunctuationSyntaxKind = SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.DotToken | SyntaxKind.DotDotDotToken | SyntaxKind.SemicolonToken | SyntaxKind.CommaToken | SyntaxKind.QuestionDotToken | SyntaxKind.LessThanToken | SyntaxKind.LessThanSlashToken | SyntaxKind.GreaterThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.EqualsEqualsToken | SyntaxKind.ExclamationEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.EqualsGreaterThanToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.AsteriskToken | SyntaxKind.AsteriskAsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken | SyntaxKind.ExclamationToken | SyntaxKind.TildeToken | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken | SyntaxKind.QuestionQuestionToken | SyntaxKind.QuestionToken | SyntaxKind.ColonToken | SyntaxKind.AtToken | SyntaxKind.BacktickToken | SyntaxKind.EqualsToken | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; - export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.StaticKeyword; + export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; + export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; @@ -535,13 +537,14 @@ declare namespace ts { Const = 2048, HasComputedJSDocModifiers = 4096, Deprecated = 8192, + Override = 16384, HasComputedFlags = 536870912, AccessibilityModifier = 28, ParameterPropertyModifier = 92, NonPublicAccessibilityModifier = 24, - TypeScriptModifier = 2270, + TypeScriptModifier = 18654, ExportDefault = 513, - All = 11263 + All = 27647 } export enum JsxFlags { None = 0, @@ -605,10 +608,11 @@ declare namespace ts { export type ProtectedKeyword = ModifierToken; export type PublicKeyword = ModifierToken; export type ReadonlyKeyword = ModifierToken; + export type OverrideKeyword = ModifierToken; export type StaticKeyword = ModifierToken; /** @deprecated Use `ReadonlyKeyword` instead. */ export type ReadonlyToken = ReadonlyKeyword; - export type Modifier = AbstractKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | ReadonlyKeyword | StaticKeyword; + export type Modifier = AbstractKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; export type AccessibilityModifier = PublicKeyword | PrivateKeyword | ProtectedKeyword; export type ParameterPropertyModifier = AccessibilityModifier | ReadonlyKeyword; export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword; @@ -1801,6 +1805,9 @@ declare namespace ts { export interface JSDocReadonlyTag extends JSDocTag { readonly kind: SyntaxKind.JSDocReadonlyTag; } + export interface JSDocOverrideTag extends JSDocTag { + readonly kind: SyntaxKind.JSDocOverrideTag; + } export interface JSDocEnumTag extends JSDocTag, Declaration { readonly kind: SyntaxKind.JSDocEnumTag; readonly parent: JSDoc; @@ -2861,6 +2868,7 @@ declare namespace ts { outFile?: string; paths?: MapLike; preserveConstEnums?: boolean; + noImplicitOverride?: boolean; preserveSymlinks?: boolean; project?: string; reactNamespace?: string; @@ -3535,6 +3543,8 @@ declare namespace ts { updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray | undefined): JSDocUnknownTag; createJSDocDeprecatedTag(tagName: Identifier, comment?: string | NodeArray): JSDocDeprecatedTag; updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier, comment?: string | NodeArray): JSDocDeprecatedTag; + createJSDocOverrideTag(tagName: Identifier, comment?: string | NodeArray): JSDocOverrideTag; + updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier, comment?: string | NodeArray): JSDocOverrideTag; createJSDocText(text: string): JSDocText; updateJSDocText(node: JSDocText, text: string): JSDocText; createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined): JSDoc; @@ -4184,6 +4194,7 @@ declare namespace ts { function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; /** Gets the JSDoc protected tag for the node if present */ function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; + function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ @@ -4562,6 +4573,7 @@ declare namespace ts { function isJSDocPrivateTag(node: Node): node is JSDocPrivateTag; function isJSDocProtectedTag(node: Node): node is JSDocProtectedTag; function isJSDocReadonlyTag(node: Node): node is JSDocReadonlyTag; + function isJSDocOverrideTag(node: Node): node is JSDocOverrideTag; function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag; function isJSDocSeeTag(node: Node): node is JSDocSeeTag; function isJSDocEnumTag(node: Node): node is JSDocEnumTag; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index c18a30d445c15..2c994b8e0f804 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -260,194 +260,196 @@ declare namespace ts { FromKeyword = 153, GlobalKeyword = 154, BigIntKeyword = 155, - OfKeyword = 156, - QualifiedName = 157, - ComputedPropertyName = 158, - TypeParameter = 159, - Parameter = 160, - Decorator = 161, - PropertySignature = 162, - PropertyDeclaration = 163, - MethodSignature = 164, - MethodDeclaration = 165, - Constructor = 166, - GetAccessor = 167, - SetAccessor = 168, - CallSignature = 169, - ConstructSignature = 170, - IndexSignature = 171, - TypePredicate = 172, - TypeReference = 173, - FunctionType = 174, - ConstructorType = 175, - TypeQuery = 176, - TypeLiteral = 177, - ArrayType = 178, - TupleType = 179, - OptionalType = 180, - RestType = 181, - UnionType = 182, - IntersectionType = 183, - ConditionalType = 184, - InferType = 185, - ParenthesizedType = 186, - ThisType = 187, - TypeOperator = 188, - IndexedAccessType = 189, - MappedType = 190, - LiteralType = 191, - NamedTupleMember = 192, - TemplateLiteralType = 193, - TemplateLiteralTypeSpan = 194, - ImportType = 195, - ObjectBindingPattern = 196, - ArrayBindingPattern = 197, - BindingElement = 198, - ArrayLiteralExpression = 199, - ObjectLiteralExpression = 200, - PropertyAccessExpression = 201, - ElementAccessExpression = 202, - CallExpression = 203, - NewExpression = 204, - TaggedTemplateExpression = 205, - TypeAssertionExpression = 206, - ParenthesizedExpression = 207, - FunctionExpression = 208, - ArrowFunction = 209, - DeleteExpression = 210, - TypeOfExpression = 211, - VoidExpression = 212, - AwaitExpression = 213, - PrefixUnaryExpression = 214, - PostfixUnaryExpression = 215, - BinaryExpression = 216, - ConditionalExpression = 217, - TemplateExpression = 218, - YieldExpression = 219, - SpreadElement = 220, - ClassExpression = 221, - OmittedExpression = 222, - ExpressionWithTypeArguments = 223, - AsExpression = 224, - NonNullExpression = 225, - MetaProperty = 226, - SyntheticExpression = 227, - TemplateSpan = 228, - SemicolonClassElement = 229, - Block = 230, - EmptyStatement = 231, - VariableStatement = 232, - ExpressionStatement = 233, - IfStatement = 234, - DoStatement = 235, - WhileStatement = 236, - ForStatement = 237, - ForInStatement = 238, - ForOfStatement = 239, - ContinueStatement = 240, - BreakStatement = 241, - ReturnStatement = 242, - WithStatement = 243, - SwitchStatement = 244, - LabeledStatement = 245, - ThrowStatement = 246, - TryStatement = 247, - DebuggerStatement = 248, - VariableDeclaration = 249, - VariableDeclarationList = 250, - FunctionDeclaration = 251, - ClassDeclaration = 252, - InterfaceDeclaration = 253, - TypeAliasDeclaration = 254, - EnumDeclaration = 255, - ModuleDeclaration = 256, - ModuleBlock = 257, - CaseBlock = 258, - NamespaceExportDeclaration = 259, - ImportEqualsDeclaration = 260, - ImportDeclaration = 261, - ImportClause = 262, - NamespaceImport = 263, - NamedImports = 264, - ImportSpecifier = 265, - ExportAssignment = 266, - ExportDeclaration = 267, - NamedExports = 268, - NamespaceExport = 269, - ExportSpecifier = 270, - MissingDeclaration = 271, - ExternalModuleReference = 272, - JsxElement = 273, - JsxSelfClosingElement = 274, - JsxOpeningElement = 275, - JsxClosingElement = 276, - JsxFragment = 277, - JsxOpeningFragment = 278, - JsxClosingFragment = 279, - JsxAttribute = 280, - JsxAttributes = 281, - JsxSpreadAttribute = 282, - JsxExpression = 283, - CaseClause = 284, - DefaultClause = 285, - HeritageClause = 286, - CatchClause = 287, - PropertyAssignment = 288, - ShorthandPropertyAssignment = 289, - SpreadAssignment = 290, - EnumMember = 291, - UnparsedPrologue = 292, - UnparsedPrepend = 293, - UnparsedText = 294, - UnparsedInternalText = 295, - UnparsedSyntheticReference = 296, - SourceFile = 297, - Bundle = 298, - UnparsedSource = 299, - InputFiles = 300, - JSDocTypeExpression = 301, - JSDocNameReference = 302, - JSDocAllType = 303, - JSDocUnknownType = 304, - JSDocNullableType = 305, - JSDocNonNullableType = 306, - JSDocOptionalType = 307, - JSDocFunctionType = 308, - JSDocVariadicType = 309, - JSDocNamepathType = 310, - JSDocComment = 311, - JSDocText = 312, - JSDocTypeLiteral = 313, - JSDocSignature = 314, - JSDocLink = 315, - JSDocTag = 316, - JSDocAugmentsTag = 317, - JSDocImplementsTag = 318, - JSDocAuthorTag = 319, - JSDocDeprecatedTag = 320, - JSDocClassTag = 321, - JSDocPublicTag = 322, - JSDocPrivateTag = 323, - JSDocProtectedTag = 324, - JSDocReadonlyTag = 325, - JSDocCallbackTag = 326, - JSDocEnumTag = 327, - JSDocParameterTag = 328, - JSDocReturnTag = 329, - JSDocThisTag = 330, - JSDocTypeTag = 331, - JSDocTemplateTag = 332, - JSDocTypedefTag = 333, - JSDocSeeTag = 334, - JSDocPropertyTag = 335, - SyntaxList = 336, - NotEmittedStatement = 337, - PartiallyEmittedExpression = 338, - CommaListExpression = 339, - MergeDeclarationMarker = 340, - EndOfDeclarationMarker = 341, - SyntheticReferenceExpression = 342, - Count = 343, + OverrideKeyword = 156, + OfKeyword = 157, + QualifiedName = 158, + ComputedPropertyName = 159, + TypeParameter = 160, + Parameter = 161, + Decorator = 162, + PropertySignature = 163, + PropertyDeclaration = 164, + MethodSignature = 165, + MethodDeclaration = 166, + Constructor = 167, + GetAccessor = 168, + SetAccessor = 169, + CallSignature = 170, + ConstructSignature = 171, + IndexSignature = 172, + TypePredicate = 173, + TypeReference = 174, + FunctionType = 175, + ConstructorType = 176, + TypeQuery = 177, + TypeLiteral = 178, + ArrayType = 179, + TupleType = 180, + OptionalType = 181, + RestType = 182, + UnionType = 183, + IntersectionType = 184, + ConditionalType = 185, + InferType = 186, + ParenthesizedType = 187, + ThisType = 188, + TypeOperator = 189, + IndexedAccessType = 190, + MappedType = 191, + LiteralType = 192, + NamedTupleMember = 193, + TemplateLiteralType = 194, + TemplateLiteralTypeSpan = 195, + ImportType = 196, + ObjectBindingPattern = 197, + ArrayBindingPattern = 198, + BindingElement = 199, + ArrayLiteralExpression = 200, + ObjectLiteralExpression = 201, + PropertyAccessExpression = 202, + ElementAccessExpression = 203, + CallExpression = 204, + NewExpression = 205, + TaggedTemplateExpression = 206, + TypeAssertionExpression = 207, + ParenthesizedExpression = 208, + FunctionExpression = 209, + ArrowFunction = 210, + DeleteExpression = 211, + TypeOfExpression = 212, + VoidExpression = 213, + AwaitExpression = 214, + PrefixUnaryExpression = 215, + PostfixUnaryExpression = 216, + BinaryExpression = 217, + ConditionalExpression = 218, + TemplateExpression = 219, + YieldExpression = 220, + SpreadElement = 221, + ClassExpression = 222, + OmittedExpression = 223, + ExpressionWithTypeArguments = 224, + AsExpression = 225, + NonNullExpression = 226, + MetaProperty = 227, + SyntheticExpression = 228, + TemplateSpan = 229, + SemicolonClassElement = 230, + Block = 231, + EmptyStatement = 232, + VariableStatement = 233, + ExpressionStatement = 234, + IfStatement = 235, + DoStatement = 236, + WhileStatement = 237, + ForStatement = 238, + ForInStatement = 239, + ForOfStatement = 240, + ContinueStatement = 241, + BreakStatement = 242, + ReturnStatement = 243, + WithStatement = 244, + SwitchStatement = 245, + LabeledStatement = 246, + ThrowStatement = 247, + TryStatement = 248, + DebuggerStatement = 249, + VariableDeclaration = 250, + VariableDeclarationList = 251, + FunctionDeclaration = 252, + ClassDeclaration = 253, + InterfaceDeclaration = 254, + TypeAliasDeclaration = 255, + EnumDeclaration = 256, + ModuleDeclaration = 257, + ModuleBlock = 258, + CaseBlock = 259, + NamespaceExportDeclaration = 260, + ImportEqualsDeclaration = 261, + ImportDeclaration = 262, + ImportClause = 263, + NamespaceImport = 264, + NamedImports = 265, + ImportSpecifier = 266, + ExportAssignment = 267, + ExportDeclaration = 268, + NamedExports = 269, + NamespaceExport = 270, + ExportSpecifier = 271, + MissingDeclaration = 272, + ExternalModuleReference = 273, + JsxElement = 274, + JsxSelfClosingElement = 275, + JsxOpeningElement = 276, + JsxClosingElement = 277, + JsxFragment = 278, + JsxOpeningFragment = 279, + JsxClosingFragment = 280, + JsxAttribute = 281, + JsxAttributes = 282, + JsxSpreadAttribute = 283, + JsxExpression = 284, + CaseClause = 285, + DefaultClause = 286, + HeritageClause = 287, + CatchClause = 288, + PropertyAssignment = 289, + ShorthandPropertyAssignment = 290, + SpreadAssignment = 291, + EnumMember = 292, + UnparsedPrologue = 293, + UnparsedPrepend = 294, + UnparsedText = 295, + UnparsedInternalText = 296, + UnparsedSyntheticReference = 297, + SourceFile = 298, + Bundle = 299, + UnparsedSource = 300, + InputFiles = 301, + JSDocTypeExpression = 302, + JSDocNameReference = 303, + JSDocAllType = 304, + JSDocUnknownType = 305, + JSDocNullableType = 306, + JSDocNonNullableType = 307, + JSDocOptionalType = 308, + JSDocFunctionType = 309, + JSDocVariadicType = 310, + JSDocNamepathType = 311, + JSDocComment = 312, + JSDocText = 313, + JSDocTypeLiteral = 314, + JSDocSignature = 315, + JSDocLink = 316, + JSDocTag = 317, + JSDocAugmentsTag = 318, + JSDocImplementsTag = 319, + JSDocAuthorTag = 320, + JSDocDeprecatedTag = 321, + JSDocClassTag = 322, + JSDocPublicTag = 323, + JSDocPrivateTag = 324, + JSDocProtectedTag = 325, + JSDocReadonlyTag = 326, + JSDocOverrideTag = 327, + JSDocCallbackTag = 328, + JSDocEnumTag = 329, + JSDocParameterTag = 330, + JSDocReturnTag = 331, + JSDocThisTag = 332, + JSDocTypeTag = 333, + JSDocTemplateTag = 334, + JSDocTypedefTag = 335, + JSDocSeeTag = 336, + JSDocPropertyTag = 337, + SyntaxList = 338, + NotEmittedStatement = 339, + PartiallyEmittedExpression = 340, + CommaListExpression = 341, + MergeDeclarationMarker = 342, + EndOfDeclarationMarker = 343, + SyntheticReferenceExpression = 344, + Count = 345, FirstAssignment = 62, LastAssignment = 77, FirstCompoundAssignment = 63, @@ -455,15 +457,15 @@ declare namespace ts { FirstReservedWord = 80, LastReservedWord = 115, FirstKeyword = 80, - LastKeyword = 156, + LastKeyword = 157, FirstFutureReservedWord = 116, LastFutureReservedWord = 124, - FirstTypeNode = 172, - LastTypeNode = 195, + FirstTypeNode = 173, + LastTypeNode = 196, FirstPunctuation = 18, LastPunctuation = 77, FirstToken = 0, - LastToken = 156, + LastToken = 157, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -472,20 +474,20 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 77, - FirstStatement = 232, - LastStatement = 248, - FirstNode = 157, - FirstJSDocNode = 301, - LastJSDocNode = 335, - FirstJSDocTagNode = 316, - LastJSDocTagNode = 335, + FirstStatement = 233, + LastStatement = 249, + FirstNode = 158, + FirstJSDocNode = 302, + LastJSDocNode = 337, + FirstJSDocTagNode = 317, + LastJSDocTagNode = 337, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; export type PunctuationSyntaxKind = SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.DotToken | SyntaxKind.DotDotDotToken | SyntaxKind.SemicolonToken | SyntaxKind.CommaToken | SyntaxKind.QuestionDotToken | SyntaxKind.LessThanToken | SyntaxKind.LessThanSlashToken | SyntaxKind.GreaterThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.EqualsEqualsToken | SyntaxKind.ExclamationEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.EqualsGreaterThanToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.AsteriskToken | SyntaxKind.AsteriskAsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken | SyntaxKind.ExclamationToken | SyntaxKind.TildeToken | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken | SyntaxKind.QuestionQuestionToken | SyntaxKind.QuestionToken | SyntaxKind.ColonToken | SyntaxKind.AtToken | SyntaxKind.BacktickToken | SyntaxKind.EqualsToken | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; - export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.StaticKeyword; + export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; + export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; @@ -535,13 +537,14 @@ declare namespace ts { Const = 2048, HasComputedJSDocModifiers = 4096, Deprecated = 8192, + Override = 16384, HasComputedFlags = 536870912, AccessibilityModifier = 28, ParameterPropertyModifier = 92, NonPublicAccessibilityModifier = 24, - TypeScriptModifier = 2270, + TypeScriptModifier = 18654, ExportDefault = 513, - All = 11263 + All = 27647 } export enum JsxFlags { None = 0, @@ -605,10 +608,11 @@ declare namespace ts { export type ProtectedKeyword = ModifierToken; export type PublicKeyword = ModifierToken; export type ReadonlyKeyword = ModifierToken; + export type OverrideKeyword = ModifierToken; export type StaticKeyword = ModifierToken; /** @deprecated Use `ReadonlyKeyword` instead. */ export type ReadonlyToken = ReadonlyKeyword; - export type Modifier = AbstractKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | ReadonlyKeyword | StaticKeyword; + export type Modifier = AbstractKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; export type AccessibilityModifier = PublicKeyword | PrivateKeyword | ProtectedKeyword; export type ParameterPropertyModifier = AccessibilityModifier | ReadonlyKeyword; export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword; @@ -1801,6 +1805,9 @@ declare namespace ts { export interface JSDocReadonlyTag extends JSDocTag { readonly kind: SyntaxKind.JSDocReadonlyTag; } + export interface JSDocOverrideTag extends JSDocTag { + readonly kind: SyntaxKind.JSDocOverrideTag; + } export interface JSDocEnumTag extends JSDocTag, Declaration { readonly kind: SyntaxKind.JSDocEnumTag; readonly parent: JSDoc; @@ -2861,6 +2868,7 @@ declare namespace ts { outFile?: string; paths?: MapLike; preserveConstEnums?: boolean; + noImplicitOverride?: boolean; preserveSymlinks?: boolean; project?: string; reactNamespace?: string; @@ -3535,6 +3543,8 @@ declare namespace ts { updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray | undefined): JSDocUnknownTag; createJSDocDeprecatedTag(tagName: Identifier, comment?: string | NodeArray): JSDocDeprecatedTag; updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier, comment?: string | NodeArray): JSDocDeprecatedTag; + createJSDocOverrideTag(tagName: Identifier, comment?: string | NodeArray): JSDocOverrideTag; + updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier, comment?: string | NodeArray): JSDocOverrideTag; createJSDocText(text: string): JSDocText; updateJSDocText(node: JSDocText, text: string): JSDocText; createJSDocComment(comment?: string | NodeArray | undefined, tags?: readonly JSDocTag[] | undefined): JSDoc; @@ -4184,6 +4194,7 @@ declare namespace ts { function getJSDocProtectedTag(node: Node): JSDocProtectedTag | undefined; /** Gets the JSDoc protected tag for the node if present */ function getJSDocReadonlyTag(node: Node): JSDocReadonlyTag | undefined; + function getJSDocOverrideTagNoCache(node: Node): JSDocOverrideTag | undefined; /** Gets the JSDoc deprecated tag for the node if present */ function getJSDocDeprecatedTag(node: Node): JSDocDeprecatedTag | undefined; /** Gets the JSDoc enum tag for the node if present */ @@ -4562,6 +4573,7 @@ declare namespace ts { function isJSDocPrivateTag(node: Node): node is JSDocPrivateTag; function isJSDocProtectedTag(node: Node): node is JSDocProtectedTag; function isJSDocReadonlyTag(node: Node): node is JSDocReadonlyTag; + function isJSDocOverrideTag(node: Node): node is JSDocOverrideTag; function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag; function isJSDocSeeTag(node: Node): node is JSDocSeeTag; function isJSDocEnumTag(node: Node): node is JSDocEnumTag; diff --git a/tests/baselines/reference/jsdocOverrideTag1.errors.txt b/tests/baselines/reference/jsdocOverrideTag1.errors.txt new file mode 100644 index 0000000000000..3bc565a1744bc --- /dev/null +++ b/tests/baselines/reference/jsdocOverrideTag1.errors.txt @@ -0,0 +1,55 @@ +tests/cases/conformance/jsdoc/0.js(27,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'A'. +tests/cases/conformance/jsdoc/0.js(32,5): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'A'. +tests/cases/conformance/jsdoc/0.js(40,5): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. + + +==== tests/cases/conformance/jsdoc/0.js (3 errors) ==== + class A { + + /** + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { + return typeof a === 'string' + } + bar () { + + } + } + + class B extends A { + /** + * @override + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { + return super.foo(a) + } + + bar () { + ~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'A'. + + } + + /** @override */ + baz () { + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'A'. + + } + } + + + class C { + /** @override */ + foo () { + ~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/jsdocOverrideTag1.symbols b/tests/baselines/reference/jsdocOverrideTag1.symbols new file mode 100644 index 0000000000000..8496b1024fc6a --- /dev/null +++ b/tests/baselines/reference/jsdocOverrideTag1.symbols @@ -0,0 +1,65 @@ +=== tests/cases/conformance/jsdoc/0.js === +class A { +>A : Symbol(A, Decl(0.js, 0, 0)) + + /** + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { +>foo : Symbol(A.foo, Decl(0.js, 0, 9)) +>a : Symbol(a, Decl(0.js, 7, 9)) + + return typeof a === 'string' +>a : Symbol(a, Decl(0.js, 7, 9)) + } + bar () { +>bar : Symbol(A.bar, Decl(0.js, 9, 5)) + + } +} + +class B extends A { +>B : Symbol(B, Decl(0.js, 13, 1)) +>A : Symbol(A, Decl(0.js, 0, 0)) + + /** + * @override + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { +>foo : Symbol(B.foo, Decl(0.js, 15, 19)) +>a : Symbol(a, Decl(0.js, 22, 9)) + + return super.foo(a) +>super.foo : Symbol(A.foo, Decl(0.js, 0, 9)) +>super : Symbol(A, Decl(0.js, 0, 0)) +>foo : Symbol(A.foo, Decl(0.js, 0, 9)) +>a : Symbol(a, Decl(0.js, 22, 9)) + } + + bar () { +>bar : Symbol(B.bar, Decl(0.js, 24, 5)) + + } + + /** @override */ + baz () { +>baz : Symbol(B.baz, Decl(0.js, 28, 5)) + + } +} + + +class C { +>C : Symbol(C, Decl(0.js, 34, 1)) + + /** @override */ + foo () { +>foo : Symbol(C.foo, Decl(0.js, 37, 9)) + + } +} diff --git a/tests/baselines/reference/jsdocOverrideTag1.types b/tests/baselines/reference/jsdocOverrideTag1.types new file mode 100644 index 0000000000000..f450dd56b8d5e --- /dev/null +++ b/tests/baselines/reference/jsdocOverrideTag1.types @@ -0,0 +1,69 @@ +=== tests/cases/conformance/jsdoc/0.js === +class A { +>A : A + + /** + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { +>foo : (a: string | number) => boolean +>a : string | number + + return typeof a === 'string' +>typeof a === 'string' : boolean +>typeof a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>a : string | number +>'string' : "string" + } + bar () { +>bar : () => void + + } +} + +class B extends A { +>B : B +>A : A + + /** + * @override + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { +>foo : (a: string | number) => boolean +>a : string | number + + return super.foo(a) +>super.foo(a) : boolean +>super.foo : (a: string | number) => boolean +>super : A +>foo : (a: string | number) => boolean +>a : string | number + } + + bar () { +>bar : () => void + + } + + /** @override */ + baz () { +>baz : () => void + + } +} + + +class C { +>C : C + + /** @override */ + foo () { +>foo : () => void + + } +} diff --git a/tests/baselines/reference/override1.errors.txt b/tests/baselines/reference/override1.errors.txt new file mode 100644 index 0000000000000..04b0333523e2a --- /dev/null +++ b/tests/baselines/reference/override1.errors.txt @@ -0,0 +1,71 @@ +tests/cases/conformance/override/override1.ts(9,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override1.ts(11,14): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. +tests/cases/conformance/override/override1.ts(15,14): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. +tests/cases/conformance/override/override1.ts(22,9): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override1.ts(24,18): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. +tests/cases/conformance/override/override1.ts(33,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class '(Anonymous class)'. +tests/cases/conformance/override/override1.ts(37,14): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class '(Anonymous class)'. +tests/cases/conformance/override/override1.ts(42,18): error TS4112: This member cannot have an 'override' modifier because its containing class '(Anonymous class)' does not extend another class. + + +==== tests/cases/conformance/override/override1.ts (8 errors) ==== + class B { + foo (v: string) {} + fooo (v: string) {} + } + + class D extends B { + override foo (v: string) {} + + fooo (v: string) {} + ~~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + + override bar(v: string) {} + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. + } + + class C { + override foo(v: string) {} + ~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. + } + + function f () { + return class extends B { + override foo (v: string) {} + + fooo (v: string) {} + ~~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + + override bar(v: string) {} + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. + } + } + + class E extends (class { + foo () { } + bar () { } + }) { + override foo () { } + bar () { } + ~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class '(Anonymous class)'. + + baz() {} + + override bazz () {} + ~~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class '(Anonymous class)'. + } + + function ff () { + return class { + override foo () {} + ~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class '(Anonymous class)' does not extend another class. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/override1.js b/tests/baselines/reference/override1.js new file mode 100644 index 0000000000000..af5357ffeac51 --- /dev/null +++ b/tests/baselines/reference/override1.js @@ -0,0 +1,161 @@ +//// [override1.ts] +class B { + foo (v: string) {} + fooo (v: string) {} +} + +class D extends B { + override foo (v: string) {} + + fooo (v: string) {} + + override bar(v: string) {} +} + +class C { + override foo(v: string) {} +} + +function f () { + return class extends B { + override foo (v: string) {} + + fooo (v: string) {} + + override bar(v: string) {} + } +} + +class E extends (class { + foo () { } + bar () { } +}) { + override foo () { } + bar () { } + + baz() {} + + override bazz () {} +} + +function ff () { + return class { + override foo () {} + } +} + +//// [override1.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B() { + } + B.prototype.foo = function (v) { }; + B.prototype.fooo = function (v) { }; + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + D.prototype.foo = function (v) { }; + D.prototype.fooo = function (v) { }; + D.prototype.bar = function (v) { }; + return D; +}(B)); +var C = /** @class */ (function () { + function C() { + } + C.prototype.foo = function (v) { }; + return C; +}()); +function f() { + return /** @class */ (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_1.prototype.foo = function (v) { }; + class_1.prototype.fooo = function (v) { }; + class_1.prototype.bar = function (v) { }; + return class_1; + }(B)); +} +var E = /** @class */ (function (_super) { + __extends(E, _super); + function E() { + return _super !== null && _super.apply(this, arguments) || this; + } + E.prototype.foo = function () { }; + E.prototype.bar = function () { }; + E.prototype.baz = function () { }; + E.prototype.bazz = function () { }; + return E; +}((/** @class */ (function () { + function class_2() { + } + class_2.prototype.foo = function () { }; + class_2.prototype.bar = function () { }; + return class_2; +}())))); +function ff() { + return /** @class */ (function () { + function class_3() { + } + class_3.prototype.foo = function () { }; + return class_3; + }()); +} + + +//// [override1.d.ts] +declare class B { + foo(v: string): void; + fooo(v: string): void; +} +declare class D extends B { + foo(v: string): void; + fooo(v: string): void; + bar(v: string): void; +} +declare class C { + foo(v: string): void; +} +declare function f(): { + new (): { + foo(v: string): void; + fooo(v: string): void; + bar(v: string): void; + }; +}; +declare const E_base: { + new (): { + foo(): void; + bar(): void; + }; +}; +declare class E extends E_base { + foo(): void; + bar(): void; + baz(): void; + bazz(): void; +} +declare function ff(): { + new (): { + foo(): void; + }; +}; diff --git a/tests/baselines/reference/override1.symbols b/tests/baselines/reference/override1.symbols new file mode 100644 index 0000000000000..18aa50df1d17a --- /dev/null +++ b/tests/baselines/reference/override1.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/override/override1.ts === +class B { +>B : Symbol(B, Decl(override1.ts, 0, 0)) + + foo (v: string) {} +>foo : Symbol(B.foo, Decl(override1.ts, 0, 9)) +>v : Symbol(v, Decl(override1.ts, 1, 9)) + + fooo (v: string) {} +>fooo : Symbol(B.fooo, Decl(override1.ts, 1, 22)) +>v : Symbol(v, Decl(override1.ts, 2, 10)) +} + +class D extends B { +>D : Symbol(D, Decl(override1.ts, 3, 1)) +>B : Symbol(B, Decl(override1.ts, 0, 0)) + + override foo (v: string) {} +>foo : Symbol(D.foo, Decl(override1.ts, 5, 19)) +>v : Symbol(v, Decl(override1.ts, 6, 18)) + + fooo (v: string) {} +>fooo : Symbol(D.fooo, Decl(override1.ts, 6, 31)) +>v : Symbol(v, Decl(override1.ts, 8, 10)) + + override bar(v: string) {} +>bar : Symbol(D.bar, Decl(override1.ts, 8, 23)) +>v : Symbol(v, Decl(override1.ts, 10, 17)) +} + +class C { +>C : Symbol(C, Decl(override1.ts, 11, 1)) + + override foo(v: string) {} +>foo : Symbol(C.foo, Decl(override1.ts, 13, 9)) +>v : Symbol(v, Decl(override1.ts, 14, 17)) +} + +function f () { +>f : Symbol(f, Decl(override1.ts, 15, 1)) + + return class extends B { +>B : Symbol(B, Decl(override1.ts, 0, 0)) + + override foo (v: string) {} +>foo : Symbol((Anonymous class).foo, Decl(override1.ts, 18, 28)) +>v : Symbol(v, Decl(override1.ts, 19, 22)) + + fooo (v: string) {} +>fooo : Symbol((Anonymous class).fooo, Decl(override1.ts, 19, 35)) +>v : Symbol(v, Decl(override1.ts, 21, 14)) + + override bar(v: string) {} +>bar : Symbol((Anonymous class).bar, Decl(override1.ts, 21, 27)) +>v : Symbol(v, Decl(override1.ts, 23, 21)) + } +} + +class E extends (class { +>E : Symbol(E, Decl(override1.ts, 25, 1)) + + foo () { } +>foo : Symbol((Anonymous class).foo, Decl(override1.ts, 27, 24)) + + bar () { } +>bar : Symbol((Anonymous class).bar, Decl(override1.ts, 28, 14)) + +}) { + override foo () { } +>foo : Symbol(E.foo, Decl(override1.ts, 30, 4)) + + bar () { } +>bar : Symbol(E.bar, Decl(override1.ts, 31, 23)) + + baz() {} +>baz : Symbol(E.baz, Decl(override1.ts, 32, 14)) + + override bazz () {} +>bazz : Symbol(E.bazz, Decl(override1.ts, 34, 12)) +} + +function ff () { +>ff : Symbol(ff, Decl(override1.ts, 37, 1)) + + return class { + override foo () {} +>foo : Symbol((Anonymous class).foo, Decl(override1.ts, 40, 18)) + } +} diff --git a/tests/baselines/reference/override1.types b/tests/baselines/reference/override1.types new file mode 100644 index 0000000000000..e65e151a7e53f --- /dev/null +++ b/tests/baselines/reference/override1.types @@ -0,0 +1,94 @@ +=== tests/cases/conformance/override/override1.ts === +class B { +>B : B + + foo (v: string) {} +>foo : (v: string) => void +>v : string + + fooo (v: string) {} +>fooo : (v: string) => void +>v : string +} + +class D extends B { +>D : D +>B : B + + override foo (v: string) {} +>foo : (v: string) => void +>v : string + + fooo (v: string) {} +>fooo : (v: string) => void +>v : string + + override bar(v: string) {} +>bar : (v: string) => void +>v : string +} + +class C { +>C : C + + override foo(v: string) {} +>foo : (v: string) => void +>v : string +} + +function f () { +>f : () => typeof (Anonymous class) + + return class extends B { +>class extends B { override foo (v: string) {} fooo (v: string) {} override bar(v: string) {} } : typeof (Anonymous class) +>B : B + + override foo (v: string) {} +>foo : (v: string) => void +>v : string + + fooo (v: string) {} +>fooo : (v: string) => void +>v : string + + override bar(v: string) {} +>bar : (v: string) => void +>v : string + } +} + +class E extends (class { +>E : E +>(class { foo () { } bar () { }}) : (Anonymous class) +>class { foo () { } bar () { }} : typeof (Anonymous class) + + foo () { } +>foo : () => void + + bar () { } +>bar : () => void + +}) { + override foo () { } +>foo : () => void + + bar () { } +>bar : () => void + + baz() {} +>baz : () => void + + override bazz () {} +>bazz : () => void +} + +function ff () { +>ff : () => typeof (Anonymous class) + + return class { +>class { override foo () {} } : typeof (Anonymous class) + + override foo () {} +>foo : () => void + } +} diff --git a/tests/baselines/reference/override10.js b/tests/baselines/reference/override10.js new file mode 100644 index 0000000000000..61de880a2ffad --- /dev/null +++ b/tests/baselines/reference/override10.js @@ -0,0 +1,53 @@ +//// [override10.ts] +abstract class Base { + abstract foo(): unknown; + abstract bar(): void; +} + +// No errors: +abstract class Sub extends Base { + override abstract foo(): number; + bar() { } +} + +//// [override10.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Base = /** @class */ (function () { + function Base() { + } + return Base; +}()); +// No errors: +var Sub = /** @class */ (function (_super) { + __extends(Sub, _super); + function Sub() { + return _super !== null && _super.apply(this, arguments) || this; + } + Sub.prototype.bar = function () { }; + return Sub; +}(Base)); + + +//// [override10.d.ts] +declare abstract class Base { + abstract foo(): unknown; + abstract bar(): void; +} +declare abstract class Sub extends Base { + abstract foo(): number; + bar(): void; +} diff --git a/tests/baselines/reference/override10.symbols b/tests/baselines/reference/override10.symbols new file mode 100644 index 0000000000000..99382520fd3bf --- /dev/null +++ b/tests/baselines/reference/override10.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/override/override10.ts === +abstract class Base { +>Base : Symbol(Base, Decl(override10.ts, 0, 0)) + + abstract foo(): unknown; +>foo : Symbol(Base.foo, Decl(override10.ts, 0, 21)) + + abstract bar(): void; +>bar : Symbol(Base.bar, Decl(override10.ts, 1, 28)) +} + +// No errors: +abstract class Sub extends Base { +>Sub : Symbol(Sub, Decl(override10.ts, 3, 1)) +>Base : Symbol(Base, Decl(override10.ts, 0, 0)) + + override abstract foo(): number; +>foo : Symbol(Sub.foo, Decl(override10.ts, 6, 33)) + + bar() { } +>bar : Symbol(Sub.bar, Decl(override10.ts, 7, 36)) +} diff --git a/tests/baselines/reference/override10.types b/tests/baselines/reference/override10.types new file mode 100644 index 0000000000000..ce42a87972701 --- /dev/null +++ b/tests/baselines/reference/override10.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/override/override10.ts === +abstract class Base { +>Base : Base + + abstract foo(): unknown; +>foo : () => unknown + + abstract bar(): void; +>bar : () => void +} + +// No errors: +abstract class Sub extends Base { +>Sub : Sub +>Base : Base + + override abstract foo(): number; +>foo : () => number + + bar() { } +>bar : () => void +} diff --git a/tests/baselines/reference/override11.errors.txt b/tests/baselines/reference/override11.errors.txt new file mode 100644 index 0000000000000..0af9f32dd0a65 --- /dev/null +++ b/tests/baselines/reference/override11.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/override/override11.ts(6,18): error TS1090: 'override' modifier cannot appear on a parameter. + + +==== tests/cases/conformance/override/override11.ts (1 errors) ==== + class Base { + foo = 1; + } + + class Sub extends Base { + constructor (override public foo: number) { + ~~~~~~~~ +!!! error TS1090: 'override' modifier cannot appear on a parameter. + super(); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/override11.js b/tests/baselines/reference/override11.js new file mode 100644 index 0000000000000..4bdc26c775942 --- /dev/null +++ b/tests/baselines/reference/override11.js @@ -0,0 +1,43 @@ +//// [override11.ts] +class Base { + foo = 1; +} + +class Sub extends Base { + constructor (override public foo: number) { + super(); + } +} + + +//// [override11.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Base = /** @class */ (function () { + function Base() { + this.foo = 1; + } + return Base; +}()); +var Sub = /** @class */ (function (_super) { + __extends(Sub, _super); + function Sub(foo) { + var _this = _super.call(this) || this; + _this.foo = foo; + return _this; + } + return Sub; +}(Base)); diff --git a/tests/baselines/reference/override11.symbols b/tests/baselines/reference/override11.symbols new file mode 100644 index 0000000000000..3f66e4e87f516 --- /dev/null +++ b/tests/baselines/reference/override11.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/override/override11.ts === +class Base { +>Base : Symbol(Base, Decl(override11.ts, 0, 0)) + + foo = 1; +>foo : Symbol(Base.foo, Decl(override11.ts, 0, 12)) +} + +class Sub extends Base { +>Sub : Symbol(Sub, Decl(override11.ts, 2, 1)) +>Base : Symbol(Base, Decl(override11.ts, 0, 0)) + + constructor (override public foo: number) { +>foo : Symbol(Sub.foo, Decl(override11.ts, 5, 17)) + + super(); +>super : Symbol(Base, Decl(override11.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/override11.types b/tests/baselines/reference/override11.types new file mode 100644 index 0000000000000..679ab4b89fbfc --- /dev/null +++ b/tests/baselines/reference/override11.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/override/override11.ts === +class Base { +>Base : Base + + foo = 1; +>foo : number +>1 : 1 +} + +class Sub extends Base { +>Sub : Sub +>Base : Base + + constructor (override public foo: number) { +>foo : number + + super(); +>super() : void +>super : typeof Base + } +} + diff --git a/tests/baselines/reference/override2.errors.txt b/tests/baselines/reference/override2.errors.txt new file mode 100644 index 0000000000000..ed32ab6aae706 --- /dev/null +++ b/tests/baselines/reference/override2.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/override/override2.ts(13,14): error TS4116: This member must have an 'override' modifier because it overrides an abstract method that is declared in the base class 'AB'. +tests/cases/conformance/override/override2.ts(18,14): error TS4116: This member must have an 'override' modifier because it overrides an abstract method that is declared in the base class 'AB'. + + +==== tests/cases/conformance/override/override2.ts (2 errors) ==== + abstract class AB { + abstract foo(v: string): void; + + abstract bar(v: string): void; + abstract baz(v: string): void; + } + + abstract class AD1 extends AB { + + } + + abstract class AD2 extends AB { + abstract foo(v: ''): void // need override? + ~~~ +!!! error TS4116: This member must have an 'override' modifier because it overrides an abstract method that is declared in the base class 'AB'. + } + + abstract class AD3 extends AB { + override foo(v: ''): void { } // need override? + abstract bar(): void; + ~~~ +!!! error TS4116: This member must have an 'override' modifier because it overrides an abstract method that is declared in the base class 'AB'. + baz(): void { } + } + + class D4 extends AB { + override foo(v: ''): void {} + override bar(v: ''): void {} + baz(): void { } + } \ No newline at end of file diff --git a/tests/baselines/reference/override2.js b/tests/baselines/reference/override2.js new file mode 100644 index 0000000000000..2f8d6ce799887 --- /dev/null +++ b/tests/baselines/reference/override2.js @@ -0,0 +1,105 @@ +//// [override2.ts] +abstract class AB { + abstract foo(v: string): void; + + abstract bar(v: string): void; + abstract baz(v: string): void; +} + +abstract class AD1 extends AB { + +} + +abstract class AD2 extends AB { + abstract foo(v: ''): void // need override? +} + +abstract class AD3 extends AB { + override foo(v: ''): void { } // need override? + abstract bar(): void; + baz(): void { } +} + +class D4 extends AB { + override foo(v: ''): void {} + override bar(v: ''): void {} + baz(): void { } +} + +//// [override2.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var AB = /** @class */ (function () { + function AB() { + } + return AB; +}()); +var AD1 = /** @class */ (function (_super) { + __extends(AD1, _super); + function AD1() { + return _super !== null && _super.apply(this, arguments) || this; + } + return AD1; +}(AB)); +var AD2 = /** @class */ (function (_super) { + __extends(AD2, _super); + function AD2() { + return _super !== null && _super.apply(this, arguments) || this; + } + return AD2; +}(AB)); +var AD3 = /** @class */ (function (_super) { + __extends(AD3, _super); + function AD3() { + return _super !== null && _super.apply(this, arguments) || this; + } + AD3.prototype.foo = function (v) { }; // need override? + AD3.prototype.baz = function () { }; + return AD3; +}(AB)); +var D4 = /** @class */ (function (_super) { + __extends(D4, _super); + function D4() { + return _super !== null && _super.apply(this, arguments) || this; + } + D4.prototype.foo = function (v) { }; + D4.prototype.bar = function (v) { }; + D4.prototype.baz = function () { }; + return D4; +}(AB)); + + +//// [override2.d.ts] +declare abstract class AB { + abstract foo(v: string): void; + abstract bar(v: string): void; + abstract baz(v: string): void; +} +declare abstract class AD1 extends AB { +} +declare abstract class AD2 extends AB { + abstract foo(v: ''): void; +} +declare abstract class AD3 extends AB { + foo(v: ''): void; + abstract bar(): void; + baz(): void; +} +declare class D4 extends AB { + foo(v: ''): void; + bar(v: ''): void; + baz(): void; +} diff --git a/tests/baselines/reference/override2.symbols b/tests/baselines/reference/override2.symbols new file mode 100644 index 0000000000000..869047851e5e3 --- /dev/null +++ b/tests/baselines/reference/override2.symbols @@ -0,0 +1,62 @@ +=== tests/cases/conformance/override/override2.ts === +abstract class AB { +>AB : Symbol(AB, Decl(override2.ts, 0, 0)) + + abstract foo(v: string): void; +>foo : Symbol(AB.foo, Decl(override2.ts, 0, 19)) +>v : Symbol(v, Decl(override2.ts, 1, 17)) + + abstract bar(v: string): void; +>bar : Symbol(AB.bar, Decl(override2.ts, 1, 34)) +>v : Symbol(v, Decl(override2.ts, 3, 17)) + + abstract baz(v: string): void; +>baz : Symbol(AB.baz, Decl(override2.ts, 3, 34)) +>v : Symbol(v, Decl(override2.ts, 4, 17)) +} + +abstract class AD1 extends AB { +>AD1 : Symbol(AD1, Decl(override2.ts, 5, 1)) +>AB : Symbol(AB, Decl(override2.ts, 0, 0)) + +} + +abstract class AD2 extends AB { +>AD2 : Symbol(AD2, Decl(override2.ts, 9, 1)) +>AB : Symbol(AB, Decl(override2.ts, 0, 0)) + + abstract foo(v: ''): void // need override? +>foo : Symbol(AD2.foo, Decl(override2.ts, 11, 31)) +>v : Symbol(v, Decl(override2.ts, 12, 17)) +} + +abstract class AD3 extends AB { +>AD3 : Symbol(AD3, Decl(override2.ts, 13, 1)) +>AB : Symbol(AB, Decl(override2.ts, 0, 0)) + + override foo(v: ''): void { } // need override? +>foo : Symbol(AD3.foo, Decl(override2.ts, 15, 31)) +>v : Symbol(v, Decl(override2.ts, 16, 17)) + + abstract bar(): void; +>bar : Symbol(AD3.bar, Decl(override2.ts, 16, 33)) + + baz(): void { } +>baz : Symbol(AD3.baz, Decl(override2.ts, 17, 25)) +} + +class D4 extends AB { +>D4 : Symbol(D4, Decl(override2.ts, 19, 1)) +>AB : Symbol(AB, Decl(override2.ts, 0, 0)) + + override foo(v: ''): void {} +>foo : Symbol(D4.foo, Decl(override2.ts, 21, 21)) +>v : Symbol(v, Decl(override2.ts, 22, 17)) + + override bar(v: ''): void {} +>bar : Symbol(D4.bar, Decl(override2.ts, 22, 32)) +>v : Symbol(v, Decl(override2.ts, 23, 17)) + + baz(): void { } +>baz : Symbol(D4.baz, Decl(override2.ts, 23, 32)) +} diff --git a/tests/baselines/reference/override2.types b/tests/baselines/reference/override2.types new file mode 100644 index 0000000000000..98bd1f1902a73 --- /dev/null +++ b/tests/baselines/reference/override2.types @@ -0,0 +1,62 @@ +=== tests/cases/conformance/override/override2.ts === +abstract class AB { +>AB : AB + + abstract foo(v: string): void; +>foo : (v: string) => void +>v : string + + abstract bar(v: string): void; +>bar : (v: string) => void +>v : string + + abstract baz(v: string): void; +>baz : (v: string) => void +>v : string +} + +abstract class AD1 extends AB { +>AD1 : AD1 +>AB : AB + +} + +abstract class AD2 extends AB { +>AD2 : AD2 +>AB : AB + + abstract foo(v: ''): void // need override? +>foo : (v: '') => void +>v : "" +} + +abstract class AD3 extends AB { +>AD3 : AD3 +>AB : AB + + override foo(v: ''): void { } // need override? +>foo : (v: '') => void +>v : "" + + abstract bar(): void; +>bar : () => void + + baz(): void { } +>baz : () => void +} + +class D4 extends AB { +>D4 : D4 +>AB : AB + + override foo(v: ''): void {} +>foo : (v: '') => void +>v : "" + + override bar(v: ''): void {} +>bar : (v: '') => void +>v : "" + + baz(): void { } +>baz : () => void +} diff --git a/tests/baselines/reference/override3.errors.txt b/tests/baselines/reference/override3.errors.txt new file mode 100644 index 0000000000000..b3d1c98b2f76d --- /dev/null +++ b/tests/baselines/reference/override3.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/override/override3.ts(22,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'D'. + + +==== tests/cases/conformance/override/override3.ts (1 errors) ==== + declare class B { + foo(): void + bar(): void + } + + declare class D extends B { + foo (): void; + override bar (): void; + } + + class DB extends B { + override foo(): void {} + override bar(): void {} + } + + class DD extends D { + override foo(): void {} + override bar(): void {} + } + + class EB extends D { + foo(): void {} + ~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'D'. + override bar(): void {} + } + \ No newline at end of file diff --git a/tests/baselines/reference/override3.js b/tests/baselines/reference/override3.js new file mode 100644 index 0000000000000..dc7f818c87f64 --- /dev/null +++ b/tests/baselines/reference/override3.js @@ -0,0 +1,93 @@ +//// [override3.ts] +declare class B { + foo(): void + bar(): void +} + +declare class D extends B { + foo (): void; + override bar (): void; +} + +class DB extends B { + override foo(): void {} + override bar(): void {} +} + +class DD extends D { + override foo(): void {} + override bar(): void {} +} + +class EB extends D { + foo(): void {} + override bar(): void {} +} + + +//// [override3.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var DB = /** @class */ (function (_super) { + __extends(DB, _super); + function DB() { + return _super !== null && _super.apply(this, arguments) || this; + } + DB.prototype.foo = function () { }; + DB.prototype.bar = function () { }; + return DB; +}(B)); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD() { + return _super !== null && _super.apply(this, arguments) || this; + } + DD.prototype.foo = function () { }; + DD.prototype.bar = function () { }; + return DD; +}(D)); +var EB = /** @class */ (function (_super) { + __extends(EB, _super); + function EB() { + return _super !== null && _super.apply(this, arguments) || this; + } + EB.prototype.foo = function () { }; + EB.prototype.bar = function () { }; + return EB; +}(D)); + + +//// [override3.d.ts] +declare class B { + foo(): void; + bar(): void; +} +declare class D extends B { + foo(): void; + bar(): void; +} +declare class DB extends B { + foo(): void; + bar(): void; +} +declare class DD extends D { + foo(): void; + bar(): void; +} +declare class EB extends D { + foo(): void; + bar(): void; +} diff --git a/tests/baselines/reference/override3.symbols b/tests/baselines/reference/override3.symbols new file mode 100644 index 0000000000000..cc529eef3fffb --- /dev/null +++ b/tests/baselines/reference/override3.symbols @@ -0,0 +1,55 @@ +=== tests/cases/conformance/override/override3.ts === +declare class B { +>B : Symbol(B, Decl(override3.ts, 0, 0)) + + foo(): void +>foo : Symbol(B.foo, Decl(override3.ts, 0, 17)) + + bar(): void +>bar : Symbol(B.bar, Decl(override3.ts, 1, 15)) +} + +declare class D extends B { +>D : Symbol(D, Decl(override3.ts, 3, 1)) +>B : Symbol(B, Decl(override3.ts, 0, 0)) + + foo (): void; +>foo : Symbol(D.foo, Decl(override3.ts, 5, 27)) + + override bar (): void; +>bar : Symbol(D.bar, Decl(override3.ts, 6, 17)) +} + +class DB extends B { +>DB : Symbol(DB, Decl(override3.ts, 8, 1)) +>B : Symbol(B, Decl(override3.ts, 0, 0)) + + override foo(): void {} +>foo : Symbol(DB.foo, Decl(override3.ts, 10, 20)) + + override bar(): void {} +>bar : Symbol(DB.bar, Decl(override3.ts, 11, 27)) +} + +class DD extends D { +>DD : Symbol(DD, Decl(override3.ts, 13, 1)) +>D : Symbol(D, Decl(override3.ts, 3, 1)) + + override foo(): void {} +>foo : Symbol(DD.foo, Decl(override3.ts, 15, 20)) + + override bar(): void {} +>bar : Symbol(DD.bar, Decl(override3.ts, 16, 27)) +} + +class EB extends D { +>EB : Symbol(EB, Decl(override3.ts, 18, 1)) +>D : Symbol(D, Decl(override3.ts, 3, 1)) + + foo(): void {} +>foo : Symbol(EB.foo, Decl(override3.ts, 20, 20)) + + override bar(): void {} +>bar : Symbol(EB.bar, Decl(override3.ts, 21, 18)) +} + diff --git a/tests/baselines/reference/override3.types b/tests/baselines/reference/override3.types new file mode 100644 index 0000000000000..6e94141d6ef5f --- /dev/null +++ b/tests/baselines/reference/override3.types @@ -0,0 +1,55 @@ +=== tests/cases/conformance/override/override3.ts === +declare class B { +>B : B + + foo(): void +>foo : () => void + + bar(): void +>bar : () => void +} + +declare class D extends B { +>D : D +>B : B + + foo (): void; +>foo : () => void + + override bar (): void; +>bar : () => void +} + +class DB extends B { +>DB : DB +>B : B + + override foo(): void {} +>foo : () => void + + override bar(): void {} +>bar : () => void +} + +class DD extends D { +>DD : DD +>D : D + + override foo(): void {} +>foo : () => void + + override bar(): void {} +>bar : () => void +} + +class EB extends D { +>EB : EB +>D : D + + foo(): void {} +>foo : () => void + + override bar(): void {} +>bar : () => void +} + diff --git a/tests/baselines/reference/override4.errors.txt b/tests/baselines/reference/override4.errors.txt new file mode 100644 index 0000000000000..baec00687f13f --- /dev/null +++ b/tests/baselines/reference/override4.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/override/override4.ts(11,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override4.ts(13,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override4.ts(17,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override4.ts(23,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + + +==== tests/cases/conformance/override/override4.ts (4 errors) ==== + class B { + p1: number = 1; + p2: number = 1; + p3: () => void; + p4: () => void; + foo (v: string) {} + fooo (v: string) {} + } + + class D extends B { + p1: number = 2; + ~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + override p2: number = 3; + p3: () => void; + ~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + override p4: () => void; + override foo (v: string) {} + + fooo (v: string) {} + ~~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + + } + + class DD extends B { + override foo: () => void + fooo: () => void; + ~~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + } \ No newline at end of file diff --git a/tests/baselines/reference/override4.js b/tests/baselines/reference/override4.js new file mode 100644 index 0000000000000..6fbb9eac2ec0b --- /dev/null +++ b/tests/baselines/reference/override4.js @@ -0,0 +1,93 @@ +//// [override4.ts] +class B { + p1: number = 1; + p2: number = 1; + p3: () => void; + p4: () => void; + foo (v: string) {} + fooo (v: string) {} +} + +class D extends B { + p1: number = 2; + override p2: number = 3; + p3: () => void; + override p4: () => void; + override foo (v: string) {} + + fooo (v: string) {} + +} + +class DD extends B { + override foo: () => void + fooo: () => void; +} + +//// [override4.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B() { + this.p1 = 1; + this.p2 = 1; + } + B.prototype.foo = function (v) { }; + B.prototype.fooo = function (v) { }; + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.p1 = 2; + _this.p2 = 3; + return _this; + } + D.prototype.foo = function (v) { }; + D.prototype.fooo = function (v) { }; + return D; +}(B)); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD() { + return _super !== null && _super.apply(this, arguments) || this; + } + return DD; +}(B)); + + +//// [override4.d.ts] +declare class B { + p1: number; + p2: number; + p3: () => void; + p4: () => void; + foo(v: string): void; + fooo(v: string): void; +} +declare class D extends B { + p1: number; + p2: number; + p3: () => void; + p4: () => void; + foo(v: string): void; + fooo(v: string): void; +} +declare class DD extends B { + foo: () => void; + fooo: () => void; +} diff --git a/tests/baselines/reference/override4.symbols b/tests/baselines/reference/override4.symbols new file mode 100644 index 0000000000000..f6926e47ffdde --- /dev/null +++ b/tests/baselines/reference/override4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/override/override4.ts === +class B { +>B : Symbol(B, Decl(override4.ts, 0, 0)) + + p1: number = 1; +>p1 : Symbol(B.p1, Decl(override4.ts, 0, 9)) + + p2: number = 1; +>p2 : Symbol(B.p2, Decl(override4.ts, 1, 19)) + + p3: () => void; +>p3 : Symbol(B.p3, Decl(override4.ts, 2, 19)) + + p4: () => void; +>p4 : Symbol(B.p4, Decl(override4.ts, 3, 19)) + + foo (v: string) {} +>foo : Symbol(B.foo, Decl(override4.ts, 4, 19)) +>v : Symbol(v, Decl(override4.ts, 5, 9)) + + fooo (v: string) {} +>fooo : Symbol(B.fooo, Decl(override4.ts, 5, 22)) +>v : Symbol(v, Decl(override4.ts, 6, 10)) +} + +class D extends B { +>D : Symbol(D, Decl(override4.ts, 7, 1)) +>B : Symbol(B, Decl(override4.ts, 0, 0)) + + p1: number = 2; +>p1 : Symbol(D.p1, Decl(override4.ts, 9, 19)) + + override p2: number = 3; +>p2 : Symbol(D.p2, Decl(override4.ts, 10, 19)) + + p3: () => void; +>p3 : Symbol(D.p3, Decl(override4.ts, 11, 28)) + + override p4: () => void; +>p4 : Symbol(D.p4, Decl(override4.ts, 12, 19)) + + override foo (v: string) {} +>foo : Symbol(D.foo, Decl(override4.ts, 13, 28)) +>v : Symbol(v, Decl(override4.ts, 14, 18)) + + fooo (v: string) {} +>fooo : Symbol(D.fooo, Decl(override4.ts, 14, 31)) +>v : Symbol(v, Decl(override4.ts, 16, 10)) + +} + +class DD extends B { +>DD : Symbol(DD, Decl(override4.ts, 18, 1)) +>B : Symbol(B, Decl(override4.ts, 0, 0)) + + override foo: () => void +>foo : Symbol(DD.foo, Decl(override4.ts, 20, 20)) + + fooo: () => void; +>fooo : Symbol(DD.fooo, Decl(override4.ts, 21, 28)) +} diff --git a/tests/baselines/reference/override4.types b/tests/baselines/reference/override4.types new file mode 100644 index 0000000000000..7803126098b58 --- /dev/null +++ b/tests/baselines/reference/override4.types @@ -0,0 +1,65 @@ +=== tests/cases/conformance/override/override4.ts === +class B { +>B : B + + p1: number = 1; +>p1 : number +>1 : 1 + + p2: number = 1; +>p2 : number +>1 : 1 + + p3: () => void; +>p3 : () => void + + p4: () => void; +>p4 : () => void + + foo (v: string) {} +>foo : (v: string) => void +>v : string + + fooo (v: string) {} +>fooo : (v: string) => void +>v : string +} + +class D extends B { +>D : D +>B : B + + p1: number = 2; +>p1 : number +>2 : 2 + + override p2: number = 3; +>p2 : number +>3 : 3 + + p3: () => void; +>p3 : () => void + + override p4: () => void; +>p4 : () => void + + override foo (v: string) {} +>foo : (v: string) => void +>v : string + + fooo (v: string) {} +>fooo : (v: string) => void +>v : string + +} + +class DD extends B { +>DD : DD +>B : B + + override foo: () => void +>foo : () => void + + fooo: () => void; +>fooo : () => void +} diff --git a/tests/baselines/reference/override5.errors.txt b/tests/baselines/reference/override5.errors.txt new file mode 100644 index 0000000000000..18358a4928284 --- /dev/null +++ b/tests/baselines/reference/override5.errors.txt @@ -0,0 +1,83 @@ +tests/cases/conformance/override/override5.ts(12,13): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override5.ts(14,14): error TS1040: 'override' modifier cannot be used in an ambient context. +tests/cases/conformance/override/override5.ts(20,14): error TS1243: 'static' modifier cannot be used with 'override' modifier. +tests/cases/conformance/override/override5.ts(22,14): error TS1030: 'override' modifier already seen. +tests/cases/conformance/override/override5.ts(25,14): error TS1029: 'public' modifier must precede 'override' modifier. +tests/cases/conformance/override/override5.ts(27,5): error TS1089: 'override' modifier cannot appear on a constructor declaration. +tests/cases/conformance/override/override5.ts(44,23): error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. +tests/cases/conformance/override/override5.ts(45,23): error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. + + +==== tests/cases/conformance/override/override5.ts (8 errors) ==== + class B { + p1: number = 1; + p2: number = 2; + p3: number = 3; + p4: number = 4; + oop: number; + pp: number; + op: number; + } + + class D extends B{ + declare p1: number + ~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + + override declare p2: number; + ~~~~~~~ +!!! error TS1040: 'override' modifier cannot be used in an ambient context. + + readonly override p3: number; + + override readonly p4: number; + + override static sp: number; + ~~~~~~ +!!! error TS1243: 'static' modifier cannot be used with 'override' modifier. + + override override oop: number; + ~~~~~~~~ +!!! error TS1030: 'override' modifier already seen. + + public override pp: number; + override public op: number; + ~~~~~~ +!!! error TS1029: 'public' modifier must precede 'override' modifier. + + override constructor () { + ~~~~~~~~ +!!! error TS1089: 'override' modifier cannot appear on a constructor declaration. + super(); + } + } + + + abstract class AB { + abstract f (): void; + abstract b (): void; + } + + abstract class AD extends AB { + override abstract f(): void; + abstract override b(): void; + } + + abstract class AND { + override abstract f(): void; + ~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. + abstract override b(): void; + ~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. + } + + class ADD extends AD { + f(): void { + + } + override b(): void { + + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/override5.js b/tests/baselines/reference/override5.js new file mode 100644 index 0000000000000..3ab9d96d52f6b --- /dev/null +++ b/tests/baselines/reference/override5.js @@ -0,0 +1,157 @@ +//// [override5.ts] +class B { + p1: number = 1; + p2: number = 2; + p3: number = 3; + p4: number = 4; + oop: number; + pp: number; + op: number; +} + +class D extends B{ + declare p1: number + + override declare p2: number; + + readonly override p3: number; + + override readonly p4: number; + + override static sp: number; + + override override oop: number; + + public override pp: number; + override public op: number; + + override constructor () { + super(); + } +} + + +abstract class AB { + abstract f (): void; + abstract b (): void; +} + +abstract class AD extends AB { + override abstract f(): void; + abstract override b(): void; +} + +abstract class AND { + override abstract f(): void; + abstract override b(): void; +} + +class ADD extends AD { + f(): void { + + } + override b(): void { + + } +} + + +//// [override5.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B() { + this.p1 = 1; + this.p2 = 2; + this.p3 = 3; + this.p4 = 4; + } + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super.call(this) || this; + } + return D; +}(B)); +var AB = /** @class */ (function () { + function AB() { + } + return AB; +}()); +var AD = /** @class */ (function (_super) { + __extends(AD, _super); + function AD() { + return _super !== null && _super.apply(this, arguments) || this; + } + return AD; +}(AB)); +var AND = /** @class */ (function () { + function AND() { + } + return AND; +}()); +var ADD = /** @class */ (function (_super) { + __extends(ADD, _super); + function ADD() { + return _super !== null && _super.apply(this, arguments) || this; + } + ADD.prototype.f = function () { + }; + ADD.prototype.b = function () { + }; + return ADD; +}(AD)); + + +//// [override5.d.ts] +declare class B { + p1: number; + p2: number; + p3: number; + p4: number; + oop: number; + pp: number; + op: number; +} +declare class D extends B { + p1: number; + p2: number; + readonly p3: number; + readonly p4: number; + static sp: number; + oop: number; + pp: number; + op: number; + constructor(); +} +declare abstract class AB { + abstract f(): void; + abstract b(): void; +} +declare abstract class AD extends AB { + abstract f(): void; + abstract b(): void; +} +declare abstract class AND { + abstract f(): void; + abstract b(): void; +} +declare class ADD extends AD { + f(): void; + b(): void; +} diff --git a/tests/baselines/reference/override5.symbols b/tests/baselines/reference/override5.symbols new file mode 100644 index 0000000000000..9f504d682652e --- /dev/null +++ b/tests/baselines/reference/override5.symbols @@ -0,0 +1,106 @@ +=== tests/cases/conformance/override/override5.ts === +class B { +>B : Symbol(B, Decl(override5.ts, 0, 0)) + + p1: number = 1; +>p1 : Symbol(B.p1, Decl(override5.ts, 0, 9)) + + p2: number = 2; +>p2 : Symbol(B.p2, Decl(override5.ts, 1, 19)) + + p3: number = 3; +>p3 : Symbol(B.p3, Decl(override5.ts, 2, 19)) + + p4: number = 4; +>p4 : Symbol(B.p4, Decl(override5.ts, 3, 19)) + + oop: number; +>oop : Symbol(B.oop, Decl(override5.ts, 4, 19)) + + pp: number; +>pp : Symbol(B.pp, Decl(override5.ts, 5, 16)) + + op: number; +>op : Symbol(B.op, Decl(override5.ts, 6, 15)) +} + +class D extends B{ +>D : Symbol(D, Decl(override5.ts, 8, 1)) +>B : Symbol(B, Decl(override5.ts, 0, 0)) + + declare p1: number +>p1 : Symbol(D.p1, Decl(override5.ts, 10, 18)) + + override declare p2: number; +>p2 : Symbol(D.p2, Decl(override5.ts, 11, 22)) + + readonly override p3: number; +>p3 : Symbol(D.p3, Decl(override5.ts, 13, 32)) + + override readonly p4: number; +>p4 : Symbol(D.p4, Decl(override5.ts, 15, 33)) + + override static sp: number; +>sp : Symbol(D.sp, Decl(override5.ts, 17, 33)) + + override override oop: number; +>oop : Symbol(D.oop, Decl(override5.ts, 19, 31)) + + public override pp: number; +>pp : Symbol(D.pp, Decl(override5.ts, 21, 34)) + + override public op: number; +>op : Symbol(D.op, Decl(override5.ts, 23, 31)) + + override constructor () { + super(); +>super : Symbol(B, Decl(override5.ts, 0, 0)) + } +} + + +abstract class AB { +>AB : Symbol(AB, Decl(override5.ts, 29, 1)) + + abstract f (): void; +>f : Symbol(AB.f, Decl(override5.ts, 32, 19)) + + abstract b (): void; +>b : Symbol(AB.b, Decl(override5.ts, 33, 24)) +} + +abstract class AD extends AB { +>AD : Symbol(AD, Decl(override5.ts, 35, 1)) +>AB : Symbol(AB, Decl(override5.ts, 29, 1)) + + override abstract f(): void; +>f : Symbol(AD.f, Decl(override5.ts, 37, 30)) + + abstract override b(): void; +>b : Symbol(AD.b, Decl(override5.ts, 38, 32)) +} + +abstract class AND { +>AND : Symbol(AND, Decl(override5.ts, 40, 1)) + + override abstract f(): void; +>f : Symbol(AND.f, Decl(override5.ts, 42, 20)) + + abstract override b(): void; +>b : Symbol(AND.b, Decl(override5.ts, 43, 32)) +} + +class ADD extends AD { +>ADD : Symbol(ADD, Decl(override5.ts, 45, 1)) +>AD : Symbol(AD, Decl(override5.ts, 35, 1)) + + f(): void { +>f : Symbol(ADD.f, Decl(override5.ts, 47, 22)) + + } + override b(): void { +>b : Symbol(ADD.b, Decl(override5.ts, 50, 5)) + + } +} + diff --git a/tests/baselines/reference/override5.types b/tests/baselines/reference/override5.types new file mode 100644 index 0000000000000..f65d7b3cabb43 --- /dev/null +++ b/tests/baselines/reference/override5.types @@ -0,0 +1,111 @@ +=== tests/cases/conformance/override/override5.ts === +class B { +>B : B + + p1: number = 1; +>p1 : number +>1 : 1 + + p2: number = 2; +>p2 : number +>2 : 2 + + p3: number = 3; +>p3 : number +>3 : 3 + + p4: number = 4; +>p4 : number +>4 : 4 + + oop: number; +>oop : number + + pp: number; +>pp : number + + op: number; +>op : number +} + +class D extends B{ +>D : D +>B : B + + declare p1: number +>p1 : number + + override declare p2: number; +>p2 : number + + readonly override p3: number; +>p3 : number + + override readonly p4: number; +>p4 : number + + override static sp: number; +>sp : number + + override override oop: number; +>oop : number + + public override pp: number; +>pp : number + + override public op: number; +>op : number + + override constructor () { + super(); +>super() : void +>super : typeof B + } +} + + +abstract class AB { +>AB : AB + + abstract f (): void; +>f : () => void + + abstract b (): void; +>b : () => void +} + +abstract class AD extends AB { +>AD : AD +>AB : AB + + override abstract f(): void; +>f : () => void + + abstract override b(): void; +>b : () => void +} + +abstract class AND { +>AND : AND + + override abstract f(): void; +>f : () => void + + abstract override b(): void; +>b : () => void +} + +class ADD extends AD { +>ADD : ADD +>AD : AD + + f(): void { +>f : () => void + + } + override b(): void { +>b : () => void + + } +} + diff --git a/tests/baselines/reference/override6.errors.txt b/tests/baselines/reference/override6.errors.txt new file mode 100644 index 0000000000000..cd05376f2a63f --- /dev/null +++ b/tests/baselines/reference/override6.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/override/override6.ts(9,12): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/override6.ts(10,17): error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'B'. +tests/cases/conformance/override/override6.ts(10,37): error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'B'. + + +==== tests/cases/conformance/override/override6.ts (3 errors) ==== + class B { + public baz: number = 1; + constructor(public foo: string, public bar: number) { + + } + } + + class D extends B { + public bar: number = 1 + ~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + constructor(public foo: string, public baz: number) { + ~~~~~~~~~~~~~~~~~~ +!!! error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'B'. + ~~~~~~~~~~~~~~~~~~ +!!! error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'B'. + super(foo, 42) + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/override6.js b/tests/baselines/reference/override6.js new file mode 100644 index 0000000000000..f27cf2a32f25f --- /dev/null +++ b/tests/baselines/reference/override6.js @@ -0,0 +1,66 @@ +//// [override6.ts] +class B { + public baz: number = 1; + constructor(public foo: string, public bar: number) { + + } +} + +class D extends B { + public bar: number = 1 + constructor(public foo: string, public baz: number) { + super(foo, 42) + } +} + + +//// [override6.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B(foo, bar) { + this.foo = foo; + this.bar = bar; + this.baz = 1; + } + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D(foo, baz) { + var _this = _super.call(this, foo, 42) || this; + _this.foo = foo; + _this.baz = baz; + _this.bar = 1; + return _this; + } + return D; +}(B)); + + +//// [override6.d.ts] +declare class B { + foo: string; + bar: number; + baz: number; + constructor(foo: string, bar: number); +} +declare class D extends B { + foo: string; + baz: number; + bar: number; + constructor(foo: string, baz: number); +} diff --git a/tests/baselines/reference/override6.symbols b/tests/baselines/reference/override6.symbols new file mode 100644 index 0000000000000..b341f2276cde4 --- /dev/null +++ b/tests/baselines/reference/override6.symbols @@ -0,0 +1,31 @@ +=== tests/cases/conformance/override/override6.ts === +class B { +>B : Symbol(B, Decl(override6.ts, 0, 0)) + + public baz: number = 1; +>baz : Symbol(B.baz, Decl(override6.ts, 0, 9)) + + constructor(public foo: string, public bar: number) { +>foo : Symbol(B.foo, Decl(override6.ts, 2, 16)) +>bar : Symbol(B.bar, Decl(override6.ts, 2, 35)) + + } +} + +class D extends B { +>D : Symbol(D, Decl(override6.ts, 5, 1)) +>B : Symbol(B, Decl(override6.ts, 0, 0)) + + public bar: number = 1 +>bar : Symbol(D.bar, Decl(override6.ts, 7, 19)) + + constructor(public foo: string, public baz: number) { +>foo : Symbol(D.foo, Decl(override6.ts, 9, 16)) +>baz : Symbol(D.baz, Decl(override6.ts, 9, 35)) + + super(foo, 42) +>super : Symbol(B, Decl(override6.ts, 0, 0)) +>foo : Symbol(foo, Decl(override6.ts, 9, 16)) + } +} + diff --git a/tests/baselines/reference/override6.types b/tests/baselines/reference/override6.types new file mode 100644 index 0000000000000..a57f57847bf2c --- /dev/null +++ b/tests/baselines/reference/override6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/override/override6.ts === +class B { +>B : B + + public baz: number = 1; +>baz : number +>1 : 1 + + constructor(public foo: string, public bar: number) { +>foo : string +>bar : number + + } +} + +class D extends B { +>D : D +>B : B + + public bar: number = 1 +>bar : number +>1 : 1 + + constructor(public foo: string, public baz: number) { +>foo : string +>baz : number + + super(foo, 42) +>super(foo, 42) : void +>super : typeof B +>foo : string +>42 : 42 + } +} + diff --git a/tests/baselines/reference/override7.errors.txt b/tests/baselines/reference/override7.errors.txt new file mode 100644 index 0000000000000..69e96245c3b1c --- /dev/null +++ b/tests/baselines/reference/override7.errors.txt @@ -0,0 +1,74 @@ +tests/cases/conformance/override/override7.ts(19,14): error TS1030: 'override' modifier already seen. +tests/cases/conformance/override/override7.ts(19,23): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. +tests/cases/conformance/override/override7.ts(21,21): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. +tests/cases/conformance/override/override7.ts(22,21): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. +tests/cases/conformance/override/override7.ts(41,23): error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. +tests/cases/conformance/override/override7.ts(42,23): error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. + + +==== tests/cases/conformance/override/override7.ts (6 errors) ==== + class B { + p1: number = 1; + p2: number = 2; + p3: number = 3; + p4: number = 4; + } + + class D extends B{ + declare p1: number + + override declare p2: number; + + readonly override p3: number; + + override readonly p4: number; + + override static sp: number; + + override override oop: number; + ~~~~~~~~ +!!! error TS1030: 'override' modifier already seen. + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. + + public override pp: number; + ~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. + override public op: number; + ~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. + + override constructor () { + super(); + } + } + + + abstract class AB { + abstract f (): void; + abstract b (): void; + } + + abstract class AD extends AB { + override abstract f(): void; + abstract override b(): void; + } + + abstract class AND { + override abstract f(): void; + ~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. + abstract override b(): void; + ~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'AND' does not extend another class. + } + + class ADD extends AD { + override f(): void { + + } + override b(): void { + + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/override7.js b/tests/baselines/reference/override7.js new file mode 100644 index 0000000000000..36108f2359ed8 --- /dev/null +++ b/tests/baselines/reference/override7.js @@ -0,0 +1,151 @@ +//// [override7.ts] +class B { + p1: number = 1; + p2: number = 2; + p3: number = 3; + p4: number = 4; +} + +class D extends B{ + declare p1: number + + override declare p2: number; + + readonly override p3: number; + + override readonly p4: number; + + override static sp: number; + + override override oop: number; + + public override pp: number; + override public op: number; + + override constructor () { + super(); + } +} + + +abstract class AB { + abstract f (): void; + abstract b (): void; +} + +abstract class AD extends AB { + override abstract f(): void; + abstract override b(): void; +} + +abstract class AND { + override abstract f(): void; + abstract override b(): void; +} + +class ADD extends AD { + override f(): void { + + } + override b(): void { + + } +} + + +//// [override7.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B() { + this.p1 = 1; + this.p2 = 2; + this.p3 = 3; + this.p4 = 4; + } + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super.call(this) || this; + } + return D; +}(B)); +var AB = /** @class */ (function () { + function AB() { + } + return AB; +}()); +var AD = /** @class */ (function (_super) { + __extends(AD, _super); + function AD() { + return _super !== null && _super.apply(this, arguments) || this; + } + return AD; +}(AB)); +var AND = /** @class */ (function () { + function AND() { + } + return AND; +}()); +var ADD = /** @class */ (function (_super) { + __extends(ADD, _super); + function ADD() { + return _super !== null && _super.apply(this, arguments) || this; + } + ADD.prototype.f = function () { + }; + ADD.prototype.b = function () { + }; + return ADD; +}(AD)); + + +//// [override7.d.ts] +declare class B { + p1: number; + p2: number; + p3: number; + p4: number; +} +declare class D extends B { + p1: number; + p2: number; + readonly p3: number; + readonly p4: number; + static sp: number; + oop: number; + pp: number; + op: number; + constructor(); +} +declare abstract class AB { + abstract f(): void; + abstract b(): void; +} +declare abstract class AD extends AB { + abstract f(): void; + abstract b(): void; +} +declare abstract class AND { + abstract f(): void; + abstract b(): void; +} +declare class ADD extends AD { + f(): void; + b(): void; +} diff --git a/tests/baselines/reference/override7.symbols b/tests/baselines/reference/override7.symbols new file mode 100644 index 0000000000000..4a0a173424462 --- /dev/null +++ b/tests/baselines/reference/override7.symbols @@ -0,0 +1,97 @@ +=== tests/cases/conformance/override/override7.ts === +class B { +>B : Symbol(B, Decl(override7.ts, 0, 0)) + + p1: number = 1; +>p1 : Symbol(B.p1, Decl(override7.ts, 0, 9)) + + p2: number = 2; +>p2 : Symbol(B.p2, Decl(override7.ts, 1, 19)) + + p3: number = 3; +>p3 : Symbol(B.p3, Decl(override7.ts, 2, 19)) + + p4: number = 4; +>p4 : Symbol(B.p4, Decl(override7.ts, 3, 19)) +} + +class D extends B{ +>D : Symbol(D, Decl(override7.ts, 5, 1)) +>B : Symbol(B, Decl(override7.ts, 0, 0)) + + declare p1: number +>p1 : Symbol(D.p1, Decl(override7.ts, 7, 18)) + + override declare p2: number; +>p2 : Symbol(D.p2, Decl(override7.ts, 8, 22)) + + readonly override p3: number; +>p3 : Symbol(D.p3, Decl(override7.ts, 10, 32)) + + override readonly p4: number; +>p4 : Symbol(D.p4, Decl(override7.ts, 12, 33)) + + override static sp: number; +>sp : Symbol(D.sp, Decl(override7.ts, 14, 33)) + + override override oop: number; +>oop : Symbol(D.oop, Decl(override7.ts, 16, 31)) + + public override pp: number; +>pp : Symbol(D.pp, Decl(override7.ts, 18, 34)) + + override public op: number; +>op : Symbol(D.op, Decl(override7.ts, 20, 31)) + + override constructor () { + super(); +>super : Symbol(B, Decl(override7.ts, 0, 0)) + } +} + + +abstract class AB { +>AB : Symbol(AB, Decl(override7.ts, 26, 1)) + + abstract f (): void; +>f : Symbol(AB.f, Decl(override7.ts, 29, 19)) + + abstract b (): void; +>b : Symbol(AB.b, Decl(override7.ts, 30, 24)) +} + +abstract class AD extends AB { +>AD : Symbol(AD, Decl(override7.ts, 32, 1)) +>AB : Symbol(AB, Decl(override7.ts, 26, 1)) + + override abstract f(): void; +>f : Symbol(AD.f, Decl(override7.ts, 34, 30)) + + abstract override b(): void; +>b : Symbol(AD.b, Decl(override7.ts, 35, 32)) +} + +abstract class AND { +>AND : Symbol(AND, Decl(override7.ts, 37, 1)) + + override abstract f(): void; +>f : Symbol(AND.f, Decl(override7.ts, 39, 20)) + + abstract override b(): void; +>b : Symbol(AND.b, Decl(override7.ts, 40, 32)) +} + +class ADD extends AD { +>ADD : Symbol(ADD, Decl(override7.ts, 42, 1)) +>AD : Symbol(AD, Decl(override7.ts, 32, 1)) + + override f(): void { +>f : Symbol(ADD.f, Decl(override7.ts, 44, 22)) + + } + override b(): void { +>b : Symbol(ADD.b, Decl(override7.ts, 47, 5)) + + } +} + diff --git a/tests/baselines/reference/override7.types b/tests/baselines/reference/override7.types new file mode 100644 index 0000000000000..537b63572d7b0 --- /dev/null +++ b/tests/baselines/reference/override7.types @@ -0,0 +1,102 @@ +=== tests/cases/conformance/override/override7.ts === +class B { +>B : B + + p1: number = 1; +>p1 : number +>1 : 1 + + p2: number = 2; +>p2 : number +>2 : 2 + + p3: number = 3; +>p3 : number +>3 : 3 + + p4: number = 4; +>p4 : number +>4 : 4 +} + +class D extends B{ +>D : D +>B : B + + declare p1: number +>p1 : number + + override declare p2: number; +>p2 : number + + readonly override p3: number; +>p3 : number + + override readonly p4: number; +>p4 : number + + override static sp: number; +>sp : number + + override override oop: number; +>oop : number + + public override pp: number; +>pp : number + + override public op: number; +>op : number + + override constructor () { + super(); +>super() : void +>super : typeof B + } +} + + +abstract class AB { +>AB : AB + + abstract f (): void; +>f : () => void + + abstract b (): void; +>b : () => void +} + +abstract class AD extends AB { +>AD : AD +>AB : AB + + override abstract f(): void; +>f : () => void + + abstract override b(): void; +>b : () => void +} + +abstract class AND { +>AND : AND + + override abstract f(): void; +>f : () => void + + abstract override b(): void; +>b : () => void +} + +class ADD extends AD { +>ADD : ADD +>AD : AD + + override f(): void { +>f : () => void + + } + override b(): void { +>b : () => void + + } +} + diff --git a/tests/baselines/reference/override8.errors.txt b/tests/baselines/reference/override8.errors.txt new file mode 100644 index 0000000000000..f1b2fa8654b5f --- /dev/null +++ b/tests/baselines/reference/override8.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/override/override8.ts(6,17): error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'B'. +tests/cases/conformance/override/override8.ts(18,17): error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'BB'. +tests/cases/conformance/override/override8.ts(24,12): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'BB'. + + +==== tests/cases/conformance/override/override8.ts (3 errors) ==== + class B { + a: string + } + + class D extends B { + constructor(public a: string, public b: string) { + ~~~~~~~~~~~~~~~~ +!!! error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'B'. + super(); + } + } + + class BB { + constructor(public a: string) { + + } + } + + class DD extends BB { + constructor(public a: string) { + ~~~~~~~~~~~~~~~~ +!!! error TS4115: This parameter property must be rewritten as a property declaration with an 'override' modifier because it overrides a member in base class 'BB'. + super(a) + } + } + + class DDD extends BB { + public a: string; + ~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'BB'. + + constructor(a: string) { + super(a) + this.a = a + } + } \ No newline at end of file diff --git a/tests/baselines/reference/override8.js b/tests/baselines/reference/override8.js new file mode 100644 index 0000000000000..fb92faec3b806 --- /dev/null +++ b/tests/baselines/reference/override8.js @@ -0,0 +1,110 @@ +//// [override8.ts] +class B { + a: string +} + +class D extends B { + constructor(public a: string, public b: string) { + super(); + } +} + +class BB { + constructor(public a: string) { + + } +} + +class DD extends BB { + constructor(public a: string) { + super(a) + } +} + +class DDD extends BB { + public a: string; + + constructor(a: string) { + super(a) + this.a = a + } +} + +//// [override8.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var B = /** @class */ (function () { + function B() { + } + return B; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D(a, b) { + var _this = _super.call(this) || this; + _this.a = a; + _this.b = b; + return _this; + } + return D; +}(B)); +var BB = /** @class */ (function () { + function BB(a) { + this.a = a; + } + return BB; +}()); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD(a) { + var _this = _super.call(this, a) || this; + _this.a = a; + return _this; + } + return DD; +}(BB)); +var DDD = /** @class */ (function (_super) { + __extends(DDD, _super); + function DDD(a) { + var _this = _super.call(this, a) || this; + _this.a = a; + return _this; + } + return DDD; +}(BB)); + + +//// [override8.d.ts] +declare class B { + a: string; +} +declare class D extends B { + a: string; + b: string; + constructor(a: string, b: string); +} +declare class BB { + a: string; + constructor(a: string); +} +declare class DD extends BB { + a: string; + constructor(a: string); +} +declare class DDD extends BB { + a: string; + constructor(a: string); +} diff --git a/tests/baselines/reference/override8.symbols b/tests/baselines/reference/override8.symbols new file mode 100644 index 0000000000000..244a02871e2dc --- /dev/null +++ b/tests/baselines/reference/override8.symbols @@ -0,0 +1,64 @@ +=== tests/cases/conformance/override/override8.ts === +class B { +>B : Symbol(B, Decl(override8.ts, 0, 0)) + + a: string +>a : Symbol(B.a, Decl(override8.ts, 0, 9)) +} + +class D extends B { +>D : Symbol(D, Decl(override8.ts, 2, 1)) +>B : Symbol(B, Decl(override8.ts, 0, 0)) + + constructor(public a: string, public b: string) { +>a : Symbol(D.a, Decl(override8.ts, 5, 16)) +>b : Symbol(D.b, Decl(override8.ts, 5, 33)) + + super(); +>super : Symbol(B, Decl(override8.ts, 0, 0)) + } +} + +class BB { +>BB : Symbol(BB, Decl(override8.ts, 8, 1)) + + constructor(public a: string) { +>a : Symbol(BB.a, Decl(override8.ts, 11, 16)) + + } +} + +class DD extends BB { +>DD : Symbol(DD, Decl(override8.ts, 14, 1)) +>BB : Symbol(BB, Decl(override8.ts, 8, 1)) + + constructor(public a: string) { +>a : Symbol(DD.a, Decl(override8.ts, 17, 16)) + + super(a) +>super : Symbol(BB, Decl(override8.ts, 8, 1)) +>a : Symbol(a, Decl(override8.ts, 17, 16)) + } +} + +class DDD extends BB { +>DDD : Symbol(DDD, Decl(override8.ts, 20, 1)) +>BB : Symbol(BB, Decl(override8.ts, 8, 1)) + + public a: string; +>a : Symbol(DDD.a, Decl(override8.ts, 22, 22)) + + constructor(a: string) { +>a : Symbol(a, Decl(override8.ts, 25, 16)) + + super(a) +>super : Symbol(BB, Decl(override8.ts, 8, 1)) +>a : Symbol(a, Decl(override8.ts, 25, 16)) + + this.a = a +>this.a : Symbol(DDD.a, Decl(override8.ts, 22, 22)) +>this : Symbol(DDD, Decl(override8.ts, 20, 1)) +>a : Symbol(DDD.a, Decl(override8.ts, 22, 22)) +>a : Symbol(a, Decl(override8.ts, 25, 16)) + } +} diff --git a/tests/baselines/reference/override8.types b/tests/baselines/reference/override8.types new file mode 100644 index 0000000000000..564ab8fbd76fb --- /dev/null +++ b/tests/baselines/reference/override8.types @@ -0,0 +1,68 @@ +=== tests/cases/conformance/override/override8.ts === +class B { +>B : B + + a: string +>a : string +} + +class D extends B { +>D : D +>B : B + + constructor(public a: string, public b: string) { +>a : string +>b : string + + super(); +>super() : void +>super : typeof B + } +} + +class BB { +>BB : BB + + constructor(public a: string) { +>a : string + + } +} + +class DD extends BB { +>DD : DD +>BB : BB + + constructor(public a: string) { +>a : string + + super(a) +>super(a) : void +>super : typeof BB +>a : string + } +} + +class DDD extends BB { +>DDD : DDD +>BB : BB + + public a: string; +>a : string + + constructor(a: string) { +>a : string + + super(a) +>super(a) : void +>super : typeof BB +>a : string + + this.a = a +>this.a = a : string +>this.a : string +>this : this +>a : string +>a : string + } +} diff --git a/tests/baselines/reference/override9.errors.txt b/tests/baselines/reference/override9.errors.txt new file mode 100644 index 0000000000000..a1637ec567985 --- /dev/null +++ b/tests/baselines/reference/override9.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/override/override9.ts(8,5): error TS1070: 'override' modifier cannot appear on a type member. +tests/cases/conformance/override/override9.ts(10,5): error TS1070: 'override' modifier cannot appear on a type member. + + +==== tests/cases/conformance/override/override9.ts (2 errors) ==== + interface B { + foo (): void + bar (): void + } + + interface D extends B { + foo (): void; + override bar(): void; + ~~~~~~~~ +!!! error TS1070: 'override' modifier cannot appear on a type member. + baz(): void; + override bazz(): void; + ~~~~~~~~ +!!! error TS1070: 'override' modifier cannot appear on a type member. + } + \ No newline at end of file diff --git a/tests/baselines/reference/override9.js b/tests/baselines/reference/override9.js new file mode 100644 index 0000000000000..254125d798ebf --- /dev/null +++ b/tests/baselines/reference/override9.js @@ -0,0 +1,28 @@ +//// [override9.ts] +interface B { + foo (): void + bar (): void +} + +interface D extends B { + foo (): void; + override bar(): void; + baz(): void; + override bazz(): void; +} + + +//// [override9.js] + + +//// [override9.d.ts] +interface B { + foo(): void; + bar(): void; +} +interface D extends B { + foo(): void; + bar(): void; + baz(): void; + bazz(): void; +} diff --git a/tests/baselines/reference/override9.symbols b/tests/baselines/reference/override9.symbols new file mode 100644 index 0000000000000..e13c60a9e3801 --- /dev/null +++ b/tests/baselines/reference/override9.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/override/override9.ts === +interface B { +>B : Symbol(B, Decl(override9.ts, 0, 0)) + + foo (): void +>foo : Symbol(B.foo, Decl(override9.ts, 0, 13)) + + bar (): void +>bar : Symbol(B.bar, Decl(override9.ts, 1, 16)) +} + +interface D extends B { +>D : Symbol(D, Decl(override9.ts, 3, 1)) +>B : Symbol(B, Decl(override9.ts, 0, 0)) + + foo (): void; +>foo : Symbol(D.foo, Decl(override9.ts, 5, 23)) + + override bar(): void; +>bar : Symbol(D.bar, Decl(override9.ts, 6, 17)) + + baz(): void; +>baz : Symbol(D.baz, Decl(override9.ts, 7, 25)) + + override bazz(): void; +>bazz : Symbol(D.bazz, Decl(override9.ts, 8, 16)) +} + diff --git a/tests/baselines/reference/override9.types b/tests/baselines/reference/override9.types new file mode 100644 index 0000000000000..a7af4f6332a98 --- /dev/null +++ b/tests/baselines/reference/override9.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/override/override9.ts === +interface B { + foo (): void +>foo : () => void + + bar (): void +>bar : () => void +} + +interface D extends B { + foo (): void; +>foo : () => void + + override bar(): void; +>bar : () => void + + baz(): void; +>baz : () => void + + override bazz(): void; +>bazz : () => void +} + diff --git a/tests/baselines/reference/overrideWithoutNoImplicitOverride1.errors.txt b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.errors.txt new file mode 100644 index 0000000000000..f548562202519 --- /dev/null +++ b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts(2,14): error TS4112: This member cannot have an 'override' modifier because its containing class 'AmbientClass' does not extend another class. +tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts(6,14): error TS4112: This member cannot have an 'override' modifier because its containing class 'NonAmbientClass' does not extend another class. +tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts(18,14): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'AmbientBase'. +tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts(31,18): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'AmbientBase'. +tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts(44,14): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'NonAmbientBase'. + + +==== tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts (5 errors) ==== + export declare class AmbientClass { + override yadda(): void; + ~~~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'AmbientClass' does not extend another class. + } + + export class NonAmbientClass { + override yadda(): void {} + ~~~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'NonAmbientClass' does not extend another class. + } + + ///// + + export declare class AmbientBase { + foo(): void; + } + + export declare class AmbientDerived extends AmbientBase { + foo(): void; + + override bar(): void; + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'AmbientBase'. + } + + ///// + + declare namespace ambientNamespace { + export class AmbientBase { + foo(): void; + } + + export class AmbientDerived extends AmbientBase { + foo(): void; + + override bar(): void; + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'AmbientBase'. + } + } + + ///// + + export class NonAmbientBase { + foo(): void {} + } + + export class NonAmbientDerived extends NonAmbientBase { + foo(): void {} + + override bar(): void {} + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'NonAmbientBase'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/overrideWithoutNoImplicitOverride1.js b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.js new file mode 100644 index 0000000000000..e32cb4fb4897a --- /dev/null +++ b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.js @@ -0,0 +1,92 @@ +//// [overrideWithoutNoImplicitOverride1.ts] +export declare class AmbientClass { + override yadda(): void; +} + +export class NonAmbientClass { + override yadda(): void {} +} + +///// + +export declare class AmbientBase { + foo(): void; +} + +export declare class AmbientDerived extends AmbientBase { + foo(): void; + + override bar(): void; +} + +///// + +declare namespace ambientNamespace { + export class AmbientBase { + foo(): void; + } + + export class AmbientDerived extends AmbientBase { + foo(): void; + + override bar(): void; + } +} + +///// + +export class NonAmbientBase { + foo(): void {} +} + +export class NonAmbientDerived extends NonAmbientBase { + foo(): void {} + + override bar(): void {} +} + + +//// [overrideWithoutNoImplicitOverride1.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +exports.NonAmbientDerived = exports.NonAmbientBase = exports.NonAmbientClass = void 0; +var NonAmbientClass = /** @class */ (function () { + function NonAmbientClass() { + } + NonAmbientClass.prototype.yadda = function () { }; + return NonAmbientClass; +}()); +exports.NonAmbientClass = NonAmbientClass; +///// +var NonAmbientBase = /** @class */ (function () { + function NonAmbientBase() { + } + NonAmbientBase.prototype.foo = function () { }; + return NonAmbientBase; +}()); +exports.NonAmbientBase = NonAmbientBase; +var NonAmbientDerived = /** @class */ (function (_super) { + __extends(NonAmbientDerived, _super); + function NonAmbientDerived() { + return _super !== null && _super.apply(this, arguments) || this; + } + NonAmbientDerived.prototype.foo = function () { }; + NonAmbientDerived.prototype.bar = function () { }; + return NonAmbientDerived; +}(NonAmbientBase)); +exports.NonAmbientDerived = NonAmbientDerived; diff --git a/tests/baselines/reference/overrideWithoutNoImplicitOverride1.symbols b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.symbols new file mode 100644 index 0000000000000..f4db5c5b1c1d1 --- /dev/null +++ b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.symbols @@ -0,0 +1,79 @@ +=== tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts === +export declare class AmbientClass { +>AmbientClass : Symbol(AmbientClass, Decl(overrideWithoutNoImplicitOverride1.ts, 0, 0)) + + override yadda(): void; +>yadda : Symbol(AmbientClass.yadda, Decl(overrideWithoutNoImplicitOverride1.ts, 0, 35)) +} + +export class NonAmbientClass { +>NonAmbientClass : Symbol(NonAmbientClass, Decl(overrideWithoutNoImplicitOverride1.ts, 2, 1)) + + override yadda(): void {} +>yadda : Symbol(NonAmbientClass.yadda, Decl(overrideWithoutNoImplicitOverride1.ts, 4, 30)) +} + +///// + +export declare class AmbientBase { +>AmbientBase : Symbol(AmbientBase, Decl(overrideWithoutNoImplicitOverride1.ts, 6, 1)) + + foo(): void; +>foo : Symbol(AmbientBase.foo, Decl(overrideWithoutNoImplicitOverride1.ts, 10, 34)) +} + +export declare class AmbientDerived extends AmbientBase { +>AmbientDerived : Symbol(AmbientDerived, Decl(overrideWithoutNoImplicitOverride1.ts, 12, 1)) +>AmbientBase : Symbol(AmbientBase, Decl(overrideWithoutNoImplicitOverride1.ts, 6, 1)) + + foo(): void; +>foo : Symbol(AmbientDerived.foo, Decl(overrideWithoutNoImplicitOverride1.ts, 14, 57)) + + override bar(): void; +>bar : Symbol(AmbientDerived.bar, Decl(overrideWithoutNoImplicitOverride1.ts, 15, 16)) +} + +///// + +declare namespace ambientNamespace { +>ambientNamespace : Symbol(ambientNamespace, Decl(overrideWithoutNoImplicitOverride1.ts, 18, 1)) + + export class AmbientBase { +>AmbientBase : Symbol(AmbientBase, Decl(overrideWithoutNoImplicitOverride1.ts, 22, 36)) + + foo(): void; +>foo : Symbol(AmbientBase.foo, Decl(overrideWithoutNoImplicitOverride1.ts, 23, 30)) + } + + export class AmbientDerived extends AmbientBase { +>AmbientDerived : Symbol(AmbientDerived, Decl(overrideWithoutNoImplicitOverride1.ts, 25, 5)) +>AmbientBase : Symbol(AmbientBase, Decl(overrideWithoutNoImplicitOverride1.ts, 22, 36)) + + foo(): void; +>foo : Symbol(AmbientDerived.foo, Decl(overrideWithoutNoImplicitOverride1.ts, 27, 53)) + + override bar(): void; +>bar : Symbol(AmbientDerived.bar, Decl(overrideWithoutNoImplicitOverride1.ts, 28, 20)) + } +} + +///// + +export class NonAmbientBase { +>NonAmbientBase : Symbol(NonAmbientBase, Decl(overrideWithoutNoImplicitOverride1.ts, 32, 1)) + + foo(): void {} +>foo : Symbol(NonAmbientBase.foo, Decl(overrideWithoutNoImplicitOverride1.ts, 36, 29)) +} + +export class NonAmbientDerived extends NonAmbientBase { +>NonAmbientDerived : Symbol(NonAmbientDerived, Decl(overrideWithoutNoImplicitOverride1.ts, 38, 1)) +>NonAmbientBase : Symbol(NonAmbientBase, Decl(overrideWithoutNoImplicitOverride1.ts, 32, 1)) + + foo(): void {} +>foo : Symbol(NonAmbientDerived.foo, Decl(overrideWithoutNoImplicitOverride1.ts, 40, 55)) + + override bar(): void {} +>bar : Symbol(NonAmbientDerived.bar, Decl(overrideWithoutNoImplicitOverride1.ts, 41, 18)) +} + diff --git a/tests/baselines/reference/overrideWithoutNoImplicitOverride1.types b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.types new file mode 100644 index 0000000000000..4451b77855192 --- /dev/null +++ b/tests/baselines/reference/overrideWithoutNoImplicitOverride1.types @@ -0,0 +1,79 @@ +=== tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts === +export declare class AmbientClass { +>AmbientClass : AmbientClass + + override yadda(): void; +>yadda : () => void +} + +export class NonAmbientClass { +>NonAmbientClass : NonAmbientClass + + override yadda(): void {} +>yadda : () => void +} + +///// + +export declare class AmbientBase { +>AmbientBase : AmbientBase + + foo(): void; +>foo : () => void +} + +export declare class AmbientDerived extends AmbientBase { +>AmbientDerived : AmbientDerived +>AmbientBase : AmbientBase + + foo(): void; +>foo : () => void + + override bar(): void; +>bar : () => void +} + +///// + +declare namespace ambientNamespace { +>ambientNamespace : typeof ambientNamespace + + export class AmbientBase { +>AmbientBase : AmbientBase + + foo(): void; +>foo : () => void + } + + export class AmbientDerived extends AmbientBase { +>AmbientDerived : AmbientDerived +>AmbientBase : AmbientBase + + foo(): void; +>foo : () => void + + override bar(): void; +>bar : () => void + } +} + +///// + +export class NonAmbientBase { +>NonAmbientBase : NonAmbientBase + + foo(): void {} +>foo : () => void +} + +export class NonAmbientDerived extends NonAmbientBase { +>NonAmbientDerived : NonAmbientDerived +>NonAmbientBase : NonAmbientBase + + foo(): void {} +>foo : () => void + + override bar(): void {} +>bar : () => void +} + diff --git a/tests/baselines/reference/override_js1.symbols b/tests/baselines/reference/override_js1.symbols new file mode 100644 index 0000000000000..a2110ac8fcdd8 --- /dev/null +++ b/tests/baselines/reference/override_js1.symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/override/a.js === +class B { +>B : Symbol(B, Decl(a.js, 0, 0)) + + foo (v) {} +>foo : Symbol(B.foo, Decl(a.js, 0, 9)) +>v : Symbol(v, Decl(a.js, 1, 9)) + + fooo (v) {} +>fooo : Symbol(B.fooo, Decl(a.js, 1, 14)) +>v : Symbol(v, Decl(a.js, 2, 10)) +} + +class D extends B { +>D : Symbol(D, Decl(a.js, 3, 1)) +>B : Symbol(B, Decl(a.js, 0, 0)) + + foo (v) {} +>foo : Symbol(D.foo, Decl(a.js, 5, 19)) +>v : Symbol(v, Decl(a.js, 6, 9)) + + /** @override */ + fooo (v) {} +>fooo : Symbol(D.fooo, Decl(a.js, 6, 14)) +>v : Symbol(v, Decl(a.js, 8, 10)) + + /** @override */ + bar(v) {} +>bar : Symbol(D.bar, Decl(a.js, 8, 15)) +>v : Symbol(v, Decl(a.js, 10, 8)) +} + +class C { +>C : Symbol(C, Decl(a.js, 11, 1)) + + foo () {} +>foo : Symbol(C.foo, Decl(a.js, 13, 9)) + + /** @override */ + fooo (v) {} +>fooo : Symbol(C.fooo, Decl(a.js, 14, 13)) +>v : Symbol(v, Decl(a.js, 16, 10)) + + /** @override */ + bar(v) {} +>bar : Symbol(C.bar, Decl(a.js, 16, 15)) +>v : Symbol(v, Decl(a.js, 18, 8)) +} diff --git a/tests/baselines/reference/override_js1.types b/tests/baselines/reference/override_js1.types new file mode 100644 index 0000000000000..51c7de2e81014 --- /dev/null +++ b/tests/baselines/reference/override_js1.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/override/a.js === +class B { +>B : B + + foo (v) {} +>foo : (v: any) => void +>v : any + + fooo (v) {} +>fooo : (v: any) => void +>v : any +} + +class D extends B { +>D : D +>B : B + + foo (v) {} +>foo : (v: any) => void +>v : any + + /** @override */ + fooo (v) {} +>fooo : (v: any) => void +>v : any + + /** @override */ + bar(v) {} +>bar : (v: any) => void +>v : any +} + +class C { +>C : C + + foo () {} +>foo : () => void + + /** @override */ + fooo (v) {} +>fooo : (v: any) => void +>v : any + + /** @override */ + bar(v) {} +>bar : (v: any) => void +>v : any +} diff --git a/tests/baselines/reference/override_js2.errors.txt b/tests/baselines/reference/override_js2.errors.txt new file mode 100644 index 0000000000000..54254dbdc762f --- /dev/null +++ b/tests/baselines/reference/override_js2.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/override/a.js(7,5): error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. +tests/cases/conformance/override/a.js(11,5): error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. +tests/cases/conformance/override/a.js(17,5): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. +tests/cases/conformance/override/a.js(19,5): error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. + + +==== tests/cases/conformance/override/a.js (4 errors) ==== + class B { + foo (v) {} + fooo (v) {} + } + + class D extends B { + foo (v) {} + ~~~ +!!! error TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'B'. + /** @override */ + fooo (v) {} + /** @override */ + bar(v) {} + ~~~ +!!! error TS4113: This member cannot have an 'override' modifier because it is not declared in the base class 'B'. + } + + class C { + foo () {} + /** @override */ + fooo (v) {} + ~~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. + /** @override */ + bar(v) {} + ~~~ +!!! error TS4112: This member cannot have an 'override' modifier because its containing class 'C' does not extend another class. + } \ No newline at end of file diff --git a/tests/baselines/reference/override_js2.symbols b/tests/baselines/reference/override_js2.symbols new file mode 100644 index 0000000000000..a2110ac8fcdd8 --- /dev/null +++ b/tests/baselines/reference/override_js2.symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/override/a.js === +class B { +>B : Symbol(B, Decl(a.js, 0, 0)) + + foo (v) {} +>foo : Symbol(B.foo, Decl(a.js, 0, 9)) +>v : Symbol(v, Decl(a.js, 1, 9)) + + fooo (v) {} +>fooo : Symbol(B.fooo, Decl(a.js, 1, 14)) +>v : Symbol(v, Decl(a.js, 2, 10)) +} + +class D extends B { +>D : Symbol(D, Decl(a.js, 3, 1)) +>B : Symbol(B, Decl(a.js, 0, 0)) + + foo (v) {} +>foo : Symbol(D.foo, Decl(a.js, 5, 19)) +>v : Symbol(v, Decl(a.js, 6, 9)) + + /** @override */ + fooo (v) {} +>fooo : Symbol(D.fooo, Decl(a.js, 6, 14)) +>v : Symbol(v, Decl(a.js, 8, 10)) + + /** @override */ + bar(v) {} +>bar : Symbol(D.bar, Decl(a.js, 8, 15)) +>v : Symbol(v, Decl(a.js, 10, 8)) +} + +class C { +>C : Symbol(C, Decl(a.js, 11, 1)) + + foo () {} +>foo : Symbol(C.foo, Decl(a.js, 13, 9)) + + /** @override */ + fooo (v) {} +>fooo : Symbol(C.fooo, Decl(a.js, 14, 13)) +>v : Symbol(v, Decl(a.js, 16, 10)) + + /** @override */ + bar(v) {} +>bar : Symbol(C.bar, Decl(a.js, 16, 15)) +>v : Symbol(v, Decl(a.js, 18, 8)) +} diff --git a/tests/baselines/reference/override_js2.types b/tests/baselines/reference/override_js2.types new file mode 100644 index 0000000000000..51c7de2e81014 --- /dev/null +++ b/tests/baselines/reference/override_js2.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/override/a.js === +class B { +>B : B + + foo (v) {} +>foo : (v: any) => void +>v : any + + fooo (v) {} +>fooo : (v: any) => void +>v : any +} + +class D extends B { +>D : D +>B : B + + foo (v) {} +>foo : (v: any) => void +>v : any + + /** @override */ + fooo (v) {} +>fooo : (v: any) => void +>v : any + + /** @override */ + bar(v) {} +>bar : (v: any) => void +>v : any +} + +class C { +>C : C + + foo () {} +>foo : () => void + + /** @override */ + fooo (v) {} +>fooo : (v: any) => void +>v : any + + /** @override */ + bar(v) {} +>bar : (v: any) => void +>v : any +} diff --git a/tests/baselines/reference/override_js3.errors.txt b/tests/baselines/reference/override_js3.errors.txt new file mode 100644 index 0000000000000..02bdbe3a3e80e --- /dev/null +++ b/tests/baselines/reference/override_js3.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/override/a.js(7,5): error TS8009: The 'override' modifier can only be used in TypeScript files. + + +==== tests/cases/conformance/override/a.js (1 errors) ==== + class B { + foo (v) {} + fooo (v) {} + } + + class D extends B { + override foo (v) {} + ~~~~~~~~ +!!! error TS8009: The 'override' modifier can only be used in TypeScript files. + /** @override */ + fooo (v) {} + } + \ No newline at end of file diff --git a/tests/baselines/reference/override_js3.symbols b/tests/baselines/reference/override_js3.symbols new file mode 100644 index 0000000000000..c0f89948a14ea --- /dev/null +++ b/tests/baselines/reference/override_js3.symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/override/a.js === +class B { +>B : Symbol(B, Decl(a.js, 0, 0)) + + foo (v) {} +>foo : Symbol(B.foo, Decl(a.js, 0, 9)) +>v : Symbol(v, Decl(a.js, 1, 9)) + + fooo (v) {} +>fooo : Symbol(B.fooo, Decl(a.js, 1, 14)) +>v : Symbol(v, Decl(a.js, 2, 10)) +} + +class D extends B { +>D : Symbol(D, Decl(a.js, 3, 1)) +>B : Symbol(B, Decl(a.js, 0, 0)) + + override foo (v) {} +>foo : Symbol(D.foo, Decl(a.js, 5, 19)) +>v : Symbol(v, Decl(a.js, 6, 18)) + + /** @override */ + fooo (v) {} +>fooo : Symbol(D.fooo, Decl(a.js, 6, 23)) +>v : Symbol(v, Decl(a.js, 8, 10)) +} + diff --git a/tests/baselines/reference/override_js3.types b/tests/baselines/reference/override_js3.types new file mode 100644 index 0000000000000..40cdf389c6e37 --- /dev/null +++ b/tests/baselines/reference/override_js3.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/override/a.js === +class B { +>B : B + + foo (v) {} +>foo : (v: any) => void +>v : any + + fooo (v) {} +>fooo : (v: any) => void +>v : any +} + +class D extends B { +>D : D +>B : B + + override foo (v) {} +>foo : (v: any) => void +>v : any + + /** @override */ + fooo (v) {} +>fooo : (v: any) => void +>v : any +} + diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/noImplicitOverride/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/noImplicitOverride/tsconfig.json new file mode 100644 index 0000000000000..291a476f1ffb2 --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/noImplicitOverride/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "noImplicitOverride": true + } +} diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/pedanticOverride/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/pedanticOverride/tsconfig.json new file mode 100644 index 0000000000000..776ea7cf4457a --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/pedanticOverride/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "pedanticOverride": true + } +} diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index add44c4a37748..194d0d139323d 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json index 8f6dfb272db94..6cd483e76a9f0 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 5f20390286c24..d10611ebdae17 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index f88c76a526ca8..485a029ae8329 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index 449723ad6367f..66028174a9ea6 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index f7039bfbca288..d926a958770fe 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index add44c4a37748..194d0d139323d 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index d6c803e36c930..9c4a96d98d35c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 48811f1681bb0..dd5852675808c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -40,6 +40,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js index fa56b5062e6e3..16b925d5936d4 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js @@ -61,6 +61,7 @@ interface Array { length: number; [n: number]: T; } // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js index 0585c1897c8cd..7ce20f4eb951f 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js @@ -61,6 +61,7 @@ interface Array { length: number; [n: number]: T; } // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js index bcaad992e4d0b..f35e860335bb8 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js @@ -61,6 +61,7 @@ interface Array { length: number; [n: number]: T; } // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js index d55d9057910a0..8f6c7e53cc61b 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js @@ -61,6 +61,7 @@ interface Array { length: number; [n: number]: T; } // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js index a1f3ef05d3f72..0bc0a489d1891 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js @@ -61,6 +61,7 @@ interface Array { length: number; [n: number]: T; } // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js index 051cd4e2ed9db..79c6b55b1f1e0 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js @@ -61,6 +61,7 @@ interface Array { length: number; [n: number]: T; } // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an 'override' modifier. */ // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ /* Module Resolution Options */ diff --git a/tests/cases/conformance/jsdoc/jsdocOverrideTag1.ts b/tests/cases/conformance/jsdoc/jsdocOverrideTag1.ts new file mode 100644 index 0000000000000..92256baf702fe --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocOverrideTag1.ts @@ -0,0 +1,49 @@ +// @allowJS: true +// @checkJS: true +// @noEmit: true +// @noImplicitOverride: true +// @Filename: 0.js + +class A { + + /** + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { + return typeof a === 'string' + } + bar () { + + } +} + +class B extends A { + /** + * @override + * @method + * @param {string | number} a + * @returns {boolean} + */ + foo (a) { + return super.foo(a) + } + + bar () { + + } + + /** @override */ + baz () { + + } +} + + +class C { + /** @override */ + foo () { + + } +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override1.ts b/tests/cases/conformance/override/override1.ts new file mode 100644 index 0000000000000..d83232dab6095 --- /dev/null +++ b/tests/cases/conformance/override/override1.ts @@ -0,0 +1,46 @@ +// @declaration: true +// @noImplicitOverride: true +class B { + foo (v: string) {} + fooo (v: string) {} +} + +class D extends B { + override foo (v: string) {} + + fooo (v: string) {} + + override bar(v: string) {} +} + +class C { + override foo(v: string) {} +} + +function f () { + return class extends B { + override foo (v: string) {} + + fooo (v: string) {} + + override bar(v: string) {} + } +} + +class E extends (class { + foo () { } + bar () { } +}) { + override foo () { } + bar () { } + + baz() {} + + override bazz () {} +} + +function ff () { + return class { + override foo () {} + } +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override10.ts b/tests/cases/conformance/override/override10.ts new file mode 100644 index 0000000000000..98de0c7f1c6eb --- /dev/null +++ b/tests/cases/conformance/override/override10.ts @@ -0,0 +1,13 @@ +// @declaration: true +// @noImplicitOverride: true + +abstract class Base { + abstract foo(): unknown; + abstract bar(): void; +} + +// No errors: +abstract class Sub extends Base { + override abstract foo(): number; + bar() { } +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override11.ts b/tests/cases/conformance/override/override11.ts new file mode 100644 index 0000000000000..c7737a182cfbb --- /dev/null +++ b/tests/cases/conformance/override/override11.ts @@ -0,0 +1,9 @@ +class Base { + foo = 1; +} + +class Sub extends Base { + constructor (override public foo: number) { + super(); + } +} diff --git a/tests/cases/conformance/override/override2.ts b/tests/cases/conformance/override/override2.ts new file mode 100644 index 0000000000000..b04a979001b03 --- /dev/null +++ b/tests/cases/conformance/override/override2.ts @@ -0,0 +1,28 @@ +// @declaration: true +// @noImplicitOverride: true +abstract class AB { + abstract foo(v: string): void; + + abstract bar(v: string): void; + abstract baz(v: string): void; +} + +abstract class AD1 extends AB { + +} + +abstract class AD2 extends AB { + abstract foo(v: ''): void // need override? +} + +abstract class AD3 extends AB { + override foo(v: ''): void { } // need override? + abstract bar(): void; + baz(): void { } +} + +class D4 extends AB { + override foo(v: ''): void {} + override bar(v: ''): void {} + baz(): void { } +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override3.ts b/tests/cases/conformance/override/override3.ts new file mode 100644 index 0000000000000..1930ced3d1198 --- /dev/null +++ b/tests/cases/conformance/override/override3.ts @@ -0,0 +1,26 @@ +// @declaration: true +// @noImplicitOverride: true +declare class B { + foo(): void + bar(): void +} + +declare class D extends B { + foo (): void; + override bar (): void; +} + +class DB extends B { + override foo(): void {} + override bar(): void {} +} + +class DD extends D { + override foo(): void {} + override bar(): void {} +} + +class EB extends D { + foo(): void {} + override bar(): void {} +} diff --git a/tests/cases/conformance/override/override4.ts b/tests/cases/conformance/override/override4.ts new file mode 100644 index 0000000000000..441fdb73552a7 --- /dev/null +++ b/tests/cases/conformance/override/override4.ts @@ -0,0 +1,26 @@ +// @declaration: true +// @noImplicitOverride: true +class B { + p1: number = 1; + p2: number = 1; + p3: () => void; + p4: () => void; + foo (v: string) {} + fooo (v: string) {} +} + +class D extends B { + p1: number = 2; + override p2: number = 3; + p3: () => void; + override p4: () => void; + override foo (v: string) {} + + fooo (v: string) {} + +} + +class DD extends B { + override foo: () => void + fooo: () => void; +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override5.ts b/tests/cases/conformance/override/override5.ts new file mode 100644 index 0000000000000..cd6bd1001c4a6 --- /dev/null +++ b/tests/cases/conformance/override/override5.ts @@ -0,0 +1,57 @@ +// @declaration: true +// @noImplicitOverride: true +class B { + p1: number = 1; + p2: number = 2; + p3: number = 3; + p4: number = 4; + oop: number; + pp: number; + op: number; +} + +class D extends B{ + declare p1: number + + override declare p2: number; + + readonly override p3: number; + + override readonly p4: number; + + override static sp: number; + + override override oop: number; + + public override pp: number; + override public op: number; + + override constructor () { + super(); + } +} + + +abstract class AB { + abstract f (): void; + abstract b (): void; +} + +abstract class AD extends AB { + override abstract f(): void; + abstract override b(): void; +} + +abstract class AND { + override abstract f(): void; + abstract override b(): void; +} + +class ADD extends AD { + f(): void { + + } + override b(): void { + + } +} diff --git a/tests/cases/conformance/override/override6.ts b/tests/cases/conformance/override/override6.ts new file mode 100644 index 0000000000000..df9f34f51a8ff --- /dev/null +++ b/tests/cases/conformance/override/override6.ts @@ -0,0 +1,15 @@ +// @declaration: true +// @noImplicitOverride: true +class B { + public baz: number = 1; + constructor(public foo: string, public bar: number) { + + } +} + +class D extends B { + public bar: number = 1 + constructor(public foo: string, public baz: number) { + super(foo, 42) + } +} diff --git a/tests/cases/conformance/override/override7.ts b/tests/cases/conformance/override/override7.ts new file mode 100644 index 0000000000000..14881e1051a3b --- /dev/null +++ b/tests/cases/conformance/override/override7.ts @@ -0,0 +1,54 @@ +// @declaration: true +// @noImplicitOverride: false +class B { + p1: number = 1; + p2: number = 2; + p3: number = 3; + p4: number = 4; +} + +class D extends B{ + declare p1: number + + override declare p2: number; + + readonly override p3: number; + + override readonly p4: number; + + override static sp: number; + + override override oop: number; + + public override pp: number; + override public op: number; + + override constructor () { + super(); + } +} + + +abstract class AB { + abstract f (): void; + abstract b (): void; +} + +abstract class AD extends AB { + override abstract f(): void; + abstract override b(): void; +} + +abstract class AND { + override abstract f(): void; + abstract override b(): void; +} + +class ADD extends AD { + override f(): void { + + } + override b(): void { + + } +} diff --git a/tests/cases/conformance/override/override8.ts b/tests/cases/conformance/override/override8.ts new file mode 100644 index 0000000000000..0525a39f4215f --- /dev/null +++ b/tests/cases/conformance/override/override8.ts @@ -0,0 +1,32 @@ +// @declaration: true +// @noImplicitOverride: true +class B { + a: string +} + +class D extends B { + constructor(public a: string, public b: string) { + super(); + } +} + +class BB { + constructor(public a: string) { + + } +} + +class DD extends BB { + constructor(public a: string) { + super(a) + } +} + +class DDD extends BB { + public a: string; + + constructor(a: string) { + super(a) + this.a = a + } +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override9.ts b/tests/cases/conformance/override/override9.ts new file mode 100644 index 0000000000000..cac32f455ac29 --- /dev/null +++ b/tests/cases/conformance/override/override9.ts @@ -0,0 +1,13 @@ +// @declaration: true +// @noImplicitOverride: true +interface B { + foo (): void + bar (): void +} + +interface D extends B { + foo (): void; + override bar(): void; + baz(): void; + override bazz(): void; +} diff --git a/tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts b/tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts new file mode 100644 index 0000000000000..c4c24e49c74b5 --- /dev/null +++ b/tests/cases/conformance/override/overrideWithoutNoImplicitOverride1.ts @@ -0,0 +1,47 @@ +// @noImplicitOverride: false + +export declare class AmbientClass { + override yadda(): void; +} + +export class NonAmbientClass { + override yadda(): void {} +} + +///// + +export declare class AmbientBase { + foo(): void; +} + +export declare class AmbientDerived extends AmbientBase { + foo(): void; + + override bar(): void; +} + +///// + +declare namespace ambientNamespace { + export class AmbientBase { + foo(): void; + } + + export class AmbientDerived extends AmbientBase { + foo(): void; + + override bar(): void; + } +} + +///// + +export class NonAmbientBase { + foo(): void {} +} + +export class NonAmbientDerived extends NonAmbientBase { + foo(): void {} + + override bar(): void {} +} diff --git a/tests/cases/conformance/override/override_js1.ts b/tests/cases/conformance/override/override_js1.ts new file mode 100644 index 0000000000000..75df72695e012 --- /dev/null +++ b/tests/cases/conformance/override/override_js1.ts @@ -0,0 +1,25 @@ +// @noImplicitOverride: true +// @allowJs: true +// @noEmit: true +// @Filename: a.js + +class B { + foo (v) {} + fooo (v) {} +} + +class D extends B { + foo (v) {} + /** @override */ + fooo (v) {} + /** @override */ + bar(v) {} +} + +class C { + foo () {} + /** @override */ + fooo (v) {} + /** @override */ + bar(v) {} +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override_js2.ts b/tests/cases/conformance/override/override_js2.ts new file mode 100644 index 0000000000000..2de6b1662712e --- /dev/null +++ b/tests/cases/conformance/override/override_js2.ts @@ -0,0 +1,26 @@ +// @noImplicitOverride: true +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: a.js + +class B { + foo (v) {} + fooo (v) {} +} + +class D extends B { + foo (v) {} + /** @override */ + fooo (v) {} + /** @override */ + bar(v) {} +} + +class C { + foo () {} + /** @override */ + fooo (v) {} + /** @override */ + bar(v) {} +} \ No newline at end of file diff --git a/tests/cases/conformance/override/override_js3.ts b/tests/cases/conformance/override/override_js3.ts new file mode 100644 index 0000000000000..f36a29e37796d --- /dev/null +++ b/tests/cases/conformance/override/override_js3.ts @@ -0,0 +1,16 @@ +// @noImplicitOverride: true +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: a.js + +class B { + foo (v) {} + fooo (v) {} +} + +class D extends B { + override foo (v) {} + /** @override */ + fooo (v) {} +} diff --git a/tests/cases/fourslash/codeFixOverrideModifier1.ts b/tests/cases/fourslash/codeFixOverrideModifier1.ts new file mode 100644 index 0000000000000..1930b2130a88a --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier1.ts @@ -0,0 +1,17 @@ +/// + +// @noImplicitOverride: true +//// class B { +//// foo (v: string) {} +//// fooo (v: string) {} +//// } +//// class D extends B { +//// override foo (v: string) {} +//// [|fooo (v: string) {}|] +//// } + +verify.codeFix({ + description: "Add 'override' modifier", + newRangeContent: "override fooo (v: string) {}", + index: 0 +}) diff --git a/tests/cases/fourslash/codeFixOverrideModifier10.ts b/tests/cases/fourslash/codeFixOverrideModifier10.ts new file mode 100644 index 0000000000000..fd70f63f08629 --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier10.ts @@ -0,0 +1,15 @@ +/// + +// @noImplicitOverride: true + +//// class B { +//// b: string +//// } +//// class D extends B { +//// c = 10; +//// constructor(public a: string, public readonly b: string) { +//// super(); +//// } +//// } + +verify.not.codeFixAvailable(); diff --git a/tests/cases/fourslash/codeFixOverrideModifier11.ts b/tests/cases/fourslash/codeFixOverrideModifier11.ts new file mode 100644 index 0000000000000..6620ab257e6b9 --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier11.ts @@ -0,0 +1,12 @@ +/// + +// @noImplicitOverride: true + +//// abstract class Base { +//// abstract bar(): void; +//// } +//// class Sub extends Base { +//// [|override bar() {}|] +//// } + +verify.not.refactorAvailable(); diff --git a/tests/cases/fourslash/codeFixOverrideModifier12.ts b/tests/cases/fourslash/codeFixOverrideModifier12.ts new file mode 100644 index 0000000000000..60c673e739b0d --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier12.ts @@ -0,0 +1,16 @@ +/// + +// @noImplicitOverride: true + +//// abstract class Base { +//// abstract bar(): void; +//// } +//// class Sub extends Base { +//// [|abstract bar() {}|] +//// } + +verify.codeFix({ + description: "Add 'override' modifier", + newRangeContent: "override abstract bar() {}", + index: 0 +}) diff --git a/tests/cases/fourslash/codeFixOverrideModifier2.ts b/tests/cases/fourslash/codeFixOverrideModifier2.ts new file mode 100644 index 0000000000000..5b590f23330de --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier2.ts @@ -0,0 +1,19 @@ +/// + +// @noImplicitOverride: true +//// class B { +//// foo (v: string) {} +//// fooo (v: string) {} +//// } +//// function f () { +//// return class extends B { +//// override foo (v: string) {} +//// [|fooo (v: string) {}|] +//// } +//// } + +verify.codeFix({ + description: "Add 'override' modifier", + newRangeContent: "override fooo (v: string) {}", + index: 0 +}) diff --git a/tests/cases/fourslash/codeFixOverrideModifier3.ts b/tests/cases/fourslash/codeFixOverrideModifier3.ts new file mode 100644 index 0000000000000..40f8ed0b5afbc --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier3.ts @@ -0,0 +1,18 @@ +/// + +// @noImplicitOverride: true + +//// class E extends (class { +//// foo () {} +//// bar () {} +//// }) { +//// override foo () {} +//// [|bar () {}|] +//// baz() {} +//// } + +verify.codeFix({ + description: "Add 'override' modifier", + newRangeContent: "override bar () {}", + index: 0 +}) diff --git a/tests/cases/fourslash/codeFixOverrideModifier4.ts b/tests/cases/fourslash/codeFixOverrideModifier4.ts new file mode 100644 index 0000000000000..24a5e643cf9b2 --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier4.ts @@ -0,0 +1,17 @@ +/// + +// @noImplicitOverride: true +//// class B { +//// foo (v: string) {} +//// fooo (v: string) {} +//// } +//// class D extends B { +//// override foo (v: string) {} +//// [|override bar(v: string) {}|] +//// } + +verify.codeFix({ + description: "Remove 'override' modifier", + newRangeContent: "bar(v: string) {}", + index: 0 +}) diff --git a/tests/cases/fourslash/codeFixOverrideModifier5.ts b/tests/cases/fourslash/codeFixOverrideModifier5.ts new file mode 100644 index 0000000000000..b81cd1ff08a0c --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier5.ts @@ -0,0 +1,13 @@ +/// + +// @noImplicitOverride: true +//// class C { +//// [|override foo(v: string) {}|] +//// } + +verify.codeFix({ + description: "Remove 'override' modifier", + newRangeContent: "foo(v: string) {}", + index: 0 +}) + diff --git a/tests/cases/fourslash/codeFixOverrideModifier6.ts b/tests/cases/fourslash/codeFixOverrideModifier6.ts new file mode 100644 index 0000000000000..ae3e9566320ca --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier6.ts @@ -0,0 +1,20 @@ +/// + +// @noImplicitOverride: true +//// class B { +//// foo (v: string) {} +//// fooo (v: string) {} +//// } +//// function f () { +//// return class extends B { +//// override foo (v: string) {} +//// [|override bar(v: string) {}|] +//// } +//// } + +verify.codeFix({ + description: "Remove 'override' modifier", + newRangeContent: 'bar(v: string) {}', + index: 0 +}) + diff --git a/tests/cases/fourslash/codeFixOverrideModifier7.ts b/tests/cases/fourslash/codeFixOverrideModifier7.ts new file mode 100644 index 0000000000000..2e4fb59337344 --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier7.ts @@ -0,0 +1,19 @@ +/// + +// @noImplicitOverride: true +//// class E extends (class { +//// foo () {} +//// bar () {} +//// }) { +//// override foo () { } +//// baz() {} +//// [|override bazz () {}|] +//// } + + +verify.codeFix({ + description: "Remove 'override' modifier", + newRangeContent: "bazz () {}", + index: 0 +}) + diff --git a/tests/cases/fourslash/codeFixOverrideModifier8.ts b/tests/cases/fourslash/codeFixOverrideModifier8.ts new file mode 100644 index 0000000000000..d39ee2778533d --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier8.ts @@ -0,0 +1,15 @@ +/// + +// @noImplicitOverride: true +//// function ff () { +//// return class { +//// [|override foo () {}|] +//// } +//// } + +verify.codeFix({ + description: "Remove 'override' modifier", + newRangeContent: "foo () {}", + index: 0 +}) + diff --git a/tests/cases/fourslash/codeFixOverrideModifier9.ts b/tests/cases/fourslash/codeFixOverrideModifier9.ts new file mode 100644 index 0000000000000..77e24bf09ca3c --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier9.ts @@ -0,0 +1,15 @@ +/// + +// @noImplicitOverride: true + +//// class B { +//// a: string +//// } +//// class D extends B { +//// constructor(public a: string, public b: string) { +//// super(); +//// } +//// } + +verify.not.codeFixAvailable(); + diff --git a/tests/cases/fourslash/codeFixOverrideModifier_fixAll1.ts b/tests/cases/fourslash/codeFixOverrideModifier_fixAll1.ts new file mode 100644 index 0000000000000..1ec3130dc82dc --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier_fixAll1.ts @@ -0,0 +1,75 @@ +/// + +// @noImplicitOverride: true +//// class B { +//// foo (v: string) {} +//// fooo (v: string) {} +//// } +//// class D extends B { +//// override foo (v: string) {} +//// fooo (v: string) {} +//// override bar(v: string) {} +//// } +//// class C { +//// override foo(v: string) {} +//// } +//// function f () { +//// return class extends B { +//// override foo (v: string) {} +//// fooo (v: string) {} +//// override bar(v: string) {} +//// } +//// } +//// class E extends (class { +//// foo () { } +//// bar () { } +//// }) { +//// override foo () { } +//// bar () { } +//// baz() {} +//// override bazz () {} +//// } +//// function ff () { +//// return class { +//// override foo () {} +//// } +//// } + +verify.codeFixAll({ + fixId: "fixAddOverrideModifier", + fixAllDescription: "Add all missing 'override' modifiers", + newFileContent: `class B { + foo (v: string) {} + fooo (v: string) {} +} +class D extends B { + override foo (v: string) {} + override fooo (v: string) {} + override bar(v: string) {} +} +class C { + override foo(v: string) {} +} +function f () { + return class extends B { + override foo (v: string) {} + override fooo (v: string) {} + override bar(v: string) {} + } +} +class E extends (class { + foo () { } + bar () { } +}) { + override foo () { } + override bar () { } + baz() {} + override bazz () {} +} +function ff () { + return class { + override foo () {} + } +}` +}) + diff --git a/tests/cases/fourslash/codeFixOverrideModifier_fixAll2.ts b/tests/cases/fourslash/codeFixOverrideModifier_fixAll2.ts new file mode 100644 index 0000000000000..7d391f73fec1b --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier_fixAll2.ts @@ -0,0 +1,75 @@ +/// + +// @noImplicitOverride: true +//// class B { +//// foo (v: string) {} +//// fooo (v: string) {} +//// } +//// class D extends B { +//// override foo (v: string) {} +//// fooo (v: string) {} +//// override bar(v: string) {} +//// } +//// class C { +//// override foo(v: string) {} +//// } +//// function f () { +//// return class extends B { +//// override foo (v: string) {} +//// fooo (v: string) {} +//// override bar(v: string) {} +//// } +//// } +//// class E extends (class { +//// foo () { } +//// bar () { } +//// }) { +//// override foo () { } +//// bar () { } +//// baz() {} +//// override bazz () {} +//// } +//// function ff () { +//// return class { +//// override foo () {} +//// } +//// } + +verify.codeFixAll({ + fixId: "fixRemoveOverrideModifier", + fixAllDescription: "Remove all unnecessary 'override' modifiers", + newFileContent: `class B { + foo (v: string) {} + fooo (v: string) {} +} +class D extends B { + override foo (v: string) {} + fooo (v: string) {} + bar(v: string) {} +} +class C { + foo(v: string) {} +} +function f () { + return class extends B { + override foo (v: string) {} + fooo (v: string) {} + bar(v: string) {} + } +} +class E extends (class { + foo () { } + bar () { } +}) { + override foo () { } + bar () { } + baz() {} + bazz () {} +} +function ff () { + return class { + foo () {} + } +}` +}) + diff --git a/tests/cases/fourslash/codeFixOverrideModifier_js1.ts b/tests/cases/fourslash/codeFixOverrideModifier_js1.ts new file mode 100644 index 0000000000000..dd5675266572a --- /dev/null +++ b/tests/cases/fourslash/codeFixOverrideModifier_js1.ts @@ -0,0 +1,22 @@ +/// + +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @noImplicitOverride: true +// @filename: a.js +//// class B { +//// foo (v) {} +//// } +//// class D extends B { +//// foo (v) {} +//// /**@override*/ +//// bar (v) {} +//// } +//// class C { +//// /**@override*/ +//// foo () {} +//// } + +verify.not.codeFixAvailable("fixAddOverrideModifier"); +verify.not.codeFixAvailable("fixRemoveOverrideModifier"); diff --git a/tests/cases/fourslash/completionEntryForClassMembers.ts b/tests/cases/fourslash/completionEntryForClassMembers.ts index d0023dc15f4f6..57c23f5649f66 100644 --- a/tests/cases/fourslash/completionEntryForClassMembers.ts +++ b/tests/cases/fourslash/completionEntryForClassMembers.ts @@ -146,7 +146,7 @@ verify.completions( "classThatStartedWritingIdentifierAfterPrivateModifier", "classThatStartedWritingIdentifierAfterPrivateStaticModifier", ], - exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set"].map( + exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set", "override"].map( name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) ), isNewIdentifierLocation: true, diff --git a/tests/cases/fourslash/completionListInNamedClassExpression.ts b/tests/cases/fourslash/completionListInNamedClassExpression.ts index 68d994ca2c117..d69a607bc4642 100644 --- a/tests/cases/fourslash/completionListInNamedClassExpression.ts +++ b/tests/cases/fourslash/completionListInNamedClassExpression.ts @@ -11,7 +11,7 @@ verify.completions( { marker: "0", includes: { name: "myClass", text: "(local class) myClass", kind: "local class" } }, { marker: "1", - exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set"].map( + exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set", "override"].map( name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) ), isNewIdentifierLocation: true, diff --git a/tests/cases/fourslash/completionsWithOverride1.ts b/tests/cases/fourslash/completionsWithOverride1.ts new file mode 100644 index 0000000000000..f78fb4c95849c --- /dev/null +++ b/tests/cases/fourslash/completionsWithOverride1.ts @@ -0,0 +1,18 @@ +/// + +//// class A { +//// foo () {} +//// bar () {} +//// } +//// class B extends A { +//// override /*1*/ +//// } + +verify.completions({ + marker: "1", + includes: [ + "foo", + "bar" + ], + isNewIdentifierLocation: true +}) diff --git a/tests/cases/fourslash/completionsWithOverride2.ts b/tests/cases/fourslash/completionsWithOverride2.ts new file mode 100644 index 0000000000000..6fce32208b653 --- /dev/null +++ b/tests/cases/fourslash/completionsWithOverride2.ts @@ -0,0 +1,24 @@ +/// + +//// interface I { +//// baz () {} +//// } +//// class A { +//// foo () {} +//// bar () {} +//// } +//// class B extends A implements I { +//// override /*1*/ +//// } + +verify.completions({ + marker: "1", + includes: [ + "foo", + "bar" + ], + excludes: [ + "baz" + ], + isNewIdentifierLocation: true +})