diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a060076951def..490b1bd9fbd40 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1832,6 +1832,7 @@ namespace ts { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: case SyntaxKind.ConstructorType: + case SyntaxKind.ClassStaticBlockDeclaration: return ContainerFlags.IsContainer | ContainerFlags.IsControlFlowContainer | ContainerFlags.HasLocals | ContainerFlags.IsFunctionLike; case SyntaxKind.FunctionExpression: @@ -1867,7 +1868,7 @@ namespace ts { // By not creating a new block-scoped-container here, we ensure that both 'var x' // and 'let x' go into the Function-container's locals, and we do get a collision // conflict. - return isFunctionLike(node.parent) ? ContainerFlags.None : ContainerFlags.IsBlockScopedContainer; + return isFunctionLike(node.parent) || isClassStaticBlockDeclaration(node.parent) ? ContainerFlags.None : ContainerFlags.IsBlockScopedContainer; } return ContainerFlags.None; @@ -1929,6 +1930,7 @@ namespace ts { case SyntaxKind.JSDocFunctionType: case SyntaxKind.JSDocTypedefTag: case SyntaxKind.JSDocCallbackTag: + case SyntaxKind.ClassStaticBlockDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.MappedType: // All the children of these container types are never visible through another @@ -2328,7 +2330,7 @@ namespace ts { // Report error if function is not top level function declaration if (blockScopeContainer.kind !== SyntaxKind.SourceFile && blockScopeContainer.kind !== SyntaxKind.ModuleDeclaration && - !isFunctionLike(blockScopeContainer)) { + !isFunctionLikeOrClassStaticBlockDeclaration(blockScopeContainer)) { // We check first if the name is inside class declaration or class expression; if so give explicit message // otherwise report generic error message. const errorSpan = getErrorSpanForNode(file, node); @@ -2712,7 +2714,7 @@ namespace ts { updateStrictModeStatementList((node as SourceFile).statements); return bindSourceFileIfExternalModule(); case SyntaxKind.Block: - if (!isFunctionLike(node.parent)) { + if (!isFunctionLikeOrClassStaticBlockDeclaration(node.parent)) { return; } // falls through diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2a25f0daa7817..f0eff1254b094 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24185,7 +24185,7 @@ namespace ts { // To avoid that we will give an error to users if they use arguments objects in arrow function so that they // can explicitly bound arguments objects if (symbol === argumentsSymbol) { - if (isInPropertyInitializer(node)) { + if (isInPropertyInitializerOrClassStaticBlock(node)) { error(node, Diagnostics.arguments_cannot_be_referenced_in_property_initializers); return errorType; } @@ -24543,6 +24543,9 @@ 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.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; @@ -24601,7 +24604,8 @@ namespace ts { if (isClassLike(container.parent)) { const symbol = getSymbolOfNode(container.parent); - const type = hasSyntacticModifier(container, ModifierFlags.Static) ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; + const isStatic = hasSyntacticModifier(container, ModifierFlags.Static) || isClassStaticBlockDeclaration(container); + const type = isStatic ? getTypeOfSymbol(symbol) : (getDeclaredTypeOfSymbol(symbol) as InterfaceType).thisType!; return getFlowTypeOfReference(node, type); } @@ -27564,7 +27568,7 @@ namespace ts { let diagnosticMessage; const declarationName = idText(right); - if (isInPropertyInitializer(node) + if (isInPropertyInitializerOrClassStaticBlock(node) && !isOptionalPropertyDeclaration(valueDeclaration) && !(isAccessExpression(node) && isAccessExpression(node.expression)) && !isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right) @@ -27585,7 +27589,7 @@ namespace ts { } } - function isInPropertyInitializer(node: Node): boolean { + function isInPropertyInitializerOrClassStaticBlock(node: Node): boolean { return !!findAncestor(node, node => { switch (node.kind) { case SyntaxKind.PropertyDeclaration: @@ -27605,6 +27609,8 @@ namespace ts { case SyntaxKind.ExpressionWithTypeArguments: case SyntaxKind.HeritageClause: return false; + case SyntaxKind.ExpressionStatement: + return isBlock(node.parent) && isClassStaticBlockDeclaration(node.parent.parent) ? true : "quit"; default: return isExpressionNode(node) ? false : "quit"; } @@ -31269,7 +31275,11 @@ namespace ts { function checkAwaitExpression(node: AwaitExpression): Type { // Grammar checking if (produceDiagnostics) { - if (!(node.flags & NodeFlags.AwaitContext)) { + const container = getContainingFunctionOrClassStaticBlock(node); + if (container && isClassStaticBlockDeclaration(container)) { + error(node, Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block); + } + else if (!(node.flags & NodeFlags.AwaitContext)) { if (isInTopLevelContext(node)) { const sourceFile = getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { @@ -31294,9 +31304,8 @@ namespace ts { if (!hasParseDiagnostics(sourceFile)) { const span = getSpanOfTokenAtPosition(sourceFile, node.pos); const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules); - const func = getContainingFunction(node); - if (func && func.kind !== SyntaxKind.Constructor && (getFunctionFlags(func) & FunctionFlags.Async) === 0) { - const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async); + if (container && container.kind !== SyntaxKind.Constructor && (getFunctionFlags(container) & FunctionFlags.Async) === 0) { + const relatedInfo = createDiagnosticForNode(container, Diagnostics.Did_you_mean_to_mark_this_function_as_async); addRelatedInfo(diagnostic, relatedInfo); } diagnostics.add(diagnostic); @@ -33455,6 +33464,12 @@ namespace ts { } } + function checkClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { + checkGrammarDecoratorsAndModifiers(node); + + forEachChild(node, checkSourceElement); + } + function checkConstructorDeclaration(node: ConstructorDeclaration) { // Grammar check on signature of constructor and modifier of the constructor is done in checkSignatureDeclaration function. checkSignatureDeclaration(node); @@ -35062,10 +35077,11 @@ namespace ts { break; case SyntaxKind.IndexSignature: case SyntaxKind.SemicolonClassElement: + case SyntaxKind.ClassStaticBlockDeclaration: // Can't be private break; default: - Debug.fail(); + Debug.fail("Unexpected class member"); } } } @@ -35497,6 +35513,7 @@ namespace ts { if (!node.name) { return; } + // For a computed property, just check the initializer and exit // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including @@ -35873,11 +35890,17 @@ namespace ts { function checkForOfStatement(node: ForOfStatement): void { checkGrammarForInOrForOfStatement(node); + const container = getContainingFunctionOrClassStaticBlock(node); if (node.awaitModifier) { - const functionFlags = getFunctionFlags(getContainingFunction(node)); - if ((functionFlags & (FunctionFlags.Invalid | FunctionFlags.Async)) === FunctionFlags.Async && languageVersion < ScriptTarget.ESNext) { - // for..await..of in an async function or async generator function prior to ESNext requires the __asyncValues helper - checkExternalEmitHelpers(node, ExternalEmitHelpers.ForAwaitOfIncludes); + if (container && isClassStaticBlockDeclaration(container)) { + grammarErrorOnNode(node.awaitModifier, Diagnostics.For_await_loops_cannot_be_used_inside_a_class_static_block); + } + else { + const functionFlags = getFunctionFlags(container); + if ((functionFlags & (FunctionFlags.Invalid | FunctionFlags.Async)) === FunctionFlags.Async && languageVersion < ScriptTarget.ESNext) { + // for..await..of in an async function or async generator function prior to ESNext requires the __asyncValues helper + checkExternalEmitHelpers(node, ExternalEmitHelpers.ForAwaitOfIncludes); + } } } else if (compilerOptions.downlevelIteration && languageVersion < ScriptTarget.ES2015) { @@ -36757,28 +36780,33 @@ namespace ts { return; } - const func = getContainingFunction(node); - if (!func) { + const container = getContainingFunctionOrClassStaticBlock(node); + if(container && isClassStaticBlockDeclaration(container)) { + grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block); + return; + } + + if (!container) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); return; } - const signature = getSignatureFromDeclaration(func); + const signature = getSignatureFromDeclaration(container); const returnType = getReturnTypeOfSignature(signature); - const functionFlags = getFunctionFlags(func); + const functionFlags = getFunctionFlags(container); if (strictNullChecks || node.expression || returnType.flags & TypeFlags.Never) { const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType; - if (func.kind === SyntaxKind.SetAccessor) { + if (container.kind === SyntaxKind.SetAccessor) { if (node.expression) { error(node, Diagnostics.Setters_cannot_return_a_value); } } - else if (func.kind === SyntaxKind.Constructor) { + else if (container.kind === SyntaxKind.Constructor) { if (node.expression && !checkTypeAssignableToAndOptionallyElaborate(exprType, returnType, node, node.expression)) { error(node, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } - else if (getReturnTypeFromAnnotation(func)) { + else if (getReturnTypeFromAnnotation(container)) { const unwrappedReturnType = unwrapReturnType(returnType, functionFlags) ?? returnType; const unwrappedExprType = functionFlags & FunctionFlags.Async ? checkAwaitedType(exprType, node, Diagnostics.The_return_type_of_an_async_function_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member) @@ -36791,7 +36819,7 @@ namespace ts { } } } - else if (func.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(func, returnType)) { + else if (container.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(container, returnType)) { // The function has a return type, but the return statement doesn't have an expression. error(node, Diagnostics.Not_all_code_paths_return_a_value); } @@ -38621,6 +38649,8 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return checkMethodDeclaration(node as MethodDeclaration | MethodSignature); + case SyntaxKind.ClassStaticBlockDeclaration: + return checkClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); case SyntaxKind.Constructor: return checkConstructorDeclaration(node as ConstructorDeclaration); case SyntaxKind.GetAccessor: @@ -41098,6 +41128,7 @@ namespace ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.VariableStatement: case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.ClassStaticBlockDeclaration: return true; case SyntaxKind.EnumDeclaration: return nodeHasAnyModifiersExcept(node, SyntaxKind.ConstKeyword); @@ -41835,7 +41866,7 @@ namespace ts { function checkGrammarBreakOrContinueStatement(node: BreakOrContinueStatement): boolean { let current: Node = node; while (current) { - if (isFunctionLike(current)) { + if (isFunctionLikeOrClassStaticBlockDeclaration(current)) { return grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c3c5600a8ef32..ac42b13400b99 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -7154,5 +7154,21 @@ "Class decorators can't be used with static private identifier. Consider removing the experimental decorator.": { "category": "Error", "code": 18036 + }, + "Await expression cannot be used inside a class static block.": { + "category": "Error", + "code": 18037 + }, + "'For await' loops cannot be used inside a class static block.": { + "category": "Error", + "code": 18038 + }, + "Invalid use of '{0}'. It cannot be used inside a class static block.": { + "category": "Error", + "code": 18039 + }, + "A 'return' statement cannot be used inside a class static block.": { + "category": "Error", + "code": 18041 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 483310a6002fc..5667e792b4606 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1351,6 +1351,8 @@ namespace ts { return emitMethodSignature(node as MethodSignature); case SyntaxKind.MethodDeclaration: return emitMethodDeclaration(node as MethodDeclaration); + case SyntaxKind.ClassStaticBlockDeclaration: + return emitClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); case SyntaxKind.Constructor: return emitConstructor(node as ConstructorDeclaration); case SyntaxKind.GetAccessor: @@ -2063,6 +2065,13 @@ namespace ts { emitSignatureAndBody(node, emitSignatureHead); } + function emitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { + emitDecorators(node, node.decorators); + emitModifiers(node, node.modifiers); + writeKeyword("static"); + emitBlockFunctionBody(node.body); + } + function emitConstructor(node: ConstructorDeclaration) { emitModifiers(node, node.modifiers); writeKeyword("constructor"); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 64aa7bbb5f311..a49e748c2b449 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -94,6 +94,8 @@ namespace ts { updateConstructSignature, createIndexSignature, updateIndexSignature, + createClassStaticBlockDeclaration, + updateClassStaticBlockDeclaration, createTemplateLiteralTypeSpan, updateTemplateLiteralTypeSpan, createKeywordTypeNode, @@ -1415,6 +1417,38 @@ namespace ts { : node; } + // @api + function createClassStaticBlockDeclaration( + decorators: readonly Decorator[] | undefined, + modifiers: readonly Modifier[] | undefined, + body: Block + ): ClassStaticBlockDeclaration { + const node = createBaseGenericNamedDeclaration( + SyntaxKind.ClassStaticBlockDeclaration, + decorators, + modifiers, + /*name*/ undefined, + /*typeParameters*/ undefined + ); + node.body = body; + node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; + return node; + } + + // @api + function updateClassStaticBlockDeclaration( + node: ClassStaticBlockDeclaration, + decorators: readonly Decorator[] | undefined, + modifiers: readonly Modifier[] | undefined, + body: Block + ): ClassStaticBlockDeclaration { + return node.decorators !== decorators + || node.modifier !== modifiers + || node.body !== body + ? update(createClassStaticBlockDeclaration(decorators, modifiers, body), node) + : node; + } + // @api function createConstructorDeclaration( decorators: readonly Decorator[] | undefined, diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index fbe8a1ccd69fa..270fded5c920b 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -182,6 +182,10 @@ namespace ts { return node.kind === SyntaxKind.MethodDeclaration; } + export function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration { + return node.kind === SyntaxKind.ClassStaticBlockDeclaration; + } + export function isConstructorDeclaration(node: Node): node is ConstructorDeclaration { return node.kind === SyntaxKind.Constructor; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 4ba7f4fad5804..f3ac472e122b0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -168,6 +168,10 @@ namespace ts { visitNode(cbNode, (node as FunctionLikeDeclaration).type) || visitNode(cbNode, (node as ArrowFunction).equalsGreaterThanToken) || visitNode(cbNode, (node as FunctionLikeDeclaration).body); + case SyntaxKind.ClassStaticBlockDeclaration: + return visitNodes(cbNode, cbNodes, node.decorators) || + visitNodes(cbNode, cbNodes, node.modifiers) || + visitNode(cbNode, (node as ClassStaticBlockDeclaration).body); case SyntaxKind.TypeReference: return visitNode(cbNode, (node as TypeReferenceNode).typeName) || visitNodes(cbNode, cbNodes, (node as TypeReferenceNode).typeArguments); @@ -5573,10 +5577,8 @@ namespace ts { // // FunctionExpression: // function BindingIdentifier[opt](FormalParameters){ FunctionBody } - const saveDecoratorContext = inDecoratorContext(); - if (saveDecoratorContext) { - setDecoratorContext(/*val*/ false); - } + const savedDecoratorContext = inDecoratorContext(); + setDecoratorContext(/*val*/ false); const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -5585,8 +5587,7 @@ namespace ts { const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; const isAsync = some(modifiers, isAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; - const name = - isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : + const name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : isGenerator ? doInYieldContext(parseOptionalBindingIdentifier) : isAsync ? doInAwaitContext(parseOptionalBindingIdentifier) : parseOptionalBindingIdentifier(); @@ -5596,9 +5597,7 @@ namespace ts { const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlock(isGenerator | isAsync); - if (saveDecoratorContext) { - setDecoratorContext(/*val*/ true); - } + setDecoratorContext(savedDecoratorContext); const node = factory.createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -6422,7 +6421,7 @@ namespace ts { // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. - let declarations; + let declarations: readonly VariableDeclaration[]; if (token() === SyntaxKind.OfKeyword && lookAhead(canFollowContextualOfKeyword)) { declarations = createMissingList(); } @@ -6454,6 +6453,7 @@ namespace ts { function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): FunctionDeclaration { const savedAwaitContext = inAwaitContext(); + const modifierFlags = modifiersToFlags(modifiers); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -6649,6 +6649,27 @@ namespace ts { return false; } + function parseClassStaticBlockDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: ModifiersArray | undefined): ClassStaticBlockDeclaration { + parseExpectedToken(SyntaxKind.StaticKeyword); + const body = parseClassStaticBlockBody(); + return withJSDoc(finishNode(factory.createClassStaticBlockDeclaration(decorators, modifiers, body), pos), hasJSDoc); + } + + function parseClassStaticBlockBody() { + const savedYieldContext = inYieldContext(); + const savedAwaitContext = inAwaitContext(); + + setYieldContext(false); + setAwaitContext(true); + + const body = parseBlock(/*ignoreMissingOpenBrace*/ false); + + setYieldContext(savedYieldContext); + setAwaitContext(savedAwaitContext); + + return body; + } + function parseDecoratorExpression() { if (inAwaitContext() && token() === SyntaxKind.AwaitKeyword) { // `@await` is is disallowed in an [Await] context, but can cause parsing to go off the rails @@ -6680,7 +6701,7 @@ namespace ts { return list && createNodeArray(list, pos); } - function tryParseModifier(permitInvalidConstAsModifier?: boolean): Modifier | undefined { + function tryParseModifier(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): Modifier | undefined { const pos = getNodePos(); const kind = token(); @@ -6691,6 +6712,9 @@ namespace ts { return undefined; } } + else if (stopOnStartOfClassStaticBlock && token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) { + return undefined; + } else { if (!parseAnyContextualModifier()) { return undefined; @@ -6707,10 +6731,10 @@ namespace ts { * * In such situations, 'permitInvalidConstAsModifier' should be set to true. */ - function parseModifiers(permitInvalidConstAsModifier?: boolean): NodeArray | undefined { + function parseModifiers(permitInvalidConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean): NodeArray | undefined { const pos = getNodePos(); let list, modifier; - while (modifier = tryParseModifier(permitInvalidConstAsModifier)) { + while (modifier = tryParseModifier(permitInvalidConstAsModifier, stopOnStartOfClassStaticBlock)) { list = append(list, modifier); } return list && createNodeArray(list, pos); @@ -6736,7 +6760,10 @@ namespace ts { const hasJSDoc = hasPrecedingJSDocComment(); const decorators = parseDecorators(); - const modifiers = parseModifiers(/*permitInvalidConstAsModifier*/ true); + const modifiers = parseModifiers(/*permitInvalidConstAsModifier*/ true, /*stopOnStartOfClassStaticBlock*/ true); + if (token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) { + return parseClassStaticBlockDeclaration(pos, hasJSDoc, decorators, modifiers); + } if (parseContextualModifier(SyntaxKind.GetKeyword)) { return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor); @@ -6797,6 +6824,7 @@ namespace ts { function parseClassDeclarationOrExpression(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: ClassLikeDeclaration["kind"]): ClassLikeDeclaration { const savedAwaitContext = inAwaitContext(); parseExpected(SyntaxKind.ClassKeyword); + // We don't parse the name here in await context, instead we will report a grammar error in the checker. const name = parseNameOfClassDeclarationOrExpression(); const typeParameters = parseTypeParameters(); @@ -6998,6 +7026,10 @@ namespace ts { return nextToken() === SyntaxKind.OpenParenToken; } + function nextTokenIsOpenBrace() { + return nextToken() === SyntaxKind.OpenBraceToken; + } + function nextTokenIsSlash() { return nextToken() === SyntaxKind.SlashToken; } diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index e820851dde949..6ce6c7dd58c76 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -102,6 +102,7 @@ namespace ts { factory, hoistVariableDeclaration, endLexicalEnvironment, + startLexicalEnvironment, resumeLexicalEnvironment, addBlockScopedVariable } = context; @@ -110,7 +111,7 @@ namespace ts { const languageVersion = getEmitScriptTarget(compilerOptions); const useDefineForClassFields = getUseDefineForClassFields(compilerOptions); - const shouldTransformPrivateElements = languageVersion < ScriptTarget.ESNext; + const shouldTransformPrivateElementsOrClassStaticBlocks = languageVersion < ScriptTarget.ESNext; const previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; @@ -176,10 +177,20 @@ namespace ts { return visitForStatement(node as ForStatement); case SyntaxKind.TaggedTemplateExpression: return visitTaggedTemplateExpression(node as TaggedTemplateExpression); + case SyntaxKind.ClassStaticBlockDeclaration: + return visitClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); } return visitEachChild(node, visitor, context); } + function visitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks) { + return visitEachChild(node, classElementVisitor, context); + } + // ClassStaticBlockDeclaration for classes are transformed in `visitClassDeclaration` or `visitClassExpression`. + return undefined; + } + function visitorDestructuringTarget(node: Node): VisitResult { switch (node.kind) { case SyntaxKind.ObjectLiteralExpression: @@ -195,7 +206,7 @@ namespace ts { * Replace it with an empty identifier to indicate a problem with the code. */ function visitPrivateIdentifier(node: PrivateIdentifier) { - if (!shouldTransformPrivateElements) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks) { return node; } return setOriginalNode(factory.createIdentifier(""), node); @@ -262,7 +273,7 @@ namespace ts { function visitMethodOrAccessorDeclaration(node: MethodDeclaration | AccessorDeclaration) { Debug.assert(!some(node.decorators)); - if (!shouldTransformPrivateElements || !isPrivateIdentifier(node.name)) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks || !isPrivateIdentifier(node.name)) { return visitEachChild(node, classElementVisitor, context); } @@ -318,7 +329,7 @@ namespace ts { Debug.assert(!some(node.decorators)); if (isPrivateIdentifier(node.name)) { - if (!shouldTransformPrivateElements) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks) { // Initializer is elided as the field is initialized in transformConstructor. return factory.updatePropertyDeclaration( node, @@ -383,7 +394,7 @@ namespace ts { } function visitPropertyAccessExpression(node: PropertyAccessExpression) { - if (shouldTransformPrivateElements && isPrivateIdentifier(node.name)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(node.name)) { const privateIdentifierInfo = accessPrivateIdentifier(node.name); if (privateIdentifierInfo) { return setTextRange( @@ -399,7 +410,7 @@ namespace ts { } function visitPrefixUnaryExpression(node: PrefixUnaryExpression) { - if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.operand)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.operand)) { const operator = node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusToken : node.operator === SyntaxKind.MinusMinusToken ? SyntaxKind.MinusToken : undefined; @@ -425,7 +436,7 @@ namespace ts { } function visitPostfixUnaryExpression(node: PostfixUnaryExpression, valueIsDiscarded: boolean) { - if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.operand)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.operand)) { const operator = node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusToken : node.operator === SyntaxKind.MinusMinusToken ? SyntaxKind.MinusToken : undefined; @@ -491,7 +502,7 @@ namespace ts { } function visitCallExpression(node: CallExpression) { - if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.expression)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.expression)) { // Transform call expressions of private names to properly bind the `this` parameter. const { thisArg, target } = factory.createCallBinding(node.expression, hoistVariableDeclaration, languageVersion); if (isCallChain(node)) { @@ -514,7 +525,7 @@ namespace ts { } function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { - if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.tag)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.tag)) { // Bind the `this` correctly for tagged template literals when the tag is a private identifier property access. const { thisArg, target } = factory.createCallBinding(node.tag, hoistVariableDeclaration, languageVersion); return factory.updateTaggedTemplateExpression( @@ -531,8 +542,24 @@ namespace ts { return visitEachChild(node, visitor, context); } + function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { + startLexicalEnvironment(); + let statements = visitNodes(node.body.statements, visitor, isStatement); + statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); + + return setTextRange( + setOriginalNode( + factory.createImmediatelyInvokedArrowFunction(statements), + node + ), + node + ); + } + } + function visitBinaryExpression(node: BinaryExpression) { - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { if (isDestructuringAssignment(node)) { const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined; @@ -616,7 +643,7 @@ namespace ts { function visitClassLike(node: ClassLikeDeclaration) { const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined; - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { startPrivateIdentifierEnvironment(); const name = getNameOfDeclaration(node); @@ -637,7 +664,7 @@ namespace ts { visitClassDeclaration(node) : visitClassExpression(node); - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { endPrivateIdentifierEnvironment(); } pendingExpressions = savedPendingExpressions; @@ -645,7 +672,7 @@ namespace ts { } function doesClassElementNeedTransform(node: ClassElement) { - return isPropertyDeclaration(node) || (shouldTransformPrivateElements && node.name && isPrivateIdentifier(node.name)); + return isPropertyDeclaration(node) || isClassStaticBlockDeclaration(node) || (shouldTransformPrivateElementsOrClassStaticBlocks && node.name && isPrivateIdentifier(node.name)); } function getPrivateInstanceMethodsAndAccessors(node: ClassLikeDeclaration) { @@ -657,9 +684,9 @@ namespace ts { return visitEachChild(node, visitor, context); } - const staticProperties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ true); + const staticProperties = getStaticPropertiesAndClassStaticBlock(node); let pendingPrivateStateAssignment: BinaryExpression | undefined; - if (shouldTransformPrivateElements && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { + 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( @@ -699,7 +726,7 @@ namespace ts { // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. if (some(staticProperties)) { - addPropertyStatements(statements, staticProperties, factory.getInternalName(node)); + addPropertyOrClassStaticBlockStatements(statements, staticProperties, factory.getInternalName(node)); } return statements; @@ -719,7 +746,7 @@ namespace ts { // these statements after the class expression variable statement. const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); - const staticProperties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ true); + const staticPropertiesOrClassStaticBlocks = getStaticPropertiesAndClassStaticBlock(node); const extendsClauseElement = getEffectiveBaseTypeNode(node); const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); @@ -732,7 +759,7 @@ namespace ts { const requiresBlockScopedVar = classCheckFlags & NodeCheckFlags.BlockScopedBindingInLoop; return factory.createTempVariable(requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration, !!isClassWithConstructorReference); } - if (shouldTransformPrivateElements && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { temp = createClassTempVar(); getPrivateIdentifierEnvironment().classConstructor = factory.cloneNode(temp); } @@ -746,7 +773,7 @@ namespace ts { visitNodes(node.heritageClauses, visitor, isHeritageClause), transformClassMembers(node, isDerivedClass) ); - const hasTransformableStatics = some(staticProperties, p => !!p.initializer || (shouldTransformPrivateElements && isPrivateIdentifier(p.name))); + const hasTransformableStatics = some(staticPropertiesOrClassStaticBlocks, p => isClassStaticBlockDeclaration(p) || !!p.initializer || (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(p.name))); if (hasTransformableStatics || some(pendingExpressions)) { if (isDecoratedClassDeclaration) { Debug.assertIsDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); @@ -756,8 +783,8 @@ namespace ts { pendingStatements.push(factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions))); } - if (pendingStatements && some(staticProperties)) { - addPropertyStatements(pendingStatements, staticProperties, factory.getInternalName(node)); + if (pendingStatements && some(staticPropertiesOrClassStaticBlocks)) { + addPropertyOrClassStaticBlockStatements(pendingStatements, staticPropertiesOrClassStaticBlocks, factory.getInternalName(node)); } if (temp) { return factory.inlineExpressions([factory.createAssignment(temp, classExpression), temp]); @@ -781,7 +808,7 @@ namespace ts { expressions.push(startOnNewLine(factory.createAssignment(temp, classExpression))); // Add any pending expressions leftover from elided or relocated computed property names addRange(expressions, map(pendingExpressions, startOnNewLine)); - addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); + addRange(expressions, generateInitializedPropertyExpressionsOrClassStaticBlock(staticPropertiesOrClassStaticBlocks, temp)); expressions.push(startOnNewLine(temp)); @@ -793,7 +820,7 @@ namespace ts { } function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { // Declare private names. for (const member of node.members) { if (isPrivateIdentifierClassElementDeclaration(member)) { @@ -840,7 +867,7 @@ namespace ts { // then we don't need to transform any class properties. return languageVersion < ScriptTarget.ESNext; } - return isInitializedProperty(member) || shouldTransformPrivateElements && isPrivateIdentifierClassElementDeclaration(member); + return isInitializedProperty(member) || shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierClassElementDeclaration(member); } function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { @@ -933,7 +960,7 @@ namespace ts { const receiver = factory.createThis(); // private methods can be called in property initializers, they should execute first. addMethodStatements(statements, privateMethodsAndAccessors, receiver); - addPropertyStatements(statements, properties, receiver); + addPropertyOrClassStaticBlockStatements(statements, properties, receiver); // Add existing statements, skipping the initial super call. if (constructor) { @@ -960,9 +987,9 @@ namespace ts { * @param properties An array of property declarations to transform. * @param receiver The receiver on which each property should be assigned. */ - function addPropertyStatements(statements: Statement[], properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { + function addPropertyOrClassStaticBlockStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { for (const property of properties) { - const expression = transformProperty(property, receiver); + const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property) : transformProperty(property, receiver); if (!expression) { continue; } @@ -977,13 +1004,13 @@ namespace ts { /** * Generates assignment expressions for property initializers. * - * @param properties An array of property declarations to transform. + * @param propertiesOrClassStaticBlocks An array of property declarations to transform. * @param receiver The receiver on which each property should be assigned. */ - function generateInitializedPropertyExpressions(properties: readonly PropertyDeclaration[], receiver: LeftHandSideExpression) { + function generateInitializedPropertyExpressionsOrClassStaticBlock(propertiesOrClassStaticBlocks: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { const expressions: Expression[] = []; - for (const property of properties) { - const expression = transformProperty(property, receiver); + for (const property of propertiesOrClassStaticBlocks) { + const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property) : transformProperty(property, receiver); if (!expression) { continue; } @@ -1010,7 +1037,7 @@ namespace ts { ? factory.updateComputedPropertyName(property.name, factory.getGeneratedNameForNode(property.name)) : property.name; - if (shouldTransformPrivateElements && isPrivateIdentifier(propertyName)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(propertyName)) { const privateIdentifierInfo = accessPrivateIdentifier(propertyName); if (privateIdentifierInfo) { if (privateIdentifierInfo.kind === PrivateIdentifierKind.Field) { @@ -1082,7 +1109,7 @@ namespace ts { * @param receiver The receiver on which each method should be assigned. */ function addMethodStatements(statements: Statement[], methods: readonly (MethodDeclaration | AccessorDeclaration)[], receiver: LeftHandSideExpression) { - if (!shouldTransformPrivateElements || !some(methods)) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks || !some(methods)) { return; } @@ -1337,7 +1364,7 @@ namespace ts { getPendingExpressions().push(...assignmentExpressions); } - function createHoistedVariableForClass(name: string, node: PrivateIdentifier): Identifier { + function createHoistedVariableForClass(name: string, node: PrivateIdentifier | ClassStaticBlockDeclaration): Identifier { const { className } = getPrivateIdentifierEnvironment(); const prefix = className ? `_${className}` : ""; const identifier = factory.createUniqueName(`${prefix}_${name}`, GeneratedIdentifierFlags.Optimistic); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index cc58530f46633..d25a892cc2e69 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -569,6 +569,8 @@ namespace ts { case SyntaxKind.ExportDeclaration: case SyntaxKind.ExportAssignment: return false; + case SyntaxKind.ClassStaticBlockDeclaration: + return true; } return false; } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 5235b9330ac8a..a4baf4ae27458 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1610,6 +1610,7 @@ namespace ts { break; case SyntaxKind.Constructor: + case SyntaxKind.ClassStaticBlockDeclaration: // Constructors are handled in visitClassExpression/visitClassDeclaration break; diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 26a8a019c084f..ff416451eb72e 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -324,6 +324,7 @@ namespace ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: + case SyntaxKind.ClassStaticBlockDeclaration: // Fallback to the default visit behavior. return visitorWorker(node); diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 7e4284766d6f3..b899cf0991ea4 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -342,6 +342,16 @@ namespace ts { return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; } + function isStaticPropertyDeclarationOrClassStaticBlockDeclaration(element: ClassElement): element is PropertyDeclaration | ClassStaticBlockDeclaration { + return isStaticPropertyDeclaration(element) || isClassStaticBlockDeclaration(element); + } + + export function getStaticPropertiesAndClassStaticBlock(node: ClassExpression | ClassDeclaration): readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[]; + export function getStaticPropertiesAndClassStaticBlock(node: ClassExpression | ClassDeclaration): readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[]; + export function getStaticPropertiesAndClassStaticBlock(node: ClassExpression | ClassDeclaration): readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[] { + return filter(node.members, isStaticPropertyDeclarationOrClassStaticBlockDeclaration); + } + /** * Is a class element either a static or an instance property declaration with an initializer? * @@ -354,6 +364,10 @@ namespace ts { && hasStaticModifier(member) === isStatic; } + function isStaticPropertyDeclaration(member: ClassElement) { + return isPropertyDeclaration(member) && hasStaticModifier(member); + } + /** * Gets a value indicating whether a class element is either a static or an instance property declaration with an initializer. * diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1cc5f83ec360f..385a07414b294 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -206,6 +206,7 @@ namespace ts { PropertyDeclaration, MethodSignature, MethodDeclaration, + ClassStaticBlockDeclaration, Constructor, GetAccessor, SetAccessor, @@ -873,6 +874,7 @@ namespace ts { export type HasJSDoc = | ParameterDeclaration | CallSignatureDeclaration + | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature @@ -1535,6 +1537,14 @@ namespace ts { readonly type: TypeNode; } + export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { + readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly parent: ClassDeclaration | ClassExpression; + 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 + } + export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -7053,6 +7063,8 @@ namespace ts { updateIndexSignature(node: IndexSignatureDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, parameters: readonly ParameterDeclaration[], type: TypeNode): IndexSignatureDeclaration; createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan; updateTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan; + createClassStaticBlockDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, body: Block): ClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, body: Block): ClassStaticBlockDeclaration; // // Types diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 94dd3e86cf113..9a1fb530a64c1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -281,6 +281,7 @@ namespace ts { case SyntaxKind.ForStatement: case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: + case SyntaxKind.ClassStaticBlockDeclaration: return true; } return false; @@ -759,7 +760,7 @@ namespace ts { export function isBlockScopedContainerTopLevel(node: Node): boolean { return node.kind === SyntaxKind.SourceFile || node.kind === SyntaxKind.ModuleDeclaration || - isFunctionLike(node); + isFunctionLikeOrClassStaticBlockDeclaration(node); } export function isGlobalScopeAugmentation(module: ModuleDeclaration): boolean { @@ -849,7 +850,7 @@ namespace ts { case SyntaxKind.Block: // function block is not considered block-scope container // see comment in binder.ts: bind(...), case for SyntaxKind.Block - return !isFunctionLike(parentNode); + return !isFunctionLikeOrClassStaticBlockDeclaration(parentNode); } return false; @@ -1573,6 +1574,19 @@ namespace ts { return findAncestor(node.parent, isClassLike); } + export function getContainingClassStaticBlock(node: Node): Node | undefined { + return findAncestor(node.parent, n => { + if (isClassLike(n) || isFunctionLike(n)) { + return "quit"; + } + return isClassStaticBlockDeclaration(n); + }); + } + + export function getContainingFunctionOrClassStaticBlock(node: Node): SignatureDeclaration | ClassStaticBlockDeclaration | undefined { + return findAncestor(node.parent, isFunctionLikeOrClassStaticBlockDeclaration); + } + export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node { Debug.assert(node.kind !== SyntaxKind.SourceFile); while (true) { @@ -1618,6 +1632,7 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ClassStaticBlockDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.MethodDeclaration: diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index b156908537953..5e4b8b4275f91 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1227,6 +1227,11 @@ namespace ts { return !!node && isFunctionLikeKind(node.kind); } + /* @internal */ + export function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is SignatureDeclaration | ClassStaticBlockDeclaration { + return !!node && (isFunctionLikeKind(node.kind) || isClassStaticBlockDeclaration(node)); + } + /* @internal */ export function isFunctionLikeDeclaration(node: Node): node is FunctionLikeDeclaration { return node && isFunctionLikeDeclarationKind(node.kind); @@ -1278,6 +1283,7 @@ namespace ts { || kind === SyntaxKind.GetAccessor || kind === SyntaxKind.SetAccessor || kind === SyntaxKind.IndexSignature + || kind === SyntaxKind.ClassStaticBlockDeclaration || kind === SyntaxKind.SemicolonClassElement; } @@ -1683,6 +1689,7 @@ namespace ts { || kind === SyntaxKind.BindingElement || kind === SyntaxKind.ClassDeclaration || kind === SyntaxKind.ClassExpression + || kind === SyntaxKind.ClassStaticBlockDeclaration || kind === SyntaxKind.Constructor || kind === SyntaxKind.EnumDeclaration || kind === SyntaxKind.EnumMember diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 1758aa4397680..94ab1afbb8aa0 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -475,6 +475,15 @@ namespace ts { visitParameterList(node.parameters, visitor, context, nodesVisitor), visitFunctionBody(node.body!, visitor, context, nodeVisitor)); + case SyntaxKind.ClassStaticBlockDeclaration: + Debug.type(node); + context.startLexicalEnvironment(); + context.suspendLexicalEnvironment(); + return factory.updateClassStaticBlockDeclaration(node, + nodesVisitor(node.decorators, visitor, isDecorator), + nodesVisitor(node.modifiers, visitor, isModifier), + visitFunctionBody(node.body, visitor, context, nodeVisitor)); + case SyntaxKind.CallSignature: Debug.type(node); return factory.updateCallSignature(node, diff --git a/src/services/callHierarchy.ts b/src/services/callHierarchy.ts index 2c2a83a22cba2..bfb533b0160b2 100644 --- a/src/services/callHierarchy.ts +++ b/src/services/callHierarchy.ts @@ -30,6 +30,7 @@ namespace ts.CallHierarchy { | ModuleDeclaration & { name: Identifier } | FunctionDeclaration | ClassDeclaration + | ClassStaticBlockDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration @@ -49,6 +50,7 @@ namespace ts.CallHierarchy { || isFunctionExpression(node) || isClassDeclaration(node) || isClassExpression(node) + || isClassStaticBlockDeclaration(node) || isMethodDeclaration(node) || isMethodSignature(node) || isGetAccessorDeclaration(node) @@ -65,6 +67,7 @@ namespace ts.CallHierarchy { || isModuleDeclaration(node) && isIdentifier(node.name) || isFunctionDeclaration(node) || isClassDeclaration(node) + || isClassStaticBlockDeclaration(node) || isMethodDeclaration(node) || isMethodSignature(node) || isGetAccessorDeclaration(node) @@ -104,6 +107,16 @@ namespace ts.CallHierarchy { } } + if (isClassStaticBlockDeclaration(node)) { + const sourceFile = node.getSourceFile(); + const pos = skipTrivia(sourceFile.text, moveRangePastModifiers(node).pos); + const end = pos + 6; /* "static".length */ + const typeChecker = program.getTypeChecker(); + const symbol = typeChecker.getSymbolAtLocation(node.parent); + const prefix = symbol ? `${typeChecker.symbolToString(symbol, node.parent)} ` : ""; + return { text: `${prefix}static {}`, pos, end }; + } + const declName = isConstNamedExpression(node) ? node.parent.name : Debug.checkDefined(getNameOfDeclaration(node), "Expected call hierarchy item to have a name"); @@ -197,6 +210,9 @@ namespace ts.CallHierarchy { /** Find the implementation or the first declaration for a call hierarchy declaration. */ function findImplementationOrAllInitialDeclarations(typeChecker: TypeChecker, node: CallHierarchyDeclaration): CallHierarchyDeclaration | CallHierarchyDeclaration[] { + if (isClassStaticBlockDeclaration(node)) { + return node; + } if (isFunctionLikeDeclaration(node)) { return findImplementation(typeChecker, node) ?? findAllInitialDeclarations(typeChecker, node) ?? @@ -207,13 +223,14 @@ namespace ts.CallHierarchy { /** Resolves the call hierarchy declaration for a node. */ export function resolveCallHierarchyDeclaration(program: Program, location: Node): CallHierarchyDeclaration | CallHierarchyDeclaration[] | undefined { - // A call hierarchy item must refer to either a SourceFile, Module Declaration, or something intrinsically callable that has a name: + // A call hierarchy item must refer to either a SourceFile, Module Declaration, Class Static Block, or something intrinsically callable that has a name: // - Class Declarations // - Class Expressions (with a name) // - Function Declarations // - Function Expressions (with a name or assigned to a const variable) // - Arrow Functions (assigned to a const variable) // - Constructors + // - Class `static {}` initializer blocks // - Methods // - Accessors // @@ -249,6 +266,10 @@ namespace ts.CallHierarchy { } return undefined; } + if (location.kind === SyntaxKind.StaticKeyword && isClassStaticBlockDeclaration(location.parent)) { + location = location.parent; + continue; + } // #39453 if (isVariableDeclaration(location) && location.initializer && isConstNamedExpression(location.initializer)) { return location.initializer; @@ -322,7 +343,7 @@ namespace ts.CallHierarchy { /** Gets the call sites that call into the provided call hierarchy declaration. */ export function getIncomingCalls(program: Program, declaration: CallHierarchyDeclaration, cancellationToken: CancellationToken): CallHierarchyIncomingCall[] { // Source files and modules have no incoming calls. - if (isSourceFile(declaration) || isModuleDeclaration(declaration)) { + if (isSourceFile(declaration) || isModuleDeclaration(declaration) || isClassStaticBlockDeclaration(declaration)) { return []; } const location = getCallHierarchyDeclarationReferenceNode(declaration); @@ -331,11 +352,12 @@ namespace ts.CallHierarchy { } function createCallSiteCollector(program: Program, callSites: CallSite[]): (node: Node | undefined) => void { - function recordCallSite(node: CallExpression | NewExpression | TaggedTemplateExpression | PropertyAccessExpression | ElementAccessExpression | Decorator | JsxOpeningLikeElement) { + function recordCallSite(node: CallExpression | NewExpression | TaggedTemplateExpression | PropertyAccessExpression | ElementAccessExpression | Decorator | JsxOpeningLikeElement | ClassStaticBlockDeclaration) { const target = isTaggedTemplateExpression(node) ? node.tag : isJsxOpeningLikeElement(node) ? node.tagName : isAccessExpression(node) ? node : + isClassStaticBlockDeclaration(node) ? node : node.expression; const declaration = resolveCallHierarchyDeclaration(program, target); if (declaration) { @@ -379,6 +401,9 @@ namespace ts.CallHierarchy { case SyntaxKind.TypeAliasDeclaration: // do not descend into nodes that cannot contain callable nodes return; + case SyntaxKind.ClassStaticBlockDeclaration: + recordCallSite(node as ClassStaticBlockDeclaration); + return; case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: // do not descend into the type side of an assertion @@ -454,6 +479,10 @@ namespace ts.CallHierarchy { } } + function collectCallSitesOfClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, collect: (node: Node | undefined) => void) { + collect(node.body); + } + function collectCallSitesOfClassLikeDeclaration(node: ClassLikeDeclaration, collect: (node: Node | undefined) => void) { forEach(node.decorators, collect); const heritage = getClassExtendsHeritageElement(node); @@ -469,6 +498,9 @@ namespace ts.CallHierarchy { forEach(member.parameters, collect); collect(member.body); } + else if (isClassStaticBlockDeclaration(member)) { + collect(member); + } } } @@ -494,6 +526,9 @@ namespace ts.CallHierarchy { case SyntaxKind.ClassExpression: collectCallSitesOfClassLikeDeclaration(node, collect); break; + case SyntaxKind.ClassStaticBlockDeclaration: + collectCallSitesOfClassStaticBlockDeclaration(node, collect); + break; default: Debug.assertNever(node); } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index cbcb270917b52..8422fbe09c8da 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -884,6 +884,10 @@ namespace ts.FindAllReferences { node.kind === SyntaxKind.ReadonlyKeyword ? isReadonlyTypeOperator : undefined); } + if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) { + return [{ definition: { type: DefinitionKind.Keyword, node }, references: [nodeEntry(node)] }]; + } + // Labels if (isJumpStatementTarget(node)) { const labelDefinition = getTargetLabel(node.parent, node.text); diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 9fa856675197a..7c740fed7f060 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -22,6 +22,19 @@ namespace ts.GoToDefinition { return label ? [createDefinitionInfoFromName(typeChecker, label, ScriptElementKind.label, node.text, /*containerName*/ undefined!)] : undefined; // TODO: GH#18217 } + if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) { + const classDecl = node.parent.parent; + const symbol = getSymbol(classDecl, typeChecker); + const staticBlocks = filter(classDecl.members, isClassStaticBlockDeclaration); + const containerName = symbol ? typeChecker.symbolToString(symbol, classDecl) : ""; + const sourceFile = node.getSourceFile(); + return map(staticBlocks, staticBlock => { + let { pos } = moveRangePastModifiers(staticBlock); + pos = skipTrivia(sourceFile.text, pos); + return createDefinitionInfoFromName(typeChecker, staticBlock, ScriptElementKind.constructorImplementationElement, "static {}", containerName, { start: pos, length: "static".length }); + }); + } + const symbol = getSymbol(node, typeChecker); // Could not find a symbol e.g. node is string or number keyword, @@ -305,10 +318,12 @@ namespace ts.GoToDefinition { } /** Creates a DefinitionInfo directly from the name of a declaration. */ - function createDefinitionInfoFromName(checker: TypeChecker, declaration: Declaration, symbolKind: ScriptElementKind, symbolName: string, containerName: string): DefinitionInfo { - const name = getNameOfDeclaration(declaration) || declaration; - const sourceFile = name.getSourceFile(); - const textSpan = createTextSpanFromNode(name, sourceFile); + function createDefinitionInfoFromName(checker: TypeChecker, declaration: Declaration, symbolKind: ScriptElementKind, symbolName: string, containerName: string, textSpan?: TextSpan): DefinitionInfo { + const sourceFile = declaration.getSourceFile(); + if (!textSpan) { + const name = getNameOfDeclaration(declaration) || declaration; + textSpan = createTextSpanFromNode(name, sourceFile); + } return { fileName: sourceFile.fileName, textSpan, diff --git a/src/services/types.ts b/src/services/types.ts index be1d09ff69c57..9d0e2f52f8edc 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -1378,7 +1378,10 @@ namespace ts { */ memberVariableElement = "property", - /** class X { constructor() { } } */ + /** + * class X { constructor() { } } + * class X { static { } } + */ constructorImplementationElement = "constructor", /** interface Y { ():number; } */ diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 0fc816729ff3d..383d48391d8ad 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -416,7 +416,9 @@ namespace ts { case SyntaxKind.IndexSignature: return ScriptElementKind.indexSignatureElement; case SyntaxKind.ConstructSignature: return ScriptElementKind.constructSignatureElement; case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement; - case SyntaxKind.Constructor: return ScriptElementKind.constructorImplementationElement; + case SyntaxKind.Constructor: + case SyntaxKind.ClassStaticBlockDeclaration: + return ScriptElementKind.constructorImplementationElement; case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement; case SyntaxKind.EnumMember: return ScriptElementKind.enumMemberElement; case SyntaxKind.Parameter: return hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement; @@ -1620,7 +1622,7 @@ namespace ts { if (flags & ModifierFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier); if (flags & ModifierFlags.Protected) result.push(ScriptElementKindModifier.protectedMemberModifier); if (flags & ModifierFlags.Public) result.push(ScriptElementKindModifier.publicMemberModifier); - if (flags & ModifierFlags.Static) result.push(ScriptElementKindModifier.staticModifier); + if (flags & ModifierFlags.Static || isClassStaticBlockDeclaration(node)) result.push(ScriptElementKindModifier.staticModifier); if (flags & ModifierFlags.Abstract) result.push(ScriptElementKindModifier.abstractModifier); if (flags & ModifierFlags.Export) result.push(ScriptElementKindModifier.exportedModifier); if (flags & ModifierFlags.Deprecated) result.push(ScriptElementKindModifier.deprecatedModifier); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 7f30f901a9a16..b45a6481871e3 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -273,188 +273,189 @@ declare namespace ts { PropertyDeclaration = 165, MethodSignature = 166, MethodDeclaration = 167, - Constructor = 168, - GetAccessor = 169, - SetAccessor = 170, - CallSignature = 171, - ConstructSignature = 172, - IndexSignature = 173, - TypePredicate = 174, - TypeReference = 175, - FunctionType = 176, - ConstructorType = 177, - TypeQuery = 178, - TypeLiteral = 179, - ArrayType = 180, - TupleType = 181, - OptionalType = 182, - RestType = 183, - UnionType = 184, - IntersectionType = 185, - ConditionalType = 186, - InferType = 187, - ParenthesizedType = 188, - ThisType = 189, - TypeOperator = 190, - IndexedAccessType = 191, - MappedType = 192, - LiteralType = 193, - NamedTupleMember = 194, - TemplateLiteralType = 195, - TemplateLiteralTypeSpan = 196, - ImportType = 197, - ObjectBindingPattern = 198, - ArrayBindingPattern = 199, - BindingElement = 200, - ArrayLiteralExpression = 201, - ObjectLiteralExpression = 202, - PropertyAccessExpression = 203, - ElementAccessExpression = 204, - CallExpression = 205, - NewExpression = 206, - TaggedTemplateExpression = 207, - TypeAssertionExpression = 208, - ParenthesizedExpression = 209, - FunctionExpression = 210, - ArrowFunction = 211, - DeleteExpression = 212, - TypeOfExpression = 213, - VoidExpression = 214, - AwaitExpression = 215, - PrefixUnaryExpression = 216, - PostfixUnaryExpression = 217, - BinaryExpression = 218, - ConditionalExpression = 219, - TemplateExpression = 220, - YieldExpression = 221, - SpreadElement = 222, - ClassExpression = 223, - OmittedExpression = 224, - ExpressionWithTypeArguments = 225, - AsExpression = 226, - NonNullExpression = 227, - MetaProperty = 228, - SyntheticExpression = 229, - TemplateSpan = 230, - SemicolonClassElement = 231, - Block = 232, - EmptyStatement = 233, - VariableStatement = 234, - ExpressionStatement = 235, - IfStatement = 236, - DoStatement = 237, - WhileStatement = 238, - ForStatement = 239, - ForInStatement = 240, - ForOfStatement = 241, - ContinueStatement = 242, - BreakStatement = 243, - ReturnStatement = 244, - WithStatement = 245, - SwitchStatement = 246, - LabeledStatement = 247, - ThrowStatement = 248, - TryStatement = 249, - DebuggerStatement = 250, - VariableDeclaration = 251, - VariableDeclarationList = 252, - FunctionDeclaration = 253, - ClassDeclaration = 254, - InterfaceDeclaration = 255, - TypeAliasDeclaration = 256, - EnumDeclaration = 257, - ModuleDeclaration = 258, - ModuleBlock = 259, - CaseBlock = 260, - NamespaceExportDeclaration = 261, - ImportEqualsDeclaration = 262, - ImportDeclaration = 263, - ImportClause = 264, - NamespaceImport = 265, - NamedImports = 266, - ImportSpecifier = 267, - ExportAssignment = 268, - ExportDeclaration = 269, - NamedExports = 270, - NamespaceExport = 271, - ExportSpecifier = 272, - MissingDeclaration = 273, - ExternalModuleReference = 274, - JsxElement = 275, - JsxSelfClosingElement = 276, - JsxOpeningElement = 277, - JsxClosingElement = 278, - JsxFragment = 279, - JsxOpeningFragment = 280, - JsxClosingFragment = 281, - JsxAttribute = 282, - JsxAttributes = 283, - JsxSpreadAttribute = 284, - JsxExpression = 285, - CaseClause = 286, - DefaultClause = 287, - HeritageClause = 288, - CatchClause = 289, - PropertyAssignment = 290, - ShorthandPropertyAssignment = 291, - SpreadAssignment = 292, - EnumMember = 293, - UnparsedPrologue = 294, - UnparsedPrepend = 295, - UnparsedText = 296, - UnparsedInternalText = 297, - UnparsedSyntheticReference = 298, - SourceFile = 299, - Bundle = 300, - UnparsedSource = 301, - InputFiles = 302, - JSDocTypeExpression = 303, - JSDocNameReference = 304, - JSDocMemberName = 305, - JSDocAllType = 306, - JSDocUnknownType = 307, - JSDocNullableType = 308, - JSDocNonNullableType = 309, - JSDocOptionalType = 310, - JSDocFunctionType = 311, - JSDocVariadicType = 312, - JSDocNamepathType = 313, - JSDocComment = 314, - JSDocText = 315, - JSDocTypeLiteral = 316, - JSDocSignature = 317, - JSDocLink = 318, - JSDocLinkCode = 319, - JSDocLinkPlain = 320, - JSDocTag = 321, - JSDocAugmentsTag = 322, - JSDocImplementsTag = 323, - JSDocAuthorTag = 324, - JSDocDeprecatedTag = 325, - JSDocClassTag = 326, - JSDocPublicTag = 327, - JSDocPrivateTag = 328, - JSDocProtectedTag = 329, - JSDocReadonlyTag = 330, - JSDocOverrideTag = 331, - JSDocCallbackTag = 332, - JSDocEnumTag = 333, - JSDocParameterTag = 334, - JSDocReturnTag = 335, - JSDocThisTag = 336, - JSDocTypeTag = 337, - JSDocTemplateTag = 338, - JSDocTypedefTag = 339, - JSDocSeeTag = 340, - JSDocPropertyTag = 341, - SyntaxList = 342, - NotEmittedStatement = 343, - PartiallyEmittedExpression = 344, - CommaListExpression = 345, - MergeDeclarationMarker = 346, - EndOfDeclarationMarker = 347, - SyntheticReferenceExpression = 348, - Count = 349, + ClassStaticBlockDeclaration = 168, + Constructor = 169, + GetAccessor = 170, + SetAccessor = 171, + CallSignature = 172, + ConstructSignature = 173, + IndexSignature = 174, + TypePredicate = 175, + TypeReference = 176, + FunctionType = 177, + ConstructorType = 178, + TypeQuery = 179, + TypeLiteral = 180, + ArrayType = 181, + TupleType = 182, + OptionalType = 183, + RestType = 184, + UnionType = 185, + IntersectionType = 186, + ConditionalType = 187, + InferType = 188, + ParenthesizedType = 189, + ThisType = 190, + TypeOperator = 191, + IndexedAccessType = 192, + MappedType = 193, + LiteralType = 194, + NamedTupleMember = 195, + TemplateLiteralType = 196, + TemplateLiteralTypeSpan = 197, + ImportType = 198, + ObjectBindingPattern = 199, + ArrayBindingPattern = 200, + BindingElement = 201, + ArrayLiteralExpression = 202, + ObjectLiteralExpression = 203, + PropertyAccessExpression = 204, + ElementAccessExpression = 205, + CallExpression = 206, + NewExpression = 207, + TaggedTemplateExpression = 208, + TypeAssertionExpression = 209, + ParenthesizedExpression = 210, + FunctionExpression = 211, + ArrowFunction = 212, + DeleteExpression = 213, + TypeOfExpression = 214, + VoidExpression = 215, + AwaitExpression = 216, + PrefixUnaryExpression = 217, + PostfixUnaryExpression = 218, + BinaryExpression = 219, + ConditionalExpression = 220, + TemplateExpression = 221, + YieldExpression = 222, + SpreadElement = 223, + ClassExpression = 224, + OmittedExpression = 225, + ExpressionWithTypeArguments = 226, + AsExpression = 227, + NonNullExpression = 228, + MetaProperty = 229, + SyntheticExpression = 230, + TemplateSpan = 231, + SemicolonClassElement = 232, + Block = 233, + EmptyStatement = 234, + VariableStatement = 235, + ExpressionStatement = 236, + IfStatement = 237, + DoStatement = 238, + WhileStatement = 239, + ForStatement = 240, + ForInStatement = 241, + ForOfStatement = 242, + ContinueStatement = 243, + BreakStatement = 244, + ReturnStatement = 245, + WithStatement = 246, + SwitchStatement = 247, + LabeledStatement = 248, + ThrowStatement = 249, + TryStatement = 250, + DebuggerStatement = 251, + VariableDeclaration = 252, + VariableDeclarationList = 253, + FunctionDeclaration = 254, + ClassDeclaration = 255, + InterfaceDeclaration = 256, + TypeAliasDeclaration = 257, + EnumDeclaration = 258, + ModuleDeclaration = 259, + ModuleBlock = 260, + CaseBlock = 261, + NamespaceExportDeclaration = 262, + ImportEqualsDeclaration = 263, + ImportDeclaration = 264, + ImportClause = 265, + NamespaceImport = 266, + NamedImports = 267, + ImportSpecifier = 268, + ExportAssignment = 269, + ExportDeclaration = 270, + NamedExports = 271, + NamespaceExport = 272, + ExportSpecifier = 273, + MissingDeclaration = 274, + ExternalModuleReference = 275, + JsxElement = 276, + JsxSelfClosingElement = 277, + JsxOpeningElement = 278, + JsxClosingElement = 279, + JsxFragment = 280, + JsxOpeningFragment = 281, + JsxClosingFragment = 282, + JsxAttribute = 283, + JsxAttributes = 284, + JsxSpreadAttribute = 285, + JsxExpression = 286, + CaseClause = 287, + DefaultClause = 288, + HeritageClause = 289, + CatchClause = 290, + PropertyAssignment = 291, + ShorthandPropertyAssignment = 292, + SpreadAssignment = 293, + EnumMember = 294, + UnparsedPrologue = 295, + UnparsedPrepend = 296, + UnparsedText = 297, + UnparsedInternalText = 298, + UnparsedSyntheticReference = 299, + SourceFile = 300, + Bundle = 301, + UnparsedSource = 302, + InputFiles = 303, + JSDocTypeExpression = 304, + JSDocNameReference = 305, + JSDocMemberName = 306, + JSDocAllType = 307, + JSDocUnknownType = 308, + JSDocNullableType = 309, + JSDocNonNullableType = 310, + JSDocOptionalType = 311, + JSDocFunctionType = 312, + JSDocVariadicType = 313, + JSDocNamepathType = 314, + JSDocComment = 315, + JSDocText = 316, + JSDocTypeLiteral = 317, + JSDocSignature = 318, + JSDocLink = 319, + JSDocLinkCode = 320, + JSDocLinkPlain = 321, + JSDocTag = 322, + JSDocAugmentsTag = 323, + JSDocImplementsTag = 324, + JSDocAuthorTag = 325, + JSDocDeprecatedTag = 326, + JSDocClassTag = 327, + JSDocPublicTag = 328, + JSDocPrivateTag = 329, + JSDocProtectedTag = 330, + JSDocReadonlyTag = 331, + JSDocOverrideTag = 332, + JSDocCallbackTag = 333, + JSDocEnumTag = 334, + JSDocParameterTag = 335, + JSDocReturnTag = 336, + JSDocThisTag = 337, + JSDocTypeTag = 338, + JSDocTemplateTag = 339, + JSDocTypedefTag = 340, + JSDocSeeTag = 341, + JSDocPropertyTag = 342, + SyntaxList = 343, + NotEmittedStatement = 344, + PartiallyEmittedExpression = 345, + CommaListExpression = 346, + MergeDeclarationMarker = 347, + EndOfDeclarationMarker = 348, + SyntheticReferenceExpression = 349, + Count = 350, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -465,8 +466,8 @@ declare namespace ts { LastKeyword = 158, FirstFutureReservedWord = 117, LastFutureReservedWord = 125, - FirstTypeNode = 174, - LastTypeNode = 197, + FirstTypeNode = 175, + LastTypeNode = 198, FirstPunctuation = 18, LastPunctuation = 78, FirstToken = 0, @@ -479,13 +480,13 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 78, - FirstStatement = 234, - LastStatement = 250, + FirstStatement = 235, + LastStatement = 251, FirstNode = 159, - FirstJSDocNode = 303, - LastJSDocNode = 341, - FirstJSDocTagNode = 321, - LastJSDocTagNode = 341, + FirstJSDocNode = 304, + LastJSDocNode = 342, + FirstJSDocTagNode = 322, + LastJSDocTagNode = 342, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -568,7 +569,7 @@ declare namespace ts { } export interface JSDocContainer { } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | EndOfFileToken; + export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | EndOfFileToken; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -850,6 +851,11 @@ declare namespace ts { readonly parent: ObjectTypeDeclaration; readonly type: TypeNode; } + export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { + readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly parent: ClassDeclaration | ClassExpression; + readonly body: Block; + } export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -3292,6 +3298,8 @@ declare namespace ts { updateIndexSignature(node: IndexSignatureDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, parameters: readonly ParameterDeclaration[], type: TypeNode): IndexSignatureDeclaration; createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan; updateTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan; + createClassStaticBlockDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, body: Block): ClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, body: Block): ClassStaticBlockDeclaration; createKeywordTypeNode(kind: TKind): KeywordTypeNode; createTypePredicateNode(assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode | string, type: TypeNode | undefined): TypePredicateNode; updateTypePredicateNode(node: TypePredicateNode, assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode, type: TypeNode | undefined): TypePredicateNode; @@ -4455,6 +4463,7 @@ declare namespace ts { function isPropertyDeclaration(node: Node): node is PropertyDeclaration; function isMethodSignature(node: Node): node is MethodSignature; function isMethodDeclaration(node: Node): node is MethodDeclaration; + function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; function isConstructorDeclaration(node: Node): node is ConstructorDeclaration; function isGetAccessorDeclaration(node: Node): node is GetAccessorDeclaration; function isSetAccessorDeclaration(node: Node): node is SetAccessorDeclaration; @@ -6405,7 +6414,10 @@ declare namespace ts { * interface Y { foo:number; } */ memberVariableElement = "property", - /** class X { constructor() { } } */ + /** + * class X { constructor() { } } + * class X { static { } } + */ constructorImplementationElement = "constructor", /** interface Y { ():number; } */ callSignatureElement = "call", diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index cabab4bf61bfc..c7160064d611e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -273,188 +273,189 @@ declare namespace ts { PropertyDeclaration = 165, MethodSignature = 166, MethodDeclaration = 167, - Constructor = 168, - GetAccessor = 169, - SetAccessor = 170, - CallSignature = 171, - ConstructSignature = 172, - IndexSignature = 173, - TypePredicate = 174, - TypeReference = 175, - FunctionType = 176, - ConstructorType = 177, - TypeQuery = 178, - TypeLiteral = 179, - ArrayType = 180, - TupleType = 181, - OptionalType = 182, - RestType = 183, - UnionType = 184, - IntersectionType = 185, - ConditionalType = 186, - InferType = 187, - ParenthesizedType = 188, - ThisType = 189, - TypeOperator = 190, - IndexedAccessType = 191, - MappedType = 192, - LiteralType = 193, - NamedTupleMember = 194, - TemplateLiteralType = 195, - TemplateLiteralTypeSpan = 196, - ImportType = 197, - ObjectBindingPattern = 198, - ArrayBindingPattern = 199, - BindingElement = 200, - ArrayLiteralExpression = 201, - ObjectLiteralExpression = 202, - PropertyAccessExpression = 203, - ElementAccessExpression = 204, - CallExpression = 205, - NewExpression = 206, - TaggedTemplateExpression = 207, - TypeAssertionExpression = 208, - ParenthesizedExpression = 209, - FunctionExpression = 210, - ArrowFunction = 211, - DeleteExpression = 212, - TypeOfExpression = 213, - VoidExpression = 214, - AwaitExpression = 215, - PrefixUnaryExpression = 216, - PostfixUnaryExpression = 217, - BinaryExpression = 218, - ConditionalExpression = 219, - TemplateExpression = 220, - YieldExpression = 221, - SpreadElement = 222, - ClassExpression = 223, - OmittedExpression = 224, - ExpressionWithTypeArguments = 225, - AsExpression = 226, - NonNullExpression = 227, - MetaProperty = 228, - SyntheticExpression = 229, - TemplateSpan = 230, - SemicolonClassElement = 231, - Block = 232, - EmptyStatement = 233, - VariableStatement = 234, - ExpressionStatement = 235, - IfStatement = 236, - DoStatement = 237, - WhileStatement = 238, - ForStatement = 239, - ForInStatement = 240, - ForOfStatement = 241, - ContinueStatement = 242, - BreakStatement = 243, - ReturnStatement = 244, - WithStatement = 245, - SwitchStatement = 246, - LabeledStatement = 247, - ThrowStatement = 248, - TryStatement = 249, - DebuggerStatement = 250, - VariableDeclaration = 251, - VariableDeclarationList = 252, - FunctionDeclaration = 253, - ClassDeclaration = 254, - InterfaceDeclaration = 255, - TypeAliasDeclaration = 256, - EnumDeclaration = 257, - ModuleDeclaration = 258, - ModuleBlock = 259, - CaseBlock = 260, - NamespaceExportDeclaration = 261, - ImportEqualsDeclaration = 262, - ImportDeclaration = 263, - ImportClause = 264, - NamespaceImport = 265, - NamedImports = 266, - ImportSpecifier = 267, - ExportAssignment = 268, - ExportDeclaration = 269, - NamedExports = 270, - NamespaceExport = 271, - ExportSpecifier = 272, - MissingDeclaration = 273, - ExternalModuleReference = 274, - JsxElement = 275, - JsxSelfClosingElement = 276, - JsxOpeningElement = 277, - JsxClosingElement = 278, - JsxFragment = 279, - JsxOpeningFragment = 280, - JsxClosingFragment = 281, - JsxAttribute = 282, - JsxAttributes = 283, - JsxSpreadAttribute = 284, - JsxExpression = 285, - CaseClause = 286, - DefaultClause = 287, - HeritageClause = 288, - CatchClause = 289, - PropertyAssignment = 290, - ShorthandPropertyAssignment = 291, - SpreadAssignment = 292, - EnumMember = 293, - UnparsedPrologue = 294, - UnparsedPrepend = 295, - UnparsedText = 296, - UnparsedInternalText = 297, - UnparsedSyntheticReference = 298, - SourceFile = 299, - Bundle = 300, - UnparsedSource = 301, - InputFiles = 302, - JSDocTypeExpression = 303, - JSDocNameReference = 304, - JSDocMemberName = 305, - JSDocAllType = 306, - JSDocUnknownType = 307, - JSDocNullableType = 308, - JSDocNonNullableType = 309, - JSDocOptionalType = 310, - JSDocFunctionType = 311, - JSDocVariadicType = 312, - JSDocNamepathType = 313, - JSDocComment = 314, - JSDocText = 315, - JSDocTypeLiteral = 316, - JSDocSignature = 317, - JSDocLink = 318, - JSDocLinkCode = 319, - JSDocLinkPlain = 320, - JSDocTag = 321, - JSDocAugmentsTag = 322, - JSDocImplementsTag = 323, - JSDocAuthorTag = 324, - JSDocDeprecatedTag = 325, - JSDocClassTag = 326, - JSDocPublicTag = 327, - JSDocPrivateTag = 328, - JSDocProtectedTag = 329, - JSDocReadonlyTag = 330, - JSDocOverrideTag = 331, - JSDocCallbackTag = 332, - JSDocEnumTag = 333, - JSDocParameterTag = 334, - JSDocReturnTag = 335, - JSDocThisTag = 336, - JSDocTypeTag = 337, - JSDocTemplateTag = 338, - JSDocTypedefTag = 339, - JSDocSeeTag = 340, - JSDocPropertyTag = 341, - SyntaxList = 342, - NotEmittedStatement = 343, - PartiallyEmittedExpression = 344, - CommaListExpression = 345, - MergeDeclarationMarker = 346, - EndOfDeclarationMarker = 347, - SyntheticReferenceExpression = 348, - Count = 349, + ClassStaticBlockDeclaration = 168, + Constructor = 169, + GetAccessor = 170, + SetAccessor = 171, + CallSignature = 172, + ConstructSignature = 173, + IndexSignature = 174, + TypePredicate = 175, + TypeReference = 176, + FunctionType = 177, + ConstructorType = 178, + TypeQuery = 179, + TypeLiteral = 180, + ArrayType = 181, + TupleType = 182, + OptionalType = 183, + RestType = 184, + UnionType = 185, + IntersectionType = 186, + ConditionalType = 187, + InferType = 188, + ParenthesizedType = 189, + ThisType = 190, + TypeOperator = 191, + IndexedAccessType = 192, + MappedType = 193, + LiteralType = 194, + NamedTupleMember = 195, + TemplateLiteralType = 196, + TemplateLiteralTypeSpan = 197, + ImportType = 198, + ObjectBindingPattern = 199, + ArrayBindingPattern = 200, + BindingElement = 201, + ArrayLiteralExpression = 202, + ObjectLiteralExpression = 203, + PropertyAccessExpression = 204, + ElementAccessExpression = 205, + CallExpression = 206, + NewExpression = 207, + TaggedTemplateExpression = 208, + TypeAssertionExpression = 209, + ParenthesizedExpression = 210, + FunctionExpression = 211, + ArrowFunction = 212, + DeleteExpression = 213, + TypeOfExpression = 214, + VoidExpression = 215, + AwaitExpression = 216, + PrefixUnaryExpression = 217, + PostfixUnaryExpression = 218, + BinaryExpression = 219, + ConditionalExpression = 220, + TemplateExpression = 221, + YieldExpression = 222, + SpreadElement = 223, + ClassExpression = 224, + OmittedExpression = 225, + ExpressionWithTypeArguments = 226, + AsExpression = 227, + NonNullExpression = 228, + MetaProperty = 229, + SyntheticExpression = 230, + TemplateSpan = 231, + SemicolonClassElement = 232, + Block = 233, + EmptyStatement = 234, + VariableStatement = 235, + ExpressionStatement = 236, + IfStatement = 237, + DoStatement = 238, + WhileStatement = 239, + ForStatement = 240, + ForInStatement = 241, + ForOfStatement = 242, + ContinueStatement = 243, + BreakStatement = 244, + ReturnStatement = 245, + WithStatement = 246, + SwitchStatement = 247, + LabeledStatement = 248, + ThrowStatement = 249, + TryStatement = 250, + DebuggerStatement = 251, + VariableDeclaration = 252, + VariableDeclarationList = 253, + FunctionDeclaration = 254, + ClassDeclaration = 255, + InterfaceDeclaration = 256, + TypeAliasDeclaration = 257, + EnumDeclaration = 258, + ModuleDeclaration = 259, + ModuleBlock = 260, + CaseBlock = 261, + NamespaceExportDeclaration = 262, + ImportEqualsDeclaration = 263, + ImportDeclaration = 264, + ImportClause = 265, + NamespaceImport = 266, + NamedImports = 267, + ImportSpecifier = 268, + ExportAssignment = 269, + ExportDeclaration = 270, + NamedExports = 271, + NamespaceExport = 272, + ExportSpecifier = 273, + MissingDeclaration = 274, + ExternalModuleReference = 275, + JsxElement = 276, + JsxSelfClosingElement = 277, + JsxOpeningElement = 278, + JsxClosingElement = 279, + JsxFragment = 280, + JsxOpeningFragment = 281, + JsxClosingFragment = 282, + JsxAttribute = 283, + JsxAttributes = 284, + JsxSpreadAttribute = 285, + JsxExpression = 286, + CaseClause = 287, + DefaultClause = 288, + HeritageClause = 289, + CatchClause = 290, + PropertyAssignment = 291, + ShorthandPropertyAssignment = 292, + SpreadAssignment = 293, + EnumMember = 294, + UnparsedPrologue = 295, + UnparsedPrepend = 296, + UnparsedText = 297, + UnparsedInternalText = 298, + UnparsedSyntheticReference = 299, + SourceFile = 300, + Bundle = 301, + UnparsedSource = 302, + InputFiles = 303, + JSDocTypeExpression = 304, + JSDocNameReference = 305, + JSDocMemberName = 306, + JSDocAllType = 307, + JSDocUnknownType = 308, + JSDocNullableType = 309, + JSDocNonNullableType = 310, + JSDocOptionalType = 311, + JSDocFunctionType = 312, + JSDocVariadicType = 313, + JSDocNamepathType = 314, + JSDocComment = 315, + JSDocText = 316, + JSDocTypeLiteral = 317, + JSDocSignature = 318, + JSDocLink = 319, + JSDocLinkCode = 320, + JSDocLinkPlain = 321, + JSDocTag = 322, + JSDocAugmentsTag = 323, + JSDocImplementsTag = 324, + JSDocAuthorTag = 325, + JSDocDeprecatedTag = 326, + JSDocClassTag = 327, + JSDocPublicTag = 328, + JSDocPrivateTag = 329, + JSDocProtectedTag = 330, + JSDocReadonlyTag = 331, + JSDocOverrideTag = 332, + JSDocCallbackTag = 333, + JSDocEnumTag = 334, + JSDocParameterTag = 335, + JSDocReturnTag = 336, + JSDocThisTag = 337, + JSDocTypeTag = 338, + JSDocTemplateTag = 339, + JSDocTypedefTag = 340, + JSDocSeeTag = 341, + JSDocPropertyTag = 342, + SyntaxList = 343, + NotEmittedStatement = 344, + PartiallyEmittedExpression = 345, + CommaListExpression = 346, + MergeDeclarationMarker = 347, + EndOfDeclarationMarker = 348, + SyntheticReferenceExpression = 349, + Count = 350, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -465,8 +466,8 @@ declare namespace ts { LastKeyword = 158, FirstFutureReservedWord = 117, LastFutureReservedWord = 125, - FirstTypeNode = 174, - LastTypeNode = 197, + FirstTypeNode = 175, + LastTypeNode = 198, FirstPunctuation = 18, LastPunctuation = 78, FirstToken = 0, @@ -479,13 +480,13 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 78, - FirstStatement = 234, - LastStatement = 250, + FirstStatement = 235, + LastStatement = 251, FirstNode = 159, - FirstJSDocNode = 303, - LastJSDocNode = 341, - FirstJSDocTagNode = 321, - LastJSDocTagNode = 341, + FirstJSDocNode = 304, + LastJSDocNode = 342, + FirstJSDocTagNode = 322, + LastJSDocTagNode = 342, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -568,7 +569,7 @@ declare namespace ts { } export interface JSDocContainer { } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | EndOfFileToken; + export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | EndOfFileToken; export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType; export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement; export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute; @@ -850,6 +851,11 @@ declare namespace ts { readonly parent: ObjectTypeDeclaration; readonly type: TypeNode; } + export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { + readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly parent: ClassDeclaration | ClassExpression; + readonly body: Block; + } export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -3292,6 +3298,8 @@ declare namespace ts { updateIndexSignature(node: IndexSignatureDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, parameters: readonly ParameterDeclaration[], type: TypeNode): IndexSignatureDeclaration; createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan; updateTemplateLiteralTypeSpan(node: TemplateLiteralTypeSpan, type: TypeNode, literal: TemplateMiddle | TemplateTail): TemplateLiteralTypeSpan; + createClassStaticBlockDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, body: Block): ClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, body: Block): ClassStaticBlockDeclaration; createKeywordTypeNode(kind: TKind): KeywordTypeNode; createTypePredicateNode(assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode | string, type: TypeNode | undefined): TypePredicateNode; updateTypePredicateNode(node: TypePredicateNode, assertsModifier: AssertsKeyword | undefined, parameterName: Identifier | ThisTypeNode, type: TypeNode | undefined): TypePredicateNode; @@ -4455,6 +4463,7 @@ declare namespace ts { function isPropertyDeclaration(node: Node): node is PropertyDeclaration; function isMethodSignature(node: Node): node is MethodSignature; function isMethodDeclaration(node: Node): node is MethodDeclaration; + function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; function isConstructorDeclaration(node: Node): node is ConstructorDeclaration; function isGetAccessorDeclaration(node: Node): node is GetAccessorDeclaration; function isSetAccessorDeclaration(node: Node): node is SetAccessorDeclaration; @@ -6405,7 +6414,10 @@ declare namespace ts { * interface Y { foo:number; } */ memberVariableElement = "property", - /** class X { constructor() { } } */ + /** + * class X { constructor() { } } + * class X { static { } } + */ constructorImplementationElement = "constructor", /** interface Y { ():number; } */ callSignatureElement = "call", diff --git a/tests/baselines/reference/callHierarchyClassStaticBlock.callHierarchy.txt b/tests/baselines/reference/callHierarchyClassStaticBlock.callHierarchy.txt new file mode 100644 index 0000000000000..fbf3658c9823b --- /dev/null +++ b/tests/baselines/reference/callHierarchyClassStaticBlock.callHierarchy.txt @@ -0,0 +1,139 @@ +╭ name: bar +├ kind: function +├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock.ts +├ span: +│ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:7:9-11:10 +│ │ 7: function bar() { +│ │ ^^^^^^^^^^^^^^^^ +│ │ 8: baz(); +│ │ ^^^^^^^^^^^^^^^^^^ +│ │ 9: quxx(); +│ │ ^^^^^^^^^^^^^^^^^^^ +│ │ 10: baz(); +│ │ ^^^^^^^^^^^^^^^^^^ +│ │ 11: } +│ │ ^^^^^^^^^ +│ ╰ +├ selectionSpan: +│ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:7:18-7:21 +│ │ 7: function bar() { +│ │ ^^^ +│ ╰ +├ incoming: +│ ╭ from: +│ │ ╭ name: foo +│ │ ├ kind: function +│ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock.ts +│ │ ├ span: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:3:9-5:10 +│ │ │ │ 3: function foo() { +│ │ │ │ ^^^^^^^^^^^^^^^^ +│ │ │ │ 4: bar(); +│ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ 5: } +│ │ │ │ ^^^^^^^^^ +│ │ │ ╰ +│ │ ├ selectionSpan: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:3:18-3:21 +│ │ │ │ 3: function foo() { +│ │ │ │ ^^^ +│ │ │ ╰ +│ │ ├ incoming: +│ │ │ ╭ from: +│ │ │ │ ╭ name: static {} +│ │ │ │ ├ kind: constructor +│ │ │ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock.ts +│ │ │ │ ├ span: +│ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:2:5-14:6 +│ │ │ │ │ │ 2: static { +│ │ │ │ │ │ ^^^^^^^^ +│ │ │ │ │ │ 3: function foo() { +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 4: bar(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 5: } +│ │ │ │ │ │ ^^^^^^^^^ +│ │ │ │ │ │ 6: +│ │ │ │ │ │ ^ +│ │ │ │ │ │ 7: function bar() { +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 8: baz(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 9: quxx(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 10: baz(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 11: } +│ │ │ │ │ │ ^^^^^^^^^ +│ │ │ │ │ │ 12: +│ │ │ │ │ │ ^ +│ │ │ │ │ │ 13: foo(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^ +│ │ │ │ │ │ 14: } +│ │ │ │ │ │ ^^^^^ +│ │ │ │ │ ╰ +│ │ │ │ ├ selectionSpan: +│ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:2:5-2:11 +│ │ │ │ │ │ 2: static { +│ │ │ │ │ │ ^^^^^^ +│ │ │ │ │ ╰ +│ │ │ │ ╰ incoming: none +│ │ │ ├ fromSpans: +│ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:13:9-13:12 +│ │ │ │ │ 13: foo(); +│ │ │ │ │ ^^^ +│ │ ╰ ╰ ╰ +│ ├ fromSpans: +│ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:4:13-4:16 +│ │ │ 4: bar(); +│ │ │ ^^^ +│ ╰ ╰ +├ outgoing: +│ ╭ to: +│ │ ╭ name: baz +│ │ ├ kind: function +│ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock.ts +│ │ ├ span: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:17:1-18:2 +│ │ │ │ 17: function baz() { +│ │ │ │ ^^^^^^^^^^^^^^^^ +│ │ │ │ 18: } +│ │ │ │ ^ +│ │ │ ╰ +│ │ ├ selectionSpan: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:17:10-17:13 +│ │ │ │ 17: function baz() { +│ │ │ │ ^^^ +│ │ │ ╰ +│ │ ╰ outgoing: none +│ ├ fromSpans: +│ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:8:13-8:16 +│ │ │ 8: baz(); +│ │ │ ^^^ +│ │ ╰ +│ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:10:13-10:16 +│ │ │ 10: baz(); +│ │ │ ^^^ +│ ╰ ╰ +│ ╭ to: +│ │ ╭ name: quxx +│ │ ├ kind: function +│ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock.ts +│ │ ├ span: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:20:1-21:2 +│ │ │ │ 20: function quxx() { +│ │ │ │ ^^^^^^^^^^^^^^^^^ +│ │ │ │ 21: } +│ │ │ │ ^ +│ │ │ ╰ +│ │ ├ selectionSpan: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:20:10-20:14 +│ │ │ │ 20: function quxx() { +│ │ │ │ ^^^^ +│ │ │ ╰ +│ │ ╰ outgoing: none +│ ├ fromSpans: +│ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock.ts:9:13-9:17 +│ │ │ 9: quxx(); +│ │ │ ^^^^ +╰ ╰ ╰ diff --git a/tests/baselines/reference/callHierarchyClassStaticBlock2.callHierarchy.txt b/tests/baselines/reference/callHierarchyClassStaticBlock2.callHierarchy.txt new file mode 100644 index 0000000000000..beaf564c2d5e7 --- /dev/null +++ b/tests/baselines/reference/callHierarchyClassStaticBlock2.callHierarchy.txt @@ -0,0 +1,139 @@ +╭ name: static {} +├ kind: constructor +├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts +├ span: +│ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:2:5-14:6 +│ │ 2: static { +│ │ ^^^^^^^^ +│ │ 3: function foo() { +│ │ ^^^^^^^^^^^^^^^^^^^^^^^^ +│ │ 4: bar(); +│ │ ^^^^^^^^^^^^^^^^^^ +│ │ 5: } +│ │ ^^^^^^^^^ +│ │ 6: +│ │ ^ +│ │ 7: function bar() { +│ │ ^^^^^^^^^^^^^^^^^^^^^^^^ +│ │ 8: baz(); +│ │ ^^^^^^^^^^^^^^^^^^ +│ │ 9: quxx(); +│ │ ^^^^^^^^^^^^^^^^^^^ +│ │ 10: baz(); +│ │ ^^^^^^^^^^^^^^^^^^ +│ │ 11: } +│ │ ^^^^^^^^^ +│ │ 12: +│ │ ^ +│ │ 13: foo(); +│ │ ^^^^^^^^^^^^^^ +│ │ 14: } +│ │ ^^^^^ +│ ╰ +├ selectionSpan: +│ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:2:5-2:11 +│ │ 2: static { +│ │ ^^^^^^ +│ ╰ +├ incoming: none +├ outgoing: +│ ╭ to: +│ │ ╭ name: foo +│ │ ├ kind: function +│ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts +│ │ ├ span: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:3:9-5:10 +│ │ │ │ 3: function foo() { +│ │ │ │ ^^^^^^^^^^^^^^^^ +│ │ │ │ 4: bar(); +│ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ 5: } +│ │ │ │ ^^^^^^^^^ +│ │ │ ╰ +│ │ ├ selectionSpan: +│ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:3:18-3:21 +│ │ │ │ 3: function foo() { +│ │ │ │ ^^^ +│ │ │ ╰ +│ │ ├ outgoing: +│ │ │ ╭ to: +│ │ │ │ ╭ name: bar +│ │ │ │ ├ kind: function +│ │ │ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts +│ │ │ │ ├ span: +│ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:7:9-11:10 +│ │ │ │ │ │ 7: function bar() { +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 8: baz(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 9: quxx(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 10: baz(); +│ │ │ │ │ │ ^^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ 11: } +│ │ │ │ │ │ ^^^^^^^^^ +│ │ │ │ │ ╰ +│ │ │ │ ├ selectionSpan: +│ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:7:18-7:21 +│ │ │ │ │ │ 7: function bar() { +│ │ │ │ │ │ ^^^ +│ │ │ │ │ ╰ +│ │ │ │ ├ outgoing: +│ │ │ │ │ ╭ to: +│ │ │ │ │ │ ╭ name: baz +│ │ │ │ │ │ ├ kind: function +│ │ │ │ │ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts +│ │ │ │ │ │ ├ span: +│ │ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:17:1-18:2 +│ │ │ │ │ │ │ │ 17: function baz() { +│ │ │ │ │ │ │ │ ^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ │ │ 18: } +│ │ │ │ │ │ │ │ ^ +│ │ │ │ │ │ │ ╰ +│ │ │ │ │ │ ├ selectionSpan: +│ │ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:17:10-17:13 +│ │ │ │ │ │ │ │ 17: function baz() { +│ │ │ │ │ │ │ │ ^^^ +│ │ │ │ │ │ │ ╰ +│ │ │ │ │ │ ╰ outgoing: none +│ │ │ │ │ ├ fromSpans: +│ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:8:13-8:16 +│ │ │ │ │ │ │ 8: baz(); +│ │ │ │ │ │ │ ^^^ +│ │ │ │ │ │ ╰ +│ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:10:13-10:16 +│ │ │ │ │ │ │ 10: baz(); +│ │ │ │ │ │ │ ^^^ +│ │ │ │ │ ╰ ╰ +│ │ │ │ │ ╭ to: +│ │ │ │ │ │ ╭ name: quxx +│ │ │ │ │ │ ├ kind: function +│ │ │ │ │ │ ├ file: /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts +│ │ │ │ │ │ ├ span: +│ │ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:20:1-21:2 +│ │ │ │ │ │ │ │ 20: function quxx() { +│ │ │ │ │ │ │ │ ^^^^^^^^^^^^^^^^^ +│ │ │ │ │ │ │ │ 21: } +│ │ │ │ │ │ │ │ ^ +│ │ │ │ │ │ │ ╰ +│ │ │ │ │ │ ├ selectionSpan: +│ │ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:20:10-20:14 +│ │ │ │ │ │ │ │ 20: function quxx() { +│ │ │ │ │ │ │ │ ^^^^ +│ │ │ │ │ │ │ ╰ +│ │ │ │ │ │ ╰ outgoing: none +│ │ │ │ │ ├ fromSpans: +│ │ │ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:9:13-9:17 +│ │ │ │ │ │ │ 9: quxx(); +│ │ │ │ │ │ │ ^^^^ +│ │ │ │ ╰ ╰ ╰ +│ │ │ ├ fromSpans: +│ │ │ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:4:13-4:16 +│ │ │ │ │ 4: bar(); +│ │ │ │ │ ^^^ +│ │ ╰ ╰ ╰ +│ ├ fromSpans: +│ │ ╭ /tests/cases/fourslash/callHierarchyClassStaticBlock2.ts:13:9-13:12 +│ │ │ 13: foo(); +│ │ │ ^^^ +╰ ╰ ╰ diff --git a/tests/baselines/reference/classStaticBlock1(target=es2015).js b/tests/baselines/reference/classStaticBlock1(target=es2015).js new file mode 100644 index 0000000000000..2129bc16bf1cc --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es2015).js @@ -0,0 +1,20 @@ +//// [classStaticBlock1.ts] +const a = 2; + +class C { + static { + const a = 1; + + a; + } +} + + +//// [classStaticBlock1.js] +const a = 2; +class C { +} +(() => { + const a = 1; + a; +})(); diff --git a/tests/baselines/reference/classStaticBlock1(target=es2015).symbols b/tests/baselines/reference/classStaticBlock1(target=es2015).symbols new file mode 100644 index 0000000000000..e4aa99e0d68d5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es2015).symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts === +const a = 2; +>a : Symbol(a, Decl(classStaticBlock1.ts, 0, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock1.ts, 0, 12)) + + static { + const a = 1; +>a : Symbol(a, Decl(classStaticBlock1.ts, 4, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock1.ts, 4, 13)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock1(target=es2015).types b/tests/baselines/reference/classStaticBlock1(target=es2015).types new file mode 100644 index 0000000000000..a0fd3b4d6480a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es2015).types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts === +const a = 2; +>a : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 1; +>a : 1 +>1 : 1 + + a; +>a : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock1(target=es5).js b/tests/baselines/reference/classStaticBlock1(target=es5).js new file mode 100644 index 0000000000000..9bd8a1a9d7bff --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es5).js @@ -0,0 +1,23 @@ +//// [classStaticBlock1.ts] +const a = 2; + +class C { + static { + const a = 1; + + a; + } +} + + +//// [classStaticBlock1.js] +var a = 2; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +(function () { + var a = 1; + a; +})(); diff --git a/tests/baselines/reference/classStaticBlock1(target=es5).symbols b/tests/baselines/reference/classStaticBlock1(target=es5).symbols new file mode 100644 index 0000000000000..e4aa99e0d68d5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es5).symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts === +const a = 2; +>a : Symbol(a, Decl(classStaticBlock1.ts, 0, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock1.ts, 0, 12)) + + static { + const a = 1; +>a : Symbol(a, Decl(classStaticBlock1.ts, 4, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock1.ts, 4, 13)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock1(target=es5).types b/tests/baselines/reference/classStaticBlock1(target=es5).types new file mode 100644 index 0000000000000..a0fd3b4d6480a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es5).types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts === +const a = 2; +>a : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 1; +>a : 1 +>1 : 1 + + a; +>a : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock1(target=esnext).js b/tests/baselines/reference/classStaticBlock1(target=esnext).js new file mode 100644 index 0000000000000..c7180cdabd6f8 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=esnext).js @@ -0,0 +1,20 @@ +//// [classStaticBlock1.ts] +const a = 2; + +class C { + static { + const a = 1; + + a; + } +} + + +//// [classStaticBlock1.js] +const a = 2; +class C { + static { + const a = 1; + a; + } +} diff --git a/tests/baselines/reference/classStaticBlock1(target=esnext).symbols b/tests/baselines/reference/classStaticBlock1(target=esnext).symbols new file mode 100644 index 0000000000000..e4aa99e0d68d5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=esnext).symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts === +const a = 2; +>a : Symbol(a, Decl(classStaticBlock1.ts, 0, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock1.ts, 0, 12)) + + static { + const a = 1; +>a : Symbol(a, Decl(classStaticBlock1.ts, 4, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock1.ts, 4, 13)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock1(target=esnext).types b/tests/baselines/reference/classStaticBlock1(target=esnext).types new file mode 100644 index 0000000000000..a0fd3b4d6480a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=esnext).types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts === +const a = 2; +>a : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 1; +>a : 1 +>1 : 1 + + a; +>a : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock10(target=es2015).js b/tests/baselines/reference/classStaticBlock10(target=es2015).js new file mode 100644 index 0000000000000..dcf0be3960cb6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es2015).js @@ -0,0 +1,54 @@ +//// [classStaticBlock10.ts] +var a1 = 1; +var a2 = 1; +const b1 = 2; +const b2 = 2; + +function f () { + var a1 = 11; + const b1 = 22; + + class C1 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } + } +} + +class C2 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } +} + +//// [classStaticBlock10.js] +var a1 = 1; +var a2 = 1; +const b1 = 2; +const b2 = 2; +function f() { + var a1 = 11; + const b1 = 22; + class C1 { + } + (() => { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + })(); +} +class C2 { +} +(() => { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; +})(); diff --git a/tests/baselines/reference/classStaticBlock10(target=es2015).symbols b/tests/baselines/reference/classStaticBlock10(target=es2015).symbols new file mode 100644 index 0000000000000..12d2d16b0784c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es2015).symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts === +var a1 = 1; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 0, 3)) + +var a2 = 1; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 1, 3)) + +const b1 = 2; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 2, 5)) + +const b2 = 2; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 3, 5)) + +function f () { +>f : Symbol(f, Decl(classStaticBlock10.ts, 3, 13)) + + var a1 = 11; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 6, 7)) + + const b1 = 22; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 7, 9)) + + class C1 { +>C1 : Symbol(C1, Decl(classStaticBlock10.ts, 7, 18)) + + static { + var a1 = 111; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 11, 15)) + + var a2 = 111; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 12, 15)) + + const b1 = 222; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 13, 17)) + + const b2 = 222; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 14, 17)) + } + } +} + +class C2 { +>C2 : Symbol(C2, Decl(classStaticBlock10.ts, 17, 1)) + + static { + var a1 = 111; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 21, 11)) + + var a2 = 111; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 22, 11)) + + const b1 = 222; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 23, 13)) + + const b2 = 222; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 24, 13)) + } +} diff --git a/tests/baselines/reference/classStaticBlock10(target=es2015).types b/tests/baselines/reference/classStaticBlock10(target=es2015).types new file mode 100644 index 0000000000000..dbbf3ebd6b0a4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es2015).types @@ -0,0 +1,72 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts === +var a1 = 1; +>a1 : number +>1 : 1 + +var a2 = 1; +>a2 : number +>1 : 1 + +const b1 = 2; +>b1 : 2 +>2 : 2 + +const b2 = 2; +>b2 : 2 +>2 : 2 + +function f () { +>f : () => void + + var a1 = 11; +>a1 : number +>11 : 11 + + const b1 = 22; +>b1 : 22 +>22 : 22 + + class C1 { +>C1 : C1 + + static { + var a1 = 111; +>a1 : number +>111 : 111 + + var a2 = 111; +>a2 : number +>111 : 111 + + const b1 = 222; +>b1 : 222 +>222 : 222 + + const b2 = 222; +>b2 : 222 +>222 : 222 + } + } +} + +class C2 { +>C2 : C2 + + static { + var a1 = 111; +>a1 : number +>111 : 111 + + var a2 = 111; +>a2 : number +>111 : 111 + + const b1 = 222; +>b1 : 222 +>222 : 222 + + const b2 = 222; +>b2 : 222 +>222 : 222 + } +} diff --git a/tests/baselines/reference/classStaticBlock10(target=es5).js b/tests/baselines/reference/classStaticBlock10(target=es5).js new file mode 100644 index 0000000000000..e390c2eb62da5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es5).js @@ -0,0 +1,60 @@ +//// [classStaticBlock10.ts] +var a1 = 1; +var a2 = 1; +const b1 = 2; +const b2 = 2; + +function f () { + var a1 = 11; + const b1 = 22; + + class C1 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } + } +} + +class C2 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } +} + +//// [classStaticBlock10.js] +var a1 = 1; +var a2 = 1; +var b1 = 2; +var b2 = 2; +function f() { + var a1 = 11; + var b1 = 22; + var C1 = /** @class */ (function () { + function C1() { + } + return C1; + }()); + (function () { + var a1 = 111; + var a2 = 111; + var b1 = 222; + var b2 = 222; + })(); +} +var C2 = /** @class */ (function () { + function C2() { + } + return C2; +}()); +(function () { + var a1 = 111; + var a2 = 111; + var b1 = 222; + var b2 = 222; +})(); diff --git a/tests/baselines/reference/classStaticBlock10(target=es5).symbols b/tests/baselines/reference/classStaticBlock10(target=es5).symbols new file mode 100644 index 0000000000000..12d2d16b0784c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es5).symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts === +var a1 = 1; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 0, 3)) + +var a2 = 1; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 1, 3)) + +const b1 = 2; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 2, 5)) + +const b2 = 2; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 3, 5)) + +function f () { +>f : Symbol(f, Decl(classStaticBlock10.ts, 3, 13)) + + var a1 = 11; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 6, 7)) + + const b1 = 22; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 7, 9)) + + class C1 { +>C1 : Symbol(C1, Decl(classStaticBlock10.ts, 7, 18)) + + static { + var a1 = 111; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 11, 15)) + + var a2 = 111; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 12, 15)) + + const b1 = 222; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 13, 17)) + + const b2 = 222; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 14, 17)) + } + } +} + +class C2 { +>C2 : Symbol(C2, Decl(classStaticBlock10.ts, 17, 1)) + + static { + var a1 = 111; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 21, 11)) + + var a2 = 111; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 22, 11)) + + const b1 = 222; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 23, 13)) + + const b2 = 222; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 24, 13)) + } +} diff --git a/tests/baselines/reference/classStaticBlock10(target=es5).types b/tests/baselines/reference/classStaticBlock10(target=es5).types new file mode 100644 index 0000000000000..dbbf3ebd6b0a4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es5).types @@ -0,0 +1,72 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts === +var a1 = 1; +>a1 : number +>1 : 1 + +var a2 = 1; +>a2 : number +>1 : 1 + +const b1 = 2; +>b1 : 2 +>2 : 2 + +const b2 = 2; +>b2 : 2 +>2 : 2 + +function f () { +>f : () => void + + var a1 = 11; +>a1 : number +>11 : 11 + + const b1 = 22; +>b1 : 22 +>22 : 22 + + class C1 { +>C1 : C1 + + static { + var a1 = 111; +>a1 : number +>111 : 111 + + var a2 = 111; +>a2 : number +>111 : 111 + + const b1 = 222; +>b1 : 222 +>222 : 222 + + const b2 = 222; +>b2 : 222 +>222 : 222 + } + } +} + +class C2 { +>C2 : C2 + + static { + var a1 = 111; +>a1 : number +>111 : 111 + + var a2 = 111; +>a2 : number +>111 : 111 + + const b1 = 222; +>b1 : 222 +>222 : 222 + + const b2 = 222; +>b2 : 222 +>222 : 222 + } +} diff --git a/tests/baselines/reference/classStaticBlock10(target=esnext).js b/tests/baselines/reference/classStaticBlock10(target=esnext).js new file mode 100644 index 0000000000000..6593ae74ffed9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=esnext).js @@ -0,0 +1,54 @@ +//// [classStaticBlock10.ts] +var a1 = 1; +var a2 = 1; +const b1 = 2; +const b2 = 2; + +function f () { + var a1 = 11; + const b1 = 22; + + class C1 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } + } +} + +class C2 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } +} + +//// [classStaticBlock10.js] +var a1 = 1; +var a2 = 1; +const b1 = 2; +const b2 = 2; +function f() { + var a1 = 11; + const b1 = 22; + class C1 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } + } +} +class C2 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } +} diff --git a/tests/baselines/reference/classStaticBlock10(target=esnext).symbols b/tests/baselines/reference/classStaticBlock10(target=esnext).symbols new file mode 100644 index 0000000000000..12d2d16b0784c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=esnext).symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts === +var a1 = 1; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 0, 3)) + +var a2 = 1; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 1, 3)) + +const b1 = 2; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 2, 5)) + +const b2 = 2; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 3, 5)) + +function f () { +>f : Symbol(f, Decl(classStaticBlock10.ts, 3, 13)) + + var a1 = 11; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 6, 7)) + + const b1 = 22; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 7, 9)) + + class C1 { +>C1 : Symbol(C1, Decl(classStaticBlock10.ts, 7, 18)) + + static { + var a1 = 111; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 11, 15)) + + var a2 = 111; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 12, 15)) + + const b1 = 222; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 13, 17)) + + const b2 = 222; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 14, 17)) + } + } +} + +class C2 { +>C2 : Symbol(C2, Decl(classStaticBlock10.ts, 17, 1)) + + static { + var a1 = 111; +>a1 : Symbol(a1, Decl(classStaticBlock10.ts, 21, 11)) + + var a2 = 111; +>a2 : Symbol(a2, Decl(classStaticBlock10.ts, 22, 11)) + + const b1 = 222; +>b1 : Symbol(b1, Decl(classStaticBlock10.ts, 23, 13)) + + const b2 = 222; +>b2 : Symbol(b2, Decl(classStaticBlock10.ts, 24, 13)) + } +} diff --git a/tests/baselines/reference/classStaticBlock10(target=esnext).types b/tests/baselines/reference/classStaticBlock10(target=esnext).types new file mode 100644 index 0000000000000..dbbf3ebd6b0a4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=esnext).types @@ -0,0 +1,72 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts === +var a1 = 1; +>a1 : number +>1 : 1 + +var a2 = 1; +>a2 : number +>1 : 1 + +const b1 = 2; +>b1 : 2 +>2 : 2 + +const b2 = 2; +>b2 : 2 +>2 : 2 + +function f () { +>f : () => void + + var a1 = 11; +>a1 : number +>11 : 11 + + const b1 = 22; +>b1 : 22 +>22 : 22 + + class C1 { +>C1 : C1 + + static { + var a1 = 111; +>a1 : number +>111 : 111 + + var a2 = 111; +>a2 : number +>111 : 111 + + const b1 = 222; +>b1 : 222 +>222 : 222 + + const b2 = 222; +>b2 : 222 +>222 : 222 + } + } +} + +class C2 { +>C2 : C2 + + static { + var a1 = 111; +>a1 : number +>111 : 111 + + var a2 = 111; +>a2 : number +>111 : 111 + + const b1 = 222; +>b1 : 222 +>222 : 222 + + const b2 = 222; +>b2 : 222 +>222 : 222 + } +} diff --git a/tests/baselines/reference/classStaticBlock11(target=es2015).js b/tests/baselines/reference/classStaticBlock11(target=es2015).js new file mode 100644 index 0000000000000..7dbf78f783e13 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es2015).js @@ -0,0 +1,40 @@ +//// [classStaticBlock11.ts] +let getX; +class C { + #x = 1 + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + } +} + + +//// [classStaticBlock11.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _C_x; +let getX; +class C { + constructor(x) { + _C_x.set(this, 1); + __classPrivateFieldSet(this, _C_x, x, "f"); + } +} +_C_x = new WeakMap(); +(() => { + // getX has privileged access to #x + getX = (obj) => __classPrivateFieldGet(obj, _C_x, "f"); +})(); diff --git a/tests/baselines/reference/classStaticBlock11(target=es2015).symbols b/tests/baselines/reference/classStaticBlock11(target=es2015).symbols new file mode 100644 index 0000000000000..d61ff7c9e16f9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es2015).symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts === +let getX; +>getX : Symbol(getX, Decl(classStaticBlock11.ts, 0, 3)) + +class C { +>C : Symbol(C, Decl(classStaticBlock11.ts, 0, 9)) + + #x = 1 +>#x : Symbol(C.#x, Decl(classStaticBlock11.ts, 1, 9)) + + constructor(x: number) { +>x : Symbol(x, Decl(classStaticBlock11.ts, 3, 14)) + + this.#x = x; +>this.#x : Symbol(C.#x, Decl(classStaticBlock11.ts, 1, 9)) +>this : Symbol(C, Decl(classStaticBlock11.ts, 0, 9)) +>x : Symbol(x, Decl(classStaticBlock11.ts, 3, 14)) + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; +>getX : Symbol(getX, Decl(classStaticBlock11.ts, 0, 3)) +>obj : Symbol(obj, Decl(classStaticBlock11.ts, 9, 12)) +>C : Symbol(C, Decl(classStaticBlock11.ts, 0, 9)) +>obj.#x : Symbol(C.#x, Decl(classStaticBlock11.ts, 1, 9)) +>obj : Symbol(obj, Decl(classStaticBlock11.ts, 9, 12)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock11(target=es2015).types b/tests/baselines/reference/classStaticBlock11(target=es2015).types new file mode 100644 index 0000000000000..c295e7b93df36 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es2015).types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts === +let getX; +>getX : any + +class C { +>C : C + + #x = 1 +>#x : number +>1 : 1 + + constructor(x: number) { +>x : number + + this.#x = x; +>this.#x = x : number +>this.#x : number +>this : this +>x : number + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; +>getX = (obj: C) => obj.#x : (obj: C) => number +>getX : any +>(obj: C) => obj.#x : (obj: C) => number +>obj : C +>obj.#x : number +>obj : C + } +} + diff --git a/tests/baselines/reference/classStaticBlock11(target=esnext).js b/tests/baselines/reference/classStaticBlock11(target=esnext).js new file mode 100644 index 0000000000000..42228bd5d223d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=esnext).js @@ -0,0 +1,27 @@ +//// [classStaticBlock11.ts] +let getX; +class C { + #x = 1 + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + } +} + + +//// [classStaticBlock11.js] +let getX; +class C { + #x = 1; + constructor(x) { + this.#x = x; + } + static { + // getX has privileged access to #x + getX = (obj) => obj.#x; + } +} diff --git a/tests/baselines/reference/classStaticBlock11(target=esnext).symbols b/tests/baselines/reference/classStaticBlock11(target=esnext).symbols new file mode 100644 index 0000000000000..d61ff7c9e16f9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=esnext).symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts === +let getX; +>getX : Symbol(getX, Decl(classStaticBlock11.ts, 0, 3)) + +class C { +>C : Symbol(C, Decl(classStaticBlock11.ts, 0, 9)) + + #x = 1 +>#x : Symbol(C.#x, Decl(classStaticBlock11.ts, 1, 9)) + + constructor(x: number) { +>x : Symbol(x, Decl(classStaticBlock11.ts, 3, 14)) + + this.#x = x; +>this.#x : Symbol(C.#x, Decl(classStaticBlock11.ts, 1, 9)) +>this : Symbol(C, Decl(classStaticBlock11.ts, 0, 9)) +>x : Symbol(x, Decl(classStaticBlock11.ts, 3, 14)) + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; +>getX : Symbol(getX, Decl(classStaticBlock11.ts, 0, 3)) +>obj : Symbol(obj, Decl(classStaticBlock11.ts, 9, 12)) +>C : Symbol(C, Decl(classStaticBlock11.ts, 0, 9)) +>obj.#x : Symbol(C.#x, Decl(classStaticBlock11.ts, 1, 9)) +>obj : Symbol(obj, Decl(classStaticBlock11.ts, 9, 12)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock11(target=esnext).types b/tests/baselines/reference/classStaticBlock11(target=esnext).types new file mode 100644 index 0000000000000..c295e7b93df36 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=esnext).types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts === +let getX; +>getX : any + +class C { +>C : C + + #x = 1 +>#x : number +>1 : 1 + + constructor(x: number) { +>x : number + + this.#x = x; +>this.#x = x : number +>this.#x : number +>this : this +>x : number + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; +>getX = (obj: C) => obj.#x : (obj: C) => number +>getX : any +>(obj: C) => obj.#x : (obj: C) => number +>obj : C +>obj.#x : number +>obj : C + } +} + diff --git a/tests/baselines/reference/classStaticBlock12.js b/tests/baselines/reference/classStaticBlock12.js new file mode 100644 index 0000000000000..e05449fe4a161 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock12.js @@ -0,0 +1,24 @@ +//// [classStaticBlock12.ts] +class C { + static #x = 1; + + static { + C.#x; + } +} + + +//// [classStaticBlock12.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _C_x; +class C { +} +_a = C; +_C_x = { value: 1 }; +(() => { + __classPrivateFieldGet(C, _a, "f", _C_x); +})(); diff --git a/tests/baselines/reference/classStaticBlock12.symbols b/tests/baselines/reference/classStaticBlock12.symbols new file mode 100644 index 0000000000000..3d11bc442fb76 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock12.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock12.ts, 0, 0)) + + static #x = 1; +>#x : Symbol(C.#x, Decl(classStaticBlock12.ts, 0, 9)) + + static { + C.#x; +>C.#x : Symbol(C.#x, Decl(classStaticBlock12.ts, 0, 9)) +>C : Symbol(C, Decl(classStaticBlock12.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock12.types b/tests/baselines/reference/classStaticBlock12.types new file mode 100644 index 0000000000000..4e441c1829ece --- /dev/null +++ b/tests/baselines/reference/classStaticBlock12.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts === +class C { +>C : C + + static #x = 1; +>#x : number +>1 : 1 + + static { + C.#x; +>C.#x : number +>C : typeof C + } +} + diff --git a/tests/baselines/reference/classStaticBlock13(target=es2015).js b/tests/baselines/reference/classStaticBlock13(target=es2015).js new file mode 100644 index 0000000000000..442dbba65755f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es2015).js @@ -0,0 +1,31 @@ +//// [classStaticBlock13.ts] +class C { + static #x = 123; + + static { + console.log(C.#x) + } + + foo () { + return C.#x; + } +} + + +//// [classStaticBlock13.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _C_x; +class C { + foo() { + return __classPrivateFieldGet(C, _a, "f", _C_x); + } +} +_a = C; +_C_x = { value: 123 }; +(() => { + console.log(__classPrivateFieldGet(C, _a, "f", _C_x)); +})(); diff --git a/tests/baselines/reference/classStaticBlock13(target=es2015).symbols b/tests/baselines/reference/classStaticBlock13(target=es2015).symbols new file mode 100644 index 0000000000000..7f94ddadbe167 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es2015).symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock13.ts, 0, 0)) + + static #x = 123; +>#x : Symbol(C.#x, Decl(classStaticBlock13.ts, 0, 9)) + + static { + console.log(C.#x) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.#x : Symbol(C.#x, Decl(classStaticBlock13.ts, 0, 9)) +>C : Symbol(C, Decl(classStaticBlock13.ts, 0, 0)) + } + + foo () { +>foo : Symbol(C.foo, Decl(classStaticBlock13.ts, 5, 3)) + + return C.#x; +>C.#x : Symbol(C.#x, Decl(classStaticBlock13.ts, 0, 9)) +>C : Symbol(C, Decl(classStaticBlock13.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock13(target=es2015).types b/tests/baselines/reference/classStaticBlock13(target=es2015).types new file mode 100644 index 0000000000000..735409daa5c44 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es2015).types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts === +class C { +>C : C + + static #x = 123; +>#x : number +>123 : 123 + + static { + console.log(C.#x) +>console.log(C.#x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.#x : number +>C : typeof C + } + + foo () { +>foo : () => number + + return C.#x; +>C.#x : number +>C : typeof C + } +} + diff --git a/tests/baselines/reference/classStaticBlock13(target=esnext).js b/tests/baselines/reference/classStaticBlock13(target=esnext).js new file mode 100644 index 0000000000000..5821962aee033 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=esnext).js @@ -0,0 +1,24 @@ +//// [classStaticBlock13.ts] +class C { + static #x = 123; + + static { + console.log(C.#x) + } + + foo () { + return C.#x; + } +} + + +//// [classStaticBlock13.js] +class C { + static #x = 123; + static { + console.log(C.#x); + } + foo() { + return C.#x; + } +} diff --git a/tests/baselines/reference/classStaticBlock13(target=esnext).symbols b/tests/baselines/reference/classStaticBlock13(target=esnext).symbols new file mode 100644 index 0000000000000..7f94ddadbe167 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=esnext).symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock13.ts, 0, 0)) + + static #x = 123; +>#x : Symbol(C.#x, Decl(classStaticBlock13.ts, 0, 9)) + + static { + console.log(C.#x) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.#x : Symbol(C.#x, Decl(classStaticBlock13.ts, 0, 9)) +>C : Symbol(C, Decl(classStaticBlock13.ts, 0, 0)) + } + + foo () { +>foo : Symbol(C.foo, Decl(classStaticBlock13.ts, 5, 3)) + + return C.#x; +>C.#x : Symbol(C.#x, Decl(classStaticBlock13.ts, 0, 9)) +>C : Symbol(C, Decl(classStaticBlock13.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock13(target=esnext).types b/tests/baselines/reference/classStaticBlock13(target=esnext).types new file mode 100644 index 0000000000000..735409daa5c44 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=esnext).types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts === +class C { +>C : C + + static #x = 123; +>#x : number +>123 : 123 + + static { + console.log(C.#x) +>console.log(C.#x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.#x : number +>C : typeof C + } + + foo () { +>foo : () => number + + return C.#x; +>C.#x : number +>C : typeof C + } +} + diff --git a/tests/baselines/reference/classStaticBlock14.js b/tests/baselines/reference/classStaticBlock14.js new file mode 100644 index 0000000000000..e64e2a7d5d795 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock14.js @@ -0,0 +1,35 @@ +//// [classStaticBlock14.ts] +class C { + static #_1 = 1; + static #_3 = 1; + static #_5 = 1; + + static {} + static {} + static {} + static {} + static {} + static {} +} + + +//// [classStaticBlock14.js] +var _a, _C__1, _C__3, _C__5; +class C { +} +_a = C; +_C__1 = { value: 1 }; +_C__3 = { value: 1 }; +_C__5 = { value: 1 }; +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); diff --git a/tests/baselines/reference/classStaticBlock14.symbols b/tests/baselines/reference/classStaticBlock14.symbols new file mode 100644 index 0000000000000..5e52a5b088420 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock14.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock14.ts, 0, 0)) + + static #_1 = 1; +>#_1 : Symbol(C.#_1, Decl(classStaticBlock14.ts, 0, 9)) + + static #_3 = 1; +>#_3 : Symbol(C.#_3, Decl(classStaticBlock14.ts, 1, 17)) + + static #_5 = 1; +>#_5 : Symbol(C.#_5, Decl(classStaticBlock14.ts, 2, 17)) + + static {} + static {} + static {} + static {} + static {} + static {} +} + diff --git a/tests/baselines/reference/classStaticBlock14.types b/tests/baselines/reference/classStaticBlock14.types new file mode 100644 index 0000000000000..08de67a56e183 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock14.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts === +class C { +>C : C + + static #_1 = 1; +>#_1 : number +>1 : 1 + + static #_3 = 1; +>#_3 : number +>1 : 1 + + static #_5 = 1; +>#_5 : number +>1 : 1 + + static {} + static {} + static {} + static {} + static {} + static {} +} + diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).js b/tests/baselines/reference/classStaticBlock15(target=es2015).js new file mode 100644 index 0000000000000..0c18e76329367 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).js @@ -0,0 +1,41 @@ +//// [classStaticBlock15.ts] +var _C__1; + +class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) + + +//// [classStaticBlock15.js] +var _a, _C__1_1, _C__3, _C__5; +var _C__1; +class C { +} +_a = C; +_C__1_1 = { value: 1 }; +_C__3 = { value: 3 }; +_C__5 = { value: 5 }; +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +console.log(_C__1); diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).symbols b/tests/baselines/reference/classStaticBlock15(target=es2015).symbols new file mode 100644 index 0000000000000..12ab9dd68059b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +var _C__1; +>_C__1 : Symbol(_C__1, Decl(classStaticBlock15.ts, 0, 3)) + +class C { +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 10)) + + static #_1 = 1; +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 2, 9)) + + static #_3 = 3; +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 3, 17)) + + static #_5 = 5; +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 4, 17)) + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>_C__1 : Symbol(_C__1, Decl(classStaticBlock15.ts, 0, 3)) + diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).types b/tests/baselines/reference/classStaticBlock15(target=es2015).types new file mode 100644 index 0000000000000..262ff1a4c2769 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +var _C__1; +>_C__1 : any + +class C { +>C : C + + static #_1 = 1; +>#_1 : number +>1 : 1 + + static #_3 = 3; +>#_3 : number +>3 : 3 + + static #_5 = 5; +>#_5 : number +>5 : 5 + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) +>console.log(_C__1) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>_C__1 : any + diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).js b/tests/baselines/reference/classStaticBlock15(target=esnext).js new file mode 100644 index 0000000000000..5646a0ef941b3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).js @@ -0,0 +1,33 @@ +//// [classStaticBlock15.ts] +var _C__1; + +class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) + + +//// [classStaticBlock15.js] +var _C__1; +class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + static { } + static { } + static { } + static { } + static { } + static { } +} +console.log(_C__1); diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).symbols b/tests/baselines/reference/classStaticBlock15(target=esnext).symbols new file mode 100644 index 0000000000000..12ab9dd68059b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +var _C__1; +>_C__1 : Symbol(_C__1, Decl(classStaticBlock15.ts, 0, 3)) + +class C { +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 10)) + + static #_1 = 1; +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 2, 9)) + + static #_3 = 3; +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 3, 17)) + + static #_5 = 5; +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 4, 17)) + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>_C__1 : Symbol(_C__1, Decl(classStaticBlock15.ts, 0, 3)) + diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).types b/tests/baselines/reference/classStaticBlock15(target=esnext).types new file mode 100644 index 0000000000000..262ff1a4c2769 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +var _C__1; +>_C__1 : any + +class C { +>C : C + + static #_1 = 1; +>#_1 : number +>1 : 1 + + static #_3 = 3; +>#_3 : number +>3 : 3 + + static #_5 = 5; +>#_5 : number +>5 : 5 + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) +>console.log(_C__1) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>_C__1 : any + diff --git a/tests/baselines/reference/classStaticBlock16.errors.txt b/tests/baselines/reference/classStaticBlock16.errors.txt new file mode 100644 index 0000000000000..2e3218799ec3f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock16.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts(11,5): error TS2448: Block-scoped variable 'getY' used before its declaration. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts(11,28): error TS18013: Property '#y' is not accessible outside class 'D' because it has a private identifier. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts(21,28): error TS18013: Property '#x' is not accessible outside class 'C' because it has a private identifier. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts (3 errors) ==== + let getX: (c: C) => number; + class C { + #x = 1 + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + getY = (obj: D) => obj.#y; + ~~~~ +!!! error TS2448: Block-scoped variable 'getY' used before its declaration. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts:15:5: 'getY' is declared here. + ~~ +!!! error TS18013: Property '#y' is not accessible outside class 'D' because it has a private identifier. + } + } + + let getY: (c: D) => number; + class D { + #y = 1 + + static { + // getY has privileged access to y + getX = (obj: C) => obj.#x; + ~~ +!!! error TS18013: Property '#x' is not accessible outside class 'C' because it has a private identifier. + getY = (obj: D) => obj.#y; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock16.js b/tests/baselines/reference/classStaticBlock16.js new file mode 100644 index 0000000000000..566d3ceeb179e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock16.js @@ -0,0 +1,64 @@ +//// [classStaticBlock16.ts] +let getX: (c: C) => number; +class C { + #x = 1 + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + getY = (obj: D) => obj.#y; + } +} + +let getY: (c: D) => number; +class D { + #y = 1 + + static { + // getY has privileged access to y + getX = (obj: C) => obj.#x; + getY = (obj: D) => obj.#y; + } +} + +//// [classStaticBlock16.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _C_x, _D_y; +let getX; +class C { + constructor(x) { + _C_x.set(this, 1); + __classPrivateFieldSet(this, _C_x, x, "f"); + } +} +_C_x = new WeakMap(); +(() => { + // getX has privileged access to #x + getX = (obj) => __classPrivateFieldGet(obj, _C_x, "f"); + getY = (obj) => obj.; +})(); +let getY; +class D { + constructor() { + _D_y.set(this, 1); + } +} +_D_y = new WeakMap(); +(() => { + // getY has privileged access to y + getX = (obj) => obj.; + getY = (obj) => __classPrivateFieldGet(obj, _D_y, "f"); +})(); diff --git a/tests/baselines/reference/classStaticBlock16.symbols b/tests/baselines/reference/classStaticBlock16.symbols new file mode 100644 index 0000000000000..14e8b724c1287 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock16.symbols @@ -0,0 +1,65 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts === +let getX: (c: C) => number; +>getX : Symbol(getX, Decl(classStaticBlock16.ts, 0, 3)) +>c : Symbol(c, Decl(classStaticBlock16.ts, 0, 11)) +>C : Symbol(C, Decl(classStaticBlock16.ts, 0, 27)) + +class C { +>C : Symbol(C, Decl(classStaticBlock16.ts, 0, 27)) + + #x = 1 +>#x : Symbol(C.#x, Decl(classStaticBlock16.ts, 1, 9)) + + constructor(x: number) { +>x : Symbol(x, Decl(classStaticBlock16.ts, 3, 14)) + + this.#x = x; +>this.#x : Symbol(C.#x, Decl(classStaticBlock16.ts, 1, 9)) +>this : Symbol(C, Decl(classStaticBlock16.ts, 0, 27)) +>x : Symbol(x, Decl(classStaticBlock16.ts, 3, 14)) + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; +>getX : Symbol(getX, Decl(classStaticBlock16.ts, 0, 3)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 9, 12)) +>C : Symbol(C, Decl(classStaticBlock16.ts, 0, 27)) +>obj.#x : Symbol(C.#x, Decl(classStaticBlock16.ts, 1, 9)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 9, 12)) + + getY = (obj: D) => obj.#y; +>getY : Symbol(getY, Decl(classStaticBlock16.ts, 14, 3)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 10, 12)) +>D : Symbol(D, Decl(classStaticBlock16.ts, 14, 27)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 10, 12)) + } +} + +let getY: (c: D) => number; +>getY : Symbol(getY, Decl(classStaticBlock16.ts, 14, 3)) +>c : Symbol(c, Decl(classStaticBlock16.ts, 14, 11)) +>D : Symbol(D, Decl(classStaticBlock16.ts, 14, 27)) + +class D { +>D : Symbol(D, Decl(classStaticBlock16.ts, 14, 27)) + + #y = 1 +>#y : Symbol(D.#y, Decl(classStaticBlock16.ts, 15, 9)) + + static { + // getY has privileged access to y + getX = (obj: C) => obj.#x; +>getX : Symbol(getX, Decl(classStaticBlock16.ts, 0, 3)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 20, 12)) +>C : Symbol(C, Decl(classStaticBlock16.ts, 0, 27)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 20, 12)) + + getY = (obj: D) => obj.#y; +>getY : Symbol(getY, Decl(classStaticBlock16.ts, 14, 3)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 21, 12)) +>D : Symbol(D, Decl(classStaticBlock16.ts, 14, 27)) +>obj.#y : Symbol(D.#y, Decl(classStaticBlock16.ts, 15, 9)) +>obj : Symbol(obj, Decl(classStaticBlock16.ts, 21, 12)) + } +} diff --git a/tests/baselines/reference/classStaticBlock16.types b/tests/baselines/reference/classStaticBlock16.types new file mode 100644 index 0000000000000..b5e9626a9408c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock16.types @@ -0,0 +1,72 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts === +let getX: (c: C) => number; +>getX : (c: C) => number +>c : C + +class C { +>C : C + + #x = 1 +>#x : number +>1 : 1 + + constructor(x: number) { +>x : number + + this.#x = x; +>this.#x = x : number +>this.#x : number +>this : this +>x : number + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; +>getX = (obj: C) => obj.#x : (obj: C) => number +>getX : (c: C) => number +>(obj: C) => obj.#x : (obj: C) => number +>obj : C +>obj.#x : number +>obj : C + + getY = (obj: D) => obj.#y; +>getY = (obj: D) => obj.#y : (obj: D) => any +>getY : (c: D) => number +>(obj: D) => obj.#y : (obj: D) => any +>obj : D +>obj.#y : any +>obj : D + } +} + +let getY: (c: D) => number; +>getY : (c: D) => number +>c : D + +class D { +>D : D + + #y = 1 +>#y : number +>1 : 1 + + static { + // getY has privileged access to y + getX = (obj: C) => obj.#x; +>getX = (obj: C) => obj.#x : (obj: C) => any +>getX : (c: C) => number +>(obj: C) => obj.#x : (obj: C) => any +>obj : C +>obj.#x : any +>obj : C + + getY = (obj: D) => obj.#y; +>getY = (obj: D) => obj.#y : (obj: D) => number +>getY : (c: D) => number +>(obj: D) => obj.#y : (obj: D) => number +>obj : D +>obj.#y : number +>obj : D + } +} diff --git a/tests/baselines/reference/classStaticBlock17.js b/tests/baselines/reference/classStaticBlock17.js new file mode 100644 index 0000000000000..9464a543cfa61 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock17.js @@ -0,0 +1,74 @@ +//// [classStaticBlock17.ts] +let friendA: { getX(o: A): number, setX(o: A, v: number): void }; + +class A { + #x: number; + + constructor (v: number) { + this.#x = v; + } + + getX () { + return this.#x; + } + + static { + friendA = { + getX(obj) { return obj.#x }, + setX(obj, value) { obj.#x = value } + }; + } +}; + +class B { + constructor(a: A) { + const x = friendA.getX(a); // ok + friendA.setX(a, x + 1); // ok + } +}; + +const a = new A(41); +const b = new B(a); +a.getX(); + +//// [classStaticBlock17.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _A_x; +let friendA; +class A { + constructor(v) { + _A_x.set(this, void 0); + __classPrivateFieldSet(this, _A_x, v, "f"); + } + getX() { + return __classPrivateFieldGet(this, _A_x, "f"); + } +} +_A_x = new WeakMap(); +(() => { + friendA = { + getX(obj) { return __classPrivateFieldGet(obj, _A_x, "f"); }, + setX(obj, value) { __classPrivateFieldSet(obj, _A_x, value, "f"); } + }; +})(); +; +class B { + constructor(a) { + const x = friendA.getX(a); // ok + friendA.setX(a, x + 1); // ok + } +} +; +const a = new A(41); +const b = new B(a); +a.getX(); diff --git a/tests/baselines/reference/classStaticBlock17.symbols b/tests/baselines/reference/classStaticBlock17.symbols new file mode 100644 index 0000000000000..6038b5c8ef899 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock17.symbols @@ -0,0 +1,93 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock17.ts === +let friendA: { getX(o: A): number, setX(o: A, v: number): void }; +>friendA : Symbol(friendA, Decl(classStaticBlock17.ts, 0, 3)) +>getX : Symbol(getX, Decl(classStaticBlock17.ts, 0, 14)) +>o : Symbol(o, Decl(classStaticBlock17.ts, 0, 20)) +>A : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) +>setX : Symbol(setX, Decl(classStaticBlock17.ts, 0, 34)) +>o : Symbol(o, Decl(classStaticBlock17.ts, 0, 40)) +>A : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) +>v : Symbol(v, Decl(classStaticBlock17.ts, 0, 45)) + +class A { +>A : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) + + #x: number; +>#x : Symbol(A.#x, Decl(classStaticBlock17.ts, 2, 9)) + + constructor (v: number) { +>v : Symbol(v, Decl(classStaticBlock17.ts, 5, 15)) + + this.#x = v; +>this.#x : Symbol(A.#x, Decl(classStaticBlock17.ts, 2, 9)) +>this : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) +>v : Symbol(v, Decl(classStaticBlock17.ts, 5, 15)) + } + + getX () { +>getX : Symbol(A.getX, Decl(classStaticBlock17.ts, 7, 3)) + + return this.#x; +>this.#x : Symbol(A.#x, Decl(classStaticBlock17.ts, 2, 9)) +>this : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) + } + + static { + friendA = { +>friendA : Symbol(friendA, Decl(classStaticBlock17.ts, 0, 3)) + + getX(obj) { return obj.#x }, +>getX : Symbol(getX, Decl(classStaticBlock17.ts, 14, 15)) +>obj : Symbol(obj, Decl(classStaticBlock17.ts, 15, 11)) +>obj.#x : Symbol(A.#x, Decl(classStaticBlock17.ts, 2, 9)) +>obj : Symbol(obj, Decl(classStaticBlock17.ts, 15, 11)) + + setX(obj, value) { obj.#x = value } +>setX : Symbol(setX, Decl(classStaticBlock17.ts, 15, 34)) +>obj : Symbol(obj, Decl(classStaticBlock17.ts, 16, 11)) +>value : Symbol(value, Decl(classStaticBlock17.ts, 16, 15)) +>obj.#x : Symbol(A.#x, Decl(classStaticBlock17.ts, 2, 9)) +>obj : Symbol(obj, Decl(classStaticBlock17.ts, 16, 11)) +>value : Symbol(value, Decl(classStaticBlock17.ts, 16, 15)) + + }; + } +}; + +class B { +>B : Symbol(B, Decl(classStaticBlock17.ts, 19, 2)) + + constructor(a: A) { +>a : Symbol(a, Decl(classStaticBlock17.ts, 22, 14)) +>A : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) + + const x = friendA.getX(a); // ok +>x : Symbol(x, Decl(classStaticBlock17.ts, 23, 9)) +>friendA.getX : Symbol(getX, Decl(classStaticBlock17.ts, 0, 14)) +>friendA : Symbol(friendA, Decl(classStaticBlock17.ts, 0, 3)) +>getX : Symbol(getX, Decl(classStaticBlock17.ts, 0, 14)) +>a : Symbol(a, Decl(classStaticBlock17.ts, 22, 14)) + + friendA.setX(a, x + 1); // ok +>friendA.setX : Symbol(setX, Decl(classStaticBlock17.ts, 0, 34)) +>friendA : Symbol(friendA, Decl(classStaticBlock17.ts, 0, 3)) +>setX : Symbol(setX, Decl(classStaticBlock17.ts, 0, 34)) +>a : Symbol(a, Decl(classStaticBlock17.ts, 22, 14)) +>x : Symbol(x, Decl(classStaticBlock17.ts, 23, 9)) + } +}; + +const a = new A(41); +>a : Symbol(a, Decl(classStaticBlock17.ts, 28, 5)) +>A : Symbol(A, Decl(classStaticBlock17.ts, 0, 65)) + +const b = new B(a); +>b : Symbol(b, Decl(classStaticBlock17.ts, 29, 5)) +>B : Symbol(B, Decl(classStaticBlock17.ts, 19, 2)) +>a : Symbol(a, Decl(classStaticBlock17.ts, 28, 5)) + +a.getX(); +>a.getX : Symbol(A.getX, Decl(classStaticBlock17.ts, 7, 3)) +>a : Symbol(a, Decl(classStaticBlock17.ts, 28, 5)) +>getX : Symbol(A.getX, Decl(classStaticBlock17.ts, 7, 3)) + diff --git a/tests/baselines/reference/classStaticBlock17.types b/tests/baselines/reference/classStaticBlock17.types new file mode 100644 index 0000000000000..ae27524b4bc96 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock17.types @@ -0,0 +1,102 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock17.ts === +let friendA: { getX(o: A): number, setX(o: A, v: number): void }; +>friendA : { getX(o: A): number; setX(o: A, v: number): void; } +>getX : (o: A) => number +>o : A +>setX : (o: A, v: number) => void +>o : A +>v : number + +class A { +>A : A + + #x: number; +>#x : number + + constructor (v: number) { +>v : number + + this.#x = v; +>this.#x = v : number +>this.#x : number +>this : this +>v : number + } + + getX () { +>getX : () => number + + return this.#x; +>this.#x : number +>this : this + } + + static { + friendA = { +>friendA = { getX(obj) { return obj.#x }, setX(obj, value) { obj.#x = value } } : { getX(obj: A): number; setX(obj: A, value: number): void; } +>friendA : { getX(o: A): number; setX(o: A, v: number): void; } +>{ getX(obj) { return obj.#x }, setX(obj, value) { obj.#x = value } } : { getX(obj: A): number; setX(obj: A, value: number): void; } + + getX(obj) { return obj.#x }, +>getX : (obj: A) => number +>obj : A +>obj.#x : number +>obj : A + + setX(obj, value) { obj.#x = value } +>setX : (obj: A, value: number) => void +>obj : A +>value : number +>obj.#x = value : number +>obj.#x : number +>obj : A +>value : number + + }; + } +}; + +class B { +>B : B + + constructor(a: A) { +>a : A + + const x = friendA.getX(a); // ok +>x : number +>friendA.getX(a) : number +>friendA.getX : (o: A) => number +>friendA : { getX(o: A): number; setX(o: A, v: number): void; } +>getX : (o: A) => number +>a : A + + friendA.setX(a, x + 1); // ok +>friendA.setX(a, x + 1) : void +>friendA.setX : (o: A, v: number) => void +>friendA : { getX(o: A): number; setX(o: A, v: number): void; } +>setX : (o: A, v: number) => void +>a : A +>x + 1 : number +>x : number +>1 : 1 + } +}; + +const a = new A(41); +>a : A +>new A(41) : A +>A : typeof A +>41 : 41 + +const b = new B(a); +>b : B +>new B(a) : B +>B : typeof B +>a : A + +a.getX(); +>a.getX() : number +>a.getX : () => number +>a : A +>getX : () => number + diff --git a/tests/baselines/reference/classStaticBlock18(target=es2015).js b/tests/baselines/reference/classStaticBlock18(target=es2015).js new file mode 100644 index 0000000000000..7269e6f67a78d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es2015).js @@ -0,0 +1,34 @@ +//// [classStaticBlock18.ts] +function foo () { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + } + } + } +} + + +//// [classStaticBlock18.js] +function foo() { + var _a; + return _a = class { + }, + _a.foo = 1, + (() => { + var _a; + const c = (_a = class { + }, + _a.bar = 2, + (() => { + // do + })(), + _a); + })(), + _a; +} diff --git a/tests/baselines/reference/classStaticBlock18(target=es2015).symbols b/tests/baselines/reference/classStaticBlock18(target=es2015).symbols new file mode 100644 index 0000000000000..22e9413ef67ef --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es2015).symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts === +function foo () { +>foo : Symbol(foo, Decl(classStaticBlock18.ts, 0, 0)) + + return class { + static foo = 1; +>foo : Symbol((Anonymous class).foo, Decl(classStaticBlock18.ts, 1, 16)) + + static { + const c = class { +>c : Symbol(c, Decl(classStaticBlock18.ts, 4, 11)) + + static bar = 2; +>bar : Symbol(c.bar, Decl(classStaticBlock18.ts, 4, 23)) + + static { + // do + } + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock18(target=es2015).types b/tests/baselines/reference/classStaticBlock18(target=es2015).types new file mode 100644 index 0000000000000..5bc9155932a2b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es2015).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts === +function foo () { +>foo : () => typeof (Anonymous class) + + return class { +>class { static foo = 1; static { const c = class { static bar = 2; static { // do } } } } : typeof (Anonymous class) + + static foo = 1; +>foo : number +>1 : 1 + + static { + const c = class { +>c : typeof c +>class { static bar = 2; static { // do } } : typeof c + + static bar = 2; +>bar : number +>2 : 2 + + static { + // do + } + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock18(target=es5).js b/tests/baselines/reference/classStaticBlock18(target=es5).js new file mode 100644 index 0000000000000..48597ad94cc17 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es5).js @@ -0,0 +1,40 @@ +//// [classStaticBlock18.ts] +function foo () { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + } + } + } +} + + +//// [classStaticBlock18.js] +function foo() { + var _a; + return _a = /** @class */ (function () { + function class_1() { + } + return class_1; + }()), + _a.foo = 1, + (function () { + var _a; + var c = (_a = /** @class */ (function () { + function class_2() { + } + return class_2; + }()), + _a.bar = 2, + (function () { + // do + })(), + _a); + })(), + _a; +} diff --git a/tests/baselines/reference/classStaticBlock18(target=es5).symbols b/tests/baselines/reference/classStaticBlock18(target=es5).symbols new file mode 100644 index 0000000000000..22e9413ef67ef --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es5).symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts === +function foo () { +>foo : Symbol(foo, Decl(classStaticBlock18.ts, 0, 0)) + + return class { + static foo = 1; +>foo : Symbol((Anonymous class).foo, Decl(classStaticBlock18.ts, 1, 16)) + + static { + const c = class { +>c : Symbol(c, Decl(classStaticBlock18.ts, 4, 11)) + + static bar = 2; +>bar : Symbol(c.bar, Decl(classStaticBlock18.ts, 4, 23)) + + static { + // do + } + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock18(target=es5).types b/tests/baselines/reference/classStaticBlock18(target=es5).types new file mode 100644 index 0000000000000..5bc9155932a2b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es5).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts === +function foo () { +>foo : () => typeof (Anonymous class) + + return class { +>class { static foo = 1; static { const c = class { static bar = 2; static { // do } } } } : typeof (Anonymous class) + + static foo = 1; +>foo : number +>1 : 1 + + static { + const c = class { +>c : typeof c +>class { static bar = 2; static { // do } } : typeof c + + static bar = 2; +>bar : number +>2 : 2 + + static { + // do + } + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock18(target=esnext).js b/tests/baselines/reference/classStaticBlock18(target=esnext).js new file mode 100644 index 0000000000000..ed8123e3e059d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=esnext).js @@ -0,0 +1,30 @@ +//// [classStaticBlock18.ts] +function foo () { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + } + } + } +} + + +//// [classStaticBlock18.js] +function foo() { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + }; + } + }; +} diff --git a/tests/baselines/reference/classStaticBlock18(target=esnext).symbols b/tests/baselines/reference/classStaticBlock18(target=esnext).symbols new file mode 100644 index 0000000000000..22e9413ef67ef --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=esnext).symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts === +function foo () { +>foo : Symbol(foo, Decl(classStaticBlock18.ts, 0, 0)) + + return class { + static foo = 1; +>foo : Symbol((Anonymous class).foo, Decl(classStaticBlock18.ts, 1, 16)) + + static { + const c = class { +>c : Symbol(c, Decl(classStaticBlock18.ts, 4, 11)) + + static bar = 2; +>bar : Symbol(c.bar, Decl(classStaticBlock18.ts, 4, 23)) + + static { + // do + } + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock18(target=esnext).types b/tests/baselines/reference/classStaticBlock18(target=esnext).types new file mode 100644 index 0000000000000..5bc9155932a2b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=esnext).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts === +function foo () { +>foo : () => typeof (Anonymous class) + + return class { +>class { static foo = 1; static { const c = class { static bar = 2; static { // do } } } } : typeof (Anonymous class) + + static foo = 1; +>foo : number +>1 : 1 + + static { + const c = class { +>c : typeof c +>class { static bar = 2; static { // do } } : typeof c + + static bar = 2; +>bar : number +>2 : 2 + + static { + // do + } + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock19.errors.txt b/tests/baselines/reference/classStaticBlock19.errors.txt new file mode 100644 index 0000000000000..dbfa26cc56520 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock19.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts(2,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts (1 errors) ==== + class C { + @decorator + ~ +!!! error TS1206: Decorators are not valid here. + static { + // something + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock19.js b/tests/baselines/reference/classStaticBlock19.js new file mode 100644 index 0000000000000..3f74c18a6970c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock19.js @@ -0,0 +1,18 @@ +//// [classStaticBlock19.ts] +class C { + @decorator + static { + // something + } +} + + +//// [classStaticBlock19.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +(function () { + // something +})(); diff --git a/tests/baselines/reference/classStaticBlock19.symbols b/tests/baselines/reference/classStaticBlock19.symbols new file mode 100644 index 0000000000000..e921d8ca002b7 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock19.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock19.ts, 0, 0)) + + @decorator + static { + // something + } +} + diff --git a/tests/baselines/reference/classStaticBlock19.types b/tests/baselines/reference/classStaticBlock19.types new file mode 100644 index 0000000000000..076e76ee44a67 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock19.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts === +class C { +>C : C + + @decorator +>decorator : any + + static { + // something + } +} + diff --git a/tests/baselines/reference/classStaticBlock2(target=es2015).js b/tests/baselines/reference/classStaticBlock2(target=es2015).js new file mode 100644 index 0000000000000..b578941d6154a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es2015).js @@ -0,0 +1,36 @@ +//// [classStaticBlock2.ts] +const a = 1; +const b = 2; + +class C { + static { + const a = 11; + + a; + b; + } + + static { + const a = 11; + + a; + b; + } +} + + +//// [classStaticBlock2.js] +const a = 1; +const b = 2; +class C { +} +(() => { + const a = 11; + a; + b; +})(); +(() => { + const a = 11; + a; + b; +})(); diff --git a/tests/baselines/reference/classStaticBlock2(target=es2015).symbols b/tests/baselines/reference/classStaticBlock2(target=es2015).symbols new file mode 100644 index 0000000000000..93bfa964aaeb6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es2015).symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts === +const a = 1; +>a : Symbol(a, Decl(classStaticBlock2.ts, 0, 5)) + +const b = 2; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock2.ts, 1, 12)) + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock2.ts, 5, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock2.ts, 5, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + } + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock2.ts, 12, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock2.ts, 12, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock2(target=es2015).types b/tests/baselines/reference/classStaticBlock2(target=es2015).types new file mode 100644 index 0000000000000..2e22833b22ddf --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es2015).types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts === +const a = 1; +>a : 1 +>1 : 1 + +const b = 2; +>b : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } +} + diff --git a/tests/baselines/reference/classStaticBlock2(target=es5).js b/tests/baselines/reference/classStaticBlock2(target=es5).js new file mode 100644 index 0000000000000..8165387d27820 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es5).js @@ -0,0 +1,39 @@ +//// [classStaticBlock2.ts] +const a = 1; +const b = 2; + +class C { + static { + const a = 11; + + a; + b; + } + + static { + const a = 11; + + a; + b; + } +} + + +//// [classStaticBlock2.js] +var a = 1; +var b = 2; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +(function () { + var a = 11; + a; + b; +})(); +(function () { + var a = 11; + a; + b; +})(); diff --git a/tests/baselines/reference/classStaticBlock2(target=es5).symbols b/tests/baselines/reference/classStaticBlock2(target=es5).symbols new file mode 100644 index 0000000000000..93bfa964aaeb6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es5).symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts === +const a = 1; +>a : Symbol(a, Decl(classStaticBlock2.ts, 0, 5)) + +const b = 2; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock2.ts, 1, 12)) + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock2.ts, 5, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock2.ts, 5, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + } + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock2.ts, 12, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock2.ts, 12, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock2(target=es5).types b/tests/baselines/reference/classStaticBlock2(target=es5).types new file mode 100644 index 0000000000000..2e22833b22ddf --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es5).types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts === +const a = 1; +>a : 1 +>1 : 1 + +const b = 2; +>b : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } +} + diff --git a/tests/baselines/reference/classStaticBlock2(target=esnext).js b/tests/baselines/reference/classStaticBlock2(target=esnext).js new file mode 100644 index 0000000000000..ccff801b61335 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=esnext).js @@ -0,0 +1,36 @@ +//// [classStaticBlock2.ts] +const a = 1; +const b = 2; + +class C { + static { + const a = 11; + + a; + b; + } + + static { + const a = 11; + + a; + b; + } +} + + +//// [classStaticBlock2.js] +const a = 1; +const b = 2; +class C { + static { + const a = 11; + a; + b; + } + static { + const a = 11; + a; + b; + } +} diff --git a/tests/baselines/reference/classStaticBlock2(target=esnext).symbols b/tests/baselines/reference/classStaticBlock2(target=esnext).symbols new file mode 100644 index 0000000000000..93bfa964aaeb6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=esnext).symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts === +const a = 1; +>a : Symbol(a, Decl(classStaticBlock2.ts, 0, 5)) + +const b = 2; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock2.ts, 1, 12)) + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock2.ts, 5, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock2.ts, 5, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + } + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock2.ts, 12, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock2.ts, 12, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock2.ts, 1, 5)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock2(target=esnext).types b/tests/baselines/reference/classStaticBlock2(target=esnext).types new file mode 100644 index 0000000000000..2e22833b22ddf --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=esnext).types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts === +const a = 1; +>a : 1 +>1 : 1 + +const b = 2; +>b : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } +} + diff --git a/tests/baselines/reference/classStaticBlock20.errors.txt b/tests/baselines/reference/classStaticBlock20.errors.txt new file mode 100644 index 0000000000000..87f6864f5d85c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock20.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts(2,5): error TS1184: Modifiers cannot appear here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts(6,5): error TS1184: Modifiers cannot appear here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts(10,5): error TS1184: Modifiers cannot appear here. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts (3 errors) ==== + class C { + async static { + ~~~~~ +!!! error TS1184: Modifiers cannot appear here. + // something + } + + public static { + ~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + // something + } + + readonly private static { + ~~~~~~~~ +!!! error TS1184: Modifiers cannot appear here. + // something + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock20.js b/tests/baselines/reference/classStaticBlock20.js new file mode 100644 index 0000000000000..bd4d4597c6515 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock20.js @@ -0,0 +1,31 @@ +//// [classStaticBlock20.ts] +class C { + async static { + // something + } + + public static { + // something + } + + readonly private static { + // something + } +} + + +//// [classStaticBlock20.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +(function () { + // something +})(); +(function () { + // something +})(); +(function () { + // something +})(); diff --git a/tests/baselines/reference/classStaticBlock20.symbols b/tests/baselines/reference/classStaticBlock20.symbols new file mode 100644 index 0000000000000..00464f3f7b225 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock20.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock20.ts, 0, 0)) + + async static { + // something + } + + public static { + // something + } + + readonly private static { + // something + } +} + diff --git a/tests/baselines/reference/classStaticBlock20.types b/tests/baselines/reference/classStaticBlock20.types new file mode 100644 index 0000000000000..ba0c15b3776e0 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock20.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts === +class C { +>C : C + + async static { + // something + } + + public static { + // something + } + + readonly private static { + // something + } +} + diff --git a/tests/baselines/reference/classStaticBlock21.js b/tests/baselines/reference/classStaticBlock21.js new file mode 100644 index 0000000000000..2b1b059fc59ea --- /dev/null +++ b/tests/baselines/reference/classStaticBlock21.js @@ -0,0 +1,19 @@ +//// [classStaticBlock21.ts] +class C { + /* jsdocs */ + static { + // something + } +} + + +//// [classStaticBlock21.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +/* jsdocs */ +(function () { + // something +})(); diff --git a/tests/baselines/reference/classStaticBlock21.symbols b/tests/baselines/reference/classStaticBlock21.symbols new file mode 100644 index 0000000000000..2adf968775a1b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock21.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock21.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock21.ts, 0, 0)) + + /* jsdocs */ + static { + // something + } +} + diff --git a/tests/baselines/reference/classStaticBlock21.types b/tests/baselines/reference/classStaticBlock21.types new file mode 100644 index 0000000000000..2cf5b1acb7e3d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock21.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock21.ts === +class C { +>C : C + + /* jsdocs */ + static { + // something + } +} + diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt new file mode 100644 index 0000000000000..cb89b33e3bc3b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -0,0 +1,94 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(7,11): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,14): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,11): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(29,15): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(32,12): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (7 errors) ==== + let await: "any"; + class C { + static { + let await: any; // illegal, cannot declare a new binding for await + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + let { await } = {} as any; // illegal, cannot declare a new binding for await + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + let { await: other } = {} as any; // legal + } + static { + let await; // illegal, cannot declare a new binding for await + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + function await() { }; // illegal + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + class await { }; // illegal + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + }; + } + static { + (function await() { }); // legal, 'await' in function expression name not bound inside of static block + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + (class await { }); // legal, 'await' in class expression name not bound inside of static block + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + (function () { return await; }); // legal, 'await' is inside of a new function boundary + } + static { + (() => await); // legal, 'await' is inside of a new function boundary + } + + static { + class E { + constructor() { await; } + method() { await; } + get accessor() { + await; + return 1; + } + set accessor(v: any) { + await; + } + propLambda = () => { await; } + propFunc = function () { await; } + } + } + static { + class S { + static method() { await; } + static get accessor() { + await; + return 1; + } + static set accessor(v: any) { + await; + } + static propLambda = () => { await; } + static propFunc = function () { await; } + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock22.js b/tests/baselines/reference/classStaticBlock22.js new file mode 100644 index 0000000000000..bed746875acdf --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.js @@ -0,0 +1,146 @@ +//// [classStaticBlock22.ts] +let await: "any"; +class C { + static { + let await: any; // illegal, cannot declare a new binding for await + } + static { + let { await } = {} as any; // illegal, cannot declare a new binding for await + } + static { + let { await: other } = {} as any; // legal + } + static { + let await; // illegal, cannot declare a new binding for await + } + static { + function await() { }; // illegal + } + static { + class await { }; // illegal + } + + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + }; + } + static { + (function await() { }); // legal, 'await' in function expression name not bound inside of static block + } + static { + (class await { }); // legal, 'await' in class expression name not bound inside of static block + } + static { + (function () { return await; }); // legal, 'await' is inside of a new function boundary + } + static { + (() => await); // legal, 'await' is inside of a new function boundary + } + + static { + class E { + constructor() { await; } + method() { await; } + get accessor() { + await; + return 1; + } + set accessor(v: any) { + await; + } + propLambda = () => { await; } + propFunc = function () { await; } + } + } + static { + class S { + static method() { await; } + static get accessor() { + await; + return 1; + } + static set accessor(v: any) { + await; + } + static propLambda = () => { await; } + static propFunc = function () { await; } + } + } +} + +//// [classStaticBlock22.js] +let await; +class C { + static { + let await; // illegal, cannot declare a new binding for await + } + static { + let { await } = {}; // illegal, cannot declare a new binding for await + } + static { + let { await: other } = {}; // legal + } + static { + let await; // illegal, cannot declare a new binding for await + } + static { + function await() { } + ; // illegal + } + static { + class await { + } + ; // illegal + } + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + } + ; + } + static { + (function await() { }); // legal, 'await' in function expression name not bound inside of static block + } + static { + (class await { + }); // legal, 'await' in class expression name not bound inside of static block + } + static { + (function () { return await; }); // legal, 'await' is inside of a new function boundary + } + static { + (() => await); // legal, 'await' is inside of a new function boundary + } + static { + class E { + constructor() { await; } + method() { await; } + get accessor() { + await; + return 1; + } + set accessor(v) { + await; + } + propLambda = () => { await; }; + propFunc = function () { await; }; + } + } + static { + class S { + static method() { await; } + static get accessor() { + await; + return 1; + } + static set accessor(v) { + await; + } + static propLambda = () => { await; }; + static propFunc = function () { await; }; + } + } +} diff --git a/tests/baselines/reference/classStaticBlock22.symbols b/tests/baselines/reference/classStaticBlock22.symbols new file mode 100644 index 0000000000000..9f78f245322f3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.symbols @@ -0,0 +1,130 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts === +let await: "any"; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + +class C { +>C : Symbol(C, Decl(classStaticBlock22.ts, 0, 17)) + + static { + let await: any; // illegal, cannot declare a new binding for await +>await : Symbol(await, Decl(classStaticBlock22.ts, 3, 7)) + } + static { + let { await } = {} as any; // illegal, cannot declare a new binding for await +>await : Symbol(await, Decl(classStaticBlock22.ts, 6, 9)) + } + static { + let { await: other } = {} as any; // legal +>other : Symbol(other, Decl(classStaticBlock22.ts, 9, 9)) + } + static { + let await; // illegal, cannot declare a new binding for await +>await : Symbol(await, Decl(classStaticBlock22.ts, 12, 7)) + } + static { + function await() { }; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 14, 10)) + } + static { + class await { }; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 17, 10)) + } + + static { + class D { +>D : Symbol(D, Decl(classStaticBlock22.ts, 21, 10)) + + await = 1; // legal +>await : Symbol(D.await, Decl(classStaticBlock22.ts, 22, 13)) + + x = await; // legal (initializers have an implicit function boundary) +>x : Symbol(D.x, Decl(classStaticBlock22.ts, 23, 16)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + }; + } + static { + (function await() { }); // legal, 'await' in function expression name not bound inside of static block +>await : Symbol(await, Decl(classStaticBlock22.ts, 28, 5)) + } + static { + (class await { }); // legal, 'await' in class expression name not bound inside of static block +>await : Symbol(await, Decl(classStaticBlock22.ts, 31, 5)) + } + static { + (function () { return await; }); // legal, 'await' is inside of a new function boundary +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + static { + (() => await); // legal, 'await' is inside of a new function boundary +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + + static { + class E { +>E : Symbol(E, Decl(classStaticBlock22.ts, 40, 10)) + + constructor() { await; } +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + method() { await; } +>method : Symbol(E.method, Decl(classStaticBlock22.ts, 42, 30)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + get accessor() { +>accessor : Symbol(E.accessor, Decl(classStaticBlock22.ts, 43, 25), Decl(classStaticBlock22.ts, 47, 7)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + return 1; + } + set accessor(v: any) { +>accessor : Symbol(E.accessor, Decl(classStaticBlock22.ts, 43, 25), Decl(classStaticBlock22.ts, 47, 7)) +>v : Symbol(v, Decl(classStaticBlock22.ts, 48, 19)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + propLambda = () => { await; } +>propLambda : Symbol(E.propLambda, Decl(classStaticBlock22.ts, 50, 7)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + propFunc = function () { await; } +>propFunc : Symbol(E.propFunc, Decl(classStaticBlock22.ts, 51, 35)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + } + static { + class S { +>S : Symbol(S, Decl(classStaticBlock22.ts, 55, 10)) + + static method() { await; } +>method : Symbol(S.method, Decl(classStaticBlock22.ts, 56, 13)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + static get accessor() { +>accessor : Symbol(S.accessor, Decl(classStaticBlock22.ts, 57, 32), Decl(classStaticBlock22.ts, 61, 7)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + return 1; + } + static set accessor(v: any) { +>accessor : Symbol(S.accessor, Decl(classStaticBlock22.ts, 57, 32), Decl(classStaticBlock22.ts, 61, 7)) +>v : Symbol(v, Decl(classStaticBlock22.ts, 62, 26)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + static propLambda = () => { await; } +>propLambda : Symbol(S.propLambda, Decl(classStaticBlock22.ts, 64, 7)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + static propFunc = function () { await; } +>propFunc : Symbol(S.propFunc, Decl(classStaticBlock22.ts, 65, 42)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + } +} diff --git a/tests/baselines/reference/classStaticBlock22.types b/tests/baselines/reference/classStaticBlock22.types new file mode 100644 index 0000000000000..8334f1b584217 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.types @@ -0,0 +1,150 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts === +let await: "any"; +>await : "any" + +class C { +>C : C + + static { + let await: any; // illegal, cannot declare a new binding for await +>await : any + } + static { + let { await } = {} as any; // illegal, cannot declare a new binding for await +>await : any +>{} as any : any +>{} : {} + } + static { + let { await: other } = {} as any; // legal +>await : any +>other : any +>{} as any : any +>{} : {} + } + static { + let await; // illegal, cannot declare a new binding for await +>await : any + } + static { + function await() { }; // illegal +>await : () => void + } + static { + class await { }; // illegal +>await : await + } + + static { + class D { +>D : D + + await = 1; // legal +>await : number +>1 : 1 + + x = await; // legal (initializers have an implicit function boundary) +>x : "any" +>await : "any" + + }; + } + static { + (function await() { }); // legal, 'await' in function expression name not bound inside of static block +>(function await() { }) : () => void +>function await() { } : () => void +>await : () => void + } + static { + (class await { }); // legal, 'await' in class expression name not bound inside of static block +>(class await { }) : typeof await +>class await { } : typeof await +>await : typeof await + } + static { + (function () { return await; }); // legal, 'await' is inside of a new function boundary +>(function () { return await; }) : () => "any" +>function () { return await; } : () => "any" +>await : "any" + } + static { + (() => await); // legal, 'await' is inside of a new function boundary +>(() => await) : () => "any" +>() => await : () => "any" +>await : "any" + } + + static { + class E { +>E : E + + constructor() { await; } +>await : "any" + + method() { await; } +>method : () => void +>await : "any" + + get accessor() { +>accessor : any + + await; +>await : "any" + + return 1; +>1 : 1 + } + set accessor(v: any) { +>accessor : any +>v : any + + await; +>await : "any" + } + propLambda = () => { await; } +>propLambda : () => void +>() => { await; } : () => void +>await : "any" + + propFunc = function () { await; } +>propFunc : () => void +>function () { await; } : () => void +>await : "any" + } + } + static { + class S { +>S : S + + static method() { await; } +>method : () => void +>await : "any" + + static get accessor() { +>accessor : any + + await; +>await : "any" + + return 1; +>1 : 1 + } + static set accessor(v: any) { +>accessor : any +>v : any + + await; +>await : "any" + } + static propLambda = () => { await; } +>propLambda : () => void +>() => { await; } : () => void +>await : "any" + + static propFunc = function () { await; } +>propFunc : () => void +>function () { await; } : () => void +>await : "any" + } + } +} diff --git a/tests/baselines/reference/classStaticBlock23.errors.txt b/tests/baselines/reference/classStaticBlock23.errors.txt new file mode 100644 index 0000000000000..eee258b4a5b12 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock23.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(5,9): error TS18038: 'For await' loops cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(14,11): error TS18038: 'For await' loops cannot be used inside a class static block. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts (2 errors) ==== + const nums = [1, 2, 3].map(n => Promise.resolve(n)) + + class C { + static { + for await (const nn of nums) { + ~~~~~ +!!! error TS18038: 'For await' loops cannot be used inside a class static block. + console.log(nn) + } + } + } + + async function foo () { + class C { + static { + for await (const nn of nums) { + ~~~~~ +!!! error TS18038: 'For await' loops cannot be used inside a class static block. + console.log(nn) + } + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock23.js b/tests/baselines/reference/classStaticBlock23.js new file mode 100644 index 0000000000000..ae72a288a2bab --- /dev/null +++ b/tests/baselines/reference/classStaticBlock23.js @@ -0,0 +1,39 @@ +//// [classStaticBlock23.ts] +const nums = [1, 2, 3].map(n => Promise.resolve(n)) + +class C { + static { + for await (const nn of nums) { + console.log(nn) + } + } +} + +async function foo () { + class C { + static { + for await (const nn of nums) { + console.log(nn) + } + } + } +} + +//// [classStaticBlock23.js] +const nums = [1, 2, 3].map(n => Promise.resolve(n)); +class C { + static { + for await (const nn of nums) { + console.log(nn); + } + } +} +async function foo() { + class C { + static { + for await (const nn of nums) { + console.log(nn); + } + } + } +} diff --git a/tests/baselines/reference/classStaticBlock23.symbols b/tests/baselines/reference/classStaticBlock23.symbols new file mode 100644 index 0000000000000..39771ac55fbab --- /dev/null +++ b/tests/baselines/reference/classStaticBlock23.symbols @@ -0,0 +1,48 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts === +const nums = [1, 2, 3].map(n => Promise.resolve(n)) +>nums : Symbol(nums, Decl(classStaticBlock23.ts, 0, 5)) +>[1, 2, 3].map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) +>n : Symbol(n, Decl(classStaticBlock23.ts, 0, 27)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>n : Symbol(n, Decl(classStaticBlock23.ts, 0, 27)) + +class C { +>C : Symbol(C, Decl(classStaticBlock23.ts, 0, 51)) + + static { + for await (const nn of nums) { +>nn : Symbol(nn, Decl(classStaticBlock23.ts, 4, 20)) +>nums : Symbol(nums, Decl(classStaticBlock23.ts, 0, 5)) + + console.log(nn) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>nn : Symbol(nn, Decl(classStaticBlock23.ts, 4, 20)) + } + } +} + +async function foo () { +>foo : Symbol(foo, Decl(classStaticBlock23.ts, 8, 1)) + + class C { +>C : Symbol(C, Decl(classStaticBlock23.ts, 10, 23)) + + static { + for await (const nn of nums) { +>nn : Symbol(nn, Decl(classStaticBlock23.ts, 13, 22)) +>nums : Symbol(nums, Decl(classStaticBlock23.ts, 0, 5)) + + console.log(nn) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>nn : Symbol(nn, Decl(classStaticBlock23.ts, 13, 22)) + } + } + } +} diff --git a/tests/baselines/reference/classStaticBlock23.types b/tests/baselines/reference/classStaticBlock23.types new file mode 100644 index 0000000000000..379a40f31c5d1 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock23.types @@ -0,0 +1,57 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts === +const nums = [1, 2, 3].map(n => Promise.resolve(n)) +>nums : Promise[] +>[1, 2, 3].map(n => Promise.resolve(n)) : Promise[] +>[1, 2, 3].map : (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>map : (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[] +>n => Promise.resolve(n) : (n: number) => Promise +>n : number +>Promise.resolve(n) : Promise +>Promise.resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>Promise : PromiseConstructor +>resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>n : number + +class C { +>C : C + + static { + for await (const nn of nums) { +>nn : number +>nums : Promise[] + + console.log(nn) +>console.log(nn) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>nn : number + } + } +} + +async function foo () { +>foo : () => Promise + + class C { +>C : C + + static { + for await (const nn of nums) { +>nn : number +>nums : Promise[] + + console.log(nn) +>console.log(nn) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>nn : number + } + } + } +} diff --git a/tests/baselines/reference/classStaticBlock24(module=amd).js b/tests/baselines/reference/classStaticBlock24(module=amd).js new file mode 100644 index 0000000000000..e3c7f932803c2 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=amd).js @@ -0,0 +1,24 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.C = void 0; + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + exports.C = C; + (function () { + C.x = 1; + })(); +}); diff --git a/tests/baselines/reference/classStaticBlock24(module=amd).symbols b/tests/baselines/reference/classStaticBlock24(module=amd).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=amd).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=amd).types b/tests/baselines/reference/classStaticBlock24(module=amd).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=amd).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=commonjs).js b/tests/baselines/reference/classStaticBlock24(module=commonjs).js new file mode 100644 index 0000000000000..196e0645e3cef --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=commonjs).js @@ -0,0 +1,22 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +"use strict"; +exports.__esModule = true; +exports.C = void 0; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +exports.C = C; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=commonjs).symbols b/tests/baselines/reference/classStaticBlock24(module=commonjs).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=commonjs).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=commonjs).types b/tests/baselines/reference/classStaticBlock24(module=commonjs).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=commonjs).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=es2015).js b/tests/baselines/reference/classStaticBlock24(module=es2015).js new file mode 100644 index 0000000000000..450e53df8a141 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2015).js @@ -0,0 +1,19 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +export { C }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=es2015).symbols b/tests/baselines/reference/classStaticBlock24(module=es2015).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2015).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=es2015).types b/tests/baselines/reference/classStaticBlock24(module=es2015).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2015).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=es2020).js b/tests/baselines/reference/classStaticBlock24(module=es2020).js new file mode 100644 index 0000000000000..450e53df8a141 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2020).js @@ -0,0 +1,19 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +export { C }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=es2020).symbols b/tests/baselines/reference/classStaticBlock24(module=es2020).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2020).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=es2020).types b/tests/baselines/reference/classStaticBlock24(module=es2020).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2020).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=esnext).js b/tests/baselines/reference/classStaticBlock24(module=esnext).js new file mode 100644 index 0000000000000..450e53df8a141 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=esnext).js @@ -0,0 +1,19 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +export { C }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=esnext).symbols b/tests/baselines/reference/classStaticBlock24(module=esnext).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=esnext).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=esnext).types b/tests/baselines/reference/classStaticBlock24(module=esnext).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=esnext).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=system).js b/tests/baselines/reference/classStaticBlock24(module=system).js new file mode 100644 index 0000000000000..61c0da67830a6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=system).js @@ -0,0 +1,29 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var C; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + C = /** @class */ (function () { + function C() { + } + return C; + }()); + exports_1("C", C); + (function () { + C.x = 1; + })(); + } + }; +}); diff --git a/tests/baselines/reference/classStaticBlock24(module=system).symbols b/tests/baselines/reference/classStaticBlock24(module=system).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=system).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=system).types b/tests/baselines/reference/classStaticBlock24(module=system).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=system).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=umd).js b/tests/baselines/reference/classStaticBlock24(module=umd).js new file mode 100644 index 0000000000000..d9a17e515ce0d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=umd).js @@ -0,0 +1,32 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.C = void 0; + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + exports.C = C; + (function () { + C.x = 1; + })(); +}); diff --git a/tests/baselines/reference/classStaticBlock24(module=umd).symbols b/tests/baselines/reference/classStaticBlock24(module=umd).symbols new file mode 100644 index 0000000000000..41b09da5f7732 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=umd).symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) + + static x: number; +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + + static { + C.x = 1; +>C.x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) +>C : Symbol(C, Decl(classStaticBlock24.ts, 0, 0)) +>x : Symbol(C.x, Decl(classStaticBlock24.ts, 0, 16)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock24(module=umd).types b/tests/baselines/reference/classStaticBlock24(module=umd).types new file mode 100644 index 0000000000000..15bf228fcc593 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=umd).types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts === +export class C { +>C : C + + static x: number; +>x : number + + static { + C.x = 1; +>C.x = 1 : 1 +>C.x : number +>C : typeof C +>x : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/classStaticBlock25.js b/tests/baselines/reference/classStaticBlock25.js new file mode 100644 index 0000000000000..79864030028c1 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock25.js @@ -0,0 +1,44 @@ +//// [classStaticBlock25.ts] +const a = 1; +const b = 2; + +class C { + static { + const a = 11; + + a; + b; + } + + static { + const a = 11; + + a; + b; + } +} + + +//// [classStaticBlock25.js] +const a = 1; +const b = 2; +class C { + static { + const a = 11; + a; + b; + } + static { + const a = 11; + a; + b; + } +} +//# sourceMappingURL=classStaticBlock25.js.map + +//// [classStaticBlock25.d.ts] +declare const a = 1; +declare const b = 2; +declare class C { +} +//# sourceMappingURL=classStaticBlock25.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock25.js.map b/tests/baselines/reference/classStaticBlock25.js.map new file mode 100644 index 0000000000000..f3bccac8cb86f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock25.js.map @@ -0,0 +1,7 @@ +//// [classStaticBlock25.js.map] +{"version":3,"file":"classStaticBlock25.js","sourceRoot":"","sources":["classStaticBlock25.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,GAAG,CAAC,CAAC;AACZ,MAAM,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,CAAC;IACH;QACI,MAAM,CAAC,GAAG,EAAE,CAAC;QAEb,CAAC,CAAC;QACF,CAAC,CAAC;IACN,CAAC;IAED;QACI,MAAM,CAAC,GAAG,EAAE,CAAC;QAEb,CAAC,CAAC;QACF,CAAC,CAAC;IACN,CAAC;CACJ"} +//// https://sokra.github.io/source-map-visualization#base64,Y29uc3QgYSA9IDE7DQpjb25zdCBiID0gMjsNCmNsYXNzIEMgew0KICAgIHN0YXRpYyB7DQogICAgICAgIGNvbnN0IGEgPSAxMTsNCiAgICAgICAgYTsNCiAgICAgICAgYjsNCiAgICB9DQogICAgc3RhdGljIHsNCiAgICAgICAgY29uc3QgYSA9IDExOw0KICAgICAgICBhOw0KICAgICAgICBiOw0KICAgIH0NCn0NCi8vIyBzb3VyY2VNYXBwaW5nVVJMPWNsYXNzU3RhdGljQmxvY2syNS5qcy5tYXA=,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3NTdGF0aWNCbG9jazI1LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiY2xhc3NTdGF0aWNCbG9jazI1LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNaLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUVaLE1BQU0sQ0FBQztJQUNIO1FBQ0ksTUFBTSxDQUFDLEdBQUcsRUFBRSxDQUFDO1FBRWIsQ0FBQyxDQUFDO1FBQ0YsQ0FBQyxDQUFDO0lBQ04sQ0FBQztJQUVEO1FBQ0ksTUFBTSxDQUFDLEdBQUcsRUFBRSxDQUFDO1FBRWIsQ0FBQyxDQUFDO1FBQ0YsQ0FBQyxDQUFDO0lBQ04sQ0FBQztDQUNKIn0=,Y29uc3QgYSA9IDE7CmNvbnN0IGIgPSAyOwoKY2xhc3MgQyB7CiAgICBzdGF0aWMgewogICAgICAgIGNvbnN0IGEgPSAxMTsKCiAgICAgICAgYTsKICAgICAgICBiOwogICAgfQoKICAgIHN0YXRpYyB7CiAgICAgICAgY29uc3QgYSA9IDExOwoKICAgICAgICBhOwogICAgICAgIGI7CiAgICB9Cn0K + +//// [classStaticBlock25.d.ts.map] +{"version":3,"file":"classStaticBlock25.d.ts","sourceRoot":"","sources":["classStaticBlock25.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,CAAC,IAAI,CAAC;AACZ,QAAA,MAAM,CAAC,IAAI,CAAC;AAEZ,cAAM,CAAC;CAcN"} +//// https://sokra.github.io/source-map-visualization#base64,ZGVjbGFyZSBjb25zdCBhID0gMTsNCmRlY2xhcmUgY29uc3QgYiA9IDI7DQpkZWNsYXJlIGNsYXNzIEMgew0KfQ0KLy8jIHNvdXJjZU1hcHBpbmdVUkw9Y2xhc3NTdGF0aWNCbG9jazI1LmQudHMubWFw,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3NTdGF0aWNCbG9jazI1LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJjbGFzc1N0YXRpY0Jsb2NrMjUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsUUFBQSxNQUFNLENBQUMsSUFBSSxDQUFDO0FBQ1osUUFBQSxNQUFNLENBQUMsSUFBSSxDQUFDO0FBRVosY0FBTSxDQUFDO0NBY04ifQ==,Y29uc3QgYSA9IDE7CmNvbnN0IGIgPSAyOwoKY2xhc3MgQyB7CiAgICBzdGF0aWMgewogICAgICAgIGNvbnN0IGEgPSAxMTsKCiAgICAgICAgYTsKICAgICAgICBiOwogICAgfQoKICAgIHN0YXRpYyB7CiAgICAgICAgY29uc3QgYSA9IDExOwoKICAgICAgICBhOwogICAgICAgIGI7CiAgICB9Cn0K diff --git a/tests/baselines/reference/classStaticBlock25.sourcemap.txt b/tests/baselines/reference/classStaticBlock25.sourcemap.txt new file mode 100644 index 0000000000000..91f7b7913f116 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock25.sourcemap.txt @@ -0,0 +1,287 @@ +=================================================================== +JsFile: classStaticBlock25.js +mapUrl: classStaticBlock25.js.map +sourceRoot: +sources: classStaticBlock25.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.js +sourceFile:classStaticBlock25.ts +------------------------------------------------------------------- +>>>const a = 1; +1 > +2 >^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^-> +1 > +2 >const +3 > a +4 > = +5 > 1 +6 > ; +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 7) Source(1, 7) + SourceIndex(0) +3 >Emitted(1, 8) Source(1, 8) + SourceIndex(0) +4 >Emitted(1, 11) Source(1, 11) + SourceIndex(0) +5 >Emitted(1, 12) Source(1, 12) + SourceIndex(0) +6 >Emitted(1, 13) Source(1, 13) + SourceIndex(0) +--- +>>>const b = 2; +1-> +2 >^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +1-> + > +2 >const +3 > b +4 > = +5 > 2 +6 > ; +1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(2, 7) Source(2, 7) + SourceIndex(0) +3 >Emitted(2, 8) Source(2, 8) + SourceIndex(0) +4 >Emitted(2, 11) Source(2, 11) + SourceIndex(0) +5 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) +6 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) +--- +>>>class C { +1 > +2 >^^^^^^ +3 > ^ +4 > ^^^^^^-> +1 > + > + > +2 >class +3 > C +1 >Emitted(3, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(3, 7) Source(4, 7) + SourceIndex(0) +3 >Emitted(3, 8) Source(4, 8) + SourceIndex(0) +--- +>>> static { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^-> +1-> { + > +1->Emitted(4, 5) Source(5, 5) + SourceIndex(0) +--- +>>> const a = 11; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^ +5 > ^^ +6 > ^ +1->static { + > +2 > const +3 > a +4 > = +5 > 11 +6 > ; +1->Emitted(5, 9) Source(6, 9) + SourceIndex(0) +2 >Emitted(5, 15) Source(6, 15) + SourceIndex(0) +3 >Emitted(5, 16) Source(6, 16) + SourceIndex(0) +4 >Emitted(5, 19) Source(6, 19) + SourceIndex(0) +5 >Emitted(5, 21) Source(6, 21) + SourceIndex(0) +6 >Emitted(5, 22) Source(6, 22) + SourceIndex(0) +--- +>>> a; +1 >^^^^^^^^ +2 > ^ +3 > ^ +4 > ^-> +1 > + > + > +2 > a +3 > ; +1 >Emitted(6, 9) Source(8, 9) + SourceIndex(0) +2 >Emitted(6, 10) Source(8, 10) + SourceIndex(0) +3 >Emitted(6, 11) Source(8, 11) + SourceIndex(0) +--- +>>> b; +1->^^^^^^^^ +2 > ^ +3 > ^ +1-> + > +2 > b +3 > ; +1->Emitted(7, 9) Source(9, 9) + SourceIndex(0) +2 >Emitted(7, 10) Source(9, 10) + SourceIndex(0) +3 >Emitted(7, 11) Source(9, 11) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(8, 5) Source(10, 5) + SourceIndex(0) +2 >Emitted(8, 6) Source(10, 6) + SourceIndex(0) +--- +>>> static { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^-> +1-> + > + > +1->Emitted(9, 5) Source(12, 5) + SourceIndex(0) +--- +>>> const a = 11; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^ +5 > ^^ +6 > ^ +1->static { + > +2 > const +3 > a +4 > = +5 > 11 +6 > ; +1->Emitted(10, 9) Source(13, 9) + SourceIndex(0) +2 >Emitted(10, 15) Source(13, 15) + SourceIndex(0) +3 >Emitted(10, 16) Source(13, 16) + SourceIndex(0) +4 >Emitted(10, 19) Source(13, 19) + SourceIndex(0) +5 >Emitted(10, 21) Source(13, 21) + SourceIndex(0) +6 >Emitted(10, 22) Source(13, 22) + SourceIndex(0) +--- +>>> a; +1 >^^^^^^^^ +2 > ^ +3 > ^ +4 > ^-> +1 > + > + > +2 > a +3 > ; +1 >Emitted(11, 9) Source(15, 9) + SourceIndex(0) +2 >Emitted(11, 10) Source(15, 10) + SourceIndex(0) +3 >Emitted(11, 11) Source(15, 11) + SourceIndex(0) +--- +>>> b; +1->^^^^^^^^ +2 > ^ +3 > ^ +1-> + > +2 > b +3 > ; +1->Emitted(12, 9) Source(16, 9) + SourceIndex(0) +2 >Emitted(12, 10) Source(16, 10) + SourceIndex(0) +3 >Emitted(12, 11) Source(16, 11) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(13, 5) Source(17, 5) + SourceIndex(0) +2 >Emitted(13, 6) Source(17, 6) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +1 >Emitted(14, 2) Source(18, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=classStaticBlock25.js.map=================================================================== +JsFile: classStaticBlock25.d.ts +mapUrl: classStaticBlock25.d.ts.map +sourceRoot: +sources: classStaticBlock25.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.d.ts +sourceFile:classStaticBlock25.ts +------------------------------------------------------------------- +>>>declare const a = 1; +1 > +2 >^^^^^^^^ +3 > ^^^^^^ +4 > ^ +5 > ^^^^ +6 > ^ +7 > ^-> +1 > +2 > +3 > const +4 > a +5 > = 1 +6 > ; +1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(1, 9) Source(1, 1) + SourceIndex(0) +3 >Emitted(1, 15) Source(1, 7) + SourceIndex(0) +4 >Emitted(1, 16) Source(1, 8) + SourceIndex(0) +5 >Emitted(1, 20) Source(1, 12) + SourceIndex(0) +6 >Emitted(1, 21) Source(1, 13) + SourceIndex(0) +--- +>>>declare const b = 2; +1-> +2 >^^^^^^^^ +3 > ^^^^^^ +4 > ^ +5 > ^^^^ +6 > ^ +1-> + > +2 > +3 > const +4 > b +5 > = 2 +6 > ; +1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(2, 9) Source(2, 1) + SourceIndex(0) +3 >Emitted(2, 15) Source(2, 7) + SourceIndex(0) +4 >Emitted(2, 16) Source(2, 8) + SourceIndex(0) +5 >Emitted(2, 20) Source(2, 12) + SourceIndex(0) +6 >Emitted(2, 21) Source(2, 13) + SourceIndex(0) +--- +>>>declare class C { +1 > +2 >^^^^^^^^^^^^^^ +3 > ^ +1 > + > + > +2 >class +3 > C +1 >Emitted(3, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(3, 15) Source(4, 7) + SourceIndex(0) +3 >Emitted(3, 16) Source(4, 8) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > { + > static { + > const a = 11; + > + > a; + > b; + > } + > + > static { + > const a = 11; + > + > a; + > b; + > } + >} +1 >Emitted(4, 2) Source(18, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=classStaticBlock25.d.ts.map \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock25.symbols b/tests/baselines/reference/classStaticBlock25.symbols new file mode 100644 index 0000000000000..034fa041ed6d4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock25.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.ts === +const a = 1; +>a : Symbol(a, Decl(classStaticBlock25.ts, 0, 5)) + +const b = 2; +>b : Symbol(b, Decl(classStaticBlock25.ts, 1, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock25.ts, 1, 12)) + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock25.ts, 5, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock25.ts, 5, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock25.ts, 1, 5)) + } + + static { + const a = 11; +>a : Symbol(a, Decl(classStaticBlock25.ts, 12, 13)) + + a; +>a : Symbol(a, Decl(classStaticBlock25.ts, 12, 13)) + + b; +>b : Symbol(b, Decl(classStaticBlock25.ts, 1, 5)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock25.types b/tests/baselines/reference/classStaticBlock25.types new file mode 100644 index 0000000000000..dd78af7dda7e6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock25.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.ts === +const a = 1; +>a : 1 +>1 : 1 + +const b = 2; +>b : 2 +>2 : 2 + +class C { +>C : C + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } + + static { + const a = 11; +>a : 11 +>11 : 11 + + a; +>a : 11 + + b; +>b : 2 + } +} + diff --git a/tests/baselines/reference/classStaticBlock26.errors.txt b/tests/baselines/reference/classStaticBlock26.errors.txt new file mode 100644 index 0000000000000..3c5eb52fb8f34 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.errors.txt @@ -0,0 +1,86 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(3,9): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(3,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(6,9): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(9,13): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(9,18): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(13,14): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(13,19): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(17,18): error TS1005: ':' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(20,9): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(20,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(21,15): error TS1003: Identifier expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(21,15): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(21,20): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(25,21): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(25,26): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(25,28): error TS1005: ';' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(26,21): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(26,27): error TS1109: Expression expected. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts (18 errors) ==== + class C { + static { + await; // illegal + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + } + static { + await (1); // illegal + ~~~~~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + } + static { + ({ [await]: 1 }); // illegal + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + } + static { + class D { + [await] = 1; // illegal (computed property names are evaluated outside of a class body + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + }; + } + static { + ({ await }); // illegal short-hand property reference + ~ +!!! error TS1005: ':' expected. + } + static { + await: // illegal, 'await' cannot be used as a label + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + break await; // illegal, 'await' cannot be used as a label + ~~~~~ +!!! error TS1003: Identifier expected. + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + } + static { + function f(await) { } + const ff = (await) => { } + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + ~~ +!!! error TS1005: ';' expected. + const fff = await => { } + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~~ +!!! error TS1109: Expression expected. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock26.js b/tests/baselines/reference/classStaticBlock26.js new file mode 100644 index 0000000000000..ababa6abf24ac --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.js @@ -0,0 +1,64 @@ +//// [classStaticBlock26.ts] +class C { + static { + await; // illegal + } + static { + await (1); // illegal + } + static { + ({ [await]: 1 }); // illegal + } + static { + class D { + [await] = 1; // illegal (computed property names are evaluated outside of a class body + }; + } + static { + ({ await }); // illegal short-hand property reference + } + static { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } + static { + function f(await) { } + const ff = (await) => { } + const fff = await => { } + } +} + + +//// [classStaticBlock26.js] +class C { + static { + await ; // illegal + } + static { + await (1); // illegal + } + static { + ({ [await ]: 1 }); // illegal + } + static { + class D { + [await ] = 1; // illegal (computed property names are evaluated outside of a class body + } + ; + } + static { + ({ await: }); // illegal short-hand property reference + } + static { + await ; + break ; + await ; // illegal, 'await' cannot be used as a label + } + static { + function f(await) { } + const ff = (await ); + { } + const fff = await ; + { } + } +} diff --git a/tests/baselines/reference/classStaticBlock26.symbols b/tests/baselines/reference/classStaticBlock26.symbols new file mode 100644 index 0000000000000..2d3b2717ba213 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.symbols @@ -0,0 +1,44 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock26.ts, 0, 0)) + + static { + await; // illegal + } + static { + await (1); // illegal + } + static { + ({ [await]: 1 }); // illegal +>[await] : Symbol([await], Decl(classStaticBlock26.ts, 8, 10)) + } + static { + class D { +>D : Symbol(D, Decl(classStaticBlock26.ts, 10, 12)) + + [await] = 1; // illegal (computed property names are evaluated outside of a class body +>[await] : Symbol(D[await], Decl(classStaticBlock26.ts, 11, 17)) + + }; + } + static { + ({ await }); // illegal short-hand property reference +>await : Symbol(await, Decl(classStaticBlock26.ts, 16, 10)) + } + static { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } + static { + function f(await) { } +>f : Symbol(f, Decl(classStaticBlock26.ts, 22, 12)) +>await : Symbol(await, Decl(classStaticBlock26.ts, 23, 19)) + + const ff = (await) => { } +>ff : Symbol(ff, Decl(classStaticBlock26.ts, 24, 13)) + + const fff = await => { } +>fff : Symbol(fff, Decl(classStaticBlock26.ts, 25, 13)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock26.types b/tests/baselines/reference/classStaticBlock26.types new file mode 100644 index 0000000000000..0922330a47533 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.types @@ -0,0 +1,71 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts === +class C { +>C : C + + static { + await; // illegal +>await : any +> : any + } + static { + await (1); // illegal +>await (1) : 1 +>(1) : 1 +>1 : 1 + } + static { + ({ [await]: 1 }); // illegal +>({ [await]: 1 }) : { [x: number]: number; } +>{ [await]: 1 } : { [x: number]: number; } +>[await] : number +>await : any +> : any +>1 : 1 + } + static { + class D { +>D : D + + [await] = 1; // illegal (computed property names are evaluated outside of a class body +>[await] : number +>await : any +> : any +>1 : 1 + + }; + } + static { + ({ await }); // illegal short-hand property reference +>({ await }) : { await: any; } +>{ await } : { await: any; } +>await : any +> : any + } + static { + await: // illegal, 'await' cannot be used as a label +>await : any +> : any + + break await; // illegal, 'await' cannot be used as a label +> : any +>await : any +> : any + } + static { + function f(await) { } +>f : (await: any) => void +>await : any + + const ff = (await) => { } +>ff : any +>(await) : any +>await : any +> : any + + const fff = await => { } +>fff : any +>await : any +> : any + } +} + diff --git a/tests/baselines/reference/classStaticBlock3.errors.txt b/tests/baselines/reference/classStaticBlock3.errors.txt new file mode 100644 index 0000000000000..bf01354e1405f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts(7,29): error TS2729: Property 'f2' is used before its initialization. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts(7,35): error TS2729: Property 'f3' is used before its initialization. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts(13,35): error TS2729: Property 'f3' is used before its initialization. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts (3 errors) ==== + const a = 1; + + class C { + static f1 = 1; + + static { + console.log(C.f1, C.f2, C.f3) + ~~ +!!! error TS2729: Property 'f2' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts:10:12: 'f2' is declared here. + ~~ +!!! error TS2729: Property 'f3' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts:16:12: 'f3' is declared here. + } + + static f2 = 2; + + static { + console.log(C.f1, C.f2, C.f3) + ~~ +!!! error TS2729: Property 'f3' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts:16:12: 'f3' is declared here. + } + + static f3 = 3; + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock3.js b/tests/baselines/reference/classStaticBlock3.js new file mode 100644 index 0000000000000..99fe38cf28e28 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3.js @@ -0,0 +1,33 @@ +//// [classStaticBlock3.ts] +const a = 1; + +class C { + static f1 = 1; + + static { + console.log(C.f1, C.f2, C.f3) + } + + static f2 = 2; + + static { + console.log(C.f1, C.f2, C.f3) + } + + static f3 = 3; +} + + +//// [classStaticBlock3.js] +const a = 1; +class C { + static f1 = 1; + static { + console.log(C.f1, C.f2, C.f3); + } + static f2 = 2; + static { + console.log(C.f1, C.f2, C.f3); + } + static f3 = 3; +} diff --git a/tests/baselines/reference/classStaticBlock3.symbols b/tests/baselines/reference/classStaticBlock3.symbols new file mode 100644 index 0000000000000..758fa0790609a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3.symbols @@ -0,0 +1,49 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts === +const a = 1; +>a : Symbol(a, Decl(classStaticBlock3.ts, 0, 5)) + +class C { +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) + + static f1 = 1; +>f1 : Symbol(C.f1, Decl(classStaticBlock3.ts, 2, 9)) + + static { + console.log(C.f1, C.f2, C.f3) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.f1 : Symbol(C.f1, Decl(classStaticBlock3.ts, 2, 9)) +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) +>f1 : Symbol(C.f1, Decl(classStaticBlock3.ts, 2, 9)) +>C.f2 : Symbol(C.f2, Decl(classStaticBlock3.ts, 7, 5)) +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) +>f2 : Symbol(C.f2, Decl(classStaticBlock3.ts, 7, 5)) +>C.f3 : Symbol(C.f3, Decl(classStaticBlock3.ts, 13, 5)) +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) +>f3 : Symbol(C.f3, Decl(classStaticBlock3.ts, 13, 5)) + } + + static f2 = 2; +>f2 : Symbol(C.f2, Decl(classStaticBlock3.ts, 7, 5)) + + static { + console.log(C.f1, C.f2, C.f3) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.f1 : Symbol(C.f1, Decl(classStaticBlock3.ts, 2, 9)) +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) +>f1 : Symbol(C.f1, Decl(classStaticBlock3.ts, 2, 9)) +>C.f2 : Symbol(C.f2, Decl(classStaticBlock3.ts, 7, 5)) +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) +>f2 : Symbol(C.f2, Decl(classStaticBlock3.ts, 7, 5)) +>C.f3 : Symbol(C.f3, Decl(classStaticBlock3.ts, 13, 5)) +>C : Symbol(C, Decl(classStaticBlock3.ts, 0, 12)) +>f3 : Symbol(C.f3, Decl(classStaticBlock3.ts, 13, 5)) + } + + static f3 = 3; +>f3 : Symbol(C.f3, Decl(classStaticBlock3.ts, 13, 5)) +} + diff --git a/tests/baselines/reference/classStaticBlock3.types b/tests/baselines/reference/classStaticBlock3.types new file mode 100644 index 0000000000000..d5705a72e8775 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3.types @@ -0,0 +1,55 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts === +const a = 1; +>a : 1 +>1 : 1 + +class C { +>C : C + + static f1 = 1; +>f1 : number +>1 : 1 + + static { + console.log(C.f1, C.f2, C.f3) +>console.log(C.f1, C.f2, C.f3) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.f1 : number +>C : typeof C +>f1 : number +>C.f2 : number +>C : typeof C +>f2 : number +>C.f3 : number +>C : typeof C +>f3 : number + } + + static f2 = 2; +>f2 : number +>2 : 2 + + static { + console.log(C.f1, C.f2, C.f3) +>console.log(C.f1, C.f2, C.f3) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.f1 : number +>C : typeof C +>f1 : number +>C.f2 : number +>C : typeof C +>f2 : number +>C.f3 : number +>C : typeof C +>f3 : number + } + + static f3 = 3; +>f3 : number +>3 : 3 +} + diff --git a/tests/baselines/reference/classStaticBlock4.errors.txt b/tests/baselines/reference/classStaticBlock4.errors.txt new file mode 100644 index 0000000000000..4bd2b377e0b97 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.errors.txt @@ -0,0 +1,32 @@ +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) ==== + 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. + C.s2; + ~~ +!!! error TS2729: Property 's2' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts:12:12: 's2' is declared here. + } + + static s2 = 2; + static ss2 = this.s1; + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4.js b/tests/baselines/reference/classStaticBlock4.js new file mode 100644 index 0000000000000..b8821bc0f36c4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.js @@ -0,0 +1,29 @@ +//// [classStaticBlock4.ts] +class C { + static s1 = 1; + + static { + this.s1; + C.s1; + + this.s2; + C.s2; + } + + static s2 = 2; + static ss2 = this.s1; +} + + +//// [classStaticBlock4.js] +class C { + static s1 = 1; + static { + this.s1; + C.s1; + this.s2; + C.s2; + } + static s2 = 2; + static ss2 = this.s1; +} diff --git a/tests/baselines/reference/classStaticBlock4.symbols b/tests/baselines/reference/classStaticBlock4.symbols new file mode 100644 index 0000000000000..fd412244fbe0e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + static s1 = 1; +>s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) + + static { + this.s1; +>this.s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) +>this : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) +>s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) + + C.s1; +>C.s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) +>C : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) +>s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) + + this.s2; +>this.s2 : Symbol(C.s2, Decl(classStaticBlock4.ts, 9, 5)) +>this : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) +>s2 : Symbol(C.s2, Decl(classStaticBlock4.ts, 9, 5)) + + C.s2; +>C.s2 : Symbol(C.s2, Decl(classStaticBlock4.ts, 9, 5)) +>C : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) +>s2 : Symbol(C.s2, Decl(classStaticBlock4.ts, 9, 5)) + } + + static s2 = 2; +>s2 : Symbol(C.s2, Decl(classStaticBlock4.ts, 9, 5)) + + static ss2 = this.s1; +>ss2 : Symbol(C.ss2, Decl(classStaticBlock4.ts, 11, 18)) +>this.s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) +>this : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) +>s1 : Symbol(C.s1, Decl(classStaticBlock4.ts, 0, 9)) +} + diff --git a/tests/baselines/reference/classStaticBlock4.types b/tests/baselines/reference/classStaticBlock4.types new file mode 100644 index 0000000000000..db068a795397c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts === +class C { +>C : C + + static s1 = 1; +>s1 : number +>1 : 1 + + static { + this.s1; +>this.s1 : number +>this : typeof C +>s1 : number + + C.s1; +>C.s1 : number +>C : typeof C +>s1 : number + + this.s2; +>this.s2 : number +>this : typeof C +>s2 : number + + C.s2; +>C.s2 : number +>C : typeof C +>s2 : number + } + + static s2 = 2; +>s2 : number +>2 : 2 + + static ss2 = this.s1; +>ss2 : number +>this.s1 : number +>this : typeof C +>s1 : number +} + diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt new file mode 100644 index 0000000000000..71227c6036a79 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt @@ -0,0 +1,31 @@ +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 new file mode 100644 index 0000000000000..557bf8b05b4ec --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).js @@ -0,0 +1,32 @@ +//// [classStaticBlock5.ts] +class B { + static a = 1; + static b = 2; +} + +class C extends B { + static b = 3; + static c = super.a + + static { + this.b; + super.b; + super.a; + } +} + + +//// [classStaticBlock5.js] +class B { +} +B.a = 1; +B.b = 2; +class C extends B { +} +C.b = 3; +C.c = super.a; +(() => { + this.b; + super.b; + super.a; +})(); diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).symbols b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols new file mode 100644 index 0000000000000..1e2334d1dff10 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts === +class B { +>B : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) + + static a = 1; +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) + + static b = 2; +>b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) +} + +class C extends B { +>C : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) +>B : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) + + static b = 3; +>b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) + + static c = super.a +>c : Symbol(C.c, Decl(classStaticBlock5.ts, 6, 17)) + + static { + this.b; +>this.b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) +>this : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) +>b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) + + super.b; + super.a; + } +} + diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).types b/tests/baselines/reference/classStaticBlock5(target=es2015).types new file mode 100644 index 0000000000000..beb56840bfc1c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts === +class B { +>B : B + + static a = 1; +>a : number +>1 : 1 + + static b = 2; +>b : number +>2 : 2 +} + +class C extends B { +>C : C +>B : B + + static b = 3; +>b : number +>3 : 3 + + static c = super.a +>c : any +>super.a : any +>super : any +>a : any + + static { + this.b; +>this.b : number +>this : typeof C +>b : number + + super.b; +>super.b : any +>super : any +>b : any + + super.a; +>super.a : any +>super : any +>a : any + } +} + diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt new file mode 100644 index 0000000000000..71227c6036a79 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt @@ -0,0 +1,31 @@ +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=es5).js b/tests/baselines/reference/classStaticBlock5(target=es5).js new file mode 100644 index 0000000000000..0b26d0f4dcd1e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es5).js @@ -0,0 +1,56 @@ +//// [classStaticBlock5.ts] +class B { + static a = 1; + static b = 2; +} + +class C extends B { + static b = 3; + static c = super.a + + static { + this.b; + super.b; + super.a; + } +} + + +//// [classStaticBlock5.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 _this = this; +var B = /** @class */ (function () { + function B() { + } + B.a = 1; + B.b = 2; + return B; +}()); +var C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + C.b = 3; + C.c = _super.a; + (function () { + _this.b; + _super.b; + _super.a; + })(); + return C; +}(B)); diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).symbols b/tests/baselines/reference/classStaticBlock5(target=es5).symbols new file mode 100644 index 0000000000000..1e2334d1dff10 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es5).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts === +class B { +>B : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) + + static a = 1; +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) + + static b = 2; +>b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) +} + +class C extends B { +>C : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) +>B : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) + + static b = 3; +>b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) + + static c = super.a +>c : Symbol(C.c, Decl(classStaticBlock5.ts, 6, 17)) + + static { + this.b; +>this.b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) +>this : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) +>b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) + + super.b; + super.a; + } +} + diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).types b/tests/baselines/reference/classStaticBlock5(target=es5).types new file mode 100644 index 0000000000000..beb56840bfc1c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es5).types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts === +class B { +>B : B + + static a = 1; +>a : number +>1 : 1 + + static b = 2; +>b : number +>2 : 2 +} + +class C extends B { +>C : C +>B : B + + static b = 3; +>b : number +>3 : 3 + + static c = super.a +>c : any +>super.a : any +>super : any +>a : any + + static { + this.b; +>this.b : number +>this : typeof C +>b : number + + super.b; +>super.b : any +>super : any +>b : any + + super.a; +>super.a : any +>super : any +>a : any + } +} + diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt new file mode 100644 index 0000000000000..71227c6036a79 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt @@ -0,0 +1,31 @@ +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).js b/tests/baselines/reference/classStaticBlock5(target=esnext).js new file mode 100644 index 0000000000000..84fece2b40219 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).js @@ -0,0 +1,32 @@ +//// [classStaticBlock5.ts] +class B { + static a = 1; + static b = 2; +} + +class C extends B { + static b = 3; + static c = super.a + + static { + this.b; + super.b; + super.a; + } +} + + +//// [classStaticBlock5.js] +class B { + static a = 1; + static b = 2; +} +class C extends B { + static b = 3; + static c = super.a; + static { + this.b; + super.b; + super.a; + } +} diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).symbols b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols new file mode 100644 index 0000000000000..1e2334d1dff10 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts === +class B { +>B : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) + + static a = 1; +>a : Symbol(B.a, Decl(classStaticBlock5.ts, 0, 9)) + + static b = 2; +>b : Symbol(B.b, Decl(classStaticBlock5.ts, 1, 17)) +} + +class C extends B { +>C : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) +>B : Symbol(B, Decl(classStaticBlock5.ts, 0, 0)) + + static b = 3; +>b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) + + static c = super.a +>c : Symbol(C.c, Decl(classStaticBlock5.ts, 6, 17)) + + static { + this.b; +>this.b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) +>this : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) +>b : Symbol(C.b, Decl(classStaticBlock5.ts, 5, 19)) + + super.b; + super.a; + } +} + diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).types b/tests/baselines/reference/classStaticBlock5(target=esnext).types new file mode 100644 index 0000000000000..beb56840bfc1c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts === +class B { +>B : B + + static a = 1; +>a : number +>1 : 1 + + static b = 2; +>b : number +>2 : 2 +} + +class C extends B { +>C : C +>B : B + + static b = 3; +>b : number +>3 : 3 + + static c = super.a +>c : any +>super.a : any +>super : any +>a : any + + static { + this.b; +>this.b : number +>this : typeof C +>b : number + + super.b; +>super.b : any +>super : any +>b : any + + super.a; +>super.a : any +>super : any +>a : any + } +} + diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt new file mode 100644 index 0000000000000..95e69c743769c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -0,0 +1,111 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(8,13): error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(9,13): error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,9): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS2662: Cannot find name 'arguments'. Did you mean the static member 'C.arguments'? +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(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. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(45,17): error TS2522: The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(46,22): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(55,13): error TS2815: 'arguments' cannot be referenced in property initializers. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (15 errors) ==== + class B { + static a = 1; + } + + class C extends B { + static { + let await = 1; + let arguments = 1; + ~~~~~~~~~ +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. + let eval = 1; + ~~~~ +!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode. + } + + static { + await: if (true) { + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + + } + + arguments; + ~~~~~~~~~ +!!! error TS2662: Cannot find name 'arguments'. Did you mean the static member 'C.arguments'? + await; + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + super(); + ~~~~~ +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. + } + } + + class CC { + constructor () { + class C extends B { + static { + class CC extends B { + constructor () { + super(); + } + } + super(); + ~~~~~ +!!! error TS2335: 'super' can only be referenced in a derived class. + } + } + } + } + + async function foo () { + class C extends B { + static { + arguments; + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers. + await; + ~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + ~ +!!! error TS1109: Expression expected. + + async function ff () { + arguments; + ~~~~~~~~~ +!!! error TS2522: The 'arguments' object cannot be referenced in an async function or method in ES3 and ES5. Consider using a standard function or method. + await; + ~ +!!! error TS1109: Expression expected. + } + } + } + } + + function foo1 () { + class C extends B { + static { + arguments; + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers. + + function ff () { + arguments; + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js new file mode 100644 index 0000000000000..69d146407890e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.js @@ -0,0 +1,213 @@ +//// [classStaticBlock6.ts] +class B { + static a = 1; +} + +class C extends B { + static { + let await = 1; + let arguments = 1; + let eval = 1; + } + + static { + await: if (true) { + + } + + arguments; + await; + super(); + } +} + +class CC { + constructor () { + class C extends B { + static { + class CC extends B { + constructor () { + super(); + } + } + super(); + } + } + } +} + +async function foo () { + class C extends B { + static { + arguments; + await; + + async function ff () { + arguments; + await; + } + } + } +} + +function foo1 () { + class C extends B { + static { + arguments; + + function ff () { + arguments; + } + } + } +} + + +//// [classStaticBlock6.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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var B = /** @class */ (function () { + function B() { + } + B.a = 1; + return B; +}()); +var C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; +}(B)); +(function () { + var await = 1; + var arguments = 1; + var eval = 1; +})(); +(function () { + yield ; + if (true) { + } + arguments; + yield ; + _this = _super.call(this) || this; +})(); +var CC = /** @class */ (function () { + function CC() { + var C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; + }(B)); + (function () { + var CC = /** @class */ (function (_super) { + __extends(CC, _super); + function CC() { + return _super.call(this) || this; + } + return CC; + }(B)); + _this = _super.call(this) || this; + })(); + } + return CC; +}()); +function foo() { + return __awaiter(this, void 0, void 0, function () { + var C; + return __generator(this, function (_a) { + C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; + }(B)); + (function () { + arguments; + yield ; + function ff() { + return __awaiter(this, arguments, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + arguments; + return [4 /*yield*/, ]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + } + })(); + return [2 /*return*/]; + }); + }); +} +function foo1() { + var C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; + }(B)); + (function () { + arguments; + function ff() { + arguments; + } + })(); +} diff --git a/tests/baselines/reference/classStaticBlock6.symbols b/tests/baselines/reference/classStaticBlock6.symbols new file mode 100644 index 0000000000000..6505cd0cf9a99 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.symbols @@ -0,0 +1,104 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts === +class B { +>B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + + static a = 1; +>a : Symbol(B.a, Decl(classStaticBlock6.ts, 0, 9)) +} + +class C extends B { +>C : Symbol(C, Decl(classStaticBlock6.ts, 2, 1)) +>B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + + static { + let await = 1; +>await : Symbol(await, Decl(classStaticBlock6.ts, 6, 11)) + + let arguments = 1; +>arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) + + let eval = 1; +>eval : Symbol(eval, Decl(classStaticBlock6.ts, 8, 11)) + } + + static { + await: if (true) { + + } + + arguments; + await; + super(); + } +} + +class CC { +>CC : Symbol(CC, Decl(classStaticBlock6.ts, 20, 1)) + + constructor () { + class C extends B { +>C : Symbol(C, Decl(classStaticBlock6.ts, 23, 20)) +>B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + + static { + class CC extends B { +>CC : Symbol(CC, Decl(classStaticBlock6.ts, 25, 20)) +>B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + + constructor () { + super(); +>super : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + } + } + super(); + } + } + } +} + +async function foo () { +>foo : Symbol(foo, Decl(classStaticBlock6.ts, 35, 1)) + + class C extends B { +>C : Symbol(C, Decl(classStaticBlock6.ts, 37, 23)) +>B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + + static { + arguments; +>arguments : Symbol(arguments) + + await; + + async function ff () { +>ff : Symbol(ff, Decl(classStaticBlock6.ts, 41, 18)) + + arguments; +>arguments : Symbol(arguments) + + await; + } + } + } +} + +function foo1 () { +>foo1 : Symbol(foo1, Decl(classStaticBlock6.ts, 49, 1)) + + class C extends B { +>C : Symbol(C, Decl(classStaticBlock6.ts, 51, 18)) +>B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) + + static { + arguments; +>arguments : Symbol(arguments) + + function ff () { +>ff : Symbol(ff, Decl(classStaticBlock6.ts, 54, 22)) + + arguments; +>arguments : Symbol(arguments) + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock6.types b/tests/baselines/reference/classStaticBlock6.types new file mode 100644 index 0000000000000..af1243a74f89a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.types @@ -0,0 +1,125 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts === +class B { +>B : B + + static a = 1; +>a : number +>1 : 1 +} + +class C extends B { +>C : C +>B : B + + static { + let await = 1; +>await : number +>1 : 1 + + let arguments = 1; +>arguments : number +>1 : 1 + + let eval = 1; +>eval : number +>1 : 1 + } + + static { + await: if (true) { +>await : any +> : any +>true : true + + } + + arguments; +>arguments : any + + await; +>await : any +> : any + + super(); +>super() : void +>super : any + } +} + +class CC { +>CC : CC + + constructor () { + class C extends B { +>C : C +>B : B + + static { + class CC extends B { +>CC : CC +>B : B + + constructor () { + super(); +>super() : void +>super : typeof B + } + } + super(); +>super() : void +>super : any + } + } + } +} + +async function foo () { +>foo : () => Promise + + class C extends B { +>C : C +>B : B + + static { + arguments; +>arguments : any + + await; +>await : any +> : any + + async function ff () { +>ff : () => Promise + + arguments; +>arguments : IArguments + + await; +>await : any +> : any + } + } + } +} + +function foo1 () { +>foo1 : () => void + + class C extends B { +>C : C +>B : B + + static { + arguments; +>arguments : any + + function ff () { +>ff : () => void + + arguments; +>arguments : IArguments + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt new file mode 100644 index 0000000000000..c7892aa3eb98c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -0,0 +1,67 @@ +error TS2318: Cannot find global type 'IterableIterator'. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(4,9): error TS1163: A 'yield' expression is only allowed in a generator body. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(5,9): error TS18041: A 'return' statement cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(12,13): error TS18037: Await expression cannot be used inside a class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(24,13): error TS1163: A 'yield' expression is only allowed in a generator body. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(36,13): error TS18041: A 'return' statement cannot be used inside a class static block. + + +!!! error TS2318: Cannot find global type 'IterableIterator'. +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (6 errors) ==== + class C { + static { + await 1; + ~~~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + yield 1; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + return 1; + ~~~~~~ +!!! error TS18041: A 'return' statement cannot be used inside a class static block. + } + } + + async function f1 () { + class C { + static { + await 1; + ~~~~~~~ +!!! error TS18037: Await expression cannot be used inside a class static block. + + async function ff () { + await 1; + } + } + } + } + + function * f2 () { + class C { + static { + yield 1; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + + function * ff () { + yield 1; + } + } + } + } + + function f3 () { + class C { + static { + return 1; + ~~~~~~ +!!! error TS18041: A 'return' statement cannot be used inside a class static block. + + function ff () { + return 1 + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock7.js b/tests/baselines/reference/classStaticBlock7.js new file mode 100644 index 0000000000000..fd198db1871dd --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.js @@ -0,0 +1,158 @@ +//// [classStaticBlock7.ts] +class C { + static { + await 1; + yield 1; + return 1; + } +} + +async function f1 () { + class C { + static { + await 1; + + async function ff () { + await 1; + } + } + } +} + +function * f2 () { + class C { + static { + yield 1; + + function * ff () { + yield 1; + } + } + } +} + +function f3 () { + class C { + static { + return 1; + + function ff () { + return 1 + } + } + } +} + + +//// [classStaticBlock7.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +(function () { + yield 1; + yield 1; + return 1; +})(); +function f1() { + return __awaiter(this, void 0, void 0, function () { + var C; + return __generator(this, function (_a) { + C = /** @class */ (function () { + function C() { + } + return C; + }()); + (function () { + yield 1; + function ff() { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + } + })(); + return [2 /*return*/]; + }); + }); +} +function f2() { + var C; + return __generator(this, function (_a) { + C = /** @class */ (function () { + function C() { + } + return C; + }()); + (function () { + yield 1; + function ff() { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, 1]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + } + })(); + return [2 /*return*/]; + }); +} +function f3() { + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + (function () { + return 1; + function ff() { + return 1; + } + })(); +} diff --git a/tests/baselines/reference/classStaticBlock7.symbols b/tests/baselines/reference/classStaticBlock7.symbols new file mode 100644 index 0000000000000..d42ee5e420396 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.symbols @@ -0,0 +1,65 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock7.ts, 0, 0)) + + static { + await 1; + yield 1; + return 1; + } +} + +async function f1 () { +>f1 : Symbol(f1, Decl(classStaticBlock7.ts, 6, 1)) + + class C { +>C : Symbol(C, Decl(classStaticBlock7.ts, 8, 22)) + + static { + await 1; + + async function ff () { +>ff : Symbol(ff, Decl(classStaticBlock7.ts, 11, 20)) + + await 1; + } + } + } +} + +function * f2 () { +>f2 : Symbol(f2, Decl(classStaticBlock7.ts, 18, 1)) + + class C { +>C : Symbol(C, Decl(classStaticBlock7.ts, 20, 18)) + + static { + yield 1; + + function * ff () { +>ff : Symbol(ff, Decl(classStaticBlock7.ts, 23, 20)) + + yield 1; + } + } + } +} + +function f3 () { +>f3 : Symbol(f3, Decl(classStaticBlock7.ts, 30, 1)) + + class C { +>C : Symbol(C, Decl(classStaticBlock7.ts, 32, 16)) + + static { + return 1; + + function ff () { +>ff : Symbol(ff, Decl(classStaticBlock7.ts, 35, 21)) + + return 1 + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock7.types b/tests/baselines/reference/classStaticBlock7.types new file mode 100644 index 0000000000000..83eade23082c8 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts === +class C { +>C : C + + static { + await 1; +>await 1 : 1 +>1 : 1 + + yield 1; +>yield 1 : any +>1 : 1 + + return 1; +>1 : 1 + } +} + +async function f1 () { +>f1 : () => Promise + + class C { +>C : C + + static { + await 1; +>await 1 : 1 +>1 : 1 + + async function ff () { +>ff : () => Promise + + await 1; +>await 1 : 1 +>1 : 1 + } + } + } +} + +function * f2 () { +>f2 : () => {} + + class C { +>C : C + + static { + yield 1; +>yield 1 : any +>1 : 1 + + function * ff () { +>ff : () => {} + + yield 1; +>yield 1 : any +>1 : 1 + } + } + } +} + +function f3 () { +>f3 : () => void + + class C { +>C : C + + static { + return 1; +>1 : 1 + + function ff () { +>ff : () => number + + return 1 +>1 : 1 + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock8.errors.txt b/tests/baselines/reference/classStaticBlock8.errors.txt new file mode 100644 index 0000000000000..f98906f4528ef --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.errors.txt @@ -0,0 +1,64 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(6,21): error TS1107: Jump target cannot cross function boundary. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(9,21): error TS1107: Jump target cannot cross function boundary. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(12,21): error TS1107: Jump target cannot cross function boundary. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(15,21): error TS1107: Jump target cannot cross function boundary. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts (4 errors) ==== + function foo (v: number) { + label: while (v) { + class C { + static { + if (v === 1) { + break label; + ~~~~~~~~~~~~ +!!! error TS1107: Jump target cannot cross function boundary. + } + if (v === 2) { + continue label; + ~~~~~~~~~~~~~~~ +!!! error TS1107: Jump target cannot cross function boundary. + } + if (v === 3) { + break + ~~~~~ +!!! error TS1107: Jump target cannot cross function boundary. + } + if (v === 4) { + continue + ~~~~~~~~ +!!! error TS1107: Jump target cannot cross function boundary. + } + } + } + + if (v === 5) { + break label; + } + if (v === 6) { + continue label; + } + if (v === 7) { + break; + } + if (v === 8) { + continue; + } + } + + class C { + static { + outer: break outer; // valid + loop: while (v) { + if (v === 1) break loop; // valid + if (v === 2) continue loop; // valid + if (v === 3) break; // valid + if (v === 4) continue; // valid + } + switch (v) { + default: break; // valid + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock8.js b/tests/baselines/reference/classStaticBlock8.js new file mode 100644 index 0000000000000..9d9e42a9c5956 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.js @@ -0,0 +1,108 @@ +//// [classStaticBlock8.ts] +function foo (v: number) { + label: while (v) { + class C { + static { + if (v === 1) { + break label; + } + if (v === 2) { + continue label; + } + if (v === 3) { + break + } + if (v === 4) { + continue + } + } + } + + if (v === 5) { + break label; + } + if (v === 6) { + continue label; + } + if (v === 7) { + break; + } + if (v === 8) { + continue; + } + } + + class C { + static { + outer: break outer; // valid + loop: while (v) { + if (v === 1) break loop; // valid + if (v === 2) continue loop; // valid + if (v === 3) break; // valid + if (v === 4) continue; // valid + } + switch (v) { + default: break; // valid + } + } + } +} + + +//// [classStaticBlock8.js] +function foo(v) { + label: while (v) { + var C_1 = /** @class */ (function () { + function C() { + } + return C; + }()); + (function () { + if (v === 1) { + break label; + } + if (v === 2) { + continue label; + } + if (v === 3) { + break; + } + if (v === 4) { + continue; + } + })(); + if (v === 5) { + break label; + } + if (v === 6) { + continue label; + } + if (v === 7) { + break; + } + if (v === 8) { + continue; + } + } + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + (function () { + outer: break outer; // valid + loop: while (v) { + if (v === 1) + break loop; // valid + if (v === 2) + continue loop; // valid + if (v === 3) + break; // valid + if (v === 4) + continue; // valid + } + switch (v) { + default: break; // valid + } + })(); +} diff --git a/tests/baselines/reference/classStaticBlock8.symbols b/tests/baselines/reference/classStaticBlock8.symbols new file mode 100644 index 0000000000000..5c2eeee615797 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.symbols @@ -0,0 +1,86 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts === +function foo (v: number) { +>foo : Symbol(foo, Decl(classStaticBlock8.ts, 0, 0)) +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + label: while (v) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + class C { +>C : Symbol(C, Decl(classStaticBlock8.ts, 1, 22)) + + static { + if (v === 1) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + break label; + } + if (v === 2) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + continue label; + } + if (v === 3) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + break + } + if (v === 4) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + continue + } + } + } + + if (v === 5) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + break label; + } + if (v === 6) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + continue label; + } + if (v === 7) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + break; + } + if (v === 8) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + continue; + } + } + + class C { +>C : Symbol(C, Decl(classStaticBlock8.ts, 31, 5)) + + static { + outer: break outer; // valid + loop: while (v) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + if (v === 1) break loop; // valid +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + if (v === 2) continue loop; // valid +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + if (v === 3) break; // valid +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + if (v === 4) continue; // valid +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + } + switch (v) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + default: break; // valid + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock8.types b/tests/baselines/reference/classStaticBlock8.types new file mode 100644 index 0000000000000..7651bd003aa6e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.types @@ -0,0 +1,121 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts === +function foo (v: number) { +>foo : (v: number) => void +>v : number + + label: while (v) { +>label : any +>v : number + + class C { +>C : C + + static { + if (v === 1) { +>v === 1 : boolean +>v : number +>1 : 1 + + break label; +>label : any + } + if (v === 2) { +>v === 2 : boolean +>v : number +>2 : 2 + + continue label; +>label : any + } + if (v === 3) { +>v === 3 : boolean +>v : number +>3 : 3 + + break + } + if (v === 4) { +>v === 4 : boolean +>v : number +>4 : 4 + + continue + } + } + } + + if (v === 5) { +>v === 5 : boolean +>v : number +>5 : 5 + + break label; +>label : any + } + if (v === 6) { +>v === 6 : boolean +>v : number +>6 : 6 + + continue label; +>label : any + } + if (v === 7) { +>v === 7 : boolean +>v : number +>7 : 7 + + break; + } + if (v === 8) { +>v === 8 : boolean +>v : number +>8 : 8 + + continue; + } + } + + class C { +>C : C + + static { + outer: break outer; // valid +>outer : any +>outer : any + + loop: while (v) { +>loop : any +>v : number + + if (v === 1) break loop; // valid +>v === 1 : boolean +>v : number +>1 : 1 +>loop : any + + if (v === 2) continue loop; // valid +>v === 2 : boolean +>v : number +>2 : 2 +>loop : any + + if (v === 3) break; // valid +>v === 3 : boolean +>v : number +>3 : 3 + + if (v === 4) continue; // valid +>v === 4 : boolean +>v : number +>4 : 4 + } + switch (v) { +>v : number + + default: break; // valid + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt new file mode 100644 index 0000000000000..4e8572da31914 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(2,20): error TS2729: Property 'foo' is used before its initialization. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(4,11): error TS2729: Property 'foo' is used before its initialization. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts (2 errors) ==== + class A { + static bar = A.foo + 1 + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts:6:12: 'foo' is declared here. + static { + A.foo + 2; + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts:6:12: 'foo' is declared here. + } + static foo = 1; + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).js b/tests/baselines/reference/classStaticBlock9(target=es2015).js new file mode 100644 index 0000000000000..d2b5eefa004c9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).js @@ -0,0 +1,18 @@ +//// [classStaticBlock9.ts] +class A { + static bar = A.foo + 1 + static { + A.foo + 2; + } + static foo = 1; +} + + +//// [classStaticBlock9.js] +class A { +} +A.bar = A.foo + 1; +(() => { + A.foo + 2; +})(); +A.foo = 1; diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).symbols b/tests/baselines/reference/classStaticBlock9(target=es2015).symbols new file mode 100644 index 0000000000000..2cb44695c8328 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts === +class A { +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) + + static bar = A.foo + 1 +>bar : Symbol(A.bar, Decl(classStaticBlock9.ts, 0, 9)) +>A.foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) + + static { + A.foo + 2; +>A.foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) + } + static foo = 1; +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +} + diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).types b/tests/baselines/reference/classStaticBlock9(target=es2015).types new file mode 100644 index 0000000000000..9ac192ac54bed --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts === +class A { +>A : A + + static bar = A.foo + 1 +>bar : number +>A.foo + 1 : number +>A.foo : number +>A : typeof A +>foo : number +>1 : 1 + + static { + A.foo + 2; +>A.foo + 2 : number +>A.foo : number +>A : typeof A +>foo : number +>2 : 2 + } + static foo = 1; +>foo : number +>1 : 1 +} + diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt new file mode 100644 index 0000000000000..4e8572da31914 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(2,20): error TS2729: Property 'foo' is used before its initialization. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(4,11): error TS2729: Property 'foo' is used before its initialization. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts (2 errors) ==== + class A { + static bar = A.foo + 1 + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts:6:12: 'foo' is declared here. + static { + A.foo + 2; + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts:6:12: 'foo' is declared here. + } + static foo = 1; + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).js b/tests/baselines/reference/classStaticBlock9(target=es5).js new file mode 100644 index 0000000000000..1b957f3b714e9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es5).js @@ -0,0 +1,21 @@ +//// [classStaticBlock9.ts] +class A { + static bar = A.foo + 1 + static { + A.foo + 2; + } + static foo = 1; +} + + +//// [classStaticBlock9.js] +var A = /** @class */ (function () { + function A() { + } + A.bar = A.foo + 1; + (function () { + A.foo + 2; + })(); + A.foo = 1; + return A; +}()); diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).symbols b/tests/baselines/reference/classStaticBlock9(target=es5).symbols new file mode 100644 index 0000000000000..2cb44695c8328 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es5).symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts === +class A { +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) + + static bar = A.foo + 1 +>bar : Symbol(A.bar, Decl(classStaticBlock9.ts, 0, 9)) +>A.foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) + + static { + A.foo + 2; +>A.foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) + } + static foo = 1; +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +} + diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).types b/tests/baselines/reference/classStaticBlock9(target=es5).types new file mode 100644 index 0000000000000..9ac192ac54bed --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es5).types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts === +class A { +>A : A + + static bar = A.foo + 1 +>bar : number +>A.foo + 1 : number +>A.foo : number +>A : typeof A +>foo : number +>1 : 1 + + static { + A.foo + 2; +>A.foo + 2 : number +>A.foo : number +>A : typeof A +>foo : number +>2 : 2 + } + static foo = 1; +>foo : number +>1 : 1 +} + diff --git a/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt new file mode 100644 index 0000000000000..4e8572da31914 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(2,20): error TS2729: Property 'foo' is used before its initialization. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(4,11): error TS2729: Property 'foo' is used before its initialization. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts (2 errors) ==== + class A { + static bar = A.foo + 1 + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts:6:12: 'foo' is declared here. + static { + A.foo + 2; + ~~~ +!!! error TS2729: Property 'foo' is used before its initialization. +!!! related TS2728 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts:6:12: 'foo' is declared here. + } + static foo = 1; + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock9(target=esnext).js b/tests/baselines/reference/classStaticBlock9(target=esnext).js new file mode 100644 index 0000000000000..de762275b1eec --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).js @@ -0,0 +1,18 @@ +//// [classStaticBlock9.ts] +class A { + static bar = A.foo + 1 + static { + A.foo + 2; + } + static foo = 1; +} + + +//// [classStaticBlock9.js] +class A { + static bar = A.foo + 1; + static { + A.foo + 2; + } + static foo = 1; +} diff --git a/tests/baselines/reference/classStaticBlock9(target=esnext).symbols b/tests/baselines/reference/classStaticBlock9(target=esnext).symbols new file mode 100644 index 0000000000000..2cb44695c8328 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts === +class A { +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) + + static bar = A.foo + 1 +>bar : Symbol(A.bar, Decl(classStaticBlock9.ts, 0, 9)) +>A.foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) + + static { + A.foo + 2; +>A.foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +>A : Symbol(A, Decl(classStaticBlock9.ts, 0, 0)) +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) + } + static foo = 1; +>foo : Symbol(A.foo, Decl(classStaticBlock9.ts, 4, 5)) +} + diff --git a/tests/baselines/reference/classStaticBlock9(target=esnext).types b/tests/baselines/reference/classStaticBlock9(target=esnext).types new file mode 100644 index 0000000000000..9ac192ac54bed --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts === +class A { +>A : A + + static bar = A.foo + 1 +>bar : number +>A.foo + 1 : number +>A.foo : number +>A : typeof A +>foo : number +>1 : 1 + + static { + A.foo + 2; +>A.foo + 2 : number +>A.foo : number +>A : typeof A +>foo : number +>2 : 2 + } + static foo = 1; +>foo : number +>1 : 1 +} + diff --git a/tests/baselines/reference/findAllRefsClassStaticBlocks.baseline.jsonc b/tests/baselines/reference/findAllRefsClassStaticBlocks.baseline.jsonc new file mode 100644 index 0000000000000..1d05a33aa9f6e --- /dev/null +++ b/tests/baselines/reference/findAllRefsClassStaticBlocks.baseline.jsonc @@ -0,0 +1,128 @@ +// === /tests/cases/fourslash/findAllRefsClassStaticBlocks.ts === +// class ClassStaticBocks { +// static x; +// /*FIND ALL REFS*/[|static|] {} +// static y; +// static {} +// static y; +// static {} +// } + +[ + { + "definition": { + "containerKind": "", + "containerName": "", + "fileName": "/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts", + "kind": "keyword", + "name": "static", + "textSpan": { + "start": 43, + "length": 6 + }, + "displayParts": [ + { + "text": "static", + "kind": "keyword" + } + ] + }, + "references": [ + { + "textSpan": { + "start": 43, + "length": 6 + }, + "fileName": "/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts", + "isWriteAccess": false, + "isDefinition": false + } + ] + } +] + +// === /tests/cases/fourslash/findAllRefsClassStaticBlocks.ts === +// class ClassStaticBocks { +// static x; +// static {} +// static y; +// /*FIND ALL REFS*/[|static|] {} +// static y; +// static {} +// } + +[ + { + "definition": { + "containerKind": "", + "containerName": "", + "fileName": "/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts", + "kind": "keyword", + "name": "static", + "textSpan": { + "start": 71, + "length": 6 + }, + "displayParts": [ + { + "text": "static", + "kind": "keyword" + } + ] + }, + "references": [ + { + "textSpan": { + "start": 71, + "length": 6 + }, + "fileName": "/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts", + "isWriteAccess": false, + "isDefinition": false + } + ] + } +] + +// === /tests/cases/fourslash/findAllRefsClassStaticBlocks.ts === +// class ClassStaticBocks { +// static x; +// static {} +// static y; +// static {} +// static y; +// /*FIND ALL REFS*/[|static|] {} +// } + +[ + { + "definition": { + "containerKind": "", + "containerName": "", + "fileName": "/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts", + "kind": "keyword", + "name": "static", + "textSpan": { + "start": 99, + "length": 6 + }, + "displayParts": [ + { + "text": "static", + "kind": "keyword" + } + ] + }, + "references": [ + { + "textSpan": { + "start": 99, + "length": 6 + }, + "fileName": "/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts", + "isWriteAccess": false, + "isDefinition": false + } + ] + } +] \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts new file mode 100644 index 0000000000000..8a0edbfedbe1a --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts @@ -0,0 +1,10 @@ +// @target: esnext, es2015, es5 +const a = 2; + +class C { + static { + const a = 1; + + a; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts new file mode 100644 index 0000000000000..c6e1fc2244d99 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts @@ -0,0 +1,28 @@ +// @target: esnext, es2015, es5 +var a1 = 1; +var a2 = 1; +const b1 = 2; +const b2 = 2; + +function f () { + var a1 = 11; + const b1 = 22; + + class C1 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } + } +} + +class C2 { + static { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts new file mode 100644 index 0000000000000..685d870cceb09 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts @@ -0,0 +1,14 @@ +// @target: esnext, es2015 + +let getX; +class C { + #x = 1 + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts new file mode 100644 index 0000000000000..436c690665368 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts @@ -0,0 +1,10 @@ +// @useDefineForClassFields: false +// @target: es2015 + +class C { + static #x = 1; + + static { + C.#x; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts new file mode 100644 index 0000000000000..8120cc3575cb3 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts @@ -0,0 +1,14 @@ +// @target: esnext, es2015 +// @useDefineForClassFields: true + +class C { + static #x = 123; + + static { + console.log(C.#x) + } + + foo () { + return C.#x; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts new file mode 100644 index 0000000000000..ff510c843657a --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts @@ -0,0 +1,15 @@ +// @useDefineForClassFields: false +// @target: es2015 + +class C { + static #_1 = 1; + static #_3 = 1; + static #_5 = 1; + + static {} + static {} + static {} + static {} + static {} + static {} +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts new file mode 100644 index 0000000000000..ec2727660f123 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts @@ -0,0 +1,18 @@ +// @target: esnext, es2015 +// @useDefineForClassFields: true +var _C__1; + +class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts new file mode 100644 index 0000000000000..bc15e5f1ab398 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts @@ -0,0 +1,26 @@ +// @target: es2015 + +let getX: (c: C) => number; +class C { + #x = 1 + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + getY = (obj: D) => obj.#y; + } +} + +let getY: (c: D) => number; +class D { + #y = 1 + + static { + // getY has privileged access to y + getX = (obj: C) => obj.#x; + getY = (obj: D) => obj.#y; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock17.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock17.ts new file mode 100644 index 0000000000000..8d26cb4a08261 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock17.ts @@ -0,0 +1,33 @@ +// @target: es2015 + +let friendA: { getX(o: A): number, setX(o: A, v: number): void }; + +class A { + #x: number; + + constructor (v: number) { + this.#x = v; + } + + getX () { + return this.#x; + } + + static { + friendA = { + getX(obj) { return obj.#x }, + setX(obj, value) { obj.#x = value } + }; + } +}; + +class B { + constructor(a: A) { + const x = friendA.getX(a); // ok + friendA.setX(a, x + 1); // ok + } +}; + +const a = new A(41); +const b = new B(a); +a.getX(); \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts new file mode 100644 index 0000000000000..a36bd50917c20 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts @@ -0,0 +1,15 @@ +// @target: esnext, es2015, es5 + +function foo () { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + } + } + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts new file mode 100644 index 0000000000000..33bb993be64f8 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts @@ -0,0 +1,6 @@ +class C { + @decorator + static { + // something + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts new file mode 100644 index 0000000000000..292d7181bba5d --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts @@ -0,0 +1,20 @@ +// @target: esnext, es2015, es5 + +const a = 1; +const b = 2; + +class C { + static { + const a = 11; + + a; + b; + } + + static { + const a = 11; + + a; + b; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts new file mode 100644 index 0000000000000..72a9d09161ec2 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts @@ -0,0 +1,13 @@ +class C { + async static { + // something + } + + public static { + // something + } + + readonly private static { + // something + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock21.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock21.ts new file mode 100644 index 0000000000000..9fbd6ab3f968c --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock21.ts @@ -0,0 +1,6 @@ +class C { + /* jsdocs */ + static { + // something + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts new file mode 100644 index 0000000000000..8d3be9861aa71 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts @@ -0,0 +1,72 @@ +// @target: esnext + +let await: "any"; +class C { + static { + let await: any; // illegal, cannot declare a new binding for await + } + static { + let { await } = {} as any; // illegal, cannot declare a new binding for await + } + static { + let { await: other } = {} as any; // legal + } + static { + let await; // illegal, cannot declare a new binding for await + } + static { + function await() { }; // illegal + } + static { + class await { }; // illegal + } + + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + }; + } + static { + (function await() { }); // legal, 'await' in function expression name not bound inside of static block + } + static { + (class await { }); // legal, 'await' in class expression name not bound inside of static block + } + static { + (function () { return await; }); // legal, 'await' is inside of a new function boundary + } + static { + (() => await); // legal, 'await' is inside of a new function boundary + } + + static { + class E { + constructor() { await; } + method() { await; } + get accessor() { + await; + return 1; + } + set accessor(v: any) { + await; + } + propLambda = () => { await; } + propFunc = function () { await; } + } + } + static { + class S { + static method() { await; } + static get accessor() { + await; + return 1; + } + static set accessor(v: any) { + await; + } + static propLambda = () => { await; } + static propFunc = function () { await; } + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts new file mode 100644 index 0000000000000..bb83b27dcab32 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts @@ -0,0 +1,21 @@ +// @target: esnext + +const nums = [1, 2, 3].map(n => Promise.resolve(n)) + +class C { + static { + for await (const nn of nums) { + console.log(nn) + } + } +} + +async function foo () { + class C { + static { + for await (const nn of nums) { + console.log(nn) + } + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts new file mode 100644 index 0000000000000..8132238772b65 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts @@ -0,0 +1,8 @@ +// @module: commonjs, es2015, es2020, UMD, AMD, System, esnext + +export class C { + static x: number; + static { + C.x = 1; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.ts new file mode 100644 index 0000000000000..56f99a612298d --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.ts @@ -0,0 +1,23 @@ +// @target: esnext +// @declaration: true +// @declarationMap: true +// @sourceMap: true + +const a = 1; +const b = 2; + +class C { + static { + const a = 11; + + a; + b; + } + + static { + const a = 11; + + a; + b; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts new file mode 100644 index 0000000000000..1081729acdb2d --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts @@ -0,0 +1,30 @@ +// @target: esnext + +class C { + static { + await; // illegal + } + static { + await (1); // illegal + } + static { + ({ [await]: 1 }); // illegal + } + static { + class D { + [await] = 1; // illegal (computed property names are evaluated outside of a class body + }; + } + static { + ({ await }); // illegal short-hand property reference + } + static { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } + static { + function f(await) { } + const ff = (await) => { } + const fff = await => { } + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts new file mode 100644 index 0000000000000..84125fdbed75a --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts @@ -0,0 +1,19 @@ +// @target: esnext + +const a = 1; + +class C { + static f1 = 1; + + static { + console.log(C.f1, C.f2, C.f3) + } + + static f2 = 2; + + static { + console.log(C.f1, C.f2, C.f3) + } + + static f3 = 3; +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts new file mode 100644 index 0000000000000..7a944a496911f --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts @@ -0,0 +1,16 @@ +// @target: esnext + +class C { + static s1 = 1; + + static { + this.s1; + C.s1; + + this.s2; + C.s2; + } + + static s2 = 2; + static ss2 = this.s1; +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts new file mode 100644 index 0000000000000..cd0f7276c1b5f --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts @@ -0,0 +1,17 @@ +// @target: esnext, es2015, es5 + +class B { + static a = 1; + static b = 2; +} + +class C extends B { + static b = 3; + static c = super.a + + static { + this.b; + super.b; + super.a; + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts new file mode 100644 index 0000000000000..cdd0cda2fe7af --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts @@ -0,0 +1,62 @@ +class B { + static a = 1; +} + +class C extends B { + static { + let await = 1; + let arguments = 1; + let eval = 1; + } + + static { + await: if (true) { + + } + + arguments; + await; + super(); + } +} + +class CC { + constructor () { + class C extends B { + static { + class CC extends B { + constructor () { + super(); + } + } + super(); + } + } + } +} + +async function foo () { + class C extends B { + static { + arguments; + await; + + async function ff () { + arguments; + await; + } + } + } +} + +function foo1 () { + class C extends B { + static { + arguments; + + function ff () { + arguments; + } + } + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts new file mode 100644 index 0000000000000..727ada0342725 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts @@ -0,0 +1,43 @@ +class C { + static { + await 1; + yield 1; + return 1; + } +} + +async function f1 () { + class C { + static { + await 1; + + async function ff () { + await 1; + } + } + } +} + +function * f2 () { + class C { + static { + yield 1; + + function * ff () { + yield 1; + } + } + } +} + +function f3 () { + class C { + static { + return 1; + + function ff () { + return 1 + } + } + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts new file mode 100644 index 0000000000000..d2e5220b834f6 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts @@ -0,0 +1,48 @@ +function foo (v: number) { + label: while (v) { + class C { + static { + if (v === 1) { + break label; + } + if (v === 2) { + continue label; + } + if (v === 3) { + break + } + if (v === 4) { + continue + } + } + } + + if (v === 5) { + break label; + } + if (v === 6) { + continue label; + } + if (v === 7) { + break; + } + if (v === 8) { + continue; + } + } + + class C { + static { + outer: break outer; // valid + loop: while (v) { + if (v === 1) break loop; // valid + if (v === 2) continue loop; // valid + if (v === 3) break; // valid + if (v === 4) continue; // valid + } + switch (v) { + default: break; // valid + } + } + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts new file mode 100644 index 0000000000000..d99157b190983 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts @@ -0,0 +1,8 @@ +// @target: esnext, es2015, es5 +class A { + static bar = A.foo + 1 + static { + A.foo + 2; + } + static foo = 1; +} diff --git a/tests/cases/fourslash/callHierarchyClassStaticBlock.ts b/tests/cases/fourslash/callHierarchyClassStaticBlock.ts new file mode 100644 index 0000000000000..213180630c9e8 --- /dev/null +++ b/tests/cases/fourslash/callHierarchyClassStaticBlock.ts @@ -0,0 +1,26 @@ +/// + +//// class C { +//// static { +//// function foo() { +//// bar(); +//// } +//// +//// function /**/bar() { +//// baz(); +//// quxx(); +//// baz(); +//// } +//// +//// foo(); +//// } +//// } +//// +//// function baz() { +//// } +//// +//// function quxx() { +//// } + +goTo.marker(); +verify.baselineCallHierarchy(); diff --git a/tests/cases/fourslash/callHierarchyClassStaticBlock2.ts b/tests/cases/fourslash/callHierarchyClassStaticBlock2.ts new file mode 100644 index 0000000000000..584897515bccf --- /dev/null +++ b/tests/cases/fourslash/callHierarchyClassStaticBlock2.ts @@ -0,0 +1,26 @@ +/// + +//// class C { +//// /**/static { +//// function foo() { +//// bar(); +//// } +//// +//// function bar() { +//// baz(); +//// quxx(); +//// baz(); +//// } +//// +//// foo(); +//// } +//// } +//// +//// function baz() { +//// } +//// +//// function quxx() { +//// } + +goTo.marker(); +verify.baselineCallHierarchy(); diff --git a/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts b/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts new file mode 100644 index 0000000000000..feef6e2ec690c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsClassStaticBlocks.ts @@ -0,0 +1,12 @@ +/// + +////class ClassStaticBocks { +//// static x; +//// [|[|/*classStaticBocks1*/static|] {}|] +//// static y; +//// [|[|/*classStaticBocks2*/static|] {}|] +//// static y; +//// [|[|/*classStaticBocks3*/static|] {}|] +////} + +verify.baselineFindAllReferences("classStaticBocks1", "classStaticBocks2", "classStaticBocks3"); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionClassStaticBlocks.ts b/tests/cases/fourslash/goToDefinitionClassStaticBlocks.ts new file mode 100644 index 0000000000000..650c177cc933c --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionClassStaticBlocks.ts @@ -0,0 +1,16 @@ +/// + +////class ClassStaticBocks { +//// static x; +//// [|/*classStaticBocks1*/static|] {} +//// static y; +//// [|/*classStaticBocks2*/static|] {} +//// static y; +//// [|/*classStaticBocks3*/static|] {} +////} + +verify.goToDefinition({ + classStaticBocks1: ["classStaticBocks1", "classStaticBocks2", "classStaticBocks3"], + classStaticBocks2: ["classStaticBocks1", "classStaticBocks2", "classStaticBocks3"], + classStaticBocks3: ["classStaticBocks1", "classStaticBocks2", "classStaticBocks3"], +}); diff --git a/tests/cases/fourslash/navigationBarClassStaticBlock.ts b/tests/cases/fourslash/navigationBarClassStaticBlock.ts new file mode 100644 index 0000000000000..d0ee3ec3aceb5 --- /dev/null +++ b/tests/cases/fourslash/navigationBarClassStaticBlock.ts @@ -0,0 +1,48 @@ +/// + +////class C { +//// static { +//// let x; +//// } +////} + +verify.navigationTree({ + text: "", + kind: "script", + childItems: [ + { + text: "C", + kind: "class", + childItems: [ + { + "text": "x", + "kind": "let" + } + ] + } + ] +}); + +verify.navigationBar([ + { + text: "", + kind: "script", + childItems: [ + { + text: "C", + kind: "class" + } + ] + }, + { + text: "C", + kind: "class", + childItems: [ + { + "text": "x", + "kind": "let" + } + ], + indent: 1 + } +]);