From a4cabe725b413f154f738b48c1fe2f053cff7d26 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 12 Sep 2022 15:12:11 -0400 Subject: [PATCH] Support for auto-accessor fields from the Stage 3 Decorators proposal (#49705) * Support for auto-accessor fields * Add tests, ensure accessors are initialized in ctor * classFields cleanup and PR feedback --- scripts/eslint/rules/debug-assert.js | 2 +- src/compiler/binder.ts | 5 +- src/compiler/checker.ts | 93 +- src/compiler/diagnosticMessages.json | 12 + src/compiler/emitter.ts | 187 ++- src/compiler/factory/nodeFactory.ts | 69 +- src/compiler/factory/nodeTests.ts | 5 + src/compiler/factory/parenthesizerRules.ts | 4 +- src/compiler/factory/utilities.ts | 137 ++ src/compiler/parser.ts | 4 + src/compiler/program.ts | 5 +- src/compiler/scanner.ts | 1 + src/compiler/transformers/classFields.ts | 1215 +++++++++----- src/compiler/transformers/legacyDecorators.ts | 2 +- src/compiler/transformers/utilities.ts | 4 +- src/compiler/types.ts | 57 +- src/compiler/utilities.ts | 17 +- src/compiler/utilitiesPublic.ts | 28 +- src/compiler/visitorPublic.ts | 15 +- .../4.0/nodeFactoryTopLevelExports.ts | 2 +- src/harness/fourslashInterfaceImpl.ts | 1 + src/services/classifier.ts | 1 + src/services/codefixes/generateAccessors.ts | 12 +- src/services/codefixes/helpers.ts | 40 +- src/services/completions.ts | 1 + src/services/formatting/rules.ts | 1 + src/services/symbolDisplay.ts | 6 +- src/services/types.ts | 3 + src/testRunner/tsconfig.json | 1 + .../unittests/evaluation/autoAccessors.ts | 113 ++ .../reference/api/tsserverlibrary.d.ts | 526 +++--- tests/baselines/reference/api/typescript.d.ts | 526 +++--- .../reference/autoAccessor1(target=es2015).js | 39 + .../autoAccessor1(target=es2015).symbols | 17 + .../autoAccessor1(target=es2015).types | 19 + .../reference/autoAccessor1(target=es2022).js | 24 + .../autoAccessor1(target=es2022).symbols | 17 + .../autoAccessor1(target=es2022).types | 19 + .../autoAccessor1(target=es5).errors.txt | 22 + .../autoAccessor1(target=es5).symbols | 17 + .../reference/autoAccessor1(target=es5).types | 19 + .../reference/autoAccessor1(target=esnext).js | 16 + .../autoAccessor1(target=esnext).symbols | 17 + .../autoAccessor1(target=esnext).types | 19 + .../reference/autoAccessor2(target=es2015).js | 48 + .../autoAccessor2(target=es2015).symbols | 37 + .../autoAccessor2(target=es2015).types | 47 + .../reference/autoAccessor2(target=es2022).js | 42 + .../autoAccessor2(target=es2022).symbols | 37 + .../autoAccessor2(target=es2022).types | 47 + .../reference/autoAccessor2(target=esnext).js | 34 + .../autoAccessor2(target=esnext).symbols | 37 + .../autoAccessor2(target=esnext).types | 47 + .../reference/autoAccessor3(target=es2015).js | 39 + .../autoAccessor3(target=es2015).symbols | 17 + .../autoAccessor3(target=es2015).types | 19 + .../reference/autoAccessor3(target=es2022).js | 24 + .../autoAccessor3(target=es2022).symbols | 17 + .../autoAccessor3(target=es2022).types | 19 + .../autoAccessor3(target=es5).errors.txt | 22 + .../autoAccessor3(target=es5).symbols | 17 + .../reference/autoAccessor3(target=es5).types | 19 + .../reference/autoAccessor3(target=esnext).js | 16 + .../autoAccessor3(target=esnext).symbols | 17 + .../autoAccessor3(target=esnext).types | 19 + .../reference/autoAccessor4(target=es2015).js | 39 + .../autoAccessor4(target=es2015).symbols | 17 + .../autoAccessor4(target=es2015).types | 19 + .../reference/autoAccessor4(target=es2022).js | 24 + .../autoAccessor4(target=es2022).symbols | 17 + .../autoAccessor4(target=es2022).types | 19 + .../autoAccessor4(target=es5).errors.txt | 22 + .../autoAccessor4(target=es5).symbols | 17 + .../reference/autoAccessor4(target=es5).types | 19 + .../reference/autoAccessor4(target=esnext).js | 16 + .../autoAccessor4(target=esnext).symbols | 17 + .../autoAccessor4(target=esnext).types | 19 + .../autoAccessor5(target=es2015).errors.txt | 17 + .../reference/autoAccessor5(target=es2015).js | 50 + .../autoAccessor5(target=es2015).symbols | 31 + .../autoAccessor5(target=es2015).types | 35 + .../autoAccessor5(target=es2022).errors.txt | 17 + .../reference/autoAccessor5(target=es2022).js | 34 + .../autoAccessor5(target=es2022).symbols | 31 + .../autoAccessor5(target=es2022).types | 35 + .../autoAccessor5(target=es5).errors.txt | 29 + .../reference/autoAccessor5(target=es5).js | 81 + .../autoAccessor5(target=es5).symbols | 31 + .../reference/autoAccessor5(target=es5).types | 35 + .../autoAccessor5(target=esnext).errors.txt | 17 + .../reference/autoAccessor5(target=esnext).js | 23 + .../autoAccessor5(target=esnext).symbols | 31 + .../autoAccessor5(target=esnext).types | 35 + ...,usedefineforclassfields=false).errors.txt | 18 + ...t=es2015,usedefineforclassfields=false).js | 44 + ...015,usedefineforclassfields=false).symbols | 27 + ...s2015,usedefineforclassfields=false).types | 28 + ...5,usedefineforclassfields=true).errors.txt | 18 + ...et=es2015,usedefineforclassfields=true).js | 49 + ...2015,usedefineforclassfields=true).symbols | 27 + ...es2015,usedefineforclassfields=true).types | 28 + ...,usedefineforclassfields=false).errors.txt | 18 + ...t=es2022,usedefineforclassfields=false).js | 29 + ...022,usedefineforclassfields=false).symbols | 27 + ...s2022,usedefineforclassfields=false).types | 28 + ...2,usedefineforclassfields=true).errors.txt | 18 + ...et=es2022,usedefineforclassfields=true).js | 26 + ...2022,usedefineforclassfields=true).symbols | 27 + ...es2022,usedefineforclassfields=true).types | 28 + ...,usedefineforclassfields=false).errors.txt | 18 + ...t=esnext,usedefineforclassfields=false).js | 26 + ...ext,usedefineforclassfields=false).symbols | 27 + ...snext,usedefineforclassfields=false).types | 28 + ...t,usedefineforclassfields=true).errors.txt | 18 + ...et=esnext,usedefineforclassfields=true).js | 24 + ...next,usedefineforclassfields=true).symbols | 27 + ...esnext,usedefineforclassfields=true).types | 28 + ...t=es2015,usedefineforclassfields=false).js | 41 + ...015,usedefineforclassfields=false).symbols | 24 + ...s2015,usedefineforclassfields=false).types | 26 + ...et=es2015,usedefineforclassfields=true).js | 41 + ...2015,usedefineforclassfields=true).symbols | 24 + ...es2015,usedefineforclassfields=true).types | 26 + ...t=es2022,usedefineforclassfields=false).js | 29 + ...022,usedefineforclassfields=false).symbols | 24 + ...s2022,usedefineforclassfields=false).types | 26 + ...et=es2022,usedefineforclassfields=true).js | 25 + ...2022,usedefineforclassfields=true).symbols | 24 + ...es2022,usedefineforclassfields=true).types | 26 + ...t=esnext,usedefineforclassfields=false).js | 26 + ...ext,usedefineforclassfields=false).symbols | 24 + ...snext,usedefineforclassfields=false).types | 26 + ...et=esnext,usedefineforclassfields=true).js | 23 + ...next,usedefineforclassfields=true).symbols | 24 + ...esnext,usedefineforclassfields=true).types | 26 + tests/baselines/reference/autoAccessor8.js | 49 + .../baselines/reference/autoAccessor8.symbols | 37 + tests/baselines/reference/autoAccessor8.types | 37 + .../reference/autoAccessorAllowedModifiers.js | 49 + ...autoAccessorDisallowedModifiers.errors.txt | 124 ++ .../autoAccessorDisallowedModifiers.js | 66 + ...mentalDecorators(target=es2015).errors.txt | 27 + ...orExperimentalDecorators(target=es2015).js | 64 + ...erimentalDecorators(target=es2015).symbols | 41 + ...xperimentalDecorators(target=es2015).types | 39 + ...mentalDecorators(target=es2022).errors.txt | 27 + ...orExperimentalDecorators(target=es2022).js | 49 + ...erimentalDecorators(target=es2022).symbols | 41 + ...xperimentalDecorators(target=es2022).types | 39 + ...mentalDecorators(target=esnext).errors.txt | 27 + ...orExperimentalDecorators(target=esnext).js | 41 + ...erimentalDecorators(target=esnext).symbols | 41 + ...xperimentalDecorators(target=esnext).types | 39 + .../completionsOverridingMethod15.baseline | 12 + .../completionsOverridingMethod16.baseline | 12 + .../reference/controlFlowPrivateClassField.js | 4 +- .../reference/decoratorOnClassProperty13.js | 37 + .../decoratorOnClassProperty13.symbols | 15 + .../decoratorOnClassProperty13.types | 14 + .../reference/privateIdentifierChain.1.js | 8 +- ...ameComputedPropertyName2(target=es2015).js | 2 +- .../reference/privateNameDuplicateField.js | 14 +- ...FieldDestructuredBinding(target=es2015).js | 12 +- .../reference/privateNameMethodAssignment.js | 2 +- ...rivateNameNestedClassAccessorsShadowing.js | 2 +- .../privateNameNestedClassMethodShadowing.js | 2 +- ...FieldDestructuredBinding(target=es2015).js | 12 +- ...FieldDestructuredBinding(target=es2022).js | 14 +- ...FieldDestructuredBinding(target=esnext).js | 14 +- .../privateNameStaticMethodAssignment.js | 2 +- ...eStaticsAndStaticMethods(target=es2022).js | 14 +- ...eStaticsAndStaticMethods(target=esnext).js | 14 +- .../privateNamesAndGenericClasses-2.js | 10 +- .../privateNamesAndMethods(target=es2022).js | 14 +- .../privateNamesAndMethods(target=esnext).js | 14 +- ...ateNamesAndStaticMethods(target=es2022).js | 14 +- ...ateNamesAndStaticMethods(target=esnext).js | 14 +- ...nfoDisplayPartsClassAutoAccessors.baseline | 1422 +++++++++++++++++ ...eOfThisInStaticMembers12(target=es2022).js | 17 +- ...eOfThisInStaticMembers12(target=esnext).js | 17 +- .../autoAccessor1.ts | 9 + .../autoAccessor2.ts | 18 + .../autoAccessor3.ts | 9 + .../autoAccessor4.ts | 9 + .../autoAccessor5.ts | 13 + .../autoAccessor6.ts | 14 + .../autoAccessor7.ts | 14 + .../autoAccessor8.ts | 20 + .../autoAccessorAllowedModifiers.ts | 29 + .../autoAccessorDisallowedModifiers.ts | 39 + .../autoAccessorExperimentalDecorators.ts | 20 + .../property/decoratorOnClassProperty13.ts | 7 + ...ImplementClassAbstractGettersAndSetters.ts | 5 + .../completionEntryForClassMembers.ts | 4 +- .../completionListInNamedClassExpression.ts | 17 +- ...quickInfoDisplayPartsClassAutoAccessors.ts | 33 + 196 files changed, 7457 insertions(+), 1227 deletions(-) create mode 100644 src/testRunner/unittests/evaluation/autoAccessors.ts create mode 100644 tests/baselines/reference/autoAccessor1(target=es2015).js create mode 100644 tests/baselines/reference/autoAccessor1(target=es2015).symbols create mode 100644 tests/baselines/reference/autoAccessor1(target=es2015).types create mode 100644 tests/baselines/reference/autoAccessor1(target=es2022).js create mode 100644 tests/baselines/reference/autoAccessor1(target=es2022).symbols create mode 100644 tests/baselines/reference/autoAccessor1(target=es2022).types create mode 100644 tests/baselines/reference/autoAccessor1(target=es5).errors.txt create mode 100644 tests/baselines/reference/autoAccessor1(target=es5).symbols create mode 100644 tests/baselines/reference/autoAccessor1(target=es5).types create mode 100644 tests/baselines/reference/autoAccessor1(target=esnext).js create mode 100644 tests/baselines/reference/autoAccessor1(target=esnext).symbols create mode 100644 tests/baselines/reference/autoAccessor1(target=esnext).types create mode 100644 tests/baselines/reference/autoAccessor2(target=es2015).js create mode 100644 tests/baselines/reference/autoAccessor2(target=es2015).symbols create mode 100644 tests/baselines/reference/autoAccessor2(target=es2015).types create mode 100644 tests/baselines/reference/autoAccessor2(target=es2022).js create mode 100644 tests/baselines/reference/autoAccessor2(target=es2022).symbols create mode 100644 tests/baselines/reference/autoAccessor2(target=es2022).types create mode 100644 tests/baselines/reference/autoAccessor2(target=esnext).js create mode 100644 tests/baselines/reference/autoAccessor2(target=esnext).symbols create mode 100644 tests/baselines/reference/autoAccessor2(target=esnext).types create mode 100644 tests/baselines/reference/autoAccessor3(target=es2015).js create mode 100644 tests/baselines/reference/autoAccessor3(target=es2015).symbols create mode 100644 tests/baselines/reference/autoAccessor3(target=es2015).types create mode 100644 tests/baselines/reference/autoAccessor3(target=es2022).js create mode 100644 tests/baselines/reference/autoAccessor3(target=es2022).symbols create mode 100644 tests/baselines/reference/autoAccessor3(target=es2022).types create mode 100644 tests/baselines/reference/autoAccessor3(target=es5).errors.txt create mode 100644 tests/baselines/reference/autoAccessor3(target=es5).symbols create mode 100644 tests/baselines/reference/autoAccessor3(target=es5).types create mode 100644 tests/baselines/reference/autoAccessor3(target=esnext).js create mode 100644 tests/baselines/reference/autoAccessor3(target=esnext).symbols create mode 100644 tests/baselines/reference/autoAccessor3(target=esnext).types create mode 100644 tests/baselines/reference/autoAccessor4(target=es2015).js create mode 100644 tests/baselines/reference/autoAccessor4(target=es2015).symbols create mode 100644 tests/baselines/reference/autoAccessor4(target=es2015).types create mode 100644 tests/baselines/reference/autoAccessor4(target=es2022).js create mode 100644 tests/baselines/reference/autoAccessor4(target=es2022).symbols create mode 100644 tests/baselines/reference/autoAccessor4(target=es2022).types create mode 100644 tests/baselines/reference/autoAccessor4(target=es5).errors.txt create mode 100644 tests/baselines/reference/autoAccessor4(target=es5).symbols create mode 100644 tests/baselines/reference/autoAccessor4(target=es5).types create mode 100644 tests/baselines/reference/autoAccessor4(target=esnext).js create mode 100644 tests/baselines/reference/autoAccessor4(target=esnext).symbols create mode 100644 tests/baselines/reference/autoAccessor4(target=esnext).types create mode 100644 tests/baselines/reference/autoAccessor5(target=es2015).errors.txt create mode 100644 tests/baselines/reference/autoAccessor5(target=es2015).js create mode 100644 tests/baselines/reference/autoAccessor5(target=es2015).symbols create mode 100644 tests/baselines/reference/autoAccessor5(target=es2015).types create mode 100644 tests/baselines/reference/autoAccessor5(target=es2022).errors.txt create mode 100644 tests/baselines/reference/autoAccessor5(target=es2022).js create mode 100644 tests/baselines/reference/autoAccessor5(target=es2022).symbols create mode 100644 tests/baselines/reference/autoAccessor5(target=es2022).types create mode 100644 tests/baselines/reference/autoAccessor5(target=es5).errors.txt create mode 100644 tests/baselines/reference/autoAccessor5(target=es5).js create mode 100644 tests/baselines/reference/autoAccessor5(target=es5).symbols create mode 100644 tests/baselines/reference/autoAccessor5(target=es5).types create mode 100644 tests/baselines/reference/autoAccessor5(target=esnext).errors.txt create mode 100644 tests/baselines/reference/autoAccessor5(target=esnext).js create mode 100644 tests/baselines/reference/autoAccessor5(target=esnext).symbols create mode 100644 tests/baselines/reference/autoAccessor5(target=esnext).types create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).errors.txt create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).js create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).errors.txt create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).types create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).errors.txt create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).js create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).errors.txt create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).types create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).errors.txt create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).js create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).errors.txt create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).types create mode 100644 tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).js create mode 100644 tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).types create mode 100644 tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).js create mode 100644 tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).types create mode 100644 tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).js create mode 100644 tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).symbols create mode 100644 tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).types create mode 100644 tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).js create mode 100644 tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).symbols create mode 100644 tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).types create mode 100644 tests/baselines/reference/autoAccessor8.js create mode 100644 tests/baselines/reference/autoAccessor8.symbols create mode 100644 tests/baselines/reference/autoAccessor8.types create mode 100644 tests/baselines/reference/autoAccessorAllowedModifiers.js create mode 100644 tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt create mode 100644 tests/baselines/reference/autoAccessorDisallowedModifiers.js create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).errors.txt create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).js create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).symbols create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).types create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).errors.txt create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).js create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).symbols create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).types create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).errors.txt create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).js create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).symbols create mode 100644 tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).types create mode 100644 tests/baselines/reference/decoratorOnClassProperty13.js create mode 100644 tests/baselines/reference/decoratorOnClassProperty13.symbols create mode 100644 tests/baselines/reference/decoratorOnClassProperty13.types create mode 100644 tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor8.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts create mode 100644 tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts diff --git a/scripts/eslint/rules/debug-assert.js b/scripts/eslint/rules/debug-assert.js index 5d416afbd2565..7f01a43c9c30b 100644 --- a/scripts/eslint/rules/debug-assert.js +++ b/scripts/eslint/rules/debug-assert.js @@ -46,7 +46,7 @@ module.exports = createRule({ context.report({ messageId: "secondArgumentDebugAssertError", node: message1Node }); } - if (argsLen < 3) { + if (argsLen !== 3) { return; } diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 6ffe3a7ef526e..1e347f9d81e15 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2732,7 +2732,10 @@ namespace ts { } function bindPropertyWorker(node: PropertyDeclaration | PropertySignature) { - return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); + const isAutoAccessor = isAutoAccessorPropertyDeclaration(node); + const includes = isAutoAccessor ? SymbolFlags.Accessor : SymbolFlags.Property; + const excludes = isAutoAccessor ? SymbolFlags.AccessorExcludes : SymbolFlags.PropertyExcludes; + return bindPropertyOrMethodOrAccessor(node, includes | (node.questionToken ? SymbolFlags.Optional : SymbolFlags.None), excludes); } function bindAnonymousTypeWorker(node: TypeLiteralNode | MappedTypeNode | JSDocTypeLiteral) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 862fb23fa361e..f30f8e9d00a42 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9083,7 +9083,7 @@ namespace ts { return getTypeForBindingElement(declaration as BindingElement); } - const isProperty = isPropertyDeclaration(declaration) || isPropertySignature(declaration); + const isProperty = isPropertyDeclaration(declaration) && !hasAccessorModifier(declaration) || isPropertySignature(declaration); const isOptional = includeOptionality && ( isProperty && !!declaration.questionToken || isParameter(declaration) && (!!declaration.questionToken || isJSDocOptionalParameter(declaration)) || @@ -9831,21 +9831,25 @@ namespace ts { return type; } - function getAnnotatedAccessorTypeNode(accessor: AccessorDeclaration | undefined): TypeNode | undefined { + function getAnnotatedAccessorTypeNode(accessor: AccessorDeclaration | PropertyDeclaration | undefined): TypeNode | undefined { if (accessor) { - if (accessor.kind === SyntaxKind.GetAccessor) { - const getterTypeAnnotation = getEffectiveReturnTypeNode(accessor); - return getterTypeAnnotation; - } - else { - const setterTypeAnnotation = getEffectiveSetAccessorTypeAnnotationNode(accessor); - return setterTypeAnnotation; + switch (accessor.kind) { + case SyntaxKind.GetAccessor: + const getterTypeAnnotation = getEffectiveReturnTypeNode(accessor); + return getterTypeAnnotation; + case SyntaxKind.SetAccessor: + const setterTypeAnnotation = getEffectiveSetAccessorTypeAnnotationNode(accessor); + return setterTypeAnnotation; + case SyntaxKind.PropertyDeclaration: + Debug.assert(hasAccessorModifier(accessor)); + const accessorTypeAnnotation = getEffectiveTypeAnnotationNode(accessor); + return accessorTypeAnnotation; } } return undefined; } - function getAnnotatedAccessorType(accessor: AccessorDeclaration | undefined): Type | undefined { + function getAnnotatedAccessorType(accessor: AccessorDeclaration | PropertyDeclaration | undefined): Type | undefined { const node = getAnnotatedAccessorTypeNode(accessor); return node && getTypeFromTypeNode(node); } @@ -9867,12 +9871,16 @@ namespace ts { } const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); + const accessor = tryCast(getDeclarationOfKind(symbol, SyntaxKind.PropertyDeclaration), isAutoAccessorPropertyDeclaration); + // We try to resolve a getter type annotation, a setter type annotation, or a getter function // body return type inference, in that order. let type = getter && isInJSFile(getter) && getTypeForDeclarationFromJSDocComment(getter) || getAnnotatedAccessorType(getter) || getAnnotatedAccessorType(setter) || - getter && getter.body && getReturnTypeFromBody(getter); + getAnnotatedAccessorType(accessor) || + getter && getter.body && getReturnTypeFromBody(getter) || + accessor && accessor.initializer && getWidenedTypeForVariableLikeDeclaration(accessor, /*includeOptionality*/ true); if (!type) { if (setter && !isPrivateWithinAmbient(setter)) { errorOrSuggestion(noImplicitAny, setter, Diagnostics.Property_0_implicitly_has_type_any_because_its_set_accessor_lacks_a_parameter_type_annotation, symbolToString(symbol)); @@ -9880,6 +9888,9 @@ namespace ts { else if (getter && !isPrivateWithinAmbient(getter)) { errorOrSuggestion(noImplicitAny, getter, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol)); } + else if (accessor && !isPrivateWithinAmbient(accessor)) { + errorOrSuggestion(noImplicitAny, accessor, Diagnostics.Member_0_implicitly_has_an_1_type, symbolToString(symbol), "any"); + } type = anyType; } if (!popTypeResolution()) { @@ -9889,6 +9900,9 @@ namespace ts { else if (getAnnotatedAccessorTypeNode(setter)) { error(setter, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol)); } + else if (getAnnotatedAccessorTypeNode(accessor)) { + error(setter, Diagnostics._0_is_referenced_directly_or_indirectly_in_its_own_type_annotation, symbolToString(symbol)); + } else if (getter && noImplicitAny) { error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); } @@ -9905,7 +9919,9 @@ namespace ts { if (!pushTypeResolution(symbol, TypeSystemPropertyName.WriteType)) { return errorType; } - const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); + + const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor) + ?? tryCast(getDeclarationOfKind(symbol, SyntaxKind.PropertyDeclaration), isAutoAccessorPropertyDeclaration); let writeType = getAnnotatedAccessorType(setter); if (!popTypeResolution()) { if (getAnnotatedAccessorTypeNode(setter)) { @@ -11063,8 +11079,10 @@ namespace ts { const members = getMembersOfDeclaration(decl); if (members) { for (const member of members) { - if (isStatic === hasStaticModifier(member) && hasLateBindableName(member)) { - lateBindMember(symbol, earlySymbols, lateSymbols, member); + if (isStatic === hasStaticModifier(member)) { + if (hasLateBindableName(member)) { + lateBindMember(symbol, earlySymbols, lateSymbols, member); + } } } } @@ -11078,8 +11096,10 @@ namespace ts { || isBinaryExpression(member) && isPossiblyAliasedThisProperty(member, assignmentKind) || assignmentKind === AssignmentDeclarationKind.ObjectDefinePrototypeProperty || assignmentKind === AssignmentDeclarationKind.Prototype; // A straight `Prototype` assignment probably can never have a computed name - if (isStatic === !isInstanceMember && hasLateBindableName(member)) { - lateBindMember(symbol, earlySymbols, lateSymbols, member); + if (isStatic === !isInstanceMember) { + if (hasLateBindableName(member)) { + lateBindMember(symbol, earlySymbols, lateSymbols, member); + } } } } @@ -12924,7 +12944,7 @@ namespace ts { } function isOptionalPropertyDeclaration(node: Declaration) { - return isPropertyDeclaration(node) && node.questionToken; + return isPropertyDeclaration(node) && !hasAccessorModifier(node) && node.questionToken; } function isOptionalJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag { @@ -30759,7 +30779,7 @@ namespace ts { // A method or accessor declaration decorator will have two or three arguments (see // `PropertyDecorator` and `MethodDecorator` in core.d.ts). If we are emitting decorators // for ES3, we will only pass two arguments. - const hasPropDesc = parent.kind !== SyntaxKind.PropertyDeclaration && languageVersion !== ScriptTarget.ES3; + const hasPropDesc = languageVersion !== ScriptTarget.ES3 && (!isPropertyDeclaration(parent) || hasAccessorModifier(parent)); return [ createSyntheticExpression(expr, getParentTypeOfClassElement(parent as ClassElement)), createSyntheticExpression(expr, getClassElementPropertyKeyType(parent as ClassElement)), @@ -30778,7 +30798,7 @@ namespace ts { case SyntaxKind.ClassExpression: return 1; case SyntaxKind.PropertyDeclaration: - return 2; + return hasAccessorModifier(node.parent) ? 3 : 2; case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -44189,6 +44209,9 @@ namespace ts { else if (flags & ModifierFlags.Readonly) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "override", "readonly"); } + else if (flags & ModifierFlags.Accessor) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "override", "accessor"); + } else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "override", "async"); } @@ -44210,6 +44233,9 @@ namespace ts { else if (flags & ModifierFlags.Static) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "static"); } + else if (flags & ModifierFlags.Accessor) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "accessor"); + } else if (flags & ModifierFlags.Readonly) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "readonly"); } @@ -44243,6 +44269,9 @@ namespace ts { else if (flags & ModifierFlags.Async) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "async"); } + else if (flags & ModifierFlags.Accessor) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "accessor"); + } else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, "static"); } @@ -44259,6 +44288,23 @@ namespace ts { lastStatic = modifier; break; + case SyntaxKind.AccessorKeyword: + if (flags & ModifierFlags.Accessor) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "accessor"); + } + else if (flags & ModifierFlags.Readonly) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "accessor", "readonly"); + } + else if (flags & ModifierFlags.Ambient) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "accessor", "declare"); + } + else if (node.kind !== SyntaxKind.PropertyDeclaration) { + return grammarErrorOnNode(modifier, Diagnostics.accessor_modifier_can_only_appear_on_a_property_declaration); + } + + flags |= ModifierFlags.Accessor; + break; + case SyntaxKind.ReadonlyKeyword: if (flags & ModifierFlags.Readonly) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "readonly"); @@ -44355,6 +44401,9 @@ namespace ts { if (flags & ModifierFlags.Override) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "abstract", "override"); } + if (flags & ModifierFlags.Accessor) { + return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "abstract", "accessor"); + } } if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.PrivateIdentifier) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_a_private_identifier, "abstract"); @@ -45553,6 +45602,12 @@ namespace ts { if (languageVersion < ScriptTarget.ES2015 && isPrivateIdentifier(node.name)) { return grammarErrorOnNode(node.name, Diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher); } + if (languageVersion < ScriptTarget.ES2015 && isAutoAccessorPropertyDeclaration(node)) { + return grammarErrorOnNode(node.name, Diagnostics.Properties_with_the_accessor_modifier_are_only_available_when_targeting_ECMAScript_2015_and_higher); + } + if (isAutoAccessorPropertyDeclaration(node) && checkGrammarForInvalidQuestionMark(node.questionToken, Diagnostics.An_accessor_property_cannot_be_declared_optional)) { + return true; + } } else if (node.parent.kind === SyntaxKind.InterfaceDeclaration) { if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_an_interface_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6cec02b9e1a41..bc71059ac83aa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -899,6 +899,14 @@ "category": "Error", "code": 1274 }, + "'accessor' modifier can only appear on a property declaration.": { + "category": "Error", + "code": 1275 + }, + "An 'accessor' property cannot be declared optional.": { + "category": "Error", + "code": 1276 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", @@ -7485,5 +7493,9 @@ "'{0}' is automatically exported here.": { "category": "Message", "code": 18044 + }, + "Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher.": { + "category": "Error", + "code": 18045 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4e571c49a8c8c..750f97f361530 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -903,6 +903,10 @@ namespace ts { let nodeIdToGeneratedName: string[]; // Map of generated names for specific nodes. let autoGeneratedIdToGeneratedName: string[]; // Map of generated names for temp and loop variables. let generatedNames: Set; // Set of names generated by the NameGenerator. + let formattedNameTempFlagsStack: (ESMap | undefined)[]; + let formattedNameTempFlags: ESMap | undefined; + let privateNameTempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes. + let privateNameTempFlags: TempFlags; // TempFlags for the current name generation scope. let tempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes. let tempFlags: TempFlags; // TempFlags for the current name generation scope. let reservedNamesStack: Set[]; // Stack of TempFlags reserved in enclosing name generation scopes. @@ -1191,6 +1195,10 @@ namespace ts { nodeIdToGeneratedName = []; autoGeneratedIdToGeneratedName = []; generatedNames = new Set(); + formattedNameTempFlagsStack = []; + formattedNameTempFlags = new Map(); + privateNameTempFlagsStack = []; + privateNameTempFlags = TempFlags.Auto; tempFlagsStack = []; tempFlags = TempFlags.Auto; reservedNamesStack = []; @@ -4954,7 +4962,7 @@ namespace ts { } function getTextOfNode(node: Identifier | PrivateIdentifier | LiteralExpression, includeTrivia?: boolean): string { - if (isGeneratedIdentifier(node)) { + if (isGeneratedIdentifier(node) || isGeneratedPrivateIdentifier(node)) { return generateName(node); } if (isStringLiteral(node) && node.textSourceNode) { @@ -4979,7 +4987,7 @@ namespace ts { function getLiteralTextOfNode(node: LiteralLikeNode, neverAsciiEscape: boolean | undefined, jsxAttributeEscape: boolean): string { if (node.kind === SyntaxKind.StringLiteral && (node as StringLiteral).textSourceNode) { const textSourceNode = (node as StringLiteral).textSourceNode!; - if (isIdentifier(textSourceNode) || isNumericLiteral(textSourceNode)) { + if (isIdentifier(textSourceNode) || isPrivateIdentifier(textSourceNode) || isNumericLiteral(textSourceNode)) { const text = isNumericLiteral(textSourceNode) ? textSourceNode.text : getTextOfNode(textSourceNode); return jsxAttributeEscape ? `"${escapeJsxAttributeString(text)}"` : neverAsciiEscape || (getEmitFlags(node) & EmitFlags.NoAsciiEscaping) ? `"${escapeString(text)}"` : @@ -5006,7 +5014,11 @@ namespace ts { return; } tempFlagsStack.push(tempFlags); - tempFlags = 0; + tempFlags = TempFlags.Auto; + privateNameTempFlagsStack.push(privateNameTempFlags); + privateNameTempFlags = TempFlags.Auto; + formattedNameTempFlagsStack.push(formattedNameTempFlags); + formattedNameTempFlags = undefined; reservedNamesStack.push(reservedNames); } @@ -5018,6 +5030,8 @@ namespace ts { return; } tempFlags = tempFlagsStack.pop()!; + privateNameTempFlags = privateNameTempFlagsStack.pop()!; + formattedNameTempFlags = formattedNameTempFlagsStack.pop(); reservedNames = reservedNamesStack.pop()!; } @@ -5130,7 +5144,7 @@ namespace ts { function generateNameIfNeeded(name: DeclarationName | undefined) { if (name) { - if (isGeneratedIdentifier(name)) { + if (isGeneratedIdentifier(name) || isGeneratedPrivateIdentifier(name)) { generateName(name); } else if (isBindingPattern(name)) { @@ -5142,11 +5156,11 @@ namespace ts { /** * Generate the text for a generated identifier. */ - function generateName(name: GeneratedIdentifier) { + function generateName(name: GeneratedIdentifier | GeneratedPrivateIdentifier) { if ((name.autoGenerateFlags & GeneratedIdentifierFlags.KindMask) === GeneratedIdentifierFlags.Node) { // Node names generate unique names based on their original node // and are cached based on that node's id. - return generateNameCached(getNodeForGeneratedName(name), name.autoGenerateFlags); + return generateNameCached(getNodeForGeneratedName(name), isPrivateIdentifier(name), name.autoGenerateFlags, name.autoGeneratePrefix, name.autoGenerateSuffix); } else { // Auto, Loop, and Unique names are cached based on their unique @@ -5156,9 +5170,9 @@ namespace ts { } } - function generateNameCached(node: Node, flags?: GeneratedIdentifierFlags) { + function generateNameCached(node: Node, privateName: boolean, flags?: GeneratedIdentifierFlags, prefix?: string | GeneratedNamePart, suffix?: string) { const nodeId = getNodeId(node); - return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = generateNameForNode(node, flags)); + return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = generateNameForNode(node, privateName, flags ?? GeneratedIdentifierFlags.None, formatGeneratedNamePart(prefix, generateName), formatGeneratedNamePart(suffix))); } /** @@ -5194,22 +5208,59 @@ namespace ts { return true; } + function getTempFlags(formattedNameKey: string) { + switch (formattedNameKey) { + case "": + return tempFlags; + case "#": + return privateNameTempFlags; + default: + return formattedNameTempFlags?.get(formattedNameKey) ?? TempFlags.Auto; + } + } + + function setTempFlags(formattedNameKey: string, flags: TempFlags) { + switch (formattedNameKey) { + case "": + tempFlags = flags; + break; + case "#": + privateNameTempFlags = flags; + break; + default: + formattedNameTempFlags ??= new Map(); + formattedNameTempFlags.set(formattedNameKey, flags); + break; + } + } + /** * Return the next available name in the pattern _a ... _z, _0, _1, ... * TempFlags._i or TempFlags._n may be used to express a preference for that dedicated name. * Note that names generated by makeTempVariableName and makeUniqueName will never conflict. */ - function makeTempVariableName(flags: TempFlags, reservedInNestedScopes?: boolean): string { + function makeTempVariableName(flags: TempFlags, reservedInNestedScopes: boolean, privateName: boolean, prefix: string, suffix: string): string { + if (prefix.length > 0 && prefix.charCodeAt(0) === CharacterCodes.hash) { + prefix = prefix.slice(1); + } + + // Generate a key to use to acquire a TempFlags counter based on the fixed portions of the generated name. + const key = formatGeneratedName(privateName, prefix, "", suffix); + let tempFlags = getTempFlags(key); + if (flags && !(tempFlags & flags)) { const name = flags === TempFlags._i ? "_i" : "_n"; - if (isUniqueName(name)) { + const fullName = formatGeneratedName(privateName, prefix, name, suffix); + if (isUniqueName(fullName)) { tempFlags |= flags; if (reservedInNestedScopes) { - reserveNameInNestedScopes(name); + reserveNameInNestedScopes(fullName); } - return name; + setTempFlags(key, tempFlags); + return fullName; } } + while (true) { const count = tempFlags & TempFlags.CountMask; tempFlags++; @@ -5218,11 +5269,13 @@ namespace ts { const name = count < 26 ? "_" + String.fromCharCode(CharacterCodes.a + count) : "_" + (count - 26); - if (isUniqueName(name)) { + const fullName = formatGeneratedName(privateName, prefix, name, suffix); + if (isUniqueName(fullName)) { if (reservedInNestedScopes) { - reserveNameInNestedScopes(name); + reserveNameInNestedScopes(fullName); } - return name; + setTempFlags(key, tempFlags); + return fullName; } } } @@ -5235,16 +5288,23 @@ namespace ts { * makeUniqueName are guaranteed to never conflict. * If `optimistic` is set, the first instance will use 'baseName' verbatim instead of 'baseName_1' */ - function makeUniqueName(baseName: string, checkFn: (name: string) => boolean = isUniqueName, optimistic?: boolean, scoped?: boolean): string { + function makeUniqueName(baseName: string, checkFn: (name: string) => boolean = isUniqueName, optimistic: boolean, scoped: boolean, privateName: boolean, prefix: string, suffix: string): string { + if (baseName.length > 0 && baseName.charCodeAt(0) === CharacterCodes.hash) { + baseName = baseName.slice(1); + } + if (prefix.length > 0 && prefix.charCodeAt(0) === CharacterCodes.hash) { + prefix = prefix.slice(1); + } if (optimistic) { - if (checkFn(baseName)) { + const fullName = formatGeneratedName(privateName, prefix, baseName, suffix); + if (checkFn(fullName)) { if (scoped) { - reserveNameInNestedScopes(baseName); + reserveNameInNestedScopes(fullName); } else { - generatedNames.add(baseName); + generatedNames.add(fullName); } - return baseName; + return fullName; } } // Find the first unique 'name_n', where n is a positive number @@ -5253,22 +5313,22 @@ namespace ts { } let i = 1; while (true) { - const generatedName = baseName + i; - if (checkFn(generatedName)) { + const fullName = formatGeneratedName(privateName, prefix, baseName + i, suffix); + if (checkFn(fullName)) { if (scoped) { - reserveNameInNestedScopes(generatedName); + reserveNameInNestedScopes(fullName); } else { - generatedNames.add(generatedName); + generatedNames.add(fullName); } - return generatedName; + return fullName; } i++; } } function makeFileLevelOptimisticUniqueName(name: string) { - return makeUniqueName(name, isFileLevelUniqueName, /*optimistic*/ true); + return makeUniqueName(name, isFileLevelUniqueName, /*optimistic*/ true, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); } /** @@ -5277,7 +5337,7 @@ namespace ts { function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { const name = getTextOfNode(node.name); // Use module/enum name itself if it is unique, otherwise make a unique variation - return isUniqueLocalName(name, node) ? name : makeUniqueName(name); + return isUniqueLocalName(name, node) ? name : makeUniqueName(name, isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); } /** @@ -5287,109 +5347,98 @@ namespace ts { const expr = getExternalModuleName(node)!; // TODO: GH#18217 const baseName = isStringLiteral(expr) ? makeIdentifierFromModuleName(expr.text) : "module"; - return makeUniqueName(baseName); + return makeUniqueName(baseName, isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); } /** * Generates a unique name for a default export. */ function generateNameForExportDefault() { - return makeUniqueName("default"); + return makeUniqueName("default", isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); } /** * Generates a unique name for a class expression. */ function generateNameForClassExpression() { - return makeUniqueName("class"); + return makeUniqueName("class", isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ ""); } - function generateNameForMethodOrAccessor(node: MethodDeclaration | AccessorDeclaration) { + function generateNameForMethodOrAccessor(node: MethodDeclaration | AccessorDeclaration, privateName: boolean, prefix: string, suffix: string) { if (isIdentifier(node.name)) { - return generateNameCached(node.name); + return generateNameCached(node.name, privateName); } - return makeTempVariableName(TempFlags.Auto); + return makeTempVariableName(TempFlags.Auto, /*reservedInNestedScopes*/ false, privateName, prefix, suffix); } /** * Generates a unique name from a node. */ - function generateNameForNode(node: Node, flags?: GeneratedIdentifierFlags): string { + function generateNameForNode(node: Node, privateName: boolean, flags: GeneratedIdentifierFlags, prefix: string, suffix: string): string { switch (node.kind) { case SyntaxKind.Identifier: + case SyntaxKind.PrivateIdentifier: return makeUniqueName( getTextOfNode(node as Identifier), isUniqueName, - !!(flags! & GeneratedIdentifierFlags.Optimistic), - !!(flags! & GeneratedIdentifierFlags.ReservedInNestedScopes) + !!(flags & GeneratedIdentifierFlags.Optimistic), + !!(flags & GeneratedIdentifierFlags.ReservedInNestedScopes), + privateName, + prefix, + suffix ); case SyntaxKind.ModuleDeclaration: case SyntaxKind.EnumDeclaration: + Debug.assert(!prefix && !suffix && !privateName); return generateNameForModuleOrEnum(node as ModuleDeclaration | EnumDeclaration); case SyntaxKind.ImportDeclaration: case SyntaxKind.ExportDeclaration: + Debug.assert(!prefix && !suffix && !privateName); return generateNameForImportOrExportDeclaration(node as ImportDeclaration | ExportDeclaration); case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.ExportAssignment: + Debug.assert(!prefix && !suffix && !privateName); return generateNameForExportDefault(); case SyntaxKind.ClassExpression: + Debug.assert(!prefix && !suffix && !privateName); return generateNameForClassExpression(); case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return generateNameForMethodOrAccessor(node as MethodDeclaration | AccessorDeclaration); + return generateNameForMethodOrAccessor(node as MethodDeclaration | AccessorDeclaration, privateName, prefix, suffix); case SyntaxKind.ComputedPropertyName: - return makeTempVariableName(TempFlags.Auto, /*reserveInNestedScopes*/ true); + return makeTempVariableName(TempFlags.Auto, /*reserveInNestedScopes*/ true, privateName, prefix, suffix); default: - return makeTempVariableName(TempFlags.Auto); + return makeTempVariableName(TempFlags.Auto, /*reserveInNestedScopes*/ false, privateName, prefix, suffix); } } /** * Generates a unique identifier for a node. */ - function makeName(name: GeneratedIdentifier) { + function makeName(name: GeneratedIdentifier | GeneratedPrivateIdentifier) { + const prefix = formatGeneratedNamePart(name.autoGeneratePrefix, generateName); + const suffix = formatGeneratedNamePart (name.autoGenerateSuffix); switch (name.autoGenerateFlags & GeneratedIdentifierFlags.KindMask) { case GeneratedIdentifierFlags.Auto: - return makeTempVariableName(TempFlags.Auto, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes)); + return makeTempVariableName(TempFlags.Auto, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes), isPrivateIdentifier(name), prefix, suffix); case GeneratedIdentifierFlags.Loop: - return makeTempVariableName(TempFlags._i, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes)); + Debug.assertNode(name, isIdentifier); + return makeTempVariableName(TempFlags._i, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes), /*privateName*/ false, prefix, suffix); case GeneratedIdentifierFlags.Unique: return makeUniqueName( idText(name), (name.autoGenerateFlags & GeneratedIdentifierFlags.FileLevel) ? isFileLevelUniqueName : isUniqueName, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.Optimistic), - !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes) + !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes), + isPrivateIdentifier(name), + prefix, + suffix ); } - return Debug.fail("Unsupported GeneratedIdentifierKind."); - } - - /** - * Gets the node from which a name should be generated. - */ - function getNodeForGeneratedName(name: GeneratedIdentifier) { - const autoGenerateId = name.autoGenerateId; - let node = name as Node; - let original = node.original; - while (original) { - node = original; - - // if "node" is a different generated name (having a different - // "autoGenerateId"), use it and stop traversing. - if (isIdentifier(node) - && !!(node.autoGenerateFlags! & GeneratedIdentifierFlags.Node) - && node.autoGenerateId !== autoGenerateId) { - break; - } - - original = node.original; - } - - // otherwise, return the original node for the source; - return node; + return Debug.fail(`Unsupported GeneratedIdentifierKind: ${Debug.formatEnum(name.autoGenerateFlags & GeneratedIdentifierFlags.KindMask, (ts as any).GeneratedIdentifierFlags, /*isFlags*/ true)}.`); } // Comments diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 02e72593f07f7..9d7a2fce604d5 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -60,6 +60,8 @@ namespace ts { createUniqueName, getGeneratedNameForNode, createPrivateIdentifier, + createUniquePrivateName, + getGeneratedPrivateNameForNode, createToken, createSuper, createThis, @@ -819,7 +821,7 @@ namespace ts { } // @api - function createStringLiteralFromNode(sourceNode: PropertyNameLiteral): StringLiteral { + function createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier): StringLiteral { const node = createBaseStringLiteral(getTextOfIdentifierOrLiteral(sourceNode), /*isSingleQuote*/ undefined); node.textSourceNode = sourceNode; return node; @@ -861,10 +863,12 @@ namespace ts { return node; } - function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags) { + function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { const node = createBaseIdentifier(text, /*originalKeywordKind*/ undefined) as Mutable; node.autoGenerateFlags = autoGenerateFlags; node.autoGenerateId = nextAutoGenerateId; + node.autoGeneratePrefix = prefix; + node.autoGenerateSuffix = suffix; nextAutoGenerateId++; return node; } @@ -890,10 +894,10 @@ namespace ts { } // @api - function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean): GeneratedIdentifier { + function createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean, prefix?: string | GeneratedNamePart, suffix?: string): GeneratedIdentifier { let flags = GeneratedIdentifierFlags.Auto; if (reservedInNestedScopes) flags |= GeneratedIdentifierFlags.ReservedInNestedScopes; - const name = createBaseGeneratedIdentifier("", flags); + const name = createBaseGeneratedIdentifier("", flags, prefix, suffix); if (recordTempVariable) { recordTempVariable(name); } @@ -905,35 +909,72 @@ namespace ts { function createLoopVariable(reservedInNestedScopes?: boolean): Identifier { let flags = GeneratedIdentifierFlags.Loop; if (reservedInNestedScopes) flags |= GeneratedIdentifierFlags.ReservedInNestedScopes; - return createBaseGeneratedIdentifier("", flags); + return createBaseGeneratedIdentifier("", flags, /*prefix*/ undefined, /*suffix*/ undefined); } /** Create a unique name based on the supplied text. */ // @api - function createUniqueName(text: string, flags: GeneratedIdentifierFlags = GeneratedIdentifierFlags.None): Identifier { + function createUniqueName(text: string, flags: GeneratedIdentifierFlags = GeneratedIdentifierFlags.None, prefix?: string | GeneratedNamePart, suffix?: string): Identifier { Debug.assert(!(flags & GeneratedIdentifierFlags.KindMask), "Argument out of range: flags"); Debug.assert((flags & (GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel)) !== GeneratedIdentifierFlags.FileLevel, "GeneratedIdentifierFlags.FileLevel cannot be set without also setting GeneratedIdentifierFlags.Optimistic"); - return createBaseGeneratedIdentifier(text, GeneratedIdentifierFlags.Unique | flags); + return createBaseGeneratedIdentifier(text, GeneratedIdentifierFlags.Unique | flags, prefix, suffix); } /** Create a unique name generated for a node. */ // @api - function getGeneratedNameForNode(node: Node | undefined, flags: GeneratedIdentifierFlags = 0): Identifier { + function getGeneratedNameForNode(node: Node | undefined, flags: GeneratedIdentifierFlags = 0, prefix?: string | GeneratedNamePart, suffix?: string): Identifier { Debug.assert(!(flags & GeneratedIdentifierFlags.KindMask), "Argument out of range: flags"); - const name = createBaseGeneratedIdentifier(node && isIdentifier(node) ? idText(node) : "", GeneratedIdentifierFlags.Node | flags); + const text = !node ? "" : + isMemberName(node) ? formatGeneratedName(/*privateName*/ false, prefix, node, suffix, idText) : + `generated@${getNodeId(node)}`; + if (prefix || suffix) flags |= GeneratedIdentifierFlags.Optimistic; + const name = createBaseGeneratedIdentifier(text, GeneratedIdentifierFlags.Node | flags, prefix, suffix); name.original = node; return name; } - // @api - function createPrivateIdentifier(text: string): PrivateIdentifier { - if (!startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text); + function createBasePrivateIdentifier(text: string) { const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as Mutable; node.escapedText = escapeLeadingUnderscores(text); node.transformFlags |= TransformFlags.ContainsClassFields; return node; } + // @api + function createPrivateIdentifier(text: string): PrivateIdentifier { + if (!startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text); + return createBasePrivateIdentifier(text); + } + + function createBaseGeneratedPrivateIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) { + const node = createBasePrivateIdentifier(text); + node.autoGenerateFlags = autoGenerateFlags; + node.autoGenerateId = nextAutoGenerateId; + node.autoGeneratePrefix = prefix; + node.autoGenerateSuffix = suffix; + nextAutoGenerateId++; + return node; + } + + /** Create a unique name based on the supplied text. */ + // @api + function createUniquePrivateName(text?: string, prefix?: string | GeneratedNamePart, suffix?: string): PrivateIdentifier { + if (text && !startsWith(text, "#")) Debug.fail("First character of private identifier must be #: " + text); + const autoGenerateFlags = GeneratedIdentifierFlags.ReservedInNestedScopes | + (text ? GeneratedIdentifierFlags.Unique : GeneratedIdentifierFlags.Auto); + return createBaseGeneratedPrivateIdentifier(text ?? "", autoGenerateFlags, prefix, suffix); + } + + // @api + function getGeneratedPrivateNameForNode(node: Node, prefix?: string | GeneratedNamePart, suffix?: string): PrivateIdentifier { + const text = isMemberName(node) ? formatGeneratedName(/*privateName*/ true, prefix, node, suffix, idText) : + `#generated@${getNodeId(node)}`; + const flags = prefix || suffix ? GeneratedIdentifierFlags.Optimistic : GeneratedIdentifierFlags.None; + const name = createBaseGeneratedPrivateIdentifier(text, GeneratedIdentifierFlags.Node | flags, prefix, suffix); + name.original = node; + return name; + } + // // Punctuation // @@ -998,6 +1039,9 @@ namespace ts { case SyntaxKind.StaticKeyword: transformFlags = TransformFlags.ContainsES2015; break; + case SyntaxKind.AccessorKeyword: + transformFlags = TransformFlags.ContainsClassFields; + break; case SyntaxKind.ThisKeyword: // 'this' indicates a lexical 'this' transformFlags = TransformFlags.ContainsLexicalThis; @@ -1061,6 +1105,7 @@ namespace ts { if (flags & ModifierFlags.Static) result.push(createModifier(SyntaxKind.StaticKeyword)); if (flags & ModifierFlags.Override) result.push(createModifier(SyntaxKind.OverrideKeyword)); if (flags & ModifierFlags.Readonly) result.push(createModifier(SyntaxKind.ReadonlyKeyword)); + if (flags & ModifierFlags.Accessor) result.push(createModifier(SyntaxKind.AccessorKeyword)); if (flags & ModifierFlags.Async) result.push(createModifier(SyntaxKind.AsyncKeyword)); if (flags & ModifierFlags.In) result.push(createModifier(SyntaxKind.InKeyword)); if (flags & ModifierFlags.Out) result.push(createModifier(SyntaxKind.OutKeyword)); diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index f44c91364081a..a2a558e9079b1 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -139,6 +139,11 @@ namespace ts { return node.kind === SyntaxKind.OverrideKeyword; } + /* @internal */ + export function isAccessorModifier(node: Node): node is AccessorKeyword { + return node.kind === SyntaxKind.AccessorKeyword; + } + /*@internal*/ export function isSuperKeyword(node: Node): node is SuperExpression { return node.kind === SyntaxKind.SuperKeyword; diff --git a/src/compiler/factory/parenthesizerRules.ts b/src/compiler/factory/parenthesizerRules.ts index b09f1826efd8d..21422f2bc6fef 100644 --- a/src/compiler/factory/parenthesizerRules.ts +++ b/src/compiler/factory/parenthesizerRules.ts @@ -177,13 +177,15 @@ namespace ts { // (a|b)|c -> a|(b|c) -> a|b|c // (a&b)&c -> a&(b&c) -> a&b&c // (a^b)^c -> a^(b^c) -> a^b^c + // (a,b),c -> a,(b,c) -> a,b,c // // While addition is associative in mathematics, JavaScript's `+` is not // guaranteed to be associative as it is overloaded with string concatenation. return binaryOperator === SyntaxKind.AsteriskToken || binaryOperator === SyntaxKind.BarToken || binaryOperator === SyntaxKind.AmpersandToken - || binaryOperator === SyntaxKind.CaretToken; + || binaryOperator === SyntaxKind.CaretToken + || binaryOperator === SyntaxKind.CommaToken; } /** diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 7cb707a90a53f..6c7f02c240f2e 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -1244,4 +1244,141 @@ namespace ts { if (nodes.length === 0) return nodes; return setTextRange(factory.createNodeArray([], nodes.hasTrailingComma), nodes); } + + /** + * Gets the node from which a name should be generated. + */ + export function getNodeForGeneratedName(name: GeneratedIdentifier | GeneratedPrivateIdentifier) { + if (name.autoGenerateFlags & GeneratedIdentifierFlags.Node) { + const autoGenerateId = name.autoGenerateId; + let node = name as Node; + let original = node.original; + while (original) { + node = original; + + // if "node" is a different generated name (having a different "autoGenerateId"), use it and stop traversing. + if (isMemberName(node) + && !!(node.autoGenerateFlags! & GeneratedIdentifierFlags.Node) + && node.autoGenerateId !== autoGenerateId) { + break; + } + + original = node.original; + } + // otherwise, return the original node for the source + return node; + } + return name; + } + + /** + * Formats a prefix or suffix of a generated name. + */ + export function formatGeneratedNamePart(part: string | undefined): string; + /** + * Formats a prefix or suffix of a generated name. If the part is a {@link GeneratedNamePart}, calls {@link generateName} to format the source node. + */ + export function formatGeneratedNamePart(part: string | GeneratedNamePart | undefined, generateName: (name: GeneratedIdentifier | GeneratedPrivateIdentifier) => string): string; + export function formatGeneratedNamePart(part: string | GeneratedNamePart | undefined, generateName?: (name: GeneratedIdentifier | GeneratedPrivateIdentifier) => string): string { + return typeof part === "object" ? formatGeneratedName(/*privateName*/ false, part.prefix, part.node, part.suffix, generateName!) : + typeof part === "string" ? part.length > 0 && part.charCodeAt(0) === CharacterCodes.hash ? part.slice(1) : part : + ""; + } + + function formatIdentifier(name: string | Identifier | PrivateIdentifier, generateName?: (name: GeneratedIdentifier | GeneratedPrivateIdentifier) => string) { + return typeof name === "string" ? name : + formatIdentifierWorker(name, Debug.checkDefined(generateName)); + } + + function formatIdentifierWorker(node: Identifier | PrivateIdentifier, generateName: (name: GeneratedIdentifier | GeneratedPrivateIdentifier) => string) { + return isGeneratedPrivateIdentifier(node) ? generateName(node).slice(1) : + isGeneratedIdentifier(node) ? generateName(node) : + isPrivateIdentifier(node) ? (node.escapedText as string).slice(1) : + idText(node); + } + + /** + * Formats a generated name. + * @param privateName When `true`, inserts a `#` character at the start of the result. + * @param prefix The prefix (if any) to include before the base name. + * @param baseName The base name for the generated name. + * @param suffix The suffix (if any) to include after the base name. + */ + export function formatGeneratedName(privateName: boolean, prefix: string | undefined, baseName: string, suffix: string | undefined): string; + /** + * Formats a generated name. + * @param privateName When `true`, inserts a `#` character at the start of the result. + * @param prefix The prefix (if any) to include before the base name. + * @param baseName The base name for the generated name. + * @param suffix The suffix (if any) to include after the base name. + * @param generateName Called to format the source node of {@link prefix} when it is a {@link GeneratedNamePart}. + */ + export function formatGeneratedName(privateName: boolean, prefix: string | GeneratedNamePart | undefined, baseName: string | Identifier | PrivateIdentifier, suffix: string | GeneratedNamePart | undefined, generateName: (name: GeneratedIdentifier | GeneratedPrivateIdentifier) => string): string; + export function formatGeneratedName(privateName: boolean, prefix: string | GeneratedNamePart | undefined, baseName: string | Identifier | PrivateIdentifier, suffix: string | GeneratedNamePart | undefined, generateName?: (name: GeneratedIdentifier | GeneratedPrivateIdentifier) => string) { + prefix = formatGeneratedNamePart(prefix, generateName!); + suffix = formatGeneratedNamePart(suffix, generateName!); + baseName = formatIdentifier(baseName, generateName); + return `${privateName ? "#" : ""}${prefix}${baseName}${suffix}`; + } + + + /** + * Creates a private backing field for an `accessor` {@link PropertyDeclaration}. + */ + export function createAccessorPropertyBackingField(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, initializer: Expression | undefined) { + return factory.updatePropertyDeclaration( + node, + modifiers, + factory.getGeneratedPrivateNameForNode(node.name, /*prefix*/ undefined, "_accessor_storage"), + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + initializer + ); + } + + /** + * Creates a {@link GetAccessorDeclaration} that reads from a private backing field. + */ + export function createAccessorPropertyGetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName) { + return factory.createGetAccessorDeclaration( + modifiers, + name, + [], + /*type*/ undefined, + factory.createBlock([ + factory.createReturnStatement( + factory.createPropertyAccessExpression( + factory.createThis(), + factory.getGeneratedPrivateNameForNode(node.name, /*prefix*/ undefined, "_accessor_storage") + ) + ) + ]) + ); + } + + /** + * Creates a {@link SetAccessorDeclaration} that writes to a private backing field. + */ + export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName) { + return factory.createSetAccessorDeclaration( + modifiers, + name, + [factory.createParameterDeclaration( + /*modifiers*/ undefined, + /*dotdotDotToken*/ undefined, + "value" + )], + factory.createBlock([ + factory.createExpressionStatement( + factory.createAssignment( + factory.createPropertyAccessExpression( + factory.createThis(), + factory.getGeneratedPrivateNameForNode(node.name, /*prefix*/ undefined, "_accessor_storage") + ), + factory.createIdentifier("value") + ) + ) + ]) + ); + } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index dbcffe1680ee9..1a9e69692ccbc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2313,6 +2313,7 @@ namespace ts { return canFollowExportModifier(); case SyntaxKind.DefaultKeyword: return nextTokenCanFollowDefaultKeyword(); + case SyntaxKind.AccessorKeyword: case SyntaxKind.StaticKeyword: case SyntaxKind.GetKeyword: case SyntaxKind.SetKeyword: @@ -6613,6 +6614,7 @@ namespace ts { case SyntaxKind.NamespaceKeyword: return nextTokenIsIdentifierOrStringLiteralOnSameLine(); case SyntaxKind.AbstractKeyword: + case SyntaxKind.AccessorKeyword: case SyntaxKind.AsyncKeyword: case SyntaxKind.DeclareKeyword: case SyntaxKind.PrivateKeyword: @@ -6705,6 +6707,7 @@ namespace ts { // When these don't start a declaration, they're an identifier in an expression statement return true; + case SyntaxKind.AccessorKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: @@ -6791,6 +6794,7 @@ namespace ts { case SyntaxKind.ProtectedKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.AbstractKeyword: + case SyntaxKind.AccessorKeyword: case SyntaxKind.StaticKeyword: case SyntaxKind.ReadonlyKeyword: case SyntaxKind.GlobalKeyword: diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 4b3b8fca03679..6b064be8640ca 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2413,7 +2413,9 @@ namespace ts { // Check modifiers of property declaration if (nodes === (parent as PropertyDeclaration).modifiers) { for (const modifier of nodes as NodeArray) { - if (isModifier(modifier) && modifier.kind !== SyntaxKind.StaticKeyword) { + if (isModifier(modifier) + && modifier.kind !== SyntaxKind.StaticKeyword + && modifier.kind !== SyntaxKind.AccessorKeyword) { diagnostics.push(createDiagnosticForNode(modifier, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, tokenToString(modifier.kind))); } } @@ -2467,6 +2469,7 @@ namespace ts { case SyntaxKind.StaticKeyword: case SyntaxKind.ExportKeyword: case SyntaxKind.DefaultKeyword: + case SyntaxKind.AccessorKeyword: } } } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 05ae6268d7153..a54389fbb9474 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -80,6 +80,7 @@ namespace ts { /** @internal */ export const textToKeywordObj: MapLike = { abstract: SyntaxKind.AbstractKeyword, + accessor: SyntaxKind.AccessorKeyword, any: SyntaxKind.AnyKeyword, as: SyntaxKind.AsKeyword, asserts: SyntaxKind.AssertsKeyword, diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 13ea666881eaf..3ae7696d7c96e 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -12,11 +12,13 @@ namespace ts { */ ClassStaticThisOrSuperReference = 1 << 1, } + export const enum PrivateIdentifierKind { Field = "f", Method = "m", Accessor = "a" } + interface PrivateIdentifierInfoBase { /** * brandCheckIdentifier can contain: @@ -35,6 +37,7 @@ namespace ts { */ isValid: boolean; } + interface PrivateIdentifierAccessorInfo extends PrivateIdentifierInfoBase { kind: PrivateIdentifierKind.Accessor; /** @@ -46,6 +49,7 @@ namespace ts { */ setterName?: Identifier; } + interface PrivateIdentifierMethodInfo extends PrivateIdentifierInfoBase { kind: PrivateIdentifierKind.Method; /** @@ -53,6 +57,7 @@ namespace ts { */ methodName: Identifier; } + interface PrivateIdentifierInstanceFieldInfo extends PrivateIdentifierInfoBase { kind: PrivateIdentifierKind.Field; isStatic: false; @@ -61,11 +66,12 @@ namespace ts { */ variableName: undefined; } + interface PrivateIdentifierStaticFieldInfo extends PrivateIdentifierInfoBase { kind: PrivateIdentifierKind.Field; isStatic: true; /** - * Contains the variable that will server as the storage for the field. + * Contains the variable that will serve as the storage for the field. */ variableName: Identifier; } @@ -80,7 +86,7 @@ namespace ts { /** * Used for prefixing generated variable names. */ - className: string; + className?: Identifier; /** * Used for brand check on private methods. */ @@ -88,7 +94,11 @@ namespace ts { /** * A mapping of private names to information needed for transformation. */ - identifiers: UnderscoreEscapedMap + identifiers?: UnderscoreEscapedMap; + /** + * A mapping of generated private names to information needed for transformation. + */ + generatedIdentifiers?: ESMap; } interface ClassLexicalEnvironment { @@ -133,18 +143,35 @@ namespace ts { const languageVersion = getEmitScriptTarget(compilerOptions); const useDefineForClassFields = getUseDefineForClassFields(compilerOptions); + // Always transform field initializers using Set semantics when `useDefineForClassFields: false`. + const shouldTransformInitializersUsingSet = !useDefineForClassFields; + + // Transform field initializers using Define semantics when `useDefineForClassFields: true` and target < ES2022. + const shouldTransformInitializersUsingDefine = useDefineForClassFields && languageVersion < ScriptTarget.ES2022; + const shouldTransformInitializers = shouldTransformInitializersUsingSet || shouldTransformInitializersUsingDefine; + + // We need to transform private members and class static blocks when target < ES2022. const shouldTransformPrivateElementsOrClassStaticBlocks = languageVersion < ScriptTarget.ES2022; + // We need to transform `accessor` fields when target < ESNext + const shouldTransformAutoAccessors = languageVersion < ScriptTarget.ESNext; + // We need to transform `this` in a static initializer into a reference to the class - // when targeting < ES2022 since the assignment will be moved outside of the class body. + // when target < ES2022 since the assignment will be moved outside of the class body. const shouldTransformThisInStaticInitializers = languageVersion < ScriptTarget.ES2022; - // We don't need to transform `super` property access when targeting ES5, ES3 because + // We don't need to transform `super` property access when target <= ES5 because // the es2015 transformation handles those. const shouldTransformSuperInStaticInitializers = shouldTransformThisInStaticInitializers && languageVersion >= ScriptTarget.ES2015; + const shouldTransformAnything = + shouldTransformInitializers || + shouldTransformPrivateElementsOrClassStaticBlocks || + shouldTransformAutoAccessors; + const previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; + const previousOnEmitNode = context.onEmitNode; context.onEmitNode = onEmitNode; @@ -166,98 +193,117 @@ namespace ts { const classLexicalEnvironmentStack: (ClassLexicalEnvironment | undefined)[] = []; const classLexicalEnvironmentMap = new Map(); + let currentClassLexicalEnvironment: ClassLexicalEnvironment | undefined; + let currentClassContainer: ClassLikeDeclaration | undefined; let currentComputedPropertyNameClassLexicalEnvironment: ClassLexicalEnvironment | undefined; let currentStaticPropertyDeclarationOrStaticBlock: PropertyDeclaration | ClassStaticBlockDeclaration | undefined; return chainBundle(context, transformSourceFile); function transformSourceFile(node: SourceFile) { - const options = context.getCompilerOptions(); - if (node.isDeclarationFile - || useDefineForClassFields && getEmitScriptTarget(options) >= ScriptTarget.ES2022) { + if (node.isDeclarationFile || !shouldTransformAnything) { return node; } + const visited = visitEachChild(node, visitor, context); addEmitHelpers(visited, context.readEmitHelpers()); return visited; } - function visitorWorker(node: Node, valueIsDiscarded: boolean): VisitResult { - if (node.transformFlags & TransformFlags.ContainsClassFields) { - switch (node.kind) { - case SyntaxKind.ClassExpression: - case SyntaxKind.ClassDeclaration: - return visitClassLike(node as ClassLikeDeclaration); - case SyntaxKind.PropertyDeclaration: - return visitPropertyDeclaration(node as PropertyDeclaration); - case SyntaxKind.VariableStatement: - return visitVariableStatement(node as VariableStatement); - case SyntaxKind.PrivateIdentifier: - return visitPrivateIdentifier(node as PrivateIdentifier); - case SyntaxKind.ClassStaticBlockDeclaration: - return visitClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); - } + function visitor(node: Node): VisitResult { + if (!(node.transformFlags & TransformFlags.ContainsClassFields) && + !(node.transformFlags & TransformFlags.ContainsLexicalThisOrSuper)) { + return node; } - if (node.transformFlags & TransformFlags.ContainsClassFields || - node.transformFlags & TransformFlags.ContainsLexicalSuper && - shouldTransformSuperInStaticInitializers && - currentStaticPropertyDeclarationOrStaticBlock && - currentClassLexicalEnvironment) { - switch (node.kind) { - case SyntaxKind.PrefixUnaryExpression: - case SyntaxKind.PostfixUnaryExpression: - return visitPreOrPostfixUnaryExpression(node as PrefixUnaryExpression | PostfixUnaryExpression, valueIsDiscarded); - case SyntaxKind.BinaryExpression: - return visitBinaryExpression(node as BinaryExpression, valueIsDiscarded); - case SyntaxKind.CallExpression: - return visitCallExpression(node as CallExpression); - case SyntaxKind.TaggedTemplateExpression: - return visitTaggedTemplateExpression(node as TaggedTemplateExpression); - case SyntaxKind.PropertyAccessExpression: - return visitPropertyAccessExpression(node as PropertyAccessExpression); - case SyntaxKind.ElementAccessExpression: - return visitElementAccessExpression(node as ElementAccessExpression); - case SyntaxKind.ExpressionStatement: - return visitExpressionStatement(node as ExpressionStatement); - case SyntaxKind.ForStatement: - return visitForStatement(node as ForStatement); - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.Constructor: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: { - const savedCurrentStaticPropertyDeclarationOrStaticBlock = currentStaticPropertyDeclarationOrStaticBlock; - currentStaticPropertyDeclarationOrStaticBlock = undefined; - const result = visitEachChild(node, visitor, context); - currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock; - return result; - } + + switch (node.kind) { + case SyntaxKind.AccessorKeyword: + return shouldTransformAutoAccessors ? undefined : node; + case SyntaxKind.ClassDeclaration: + return visitClassDeclaration(node as ClassDeclaration); + case SyntaxKind.ClassExpression: + return visitClassExpression(node as ClassExpression); + case SyntaxKind.ClassStaticBlockDeclaration: + return visitClassStaticBlockDeclaration(node as ClassStaticBlockDeclaration); + case SyntaxKind.PropertyDeclaration: + return visitPropertyDeclaration(node as PropertyDeclaration); + case SyntaxKind.VariableStatement: + return visitVariableStatement(node as VariableStatement); + case SyntaxKind.PrivateIdentifier: + return visitPrivateIdentifier(node as PrivateIdentifier); + case SyntaxKind.PropertyAccessExpression: + return visitPropertyAccessExpression(node as PropertyAccessExpression); + case SyntaxKind.ElementAccessExpression: + return visitElementAccessExpression(node as ElementAccessExpression); + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + return visitPreOrPostfixUnaryExpression(node as PrefixUnaryExpression | PostfixUnaryExpression, /*valueIsDiscarded*/ false); + case SyntaxKind.BinaryExpression: + return visitBinaryExpression(node as BinaryExpression, /*valueIsDiscarded*/ false); + case SyntaxKind.CallExpression: + return visitCallExpression(node as CallExpression); + case SyntaxKind.ExpressionStatement: + return visitExpressionStatement(node as ExpressionStatement); + case SyntaxKind.TaggedTemplateExpression: + return visitTaggedTemplateExpression(node as TaggedTemplateExpression); + case SyntaxKind.ForStatement: + return visitForStatement(node as ForStatement); + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: { + // If we are descending into a new scope, clear the current static property or block + return setCurrentStaticPropertyDeclarationOrStaticBlockAnd( + /*current*/ undefined, + fallbackVisitor, + node + ); } + default: + return fallbackVisitor(node); } - return visitEachChild(node, visitor, context); } - function discardedValueVisitor(node: Node): VisitResult { - return visitorWorker(node, /*valueIsDiscarded*/ true); + function fallbackVisitor(node: Node) { + return visitEachChild(node, visitor, context); } - function visitor(node: Node): VisitResult { - return visitorWorker(node, /*valueIsDiscarded*/ false); + /** + * Visits a node in an expression whose result is discarded. + */ + function discardedValueVisitor(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.PrefixUnaryExpression: + case SyntaxKind.PostfixUnaryExpression: + return visitPreOrPostfixUnaryExpression(node as PrefixUnaryExpression | PostfixUnaryExpression, /*valueIsDiscarded*/ true); + case SyntaxKind.BinaryExpression: + return visitBinaryExpression(node as BinaryExpression, /*valueIsDiscarded*/ true); + default: + return visitor(node); + } } + /** + * Visits a node in a {@link HeritageClause}. + */ function heritageClauseVisitor(node: Node): VisitResult { switch (node.kind) { case SyntaxKind.HeritageClause: return visitEachChild(node, heritageClauseVisitor, context); case SyntaxKind.ExpressionWithTypeArguments: - return visitExpressionWithTypeArguments(node as ExpressionWithTypeArguments); + return visitExpressionWithTypeArgumentsInHeritageClause(node as ExpressionWithTypeArguments); + default: + return visitor(node); } - return visitor(node); } - function visitorDestructuringTarget(node: Node): VisitResult { + /** + * Visits the assignment target of a destructuring assignment. + */ + function assignmentTargetVisitor(node: Node): VisitResult { switch (node.kind) { case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.ArrayLiteralExpression: @@ -267,6 +313,50 @@ namespace ts { } } + /** + * Visits a member of a class. + */ + function classElementVisitor(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.Constructor: + return visitConstructorDeclaration(node as ConstructorDeclaration); + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + return setCurrentStaticPropertyDeclarationOrStaticBlockAnd( + /*current*/ undefined, + visitMethodOrAccessorDeclaration, + node as MethodDeclaration | AccessorDeclaration); + case SyntaxKind.PropertyDeclaration: + return setCurrentStaticPropertyDeclarationOrStaticBlockAnd( + /*current*/ undefined, + visitPropertyDeclaration, + node as PropertyDeclaration); + case SyntaxKind.ComputedPropertyName: + return visitComputedPropertyName(node as ComputedPropertyName); + case SyntaxKind.SemicolonClassElement: + return node; + default: + return visitor(node); + } + } + + /** + * Visits the results of an auto-accessor field transformation in a second pass. + */ + function accessorFieldResultVisitor(node: Node) { + switch (node.kind) { + case SyntaxKind.PropertyDeclaration: + return transformFieldInitializer(node as PropertyDeclaration); + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return classElementVisitor(node); + default: + Debug.assertMissingNode(node, "Expected node to either be a PropertyDeclaration, GetAccessorDeclaration, or SetAccessorDeclaration"); + break; + } + } + /** * If we visit a private name, this means it is an undeclared private name. * Replace it with an empty identifier to indicate a problem with the code, @@ -283,17 +373,18 @@ namespace ts { return setOriginalNode(factory.createIdentifier(""), node); } + type PrivateIdentifierInExpression = BinaryExpression & { readonly left: PrivateIdentifier, readonly token: InKeyword }; + + function isPrivateIdentifierInExpression(node: BinaryExpression): node is PrivateIdentifierInExpression { + return isPrivateIdentifier(node.left) + && node.operatorToken.kind === SyntaxKind.InKeyword; + } + /** * Visits `#id in expr` */ - function visitPrivateIdentifierInInExpression(node: BinaryExpression) { - if (!shouldTransformPrivateElementsOrClassStaticBlocks) { - return node; - } - const privId = node.left; - Debug.assertNode(privId, isPrivateIdentifier); - Debug.assert(node.operatorToken.kind === SyntaxKind.InKeyword); - const info = accessPrivateIdentifier(privId); + function transformPrivateIdentifierInInExpression(node: PrivateIdentifierInExpression) { + const info = accessPrivateIdentifier(node.left); if (info) { const receiver = visitNode(node.right, visitor, isExpression); @@ -307,37 +398,6 @@ namespace ts { return visitEachChild(node, visitor, context); } - /** - * Visits the members of a class that has fields. - * - * @param node The node to visit. - */ - function classElementVisitor(node: Node): VisitResult { - switch (node.kind) { - case SyntaxKind.Constructor: - // Constructors for classes using class fields are transformed in - // `visitClassDeclaration` or `visitClassExpression`. - return undefined; - - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.MethodDeclaration: - return visitMethodOrAccessorDeclaration(node as MethodDeclaration | AccessorDeclaration); - - case SyntaxKind.PropertyDeclaration: - return visitPropertyDeclaration(node as PropertyDeclaration); - - case SyntaxKind.ComputedPropertyName: - return visitComputedPropertyName(node as ComputedPropertyName); - - case SyntaxKind.SemicolonClassElement: - return node; - - default: - return visitor(node); - } - } - function visitVariableStatement(node: VariableStatement) { const savedPendingStatements = pendingStatements; pendingStatements = []; @@ -351,18 +411,25 @@ namespace ts { return statement; } - function visitComputedPropertyName(name: ComputedPropertyName) { - let node = visitEachChild(name, visitor, context); + function visitComputedPropertyName(node: ComputedPropertyName) { + let expression = visitNode(node.expression, visitor, isExpression); if (some(pendingExpressions)) { - const expressions = pendingExpressions; - expressions.push(node.expression); - pendingExpressions = []; - node = factory.updateComputedPropertyName( - node, - factory.inlineExpressions(expressions) - ); + if (isParenthesizedExpression(expression)) { + expression = factory.updateParenthesizedExpression(expression, factory.inlineExpressions([...pendingExpressions, expression.expression])); + } + else { + expression = factory.inlineExpressions([...pendingExpressions, expression]); + } + pendingExpressions = undefined; } - return node; + return factory.updateComputedPropertyName(node, expression); + } + + function visitConstructorDeclaration(node: ConstructorDeclaration) { + if (currentClassContainer) { + return transformConstructor(node, currentClassContainer); + } + return fallbackVisitor(node); } function visitMethodOrAccessorDeclaration(node: MethodDeclaration | AccessorDeclaration) { @@ -385,13 +452,13 @@ namespace ts { factory.createAssignment( functionName, factory.createFunctionExpression( - filter(node.modifiers, (m): m is Modifier => isModifier(m) && !isStaticModifier(m)), + filter(node.modifiers, (m): m is Modifier => isModifier(m) && !isStaticModifier(m) && !isAccessorModifier(m)), node.asteriskToken, functionName, /* typeParameters */ undefined, - visitParameterList(node.parameters, classElementVisitor, context), + visitParameterList(node.parameters, visitor, context), /* type */ undefined, - visitFunctionBody(node.body!, classElementVisitor, context) + visitFunctionBody(node.body!, visitor, context) ) ) ); @@ -401,6 +468,18 @@ namespace ts { return undefined; } + function setCurrentStaticPropertyDeclarationOrStaticBlockAnd( + current: ClassStaticBlockDeclaration | PropertyDeclaration | undefined, + visitor: (arg: T) => U, + arg: T, + ) { + const savedCurrentStaticPropertyDeclarationOrStaticBlock = currentStaticPropertyDeclarationOrStaticBlock; + currentStaticPropertyDeclarationOrStaticBlock = current; + const result = visitor(arg); + currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock; + return result; + } + function getHoistedFunctionName(node: MethodDeclaration | AccessorDeclaration) { Debug.assert(isPrivateIdentifier(node.name)); const info = accessPrivateIdentifier(node.name); @@ -420,62 +499,131 @@ namespace ts { } } - function visitPropertyDeclaration(node: PropertyDeclaration) { - Debug.assert(!hasDecorators(node)); + function transformAutoAccessor(node: AutoAccessorPropertyDeclaration): VisitResult { + // transforms: + // accessor x = 1; + // into: + // #x = 1; + // get x() { return this.#x; } + // set x(value) { this.#x = value; } - if (isPrivateIdentifier(node.name)) { - if (!shouldTransformPrivateElementsOrClassStaticBlocks) { - if (isStatic(node)) { - // static fields are left as is - return visitEachChild(node, visitor, context); - } + Debug.assertEachNode(node.modifiers, isModifier); - // Initializer is elided as the field is initialized in transformConstructor. - return factory.updatePropertyDeclaration( - node, - visitNodes(node.modifiers, visitor, isModifierLike), - node.name, - /*questionOrExclamationToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined - ); - } + const commentRange = getCommentRange(node); + const sourceMapRange = getSourceMapRange(node); + + // Since we're creating two declarations where there was previously one, cache + // the expression for any computed property names. + const name = node.name; + let getterName = name; + let setterName = name; + if (isComputedPropertyName(name) && !isSimpleInlineableExpression(name.expression)) { + const temp = factory.createTempVariable(hoistVariableDeclaration); + setSourceMapRange(temp, name.expression); + const expression = visitNode(name.expression, visitor, isExpression); + const assignment = factory.createAssignment(temp, expression); + setSourceMapRange(assignment, name.expression); + getterName = factory.updateComputedPropertyName(name, factory.inlineExpressions([assignment, temp])); + setterName = factory.updateComputedPropertyName(name, temp); + } + + const backingField = createAccessorPropertyBackingField(factory, node, node.modifiers, node.initializer); + setOriginalNode(backingField, node); + setEmitFlags(backingField, EmitFlags.NoComments); + setSourceMapRange(backingField, sourceMapRange); - // leave invalid code untransformed + const getter = createAccessorPropertyGetRedirector(factory, node, node.modifiers, getterName); + setOriginalNode(getter, node); + setCommentRange(getter, commentRange); + setSourceMapRange(getter, sourceMapRange); + + const setter = createAccessorPropertySetRedirector(factory, node, node.modifiers, setterName); + setOriginalNode(setter, node); + setEmitFlags(setter, EmitFlags.NoComments); + setSourceMapRange(setter, sourceMapRange); + + return visitArray([backingField, getter, setter], accessorFieldResultVisitor, isClassElement); + } + + function transformPrivateFieldInitializer(node: PrivateIdentifierPropertyDeclaration) { + if (shouldTransformPrivateElementsOrClassStaticBlocks) { + // If we are transforming private elements into WeakMap/WeakSet, we should elide the node. const info = accessPrivateIdentifier(node.name); Debug.assert(info, "Undeclared private name for property declaration."); - if (!info.isValid) { - return node; - } + + // Leave invalid code untransformed; otherwise, elide the node as it is transformed elsewhere. + return info.isValid ? undefined : node; } - // Create a temporary variable to store a computed property name (if necessary). - // If it's not inlineable, then we emit an expression after the class which assigns - // the property name to the temporary variable. - const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer || useDefineForClassFields); - if (expr && !isSimpleInlineableExpression(expr)) { - getPendingExpressions().push(expr); + + if (shouldTransformInitializersUsingSet && !isStatic(node)) { + // If we are transforming initializers using Set semantics we will elide the initializer as it will + // be moved to the constructor to preserve evaluation order next to public instance fields. We don't + // need to do this transformation for private static fields since public static fields can be + // transformed into `static {}` blocks. + return factory.updatePropertyDeclaration( + node, + visitNodes(node.modifiers, visitor, isModifierLike), + node.name, + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined + ); } - if (isStatic(node) && !shouldTransformPrivateElementsOrClassStaticBlocks && !useDefineForClassFields) { - const initializerStatement = transformPropertyOrClassStaticBlock(node, factory.createThis()); - if (initializerStatement) { - const staticBlock = factory.createClassStaticBlockDeclaration( - factory.createBlock([initializerStatement]) - ); + return visitEachChild(node, visitor, context); + } + + function transformPublicFieldInitializer(node: PropertyDeclaration) { + if (shouldTransformInitializers) { + // Create a temporary variable to store a computed property name (if necessary). + // If it's not inlineable, then we emit an expression after the class which assigns + // the property name to the temporary variable. + + const expr = getPropertyNameExpressionIfNeeded(node.name, /*shouldHoist*/ !!node.initializer || useDefineForClassFields); + if (expr) { + getPendingExpressions().push(expr); + } + + if (isStatic(node) && !shouldTransformPrivateElementsOrClassStaticBlocks) { + const initializerStatement = transformPropertyOrClassStaticBlock(node, factory.createThis()); + if (initializerStatement) { + const staticBlock = factory.createClassStaticBlockDeclaration( + factory.createBlock([initializerStatement]) + ); - setOriginalNode(staticBlock, node); - setCommentRange(staticBlock, node); + setOriginalNode(staticBlock, node); + setCommentRange(staticBlock, node); - // Set the comment range for the statement to an empty synthetic range - // and drop synthetic comments from the statement to avoid printing them twice. - setCommentRange(initializerStatement, { pos: -1, end: -1 }); - setSyntheticLeadingComments(initializerStatement, undefined); - setSyntheticTrailingComments(initializerStatement, undefined); - return staticBlock; + // Set the comment range for the statement to an empty synthetic range + // and drop synthetic comments from the statement to avoid printing them twice. + setCommentRange(initializerStatement, { pos: -1, end: -1 }); + setSyntheticLeadingComments(initializerStatement, undefined); + setSyntheticTrailingComments(initializerStatement, undefined); + return staticBlock; + } } + + return undefined; } - return undefined; + return visitEachChild(node, classElementVisitor, context); + } + + function transformFieldInitializer(node: PropertyDeclaration) { + Debug.assert(!hasDecorators(node), "Decorators should already have been transformed and elided."); + return isPrivateIdentifierClassElementDeclaration(node) ? + transformPrivateFieldInitializer(node) : + transformPublicFieldInitializer(node); + } + + function visitPropertyDeclaration(node: PropertyDeclaration) { + // If this is an auto-accessor, we defer to `transformAutoAccessor`. That function + // will in turn call `transformFieldInitializer` as needed. + if (shouldTransformAutoAccessors && isAutoAccessorPropertyDeclaration(node)) { + return transformAutoAccessor(node); + } + + return transformFieldInitializer(node); } function createPrivateIdentifierAccess(info: PrivateIdentifierInfo, receiver: Expression): Expression { @@ -575,9 +723,11 @@ namespace ts { } function visitPreOrPostfixUnaryExpression(node: PrefixUnaryExpression | PostfixUnaryExpression, valueIsDiscarded: boolean) { - if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) { + if (node.operator === SyntaxKind.PlusPlusToken || + node.operator === SyntaxKind.MinusMinusToken) { const operand = skipParentheses(node.operand); - if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(operand)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && + isPrivateIdentifierPropertyAccessExpression(operand)) { let info: PrivateIdentifierInfo | undefined; if (info = accessPrivateIdentifier(operand.name)) { const receiver = visitNode(operand.expression, visitor, isExpression); @@ -686,7 +836,10 @@ namespace ts { } function visitCallExpression(node: CallExpression) { - if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.expression)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && + isPrivateIdentifierPropertyAccessExpression(node.expression)) { + // obj.#x() + // Transform call expressions of private names to properly bind the `this` parameter. const { thisArg, target } = factory.createCallBinding(node.expression, hoistVariableDeclaration, languageVersion); if (isCallChain(node)) { @@ -710,6 +863,8 @@ namespace ts { isSuperProperty(node.expression) && currentStaticPropertyDeclarationOrStaticBlock && currentClassLexicalEnvironment?.classConstructor) { + // super.x() + // super[x]() // converts `super.f(...)` into `Reflect.get(_baseTemp, "f", _classTemp).call(_classTemp, ...)` const invocation = factory.createFunctionCallCall( @@ -726,7 +881,8 @@ namespace ts { } function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { - if (shouldTransformPrivateElementsOrClassStaticBlocks && 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( @@ -770,11 +926,12 @@ namespace ts { } startLexicalEnvironment(); - const savedCurrentStaticPropertyDeclarationOrStaticBlock = currentStaticPropertyDeclarationOrStaticBlock; - currentStaticPropertyDeclarationOrStaticBlock = node; - let statements = visitNodes(node.body.statements, visitor, isStatement); + let statements = setCurrentStaticPropertyDeclarationOrStaticBlockAnd( + node, + statements => visitNodes(statements, visitor, isStatement), + node.body.statements + ); statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); - currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock; const iife = factory.createImmediatelyInvokedArrowFunction(statements); setOriginalNode(iife, node); @@ -786,11 +943,14 @@ namespace ts { function visitBinaryExpression(node: BinaryExpression, valueIsDiscarded: boolean) { if (isDestructuringAssignment(node)) { + // ({ x: obj.#x } = ...) + // ({ x: super.x } = ...) + // ({ x: super[x] } = ...) const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined; node = factory.updateBinaryExpression( node, - visitNode(node.left, visitorDestructuringTarget), + visitNode(node.left, assignmentTargetVisitor), node.operatorToken, visitNode(node.right, visitor) ); @@ -801,7 +961,9 @@ namespace ts { return expr; } if (isAssignmentExpression(node)) { - if (shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierPropertyAccessExpression(node.left)) { + if (shouldTransformPrivateElementsOrClassStaticBlocks && + isPrivateIdentifierPropertyAccessExpression(node.left)) { + // obj.#x = ... const info = accessPrivateIdentifier(node.left.name); if (info) { return setTextRange( @@ -817,6 +979,10 @@ namespace ts { isSuperProperty(node.left) && currentStaticPropertyDeclarationOrStaticBlock && currentClassLexicalEnvironment) { + // super.x = ... + // super[x] = ... + // super.x += ... + // super.x -= ... const { classConstructor, superClassReference, facts } = currentClassLexicalEnvironment; if (facts & ClassFacts.ClassWasDecorated) { return factory.updateBinaryExpression( @@ -884,8 +1050,10 @@ namespace ts { } } } - if (node.operatorToken.kind === SyntaxKind.InKeyword && isPrivateIdentifier(node.left)) { - return visitPrivateIdentifierInInExpression(node); + if (shouldTransformPrivateElementsOrClassStaticBlocks && + isPrivateIdentifierInExpression(node)) { + // #x in obj + return transformPrivateIdentifierInInExpression(node); } return visitEachChild(node, visitor, context); } @@ -936,46 +1104,6 @@ namespace ts { } } - /** - * Set up the environment for a class. - */ - function visitClassLike(node: ClassLikeDeclaration) { - if (!forEach(node.members, doesClassElementNeedTransform)) { - return visitEachChild(node, visitor, context); - } - - const savedPendingExpressions = pendingExpressions; - pendingExpressions = undefined; - startClassLexicalEnvironment(); - - if (shouldTransformPrivateElementsOrClassStaticBlocks) { - const name = getNameOfDeclaration(node); - if (name && isIdentifier(name)) { - getPrivateIdentifierEnvironment().className = idText(name); - } - - const privateInstanceMethodsAndAccessors = getPrivateInstanceMethodsAndAccessors(node); - if (some(privateInstanceMethodsAndAccessors)) { - getPrivateIdentifierEnvironment().weakSetName = createHoistedVariableForClass( - "instances", - privateInstanceMethodsAndAccessors[0].name - ); - } - } - - const result = isClassDeclaration(node) ? - visitClassDeclaration(node) : - visitClassExpression(node); - - endClassLexicalEnvironment(); - pendingExpressions = savedPendingExpressions; - return result; - } - - function doesClassElementNeedTransform(node: ClassElement) { - return isPropertyDeclaration(node) || isClassStaticBlockDeclaration(node) || (shouldTransformPrivateElementsOrClassStaticBlocks && node.name && isPrivateIdentifier(node.name)); - } - function getPrivateInstanceMethodsAndAccessors(node: ClassLikeDeclaration) { return filter(node.members, isNonStaticMethodOrAccessorWithPrivateName); } @@ -988,7 +1116,7 @@ namespace ts { } for (const member of node.members) { if (!isStatic(member)) continue; - if (member.name && isPrivateIdentifier(member.name) && shouldTransformPrivateElementsOrClassStaticBlocks) { + if (member.name && (isPrivateIdentifier(member.name) || isAutoAccessorPropertyDeclaration(member)) && shouldTransformPrivateElementsOrClassStaticBlocks) { facts |= ClassFacts.NeedsClassConstructorReference; } if (isPropertyDeclaration(member) || isClassStaticBlockDeclaration(member)) { @@ -1008,7 +1136,7 @@ namespace ts { return facts; } - function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments) { + function visitExpressionWithTypeArgumentsInHeritageClause(node: ExpressionWithTypeArguments) { const facts = currentClassLexicalEnvironment?.facts || ClassFacts.None; if (facts & ClassFacts.NeedsClassSuperReference) { const temp = factory.createTempVariable(hoistVariableDeclaration, /*reserveInNestedScopes*/ true); @@ -1025,15 +1153,50 @@ namespace ts { return visitEachChild(node, visitor, context); } - function visitClassDeclaration(node: ClassDeclaration) { + function visitInNewClassLexicalEnvironment(node: T, visitor: (node: T, facts: ClassFacts) => U) { + const savedCurrentClassContainer = currentClassContainer; + const savedPendingExpressions = pendingExpressions; + currentClassContainer = node; + pendingExpressions = undefined; + startClassLexicalEnvironment(); + + if (shouldTransformPrivateElementsOrClassStaticBlocks) { + const name = getNameOfDeclaration(node); + if (name && isIdentifier(name)) { + getPrivateIdentifierEnvironment().className = name; + } + + const privateInstanceMethodsAndAccessors = getPrivateInstanceMethodsAndAccessors(node); + if (some(privateInstanceMethodsAndAccessors)) { + getPrivateIdentifierEnvironment().weakSetName = createHoistedVariableForClass( + "instances", + privateInstanceMethodsAndAccessors[0].name + ); + } + } + const facts = getClassFacts(node); if (facts) { getClassLexicalEnvironment().facts = facts; } + if (facts & ClassFacts.NeedsSubstitutionForThisInClassStaticField) { enableSubstitutionForClassStaticThisOrSuperReference(); } + const result = visitor(node, facts); + endClassLexicalEnvironment(); + currentClassContainer = savedCurrentClassContainer; + pendingExpressions = savedPendingExpressions; + return result; + + } + + function visitClassDeclaration(node: ClassDeclaration) { + return visitInNewClassLexicalEnvironment(node, visitClassDeclarationInNewClassLexicalEnvironment); + } + + function visitClassDeclarationInNewClassLexicalEnvironment(node: ClassDeclaration, facts: ClassFacts) { // If a class has private static fields, or a static field has a `this` or `super` reference, // then we need to allocate a temp variable to hold on to that reference. let pendingClassReferenceAssignment: BinaryExpression | undefined; @@ -1043,19 +1206,24 @@ namespace ts { pendingClassReferenceAssignment = factory.createAssignment(temp, factory.getInternalName(node)); } - const extendsClauseElement = getEffectiveBaseTypeNode(node); - const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); + const modifiers = visitNodes(node.modifiers, visitor, isModifierLike); + const heritageClauses = visitNodes(node.heritageClauses, heritageClauseVisitor, isHeritageClause); + const { members, prologue } = transformClassMembers(node); + const classDecl = factory.updateClassDeclaration( + node, + modifiers, + node.name, + /*typeParameters*/ undefined, + heritageClauses, + members + ); - const statements: Statement[] = [ - factory.updateClassDeclaration( - node, - node.modifiers, - node.name, - /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, heritageClauseVisitor, isHeritageClause), - transformClassMembers(node, isDerivedClass) - ) - ]; + const statements: Statement[] = []; + if (prologue) { + statements.push(factory.createExpressionStatement(prologue)); + } + + statements.push(classDecl); if (pendingClassReferenceAssignment) { getPendingExpressions().unshift(pendingClassReferenceAssignment); @@ -1066,30 +1234,27 @@ namespace ts { statements.push(factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions))); } - // Emit static property assignment. Because classDeclaration is lexically evaluated, - // it is safe to emit static property assignment after classDeclaration - // From ES6 specification: - // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using - // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + if (shouldTransformInitializersUsingSet || shouldTransformPrivateElementsOrClassStaticBlocks) { + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. - const staticProperties = getStaticPropertiesAndClassStaticBlock(node); - if (some(staticProperties)) { - addPropertyOrClassStaticBlockStatements(statements, staticProperties, factory.getInternalName(node)); + const staticProperties = getStaticPropertiesAndClassStaticBlock(node); + if (some(staticProperties)) { + addPropertyOrClassStaticBlockStatements(statements, staticProperties, factory.getInternalName(node)); + } } return statements; } function visitClassExpression(node: ClassExpression): Expression { - const facts = getClassFacts(node); - if (facts) { - getClassLexicalEnvironment().facts = facts; - } - - if (facts & ClassFacts.NeedsSubstitutionForThisInClassStaticField) { - enableSubstitutionForClassStaticThisOrSuperReference(); - } + return visitInNewClassLexicalEnvironment(node, visitClassExpressionInNewClassLexicalEnvironment); + } + function visitClassExpressionInNewClassLexicalEnvironment(node: ClassExpression, facts: ClassFacts): Expression { // If this class expression is a transformation of a decorated class declaration, // then we want to output the pendingExpressions as statements, not as inlined // expressions with the class statement. @@ -1101,9 +1266,6 @@ namespace ts { const staticPropertiesOrClassStaticBlocks = getStaticPropertiesAndClassStaticBlock(node); - const extendsClauseElement = getEffectiveBaseTypeNode(node); - const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); - const isClassWithConstructorReference = resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithConstructorReference; let temp: Identifier | undefined; function createClassTempVar() { @@ -1118,16 +1280,32 @@ namespace ts { getClassLexicalEnvironment().classConstructor = factory.cloneNode(temp); } + const modifiers = visitNodes(node.modifiers, visitor, isModifierLike); + const heritageClauses = visitNodes(node.heritageClauses, heritageClauseVisitor, isHeritageClause); + const { members, prologue } = transformClassMembers(node); const classExpression = factory.updateClassExpression( node, - visitNodes(node.modifiers, visitor, isModifierLike), + modifiers, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, heritageClauseVisitor, isHeritageClause), - transformClassMembers(node, isDerivedClass) + heritageClauses, + members ); - const hasTransformableStatics = shouldTransformPrivateElementsOrClassStaticBlocks && some(staticPropertiesOrClassStaticBlocks, p => isClassStaticBlockDeclaration(p) || !!p.initializer || isPrivateIdentifier(p.name)); + const expressions: Expression[] = []; + if (prologue) { + expressions.push(prologue); + } + + // Static initializers are transformed to `static {}` blocks when `useDefineForClassFields: false` + // and not also transforming static blocks. + const hasTransformableStatics = + shouldTransformPrivateElementsOrClassStaticBlocks && + some(staticPropertiesOrClassStaticBlocks, node => + isClassStaticBlockDeclaration(node) || + isPrivateIdentifierClassElementDeclaration(node) || + shouldTransformInitializers && isInitializedProperty(node)); + if (hasTransformableStatics || some(pendingExpressions)) { if (isDecoratedClassDeclaration) { Debug.assertIsDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); @@ -1140,13 +1318,20 @@ namespace ts { if (pendingStatements && some(staticPropertiesOrClassStaticBlocks)) { addPropertyOrClassStaticBlockStatements(pendingStatements, staticPropertiesOrClassStaticBlocks, factory.getInternalName(node)); } + if (temp) { - return factory.inlineExpressions([factory.createAssignment(temp, classExpression), temp]); + expressions.push( + startOnNewLine(factory.createAssignment(temp, classExpression)), + startOnNewLine(temp)); + } + else { + expressions.push(classExpression); + if (prologue) { + startOnNewLine(classExpression); + } } - return classExpression; } else { - const expressions: Expression[] = []; temp ||= createClassTempVar(); if (isClassWithConstructorReference) { // record an alias as the class name is not in scope for statics. @@ -1164,56 +1349,96 @@ namespace ts { addRange(expressions, map(pendingExpressions, startOnNewLine)); addRange(expressions, generateInitializedPropertyExpressionsOrClassStaticBlock(staticPropertiesOrClassStaticBlocks, temp)); expressions.push(startOnNewLine(temp)); - - return factory.inlineExpressions(expressions); + } + } + else { + expressions.push(classExpression); + if (prologue) { + startOnNewLine(classExpression); } } - return classExpression; + return factory.inlineExpressions(expressions); } function visitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) { if (!shouldTransformPrivateElementsOrClassStaticBlocks) { - return visitEachChild(node, classElementVisitor, context); + return visitEachChild(node, visitor, context); } // ClassStaticBlockDeclaration for classes are transformed in `visitClassDeclaration` or `visitClassExpression`. return undefined; } - function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - const members: ClassElement[] = []; + function transformClassMembers(node: ClassDeclaration | ClassExpression) { + // Declare private names if (shouldTransformPrivateElementsOrClassStaticBlocks) { - // Declare private names. for (const member of node.members) { if (isPrivateIdentifierClassElementDeclaration(member)) { - addPrivateIdentifierToEnvironment(member); + addPrivateIdentifierToEnvironment(member, member.name, addPrivateIdentifierClassElementToEnvironment); } } - if (some(getPrivateInstanceMethodsAndAccessors(node))) { createBrandCheckWeakSetForPrivateMethods(); } + if (shouldTransformAutoAccessors) { + for (const member of node.members) { + if (isAutoAccessorPropertyDeclaration(member)) { + const storageName = factory.getGeneratedPrivateNameForNode(member.name, /*prefix*/ undefined, "_accessor_storage"); + addPrivateIdentifierToEnvironment(member, storageName, addPrivateIdentifierPropertyDeclarationToEnvironment); + } + } + } } - const constructor = transformConstructor(node, isDerivedClass); - const visitedMembers = visitNodes(node.members, classElementVisitor, isClassElement); + let members = visitNodes(node.members, classElementVisitor, isClassElement); - if (constructor) { - members.push(constructor); + // Create a synthetic constructor if necessary + let syntheticConstructor: ConstructorDeclaration | undefined; + if (!some(members, isConstructorDeclaration)) { + syntheticConstructor = transformConstructor(/*constructor*/ undefined, node); } + let prologue: Expression | undefined; + + // If there are pending expressions create a class static block in which to evaluate them, but only if + // class static blocks are not also being transformed. This block will be injected at the top of the class + // to ensure that expressions from computed property names are evaluated before any other static + // initializers. + let syntheticStaticBlock: ClassStaticBlockDeclaration | undefined; if (!shouldTransformPrivateElementsOrClassStaticBlocks && some(pendingExpressions)) { - members.push(factory.createClassStaticBlockDeclaration( - factory.createBlock([ - factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions)) - ]) - )); + let statement = factory.createExpressionStatement(factory.inlineExpressions(pendingExpressions)); + if (statement.transformFlags & TransformFlags.ContainsLexicalThisOrSuper) { + // If there are `this` or `super` references from computed property names, shift the expression + // into an arrow function to be evaluated in the outer scope so that `this` and `super` are + // properly captured. + const temp = factory.createTempVariable(hoistVariableDeclaration); + const arrow = factory.createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + /*parameters*/ [], + /*type*/ undefined, + /*equalsGreaterThanToken*/ undefined, + factory.createBlock([statement])); + prologue = factory.createAssignment(temp, arrow); + statement = factory.createExpressionStatement(factory.createCallExpression(temp, /*typeArguments*/ undefined, [])); + } + + const block = factory.createBlock([statement]); + syntheticStaticBlock = factory.createClassStaticBlockDeclaration(block); pendingExpressions = undefined; } - addRange(members, visitedMembers); + // If we created a synthetic constructor or class static block, add them to the visited members + // and return a new array. + if (syntheticConstructor || syntheticStaticBlock) { + let membersArray: ClassElement[] | undefined; + membersArray = append(membersArray, syntheticConstructor); + membersArray = append(membersArray, syntheticStaticBlock); + membersArray = addRange(membersArray, members); + members = setTextRange(factory.createNodeArray(membersArray), /*location*/ node.members); + } - return setTextRange(factory.createNodeArray(members), /*location*/ node.members); + return { members, prologue }; } function createBrandCheckWeakSetForPrivateMethods() { @@ -1233,28 +1458,35 @@ namespace ts { } function isClassElementThatRequiresConstructorStatement(member: ClassElement) { - if (isStatic(member) || hasSyntacticModifier(getOriginalNode(member), ModifierFlags.Abstract)) { + if (isStatic(member) || hasAbstractModifier(getOriginalNode(member))) { return false; } - if (useDefineForClassFields) { - // If we are using define semantics and targeting ESNext or higher, - // then we don't need to transform any class properties. - return languageVersion < ScriptTarget.ES2022; - } - return isInitializedProperty(member) || shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierClassElementDeclaration(member); + + return shouldTransformInitializersUsingDefine && isPropertyDeclaration(member) || + shouldTransformInitializersUsingSet && isInitializedProperty(member) || + shouldTransformPrivateElementsOrClassStaticBlocks && isPrivateIdentifierClassElementDeclaration(member) || + shouldTransformPrivateElementsOrClassStaticBlocks && shouldTransformAutoAccessors && isAutoAccessorPropertyDeclaration(member); } - function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); - const elements = node.members.filter(isClassElementThatRequiresConstructorStatement); - if (!some(elements)) { + function transformConstructor(constructor: ConstructorDeclaration | undefined, container: ClassDeclaration | ClassExpression) { + constructor = visitNode(constructor, visitor, isConstructorDeclaration); + if (!some(container.members, isClassElementThatRequiresConstructorStatement)) { return constructor; } + + const extendsClauseElement = getEffectiveBaseTypeNode(container); + const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); const parameters = visitParameterList(constructor ? constructor.parameters : undefined, visitor, context); - const body = transformConstructorBody(node, constructor, isDerivedClass); + const body = transformConstructorBody(container, constructor, isDerivedClass); if (!body) { - return undefined; + return constructor; + } + + if (constructor) { + Debug.assert(parameters); + return factory.updateConstructorDeclaration(constructor, /*modifiers*/ undefined, parameters, body); } + return startOnNewLine( setOriginalNode( setTextRange( @@ -1263,7 +1495,7 @@ namespace ts { parameters ?? [], body ), - constructor || node + constructor || container ), constructor ) @@ -1273,7 +1505,7 @@ namespace ts { function transformConstructorBody(node: ClassDeclaration | ClassExpression, constructor: ConstructorDeclaration | undefined, isDerivedClass: boolean) { let properties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ false); if (!useDefineForClassFields) { - properties = filter(properties, property => !!property.initializer || isPrivateIdentifier(property.name)); + properties = filter(properties, property => !!property.initializer || isPrivateIdentifier(property.name) || hasAccessorModifier(property)); } const privateMethodsAndAccessors = getPrivateInstanceMethodsAndAccessors(node); @@ -1385,13 +1617,21 @@ namespace ts { statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment()); + if (statements.length === 0 && !constructor) { + return undefined; + } + + const multiLine = constructor?.body && constructor.body.statements.length >= statements.length ? + constructor.body.multiLine ?? statements.length > 0 : + statements.length > 0; + return setTextRange( factory.createBlock( setTextRange( factory.createNodeArray(statements), /*location*/ constructor ? constructor.body!.statements : node.members ), - /*multiLine*/ true + multiLine ), /*location*/ constructor ? constructor.body : undefined ); @@ -1435,9 +1675,10 @@ namespace ts { } const statement = factory.createExpressionStatement(expression); + setOriginalNode(statement, property); + addEmitFlags(statement, getEmitFlags(property) & EmitFlags.NoComments); setSourceMapRange(statement, moveRangePastModifiers(property)); setCommentRange(statement, property); - setOriginalNode(statement, property); // `setOriginalNode` *copies* the `emitNode` from `property`, so now both // `statement` and `expression` have a copy of the synthesized comments. @@ -1462,9 +1703,10 @@ namespace ts { continue; } startOnNewLine(expression); + setOriginalNode(expression, property); + addEmitFlags(expression, getEmitFlags(property) & EmitFlags.NoComments); setSourceMapRange(expression, moveRangePastModifiers(property)); setCommentRange(expression, property); - setOriginalNode(expression, property); expressions.push(expression); } @@ -1493,9 +1735,13 @@ namespace ts { function transformPropertyWorker(property: PropertyDeclaration, receiver: LeftHandSideExpression) { // We generate a name here in order to reuse the value cached by the relocated computed name expression (which uses the same generated name) const emitAssignment = !useDefineForClassFields; - const propertyName = isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) - ? factory.updateComputedPropertyName(property.name, factory.getGeneratedNameForNode(property.name)) - : property.name; + + const propertyName = + hasAccessorModifier(property) ? + factory.getGeneratedPrivateNameForNode(property.name) : + isComputedPropertyName(property.name) && !isSimpleInlineableExpression(property.name.expression) ? + factory.updateComputedPropertyName(property.name, factory.getGeneratedNameForNode(property.name)) : + property.name; if (hasStaticModifier(property)) { currentStaticPropertyDeclarationOrStaticBlock = property; @@ -1597,7 +1843,7 @@ namespace ts { * @param methods An array of method declarations. * @param receiver The receiver on which each method should be assigned. */ - function addMethodStatements(statements: Statement[], methods: readonly (MethodDeclaration | AccessorDeclaration)[], receiver: LeftHandSideExpression) { + function addMethodStatements(statements: Statement[], methods: readonly (MethodDeclaration | AccessorDeclaration | AutoAccessorPropertyDeclaration)[], receiver: LeftHandSideExpression) { if (!shouldTransformPrivateElementsOrClassStaticBlocks || !some(methods)) { return; } @@ -1802,99 +2048,77 @@ namespace ts { function getPrivateIdentifierEnvironment() { const lex = getClassLexicalEnvironment(); lex.privateIdentifierEnvironment ||= { - className: "", - identifiers: new Map() + className: undefined, + weakSetName: undefined, + identifiers: undefined, + generatedIdentifiers: undefined, }; return lex.privateIdentifierEnvironment; } function getPendingExpressions() { - return pendingExpressions || (pendingExpressions = []); + return pendingExpressions ??= []; } - function addPrivateIdentifierToEnvironment(node: PrivateClassElementDeclaration) { - const text = getTextOfPropertyName(node.name) as string; - const lex = getClassLexicalEnvironment(); - const { classConstructor } = lex; - - const privateEnv = getPrivateIdentifierEnvironment(); - const { weakSetName } = privateEnv; - - const assignmentExpressions: Expression[] = []; - - const privateName = node.name.escapedText; - const previousInfo = privateEnv.identifiers.get(privateName); - const isValid = !isReservedPrivateName(node.name) && previousInfo === undefined; - - if (hasStaticModifier(node)) { - Debug.assert(classConstructor, "weakSetName should be set in private identifier environment"); - if (isPropertyDeclaration(node)) { - const variableName = createHoistedVariableForPrivateName(text, node); - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Field, - variableName, - brandCheckIdentifier: classConstructor, - isStatic: true, - isValid, - }); - } - else if (isMethodDeclaration(node)) { - const functionName = createHoistedVariableForPrivateName(text, node); - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Method, - methodName: functionName, - brandCheckIdentifier: classConstructor, - isStatic: true, - isValid, - }); - } - else if (isGetAccessorDeclaration(node)) { - const getterName = createHoistedVariableForPrivateName(text + "_get", node); - if (previousInfo?.kind === PrivateIdentifierKind.Accessor && previousInfo.isStatic && !previousInfo.getterName) { - previousInfo.getterName = getterName; - } - else { - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Accessor, - getterName, - setterName: undefined, - brandCheckIdentifier: classConstructor, - isStatic: true, - isValid, - }); - } - } - else if (isSetAccessorDeclaration(node)) { - const setterName = createHoistedVariableForPrivateName(text + "_set", node); - if (previousInfo?.kind === PrivateIdentifierKind.Accessor && previousInfo.isStatic && !previousInfo.setterName) { - previousInfo.setterName = setterName; - } - else { - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Accessor, - getterName: undefined, - setterName, - brandCheckIdentifier: classConstructor, - isStatic: true, - isValid, - }); - } - } - else { - Debug.assertNever(node, "Unknown class element type."); - } + function addPrivateIdentifierClassElementToEnvironment( + node: PropertyDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + previousInfo: PrivateIdentifierInfo | undefined + ) { + if (isAutoAccessorPropertyDeclaration(node)) { + addPrivateIdentifierAutoAccessorPropertyDeclarationToEnvironment(node, name, lex, privateEnv, isStatic, isValid, previousInfo); } else if (isPropertyDeclaration(node)) { - const weakMapName = createHoistedVariableForPrivateName(text, node); - privateEnv.identifiers.set(privateName, { + addPrivateIdentifierPropertyDeclarationToEnvironment(node, name, lex, privateEnv, isStatic, isValid, previousInfo); + } + else if (isMethodDeclaration(node)) { + addPrivateIdentifierMethodDeclarationToEnvironment(node, name, lex, privateEnv, isStatic, isValid, previousInfo); + } + else if (isGetAccessorDeclaration(node)) { + addPrivateIdentifierGetAccessorDeclarationToEnvironment(node, name, lex, privateEnv, isStatic, isValid, previousInfo); + } + else if (isSetAccessorDeclaration(node)) { + addPrivateIdentifierSetAccessorDeclarationToEnvironment(node, name, lex, privateEnv, isStatic, isValid, previousInfo); + } + } + + function addPrivateIdentifierPropertyDeclarationToEnvironment( + _node: PropertyDeclaration, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + _previousInfo: PrivateIdentifierInfo | undefined + ) { + if (isStatic) { + Debug.assert(lex.classConstructor, "classConstructor should be set in private identifier environment"); + + const variableName = createHoistedVariableForPrivateName(name); + setPrivateIdentifier(privateEnv, name, { + kind: PrivateIdentifierKind.Field, + brandCheckIdentifier: lex.classConstructor, + variableName, + isStatic: true, + isValid, + }); + } + else { + const weakMapName = createHoistedVariableForPrivateName(name); + + setPrivateIdentifier(privateEnv, name, { kind: PrivateIdentifierKind.Field, brandCheckIdentifier: weakMapName, - isStatic: false, variableName: undefined, + isStatic: false, isValid, }); - assignmentExpressions.push(factory.createAssignment( + getPendingExpressions().push(factory.createAssignment( weakMapName, factory.createNewExpression( factory.createIdentifier("WeakMap"), @@ -1903,66 +2127,142 @@ namespace ts { ) )); } - else if (isMethodDeclaration(node)) { - Debug.assert(weakSetName, "weakSetName should be set in private identifier environment"); + } - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Method, - methodName: createHoistedVariableForPrivateName(text, node), - brandCheckIdentifier: weakSetName, - isStatic: false, + function addPrivateIdentifierMethodDeclarationToEnvironment( + _node: MethodDeclaration, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + _previousInfo: PrivateIdentifierInfo | undefined + ) { + const methodName = createHoistedVariableForPrivateName(name); + const brandCheckIdentifier = isStatic ? + Debug.checkDefined(lex.classConstructor, "classConstructor should be set in private identifier environment") : + Debug.checkDefined(privateEnv.weakSetName, "weakSetName should be set in private identifier environment"); + + setPrivateIdentifier(privateEnv, name, { + kind: PrivateIdentifierKind.Method, + methodName, + brandCheckIdentifier, + isStatic, + isValid, + }); + } + + function addPrivateIdentifierGetAccessorDeclarationToEnvironment( + _node: GetAccessorDeclaration, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + previousInfo: PrivateIdentifierInfo | undefined + ) { + const getterName = createHoistedVariableForPrivateName(name, "_get"); + const brandCheckIdentifier = isStatic ? + Debug.checkDefined(lex.classConstructor, "classConstructor should be set in private identifier environment") : + Debug.checkDefined(privateEnv.weakSetName, "weakSetName should be set in private identifier environment"); + + if (previousInfo?.kind === PrivateIdentifierKind.Accessor && previousInfo.isStatic === isStatic && !previousInfo.getterName) { + previousInfo.getterName = getterName; + } + else { + setPrivateIdentifier(privateEnv, name, { + kind: PrivateIdentifierKind.Accessor, + getterName, + setterName: undefined, + brandCheckIdentifier, + isStatic, isValid, }); } - else if (isAccessor(node)) { - Debug.assert(weakSetName, "weakSetName should be set in private identifier environment"); - - if (isGetAccessor(node)) { - const getterName = createHoistedVariableForPrivateName(text + "_get", node); + } - if (previousInfo?.kind === PrivateIdentifierKind.Accessor && !previousInfo.isStatic && !previousInfo.getterName) { - previousInfo.getterName = getterName; - } - else { - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Accessor, - getterName, - setterName: undefined, - brandCheckIdentifier: weakSetName, - isStatic: false, - isValid, - }); - } - } - else { - const setterName = createHoistedVariableForPrivateName(text + "_set", node); + function addPrivateIdentifierSetAccessorDeclarationToEnvironment( + _node: SetAccessorDeclaration, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + previousInfo: PrivateIdentifierInfo | undefined + ) { + const setterName = createHoistedVariableForPrivateName(name, "_set"); + const brandCheckIdentifier = isStatic ? + Debug.checkDefined(lex.classConstructor, "classConstructor should be set in private identifier environment") : + Debug.checkDefined(privateEnv.weakSetName, "weakSetName should be set in private identifier environment"); - if (previousInfo?.kind === PrivateIdentifierKind.Accessor && !previousInfo.isStatic && !previousInfo.setterName) { - previousInfo.setterName = setterName; - } - else { - privateEnv.identifiers.set(privateName, { - kind: PrivateIdentifierKind.Accessor, - getterName: undefined, - setterName, - brandCheckIdentifier: weakSetName, - isStatic: false, - isValid, - }); - } - } + if (previousInfo?.kind === PrivateIdentifierKind.Accessor && previousInfo.isStatic === isStatic && !previousInfo.setterName) { + previousInfo.setterName = setterName; } else { - Debug.assertNever(node, "Unknown class element type."); + setPrivateIdentifier(privateEnv, name, { + kind: PrivateIdentifierKind.Accessor, + getterName: undefined, + setterName, + brandCheckIdentifier, + isStatic, + isValid, + }); } + } - getPendingExpressions().push(...assignmentExpressions); + function addPrivateIdentifierAutoAccessorPropertyDeclarationToEnvironment( + _node: AutoAccessorPropertyDeclaration, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + _previousInfo: PrivateIdentifierInfo | undefined + ) { + const getterName = createHoistedVariableForPrivateName(name, "_get"); + const setterName = createHoistedVariableForPrivateName(name, "_set"); + const brandCheckIdentifier = isStatic ? + Debug.checkDefined(lex.classConstructor, "classConstructor should be set in private identifier environment") : + Debug.checkDefined(privateEnv.weakSetName, "weakSetName should be set in private identifier environment"); + + setPrivateIdentifier(privateEnv, name, { + kind: PrivateIdentifierKind.Accessor, + getterName, + setterName, + brandCheckIdentifier, + isStatic, + isValid, + }); + } + + function addPrivateIdentifierToEnvironment( + node: T, + name: PrivateIdentifier, + addDeclaration: ( + node: T, + name: PrivateIdentifier, + lex: ClassLexicalEnvironment, + privateEnv: PrivateIdentifierEnvironment, + isStatic: boolean, + isValid: boolean, + previousInfo: PrivateIdentifierInfo | undefined + ) => void + ) { + const lex = getClassLexicalEnvironment(); + const privateEnv = getPrivateIdentifierEnvironment(); + const previousInfo = getPrivateIdentifier(privateEnv, name); + const isStatic = hasStaticModifier(node); + const isValid = !isReservedPrivateName(name) && previousInfo === undefined; + addDeclaration(node, name, lex, privateEnv, isStatic, isValid, previousInfo); } - function createHoistedVariableForClass(name: string, node: PrivateIdentifier | ClassStaticBlockDeclaration): Identifier { + function createHoistedVariableForClass(name: string | PrivateIdentifier | undefined, node: PrivateIdentifier | ClassStaticBlockDeclaration, suffix?: string): Identifier { const { className } = getPrivateIdentifierEnvironment(); - const prefix = className ? `_${className}` : ""; - const identifier = factory.createUniqueName(`${prefix}_${name}`, GeneratedIdentifierFlags.Optimistic); + const prefix: GeneratedNamePart | string = className ? { prefix: "_", node: className, suffix: "_" } : "_"; + const identifier = + typeof name === "object" ? factory.getGeneratedNameForNode(name, GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.ReservedInNestedScopes, prefix, suffix) : + typeof name === "string" ? factory.createUniqueName(name, GeneratedIdentifierFlags.Optimistic, prefix, suffix) : + factory.createTempVariable(/*recordTempVariable*/ undefined, /*reserveInNestedScopes*/ true, prefix, suffix); if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BlockScopedBindingInLoop) { addBlockScopedVariable(identifier); @@ -1974,13 +2274,39 @@ namespace ts { return identifier; } - function createHoistedVariableForPrivateName(privateName: string, node: PrivateClassElementDeclaration): Identifier { - return createHoistedVariableForClass(privateName.substring(1), node.name); + function createHoistedVariableForPrivateName(name: PrivateIdentifier, suffix?: string): Identifier { + const text = tryGetTextOfPropertyName(name) as string | undefined; + return createHoistedVariableForClass(text?.substring(1) ?? name, name, suffix); } + /** + * Access an already defined {@link PrivateIdentifier} in the current {@link PrivateIdentifierEnvironment}. + * + * @seealso {@link addPrivateIdentifierToEnvironment} + */ function accessPrivateIdentifier(name: PrivateIdentifier) { + if (isGeneratedPrivateIdentifier(name)) { + return accessGeneratedPrivateIdentifier(name); + } + else { + return accessPrivateIdentifierByText(name.escapedText); + } + } + + function accessPrivateIdentifierByText(text: __String) { + return accessPrivateIdentifierWorker(getPrivateIdentifierInfo, text); + } + + function accessGeneratedPrivateIdentifier(name: GeneratedPrivateIdentifier) { + return accessPrivateIdentifierWorker(getGeneratedPrivateIdentifierInfo, getNodeForGeneratedName(name)); + } + + function accessPrivateIdentifierWorker( + getPrivateIdentifierInfo: (privateEnv: PrivateIdentifierEnvironment, key: K) => PrivateIdentifierInfo | undefined, + privateIdentifierKey: K + ) { if (currentClassLexicalEnvironment?.privateIdentifierEnvironment) { - const info = currentClassLexicalEnvironment.privateIdentifierEnvironment.identifiers.get(name.escapedText); + const info = getPrivateIdentifierInfo(currentClassLexicalEnvironment.privateIdentifierEnvironment, privateIdentifierKey); if (info) { return info; } @@ -1990,9 +2316,11 @@ namespace ts { if (!env) { continue; } - const info = env.privateIdentifierEnvironment?.identifiers.get(name.escapedText); - if (info) { - return info; + if (env.privateIdentifierEnvironment) { + const info = getPrivateIdentifierInfo(env.privateIdentifierEnvironment, privateIdentifierKey); + if (info) { + return info; + } } } return undefined; @@ -2073,7 +2401,7 @@ namespace ts { } } } - return visitNode(node, visitorDestructuringTarget); + return visitNode(node, assignmentTargetVisitor); } function visitObjectAssignmentTarget(node: ObjectLiteralElementLike) { @@ -2119,13 +2447,13 @@ namespace ts { visitNode(node.name, visitor, isPropertyName), wrapped ? initializer ? factory.createAssignment(wrapped, visitNode(initializer, visitor)) : wrapped : - visitNode(node.initializer, visitorDestructuringTarget, isExpression) + visitNode(node.initializer, assignmentTargetVisitor, isExpression) ); } if (isSpreadAssignment(node)) { return factory.updateSpreadAssignment( node, - wrapped || visitNode(node.expression, visitorDestructuringTarget, isExpression) + wrapped || visitNode(node.expression, assignmentTargetVisitor, isExpression) ); } Debug.assert(wrapped === undefined, "Should not have generated a wrapped target"); @@ -2191,6 +2519,31 @@ namespace ts { } function isReservedPrivateName(node: PrivateIdentifier) { - return node.escapedText === "#constructor"; + return !isGeneratedPrivateIdentifier(node) && node.escapedText === "#constructor"; + } + + function getPrivateIdentifier(privateEnv: PrivateIdentifierEnvironment, name: PrivateIdentifier) { + return isGeneratedPrivateIdentifier(name) ? + getGeneratedPrivateIdentifierInfo(privateEnv, getNodeForGeneratedName(name)) : + getPrivateIdentifierInfo(privateEnv, name.escapedText); + } + + function setPrivateIdentifier(privateEnv: PrivateIdentifierEnvironment, name: PrivateIdentifier, info: PrivateIdentifierInfo) { + if (isGeneratedPrivateIdentifier(name)) { + privateEnv.generatedIdentifiers ??= new Map(); + privateEnv.generatedIdentifiers.set(getNodeForGeneratedName(name), info); + } + else { + privateEnv.identifiers ??= new Map(); + privateEnv.identifiers.set(name.escapedText, info); + } + } + + function getPrivateIdentifierInfo(privateEnv: PrivateIdentifierEnvironment, key: __String) { + return privateEnv.identifiers?.get(key); + } + + function getGeneratedPrivateIdentifierInfo(privateEnv: PrivateIdentifierEnvironment, key: Node) { + return privateEnv.generatedIdentifiers?.get(key); } } diff --git a/src/compiler/transformers/legacyDecorators.ts b/src/compiler/transformers/legacyDecorators.ts index 37889e91c00b9..fac91f5f6f584 100644 --- a/src/compiler/transformers/legacyDecorators.ts +++ b/src/compiler/transformers/legacyDecorators.ts @@ -503,7 +503,7 @@ namespace ts { const prefix = getClassMemberPrefix(node, member); const memberName = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ !hasSyntacticModifier(member, ModifierFlags.Ambient)); const descriptor = languageVersion > ScriptTarget.ES3 - ? member.kind === SyntaxKind.PropertyDeclaration + ? isPropertyDeclaration(member) && !hasAccessorModifier(member) // We emit `void 0` here to indicate to `__decorate` that it can invoke `Object.defineProperty` directly, but that it // should not invoke `Object.getOwnPropertyDescriptor`. ? factory.createVoidZero() diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index bbe8f165919bf..2c0552ee40c42 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -381,8 +381,8 @@ namespace ts { * * @param member The class element node. */ - export function isNonStaticMethodOrAccessorWithPrivateName(member: ClassElement): member is PrivateIdentifierMethodDeclaration | PrivateIdentifierAccessorDeclaration { - return !isStatic(member) && isMethodOrAccessor(member) && isPrivateIdentifier(member.name); + export function isNonStaticMethodOrAccessorWithPrivateName(member: ClassElement): member is PrivateIdentifierMethodDeclaration | PrivateIdentifierAccessorDeclaration | PrivateIdentifierAutoAccessorPropertyDeclaration { + return !isStatic(member) && (isMethodOrAccessor(member) || isAutoAccessorPropertyDeclaration(member)) && isPrivateIdentifier(member.name); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2fb40e37d3ff0..bda77e561762d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -159,6 +159,7 @@ namespace ts { YieldKeyword, // Contextual keywords AbstractKeyword, + AccessorKeyword, AsKeyword, AssertsKeyword, AssertKeyword, @@ -550,6 +551,7 @@ namespace ts { export type KeywordSyntaxKind = | SyntaxKind.AbstractKeyword + | SyntaxKind.AccessorKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword @@ -634,6 +636,7 @@ namespace ts { export type ModifierSyntaxKind = | SyntaxKind.AbstractKeyword + | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword @@ -817,9 +820,10 @@ namespace ts { Protected = 1 << 4, // Property/Method Static = 1 << 5, // Property/Method Readonly = 1 << 6, // Property/Method - Abstract = 1 << 7, // Class/Method/ConstructSignature - Async = 1 << 8, // Property/Method/Function - Default = 1 << 9, // Function/Class (export default declaration) + Accessor = 1 << 7, // Property + Abstract = 1 << 8, // Class/Method/ConstructSignature + Async = 1 << 9, // Property/Method/Function + Default = 1 << 10, // Function/Class (export default declaration) Const = 1 << 11, // Const enum HasComputedJSDocModifiers = 1 << 12, // Indicates the computed modifier flags include modifiers from JSDoc. @@ -837,7 +841,7 @@ namespace ts { TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override | In | Out, ExportDefault = Export | Default, - All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated | Override | In | Out | Decorator, + All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Accessor | Async | Default | Const | Deprecated | Override | In | Out | Decorator, Modifier = All & ~Decorator } @@ -1332,6 +1336,7 @@ namespace ts { } export type AbstractKeyword = ModifierToken; + export type AccessorKeyword = ModifierToken; export type AsyncKeyword = ModifierToken; export type ConstKeyword = ModifierToken; export type DeclareKeyword = ModifierToken; @@ -1351,6 +1356,7 @@ namespace ts { export type Modifier = | AbstractKeyword + | AccessorKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword @@ -1383,6 +1389,7 @@ namespace ts { | AccessibilityModifier | ReadonlyKeyword | StaticKeyword + | AccessorKeyword ; export type ModifiersArray = NodeArray; @@ -1413,6 +1420,8 @@ namespace ts { readonly originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later /*@internal*/ readonly autoGenerateFlags?: GeneratedIdentifierFlags; // Specifies whether to auto-generate the text for an identifier. /*@internal*/ readonly autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name. + /*@internal*/ readonly autoGeneratePrefix?: string | GeneratedNamePart; + /*@internal*/ readonly autoGenerateSuffix?: string; /*@internal*/ generatedImportReference?: ImportSpecifier; // Reference to the generated import specifier this identifier refers to isInJSDocNamespace?: boolean; // if the node is a member in a JSDoc namespace /*@internal*/ typeArguments?: NodeArray; // Only defined on synthesized nodes. Though not syntactically valid, used in emitting diagnostics, quickinfo, and signature help. @@ -1502,8 +1511,16 @@ namespace ts { // escaping not strictly necessary // avoids gotchas in transforms and utils readonly escapedText: __String; + /*@internal*/ readonly autoGenerateFlags?: GeneratedIdentifierFlags; // Specifies whether to auto-generate the text for an identifier. + /*@internal*/ readonly autoGenerateId?: number; // Ensures unique generated identifiers get unique names, but clones get the same name. + /*@internal*/ readonly autoGeneratePrefix?: string | GeneratedNamePart; + /*@internal*/ readonly autoGenerateSuffix?: string; } + /*@internal*/ + export interface GeneratedPrivateIdentifier extends PrivateIdentifier { + autoGenerateFlags: GeneratedIdentifierFlags; + } /* @internal */ // A name that supports late-binding (used in checker) @@ -1627,11 +1644,19 @@ namespace ts { readonly initializer?: Expression; // Optional initializer } + export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { + _autoAccessorBrand: any; + } + /*@internal*/ export interface PrivateIdentifierPropertyDeclaration extends PropertyDeclaration { name: PrivateIdentifier; } /*@internal*/ + export interface PrivateIdentifierAutoAccessorPropertyDeclaration extends AutoAccessorPropertyDeclaration { + name: PrivateIdentifier; + } + /*@internal*/ export interface PrivateIdentifierMethodDeclaration extends MethodDeclaration { name: PrivateIdentifier; } @@ -1648,6 +1673,7 @@ namespace ts { /*@internal*/ export type PrivateClassElementDeclaration = | PrivateIdentifierPropertyDeclaration + | PrivateIdentifierAutoAccessorPropertyDeclaration | PrivateIdentifierMethodDeclaration | PrivateIdentifierGetAccessorDeclaration | PrivateIdentifierSetAccessorDeclaration; @@ -2051,7 +2077,7 @@ namespace ts { export interface StringLiteral extends LiteralExpression, Declaration { readonly kind: SyntaxKind.StringLiteral; - /* @internal */ readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). + /* @internal */ readonly textSourceNode?: Identifier | StringLiteralLike | NumericLiteral | PrivateIdentifier; // Allows a StringLiteral to get its text from another node (used by transforms). /** Note: this is only set when synthesizing a node, not during parsing. */ /* @internal */ readonly singleQuote?: boolean; } @@ -5287,6 +5313,7 @@ namespace ts { MethodExcludes = Value & ~Method, GetAccessorExcludes = Value & ~SetAccessor, SetAccessorExcludes = Value & ~GetAccessor, + AccessorExcludes = Value & ~Accessor, TypeParameterExcludes = Type & ~TypeParameter, TypeAliasExcludes = Type, AliasExcludes = Alias, @@ -7590,6 +7617,15 @@ namespace ts { convertToAssignmentElementTarget(node: BindingOrAssignmentElementTarget): Expression; } + /* @internal */ + export interface GeneratedNamePart { + /** an additional prefix to insert before the text sourced from `node` */ + prefix?: string; + node: Identifier | PrivateIdentifier; + /** an additional suffix to insert after the text sourced from `node` */ + suffix?: string; + } + export interface NodeFactory { /* @internal */ readonly parenthesizer: ParenthesizerRules; /* @internal */ readonly converters: NodeConverters; @@ -7605,7 +7641,7 @@ namespace ts { createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral; createStringLiteral(text: string, isSingleQuote?: boolean): StringLiteral; /* @internal*/ createStringLiteral(text: string, isSingleQuote?: boolean, hasExtendedUnicodeEscape?: boolean): StringLiteral; // eslint-disable-line @typescript-eslint/unified-signatures - createStringLiteralFromNode(sourceNode: PropertyNameLiteral, isSingleQuote?: boolean): StringLiteral; + createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier, isSingleQuote?: boolean): StringLiteral; createRegularExpressionLiteral(text: string): RegularExpressionLiteral; // @@ -7626,6 +7662,7 @@ namespace ts { * setting `EmitFlags.ReuseTempVariableScope` on the nested function itself. */ createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean): Identifier; + /*@internal*/ createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean, prefix?: string | GeneratedNamePart, suffix?: string): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures /** * Create a unique temporary variable for use in a loop. @@ -7637,11 +7674,17 @@ namespace ts { /** Create a unique name based on the supplied text. */ createUniqueName(text: string, flags?: GeneratedIdentifierFlags): Identifier; + /*@internal*/ createUniqueName(text: string, flags?: GeneratedIdentifierFlags, prefix?: string | GeneratedNamePart, suffix?: string): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures /** Create a unique name generated for a node. */ getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier; + /*@internal*/ getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags, prefix?: string | GeneratedNamePart, suffix?: string): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures createPrivateIdentifier(text: string): PrivateIdentifier + createUniquePrivateName(text?: string): PrivateIdentifier; + /*@internal*/ createUniquePrivateName(text?: string, prefix?: string | GeneratedNamePart, suffix?: string): PrivateIdentifier; // eslint-disable-line @typescript-eslint/unified-signatures + getGeneratedPrivateNameForNode(node: Node): PrivateIdentifier; + /*@internal*/ getGeneratedPrivateNameForNode(node: Node, prefix?: string | GeneratedNamePart, suffix?: string): PrivateIdentifier; // eslint-disable-line @typescript-eslint/unified-signatures // // Punctuation @@ -8508,7 +8551,7 @@ namespace ts { (nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; } - export type VisitResult = T | T[] | undefined; + export type VisitResult = T | readonly T[] | undefined; export interface Printer { /** diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c2ff0ab4fc7b0..792c7d1f5cb3c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -853,6 +853,10 @@ namespace ts { return false; } + export function isAmbientPropertyDeclaration(node: PropertyDeclaration) { + return !!(node.flags & NodeFlags.Ambient) || hasSyntacticModifier(node, ModifierFlags.Ambient); + } + export function isBlockScope(node: Node, parentNode: Node | undefined): boolean { switch (node.kind) { case SyntaxKind.SourceFile: @@ -996,7 +1000,7 @@ namespace ts { switch (name.kind) { case SyntaxKind.Identifier: case SyntaxKind.PrivateIdentifier: - return name.escapedText; + return name.autoGenerateFlags ? undefined : name.escapedText; case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: @@ -3407,7 +3411,7 @@ namespace ts { return false; } } - export function getTextOfIdentifierOrLiteral(node: PropertyNameLiteral): string { + export function getTextOfIdentifierOrLiteral(node: PropertyNameLiteral | PrivateIdentifier): string { return isMemberName(node) ? idText(node) : node.text; } @@ -4922,6 +4926,10 @@ namespace ts { return hasSyntacticModifier(node, ModifierFlags.Ambient); } + export function hasAccessorModifier(node: Node): boolean { + return hasSyntacticModifier(node, ModifierFlags.Accessor); + } + export function hasEffectiveReadonlyModifier(node: Node): boolean { return hasEffectiveModifier(node, ModifierFlags.Readonly); } @@ -5031,6 +5039,7 @@ namespace ts { case SyntaxKind.ProtectedKeyword: return ModifierFlags.Protected; case SyntaxKind.PrivateKeyword: return ModifierFlags.Private; case SyntaxKind.AbstractKeyword: return ModifierFlags.Abstract; + case SyntaxKind.AccessorKeyword: return ModifierFlags.Accessor; case SyntaxKind.ExportKeyword: return ModifierFlags.Export; case SyntaxKind.DeclareKeyword: return ModifierFlags.Ambient; case SyntaxKind.ConstKeyword: return ModifierFlags.Const; @@ -5045,10 +5054,6 @@ namespace ts { return ModifierFlags.None; } - export function createModifiers(modifierFlags: ModifierFlags): ModifiersArray | undefined { - return modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : undefined; - } - export function isLogicalOperator(token: SyntaxKind): boolean { return token === SyntaxKind.BarBarToken || token === SyntaxKind.AmpersandAmpersandToken diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index bc80f301e3ff8..c8b959eb8f87c 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1199,6 +1199,11 @@ namespace ts { return isIdentifier(node) && (node.autoGenerateFlags! & GeneratedIdentifierFlags.KindMask) > GeneratedIdentifierFlags.None; } + /* @internal */ + export function isGeneratedPrivateIdentifier(node: Node): node is GeneratedPrivateIdentifier { + return isPrivateIdentifier(node) && (node.autoGenerateFlags! & GeneratedIdentifierFlags.KindMask) > GeneratedIdentifierFlags.None; + } + // Private Identifiers /*@internal*/ export function isPrivateIdentifierClassElementDeclaration(node: Node): node is PrivateClassElementDeclaration { @@ -1216,6 +1221,7 @@ namespace ts { export function isModifierKind(token: SyntaxKind): token is Modifier["kind"] { switch (token) { case SyntaxKind.AbstractKeyword: + case SyntaxKind.AccessorKeyword: case SyntaxKind.AsyncKeyword: case SyntaxKind.ConstKeyword: case SyntaxKind.DeclareKeyword: @@ -1241,7 +1247,10 @@ namespace ts { /* @internal */ export function isClassMemberModifier(idToken: SyntaxKind): boolean { - return isParameterPropertyModifier(idToken) || idToken === SyntaxKind.StaticKeyword || idToken === SyntaxKind.OverrideKeyword; + return isParameterPropertyModifier(idToken) || + idToken === SyntaxKind.StaticKeyword || + idToken === SyntaxKind.OverrideKeyword || + idToken === SyntaxKind.AccessorKeyword; } export function isModifier(node: Node): node is Modifier { @@ -1349,6 +1358,10 @@ namespace ts { return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor); } + export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration { + return isPropertyDeclaration(node) && hasAccessorModifier(node); + } + /* @internal */ export function isMethodOrAccessor(node: Node): node is MethodDeclaration | AccessorDeclaration { switch (node.kind) { @@ -1361,6 +1374,19 @@ namespace ts { } } + /* @internal */ + export function isNamedClassElement(node: Node): node is MethodDeclaration | AccessorDeclaration | PropertyDeclaration { + switch (node.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.PropertyDeclaration: + return true; + default: + return false; + } + } + // Type members export function isModifierLike(node: Node): node is ModifierLike { diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 02eeee55ad72f..4069b1f86164a 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -44,6 +44,9 @@ namespace ts { return visitedNode as T; } + /* @internal */ + export function visitNodes(nodes: NodeArray, visitor: Visitor, test: (node: Node) => node is U, start?: number, count?: number): NodeArray; + /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -55,6 +58,9 @@ namespace ts { */ export function visitNodes(nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; + /* @internal */ + export function visitNodes(nodes: NodeArray | undefined, visitor: Visitor, test: (node: Node) => node is U, start?: number, count?: number): NodeArray | undefined; + /** * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place. * @@ -116,7 +122,14 @@ namespace ts { } /* @internal */ - export function visitArray(nodes: readonly T[] | undefined, visitor: Visitor, test: (node: Node) => node is U, start?: number, count?: number): readonly U[] | undefined { + export function visitArray(nodes: T[] | undefined, visitor: Visitor, test: (node: Node) => node is U, start?: number, count?: number): U[] | undefined; + /* @internal */ + export function visitArray(nodes: readonly T[] | undefined, visitor: Visitor, test: (node: Node) => node is U, start?: number, count?: number): readonly U[] | undefined; + /* @internal */ + export function visitArray(nodes: T[] | undefined, visitor: Visitor, test: (node: Node) => node is T, start?: number, count?: number): T[] | undefined; + /* @internal */ + export function visitArray(nodes: readonly T[] | undefined, visitor: Visitor, test: (node: Node) => node is T, start?: number, count?: number): readonly T[] | undefined; + export function visitArray(nodes: readonly T[] | undefined, visitor: Visitor, test: (node: Node) => node is U, start?: number, count?: number) { if (nodes === undefined) { return nodes; } diff --git a/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts b/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts index 6b14268806cdf..3bb201d1ec8a2 100644 --- a/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts +++ b/src/deprecatedCompat/4.0/nodeFactoryTopLevelExports.ts @@ -30,7 +30,7 @@ namespace ts { export const createLoopVariable = Debug.deprecate(factory.createLoopVariable, factoryDeprecation); /** @deprecated Use `factory.createUniqueName` or the factory supplied by your transformation context instead. */ - export const createUniqueName = Debug.deprecate(factory.createUniqueName, factoryDeprecation); + export const createUniqueName: (text: string, flags?: GeneratedIdentifierFlags | undefined) => Identifier = Debug.deprecate(factory.createUniqueName, factoryDeprecation); /** @deprecated Use `factory.createPrivateIdentifier` or the factory supplied by your transformation context instead. */ export const createPrivateIdentifier = Debug.deprecate(factory.createPrivateIdentifier, factoryDeprecation); diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index c43b8f0bc4cdd..4112072d38835 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1271,6 +1271,7 @@ namespace FourSlashInterface { export const classElementKeywords: readonly ExpectedCompletionEntryObject[] = [ "abstract", + "accessor", "async", "constructor", "declare", diff --git a/src/services/classifier.ts b/src/services/classifier.ts index ac15be962ab47..635652610a418 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -320,6 +320,7 @@ namespace ts { case SyntaxKind.SetKeyword: case SyntaxKind.ConstructorKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.AccessorKeyword: return true; // Allow things like "public get", "public constructor" and "public static". default: return false; // Any other keyword following "public" is actually an identifier, not a real keyword. diff --git a/src/services/codefixes/generateAccessors.ts b/src/services/codefixes/generateAccessors.ts index 7486feab0648c..4fe71a352158a 100644 --- a/src/services/codefixes/generateAccessors.ts +++ b/src/services/codefixes/generateAccessors.ts @@ -29,18 +29,18 @@ namespace ts.codefix { suppressLeadingAndTrailingTrivia(declaration); suppressLeadingAndTrailingTrivia(container); - let accessorModifiers: NodeArray | undefined; + let accessorModifiers: readonly ModifierLike[] | undefined; let fieldModifiers: readonly ModifierLike[] | undefined; if (isClassLike(container)) { const modifierFlags = getEffectiveModifierFlags(declaration); if (isSourceFileJS(file)) { - const modifiers = createModifiers(modifierFlags); + const modifiers = factory.createModifiersFromModifierFlags(modifierFlags); accessorModifiers = modifiers; fieldModifiers = modifiers; } else { - accessorModifiers = createModifiers(prepareModifierFlagsForAccessor(modifierFlags)); - fieldModifiers = createModifiers(prepareModifierFlagsForField(modifierFlags)); + accessorModifiers = factory.createModifiersFromModifierFlags(prepareModifierFlagsForAccessor(modifierFlags)); + fieldModifiers = factory.createModifiersFromModifierFlags(prepareModifierFlagsForField(modifierFlags)); } if (canHaveDecorators(declaration)) { fieldModifiers = concatenate(getDecorators(declaration), fieldModifiers); @@ -146,7 +146,7 @@ namespace ts.codefix { }; } - function generateGetAccessor(fieldName: AcceptedNameType, accessorName: AcceptedNameType, type: TypeNode | undefined, modifiers: NodeArray | undefined, isStatic: boolean, container: ContainerDeclaration) { + function generateGetAccessor(fieldName: AcceptedNameType, accessorName: AcceptedNameType, type: TypeNode | undefined, modifiers: readonly ModifierLike[] | undefined, isStatic: boolean, container: ContainerDeclaration) { return factory.createGetAccessorDeclaration( modifiers, accessorName, @@ -160,7 +160,7 @@ namespace ts.codefix { ); } - function generateSetAccessor(fieldName: AcceptedNameType, accessorName: AcceptedNameType, type: TypeNode | undefined, modifiers: NodeArray | undefined, isStatic: boolean, container: ContainerDeclaration) { + function generateSetAccessor(fieldName: AcceptedNameType, accessorName: AcceptedNameType, type: TypeNode | undefined, modifiers: readonly ModifierLike[] | undefined, isStatic: boolean, container: ContainerDeclaration) { return factory.createSetAccessorDeclaration( modifiers, accessorName, diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index ba8bd0453dd09..5e26fbb38ab63 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -79,8 +79,16 @@ namespace ts.codefix { * In such cases, we assume the declaration to be a `PropertySignature`. */ const kind = declaration?.kind ?? SyntaxKind.PropertySignature; - const declarationName = getNameOfDeclaration(declaration) as PropertyName; - const visibilityModifier = createVisibilityModifier(declaration ? getEffectiveModifierFlags(declaration) : ModifierFlags.None); + const declarationName = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName; + const effectiveModifierFlags = declaration ? getEffectiveModifierFlags(declaration) : ModifierFlags.None; + let modifierFlags = + effectiveModifierFlags & ModifierFlags.Public ? ModifierFlags.Public : + effectiveModifierFlags & ModifierFlags.Protected ? ModifierFlags.Protected : + ModifierFlags.None; + if (declaration && isAutoAccessorPropertyDeclaration(declaration)) { + modifierFlags |= ModifierFlags.Accessor; + } + const modifiers = modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : undefined; const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration)); const optional = !!(symbol.flags & SymbolFlags.Optional); const ambient = !!(enclosingDeclaration.flags & NodeFlags.Ambient) || isAmbient; @@ -99,7 +107,7 @@ namespace ts.codefix { } } addClassElement(factory.createPropertyDeclaration( - createModifiers(visibilityModifier), + modifiers, declaration ? createName(declarationName) : symbol.getName(), optional && (preserveOptional & PreserveOptionalFlags.Property) ? factory.createToken(SyntaxKind.QuestionToken) : undefined, typeNode, @@ -123,7 +131,7 @@ namespace ts.codefix { for (const accessor of orderedAccessors) { if (isGetAccessorDeclaration(accessor)) { addClassElement(factory.createGetAccessorDeclaration( - createModifiers(visibilityModifier), + modifiers, createName(declarationName), emptyArray, createTypeNode(typeNode), @@ -134,7 +142,7 @@ namespace ts.codefix { const parameter = getSetAccessorValueParameter(accessor); const parameterName = parameter && isIdentifier(parameter.name) ? idText(parameter.name) : undefined; addClassElement(factory.createSetAccessorDeclaration( - createModifiers(visibilityModifier), + modifiers, createName(declarationName), createDummyParameters(1, [parameterName], [createTypeNode(typeNode)], 1, /*inJs*/ false), createBody(body, quotePreference, ambient))); @@ -160,23 +168,23 @@ namespace ts.codefix { if (declarations.length === 1) { Debug.assert(signatures.length === 1, "One declaration implies one signature"); const signature = signatures[0]; - outputMethod(quotePreference, signature, createModifiers(visibilityModifier), createName(declarationName), createBody(body, quotePreference, ambient)); + outputMethod(quotePreference, signature, modifiers, createName(declarationName), createBody(body, quotePreference, ambient)); break; } for (const signature of signatures) { // Ensure nodes are fresh so they can have different positions when going through formatting. - outputMethod(quotePreference, signature, createModifiers(visibilityModifier), createName(declarationName)); + outputMethod(quotePreference, signature, modifiers, createName(declarationName)); } if (!ambient) { if (declarations.length > signatures.length) { const signature = checker.getSignatureFromDeclaration(declarations[declarations.length - 1] as SignatureDeclaration)!; - outputMethod(quotePreference, signature, createModifiers(visibilityModifier), createName(declarationName), createBody(body, quotePreference)); + outputMethod(quotePreference, signature, modifiers, createName(declarationName), createBody(body, quotePreference)); } else { Debug.assert(declarations.length === signatures.length, "Declarations and signatures should match count"); - addClassElement(createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, createName(declarationName), optional && !!(preserveOptional & PreserveOptionalFlags.Method), createModifiers(visibilityModifier), quotePreference, body)); + addClassElement(createMethodImplementingSignatures(checker, context, enclosingDeclaration, signatures, createName(declarationName), optional && !!(preserveOptional & PreserveOptionalFlags.Method), modifiers, quotePreference, body)); } } break; @@ -191,10 +199,6 @@ namespace ts.codefix { return getSynthesizedDeepClone(node, /*includeTrivia*/ false); } - function createModifiers(modifier: Modifier | undefined) { - return modifier ? factory.createNodeArray([modifier]) : undefined; - } - function createBody(block: Block | undefined, quotePreference: QuotePreference, ambient?: boolean) { return ambient ? undefined : getSynthesizedDeepClone(block, /*includeTrivia*/ false) || createStubbedMethodBody(quotePreference); @@ -644,16 +648,6 @@ namespace ts.codefix { /*multiline*/ true); } - function createVisibilityModifier(flags: ModifierFlags): Modifier | undefined { - if (flags & ModifierFlags.Public) { - return factory.createToken(SyntaxKind.PublicKeyword); - } - else if (flags & ModifierFlags.Protected) { - return factory.createToken(SyntaxKind.ProtectedKeyword); - } - return undefined; - } - export function setJsonCompilerOptionValues( changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile, diff --git a/src/services/completions.ts b/src/services/completions.ts index 36724b760a966..48e1c28bf01de 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -3949,6 +3949,7 @@ namespace ts.Completions { function isClassMemberCompletionKeyword(kind: SyntaxKind) { switch (kind) { case SyntaxKind.AbstractKeyword: + case SyntaxKind.AccessorKeyword: case SyntaxKind.ConstructorKeyword: case SyntaxKind.GetKeyword: case SyntaxKind.SetKeyword: diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index ab13fc16cdebd..637201b0c2546 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -149,6 +149,7 @@ namespace ts.formatting { "SpaceAfterCertainTypeScriptKeywords", [ SyntaxKind.AbstractKeyword, + SyntaxKind.AccessorKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 44113d901572e..87b5e16f29db9 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -159,7 +159,7 @@ namespace ts.SymbolDisplay { if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Alias) { // If symbol is accessor, they are allowed only if location is at declaration identifier of the accessor if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) { - const declaration = find(symbol.declarations as ((GetAccessorDeclaration | SetAccessorDeclaration)[]), declaration => declaration.name === location); + const declaration = find(symbol.declarations as ((GetAccessorDeclaration | SetAccessorDeclaration | PropertyDeclaration)[]), declaration => declaration.name === location); if (declaration) { switch(declaration.kind){ case SyntaxKind.GetAccessor: @@ -168,6 +168,9 @@ namespace ts.SymbolDisplay { case SyntaxKind.SetAccessor: symbolKind = ScriptElementKind.memberSetAccessorElement; break; + case SyntaxKind.PropertyDeclaration: + symbolKind = ScriptElementKind.memberAccessorVariableElement; + break; default: Debug.assertNever(declaration); } @@ -509,6 +512,7 @@ namespace ts.SymbolDisplay { } // For properties, variables and local vars: show the type if (symbolKind === ScriptElementKind.memberVariableElement || + symbolKind === ScriptElementKind.memberAccessorVariableElement || symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement || symbolKind === ScriptElementKind.jsxAttribute || diff --git a/src/services/types.ts b/src/services/types.ts index ff3d2ed56bcb4..98de7db46fe90 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -1467,6 +1467,9 @@ namespace ts { */ memberVariableElement = "property", + /** class X { [public|private]* accessor foo: number; } */ + memberAccessorVariableElement = "accessor", + /** * class X { constructor() { } } * class X { static { } } diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 8af0757080b1c..b7c699fcea611 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -89,6 +89,7 @@ "unittests/evaluation/arraySpread.ts", "unittests/evaluation/asyncArrow.ts", "unittests/evaluation/asyncGenerator.ts", + "unittests/evaluation/autoAccessors.ts", "unittests/evaluation/awaiter.ts", "unittests/evaluation/destructuring.ts", "unittests/evaluation/externalModules.ts", diff --git a/src/testRunner/unittests/evaluation/autoAccessors.ts b/src/testRunner/unittests/evaluation/autoAccessors.ts new file mode 100644 index 0000000000000..0873cd061e7f7 --- /dev/null +++ b/src/testRunner/unittests/evaluation/autoAccessors.ts @@ -0,0 +1,113 @@ +describe("unittests:: evaluation:: autoAccessors", () => { + const editions = [ + { name: "es2022", target: ts.ScriptTarget.ES2022 }, + { name: "es2015", target: ts.ScriptTarget.ES2015 }, + ]; + for (const { name, target } of editions) { + describe(name, () => { + it("generates accessor pair", async () => { + const { C } = evaluator.evaluateTypeScript(` + export class C { + accessor x; + } + `, { target }); + + const desc = Object.getOwnPropertyDescriptor(C.prototype, "x"); + assert.isDefined(desc); + assert.isFunction(desc!.get); + assert.isFunction(desc!.set); + }); + + it("storage is private", async () => { + const { C } = evaluator.evaluateTypeScript(` + export class C { + accessor x; + } + `, { target }); + + const desc = Object.getOwnPropertyDescriptor(C.prototype, "x"); + const obj = Object.create(C.prototype); + assert.throws(() => desc!.get!.call(obj), /private/); + }); + + it("getter and setter wrap same field", async () => { + const { C } = evaluator.evaluateTypeScript(` + export class C { + accessor x; + } + `, { target }); + const obj = new C(); + obj.x = 1; + assert.equal(obj.x, 1); + + obj.x = 2; + assert.equal(obj.x, 2); + }); + + it("supports initializer", async () => { + const { C } = evaluator.evaluateTypeScript(` + export class C { + accessor x = 1; + } + `, { target }); + const obj = new C(); + assert.equal(obj.x, 1); + }); + + it("legacy decorator can intercept getter/setter", async () => { + const { actions, C } = evaluator.evaluateTypeScript(` + function dec(target, key, descriptor) { + const { get, set } = descriptor; + actions.push({ kind: "decorate", target, key }); + descriptor.get = function() { + actions.push({ kind: "get", this: this }); + return get.call(this); + }; + descriptor.set = function(value) { + actions.push({ kind: "set", this: this, value }); + set.call(this, value); + }; + } + export const actions = []; + export class C { + @dec + accessor x; + } + `, { target, experimentalDecorators: true }); + + assert.deepEqual(actions, [ + { kind: "decorate", target: C.prototype, key: "x" } + ]); + const obj = new C(); + obj.x = 1; + assert.equal(obj.x, 1); + assert.deepEqual(actions, [ + { kind: "decorate", target: C.prototype, key: "x" }, + { kind: "set", this: obj, value: 1 }, + { kind: "get", this: obj }, + ]); + }); + + it("legacy decorator cannot intercept initializer", async () => { + const { actions, C } = evaluator.evaluateTypeScript(` + function dec(target, key, descriptor) { + const { get, set } = descriptor; + descriptor.set = function(value) { + actions.push({ kind: "set", this: this, value }); + set.call(this, value); + }; + } + export const actions = []; + export class C { + @dec + accessor x = 1; + } + `, { target, experimentalDecorators: true }); + + const obj = new C(); + assert.equal(obj.x, 1); + assert.deepEqual(actions, []); + }); + }); + } +}); \ No newline at end of file diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2544ef8fc6884..c30eeaecddad7 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -232,239 +232,240 @@ declare namespace ts { StaticKeyword = 124, YieldKeyword = 125, AbstractKeyword = 126, - AsKeyword = 127, - AssertsKeyword = 128, - AssertKeyword = 129, - AnyKeyword = 130, - AsyncKeyword = 131, - AwaitKeyword = 132, - BooleanKeyword = 133, - ConstructorKeyword = 134, - DeclareKeyword = 135, - GetKeyword = 136, - InferKeyword = 137, - IntrinsicKeyword = 138, - IsKeyword = 139, - KeyOfKeyword = 140, - ModuleKeyword = 141, - NamespaceKeyword = 142, - NeverKeyword = 143, - OutKeyword = 144, - ReadonlyKeyword = 145, - RequireKeyword = 146, - NumberKeyword = 147, - ObjectKeyword = 148, - SatisfiesKeyword = 149, - SetKeyword = 150, - StringKeyword = 151, - SymbolKeyword = 152, - TypeKeyword = 153, - UndefinedKeyword = 154, - UniqueKeyword = 155, - UnknownKeyword = 156, - FromKeyword = 157, - GlobalKeyword = 158, - BigIntKeyword = 159, - OverrideKeyword = 160, - OfKeyword = 161, - QualifiedName = 162, - ComputedPropertyName = 163, - TypeParameter = 164, - Parameter = 165, - Decorator = 166, - PropertySignature = 167, - PropertyDeclaration = 168, - MethodSignature = 169, - MethodDeclaration = 170, - ClassStaticBlockDeclaration = 171, - Constructor = 172, - GetAccessor = 173, - SetAccessor = 174, - CallSignature = 175, - ConstructSignature = 176, - IndexSignature = 177, - TypePredicate = 178, - TypeReference = 179, - FunctionType = 180, - ConstructorType = 181, - TypeQuery = 182, - TypeLiteral = 183, - ArrayType = 184, - TupleType = 185, - OptionalType = 186, - RestType = 187, - UnionType = 188, - IntersectionType = 189, - ConditionalType = 190, - InferType = 191, - ParenthesizedType = 192, - ThisType = 193, - TypeOperator = 194, - IndexedAccessType = 195, - MappedType = 196, - LiteralType = 197, - NamedTupleMember = 198, - TemplateLiteralType = 199, - TemplateLiteralTypeSpan = 200, - ImportType = 201, - ObjectBindingPattern = 202, - ArrayBindingPattern = 203, - BindingElement = 204, - ArrayLiteralExpression = 205, - ObjectLiteralExpression = 206, - PropertyAccessExpression = 207, - ElementAccessExpression = 208, - CallExpression = 209, - NewExpression = 210, - TaggedTemplateExpression = 211, - TypeAssertionExpression = 212, - ParenthesizedExpression = 213, - FunctionExpression = 214, - ArrowFunction = 215, - DeleteExpression = 216, - TypeOfExpression = 217, - VoidExpression = 218, - AwaitExpression = 219, - PrefixUnaryExpression = 220, - PostfixUnaryExpression = 221, - BinaryExpression = 222, - ConditionalExpression = 223, - TemplateExpression = 224, - YieldExpression = 225, - SpreadElement = 226, - ClassExpression = 227, - OmittedExpression = 228, - ExpressionWithTypeArguments = 229, - AsExpression = 230, - NonNullExpression = 231, - MetaProperty = 232, - SyntheticExpression = 233, - SatisfiesExpression = 234, - TemplateSpan = 235, - SemicolonClassElement = 236, - Block = 237, - EmptyStatement = 238, - VariableStatement = 239, - ExpressionStatement = 240, - IfStatement = 241, - DoStatement = 242, - WhileStatement = 243, - ForStatement = 244, - ForInStatement = 245, - ForOfStatement = 246, - ContinueStatement = 247, - BreakStatement = 248, - ReturnStatement = 249, - WithStatement = 250, - SwitchStatement = 251, - LabeledStatement = 252, - ThrowStatement = 253, - TryStatement = 254, - DebuggerStatement = 255, - VariableDeclaration = 256, - VariableDeclarationList = 257, - FunctionDeclaration = 258, - ClassDeclaration = 259, - InterfaceDeclaration = 260, - TypeAliasDeclaration = 261, - EnumDeclaration = 262, - ModuleDeclaration = 263, - ModuleBlock = 264, - CaseBlock = 265, - NamespaceExportDeclaration = 266, - ImportEqualsDeclaration = 267, - ImportDeclaration = 268, - ImportClause = 269, - NamespaceImport = 270, - NamedImports = 271, - ImportSpecifier = 272, - ExportAssignment = 273, - ExportDeclaration = 274, - NamedExports = 275, - NamespaceExport = 276, - ExportSpecifier = 277, - MissingDeclaration = 278, - ExternalModuleReference = 279, - JsxElement = 280, - JsxSelfClosingElement = 281, - JsxOpeningElement = 282, - JsxClosingElement = 283, - JsxFragment = 284, - JsxOpeningFragment = 285, - JsxClosingFragment = 286, - JsxAttribute = 287, - JsxAttributes = 288, - JsxSpreadAttribute = 289, - JsxExpression = 290, - CaseClause = 291, - DefaultClause = 292, - HeritageClause = 293, - CatchClause = 294, - AssertClause = 295, - AssertEntry = 296, - ImportTypeAssertionContainer = 297, - PropertyAssignment = 298, - ShorthandPropertyAssignment = 299, - SpreadAssignment = 300, - EnumMember = 301, - UnparsedPrologue = 302, - UnparsedPrepend = 303, - UnparsedText = 304, - UnparsedInternalText = 305, - UnparsedSyntheticReference = 306, - SourceFile = 307, - Bundle = 308, - UnparsedSource = 309, - InputFiles = 310, - JSDocTypeExpression = 311, - JSDocNameReference = 312, - JSDocMemberName = 313, - JSDocAllType = 314, - JSDocUnknownType = 315, - JSDocNullableType = 316, - JSDocNonNullableType = 317, - JSDocOptionalType = 318, - JSDocFunctionType = 319, - JSDocVariadicType = 320, - JSDocNamepathType = 321, - JSDoc = 322, + AccessorKeyword = 127, + AsKeyword = 128, + AssertsKeyword = 129, + AssertKeyword = 130, + AnyKeyword = 131, + AsyncKeyword = 132, + AwaitKeyword = 133, + BooleanKeyword = 134, + ConstructorKeyword = 135, + DeclareKeyword = 136, + GetKeyword = 137, + InferKeyword = 138, + IntrinsicKeyword = 139, + IsKeyword = 140, + KeyOfKeyword = 141, + ModuleKeyword = 142, + NamespaceKeyword = 143, + NeverKeyword = 144, + OutKeyword = 145, + ReadonlyKeyword = 146, + RequireKeyword = 147, + NumberKeyword = 148, + ObjectKeyword = 149, + SatisfiesKeyword = 150, + SetKeyword = 151, + StringKeyword = 152, + SymbolKeyword = 153, + TypeKeyword = 154, + UndefinedKeyword = 155, + UniqueKeyword = 156, + UnknownKeyword = 157, + FromKeyword = 158, + GlobalKeyword = 159, + BigIntKeyword = 160, + OverrideKeyword = 161, + OfKeyword = 162, + QualifiedName = 163, + ComputedPropertyName = 164, + TypeParameter = 165, + Parameter = 166, + Decorator = 167, + PropertySignature = 168, + PropertyDeclaration = 169, + MethodSignature = 170, + MethodDeclaration = 171, + ClassStaticBlockDeclaration = 172, + Constructor = 173, + GetAccessor = 174, + SetAccessor = 175, + CallSignature = 176, + ConstructSignature = 177, + IndexSignature = 178, + TypePredicate = 179, + TypeReference = 180, + FunctionType = 181, + ConstructorType = 182, + TypeQuery = 183, + TypeLiteral = 184, + ArrayType = 185, + TupleType = 186, + OptionalType = 187, + RestType = 188, + UnionType = 189, + IntersectionType = 190, + ConditionalType = 191, + InferType = 192, + ParenthesizedType = 193, + ThisType = 194, + TypeOperator = 195, + IndexedAccessType = 196, + MappedType = 197, + LiteralType = 198, + NamedTupleMember = 199, + TemplateLiteralType = 200, + TemplateLiteralTypeSpan = 201, + ImportType = 202, + ObjectBindingPattern = 203, + ArrayBindingPattern = 204, + BindingElement = 205, + ArrayLiteralExpression = 206, + ObjectLiteralExpression = 207, + PropertyAccessExpression = 208, + ElementAccessExpression = 209, + CallExpression = 210, + NewExpression = 211, + TaggedTemplateExpression = 212, + TypeAssertionExpression = 213, + ParenthesizedExpression = 214, + FunctionExpression = 215, + ArrowFunction = 216, + DeleteExpression = 217, + TypeOfExpression = 218, + VoidExpression = 219, + AwaitExpression = 220, + PrefixUnaryExpression = 221, + PostfixUnaryExpression = 222, + BinaryExpression = 223, + ConditionalExpression = 224, + TemplateExpression = 225, + YieldExpression = 226, + SpreadElement = 227, + ClassExpression = 228, + OmittedExpression = 229, + ExpressionWithTypeArguments = 230, + AsExpression = 231, + NonNullExpression = 232, + MetaProperty = 233, + SyntheticExpression = 234, + SatisfiesExpression = 235, + TemplateSpan = 236, + SemicolonClassElement = 237, + Block = 238, + EmptyStatement = 239, + VariableStatement = 240, + ExpressionStatement = 241, + IfStatement = 242, + DoStatement = 243, + WhileStatement = 244, + ForStatement = 245, + ForInStatement = 246, + ForOfStatement = 247, + ContinueStatement = 248, + BreakStatement = 249, + ReturnStatement = 250, + WithStatement = 251, + SwitchStatement = 252, + LabeledStatement = 253, + ThrowStatement = 254, + TryStatement = 255, + DebuggerStatement = 256, + VariableDeclaration = 257, + VariableDeclarationList = 258, + FunctionDeclaration = 259, + ClassDeclaration = 260, + InterfaceDeclaration = 261, + TypeAliasDeclaration = 262, + EnumDeclaration = 263, + ModuleDeclaration = 264, + ModuleBlock = 265, + CaseBlock = 266, + NamespaceExportDeclaration = 267, + ImportEqualsDeclaration = 268, + ImportDeclaration = 269, + ImportClause = 270, + NamespaceImport = 271, + NamedImports = 272, + ImportSpecifier = 273, + ExportAssignment = 274, + ExportDeclaration = 275, + NamedExports = 276, + NamespaceExport = 277, + ExportSpecifier = 278, + MissingDeclaration = 279, + ExternalModuleReference = 280, + JsxElement = 281, + JsxSelfClosingElement = 282, + JsxOpeningElement = 283, + JsxClosingElement = 284, + JsxFragment = 285, + JsxOpeningFragment = 286, + JsxClosingFragment = 287, + JsxAttribute = 288, + JsxAttributes = 289, + JsxSpreadAttribute = 290, + JsxExpression = 291, + CaseClause = 292, + DefaultClause = 293, + HeritageClause = 294, + CatchClause = 295, + AssertClause = 296, + AssertEntry = 297, + ImportTypeAssertionContainer = 298, + PropertyAssignment = 299, + ShorthandPropertyAssignment = 300, + SpreadAssignment = 301, + EnumMember = 302, + UnparsedPrologue = 303, + UnparsedPrepend = 304, + UnparsedText = 305, + UnparsedInternalText = 306, + UnparsedSyntheticReference = 307, + SourceFile = 308, + Bundle = 309, + UnparsedSource = 310, + InputFiles = 311, + JSDocTypeExpression = 312, + JSDocNameReference = 313, + JSDocMemberName = 314, + JSDocAllType = 315, + JSDocUnknownType = 316, + JSDocNullableType = 317, + JSDocNonNullableType = 318, + JSDocOptionalType = 319, + JSDocFunctionType = 320, + JSDocVariadicType = 321, + JSDocNamepathType = 322, + JSDoc = 323, /** @deprecated Use SyntaxKind.JSDoc */ - JSDocComment = 322, - JSDocText = 323, - JSDocTypeLiteral = 324, - JSDocSignature = 325, - JSDocLink = 326, - JSDocLinkCode = 327, - JSDocLinkPlain = 328, - JSDocTag = 329, - JSDocAugmentsTag = 330, - JSDocImplementsTag = 331, - JSDocAuthorTag = 332, - JSDocDeprecatedTag = 333, - JSDocClassTag = 334, - JSDocPublicTag = 335, - JSDocPrivateTag = 336, - JSDocProtectedTag = 337, - JSDocReadonlyTag = 338, - JSDocOverrideTag = 339, - JSDocCallbackTag = 340, - JSDocEnumTag = 341, - JSDocParameterTag = 342, - JSDocReturnTag = 343, - JSDocThisTag = 344, - JSDocTypeTag = 345, - JSDocTemplateTag = 346, - JSDocTypedefTag = 347, - JSDocSeeTag = 348, - JSDocPropertyTag = 349, - SyntaxList = 350, - NotEmittedStatement = 351, - PartiallyEmittedExpression = 352, - CommaListExpression = 353, - MergeDeclarationMarker = 354, - EndOfDeclarationMarker = 355, - SyntheticReferenceExpression = 356, - Count = 357, + JSDocComment = 323, + JSDocText = 324, + JSDocTypeLiteral = 325, + JSDocSignature = 326, + JSDocLink = 327, + JSDocLinkCode = 328, + JSDocLinkPlain = 329, + JSDocTag = 330, + JSDocAugmentsTag = 331, + JSDocImplementsTag = 332, + JSDocAuthorTag = 333, + JSDocDeprecatedTag = 334, + JSDocClassTag = 335, + JSDocPublicTag = 336, + JSDocPrivateTag = 337, + JSDocProtectedTag = 338, + JSDocReadonlyTag = 339, + JSDocOverrideTag = 340, + JSDocCallbackTag = 341, + JSDocEnumTag = 342, + JSDocParameterTag = 343, + JSDocReturnTag = 344, + JSDocThisTag = 345, + JSDocTypeTag = 346, + JSDocTemplateTag = 347, + JSDocTypedefTag = 348, + JSDocSeeTag = 349, + JSDocPropertyTag = 350, + SyntaxList = 351, + NotEmittedStatement = 352, + PartiallyEmittedExpression = 353, + CommaListExpression = 354, + MergeDeclarationMarker = 355, + EndOfDeclarationMarker = 356, + SyntheticReferenceExpression = 357, + Count = 358, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -472,15 +473,15 @@ declare namespace ts { FirstReservedWord = 81, LastReservedWord = 116, FirstKeyword = 81, - LastKeyword = 161, + LastKeyword = 162, FirstFutureReservedWord = 117, LastFutureReservedWord = 125, - FirstTypeNode = 178, - LastTypeNode = 201, + FirstTypeNode = 179, + LastTypeNode = 202, FirstPunctuation = 18, LastPunctuation = 78, FirstToken = 0, - LastToken = 161, + LastToken = 162, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -489,20 +490,20 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 78, - FirstStatement = 239, - LastStatement = 255, - FirstNode = 162, - FirstJSDocNode = 311, - LastJSDocNode = 349, - FirstJSDocTagNode = 329, - LastJSDocTagNode = 349, + FirstStatement = 240, + LastStatement = 256, + FirstNode = 163, + FirstJSDocNode = 312, + LastJSDocNode = 350, + FirstJSDocTagNode = 330, + LastJSDocTagNode = 350, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; export type PunctuationSyntaxKind = SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.DotToken | SyntaxKind.DotDotDotToken | SyntaxKind.SemicolonToken | SyntaxKind.CommaToken | SyntaxKind.QuestionDotToken | SyntaxKind.LessThanToken | SyntaxKind.LessThanSlashToken | SyntaxKind.GreaterThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.EqualsEqualsToken | SyntaxKind.ExclamationEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.EqualsGreaterThanToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.AsteriskToken | SyntaxKind.AsteriskAsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken | SyntaxKind.ExclamationToken | SyntaxKind.TildeToken | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken | SyntaxKind.QuestionQuestionToken | SyntaxKind.QuestionToken | SyntaxKind.ColonToken | SyntaxKind.AtToken | SyntaxKind.BacktickToken | SyntaxKind.HashToken | SyntaxKind.EqualsToken | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SatisfiesKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; - export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; + export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SatisfiesKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; + export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; @@ -547,9 +548,10 @@ declare namespace ts { Protected = 16, Static = 32, Readonly = 64, - Abstract = 128, - Async = 256, - Default = 512, + Accessor = 128, + Abstract = 256, + Async = 512, + Default = 1024, Const = 2048, HasComputedJSDocModifiers = 4096, Deprecated = 8192, @@ -561,10 +563,10 @@ declare namespace ts { AccessibilityModifier = 28, ParameterPropertyModifier = 16476, NonPublicAccessibilityModifier = 24, - TypeScriptModifier = 116958, - ExportDefault = 513, - All = 257023, - Modifier = 125951 + TypeScriptModifier = 117086, + ExportDefault = 1025, + All = 258047, + Modifier = 126975 } export enum JsxFlags { None = 0, @@ -620,6 +622,7 @@ declare namespace ts { export interface ModifierToken extends KeywordToken { } export type AbstractKeyword = ModifierToken; + export type AccessorKeyword = ModifierToken; export type AsyncKeyword = ModifierToken; export type ConstKeyword = ModifierToken; export type DeclareKeyword = ModifierToken; @@ -635,11 +638,11 @@ declare namespace ts { export type StaticKeyword = ModifierToken; /** @deprecated Use `ReadonlyKeyword` instead. */ export type ReadonlyToken = ReadonlyKeyword; - export type Modifier = AbstractKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | InKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OutKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; + export type Modifier = AbstractKeyword | AccessorKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | InKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OutKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; export type ModifierLike = Modifier | Decorator; export type AccessibilityModifier = PublicKeyword | PrivateKeyword | ProtectedKeyword; export type ParameterPropertyModifier = AccessibilityModifier | ReadonlyKeyword; - export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword; + export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword | AccessorKeyword; export type ModifiersArray = NodeArray; export enum GeneratedIdentifierFlags { None = 0, @@ -766,6 +769,9 @@ declare namespace ts { readonly type?: TypeNode; readonly initializer?: Expression; } + export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { + _autoAccessorBrand: any; + } export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; readonly name?: PropertyName; @@ -2570,6 +2576,7 @@ declare namespace ts { MethodExcludes = 103359, GetAccessorExcludes = 46015, SetAccessorExcludes = 78783, + AccessorExcludes = 13247, TypeParameterExcludes = 526824, TypeAliasExcludes = 788968, AliasExcludes = 2097152, @@ -3395,7 +3402,7 @@ declare namespace ts { createNumericLiteral(value: string | number, numericLiteralFlags?: TokenFlags): NumericLiteral; createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral; createStringLiteral(text: string, isSingleQuote?: boolean): StringLiteral; - createStringLiteralFromNode(sourceNode: PropertyNameLiteral, isSingleQuote?: boolean): StringLiteral; + createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier, isSingleQuote?: boolean): StringLiteral; createRegularExpressionLiteral(text: string): RegularExpressionLiteral; createIdentifier(text: string): Identifier; /** @@ -3420,6 +3427,8 @@ declare namespace ts { /** Create a unique name generated for a node. */ getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier; createPrivateIdentifier(text: string): PrivateIdentifier; + createUniquePrivateName(text?: string): PrivateIdentifier; + getGeneratedPrivateNameForNode(node: Node): PrivateIdentifier; createToken(token: SyntaxKind.SuperKeyword): SuperExpression; createToken(token: SyntaxKind.ThisKeyword): ThisExpression; createToken(token: SyntaxKind.NullKeyword): NullLiteral; @@ -3958,7 +3967,7 @@ declare namespace ts { (nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; (nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; } - export type VisitResult = T | T[] | undefined; + export type VisitResult = T | readonly T[] | undefined; export interface Printer { /** * Print a node and its subtree as-is, without any emit transformations. @@ -4525,6 +4534,7 @@ declare namespace ts { function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; + function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration; function isModifierLike(node: Node): node is ModifierLike; function isTypeElement(node: Node): node is TypeElement; function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; @@ -6750,6 +6760,8 @@ declare namespace ts { * interface Y { foo:number; } */ memberVariableElement = "property", + /** class X { [public|private]* accessor foo: number; } */ + memberAccessorVariableElement = "accessor", /** * class X { constructor() { } } * class X { static { } } @@ -10896,7 +10908,7 @@ declare namespace ts { (text: string, isSingleQuote?: boolean | undefined, hasExtendedUnicodeEscape?: boolean | undefined): StringLiteral; }; /** @deprecated Use `factory.createStringLiteralFromNode` or the factory supplied by your transformation context instead. */ - const createStringLiteralFromNode: (sourceNode: PropertyNameLiteral, isSingleQuote?: boolean | undefined) => StringLiteral; + const createStringLiteralFromNode: (sourceNode: PrivateIdentifier | PropertyNameLiteral, isSingleQuote?: boolean | undefined) => StringLiteral; /** @deprecated Use `factory.createRegularExpressionLiteral` or the factory supplied by your transformation context instead. */ const createRegularExpressionLiteral: (text: string) => RegularExpressionLiteral; /** @deprecated Use `factory.createLoopVariable` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 1f2b8230a6e12..847e1301be640 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -232,239 +232,240 @@ declare namespace ts { StaticKeyword = 124, YieldKeyword = 125, AbstractKeyword = 126, - AsKeyword = 127, - AssertsKeyword = 128, - AssertKeyword = 129, - AnyKeyword = 130, - AsyncKeyword = 131, - AwaitKeyword = 132, - BooleanKeyword = 133, - ConstructorKeyword = 134, - DeclareKeyword = 135, - GetKeyword = 136, - InferKeyword = 137, - IntrinsicKeyword = 138, - IsKeyword = 139, - KeyOfKeyword = 140, - ModuleKeyword = 141, - NamespaceKeyword = 142, - NeverKeyword = 143, - OutKeyword = 144, - ReadonlyKeyword = 145, - RequireKeyword = 146, - NumberKeyword = 147, - ObjectKeyword = 148, - SatisfiesKeyword = 149, - SetKeyword = 150, - StringKeyword = 151, - SymbolKeyword = 152, - TypeKeyword = 153, - UndefinedKeyword = 154, - UniqueKeyword = 155, - UnknownKeyword = 156, - FromKeyword = 157, - GlobalKeyword = 158, - BigIntKeyword = 159, - OverrideKeyword = 160, - OfKeyword = 161, - QualifiedName = 162, - ComputedPropertyName = 163, - TypeParameter = 164, - Parameter = 165, - Decorator = 166, - PropertySignature = 167, - PropertyDeclaration = 168, - MethodSignature = 169, - MethodDeclaration = 170, - ClassStaticBlockDeclaration = 171, - Constructor = 172, - GetAccessor = 173, - SetAccessor = 174, - CallSignature = 175, - ConstructSignature = 176, - IndexSignature = 177, - TypePredicate = 178, - TypeReference = 179, - FunctionType = 180, - ConstructorType = 181, - TypeQuery = 182, - TypeLiteral = 183, - ArrayType = 184, - TupleType = 185, - OptionalType = 186, - RestType = 187, - UnionType = 188, - IntersectionType = 189, - ConditionalType = 190, - InferType = 191, - ParenthesizedType = 192, - ThisType = 193, - TypeOperator = 194, - IndexedAccessType = 195, - MappedType = 196, - LiteralType = 197, - NamedTupleMember = 198, - TemplateLiteralType = 199, - TemplateLiteralTypeSpan = 200, - ImportType = 201, - ObjectBindingPattern = 202, - ArrayBindingPattern = 203, - BindingElement = 204, - ArrayLiteralExpression = 205, - ObjectLiteralExpression = 206, - PropertyAccessExpression = 207, - ElementAccessExpression = 208, - CallExpression = 209, - NewExpression = 210, - TaggedTemplateExpression = 211, - TypeAssertionExpression = 212, - ParenthesizedExpression = 213, - FunctionExpression = 214, - ArrowFunction = 215, - DeleteExpression = 216, - TypeOfExpression = 217, - VoidExpression = 218, - AwaitExpression = 219, - PrefixUnaryExpression = 220, - PostfixUnaryExpression = 221, - BinaryExpression = 222, - ConditionalExpression = 223, - TemplateExpression = 224, - YieldExpression = 225, - SpreadElement = 226, - ClassExpression = 227, - OmittedExpression = 228, - ExpressionWithTypeArguments = 229, - AsExpression = 230, - NonNullExpression = 231, - MetaProperty = 232, - SyntheticExpression = 233, - SatisfiesExpression = 234, - TemplateSpan = 235, - SemicolonClassElement = 236, - Block = 237, - EmptyStatement = 238, - VariableStatement = 239, - ExpressionStatement = 240, - IfStatement = 241, - DoStatement = 242, - WhileStatement = 243, - ForStatement = 244, - ForInStatement = 245, - ForOfStatement = 246, - ContinueStatement = 247, - BreakStatement = 248, - ReturnStatement = 249, - WithStatement = 250, - SwitchStatement = 251, - LabeledStatement = 252, - ThrowStatement = 253, - TryStatement = 254, - DebuggerStatement = 255, - VariableDeclaration = 256, - VariableDeclarationList = 257, - FunctionDeclaration = 258, - ClassDeclaration = 259, - InterfaceDeclaration = 260, - TypeAliasDeclaration = 261, - EnumDeclaration = 262, - ModuleDeclaration = 263, - ModuleBlock = 264, - CaseBlock = 265, - NamespaceExportDeclaration = 266, - ImportEqualsDeclaration = 267, - ImportDeclaration = 268, - ImportClause = 269, - NamespaceImport = 270, - NamedImports = 271, - ImportSpecifier = 272, - ExportAssignment = 273, - ExportDeclaration = 274, - NamedExports = 275, - NamespaceExport = 276, - ExportSpecifier = 277, - MissingDeclaration = 278, - ExternalModuleReference = 279, - JsxElement = 280, - JsxSelfClosingElement = 281, - JsxOpeningElement = 282, - JsxClosingElement = 283, - JsxFragment = 284, - JsxOpeningFragment = 285, - JsxClosingFragment = 286, - JsxAttribute = 287, - JsxAttributes = 288, - JsxSpreadAttribute = 289, - JsxExpression = 290, - CaseClause = 291, - DefaultClause = 292, - HeritageClause = 293, - CatchClause = 294, - AssertClause = 295, - AssertEntry = 296, - ImportTypeAssertionContainer = 297, - PropertyAssignment = 298, - ShorthandPropertyAssignment = 299, - SpreadAssignment = 300, - EnumMember = 301, - UnparsedPrologue = 302, - UnparsedPrepend = 303, - UnparsedText = 304, - UnparsedInternalText = 305, - UnparsedSyntheticReference = 306, - SourceFile = 307, - Bundle = 308, - UnparsedSource = 309, - InputFiles = 310, - JSDocTypeExpression = 311, - JSDocNameReference = 312, - JSDocMemberName = 313, - JSDocAllType = 314, - JSDocUnknownType = 315, - JSDocNullableType = 316, - JSDocNonNullableType = 317, - JSDocOptionalType = 318, - JSDocFunctionType = 319, - JSDocVariadicType = 320, - JSDocNamepathType = 321, - JSDoc = 322, + AccessorKeyword = 127, + AsKeyword = 128, + AssertsKeyword = 129, + AssertKeyword = 130, + AnyKeyword = 131, + AsyncKeyword = 132, + AwaitKeyword = 133, + BooleanKeyword = 134, + ConstructorKeyword = 135, + DeclareKeyword = 136, + GetKeyword = 137, + InferKeyword = 138, + IntrinsicKeyword = 139, + IsKeyword = 140, + KeyOfKeyword = 141, + ModuleKeyword = 142, + NamespaceKeyword = 143, + NeverKeyword = 144, + OutKeyword = 145, + ReadonlyKeyword = 146, + RequireKeyword = 147, + NumberKeyword = 148, + ObjectKeyword = 149, + SatisfiesKeyword = 150, + SetKeyword = 151, + StringKeyword = 152, + SymbolKeyword = 153, + TypeKeyword = 154, + UndefinedKeyword = 155, + UniqueKeyword = 156, + UnknownKeyword = 157, + FromKeyword = 158, + GlobalKeyword = 159, + BigIntKeyword = 160, + OverrideKeyword = 161, + OfKeyword = 162, + QualifiedName = 163, + ComputedPropertyName = 164, + TypeParameter = 165, + Parameter = 166, + Decorator = 167, + PropertySignature = 168, + PropertyDeclaration = 169, + MethodSignature = 170, + MethodDeclaration = 171, + ClassStaticBlockDeclaration = 172, + Constructor = 173, + GetAccessor = 174, + SetAccessor = 175, + CallSignature = 176, + ConstructSignature = 177, + IndexSignature = 178, + TypePredicate = 179, + TypeReference = 180, + FunctionType = 181, + ConstructorType = 182, + TypeQuery = 183, + TypeLiteral = 184, + ArrayType = 185, + TupleType = 186, + OptionalType = 187, + RestType = 188, + UnionType = 189, + IntersectionType = 190, + ConditionalType = 191, + InferType = 192, + ParenthesizedType = 193, + ThisType = 194, + TypeOperator = 195, + IndexedAccessType = 196, + MappedType = 197, + LiteralType = 198, + NamedTupleMember = 199, + TemplateLiteralType = 200, + TemplateLiteralTypeSpan = 201, + ImportType = 202, + ObjectBindingPattern = 203, + ArrayBindingPattern = 204, + BindingElement = 205, + ArrayLiteralExpression = 206, + ObjectLiteralExpression = 207, + PropertyAccessExpression = 208, + ElementAccessExpression = 209, + CallExpression = 210, + NewExpression = 211, + TaggedTemplateExpression = 212, + TypeAssertionExpression = 213, + ParenthesizedExpression = 214, + FunctionExpression = 215, + ArrowFunction = 216, + DeleteExpression = 217, + TypeOfExpression = 218, + VoidExpression = 219, + AwaitExpression = 220, + PrefixUnaryExpression = 221, + PostfixUnaryExpression = 222, + BinaryExpression = 223, + ConditionalExpression = 224, + TemplateExpression = 225, + YieldExpression = 226, + SpreadElement = 227, + ClassExpression = 228, + OmittedExpression = 229, + ExpressionWithTypeArguments = 230, + AsExpression = 231, + NonNullExpression = 232, + MetaProperty = 233, + SyntheticExpression = 234, + SatisfiesExpression = 235, + TemplateSpan = 236, + SemicolonClassElement = 237, + Block = 238, + EmptyStatement = 239, + VariableStatement = 240, + ExpressionStatement = 241, + IfStatement = 242, + DoStatement = 243, + WhileStatement = 244, + ForStatement = 245, + ForInStatement = 246, + ForOfStatement = 247, + ContinueStatement = 248, + BreakStatement = 249, + ReturnStatement = 250, + WithStatement = 251, + SwitchStatement = 252, + LabeledStatement = 253, + ThrowStatement = 254, + TryStatement = 255, + DebuggerStatement = 256, + VariableDeclaration = 257, + VariableDeclarationList = 258, + FunctionDeclaration = 259, + ClassDeclaration = 260, + InterfaceDeclaration = 261, + TypeAliasDeclaration = 262, + EnumDeclaration = 263, + ModuleDeclaration = 264, + ModuleBlock = 265, + CaseBlock = 266, + NamespaceExportDeclaration = 267, + ImportEqualsDeclaration = 268, + ImportDeclaration = 269, + ImportClause = 270, + NamespaceImport = 271, + NamedImports = 272, + ImportSpecifier = 273, + ExportAssignment = 274, + ExportDeclaration = 275, + NamedExports = 276, + NamespaceExport = 277, + ExportSpecifier = 278, + MissingDeclaration = 279, + ExternalModuleReference = 280, + JsxElement = 281, + JsxSelfClosingElement = 282, + JsxOpeningElement = 283, + JsxClosingElement = 284, + JsxFragment = 285, + JsxOpeningFragment = 286, + JsxClosingFragment = 287, + JsxAttribute = 288, + JsxAttributes = 289, + JsxSpreadAttribute = 290, + JsxExpression = 291, + CaseClause = 292, + DefaultClause = 293, + HeritageClause = 294, + CatchClause = 295, + AssertClause = 296, + AssertEntry = 297, + ImportTypeAssertionContainer = 298, + PropertyAssignment = 299, + ShorthandPropertyAssignment = 300, + SpreadAssignment = 301, + EnumMember = 302, + UnparsedPrologue = 303, + UnparsedPrepend = 304, + UnparsedText = 305, + UnparsedInternalText = 306, + UnparsedSyntheticReference = 307, + SourceFile = 308, + Bundle = 309, + UnparsedSource = 310, + InputFiles = 311, + JSDocTypeExpression = 312, + JSDocNameReference = 313, + JSDocMemberName = 314, + JSDocAllType = 315, + JSDocUnknownType = 316, + JSDocNullableType = 317, + JSDocNonNullableType = 318, + JSDocOptionalType = 319, + JSDocFunctionType = 320, + JSDocVariadicType = 321, + JSDocNamepathType = 322, + JSDoc = 323, /** @deprecated Use SyntaxKind.JSDoc */ - JSDocComment = 322, - JSDocText = 323, - JSDocTypeLiteral = 324, - JSDocSignature = 325, - JSDocLink = 326, - JSDocLinkCode = 327, - JSDocLinkPlain = 328, - JSDocTag = 329, - JSDocAugmentsTag = 330, - JSDocImplementsTag = 331, - JSDocAuthorTag = 332, - JSDocDeprecatedTag = 333, - JSDocClassTag = 334, - JSDocPublicTag = 335, - JSDocPrivateTag = 336, - JSDocProtectedTag = 337, - JSDocReadonlyTag = 338, - JSDocOverrideTag = 339, - JSDocCallbackTag = 340, - JSDocEnumTag = 341, - JSDocParameterTag = 342, - JSDocReturnTag = 343, - JSDocThisTag = 344, - JSDocTypeTag = 345, - JSDocTemplateTag = 346, - JSDocTypedefTag = 347, - JSDocSeeTag = 348, - JSDocPropertyTag = 349, - SyntaxList = 350, - NotEmittedStatement = 351, - PartiallyEmittedExpression = 352, - CommaListExpression = 353, - MergeDeclarationMarker = 354, - EndOfDeclarationMarker = 355, - SyntheticReferenceExpression = 356, - Count = 357, + JSDocComment = 323, + JSDocText = 324, + JSDocTypeLiteral = 325, + JSDocSignature = 326, + JSDocLink = 327, + JSDocLinkCode = 328, + JSDocLinkPlain = 329, + JSDocTag = 330, + JSDocAugmentsTag = 331, + JSDocImplementsTag = 332, + JSDocAuthorTag = 333, + JSDocDeprecatedTag = 334, + JSDocClassTag = 335, + JSDocPublicTag = 336, + JSDocPrivateTag = 337, + JSDocProtectedTag = 338, + JSDocReadonlyTag = 339, + JSDocOverrideTag = 340, + JSDocCallbackTag = 341, + JSDocEnumTag = 342, + JSDocParameterTag = 343, + JSDocReturnTag = 344, + JSDocThisTag = 345, + JSDocTypeTag = 346, + JSDocTemplateTag = 347, + JSDocTypedefTag = 348, + JSDocSeeTag = 349, + JSDocPropertyTag = 350, + SyntaxList = 351, + NotEmittedStatement = 352, + PartiallyEmittedExpression = 353, + CommaListExpression = 354, + MergeDeclarationMarker = 355, + EndOfDeclarationMarker = 356, + SyntheticReferenceExpression = 357, + Count = 358, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -472,15 +473,15 @@ declare namespace ts { FirstReservedWord = 81, LastReservedWord = 116, FirstKeyword = 81, - LastKeyword = 161, + LastKeyword = 162, FirstFutureReservedWord = 117, LastFutureReservedWord = 125, - FirstTypeNode = 178, - LastTypeNode = 201, + FirstTypeNode = 179, + LastTypeNode = 202, FirstPunctuation = 18, LastPunctuation = 78, FirstToken = 0, - LastToken = 161, + LastToken = 162, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -489,20 +490,20 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 78, - FirstStatement = 239, - LastStatement = 255, - FirstNode = 162, - FirstJSDocNode = 311, - LastJSDocNode = 349, - FirstJSDocTagNode = 329, - LastJSDocTagNode = 349, + FirstStatement = 240, + LastStatement = 256, + FirstNode = 163, + FirstJSDocNode = 312, + LastJSDocNode = 350, + FirstJSDocTagNode = 330, + LastJSDocTagNode = 350, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; export type PunctuationSyntaxKind = SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.DotToken | SyntaxKind.DotDotDotToken | SyntaxKind.SemicolonToken | SyntaxKind.CommaToken | SyntaxKind.QuestionDotToken | SyntaxKind.LessThanToken | SyntaxKind.LessThanSlashToken | SyntaxKind.GreaterThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.EqualsEqualsToken | SyntaxKind.ExclamationEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.EqualsGreaterThanToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.AsteriskToken | SyntaxKind.AsteriskAsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken | SyntaxKind.ExclamationToken | SyntaxKind.TildeToken | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken | SyntaxKind.QuestionQuestionToken | SyntaxKind.QuestionToken | SyntaxKind.ColonToken | SyntaxKind.AtToken | SyntaxKind.BacktickToken | SyntaxKind.HashToken | SyntaxKind.EqualsToken | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SatisfiesKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; - export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; + export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SatisfiesKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; + export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AccessorKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.InKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.OutKeyword | SyntaxKind.OverrideKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; export type JsxTokenSyntaxKind = SyntaxKind.LessThanSlashToken | SyntaxKind.EndOfFileToken | SyntaxKind.ConflictMarkerTrivia | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.OpenBraceToken | SyntaxKind.LessThanToken; @@ -547,9 +548,10 @@ declare namespace ts { Protected = 16, Static = 32, Readonly = 64, - Abstract = 128, - Async = 256, - Default = 512, + Accessor = 128, + Abstract = 256, + Async = 512, + Default = 1024, Const = 2048, HasComputedJSDocModifiers = 4096, Deprecated = 8192, @@ -561,10 +563,10 @@ declare namespace ts { AccessibilityModifier = 28, ParameterPropertyModifier = 16476, NonPublicAccessibilityModifier = 24, - TypeScriptModifier = 116958, - ExportDefault = 513, - All = 257023, - Modifier = 125951 + TypeScriptModifier = 117086, + ExportDefault = 1025, + All = 258047, + Modifier = 126975 } export enum JsxFlags { None = 0, @@ -620,6 +622,7 @@ declare namespace ts { export interface ModifierToken extends KeywordToken { } export type AbstractKeyword = ModifierToken; + export type AccessorKeyword = ModifierToken; export type AsyncKeyword = ModifierToken; export type ConstKeyword = ModifierToken; export type DeclareKeyword = ModifierToken; @@ -635,11 +638,11 @@ declare namespace ts { export type StaticKeyword = ModifierToken; /** @deprecated Use `ReadonlyKeyword` instead. */ export type ReadonlyToken = ReadonlyKeyword; - export type Modifier = AbstractKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | InKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OutKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; + export type Modifier = AbstractKeyword | AccessorKeyword | AsyncKeyword | ConstKeyword | DeclareKeyword | DefaultKeyword | ExportKeyword | InKeyword | PrivateKeyword | ProtectedKeyword | PublicKeyword | OutKeyword | OverrideKeyword | ReadonlyKeyword | StaticKeyword; export type ModifierLike = Modifier | Decorator; export type AccessibilityModifier = PublicKeyword | PrivateKeyword | ProtectedKeyword; export type ParameterPropertyModifier = AccessibilityModifier | ReadonlyKeyword; - export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword; + export type ClassMemberModifier = AccessibilityModifier | ReadonlyKeyword | StaticKeyword | AccessorKeyword; export type ModifiersArray = NodeArray; export enum GeneratedIdentifierFlags { None = 0, @@ -766,6 +769,9 @@ declare namespace ts { readonly type?: TypeNode; readonly initializer?: Expression; } + export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { + _autoAccessorBrand: any; + } export interface ObjectLiteralElement extends NamedDeclaration { _objectLiteralBrand: any; readonly name?: PropertyName; @@ -2570,6 +2576,7 @@ declare namespace ts { MethodExcludes = 103359, GetAccessorExcludes = 46015, SetAccessorExcludes = 78783, + AccessorExcludes = 13247, TypeParameterExcludes = 526824, TypeAliasExcludes = 788968, AliasExcludes = 2097152, @@ -3395,7 +3402,7 @@ declare namespace ts { createNumericLiteral(value: string | number, numericLiteralFlags?: TokenFlags): NumericLiteral; createBigIntLiteral(value: string | PseudoBigInt): BigIntLiteral; createStringLiteral(text: string, isSingleQuote?: boolean): StringLiteral; - createStringLiteralFromNode(sourceNode: PropertyNameLiteral, isSingleQuote?: boolean): StringLiteral; + createStringLiteralFromNode(sourceNode: PropertyNameLiteral | PrivateIdentifier, isSingleQuote?: boolean): StringLiteral; createRegularExpressionLiteral(text: string): RegularExpressionLiteral; createIdentifier(text: string): Identifier; /** @@ -3420,6 +3427,8 @@ declare namespace ts { /** Create a unique name generated for a node. */ getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier; createPrivateIdentifier(text: string): PrivateIdentifier; + createUniquePrivateName(text?: string): PrivateIdentifier; + getGeneratedPrivateNameForNode(node: Node): PrivateIdentifier; createToken(token: SyntaxKind.SuperKeyword): SuperExpression; createToken(token: SyntaxKind.ThisKeyword): ThisExpression; createToken(token: SyntaxKind.NullKeyword): NullLiteral; @@ -3958,7 +3967,7 @@ declare namespace ts { (nodes: NodeArray, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray; (nodes: NodeArray | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray | undefined; } - export type VisitResult = T | T[] | undefined; + export type VisitResult = T | readonly T[] | undefined; export interface Printer { /** * Print a node and its subtree as-is, without any emit transformations. @@ -4525,6 +4534,7 @@ declare namespace ts { function isClassElement(node: Node): node is ClassElement; function isClassLike(node: Node): node is ClassLikeDeclaration; function isAccessor(node: Node): node is AccessorDeclaration; + function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration; function isModifierLike(node: Node): node is ModifierLike; function isTypeElement(node: Node): node is TypeElement; function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement; @@ -6750,6 +6760,8 @@ declare namespace ts { * interface Y { foo:number; } */ memberVariableElement = "property", + /** class X { [public|private]* accessor foo: number; } */ + memberAccessorVariableElement = "accessor", /** * class X { constructor() { } } * class X { static { } } @@ -7029,7 +7041,7 @@ declare namespace ts { (text: string, isSingleQuote?: boolean | undefined, hasExtendedUnicodeEscape?: boolean | undefined): StringLiteral; }; /** @deprecated Use `factory.createStringLiteralFromNode` or the factory supplied by your transformation context instead. */ - const createStringLiteralFromNode: (sourceNode: PropertyNameLiteral, isSingleQuote?: boolean | undefined) => StringLiteral; + const createStringLiteralFromNode: (sourceNode: PrivateIdentifier | PropertyNameLiteral, isSingleQuote?: boolean | undefined) => StringLiteral; /** @deprecated Use `factory.createRegularExpressionLiteral` or the factory supplied by your transformation context instead. */ const createRegularExpressionLiteral: (text: string) => RegularExpressionLiteral; /** @deprecated Use `factory.createLoopVariable` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/autoAccessor1(target=es2015).js b/tests/baselines/reference/autoAccessor1(target=es2015).js new file mode 100644 index 0000000000000..5749b5605673f --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es2015).js @@ -0,0 +1,39 @@ +//// [autoAccessor1.ts] +class C1 { + accessor a: any; + accessor b = 1; + static accessor c: any; + static accessor d = 2; +} + + +//// [autoAccessor1.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 __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, _C1_a_accessor_storage, _C1_b_accessor_storage, _C1_c_accessor_storage, _C1_d_accessor_storage; +class C1 { + constructor() { + _C1_a_accessor_storage.set(this, void 0); + _C1_b_accessor_storage.set(this, 1); + } + get a() { return __classPrivateFieldGet(this, _C1_a_accessor_storage, "f"); } + set a(value) { __classPrivateFieldSet(this, _C1_a_accessor_storage, value, "f"); } + get b() { return __classPrivateFieldGet(this, _C1_b_accessor_storage, "f"); } + set b(value) { __classPrivateFieldSet(this, _C1_b_accessor_storage, value, "f"); } + static get c() { return __classPrivateFieldGet(this, _a, "f", _C1_c_accessor_storage); } + static set c(value) { __classPrivateFieldSet(this, _a, value, "f", _C1_c_accessor_storage); } + static get d() { return __classPrivateFieldGet(this, _a, "f", _C1_d_accessor_storage); } + static set d(value) { __classPrivateFieldSet(this, _a, value, "f", _C1_d_accessor_storage); } +} +_a = C1, _C1_a_accessor_storage = new WeakMap(), _C1_b_accessor_storage = new WeakMap(); +_C1_c_accessor_storage = { value: void 0 }; +_C1_d_accessor_storage = { value: 2 }; diff --git a/tests/baselines/reference/autoAccessor1(target=es2015).symbols b/tests/baselines/reference/autoAccessor1(target=es2015).symbols new file mode 100644 index 0000000000000..cc534d5d543f9 --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es2015).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor1.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor1.ts, 0, 10)) + + accessor b = 1; +>b : Symbol(C1.b, Decl(autoAccessor1.ts, 1, 20)) + + static accessor c: any; +>c : Symbol(C1.c, Decl(autoAccessor1.ts, 2, 19)) + + static accessor d = 2; +>d : Symbol(C1.d, Decl(autoAccessor1.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor1(target=es2015).types b/tests/baselines/reference/autoAccessor1(target=es2015).types new file mode 100644 index 0000000000000..2f31df539b8fa --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es2015).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any + + accessor b = 1; +>b : number +>1 : 1 + + static accessor c: any; +>c : any + + static accessor d = 2; +>d : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor1(target=es2022).js b/tests/baselines/reference/autoAccessor1(target=es2022).js new file mode 100644 index 0000000000000..4b93d2f205dae --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es2022).js @@ -0,0 +1,24 @@ +//// [autoAccessor1.ts] +class C1 { + accessor a: any; + accessor b = 1; + static accessor c: any; + static accessor d = 2; +} + + +//// [autoAccessor1.js] +class C1 { + #a_accessor_storage; + get a() { return this.#a_accessor_storage; } + set a(value) { this.#a_accessor_storage = value; } + #b_accessor_storage = 1; + get b() { return this.#b_accessor_storage; } + set b(value) { this.#b_accessor_storage = value; } + static #c_accessor_storage; + static get c() { return this.#c_accessor_storage; } + static set c(value) { this.#c_accessor_storage = value; } + static #d_accessor_storage = 2; + static get d() { return this.#d_accessor_storage; } + static set d(value) { this.#d_accessor_storage = value; } +} diff --git a/tests/baselines/reference/autoAccessor1(target=es2022).symbols b/tests/baselines/reference/autoAccessor1(target=es2022).symbols new file mode 100644 index 0000000000000..cc534d5d543f9 --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es2022).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor1.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor1.ts, 0, 10)) + + accessor b = 1; +>b : Symbol(C1.b, Decl(autoAccessor1.ts, 1, 20)) + + static accessor c: any; +>c : Symbol(C1.c, Decl(autoAccessor1.ts, 2, 19)) + + static accessor d = 2; +>d : Symbol(C1.d, Decl(autoAccessor1.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor1(target=es2022).types b/tests/baselines/reference/autoAccessor1(target=es2022).types new file mode 100644 index 0000000000000..2f31df539b8fa --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es2022).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any + + accessor b = 1; +>b : number +>1 : 1 + + static accessor c: any; +>c : any + + static accessor d = 2; +>d : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor1(target=es5).errors.txt b/tests/baselines/reference/autoAccessor1(target=es5).errors.txt new file mode 100644 index 0000000000000..aa03e0e14d00c --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es5).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts(2,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts(3,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts(4,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts(5,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts (4 errors) ==== + class C1 { + accessor a: any; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + accessor b = 1; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor c: any; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor d = 2; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor1(target=es5).symbols b/tests/baselines/reference/autoAccessor1(target=es5).symbols new file mode 100644 index 0000000000000..cc534d5d543f9 --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es5).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor1.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor1.ts, 0, 10)) + + accessor b = 1; +>b : Symbol(C1.b, Decl(autoAccessor1.ts, 1, 20)) + + static accessor c: any; +>c : Symbol(C1.c, Decl(autoAccessor1.ts, 2, 19)) + + static accessor d = 2; +>d : Symbol(C1.d, Decl(autoAccessor1.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor1(target=es5).types b/tests/baselines/reference/autoAccessor1(target=es5).types new file mode 100644 index 0000000000000..2f31df539b8fa --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=es5).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any + + accessor b = 1; +>b : number +>1 : 1 + + static accessor c: any; +>c : any + + static accessor d = 2; +>d : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor1(target=esnext).js b/tests/baselines/reference/autoAccessor1(target=esnext).js new file mode 100644 index 0000000000000..312758e2aa9f9 --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=esnext).js @@ -0,0 +1,16 @@ +//// [autoAccessor1.ts] +class C1 { + accessor a: any; + accessor b = 1; + static accessor c: any; + static accessor d = 2; +} + + +//// [autoAccessor1.js] +class C1 { + accessor a; + accessor b = 1; + static accessor c; + static accessor d = 2; +} diff --git a/tests/baselines/reference/autoAccessor1(target=esnext).symbols b/tests/baselines/reference/autoAccessor1(target=esnext).symbols new file mode 100644 index 0000000000000..cc534d5d543f9 --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=esnext).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor1.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor1.ts, 0, 10)) + + accessor b = 1; +>b : Symbol(C1.b, Decl(autoAccessor1.ts, 1, 20)) + + static accessor c: any; +>c : Symbol(C1.c, Decl(autoAccessor1.ts, 2, 19)) + + static accessor d = 2; +>d : Symbol(C1.d, Decl(autoAccessor1.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor1(target=esnext).types b/tests/baselines/reference/autoAccessor1(target=esnext).types new file mode 100644 index 0000000000000..2f31df539b8fa --- /dev/null +++ b/tests/baselines/reference/autoAccessor1(target=esnext).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any + + accessor b = 1; +>b : number +>1 : 1 + + static accessor c: any; +>c : any + + static accessor d = 2; +>d : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor2(target=es2015).js b/tests/baselines/reference/autoAccessor2(target=es2015).js new file mode 100644 index 0000000000000..7b4cb28008e9e --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=es2015).js @@ -0,0 +1,48 @@ +//// [autoAccessor2.ts] +class C1 { + accessor #a: any; + accessor #b = 1; + static accessor #c: any; + static accessor #d = 2; + + constructor() { + this.#a = 3; + this.#b = 4; + } + + static { + this.#c = 5; + this.#d = 6; + } +} + + +//// [autoAccessor2.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 __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 _C1_instances, _a, _C1_a_get, _C1_a_set, _C1_b_get, _C1_b_set, _C1_c_get, _C1_c_set, _C1_d_get, _C1_d_set, _C1_a_accessor_storage, _C1_b_accessor_storage, _C1_c_accessor_storage, _C1_d_accessor_storage; +class C1 { + constructor() { + _C1_instances.add(this); + _C1_a_accessor_storage.set(this, void 0); + _C1_b_accessor_storage.set(this, 1); + __classPrivateFieldSet(this, _C1_instances, 3, "a", _C1_a_set); + __classPrivateFieldSet(this, _C1_instances, 4, "a", _C1_b_set); + } +} +_a = C1, _C1_instances = new WeakSet(), _C1_a_accessor_storage = new WeakMap(), _C1_b_accessor_storage = new WeakMap(), _C1_a_get = function _C1_a_get() { return __classPrivateFieldGet(this, _C1_a_accessor_storage, "f"); }, _C1_a_set = function _C1_a_set(value) { __classPrivateFieldSet(this, _C1_a_accessor_storage, value, "f"); }, _C1_b_get = function _C1_b_get() { return __classPrivateFieldGet(this, _C1_b_accessor_storage, "f"); }, _C1_b_set = function _C1_b_set(value) { __classPrivateFieldSet(this, _C1_b_accessor_storage, value, "f"); }, _C1_c_get = function _C1_c_get() { return __classPrivateFieldGet(this, _a, "f", _C1_c_accessor_storage); }, _C1_c_set = function _C1_c_set(value) { __classPrivateFieldSet(this, _a, value, "f", _C1_c_accessor_storage); }, _C1_d_get = function _C1_d_get() { return __classPrivateFieldGet(this, _a, "f", _C1_d_accessor_storage); }, _C1_d_set = function _C1_d_set(value) { __classPrivateFieldSet(this, _a, value, "f", _C1_d_accessor_storage); }; +_C1_c_accessor_storage = { value: void 0 }; +_C1_d_accessor_storage = { value: 2 }; +(() => { + __classPrivateFieldSet(_a, _a, 5, "a", _C1_c_set); + __classPrivateFieldSet(_a, _a, 6, "a", _C1_d_set); +})(); diff --git a/tests/baselines/reference/autoAccessor2(target=es2015).symbols b/tests/baselines/reference/autoAccessor2(target=es2015).symbols new file mode 100644 index 0000000000000..24e0c62880c3c --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=es2015).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + accessor #a: any; +>#a : Symbol(C1.#a, Decl(autoAccessor2.ts, 0, 10)) + + accessor #b = 1; +>#b : Symbol(C1.#b, Decl(autoAccessor2.ts, 1, 21)) + + static accessor #c: any; +>#c : Symbol(C1.#c, Decl(autoAccessor2.ts, 2, 20)) + + static accessor #d = 2; +>#d : Symbol(C1.#d, Decl(autoAccessor2.ts, 3, 28)) + + constructor() { + this.#a = 3; +>this.#a : Symbol(C1.#a, Decl(autoAccessor2.ts, 0, 10)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + this.#b = 4; +>this.#b : Symbol(C1.#b, Decl(autoAccessor2.ts, 1, 21)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + } + + static { + this.#c = 5; +>this.#c : Symbol(C1.#c, Decl(autoAccessor2.ts, 2, 20)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + this.#d = 6; +>this.#d : Symbol(C1.#d, Decl(autoAccessor2.ts, 3, 28)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/autoAccessor2(target=es2015).types b/tests/baselines/reference/autoAccessor2(target=es2015).types new file mode 100644 index 0000000000000..0bff019ef3707 --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=es2015).types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts === +class C1 { +>C1 : C1 + + accessor #a: any; +>#a : any + + accessor #b = 1; +>#b : number +>1 : 1 + + static accessor #c: any; +>#c : any + + static accessor #d = 2; +>#d : number +>2 : 2 + + constructor() { + this.#a = 3; +>this.#a = 3 : 3 +>this.#a : any +>this : this +>3 : 3 + + this.#b = 4; +>this.#b = 4 : 4 +>this.#b : number +>this : this +>4 : 4 + } + + static { + this.#c = 5; +>this.#c = 5 : 5 +>this.#c : any +>this : typeof C1 +>5 : 5 + + this.#d = 6; +>this.#d = 6 : 6 +>this.#d : number +>this : typeof C1 +>6 : 6 + } +} + diff --git a/tests/baselines/reference/autoAccessor2(target=es2022).js b/tests/baselines/reference/autoAccessor2(target=es2022).js new file mode 100644 index 0000000000000..7c847b3334ac9 --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=es2022).js @@ -0,0 +1,42 @@ +//// [autoAccessor2.ts] +class C1 { + accessor #a: any; + accessor #b = 1; + static accessor #c: any; + static accessor #d = 2; + + constructor() { + this.#a = 3; + this.#b = 4; + } + + static { + this.#c = 5; + this.#d = 6; + } +} + + +//// [autoAccessor2.js] +class C1 { + #a_accessor_storage; + get #a() { return this.#a_accessor_storage; } + set #a(value) { this.#a_accessor_storage = value; } + #b_accessor_storage = 1; + get #b() { return this.#b_accessor_storage; } + set #b(value) { this.#b_accessor_storage = value; } + static #c_accessor_storage; + static get #c() { return this.#c_accessor_storage; } + static set #c(value) { this.#c_accessor_storage = value; } + static #d_accessor_storage = 2; + static get #d() { return this.#d_accessor_storage; } + static set #d(value) { this.#d_accessor_storage = value; } + constructor() { + this.#a = 3; + this.#b = 4; + } + static { + this.#c = 5; + this.#d = 6; + } +} diff --git a/tests/baselines/reference/autoAccessor2(target=es2022).symbols b/tests/baselines/reference/autoAccessor2(target=es2022).symbols new file mode 100644 index 0000000000000..24e0c62880c3c --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=es2022).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + accessor #a: any; +>#a : Symbol(C1.#a, Decl(autoAccessor2.ts, 0, 10)) + + accessor #b = 1; +>#b : Symbol(C1.#b, Decl(autoAccessor2.ts, 1, 21)) + + static accessor #c: any; +>#c : Symbol(C1.#c, Decl(autoAccessor2.ts, 2, 20)) + + static accessor #d = 2; +>#d : Symbol(C1.#d, Decl(autoAccessor2.ts, 3, 28)) + + constructor() { + this.#a = 3; +>this.#a : Symbol(C1.#a, Decl(autoAccessor2.ts, 0, 10)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + this.#b = 4; +>this.#b : Symbol(C1.#b, Decl(autoAccessor2.ts, 1, 21)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + } + + static { + this.#c = 5; +>this.#c : Symbol(C1.#c, Decl(autoAccessor2.ts, 2, 20)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + this.#d = 6; +>this.#d : Symbol(C1.#d, Decl(autoAccessor2.ts, 3, 28)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/autoAccessor2(target=es2022).types b/tests/baselines/reference/autoAccessor2(target=es2022).types new file mode 100644 index 0000000000000..0bff019ef3707 --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=es2022).types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts === +class C1 { +>C1 : C1 + + accessor #a: any; +>#a : any + + accessor #b = 1; +>#b : number +>1 : 1 + + static accessor #c: any; +>#c : any + + static accessor #d = 2; +>#d : number +>2 : 2 + + constructor() { + this.#a = 3; +>this.#a = 3 : 3 +>this.#a : any +>this : this +>3 : 3 + + this.#b = 4; +>this.#b = 4 : 4 +>this.#b : number +>this : this +>4 : 4 + } + + static { + this.#c = 5; +>this.#c = 5 : 5 +>this.#c : any +>this : typeof C1 +>5 : 5 + + this.#d = 6; +>this.#d = 6 : 6 +>this.#d : number +>this : typeof C1 +>6 : 6 + } +} + diff --git a/tests/baselines/reference/autoAccessor2(target=esnext).js b/tests/baselines/reference/autoAccessor2(target=esnext).js new file mode 100644 index 0000000000000..f184c001cd366 --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=esnext).js @@ -0,0 +1,34 @@ +//// [autoAccessor2.ts] +class C1 { + accessor #a: any; + accessor #b = 1; + static accessor #c: any; + static accessor #d = 2; + + constructor() { + this.#a = 3; + this.#b = 4; + } + + static { + this.#c = 5; + this.#d = 6; + } +} + + +//// [autoAccessor2.js] +class C1 { + accessor #a; + accessor #b = 1; + static accessor #c; + static accessor #d = 2; + constructor() { + this.#a = 3; + this.#b = 4; + } + static { + this.#c = 5; + this.#d = 6; + } +} diff --git a/tests/baselines/reference/autoAccessor2(target=esnext).symbols b/tests/baselines/reference/autoAccessor2(target=esnext).symbols new file mode 100644 index 0000000000000..24e0c62880c3c --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=esnext).symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + accessor #a: any; +>#a : Symbol(C1.#a, Decl(autoAccessor2.ts, 0, 10)) + + accessor #b = 1; +>#b : Symbol(C1.#b, Decl(autoAccessor2.ts, 1, 21)) + + static accessor #c: any; +>#c : Symbol(C1.#c, Decl(autoAccessor2.ts, 2, 20)) + + static accessor #d = 2; +>#d : Symbol(C1.#d, Decl(autoAccessor2.ts, 3, 28)) + + constructor() { + this.#a = 3; +>this.#a : Symbol(C1.#a, Decl(autoAccessor2.ts, 0, 10)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + this.#b = 4; +>this.#b : Symbol(C1.#b, Decl(autoAccessor2.ts, 1, 21)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + } + + static { + this.#c = 5; +>this.#c : Symbol(C1.#c, Decl(autoAccessor2.ts, 2, 20)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + + this.#d = 6; +>this.#d : Symbol(C1.#d, Decl(autoAccessor2.ts, 3, 28)) +>this : Symbol(C1, Decl(autoAccessor2.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/autoAccessor2(target=esnext).types b/tests/baselines/reference/autoAccessor2(target=esnext).types new file mode 100644 index 0000000000000..0bff019ef3707 --- /dev/null +++ b/tests/baselines/reference/autoAccessor2(target=esnext).types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts === +class C1 { +>C1 : C1 + + accessor #a: any; +>#a : any + + accessor #b = 1; +>#b : number +>1 : 1 + + static accessor #c: any; +>#c : any + + static accessor #d = 2; +>#d : number +>2 : 2 + + constructor() { + this.#a = 3; +>this.#a = 3 : 3 +>this.#a : any +>this : this +>3 : 3 + + this.#b = 4; +>this.#b = 4 : 4 +>this.#b : number +>this : this +>4 : 4 + } + + static { + this.#c = 5; +>this.#c = 5 : 5 +>this.#c : any +>this : typeof C1 +>5 : 5 + + this.#d = 6; +>this.#d = 6 : 6 +>this.#d : number +>this : typeof C1 +>6 : 6 + } +} + diff --git a/tests/baselines/reference/autoAccessor3(target=es2015).js b/tests/baselines/reference/autoAccessor3(target=es2015).js new file mode 100644 index 0000000000000..c2bebd8dc6109 --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es2015).js @@ -0,0 +1,39 @@ +//// [autoAccessor3.ts] +class C1 { + accessor "w": any; + accessor "x" = 1; + static accessor "y": any; + static accessor "z" = 2; +} + + +//// [autoAccessor3.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 __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, _C1__a_accessor_storage, _C1__b_accessor_storage, _C1__c_accessor_storage, _C1__d_accessor_storage; +class C1 { + constructor() { + _C1__a_accessor_storage.set(this, void 0); + _C1__b_accessor_storage.set(this, 1); + } + get "w"() { return __classPrivateFieldGet(this, _C1__a_accessor_storage, "f"); } + set "w"(value) { __classPrivateFieldSet(this, _C1__a_accessor_storage, value, "f"); } + get "x"() { return __classPrivateFieldGet(this, _C1__b_accessor_storage, "f"); } + set "x"(value) { __classPrivateFieldSet(this, _C1__b_accessor_storage, value, "f"); } + static get "y"() { return __classPrivateFieldGet(this, _a, "f", _C1__c_accessor_storage); } + static set "y"(value) { __classPrivateFieldSet(this, _a, value, "f", _C1__c_accessor_storage); } + static get "z"() { return __classPrivateFieldGet(this, _a, "f", _C1__d_accessor_storage); } + static set "z"(value) { __classPrivateFieldSet(this, _a, value, "f", _C1__d_accessor_storage); } +} +_a = C1, _C1__a_accessor_storage = new WeakMap(), _C1__b_accessor_storage = new WeakMap(); +_C1__c_accessor_storage = { value: void 0 }; +_C1__d_accessor_storage = { value: 2 }; diff --git a/tests/baselines/reference/autoAccessor3(target=es2015).symbols b/tests/baselines/reference/autoAccessor3(target=es2015).symbols new file mode 100644 index 0000000000000..9cf05f23a9e4d --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es2015).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor3.ts, 0, 0)) + + accessor "w": any; +>"w" : Symbol(C1["w"], Decl(autoAccessor3.ts, 0, 10)) + + accessor "x" = 1; +>"x" : Symbol(C1["x"], Decl(autoAccessor3.ts, 1, 22)) + + static accessor "y": any; +>"y" : Symbol(C1["y"], Decl(autoAccessor3.ts, 2, 21)) + + static accessor "z" = 2; +>"z" : Symbol(C1["z"], Decl(autoAccessor3.ts, 3, 29)) +} + diff --git a/tests/baselines/reference/autoAccessor3(target=es2015).types b/tests/baselines/reference/autoAccessor3(target=es2015).types new file mode 100644 index 0000000000000..dec77973d0cd6 --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es2015).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : C1 + + accessor "w": any; +>"w" : any + + accessor "x" = 1; +>"x" : number +>1 : 1 + + static accessor "y": any; +>"y" : any + + static accessor "z" = 2; +>"z" : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor3(target=es2022).js b/tests/baselines/reference/autoAccessor3(target=es2022).js new file mode 100644 index 0000000000000..20453ef464fba --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es2022).js @@ -0,0 +1,24 @@ +//// [autoAccessor3.ts] +class C1 { + accessor "w": any; + accessor "x" = 1; + static accessor "y": any; + static accessor "z" = 2; +} + + +//// [autoAccessor3.js] +class C1 { + #_a_accessor_storage; + get "w"() { return this.#_a_accessor_storage; } + set "w"(value) { this.#_a_accessor_storage = value; } + #_b_accessor_storage = 1; + get "x"() { return this.#_b_accessor_storage; } + set "x"(value) { this.#_b_accessor_storage = value; } + static #_c_accessor_storage; + static get "y"() { return this.#_c_accessor_storage; } + static set "y"(value) { this.#_c_accessor_storage = value; } + static #_d_accessor_storage = 2; + static get "z"() { return this.#_d_accessor_storage; } + static set "z"(value) { this.#_d_accessor_storage = value; } +} diff --git a/tests/baselines/reference/autoAccessor3(target=es2022).symbols b/tests/baselines/reference/autoAccessor3(target=es2022).symbols new file mode 100644 index 0000000000000..9cf05f23a9e4d --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es2022).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor3.ts, 0, 0)) + + accessor "w": any; +>"w" : Symbol(C1["w"], Decl(autoAccessor3.ts, 0, 10)) + + accessor "x" = 1; +>"x" : Symbol(C1["x"], Decl(autoAccessor3.ts, 1, 22)) + + static accessor "y": any; +>"y" : Symbol(C1["y"], Decl(autoAccessor3.ts, 2, 21)) + + static accessor "z" = 2; +>"z" : Symbol(C1["z"], Decl(autoAccessor3.ts, 3, 29)) +} + diff --git a/tests/baselines/reference/autoAccessor3(target=es2022).types b/tests/baselines/reference/autoAccessor3(target=es2022).types new file mode 100644 index 0000000000000..dec77973d0cd6 --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es2022).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : C1 + + accessor "w": any; +>"w" : any + + accessor "x" = 1; +>"x" : number +>1 : 1 + + static accessor "y": any; +>"y" : any + + static accessor "z" = 2; +>"z" : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor3(target=es5).errors.txt b/tests/baselines/reference/autoAccessor3(target=es5).errors.txt new file mode 100644 index 0000000000000..deea9cec64f11 --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es5).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts(2,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts(3,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts(4,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts(5,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts (4 errors) ==== + class C1 { + accessor "w": any; + ~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + accessor "x" = 1; + ~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor "y": any; + ~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor "z" = 2; + ~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor3(target=es5).symbols b/tests/baselines/reference/autoAccessor3(target=es5).symbols new file mode 100644 index 0000000000000..9cf05f23a9e4d --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es5).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor3.ts, 0, 0)) + + accessor "w": any; +>"w" : Symbol(C1["w"], Decl(autoAccessor3.ts, 0, 10)) + + accessor "x" = 1; +>"x" : Symbol(C1["x"], Decl(autoAccessor3.ts, 1, 22)) + + static accessor "y": any; +>"y" : Symbol(C1["y"], Decl(autoAccessor3.ts, 2, 21)) + + static accessor "z" = 2; +>"z" : Symbol(C1["z"], Decl(autoAccessor3.ts, 3, 29)) +} + diff --git a/tests/baselines/reference/autoAccessor3(target=es5).types b/tests/baselines/reference/autoAccessor3(target=es5).types new file mode 100644 index 0000000000000..dec77973d0cd6 --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=es5).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : C1 + + accessor "w": any; +>"w" : any + + accessor "x" = 1; +>"x" : number +>1 : 1 + + static accessor "y": any; +>"y" : any + + static accessor "z" = 2; +>"z" : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor3(target=esnext).js b/tests/baselines/reference/autoAccessor3(target=esnext).js new file mode 100644 index 0000000000000..cad23cf54be1e --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=esnext).js @@ -0,0 +1,16 @@ +//// [autoAccessor3.ts] +class C1 { + accessor "w": any; + accessor "x" = 1; + static accessor "y": any; + static accessor "z" = 2; +} + + +//// [autoAccessor3.js] +class C1 { + accessor "w"; + accessor "x" = 1; + static accessor "y"; + static accessor "z" = 2; +} diff --git a/tests/baselines/reference/autoAccessor3(target=esnext).symbols b/tests/baselines/reference/autoAccessor3(target=esnext).symbols new file mode 100644 index 0000000000000..9cf05f23a9e4d --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=esnext).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor3.ts, 0, 0)) + + accessor "w": any; +>"w" : Symbol(C1["w"], Decl(autoAccessor3.ts, 0, 10)) + + accessor "x" = 1; +>"x" : Symbol(C1["x"], Decl(autoAccessor3.ts, 1, 22)) + + static accessor "y": any; +>"y" : Symbol(C1["y"], Decl(autoAccessor3.ts, 2, 21)) + + static accessor "z" = 2; +>"z" : Symbol(C1["z"], Decl(autoAccessor3.ts, 3, 29)) +} + diff --git a/tests/baselines/reference/autoAccessor3(target=esnext).types b/tests/baselines/reference/autoAccessor3(target=esnext).types new file mode 100644 index 0000000000000..dec77973d0cd6 --- /dev/null +++ b/tests/baselines/reference/autoAccessor3(target=esnext).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts === +class C1 { +>C1 : C1 + + accessor "w": any; +>"w" : any + + accessor "x" = 1; +>"x" : number +>1 : 1 + + static accessor "y": any; +>"y" : any + + static accessor "z" = 2; +>"z" : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor4(target=es2015).js b/tests/baselines/reference/autoAccessor4(target=es2015).js new file mode 100644 index 0000000000000..d529342e8d96d --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es2015).js @@ -0,0 +1,39 @@ +//// [autoAccessor4.ts] +class C1 { + accessor 0: any; + accessor 1 = 1; + static accessor 2: any; + static accessor 3 = 2; +} + + +//// [autoAccessor4.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 __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, _C1__a_accessor_storage, _C1__b_accessor_storage, _C1__c_accessor_storage, _C1__d_accessor_storage; +class C1 { + constructor() { + _C1__a_accessor_storage.set(this, void 0); + _C1__b_accessor_storage.set(this, 1); + } + get 0() { return __classPrivateFieldGet(this, _C1__a_accessor_storage, "f"); } + set 0(value) { __classPrivateFieldSet(this, _C1__a_accessor_storage, value, "f"); } + get 1() { return __classPrivateFieldGet(this, _C1__b_accessor_storage, "f"); } + set 1(value) { __classPrivateFieldSet(this, _C1__b_accessor_storage, value, "f"); } + static get 2() { return __classPrivateFieldGet(this, _a, "f", _C1__c_accessor_storage); } + static set 2(value) { __classPrivateFieldSet(this, _a, value, "f", _C1__c_accessor_storage); } + static get 3() { return __classPrivateFieldGet(this, _a, "f", _C1__d_accessor_storage); } + static set 3(value) { __classPrivateFieldSet(this, _a, value, "f", _C1__d_accessor_storage); } +} +_a = C1, _C1__a_accessor_storage = new WeakMap(), _C1__b_accessor_storage = new WeakMap(); +_C1__c_accessor_storage = { value: void 0 }; +_C1__d_accessor_storage = { value: 2 }; diff --git a/tests/baselines/reference/autoAccessor4(target=es2015).symbols b/tests/baselines/reference/autoAccessor4(target=es2015).symbols new file mode 100644 index 0000000000000..8452d711bfc0f --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es2015).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor4.ts, 0, 0)) + + accessor 0: any; +>0 : Symbol(C1[0], Decl(autoAccessor4.ts, 0, 10)) + + accessor 1 = 1; +>1 : Symbol(C1[1], Decl(autoAccessor4.ts, 1, 20)) + + static accessor 2: any; +>2 : Symbol(C1[2], Decl(autoAccessor4.ts, 2, 19)) + + static accessor 3 = 2; +>3 : Symbol(C1[3], Decl(autoAccessor4.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor4(target=es2015).types b/tests/baselines/reference/autoAccessor4(target=es2015).types new file mode 100644 index 0000000000000..d77c24d296b02 --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es2015).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : C1 + + accessor 0: any; +>0 : any + + accessor 1 = 1; +>1 : number +>1 : 1 + + static accessor 2: any; +>2 : any + + static accessor 3 = 2; +>3 : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor4(target=es2022).js b/tests/baselines/reference/autoAccessor4(target=es2022).js new file mode 100644 index 0000000000000..5f5cf868637c6 --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es2022).js @@ -0,0 +1,24 @@ +//// [autoAccessor4.ts] +class C1 { + accessor 0: any; + accessor 1 = 1; + static accessor 2: any; + static accessor 3 = 2; +} + + +//// [autoAccessor4.js] +class C1 { + #_a_accessor_storage; + get 0() { return this.#_a_accessor_storage; } + set 0(value) { this.#_a_accessor_storage = value; } + #_b_accessor_storage = 1; + get 1() { return this.#_b_accessor_storage; } + set 1(value) { this.#_b_accessor_storage = value; } + static #_c_accessor_storage; + static get 2() { return this.#_c_accessor_storage; } + static set 2(value) { this.#_c_accessor_storage = value; } + static #_d_accessor_storage = 2; + static get 3() { return this.#_d_accessor_storage; } + static set 3(value) { this.#_d_accessor_storage = value; } +} diff --git a/tests/baselines/reference/autoAccessor4(target=es2022).symbols b/tests/baselines/reference/autoAccessor4(target=es2022).symbols new file mode 100644 index 0000000000000..8452d711bfc0f --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es2022).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor4.ts, 0, 0)) + + accessor 0: any; +>0 : Symbol(C1[0], Decl(autoAccessor4.ts, 0, 10)) + + accessor 1 = 1; +>1 : Symbol(C1[1], Decl(autoAccessor4.ts, 1, 20)) + + static accessor 2: any; +>2 : Symbol(C1[2], Decl(autoAccessor4.ts, 2, 19)) + + static accessor 3 = 2; +>3 : Symbol(C1[3], Decl(autoAccessor4.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor4(target=es2022).types b/tests/baselines/reference/autoAccessor4(target=es2022).types new file mode 100644 index 0000000000000..d77c24d296b02 --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es2022).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : C1 + + accessor 0: any; +>0 : any + + accessor 1 = 1; +>1 : number +>1 : 1 + + static accessor 2: any; +>2 : any + + static accessor 3 = 2; +>3 : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor4(target=es5).errors.txt b/tests/baselines/reference/autoAccessor4(target=es5).errors.txt new file mode 100644 index 0000000000000..d53f1d01f0131 --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es5).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts(2,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts(3,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts(4,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts(5,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts (4 errors) ==== + class C1 { + accessor 0: any; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + accessor 1 = 1; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor 2: any; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor 3 = 2; + ~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor4(target=es5).symbols b/tests/baselines/reference/autoAccessor4(target=es5).symbols new file mode 100644 index 0000000000000..8452d711bfc0f --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es5).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor4.ts, 0, 0)) + + accessor 0: any; +>0 : Symbol(C1[0], Decl(autoAccessor4.ts, 0, 10)) + + accessor 1 = 1; +>1 : Symbol(C1[1], Decl(autoAccessor4.ts, 1, 20)) + + static accessor 2: any; +>2 : Symbol(C1[2], Decl(autoAccessor4.ts, 2, 19)) + + static accessor 3 = 2; +>3 : Symbol(C1[3], Decl(autoAccessor4.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor4(target=es5).types b/tests/baselines/reference/autoAccessor4(target=es5).types new file mode 100644 index 0000000000000..d77c24d296b02 --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=es5).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : C1 + + accessor 0: any; +>0 : any + + accessor 1 = 1; +>1 : number +>1 : 1 + + static accessor 2: any; +>2 : any + + static accessor 3 = 2; +>3 : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor4(target=esnext).js b/tests/baselines/reference/autoAccessor4(target=esnext).js new file mode 100644 index 0000000000000..431d6dee3ef5a --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=esnext).js @@ -0,0 +1,16 @@ +//// [autoAccessor4.ts] +class C1 { + accessor 0: any; + accessor 1 = 1; + static accessor 2: any; + static accessor 3 = 2; +} + + +//// [autoAccessor4.js] +class C1 { + accessor 0; + accessor 1 = 1; + static accessor 2; + static accessor 3 = 2; +} diff --git a/tests/baselines/reference/autoAccessor4(target=esnext).symbols b/tests/baselines/reference/autoAccessor4(target=esnext).symbols new file mode 100644 index 0000000000000..8452d711bfc0f --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=esnext).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor4.ts, 0, 0)) + + accessor 0: any; +>0 : Symbol(C1[0], Decl(autoAccessor4.ts, 0, 10)) + + accessor 1 = 1; +>1 : Symbol(C1[1], Decl(autoAccessor4.ts, 1, 20)) + + static accessor 2: any; +>2 : Symbol(C1[2], Decl(autoAccessor4.ts, 2, 19)) + + static accessor 3 = 2; +>3 : Symbol(C1[3], Decl(autoAccessor4.ts, 3, 27)) +} + diff --git a/tests/baselines/reference/autoAccessor4(target=esnext).types b/tests/baselines/reference/autoAccessor4(target=esnext).types new file mode 100644 index 0000000000000..d77c24d296b02 --- /dev/null +++ b/tests/baselines/reference/autoAccessor4(target=esnext).types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts === +class C1 { +>C1 : C1 + + accessor 0: any; +>0 : any + + accessor 1 = 1; +>1 : number +>1 : 1 + + static accessor 2: any; +>2 : any + + static accessor 3 = 2; +>3 : number +>2 : 2 +} + diff --git a/tests/baselines/reference/autoAccessor5(target=es2015).errors.txt b/tests/baselines/reference/autoAccessor5(target=es2015).errors.txt new file mode 100644 index 0000000000000..453fd4b6f7fe1 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2015).errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(10,14): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts (1 errors) ==== + class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; + } + + declare var f: any; + class C2 { + accessor [f()] = 1; + ~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + } \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor5(target=es2015).js b/tests/baselines/reference/autoAccessor5(target=es2015).js new file mode 100644 index 0000000000000..a7394e4d18c8a --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2015).js @@ -0,0 +1,50 @@ +//// [autoAccessor5.ts] +class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; +} + +declare var f: any; +class C2 { + accessor [f()] = 1; +} + +//// [autoAccessor5.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 __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, _C1__a_accessor_storage, _C1__b_accessor_storage, _C1__c_accessor_storage, _C1__d_accessor_storage, _C2__e_accessor_storage, _b; +class C1 { + constructor() { + _C1__a_accessor_storage.set(this, void 0); + _C1__b_accessor_storage.set(this, 1); + } + get [(_C1__a_accessor_storage = new WeakMap(), _C1__b_accessor_storage = new WeakMap(), "w")]() { return __classPrivateFieldGet(this, _C1__a_accessor_storage, "f"); } + set ["w"](value) { __classPrivateFieldSet(this, _C1__a_accessor_storage, value, "f"); } + get ["x"]() { return __classPrivateFieldGet(this, _C1__b_accessor_storage, "f"); } + set ["x"](value) { __classPrivateFieldSet(this, _C1__b_accessor_storage, value, "f"); } + static get ["y"]() { return __classPrivateFieldGet(this, _a, "f", _C1__c_accessor_storage); } + static set ["y"](value) { __classPrivateFieldSet(this, _a, value, "f", _C1__c_accessor_storage); } + static get ["z"]() { return __classPrivateFieldGet(this, _a, "f", _C1__d_accessor_storage); } + static set ["z"](value) { __classPrivateFieldSet(this, _a, value, "f", _C1__d_accessor_storage); } +} +_a = C1; +_C1__c_accessor_storage = { value: void 0 }; +_C1__d_accessor_storage = { value: 2 }; +class C2 { + constructor() { + _C2__e_accessor_storage.set(this, 1); + } + get [(_C2__e_accessor_storage = new WeakMap(), _b = f(), _b)]() { return __classPrivateFieldGet(this, _C2__e_accessor_storage, "f"); } + set [_b](value) { __classPrivateFieldSet(this, _C2__e_accessor_storage, value, "f"); } +} diff --git a/tests/baselines/reference/autoAccessor5(target=es2015).symbols b/tests/baselines/reference/autoAccessor5(target=es2015).symbols new file mode 100644 index 0000000000000..71d59a6ef2281 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2015).symbols @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor5.ts, 0, 0)) + + accessor ["w"]: any; +>["w"] : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) +>"w" : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) + + accessor ["x"] = 1; +>["x"] : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) +>"x" : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) + + static accessor ["y"]: any; +>["y"] : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) +>"y" : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) + + static accessor ["z"] = 2; +>["z"] : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +>"z" : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +} + +declare var f: any; +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessor5.ts, 7, 19)) + + accessor [f()] = 1; +>[f()] : Symbol(C2[f()], Decl(autoAccessor5.ts, 8, 10)) +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) +} diff --git a/tests/baselines/reference/autoAccessor5(target=es2015).types b/tests/baselines/reference/autoAccessor5(target=es2015).types new file mode 100644 index 0000000000000..48b48c552dcf4 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2015).types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : C1 + + accessor ["w"]: any; +>["w"] : any +>"w" : "w" + + accessor ["x"] = 1; +>["x"] : number +>"x" : "x" +>1 : 1 + + static accessor ["y"]: any; +>["y"] : any +>"y" : "y" + + static accessor ["z"] = 2; +>["z"] : number +>"z" : "z" +>2 : 2 +} + +declare var f: any; +>f : any + +class C2 { +>C2 : C2 + + accessor [f()] = 1; +>[f()] : number +>f() : any +>f : any +>1 : 1 +} diff --git a/tests/baselines/reference/autoAccessor5(target=es2022).errors.txt b/tests/baselines/reference/autoAccessor5(target=es2022).errors.txt new file mode 100644 index 0000000000000..453fd4b6f7fe1 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2022).errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(10,14): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts (1 errors) ==== + class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; + } + + declare var f: any; + class C2 { + accessor [f()] = 1; + ~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + } \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor5(target=es2022).js b/tests/baselines/reference/autoAccessor5(target=es2022).js new file mode 100644 index 0000000000000..f5022161cea00 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2022).js @@ -0,0 +1,34 @@ +//// [autoAccessor5.ts] +class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; +} + +declare var f: any; +class C2 { + accessor [f()] = 1; +} + +//// [autoAccessor5.js] +var _a; +class C1 { + #_a_accessor_storage; + get ["w"]() { return this.#_a_accessor_storage; } + set ["w"](value) { this.#_a_accessor_storage = value; } + #_b_accessor_storage = 1; + get ["x"]() { return this.#_b_accessor_storage; } + set ["x"](value) { this.#_b_accessor_storage = value; } + static #_c_accessor_storage; + static get ["y"]() { return this.#_c_accessor_storage; } + static set ["y"](value) { this.#_c_accessor_storage = value; } + static #_d_accessor_storage = 2; + static get ["z"]() { return this.#_d_accessor_storage; } + static set ["z"](value) { this.#_d_accessor_storage = value; } +} +class C2 { + #_e_accessor_storage = 1; + get [(_a = f(), _a)]() { return this.#_e_accessor_storage; } + set [_a](value) { this.#_e_accessor_storage = value; } +} diff --git a/tests/baselines/reference/autoAccessor5(target=es2022).symbols b/tests/baselines/reference/autoAccessor5(target=es2022).symbols new file mode 100644 index 0000000000000..71d59a6ef2281 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2022).symbols @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor5.ts, 0, 0)) + + accessor ["w"]: any; +>["w"] : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) +>"w" : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) + + accessor ["x"] = 1; +>["x"] : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) +>"x" : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) + + static accessor ["y"]: any; +>["y"] : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) +>"y" : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) + + static accessor ["z"] = 2; +>["z"] : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +>"z" : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +} + +declare var f: any; +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessor5.ts, 7, 19)) + + accessor [f()] = 1; +>[f()] : Symbol(C2[f()], Decl(autoAccessor5.ts, 8, 10)) +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) +} diff --git a/tests/baselines/reference/autoAccessor5(target=es2022).types b/tests/baselines/reference/autoAccessor5(target=es2022).types new file mode 100644 index 0000000000000..48b48c552dcf4 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es2022).types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : C1 + + accessor ["w"]: any; +>["w"] : any +>"w" : "w" + + accessor ["x"] = 1; +>["x"] : number +>"x" : "x" +>1 : 1 + + static accessor ["y"]: any; +>["y"] : any +>"y" : "y" + + static accessor ["z"] = 2; +>["z"] : number +>"z" : "z" +>2 : 2 +} + +declare var f: any; +>f : any + +class C2 { +>C2 : C2 + + accessor [f()] = 1; +>[f()] : number +>f() : any +>f : any +>1 : 1 +} diff --git a/tests/baselines/reference/autoAccessor5(target=es5).errors.txt b/tests/baselines/reference/autoAccessor5(target=es5).errors.txt new file mode 100644 index 0000000000000..a2290861f4db0 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es5).errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(2,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(3,14): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(4,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(5,21): error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(10,14): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts (5 errors) ==== + class C1 { + accessor ["w"]: any; + ~~~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + accessor ["x"] = 1; + ~~~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor ["y"]: any; + ~~~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + static accessor ["z"] = 2; + ~~~~~ +!!! error TS18045: Properties with the 'accessor' modifier are only available when targeting ECMAScript 2015 and higher. + } + + declare var f: any; + class C2 { + accessor [f()] = 1; + ~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + } \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor5(target=es5).js b/tests/baselines/reference/autoAccessor5(target=es5).js new file mode 100644 index 0000000000000..093dceb5fbd26 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es5).js @@ -0,0 +1,81 @@ +//// [autoAccessor5.ts] +class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; +} + +declare var f: any; +class C2 { + accessor [f()] = 1; +} + +//// [autoAccessor5.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 __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 _C2__a_accessor_storage, _a; +var C1 = /** @class */ (function () { + function C1() { + _C1__b_accessor_storage.set(this, void 0); + _C1__c_accessor_storage.set(this, 1); + } + Object.defineProperty(C1.prototype, (_C1__b_accessor_storage = new WeakMap(), _C1__c_accessor_storage = new WeakMap(), "w"), { + get: function () { return __classPrivateFieldGet(this, _C1__b_accessor_storage, "f"); }, + enumerable: false, + configurable: true + }); + Object.defineProperty(C1.prototype, "w", { + set: function (value) { __classPrivateFieldSet(this, _C1__b_accessor_storage, value, "f"); }, + enumerable: false, + configurable: true + }); + Object.defineProperty(C1.prototype, "x", { + get: function () { return __classPrivateFieldGet(this, _C1__c_accessor_storage, "f"); }, + set: function (value) { __classPrivateFieldSet(this, _C1__c_accessor_storage, value, "f"); }, + enumerable: false, + configurable: true + }); + Object.defineProperty(C1, "y", { + get: function () { return __classPrivateFieldGet(this, _b, "f", _C1__d_accessor_storage); }, + set: function (value) { __classPrivateFieldSet(this, _b, value, "f", _C1__d_accessor_storage); }, + enumerable: false, + configurable: true + }); + Object.defineProperty(C1, "z", { + get: function () { return __classPrivateFieldGet(this, _b, "f", _C1__e_accessor_storage); }, + set: function (value) { __classPrivateFieldSet(this, _b, value, "f", _C1__e_accessor_storage); }, + enumerable: false, + configurable: true + }); + var _b, _C1__b_accessor_storage, _C1__c_accessor_storage, _C1__d_accessor_storage, _C1__e_accessor_storage; + _b = C1; + _C1__d_accessor_storage = { value: void 0 }; + _C1__e_accessor_storage = { value: 2 }; + return C1; +}()); +var C2 = /** @class */ (function () { + function C2() { + _C2__a_accessor_storage.set(this, 1); + } + Object.defineProperty(C2.prototype, (_C2__a_accessor_storage = new WeakMap(), _a = f(), _a), { + get: function () { return __classPrivateFieldGet(this, _C2__a_accessor_storage, "f"); }, + enumerable: false, + configurable: true + }); + Object.defineProperty(C2.prototype, _a, { + set: function (value) { __classPrivateFieldSet(this, _C2__a_accessor_storage, value, "f"); }, + enumerable: false, + configurable: true + }); + return C2; +}()); diff --git a/tests/baselines/reference/autoAccessor5(target=es5).symbols b/tests/baselines/reference/autoAccessor5(target=es5).symbols new file mode 100644 index 0000000000000..71d59a6ef2281 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es5).symbols @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor5.ts, 0, 0)) + + accessor ["w"]: any; +>["w"] : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) +>"w" : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) + + accessor ["x"] = 1; +>["x"] : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) +>"x" : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) + + static accessor ["y"]: any; +>["y"] : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) +>"y" : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) + + static accessor ["z"] = 2; +>["z"] : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +>"z" : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +} + +declare var f: any; +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessor5.ts, 7, 19)) + + accessor [f()] = 1; +>[f()] : Symbol(C2[f()], Decl(autoAccessor5.ts, 8, 10)) +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) +} diff --git a/tests/baselines/reference/autoAccessor5(target=es5).types b/tests/baselines/reference/autoAccessor5(target=es5).types new file mode 100644 index 0000000000000..48b48c552dcf4 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=es5).types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : C1 + + accessor ["w"]: any; +>["w"] : any +>"w" : "w" + + accessor ["x"] = 1; +>["x"] : number +>"x" : "x" +>1 : 1 + + static accessor ["y"]: any; +>["y"] : any +>"y" : "y" + + static accessor ["z"] = 2; +>["z"] : number +>"z" : "z" +>2 : 2 +} + +declare var f: any; +>f : any + +class C2 { +>C2 : C2 + + accessor [f()] = 1; +>[f()] : number +>f() : any +>f : any +>1 : 1 +} diff --git a/tests/baselines/reference/autoAccessor5(target=esnext).errors.txt b/tests/baselines/reference/autoAccessor5(target=esnext).errors.txt new file mode 100644 index 0000000000000..453fd4b6f7fe1 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=esnext).errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts(10,14): error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts (1 errors) ==== + class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; + } + + declare var f: any; + class C2 { + accessor [f()] = 1; + ~~~~~ +!!! error TS1166: A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. + } \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor5(target=esnext).js b/tests/baselines/reference/autoAccessor5(target=esnext).js new file mode 100644 index 0000000000000..d7620567c7b76 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=esnext).js @@ -0,0 +1,23 @@ +//// [autoAccessor5.ts] +class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; +} + +declare var f: any; +class C2 { + accessor [f()] = 1; +} + +//// [autoAccessor5.js] +class C1 { + accessor ["w"]; + accessor ["x"] = 1; + static accessor ["y"]; + static accessor ["z"] = 2; +} +class C2 { + accessor [f()] = 1; +} diff --git a/tests/baselines/reference/autoAccessor5(target=esnext).symbols b/tests/baselines/reference/autoAccessor5(target=esnext).symbols new file mode 100644 index 0000000000000..71d59a6ef2281 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=esnext).symbols @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor5.ts, 0, 0)) + + accessor ["w"]: any; +>["w"] : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) +>"w" : Symbol(C1["w"], Decl(autoAccessor5.ts, 0, 10)) + + accessor ["x"] = 1; +>["x"] : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) +>"x" : Symbol(C1["x"], Decl(autoAccessor5.ts, 1, 24)) + + static accessor ["y"]: any; +>["y"] : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) +>"y" : Symbol(C1["y"], Decl(autoAccessor5.ts, 2, 23)) + + static accessor ["z"] = 2; +>["z"] : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +>"z" : Symbol(C1["z"], Decl(autoAccessor5.ts, 3, 31)) +} + +declare var f: any; +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessor5.ts, 7, 19)) + + accessor [f()] = 1; +>[f()] : Symbol(C2[f()], Decl(autoAccessor5.ts, 8, 10)) +>f : Symbol(f, Decl(autoAccessor5.ts, 7, 11)) +} diff --git a/tests/baselines/reference/autoAccessor5(target=esnext).types b/tests/baselines/reference/autoAccessor5(target=esnext).types new file mode 100644 index 0000000000000..48b48c552dcf4 --- /dev/null +++ b/tests/baselines/reference/autoAccessor5(target=esnext).types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts === +class C1 { +>C1 : C1 + + accessor ["w"]: any; +>["w"] : any +>"w" : "w" + + accessor ["x"] = 1; +>["x"] : number +>"x" : "x" +>1 : 1 + + static accessor ["y"]: any; +>["y"] : any +>"y" : "y" + + static accessor ["z"] = 2; +>["z"] : number +>"z" : "z" +>2 : 2 +} + +declare var f: any; +>f : any + +class C2 { +>C2 : C2 + + accessor [f()] = 1; +>[f()] : number +>f() : any +>f : any +>1 : 1 +} diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).errors.txt b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).errors.txt new file mode 100644 index 0000000000000..e8867ac42e138 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts(6,5): error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts (1 errors) ==== + class C1 { + accessor a: any; + } + + class C2 extends C1 { + a = 1; + ~ +!!! error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + } + + class C3 extends C1 { + get a() { return super.a; } + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).js b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).js new file mode 100644 index 0000000000000..0868215c3fe0c --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).js @@ -0,0 +1,44 @@ +//// [autoAccessor6.ts] +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} + + +//// [autoAccessor6.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 __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 _C1_a_accessor_storage; +class C1 { + constructor() { + _C1_a_accessor_storage.set(this, void 0); + } + get a() { return __classPrivateFieldGet(this, _C1_a_accessor_storage, "f"); } + set a(value) { __classPrivateFieldSet(this, _C1_a_accessor_storage, value, "f"); } +} +_C1_a_accessor_storage = new WeakMap(); +class C2 extends C1 { + constructor() { + super(...arguments); + this.a = 1; + } +} +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).symbols b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..81d3591d79d78 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor6.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + a = 1; +>a : Symbol(C2.a, Decl(autoAccessor6.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor6.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + get a() { return super.a; } +>a : Symbol(C3.a, Decl(autoAccessor6.ts, 8, 21)) +>super.a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +>super : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).types b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..e93c302e46076 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=false).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return super.a; } +>a : any +>super.a : any +>super : C1 +>a : any +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).errors.txt new file mode 100644 index 0000000000000..e8867ac42e138 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts(6,5): error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts (1 errors) ==== + class C1 { + accessor a: any; + } + + class C2 extends C1 { + a = 1; + ~ +!!! error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + } + + class C3 extends C1 { + get a() { return super.a; } + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).js b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..54ab76c1b4a48 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).js @@ -0,0 +1,49 @@ +//// [autoAccessor6.ts] +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} + + +//// [autoAccessor6.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 __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 _C1_a_accessor_storage; +class C1 { + constructor() { + _C1_a_accessor_storage.set(this, void 0); + } + get a() { return __classPrivateFieldGet(this, _C1_a_accessor_storage, "f"); } + set a(value) { __classPrivateFieldSet(this, _C1_a_accessor_storage, value, "f"); } +} +_C1_a_accessor_storage = new WeakMap(); +class C2 extends C1 { + constructor() { + super(...arguments); + Object.defineProperty(this, "a", { + enumerable: true, + configurable: true, + writable: true, + value: 1 + }); + } +} +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).symbols b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..81d3591d79d78 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor6.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + a = 1; +>a : Symbol(C2.a, Decl(autoAccessor6.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor6.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + get a() { return super.a; } +>a : Symbol(C3.a, Decl(autoAccessor6.ts, 8, 21)) +>super.a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +>super : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).types b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..e93c302e46076 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2015,usedefineforclassfields=true).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return super.a; } +>a : any +>super.a : any +>super : C1 +>a : any +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).errors.txt b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).errors.txt new file mode 100644 index 0000000000000..e8867ac42e138 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts(6,5): error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts (1 errors) ==== + class C1 { + accessor a: any; + } + + class C2 extends C1 { + a = 1; + ~ +!!! error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + } + + class C3 extends C1 { + get a() { return super.a; } + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).js b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).js new file mode 100644 index 0000000000000..26181ea85fe31 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).js @@ -0,0 +1,29 @@ +//// [autoAccessor6.ts] +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} + + +//// [autoAccessor6.js] +class C1 { + #a_accessor_storage; + get a() { return this.#a_accessor_storage; } + set a(value) { this.#a_accessor_storage = value; } +} +class C2 extends C1 { + constructor() { + super(...arguments); + this.a = 1; + } +} +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).symbols b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..81d3591d79d78 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor6.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + a = 1; +>a : Symbol(C2.a, Decl(autoAccessor6.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor6.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + get a() { return super.a; } +>a : Symbol(C3.a, Decl(autoAccessor6.ts, 8, 21)) +>super.a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +>super : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).types b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..e93c302e46076 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=false).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return super.a; } +>a : any +>super.a : any +>super : C1 +>a : any +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).errors.txt new file mode 100644 index 0000000000000..e8867ac42e138 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts(6,5): error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts (1 errors) ==== + class C1 { + accessor a: any; + } + + class C2 extends C1 { + a = 1; + ~ +!!! error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + } + + class C3 extends C1 { + get a() { return super.a; } + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).js b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..8092e0db5ae42 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).js @@ -0,0 +1,26 @@ +//// [autoAccessor6.ts] +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} + + +//// [autoAccessor6.js] +class C1 { + #a_accessor_storage; + get a() { return this.#a_accessor_storage; } + set a(value) { this.#a_accessor_storage = value; } +} +class C2 extends C1 { + a = 1; +} +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).symbols b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..81d3591d79d78 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor6.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + a = 1; +>a : Symbol(C2.a, Decl(autoAccessor6.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor6.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + get a() { return super.a; } +>a : Symbol(C3.a, Decl(autoAccessor6.ts, 8, 21)) +>super.a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +>super : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + diff --git a/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).types b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..e93c302e46076 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=es2022,usedefineforclassfields=true).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return super.a; } +>a : any +>super.a : any +>super : C1 +>a : any +} + diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).errors.txt b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).errors.txt new file mode 100644 index 0000000000000..e8867ac42e138 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts(6,5): error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts (1 errors) ==== + class C1 { + accessor a: any; + } + + class C2 extends C1 { + a = 1; + ~ +!!! error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + } + + class C3 extends C1 { + get a() { return super.a; } + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).js b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).js new file mode 100644 index 0000000000000..9dfddc101abc6 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).js @@ -0,0 +1,26 @@ +//// [autoAccessor6.ts] +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} + + +//// [autoAccessor6.js] +class C1 { +} +class C2 extends C1 { + constructor() { + super(...arguments); + this.a = 1; + } +} +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).symbols b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..81d3591d79d78 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor6.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + a = 1; +>a : Symbol(C2.a, Decl(autoAccessor6.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor6.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + get a() { return super.a; } +>a : Symbol(C3.a, Decl(autoAccessor6.ts, 8, 21)) +>super.a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +>super : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).types b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..e93c302e46076 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=false).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return super.a; } +>a : any +>super.a : any +>super : C1 +>a : any +} + diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).errors.txt b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).errors.txt new file mode 100644 index 0000000000000..e8867ac42e138 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts(6,5): error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts (1 errors) ==== + class C1 { + accessor a: any; + } + + class C2 extends C1 { + a = 1; + ~ +!!! error TS2610: 'a' is defined as an accessor in class 'C1', but is overridden here in 'C2' as an instance property. + } + + class C3 extends C1 { + get a() { return super.a; } + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).js b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..47d8e6c085d18 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).js @@ -0,0 +1,24 @@ +//// [autoAccessor6.ts] +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} + + +//// [autoAccessor6.js] +class C1 { + accessor a; +} +class C2 extends C1 { + a = 1; +} +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).symbols b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..81d3591d79d78 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor6.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + a = 1; +>a : Symbol(C2.a, Decl(autoAccessor6.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor6.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) + + get a() { return super.a; } +>a : Symbol(C3.a, Decl(autoAccessor6.ts, 8, 21)) +>super.a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +>super : Symbol(C1, Decl(autoAccessor6.ts, 0, 0)) +>a : Symbol(C1.a, Decl(autoAccessor6.ts, 0, 10)) +} + diff --git a/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).types b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..e93c302e46076 --- /dev/null +++ b/tests/baselines/reference/autoAccessor6(target=esnext,usedefineforclassfields=true).types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return super.a; } +>a : any +>super.a : any +>super : C1 +>a : any +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).js b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).js new file mode 100644 index 0000000000000..1c1661a1f77f3 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).js @@ -0,0 +1,41 @@ +//// [autoAccessor7.ts] +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} + + +//// [autoAccessor7.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 __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 _C2_a_accessor_storage; +class C1 { +} +class C2 extends C1 { + constructor() { + super(...arguments); + _C2_a_accessor_storage.set(this, 1); + } + get a() { return __classPrivateFieldGet(this, _C2_a_accessor_storage, "f"); } + set a(value) { __classPrivateFieldSet(this, _C2_a_accessor_storage, value, "f"); } +} +_C2_a_accessor_storage = new WeakMap(); +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).symbols b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..4e4fd71011864 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + abstract accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor7.ts, 0, 19)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor7.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + accessor a = 1; +>a : Symbol(C2.a, Decl(autoAccessor7.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor7.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + get a() { return 1; } +>a : Symbol(C3.a, Decl(autoAccessor7.ts, 8, 21)) +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).types b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..e64536a22b8b2 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=false).types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : C1 + + abstract accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + accessor a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return 1; } +>a : number +>1 : 1 +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).js b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..1c1661a1f77f3 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).js @@ -0,0 +1,41 @@ +//// [autoAccessor7.ts] +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} + + +//// [autoAccessor7.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 __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 _C2_a_accessor_storage; +class C1 { +} +class C2 extends C1 { + constructor() { + super(...arguments); + _C2_a_accessor_storage.set(this, 1); + } + get a() { return __classPrivateFieldGet(this, _C2_a_accessor_storage, "f"); } + set a(value) { __classPrivateFieldSet(this, _C2_a_accessor_storage, value, "f"); } +} +_C2_a_accessor_storage = new WeakMap(); +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).symbols b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..4e4fd71011864 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + abstract accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor7.ts, 0, 19)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor7.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + accessor a = 1; +>a : Symbol(C2.a, Decl(autoAccessor7.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor7.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + get a() { return 1; } +>a : Symbol(C3.a, Decl(autoAccessor7.ts, 8, 21)) +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).types b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..e64536a22b8b2 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2015,usedefineforclassfields=true).types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : C1 + + abstract accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + accessor a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return 1; } +>a : number +>1 : 1 +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).js b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).js new file mode 100644 index 0000000000000..403aaa048a18e --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).js @@ -0,0 +1,29 @@ +//// [autoAccessor7.ts] +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} + + +//// [autoAccessor7.js] +class C1 { +} +class C2 extends C1 { + constructor() { + super(...arguments); + this.#a_accessor_storage = 1; + } + #a_accessor_storage; + get a() { return this.#a_accessor_storage; } + set a(value) { this.#a_accessor_storage = value; } +} +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).symbols b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..4e4fd71011864 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + abstract accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor7.ts, 0, 19)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor7.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + accessor a = 1; +>a : Symbol(C2.a, Decl(autoAccessor7.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor7.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + get a() { return 1; } +>a : Symbol(C3.a, Decl(autoAccessor7.ts, 8, 21)) +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).types b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..e64536a22b8b2 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=false).types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : C1 + + abstract accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + accessor a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return 1; } +>a : number +>1 : 1 +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).js b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..29f5e54f4080d --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).js @@ -0,0 +1,25 @@ +//// [autoAccessor7.ts] +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} + + +//// [autoAccessor7.js] +class C1 { +} +class C2 extends C1 { + #a_accessor_storage = 1; + get a() { return this.#a_accessor_storage; } + set a(value) { this.#a_accessor_storage = value; } +} +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).symbols b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..4e4fd71011864 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + abstract accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor7.ts, 0, 19)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor7.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + accessor a = 1; +>a : Symbol(C2.a, Decl(autoAccessor7.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor7.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + get a() { return 1; } +>a : Symbol(C3.a, Decl(autoAccessor7.ts, 8, 21)) +} + diff --git a/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).types b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..e64536a22b8b2 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=es2022,usedefineforclassfields=true).types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : C1 + + abstract accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + accessor a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return 1; } +>a : number +>1 : 1 +} + diff --git a/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).js b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).js new file mode 100644 index 0000000000000..2b8e93b75f8d5 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).js @@ -0,0 +1,26 @@ +//// [autoAccessor7.ts] +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} + + +//// [autoAccessor7.js] +class C1 { +} +class C2 extends C1 { + constructor() { + super(...arguments); + this.#a_1 = 1; + } +} +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).symbols b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).symbols new file mode 100644 index 0000000000000..4e4fd71011864 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + abstract accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor7.ts, 0, 19)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor7.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + accessor a = 1; +>a : Symbol(C2.a, Decl(autoAccessor7.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor7.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + get a() { return 1; } +>a : Symbol(C3.a, Decl(autoAccessor7.ts, 8, 21)) +} + diff --git a/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).types b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).types new file mode 100644 index 0000000000000..e64536a22b8b2 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=false).types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : C1 + + abstract accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + accessor a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return 1; } +>a : number +>1 : 1 +} + diff --git a/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).js b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).js new file mode 100644 index 0000000000000..7d3989d8cbd58 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).js @@ -0,0 +1,23 @@ +//// [autoAccessor7.ts] +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} + + +//// [autoAccessor7.js] +class C1 { +} +class C2 extends C1 { + accessor a = 1; +} +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).symbols b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).symbols new file mode 100644 index 0000000000000..4e4fd71011864 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + abstract accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor7.ts, 0, 19)) +} + +class C2 extends C1 { +>C2 : Symbol(C2, Decl(autoAccessor7.ts, 2, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + accessor a = 1; +>a : Symbol(C2.a, Decl(autoAccessor7.ts, 4, 21)) +} + +class C3 extends C1 { +>C3 : Symbol(C3, Decl(autoAccessor7.ts, 6, 1)) +>C1 : Symbol(C1, Decl(autoAccessor7.ts, 0, 0)) + + get a() { return 1; } +>a : Symbol(C3.a, Decl(autoAccessor7.ts, 8, 21)) +} + diff --git a/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).types b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).types new file mode 100644 index 0000000000000..e64536a22b8b2 --- /dev/null +++ b/tests/baselines/reference/autoAccessor7(target=esnext,usedefineforclassfields=true).types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts === +abstract class C1 { +>C1 : C1 + + abstract accessor a: any; +>a : any +} + +class C2 extends C1 { +>C2 : C2 +>C1 : C1 + + accessor a = 1; +>a : number +>1 : 1 +} + +class C3 extends C1 { +>C3 : C3 +>C1 : C1 + + get a() { return 1; } +>a : number +>1 : 1 +} + diff --git a/tests/baselines/reference/autoAccessor8.js b/tests/baselines/reference/autoAccessor8.js new file mode 100644 index 0000000000000..3e553dc952ee0 --- /dev/null +++ b/tests/baselines/reference/autoAccessor8.js @@ -0,0 +1,49 @@ +//// [autoAccessor8.ts] +class C1 { + accessor a: any; + static accessor b: any; +} + +declare class C2 { + accessor a: any; + static accessor b: any; +} + +function f() { + class C3 { + accessor a: any; + static accessor b: any; + } + return C3; +} + + +//// [autoAccessor8.js] +class C1 { + accessor a; + static accessor b; +} +function f() { + class C3 { + accessor a; + static accessor b; + } + return C3; +} + + +//// [autoAccessor8.d.ts] +declare class C1 { + accessor a: any; + static accessor b: any; +} +declare class C2 { + accessor a: any; + static accessor b: any; +} +declare function f(): { + new (): { + a: any; + }; + b: any; +}; diff --git a/tests/baselines/reference/autoAccessor8.symbols b/tests/baselines/reference/autoAccessor8.symbols new file mode 100644 index 0000000000000..70179862f1f91 --- /dev/null +++ b/tests/baselines/reference/autoAccessor8.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor8.ts === +class C1 { +>C1 : Symbol(C1, Decl(autoAccessor8.ts, 0, 0)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessor8.ts, 0, 10)) + + static accessor b: any; +>b : Symbol(C1.b, Decl(autoAccessor8.ts, 1, 20)) +} + +declare class C2 { +>C2 : Symbol(C2, Decl(autoAccessor8.ts, 3, 1)) + + accessor a: any; +>a : Symbol(C2.a, Decl(autoAccessor8.ts, 5, 18)) + + static accessor b: any; +>b : Symbol(C2.b, Decl(autoAccessor8.ts, 6, 20)) +} + +function f() { +>f : Symbol(f, Decl(autoAccessor8.ts, 8, 1)) + + class C3 { +>C3 : Symbol(C3, Decl(autoAccessor8.ts, 10, 14)) + + accessor a: any; +>a : Symbol(C3.a, Decl(autoAccessor8.ts, 11, 14)) + + static accessor b: any; +>b : Symbol(C3.b, Decl(autoAccessor8.ts, 12, 24)) + } + return C3; +>C3 : Symbol(C3, Decl(autoAccessor8.ts, 10, 14)) +} + diff --git a/tests/baselines/reference/autoAccessor8.types b/tests/baselines/reference/autoAccessor8.types new file mode 100644 index 0000000000000..39cd36ed09342 --- /dev/null +++ b/tests/baselines/reference/autoAccessor8.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor8.ts === +class C1 { +>C1 : C1 + + accessor a: any; +>a : any + + static accessor b: any; +>b : any +} + +declare class C2 { +>C2 : C2 + + accessor a: any; +>a : any + + static accessor b: any; +>b : any +} + +function f() { +>f : () => typeof C3 + + class C3 { +>C3 : C3 + + accessor a: any; +>a : any + + static accessor b: any; +>b : any + } + return C3; +>C3 : typeof C3 +} + diff --git a/tests/baselines/reference/autoAccessorAllowedModifiers.js b/tests/baselines/reference/autoAccessorAllowedModifiers.js new file mode 100644 index 0000000000000..3e91d75670421 --- /dev/null +++ b/tests/baselines/reference/autoAccessorAllowedModifiers.js @@ -0,0 +1,49 @@ +//// [autoAccessorAllowedModifiers.ts] +abstract class C1 { + accessor a: any; + public accessor b: any; + private accessor c: any; + protected accessor d: any; + abstract accessor e: any; + static accessor f: any; + public static accessor g: any; + private static accessor h: any; + protected static accessor i: any; + accessor #j: any; + accessor "k": any; + accessor 108: any; + accessor ["m"]: any; + accessor n!: number; +} + +class C2 extends C1 { + override accessor e: any; + static override accessor i: any; +} + +declare class C3 { + accessor a: any; +} + + + +//// [autoAccessorAllowedModifiers.js] +class C1 { + accessor a; + accessor b; + accessor c; + accessor d; + static accessor f; + static accessor g; + static accessor h; + static accessor i; + accessor #j; + accessor "k"; + accessor 108; + accessor ["m"]; + accessor n; +} +class C2 extends C1 { + accessor e; + static accessor i; +} diff --git a/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt b/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt new file mode 100644 index 0000000000000..d816b65516d5a --- /dev/null +++ b/tests/baselines/reference/autoAccessorDisallowedModifiers.errors.txt @@ -0,0 +1,124 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(2,14): error TS1030: 'accessor' modifier already seen. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(3,14): error TS1243: 'accessor' modifier cannot be used with 'readonly' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(4,13): error TS1243: 'accessor' modifier cannot be used with 'declare' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(5,14): error TS1029: 'public' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(6,14): error TS1029: 'private' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(7,14): error TS1029: 'protected' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(8,14): error TS1029: 'abstract' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(9,14): error TS1029: 'static' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(10,5): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(11,5): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(12,5): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(13,5): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(14,15): error TS1276: An 'accessor' property cannot be declared optional. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(18,14): error TS1029: 'override' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(22,5): error TS1070: 'accessor' modifier cannot appear on a type member. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(25,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(26,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(27,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(28,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(29,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(30,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(33,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts (28 errors) ==== + abstract class C1 { + accessor accessor a: any; + ~~~~~~~~ +!!! error TS1030: 'accessor' modifier already seen. + readonly accessor b: any; + ~~~~~~~~ +!!! error TS1243: 'accessor' modifier cannot be used with 'readonly' modifier. + declare accessor c: any; + ~~~~~~~~ +!!! error TS1243: 'accessor' modifier cannot be used with 'declare' modifier. + accessor public d: any; + ~~~~~~ +!!! error TS1029: 'public' modifier must precede 'accessor' modifier. + accessor private e: any; + ~~~~~~~ +!!! error TS1029: 'private' modifier must precede 'accessor' modifier. + accessor protected f: any; + ~~~~~~~~~ +!!! error TS1029: 'protected' modifier must precede 'accessor' modifier. + accessor abstract g: any; + ~~~~~~~~ +!!! error TS1029: 'abstract' modifier must precede 'accessor' modifier. + accessor static h: any; + ~~~~~~ +!!! error TS1029: 'static' modifier must precede 'accessor' modifier. + accessor i() {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor get j() { return false; } + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor set k(v: any) {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor constructor() {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor l?: any; + ~ +!!! error TS1276: An 'accessor' property cannot be declared optional. + } + + class C2 extends C1 { + accessor override g: any; + ~~~~~~~~ +!!! error TS1029: 'override' modifier must precede 'accessor' modifier. + } + + interface I1 { + accessor a: number; + ~~~~~~~~ +!!! error TS1070: 'accessor' modifier cannot appear on a type member. + } + + accessor class C3 {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor interface I2 {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor namespace N1 {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor enum E1 {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor var V1: any; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor type T1 = never; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor function F1() {} + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor import "x"; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor import {} from "x"; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + ~~~ +!!! error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? + accessor export { V1 }; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor export default V1; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor import N2 = N1; + ~~~~~~~~ +!!! error TS1275: 'accessor' modifier can only appear on a property declaration. + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessorDisallowedModifiers.js b/tests/baselines/reference/autoAccessorDisallowedModifiers.js new file mode 100644 index 0000000000000..83fcb6a3ff2ff --- /dev/null +++ b/tests/baselines/reference/autoAccessorDisallowedModifiers.js @@ -0,0 +1,66 @@ +//// [autoAccessorDisallowedModifiers.ts] +abstract class C1 { + accessor accessor a: any; + readonly accessor b: any; + declare accessor c: any; + accessor public d: any; + accessor private e: any; + accessor protected f: any; + accessor abstract g: any; + accessor static h: any; + accessor i() {} + accessor get j() { return false; } + accessor set k(v: any) {} + accessor constructor() {} + accessor l?: any; +} + +class C2 extends C1 { + accessor override g: any; +} + +interface I1 { + accessor a: number; +} + +accessor class C3 {} +accessor interface I2 {} +accessor namespace N1 {} +accessor enum E1 {} +accessor var V1: any; +accessor type T1 = never; +accessor function F1() {} +accessor import "x"; +accessor import {} from "x"; +accessor export { V1 }; +accessor export default V1; +accessor import N2 = N1; + + +//// [autoAccessorDisallowedModifiers.js] +class C1 { + accessor accessor a; + accessor b; + accessor d; + accessor e; + accessor f; + accessor static h; + accessor i() { } + accessor get j() { return false; } + accessor set k(v) { } + constructor() { } + accessor l; +} +class C2 extends C1 { + accessor g; +} +accessor class C3 { +} +accessor var E1; +(function (E1) { +})(E1 || (E1 = {})); +accessor var V1; +accessor function F1() { } +accessor import "x"; +export { V1 }; +export default V1; diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).errors.txt b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).errors.txt new file mode 100644 index 0000000000000..059790cbfde3c --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts(12,5): error TS1206: Decorators are not valid here. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts(15,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts (2 errors) ==== + declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + + class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; + } + + class C2 { + @dec + ~ +!!! error TS1206: Decorators are not valid here. + accessor #a: any; + + @dec + ~ +!!! error TS1206: Decorators are not valid here. + static accessor #b: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).js b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).js new file mode 100644 index 0000000000000..2a9c980122cf8 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).js @@ -0,0 +1,64 @@ +//// [autoAccessorExperimentalDecorators.ts] +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + +class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; +} + +class C2 { + @dec + accessor #a: any; + + @dec + static accessor #b: any; +} + + +//// [autoAccessorExperimentalDecorators.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __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 __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, _C1_a_accessor_storage, _C1_b_accessor_storage, _C2_instances, _b, _C2_a_get, _C2_a_set, _C2_b_get, _C2_b_set, _C2_a_1_accessor_storage, _C2_b_1_accessor_storage; +class C1 { + constructor() { + _C1_a_accessor_storage.set(this, void 0); + } + get a() { return __classPrivateFieldGet(this, _C1_a_accessor_storage, "f"); } + set a(value) { __classPrivateFieldSet(this, _C1_a_accessor_storage, value, "f"); } + static get b() { return __classPrivateFieldGet(this, _a, "f", _C1_b_accessor_storage); } + static set b(value) { __classPrivateFieldSet(this, _a, value, "f", _C1_b_accessor_storage); } +} +_a = C1, _C1_a_accessor_storage = new WeakMap(); +_C1_b_accessor_storage = { value: void 0 }; +__decorate([ + dec +], C1.prototype, "a", null); +__decorate([ + dec +], C1, "b", null); +class C2 { + constructor() { + _C2_instances.add(this); + _C2_a_1_accessor_storage.set(this, void 0); + } +} +_b = C2, _C2_instances = new WeakSet(), _C2_a_1_accessor_storage = new WeakMap(), _C2_a_get = function _C2_a_get() { return __classPrivateFieldGet(this, _C2_a_1_accessor_storage, "f"); }, _C2_a_set = function _C2_a_set(value) { __classPrivateFieldSet(this, _C2_a_1_accessor_storage, value, "f"); }, _C2_b_get = function _C2_b_get() { return __classPrivateFieldGet(this, _b, "f", _C2_b_1_accessor_storage); }, _C2_b_set = function _C2_b_set(value) { __classPrivateFieldSet(this, _b, value, "f", _C2_b_1_accessor_storage); }; +_C2_b_1_accessor_storage = { value: void 0 }; diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).symbols b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).symbols new file mode 100644 index 0000000000000..361d8a357c257 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts === +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) +>target : Symbol(target, Decl(autoAccessorExperimentalDecorators.ts, 0, 18)) +>key : Symbol(key, Decl(autoAccessorExperimentalDecorators.ts, 0, 30)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>desc : Symbol(desc, Decl(autoAccessorExperimentalDecorators.ts, 0, 48)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.es5.d.ts, --, --)) + +class C1 { +>C1 : Symbol(C1, Decl(autoAccessorExperimentalDecorators.ts, 0, 83)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessorExperimentalDecorators.ts, 2, 10)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + static accessor b: any; +>b : Symbol(C1.b, Decl(autoAccessorExperimentalDecorators.ts, 4, 20)) +} + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessorExperimentalDecorators.ts, 8, 1)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + accessor #a: any; +>#a : Symbol(C2.#a, Decl(autoAccessorExperimentalDecorators.ts, 10, 10)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + static accessor #b: any; +>#b : Symbol(C2.#b, Decl(autoAccessorExperimentalDecorators.ts, 12, 21)) +} + diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).types b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).types new file mode 100644 index 0000000000000..3ddf3b2cce215 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2015).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts === +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void +>target : any +>key : PropertyKey +>desc : PropertyDescriptor + +class C1 { +>C1 : C1 + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + accessor a: any; +>a : any + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + static accessor b: any; +>b : any +} + +class C2 { +>C2 : C2 + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + accessor #a: any; +>#a : any + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + static accessor #b: any; +>#b : any +} + diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).errors.txt b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).errors.txt new file mode 100644 index 0000000000000..059790cbfde3c --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts(12,5): error TS1206: Decorators are not valid here. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts(15,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts (2 errors) ==== + declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + + class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; + } + + class C2 { + @dec + ~ +!!! error TS1206: Decorators are not valid here. + accessor #a: any; + + @dec + ~ +!!! error TS1206: Decorators are not valid here. + static accessor #b: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).js b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).js new file mode 100644 index 0000000000000..2b1543d3047e7 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).js @@ -0,0 +1,49 @@ +//// [autoAccessorExperimentalDecorators.ts] +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + +class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; +} + +class C2 { + @dec + accessor #a: any; + + @dec + static accessor #b: any; +} + + +//// [autoAccessorExperimentalDecorators.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +class C1 { + #a_accessor_storage; + get a() { return this.#a_accessor_storage; } + set a(value) { this.#a_accessor_storage = value; } + static #b_accessor_storage; + static get b() { return this.#b_accessor_storage; } + static set b(value) { this.#b_accessor_storage = value; } +} +__decorate([ + dec +], C1.prototype, "a", null); +__decorate([ + dec +], C1, "b", null); +class C2 { + #a_1_accessor_storage; + get #a() { return this.#a_1_accessor_storage; } + set #a(value) { this.#a_1_accessor_storage = value; } + static #b_1_accessor_storage; + static get #b() { return this.#b_1_accessor_storage; } + static set #b(value) { this.#b_1_accessor_storage = value; } +} diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).symbols b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).symbols new file mode 100644 index 0000000000000..361d8a357c257 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts === +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) +>target : Symbol(target, Decl(autoAccessorExperimentalDecorators.ts, 0, 18)) +>key : Symbol(key, Decl(autoAccessorExperimentalDecorators.ts, 0, 30)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>desc : Symbol(desc, Decl(autoAccessorExperimentalDecorators.ts, 0, 48)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.es5.d.ts, --, --)) + +class C1 { +>C1 : Symbol(C1, Decl(autoAccessorExperimentalDecorators.ts, 0, 83)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessorExperimentalDecorators.ts, 2, 10)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + static accessor b: any; +>b : Symbol(C1.b, Decl(autoAccessorExperimentalDecorators.ts, 4, 20)) +} + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessorExperimentalDecorators.ts, 8, 1)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + accessor #a: any; +>#a : Symbol(C2.#a, Decl(autoAccessorExperimentalDecorators.ts, 10, 10)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + static accessor #b: any; +>#b : Symbol(C2.#b, Decl(autoAccessorExperimentalDecorators.ts, 12, 21)) +} + diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).types b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).types new file mode 100644 index 0000000000000..3ddf3b2cce215 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=es2022).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts === +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void +>target : any +>key : PropertyKey +>desc : PropertyDescriptor + +class C1 { +>C1 : C1 + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + accessor a: any; +>a : any + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + static accessor b: any; +>b : any +} + +class C2 { +>C2 : C2 + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + accessor #a: any; +>#a : any + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + static accessor #b: any; +>#b : any +} + diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).errors.txt b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).errors.txt new file mode 100644 index 0000000000000..059790cbfde3c --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts(12,5): error TS1206: Decorators are not valid here. +tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts(15,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts (2 errors) ==== + declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + + class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; + } + + class C2 { + @dec + ~ +!!! error TS1206: Decorators are not valid here. + accessor #a: any; + + @dec + ~ +!!! error TS1206: Decorators are not valid here. + static accessor #b: any; + } + \ No newline at end of file diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).js b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).js new file mode 100644 index 0000000000000..20f3b3d513711 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).js @@ -0,0 +1,41 @@ +//// [autoAccessorExperimentalDecorators.ts] +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + +class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; +} + +class C2 { + @dec + accessor #a: any; + + @dec + static accessor #b: any; +} + + +//// [autoAccessorExperimentalDecorators.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +class C1 { + accessor a; + static accessor b; +} +__decorate([ + dec +], C1.prototype, "a", null); +__decorate([ + dec +], C1, "b", null); +class C2 { + accessor #a; + static accessor #b; +} diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).symbols b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).symbols new file mode 100644 index 0000000000000..361d8a357c257 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts === +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) +>target : Symbol(target, Decl(autoAccessorExperimentalDecorators.ts, 0, 18)) +>key : Symbol(key, Decl(autoAccessorExperimentalDecorators.ts, 0, 30)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>desc : Symbol(desc, Decl(autoAccessorExperimentalDecorators.ts, 0, 48)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.es5.d.ts, --, --)) + +class C1 { +>C1 : Symbol(C1, Decl(autoAccessorExperimentalDecorators.ts, 0, 83)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + accessor a: any; +>a : Symbol(C1.a, Decl(autoAccessorExperimentalDecorators.ts, 2, 10)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + static accessor b: any; +>b : Symbol(C1.b, Decl(autoAccessorExperimentalDecorators.ts, 4, 20)) +} + +class C2 { +>C2 : Symbol(C2, Decl(autoAccessorExperimentalDecorators.ts, 8, 1)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + accessor #a: any; +>#a : Symbol(C2.#a, Decl(autoAccessorExperimentalDecorators.ts, 10, 10)) + + @dec +>dec : Symbol(dec, Decl(autoAccessorExperimentalDecorators.ts, 0, 11)) + + static accessor #b: any; +>#b : Symbol(C2.#b, Decl(autoAccessorExperimentalDecorators.ts, 12, 21)) +} + diff --git a/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).types b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).types new file mode 100644 index 0000000000000..3ddf3b2cce215 --- /dev/null +++ b/tests/baselines/reference/autoAccessorExperimentalDecorators(target=esnext).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts === +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void +>target : any +>key : PropertyKey +>desc : PropertyDescriptor + +class C1 { +>C1 : C1 + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + accessor a: any; +>a : any + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + static accessor b: any; +>b : any +} + +class C2 { +>C2 : C2 + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + accessor #a: any; +>#a : any + + @dec +>dec : (target: any, key: PropertyKey, desc: PropertyDescriptor) => void + + static accessor #b: any; +>#b : any +} + diff --git a/tests/baselines/reference/completionsOverridingMethod15.baseline b/tests/baselines/reference/completionsOverridingMethod15.baseline index 16f78ebae8115..4c594a35f3527 100644 --- a/tests/baselines/reference/completionsOverridingMethod15.baseline +++ b/tests/baselines/reference/completionsOverridingMethod15.baseline @@ -23,6 +23,18 @@ } ] }, + { + "name": "accessor", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "accessor", + "kind": "keyword" + } + ] + }, { "name": "async", "kind": "keyword", diff --git a/tests/baselines/reference/completionsOverridingMethod16.baseline b/tests/baselines/reference/completionsOverridingMethod16.baseline index ec29be4e1004b..9bfad8e55a321 100644 --- a/tests/baselines/reference/completionsOverridingMethod16.baseline +++ b/tests/baselines/reference/completionsOverridingMethod16.baseline @@ -23,6 +23,18 @@ } ] }, + { + "name": "accessor", + "kind": "keyword", + "kindModifiers": "", + "sortText": "15", + "displayParts": [ + { + "text": "accessor", + "kind": "keyword" + } + ] + }, { "name": "async", "kind": "keyword", diff --git a/tests/baselines/reference/controlFlowPrivateClassField.js b/tests/baselines/reference/controlFlowPrivateClassField.js index 0ec517e098d14..0057757653ff3 100644 --- a/tests/baselines/reference/controlFlowPrivateClassField.js +++ b/tests/baselines/reference/controlFlowPrivateClassField.js @@ -29,19 +29,19 @@ class Example2 { //// [controlFlowPrivateClassField.js] "use strict"; class Example { + #test; constructor(test) { this.#test = test; } - #test; get test() { return this.#test; } } class Example2 { + #test; constructor(test) { this.#test = test; } - #test; get test() { if (this.#test) { return this.#test; diff --git a/tests/baselines/reference/decoratorOnClassProperty13.js b/tests/baselines/reference/decoratorOnClassProperty13.js new file mode 100644 index 0000000000000..3ce4ead68fa39 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty13.js @@ -0,0 +1,37 @@ +//// [decoratorOnClassProperty13.ts] +declare function dec(target: any, propertyKey: string, desc: PropertyDescriptor): void; + +class C { + @dec accessor prop; +} + +//// [decoratorOnClassProperty13.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __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 __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_prop_accessor_storage; +class C { + constructor() { + _C_prop_accessor_storage.set(this, void 0); + } + get prop() { return __classPrivateFieldGet(this, _C_prop_accessor_storage, "f"); } + set prop(value) { __classPrivateFieldSet(this, _C_prop_accessor_storage, value, "f"); } +} +_C_prop_accessor_storage = new WeakMap(); +__decorate([ + dec +], C.prototype, "prop", null); diff --git a/tests/baselines/reference/decoratorOnClassProperty13.symbols b/tests/baselines/reference/decoratorOnClassProperty13.symbols new file mode 100644 index 0000000000000..cc9d96096bb57 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty13.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts === +declare function dec(target: any, propertyKey: string, desc: PropertyDescriptor): void; +>dec : Symbol(dec, Decl(decoratorOnClassProperty13.ts, 0, 0)) +>target : Symbol(target, Decl(decoratorOnClassProperty13.ts, 0, 21)) +>propertyKey : Symbol(propertyKey, Decl(decoratorOnClassProperty13.ts, 0, 33)) +>desc : Symbol(desc, Decl(decoratorOnClassProperty13.ts, 0, 54)) +>PropertyDescriptor : Symbol(PropertyDescriptor, Decl(lib.es5.d.ts, --, --)) + +class C { +>C : Symbol(C, Decl(decoratorOnClassProperty13.ts, 0, 87)) + + @dec accessor prop; +>dec : Symbol(dec, Decl(decoratorOnClassProperty13.ts, 0, 0)) +>prop : Symbol(C.prop, Decl(decoratorOnClassProperty13.ts, 2, 9)) +} diff --git a/tests/baselines/reference/decoratorOnClassProperty13.types b/tests/baselines/reference/decoratorOnClassProperty13.types new file mode 100644 index 0000000000000..ed061c458fdbc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty13.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts === +declare function dec(target: any, propertyKey: string, desc: PropertyDescriptor): void; +>dec : (target: any, propertyKey: string, desc: PropertyDescriptor) => void +>target : any +>propertyKey : string +>desc : PropertyDescriptor + +class C { +>C : C + + @dec accessor prop; +>dec : (target: any, propertyKey: string, desc: PropertyDescriptor) => void +>prop : any +} diff --git a/tests/baselines/reference/privateIdentifierChain.1.js b/tests/baselines/reference/privateIdentifierChain.1.js index 9ce965e2fe9f7..ff73beb38ca96 100644 --- a/tests/baselines/reference/privateIdentifierChain.1.js +++ b/tests/baselines/reference/privateIdentifierChain.1.js @@ -16,13 +16,13 @@ class A { //// [privateIdentifierChain.1.js] "use strict"; class A { + #b; + getA() { + return new A(); + } constructor() { this?.#b; // Error this?.a.#b; // Error this?.getA().#b; // Error } - #b; - getA() { - return new A(); - } } diff --git a/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js b/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js index 248d8203636d6..8b84f1973fb88 100644 --- a/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js +++ b/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js @@ -21,6 +21,6 @@ class A { constructor() { _A_x.set(this, 100); } - [(_A_x = new WeakMap(), (getX = (a) => __classPrivateFieldGet(a, _A_x, "f"), "_"))]() { } + [(_A_x = new WeakMap(), getX = (a) => __classPrivateFieldGet(a, _A_x, "f"), "_")]() { } } console.log(getX(new A)); diff --git a/tests/baselines/reference/privateNameDuplicateField.js b/tests/baselines/reference/privateNameDuplicateField.js index 3b59b74ad8165..7070236925786 100644 --- a/tests/baselines/reference/privateNameDuplicateField.js +++ b/tests/baselines/reference/privateNameDuplicateField.js @@ -456,24 +456,18 @@ function Field() { _A_Field_StaticField_foo_1 = { value: "foo" }; // Error class A_Field_StaticMethod { - constructor() { - } #foo = "foo"; static #foo() { } } _b = A_Field_StaticMethod, _A_Field_StaticMethod_foo = new WeakMap(); // Error class A_Field_StaticGetter { - constructor() { - } #foo = "foo"; static get #foo() { return ""; } } _c = A_Field_StaticGetter, _A_Field_StaticGetter_foo = new WeakMap(); // Error class A_Field_StaticSetter { - constructor() { - } #foo = "foo"; static set #foo(value) { } } @@ -557,7 +551,7 @@ function Method() { _d = A_Method_StaticSetter, _A_Method_StaticSetter_instances = new WeakSet(); } function Getter() { - var _A_Getter_Field_instances, _A_Getter_Field_foo_get, _A_Getter_Field_foo, _A_Getter_Method_instances, _A_Getter_Method_foo_get, _A_Getter_Method_foo, _A_Getter_Getter_instances, _A_Getter_Getter_foo_get, _A_Getter_Getter_foo_get_1, _A_Getter_Setter_instances, _A_Getter_Setter_foo_get, _A_Getter_Setter_foo_set, _A_Getter_StaticField_instances, _a, _A_Getter_StaticField_foo_get, _A_Getter_StaticField_foo, _A_Getter_StaticMethod_instances, _b, _A_Getter_StaticMethod_foo_get, _A_Getter_StaticMethod_foo, _A_Getter_StaticGetter_instances, _c, _A_Getter_StaticGetter_foo_get, _A_Getter_StaticGetter_foo_get_1, _A_Getter_StaticSetter_instances, _d, _A_Getter_StaticSetter_foo_get, _A_Getter_StaticSetter_foo_set; + var _A_Getter_Field_instances, _A_Getter_Field_foo_get, _A_Getter_Field_foo, _A_Getter_Method_instances, _A_Getter_Method_foo_get, _A_Getter_Method_foo, _A_Getter_Getter_instances, _A_Getter_Getter_foo_get, _A_Getter_Getter_foo_1_get, _A_Getter_Setter_instances, _A_Getter_Setter_foo_get, _A_Getter_Setter_foo_set, _A_Getter_StaticField_instances, _a, _A_Getter_StaticField_foo_get, _A_Getter_StaticField_foo, _A_Getter_StaticMethod_instances, _b, _A_Getter_StaticMethod_foo_get, _A_Getter_StaticMethod_foo, _A_Getter_StaticGetter_instances, _c, _A_Getter_StaticGetter_foo_get, _A_Getter_StaticGetter_foo_1_get, _A_Getter_StaticSetter_instances, _d, _A_Getter_StaticSetter_foo_get, _A_Getter_StaticSetter_foo_set; // Error class A_Getter_Field { constructor() { @@ -631,7 +625,7 @@ function Getter() { _d = A_Getter_StaticSetter, _A_Getter_StaticSetter_instances = new WeakSet(); } function Setter() { - var _A_Setter_Field_instances, _A_Setter_Field_foo_set, _A_Setter_Field_foo, _A_Setter_Method_instances, _A_Setter_Method_foo_set, _A_Setter_Method_foo, _A_Setter_Getter_instances, _A_Setter_Getter_foo_set, _A_Setter_Getter_foo_get, _A_Setter_Setter_instances, _A_Setter_Setter_foo_set, _A_Setter_Setter_foo_set_1, _A_Setter_StaticField_instances, _a, _A_Setter_StaticField_foo_set, _A_Setter_StaticField_foo, _A_Setter_StaticMethod_instances, _b, _A_Setter_StaticMethod_foo_set, _A_Setter_StaticMethod_foo, _A_Setter_StaticGetter_instances, _c, _A_Setter_StaticGetter_foo_set, _A_Setter_StaticGetter_foo_get, _A_Setter_StaticSetter_instances, _d, _A_Setter_StaticSetter_foo_set, _A_Setter_StaticSetter_foo_set_1; + var _A_Setter_Field_instances, _A_Setter_Field_foo_set, _A_Setter_Field_foo, _A_Setter_Method_instances, _A_Setter_Method_foo_set, _A_Setter_Method_foo, _A_Setter_Getter_instances, _A_Setter_Getter_foo_set, _A_Setter_Getter_foo_get, _A_Setter_Setter_instances, _A_Setter_Setter_foo_set, _A_Setter_Setter_foo_1_set, _A_Setter_StaticField_instances, _a, _A_Setter_StaticField_foo_set, _A_Setter_StaticField_foo, _A_Setter_StaticMethod_instances, _b, _A_Setter_StaticMethod_foo_set, _A_Setter_StaticMethod_foo, _A_Setter_StaticGetter_instances, _c, _A_Setter_StaticGetter_foo_set, _A_Setter_StaticGetter_foo_get, _A_Setter_StaticSetter_instances, _d, _A_Setter_StaticSetter_foo_set, _A_Setter_StaticSetter_foo_1_set; // Error class A_Setter_Field { constructor() { @@ -836,7 +830,7 @@ function StaticMethod() { _h = A_StaticMethod_StaticSetter; } function StaticGetter() { - var _a, _A_StaticGetter_Field_foo_get, _A_StaticGetter_Field_foo, _A_StaticGetter_Method_instances, _b, _A_StaticGetter_Method_foo_get, _A_StaticGetter_Method_foo, _A_StaticGetter_Getter_instances, _c, _A_StaticGetter_Getter_foo_get, _A_StaticGetter_Getter_foo_get_1, _A_StaticGetter_Setter_instances, _d, _A_StaticGetter_Setter_foo_get, _A_StaticGetter_Setter_foo_set, _e, _A_StaticGetter_StaticField_foo_get, _A_StaticGetter_StaticField_foo, _f, _A_StaticGetter_StaticMethod_foo_get, _A_StaticGetter_StaticMethod_foo, _g, _A_StaticGetter_StaticGetter_foo_get, _A_StaticGetter_StaticGetter_foo_get_1, _h, _A_StaticGetter_StaticSetter_foo_get, _A_StaticGetter_StaticSetter_foo_set; + var _a, _A_StaticGetter_Field_foo_get, _A_StaticGetter_Field_foo, _A_StaticGetter_Method_instances, _b, _A_StaticGetter_Method_foo_get, _A_StaticGetter_Method_foo, _A_StaticGetter_Getter_instances, _c, _A_StaticGetter_Getter_foo_get, _A_StaticGetter_Getter_foo_1_get, _A_StaticGetter_Setter_instances, _d, _A_StaticGetter_Setter_foo_get, _A_StaticGetter_Setter_foo_set, _e, _A_StaticGetter_StaticField_foo_get, _A_StaticGetter_StaticField_foo, _f, _A_StaticGetter_StaticMethod_foo_get, _A_StaticGetter_StaticMethod_foo, _g, _A_StaticGetter_StaticGetter_foo_get, _A_StaticGetter_StaticGetter_foo_1_get, _h, _A_StaticGetter_StaticSetter_foo_get, _A_StaticGetter_StaticSetter_foo_set; // Error class A_StaticGetter_Field { constructor() { @@ -897,7 +891,7 @@ function StaticGetter() { _h = A_StaticGetter_StaticSetter, _A_StaticGetter_StaticSetter_foo_get = function _A_StaticGetter_StaticSetter_foo_get() { return ""; }, _A_StaticGetter_StaticSetter_foo_set = function _A_StaticGetter_StaticSetter_foo_set(value) { }; } function StaticSetter() { - var _a, _A_StaticSetter_Field_foo_set, _A_StaticSetter_Field_foo, _A_StaticSetter_Method_instances, _b, _A_StaticSetter_Method_foo_set, _A_StaticSetter_Method_foo, _A_StaticSetter_Getter_instances, _c, _A_StaticSetter_Getter_foo_set, _A_StaticSetter_Getter_foo_get, _A_StaticSetter_Setter_instances, _d, _A_StaticSetter_Setter_foo_set, _A_StaticSetter_Setter_foo_set_1, _e, _A_StaticSetter_StaticField_foo_set, _A_StaticSetter_StaticField_foo, _f, _A_StaticSetter_StaticMethod_foo_set, _A_StaticSetter_StaticMethod_foo, _g, _A_StaticSetter_StaticGetter_foo_set, _A_StaticSetter_StaticGetter_foo_get, _h, _A_StaticSetter_StaticSetter_foo_set, _A_StaticSetter_StaticSetter_foo_set_1; + var _a, _A_StaticSetter_Field_foo_set, _A_StaticSetter_Field_foo, _A_StaticSetter_Method_instances, _b, _A_StaticSetter_Method_foo_set, _A_StaticSetter_Method_foo, _A_StaticSetter_Getter_instances, _c, _A_StaticSetter_Getter_foo_set, _A_StaticSetter_Getter_foo_get, _A_StaticSetter_Setter_instances, _d, _A_StaticSetter_Setter_foo_set, _A_StaticSetter_Setter_foo_1_set, _e, _A_StaticSetter_StaticField_foo_set, _A_StaticSetter_StaticField_foo, _f, _A_StaticSetter_StaticMethod_foo_set, _A_StaticSetter_StaticMethod_foo, _g, _A_StaticSetter_StaticGetter_foo_set, _A_StaticSetter_StaticGetter_foo_get, _h, _A_StaticSetter_StaticSetter_foo_set, _A_StaticSetter_StaticSetter_foo_1_set; // Error class A_StaticSetter_Field { constructor() { diff --git a/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js b/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js index e81cf2550e0a0..0f0cf8fdb6f0b 100644 --- a/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js +++ b/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js @@ -33,6 +33,12 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function ( }; var _A_field; class A { + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } constructor() { var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; _A_field.set(this, 1); @@ -46,12 +52,6 @@ class A { _k = this, [({ set value(_m) { __classPrivateFieldSet(_k, _A_field, _m, "f"); } }).value = 2] = []; _l = this.otherObject, [({ set value(_m) { __classPrivateFieldSet(_l, _A_field, _m, "f"); } }).value = 2] = []; } - testObject() { - return { x: 10, y: 6 }; - } - testArray() { - return [10, 11]; - } static test(_a) { [({ set value(_b) { __classPrivateFieldSet(_a, _A_field, _b, "f"); } }).value] = [2]; } diff --git a/tests/baselines/reference/privateNameMethodAssignment.js b/tests/baselines/reference/privateNameMethodAssignment.js index 08b4bb806bd1b..1533668f7c7f1 100644 --- a/tests/baselines/reference/privateNameMethodAssignment.js +++ b/tests/baselines/reference/privateNameMethodAssignment.js @@ -26,6 +26,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( }; var _A3_instances, _A3_method; class A3 { + ; constructor(a, b) { var _a, _b, _c; _A3_instances.add(this); @@ -36,6 +37,5 @@ class A3 { let x = __classPrivateFieldGet(this, _A3_instances, "m", _A3_method); __classPrivateFieldSet(_b = b, _A3_instances, (_c = __classPrivateFieldGet(_b, _A3_instances, "m", _A3_method), _c++, _c), "m"); //Error, not writable } - ; } _A3_instances = new WeakSet(), _A3_method = function _A3_method() { }; diff --git a/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js index 05e47e8bc5337..e735e0309fb0d 100644 --- a/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js +++ b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js @@ -23,6 +23,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( }; var _Base_instances, _Base_x_get; class Base { + ; constructor() { var _Derived_instances, _Derived_x_get; _Base_instances.add(this); @@ -40,6 +41,5 @@ class Base { } _Derived_instances = new WeakSet(), _Derived_x_get = function _Derived_x_get() { return 1; }; } - ; } _Base_instances = new WeakSet(), _Base_x_get = function _Base_x_get() { return 1; }; diff --git a/tests/baselines/reference/privateNameNestedClassMethodShadowing.js b/tests/baselines/reference/privateNameNestedClassMethodShadowing.js index df19ceac68b07..af9943b99d7f3 100644 --- a/tests/baselines/reference/privateNameNestedClassMethodShadowing.js +++ b/tests/baselines/reference/privateNameNestedClassMethodShadowing.js @@ -23,6 +23,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( }; var _Base_instances, _Base_x; class Base { + ; constructor() { var _Derived_instances, _Derived_x; _Base_instances.add(this); @@ -40,6 +41,5 @@ class Base { } _Derived_instances = new WeakSet(), _Derived_x = function _Derived_x() { }; } - ; } _Base_instances = new WeakSet(), _Base_x = function _Base_x() { }; diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js index f5ddbe3a7856a..943b099162020 100644 --- a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js @@ -33,6 +33,12 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function ( }; var _b, _A_field; class A { + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } constructor() { var _c; this.otherClass = A; @@ -45,12 +51,6 @@ class A { [({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value = 2] = []; _c = this.otherClass, [({ set value(_b) { __classPrivateFieldSet(_c, _b, _b, "f", _A_field); } }).value = 2] = []; } - testObject() { - return { x: 10, y: 6 }; - } - testArray() { - return [10, 11]; - } static test(_a) { [({ set value(_c) { __classPrivateFieldSet(_a, _b, _c, "f", _A_field); } }).value] = [2]; } diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2022).js b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2022).js index 69b4fff34e2bf..7b1829df27204 100644 --- a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2022).js +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2022).js @@ -26,6 +26,13 @@ class A { //// [privateNameStaticFieldDestructuredBinding.js] class A { + static #field = 1; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } constructor() { this.otherClass = A; let y; @@ -37,13 +44,6 @@ class A { [A.#field = 2] = []; [this.otherClass.#field = 2] = []; } - static #field = 1; - testObject() { - return { x: 10, y: 6 }; - } - testArray() { - return [10, 11]; - } static test(_a) { [_a.#field] = [2]; } diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js index 69b4fff34e2bf..7b1829df27204 100644 --- a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js @@ -26,6 +26,13 @@ class A { //// [privateNameStaticFieldDestructuredBinding.js] class A { + static #field = 1; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } constructor() { this.otherClass = A; let y; @@ -37,13 +44,6 @@ class A { [A.#field = 2] = []; [this.otherClass.#field = 2] = []; } - static #field = 1; - testObject() { - return { x: 10, y: 6 }; - } - testArray() { - return [10, 11]; - } static test(_a) { [_a.#field] = [2]; } diff --git a/tests/baselines/reference/privateNameStaticMethodAssignment.js b/tests/baselines/reference/privateNameStaticMethodAssignment.js index aad92bf3205b6..eaaeca788c308 100644 --- a/tests/baselines/reference/privateNameStaticMethodAssignment.js +++ b/tests/baselines/reference/privateNameStaticMethodAssignment.js @@ -26,6 +26,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( }; var _a, _A3_method; class A3 { + ; constructor(a, b) { var _b, _c; __classPrivateFieldSet(A3, _a, () => { }, "m"); // Error, not writable @@ -35,6 +36,5 @@ class A3 { let x = __classPrivateFieldGet(A3, _a, "m", _A3_method); __classPrivateFieldSet(_b = b, _a, (_c = __classPrivateFieldGet(_b, _a, "m", _A3_method), _c++, _c), "m"); //Error, not writable } - ; } _a = A3, _A3_method = function _A3_method() { }; diff --git a/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=es2022).js b/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=es2022).js index 971fb06aeb4e0..720176995905f 100644 --- a/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=es2022).js +++ b/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=es2022).js @@ -33,13 +33,6 @@ class B extends A { //// [privateNameStaticsAndStaticMethods.js] "use strict"; class A { - constructor() { - A.#foo(30); - A.#bar(30); - A.#bar(30); - A.#quux = A.#quux + 1; - A.#quux++; - } static #foo(a) { } static async #bar(a) { } static async *#baz(a) { @@ -52,6 +45,13 @@ class A { static set #quux(val) { this.#_quux = val; } + constructor() { + A.#foo(30); + A.#bar(30); + A.#bar(30); + A.#quux = A.#quux + 1; + A.#quux++; + } } class B extends A { static #foo(a) { } diff --git a/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=esnext).js b/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=esnext).js index 971fb06aeb4e0..720176995905f 100644 --- a/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=esnext).js +++ b/tests/baselines/reference/privateNameStaticsAndStaticMethods(target=esnext).js @@ -33,13 +33,6 @@ class B extends A { //// [privateNameStaticsAndStaticMethods.js] "use strict"; class A { - constructor() { - A.#foo(30); - A.#bar(30); - A.#bar(30); - A.#quux = A.#quux + 1; - A.#quux++; - } static #foo(a) { } static async #bar(a) { } static async *#baz(a) { @@ -52,6 +45,13 @@ class A { static set #quux(val) { this.#_quux = val; } + constructor() { + A.#foo(30); + A.#bar(30); + A.#bar(30); + A.#quux = A.#quux + 1; + A.#quux++; + } } class B extends A { static #foo(a) { } diff --git a/tests/baselines/reference/privateNamesAndGenericClasses-2.js b/tests/baselines/reference/privateNamesAndGenericClasses-2.js index 8e0d5c27c5619..2162584cf22f9 100644 --- a/tests/baselines/reference/privateNamesAndGenericClasses-2.js +++ b/tests/baselines/reference/privateNamesAndGenericClasses-2.js @@ -29,17 +29,17 @@ b = a; // Error //// [privateNamesAndGenericClasses-2.js] "use strict"; +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 __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_instances, _C_foo, _C_bar; class C { constructor(t) { diff --git a/tests/baselines/reference/privateNamesAndMethods(target=es2022).js b/tests/baselines/reference/privateNamesAndMethods(target=es2022).js index 5041d2a69d232..007e5810e6be1 100644 --- a/tests/baselines/reference/privateNamesAndMethods(target=es2022).js +++ b/tests/baselines/reference/privateNamesAndMethods(target=es2022).js @@ -32,13 +32,6 @@ class B extends A { //// [privateNamesAndMethods.js] class A { - constructor() { - this.#foo(30); - this.#bar(30); - this.#baz(30); - this.#quux = this.#quux + 1; - this.#quux++; - } #foo(a) { } async #bar(a) { } async *#baz(a) { @@ -51,6 +44,13 @@ class A { set #quux(val) { this.#_quux = val; } + constructor() { + this.#foo(30); + this.#bar(30); + this.#baz(30); + this.#quux = this.#quux + 1; + this.#quux++; + } } class B extends A { #foo(a) { } diff --git a/tests/baselines/reference/privateNamesAndMethods(target=esnext).js b/tests/baselines/reference/privateNamesAndMethods(target=esnext).js index 5041d2a69d232..007e5810e6be1 100644 --- a/tests/baselines/reference/privateNamesAndMethods(target=esnext).js +++ b/tests/baselines/reference/privateNamesAndMethods(target=esnext).js @@ -32,13 +32,6 @@ class B extends A { //// [privateNamesAndMethods.js] class A { - constructor() { - this.#foo(30); - this.#bar(30); - this.#baz(30); - this.#quux = this.#quux + 1; - this.#quux++; - } #foo(a) { } async #bar(a) { } async *#baz(a) { @@ -51,6 +44,13 @@ class A { set #quux(val) { this.#_quux = val; } + constructor() { + this.#foo(30); + this.#bar(30); + this.#baz(30); + this.#quux = this.#quux + 1; + this.#quux++; + } } class B extends A { #foo(a) { } diff --git a/tests/baselines/reference/privateNamesAndStaticMethods(target=es2022).js b/tests/baselines/reference/privateNamesAndStaticMethods(target=es2022).js index 7ec1ea5b8cc6f..ca2c039123d6b 100644 --- a/tests/baselines/reference/privateNamesAndStaticMethods(target=es2022).js +++ b/tests/baselines/reference/privateNamesAndStaticMethods(target=es2022).js @@ -33,13 +33,6 @@ class B extends A { //// [privateNamesAndStaticMethods.js] "use strict"; class A { - constructor() { - A.#foo(30); - A.#bar(30); - A.#bar(30); - A.#quux = A.#quux + 1; - A.#quux++; - } static #foo(a) { } static async #bar(a) { } static async *#baz(a) { @@ -52,6 +45,13 @@ class A { static set #quux(val) { this.#_quux = val; } + constructor() { + A.#foo(30); + A.#bar(30); + A.#bar(30); + A.#quux = A.#quux + 1; + A.#quux++; + } } class B extends A { static #foo(a) { } diff --git a/tests/baselines/reference/privateNamesAndStaticMethods(target=esnext).js b/tests/baselines/reference/privateNamesAndStaticMethods(target=esnext).js index 7ec1ea5b8cc6f..ca2c039123d6b 100644 --- a/tests/baselines/reference/privateNamesAndStaticMethods(target=esnext).js +++ b/tests/baselines/reference/privateNamesAndStaticMethods(target=esnext).js @@ -33,13 +33,6 @@ class B extends A { //// [privateNamesAndStaticMethods.js] "use strict"; class A { - constructor() { - A.#foo(30); - A.#bar(30); - A.#bar(30); - A.#quux = A.#quux + 1; - A.#quux++; - } static #foo(a) { } static async #bar(a) { } static async *#baz(a) { @@ -52,6 +45,13 @@ class A { static set #quux(val) { this.#_quux = val; } + constructor() { + A.#foo(30); + A.#bar(30); + A.#bar(30); + A.#quux = A.#quux + 1; + A.#quux++; + } } class B extends A { static #foo(a) { } diff --git a/tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline b/tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline new file mode 100644 index 0000000000000..c49934974d56d --- /dev/null +++ b/tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline @@ -0,0 +1,1422 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 30, + "name": "1a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "public", + "textSpan": { + "start": 30, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 75, + "name": "2a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "private", + "textSpan": { + "start": 75, + "length": 15 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 123, + "name": "3a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "protected", + "textSpan": { + "start": 123, + "length": 17 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 170, + "name": "4a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "static", + "textSpan": { + "start": 170, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 222, + "name": "5a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "private,static", + "textSpan": { + "start": 222, + "length": 21 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 283, + "name": "6a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "protected,static", + "textSpan": { + "start": 283, + "length": 23 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 371, + "name": "1g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 371, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 404, + "name": "2g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private", + "textSpan": { + "start": 404, + "length": 15 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 438, + "name": "3g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected", + "textSpan": { + "start": 438, + "length": 17 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 471, + "name": "4g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 471, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 501, + "name": "5g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private,static", + "textSpan": { + "start": 501, + "length": 21 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 538, + "name": "6g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected,static", + "textSpan": { + "start": 538, + "length": 23 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 576, + "name": "1s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 576, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 610, + "name": "2s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private", + "textSpan": { + "start": 610, + "length": 15 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 645, + "name": "3s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected", + "textSpan": { + "start": 645, + "length": 17 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 679, + "name": "4s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 679, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 710, + "name": "5s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private,static", + "textSpan": { + "start": 710, + "length": 21 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 748, + "name": "6s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected,static", + "textSpan": { + "start": 748, + "length": 23 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 830, + "name": "7g" + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 830, + "length": 9 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "cInstance", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 840, + "name": "8g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 840, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 860, + "name": "9g" + }, + "quickInfo": { + "kind": "class", + "kindModifiers": "", + "textSpan": { + "start": 860, + "length": 1 + }, + "displayParts": [ + { + "text": "class", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 862, + "name": "10g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 862, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 878, + "name": "7s" + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 878, + "length": 9 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "cInstance", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 888, + "name": "8s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 888, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 908, + "name": "9s" + }, + "quickInfo": { + "kind": "class", + "kindModifiers": "", + "textSpan": { + "start": 908, + "length": 1 + }, + "displayParts": [ + { + "text": "class", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 910, + "name": "10s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 910, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + } +] \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es2022).js b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es2022).js index 4072197b7007d..61a0be489d18b 100644 --- a/tests/baselines/reference/typeOfThisInStaticMembers12(target=es2022).js +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=es2022).js @@ -9,14 +9,15 @@ class C { //// [typeOfThisInStaticMembers12.js] -var _a, _b; +var _a, _b, _c; class C { static { this.c = "foo"; } - static { this.bar = class Inner { - constructor() { - this[_b] = 123; - } - static { _a = this.c, _b = this.c; } - static { this[_a] = 123; } - }; } + static { this.bar = (_c = () => { _a = this.c, _b = this.c; }, + class Inner { + constructor() { + this[_b] = 123; + } + static { _c(); } + static { this[_a] = 123; } + }); } } diff --git a/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js index 4072197b7007d..61a0be489d18b 100644 --- a/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js +++ b/tests/baselines/reference/typeOfThisInStaticMembers12(target=esnext).js @@ -9,14 +9,15 @@ class C { //// [typeOfThisInStaticMembers12.js] -var _a, _b; +var _a, _b, _c; class C { static { this.c = "foo"; } - static { this.bar = class Inner { - constructor() { - this[_b] = 123; - } - static { _a = this.c, _b = this.c; } - static { this[_a] = 123; } - }; } + static { this.bar = (_c = () => { _a = this.c, _b = this.c; }, + class Inner { + constructor() { + this[_b] = 123; + } + static { _c(); } + static { this[_a] = 123; } + }); } } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts new file mode 100644 index 0000000000000..177db89c2eddb --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor1.ts @@ -0,0 +1,9 @@ +// @target: esnext, es2022, es2015, es5 +// @noEmitOnError: true + +class C1 { + accessor a: any; + accessor b = 1; + static accessor c: any; + static accessor d = 2; +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts new file mode 100644 index 0000000000000..790702188cc35 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor2.ts @@ -0,0 +1,18 @@ +// @target: esnext, es2022, es2015 + +class C1 { + accessor #a: any; + accessor #b = 1; + static accessor #c: any; + static accessor #d = 2; + + constructor() { + this.#a = 3; + this.#b = 4; + } + + static { + this.#c = 5; + this.#d = 6; + } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts new file mode 100644 index 0000000000000..1c74a8be284c9 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor3.ts @@ -0,0 +1,9 @@ +// @target: esnext, es2022, es2015, es5 +// @noEmitOnError: true + +class C1 { + accessor "w": any; + accessor "x" = 1; + static accessor "y": any; + static accessor "z" = 2; +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts new file mode 100644 index 0000000000000..fcbf1e6f7bd58 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor4.ts @@ -0,0 +1,9 @@ +// @target: esnext, es2022, es2015, es5 +// @noEmitOnError: true + +class C1 { + accessor 0: any; + accessor 1 = 1; + static accessor 2: any; + static accessor 3 = 2; +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts new file mode 100644 index 0000000000000..dbbb949a3e34f --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor5.ts @@ -0,0 +1,13 @@ +// @target: esnext, es2022, es2015, es5 + +class C1 { + accessor ["w"]: any; + accessor ["x"] = 1; + static accessor ["y"]: any; + static accessor ["z"] = 2; +} + +declare var f: any; +class C2 { + accessor [f()] = 1; +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts new file mode 100644 index 0000000000000..aeb0c28609c25 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor6.ts @@ -0,0 +1,14 @@ +// @target: esnext, es2022, es2015 +// @useDefineForClassFields: * + +class C1 { + accessor a: any; +} + +class C2 extends C1 { + a = 1; +} + +class C3 extends C1 { + get a() { return super.a; } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts new file mode 100644 index 0000000000000..7993326180d10 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor7.ts @@ -0,0 +1,14 @@ +// @target: esnext, es2022, es2015 +// @useDefineForClassFields: * + +abstract class C1 { + abstract accessor a: any; +} + +class C2 extends C1 { + accessor a = 1; +} + +class C3 extends C1 { + get a() { return 1; } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor8.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor8.ts new file mode 100644 index 0000000000000..8e3a19e4d2b9d --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessor8.ts @@ -0,0 +1,20 @@ +// @target: esnext +// @declaration: true + +class C1 { + accessor a: any; + static accessor b: any; +} + +declare class C2 { + accessor a: any; + static accessor b: any; +} + +function f() { + class C3 { + accessor a: any; + static accessor b: any; + } + return C3; +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts new file mode 100644 index 0000000000000..0c7bb3d1ad94f --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorAllowedModifiers.ts @@ -0,0 +1,29 @@ +// @target: esnext +// @noTypesAndSymbols: true + +abstract class C1 { + accessor a: any; + public accessor b: any; + private accessor c: any; + protected accessor d: any; + abstract accessor e: any; + static accessor f: any; + public static accessor g: any; + private static accessor h: any; + protected static accessor i: any; + accessor #j: any; + accessor "k": any; + accessor 108: any; + accessor ["m"]: any; + accessor n!: number; +} + +class C2 extends C1 { + override accessor e: any; + static override accessor i: any; +} + +declare class C3 { + accessor a: any; +} + diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts new file mode 100644 index 0000000000000..44e848c1d7ae9 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts @@ -0,0 +1,39 @@ +// @target: esnext +// @noTypesAndSymbols: true + +abstract class C1 { + accessor accessor a: any; + readonly accessor b: any; + declare accessor c: any; + accessor public d: any; + accessor private e: any; + accessor protected f: any; + accessor abstract g: any; + accessor static h: any; + accessor i() {} + accessor get j() { return false; } + accessor set k(v: any) {} + accessor constructor() {} + accessor l?: any; +} + +class C2 extends C1 { + accessor override g: any; +} + +interface I1 { + accessor a: number; +} + +accessor class C3 {} +accessor interface I2 {} +accessor namespace N1 {} +accessor enum E1 {} +accessor var V1: any; +accessor type T1 = never; +accessor function F1() {} +accessor import "x"; +accessor import {} from "x"; +accessor export { V1 }; +accessor export default V1; +accessor import N2 = N1; diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts new file mode 100644 index 0000000000000..525beec0d4b33 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorExperimentalDecorators.ts @@ -0,0 +1,20 @@ +// @target: esnext, es2022, es2015 +// @experimentalDecorators: true + +declare var dec: (target: any, key: PropertyKey, desc: PropertyDescriptor) => void; + +class C1 { + @dec + accessor a: any; + + @dec + static accessor b: any; +} + +class C2 { + @dec + accessor #a: any; + + @dec + static accessor #b: any; +} diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts new file mode 100644 index 0000000000000..95977876681ac --- /dev/null +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty13.ts @@ -0,0 +1,7 @@ +// @target: ES2015 +// @experimentaldecorators: true +declare function dec(target: any, propertyKey: string, desc: PropertyDescriptor): void; + +class C { + @dec accessor prop; +} \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts b/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts index dad3c42964d40..e4981c24ceafc 100644 --- a/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts +++ b/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts @@ -7,6 +7,8 @@ //// abstract get b(): number; //// //// abstract set c(arg: number | string); +//// +//// abstract accessor d: string; ////} //// ////class C implements A {} @@ -21,6 +23,8 @@ verify.codeFix({ abstract get b(): number; abstract set c(arg: number | string); + + abstract accessor d: string; } class C implements A { @@ -36,5 +40,6 @@ class C implements A { set c(arg: string | number) { throw new Error("Method not implemented."); } + accessor d: string; }`, }); diff --git a/tests/cases/fourslash/completionEntryForClassMembers.ts b/tests/cases/fourslash/completionEntryForClassMembers.ts index 4d691c383abe0..fd148965c55e2 100644 --- a/tests/cases/fourslash/completionEntryForClassMembers.ts +++ b/tests/cases/fourslash/completionEntryForClassMembers.ts @@ -146,9 +146,7 @@ verify.completions( "classThatStartedWritingIdentifierAfterPrivateModifier", "classThatStartedWritingIdentifierAfterPrivateStaticModifier", ], - unsorted: ["private", "protected", "public", "static", "abstract", "async", "constructor", "declare", "get", "readonly", "set", "override"].map( - name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) - ), + unsorted: completion.classElementKeywords, isNewIdentifierLocation: true, }, { diff --git a/tests/cases/fourslash/completionListInNamedClassExpression.ts b/tests/cases/fourslash/completionListInNamedClassExpression.ts index 1a3068e9d0360..98658ee6888f4 100644 --- a/tests/cases/fourslash/completionListInNamedClassExpression.ts +++ b/tests/cases/fourslash/completionListInNamedClassExpression.ts @@ -11,22 +11,7 @@ verify.completions( { marker: "0", includes: { name: "myClass", text: "(local class) myClass", kind: "local class" } }, { marker: "1", - exact: [ - "abstract", - "async", - "constructor", - "declare", - "get", - "override", - "private", - "protected", - "public", - "readonly", - "set", - "static", - ].map( - name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) - ), + exact: completion.classElementKeywords, isNewIdentifierLocation: true, } ); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts new file mode 100644 index 0000000000000..619169e8b3a17 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts @@ -0,0 +1,33 @@ +/// + +////class c { +//// public accessor /*1a*/publicProperty: string; +//// private accessor /*2a*/privateProperty: string; +//// protected accessor /*3a*/protectedProperty: string; +//// static accessor /*4a*/staticProperty: string; +//// private static accessor /*5a*/privateStaticProperty: string; +//// protected static accessor /*6a*/protectedStaticProperty: string; +//// method() { +//// var x: string; +//// x = this./*1g*/publicProperty; +//// x = this./*2g*/privateProperty; +//// x = this./*3g*/protectedProperty; +//// x = c./*4g*/staticProperty; +//// x = c./*5g*/privateStaticProperty; +//// x = c./*6g*/protectedStaticProperty; +//// this./*1s*/publicProperty = ""; +//// this./*2s*/privateProperty = ""; +//// this./*3s*/protectedProperty = ""; +//// c./*4s*/staticProperty = ""; +//// c./*5s*/privateStaticProperty = ""; +//// c./*6s*/protectedStaticProperty = ""; +//// } +////} +////var cInstance = new c(); +////var y: string; +////y = /*7g*/cInstance./*8g*/publicProperty; +////y = /*9g*/c./*10g*/staticProperty; +/////*7s*/cInstance./*8s*/publicProperty = y; +/////*9s*/c./*10s*/staticProperty = y; + +verify.baselineQuickInfo(); \ No newline at end of file