From dde4ca26e6780cff88cc92b880eadcdc27cde4a1 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 19 Mar 2021 14:26:54 +0800 Subject: [PATCH 01/36] Class static block (#9) * Add types factory and parser * Add some case * Make class static block as a container * Update cases * Add visitor * Add emitter and more compile target * Check boundary of break and continue --- src/compiler/binder.ts | 4 +- src/compiler/checker.ts | 4 +- src/compiler/emitter.ts | 13 +++ src/compiler/factory/nodeFactory.ts | 32 ++++++++ src/compiler/parser.ts | 32 ++++++++ src/compiler/transformers/ts.ts | 1 + src/compiler/types.ts | 9 +++ src/compiler/utilities.ts | 1 + src/compiler/utilitiesPublic.ts | 9 +++ src/compiler/visitorPublic.ts | 8 ++ .../classStaticBlock1(target=es2015).js | 16 ++++ .../classStaticBlock1(target=es2015).symbols | 16 ++++ .../classStaticBlock1(target=es2015).types | 18 +++++ .../classStaticBlock1(target=es5).js | 19 +++++ .../classStaticBlock1(target=es5).symbols | 16 ++++ .../classStaticBlock1(target=es5).types | 18 +++++ .../classStaticBlock1(target=esnext).js | 20 +++++ .../classStaticBlock1(target=esnext).symbols | 16 ++++ .../classStaticBlock1(target=esnext).types | 18 +++++ .../baselines/reference/classStaticBlock1.js | 19 +++++ .../reference/classStaticBlock1.symbols | 16 ++++ .../reference/classStaticBlock1.types | 18 +++++ .../classStaticBlock10(target=es2015).js | 42 ++++++++++ .../classStaticBlock10(target=es2015).symbols | 58 ++++++++++++++ .../classStaticBlock10(target=es2015).types | 72 +++++++++++++++++ .../classStaticBlock10(target=es5).js | 48 +++++++++++ .../classStaticBlock10(target=es5).symbols | 58 ++++++++++++++ .../classStaticBlock10(target=es5).types | 72 +++++++++++++++++ .../classStaticBlock10(target=esnext).js | 54 +++++++++++++ .../classStaticBlock10(target=esnext).symbols | 58 ++++++++++++++ .../classStaticBlock10(target=esnext).types | 72 +++++++++++++++++ .../baselines/reference/classStaticBlock10.js | 48 +++++++++++ .../reference/classStaticBlock10.symbols | 58 ++++++++++++++ .../reference/classStaticBlock10.types | 72 +++++++++++++++++ .../classStaticBlock2(target=es2015).js | 26 ++++++ .../classStaticBlock2(target=es2015).symbols | 33 ++++++++ .../classStaticBlock2(target=es2015).types | 37 +++++++++ .../classStaticBlock2(target=es5).js | 29 +++++++ .../classStaticBlock2(target=es5).symbols | 33 ++++++++ .../classStaticBlock2(target=es5).types | 37 +++++++++ .../classStaticBlock2(target=esnext).js | 36 +++++++++ .../classStaticBlock2(target=esnext).symbols | 33 ++++++++ .../classStaticBlock2(target=esnext).types | 37 +++++++++ .../baselines/reference/classStaticBlock2.js | 29 +++++++ .../reference/classStaticBlock2.symbols | 33 ++++++++ .../reference/classStaticBlock2.types | 37 +++++++++ .../classStaticBlock3(target=es2015).js | 27 +++++++ .../classStaticBlock3(target=es2015).symbols | 49 ++++++++++++ .../classStaticBlock3(target=es2015).types | 55 +++++++++++++ .../classStaticBlock3(target=es5).js | 30 +++++++ .../classStaticBlock3(target=es5).symbols | 49 ++++++++++++ .../classStaticBlock3(target=es5).types | 55 +++++++++++++ .../classStaticBlock3(target=esnext).js | 33 ++++++++ .../classStaticBlock3(target=esnext).symbols | 49 ++++++++++++ .../classStaticBlock3(target=esnext).types | 55 +++++++++++++ .../baselines/reference/classStaticBlock3.js | 30 +++++++ .../reference/classStaticBlock3.symbols | 49 ++++++++++++ .../reference/classStaticBlock3.types | 55 +++++++++++++ ...lassStaticBlock4(target=es2015).errors.txt | 27 +++++++ .../classStaticBlock4(target=es2015).js | 23 ++++++ .../classStaticBlock4(target=es2015).symbols | 35 ++++++++ .../classStaticBlock4(target=es2015).types | 41 ++++++++++ .../classStaticBlock4(target=es5).errors.txt | 27 +++++++ .../classStaticBlock4(target=es5).js | 26 ++++++ .../classStaticBlock4(target=es5).symbols | 35 ++++++++ .../classStaticBlock4(target=es5).types | 41 ++++++++++ ...lassStaticBlock4(target=esnext).errors.txt | 27 +++++++ .../classStaticBlock4(target=esnext).js | 29 +++++++ .../classStaticBlock4(target=esnext).symbols | 35 ++++++++ .../classStaticBlock4(target=esnext).types | 41 ++++++++++ .../reference/classStaticBlock4.errors.txt | 27 +++++++ .../baselines/reference/classStaticBlock4.js | 26 ++++++ .../reference/classStaticBlock4.symbols | 35 ++++++++ .../reference/classStaticBlock4.types | 41 ++++++++++ ...lassStaticBlock5(target=es2015).errors.txt | 31 +++++++ .../classStaticBlock5(target=es2015).js | 27 +++++++ .../classStaticBlock5(target=es2015).symbols | 30 +++++++ .../classStaticBlock5(target=es2015).types | 45 +++++++++++ .../classStaticBlock5(target=es5).errors.txt | 31 +++++++ .../classStaticBlock5(target=es5).js | 50 ++++++++++++ .../classStaticBlock5(target=es5).symbols | 30 +++++++ .../classStaticBlock5(target=es5).types | 45 +++++++++++ ...lassStaticBlock5(target=esnext).errors.txt | 31 +++++++ .../classStaticBlock5(target=esnext).js | 32 ++++++++ .../classStaticBlock5(target=esnext).symbols | 30 +++++++ .../classStaticBlock5(target=esnext).types | 45 +++++++++++ .../reference/classStaticBlock5.errors.txt | 31 +++++++ .../baselines/reference/classStaticBlock5.js | 50 ++++++++++++ .../reference/classStaticBlock5.symbols | 30 +++++++ .../reference/classStaticBlock5.types | 45 +++++++++++ .../reference/classStaticBlock6.errors.txt | 33 ++++++++ .../baselines/reference/classStaticBlock6.js | 52 ++++++++++++ .../reference/classStaticBlock6.symbols | 37 +++++++++ .../reference/classStaticBlock6.types | 45 +++++++++++ .../reference/classStaticBlock7.errors.txt | 20 +++++ .../baselines/reference/classStaticBlock7.js | 16 ++++ .../reference/classStaticBlock7.symbols | 11 +++ .../reference/classStaticBlock7.types | 18 +++++ .../reference/classStaticBlock8.errors.txt | 56 +++++++++++++ .../baselines/reference/classStaticBlock8.js | 59 ++++++++++++++ .../reference/classStaticBlock8.symbols | 59 ++++++++++++++ .../reference/classStaticBlock8.types | 80 +++++++++++++++++++ ...lassStaticBlock9(target=es2015).errors.txt | 15 ++++ .../classStaticBlock9(target=es2015).js | 15 ++++ .../classStaticBlock9(target=es2015).symbols | 20 +++++ .../classStaticBlock9(target=es2015).types | 25 ++++++ .../classStaticBlock9(target=es5).errors.txt | 15 ++++ .../classStaticBlock9(target=es5).js | 18 +++++ .../classStaticBlock9(target=es5).symbols | 20 +++++ .../classStaticBlock9(target=es5).types | 25 ++++++ ...lassStaticBlock9(target=esnext).errors.txt | 15 ++++ .../classStaticBlock9(target=esnext).js | 18 +++++ .../classStaticBlock9(target=esnext).symbols | 20 +++++ .../classStaticBlock9(target=esnext).types | 25 ++++++ .../reference/classStaticBlock9.errors.txt | 15 ++++ .../baselines/reference/classStaticBlock9.js | 18 +++++ .../reference/classStaticBlock9.symbols | 20 +++++ .../reference/classStaticBlock9.types | 25 ++++++ .../classStaticBlock/classStaticBlock1.ts | 10 +++ .../classStaticBlock/classStaticBlock10.ts | 28 +++++++ .../classStaticBlock/classStaticBlock2.ts | 20 +++++ .../classStaticBlock/classStaticBlock3.ts | 19 +++++ .../classStaticBlock/classStaticBlock4.ts | 16 ++++ .../classStaticBlock/classStaticBlock5.ts | 17 ++++ .../classStaticBlock/classStaticBlock6.ts | 20 +++++ .../classStaticBlock/classStaticBlock7.ts | 7 ++ .../classStaticBlock/classStaticBlock8.ts | 33 ++++++++ .../classStaticBlock/classStaticBlock9.ts | 8 ++ 128 files changed, 4041 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock1(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock1(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock1(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock1(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock1(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock1(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock1(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock1(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock1(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock1.js create mode 100644 tests/baselines/reference/classStaticBlock1.symbols create mode 100644 tests/baselines/reference/classStaticBlock1.types create mode 100644 tests/baselines/reference/classStaticBlock10(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock10(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock10(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock10(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock10(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock10(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock10(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock10(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock10(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock10.js create mode 100644 tests/baselines/reference/classStaticBlock10.symbols create mode 100644 tests/baselines/reference/classStaticBlock10.types create mode 100644 tests/baselines/reference/classStaticBlock2(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock2(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock2(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock2(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock2(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock2(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock2(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock2(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock2(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock2.js create mode 100644 tests/baselines/reference/classStaticBlock2.symbols create mode 100644 tests/baselines/reference/classStaticBlock2.types create mode 100644 tests/baselines/reference/classStaticBlock3(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock3(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock3(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock3.js create mode 100644 tests/baselines/reference/classStaticBlock3.symbols create mode 100644 tests/baselines/reference/classStaticBlock3.types create mode 100644 tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock4(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock4(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock4(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock4(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock4(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock4(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock4.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock4.js create mode 100644 tests/baselines/reference/classStaticBlock4.symbols create mode 100644 tests/baselines/reference/classStaticBlock4.types create mode 100644 tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock5(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock5(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock5(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock5(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock5(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock5(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock5(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock5(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock5(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock5(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock5.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock5.js create mode 100644 tests/baselines/reference/classStaticBlock5.symbols create mode 100644 tests/baselines/reference/classStaticBlock5.types create mode 100644 tests/baselines/reference/classStaticBlock6.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock6.js create mode 100644 tests/baselines/reference/classStaticBlock6.symbols create mode 100644 tests/baselines/reference/classStaticBlock6.types create mode 100644 tests/baselines/reference/classStaticBlock7.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock7.js create mode 100644 tests/baselines/reference/classStaticBlock7.symbols create mode 100644 tests/baselines/reference/classStaticBlock7.types create mode 100644 tests/baselines/reference/classStaticBlock8.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock8.js create mode 100644 tests/baselines/reference/classStaticBlock8.symbols create mode 100644 tests/baselines/reference/classStaticBlock8.types create mode 100644 tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock9(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock9(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock9(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock9(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock9(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock9(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock9(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock9(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock9(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock9(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock9.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock9.js create mode 100644 tests/baselines/reference/classStaticBlock9.symbols create mode 100644 tests/baselines/reference/classStaticBlock9.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock1.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock10.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock2.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index c6a2b14afdf97..cc30d7cf0a720 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1829,6 +1829,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: @@ -1864,7 +1865,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; @@ -1926,6 +1927,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 diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8daacfbaffefb..b528f85f05e5f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -38038,6 +38038,8 @@ namespace ts { return checkMappedType(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); + case SyntaxKind.ClassStaticBlockDeclaration: + return forEachChild(node, checkSourceElement); case SyntaxKind.Block: case SyntaxKind.ModuleBlock: return checkBlock(node); @@ -41092,7 +41094,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/emitter.ts b/src/compiler/emitter.ts index 2ac23adbeacc8..a4788cde3890b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1341,6 +1341,8 @@ namespace ts { return emitMethodSignature(node); case SyntaxKind.MethodDeclaration: return emitMethodDeclaration(node); + case SyntaxKind.ClassStaticBlockDeclaration: + return emitClassStaticBlockDeclaration(node); case SyntaxKind.Constructor: return emitConstructor(node); case SyntaxKind.GetAccessor: @@ -2008,6 +2010,11 @@ namespace ts { emitSignatureAndBody(node, emitSignatureHead); } + function emitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { + emit(node.staticToken); + emitBlockFunctionBody(node.body); + } + function emitConstructor(node: ConstructorDeclaration) { emitModifiers(node, node.modifiers); writeKeyword("constructor"); @@ -5770,6 +5777,12 @@ namespace ts { visitTypeNode(node.type), visitFunctionBody(node.body)); + case SyntaxKind.ClassStaticBlockDeclaration: + Debug.type(node); + return factory.updateClassStaticBlockDeclaration(node, + visit(node.staticToken, isStaticModifier), + visitFunctionBody(node.body)); + case SyntaxKind.Constructor: Debug.type(node); return factory.updateConstructorDeclaration(node, diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 54a600abd4a7b..6bd135f3bea39 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, @@ -1610,6 +1612,36 @@ namespace ts { : node; } + // @api + function createClassStaticBlockDeclaration( + staticToken: Token, + body: Block + ): ClassStaticBlockDeclaration { + const node = createBaseGenericNamedDeclaration( + SyntaxKind.ClassStaticBlockDeclaration, + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*name*/ undefined, + /*typeParameters*/ undefined + ); + node.staticToken = staticToken; + node.body = body; + node.transformFlags = TransformFlags.ContainsESNext; + return node; + } + + // @api + function updateClassStaticBlockDeclaration( + node: ClassStaticBlockDeclaration, + staticToken: Token, + body: Block + ): ClassStaticBlockDeclaration { + return node.staticToken !== staticToken + || node.body !== body + ? update(createClassStaticBlockDeclaration(staticToken, body), node) + : node; + } + // @api function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateLiteralTypeSpan); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bf336c7e62c4d..8a64412049a95 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -168,6 +168,9 @@ namespace ts { visitNode(cbNode, (node).type) || visitNode(cbNode, (node).equalsGreaterThanToken) || visitNode(cbNode, (node).body); + case SyntaxKind.ClassStaticBlockDeclaration: + return visitNode(cbNode, (node).staticToken) || + visitNode(cbNode, (node).body); case SyntaxKind.TypeReference: return visitNode(cbNode, (node).typeName) || visitNodes(cbNode, cbNodes, (node).typeArguments); @@ -6562,6 +6565,28 @@ namespace ts { return false; } + function parseClassStaticBlockDeclaration(): ClassStaticBlockDeclaration { + const pos = getNodePos(); + const staticKeyworkd = parseExpectedToken(SyntaxKind.StaticKeyword); + const body = parseClassStaticBlockBodyBlock(); + return finishNode(factory.createClassStaticBlockDeclaration(staticKeyworkd, body), pos); + } + + function parseClassStaticBlockBodyBlock() { + const savedYieldContext = inYieldContext(); + setYieldContext(false); + + const savedAwaitContext = inAwaitContext(); + setAwaitContext(false); + + const block = parseBlock(/*ignoreMissingOpenBrace*/ false); + + setAwaitContext(savedAwaitContext); + setYieldContext(savedYieldContext); + + return block; + } + function parseDecoratorExpression() { if (inAwaitContext() && token() === SyntaxKind.AwaitKeyword) { // `@await` is is disallowed in an [Await] context, but can cause parsing to go off the rails @@ -6646,6 +6671,9 @@ namespace ts { nextToken(); return finishNode(factory.createSemicolonClassElement(), pos); } + if (token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) { + return parseClassStaticBlockDeclaration(); + } const hasJSDoc = hasPrecedingJSDocComment(); const decorators = parseDecorators(); @@ -6911,6 +6939,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/ts.ts b/src/compiler/transformers/ts.ts index 0d24f332c15bd..2a7457b8e0954 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/types.ts b/src/compiler/types.ts index 3d70582fdaf33..c942e857e00f7 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -208,6 +208,7 @@ namespace ts { SetAccessor, CallSignature, ConstructSignature, + ClassStaticBlockDeclaration, IndexSignature, // Type TypePredicate, @@ -1502,6 +1503,12 @@ namespace ts { readonly type: TypeNode; } + export interface ClassStaticBlockDeclaration extends ClassElement { + readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly staticToken: Token; + readonly body: Block; + } + export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -6932,6 +6939,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(staticToken: Token, body: Block): ClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, staticToken: Token, body: Block): ClassStaticBlockDeclaration; // // Types diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6df07c9b013b3..c71fea3b69c40 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1601,6 +1601,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 8285699d08753..fdd95633d2efa 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1221,6 +1221,14 @@ namespace ts { return !!node && isFunctionLikeKind(node.kind); } + export function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration { + return node.kind === SyntaxKind.ClassStaticBlockDeclaration; + } + + 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); @@ -1272,6 +1280,7 @@ namespace ts { || kind === SyntaxKind.GetAccessor || kind === SyntaxKind.SetAccessor || kind === SyntaxKind.IndexSignature + || kind === SyntaxKind.ClassStaticBlockDeclaration || kind === SyntaxKind.SemicolonClassElement; } diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 960cd16f8479b..3ccfdde23bde0 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -475,6 +475,14 @@ 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, + nodeVisitor(node.staticToken, visitor, isStaticModifier), + visitFunctionBody(node.body, visitor, context, nodeVisitor)); + case SyntaxKind.CallSignature: Debug.type(node); return factory.updateCallSignature(node, diff --git a/tests/baselines/reference/classStaticBlock1(target=es2015).js b/tests/baselines/reference/classStaticBlock1(target=es2015).js new file mode 100644 index 0000000000000..c852add6ad402 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es2015).js @@ -0,0 +1,16 @@ +//// [classStaticBlock1.ts] +const a = 2; + +class C { + static { + const a = 1; + + a; + } +} + + +//// [classStaticBlock1.js] +const a = 2; +class C { +} 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..58eccef93a8a5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1(target=es5).js @@ -0,0 +1,19 @@ +//// [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; +}()); 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/classStaticBlock1.js b/tests/baselines/reference/classStaticBlock1.js new file mode 100644 index 0000000000000..58eccef93a8a5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1.js @@ -0,0 +1,19 @@ +//// [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; +}()); diff --git a/tests/baselines/reference/classStaticBlock1.symbols b/tests/baselines/reference/classStaticBlock1.symbols new file mode 100644 index 0000000000000..e4aa99e0d68d5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1.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.types b/tests/baselines/reference/classStaticBlock1.types new file mode 100644 index 0000000000000..a0fd3b4d6480a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock1.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..6e1685db40c3a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es2015).js @@ -0,0 +1,42 @@ +//// [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 { + } +} +class C2 { +} 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..faa79b8dae154 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10(target=es5).js @@ -0,0 +1,48 @@ +//// [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; + }()); +} +var C2 = /** @class */ (function () { + function C2() { + } + return C2; +}()); 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/classStaticBlock10.js b/tests/baselines/reference/classStaticBlock10.js new file mode 100644 index 0000000000000..faa79b8dae154 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10.js @@ -0,0 +1,48 @@ +//// [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; + }()); +} +var C2 = /** @class */ (function () { + function C2() { + } + return C2; +}()); diff --git a/tests/baselines/reference/classStaticBlock10.symbols b/tests/baselines/reference/classStaticBlock10.symbols new file mode 100644 index 0000000000000..12d2d16b0784c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10.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.types b/tests/baselines/reference/classStaticBlock10.types new file mode 100644 index 0000000000000..dbbf3ebd6b0a4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock10.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/classStaticBlock2(target=es2015).js b/tests/baselines/reference/classStaticBlock2(target=es2015).js new file mode 100644 index 0000000000000..d9477576ca879 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es2015).js @@ -0,0 +1,26 @@ +//// [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 { +} 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..e535663fcdeaa --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2(target=es5).js @@ -0,0 +1,29 @@ +//// [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; +}()); 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/classStaticBlock2.js b/tests/baselines/reference/classStaticBlock2.js new file mode 100644 index 0000000000000..e535663fcdeaa --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2.js @@ -0,0 +1,29 @@ +//// [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; +}()); diff --git a/tests/baselines/reference/classStaticBlock2.symbols b/tests/baselines/reference/classStaticBlock2.symbols new file mode 100644 index 0000000000000..93bfa964aaeb6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2.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.types b/tests/baselines/reference/classStaticBlock2.types new file mode 100644 index 0000000000000..2e22833b22ddf --- /dev/null +++ b/tests/baselines/reference/classStaticBlock2.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/classStaticBlock3(target=es2015).js b/tests/baselines/reference/classStaticBlock3(target=es2015).js new file mode 100644 index 0000000000000..9d352771472d1 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es2015).js @@ -0,0 +1,27 @@ +//// [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 { +} +C.f1 = 1; +C.f2 = 2; +C.f3 = 3; diff --git a/tests/baselines/reference/classStaticBlock3(target=es2015).symbols b/tests/baselines/reference/classStaticBlock3(target=es2015).symbols new file mode 100644 index 0000000000000..758fa0790609a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es2015).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(target=es2015).types b/tests/baselines/reference/classStaticBlock3(target=es2015).types new file mode 100644 index 0000000000000..d5705a72e8775 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es2015).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/classStaticBlock3(target=es5).js b/tests/baselines/reference/classStaticBlock3(target=es5).js new file mode 100644 index 0000000000000..5dfb77ff34ba9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es5).js @@ -0,0 +1,30 @@ +//// [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] +var a = 1; +var C = /** @class */ (function () { + function C() { + } + C.f1 = 1; + C.f2 = 2; + C.f3 = 3; + return C; +}()); diff --git a/tests/baselines/reference/classStaticBlock3(target=es5).symbols b/tests/baselines/reference/classStaticBlock3(target=es5).symbols new file mode 100644 index 0000000000000..758fa0790609a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es5).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(target=es5).types b/tests/baselines/reference/classStaticBlock3(target=es5).types new file mode 100644 index 0000000000000..d5705a72e8775 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es5).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/classStaticBlock3(target=esnext).js b/tests/baselines/reference/classStaticBlock3(target=esnext).js new file mode 100644 index 0000000000000..548d2aaa16f27 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=esnext).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 { + console.log(C.f1, C.f2, C.f3); + } + static { + console.log(C.f1, C.f2, C.f3); + } +} +C.f1 = 1; +C.f2 = 2; +C.f3 = 3; diff --git a/tests/baselines/reference/classStaticBlock3(target=esnext).symbols b/tests/baselines/reference/classStaticBlock3(target=esnext).symbols new file mode 100644 index 0000000000000..758fa0790609a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=esnext).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(target=esnext).types b/tests/baselines/reference/classStaticBlock3(target=esnext).types new file mode 100644 index 0000000000000..d5705a72e8775 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=esnext).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/classStaticBlock3.js b/tests/baselines/reference/classStaticBlock3.js new file mode 100644 index 0000000000000..5dfb77ff34ba9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3.js @@ -0,0 +1,30 @@ +//// [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] +var a = 1; +var C = /** @class */ (function () { + function C() { + } + C.f1 = 1; + C.f2 = 2; + C.f3 = 3; + return C; +}()); 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(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt new file mode 100644 index 0000000000000..87e988d8b1c6e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== + class C { + static s1 = 1; + + static { + this.s1; + ~~ +!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? + C.s1; + + this.s2; + ~~ +!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? + C.s2; + } + + static s2 = 2; + static ss2 = this.s1; + ~~~~ +!!! error TS2334: 'this' cannot be referenced in a static property initializer. + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).js b/tests/baselines/reference/classStaticBlock4(target=es2015).js new file mode 100644 index 0000000000000..05889c7f02fa9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).js @@ -0,0 +1,23 @@ +//// [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 { +} +C.s1 = 1; +C.s2 = 2; +C.ss2 = this.s1; diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).symbols b/tests/baselines/reference/classStaticBlock4(target=es2015).symbols new file mode 100644 index 0000000000000..5b812c63d7121 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).symbols @@ -0,0 +1,35 @@ +=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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(target=es2015).types b/tests/baselines/reference/classStaticBlock4(target=es2015).types new file mode 100644 index 0000000000000..91d7ba0613136 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).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 : any +>this : this +>s1 : any + + C.s1; +>C.s1 : number +>C : typeof C +>s1 : number + + this.s2; +>this.s2 : any +>this : this +>s2 : any + + 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/classStaticBlock4(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt new file mode 100644 index 0000000000000..87e988d8b1c6e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== + class C { + static s1 = 1; + + static { + this.s1; + ~~ +!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? + C.s1; + + this.s2; + ~~ +!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? + C.s2; + } + + static s2 = 2; + static ss2 = this.s1; + ~~~~ +!!! error TS2334: 'this' cannot be referenced in a static property initializer. + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).js b/tests/baselines/reference/classStaticBlock4(target=es5).js new file mode 100644 index 0000000000000..adba8791e76e7 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es5).js @@ -0,0 +1,26 @@ +//// [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] +var C = /** @class */ (function () { + function C() { + } + C.s1 = 1; + C.s2 = 2; + C.ss2 = this.s1; + return C; +}()); diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).symbols b/tests/baselines/reference/classStaticBlock4(target=es5).symbols new file mode 100644 index 0000000000000..5b812c63d7121 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es5).symbols @@ -0,0 +1,35 @@ +=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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(target=es5).types b/tests/baselines/reference/classStaticBlock4(target=es5).types new file mode 100644 index 0000000000000..91d7ba0613136 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=es5).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 : any +>this : this +>s1 : any + + C.s1; +>C.s1 : number +>C : typeof C +>s1 : number + + this.s2; +>this.s2 : any +>this : this +>s2 : any + + 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/classStaticBlock4(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt new file mode 100644 index 0000000000000..87e988d8b1c6e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== + class C { + static s1 = 1; + + static { + this.s1; + ~~ +!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? + C.s1; + + this.s2; + ~~ +!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? + C.s2; + } + + static s2 = 2; + static ss2 = this.s1; + ~~~~ +!!! error TS2334: 'this' cannot be referenced in a static property initializer. + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4(target=esnext).js b/tests/baselines/reference/classStaticBlock4(target=esnext).js new file mode 100644 index 0000000000000..9bc8a29c8ac43 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).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 { + this.s1; + C.s1; + this.s2; + C.s2; + } +} +C.s1 = 1; +C.s2 = 2; +C.ss2 = this.s1; diff --git a/tests/baselines/reference/classStaticBlock4(target=esnext).symbols b/tests/baselines/reference/classStaticBlock4(target=esnext).symbols new file mode 100644 index 0000000000000..5b812c63d7121 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).symbols @@ -0,0 +1,35 @@ +=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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(target=esnext).types b/tests/baselines/reference/classStaticBlock4(target=esnext).types new file mode 100644 index 0000000000000..91d7ba0613136 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).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 : any +>this : this +>s1 : any + + C.s1; +>C.s1 : number +>C : typeof C +>s1 : number + + this.s2; +>this.s2 : any +>this : this +>s2 : any + + 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/classStaticBlock4.errors.txt b/tests/baselines/reference/classStaticBlock4.errors.txt new file mode 100644 index 0000000000000..87e988d8b1c6e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== + class C { + static s1 = 1; + + static { + this.s1; + ~~ +!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? + C.s1; + + this.s2; + ~~ +!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? + C.s2; + } + + static s2 = 2; + static ss2 = this.s1; + ~~~~ +!!! error TS2334: 'this' cannot be referenced in a static property initializer. + } + \ 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..adba8791e76e7 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.js @@ -0,0 +1,26 @@ +//// [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] +var C = /** @class */ (function () { + function C() { + } + C.s1 = 1; + C.s2 = 2; + C.ss2 = this.s1; + return C; +}()); diff --git a/tests/baselines/reference/classStaticBlock4.symbols b/tests/baselines/reference/classStaticBlock4.symbols new file mode 100644 index 0000000000000..5b812c63d7121 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock4.symbols @@ -0,0 +1,35 @@ +=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) + + 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..91d7ba0613136 --- /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 : any +>this : this +>s1 : any + + C.s1; +>C.s1 : number +>C : typeof C +>s1 : number + + this.s2; +>this.s2 : any +>this : this +>s2 : any + + 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..eeabc4440f902 --- /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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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 TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + 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..b23360c01866e --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).js @@ -0,0 +1,27 @@ +//// [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; diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).symbols b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols new file mode 100644 index 0000000000000..2e0175423fafb --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols @@ -0,0 +1,30 @@ +=== 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 : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) + + 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..9e0dfa94d3fee --- /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 : any +>this : this +>b : any + + 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..eeabc4440f902 --- /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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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 TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + 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..5f5d79c670049 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es5).js @@ -0,0 +1,50 @@ +//// [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 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; + 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..2e0175423fafb --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=es5).symbols @@ -0,0 +1,30 @@ +=== 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 : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) + + 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..9e0dfa94d3fee --- /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 : any +>this : this +>b : any + + 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..eeabc4440f902 --- /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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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 TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + 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..8132aada6b28d --- /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 { +} +B.a = 1; +B.b = 2; +class C extends B { + static { + this.b; + super.b; + super.a; + } +} +C.b = 3; +C.c = 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..2e0175423fafb --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols @@ -0,0 +1,30 @@ +=== 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 : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) + + 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..9e0dfa94d3fee --- /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 : any +>this : this +>b : any + + 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.errors.txt b/tests/baselines/reference/classStaticBlock5.errors.txt new file mode 100644 index 0000000000000..eeabc4440f902 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5.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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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 TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + 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.js b/tests/baselines/reference/classStaticBlock5.js new file mode 100644 index 0000000000000..5f5d79c670049 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5.js @@ -0,0 +1,50 @@ +//// [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 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; + return C; +}(B)); diff --git a/tests/baselines/reference/classStaticBlock5.symbols b/tests/baselines/reference/classStaticBlock5.symbols new file mode 100644 index 0000000000000..2e0175423fafb --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5.symbols @@ -0,0 +1,30 @@ +=== 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 : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) + + super.b; + super.a; + } +} + diff --git a/tests/baselines/reference/classStaticBlock5.types b/tests/baselines/reference/classStaticBlock5.types new file mode 100644 index 0000000000000..9e0dfa94d3fee --- /dev/null +++ b/tests/baselines/reference/classStaticBlock5.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 : any +>this : this +>b : any + + 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..6b18acbb48a3b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -0,0 +1,33 @@ +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(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (3 errors) ==== + class B { + static a = 1; + } + + class C extends B { + static { + var await = 1; + var arguments = 1; + ~~~~~~~~~ +!!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. + var eval = 1; + ~~~~ +!!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode. + + + await: if (true) { + + } + + arguments; + await; + super(); + ~~~~~ +!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js new file mode 100644 index 0000000000000..a2e3c0082ffd4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.js @@ -0,0 +1,52 @@ +//// [classStaticBlock6.ts] +class B { + static a = 1; +} + +class C extends B { + static { + var await = 1; + var arguments = 1; + var eval = 1; + + + await: if (true) { + + } + + arguments; + await; + super(); + } +} + + +//// [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 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)); diff --git a/tests/baselines/reference/classStaticBlock6.symbols b/tests/baselines/reference/classStaticBlock6.symbols new file mode 100644 index 0000000000000..9d604e9bcabc3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.symbols @@ -0,0 +1,37 @@ +=== 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 { + var await = 1; +>await : Symbol(await, Decl(classStaticBlock6.ts, 6, 11)) + + var arguments = 1; +>arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) + + var eval = 1; +>eval : Symbol(eval, Decl(classStaticBlock6.ts, 8, 11)) + + + await: if (true) { + + } + + arguments; +>arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) + + await; +>await : Symbol(await, Decl(classStaticBlock6.ts, 6, 11)) + + super(); + } +} + diff --git a/tests/baselines/reference/classStaticBlock6.types b/tests/baselines/reference/classStaticBlock6.types new file mode 100644 index 0000000000000..11e2f3753bc6d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock6.types @@ -0,0 +1,45 @@ +=== 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 { + var await = 1; +>await : number +>1 : 1 + + var arguments = 1; +>arguments : number +>1 : 1 + + var eval = 1; +>eval : number +>1 : 1 + + + await: if (true) { +>await : any +>true : true + + } + + arguments; +>arguments : number + + await; +>await : number + + super(); +>super() : void +>super : any + } +} + diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt new file mode 100644 index 0000000000000..891d67478e9d3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. +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 TS1108: A 'return' statement can only be used within a function body. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (3 errors) ==== + class C { + static { + await 1; + ~~~~~ +!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. + yield 1; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + return 1; + ~~~~~~ +!!! error TS1108: A 'return' statement can only be used within a function body. + } + } + \ 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..de4d361871310 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.js @@ -0,0 +1,16 @@ +//// [classStaticBlock7.ts] +class C { + static { + await 1; + yield 1; + return 1; + } +} + + +//// [classStaticBlock7.js] +var C = /** @class */ (function () { + function C() { + } + return C; +}()); diff --git a/tests/baselines/reference/classStaticBlock7.symbols b/tests/baselines/reference/classStaticBlock7.symbols new file mode 100644 index 0000000000000..ab40a1f74e18c --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock7.ts, 0, 0)) + + static { + await 1; + yield 1; + return 1; + } +} + diff --git a/tests/baselines/reference/classStaticBlock7.types b/tests/baselines/reference/classStaticBlock7.types new file mode 100644 index 0000000000000..d1e8ba48866f6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock7.types @@ -0,0 +1,18 @@ +=== 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 + } +} + diff --git a/tests/baselines/reference/classStaticBlock8.errors.txt b/tests/baselines/reference/classStaticBlock8.errors.txt new file mode 100644 index 0000000000000..a605f7f309ea0 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(9,21): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. +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(25,13): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(28,13): error TS1107: Jump target cannot cross function boundary. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(31,13): error TS1107: Jump target cannot cross function boundary. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts (6 errors) ==== + function foo (v: number) { + label: if (v) { + class C { + static { + if (v === 1) { + break label; + } + if (v === 2) { + continue label; + ~~~~~~~~~~~~~~~ +!!! error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. + } + 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; + ~~~~~~~~~~~~~~~ +!!! error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. + } + if (v === 7) { + break; + ~~~~~~ +!!! error TS1107: Jump target cannot cross function boundary. + } + if (v === 8) { + continue; + ~~~~~~~~~ +!!! error TS1107: Jump target cannot cross function boundary. + } + } + } + \ 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..7b3bfe4f29978 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.js @@ -0,0 +1,59 @@ +//// [classStaticBlock8.ts] +function foo (v: number) { + label: if (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; + } + } +} + + +//// [classStaticBlock8.js] +function foo(v) { + label: if (v) { + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + if (v === 5) { + break label; + } + if (v === 6) { + continue label; + } + if (v === 7) { + break; + } + if (v === 8) { + continue; + } + } +} diff --git a/tests/baselines/reference/classStaticBlock8.symbols b/tests/baselines/reference/classStaticBlock8.symbols new file mode 100644 index 0000000000000..ed735ce743148 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.symbols @@ -0,0 +1,59 @@ +=== 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: if (v) { +>v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) + + class C { +>C : Symbol(C, Decl(classStaticBlock8.ts, 1, 19)) + + 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; + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock8.types b/tests/baselines/reference/classStaticBlock8.types new file mode 100644 index 0000000000000..485b067e289d6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock8.types @@ -0,0 +1,80 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts === +function foo (v: number) { +>foo : (v: number) => void +>v : number + + label: if (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; + } + } +} + 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..32788846e768a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt @@ -0,0 +1,15 @@ +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 (1 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; + } + 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..6d77595ffba36 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).js @@ -0,0 +1,15 @@ +//// [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 = 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..32788846e768a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt @@ -0,0 +1,15 @@ +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 (1 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; + } + 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..1eb6145d9b62f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=es5).js @@ -0,0 +1,18 @@ +//// [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; + 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..32788846e768a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt @@ -0,0 +1,15 @@ +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 (1 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; + } + 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..e680483660562 --- /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 { + A.foo + 2; + } +} +A.bar = A.foo + 1; +A.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/classStaticBlock9.errors.txt b/tests/baselines/reference/classStaticBlock9.errors.txt new file mode 100644 index 0000000000000..32788846e768a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9.errors.txt @@ -0,0 +1,15 @@ +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 (1 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; + } + static foo = 1; + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock9.js b/tests/baselines/reference/classStaticBlock9.js new file mode 100644 index 0000000000000..1eb6145d9b62f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9.js @@ -0,0 +1,18 @@ +//// [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; + A.foo = 1; + return A; +}()); diff --git a/tests/baselines/reference/classStaticBlock9.symbols b/tests/baselines/reference/classStaticBlock9.symbols new file mode 100644 index 0000000000000..2cb44695c8328 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9.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.types b/tests/baselines/reference/classStaticBlock9.types new file mode 100644 index 0000000000000..9ac192ac54bed --- /dev/null +++ b/tests/baselines/reference/classStaticBlock9.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/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/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/classStaticBlock3.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts new file mode 100644 index 0000000000000..f34912cb5b650 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts @@ -0,0 +1,19 @@ +// @target: esnext, es2015, es5 + +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..2b8696fe08d5d --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts @@ -0,0 +1,16 @@ +// @target: esnext, es2015, es5 + +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..24eef812abc38 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts @@ -0,0 +1,20 @@ +class B { + static a = 1; +} + +class C extends B { + static { + var await = 1; + var arguments = 1; + var eval = 1; + + + await: if (true) { + + } + + arguments; + await; + super(); + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts new file mode 100644 index 0000000000000..d3daa8bd21cdb --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts @@ -0,0 +1,7 @@ +class C { + static { + await 1; + yield 1; + 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..c1eb8ef10f16a --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts @@ -0,0 +1,33 @@ +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; + } + } +} 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; +} From 188cf27666edb3aac34da6719c78d99ece024880 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 19 Mar 2021 15:43:55 +0800 Subject: [PATCH 02/36] Add basic transformer --- src/compiler/factory/nodeFactory.ts | 2 +- src/compiler/transformers/classFields.ts | 27 +++++++++++++++++-- src/compiler/transformers/es2015.ts | 1 + src/compiler/transformers/utilities.ts | 2 +- .../classStaticBlock3(target=es2015).js | 12 +++++++++ .../classStaticBlock3(target=es5).js | 12 +++++++++ .../classStaticBlock4(target=es2015).js | 12 +++++++++ .../classStaticBlock4(target=es5).js | 13 +++++++++ .../classStaticBlock5(target=es2015).js | 11 ++++++++ .../classStaticBlock5(target=es5).js | 12 +++++++++ .../reference/classStaticBlock8.errors.txt | 21 +++++---------- .../baselines/reference/classStaticBlock8.js | 5 ++-- .../reference/classStaticBlock8.symbols | 5 ++-- .../reference/classStaticBlock8.types | 3 +-- .../classStaticBlock9(target=es2015).js | 9 +++++++ .../classStaticBlock9(target=es5).js | 9 +++++++ 16 files changed, 130 insertions(+), 26 deletions(-) diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 6bd135f3bea39..d4777b94429c8 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1626,7 +1626,7 @@ namespace ts { ); node.staticToken = staticToken; node.body = body; - node.transformFlags = TransformFlags.ContainsESNext; + node.transformFlags = TransformFlags.ContainsClassFields; return node; } diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index ff6b53655f01d..acba02bfad263 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -175,10 +175,19 @@ 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 (!shouldTransformPrivateElements) { + return visitEachChild(node, classElementVisitor, context); + } + return undefined; + } + function visitorDestructuringTarget(node: Node): VisitResult { switch (node.kind) { case SyntaxKind.ObjectLiteralExpression: @@ -530,6 +539,20 @@ namespace ts { return visitEachChild(node, visitor, context); } + function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { + if (shouldTransformPrivateElements) { + receiver = visitNode(receiver, visitor, isExpression); + const right = factory.createImmediatelyInvokedArrowFunction(visitNodes(node.body.statements, visitor, isBlock)); + return context.getEmitHelperFactory().createClassPrivateFieldSetHelper( + receiver, + factory.createUniqueName("_"), + right, + PrivateIdentifierKind.Field, + /*f*/ undefined + ); + } + } + function visitBinaryExpression(node: BinaryExpression) { if (shouldTransformPrivateElements) { if (isDestructuringAssignment(node)) { @@ -955,9 +978,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 addPropertyStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { for (const property of properties) { - const expression = transformProperty(property, receiver); + const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property, receiver) : transformProperty(property, receiver); if (!expression) { continue; } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 6f28a651190e7..288a09a63f4b6 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1595,6 +1595,7 @@ namespace ts { break; case SyntaxKind.Constructor: + case SyntaxKind.ClassStaticBlockDeclaration: // Constructors are handled in visitClassExpression/visitClassDeclaration break; diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index e1c3b0b957d6d..0bc1c3edcef2d 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -339,7 +339,7 @@ namespace ts { export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: true, isStatic: boolean): readonly InitializedPropertyDeclaration[]; export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[]; export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[] { - return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; + return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic) || isStatic && isClassStaticBlockDeclaration(m)) as PropertyDeclaration[]; } /** diff --git a/tests/baselines/reference/classStaticBlock3(target=es2015).js b/tests/baselines/reference/classStaticBlock3(target=es2015).js index 9d352771472d1..f188c5f0d4bef 100644 --- a/tests/baselines/reference/classStaticBlock3(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock3(target=es2015).js @@ -19,9 +19,21 @@ class C { //// [classStaticBlock3.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; +}; const a = 1; class C { } C.f1 = 1; +__classPrivateFieldSet(C, _1, (() => { + console.log(C.f1, C.f2, C.f3); +})(), "f"); C.f2 = 2; +__classPrivateFieldSet(C, _2, (() => { + console.log(C.f1, C.f2, C.f3); +})(), "f"); C.f3 = 3; diff --git a/tests/baselines/reference/classStaticBlock3(target=es5).js b/tests/baselines/reference/classStaticBlock3(target=es5).js index 5dfb77ff34ba9..77151586b9810 100644 --- a/tests/baselines/reference/classStaticBlock3(target=es5).js +++ b/tests/baselines/reference/classStaticBlock3(target=es5).js @@ -19,12 +19,24 @@ class C { //// [classStaticBlock3.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 a = 1; var C = /** @class */ (function () { function C() { } C.f1 = 1; + __classPrivateFieldSet(C, _1, (function () { + console.log(C.f1, C.f2, C.f3); + })(), "f"); C.f2 = 2; + __classPrivateFieldSet(C, _2, (function () { + console.log(C.f1, C.f2, C.f3); + })(), "f"); C.f3 = 3; return C; }()); diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).js b/tests/baselines/reference/classStaticBlock4(target=es2015).js index 05889c7f02fa9..faa662beb8d0a 100644 --- a/tests/baselines/reference/classStaticBlock4(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).js @@ -16,8 +16,20 @@ class C { //// [classStaticBlock4.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; +}; class C { } C.s1 = 1; +__classPrivateFieldSet(C, _1, (() => { + this.s1; + C.s1; + this.s2; + C.s2; +})(), "f"); C.s2 = 2; C.ss2 = this.s1; diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).js b/tests/baselines/reference/classStaticBlock4(target=es5).js index adba8791e76e7..1e70d121bba3f 100644 --- a/tests/baselines/reference/classStaticBlock4(target=es5).js +++ b/tests/baselines/reference/classStaticBlock4(target=es5).js @@ -16,10 +16,23 @@ class C { //// [classStaticBlock4.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 _this = this; var C = /** @class */ (function () { function C() { } C.s1 = 1; + __classPrivateFieldSet(C, _1, (function () { + _this.s1; + C.s1; + _this.s2; + C.s2; + })(), "f"); C.s2 = 2; C.ss2 = this.s1; return C; diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).js b/tests/baselines/reference/classStaticBlock5(target=es2015).js index b23360c01866e..18515f7dddb0c 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).js @@ -17,6 +17,12 @@ class C extends B { //// [classStaticBlock5.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; +}; class B { } B.a = 1; @@ -25,3 +31,8 @@ class C extends B { } C.b = 3; C.c = super.a; +__classPrivateFieldSet(C, _1, (() => { + this.b; + super.b; + super.a; +})(), "f"); diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).js b/tests/baselines/reference/classStaticBlock5(target=es5).js index 5f5d79c670049..cb5588cf934a3 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).js +++ b/tests/baselines/reference/classStaticBlock5(target=es5).js @@ -32,6 +32,13 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +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 _this = this; var B = /** @class */ (function () { function B() { } @@ -46,5 +53,10 @@ var C = /** @class */ (function (_super) { } C.b = 3; C.c = _super.a; + __classPrivateFieldSet(C, _1, (function () { + _this.b; + _super.b; + _super.a; + })(), "f"); return C; }(B)); diff --git a/tests/baselines/reference/classStaticBlock8.errors.txt b/tests/baselines/reference/classStaticBlock8.errors.txt index a605f7f309ea0..ec20040143e3c 100644 --- a/tests/baselines/reference/classStaticBlock8.errors.txt +++ b/tests/baselines/reference/classStaticBlock8.errors.txt @@ -1,23 +1,23 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(9,21): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. +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(25,13): error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(28,13): error TS1107: Jump target cannot cross function boundary. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(31,13): error TS1107: Jump target cannot cross function boundary. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts (6 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts (4 errors) ==== function foo (v: number) { - label: if (v) { + 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 TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. +!!! error TS1107: Jump target cannot cross function boundary. } if (v === 3) { break @@ -29,7 +29,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(31,13): er ~~~~~~~~ !!! error TS1107: Jump target cannot cross function boundary. } - } } @@ -38,18 +37,12 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(31,13): er } if (v === 6) { continue label; - ~~~~~~~~~~~~~~~ -!!! error TS1115: A 'continue' statement can only jump to a label of an enclosing iteration statement. } if (v === 7) { break; - ~~~~~~ -!!! error TS1107: Jump target cannot cross function boundary. } if (v === 8) { continue; - ~~~~~~~~~ -!!! error TS1107: Jump target cannot cross function boundary. } } } diff --git a/tests/baselines/reference/classStaticBlock8.js b/tests/baselines/reference/classStaticBlock8.js index 7b3bfe4f29978..a8667ac2a80bb 100644 --- a/tests/baselines/reference/classStaticBlock8.js +++ b/tests/baselines/reference/classStaticBlock8.js @@ -1,6 +1,6 @@ //// [classStaticBlock8.ts] function foo (v: number) { - label: if (v) { + label: while (v) { class C { static { if (v === 1) { @@ -15,7 +15,6 @@ function foo (v: number) { if (v === 4) { continue } - } } @@ -37,7 +36,7 @@ function foo (v: number) { //// [classStaticBlock8.js] function foo(v) { - label: if (v) { + label: while (v) { var C = /** @class */ (function () { function C() { } diff --git a/tests/baselines/reference/classStaticBlock8.symbols b/tests/baselines/reference/classStaticBlock8.symbols index ed735ce743148..0d0c47c2aa459 100644 --- a/tests/baselines/reference/classStaticBlock8.symbols +++ b/tests/baselines/reference/classStaticBlock8.symbols @@ -3,11 +3,11 @@ function foo (v: number) { >foo : Symbol(foo, Decl(classStaticBlock8.ts, 0, 0)) >v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) - label: if (v) { + label: while (v) { >v : Symbol(v, Decl(classStaticBlock8.ts, 0, 14)) class C { ->C : Symbol(C, Decl(classStaticBlock8.ts, 1, 19)) +>C : Symbol(C, Decl(classStaticBlock8.ts, 1, 22)) static { if (v === 1) { @@ -30,7 +30,6 @@ function foo (v: number) { continue } - } } diff --git a/tests/baselines/reference/classStaticBlock8.types b/tests/baselines/reference/classStaticBlock8.types index 485b067e289d6..3c360846b9b1c 100644 --- a/tests/baselines/reference/classStaticBlock8.types +++ b/tests/baselines/reference/classStaticBlock8.types @@ -3,7 +3,7 @@ function foo (v: number) { >foo : (v: number) => void >v : number - label: if (v) { + label: while (v) { >label : any >v : number @@ -41,7 +41,6 @@ function foo (v: number) { continue } - } } diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).js b/tests/baselines/reference/classStaticBlock9(target=es2015).js index 6d77595ffba36..65435050082bf 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).js @@ -9,7 +9,16 @@ class A { //// [classStaticBlock9.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; +}; class A { } A.bar = A.foo + 1; +__classPrivateFieldSet(A, _1, (() => { + A.foo + 2; +})(), "f"); A.foo = 1; diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).js b/tests/baselines/reference/classStaticBlock9(target=es5).js index 1eb6145d9b62f..85d97efacbe6a 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es5).js +++ b/tests/baselines/reference/classStaticBlock9(target=es5).js @@ -9,10 +9,19 @@ class A { //// [classStaticBlock9.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 A = /** @class */ (function () { function A() { } A.bar = A.foo + 1; + __classPrivateFieldSet(A, _1, (function () { + A.foo + 2; + })(), "f"); A.foo = 1; return A; }()); From e26d82a9eff3dbc53bd1b7a7df61076a772fcbf7 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 19 Mar 2021 16:51:00 +0800 Subject: [PATCH 03/36] Fix emit behavior --- src/compiler/factory/nodeFactory.ts | 2 +- src/compiler/transformers/classFields.ts | 14 +++---- .../classStaticBlock11(target=es2015).js | 40 ++++++++++++++++++ .../classStaticBlock11(target=es2015).symbols | 30 ++++++++++++++ .../classStaticBlock11(target=es2015).types | 33 +++++++++++++++ .../classStaticBlock11(target=es5).errors.txt | 19 +++++++++ .../classStaticBlock11(target=es5).js | 41 +++++++++++++++++++ .../classStaticBlock11(target=es5).symbols | 30 ++++++++++++++ .../classStaticBlock11(target=es5).types | 33 +++++++++++++++ .../classStaticBlock11(target=esnext).js | 28 +++++++++++++ .../classStaticBlock11(target=esnext).symbols | 30 ++++++++++++++ .../classStaticBlock11(target=esnext).types | 33 +++++++++++++++ .../reference/classStaticBlock12.errors.txt | 14 +++++++ .../baselines/reference/classStaticBlock12.js | 27 ++++++++++++ .../reference/classStaticBlock12.symbols | 14 +++++++ .../reference/classStaticBlock12.types | 15 +++++++ .../classStaticBlock13(target=es2015).js | 31 ++++++++++++++ .../classStaticBlock13(target=es2015).symbols | 25 +++++++++++ .../classStaticBlock13(target=es2015).types | 27 ++++++++++++ .../classStaticBlock13(target=es5).errors.txt | 18 ++++++++ .../classStaticBlock13(target=es5).js | 39 ++++++++++++++++++ .../classStaticBlock13(target=es5).symbols | 25 +++++++++++ .../classStaticBlock13(target=es5).types | 27 ++++++++++++ .../classStaticBlock13(target=esnext).js | 24 +++++++++++ .../classStaticBlock13(target=esnext).symbols | 25 +++++++++++ .../classStaticBlock13(target=esnext).types | 27 ++++++++++++ .../reference/classStaticBlock14.errors.txt | 25 +++++++++++ .../baselines/reference/classStaticBlock14.js | 38 +++++++++++++++++ .../reference/classStaticBlock14.symbols | 21 ++++++++++ .../reference/classStaticBlock14.types | 24 +++++++++++ ...assStaticBlock15(target=es2015).errors.txt | 21 ++++++++++ .../classStaticBlock15(target=es2015).js | 38 +++++++++++++++++ .../classStaticBlock15(target=es2015).symbols | 26 ++++++++++++ .../classStaticBlock15(target=es2015).types | 31 ++++++++++++++ .../classStaticBlock15(target=es5).errors.txt | 30 ++++++++++++++ .../classStaticBlock15(target=es5).js | 41 +++++++++++++++++++ .../classStaticBlock15(target=es5).symbols | 26 ++++++++++++ .../classStaticBlock15(target=es5).types | 31 ++++++++++++++ ...assStaticBlock15(target=esnext).errors.txt | 21 ++++++++++ .../classStaticBlock15(target=esnext).js | 30 ++++++++++++++ .../classStaticBlock15(target=esnext).symbols | 26 ++++++++++++ .../classStaticBlock15(target=esnext).types | 31 ++++++++++++++ .../classStaticBlock3(target=es2015).js | 19 ++++----- .../classStaticBlock3(target=es5).js | 19 ++++----- .../classStaticBlock4(target=es2015).js | 19 ++++----- .../classStaticBlock4(target=es5).js | 19 ++++----- .../classStaticBlock5(target=es2015).js | 17 +++----- .../classStaticBlock5(target=es5).js | 17 +++----- .../classStaticBlock9(target=es2015).js | 13 ++---- .../classStaticBlock9(target=es5).js | 13 ++---- .../classStaticBlock/classStaticBlock11.ts | 14 +++++++ .../classStaticBlock/classStaticBlock12.ts | 9 ++++ .../classStaticBlock/classStaticBlock13.ts | 14 +++++++ .../classStaticBlock/classStaticBlock14.ts | 14 +++++++ .../classStaticBlock/classStaticBlock15.ts | 17 ++++++++ 55 files changed, 1238 insertions(+), 97 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock11(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock11(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock11(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock11(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock11(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock11(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock12.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock12.js create mode 100644 tests/baselines/reference/classStaticBlock12.symbols create mode 100644 tests/baselines/reference/classStaticBlock12.types create mode 100644 tests/baselines/reference/classStaticBlock13(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock13(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock13(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock13(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock13(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock13(target=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock14.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock14.js create mode 100644 tests/baselines/reference/classStaticBlock14.symbols create mode 100644 tests/baselines/reference/classStaticBlock14.types create mode 100644 tests/baselines/reference/classStaticBlock15(target=es2015).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock15(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock15(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock15(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock15(target=esnext).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock15(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock15(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock15(target=esnext).types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index d4777b94429c8..5d7c6e678e166 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1626,7 +1626,7 @@ namespace ts { ); node.staticToken = staticToken; node.body = body; - node.transformFlags = TransformFlags.ContainsClassFields; + node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; return node; } diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index acba02bfad263..72e23f5a23023 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -542,13 +542,11 @@ namespace ts { function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { if (shouldTransformPrivateElements) { receiver = visitNode(receiver, visitor, isExpression); - const right = factory.createImmediatelyInvokedArrowFunction(visitNodes(node.body.statements, visitor, isBlock)); - return context.getEmitHelperFactory().createClassPrivateFieldSetHelper( - receiver, - factory.createUniqueName("_"), - right, - PrivateIdentifierKind.Field, - /*f*/ undefined + const right = factory.createImmediatelyInvokedArrowFunction(visitNode(node.body, visitor, isBlock).statements); + const name = createHoistedVariableForClass("_", node); + return createPrivateStaticFieldInitializer( + name, + right ); } } @@ -1355,7 +1353,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/tests/baselines/reference/classStaticBlock11(target=es2015).js b/tests/baselines/reference/classStaticBlock11(target=es2015).js new file mode 100644 index 0000000000000..b218d2f8a4a5f --- /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, _C__; +let getX; +class C { + constructor(x) { + _C_x.set(this, 1); + __classPrivateFieldSet(this, _C_x, x, "f"); + } +} +_C_x = new WeakMap(); +_C__ = { value: (() => { + // 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=es5).errors.txt b/tests/baselines/reference/classStaticBlock11(target=es5).errors.txt new file mode 100644 index 0000000000000..e84ce1a7415b6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es5).errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts(3,3): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts (1 errors) ==== + let getX; + class C { + #x = 1 + ~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + constructor(x: number) { + this.#x = x; + } + + static { + // getX has privileged access to #x + getX = (obj: C) => obj.#x; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock11(target=es5).js b/tests/baselines/reference/classStaticBlock11(target=es5).js new file mode 100644 index 0000000000000..fcf8c8f1196fd --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es5).js @@ -0,0 +1,41 @@ +//// [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, _C__; +var getX; +var C = /** @class */ (function () { + function C(x) { + _C_x.set(this, 1); + __classPrivateFieldSet(this, _C_x, x, "f"); + } + return C; +}()); +_C_x = new WeakMap(); +_C__ = { value: (function () { + // getX has privileged access to #x + getX = function (obj) { return __classPrivateFieldGet(obj, _C_x, "f"); }; + })() }; diff --git a/tests/baselines/reference/classStaticBlock11(target=es5).symbols b/tests/baselines/reference/classStaticBlock11(target=es5).symbols new file mode 100644 index 0000000000000..d61ff7c9e16f9 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es5).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=es5).types b/tests/baselines/reference/classStaticBlock11(target=es5).types new file mode 100644 index 0000000000000..c295e7b93df36 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=es5).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..af7697baf6644 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock11(target=esnext).js @@ -0,0 +1,28 @@ +//// [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 { + constructor(x) { + this.#x = 1; + this.#x = 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.errors.txt b/tests/baselines/reference/classStaticBlock12.errors.txt new file mode 100644 index 0000000000000..d4535ca1542bd --- /dev/null +++ b/tests/baselines/reference/classStaticBlock12.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts (1 errors) ==== + class C { + static #x = 1; + ~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + static { + C.#x; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock12.js b/tests/baselines/reference/classStaticBlock12.js new file mode 100644 index 0000000000000..fd85eadf08087 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock12.js @@ -0,0 +1,27 @@ +//// [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 C = /** @class */ (function () { + function C() { + } + var _a, _C_x, _C__; + _a = C; + _C_x = { value: 1 }; + _C__ = { value: (function () { + __classPrivateFieldGet(C, _a, "f", _C_x); + })() }; + return C; +}()); 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..521c946a38113 --- /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, _C__; +class C { + foo() { + return __classPrivateFieldGet(C, _a, "f", _C_x); + } +} +_a = C; +_C_x = { value: 123 }; +_C__ = { value: (() => { + 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=es5).errors.txt b/tests/baselines/reference/classStaticBlock13(target=es5).errors.txt new file mode 100644 index 0000000000000..e0f90aaa81975 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es5).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts (1 errors) ==== + class C { + static #x = 123; + ~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + static { + console.log(C.#x) + } + + foo () { + return C.#x; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock13(target=es5).js b/tests/baselines/reference/classStaticBlock13(target=es5).js new file mode 100644 index 0000000000000..25fc0311041a4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es5).js @@ -0,0 +1,39 @@ +//// [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 C = /** @class */ (function () { + function C() { + } + Object.defineProperty(C.prototype, "foo", { + enumerable: false, + configurable: true, + writable: true, + value: function () { + return __classPrivateFieldGet(C, _a, "f", _C_x); + } + }); + var _a, _C_x, _C__; + _a = C; + _C_x = { value: 123 }; + _C__ = { value: (function () { + console.log(__classPrivateFieldGet(C, _a, "f", _C_x)); + })() }; + return C; +}()); diff --git a/tests/baselines/reference/classStaticBlock13(target=es5).symbols b/tests/baselines/reference/classStaticBlock13(target=es5).symbols new file mode 100644 index 0000000000000..7f94ddadbe167 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es5).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=es5).types b/tests/baselines/reference/classStaticBlock13(target=es5).types new file mode 100644 index 0000000000000..735409daa5c44 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock13(target=es5).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.errors.txt b/tests/baselines/reference/classStaticBlock14.errors.txt new file mode 100644 index 0000000000000..e88e1244dd6df --- /dev/null +++ b/tests/baselines/reference/classStaticBlock14.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts(3,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts(4,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts (3 errors) ==== + class C { + static #_1 = 1; + ~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + static #_3 = 1; + ~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + static #_5 = 1; + ~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + static {} + static {} + static {} + static {} + static {} + static {} + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock14.js b/tests/baselines/reference/classStaticBlock14.js new file mode 100644 index 0000000000000..4420febdac50f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock14.js @@ -0,0 +1,38 @@ +//// [classStaticBlock14.ts] +class C { + static #_1 = 1; + static #_3 = 1; + static #_5 = 1; + + static {} + static {} + static {} + static {} + static {} + static {} +} + + +//// [classStaticBlock14.js] +var C = /** @class */ (function () { + function C() { + } + var _a, _C__1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; + _a = C; + _C__1 = { value: 1 }; + _C__3 = { value: 1 }; + _C__5 = { value: 1 }; + _C__ = { value: (function () { + })() }; + _C__2 = { value: (function () { + })() }; + _C__4 = { value: (function () { + })() }; + _C__6 = { value: (function () { + })() }; + _C__7 = { value: (function () { + })() }; + _C__8 = { value: (function () { + })() }; + return C; +}()); 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).errors.txt b/tests/baselines/reference/classStaticBlock15(target=es2015).errors.txt new file mode 100644 index 0000000000000..b922214e105b0 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(14,13): error TS2304: Cannot find name '_C__1'. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts (1 errors) ==== + class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} + } + + console.log(_C__1) + ~~~~~ +!!! error TS2304: Cannot find name '_C__1'. + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).js b/tests/baselines/reference/classStaticBlock15(target=es2015).js new file mode 100644 index 0000000000000..739e96ae04142 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).js @@ -0,0 +1,38 @@ +//// [classStaticBlock15.ts] +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, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; +class C { +} +_a = C; +_C__1_1 = { value: 1 }; +_C__3 = { value: 3 }; +_C__5 = { value: 5 }; +_C__ = { value: (() => { + })() }; +_C__2 = { value: (() => { + })() }; +_C__4 = { value: (() => { + })() }; +_C__6 = { value: (() => { + })() }; +_C__7 = { value: (() => { + })() }; +_C__8 = { value: (() => { + })() }; +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..4d236f95d2e27 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 0)) + + static #_1 = 1; +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 0, 9)) + + static #_3 = 3; +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 1, 17)) + + static #_5 = 5; +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 2, 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, --, --)) + diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).types b/tests/baselines/reference/classStaticBlock15(target=es2015).types new file mode 100644 index 0000000000000..8b10940745a8b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +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=es5).errors.txt b/tests/baselines/reference/classStaticBlock15(target=es5).errors.txt new file mode 100644 index 0000000000000..1a1e72d9199b3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es5).errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(3,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(4,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(14,13): error TS2304: Cannot find name '_C__1'. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts (4 errors) ==== + class C { + static #_1 = 1; + ~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + static #_3 = 3; + ~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + static #_5 = 5; + ~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. + + static {} + static {} + static {} + static {} + static {} + static {} + } + + console.log(_C__1) + ~~~~~ +!!! error TS2304: Cannot find name '_C__1'. + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).js b/tests/baselines/reference/classStaticBlock15(target=es5).js new file mode 100644 index 0000000000000..561cb55c53d1b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es5).js @@ -0,0 +1,41 @@ +//// [classStaticBlock15.ts] +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 = /** @class */ (function () { + function C() { + } + var _a, _C__1_1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; + _a = C; + _C__1_1 = { value: 1 }; + _C__3 = { value: 3 }; + _C__5 = { value: 5 }; + _C__ = { value: (function () { + })() }; + _C__2 = { value: (function () { + })() }; + _C__4 = { value: (function () { + })() }; + _C__6 = { value: (function () { + })() }; + _C__7 = { value: (function () { + })() }; + _C__8 = { value: (function () { + })() }; + return C; +}()); +console.log(_C__1); diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).symbols b/tests/baselines/reference/classStaticBlock15(target=es5).symbols new file mode 100644 index 0000000000000..4d236f95d2e27 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es5).symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 0)) + + static #_1 = 1; +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 0, 9)) + + static #_3 = 3; +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 1, 17)) + + static #_5 = 5; +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 2, 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, --, --)) + diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).types b/tests/baselines/reference/classStaticBlock15(target=es5).types new file mode 100644 index 0000000000000..8b10940745a8b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=es5).types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +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).errors.txt b/tests/baselines/reference/classStaticBlock15(target=esnext).errors.txt new file mode 100644 index 0000000000000..b922214e105b0 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(14,13): error TS2304: Cannot find name '_C__1'. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts (1 errors) ==== + class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} + } + + console.log(_C__1) + ~~~~~ +!!! error TS2304: Cannot find name '_C__1'. + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).js b/tests/baselines/reference/classStaticBlock15(target=esnext).js new file mode 100644 index 0000000000000..43af3a33b22e7 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).js @@ -0,0 +1,30 @@ +//// [classStaticBlock15.ts] +class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) + + +//// [classStaticBlock15.js] +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..4d236f95d2e27 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 0)) + + static #_1 = 1; +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 0, 9)) + + static #_3 = 3; +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 1, 17)) + + static #_5 = 5; +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 2, 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, --, --)) + diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).types b/tests/baselines/reference/classStaticBlock15(target=esnext).types new file mode 100644 index 0000000000000..8b10940745a8b --- /dev/null +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +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/classStaticBlock3(target=es2015).js b/tests/baselines/reference/classStaticBlock3(target=es2015).js index f188c5f0d4bef..722aa49d56081 100644 --- a/tests/baselines/reference/classStaticBlock3(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock3(target=es2015).js @@ -19,21 +19,16 @@ class C { //// [classStaticBlock3.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 _C__, _C__1; const a = 1; class C { } C.f1 = 1; -__classPrivateFieldSet(C, _1, (() => { - console.log(C.f1, C.f2, C.f3); -})(), "f"); +_C__ = { value: (() => { + console.log(C.f1, C.f2, C.f3); + })() }; C.f2 = 2; -__classPrivateFieldSet(C, _2, (() => { - console.log(C.f1, C.f2, C.f3); -})(), "f"); +_C__1 = { value: (() => { + console.log(C.f1, C.f2, C.f3); + })() }; C.f3 = 3; diff --git a/tests/baselines/reference/classStaticBlock3(target=es5).js b/tests/baselines/reference/classStaticBlock3(target=es5).js index 77151586b9810..7c7d46731880d 100644 --- a/tests/baselines/reference/classStaticBlock3(target=es5).js +++ b/tests/baselines/reference/classStaticBlock3(target=es5).js @@ -19,24 +19,19 @@ class C { //// [classStaticBlock3.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 a = 1; var C = /** @class */ (function () { function C() { } + var _C__, _C__1; C.f1 = 1; - __classPrivateFieldSet(C, _1, (function () { - console.log(C.f1, C.f2, C.f3); - })(), "f"); + _C__ = { value: (function () { + console.log(C.f1, C.f2, C.f3); + })() }; C.f2 = 2; - __classPrivateFieldSet(C, _2, (function () { - console.log(C.f1, C.f2, C.f3); - })(), "f"); + _C__1 = { value: (function () { + console.log(C.f1, C.f2, C.f3); + })() }; C.f3 = 3; return C; }()); diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).js b/tests/baselines/reference/classStaticBlock4(target=es2015).js index faa662beb8d0a..6a49dac60142a 100644 --- a/tests/baselines/reference/classStaticBlock4(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).js @@ -16,20 +16,15 @@ class C { //// [classStaticBlock4.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 _C__; class C { } C.s1 = 1; -__classPrivateFieldSet(C, _1, (() => { - this.s1; - C.s1; - this.s2; - C.s2; -})(), "f"); +_C__ = { value: (() => { + this.s1; + C.s1; + this.s2; + C.s2; + })() }; C.s2 = 2; C.ss2 = this.s1; diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).js b/tests/baselines/reference/classStaticBlock4(target=es5).js index 1e70d121bba3f..1c11c48e32729 100644 --- a/tests/baselines/reference/classStaticBlock4(target=es5).js +++ b/tests/baselines/reference/classStaticBlock4(target=es5).js @@ -16,23 +16,18 @@ class C { //// [classStaticBlock4.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 _this = this; var C = /** @class */ (function () { function C() { } + var _C__; C.s1 = 1; - __classPrivateFieldSet(C, _1, (function () { - _this.s1; - C.s1; - _this.s2; - C.s2; - })(), "f"); + _C__ = { value: (function () { + _this.s1; + C.s1; + _this.s2; + C.s2; + })() }; C.s2 = 2; C.ss2 = this.s1; return C; diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).js b/tests/baselines/reference/classStaticBlock5(target=es2015).js index 18515f7dddb0c..e69ce1e902168 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).js @@ -17,12 +17,7 @@ class C extends B { //// [classStaticBlock5.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 _C__; class B { } B.a = 1; @@ -31,8 +26,8 @@ class C extends B { } C.b = 3; C.c = super.a; -__classPrivateFieldSet(C, _1, (() => { - this.b; - super.b; - super.a; -})(), "f"); +_C__ = { value: (() => { + this.b; + super.b; + super.a; + })() }; diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).js b/tests/baselines/reference/classStaticBlock5(target=es5).js index cb5588cf934a3..7aee91846eea4 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).js +++ b/tests/baselines/reference/classStaticBlock5(target=es5).js @@ -32,12 +32,6 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -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 _this = this; var B = /** @class */ (function () { function B() { @@ -51,12 +45,13 @@ var C = /** @class */ (function (_super) { function C() { return _super !== null && _super.apply(this, arguments) || this; } + var _C__; C.b = 3; C.c = _super.a; - __classPrivateFieldSet(C, _1, (function () { - _this.b; - _super.b; - _super.a; - })(), "f"); + _C__ = { value: (function () { + _this.b; + _super.b; + _super.a; + })() }; return C; }(B)); diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).js b/tests/baselines/reference/classStaticBlock9(target=es2015).js index 65435050082bf..d7a213f4b59d9 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).js @@ -9,16 +9,11 @@ class A { //// [classStaticBlock9.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 _A__; class A { } A.bar = A.foo + 1; -__classPrivateFieldSet(A, _1, (() => { - A.foo + 2; -})(), "f"); +_A__ = { value: (() => { + A.foo + 2; + })() }; A.foo = 1; diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).js b/tests/baselines/reference/classStaticBlock9(target=es5).js index 85d97efacbe6a..23e4ba3e909fa 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es5).js +++ b/tests/baselines/reference/classStaticBlock9(target=es5).js @@ -9,19 +9,14 @@ class A { //// [classStaticBlock9.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 A = /** @class */ (function () { function A() { } + var _A__; A.bar = A.foo + 1; - __classPrivateFieldSet(A, _1, (function () { - A.foo + 2; - })(), "f"); + _A__ = { value: (function () { + A.foo + 2; + })() }; A.foo = 1; return A; }()); diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts new file mode 100644 index 0000000000000..73786b4e0d29d --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts @@ -0,0 +1,14 @@ +// @target: esnext, es2015, es5 + +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..2071f21c5d92b --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts @@ -0,0 +1,9 @@ +// @useDefineForClassFields: false + +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..6b05c3e0df50d --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts @@ -0,0 +1,14 @@ +// @target: esnext, es2015, es5 +// @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..c5e4f30e02dd9 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts @@ -0,0 +1,14 @@ +// @useDefineForClassFields: false + +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..c7d5c2da04ffa --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts @@ -0,0 +1,17 @@ +// @target: esnext, es2015, es5 +// @useDefineForClassFields: true + +class C { + static #_1 = 1; + static #_3 = 3; + static #_5 = 5; + + static {} + static {} + static {} + static {} + static {} + static {} +} + +console.log(_C__1) From 7c50597805922951d9a4cb87ca0011bc52c6b655 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 19 Mar 2021 16:55:06 +0800 Subject: [PATCH 04/36] Add more tests --- .../reference/classStaticBlock16.errors.txt | 37 ++++++++++ .../baselines/reference/classStaticBlock16.js | 64 +++++++++++++++++ .../reference/classStaticBlock16.symbols | 65 +++++++++++++++++ .../reference/classStaticBlock16.types | 72 +++++++++++++++++++ .../classStaticBlock/classStaticBlock16.ts | 26 +++++++ 5 files changed, 264 insertions(+) create mode 100644 tests/baselines/reference/classStaticBlock16.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock16.js create mode 100644 tests/baselines/reference/classStaticBlock16.symbols create mode 100644 tests/baselines/reference/classStaticBlock16.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock16.ts 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..7c282010398f1 --- /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, _C__, _D_y, _D__; +let getX; +class C { + constructor(x) { + _C_x.set(this, 1); + __classPrivateFieldSet(this, _C_x, x, "f"); + } +} +_C_x = new WeakMap(); +_C__ = { value: (() => { + // 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(); +_D__ = { value: (() => { + // 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/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 From 6f4b7b3f1b10d31640f1c1d7a7ffd2480df2c516 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 19 Mar 2021 17:09:24 +0800 Subject: [PATCH 05/36] Add friend tests --- .../baselines/reference/classStaticBlock17.js | 74 +++++++++++++ .../reference/classStaticBlock17.symbols | 93 ++++++++++++++++ .../reference/classStaticBlock17.types | 102 ++++++++++++++++++ .../classStaticBlock/classStaticBlock17.ts | 33 ++++++ 4 files changed, 302 insertions(+) create mode 100644 tests/baselines/reference/classStaticBlock17.js create mode 100644 tests/baselines/reference/classStaticBlock17.symbols create mode 100644 tests/baselines/reference/classStaticBlock17.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock17.ts diff --git a/tests/baselines/reference/classStaticBlock17.js b/tests/baselines/reference/classStaticBlock17.js new file mode 100644 index 0000000000000..b079e496807fb --- /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, _A__; +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(); +_A__ = { value: (() => { + 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/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 From 3c0b7cf40c37606f5807a143c84da1fde4a11c88 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 19 Mar 2021 17:16:31 +0800 Subject: [PATCH 06/36] Update baseline --- .../reference/api/tsserverlibrary.d.ts | 372 +++++++++--------- tests/baselines/reference/api/typescript.d.ts | 372 +++++++++--------- 2 files changed, 382 insertions(+), 362 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 75b3a9747c00a..05f1929209087 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -275,179 +275,180 @@ declare namespace ts { SetAccessor = 168, CallSignature = 169, ConstructSignature = 170, - IndexSignature = 171, - TypePredicate = 172, - TypeReference = 173, - FunctionType = 174, - ConstructorType = 175, - TypeQuery = 176, - TypeLiteral = 177, - ArrayType = 178, - TupleType = 179, - OptionalType = 180, - RestType = 181, - UnionType = 182, - IntersectionType = 183, - ConditionalType = 184, - InferType = 185, - ParenthesizedType = 186, - ThisType = 187, - TypeOperator = 188, - IndexedAccessType = 189, - MappedType = 190, - LiteralType = 191, - NamedTupleMember = 192, - TemplateLiteralType = 193, - TemplateLiteralTypeSpan = 194, - ImportType = 195, - ObjectBindingPattern = 196, - ArrayBindingPattern = 197, - BindingElement = 198, - ArrayLiteralExpression = 199, - ObjectLiteralExpression = 200, - PropertyAccessExpression = 201, - ElementAccessExpression = 202, - CallExpression = 203, - NewExpression = 204, - TaggedTemplateExpression = 205, - TypeAssertionExpression = 206, - ParenthesizedExpression = 207, - FunctionExpression = 208, - ArrowFunction = 209, - DeleteExpression = 210, - TypeOfExpression = 211, - VoidExpression = 212, - AwaitExpression = 213, - PrefixUnaryExpression = 214, - PostfixUnaryExpression = 215, - BinaryExpression = 216, - ConditionalExpression = 217, - TemplateExpression = 218, - YieldExpression = 219, - SpreadElement = 220, - ClassExpression = 221, - OmittedExpression = 222, - ExpressionWithTypeArguments = 223, - AsExpression = 224, - NonNullExpression = 225, - MetaProperty = 226, - SyntheticExpression = 227, - TemplateSpan = 228, - SemicolonClassElement = 229, - Block = 230, - EmptyStatement = 231, - VariableStatement = 232, - ExpressionStatement = 233, - IfStatement = 234, - DoStatement = 235, - WhileStatement = 236, - ForStatement = 237, - ForInStatement = 238, - ForOfStatement = 239, - ContinueStatement = 240, - BreakStatement = 241, - ReturnStatement = 242, - WithStatement = 243, - SwitchStatement = 244, - LabeledStatement = 245, - ThrowStatement = 246, - TryStatement = 247, - DebuggerStatement = 248, - VariableDeclaration = 249, - VariableDeclarationList = 250, - FunctionDeclaration = 251, - ClassDeclaration = 252, - InterfaceDeclaration = 253, - TypeAliasDeclaration = 254, - EnumDeclaration = 255, - ModuleDeclaration = 256, - ModuleBlock = 257, - CaseBlock = 258, - NamespaceExportDeclaration = 259, - ImportEqualsDeclaration = 260, - ImportDeclaration = 261, - ImportClause = 262, - NamespaceImport = 263, - NamedImports = 264, - ImportSpecifier = 265, - ExportAssignment = 266, - ExportDeclaration = 267, - NamedExports = 268, - NamespaceExport = 269, - ExportSpecifier = 270, - MissingDeclaration = 271, - ExternalModuleReference = 272, - JsxElement = 273, - JsxSelfClosingElement = 274, - JsxOpeningElement = 275, - JsxClosingElement = 276, - JsxFragment = 277, - JsxOpeningFragment = 278, - JsxClosingFragment = 279, - JsxAttribute = 280, - JsxAttributes = 281, - JsxSpreadAttribute = 282, - JsxExpression = 283, - CaseClause = 284, - DefaultClause = 285, - HeritageClause = 286, - CatchClause = 287, - PropertyAssignment = 288, - ShorthandPropertyAssignment = 289, - SpreadAssignment = 290, - EnumMember = 291, - UnparsedPrologue = 292, - UnparsedPrepend = 293, - UnparsedText = 294, - UnparsedInternalText = 295, - UnparsedSyntheticReference = 296, - SourceFile = 297, - Bundle = 298, - UnparsedSource = 299, - InputFiles = 300, - JSDocTypeExpression = 301, - JSDocNameReference = 302, - JSDocAllType = 303, - JSDocUnknownType = 304, - JSDocNullableType = 305, - JSDocNonNullableType = 306, - JSDocOptionalType = 307, - JSDocFunctionType = 308, - JSDocVariadicType = 309, - JSDocNamepathType = 310, - JSDocComment = 311, - JSDocText = 312, - JSDocTypeLiteral = 313, - JSDocSignature = 314, - JSDocLink = 315, - JSDocTag = 316, - JSDocAugmentsTag = 317, - JSDocImplementsTag = 318, - JSDocAuthorTag = 319, - JSDocDeprecatedTag = 320, - JSDocClassTag = 321, - JSDocPublicTag = 322, - JSDocPrivateTag = 323, - JSDocProtectedTag = 324, - JSDocReadonlyTag = 325, - JSDocCallbackTag = 326, - JSDocEnumTag = 327, - JSDocParameterTag = 328, - JSDocReturnTag = 329, - JSDocThisTag = 330, - JSDocTypeTag = 331, - JSDocTemplateTag = 332, - JSDocTypedefTag = 333, - JSDocSeeTag = 334, - JSDocPropertyTag = 335, - SyntaxList = 336, - NotEmittedStatement = 337, - PartiallyEmittedExpression = 338, - CommaListExpression = 339, - MergeDeclarationMarker = 340, - EndOfDeclarationMarker = 341, - SyntheticReferenceExpression = 342, - Count = 343, + ClassStaticBlockDeclaration = 171, + IndexSignature = 172, + TypePredicate = 173, + TypeReference = 174, + FunctionType = 175, + ConstructorType = 176, + TypeQuery = 177, + TypeLiteral = 178, + ArrayType = 179, + TupleType = 180, + OptionalType = 181, + RestType = 182, + UnionType = 183, + IntersectionType = 184, + ConditionalType = 185, + InferType = 186, + ParenthesizedType = 187, + ThisType = 188, + TypeOperator = 189, + IndexedAccessType = 190, + MappedType = 191, + LiteralType = 192, + NamedTupleMember = 193, + TemplateLiteralType = 194, + TemplateLiteralTypeSpan = 195, + ImportType = 196, + ObjectBindingPattern = 197, + ArrayBindingPattern = 198, + BindingElement = 199, + ArrayLiteralExpression = 200, + ObjectLiteralExpression = 201, + PropertyAccessExpression = 202, + ElementAccessExpression = 203, + CallExpression = 204, + NewExpression = 205, + TaggedTemplateExpression = 206, + TypeAssertionExpression = 207, + ParenthesizedExpression = 208, + FunctionExpression = 209, + ArrowFunction = 210, + DeleteExpression = 211, + TypeOfExpression = 212, + VoidExpression = 213, + AwaitExpression = 214, + PrefixUnaryExpression = 215, + PostfixUnaryExpression = 216, + BinaryExpression = 217, + ConditionalExpression = 218, + TemplateExpression = 219, + YieldExpression = 220, + SpreadElement = 221, + ClassExpression = 222, + OmittedExpression = 223, + ExpressionWithTypeArguments = 224, + AsExpression = 225, + NonNullExpression = 226, + MetaProperty = 227, + SyntheticExpression = 228, + TemplateSpan = 229, + SemicolonClassElement = 230, + Block = 231, + EmptyStatement = 232, + VariableStatement = 233, + ExpressionStatement = 234, + IfStatement = 235, + DoStatement = 236, + WhileStatement = 237, + ForStatement = 238, + ForInStatement = 239, + ForOfStatement = 240, + ContinueStatement = 241, + BreakStatement = 242, + ReturnStatement = 243, + WithStatement = 244, + SwitchStatement = 245, + LabeledStatement = 246, + ThrowStatement = 247, + TryStatement = 248, + DebuggerStatement = 249, + VariableDeclaration = 250, + VariableDeclarationList = 251, + FunctionDeclaration = 252, + ClassDeclaration = 253, + InterfaceDeclaration = 254, + TypeAliasDeclaration = 255, + EnumDeclaration = 256, + ModuleDeclaration = 257, + ModuleBlock = 258, + CaseBlock = 259, + NamespaceExportDeclaration = 260, + ImportEqualsDeclaration = 261, + ImportDeclaration = 262, + ImportClause = 263, + NamespaceImport = 264, + NamedImports = 265, + ImportSpecifier = 266, + ExportAssignment = 267, + ExportDeclaration = 268, + NamedExports = 269, + NamespaceExport = 270, + ExportSpecifier = 271, + MissingDeclaration = 272, + ExternalModuleReference = 273, + JsxElement = 274, + JsxSelfClosingElement = 275, + JsxOpeningElement = 276, + JsxClosingElement = 277, + JsxFragment = 278, + JsxOpeningFragment = 279, + JsxClosingFragment = 280, + JsxAttribute = 281, + JsxAttributes = 282, + JsxSpreadAttribute = 283, + JsxExpression = 284, + CaseClause = 285, + DefaultClause = 286, + HeritageClause = 287, + CatchClause = 288, + PropertyAssignment = 289, + ShorthandPropertyAssignment = 290, + SpreadAssignment = 291, + EnumMember = 292, + UnparsedPrologue = 293, + UnparsedPrepend = 294, + UnparsedText = 295, + UnparsedInternalText = 296, + UnparsedSyntheticReference = 297, + SourceFile = 298, + Bundle = 299, + UnparsedSource = 300, + InputFiles = 301, + JSDocTypeExpression = 302, + JSDocNameReference = 303, + JSDocAllType = 304, + JSDocUnknownType = 305, + JSDocNullableType = 306, + JSDocNonNullableType = 307, + JSDocOptionalType = 308, + JSDocFunctionType = 309, + JSDocVariadicType = 310, + JSDocNamepathType = 311, + JSDocComment = 312, + JSDocText = 313, + JSDocTypeLiteral = 314, + JSDocSignature = 315, + JSDocLink = 316, + JSDocTag = 317, + JSDocAugmentsTag = 318, + JSDocImplementsTag = 319, + JSDocAuthorTag = 320, + JSDocDeprecatedTag = 321, + JSDocClassTag = 322, + JSDocPublicTag = 323, + JSDocPrivateTag = 324, + JSDocProtectedTag = 325, + JSDocReadonlyTag = 326, + JSDocCallbackTag = 327, + JSDocEnumTag = 328, + JSDocParameterTag = 329, + JSDocReturnTag = 330, + JSDocThisTag = 331, + JSDocTypeTag = 332, + JSDocTemplateTag = 333, + JSDocTypedefTag = 334, + JSDocSeeTag = 335, + JSDocPropertyTag = 336, + SyntaxList = 337, + NotEmittedStatement = 338, + PartiallyEmittedExpression = 339, + CommaListExpression = 340, + MergeDeclarationMarker = 341, + EndOfDeclarationMarker = 342, + SyntheticReferenceExpression = 343, + Count = 344, FirstAssignment = 62, LastAssignment = 77, FirstCompoundAssignment = 63, @@ -458,8 +459,8 @@ declare namespace ts { LastKeyword = 156, FirstFutureReservedWord = 116, LastFutureReservedWord = 124, - FirstTypeNode = 172, - LastTypeNode = 195, + FirstTypeNode = 173, + LastTypeNode = 196, FirstPunctuation = 18, LastPunctuation = 77, FirstToken = 0, @@ -472,13 +473,13 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 77, - FirstStatement = 232, - LastStatement = 248, + FirstStatement = 233, + LastStatement = 249, FirstNode = 157, - FirstJSDocNode = 301, - LastJSDocNode = 335, - FirstJSDocTagNode = 316, - LastJSDocTagNode = 335, + FirstJSDocNode = 302, + LastJSDocNode = 336, + FirstJSDocTagNode = 317, + LastJSDocTagNode = 336, } 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; @@ -841,6 +842,11 @@ declare namespace ts { readonly parent: ObjectTypeDeclaration; readonly type: TypeNode; } + export interface ClassStaticBlockDeclaration extends ClassElement { + readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly staticToken: Token; + readonly body: Block; + } export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -3259,6 +3265,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(staticToken: Token, body: Block): ClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, staticToken: Token, 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; @@ -4268,6 +4276,8 @@ declare namespace ts { function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; + function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; + function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration); function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index c0edb345ad537..e7a9fbb6e780b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -275,179 +275,180 @@ declare namespace ts { SetAccessor = 168, CallSignature = 169, ConstructSignature = 170, - IndexSignature = 171, - TypePredicate = 172, - TypeReference = 173, - FunctionType = 174, - ConstructorType = 175, - TypeQuery = 176, - TypeLiteral = 177, - ArrayType = 178, - TupleType = 179, - OptionalType = 180, - RestType = 181, - UnionType = 182, - IntersectionType = 183, - ConditionalType = 184, - InferType = 185, - ParenthesizedType = 186, - ThisType = 187, - TypeOperator = 188, - IndexedAccessType = 189, - MappedType = 190, - LiteralType = 191, - NamedTupleMember = 192, - TemplateLiteralType = 193, - TemplateLiteralTypeSpan = 194, - ImportType = 195, - ObjectBindingPattern = 196, - ArrayBindingPattern = 197, - BindingElement = 198, - ArrayLiteralExpression = 199, - ObjectLiteralExpression = 200, - PropertyAccessExpression = 201, - ElementAccessExpression = 202, - CallExpression = 203, - NewExpression = 204, - TaggedTemplateExpression = 205, - TypeAssertionExpression = 206, - ParenthesizedExpression = 207, - FunctionExpression = 208, - ArrowFunction = 209, - DeleteExpression = 210, - TypeOfExpression = 211, - VoidExpression = 212, - AwaitExpression = 213, - PrefixUnaryExpression = 214, - PostfixUnaryExpression = 215, - BinaryExpression = 216, - ConditionalExpression = 217, - TemplateExpression = 218, - YieldExpression = 219, - SpreadElement = 220, - ClassExpression = 221, - OmittedExpression = 222, - ExpressionWithTypeArguments = 223, - AsExpression = 224, - NonNullExpression = 225, - MetaProperty = 226, - SyntheticExpression = 227, - TemplateSpan = 228, - SemicolonClassElement = 229, - Block = 230, - EmptyStatement = 231, - VariableStatement = 232, - ExpressionStatement = 233, - IfStatement = 234, - DoStatement = 235, - WhileStatement = 236, - ForStatement = 237, - ForInStatement = 238, - ForOfStatement = 239, - ContinueStatement = 240, - BreakStatement = 241, - ReturnStatement = 242, - WithStatement = 243, - SwitchStatement = 244, - LabeledStatement = 245, - ThrowStatement = 246, - TryStatement = 247, - DebuggerStatement = 248, - VariableDeclaration = 249, - VariableDeclarationList = 250, - FunctionDeclaration = 251, - ClassDeclaration = 252, - InterfaceDeclaration = 253, - TypeAliasDeclaration = 254, - EnumDeclaration = 255, - ModuleDeclaration = 256, - ModuleBlock = 257, - CaseBlock = 258, - NamespaceExportDeclaration = 259, - ImportEqualsDeclaration = 260, - ImportDeclaration = 261, - ImportClause = 262, - NamespaceImport = 263, - NamedImports = 264, - ImportSpecifier = 265, - ExportAssignment = 266, - ExportDeclaration = 267, - NamedExports = 268, - NamespaceExport = 269, - ExportSpecifier = 270, - MissingDeclaration = 271, - ExternalModuleReference = 272, - JsxElement = 273, - JsxSelfClosingElement = 274, - JsxOpeningElement = 275, - JsxClosingElement = 276, - JsxFragment = 277, - JsxOpeningFragment = 278, - JsxClosingFragment = 279, - JsxAttribute = 280, - JsxAttributes = 281, - JsxSpreadAttribute = 282, - JsxExpression = 283, - CaseClause = 284, - DefaultClause = 285, - HeritageClause = 286, - CatchClause = 287, - PropertyAssignment = 288, - ShorthandPropertyAssignment = 289, - SpreadAssignment = 290, - EnumMember = 291, - UnparsedPrologue = 292, - UnparsedPrepend = 293, - UnparsedText = 294, - UnparsedInternalText = 295, - UnparsedSyntheticReference = 296, - SourceFile = 297, - Bundle = 298, - UnparsedSource = 299, - InputFiles = 300, - JSDocTypeExpression = 301, - JSDocNameReference = 302, - JSDocAllType = 303, - JSDocUnknownType = 304, - JSDocNullableType = 305, - JSDocNonNullableType = 306, - JSDocOptionalType = 307, - JSDocFunctionType = 308, - JSDocVariadicType = 309, - JSDocNamepathType = 310, - JSDocComment = 311, - JSDocText = 312, - JSDocTypeLiteral = 313, - JSDocSignature = 314, - JSDocLink = 315, - JSDocTag = 316, - JSDocAugmentsTag = 317, - JSDocImplementsTag = 318, - JSDocAuthorTag = 319, - JSDocDeprecatedTag = 320, - JSDocClassTag = 321, - JSDocPublicTag = 322, - JSDocPrivateTag = 323, - JSDocProtectedTag = 324, - JSDocReadonlyTag = 325, - JSDocCallbackTag = 326, - JSDocEnumTag = 327, - JSDocParameterTag = 328, - JSDocReturnTag = 329, - JSDocThisTag = 330, - JSDocTypeTag = 331, - JSDocTemplateTag = 332, - JSDocTypedefTag = 333, - JSDocSeeTag = 334, - JSDocPropertyTag = 335, - SyntaxList = 336, - NotEmittedStatement = 337, - PartiallyEmittedExpression = 338, - CommaListExpression = 339, - MergeDeclarationMarker = 340, - EndOfDeclarationMarker = 341, - SyntheticReferenceExpression = 342, - Count = 343, + ClassStaticBlockDeclaration = 171, + IndexSignature = 172, + TypePredicate = 173, + TypeReference = 174, + FunctionType = 175, + ConstructorType = 176, + TypeQuery = 177, + TypeLiteral = 178, + ArrayType = 179, + TupleType = 180, + OptionalType = 181, + RestType = 182, + UnionType = 183, + IntersectionType = 184, + ConditionalType = 185, + InferType = 186, + ParenthesizedType = 187, + ThisType = 188, + TypeOperator = 189, + IndexedAccessType = 190, + MappedType = 191, + LiteralType = 192, + NamedTupleMember = 193, + TemplateLiteralType = 194, + TemplateLiteralTypeSpan = 195, + ImportType = 196, + ObjectBindingPattern = 197, + ArrayBindingPattern = 198, + BindingElement = 199, + ArrayLiteralExpression = 200, + ObjectLiteralExpression = 201, + PropertyAccessExpression = 202, + ElementAccessExpression = 203, + CallExpression = 204, + NewExpression = 205, + TaggedTemplateExpression = 206, + TypeAssertionExpression = 207, + ParenthesizedExpression = 208, + FunctionExpression = 209, + ArrowFunction = 210, + DeleteExpression = 211, + TypeOfExpression = 212, + VoidExpression = 213, + AwaitExpression = 214, + PrefixUnaryExpression = 215, + PostfixUnaryExpression = 216, + BinaryExpression = 217, + ConditionalExpression = 218, + TemplateExpression = 219, + YieldExpression = 220, + SpreadElement = 221, + ClassExpression = 222, + OmittedExpression = 223, + ExpressionWithTypeArguments = 224, + AsExpression = 225, + NonNullExpression = 226, + MetaProperty = 227, + SyntheticExpression = 228, + TemplateSpan = 229, + SemicolonClassElement = 230, + Block = 231, + EmptyStatement = 232, + VariableStatement = 233, + ExpressionStatement = 234, + IfStatement = 235, + DoStatement = 236, + WhileStatement = 237, + ForStatement = 238, + ForInStatement = 239, + ForOfStatement = 240, + ContinueStatement = 241, + BreakStatement = 242, + ReturnStatement = 243, + WithStatement = 244, + SwitchStatement = 245, + LabeledStatement = 246, + ThrowStatement = 247, + TryStatement = 248, + DebuggerStatement = 249, + VariableDeclaration = 250, + VariableDeclarationList = 251, + FunctionDeclaration = 252, + ClassDeclaration = 253, + InterfaceDeclaration = 254, + TypeAliasDeclaration = 255, + EnumDeclaration = 256, + ModuleDeclaration = 257, + ModuleBlock = 258, + CaseBlock = 259, + NamespaceExportDeclaration = 260, + ImportEqualsDeclaration = 261, + ImportDeclaration = 262, + ImportClause = 263, + NamespaceImport = 264, + NamedImports = 265, + ImportSpecifier = 266, + ExportAssignment = 267, + ExportDeclaration = 268, + NamedExports = 269, + NamespaceExport = 270, + ExportSpecifier = 271, + MissingDeclaration = 272, + ExternalModuleReference = 273, + JsxElement = 274, + JsxSelfClosingElement = 275, + JsxOpeningElement = 276, + JsxClosingElement = 277, + JsxFragment = 278, + JsxOpeningFragment = 279, + JsxClosingFragment = 280, + JsxAttribute = 281, + JsxAttributes = 282, + JsxSpreadAttribute = 283, + JsxExpression = 284, + CaseClause = 285, + DefaultClause = 286, + HeritageClause = 287, + CatchClause = 288, + PropertyAssignment = 289, + ShorthandPropertyAssignment = 290, + SpreadAssignment = 291, + EnumMember = 292, + UnparsedPrologue = 293, + UnparsedPrepend = 294, + UnparsedText = 295, + UnparsedInternalText = 296, + UnparsedSyntheticReference = 297, + SourceFile = 298, + Bundle = 299, + UnparsedSource = 300, + InputFiles = 301, + JSDocTypeExpression = 302, + JSDocNameReference = 303, + JSDocAllType = 304, + JSDocUnknownType = 305, + JSDocNullableType = 306, + JSDocNonNullableType = 307, + JSDocOptionalType = 308, + JSDocFunctionType = 309, + JSDocVariadicType = 310, + JSDocNamepathType = 311, + JSDocComment = 312, + JSDocText = 313, + JSDocTypeLiteral = 314, + JSDocSignature = 315, + JSDocLink = 316, + JSDocTag = 317, + JSDocAugmentsTag = 318, + JSDocImplementsTag = 319, + JSDocAuthorTag = 320, + JSDocDeprecatedTag = 321, + JSDocClassTag = 322, + JSDocPublicTag = 323, + JSDocPrivateTag = 324, + JSDocProtectedTag = 325, + JSDocReadonlyTag = 326, + JSDocCallbackTag = 327, + JSDocEnumTag = 328, + JSDocParameterTag = 329, + JSDocReturnTag = 330, + JSDocThisTag = 331, + JSDocTypeTag = 332, + JSDocTemplateTag = 333, + JSDocTypedefTag = 334, + JSDocSeeTag = 335, + JSDocPropertyTag = 336, + SyntaxList = 337, + NotEmittedStatement = 338, + PartiallyEmittedExpression = 339, + CommaListExpression = 340, + MergeDeclarationMarker = 341, + EndOfDeclarationMarker = 342, + SyntheticReferenceExpression = 343, + Count = 344, FirstAssignment = 62, LastAssignment = 77, FirstCompoundAssignment = 63, @@ -458,8 +459,8 @@ declare namespace ts { LastKeyword = 156, FirstFutureReservedWord = 116, LastFutureReservedWord = 124, - FirstTypeNode = 172, - LastTypeNode = 195, + FirstTypeNode = 173, + LastTypeNode = 196, FirstPunctuation = 18, LastPunctuation = 77, FirstToken = 0, @@ -472,13 +473,13 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 77, - FirstStatement = 232, - LastStatement = 248, + FirstStatement = 233, + LastStatement = 249, FirstNode = 157, - FirstJSDocNode = 301, - LastJSDocNode = 335, - FirstJSDocTagNode = 316, - LastJSDocTagNode = 335, + FirstJSDocNode = 302, + LastJSDocNode = 336, + FirstJSDocTagNode = 317, + LastJSDocTagNode = 336, } 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; @@ -841,6 +842,11 @@ declare namespace ts { readonly parent: ObjectTypeDeclaration; readonly type: TypeNode; } + export interface ClassStaticBlockDeclaration extends ClassElement { + readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly staticToken: Token; + readonly body: Block; + } export interface TypeNode extends Node { _typeNodeBrand: any; } @@ -3259,6 +3265,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(staticToken: Token, body: Block): ClassStaticBlockDeclaration; + updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, staticToken: Token, 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; @@ -4268,6 +4276,8 @@ declare namespace ts { function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; + function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; + function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration); function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; From bafd15ca1f921299650db970ef49e2ca493dd0ff Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 26 Mar 2021 16:18:20 +0800 Subject: [PATCH 07/36] Fix cr issues --- src/compiler/emitter.ts | 7 +- src/compiler/factory/nodeFactory.ts | 62 +++++++++-------- src/compiler/factory/nodeTests.ts | 4 ++ src/compiler/parser.ts | 27 ++++---- src/compiler/transformers/classFields.ts | 69 ++++++++++--------- src/compiler/transformers/utilities.ts | 12 +++- src/compiler/types.ts | 12 ++-- src/compiler/utilitiesPublic.ts | 5 +- src/compiler/visitorPublic.ts | 3 +- .../classStaticBlock1(target=es2015).js | 5 ++ .../classStaticBlock1(target=es5).js | 5 ++ .../baselines/reference/classStaticBlock1.js | 19 ----- .../reference/classStaticBlock1.symbols | 16 ----- .../reference/classStaticBlock1.types | 18 ----- .../classStaticBlock10(target=es2015).js | 14 ++++ .../classStaticBlock10(target=es5).js | 14 ++++ .../classStaticBlock18(target=es2015).js | 33 +++++++++ .../classStaticBlock18(target=es2015).symbols | 23 +++++++ .../classStaticBlock18(target=es2015).types | 28 ++++++++ .../classStaticBlock18(target=es5).js | 39 +++++++++++ .../classStaticBlock18(target=es5).symbols | 23 +++++++ .../classStaticBlock18(target=es5).types | 28 ++++++++ .../classStaticBlock18(target=esnext).js | 34 +++++++++ .../classStaticBlock18(target=esnext).symbols | 23 +++++++ .../classStaticBlock18(target=esnext).types | 28 ++++++++ .../classStaticBlock2(target=es2015).js | 11 +++ .../classStaticBlock2(target=es5).js | 11 +++ .../baselines/reference/classStaticBlock6.js | 11 +++ .../baselines/reference/classStaticBlock7.js | 6 ++ .../baselines/reference/classStaticBlock8.js | 15 ++++ .../classStaticBlock/classStaticBlock18.ts | 15 ++++ 31 files changed, 478 insertions(+), 142 deletions(-) delete mode 100644 tests/baselines/reference/classStaticBlock1.js delete mode 100644 tests/baselines/reference/classStaticBlock1.symbols delete mode 100644 tests/baselines/reference/classStaticBlock1.types create mode 100644 tests/baselines/reference/classStaticBlock18(target=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock18(target=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock18(target=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock18(target=es5).js create mode 100644 tests/baselines/reference/classStaticBlock18(target=es5).symbols create mode 100644 tests/baselines/reference/classStaticBlock18(target=es5).types create mode 100644 tests/baselines/reference/classStaticBlock18(target=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock18(target=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock18(target=esnext).types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock18.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a4788cde3890b..e0df65b030a15 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2011,7 +2011,9 @@ namespace ts { } function emitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { - emit(node.staticToken); + emitDecorators(node, node.decorators); + emitModifiers(node, node.modifiers); + writeKeyword("static"); emitBlockFunctionBody(node.body); } @@ -5780,7 +5782,8 @@ namespace ts { case SyntaxKind.ClassStaticBlockDeclaration: Debug.type(node); return factory.updateClassStaticBlockDeclaration(node, - visit(node.staticToken, isStaticModifier), + visitList(node.decorators, isDecorator), + visitList(node.modifiers, isModifier), visitFunctionBody(node.body)); case SyntaxKind.Constructor: diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 5d7c6e678e166..1f72290392097 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1394,6 +1394,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, @@ -1612,36 +1644,6 @@ namespace ts { : node; } - // @api - function createClassStaticBlockDeclaration( - staticToken: Token, - body: Block - ): ClassStaticBlockDeclaration { - const node = createBaseGenericNamedDeclaration( - SyntaxKind.ClassStaticBlockDeclaration, - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*name*/ undefined, - /*typeParameters*/ undefined - ); - node.staticToken = staticToken; - node.body = body; - node.transformFlags = propagateChildFlags(body) | TransformFlags.ContainsClassFields; - return node; - } - - // @api - function updateClassStaticBlockDeclaration( - node: ClassStaticBlockDeclaration, - staticToken: Token, - body: Block - ): ClassStaticBlockDeclaration { - return node.staticToken !== staticToken - || node.body !== body - ? update(createClassStaticBlockDeclaration(staticToken, body), node) - : node; - } - // @api function createTemplateLiteralTypeSpan(type: TypeNode, literal: TemplateMiddle | TemplateTail) { const node = createBaseNode(SyntaxKind.TemplateLiteralTypeSpan); diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index 06757ab363ed8..4aebac11bdbcc 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 8a64412049a95..5016ca969f0c3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -169,7 +169,8 @@ namespace ts { visitNode(cbNode, (node).equalsGreaterThanToken) || visitNode(cbNode, (node).body); case SyntaxKind.ClassStaticBlockDeclaration: - return visitNode(cbNode, (node).staticToken) || + return visitNodes(cbNode, cbNodes, node.decorators) || + visitNodes(cbNode, cbNodes, node.modifiers) || visitNode(cbNode, (node).body); case SyntaxKind.TypeReference: return visitNode(cbNode, (node).typeName) || @@ -6565,11 +6566,10 @@ namespace ts { return false; } - function parseClassStaticBlockDeclaration(): ClassStaticBlockDeclaration { - const pos = getNodePos(); - const staticKeyworkd = parseExpectedToken(SyntaxKind.StaticKeyword); + function parseClassStaticBlockDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: ModifiersArray | undefined): ClassStaticBlockDeclaration { + parseExpectedToken(SyntaxKind.StaticKeyword); const body = parseClassStaticBlockBodyBlock(); - return finishNode(factory.createClassStaticBlockDeclaration(staticKeyworkd, body), pos); + return withJSDoc(finishNode(factory.createClassStaticBlockDeclaration(decorators, modifiers, body), pos), hasJSDoc); } function parseClassStaticBlockBodyBlock() { @@ -6618,7 +6618,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(); @@ -6629,6 +6629,9 @@ namespace ts { return undefined; } } + else if (stopOnStartOfClassStaticBlock && token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) { + return undefined; + } else { if (!parseAnyContextualModifier()) { return undefined; @@ -6645,10 +6648,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); @@ -6671,13 +6674,13 @@ namespace ts { nextToken(); return finishNode(factory.createSemicolonClassElement(), pos); } - if (token() === SyntaxKind.StaticKeyword && lookAhead(nextTokenIsOpenBrace)) { - return parseClassStaticBlockDeclaration(); - } 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); diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 72e23f5a23023..471769b330643 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -109,7 +109,7 @@ namespace ts { const compilerOptions = context.getCompilerOptions(); const languageVersion = getEmitScriptTarget(compilerOptions); - const shouldTransformPrivateElements = languageVersion < ScriptTarget.ESNext; + const shouldTransformPrivateElementsOrClassStaticBlocks = languageVersion < ScriptTarget.ESNext; const previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; @@ -182,9 +182,10 @@ namespace ts { } function visitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { - if (!shouldTransformPrivateElements) { + if (!shouldTransformPrivateElementsOrClassStaticBlocks) { return visitEachChild(node, classElementVisitor, context); } + // ClassStaticBlockDeclaration for classes are transformed in `visitClassDeclaration` or `visitClassExpression`. return undefined; } @@ -203,7 +204,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); @@ -270,7 +271,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); } @@ -326,7 +327,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, @@ -391,7 +392,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( @@ -407,7 +408,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; @@ -433,7 +434,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; @@ -499,7 +500,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)) { @@ -522,7 +523,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( @@ -540,7 +541,7 @@ namespace ts { } function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { receiver = visitNode(receiver, visitor, isExpression); const right = factory.createImmediatelyInvokedArrowFunction(visitNode(node.body, visitor, isBlock).statements); const name = createHoistedVariableForClass("_", node); @@ -552,7 +553,7 @@ namespace ts { } function visitBinaryExpression(node: BinaryExpression) { - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { if (isDestructuringAssignment(node)) { const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined!; @@ -636,7 +637,7 @@ namespace ts { function visitClassLike(node: ClassLikeDeclaration) { const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined; - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { startPrivateIdentifierEnvironment(); const name = getNameOfDeclaration(node); @@ -657,7 +658,7 @@ namespace ts { visitClassDeclaration(node) : visitClassExpression(node); - if (shouldTransformPrivateElements) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { endPrivateIdentifierEnvironment(); } pendingExpressions = savedPendingExpressions; @@ -665,7 +666,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) { @@ -677,8 +678,8 @@ namespace ts { return visitEachChild(node, visitor, context); } - const staticProperties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ true); - if (shouldTransformPrivateElements && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { + const staticProperties = getStaticPropertiesAndClassStaticBlock(node); + 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); getPendingExpressions().push(factory.createAssignment( @@ -714,7 +715,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; @@ -734,7 +735,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); @@ -747,7 +748,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); } @@ -761,7 +762,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."); @@ -771,8 +772,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]); @@ -796,7 +797,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)); @@ -808,7 +809,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)) { @@ -855,7 +856,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) { @@ -949,7 +950,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) { @@ -976,7 +977,7 @@ 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 | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { + function addPropertyOrClassStaticBlockStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { for (const property of properties) { const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property, receiver) : transformProperty(property, receiver); if (!expression) { @@ -993,13 +994,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, receiver) : transformProperty(property, receiver); if (!expression) { continue; } @@ -1026,7 +1027,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) { @@ -1098,7 +1099,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; } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 0bc1c3edcef2d..3e1ba108b8b60 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -339,7 +339,13 @@ namespace ts { export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: true, isStatic: boolean): readonly InitializedPropertyDeclaration[]; export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[]; export function getProperties(node: ClassExpression | ClassDeclaration, requireInitializer: boolean, isStatic: boolean): readonly PropertyDeclaration[] { - return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic) || isStatic && isClassStaticBlockDeclaration(m)) as PropertyDeclaration[]; + return filter(node.members, m => isInitializedOrStaticProperty(m, requireInitializer, isStatic)) as PropertyDeclaration[]; + } + + 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, or(isStaticPropertyDeclaration, isClassStaticBlockDeclaration)) as (PropertyDeclaration | ClassStaticBlockDeclaration)[]; } /** @@ -354,6 +360,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 c942e857e00f7..afc0435b8667f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -203,12 +203,12 @@ namespace ts { PropertyDeclaration, MethodSignature, MethodDeclaration, + ClassStaticBlockDeclaration, Constructor, GetAccessor, SetAccessor, CallSignature, ConstructSignature, - ClassStaticBlockDeclaration, IndexSignature, // Type TypePredicate, @@ -862,6 +862,7 @@ namespace ts { export type HasJSDoc = | ParameterDeclaration | CallSignatureDeclaration + | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature @@ -1503,10 +1504,11 @@ namespace ts { readonly type: TypeNode; } - export interface ClassStaticBlockDeclaration extends ClassElement { + export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.ClassStaticBlockDeclaration; - readonly staticToken: Token; 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 { @@ -6939,8 +6941,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(staticToken: Token, body: Block): ClassStaticBlockDeclaration; - updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, staticToken: Token, body: Block): ClassStaticBlockDeclaration; + 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/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index fdd95633d2efa..c822654386bc6 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1221,10 +1221,6 @@ namespace ts { return !!node && isFunctionLikeKind(node.kind); } - export function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration { - return node.kind === SyntaxKind.ClassStaticBlockDeclaration; - } - export function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration) { return !!node && (isFunctionLikeKind(node.kind) || isClassStaticBlockDeclaration(node)); } @@ -1879,6 +1875,7 @@ namespace ts { return node.kind === SyntaxKind.JSDocComment || node.kind === SyntaxKind.JSDocNamepathType || node.kind === SyntaxKind.JSDocText + || node.kind === SyntaxKind.JSDocLink || isJSDocTag(node) || isJSDocTypeLiteral(node) diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 3ccfdde23bde0..1cad9f2d9be31 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -480,7 +480,8 @@ namespace ts { context.startLexicalEnvironment(); context.suspendLexicalEnvironment(); return factory.updateClassStaticBlockDeclaration(node, - nodeVisitor(node.staticToken, visitor, isStaticModifier), + nodesVisitor(node.decorators, visitor, isDecorator), + nodesVisitor(node.modifiers, visitor, isModifier), visitFunctionBody(node.body, visitor, context, nodeVisitor)); case SyntaxKind.CallSignature: diff --git a/tests/baselines/reference/classStaticBlock1(target=es2015).js b/tests/baselines/reference/classStaticBlock1(target=es2015).js index c852add6ad402..3001cf5baa67c 100644 --- a/tests/baselines/reference/classStaticBlock1(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock1(target=es2015).js @@ -11,6 +11,11 @@ class C { //// [classStaticBlock1.js] +var _C__; const a = 2; class C { } +_C__ = { value: (() => { + const a = 1; + a; + })() }; diff --git a/tests/baselines/reference/classStaticBlock1(target=es5).js b/tests/baselines/reference/classStaticBlock1(target=es5).js index 58eccef93a8a5..49d1101127ad4 100644 --- a/tests/baselines/reference/classStaticBlock1(target=es5).js +++ b/tests/baselines/reference/classStaticBlock1(target=es5).js @@ -11,9 +11,14 @@ class C { //// [classStaticBlock1.js] +var _C__; var a = 2; var C = /** @class */ (function () { function C() { } return C; }()); +_C__ = { value: (function () { + var a_1 = 1; + a_1; + })() }; diff --git a/tests/baselines/reference/classStaticBlock1.js b/tests/baselines/reference/classStaticBlock1.js deleted file mode 100644 index 58eccef93a8a5..0000000000000 --- a/tests/baselines/reference/classStaticBlock1.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [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; -}()); diff --git a/tests/baselines/reference/classStaticBlock1.symbols b/tests/baselines/reference/classStaticBlock1.symbols deleted file mode 100644 index e4aa99e0d68d5..0000000000000 --- a/tests/baselines/reference/classStaticBlock1.symbols +++ /dev/null @@ -1,16 +0,0 @@ -=== 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.types b/tests/baselines/reference/classStaticBlock1.types deleted file mode 100644 index a0fd3b4d6480a..0000000000000 --- a/tests/baselines/reference/classStaticBlock1.types +++ /dev/null @@ -1,18 +0,0 @@ -=== 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 index 6e1685db40c3a..1e102364c5de5 100644 --- a/tests/baselines/reference/classStaticBlock10(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock10(target=es2015).js @@ -28,15 +28,29 @@ class C2 { } //// [classStaticBlock10.js] +var _C2__; var a1 = 1; var a2 = 1; const b1 = 2; const b2 = 2; function f() { + var _C1__; var a1 = 11; const b1 = 22; class C1 { } + _C1__ = { value: (() => { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + })() }; } class C2 { } +_C2__ = { value: (() => { + var a1 = 111; + var a2 = 111; + const b1 = 222; + const b2 = 222; + })() }; diff --git a/tests/baselines/reference/classStaticBlock10(target=es5).js b/tests/baselines/reference/classStaticBlock10(target=es5).js index faa79b8dae154..73626c52f89ef 100644 --- a/tests/baselines/reference/classStaticBlock10(target=es5).js +++ b/tests/baselines/reference/classStaticBlock10(target=es5).js @@ -28,11 +28,13 @@ class C2 { } //// [classStaticBlock10.js] +var _C2__; var a1 = 1; var a2 = 1; var b1 = 2; var b2 = 2; function f() { + var _C1__; var a1 = 11; var b1 = 22; var C1 = /** @class */ (function () { @@ -40,9 +42,21 @@ function f() { } return C1; }()); + _C1__ = { value: (function () { + var a1 = 111; + var a2 = 111; + var b1_1 = 222; + var b2_1 = 222; + })() }; } var C2 = /** @class */ (function () { function C2() { } return C2; }()); +_C2__ = { value: (function () { + var a1 = 111; + var a2 = 111; + var b1_2 = 222; + var b2_2 = 222; + })() }; diff --git a/tests/baselines/reference/classStaticBlock18(target=es2015).js b/tests/baselines/reference/classStaticBlock18(target=es2015).js new file mode 100644 index 0000000000000..ac0a8ddc726a4 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es2015).js @@ -0,0 +1,33 @@ +//// [classStaticBlock18.ts] +function foo () { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + } + } + } +} + + +//// [classStaticBlock18.js] +function foo() { + var _a, _b, _c__, __; + return _a = class { + }, + _a.foo = 1, + __ = { value: (() => { + const c = (_b = class { + }, + _b.bar = 2, + _c__ = { value: (() => { + // do + })() }, + _b); + })() }, + _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..093ed790b745f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=es5).js @@ -0,0 +1,39 @@ +//// [classStaticBlock18.ts] +function foo () { + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + } + } + } +} + + +//// [classStaticBlock18.js] +function foo() { + var _a, _b, _c__, __; + return _a = /** @class */ (function () { + function class_1() { + } + return class_1; + }()), + _a.foo = 1, + __ = { value: (function () { + var c_1 = (_b = /** @class */ (function () { + function class_2() { + } + return class_2; + }()), + _b.bar = 2, + _c__ = { value: (function () { + // do + })() }, + _b); + })() }, + _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..6440791d08284 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock18(target=esnext).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 { + static { + var _b; + const c = (_b = class { + static { + // do + } + }, + _b.bar = 2, + _b); + } + }, + _a.foo = 1, + _a; +} 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/classStaticBlock2(target=es2015).js b/tests/baselines/reference/classStaticBlock2(target=es2015).js index d9477576ca879..54117f2a89471 100644 --- a/tests/baselines/reference/classStaticBlock2(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock2(target=es2015).js @@ -20,7 +20,18 @@ class C { //// [classStaticBlock2.js] +var _C__, _C__1; const a = 1; const b = 2; class C { } +_C__ = { value: (() => { + const a = 11; + a; + b; + })() }; +_C__1 = { value: (() => { + const a = 11; + a; + b; + })() }; diff --git a/tests/baselines/reference/classStaticBlock2(target=es5).js b/tests/baselines/reference/classStaticBlock2(target=es5).js index e535663fcdeaa..0a81e444d8148 100644 --- a/tests/baselines/reference/classStaticBlock2(target=es5).js +++ b/tests/baselines/reference/classStaticBlock2(target=es5).js @@ -20,6 +20,7 @@ class C { //// [classStaticBlock2.js] +var _C__, _C__1; var a = 1; var b = 2; var C = /** @class */ (function () { @@ -27,3 +28,13 @@ var C = /** @class */ (function () { } return C; }()); +_C__ = { value: (function () { + var a_1 = 11; + a_1; + b; + })() }; +_C__1 = { value: (function () { + var a_2 = 11; + a_2; + b; + })() }; diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index a2e3c0082ffd4..d9486fa05e40e 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -37,6 +37,7 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var _C__; var B = /** @class */ (function () { function B() { } @@ -50,3 +51,13 @@ var C = /** @class */ (function (_super) { } return C; }(B)); +_C__ = { value: (function () { + var await = 1; + var arguments = 1; + var eval = 1; + await: if (true) { + } + arguments; + await; + _this = _super.call(this) || this; + })() }; diff --git a/tests/baselines/reference/classStaticBlock7.js b/tests/baselines/reference/classStaticBlock7.js index de4d361871310..f0ef3ec6b7a79 100644 --- a/tests/baselines/reference/classStaticBlock7.js +++ b/tests/baselines/reference/classStaticBlock7.js @@ -9,8 +9,14 @@ class C { //// [classStaticBlock7.js] +var _C__; var C = /** @class */ (function () { function C() { } return C; }()); +_C__ = { value: (function () { + yield 1; + yield 1; + return 1; + })() }; diff --git a/tests/baselines/reference/classStaticBlock8.js b/tests/baselines/reference/classStaticBlock8.js index a8667ac2a80bb..4ba5d2f2aaa4f 100644 --- a/tests/baselines/reference/classStaticBlock8.js +++ b/tests/baselines/reference/classStaticBlock8.js @@ -36,12 +36,27 @@ function foo (v: number) { //// [classStaticBlock8.js] function foo(v) { + var _C__; label: while (v) { var C = /** @class */ (function () { function C() { } return C; }()); + _C__ = { value: (function () { + if (v === 1) { + break label; + } + if (v === 2) { + continue label; + } + if (v === 3) { + break; + } + if (v === 4) { + continue; + } + })() }; if (v === 5) { break label; } 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 + } + } + } + } +} From c3a8b27ba6a2ff8159f970288d44f9b866977bd2 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 26 Mar 2021 16:34:31 +0800 Subject: [PATCH 08/36] Accept baseline --- .../reference/api/tsserverlibrary.d.ts | 23 +++++++++---------- tests/baselines/reference/api/typescript.d.ts | 23 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 05f1929209087..705bf832fc9ce 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -270,12 +270,12 @@ declare namespace ts { PropertyDeclaration = 163, MethodSignature = 164, MethodDeclaration = 165, - Constructor = 166, - GetAccessor = 167, - SetAccessor = 168, - CallSignature = 169, - ConstructSignature = 170, - ClassStaticBlockDeclaration = 171, + ClassStaticBlockDeclaration = 166, + Constructor = 167, + GetAccessor = 168, + SetAccessor = 169, + CallSignature = 170, + ConstructSignature = 171, IndexSignature = 172, TypePredicate = 173, TypeReference = 174, @@ -561,7 +561,7 @@ declare namespace ts { } export interface JSDocContainer { } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | LabeledStatement | ExpressionStatement | VariableStatement | 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 | LabeledStatement | ExpressionStatement | VariableStatement | 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; @@ -842,9 +842,8 @@ declare namespace ts { readonly parent: ObjectTypeDeclaration; readonly type: TypeNode; } - export interface ClassStaticBlockDeclaration extends ClassElement { + export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.ClassStaticBlockDeclaration; - readonly staticToken: Token; readonly body: Block; } export interface TypeNode extends Node { @@ -3265,8 +3264,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(staticToken: Token, body: Block): ClassStaticBlockDeclaration; - updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, staticToken: Token, body: Block): ClassStaticBlockDeclaration; + 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; @@ -4276,7 +4275,6 @@ declare namespace ts { function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; - function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration); function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; @@ -4418,6 +4416,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; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index e7a9fbb6e780b..ca95a2524260d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -270,12 +270,12 @@ declare namespace ts { PropertyDeclaration = 163, MethodSignature = 164, MethodDeclaration = 165, - Constructor = 166, - GetAccessor = 167, - SetAccessor = 168, - CallSignature = 169, - ConstructSignature = 170, - ClassStaticBlockDeclaration = 171, + ClassStaticBlockDeclaration = 166, + Constructor = 167, + GetAccessor = 168, + SetAccessor = 169, + CallSignature = 170, + ConstructSignature = 171, IndexSignature = 172, TypePredicate = 173, TypeReference = 174, @@ -561,7 +561,7 @@ declare namespace ts { } export interface JSDocContainer { } - export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | LabeledStatement | ExpressionStatement | VariableStatement | 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 | LabeledStatement | ExpressionStatement | VariableStatement | 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; @@ -842,9 +842,8 @@ declare namespace ts { readonly parent: ObjectTypeDeclaration; readonly type: TypeNode; } - export interface ClassStaticBlockDeclaration extends ClassElement { + export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.ClassStaticBlockDeclaration; - readonly staticToken: Token; readonly body: Block; } export interface TypeNode extends Node { @@ -3265,8 +3264,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(staticToken: Token, body: Block): ClassStaticBlockDeclaration; - updateClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, staticToken: Token, body: Block): ClassStaticBlockDeclaration; + 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; @@ -4276,7 +4275,6 @@ declare namespace ts { function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; - function isClassStaticBlockDeclaration(node: Node): node is ClassStaticBlockDeclaration; function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration); function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; @@ -4418,6 +4416,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; From 4c19c80ece61cf67ca0b208c6f58ccbe277b374b Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 26 Mar 2021 16:54:29 +0800 Subject: [PATCH 09/36] Add decorator and modifier check --- src/compiler/checker.ts | 11 +++++-- .../reference/classStaticBlock19.errors.txt | 13 ++++++++ .../baselines/reference/classStaticBlock19.js | 19 +++++++++++ .../reference/classStaticBlock19.symbols | 10 ++++++ .../reference/classStaticBlock19.types | 12 +++++++ .../reference/classStaticBlock20.errors.txt | 26 +++++++++++++++ .../baselines/reference/classStaticBlock20.js | 32 +++++++++++++++++++ .../reference/classStaticBlock20.symbols | 17 ++++++++++ .../reference/classStaticBlock20.types | 17 ++++++++++ .../baselines/reference/classStaticBlock21.js | 20 ++++++++++++ .../reference/classStaticBlock21.symbols | 10 ++++++ .../reference/classStaticBlock21.types | 10 ++++++ .../classStaticBlock/classStaticBlock19.ts | 6 ++++ .../classStaticBlock/classStaticBlock20.ts | 13 ++++++++ .../classStaticBlock/classStaticBlock21.ts | 6 ++++ 15 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock19.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock19.js create mode 100644 tests/baselines/reference/classStaticBlock19.symbols create mode 100644 tests/baselines/reference/classStaticBlock19.types create mode 100644 tests/baselines/reference/classStaticBlock20.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock20.js create mode 100644 tests/baselines/reference/classStaticBlock20.symbols create mode 100644 tests/baselines/reference/classStaticBlock20.types create mode 100644 tests/baselines/reference/classStaticBlock21.js create mode 100644 tests/baselines/reference/classStaticBlock21.symbols create mode 100644 tests/baselines/reference/classStaticBlock21.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock19.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock20.ts create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock21.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b528f85f05e5f..2db5cfb5feaf4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32864,6 +32864,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); @@ -37962,6 +37968,8 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: return checkMethodDeclaration(node); + case SyntaxKind.ClassStaticBlockDeclaration: + return checkClassStaticBlockDeclaration(node); case SyntaxKind.Constructor: return checkConstructorDeclaration(node); case SyntaxKind.GetAccessor: @@ -38038,8 +38046,6 @@ namespace ts { return checkMappedType(node); case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(node); - case SyntaxKind.ClassStaticBlockDeclaration: - return forEachChild(node, checkSourceElement); case SyntaxKind.Block: case SyntaxKind.ModuleBlock: return checkBlock(node); @@ -40357,6 +40363,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); 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..8a1e4aabcdb23 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock19.js @@ -0,0 +1,19 @@ +//// [classStaticBlock19.ts] +class C { + @decorator + static { + // something + } +} + + +//// [classStaticBlock19.js] +var _C__; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +_C__ = { value: (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/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..44af03659c35d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock20.js @@ -0,0 +1,32 @@ +//// [classStaticBlock20.ts] +class C { + async static { + // something + } + + public static { + // something + } + + readonly private static { + // something + } +} + + +//// [classStaticBlock20.js] +var _C__, _C__1, _C__2; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +_C__ = { value: (function () { + // something + })() }; +_C__1 = { value: (function () { + // something + })() }; +_C__2 = { value: (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..a440cff2a2517 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock21.js @@ -0,0 +1,20 @@ +//// [classStaticBlock21.ts] +class C { + /* jsdocs */ + static { + // something + } +} + + +//// [classStaticBlock21.js] +var _C__; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +/* jsdocs */ +_C__ = { value: (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/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/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 + } +} From 3a61e56fd579ba7c7bcb0e01e4070bef9ca9e0d8 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 16 Apr 2021 17:57:48 +0800 Subject: [PATCH 10/36] Add functional boundary check --- src/compiler/checker.ts | 23 ++++ src/compiler/diagnosticMessages.json | 4 + src/compiler/parser.ts | 83 +++++++++--- src/compiler/types.ts | 5 +- .../classStaticBlock11(target=esnext).js | 3 +- .../classStaticBlock18(target=esnext).js | 26 ++-- .../reference/classStaticBlock22.errors.txt | 97 ++++++++++++++ .../baselines/reference/classStaticBlock22.js | 120 ++++++++++++++++++ .../reference/classStaticBlock22.symbols | 86 +++++++++++++ .../reference/classStaticBlock22.types | 111 ++++++++++++++++ .../classStaticBlock3(target=esnext).js | 6 +- ...lassStaticBlock4(target=esnext).errors.txt | 5 +- .../classStaticBlock4(target=esnext).js | 6 +- .../classStaticBlock5(target=esnext).js | 8 +- .../reference/classStaticBlock6.errors.txt | 11 +- .../classStaticBlock9(target=esnext).js | 4 +- .../classStaticBlock/classStaticBlock22.ts | 58 +++++++++ 17 files changed, 603 insertions(+), 53 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock22.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock22.js create mode 100644 tests/baselines/reference/classStaticBlock22.symbols create mode 100644 tests/baselines/reference/classStaticBlock22.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61e14cc9fbdfa..c0425e3c5f01b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23965,7 +23965,17 @@ namespace ts { } } + function checkGrammarIdentifierInClassStaticBlockContext(node: Identifier) { + if (node.flags & NodeFlags.ClassStaticBlockContext && ( + node.originalKeywordKind === SyntaxKind.AwaitKeyword || node.escapedText === "await" + )) { + grammarErrorOnNode(node, Diagnostics.Identifier_await_cannot_be_used_inside_class_static_block); + } + } + function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type { + checkGrammarIdentifierInClassStaticBlockContext(node); + const symbol = getResolvedSymbol(node); if (symbol === unknownSymbol) { return errorType; @@ -34488,6 +34498,9 @@ namespace ts { function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { + if (node.name) { + checkGrammarIdentifierInClassStaticBlockContext(node.name); + } checkFunctionOrMethodDeclaration(node); checkGrammarForGenerator(node); checkCollisionWithRequireExportsInGeneratedCode(node, node.name!); @@ -35213,6 +35226,11 @@ namespace ts { if (!node.name) { return; } + + if (node.name.kind === SyntaxKind.Identifier) { + checkGrammarIdentifierInClassStaticBlockContext(node.name); + } + // 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 @@ -36449,6 +36467,7 @@ namespace ts { function checkBreakOrContinueStatement(node: BreakOrContinueStatement) { // Grammar checking + if (node.label) checkGrammarIdentifierInClassStaticBlockContext(node.label); if (!checkGrammarStatementInAmbientContext(node)) checkGrammarBreakOrContinueStatement(node); // TODO: Check that target label is valid @@ -36592,6 +36611,7 @@ namespace ts { return false; }); } + checkGrammarIdentifierInClassStaticBlockContext(node.label); // ensure that label is unique checkSourceElement(node.statement); @@ -36914,6 +36934,9 @@ namespace ts { if (!node.name && !hasSyntacticModifier(node, ModifierFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } + if (node.name) { + checkGrammarIdentifierInClassStaticBlockContext(node.name); + } checkClassLikeDeclaration(node); forEach(node.members, checkSourceElement); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 270c1b7da3437..259194acacaaa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6473,5 +6473,9 @@ "Class decorators can't be used with static private identifier. Consider removing the experimental decorator.": { "category": "Error", "code": 18036 + }, + "Identifier 'await' cannot be used inside class static block.": { + "category": "Error", + "code": 18037 } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d952b55fea1ea..7b2c27038681c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1246,6 +1246,10 @@ namespace ts { setContextFlag(val, NodeFlags.AwaitContext); } + function setClassStaticBlockContext(val: boolean) { + setContextFlag(val, NodeFlags.ClassStaticBlockContext); + } + function doOutsideOfContext(context: NodeFlags, func: () => T): T { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear @@ -1320,6 +1324,10 @@ namespace ts { return doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext, func); } + function doOutsideOfClassStaticBlockContext(func: () => T): T { + return doOutsideOfContext(NodeFlags.ClassStaticBlockContext, func); + } + function inContext(flags: NodeFlags) { return (contextFlags & flags) !== 0; } @@ -1340,6 +1348,10 @@ namespace ts { return inContext(NodeFlags.AwaitContext); } + function inClassStaticBlockContext() { + return inContext(NodeFlags.ClassStaticBlockContext); + } + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): DiagnosticWithDetachedLocation | undefined { return parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0); } @@ -4113,6 +4125,9 @@ namespace ts { function parseSimpleArrowFunctionExpression(pos: number, identifier: Identifier, asyncModifier?: NodeArray | undefined): ArrowFunction { Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(false); + (identifier as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; const parameter = factory.createParameterDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, @@ -4128,6 +4143,7 @@ namespace ts { const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken); const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier); const node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body); + setClassStaticBlockContext(savedClassStaticBlockContext); return addJSDocComment(finishNode(node, pos)); } @@ -4339,6 +4355,10 @@ namespace ts { } function parseParenthesizedArrowFunctionExpression(allowAmbiguity: boolean): ArrowFunction | undefined { + return doOutsideOfClassStaticBlockContext(() => parseParenthesizedArrowFunctionExpressionWorker(allowAmbiguity)); + } + + function parseParenthesizedArrowFunctionExpressionWorker(allowAmbiguity: boolean): ArrowFunction | undefined { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiersForArrowFunction(); @@ -5512,6 +5532,10 @@ namespace ts { parseExpected(SyntaxKind.ColonToken); const initializer = allowInAnd(parseAssignmentExpressionOrHigher); node = factory.createPropertyAssignment(name, initializer); + if (!isComputedPropertyName(name)) { + // propertyName should not care ClassStaticBlockContext if not computed property name. + (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; + } } // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker node.decorators = decorators; @@ -5537,10 +5561,12 @@ namespace ts { // // FunctionExpression: // function BindingIdentifier[opt](FormalParameters){ FunctionBody } - const saveDecoratorContext = inDecoratorContext(); - if (saveDecoratorContext) { + const savedDecoratorContext = inDecoratorContext(); + if (savedDecoratorContext) { setDecoratorContext(/*val*/ false); } + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(false); const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -5560,9 +5586,10 @@ namespace ts { const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlock(isGenerator | isAsync); - if (saveDecoratorContext) { + if (savedDecoratorContext) { setDecoratorContext(/*val*/ true); } + setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -6297,6 +6324,8 @@ namespace ts { else { parseExpected(SyntaxKind.ColonToken); name = parseIdentifierOrPattern(); + // propertyName should not care about the ClassStaticBlockContext + (propertyName as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; } const initializer = parseInitializer(); return finishNode(factory.createBindingElement(dotDotDotToken, propertyName, name, initializer), pos); @@ -6414,6 +6443,7 @@ namespace ts { function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): FunctionDeclaration { const savedAwaitContext = inAwaitContext(); + const savedClassStaticBlockContext = inClassStaticBlockContext(); const modifierFlags = modifiersToFlags(modifiers); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -6423,10 +6453,12 @@ namespace ts { const isAsync = modifierFlags & ModifierFlags.Async ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); if (modifierFlags & ModifierFlags.Export) setAwaitContext(/*value*/ true); + setClassStaticBlockContext(false); const parameters = parseParameters(isGenerator | isAsync); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlockOrSemicolon(isGenerator | isAsync, Diagnostics.or_expected); setAwaitContext(savedAwaitContext); + setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionDeclaration(decorators, modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6516,17 +6548,27 @@ namespace ts { ): PropertyDeclaration | MethodDeclaration { const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const name = parsePropertyName(); + if (!isComputedPropertyName(name)) { + // property name is not care about ClassStaticBlockContext if not computed property name. + (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; + } // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(pos, hasJSDoc, decorators, modifiers, asteriskToken, name, questionToken, /*exclamationToken*/ undefined, Diagnostics.or_expected); + return doOutsideOfClassStaticBlockContext(() => parseMethodDeclaration(pos, hasJSDoc, decorators, modifiers, asteriskToken, name, questionToken, /*exclamationToken*/ undefined, Diagnostics.or_expected)); } - return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken); + return doOutsideOfClassStaticBlockContext(() => parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken)); } function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration { + const savedClassStaticBlockContext = inClassStaticBlockContext(); const name = parsePropertyName(); + if (!isComputedPropertyName(name)) { + // property name is not care about ClassStaticBlockContext if not computed property name. + (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; + } + setClassStaticBlockContext(false); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6537,6 +6579,7 @@ namespace ts { // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors node.typeParameters = typeParameters; if (type && node.kind === SyntaxKind.SetAccessor) (node as Mutable).type = type; + setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6616,18 +6659,11 @@ namespace ts { } function parseClassStaticBlockBodyBlock() { - const savedYieldContext = inYieldContext(); - setYieldContext(false); - - const savedAwaitContext = inAwaitContext(); - setAwaitContext(false); - - const block = parseBlock(/*ignoreMissingOpenBrace*/ false); - - setAwaitContext(savedAwaitContext); - setYieldContext(savedYieldContext); - - return block; + return doOutsideOfYieldAndAwaitContext(() => { + return doInsideOfContext(NodeFlags.ClassStaticBlockContext, () => { + return parseBlock(/*ignoreMissingOpenBrace*/ false); + }); + }); } function parseDecoratorExpression() { @@ -6783,9 +6819,21 @@ namespace ts { function parseClassDeclarationOrExpression(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: ClassLikeDeclaration["kind"]): ClassLikeDeclaration { const savedAwaitContext = inAwaitContext(); + const savedClassStaticBlockContext = inClassStaticBlockContext(); parseExpected(SyntaxKind.ClassKeyword); + + if (kind === SyntaxKind.ClassExpression) { + // all class expression is not inside function boundary + setClassStaticBlockContext(false); + } // We don't parse the name here in await context, instead we will report a grammar error in the checker. const name = parseNameOfClassDeclarationOrExpression(); + + if (kind === SyntaxKind.ClassDeclaration) { + // class declaration's name is inside function boundary + setClassStaticBlockContext(false); + } + const typeParameters = parseTypeParameters(); if (some(modifiers, isExportModifier)) setAwaitContext(/*value*/ true); const heritageClauses = parseHeritageClauses(); @@ -6801,6 +6849,7 @@ namespace ts { members = createMissingList(); } setAwaitContext(savedAwaitContext); + setClassStaticBlockContext(savedClassStaticBlockContext); const node = kind === SyntaxKind.ClassDeclaration ? factory.createClassDeclaration(decorators, modifiers, name, typeParameters, heritageClauses, members) : factory.createClassExpression(decorators, modifiers, name, typeParameters, heritageClauses, members); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 20717df903f6a..b65f68d4fb1c8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -768,6 +768,7 @@ namespace ts { JsonFile = 1 << 25, // If node was parsed in a Json /* @internal */ TypeCached = 1 << 26, // If a type was cached for node at any point /* @internal */ Deprecated = 1 << 27, // If has '@deprecated' JSDoc tag + ClassStaticBlockContext = 1 << 28, // If node was parsed in the 'class static block' and not in another function boundary. BlockScoped = Let | Const, @@ -775,10 +776,10 @@ namespace ts { ReachabilityAndEmitFlags = ReachabilityCheckFlags | HasAsyncFunctions, // Parsing context flags - ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | JavaScriptFile | InWithStatement | Ambient, + ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | ClassStaticBlockContext | JavaScriptFile | InWithStatement | Ambient, // Exclude these flags when parsing a Type - TypeExcludesFlags = YieldContext | AwaitContext, + TypeExcludesFlags = YieldContext | AwaitContext | ClassStaticBlockContext, // Represents all flags that are potentially set once and // never cleared on SourceFiles which get re-used in between incremental parses. diff --git a/tests/baselines/reference/classStaticBlock11(target=esnext).js b/tests/baselines/reference/classStaticBlock11(target=esnext).js index af7697baf6644..42228bd5d223d 100644 --- a/tests/baselines/reference/classStaticBlock11(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock11(target=esnext).js @@ -16,11 +16,10 @@ class C { //// [classStaticBlock11.js] let getX; class C { + #x = 1; constructor(x) { - this.#x = 1; this.#x = x; } - #x; static { // getX has privileged access to #x getX = (obj) => obj.#x; diff --git a/tests/baselines/reference/classStaticBlock18(target=esnext).js b/tests/baselines/reference/classStaticBlock18(target=esnext).js index 6440791d08284..ed8123e3e059d 100644 --- a/tests/baselines/reference/classStaticBlock18(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock18(target=esnext).js @@ -16,19 +16,15 @@ function foo () { //// [classStaticBlock18.js] function foo() { - var _a; - return _a = class { - static { - var _b; - const c = (_b = class { - static { - // do - } - }, - _b.bar = 2, - _b); - } - }, - _a.foo = 1, - _a; + return class { + static foo = 1; + static { + const c = class { + static bar = 2; + static { + // do + } + }; + } + }; } diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt new file mode 100644 index 0000000000000..f1c0c0138e5d3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -0,0 +1,97 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(7,11): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS2349: This expression is not callable. + Type 'String' has no call signatures. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(22,14): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(25,11): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(28,8): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Identifier 'await' cannot be used inside class static block. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (12 errors) ==== + let await: "any"; + class C { + static { + let await: any; // illegal, cannot declare a new binding for await + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + let { await } = {} as any; // illegal, cannot declare a new binding for await + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + let { await: other } = {} as any; // legal + } + static { + let await; // illegal, cannot declare a new binding for await + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + await; // illegal + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + await(1); // illegal + ~~~~~ +!!! error TS2349: This expression is not callable. +!!! error TS2349: Type 'String' has no call signatures. + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + function await() {}; // illegal + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + class await {}; // illegal + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + ({ await }); // illegal short-hand property reference + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + ({ [await]: 1 }); // illegal + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + [await] = 1; // illegal (computed property names are evaluated outside of a class body + }; + } + 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 { + await: // illegal, 'await' cannot be used as a label + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + break await; // illegal, 'await' cannot be used as a label + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. + } + } \ 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..290c21a5e7e64 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.js @@ -0,0 +1,120 @@ +//// [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 { + await; // illegal + } + static { + await(1); // illegal + } + static { + function await() {}; // illegal + } + static { + class await {}; // illegal + } + static { + ({ await }); // illegal short-hand property reference + } + static { + ({ [await]: 1 }); // illegal + } + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + [await] = 1; // illegal (computed property names are evaluated outside of a class body + }; + } + 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 { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } +} + +//// [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 { + await; // illegal + } + static { + await(1); // illegal + } + static { + function await() { } + ; // illegal + } + static { + class await { + } + ; // illegal + } + static { + ({ await }); // illegal short-hand property reference + } + static { + ({ [await]: 1 }); // illegal + } + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + [await] = 1; // illegal (computed property names are evaluated outside of a class body + } + ; + } + 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 { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } +} diff --git a/tests/baselines/reference/classStaticBlock22.symbols b/tests/baselines/reference/classStaticBlock22.symbols new file mode 100644 index 0000000000000..967d2e75b7283 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.symbols @@ -0,0 +1,86 @@ +=== 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 { + await; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + static { + await(1); // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + static { + function await() {}; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 20, 10)) + } + static { + class await {}; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 23, 10)) + } + static { + ({ await }); // illegal short-hand property reference +>await : Symbol(await, Decl(classStaticBlock22.ts, 27, 6)) + } + static { + ({ [await]: 1 }); // illegal +>[await] : Symbol([await], Decl(classStaticBlock22.ts, 30, 6)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + static { + class D { +>D : Symbol(D, Decl(classStaticBlock22.ts, 32, 10)) + + await = 1; // legal +>await : Symbol(D.await, Decl(classStaticBlock22.ts, 33, 13)) + + x = await; // legal (initializers have an implicit function boundary) +>x : Symbol(D.x, Decl(classStaticBlock22.ts, 34, 18)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + [await] = 1; // illegal (computed property names are evaluated outside of a class body +>[await] : Symbol(D[await], Decl(classStaticBlock22.ts, 35, 18)) +>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, 40, 5)) + } + static { + (class await {}); // legal, 'await' in class expression name not bound inside of static block +>await : Symbol(await, Decl(classStaticBlock22.ts, 43, 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 { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } +} diff --git a/tests/baselines/reference/classStaticBlock22.types b/tests/baselines/reference/classStaticBlock22.types new file mode 100644 index 0000000000000..ce6f17adbb39f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock22.types @@ -0,0 +1,111 @@ +=== 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 { + await; // illegal +>await : "any" + } + static { + await(1); // illegal +>await(1) : any +>await : "any" +>1 : 1 + } + static { + function await() {}; // illegal +>await : () => void + } + static { + class await {}; // illegal +>await : await + } + static { + ({ await }); // illegal short-hand property reference +>({ await }) : { await: "any"; } +>{ await } : { await: "any"; } +>await : "any" + } + static { + ({ [await]: 1 }); // illegal +>({ [await]: 1 }) : { any: number; } +>{ [await]: 1 } : { any: number; } +>[await] : number +>await : "any" +>1 : 1 + } + 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" + + [await] = 1; // illegal (computed property names are evaluated outside of a class body +>[await] : number +>await : "any" +>1 : 1 + + }; + } + 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 { + await: // illegal, 'await' cannot be used as a label +>await : any + + break await; // illegal, 'await' cannot be used as a label +>await : any + } +} diff --git a/tests/baselines/reference/classStaticBlock3(target=esnext).js b/tests/baselines/reference/classStaticBlock3(target=esnext).js index 548d2aaa16f27..99fe38cf28e28 100644 --- a/tests/baselines/reference/classStaticBlock3(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock3(target=esnext).js @@ -21,13 +21,13 @@ class C { //// [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; } -C.f1 = 1; -C.f2 = 2; -C.f3 = 3; diff --git a/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt index 87e988d8b1c6e..1768750e34f12 100644 --- a/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (2 errors) ==== class C { static s1 = 1; @@ -21,7 +20,5 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): er static s2 = 2; static ss2 = this.s1; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4(target=esnext).js b/tests/baselines/reference/classStaticBlock4(target=esnext).js index 9bc8a29c8ac43..b8821bc0f36c4 100644 --- a/tests/baselines/reference/classStaticBlock4(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).js @@ -17,13 +17,13 @@ class C { //// [classStaticBlock4.js] class C { + static s1 = 1; static { this.s1; C.s1; this.s2; C.s2; } + static s2 = 2; + static ss2 = this.s1; } -C.s1 = 1; -C.s2 = 2; -C.ss2 = this.s1; diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).js b/tests/baselines/reference/classStaticBlock5(target=esnext).js index 8132aada6b28d..84fece2b40219 100644 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).js @@ -18,15 +18,15 @@ class C extends B { //// [classStaticBlock5.js] class B { + static a = 1; + static b = 2; } -B.a = 1; -B.b = 2; class C extends B { + static b = 3; + static c = super.a; static { this.b; super.b; super.a; } } -C.b = 3; -C.c = super.a; diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 6b18acbb48a3b..e0ade776056e6 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): error TS18037: Identifier 'await' cannot be used inside class static block. 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(12,9): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS18037: Identifier 'await' cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (3 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (6 errors) ==== class B { static a = 1; } @@ -11,6 +14,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err class C extends B { static { var await = 1; + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. var arguments = 1; ~~~~~~~~~ !!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. @@ -20,11 +25,15 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err await: if (true) { + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. } arguments; await; + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. diff --git a/tests/baselines/reference/classStaticBlock9(target=esnext).js b/tests/baselines/reference/classStaticBlock9(target=esnext).js index e680483660562..de762275b1eec 100644 --- a/tests/baselines/reference/classStaticBlock9(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).js @@ -10,9 +10,9 @@ class A { //// [classStaticBlock9.js] class A { + static bar = A.foo + 1; static { A.foo + 2; } + static foo = 1; } -A.bar = A.foo + 1; -A.foo = 1; diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts new file mode 100644 index 0000000000000..642836ad81863 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts @@ -0,0 +1,58 @@ +// @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 { + await; // illegal + } + static { + await(1); // illegal + } + static { + function await() {}; // illegal + } + static { + class await {}; // illegal + } + static { + ({ await }); // illegal short-hand property reference + } + static { + ({ [await]: 1 }); // illegal + } + static { + class D { + await = 1; // legal + x = await; // legal (initializers have an implicit function boundary) + [await] = 1; // illegal (computed property names are evaluated outside of a class body + }; + } + 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 { + await: // illegal, 'await' cannot be used as a label + break await; // illegal, 'await' cannot be used as a label + } +} \ No newline at end of file From 1bed545566f64bf1f3b66877cd93e4883b7f36ab Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 23 Apr 2021 14:41:09 +0800 Subject: [PATCH 11/36] Fix conflict --- src/compiler/emitter.ts | 1253 --------------------------------------- 1 file changed, 1253 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 84108339e6e39..c9c8279628a5e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5699,1259 +5699,6 @@ namespace ts { } } -<<<<<<< HEAD - const enum PreprintPipelinePhase { - Notification, - Substitution, - Visit - } - - function createPreprinter(handlers: PrintHandlers) { - const { - substituteNode = noEmitSubstitution, - onEmitNode = noEmitNotification, - isEmitNotificationEnabled - } = handlers; - - let pipelineResult: Node | undefined; - - // Outer visitors - // - // These visitors are invoked by inner visitors to re-enter the pipeline - // for notification and substitution. - - const visit = makeVisitor(pipelineVisitorForUnspecified); - const visitSourceFile = makeVisitor(pipelineVisitorForSourceFile, isSourceFile); - const visitIdentifierName = makeVisitor(pipelineVisitorForIdentifierName, isIdentifier); - const visitModuleName = makeVisitor(pipelineVisitorForIdentifierNameOrUnspecified, isModuleName); - const visitPropertyName = makeVisitor(pipelineVisitorForIdentifierNameOrUnspecified, isPropertyName); - const visitMemberName = makeVisitor(pipelineVisitorForIdentifierNameOrUnspecified, isMemberName); - const visitBindingName = makeVisitor(pipelineVisitorForIdentifierNameOrUnspecified, isBindingName); - const visitEntityName = makeVisitor(pipelineVisitorForIdentifierReferenceOrUnspecified, isEntityName); - const visitExpression = makeVisitor(pipelineVisitorForExpression, isExpression); - const visitForInitializer = makeVisitor(pipelineVisitorForForInitializer, isForInitializer); - const visitTypeNode = makeVisitor(pipelineVisitorForUnspecified, isTypeNode); - const visitEmbeddedStatement = makeVisitor(pipelineVisitorForEmbeddedStatement, isStatement, factory.liftToBlock); - const visitJsxAttributeValue = makeVisitor(pipelineVisitorForJsxAttributeValue, isStringLiteralOrJsxExpression); - const visitMappedTypeParameter = makeVisitor(pipelineVisitorForMappedTypeParameter, isTypeParameterDeclaration); - const visitConciseBody = makeVisitor(pipelineVisitorForConciseBody, isConciseBody); - const visitFunctionBody = makeVisitor(pipelineVisitorForUnspecified, isFunctionBody); - const visitList = makeListVisitor(pipelineVisitorForUnspecified); - const visitTypeNodeList = makeListVisitor(pipelineVisitorForUnspecified, isTypeNode); - const visitExpressionList = makeListVisitor(pipelineVisitorForExpression, isExpression); - const visitParameterList = makeListVisitor(pipelineVisitorForUnspecified, isParameter); - - function makeVisitor(outerVisitor: (node: Node) => Node | undefined, defaultTest?: (node: Node) => node is T, lift?: (nodes: readonly Node[]) => Node) { - function visit(node: T, test: (node: Node) => node is U): U; - function visit(node: T | undefined, test: (node: Node) => node is U): U | undefined; - function visit(node: T, test?: (node: Node) => node is T): T; - function visit(node: T | undefined, test?: (node: Node) => node is T): T | undefined; - function visit(node: Node | undefined, test?: (node: Node) => node is T): Node | undefined { - return visitNode(node, outerVisitor, test || defaultTest, lift); - } - return visit; - } - - function makeListVisitor(outerVisitor: (node: Node) => Node | undefined, defaultTest?: (node: Node) => node is T) { - function visitList(nodes: NodeArray, test: (node: Node) => node is U): NodeArray; - function visitList(nodes: NodeArray | undefined, test: (node: Node) => node is U): NodeArray | undefined; - function visitList(nodes: NodeArray, test?: (node: Node) => boolean): NodeArray; - function visitList(nodes: NodeArray | undefined, test?: (node: Node) => boolean): NodeArray | undefined; - function visitList(nodes: NodeArray | undefined, test: (node: Node) => boolean = defaultTest || returnTrue): NodeArray | undefined { - return visitNodes(nodes, outerVisitor, test); - } - return visitList; - } - - // Pipeline Visitors - // - // These visitors execute our existing pipeline logic for notification and substitution, - // but adapted to our visitor pattern. In some cases, we refine the `EmitHint` we pass - // to the `onEmitNode` and `substituteNode` APIs to ensure they receive the appropriate - // context. - // - // For example, the ConciseBody of an arrow function could be an Identifier, in which - // case we would want to use `EmitHint.Expression` to ensure we treat the identifier - // as an expression during substitution. - - function pipelineVisitorForSourceFile(node: SourceFile) { return pipelineVisitorWorker(EmitHint.SourceFile, node); } - function pipelineVisitorForExpression(node: Expression) { return pipelineVisitorWorker(EmitHint.Expression, node); } - function pipelineVisitorForIdentifierName(node: Identifier) { return pipelineVisitorWorker(EmitHint.IdentifierName, node); } - function pipelineVisitorForIdentifierNameOrUnspecified(node: Node) { return pipelineVisitorWorker(isIdentifier(node) ? EmitHint.IdentifierName : EmitHint.Unspecified, node); } - function pipelineVisitorForIdentifierReferenceOrUnspecified(node: Node) { return pipelineVisitorWorker(isIdentifier(node) ? EmitHint.Expression : EmitHint.Unspecified, node); } - function pipelineVisitorForForInitializer(node: ForInitializer) { return pipelineVisitorWorker(isVariableDeclarationList(node) ? EmitHint.Unspecified : EmitHint.Expression, node); } - function pipelineVisitorForMappedTypeParameter(node: TypeParameterDeclaration) { return pipelineVisitorWorker(EmitHint.MappedTypeParameter, node); } - function pipelineVisitorForEmbeddedStatement(node: Statement) { return pipelineVisitorWorker(isEmptyStatement(node) ? EmitHint.EmbeddedStatement : EmitHint.Unspecified, node); } - function pipelineVisitorForJsxAttributeValue(node: StringLiteral | JsxExpression) { return pipelineVisitorWorker(isStringLiteral(node) ? EmitHint.JsxAttributeValue : EmitHint.Unspecified, node); } - function pipelineVisitorForConciseBody(node: ConciseBody) { return pipelineVisitorWorker(isBlock(node) ? EmitHint.Unspecified : EmitHint.Expression, node); } - function pipelineVisitorForUnspecified(node: Node) { return pipelineVisitorWorker(EmitHint.Unspecified, node); } - - /** - * Adapts the emit pipeline API to work with the visitor API - */ - function pipelineVisitorWorker(hint: EmitHint, node: Node) { - resetPipelineResult(); - // Get the first supported pipeline phase for this node and evaluate it. We can skip several stack - // frames if we aren't doing emit notification, so we check for substitution and direct callbacks - // and execute those immediately. - const pipelinePhase = getPipelinePhase(PreprintPipelinePhase.Notification, node); - if (pipelinePhase === pipelineVisitDirect) { - return visitor(hint, node); - } - - if (pipelinePhase === pipelineVisitWithSubstitution) { - // The next phase after substitution is always direct visitation, so we can reduce the call stack - // depth by calling the visitor directly. - return visitor(hint, substituteNode(hint, node)); - } - - pipelinePhase(hint, node); - Debug.assertIsDefined(pipelineResult); - const result = pipelineResult; - resetPipelineResult(); - return result; - } - - function resetPipelineResult() { - pipelineResult = undefined; - } - - /** - * Gets the pipeline callback to pass to the relevant API (i.e., `substituteNode` or `onEmitNode`) - */ - function getPipelinePhase(phase: PreprintPipelinePhase, node: Node) { - switch (phase) { - case PreprintPipelinePhase.Notification: - if (onEmitNode !== noEmitNotification && (!isEmitNotificationEnabled || isEmitNotificationEnabled(node))) { - return pipelineVisitWithNotification; - } - // falls through - case PreprintPipelinePhase.Substitution: - if (substituteNode !== noEmitSubstitution) { - return pipelineVisitWithSubstitution; - } - // falls through - default: - return pipelineVisitDirect; - } - } - - /** - * A callback that can be evaluated to trigger emit notification as part of the emit pipeline. - */ - function pipelineVisitWithNotification(hint: EmitHint, node: Node) { - onEmitNode(hint, node, getPipelinePhase(PreprintPipelinePhase.Substitution, node)); - } - - /** - * A callback that can be evaluated to trigger JIT substitution as part of the emit pipeline. - */ - function pipelineVisitWithSubstitution(hint: EmitHint, node: Node) { - // Next phase is always direct visitation, so we can reduce the call stack - // depth by calling the visitor directly. - pipelineResult = visitor(hint, substituteNode(hint, node)); - } - - /** - * A callback that can be evaluated to visit the subtree of a node. - */ - function pipelineVisitDirect(hint: EmitHint, node: Node) { - pipelineResult = visitor(hint, node); - } - - /** - * Re-enters the visitor pattern from the pipeline pattern to perform - * tree updates and trigger parenthesization rules. - */ - function visitor(hint: EmitHint, node: Node): Node { - // This should align with the assertions in `pipelineEmitWithHint`. - if (hint === EmitHint.SourceFile) return preprintSourceFile(cast(node, isSourceFile)); - if (hint === EmitHint.IdentifierName) return preprintIdentifier(cast(node, isIdentifier)); - if (hint === EmitHint.JsxAttributeValue) return cast(node, isStringLiteral); - if (hint === EmitHint.MappedTypeParameter) return preprintTypeParameterDeclaration(cast(node, isTypeParameterDeclaration)); - if (hint === EmitHint.EmbeddedStatement) return cast(node, isEmptyStatement); - - const kind = node.kind; - // No need to visit nodes without children. - if ((kind > SyntaxKind.FirstToken && kind <= SyntaxKind.LastToken) || kind === SyntaxKind.ThisType) { - return node; - } - - if (hint === EmitHint.Unspecified) { - if (isKeyword(node.kind)) return node; - - switch (node.kind) { - // Identifiers - case SyntaxKind.Identifier: - return preprintIdentifier(node as Identifier); - - // Names - case SyntaxKind.QualifiedName: - Debug.type(node); - return factory.updateQualifiedName(node, - visitEntityName(node.left), - visitIdentifierName(node.right)); - - case SyntaxKind.ComputedPropertyName: - Debug.type(node); - return factory.updateComputedPropertyName(node, - visitExpression(node.expression)); - - // Signature elements - case SyntaxKind.TypeParameter: - return preprintTypeParameterDeclaration(node as TypeParameterDeclaration); - - case SyntaxKind.Parameter: - Debug.type(node); - return factory.updateParameterDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visit(node.dotDotDotToken, isDotDotDotToken), - visitBindingName(node.name), - visit(node.questionToken, isQuestionToken), - visitTypeNode(node.type), - visitExpression(node.initializer)); - - case SyntaxKind.Decorator: - Debug.type(node); - return factory.updateDecorator(node, - visitExpression(node.expression)); - - // Type members - case SyntaxKind.PropertySignature: - Debug.type(node); - return factory.updatePropertySignature(node, - visitList(node.modifiers, isModifier), - visitPropertyName(node.name), - visit(node.questionToken, isQuestionToken), - visitTypeNode(node.type)); - - case SyntaxKind.PropertyDeclaration: - Debug.type(node); - return factory.updatePropertyDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitPropertyName(node.name), - visit(node.questionToken || node.exclamationToken, isQuestionOrExclamationToken), - visitTypeNode(node.type), - visitExpression(node.initializer)); - - case SyntaxKind.MethodSignature: - Debug.type(node); - return factory.updateMethodSignature(node, - visitList(node.modifiers, isModifier), - visitPropertyName(node.name), - visit(node.questionToken, isQuestionToken), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type)); - - case SyntaxKind.MethodDeclaration: - Debug.type(node); - return factory.updateMethodDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visit(node.asteriskToken, isAsteriskToken), - visitPropertyName(node.name), - visit(node.questionToken, isQuestionToken), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type), - visitFunctionBody(node.body)); - - case SyntaxKind.ClassStaticBlockDeclaration: - Debug.type(node); - return factory.updateClassStaticBlockDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitFunctionBody(node.body)); - - case SyntaxKind.Constructor: - Debug.type(node); - return factory.updateConstructorDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitParameterList(node.parameters), - visitFunctionBody(node.body)); - - case SyntaxKind.GetAccessor: - Debug.type(node); - return factory.updateGetAccessorDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitPropertyName(node.name), - visitParameterList(node.parameters), - visitTypeNode(node.type), - visitFunctionBody(node.body)); - - case SyntaxKind.SetAccessor: - Debug.type(node); - return factory.updateSetAccessorDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitPropertyName(node.name), - visitParameterList(node.parameters), - visitFunctionBody(node.body)); - - case SyntaxKind.CallSignature: - Debug.type(node); - return factory.updateCallSignature(node, - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type)); - - case SyntaxKind.ConstructSignature: - Debug.type(node); - return factory.updateConstructSignature(node, - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type)); - - case SyntaxKind.IndexSignature: - Debug.type(node); - return factory.updateIndexSignature(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitParameterList(node.parameters), - visitTypeNode(node.type)); - - // Types - case SyntaxKind.TypePredicate: - Debug.type(node); - return factory.updateTypePredicateNode(node, - visit(node.assertsModifier, isAssertsKeyword), - visit(node.parameterName, isIdentifierOrThisTypeNode), - visitTypeNode(node.type)); - - case SyntaxKind.TypeReference: - Debug.type(node); - return factory.updateTypeReferenceNode(node, - visitEntityName(node.typeName), - visitTypeNodeList(node.typeArguments)); - - case SyntaxKind.FunctionType: - Debug.type(node); - return factory.updateFunctionTypeNode(node, - visitList(node.typeParameters, isTypeParameterDeclaration), - visitNodes(node.parameters, pipelineVisitorForUnspecified, isParameterDeclaration), - visitTypeNode(node.type)); - - case SyntaxKind.ConstructorType: - Debug.type(node); - return factory.updateConstructorTypeNode(node, - visitNodes(node.modifiers, pipelineVisitorForUnspecified, isModifier), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type)); - - case SyntaxKind.TypeQuery: - Debug.type(node); - return factory.updateTypeQueryNode(node, - visitEntityName(node.exprName)); - - case SyntaxKind.TypeLiteral: - Debug.type(node); - return factory.updateTypeLiteralNode(node, - visitList(node.members, isTypeElement)); - - case SyntaxKind.ArrayType: - Debug.type(node); - return factory.updateArrayTypeNode(node, - visitTypeNode(node.elementType)); - - case SyntaxKind.TupleType: - Debug.type(node); - return factory.updateTupleTypeNode(node, - visitTypeNodeList(node.elements)); - - case SyntaxKind.OptionalType: - Debug.type(node); - return factory.updateOptionalTypeNode(node, - visitTypeNode(node.type)); - - case SyntaxKind.RestType: - Debug.type(node); - return factory.updateRestTypeNode(node, - visitTypeNode(node.type)); - - case SyntaxKind.UnionType: - Debug.type(node); - return factory.updateUnionTypeNode(node, - visitTypeNodeList(node.types)); - - case SyntaxKind.IntersectionType: - Debug.type(node); - return factory.updateIntersectionTypeNode(node, - visitTypeNodeList(node.types)); - - case SyntaxKind.ConditionalType: - Debug.type(node); - return factory.updateConditionalTypeNode(node, - visitTypeNode(node.checkType), - visitTypeNode(node.extendsType), - visitTypeNode(node.trueType), - visitTypeNode(node.falseType)); - - case SyntaxKind.InferType: - Debug.type(node); - return factory.updateInferTypeNode(node, - visit(node.typeParameter, isTypeParameterDeclaration)); - - case SyntaxKind.ImportType: - Debug.type(node); - return factory.updateImportTypeNode(node, - visitTypeNode(node.argument), - visitEntityName(node.qualifier), - visitTypeNodeList(node.typeArguments), - node.isTypeOf - ); - - case SyntaxKind.NamedTupleMember: - Debug.type(node); - return factory.updateNamedTupleMember(node, - visit(node.dotDotDotToken, isDotDotDotToken), - visitIdentifierName(node.name), - visit(node.questionToken, isQuestionToken), - visitTypeNode(node.type), - ); - - case SyntaxKind.ParenthesizedType: - Debug.type(node); - return factory.updateParenthesizedType(node, - visitTypeNode(node.type)); - - case SyntaxKind.ExpressionWithTypeArguments: - Debug.type(node); - return factory.updateExpressionWithTypeArguments(node, - visitExpression(node.expression), - visitTypeNodeList(node.typeArguments)); - - case SyntaxKind.TypeOperator: - Debug.type(node); - return factory.updateTypeOperatorNode(node, - visitTypeNode(node.type)); - - case SyntaxKind.IndexedAccessType: - Debug.type(node); - return factory.updateIndexedAccessTypeNode(node, - visitTypeNode(node.objectType), - visitTypeNode(node.indexType)); - - case SyntaxKind.MappedType: - Debug.type(node); - return factory.updateMappedTypeNode(node, - visit(node.readonlyToken, isReadonlyKeywordOrPlusOrMinusToken), - visitMappedTypeParameter(node.typeParameter), - visitTypeNode(node.nameType), - visit(node.questionToken, isQuestionOrPlusOrMinusToken), - visitTypeNode(node.type)); - - case SyntaxKind.LiteralType: - Debug.type(node); - return factory.updateLiteralTypeNode(node, - visitExpression(node.literal, isLiteralTypeLikeExpression)); - - case SyntaxKind.TemplateLiteralType: - Debug.type(node); - return factory.updateTemplateLiteralType(node, - visit(node.head, isTemplateHead), - visitList(node.templateSpans, isTemplateLiteralTypeSpan)); - - case SyntaxKind.TemplateLiteralTypeSpan: - Debug.type(node); - return factory.updateTemplateLiteralTypeSpan(node, - visitTypeNode(node.type), - visit(node.literal, isTemplateMiddleOrTemplateTail)); - - // Binding patterns - case SyntaxKind.ObjectBindingPattern: - Debug.type(node); - return factory.updateObjectBindingPattern(node, - visitList(node.elements, isBindingElement)); - - case SyntaxKind.ArrayBindingPattern: - Debug.type(node); - return factory.updateArrayBindingPattern(node, - visitList(node.elements, isArrayBindingElement)); - - case SyntaxKind.BindingElement: - Debug.type(node); - return factory.updateBindingElement(node, - visit(node.dotDotDotToken, isDotDotDotToken), - visitPropertyName(node.propertyName), - visitBindingName(node.name), - visitExpression(node.initializer)); - - // Misc - case SyntaxKind.TemplateSpan: - Debug.type(node); - return factory.updateTemplateSpan(node, - visitExpression(node.expression), - visit(node.literal, isTemplateMiddleOrTemplateTail)); - - // Element - case SyntaxKind.Block: - Debug.type(node); - return factory.updateBlock(node, - visitList(node.statements, isStatement)); - - case SyntaxKind.VariableStatement: - Debug.type(node); - return factory.updateVariableStatement(node, - visitList(node.modifiers, isModifier), - visit(node.declarationList, isVariableDeclarationList)); - - case SyntaxKind.ExpressionStatement: - Debug.type(node); - return factory.updateExpressionStatement(node, - visitExpression(node.expression)); - - case SyntaxKind.IfStatement: - Debug.type(node); - return factory.updateIfStatement(node, - visitExpression(node.expression), - visitEmbeddedStatement(node.thenStatement), - visitEmbeddedStatement(node.elseStatement)); - - case SyntaxKind.DoStatement: - Debug.type(node); - return factory.updateDoStatement(node, - visitEmbeddedStatement(node.statement), - visitExpression(node.expression)); - - case SyntaxKind.WhileStatement: - Debug.type(node); - return factory.updateWhileStatement(node, - visitExpression(node.expression), - visitEmbeddedStatement(node.statement)); - - case SyntaxKind.ForStatement: - Debug.type(node); - return factory.updateForStatement(node, - visitForInitializer(node.initializer), - visitExpression(node.condition), - visitExpression(node.incrementor), - visitEmbeddedStatement(node.statement)); - - case SyntaxKind.ForInStatement: - Debug.type(node); - return factory.updateForInStatement(node, - visitForInitializer(node.initializer), - visitExpression(node.expression), - visitEmbeddedStatement(node.statement)); - - case SyntaxKind.ForOfStatement: - Debug.type(node); - return factory.updateForOfStatement(node, - visit(node.awaitModifier, isAwaitKeyword), - visitForInitializer(node.initializer), - visitExpression(node.expression), - visitEmbeddedStatement(node.statement)); - - case SyntaxKind.ContinueStatement: - Debug.type(node); - return factory.updateContinueStatement(node, - visitIdentifierName(node.label)); - - case SyntaxKind.BreakStatement: - Debug.type(node); - return factory.updateBreakStatement(node, - visitIdentifierName(node.label)); - - case SyntaxKind.ReturnStatement: - Debug.type(node); - return factory.updateReturnStatement(node, - visitExpression(node.expression)); - - case SyntaxKind.WithStatement: - Debug.type(node); - return factory.updateWithStatement(node, - visitExpression(node.expression), - visitEmbeddedStatement(node.statement)); - - case SyntaxKind.SwitchStatement: - Debug.type(node); - return factory.updateSwitchStatement(node, - visitExpression(node.expression), - visit(node.caseBlock, isCaseBlock)); - - case SyntaxKind.LabeledStatement: - Debug.type(node); - return factory.updateLabeledStatement(node, - visitIdentifierName(node.label), - visitEmbeddedStatement(node.statement)); - - case SyntaxKind.ThrowStatement: - Debug.type(node); - return factory.updateThrowStatement(node, - visitExpression(node.expression)); - - case SyntaxKind.TryStatement: - Debug.type(node); - return factory.updateTryStatement(node, - visit(node.tryBlock, isBlock), - visit(node.catchClause, isCatchClause), - visit(node.finallyBlock, isBlock)); - - // Declarations - case SyntaxKind.VariableDeclaration: - Debug.type(node); - return factory.updateVariableDeclaration(node, - visitBindingName(node.name), - visit(node.exclamationToken, isExclamationToken), - visitTypeNode(node.type), - visitExpression(node.initializer)); - - case SyntaxKind.VariableDeclarationList: - Debug.type(node); - return factory.updateVariableDeclarationList(node, - visitList(node.declarations, isVariableDeclaration)); - - case SyntaxKind.FunctionDeclaration: - Debug.type(node); - return factory.updateFunctionDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visit(node.asteriskToken, isAsteriskToken), - visitIdentifierName(node.name), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type), - visitFunctionBody(node.body)); - - case SyntaxKind.ClassDeclaration: - Debug.type(node); - return factory.updateClassDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitIdentifierName(node.name), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitList(node.heritageClauses, isHeritageClause), - visitList(node.members, isClassElement)); - - case SyntaxKind.InterfaceDeclaration: - Debug.type(node); - return factory.updateInterfaceDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitIdentifierName(node.name), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitList(node.heritageClauses, isHeritageClause), - visitList(node.members, isTypeElement)); - - case SyntaxKind.TypeAliasDeclaration: - Debug.type(node); - return factory.updateTypeAliasDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitIdentifierName(node.name), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitTypeNode(node.type)); - - case SyntaxKind.EnumDeclaration: - Debug.type(node); - return factory.updateEnumDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitIdentifierName(node.name), - visitList(node.members, isEnumMember)); - - case SyntaxKind.ModuleDeclaration: - Debug.type(node); - return factory.updateModuleDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitModuleName(node.name), - visit(node.body, isModuleBody)); - - case SyntaxKind.ModuleBlock: - Debug.type(node); - return factory.updateModuleBlock(node, - visitList(node.statements, isStatement)); - - case SyntaxKind.CaseBlock: - Debug.type(node); - return factory.updateCaseBlock(node, - visitList(node.clauses, isCaseOrDefaultClause)); - - case SyntaxKind.NamespaceExportDeclaration: - Debug.type(node); - return factory.updateNamespaceExportDeclaration(node, - visitIdentifierName(node.name)); - - case SyntaxKind.ImportEqualsDeclaration: - Debug.type(node); - return factory.updateImportEqualsDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - node.isTypeOnly, - visitIdentifierName(node.name), - visit(node.moduleReference, isModuleReference)); - - case SyntaxKind.ImportDeclaration: - Debug.type(node); - return factory.updateImportDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visit(node.importClause, isImportClause), - visitExpression(node.moduleSpecifier)); - - case SyntaxKind.ImportClause: - Debug.type(node); - return factory.updateImportClause(node, - node.isTypeOnly, - visitIdentifierName(node.name), - visit(node.namedBindings, isNamedImportBindings)); - - case SyntaxKind.NamespaceImport: - Debug.type(node); - return factory.updateNamespaceImport(node, - visitIdentifierName(node.name)); - - case SyntaxKind.NamespaceExport: - Debug.type(node); - return factory.updateNamespaceExport(node, - visitIdentifierName(node.name)); - - case SyntaxKind.NamedImports: - Debug.type(node); - return factory.updateNamedImports(node, - visitList(node.elements, isImportSpecifier)); - - case SyntaxKind.ImportSpecifier: - Debug.type(node); - return factory.updateImportSpecifier(node, - visitIdentifierName(node.propertyName), - visitIdentifierName(node.name)); - - case SyntaxKind.ExportAssignment: - Debug.type(node); - return factory.updateExportAssignment(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitExpression(node.expression)); - - case SyntaxKind.ExportDeclaration: - Debug.type(node); - return factory.updateExportDeclaration(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - node.isTypeOnly, - visit(node.exportClause, isNamedExportBindings), - visitExpression(node.moduleSpecifier)); - - case SyntaxKind.NamedExports: - Debug.type(node); - return factory.updateNamedExports(node, - visitList(node.elements, isExportSpecifier)); - - case SyntaxKind.ExportSpecifier: - Debug.type(node); - return factory.updateExportSpecifier(node, - visitIdentifierName(node.propertyName), - visitIdentifierName(node.name)); - - case SyntaxKind.MissingDeclaration: - return node; - - // Module references - case SyntaxKind.ExternalModuleReference: - Debug.type(node); - return factory.updateExternalModuleReference(node, - visitExpression(node.expression)); - - // JSX (non-expression) - case SyntaxKind.JsxOpeningElement: - Debug.type(node); - return factory.updateJsxOpeningElement(node, - visitExpression(node.tagName, isJsxTagNameExpression), - visitList(node.typeArguments, isTypeNode), - visit(node.attributes, isJsxAttributes)); - - case SyntaxKind.JsxClosingElement: - Debug.type(node); - return factory.updateJsxClosingElement(node, - visitExpression(node.tagName, isJsxTagNameExpression)); - - case SyntaxKind.JsxAttribute: - Debug.type(node); - return factory.updateJsxAttribute(node, - visitIdentifierName(node.name), - visitJsxAttributeValue(node.initializer)); - - case SyntaxKind.JsxAttributes: - Debug.type(node); - return factory.updateJsxAttributes(node, - visitList(node.properties, isJsxAttributeLike)); - - case SyntaxKind.JsxSpreadAttribute: - Debug.type(node); - return factory.updateJsxSpreadAttribute(node, - visitExpression(node.expression)); - - case SyntaxKind.JsxExpression: - Debug.type(node); - return factory.updateJsxExpression(node, - visitExpression(node.expression)); - - // Clauses - case SyntaxKind.CaseClause: - Debug.type(node); - return factory.updateCaseClause(node, - visitExpression(node.expression), - visitList(node.statements, isStatement)); - - case SyntaxKind.DefaultClause: - Debug.type(node); - return factory.updateDefaultClause(node, - visitList(node.statements, isStatement)); - - case SyntaxKind.HeritageClause: - Debug.type(node); - return factory.updateHeritageClause(node, - visitList(node.types, isExpressionWithTypeArguments)); - - case SyntaxKind.CatchClause: - Debug.type(node); - return factory.updateCatchClause(node, - visit(node.variableDeclaration, isVariableDeclaration), - visit(node.block, isBlock)); - - // Property assignments - case SyntaxKind.PropertyAssignment: - Debug.type(node); - return factory.updatePropertyAssignment(node, - visitPropertyName(node.name), - visitExpression(node.initializer)); - - case SyntaxKind.ShorthandPropertyAssignment: - Debug.type(node); - return factory.updateShorthandPropertyAssignment(node, - visitIdentifierName(node.name, isIdentifier), - visitExpression(node.objectAssignmentInitializer)); - - case SyntaxKind.SpreadAssignment: - Debug.type(node); - return factory.updateSpreadAssignment(node, - visitExpression(node.expression)); - - // Enum - case SyntaxKind.EnumMember: - Debug.type(node); - return factory.updateEnumMember(node, - visitPropertyName(node.name), - visitExpression(node.initializer)); - - // JSDoc nodes (only used in codefixes currently) - case SyntaxKind.JSDocTypeExpression: - case SyntaxKind.JSDocNameReference: - case SyntaxKind.JSDocAllType: - case SyntaxKind.JSDocUnknownType: - case SyntaxKind.JSDocNullableType: - case SyntaxKind.JSDocNonNullableType: - case SyntaxKind.JSDocOptionalType: - case SyntaxKind.JSDocFunctionType: - case SyntaxKind.JSDocVariadicType: - case SyntaxKind.JSDocNamepathType: - case SyntaxKind.JSDocComment: - case SyntaxKind.JSDocTypeLiteral: - case SyntaxKind.JSDocSignature: - case SyntaxKind.JSDocTag: - case SyntaxKind.JSDocAugmentsTag: - case SyntaxKind.JSDocImplementsTag: - case SyntaxKind.JSDocAuthorTag: - case SyntaxKind.JSDocDeprecatedTag: - case SyntaxKind.JSDocClassTag: - case SyntaxKind.JSDocPublicTag: - case SyntaxKind.JSDocPrivateTag: - case SyntaxKind.JSDocProtectedTag: - case SyntaxKind.JSDocReadonlyTag: - case SyntaxKind.JSDocCallbackTag: - case SyntaxKind.JSDocEnumTag: - case SyntaxKind.JSDocParameterTag: - case SyntaxKind.JSDocPropertyTag: - case SyntaxKind.JSDocReturnTag: - case SyntaxKind.JSDocThisTag: - case SyntaxKind.JSDocTypeTag: - case SyntaxKind.JSDocTemplateTag: - case SyntaxKind.JSDocTypedefTag: - case SyntaxKind.JSDocSeeTag: - return node; - - // Transformation nodes (ignored) - } - - if (isExpression(node)) { - // If this was an expression that was originally in an `Unspecified` hint, - // re-trigger substitution using the correct hint. - hint = EmitHint.Expression; - if (substituteNode !== noEmitSubstitution) { - node = substituteNode(hint, node); - } - } - else if (isSourceFile(node)) { - return preprintSourceFile(node); - } - } - - if (hint === EmitHint.Expression) { - switch (node.kind) { - // Identifiers - case SyntaxKind.Identifier: - return preprintIdentifier(node as Identifier); - - // Expression - case SyntaxKind.ArrayLiteralExpression: - Debug.type(node); - return factory.updateArrayLiteralExpression(node, - visitExpressionList(node.elements)); - - case SyntaxKind.ObjectLiteralExpression: - Debug.type(node); - return factory.updateObjectLiteralExpression(node, - visitList(node.properties, isObjectLiteralElementLike)); - - case SyntaxKind.PropertyAccessExpression: - if (node.flags & NodeFlags.OptionalChain) { - Debug.type(node); - return factory.updatePropertyAccessChain(node, - visitExpression(node.expression), - visit(node.questionDotToken, isQuestionDotToken), - visitMemberName(node.name)); - } - Debug.type(node); - return factory.updatePropertyAccessExpression(node, - visitExpression(node.expression), - visitMemberName(node.name)); - - case SyntaxKind.ElementAccessExpression: - if (node.flags & NodeFlags.OptionalChain) { - Debug.type(node); - return factory.updateElementAccessChain(node, - visitExpression(node.expression), - visit(node.questionDotToken, isQuestionDotToken), - visitExpression(node.argumentExpression)); - } - Debug.type(node); - return factory.updateElementAccessExpression(node, - visitExpression(node.expression), - visitExpression(node.argumentExpression)); - - case SyntaxKind.CallExpression: - if (node.flags & NodeFlags.OptionalChain) { - Debug.type(node); - return factory.updateCallChain(node, - visitExpression(node.expression), - visit(node.questionDotToken, isQuestionDotToken), - visitTypeNodeList(node.typeArguments), - visitExpressionList(node.arguments)); - } - Debug.type(node); - return factory.updateCallExpression(node, - visitExpression(node.expression), - visitTypeNodeList(node.typeArguments), - visitExpressionList(node.arguments)); - - case SyntaxKind.NewExpression: - Debug.type(node); - return factory.updateNewExpression(node, - visitExpression(node.expression), - visitTypeNodeList(node.typeArguments), - visitExpressionList(node.arguments)); - - case SyntaxKind.TaggedTemplateExpression: - Debug.type(node); - return factory.updateTaggedTemplateExpression(node, - visitExpression(node.tag), - visitTypeNodeList(node.typeArguments), - visitExpression(node.template, isTemplateLiteral)); - - case SyntaxKind.TypeAssertionExpression: - Debug.type(node); - return factory.updateTypeAssertion(node, - visitTypeNode(node.type), - visitExpression(node.expression)); - - case SyntaxKind.ParenthesizedExpression: - Debug.type(node); - return factory.updateParenthesizedExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.FunctionExpression: - Debug.type(node); - return factory.updateFunctionExpression(node, - visitList(node.modifiers, isModifier), - visit(node.asteriskToken, isAsteriskToken), - visitIdentifierName(node.name), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type), - visitFunctionBody(node.body)); - - case SyntaxKind.ArrowFunction: - Debug.type(node); - return factory.updateArrowFunction(node, - visitList(node.modifiers, isModifier), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitParameterList(node.parameters), - visitTypeNode(node.type), - visit(node.equalsGreaterThanToken, isEqualsGreaterThanToken), - visitConciseBody(node.body)); - - case SyntaxKind.DeleteExpression: - Debug.type(node); - return factory.updateDeleteExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.TypeOfExpression: - Debug.type(node); - return factory.updateTypeOfExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.VoidExpression: - Debug.type(node); - return factory.updateVoidExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.AwaitExpression: - Debug.type(node); - return factory.updateAwaitExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.PrefixUnaryExpression: - Debug.type(node); - return factory.updatePrefixUnaryExpression(node, - visitExpression(node.operand)); - - case SyntaxKind.PostfixUnaryExpression: - Debug.type(node); - return factory.updatePostfixUnaryExpression(node, - visitExpression(node.operand)); - - case SyntaxKind.BinaryExpression: - return preprintBinaryExpression(node as BinaryExpression); - - case SyntaxKind.ConditionalExpression: - Debug.type(node); - return factory.updateConditionalExpression(node, - visitExpression(node.condition), - visit(node.questionToken, isQuestionToken), - visitExpression(node.whenTrue), - visit(node.colonToken, isColonToken), - visitExpression(node.whenFalse)); - - case SyntaxKind.TemplateExpression: - Debug.type(node); - return factory.updateTemplateExpression(node, - visit(node.head, isTemplateHead), - visitList(node.templateSpans, isTemplateSpan)); - - case SyntaxKind.YieldExpression: - Debug.type(node); - return factory.updateYieldExpression(node, - visit(node.asteriskToken, isAsteriskToken), - visitExpression(node.expression)); - - case SyntaxKind.SpreadElement: - Debug.type(node); - return factory.updateSpreadElement(node, - visitExpression(node.expression)); - - case SyntaxKind.ClassExpression: - Debug.type(node); - return factory.updateClassExpression(node, - visitList(node.decorators, isDecorator), - visitList(node.modifiers, isModifier), - visitIdentifierName(node.name), - visitList(node.typeParameters, isTypeParameterDeclaration), - visitList(node.heritageClauses, isHeritageClause), - visitList(node.members, isClassElement)); - - case SyntaxKind.AsExpression: - Debug.type(node); - return factory.updateAsExpression(node, - visitExpression(node.expression), - visitTypeNode(node.type)); - - case SyntaxKind.NonNullExpression: - if (node.flags & NodeFlags.OptionalChain) { - Debug.type(node); - return factory.updateNonNullChain(node, - visitExpression(node.expression)); - } - Debug.type(node); - return factory.updateNonNullExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.MetaProperty: - Debug.type(node); - return factory.updateMetaProperty(node, - visitIdentifierName(node.name)); - - - // JSX (expression only) - case SyntaxKind.JsxElement: - Debug.type(node); - return factory.updateJsxElement(node, - visit(node.openingElement, isJsxOpeningElement), - visitList(node.children, isJsxChild), - visit(node.closingElement, isJsxClosingElement)); - - case SyntaxKind.JsxSelfClosingElement: - Debug.type(node); - return factory.updateJsxSelfClosingElement(node, - visitExpression(node.tagName, isJsxTagNameExpression), - visitList(node.typeArguments, isTypeNode), - visit(node.attributes, isJsxAttributes)); - - case SyntaxKind.JsxFragment: - Debug.type(node); - return factory.updateJsxFragment(node, - visit(node.openingFragment, isJsxOpeningFragment), - visitList(node.children, isJsxChild), - visit(node.closingFragment, isJsxClosingFragment)); - - // Transformation nodes - case SyntaxKind.PartiallyEmittedExpression: - Debug.type(node); - return factory.updatePartiallyEmittedExpression(node, - visitExpression(node.expression)); - - case SyntaxKind.CommaListExpression: - Debug.type(node); - return factory.updateCommaListExpression(node, - visitExpressionList(node.elements, isExpression)); - } - } - - if (Debug.shouldAssert(AssertionLevel.Normal)) { - // Any other node should not have children or this list isn't up to date. - Debug.assertMissingNode(forEachChild(node, identity), `Expected ${Debug.formatSyntaxKind(node.kind)} to contain no children.`); - } - - // No need to visit nodes with no children. - return node; - } - - function preprintSourceFile(node: SourceFile) { - return factory.updateSourceFile(node, - visitList(node.statements, isStatement)); - } - - function preprintIdentifier(node: Identifier) { - return factory.updateIdentifier(node, - visitList(node.typeArguments, isTypeNodeOrTypeParameterDeclaration)); - } - - function preprintTypeParameterDeclaration(node: TypeParameterDeclaration) { - return factory.updateTypeParameterDeclaration(node, - visitIdentifierName(node.name), - visitTypeNode(node.constraint), - visitTypeNode(node.default)); - } - - function createPreprintBinaryExpression() { - interface WorkArea { - stackIndex: number; - leftStack: Expression[]; - operatorStack: BinaryOperatorToken[]; - rightStack: Expression[]; - } - - return createBinaryExpressionTrampoline(onEnter, onLeft, onOperator, onRight, onExit, foldState); - - function onEnter(node: BinaryExpression, state: WorkArea | undefined) { - if (state) { - state.stackIndex++; - state.leftStack[state.stackIndex] = node.left; - state.operatorStack[state.stackIndex] = node.operatorToken; - state.rightStack[state.stackIndex] = node.right; - } - else { - state = { - stackIndex: 0, - leftStack: [node.left], - operatorStack: [node.operatorToken], - rightStack: [node.right], - }; - } - return state; - } - - function onLeft(left: Expression, state: WorkArea, _node: BinaryExpression) { - return maybeVisitExpression(left, state, "left"); - } - - function onOperator(operator: BinaryOperatorToken, state: WorkArea, _node: BinaryExpression) { - state.operatorStack[state.stackIndex] = visit(operator, isBinaryOperatorToken); - } - - function onRight(right: Expression, state: WorkArea, _node: BinaryExpression) { - return maybeVisitExpression(right, state, "right"); - } - - function onExit(node: BinaryExpression, state: WorkArea) { - const left = state.leftStack[state.stackIndex]; - const operator = state.operatorStack[state.stackIndex]; - const right = state.rightStack[state.stackIndex]; - if (state.stackIndex > 0) { - state.stackIndex--; - } - return factory.updateBinaryExpression(node, left, operator, right); - } - - function foldState(state: WorkArea, result: BinaryExpression, side: "left" | "right") { - (side === "left" ? state.leftStack : state.rightStack)[state.stackIndex] = result; - return state; - } - - function maybeVisitExpression(node: Expression, state: WorkArea, side: "left" | "right") { - // Get the first supported pipeline phase for this node. We can skip several stack - // frames if we aren't doing emit notification, so we check for substitution and - // direct callbacks and execute those immediately. - let pipelinePhase = getPipelinePhase(PreprintPipelinePhase.Notification, node); - if (pipelinePhase === pipelineVisitWithSubstitution) { - // The next phase after substitution is always direct visitation, so we can reduce the call stack - // depth by proceding to the direct visitor. - node = cast(substituteNode(EmitHint.Expression, node), isExpression); - pipelinePhase = pipelineVisitDirect; - } - if (pipelinePhase === pipelineVisitDirect && isBinaryExpression(node)) { - // If we are visiting directly and the next node is a BinaryExpression, we can - // add it to the stack and continue the trampoline. - return node; - } - else { - // Visit the expression and store the result on whichever side we are currently visiting. - (side === "left" ? state.leftStack : state.rightStack)[state.stackIndex] = visitExpression(node, isExpression); - } - } - } - - const preprintBinaryExpression = createPreprintBinaryExpression(); - - function preprint(hint: EmitHint, node: Node) { - // If we're not performing substitution or notification, we have no work to do here. - if (substituteNode === noEmitSubstitution && - onEmitNode === noEmitNotification) { - return node; - } - switch (hint) { - case EmitHint.SourceFile: return visitSourceFile(cast(node, isSourceFile)); - case EmitHint.Expression: return visitExpression(cast(node, isExpression)); - case EmitHint.IdentifierName: return visitIdentifierName(cast(node, isIdentifier)); - case EmitHint.MappedTypeParameter: return visitMappedTypeParameter(cast(node, isTypeParameterDeclaration)); - case EmitHint.EmbeddedStatement: return visitEmbeddedStatement(cast(node, isStatement)); - case EmitHint.JsxAttributeValue: return visitJsxAttributeValue(cast(node, isStringLiteralOrJsxExpression)); - default: return visit(node); - } - } - - return preprint; - } - -======= ->>>>>>> master function createBracketsMap() { const brackets: string[][] = []; brackets[ListFormat.Braces] = ["{", "}"]; From 54bd285e03642fca5f97ac838602e5bcd7dd6cfd Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 23 Apr 2021 15:37:41 +0800 Subject: [PATCH 12/36] Fix computed prop name within context --- src/compiler/parser.ts | 16 ++++------------ .../reference/classStaticBlock22.errors.txt | 5 ++++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7b2c27038681c..294a7cb774a35 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6819,20 +6819,13 @@ namespace ts { function parseClassDeclarationOrExpression(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: ClassLikeDeclaration["kind"]): ClassLikeDeclaration { const savedAwaitContext = inAwaitContext(); - const savedClassStaticBlockContext = inClassStaticBlockContext(); parseExpected(SyntaxKind.ClassKeyword); - if (kind === SyntaxKind.ClassExpression) { - // all class expression is not inside function boundary - setClassStaticBlockContext(false); - } // We don't parse the name here in await context, instead we will report a grammar error in the checker. - const name = parseNameOfClassDeclarationOrExpression(); - - if (kind === SyntaxKind.ClassDeclaration) { - // class declaration's name is inside function boundary - setClassStaticBlockContext(false); - } + const name = doOutsideOfContext( + kind === SyntaxKind.ClassExpression ? NodeFlags.ClassStaticBlockContext : NodeFlags.None, + parseNameOfClassDeclarationOrExpression + ); const typeParameters = parseTypeParameters(); if (some(modifiers, isExportModifier)) setAwaitContext(/*value*/ true); @@ -6849,7 +6842,6 @@ namespace ts { members = createMissingList(); } setAwaitContext(savedAwaitContext); - setClassStaticBlockContext(savedClassStaticBlockContext); const node = kind === SyntaxKind.ClassDeclaration ? factory.createClassDeclaration(decorators, modifiers, name, typeParameters, heritageClauses, members) : factory.createClassExpression(decorators, modifiers, name, typeParameters, heritageClauses, members); diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt index f1c0c0138e5d3..9ad8b3b0b3ba9 100644 --- a/tests/baselines/reference/classStaticBlock22.errors.txt +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -9,11 +9,12 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(22,14): e tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(25,11): error TS18037: Identifier 'await' cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(28,8): error TS18037: Identifier 'await' cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,10): error TS18037: Identifier 'await' cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Identifier 'await' cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Identifier 'await' cannot be used inside class static block. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (12 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (13 errors) ==== let await: "any"; class C { static { @@ -72,6 +73,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): e await = 1; // legal x = await; // legal (initializers have an implicit function boundary) [await] = 1; // illegal (computed property names are evaluated outside of a class body + ~~~~~ +!!! error TS18037: Identifier 'await' cannot be used inside class static block. }; } static { From efa72d95fe319be5861e00e060a2994fa0040b53 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 23 Apr 2021 15:58:01 +0800 Subject: [PATCH 13/36] Add more tests --- src/compiler/parser.ts | 22 +++-- .../reference/classStaticBlock22.errors.txt | 34 +++++++ .../baselines/reference/classStaticBlock22.js | 68 ++++++++++++++ .../reference/classStaticBlock22.symbols | 80 +++++++++++++++++ .../reference/classStaticBlock22.types | 88 +++++++++++++++++++ .../classStaticBlock/classStaticBlock22.ts | 34 +++++++ 6 files changed, 314 insertions(+), 12 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 294a7cb774a35..63edd0ae06075 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3095,9 +3095,11 @@ namespace ts { // BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt const savedYieldContext = inYieldContext(); const savedAwaitContext = inAwaitContext(); + const savedClassStaticBlockContext = inClassStaticBlockContext(); setYieldContext(!!(flags & SignatureFlags.Yield)); setAwaitContext(!!(flags & SignatureFlags.Await)); + setClassStaticBlockContext(false); const parameters = flags & SignatureFlags.JSDoc ? parseDelimitedList(ParsingContext.JSDocParameters, parseJSDocParameter) : @@ -3105,6 +3107,7 @@ namespace ts { setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); + setClassStaticBlockContext(savedClassStaticBlockContext); return parameters; } @@ -5565,8 +5568,6 @@ namespace ts { if (savedDecoratorContext) { setDecoratorContext(/*val*/ false); } - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(false); const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -5575,11 +5576,11 @@ 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 = + const name = doOutsideOfClassStaticBlockContext(() => isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : isGenerator ? doInYieldContext(parseOptionalBindingIdentifier) : isAsync ? doInAwaitContext(parseOptionalBindingIdentifier) : - parseOptionalBindingIdentifier(); + parseOptionalBindingIdentifier()); const typeParameters = parseTypeParameters(); const parameters = parseParameters(isGenerator | isAsync); @@ -5589,7 +5590,6 @@ namespace ts { if (savedDecoratorContext) { setDecoratorContext(/*val*/ true); } - setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -5662,6 +5662,9 @@ namespace ts { const savedAwaitContext = inAwaitContext(); setAwaitContext(!!(flags & SignatureFlags.Await)); + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(false); + const savedTopLevel = topLevel; topLevel = false; @@ -5681,6 +5684,7 @@ namespace ts { topLevel = savedTopLevel; setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); + setClassStaticBlockContext(savedClassStaticBlockContext); return block; } @@ -6443,7 +6447,6 @@ namespace ts { function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): FunctionDeclaration { const savedAwaitContext = inAwaitContext(); - const savedClassStaticBlockContext = inClassStaticBlockContext(); const modifierFlags = modifiersToFlags(modifiers); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -6453,12 +6456,10 @@ namespace ts { const isAsync = modifierFlags & ModifierFlags.Async ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); if (modifierFlags & ModifierFlags.Export) setAwaitContext(/*value*/ true); - setClassStaticBlockContext(false); const parameters = parseParameters(isGenerator | isAsync); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlockOrSemicolon(isGenerator | isAsync, Diagnostics.or_expected); setAwaitContext(savedAwaitContext); - setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionDeclaration(decorators, modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6556,19 +6557,17 @@ namespace ts { // report an error in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { - return doOutsideOfClassStaticBlockContext(() => parseMethodDeclaration(pos, hasJSDoc, decorators, modifiers, asteriskToken, name, questionToken, /*exclamationToken*/ undefined, Diagnostics.or_expected)); + return parseMethodDeclaration(pos, hasJSDoc, decorators, modifiers, asteriskToken, name, questionToken, /*exclamationToken*/ undefined, Diagnostics.or_expected); } return doOutsideOfClassStaticBlockContext(() => parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken)); } function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration { - const savedClassStaticBlockContext = inClassStaticBlockContext(); const name = parsePropertyName(); if (!isComputedPropertyName(name)) { // property name is not care about ClassStaticBlockContext if not computed property name. (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; } - setClassStaticBlockContext(false); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6579,7 +6578,6 @@ namespace ts { // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors node.typeParameters = typeParameters; if (type && node.kind === SyntaxKind.SetAccessor) (node as Mutable).type = type; - setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt index 9ad8b3b0b3ba9..d9f4c6f685797 100644 --- a/tests/baselines/reference/classStaticBlock22.errors.txt +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -97,4 +97,38 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): e ~~~~~ !!! error TS18037: Identifier 'await' cannot be used inside class static block. } + 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; } + } + } + static { + function f (await) {} + const ff = (await) => {} + const fff = await => {} + } } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock22.js b/tests/baselines/reference/classStaticBlock22.js index 290c21a5e7e64..4fe3aed0a8e54 100644 --- a/tests/baselines/reference/classStaticBlock22.js +++ b/tests/baselines/reference/classStaticBlock22.js @@ -54,6 +54,40 @@ class C { await: // illegal, 'await' cannot be used as a label break await; // illegal, 'await' cannot be used as a label } + 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; } + } + } + static { + function f (await) {} + const ff = (await) => {} + const fff = await => {} + } } //// [classStaticBlock22.js] @@ -117,4 +151,38 @@ class C { await: // illegal, 'await' cannot be used as a label break await; // illegal, 'await' cannot be used as a label } + 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; }; + } + } + static { + function f(await) { } + const ff = (await) => { }; + const fff = await => { }; + } } diff --git a/tests/baselines/reference/classStaticBlock22.symbols b/tests/baselines/reference/classStaticBlock22.symbols index 967d2e75b7283..64eaccba8ab2e 100644 --- a/tests/baselines/reference/classStaticBlock22.symbols +++ b/tests/baselines/reference/classStaticBlock22.symbols @@ -83,4 +83,84 @@ class C { await: // illegal, 'await' cannot be used as a label break await; // illegal, 'await' cannot be used as a label } + static { + class E { +>E : Symbol(E, Decl(classStaticBlock22.ts, 55, 10)) + + constructor () { await; } +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + method () { await; } +>method : Symbol(E.method, Decl(classStaticBlock22.ts, 57, 31)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + get accessor () { +>accessor : Symbol(E.accessor, Decl(classStaticBlock22.ts, 58, 26), Decl(classStaticBlock22.ts, 62, 7)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + return 1; + } + set accessor (v: any) { +>accessor : Symbol(E.accessor, Decl(classStaticBlock22.ts, 58, 26), Decl(classStaticBlock22.ts, 62, 7)) +>v : Symbol(v, Decl(classStaticBlock22.ts, 63, 20)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + propLambda = () => { await; } +>propLambda : Symbol(E.propLambda, Decl(classStaticBlock22.ts, 65, 7)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + propFunc = function () { await; } +>propFunc : Symbol(E.propFunc, Decl(classStaticBlock22.ts, 66, 35)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + } + static { + class S { +>S : Symbol(S, Decl(classStaticBlock22.ts, 70, 10)) + + static method () { await; } +>method : Symbol(S.method, Decl(classStaticBlock22.ts, 71, 13)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + static get accessor () { +>accessor : Symbol(S.accessor, Decl(classStaticBlock22.ts, 72, 33), Decl(classStaticBlock22.ts, 76, 7)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + return 1; + } + static set accessor (v: any) { +>accessor : Symbol(S.accessor, Decl(classStaticBlock22.ts, 72, 33), Decl(classStaticBlock22.ts, 76, 7)) +>v : Symbol(v, Decl(classStaticBlock22.ts, 77, 27)) + + await; +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + static propLambda = () => { await; } +>propLambda : Symbol(S.propLambda, Decl(classStaticBlock22.ts, 79, 7)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + + static propFunc = function () { await; } +>propFunc : Symbol(S.propFunc, Decl(classStaticBlock22.ts, 80, 42)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) + } + } + static { + function f (await) {} +>f : Symbol(f, Decl(classStaticBlock22.ts, 84, 10)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 85, 16)) + + const ff = (await) => {} +>ff : Symbol(ff, Decl(classStaticBlock22.ts, 86, 9)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 86, 16)) + + const fff = await => {} +>fff : Symbol(fff, Decl(classStaticBlock22.ts, 87, 9)) +>await : Symbol(await, Decl(classStaticBlock22.ts, 87, 15)) + } } diff --git a/tests/baselines/reference/classStaticBlock22.types b/tests/baselines/reference/classStaticBlock22.types index ce6f17adbb39f..da7813a38a2f0 100644 --- a/tests/baselines/reference/classStaticBlock22.types +++ b/tests/baselines/reference/classStaticBlock22.types @@ -106,6 +106,94 @@ class C { >await : any break await; // illegal, 'await' cannot be used as a label +>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" + } + } + static { + function f (await) {} +>f : (await: any) => void +>await : any + + const ff = (await) => {} +>ff : (await: any) => void +>(await) => {} : (await: any) => void +>await : any + + const fff = await => {} +>fff : (await: any) => void +>await => {} : (await: any) => void >await : any } } diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts index 642836ad81863..e1d605290a37e 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts @@ -55,4 +55,38 @@ class C { await: // illegal, 'await' cannot be used as a label break await; // illegal, 'await' cannot be used as a label } + 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; } + } + } + static { + function f (await) {} + const ff = (await) => {} + const fff = await => {} + } } \ No newline at end of file From 561b9d6a35bc0db0fa1e28b046761751c00ba134 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 23 Apr 2021 15:58:53 +0800 Subject: [PATCH 14/36] Update baseline --- tests/baselines/reference/api/tsserverlibrary.d.ts | 5 +++-- tests/baselines/reference/api/typescript.d.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index f802af58b8763..839ea282e4bdf 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -517,11 +517,12 @@ declare namespace ts { HasAggregatedChildData = 524288, JSDoc = 4194304, JsonFile = 33554432, + ClassStaticBlockContext = 268435456, BlockScoped = 3, ReachabilityCheckFlags = 768, ReachabilityAndEmitFlags = 2816, - ContextFlags = 25358336, - TypeExcludesFlags = 40960, + ContextFlags = 293793792, + TypeExcludesFlags = 268476416, } export enum ModifierFlags { None = 0, diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index ecf6fabb9efdd..a3d1f23e09b22 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -517,11 +517,12 @@ declare namespace ts { HasAggregatedChildData = 524288, JSDoc = 4194304, JsonFile = 33554432, + ClassStaticBlockContext = 268435456, BlockScoped = 3, ReachabilityCheckFlags = 768, ReachabilityAndEmitFlags = 2816, - ContextFlags = 25358336, - TypeExcludesFlags = 40960, + ContextFlags = 293793792, + TypeExcludesFlags = 268476416, } export enum ModifierFlags { None = 0, From 8e3543f7dd21d659b870cb9236af914d4dd826b8 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 27 Apr 2021 14:52:30 +0800 Subject: [PATCH 15/36] Avoid invalid test baseline --- .../baselines/reference/classStaticBlock10.js | 48 ------------- .../reference/classStaticBlock10.symbols | 58 --------------- .../reference/classStaticBlock10.types | 72 ------------------- .../baselines/reference/classStaticBlock2.js | 29 -------- .../reference/classStaticBlock2.symbols | 33 --------- .../reference/classStaticBlock2.types | 37 ---------- .../baselines/reference/classStaticBlock3.js | 30 -------- .../reference/classStaticBlock3.symbols | 49 ------------- .../reference/classStaticBlock3.types | 55 -------------- .../reference/classStaticBlock4.errors.txt | 27 ------- .../baselines/reference/classStaticBlock4.js | 26 ------- .../reference/classStaticBlock4.symbols | 35 --------- .../reference/classStaticBlock4.types | 41 ----------- .../reference/classStaticBlock5.errors.txt | 31 -------- .../baselines/reference/classStaticBlock5.js | 50 ------------- .../reference/classStaticBlock5.symbols | 30 -------- .../reference/classStaticBlock5.types | 45 ------------ .../reference/classStaticBlock9.errors.txt | 15 ---- .../baselines/reference/classStaticBlock9.js | 18 ----- .../reference/classStaticBlock9.symbols | 20 ------ .../reference/classStaticBlock9.types | 25 ------- 21 files changed, 774 deletions(-) delete mode 100644 tests/baselines/reference/classStaticBlock10.js delete mode 100644 tests/baselines/reference/classStaticBlock10.symbols delete mode 100644 tests/baselines/reference/classStaticBlock10.types delete mode 100644 tests/baselines/reference/classStaticBlock2.js delete mode 100644 tests/baselines/reference/classStaticBlock2.symbols delete mode 100644 tests/baselines/reference/classStaticBlock2.types delete mode 100644 tests/baselines/reference/classStaticBlock3.js delete mode 100644 tests/baselines/reference/classStaticBlock3.symbols delete mode 100644 tests/baselines/reference/classStaticBlock3.types delete mode 100644 tests/baselines/reference/classStaticBlock4.errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock4.js delete mode 100644 tests/baselines/reference/classStaticBlock4.symbols delete mode 100644 tests/baselines/reference/classStaticBlock4.types delete mode 100644 tests/baselines/reference/classStaticBlock5.errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock5.js delete mode 100644 tests/baselines/reference/classStaticBlock5.symbols delete mode 100644 tests/baselines/reference/classStaticBlock5.types delete mode 100644 tests/baselines/reference/classStaticBlock9.errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock9.js delete mode 100644 tests/baselines/reference/classStaticBlock9.symbols delete mode 100644 tests/baselines/reference/classStaticBlock9.types diff --git a/tests/baselines/reference/classStaticBlock10.js b/tests/baselines/reference/classStaticBlock10.js deleted file mode 100644 index faa79b8dae154..0000000000000 --- a/tests/baselines/reference/classStaticBlock10.js +++ /dev/null @@ -1,48 +0,0 @@ -//// [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; - }()); -} -var C2 = /** @class */ (function () { - function C2() { - } - return C2; -}()); diff --git a/tests/baselines/reference/classStaticBlock10.symbols b/tests/baselines/reference/classStaticBlock10.symbols deleted file mode 100644 index 12d2d16b0784c..0000000000000 --- a/tests/baselines/reference/classStaticBlock10.symbols +++ /dev/null @@ -1,58 +0,0 @@ -=== 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.types b/tests/baselines/reference/classStaticBlock10.types deleted file mode 100644 index dbbf3ebd6b0a4..0000000000000 --- a/tests/baselines/reference/classStaticBlock10.types +++ /dev/null @@ -1,72 +0,0 @@ -=== 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/classStaticBlock2.js b/tests/baselines/reference/classStaticBlock2.js deleted file mode 100644 index e535663fcdeaa..0000000000000 --- a/tests/baselines/reference/classStaticBlock2.js +++ /dev/null @@ -1,29 +0,0 @@ -//// [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; -}()); diff --git a/tests/baselines/reference/classStaticBlock2.symbols b/tests/baselines/reference/classStaticBlock2.symbols deleted file mode 100644 index 93bfa964aaeb6..0000000000000 --- a/tests/baselines/reference/classStaticBlock2.symbols +++ /dev/null @@ -1,33 +0,0 @@ -=== 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.types b/tests/baselines/reference/classStaticBlock2.types deleted file mode 100644 index 2e22833b22ddf..0000000000000 --- a/tests/baselines/reference/classStaticBlock2.types +++ /dev/null @@ -1,37 +0,0 @@ -=== 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/classStaticBlock3.js b/tests/baselines/reference/classStaticBlock3.js deleted file mode 100644 index 5dfb77ff34ba9..0000000000000 --- a/tests/baselines/reference/classStaticBlock3.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [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] -var a = 1; -var C = /** @class */ (function () { - function C() { - } - C.f1 = 1; - C.f2 = 2; - C.f3 = 3; - return C; -}()); diff --git a/tests/baselines/reference/classStaticBlock3.symbols b/tests/baselines/reference/classStaticBlock3.symbols deleted file mode 100644 index 758fa0790609a..0000000000000 --- a/tests/baselines/reference/classStaticBlock3.symbols +++ /dev/null @@ -1,49 +0,0 @@ -=== 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 deleted file mode 100644 index d5705a72e8775..0000000000000 --- a/tests/baselines/reference/classStaticBlock3.types +++ /dev/null @@ -1,55 +0,0 @@ -=== 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 deleted file mode 100644 index 87e988d8b1c6e..0000000000000 --- a/tests/baselines/reference/classStaticBlock4.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== - class C { - static s1 = 1; - - static { - this.s1; - ~~ -!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? - C.s1; - - this.s2; - ~~ -!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? - C.s2; - } - - static s2 = 2; - static ss2 = this.s1; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4.js b/tests/baselines/reference/classStaticBlock4.js deleted file mode 100644 index adba8791e76e7..0000000000000 --- a/tests/baselines/reference/classStaticBlock4.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [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] -var C = /** @class */ (function () { - function C() { - } - C.s1 = 1; - C.s2 = 2; - C.ss2 = this.s1; - return C; -}()); diff --git a/tests/baselines/reference/classStaticBlock4.symbols b/tests/baselines/reference/classStaticBlock4.symbols deleted file mode 100644 index 5b812c63d7121..0000000000000 --- a/tests/baselines/reference/classStaticBlock4.symbols +++ /dev/null @@ -1,35 +0,0 @@ -=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) - - 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) - - 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 deleted file mode 100644 index 91d7ba0613136..0000000000000 --- a/tests/baselines/reference/classStaticBlock4.types +++ /dev/null @@ -1,41 +0,0 @@ -=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts === -class C { ->C : C - - static s1 = 1; ->s1 : number ->1 : 1 - - static { - this.s1; ->this.s1 : any ->this : this ->s1 : any - - C.s1; ->C.s1 : number ->C : typeof C ->s1 : number - - this.s2; ->this.s2 : any ->this : this ->s2 : any - - 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.errors.txt b/tests/baselines/reference/classStaticBlock5.errors.txt deleted file mode 100644 index eeabc4440f902..0000000000000 --- a/tests/baselines/reference/classStaticBlock5.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(8,16): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(11,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? -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 TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? - 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.js b/tests/baselines/reference/classStaticBlock5.js deleted file mode 100644 index 5f5d79c670049..0000000000000 --- a/tests/baselines/reference/classStaticBlock5.js +++ /dev/null @@ -1,50 +0,0 @@ -//// [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 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; - return C; -}(B)); diff --git a/tests/baselines/reference/classStaticBlock5.symbols b/tests/baselines/reference/classStaticBlock5.symbols deleted file mode 100644 index 2e0175423fafb..0000000000000 --- a/tests/baselines/reference/classStaticBlock5.symbols +++ /dev/null @@ -1,30 +0,0 @@ -=== 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 : Symbol(C, Decl(classStaticBlock5.ts, 3, 1)) - - super.b; - super.a; - } -} - diff --git a/tests/baselines/reference/classStaticBlock5.types b/tests/baselines/reference/classStaticBlock5.types deleted file mode 100644 index 9e0dfa94d3fee..0000000000000 --- a/tests/baselines/reference/classStaticBlock5.types +++ /dev/null @@ -1,45 +0,0 @@ -=== 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 : any ->this : this ->b : any - - super.b; ->super.b : any ->super : any ->b : any - - super.a; ->super.a : any ->super : any ->a : any - } -} - diff --git a/tests/baselines/reference/classStaticBlock9.errors.txt b/tests/baselines/reference/classStaticBlock9.errors.txt deleted file mode 100644 index 32788846e768a..0000000000000 --- a/tests/baselines/reference/classStaticBlock9.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -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 (1 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; - } - static foo = 1; - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock9.js b/tests/baselines/reference/classStaticBlock9.js deleted file mode 100644 index 1eb6145d9b62f..0000000000000 --- a/tests/baselines/reference/classStaticBlock9.js +++ /dev/null @@ -1,18 +0,0 @@ -//// [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; - A.foo = 1; - return A; -}()); diff --git a/tests/baselines/reference/classStaticBlock9.symbols b/tests/baselines/reference/classStaticBlock9.symbols deleted file mode 100644 index 2cb44695c8328..0000000000000 --- a/tests/baselines/reference/classStaticBlock9.symbols +++ /dev/null @@ -1,20 +0,0 @@ -=== 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.types b/tests/baselines/reference/classStaticBlock9.types deleted file mode 100644 index 9ac192ac54bed..0000000000000 --- a/tests/baselines/reference/classStaticBlock9.types +++ /dev/null @@ -1,25 +0,0 @@ -=== 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 -} - From c4f71e24731575df7701238ce15260e95eb0cdfb Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 27 Apr 2021 15:26:42 +0800 Subject: [PATCH 16/36] Support use before initialize check --- src/compiler/checker.ts | 6 ++-- ...lassStaticBlock3(target=es2015).errors.txt | 33 +++++++++++++++++++ .../classStaticBlock3(target=es5).errors.txt | 33 +++++++++++++++++++ ...lassStaticBlock3(target=esnext).errors.txt | 33 +++++++++++++++++++ ...lassStaticBlock4(target=es2015).errors.txt | 6 +++- .../classStaticBlock4(target=es5).errors.txt | 6 +++- ...lassStaticBlock4(target=esnext).errors.txt | 6 +++- ...lassStaticBlock9(target=es2015).errors.txt | 6 +++- .../classStaticBlock9(target=es5).errors.txt | 6 +++- ...lassStaticBlock9(target=esnext).errors.txt | 6 +++- 10 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock3(target=es2015).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).errors.txt create mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1c11a2f38d702..a087777fe4580 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27331,7 +27331,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) @@ -27352,7 +27352,7 @@ namespace ts { } } - function isInPropertyInitializer(node: Node): boolean { + function isInPropertyInitializerOrClassStaticBlock(node: Node): boolean { return !!findAncestor(node, node => { switch (node.kind) { case SyntaxKind.PropertyDeclaration: @@ -27372,6 +27372,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"; } diff --git a/tests/baselines/reference/classStaticBlock3(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock3(target=es2015).errors.txt new file mode 100644 index 0000000000000..bf01354e1405f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es2015).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(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock3(target=es5).errors.txt new file mode 100644 index 0000000000000..bf01354e1405f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=es5).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(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock3(target=esnext).errors.txt new file mode 100644 index 0000000000000..bf01354e1405f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock3(target=esnext).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/classStaticBlock4(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt index 87e988d8b1c6e..b85180f1df07d 100644 --- a/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt +++ b/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt @@ -1,9 +1,10 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +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(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (4 errors) ==== class C { static s1 = 1; @@ -17,6 +18,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): er ~~ !!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? 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; diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt index 87e988d8b1c6e..b85180f1df07d 100644 --- a/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt +++ b/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt @@ -1,9 +1,10 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +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(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (4 errors) ==== class C { static s1 = 1; @@ -17,6 +18,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(13,18): er ~~ !!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? 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; diff --git a/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt index 1768750e34f12..fa0c4d51af6d9 100644 --- a/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt +++ b/tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt @@ -1,8 +1,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +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 (2 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (3 errors) ==== class C { static s1 = 1; @@ -16,6 +17,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): err ~~ !!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? 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; diff --git a/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt index 32788846e768a..4e8572da31914 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).errors.txt @@ -1,7 +1,8 @@ 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 (1 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts (2 errors) ==== class A { static bar = A.foo + 1 ~~~ @@ -9,6 +10,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(2,20): err !!! 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; } diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt index 32788846e768a..4e8572da31914 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt +++ b/tests/baselines/reference/classStaticBlock9(target=es5).errors.txt @@ -1,7 +1,8 @@ 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 (1 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts (2 errors) ==== class A { static bar = A.foo + 1 ~~~ @@ -9,6 +10,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(2,20): err !!! 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; } diff --git a/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt index 32788846e768a..4e8572da31914 100644 --- a/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt +++ b/tests/baselines/reference/classStaticBlock9(target=esnext).errors.txt @@ -1,7 +1,8 @@ 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 (1 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts (2 errors) ==== class A { static bar = A.foo + 1 ~~~ @@ -9,6 +10,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock9.ts(2,20): err !!! 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; } From e8cd4f87888f2e84bd60b6b5b6eeb04c545c7303 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 6 Jun 2021 22:30:45 +0800 Subject: [PATCH 17/36] wip --- src/compiler/checker.ts | 26 +---- src/compiler/diagnosticMessages.json | 2 +- src/compiler/parser.ts | 72 +++--------- .../reference/classStaticBlock22.errors.txt | 110 ++++++++++++------ .../baselines/reference/classStaticBlock22.js | 28 +++-- .../reference/classStaticBlock22.symbols | 8 -- .../reference/classStaticBlock22.types | 41 ++++--- .../reference/classStaticBlock6.errors.txt | 19 +-- .../baselines/reference/classStaticBlock6.js | 5 +- .../reference/classStaticBlock6.symbols | 2 - .../reference/classStaticBlock6.types | 4 +- .../reference/classStaticBlock7.errors.txt | 6 +- 12 files changed, 159 insertions(+), 164 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e83840f983343..468314f4aa923 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24178,17 +24178,7 @@ namespace ts { } } - function checkGrammarIdentifierInClassStaticBlockContext(node: Identifier) { - if (node.flags & NodeFlags.ClassStaticBlockContext && ( - node.originalKeywordKind === SyntaxKind.AwaitKeyword || node.escapedText === "await" - )) { - grammarErrorOnNode(node, Diagnostics.Identifier_await_cannot_be_used_inside_class_static_block); - } - } - function checkIdentifier(node: Identifier, checkMode: CheckMode | undefined): Type { - checkGrammarIdentifierInClassStaticBlockContext(node); - const symbol = getResolvedSymbol(node); if (symbol === unknownSymbol) { return errorType; @@ -31270,6 +31260,10 @@ namespace ts { } } + if (node.flags & NodeFlags.ClassStaticBlockContext) { + error(node, Diagnostics.Await_expression_cannot_be_used_inside_class_static_block); + } + if (isInParameterInitializerBeforeContainingFunction(node)) { error(node, Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer); } @@ -34728,9 +34722,6 @@ namespace ts { function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { - if (node.name) { - checkGrammarIdentifierInClassStaticBlockContext(node.name); - } checkFunctionOrMethodDeclaration(node); checkGrammarForGenerator(node); checkCollisionWithRequireExportsInGeneratedCode(node, node.name!); @@ -35457,10 +35448,6 @@ namespace ts { return; } - if (node.name.kind === SyntaxKind.Identifier) { - checkGrammarIdentifierInClassStaticBlockContext(node.name); - } - // 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 @@ -36697,7 +36684,6 @@ namespace ts { function checkBreakOrContinueStatement(node: BreakOrContinueStatement) { // Grammar checking - if (node.label) checkGrammarIdentifierInClassStaticBlockContext(node.label); if (!checkGrammarStatementInAmbientContext(node)) checkGrammarBreakOrContinueStatement(node); // TODO: Check that target label is valid @@ -36841,7 +36827,6 @@ namespace ts { return false; }); } - checkGrammarIdentifierInClassStaticBlockContext(node.label); // ensure that label is unique checkSourceElement(node.statement); @@ -37165,9 +37150,6 @@ namespace ts { if (!node.name && !hasSyntacticModifier(node, ModifierFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } - if (node.name) { - checkGrammarIdentifierInClassStaticBlockContext(node.name); - } checkClassLikeDeclaration(node); forEach(node.members, checkSourceElement); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c532f88339f38..ce0b449d3aec4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6506,7 +6506,7 @@ "category": "Error", "code": 18036 }, - "Identifier 'await' cannot be used inside class static block.": { + "Await expression cannot be used inside class static block.": { "category": "Error", "code": 18037 } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cc269a459d7c9..dd9884e95b95c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1251,10 +1251,6 @@ namespace ts { setContextFlag(val, NodeFlags.AwaitContext); } - function setClassStaticBlockContext(val: boolean) { - setContextFlag(val, NodeFlags.ClassStaticBlockContext); - } - function doOutsideOfContext(context: NodeFlags, func: () => T): T { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear @@ -1321,6 +1317,10 @@ namespace ts { return doOutsideOfContext(NodeFlags.AwaitContext, func); } + function doOutsideYieldContext(func: () => T): T { + return doOutsideOfContext(NodeFlags.YieldContext, func); + } + function doInYieldAndAwaitContext(func: () => T): T { return doInsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext, func); } @@ -1329,10 +1329,6 @@ namespace ts { return doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext, func); } - function doOutsideOfClassStaticBlockContext(func: () => T): T { - return doOutsideOfContext(NodeFlags.ClassStaticBlockContext, func); - } - function inContext(flags: NodeFlags) { return (contextFlags & flags) !== 0; } @@ -1353,10 +1349,6 @@ namespace ts { return inContext(NodeFlags.AwaitContext); } - function inClassStaticBlockContext() { - return inContext(NodeFlags.ClassStaticBlockContext); - } - function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0); } @@ -3087,11 +3079,9 @@ namespace ts { // BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt const savedYieldContext = inYieldContext(); const savedAwaitContext = inAwaitContext(); - const savedClassStaticBlockContext = inClassStaticBlockContext(); setYieldContext(!!(flags & SignatureFlags.Yield)); setAwaitContext(!!(flags & SignatureFlags.Await)); - setClassStaticBlockContext(false); const parameters = flags & SignatureFlags.JSDoc ? parseDelimitedList(ParsingContext.JSDocParameters, parseJSDocParameter) : @@ -3099,7 +3089,6 @@ namespace ts { setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); - setClassStaticBlockContext(savedClassStaticBlockContext); return parameters; } @@ -4120,9 +4109,6 @@ namespace ts { function parseSimpleArrowFunctionExpression(pos: number, identifier: Identifier, asyncModifier?: NodeArray | undefined): ArrowFunction { Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(false); - (identifier as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; const parameter = factory.createParameterDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, @@ -4138,7 +4124,6 @@ namespace ts { const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken); const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier); const node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body); - setClassStaticBlockContext(savedClassStaticBlockContext); return addJSDocComment(finishNode(node, pos)); } @@ -4350,10 +4335,6 @@ namespace ts { } function parseParenthesizedArrowFunctionExpression(allowAmbiguity: boolean): ArrowFunction | undefined { - return doOutsideOfClassStaticBlockContext(() => parseParenthesizedArrowFunctionExpressionWorker(allowAmbiguity)); - } - - function parseParenthesizedArrowFunctionExpressionWorker(allowAmbiguity: boolean): ArrowFunction | undefined { const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); const modifiers = parseModifiersForArrowFunction(); @@ -5565,10 +5546,6 @@ namespace ts { parseExpected(SyntaxKind.ColonToken); const initializer = allowInAnd(parseAssignmentExpressionOrHigher); node = factory.createPropertyAssignment(name, initializer); - if (!isComputedPropertyName(name)) { - // propertyName should not care ClassStaticBlockContext if not computed property name. - (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; - } } // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker node.decorators = decorators; @@ -5614,11 +5591,10 @@ 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 = doOutsideOfClassStaticBlockContext(() => - isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : + const name = isGenerator && isAsync ? doInYieldAndAwaitContext(parseOptionalBindingIdentifier) : isGenerator ? doInYieldContext(parseOptionalBindingIdentifier) : isAsync ? doInAwaitContext(parseOptionalBindingIdentifier) : - parseOptionalBindingIdentifier()); + parseOptionalBindingIdentifier(); const typeParameters = parseTypeParameters(); const parameters = parseParameters(isGenerator | isAsync); @@ -5708,9 +5684,6 @@ namespace ts { const savedAwaitContext = inAwaitContext(); setAwaitContext(!!(flags & SignatureFlags.Await)); - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(false); - const savedTopLevel = topLevel; topLevel = false; @@ -5730,7 +5703,6 @@ namespace ts { topLevel = savedTopLevel; setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); - setClassStaticBlockContext(savedClassStaticBlockContext); return block; } @@ -6370,8 +6342,6 @@ namespace ts { else { parseExpected(SyntaxKind.ColonToken); name = parseIdentifierOrPattern(); - // propertyName should not care about the ClassStaticBlockContext - (propertyName as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; } const initializer = parseInitializer(); return finishNode(factory.createBindingElement(dotDotDotToken, propertyName, name, initializer), pos); @@ -6457,7 +6427,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(); } @@ -6591,25 +6561,17 @@ namespace ts { ): PropertyDeclaration | MethodDeclaration { const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); const name = parsePropertyName(); - if (!isComputedPropertyName(name)) { - // property name is not care about ClassStaticBlockContext if not computed property name. - (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; - } // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseMethodDeclaration(pos, hasJSDoc, decorators, modifiers, asteriskToken, name, questionToken, /*exclamationToken*/ undefined, Diagnostics.or_expected); } - return doOutsideOfClassStaticBlockContext(() => parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken)); + return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken); } function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration { const name = parsePropertyName(); - if (!isComputedPropertyName(name)) { - // property name is not care about ClassStaticBlockContext if not computed property name. - (name as Mutable).flags &= ~NodeFlags.ClassStaticBlockContext; - } const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6694,15 +6656,15 @@ namespace ts { function parseClassStaticBlockDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: ModifiersArray | undefined): ClassStaticBlockDeclaration { parseExpectedToken(SyntaxKind.StaticKeyword); - const body = parseClassStaticBlockBodyBlock(); + const body = parseClassStaticBlockBody(); return withJSDoc(finishNode(factory.createClassStaticBlockDeclaration(decorators, modifiers, body), pos), hasJSDoc); } - function parseClassStaticBlockBodyBlock() { - return doOutsideOfYieldAndAwaitContext(() => { - return doInsideOfContext(NodeFlags.ClassStaticBlockContext, () => { - return parseBlock(/*ignoreMissingOpenBrace*/ false); - }); + function parseClassStaticBlockBody() { + return doOutsideYieldContext(() => { + return doInsideOfContext(NodeFlags.AwaitContext | NodeFlags.ClassStaticBlockContext, () => { + return parseBlock(/*ignoreMissingOpenBrace*/ false) + }) }); } @@ -6862,11 +6824,7 @@ namespace ts { 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 = doOutsideOfContext( - kind === SyntaxKind.ClassExpression ? NodeFlags.ClassStaticBlockContext : NodeFlags.None, - parseNameOfClassDeclarationOrExpression - ); - + const name = parseNameOfClassDeclarationOrExpression(); const typeParameters = parseTypeParameters(); if (some(modifiers, isExportModifier)) setAwaitContext(/*value*/ true); const heritageClauses = parseHeritageClauses(); diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt index d9f4c6f685797..7564250be4b51 100644 --- a/tests/baselines/reference/classStaticBlock22.errors.txt +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -1,72 +1,94 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(7,11): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS2349: This expression is not callable. - Type 'String' has no call signatures. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(22,14): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(25,11): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(28,8): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,10): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,5): error TS2304: Cannot find name 'let'. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS1005: ';' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,16): error TS2693: 'any' only refers to a type, but is being used as a value here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,5): error TS2304: Cannot find name 'let'. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS1005: ';' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,10): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(28,14): error TS1005: ':' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,10): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,15): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,10): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS1003: Identifier expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,20): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,17): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,22): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,24): error TS1005: ';' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,17): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): error TS1109: Expression expected. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (13 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (27 errors) ==== let await: "any"; class C { static { let await: any; // illegal, cannot declare a new binding for await + ~~~ +!!! error TS2304: Cannot find name 'let'. ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS1005: ';' expected. + ~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. + ~~~ +!!! error TS2693: 'any' only refers to a type, but is being used as a value here. } static { let { await } = {} as any; // illegal, cannot declare a new binding for await - ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. } static { let { await: other } = {} as any; // legal } static { let await; // illegal, cannot declare a new binding for await + ~~~ +!!! error TS2304: Cannot find name 'let'. + ~~~~~ +!!! error TS1005: ';' expected. ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. } static { await; // illegal ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. } static { await(1); // illegal - ~~~~~ -!!! error TS2349: This expression is not callable. -!!! error TS2349: Type 'String' has no call signatures. - ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. + ~~~~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. } static { function await() {}; // illegal - ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. } static { class await {}; // illegal - ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. } static { ({ await }); // illegal short-hand property reference - ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. + ~ +!!! error TS1005: ':' expected. } static { ({ [await]: 1 }); // illegal ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. } static { class D { @@ -74,7 +96,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): e x = await; // legal (initializers have an implicit function boundary) [await] = 1; // illegal (computed property names are evaluated outside of a class body ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. }; } static { @@ -92,10 +116,16 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): e static { await: // illegal, 'await' cannot be used as a label ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. break await; // illegal, 'await' cannot be used as a label ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS1003: Identifier expected. + ~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. } static { class E { @@ -129,6 +159,16 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): e static { function f (await) {} const ff = (await) => {} + ~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. + ~~ +!!! error TS1005: ';' expected. const fff = await => {} + ~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. + ~~ +!!! error TS1109: Expression expected. } } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock22.js b/tests/baselines/reference/classStaticBlock22.js index 4fe3aed0a8e54..579ef690ba9f5 100644 --- a/tests/baselines/reference/classStaticBlock22.js +++ b/tests/baselines/reference/classStaticBlock22.js @@ -94,7 +94,9 @@ class C { let await; class C { static { - let await; // illegal, cannot declare a new binding for await + let; + await ; + any; // illegal, cannot declare a new binding for await } static { let { await } = {}; // illegal, cannot declare a new binding for await @@ -103,13 +105,14 @@ class C { let { await: other } = {}; // legal } static { - let await; // illegal, cannot declare a new binding for await + let; + await ; // illegal, cannot declare a new binding for await } static { - await; // illegal + await ; // illegal } static { - await(1); // illegal + await (1); // illegal } static { function await() { } @@ -121,16 +124,16 @@ class C { ; // illegal } static { - ({ await }); // illegal short-hand property reference + ({ await: }); // illegal short-hand property reference } static { - ({ [await]: 1 }); // illegal + ({ [await ]: 1 }); // illegal } static { class D { await = 1; // legal x = await; // legal (initializers have an implicit function boundary) - [await] = 1; // illegal (computed property names are evaluated outside of a class body + [await ] = 1; // illegal (computed property names are evaluated outside of a class body } ; } @@ -148,8 +151,9 @@ class C { (() => await); // legal, 'await' is inside of a new function boundary } static { - await: // illegal, 'await' cannot be used as a label - break await; // illegal, 'await' cannot be used as a label + await ; + break ; + await ; // illegal, 'await' cannot be used as a label } static { class E { @@ -182,7 +186,9 @@ class C { } static { function f(await) { } - const ff = (await) => { }; - const fff = await => { }; + const ff = (await ); + { } + const fff = await ; + { } } } diff --git a/tests/baselines/reference/classStaticBlock22.symbols b/tests/baselines/reference/classStaticBlock22.symbols index 64eaccba8ab2e..be8cf7bd984e9 100644 --- a/tests/baselines/reference/classStaticBlock22.symbols +++ b/tests/baselines/reference/classStaticBlock22.symbols @@ -7,7 +7,6 @@ class C { 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 @@ -19,15 +18,12 @@ class C { } static { let await; // illegal, cannot declare a new binding for await ->await : Symbol(await, Decl(classStaticBlock22.ts, 12, 7)) } static { await; // illegal ->await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) } static { await(1); // illegal ->await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) } static { function await() {}; // illegal @@ -44,7 +40,6 @@ class C { static { ({ [await]: 1 }); // illegal >[await] : Symbol([await], Decl(classStaticBlock22.ts, 30, 6)) ->await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) } static { class D { @@ -59,7 +54,6 @@ class C { [await] = 1; // illegal (computed property names are evaluated outside of a class body >[await] : Symbol(D[await], Decl(classStaticBlock22.ts, 35, 18)) ->await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) }; } @@ -157,10 +151,8 @@ class C { const ff = (await) => {} >ff : Symbol(ff, Decl(classStaticBlock22.ts, 86, 9)) ->await : Symbol(await, Decl(classStaticBlock22.ts, 86, 16)) const fff = await => {} >fff : Symbol(fff, Decl(classStaticBlock22.ts, 87, 9)) ->await : Symbol(await, Decl(classStaticBlock22.ts, 87, 15)) } } diff --git a/tests/baselines/reference/classStaticBlock22.types b/tests/baselines/reference/classStaticBlock22.types index da7813a38a2f0..4fb6162c3417c 100644 --- a/tests/baselines/reference/classStaticBlock22.types +++ b/tests/baselines/reference/classStaticBlock22.types @@ -7,7 +7,10 @@ class C { static { let await: any; // illegal, cannot declare a new binding for await +>let : any >await : any +> : any +>any : any } static { let { await } = {} as any; // illegal, cannot declare a new binding for await @@ -24,16 +27,19 @@ class C { } static { let await; // illegal, cannot declare a new binding for await +>let : any >await : any +> : any } static { await; // illegal ->await : "any" +>await : any +> : any } static { await(1); // illegal ->await(1) : any ->await : "any" +>await(1) : 1 +>(1) : 1 >1 : 1 } static { @@ -46,16 +52,18 @@ class C { } static { ({ await }); // illegal short-hand property reference ->({ await }) : { await: "any"; } ->{ await } : { await: "any"; } ->await : "any" +>({ await }) : { await: any; } +>{ await } : { await: any; } +>await : any +> : any } static { ({ [await]: 1 }); // illegal ->({ [await]: 1 }) : { any: number; } ->{ [await]: 1 } : { any: number; } +>({ [await]: 1 }) : { [x: number]: number; } +>{ [await]: 1 } : { [x: number]: number; } >[await] : number ->await : "any" +>await : any +> : any >1 : 1 } static { @@ -72,7 +80,8 @@ class C { [await] = 1; // illegal (computed property names are evaluated outside of a class body >[await] : number ->await : "any" +>await : any +> : any >1 : 1 }; @@ -104,9 +113,12 @@ class C { 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 { class E { @@ -187,13 +199,14 @@ class C { >await : any const ff = (await) => {} ->ff : (await: any) => void ->(await) => {} : (await: any) => void +>ff : any +>(await) : any >await : any +> : any const fff = await => {} ->fff : (await: any) => void ->await => {} : (await: any) => void +>fff : any >await : any +> : any } } diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index e0ade776056e6..1017de30820e1 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -1,12 +1,13 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): error TS18037: Identifier 'await' cannot be used inside class static block. 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(12,9): error TS18037: Identifier 'await' cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS18037: Identifier 'await' cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(12,9): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(12,14): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,14): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (6 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (7 errors) ==== class B { static a = 1; } @@ -14,8 +15,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err class C extends B { static { var await = 1; - ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. var arguments = 1; ~~~~~~~~~ !!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. @@ -26,14 +25,18 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err await: if (true) { ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. } arguments; await; ~~~~~ -!!! error TS18037: Identifier 'await' cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. super(); ~~~~~ !!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index d9486fa05e40e..1b8153d3a7ae0 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -55,9 +55,10 @@ _C__ = { value: (function () { var await = 1; var arguments = 1; var eval = 1; - await: if (true) { + yield ; + if (true) { } arguments; - await; + yield ; _this = _super.call(this) || this; })() }; diff --git a/tests/baselines/reference/classStaticBlock6.symbols b/tests/baselines/reference/classStaticBlock6.symbols index 9d604e9bcabc3..36780356cb437 100644 --- a/tests/baselines/reference/classStaticBlock6.symbols +++ b/tests/baselines/reference/classStaticBlock6.symbols @@ -29,8 +29,6 @@ class C extends B { >arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) await; ->await : Symbol(await, Decl(classStaticBlock6.ts, 6, 11)) - super(); } } diff --git a/tests/baselines/reference/classStaticBlock6.types b/tests/baselines/reference/classStaticBlock6.types index 11e2f3753bc6d..bee52c5ec5588 100644 --- a/tests/baselines/reference/classStaticBlock6.types +++ b/tests/baselines/reference/classStaticBlock6.types @@ -27,6 +27,7 @@ class C extends B { await: if (true) { >await : any +> : any >true : true } @@ -35,7 +36,8 @@ class C extends B { >arguments : number await; ->await : number +>await : any +> : any super(); >super() : void diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt index 891d67478e9d3..badf7158ba080 100644 --- a/tests/baselines/reference/classStaticBlock7.errors.txt +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS18037: Await expression cannot be used inside 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 TS1108: A 'return' statement can only be used within a function body. @@ -7,8 +7,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(5,9): erro class C { static { await 1; - ~~~~~ -!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. + ~~~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. yield 1; ~~~~~ !!! error TS1163: A 'yield' expression is only allowed in a generator body. From 16a3bcf614ea4011e725c13ab7b3da6d0e73289a Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 11 Jun 2021 22:37:27 +0800 Subject: [PATCH 18/36] Fix class static block context --- src/compiler/parser.ts | 45 +++++++++++++++---- .../reference/classStaticBlock6.errors.txt | 20 +++++++-- .../baselines/reference/classStaticBlock6.js | 16 ++++--- .../reference/classStaticBlock6.symbols | 8 ++-- .../reference/classStaticBlock6.types | 10 +++-- .../classStaticBlock/classStaticBlock6.ts | 6 +-- 6 files changed, 73 insertions(+), 32 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dd9884e95b95c..db07adbfa0315 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1251,6 +1251,10 @@ namespace ts { setContextFlag(val, NodeFlags.AwaitContext); } + function setClassStaticBlockContext(val: boolean) { + setContextFlag(val, NodeFlags.ClassStaticBlockContext); + } + function doOutsideOfContext(context: NodeFlags, func: () => T): T { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear @@ -1317,6 +1321,10 @@ namespace ts { return doOutsideOfContext(NodeFlags.AwaitContext, func); } + function doOutsideOfClassStaticBlockContext(func: () => T): T { + return doOutsideOfContext(NodeFlags.ClassStaticBlockContext, func); + } + function doOutsideYieldContext(func: () => T): T { return doOutsideOfContext(NodeFlags.YieldContext, func); } @@ -1349,6 +1357,10 @@ namespace ts { return inContext(NodeFlags.AwaitContext); } + function inClassStaticBlockContext() { + return inContext(NodeFlags.ClassStaticBlockContext); + } + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0); } @@ -4010,7 +4022,7 @@ namespace ts { // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done // with AssignmentExpression if we see one. - const arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression(); + const arrowExpression = doOutsideOfClassStaticBlockContext(() => tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression()); if (arrowExpression) { return arrowExpression; } @@ -5580,9 +5592,9 @@ namespace ts { // FunctionExpression: // function BindingIdentifier[opt](FormalParameters){ FunctionBody } const savedDecoratorContext = inDecoratorContext(); - if (savedDecoratorContext) { - setDecoratorContext(/*val*/ false); - } + setDecoratorContext(/*val*/ false); + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(/*val*/ false); const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -5601,9 +5613,8 @@ namespace ts { const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlock(isGenerator | isAsync); - if (savedDecoratorContext) { - setDecoratorContext(/*val*/ true); - } + setDecoratorContext(savedDecoratorContext); + setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -6459,6 +6470,9 @@ namespace ts { function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): FunctionDeclaration { const savedAwaitContext = inAwaitContext(); + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(/*val*/ false); + const modifierFlags = modifiersToFlags(modifiers); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -6472,6 +6486,7 @@ namespace ts { const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlockOrSemicolon(isGenerator | isAsync, Diagnostics.or_expected); setAwaitContext(savedAwaitContext); + setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionDeclaration(decorators, modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6491,6 +6506,8 @@ namespace ts { function tryParseConstructorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): ConstructorDeclaration | undefined { return tryParse(() => { if (parseConstructorName()) { + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(/*val*/ false); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6499,6 +6516,7 @@ namespace ts { // Attach `typeParameters` and `type` if they exist so that we can report them in the grammar checker. node.typeParameters = typeParameters; node.type = type; + setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } }); @@ -6515,6 +6533,8 @@ namespace ts { exclamationToken: ExclamationToken | undefined, diagnosticMessage?: DiagnosticMessage ): MethodDeclaration { + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(/*val*/ false); const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; const isAsync = some(modifiers, isAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); @@ -6534,6 +6554,7 @@ namespace ts { ); // An exclamation token on a method is invalid syntax and will be handled by the grammar checker node.exclamationToken = exclamationToken; + setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6545,11 +6566,14 @@ namespace ts { name: PropertyName, questionToken: QuestionToken | undefined ): PropertyDeclaration { + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(/*val*/ false); const exclamationToken = !questionToken && !scanner.hasPrecedingLineBreak() ? parseOptionalToken(SyntaxKind.ExclamationToken) : undefined; const type = parseTypeAnnotation(); const initializer = doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext | NodeFlags.DisallowInContext, parseInitializer); parseSemicolon(); const node = factory.createPropertyDeclaration(decorators, modifiers, name, questionToken || exclamationToken, type, initializer); + setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6572,6 +6596,8 @@ namespace ts { function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration { const name = parsePropertyName(); + const savedClassStaticBlockContext = inClassStaticBlockContext(); + setClassStaticBlockContext(/*val*/ false); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6582,6 +6608,7 @@ namespace ts { // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors node.typeParameters = typeParameters; if (type && node.kind === SyntaxKind.SetAccessor) (node as Mutable).type = type; + setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6663,8 +6690,8 @@ namespace ts { function parseClassStaticBlockBody() { return doOutsideYieldContext(() => { return doInsideOfContext(NodeFlags.AwaitContext | NodeFlags.ClassStaticBlockContext, () => { - return parseBlock(/*ignoreMissingOpenBrace*/ false) - }) + return parseBlock(/*ignoreMissingOpenBrace*/ false); + }); }); } diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 1017de30820e1..182e05d557273 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -1,3 +1,7 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,9): error TS2304: Cannot find name 'let'. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): error TS1005: ';' expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,19): error TS1109: Expression expected. 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(12,9): error TS18037: Await expression cannot be used inside class static block. @@ -7,18 +11,26 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,14): er tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (7 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (11 errors) ==== class B { static a = 1; } class C extends B { static { - var await = 1; - var arguments = 1; + let await = 1; + ~~~ +!!! error TS2304: Cannot find name 'let'. + ~~~~~ +!!! error TS1005: ';' expected. + ~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. + let arguments = 1; ~~~~~~~~~ !!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. - var eval = 1; + let eval = 1; ~~~~ !!! error TS1210: Invalid use of 'eval'. Class definitions are automatically in strict mode. diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index 1b8153d3a7ae0..66448a02e36e2 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -5,9 +5,9 @@ class B { class C extends B { static { - var await = 1; - var arguments = 1; - var eval = 1; + let await = 1; + let arguments = 1; + let eval = 1; await: if (true) { @@ -52,13 +52,15 @@ var C = /** @class */ (function (_super) { return C; }(B)); _C__ = { value: (function () { - var await = 1; - var arguments = 1; - var eval = 1; + let; + yield ; + 1; + var arguments_1 = 1; + var eval_1 = 1; yield ; if (true) { } - arguments; + arguments_1; yield ; _this = _super.call(this) || this; })() }; diff --git a/tests/baselines/reference/classStaticBlock6.symbols b/tests/baselines/reference/classStaticBlock6.symbols index 36780356cb437..48241e0e54c33 100644 --- a/tests/baselines/reference/classStaticBlock6.symbols +++ b/tests/baselines/reference/classStaticBlock6.symbols @@ -11,13 +11,11 @@ class C extends B { >B : Symbol(B, Decl(classStaticBlock6.ts, 0, 0)) static { - var await = 1; ->await : Symbol(await, Decl(classStaticBlock6.ts, 6, 11)) - - var arguments = 1; + let await = 1; + let arguments = 1; >arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) - var eval = 1; + let eval = 1; >eval : Symbol(eval, Decl(classStaticBlock6.ts, 8, 11)) diff --git a/tests/baselines/reference/classStaticBlock6.types b/tests/baselines/reference/classStaticBlock6.types index bee52c5ec5588..089078b6728c5 100644 --- a/tests/baselines/reference/classStaticBlock6.types +++ b/tests/baselines/reference/classStaticBlock6.types @@ -12,15 +12,17 @@ class C extends B { >B : B static { - var await = 1; ->await : number + let await = 1; +>let : any +>await : any +> : any >1 : 1 - var arguments = 1; + let arguments = 1; >arguments : number >1 : 1 - var eval = 1; + let eval = 1; >eval : number >1 : 1 diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts index 24eef812abc38..f770f7c2400d5 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts @@ -4,9 +4,9 @@ class B { class C extends B { static { - var await = 1; - var arguments = 1; - var eval = 1; + let await = 1; + let arguments = 1; + let eval = 1; await: if (true) { From 192fd33f3ac4dce907d27cab0cb268d639f59523 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 12 Jun 2021 00:06:14 +0800 Subject: [PATCH 19/36] Fix checks --- src/compiler/checker.ts | 7 + src/compiler/diagnosticMessages.json | 12 ++ src/compiler/utilities.ts | 9 + .../reference/classStaticBlock23.errors.txt | 28 +++ .../baselines/reference/classStaticBlock23.js | 39 +++++ .../reference/classStaticBlock23.symbols | 48 ++++++ .../reference/classStaticBlock23.types | 57 +++++++ .../reference/classStaticBlock6.errors.txt | 83 ++++++++- .../baselines/reference/classStaticBlock6.js | 159 +++++++++++++++++- .../reference/classStaticBlock6.symbols | 75 ++++++++- .../reference/classStaticBlock6.types | 82 ++++++++- .../reference/classStaticBlock7.errors.txt | 61 ++++++- .../baselines/reference/classStaticBlock7.js | 140 +++++++++++++++ .../reference/classStaticBlock7.symbols | 54 ++++++ .../reference/classStaticBlock7.types | 64 +++++++ .../classStaticBlock/classStaticBlock23.ts | 21 +++ .../classStaticBlock/classStaticBlock6.ts | 44 ++++- .../classStaticBlock/classStaticBlock7.ts | 36 ++++ 18 files changed, 1002 insertions(+), 17 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock23.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock23.js create mode 100644 tests/baselines/reference/classStaticBlock23.symbols create mode 100644 tests/baselines/reference/classStaticBlock23.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 09ba875d1ecb6..9439e217c7bcd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35871,6 +35871,10 @@ namespace ts { checkGrammarForInOrForOfStatement(node); if (node.awaitModifier) { + if (node.flags & NodeFlags.ClassStaticBlockContext) { + grammarErrorOnNode(node.awaitModifier, Diagnostics.For_await_loops_cannot_be_used_inside_class_static_block); + } + 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 @@ -36754,6 +36758,9 @@ namespace ts { return; } + if(node.flags & NodeFlags.ClassStaticBlockContext) { + grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_cannot_be_used_inside_class_static_block); + } const func = getContainingFunction(node); if (!func) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dd6cc2db9d757..0a6977cd29327 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6604,5 +6604,17 @@ "Await expression cannot be used inside class static block.": { "category": "Error", "code": 18037 + }, + "'For await' loops cannot be used inside class static block.": { + "category": "Error", + "code": 18038 + }, + "Invalid use of '{0}'. It cannot be used inside class static block.": { + "category": "Error", + "code": 18039 + }, + "A 'return' statement cannot be used inside class static block.": { + "category": "Error", + "code": 18041 } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b2e786e7a47c5..6fd2ef61c7bc1 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1573,6 +1573,15 @@ 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 getThisContainer(node: Node, includeArrowFunctions: boolean): Node { Debug.assert(node.kind !== SyntaxKind.SourceFile); while (true) { diff --git a/tests/baselines/reference/classStaticBlock23.errors.txt b/tests/baselines/reference/classStaticBlock23.errors.txt new file mode 100644 index 0000000000000..c540340187491 --- /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 class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(14,11): error TS18038: 'For await' loops cannot be used inside 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 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 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/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 182e05d557273..4ea5d01bb42d0 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -4,14 +4,23 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): err tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,19): error TS1109: Expression expected. 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(12,9): error TS18037: Await expression cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(12,14): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,9): error TS18037: Await expression cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(17,14): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(13,9): error TS18037: Await expression cannot be used inside 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 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 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(42,13): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(42,18): error TS1109: Expression expected. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(44,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. +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(57,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (11 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (20 errors) ==== class B { static a = 1; } @@ -33,8 +42,9 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err 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 class static block. @@ -44,6 +54,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err } arguments; + ~~~~~~~~~ +!!! error TS2662: Cannot find name 'arguments'. Did you mean the static member 'C.arguments'? await; ~~~~~ !!! error TS18037: Await expression cannot be used inside class static block. @@ -54,4 +66,61 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err !!! 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 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 TS18037: Await expression cannot be used inside class static block. + ~ +!!! error TS1109: Expression expected. + + async function ff () { + ~~ +!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. + 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; + + function ff () { + ~~ +!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. + arguments; + } + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index 66448a02e36e2..79e296fb2cb78 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -8,8 +8,9 @@ class C extends B { let await = 1; let arguments = 1; let eval = 1; + } - + static { await: if (true) { } @@ -19,6 +20,47 @@ class C extends B { 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] @@ -37,7 +79,43 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); -var _C__; +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__, _C__1; var B = /** @class */ (function () { function B() { } @@ -57,10 +135,85 @@ _C__ = { value: (function () { 1; var arguments_1 = 1; var eval_1 = 1; + })() }; +_C__1 = { value: (function () { yield ; if (true) { } - arguments_1; + arguments; yield ; _this = _super.call(this) || this; })() }; +var CC = /** @class */ (function () { + function CC() { + var _C__2; + var C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; + }(B)); + _C__2 = { value: (function () { + var CC_1 = /** @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() { + var _C__3; + return __awaiter(this, arguments, 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)); + _C__3 = { value: (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__4; + var C = /** @class */ (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; + }(B)); + _C__4 = { value: (function () { + arguments; + function ff() { + arguments; + } + })() }; +} diff --git a/tests/baselines/reference/classStaticBlock6.symbols b/tests/baselines/reference/classStaticBlock6.symbols index 48241e0e54c33..26c7e0f0e39e7 100644 --- a/tests/baselines/reference/classStaticBlock6.symbols +++ b/tests/baselines/reference/classStaticBlock6.symbols @@ -17,17 +17,86 @@ class C extends B { let eval = 1; >eval : Symbol(eval, Decl(classStaticBlock6.ts, 8, 11)) + } - + static { await: if (true) { } arguments; ->arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) - 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 index 089078b6728c5..3732a03d3c43f 100644 --- a/tests/baselines/reference/classStaticBlock6.types +++ b/tests/baselines/reference/classStaticBlock6.types @@ -25,8 +25,9 @@ class C extends B { let eval = 1; >eval : number >1 : 1 + } - + static { await: if (true) { >await : any > : any @@ -35,7 +36,7 @@ class C extends B { } arguments; ->arguments : number +>arguments : any await; >await : any @@ -47,3 +48,80 @@ class C extends B { } } +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 : IArguments + + 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 : IArguments + + function ff () { +>ff : () => void + + arguments; +>arguments : IArguments + } + } + } +} + diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt index badf7158ba080..0c730a6bea832 100644 --- a/tests/baselines/reference/classStaticBlock7.errors.txt +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -1,9 +1,18 @@ +error TS2318: Cannot find global type 'IterableIterator'. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS18037: Await expression cannot be used inside 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 TS1108: A 'return' statement can only be used within a function body. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(5,9): error TS18041: A 'return' statement cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(12,13): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(14,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. +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(26,24): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(36,13): error TS18041: A 'return' statement cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (3 errors) ==== +!!! error TS2318: Cannot find global type 'IterableIterator'. +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (10 errors) ==== class C { static { await 1; @@ -15,6 +24,56 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(5,9): erro return 1; ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. + ~~~~~~ +!!! error TS18041: A 'return' statement cannot be used inside class static block. + } + } + + async function f1 () { + class C { + static { + await 1; + ~~~~~~~ +!!! error TS18037: Await expression cannot be used inside class static block. + + async function ff () { + ~~ +!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. + await 1; + } + } + } + } + + function * f2 () { + class C { + static { + yield 1; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + + function * ff () { + ~~ +!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. + yield 1; + } + } + } + } + + function f3 () { + class C { + static { + return 1; + ~~~~~~ +!!! error TS18041: A 'return' statement cannot be used inside class static block. + + function ff () { + ~~ +!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. + return 1 + } + } } } \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock7.js b/tests/baselines/reference/classStaticBlock7.js index f0ef3ec6b7a79..9579f500e55b6 100644 --- a/tests/baselines/reference/classStaticBlock7.js +++ b/tests/baselines/reference/classStaticBlock7.js @@ -6,9 +6,81 @@ class C { 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__; var C = /** @class */ (function () { function C() { @@ -20,3 +92,71 @@ _C__ = { value: (function () { yield 1; return 1; })() }; +function f1() { + var _C__1; + return __awaiter(this, void 0, void 0, function () { + var C; + return __generator(this, function (_a) { + C = /** @class */ (function () { + function C() { + } + return C; + }()); + _C__1 = { value: (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; + var _C__2; + return __generator(this, function (_a) { + C = /** @class */ (function () { + function C() { + } + return C; + }()); + _C__2 = { value: (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__3; + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + _C__3 = { value: (function () { + return 1; + function ff() { + return 1; + } + })() }; +} diff --git a/tests/baselines/reference/classStaticBlock7.symbols b/tests/baselines/reference/classStaticBlock7.symbols index ab40a1f74e18c..d42ee5e420396 100644 --- a/tests/baselines/reference/classStaticBlock7.symbols +++ b/tests/baselines/reference/classStaticBlock7.symbols @@ -9,3 +9,57 @@ class C { } } +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 index d1e8ba48866f6..83eade23082c8 100644 --- a/tests/baselines/reference/classStaticBlock7.types +++ b/tests/baselines/reference/classStaticBlock7.types @@ -16,3 +16,67 @@ class C { } } +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/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/classStaticBlock6.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts index f770f7c2400d5..cdd0cda2fe7af 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts @@ -7,8 +7,9 @@ class C extends B { let await = 1; let arguments = 1; let eval = 1; + } - + static { await: if (true) { } @@ -18,3 +19,44 @@ class C extends B { 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 index d3daa8bd21cdb..727ada0342725 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts @@ -5,3 +5,39 @@ class C { 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 + } + } + } +} From bcb3ddb0c8f845677c2a8aa5012e9b8fc20e3543 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 16 Jun 2021 16:54:49 +0800 Subject: [PATCH 20/36] Fix missing case --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e83840f983343..7e7d3469acac0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35023,6 +35023,7 @@ namespace ts { break; case SyntaxKind.IndexSignature: case SyntaxKind.SemicolonClassElement: + case SyntaxKind.ClassStaticBlockDeclaration: // Can't be private break; default: From 6d0a1e551d366fb138e6625beebd541d61a8d238 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 16 Jun 2021 16:57:05 +0800 Subject: [PATCH 21/36] Improve assert message --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 57096cbc12134..567decd1e78fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35062,7 +35062,7 @@ namespace ts { // Can't be private break; default: - Debug.fail(); + Debug.fail("Unexpected class member"); } } } From 61e67fdb82a031950e399dc57f26a62f0a66a9ab Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 12:15:38 +0800 Subject: [PATCH 22/36] Accept baseline --- src/compiler/checker.ts | 2 +- .../reference/classStaticBlock22.errors.txt | 29 +------------------ .../baselines/reference/classStaticBlock22.js | 7 ++--- .../reference/classStaticBlock22.symbols | 2 ++ .../reference/classStaticBlock22.types | 5 ---- .../reference/classStaticBlock6.errors.txt | 21 ++++---------- .../baselines/reference/classStaticBlock6.js | 6 ++-- .../reference/classStaticBlock6.symbols | 2 ++ .../reference/classStaticBlock6.types | 8 ++--- 9 files changed, 19 insertions(+), 63 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 82d8a03e844ad..945f27b5c73d1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24188,7 +24188,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; } diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt index 7564250be4b51..fdf1531f7d647 100644 --- a/tests/baselines/reference/classStaticBlock22.errors.txt +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -1,12 +1,3 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,5): error TS2304: Cannot find name 'let'. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS1005: ';' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,9): error TS18037: Await expression cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,14): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(4,16): error TS2693: 'any' only refers to a type, but is being used as a value here. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,5): error TS2304: Cannot find name 'let'. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS1005: ';' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,9): error TS18037: Await expression cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(13,14): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Await expression cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,10): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Await expression cannot be used inside class static block. @@ -27,21 +18,11 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,17): e tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): error TS1109: Expression expected. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (27 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts (18 errors) ==== let await: "any"; class C { static { let await: any; // illegal, cannot declare a new binding for await - ~~~ -!!! error TS2304: Cannot find name 'let'. - ~~~~~ -!!! error TS1005: ';' expected. - ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. - ~ -!!! error TS1109: Expression expected. - ~~~ -!!! error TS2693: 'any' only refers to a type, but is being used as a value here. } static { let { await } = {} as any; // illegal, cannot declare a new binding for await @@ -51,14 +32,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e } static { let await; // illegal, cannot declare a new binding for await - ~~~ -!!! error TS2304: Cannot find name 'let'. - ~~~~~ -!!! error TS1005: ';' expected. - ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. - ~ -!!! error TS1109: Expression expected. } static { await; // illegal diff --git a/tests/baselines/reference/classStaticBlock22.js b/tests/baselines/reference/classStaticBlock22.js index 579ef690ba9f5..1757b74fa225f 100644 --- a/tests/baselines/reference/classStaticBlock22.js +++ b/tests/baselines/reference/classStaticBlock22.js @@ -94,9 +94,7 @@ class C { let await; class C { static { - let; - await ; - any; // illegal, cannot declare a new binding for await + let await; // illegal, cannot declare a new binding for await } static { let { await } = {}; // illegal, cannot declare a new binding for await @@ -105,8 +103,7 @@ class C { let { await: other } = {}; // legal } static { - let; - await ; // illegal, cannot declare a new binding for await + let await; // illegal, cannot declare a new binding for await } static { await ; // illegal diff --git a/tests/baselines/reference/classStaticBlock22.symbols b/tests/baselines/reference/classStaticBlock22.symbols index be8cf7bd984e9..56735f54b666c 100644 --- a/tests/baselines/reference/classStaticBlock22.symbols +++ b/tests/baselines/reference/classStaticBlock22.symbols @@ -7,6 +7,7 @@ class C { 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 @@ -18,6 +19,7 @@ class C { } static { let await; // illegal, cannot declare a new binding for await +>await : Symbol(await, Decl(classStaticBlock22.ts, 12, 7)) } static { await; // illegal diff --git a/tests/baselines/reference/classStaticBlock22.types b/tests/baselines/reference/classStaticBlock22.types index 4fb6162c3417c..e581d5b18851d 100644 --- a/tests/baselines/reference/classStaticBlock22.types +++ b/tests/baselines/reference/classStaticBlock22.types @@ -7,10 +7,7 @@ class C { static { let await: any; // illegal, cannot declare a new binding for await ->let : any >await : any -> : any ->any : any } static { let { await } = {} as any; // illegal, cannot declare a new binding for await @@ -27,9 +24,7 @@ class C { } static { let await; // illegal, cannot declare a new binding for await ->let : any >await : any -> : any } static { await; // illegal diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 4ea5d01bb42d0..9345c112f9fa3 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -1,7 +1,3 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,9): error TS2304: Cannot find name 'let'. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): error TS1005: ';' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,13): error TS18037: Await expression cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(7,19): error TS1109: Expression expected. 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 class static block. @@ -11,16 +7,17 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(18,9): err 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 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(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 class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(42,18): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(44,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. 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(57,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (20 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (17 errors) ==== class B { static a = 1; } @@ -28,14 +25,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er class C extends B { static { let await = 1; - ~~~ -!!! error TS2304: Cannot find name 'let'. - ~~~~~ -!!! error TS1005: ';' expected. - ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. - ~ -!!! error TS1109: Expression expected. let arguments = 1; ~~~~~~~~~ !!! error TS1210: Invalid use of 'arguments'. Class definitions are automatically in strict mode. @@ -89,7 +78,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er static { 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. +!!! error TS2815: 'arguments' cannot be referenced in property initializers. await; ~~~~~ !!! error TS18037: Await expression cannot be used inside class static block. @@ -114,6 +103,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er class C extends B { static { arguments; + ~~~~~~~~~ +!!! error TS2815: 'arguments' cannot be referenced in property initializers. function ff () { ~~ diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index 79e296fb2cb78..3ad0d38a199c9 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -130,9 +130,7 @@ var C = /** @class */ (function (_super) { return C; }(B)); _C__ = { value: (function () { - let; - yield ; - 1; + var await_1 = 1; var arguments_1 = 1; var eval_1 = 1; })() }; @@ -169,7 +167,7 @@ var CC = /** @class */ (function () { }()); function foo() { var _C__3; - return __awaiter(this, arguments, void 0, function () { + return __awaiter(this, void 0, void 0, function () { var C; return __generator(this, function (_a) { C = /** @class */ (function (_super) { diff --git a/tests/baselines/reference/classStaticBlock6.symbols b/tests/baselines/reference/classStaticBlock6.symbols index 26c7e0f0e39e7..6505cd0cf9a99 100644 --- a/tests/baselines/reference/classStaticBlock6.symbols +++ b/tests/baselines/reference/classStaticBlock6.symbols @@ -12,6 +12,8 @@ class C extends B { static { let await = 1; +>await : Symbol(await, Decl(classStaticBlock6.ts, 6, 11)) + let arguments = 1; >arguments : Symbol(arguments, Decl(classStaticBlock6.ts, 7, 11)) diff --git a/tests/baselines/reference/classStaticBlock6.types b/tests/baselines/reference/classStaticBlock6.types index 3732a03d3c43f..af1243a74f89a 100644 --- a/tests/baselines/reference/classStaticBlock6.types +++ b/tests/baselines/reference/classStaticBlock6.types @@ -13,9 +13,7 @@ class C extends B { static { let await = 1; ->let : any ->await : any -> : any +>await : number >1 : 1 let arguments = 1; @@ -84,7 +82,7 @@ async function foo () { static { arguments; ->arguments : IArguments +>arguments : any await; >await : any @@ -113,7 +111,7 @@ function foo1 () { static { arguments; ->arguments : IArguments +>arguments : any function ff () { >ff : () => void From e6085318b867de23c7a69c21a5c0aae7317ccdc0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 12:52:43 +0800 Subject: [PATCH 23/36] Avoid new context --- src/compiler/checker.ts | 43 ++++++++------- src/compiler/parser.ts | 53 +++++-------------- src/compiler/transformers/utilities.ts | 6 ++- src/compiler/types.ts | 5 +- src/compiler/utilities.ts | 4 ++ src/compiler/utilitiesPublic.ts | 3 +- .../reference/api/tsserverlibrary.d.ts | 6 +-- tests/baselines/reference/api/typescript.d.ts | 6 +-- .../reference/classStaticBlock7.errors.txt | 5 +- 9 files changed, 54 insertions(+), 77 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 945f27b5c73d1..1b0c7d81b9fc6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31272,6 +31272,7 @@ namespace ts { function checkAwaitExpression(node: AwaitExpression): Type { // Grammar checking if (produceDiagnostics) { + const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); if (!(node.flags & NodeFlags.AwaitContext)) { if (isInTopLevelContext(node)) { const sourceFile = getSourceFileOfNode(node); @@ -31297,17 +31298,15 @@ 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 (containingFunctionOrClassStaticBlock && containingFunctionOrClassStaticBlock.kind !== SyntaxKind.ClassStaticBlockDeclaration && containingFunctionOrClassStaticBlock.kind !== SyntaxKind.Constructor && (getFunctionFlags(containingFunctionOrClassStaticBlock) & FunctionFlags.Async) === 0) { + const relatedInfo = createDiagnosticForNode(containingFunctionOrClassStaticBlock, Diagnostics.Did_you_mean_to_mark_this_function_as_async); addRelatedInfo(diagnostic, relatedInfo); } diagnostics.add(diagnostic); } } } - - if (node.flags & NodeFlags.ClassStaticBlockContext) { + else if (containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { error(node, Diagnostics.Await_expression_cannot_be_used_inside_class_static_block); } @@ -35888,15 +35887,17 @@ namespace ts { function checkForOfStatement(node: ForOfStatement): void { checkGrammarForInOrForOfStatement(node); + const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); if (node.awaitModifier) { - if (node.flags & NodeFlags.ClassStaticBlockContext) { + if (containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { grammarErrorOnNode(node.awaitModifier, Diagnostics.For_await_loops_cannot_be_used_inside_class_static_block); } - - 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); + else { + const functionFlags = getFunctionFlags(containingFunctionOrClassStaticBlock); + 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) { @@ -36776,31 +36777,33 @@ namespace ts { return; } - if(node.flags & NodeFlags.ClassStaticBlockContext) { + const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); + if(containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_cannot_be_used_inside_class_static_block); + return; } - const func = getContainingFunction(node); - if (!func) { + + if (!containingFunctionOrClassStaticBlock) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); return; } - const signature = getSignatureFromDeclaration(func); + const signature = getSignatureFromDeclaration(containingFunctionOrClassStaticBlock); const returnType = getReturnTypeOfSignature(signature); - const functionFlags = getFunctionFlags(func); + const functionFlags = getFunctionFlags(containingFunctionOrClassStaticBlock); if (strictNullChecks || node.expression || returnType.flags & TypeFlags.Never) { const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType; - if (func.kind === SyntaxKind.SetAccessor) { + if (containingFunctionOrClassStaticBlock.kind === SyntaxKind.SetAccessor) { if (node.expression) { error(node, Diagnostics.Setters_cannot_return_a_value); } } - else if (func.kind === SyntaxKind.Constructor) { + else if (containingFunctionOrClassStaticBlock.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(containingFunctionOrClassStaticBlock)) { 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) @@ -36813,7 +36816,7 @@ namespace ts { } } } - else if (func.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(func, returnType)) { + else if (containingFunctionOrClassStaticBlock.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(containingFunctionOrClassStaticBlock, 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); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 82b58a689b3fc..f3ac472e122b0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1251,10 +1251,6 @@ namespace ts { setContextFlag(val, NodeFlags.AwaitContext); } - function setClassStaticBlockContext(val: boolean) { - setContextFlag(val, NodeFlags.ClassStaticBlockContext); - } - function doOutsideOfContext(context: NodeFlags, func: () => T): T { // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear @@ -1321,14 +1317,6 @@ namespace ts { return doOutsideOfContext(NodeFlags.AwaitContext, func); } - function doOutsideOfClassStaticBlockContext(func: () => T): T { - return doOutsideOfContext(NodeFlags.ClassStaticBlockContext, func); - } - - function doOutsideYieldContext(func: () => T): T { - return doOutsideOfContext(NodeFlags.YieldContext, func); - } - function doInYieldAndAwaitContext(func: () => T): T { return doInsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext, func); } @@ -1357,10 +1345,6 @@ namespace ts { return inContext(NodeFlags.AwaitContext); } - function inClassStaticBlockContext() { - return inContext(NodeFlags.ClassStaticBlockContext); - } - function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { parseErrorAt(scanner.getTokenPos(), scanner.getTextPos(), message, arg0); } @@ -4024,7 +4008,7 @@ namespace ts { // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done // with AssignmentExpression if we see one. - const arrowExpression = doOutsideOfClassStaticBlockContext(() => tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression()); + const arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression(); if (arrowExpression) { return arrowExpression; } @@ -5595,8 +5579,6 @@ namespace ts { // function BindingIdentifier[opt](FormalParameters){ FunctionBody } const savedDecoratorContext = inDecoratorContext(); setDecoratorContext(/*val*/ false); - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(/*val*/ false); const pos = getNodePos(); const hasJSDoc = hasPrecedingJSDocComment(); @@ -5616,7 +5598,6 @@ namespace ts { const body = parseFunctionBlock(isGenerator | isAsync); setDecoratorContext(savedDecoratorContext); - setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionExpression(modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); @@ -6472,8 +6453,6 @@ namespace ts { function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): FunctionDeclaration { const savedAwaitContext = inAwaitContext(); - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(/*val*/ false); const modifierFlags = modifiersToFlags(modifiers); parseExpected(SyntaxKind.FunctionKeyword); @@ -6488,7 +6467,6 @@ namespace ts { const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlockOrSemicolon(isGenerator | isAsync, Diagnostics.or_expected); setAwaitContext(savedAwaitContext); - setClassStaticBlockContext(savedClassStaticBlockContext); const node = factory.createFunctionDeclaration(decorators, modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6508,8 +6486,6 @@ namespace ts { function tryParseConstructorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): ConstructorDeclaration | undefined { return tryParse(() => { if (parseConstructorName()) { - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(/*val*/ false); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6518,7 +6494,6 @@ namespace ts { // Attach `typeParameters` and `type` if they exist so that we can report them in the grammar checker. node.typeParameters = typeParameters; node.type = type; - setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } }); @@ -6535,8 +6510,6 @@ namespace ts { exclamationToken: ExclamationToken | undefined, diagnosticMessage?: DiagnosticMessage ): MethodDeclaration { - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(/*val*/ false); const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; const isAsync = some(modifiers, isAsyncModifier) ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); @@ -6556,7 +6529,6 @@ namespace ts { ); // An exclamation token on a method is invalid syntax and will be handled by the grammar checker node.exclamationToken = exclamationToken; - setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6568,14 +6540,11 @@ namespace ts { name: PropertyName, questionToken: QuestionToken | undefined ): PropertyDeclaration { - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(/*val*/ false); const exclamationToken = !questionToken && !scanner.hasPrecedingLineBreak() ? parseOptionalToken(SyntaxKind.ExclamationToken) : undefined; const type = parseTypeAnnotation(); const initializer = doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext | NodeFlags.DisallowInContext, parseInitializer); parseSemicolon(); const node = factory.createPropertyDeclaration(decorators, modifiers, name, questionToken || exclamationToken, type, initializer); - setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6598,8 +6567,6 @@ namespace ts { function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration { const name = parsePropertyName(); - const savedClassStaticBlockContext = inClassStaticBlockContext(); - setClassStaticBlockContext(/*val*/ false); const typeParameters = parseTypeParameters(); const parameters = parseParameters(SignatureFlags.None); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); @@ -6610,7 +6577,6 @@ namespace ts { // Keep track of `typeParameters` (for both) and `type` (for setters) if they were parsed those indicate grammar errors node.typeParameters = typeParameters; if (type && node.kind === SyntaxKind.SetAccessor) (node as Mutable).type = type; - setClassStaticBlockContext(savedClassStaticBlockContext); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6690,11 +6656,18 @@ namespace ts { } function parseClassStaticBlockBody() { - return doOutsideYieldContext(() => { - return doInsideOfContext(NodeFlags.AwaitContext | NodeFlags.ClassStaticBlockContext, () => { - return parseBlock(/*ignoreMissingOpenBrace*/ false); - }); - }); + const savedYieldContext = inYieldContext(); + const savedAwaitContext = inAwaitContext(); + + setYieldContext(false); + setAwaitContext(true); + + const body = parseBlock(/*ignoreMissingOpenBrace*/ false); + + setYieldContext(savedYieldContext); + setAwaitContext(savedAwaitContext); + + return body; } function parseDecoratorExpression() { diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 5e9c1d311a92a..b899cf0991ea4 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -342,10 +342,14 @@ 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, or(isStaticPropertyDeclaration, isClassStaticBlockDeclaration)) as (PropertyDeclaration | ClassStaticBlockDeclaration)[]; + return filter(node.members, isStaticPropertyDeclarationOrClassStaticBlockDeclaration); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 06018a88eacfb..4b9c9e42f9e93 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -775,7 +775,6 @@ namespace ts { JsonFile = 1 << 25, // If node was parsed in a Json /* @internal */ TypeCached = 1 << 26, // If a type was cached for node at any point /* @internal */ Deprecated = 1 << 27, // If has '@deprecated' JSDoc tag - ClassStaticBlockContext = 1 << 28, // If node was parsed in the 'class static block' and not in another function boundary. BlockScoped = Let | Const, @@ -783,10 +782,10 @@ namespace ts { ReachabilityAndEmitFlags = ReachabilityCheckFlags | HasAsyncFunctions, // Parsing context flags - ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | ClassStaticBlockContext | JavaScriptFile | InWithStatement | Ambient, + ContextFlags = DisallowInContext | YieldContext | DecoratorContext | AwaitContext | JavaScriptFile | InWithStatement | Ambient, // Exclude these flags when parsing a Type - TypeExcludesFlags = YieldContext | AwaitContext | ClassStaticBlockContext, + TypeExcludesFlags = YieldContext | AwaitContext, // Represents all flags that are potentially set once and // never cleared on SourceFiles which get re-used in between incremental parses. diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 24ce2db5f6950..956f1fd10931c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1582,6 +1582,10 @@ namespace ts { }); } + 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) { diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 4a9707b939698..f7ce080a5268e 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1227,7 +1227,8 @@ namespace ts { return !!node && isFunctionLikeKind(node.kind); } - export function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration) { + /* @internal */ + export function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is SignatureDeclaration | ClassStaticBlockDeclaration { return !!node && (isFunctionLikeKind(node.kind) || isClassStaticBlockDeclaration(node)); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 94b24db6b1920..124ef7a8d8416 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -522,12 +522,11 @@ declare namespace ts { HasAggregatedChildData = 524288, JSDoc = 4194304, JsonFile = 33554432, - ClassStaticBlockContext = 268435456, BlockScoped = 3, ReachabilityCheckFlags = 768, ReachabilityAndEmitFlags = 2816, - ContextFlags = 293793792, - TypeExcludesFlags = 268476416, + ContextFlags = 25358336, + TypeExcludesFlags = 40960, } export enum ModifierFlags { None = 0, @@ -4322,7 +4321,6 @@ declare namespace ts { function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; - function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration); function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 6ed093004bea2..56a67b384c838 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -522,12 +522,11 @@ declare namespace ts { HasAggregatedChildData = 524288, JSDoc = 4194304, JsonFile = 33554432, - ClassStaticBlockContext = 268435456, BlockScoped = 3, ReachabilityCheckFlags = 768, ReachabilityAndEmitFlags = 2816, - ContextFlags = 293793792, - TypeExcludesFlags = 268476416, + ContextFlags = 25358336, + TypeExcludesFlags = 40960, } export enum ModifierFlags { None = 0, @@ -4322,7 +4321,6 @@ declare namespace ts { function isPropertyName(node: Node): node is PropertyName; function isBindingName(node: Node): node is BindingName; function isFunctionLike(node: Node | undefined): node is SignatureDeclaration; - function isFunctionLikeOrClassStaticBlockDeclaration(node: Node | undefined): node is (SignatureDeclaration | ClassStaticBlockDeclaration); function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt index 0c730a6bea832..1ba3e17f28712 100644 --- a/tests/baselines/reference/classStaticBlock7.errors.txt +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -1,7 +1,6 @@ error TS2318: Cannot find global type 'IterableIterator'. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS18037: Await expression cannot be used inside 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 TS1108: A 'return' statement can only be used within a function body. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(5,9): error TS18041: A 'return' statement cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(12,13): error TS18037: Await expression cannot be used inside class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(14,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. @@ -12,7 +11,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er !!! error TS2318: Cannot find global type 'IterableIterator'. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (10 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (9 errors) ==== class C { static { await 1; @@ -23,8 +22,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er !!! error TS1163: A 'yield' expression is only allowed in a generator body. return 1; ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. - ~~~~~~ !!! error TS18041: A 'return' statement cannot be used inside class static block. } } From 7fb981dcf5942e8118a67cdb4e9566ca6492dead Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 13:00:20 +0800 Subject: [PATCH 24/36] Update diagnostic message --- src/compiler/checker.ts | 6 ++-- src/compiler/diagnosticMessages.json | 8 ++--- .../reference/classStaticBlock22.errors.txt | 32 +++++++++---------- .../reference/classStaticBlock23.errors.txt | 8 ++--- .../reference/classStaticBlock6.errors.txt | 12 +++---- .../reference/classStaticBlock7.errors.txt | 16 +++++----- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b0c7d81b9fc6..44269743873f3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31307,7 +31307,7 @@ namespace ts { } } else if (containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { - error(node, Diagnostics.Await_expression_cannot_be_used_inside_class_static_block); + error(node, Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block); } if (isInParameterInitializerBeforeContainingFunction(node)) { @@ -35890,7 +35890,7 @@ namespace ts { const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); if (node.awaitModifier) { if (containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { - grammarErrorOnNode(node.awaitModifier, Diagnostics.For_await_loops_cannot_be_used_inside_class_static_block); + grammarErrorOnNode(node.awaitModifier, Diagnostics.For_await_loops_cannot_be_used_inside_a_class_static_block); } else { const functionFlags = getFunctionFlags(containingFunctionOrClassStaticBlock); @@ -36779,7 +36779,7 @@ namespace ts { const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); if(containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { - grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_cannot_be_used_inside_class_static_block); + grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block); return; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 00dd7e884aab0..ac42b13400b99 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -7155,19 +7155,19 @@ "category": "Error", "code": 18036 }, - "Await expression cannot be used inside class static block.": { + "Await expression cannot be used inside a class static block.": { "category": "Error", "code": 18037 }, - "'For await' loops cannot be used inside class static block.": { + "'For await' loops cannot be used inside a class static block.": { "category": "Error", "code": 18038 }, - "Invalid use of '{0}'. It cannot be used inside class static block.": { + "Invalid use of '{0}'. It cannot be used inside a class static block.": { "category": "Error", "code": 18039 }, - "A 'return' statement cannot be used inside class static block.": { + "A 'return' statement cannot be used inside a class static block.": { "category": "Error", "code": 18041 } diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt index fdf1531f7d647..8a12b3ffe84cd 100644 --- a/tests/baselines/reference/classStaticBlock22.errors.txt +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -1,20 +1,20 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,10): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(28,14): error TS1005: ':' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,14): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,10): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,10): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,15): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,10): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS1003: Identifier expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,20): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,17): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,17): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,22): error TS1109: Expression expected. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,24): error TS1005: ';' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,17): error TS18037: Await expression cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,17): error TS18037: Await expression cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): error TS1109: Expression expected. @@ -36,14 +36,14 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e static { await; // illegal ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! 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 class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. } static { function await() {}; // illegal @@ -59,7 +59,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e static { ({ [await]: 1 }); // illegal ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~ !!! error TS1109: Expression expected. } @@ -69,7 +69,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e x = await; // legal (initializers have an implicit function boundary) [await] = 1; // illegal (computed property names are evaluated outside of a class body ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~ !!! error TS1109: Expression expected. }; @@ -89,14 +89,14 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e static { await: // illegal, 'await' cannot be used as a label ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! 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 class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~ !!! error TS1109: Expression expected. } @@ -133,14 +133,14 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e function f (await) {} const ff = (await) => {} ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! 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 class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~~ !!! error TS1109: Expression expected. } diff --git a/tests/baselines/reference/classStaticBlock23.errors.txt b/tests/baselines/reference/classStaticBlock23.errors.txt index c540340187491..eee258b4a5b12 100644 --- a/tests/baselines/reference/classStaticBlock23.errors.txt +++ b/tests/baselines/reference/classStaticBlock23.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(5,9): error TS18038: 'For await' loops cannot be used inside class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(14,11): error TS18038: 'For await' loops cannot be used inside class static block. +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) ==== @@ -9,7 +9,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(14,11): e static { for await (const nn of nums) { ~~~~~ -!!! error TS18038: 'For await' loops cannot be used inside class static block. +!!! error TS18038: 'For await' loops cannot be used inside a class static block. console.log(nn) } } @@ -20,7 +20,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts(14,11): e static { for await (const nn of nums) { ~~~~~ -!!! error TS18038: 'For await' loops cannot be used inside class static block. +!!! error TS18038: 'For await' loops cannot be used inside a class static block. console.log(nn) } } diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 9345c112f9fa3..89422160b8066 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -1,14 +1,14 @@ 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 class static block. +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 class static block. +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 class static block. +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(44,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. 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. @@ -36,7 +36,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er static { await: if (true) { ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~ !!! error TS1109: Expression expected. @@ -47,7 +47,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er !!! error TS2662: Cannot find name 'arguments'. Did you mean the static member 'C.arguments'? await; ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~ !!! error TS1109: Expression expected. super(); @@ -81,7 +81,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er !!! error TS2815: 'arguments' cannot be referenced in property initializers. await; ~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. ~ !!! error TS1109: Expression expected. diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt index 1ba3e17f28712..78b17ebac7861 100644 --- a/tests/baselines/reference/classStaticBlock7.errors.txt +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -1,12 +1,12 @@ error TS2318: Cannot find global type 'IterableIterator'. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): error TS18037: Await expression cannot be used inside class static block. +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 class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(12,13): error TS18037: Await expression cannot be used inside class static block. +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(14,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. 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(26,24): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(36,13): error TS18041: A 'return' statement cannot be used inside class static block. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(36,13): error TS18041: A 'return' statement cannot be used inside a class static block. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. @@ -16,13 +16,13 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er static { await 1; ~~~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! 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 class static block. +!!! error TS18041: A 'return' statement cannot be used inside a class static block. } } @@ -31,7 +31,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er static { await 1; ~~~~~~~ -!!! error TS18037: Await expression cannot be used inside class static block. +!!! error TS18037: Await expression cannot be used inside a class static block. async function ff () { ~~ @@ -63,7 +63,7 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er static { return 1; ~~~~~~ -!!! error TS18041: A 'return' statement cannot be used inside class static block. +!!! error TS18041: A 'return' statement cannot be used inside a class static block. function ff () { ~~ From dabdce698b8a0b347292585062bdd670600f5322 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 13:58:43 +0800 Subject: [PATCH 25/36] Fix name collision --- src/compiler/binder.ts | 2 +- src/compiler/transformers/classFields.ts | 8 +++++++- src/compiler/utilities.ts | 5 +++-- src/compiler/utilitiesPublic.ts | 1 + .../baselines/reference/classStaticBlock1(target=es5).js | 4 ++-- .../reference/classStaticBlock10(target=es5).js | 8 ++++---- .../reference/classStaticBlock18(target=es2015).js | 9 +++++---- .../reference/classStaticBlock18(target=es5).js | 9 +++++---- .../baselines/reference/classStaticBlock2(target=es5).js | 8 ++++---- tests/baselines/reference/classStaticBlock6.js | 8 ++++---- 10 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5b3bfe991e328..da8132511a375 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2714,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/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 55e01a8e76891..b2f5a77e52e57 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; @@ -544,7 +545,12 @@ namespace ts { function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { receiver = visitNode(receiver, visitor, isExpression); - const right = factory.createImmediatelyInvokedArrowFunction(visitNode(node.body, visitor, isBlock).statements); + + startLexicalEnvironment(); + let statements = visitNodes(node.body.statements, visitor, isStatement); + statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); + + const right = factory.createImmediatelyInvokedArrowFunction(statements); const name = createHoistedVariableForClass("_", node); return createPrivateStaticFieldInitializer( name, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 956f1fd10931c..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; diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index f7ce080a5268e..5e4b8b4275f91 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1689,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/tests/baselines/reference/classStaticBlock1(target=es5).js b/tests/baselines/reference/classStaticBlock1(target=es5).js index 49d1101127ad4..42e28966b754e 100644 --- a/tests/baselines/reference/classStaticBlock1(target=es5).js +++ b/tests/baselines/reference/classStaticBlock1(target=es5).js @@ -19,6 +19,6 @@ var C = /** @class */ (function () { return C; }()); _C__ = { value: (function () { - var a_1 = 1; - a_1; + var a = 1; + a; })() }; diff --git a/tests/baselines/reference/classStaticBlock10(target=es5).js b/tests/baselines/reference/classStaticBlock10(target=es5).js index 73626c52f89ef..3bb0f9c64b172 100644 --- a/tests/baselines/reference/classStaticBlock10(target=es5).js +++ b/tests/baselines/reference/classStaticBlock10(target=es5).js @@ -45,8 +45,8 @@ function f() { _C1__ = { value: (function () { var a1 = 111; var a2 = 111; - var b1_1 = 222; - var b2_1 = 222; + var b1 = 222; + var b2 = 222; })() }; } var C2 = /** @class */ (function () { @@ -57,6 +57,6 @@ var C2 = /** @class */ (function () { _C2__ = { value: (function () { var a1 = 111; var a2 = 111; - var b1_2 = 222; - var b2_2 = 222; + var b1 = 222; + var b2 = 222; })() }; diff --git a/tests/baselines/reference/classStaticBlock18(target=es2015).js b/tests/baselines/reference/classStaticBlock18(target=es2015).js index ac0a8ddc726a4..a2de9bb8ce76b 100644 --- a/tests/baselines/reference/classStaticBlock18(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock18(target=es2015).js @@ -16,18 +16,19 @@ function foo () { //// [classStaticBlock18.js] function foo() { - var _a, _b, _c__, __; + var _a, __; return _a = class { }, _a.foo = 1, __ = { value: (() => { - const c = (_b = class { + var _a, _c__; + const c = (_a = class { }, - _b.bar = 2, + _a.bar = 2, _c__ = { value: (() => { // do })() }, - _b); + _a); })() }, _a; } diff --git a/tests/baselines/reference/classStaticBlock18(target=es5).js b/tests/baselines/reference/classStaticBlock18(target=es5).js index 093ed790b745f..8a4714ccb4a95 100644 --- a/tests/baselines/reference/classStaticBlock18(target=es5).js +++ b/tests/baselines/reference/classStaticBlock18(target=es5).js @@ -16,7 +16,7 @@ function foo () { //// [classStaticBlock18.js] function foo() { - var _a, _b, _c__, __; + var _a, __; return _a = /** @class */ (function () { function class_1() { } @@ -24,16 +24,17 @@ function foo() { }()), _a.foo = 1, __ = { value: (function () { - var c_1 = (_b = /** @class */ (function () { + var _a, _c__; + var c = (_a = /** @class */ (function () { function class_2() { } return class_2; }()), - _b.bar = 2, + _a.bar = 2, _c__ = { value: (function () { // do })() }, - _b); + _a); })() }, _a; } diff --git a/tests/baselines/reference/classStaticBlock2(target=es5).js b/tests/baselines/reference/classStaticBlock2(target=es5).js index 0a81e444d8148..23c52b9511b3e 100644 --- a/tests/baselines/reference/classStaticBlock2(target=es5).js +++ b/tests/baselines/reference/classStaticBlock2(target=es5).js @@ -29,12 +29,12 @@ var C = /** @class */ (function () { return C; }()); _C__ = { value: (function () { - var a_1 = 11; - a_1; + var a = 11; + a; b; })() }; _C__1 = { value: (function () { - var a_2 = 11; - a_2; + var a = 11; + a; b; })() }; diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index 3ad0d38a199c9..4935e1e195e63 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -130,9 +130,9 @@ var C = /** @class */ (function (_super) { return C; }(B)); _C__ = { value: (function () { - var await_1 = 1; - var arguments_1 = 1; - var eval_1 = 1; + var await = 1; + var arguments = 1; + var eval = 1; })() }; _C__1 = { value: (function () { yield ; @@ -153,7 +153,7 @@ var CC = /** @class */ (function () { return C; }(B)); _C__2 = { value: (function () { - var CC_1 = /** @class */ (function (_super) { + var CC = /** @class */ (function (_super) { __extends(CC, _super); function CC() { return _super.call(this) || this; From 4f54d717987c236762c8dcd937b540554ba383ef Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 14:04:33 +0800 Subject: [PATCH 26/36] Fix targets --- .../reference/classStaticBlock12.errors.txt | 14 ----- .../baselines/reference/classStaticBlock12.js | 19 +++---- .../reference/classStaticBlock14.errors.txt | 25 --------- .../baselines/reference/classStaticBlock14.js | 41 +++++++------- .../classStaticBlock3(target=es2015).js | 34 ------------ .../classStaticBlock3(target=es5).errors.txt | 33 ----------- .../classStaticBlock3(target=es5).js | 37 ------------- .../classStaticBlock3(target=es5).symbols | 49 ----------------- .../classStaticBlock3(target=es5).types | 55 ------------------- ...lassStaticBlock3(target=esnext).errors.txt | 33 ----------- .../classStaticBlock3(target=esnext).symbols | 49 ----------------- .../classStaticBlock3(target=esnext).types | 55 ------------------- ...rrors.txt => classStaticBlock3.errors.txt} | 0 ...target=esnext).js => classStaticBlock3.js} | 0 ...015).symbols => classStaticBlock3.symbols} | 0 ...=es2015).types => classStaticBlock3.types} | 0 ...lassStaticBlock4(target=es2015).errors.txt | 31 ----------- .../classStaticBlock4(target=es2015).js | 30 ---------- .../classStaticBlock4(target=es5).errors.txt | 31 ----------- .../classStaticBlock4(target=es5).js | 34 ------------ .../classStaticBlock4(target=es5).symbols | 35 ------------ .../classStaticBlock4(target=es5).types | 41 -------------- .../classStaticBlock4(target=esnext).symbols | 35 ------------ .../classStaticBlock4(target=esnext).types | 41 -------------- ...rrors.txt => classStaticBlock4.errors.txt} | 0 ...target=esnext).js => classStaticBlock4.js} | 0 ...015).symbols => classStaticBlock4.symbols} | 0 ...=es2015).types => classStaticBlock4.types} | 0 .../classStaticBlock/classStaticBlock11.ts | 2 +- .../classStaticBlock/classStaticBlock12.ts | 1 + .../classStaticBlock/classStaticBlock13.ts | 2 +- .../classStaticBlock/classStaticBlock14.ts | 1 + .../classStaticBlock/classStaticBlock15.ts | 2 +- .../classStaticBlock/classStaticBlock3.ts | 2 +- .../classStaticBlock/classStaticBlock4.ts | 2 +- 35 files changed, 34 insertions(+), 700 deletions(-) delete mode 100644 tests/baselines/reference/classStaticBlock12.errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock14.errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock3(target=es2015).js delete mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).js delete mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).symbols delete mode 100644 tests/baselines/reference/classStaticBlock3(target=es5).types delete mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).symbols delete mode 100644 tests/baselines/reference/classStaticBlock3(target=esnext).types rename tests/baselines/reference/{classStaticBlock3(target=es2015).errors.txt => classStaticBlock3.errors.txt} (100%) rename tests/baselines/reference/{classStaticBlock3(target=esnext).js => classStaticBlock3.js} (100%) rename tests/baselines/reference/{classStaticBlock3(target=es2015).symbols => classStaticBlock3.symbols} (100%) rename tests/baselines/reference/{classStaticBlock3(target=es2015).types => classStaticBlock3.types} (100%) delete mode 100644 tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock4(target=es2015).js delete mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).js delete mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).symbols delete mode 100644 tests/baselines/reference/classStaticBlock4(target=es5).types delete mode 100644 tests/baselines/reference/classStaticBlock4(target=esnext).symbols delete mode 100644 tests/baselines/reference/classStaticBlock4(target=esnext).types rename tests/baselines/reference/{classStaticBlock4(target=esnext).errors.txt => classStaticBlock4.errors.txt} (100%) rename tests/baselines/reference/{classStaticBlock4(target=esnext).js => classStaticBlock4.js} (100%) rename tests/baselines/reference/{classStaticBlock4(target=es2015).symbols => classStaticBlock4.symbols} (100%) rename tests/baselines/reference/{classStaticBlock4(target=es2015).types => classStaticBlock4.types} (100%) diff --git a/tests/baselines/reference/classStaticBlock12.errors.txt b/tests/baselines/reference/classStaticBlock12.errors.txt deleted file mode 100644 index d4535ca1542bd..0000000000000 --- a/tests/baselines/reference/classStaticBlock12.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts (1 errors) ==== - class C { - static #x = 1; - ~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - static { - C.#x; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock12.js b/tests/baselines/reference/classStaticBlock12.js index fd85eadf08087..42c7d06abd69d 100644 --- a/tests/baselines/reference/classStaticBlock12.js +++ b/tests/baselines/reference/classStaticBlock12.js @@ -14,14 +14,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( 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 = /** @class */ (function () { - function C() { - } - var _a, _C_x, _C__; - _a = C; - _C_x = { value: 1 }; - _C__ = { value: (function () { - __classPrivateFieldGet(C, _a, "f", _C_x); - })() }; - return C; -}()); +var _a, _C_x, _C__; +class C { +} +_a = C; +_C_x = { value: 1 }; +_C__ = { value: (() => { + __classPrivateFieldGet(C, _a, "f", _C_x); + })() }; diff --git a/tests/baselines/reference/classStaticBlock14.errors.txt b/tests/baselines/reference/classStaticBlock14.errors.txt deleted file mode 100644 index e88e1244dd6df..0000000000000 --- a/tests/baselines/reference/classStaticBlock14.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts(3,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts(4,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts (3 errors) ==== - class C { - static #_1 = 1; - ~~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - static #_3 = 1; - ~~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - static #_5 = 1; - ~~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - static {} - static {} - static {} - static {} - static {} - static {} - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock14.js b/tests/baselines/reference/classStaticBlock14.js index 4420febdac50f..a68bf8cfd6061 100644 --- a/tests/baselines/reference/classStaticBlock14.js +++ b/tests/baselines/reference/classStaticBlock14.js @@ -14,25 +14,22 @@ class C { //// [classStaticBlock14.js] -var C = /** @class */ (function () { - function C() { - } - var _a, _C__1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; - _a = C; - _C__1 = { value: 1 }; - _C__3 = { value: 1 }; - _C__5 = { value: 1 }; - _C__ = { value: (function () { - })() }; - _C__2 = { value: (function () { - })() }; - _C__4 = { value: (function () { - })() }; - _C__6 = { value: (function () { - })() }; - _C__7 = { value: (function () { - })() }; - _C__8 = { value: (function () { - })() }; - return C; -}()); +var _a, _C__1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; +class C { +} +_a = C; +_C__1 = { value: 1 }; +_C__3 = { value: 1 }; +_C__5 = { value: 1 }; +_C__ = { value: (() => { + })() }; +_C__2 = { value: (() => { + })() }; +_C__4 = { value: (() => { + })() }; +_C__6 = { value: (() => { + })() }; +_C__7 = { value: (() => { + })() }; +_C__8 = { value: (() => { + })() }; diff --git a/tests/baselines/reference/classStaticBlock3(target=es2015).js b/tests/baselines/reference/classStaticBlock3(target=es2015).js deleted file mode 100644 index 722aa49d56081..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=es2015).js +++ /dev/null @@ -1,34 +0,0 @@ -//// [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] -var _C__, _C__1; -const a = 1; -class C { -} -C.f1 = 1; -_C__ = { value: (() => { - console.log(C.f1, C.f2, C.f3); - })() }; -C.f2 = 2; -_C__1 = { value: (() => { - console.log(C.f1, C.f2, C.f3); - })() }; -C.f3 = 3; diff --git a/tests/baselines/reference/classStaticBlock3(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock3(target=es5).errors.txt deleted file mode 100644 index bf01354e1405f..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=es5).errors.txt +++ /dev/null @@ -1,33 +0,0 @@ -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(target=es5).js b/tests/baselines/reference/classStaticBlock3(target=es5).js deleted file mode 100644 index 7c7d46731880d..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=es5).js +++ /dev/null @@ -1,37 +0,0 @@ -//// [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] -var a = 1; -var C = /** @class */ (function () { - function C() { - } - var _C__, _C__1; - C.f1 = 1; - _C__ = { value: (function () { - console.log(C.f1, C.f2, C.f3); - })() }; - C.f2 = 2; - _C__1 = { value: (function () { - console.log(C.f1, C.f2, C.f3); - })() }; - C.f3 = 3; - return C; -}()); diff --git a/tests/baselines/reference/classStaticBlock3(target=es5).symbols b/tests/baselines/reference/classStaticBlock3(target=es5).symbols deleted file mode 100644 index 758fa0790609a..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=es5).symbols +++ /dev/null @@ -1,49 +0,0 @@ -=== 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(target=es5).types b/tests/baselines/reference/classStaticBlock3(target=es5).types deleted file mode 100644 index d5705a72e8775..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=es5).types +++ /dev/null @@ -1,55 +0,0 @@ -=== 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/classStaticBlock3(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock3(target=esnext).errors.txt deleted file mode 100644 index bf01354e1405f..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=esnext).errors.txt +++ /dev/null @@ -1,33 +0,0 @@ -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(target=esnext).symbols b/tests/baselines/reference/classStaticBlock3(target=esnext).symbols deleted file mode 100644 index 758fa0790609a..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=esnext).symbols +++ /dev/null @@ -1,49 +0,0 @@ -=== 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(target=esnext).types b/tests/baselines/reference/classStaticBlock3(target=esnext).types deleted file mode 100644 index d5705a72e8775..0000000000000 --- a/tests/baselines/reference/classStaticBlock3(target=esnext).types +++ /dev/null @@ -1,55 +0,0 @@ -=== 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/classStaticBlock3(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock3.errors.txt similarity index 100% rename from tests/baselines/reference/classStaticBlock3(target=es2015).errors.txt rename to tests/baselines/reference/classStaticBlock3.errors.txt diff --git a/tests/baselines/reference/classStaticBlock3(target=esnext).js b/tests/baselines/reference/classStaticBlock3.js similarity index 100% rename from tests/baselines/reference/classStaticBlock3(target=esnext).js rename to tests/baselines/reference/classStaticBlock3.js diff --git a/tests/baselines/reference/classStaticBlock3(target=es2015).symbols b/tests/baselines/reference/classStaticBlock3.symbols similarity index 100% rename from tests/baselines/reference/classStaticBlock3(target=es2015).symbols rename to tests/baselines/reference/classStaticBlock3.symbols diff --git a/tests/baselines/reference/classStaticBlock3(target=es2015).types b/tests/baselines/reference/classStaticBlock3.types similarity index 100% rename from tests/baselines/reference/classStaticBlock3(target=es2015).types rename to tests/baselines/reference/classStaticBlock3.types diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt deleted file mode 100644 index b85180f1df07d..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=es2015).errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? -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(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (4 errors) ==== - class C { - static s1 = 1; - - static { - this.s1; - ~~ -!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? - C.s1; - - this.s2; - ~~ -!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? - 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; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).js b/tests/baselines/reference/classStaticBlock4(target=es2015).js deleted file mode 100644 index 6a49dac60142a..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=es2015).js +++ /dev/null @@ -1,30 +0,0 @@ -//// [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] -var _C__; -class C { -} -C.s1 = 1; -_C__ = { value: (() => { - this.s1; - C.s1; - this.s2; - C.s2; - })() }; -C.s2 = 2; -C.ss2 = this.s1; diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt deleted file mode 100644 index b85180f1df07d..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=es5).errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? -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(13,18): error TS2334: 'this' cannot be referenced in a static property initializer. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (4 errors) ==== - class C { - static s1 = 1; - - static { - this.s1; - ~~ -!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? - C.s1; - - this.s2; - ~~ -!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? - 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; - ~~~~ -!!! error TS2334: 'this' cannot be referenced in a static property initializer. - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).js b/tests/baselines/reference/classStaticBlock4(target=es5).js deleted file mode 100644 index 1c11c48e32729..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=es5).js +++ /dev/null @@ -1,34 +0,0 @@ -//// [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] -var _this = this; -var C = /** @class */ (function () { - function C() { - } - var _C__; - C.s1 = 1; - _C__ = { value: (function () { - _this.s1; - C.s1; - _this.s2; - C.s2; - })() }; - C.s2 = 2; - C.ss2 = this.s1; - return C; -}()); diff --git a/tests/baselines/reference/classStaticBlock4(target=es5).symbols b/tests/baselines/reference/classStaticBlock4(target=es5).symbols deleted file mode 100644 index 5b812c63d7121..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=es5).symbols +++ /dev/null @@ -1,35 +0,0 @@ -=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) - - 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) - - 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(target=es5).types b/tests/baselines/reference/classStaticBlock4(target=es5).types deleted file mode 100644 index 91d7ba0613136..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=es5).types +++ /dev/null @@ -1,41 +0,0 @@ -=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts === -class C { ->C : C - - static s1 = 1; ->s1 : number ->1 : 1 - - static { - this.s1; ->this.s1 : any ->this : this ->s1 : any - - C.s1; ->C.s1 : number ->C : typeof C ->s1 : number - - this.s2; ->this.s2 : any ->this : this ->s2 : any - - 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/classStaticBlock4(target=esnext).symbols b/tests/baselines/reference/classStaticBlock4(target=esnext).symbols deleted file mode 100644 index 5b812c63d7121..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=esnext).symbols +++ /dev/null @@ -1,35 +0,0 @@ -=== 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) - - 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 : Symbol(C, Decl(classStaticBlock4.ts, 0, 0)) - - 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(target=esnext).types b/tests/baselines/reference/classStaticBlock4(target=esnext).types deleted file mode 100644 index 91d7ba0613136..0000000000000 --- a/tests/baselines/reference/classStaticBlock4(target=esnext).types +++ /dev/null @@ -1,41 +0,0 @@ -=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts === -class C { ->C : C - - static s1 = 1; ->s1 : number ->1 : 1 - - static { - this.s1; ->this.s1 : any ->this : this ->s1 : any - - C.s1; ->C.s1 : number ->C : typeof C ->s1 : number - - this.s2; ->this.s2 : any ->this : this ->s2 : any - - 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/classStaticBlock4(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock4.errors.txt similarity index 100% rename from tests/baselines/reference/classStaticBlock4(target=esnext).errors.txt rename to tests/baselines/reference/classStaticBlock4.errors.txt diff --git a/tests/baselines/reference/classStaticBlock4(target=esnext).js b/tests/baselines/reference/classStaticBlock4.js similarity index 100% rename from tests/baselines/reference/classStaticBlock4(target=esnext).js rename to tests/baselines/reference/classStaticBlock4.js diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).symbols b/tests/baselines/reference/classStaticBlock4.symbols similarity index 100% rename from tests/baselines/reference/classStaticBlock4(target=es2015).symbols rename to tests/baselines/reference/classStaticBlock4.symbols diff --git a/tests/baselines/reference/classStaticBlock4(target=es2015).types b/tests/baselines/reference/classStaticBlock4.types similarity index 100% rename from tests/baselines/reference/classStaticBlock4(target=es2015).types rename to tests/baselines/reference/classStaticBlock4.types diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts index 73786b4e0d29d..685d870cceb09 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts @@ -1,4 +1,4 @@ -// @target: esnext, es2015, es5 +// @target: esnext, es2015 let getX; class C { diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts index 2071f21c5d92b..436c690665368 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock12.ts @@ -1,4 +1,5 @@ // @useDefineForClassFields: false +// @target: es2015 class C { static #x = 1; diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts index 6b05c3e0df50d..8120cc3575cb3 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts @@ -1,4 +1,4 @@ -// @target: esnext, es2015, es5 +// @target: esnext, es2015 // @useDefineForClassFields: true class C { diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts index c5e4f30e02dd9..ff510c843657a 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock14.ts @@ -1,4 +1,5 @@ // @useDefineForClassFields: false +// @target: es2015 class C { static #_1 = 1; diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts index c7d5c2da04ffa..c21b31e04fc94 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts @@ -1,4 +1,4 @@ -// @target: esnext, es2015, es5 +// @target: esnext, es2015 // @useDefineForClassFields: true class C { diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts index f34912cb5b650..84125fdbed75a 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock3.ts @@ -1,4 +1,4 @@ -// @target: esnext, es2015, es5 +// @target: esnext const a = 1; diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts index 2b8696fe08d5d..7a944a496911f 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts @@ -1,4 +1,4 @@ -// @target: esnext, es2015, es5 +// @target: esnext class C { static s1 = 1; From 1b33a048def9fbe87f04a9490c68e06aa65549f7 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 14:12:16 +0800 Subject: [PATCH 27/36] Avoid unnecessary files --- .../classStaticBlock11(target=es5).errors.txt | 19 --------- .../classStaticBlock11(target=es5).js | 41 ------------------- .../classStaticBlock11(target=es5).symbols | 30 -------------- .../classStaticBlock11(target=es5).types | 33 --------------- .../classStaticBlock13(target=es5).errors.txt | 18 -------- .../classStaticBlock13(target=es5).js | 39 ------------------ .../classStaticBlock13(target=es5).symbols | 25 ----------- .../classStaticBlock13(target=es5).types | 27 ------------ ...assStaticBlock15(target=es2015).errors.txt | 21 ---------- .../classStaticBlock15(target=es2015).js | 3 ++ .../classStaticBlock15(target=es2015).symbols | 12 ++++-- .../classStaticBlock15(target=es2015).types | 3 ++ .../classStaticBlock15(target=es5).errors.txt | 30 -------------- .../classStaticBlock15(target=es5).js | 41 ------------------- .../classStaticBlock15(target=es5).symbols | 26 ------------ .../classStaticBlock15(target=es5).types | 31 -------------- ...assStaticBlock15(target=esnext).errors.txt | 21 ---------- .../classStaticBlock15(target=esnext).js | 3 ++ .../classStaticBlock15(target=esnext).symbols | 12 ++++-- .../classStaticBlock15(target=esnext).types | 3 ++ .../classStaticBlock/classStaticBlock15.ts | 1 + 21 files changed, 29 insertions(+), 410 deletions(-) delete mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).js delete mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).symbols delete mode 100644 tests/baselines/reference/classStaticBlock11(target=es5).types delete mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).js delete mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).symbols delete mode 100644 tests/baselines/reference/classStaticBlock13(target=es5).types delete mode 100644 tests/baselines/reference/classStaticBlock15(target=es2015).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).errors.txt delete mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).js delete mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).symbols delete mode 100644 tests/baselines/reference/classStaticBlock15(target=es5).types delete mode 100644 tests/baselines/reference/classStaticBlock15(target=esnext).errors.txt diff --git a/tests/baselines/reference/classStaticBlock11(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock11(target=es5).errors.txt deleted file mode 100644 index e84ce1a7415b6..0000000000000 --- a/tests/baselines/reference/classStaticBlock11(target=es5).errors.txt +++ /dev/null @@ -1,19 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts(3,3): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock11.ts (1 errors) ==== - let getX; - class C { - #x = 1 - ~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - constructor(x: number) { - this.#x = x; - } - - static { - // getX has privileged access to #x - getX = (obj: C) => obj.#x; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock11(target=es5).js b/tests/baselines/reference/classStaticBlock11(target=es5).js deleted file mode 100644 index fcf8c8f1196fd..0000000000000 --- a/tests/baselines/reference/classStaticBlock11(target=es5).js +++ /dev/null @@ -1,41 +0,0 @@ -//// [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, _C__; -var getX; -var C = /** @class */ (function () { - function C(x) { - _C_x.set(this, 1); - __classPrivateFieldSet(this, _C_x, x, "f"); - } - return C; -}()); -_C_x = new WeakMap(); -_C__ = { value: (function () { - // getX has privileged access to #x - getX = function (obj) { return __classPrivateFieldGet(obj, _C_x, "f"); }; - })() }; diff --git a/tests/baselines/reference/classStaticBlock11(target=es5).symbols b/tests/baselines/reference/classStaticBlock11(target=es5).symbols deleted file mode 100644 index d61ff7c9e16f9..0000000000000 --- a/tests/baselines/reference/classStaticBlock11(target=es5).symbols +++ /dev/null @@ -1,30 +0,0 @@ -=== 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=es5).types b/tests/baselines/reference/classStaticBlock11(target=es5).types deleted file mode 100644 index c295e7b93df36..0000000000000 --- a/tests/baselines/reference/classStaticBlock11(target=es5).types +++ /dev/null @@ -1,33 +0,0 @@ -=== 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/classStaticBlock13(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock13(target=es5).errors.txt deleted file mode 100644 index e0f90aaa81975..0000000000000 --- a/tests/baselines/reference/classStaticBlock13(target=es5).errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock13.ts (1 errors) ==== - class C { - static #x = 123; - ~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - static { - console.log(C.#x) - } - - foo () { - return C.#x; - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock13(target=es5).js b/tests/baselines/reference/classStaticBlock13(target=es5).js deleted file mode 100644 index 25fc0311041a4..0000000000000 --- a/tests/baselines/reference/classStaticBlock13(target=es5).js +++ /dev/null @@ -1,39 +0,0 @@ -//// [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 C = /** @class */ (function () { - function C() { - } - Object.defineProperty(C.prototype, "foo", { - enumerable: false, - configurable: true, - writable: true, - value: function () { - return __classPrivateFieldGet(C, _a, "f", _C_x); - } - }); - var _a, _C_x, _C__; - _a = C; - _C_x = { value: 123 }; - _C__ = { value: (function () { - console.log(__classPrivateFieldGet(C, _a, "f", _C_x)); - })() }; - return C; -}()); diff --git a/tests/baselines/reference/classStaticBlock13(target=es5).symbols b/tests/baselines/reference/classStaticBlock13(target=es5).symbols deleted file mode 100644 index 7f94ddadbe167..0000000000000 --- a/tests/baselines/reference/classStaticBlock13(target=es5).symbols +++ /dev/null @@ -1,25 +0,0 @@ -=== 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=es5).types b/tests/baselines/reference/classStaticBlock13(target=es5).types deleted file mode 100644 index 735409daa5c44..0000000000000 --- a/tests/baselines/reference/classStaticBlock13(target=es5).types +++ /dev/null @@ -1,27 +0,0 @@ -=== 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/classStaticBlock15(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock15(target=es2015).errors.txt deleted file mode 100644 index b922214e105b0..0000000000000 --- a/tests/baselines/reference/classStaticBlock15(target=es2015).errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(14,13): error TS2304: Cannot find name '_C__1'. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts (1 errors) ==== - class C { - static #_1 = 1; - static #_3 = 3; - static #_5 = 5; - - static {} - static {} - static {} - static {} - static {} - static {} - } - - console.log(_C__1) - ~~~~~ -!!! error TS2304: Cannot find name '_C__1'. - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).js b/tests/baselines/reference/classStaticBlock15(target=es2015).js index 739e96ae04142..3c960d8cc6480 100644 --- a/tests/baselines/reference/classStaticBlock15(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).js @@ -1,4 +1,6 @@ //// [classStaticBlock15.ts] +var _C__1; + class C { static #_1 = 1; static #_3 = 3; @@ -17,6 +19,7 @@ console.log(_C__1) //// [classStaticBlock15.js] var _a, _C__1_1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; +var _C__1; class C { } _a = C; diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).symbols b/tests/baselines/reference/classStaticBlock15(target=es2015).symbols index 4d236f95d2e27..12ab9dd68059b 100644 --- a/tests/baselines/reference/classStaticBlock15(target=es2015).symbols +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).symbols @@ -1,15 +1,18 @@ === 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, 0)) +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 10)) static #_1 = 1; ->#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 0, 9)) +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 2, 9)) static #_3 = 3; ->#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 1, 17)) +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 3, 17)) static #_5 = 5; ->#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 2, 17)) +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 4, 17)) static {} static {} @@ -23,4 +26,5 @@ 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 index 8b10940745a8b..262ff1a4c2769 100644 --- a/tests/baselines/reference/classStaticBlock15(target=es2015).types +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).types @@ -1,4 +1,7 @@ === tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +var _C__1; +>_C__1 : any + class C { >C : C diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock15(target=es5).errors.txt deleted file mode 100644 index 1a1e72d9199b3..0000000000000 --- a/tests/baselines/reference/classStaticBlock15(target=es5).errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(2,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(3,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(4,10): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(14,13): error TS2304: Cannot find name '_C__1'. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts (4 errors) ==== - class C { - static #_1 = 1; - ~~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - static #_3 = 3; - ~~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - static #_5 = 5; - ~~~ -!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. - - static {} - static {} - static {} - static {} - static {} - static {} - } - - console.log(_C__1) - ~~~~~ -!!! error TS2304: Cannot find name '_C__1'. - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).js b/tests/baselines/reference/classStaticBlock15(target=es5).js deleted file mode 100644 index 561cb55c53d1b..0000000000000 --- a/tests/baselines/reference/classStaticBlock15(target=es5).js +++ /dev/null @@ -1,41 +0,0 @@ -//// [classStaticBlock15.ts] -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 = /** @class */ (function () { - function C() { - } - var _a, _C__1_1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; - _a = C; - _C__1_1 = { value: 1 }; - _C__3 = { value: 3 }; - _C__5 = { value: 5 }; - _C__ = { value: (function () { - })() }; - _C__2 = { value: (function () { - })() }; - _C__4 = { value: (function () { - })() }; - _C__6 = { value: (function () { - })() }; - _C__7 = { value: (function () { - })() }; - _C__8 = { value: (function () { - })() }; - return C; -}()); -console.log(_C__1); diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).symbols b/tests/baselines/reference/classStaticBlock15(target=es5).symbols deleted file mode 100644 index 4d236f95d2e27..0000000000000 --- a/tests/baselines/reference/classStaticBlock15(target=es5).symbols +++ /dev/null @@ -1,26 +0,0 @@ -=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === -class C { ->C : Symbol(C, Decl(classStaticBlock15.ts, 0, 0)) - - static #_1 = 1; ->#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 0, 9)) - - static #_3 = 3; ->#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 1, 17)) - - static #_5 = 5; ->#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 2, 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, --, --)) - diff --git a/tests/baselines/reference/classStaticBlock15(target=es5).types b/tests/baselines/reference/classStaticBlock15(target=es5).types deleted file mode 100644 index 8b10940745a8b..0000000000000 --- a/tests/baselines/reference/classStaticBlock15(target=es5).types +++ /dev/null @@ -1,31 +0,0 @@ -=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === -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).errors.txt b/tests/baselines/reference/classStaticBlock15(target=esnext).errors.txt deleted file mode 100644 index b922214e105b0..0000000000000 --- a/tests/baselines/reference/classStaticBlock15(target=esnext).errors.txt +++ /dev/null @@ -1,21 +0,0 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts(14,13): error TS2304: Cannot find name '_C__1'. - - -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts (1 errors) ==== - class C { - static #_1 = 1; - static #_3 = 3; - static #_5 = 5; - - static {} - static {} - static {} - static {} - static {} - static {} - } - - console.log(_C__1) - ~~~~~ -!!! error TS2304: Cannot find name '_C__1'. - \ No newline at end of file diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).js b/tests/baselines/reference/classStaticBlock15(target=esnext).js index 43af3a33b22e7..5646a0ef941b3 100644 --- a/tests/baselines/reference/classStaticBlock15(target=esnext).js +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).js @@ -1,4 +1,6 @@ //// [classStaticBlock15.ts] +var _C__1; + class C { static #_1 = 1; static #_3 = 3; @@ -16,6 +18,7 @@ console.log(_C__1) //// [classStaticBlock15.js] +var _C__1; class C { static #_1 = 1; static #_3 = 3; diff --git a/tests/baselines/reference/classStaticBlock15(target=esnext).symbols b/tests/baselines/reference/classStaticBlock15(target=esnext).symbols index 4d236f95d2e27..12ab9dd68059b 100644 --- a/tests/baselines/reference/classStaticBlock15(target=esnext).symbols +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).symbols @@ -1,15 +1,18 @@ === 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, 0)) +>C : Symbol(C, Decl(classStaticBlock15.ts, 0, 10)) static #_1 = 1; ->#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 0, 9)) +>#_1 : Symbol(C.#_1, Decl(classStaticBlock15.ts, 2, 9)) static #_3 = 3; ->#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 1, 17)) +>#_3 : Symbol(C.#_3, Decl(classStaticBlock15.ts, 3, 17)) static #_5 = 5; ->#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 2, 17)) +>#_5 : Symbol(C.#_5, Decl(classStaticBlock15.ts, 4, 17)) static {} static {} @@ -23,4 +26,5 @@ 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 index 8b10940745a8b..262ff1a4c2769 100644 --- a/tests/baselines/reference/classStaticBlock15(target=esnext).types +++ b/tests/baselines/reference/classStaticBlock15(target=esnext).types @@ -1,4 +1,7 @@ === tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts === +var _C__1; +>_C__1 : any + class C { >C : C diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts index c21b31e04fc94..ec2727660f123 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock15.ts @@ -1,5 +1,6 @@ // @target: esnext, es2015 // @useDefineForClassFields: true +var _C__1; class C { static #_1 = 1; From bf776562bcbfac487cd95643cd2c85b03a4c3db0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 14:28:30 +0800 Subject: [PATCH 28/36] Add more case --- .../reference/classStaticBlock8.errors.txt | 15 +++++++ .../baselines/reference/classStaticBlock8.js | 40 +++++++++++++++++- .../reference/classStaticBlock8.symbols | 28 +++++++++++++ .../reference/classStaticBlock8.types | 42 +++++++++++++++++++ .../classStaticBlock/classStaticBlock8.ts | 15 +++++++ 5 files changed, 138 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/classStaticBlock8.errors.txt b/tests/baselines/reference/classStaticBlock8.errors.txt index ec20040143e3c..f98906f4528ef 100644 --- a/tests/baselines/reference/classStaticBlock8.errors.txt +++ b/tests/baselines/reference/classStaticBlock8.errors.txt @@ -45,5 +45,20 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts(15,21): er 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 index 4ba5d2f2aaa4f..2b054c56bcec5 100644 --- a/tests/baselines/reference/classStaticBlock8.js +++ b/tests/baselines/reference/classStaticBlock8.js @@ -31,14 +31,29 @@ function foo (v: number) { 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) { - var _C__; + var _C__, _C__1; label: while (v) { - var C = /** @class */ (function () { + var C_1 = /** @class */ (function () { function C() { } return C; @@ -70,4 +85,25 @@ function foo(v) { continue; } } + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + _C__1 = { value: (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 index 0d0c47c2aa459..5c2eeee615797 100644 --- a/tests/baselines/reference/classStaticBlock8.symbols +++ b/tests/baselines/reference/classStaticBlock8.symbols @@ -54,5 +54,33 @@ function foo (v: number) { 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 index 3c360846b9b1c..7651bd003aa6e 100644 --- a/tests/baselines/reference/classStaticBlock8.types +++ b/tests/baselines/reference/classStaticBlock8.types @@ -75,5 +75,47 @@ function foo (v: number) { 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/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts index c1eb8ef10f16a..d2e5220b834f6 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock8.ts @@ -30,4 +30,19 @@ function foo (v: number) { 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 + } + } + } } From 045a9e85693bbd908cc5682b8bc14e255881203f Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 14:34:13 +0800 Subject: [PATCH 29/36] Add more test cases --- .../classStaticBlock24(module=amd).js | 25 ++++++++++++++ .../classStaticBlock24(module=amd).symbols | 15 +++++++++ .../classStaticBlock24(module=amd).types | 17 ++++++++++ .../classStaticBlock24(module=commonjs).js | 23 +++++++++++++ ...lassStaticBlock24(module=commonjs).symbols | 15 +++++++++ .../classStaticBlock24(module=commonjs).types | 17 ++++++++++ .../classStaticBlock24(module=es2015).js | 20 +++++++++++ .../classStaticBlock24(module=es2015).symbols | 15 +++++++++ .../classStaticBlock24(module=es2015).types | 17 ++++++++++ .../classStaticBlock24(module=es2020).js | 20 +++++++++++ .../classStaticBlock24(module=es2020).symbols | 15 +++++++++ .../classStaticBlock24(module=es2020).types | 17 ++++++++++ .../classStaticBlock24(module=esnext).js | 20 +++++++++++ .../classStaticBlock24(module=esnext).symbols | 15 +++++++++ .../classStaticBlock24(module=esnext).types | 17 ++++++++++ .../classStaticBlock24(module=system).js | 29 ++++++++++++++++ .../classStaticBlock24(module=system).symbols | 15 +++++++++ .../classStaticBlock24(module=system).types | 17 ++++++++++ .../classStaticBlock24(module=umd).js | 33 +++++++++++++++++++ .../classStaticBlock24(module=umd).symbols | 15 +++++++++ .../classStaticBlock24(module=umd).types | 17 ++++++++++ .../classStaticBlock/classStaticBlock24.ts | 8 +++++ 22 files changed, 402 insertions(+) create mode 100644 tests/baselines/reference/classStaticBlock24(module=amd).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=amd).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=amd).types create mode 100644 tests/baselines/reference/classStaticBlock24(module=commonjs).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=commonjs).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=commonjs).types create mode 100644 tests/baselines/reference/classStaticBlock24(module=es2015).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=es2015).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=es2015).types create mode 100644 tests/baselines/reference/classStaticBlock24(module=es2020).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=es2020).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=es2020).types create mode 100644 tests/baselines/reference/classStaticBlock24(module=esnext).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=esnext).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=esnext).types create mode 100644 tests/baselines/reference/classStaticBlock24(module=system).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=system).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=system).types create mode 100644 tests/baselines/reference/classStaticBlock24(module=umd).js create mode 100644 tests/baselines/reference/classStaticBlock24(module=umd).symbols create mode 100644 tests/baselines/reference/classStaticBlock24(module=umd).types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock24.ts diff --git a/tests/baselines/reference/classStaticBlock24(module=amd).js b/tests/baselines/reference/classStaticBlock24(module=amd).js new file mode 100644 index 0000000000000..f1f3cc62c017f --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=amd).js @@ -0,0 +1,25 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var _C__; + exports.__esModule = true; + exports.C = void 0; + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + exports.C = C; + _C__ = { value: (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..850901073da7d --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=commonjs).js @@ -0,0 +1,23 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +"use strict"; +var _C__; +exports.__esModule = true; +exports.C = void 0; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +exports.C = C; +_C__ = { value: (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..60eec043563c3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2015).js @@ -0,0 +1,20 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +var _C__; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +export { C }; +_C__ = { value: (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..60eec043563c3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=es2020).js @@ -0,0 +1,20 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +var _C__; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +export { C }; +_C__ = { value: (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..60eec043563c3 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=esnext).js @@ -0,0 +1,20 @@ +//// [classStaticBlock24.ts] +export class C { + static x: number; + static { + C.x = 1; + } +} + + +//// [classStaticBlock24.js] +var _C__; +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +export { C }; +_C__ = { value: (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..365bd4ac25b40 --- /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__, C; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + C = /** @class */ (function () { + function C() { + } + return C; + }()); + exports_1("C", C); + _C__ = { value: (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..82e26b3bdac3a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock24(module=umd).js @@ -0,0 +1,33 @@ +//// [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"; + var _C__; + exports.__esModule = true; + exports.C = void 0; + var C = /** @class */ (function () { + function C() { + } + return C; + }()); + exports.C = C; + _C__ = { value: (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/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; + } +} From 4278c0c5fc1bac28700245a0c3f4b79ae042946e Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 14:39:30 +0800 Subject: [PATCH 30/36] Fix strict mode function declaration --- src/compiler/binder.ts | 2 +- .../baselines/reference/classStaticBlock6.errors.txt | 8 +------- .../baselines/reference/classStaticBlock7.errors.txt | 11 +---------- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index da8132511a375..490b1bd9fbd40 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2330,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); diff --git a/tests/baselines/reference/classStaticBlock6.errors.txt b/tests/baselines/reference/classStaticBlock6.errors.txt index 89422160b8066..95e69c743769c 100644 --- a/tests/baselines/reference/classStaticBlock6.errors.txt +++ b/tests/baselines/reference/classStaticBlock6.errors.txt @@ -10,14 +10,12 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(32,17): er 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(44,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. 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(57,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (17 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts (15 errors) ==== class B { static a = 1; } @@ -86,8 +84,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er !!! error TS1109: Expression expected. async function ff () { - ~~ -!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. 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. @@ -107,8 +103,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock6.ts(57,22): er !!! error TS2815: 'arguments' cannot be referenced in property initializers. function ff () { - ~~ -!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. arguments; } } diff --git a/tests/baselines/reference/classStaticBlock7.errors.txt b/tests/baselines/reference/classStaticBlock7.errors.txt index 78b17ebac7861..c7892aa3eb98c 100644 --- a/tests/baselines/reference/classStaticBlock7.errors.txt +++ b/tests/baselines/reference/classStaticBlock7.errors.txt @@ -3,15 +3,12 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(3,9): erro 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(14,28): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. 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(26,24): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(36,13): error TS18041: A 'return' statement cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. !!! error TS2318: Cannot find global type 'IterableIterator'. -==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (9 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts (6 errors) ==== class C { static { await 1; @@ -34,8 +31,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er !!! error TS18037: Await expression cannot be used inside a class static block. async function ff () { - ~~ -!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. await 1; } } @@ -50,8 +45,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er !!! error TS1163: A 'yield' expression is only allowed in a generator body. function * ff () { - ~~ -!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. yield 1; } } @@ -66,8 +59,6 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock7.ts(38,22): er !!! error TS18041: A 'return' statement cannot be used inside a class static block. function ff () { - ~~ -!!! error TS1251: Function declarations are not allowed inside blocks in strict mode when targeting 'ES3' or 'ES5'. Class definitions are automatically in strict mode. return 1 } } From 34dce4680e2b8ca3521745bb12bd1b999ba95a3a Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Jun 2021 15:24:56 +0800 Subject: [PATCH 31/36] Avoid private fields initializer if no private identifier references --- src/compiler/transformers/classFields.ts | 32 +++++-- .../classStaticBlock1(target=es2015).js | 9 +- .../classStaticBlock1(target=es5).js | 9 +- .../classStaticBlock10(target=es2015).js | 24 +++-- .../classStaticBlock10(target=es5).js | 26 +++-- .../baselines/reference/classStaticBlock14.js | 26 ++--- .../classStaticBlock15(target=es2015).js | 26 ++--- .../classStaticBlock18(target=es2015).js | 22 ++--- .../classStaticBlock18(target=es5).js | 28 +++--- .../baselines/reference/classStaticBlock19.js | 7 +- .../classStaticBlock2(target=es2015).js | 21 ++--- .../classStaticBlock2(target=es5).js | 21 ++--- .../baselines/reference/classStaticBlock20.js | 19 ++-- .../baselines/reference/classStaticBlock21.js | 7 +- .../classStaticBlock24(module=amd).js | 7 +- .../classStaticBlock24(module=commonjs).js | 7 +- .../classStaticBlock24(module=es2015).js | 7 +- .../classStaticBlock24(module=es2020).js | 7 +- .../classStaticBlock24(module=esnext).js | 7 +- .../classStaticBlock24(module=system).js | 8 +- .../classStaticBlock24(module=umd).js | 7 +- .../classStaticBlock5(target=es2015).js | 11 +-- .../classStaticBlock5(target=es5).js | 11 +-- .../baselines/reference/classStaticBlock6.js | 94 +++++++++---------- .../baselines/reference/classStaticBlock7.js | 78 ++++++++------- .../baselines/reference/classStaticBlock8.js | 61 ++++++------ .../classStaticBlock9(target=es2015).js | 7 +- .../classStaticBlock9(target=es5).js | 7 +- 28 files changed, 292 insertions(+), 304 deletions(-) diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index b2f5a77e52e57..67692e6a6863c 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -132,6 +132,8 @@ namespace ts { */ let pendingStatements: Statement[] | undefined; + let classStaticBlockContainsPrivateFields = false; + const privateIdentifierEnvironmentStack: (PrivateIdentifierEnvironment | undefined)[] = []; let currentPrivateIdentifierEnvironment: PrivateIdentifierEnvironment | undefined; @@ -395,6 +397,7 @@ namespace ts { function visitPropertyAccessExpression(node: PropertyAccessExpression) { if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(node.name)) { + classStaticBlockContainsPrivateFields = true; const privateIdentifierInfo = accessPrivateIdentifier(node.name); if (privateIdentifierInfo) { return setTextRange( @@ -544,21 +547,36 @@ namespace ts { function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { - receiver = visitNode(receiver, visitor, isExpression); + const savedClassStaticBlockContainsPrivateFields = classStaticBlockContainsPrivateFields; + classStaticBlockContainsPrivateFields = false; startLexicalEnvironment(); let statements = visitNodes(node.body.statements, visitor, isStatement); statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); - const right = factory.createImmediatelyInvokedArrowFunction(statements); - const name = createHoistedVariableForClass("_", node); - return createPrivateStaticFieldInitializer( - name, - right - ); + const result = classStaticBlockContainsPrivateFields ? + transformClassStaticBlockDeclarationWithPrivateFields(statements, node, receiver) : + transformClassStaticBlockDeclarationWithIIFE(statements); + + classStaticBlockContainsPrivateFields = savedClassStaticBlockContainsPrivateFields; + return result; } } + function transformClassStaticBlockDeclarationWithIIFE(statements: NodeArray) { + return factory.createImmediatelyInvokedArrowFunction(statements); + } + + function transformClassStaticBlockDeclarationWithPrivateFields(statements: NodeArray, node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { + receiver = visitNode(receiver, visitor, isExpression); + const right = factory.createImmediatelyInvokedArrowFunction(statements); + const name = createHoistedVariableForClass("_", node); + return createPrivateStaticFieldInitializer( + name, + right + ); + } + function visitBinaryExpression(node: BinaryExpression) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { if (isDestructuringAssignment(node)) { diff --git a/tests/baselines/reference/classStaticBlock1(target=es2015).js b/tests/baselines/reference/classStaticBlock1(target=es2015).js index 3001cf5baa67c..2129bc16bf1cc 100644 --- a/tests/baselines/reference/classStaticBlock1(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock1(target=es2015).js @@ -11,11 +11,10 @@ class C { //// [classStaticBlock1.js] -var _C__; const a = 2; class C { } -_C__ = { value: (() => { - const a = 1; - a; - })() }; +(() => { + const a = 1; + a; +})(); diff --git a/tests/baselines/reference/classStaticBlock1(target=es5).js b/tests/baselines/reference/classStaticBlock1(target=es5).js index 42e28966b754e..9bd8a1a9d7bff 100644 --- a/tests/baselines/reference/classStaticBlock1(target=es5).js +++ b/tests/baselines/reference/classStaticBlock1(target=es5).js @@ -11,14 +11,13 @@ class C { //// [classStaticBlock1.js] -var _C__; var a = 2; var C = /** @class */ (function () { function C() { } return C; }()); -_C__ = { value: (function () { - var a = 1; - a; - })() }; +(function () { + var a = 1; + a; +})(); diff --git a/tests/baselines/reference/classStaticBlock10(target=es2015).js b/tests/baselines/reference/classStaticBlock10(target=es2015).js index 1e102364c5de5..dcf0be3960cb6 100644 --- a/tests/baselines/reference/classStaticBlock10(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock10(target=es2015).js @@ -28,29 +28,27 @@ class C2 { } //// [classStaticBlock10.js] -var _C2__; var a1 = 1; var a2 = 1; const b1 = 2; const b2 = 2; function f() { - var _C1__; var a1 = 11; const b1 = 22; class C1 { } - _C1__ = { value: (() => { - var a1 = 111; - var a2 = 111; - const b1 = 222; - const b2 = 222; - })() }; -} -class C2 { -} -_C2__ = { value: (() => { + (() => { 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=es5).js b/tests/baselines/reference/classStaticBlock10(target=es5).js index 3bb0f9c64b172..e390c2eb62da5 100644 --- a/tests/baselines/reference/classStaticBlock10(target=es5).js +++ b/tests/baselines/reference/classStaticBlock10(target=es5).js @@ -28,13 +28,11 @@ class C2 { } //// [classStaticBlock10.js] -var _C2__; var a1 = 1; var a2 = 1; var b1 = 2; var b2 = 2; function f() { - var _C1__; var a1 = 11; var b1 = 22; var C1 = /** @class */ (function () { @@ -42,21 +40,21 @@ function f() { } return C1; }()); - _C1__ = { value: (function () { - var a1 = 111; - var a2 = 111; - var b1 = 222; - var b2 = 222; - })() }; + (function () { + var a1 = 111; + var a2 = 111; + var b1 = 222; + var b2 = 222; + })(); } var C2 = /** @class */ (function () { function C2() { } return C2; }()); -_C2__ = { value: (function () { - var a1 = 111; - var a2 = 111; - var b1 = 222; - var b2 = 222; - })() }; +(function () { + var a1 = 111; + var a2 = 111; + var b1 = 222; + var b2 = 222; +})(); diff --git a/tests/baselines/reference/classStaticBlock14.js b/tests/baselines/reference/classStaticBlock14.js index a68bf8cfd6061..e64e2a7d5d795 100644 --- a/tests/baselines/reference/classStaticBlock14.js +++ b/tests/baselines/reference/classStaticBlock14.js @@ -14,22 +14,22 @@ class C { //// [classStaticBlock14.js] -var _a, _C__1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; +var _a, _C__1, _C__3, _C__5; class C { } _a = C; _C__1 = { value: 1 }; _C__3 = { value: 1 }; _C__5 = { value: 1 }; -_C__ = { value: (() => { - })() }; -_C__2 = { value: (() => { - })() }; -_C__4 = { value: (() => { - })() }; -_C__6 = { value: (() => { - })() }; -_C__7 = { value: (() => { - })() }; -_C__8 = { value: (() => { - })() }; +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); diff --git a/tests/baselines/reference/classStaticBlock15(target=es2015).js b/tests/baselines/reference/classStaticBlock15(target=es2015).js index 3c960d8cc6480..0c18e76329367 100644 --- a/tests/baselines/reference/classStaticBlock15(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock15(target=es2015).js @@ -18,7 +18,7 @@ console.log(_C__1) //// [classStaticBlock15.js] -var _a, _C__1_1, _C__3, _C__5, _C__, _C__2, _C__4, _C__6, _C__7, _C__8; +var _a, _C__1_1, _C__3, _C__5; var _C__1; class C { } @@ -26,16 +26,16 @@ _a = C; _C__1_1 = { value: 1 }; _C__3 = { value: 3 }; _C__5 = { value: 5 }; -_C__ = { value: (() => { - })() }; -_C__2 = { value: (() => { - })() }; -_C__4 = { value: (() => { - })() }; -_C__6 = { value: (() => { - })() }; -_C__7 = { value: (() => { - })() }; -_C__8 = { value: (() => { - })() }; +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); +(() => { +})(); console.log(_C__1); diff --git a/tests/baselines/reference/classStaticBlock18(target=es2015).js b/tests/baselines/reference/classStaticBlock18(target=es2015).js index a2de9bb8ce76b..7269e6f67a78d 100644 --- a/tests/baselines/reference/classStaticBlock18(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock18(target=es2015).js @@ -16,19 +16,19 @@ function foo () { //// [classStaticBlock18.js] function foo() { - var _a, __; + var _a; return _a = class { }, _a.foo = 1, - __ = { value: (() => { - var _a, _c__; - const c = (_a = class { - }, - _a.bar = 2, - _c__ = { value: (() => { - // do - })() }, - _a); - })() }, + (() => { + var _a; + const c = (_a = class { + }, + _a.bar = 2, + (() => { + // do + })(), + _a); + })(), _a; } diff --git a/tests/baselines/reference/classStaticBlock18(target=es5).js b/tests/baselines/reference/classStaticBlock18(target=es5).js index 8a4714ccb4a95..48597ad94cc17 100644 --- a/tests/baselines/reference/classStaticBlock18(target=es5).js +++ b/tests/baselines/reference/classStaticBlock18(target=es5).js @@ -16,25 +16,25 @@ function foo () { //// [classStaticBlock18.js] function foo() { - var _a, __; + var _a; return _a = /** @class */ (function () { function class_1() { } return class_1; }()), _a.foo = 1, - __ = { value: (function () { - var _a, _c__; - var c = (_a = /** @class */ (function () { - function class_2() { - } - return class_2; - }()), - _a.bar = 2, - _c__ = { value: (function () { - // do - })() }, - _a); - })() }, + (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/classStaticBlock19.js b/tests/baselines/reference/classStaticBlock19.js index 8a1e4aabcdb23..3f74c18a6970c 100644 --- a/tests/baselines/reference/classStaticBlock19.js +++ b/tests/baselines/reference/classStaticBlock19.js @@ -8,12 +8,11 @@ class C { //// [classStaticBlock19.js] -var _C__; var C = /** @class */ (function () { function C() { } return C; }()); -_C__ = { value: (function () { - // something - })() }; +(function () { + // something +})(); diff --git a/tests/baselines/reference/classStaticBlock2(target=es2015).js b/tests/baselines/reference/classStaticBlock2(target=es2015).js index 54117f2a89471..b578941d6154a 100644 --- a/tests/baselines/reference/classStaticBlock2(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock2(target=es2015).js @@ -20,18 +20,17 @@ class C { //// [classStaticBlock2.js] -var _C__, _C__1; const a = 1; const b = 2; class C { } -_C__ = { value: (() => { - const a = 11; - a; - b; - })() }; -_C__1 = { value: (() => { - const a = 11; - a; - b; - })() }; +(() => { + const a = 11; + a; + b; +})(); +(() => { + const a = 11; + a; + b; +})(); diff --git a/tests/baselines/reference/classStaticBlock2(target=es5).js b/tests/baselines/reference/classStaticBlock2(target=es5).js index 23c52b9511b3e..8165387d27820 100644 --- a/tests/baselines/reference/classStaticBlock2(target=es5).js +++ b/tests/baselines/reference/classStaticBlock2(target=es5).js @@ -20,7 +20,6 @@ class C { //// [classStaticBlock2.js] -var _C__, _C__1; var a = 1; var b = 2; var C = /** @class */ (function () { @@ -28,13 +27,13 @@ var C = /** @class */ (function () { } return C; }()); -_C__ = { value: (function () { - var a = 11; - a; - b; - })() }; -_C__1 = { value: (function () { - var a = 11; - a; - b; - })() }; +(function () { + var a = 11; + a; + b; +})(); +(function () { + var a = 11; + a; + b; +})(); diff --git a/tests/baselines/reference/classStaticBlock20.js b/tests/baselines/reference/classStaticBlock20.js index 44af03659c35d..bd4d4597c6515 100644 --- a/tests/baselines/reference/classStaticBlock20.js +++ b/tests/baselines/reference/classStaticBlock20.js @@ -15,18 +15,17 @@ class C { //// [classStaticBlock20.js] -var _C__, _C__1, _C__2; var C = /** @class */ (function () { function C() { } return C; }()); -_C__ = { value: (function () { - // something - })() }; -_C__1 = { value: (function () { - // something - })() }; -_C__2 = { value: (function () { - // something - })() }; +(function () { + // something +})(); +(function () { + // something +})(); +(function () { + // something +})(); diff --git a/tests/baselines/reference/classStaticBlock21.js b/tests/baselines/reference/classStaticBlock21.js index a440cff2a2517..2b1b059fc59ea 100644 --- a/tests/baselines/reference/classStaticBlock21.js +++ b/tests/baselines/reference/classStaticBlock21.js @@ -8,13 +8,12 @@ class C { //// [classStaticBlock21.js] -var _C__; var C = /** @class */ (function () { function C() { } return C; }()); /* jsdocs */ -_C__ = { value: (function () { - // something - })() }; +(function () { + // something +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=amd).js b/tests/baselines/reference/classStaticBlock24(module=amd).js index f1f3cc62c017f..e3c7f932803c2 100644 --- a/tests/baselines/reference/classStaticBlock24(module=amd).js +++ b/tests/baselines/reference/classStaticBlock24(module=amd).js @@ -10,7 +10,6 @@ export class C { //// [classStaticBlock24.js] define(["require", "exports"], function (require, exports) { "use strict"; - var _C__; exports.__esModule = true; exports.C = void 0; var C = /** @class */ (function () { @@ -19,7 +18,7 @@ define(["require", "exports"], function (require, exports) { return C; }()); exports.C = C; - _C__ = { value: (function () { - C.x = 1; - })() }; + (function () { + C.x = 1; + })(); }); diff --git a/tests/baselines/reference/classStaticBlock24(module=commonjs).js b/tests/baselines/reference/classStaticBlock24(module=commonjs).js index 850901073da7d..196e0645e3cef 100644 --- a/tests/baselines/reference/classStaticBlock24(module=commonjs).js +++ b/tests/baselines/reference/classStaticBlock24(module=commonjs).js @@ -9,7 +9,6 @@ export class C { //// [classStaticBlock24.js] "use strict"; -var _C__; exports.__esModule = true; exports.C = void 0; var C = /** @class */ (function () { @@ -18,6 +17,6 @@ var C = /** @class */ (function () { return C; }()); exports.C = C; -_C__ = { value: (function () { - C.x = 1; - })() }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=es2015).js b/tests/baselines/reference/classStaticBlock24(module=es2015).js index 60eec043563c3..450e53df8a141 100644 --- a/tests/baselines/reference/classStaticBlock24(module=es2015).js +++ b/tests/baselines/reference/classStaticBlock24(module=es2015).js @@ -8,13 +8,12 @@ export class C { //// [classStaticBlock24.js] -var _C__; var C = /** @class */ (function () { function C() { } return C; }()); export { C }; -_C__ = { value: (function () { - C.x = 1; - })() }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=es2020).js b/tests/baselines/reference/classStaticBlock24(module=es2020).js index 60eec043563c3..450e53df8a141 100644 --- a/tests/baselines/reference/classStaticBlock24(module=es2020).js +++ b/tests/baselines/reference/classStaticBlock24(module=es2020).js @@ -8,13 +8,12 @@ export class C { //// [classStaticBlock24.js] -var _C__; var C = /** @class */ (function () { function C() { } return C; }()); export { C }; -_C__ = { value: (function () { - C.x = 1; - })() }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=esnext).js b/tests/baselines/reference/classStaticBlock24(module=esnext).js index 60eec043563c3..450e53df8a141 100644 --- a/tests/baselines/reference/classStaticBlock24(module=esnext).js +++ b/tests/baselines/reference/classStaticBlock24(module=esnext).js @@ -8,13 +8,12 @@ export class C { //// [classStaticBlock24.js] -var _C__; var C = /** @class */ (function () { function C() { } return C; }()); export { C }; -_C__ = { value: (function () { - C.x = 1; - })() }; +(function () { + C.x = 1; +})(); diff --git a/tests/baselines/reference/classStaticBlock24(module=system).js b/tests/baselines/reference/classStaticBlock24(module=system).js index 365bd4ac25b40..61c0da67830a6 100644 --- a/tests/baselines/reference/classStaticBlock24(module=system).js +++ b/tests/baselines/reference/classStaticBlock24(module=system).js @@ -10,7 +10,7 @@ export class C { //// [classStaticBlock24.js] System.register([], function (exports_1, context_1) { "use strict"; - var _C__, C; + var C; var __moduleName = context_1 && context_1.id; return { setters: [], @@ -21,9 +21,9 @@ System.register([], function (exports_1, context_1) { return C; }()); exports_1("C", C); - _C__ = { value: (function () { - C.x = 1; - })() }; + (function () { + C.x = 1; + })(); } }; }); diff --git a/tests/baselines/reference/classStaticBlock24(module=umd).js b/tests/baselines/reference/classStaticBlock24(module=umd).js index 82e26b3bdac3a..d9a17e515ce0d 100644 --- a/tests/baselines/reference/classStaticBlock24(module=umd).js +++ b/tests/baselines/reference/classStaticBlock24(module=umd).js @@ -18,7 +18,6 @@ export class C { } })(function (require, exports) { "use strict"; - var _C__; exports.__esModule = true; exports.C = void 0; var C = /** @class */ (function () { @@ -27,7 +26,7 @@ export class C { return C; }()); exports.C = C; - _C__ = { value: (function () { - C.x = 1; - })() }; + (function () { + C.x = 1; + })(); }); diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).js b/tests/baselines/reference/classStaticBlock5(target=es2015).js index e69ce1e902168..557bf8b05b4ec 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).js @@ -17,7 +17,6 @@ class C extends B { //// [classStaticBlock5.js] -var _C__; class B { } B.a = 1; @@ -26,8 +25,8 @@ class C extends B { } C.b = 3; C.c = super.a; -_C__ = { value: (() => { - this.b; - super.b; - super.a; - })() }; +(() => { + this.b; + super.b; + super.a; +})(); diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).js b/tests/baselines/reference/classStaticBlock5(target=es5).js index 7aee91846eea4..0b26d0f4dcd1e 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).js +++ b/tests/baselines/reference/classStaticBlock5(target=es5).js @@ -45,13 +45,12 @@ var C = /** @class */ (function (_super) { function C() { return _super !== null && _super.apply(this, arguments) || this; } - var _C__; C.b = 3; C.c = _super.a; - _C__ = { value: (function () { - _this.b; - _super.b; - _super.a; - })() }; + (function () { + _this.b; + _super.b; + _super.a; + })(); return C; }(B)); diff --git a/tests/baselines/reference/classStaticBlock6.js b/tests/baselines/reference/classStaticBlock6.js index 4935e1e195e63..69d146407890e 100644 --- a/tests/baselines/reference/classStaticBlock6.js +++ b/tests/baselines/reference/classStaticBlock6.js @@ -115,7 +115,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) { if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; -var _C__, _C__1; var B = /** @class */ (function () { function B() { } @@ -129,22 +128,21 @@ var C = /** @class */ (function (_super) { } return C; }(B)); -_C__ = { value: (function () { - var await = 1; - var arguments = 1; - var eval = 1; - })() }; -_C__1 = { value: (function () { - yield ; - if (true) { - } - arguments; - yield ; - _this = _super.call(this) || this; - })() }; +(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__2; var C = /** @class */ (function (_super) { __extends(C, _super); function C() { @@ -152,21 +150,20 @@ var CC = /** @class */ (function () { } return C; }(B)); - _C__2 = { value: (function () { - var CC = /** @class */ (function (_super) { - __extends(CC, _super); - function CC() { - return _super.call(this) || this; - } - return CC; - }(B)); - _this = _super.call(this) || this; - })() }; + (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() { - var _C__3; return __awaiter(this, void 0, void 0, function () { var C; return __generator(this, function (_a) { @@ -177,30 +174,29 @@ function foo() { } return C; }(B)); - _C__3 = { value: (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*/]; - } - }); + (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__4; var C = /** @class */ (function (_super) { __extends(C, _super); function C() { @@ -208,10 +204,10 @@ function foo1() { } return C; }(B)); - _C__4 = { value: (function () { + (function () { + arguments; + function ff() { arguments; - function ff() { - arguments; - } - })() }; + } + })(); } diff --git a/tests/baselines/reference/classStaticBlock7.js b/tests/baselines/reference/classStaticBlock7.js index 9579f500e55b6..fd198db1871dd 100644 --- a/tests/baselines/reference/classStaticBlock7.js +++ b/tests/baselines/reference/classStaticBlock7.js @@ -81,19 +81,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) { if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; -var _C__; var C = /** @class */ (function () { function C() { } return C; }()); -_C__ = { value: (function () { - yield 1; - yield 1; - return 1; - })() }; +(function () { + yield 1; + yield 1; + return 1; +})(); function f1() { - var _C__1; return __awaiter(this, void 0, void 0, function () { var C; return __generator(this, function (_a) { @@ -102,61 +100,59 @@ function f1() { } return C; }()); - _C__1 = { value: (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*/]; - } - }); + (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; - var _C__2; return __generator(this, function (_a) { C = /** @class */ (function () { function C() { } return C; }()); - _C__2 = { value: (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*/]; - } - }); - } - })() }; + (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__3; var C = /** @class */ (function () { function C() { } return C; }()); - _C__3 = { value: (function () { + (function () { + return 1; + function ff() { return 1; - function ff() { - return 1; - } - })() }; + } + })(); } diff --git a/tests/baselines/reference/classStaticBlock8.js b/tests/baselines/reference/classStaticBlock8.js index 2b054c56bcec5..9d9e42a9c5956 100644 --- a/tests/baselines/reference/classStaticBlock8.js +++ b/tests/baselines/reference/classStaticBlock8.js @@ -51,27 +51,26 @@ function foo (v: number) { //// [classStaticBlock8.js] function foo(v) { - var _C__, _C__1; label: while (v) { var C_1 = /** @class */ (function () { function C() { } return C; }()); - _C__ = { value: (function () { - if (v === 1) { - break label; - } - if (v === 2) { - continue label; - } - if (v === 3) { - break; - } - if (v === 4) { - continue; - } - })() }; + (function () { + if (v === 1) { + break label; + } + if (v === 2) { + continue label; + } + if (v === 3) { + break; + } + if (v === 4) { + continue; + } + })(); if (v === 5) { break label; } @@ -90,20 +89,20 @@ function foo(v) { } return C; }()); - _C__1 = { value: (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 - } - })() }; + (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/classStaticBlock9(target=es2015).js b/tests/baselines/reference/classStaticBlock9(target=es2015).js index d7a213f4b59d9..d2b5eefa004c9 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock9(target=es2015).js @@ -9,11 +9,10 @@ class A { //// [classStaticBlock9.js] -var _A__; class A { } A.bar = A.foo + 1; -_A__ = { value: (() => { - A.foo + 2; - })() }; +(() => { + A.foo + 2; +})(); A.foo = 1; diff --git a/tests/baselines/reference/classStaticBlock9(target=es5).js b/tests/baselines/reference/classStaticBlock9(target=es5).js index 23e4ba3e909fa..1b957f3b714e9 100644 --- a/tests/baselines/reference/classStaticBlock9(target=es5).js +++ b/tests/baselines/reference/classStaticBlock9(target=es5).js @@ -12,11 +12,10 @@ class A { var A = /** @class */ (function () { function A() { } - var _A__; A.bar = A.foo + 1; - _A__ = { value: (function () { - A.foo + 2; - })() }; + (function () { + A.foo + 2; + })(); A.foo = 1; return A; }()); From 307c1d928c90de8d20d3fa310584dea31cdeda62 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Jun 2021 11:39:23 +0800 Subject: [PATCH 32/36] Avoid private fields and add more test case --- src/compiler/checker.ts | 38 +-- src/compiler/transformers/classFields.ts | 39 +-- src/compiler/transformers/declarations.ts | 2 + .../classStaticBlock11(target=es2015).js | 10 +- .../baselines/reference/classStaticBlock12.js | 8 +- .../classStaticBlock13(target=es2015).js | 8 +- .../baselines/reference/classStaticBlock16.js | 22 +- .../baselines/reference/classStaticBlock17.js | 14 +- .../baselines/reference/classStaticBlock25.js | 44 +++ .../reference/classStaticBlock25.js.map | 7 + .../classStaticBlock25.sourcemap.txt | 287 ++++++++++++++++++ .../reference/classStaticBlock25.symbols | 33 ++ .../reference/classStaticBlock25.types | 37 +++ .../classStaticBlock/classStaticBlock25.ts | 23 ++ 14 files changed, 493 insertions(+), 79 deletions(-) create mode 100644 tests/baselines/reference/classStaticBlock25.js create mode 100644 tests/baselines/reference/classStaticBlock25.js.map create mode 100644 tests/baselines/reference/classStaticBlock25.sourcemap.txt create mode 100644 tests/baselines/reference/classStaticBlock25.symbols create mode 100644 tests/baselines/reference/classStaticBlock25.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock25.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 44269743873f3..892c02470a0c2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -31272,8 +31272,11 @@ namespace ts { function checkAwaitExpression(node: AwaitExpression): Type { // Grammar checking if (produceDiagnostics) { - const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); - 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)) { @@ -31298,17 +31301,14 @@ 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); - if (containingFunctionOrClassStaticBlock && containingFunctionOrClassStaticBlock.kind !== SyntaxKind.ClassStaticBlockDeclaration && containingFunctionOrClassStaticBlock.kind !== SyntaxKind.Constructor && (getFunctionFlags(containingFunctionOrClassStaticBlock) & FunctionFlags.Async) === 0) { - const relatedInfo = createDiagnosticForNode(containingFunctionOrClassStaticBlock, 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); } } } - else if (containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { - error(node, Diagnostics.Await_expression_cannot_be_used_inside_a_class_static_block); - } if (isInParameterInitializerBeforeContainingFunction(node)) { error(node, Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer); @@ -35887,13 +35887,13 @@ namespace ts { function checkForOfStatement(node: ForOfStatement): void { checkGrammarForInOrForOfStatement(node); - const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); + const container = getContainingFunctionOrClassStaticBlock(node); if (node.awaitModifier) { - if (containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { + if (container && isClassStaticBlockDeclaration(container)) { grammarErrorOnNode(node.awaitModifier, Diagnostics.For_await_loops_cannot_be_used_inside_a_class_static_block); } else { - const functionFlags = getFunctionFlags(containingFunctionOrClassStaticBlock); + 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); @@ -36777,33 +36777,33 @@ namespace ts { return; } - const containingFunctionOrClassStaticBlock = getContainingFunctionOrClassStaticBlock(node); - if(containingFunctionOrClassStaticBlock && isClassStaticBlockDeclaration(containingFunctionOrClassStaticBlock)) { + const container = getContainingFunctionOrClassStaticBlock(node); + if(container && isClassStaticBlockDeclaration(container)) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block); return; } - if (!containingFunctionOrClassStaticBlock) { + if (!container) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); return; } - const signature = getSignatureFromDeclaration(containingFunctionOrClassStaticBlock); + const signature = getSignatureFromDeclaration(container); const returnType = getReturnTypeOfSignature(signature); - const functionFlags = getFunctionFlags(containingFunctionOrClassStaticBlock); + const functionFlags = getFunctionFlags(container); if (strictNullChecks || node.expression || returnType.flags & TypeFlags.Never) { const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType; - if (containingFunctionOrClassStaticBlock.kind === SyntaxKind.SetAccessor) { + if (container.kind === SyntaxKind.SetAccessor) { if (node.expression) { error(node, Diagnostics.Setters_cannot_return_a_value); } } - else if (containingFunctionOrClassStaticBlock.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(containingFunctionOrClassStaticBlock)) { + 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) @@ -36816,7 +36816,7 @@ namespace ts { } } } - else if (containingFunctionOrClassStaticBlock.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(containingFunctionOrClassStaticBlock, 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); } diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 67692e6a6863c..6ce6c7dd58c76 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -132,8 +132,6 @@ namespace ts { */ let pendingStatements: Statement[] | undefined; - let classStaticBlockContainsPrivateFields = false; - const privateIdentifierEnvironmentStack: (PrivateIdentifierEnvironment | undefined)[] = []; let currentPrivateIdentifierEnvironment: PrivateIdentifierEnvironment | undefined; @@ -397,7 +395,6 @@ namespace ts { function visitPropertyAccessExpression(node: PropertyAccessExpression) { if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifier(node.name)) { - classStaticBlockContainsPrivateFields = true; const privateIdentifierInfo = accessPrivateIdentifier(node.name); if (privateIdentifierInfo) { return setTextRange( @@ -545,38 +542,22 @@ namespace ts { return visitEachChild(node, visitor, context); } - function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { + function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { - const savedClassStaticBlockContainsPrivateFields = classStaticBlockContainsPrivateFields; - classStaticBlockContainsPrivateFields = false; - startLexicalEnvironment(); let statements = visitNodes(node.body.statements, visitor, isStatement); statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); - const result = classStaticBlockContainsPrivateFields ? - transformClassStaticBlockDeclarationWithPrivateFields(statements, node, receiver) : - transformClassStaticBlockDeclarationWithIIFE(statements); - - classStaticBlockContainsPrivateFields = savedClassStaticBlockContainsPrivateFields; - return result; + return setTextRange( + setOriginalNode( + factory.createImmediatelyInvokedArrowFunction(statements), + node + ), + node + ); } } - function transformClassStaticBlockDeclarationWithIIFE(statements: NodeArray) { - return factory.createImmediatelyInvokedArrowFunction(statements); - } - - function transformClassStaticBlockDeclarationWithPrivateFields(statements: NodeArray, node: ClassStaticBlockDeclaration, receiver: LeftHandSideExpression) { - receiver = visitNode(receiver, visitor, isExpression); - const right = factory.createImmediatelyInvokedArrowFunction(statements); - const name = createHoistedVariableForClass("_", node); - return createPrivateStaticFieldInitializer( - name, - right - ); - } - function visitBinaryExpression(node: BinaryExpression) { if (shouldTransformPrivateElementsOrClassStaticBlocks) { if (isDestructuringAssignment(node)) { @@ -1008,7 +989,7 @@ namespace ts { */ function addPropertyOrClassStaticBlockStatements(statements: Statement[], properties: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { for (const property of properties) { - const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property, receiver) : transformProperty(property, receiver); + const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property) : transformProperty(property, receiver); if (!expression) { continue; } @@ -1029,7 +1010,7 @@ namespace ts { function generateInitializedPropertyExpressionsOrClassStaticBlock(propertiesOrClassStaticBlocks: readonly (PropertyDeclaration | ClassStaticBlockDeclaration)[], receiver: LeftHandSideExpression) { const expressions: Expression[] = []; for (const property of propertiesOrClassStaticBlocks) { - const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property, receiver) : transformProperty(property, receiver); + const expression = isClassStaticBlockDeclaration(property) ? transformClassStaticBlockDeclaration(property) : transformProperty(property, receiver); if (!expression) { continue; } 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/tests/baselines/reference/classStaticBlock11(target=es2015).js b/tests/baselines/reference/classStaticBlock11(target=es2015).js index b218d2f8a4a5f..7dbf78f783e13 100644 --- a/tests/baselines/reference/classStaticBlock11(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock11(target=es2015).js @@ -25,7 +25,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( 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, _C__; +var _C_x; let getX; class C { constructor(x) { @@ -34,7 +34,7 @@ class C { } } _C_x = new WeakMap(); -_C__ = { value: (() => { - // getX has privileged access to #x - getX = (obj) => __classPrivateFieldGet(obj, _C_x, "f"); - })() }; +(() => { + // getX has privileged access to #x + getX = (obj) => __classPrivateFieldGet(obj, _C_x, "f"); +})(); diff --git a/tests/baselines/reference/classStaticBlock12.js b/tests/baselines/reference/classStaticBlock12.js index 42c7d06abd69d..e05449fe4a161 100644 --- a/tests/baselines/reference/classStaticBlock12.js +++ b/tests/baselines/reference/classStaticBlock12.js @@ -14,11 +14,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( 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, _C__; +var _a, _C_x; class C { } _a = C; _C_x = { value: 1 }; -_C__ = { value: (() => { - __classPrivateFieldGet(C, _a, "f", _C_x); - })() }; +(() => { + __classPrivateFieldGet(C, _a, "f", _C_x); +})(); diff --git a/tests/baselines/reference/classStaticBlock13(target=es2015).js b/tests/baselines/reference/classStaticBlock13(target=es2015).js index 521c946a38113..442dbba65755f 100644 --- a/tests/baselines/reference/classStaticBlock13(target=es2015).js +++ b/tests/baselines/reference/classStaticBlock13(target=es2015).js @@ -18,7 +18,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( 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, _C__; +var _a, _C_x; class C { foo() { return __classPrivateFieldGet(C, _a, "f", _C_x); @@ -26,6 +26,6 @@ class C { } _a = C; _C_x = { value: 123 }; -_C__ = { value: (() => { - console.log(__classPrivateFieldGet(C, _a, "f", _C_x)); - })() }; +(() => { + console.log(__classPrivateFieldGet(C, _a, "f", _C_x)); +})(); diff --git a/tests/baselines/reference/classStaticBlock16.js b/tests/baselines/reference/classStaticBlock16.js index 7c282010398f1..566d3ceeb179e 100644 --- a/tests/baselines/reference/classStaticBlock16.js +++ b/tests/baselines/reference/classStaticBlock16.js @@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( 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, _C__, _D_y, _D__; +var _C_x, _D_y; let getX; class C { constructor(x) { @@ -45,11 +45,11 @@ class C { } } _C_x = new WeakMap(); -_C__ = { value: (() => { - // getX has privileged access to #x - getX = (obj) => __classPrivateFieldGet(obj, _C_x, "f"); - getY = (obj) => obj.; - })() }; +(() => { + // getX has privileged access to #x + getX = (obj) => __classPrivateFieldGet(obj, _C_x, "f"); + getY = (obj) => obj.; +})(); let getY; class D { constructor() { @@ -57,8 +57,8 @@ class D { } } _D_y = new WeakMap(); -_D__ = { value: (() => { - // getY has privileged access to y - getX = (obj) => obj.; - getY = (obj) => __classPrivateFieldGet(obj, _D_y, "f"); - })() }; +(() => { + // getY has privileged access to y + getX = (obj) => obj.; + getY = (obj) => __classPrivateFieldGet(obj, _D_y, "f"); +})(); diff --git a/tests/baselines/reference/classStaticBlock17.js b/tests/baselines/reference/classStaticBlock17.js index b079e496807fb..9464a543cfa61 100644 --- a/tests/baselines/reference/classStaticBlock17.js +++ b/tests/baselines/reference/classStaticBlock17.js @@ -43,7 +43,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( 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, _A__; +var _A_x; let friendA; class A { constructor(v) { @@ -55,12 +55,12 @@ class A { } } _A_x = new WeakMap(); -_A__ = { value: (() => { - friendA = { - getX(obj) { return __classPrivateFieldGet(obj, _A_x, "f"); }, - setX(obj, value) { __classPrivateFieldSet(obj, _A_x, value, "f"); } - }; - })() }; +(() => { + friendA = { + getX(obj) { return __classPrivateFieldGet(obj, _A_x, "f"); }, + setX(obj, value) { __classPrivateFieldSet(obj, _A_x, value, "f"); } + }; +})(); ; class B { constructor(a) { 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/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; + } +} From 1f173a9e68b6b8699339f8a1f7e73c45e6dd97a9 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Jun 2021 17:56:59 +0800 Subject: [PATCH 33/36] Add more case --- .../reference/classStaticBlock26.errors.txt | 24 +++++++++++++++++ .../baselines/reference/classStaticBlock26.js | 26 +++++++++++++++++++ .../reference/classStaticBlock26.symbols | 18 +++++++++++++ .../reference/classStaticBlock26.types | 21 +++++++++++++++ .../classStaticBlock/classStaticBlock26.ts | 13 ++++++++++ 5 files changed, 102 insertions(+) create mode 100644 tests/baselines/reference/classStaticBlock26.errors.txt create mode 100644 tests/baselines/reference/classStaticBlock26.js create mode 100644 tests/baselines/reference/classStaticBlock26.symbols create mode 100644 tests/baselines/reference/classStaticBlock26.types create mode 100644 tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts diff --git a/tests/baselines/reference/classStaticBlock26.errors.txt b/tests/baselines/reference/classStaticBlock26.errors.txt new file mode 100644 index 0000000000000..bc5938561ce2a --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(3,13): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(6,13): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(9,15): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + + +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts (3 errors) ==== + class C { + static { + let await = 1; + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + var await = 1; + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + static { + const await = 1; + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + } + } + \ 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..7b7ff83dc23c5 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.js @@ -0,0 +1,26 @@ +//// [classStaticBlock26.ts] +class C { + static { + let await = 1; + } + static { + var await = 1; + } + static { + const await = 1; + } +} + + +//// [classStaticBlock26.js] +class C { + static { + let await = 1; + } + static { + var await = 1; + } + static { + const await = 1; + } +} diff --git a/tests/baselines/reference/classStaticBlock26.symbols b/tests/baselines/reference/classStaticBlock26.symbols new file mode 100644 index 0000000000000..c104550329ce6 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts === +class C { +>C : Symbol(C, Decl(classStaticBlock26.ts, 0, 0)) + + static { + let await = 1; +>await : Symbol(await, Decl(classStaticBlock26.ts, 2, 11)) + } + static { + var await = 1; +>await : Symbol(await, Decl(classStaticBlock26.ts, 5, 11)) + } + static { + const await = 1; +>await : Symbol(await, Decl(classStaticBlock26.ts, 8, 13)) + } +} + diff --git a/tests/baselines/reference/classStaticBlock26.types b/tests/baselines/reference/classStaticBlock26.types new file mode 100644 index 0000000000000..148518a06ed89 --- /dev/null +++ b/tests/baselines/reference/classStaticBlock26.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts === +class C { +>C : C + + static { + let await = 1; +>await : number +>1 : 1 + } + static { + var await = 1; +>await : number +>1 : 1 + } + static { + const await = 1; +>await : 1 +>1 : 1 + } +} + diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts new file mode 100644 index 0000000000000..0524027744119 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts @@ -0,0 +1,13 @@ +// @target: esnext + +class C { + static { + let await = 1; + } + static { + var await = 1; + } + static { + const await = 1; + } +} From b409d8cc0359646c0f91e779f7a05526da37425d Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 23 Jun 2021 18:22:41 -0700 Subject: [PATCH 34/36] Add tests and support for related services functionality --- src/compiler/types.ts | 1 + src/services/callHierarchy.ts | 41 +++++- src/services/findAllReferences.ts | 4 + src/services/goToDefinition.ts | 23 ++- src/services/types.ts | 5 +- src/services/utilities.ts | 6 +- .../reference/api/tsserverlibrary.d.ts | 6 +- tests/baselines/reference/api/typescript.d.ts | 6 +- ...ierarchyClassStaticBlock.callHierarchy.txt | 139 ++++++++++++++++++ ...erarchyClassStaticBlock2.callHierarchy.txt | 139 ++++++++++++++++++ ...indAllRefsClassStaticBlocks.baseline.jsonc | 128 ++++++++++++++++ .../callHierarchyClassStaticBlock.ts | 26 ++++ .../callHierarchyClassStaticBlock2.ts | 26 ++++ .../fourslash/findAllRefsClassStaticBlocks.ts | 12 ++ .../goToDefinitionClassStaticBlocks.ts | 16 ++ .../navigationBarClassStaticBlock.ts | 48 ++++++ 16 files changed, 614 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/callHierarchyClassStaticBlock.callHierarchy.txt create mode 100644 tests/baselines/reference/callHierarchyClassStaticBlock2.callHierarchy.txt create mode 100644 tests/baselines/reference/findAllRefsClassStaticBlocks.baseline.jsonc create mode 100644 tests/cases/fourslash/callHierarchyClassStaticBlock.ts create mode 100644 tests/cases/fourslash/callHierarchyClassStaticBlock2.ts create mode 100644 tests/cases/fourslash/findAllRefsClassStaticBlocks.ts create mode 100644 tests/cases/fourslash/goToDefinitionClassStaticBlocks.ts create mode 100644 tests/cases/fourslash/navigationBarClassStaticBlock.ts diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4b9c9e42f9e93..385a07414b294 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1539,6 +1539,7 @@ namespace ts { 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 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 124ef7a8d8416..b45a6481871e3 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -853,6 +853,7 @@ declare namespace ts { } export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly parent: ClassDeclaration | ClassExpression; readonly body: Block; } export interface TypeNode extends Node { @@ -6413,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 56a67b384c838..c7160064d611e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -853,6 +853,7 @@ declare namespace ts { } export interface ClassStaticBlockDeclaration extends ClassElement, JSDocContainer { readonly kind: SyntaxKind.ClassStaticBlockDeclaration; + readonly parent: ClassDeclaration | ClassExpression; readonly body: Block; } export interface TypeNode extends Node { @@ -6413,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/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/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 + } +]); From aa289860d34abfbc2483a5115194c42db53e521b Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 24 Jun 2021 11:16:29 +0800 Subject: [PATCH 35/36] Fix this reference in static block --- src/compiler/checker.ts | 6 +++++- .../reference/classStaticBlock4.errors.txt | 16 ++++++++++------ .../reference/classStaticBlock4.symbols | 4 ++++ .../baselines/reference/classStaticBlock4.types | 12 ++++++------ .../classStaticBlock5(target=es2015).errors.txt | 6 +++--- .../classStaticBlock5(target=es2015).symbols | 2 ++ .../classStaticBlock5(target=es2015).types | 6 +++--- .../classStaticBlock5(target=es5).errors.txt | 6 +++--- .../classStaticBlock5(target=es5).symbols | 2 ++ .../classStaticBlock5(target=es5).types | 6 +++--- .../classStaticBlock5(target=esnext).errors.txt | 6 +++--- .../classStaticBlock5(target=esnext).symbols | 2 ++ .../classStaticBlock5(target=esnext).types | 6 +++--- 13 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6ed9457d67572..f0eff1254b094 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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); } diff --git a/tests/baselines/reference/classStaticBlock4.errors.txt b/tests/baselines/reference/classStaticBlock4.errors.txt index fa0c4d51af6d9..4bd2b377e0b97 100644 --- a/tests/baselines/reference/classStaticBlock4.errors.txt +++ b/tests/baselines/reference/classStaticBlock4.errors.txt @@ -1,21 +1,25 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(5,14): error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? -tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts(8,14): error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +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 (3 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock4.ts (4 errors) ==== class C { static s1 = 1; static { this.s1; - ~~ -!!! error TS2576: Property 's1' does not exist on type 'C'. Did you mean to access the static member 'C.s1' instead? + ~~~~ +!!! error TS2332: 'this' cannot be referenced in current location. C.s1; this.s2; + ~~~~ +!!! error TS2332: 'this' cannot be referenced in current location. ~~ -!!! error TS2576: Property 's2' does not exist on type 'C'. Did you mean to access the static member 'C.s2' instead? +!!! 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. diff --git a/tests/baselines/reference/classStaticBlock4.symbols b/tests/baselines/reference/classStaticBlock4.symbols index 5b812c63d7121..fd412244fbe0e 100644 --- a/tests/baselines/reference/classStaticBlock4.symbols +++ b/tests/baselines/reference/classStaticBlock4.symbols @@ -7,7 +7,9 @@ class C { 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)) @@ -15,7 +17,9 @@ class C { >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)) diff --git a/tests/baselines/reference/classStaticBlock4.types b/tests/baselines/reference/classStaticBlock4.types index 91d7ba0613136..db068a795397c 100644 --- a/tests/baselines/reference/classStaticBlock4.types +++ b/tests/baselines/reference/classStaticBlock4.types @@ -8,9 +8,9 @@ class C { static { this.s1; ->this.s1 : any ->this : this ->s1 : any +>this.s1 : number +>this : typeof C +>s1 : number C.s1; >C.s1 : number @@ -18,9 +18,9 @@ class C { >s1 : number this.s2; ->this.s2 : any ->this : this ->s2 : any +>this.s2 : number +>this : typeof C +>s2 : number C.s2; >C.s2 : number diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt b/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt index eeabc4440f902..71227c6036a79 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).errors.txt @@ -1,5 +1,5 @@ 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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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. @@ -18,8 +18,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): err static { this.b; - ~ -!!! error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + ~~~~ +!!! 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. diff --git a/tests/baselines/reference/classStaticBlock5(target=es2015).symbols b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols index 2e0175423fafb..1e2334d1dff10 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).symbols +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).symbols @@ -21,7 +21,9 @@ class C extends B { 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 index 9e0dfa94d3fee..beb56840bfc1c 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es2015).types +++ b/tests/baselines/reference/classStaticBlock5(target=es2015).types @@ -27,9 +27,9 @@ class C extends B { static { this.b; ->this.b : any ->this : this ->b : any +>this.b : number +>this : typeof C +>b : number super.b; >super.b : any diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt b/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt index eeabc4440f902..71227c6036a79 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt +++ b/tests/baselines/reference/classStaticBlock5(target=es5).errors.txt @@ -1,5 +1,5 @@ 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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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. @@ -18,8 +18,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): err static { this.b; - ~ -!!! error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + ~~~~ +!!! 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. diff --git a/tests/baselines/reference/classStaticBlock5(target=es5).symbols b/tests/baselines/reference/classStaticBlock5(target=es5).symbols index 2e0175423fafb..1e2334d1dff10 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).symbols +++ b/tests/baselines/reference/classStaticBlock5(target=es5).symbols @@ -21,7 +21,9 @@ class C extends B { 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 index 9e0dfa94d3fee..beb56840bfc1c 100644 --- a/tests/baselines/reference/classStaticBlock5(target=es5).types +++ b/tests/baselines/reference/classStaticBlock5(target=es5).types @@ -27,9 +27,9 @@ class C extends B { static { this.b; ->this.b : any ->this : this ->b : any +>this.b : number +>this : typeof C +>b : number super.b; >super.b : any diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt b/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt index eeabc4440f902..71227c6036a79 100644 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).errors.txt @@ -1,5 +1,5 @@ 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,14): error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? +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. @@ -18,8 +18,8 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock5.ts(13,9): err static { this.b; - ~ -!!! error TS2576: Property 'b' does not exist on type 'C'. Did you mean to access the static member 'C.b' instead? + ~~~~ +!!! 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. diff --git a/tests/baselines/reference/classStaticBlock5(target=esnext).symbols b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols index 2e0175423fafb..1e2334d1dff10 100644 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).symbols +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).symbols @@ -21,7 +21,9 @@ class C extends B { 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 index 9e0dfa94d3fee..beb56840bfc1c 100644 --- a/tests/baselines/reference/classStaticBlock5(target=esnext).types +++ b/tests/baselines/reference/classStaticBlock5(target=esnext).types @@ -27,9 +27,9 @@ class C extends B { static { this.b; ->this.b : any ->this : this ->b : any +>this.b : number +>this : typeof C +>b : number super.b; >super.b : any From 6234640ec6b7775a4a8249c1574958ed6189e625 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 24 Jun 2021 14:33:13 +0800 Subject: [PATCH 36/36] Split parser diagnostic and binder diagnostic --- .../reference/classStaticBlock22.errors.txt | 129 ++++++------------ .../baselines/reference/classStaticBlock22.js | 77 +++-------- .../reference/classStaticBlock22.symbols | 104 +++++--------- .../reference/classStaticBlock22.types | 95 +++---------- .../reference/classStaticBlock26.errors.txt | 84 ++++++++++-- .../baselines/reference/classStaticBlock26.js | 50 ++++++- .../reference/classStaticBlock26.symbols | 38 +++++- .../reference/classStaticBlock26.types | 62 ++++++++- .../classStaticBlock/classStaticBlock22.ts | 52 +++---- .../classStaticBlock/classStaticBlock26.ts | 23 +++- 10 files changed, 351 insertions(+), 363 deletions(-) diff --git a/tests/baselines/reference/classStaticBlock22.errors.txt b/tests/baselines/reference/classStaticBlock22.errors.txt index 8a12b3ffe84cd..cb89b33e3bc3b 100644 --- a/tests/baselines/reference/classStaticBlock22.errors.txt +++ b/tests/baselines/reference/classStaticBlock22.errors.txt @@ -1,84 +1,59 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,5): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(16,10): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(19,5): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(28,14): error TS1005: ':' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,9): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(31,14): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,10): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(37,15): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,5): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(53,10): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS1003: Identifier expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,15): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(54,20): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,17): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,22): error TS1109: Expression expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(87,24): error TS1005: ';' expected. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,17): error TS18037: Await expression cannot be used inside a class static block. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): error TS1109: Expression expected. +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 (18 errors) ==== +==== 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 { - 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 { - function await() {}; // illegal - } - static { - class await {}; // illegal - } - static { - ({ await }); // illegal short-hand property reference - ~ -!!! error TS1005: ':' expected. + function await() { }; // illegal + ~~~~~ +!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. } static { - ({ [await]: 1 }); // illegal - ~~~~~ -!!! error TS18037: Await expression cannot be used inside a class static block. - ~ -!!! error TS1109: Expression expected. + 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) - [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. - }; + 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 + (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 + (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 @@ -86,29 +61,16 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e static { (() => await); // legal, 'await' is inside of a new function boundary } - 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 { class E { - constructor () { await; } - method () { await; } - get accessor () { + constructor() { await; } + method() { await; } + get accessor() { await; return 1; } - set accessor (v: any) { + set accessor(v: any) { await; } propLambda = () => { await; } @@ -117,31 +79,16 @@ tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts(88,23): e } static { class S { - static method () { await; } - static get accessor () { + static method() { await; } + static get accessor() { await; return 1; } - static set accessor (v: any) { + static set accessor(v: any) { await; } static propLambda = () => { await; } static propFunc = function () { await; } } } - 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/classStaticBlock22.js b/tests/baselines/reference/classStaticBlock22.js index 1757b74fa225f..bed746875acdf 100644 --- a/tests/baselines/reference/classStaticBlock22.js +++ b/tests/baselines/reference/classStaticBlock22.js @@ -14,35 +14,23 @@ class C { let await; // illegal, cannot declare a new binding for await } static { - await; // illegal + function await() { }; // illegal } static { - await(1); // illegal - } - static { - function await() {}; // illegal - } - static { - class await {}; // illegal - } - static { - ({ await }); // illegal short-hand property reference - } - static { - ({ [await]: 1 }); // illegal + class await { }; // illegal } + static { class D { - await = 1; // legal - x = await; // legal (initializers have an implicit function boundary) - [await] = 1; // illegal (computed property names are evaluated outside of a class body - }; + 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 + (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 + (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 @@ -50,19 +38,16 @@ class C { static { (() => await); // legal, 'await' is inside of a new function boundary } - static { - await: // illegal, 'await' cannot be used as a label - break await; // illegal, 'await' cannot be used as a label - } + static { class E { - constructor () { await; } - method () { await; } - get accessor () { + constructor() { await; } + method() { await; } + get accessor() { await; return 1; } - set accessor (v: any) { + set accessor(v: any) { await; } propLambda = () => { await; } @@ -71,23 +56,18 @@ class C { } static { class S { - static method () { await; } - static get accessor () { + static method() { await; } + static get accessor() { await; return 1; } - static set accessor (v: any) { + static set accessor(v: any) { await; } static propLambda = () => { await; } static propFunc = function () { await; } } } - static { - function f (await) {} - const ff = (await) => {} - const fff = await => {} - } } //// [classStaticBlock22.js] @@ -105,12 +85,6 @@ class C { static { let await; // illegal, cannot declare a new binding for await } - static { - await ; // illegal - } - static { - await (1); // illegal - } static { function await() { } ; // illegal @@ -120,17 +94,10 @@ class C { } ; // illegal } - static { - ({ await: }); // illegal short-hand property reference - } - static { - ({ [await ]: 1 }); // illegal - } static { class D { await = 1; // legal x = await; // legal (initializers have an implicit function boundary) - [await ] = 1; // illegal (computed property names are evaluated outside of a class body } ; } @@ -147,11 +114,6 @@ class C { static { (() => await); // legal, 'await' is inside of a new function boundary } - static { - await ; - break ; - await ; // illegal, 'await' cannot be used as a label - } static { class E { constructor() { await; } @@ -181,11 +143,4 @@ class C { static propFunc = function () { await; }; } } - static { - function f(await) { } - const ff = (await ); - { } - const fff = await ; - { } - } } diff --git a/tests/baselines/reference/classStaticBlock22.symbols b/tests/baselines/reference/classStaticBlock22.symbols index 56735f54b666c..9f78f245322f3 100644 --- a/tests/baselines/reference/classStaticBlock22.symbols +++ b/tests/baselines/reference/classStaticBlock22.symbols @@ -22,50 +22,34 @@ class C { >await : Symbol(await, Decl(classStaticBlock22.ts, 12, 7)) } static { - await; // illegal + function await() { }; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 14, 10)) } static { - await(1); // illegal - } - static { - function await() {}; // illegal ->await : Symbol(await, Decl(classStaticBlock22.ts, 20, 10)) - } - static { - class await {}; // illegal ->await : Symbol(await, Decl(classStaticBlock22.ts, 23, 10)) - } - static { - ({ await }); // illegal short-hand property reference ->await : Symbol(await, Decl(classStaticBlock22.ts, 27, 6)) - } - static { - ({ [await]: 1 }); // illegal ->[await] : Symbol([await], Decl(classStaticBlock22.ts, 30, 6)) + class await { }; // illegal +>await : Symbol(await, Decl(classStaticBlock22.ts, 17, 10)) } + static { class D { ->D : Symbol(D, Decl(classStaticBlock22.ts, 32, 10)) +>D : Symbol(D, Decl(classStaticBlock22.ts, 21, 10)) - await = 1; // legal ->await : Symbol(D.await, Decl(classStaticBlock22.ts, 33, 13)) + 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, 34, 18)) + 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)) - [await] = 1; // illegal (computed property names are evaluated outside of a class body ->[await] : Symbol(D[await], Decl(classStaticBlock22.ts, 35, 18)) - - }; + }; } static { - (function await() {}); // legal, 'await' in function expression name not bound inside of static block ->await : Symbol(await, Decl(classStaticBlock22.ts, 40, 5)) + (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, 43, 5)) + (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 @@ -75,86 +59,72 @@ class C { (() => await); // legal, 'await' is inside of a new function boundary >await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) } - static { - await: // illegal, 'await' cannot be used as a label - break await; // illegal, 'await' cannot be used as a label - } + static { class E { ->E : Symbol(E, Decl(classStaticBlock22.ts, 55, 10)) +>E : Symbol(E, Decl(classStaticBlock22.ts, 40, 10)) - constructor () { await; } + constructor() { await; } >await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) - method () { await; } ->method : Symbol(E.method, Decl(classStaticBlock22.ts, 57, 31)) + 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, 58, 26), Decl(classStaticBlock22.ts, 62, 7)) + 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, 58, 26), Decl(classStaticBlock22.ts, 62, 7)) ->v : Symbol(v, Decl(classStaticBlock22.ts, 63, 20)) + 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, 65, 7)) +>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, 66, 35)) +>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, 70, 10)) +>S : Symbol(S, Decl(classStaticBlock22.ts, 55, 10)) - static method () { await; } ->method : Symbol(S.method, Decl(classStaticBlock22.ts, 71, 13)) + 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, 72, 33), Decl(classStaticBlock22.ts, 76, 7)) + 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, 72, 33), Decl(classStaticBlock22.ts, 76, 7)) ->v : Symbol(v, Decl(classStaticBlock22.ts, 77, 27)) + 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, 79, 7)) +>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, 80, 42)) +>propFunc : Symbol(S.propFunc, Decl(classStaticBlock22.ts, 65, 42)) >await : Symbol(await, Decl(classStaticBlock22.ts, 0, 3)) } } - static { - function f (await) {} ->f : Symbol(f, Decl(classStaticBlock22.ts, 84, 10)) ->await : Symbol(await, Decl(classStaticBlock22.ts, 85, 16)) - - const ff = (await) => {} ->ff : Symbol(ff, Decl(classStaticBlock22.ts, 86, 9)) - - const fff = await => {} ->fff : Symbol(fff, Decl(classStaticBlock22.ts, 87, 9)) - } } diff --git a/tests/baselines/reference/classStaticBlock22.types b/tests/baselines/reference/classStaticBlock22.types index e581d5b18851d..8334f1b584217 100644 --- a/tests/baselines/reference/classStaticBlock22.types +++ b/tests/baselines/reference/classStaticBlock22.types @@ -27,70 +27,38 @@ class C { >await : any } static { - await; // illegal ->await : any -> : any - } - static { - await(1); // illegal ->await(1) : 1 ->(1) : 1 ->1 : 1 - } - static { - function await() {}; // illegal + function await() { }; // illegal >await : () => void } static { - class await {}; // illegal + class await { }; // illegal >await : await } - static { - ({ await }); // illegal short-hand property reference ->({ await }) : { await: any; } ->{ await } : { await: any; } ->await : any -> : any - } - 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; // legal + await = 1; // legal >await : number >1 : 1 - x = await; // legal (initializers have an implicit function boundary) + x = await; // legal (initializers have an implicit function boundary) >x : "any" >await : "any" - [await] = 1; // illegal (computed property names are evaluated outside of a class body ->[await] : number ->await : any -> : any ->1 : 1 - - }; + }; } static { - (function await() {}); // legal, 'await' in function expression name not bound inside of static block ->(function await() {}) : () => void ->function await() {} : () => void + (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 + (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 { @@ -105,28 +73,19 @@ class C { >() => await : () => "any" >await : "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 { class E { >E : E - constructor () { await; } + constructor() { await; } >await : "any" - method () { await; } + method() { await; } >method : () => void >await : "any" - get accessor () { + get accessor() { >accessor : any await; @@ -135,7 +94,7 @@ class C { return 1; >1 : 1 } - set accessor (v: any) { + set accessor(v: any) { >accessor : any >v : any @@ -157,11 +116,11 @@ class C { class S { >S : S - static method () { await; } + static method() { await; } >method : () => void >await : "any" - static get accessor () { + static get accessor() { >accessor : any await; @@ -170,7 +129,7 @@ class C { return 1; >1 : 1 } - static set accessor (v: any) { + static set accessor(v: any) { >accessor : any >v : any @@ -188,20 +147,4 @@ class C { >await : "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/classStaticBlock26.errors.txt b/tests/baselines/reference/classStaticBlock26.errors.txt index bc5938561ce2a..3c5eb52fb8f34 100644 --- a/tests/baselines/reference/classStaticBlock26.errors.txt +++ b/tests/baselines/reference/classStaticBlock26.errors.txt @@ -1,24 +1,86 @@ -tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(3,13): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(6,13): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. -tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts(9,15): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +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 (3 errors) ==== +==== tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts (18 errors) ==== class C { static { - let await = 1; - ~~~~~ -!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. + 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 { - var await = 1; + ({ [await]: 1 }); // illegal ~~~~~ -!!! error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +!!! 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 { - const await = 1; + ({ 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 TS1359: Identifier expected. 'await' is a reserved word that cannot be used here. +!!! 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 index 7b7ff83dc23c5..ababa6abf24ac 100644 --- a/tests/baselines/reference/classStaticBlock26.js +++ b/tests/baselines/reference/classStaticBlock26.js @@ -1,13 +1,30 @@ //// [classStaticBlock26.ts] class C { static { - let await = 1; + await; // illegal } static { - var await = 1; + await (1); // illegal } static { - const await = 1; + ({ [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 => { } } } @@ -15,12 +32,33 @@ class C { //// [classStaticBlock26.js] class C { static { - let await = 1; + 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 { - var await = 1; + await ; + break ; + await ; // illegal, 'await' cannot be used as a label } static { - const await = 1; + function f(await) { } + const ff = (await ); + { } + const fff = await ; + { } } } diff --git a/tests/baselines/reference/classStaticBlock26.symbols b/tests/baselines/reference/classStaticBlock26.symbols index c104550329ce6..2d3b2717ba213 100644 --- a/tests/baselines/reference/classStaticBlock26.symbols +++ b/tests/baselines/reference/classStaticBlock26.symbols @@ -3,16 +3,42 @@ class C { >C : Symbol(C, Decl(classStaticBlock26.ts, 0, 0)) static { - let await = 1; ->await : Symbol(await, Decl(classStaticBlock26.ts, 2, 11)) + await; // illegal } static { - var await = 1; ->await : Symbol(await, Decl(classStaticBlock26.ts, 5, 11)) + await (1); // illegal } static { - const await = 1; ->await : Symbol(await, Decl(classStaticBlock26.ts, 8, 13)) + ({ [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 index 148518a06ed89..0922330a47533 100644 --- a/tests/baselines/reference/classStaticBlock26.types +++ b/tests/baselines/reference/classStaticBlock26.types @@ -3,19 +3,69 @@ class C { >C : C static { - let await = 1; ->await : number + await; // illegal +>await : any +> : any + } + static { + await (1); // illegal +>await (1) : 1 +>(1) : 1 >1 : 1 } static { - var await = 1; ->await : number + ({ [await]: 1 }); // illegal +>({ [await]: 1 }) : { [x: number]: number; } +>{ [await]: 1 } : { [x: number]: number; } +>[await] : number +>await : any +> : any >1 : 1 } static { - const await = 1; ->await : 1 + 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/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts index e1d605290a37e..8d3be9861aa71 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock22.ts @@ -15,35 +15,23 @@ class C { let await; // illegal, cannot declare a new binding for await } static { - await; // illegal + function await() { }; // illegal } static { - await(1); // illegal - } - static { - function await() {}; // illegal - } - static { - class await {}; // illegal - } - static { - ({ await }); // illegal short-hand property reference - } - static { - ({ [await]: 1 }); // illegal + class await { }; // illegal } + static { class D { - await = 1; // legal - x = await; // legal (initializers have an implicit function boundary) - [await] = 1; // illegal (computed property names are evaluated outside of a class body - }; + 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 + (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 + (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 @@ -51,19 +39,16 @@ class C { static { (() => await); // legal, 'await' is inside of a new function boundary } - static { - await: // illegal, 'await' cannot be used as a label - break await; // illegal, 'await' cannot be used as a label - } + static { class E { - constructor () { await; } - method () { await; } - get accessor () { + constructor() { await; } + method() { await; } + get accessor() { await; return 1; } - set accessor (v: any) { + set accessor(v: any) { await; } propLambda = () => { await; } @@ -72,21 +57,16 @@ class C { } static { class S { - static method () { await; } - static get accessor () { + static method() { await; } + static get accessor() { await; return 1; } - static set accessor (v: any) { + static set accessor(v: any) { await; } static propLambda = () => { await; } static propFunc = function () { await; } } } - static { - function f (await) {} - const ff = (await) => {} - const fff = await => {} - } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts index 0524027744119..1081729acdb2d 100644 --- a/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts @@ -2,12 +2,29 @@ class C { static { - let await = 1; + await; // illegal } static { - var await = 1; + await (1); // illegal } static { - const await = 1; + ({ [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 => { } } }