diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 490b1bd9fbd40..faefba86582f1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -669,7 +669,7 @@ namespace ts { } // We create a return control flow graph for IIFEs and constructors. For constructors // we use the return control flow graph in strict property initialization checks. - currentReturnTarget = isIIFE || node.kind === SyntaxKind.Constructor || (isInJSFile(node) && (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression)) ? createBranchLabel() : undefined; + currentReturnTarget = isIIFE || node.kind === SyntaxKind.Constructor || node.kind === SyntaxKind.ClassStaticBlockDeclaration || (isInJSFile(node) && (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression)) ? createBranchLabel() : undefined; currentExceptionTarget = undefined; currentBreakTarget = undefined; currentContinueTarget = undefined; @@ -678,10 +678,10 @@ namespace ts { bindChildren(node); // Reset all reachability check related flags on node (for incremental scenarios) node.flags &= ~NodeFlags.ReachabilityAndEmitFlags; - if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & ContainerFlags.IsFunctionLike && nodeIsPresent((node as FunctionLikeDeclaration).body)) { + if (!(currentFlow.flags & FlowFlags.Unreachable) && containerFlags & ContainerFlags.IsFunctionLike && nodeIsPresent((node as FunctionLikeDeclaration | ClassStaticBlockDeclaration).body)) { node.flags |= NodeFlags.HasImplicitReturn; if (hasExplicitReturn) node.flags |= NodeFlags.HasExplicitReturn; - (node as FunctionLikeDeclaration).endFlowNode = currentFlow; + (node as FunctionLikeDeclaration | ClassStaticBlockDeclaration).endFlowNode = currentFlow; } if (node.kind === SyntaxKind.SourceFile) { node.flags |= emitFlags; @@ -691,8 +691,8 @@ namespace ts { if (currentReturnTarget) { addAntecedent(currentReturnTarget, currentFlow); currentFlow = finishFlowLabel(currentReturnTarget); - if (node.kind === SyntaxKind.Constructor || (isInJSFile(node) && (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression))) { - (node as FunctionLikeDeclaration).returnFlowNode = currentFlow; + if (node.kind === SyntaxKind.Constructor || node.kind === SyntaxKind.ClassStaticBlockDeclaration || (isInJSFile(node) && (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression))) { + (node as FunctionLikeDeclaration | ClassStaticBlockDeclaration).returnFlowNode = currentFlow; } } if (!isIIFE) { @@ -1944,7 +1944,7 @@ namespace ts { } function declareClassMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { - return hasSyntacticModifier(node, ModifierFlags.Static) + return isStatic(node) ? declareSymbol(container.symbol.exports!, container.symbol, node, symbolFlags, symbolExcludes) : declareSymbol(container.symbol.members!, container.symbol, node, symbolFlags, symbolExcludes); } @@ -2950,7 +2950,7 @@ namespace ts { // this.foo assignment in a JavaScript class // Bind this property to the containing class const containingClass = thisContainer.parent; - const symbolTable = hasSyntacticModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!; + const symbolTable = isStatic(thisContainer) ? containingClass.symbol.exports! : containingClass.symbol.members!; if (hasDynamicName(node)) { bindDynamicallyNamedThisPropertyAssignment(node, containingClass.symbol, symbolTable); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aeb908daeff30..ad5c60e5bffaa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1579,21 +1579,34 @@ namespace ts { if (isFunctionLike(current)) { return true; } + if (isClassStaticBlockDeclaration(current)) { + return declaration.pos < usage.pos; + } - const initializerOfProperty = current.parent && - current.parent.kind === SyntaxKind.PropertyDeclaration && - (current.parent as PropertyDeclaration).initializer === current; - - if (initializerOfProperty) { - if (hasSyntacticModifier(current.parent, ModifierFlags.Static)) { - if (declaration.kind === SyntaxKind.MethodDeclaration) { - return true; + const propertyDeclaration = tryCast(current.parent, isPropertyDeclaration); + if (propertyDeclaration) { + const initializerOfProperty = propertyDeclaration.initializer === current; + if (initializerOfProperty) { + if (isStatic(current.parent)) { + if (declaration.kind === SyntaxKind.MethodDeclaration) { + return true; + } + if (isPropertyDeclaration(declaration) && getContainingClass(usage) === getContainingClass(declaration)) { + const propName = declaration.name; + if (isIdentifier(propName) || isPrivateIdentifier(propName)) { + const type = getTypeOfSymbol(getSymbolOfNode(declaration)); + const staticBlocks = filter(declaration.parent.members, isClassStaticBlockDeclaration); + if (isPropertyInitializedInStaticBlocks(propName, type, staticBlocks, declaration.parent.pos, current.pos)) { + return true; + } + } + } } - } - else { - const isDeclarationInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !hasSyntacticModifier(declaration, ModifierFlags.Static); - if (!isDeclarationInstanceProperty || getContainingClass(usage) !== getContainingClass(declaration)) { - return true; + else { + const isDeclarationInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !isStatic(declaration); + if (!isDeclarationInstanceProperty || getContainingClass(usage) !== getContainingClass(declaration)) { + return true; + } } } } @@ -1857,7 +1870,7 @@ namespace ts { // local variables of the constructor. This effectively means that entities from outer scopes // by the same name as a constructor parameter or local variable are inaccessible // in initializer expressions for instance member variables. - if (!hasSyntacticModifier(location, ModifierFlags.Static)) { + if (!isStatic(location)) { const ctor = findConstructorDeclaration(location.parent as ClassLikeDeclaration); if (ctor && ctor.locals) { if (lookup(ctor.locals, name, meaning & SymbolFlags.Value)) { @@ -1879,7 +1892,7 @@ namespace ts { result = undefined; break; } - if (lastLocation && hasSyntacticModifier(lastLocation, ModifierFlags.Static)) { + if (lastLocation && isStatic(lastLocation)) { // TypeScript 1.0 spec (April 2014): 3.4.1 // The scope of a type parameter extends over the entire declaration with which the type // parameter list is associated, with the exception of static member declarations in classes. @@ -2189,7 +2202,7 @@ namespace ts { // initializers in instance property declaration of class like entities are executed in constructor and thus deferred return isTypeQueryNode(location) || (( isFunctionLikeDeclaration(location) || - (location.kind === SyntaxKind.PropertyDeclaration && !hasSyntacticModifier(location, ModifierFlags.Static)) + (location.kind === SyntaxKind.PropertyDeclaration && !isStatic(location)) ) && (!lastLocation || lastLocation !== (location as SignatureDeclaration | PropertyDeclaration).name)); // A name is evaluated within the enclosing scope - so it shouldn't count as deferred } if (lastLocation && lastLocation === (location as FunctionExpression | ArrowFunction).name) { @@ -2258,7 +2271,7 @@ namespace ts { // No static member is present. // Check if we're in an instance method and look for a relevant instance member. - if (location === container && !hasSyntacticModifier(location, ModifierFlags.Static)) { + if (location === container && !isStatic(location)) { const instanceType = (getDeclaredTypeOfSymbol(classSymbol) as InterfaceType).thisType!; // TODO: GH#18217 if (getPropertyOfType(instanceType, name)) { error(errorLocation, Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0, diagnosticName(nameArg)); @@ -4855,7 +4868,7 @@ namespace ts { } function shouldWriteTypeOfFunctionSymbol() { const isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method) && // typeof static method - some(symbol.declarations, declaration => hasSyntacticModifier(declaration, ModifierFlags.Static)); + some(symbol.declarations, declaration => isStatic(declaration)); const isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) && (symbol.parent || // is exported function symbol forEach(symbol.declarations, declaration => @@ -7008,7 +7021,7 @@ namespace ts { function isNamespaceMember(p: Symbol) { return !!(p.flags & (SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias)) || - !(p.flags & SymbolFlags.Prototype || p.escapedName === "prototype" || p.valueDeclaration && getEffectiveModifierFlags(p.valueDeclaration) & ModifierFlags.Static && isClassLike(p.valueDeclaration.parent)); + !(p.flags & SymbolFlags.Prototype || p.escapedName === "prototype" || p.valueDeclaration && isStatic(p.valueDeclaration) && isClassLike(p.valueDeclaration.parent)); } function sanitizeJSDocImplements(clauses: readonly ExpressionWithTypeArguments[]): ExpressionWithTypeArguments[] | undefined { @@ -8448,14 +8461,23 @@ namespace ts { return addOptionality(type, isProperty, isOptional); } - if (isPropertyDeclaration(declaration) && !hasStaticModifier(declaration) && (noImplicitAny || isInJSFile(declaration))) { + if (isPropertyDeclaration(declaration) && (noImplicitAny || isInJSFile(declaration))) { // We have a property declaration with no type annotation or initializer, in noImplicitAny mode or a .js file. - // Use control flow analysis of this.xxx assignments in the constructor to determine the type of the property. - const constructor = findConstructorDeclaration(declaration.parent); - const type = constructor ? getFlowTypeInConstructor(declaration.symbol, constructor) : - getEffectiveModifierFlags(declaration) & ModifierFlags.Ambient ? getTypeOfPropertyInBaseClass(declaration.symbol) : - undefined; - return type && addOptionality(type, /*isProperty*/ true, isOptional); + // Use control flow analysis of this.xxx assignments in the constructor or static block to determine the type of the property. + if (!hasStaticModifier(declaration)) { + const constructor = findConstructorDeclaration(declaration.parent); + const type = constructor ? getFlowTypeInConstructor(declaration.symbol, constructor) : + getEffectiveModifierFlags(declaration) & ModifierFlags.Ambient ? getTypeOfPropertyInBaseClass(declaration.symbol) : + undefined; + return type && addOptionality(type, /*isProperty*/ true, isOptional); + } + else { + const staticBlocks = filter(declaration.parent.members, isClassStaticBlockDeclaration); + const type = staticBlocks.length ? getFlowTypeInStaticBlocks(declaration.symbol, staticBlocks) : + getEffectiveModifierFlags(declaration) & ModifierFlags.Ambient ? getTypeOfPropertyInBaseClass(declaration.symbol) : + undefined; + return type && addOptionality(type, /*isProperty*/ true, isOptional); + } } if (isJsxAttribute(declaration)) { @@ -8530,6 +8552,27 @@ namespace ts { return getFlowTypeOfReference(reference, autoType, undefinedType); } + function getFlowTypeInStaticBlocks(symbol: Symbol, staticBlocks: readonly ClassStaticBlockDeclaration[]) { + const accessName = startsWith(symbol.escapedName as string, "__#") + ? factory.createPrivateIdentifier((symbol.escapedName as string).split("@")[1]) + : unescapeLeadingUnderscores(symbol.escapedName); + for (const staticBlock of staticBlocks) { + const reference = factory.createPropertyAccessExpression(factory.createThis(), accessName); + setParent(reference.expression, reference); + setParent(reference, staticBlock); + reference.flowNode = staticBlock.returnFlowNode; + const flowType = getFlowTypeOfProperty(reference, symbol); + if (noImplicitAny && (flowType === autoType || flowType === autoArrayType)) { + error(symbol.valueDeclaration, Diagnostics.Member_0_implicitly_has_an_1_type, symbolToString(symbol), typeToString(flowType)); + } + // We don't infer a type if assignments are only null or undefined. + if (everyType(flowType, isNullableType)) { + continue; + } + return convertAutoToAny(flowType); + } + } + function getFlowTypeInConstructor(symbol: Symbol, constructor: ConstructorDeclaration) { const accessName = startsWith(symbol.escapedName as string, "__#") ? factory.createPrivateIdentifier((symbol.escapedName as string).split("@")[1]) @@ -10131,7 +10174,7 @@ namespace ts { } function isStaticPrivateIdentifierProperty(s: Symbol): boolean { - return !!s.valueDeclaration && isPrivateIdentifierClassElementDeclaration(s.valueDeclaration) && hasSyntacticModifier(s.valueDeclaration, ModifierFlags.Static); + return !!s.valueDeclaration && isPrivateIdentifierClassElementDeclaration(s.valueDeclaration) && isStatic(s.valueDeclaration); } function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers { @@ -15617,7 +15660,7 @@ namespace ts { const container = getThisContainer(node, /*includeArrowFunctions*/ false); const parent = container && container.parent; if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) { - if (!hasSyntacticModifier(container, ModifierFlags.Static) && + if (!isStatic(container) && (!isConstructorDeclaration(container) || isNodeDescendantOf(node, container.body))) { return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent as ClassLikeDeclaration | InterfaceDeclaration)).thisType!; } @@ -24242,7 +24285,7 @@ namespace ts { let container = getThisContainer(node, /*includeArrowFunctions*/ false); while (container.kind !== SyntaxKind.SourceFile) { if (container.parent === declaration) { - if (container.kind === SyntaxKind.PropertyDeclaration && hasSyntacticModifier(container, ModifierFlags.Static)) { + if (container.kind === SyntaxKind.PropertyDeclaration && isStatic(container)) { getNodeLinks(declaration).flags |= NodeCheckFlags.ClassWithConstructorReference; getNodeLinks(node).flags |= NodeCheckFlags.ConstructorReferenceInClass; } @@ -24505,6 +24548,13 @@ namespace ts { } } + function checkThisInStaticClassFieldInitializerInDecoratedClass(thisExpression: Node, container: Node) { + if (isPropertyDeclaration(container) && hasStaticModifier(container) && + container.initializer && textRangeContainsPositionInclusive(container.initializer, thisExpression.pos) && length(container.parent.decorators)) { + error(thisExpression, Diagnostics.Cannot_use_this_in_a_static_property_initializer_of_a_decorated_class); + } + } + function checkThisExpression(node: Node): Type { const isNodeInTypeQuery = isInTypeQuery(node); // Stop at the first arrow function so that we can @@ -24522,6 +24572,7 @@ namespace ts { capturedByArrowFunction = true; } + checkThisInStaticClassFieldInitializerInDecoratedClass(node, container); switch (container.kind) { case SyntaxKind.ModuleDeclaration: error(node, Diagnostics.this_cannot_be_referenced_in_a_module_or_namespace_body); @@ -24537,16 +24588,6 @@ namespace ts { // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks } break; - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - if (hasSyntacticModifier(container, ModifierFlags.Static) && !(compilerOptions.target === ScriptTarget.ESNext && useDefineForClassFields)) { - error(node, Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer); - // do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks - } - break; - case SyntaxKind.ClassStaticBlockDeclaration: - error(node, Diagnostics.this_cannot_be_referenced_in_current_location); - break; case SyntaxKind.ComputedPropertyName: error(node, Diagnostics.this_cannot_be_referenced_in_a_computed_property_name); break; @@ -24605,8 +24646,7 @@ namespace ts { if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); - const isStatic = hasSyntacticModifier(container, ModifierFlags.Static) || isClassStaticBlockDeclaration(container); - const type = isStatic ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; + const type = isStatic(container) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; return getFlowTypeOfReference(node, type); } @@ -24636,7 +24676,7 @@ namespace ts { } if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); - return hasSyntacticModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; + return isStatic(container) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; } } @@ -24757,7 +24797,7 @@ namespace ts { checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class); } - if (hasSyntacticModifier(container, ModifierFlags.Static) || isCallExpression) { + if (isStatic(container) || isCallExpression) { nodeCheckFlag = NodeCheckFlags.SuperStatic; } else { @@ -24893,11 +24933,13 @@ namespace ts { // topmost container must be something that is directly nested in the class declaration\object literal expression if (isClassLike(container.parent) || container.parent.kind === SyntaxKind.ObjectLiteralExpression) { - if (hasSyntacticModifier(container, ModifierFlags.Static)) { + if (isStatic(container)) { return container.kind === SyntaxKind.MethodDeclaration || container.kind === SyntaxKind.MethodSignature || container.kind === SyntaxKind.GetAccessor || - container.kind === SyntaxKind.SetAccessor; + container.kind === SyntaxKind.SetAccessor || + container.kind === SyntaxKind.PropertyDeclaration || + container.kind === SyntaxKind.ClassStaticBlockDeclaration; } else { return container.kind === SyntaxKind.MethodDeclaration || @@ -25036,7 +25078,7 @@ namespace ts { case SyntaxKind.BindingElement: return getContextualTypeForBindingElement(declaration); case SyntaxKind.PropertyDeclaration: - if (hasSyntacticModifier(declaration, ModifierFlags.Static)) { + if (isStatic(declaration)) { return getContextualTypeForStaticPropertyDeclaration(declaration); } // By default, do nothing and return undefined - only the above cases have context implied by a parent @@ -27539,10 +27581,12 @@ namespace ts { let assumeUninitialized = false; if (strictNullChecks && strictPropertyInitialization && isAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword) { const declaration = prop && prop.valueDeclaration; - if (declaration && isInstancePropertyWithoutInitializer(declaration)) { - const flowContainer = getControlFlowContainer(node); - if (flowContainer.kind === SyntaxKind.Constructor && flowContainer.parent === declaration.parent && !(declaration.flags & NodeFlags.Ambient)) { - assumeUninitialized = true; + if (declaration && isPropertyWithoutInitializer(declaration)) { + if (!isStatic(declaration)) { + const flowContainer = getControlFlowContainer(node); + if (flowContainer.kind === SyntaxKind.Constructor && flowContainer.parent === declaration.parent && !(declaration.flags & NodeFlags.Ambient)) { + assumeUninitialized = true; + } } } } @@ -27708,7 +27752,7 @@ namespace ts { function typeHasStaticProperty(propName: __String, containingType: Type): boolean { const prop = containingType.symbol && getPropertyOfType(getTypeOfSymbol(containingType.symbol), propName); - return prop !== undefined && !!prop.valueDeclaration && hasSyntacticModifier(prop.valueDeclaration, ModifierFlags.Static); + return prop !== undefined && !!prop.valueDeclaration && isStatic(prop.valueDeclaration); } function getSuggestedLibForNonExistentName(name: __String | Identifier) { @@ -33272,16 +33316,16 @@ namespace ts { } } else { - const isStatic = hasSyntacticModifier(member, ModifierFlags.Static); + const isStaticMember = isStatic(member); const name = member.name; if (!name) { continue; } const isPrivate = isPrivateIdentifier(name); - const privateStaticFlags = isPrivate && isStatic ? DeclarationMeaning.PrivateStatic : 0; + const privateStaticFlags = isPrivate && isStaticMember ? DeclarationMeaning.PrivateStatic : 0; const names = isPrivate ? privateIdentifiers : - isStatic ? staticNames : + isStaticMember ? staticNames : instanceNames; const memberName = name && getPropertyNameForPropertyNameNode(name); @@ -33351,8 +33395,8 @@ namespace ts { function checkClassForStaticPropertyNameConflicts(node: ClassLikeDeclaration) { for (const member of node.members) { const memberNameNode = member.name; - const isStatic = hasSyntacticModifier(member, ModifierFlags.Static); - if (isStatic && memberNameNode) { + const isStaticMember = isStatic(member); + if (isStaticMember && memberNameNode) { const memberName = getPropertyNameForPropertyNameNode(memberNameNode); switch (memberName) { case "name": @@ -33534,7 +33578,7 @@ namespace ts { return true; } return n.kind === SyntaxKind.PropertyDeclaration && - !hasSyntacticModifier(n, ModifierFlags.Static) && + !isStatic(n) && !!(n as PropertyDeclaration).initializer; } @@ -34019,13 +34063,13 @@ namespace ts { )) { const reportError = (node.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && - hasSyntacticModifier(node, ModifierFlags.Static) !== hasSyntacticModifier(subsequentNode, ModifierFlags.Static); + isStatic(node) !== isStatic(subsequentNode); // we can get here in two cases // 1. mixed static and instance class members // 2. something with the same name was defined before the set of overloads that prevents them from merging // here we'll report error only for the first case since for second we should already report error in binder if (reportError) { - const diagnostic = hasSyntacticModifier(node, ModifierFlags.Static) ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static; + const diagnostic = isStatic(node) ? Diagnostics.Function_overload_must_be_static : Diagnostics.Function_overload_must_not_be_static; error(errorNode, diagnostic); } return; @@ -36997,13 +37041,13 @@ namespace ts { } } - function checkIndexConstraints(type: Type, isStatic?: boolean) { + function checkIndexConstraints(type: Type, isStaticIndex?: boolean) { const indexInfos = getIndexInfosOfType(type); if (indexInfos.length === 0) { return; } for (const prop of getPropertiesOfObjectType(type)) { - if (!(isStatic && prop.flags & SymbolFlags.Prototype)) { + if (!(isStaticIndex && prop.flags & SymbolFlags.Prototype)) { checkIndexConstraintForProperty(type, prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*includeNonPublic*/ true), getNonMissingTypeOfSymbol(prop)); } } @@ -37012,7 +37056,7 @@ namespace ts { for (const member of typeDeclaration.members) { // Only process instance properties with computed names here. Static properties cannot be in conflict with indexers, // and properties with literal names were already checked. - if (!hasSyntacticModifier(member, ModifierFlags.Static) && !hasBindableName(member)) { + if (!isStatic(member) && !hasBindableName(member)) { const symbol = getSymbolOfNode(member); checkIndexConstraintForProperty(type, symbol, getTypeOfExpression((member as DynamicNamedDeclaration).name.expression), getNonMissingTypeOfSymbol(symbol)); } @@ -37356,7 +37400,7 @@ namespace ts { if (produceDiagnostics) { checkIndexConstraints(type); - checkIndexConstraints(staticType, /*isStatic*/ true); + checkIndexConstraints(staticType, /*isStaticIndex*/ true); checkTypeForDuplicateIndexSignatures(node); checkPropertyInitialization(node); } @@ -37386,7 +37430,7 @@ namespace ts { function checkClassMember(member: ClassElement | ParameterPropertyDeclaration, memberIsParameterProperty?: boolean) { const hasOverride = hasOverrideModifier(member); - const hasStatic = hasStaticModifier(member); + const hasStatic = isStatic(member); if (baseWithThis && (hasOverride || compilerOptions.noImplicitOverride)) { const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member); if (!declaredProp) { @@ -37433,7 +37477,7 @@ namespace ts { // 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; for (const member of node.members) { - if (hasStaticModifier(member)) { + if (isStatic(member)) { continue; } const declaredProp = member.name && getSymbolAtLocation(member.name) || getSymbolAtLocation(member); @@ -37689,7 +37733,7 @@ namespace ts { if (getEffectiveModifierFlags(member) & ModifierFlags.Ambient) { continue; } - if (isInstancePropertyWithoutInitializer(member)) { + if (!isStatic(member) && isPropertyWithoutInitializer(member)) { const propName = (member as PropertyDeclaration).name; if (isIdentifier(propName) || isPrivateIdentifier(propName)) { const type = getTypeOfSymbol(getSymbolOfNode(member)); @@ -37703,13 +37747,30 @@ namespace ts { } } - function isInstancePropertyWithoutInitializer(node: Node) { + function isPropertyWithoutInitializer(node: Node) { return node.kind === SyntaxKind.PropertyDeclaration && - !hasSyntacticModifier(node, ModifierFlags.Static | ModifierFlags.Abstract) && + !hasAbstractModifier(node) && !(node as PropertyDeclaration).exclamationToken && !(node as PropertyDeclaration).initializer; } + function isPropertyInitializedInStaticBlocks(propName: Identifier | PrivateIdentifier, propType: Type, staticBlocks: readonly ClassStaticBlockDeclaration[], startPos: number, endPos: number) { + for (const staticBlock of staticBlocks) { + // static block must be within the provided range as they are evaluated in document order (unlike constructors) + if (staticBlock.pos >= startPos && staticBlock.pos <= endPos) { + const reference = factory.createPropertyAccessExpression(factory.createThis(), propName); + setParent(reference.expression, reference); + setParent(reference, staticBlock); + reference.flowNode = staticBlock.returnFlowNode; + const flowType = getFlowTypeOfReference(reference, propType, getOptionalType(propType)); + if (!(getFalsyFlags(flowType) & TypeFlags.Undefined)) { + return true; + } + } + } + return false; + } + function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) { const reference = factory.createPropertyAccessExpression(factory.createThis(), propName); setParent(reference.expression, reference); @@ -39121,7 +39182,7 @@ namespace ts { } const symbols = createSymbolTable(); - let isStatic = false; + let isStaticSymbol = false; populateSymbols(); @@ -39159,7 +39220,7 @@ namespace ts { // add the type parameters into the symbol table // (type parameters of classDeclaration/classExpression and interface are in member property of the symbol. // Note: that the memberFlags come from previous iteration. - if (!isStatic) { + if (!isStaticSymbol) { copySymbols(getMembersOfSymbol(getSymbolOfNode(location as ClassDeclaration | InterfaceDeclaration)), meaning & SymbolFlags.Type); } break; @@ -39175,7 +39236,7 @@ namespace ts { copySymbol(argumentsSymbol, meaning); } - isStatic = hasSyntacticModifier(location, ModifierFlags.Static); + isStaticSymbol = isStatic(location); location = location.parent; } @@ -39774,7 +39835,7 @@ namespace ts { */ function getParentTypeOfClassElement(node: ClassElement) { const classSymbol = getSymbolOfNode(node.parent)!; - return hasSyntacticModifier(node, ModifierFlags.Static) + return isStatic(node) ? getTypeOfSymbol(classSymbol) : getDeclaredTypeOfSymbol(classSymbol); } @@ -41818,8 +41879,8 @@ namespace ts { break; case SyntaxKind.PropertyDeclaration: - if (!hasSyntacticModifier(parent, ModifierFlags.Static) || - !hasEffectiveModifier(parent, ModifierFlags.Readonly)) { + if (!isStatic(parent) || + !hasEffectiveReadonlyModifier(parent)) { return grammarErrorOnNode((parent as PropertyDeclaration).name, Diagnostics.A_property_of_a_class_whose_type_is_a_unique_symbol_type_must_be_both_static_and_readonly); } break; @@ -42236,7 +42297,7 @@ namespace ts { } if (isPropertyDeclaration(node) && node.exclamationToken && (!isClassLike(node.parent) || !node.type || node.initializer || - node.flags & NodeFlags.Ambient || hasSyntacticModifier(node, ModifierFlags.Static | ModifierFlags.Abstract))) { + node.flags & NodeFlags.Ambient || isStatic(node) || hasAbstractModifier(node))) { const message = node.initializer ? Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions : !node.type diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ac42b13400b99..134588f89fe57 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3344,6 +3344,14 @@ "category": "Error", "code": 2815 }, + "Cannot use 'this' in a static property initializer of a decorated class.": { + "category": "Error", + "code": 2816 + }, + "Property '{0}' has no initializer and is not definitely assigned in a class static block.": { + "category": "Error", + "code": 2817 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index a49e748c2b449..2c2fde823ac16 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -496,8 +496,11 @@ namespace ts { createArraySliceCall, createArrayConcatCall, createObjectDefinePropertyCall, + createReflectGetCall, + createReflectSetCall, createPropertyDescriptor, createCallBinding, + createAssignmentTargetWrapper, // Utilities inlineExpressions, @@ -998,8 +1001,10 @@ namespace ts { case SyntaxKind.UndefinedKeyword: // `undefined` is an Identifier in the expression case. transformFlags = TransformFlags.ContainsTypeScript; break; - case SyntaxKind.StaticKeyword: case SyntaxKind.SuperKeyword: + transformFlags = TransformFlags.ContainsES2015 | TransformFlags.ContainsLexicalSuper; + break; + case SyntaxKind.StaticKeyword: transformFlags = TransformFlags.ContainsES2015; break; case SyntaxKind.ThisKeyword: @@ -2624,7 +2629,7 @@ namespace ts { propagateChildFlags(node.equalsGreaterThanToken) | TransformFlags.ContainsES2015; if (modifiersToFlags(node.modifiers) & ModifierFlags.Async) { - node.transformFlags |= TransformFlags.ContainsES2017; + node.transformFlags |= TransformFlags.ContainsES2017 | TransformFlags.ContainsLexicalThis; } return node; } @@ -5435,6 +5440,15 @@ namespace ts { } function createMethodCall(object: Expression, methodName: string | Identifier, argumentsList: readonly Expression[]) { + // Preserve the optionality of `object`. + if (isCallChain(object)) { + return createCallChain( + createPropertyAccessChain(object, /*questionDotToken*/ undefined, methodName), + /*questionDotToken*/ undefined, + /*typeArguments*/ undefined, + argumentsList + ); + } return createCallExpression( createPropertyAccessExpression(object, methodName), /*typeArguments*/ undefined, @@ -5470,6 +5484,14 @@ namespace ts { return createGlobalMethodCall("Object", "defineProperty", [target, asExpression(propertyName), attributes]); } + function createReflectGetCall(target: Expression, propertyKey: Expression, receiver?: Expression): CallExpression { + return createGlobalMethodCall("Reflect", "get", receiver ? [target, propertyKey, receiver] : [target, propertyKey]); + } + + function createReflectSetCall(target: Expression, propertyKey: Expression, value: Expression, receiver?: Expression): CallExpression { + return createGlobalMethodCall("Reflect", "set", receiver ? [target, propertyKey, value, receiver] : [target, propertyKey, value]); + } + function tryAddPropertyAssignment(properties: Push, propertyName: string, expression: Expression | undefined) { if (expression) { properties.push(createPropertyAssignment(propertyName, expression)); @@ -5645,6 +5667,34 @@ namespace ts { return { target, thisArg }; } + function createAssignmentTargetWrapper(paramName: Identifier, expression: Expression): LeftHandSideExpression { + return createPropertyAccessExpression( + // Explicit parens required because of v8 regression (https://bugs.chromium.org/p/v8/issues/detail?id=9560) + createParenthesizedExpression( + createObjectLiteralExpression([ + createSetAccessorDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + "value", + [createParameterDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + paramName, + /*questionToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined + )], + createBlock([ + createExpressionStatement(expression) + ]) + ) + ]) + ), + "value" + ); + } + function inlineExpressions(expressions: readonly Expression[]) { // Avoid deeply nested comma expressions as traversing them during emit can result in "Maximum call // stack size exceeded" errors. diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index a8397d33f5407..6d40ae277bd4e 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -303,6 +303,67 @@ namespace ts { } } + /** + * Expand the read and increment/decrement operations a pre- or post-increment or pre- or post-decrement expression. + * + * ```ts + * // input + * ++ + * // output (if result is not discarded) + * var ; + * ( = , = ++, ) + * // output (if result is discarded) + * var ; + * ( = , ++, ) + * + * // input + * ++ + * // output (if result is not discarded) + * var ; + * ( = , = ++) + * // output (if result is discarded) + * var ; + * ( = , ++) + * ``` + * + * It is up to the caller to supply a temporary variable for `` if one is needed. + * The temporary variable `` is injected so that `++` and `--` work uniformly with `number` and `bigint`. + * The result of the expression is always the final result of incrementing or decrementing the expression, so that it can be used for storage. + * + * @param factory {@link NodeFactory} used to create the expanded representation. + * @param node The original prefix or postfix unary node. + * @param expression The expression to use as the value to increment or decrement + * @param resultVariable A temporary variable in which to store the result. Pass `undefined` if the result is discarded, or if the value of `` is the expected result. + */ + export function expandPreOrPostfixIncrementOrDecrementExpression(factory: NodeFactory, node: PrefixUnaryExpression | PostfixUnaryExpression, expression: Expression, recordTempVariable: (node: Identifier) => void, resultVariable: Identifier | undefined) { + const operator = node.operator; + Debug.assert(operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken, "Expected 'node' to be a pre- or post-increment or pre- or post-decrement expression"); + + const temp = factory.createTempVariable(recordTempVariable); + expression = factory.createAssignment(temp, expression); + setTextRange(expression, node.operand); + + let operation: Expression = isPrefixUnaryExpression(node) ? + factory.createPrefixUnaryExpression(operator, temp) : + factory.createPostfixUnaryExpression(temp, operator); + setTextRange(operation, node); + + if (resultVariable) { + operation = factory.createAssignment(resultVariable, operation); + setTextRange(operation, node); + } + + expression = factory.createComma(expression, operation); + setTextRange(expression, node); + + if (isPostfixUnaryExpression(node)) { + expression = factory.createComma(expression, temp); + setTextRange(expression, node); + } + + return expression; + } + /** * Gets whether an identifier should only be referred to by its internal name. */ diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 6ce6c7dd58c76..4a8b407578981 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -6,6 +6,11 @@ namespace ts { * which have initializers that reference the class name. */ ClassAliases = 1 << 0, + /** + * Enables substitutions for class expressions with static fields + * which have initializers that reference the 'this' or 'super'. + */ + ClassStaticThisOrSuperReference = 1 << 1, } export const enum PrivateIdentifierKind { Field = "f", @@ -76,10 +81,6 @@ namespace ts { * Used for prefixing generated variable names. */ className: string; - /** - * Used for brand check on static members - */ - classConstructor?: Identifier; /** * Used for brand check on private methods. */ @@ -90,6 +91,27 @@ namespace ts { identifiers: UnderscoreEscapedMap } + interface ClassLexicalEnvironment { + facts: ClassFacts; + /** + * Used for brand checks on static members, and `this` references in static initializers + */ + classConstructor: Identifier | undefined; + /** + * Used for `super` references in static initializers. + */ + superClassReference: Identifier | undefined; + privateIdentifierEnvironment: PrivateIdentifierEnvironment | undefined; + } + + const enum ClassFacts { + None = 0, + ClassWasDecorated = 1 << 0, + NeedsClassConstructorReference = 1 << 1, + NeedsClassSuperReference = 1 << 2, + NeedsSubstitutionForThisInClassStaticField = 1 << 3, + } + /** * Transforms ECMAScript Class Syntax. * TypeScript parameter property syntax is transformed in the TypeScript transformer. @@ -113,8 +135,15 @@ namespace ts { const shouldTransformPrivateElementsOrClassStaticBlocks = languageVersion < ScriptTarget.ESNext; + // We don't need to transform `super` property access when targeting ES5, ES3 because + // the es2015 transformation handles those. + const shouldTransformSuperInStaticInitializers = (languageVersion <= ScriptTarget.ES2021 || !useDefineForClassFields) && languageVersion >= ScriptTarget.ES2015; + const shouldTransformThisInStaticInitializers = languageVersion <= ScriptTarget.ES2021 || !useDefineForClassFields; + const previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; + const previousOnEmitNode = context.onEmitNode; + context.onEmitNode = onEmitNode; let enabledSubstitutions: ClassPropertySubstitutionFlags; @@ -132,8 +161,11 @@ namespace ts { */ let pendingStatements: Statement[] | undefined; - const privateIdentifierEnvironmentStack: (PrivateIdentifierEnvironment | undefined)[] = []; - let currentPrivateIdentifierEnvironment: PrivateIdentifierEnvironment | undefined; + const classLexicalEnvironmentStack: (ClassLexicalEnvironment | undefined)[] = []; + const classLexicalEnvironmentMap = new Map(); + let currentClassLexicalEnvironment: ClassLexicalEnvironment | undefined; + let currentComputedPropertyNameClassLexicalEnvironment: ClassLexicalEnvironment | undefined; + let currentStaticPropertyDeclarationOrStaticBlock: PropertyDeclaration | ClassStaticBlockDeclaration | undefined; return chainBundle(context, transformSourceFile); @@ -148,47 +180,78 @@ namespace ts { return visited; } - function visitor(node: Node): VisitResult { - if (!(node.transformFlags & TransformFlags.ContainsClassFields)) return node; - - switch (node.kind) { - case SyntaxKind.ClassExpression: - case SyntaxKind.ClassDeclaration: - return visitClassLike(node as ClassLikeDeclaration); - case SyntaxKind.PropertyDeclaration: - return visitPropertyDeclaration(node as PropertyDeclaration); - case SyntaxKind.VariableStatement: - return visitVariableStatement(node as VariableStatement); - case SyntaxKind.PropertyAccessExpression: - return visitPropertyAccessExpression(node as PropertyAccessExpression); - case SyntaxKind.PrefixUnaryExpression: - return visitPrefixUnaryExpression(node as PrefixUnaryExpression); - case SyntaxKind.PostfixUnaryExpression: - return visitPostfixUnaryExpression(node as PostfixUnaryExpression, /*valueIsDiscarded*/ false); - case SyntaxKind.CallExpression: - return visitCallExpression(node as CallExpression); - case SyntaxKind.BinaryExpression: - return visitBinaryExpression(node as BinaryExpression); - case SyntaxKind.PrivateIdentifier: - return visitPrivateIdentifier(node as PrivateIdentifier); - case SyntaxKind.ExpressionStatement: - return visitExpressionStatement(node as ExpressionStatement); - case SyntaxKind.ForStatement: - return visitForStatement(node as ForStatement); - case SyntaxKind.TaggedTemplateExpression: - return visitTaggedTemplateExpression(node as TaggedTemplateExpression); - case SyntaxKind.ClassStaticBlockDeclaration: - return visitClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); + function visitorWorker(node: Node, valueIsDiscarded: boolean): VisitResult { + if (node.transformFlags & TransformFlags.ContainsClassFields) { + switch (node.kind) { + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassDeclaration: + return visitClassLike(node as ClassLikeDeclaration); + case SyntaxKind.PropertyDeclaration: + return visitPropertyDeclaration(node as PropertyDeclaration); + case SyntaxKind.VariableStatement: + return visitVariableStatement(node as VariableStatement); + case SyntaxKind.PrivateIdentifier: + return visitPrivateIdentifier(node as PrivateIdentifier); + case SyntaxKind.ClassStaticBlockDeclaration: + return visitClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); + } + } + if (node.transformFlags & TransformFlags.ContainsClassFields || + node.transformFlags & TransformFlags.ContainsLexicalSuper && + shouldTransformSuperInStaticInitializers && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + switch (node.kind) { + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + return visitPreOrPostfixUnaryExpression(node as PrefixUnaryExpression | PostfixUnaryExpression, valueIsDiscarded); + case SyntaxKind.BinaryExpression: + return visitBinaryExpression(node as BinaryExpression, valueIsDiscarded); + case SyntaxKind.CallExpression: + return visitCallExpression(node as CallExpression); + case SyntaxKind.TaggedTemplateExpression: + return visitTaggedTemplateExpression(node as TaggedTemplateExpression); + case SyntaxKind.PropertyAccessExpression: + return visitPropertyAccessExpression(node as PropertyAccessExpression); + case SyntaxKind.ElementAccessExpression: + return visitElementAccessExpression(node as ElementAccessExpression); + case SyntaxKind.ExpressionStatement: + return visitExpressionStatement(node as ExpressionStatement); + case SyntaxKind.ForStatement: + return visitForStatement(node as ForStatement); + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: { + const savedCurrentStaticPropertyDeclarationOrStaticBlock = currentStaticPropertyDeclarationOrStaticBlock; + currentStaticPropertyDeclarationOrStaticBlock = undefined; + const result = visitEachChild(node, visitor, context); + currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock; + return result; + } + } } return visitEachChild(node, visitor, context); } - function visitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { - if (!shouldTransformPrivateElementsOrClassStaticBlocks) { - return visitEachChild(node, classElementVisitor, context); + function discardedValueVisitor(node: Node): VisitResult { + return visitorWorker(node, /*valueIsDiscarded*/ true); + } + + function visitor(node: Node): VisitResult { + return visitorWorker(node, /*valueIsDiscarded*/ false); + } + + function heritageClauseVisitor(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.HeritageClause: + return visitEachChild(node, heritageClauseVisitor, context); + case SyntaxKind.ExpressionWithTypeArguments: + return visitExpressionWithTypeArguments(node as ExpressionWithTypeArguments); } - // ClassStaticBlockDeclaration for classes are transformed in `visitClassDeclaration` or `visitClassExpression`. - return undefined; + return visitor(node); } function visitorDestructuringTarget(node: Node): VisitResult { @@ -406,89 +469,153 @@ namespace ts { ); } } + if (shouldTransformSuperInStaticInitializers && + isSuperProperty(node) && + isIdentifier(node.name) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + return visitInvalidSuperProperty(node); + } + if (classConstructor && superClassReference) { + // converts `super.x` into `Reflect.get(_baseTemp, "x", _classTemp)` + const superProperty = factory.createReflectGetCall( + superClassReference, + factory.createStringLiteralFromNode(node.name), + classConstructor + ); + setOriginalNode(superProperty, node.expression); + setTextRange(superProperty, node.expression); + return superProperty; + } + } return visitEachChild(node, visitor, context); } - function visitPrefixUnaryExpression(node: PrefixUnaryExpression) { - if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.operand)) { - const operator = node.operator === SyntaxKind.PlusPlusToken ? - SyntaxKind.PlusToken : node.operator === SyntaxKind.MinusMinusToken ? - SyntaxKind.MinusToken : undefined; - let info: PrivateIdentifierInfo | undefined; - if (operator && (info = accessPrivateIdentifier(node.operand.name))) { - const receiver = visitNode(node.operand.expression, visitor, isExpression); - const { readExpression, initializeExpression } = createCopiableReceiverExpr(receiver); - - const existingValue = factory.createPrefixUnaryExpression(SyntaxKind.PlusToken, createPrivateIdentifierAccess(info, readExpression)); + function visitElementAccessExpression(node: ElementAccessExpression) { + if (shouldTransformSuperInStaticInitializers && + isSuperProperty(node) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + return visitInvalidSuperProperty(node); + } - return setOriginalNode( - createPrivateIdentifierAssignment( - info, - initializeExpression || readExpression, - factory.createBinaryExpression(existingValue, operator, factory.createNumericLiteral(1)), - SyntaxKind.EqualsToken - ), - node + if (classConstructor && superClassReference) { + // converts `super[x]` into `Reflect.get(_baseTemp, x, _classTemp)` + const superProperty = factory.createReflectGetCall( + superClassReference, + visitNode(node.argumentExpression, visitor, isExpression), + classConstructor ); + setOriginalNode(superProperty, node.expression); + setTextRange(superProperty, node.expression); + return superProperty; } } return visitEachChild(node, visitor, context); } - function visitPostfixUnaryExpression(node: PostfixUnaryExpression, valueIsDiscarded: boolean) { - if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.operand)) { - const operator = node.operator === SyntaxKind.PlusPlusToken ? - SyntaxKind.PlusToken : node.operator === SyntaxKind.MinusMinusToken ? - SyntaxKind.MinusToken : undefined; - let info: PrivateIdentifierInfo | undefined; - if (operator && (info = accessPrivateIdentifier(node.operand.name))) { - const receiver = visitNode(node.operand.expression, visitor, isExpression); - const { readExpression, initializeExpression } = createCopiableReceiverExpr(receiver); - - const existingValue = factory.createPrefixUnaryExpression(SyntaxKind.PlusToken, createPrivateIdentifierAccess(info, readExpression)); - - // Create a temporary variable to store the value returned by the expression. - const returnValue = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration); - - return setOriginalNode( - factory.inlineExpressions(compact([ - createPrivateIdentifierAssignment( - info, - initializeExpression || readExpression, - factory.createBinaryExpression( - returnValue ? factory.createAssignment(returnValue, existingValue) : existingValue, - operator, - factory.createNumericLiteral(1) - ), - SyntaxKind.EqualsToken - ), - returnValue - ])), - node - ); + function visitPreOrPostfixUnaryExpression(node: PrefixUnaryExpression | PostfixUnaryExpression, valueIsDiscarded: boolean) { + if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.operand)) { + let info: PrivateIdentifierInfo | undefined; + if (info = accessPrivateIdentifier(node.operand.name)) { + const receiver = visitNode(node.operand.expression, visitor, isExpression); + const { readExpression, initializeExpression } = createCopiableReceiverExpr(receiver); + + let expression: Expression = createPrivateIdentifierAccess(info, readExpression); + const temp = isPrefixUnaryExpression(node) || valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration); + expression = expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp); + expression = createPrivateIdentifierAssignment( + info, + initializeExpression || readExpression, + expression, + SyntaxKind.EqualsToken + ); + setOriginalNode(expression, node); + setTextRange(expression, node); + if (temp) { + expression = factory.createComma(expression, temp); + setTextRange(expression, node); + } + return expression; + } + } + else if (shouldTransformSuperInStaticInitializers && + isSuperProperty(node.operand) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + // converts `++super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)` + // converts `++super[f()]` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = ++_b), _classTemp), _c)` + // converts `--super.a` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = --_a), _classTemp), _b)` + // converts `--super[f()]` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = --_b), _classTemp), _c)` + // converts `super.a++` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = _a++), _classTemp), _b)` + // converts `super[f()]++` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b++), _classTemp), _c)` + // converts `super.a--` into `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = _a--), _classTemp), _b)` + // converts `super[f()]--` into `(Reflect.set(_baseTemp, _a = f(), (_b = Reflect.get(_baseTemp, _a, _classTemp), _c = _b--), _classTemp), _c)` + const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + const operand = visitInvalidSuperProperty(node.operand); + return isPrefixUnaryExpression(node) ? + factory.updatePrefixUnaryExpression(node, operand) : + factory.updatePostfixUnaryExpression(node, operand); + } + if (classConstructor && superClassReference) { + let setterName: Expression | undefined; + let getterName: Expression | undefined; + if (isPropertyAccessExpression(node.operand)) { + if (isIdentifier(node.operand.name)) { + getterName = setterName = factory.createStringLiteralFromNode(node.operand.name); + } + } + else { + if (isSimpleInlineableExpression(node.operand.argumentExpression)) { + getterName = setterName = node.operand.argumentExpression; + } + else { + getterName = factory.createTempVariable(hoistVariableDeclaration); + setterName = factory.createAssignment(getterName, visitNode(node.operand.argumentExpression, visitor, isExpression)); + } + } + if (setterName && getterName) { + let expression: Expression = factory.createReflectGetCall(superClassReference, getterName, classConstructor); + setTextRange(expression, node.operand); + + const temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration); + expression = expandPreOrPostfixIncrementOrDecrementExpression(factory, node, expression, hoistVariableDeclaration, temp); + expression = factory.createReflectSetCall(superClassReference, setterName, expression, classConstructor); + setOriginalNode(expression, node); + setTextRange(expression, node); + if (temp) { + expression = factory.createComma(expression, temp); + setTextRange(expression, node); + } + return expression; + } + } } } return visitEachChild(node, visitor, context); } function visitForStatement(node: ForStatement) { - if (node.incrementor && isPostfixUnaryExpression(node.incrementor)) { - return factory.updateForStatement( - node, - visitNode(node.initializer, visitor, isForInitializer), - visitNode(node.condition, visitor, isExpression), - visitPostfixUnaryExpression(node.incrementor, /*valueIsDiscarded*/ true), - visitIterationBody(node.statement, visitor, context) - ); - } - return visitEachChild(node, visitor, context); + return factory.updateForStatement( + node, + visitNode(node.initializer, discardedValueVisitor, isForInitializer), + visitNode(node.condition, visitor, isExpression), + visitNode(node.incrementor, discardedValueVisitor, isExpression), + visitIterationBody(node.statement, visitor, context) + ); } function visitExpressionStatement(node: ExpressionStatement) { - if (isPostfixUnaryExpression(node.expression)) { - return factory.updateExpressionStatement(node, visitPostfixUnaryExpression(node.expression, /*valueIsDiscarded*/ true)); - } - return visitEachChild(node, visitor, context); + return factory.updateExpressionStatement( + node, + visitNode(node.expression, discardedValueVisitor, isExpression) + ); } function createCopiableReceiverExpr(receiver: Expression): { readExpression: Expression; initializeExpression: Expression | undefined } { @@ -521,6 +648,23 @@ namespace ts { [visitNode(thisArg, visitor, isExpression), ...visitNodes(node.arguments, visitor, isExpression)] ); } + + if (shouldTransformSuperInStaticInitializers && + isSuperProperty(node.expression) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment?.classConstructor) { + + // converts `super.f(...)` into `Reflect.get(_baseTemp, "f", _classTemp).call(_classTemp, ...)` + const invocation = factory.createFunctionCallCall( + visitNode(node.expression, visitor, isExpression), + currentClassLexicalEnvironment.classConstructor, + visitNodes(node.arguments, visitor, isExpression) + ); + setOriginalNode(invocation, node); + setTextRange(invocation, node); + return invocation; + } + return visitEachChild(node, visitor, context); } @@ -539,43 +683,68 @@ namespace ts { visitNode(node.template, visitor, isTemplateLiteral) ); } + if (shouldTransformSuperInStaticInitializers && + isSuperProperty(node.tag) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment?.classConstructor) { + + // converts `` super.f`x` `` into `` Reflect.get(_baseTemp, "f", _classTemp).bind(_classTemp)`x` `` + const invocation = factory.createFunctionBindCall( + visitNode(node.tag, visitor, isExpression), + currentClassLexicalEnvironment.classConstructor, + [] + ); + setOriginalNode(invocation, node); + setTextRange(invocation, node); + return factory.updateTaggedTemplateExpression( + node, + invocation, + /*typeArguments*/ undefined, + visitNode(node.template, visitor, isTemplateLiteral) + ); + } return visitEachChild(node, visitor, context); } function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { + if (currentClassLexicalEnvironment) { + classLexicalEnvironmentMap.set(getOriginalNodeId(node), currentClassLexicalEnvironment); + } + startLexicalEnvironment(); + const savedCurrentStaticPropertyDeclarationOrStaticBlock = currentStaticPropertyDeclarationOrStaticBlock; + currentStaticPropertyDeclarationOrStaticBlock = node; let statements = visitNodes(node.body.statements, visitor, isStatement); statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); + currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock; - return setTextRange( - setOriginalNode( - factory.createImmediatelyInvokedArrowFunction(statements), - node - ), - node - ); + const iife = factory.createImmediatelyInvokedArrowFunction(statements); + setOriginalNode(iife, node); + setTextRange(iife, node); + addEmitFlags(iife, EmitFlags.AdviseOnEmitNode); + return iife; } } - function visitBinaryExpression(node: BinaryExpression) { - if (shouldTransformPrivateElementsOrClassStaticBlocks) { - if (isDestructuringAssignment(node)) { - const savedPendingExpressions = pendingExpressions; - pendingExpressions = undefined; - node = factory.updateBinaryExpression( - node, - visitNode(node.left, visitorDestructuringTarget), - node.operatorToken, - visitNode(node.right, visitor) - ); - const expr = some(pendingExpressions) ? - factory.inlineExpressions(compact([...pendingExpressions!, node])) : - node; - pendingExpressions = savedPendingExpressions; - return expr; - } - if (isAssignmentExpression(node) && isPrivateIdentifierPropertyAccessExpression(node.left)) { + function visitBinaryExpression(node: BinaryExpression, valueIsDiscarded: boolean) { + if (isDestructuringAssignment(node)) { + const savedPendingExpressions = pendingExpressions; + pendingExpressions = undefined; + node = factory.updateBinaryExpression( + node, + visitNode(node.left, visitorDestructuringTarget), + node.operatorToken, + visitNode(node.right, visitor) + ); + const expr = some(pendingExpressions) ? + factory.inlineExpressions(compact([...pendingExpressions!, node])) : + node; + pendingExpressions = savedPendingExpressions; + return expr; + } + if (isAssignmentExpression(node)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.left)) { const info = accessPrivateIdentifier(node.left.name); if (info) { return setTextRange( @@ -587,6 +756,76 @@ namespace ts { ); } } + else if (shouldTransformSuperInStaticInitializers && + isSuperProperty(node.left) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + return factory.updateBinaryExpression( + node, + visitInvalidSuperProperty(node.left), + node.operatorToken, + visitNode(node.right, visitor, isExpression)); + } + if (classConstructor && superClassReference) { + let setterName = + isElementAccessExpression(node.left) ? visitNode(node.left.argumentExpression, visitor, isExpression) : + isIdentifier(node.left.name) ? factory.createStringLiteralFromNode(node.left.name) : + undefined; + if (setterName) { + // converts `super.x = 1` into `(Reflect.set(_baseTemp, "x", _a = 1, _classTemp), _a)` + // converts `super[f()] = 1` into `(Reflect.set(_baseTemp, f(), _a = 1, _classTemp), _a)` + // converts `super.x += 1` into `(Reflect.set(_baseTemp, "x", _a = Reflect.get(_baseTemp, "x", _classtemp) + 1, _classTemp), _a)` + // converts `super[f()] += 1` into `(Reflect.set(_baseTemp, _a = f(), _b = Reflect.get(_baseTemp, _a, _classtemp) + 1, _classTemp), _b)` + + let expression = visitNode(node.right, visitor, isExpression); + if (isCompoundAssignment(node.operatorToken.kind)) { + let getterName = setterName; + if (!isSimpleInlineableExpression(setterName)) { + getterName = factory.createTempVariable(hoistVariableDeclaration); + setterName = factory.createAssignment(getterName, setterName); + } + const superPropertyGet = factory.createReflectGetCall( + superClassReference, + getterName, + classConstructor + ); + setOriginalNode(superPropertyGet, node.left); + setTextRange(superPropertyGet, node.left); + + expression = factory.createBinaryExpression( + superPropertyGet, + getNonAssignmentOperatorForCompoundAssignment(node.operatorToken.kind), + expression + ); + setTextRange(expression, node); + } + + const temp = valueIsDiscarded ? undefined : factory.createTempVariable(hoistVariableDeclaration); + if (temp) { + expression = factory.createAssignment(temp, expression); + setTextRange(temp, node); + } + + expression = factory.createReflectSetCall( + superClassReference, + setterName, + expression, + classConstructor + ); + setOriginalNode(expression, node); + setTextRange(expression, node); + + if (temp) { + expression = factory.createComma(expression, temp); + setTextRange(expression, node); + } + + return expression; + } + } + } } return visitEachChild(node, visitor, context); } @@ -641,11 +880,15 @@ namespace ts { * Set up the environment for a class. */ function visitClassLike(node: ClassLikeDeclaration) { + if (!forEach(node.members, doesClassElementNeedTransform)) { + return visitEachChild(node, visitor, context); + } + const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined; - if (shouldTransformPrivateElementsOrClassStaticBlocks) { - startPrivateIdentifierEnvironment(); + startClassLexicalEnvironment(); + if (shouldTransformPrivateElementsOrClassStaticBlocks) { const name = getNameOfDeclaration(node); if (name && isIdentifier(name)) { getPrivateIdentifierEnvironment().className = idText(name); @@ -664,9 +907,7 @@ namespace ts { visitClassDeclaration(node) : visitClassExpression(node); - if (shouldTransformPrivateElementsOrClassStaticBlocks) { - endPrivateIdentifierEnvironment(); - } + endClassLexicalEnvironment(); pendingExpressions = savedPendingExpressions; return result; } @@ -679,20 +920,69 @@ namespace ts { return filter(node.members, isNonStaticMethodOrAccessorWithPrivateName); } + function getClassFacts(node: ClassLikeDeclaration) { + let facts = ClassFacts.None; + const original = getOriginalNode(node); + if (isClassDeclaration(original) && some(original.decorators)) { + facts |= ClassFacts.ClassWasDecorated; + } + for (const member of node.members) { + if (!isStatic(member)) continue; + if (member.name && isPrivateIdentifier(member.name) && shouldTransformPrivateElementsOrClassStaticBlocks) { + facts |= ClassFacts.NeedsClassConstructorReference; + } + if (isPropertyDeclaration(member) || isClassStaticBlockDeclaration(member)) { + if (shouldTransformThisInStaticInitializers && member.transformFlags & TransformFlags.ContainsLexicalThis) { + facts |= ClassFacts.NeedsSubstitutionForThisInClassStaticField; + if (!(facts & ClassFacts.ClassWasDecorated)) { + facts |= ClassFacts.NeedsClassConstructorReference; + } + } + if (shouldTransformSuperInStaticInitializers && member.transformFlags & TransformFlags.ContainsLexicalSuper) { + if (!(facts & ClassFacts.ClassWasDecorated)) { + facts |= ClassFacts.NeedsClassConstructorReference | ClassFacts.NeedsClassSuperReference; + } + } + } + } + return facts; + } + + function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments) { + const facts = currentClassLexicalEnvironment?.facts || ClassFacts.None; + if (facts & ClassFacts.NeedsClassSuperReference) { + const temp = factory.createTempVariable(hoistVariableDeclaration, /*reserveInNestedScopes*/ true); + getClassLexicalEnvironment().superClassReference = temp; + return factory.updateExpressionWithTypeArguments( + node, + factory.createAssignment( + temp, + visitNode(node.expression, visitor, isExpression) + ), + /*typeArguments*/ undefined + ); + } + return visitEachChild(node, visitor, context); + } + function visitClassDeclaration(node: ClassDeclaration) { - if (!forEach(node.members, doesClassElementNeedTransform)) { - return visitEachChild(node, visitor, context); + const facts = getClassFacts(node); + if (facts) { + getClassLexicalEnvironment().facts = facts; + } + if (facts & ClassFacts.NeedsSubstitutionForThisInClassStaticField) { + enableSubstitutionForClassStaticThisOrSuperReference(); } const staticProperties = getStaticPropertiesAndClassStaticBlock(node); - let pendingPrivateStateAssignment: BinaryExpression | undefined; - if (shouldTransformPrivateElementsOrClassStaticBlocks && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { - const temp = factory.createTempVariable(hoistVariableDeclaration, /* reservedInNestedScopes */ true); - getPrivateIdentifierEnvironment().classConstructor = factory.cloneNode(temp); - pendingPrivateStateAssignment = factory.createAssignment( - temp, - factory.getInternalName(node) - ); + + // If a class has private static fields, or a static field has a `this` or `super` reference, + // then we need to allocate a temp variable to hold on to that reference. + let pendingClassReferenceAssignment: BinaryExpression | undefined; + if (facts & ClassFacts.NeedsClassConstructorReference) { + const temp = factory.createTempVariable(hoistVariableDeclaration, /*reservedInNestedScopes*/ true); + getClassLexicalEnvironment().classConstructor = factory.cloneNode(temp); + pendingClassReferenceAssignment = factory.createAssignment(temp, factory.getInternalName(node)); } const extendsClauseElement = getEffectiveBaseTypeNode(node); @@ -705,13 +995,13 @@ namespace ts { node.modifiers, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), + visitNodes(node.heritageClauses, heritageClauseVisitor, isHeritageClause), transformClassMembers(node, isDerivedClass) ) ]; - if (pendingPrivateStateAssignment) { - getPendingExpressions().unshift(pendingPrivateStateAssignment); + if (pendingClassReferenceAssignment) { + getPendingExpressions().unshift(pendingClassReferenceAssignment); } // Write any pending expressions from elided or moved computed property names @@ -733,8 +1023,13 @@ namespace ts { } function visitClassExpression(node: ClassExpression): Expression { - if (!forEach(node.members, doesClassElementNeedTransform)) { - return visitEachChild(node, visitor, context); + const facts = getClassFacts(node); + if (facts) { + getClassLexicalEnvironment().facts = facts; + } + + if (facts & ClassFacts.NeedsSubstitutionForThisInClassStaticField) { + enableSubstitutionForClassStaticThisOrSuperReference(); } // If this class expression is a transformation of a decorated class declaration, @@ -744,7 +1039,7 @@ namespace ts { // In this case, we use pendingStatements to produce the same output as the // class declaration transformation. The VariableStatement visitor will insert // these statements after the class expression variable statement. - const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); + const isDecoratedClassDeclaration = !!(facts & ClassFacts.ClassWasDecorated); const staticPropertiesOrClassStaticBlocks = getStaticPropertiesAndClassStaticBlock(node); @@ -759,9 +1054,10 @@ namespace ts { const requiresBlockScopedVar = classCheckFlags & NodeCheckFlags.BlockScopedBindingInLoop; return factory.createTempVariable(requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration, !!isClassWithConstructorReference); } - if (shouldTransformPrivateElementsOrClassStaticBlocks && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { + + if (facts & ClassFacts.NeedsClassConstructorReference) { temp = createClassTempVar(); - getPrivateIdentifierEnvironment().classConstructor = factory.cloneNode(temp); + getClassLexicalEnvironment().classConstructor = factory.cloneNode(temp); } const classExpression = factory.updateClassExpression( @@ -770,9 +1066,10 @@ namespace ts { node.modifiers, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), + visitNodes(node.heritageClauses, heritageClauseVisitor, isHeritageClause), transformClassMembers(node, isDerivedClass) ); + const hasTransformableStatics = some(staticPropertiesOrClassStaticBlocks, p => isClassStaticBlockDeclaration(p) || !!p.initializer || (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(p.name))); if (hasTransformableStatics || some(pendingExpressions)) { if (isDecoratedClassDeclaration) { @@ -809,7 +1106,6 @@ namespace ts { // Add any pending expressions leftover from elided or relocated computed property names addRange(expressions, map(pendingExpressions, startOnNewLine)); addRange(expressions, generateInitializedPropertyExpressionsOrClassStaticBlock(staticPropertiesOrClassStaticBlocks, temp)); - expressions.push(startOnNewLine(temp)); return factory.inlineExpressions(expressions); @@ -819,6 +1115,14 @@ namespace ts { return classExpression; } + function visitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks) { + return visitEachChild(node, classElementVisitor, context); + } + // ClassStaticBlockDeclaration for classes are transformed in `visitClassDeclaration` or `visitClassExpression`. + return undefined; + } + function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { // Declare private names. @@ -859,7 +1163,7 @@ namespace ts { } function isClassElementThatRequiresConstructorStatement(member: ClassElement) { - if (hasStaticModifier(member) || hasSyntacticModifier(getOriginalNode(member), ModifierFlags.Abstract)) { + if (isStatic(member) || hasSyntacticModifier(getOriginalNode(member), ModifierFlags.Abstract)) { return false; } if (useDefineForClassFields) { @@ -989,7 +1293,9 @@ namespace ts { */ function addPropertyOrClassStaticBlockStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { for (const property of properties) { - const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property) : transformProperty(property, receiver); + const expression = isClassStaticBlockDeclaration(property) ? + transformClassStaticBlockDeclaration(property) : + transformProperty(property, receiver); if (!expression) { continue; } @@ -1031,12 +1337,29 @@ namespace ts { * @param receiver The object receiving the property assignment. */ function transformProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { + const savedCurrentStaticPropertyDeclarationOrStaticBlock = currentStaticPropertyDeclarationOrStaticBlock; + const transformed = transformPropertyWorker(property, receiver); + if (transformed && hasStaticModifier(property) && currentClassLexicalEnvironment?.facts) { + // capture the lexical environment for the member + setOriginalNode(transformed, property); + addEmitFlags(transformed, EmitFlags.AdviseOnEmitNode); + classLexicalEnvironmentMap.set(getOriginalNodeId(transformed), currentClassLexicalEnvironment); + } + currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock; + return transformed; + } + + function transformPropertyWorker(property: PropertyDeclaration, receiver: LeftHandSideExpression) { // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) const emitAssignment = !useDefineForClassFields; const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) ? factory.updateComputedPropertyName(property.name, factory.getGeneratedNameForNode(property.name)) : property.name; + if (hasStaticModifier(property)) { + currentStaticPropertyDeclarationOrStaticBlock = property; + } + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(propertyName)) { const privateIdentifierInfo = accessPrivateIdentifier(propertyName); if (privateIdentifierInfo) { @@ -1071,6 +1394,7 @@ namespace ts { if (hasSyntacticModifier(propertyOriginalNode, ModifierFlags.Abstract)) { return undefined; } + const initializer = property.initializer || emitAssignment ? visitNode(property.initializer, visitor, isExpression) ?? factory.createVoidZero() : isParameterPropertyDeclaration(propertyOriginalNode, propertyOriginalNode.parent) && isIdentifier(propertyName) ? propertyName : factory.createVoidZero(); @@ -1101,6 +1425,30 @@ namespace ts { } } + function enableSubstitutionForClassStaticThisOrSuperReference() { + if ((enabledSubstitutions & ClassPropertySubstitutionFlags.ClassStaticThisOrSuperReference) === 0) { + enabledSubstitutions |= ClassPropertySubstitutionFlags.ClassStaticThisOrSuperReference; + + // substitute `this` in a static field initializer + context.enableSubstitution(SyntaxKind.ThisKeyword); + + // these push a new lexical environment that is not the class lexical environment + context.enableEmitNotification(SyntaxKind.FunctionDeclaration); + context.enableEmitNotification(SyntaxKind.FunctionExpression); + context.enableEmitNotification(SyntaxKind.Constructor); + + // these push a new lexical environment that is not the class lexical environment, except + // when they have a computed property name + context.enableEmitNotification(SyntaxKind.GetAccessor); + context.enableEmitNotification(SyntaxKind.SetAccessor); + context.enableEmitNotification(SyntaxKind.MethodDeclaration); + context.enableEmitNotification(SyntaxKind.PropertyDeclaration); + + // class lexical environments are restored when entering a computed property name + context.enableEmitNotification(SyntaxKind.ComputedPropertyName); + } + } + /** * Generates brand-check initializer for private methods. * @@ -1122,6 +1470,80 @@ namespace ts { ); } + function visitInvalidSuperProperty(node: SuperProperty) { + return isPropertyAccessExpression(node) ? + factory.updatePropertyAccessExpression( + node, + factory.createVoidZero(), + node.name) : + factory.updateElementAccessExpression( + node, + factory.createVoidZero(), + visitNode(node.argumentExpression, visitor, isExpression)); + } + + function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) { + const original = getOriginalNode(node); + if (original.id) { + const classLexicalEnvironment = classLexicalEnvironmentMap.get(original.id); + if (classLexicalEnvironment) { + const savedClassLexicalEnvironment = currentClassLexicalEnvironment; + const savedCurrentComputedPropertyNameClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment; + currentClassLexicalEnvironment = classLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = classLexicalEnvironment; + previousOnEmitNode(hint, node, emitCallback); + currentClassLexicalEnvironment = savedClassLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = savedCurrentComputedPropertyNameClassLexicalEnvironment; + return; + } + } + + switch (node.kind) { + case SyntaxKind.FunctionExpression: + if (isArrowFunction(original) || getEmitFlags(node) & EmitFlags.AsyncFunctionBody) { + break; + } + + // falls through + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Constructor: { + const savedClassLexicalEnvironment = currentClassLexicalEnvironment; + const savedCurrentComputedPropertyNameClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment; + currentClassLexicalEnvironment = undefined; + currentComputedPropertyNameClassLexicalEnvironment = undefined; + previousOnEmitNode(hint, node, emitCallback); + currentClassLexicalEnvironment = savedClassLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = savedCurrentComputedPropertyNameClassLexicalEnvironment; + return; + } + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: { + const savedClassLexicalEnvironment = currentClassLexicalEnvironment; + const savedCurrentComputedPropertyNameClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = currentClassLexicalEnvironment; + currentClassLexicalEnvironment = undefined; + previousOnEmitNode(hint, node, emitCallback); + currentClassLexicalEnvironment = savedClassLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = savedCurrentComputedPropertyNameClassLexicalEnvironment; + return; + } + case SyntaxKind.ComputedPropertyName: { + const savedClassLexicalEnvironment = currentClassLexicalEnvironment; + const savedCurrentComputedPropertyNameClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment; + currentClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = undefined; + previousOnEmitNode(hint, node, emitCallback); + currentClassLexicalEnvironment = savedClassLexicalEnvironment; + currentComputedPropertyNameClassLexicalEnvironment = savedCurrentComputedPropertyNameClassLexicalEnvironment; + return; + } + } + previousOnEmitNode(hint, node, emitCallback); + } + /** * Hooks node substitutions. * @@ -1140,6 +1562,27 @@ namespace ts { switch (node.kind) { case SyntaxKind.Identifier: return substituteExpressionIdentifier(node as Identifier); + case SyntaxKind.ThisKeyword: + return substituteThisExpression(node as ThisExpression); + } + return node; + } + + function substituteThisExpression(node: ThisExpression) { + if (enabledSubstitutions & ClassPropertySubstitutionFlags.ClassStaticThisOrSuperReference && currentClassLexicalEnvironment) { + const { facts, classConstructor } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + return factory.createParenthesizedExpression(factory.createVoidZero()); + } + if (classConstructor) { + return setTextRange( + setOriginalNode( + factory.cloneNode(classConstructor), + node, + ), + node + ); + } } return node; } @@ -1197,24 +1640,31 @@ namespace ts { } } - function startPrivateIdentifierEnvironment() { - privateIdentifierEnvironmentStack.push(currentPrivateIdentifierEnvironment); - currentPrivateIdentifierEnvironment = undefined; + function startClassLexicalEnvironment() { + classLexicalEnvironmentStack.push(currentClassLexicalEnvironment); + currentClassLexicalEnvironment = undefined; } - function endPrivateIdentifierEnvironment() { - currentPrivateIdentifierEnvironment = privateIdentifierEnvironmentStack.pop(); + function endClassLexicalEnvironment() { + currentClassLexicalEnvironment = classLexicalEnvironmentStack.pop(); } - function getPrivateIdentifierEnvironment() { - if (!currentPrivateIdentifierEnvironment) { - currentPrivateIdentifierEnvironment = { - className: "", - identifiers: new Map() - }; - } + function getClassLexicalEnvironment() { + return currentClassLexicalEnvironment ||= { + facts: ClassFacts.None, + classConstructor: undefined, + superClassReference: undefined, + privateIdentifierEnvironment: undefined, + }; + } - return currentPrivateIdentifierEnvironment; + function getPrivateIdentifierEnvironment() { + const lex = getClassLexicalEnvironment(); + lex.privateIdentifierEnvironment ||= { + className: "", + identifiers: new Map() + }; + return lex.privateIdentifierEnvironment; } function getPendingExpressions() { @@ -1223,19 +1673,23 @@ namespace ts { function addPrivateIdentifierToEnvironment(node: PrivateClassElementDeclaration) { const text = getTextOfPropertyName(node.name) as string; - const env = getPrivateIdentifierEnvironment(); - const { weakSetName, classConstructor } = env; + const lex = getClassLexicalEnvironment(); + const { classConstructor } = lex; + + const privateEnv = getPrivateIdentifierEnvironment(); + const { weakSetName } = privateEnv; + const assignmentExpressions: Expression[] = []; const privateName = node.name.escapedText; - const previousInfo = env.identifiers.get(privateName); + const previousInfo = privateEnv.identifiers.get(privateName); const isValid = !isReservedPrivateName(node.name) && previousInfo === undefined; if (hasStaticModifier(node)) { Debug.assert(classConstructor, "weakSetName should be set in private identifier environment"); if (isPropertyDeclaration(node)) { const variableName = createHoistedVariableForPrivateName(text, node); - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Field, variableName, brandCheckIdentifier: classConstructor, @@ -1245,7 +1699,7 @@ namespace ts { } else if (isMethodDeclaration(node)) { const functionName = createHoistedVariableForPrivateName(text, node); - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Method, methodName: functionName, brandCheckIdentifier: classConstructor, @@ -1259,7 +1713,7 @@ namespace ts { previousInfo.getterName = getterName; } else { - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Accessor, getterName, setterName: undefined, @@ -1275,7 +1729,7 @@ namespace ts { previousInfo.setterName = setterName; } else { - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Accessor, getterName: undefined, setterName, @@ -1291,7 +1745,7 @@ namespace ts { } else if (isPropertyDeclaration(node)) { const weakMapName = createHoistedVariableForPrivateName(text, node); - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Field, brandCheckIdentifier: weakMapName, isStatic: false, @@ -1311,7 +1765,7 @@ namespace ts { else if (isMethodDeclaration(node)) { Debug.assert(weakSetName, "weakSetName should be set in private identifier environment"); - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Method, methodName: createHoistedVariableForPrivateName(text, node), brandCheckIdentifier: weakSetName, @@ -1329,7 +1783,7 @@ namespace ts { previousInfo.getterName = getterName; } else { - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Accessor, getterName, setterName: undefined, @@ -1346,7 +1800,7 @@ namespace ts { previousInfo.setterName = setterName; } else { - env.identifiers.set(privateName, { + privateEnv.identifiers.set(privateName, { kind: PrivateIdentifierKind.Accessor, getterName: undefined, setterName, @@ -1384,18 +1838,18 @@ namespace ts { } function accessPrivateIdentifier(name: PrivateIdentifier) { - if (currentPrivateIdentifierEnvironment) { - const info = currentPrivateIdentifierEnvironment.identifiers.get(name.escapedText); + if (currentClassLexicalEnvironment?.privateIdentifierEnvironment) { + const info = currentClassLexicalEnvironment.privateIdentifierEnvironment.identifiers.get(name.escapedText); if (info) { return info; } } - for (let i = privateIdentifierEnvironmentStack.length - 1; i >= 0; --i) { - const env = privateIdentifierEnvironmentStack[i]; + for (let i = classLexicalEnvironmentStack.length - 1; i >= 0; --i) { + const env = classLexicalEnvironmentStack[i]; if (!env) { continue; } - const info = env.identifiers.get(name.escapedText); + const info = env.privateIdentifierEnvironment?.identifiers.get(name.escapedText); if (info) { return info; } @@ -1403,7 +1857,6 @@ namespace ts { return undefined; } - function wrapPrivateIdentifierForDestructuringTarget(node: PrivateIdentifierPropertyAccessExpression) { const parameter = factory.getGeneratedNameForNode(node); const info = accessPrivateIdentifier(node.name); @@ -1415,89 +1868,134 @@ namespace ts { // differently inside the function. if (isThisProperty(node) || isSuperProperty(node) || !isSimpleCopiableExpression(node.expression)) { receiver = factory.createTempVariable(hoistVariableDeclaration, /*reservedInNestedScopes*/ true); - getPendingExpressions().push(factory.createBinaryExpression(receiver, SyntaxKind.EqualsToken, node.expression)); - } - return factory.createPropertyAccessExpression( - // Explicit parens required because of v8 regression (https://bugs.chromium.org/p/v8/issues/detail?id=9560) - factory.createParenthesizedExpression( - factory.createObjectLiteralExpression([ - factory.createSetAccessorDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - "value", - [factory.createParameterDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*dotDotDotToken*/ undefined, - parameter, - /*questionToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined - )], - factory.createBlock( - [factory.createExpressionStatement( - createPrivateIdentifierAssignment( - info, - receiver, - parameter, - SyntaxKind.EqualsToken - ) - )] - ) - ) - ]) - ), - "value" + getPendingExpressions().push(factory.createBinaryExpression(receiver, SyntaxKind.EqualsToken, visitNode(node.expression, visitor, isExpression))); + } + return factory.createAssignmentTargetWrapper( + parameter, + createPrivateIdentifierAssignment( + info, + receiver, + parameter, + SyntaxKind.EqualsToken + ) ); } function visitArrayAssignmentTarget(node: BindingOrAssignmentElement) { const target = getTargetOfBindingOrAssignmentElement(node); - if (target && isPrivateIdentifierPropertyAccessExpression(target)) { - const wrapped = wrapPrivateIdentifierForDestructuringTarget(target); - if (isAssignmentExpression(node)) { - return factory.updateBinaryExpression( - node, - wrapped, - node.operatorToken, - visitNode(node.right, visitor, isExpression) - ); + if (target) { + let wrapped: LeftHandSideExpression | undefined; + if (isPrivateIdentifierPropertyAccessExpression(target)) { + wrapped = wrapPrivateIdentifierForDestructuringTarget(target); } - else if (isSpreadElement(node)) { - return factory.updateSpreadElement(node, wrapped); + else if (shouldTransformSuperInStaticInitializers && + isSuperProperty(target) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + wrapped = visitInvalidSuperProperty(target); + } + else if (classConstructor && superClassReference) { + const name = + isElementAccessExpression(target) ? visitNode(target.argumentExpression, visitor, isExpression) : + isIdentifier(target.name) ? factory.createStringLiteralFromNode(target.name) : + undefined; + if (name) { + const temp = factory.createTempVariable(/*recordTempVariable*/ undefined); + wrapped = factory.createAssignmentTargetWrapper( + temp, + factory.createReflectSetCall( + superClassReference, + name, + temp, + classConstructor, + ) + ); + } + } } - else { - return wrapped; + if (wrapped) { + if (isAssignmentExpression(node)) { + return factory.updateBinaryExpression( + node, + wrapped, + node.operatorToken, + visitNode(node.right, visitor, isExpression) + ); + } + else if (isSpreadElement(node)) { + return factory.updateSpreadElement(node, wrapped); + } + else { + return wrapped; + } } } return visitNode(node, visitorDestructuringTarget); } function visitObjectAssignmentTarget(node: ObjectLiteralElementLike) { - if (isPropertyAssignment(node)) { + if (isObjectBindingOrAssignmentElement(node) && !isShorthandPropertyAssignment(node)) { const target = getTargetOfBindingOrAssignmentElement(node); - if (target && isPrivateIdentifierPropertyAccessExpression(target)) { + let wrapped: LeftHandSideExpression | undefined; + if (target) { + if (isPrivateIdentifierPropertyAccessExpression(target)) { + wrapped = wrapPrivateIdentifierForDestructuringTarget(target); + } + else if (shouldTransformSuperInStaticInitializers && + isSuperProperty(target) && + currentStaticPropertyDeclarationOrStaticBlock && + currentClassLexicalEnvironment) { + const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; + if (facts & ClassFacts.ClassWasDecorated) { + wrapped = visitInvalidSuperProperty(target); + } + else if (classConstructor && superClassReference) { + const name = + isElementAccessExpression(target) ? visitNode(target.argumentExpression, visitor, isExpression) : + isIdentifier(target.name) ? factory.createStringLiteralFromNode(target.name) : + undefined; + if (name) { + const temp = factory.createTempVariable(/*recordTempVariable*/ undefined); + wrapped = factory.createAssignmentTargetWrapper( + temp, + factory.createReflectSetCall( + superClassReference, + name, + temp, + classConstructor, + ) + ); + } + } + } + } + if (isPropertyAssignment(node)) { const initializer = getInitializerOfBindingOrAssignmentElement(node); - const wrapped = wrapPrivateIdentifierForDestructuringTarget(target); return factory.updatePropertyAssignment( node, - visitNode(node.name, visitor), - initializer ? factory.createAssignment(wrapped, visitNode(initializer, visitor)) : wrapped, + visitNode(node.name, visitor, isPropertyName), + wrapped ? + initializer ? factory.createAssignment(wrapped, visitNode(initializer, visitor)) : wrapped : + visitNode(node.initializer, visitorDestructuringTarget, isExpression) ); } - return factory.updatePropertyAssignment( - node, - visitNode(node.name, visitor), - visitNode(node.initializer, visitorDestructuringTarget) - ); + if (isSpreadAssignment(node)) { + return factory.updateSpreadAssignment( + node, + wrapped || visitNode(node.expression, visitorDestructuringTarget, isExpression) + ); + } + Debug.assert(wrapped === undefined, "Should not have generated a wrapped target"); } return visitNode(node, visitor); } - function visitAssignmentPattern(node: AssignmentPattern) { if (isArrayLiteralExpression(node)) { // Transforms private names in destructuring assignment array bindings. + // Transforms SuperProperty assignments in destructuring assignment array bindings in static initializers. // // Source: // ([ this.#myProp ] = [ "hello" ]); @@ -1511,6 +2009,7 @@ namespace ts { } else { // Transforms private names in destructuring assignment object bindings. + // Transforms SuperProperty assignments in destructuring assignment object bindings in static initializers. // // Source: // ({ stringProperty: this.#myProp } = { stringProperty: "hello" }); diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 7be27b453a0d2..81b00987efdd8 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -75,7 +75,7 @@ namespace ts { } function getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { - if (hasSyntacticModifier(node, ModifierFlags.Static)) { + if (isStatic(node)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -106,7 +106,7 @@ namespace ts { } function getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) { - if (hasSyntacticModifier(node, ModifierFlags.Static)) { + if (isStatic(node)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -173,7 +173,7 @@ namespace ts { else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertyAccessExpression || node.kind === SyntaxKind.PropertySignature || (node.kind === SyntaxKind.Parameter && hasSyntacticModifier(node.parent, ModifierFlags.Private))) { // TODO(jfreeman): Deal with computed properties in error reporting. - if (hasSyntacticModifier(node, ModifierFlags.Static)) { + if (isStatic(node)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -210,7 +210,7 @@ namespace ts { if (node.kind === SyntaxKind.SetAccessor) { // Getters can infer the return type from the returned expression, but setters cannot, so the // "_from_external_module_1_but_cannot_be_named" case cannot occur. - if (hasSyntacticModifier(node, ModifierFlags.Static)) { + if (isStatic(node)) { diagnosticMessage = symbolAccessibilityResult.errorModuleName ? Diagnostics.Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_private_name_1; @@ -222,7 +222,7 @@ namespace ts { } } else { - if (hasSyntacticModifier(node, ModifierFlags.Static)) { + if (isStatic(node)) { diagnosticMessage = symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -270,7 +270,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasSyntacticModifier(node, ModifierFlags.Static)) { + if (isStatic(node)) { diagnosticMessage = symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : @@ -349,7 +349,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasSyntacticModifier(node.parent, ModifierFlags.Static)) { + if (isStatic(node.parent)) { return symbolAccessibilityResult.errorModuleName ? symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : @@ -417,7 +417,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - if (hasSyntacticModifier(node.parent, ModifierFlags.Static)) { + if (isStatic(node.parent)) { diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index a4baf4ae27458..52963c530ab77 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -169,6 +169,8 @@ namespace ts { ForStatement = 1 << 11, // Enclosing block-scoped container is a ForStatement ForInOrForOfStatement = 1 << 12, // Enclosing block-scoped container is a ForInStatement or ForOfStatement ConstructorWithCapturedSuper = 1 << 13, // Enclosed in a constructor that captures 'this' for use with 'super' + StaticInitializer = 1 << 14, // Enclosed in a static initializer + // NOTE: do not add more ancestor flags without also updating AncestorFactsMask below. // NOTE: when adding a new ancestor flag, be sure to update the subtree flags below. @@ -176,7 +178,7 @@ namespace ts { // Ancestor masks // - AncestorFactsMask = (ConstructorWithCapturedSuper << 1) - 1, + AncestorFactsMask = (StaticInitializer << 1) - 1, // We are always in *some* kind of block scope, but only specific block-scope containers are // top-level or Blocks. @@ -189,7 +191,7 @@ namespace ts { // Functions, methods, and accessors are both new lexical scopes and new block scopes. FunctionIncludes = Function | TopLevel, - FunctionExcludes = BlockScopeExcludes & ~TopLevel | ArrowFunction | AsyncFunctionBody | CapturesThis | NonStaticClassElement | ConstructorWithCapturedSuper | IterationContainer, + FunctionExcludes = BlockScopeExcludes & ~TopLevel | ArrowFunction | AsyncFunctionBody | CapturesThis | NonStaticClassElement | ConstructorWithCapturedSuper | IterationContainer | StaticInitializer, AsyncFunctionBodyIncludes = FunctionIncludes | AsyncFunctionBody, AsyncFunctionBodyExcludes = FunctionExcludes & ~NonStaticClassElement, @@ -225,12 +227,15 @@ namespace ts { IterationStatementBlockIncludes = IterationStatementBlock, IterationStatementBlockExcludes = BlockScopeExcludes, + StaticInitializerIncludes = FunctionIncludes | StaticInitializer, + StaticInitializerExcludes = FunctionExcludes, + // // Subtree facts // - NewTarget = 1 << 14, // Contains a 'new.target' meta-property - CapturedLexicalThis = 1 << 15, // Contains a lexical `this` reference captured by an arrow function. + NewTarget = 1 << 15, // Contains a 'new.target' meta-property + CapturedLexicalThis = 1 << 16, // Contains a lexical `this` reference captured by an arrow function. // // Subtree masks @@ -377,6 +382,23 @@ namespace ts { return shouldVisitNode(node) ? visitorWorker(node, /*expressionResultIsUnused*/ true) : node; } + function classWrapperStatementVisitor(node: Node): VisitResult { + if (shouldVisitNode(node)) { + const original = getOriginalNode(node); + if (isPropertyDeclaration(original) && hasStaticModifier(original)) { + const ancestorFacts = enterSubtree( + HierarchyFacts.StaticInitializerExcludes, + HierarchyFacts.StaticInitializerIncludes + ); + const result = visitorWorker(node, /*expressionResultIsUnused*/ false); + exitSubtree(ancestorFacts, HierarchyFacts.FunctionSubtreeExcludes, HierarchyFacts.None); + return result; + } + return visitorWorker(node, /*expressionResultIsUnused*/ false); + } + return node; + } + function callExpressionVisitor(node: Node): VisitResult { if (node.kind === SyntaxKind.SuperKeyword) { return visitSuperKeyword(/*isExpressionOfCall*/ true); @@ -602,7 +624,7 @@ namespace ts { } function visitThisKeyword(node: Node): Node { - if (hierarchyFacts & HierarchyFacts.ArrowFunction) { + if (hierarchyFacts & HierarchyFacts.ArrowFunction && !(hierarchyFacts & HierarchyFacts.StaticInitializer)) { hierarchyFacts |= HierarchyFacts.CapturedLexicalThis; } if (convertedLoopState) { @@ -1750,7 +1772,7 @@ namespace ts { * @param node An ArrowFunction node. */ function visitArrowFunction(node: ArrowFunction) { - if (node.transformFlags & TransformFlags.ContainsLexicalThis) { + if (node.transformFlags & TransformFlags.ContainsLexicalThis && !(hierarchyFacts & HierarchyFacts.StaticInitializer)) { hierarchyFacts |= HierarchyFacts.CapturedLexicalThis; } @@ -1770,10 +1792,6 @@ namespace ts { setOriginalNode(func, node); setEmitFlags(func, EmitFlags.CapturesThis); - if (hierarchyFacts & HierarchyFacts.CapturedLexicalThis) { - enableSubstitutionsForCapturedThis(); - } - // If an arrow function contains exitSubtree(ancestorFacts, HierarchyFacts.ArrowFunctionSubtreeExcludes, HierarchyFacts.None); @@ -1853,7 +1871,7 @@ namespace ts { function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: TextRange | undefined, name: Identifier | undefined, container: Node | undefined): FunctionExpression { const savedConvertedLoopState = convertedLoopState; convertedLoopState = undefined; - const ancestorFacts = container && isClassLike(container) && !hasSyntacticModifier(node, ModifierFlags.Static) + const ancestorFacts = container && isClassLike(container) && !isStatic(node) ? enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes | HierarchyFacts.NonStaticClassElement) : enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes); const parameters = visitParameterList(node.parameters, visitor, context); @@ -3688,7 +3706,7 @@ namespace ts { // visit the class body statements outside of any converted loop body. const savedConvertedLoopState = convertedLoopState; convertedLoopState = undefined; - const bodyStatements = visitNodes(body.statements, visitor, isStatement); + const bodyStatements = visitNodes(body.statements, classWrapperStatementVisitor, isStatement); convertedLoopState = savedConvertedLoopState; const classStatements = filter(bodyStatements, isVariableStatementWithInitializer); @@ -3715,7 +3733,10 @@ namespace ts { // return C; // }()) // - const aliasAssignment = tryCast(initializer, isAssignmentExpression); + let aliasAssignment = tryCast(initializer, isAssignmentExpression); + if (!aliasAssignment && isBinaryExpression(initializer) && initializer.operatorToken.kind === SyntaxKind.CommaToken) { + aliasAssignment = tryCast(initializer.left, isAssignmentExpression); + } // The underlying call (3) is another IIFE that may contain a '_super' argument. const call = cast(aliasAssignment ? skipOuterExpressions(aliasAssignment.right) : initializer, isCallExpression); @@ -4358,7 +4379,7 @@ namespace ts { } function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { - return hasSyntacticModifier(member, ModifierFlags.Static) + return isStatic(member) ? factory.getInternalName(node) : factory.createPropertyAccessExpression(factory.getInternalName(node), "prototype"); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index ff416451eb72e..aa677c911b874 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -945,7 +945,7 @@ namespace ts { * @param member The class member. */ function isStaticDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { - return isDecoratedClassElement(member, /*isStatic*/ true, parent); + return isDecoratedClassElement(member, /*isStaticElement*/ true, parent); } /** @@ -955,7 +955,7 @@ namespace ts { * @param member The class member. */ function isInstanceDecoratedClassElement(member: ClassElement, parent: ClassLikeDeclaration) { - return isDecoratedClassElement(member, /*isStatic*/ false, parent); + return isDecoratedClassElement(member, /*isStaticElement*/ false, parent); } /** @@ -964,9 +964,9 @@ namespace ts { * * @param member The class member. */ - function isDecoratedClassElement(member: ClassElement, isStatic: boolean, parent: ClassLikeDeclaration) { + function isDecoratedClassElement(member: ClassElement, isStaticElement: boolean, parent: ClassLikeDeclaration) { return nodeOrChildIsDecorated(member, parent) - && isStatic === hasSyntacticModifier(member, ModifierFlags.Static); + && isStaticElement === isStatic(member); } /** @@ -3158,7 +3158,7 @@ namespace ts { } function getClassMemberPrefix(node: ClassExpression | ClassDeclaration, member: ClassElement) { - return hasSyntacticModifier(member, ModifierFlags.Static) + return isStatic(member) ? factory.getDeclarationName(node) : getClassPrototype(node); } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index b899cf0991ea4..276d034c7b92c 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -385,6 +385,6 @@ namespace ts { * @param member The class element node. */ export function isNonStaticMethodOrAccessorWithPrivateName(member: ClassElement): member is PrivateIdentifierMethodDeclaration | PrivateIdentifierAccessorDeclaration { - return !hasStaticModifier(member) && isMethodOrAccessor(member) && isPrivateIdentifier(member.name); + return !isStatic(member) && isMethodOrAccessor(member) && isPrivateIdentifier(member.name); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4531871cecb15..7c0133676e00a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1543,6 +1543,8 @@ namespace ts { readonly body: Block; /* @internal */ readonly decorators?: NodeArray; // Present for use with reporting a grammar error /* @internal */ readonly modifier?: ModifiersArray; // Present for use with reporting a grammar error + /* @internal */ endFlowNode?: FlowNode; + /* @internal */ returnFlowNode?: FlowNode; } export interface TypeNode extends Node { @@ -6632,7 +6634,7 @@ namespace ts { ContainsDynamicImport = 1 << 22, ContainsClassFields = 1 << 23, ContainsPossibleTopLevelAwait = 1 << 24, - + ContainsLexicalSuper = 1 << 25, // Please leave this as 1 << 29. // It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system. // It is a good reminder of how much room we have left @@ -6660,12 +6662,12 @@ namespace ts { PropertyAccessExcludes = OuterExpressionExcludes, NodeExcludes = PropertyAccessExcludes, ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, - FunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, - ConstructorExcludes = NodeExcludes | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, - MethodOrAccessorExcludes = NodeExcludes | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread, - PropertyExcludes = NodeExcludes | ContainsLexicalThis, + FunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsLexicalSuper | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, + ConstructorExcludes = NodeExcludes | ContainsLexicalThis | ContainsLexicalSuper | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, + MethodOrAccessorExcludes = NodeExcludes | ContainsLexicalThis | ContainsLexicalSuper | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread, + PropertyExcludes = NodeExcludes | ContainsLexicalThis | ContainsLexicalSuper, ClassExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsComputedPropertyName, - ModuleExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion | ContainsPossibleTopLevelAwait, + ModuleExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsLexicalSuper | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion | ContainsPossibleTopLevelAwait, TypeExcludes = ~ContainsTypeScript, ObjectLiteralExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsComputedPropertyName | ContainsObjectRestOrSpread, ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsRestOrSpread, @@ -6673,10 +6675,11 @@ namespace ts { ParameterExcludes = NodeExcludes, CatchClauseExcludes = NodeExcludes | ContainsObjectRestOrSpread, BindingPatternExcludes = NodeExcludes | ContainsRestOrSpread, + ContainsLexicalThisOrSuper = ContainsLexicalThis | ContainsLexicalSuper, // Propagating flags // - Bitmasks for flags that should propagate from a child - PropertyNamePropagatingFlags = ContainsLexicalThis, + PropertyNamePropagatingFlags = ContainsLexicalThis | ContainsLexicalSuper, // Masks // - Additional bitmasks @@ -7548,10 +7551,28 @@ namespace ts { /* @internal */ createFunctionCallCall(target: Expression, thisArg: Expression, argumentsList: readonly Expression[]): CallExpression; /* @internal */ createFunctionApplyCall(target: Expression, thisArg: Expression, argumentsExpression: Expression): CallExpression; /* @internal */ createObjectDefinePropertyCall(target: Expression, propertyName: string | Expression, attributes: Expression): CallExpression; + /* @internal */ createReflectGetCall(target: Expression, propertyKey: Expression, receiver?: Expression): CallExpression; + /* @internal */ createReflectSetCall(target: Expression, propertyKey: Expression, value: Expression, receiver?: Expression): CallExpression; /* @internal */ createPropertyDescriptor(attributes: PropertyDescriptorAttributes, singleLine?: boolean): ObjectLiteralExpression; /* @internal */ createArraySliceCall(array: Expression, start?: number | Expression): CallExpression; /* @internal */ createArrayConcatCall(array: Expression, values: readonly Expression[]): CallExpression; /* @internal */ createCallBinding(expression: Expression, recordTempVariable: (temp: Identifier) => void, languageVersion?: ScriptTarget, cacheIdentifiers?: boolean): CallBinding; + /** + * Wraps an expression that cannot be an assignment target in an expression that can be. + * + * Given a `paramName` of `_a`: + * ``` + * Reflect.set(obj, "x", _a) + * ``` + * Becomes + * ```ts + * ({ set value(_a) { Reflect.set(obj, "x", _a); } }).value + * ``` + * + * @param paramName + * @param expression + */ + /* @internal */ createAssignmentTargetWrapper(paramName: Identifier, expression: Expression): LeftHandSideExpression; /* @internal */ inlineExpressions(expressions: readonly Expression[]): Expression; /** * Gets the internal name of a declaration. This is primarily used for declarations that can be diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9a1fb530a64c1..479e7cabb0d81 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1706,6 +1706,7 @@ namespace ts { case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: + case SyntaxKind.ClassStaticBlockDeclaration: return node; case SyntaxKind.Decorator: // Decorators are always applied outside of the body of a class or method. @@ -4400,7 +4401,7 @@ namespace ts { else { forEach(declarations, member => { if (isAccessor(member) - && hasSyntacticModifier(member, ModifierFlags.Static) === hasSyntacticModifier(accessor, ModifierFlags.Static)) { + && isStatic(member) === isStatic(accessor)) { const memberName = getPropertyNameForPropertyNameNode(member.name); const accessorName = getPropertyNameForPropertyNameNode(accessor.name); if (memberName === accessorName) { @@ -4711,6 +4712,11 @@ namespace ts { return !!getSelectedSyntacticModifierFlags(node, flags); } + export function isStatic(node: Node) { + // https://tc39.es/ecma262/#sec-static-semantics-isstatic + return isClassElement(node) && hasStaticModifier(node) || isClassStaticBlockDeclaration(node); + } + export function hasStaticModifier(node: Node): boolean { return hasSyntacticModifier(node, ModifierFlags.Static); } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index ba026e80e52df..b9236521cba67 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1425,6 +1425,18 @@ namespace ts { return false; } + /* @internal */ + export function isObjectBindingOrAssignmentElement(node: Node): node is ObjectBindingOrAssignmentElement { + switch (node.kind) { + case SyntaxKind.BindingElement: + case SyntaxKind.PropertyAssignment: // AssignmentProperty + case SyntaxKind.ShorthandPropertyAssignment: // AssignmentProperty + case SyntaxKind.SpreadAssignment: // AssignmentRestProperty + return true; + } + return false; + } + /** * Determines whether a node is an ArrayBindingOrAssignmentPattern */ diff --git a/src/services/completions.ts b/src/services/completions.ts index ca907646f0afa..98701ec193fd3 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2173,6 +2173,9 @@ namespace ts.Completions { break; } } + if (isClassStaticBlockDeclaration(classElement)) { + classElementModifierFlags |= ModifierFlags.Static; + } // No member list for private methods if (!(classElementModifierFlags & ModifierFlags.Private)) { @@ -2626,7 +2629,7 @@ namespace ts.Completions { } // do not filter it out if the static presence doesnt match - if (hasEffectiveModifier(m, ModifierFlags.Static) !== !!(currentClassElementModifierFlags & ModifierFlags.Static)) { + if (isStatic(m) !== !!(currentClassElementModifierFlags & ModifierFlags.Static)) { continue; } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 8422fbe09c8da..45308754a66dd 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1684,7 +1684,7 @@ namespace ts.FindAllReferences { Debug.assert(classLike.name === referenceLocation); const addRef = state.referenceAdder(search.symbol); for (const member of classLike.members) { - if (!(isMethodOrAccessor(member) && hasSyntacticModifier(member, ModifierFlags.Static))) { + if (!(isMethodOrAccessor(member) && isStatic(member))) { continue; } if (member.body) { @@ -1917,7 +1917,7 @@ namespace ts.FindAllReferences { // If we have a 'super' container, we must have an enclosing class. // Now make sure the owning class is the same as the search-space // and has the same static qualifier as the original 'super's owner. - return container && (ModifierFlags.Static & getSyntacticModifierFlags(container)) === staticFlag && container.parent.symbol === searchSpaceNode.symbol ? nodeEntry(node) : undefined; + return container && isStatic(container) === !!staticFlag && container.parent.symbol === searchSpaceNode.symbol ? nodeEntry(node) : undefined; }); return [{ definition: { type: DefinitionKind.Symbol, symbol: searchSpaceNode.symbol }, references }]; @@ -1983,7 +1983,7 @@ namespace ts.FindAllReferences { case SyntaxKind.ObjectLiteralExpression: // Make sure the container belongs to the same class/object literals // and has the appropriate static modifier from the original container. - return container.parent && searchSpaceNode.symbol === container.parent.symbol && (getSyntacticModifierFlags(container) & ModifierFlags.Static) === staticFlag; + return container.parent && searchSpaceNode.symbol === container.parent.symbol && isStatic(container) === !!staticFlag; case SyntaxKind.SourceFile: return container.kind === SyntaxKind.SourceFile && !isExternalModule(container as SourceFile) && !isParameterName(node); } @@ -2030,7 +2030,7 @@ namespace ts.FindAllReferences { (sym, root, base) => { // static method/property and instance method/property might have the same name. Only include static or only include instance. if (base) { - if (isStatic(symbol) !== isStatic(base)) { + if (isStaticSymbol(symbol) !== isStaticSymbol(base)) { base = undefined; } } @@ -2196,7 +2196,7 @@ namespace ts.FindAllReferences { readonly kind: NodeEntryKind | undefined; } - function isStatic(symbol: Symbol): boolean { + function isStaticSymbol(symbol: Symbol): boolean { if (!symbol.valueDeclaration) { return false; } const modifierFlags = getEffectiveModifierFlags(symbol.valueDeclaration); return !!(modifierFlags & ModifierFlags.Static); @@ -2210,7 +2210,7 @@ namespace ts.FindAllReferences { // check whether the symbol used to search itself is just the searched one. if (baseSymbol) { // static method/property and instance method/property might have the same name. Only check static or only check instance. - if (isStatic(referenceSymbol) !== isStatic(baseSymbol)) { + if (isStaticSymbol(referenceSymbol) !== isStaticSymbol(baseSymbol)) { baseSymbol = undefined; } } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index ab315d3eb2d34..6f9cdd55950c3 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -627,7 +627,7 @@ namespace ts.NavigationBar { case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return hasSyntacticModifier(a, ModifierFlags.Static) === hasSyntacticModifier(b, ModifierFlags.Static); + return isStatic(a) === isStatic(b); case SyntaxKind.ModuleDeclaration: return areSameModule(a as ModuleDeclaration, b as ModuleDeclaration) && getFullyQualifiedModuleName(a as ModuleDeclaration) === getFullyQualifiedModuleName(b as ModuleDeclaration); diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index ebf72aa7589d3..7c5e881ce5537 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -398,7 +398,7 @@ namespace ts.refactor.extractSymbol { let current: Node = nodeToCheck; while (current !== containingClass) { if (current.kind === SyntaxKind.PropertyDeclaration) { - if (hasSyntacticModifier(current, ModifierFlags.Static)) { + if (isStatic(current)) { rangeFacts |= RangeFacts.InStaticRegion; } break; @@ -411,7 +411,7 @@ namespace ts.refactor.extractSymbol { break; } else if (current.kind === SyntaxKind.MethodDeclaration) { - if (hasSyntacticModifier(current, ModifierFlags.Static)) { + if (isStatic(current)) { rangeFacts |= RangeFacts.InStaticRegion; } } diff --git a/tests/baselines/reference/asyncArrowInClassES5.js b/tests/baselines/reference/asyncArrowInClassES5.js index f0204f7319bda..08d9e0fe46e3d 100644 --- a/tests/baselines/reference/asyncArrowInClassES5.js +++ b/tests/baselines/reference/asyncArrowInClassES5.js @@ -10,11 +10,12 @@ class Test { //// [asyncArrowInClassES5.js] // https://github.com/Microsoft/TypeScript/issues/16924 // Should capture `this` -var _this = this; var Test = /** @class */ (function () { function Test() { } - Test.member = function (x) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { + var _a; + _a = Test; + Test.member = function (x) { return __awaiter(_a, void 0, void 0, function () { return __generator(_a, function (_b) { return [2 /*return*/]; }); }); }; return Test; diff --git a/tests/baselines/reference/classStaticBlock4.errors.txt b/tests/baselines/reference/classStaticBlock4.errors.txt index 4bd2b377e0b97..d4ec1db72f646 100644 --- a/tests/baselines/reference/classStaticBlock4.errors.txt +++ b/tests/baselines/reference/classStaticBlock4.errors.txt @@ -1,22 +1,16 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,9): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2729: Property 's2' is used before its initialization. tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(9,11): error TS2729: Property 's2' is used before its initialization. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (4 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (2 errors) ==== class C { static s1 = 1; static { this.s1; - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. C.s1; this.s2; - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. ~~ !!! error TS2729: Property 's2' is used before its initialization. !!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts:12:12: 's2' is declared here. diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt deleted file mode 100644 index 71227c6036a79..0000000000000 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(8,16): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(11,9): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(12,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts (4 errors) ==== - class B { - static a = 1; - static b = 2; - } - - class C extends B { - static b = 3; - static c = super.a - ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. - - static { - this.b; - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - super.b; - ~~~~~ -!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. - super.a; - ~~~~~ -!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).js b/tests/baselines/reference/classStaticBlock5(target=es2015).js index 557bf8b05b4ec..ef2d9f44234ff 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).js @@ -17,16 +17,18 @@ class C extends B { //// [classStaticBlock5.js] +var _a, _b; class B { } B.a = 1; B.b = 2; -class C extends B { +class C extends (_b = B) { } +_a = C; C.b = 3; -C.c = super.a; +C.c = Reflect.get(_b, "a", _a); (() => { - this.b; - super.b; - super.a; + _a.b; + Reflect.get(_b, "b", _a); + Reflect.get(_b, "a", _a); })(); diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).symbols b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols index 1e2334d1dff10..4559a1eaaf287 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).symbols +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols @@ -18,6 +18,9 @@ class C extends B { static c = super.a >c : Symbol(C.c, Decl(classStaticBlock5.ts, 6, 17)) +>super.a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) static { this.b; @@ -26,7 +29,14 @@ class C extends B { >b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) super.b; +>super.b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) + super.a; +>super.a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) } } diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).types b/tests/baselines/reference/classStaticBlock5(target=es2015).types index beb56840bfc1c..8aebace4d70e3 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).types +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).types @@ -20,10 +20,10 @@ class C extends B { >3 : 3 static c = super.a ->c : any ->super.a : any ->super : any ->a : any +>c : number +>super.a : number +>super : typeof B +>a : number static { this.b; @@ -32,14 +32,14 @@ class C extends B { >b : number super.b; ->super.b : any ->super : any ->b : any +>super.b : number +>super : typeof B +>b : number super.a; ->super.a : any ->super : any ->a : any +>super.a : number +>super : typeof B +>a : number } } diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt index 71227c6036a79..18ca200f7ceb4 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt +++ b/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt @@ -1,10 +1,9 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(8,16): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(11,9): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(12,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(8,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(12,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts (4 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts (3 errors) ==== class B { static a = 1; static b = 2; @@ -13,19 +12,17 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): err class C extends B { static b = 3; static c = super.a - ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. static { this.b; - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. super.b; - ~~~~~ -!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. super.a; - ~~~~~ -!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. } } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).js b/tests/baselines/reference/classStaticBlock5(target=es5).js index 0b26d0f4dcd1e..db5b10ebd4ca3 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).js +++ b/tests/baselines/reference/classStaticBlock5(target=es5).js @@ -45,10 +45,12 @@ var C = /** @class */ (function (_super) { function C() { return _super !== null && _super.apply(this, arguments) || this; } + var _a; + _a = C; C.b = 3; C.c = _super.a; (function () { - _this.b; + _a.b; _super.b; _super.a; })(); diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).symbols b/tests/baselines/reference/classStaticBlock5(target=es5).symbols index 1e2334d1dff10..4559a1eaaf287 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).symbols +++ b/tests/baselines/reference/classStaticBlock5(target=es5).symbols @@ -18,6 +18,9 @@ class C extends B { static c = super.a >c : Symbol(C.c, Decl(classStaticBlock5.ts, 6, 17)) +>super.a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) static { this.b; @@ -26,7 +29,14 @@ class C extends B { >b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) super.b; +>super.b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) + super.a; +>super.a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) } } diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).types b/tests/baselines/reference/classStaticBlock5(target=es5).types index beb56840bfc1c..8aebace4d70e3 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).types +++ b/tests/baselines/reference/classStaticBlock5(target=es5).types @@ -20,10 +20,10 @@ class C extends B { >3 : 3 static c = super.a ->c : any ->super.a : any ->super : any ->a : any +>c : number +>super.a : number +>super : typeof B +>a : number static { this.b; @@ -32,14 +32,14 @@ class C extends B { >b : number super.b; ->super.b : any ->super : any ->b : any +>super.b : number +>super : typeof B +>b : number super.a; ->super.a : any ->super : any ->a : any +>super.a : number +>super : typeof B +>a : number } } diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt deleted file mode 100644 index 71227c6036a79..0000000000000 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(8,16): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(11,9): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(12,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts (4 errors) ==== - class B { - static a = 1; - static b = 2; - } - - class C extends B { - static b = 3; - static c = super.a - ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. - - static { - this.b; - ~~~~ -!!! error TS2332: 'this' cannot be referenced in current location. - super.b; - ~~~~~ -!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. - super.a; - ~~~~~ -!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).symbols b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols index 1e2334d1dff10..4559a1eaaf287 100644 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).symbols +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols @@ -18,6 +18,9 @@ class C extends B { static c = super.a >c : Symbol(C.c, Decl(classStaticBlock5.ts, 6, 17)) +>super.a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) static { this.b; @@ -26,7 +29,14 @@ class C extends B { >b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) super.b; +>super.b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) + super.a; +>super.a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) +>super : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) } } diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).types b/tests/baselines/reference/classStaticBlock5(target=esnext).types index beb56840bfc1c..8aebace4d70e3 100644 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).types +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).types @@ -20,10 +20,10 @@ class C extends B { >3 : 3 static c = super.a ->c : any ->super.a : any ->super : any ->a : any +>c : number +>super.a : number +>super : typeof B +>a : number static { this.b; @@ -32,14 +32,14 @@ class C extends B { >b : number super.b; ->super.b : any ->super : any ->b : any +>super.b : number +>super : typeof B +>b : number super.a; ->super.a : any ->super : any ->a : any +>super.a : number +>super : typeof B +>a : number } } diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 95e69c743769c..82f056d5b8423 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -6,7 +6,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): err tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,14): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(19,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(32,17): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(32,17): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(41,13): error TS2815: 'arguments' cannot be referenced in property initializers. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(42,13): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(42,18): error TS1109: Expression expected. @@ -65,7 +65,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(55,13): er } super(); ~~~~~ -!!! error TS2335: 'super' can only be referenced in a derived class. +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. } } } diff --git a/tests/baselines/reference/classStaticBlockUseBeforeDef1.symbols b/tests/baselines/reference/classStaticBlockUseBeforeDef1.symbols new file mode 100644 index 0000000000000..3a432e830e4b1 --- /dev/null +++ b/tests/baselines/reference/classStaticBlockUseBeforeDef1.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef1.ts === +class C { +>C : Symbol(C, Decl(classStaticBlockUseBeforeDef1.ts, 0, 0)) + + static x; +>x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef1.ts, 0, 9)) + + static { + this.x = 1; +>this.x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef1.ts, 0, 9)) +>this : Symbol(C, Decl(classStaticBlockUseBeforeDef1.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef1.ts, 0, 9)) + } + static y = this.x; +>y : Symbol(C.y, Decl(classStaticBlockUseBeforeDef1.ts, 4, 5)) +>this.x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef1.ts, 0, 9)) +>this : Symbol(C, Decl(classStaticBlockUseBeforeDef1.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef1.ts, 0, 9)) + + static z; +>z : Symbol(C.z, Decl(classStaticBlockUseBeforeDef1.ts, 5, 22)) + + static { + this.z = this.y; +>this.z : Symbol(C.z, Decl(classStaticBlockUseBeforeDef1.ts, 5, 22)) +>this : Symbol(C, Decl(classStaticBlockUseBeforeDef1.ts, 0, 0)) +>z : Symbol(C.z, Decl(classStaticBlockUseBeforeDef1.ts, 5, 22)) +>this.y : Symbol(C.y, Decl(classStaticBlockUseBeforeDef1.ts, 4, 5)) +>this : Symbol(C, Decl(classStaticBlockUseBeforeDef1.ts, 0, 0)) +>y : Symbol(C.y, Decl(classStaticBlockUseBeforeDef1.ts, 4, 5)) + } +} diff --git a/tests/baselines/reference/classStaticBlockUseBeforeDef1.types b/tests/baselines/reference/classStaticBlockUseBeforeDef1.types new file mode 100644 index 0000000000000..084534b0a169f --- /dev/null +++ b/tests/baselines/reference/classStaticBlockUseBeforeDef1.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef1.ts === +class C { +>C : C + + static x; +>x : number + + static { + this.x = 1; +>this.x = 1 : 1 +>this.x : number +>this : typeof C +>x : number +>1 : 1 + } + static y = this.x; +>y : number +>this.x : number +>this : typeof C +>x : number + + static z; +>z : number + + static { + this.z = this.y; +>this.z = this.y : number +>this.z : number +>this : typeof C +>z : number +>this.y : number +>this : typeof C +>y : number + } +} diff --git a/tests/baselines/reference/classStaticBlockUseBeforeDef2.errors.txt b/tests/baselines/reference/classStaticBlockUseBeforeDef2.errors.txt new file mode 100644 index 0000000000000..ca13946d6230a --- /dev/null +++ b/tests/baselines/reference/classStaticBlockUseBeforeDef2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts(3,14): error TS2729: Property 'x' is used before its initialization. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts (1 errors) ==== + class C { + static { + this.x = 1; + ~ +!!! error TS2729: Property 'x' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts:5:12: 'x' is declared here. + } + static x; + } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlockUseBeforeDef2.symbols b/tests/baselines/reference/classStaticBlockUseBeforeDef2.symbols new file mode 100644 index 0000000000000..69716958faa82 --- /dev/null +++ b/tests/baselines/reference/classStaticBlockUseBeforeDef2.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts === +class C { +>C : Symbol(C, Decl(classStaticBlockUseBeforeDef2.ts, 0, 0)) + + static { + this.x = 1; +>this.x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef2.ts, 3, 5)) +>this : Symbol(C, Decl(classStaticBlockUseBeforeDef2.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef2.ts, 3, 5)) + } + static x; +>x : Symbol(C.x, Decl(classStaticBlockUseBeforeDef2.ts, 3, 5)) +} diff --git a/tests/baselines/reference/classStaticBlockUseBeforeDef2.types b/tests/baselines/reference/classStaticBlockUseBeforeDef2.types new file mode 100644 index 0000000000000..660b09c8d25b1 --- /dev/null +++ b/tests/baselines/reference/classStaticBlockUseBeforeDef2.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts === +class C { +>C : C + + static { + this.x = 1; +>this.x = 1 : 1 +>this.x : number +>this : typeof C +>x : number +>1 : 1 + } + static x; +>x : number +} diff --git a/tests/baselines/reference/inferringClassMembersFromAssignments.errors.txt b/tests/baselines/reference/inferringClassMembersFromAssignments.errors.txt index 379d3f018c2c1..44ab30d997aae 100644 --- a/tests/baselines/reference/inferringClassMembersFromAssignments.errors.txt +++ b/tests/baselines/reference/inferringClassMembersFromAssignments.errors.txt @@ -1,11 +1,9 @@ tests/cases/conformance/salsa/a.js(14,13): error TS7008: Member 'inMethodNullable' implicitly has an 'any' type. tests/cases/conformance/salsa/a.js(20,9): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/conformance/salsa/a.js(39,9): error TS2322: Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/salsa/a.js(93,13): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/salsa/a.js(96,13): error TS2334: 'this' cannot be referenced in a static property initializer. -==== tests/cases/conformance/salsa/a.js (5 errors) ==== +==== tests/cases/conformance/salsa/a.js (3 errors) ==== class C { constructor() { if (Math.random()) { @@ -105,13 +103,9 @@ tests/cases/conformance/salsa/a.js(96,13): error TS2334: 'this' cannot be refere static prop = () => { if (Math.random()) { this.inStaticPropertyDeclaration = 0; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. } else { this.inStaticPropertyDeclaration = "string" - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. } } } diff --git a/tests/baselines/reference/inferringClassMembersFromAssignments.js b/tests/baselines/reference/inferringClassMembersFromAssignments.js index e8d25a917dd47..b3830e6f2c7eb 100644 --- a/tests/baselines/reference/inferringClassMembersFromAssignments.js +++ b/tests/baselines/reference/inferringClassMembersFromAssignments.js @@ -133,7 +133,6 @@ var stringOrNumberOrUndefined = C.inStaticNestedArrowFunction; //// [output.js] -var _this = this; var C = /** @class */ (function () { function C() { var _this = this; @@ -225,12 +224,14 @@ var C = /** @class */ (function () { this.inStaticSetter = "string"; } }; + var _a; + _a = C; C.prop = function () { if (Math.random()) { - _this.inStaticPropertyDeclaration = 0; + _a.inStaticPropertyDeclaration = 0; } else { - _this.inStaticPropertyDeclaration = "string"; + _a.inStaticPropertyDeclaration = "string"; } }; return C; diff --git a/tests/baselines/reference/privateNameFieldUnaryMutation.js b/tests/baselines/reference/privateNameFieldUnaryMutation.js index 5ff58fdd5d68a..8d16a10861b38 100644 --- a/tests/baselines/reference/privateNameFieldUnaryMutation.js +++ b/tests/baselines/reference/privateNameFieldUnaryMutation.js @@ -44,31 +44,31 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function ( var _C_test; class C { constructor() { - var _a, _b; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; _C_test.set(this, 24); - __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f"); - __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") - 1, "f"); - __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f"); - __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") - 1, "f"); - const a = (__classPrivateFieldSet(this, _C_test, (_a = +__classPrivateFieldGet(this, _C_test, "f")) + 1, "f"), _a); - const b = (__classPrivateFieldSet(this, _C_test, (_b = +__classPrivateFieldGet(this, _C_test, "f")) - 1, "f"), _b); - const c = __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f"); - const d = __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") - 1, "f"); - for (__classPrivateFieldSet(this, _C_test, 0, "f"); __classPrivateFieldGet(this, _C_test, "f") < 10; __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f")) { } - for (__classPrivateFieldSet(this, _C_test, 0, "f"); __classPrivateFieldGet(this, _C_test, "f") < 10; __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f")) { } + __classPrivateFieldSet(this, _C_test, (_a = __classPrivateFieldGet(this, _C_test, "f"), _a++, _a), "f"); + __classPrivateFieldSet(this, _C_test, (_b = __classPrivateFieldGet(this, _C_test, "f"), _b--, _b), "f"); + __classPrivateFieldSet(this, _C_test, (_c = __classPrivateFieldGet(this, _C_test, "f"), ++_c), "f"); + __classPrivateFieldSet(this, _C_test, (_d = __classPrivateFieldGet(this, _C_test, "f"), --_d), "f"); + const a = (__classPrivateFieldSet(this, _C_test, (_f = __classPrivateFieldGet(this, _C_test, "f"), _e = _f++, _f), "f"), _e); + const b = (__classPrivateFieldSet(this, _C_test, (_h = __classPrivateFieldGet(this, _C_test, "f"), _g = _h--, _h), "f"), _g); + const c = __classPrivateFieldSet(this, _C_test, (_j = __classPrivateFieldGet(this, _C_test, "f"), ++_j), "f"); + const d = __classPrivateFieldSet(this, _C_test, (_k = __classPrivateFieldGet(this, _C_test, "f"), --_k), "f"); + for (__classPrivateFieldSet(this, _C_test, 0, "f"); __classPrivateFieldGet(this, _C_test, "f") < 10; __classPrivateFieldSet(this, _C_test, (_l = __classPrivateFieldGet(this, _C_test, "f"), ++_l), "f")) { } + for (__classPrivateFieldSet(this, _C_test, 0, "f"); __classPrivateFieldGet(this, _C_test, "f") < 10; __classPrivateFieldSet(this, _C_test, (_m = __classPrivateFieldGet(this, _C_test, "f"), _m++, _m), "f")) { } } test() { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; - __classPrivateFieldSet(_a = this.getInstance(), _C_test, +__classPrivateFieldGet(_a, _C_test, "f") + 1, "f"); - __classPrivateFieldSet(_b = this.getInstance(), _C_test, +__classPrivateFieldGet(_b, _C_test, "f") - 1, "f"); - __classPrivateFieldSet(_c = this.getInstance(), _C_test, +__classPrivateFieldGet(_c, _C_test, "f") + 1, "f"); - __classPrivateFieldSet(_d = this.getInstance(), _C_test, +__classPrivateFieldGet(_d, _C_test, "f") - 1, "f"); - const a = (__classPrivateFieldSet(_e = this.getInstance(), _C_test, (_f = +__classPrivateFieldGet(_e, _C_test, "f")) + 1, "f"), _f); - const b = (__classPrivateFieldSet(_g = this.getInstance(), _C_test, (_h = +__classPrivateFieldGet(_g, _C_test, "f")) - 1, "f"), _h); - const c = __classPrivateFieldSet(_j = this.getInstance(), _C_test, +__classPrivateFieldGet(_j, _C_test, "f") + 1, "f"); - const d = __classPrivateFieldSet(_k = this.getInstance(), _C_test, +__classPrivateFieldGet(_k, _C_test, "f") - 1, "f"); - for (__classPrivateFieldSet(this.getInstance(), _C_test, 0, "f"); __classPrivateFieldGet(this.getInstance(), _C_test, "f") < 10; __classPrivateFieldSet(_l = this.getInstance(), _C_test, +__classPrivateFieldGet(_l, _C_test, "f") + 1, "f")) { } - for (__classPrivateFieldSet(this.getInstance(), _C_test, 0, "f"); __classPrivateFieldGet(this.getInstance(), _C_test, "f") < 10; __classPrivateFieldSet(_m = this.getInstance(), _C_test, +__classPrivateFieldGet(_m, _C_test, "f") + 1, "f")) { } + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x; + __classPrivateFieldSet(_a = this.getInstance(), _C_test, (_b = __classPrivateFieldGet(_a, _C_test, "f"), _b++, _b), "f"); + __classPrivateFieldSet(_c = this.getInstance(), _C_test, (_d = __classPrivateFieldGet(_c, _C_test, "f"), _d--, _d), "f"); + __classPrivateFieldSet(_e = this.getInstance(), _C_test, (_f = __classPrivateFieldGet(_e, _C_test, "f"), ++_f), "f"); + __classPrivateFieldSet(_g = this.getInstance(), _C_test, (_h = __classPrivateFieldGet(_g, _C_test, "f"), --_h), "f"); + const a = (__classPrivateFieldSet(_j = this.getInstance(), _C_test, (_l = __classPrivateFieldGet(_j, _C_test, "f"), _k = _l++, _l), "f"), _k); + const b = (__classPrivateFieldSet(_m = this.getInstance(), _C_test, (_p = __classPrivateFieldGet(_m, _C_test, "f"), _o = _p--, _p), "f"), _o); + const c = __classPrivateFieldSet(_q = this.getInstance(), _C_test, (_r = __classPrivateFieldGet(_q, _C_test, "f"), ++_r), "f"); + const d = __classPrivateFieldSet(_s = this.getInstance(), _C_test, (_t = __classPrivateFieldGet(_s, _C_test, "f"), --_t), "f"); + for (__classPrivateFieldSet(this.getInstance(), _C_test, 0, "f"); __classPrivateFieldGet(this.getInstance(), _C_test, "f") < 10; __classPrivateFieldSet(_u = this.getInstance(), _C_test, (_v = __classPrivateFieldGet(_u, _C_test, "f"), ++_v), "f")) { } + for (__classPrivateFieldSet(this.getInstance(), _C_test, 0, "f"); __classPrivateFieldGet(this.getInstance(), _C_test, "f") < 10; __classPrivateFieldSet(_w = this.getInstance(), _C_test, (_x = __classPrivateFieldGet(_w, _C_test, "f"), _x++, _x), "f")) { } } getInstance() { return new C(); } } diff --git a/tests/baselines/reference/privateNameMethodAssignment.js b/tests/baselines/reference/privateNameMethodAssignment.js index c33e3406f9d9b..08b4bb806bd1b 100644 --- a/tests/baselines/reference/privateNameMethodAssignment.js +++ b/tests/baselines/reference/privateNameMethodAssignment.js @@ -27,14 +27,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( var _A3_instances, _A3_method; class A3 { constructor(a, b) { - var _a, _b; + var _a, _b, _c; _A3_instances.add(this); __classPrivateFieldSet(this, _A3_instances, () => { }, "m"); // Error, not writable __classPrivateFieldSet(a, _A3_instances, () => { }, "m"); // Error, not writable __classPrivateFieldSet(b, _A3_instances, () => { }, "m"); //Error, not writable (_a = this, { x: ({ set value(_b) { __classPrivateFieldSet(_a, _A3_instances, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable let x = __classPrivateFieldGet(this, _A3_instances, "m", _A3_method); - __classPrivateFieldSet(_b = b, _A3_instances, +__classPrivateFieldGet(_b, _A3_instances, "m", _A3_method) + 1, "m"); //Error, not writable + __classPrivateFieldSet(_b = b, _A3_instances, (_c = __classPrivateFieldGet(_b, _A3_instances, "m", _A3_method), _c++, _c), "m"); //Error, not writable } ; } diff --git a/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js index 810c3df10b50c..b112c14c46656 100644 --- a/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js +++ b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js @@ -44,30 +44,30 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function ( var _a, _C_test; class C { constructor() { - var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; - __classPrivateFieldSet(_b = C, _a, +__classPrivateFieldGet(_b, _a, "f", _C_test) + 1, "f", _C_test); - __classPrivateFieldSet(_c = C, _a, +__classPrivateFieldGet(_c, _a, "f", _C_test) - 1, "f", _C_test); - __classPrivateFieldSet(_d = C, _a, +__classPrivateFieldGet(_d, _a, "f", _C_test) + 1, "f", _C_test); - __classPrivateFieldSet(_e = C, _a, +__classPrivateFieldGet(_e, _a, "f", _C_test) - 1, "f", _C_test); - const a = (__classPrivateFieldSet(_f = C, _a, (_g = +__classPrivateFieldGet(_f, _a, "f", _C_test)) + 1, "f", _C_test), _g); - const b = (__classPrivateFieldSet(_h = C, _a, (_j = +__classPrivateFieldGet(_h, _a, "f", _C_test)) - 1, "f", _C_test), _j); - const c = __classPrivateFieldSet(_k = C, _a, +__classPrivateFieldGet(_k, _a, "f", _C_test) + 1, "f", _C_test); - const d = __classPrivateFieldSet(_l = C, _a, +__classPrivateFieldGet(_l, _a, "f", _C_test) - 1, "f", _C_test); - for (__classPrivateFieldSet(C, _a, 0, "f", _C_test); __classPrivateFieldGet(C, _a, "f", _C_test) < 10; __classPrivateFieldSet(_m = C, _a, +__classPrivateFieldGet(_m, _a, "f", _C_test) + 1, "f", _C_test)) { } - for (__classPrivateFieldSet(C, _a, 0, "f", _C_test); __classPrivateFieldGet(C, _a, "f", _C_test) < 10; __classPrivateFieldSet(_o = C, _a, +__classPrivateFieldGet(_o, _a, "f", _C_test) + 1, "f", _C_test)) { } + var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y; + __classPrivateFieldSet(_b = C, _a, (_c = __classPrivateFieldGet(_b, _a, "f", _C_test), _c++, _c), "f", _C_test); + __classPrivateFieldSet(_d = C, _a, (_e = __classPrivateFieldGet(_d, _a, "f", _C_test), _e--, _e), "f", _C_test); + __classPrivateFieldSet(_f = C, _a, (_g = __classPrivateFieldGet(_f, _a, "f", _C_test), ++_g), "f", _C_test); + __classPrivateFieldSet(_h = C, _a, (_j = __classPrivateFieldGet(_h, _a, "f", _C_test), --_j), "f", _C_test); + const a = (__classPrivateFieldSet(_k = C, _a, (_m = __classPrivateFieldGet(_k, _a, "f", _C_test), _l = _m++, _m), "f", _C_test), _l); + const b = (__classPrivateFieldSet(_o = C, _a, (_q = __classPrivateFieldGet(_o, _a, "f", _C_test), _p = _q--, _q), "f", _C_test), _p); + const c = __classPrivateFieldSet(_r = C, _a, (_s = __classPrivateFieldGet(_r, _a, "f", _C_test), ++_s), "f", _C_test); + const d = __classPrivateFieldSet(_t = C, _a, (_u = __classPrivateFieldGet(_t, _a, "f", _C_test), --_u), "f", _C_test); + for (__classPrivateFieldSet(C, _a, 0, "f", _C_test); __classPrivateFieldGet(C, _a, "f", _C_test) < 10; __classPrivateFieldSet(_v = C, _a, (_w = __classPrivateFieldGet(_v, _a, "f", _C_test), ++_w), "f", _C_test)) { } + for (__classPrivateFieldSet(C, _a, 0, "f", _C_test); __classPrivateFieldGet(C, _a, "f", _C_test) < 10; __classPrivateFieldSet(_x = C, _a, (_y = __classPrivateFieldGet(_x, _a, "f", _C_test), _y++, _y), "f", _C_test)) { } } test() { - var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; - __classPrivateFieldSet(_b = this.getClass(), _a, +__classPrivateFieldGet(_b, _a, "f", _C_test) + 1, "f", _C_test); - __classPrivateFieldSet(_c = this.getClass(), _a, +__classPrivateFieldGet(_c, _a, "f", _C_test) - 1, "f", _C_test); - __classPrivateFieldSet(_d = this.getClass(), _a, +__classPrivateFieldGet(_d, _a, "f", _C_test) + 1, "f", _C_test); - __classPrivateFieldSet(_e = this.getClass(), _a, +__classPrivateFieldGet(_e, _a, "f", _C_test) - 1, "f", _C_test); - const a = (__classPrivateFieldSet(_f = this.getClass(), _a, (_g = +__classPrivateFieldGet(_f, _a, "f", _C_test)) + 1, "f", _C_test), _g); - const b = (__classPrivateFieldSet(_h = this.getClass(), _a, (_j = +__classPrivateFieldGet(_h, _a, "f", _C_test)) - 1, "f", _C_test), _j); - const c = __classPrivateFieldSet(_k = this.getClass(), _a, +__classPrivateFieldGet(_k, _a, "f", _C_test) + 1, "f", _C_test); - const d = __classPrivateFieldSet(_l = this.getClass(), _a, +__classPrivateFieldGet(_l, _a, "f", _C_test) - 1, "f", _C_test); - for (__classPrivateFieldSet(this.getClass(), _a, 0, "f", _C_test); __classPrivateFieldGet(this.getClass(), _a, "f", _C_test) < 10; __classPrivateFieldSet(_m = this.getClass(), _a, +__classPrivateFieldGet(_m, _a, "f", _C_test) + 1, "f", _C_test)) { } - for (__classPrivateFieldSet(this.getClass(), _a, 0, "f", _C_test); __classPrivateFieldGet(this.getClass(), _a, "f", _C_test) < 10; __classPrivateFieldSet(_o = this.getClass(), _a, +__classPrivateFieldGet(_o, _a, "f", _C_test) + 1, "f", _C_test)) { } + var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y; + __classPrivateFieldSet(_b = this.getClass(), _a, (_c = __classPrivateFieldGet(_b, _a, "f", _C_test), _c++, _c), "f", _C_test); + __classPrivateFieldSet(_d = this.getClass(), _a, (_e = __classPrivateFieldGet(_d, _a, "f", _C_test), _e--, _e), "f", _C_test); + __classPrivateFieldSet(_f = this.getClass(), _a, (_g = __classPrivateFieldGet(_f, _a, "f", _C_test), ++_g), "f", _C_test); + __classPrivateFieldSet(_h = this.getClass(), _a, (_j = __classPrivateFieldGet(_h, _a, "f", _C_test), --_j), "f", _C_test); + const a = (__classPrivateFieldSet(_k = this.getClass(), _a, (_m = __classPrivateFieldGet(_k, _a, "f", _C_test), _l = _m++, _m), "f", _C_test), _l); + const b = (__classPrivateFieldSet(_o = this.getClass(), _a, (_q = __classPrivateFieldGet(_o, _a, "f", _C_test), _p = _q--, _q), "f", _C_test), _p); + const c = __classPrivateFieldSet(_r = this.getClass(), _a, (_s = __classPrivateFieldGet(_r, _a, "f", _C_test), ++_s), "f", _C_test); + const d = __classPrivateFieldSet(_t = this.getClass(), _a, (_u = __classPrivateFieldGet(_t, _a, "f", _C_test), --_u), "f", _C_test); + for (__classPrivateFieldSet(this.getClass(), _a, 0, "f", _C_test); __classPrivateFieldGet(this.getClass(), _a, "f", _C_test) < 10; __classPrivateFieldSet(_v = this.getClass(), _a, (_w = __classPrivateFieldGet(_v, _a, "f", _C_test), ++_w), "f", _C_test)) { } + for (__classPrivateFieldSet(this.getClass(), _a, 0, "f", _C_test); __classPrivateFieldGet(this.getClass(), _a, "f", _C_test) < 10; __classPrivateFieldSet(_x = this.getClass(), _a, (_y = __classPrivateFieldGet(_x, _a, "f", _C_test), _y++, _y), "f", _C_test)) { } } getClass() { return C; } } diff --git a/tests/baselines/reference/privateNameStaticMethodAssignment.js b/tests/baselines/reference/privateNameStaticMethodAssignment.js index 48b6df46c24c8..aad92bf3205b6 100644 --- a/tests/baselines/reference/privateNameStaticMethodAssignment.js +++ b/tests/baselines/reference/privateNameStaticMethodAssignment.js @@ -27,13 +27,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( var _a, _A3_method; class A3 { constructor(a, b) { - var _b; + var _b, _c; __classPrivateFieldSet(A3, _a, () => { }, "m"); // Error, not writable __classPrivateFieldSet(a, _a, () => { }, "m"); // Error, not writable __classPrivateFieldSet(b, _a, () => { }, "m"); //Error, not writable ({ x: ({ set value(_b) { __classPrivateFieldSet(A3, _a, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable let x = __classPrivateFieldGet(A3, _a, "m", _A3_method); - __classPrivateFieldSet(_b = b, _a, +__classPrivateFieldGet(_b, _a, "m", _A3_method) + 1, "m"); //Error, not writable + __classPrivateFieldSet(_b = b, _a, (_c = __classPrivateFieldGet(_b, _a, "m", _A3_method), _c++, _c), "m"); //Error, not writable } ; } diff --git a/tests/baselines/reference/privateWriteOnlyAccessorRead.js b/tests/baselines/reference/privateWriteOnlyAccessorRead.js index 8761f3f667fa1..1b822605639a4 100644 --- a/tests/baselines/reference/privateWriteOnlyAccessorRead.js +++ b/tests/baselines/reference/privateWriteOnlyAccessorRead.js @@ -63,20 +63,20 @@ class Test { _Test_instances.add(this); } m() { - var _a, _b, _c; + var _a, _b, _c, _d; const foo = { bar: 1 }; console.log(__classPrivateFieldGet(this, _Test_instances, "a")); // error __classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok __classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok __classPrivateFieldGet(this, _Test_instances, "a").foo = foo; // error - (_a = this, { o: ({ set value(_d) { __classPrivateFieldSet(_a, _Test_instances, _d, "a", _Test_value_set); } }).value } = { o: { foo } }); //ok - (__classPrivateFieldGet(this, _Test_instances, "a") = __rest({ foo }, [])); //ok + (_a = this, { o: ({ set value(_e) { __classPrivateFieldSet(_a, _Test_instances, _e, "a", _Test_value_set); } }).value } = { o: { foo } }); //ok + (_b = this, ({ set value(_e) { __classPrivateFieldSet(_b, _Test_instances, _e, "a", _Test_value_set); } }).value = __rest({ foo }, [])); //ok ({ foo: __classPrivateFieldGet(this, _Test_instances, "a").foo } = { foo }); //error ({ foo: Object.assign({}, __classPrivateFieldGet(this, _Test_instances, "a").foo), } = { foo }); //error let r = { o: __classPrivateFieldGet(this, _Test_instances, "a") }; //error - _b = this, _c = this, [({ set value(_d) { __classPrivateFieldSet(_b, _Test_instances, _d, "a", _Test_valueOne_set); } }).value, ...({ set value(_d) { __classPrivateFieldSet(_c, _Test_instances, _d, "a", _Test_valueRest_set); } }).value] = [1, 2, 3]; + _c = this, _d = this, [({ set value(_e) { __classPrivateFieldSet(_c, _Test_instances, _e, "a", _Test_valueOne_set); } }).value, ...({ set value(_e) { __classPrivateFieldSet(_d, _Test_instances, _e, "a", _Test_valueRest_set); } }).value] = [1, 2, 3]; let arr = [ __classPrivateFieldGet(this, _Test_instances, "a"), ...__classPrivateFieldGet(this, _Test_instances, "a") diff --git a/tests/baselines/reference/sourceMapValidationDecorators.js.map b/tests/baselines/reference/sourceMapValidationDecorators.js.map index 5b5471bc7bf62..e2312dd2f3977 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.js.map +++ b/tests/baselines/reference/sourceMapValidationDecorators.js.map @@ -1,3 +1,3 @@ //// [sourceMapValidationDecorators.js.map] -{"version":3,"file":"sourceMapValidationDecorators.js","sourceRoot":"","sources":["sourceMapValidationDecorators.ts"],"names":[],"mappings":";;;;;;;;;AASA;IACI,iBAGS,QAAgB;QAIvB,WAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,0BAAc;;QAJP,aAAQ,GAAR,QAAQ,CAAQ;IAKzB,CAAC;IAID,uBAAK,GAAL;QACI,OAAO,MAAM,GAAG,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5C,CAAC;IAUO,oBAAE,GAAV,UAGE,CAAS;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAID,sBAAI,8BAAS;aAAb;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;aAED,UAGE,SAAiB;YACf,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC9B,CAAC;;;OAPA;IAbc,UAAE,GAAW,EAAE,CAAC;IAV/B;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;wCAGtB;IAID;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;sCACL;IAMlB;QACG,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;qCAGzB;IAID;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;QAMpB,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;4CAJzB;IAbD;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;6BACQ;IAvB7B,OAAO;QAFZ,eAAe;QACf,eAAe,CAAC,EAAE,CAAC;QAGb,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;QAGvB,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;OAPxB,OAAO,CA4CZ;IAAD,cAAC;CAAA,AA5CD,IA4CC"} -//// https://sokra.github.io/source-map-visualization#base64,dmFyIF9fZGVjb3JhdGUgPSAodGhpcyAmJiB0aGlzLl9fZGVjb3JhdGUpIHx8IGZ1bmN0aW9uIChkZWNvcmF0b3JzLCB0YXJnZXQsIGtleSwgZGVzYykgew0KICAgIHZhciBjID0gYXJndW1lbnRzLmxlbmd0aCwgciA9IGMgPCAzID8gdGFyZ2V0IDogZGVzYyA9PT0gbnVsbCA/IGRlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yKHRhcmdldCwga2V5KSA6IGRlc2MsIGQ7DQogICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAib2JqZWN0IiAmJiB0eXBlb2YgUmVmbGVjdC5kZWNvcmF0ZSA9PT0gImZ1bmN0aW9uIikgciA9IFJlZmxlY3QuZGVjb3JhdGUoZGVjb3JhdG9ycywgdGFyZ2V0LCBrZXksIGRlc2MpOw0KICAgIGVsc2UgZm9yICh2YXIgaSA9IGRlY29yYXRvcnMubGVuZ3RoIC0gMTsgaSA+PSAwOyBpLS0pIGlmIChkID0gZGVjb3JhdG9yc1tpXSkgciA9IChjIDwgMyA/IGQocikgOiBjID4gMyA/IGQodGFyZ2V0LCBrZXksIHIpIDogZCh0YXJnZXQsIGtleSkpIHx8IHI7DQogICAgcmV0dXJuIGMgPiAzICYmIHIgJiYgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRhcmdldCwga2V5LCByKSwgcjsNCn07DQp2YXIgX19wYXJhbSA9ICh0aGlzICYmIHRoaXMuX19wYXJhbSkgfHwgZnVuY3Rpb24gKHBhcmFtSW5kZXgsIGRlY29yYXRvcikgew0KICAgIHJldHVybiBmdW5jdGlvbiAodGFyZ2V0LCBrZXkpIHsgZGVjb3JhdG9yKHRhcmdldCwga2V5LCBwYXJhbUluZGV4KTsgfQ0KfTsNCnZhciBHcmVldGVyID0gLyoqIEBjbGFzcyAqLyAoZnVuY3Rpb24gKCkgew0KICAgIGZ1bmN0aW9uIEdyZWV0ZXIoZ3JlZXRpbmcpIHsNCiAgICAgICAgdmFyIGIgPSBbXTsNCiAgICAgICAgZm9yICh2YXIgX2kgPSAxOyBfaSA8IGFyZ3VtZW50cy5sZW5ndGg7IF9pKyspIHsNCiAgICAgICAgICAgIGJbX2kgLSAxXSA9IGFyZ3VtZW50c1tfaV07DQogICAgICAgIH0NCiAgICAgICAgdGhpcy5ncmVldGluZyA9IGdyZWV0aW5nOw0KICAgIH0NCiAgICBHcmVldGVyLnByb3RvdHlwZS5ncmVldCA9IGZ1bmN0aW9uICgpIHsNCiAgICAgICAgcmV0dXJuICI8aDE+IiArIHRoaXMuZ3JlZXRpbmcgKyAiPC9oMT4iOw0KICAgIH07DQogICAgR3JlZXRlci5wcm90b3R5cGUuZm4gPSBmdW5jdGlvbiAoeCkgew0KICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsNCiAgICB9Ow0KICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShHcmVldGVyLnByb3RvdHlwZSwgImdyZWV0aW5ncyIsIHsNCiAgICAgICAgZ2V0OiBmdW5jdGlvbiAoKSB7DQogICAgICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsNCiAgICAgICAgfSwNCiAgICAgICAgc2V0OiBmdW5jdGlvbiAoZ3JlZXRpbmdzKSB7DQogICAgICAgICAgICB0aGlzLmdyZWV0aW5nID0gZ3JlZXRpbmdzOw0KICAgICAgICB9LA0KICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwNCiAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlDQogICAgfSk7DQogICAgR3JlZXRlci54MSA9IDEwOw0KICAgIF9fZGVjb3JhdGUoWw0KICAgICAgICBQcm9wZXJ0eURlY29yYXRvcjEsDQogICAgICAgIFByb3BlcnR5RGVjb3JhdG9yMig0MCkNCiAgICBdLCBHcmVldGVyLnByb3RvdHlwZSwgImdyZWV0IiwgbnVsbCk7DQogICAgX19kZWNvcmF0ZShbDQogICAgICAgIFByb3BlcnR5RGVjb3JhdG9yMSwNCiAgICAgICAgUHJvcGVydHlEZWNvcmF0b3IyKDUwKQ0KICAgIF0sIEdyZWV0ZXIucHJvdG90eXBlLCAieCIsIHZvaWQgMCk7DQogICAgX19kZWNvcmF0ZShbDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMSksDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMig3MCkpDQogICAgXSwgR3JlZXRlci5wcm90b3R5cGUsICJmbiIsIG51bGwpOw0KICAgIF9fZGVjb3JhdGUoWw0KICAgICAgICBQcm9wZXJ0eURlY29yYXRvcjEsDQogICAgICAgIFByb3BlcnR5RGVjb3JhdG9yMig4MCksDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMSksDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMig5MCkpDQogICAgXSwgR3JlZXRlci5wcm90b3R5cGUsICJncmVldGluZ3MiLCBudWxsKTsNCiAgICBfX2RlY29yYXRlKFsNCiAgICAgICAgUHJvcGVydHlEZWNvcmF0b3IxLA0KICAgICAgICBQcm9wZXJ0eURlY29yYXRvcjIoNjApDQogICAgXSwgR3JlZXRlciwgIngxIiwgdm9pZCAwKTsNCiAgICBHcmVldGVyID0gX19kZWNvcmF0ZShbDQogICAgICAgIENsYXNzRGVjb3JhdG9yMSwNCiAgICAgICAgQ2xhc3NEZWNvcmF0b3IyKDEwKSwNCiAgICAgICAgX19wYXJhbSgwLCBQYXJhbWV0ZXJEZWNvcmF0b3IxKSwNCiAgICAgICAgX19wYXJhbSgwLCBQYXJhbWV0ZXJEZWNvcmF0b3IyKDIwKSksDQogICAgICAgIF9fcGFyYW0oMSwgUGFyYW1ldGVyRGVjb3JhdG9yMSksDQogICAgICAgIF9fcGFyYW0oMSwgUGFyYW1ldGVyRGVjb3JhdG9yMigzMCkpDQogICAgXSwgR3JlZXRlcik7DQogICAgcmV0dXJuIEdyZWV0ZXI7DQp9KCkpOw0KLy8jIHNvdXJjZU1hcHBpbmdVUkw9c291cmNlTWFwVmFsaWRhdGlvbkRlY29yYXRvcnMuanMubWFw,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic291cmNlTWFwVmFsaWRhdGlvbkRlY29yYXRvcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJzb3VyY2VNYXBWYWxpZGF0aW9uRGVjb3JhdG9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFTQTtJQUNJLGlCQUdTLFFBQWdCO1FBSXZCLFdBQWM7YUFBZCxVQUFjLEVBQWQscUJBQWMsRUFBZCxJQUFjO1lBQWQsMEJBQWM7O1FBSlAsYUFBUSxHQUFSLFFBQVEsQ0FBUTtJQUt6QixDQUFDO0lBSUQsdUJBQUssR0FBTDtRQUNJLE9BQU8sTUFBTSxHQUFHLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDO0lBQzVDLENBQUM7SUFVTyxvQkFBRSxHQUFWLFVBR0UsQ0FBUztRQUNQLE9BQU8sSUFBSSxDQUFDLFFBQVEsQ0FBQztJQUN6QixDQUFDO0lBSUQsc0JBQUksOEJBQVM7YUFBYjtZQUNJLE9BQU8sSUFBSSxDQUFDLFFBQVEsQ0FBQztRQUN6QixDQUFDO2FBRUQsVUFHRSxTQUFpQjtZQUNmLElBQUksQ0FBQyxRQUFRLEdBQUcsU0FBUyxDQUFDO1FBQzlCLENBQUM7OztPQVBBO0lBYmMsVUFBRSxHQUFXLEVBQUUsQ0FBQztJQVYvQjtRQUZDLGtCQUFrQjtRQUNsQixrQkFBa0IsQ0FBQyxFQUFFLENBQUM7d0NBR3RCO0lBSUQ7UUFGQyxrQkFBa0I7UUFDbEIsa0JBQWtCLENBQUMsRUFBRSxDQUFDO3NDQUNMO0lBTWxCO1FBQ0csV0FBQSxtQkFBbUIsQ0FBQTtRQUNuQixXQUFBLG1CQUFtQixDQUFDLEVBQUUsQ0FBQyxDQUFBO3FDQUd6QjtJQUlEO1FBRkMsa0JBQWtCO1FBQ2xCLGtCQUFrQixDQUFDLEVBQUUsQ0FBQztRQU1wQixXQUFBLG1CQUFtQixDQUFBO1FBQ25CLFdBQUEsbUJBQW1CLENBQUMsRUFBRSxDQUFDLENBQUE7NENBSnpCO0lBYkQ7UUFGQyxrQkFBa0I7UUFDbEIsa0JBQWtCLENBQUMsRUFBRSxDQUFDOzZCQUNRO0lBdkI3QixPQUFPO1FBRlosZUFBZTtRQUNmLGVBQWUsQ0FBQyxFQUFFLENBQUM7UUFHYixXQUFBLG1CQUFtQixDQUFBO1FBQ25CLFdBQUEsbUJBQW1CLENBQUMsRUFBRSxDQUFDLENBQUE7UUFHdkIsV0FBQSxtQkFBbUIsQ0FBQTtRQUNuQixXQUFBLG1CQUFtQixDQUFDLEVBQUUsQ0FBQyxDQUFBO09BUHhCLE9BQU8sQ0E0Q1o7SUFBRCxjQUFDO0NBQUEsQUE1Q0QsSUE0Q0MifQ==,ZGVjbGFyZSBmdW5jdGlvbiBDbGFzc0RlY29yYXRvcjEodGFyZ2V0OiBGdW5jdGlvbik6IHZvaWQ7CmRlY2xhcmUgZnVuY3Rpb24gQ2xhc3NEZWNvcmF0b3IyKHg6IG51bWJlcik6ICh0YXJnZXQ6IEZ1bmN0aW9uKSA9PiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFByb3BlcnR5RGVjb3JhdG9yMSh0YXJnZXQ6IE9iamVjdCwga2V5OiBzdHJpbmcgfCBzeW1ib2wsIGRlc2NyaXB0b3I/OiBQcm9wZXJ0eURlc2NyaXB0b3IpOiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFByb3BlcnR5RGVjb3JhdG9yMih4OiBudW1iZXIpOiAodGFyZ2V0OiBPYmplY3QsIGtleTogc3RyaW5nIHwgc3ltYm9sLCBkZXNjcmlwdG9yPzogUHJvcGVydHlEZXNjcmlwdG9yKSA9PiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFBhcmFtZXRlckRlY29yYXRvcjEodGFyZ2V0OiBPYmplY3QsIGtleTogc3RyaW5nIHwgc3ltYm9sLCBwYXJhbUluZGV4OiBudW1iZXIpOiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFBhcmFtZXRlckRlY29yYXRvcjIoeDogbnVtYmVyKTogKHRhcmdldDogT2JqZWN0LCBrZXk6IHN0cmluZyB8IHN5bWJvbCwgcGFyYW1JbmRleDogbnVtYmVyKSA9PiB2b2lkOwoKQENsYXNzRGVjb3JhdG9yMQpAQ2xhc3NEZWNvcmF0b3IyKDEwKQpjbGFzcyBHcmVldGVyIHsKICAgIGNvbnN0cnVjdG9yKAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoMjApIAogICAgICBwdWJsaWMgZ3JlZXRpbmc6IHN0cmluZywgCiAgICAgIAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoMzApIAogICAgICAuLi5iOiBzdHJpbmdbXSkgewogICAgfQogICAgCiAgICBAUHJvcGVydHlEZWNvcmF0b3IxCiAgICBAUHJvcGVydHlEZWNvcmF0b3IyKDQwKQogICAgZ3JlZXQoKSB7CiAgICAgICAgcmV0dXJuICI8aDE+IiArIHRoaXMuZ3JlZXRpbmcgKyAiPC9oMT4iOwogICAgfQoKICAgIEBQcm9wZXJ0eURlY29yYXRvcjEKICAgIEBQcm9wZXJ0eURlY29yYXRvcjIoNTApCiAgICBwcml2YXRlIHg6IHN0cmluZzsKCiAgICBAUHJvcGVydHlEZWNvcmF0b3IxCiAgICBAUHJvcGVydHlEZWNvcmF0b3IyKDYwKQogICAgcHJpdmF0ZSBzdGF0aWMgeDE6IG51bWJlciA9IDEwOwogICAgCiAgICBwcml2YXRlIGZuKAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoNzApIAogICAgICB4OiBudW1iZXIpIHsKICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsKICAgIH0KCiAgICBAUHJvcGVydHlEZWNvcmF0b3IxCiAgICBAUHJvcGVydHlEZWNvcmF0b3IyKDgwKQogICAgZ2V0IGdyZWV0aW5ncygpIHsKICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsKICAgIH0KCiAgICBzZXQgZ3JlZXRpbmdzKAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoOTApIAogICAgICBncmVldGluZ3M6IHN0cmluZykgewogICAgICAgIHRoaXMuZ3JlZXRpbmcgPSBncmVldGluZ3M7CiAgICB9ICAgIAp9 +{"version":3,"file":"sourceMapValidationDecorators.js","sourceRoot":"","sources":["sourceMapValidationDecorators.ts"],"names":[],"mappings":";;;;;;;;;AASA;IACI,iBAGS,QAAgB;QAIvB,WAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,0BAAc;;QAJP,aAAQ,GAAR,QAAQ,CAAQ;IAKzB,CAAC;IAID,uBAAK,GAAL;QACI,OAAO,MAAM,GAAG,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5C,CAAC;IAUO,oBAAE,GAAV,UAGE,CAAS;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAID,sBAAI,8BAAS;aAAb;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;aAED,UAGE,SAAiB;YACf,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC9B,CAAC;;;OAPA;IAbc,UAAE,GAAW,EAAG,CAAA;IAV/B;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;wCAGtB;IAID;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;sCACL;IAMlB;QACG,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;qCAGzB;IAID;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;QAMpB,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;4CAJzB;IAbD;QAFC,kBAAkB;QAClB,kBAAkB,CAAC,EAAE,CAAC;6BACQ;IAvB7B,OAAO;QAFZ,eAAe;QACf,eAAe,CAAC,EAAE,CAAC;QAGb,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;QAGvB,WAAA,mBAAmB,CAAA;QACnB,WAAA,mBAAmB,CAAC,EAAE,CAAC,CAAA;OAPxB,OAAO,CA4CZ;IAAD,cAAC;CAAA,AA5CD,IA4CC"} +//// https://sokra.github.io/source-map-visualization#base64,dmFyIF9fZGVjb3JhdGUgPSAodGhpcyAmJiB0aGlzLl9fZGVjb3JhdGUpIHx8IGZ1bmN0aW9uIChkZWNvcmF0b3JzLCB0YXJnZXQsIGtleSwgZGVzYykgew0KICAgIHZhciBjID0gYXJndW1lbnRzLmxlbmd0aCwgciA9IGMgPCAzID8gdGFyZ2V0IDogZGVzYyA9PT0gbnVsbCA/IGRlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yKHRhcmdldCwga2V5KSA6IGRlc2MsIGQ7DQogICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAib2JqZWN0IiAmJiB0eXBlb2YgUmVmbGVjdC5kZWNvcmF0ZSA9PT0gImZ1bmN0aW9uIikgciA9IFJlZmxlY3QuZGVjb3JhdGUoZGVjb3JhdG9ycywgdGFyZ2V0LCBrZXksIGRlc2MpOw0KICAgIGVsc2UgZm9yICh2YXIgaSA9IGRlY29yYXRvcnMubGVuZ3RoIC0gMTsgaSA+PSAwOyBpLS0pIGlmIChkID0gZGVjb3JhdG9yc1tpXSkgciA9IChjIDwgMyA/IGQocikgOiBjID4gMyA/IGQodGFyZ2V0LCBrZXksIHIpIDogZCh0YXJnZXQsIGtleSkpIHx8IHI7DQogICAgcmV0dXJuIGMgPiAzICYmIHIgJiYgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRhcmdldCwga2V5LCByKSwgcjsNCn07DQp2YXIgX19wYXJhbSA9ICh0aGlzICYmIHRoaXMuX19wYXJhbSkgfHwgZnVuY3Rpb24gKHBhcmFtSW5kZXgsIGRlY29yYXRvcikgew0KICAgIHJldHVybiBmdW5jdGlvbiAodGFyZ2V0LCBrZXkpIHsgZGVjb3JhdG9yKHRhcmdldCwga2V5LCBwYXJhbUluZGV4KTsgfQ0KfTsNCnZhciBHcmVldGVyID0gLyoqIEBjbGFzcyAqLyAoZnVuY3Rpb24gKCkgew0KICAgIGZ1bmN0aW9uIEdyZWV0ZXIoZ3JlZXRpbmcpIHsNCiAgICAgICAgdmFyIGIgPSBbXTsNCiAgICAgICAgZm9yICh2YXIgX2kgPSAxOyBfaSA8IGFyZ3VtZW50cy5sZW5ndGg7IF9pKyspIHsNCiAgICAgICAgICAgIGJbX2kgLSAxXSA9IGFyZ3VtZW50c1tfaV07DQogICAgICAgIH0NCiAgICAgICAgdGhpcy5ncmVldGluZyA9IGdyZWV0aW5nOw0KICAgIH0NCiAgICBHcmVldGVyLnByb3RvdHlwZS5ncmVldCA9IGZ1bmN0aW9uICgpIHsNCiAgICAgICAgcmV0dXJuICI8aDE+IiArIHRoaXMuZ3JlZXRpbmcgKyAiPC9oMT4iOw0KICAgIH07DQogICAgR3JlZXRlci5wcm90b3R5cGUuZm4gPSBmdW5jdGlvbiAoeCkgew0KICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsNCiAgICB9Ow0KICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShHcmVldGVyLnByb3RvdHlwZSwgImdyZWV0aW5ncyIsIHsNCiAgICAgICAgZ2V0OiBmdW5jdGlvbiAoKSB7DQogICAgICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsNCiAgICAgICAgfSwNCiAgICAgICAgc2V0OiBmdW5jdGlvbiAoZ3JlZXRpbmdzKSB7DQogICAgICAgICAgICB0aGlzLmdyZWV0aW5nID0gZ3JlZXRpbmdzOw0KICAgICAgICB9LA0KICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwNCiAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlDQogICAgfSk7DQogICAgR3JlZXRlci54MSA9IDEwOw0KICAgIF9fZGVjb3JhdGUoWw0KICAgICAgICBQcm9wZXJ0eURlY29yYXRvcjEsDQogICAgICAgIFByb3BlcnR5RGVjb3JhdG9yMig0MCkNCiAgICBdLCBHcmVldGVyLnByb3RvdHlwZSwgImdyZWV0IiwgbnVsbCk7DQogICAgX19kZWNvcmF0ZShbDQogICAgICAgIFByb3BlcnR5RGVjb3JhdG9yMSwNCiAgICAgICAgUHJvcGVydHlEZWNvcmF0b3IyKDUwKQ0KICAgIF0sIEdyZWV0ZXIucHJvdG90eXBlLCAieCIsIHZvaWQgMCk7DQogICAgX19kZWNvcmF0ZShbDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMSksDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMig3MCkpDQogICAgXSwgR3JlZXRlci5wcm90b3R5cGUsICJmbiIsIG51bGwpOw0KICAgIF9fZGVjb3JhdGUoWw0KICAgICAgICBQcm9wZXJ0eURlY29yYXRvcjEsDQogICAgICAgIFByb3BlcnR5RGVjb3JhdG9yMig4MCksDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMSksDQogICAgICAgIF9fcGFyYW0oMCwgUGFyYW1ldGVyRGVjb3JhdG9yMig5MCkpDQogICAgXSwgR3JlZXRlci5wcm90b3R5cGUsICJncmVldGluZ3MiLCBudWxsKTsNCiAgICBfX2RlY29yYXRlKFsNCiAgICAgICAgUHJvcGVydHlEZWNvcmF0b3IxLA0KICAgICAgICBQcm9wZXJ0eURlY29yYXRvcjIoNjApDQogICAgXSwgR3JlZXRlciwgIngxIiwgdm9pZCAwKTsNCiAgICBHcmVldGVyID0gX19kZWNvcmF0ZShbDQogICAgICAgIENsYXNzRGVjb3JhdG9yMSwNCiAgICAgICAgQ2xhc3NEZWNvcmF0b3IyKDEwKSwNCiAgICAgICAgX19wYXJhbSgwLCBQYXJhbWV0ZXJEZWNvcmF0b3IxKSwNCiAgICAgICAgX19wYXJhbSgwLCBQYXJhbWV0ZXJEZWNvcmF0b3IyKDIwKSksDQogICAgICAgIF9fcGFyYW0oMSwgUGFyYW1ldGVyRGVjb3JhdG9yMSksDQogICAgICAgIF9fcGFyYW0oMSwgUGFyYW1ldGVyRGVjb3JhdG9yMigzMCkpDQogICAgXSwgR3JlZXRlcik7DQogICAgcmV0dXJuIEdyZWV0ZXI7DQp9KCkpOw0KLy8jIHNvdXJjZU1hcHBpbmdVUkw9c291cmNlTWFwVmFsaWRhdGlvbkRlY29yYXRvcnMuanMubWFw,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic291cmNlTWFwVmFsaWRhdGlvbkRlY29yYXRvcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJzb3VyY2VNYXBWYWxpZGF0aW9uRGVjb3JhdG9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFTQTtJQUNJLGlCQUdTLFFBQWdCO1FBSXZCLFdBQWM7YUFBZCxVQUFjLEVBQWQscUJBQWMsRUFBZCxJQUFjO1lBQWQsMEJBQWM7O1FBSlAsYUFBUSxHQUFSLFFBQVEsQ0FBUTtJQUt6QixDQUFDO0lBSUQsdUJBQUssR0FBTDtRQUNJLE9BQU8sTUFBTSxHQUFHLElBQUksQ0FBQyxRQUFRLEdBQUcsT0FBTyxDQUFDO0lBQzVDLENBQUM7SUFVTyxvQkFBRSxHQUFWLFVBR0UsQ0FBUztRQUNQLE9BQU8sSUFBSSxDQUFDLFFBQVEsQ0FBQztJQUN6QixDQUFDO0lBSUQsc0JBQUksOEJBQVM7YUFBYjtZQUNJLE9BQU8sSUFBSSxDQUFDLFFBQVEsQ0FBQztRQUN6QixDQUFDO2FBRUQsVUFHRSxTQUFpQjtZQUNmLElBQUksQ0FBQyxRQUFRLEdBQUcsU0FBUyxDQUFDO1FBQzlCLENBQUM7OztPQVBBO0lBYmMsVUFBRSxHQUFXLEVBQUcsQ0FBQTtJQVYvQjtRQUZDLGtCQUFrQjtRQUNsQixrQkFBa0IsQ0FBQyxFQUFFLENBQUM7d0NBR3RCO0lBSUQ7UUFGQyxrQkFBa0I7UUFDbEIsa0JBQWtCLENBQUMsRUFBRSxDQUFDO3NDQUNMO0lBTWxCO1FBQ0csV0FBQSxtQkFBbUIsQ0FBQTtRQUNuQixXQUFBLG1CQUFtQixDQUFDLEVBQUUsQ0FBQyxDQUFBO3FDQUd6QjtJQUlEO1FBRkMsa0JBQWtCO1FBQ2xCLGtCQUFrQixDQUFDLEVBQUUsQ0FBQztRQU1wQixXQUFBLG1CQUFtQixDQUFBO1FBQ25CLFdBQUEsbUJBQW1CLENBQUMsRUFBRSxDQUFDLENBQUE7NENBSnpCO0lBYkQ7UUFGQyxrQkFBa0I7UUFDbEIsa0JBQWtCLENBQUMsRUFBRSxDQUFDOzZCQUNRO0lBdkI3QixPQUFPO1FBRlosZUFBZTtRQUNmLGVBQWUsQ0FBQyxFQUFFLENBQUM7UUFHYixXQUFBLG1CQUFtQixDQUFBO1FBQ25CLFdBQUEsbUJBQW1CLENBQUMsRUFBRSxDQUFDLENBQUE7UUFHdkIsV0FBQSxtQkFBbUIsQ0FBQTtRQUNuQixXQUFBLG1CQUFtQixDQUFDLEVBQUUsQ0FBQyxDQUFBO09BUHhCLE9BQU8sQ0E0Q1o7SUFBRCxjQUFDO0NBQUEsQUE1Q0QsSUE0Q0MifQ==,ZGVjbGFyZSBmdW5jdGlvbiBDbGFzc0RlY29yYXRvcjEodGFyZ2V0OiBGdW5jdGlvbik6IHZvaWQ7CmRlY2xhcmUgZnVuY3Rpb24gQ2xhc3NEZWNvcmF0b3IyKHg6IG51bWJlcik6ICh0YXJnZXQ6IEZ1bmN0aW9uKSA9PiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFByb3BlcnR5RGVjb3JhdG9yMSh0YXJnZXQ6IE9iamVjdCwga2V5OiBzdHJpbmcgfCBzeW1ib2wsIGRlc2NyaXB0b3I/OiBQcm9wZXJ0eURlc2NyaXB0b3IpOiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFByb3BlcnR5RGVjb3JhdG9yMih4OiBudW1iZXIpOiAodGFyZ2V0OiBPYmplY3QsIGtleTogc3RyaW5nIHwgc3ltYm9sLCBkZXNjcmlwdG9yPzogUHJvcGVydHlEZXNjcmlwdG9yKSA9PiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFBhcmFtZXRlckRlY29yYXRvcjEodGFyZ2V0OiBPYmplY3QsIGtleTogc3RyaW5nIHwgc3ltYm9sLCBwYXJhbUluZGV4OiBudW1iZXIpOiB2b2lkOwpkZWNsYXJlIGZ1bmN0aW9uIFBhcmFtZXRlckRlY29yYXRvcjIoeDogbnVtYmVyKTogKHRhcmdldDogT2JqZWN0LCBrZXk6IHN0cmluZyB8IHN5bWJvbCwgcGFyYW1JbmRleDogbnVtYmVyKSA9PiB2b2lkOwoKQENsYXNzRGVjb3JhdG9yMQpAQ2xhc3NEZWNvcmF0b3IyKDEwKQpjbGFzcyBHcmVldGVyIHsKICAgIGNvbnN0cnVjdG9yKAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoMjApIAogICAgICBwdWJsaWMgZ3JlZXRpbmc6IHN0cmluZywgCiAgICAgIAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoMzApIAogICAgICAuLi5iOiBzdHJpbmdbXSkgewogICAgfQogICAgCiAgICBAUHJvcGVydHlEZWNvcmF0b3IxCiAgICBAUHJvcGVydHlEZWNvcmF0b3IyKDQwKQogICAgZ3JlZXQoKSB7CiAgICAgICAgcmV0dXJuICI8aDE+IiArIHRoaXMuZ3JlZXRpbmcgKyAiPC9oMT4iOwogICAgfQoKICAgIEBQcm9wZXJ0eURlY29yYXRvcjEKICAgIEBQcm9wZXJ0eURlY29yYXRvcjIoNTApCiAgICBwcml2YXRlIHg6IHN0cmluZzsKCiAgICBAUHJvcGVydHlEZWNvcmF0b3IxCiAgICBAUHJvcGVydHlEZWNvcmF0b3IyKDYwKQogICAgcHJpdmF0ZSBzdGF0aWMgeDE6IG51bWJlciA9IDEwOwogICAgCiAgICBwcml2YXRlIGZuKAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoNzApIAogICAgICB4OiBudW1iZXIpIHsKICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsKICAgIH0KCiAgICBAUHJvcGVydHlEZWNvcmF0b3IxCiAgICBAUHJvcGVydHlEZWNvcmF0b3IyKDgwKQogICAgZ2V0IGdyZWV0aW5ncygpIHsKICAgICAgICByZXR1cm4gdGhpcy5ncmVldGluZzsKICAgIH0KCiAgICBzZXQgZ3JlZXRpbmdzKAogICAgICBAUGFyYW1ldGVyRGVjb3JhdG9yMSAKICAgICAgQFBhcmFtZXRlckRlY29yYXRvcjIoOTApIAogICAgICBncmVldGluZ3M6IHN0cmluZykgewogICAgICAgIHRoaXMuZ3JlZXRpbmcgPSBncmVldGluZ3M7CiAgICB9ICAgIAp9 diff --git a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt index de57be0e9fa38..dfa6433263e52 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt @@ -360,12 +360,12 @@ sourceFile:sourceMapValidationDecorators.ts 1-> 2 > x1 3 > : number = -4 > 10 -5 > ; +4 > 10; +5 > 1->Emitted(34, 5) Source(33, 20) + SourceIndex(0) 2 >Emitted(34, 15) Source(33, 22) + SourceIndex(0) 3 >Emitted(34, 18) Source(33, 33) + SourceIndex(0) -4 >Emitted(34, 20) Source(33, 35) + SourceIndex(0) +4 >Emitted(34, 20) Source(33, 36) + SourceIndex(0) 5 >Emitted(34, 21) Source(33, 36) + SourceIndex(0) --- >>> __decorate([ diff --git a/tests/baselines/reference/superAccess2.errors.txt b/tests/baselines/reference/superAccess2.errors.txt index 264d39402d0c2..29ebbb7363f30 100644 --- a/tests/baselines/reference/superAccess2.errors.txt +++ b/tests/baselines/reference/superAccess2.errors.txt @@ -1,5 +1,4 @@ tests/cases/compiler/superAccess2.ts(7,15): error TS1034: 'super' must be followed by an argument list or member access. -tests/cases/compiler/superAccess2.ts(8,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. tests/cases/compiler/superAccess2.ts(8,22): error TS1034: 'super' must be followed by an argument list or member access. tests/cases/compiler/superAccess2.ts(11,28): error TS2336: 'super' cannot be referenced in constructor arguments. tests/cases/compiler/superAccess2.ts(11,28): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class. @@ -14,7 +13,7 @@ tests/cases/compiler/superAccess2.ts(20,26): error TS1034: 'super' must be follo tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not exist on type 'typeof P'. -==== tests/cases/compiler/superAccess2.ts (14 errors) ==== +==== tests/cases/compiler/superAccess2.ts (13 errors) ==== class P { x() { } static y() { } @@ -25,8 +24,6 @@ tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not ~ !!! error TS1034: 'super' must be followed by an argument list or member access. static yy = super; // error for static initializer accessing super - ~~~~~ -!!! error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. ~ !!! error TS1034: 'super' must be followed by an argument list or member access. diff --git a/tests/baselines/reference/superAccess2.symbols b/tests/baselines/reference/superAccess2.symbols index abb3385b9705a..06611a440af92 100644 --- a/tests/baselines/reference/superAccess2.symbols +++ b/tests/baselines/reference/superAccess2.symbols @@ -19,6 +19,7 @@ class Q extends P { static yy = super; // error for static initializer accessing super >yy : Symbol(Q.yy, Decl(superAccess2.ts, 6, 15)) +>super : Symbol(P, Decl(superAccess2.ts, 0, 0)) // Super is not allowed in constructor args constructor(public z = super, zz = super, zzz = () => super) { diff --git a/tests/baselines/reference/superAccess2.types b/tests/baselines/reference/superAccess2.types index 00ae91bf4c321..c7ec9b178e5d8 100644 --- a/tests/baselines/reference/superAccess2.types +++ b/tests/baselines/reference/superAccess2.types @@ -22,7 +22,7 @@ class Q extends P { static yy = super; // error for static initializer accessing super >yy : any >super : any ->super : any +>super : typeof P > : any // Super is not allowed in constructor args diff --git a/tests/baselines/reference/thisAndSuperInStaticMembers1(target=es2015).js b/tests/baselines/reference/thisAndSuperInStaticMembers1(target=es2015).js new file mode 100644 index 0000000000000..6c766ee87a600 --- /dev/null +++ b/tests/baselines/reference/thisAndSuperInStaticMembers1(target=es2015).js @@ -0,0 +1,218 @@ +//// [thisAndSuperInStaticMembers1.ts] +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a``; + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} + +//// [thisAndSuperInStaticMembers1.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; +var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; +class C extends (_c = B) { + constructor() { + super(...arguments); + // these should be unaffected + Object.defineProperty(this, "x", { + enumerable: true, + configurable: true, + writable: true, + value: 1 + }); + Object.defineProperty(this, "y", { + enumerable: true, + configurable: true, + writable: true, + value: this.x + }); + Object.defineProperty(this, "z", { + enumerable: true, + configurable: true, + writable: true, + value: super.f() + }); + } +} +_b = C; +Object.defineProperty(C, "x", { + enumerable: true, + configurable: true, + writable: true, + value: undefined +}); +Object.defineProperty(C, "y1", { + enumerable: true, + configurable: true, + writable: true, + value: _b.x +}); +Object.defineProperty(C, "y2", { + enumerable: true, + configurable: true, + writable: true, + value: _b.x() +}); +Object.defineProperty(C, "y3", { + enumerable: true, + configurable: true, + writable: true, + value: _b === null || _b === void 0 ? void 0 : _b.x() +}); +Object.defineProperty(C, "y4", { + enumerable: true, + configurable: true, + writable: true, + value: _b[("x")]() +}); +Object.defineProperty(C, "y5", { + enumerable: true, + configurable: true, + writable: true, + value: _b === null || _b === void 0 ? void 0 : _b[("x")]() +}); +Object.defineProperty(C, "z1", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "a", _b) +}); +Object.defineProperty(C, "z2", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "a", _b) +}); +Object.defineProperty(C, "z3", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "f", _b).call(_b) +}); +Object.defineProperty(C, "z4", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "f", _b).call(_b) +}); +Object.defineProperty(C, "z5", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.set(_c, "a", _d = 0, _b), _d) +}); +Object.defineProperty(C, "z6", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.set(_c, "a", _e = Reflect.get(_c, "a", _b) + 1, _b), _e) +}); +Object.defineProperty(C, "z7", { + enumerable: true, + configurable: true, + writable: true, + value: (() => { Reflect.set(_c, "a", 0, _b); })() +}); +Object.defineProperty(C, "z8", { + enumerable: true, + configurable: true, + writable: true, + value: [({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value] = [0] +}); +Object.defineProperty(C, "z9", { + enumerable: true, + configurable: true, + writable: true, + value: [({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value = 0] = [0] +}); +Object.defineProperty(C, "z10", { + enumerable: true, + configurable: true, + writable: true, + value: [...({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value] = [0] +}); +Object.defineProperty(C, "z11", { + enumerable: true, + configurable: true, + writable: true, + value: { x: ({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value } = { x: 0 } +}); +Object.defineProperty(C, "z12", { + enumerable: true, + configurable: true, + writable: true, + value: { x: ({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value = 0 } = { x: 0 } +}); +Object.defineProperty(C, "z13", Object.assign({ enumerable: true, configurable: true, writable: true, value: (_a = { x: 0 }, ({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value = __rest(_a, []), _a) })); +Object.defineProperty(C, "z14", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.set(_c, "a", (_g = Reflect.get(_c, "a", _b), _f = ++_g), _b), _f) +}); +Object.defineProperty(C, "z15", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.set(_c, "a", (_j = Reflect.get(_c, "a", _b), _h = --_j), _b), _h) +}); +Object.defineProperty(C, "z16", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.set(_c, _k = ("a"), (_m = Reflect.get(_c, _k, _b), _l = ++_m), _b), _l) +}); +Object.defineProperty(C, "z17", { + enumerable: true, + configurable: true, + writable: true, + value: (Reflect.set(_c, "a", (_p = Reflect.get(_c, "a", _b), _o = _p++, _p), _b), _o) +}); +Object.defineProperty(C, "z18", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "a", _b).bind(_b) `` +}); diff --git a/tests/baselines/reference/thisAndSuperInStaticMembers1(target=esnext).js b/tests/baselines/reference/thisAndSuperInStaticMembers1(target=esnext).js new file mode 100644 index 0000000000000..8bf57ccac5ae9 --- /dev/null +++ b/tests/baselines/reference/thisAndSuperInStaticMembers1(target=esnext).js @@ -0,0 +1,71 @@ +//// [thisAndSuperInStaticMembers1.ts] +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a``; + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} + +//// [thisAndSuperInStaticMembers1.js] +class C extends B { + static x = undefined; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a ``; + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} diff --git a/tests/baselines/reference/thisAndSuperInStaticMembers2(target=es2015).js b/tests/baselines/reference/thisAndSuperInStaticMembers2(target=es2015).js new file mode 100644 index 0000000000000..62f9e180aecb6 --- /dev/null +++ b/tests/baselines/reference/thisAndSuperInStaticMembers2(target=es2015).js @@ -0,0 +1,88 @@ +//// [thisAndSuperInStaticMembers2.ts] +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a``; + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} + +//// [thisAndSuperInStaticMembers2.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a; +var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; +class C extends (_c = B) { + constructor() { + super(...arguments); + // these should be unaffected + this.x = 1; + this.y = this.x; + this.z = super.f(); + } +} +_b = C; +C.x = undefined; +C.y1 = _b.x; +C.y2 = _b.x(); +C.y3 = _b === null || _b === void 0 ? void 0 : _b.x(); +C.y4 = _b[("x")](); +C.y5 = _b === null || _b === void 0 ? void 0 : _b[("x")](); +C.z1 = Reflect.get(_c, "a", _b); +C.z2 = Reflect.get(_c, "a", _b); +C.z3 = Reflect.get(_c, "f", _b).call(_b); +C.z4 = Reflect.get(_c, "f", _b).call(_b); +C.z5 = (Reflect.set(_c, "a", _d = 0, _b), _d); +C.z6 = (Reflect.set(_c, "a", _e = Reflect.get(_c, "a", _b) + 1, _b), _e); +C.z7 = (() => { Reflect.set(_c, "a", 0, _b); })(); +C.z8 = [({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value] = [0]; +C.z9 = [({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value = 0] = [0]; +C.z10 = [...({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value] = [0]; +C.z11 = { x: ({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value } = { x: 0 }; +C.z12 = { x: ({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value = 0 } = { x: 0 }; +C.z13 = (_a = { x: 0 }, ({ set value(_a) { Reflect.set(_c, "a", _a, _b); } }).value = __rest(_a, []), _a); +C.z14 = (Reflect.set(_c, "a", (_g = Reflect.get(_c, "a", _b), _f = ++_g), _b), _f); +C.z15 = (Reflect.set(_c, "a", (_j = Reflect.get(_c, "a", _b), _h = --_j), _b), _h); +C.z16 = (Reflect.set(_c, _k = ("a"), (_m = Reflect.get(_c, _k, _b), _l = ++_m), _b), _l); +C.z17 = (Reflect.set(_c, "a", (_p = Reflect.get(_c, "a", _b), _o = _p++, _p), _b), _o); +C.z18 = Reflect.get(_c, "a", _b).bind(_b) ``; diff --git a/tests/baselines/reference/thisAndSuperInStaticMembers2(target=esnext).js b/tests/baselines/reference/thisAndSuperInStaticMembers2(target=esnext).js new file mode 100644 index 0000000000000..d29dc7a000638 --- /dev/null +++ b/tests/baselines/reference/thisAndSuperInStaticMembers2(target=esnext).js @@ -0,0 +1,76 @@ +//// [thisAndSuperInStaticMembers2.ts] +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a``; + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} + +//// [thisAndSuperInStaticMembers2.js] +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; +class C extends (_b = B) { + constructor() { + super(...arguments); + // these should be unaffected + this.x = 1; + this.y = this.x; + this.z = super.f(); + } +} +_a = C; +C.x = undefined; +C.y1 = _a.x; +C.y2 = _a.x(); +C.y3 = _a?.x(); +C.y4 = _a[("x")](); +C.y5 = _a?.[("x")](); +C.z1 = Reflect.get(_b, "a", _a); +C.z2 = Reflect.get(_b, "a", _a); +C.z3 = Reflect.get(_b, "f", _a).call(_a); +C.z4 = Reflect.get(_b, "f", _a).call(_a); +C.z5 = (Reflect.set(_b, "a", _c = 0, _a), _c); +C.z6 = (Reflect.set(_b, "a", _d = Reflect.get(_b, "a", _a) + 1, _a), _d); +C.z7 = (() => { Reflect.set(_b, "a", 0, _a); })(); +C.z8 = [({ set value(_c) { Reflect.set(_b, "a", _c, _a); } }).value] = [0]; +C.z9 = [({ set value(_c) { Reflect.set(_b, "a", _c, _a); } }).value = 0] = [0]; +C.z10 = [...({ set value(_c) { Reflect.set(_b, "a", _c, _a); } }).value] = [0]; +C.z11 = { x: ({ set value(_c) { Reflect.set(_b, "a", _c, _a); } }).value } = { x: 0 }; +C.z12 = { x: ({ set value(_c) { Reflect.set(_b, "a", _c, _a); } }).value = 0 } = { x: 0 }; +C.z13 = { ...({ set value(_c) { Reflect.set(_b, "a", _c, _a); } }).value } = { x: 0 }; +C.z14 = (Reflect.set(_b, "a", (_f = Reflect.get(_b, "a", _a), _e = ++_f), _a), _e); +C.z15 = (Reflect.set(_b, "a", (_h = Reflect.get(_b, "a", _a), _g = --_h), _a), _g); +C.z16 = (Reflect.set(_b, _j = ("a"), (_l = Reflect.get(_b, _j, _a), _k = ++_l), _a), _k); +C.z17 = (Reflect.set(_b, "a", (_o = Reflect.get(_b, "a", _a), _m = _o++, _o), _a), _m); +C.z18 = Reflect.get(_b, "a", _a).bind(_a) ``; diff --git a/tests/baselines/reference/thisAndSuperInStaticMembers3.js b/tests/baselines/reference/thisAndSuperInStaticMembers3.js new file mode 100644 index 0000000000000..48044bbd60fe1 --- /dev/null +++ b/tests/baselines/reference/thisAndSuperInStaticMembers3.js @@ -0,0 +1,117 @@ +//// [thisAndSuperInStaticMembers3.ts] +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z3 = super.f(); + static z4 = super["f"](); + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} + +//// [thisAndSuperInStaticMembers3.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 C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + var _this = _super !== null && _super.apply(this, arguments) || this; + // these should be unaffected + Object.defineProperty(_this, "x", { + enumerable: true, + configurable: true, + writable: true, + value: 1 + }); + Object.defineProperty(_this, "y", { + enumerable: true, + configurable: true, + writable: true, + value: _this.x + }); + Object.defineProperty(_this, "z", { + enumerable: true, + configurable: true, + writable: true, + value: _super.prototype.f.call(_this) + }); + return _this; + } + var _a; + _a = C; + Object.defineProperty(C, "x", { + enumerable: true, + configurable: true, + writable: true, + value: undefined + }); + Object.defineProperty(C, "y1", { + enumerable: true, + configurable: true, + writable: true, + value: _a.x + }); + Object.defineProperty(C, "y2", { + enumerable: true, + configurable: true, + writable: true, + value: _a.x() + }); + Object.defineProperty(C, "y3", { + enumerable: true, + configurable: true, + writable: true, + value: _a === null || _a === void 0 ? void 0 : _a.x() + }); + Object.defineProperty(C, "y4", { + enumerable: true, + configurable: true, + writable: true, + value: _a[("x")]() + }); + Object.defineProperty(C, "y5", { + enumerable: true, + configurable: true, + writable: true, + value: _a === null || _a === void 0 ? void 0 : _a[("x")]() + }); + Object.defineProperty(C, "z3", { + enumerable: true, + configurable: true, + writable: true, + value: _super.f.call(_a) + }); + Object.defineProperty(C, "z4", { + enumerable: true, + configurable: true, + writable: true, + value: _super["f"].call(_a) + }); + return C; +}(B)); diff --git a/tests/baselines/reference/thisAndSuperInStaticMembers4.js b/tests/baselines/reference/thisAndSuperInStaticMembers4.js new file mode 100644 index 0000000000000..2c0dfd7cbccee --- /dev/null +++ b/tests/baselines/reference/thisAndSuperInStaticMembers4.js @@ -0,0 +1,62 @@ +//// [thisAndSuperInStaticMembers4.ts] +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z3 = super.f(); + static z4 = super["f"](); + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} + +//// [thisAndSuperInStaticMembers4.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 C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + var _this = _super !== null && _super.apply(this, arguments) || this; + // these should be unaffected + _this.x = 1; + _this.y = _this.x; + _this.z = _super.prototype.f.call(_this); + return _this; + } + var _a; + _a = C; + C.x = undefined; + C.y1 = _a.x; + C.y2 = _a.x(); + C.y3 = _a === null || _a === void 0 ? void 0 : _a.x(); + C.y4 = _a[("x")](); + C.y5 = _a === null || _a === void 0 ? void 0 : _a[("x")](); + C.z3 = _super.f.call(_a); + C.z4 = _super["f"].call(_a); + return C; +}(B)); diff --git a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.errors.txt b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.errors.txt deleted file mode 100644 index f62b80655a6c8..0000000000000 --- a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/thisInArrowFunctionInStaticInitializer1.ts(6,7): error TS2334: 'this' cannot be referenced in a static property initializer. - - -==== tests/cases/compiler/thisInArrowFunctionInStaticInitializer1.ts (1 errors) ==== - function log(a) { } - - class Vector { - static foo = () => { - // 'this' should not be available in a static initializer. - log(this); - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js index 2d58fd455ac4a..a38a992042548 100644 --- a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js +++ b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.js @@ -3,20 +3,21 @@ function log(a) { } class Vector { static foo = () => { - // 'this' should not be available in a static initializer. + // 'this' should be allowed in a static initializer. log(this); } } //// [thisInArrowFunctionInStaticInitializer1.js] -var _this = this; function log(a) { } var Vector = /** @class */ (function () { function Vector() { } + var _a; + _a = Vector; Vector.foo = function () { - // 'this' should not be available in a static initializer. - log(_this); + // 'this' should be allowed in a static initializer. + log(_a); }; return Vector; }()); diff --git a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.symbols b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.symbols index 7bb71d768ebb9..065ebf00ffc30 100644 --- a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.symbols +++ b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.symbols @@ -9,7 +9,7 @@ class Vector { static foo = () => { >foo : Symbol(Vector.foo, Decl(thisInArrowFunctionInStaticInitializer1.ts, 2, 14)) - // 'this' should not be available in a static initializer. + // 'this' should be allowed in a static initializer. log(this); >log : Symbol(log, Decl(thisInArrowFunctionInStaticInitializer1.ts, 0, 0)) >this : Symbol(Vector, Decl(thisInArrowFunctionInStaticInitializer1.ts, 0, 19)) diff --git a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.types b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.types index 98d38d70d676f..88caef7ebf723 100644 --- a/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.types +++ b/tests/baselines/reference/thisInArrowFunctionInStaticInitializer1.types @@ -8,9 +8,9 @@ class Vector { static foo = () => { >foo : () => void ->() => { // 'this' should not be available in a static initializer. log(this); } : () => void +>() => { // 'this' should be allowed in a static initializer. log(this); } : () => void - // 'this' should not be available in a static initializer. + // 'this' should be allowed in a static initializer. log(this); >log(this) : void >log : (a: any) => void diff --git a/tests/baselines/reference/thisInConstructorParameter2.errors.txt b/tests/baselines/reference/thisInConstructorParameter2.errors.txt index 2b6ed8017c26b..b577fe5dbd483 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.errors.txt +++ b/tests/baselines/reference/thisInConstructorParameter2.errors.txt @@ -1,14 +1,11 @@ -tests/cases/compiler/thisInConstructorParameter2.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. tests/cases/compiler/thisInConstructorParameter2.ts(5,28): error TS2333: 'this' cannot be referenced in constructor arguments. tests/cases/compiler/thisInConstructorParameter2.ts(5,39): error TS2333: 'this' cannot be referenced in constructor arguments. -==== tests/cases/compiler/thisInConstructorParameter2.ts (3 errors) ==== +==== tests/cases/compiler/thisInConstructorParameter2.ts (2 errors) ==== class P { x = this; static y = this; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. constructor(public z = this, zz = this, zzz = (p = this) => this) { ~~~~ diff --git a/tests/baselines/reference/thisInConstructorParameter2.js b/tests/baselines/reference/thisInConstructorParameter2.js index df2f22b8ae7bd..3af8ee1d8d884 100644 --- a/tests/baselines/reference/thisInConstructorParameter2.js +++ b/tests/baselines/reference/thisInConstructorParameter2.js @@ -36,6 +36,8 @@ var P = /** @class */ (function () { if (zz === void 0) { zz = this; } zz.y; }; - P.y = this; + var _a; + _a = P; + P.y = _a; return P; }()); diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 7a357e1327ea5..64f2f0d8c211c 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -1,21 +1,13 @@ -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(9,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(17,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(23,13): error TS2331: 'this' cannot be referenced in a module or namespace body. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(31,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(33,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(39,9): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(40,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== - //'this' in static member initializer - class ErrClass1 { - static t = this; // Error - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (7 errors) ==== class BaseErrClass { constructor(t: any) { } } diff --git a/tests/baselines/reference/thisInInvalidContexts.js b/tests/baselines/reference/thisInInvalidContexts.js index 7e6db52458631..ba1df2c5e4d15 100644 --- a/tests/baselines/reference/thisInInvalidContexts.js +++ b/tests/baselines/reference/thisInInvalidContexts.js @@ -1,9 +1,4 @@ //// [thisInInvalidContexts.ts] -//'this' in static member initializer -class ErrClass1 { - static t = this; // Error -} - class BaseErrClass { constructor(t: any) { } } @@ -64,13 +59,6 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -//'this' in static member initializer -var ErrClass1 = /** @class */ (function () { - function ErrClass1() { - } - ErrClass1.t = this; // Error - return ErrClass1; -}()); var BaseErrClass = /** @class */ (function () { function BaseErrClass(t) { } diff --git a/tests/baselines/reference/thisInInvalidContexts.symbols b/tests/baselines/reference/thisInInvalidContexts.symbols index 7fecdf73f4397..1536697ba75cd 100644 --- a/tests/baselines/reference/thisInInvalidContexts.symbols +++ b/tests/baselines/reference/thisInInvalidContexts.symbols @@ -1,56 +1,47 @@ === tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts === -//'this' in static member initializer -class ErrClass1 { ->ErrClass1 : Symbol(ErrClass1, Decl(thisInInvalidContexts.ts, 0, 0)) - - static t = this; // Error ->t : Symbol(ErrClass1.t, Decl(thisInInvalidContexts.ts, 1, 17)) ->this : Symbol(ErrClass1, Decl(thisInInvalidContexts.ts, 0, 0)) -} - class BaseErrClass { ->BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 3, 1)) +>BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 0, 0)) constructor(t: any) { } ->t : Symbol(t, Decl(thisInInvalidContexts.ts, 6, 16)) +>t : Symbol(t, Decl(thisInInvalidContexts.ts, 1, 16)) } class ClassWithNoInitializer extends BaseErrClass { ->ClassWithNoInitializer : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContexts.ts, 7, 1)) ->BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 3, 1)) +>ClassWithNoInitializer : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContexts.ts, 2, 1)) +>BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 0, 0)) t; ->t : Symbol(ClassWithNoInitializer.t, Decl(thisInInvalidContexts.ts, 9, 51)) +>t : Symbol(ClassWithNoInitializer.t, Decl(thisInInvalidContexts.ts, 4, 51)) //'this' in optional super call constructor() { super(this); // Error ->super : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 3, 1)) ->this : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContexts.ts, 7, 1)) +>super : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 0, 0)) +>this : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContexts.ts, 2, 1)) } } class ClassWithInitializer extends BaseErrClass { ->ClassWithInitializer : Symbol(ClassWithInitializer, Decl(thisInInvalidContexts.ts, 15, 1)) ->BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 3, 1)) +>ClassWithInitializer : Symbol(ClassWithInitializer, Decl(thisInInvalidContexts.ts, 10, 1)) +>BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 0, 0)) t = 4; ->t : Symbol(ClassWithInitializer.t, Decl(thisInInvalidContexts.ts, 17, 49)) +>t : Symbol(ClassWithInitializer.t, Decl(thisInInvalidContexts.ts, 12, 49)) //'this' in required super call constructor() { super(this); // Error ->super : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 3, 1)) ->this : Symbol(ClassWithInitializer, Decl(thisInInvalidContexts.ts, 15, 1)) +>super : Symbol(BaseErrClass, Decl(thisInInvalidContexts.ts, 0, 0)) +>this : Symbol(ClassWithInitializer, Decl(thisInInvalidContexts.ts, 10, 1)) } } module M { ->M : Symbol(M, Decl(thisInInvalidContexts.ts, 23, 1)) +>M : Symbol(M, Decl(thisInInvalidContexts.ts, 18, 1)) //'this' in module variable var x = this; // Error ->x : Symbol(x, Decl(thisInInvalidContexts.ts, 27, 7)) +>x : Symbol(x, Decl(thisInInvalidContexts.ts, 22, 7)) } //'this' as type parameter constraint @@ -58,30 +49,30 @@ module M { //'this' as a type argument function genericFunc(x: T) { } ->genericFunc : Symbol(genericFunc, Decl(thisInInvalidContexts.ts, 28, 1)) ->T : Symbol(T, Decl(thisInInvalidContexts.ts, 34, 21)) ->x : Symbol(x, Decl(thisInInvalidContexts.ts, 34, 24)) ->T : Symbol(T, Decl(thisInInvalidContexts.ts, 34, 21)) +>genericFunc : Symbol(genericFunc, Decl(thisInInvalidContexts.ts, 23, 1)) +>T : Symbol(T, Decl(thisInInvalidContexts.ts, 29, 21)) +>x : Symbol(x, Decl(thisInInvalidContexts.ts, 29, 24)) +>T : Symbol(T, Decl(thisInInvalidContexts.ts, 29, 21)) genericFunc(undefined); // Should be an error ->genericFunc : Symbol(genericFunc, Decl(thisInInvalidContexts.ts, 28, 1)) +>genericFunc : Symbol(genericFunc, Decl(thisInInvalidContexts.ts, 23, 1)) >undefined : Symbol(undefined) class ErrClass3 extends this { ->ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContexts.ts, 35, 29)) +>ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContexts.ts, 30, 29)) >this : Symbol(globalThis) } //'this' as a computed enum value enum SomeEnum { ->SomeEnum : Symbol(SomeEnum, Decl(thisInInvalidContexts.ts, 39, 1)) +>SomeEnum : Symbol(SomeEnum, Decl(thisInInvalidContexts.ts, 34, 1)) A = this, // Should not be allowed ->A : Symbol(SomeEnum.A, Decl(thisInInvalidContexts.ts, 42, 15)) +>A : Symbol(SomeEnum.A, Decl(thisInInvalidContexts.ts, 37, 15)) B = this.spaaaace // Also should not be allowed ->B : Symbol(SomeEnum.B, Decl(thisInInvalidContexts.ts, 43, 13)) +>B : Symbol(SomeEnum.B, Decl(thisInInvalidContexts.ts, 38, 13)) } diff --git a/tests/baselines/reference/thisInInvalidContexts.types b/tests/baselines/reference/thisInInvalidContexts.types index 6f35006b6c12a..e247e4678d7fd 100644 --- a/tests/baselines/reference/thisInInvalidContexts.types +++ b/tests/baselines/reference/thisInInvalidContexts.types @@ -1,13 +1,4 @@ === tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts === -//'this' in static member initializer -class ErrClass1 { ->ErrClass1 : ErrClass1 - - static t = this; // Error ->t : typeof ErrClass1 ->this : typeof ErrClass1 -} - class BaseErrClass { >BaseErrClass : BaseErrClass diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index 18f0e314a8ae7..c4f90b417a4c3 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -1,21 +1,13 @@ -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(3,16): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(14,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'undefined' is not a constructor function type. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(44,9): error TS2332: 'this' cannot be referenced in current location. -tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(9,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(17,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(23,13): error TS2331: 'this' cannot be referenced in a module or namespace body. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(31,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(33,25): error TS2507: Type 'undefined' is not a constructor function type. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(39,9): error TS2332: 'this' cannot be referenced in current location. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(40,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (8 errors) ==== - //'this' in static member initializer - class ErrClass1 { - static t = this; // Error - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (7 errors) ==== class BaseErrClass { constructor(t: any) { } } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.js b/tests/baselines/reference/thisInInvalidContextsExternalModule.js index ef18f01edda0c..4866f66f59de4 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.js +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.js @@ -1,9 +1,4 @@ //// [thisInInvalidContextsExternalModule.ts] -//'this' in static member initializer -class ErrClass1 { - static t = this; // Error -} - class BaseErrClass { constructor(t: any) { } } @@ -65,13 +60,6 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -//'this' in static member initializer -var ErrClass1 = /** @class */ (function () { - function ErrClass1() { - } - ErrClass1.t = this; // Error - return ErrClass1; -}()); var BaseErrClass = /** @class */ (function () { function BaseErrClass(t) { } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols index 9cf261fa672b3..ed9b09565cfe1 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols @@ -1,56 +1,47 @@ === tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts === -//'this' in static member initializer -class ErrClass1 { ->ErrClass1 : Symbol(ErrClass1, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) - - static t = this; // Error ->t : Symbol(ErrClass1.t, Decl(thisInInvalidContextsExternalModule.ts, 1, 17)) ->this : Symbol(ErrClass1, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) -} - class BaseErrClass { ->BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 3, 1)) +>BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) constructor(t: any) { } ->t : Symbol(t, Decl(thisInInvalidContextsExternalModule.ts, 6, 16)) +>t : Symbol(t, Decl(thisInInvalidContextsExternalModule.ts, 1, 16)) } class ClassWithNoInitializer extends BaseErrClass { ->ClassWithNoInitializer : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContextsExternalModule.ts, 7, 1)) ->BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 3, 1)) +>ClassWithNoInitializer : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContextsExternalModule.ts, 2, 1)) +>BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) t; ->t : Symbol(ClassWithNoInitializer.t, Decl(thisInInvalidContextsExternalModule.ts, 9, 51)) +>t : Symbol(ClassWithNoInitializer.t, Decl(thisInInvalidContextsExternalModule.ts, 4, 51)) //'this' in optional super call constructor() { super(this); // error: "super" has to be called before "this" accessing ->super : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 3, 1)) ->this : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContextsExternalModule.ts, 7, 1)) +>super : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) +>this : Symbol(ClassWithNoInitializer, Decl(thisInInvalidContextsExternalModule.ts, 2, 1)) } } class ClassWithInitializer extends BaseErrClass { ->ClassWithInitializer : Symbol(ClassWithInitializer, Decl(thisInInvalidContextsExternalModule.ts, 15, 1)) ->BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 3, 1)) +>ClassWithInitializer : Symbol(ClassWithInitializer, Decl(thisInInvalidContextsExternalModule.ts, 10, 1)) +>BaseErrClass : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) t = 4; ->t : Symbol(ClassWithInitializer.t, Decl(thisInInvalidContextsExternalModule.ts, 17, 49)) +>t : Symbol(ClassWithInitializer.t, Decl(thisInInvalidContextsExternalModule.ts, 12, 49)) //'this' in required super call constructor() { super(this); // Error ->super : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 3, 1)) ->this : Symbol(ClassWithInitializer, Decl(thisInInvalidContextsExternalModule.ts, 15, 1)) +>super : Symbol(BaseErrClass, Decl(thisInInvalidContextsExternalModule.ts, 0, 0)) +>this : Symbol(ClassWithInitializer, Decl(thisInInvalidContextsExternalModule.ts, 10, 1)) } } module M { ->M : Symbol(M, Decl(thisInInvalidContextsExternalModule.ts, 23, 1)) +>M : Symbol(M, Decl(thisInInvalidContextsExternalModule.ts, 18, 1)) //'this' in module variable var x = this; // Error ->x : Symbol(x, Decl(thisInInvalidContextsExternalModule.ts, 27, 7)) +>x : Symbol(x, Decl(thisInInvalidContextsExternalModule.ts, 22, 7)) } //'this' as type parameter constraint @@ -58,29 +49,29 @@ module M { //'this' as a type argument function genericFunc(x: T) { } ->genericFunc : Symbol(genericFunc, Decl(thisInInvalidContextsExternalModule.ts, 28, 1)) ->T : Symbol(T, Decl(thisInInvalidContextsExternalModule.ts, 34, 21)) ->x : Symbol(x, Decl(thisInInvalidContextsExternalModule.ts, 34, 24)) ->T : Symbol(T, Decl(thisInInvalidContextsExternalModule.ts, 34, 21)) +>genericFunc : Symbol(genericFunc, Decl(thisInInvalidContextsExternalModule.ts, 23, 1)) +>T : Symbol(T, Decl(thisInInvalidContextsExternalModule.ts, 29, 21)) +>x : Symbol(x, Decl(thisInInvalidContextsExternalModule.ts, 29, 24)) +>T : Symbol(T, Decl(thisInInvalidContextsExternalModule.ts, 29, 21)) genericFunc(undefined); // Should be an error ->genericFunc : Symbol(genericFunc, Decl(thisInInvalidContextsExternalModule.ts, 28, 1)) +>genericFunc : Symbol(genericFunc, Decl(thisInInvalidContextsExternalModule.ts, 23, 1)) >undefined : Symbol(undefined) class ErrClass3 extends this { ->ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContextsExternalModule.ts, 35, 29)) +>ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContextsExternalModule.ts, 30, 29)) } //'this' as a computed enum value enum SomeEnum { ->SomeEnum : Symbol(SomeEnum, Decl(thisInInvalidContextsExternalModule.ts, 39, 1)) +>SomeEnum : Symbol(SomeEnum, Decl(thisInInvalidContextsExternalModule.ts, 34, 1)) A = this, // Should not be allowed ->A : Symbol(SomeEnum.A, Decl(thisInInvalidContextsExternalModule.ts, 42, 15)) +>A : Symbol(SomeEnum.A, Decl(thisInInvalidContextsExternalModule.ts, 37, 15)) B = this.spaaaace // Also should not be allowed ->B : Symbol(SomeEnum.B, Decl(thisInInvalidContextsExternalModule.ts, 43, 13)) +>B : Symbol(SomeEnum.B, Decl(thisInInvalidContextsExternalModule.ts, 38, 13)) } export = this; // Should be an error diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.types b/tests/baselines/reference/thisInInvalidContextsExternalModule.types index cbd78a8bce4db..ddd2e105f60e0 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.types +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.types @@ -1,13 +1,4 @@ === tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts === -//'this' in static member initializer -class ErrClass1 { ->ErrClass1 : ErrClass1 - - static t = this; // Error ->t : typeof ErrClass1 ->this : typeof ErrClass1 -} - class BaseErrClass { >BaseErrClass : BaseErrClass diff --git a/tests/baselines/reference/thisInOuterClassBody.errors.txt b/tests/baselines/reference/thisInOuterClassBody.errors.txt index 1eeabf22e2917..e002e87900faf 100644 --- a/tests/baselines/reference/thisInOuterClassBody.errors.txt +++ b/tests/baselines/reference/thisInOuterClassBody.errors.txt @@ -1,16 +1,13 @@ -tests/cases/compiler/thisInOuterClassBody.ts(5,16): error TS2334: 'this' cannot be referenced in a static property initializer. tests/cases/compiler/thisInOuterClassBody.ts(12,22): error TS2576: Property 'y' does not exist on type 'Foo'. Did you mean to access the static member 'Foo.y' instead? tests/cases/compiler/thisInOuterClassBody.ts(18,22): error TS2339: Property 'x' does not exist on type 'typeof Foo'. -==== tests/cases/compiler/thisInOuterClassBody.ts (3 errors) ==== +==== tests/cases/compiler/thisInOuterClassBody.ts (2 errors) ==== class Foo { x = this; static y = this; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. bar() { diff --git a/tests/baselines/reference/thisInOuterClassBody.js b/tests/baselines/reference/thisInOuterClassBody.js index 2b4e3a1aabdb6..79a95c4763762 100644 --- a/tests/baselines/reference/thisInOuterClassBody.js +++ b/tests/baselines/reference/thisInOuterClassBody.js @@ -36,6 +36,8 @@ var Foo = /** @class */ (function () { var a = this.y; var b = this.x; }; - Foo.y = this; + var _a; + _a = Foo; + Foo.y = _a; return Foo; }()); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).errors.txt new file mode 100644 index 0000000000000..614a87fc98c10 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).errors.txt @@ -0,0 +1,69 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(6,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(12,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(13,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(13,26): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(14,22): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(35,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts (6 errors) ==== + declare const foo: any; + + @foo + class C { + static a = 1; + static b = this.a + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + } + + @foo + class D extends C { + static c = 2; + static d = this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static e = super.a + this.c + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static f = () => this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + + class CC { + static a = 1; + static b = this.a + 1; + } + + class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).js new file mode 100644 index 0000000000000..339ede54e72f5 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).js @@ -0,0 +1,146 @@ +//// [typeOfThisInStaticMembers10.ts] +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + + +//// [typeOfThisInStaticMembers10.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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var C = /** @class */ (function () { + function C() { + } + C.a = 1; + C.b = (void 0).a + 1; + C = __decorate([ + foo + ], C); + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + D.foo = function () { + return this.c + 1; + }; + Object.defineProperty(D, "fa", { + get: function () { + return this.c + 1; + }, + set: function (v) { + this.c = v + 1; + }, + enumerable: false, + configurable: true + }); + D.c = 2; + D.d = (void 0).c + 1; + D.e = _super.a + (void 0).c + 1; + D.f = function () { return (void 0).c + 1; }; + D.ff = function () { this.c + 1; }; + D = __decorate([ + foo + ], D); + return D; +}(C)); +var CC = /** @class */ (function () { + function CC() { + } + var _a; + _a = CC; + CC.a = 1; + CC.b = _a.a + 1; + return CC; +}()); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD() { + return _super !== null && _super.apply(this, arguments) || this; + } + DD.foo = function () { + return this.c + 1; + }; + Object.defineProperty(DD, "fa", { + get: function () { + return this.c + 1; + }, + set: function (v) { + this.c = v + 1; + }, + enumerable: false, + configurable: true + }); + var _b; + _b = DD; + DD.c = 2; + DD.d = _b.c + 1; + DD.e = _super.a + _b.c + 1; + DD.f = function () { return _b.c + 1; }; + DD.ff = function () { this.c + 1; }; + return DD; +}(CC)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).symbols new file mode 100644 index 0000000000000..32b2ea3fd4926 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).symbols @@ -0,0 +1,154 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts === +declare const foo: any; +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers10.ts, 4, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +} + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers10.ts, 10, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers10.ts, 11, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static f = () => this.c + 1; +>f : Symbol(D.f, Decl(typeOfThisInStaticMembers10.ts, 12, 36)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static ff = function () { this.c + 1 } +>ff : Symbol(D.ff, Decl(typeOfThisInStaticMembers10.ts, 13, 32)) + + static foo () { +>foo : Symbol(D.foo, Decl(typeOfThisInStaticMembers10.ts, 14, 42)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + } + static get fa () { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers10.ts, 17, 5), Decl(typeOfThisInStaticMembers10.ts, 20, 5)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + } + static set fa (v: number) { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers10.ts, 17, 5), Decl(typeOfThisInStaticMembers10.ts, 20, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 21, 19)) + + this.c = v + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 21, 19)) + } +} + +class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) + + static a = 1; +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) + + static b = this.a + 1; +>b : Symbol(CC.b, Decl(typeOfThisInStaticMembers10.ts, 27, 17)) +>this.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +} + +class DD extends CC { +>DD : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) + + static c = 2; +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static d = this.c + 1; +>d : Symbol(DD.d, Decl(typeOfThisInStaticMembers10.ts, 32, 17)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static e = super.a + this.c + 1; +>e : Symbol(DD.e, Decl(typeOfThisInStaticMembers10.ts, 33, 26)) +>super.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>super : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static f = () => this.c + 1; +>f : Symbol(DD.f, Decl(typeOfThisInStaticMembers10.ts, 34, 36)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static ff = function () { this.c + 1 } +>ff : Symbol(DD.ff, Decl(typeOfThisInStaticMembers10.ts, 35, 32)) + + static foo () { +>foo : Symbol(DD.foo, Decl(typeOfThisInStaticMembers10.ts, 36, 42)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + } + static get fa () { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers10.ts, 39, 5), Decl(typeOfThisInStaticMembers10.ts, 42, 5)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + } + static set fa (v: number) { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers10.ts, 39, 5), Decl(typeOfThisInStaticMembers10.ts, 42, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 43, 19)) + + this.c = v + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 43, 19)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).types new file mode 100644 index 0000000000000..824241e883d28 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es5).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts === +declare const foo: any; +>foo : any + +@foo +>foo : any + +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +@foo +>foo : any + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof D +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + +class CC { +>CC : CC + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof CC +>a : number +>1 : 1 +} + +class DD extends CC { +>DD : DD +>CC : CC + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof CC +>a : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof DD +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).errors.txt new file mode 100644 index 0000000000000..be9735d6cd4ee --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).errors.txt @@ -0,0 +1,63 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(6,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(12,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(13,26): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(14,22): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts (4 errors) ==== + declare const foo: any; + + @foo + class C { + static a = 1; + static b = this.a + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + } + + @foo + class D extends C { + static c = 2; + static d = this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static e = super.a + this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static f = () => this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + + class CC { + static a = 1; + static b = this.a + 1; + } + + class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).js new file mode 100644 index 0000000000000..a45a5c9915488 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).js @@ -0,0 +1,106 @@ +//// [typeOfThisInStaticMembers10.ts] +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + + +//// [typeOfThisInStaticMembers10.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var _a, _b, _c; +let C = class C { +}; +C.a = 1; +C.b = (void 0).a + 1; +C = __decorate([ + foo +], C); +let D = class D extends C { + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +}; +D.c = 2; +D.d = (void 0).c + 1; +D.e = (void 0).a + (void 0).c + 1; +D.f = () => (void 0).c + 1; +D.ff = function () { this.c + 1; }; +D = __decorate([ + foo +], D); +class CC { +} +_a = CC; +CC.a = 1; +CC.b = _a.a + 1; +class DD extends (_c = CC) { + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +} +_b = DD; +DD.c = 2; +DD.d = _b.c + 1; +DD.e = Reflect.get(_c, "a", _b) + _b.c + 1; +DD.f = () => _b.c + 1; +DD.ff = function () { this.c + 1; }; diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).symbols new file mode 100644 index 0000000000000..32b2ea3fd4926 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).symbols @@ -0,0 +1,154 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts === +declare const foo: any; +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers10.ts, 4, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +} + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers10.ts, 10, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers10.ts, 11, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static f = () => this.c + 1; +>f : Symbol(D.f, Decl(typeOfThisInStaticMembers10.ts, 12, 36)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static ff = function () { this.c + 1 } +>ff : Symbol(D.ff, Decl(typeOfThisInStaticMembers10.ts, 13, 32)) + + static foo () { +>foo : Symbol(D.foo, Decl(typeOfThisInStaticMembers10.ts, 14, 42)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + } + static get fa () { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers10.ts, 17, 5), Decl(typeOfThisInStaticMembers10.ts, 20, 5)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + } + static set fa (v: number) { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers10.ts, 17, 5), Decl(typeOfThisInStaticMembers10.ts, 20, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 21, 19)) + + this.c = v + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 21, 19)) + } +} + +class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) + + static a = 1; +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) + + static b = this.a + 1; +>b : Symbol(CC.b, Decl(typeOfThisInStaticMembers10.ts, 27, 17)) +>this.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +} + +class DD extends CC { +>DD : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) + + static c = 2; +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static d = this.c + 1; +>d : Symbol(DD.d, Decl(typeOfThisInStaticMembers10.ts, 32, 17)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static e = super.a + this.c + 1; +>e : Symbol(DD.e, Decl(typeOfThisInStaticMembers10.ts, 33, 26)) +>super.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>super : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static f = () => this.c + 1; +>f : Symbol(DD.f, Decl(typeOfThisInStaticMembers10.ts, 34, 36)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static ff = function () { this.c + 1 } +>ff : Symbol(DD.ff, Decl(typeOfThisInStaticMembers10.ts, 35, 32)) + + static foo () { +>foo : Symbol(DD.foo, Decl(typeOfThisInStaticMembers10.ts, 36, 42)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + } + static get fa () { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers10.ts, 39, 5), Decl(typeOfThisInStaticMembers10.ts, 42, 5)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + } + static set fa (v: number) { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers10.ts, 39, 5), Decl(typeOfThisInStaticMembers10.ts, 42, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 43, 19)) + + this.c = v + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 43, 19)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).types new file mode 100644 index 0000000000000..824241e883d28 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=es6).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts === +declare const foo: any; +>foo : any + +@foo +>foo : any + +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +@foo +>foo : any + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof D +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + +class CC { +>CC : CC + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof CC +>a : number +>1 : 1 +} + +class DD extends CC { +>DD : DD +>CC : CC + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof CC +>a : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof DD +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).errors.txt new file mode 100644 index 0000000000000..be9735d6cd4ee --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).errors.txt @@ -0,0 +1,63 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(6,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(12,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(13,26): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts(14,22): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts (4 errors) ==== + declare const foo: any; + + @foo + class C { + static a = 1; + static b = this.a + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + } + + @foo + class D extends C { + static c = 2; + static d = this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static e = super.a + this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static f = () => this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + + class CC { + static a = 1; + static b = this.a + 1; + } + + class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).js new file mode 100644 index 0000000000000..a45a5c9915488 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).js @@ -0,0 +1,106 @@ +//// [typeOfThisInStaticMembers10.ts] +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + + +//// [typeOfThisInStaticMembers10.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var _a, _b, _c; +let C = class C { +}; +C.a = 1; +C.b = (void 0).a + 1; +C = __decorate([ + foo +], C); +let D = class D extends C { + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +}; +D.c = 2; +D.d = (void 0).c + 1; +D.e = (void 0).a + (void 0).c + 1; +D.f = () => (void 0).c + 1; +D.ff = function () { this.c + 1; }; +D = __decorate([ + foo +], D); +class CC { +} +_a = CC; +CC.a = 1; +CC.b = _a.a + 1; +class DD extends (_c = CC) { + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +} +_b = DD; +DD.c = 2; +DD.d = _b.c + 1; +DD.e = Reflect.get(_c, "a", _b) + _b.c + 1; +DD.f = () => _b.c + 1; +DD.ff = function () { this.c + 1; }; diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).symbols new file mode 100644 index 0000000000000..32b2ea3fd4926 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).symbols @@ -0,0 +1,154 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts === +declare const foo: any; +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers10.ts, 4, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +} + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers10.ts, 0, 13)) + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers10.ts, 10, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers10.ts, 11, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers10.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers10.ts, 3, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static f = () => this.c + 1; +>f : Symbol(D.f, Decl(typeOfThisInStaticMembers10.ts, 12, 36)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + + static ff = function () { this.c + 1 } +>ff : Symbol(D.ff, Decl(typeOfThisInStaticMembers10.ts, 13, 32)) + + static foo () { +>foo : Symbol(D.foo, Decl(typeOfThisInStaticMembers10.ts, 14, 42)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + } + static get fa () { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers10.ts, 17, 5), Decl(typeOfThisInStaticMembers10.ts, 20, 5)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) + } + static set fa (v: number) { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers10.ts, 17, 5), Decl(typeOfThisInStaticMembers10.ts, 20, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 21, 19)) + + this.c = v + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers10.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers10.ts, 9, 19)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 21, 19)) + } +} + +class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) + + static a = 1; +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) + + static b = this.a + 1; +>b : Symbol(CC.b, Decl(typeOfThisInStaticMembers10.ts, 27, 17)) +>this.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +} + +class DD extends CC { +>DD : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) + + static c = 2; +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static d = this.c + 1; +>d : Symbol(DD.d, Decl(typeOfThisInStaticMembers10.ts, 32, 17)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static e = super.a + this.c + 1; +>e : Symbol(DD.e, Decl(typeOfThisInStaticMembers10.ts, 33, 26)) +>super.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>super : Symbol(CC, Decl(typeOfThisInStaticMembers10.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers10.ts, 26, 10)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static f = () => this.c + 1; +>f : Symbol(DD.f, Decl(typeOfThisInStaticMembers10.ts, 34, 36)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + + static ff = function () { this.c + 1 } +>ff : Symbol(DD.ff, Decl(typeOfThisInStaticMembers10.ts, 35, 32)) + + static foo () { +>foo : Symbol(DD.foo, Decl(typeOfThisInStaticMembers10.ts, 36, 42)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + } + static get fa () { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers10.ts, 39, 5), Decl(typeOfThisInStaticMembers10.ts, 42, 5)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) + } + static set fa (v: number) { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers10.ts, 39, 5), Decl(typeOfThisInStaticMembers10.ts, 42, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 43, 19)) + + this.c = v + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers10.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers10.ts, 31, 21)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers10.ts, 43, 19)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).types new file mode 100644 index 0000000000000..824241e883d28 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers10(target=esnext).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts === +declare const foo: any; +>foo : any + +@foo +>foo : any + +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +@foo +>foo : any + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof D +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + +class CC { +>CC : CC + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof CC +>a : number +>1 : 1 +} + +class DD extends CC { +>DD : DD +>CC : CC + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof CC +>a : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof DD +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).errors.txt new file mode 100644 index 0000000000000..64617e206600a --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).errors.txt @@ -0,0 +1,69 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(6,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(12,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(13,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(13,26): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(14,22): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(35,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts (6 errors) ==== + declare const foo: any; + + @foo + class C { + static a = 1; + static b = this.a + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + } + + @foo + class D extends C { + static c = 2; + static d = this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static e = super.a + this.c + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static f = () => this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + + class CC { + static a = 1; + static b = this.a + 1; + } + + class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).js new file mode 100644 index 0000000000000..cd9f3555b7262 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).js @@ -0,0 +1,226 @@ +//// [typeOfThisInStaticMembers11.ts] +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + + +//// [typeOfThisInStaticMembers11.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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var C = /** @class */ (function () { + function C() { + } + Object.defineProperty(C, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 + }); + Object.defineProperty(C, "b", { + enumerable: true, + configurable: true, + writable: true, + value: (void 0).a + 1 + }); + C = __decorate([ + foo + ], C); + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + Object.defineProperty(D, "foo", { + enumerable: false, + configurable: true, + writable: true, + value: function () { + return this.c + 1; + } + }); + Object.defineProperty(D, "fa", { + get: function () { + return this.c + 1; + }, + set: function (v) { + this.c = v + 1; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(D, "c", { + enumerable: true, + configurable: true, + writable: true, + value: 2 + }); + Object.defineProperty(D, "d", { + enumerable: true, + configurable: true, + writable: true, + value: (void 0).c + 1 + }); + Object.defineProperty(D, "e", { + enumerable: true, + configurable: true, + writable: true, + value: _super.a + (void 0).c + 1 + }); + Object.defineProperty(D, "f", { + enumerable: true, + configurable: true, + writable: true, + value: function () { return (void 0).c + 1; } + }); + Object.defineProperty(D, "ff", { + enumerable: true, + configurable: true, + writable: true, + value: function () { this.c + 1; } + }); + D = __decorate([ + foo + ], D); + return D; +}(C)); +var CC = /** @class */ (function () { + function CC() { + } + var _a; + _a = CC; + Object.defineProperty(CC, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 + }); + Object.defineProperty(CC, "b", { + enumerable: true, + configurable: true, + writable: true, + value: _a.a + 1 + }); + return CC; +}()); +var DD = /** @class */ (function (_super) { + __extends(DD, _super); + function DD() { + return _super !== null && _super.apply(this, arguments) || this; + } + Object.defineProperty(DD, "foo", { + enumerable: false, + configurable: true, + writable: true, + value: function () { + return this.c + 1; + } + }); + Object.defineProperty(DD, "fa", { + get: function () { + return this.c + 1; + }, + set: function (v) { + this.c = v + 1; + }, + enumerable: false, + configurable: true + }); + var _b; + _b = DD; + Object.defineProperty(DD, "c", { + enumerable: true, + configurable: true, + writable: true, + value: 2 + }); + Object.defineProperty(DD, "d", { + enumerable: true, + configurable: true, + writable: true, + value: _b.c + 1 + }); + Object.defineProperty(DD, "e", { + enumerable: true, + configurable: true, + writable: true, + value: _super.a + _b.c + 1 + }); + Object.defineProperty(DD, "f", { + enumerable: true, + configurable: true, + writable: true, + value: function () { return _b.c + 1; } + }); + Object.defineProperty(DD, "ff", { + enumerable: true, + configurable: true, + writable: true, + value: function () { this.c + 1; } + }); + return DD; +}(CC)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).symbols new file mode 100644 index 0000000000000..d1df5efc4080b --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).symbols @@ -0,0 +1,154 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts === +declare const foo: any; +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers11.ts, 4, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +} + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers11.ts, 10, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers11.ts, 11, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static f = () => this.c + 1; +>f : Symbol(D.f, Decl(typeOfThisInStaticMembers11.ts, 12, 36)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static ff = function () { this.c + 1 } +>ff : Symbol(D.ff, Decl(typeOfThisInStaticMembers11.ts, 13, 32)) + + static foo () { +>foo : Symbol(D.foo, Decl(typeOfThisInStaticMembers11.ts, 14, 42)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + } + static get fa () { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers11.ts, 17, 5), Decl(typeOfThisInStaticMembers11.ts, 20, 5)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + } + static set fa (v: number) { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers11.ts, 17, 5), Decl(typeOfThisInStaticMembers11.ts, 20, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 21, 19)) + + this.c = v + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 21, 19)) + } +} + +class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) + + static a = 1; +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) + + static b = this.a + 1; +>b : Symbol(CC.b, Decl(typeOfThisInStaticMembers11.ts, 27, 17)) +>this.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +} + +class DD extends CC { +>DD : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) + + static c = 2; +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static d = this.c + 1; +>d : Symbol(DD.d, Decl(typeOfThisInStaticMembers11.ts, 32, 17)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static e = super.a + this.c + 1; +>e : Symbol(DD.e, Decl(typeOfThisInStaticMembers11.ts, 33, 26)) +>super.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>super : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static f = () => this.c + 1; +>f : Symbol(DD.f, Decl(typeOfThisInStaticMembers11.ts, 34, 36)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static ff = function () { this.c + 1 } +>ff : Symbol(DD.ff, Decl(typeOfThisInStaticMembers11.ts, 35, 32)) + + static foo () { +>foo : Symbol(DD.foo, Decl(typeOfThisInStaticMembers11.ts, 36, 42)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + } + static get fa () { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers11.ts, 39, 5), Decl(typeOfThisInStaticMembers11.ts, 42, 5)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + } + static set fa (v: number) { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers11.ts, 39, 5), Decl(typeOfThisInStaticMembers11.ts, 42, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 43, 19)) + + this.c = v + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 43, 19)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).types new file mode 100644 index 0000000000000..44ad35960ec92 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es5).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts === +declare const foo: any; +>foo : any + +@foo +>foo : any + +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +@foo +>foo : any + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof D +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + +class CC { +>CC : CC + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof CC +>a : number +>1 : 1 +} + +class DD extends CC { +>DD : DD +>CC : CC + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof CC +>a : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof DD +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).errors.txt new file mode 100644 index 0000000000000..2e699c701e689 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).errors.txt @@ -0,0 +1,63 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(6,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(12,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(13,26): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(14,22): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts (4 errors) ==== + declare const foo: any; + + @foo + class C { + static a = 1; + static b = this.a + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + } + + @foo + class D extends C { + static c = 2; + static d = this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static e = super.a + this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static f = () => this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + + class CC { + static a = 1; + static b = this.a + 1; + } + + class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).js new file mode 100644 index 0000000000000..7057d06a10006 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).js @@ -0,0 +1,176 @@ +//// [typeOfThisInStaticMembers11.ts] +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + + +//// [typeOfThisInStaticMembers11.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var _a, _b, _c; +let C = class C { +}; +Object.defineProperty(C, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 +}); +Object.defineProperty(C, "b", { + enumerable: true, + configurable: true, + writable: true, + value: (void 0).a + 1 +}); +C = __decorate([ + foo +], C); +let D = class D extends C { + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +}; +Object.defineProperty(D, "c", { + enumerable: true, + configurable: true, + writable: true, + value: 2 +}); +Object.defineProperty(D, "d", { + enumerable: true, + configurable: true, + writable: true, + value: (void 0).c + 1 +}); +Object.defineProperty(D, "e", { + enumerable: true, + configurable: true, + writable: true, + value: (void 0).a + (void 0).c + 1 +}); +Object.defineProperty(D, "f", { + enumerable: true, + configurable: true, + writable: true, + value: () => (void 0).c + 1 +}); +Object.defineProperty(D, "ff", { + enumerable: true, + configurable: true, + writable: true, + value: function () { this.c + 1; } +}); +D = __decorate([ + foo +], D); +class CC { +} +_a = CC; +Object.defineProperty(CC, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 +}); +Object.defineProperty(CC, "b", { + enumerable: true, + configurable: true, + writable: true, + value: _a.a + 1 +}); +class DD extends (_c = CC) { + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +} +_b = DD; +Object.defineProperty(DD, "c", { + enumerable: true, + configurable: true, + writable: true, + value: 2 +}); +Object.defineProperty(DD, "d", { + enumerable: true, + configurable: true, + writable: true, + value: _b.c + 1 +}); +Object.defineProperty(DD, "e", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "a", _b) + _b.c + 1 +}); +Object.defineProperty(DD, "f", { + enumerable: true, + configurable: true, + writable: true, + value: () => _b.c + 1 +}); +Object.defineProperty(DD, "ff", { + enumerable: true, + configurable: true, + writable: true, + value: function () { this.c + 1; } +}); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).symbols new file mode 100644 index 0000000000000..d1df5efc4080b --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).symbols @@ -0,0 +1,154 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts === +declare const foo: any; +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers11.ts, 4, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +} + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers11.ts, 10, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers11.ts, 11, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static f = () => this.c + 1; +>f : Symbol(D.f, Decl(typeOfThisInStaticMembers11.ts, 12, 36)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static ff = function () { this.c + 1 } +>ff : Symbol(D.ff, Decl(typeOfThisInStaticMembers11.ts, 13, 32)) + + static foo () { +>foo : Symbol(D.foo, Decl(typeOfThisInStaticMembers11.ts, 14, 42)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + } + static get fa () { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers11.ts, 17, 5), Decl(typeOfThisInStaticMembers11.ts, 20, 5)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + } + static set fa (v: number) { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers11.ts, 17, 5), Decl(typeOfThisInStaticMembers11.ts, 20, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 21, 19)) + + this.c = v + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 21, 19)) + } +} + +class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) + + static a = 1; +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) + + static b = this.a + 1; +>b : Symbol(CC.b, Decl(typeOfThisInStaticMembers11.ts, 27, 17)) +>this.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +} + +class DD extends CC { +>DD : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) + + static c = 2; +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static d = this.c + 1; +>d : Symbol(DD.d, Decl(typeOfThisInStaticMembers11.ts, 32, 17)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static e = super.a + this.c + 1; +>e : Symbol(DD.e, Decl(typeOfThisInStaticMembers11.ts, 33, 26)) +>super.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>super : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static f = () => this.c + 1; +>f : Symbol(DD.f, Decl(typeOfThisInStaticMembers11.ts, 34, 36)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static ff = function () { this.c + 1 } +>ff : Symbol(DD.ff, Decl(typeOfThisInStaticMembers11.ts, 35, 32)) + + static foo () { +>foo : Symbol(DD.foo, Decl(typeOfThisInStaticMembers11.ts, 36, 42)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + } + static get fa () { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers11.ts, 39, 5), Decl(typeOfThisInStaticMembers11.ts, 42, 5)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + } + static set fa (v: number) { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers11.ts, 39, 5), Decl(typeOfThisInStaticMembers11.ts, 42, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 43, 19)) + + this.c = v + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 43, 19)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).types new file mode 100644 index 0000000000000..44ad35960ec92 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=es6).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts === +declare const foo: any; +>foo : any + +@foo +>foo : any + +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +@foo +>foo : any + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof D +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + +class CC { +>CC : CC + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof CC +>a : number +>1 : 1 +} + +class DD extends CC { +>DD : DD +>CC : CC + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof CC +>a : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof DD +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).errors.txt new file mode 100644 index 0000000000000..2e699c701e689 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).errors.txt @@ -0,0 +1,63 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(6,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(12,16): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(13,26): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts(14,22): error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts (4 errors) ==== + declare const foo: any; + + @foo + class C { + static a = 1; + static b = this.a + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + } + + @foo + class D extends C { + static c = 2; + static d = this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static e = super.a + this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static f = () => this.c + 1; + ~~~~ +!!! error TS2816: Cannot use 'this' in a static property initializer of a decorated class. + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + + class CC { + static a = 1; + static b = this.a + 1; + } + + class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).js new file mode 100644 index 0000000000000..3e3c578c3dde8 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).js @@ -0,0 +1,103 @@ +//// [typeOfThisInStaticMembers11.ts] +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + + +//// [typeOfThisInStaticMembers11.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +let C = class C { + static a = 1; + static b = this.a + 1; +}; +C = __decorate([ + foo +], C); +let D = class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1; }; + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +}; +D = __decorate([ + foo +], D); +class CC { + static a = 1; + static b = this.a + 1; +} +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1; }; + static foo() { + return this.c + 1; + } + static get fa() { + return this.c + 1; + } + static set fa(v) { + this.c = v + 1; + } +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).symbols new file mode 100644 index 0000000000000..d1df5efc4080b --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).symbols @@ -0,0 +1,154 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts === +declare const foo: any; +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers11.ts, 4, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +} + +@foo +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers11.ts, 0, 13)) + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers11.ts, 10, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers11.ts, 11, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers11.ts, 0, 23)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers11.ts, 3, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static f = () => this.c + 1; +>f : Symbol(D.f, Decl(typeOfThisInStaticMembers11.ts, 12, 36)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + + static ff = function () { this.c + 1 } +>ff : Symbol(D.ff, Decl(typeOfThisInStaticMembers11.ts, 13, 32)) + + static foo () { +>foo : Symbol(D.foo, Decl(typeOfThisInStaticMembers11.ts, 14, 42)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + } + static get fa () { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers11.ts, 17, 5), Decl(typeOfThisInStaticMembers11.ts, 20, 5)) + + return this.c + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) + } + static set fa (v: number) { +>fa : Symbol(D.fa, Decl(typeOfThisInStaticMembers11.ts, 17, 5), Decl(typeOfThisInStaticMembers11.ts, 20, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 21, 19)) + + this.c = v + 1; +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers11.ts, 6, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers11.ts, 9, 19)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 21, 19)) + } +} + +class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) + + static a = 1; +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) + + static b = this.a + 1; +>b : Symbol(CC.b, Decl(typeOfThisInStaticMembers11.ts, 27, 17)) +>this.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +} + +class DD extends CC { +>DD : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) + + static c = 2; +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static d = this.c + 1; +>d : Symbol(DD.d, Decl(typeOfThisInStaticMembers11.ts, 32, 17)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static e = super.a + this.c + 1; +>e : Symbol(DD.e, Decl(typeOfThisInStaticMembers11.ts, 33, 26)) +>super.a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>super : Symbol(CC, Decl(typeOfThisInStaticMembers11.ts, 24, 1)) +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers11.ts, 26, 10)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static f = () => this.c + 1; +>f : Symbol(DD.f, Decl(typeOfThisInStaticMembers11.ts, 34, 36)) +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + + static ff = function () { this.c + 1 } +>ff : Symbol(DD.ff, Decl(typeOfThisInStaticMembers11.ts, 35, 32)) + + static foo () { +>foo : Symbol(DD.foo, Decl(typeOfThisInStaticMembers11.ts, 36, 42)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + } + static get fa () { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers11.ts, 39, 5), Decl(typeOfThisInStaticMembers11.ts, 42, 5)) + + return this.c + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) + } + static set fa (v: number) { +>fa : Symbol(DD.fa, Decl(typeOfThisInStaticMembers11.ts, 39, 5), Decl(typeOfThisInStaticMembers11.ts, 42, 5)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 43, 19)) + + this.c = v + 1; +>this.c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>this : Symbol(DD, Decl(typeOfThisInStaticMembers11.ts, 29, 1)) +>c : Symbol(DD.c, Decl(typeOfThisInStaticMembers11.ts, 31, 21)) +>v : Symbol(v, Decl(typeOfThisInStaticMembers11.ts, 43, 19)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).types new file mode 100644 index 0000000000000..44ad35960ec92 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers11(target=esnext).types @@ -0,0 +1,204 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts === +declare const foo: any; +>foo : any + +@foo +>foo : any + +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +@foo +>foo : any + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof D +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + +class CC { +>CC : CC + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof CC +>a : number +>1 : 1 +} + +class DD extends CC { +>DD : DD +>CC : CC + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof CC +>a : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static f = () => this.c + 1; +>f : () => number +>() => this.c + 1 : () => number +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + + static ff = function () { this.c + 1 } +>ff : () => void +>function () { this.c + 1 } : () => void +>this.c + 1 : any +>this.c : any +>this : any +>c : any +>1 : 1 + + static foo () { +>foo : () => number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static get fa () { +>fa : number + + return this.c + 1; +>this.c + 1 : number +>this.c : number +>this : typeof DD +>c : number +>1 : 1 + } + static set fa (v: number) { +>fa : number +>v : number + + this.c = v + 1; +>this.c = v + 1 : number +>this.c : number +>this : typeof DD +>c : number +>v + 1 : number +>v : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).errors.txt new file mode 100644 index 0000000000000..3855b2ee7b651 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(4,16): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(4,17): error TS2465: 'this' cannot be referenced in a computed property name. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(5,9): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(5,10): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts (4 errors) ==== + class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).js new file mode 100644 index 0000000000000..d68ce57eeaf6a --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).js @@ -0,0 +1,29 @@ +//// [typeOfThisInStaticMembers12.ts] +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} + + +//// [typeOfThisInStaticMembers12.js] +var C = /** @class */ (function () { + function C() { + } + var _a, _b, _c, _d; + _a = C; + C.c = "foo"; + C.bar = (_b = /** @class */ (function () { + function Inner() { + this[_d] = 123; + } + return Inner; + }()), + _c = _a.c, + _d = _a.c, + _b[_c] = 123, + _b); + return C; +}()); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).symbols new file mode 100644 index 0000000000000..16ad5c64fd0df --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers12.ts, 0, 0)) + + static readonly c: "foo" = "foo" +>c : Symbol(C.c, Decl(typeOfThisInStaticMembers12.ts, 0, 9)) + + static bar = class Inner { +>bar : Symbol(C.bar, Decl(typeOfThisInStaticMembers12.ts, 1, 36)) +>Inner : Symbol(Inner, Decl(typeOfThisInStaticMembers12.ts, 2, 16)) + + static [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers12.ts, 2, 31)) + + [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers12.ts, 3, 30)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).types new file mode 100644 index 0000000000000..ca37b9e4e200e --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es5).types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts === +class C { +>C : C + + static readonly c: "foo" = "foo" +>c : "foo" +>"foo" : "foo" + + static bar = class Inner { +>bar : typeof Inner +>class Inner { static [this.c] = 123; [this.c] = 123; } : typeof Inner +>Inner : typeof Inner + + static [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + + [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).errors.txt new file mode 100644 index 0000000000000..3855b2ee7b651 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(4,16): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(4,17): error TS2465: 'this' cannot be referenced in a computed property name. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(5,9): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(5,10): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts (4 errors) ==== + class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).js new file mode 100644 index 0000000000000..59ce5132646d1 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).js @@ -0,0 +1,25 @@ +//// [typeOfThisInStaticMembers12.ts] +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} + + +//// [typeOfThisInStaticMembers12.js] +var _a, _b, _c, _d; +class C { +} +_a = C; +C.c = "foo"; +C.bar = (_b = class Inner { + constructor() { + this[_d] = 123; + } + }, + _c = _a.c, + _d = _a.c, + _b[_c] = 123, + _b); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).symbols new file mode 100644 index 0000000000000..16ad5c64fd0df --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers12.ts, 0, 0)) + + static readonly c: "foo" = "foo" +>c : Symbol(C.c, Decl(typeOfThisInStaticMembers12.ts, 0, 9)) + + static bar = class Inner { +>bar : Symbol(C.bar, Decl(typeOfThisInStaticMembers12.ts, 1, 36)) +>Inner : Symbol(Inner, Decl(typeOfThisInStaticMembers12.ts, 2, 16)) + + static [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers12.ts, 2, 31)) + + [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers12.ts, 3, 30)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).types new file mode 100644 index 0000000000000..ca37b9e4e200e --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es6).types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts === +class C { +>C : C + + static readonly c: "foo" = "foo" +>c : "foo" +>"foo" : "foo" + + static bar = class Inner { +>bar : typeof Inner +>class Inner { static [this.c] = 123; [this.c] = 123; } : typeof Inner +>Inner : typeof Inner + + static [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + + [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).errors.txt new file mode 100644 index 0000000000000..3855b2ee7b651 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(4,16): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(4,17): error TS2465: 'this' cannot be referenced in a computed property name. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(5,9): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts(5,10): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts (4 errors) ==== + class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js new file mode 100644 index 0000000000000..59ce5132646d1 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js @@ -0,0 +1,25 @@ +//// [typeOfThisInStaticMembers12.ts] +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} + + +//// [typeOfThisInStaticMembers12.js] +var _a, _b, _c, _d; +class C { +} +_a = C; +C.c = "foo"; +C.bar = (_b = class Inner { + constructor() { + this[_d] = 123; + } + }, + _c = _a.c, + _d = _a.c, + _b[_c] = 123, + _b); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).symbols new file mode 100644 index 0000000000000..16ad5c64fd0df --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers12.ts, 0, 0)) + + static readonly c: "foo" = "foo" +>c : Symbol(C.c, Decl(typeOfThisInStaticMembers12.ts, 0, 9)) + + static bar = class Inner { +>bar : Symbol(C.bar, Decl(typeOfThisInStaticMembers12.ts, 1, 36)) +>Inner : Symbol(Inner, Decl(typeOfThisInStaticMembers12.ts, 2, 16)) + + static [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers12.ts, 2, 31)) + + [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers12.ts, 3, 30)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).types new file mode 100644 index 0000000000000..ca37b9e4e200e --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts === +class C { +>C : C + + static readonly c: "foo" = "foo" +>c : "foo" +>"foo" : "foo" + + static bar = class Inner { +>bar : typeof Inner +>class Inner { static [this.c] = 123; [this.c] = 123; } : typeof Inner +>Inner : typeof Inner + + static [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + + [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).errors.txt new file mode 100644 index 0000000000000..804765ba1290d --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(4,16): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(4,17): error TS2465: 'this' cannot be referenced in a computed property name. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(5,9): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(5,10): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts (4 errors) ==== + class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).js new file mode 100644 index 0000000000000..8339f36175222 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).js @@ -0,0 +1,49 @@ +//// [typeOfThisInStaticMembers13.ts] +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} + + +//// [typeOfThisInStaticMembers13.js] +var C = /** @class */ (function () { + function C() { + } + var _a, _b, _c, _d; + _a = C; + Object.defineProperty(C, "c", { + enumerable: true, + configurable: true, + writable: true, + value: "foo" + }); + Object.defineProperty(C, "bar", { + enumerable: true, + configurable: true, + writable: true, + value: (_b = /** @class */ (function () { + function Inner() { + Object.defineProperty(this, _d, { + enumerable: true, + configurable: true, + writable: true, + value: 123 + }); + } + return Inner; + }()), + _c = _a.c, + _d = _a.c, + Object.defineProperty(_b, _c, { + enumerable: true, + configurable: true, + writable: true, + value: 123 + }), + _b) + }); + return C; +}()); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).symbols new file mode 100644 index 0000000000000..806a34350b5b9 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers13.ts, 0, 0)) + + static readonly c: "foo" = "foo" +>c : Symbol(C.c, Decl(typeOfThisInStaticMembers13.ts, 0, 9)) + + static bar = class Inner { +>bar : Symbol(C.bar, Decl(typeOfThisInStaticMembers13.ts, 1, 36)) +>Inner : Symbol(Inner, Decl(typeOfThisInStaticMembers13.ts, 2, 16)) + + static [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers13.ts, 2, 31)) + + [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers13.ts, 3, 30)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).types new file mode 100644 index 0000000000000..bb274c6f556e7 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es5).types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts === +class C { +>C : C + + static readonly c: "foo" = "foo" +>c : "foo" +>"foo" : "foo" + + static bar = class Inner { +>bar : typeof Inner +>class Inner { static [this.c] = 123; [this.c] = 123; } : typeof Inner +>Inner : typeof Inner + + static [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + + [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).errors.txt new file mode 100644 index 0000000000000..804765ba1290d --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(4,16): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(4,17): error TS2465: 'this' cannot be referenced in a computed property name. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(5,9): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(5,10): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts (4 errors) ==== + class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).js new file mode 100644 index 0000000000000..1ad7177461a6d --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).js @@ -0,0 +1,45 @@ +//// [typeOfThisInStaticMembers13.ts] +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} + + +//// [typeOfThisInStaticMembers13.js] +var _a, _b, _c, _d; +class C { +} +_a = C; +Object.defineProperty(C, "c", { + enumerable: true, + configurable: true, + writable: true, + value: "foo" +}); +Object.defineProperty(C, "bar", { + enumerable: true, + configurable: true, + writable: true, + value: (_b = class Inner { + constructor() { + Object.defineProperty(this, _d, { + enumerable: true, + configurable: true, + writable: true, + value: 123 + }); + } + }, + _c = _a.c, + _d = _a.c, + Object.defineProperty(_b, _c, { + enumerable: true, + configurable: true, + writable: true, + value: 123 + }), + _b) +}); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).symbols new file mode 100644 index 0000000000000..806a34350b5b9 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers13.ts, 0, 0)) + + static readonly c: "foo" = "foo" +>c : Symbol(C.c, Decl(typeOfThisInStaticMembers13.ts, 0, 9)) + + static bar = class Inner { +>bar : Symbol(C.bar, Decl(typeOfThisInStaticMembers13.ts, 1, 36)) +>Inner : Symbol(Inner, Decl(typeOfThisInStaticMembers13.ts, 2, 16)) + + static [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers13.ts, 2, 31)) + + [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers13.ts, 3, 30)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).types new file mode 100644 index 0000000000000..bb274c6f556e7 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=es6).types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts === +class C { +>C : C + + static readonly c: "foo" = "foo" +>c : "foo" +>"foo" : "foo" + + static bar = class Inner { +>bar : typeof Inner +>class Inner { static [this.c] = 123; [this.c] = 123; } : typeof Inner +>Inner : typeof Inner + + static [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + + [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).errors.txt new file mode 100644 index 0000000000000..804765ba1290d --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(4,16): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(4,17): error TS2465: 'this' cannot be referenced in a computed property name. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(5,9): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts(5,10): error TS2465: 'this' cannot be referenced in a computed property name. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts (4 errors) ==== + class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + [this.c] = 123; + ~~~~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + ~~~~ +!!! error TS2465: 'this' cannot be referenced in a computed property name. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).js new file mode 100644 index 0000000000000..400f037855480 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).js @@ -0,0 +1,18 @@ +//// [typeOfThisInStaticMembers13.ts] +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} + + +//// [typeOfThisInStaticMembers13.js] +class C { + static c = "foo"; + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + }; +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).symbols new file mode 100644 index 0000000000000..806a34350b5b9 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers13.ts, 0, 0)) + + static readonly c: "foo" = "foo" +>c : Symbol(C.c, Decl(typeOfThisInStaticMembers13.ts, 0, 9)) + + static bar = class Inner { +>bar : Symbol(C.bar, Decl(typeOfThisInStaticMembers13.ts, 1, 36)) +>Inner : Symbol(Inner, Decl(typeOfThisInStaticMembers13.ts, 2, 16)) + + static [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers13.ts, 2, 31)) + + [this.c] = 123; +>[this.c] : Symbol(Inner[this.c], Decl(typeOfThisInStaticMembers13.ts, 3, 30)) + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).types new file mode 100644 index 0000000000000..bb274c6f556e7 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers13(target=esnext).types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts === +class C { +>C : C + + static readonly c: "foo" = "foo" +>c : "foo" +>"foo" : "foo" + + static bar = class Inner { +>bar : typeof Inner +>class Inner { static [this.c] = 123; [this.c] = 123; } : typeof Inner +>Inner : typeof Inner + + static [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + + [this.c] = 123; +>[this.c] : number +>this.c : any +>this : any +>c : any +>123 : 123 + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers2.errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers2.errors.txt deleted file mode 100644 index 9fd14cc57193a..0000000000000 --- a/tests/baselines/reference/typeOfThisInStaticMembers2.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts(2,18): error TS2334: 'this' cannot be referenced in a static property initializer. -tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts(6,18): error TS2334: 'this' cannot be referenced in a static property initializer. - - -==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts (2 errors) ==== - class C { - static foo = this; // error - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - - class C2 { - static foo = this; // error - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers2.js b/tests/baselines/reference/typeOfThisInStaticMembers2.js index 72243cdd3e619..acc3c0cf68a37 100644 --- a/tests/baselines/reference/typeOfThisInStaticMembers2.js +++ b/tests/baselines/reference/typeOfThisInStaticMembers2.js @@ -1,22 +1,26 @@ //// [typeOfThisInStaticMembers2.ts] class C { - static foo = this; // error + static foo = this; // ok } class C2 { - static foo = this; // error + static foo = this; // ok } //// [typeOfThisInStaticMembers2.js] var C = /** @class */ (function () { function C() { } - C.foo = this; // error + var _a; + _a = C; + C.foo = _a; // ok return C; }()); var C2 = /** @class */ (function () { function C2() { } - C2.foo = this; // error + var _b; + _b = C2; + C2.foo = _b; // ok return C2; }()); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers2.symbols b/tests/baselines/reference/typeOfThisInStaticMembers2.symbols index 3bb0261771d48..ff4aee318f721 100644 --- a/tests/baselines/reference/typeOfThisInStaticMembers2.symbols +++ b/tests/baselines/reference/typeOfThisInStaticMembers2.symbols @@ -2,7 +2,7 @@ class C { >C : Symbol(C, Decl(typeOfThisInStaticMembers2.ts, 0, 0)) - static foo = this; // error + static foo = this; // ok >foo : Symbol(C.foo, Decl(typeOfThisInStaticMembers2.ts, 0, 9)) >this : Symbol(C, Decl(typeOfThisInStaticMembers2.ts, 0, 0)) } @@ -11,7 +11,7 @@ class C2 { >C2 : Symbol(C2, Decl(typeOfThisInStaticMembers2.ts, 2, 1)) >T : Symbol(T, Decl(typeOfThisInStaticMembers2.ts, 4, 9)) - static foo = this; // error + static foo = this; // ok >foo : Symbol(C2.foo, Decl(typeOfThisInStaticMembers2.ts, 4, 13)) >this : Symbol(C2, Decl(typeOfThisInStaticMembers2.ts, 2, 1)) } diff --git a/tests/baselines/reference/typeOfThisInStaticMembers2.types b/tests/baselines/reference/typeOfThisInStaticMembers2.types index 099916a7b9d13..9a07972ca6c70 100644 --- a/tests/baselines/reference/typeOfThisInStaticMembers2.types +++ b/tests/baselines/reference/typeOfThisInStaticMembers2.types @@ -2,7 +2,7 @@ class C { >C : C - static foo = this; // error + static foo = this; // ok >foo : typeof C >this : typeof C } @@ -10,7 +10,7 @@ class C { class C2 { >C2 : C2 - static foo = this; // error + static foo = this; // ok >foo : typeof C2 >this : typeof C2 } diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).errors.txt new file mode 100644 index 0000000000000..da38e0eb95920 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts(9,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts (1 errors) ==== + class C { + static a = 1; + static b = this.a + 1; + } + + class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).js new file mode 100644 index 0000000000000..fdaf4ccb06b7c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).js @@ -0,0 +1,50 @@ +//// [typeOfThisInStaticMembers3.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} + + +//// [typeOfThisInStaticMembers3.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 C = /** @class */ (function () { + function C() { + } + var _a; + _a = C; + C.a = 1; + C.b = _a.a + 1; + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + var _b; + _b = D; + D.c = 2; + D.d = _b.c + 1; + D.e = _super.a + _b.c + 1; + return D; +}(C)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).symbols new file mode 100644 index 0000000000000..bfd5a942122f0 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers3.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers3.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers3.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).types new file mode 100644 index 0000000000000..9af87449fff5c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es5).types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).js new file mode 100644 index 0000000000000..ac5018106c0f7 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).js @@ -0,0 +1,26 @@ +//// [typeOfThisInStaticMembers3.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} + + +//// [typeOfThisInStaticMembers3.js] +var _a, _b, _c; +class C { +} +_a = C; +C.a = 1; +C.b = _a.a + 1; +class D extends (_c = C) { +} +_b = D; +D.c = 2; +D.d = _b.c + 1; +D.e = Reflect.get(_c, "a", _b) + _b.c + 1; diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).symbols new file mode 100644 index 0000000000000..bfd5a942122f0 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers3.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers3.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers3.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).types new file mode 100644 index 0000000000000..9af87449fff5c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=es6).types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).js new file mode 100644 index 0000000000000..ac5018106c0f7 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).js @@ -0,0 +1,26 @@ +//// [typeOfThisInStaticMembers3.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} + + +//// [typeOfThisInStaticMembers3.js] +var _a, _b, _c; +class C { +} +_a = C; +C.a = 1; +C.b = _a.a + 1; +class D extends (_c = C) { +} +_b = D; +D.c = 2; +D.d = _b.c + 1; +D.e = Reflect.get(_c, "a", _b) + _b.c + 1; diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).symbols new file mode 100644 index 0000000000000..bfd5a942122f0 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers3.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers3.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers3.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers3.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers3.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers3.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers3.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).types new file mode 100644 index 0000000000000..9af87449fff5c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers3(target=esnext).types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).errors.txt new file mode 100644 index 0000000000000..2502ce9dd53be --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts(9,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts (1 errors) ==== + class C { + static a = 1; + static b = this.a + 1; + } + + class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).js new file mode 100644 index 0000000000000..298cf649d9ea5 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).js @@ -0,0 +1,75 @@ +//// [typeOfThisInStaticMembers4.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} + + +//// [typeOfThisInStaticMembers4.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 C = /** @class */ (function () { + function C() { + } + var _a; + _a = C; + Object.defineProperty(C, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 + }); + Object.defineProperty(C, "b", { + enumerable: true, + configurable: true, + writable: true, + value: _a.a + 1 + }); + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + var _b; + _b = D; + Object.defineProperty(D, "c", { + enumerable: true, + configurable: true, + writable: true, + value: 2 + }); + Object.defineProperty(D, "d", { + enumerable: true, + configurable: true, + writable: true, + value: _b.c + 1 + }); + Object.defineProperty(D, "e", { + enumerable: true, + configurable: true, + writable: true, + value: _super.a + _b.c + 1 + }); + return D; +}(C)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).symbols new file mode 100644 index 0000000000000..90e4f31f37107 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers4.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers4.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers4.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).types new file mode 100644 index 0000000000000..547768640b1e9 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es5).types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).js new file mode 100644 index 0000000000000..eba1388438d1f --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).js @@ -0,0 +1,51 @@ +//// [typeOfThisInStaticMembers4.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} + + +//// [typeOfThisInStaticMembers4.js] +var _a, _b, _c; +class C { +} +_a = C; +Object.defineProperty(C, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 +}); +Object.defineProperty(C, "b", { + enumerable: true, + configurable: true, + writable: true, + value: _a.a + 1 +}); +class D extends (_c = C) { +} +_b = D; +Object.defineProperty(D, "c", { + enumerable: true, + configurable: true, + writable: true, + value: 2 +}); +Object.defineProperty(D, "d", { + enumerable: true, + configurable: true, + writable: true, + value: _b.c + 1 +}); +Object.defineProperty(D, "e", { + enumerable: true, + configurable: true, + writable: true, + value: Reflect.get(_c, "a", _b) + _b.c + 1 +}); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).symbols new file mode 100644 index 0000000000000..90e4f31f37107 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers4.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers4.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers4.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).types new file mode 100644 index 0000000000000..547768640b1e9 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=es6).types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).js new file mode 100644 index 0000000000000..1d64a21910e21 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).js @@ -0,0 +1,23 @@ +//// [typeOfThisInStaticMembers4.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} + + +//// [typeOfThisInStaticMembers4.js] +class C { + static a = 1; + static b = this.a + 1; +} +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).symbols new file mode 100644 index 0000000000000..90e4f31f37107 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers4.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers4.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) + + static e = super.a + this.c + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers4.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers4.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers4.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers4.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers4.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).types new file mode 100644 index 0000000000000..547768640b1e9 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers4(target=esnext).types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = super.a + this.c + 1; +>e : number +>super.a + this.c + 1 : number +>super.a + this.c : number +>super.a : number +>super : typeof C +>a : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).js new file mode 100644 index 0000000000000..793af4829df6b --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).js @@ -0,0 +1,20 @@ +//// [typeOfThisInStaticMembers5.ts] +class C { + static create = () => new this("yep") + + constructor (private foo: string) { + + } +} + + +//// [typeOfThisInStaticMembers5.js] +var C = /** @class */ (function () { + function C(foo) { + this.foo = foo; + } + var _a; + _a = C; + C.create = function () { return new _a("yep"); }; + return C; +}()); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).symbols new file mode 100644 index 0000000000000..cb65daa136c32 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers5.ts, 0, 0)) + + static create = () => new this("yep") +>create : Symbol(C.create, Decl(typeOfThisInStaticMembers5.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers5.ts, 0, 0)) + + constructor (private foo: string) { +>foo : Symbol(C.foo, Decl(typeOfThisInStaticMembers5.ts, 3, 17)) + + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).types new file mode 100644 index 0000000000000..63650b490ca90 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es5).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts === +class C { +>C : C + + static create = () => new this("yep") +>create : () => C +>() => new this("yep") : () => C +>new this("yep") : C +>this : typeof C +>"yep" : "yep" + + constructor (private foo: string) { +>foo : string + + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).js new file mode 100644 index 0000000000000..4bbbd6ffc8090 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).js @@ -0,0 +1,19 @@ +//// [typeOfThisInStaticMembers5.ts] +class C { + static create = () => new this("yep") + + constructor (private foo: string) { + + } +} + + +//// [typeOfThisInStaticMembers5.js] +var _a; +class C { + constructor(foo) { + this.foo = foo; + } +} +_a = C; +C.create = () => new _a("yep"); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).symbols new file mode 100644 index 0000000000000..cb65daa136c32 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers5.ts, 0, 0)) + + static create = () => new this("yep") +>create : Symbol(C.create, Decl(typeOfThisInStaticMembers5.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers5.ts, 0, 0)) + + constructor (private foo: string) { +>foo : Symbol(C.foo, Decl(typeOfThisInStaticMembers5.ts, 3, 17)) + + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).types new file mode 100644 index 0000000000000..63650b490ca90 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=es6).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts === +class C { +>C : C + + static create = () => new this("yep") +>create : () => C +>() => new this("yep") : () => C +>new this("yep") : C +>this : typeof C +>"yep" : "yep" + + constructor (private foo: string) { +>foo : string + + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).js new file mode 100644 index 0000000000000..3c08a270550a6 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).js @@ -0,0 +1,18 @@ +//// [typeOfThisInStaticMembers5.ts] +class C { + static create = () => new this("yep") + + constructor (private foo: string) { + + } +} + + +//// [typeOfThisInStaticMembers5.js] +class C { + foo; + static create = () => new this("yep"); + constructor(foo) { + this.foo = foo; + } +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).symbols new file mode 100644 index 0000000000000..cb65daa136c32 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers5.ts, 0, 0)) + + static create = () => new this("yep") +>create : Symbol(C.create, Decl(typeOfThisInStaticMembers5.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers5.ts, 0, 0)) + + constructor (private foo: string) { +>foo : Symbol(C.foo, Decl(typeOfThisInStaticMembers5.ts, 3, 17)) + + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).types new file mode 100644 index 0000000000000..63650b490ca90 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers5(target=esnext).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts === +class C { +>C : C + + static create = () => new this("yep") +>create : () => C +>() => new this("yep") : () => C +>new this("yep") : C +>this : typeof C +>"yep" : "yep" + + constructor (private foo: string) { +>foo : string + + } +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers6.errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers6.errors.txt new file mode 100644 index 0000000000000..b97b0b47d0ac5 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers6.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts(6,16): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts (1 errors) ==== + class C { + static f = 1 + } + + class D extends C { + static c = super(); + ~~~~~ +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers6.js b/tests/baselines/reference/typeOfThisInStaticMembers6.js new file mode 100644 index 0000000000000..17d63989991d1 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers6.js @@ -0,0 +1,40 @@ +//// [typeOfThisInStaticMembers6.ts] +class C { + static f = 1 +} + +class D extends C { + static c = super(); +} + + +//// [typeOfThisInStaticMembers6.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 C = /** @class */ (function () { + function C() { + } + C.f = 1; + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + D.c = _this = _super.call(this) || this; + return D; +}(C)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers6.symbols b/tests/baselines/reference/typeOfThisInStaticMembers6.symbols new file mode 100644 index 0000000000000..8a3ac7e8b0743 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers6.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers6.ts, 0, 0)) + + static f = 1 +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers6.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers6.ts, 2, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers6.ts, 0, 0)) + + static c = super(); +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers6.ts, 4, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers6.types b/tests/baselines/reference/typeOfThisInStaticMembers6.types new file mode 100644 index 0000000000000..bee48163310b2 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers6.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts === +class C { +>C : C + + static f = 1 +>f : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = super(); +>c : void +>super() : void +>super : any +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).errors.txt new file mode 100644 index 0000000000000..54de1238f9098 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts(9,27): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts (1 errors) ==== + class C { + static a = 1; + static b = this.a + 1; + } + + class D extends C { + static c = 2; + static d = this.c + 1; + static e = 1 + (super.a) + (this.c + 1) + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).js new file mode 100644 index 0000000000000..a9166f43f9f51 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).js @@ -0,0 +1,50 @@ +//// [typeOfThisInStaticMembers7.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = 1 + (super.a) + (this.c + 1) + 1; +} + + +//// [typeOfThisInStaticMembers7.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 C = /** @class */ (function () { + function C() { + } + var _a; + _a = C; + C.a = 1; + C.b = _a.a + 1; + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + var _b; + _b = D; + D.c = 2; + D.d = _b.c + 1; + D.e = 1 + (_super.a) + (_b.c + 1) + 1; + return D; +}(C)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).symbols new file mode 100644 index 0000000000000..dfc319293d7ac --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers7.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers7.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) + + static e = 1 + (super.a) + (this.c + 1) + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers7.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).types new file mode 100644 index 0000000000000..23f7b690e1d51 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es5).types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = 1 + (super.a) + (this.c + 1) + 1; +>e : number +>1 + (super.a) + (this.c + 1) + 1 : number +>1 + (super.a) + (this.c + 1) : number +>1 + (super.a) : number +>1 : 1 +>(super.a) : number +>super.a : number +>super : typeof C +>a : number +>(this.c + 1) : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).js new file mode 100644 index 0000000000000..186e15bd30f8b --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).js @@ -0,0 +1,26 @@ +//// [typeOfThisInStaticMembers7.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = 1 + (super.a) + (this.c + 1) + 1; +} + + +//// [typeOfThisInStaticMembers7.js] +var _a, _b, _c; +class C { +} +_a = C; +C.a = 1; +C.b = _a.a + 1; +class D extends (_c = C) { +} +_b = D; +D.c = 2; +D.d = _b.c + 1; +D.e = 1 + (Reflect.get(_c, "a", _b)) + (_b.c + 1) + 1; diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).symbols new file mode 100644 index 0000000000000..dfc319293d7ac --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers7.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers7.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) + + static e = 1 + (super.a) + (this.c + 1) + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers7.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).types new file mode 100644 index 0000000000000..23f7b690e1d51 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=es6).types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = 1 + (super.a) + (this.c + 1) + 1; +>e : number +>1 + (super.a) + (this.c + 1) + 1 : number +>1 + (super.a) + (this.c + 1) : number +>1 + (super.a) : number +>1 : 1 +>(super.a) : number +>super.a : number +>super : typeof C +>a : number +>(this.c + 1) : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).js new file mode 100644 index 0000000000000..7e5d0bc0f819c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).js @@ -0,0 +1,23 @@ +//// [typeOfThisInStaticMembers7.ts] +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = 1 + (super.a) + (this.c + 1) + 1; +} + + +//// [typeOfThisInStaticMembers7.js] +class C { + static a = 1; + static b = this.a + 1; +} +class D extends C { + static c = 2; + static d = this.c + 1; + static e = 1 + (super.a) + (this.c + 1) + 1; +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).symbols new file mode 100644 index 0000000000000..dfc319293d7ac --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) + + static a = 1; +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) + + static b = this.a + 1; +>b : Symbol(C.b, Decl(typeOfThisInStaticMembers7.ts, 1, 17)) +>this.a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) + + static c = 2; +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) + + static d = this.c + 1; +>d : Symbol(D.d, Decl(typeOfThisInStaticMembers7.ts, 6, 17)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) + + static e = 1 + (super.a) + (this.c + 1) + 1; +>e : Symbol(D.e, Decl(typeOfThisInStaticMembers7.ts, 7, 26)) +>super.a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers7.ts, 0, 0)) +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers7.ts, 0, 9)) +>this.c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +>this : Symbol(D, Decl(typeOfThisInStaticMembers7.ts, 3, 1)) +>c : Symbol(D.c, Decl(typeOfThisInStaticMembers7.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).types new file mode 100644 index 0000000000000..23f7b690e1d51 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers7(target=esnext).types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts === +class C { +>C : C + + static a = 1; +>a : number +>1 : 1 + + static b = this.a + 1; +>b : number +>this.a + 1 : number +>this.a : number +>this : typeof C +>a : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static c = 2; +>c : number +>2 : 2 + + static d = this.c + 1; +>d : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 + + static e = 1 + (super.a) + (this.c + 1) + 1; +>e : number +>1 + (super.a) + (this.c + 1) + 1 : number +>1 + (super.a) + (this.c + 1) : number +>1 + (super.a) : number +>1 : 1 +>(super.a) : number +>super.a : number +>super : typeof C +>a : number +>(this.c + 1) : number +>this.c + 1 : number +>this.c : number +>this : typeof D +>c : number +>1 : 1 +>1 : 1 +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).errors.txt new file mode 100644 index 0000000000000..072f38100cfc6 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(5,49): error TS2339: Property 'f' does not exist on type '(Anonymous class)'. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(11,22): error TS2339: Property 'f' does not exist on type 'CC'. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(13,29): error TS2339: Property 'f' does not exist on type 'CC'. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts (3 errors) ==== + class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + ~ +!!! error TS2339: Property 'f' does not exist on type '(Anonymous class)'. + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + ~ +!!! error TS2339: Property 'f' does not exist on type 'CC'. + method () { + return this.f + 6 + ~ +!!! error TS2339: Property 'f' does not exist on type 'CC'. + } + } + })(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).js new file mode 100644 index 0000000000000..343a8096bfde8 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).js @@ -0,0 +1,51 @@ +//// [typeOfThisInStaticMembers8.ts] +class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + method () { + return this.f + 6 + } + } + })(); +} + + +//// [typeOfThisInStaticMembers8.js] +var C = /** @class */ (function () { + function C() { + } + var _a; + _a = C; + C.f = 1; + C.arrowFunctionBoundary = function () { return _a.f + 1; }; + C.functionExprBoundary = function () { return this.f + 2; }; + C.classExprBoundary = /** @class */ (function () { + function class_1() { + this.a = this.f + 3; + } + return class_1; + }()); + C.functionAndClassDeclBoundary = (function () { + function foo() { + return this.f + 4; + } + var CC = /** @class */ (function () { + function CC() { + this.a = this.f + 5; + } + CC.prototype.method = function () { + return this.f + 6; + }; + return CC; + }()); + })(); + return C; +}()); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).symbols new file mode 100644 index 0000000000000..6579e0eac2ab4 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).symbols @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers8.ts, 0, 0)) + + static f = 1; +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) + + static arrowFunctionBoundary = () => this.f + 1; +>arrowFunctionBoundary : Symbol(C.arrowFunctionBoundary, Decl(typeOfThisInStaticMembers8.ts, 1, 17)) +>this.f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers8.ts, 0, 0)) +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) + + static functionExprBoundary = function () { return this.f + 2 }; +>functionExprBoundary : Symbol(C.functionExprBoundary, Decl(typeOfThisInStaticMembers8.ts, 2, 52)) + + static classExprBoundary = class { a = this.f + 3 }; +>classExprBoundary : Symbol(C.classExprBoundary, Decl(typeOfThisInStaticMembers8.ts, 3, 68)) +>a : Symbol((Anonymous class).a, Decl(typeOfThisInStaticMembers8.ts, 4, 38)) +>this : Symbol((Anonymous class), Decl(typeOfThisInStaticMembers8.ts, 4, 30)) + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : Symbol(C.functionAndClassDeclBoundary, Decl(typeOfThisInStaticMembers8.ts, 4, 56)) + + function foo () { +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers8.ts, 5, 50)) + + return this.f + 4 + } + class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + + a = this.f + 5 +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers8.ts, 9, 18)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + + method () { +>method : Symbol(CC.method, Decl(typeOfThisInStaticMembers8.ts, 10, 26)) + + return this.f + 6 +>this : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).types new file mode 100644 index 0000000000000..08873785a925c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es5).types @@ -0,0 +1,77 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts === +class C { +>C : C + + static f = 1; +>f : number +>1 : 1 + + static arrowFunctionBoundary = () => this.f + 1; +>arrowFunctionBoundary : () => number +>() => this.f + 1 : () => number +>this.f + 1 : number +>this.f : number +>this : typeof C +>f : number +>1 : 1 + + static functionExprBoundary = function () { return this.f + 2 }; +>functionExprBoundary : () => any +>function () { return this.f + 2 } : () => any +>this.f + 2 : any +>this.f : any +>this : any +>f : any +>2 : 2 + + static classExprBoundary = class { a = this.f + 3 }; +>classExprBoundary : typeof (Anonymous class) +>class { a = this.f + 3 } : typeof (Anonymous class) +>a : any +>this.f + 3 : any +>this.f : any +>this : this +>f : any +>3 : 3 + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : void +>(() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } })() : void +>(() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } }) : () => void +>() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } } : () => void + + function foo () { +>foo : () => any + + return this.f + 4 +>this.f + 4 : any +>this.f : any +>this : any +>f : any +>4 : 4 + } + class CC { +>CC : CC + + a = this.f + 5 +>a : any +>this.f + 5 : any +>this.f : any +>this : this +>f : any +>5 : 5 + + method () { +>method : () => any + + return this.f + 6 +>this.f + 6 : any +>this.f : any +>this : this +>f : any +>6 : 6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).errors.txt new file mode 100644 index 0000000000000..072f38100cfc6 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(5,49): error TS2339: Property 'f' does not exist on type '(Anonymous class)'. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(11,22): error TS2339: Property 'f' does not exist on type 'CC'. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(13,29): error TS2339: Property 'f' does not exist on type 'CC'. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts (3 errors) ==== + class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + ~ +!!! error TS2339: Property 'f' does not exist on type '(Anonymous class)'. + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + ~ +!!! error TS2339: Property 'f' does not exist on type 'CC'. + method () { + return this.f + 6 + ~ +!!! error TS2339: Property 'f' does not exist on type 'CC'. + } + } + })(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).js new file mode 100644 index 0000000000000..b43570acc63bb --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).js @@ -0,0 +1,46 @@ +//// [typeOfThisInStaticMembers8.ts] +class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + method () { + return this.f + 6 + } + } + })(); +} + + +//// [typeOfThisInStaticMembers8.js] +var _a; +class C { +} +_a = C; +C.f = 1; +C.arrowFunctionBoundary = () => _a.f + 1; +C.functionExprBoundary = function () { return this.f + 2; }; +C.classExprBoundary = class { + constructor() { + this.a = this.f + 3; + } +}; +C.functionAndClassDeclBoundary = (() => { + function foo() { + return this.f + 4; + } + class CC { + constructor() { + this.a = this.f + 5; + } + method() { + return this.f + 6; + } + } +})(); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).symbols new file mode 100644 index 0000000000000..6579e0eac2ab4 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).symbols @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers8.ts, 0, 0)) + + static f = 1; +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) + + static arrowFunctionBoundary = () => this.f + 1; +>arrowFunctionBoundary : Symbol(C.arrowFunctionBoundary, Decl(typeOfThisInStaticMembers8.ts, 1, 17)) +>this.f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers8.ts, 0, 0)) +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) + + static functionExprBoundary = function () { return this.f + 2 }; +>functionExprBoundary : Symbol(C.functionExprBoundary, Decl(typeOfThisInStaticMembers8.ts, 2, 52)) + + static classExprBoundary = class { a = this.f + 3 }; +>classExprBoundary : Symbol(C.classExprBoundary, Decl(typeOfThisInStaticMembers8.ts, 3, 68)) +>a : Symbol((Anonymous class).a, Decl(typeOfThisInStaticMembers8.ts, 4, 38)) +>this : Symbol((Anonymous class), Decl(typeOfThisInStaticMembers8.ts, 4, 30)) + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : Symbol(C.functionAndClassDeclBoundary, Decl(typeOfThisInStaticMembers8.ts, 4, 56)) + + function foo () { +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers8.ts, 5, 50)) + + return this.f + 4 + } + class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + + a = this.f + 5 +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers8.ts, 9, 18)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + + method () { +>method : Symbol(CC.method, Decl(typeOfThisInStaticMembers8.ts, 10, 26)) + + return this.f + 6 +>this : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).types new file mode 100644 index 0000000000000..08873785a925c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=es6).types @@ -0,0 +1,77 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts === +class C { +>C : C + + static f = 1; +>f : number +>1 : 1 + + static arrowFunctionBoundary = () => this.f + 1; +>arrowFunctionBoundary : () => number +>() => this.f + 1 : () => number +>this.f + 1 : number +>this.f : number +>this : typeof C +>f : number +>1 : 1 + + static functionExprBoundary = function () { return this.f + 2 }; +>functionExprBoundary : () => any +>function () { return this.f + 2 } : () => any +>this.f + 2 : any +>this.f : any +>this : any +>f : any +>2 : 2 + + static classExprBoundary = class { a = this.f + 3 }; +>classExprBoundary : typeof (Anonymous class) +>class { a = this.f + 3 } : typeof (Anonymous class) +>a : any +>this.f + 3 : any +>this.f : any +>this : this +>f : any +>3 : 3 + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : void +>(() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } })() : void +>(() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } }) : () => void +>() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } } : () => void + + function foo () { +>foo : () => any + + return this.f + 4 +>this.f + 4 : any +>this.f : any +>this : any +>f : any +>4 : 4 + } + class CC { +>CC : CC + + a = this.f + 5 +>a : any +>this.f + 5 : any +>this.f : any +>this : this +>f : any +>5 : 5 + + method () { +>method : () => any + + return this.f + 6 +>this.f + 6 : any +>this.f : any +>this : this +>f : any +>6 : 6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).errors.txt new file mode 100644 index 0000000000000..072f38100cfc6 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(5,49): error TS2339: Property 'f' does not exist on type '(Anonymous class)'. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(11,22): error TS2339: Property 'f' does not exist on type 'CC'. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts(13,29): error TS2339: Property 'f' does not exist on type 'CC'. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts (3 errors) ==== + class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + ~ +!!! error TS2339: Property 'f' does not exist on type '(Anonymous class)'. + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + ~ +!!! error TS2339: Property 'f' does not exist on type 'CC'. + method () { + return this.f + 6 + ~ +!!! error TS2339: Property 'f' does not exist on type 'CC'. + } + } + })(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).js new file mode 100644 index 0000000000000..6d0e04fe18c71 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).js @@ -0,0 +1,40 @@ +//// [typeOfThisInStaticMembers8.ts] +class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + method () { + return this.f + 6 + } + } + })(); +} + + +//// [typeOfThisInStaticMembers8.js] +class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2; }; + static classExprBoundary = class { + a = this.f + 3; + }; + static functionAndClassDeclBoundary = (() => { + function foo() { + return this.f + 4; + } + class CC { + a = this.f + 5; + method() { + return this.f + 6; + } + } + })(); +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).symbols new file mode 100644 index 0000000000000..6579e0eac2ab4 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).symbols @@ -0,0 +1,46 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers8.ts, 0, 0)) + + static f = 1; +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) + + static arrowFunctionBoundary = () => this.f + 1; +>arrowFunctionBoundary : Symbol(C.arrowFunctionBoundary, Decl(typeOfThisInStaticMembers8.ts, 1, 17)) +>this.f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) +>this : Symbol(C, Decl(typeOfThisInStaticMembers8.ts, 0, 0)) +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers8.ts, 0, 9)) + + static functionExprBoundary = function () { return this.f + 2 }; +>functionExprBoundary : Symbol(C.functionExprBoundary, Decl(typeOfThisInStaticMembers8.ts, 2, 52)) + + static classExprBoundary = class { a = this.f + 3 }; +>classExprBoundary : Symbol(C.classExprBoundary, Decl(typeOfThisInStaticMembers8.ts, 3, 68)) +>a : Symbol((Anonymous class).a, Decl(typeOfThisInStaticMembers8.ts, 4, 38)) +>this : Symbol((Anonymous class), Decl(typeOfThisInStaticMembers8.ts, 4, 30)) + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : Symbol(C.functionAndClassDeclBoundary, Decl(typeOfThisInStaticMembers8.ts, 4, 56)) + + function foo () { +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers8.ts, 5, 50)) + + return this.f + 4 + } + class CC { +>CC : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + + a = this.f + 5 +>a : Symbol(CC.a, Decl(typeOfThisInStaticMembers8.ts, 9, 18)) +>this : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + + method () { +>method : Symbol(CC.method, Decl(typeOfThisInStaticMembers8.ts, 10, 26)) + + return this.f + 6 +>this : Symbol(CC, Decl(typeOfThisInStaticMembers8.ts, 8, 9)) + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).types new file mode 100644 index 0000000000000..08873785a925c --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers8(target=esnext).types @@ -0,0 +1,77 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts === +class C { +>C : C + + static f = 1; +>f : number +>1 : 1 + + static arrowFunctionBoundary = () => this.f + 1; +>arrowFunctionBoundary : () => number +>() => this.f + 1 : () => number +>this.f + 1 : number +>this.f : number +>this : typeof C +>f : number +>1 : 1 + + static functionExprBoundary = function () { return this.f + 2 }; +>functionExprBoundary : () => any +>function () { return this.f + 2 } : () => any +>this.f + 2 : any +>this.f : any +>this : any +>f : any +>2 : 2 + + static classExprBoundary = class { a = this.f + 3 }; +>classExprBoundary : typeof (Anonymous class) +>class { a = this.f + 3 } : typeof (Anonymous class) +>a : any +>this.f + 3 : any +>this.f : any +>this : this +>f : any +>3 : 3 + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : void +>(() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } })() : void +>(() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } }) : () => void +>() => { function foo () { return this.f + 4 } class CC { a = this.f + 5 method () { return this.f + 6 } } } : () => void + + function foo () { +>foo : () => any + + return this.f + 4 +>this.f + 4 : any +>this.f : any +>this : any +>f : any +>4 : 4 + } + class CC { +>CC : CC + + a = this.f + 5 +>a : any +>this.f + 5 : any +>this.f : any +>this : this +>f : any +>5 : 5 + + method () { +>method : () => any + + return this.f + 6 +>this.f + 6 : any +>this.f : any +>this : this +>f : any +>6 : 6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).errors.txt new file mode 100644 index 0000000000000..dfe85e64c8ff4 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(6,48): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(7,56): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(8,44): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(14,17): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(16,24): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts (6 errors) ==== + class C { + static f = 1 + } + + class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword. + static functionExprBoundary = function () { return super.f + 2 }; + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + static classExprBoundary = class { a = super.f + 3 }; + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + } + class C { + a = super.f + 5 + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + method () { + return super.f +6 + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } + } + })(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).js b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).js new file mode 100644 index 0000000000000..f086499266b31 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).js @@ -0,0 +1,74 @@ +//// [typeOfThisInStaticMembers9.ts] +class C { + static f = 1 +} + +class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2 }; + static classExprBoundary = class { a = super.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + } + class C { + a = super.f + 5 + method () { + return super.f +6 + } + } + })(); +} + + +//// [typeOfThisInStaticMembers9.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 C = /** @class */ (function () { + function C() { + } + C.f = 1; + return C; +}()); +var D = /** @class */ (function (_super) { + __extends(D, _super); + function D() { + return _super !== null && _super.apply(this, arguments) || this; + } + D.arrowFunctionBoundary = function () { return _super.f + 1; }; + D.functionExprBoundary = function () { return _super.f + 2; }; + D.classExprBoundary = /** @class */ (function () { + function class_1() { + this.a = _super.prototype.f + 3; + } + return class_1; + }()); + D.functionAndClassDeclBoundary = (function () { + function foo() { + return _super.f + 4; + } + var C = /** @class */ (function () { + function C() { + this.a = _super.prototype.f + 5; + } + C.prototype.method = function () { + return _super.prototype.f + 6; + }; + return C; + }()); + })(); + return D; +}(C)); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).symbols b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).symbols new file mode 100644 index 0000000000000..15dd3c13164c8 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) + + static f = 1 +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers9.ts, 2, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) + + static arrowFunctionBoundary = () => super.f + 1; +>arrowFunctionBoundary : Symbol(D.arrowFunctionBoundary, Decl(typeOfThisInStaticMembers9.ts, 4, 19)) +>super.f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) + + static functionExprBoundary = function () { return super.f + 2 }; +>functionExprBoundary : Symbol(D.functionExprBoundary, Decl(typeOfThisInStaticMembers9.ts, 5, 53)) + + static classExprBoundary = class { a = super.f + 3 }; +>classExprBoundary : Symbol(D.classExprBoundary, Decl(typeOfThisInStaticMembers9.ts, 6, 69)) +>a : Symbol((Anonymous class).a, Decl(typeOfThisInStaticMembers9.ts, 7, 38)) + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : Symbol(D.functionAndClassDeclBoundary, Decl(typeOfThisInStaticMembers9.ts, 7, 57)) + + function foo () { +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers9.ts, 8, 50)) + + return super.f + 4 + } + class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 11, 9)) + + a = super.f + 5 +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers9.ts, 12, 17)) + + method () { +>method : Symbol(C.method, Decl(typeOfThisInStaticMembers9.ts, 13, 27)) + + return super.f +6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).types b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).types new file mode 100644 index 0000000000000..03f49b98d4c0a --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es5).types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts === +class C { +>C : C + + static f = 1 +>f : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static arrowFunctionBoundary = () => super.f + 1; +>arrowFunctionBoundary : () => number +>() => super.f + 1 : () => number +>super.f + 1 : number +>super.f : number +>super : typeof C +>f : number +>1 : 1 + + static functionExprBoundary = function () { return super.f + 2 }; +>functionExprBoundary : () => any +>function () { return super.f + 2 } : () => any +>super.f + 2 : any +>super.f : any +>super : any +>f : any +>2 : 2 + + static classExprBoundary = class { a = super.f + 3 }; +>classExprBoundary : typeof (Anonymous class) +>class { a = super.f + 3 } : typeof (Anonymous class) +>a : any +>super.f + 3 : any +>super.f : any +>super : any +>f : any +>3 : 3 + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : void +>(() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } })() : void +>(() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } }) : () => void +>() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } } : () => void + + function foo () { +>foo : () => any + + return super.f + 4 +>super.f + 4 : any +>super.f : any +>super : any +>f : any +>4 : 4 + } + class C { +>C : C + + a = super.f + 5 +>a : any +>super.f + 5 : any +>super.f : any +>super : any +>f : any +>5 : 5 + + method () { +>method : () => any + + return super.f +6 +>super.f +6 : any +>super.f : any +>super : any +>f : any +>6 : 6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).errors.txt new file mode 100644 index 0000000000000..7bf89ab8b3f97 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(7,56): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(8,44): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(14,17): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(16,24): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts (5 errors) ==== + class C { + static f = 1 + } + + class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2 }; + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + static classExprBoundary = class { a = super.f + 3 }; + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + } + class C { + a = super.f + 5 + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + method () { + return super.f +6 + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } + } + })(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).js b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).js new file mode 100644 index 0000000000000..2bd68f8756f0a --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).js @@ -0,0 +1,51 @@ +//// [typeOfThisInStaticMembers9.ts] +class C { + static f = 1 +} + +class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2 }; + static classExprBoundary = class { a = super.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + } + class C { + a = super.f + 5 + method () { + return super.f +6 + } + } + })(); +} + + +//// [typeOfThisInStaticMembers9.js] +var _a, _b; +class C { +} +C.f = 1; +class D extends (_b = C) { +} +_a = D; +D.arrowFunctionBoundary = () => Reflect.get(_b, "f", _a) + 1; +D.functionExprBoundary = function () { return super.f + 2; }; +D.classExprBoundary = class { + constructor() { + this.a = super.f + 3; + } +}; +D.functionAndClassDeclBoundary = (() => { + function foo() { + return super.f + 4; + } + class C { + constructor() { + this.a = super.f + 5; + } + method() { + return super.f + 6; + } + } +})(); diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).symbols b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).symbols new file mode 100644 index 0000000000000..15dd3c13164c8 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) + + static f = 1 +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers9.ts, 2, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) + + static arrowFunctionBoundary = () => super.f + 1; +>arrowFunctionBoundary : Symbol(D.arrowFunctionBoundary, Decl(typeOfThisInStaticMembers9.ts, 4, 19)) +>super.f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) + + static functionExprBoundary = function () { return super.f + 2 }; +>functionExprBoundary : Symbol(D.functionExprBoundary, Decl(typeOfThisInStaticMembers9.ts, 5, 53)) + + static classExprBoundary = class { a = super.f + 3 }; +>classExprBoundary : Symbol(D.classExprBoundary, Decl(typeOfThisInStaticMembers9.ts, 6, 69)) +>a : Symbol((Anonymous class).a, Decl(typeOfThisInStaticMembers9.ts, 7, 38)) + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : Symbol(D.functionAndClassDeclBoundary, Decl(typeOfThisInStaticMembers9.ts, 7, 57)) + + function foo () { +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers9.ts, 8, 50)) + + return super.f + 4 + } + class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 11, 9)) + + a = super.f + 5 +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers9.ts, 12, 17)) + + method () { +>method : Symbol(C.method, Decl(typeOfThisInStaticMembers9.ts, 13, 27)) + + return super.f +6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).types b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).types new file mode 100644 index 0000000000000..03f49b98d4c0a --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=es6).types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts === +class C { +>C : C + + static f = 1 +>f : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static arrowFunctionBoundary = () => super.f + 1; +>arrowFunctionBoundary : () => number +>() => super.f + 1 : () => number +>super.f + 1 : number +>super.f : number +>super : typeof C +>f : number +>1 : 1 + + static functionExprBoundary = function () { return super.f + 2 }; +>functionExprBoundary : () => any +>function () { return super.f + 2 } : () => any +>super.f + 2 : any +>super.f : any +>super : any +>f : any +>2 : 2 + + static classExprBoundary = class { a = super.f + 3 }; +>classExprBoundary : typeof (Anonymous class) +>class { a = super.f + 3 } : typeof (Anonymous class) +>a : any +>super.f + 3 : any +>super.f : any +>super : any +>f : any +>3 : 3 + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : void +>(() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } })() : void +>(() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } }) : () => void +>() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } } : () => void + + function foo () { +>foo : () => any + + return super.f + 4 +>super.f + 4 : any +>super.f : any +>super : any +>f : any +>4 : 4 + } + class C { +>C : C + + a = super.f + 5 +>a : any +>super.f + 5 : any +>super.f : any +>super : any +>f : any +>5 : 5 + + method () { +>method : () => any + + return super.f +6 +>super.f +6 : any +>super.f : any +>super : any +>f : any +>6 : 6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).errors.txt b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).errors.txt new file mode 100644 index 0000000000000..7bf89ab8b3f97 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(7,56): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(8,44): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(11,20): error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(14,17): error TS2335: 'super' can only be referenced in a derived class. +tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts(16,24): error TS2335: 'super' can only be referenced in a derived class. + + +==== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts (5 errors) ==== + class C { + static f = 1 + } + + class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2 }; + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + static classExprBoundary = class { a = super.f + 3 }; + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + ~~~~~ +!!! error TS2660: 'super' can only be referenced in members of derived classes or object literal expressions. + } + class C { + a = super.f + 5 + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + method () { + return super.f +6 + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } + } + })(); + } + \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).js new file mode 100644 index 0000000000000..861937ac70d39 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).js @@ -0,0 +1,45 @@ +//// [typeOfThisInStaticMembers9.ts] +class C { + static f = 1 +} + +class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2 }; + static classExprBoundary = class { a = super.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + } + class C { + a = super.f + 5 + method () { + return super.f +6 + } + } + })(); +} + + +//// [typeOfThisInStaticMembers9.js] +class C { + static f = 1; +} +class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2; }; + static classExprBoundary = class { + a = super.f + 3; + }; + static functionAndClassDeclBoundary = (() => { + function foo() { + return super.f + 4; + } + class C { + a = super.f + 5; + method() { + return super.f + 6; + } + } + })(); +} diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).symbols b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).symbols new file mode 100644 index 0000000000000..15dd3c13164c8 --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts === +class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) + + static f = 1 +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) +} + +class D extends C { +>D : Symbol(D, Decl(typeOfThisInStaticMembers9.ts, 2, 1)) +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) + + static arrowFunctionBoundary = () => super.f + 1; +>arrowFunctionBoundary : Symbol(D.arrowFunctionBoundary, Decl(typeOfThisInStaticMembers9.ts, 4, 19)) +>super.f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) +>super : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 0, 0)) +>f : Symbol(C.f, Decl(typeOfThisInStaticMembers9.ts, 0, 9)) + + static functionExprBoundary = function () { return super.f + 2 }; +>functionExprBoundary : Symbol(D.functionExprBoundary, Decl(typeOfThisInStaticMembers9.ts, 5, 53)) + + static classExprBoundary = class { a = super.f + 3 }; +>classExprBoundary : Symbol(D.classExprBoundary, Decl(typeOfThisInStaticMembers9.ts, 6, 69)) +>a : Symbol((Anonymous class).a, Decl(typeOfThisInStaticMembers9.ts, 7, 38)) + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : Symbol(D.functionAndClassDeclBoundary, Decl(typeOfThisInStaticMembers9.ts, 7, 57)) + + function foo () { +>foo : Symbol(foo, Decl(typeOfThisInStaticMembers9.ts, 8, 50)) + + return super.f + 4 + } + class C { +>C : Symbol(C, Decl(typeOfThisInStaticMembers9.ts, 11, 9)) + + a = super.f + 5 +>a : Symbol(C.a, Decl(typeOfThisInStaticMembers9.ts, 12, 17)) + + method () { +>method : Symbol(C.method, Decl(typeOfThisInStaticMembers9.ts, 13, 27)) + + return super.f +6 + } + } + })(); +} + diff --git a/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).types b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).types new file mode 100644 index 0000000000000..03f49b98d4c0a --- /dev/null +++ b/tests/baselines/reference/typeOfThisInStaticMembers9(target=esnext).types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts === +class C { +>C : C + + static f = 1 +>f : number +>1 : 1 +} + +class D extends C { +>D : D +>C : C + + static arrowFunctionBoundary = () => super.f + 1; +>arrowFunctionBoundary : () => number +>() => super.f + 1 : () => number +>super.f + 1 : number +>super.f : number +>super : typeof C +>f : number +>1 : 1 + + static functionExprBoundary = function () { return super.f + 2 }; +>functionExprBoundary : () => any +>function () { return super.f + 2 } : () => any +>super.f + 2 : any +>super.f : any +>super : any +>f : any +>2 : 2 + + static classExprBoundary = class { a = super.f + 3 }; +>classExprBoundary : typeof (Anonymous class) +>class { a = super.f + 3 } : typeof (Anonymous class) +>a : any +>super.f + 3 : any +>super.f : any +>super : any +>f : any +>3 : 3 + + static functionAndClassDeclBoundary = (() => { +>functionAndClassDeclBoundary : void +>(() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } })() : void +>(() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } }) : () => void +>() => { function foo () { return super.f + 4 } class C { a = super.f + 5 method () { return super.f +6 } } } : () => void + + function foo () { +>foo : () => any + + return super.f + 4 +>super.f + 4 : any +>super.f : any +>super : any +>f : any +>4 : 4 + } + class C { +>C : C + + a = super.f + 5 +>a : any +>super.f + 5 : any +>super.f : any +>super : any +>f : any +>5 : 5 + + method () { +>method : () => any + + return super.f +6 +>super.f +6 : any +>super.f : any +>super : any +>f : any +>6 : 6 + } + } + })(); +} + diff --git a/tests/baselines/reference/variance.js b/tests/baselines/reference/variance.js index df84404b31beb..22fd646d33cd2 100644 --- a/tests/baselines/reference/variance.js +++ b/tests/baselines/reference/variance.js @@ -16,7 +16,7 @@ const z: Foo = x; // Repro from #30118 class Bar { - private static instance: Bar[]; + private static instance: Bar[] = []; cast(_name: ([T] extends [string] ? string : string)) { } @@ -41,5 +41,6 @@ var Bar = /** @class */ (function () { Bar.prototype.pushThis = function () { Bar.instance.push(this); }; + Bar.instance = []; return Bar; }()); diff --git a/tests/baselines/reference/variance.symbols b/tests/baselines/reference/variance.symbols index 0a6ec56d725b6..a9503a867c13d 100644 --- a/tests/baselines/reference/variance.symbols +++ b/tests/baselines/reference/variance.symbols @@ -38,12 +38,12 @@ class Bar { >Bar : Symbol(Bar, Decl(variance.ts, 11, 25)) >T : Symbol(T, Decl(variance.ts, 16, 10)) - private static instance: Bar[]; + private static instance: Bar[] = []; >instance : Symbol(Bar.instance, Decl(variance.ts, 16, 29)) >Bar : Symbol(Bar, Decl(variance.ts, 11, 25)) cast(_name: ([T] extends [string] ? string : string)) { } ->cast : Symbol(Bar.cast, Decl(variance.ts, 17, 41)) +>cast : Symbol(Bar.cast, Decl(variance.ts, 17, 46)) >_name : Symbol(_name, Decl(variance.ts, 19, 7)) >T : Symbol(T, Decl(variance.ts, 16, 10)) diff --git a/tests/baselines/reference/variance.types b/tests/baselines/reference/variance.types index 08ee1053b3dba..2f7267aca5de0 100644 --- a/tests/baselines/reference/variance.types +++ b/tests/baselines/reference/variance.types @@ -35,8 +35,9 @@ const z: Foo = x; class Bar { >Bar : Bar - private static instance: Bar[]; + private static instance: Bar[] = []; >instance : Bar[] +>[] : never[] cast(_name: ([T] extends [string] ? string : string)) { } >cast : (_name: ([T] extends [string] ? string : string)) => void diff --git a/tests/cases/compiler/thisInArrowFunctionInStaticInitializer1.ts b/tests/cases/compiler/thisInArrowFunctionInStaticInitializer1.ts index 6aba2135da0da..3ac1a2428a141 100644 --- a/tests/cases/compiler/thisInArrowFunctionInStaticInitializer1.ts +++ b/tests/cases/compiler/thisInArrowFunctionInStaticInitializer1.ts @@ -2,7 +2,7 @@ function log(a) { } class Vector { static foo = () => { - // 'this' should not be available in a static initializer. + // 'this' should be allowed in a static initializer. log(this); } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef1.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef1.ts new file mode 100644 index 0000000000000..11f8b7f55472a --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef1.ts @@ -0,0 +1,15 @@ +// @target: esnext +// @noEmit: true +// @strict: true + +class C { + static x; + static { + this.x = 1; + } + static y = this.x; + static z; + static { + this.z = this.y; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts new file mode 100644 index 0000000000000..89658a6ebe26c --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlockUseBeforeDef2.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @noEmit: true +// @strict: true + +class C { + static { + this.x = 1; + } + static x; +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers1.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers1.ts new file mode 100644 index 0000000000000..e3bfff9aedfab --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers1.ts @@ -0,0 +1,42 @@ +// @target: esnext, es2015 +// @useDefineForClassFields: true +// @noTypesAndSymbols: true + +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a``; + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers2.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers2.ts new file mode 100644 index 0000000000000..7e751c3d672a4 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers2.ts @@ -0,0 +1,42 @@ +// @target: esnext, es2015 +// @useDefineForClassFields: false +// @noTypesAndSymbols: true + +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z1 = super.a; + static z2 = super["a"]; + static z3 = super.f(); + static z4 = super["f"](); + static z5 = super.a = 0; + static z6 = super.a += 1; + static z7 = (() => { super.a = 0; })(); + static z8 = [super.a] = [0]; + static z9 = [super.a = 0] = [0]; + static z10 = [...super.a] = [0]; + static z11 = { x: super.a } = { x: 0 }; + static z12 = { x: super.a = 0 } = { x: 0 }; + static z13 = { ...super.a } = { x: 0 }; + static z14 = ++super.a; + static z15 = --super.a; + static z16 = ++super[("a")]; + static z17 = super.a++; + static z18 = super.a``; + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers3.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers3.ts new file mode 100644 index 0000000000000..413c7c54bc832 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers3.ts @@ -0,0 +1,26 @@ +// @target: es5 +// @useDefineForClassFields: true +// @noTypesAndSymbols: true + +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z3 = super.f(); + static z4 = super["f"](); + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers4.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers4.ts new file mode 100644 index 0000000000000..aad82e41dc531 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/thisAndSuperInStaticMembers4.ts @@ -0,0 +1,26 @@ +// @target: es5 +// @useDefineForClassFields: false +// @noTypesAndSymbols: true + +declare class B { + static a: any; + static f(): number; + a: number; + f(): number; +} + +class C extends B { + static x: any = undefined!; + static y1 = this.x; + static y2 = this.x(); + static y3 = this?.x(); + static y4 = this[("x")](); + static y5 = this?.[("x")](); + static z3 = super.f(); + static z4 = super["f"](); + + // these should be unaffected + x = 1; + y = this.x; + z = super.f(); +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts new file mode 100644 index 0000000000000..bb458c87d29a1 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers10.ts @@ -0,0 +1,51 @@ +// @target: esnext, es6, es5 +// @experimentalDecorators: true +// @useDefineForClassFields: false + +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts new file mode 100644 index 0000000000000..6c4025bc4707e --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers11.ts @@ -0,0 +1,51 @@ +// @target: esnext, es6, es5 +// @experimentalDecorators: true +// @useDefineForClassFields: true + +declare const foo: any; + +@foo +class C { + static a = 1; + static b = this.a + 1; +} + +@foo +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} + +class CC { + static a = 1; + static b = this.a + 1; +} + +class DD extends CC { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; + static f = () => this.c + 1; + static ff = function () { this.c + 1 } + static foo () { + return this.c + 1; + } + static get fa () { + return this.c + 1; + } + static set fa (v: number) { + this.c = v + 1; + } +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts new file mode 100644 index 0000000000000..041089512bfa8 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers12.ts @@ -0,0 +1,10 @@ +// @target: esnext, es6, es5 +// @useDefineForClassFields: false + +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts new file mode 100644 index 0000000000000..6c965e0e2d55f --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers13.ts @@ -0,0 +1,10 @@ +// @target: esnext, es6, es5 +// @useDefineForClassFields: true + +class C { + static readonly c: "foo" = "foo" + static bar = class Inner { + static [this.c] = 123; + [this.c] = 123; + } +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts index 7ab6fc48b3908..e6666219f55e6 100644 --- a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers2.ts @@ -1,7 +1,7 @@ class C { - static foo = this; // error + static foo = this; // ok } class C2 { - static foo = this; // error + static foo = this; // ok } \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts new file mode 100644 index 0000000000000..27541ce361dbd --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers3.ts @@ -0,0 +1,12 @@ +// @target: esnext, es6, es5 +// @useDefineForClassFields: false +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts new file mode 100644 index 0000000000000..0d08423bb9ce1 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers4.ts @@ -0,0 +1,12 @@ +// @target: esnext, es6, es5 +// @useDefineForClassFields: true +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = super.a + this.c + 1; +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts new file mode 100644 index 0000000000000..db6e8a76c6499 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers5.ts @@ -0,0 +1,9 @@ +// @target: esnext, es6, es5 + +class C { + static create = () => new this("yep") + + constructor (private foo: string) { + + } +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts new file mode 100644 index 0000000000000..b27d0855a2d8d --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers6.ts @@ -0,0 +1,7 @@ +class C { + static f = 1 +} + +class D extends C { + static c = super(); +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts new file mode 100644 index 0000000000000..1a2d9cd2e20eb --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers7.ts @@ -0,0 +1,12 @@ +// @target: esnext, es6, es5 + +class C { + static a = 1; + static b = this.a + 1; +} + +class D extends C { + static c = 2; + static d = this.c + 1; + static e = 1 + (super.a) + (this.c + 1) + 1; +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts new file mode 100644 index 0000000000000..8b26476f143cf --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers8.ts @@ -0,0 +1,19 @@ +// @target: esnext, es6, es5 + +class C { + static f = 1; + static arrowFunctionBoundary = () => this.f + 1; + static functionExprBoundary = function () { return this.f + 2 }; + static classExprBoundary = class { a = this.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return this.f + 4 + } + class CC { + a = this.f + 5 + method () { + return this.f + 6 + } + } + })(); +} diff --git a/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts new file mode 100644 index 0000000000000..0a648d2fa08a1 --- /dev/null +++ b/tests/cases/conformance/classes/members/instanceAndStaticMembers/typeOfThisInStaticMembers9.ts @@ -0,0 +1,22 @@ +// @target: esnext, es6, es5 + +class C { + static f = 1 +} + +class D extends C { + static arrowFunctionBoundary = () => super.f + 1; + static functionExprBoundary = function () { return super.f + 2 }; + static classExprBoundary = class { a = super.f + 3 }; + static functionAndClassDeclBoundary = (() => { + function foo () { + return super.f + 4 + } + class C { + a = super.f + 5 + method () { + return super.f +6 + } + } + })(); +} diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts index 2b929318c13fe..fdcb9c410b401 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts @@ -1,8 +1,3 @@ -//'this' in static member initializer -class ErrClass1 { - static t = this; // Error -} - class BaseErrClass { constructor(t: any) { } } diff --git a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts index e3d8ce9f5fcd2..7791be14650f4 100644 --- a/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts +++ b/tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts @@ -1,8 +1,3 @@ -//'this' in static member initializer -class ErrClass1 { - static t = this; // Error -} - class BaseErrClass { constructor(t: any) { } } diff --git a/tests/cases/conformance/types/conditional/variance.ts b/tests/cases/conformance/types/conditional/variance.ts index 1dd5db5c67e8f..11fccaa0f9d6d 100644 --- a/tests/cases/conformance/types/conditional/variance.ts +++ b/tests/cases/conformance/types/conditional/variance.ts @@ -17,7 +17,7 @@ const z: Foo = x; // Repro from #30118 class Bar { - private static instance: Bar[]; + private static instance: Bar[] = []; cast(_name: ([T] extends [string] ? string : string)) { } diff --git a/tests/cases/fourslash/codeFixAddMissingMember7.ts b/tests/cases/fourslash/codeFixAddMissingMember7.ts index 95fbb4be18cba..cdb389ceaeb6d 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember7.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember7.ts @@ -10,7 +10,7 @@ verify.codeFix({ description: "Initialize static property 'foo'", - index: 2, + index: 0, newFileContent: `class C { static p = ()=>{ this.foo === 10 }; }