From e638af7560530a76439d0ce9e2c517090fe6a60a Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Thu, 25 Mar 2021 03:15:50 +0200 Subject: [PATCH] ES private class elements (#42458) * Added support for private identifier methods. * Added tests for private methods. * Added check to only not allow private name method signatures in anything except classes. Changes objects literal checking to not bail on first private name found in object literal. * Added private accessors tests * Transform private methods Signed-off-by: Kubilay Kahveci * Rename shouldTransformPrivateFields Signed-off-by: Kubilay Kahveci * Accept baseline Signed-off-by: Kubilay Kahveci * Use a single WeakSet for brand-check Signed-off-by: Kubilay Kahveci * Accept baseline Signed-off-by: Kubilay Kahveci * Add a test for using private methods in static field initializers Signed-off-by: Kubilay Kahveci * Add breaking checker test Private methods inside class expressions should not error. Signed-off-by: Kubilay Kahveci * Add to instances once per-instance Signed-off-by: Kubilay Kahveci * Accept baseline Signed-off-by: Kubilay Kahveci * fix: evaluate receiver and rhs expressions before throwing on readonly assignment Signed-off-by: Kubilay Kahveci * Add a test for evaluating rhs before readonly assignment Signed-off-by: Kubilay Kahveci * Transpile private accessors Signed-off-by: Kubilay Kahveci * Accept baseline Signed-off-by: Kubilay Kahveci * fix: handle readonly/writeonly accessors Signed-off-by: Kubilay Kahveci * accept baseline Signed-off-by: Kubilay Kahveci * add a test for private setter without a getter Signed-off-by: Kubilay Kahveci * fix: getAllUnscopedEmitHelpers Signed-off-by: Kubilay Kahveci * fix: better handling of duplicate names Signed-off-by: Kubilay Kahveci * Fixed wrong error message for private methods in class expressions. * change error message Signed-off-by: Kubilay Kahveci * add a test for async private methods with a higher target Signed-off-by: Kubilay Kahveci * fix: setter assignment returns rhs value Signed-off-by: Kubilay Kahveci * add a test for setter assignment return value Signed-off-by: Kubilay Kahveci * fix: handle duplicate accessors Signed-off-by: Kubilay Kahveci * add tests for duplicate accessors Signed-off-by: Kubilay Kahveci * docs: add missing parameter docs Signed-off-by: Kubilay Kahveci * Fixed failing test. * baseline-accept: ordering changes Signed-off-by: Kubilay Kahveci * fix: attach weakSetName to property declaration Signed-off-by: Kubilay Kahveci * add a test for nested private methods Signed-off-by: Kubilay Kahveci * add a test with any Signed-off-by: Kubilay Kahveci * Added support for static private fields accessors and methods. * Added error message for private identifiers used with static decorators. There is no spec to go with this behavior as of yet. * Fixed emit static bug that used private names outside of classes for initialization in esnext. Fixed issue where nested privates produce incorrect brand check. * Added tests for private static fields methods and accessors. * Fixed error messages and tests after merge. * Accept new baseline. * Improved duplicate identifier checks for static private class elements. * Added error when using initializers with private static fields when useDefineForClassFields is not specified and target is esnext. * Fixed code review issues. * Removed semantically wrong emit on `useDefineForClassFields:true` with `target:esnext` * Changed emit for uninitialized private static fields. * Added runtime error in helper if a static private field is accessed before it was declared. * Fixed code review comments for private identifier static class elements. * add debug.assertNever for unknown node type (#53) * Fixed code review issues. * Fixed code review issues for private class elements. * Fixes class shadowing when checking access to a private static class element. * fix private methods/accessors in class expr inside a loop * collapse switch case * fix class name * simplify getPrivateMethodsAndAccessors * remove findPreviousAccessorInfo * lazily create weakSetName identifier * do not allocate a node if not needed in visitMehodDeclaration (#55) * Removed all the emit helpers for private identifier methods accessors and modified the existing helpers for get and set fields to do the same job. * Simplified emit for private identifier class elements. * do not clone the receiver (#57) * leave bad code in for #constructor and duplicate private names (#58) * Added check for WeakSet collision. * Added error for using a set only accessor. * update keyof tests and ?? (#62) * replace ?? with || * update keyof tests * fix emit helpers comments * produce an error if private field helpers are not up to date * add tests * fix setter-only compound assignment * fix tests * fix duplicated trailing comments (#64) * clear receiver pos and setTextRange on helper calls Co-authored-by: Kubilay Kahveci --- src/compiler/checker.ts | 219 ++-- src/compiler/diagnosticMessages.json | 32 +- src/compiler/factory/emitHelpers.ts | 150 ++- src/compiler/transformers/classFields.ts | 654 ++++++++++-- src/compiler/transformers/utilities.ts | 9 + src/compiler/types.ts | 20 + src/compiler/utilities.ts | 6 + src/compiler/utilitiesPublic.ts | 6 +- src/services/completions.ts | 4 +- src/services/findAllReferences.ts | 2 +- src/services/stringCompletions.ts | 2 +- tests/baselines/reference/importHelpersES6.js | 13 +- .../reference/importHelpersES6.symbols | 13 +- .../reference/importHelpersES6.types | 17 +- .../privateFieldAssignabilityFromUnknown.js | 6 +- .../reference/privateNameAccessors.errors.txt | 20 + .../reference/privateNameAccessors.js | 40 + .../reference/privateNameAccessors.symbols | 41 + .../reference/privateNameAccessors.types | 49 + .../privateNameAccessorsAccess.errors.txt | 37 + .../reference/privateNameAccessorsAccess.js | 55 + .../privateNameAccessorsAccess.symbols | 58 ++ .../privateNameAccessorsAccess.types | 65 ++ .../privateNameAccessorsCallExpression.js | 47 + ...privateNameAccessorsCallExpression.symbols | 63 ++ .../privateNameAccessorsCallExpression.types | 95 ++ ...ateNameAccessorssDerivedClasses.errors.txt | 18 + .../privateNameAccessorssDerivedClasses.js | 35 + ...rivateNameAccessorssDerivedClasses.symbols | 37 + .../privateNameAccessorssDerivedClasses.types | 39 + .../reference/privateNameAndAny.errors.txt | 40 +- .../baselines/reference/privateNameAndAny.js | 45 +- .../reference/privateNameAndAny.symbols | 56 +- .../reference/privateNameAndAny.types | 36 +- .../reference/privateNameAndIndexSignature.js | 6 +- .../privateNameAndObjectRestSpread.errors.txt | 18 +- .../privateNameAndObjectRestSpread.js | 30 +- .../privateNameAndObjectRestSpread.symbols | 33 +- .../privateNameAndObjectRestSpread.types | 21 + ...privateNameAndPropertySignature.errors.txt | 28 +- .../privateNameAndPropertySignature.js | 6 +- .../privateNameAndPropertySignature.symbols | 32 +- .../privateNameAndPropertySignature.types | 16 +- ...NameAndStaticInitializer(target=es2015).js | 8 +- .../reference/privateNameBadAssignment.js | 19 +- .../privateNameBadDeclaration.errors.txt | 32 +- .../reference/privateNameBadDeclaration.js | 16 +- .../privateNameBadDeclaration.symbols | 26 +- .../reference/privateNameBadDeclaration.types | 26 +- .../reference/privateNameBadSuper.js | 6 +- .../reference/privateNameCircularReference.js | 17 +- .../privateNameClassExpressionLoop.js | 14 +- .../privateNameClassExpressionLoop.symbols | 10 + .../privateNameClassExpressionLoop.types | 15 +- ...ameComputedPropertyName1(target=es2015).js | 50 +- ...ameComputedPropertyName2(target=es2015).js | 15 +- ...ameComputedPropertyName3(target=es2015).js | 38 +- .../privateNameConstructorReserved.errors.txt | 5 +- .../privateNameConstructorReserved.js | 7 +- .../privateNameConstructorSignature.js | 19 +- .../reference/privateNameDeclaration.js | 8 +- .../privateNameDeclarationMerging.js | 19 +- .../privateNameDuplicateField.errors.txt | 658 +++++++++++- .../reference/privateNameDuplicateField.js | 961 +++++++++++++++++- .../privateNameDuplicateField.symbols | 771 +++++++++++++- .../reference/privateNameDuplicateField.types | 827 ++++++++++++++- .../privateNameES5Ban(target=es3).errors.txt | 28 +- .../privateNameES5Ban(target=es3).js | 23 +- .../privateNameES5Ban(target=es5).errors.txt | 30 +- .../privateNameES5Ban(target=es5).js | 23 +- .../privateNameEmitHelpers.errors.txt | 20 + .../reference/privateNameEmitHelpers.js | 25 + .../reference/privateNameEmitHelpers.symbols | 42 + .../reference/privateNameEmitHelpers.types | 37 + tests/baselines/reference/privateNameField.js | 19 +- .../reference/privateNameFieldAccess.js | 17 +- .../reference/privateNameFieldAssignment.js | 78 +- .../privateNameFieldCallExpression.js | 33 +- .../privateNameFieldClassExpression.js | 8 +- .../privateNameFieldDerivedClasses.js | 17 +- ...FieldDestructuredBinding(target=es2015).js | 33 +- .../reference/privateNameFieldInitializer.js | 8 +- .../privateNameFieldUnaryMutation.js | 66 +- .../privateNameFieldsESNext.errors.txt | 11 +- .../privateNameInLhsReceiverExpression.js | 30 +- .../privateNameInObjectLiteral-3.errors.txt | 15 + .../reference/privateNameInObjectLiteral-3.js | 14 + .../privateNameInObjectLiteral-3.symbols | 11 + .../privateNameInObjectLiteral-3.types | 13 + .../privateNameJsBadDeclaration.errors.txt | 32 +- .../privateNameJsBadDeclaration.symbols | 30 +- .../privateNameJsBadDeclaration.types | 26 +- tests/baselines/reference/privateNameJsx.js | 6 +- .../reference/privateNameMethod.errors.txt | 22 + .../baselines/reference/privateNameMethod.js | 33 + .../reference/privateNameMethod.symbols | 28 + .../reference/privateNameMethod.types | 34 + .../privateNameMethodAccess.errors.txt | 35 + .../reference/privateNameMethodAccess.js | 55 + .../reference/privateNameMethodAccess.symbols | 54 + .../reference/privateNameMethodAccess.types | 66 ++ .../privateNameMethodAssignment.errors.txt | 30 + .../reference/privateNameMethodAssignment.js | 41 + .../privateNameMethodAssignment.symbols | 39 + .../privateNameMethodAssignment.types | 52 + .../reference/privateNameMethodAsync.js | 40 + .../reference/privateNameMethodAsync.symbols | 56 + .../reference/privateNameMethodAsync.types | 86 ++ .../privateNameMethodCallExpression.js | 58 ++ .../privateNameMethodCallExpression.symbols | 89 ++ .../privateNameMethodCallExpression.types | 132 +++ ...rivateNameMethodClassExpression.errors.txt | 21 + .../privateNameMethodClassExpression.js | 37 + .../privateNameMethodClassExpression.symbols | 43 + .../privateNameMethodClassExpression.types | 54 + .../privateNameMethodInStaticFieldInit.js | 24 + ...privateNameMethodInStaticFieldInit.symbols | 21 + .../privateNameMethodInStaticFieldInit.types | 25 + ...rivateNameMethodsDerivedClasses.errors.txt | 18 + .../privateNameMethodsDerivedClasses.js | 35 + .../privateNameMethodsDerivedClasses.symbols | 37 + .../privateNameMethodsDerivedClasses.types | 41 + ...meNestedClassAccessorsShadowing.errors.txt | 23 + ...rivateNameNestedClassAccessorsShadowing.js | 45 + ...eNameNestedClassAccessorsShadowing.symbols | 41 + ...ateNameNestedClassAccessorsShadowing.types | 44 + .../privateNameNestedClassFieldShadowing.js | 25 +- ...eNameNestedClassMethodShadowing.errors.txt | 23 + .../privateNameNestedClassMethodShadowing.js | 45 + ...vateNameNestedClassMethodShadowing.symbols | 41 + ...rivateNameNestedClassMethodShadowing.types | 42 + .../privateNameNestedClassNameConflict.js | 12 +- .../privateNameNestedMethodAccess.errors.txt | 35 + .../privateNameNestedMethodAccess.js | 60 ++ .../privateNameNestedMethodAccess.symbols | 58 ++ .../privateNameNestedMethodAccess.types | 70 ++ ...teNameNotAccessibleOutsideDefiningClass.js | 6 +- .../reference/privateNameReadonly.errors.txt | 18 + .../reference/privateNameReadonly.js | 31 + .../reference/privateNameReadonly.symbols | 27 + .../reference/privateNameReadonly.types | 34 + .../privateNameSetterExprReturnValue.js | 31 + .../privateNameSetterExprReturnValue.symbols | 29 + .../privateNameSetterExprReturnValue.types | 37 + .../privateNameSetterNoGetter.errors.txt | 15 + .../reference/privateNameSetterNoGetter.js | 36 + .../privateNameSetterNoGetter.symbols | 25 + .../reference/privateNameSetterNoGetter.types | 31 + .../privateNameStaticAccessors.errors.txt | 20 + .../reference/privateNameStaticAccessors.js | 39 + .../privateNameStaticAccessors.symbols | 41 + .../privateNameStaticAccessors.types | 49 + ...rivateNameStaticAccessorsAccess.errors.txt | 39 + .../privateNameStaticAccessorsAccess.js | 57 ++ .../privateNameStaticAccessorsAccess.symbols | 60 ++ .../privateNameStaticAccessorsAccess.types | 65 ++ ...rivateNameStaticAccessorsCallExpression.js | 50 + ...eNameStaticAccessorsCallExpression.symbols | 65 ++ ...ateNameStaticAccessorsCallExpression.types | 93 ++ ...eStaticAccessorssDerivedClasses.errors.txt | 21 + ...ivateNameStaticAccessorssDerivedClasses.js | 32 + ...NameStaticAccessorssDerivedClasses.symbols | 36 + ...teNameStaticAccessorssDerivedClasses.types | 41 + ...aticAndStaticInitializer(target=es2015).js | 15 + ...ndStaticInitializer(target=es2015).symbols | 12 + ...cAndStaticInitializer(target=es2015).types | 14 + ...taticInitializer(target=esnext).errors.txt | 15 + ...aticAndStaticInitializer(target=esnext).js | 15 + ...ndStaticInitializer(target=esnext).symbols | 12 + ...cAndStaticInitializer(target=esnext).types | 14 + .../privateNameStaticEmitHelpers.errors.txt | 20 + .../reference/privateNameStaticEmitHelpers.js | 22 + .../privateNameStaticEmitHelpers.symbols | 40 + .../privateNameStaticEmitHelpers.types | 35 + .../privateNameStaticFieldAccess.errors.txt | 14 + .../reference/privateNameStaticFieldAccess.js | 25 + .../privateNameStaticFieldAccess.symbols | 23 + .../privateNameStaticFieldAccess.types | 27 + .../privateNameStaticFieldAssignment.js | 86 ++ .../privateNameStaticFieldAssignment.symbols | 146 +++ .../privateNameStaticFieldAssignment.types | 212 ++++ .../privateNameStaticFieldCallExpression.js | 52 + ...ivateNameStaticFieldCallExpression.symbols | 68 ++ ...privateNameStaticFieldCallExpression.types | 100 ++ .../privateNameStaticFieldClassExpression.js | 52 + ...vateNameStaticFieldClassExpression.symbols | 61 ++ ...rivateNameStaticFieldClassExpression.types | 73 ++ ...teNameStaticFieldDerivedClasses.errors.txt | 25 + .../privateNameStaticFieldDerivedClasses.js | 47 + ...ivateNameStaticFieldDerivedClasses.symbols | 42 + ...privateNameStaticFieldDerivedClasses.types | 48 + ...FieldDestructuredBinding(target=es2015).js | 59 ++ ...DestructuredBinding(target=es2015).symbols | 90 ++ ...ldDestructuredBinding(target=es2015).types | 144 +++ ...tructuredBinding(target=esnext).errors.txt | 30 + ...FieldDestructuredBinding(target=esnext).js | 51 + ...DestructuredBinding(target=esnext).symbols | 90 ++ ...ldDestructuredBinding(target=esnext).types | 144 +++ ...meStaticFieldInitializer(target=es2015).js | 14 + ...ticFieldInitializer(target=es2015).symbols | 11 + ...taticFieldInitializer(target=es2015).types | 12 + ...FieldInitializer(target=esnext).errors.txt | 11 + ...meStaticFieldInitializer(target=esnext).js | 13 + ...ticFieldInitializer(target=esnext).symbols | 11 + ...taticFieldInitializer(target=esnext).types | 12 + .../privateNameStaticFieldInitializer.js | 13 + .../privateNameStaticFieldInitializer.symbols | 11 + .../privateNameStaticFieldInitializer.types | 12 + ...StaticFieldNoInitializer(target=es2015).js | 19 + ...cFieldNoInitializer(target=es2015).symbols | 14 + ...ticFieldNoInitializer(target=es2015).types | 15 + ...StaticFieldNoInitializer(target=esnext).js | 16 + ...cFieldNoInitializer(target=esnext).symbols | 14 + ...ticFieldNoInitializer(target=esnext).types | 15 + .../privateNameStaticFieldUnaryMutation.js | 75 ++ ...rivateNameStaticFieldUnaryMutation.symbols | 148 +++ .../privateNameStaticFieldUnaryMutation.types | 199 ++++ .../privateNameStaticMethod.errors.txt | 22 + .../reference/privateNameStaticMethod.js | 32 + .../reference/privateNameStaticMethod.symbols | 26 + .../reference/privateNameStaticMethod.types | 32 + ...ivateNameStaticMethodAssignment.errors.txt | 30 + .../privateNameStaticMethodAssignment.js | 40 + .../privateNameStaticMethodAssignment.symbols | 39 + .../privateNameStaticMethodAssignment.types | 53 + .../privateNameStaticMethodAsync.errors.txt | 21 + .../reference/privateNameStaticMethodAsync.js | 37 + .../privateNameStaticMethodAsync.symbols | 50 + .../privateNameStaticMethodAsync.types | 79 ++ .../privateNameStaticMethodCallExpression.js | 55 + ...vateNameStaticMethodCallExpression.symbols | 89 ++ ...rivateNameStaticMethodCallExpression.types | 131 +++ ...NameStaticMethodClassExpression.errors.txt | 21 + .../privateNameStaticMethodClassExpression.js | 32 + ...ateNameStaticMethodClassExpression.symbols | 44 + ...ivateNameStaticMethodClassExpression.types | 54 + ...rivateNameStaticMethodInStaticFieldInit.js | 21 + ...eNameStaticMethodInStaticFieldInit.symbols | 21 + ...ateNameStaticMethodInStaticFieldInit.types | 24 + .../privateNameStaticsAndStaticMethods.js | 62 ++ ...privateNameStaticsAndStaticMethods.symbols | 80 ++ .../privateNameStaticsAndStaticMethods.types | 95 ++ .../reference/privateNameUnused.errors.txt | 28 +- .../reference/privateNameUnused.symbols | 45 + .../reference/privateNameUnused.types | 50 + .../privateNameWeakMapCollision.errors.txt | 6 +- .../reference/privateNameWeakMapCollision.js | 8 +- .../privateNameWeakMapCollision.symbols | 7 +- .../privateNameWeakMapCollision.types | 3 + .../privateNamesAndDecorators.errors.txt | 5 +- .../reference/privateNamesAndDecorators.js | 8 +- .../reference/privateNamesAndFields.js | 25 +- ...privateNamesAndGenericClasses-2.errors.txt | 5 +- .../privateNamesAndGenericClasses-2.js | 40 +- .../reference/privateNamesAndIndexedAccess.js | 6 +- .../privateNamesAndMethods.errors.txt | 51 - .../privateNamesAndStaticFields.errors.txt | 11 +- .../reference/privateNamesAndStaticFields.js | 37 +- .../privateNamesAndStaticMethods.errors.txt | 54 - .../reference/privateNamesAndkeyof.errors.txt | 42 + .../reference/privateNamesAndkeyof.js | 36 +- .../reference/privateNamesAndkeyof.symbols | 44 +- .../reference/privateNamesAndkeyof.types | 56 +- .../reference/privateNamesAssertion.js | 23 + .../reference/privateNamesAssertion.symbols | 29 + .../reference/privateNamesAssertion.types | 33 + .../privateNamesConstructorChain-1.errors.txt | 5 +- .../privateNamesConstructorChain-1.js | 27 +- .../privateNamesConstructorChain-2.errors.txt | 5 +- .../privateNamesConstructorChain-2.js | 27 +- .../privateNamesInGenericClasses.errors.txt | 28 +- .../reference/privateNamesInGenericClasses.js | 50 +- .../privateNamesInGenericClasses.symbols | 102 +- .../privateNamesInGenericClasses.types | 63 ++ .../privateNamesInNestedClasses-1.js | 29 +- .../privateNamesInNestedClasses-2.errors.txt | 5 +- .../privateNamesInNestedClasses-2.js | 23 +- ...ivateNamesIncompatibleModifiers.errors.txt | 79 +- .../privateNamesIncompatibleModifiers.js | 62 +- .../privateNamesIncompatibleModifiers.symbols | 70 +- .../privateNamesIncompatibleModifiers.types | 78 ++ .../privateNamesInterfaceExtendingClass.js | 19 +- .../reference/privateNamesNoDelete.js | 17 +- .../reference/privateNamesUnique-1.js | 10 +- .../reference/privateNamesUnique-2.js | 23 +- .../reference/privateNamesUnique-3.errors.txt | 12 +- .../reference/privateNamesUnique-3.js | 25 +- .../reference/privateNamesUnique-4.js | 6 +- .../reference/privateNamesUnique-5.js | 10 +- .../privateNamesUseBeforeDef.errors.txt | 14 +- .../reference/privateNamesUseBeforeDef.js | 49 +- .../privateNamesUseBeforeDef.symbols | 38 +- .../reference/privateNamesUseBeforeDef.types | 27 + .../reference/privateStaticNameShadowing.js | 34 + .../privateStaticNameShadowing.symbols | 30 + .../privateStaticNameShadowing.types | 37 + .../privateWriteOnlyAccessorRead.errors.txt | 61 ++ .../reference/privateWriteOnlyAccessorRead.js | 88 ++ .../privateWriteOnlyAccessorRead.symbols | 119 +++ .../privateWriteOnlyAccessorRead.types | 160 +++ .../restPropertyWithBindingPattern.types | 10 +- .../reference/strictPropertyInitialization.js | 74 +- tests/cases/compiler/importHelpersES6.ts | 4 +- .../compiler/privateNameWeakMapCollision.ts | 1 + .../privateNames/privateNameAccessors.ts | 16 + .../privateNameAccessorsAccess.ts | 26 + .../privateNameAccessorsCallExpression.ts | 20 + .../privateNameAccessorssDerivedClasses.ts | 13 + .../members/privateNames/privateNameAndAny.ts | 10 +- .../privateNameAndObjectRestSpread.ts | 6 + .../privateNameAndPropertySignature.ts | 6 +- .../privateNames/privateNameBadDeclaration.ts | 8 +- .../privateNameClassExpressionLoop.ts | 3 + .../privateNames/privateNameDuplicateField.ts | 404 +++++++- .../privateNames/privateNameEmitHelpers.ts | 16 + .../privateNameInObjectLiteral-3.ts | 5 + .../privateNameJsBadDeclaration.ts | 8 +- .../members/privateNames/privateNameMethod.ts | 14 + .../privateNames/privateNameMethodAccess.ts | 24 + .../privateNameMethodAssignment.ts | 13 + .../privateNames/privateNameMethodAsync.ts | 15 + .../privateNameMethodCallExpression.ts | 25 + .../privateNameMethodClassExpression.ts | 13 + .../privateNameMethodInStaticFieldInit.ts | 8 + .../privateNameMethodsDerivedClasses.ts | 13 + ...rivateNameNestedClassAccessorsShadowing.ts | 16 + .../privateNameNestedClassMethodShadowing.ts | 16 + .../privateNameNestedMethodAccess.ts | 25 + .../privateNames/privateNameReadonly.ts | 10 + .../privateNameSetterExprReturnValue.ts | 11 + .../privateNames/privateNameSetterNoGetter.ts | 10 + .../privateNameStaticAccessors.ts | 16 + .../privateNameStaticAccessorsAccess.ts | 27 + ...rivateNameStaticAccessorsCallExpression.ts | 20 + ...ivateNameStaticAccessorssDerivedClasses.ts | 13 + .../privateNameStaticAndStaticInitializer.ts | 7 + .../privateNameStaticEmitHelpers.ts | 16 + .../privateNameStaticFieldAccess.ts | 9 + .../privateNameStaticFieldAssignment.ts | 36 + .../privateNameStaticFieldCallExpression.ts | 21 + .../privateNameStaticFieldClassExpression.ts | 23 + .../privateNameStaticFieldDerivedClasses.ts | 17 + ...ivateNameStaticFieldDestructuredBinding.ts | 25 + .../privateNameStaticFieldInitializer.ts | 6 + .../privateNameStaticFieldNoInitializer.ts | 9 + .../privateNameStaticFieldUnaryMutation.ts | 30 + .../privateNames/privateNameStaticMethod.ts | 14 + .../privateNameStaticMethodAssignment.ts | 13 + .../privateNameStaticMethodAsync.ts | 16 + .../privateNameStaticMethodCallExpression.ts | 25 + .../privateNameStaticMethodClassExpression.ts | 13 + ...rivateNameStaticMethodInStaticFieldInit.ts | 8 + .../privateNameStaticsAndStaticMethods.ts | 33 + .../members/privateNames/privateNameUnused.ts | 19 + .../privateNames/privateNamesAndkeyof.ts | 17 +- .../privateNames/privateNamesAssertion.ts | 12 + .../privateNamesInGenericClasses.ts | 14 + .../privateNamesIncompatibleModifiers.ts | 22 + .../privateNames/privateNamesUseBeforeDef.ts | 10 + .../privateStaticNameShadowing.ts | 15 + .../privateWriteOnlyAccessorRead.ts | 34 + ...ixSpellingPrivatePropertyNameNotInScope.ts | 15 + .../completionListPrivateNamesAccessors.ts | 37 + .../completionListPrivateNamesMethods.ts | 31 + .../findAllRefsPrivateNameAccessors.ts | 27 + .../findAllRefsPrivateNameMethods.ts | 24 + .../fourslash/goToDefinitionPrivateName.ts | 13 +- .../navigationBarPrivateNameMethod.ts | 109 ++ .../cases/fourslash/renamePrivateAccessor.ts | 14 + tests/cases/fourslash/renamePrivateMethod.ts | 13 + 370 files changed, 15654 insertions(+), 1223 deletions(-) create mode 100644 tests/baselines/reference/privateNameAccessors.errors.txt create mode 100644 tests/baselines/reference/privateNameAccessors.js create mode 100644 tests/baselines/reference/privateNameAccessors.symbols create mode 100644 tests/baselines/reference/privateNameAccessors.types create mode 100644 tests/baselines/reference/privateNameAccessorsAccess.errors.txt create mode 100644 tests/baselines/reference/privateNameAccessorsAccess.js create mode 100644 tests/baselines/reference/privateNameAccessorsAccess.symbols create mode 100644 tests/baselines/reference/privateNameAccessorsAccess.types create mode 100644 tests/baselines/reference/privateNameAccessorsCallExpression.js create mode 100644 tests/baselines/reference/privateNameAccessorsCallExpression.symbols create mode 100644 tests/baselines/reference/privateNameAccessorsCallExpression.types create mode 100644 tests/baselines/reference/privateNameAccessorssDerivedClasses.errors.txt create mode 100644 tests/baselines/reference/privateNameAccessorssDerivedClasses.js create mode 100644 tests/baselines/reference/privateNameAccessorssDerivedClasses.symbols create mode 100644 tests/baselines/reference/privateNameAccessorssDerivedClasses.types create mode 100644 tests/baselines/reference/privateNameEmitHelpers.errors.txt create mode 100644 tests/baselines/reference/privateNameEmitHelpers.js create mode 100644 tests/baselines/reference/privateNameEmitHelpers.symbols create mode 100644 tests/baselines/reference/privateNameEmitHelpers.types create mode 100644 tests/baselines/reference/privateNameInObjectLiteral-3.errors.txt create mode 100644 tests/baselines/reference/privateNameInObjectLiteral-3.js create mode 100644 tests/baselines/reference/privateNameInObjectLiteral-3.symbols create mode 100644 tests/baselines/reference/privateNameInObjectLiteral-3.types create mode 100644 tests/baselines/reference/privateNameMethod.errors.txt create mode 100644 tests/baselines/reference/privateNameMethod.js create mode 100644 tests/baselines/reference/privateNameMethod.symbols create mode 100644 tests/baselines/reference/privateNameMethod.types create mode 100644 tests/baselines/reference/privateNameMethodAccess.errors.txt create mode 100644 tests/baselines/reference/privateNameMethodAccess.js create mode 100644 tests/baselines/reference/privateNameMethodAccess.symbols create mode 100644 tests/baselines/reference/privateNameMethodAccess.types create mode 100644 tests/baselines/reference/privateNameMethodAssignment.errors.txt create mode 100644 tests/baselines/reference/privateNameMethodAssignment.js create mode 100644 tests/baselines/reference/privateNameMethodAssignment.symbols create mode 100644 tests/baselines/reference/privateNameMethodAssignment.types create mode 100644 tests/baselines/reference/privateNameMethodAsync.js create mode 100644 tests/baselines/reference/privateNameMethodAsync.symbols create mode 100644 tests/baselines/reference/privateNameMethodAsync.types create mode 100644 tests/baselines/reference/privateNameMethodCallExpression.js create mode 100644 tests/baselines/reference/privateNameMethodCallExpression.symbols create mode 100644 tests/baselines/reference/privateNameMethodCallExpression.types create mode 100644 tests/baselines/reference/privateNameMethodClassExpression.errors.txt create mode 100644 tests/baselines/reference/privateNameMethodClassExpression.js create mode 100644 tests/baselines/reference/privateNameMethodClassExpression.symbols create mode 100644 tests/baselines/reference/privateNameMethodClassExpression.types create mode 100644 tests/baselines/reference/privateNameMethodInStaticFieldInit.js create mode 100644 tests/baselines/reference/privateNameMethodInStaticFieldInit.symbols create mode 100644 tests/baselines/reference/privateNameMethodInStaticFieldInit.types create mode 100644 tests/baselines/reference/privateNameMethodsDerivedClasses.errors.txt create mode 100644 tests/baselines/reference/privateNameMethodsDerivedClasses.js create mode 100644 tests/baselines/reference/privateNameMethodsDerivedClasses.symbols create mode 100644 tests/baselines/reference/privateNameMethodsDerivedClasses.types create mode 100644 tests/baselines/reference/privateNameNestedClassAccessorsShadowing.errors.txt create mode 100644 tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js create mode 100644 tests/baselines/reference/privateNameNestedClassAccessorsShadowing.symbols create mode 100644 tests/baselines/reference/privateNameNestedClassAccessorsShadowing.types create mode 100644 tests/baselines/reference/privateNameNestedClassMethodShadowing.errors.txt create mode 100644 tests/baselines/reference/privateNameNestedClassMethodShadowing.js create mode 100644 tests/baselines/reference/privateNameNestedClassMethodShadowing.symbols create mode 100644 tests/baselines/reference/privateNameNestedClassMethodShadowing.types create mode 100644 tests/baselines/reference/privateNameNestedMethodAccess.errors.txt create mode 100644 tests/baselines/reference/privateNameNestedMethodAccess.js create mode 100644 tests/baselines/reference/privateNameNestedMethodAccess.symbols create mode 100644 tests/baselines/reference/privateNameNestedMethodAccess.types create mode 100644 tests/baselines/reference/privateNameReadonly.errors.txt create mode 100644 tests/baselines/reference/privateNameReadonly.js create mode 100644 tests/baselines/reference/privateNameReadonly.symbols create mode 100644 tests/baselines/reference/privateNameReadonly.types create mode 100644 tests/baselines/reference/privateNameSetterExprReturnValue.js create mode 100644 tests/baselines/reference/privateNameSetterExprReturnValue.symbols create mode 100644 tests/baselines/reference/privateNameSetterExprReturnValue.types create mode 100644 tests/baselines/reference/privateNameSetterNoGetter.errors.txt create mode 100644 tests/baselines/reference/privateNameSetterNoGetter.js create mode 100644 tests/baselines/reference/privateNameSetterNoGetter.symbols create mode 100644 tests/baselines/reference/privateNameSetterNoGetter.types create mode 100644 tests/baselines/reference/privateNameStaticAccessors.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticAccessors.js create mode 100644 tests/baselines/reference/privateNameStaticAccessors.symbols create mode 100644 tests/baselines/reference/privateNameStaticAccessors.types create mode 100644 tests/baselines/reference/privateNameStaticAccessorsAccess.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticAccessorsAccess.js create mode 100644 tests/baselines/reference/privateNameStaticAccessorsAccess.symbols create mode 100644 tests/baselines/reference/privateNameStaticAccessorsAccess.types create mode 100644 tests/baselines/reference/privateNameStaticAccessorsCallExpression.js create mode 100644 tests/baselines/reference/privateNameStaticAccessorsCallExpression.symbols create mode 100644 tests/baselines/reference/privateNameStaticAccessorsCallExpression.types create mode 100644 tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.js create mode 100644 tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.symbols create mode 100644 tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.types create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).js create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).symbols create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).types create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).errors.txt create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).js create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).symbols create mode 100644 tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).types create mode 100644 tests/baselines/reference/privateNameStaticEmitHelpers.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticEmitHelpers.js create mode 100644 tests/baselines/reference/privateNameStaticEmitHelpers.symbols create mode 100644 tests/baselines/reference/privateNameStaticEmitHelpers.types create mode 100644 tests/baselines/reference/privateNameStaticFieldAccess.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticFieldAccess.js create mode 100644 tests/baselines/reference/privateNameStaticFieldAccess.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldAccess.types create mode 100644 tests/baselines/reference/privateNameStaticFieldAssignment.js create mode 100644 tests/baselines/reference/privateNameStaticFieldAssignment.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldAssignment.types create mode 100644 tests/baselines/reference/privateNameStaticFieldCallExpression.js create mode 100644 tests/baselines/reference/privateNameStaticFieldCallExpression.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldCallExpression.types create mode 100644 tests/baselines/reference/privateNameStaticFieldClassExpression.js create mode 100644 tests/baselines/reference/privateNameStaticFieldClassExpression.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldClassExpression.types create mode 100644 tests/baselines/reference/privateNameStaticFieldDerivedClasses.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticFieldDerivedClasses.js create mode 100644 tests/baselines/reference/privateNameStaticFieldDerivedClasses.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldDerivedClasses.types create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).types create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).errors.txt create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).types create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).js create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).types create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).errors.txt create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).js create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).types create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer.js create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldInitializer.types create mode 100644 tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).js create mode 100644 tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).types create mode 100644 tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).js create mode 100644 tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).types create mode 100644 tests/baselines/reference/privateNameStaticFieldUnaryMutation.js create mode 100644 tests/baselines/reference/privateNameStaticFieldUnaryMutation.symbols create mode 100644 tests/baselines/reference/privateNameStaticFieldUnaryMutation.types create mode 100644 tests/baselines/reference/privateNameStaticMethod.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticMethod.js create mode 100644 tests/baselines/reference/privateNameStaticMethod.symbols create mode 100644 tests/baselines/reference/privateNameStaticMethod.types create mode 100644 tests/baselines/reference/privateNameStaticMethodAssignment.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticMethodAssignment.js create mode 100644 tests/baselines/reference/privateNameStaticMethodAssignment.symbols create mode 100644 tests/baselines/reference/privateNameStaticMethodAssignment.types create mode 100644 tests/baselines/reference/privateNameStaticMethodAsync.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticMethodAsync.js create mode 100644 tests/baselines/reference/privateNameStaticMethodAsync.symbols create mode 100644 tests/baselines/reference/privateNameStaticMethodAsync.types create mode 100644 tests/baselines/reference/privateNameStaticMethodCallExpression.js create mode 100644 tests/baselines/reference/privateNameStaticMethodCallExpression.symbols create mode 100644 tests/baselines/reference/privateNameStaticMethodCallExpression.types create mode 100644 tests/baselines/reference/privateNameStaticMethodClassExpression.errors.txt create mode 100644 tests/baselines/reference/privateNameStaticMethodClassExpression.js create mode 100644 tests/baselines/reference/privateNameStaticMethodClassExpression.symbols create mode 100644 tests/baselines/reference/privateNameStaticMethodClassExpression.types create mode 100644 tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.js create mode 100644 tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.symbols create mode 100644 tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.types create mode 100644 tests/baselines/reference/privateNameStaticsAndStaticMethods.js create mode 100644 tests/baselines/reference/privateNameStaticsAndStaticMethods.symbols create mode 100644 tests/baselines/reference/privateNameStaticsAndStaticMethods.types delete mode 100644 tests/baselines/reference/privateNamesAndMethods.errors.txt delete mode 100644 tests/baselines/reference/privateNamesAndStaticMethods.errors.txt create mode 100644 tests/baselines/reference/privateNamesAndkeyof.errors.txt create mode 100644 tests/baselines/reference/privateStaticNameShadowing.js create mode 100644 tests/baselines/reference/privateStaticNameShadowing.symbols create mode 100644 tests/baselines/reference/privateStaticNameShadowing.types create mode 100644 tests/baselines/reference/privateWriteOnlyAccessorRead.errors.txt create mode 100644 tests/baselines/reference/privateWriteOnlyAccessorRead.js create mode 100644 tests/baselines/reference/privateWriteOnlyAccessorRead.symbols create mode 100644 tests/baselines/reference/privateWriteOnlyAccessorRead.types create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameAccessorsCallExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameEmitHelpers.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodAsync.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodCallExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodInStaticFieldInit.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameSetterExprReturnValue.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsCallExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticEmitHelpers.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAssignment.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldCallExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldClassExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldUnaryMutation.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodCallExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodInStaticFieldInit.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateNameStaticsAndStaticMethods.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateStaticNameShadowing.ts create mode 100644 tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts create mode 100644 tests/cases/fourslash/codeFixSpellingPrivatePropertyNameNotInScope.ts create mode 100644 tests/cases/fourslash/completionListPrivateNamesAccessors.ts create mode 100644 tests/cases/fourslash/completionListPrivateNamesMethods.ts create mode 100644 tests/cases/fourslash/findAllRefsPrivateNameAccessors.ts create mode 100644 tests/cases/fourslash/findAllRefsPrivateNameMethods.ts create mode 100644 tests/cases/fourslash/navigationBarPrivateNameMethod.ts create mode 100644 tests/cases/fourslash/renamePrivateAccessor.ts create mode 100644 tests/cases/fourslash/renamePrivateMethod.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a98fd289a390..8daacfbaffefb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -240,6 +240,7 @@ namespace ts { SetAccessor = 2, PropertyAssignment = 4, Method = 8, + PrivateStatic = 16, GetOrSetAccessor = GetAccessor | SetAccessor, PropertyAssignmentOrMethod = PropertyAssignment | Method, } @@ -958,7 +959,7 @@ namespace ts { const flowNodePostSuper: (boolean | undefined)[] = []; const potentialThisCollisions: Node[] = []; const potentialNewTargetCollisions: Node[] = []; - const potentialWeakMapCollisions: Node[] = []; + const potentialWeakMapSetCollisions: Node[] = []; const awaitedTypeStack: number[] = []; const diagnostics = createDiagnosticCollection(); @@ -9968,7 +9969,7 @@ namespace ts { } function isStaticPrivateIdentifierProperty(s: Symbol): boolean { - return !!s.valueDeclaration && isPrivateIdentifierPropertyDeclaration(s.valueDeclaration) && hasSyntacticModifier(s.valueDeclaration, ModifierFlags.Static); + return !!s.valueDeclaration && isPrivateIdentifierClassElementDeclaration(s.valueDeclaration) && hasSyntacticModifier(s.valueDeclaration, ModifierFlags.Static); } function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers { @@ -15227,7 +15228,7 @@ namespace ts { /** We approximate own properties as non-methods plus methods that are inside the object literal */ function isSpreadableProperty(prop: Symbol): boolean { - return !some(prop.declarations, isPrivateIdentifierPropertyDeclaration) && + return !some(prop.declarations, isPrivateIdentifierClassElementDeclaration) && (!(prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor | SymbolFlags.SetAccessor)) || !prop.declarations?.some(decl => isClassLike(decl.parent))); } @@ -26550,7 +26551,7 @@ namespace ts { */ function checkPropertyAccessibility( node: PropertyAccessExpression | QualifiedName | PropertyAccessExpression | VariableDeclaration | ParameterDeclaration | ImportTypeNode | PropertyAssignment | ShorthandPropertyAssignment | BindingElement, - isSuper: boolean, type: Type, prop: Symbol): boolean { + isSuper: boolean, type: Type, prop: Symbol, reportError = true): boolean { const flags = getDeclarationModifierFlagsFromSymbol(prop); const errorNode = node.kind === SyntaxKind.QualifiedName ? node.right : node.kind === SyntaxKind.ImportType ? node : @@ -26566,7 +26567,9 @@ namespace ts { // a super property access is permitted and must specify a public static member function of the base class. if (languageVersion < ScriptTarget.ES2015) { if (symbolHasNonMethodDeclaration(prop)) { - error(errorNode, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + if (reportError) { + error(errorNode, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + } return false; } } @@ -26575,7 +26578,9 @@ namespace ts { // This error could mask a private property access error. But, a member // cannot simultaneously be private and abstract, so this will trigger an // additional error elsewhere. - error(errorNode, Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression, symbolToString(prop), typeToString(getDeclaringClass(prop)!)); + if (reportError) { + error(errorNode, Diagnostics.Abstract_method_0_in_class_1_cannot_be_accessed_via_super_expression, symbolToString(prop), typeToString(getDeclaringClass(prop)!)); + } return false; } } @@ -26585,17 +26590,11 @@ namespace ts { (isThisProperty(node) || isThisInitializedObjectBindingExpression(node) || isObjectBindingPattern(node.parent) && isThisInitializedDeclaration(node.parent.parent))) { const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop)!); if (declaringClassDeclaration && isNodeUsedDuringClassInitialization(node)) { - error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), getTextOfIdentifierOrLiteral(declaringClassDeclaration.name!)); // TODO: GH#18217 - return false; - } - } - - if (isPropertyAccessExpression(node) && isPrivateIdentifier(node.name)) { - if (!getContainingClass(node)) { - error(errorNode, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); + if (reportError) { + error(errorNode, Diagnostics.Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor, symbolToString(prop), getTextOfIdentifierOrLiteral(declaringClassDeclaration.name!)); // TODO: GH#18217 + } return false; } - return true; } // Public properties are otherwise accessible. @@ -26609,7 +26608,9 @@ namespace ts { if (flags & ModifierFlags.Private) { const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(getParentOfSymbol(prop)!)!; if (!isNodeWithinClass(node, declaringClassDeclaration)) { - error(errorNode, Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(getDeclaringClass(prop)!)); + if (reportError) { + error(errorNode, Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(getDeclaringClass(prop)!)); + } return false; } return true; @@ -26634,7 +26635,9 @@ namespace ts { // static member access is disallow let thisParameter: ParameterDeclaration | undefined; if (flags & ModifierFlags.Static || !(thisParameter = getThisParameterFromNodeContext(node)) || !thisParameter.type) { - error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(getDeclaringClass(prop) || type)); + if (reportError) { + error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(getDeclaringClass(prop) || type)); + } return false; } @@ -26650,7 +26653,9 @@ namespace ts { type = (type as TypeParameter).isThisType ? getConstraintOfTypeParameter(type)! : getBaseConstraintOfType(type)!; // TODO: GH#18217 Use a different variable that's allowed to be undefined } if (!type || !hasBaseType(type, enclosingClass)) { - error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1_This_is_an_instance_of_class_2, symbolToString(prop), typeToString(enclosingClass), typeToString(type)); + if (reportError) { + error(errorNode, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1_This_is_an_instance_of_class_2, symbolToString(prop), typeToString(enclosingClass), typeToString(type)); + } return false; } return true; @@ -26831,13 +26836,22 @@ namespace ts { const parentSymbol = getNodeLinks(left).resolvedSymbol; const assignmentKind = getAssignmentTargetKind(node); const apparentType = getApparentType(assignmentKind !== AssignmentKind.None || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); - if (isPrivateIdentifier(right)) { - checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldGet); - } const isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; let prop: Symbol | undefined; if (isPrivateIdentifier(right)) { + if (languageVersion < ScriptTarget.ESNext) { + if (assignmentKind !== AssignmentKind.None) { + checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldSet); + } + if (assignmentKind !== AssignmentKind.Definite) { + checkExternalEmitHelpers(node, ExternalEmitHelpers.ClassPrivateFieldGet); + } + } + const lexicallyScopedSymbol = lookupSymbolForPrivateIdentifierDeclaration(right.escapedText, right); + if (assignmentKind && lexicallyScopedSymbol && lexicallyScopedSymbol.valueDeclaration && isMethodDeclaration(lexicallyScopedSymbol.valueDeclaration)) { + grammarErrorOnNode(right, Diagnostics.Cannot_assign_to_private_method_0_Private_methods_are_not_writable, idText(right)); + } if (isAnyLike) { if (lexicallyScopedSymbol) { return apparentType; @@ -26852,6 +26866,12 @@ namespace ts { if (!prop && checkPrivateIdentifierPropertyAccess(leftType, right, lexicallyScopedSymbol)) { return errorType; } + else { + const isSetonlyAccessor = prop && prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor); + if (isSetonlyAccessor && assignmentKind !== AssignmentKind.Definite) { + error(node, Diagnostics.Private_accessor_was_defined_without_a_getter); + } + } } else { if (isAnyLike) { @@ -27125,7 +27145,15 @@ namespace ts { } function getSuggestedSymbolForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type): Symbol | undefined { - return getSpellingSuggestionForName(isString(name) ? name : idText(name), getPropertiesOfType(containingType), SymbolFlags.Value); + let props = getPropertiesOfType(containingType); + if (typeof name !== "string") { + const parent = name.parent; + if (isPropertyAccessExpression(parent)) { + props = filter(props, prop => isValidPropertyAccessForCompletions(parent, containingType, prop)); + } + name = idText(name); + } + return getSpellingSuggestionForName(name, props, SymbolFlags.Value); } function getSuggestedSymbolForNonexistentJSXAttribute(name: Identifier | PrivateIdentifier | string, containingType: Type): Symbol | undefined { @@ -27291,11 +27319,11 @@ namespace ts { } const prop = getPropertyOfType(type, propertyName); if (prop) { - if (isPropertyAccessExpression(node) && prop.valueDeclaration && isPrivateIdentifierPropertyDeclaration(prop.valueDeclaration)) { + if (prop.valueDeclaration && isPrivateIdentifierClassElementDeclaration(prop.valueDeclaration)) { const declClass = getContainingClass(prop.valueDeclaration); return !isOptionalChain(node) && !!findAncestor(node, parent => parent === declClass); } - return checkPropertyAccessibility(node, isSuper, type, prop); + return checkPropertyAccessibility(node, isSuper, type, prop, /* reportError */ false); } // In js files properties of unions are allowed in completion return isInJSFile(node) && (type.flags & TypeFlags.Union) !== 0 && (type).types.some(elementType => isValidPropertyAccessWithType(node, isSuper, propertyName, elementType)); @@ -32612,29 +32640,32 @@ namespace ts { const isStatic = hasSyntacticModifier(member, ModifierFlags.Static); const name = member.name; if (!name) { - return; + continue; } + const isPrivate = isPrivateIdentifier(name); + const privateStaticFlags = isPrivate && isStatic ? DeclarationMeaning.PrivateStatic : 0; const names = - isPrivateIdentifier(name) ? privateIdentifiers : + isPrivate ? privateIdentifiers : isStatic ? staticNames : instanceNames; + const memberName = name && getPropertyNameForPropertyNameNode(name); if (memberName) { switch (member.kind) { case SyntaxKind.GetAccessor: - addName(names, name, memberName, DeclarationMeaning.GetAccessor); + addName(names, name, memberName, DeclarationMeaning.GetAccessor | privateStaticFlags); break; case SyntaxKind.SetAccessor: - addName(names, name, memberName, DeclarationMeaning.SetAccessor); + addName(names, name, memberName, DeclarationMeaning.SetAccessor | privateStaticFlags); break; case SyntaxKind.PropertyDeclaration: - addName(names, name, memberName, DeclarationMeaning.GetOrSetAccessor); + addName(names, name, memberName, DeclarationMeaning.GetOrSetAccessor | privateStaticFlags); break; case SyntaxKind.MethodDeclaration: - addName(names, name, memberName, DeclarationMeaning.Method); + addName(names, name, memberName, DeclarationMeaning.Method | privateStaticFlags); break; } } @@ -32644,16 +32675,25 @@ namespace ts { function addName(names: UnderscoreEscapedMap, location: Node, name: __String, meaning: DeclarationMeaning) { const prev = names.get(name); if (prev) { - if (prev & DeclarationMeaning.Method) { - if (meaning !== DeclarationMeaning.Method) { - error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); - } - } - else if (prev & meaning) { - error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); + // For private identifiers, do not allow mixing of static and instance members with the same name + if ((prev & DeclarationMeaning.PrivateStatic) !== (meaning & DeclarationMeaning.PrivateStatic)) { + error(location, Diagnostics.Duplicate_identifier_0_Static_and_instance_elements_cannot_share_the_same_private_name, getTextOfNode(location)); } else { - names.set(name, prev | meaning); + const prevIsMethod = !!(prev & DeclarationMeaning.Method); + const isMethod = !!(meaning & DeclarationMeaning.Method); + if (prevIsMethod || isMethod) { + if (prevIsMethod !== isMethod) { + error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); + } + // If this is a method/method duplication is might be an overload, so this will be handled when overloads are considered + } + else if (prev & meaning & ~DeclarationMeaning.PrivateStatic) { + error(location, Diagnostics.Duplicate_identifier_0, getTextOfNode(location)); + } + else { + names.set(name, prev | meaning); + } } } else { @@ -32771,21 +32811,9 @@ namespace ts { if (!checkGrammarDecoratorsAndModifiers(node) && !checkGrammarProperty(node)) checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); - // Private class fields transformation relies on WeakMaps. - if (isPrivateIdentifier(node.name) && languageVersion < ScriptTarget.ESNext) { - for (let lexicalScope = getEnclosingBlockScopeContainer(node); !!lexicalScope; lexicalScope = getEnclosingBlockScopeContainer(lexicalScope)) { - getNodeLinks(lexicalScope).flags |= NodeCheckFlags.ContainsClassWithPrivateIdentifiers; - } - - // If this is a private field in a class expression inside the body of a loop, - // then we must use a block-scoped binding to store the WeakMap. - if (isClassExpression(node.parent)) { - const enclosingIterationStatement = getEnclosingIterationStatement(node.parent); - if (enclosingIterationStatement) { - getNodeLinks(node.name).flags |= NodeCheckFlags.BlockScopedBindingInLoop; - getNodeLinks(enclosingIterationStatement).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding; - } - } + setNodeLinksForPrivateIdentifierScope(node); + if (isPrivateIdentifier(node.name) && hasStaticModifier(node) && node.initializer && languageVersion === ScriptTarget.ESNext && !compilerOptions.useDefineForClassFields) { + error(node.initializer, Diagnostics.Static_fields_with_private_names_can_t_have_initializers_when_the_useDefineForClassFields_flag_is_not_specified_with_a_target_of_esnext_Consider_adding_the_useDefineForClassFields_flag); } } @@ -32800,10 +32828,6 @@ namespace ts { // Grammar checking if (!checkGrammarMethod(node)) checkGrammarComputedPropertyName(node.name); - if (isPrivateIdentifier(node.name)) { - error(node, Diagnostics.A_method_cannot_be_named_with_a_private_identifier); - } - // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionOrMethodDeclaration(node); @@ -32812,6 +32836,32 @@ namespace ts { if (hasSyntacticModifier(node, ModifierFlags.Abstract) && node.kind === SyntaxKind.MethodDeclaration && node.body) { error(node, Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, declarationNameToString(node.name)); } + + // Private named methods are only allowed in class declarations + if (isPrivateIdentifier(node.name) && !getContainingClass(node)) { + error(node, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); + } + + setNodeLinksForPrivateIdentifierScope(node); + } + + function setNodeLinksForPrivateIdentifierScope(node: PropertyDeclaration | PropertySignature | MethodDeclaration | MethodSignature | AccessorDeclaration) { + if (isPrivateIdentifier(node.name) && languageVersion < ScriptTarget.ESNext) { + for (let lexicalScope = getEnclosingBlockScopeContainer(node); !!lexicalScope; lexicalScope = getEnclosingBlockScopeContainer(lexicalScope)) { + getNodeLinks(lexicalScope).flags |= NodeCheckFlags.ContainsClassWithPrivateIdentifiers; + } + + // If this is a private element in a class expression inside the body of a loop, + // then we must use a block-scoped binding to store the additional variables required + // to transform private elements. + if (isClassExpression(node.parent)) { + const enclosingIterationStatement = getEnclosingIterationStatement(node.parent); + if (enclosingIterationStatement) { + getNodeLinks(node.name).flags |= NodeCheckFlags.BlockScopedBindingInLoop; + getNodeLinks(enclosingIterationStatement).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding; + } + } + } } function checkConstructorDeclaration(node: ConstructorDeclaration) { @@ -32840,7 +32890,7 @@ namespace ts { } function isInstancePropertyWithInitializerOrPrivateIdentifierProperty(n: Node): boolean { - if (isPrivateIdentifierPropertyDeclaration(n)) { + if (isPrivateIdentifierClassElementDeclaration(n)) { return true; } return n.kind === SyntaxKind.PropertyDeclaration && @@ -32917,9 +32967,7 @@ namespace ts { if (node.name.kind === SyntaxKind.ComputedPropertyName) { checkComputedPropertyName(node.name); } - if (isPrivateIdentifier(node.name)) { - error(node.name, Diagnostics.An_accessor_cannot_be_named_with_a_private_identifier); - } + if (hasBindableName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. @@ -32947,6 +32995,7 @@ namespace ts { } } checkSourceElement(node.body); + setNodeLinksForPrivateIdentifierScope(node); } function checkAccessorDeclarationTypesIdentical(first: AccessorDeclaration, second: AccessorDeclaration, getAnnotatedType: (a: AccessorDeclaration) => Type | undefined, message: DiagnosticMessage) { @@ -33214,7 +33263,7 @@ namespace ts { } function isPrivateWithinAmbient(node: Node): boolean { - return (hasEffectiveModifier(node, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(node)) && !!(node.flags & NodeFlags.Ambient); + return (hasEffectiveModifier(node, ModifierFlags.Private) || isPrivateIdentifierClassElementDeclaration(node)) && !!(node.flags & NodeFlags.Ambient); } function getEffectiveDeclarationFlags(n: Declaration, flagsToCheck: ModifierFlags): ModifierFlags { @@ -34705,10 +34754,11 @@ namespace ts { }); } - function checkWeakMapCollision(node: Node) { + function checkWeakMapSetCollision(node: Node) { const enclosingBlockScope = getEnclosingBlockScopeContainer(node); if (getNodeCheckFlags(enclosingBlockScope) & NodeCheckFlags.ContainsClassWithPrivateIdentifiers) { - errorSkippedOn("noEmit", node, Diagnostics.Compiler_reserves_name_0_when_emitting_private_identifier_downlevel, "WeakMap"); + Debug.assert(isNamedDeclaration(node) && isIdentifier(node.name) && typeof node.name.escapedText === "string", "The target of a WeakMap/WeakSet collision check should be an identifier"); + errorSkippedOn("noEmit", node, Diagnostics.Compiler_reserves_name_0_when_emitting_private_identifier_downlevel, node.name.escapedText); } } @@ -34974,8 +35024,9 @@ namespace ts { } checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); - if (languageVersion < ScriptTarget.ESNext && needCollisionCheckForIdentifier(node, node.name, "WeakMap")) { - potentialWeakMapCollisions.push(node); + if (languageVersion < ScriptTarget.ESNext + && (needCollisionCheckForIdentifier(node, node.name, "WeakMap") || needCollisionCheckForIdentifier(node, node.name, "WeakSet"))) { + potentialWeakMapSetCollisions.push(node); } } } @@ -36536,6 +36587,9 @@ namespace ts { } function checkClassDeclaration(node: ClassDeclaration) { + if (some(node.decorators) && some(node.members, p => hasStaticModifier(p) && isPrivateIdentifierClassElementDeclaration(p))) { + grammarErrorOnNode(node.decorators[0], Diagnostics.Class_decorators_can_t_be_used_with_static_private_identifier_Consider_removing_the_experimental_decorator); + } if (!node.name && !hasSyntacticModifier(node, ModifierFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } @@ -38225,7 +38279,7 @@ namespace ts { clear(potentialThisCollisions); clear(potentialNewTargetCollisions); - clear(potentialWeakMapCollisions); + clear(potentialWeakMapSetCollisions); forEach(node.statements, checkSourceElement); checkSourceElement(node.endOfFileToken); @@ -38265,9 +38319,9 @@ namespace ts { clear(potentialNewTargetCollisions); } - if (potentialWeakMapCollisions.length) { - forEach(potentialWeakMapCollisions, checkWeakMapCollision); - clear(potentialWeakMapCollisions); + if (potentialWeakMapSetCollisions.length) { + forEach(potentialWeakMapSetCollisions, checkWeakMapSetCollision); + clear(potentialWeakMapSetCollisions); } links.flags |= NodeCheckFlags.TypeChecked; @@ -39954,6 +40008,16 @@ namespace ts { if (!symbol) { error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_which_does_not_exist_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name); } + else if (helper & ExternalEmitHelpers.ClassPrivateFieldGet) { + if (!some(getSignaturesOfSymbol(symbol), signature => getParameterCount(signature) > 3)) { + error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name, 4); + } + } + else if (helper & ExternalEmitHelpers.ClassPrivateFieldSet) { + if (!some(getSignaturesOfSymbol(symbol), signature => getParameterCount(signature) > 4)) { + error(location, Diagnostics.This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0, externalHelpersModuleNameText, name, 5); + } + } } } } @@ -40074,7 +40138,7 @@ namespace ts { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "abstract"); } } - else if (isPrivateIdentifierPropertyDeclaration(node)) { + else if (isPrivateIdentifierClassElementDeclaration(node)) { return grammarErrorOnNode(modifier, Diagnostics.An_accessibility_modifier_cannot_be_used_with_a_private_identifier); } flags |= modifierToFlag(modifier.kind); @@ -40099,9 +40163,6 @@ namespace ts { else if (flags & ModifierFlags.Abstract) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract"); } - else if (isPrivateIdentifierPropertyDeclaration(node)) { - return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_a_private_identifier, "static"); - } flags |= ModifierFlags.Static; lastStatic = modifier; break; @@ -40163,7 +40224,7 @@ namespace ts { else if ((node.parent.flags & NodeFlags.Ambient) && node.parent.kind === SyntaxKind.ModuleBlock) { return grammarErrorOnNode(modifier, Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } - else if (isPrivateIdentifierPropertyDeclaration(node)) { + else if (isPrivateIdentifierClassElementDeclaration(node)) { return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_a_private_identifier, "declare"); } flags |= ModifierFlags.Ambient; @@ -40654,7 +40715,7 @@ namespace ts { } if (name.kind === SyntaxKind.PrivateIdentifier) { - return grammarErrorOnNode(name, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); + grammarErrorOnNode(name, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies); } // Modifiers are never allowed on properties except for 'async' on a method declaration @@ -40869,6 +40930,9 @@ namespace ts { if (languageVersion < ScriptTarget.ES5) { return grammarErrorOnNode(accessor.name, Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher); } + if (languageVersion < ScriptTarget.ES2015 && isPrivateIdentifier(accessor.name)) { + return grammarErrorOnNode(accessor.name, Diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher); + } if (accessor.body === undefined && !hasSyntacticModifier(accessor, ModifierFlags.Abstract)) { return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{"); } @@ -41002,6 +41066,9 @@ namespace ts { } if (isClassLike(node.parent)) { + if (languageVersion < ScriptTarget.ES2015 && isPrivateIdentifier(node.name)) { + return grammarErrorOnNode(node.name, Diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher); + } // Technically, computed properties in ambient contexts is disallowed // for property declarations and accessors too, not just methods. // However, property declarations disallow computed names in general, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ae8fe1998fb4a..e204c9ee09720 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3288,6 +3288,26 @@ "category": "Error", "code": 2802 }, + "Cannot assign to private method '{0}'. Private methods are not writable.": { + "category": "Error", + "code": 2803 + }, + "Duplicate identifier '{0}'. Static and instance elements cannot share the same private name.": { + "category": "Error", + "code": 2804 + }, + "Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag.": { + "category": "Error", + "code": 2805 + }, + "Private accessor was defined without a getter.": { + "category": "Error", + "code": 2806 + }, + "This syntax requires an imported helper named '{1}' with {2} parameters, which is not compatible with the one in '{0}'. Consider upgrading your version of '{0}'.": { + "category": "Error", + "code": 2807 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -6338,14 +6358,6 @@ "category": "Error", "code": 18019 }, - "A method cannot be named with a private identifier.": { - "category": "Error", - "code": 18022 - }, - "An accessor cannot be named with a private identifier.": { - "category": "Error", - "code": 18023 - }, "An enum member cannot be named with a private identifier.": { "category": "Error", "code": 18024 @@ -6389,5 +6401,9 @@ "Invalid value for 'jsxFragmentFactory'. '{0}' is not a valid identifier or qualified-name.": { "category": "Error", "code": 18035 + }, + "Class decorators can't be used with static private identifier. Consider removing the experimental decorator.": { + "category": "Error", + "code": 18036 } } diff --git a/src/compiler/factory/emitHelpers.ts b/src/compiler/factory/emitHelpers.ts index 4333272616da6..f3e0004efd407 100644 --- a/src/compiler/factory/emitHelpers.ts +++ b/src/compiler/factory/emitHelpers.ts @@ -32,8 +32,8 @@ namespace ts { createImportDefaultHelper(expression: Expression): Expression; createExportStarHelper(moduleExpression: Expression, exportsExpression?: Expression): Expression; // Class Fields Helpers - createClassPrivateFieldGetHelper(receiver: Expression, privateField: Identifier): Expression; - createClassPrivateFieldSetHelper(receiver: Expression, privateField: Identifier, value: Expression): Expression; + createClassPrivateFieldGetHelper(receiver: Expression, state: Identifier, kind: PrivateIdentifierKind, f: Identifier | undefined): Expression; + createClassPrivateFieldSetHelper(receiver: Expression, state: Identifier, value: Expression, kind: PrivateIdentifierKind, f: Identifier | undefined): Expression; } export function createEmitHelperFactory(context: TransformationContext): EmitHelperFactory { @@ -368,15 +368,30 @@ namespace ts { // Class Fields Helpers - function createClassPrivateFieldGetHelper(receiver: Expression, privateField: Identifier) { + function createClassPrivateFieldGetHelper(receiver: Expression, state: Identifier, kind: PrivateIdentifierKind, f: Identifier | undefined) { context.requestEmitHelper(classPrivateFieldGetHelper); - return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldGet"), /*typeArguments*/ undefined, [receiver, privateField]); + let args; + if (!f) { + args = [receiver, state, factory.createStringLiteral(kind)]; + } + else { + args = [receiver, state, factory.createStringLiteral(kind), f]; + } + return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldGet"), /*typeArguments*/ undefined, args); } - function createClassPrivateFieldSetHelper(receiver: Expression, privateField: Identifier, value: Expression) { + function createClassPrivateFieldSetHelper(receiver: Expression, state: Identifier, value: Expression, kind: PrivateIdentifierKind, f: Identifier | undefined) { context.requestEmitHelper(classPrivateFieldSetHelper); - return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldSet"), /*typeArguments*/ undefined, [receiver, privateField, value]); + let args; + if (!f) { + args = [receiver, state, value, factory.createStringLiteral(kind)]; + } + else { + args = [receiver, state, value, factory.createStringLiteral(kind), f]; + } + return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldSet"), /*typeArguments*/ undefined, args); } + } /* @internal */ @@ -803,7 +818,6 @@ namespace ts { };` }; - // emit output for the __export helper function export const exportStarHelper: UnscopedEmitHelper = { name: "typescript:export-star", importName: "__exportStar", @@ -816,31 +830,127 @@ namespace ts { };` }; - // Class fields helpers + /** + * Parameters: + * @param receiver — The object from which the private member will be read. + * @param state — One of the following: + * - A WeakMap used to read a private instance field. + * - A WeakSet used as an instance brand for private instance methods and accessors. + * - A function value that should be the undecorated class constructor used to brand check private static fields, methods, and accessors. + * @param kind — (optional pre TS 4.3, required for TS 4.3+) One of the following values: + * - undefined — Indicates a private instance field (pre TS 4.3). + * - "f" — Indicates a private field (instance or static). + * - "m" — Indicates a private method (instance or static). + * - "a" — Indicates a private accessor (instance or static). + * @param f — (optional pre TS 4.3) Depends on the arguments for state and kind: + * - If kind is "m", this should be the function corresponding to the static or instance method. + * - If kind is "a", this should be the function corresponding to the getter method, or undefined if the getter was not defined. + * - If kind is "f" and state is a function, this should be an object holding the value of a static field, or undefined if the static field declaration has not yet been evaluated. + * Usage: + * This helper will only ever be used by the compiler in the following ways: + * + * Reading from a private instance field (pre TS 4.3): + * __classPrivateFieldGet(, ) + * + * Reading from a private instance field (TS 4.3+): + * __classPrivateFieldGet(, , "f") + * + * Reading from a private instance get accessor (when defined, TS 4.3+): + * __classPrivateFieldGet(, , "a", ) + * + * Reading from a private instance get accessor (when not defined, TS 4.3+): + * __classPrivateFieldGet(, , "a", void 0) + * NOTE: This always results in a runtime error. + * + * Reading from a private instance method (TS 4.3+): + * __classPrivateFieldGet(, , "m", ) + * + * Reading from a private static field (TS 4.3+): + * __classPrivateFieldGet(, , "f", <{ value: any }>) + * + * Reading from a private static get accessor (when defined, TS 4.3+): + * __classPrivateFieldGet(, , "a", ) + * + * Reading from a private static get accessor (when not defined, TS 4.3+): + * __classPrivateFieldGet(, , "a", void 0) + * NOTE: This always results in a runtime error. + * + * Reading from a private static method (TS 4.3+): + * __classPrivateFieldGet(, , "m", ) + */ export const classPrivateFieldGetHelper: UnscopedEmitHelper = { name: "typescript:classPrivateFieldGet", importName: "__classPrivateFieldGet", scoped: false, text: ` - var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); + 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); };` }; + /** + * Parameters: + * @param receiver — The object on which the private member will be set. + * @param state — One of the following: + * - A WeakMap used to store a private instance field. + * - A WeakSet used as an instance brand for private instance methods and accessors. + * - A function value that should be the undecorated class constructor used to brand check private static fields, methods, and accessors. + * @param value — The value to set. + * @param kind — (optional pre TS 4.3, required for TS 4.3+) One of the following values: + * - undefined — Indicates a private instance field (pre TS 4.3). + * - "f" — Indicates a private field (instance or static). + * - "m" — Indicates a private method (instance or static). + * - "a" — Indicates a private accessor (instance or static). + * @param f — (optional pre TS 4.3) Depends on the arguments for state and kind: + * - If kind is "m", this should be the function corresponding to the static or instance method. + * - If kind is "a", this should be the function corresponding to the setter method, or undefined if the setter was not defined. + * - If kind is "f" and state is a function, this should be an object holding the value of a static field, or undefined if the static field declaration has not yet been evaluated. + * Usage: + * This helper will only ever be used by the compiler in the following ways: + * + * Writing to a private instance field (pre TS 4.3): + * __classPrivateFieldSet(, , ) + * + * Writing to a private instance field (TS 4.3+): + * __classPrivateFieldSet(, , , "f") + * + * Writing to a private instance set accessor (when defined, TS 4.3+): + * __classPrivateFieldSet(, , , "a", ) + * + * Writing to a private instance set accessor (when not defined, TS 4.3+): + * __classPrivateFieldSet(, , , "a", void 0) + * NOTE: This always results in a runtime error. + * + * Writing to a private instance method (TS 4.3+): + * __classPrivateFieldSet(, , , "m", ) + * NOTE: This always results in a runtime error. + * + * Writing to a private static field (TS 4.3+): + * __classPrivateFieldSet(, , , "f", <{ value: any }>) + * + * Writing to a private static set accessor (when defined, TS 4.3+): + * __classPrivateFieldSet(, , , "a", ) + * + * Writing to a private static set accessor (when not defined, TS 4.3+): + * __classPrivateFieldSet(, , , "a", void 0) + * NOTE: This always results in a runtime error. + * + * Writing to a private static method (TS 4.3+): + * __classPrivateFieldSet(, , , "m", ) + * NOTE: This always results in a runtime error. + */ export const classPrivateFieldSetHelper: UnscopedEmitHelper = { name: "typescript:classPrivateFieldSet", importName: "__classPrivateFieldSet", scoped: false, text: ` - var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; + 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; };` }; @@ -897,4 +1007,4 @@ namespace ts { && (getEmitFlags(firstSegment.expression) & EmitFlags.HelperName) && firstSegment.expression.escapedText === helperName; } -} \ No newline at end of file +} diff --git a/src/compiler/transformers/classFields.ts b/src/compiler/transformers/classFields.ts index 0e239bacb5ae6..ff6b53655f01d 100644 --- a/src/compiler/transformers/classFields.ts +++ b/src/compiler/transformers/classFields.ts @@ -7,23 +7,89 @@ namespace ts { */ ClassAliases = 1 << 0, } - - const enum PrivateIdentifierPlacement { - InstanceField + export const enum PrivateIdentifierKind { + Field = "f", + Method = "m", + Accessor = "a" + } + interface PrivateIdentifierInfoBase { + /** + * brandCheckIdentifier can contain: + * - For instance field: The WeakMap that will be the storage for the field. + * - For instance methods or accessors: The WeakSet that will be used for brand checking. + * - For static members: The constructor that will be used for brand checking. + */ + brandCheckIdentifier: Identifier; + /** + * Stores if the identifier is static or not + */ + isStatic: boolean; + /** + * Stores if the identifier declaration is valid or not. Reserved names (e.g. #constructor) + * or duplicate identifiers are considered invalid. + */ + isValid: boolean; + } + interface PrivateIdentifierAccessorInfo extends PrivateIdentifierInfoBase { + kind: PrivateIdentifierKind.Accessor; + /** + * Identifier for a variable that will contain the private get accessor implementation, if any. + */ + getterName?: Identifier; + /** + * Identifier for a variable that will contain the private set accessor implementation, if any. + */ + setterName?: Identifier; + } + interface PrivateIdentifierMethodInfo extends PrivateIdentifierInfoBase { + kind: PrivateIdentifierKind.Method; + /** + * Identifier for a variable that will contain the private method implementation. + */ + methodName: Identifier; + } + interface PrivateIdentifierInstanceFieldInfo extends PrivateIdentifierInfoBase { + kind: PrivateIdentifierKind.Field; + isStatic: false; + /** + * Defined for ease of access when in a union with PrivateIdentifierStaticFieldInfo. + */ + variableName: undefined; + } + interface PrivateIdentifierStaticFieldInfo extends PrivateIdentifierInfoBase { + kind: PrivateIdentifierKind.Field; + isStatic: true; + /** + * Contains the variable that will server as the storage for the field. + */ + variableName: Identifier; } - type PrivateIdentifierInfo = PrivateIdentifierInstanceField; + type PrivateIdentifierInfo = + | PrivateIdentifierMethodInfo + | PrivateIdentifierInstanceFieldInfo + | PrivateIdentifierStaticFieldInfo + | PrivateIdentifierAccessorInfo; - interface PrivateIdentifierInstanceField { - placement: PrivateIdentifierPlacement.InstanceField; - weakMapName: Identifier; + interface PrivateIdentifierEnvironment { + /** + * Used for prefixing generated variable names. + */ + className: string; + /** + * Used for brand check on static members + */ + classConstructor?: Identifier; + /** + * Used for brand check on private methods. + */ + weakSetName?: Identifier; + /** + * A mapping of private names to information needed for transformation. + */ + identifiers: UnderscoreEscapedMap } - /** - * A mapping of private names to information needed for transformation. - */ - type PrivateIdentifierEnvironment = UnderscoreEscapedMap; - /** * Transforms ECMAScript Class Syntax. * TypeScript parameter property syntax is transformed in the TypeScript transformer. @@ -43,7 +109,7 @@ namespace ts { const compilerOptions = context.getCompilerOptions(); const languageVersion = getEmitScriptTarget(compilerOptions); - const shouldTransformPrivateFields = languageVersion < ScriptTarget.ESNext; + const shouldTransformPrivateElements = languageVersion < ScriptTarget.ESNext; const previousOnSubstituteNode = context.onSubstituteNode; context.onSubstituteNode = onSubstituteNode; @@ -128,7 +194,7 @@ namespace ts { * Replace it with an empty identifier to indicate a problem with the code. */ function visitPrivateIdentifier(node: PrivateIdentifier) { - if (!shouldTransformPrivateFields) { + if (!shouldTransformPrivateElements) { return node; } return setOriginalNode(factory.createIdentifier(""), node); @@ -149,8 +215,7 @@ namespace ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.MethodDeclaration: - // Visit the name of the member (if it's a computed property name). - return visitEachChild(node, classElementVisitor, context); + return visitMethodOrAccessorDeclaration(node as MethodDeclaration | AccessorDeclaration); case SyntaxKind.PropertyDeclaration: return visitPropertyDeclaration(node as PropertyDeclaration); @@ -193,20 +258,85 @@ namespace ts { return node; } - function visitPropertyDeclaration(node: PropertyDeclaration) { + function visitMethodOrAccessorDeclaration(node: MethodDeclaration | AccessorDeclaration) { Debug.assert(!some(node.decorators)); - if (!shouldTransformPrivateFields && isPrivateIdentifier(node.name)) { - // Initializer is elided as the field is initialized in transformConstructor. - return factory.updatePropertyDeclaration( - node, - /*decorators*/ undefined, - visitNodes(node.modifiers, visitor, isModifier), - node.name, - /*questionOrExclamationToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined + + if (!shouldTransformPrivateElements || !isPrivateIdentifier(node.name)) { + return visitEachChild(node, classElementVisitor, context); + } + + // leave invalid code untransformed + const info = accessPrivateIdentifier(node.name); + Debug.assert(info, "Undeclared private name for property declaration."); + if (!info.isValid) { + return node; + } + + const functionName = getHoistedFunctionName(node); + if (functionName) { + getPendingExpressions().push( + factory.createAssignment( + functionName, + factory.createFunctionExpression( + filter(node.modifiers, m => !isStaticModifier(m)), + node.asteriskToken, + functionName, + /* typeParameters */ undefined, + visitParameterList(node.parameters, classElementVisitor, context), + /* type */ undefined, + visitFunctionBody(node.body!, classElementVisitor, context) + ) + ) ); } + + // remove method declaration from class + return undefined; + } + + function getHoistedFunctionName(node: MethodDeclaration | AccessorDeclaration) { + Debug.assert(isPrivateIdentifier(node.name)); + const info = accessPrivateIdentifier(node.name); + Debug.assert(info, "Undeclared private name for property declaration."); + + if (info.kind === PrivateIdentifierKind.Method) { + return info.methodName; + } + + if (info.kind === PrivateIdentifierKind.Accessor) { + if (isGetAccessor(node)) { + return info.getterName; + } + if (isSetAccessor(node)) { + return info.setterName; + } + } + } + + function visitPropertyDeclaration(node: PropertyDeclaration) { + Debug.assert(!some(node.decorators)); + + if (isPrivateIdentifier(node.name)) { + if (!shouldTransformPrivateElements) { + // Initializer is elided as the field is initialized in transformConstructor. + return factory.updatePropertyDeclaration( + node, + /*decorators*/ undefined, + visitNodes(node.modifiers, visitor, isModifier), + node.name, + /*questionOrExclamationToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined + ); + } + + // leave invalid code untransformed + const info = accessPrivateIdentifier(node.name); + Debug.assert(info, "Undeclared private name for property declaration."); + if (!info.isValid) { + return 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. @@ -218,23 +348,48 @@ namespace ts { } function createPrivateIdentifierAccess(info: PrivateIdentifierInfo, receiver: Expression): Expression { - receiver = visitNode(receiver, visitor, isExpression); - switch (info.placement) { - case PrivateIdentifierPlacement.InstanceField: + return createPrivateIdentifierAccessHelper(info, visitNode(receiver, visitor, isExpression)); + } + + function createPrivateIdentifierAccessHelper(info: PrivateIdentifierInfo, receiver: Expression): Expression { + setCommentRange(receiver, moveRangePos(receiver, -1)); + + switch(info.kind) { + case PrivateIdentifierKind.Accessor: + return context.getEmitHelperFactory().createClassPrivateFieldGetHelper( + receiver, + info.brandCheckIdentifier, + info.kind, + info.getterName + ); + case PrivateIdentifierKind.Method: return context.getEmitHelperFactory().createClassPrivateFieldGetHelper( - nodeIsSynthesized(receiver) ? receiver : factory.cloneNode(receiver), - info.weakMapName + receiver, + info.brandCheckIdentifier, + info.kind, + info.methodName ); - default: return Debug.fail("Unexpected private identifier placement"); + case PrivateIdentifierKind.Field: + return context.getEmitHelperFactory().createClassPrivateFieldGetHelper( + receiver, + info.brandCheckIdentifier, + info.kind, + info.variableName + ); + default: + Debug.assertNever(info, "Unknown private element type"); } } function visitPropertyAccessExpression(node: PropertyAccessExpression) { - if (shouldTransformPrivateFields && isPrivateIdentifier(node.name)) { + if (shouldTransformPrivateElements && isPrivateIdentifier(node.name)) { const privateIdentifierInfo = accessPrivateIdentifier(node.name); if (privateIdentifierInfo) { - return setOriginalNode( - createPrivateIdentifierAccess(privateIdentifierInfo, node.expression), + return setTextRange( + setOriginalNode( + createPrivateIdentifierAccess(privateIdentifierInfo, node.expression), + node + ), node ); } @@ -243,7 +398,7 @@ namespace ts { } function visitPrefixUnaryExpression(node: PrefixUnaryExpression) { - if (shouldTransformPrivateFields && isPrivateIdentifierPropertyAccessExpression(node.operand)) { + if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.operand)) { const operator = node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusToken : node.operator === SyntaxKind.MinusMinusToken ? SyntaxKind.MinusToken : undefined; @@ -269,7 +424,7 @@ namespace ts { } function visitPostfixUnaryExpression(node: PostfixUnaryExpression, valueIsDiscarded: boolean) { - if (shouldTransformPrivateFields && isPrivateIdentifierPropertyAccessExpression(node.operand)) { + if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.operand)) { const operator = node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusToken : node.operator === SyntaxKind.MinusMinusToken ? SyntaxKind.MinusToken : undefined; @@ -335,7 +490,7 @@ namespace ts { } function visitCallExpression(node: CallExpression) { - if (shouldTransformPrivateFields && isPrivateIdentifierPropertyAccessExpression(node.expression)) { + if (shouldTransformPrivateElements && isPrivateIdentifierPropertyAccessExpression(node.expression)) { // Transform call expressions of private names to properly bind the `this` parameter. const { thisArg, target } = factory.createCallBinding(node.expression, hoistVariableDeclaration, languageVersion); if (isCallChain(node)) { @@ -358,7 +513,7 @@ namespace ts { } function visitTaggedTemplateExpression(node: TaggedTemplateExpression) { - if (shouldTransformPrivateFields && isPrivateIdentifierPropertyAccessExpression(node.tag)) { + if (shouldTransformPrivateElements && 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( @@ -376,7 +531,7 @@ namespace ts { } function visitBinaryExpression(node: BinaryExpression) { - if (shouldTransformPrivateFields) { + if (shouldTransformPrivateElements) { if (isDestructuringAssignment(node)) { const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined!; @@ -395,8 +550,11 @@ namespace ts { if (isAssignmentExpression(node) && isPrivateIdentifierPropertyAccessExpression(node.left)) { const info = accessPrivateIdentifier(node.left.name); if (info) { - return setOriginalNode( - createPrivateIdentifierAssignment(info, node.left.expression, node.right, node.operatorToken.kind), + return setTextRange( + setOriginalNode( + createPrivateIdentifierAssignment(info, node.left.expression, node.right, node.operatorToken.kind), + node + ), node ); } @@ -405,32 +563,49 @@ namespace ts { return visitEachChild(node, visitor, context); } - function createPrivateIdentifierAssignment(info: PrivateIdentifierInfo, receiver: Expression, right: Expression, operator: AssignmentOperator) { - switch (info.placement) { - case PrivateIdentifierPlacement.InstanceField: { - return createPrivateIdentifierInstanceFieldAssignment(info, receiver, right, operator); - } - default: return Debug.fail("Unexpected private identifier placement"); - } - } - - function createPrivateIdentifierInstanceFieldAssignment(info: PrivateIdentifierInstanceField, receiver: Expression, right: Expression, operator: AssignmentOperator) { + function createPrivateIdentifierAssignment(info: PrivateIdentifierInfo, receiver: Expression, right: Expression, operator: AssignmentOperator): Expression { receiver = visitNode(receiver, visitor, isExpression); right = visitNode(right, visitor, isExpression); + if (isCompoundAssignment(operator)) { const { readExpression, initializeExpression } = createCopiableReceiverExpr(receiver); - return context.getEmitHelperFactory().createClassPrivateFieldSetHelper( - initializeExpression || readExpression, - info.weakMapName, - factory.createBinaryExpression( - context.getEmitHelperFactory().createClassPrivateFieldGetHelper(readExpression, info.weakMapName), - getNonAssignmentOperatorForCompoundAssignment(operator), - right - ) + receiver = initializeExpression || readExpression; + right = factory.createBinaryExpression( + createPrivateIdentifierAccessHelper(info, readExpression), + getNonAssignmentOperatorForCompoundAssignment(operator), + right ); } - else { - return context.getEmitHelperFactory().createClassPrivateFieldSetHelper(receiver, info.weakMapName, right); + + setCommentRange(receiver, moveRangePos(receiver, -1)); + + switch(info.kind) { + case PrivateIdentifierKind.Accessor: + return context.getEmitHelperFactory().createClassPrivateFieldSetHelper( + receiver, + info.brandCheckIdentifier, + right, + info.kind, + info.setterName + ); + case PrivateIdentifierKind.Method: + return context.getEmitHelperFactory().createClassPrivateFieldSetHelper( + receiver, + info.brandCheckIdentifier, + right, + info.kind, + /* f */ undefined + ); + case PrivateIdentifierKind.Field: + return context.getEmitHelperFactory().createClassPrivateFieldSetHelper( + receiver, + info.brandCheckIdentifier, + right, + info.kind, + info.variableName + ); + default: + Debug.assertNever(info, "Unknown private element type"); } } @@ -440,15 +615,28 @@ namespace ts { function visitClassLike(node: ClassLikeDeclaration) { const savedPendingExpressions = pendingExpressions; pendingExpressions = undefined; - if (shouldTransformPrivateFields) { + if (shouldTransformPrivateElements) { startPrivateIdentifierEnvironment(); + + 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); - if (shouldTransformPrivateFields) { + if (shouldTransformPrivateElements) { endPrivateIdentifierEnvironment(); } pendingExpressions = savedPendingExpressions; @@ -456,7 +644,11 @@ namespace ts { } function doesClassElementNeedTransform(node: ClassElement) { - return isPropertyDeclaration(node) || (shouldTransformPrivateFields && node.name && isPrivateIdentifier(node.name)); + return isPropertyDeclaration(node) || (shouldTransformPrivateElements && node.name && isPrivateIdentifier(node.name)); + } + + function getPrivateInstanceMethodsAndAccessors(node: ClassLikeDeclaration) { + return filter(node.members, isNonStaticMethodOrAccessorWithPrivateName); } function visitClassDeclaration(node: ClassDeclaration) { @@ -464,6 +656,16 @@ namespace ts { return visitEachChild(node, visitor, context); } + const staticProperties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ true); + if (shouldTransformPrivateElements && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { + const temp = factory.createTempVariable(hoistVariableDeclaration, /* reservedInNestedScopes */ true); + getPrivateIdentifierEnvironment().classConstructor = factory.cloneNode(temp); + getPendingExpressions().push(factory.createAssignment( + temp, + factory.getInternalName(node) + )); + } + const extendsClauseElement = getEffectiveBaseTypeNode(node); const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword); @@ -489,7 +691,7 @@ namespace ts { // 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 = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + if (some(staticProperties)) { addPropertyStatements(statements, staticProperties, factory.getInternalName(node)); } @@ -511,10 +713,24 @@ namespace ts { // these statements after the class expression variable statement. const isDecoratedClassDeclaration = isClassDeclaration(getOriginalNode(node)); - const staticProperties = getProperties(node, /*requireInitializer*/ true, /*isStatic*/ true); + const staticProperties = getProperties(node, /*requireInitializer*/ false, /*isStatic*/ true); + 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() { + const classCheckFlags = resolver.getNodeCheckFlags(node); + const isClassWithConstructorReference = classCheckFlags & NodeCheckFlags.ClassWithConstructorReference; + const requiresBlockScopedVar = classCheckFlags & NodeCheckFlags.BlockScopedBindingInLoop; + return factory.createTempVariable(requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration, !!isClassWithConstructorReference); + } + if (shouldTransformPrivateElements && some(node.members, m => hasStaticModifier(m) && !!m.name && isPrivateIdentifier(m.name))) { + temp = createClassTempVar(); + getPrivateIdentifierEnvironment().classConstructor = factory.cloneNode(temp); + } + const classExpression = factory.updateClassExpression( node, visitNodes(node.decorators, visitor, isDecorator), @@ -524,8 +740,8 @@ namespace ts { visitNodes(node.heritageClauses, visitor, isHeritageClause), transformClassMembers(node, isDerivedClass) ); - - if (some(staticProperties) || some(pendingExpressions)) { + const hasTransformableStatics = some(staticProperties, p => !!p.initializer || (shouldTransformPrivateElements && isPrivateIdentifier(p.name))); + if (hasTransformableStatics || some(pendingExpressions)) { if (isDecoratedClassDeclaration) { Debug.assertIsDefined(pendingStatements, "Decorated classes transformed by TypeScript are expected to be within a variable declaration."); @@ -537,14 +753,14 @@ namespace ts { if (pendingStatements && some(staticProperties)) { addPropertyStatements(pendingStatements, staticProperties, factory.getInternalName(node)); } + if (temp) { + return factory.inlineExpressions([factory.createAssignment(temp, classExpression), temp]); + } return classExpression; } else { const expressions: Expression[] = []; - const classCheckFlags = resolver.getNodeCheckFlags(node); - const isClassWithConstructorReference = classCheckFlags & NodeCheckFlags.ClassWithConstructorReference; - const requiresBlockScopedVar = classCheckFlags & NodeCheckFlags.BlockScopedBindingInLoop; - const temp = factory.createTempVariable(requiresBlockScopedVar ? addBlockScopedVariable : hoistVariableDeclaration, !!isClassWithConstructorReference); + temp ||= createClassTempVar(); if (isClassWithConstructorReference) { // record an alias as the class name is not in scope for statics. enableSubstitutionForClassAliases(); @@ -560,6 +776,7 @@ namespace ts { // Add any pending expressions leftover from elided or relocated computed property names addRange(expressions, map(pendingExpressions, startOnNewLine)); addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); + expressions.push(startOnNewLine(temp)); return factory.inlineExpressions(expressions); @@ -570,13 +787,17 @@ namespace ts { } function transformClassMembers(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { - if (shouldTransformPrivateFields) { + if (shouldTransformPrivateElements) { // Declare private names. for (const member of node.members) { - if (isPrivateIdentifierPropertyDeclaration(member)) { - addPrivateIdentifierToEnvironment(member.name); + if (isPrivateIdentifierClassElementDeclaration(member)) { + addPrivateIdentifierToEnvironment(member); } } + + if (some(getPrivateInstanceMethodsAndAccessors(node))) { + createBrandCheckWeakSetForPrivateMethods(); + } } const members: ClassElement[] = []; @@ -588,8 +809,24 @@ namespace ts { return setTextRange(factory.createNodeArray(members), /*location*/ node.members); } - function isPropertyDeclarationThatRequiresConstructorStatement(member: ClassElement): member is PropertyDeclaration { - if (!isPropertyDeclaration(member) || hasStaticModifier(member) || hasSyntacticModifier(getOriginalNode(member), ModifierFlags.Abstract)) { + function createBrandCheckWeakSetForPrivateMethods() { + const { weakSetName } = getPrivateIdentifierEnvironment(); + Debug.assert(weakSetName, "weakSetName should be set in private identifier environment"); + + getPendingExpressions().push( + factory.createAssignment( + weakSetName, + factory.createNewExpression( + factory.createIdentifier("WeakSet"), + /*typeArguments*/ undefined, + [] + ) + ) + ); + } + + function isClassElementThatRequiresConstructorStatement(member: ClassElement) { + if (hasStaticModifier(member) || hasSyntacticModifier(getOriginalNode(member), ModifierFlags.Abstract)) { return false; } if (context.getCompilerOptions().useDefineForClassFields) { @@ -597,13 +834,13 @@ namespace ts { // then we don't need to transform any class properties. return languageVersion < ScriptTarget.ESNext; } - return isInitializedProperty(member) || shouldTransformPrivateFields && isPrivateIdentifierPropertyDeclaration(member); + return isInitializedProperty(member) || shouldTransformPrivateElements && isPrivateIdentifierClassElementDeclaration(member); } function transformConstructor(node: ClassDeclaration | ClassExpression, isDerivedClass: boolean) { const constructor = visitNode(getFirstConstructorWithBody(node), visitor, isConstructorDeclaration); - const properties = node.members.filter(isPropertyDeclarationThatRequiresConstructorStatement); - if (!some(properties)) { + const elements = node.members.filter(isClassElementThatRequiresConstructorStatement); + if (!some(elements)) { return constructor; } const parameters = visitParameterList(constructor ? constructor.parameters : undefined, visitor, context); @@ -634,9 +871,11 @@ namespace ts { properties = filter(properties, property => !!property.initializer || isPrivateIdentifier(property.name)); } + const privateMethodsAndAccessors = getPrivateInstanceMethodsAndAccessors(node); + const needsConstructorBody = some(properties) || some(privateMethodsAndAccessors); // Only generate synthetic constructor when there are property initializers to move. - if (!constructor && !some(properties)) { + if (!constructor && !needsConstructorBody) { return visitFunctionBody(/*node*/ undefined, visitor, context); } @@ -686,7 +925,10 @@ namespace ts { indexOfFirstStatement = afterParameterProperties; } } - addPropertyStatements(statements, properties, factory.createThis()); + const receiver = factory.createThis(); + // private methods can be called in property initializers, they should execute first. + addMethodStatements(statements, privateMethodsAndAccessors, receiver); + addPropertyStatements(statements, properties, receiver); // Add existing statements, skipping the initial super call. if (constructor) { @@ -763,28 +1005,33 @@ namespace ts { ? factory.updateComputedPropertyName(property.name, factory.getGeneratedNameForNode(property.name)) : property.name; - if (shouldTransformPrivateFields && isPrivateIdentifier(propertyName)) { + if (shouldTransformPrivateElements && isPrivateIdentifier(propertyName)) { const privateIdentifierInfo = accessPrivateIdentifier(propertyName); if (privateIdentifierInfo) { - switch (privateIdentifierInfo.placement) { - case PrivateIdentifierPlacement.InstanceField: { + if (privateIdentifierInfo.kind === PrivateIdentifierKind.Field) { + if (!privateIdentifierInfo.isStatic) { return createPrivateInstanceFieldInitializer( receiver, visitNode(property.initializer, visitor, isExpression), - privateIdentifierInfo.weakMapName + privateIdentifierInfo.brandCheckIdentifier + ); + } + else { + return createPrivateStaticFieldInitializer( + privateIdentifierInfo.variableName, + visitNode(property.initializer, visitor, isExpression) ); } } + else { + return undefined; + } } else { Debug.fail("Undeclared private name for property declaration."); } } - if (isPrivateIdentifier(propertyName) && !property.initializer) { - return undefined; - } - - if (isPrivateIdentifier(propertyName) && !property.initializer) { + if ((isPrivateIdentifier(propertyName) || hasStaticModifier(property)) && !property.initializer) { return undefined; } @@ -822,6 +1069,27 @@ namespace ts { } } + /** + * Generates brand-check initializer for private methods. + * + * @param statements Statement list that should be used to append new statements. + * @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) { + if (!shouldTransformPrivateElements || !some(methods)) { + return; + } + + const { weakSetName } = getPrivateIdentifierEnvironment(); + Debug.assert(weakSetName, "weakSetName should be set in private identifier environment"); + statements.push( + factory.createExpressionStatement( + createPrivateInstanceMethodInitializer(receiver, weakSetName) + ) + ); + } + /** * Hooks node substitutions. * @@ -907,38 +1175,185 @@ namespace ts { } function getPrivateIdentifierEnvironment() { - return currentPrivateIdentifierEnvironment || (currentPrivateIdentifierEnvironment = new Map()); + if (!currentPrivateIdentifierEnvironment) { + currentPrivateIdentifierEnvironment = { + className: "", + identifiers: new Map() + }; + } + + return currentPrivateIdentifierEnvironment; } function getPendingExpressions() { return pendingExpressions || (pendingExpressions = []); } - function addPrivateIdentifierToEnvironment(name: PrivateIdentifier) { - const text = getTextOfPropertyName(name) as string; - const weakMapName = factory.createUniqueName("_" + text.substring(1), GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.ReservedInNestedScopes); - if (resolver.getNodeCheckFlags(name) & NodeCheckFlags.BlockScopedBindingInLoop) { - addBlockScopedVariable(weakMapName); - } - else { - hoistVariableDeclaration(weakMapName); + function addPrivateIdentifierToEnvironment(node: PrivateClassElementDeclaration) { + const text = getTextOfPropertyName(node.name) as string; + const env = getPrivateIdentifierEnvironment(); + const { weakSetName, classConstructor } = env; + const assignmentExpressions: Expression[] = []; + + const privateName = node.name.escapedText; + const previousInfo = env.identifiers.get(privateName); + const isValid = !isReservedPrivateName(node.name) && previousInfo === undefined; + + if (hasStaticModifier(node)) { + Debug.assert(classConstructor, "weakSetName should be set in private identifier environment"); + if (isPropertyDeclaration(node)) { + const variableName = createHoistedVariableForPrivateName(text, node); + env.identifiers.set(privateName, { + kind: PrivateIdentifierKind.Field, + variableName, + brandCheckIdentifier: classConstructor, + isStatic: true, + isValid, + }); + } + else if (isMethodDeclaration(node)) { + const functionName = createHoistedVariableForPrivateName(text, node); + env.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 { + env.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 { + env.identifiers.set(privateName, { + kind: PrivateIdentifierKind.Accessor, + getterName: undefined, + setterName, + brandCheckIdentifier: classConstructor, + isStatic: true, + isValid, + }); + } + } + else { + Debug.assertNever(node, "Unknown class element type."); + } } - getPrivateIdentifierEnvironment().set(name.escapedText, { placement: PrivateIdentifierPlacement.InstanceField, weakMapName }); - getPendingExpressions().push( - factory.createAssignment( + else if (isPropertyDeclaration(node)) { + const weakMapName = createHoistedVariableForPrivateName(text, node); + env.identifiers.set(privateName, { + kind: PrivateIdentifierKind.Field, + brandCheckIdentifier: weakMapName, + isStatic: false, + variableName: undefined, + isValid, + }); + + assignmentExpressions.push(factory.createAssignment( weakMapName, factory.createNewExpression( factory.createIdentifier("WeakMap"), /*typeArguments*/ undefined, [] ) - ) - ); + )); + } + else if (isMethodDeclaration(node)) { + Debug.assert(weakSetName, "weakSetName should be set in private identifier environment"); + + env.identifiers.set(privateName, { + kind: PrivateIdentifierKind.Method, + methodName: createHoistedVariableForPrivateName(text, node), + brandCheckIdentifier: weakSetName, + isStatic: false, + 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 { + env.identifiers.set(privateName, { + kind: PrivateIdentifierKind.Accessor, + getterName, + setterName: undefined, + brandCheckIdentifier: weakSetName, + isStatic: false, + isValid, + }); + } + } + else { + const setterName = createHoistedVariableForPrivateName(text + "_set", node); + + if (previousInfo?.kind === PrivateIdentifierKind.Accessor && !previousInfo.isStatic && !previousInfo.setterName) { + previousInfo.setterName = setterName; + } + else { + env.identifiers.set(privateName, { + kind: PrivateIdentifierKind.Accessor, + getterName: undefined, + setterName, + brandCheckIdentifier: weakSetName, + isStatic: false, + isValid, + }); + } + } + } + else { + Debug.assertNever(node, "Unknown class element type."); + } + + getPendingExpressions().push(...assignmentExpressions); + } + + function createHoistedVariableForClass(name: string, node: PrivateIdentifier): Identifier { + const { className } = getPrivateIdentifierEnvironment(); + const prefix = className ? `_${className}` : ""; + const identifier = factory.createUniqueName(`${prefix}_${name}`, GeneratedIdentifierFlags.Optimistic); + + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.BlockScopedBindingInLoop) { + addBlockScopedVariable(identifier); + } + else { + hoistVariableDeclaration(identifier); + } + + return identifier; + } + + function createHoistedVariableForPrivateName(privateName: string, node: PrivateClassElementDeclaration): Identifier { + return createHoistedVariableForClass(privateName.substring(1), node.name); } function accessPrivateIdentifier(name: PrivateIdentifier) { if (currentPrivateIdentifierEnvironment) { - const info = currentPrivateIdentifierEnvironment.get(name.escapedText); + const info = currentPrivateIdentifierEnvironment.identifiers.get(name.escapedText); if (info) { return info; } @@ -948,7 +1363,7 @@ namespace ts { if (!env) { continue; } - const info = env.get(name.escapedText); + const info = env.identifiers.get(name.escapedText); if (info) { return info; } @@ -1078,6 +1493,15 @@ namespace ts { } } + function createPrivateStaticFieldInitializer(variableName: Identifier, initializer: Expression | undefined) { + return factory.createAssignment( + variableName, + factory.createObjectLiteralExpression([ + factory.createPropertyAssignment("value", initializer || factory.createVoidZero()) + ]) + ); + } + function createPrivateInstanceFieldInitializer(receiver: LeftHandSideExpression, initializer: Expression | undefined, weakMapName: Identifier) { return factory.createCallExpression( factory.createPropertyAccessExpression(weakMapName, "set"), @@ -1085,4 +1509,16 @@ namespace ts { [receiver, initializer || factory.createVoidZero()] ); } + + function createPrivateInstanceMethodInitializer(receiver: LeftHandSideExpression, weakSetName: Identifier) { + return factory.createCallExpression( + factory.createPropertyAccessExpression(weakSetName, "add"), + /*typeArguments*/ undefined, + [receiver] + ); + } + + function isReservedPrivateName(node: PrivateIdentifier) { + return node.escapedText === "#constructor"; + } } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 3fe5ba5f8aa70..e1c3b0b957d6d 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -364,4 +364,13 @@ namespace ts { return member.kind === SyntaxKind.PropertyDeclaration && (member).initializer !== undefined; } + + /** + * Gets a value indicating whether a class element is a private instance method or accessor. + * + * @param member The class element node. + */ + export function isNonStaticMethodOrAccessorWithPrivateName(member: ClassElement): member is PrivateIdentifierMethodDeclaration | PrivateIdentifierAccessorDeclaration { + return !hasStaticModifier(member) && isMethodOrAccessor(member) && isPrivateIdentifier(member.name); + } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 795427421fcb6..3d70582fdaf33 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1302,6 +1302,26 @@ namespace ts { export interface PrivateIdentifierPropertyDeclaration extends PropertyDeclaration { name: PrivateIdentifier; } + /*@internal*/ + export interface PrivateIdentifierMethodDeclaration extends MethodDeclaration { + name: PrivateIdentifier; + } + /*@internal*/ + export interface PrivateIdentifierGetAccessorDeclaration extends GetAccessorDeclaration { + name: PrivateIdentifier; + } + /*@internal*/ + export interface PrivateIdentifierSetAccessorDeclaration extends SetAccessorDeclaration { + name: PrivateIdentifier; + } + /*@internal*/ + export type PrivateIdentifierAccessorDeclaration = PrivateIdentifierGetAccessorDeclaration | PrivateIdentifierSetAccessorDeclaration; + /*@internal*/ + export type PrivateClassElementDeclaration = + | PrivateIdentifierPropertyDeclaration + | PrivateIdentifierMethodDeclaration + | PrivateIdentifierGetAccessorDeclaration + | PrivateIdentifierSetAccessorDeclaration; /* @internal */ export type InitializedPropertyDeclaration = PropertyDeclaration & { readonly initializer: Expression }; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b19eca5926680..6df07c9b013b3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2706,6 +2706,9 @@ namespace ts { case SyntaxKind.NonNullExpression: node = parent; break; + case SyntaxKind.SpreadAssignment: + node = parent.parent; + break; case SyntaxKind.ShorthandPropertyAssignment: if ((parent as ShorthandPropertyAssignment).name !== node) { return AssignmentKind.None; @@ -4814,6 +4817,9 @@ namespace ts { && isLeftHandSideExpression(node.left); } + export function isLeftHandSideOfAssignment(node: Node) { + return isAssignmentExpression(node.parent) && node.parent.left === node; + } export function isDestructuringAssignment(node: Node): node is DestructuringAssignment { if (isAssignmentExpression(node, /*excludeCompoundAssignment*/ true)) { const kind = node.left.kind; diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index ec690f36e1001..8285699d08753 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -490,7 +490,7 @@ namespace ts { return unescapeLeadingUnderscores(identifierOrPrivateName.escapedText); } export function symbolName(symbol: Symbol): string { - if (symbol.valueDeclaration && isPrivateIdentifierPropertyDeclaration(symbol.valueDeclaration)) { + if (symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return idText(symbol.valueDeclaration.name); } return unescapeLeadingUnderscores(symbol.escapedName); @@ -1149,8 +1149,8 @@ namespace ts { // Private Identifiers /*@internal*/ - export function isPrivateIdentifierPropertyDeclaration(node: Node): node is PrivateIdentifierPropertyDeclaration { - return isPropertyDeclaration(node) && isPrivateIdentifier(node.name); + export function isPrivateIdentifierClassElementDeclaration(node: Node): node is PrivateClassElementDeclaration { + return (isPropertyDeclaration(node) || isMethodOrAccessor(node)) && isPrivateIdentifier(node.name); } /*@internal*/ diff --git a/src/services/completions.ts b/src/services/completions.ts index be4d4ad7b01a4..8cd4600674112 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -2550,7 +2550,7 @@ namespace ts.Completions { !existingMemberNames.has(propertySymbol.escapedName) && !!propertySymbol.declarations && !(getDeclarationModifierFlagsFromSymbol(propertySymbol) & ModifierFlags.Private) && - !(propertySymbol.valueDeclaration && isPrivateIdentifierPropertyDeclaration(propertySymbol.valueDeclaration))); + !(propertySymbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(propertySymbol.valueDeclaration))); } /** @@ -2609,7 +2609,7 @@ namespace ts.Completions { } const validNameResult: CompletionEntryDisplayNameForSymbol = { name, needsConvertPropertyAccess: false }; - if (isIdentifierText(name, target, jsxIdentifierExpected ? LanguageVariant.JSX : LanguageVariant.Standard) || symbol.valueDeclaration && isPrivateIdentifierPropertyDeclaration(symbol.valueDeclaration)) { + if (isIdentifierText(name, target, jsxIdentifierExpected ? LanguageVariant.JSX : LanguageVariant.Standard) || symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return validNameResult; } switch (kind) { diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 851d2600fc7eb..7c0ecda42fb80 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1242,7 +1242,7 @@ namespace ts.FindAllReferences { // If this is private property or method, the scope is the containing class if (flags & (SymbolFlags.Property | SymbolFlags.Method)) { - const privateDeclaration = find(declarations, d => hasEffectiveModifier(d, ModifierFlags.Private) || isPrivateIdentifierPropertyDeclaration(d)); + const privateDeclaration = find(declarations, d => hasEffectiveModifier(d, ModifierFlags.Private) || isPrivateIdentifierClassElementDeclaration(d)); if (privateDeclaration) { return getAncestor(privateDeclaration, SyntaxKind.ClassDeclaration); } diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index 12a3d724e7b82..3eb0c20209808 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -249,7 +249,7 @@ namespace ts.Completions.StringCompletions { function stringLiteralCompletionsFromProperties(type: Type | undefined): StringLiteralCompletionsFromProperties | undefined { return type && { kind: StringLiteralCompletionKind.Properties, - symbols: filter(type.getApparentProperties(), prop => !(prop.valueDeclaration && isPrivateIdentifierPropertyDeclaration(prop.valueDeclaration))), + symbols: filter(type.getApparentProperties(), prop => !(prop.valueDeclaration && isPrivateIdentifierClassElementDeclaration(prop.valueDeclaration))), hasIndexSignature: hasIndexSignature(type) }; } diff --git a/tests/baselines/reference/importHelpersES6.js b/tests/baselines/reference/importHelpersES6.js index 293ee8e28875b..9a7a6bc30c77c 100644 --- a/tests/baselines/reference/importHelpersES6.js +++ b/tests/baselines/reference/importHelpersES6.js @@ -16,21 +16,22 @@ export declare function __decorate(decorators: Function[], target: any, key?: st export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; -export declare function __classPrivateFieldGet(): any; -export declare function __classPrivateFieldSet(): any; +export declare function __classPrivateFieldGet(a: any, b: any, c: any, d: any): any; +export declare function __classPrivateFieldSet(a: any, b: any, c: any, d: any, e: any): any; + //// [a.js] -var _x; +var _A_x; import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet, __decorate } from "tslib"; let A = class A { constructor() { - _x.set(this, 1); + _A_x.set(this, 1); } f() { - return __awaiter(this, void 0, void 0, function* () { __classPrivateFieldSet(this, _x, yield __classPrivateFieldGet(this, _x)); }); + return __awaiter(this, void 0, void 0, function* () { __classPrivateFieldSet(this, _A_x, yield __classPrivateFieldGet(this, _A_x, "f"), "f"); }); } }; -_x = new WeakMap(); +_A_x = new WeakMap(); A = __decorate([ dec ], A); diff --git a/tests/baselines/reference/importHelpersES6.symbols b/tests/baselines/reference/importHelpersES6.symbols index 5e7d2762a8110..38c044cbe709e 100644 --- a/tests/baselines/reference/importHelpersES6.symbols +++ b/tests/baselines/reference/importHelpersES6.symbols @@ -63,9 +63,18 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >generator : Symbol(generator, Decl(tslib.d.ts, --, --)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) -export declare function __classPrivateFieldGet(): any; +export declare function __classPrivateFieldGet(a: any, b: any, c: any, d: any): any; >__classPrivateFieldGet : Symbol(__classPrivateFieldGet, Decl(tslib.d.ts, --, --)) +>a : Symbol(a, Decl(tslib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>c : Symbol(c, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) -export declare function __classPrivateFieldSet(): any; +export declare function __classPrivateFieldSet(a: any, b: any, c: any, d: any, e: any): any; >__classPrivateFieldSet : Symbol(__classPrivateFieldSet, Decl(tslib.d.ts, --, --)) +>a : Symbol(a, Decl(tslib.d.ts, --, --)) +>b : Symbol(b, Decl(tslib.d.ts, --, --)) +>c : Symbol(c, Decl(tslib.d.ts, --, --)) +>d : Symbol(d, Decl(tslib.d.ts, --, --)) +>e : Symbol(e, Decl(tslib.d.ts, --, --)) diff --git a/tests/baselines/reference/importHelpersES6.types b/tests/baselines/reference/importHelpersES6.types index 0402f6a17dec0..bbb6f97969104 100644 --- a/tests/baselines/reference/importHelpersES6.types +++ b/tests/baselines/reference/importHelpersES6.types @@ -61,9 +61,18 @@ export declare function __awaiter(thisArg: any, _arguments: any, P: Function, ge >P : Function >generator : Function -export declare function __classPrivateFieldGet(): any; ->__classPrivateFieldGet : () => any +export declare function __classPrivateFieldGet(a: any, b: any, c: any, d: any): any; +>__classPrivateFieldGet : (a: any, b: any, c: any, d: any) => any +>a : any +>b : any +>c : any +>d : any -export declare function __classPrivateFieldSet(): any; ->__classPrivateFieldSet : () => any +export declare function __classPrivateFieldSet(a: any, b: any, c: any, d: any, e: any): any; +>__classPrivateFieldSet : (a: any, b: any, c: any, d: any, e: any) => any +>a : any +>b : any +>c : any +>d : any +>e : any diff --git a/tests/baselines/reference/privateFieldAssignabilityFromUnknown.js b/tests/baselines/reference/privateFieldAssignabilityFromUnknown.js index b63ff22f93255..206b1d827b20a 100644 --- a/tests/baselines/reference/privateFieldAssignabilityFromUnknown.js +++ b/tests/baselines/reference/privateFieldAssignabilityFromUnknown.js @@ -8,15 +8,15 @@ const task: Class = {} as unknown; //// [privateFieldAssignabilityFromUnknown.js] "use strict"; -var _field; +var _Class_field; exports.__esModule = true; exports.Class = void 0; var Class = /** @class */ (function () { function Class() { - _field.set(this, void 0); + _Class_field.set(this, void 0); } return Class; }()); exports.Class = Class; -_field = new WeakMap(); +_Class_field = new WeakMap(); var task = {}; diff --git a/tests/baselines/reference/privateNameAccessors.errors.txt b/tests/baselines/reference/privateNameAccessors.errors.txt new file mode 100644 index 0000000000000..de5ae2636a6a0 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessors.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts(9,14): error TS2540: Cannot assign to '#roProp' because it is a read-only property. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts (1 errors) ==== + class A1 { + get #prop() { return ""; } + set #prop(param: string) { } + + get #roProp() { return ""; } + + constructor(name: string) { + this.#prop = ""; + this.#roProp = ""; // Error + ~~~~~~~ +!!! error TS2540: Cannot assign to '#roProp' because it is a read-only property. + console.log(this.#prop); + console.log(this.#roProp); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameAccessors.js b/tests/baselines/reference/privateNameAccessors.js new file mode 100644 index 0000000000000..231ea602882b8 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessors.js @@ -0,0 +1,40 @@ +//// [privateNameAccessors.ts] +class A1 { + get #prop() { return ""; } + set #prop(param: string) { } + + get #roProp() { return ""; } + + constructor(name: string) { + this.#prop = ""; + this.#roProp = ""; // Error + console.log(this.#prop); + console.log(this.#roProp); + } +} + + +//// [privateNameAccessors.js] +"use strict"; +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 _A1_instances, _A1_prop_get, _A1_prop_set, _A1_roProp_get; +class A1 { + constructor(name) { + _A1_instances.add(this); + __classPrivateFieldSet(this, _A1_instances, "", "a", _A1_prop_set); + __classPrivateFieldSet(this, _A1_instances, "", "a"); // Error + console.log(__classPrivateFieldGet(this, _A1_instances, "a", _A1_prop_get)); + console.log(__classPrivateFieldGet(this, _A1_instances, "a", _A1_roProp_get)); + } +} +_A1_instances = new WeakSet(), _A1_prop_get = function _A1_prop_get() { return ""; }, _A1_prop_set = function _A1_prop_set(param) { }, _A1_roProp_get = function _A1_roProp_get() { return ""; }; diff --git a/tests/baselines/reference/privateNameAccessors.symbols b/tests/baselines/reference/privateNameAccessors.symbols new file mode 100644 index 0000000000000..3386042d76a63 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessors.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts === +class A1 { +>A1 : Symbol(A1, Decl(privateNameAccessors.ts, 0, 0)) + + get #prop() { return ""; } +>#prop : Symbol(A1.#prop, Decl(privateNameAccessors.ts, 0, 10), Decl(privateNameAccessors.ts, 1, 30)) + + set #prop(param: string) { } +>#prop : Symbol(A1.#prop, Decl(privateNameAccessors.ts, 0, 10), Decl(privateNameAccessors.ts, 1, 30)) +>param : Symbol(param, Decl(privateNameAccessors.ts, 2, 14)) + + get #roProp() { return ""; } +>#roProp : Symbol(A1.#roProp, Decl(privateNameAccessors.ts, 2, 32)) + + constructor(name: string) { +>name : Symbol(name, Decl(privateNameAccessors.ts, 6, 16)) + + this.#prop = ""; +>this.#prop : Symbol(A1.#prop, Decl(privateNameAccessors.ts, 0, 10), Decl(privateNameAccessors.ts, 1, 30)) +>this : Symbol(A1, Decl(privateNameAccessors.ts, 0, 0)) + + this.#roProp = ""; // Error +>this.#roProp : Symbol(A1.#roProp, Decl(privateNameAccessors.ts, 2, 32)) +>this : Symbol(A1, Decl(privateNameAccessors.ts, 0, 0)) + + console.log(this.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#prop : Symbol(A1.#prop, Decl(privateNameAccessors.ts, 0, 10), Decl(privateNameAccessors.ts, 1, 30)) +>this : Symbol(A1, Decl(privateNameAccessors.ts, 0, 0)) + + console.log(this.#roProp); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#roProp : Symbol(A1.#roProp, Decl(privateNameAccessors.ts, 2, 32)) +>this : Symbol(A1, Decl(privateNameAccessors.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameAccessors.types b/tests/baselines/reference/privateNameAccessors.types new file mode 100644 index 0000000000000..8449fba9f7039 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessors.types @@ -0,0 +1,49 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts === +class A1 { +>A1 : A1 + + get #prop() { return ""; } +>#prop : string +>"" : "" + + set #prop(param: string) { } +>#prop : string +>param : string + + get #roProp() { return ""; } +>#roProp : string +>"" : "" + + constructor(name: string) { +>name : string + + this.#prop = ""; +>this.#prop = "" : "" +>this.#prop : string +>this : this +>"" : "" + + this.#roProp = ""; // Error +>this.#roProp = "" : "" +>this.#roProp : any +>this : this +>"" : "" + + console.log(this.#prop); +>console.log(this.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#prop : string +>this : this + + console.log(this.#roProp); +>console.log(this.#roProp) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#roProp : string +>this : this + } +} + diff --git a/tests/baselines/reference/privateNameAccessorsAccess.errors.txt b/tests/baselines/reference/privateNameAccessorsAccess.errors.txt new file mode 100644 index 0000000000000..f7c36306fde04 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsAccess.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts(14,10): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts(17,14): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts(22,18): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts (3 errors) ==== + class A2 { + get #prop() { return ""; } + set #prop(param: string) { } + + constructor() { + console.log(this.#prop); + let a: A2 = this; + a.#prop; + function foo (){ + a.#prop; + } + } + } + new A2().#prop; // Error + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + + function foo (){ + new A2().#prop; // Error + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + } + + class B2 { + m() { + new A2().#prop; + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameAccessorsAccess.js b/tests/baselines/reference/privateNameAccessorsAccess.js new file mode 100644 index 0000000000000..b680f6964e2c9 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsAccess.js @@ -0,0 +1,55 @@ +//// [privateNameAccessorsAccess.ts] +class A2 { + get #prop() { return ""; } + set #prop(param: string) { } + + constructor() { + console.log(this.#prop); + let a: A2 = this; + a.#prop; + function foo (){ + a.#prop; + } + } +} +new A2().#prop; // Error + +function foo (){ + new A2().#prop; // Error +} + +class B2 { + m() { + new A2().#prop; + } +} + + +//// [privateNameAccessorsAccess.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 _A2_instances, _A2_prop_get, _A2_prop_set; +class A2 { + constructor() { + _A2_instances.add(this); + console.log(__classPrivateFieldGet(this, _A2_instances, "a", _A2_prop_get)); + let a = this; + __classPrivateFieldGet(a, _A2_instances, "a", _A2_prop_get); + function foo() { + __classPrivateFieldGet(a, _A2_instances, "a", _A2_prop_get); + } + } +} +_A2_instances = new WeakSet(), _A2_prop_get = function _A2_prop_get() { return ""; }, _A2_prop_set = function _A2_prop_set(param) { }; +new A2().; // Error +function foo() { + new A2().; // Error +} +class B2 { + m() { + new A2().; + } +} diff --git a/tests/baselines/reference/privateNameAccessorsAccess.symbols b/tests/baselines/reference/privateNameAccessorsAccess.symbols new file mode 100644 index 0000000000000..9697bb2d45859 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsAccess.symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts === +class A2 { +>A2 : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) + + get #prop() { return ""; } +>#prop : Symbol(A2.#prop, Decl(privateNameAccessorsAccess.ts, 0, 10), Decl(privateNameAccessorsAccess.ts, 1, 30)) + + set #prop(param: string) { } +>#prop : Symbol(A2.#prop, Decl(privateNameAccessorsAccess.ts, 0, 10), Decl(privateNameAccessorsAccess.ts, 1, 30)) +>param : Symbol(param, Decl(privateNameAccessorsAccess.ts, 2, 14)) + + constructor() { + console.log(this.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#prop : Symbol(A2.#prop, Decl(privateNameAccessorsAccess.ts, 0, 10), Decl(privateNameAccessorsAccess.ts, 1, 30)) +>this : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) + + let a: A2 = this; +>a : Symbol(a, Decl(privateNameAccessorsAccess.ts, 6, 11)) +>A2 : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) +>this : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) + + a.#prop; +>a.#prop : Symbol(A2.#prop, Decl(privateNameAccessorsAccess.ts, 0, 10), Decl(privateNameAccessorsAccess.ts, 1, 30)) +>a : Symbol(a, Decl(privateNameAccessorsAccess.ts, 6, 11)) + + function foo (){ +>foo : Symbol(foo, Decl(privateNameAccessorsAccess.ts, 7, 16)) + + a.#prop; +>a.#prop : Symbol(A2.#prop, Decl(privateNameAccessorsAccess.ts, 0, 10), Decl(privateNameAccessorsAccess.ts, 1, 30)) +>a : Symbol(a, Decl(privateNameAccessorsAccess.ts, 6, 11)) + } + } +} +new A2().#prop; // Error +>A2 : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) + +function foo (){ +>foo : Symbol(foo, Decl(privateNameAccessorsAccess.ts, 13, 15)) + + new A2().#prop; // Error +>A2 : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) +} + +class B2 { +>B2 : Symbol(B2, Decl(privateNameAccessorsAccess.ts, 17, 1)) + + m() { +>m : Symbol(B2.m, Decl(privateNameAccessorsAccess.ts, 19, 10)) + + new A2().#prop; +>A2 : Symbol(A2, Decl(privateNameAccessorsAccess.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameAccessorsAccess.types b/tests/baselines/reference/privateNameAccessorsAccess.types new file mode 100644 index 0000000000000..9381e31558f34 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsAccess.types @@ -0,0 +1,65 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts === +class A2 { +>A2 : A2 + + get #prop() { return ""; } +>#prop : string +>"" : "" + + set #prop(param: string) { } +>#prop : string +>param : string + + constructor() { + console.log(this.#prop); +>console.log(this.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#prop : string +>this : this + + let a: A2 = this; +>a : A2 +>this : this + + a.#prop; +>a.#prop : string +>a : A2 + + function foo (){ +>foo : () => void + + a.#prop; +>a.#prop : string +>a : A2 + } + } +} +new A2().#prop; // Error +>new A2().#prop : any +>new A2() : A2 +>A2 : typeof A2 + +function foo (){ +>foo : () => void + + new A2().#prop; // Error +>new A2().#prop : any +>new A2() : A2 +>A2 : typeof A2 +} + +class B2 { +>B2 : B2 + + m() { +>m : () => void + + new A2().#prop; +>new A2().#prop : any +>new A2() : A2 +>A2 : typeof A2 + } +} + diff --git a/tests/baselines/reference/privateNameAccessorsCallExpression.js b/tests/baselines/reference/privateNameAccessorsCallExpression.js new file mode 100644 index 0000000000000..a75e534b816a9 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsCallExpression.js @@ -0,0 +1,47 @@ +//// [privateNameAccessorsCallExpression.ts] +class A { + get #fieldFunc() { return function() { this.x = 10; } } + get #fieldFunc2() { return function(a, ...b) {}; } + x = 1; + test() { + this.#fieldFunc(); + const func = this.#fieldFunc; + func(); + new this.#fieldFunc(); + + const arr = [ 1, 2 ]; + this.#fieldFunc2(0, ...arr, 3); + const b = new this.#fieldFunc2(0, ...arr, 3); + const str = this.#fieldFunc2`head${1}middle${2}tail`; + this.getInstance().#fieldFunc2`test${1}and${2}`; + } + getInstance() { return new A(); } +} + +//// [privateNameAccessorsCallExpression.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _A_instances, _A_fieldFunc_get, _A_fieldFunc2_get; +class A { + constructor() { + _A_instances.add(this); + this.x = 1; + } + test() { + var _a; + __classPrivateFieldGet(this, _A_instances, "a", _A_fieldFunc_get).call(this); + const func = __classPrivateFieldGet(this, _A_instances, "a", _A_fieldFunc_get); + func(); + new (__classPrivateFieldGet(this, _A_instances, "a", _A_fieldFunc_get))(); + const arr = [1, 2]; + __classPrivateFieldGet(this, _A_instances, "a", _A_fieldFunc2_get).call(this, 0, ...arr, 3); + const b = new (__classPrivateFieldGet(this, _A_instances, "a", _A_fieldFunc2_get))(0, ...arr, 3); + const str = __classPrivateFieldGet(this, _A_instances, "a", _A_fieldFunc2_get).bind(this) `head${1}middle${2}tail`; + __classPrivateFieldGet((_a = this.getInstance()), _A_instances, "a", _A_fieldFunc2_get).bind(_a) `test${1}and${2}`; + } + getInstance() { return new A(); } +} +_A_instances = new WeakSet(), _A_fieldFunc_get = function _A_fieldFunc_get() { return function () { this.x = 10; }; }, _A_fieldFunc2_get = function _A_fieldFunc2_get() { return function (a, ...b) { }; }; diff --git a/tests/baselines/reference/privateNameAccessorsCallExpression.symbols b/tests/baselines/reference/privateNameAccessorsCallExpression.symbols new file mode 100644 index 0000000000000..93d15d2c33e56 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsCallExpression.symbols @@ -0,0 +1,63 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessorsCallExpression.ts === +class A { +>A : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) + + get #fieldFunc() { return function() { this.x = 10; } } +>#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameAccessorsCallExpression.ts, 0, 9)) + + get #fieldFunc2() { return function(a, ...b) {}; } +>#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameAccessorsCallExpression.ts, 1, 60)) +>a : Symbol(a, Decl(privateNameAccessorsCallExpression.ts, 2, 41)) +>b : Symbol(b, Decl(privateNameAccessorsCallExpression.ts, 2, 43)) + + x = 1; +>x : Symbol(A.x, Decl(privateNameAccessorsCallExpression.ts, 2, 55)) + + test() { +>test : Symbol(A.test, Decl(privateNameAccessorsCallExpression.ts, 3, 10)) + + this.#fieldFunc(); +>this.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameAccessorsCallExpression.ts, 0, 9)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) + + const func = this.#fieldFunc; +>func : Symbol(func, Decl(privateNameAccessorsCallExpression.ts, 6, 13)) +>this.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameAccessorsCallExpression.ts, 0, 9)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) + + func(); +>func : Symbol(func, Decl(privateNameAccessorsCallExpression.ts, 6, 13)) + + new this.#fieldFunc(); +>this.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameAccessorsCallExpression.ts, 0, 9)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) + + const arr = [ 1, 2 ]; +>arr : Symbol(arr, Decl(privateNameAccessorsCallExpression.ts, 10, 13)) + + this.#fieldFunc2(0, ...arr, 3); +>this.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameAccessorsCallExpression.ts, 1, 60)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameAccessorsCallExpression.ts, 10, 13)) + + const b = new this.#fieldFunc2(0, ...arr, 3); +>b : Symbol(b, Decl(privateNameAccessorsCallExpression.ts, 12, 13)) +>this.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameAccessorsCallExpression.ts, 1, 60)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameAccessorsCallExpression.ts, 10, 13)) + + const str = this.#fieldFunc2`head${1}middle${2}tail`; +>str : Symbol(str, Decl(privateNameAccessorsCallExpression.ts, 13, 13)) +>this.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameAccessorsCallExpression.ts, 1, 60)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) + + this.getInstance().#fieldFunc2`test${1}and${2}`; +>this.getInstance().#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameAccessorsCallExpression.ts, 1, 60)) +>this.getInstance : Symbol(A.getInstance, Decl(privateNameAccessorsCallExpression.ts, 15, 5)) +>this : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) +>getInstance : Symbol(A.getInstance, Decl(privateNameAccessorsCallExpression.ts, 15, 5)) + } + getInstance() { return new A(); } +>getInstance : Symbol(A.getInstance, Decl(privateNameAccessorsCallExpression.ts, 15, 5)) +>A : Symbol(A, Decl(privateNameAccessorsCallExpression.ts, 0, 0)) +} diff --git a/tests/baselines/reference/privateNameAccessorsCallExpression.types b/tests/baselines/reference/privateNameAccessorsCallExpression.types new file mode 100644 index 0000000000000..3beb279a5cb3c --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorsCallExpression.types @@ -0,0 +1,95 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessorsCallExpression.ts === +class A { +>A : A + + get #fieldFunc() { return function() { this.x = 10; } } +>#fieldFunc : () => void +>function() { this.x = 10; } : () => void +>this.x = 10 : 10 +>this.x : any +>this : any +>x : any +>10 : 10 + + get #fieldFunc2() { return function(a, ...b) {}; } +>#fieldFunc2 : (a: any, ...b: any[]) => void +>function(a, ...b) {} : (a: any, ...b: any[]) => void +>a : any +>b : any[] + + x = 1; +>x : number +>1 : 1 + + test() { +>test : () => void + + this.#fieldFunc(); +>this.#fieldFunc() : void +>this.#fieldFunc : () => void +>this : this + + const func = this.#fieldFunc; +>func : () => void +>this.#fieldFunc : () => void +>this : this + + func(); +>func() : void +>func : () => void + + new this.#fieldFunc(); +>new this.#fieldFunc() : any +>this.#fieldFunc : () => void +>this : this + + const arr = [ 1, 2 ]; +>arr : number[] +>[ 1, 2 ] : number[] +>1 : 1 +>2 : 2 + + this.#fieldFunc2(0, ...arr, 3); +>this.#fieldFunc2(0, ...arr, 3) : void +>this.#fieldFunc2 : (a: any, ...b: any[]) => void +>this : this +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b = new this.#fieldFunc2(0, ...arr, 3); +>b : any +>new this.#fieldFunc2(0, ...arr, 3) : any +>this.#fieldFunc2 : (a: any, ...b: any[]) => void +>this : this +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str = this.#fieldFunc2`head${1}middle${2}tail`; +>str : void +>this.#fieldFunc2`head${1}middle${2}tail` : void +>this.#fieldFunc2 : (a: any, ...b: any[]) => void +>this : this +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + + this.getInstance().#fieldFunc2`test${1}and${2}`; +>this.getInstance().#fieldFunc2`test${1}and${2}` : void +>this.getInstance().#fieldFunc2 : (a: any, ...b: any[]) => void +>this.getInstance() : A +>this.getInstance : () => A +>this : this +>getInstance : () => A +>`test${1}and${2}` : string +>1 : 1 +>2 : 2 + } + getInstance() { return new A(); } +>getInstance : () => A +>new A() : A +>A : typeof A +} diff --git a/tests/baselines/reference/privateNameAccessorssDerivedClasses.errors.txt b/tests/baselines/reference/privateNameAccessorssDerivedClasses.errors.txt new file mode 100644 index 0000000000000..754827bdcb354 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorssDerivedClasses.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts(9,23): error TS18013: Property '#prop' is not accessible outside class 'Base' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts (1 errors) ==== + class Base { + get #prop(): number { return 123; } + static method(x: Derived) { + console.log(x.#prop); + } + } + class Derived extends Base { + static method(x: Derived) { + console.log(x.#prop); + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'Base' because it has a private identifier. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameAccessorssDerivedClasses.js b/tests/baselines/reference/privateNameAccessorssDerivedClasses.js new file mode 100644 index 0000000000000..fca5cb4544b68 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorssDerivedClasses.js @@ -0,0 +1,35 @@ +//// [privateNameAccessorssDerivedClasses.ts] +class Base { + get #prop(): number { return 123; } + static method(x: Derived) { + console.log(x.#prop); + } +} +class Derived extends Base { + static method(x: Derived) { + console.log(x.#prop); + } +} + + +//// [privateNameAccessorssDerivedClasses.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 _Base_instances, _Base_prop_get; +class Base { + constructor() { + _Base_instances.add(this); + } + static method(x) { + console.log(__classPrivateFieldGet(x, _Base_instances, "a", _Base_prop_get)); + } +} +_Base_instances = new WeakSet(), _Base_prop_get = function _Base_prop_get() { return 123; }; +class Derived extends Base { + static method(x) { + console.log(x.); + } +} diff --git a/tests/baselines/reference/privateNameAccessorssDerivedClasses.symbols b/tests/baselines/reference/privateNameAccessorssDerivedClasses.symbols new file mode 100644 index 0000000000000..771e5bfba3dc6 --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorssDerivedClasses.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts === +class Base { +>Base : Symbol(Base, Decl(privateNameAccessorssDerivedClasses.ts, 0, 0)) + + get #prop(): number { return 123; } +>#prop : Symbol(Base.#prop, Decl(privateNameAccessorssDerivedClasses.ts, 0, 12)) + + static method(x: Derived) { +>method : Symbol(Base.method, Decl(privateNameAccessorssDerivedClasses.ts, 1, 40)) +>x : Symbol(x, Decl(privateNameAccessorssDerivedClasses.ts, 2, 18)) +>Derived : Symbol(Derived, Decl(privateNameAccessorssDerivedClasses.ts, 5, 1)) + + console.log(x.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x.#prop : Symbol(Base.#prop, Decl(privateNameAccessorssDerivedClasses.ts, 0, 12)) +>x : Symbol(x, Decl(privateNameAccessorssDerivedClasses.ts, 2, 18)) + } +} +class Derived extends Base { +>Derived : Symbol(Derived, Decl(privateNameAccessorssDerivedClasses.ts, 5, 1)) +>Base : Symbol(Base, Decl(privateNameAccessorssDerivedClasses.ts, 0, 0)) + + static method(x: Derived) { +>method : Symbol(Derived.method, Decl(privateNameAccessorssDerivedClasses.ts, 6, 28)) +>x : Symbol(x, Decl(privateNameAccessorssDerivedClasses.ts, 7, 18)) +>Derived : Symbol(Derived, Decl(privateNameAccessorssDerivedClasses.ts, 5, 1)) + + console.log(x.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameAccessorssDerivedClasses.ts, 7, 18)) + } +} + diff --git a/tests/baselines/reference/privateNameAccessorssDerivedClasses.types b/tests/baselines/reference/privateNameAccessorssDerivedClasses.types new file mode 100644 index 0000000000000..e25cfbd47532e --- /dev/null +++ b/tests/baselines/reference/privateNameAccessorssDerivedClasses.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts === +class Base { +>Base : Base + + get #prop(): number { return 123; } +>#prop : number +>123 : 123 + + static method(x: Derived) { +>method : (x: Derived) => void +>x : Derived + + console.log(x.#prop); +>console.log(x.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#prop : number +>x : Derived + } +} +class Derived extends Base { +>Derived : Derived +>Base : Base + + static method(x: Derived) { +>method : (x: Derived) => void +>x : Derived + + console.log(x.#prop); +>console.log(x.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#prop : any +>x : Derived + } +} + diff --git a/tests/baselines/reference/privateNameAndAny.errors.txt b/tests/baselines/reference/privateNameAndAny.errors.txt index 51c072c43a83e..dbc6209113729 100644 --- a/tests/baselines/reference/privateNameAndAny.errors.txt +++ b/tests/baselines/reference/privateNameAndAny.errors.txt @@ -1,18 +1,26 @@ -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(5,15): error TS2339: Property '#bar' does not exist on type 'any'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(9,9): error TS2571: Object is of type 'unknown'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(10,9): error TS2571: Object is of type 'unknown'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(10,15): error TS2339: Property '#bar' does not exist on type 'any'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(11,9): error TS2571: Object is of type 'unknown'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(14,15): error TS2339: Property '#foo' does not exist on type 'never'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(15,15): error TS2339: Property '#bar' does not exist on type 'never'. -tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(16,15): error TS2339: Property '#foo' does not exist on type 'never'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(9,15): error TS2339: Property '#bar' does not exist on type 'any'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(13,9): error TS2571: Object is of type 'unknown'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(14,9): error TS2571: Object is of type 'unknown'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(15,9): error TS2571: Object is of type 'unknown'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(16,9): error TS2571: Object is of type 'unknown'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(16,15): error TS2339: Property '#bar' does not exist on type 'any'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(17,9): error TS2571: Object is of type 'unknown'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(20,15): error TS2339: Property '#foo' does not exist on type 'never'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(21,15): error TS2339: Property '#m' does not exist on type 'never'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(22,15): error TS2339: Property '#baz' does not exist on type 'never'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(23,15): error TS2339: Property '#bar' does not exist on type 'never'. +tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(24,15): error TS2339: Property '#foo' does not exist on type 'never'. -==== tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts (8 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts (12 errors) ==== class A { - #foo = true; + #foo = true; + static #baz = 10; + static #m() {} method(thing: any) { thing.#foo; // OK + thing.#m(); + thing.#baz; thing.#bar; // Error ~~~~ !!! error TS2339: Property '#bar' does not exist on type 'any'. @@ -21,6 +29,12 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(16,15) methodU(thing: unknown) { thing.#foo; ~~~~~ +!!! error TS2571: Object is of type 'unknown'. + thing.#m(); + ~~~~~ +!!! error TS2571: Object is of type 'unknown'. + thing.#baz; + ~~~~~ !!! error TS2571: Object is of type 'unknown'. thing.#bar; ~~~~~ @@ -35,6 +49,12 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts(16,15) thing.#foo; ~~~~ !!! error TS2339: Property '#foo' does not exist on type 'never'. + thing.#m(); + ~~ +!!! error TS2339: Property '#m' does not exist on type 'never'. + thing.#baz; + ~~~~ +!!! error TS2339: Property '#baz' does not exist on type 'never'. thing.#bar; ~~~~ !!! error TS2339: Property '#bar' does not exist on type 'never'. diff --git a/tests/baselines/reference/privateNameAndAny.js b/tests/baselines/reference/privateNameAndAny.js index 37d30dc1f5325..146b34fd5affe 100644 --- a/tests/baselines/reference/privateNameAndAny.js +++ b/tests/baselines/reference/privateNameAndAny.js @@ -1,18 +1,26 @@ //// [privateNameAndAny.ts] class A { - #foo = true; + #foo = true; + static #baz = 10; + static #m() {} method(thing: any) { thing.#foo; // OK + thing.#m(); + thing.#baz; thing.#bar; // Error thing.#foo(); } methodU(thing: unknown) { thing.#foo; + thing.#m(); + thing.#baz; thing.#bar; thing.#foo(); } methodN(thing: never) { thing.#foo; + thing.#m(); + thing.#baz; thing.#bar; thing.#foo(); } @@ -21,33 +29,38 @@ class A { //// [privateNameAndAny.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo; +var _a, _A_foo, _A_baz, _A_m; class A { constructor() { - _foo.set(this, true); + _A_foo.set(this, true); } method(thing) { - __classPrivateFieldGet(thing, _foo); // OK + __classPrivateFieldGet(thing, _A_foo, "f"); // OK + __classPrivateFieldGet(thing, _a, "m", _A_m).call(thing); + __classPrivateFieldGet(thing, _a, "f", _A_baz); thing.; // Error - __classPrivateFieldGet(thing, _foo).call(// Error - thing); + __classPrivateFieldGet(thing, _A_foo, "f").call(thing); } methodU(thing) { - __classPrivateFieldGet(thing, _foo); + __classPrivateFieldGet(thing, _A_foo, "f"); + __classPrivateFieldGet(thing, _a, "m", _A_m).call(thing); + __classPrivateFieldGet(thing, _a, "f", _A_baz); thing.; - __classPrivateFieldGet(thing, _foo).call(thing); + __classPrivateFieldGet(thing, _A_foo, "f").call(thing); } methodN(thing) { - __classPrivateFieldGet(thing, _foo); + __classPrivateFieldGet(thing, _A_foo, "f"); + __classPrivateFieldGet(thing, _a, "m", _A_m).call(thing); + __classPrivateFieldGet(thing, _a, "f", _A_baz); thing.; - __classPrivateFieldGet(thing, _foo).call(thing); + __classPrivateFieldGet(thing, _A_foo, "f").call(thing); } } -_foo = new WeakMap(); +_a = A, _A_foo = new WeakMap(), _A_m = function _A_m() { }; +_A_baz = { value: 10 }; ; diff --git a/tests/baselines/reference/privateNameAndAny.symbols b/tests/baselines/reference/privateNameAndAny.symbols index 5a8c528e2ed9b..2d18a97fd431a 100644 --- a/tests/baselines/reference/privateNameAndAny.symbols +++ b/tests/baselines/reference/privateNameAndAny.symbols @@ -2,47 +2,71 @@ class A { >A : Symbol(A, Decl(privateNameAndAny.ts, 0, 0)) - #foo = true; + #foo = true; >#foo : Symbol(A.#foo, Decl(privateNameAndAny.ts, 0, 9)) + static #baz = 10; +>#baz : Symbol(A.#baz, Decl(privateNameAndAny.ts, 1, 16)) + + static #m() {} +>#m : Symbol(A.#m, Decl(privateNameAndAny.ts, 2, 21)) + method(thing: any) { ->method : Symbol(A.method, Decl(privateNameAndAny.ts, 1, 16)) ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11)) +>method : Symbol(A.method, Decl(privateNameAndAny.ts, 3, 18)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 4, 11)) thing.#foo; // OK ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 4, 11)) + + thing.#m(); +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 4, 11)) + + thing.#baz; +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 4, 11)) thing.#bar; // Error ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 4, 11)) thing.#foo(); ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 2, 11)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 4, 11)) } methodU(thing: unknown) { ->methodU : Symbol(A.methodU, Decl(privateNameAndAny.ts, 6, 5)) ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 7, 12)) +>methodU : Symbol(A.methodU, Decl(privateNameAndAny.ts, 10, 5)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 11, 12)) thing.#foo; ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 7, 12)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 11, 12)) + + thing.#m(); +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 11, 12)) + + thing.#baz; +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 11, 12)) thing.#bar; ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 7, 12)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 11, 12)) thing.#foo(); ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 7, 12)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 11, 12)) } methodN(thing: never) { ->methodN : Symbol(A.methodN, Decl(privateNameAndAny.ts, 11, 5)) ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 12, 12)) +>methodN : Symbol(A.methodN, Decl(privateNameAndAny.ts, 17, 5)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 18, 12)) thing.#foo; ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 12, 12)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 18, 12)) + + thing.#m(); +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 18, 12)) + + thing.#baz; +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 18, 12)) thing.#bar; ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 12, 12)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 18, 12)) thing.#foo(); ->thing : Symbol(thing, Decl(privateNameAndAny.ts, 12, 12)) +>thing : Symbol(thing, Decl(privateNameAndAny.ts, 18, 12)) } }; diff --git a/tests/baselines/reference/privateNameAndAny.types b/tests/baselines/reference/privateNameAndAny.types index 4216626f5a73d..8ac6efcbf2bfa 100644 --- a/tests/baselines/reference/privateNameAndAny.types +++ b/tests/baselines/reference/privateNameAndAny.types @@ -2,16 +2,32 @@ class A { >A : A - #foo = true; + #foo = true; >#foo : boolean >true : true + static #baz = 10; +>#baz : number +>10 : 10 + + static #m() {} +>#m : () => void + method(thing: any) { >method : (thing: any) => void >thing : any thing.#foo; // OK >thing.#foo : any +>thing : any + + thing.#m(); +>thing.#m() : any +>thing.#m : any +>thing : any + + thing.#baz; +>thing.#baz : any >thing : any thing.#bar; // Error @@ -29,6 +45,15 @@ class A { thing.#foo; >thing.#foo : any +>thing : unknown + + thing.#m(); +>thing.#m() : any +>thing.#m : any +>thing : unknown + + thing.#baz; +>thing.#baz : any >thing : unknown thing.#bar; @@ -46,6 +71,15 @@ class A { thing.#foo; >thing.#foo : any +>thing : never + + thing.#m(); +>thing.#m() : any +>thing.#m : any +>thing : never + + thing.#baz; +>thing.#baz : any >thing : never thing.#bar; diff --git a/tests/baselines/reference/privateNameAndIndexSignature.js b/tests/baselines/reference/privateNameAndIndexSignature.js index 693c3900e954f..4724aaea0f5c5 100644 --- a/tests/baselines/reference/privateNameAndIndexSignature.js +++ b/tests/baselines/reference/privateNameAndIndexSignature.js @@ -13,13 +13,13 @@ class A { //// [privateNameAndIndexSignature.js] "use strict"; -var _foo; +var _A_foo; class A { constructor(message) { - _foo.set(this, 3); + _A_foo.set(this, 3); this["#bar"] = this["#bar"]; // Error (private identifiers should not prevent circularity checking for computeds) this. = 3; // Error (index signatures do not implicitly declare private names) this["#foo"] = 3; // Okay (type has index signature and "#foo" does not collide with private identifier #foo) } } -_foo = new WeakMap(); +_A_foo = new WeakMap(); diff --git a/tests/baselines/reference/privateNameAndObjectRestSpread.errors.txt b/tests/baselines/reference/privateNameAndObjectRestSpread.errors.txt index e55f40f3ba4d6..e4f5e59b9e580 100644 --- a/tests/baselines/reference/privateNameAndObjectRestSpread.errors.txt +++ b/tests/baselines/reference/privateNameAndObjectRestSpread.errors.txt @@ -1,10 +1,13 @@ -tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(6,13): error TS2339: Property '#prop' does not exist on type '{}'. -tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(8,14): error TS2339: Property '#prop' does not exist on type '{}'. +tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(7,13): error TS2339: Property '#prop' does not exist on type '{}'. +tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(9,14): error TS2339: Property '#prop' does not exist on type '{}'. +tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(12,17): error TS2339: Property '#propStatic' does not exist on type '{ prototype: C; }'. +tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts(14,15): error TS2339: Property '#propStatic' does not exist on type '{ prototype: C; }'. -==== tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts (2 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts (4 errors) ==== class C { #prop = 1; + static #propStatic = 1; method(other: C) { const obj = { ...other }; @@ -15,5 +18,14 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpr rest.#prop; ~~~~~ !!! error TS2339: Property '#prop' does not exist on type '{}'. + + const statics = { ... C}; + statics.#propStatic + ~~~~~~~~~~~ +!!! error TS2339: Property '#propStatic' does not exist on type '{ prototype: C; }'. + const { ...sRest } = C; + sRest.#propStatic; + ~~~~~~~~~~~ +!!! error TS2339: Property '#propStatic' does not exist on type '{ prototype: C; }'. } } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameAndObjectRestSpread.js b/tests/baselines/reference/privateNameAndObjectRestSpread.js index 98a109257ae1e..64247610dfd91 100644 --- a/tests/baselines/reference/privateNameAndObjectRestSpread.js +++ b/tests/baselines/reference/privateNameAndObjectRestSpread.js @@ -1,22 +1,27 @@ //// [privateNameAndObjectRestSpread.ts] class C { #prop = 1; + static #propStatic = 1; method(other: C) { const obj = { ...other }; obj.#prop; const { ...rest } = other; rest.#prop; + + const statics = { ... C}; + statics.#propStatic + const { ...sRest } = C; + sRest.#propStatic; } } //// [privateNameAndObjectRestSpread.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 __rest = (this && this.__rest) || function (s, e) { var t = {}; @@ -29,16 +34,21 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; -var _prop; +var _a, _C_prop, _C_propStatic; class C { constructor() { - _prop.set(this, 1); + _C_prop.set(this, 1); } method(other) { const obj = Object.assign({}, other); - __classPrivateFieldGet(obj, _prop); + __classPrivateFieldGet(obj, _C_prop, "f"); const rest = __rest(other, []); - __classPrivateFieldGet(rest, _prop); + __classPrivateFieldGet(rest, _C_prop, "f"); + const statics = Object.assign({}, C); + __classPrivateFieldGet(statics, _a, "f", _C_propStatic); + const sRest = __rest(C, []); + __classPrivateFieldGet(sRest, _a, "f", _C_propStatic); } } -_prop = new WeakMap(); +_a = C, _C_prop = new WeakMap(); +_C_propStatic = { value: 1 }; diff --git a/tests/baselines/reference/privateNameAndObjectRestSpread.symbols b/tests/baselines/reference/privateNameAndObjectRestSpread.symbols index b9b3ef5eed438..8d930393ee143 100644 --- a/tests/baselines/reference/privateNameAndObjectRestSpread.symbols +++ b/tests/baselines/reference/privateNameAndObjectRestSpread.symbols @@ -5,23 +5,40 @@ class C { #prop = 1; >#prop : Symbol(C.#prop, Decl(privateNameAndObjectRestSpread.ts, 0, 9)) + static #propStatic = 1; +>#propStatic : Symbol(C.#propStatic, Decl(privateNameAndObjectRestSpread.ts, 1, 14)) + method(other: C) { ->method : Symbol(C.method, Decl(privateNameAndObjectRestSpread.ts, 1, 14)) ->other : Symbol(other, Decl(privateNameAndObjectRestSpread.ts, 3, 11)) +>method : Symbol(C.method, Decl(privateNameAndObjectRestSpread.ts, 2, 27)) +>other : Symbol(other, Decl(privateNameAndObjectRestSpread.ts, 4, 11)) >C : Symbol(C, Decl(privateNameAndObjectRestSpread.ts, 0, 0)) const obj = { ...other }; ->obj : Symbol(obj, Decl(privateNameAndObjectRestSpread.ts, 4, 13)) ->other : Symbol(other, Decl(privateNameAndObjectRestSpread.ts, 3, 11)) +>obj : Symbol(obj, Decl(privateNameAndObjectRestSpread.ts, 5, 13)) +>other : Symbol(other, Decl(privateNameAndObjectRestSpread.ts, 4, 11)) obj.#prop; ->obj : Symbol(obj, Decl(privateNameAndObjectRestSpread.ts, 4, 13)) +>obj : Symbol(obj, Decl(privateNameAndObjectRestSpread.ts, 5, 13)) const { ...rest } = other; ->rest : Symbol(rest, Decl(privateNameAndObjectRestSpread.ts, 6, 15)) ->other : Symbol(other, Decl(privateNameAndObjectRestSpread.ts, 3, 11)) +>rest : Symbol(rest, Decl(privateNameAndObjectRestSpread.ts, 7, 15)) +>other : Symbol(other, Decl(privateNameAndObjectRestSpread.ts, 4, 11)) rest.#prop; ->rest : Symbol(rest, Decl(privateNameAndObjectRestSpread.ts, 6, 15)) +>rest : Symbol(rest, Decl(privateNameAndObjectRestSpread.ts, 7, 15)) + + const statics = { ... C}; +>statics : Symbol(statics, Decl(privateNameAndObjectRestSpread.ts, 10, 13)) +>C : Symbol(C, Decl(privateNameAndObjectRestSpread.ts, 0, 0)) + + statics.#propStatic +>statics : Symbol(statics, Decl(privateNameAndObjectRestSpread.ts, 10, 13)) + + const { ...sRest } = C; +>sRest : Symbol(sRest, Decl(privateNameAndObjectRestSpread.ts, 12, 15)) +>C : Symbol(C, Decl(privateNameAndObjectRestSpread.ts, 0, 0)) + + sRest.#propStatic; +>sRest : Symbol(sRest, Decl(privateNameAndObjectRestSpread.ts, 12, 15)) } } diff --git a/tests/baselines/reference/privateNameAndObjectRestSpread.types b/tests/baselines/reference/privateNameAndObjectRestSpread.types index 0bab5992fa62c..96af44dbf5917 100644 --- a/tests/baselines/reference/privateNameAndObjectRestSpread.types +++ b/tests/baselines/reference/privateNameAndObjectRestSpread.types @@ -4,6 +4,10 @@ class C { #prop = 1; >#prop : number +>1 : 1 + + static #propStatic = 1; +>#propStatic : number >1 : 1 method(other: C) { @@ -26,5 +30,22 @@ class C { rest.#prop; >rest.#prop : any >rest : {} + + const statics = { ... C}; +>statics : { prototype: C; } +>{ ... C} : { prototype: C; } +>C : typeof C + + statics.#propStatic +>statics.#propStatic : any +>statics : { prototype: C; } + + const { ...sRest } = C; +>sRest : { prototype: C; } +>C : typeof C + + sRest.#propStatic; +>sRest.#propStatic : any +>sRest : { prototype: C; } } } diff --git a/tests/baselines/reference/privateNameAndPropertySignature.errors.txt b/tests/baselines/reference/privateNameAndPropertySignature.errors.txt index ef7a8276fdc2a..37653c75ae594 100644 --- a/tests/baselines/reference/privateNameAndPropertySignature.errors.txt +++ b/tests/baselines/reference/privateNameAndPropertySignature.errors.txt @@ -1,20 +1,30 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(2,5): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(6,5): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(10,5): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(12,9): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(16,28): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(3,5): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(7,5): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(8,5): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(12,5): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(14,9): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(15,9): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(17,5): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts(20,28): error TS18016: Private identifiers are not allowed outside class bodies. -==== tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts (5 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts (9 errors) ==== type A = { - #foo: string + #foo: string; ~~~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #bar(): string; + ~~~~~~~~~~~~~~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } interface B { #foo: string; ~~~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #bar(): string; + ~~~~~~~~~~~~~~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } @@ -25,8 +35,14 @@ tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySigna bar: { #baz: string; ~~~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #taz(): string; + ~~~~~~~~~~~~~~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } + #baz(): string; + ~~~~~~~~~~~~~~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. }; declare const y: [{ qux: { #quux: 3 } }]; diff --git a/tests/baselines/reference/privateNameAndPropertySignature.js b/tests/baselines/reference/privateNameAndPropertySignature.js index 602e1159171a5..ad9f8270863d6 100644 --- a/tests/baselines/reference/privateNameAndPropertySignature.js +++ b/tests/baselines/reference/privateNameAndPropertySignature.js @@ -1,17 +1,21 @@ //// [privateNameAndPropertySignature.ts] type A = { - #foo: string + #foo: string; + #bar(): string; } interface B { #foo: string; + #bar(): string; } declare const x: { #foo: number; bar: { #baz: string; + #taz(): string; } + #baz(): string; }; declare const y: [{ qux: { #quux: 3 } }]; diff --git a/tests/baselines/reference/privateNameAndPropertySignature.symbols b/tests/baselines/reference/privateNameAndPropertySignature.symbols index da68133a97edf..1e270e73a839b 100644 --- a/tests/baselines/reference/privateNameAndPropertySignature.symbols +++ b/tests/baselines/reference/privateNameAndPropertySignature.symbols @@ -2,33 +2,45 @@ type A = { >A : Symbol(A, Decl(privateNameAndPropertySignature.ts, 0, 0)) - #foo: string + #foo: string; >#foo : Symbol(#foo, Decl(privateNameAndPropertySignature.ts, 0, 10)) + + #bar(): string; +>#bar : Symbol(#bar, Decl(privateNameAndPropertySignature.ts, 1, 17)) } interface B { ->B : Symbol(B, Decl(privateNameAndPropertySignature.ts, 2, 1)) +>B : Symbol(B, Decl(privateNameAndPropertySignature.ts, 3, 1)) #foo: string; ->#foo : Symbol(B.#foo, Decl(privateNameAndPropertySignature.ts, 4, 13)) +>#foo : Symbol(B.#foo, Decl(privateNameAndPropertySignature.ts, 5, 13)) + + #bar(): string; +>#bar : Symbol(B.#bar, Decl(privateNameAndPropertySignature.ts, 6, 17)) } declare const x: { ->x : Symbol(x, Decl(privateNameAndPropertySignature.ts, 8, 13)) +>x : Symbol(x, Decl(privateNameAndPropertySignature.ts, 10, 13)) #foo: number; ->#foo : Symbol(#foo, Decl(privateNameAndPropertySignature.ts, 8, 18)) +>#foo : Symbol(#foo, Decl(privateNameAndPropertySignature.ts, 10, 18)) bar: { ->bar : Symbol(bar, Decl(privateNameAndPropertySignature.ts, 9, 17)) +>bar : Symbol(bar, Decl(privateNameAndPropertySignature.ts, 11, 17)) #baz: string; ->#baz : Symbol(#baz, Decl(privateNameAndPropertySignature.ts, 10, 10)) +>#baz : Symbol(#baz, Decl(privateNameAndPropertySignature.ts, 12, 10)) + + #taz(): string; +>#taz : Symbol(#taz, Decl(privateNameAndPropertySignature.ts, 13, 21)) } + #baz(): string; +>#baz : Symbol(#baz, Decl(privateNameAndPropertySignature.ts, 15, 5)) + }; declare const y: [{ qux: { #quux: 3 } }]; ->y : Symbol(y, Decl(privateNameAndPropertySignature.ts, 15, 13)) ->qux : Symbol(qux, Decl(privateNameAndPropertySignature.ts, 15, 19)) ->#quux : Symbol(#quux, Decl(privateNameAndPropertySignature.ts, 15, 26)) +>y : Symbol(y, Decl(privateNameAndPropertySignature.ts, 19, 13)) +>qux : Symbol(qux, Decl(privateNameAndPropertySignature.ts, 19, 19)) +>#quux : Symbol(#quux, Decl(privateNameAndPropertySignature.ts, 19, 26)) diff --git a/tests/baselines/reference/privateNameAndPropertySignature.types b/tests/baselines/reference/privateNameAndPropertySignature.types index efe0dfbffd673..3ff962d53e007 100644 --- a/tests/baselines/reference/privateNameAndPropertySignature.types +++ b/tests/baselines/reference/privateNameAndPropertySignature.types @@ -2,17 +2,23 @@ type A = { >A : A - #foo: string + #foo: string; >#foo : string + + #bar(): string; +>#bar : () => string } interface B { #foo: string; >#foo : string + + #bar(): string; +>#bar : () => string } declare const x: { ->x : { bar: { #baz: string;}; } +>x : { bar: { #baz: string; #taz(): string;}; } #foo: number; >#foo : number @@ -22,7 +28,13 @@ declare const x: { #baz: string; >#baz : string + + #taz(): string; +>#taz : () => string } + #baz(): string; +>#baz : () => string + }; declare const y: [{ qux: { #quux: 3 } }]; diff --git a/tests/baselines/reference/privateNameAndStaticInitializer(target=es2015).js b/tests/baselines/reference/privateNameAndStaticInitializer(target=es2015).js index caeb43d15a3e9..b430336781640 100644 --- a/tests/baselines/reference/privateNameAndStaticInitializer(target=es2015).js +++ b/tests/baselines/reference/privateNameAndStaticInitializer(target=es2015).js @@ -8,12 +8,12 @@ class A { //// [privateNameAndStaticInitializer.js] -var _foo, _prop; +var _A_foo, _A_prop; class A { constructor() { - _foo.set(this, 1); - _prop.set(this, 2); + _A_foo.set(this, 1); + _A_prop.set(this, 2); } } -_foo = new WeakMap(), _prop = new WeakMap(); +_A_foo = new WeakMap(), _A_prop = new WeakMap(); A.inst = new A(); diff --git a/tests/baselines/reference/privateNameBadAssignment.js b/tests/baselines/reference/privateNameBadAssignment.js index a3f937396b0f6..aad5f192333bc 100644 --- a/tests/baselines/reference/privateNameBadAssignment.js +++ b/tests/baselines/reference/privateNameBadAssignment.js @@ -16,14 +16,13 @@ class C { //// [privateNameBadAssignment.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _bar; +var _C_bar; exports. = 1; // Error (outside class body) function A() { } A.prototype. = 2; // Error (outside class body) @@ -32,9 +31,9 @@ class B { B. = 3; // Error (outside class body) class C { constructor() { - _bar.set(this, 6); - __classPrivateFieldSet(exports, _bar, 6); // Error + _C_bar.set(this, 6); + __classPrivateFieldSet(exports, _C_bar, 6, "f"); // Error this. = 3; // Error (undeclared) } } -_bar = new WeakMap(); +_C_bar = new WeakMap(); diff --git a/tests/baselines/reference/privateNameBadDeclaration.errors.txt b/tests/baselines/reference/privateNameBadDeclaration.errors.txt index 71cf3f2089a2a..b05d61c4bf7b9 100644 --- a/tests/baselines/reference/privateNameBadDeclaration.errors.txt +++ b/tests/baselines/reference/privateNameBadDeclaration.errors.txt @@ -1,19 +1,41 @@ tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(3,3): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(7,3): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(11,10): error TS2339: Property '#z' does not exist on type 'C'. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(4,3): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(5,7): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(5,7): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(9,3): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(10,3): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(11,7): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(11,7): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts(15,10): error TS2339: Property '#z' does not exist on type 'C'. -==== tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts (3 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts (9 errors) ==== function A() { } A.prototype = { - #x: 1 // Error + #x: 1, // Error ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #m() {}, // Error + ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + get #p() { return "" } // Error + ~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } class B { } B.prototype = { - #y: 2 // Error + #y: 2, // Error ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #m() {}, // Error + ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + get #p() { return "" } // Error + ~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } class C { diff --git a/tests/baselines/reference/privateNameBadDeclaration.js b/tests/baselines/reference/privateNameBadDeclaration.js index 068720a03a8cf..cf110de187dbe 100644 --- a/tests/baselines/reference/privateNameBadDeclaration.js +++ b/tests/baselines/reference/privateNameBadDeclaration.js @@ -1,11 +1,15 @@ //// [privateNameBadDeclaration.ts] function A() { } A.prototype = { - #x: 1 // Error + #x: 1, // Error + #m() {}, // Error + get #p() { return "" } // Error } class B { } B.prototype = { - #y: 2 // Error + #y: 2, // Error + #m() {}, // Error + get #p() { return "" } // Error } class C { constructor() { @@ -16,7 +20,9 @@ class C { //// [privateNameBadDeclaration.js] function A() { } A.prototype = { - : 1 // Error + : 1, + : function () { }, + get () { return ""; } // Error }; var B = /** @class */ (function () { function B() { @@ -24,7 +30,9 @@ var B = /** @class */ (function () { return B; }()); B.prototype = { - : 2 // Error + : 2, + : function () { }, + get () { return ""; } // Error }; var C = /** @class */ (function () { function C() { diff --git a/tests/baselines/reference/privateNameBadDeclaration.symbols b/tests/baselines/reference/privateNameBadDeclaration.symbols index d689169f7115f..ed3ca5e455c10 100644 --- a/tests/baselines/reference/privateNameBadDeclaration.symbols +++ b/tests/baselines/reference/privateNameBadDeclaration.symbols @@ -7,25 +7,37 @@ A.prototype = { >A : Symbol(A, Decl(privateNameBadDeclaration.ts, 0, 0)) >prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --)) - #x: 1 // Error + #x: 1, // Error >#x : Symbol(#x, Decl(privateNameBadDeclaration.ts, 1, 15)) + + #m() {}, // Error +>#m : Symbol(#m, Decl(privateNameBadDeclaration.ts, 2, 8)) + + get #p() { return "" } // Error +>#p : Symbol(#p, Decl(privateNameBadDeclaration.ts, 3, 10)) } class B { } ->B : Symbol(B, Decl(privateNameBadDeclaration.ts, 3, 1)) +>B : Symbol(B, Decl(privateNameBadDeclaration.ts, 5, 1)) B.prototype = { >B.prototype : Symbol(B.prototype) ->B : Symbol(B, Decl(privateNameBadDeclaration.ts, 3, 1)) +>B : Symbol(B, Decl(privateNameBadDeclaration.ts, 5, 1)) >prototype : Symbol(B.prototype) - #y: 2 // Error ->#y : Symbol(#y, Decl(privateNameBadDeclaration.ts, 5, 15)) + #y: 2, // Error +>#y : Symbol(#y, Decl(privateNameBadDeclaration.ts, 7, 15)) + + #m() {}, // Error +>#m : Symbol(#m, Decl(privateNameBadDeclaration.ts, 8, 8)) + + get #p() { return "" } // Error +>#p : Symbol(#p, Decl(privateNameBadDeclaration.ts, 9, 10)) } class C { ->C : Symbol(C, Decl(privateNameBadDeclaration.ts, 7, 1)) +>C : Symbol(C, Decl(privateNameBadDeclaration.ts, 11, 1)) constructor() { this.#z = 3; ->this : Symbol(C, Decl(privateNameBadDeclaration.ts, 7, 1)) +>this : Symbol(C, Decl(privateNameBadDeclaration.ts, 11, 1)) } } diff --git a/tests/baselines/reference/privateNameBadDeclaration.types b/tests/baselines/reference/privateNameBadDeclaration.types index a84048bde966c..8dc5b5f65cba4 100644 --- a/tests/baselines/reference/privateNameBadDeclaration.types +++ b/tests/baselines/reference/privateNameBadDeclaration.types @@ -3,29 +3,43 @@ function A() { } >A : () => void A.prototype = { ->A.prototype = { #x: 1 // Error} : {} +>A.prototype = { #x: 1, // Error #m() {}, // Error get #p() { return "" } // Error} : {} >A.prototype : any >A : () => void >prototype : any ->{ #x: 1 // Error} : {} +>{ #x: 1, // Error #m() {}, // Error get #p() { return "" } // Error} : {} - #x: 1 // Error + #x: 1, // Error >#x : number >1 : 1 + + #m() {}, // Error +>#m : () => void + + get #p() { return "" } // Error +>#p : string +>"" : "" } class B { } >B : B B.prototype = { ->B.prototype = { #y: 2 // Error} : {} +>B.prototype = { #y: 2, // Error #m() {}, // Error get #p() { return "" } // Error} : {} >B.prototype : B >B : typeof B >prototype : B ->{ #y: 2 // Error} : {} +>{ #y: 2, // Error #m() {}, // Error get #p() { return "" } // Error} : {} - #y: 2 // Error + #y: 2, // Error >#y : number >2 : 2 + + #m() {}, // Error +>#m : () => void + + get #p() { return "" } // Error +>#p : string +>"" : "" } class C { >C : C diff --git a/tests/baselines/reference/privateNameBadSuper.js b/tests/baselines/reference/privateNameBadSuper.js index 07d8c2324f5cf..ac4a4a80695f1 100644 --- a/tests/baselines/reference/privateNameBadSuper.js +++ b/tests/baselines/reference/privateNameBadSuper.js @@ -9,7 +9,7 @@ class A extends B { } //// [privateNameBadSuper.js] -var _x; +var _A_x; class B { } ; @@ -17,7 +17,7 @@ class A extends B { constructor() { void 0; // Error: 'super' call must come first super(); - _x.set(this, void 0); + _A_x.set(this, void 0); } } -_x = new WeakMap(); +_A_x = new WeakMap(); diff --git a/tests/baselines/reference/privateNameCircularReference.js b/tests/baselines/reference/privateNameCircularReference.js index 7d3ef6d1d022d..a88e94a11ef8b 100644 --- a/tests/baselines/reference/privateNameCircularReference.js +++ b/tests/baselines/reference/privateNameCircularReference.js @@ -8,18 +8,17 @@ class A { //// [privateNameCircularReference.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _bar; +var _A_foo, _A_bar; class A { constructor() { - _foo.set(this, __classPrivateFieldGet(this, _bar)); - _bar.set(this, __classPrivateFieldGet(this, _foo)); + _A_foo.set(this, __classPrivateFieldGet(this, _A_bar, "f")); + _A_bar.set(this, __classPrivateFieldGet(this, _A_foo, "f")); this["#baz"] = this["#baz"]; // Error (should *not* be private name error) } } -_foo = new WeakMap(), _bar = new WeakMap(); +_A_foo = new WeakMap(), _A_bar = new WeakMap(); diff --git a/tests/baselines/reference/privateNameClassExpressionLoop.js b/tests/baselines/reference/privateNameClassExpressionLoop.js index bd83a8c9db829..dac5891a65ec3 100644 --- a/tests/baselines/reference/privateNameClassExpressionLoop.js +++ b/tests/baselines/reference/privateNameClassExpressionLoop.js @@ -3,6 +3,9 @@ const array = []; for (let i = 0; i < 10; ++i) { array.push(class C { #myField = "hello"; + #method() {} + get #accessor() { return 42; } + set #accessor(val) { } }); } @@ -11,12 +14,17 @@ for (let i = 0; i < 10; ++i) { var _a; const array = []; for (let i = 0; i < 10; ++i) { - let _myField; + let _C_instances, _C_myField, _C_method, _C_accessor_get, _C_accessor_set; array.push((_a = class C { constructor() { - _myField.set(this, "hello"); + _C_instances.add(this); + _C_myField.set(this, "hello"); } }, - _myField = new WeakMap(), + _C_myField = new WeakMap(), + _C_instances = new WeakSet(), + _C_method = function _C_method() { }, + _C_accessor_get = function _C_accessor_get() { return 42; }, + _C_accessor_set = function _C_accessor_set(val) { }, _a)); } diff --git a/tests/baselines/reference/privateNameClassExpressionLoop.symbols b/tests/baselines/reference/privateNameClassExpressionLoop.symbols index ac503fc6c9c08..3f303cbdde849 100644 --- a/tests/baselines/reference/privateNameClassExpressionLoop.symbols +++ b/tests/baselines/reference/privateNameClassExpressionLoop.symbols @@ -16,6 +16,16 @@ for (let i = 0; i < 10; ++i) { #myField = "hello"; >#myField : Symbol(C.#myField, Decl(privateNameClassExpressionLoop.ts, 2, 24)) + #method() {} +>#method : Symbol(C.#method, Decl(privateNameClassExpressionLoop.ts, 3, 27)) + + get #accessor() { return 42; } +>#accessor : Symbol(C.#accessor, Decl(privateNameClassExpressionLoop.ts, 4, 20), Decl(privateNameClassExpressionLoop.ts, 5, 38)) + + set #accessor(val) { } +>#accessor : Symbol(C.#accessor, Decl(privateNameClassExpressionLoop.ts, 4, 20), Decl(privateNameClassExpressionLoop.ts, 5, 38)) +>val : Symbol(val, Decl(privateNameClassExpressionLoop.ts, 6, 22)) + }); } diff --git a/tests/baselines/reference/privateNameClassExpressionLoop.types b/tests/baselines/reference/privateNameClassExpressionLoop.types index 5775f9fd042d8..5367c80e5db06 100644 --- a/tests/baselines/reference/privateNameClassExpressionLoop.types +++ b/tests/baselines/reference/privateNameClassExpressionLoop.types @@ -13,17 +13,28 @@ for (let i = 0; i < 10; ++i) { >i : number array.push(class C { ->array.push(class C { #myField = "hello"; }) : number +>array.push(class C { #myField = "hello"; #method() {} get #accessor() { return 42; } set #accessor(val) { } }) : number >array.push : (...items: any[]) => number >array : any[] >push : (...items: any[]) => number ->class C { #myField = "hello"; } : typeof C +>class C { #myField = "hello"; #method() {} get #accessor() { return 42; } set #accessor(val) { } } : typeof C >C : typeof C #myField = "hello"; >#myField : string >"hello" : "hello" + #method() {} +>#method : () => void + + get #accessor() { return 42; } +>#accessor : number +>42 : 42 + + set #accessor(val) { } +>#accessor : number +>val : number + }); } diff --git a/tests/baselines/reference/privateNameComputedPropertyName1(target=es2015).js b/tests/baselines/reference/privateNameComputedPropertyName1(target=es2015).js index 966a81e23a1b0..ce7464a5541ec 100644 --- a/tests/baselines/reference/privateNameComputedPropertyName1(target=es2015).js +++ b/tests/baselines/reference/privateNameComputedPropertyName1(target=es2015).js @@ -38,41 +38,39 @@ new A().test(); //// [privateNameComputedPropertyName1.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; -var _a, _b, _c, _d, _e; +var _A_a, _A_b, _A_c, _A_d, _A_e; class A { constructor() { - _a.set(this, 'a'); - _b.set(this, void 0); - _c.set(this, 'c'); - _d.set(this, void 0); - _e.set(this, ''); - __classPrivateFieldSet(this, _b, 'b'); - __classPrivateFieldSet(this, _d, 'd'); + _A_a.set(this, 'a'); + _A_b.set(this, void 0); + _A_c.set(this, 'c'); + _A_d.set(this, void 0); + _A_e.set(this, ''); + __classPrivateFieldSet(this, _A_b, 'b', "f"); + __classPrivateFieldSet(this, _A_d, 'd', "f"); } test() { const data = { a: 'a', b: 'b', c: 'c', d: 'd', e: 'e' }; - const { [__classPrivateFieldGet(this, _a)]: a, [__classPrivateFieldGet(this, _b)]: b, [__classPrivateFieldGet(this, _c)]: c, [__classPrivateFieldGet(this, _d)]: d, [__classPrivateFieldSet(this, _e, 'e')]: e, } = data; + const { [__classPrivateFieldGet(this, _A_a, "f")]: a, [__classPrivateFieldGet(this, _A_b, "f")]: b, [__classPrivateFieldGet(this, _A_c, "f")]: c, [__classPrivateFieldGet(this, _A_d, "f")]: d, [__classPrivateFieldSet(this, _A_e, 'e', "f")]: e, } = data; console.log(a, b, c, d, e); - const a1 = data[__classPrivateFieldGet(this, _a)]; - const b1 = data[__classPrivateFieldGet(this, _b)]; - const c1 = data[__classPrivateFieldGet(this, _c)]; - const d1 = data[__classPrivateFieldGet(this, _d)]; - const e1 = data[__classPrivateFieldGet(this, _e)]; + const a1 = data[__classPrivateFieldGet(this, _A_a, "f")]; + const b1 = data[__classPrivateFieldGet(this, _A_b, "f")]; + const c1 = data[__classPrivateFieldGet(this, _A_c, "f")]; + const d1 = data[__classPrivateFieldGet(this, _A_d, "f")]; + const e1 = data[__classPrivateFieldGet(this, _A_e, "f")]; console.log(a1, b1, c1, d1); } } -_a = new WeakMap(), _b = new WeakMap(), _c = new WeakMap(), _d = new WeakMap(), _e = new WeakMap(); +_A_a = new WeakMap(), _A_b = new WeakMap(), _A_c = new WeakMap(), _A_d = new WeakMap(), _A_e = new WeakMap(); new A().test(); diff --git a/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js b/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js index fcb4dc6d17f3d..248d8203636d6 100644 --- a/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js +++ b/tests/baselines/reference/privateNameComputedPropertyName2(target=es2015).js @@ -10,18 +10,17 @@ console.log(getX(new A)); //// [privateNameComputedPropertyName2.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _x; +var _A_x; let getX; class A { constructor() { - _x.set(this, 100); + _A_x.set(this, 100); } - [(_x = new WeakMap(), (getX = (a) => __classPrivateFieldGet(a, _x), "_"))]() { } + [(_A_x = new WeakMap(), (getX = (a) => __classPrivateFieldGet(a, _A_x, "f"), "_"))]() { } } console.log(getX(new A)); diff --git a/tests/baselines/reference/privateNameComputedPropertyName3(target=es2015).js b/tests/baselines/reference/privateNameComputedPropertyName3(target=es2015).js index bb6bc692a330f..03fc2a9272b21 100644 --- a/tests/baselines/reference/privateNameComputedPropertyName3(target=es2015).js +++ b/tests/baselines/reference/privateNameComputedPropertyName3(target=es2015).js @@ -25,38 +25,36 @@ console.log(new Foo("NAME").getValue(100)); //// [privateNameComputedPropertyName3.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _name; +var _Foo_name; class Foo { constructor(name) { - _name.set(this, void 0); - __classPrivateFieldSet(this, _name, name); + _Foo_name.set(this, void 0); + __classPrivateFieldSet(this, _Foo_name, name, "f"); } getValue(x) { - var _y; + var _Bar_y; const obj = this; class Bar { constructor() { - _y.set(this, 100); + _Bar_y.set(this, 100); } - [(_y = new WeakMap(), __classPrivateFieldGet(obj, _name))]() { - return x + __classPrivateFieldGet(this, _y); + [(_Bar_y = new WeakMap(), __classPrivateFieldGet(obj, _Foo_name, "f"))]() { + return x + __classPrivateFieldGet(this, _Bar_y, "f"); } } - return new Bar()[__classPrivateFieldGet(obj, _name)](); + return new Bar()[__classPrivateFieldGet(obj, _Foo_name, "f")](); } } -_name = new WeakMap(); +_Foo_name = new WeakMap(); console.log(new Foo("NAME").getValue(100)); diff --git a/tests/baselines/reference/privateNameConstructorReserved.errors.txt b/tests/baselines/reference/privateNameConstructorReserved.errors.txt index 4cc4131338f00..6ac1e71bfc6a5 100644 --- a/tests/baselines/reference/privateNameConstructorReserved.errors.txt +++ b/tests/baselines/reference/privateNameConstructorReserved.errors.txt @@ -1,13 +1,10 @@ tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts(2,5): error TS18012: '#constructor' is a reserved word. -tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts(2,5): error TS18022: A method cannot be named with a private identifier. -==== tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts (2 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts (1 errors) ==== class A { #constructor() {} // Error: `#constructor` is a reserved word. ~~~~~~~~~~~~ !!! error TS18012: '#constructor' is a reserved word. - ~~~~~~~~~~~~ -!!! error TS18022: A method cannot be named with a private identifier. } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameConstructorReserved.js b/tests/baselines/reference/privateNameConstructorReserved.js index 54cae241f51da..9e6a7eb62da90 100644 --- a/tests/baselines/reference/privateNameConstructorReserved.js +++ b/tests/baselines/reference/privateNameConstructorReserved.js @@ -5,6 +5,11 @@ class A { //// [privateNameConstructorReserved.js] +var _A_instances, _A_constructor; class A { - () { } // Error: `#constructor` is a reserved word. + constructor() { + _A_instances.add(this); + } + #constructor() { } // Error: `#constructor` is a reserved word. } +_A_instances = new WeakSet(); diff --git a/tests/baselines/reference/privateNameConstructorSignature.js b/tests/baselines/reference/privateNameConstructorSignature.js index d468fc32d31a5..e7c07e2316542 100644 --- a/tests/baselines/reference/privateNameConstructorSignature.js +++ b/tests/baselines/reference/privateNameConstructorSignature.js @@ -18,23 +18,22 @@ interface C { //// [privateNameConstructorSignature.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _x; +var _C_x; class C { constructor() { - _x.set(this, void 0); + _C_x.set(this, void 0); } static test() { - __classPrivateFieldSet(new C(), _x, 10); + __classPrivateFieldSet(new C(), _C_x, 10, "f"); const y = new C(); const z = new y(); z.x = 123; } } -_x = new WeakMap(); +_C_x = new WeakMap(); diff --git a/tests/baselines/reference/privateNameDeclaration.js b/tests/baselines/reference/privateNameDeclaration.js index f8d5f0a017ec3..288f9c8a95f0a 100644 --- a/tests/baselines/reference/privateNameDeclaration.js +++ b/tests/baselines/reference/privateNameDeclaration.js @@ -11,17 +11,17 @@ class A { //// [privateNameDeclaration.js] -var _foo, _bar; +var _A_foo, _A_bar; class A { constructor() { - _foo.set(this, void 0); - _bar.set(this, 6); + _A_foo.set(this, void 0); + _A_bar.set(this, 6); this.qux = 6; } quux() { } } -_foo = new WeakMap(), _bar = new WeakMap(); +_A_foo = new WeakMap(), _A_bar = new WeakMap(); //// [privateNameDeclaration.d.ts] diff --git a/tests/baselines/reference/privateNameDeclarationMerging.js b/tests/baselines/reference/privateNameDeclarationMerging.js index 1d278bfed2954..28b2a1f6b8e13 100644 --- a/tests/baselines/reference/privateNameDeclarationMerging.js +++ b/tests/baselines/reference/privateNameDeclarationMerging.js @@ -16,25 +16,24 @@ interface C { //// [privateNameDeclarationMerging.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _x; +var _C_x; class D { } ; class C { constructor() { - _x.set(this, void 0); + _C_x.set(this, void 0); } foo() { const c = new C(); - __classPrivateFieldGet(c, _x); // OK + __classPrivateFieldGet(c, _C_x, "f"); // OK const d = new C(); - __classPrivateFieldGet(d, _x); // Error + __classPrivateFieldGet(d, _C_x, "f"); // Error } } -_x = new WeakMap(); +_C_x = new WeakMap(); diff --git a/tests/baselines/reference/privateNameDuplicateField.errors.txt b/tests/baselines/reference/privateNameDuplicateField.errors.txt index b818eec73b47a..d766021845e93 100644 --- a/tests/baselines/reference/privateNameDuplicateField.errors.txt +++ b/tests/baselines/reference/privateNameDuplicateField.errors.txt @@ -1,11 +1,657 @@ -tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(3,5): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(6,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(11,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(12,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(17,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(18,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(23,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(24,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(30,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(36,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(42,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(48,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(56,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(56,9): error TS2717: Subsequent property declarations must have the same type. Property '#foo' must be of type '() => void', but here has type 'string'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(61,9): error TS2393: Duplicate function implementation. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(62,9): error TS2393: Duplicate function implementation. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(67,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(68,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(73,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(74,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(80,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(86,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(92,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(98,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(107,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(112,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(113,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(118,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(119,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(131,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(137,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(143,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(149,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(157,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(162,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(163,9): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(174,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(175,13): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(181,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(187,16): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(193,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(199,20): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(207,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(213,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(219,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(225,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(231,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(236,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(237,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(242,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(243,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(248,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(249,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(257,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(263,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(269,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(275,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(281,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(281,16): error TS2717: Subsequent property declarations must have the same type. Property '#foo' must be of type '() => void', but here has type 'string'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(286,16): error TS2393: Duplicate function implementation. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(287,16): error TS2393: Duplicate function implementation. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(292,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(293,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(298,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(299,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(308,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(314,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(320,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(326,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(331,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(332,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(337,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(338,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(343,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(344,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(357,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(363,9): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(370,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(376,13): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(382,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(387,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(388,16): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(399,20): error TS2300: Duplicate identifier '#foo'. +tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts(400,20): error TS2300: Duplicate identifier '#foo'. -==== tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts (1 errors) ==== - class A { - #foo = "foo"; - #foo = "foo"; - ~~~~ +==== tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts (83 errors) ==== + function Field() { + + // Error + class A_Field_Field { + #foo = "foo"; + #foo = "foo"; + ~~~~ !!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Field_Method { + #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Field_Getter { + #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Field_Setter { + #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Field_StaticField { + #foo = "foo"; + static #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Field_StaticMethod { + #foo = "foo"; + static #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Field_StaticGetter { + #foo = "foo"; + static get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Field_StaticSetter { + #foo = "foo"; + static set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + } + + function Method() { + // Error + class A_Method_Field { + #foo() { } + #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + ~~~~ +!!! error TS2717: Subsequent property declarations must have the same type. Property '#foo' must be of type '() => void', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts:55:9: '#foo' was also declared here. + } + + // Error + class A_Method_Method { + #foo() { } + ~~~~ +!!! error TS2393: Duplicate function implementation. + #foo() { } + ~~~~ +!!! error TS2393: Duplicate function implementation. + } + + // Error + class A_Method_Getter { + #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Method_Setter { + #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Method_StaticField { + #foo() { } + static #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Method_StaticMethod { + #foo() { } + static #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Method_StaticGetter { + #foo() { } + static get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Method_StaticSetter { + #foo() { } + static set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + } + + + function Getter() { + // Error + class A_Getter_Field { + get #foo() { return ""} + #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Getter_Method { + get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Getter_Getter { + get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + //OK + class A_Getter_Setter { + get #foo() { return ""} + set #foo(value: string) { } + } + + // Error + class A_Getter_StaticField { + get #foo() { return ""} + static #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Getter_StaticMethod { + get #foo() { return ""} + static #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Getter_StaticGetter { + get #foo() { return ""} + static get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Getter_StaticSetter { + get #foo() { return ""} + static set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + } + + function Setter() { + // Error + class A_Setter_Field { + set #foo(value: string) { } + #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Setter_Method { + set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // OK + class A_Setter_Getter { + set #foo(value: string) { } + get #foo() { return ""} + } + + // Error + class A_Setter_Setter { + set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_Setter_StaticField { + set #foo(value: string) { } + static #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Setter_StaticMethod { + set #foo(value: string) { } + static #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Setter_StaticGetter { + set #foo(value: string) { } + static get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_Setter_StaticSetter { + set #foo(value: string) { } + static set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + } + + function StaticField() { + // Error + class A_StaticField_Field { + static #foo = "foo"; + #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticField_Method { + static #foo = "foo"; + #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticField_Getter { + static #foo = "foo"; + get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticField_Setter { + static #foo = "foo"; + set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticField_StaticField { + static #foo = "foo"; + static #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticField_StaticMethod { + static #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticField_StaticGetter { + static #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticField_StaticSetter { + static #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + } + + function StaticMethod() { + // Error + class A_StaticMethod_Field { + static #foo() { } + #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticMethod_Method { + static #foo() { } + #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticMethod_Getter { + static #foo() { } + get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticMethod_Setter { + static #foo() { } + set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticMethod_StaticField { + static #foo() { } + static #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + ~~~~ +!!! error TS2717: Subsequent property declarations must have the same type. Property '#foo' must be of type '() => void', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts:280:16: '#foo' was also declared here. + } + + // Error + class A_StaticMethod_StaticMethod { + static #foo() { } + ~~~~ +!!! error TS2393: Duplicate function implementation. + static #foo() { } + ~~~~ +!!! error TS2393: Duplicate function implementation. + } + + // Error + class A_StaticMethod_StaticGetter { + static #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticMethod_StaticSetter { + static #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + } + + function StaticGetter() { + + // Error + class A_StaticGetter_Field { + static get #foo() { return ""} + #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticGetter_Method { + static get #foo() { return ""} + #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticGetter_Getter { + static get #foo() { return ""} + get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticGetter_Setter { + static get #foo() { return ""} + set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticGetter_StaticField { + static get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticGetter_StaticMethod { + static get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticGetter_StaticGetter { + static get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static get #foo() { return ""} + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + // OK + class A_StaticGetter_StaticSetter { + static get #foo() { return ""} + static set #foo(value: string) { } + } + } + + function StaticSetter() { + // Error + class A_StaticSetter_Field { + static set #foo(value: string) { } + #foo = "foo"; + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticSetter_Method { + static set #foo(value: string) { } + #foo() { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + + // Error + class A_StaticSetter_Getter { + static set #foo(value: string) { } + get #foo() { return ""} + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticSetter_Setter { + static set #foo(value: string) { } + set #foo(value: string) { } + ~~~~ +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. + } + + // Error + class A_StaticSetter_StaticField { + static set #foo(value: string) { } + static #foo = "foo"; + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // Error + class A_StaticSetter_StaticMethod { + static set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static #foo() { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } + + // OK + class A_StaticSetter_StaticGetter { + static set #foo(value: string) { } + static get #foo() { return ""} + } + + // Error + class A_StaticSetter_StaticSetter { + static set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + static set #foo(value: string) { } + ~~~~ +!!! error TS2300: Duplicate identifier '#foo'. + } } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameDuplicateField.js b/tests/baselines/reference/privateNameDuplicateField.js index 30b96d7c48b74..3b59b74ad8165 100644 --- a/tests/baselines/reference/privateNameDuplicateField.js +++ b/tests/baselines/reference/privateNameDuplicateField.js @@ -1,17 +1,960 @@ //// [privateNameDuplicateField.ts] -class A { - #foo = "foo"; - #foo = "foo"; +function Field() { + + // Error + class A_Field_Field { + #foo = "foo"; + #foo = "foo"; + } + + // Error + class A_Field_Method { + #foo = "foo"; + #foo() { } + } + + // Error + class A_Field_Getter { + #foo = "foo"; + get #foo() { return ""} + } + + // Error + class A_Field_Setter { + #foo = "foo"; + set #foo(value: string) { } + } + + // Error + class A_Field_StaticField { + #foo = "foo"; + static #foo = "foo"; + } + + // Error + class A_Field_StaticMethod { + #foo = "foo"; + static #foo() { } + } + + // Error + class A_Field_StaticGetter { + #foo = "foo"; + static get #foo() { return ""} + } + + // Error + class A_Field_StaticSetter { + #foo = "foo"; + static set #foo(value: string) { } + } +} + +function Method() { + // Error + class A_Method_Field { + #foo() { } + #foo = "foo"; + } + + // Error + class A_Method_Method { + #foo() { } + #foo() { } + } + + // Error + class A_Method_Getter { + #foo() { } + get #foo() { return ""} + } + + // Error + class A_Method_Setter { + #foo() { } + set #foo(value: string) { } + } + + // Error + class A_Method_StaticField { + #foo() { } + static #foo = "foo"; + } + + // Error + class A_Method_StaticMethod { + #foo() { } + static #foo() { } + } + + // Error + class A_Method_StaticGetter { + #foo() { } + static get #foo() { return ""} + } + + // Error + class A_Method_StaticSetter { + #foo() { } + static set #foo(value: string) { } + } +} + + +function Getter() { + // Error + class A_Getter_Field { + get #foo() { return ""} + #foo = "foo"; + } + + // Error + class A_Getter_Method { + get #foo() { return ""} + #foo() { } + } + + // Error + class A_Getter_Getter { + get #foo() { return ""} + get #foo() { return ""} + } + + //OK + class A_Getter_Setter { + get #foo() { return ""} + set #foo(value: string) { } + } + + // Error + class A_Getter_StaticField { + get #foo() { return ""} + static #foo() { } + } + + // Error + class A_Getter_StaticMethod { + get #foo() { return ""} + static #foo() { } + } + + // Error + class A_Getter_StaticGetter { + get #foo() { return ""} + static get #foo() { return ""} + } + + // Error + class A_Getter_StaticSetter { + get #foo() { return ""} + static set #foo(value: string) { } + } +} + +function Setter() { + // Error + class A_Setter_Field { + set #foo(value: string) { } + #foo = "foo"; + } + + // Error + class A_Setter_Method { + set #foo(value: string) { } + #foo() { } + } + + // OK + class A_Setter_Getter { + set #foo(value: string) { } + get #foo() { return ""} + } + + // Error + class A_Setter_Setter { + set #foo(value: string) { } + set #foo(value: string) { } + } + + // Error + class A_Setter_StaticField { + set #foo(value: string) { } + static #foo = "foo"; + } + + // Error + class A_Setter_StaticMethod { + set #foo(value: string) { } + static #foo() { } + } + + // Error + class A_Setter_StaticGetter { + set #foo(value: string) { } + static get #foo() { return ""} + } + + // Error + class A_Setter_StaticSetter { + set #foo(value: string) { } + static set #foo(value: string) { } + } +} + +function StaticField() { + // Error + class A_StaticField_Field { + static #foo = "foo"; + #foo = "foo"; + } + + // Error + class A_StaticField_Method { + static #foo = "foo"; + #foo() { } + } + + // Error + class A_StaticField_Getter { + static #foo = "foo"; + get #foo() { return ""} + } + + // Error + class A_StaticField_Setter { + static #foo = "foo"; + set #foo(value: string) { } + } + + // Error + class A_StaticField_StaticField { + static #foo = "foo"; + static #foo = "foo"; + } + + // Error + class A_StaticField_StaticMethod { + static #foo = "foo"; + static #foo() { } + } + + // Error + class A_StaticField_StaticGetter { + static #foo = "foo"; + static get #foo() { return ""} + } + + // Error + class A_StaticField_StaticSetter { + static #foo = "foo"; + static set #foo(value: string) { } + } +} + +function StaticMethod() { + // Error + class A_StaticMethod_Field { + static #foo() { } + #foo = "foo"; + } + + // Error + class A_StaticMethod_Method { + static #foo() { } + #foo() { } + } + + // Error + class A_StaticMethod_Getter { + static #foo() { } + get #foo() { return ""} + } + + // Error + class A_StaticMethod_Setter { + static #foo() { } + set #foo(value: string) { } + } + + // Error + class A_StaticMethod_StaticField { + static #foo() { } + static #foo = "foo"; + } + + // Error + class A_StaticMethod_StaticMethod { + static #foo() { } + static #foo() { } + } + + // Error + class A_StaticMethod_StaticGetter { + static #foo() { } + static get #foo() { return ""} + } + + // Error + class A_StaticMethod_StaticSetter { + static #foo() { } + static set #foo(value: string) { } + } +} + +function StaticGetter() { + + // Error + class A_StaticGetter_Field { + static get #foo() { return ""} + #foo = "foo"; + } + + // Error + class A_StaticGetter_Method { + static get #foo() { return ""} + #foo() { } + } + + // Error + class A_StaticGetter_Getter { + static get #foo() { return ""} + get #foo() { return ""} + } + + // Error + class A_StaticGetter_Setter { + static get #foo() { return ""} + set #foo(value: string) { } + } + + // Error + class A_StaticGetter_StaticField { + static get #foo() { return ""} + static #foo() { } + } + + // Error + class A_StaticGetter_StaticMethod { + static get #foo() { return ""} + static #foo() { } + } + + // Error + class A_StaticGetter_StaticGetter { + static get #foo() { return ""} + static get #foo() { return ""} + } + // OK + class A_StaticGetter_StaticSetter { + static get #foo() { return ""} + static set #foo(value: string) { } + } +} + +function StaticSetter() { + // Error + class A_StaticSetter_Field { + static set #foo(value: string) { } + #foo = "foo"; + } + + // Error + class A_StaticSetter_Method { + static set #foo(value: string) { } + #foo() { } + } + + + // Error + class A_StaticSetter_Getter { + static set #foo(value: string) { } + get #foo() { return ""} + } + + // Error + class A_StaticSetter_Setter { + static set #foo(value: string) { } + set #foo(value: string) { } + } + + // Error + class A_StaticSetter_StaticField { + static set #foo(value: string) { } + static #foo = "foo"; + } + + // Error + class A_StaticSetter_StaticMethod { + static set #foo(value: string) { } + static #foo() { } + } + + // OK + class A_StaticSetter_StaticGetter { + static set #foo(value: string) { } + static get #foo() { return ""} + } + + // Error + class A_StaticSetter_StaticSetter { + static set #foo(value: string) { } + static set #foo(value: string) { } + } } //// [privateNameDuplicateField.js] "use strict"; -var _foo, _foo_1; -class A { - constructor() { - _foo_1.set(this, "foo"); - _foo_1.set(this, "foo"); +function Field() { + var _A_Field_Field_foo, _A_Field_Field_foo_1, _A_Field_Method_instances, _A_Field_Method_foo, _A_Field_Method_foo_1, _A_Field_Getter_instances, _A_Field_Getter_foo, _A_Field_Getter_foo_get, _A_Field_Setter_instances, _A_Field_Setter_foo, _A_Field_Setter_foo_set, _a, _A_Field_StaticField_foo, _A_Field_StaticField_foo_1, _b, _A_Field_StaticMethod_foo, _A_Field_StaticMethod_foo_1, _c, _A_Field_StaticGetter_foo, _A_Field_StaticGetter_foo_get, _d, _A_Field_StaticSetter_foo, _A_Field_StaticSetter_foo_set; + // Error + class A_Field_Field { + constructor() { + _A_Field_Field_foo_1.set(this, "foo"); + _A_Field_Field_foo_1.set(this, "foo"); + } + #foo = "foo"; + #foo = "foo"; + } + _A_Field_Field_foo = new WeakMap(), _A_Field_Field_foo_1 = new WeakMap(); + // Error + class A_Field_Method { + constructor() { + _A_Field_Method_instances.add(this); + } + #foo = "foo"; + #foo() { } + } + _A_Field_Method_foo = new WeakMap(), _A_Field_Method_instances = new WeakSet(); + // Error + class A_Field_Getter { + constructor() { + _A_Field_Getter_instances.add(this); + } + #foo = "foo"; + get #foo() { return ""; } + } + _A_Field_Getter_foo = new WeakMap(), _A_Field_Getter_instances = new WeakSet(); + // Error + class A_Field_Setter { + constructor() { + _A_Field_Setter_instances.add(this); + } + #foo = "foo"; + set #foo(value) { } + } + _A_Field_Setter_foo = new WeakMap(), _A_Field_Setter_instances = new WeakSet(); + // Error + class A_Field_StaticField { + constructor() { + _A_Field_StaticField_foo_1 = { value: "foo" }; + } + #foo = "foo"; + static #foo = "foo"; + } + _a = A_Field_StaticField, _A_Field_StaticField_foo = new WeakMap(); + _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) { } + } + _d = A_Field_StaticSetter, _A_Field_StaticSetter_foo = new WeakMap(); +} +function Method() { + var _A_Method_Field_instances, _A_Method_Field_foo, _A_Method_Field_foo_1, _A_Method_Method_instances, _A_Method_Method_foo, _A_Method_Method_foo_1, _A_Method_Getter_instances, _A_Method_Getter_foo, _A_Method_Getter_foo_get, _A_Method_Setter_instances, _A_Method_Setter_foo, _A_Method_Setter_foo_set, _A_Method_StaticField_instances, _a, _A_Method_StaticField_foo, _A_Method_StaticField_foo_1, _A_Method_StaticMethod_instances, _b, _A_Method_StaticMethod_foo, _A_Method_StaticMethod_foo_1, _A_Method_StaticGetter_instances, _c, _A_Method_StaticGetter_foo, _A_Method_StaticGetter_foo_get, _A_Method_StaticSetter_instances, _d, _A_Method_StaticSetter_foo, _A_Method_StaticSetter_foo_set; + // Error + class A_Method_Field { + constructor() { + _A_Method_Field_instances.add(this); + _A_Method_Field_foo_1.set(this, "foo"); + } + #foo() { } + #foo = "foo"; + } + _A_Method_Field_foo_1 = new WeakMap(), _A_Method_Field_instances = new WeakSet(); + // Error + class A_Method_Method { + constructor() { + _A_Method_Method_instances.add(this); + } + #foo() { } + #foo() { } + } + _A_Method_Method_instances = new WeakSet(); + // Error + class A_Method_Getter { + constructor() { + _A_Method_Getter_instances.add(this); + } + #foo() { } + get #foo() { return ""; } + } + _A_Method_Getter_instances = new WeakSet(); + // Error + class A_Method_Setter { + constructor() { + _A_Method_Setter_instances.add(this); + } + #foo() { } + set #foo(value) { } + } + _A_Method_Setter_instances = new WeakSet(); + // Error + class A_Method_StaticField { + constructor() { + _A_Method_StaticField_instances.add(this); + } + #foo() { } + static #foo = "foo"; + } + _a = A_Method_StaticField, _A_Method_StaticField_instances = new WeakSet(); + _A_Method_StaticField_foo_1 = { value: "foo" }; + // Error + class A_Method_StaticMethod { + constructor() { + _A_Method_StaticMethod_instances.add(this); + } + #foo() { } + static #foo() { } + } + _b = A_Method_StaticMethod, _A_Method_StaticMethod_instances = new WeakSet(); + // Error + class A_Method_StaticGetter { + constructor() { + _A_Method_StaticGetter_instances.add(this); + } + #foo() { } + static get #foo() { return ""; } + } + _c = A_Method_StaticGetter, _A_Method_StaticGetter_instances = new WeakSet(); + // Error + class A_Method_StaticSetter { + constructor() { + _A_Method_StaticSetter_instances.add(this); + } + #foo() { } + static set #foo(value) { } + } + _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; + // Error + class A_Getter_Field { + constructor() { + _A_Getter_Field_instances.add(this); + _A_Getter_Field_foo.set(this, "foo"); + } + get #foo() { return ""; } + #foo = "foo"; + } + _A_Getter_Field_foo = new WeakMap(), _A_Getter_Field_instances = new WeakSet(); + // Error + class A_Getter_Method { + constructor() { + _A_Getter_Method_instances.add(this); + } + get #foo() { return ""; } + #foo() { } + } + _A_Getter_Method_instances = new WeakSet(); + // Error + class A_Getter_Getter { + constructor() { + _A_Getter_Getter_instances.add(this); + } + get #foo() { return ""; } + get #foo() { return ""; } + } + _A_Getter_Getter_instances = new WeakSet(); + //OK + class A_Getter_Setter { + constructor() { + _A_Getter_Setter_instances.add(this); + } + } + _A_Getter_Setter_instances = new WeakSet(), _A_Getter_Setter_foo_get = function _A_Getter_Setter_foo_get() { return ""; }, _A_Getter_Setter_foo_set = function _A_Getter_Setter_foo_set(value) { }; + // Error + class A_Getter_StaticField { + constructor() { + _A_Getter_StaticField_instances.add(this); + } + get #foo() { return ""; } + static #foo() { } + } + _a = A_Getter_StaticField, _A_Getter_StaticField_instances = new WeakSet(); + // Error + class A_Getter_StaticMethod { + constructor() { + _A_Getter_StaticMethod_instances.add(this); + } + get #foo() { return ""; } + static #foo() { } + } + _b = A_Getter_StaticMethod, _A_Getter_StaticMethod_instances = new WeakSet(); + // Error + class A_Getter_StaticGetter { + constructor() { + _A_Getter_StaticGetter_instances.add(this); + } + get #foo() { return ""; } + static get #foo() { return ""; } + } + _c = A_Getter_StaticGetter, _A_Getter_StaticGetter_instances = new WeakSet(); + // Error + class A_Getter_StaticSetter { + constructor() { + _A_Getter_StaticSetter_instances.add(this); + } + get #foo() { return ""; } + static set #foo(value) { } + } + _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; + // Error + class A_Setter_Field { + constructor() { + _A_Setter_Field_instances.add(this); + _A_Setter_Field_foo.set(this, "foo"); + } + set #foo(value) { } + #foo = "foo"; + } + _A_Setter_Field_foo = new WeakMap(), _A_Setter_Field_instances = new WeakSet(); + // Error + class A_Setter_Method { + constructor() { + _A_Setter_Method_instances.add(this); + } + set #foo(value) { } + #foo() { } + } + _A_Setter_Method_instances = new WeakSet(); + // OK + class A_Setter_Getter { + constructor() { + _A_Setter_Getter_instances.add(this); + } + } + _A_Setter_Getter_instances = new WeakSet(), _A_Setter_Getter_foo_set = function _A_Setter_Getter_foo_set(value) { }, _A_Setter_Getter_foo_get = function _A_Setter_Getter_foo_get() { return ""; }; + // Error + class A_Setter_Setter { + constructor() { + _A_Setter_Setter_instances.add(this); + } + set #foo(value) { } + set #foo(value) { } + } + _A_Setter_Setter_instances = new WeakSet(); + // Error + class A_Setter_StaticField { + constructor() { + _A_Setter_StaticField_instances.add(this); + } + set #foo(value) { } + static #foo = "foo"; + } + _a = A_Setter_StaticField, _A_Setter_StaticField_instances = new WeakSet(); + _A_Setter_StaticField_foo = { value: "foo" }; + // Error + class A_Setter_StaticMethod { + constructor() { + _A_Setter_StaticMethod_instances.add(this); + } + set #foo(value) { } + static #foo() { } + } + _b = A_Setter_StaticMethod, _A_Setter_StaticMethod_instances = new WeakSet(); + // Error + class A_Setter_StaticGetter { + constructor() { + _A_Setter_StaticGetter_instances.add(this); + } + set #foo(value) { } + static get #foo() { return ""; } + } + _c = A_Setter_StaticGetter, _A_Setter_StaticGetter_instances = new WeakSet(); + // Error + class A_Setter_StaticSetter { + constructor() { + _A_Setter_StaticSetter_instances.add(this); + } + set #foo(value) { } + static set #foo(value) { } + } + _d = A_Setter_StaticSetter, _A_Setter_StaticSetter_instances = new WeakSet(); +} +function StaticField() { + var _a, _A_StaticField_Field_foo, _A_StaticField_Field_foo_1, _A_StaticField_Method_instances, _b, _A_StaticField_Method_foo, _A_StaticField_Method_foo_1, _A_StaticField_Getter_instances, _c, _A_StaticField_Getter_foo, _A_StaticField_Getter_foo_get, _A_StaticField_Setter_instances, _d, _A_StaticField_Setter_foo, _A_StaticField_Setter_foo_set, _e, _A_StaticField_StaticField_foo, _A_StaticField_StaticField_foo_1, _f, _A_StaticField_StaticMethod_foo, _A_StaticField_StaticMethod_foo_1, _g, _A_StaticField_StaticGetter_foo, _A_StaticField_StaticGetter_foo_get, _h, _A_StaticField_StaticSetter_foo, _A_StaticField_StaticSetter_foo_set; + // Error + class A_StaticField_Field { + constructor() { + _A_StaticField_Field_foo_1.set(this, "foo"); + } + static #foo = "foo"; + #foo = "foo"; + } + _a = A_StaticField_Field, _A_StaticField_Field_foo_1 = new WeakMap(); + _A_StaticField_Field_foo_1.set(A_StaticField_Field, "foo"); + // Error + class A_StaticField_Method { + constructor() { + _A_StaticField_Method_instances.add(this); + } + static #foo = "foo"; + #foo() { } + } + _b = A_StaticField_Method, _A_StaticField_Method_instances = new WeakSet(); + // Error + class A_StaticField_Getter { + constructor() { + _A_StaticField_Getter_instances.add(this); + } + static #foo = "foo"; + get #foo() { return ""; } + } + _c = A_StaticField_Getter, _A_StaticField_Getter_instances = new WeakSet(); + // Error + class A_StaticField_Setter { + constructor() { + _A_StaticField_Setter_instances.add(this); + } + static #foo = "foo"; + set #foo(value) { } + } + _d = A_StaticField_Setter, _A_StaticField_Setter_instances = new WeakSet(); + // Error + class A_StaticField_StaticField { + static #foo = "foo"; + static #foo = "foo"; + } + _e = A_StaticField_StaticField; + _A_StaticField_StaticField_foo_1 = { value: "foo" }; + _A_StaticField_StaticField_foo_1 = { value: "foo" }; + // Error + class A_StaticField_StaticMethod { + static #foo = "foo"; + static #foo() { } + } + _f = A_StaticField_StaticMethod; + // Error + class A_StaticField_StaticGetter { + static #foo = "foo"; + static get #foo() { return ""; } + } + _g = A_StaticField_StaticGetter; + // Error + class A_StaticField_StaticSetter { + static #foo = "foo"; + static set #foo(value) { } + } + _h = A_StaticField_StaticSetter; +} +function StaticMethod() { + var _a, _A_StaticMethod_Field_foo, _A_StaticMethod_Field_foo_1, _A_StaticMethod_Method_instances, _b, _A_StaticMethod_Method_foo, _A_StaticMethod_Method_foo_1, _A_StaticMethod_Getter_instances, _c, _A_StaticMethod_Getter_foo, _A_StaticMethod_Getter_foo_get, _A_StaticMethod_Setter_instances, _d, _A_StaticMethod_Setter_foo, _A_StaticMethod_Setter_foo_set, _e, _A_StaticMethod_StaticField_foo, _A_StaticMethod_StaticField_foo_1, _f, _A_StaticMethod_StaticMethod_foo, _A_StaticMethod_StaticMethod_foo_1, _g, _A_StaticMethod_StaticGetter_foo, _A_StaticMethod_StaticGetter_foo_get, _h, _A_StaticMethod_StaticSetter_foo, _A_StaticMethod_StaticSetter_foo_set; + // Error + class A_StaticMethod_Field { + constructor() { + _A_StaticMethod_Field_foo_1.set(this, "foo"); + } + static #foo() { } + #foo = "foo"; + } + _a = A_StaticMethod_Field, _A_StaticMethod_Field_foo_1 = new WeakMap(); + // Error + class A_StaticMethod_Method { + constructor() { + _A_StaticMethod_Method_instances.add(this); + } + static #foo() { } + #foo() { } + } + _b = A_StaticMethod_Method, _A_StaticMethod_Method_instances = new WeakSet(); + // Error + class A_StaticMethod_Getter { + constructor() { + _A_StaticMethod_Getter_instances.add(this); + } + static #foo() { } + get #foo() { return ""; } + } + _c = A_StaticMethod_Getter, _A_StaticMethod_Getter_instances = new WeakSet(); + // Error + class A_StaticMethod_Setter { + constructor() { + _A_StaticMethod_Setter_instances.add(this); + } + static #foo() { } + set #foo(value) { } + } + _d = A_StaticMethod_Setter, _A_StaticMethod_Setter_instances = new WeakSet(); + // Error + class A_StaticMethod_StaticField { + static #foo() { } + static #foo = "foo"; + } + _e = A_StaticMethod_StaticField; + _A_StaticMethod_StaticField_foo_1 = { value: "foo" }; + // Error + class A_StaticMethod_StaticMethod { + static #foo() { } + static #foo() { } + } + _f = A_StaticMethod_StaticMethod; + // Error + class A_StaticMethod_StaticGetter { + static #foo() { } + static get #foo() { return ""; } + } + _g = A_StaticMethod_StaticGetter; + // Error + class A_StaticMethod_StaticSetter { + static #foo() { } + static set #foo(value) { } + } + _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; + // Error + class A_StaticGetter_Field { + constructor() { + _A_StaticGetter_Field_foo.set(this, "foo"); + } + static get #foo() { return ""; } + #foo = "foo"; + } + _a = A_StaticGetter_Field, _A_StaticGetter_Field_foo = new WeakMap(); + // Error + class A_StaticGetter_Method { + constructor() { + _A_StaticGetter_Method_instances.add(this); + } + static get #foo() { return ""; } + #foo() { } + } + _b = A_StaticGetter_Method, _A_StaticGetter_Method_instances = new WeakSet(); + // Error + class A_StaticGetter_Getter { + constructor() { + _A_StaticGetter_Getter_instances.add(this); + } + static get #foo() { return ""; } + get #foo() { return ""; } + } + _c = A_StaticGetter_Getter, _A_StaticGetter_Getter_instances = new WeakSet(); + // Error + class A_StaticGetter_Setter { + constructor() { + _A_StaticGetter_Setter_instances.add(this); + } + static get #foo() { return ""; } + set #foo(value) { } + } + _d = A_StaticGetter_Setter, _A_StaticGetter_Setter_instances = new WeakSet(); + // Error + class A_StaticGetter_StaticField { + static get #foo() { return ""; } + static #foo() { } + } + _e = A_StaticGetter_StaticField; + // Error + class A_StaticGetter_StaticMethod { + static get #foo() { return ""; } + static #foo() { } + } + _f = A_StaticGetter_StaticMethod; + // Error + class A_StaticGetter_StaticGetter { + static get #foo() { return ""; } + static get #foo() { return ""; } + } + _g = A_StaticGetter_StaticGetter; + // OK + class A_StaticGetter_StaticSetter { + } + _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; + // Error + class A_StaticSetter_Field { + constructor() { + _A_StaticSetter_Field_foo.set(this, "foo"); + } + static set #foo(value) { } + #foo = "foo"; + } + _a = A_StaticSetter_Field, _A_StaticSetter_Field_foo = new WeakMap(); + // Error + class A_StaticSetter_Method { + constructor() { + _A_StaticSetter_Method_instances.add(this); + } + static set #foo(value) { } + #foo() { } + } + _b = A_StaticSetter_Method, _A_StaticSetter_Method_instances = new WeakSet(); + // Error + class A_StaticSetter_Getter { + constructor() { + _A_StaticSetter_Getter_instances.add(this); + } + static set #foo(value) { } + get #foo() { return ""; } + } + _c = A_StaticSetter_Getter, _A_StaticSetter_Getter_instances = new WeakSet(); + // Error + class A_StaticSetter_Setter { + constructor() { + _A_StaticSetter_Setter_instances.add(this); + } + static set #foo(value) { } + set #foo(value) { } + } + _d = A_StaticSetter_Setter, _A_StaticSetter_Setter_instances = new WeakSet(); + // Error + class A_StaticSetter_StaticField { + static set #foo(value) { } + static #foo = "foo"; + } + _e = A_StaticSetter_StaticField; + _A_StaticSetter_StaticField_foo = { value: "foo" }; + // Error + class A_StaticSetter_StaticMethod { + static set #foo(value) { } + static #foo() { } + } + _f = A_StaticSetter_StaticMethod; + // OK + class A_StaticSetter_StaticGetter { + } + _g = A_StaticSetter_StaticGetter, _A_StaticSetter_StaticGetter_foo_set = function _A_StaticSetter_StaticGetter_foo_set(value) { }, _A_StaticSetter_StaticGetter_foo_get = function _A_StaticSetter_StaticGetter_foo_get() { return ""; }; + // Error + class A_StaticSetter_StaticSetter { + static set #foo(value) { } + static set #foo(value) { } } + _h = A_StaticSetter_StaticSetter; } -_foo = new WeakMap(), _foo_1 = new WeakMap(); diff --git a/tests/baselines/reference/privateNameDuplicateField.symbols b/tests/baselines/reference/privateNameDuplicateField.symbols index af627ed139dfe..eb8a982581ed2 100644 --- a/tests/baselines/reference/privateNameDuplicateField.symbols +++ b/tests/baselines/reference/privateNameDuplicateField.symbols @@ -1,11 +1,770 @@ === tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts === -class A { ->A : Symbol(A, Decl(privateNameDuplicateField.ts, 0, 0)) +function Field() { +>Field : Symbol(Field, Decl(privateNameDuplicateField.ts, 0, 0)) - #foo = "foo"; ->#foo : Symbol(A.#foo, Decl(privateNameDuplicateField.ts, 0, 9), Decl(privateNameDuplicateField.ts, 1, 17)) + // Error + class A_Field_Field { +>A_Field_Field : Symbol(A_Field_Field, Decl(privateNameDuplicateField.ts, 0, 18)) - #foo = "foo"; ->#foo : Symbol(A.#foo, Decl(privateNameDuplicateField.ts, 0, 9), Decl(privateNameDuplicateField.ts, 1, 17)) + #foo = "foo"; +>#foo : Symbol(A_Field_Field.#foo, Decl(privateNameDuplicateField.ts, 3, 25), Decl(privateNameDuplicateField.ts, 4, 21)) + + #foo = "foo"; +>#foo : Symbol(A_Field_Field.#foo, Decl(privateNameDuplicateField.ts, 3, 25), Decl(privateNameDuplicateField.ts, 4, 21)) + } + + // Error + class A_Field_Method { +>A_Field_Method : Symbol(A_Field_Method, Decl(privateNameDuplicateField.ts, 6, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_Method.#foo, Decl(privateNameDuplicateField.ts, 9, 26)) + + #foo() { } +>#foo : Symbol(A_Field_Method.#foo, Decl(privateNameDuplicateField.ts, 10, 21)) + } + + // Error + class A_Field_Getter { +>A_Field_Getter : Symbol(A_Field_Getter, Decl(privateNameDuplicateField.ts, 12, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_Getter.#foo, Decl(privateNameDuplicateField.ts, 15, 26)) + + get #foo() { return ""} +>#foo : Symbol(A_Field_Getter.#foo, Decl(privateNameDuplicateField.ts, 16, 21)) + } + + // Error + class A_Field_Setter { +>A_Field_Setter : Symbol(A_Field_Setter, Decl(privateNameDuplicateField.ts, 18, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_Setter.#foo, Decl(privateNameDuplicateField.ts, 21, 26)) + + set #foo(value: string) { } +>#foo : Symbol(A_Field_Setter.#foo, Decl(privateNameDuplicateField.ts, 22, 21)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 23, 17)) + } + + // Error + class A_Field_StaticField { +>A_Field_StaticField : Symbol(A_Field_StaticField, Decl(privateNameDuplicateField.ts, 24, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_StaticField.#foo, Decl(privateNameDuplicateField.ts, 27, 31)) + + static #foo = "foo"; +>#foo : Symbol(A_Field_StaticField.#foo, Decl(privateNameDuplicateField.ts, 28, 21)) + } + + // Error + class A_Field_StaticMethod { +>A_Field_StaticMethod : Symbol(A_Field_StaticMethod, Decl(privateNameDuplicateField.ts, 30, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 33, 32)) + + static #foo() { } +>#foo : Symbol(A_Field_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 34, 21)) + } + + // Error + class A_Field_StaticGetter { +>A_Field_StaticGetter : Symbol(A_Field_StaticGetter, Decl(privateNameDuplicateField.ts, 36, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 39, 32)) + + static get #foo() { return ""} +>#foo : Symbol(A_Field_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 40, 21)) + } + + // Error + class A_Field_StaticSetter { +>A_Field_StaticSetter : Symbol(A_Field_StaticSetter, Decl(privateNameDuplicateField.ts, 42, 5)) + + #foo = "foo"; +>#foo : Symbol(A_Field_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 45, 32)) + + static set #foo(value: string) { } +>#foo : Symbol(A_Field_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 46, 21)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 47, 24)) + } +} + +function Method() { +>Method : Symbol(Method, Decl(privateNameDuplicateField.ts, 49, 1)) + + // Error + class A_Method_Field { +>A_Method_Field : Symbol(A_Method_Field, Decl(privateNameDuplicateField.ts, 51, 19)) + + #foo() { } +>#foo : Symbol(A_Method_Field.#foo, Decl(privateNameDuplicateField.ts, 53, 26), Decl(privateNameDuplicateField.ts, 54, 18)) + + #foo = "foo"; +>#foo : Symbol(A_Method_Field.#foo, Decl(privateNameDuplicateField.ts, 53, 26), Decl(privateNameDuplicateField.ts, 54, 18)) + } + + // Error + class A_Method_Method { +>A_Method_Method : Symbol(A_Method_Method, Decl(privateNameDuplicateField.ts, 56, 5)) + + #foo() { } +>#foo : Symbol(A_Method_Method.#foo, Decl(privateNameDuplicateField.ts, 59, 27), Decl(privateNameDuplicateField.ts, 60, 18)) + + #foo() { } +>#foo : Symbol(A_Method_Method.#foo, Decl(privateNameDuplicateField.ts, 59, 27), Decl(privateNameDuplicateField.ts, 60, 18)) + } + + // Error + class A_Method_Getter { +>A_Method_Getter : Symbol(A_Method_Getter, Decl(privateNameDuplicateField.ts, 62, 5)) + + #foo() { } +>#foo : Symbol(A_Method_Getter.#foo, Decl(privateNameDuplicateField.ts, 65, 27)) + + get #foo() { return ""} +>#foo : Symbol(A_Method_Getter.#foo, Decl(privateNameDuplicateField.ts, 66, 18)) + } + + // Error + class A_Method_Setter { +>A_Method_Setter : Symbol(A_Method_Setter, Decl(privateNameDuplicateField.ts, 68, 5)) + + #foo() { } +>#foo : Symbol(A_Method_Setter.#foo, Decl(privateNameDuplicateField.ts, 71, 27)) + + set #foo(value: string) { } +>#foo : Symbol(A_Method_Setter.#foo, Decl(privateNameDuplicateField.ts, 72, 18)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 73, 17)) + } + + // Error + class A_Method_StaticField { +>A_Method_StaticField : Symbol(A_Method_StaticField, Decl(privateNameDuplicateField.ts, 74, 5)) + + #foo() { } +>#foo : Symbol(A_Method_StaticField.#foo, Decl(privateNameDuplicateField.ts, 77, 32)) + + static #foo = "foo"; +>#foo : Symbol(A_Method_StaticField.#foo, Decl(privateNameDuplicateField.ts, 78, 18)) + } + + // Error + class A_Method_StaticMethod { +>A_Method_StaticMethod : Symbol(A_Method_StaticMethod, Decl(privateNameDuplicateField.ts, 80, 5)) + + #foo() { } +>#foo : Symbol(A_Method_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 83, 33)) + + static #foo() { } +>#foo : Symbol(A_Method_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 84, 18)) + } + + // Error + class A_Method_StaticGetter { +>A_Method_StaticGetter : Symbol(A_Method_StaticGetter, Decl(privateNameDuplicateField.ts, 86, 5)) + + #foo() { } +>#foo : Symbol(A_Method_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 89, 33)) + + static get #foo() { return ""} +>#foo : Symbol(A_Method_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 90, 18)) + } + + // Error + class A_Method_StaticSetter { +>A_Method_StaticSetter : Symbol(A_Method_StaticSetter, Decl(privateNameDuplicateField.ts, 92, 5)) + + #foo() { } +>#foo : Symbol(A_Method_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 95, 33)) + + static set #foo(value: string) { } +>#foo : Symbol(A_Method_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 96, 18)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 97, 24)) + } +} + + +function Getter() { +>Getter : Symbol(Getter, Decl(privateNameDuplicateField.ts, 99, 1)) + + // Error + class A_Getter_Field { +>A_Getter_Field : Symbol(A_Getter_Field, Decl(privateNameDuplicateField.ts, 102, 19)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_Field.#foo, Decl(privateNameDuplicateField.ts, 104, 26), Decl(privateNameDuplicateField.ts, 105, 31)) + + #foo = "foo"; +>#foo : Symbol(A_Getter_Field.#foo, Decl(privateNameDuplicateField.ts, 104, 26), Decl(privateNameDuplicateField.ts, 105, 31)) + } + + // Error + class A_Getter_Method { +>A_Getter_Method : Symbol(A_Getter_Method, Decl(privateNameDuplicateField.ts, 107, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_Method.#foo, Decl(privateNameDuplicateField.ts, 110, 27)) + + #foo() { } +>#foo : Symbol(A_Getter_Method.#foo, Decl(privateNameDuplicateField.ts, 111, 31)) + } + + // Error + class A_Getter_Getter { +>A_Getter_Getter : Symbol(A_Getter_Getter, Decl(privateNameDuplicateField.ts, 113, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_Getter.#foo, Decl(privateNameDuplicateField.ts, 116, 27)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_Getter.#foo, Decl(privateNameDuplicateField.ts, 117, 31)) + } + + //OK + class A_Getter_Setter { +>A_Getter_Setter : Symbol(A_Getter_Setter, Decl(privateNameDuplicateField.ts, 119, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_Setter.#foo, Decl(privateNameDuplicateField.ts, 122, 27), Decl(privateNameDuplicateField.ts, 123, 31)) + + set #foo(value: string) { } +>#foo : Symbol(A_Getter_Setter.#foo, Decl(privateNameDuplicateField.ts, 122, 27), Decl(privateNameDuplicateField.ts, 123, 31)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 124, 17)) + } + + // Error + class A_Getter_StaticField { +>A_Getter_StaticField : Symbol(A_Getter_StaticField, Decl(privateNameDuplicateField.ts, 125, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 128, 32)) + + static #foo() { } +>#foo : Symbol(A_Getter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 129, 31)) + } + + // Error + class A_Getter_StaticMethod { +>A_Getter_StaticMethod : Symbol(A_Getter_StaticMethod, Decl(privateNameDuplicateField.ts, 131, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 134, 33)) + + static #foo() { } +>#foo : Symbol(A_Getter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 135, 31)) + } + + // Error + class A_Getter_StaticGetter { +>A_Getter_StaticGetter : Symbol(A_Getter_StaticGetter, Decl(privateNameDuplicateField.ts, 137, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 140, 33)) + + static get #foo() { return ""} +>#foo : Symbol(A_Getter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 141, 31)) + } + + // Error + class A_Getter_StaticSetter { +>A_Getter_StaticSetter : Symbol(A_Getter_StaticSetter, Decl(privateNameDuplicateField.ts, 143, 5)) + + get #foo() { return ""} +>#foo : Symbol(A_Getter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 146, 33)) + + static set #foo(value: string) { } +>#foo : Symbol(A_Getter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 147, 31)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 148, 24)) + } +} + +function Setter() { +>Setter : Symbol(Setter, Decl(privateNameDuplicateField.ts, 150, 1)) + + // Error + class A_Setter_Field { +>A_Setter_Field : Symbol(A_Setter_Field, Decl(privateNameDuplicateField.ts, 152, 19)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_Field.#foo, Decl(privateNameDuplicateField.ts, 154, 26), Decl(privateNameDuplicateField.ts, 155, 35)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 155, 17)) + + #foo = "foo"; +>#foo : Symbol(A_Setter_Field.#foo, Decl(privateNameDuplicateField.ts, 154, 26), Decl(privateNameDuplicateField.ts, 155, 35)) + } + + // Error + class A_Setter_Method { +>A_Setter_Method : Symbol(A_Setter_Method, Decl(privateNameDuplicateField.ts, 157, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_Method.#foo, Decl(privateNameDuplicateField.ts, 160, 27)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 161, 17)) + + #foo() { } +>#foo : Symbol(A_Setter_Method.#foo, Decl(privateNameDuplicateField.ts, 161, 35)) + } + + // OK + class A_Setter_Getter { +>A_Setter_Getter : Symbol(A_Setter_Getter, Decl(privateNameDuplicateField.ts, 163, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_Getter.#foo, Decl(privateNameDuplicateField.ts, 166, 27), Decl(privateNameDuplicateField.ts, 167, 35)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 167, 17)) + + get #foo() { return ""} +>#foo : Symbol(A_Setter_Getter.#foo, Decl(privateNameDuplicateField.ts, 166, 27), Decl(privateNameDuplicateField.ts, 167, 35)) + } + + // Error + class A_Setter_Setter { +>A_Setter_Setter : Symbol(A_Setter_Setter, Decl(privateNameDuplicateField.ts, 169, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_Setter.#foo, Decl(privateNameDuplicateField.ts, 172, 27)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 173, 17)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_Setter.#foo, Decl(privateNameDuplicateField.ts, 173, 35)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 174, 17)) + } + + // Error + class A_Setter_StaticField { +>A_Setter_StaticField : Symbol(A_Setter_StaticField, Decl(privateNameDuplicateField.ts, 175, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 178, 32)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 179, 17)) + + static #foo = "foo"; +>#foo : Symbol(A_Setter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 179, 35)) + } + + // Error + class A_Setter_StaticMethod { +>A_Setter_StaticMethod : Symbol(A_Setter_StaticMethod, Decl(privateNameDuplicateField.ts, 181, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 184, 33)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 185, 17)) + + static #foo() { } +>#foo : Symbol(A_Setter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 185, 35)) + } + + // Error + class A_Setter_StaticGetter { +>A_Setter_StaticGetter : Symbol(A_Setter_StaticGetter, Decl(privateNameDuplicateField.ts, 187, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 190, 33)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 191, 17)) + + static get #foo() { return ""} +>#foo : Symbol(A_Setter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 191, 35)) + } + + // Error + class A_Setter_StaticSetter { +>A_Setter_StaticSetter : Symbol(A_Setter_StaticSetter, Decl(privateNameDuplicateField.ts, 193, 5)) + + set #foo(value: string) { } +>#foo : Symbol(A_Setter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 196, 33)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 197, 17)) + + static set #foo(value: string) { } +>#foo : Symbol(A_Setter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 197, 35)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 198, 24)) + } +} + +function StaticField() { +>StaticField : Symbol(StaticField, Decl(privateNameDuplicateField.ts, 200, 1)) + + // Error + class A_StaticField_Field { +>A_StaticField_Field : Symbol(A_StaticField_Field, Decl(privateNameDuplicateField.ts, 202, 24)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_Field.#foo, Decl(privateNameDuplicateField.ts, 204, 31)) + + #foo = "foo"; +>#foo : Symbol(A_StaticField_Field.#foo, Decl(privateNameDuplicateField.ts, 205, 28)) + } + + // Error + class A_StaticField_Method { +>A_StaticField_Method : Symbol(A_StaticField_Method, Decl(privateNameDuplicateField.ts, 207, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_Method.#foo, Decl(privateNameDuplicateField.ts, 210, 32)) + + #foo() { } +>#foo : Symbol(A_StaticField_Method.#foo, Decl(privateNameDuplicateField.ts, 211, 28)) + } + + // Error + class A_StaticField_Getter { +>A_StaticField_Getter : Symbol(A_StaticField_Getter, Decl(privateNameDuplicateField.ts, 213, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_Getter.#foo, Decl(privateNameDuplicateField.ts, 216, 32)) + + get #foo() { return ""} +>#foo : Symbol(A_StaticField_Getter.#foo, Decl(privateNameDuplicateField.ts, 217, 28)) + } + + // Error + class A_StaticField_Setter { +>A_StaticField_Setter : Symbol(A_StaticField_Setter, Decl(privateNameDuplicateField.ts, 219, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_Setter.#foo, Decl(privateNameDuplicateField.ts, 222, 32)) + + set #foo(value: string) { } +>#foo : Symbol(A_StaticField_Setter.#foo, Decl(privateNameDuplicateField.ts, 223, 28)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 224, 17)) + } + + // Error + class A_StaticField_StaticField { +>A_StaticField_StaticField : Symbol(A_StaticField_StaticField, Decl(privateNameDuplicateField.ts, 225, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_StaticField.#foo, Decl(privateNameDuplicateField.ts, 228, 37), Decl(privateNameDuplicateField.ts, 229, 28)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_StaticField.#foo, Decl(privateNameDuplicateField.ts, 228, 37), Decl(privateNameDuplicateField.ts, 229, 28)) + } + + // Error + class A_StaticField_StaticMethod { +>A_StaticField_StaticMethod : Symbol(A_StaticField_StaticMethod, Decl(privateNameDuplicateField.ts, 231, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 234, 38)) + + static #foo() { } +>#foo : Symbol(A_StaticField_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 235, 28)) + } + + // Error + class A_StaticField_StaticGetter { +>A_StaticField_StaticGetter : Symbol(A_StaticField_StaticGetter, Decl(privateNameDuplicateField.ts, 237, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 240, 38)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticField_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 241, 28)) + } + + // Error + class A_StaticField_StaticSetter { +>A_StaticField_StaticSetter : Symbol(A_StaticField_StaticSetter, Decl(privateNameDuplicateField.ts, 243, 5)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticField_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 246, 38)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticField_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 247, 28)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 248, 24)) + } +} + +function StaticMethod() { +>StaticMethod : Symbol(StaticMethod, Decl(privateNameDuplicateField.ts, 250, 1)) + + // Error + class A_StaticMethod_Field { +>A_StaticMethod_Field : Symbol(A_StaticMethod_Field, Decl(privateNameDuplicateField.ts, 252, 25)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_Field.#foo, Decl(privateNameDuplicateField.ts, 254, 32)) + + #foo = "foo"; +>#foo : Symbol(A_StaticMethod_Field.#foo, Decl(privateNameDuplicateField.ts, 255, 25)) + } + + // Error + class A_StaticMethod_Method { +>A_StaticMethod_Method : Symbol(A_StaticMethod_Method, Decl(privateNameDuplicateField.ts, 257, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_Method.#foo, Decl(privateNameDuplicateField.ts, 260, 33)) + + #foo() { } +>#foo : Symbol(A_StaticMethod_Method.#foo, Decl(privateNameDuplicateField.ts, 261, 25)) + } + + // Error + class A_StaticMethod_Getter { +>A_StaticMethod_Getter : Symbol(A_StaticMethod_Getter, Decl(privateNameDuplicateField.ts, 263, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_Getter.#foo, Decl(privateNameDuplicateField.ts, 266, 33)) + + get #foo() { return ""} +>#foo : Symbol(A_StaticMethod_Getter.#foo, Decl(privateNameDuplicateField.ts, 267, 25)) + } + + // Error + class A_StaticMethod_Setter { +>A_StaticMethod_Setter : Symbol(A_StaticMethod_Setter, Decl(privateNameDuplicateField.ts, 269, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_Setter.#foo, Decl(privateNameDuplicateField.ts, 272, 33)) + + set #foo(value: string) { } +>#foo : Symbol(A_StaticMethod_Setter.#foo, Decl(privateNameDuplicateField.ts, 273, 25)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 274, 17)) + } + + // Error + class A_StaticMethod_StaticField { +>A_StaticMethod_StaticField : Symbol(A_StaticMethod_StaticField, Decl(privateNameDuplicateField.ts, 275, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_StaticField.#foo, Decl(privateNameDuplicateField.ts, 278, 38), Decl(privateNameDuplicateField.ts, 279, 25)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticMethod_StaticField.#foo, Decl(privateNameDuplicateField.ts, 278, 38), Decl(privateNameDuplicateField.ts, 279, 25)) + } + + // Error + class A_StaticMethod_StaticMethod { +>A_StaticMethod_StaticMethod : Symbol(A_StaticMethod_StaticMethod, Decl(privateNameDuplicateField.ts, 281, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 284, 39), Decl(privateNameDuplicateField.ts, 285, 25)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 284, 39), Decl(privateNameDuplicateField.ts, 285, 25)) + } + + // Error + class A_StaticMethod_StaticGetter { +>A_StaticMethod_StaticGetter : Symbol(A_StaticMethod_StaticGetter, Decl(privateNameDuplicateField.ts, 287, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 290, 39)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticMethod_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 291, 25)) + } + + // Error + class A_StaticMethod_StaticSetter { +>A_StaticMethod_StaticSetter : Symbol(A_StaticMethod_StaticSetter, Decl(privateNameDuplicateField.ts, 293, 5)) + + static #foo() { } +>#foo : Symbol(A_StaticMethod_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 296, 39)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticMethod_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 297, 25)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 298, 24)) + } +} + +function StaticGetter() { +>StaticGetter : Symbol(StaticGetter, Decl(privateNameDuplicateField.ts, 300, 1)) + + // Error + class A_StaticGetter_Field { +>A_StaticGetter_Field : Symbol(A_StaticGetter_Field, Decl(privateNameDuplicateField.ts, 302, 25)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_Field.#foo, Decl(privateNameDuplicateField.ts, 305, 32)) + + #foo = "foo"; +>#foo : Symbol(A_StaticGetter_Field.#foo, Decl(privateNameDuplicateField.ts, 306, 38)) + } + + // Error + class A_StaticGetter_Method { +>A_StaticGetter_Method : Symbol(A_StaticGetter_Method, Decl(privateNameDuplicateField.ts, 308, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_Method.#foo, Decl(privateNameDuplicateField.ts, 311, 33)) + + #foo() { } +>#foo : Symbol(A_StaticGetter_Method.#foo, Decl(privateNameDuplicateField.ts, 312, 38)) + } + + // Error + class A_StaticGetter_Getter { +>A_StaticGetter_Getter : Symbol(A_StaticGetter_Getter, Decl(privateNameDuplicateField.ts, 314, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_Getter.#foo, Decl(privateNameDuplicateField.ts, 317, 33)) + + get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_Getter.#foo, Decl(privateNameDuplicateField.ts, 318, 38)) + } + + // Error + class A_StaticGetter_Setter { +>A_StaticGetter_Setter : Symbol(A_StaticGetter_Setter, Decl(privateNameDuplicateField.ts, 320, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_Setter.#foo, Decl(privateNameDuplicateField.ts, 323, 33)) + + set #foo(value: string) { } +>#foo : Symbol(A_StaticGetter_Setter.#foo, Decl(privateNameDuplicateField.ts, 324, 38)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 325, 17)) + } + + // Error + class A_StaticGetter_StaticField { +>A_StaticGetter_StaticField : Symbol(A_StaticGetter_StaticField, Decl(privateNameDuplicateField.ts, 326, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 329, 38)) + + static #foo() { } +>#foo : Symbol(A_StaticGetter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 330, 38)) + } + + // Error + class A_StaticGetter_StaticMethod { +>A_StaticGetter_StaticMethod : Symbol(A_StaticGetter_StaticMethod, Decl(privateNameDuplicateField.ts, 332, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 335, 39)) + + static #foo() { } +>#foo : Symbol(A_StaticGetter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 336, 38)) + } + + // Error + class A_StaticGetter_StaticGetter { +>A_StaticGetter_StaticGetter : Symbol(A_StaticGetter_StaticGetter, Decl(privateNameDuplicateField.ts, 338, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 341, 39)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 342, 38)) + } + // OK + class A_StaticGetter_StaticSetter { +>A_StaticGetter_StaticSetter : Symbol(A_StaticGetter_StaticSetter, Decl(privateNameDuplicateField.ts, 344, 5)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticGetter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 346, 39), Decl(privateNameDuplicateField.ts, 347, 38)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticGetter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 346, 39), Decl(privateNameDuplicateField.ts, 347, 38)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 348, 24)) + } +} + +function StaticSetter() { +>StaticSetter : Symbol(StaticSetter, Decl(privateNameDuplicateField.ts, 350, 1)) + + // Error + class A_StaticSetter_Field { +>A_StaticSetter_Field : Symbol(A_StaticSetter_Field, Decl(privateNameDuplicateField.ts, 352, 25)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_Field.#foo, Decl(privateNameDuplicateField.ts, 354, 32)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 355, 24)) + + #foo = "foo"; +>#foo : Symbol(A_StaticSetter_Field.#foo, Decl(privateNameDuplicateField.ts, 355, 42)) + } + + // Error + class A_StaticSetter_Method { +>A_StaticSetter_Method : Symbol(A_StaticSetter_Method, Decl(privateNameDuplicateField.ts, 357, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_Method.#foo, Decl(privateNameDuplicateField.ts, 360, 33)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 361, 24)) + + #foo() { } +>#foo : Symbol(A_StaticSetter_Method.#foo, Decl(privateNameDuplicateField.ts, 361, 42)) + } + + + // Error + class A_StaticSetter_Getter { +>A_StaticSetter_Getter : Symbol(A_StaticSetter_Getter, Decl(privateNameDuplicateField.ts, 363, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_Getter.#foo, Decl(privateNameDuplicateField.ts, 367, 33)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 368, 24)) + + get #foo() { return ""} +>#foo : Symbol(A_StaticSetter_Getter.#foo, Decl(privateNameDuplicateField.ts, 368, 42)) + } + + // Error + class A_StaticSetter_Setter { +>A_StaticSetter_Setter : Symbol(A_StaticSetter_Setter, Decl(privateNameDuplicateField.ts, 370, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_Setter.#foo, Decl(privateNameDuplicateField.ts, 373, 33)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 374, 24)) + + set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_Setter.#foo, Decl(privateNameDuplicateField.ts, 374, 42)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 375, 17)) + } + + // Error + class A_StaticSetter_StaticField { +>A_StaticSetter_StaticField : Symbol(A_StaticSetter_StaticField, Decl(privateNameDuplicateField.ts, 376, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 379, 38), Decl(privateNameDuplicateField.ts, 380, 42)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 380, 24)) + + static #foo = "foo"; +>#foo : Symbol(A_StaticSetter_StaticField.#foo, Decl(privateNameDuplicateField.ts, 379, 38), Decl(privateNameDuplicateField.ts, 380, 42)) + } + + // Error + class A_StaticSetter_StaticMethod { +>A_StaticSetter_StaticMethod : Symbol(A_StaticSetter_StaticMethod, Decl(privateNameDuplicateField.ts, 382, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 385, 39)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 386, 24)) + + static #foo() { } +>#foo : Symbol(A_StaticSetter_StaticMethod.#foo, Decl(privateNameDuplicateField.ts, 386, 42)) + } + + // OK + class A_StaticSetter_StaticGetter { +>A_StaticSetter_StaticGetter : Symbol(A_StaticSetter_StaticGetter, Decl(privateNameDuplicateField.ts, 388, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 391, 39), Decl(privateNameDuplicateField.ts, 392, 42)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 392, 24)) + + static get #foo() { return ""} +>#foo : Symbol(A_StaticSetter_StaticGetter.#foo, Decl(privateNameDuplicateField.ts, 391, 39), Decl(privateNameDuplicateField.ts, 392, 42)) + } + + // Error + class A_StaticSetter_StaticSetter { +>A_StaticSetter_StaticSetter : Symbol(A_StaticSetter_StaticSetter, Decl(privateNameDuplicateField.ts, 394, 5)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 397, 39)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 398, 24)) + + static set #foo(value: string) { } +>#foo : Symbol(A_StaticSetter_StaticSetter.#foo, Decl(privateNameDuplicateField.ts, 398, 42)) +>value : Symbol(value, Decl(privateNameDuplicateField.ts, 399, 24)) + } } diff --git a/tests/baselines/reference/privateNameDuplicateField.types b/tests/baselines/reference/privateNameDuplicateField.types index 0f67eac2456aa..38614717ec2ad 100644 --- a/tests/baselines/reference/privateNameDuplicateField.types +++ b/tests/baselines/reference/privateNameDuplicateField.types @@ -1,13 +1,832 @@ === tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts === -class A { ->A : A +function Field() { +>Field : () => void - #foo = "foo"; + // Error + class A_Field_Field { +>A_Field_Field : A_Field_Field + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_Field_Method { +>A_Field_Method : A_Field_Method + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + #foo() { } +>#foo : () => void + } + + // Error + class A_Field_Getter { +>A_Field_Getter : A_Field_Getter + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Field_Setter { +>A_Field_Setter : A_Field_Setter + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_Field_StaticField { +>A_Field_StaticField : A_Field_StaticField + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_Field_StaticMethod { +>A_Field_StaticMethod : A_Field_StaticMethod + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static #foo() { } +>#foo : () => void + } + + // Error + class A_Field_StaticGetter { +>A_Field_StaticGetter : A_Field_StaticGetter + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Field_StaticSetter { +>A_Field_StaticSetter : A_Field_StaticSetter + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + +function Method() { +>Method : () => void + + // Error + class A_Method_Field { +>A_Method_Field : A_Method_Field + + #foo() { } +>#foo : () => void + + #foo = "foo"; +>#foo : () => void +>"foo" : "foo" + } + + // Error + class A_Method_Method { +>A_Method_Method : A_Method_Method + + #foo() { } +>#foo : () => void + + #foo() { } +>#foo : () => void + } + + // Error + class A_Method_Getter { +>A_Method_Getter : A_Method_Getter + + #foo() { } +>#foo : () => void + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Method_Setter { +>A_Method_Setter : A_Method_Setter + + #foo() { } +>#foo : () => void + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_Method_StaticField { +>A_Method_StaticField : A_Method_StaticField + + #foo() { } +>#foo : () => void + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_Method_StaticMethod { +>A_Method_StaticMethod : A_Method_StaticMethod + + #foo() { } +>#foo : () => void + + static #foo() { } +>#foo : () => void + } + + // Error + class A_Method_StaticGetter { +>A_Method_StaticGetter : A_Method_StaticGetter + + #foo() { } +>#foo : () => void + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Method_StaticSetter { +>A_Method_StaticSetter : A_Method_StaticSetter + + #foo() { } +>#foo : () => void + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + + +function Getter() { +>Getter : () => void + + // Error + class A_Getter_Field { +>A_Getter_Field : A_Getter_Field + + get #foo() { return ""} +>#foo : string +>"" : "" + + #foo = "foo"; >#foo : string >"foo" : "foo" + } + + // Error + class A_Getter_Method { +>A_Getter_Method : A_Getter_Method + + get #foo() { return ""} +>#foo : string +>"" : "" + + #foo() { } +>#foo : () => void + } + + // Error + class A_Getter_Getter { +>A_Getter_Getter : A_Getter_Getter + + get #foo() { return ""} +>#foo : string +>"" : "" + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + //OK + class A_Getter_Setter { +>A_Getter_Setter : A_Getter_Setter + + get #foo() { return ""} +>#foo : string +>"" : "" + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_Getter_StaticField { +>A_Getter_StaticField : A_Getter_StaticField + + get #foo() { return ""} +>#foo : string +>"" : "" + + static #foo() { } +>#foo : () => void + } + + // Error + class A_Getter_StaticMethod { +>A_Getter_StaticMethod : A_Getter_StaticMethod + + get #foo() { return ""} +>#foo : string +>"" : "" + + static #foo() { } +>#foo : () => void + } + + // Error + class A_Getter_StaticGetter { +>A_Getter_StaticGetter : A_Getter_StaticGetter + + get #foo() { return ""} +>#foo : string +>"" : "" + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Getter_StaticSetter { +>A_Getter_StaticSetter : A_Getter_StaticSetter + + get #foo() { return ""} +>#foo : string +>"" : "" + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + +function Setter() { +>Setter : () => void + + // Error + class A_Setter_Field { +>A_Setter_Field : A_Setter_Field - #foo = "foo"; + set #foo(value: string) { } +>#foo : string +>value : string + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_Setter_Method { +>A_Setter_Method : A_Setter_Method + + set #foo(value: string) { } +>#foo : string +>value : string + + #foo() { } +>#foo : () => void + } + + // OK + class A_Setter_Getter { +>A_Setter_Getter : A_Setter_Getter + + set #foo(value: string) { } +>#foo : string +>value : string + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Setter_Setter { +>A_Setter_Setter : A_Setter_Setter + + set #foo(value: string) { } +>#foo : string +>value : string + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_Setter_StaticField { +>A_Setter_StaticField : A_Setter_StaticField + + set #foo(value: string) { } +>#foo : string +>value : string + + static #foo = "foo"; >#foo : string >"foo" : "foo" + } + + // Error + class A_Setter_StaticMethod { +>A_Setter_StaticMethod : A_Setter_StaticMethod + + set #foo(value: string) { } +>#foo : string +>value : string + + static #foo() { } +>#foo : () => void + } + + // Error + class A_Setter_StaticGetter { +>A_Setter_StaticGetter : A_Setter_StaticGetter + + set #foo(value: string) { } +>#foo : string +>value : string + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_Setter_StaticSetter { +>A_Setter_StaticSetter : A_Setter_StaticSetter + + set #foo(value: string) { } +>#foo : string +>value : string + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + +function StaticField() { +>StaticField : () => void + + // Error + class A_StaticField_Field { +>A_StaticField_Field : A_StaticField_Field + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_StaticField_Method { +>A_StaticField_Method : A_StaticField_Method + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + #foo() { } +>#foo : () => void + } + + // Error + class A_StaticField_Getter { +>A_StaticField_Getter : A_StaticField_Getter + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticField_Setter { +>A_StaticField_Setter : A_StaticField_Setter + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_StaticField_StaticField { +>A_StaticField_StaticField : A_StaticField_StaticField + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_StaticField_StaticMethod { +>A_StaticField_StaticMethod : A_StaticField_StaticMethod + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static #foo() { } +>#foo : () => void + } + + // Error + class A_StaticField_StaticGetter { +>A_StaticField_StaticGetter : A_StaticField_StaticGetter + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticField_StaticSetter { +>A_StaticField_StaticSetter : A_StaticField_StaticSetter + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + +function StaticMethod() { +>StaticMethod : () => void + + // Error + class A_StaticMethod_Field { +>A_StaticMethod_Field : A_StaticMethod_Field + + static #foo() { } +>#foo : () => void + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_StaticMethod_Method { +>A_StaticMethod_Method : A_StaticMethod_Method + + static #foo() { } +>#foo : () => void + + #foo() { } +>#foo : () => void + } + + // Error + class A_StaticMethod_Getter { +>A_StaticMethod_Getter : A_StaticMethod_Getter + + static #foo() { } +>#foo : () => void + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticMethod_Setter { +>A_StaticMethod_Setter : A_StaticMethod_Setter + + static #foo() { } +>#foo : () => void + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_StaticMethod_StaticField { +>A_StaticMethod_StaticField : A_StaticMethod_StaticField + + static #foo() { } +>#foo : () => void + + static #foo = "foo"; +>#foo : () => void +>"foo" : "foo" + } + + // Error + class A_StaticMethod_StaticMethod { +>A_StaticMethod_StaticMethod : A_StaticMethod_StaticMethod + + static #foo() { } +>#foo : () => void + + static #foo() { } +>#foo : () => void + } + + // Error + class A_StaticMethod_StaticGetter { +>A_StaticMethod_StaticGetter : A_StaticMethod_StaticGetter + + static #foo() { } +>#foo : () => void + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticMethod_StaticSetter { +>A_StaticMethod_StaticSetter : A_StaticMethod_StaticSetter + + static #foo() { } +>#foo : () => void + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + +function StaticGetter() { +>StaticGetter : () => void + + // Error + class A_StaticGetter_Field { +>A_StaticGetter_Field : A_StaticGetter_Field + + static get #foo() { return ""} +>#foo : string +>"" : "" + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_StaticGetter_Method { +>A_StaticGetter_Method : A_StaticGetter_Method + + static get #foo() { return ""} +>#foo : string +>"" : "" + + #foo() { } +>#foo : () => void + } + + // Error + class A_StaticGetter_Getter { +>A_StaticGetter_Getter : A_StaticGetter_Getter + + static get #foo() { return ""} +>#foo : string +>"" : "" + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticGetter_Setter { +>A_StaticGetter_Setter : A_StaticGetter_Setter + + static get #foo() { return ""} +>#foo : string +>"" : "" + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_StaticGetter_StaticField { +>A_StaticGetter_StaticField : A_StaticGetter_StaticField + + static get #foo() { return ""} +>#foo : string +>"" : "" + + static #foo() { } +>#foo : () => void + } + + // Error + class A_StaticGetter_StaticMethod { +>A_StaticGetter_StaticMethod : A_StaticGetter_StaticMethod + + static get #foo() { return ""} +>#foo : string +>"" : "" + + static #foo() { } +>#foo : () => void + } + + // Error + class A_StaticGetter_StaticGetter { +>A_StaticGetter_StaticGetter : A_StaticGetter_StaticGetter + + static get #foo() { return ""} +>#foo : string +>"" : "" + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + // OK + class A_StaticGetter_StaticSetter { +>A_StaticGetter_StaticSetter : A_StaticGetter_StaticSetter + + static get #foo() { return ""} +>#foo : string +>"" : "" + + static set #foo(value: string) { } +>#foo : string +>value : string + } +} + +function StaticSetter() { +>StaticSetter : () => void + + // Error + class A_StaticSetter_Field { +>A_StaticSetter_Field : A_StaticSetter_Field + + static set #foo(value: string) { } +>#foo : string +>value : string + + #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_StaticSetter_Method { +>A_StaticSetter_Method : A_StaticSetter_Method + + static set #foo(value: string) { } +>#foo : string +>value : string + + #foo() { } +>#foo : () => void + } + + + // Error + class A_StaticSetter_Getter { +>A_StaticSetter_Getter : A_StaticSetter_Getter + + static set #foo(value: string) { } +>#foo : string +>value : string + + get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticSetter_Setter { +>A_StaticSetter_Setter : A_StaticSetter_Setter + + static set #foo(value: string) { } +>#foo : string +>value : string + + set #foo(value: string) { } +>#foo : string +>value : string + } + + // Error + class A_StaticSetter_StaticField { +>A_StaticSetter_StaticField : A_StaticSetter_StaticField + + static set #foo(value: string) { } +>#foo : string +>value : string + + static #foo = "foo"; +>#foo : string +>"foo" : "foo" + } + + // Error + class A_StaticSetter_StaticMethod { +>A_StaticSetter_StaticMethod : A_StaticSetter_StaticMethod + + static set #foo(value: string) { } +>#foo : string +>value : string + + static #foo() { } +>#foo : () => void + } + + // OK + class A_StaticSetter_StaticGetter { +>A_StaticSetter_StaticGetter : A_StaticSetter_StaticGetter + + static set #foo(value: string) { } +>#foo : string +>value : string + + static get #foo() { return ""} +>#foo : string +>"" : "" + } + + // Error + class A_StaticSetter_StaticSetter { +>A_StaticSetter_StaticSetter : A_StaticSetter_StaticSetter + + static set #foo(value: string) { } +>#foo : string +>value : string + + static set #foo(value: string) { } +>#foo : string +>value : string + } } diff --git a/tests/baselines/reference/privateNameES5Ban(target=es3).errors.txt b/tests/baselines/reference/privateNameES5Ban(target=es3).errors.txt index 48669311941cc..7d7cc6e006dbe 100644 --- a/tests/baselines/reference/privateNameES5Ban(target=es3).errors.txt +++ b/tests/baselines/reference/privateNameES5Ban(target=es3).errors.txt @@ -1,18 +1,14 @@ tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(3,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(4,5): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(5,5): error TS18019: 'static' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(6,12): error TS18022: A method cannot be named with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(4,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(5,12): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(6,12): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(7,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(7,9): error TS18023: An accessor cannot be named with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(8,9): error TS18023: An accessor cannot be named with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(9,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(9,16): error TS18023: An accessor cannot be named with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(10,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(10,16): error TS18023: An accessor cannot be named with a private identifier. -==== tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts (12 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts (8 errors) ==== class A { constructor() {} #field = 123; @@ -20,33 +16,25 @@ tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(10,16) !!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. #method() {} ~~~~~~~ -!!! error TS18022: A method cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. static #sField = "hello world"; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. + ~~~~~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. static #sMethod() {} ~~~~~~~~ -!!! error TS18022: A method cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. get #acc() { return ""; } ~~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. set #acc(x: string) {} ~~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. static get #sAcc() { return 0; } ~~~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. static set #sAcc(x: number) {} ~~~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameES5Ban(target=es3).js b/tests/baselines/reference/privateNameES5Ban(target=es3).js index b17b950cbf530..c7626d30e12fb 100644 --- a/tests/baselines/reference/privateNameES5Ban(target=es3).js +++ b/tests/baselines/reference/privateNameES5Ban(target=es3).js @@ -16,24 +16,11 @@ class A { //// [privateNameES5Ban.js] var A = /** @class */ (function () { function A() { - _field.set(this, 123); + _A_instances.add(this); + _A_field.set(this, 123); } - A.prototype. = function () { }; - A. = function () { }; - Object.defineProperty(A.prototype, "", { - get: function () { return ""; }, - set: function (x) { }, - enumerable: false, - configurable: true - }); - Object.defineProperty(A, "", { - get: function () { return 0; }, - set: function (x) { }, - enumerable: false, - configurable: true - }); - var _field, _sField; - _field = new WeakMap(), _sField = new WeakMap(); - _sField.set(A, "hello world"); + var _A_instances, _a, _A_field, _A_method, _A_sField, _A_sMethod, _A_acc_get, _A_acc_set, _A_sAcc_get, _A_sAcc_set; + _a = A, _A_field = new WeakMap(), _A_instances = new WeakSet(), _A_method = function _A_method() { }, _A_sMethod = function _A_sMethod() { }, _A_acc_get = function _A_acc_get() { return ""; }, _A_acc_set = function _A_acc_set(x) { }, _A_sAcc_get = function _A_sAcc_get() { return 0; }, _A_sAcc_set = function _A_sAcc_set(x) { }; + _A_sField = { value: "hello world" }; return A; }()); diff --git a/tests/baselines/reference/privateNameES5Ban(target=es5).errors.txt b/tests/baselines/reference/privateNameES5Ban(target=es5).errors.txt index 98da48317a6fa..76ab55e14f711 100644 --- a/tests/baselines/reference/privateNameES5Ban(target=es5).errors.txt +++ b/tests/baselines/reference/privateNameES5Ban(target=es5).errors.txt @@ -1,11 +1,11 @@ tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(3,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(4,5): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(5,5): error TS18019: 'static' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(6,12): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(7,9): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(8,9): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(9,16): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(10,16): error TS18023: An accessor cannot be named with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(4,5): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(5,12): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(6,12): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(7,9): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(8,9): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(9,16): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(10,16): error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. ==== tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts (8 errors) ==== @@ -16,25 +16,25 @@ tests/cases/conformance/classes/members/privateNames/privateNameES5Ban.ts(10,16) !!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. #method() {} ~~~~~~~ -!!! error TS18022: A method cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. static #sField = "hello world"; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. + ~~~~~~~ +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. static #sMethod() {} ~~~~~~~~ -!!! error TS18022: A method cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. get #acc() { return ""; } ~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. set #acc(x: string) {} ~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. static get #sAcc() { return 0; } ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. static set #sAcc(x: number) {} ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. +!!! error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher. } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameES5Ban(target=es5).js b/tests/baselines/reference/privateNameES5Ban(target=es5).js index b17b950cbf530..c7626d30e12fb 100644 --- a/tests/baselines/reference/privateNameES5Ban(target=es5).js +++ b/tests/baselines/reference/privateNameES5Ban(target=es5).js @@ -16,24 +16,11 @@ class A { //// [privateNameES5Ban.js] var A = /** @class */ (function () { function A() { - _field.set(this, 123); + _A_instances.add(this); + _A_field.set(this, 123); } - A.prototype. = function () { }; - A. = function () { }; - Object.defineProperty(A.prototype, "", { - get: function () { return ""; }, - set: function (x) { }, - enumerable: false, - configurable: true - }); - Object.defineProperty(A, "", { - get: function () { return 0; }, - set: function (x) { }, - enumerable: false, - configurable: true - }); - var _field, _sField; - _field = new WeakMap(), _sField = new WeakMap(); - _sField.set(A, "hello world"); + var _A_instances, _a, _A_field, _A_method, _A_sField, _A_sMethod, _A_acc_get, _A_acc_set, _A_sAcc_get, _A_sAcc_set; + _a = A, _A_field = new WeakMap(), _A_instances = new WeakSet(), _A_method = function _A_method() { }, _A_sMethod = function _A_sMethod() { }, _A_acc_get = function _A_acc_get() { return ""; }, _A_acc_set = function _A_acc_set(x) { }, _A_sAcc_get = function _A_sAcc_get() { return 0; }, _A_sAcc_set = function _A_sAcc_set(x) { }; + _A_sField = { value: "hello world" }; return A; }()); diff --git a/tests/baselines/reference/privateNameEmitHelpers.errors.txt b/tests/baselines/reference/privateNameEmitHelpers.errors.txt new file mode 100644 index 0000000000000..05d5fd4a7e8fb --- /dev/null +++ b/tests/baselines/reference/privateNameEmitHelpers.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/classes/members/privateNames/main.ts(3,12): error TS2807: This syntax requires an imported helper named '__classPrivateFieldSet' with 5 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. +tests/cases/conformance/classes/members/privateNames/main.ts(4,25): error TS2807: This syntax requires an imported helper named '__classPrivateFieldGet' with 4 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. + + +==== tests/cases/conformance/classes/members/privateNames/main.ts (2 errors) ==== + export class C { + #a = 1; + #b() { this.#c = 42; } + ~~~~~~~ +!!! error TS2807: This syntax requires an imported helper named '__classPrivateFieldSet' with 5 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. + set #c(v: number) { this.#a += v; } + ~~~~~~~ +!!! error TS2807: This syntax requires an imported helper named '__classPrivateFieldGet' with 4 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. + } + +==== tests/cases/conformance/classes/members/privateNames/tslib.d.ts (0 errors) ==== + // these are pre-TS4.3 versions of emit helpers, which only supported private instance fields + export declare function __classPrivateFieldGet(receiver: T, state: any): V; + export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameEmitHelpers.js b/tests/baselines/reference/privateNameEmitHelpers.js new file mode 100644 index 0000000000000..1c46c25afa8fe --- /dev/null +++ b/tests/baselines/reference/privateNameEmitHelpers.js @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/classes/members/privateNames/privateNameEmitHelpers.ts] //// + +//// [main.ts] +export class C { + #a = 1; + #b() { this.#c = 42; } + set #c(v: number) { this.#a += v; } +} + +//// [tslib.d.ts] +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; + + +//// [main.js] +var _C_instances, _C_a, _C_b, _C_c_set; +import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; +export class C { + constructor() { + _C_instances.add(this); + _C_a.set(this, 1); + } +} +_C_a = new WeakMap(), _C_instances = new WeakSet(), _C_b = function _C_b() { __classPrivateFieldSet(this, _C_instances, 42, "a", _C_c_set); }, _C_c_set = function _C_c_set(v) { __classPrivateFieldSet(this, _C_a, __classPrivateFieldGet(this, _C_a, "f") + v, "f"); }; diff --git a/tests/baselines/reference/privateNameEmitHelpers.symbols b/tests/baselines/reference/privateNameEmitHelpers.symbols new file mode 100644 index 0000000000000..6b34f80303b77 --- /dev/null +++ b/tests/baselines/reference/privateNameEmitHelpers.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/members/privateNames/main.ts === +export class C { +>C : Symbol(C, Decl(main.ts, 0, 0)) + + #a = 1; +>#a : Symbol(C.#a, Decl(main.ts, 0, 16)) + + #b() { this.#c = 42; } +>#b : Symbol(C.#b, Decl(main.ts, 1, 11)) +>this.#c : Symbol(C.#c, Decl(main.ts, 2, 26)) +>this : Symbol(C, Decl(main.ts, 0, 0)) + + set #c(v: number) { this.#a += v; } +>#c : Symbol(C.#c, Decl(main.ts, 2, 26)) +>v : Symbol(v, Decl(main.ts, 3, 11)) +>this.#a : Symbol(C.#a, Decl(main.ts, 0, 16)) +>this : Symbol(C, Decl(main.ts, 0, 0)) +>v : Symbol(v, Decl(main.ts, 3, 11)) +} + +=== tests/cases/conformance/classes/members/privateNames/tslib.d.ts === +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +>__classPrivateFieldGet : Symbol(__classPrivateFieldGet, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) +>receiver : Symbol(receiver, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>state : Symbol(state, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) + +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; +>__classPrivateFieldSet : Symbol(__classPrivateFieldSet, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) +>receiver : Symbol(receiver, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>state : Symbol(state, Decl(tslib.d.ts, --, --)) +>value : Symbol(value, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) + diff --git a/tests/baselines/reference/privateNameEmitHelpers.types b/tests/baselines/reference/privateNameEmitHelpers.types new file mode 100644 index 0000000000000..e45e6b60df3ce --- /dev/null +++ b/tests/baselines/reference/privateNameEmitHelpers.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/privateNames/main.ts === +export class C { +>C : C + + #a = 1; +>#a : number +>1 : 1 + + #b() { this.#c = 42; } +>#b : () => void +>this.#c = 42 : 42 +>this.#c : number +>this : this +>42 : 42 + + set #c(v: number) { this.#a += v; } +>#c : number +>v : number +>this.#a += v : number +>this.#a : number +>this : this +>v : number +} + +=== tests/cases/conformance/classes/members/privateNames/tslib.d.ts === +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +>__classPrivateFieldGet : (receiver: T, state: any) => V +>receiver : T +>state : any + +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; +>__classPrivateFieldSet : (receiver: T, state: any, value: V) => V +>receiver : T +>state : any +>value : V + diff --git a/tests/baselines/reference/privateNameField.js b/tests/baselines/reference/privateNameField.js index 8803d856771ae..cf1da2bfb3f78 100644 --- a/tests/baselines/reference/privateNameField.js +++ b/tests/baselines/reference/privateNameField.js @@ -9,18 +9,17 @@ class A { //// [privateNameField.js] "use strict"; -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _name; +var _A_name; class A { constructor(name) { - _name.set(this, void 0); - __classPrivateFieldSet(this, _name, name); + _A_name.set(this, void 0); + __classPrivateFieldSet(this, _A_name, name, "f"); } } -_name = new WeakMap(); +_A_name = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldAccess.js b/tests/baselines/reference/privateNameFieldAccess.js index 35f418690881c..c6cb80234ec09 100644 --- a/tests/baselines/reference/privateNameFieldAccess.js +++ b/tests/baselines/reference/privateNameFieldAccess.js @@ -8,17 +8,16 @@ class A { //// [privateNameFieldAccess.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _myField; +var _A_myField; class A { constructor() { - _myField.set(this, "hello world"); - console.log(__classPrivateFieldGet(this, _myField)); + _A_myField.set(this, "hello world"); + console.log(__classPrivateFieldGet(this, _A_myField, "f")); } } -_myField = new WeakMap(); +_A_myField = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldAssignment.js b/tests/baselines/reference/privateNameFieldAssignment.js index 3442958b508ec..86d8d6fed8214 100644 --- a/tests/baselines/reference/privateNameFieldAssignment.js +++ b/tests/baselines/reference/privateNameFieldAssignment.js @@ -36,53 +36,51 @@ class A { //// [privateNameFieldAssignment.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _field; +var _A_field; class A { constructor() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; - _field.set(this, 0); - __classPrivateFieldSet(this, _field, 1); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) + 2); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) - 3); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) / 4); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) * 5); - __classPrivateFieldSet(this, _field, Math.pow(__classPrivateFieldGet(this, _field), 6)); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) % 7); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) << 8); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) >> 9); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) >>> 10); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) & 11); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) | 12); - __classPrivateFieldSet(this, _field, __classPrivateFieldGet(this, _field) ^ 13); - __classPrivateFieldSet(A.getInstance(), _field, 1); - __classPrivateFieldSet(_a = A.getInstance(), _field, __classPrivateFieldGet(_a, _field) + 2); - __classPrivateFieldSet(_b = A.getInstance(), _field, __classPrivateFieldGet(_b, _field) - 3); - __classPrivateFieldSet(_c = A.getInstance(), _field, __classPrivateFieldGet(_c, _field) / 4); - __classPrivateFieldSet(_d = A.getInstance(), _field, __classPrivateFieldGet(_d, _field) * 5); - __classPrivateFieldSet(_e = A.getInstance(), _field, Math.pow(__classPrivateFieldGet(_e, _field), 6)); - __classPrivateFieldSet(_f = A.getInstance(), _field, __classPrivateFieldGet(_f, _field) % 7); - __classPrivateFieldSet(_g = A.getInstance(), _field, __classPrivateFieldGet(_g, _field) << 8); - __classPrivateFieldSet(_h = A.getInstance(), _field, __classPrivateFieldGet(_h, _field) >> 9); - __classPrivateFieldSet(_j = A.getInstance(), _field, __classPrivateFieldGet(_j, _field) >>> 10); - __classPrivateFieldSet(_k = A.getInstance(), _field, __classPrivateFieldGet(_k, _field) & 11); - __classPrivateFieldSet(_l = A.getInstance(), _field, __classPrivateFieldGet(_l, _field) | 12); - __classPrivateFieldSet(_m = A.getInstance(), _field, __classPrivateFieldGet(_m, _field) ^ 13); + _A_field.set(this, 0); + __classPrivateFieldSet(this, _A_field, 1, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") + 2, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") - 3, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") / 4, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") * 5, "f"); + __classPrivateFieldSet(this, _A_field, Math.pow(__classPrivateFieldGet(this, _A_field, "f"), 6), "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") % 7, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") << 8, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") >> 9, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") >>> 10, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") & 11, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") | 12, "f"); + __classPrivateFieldSet(this, _A_field, __classPrivateFieldGet(this, _A_field, "f") ^ 13, "f"); + __classPrivateFieldSet(A.getInstance(), _A_field, 1, "f"); + __classPrivateFieldSet(_a = A.getInstance(), _A_field, __classPrivateFieldGet(_a, _A_field, "f") + 2, "f"); + __classPrivateFieldSet(_b = A.getInstance(), _A_field, __classPrivateFieldGet(_b, _A_field, "f") - 3, "f"); + __classPrivateFieldSet(_c = A.getInstance(), _A_field, __classPrivateFieldGet(_c, _A_field, "f") / 4, "f"); + __classPrivateFieldSet(_d = A.getInstance(), _A_field, __classPrivateFieldGet(_d, _A_field, "f") * 5, "f"); + __classPrivateFieldSet(_e = A.getInstance(), _A_field, Math.pow(__classPrivateFieldGet(_e, _A_field, "f"), 6), "f"); + __classPrivateFieldSet(_f = A.getInstance(), _A_field, __classPrivateFieldGet(_f, _A_field, "f") % 7, "f"); + __classPrivateFieldSet(_g = A.getInstance(), _A_field, __classPrivateFieldGet(_g, _A_field, "f") << 8, "f"); + __classPrivateFieldSet(_h = A.getInstance(), _A_field, __classPrivateFieldGet(_h, _A_field, "f") >> 9, "f"); + __classPrivateFieldSet(_j = A.getInstance(), _A_field, __classPrivateFieldGet(_j, _A_field, "f") >>> 10, "f"); + __classPrivateFieldSet(_k = A.getInstance(), _A_field, __classPrivateFieldGet(_k, _A_field, "f") & 11, "f"); + __classPrivateFieldSet(_l = A.getInstance(), _A_field, __classPrivateFieldGet(_l, _A_field, "f") | 12, "f"); + __classPrivateFieldSet(_m = A.getInstance(), _A_field, __classPrivateFieldGet(_m, _A_field, "f") ^ 13, "f"); } static getInstance() { return new A(); } } -_field = new WeakMap(); +_A_field = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldCallExpression.js b/tests/baselines/reference/privateNameFieldCallExpression.js index e4b9a413672fc..07eb4455d03d7 100644 --- a/tests/baselines/reference/privateNameFieldCallExpression.js +++ b/tests/baselines/reference/privateNameFieldCallExpression.js @@ -21,33 +21,32 @@ class A { //// [privateNameFieldCallExpression.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _fieldFunc, _fieldFunc2; +var _A_fieldFunc, _A_fieldFunc2; class A { constructor() { - _fieldFunc.set(this, function () { this.x = 10; }); - _fieldFunc2.set(this, function (a, ...b) { }); + _A_fieldFunc.set(this, function () { this.x = 10; }); + _A_fieldFunc2.set(this, function (a, ...b) { }); this.x = 1; } test() { var _a; var _b; - __classPrivateFieldGet(this, _fieldFunc).call(this); - (_a = __classPrivateFieldGet(this, _fieldFunc)) === null || _a === void 0 ? void 0 : _a.call(this); - const func = __classPrivateFieldGet(this, _fieldFunc); + __classPrivateFieldGet(this, _A_fieldFunc, "f").call(this); + (_a = __classPrivateFieldGet(this, _A_fieldFunc, "f")) === null || _a === void 0 ? void 0 : _a.call(this); + const func = __classPrivateFieldGet(this, _A_fieldFunc, "f"); func(); - new (__classPrivateFieldGet(this, _fieldFunc))(); + new (__classPrivateFieldGet(this, _A_fieldFunc, "f"))(); const arr = [1, 2]; - __classPrivateFieldGet(this, _fieldFunc2).call(this, 0, ...arr, 3); - const b = new (__classPrivateFieldGet(this, _fieldFunc2))(0, ...arr, 3); - const str = __classPrivateFieldGet(this, _fieldFunc2).bind(this) `head${1}middle${2}tail`; - __classPrivateFieldGet((_b = this.getInstance()), _fieldFunc2).bind(_b) `test${1}and${2}`; + __classPrivateFieldGet(this, _A_fieldFunc2, "f").call(this, 0, ...arr, 3); + const b = new (__classPrivateFieldGet(this, _A_fieldFunc2, "f"))(0, ...arr, 3); + const str = __classPrivateFieldGet(this, _A_fieldFunc2, "f").bind(this) `head${1}middle${2}tail`; + __classPrivateFieldGet((_b = this.getInstance()), _A_fieldFunc2, "f").bind(_b) `test${1}and${2}`; } getInstance() { return new A(); } } -_fieldFunc = new WeakMap(), _fieldFunc2 = new WeakMap(); +_A_fieldFunc = new WeakMap(), _A_fieldFunc2 = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldClassExpression.js b/tests/baselines/reference/privateNameFieldClassExpression.js index 2d1641da71244..b62835d6fe036 100644 --- a/tests/baselines/reference/privateNameFieldClassExpression.js +++ b/tests/baselines/reference/privateNameFieldClassExpression.js @@ -15,21 +15,21 @@ class B { //// [privateNameFieldClassExpression.js] -var _foo, _foo2; +var _B_foo, _B_foo2; class B { constructor() { var _a, _b; - _foo.set(this, (_a = class { + _B_foo.set(this, (_a = class { constructor() { console.log("hello"); } }, _a.test = 123, _a)); - _foo2.set(this, (_b = class Foo { + _B_foo2.set(this, (_b = class Foo { }, _b.otherClass = 123, _b)); } } -_foo = new WeakMap(), _foo2 = new WeakMap(); +_B_foo = new WeakMap(), _B_foo2 = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldDerivedClasses.js b/tests/baselines/reference/privateNameFieldDerivedClasses.js index f38db5914e9ba..a469e47df30b1 100644 --- a/tests/baselines/reference/privateNameFieldDerivedClasses.js +++ b/tests/baselines/reference/privateNameFieldDerivedClasses.js @@ -14,22 +14,21 @@ class Derived extends Base { //// [privateNameFieldDerivedClasses.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _prop; +var _Base_prop; class Base { constructor() { - _prop.set(this, 123); + _Base_prop.set(this, 123); } static method(x) { - console.log(__classPrivateFieldGet(x, _prop)); + console.log(__classPrivateFieldGet(x, _Base_prop, "f")); } } -_prop = new WeakMap(); +_Base_prop = new WeakMap(); class Derived extends Base { static method(x) { console.log(x.); diff --git a/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js b/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js index b45ccaedfe481..e81cf2550e0a0 100644 --- a/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js +++ b/tests/baselines/reference/privateNameFieldDestructuredBinding(target=es2015).js @@ -25,27 +25,26 @@ class A { //// [privateNameFieldDestructuredBinding.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _field; +var _A_field; class A { constructor() { var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; - _field.set(this, 1); + _A_field.set(this, 1); this.otherObject = new A(); let y; - (_b = this, { x: ({ set value(_m) { __classPrivateFieldSet(_b, _field, _m); } }).value, y } = this.testObject()); - (_c = this, [({ set value(_m) { __classPrivateFieldSet(_c, _field, _m); } }).value, y] = this.testArray()); - (_d = this, _e = this, { a: ({ set value(_m) { __classPrivateFieldSet(_d, _field, _m); } }).value, b: [({ set value(_m) { __classPrivateFieldSet(_e, _field, _m); } }).value] } = { a: 1, b: [2] }); - _f = this, _g = this, [({ set value(_m) { __classPrivateFieldSet(_f, _field, _m); } }).value, [({ set value(_m) { __classPrivateFieldSet(_g, _field, _m); } }).value]] = [1, [2]]; - (_h = this, _j = this, { a: ({ set value(_m) { __classPrivateFieldSet(_h, _field, _m); } }).value = 1, b: [({ set value(_m) { __classPrivateFieldSet(_j, _field, _m); } }).value = 1] } = { b: [] }); - _k = this, [({ set value(_m) { __classPrivateFieldSet(_k, _field, _m); } }).value = 2] = []; - _l = this.otherObject, [({ set value(_m) { __classPrivateFieldSet(_l, _field, _m); } }).value = 2] = []; + (_b = this, { x: ({ set value(_m) { __classPrivateFieldSet(_b, _A_field, _m, "f"); } }).value, y } = this.testObject()); + (_c = this, [({ set value(_m) { __classPrivateFieldSet(_c, _A_field, _m, "f"); } }).value, y] = this.testArray()); + (_d = this, _e = this, { a: ({ set value(_m) { __classPrivateFieldSet(_d, _A_field, _m, "f"); } }).value, b: [({ set value(_m) { __classPrivateFieldSet(_e, _A_field, _m, "f"); } }).value] } = { a: 1, b: [2] }); + _f = this, _g = this, [({ set value(_m) { __classPrivateFieldSet(_f, _A_field, _m, "f"); } }).value, [({ set value(_m) { __classPrivateFieldSet(_g, _A_field, _m, "f"); } }).value]] = [1, [2]]; + (_h = this, _j = this, { a: ({ set value(_m) { __classPrivateFieldSet(_h, _A_field, _m, "f"); } }).value = 1, b: [({ set value(_m) { __classPrivateFieldSet(_j, _A_field, _m, "f"); } }).value = 1] } = { b: [] }); + _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 }; @@ -54,7 +53,7 @@ class A { return [10, 11]; } static test(_a) { - [({ set value(_b) { __classPrivateFieldSet(_a, _field, _b); } }).value] = [2]; + [({ set value(_b) { __classPrivateFieldSet(_a, _A_field, _b, "f"); } }).value] = [2]; } } -_field = new WeakMap(); +_A_field = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldInitializer.js b/tests/baselines/reference/privateNameFieldInitializer.js index 36aaae4851217..0fd9fd1b4235d 100644 --- a/tests/baselines/reference/privateNameFieldInitializer.js +++ b/tests/baselines/reference/privateNameFieldInitializer.js @@ -6,11 +6,11 @@ class A { //// [privateNameFieldInitializer.js] -var _field, _uninitialized; +var _A_field, _A_uninitialized; class A { constructor() { - _field.set(this, 10); - _uninitialized.set(this, void 0); + _A_field.set(this, 10); + _A_uninitialized.set(this, void 0); } } -_field = new WeakMap(), _uninitialized = new WeakMap(); +_A_field = new WeakMap(), _A_uninitialized = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldUnaryMutation.js b/tests/baselines/reference/privateNameFieldUnaryMutation.js index 91d4faecb4584..5ff58fdd5d68a 100644 --- a/tests/baselines/reference/privateNameFieldUnaryMutation.js +++ b/tests/baselines/reference/privateNameFieldUnaryMutation.js @@ -30,48 +30,46 @@ class C { //// [privateNameFieldUnaryMutation.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _test; +var _C_test; class C { constructor() { var _a, _b; - _test.set(this, 24); - __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) + 1); - __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) - 1); - __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) + 1); - __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) - 1); - const a = (__classPrivateFieldSet(this, _test, (_a = +__classPrivateFieldGet(this, _test)) + 1), _a); - const b = (__classPrivateFieldSet(this, _test, (_b = +__classPrivateFieldGet(this, _test)) - 1), _b); - const c = __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) + 1); - const d = __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) - 1); - for (__classPrivateFieldSet(this, _test, 0); __classPrivateFieldGet(this, _test) < 10; __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) + 1)) { } - for (__classPrivateFieldSet(this, _test, 0); __classPrivateFieldGet(this, _test) < 10; __classPrivateFieldSet(this, _test, +__classPrivateFieldGet(this, _test) + 1)) { } + _C_test.set(this, 24); + __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f"); + __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") - 1, "f"); + __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f"); + __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") - 1, "f"); + const a = (__classPrivateFieldSet(this, _C_test, (_a = +__classPrivateFieldGet(this, _C_test, "f")) + 1, "f"), _a); + const b = (__classPrivateFieldSet(this, _C_test, (_b = +__classPrivateFieldGet(this, _C_test, "f")) - 1, "f"), _b); + const c = __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f"); + const d = __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") - 1, "f"); + for (__classPrivateFieldSet(this, _C_test, 0, "f"); __classPrivateFieldGet(this, _C_test, "f") < 10; __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f")) { } + for (__classPrivateFieldSet(this, _C_test, 0, "f"); __classPrivateFieldGet(this, _C_test, "f") < 10; __classPrivateFieldSet(this, _C_test, +__classPrivateFieldGet(this, _C_test, "f") + 1, "f")) { } } test() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; - __classPrivateFieldSet(_a = this.getInstance(), _test, +__classPrivateFieldGet(_a, _test) + 1); - __classPrivateFieldSet(_b = this.getInstance(), _test, +__classPrivateFieldGet(_b, _test) - 1); - __classPrivateFieldSet(_c = this.getInstance(), _test, +__classPrivateFieldGet(_c, _test) + 1); - __classPrivateFieldSet(_d = this.getInstance(), _test, +__classPrivateFieldGet(_d, _test) - 1); - const a = (__classPrivateFieldSet(_e = this.getInstance(), _test, (_f = +__classPrivateFieldGet(_e, _test)) + 1), _f); - const b = (__classPrivateFieldSet(_g = this.getInstance(), _test, (_h = +__classPrivateFieldGet(_g, _test)) - 1), _h); - const c = __classPrivateFieldSet(_j = this.getInstance(), _test, +__classPrivateFieldGet(_j, _test) + 1); - const d = __classPrivateFieldSet(_k = this.getInstance(), _test, +__classPrivateFieldGet(_k, _test) - 1); - for (__classPrivateFieldSet(this.getInstance(), _test, 0); __classPrivateFieldGet(this.getInstance(), _test) < 10; __classPrivateFieldSet(_l = this.getInstance(), _test, +__classPrivateFieldGet(_l, _test) + 1)) { } - for (__classPrivateFieldSet(this.getInstance(), _test, 0); __classPrivateFieldGet(this.getInstance(), _test) < 10; __classPrivateFieldSet(_m = this.getInstance(), _test, +__classPrivateFieldGet(_m, _test) + 1)) { } + __classPrivateFieldSet(_a = this.getInstance(), _C_test, +__classPrivateFieldGet(_a, _C_test, "f") + 1, "f"); + __classPrivateFieldSet(_b = this.getInstance(), _C_test, +__classPrivateFieldGet(_b, _C_test, "f") - 1, "f"); + __classPrivateFieldSet(_c = this.getInstance(), _C_test, +__classPrivateFieldGet(_c, _C_test, "f") + 1, "f"); + __classPrivateFieldSet(_d = this.getInstance(), _C_test, +__classPrivateFieldGet(_d, _C_test, "f") - 1, "f"); + const a = (__classPrivateFieldSet(_e = this.getInstance(), _C_test, (_f = +__classPrivateFieldGet(_e, _C_test, "f")) + 1, "f"), _f); + const b = (__classPrivateFieldSet(_g = this.getInstance(), _C_test, (_h = +__classPrivateFieldGet(_g, _C_test, "f")) - 1, "f"), _h); + const c = __classPrivateFieldSet(_j = this.getInstance(), _C_test, +__classPrivateFieldGet(_j, _C_test, "f") + 1, "f"); + const d = __classPrivateFieldSet(_k = this.getInstance(), _C_test, +__classPrivateFieldGet(_k, _C_test, "f") - 1, "f"); + for (__classPrivateFieldSet(this.getInstance(), _C_test, 0, "f"); __classPrivateFieldGet(this.getInstance(), _C_test, "f") < 10; __classPrivateFieldSet(_l = this.getInstance(), _C_test, +__classPrivateFieldGet(_l, _C_test, "f") + 1, "f")) { } + for (__classPrivateFieldSet(this.getInstance(), _C_test, 0, "f"); __classPrivateFieldGet(this.getInstance(), _C_test, "f") < 10; __classPrivateFieldSet(_m = this.getInstance(), _C_test, +__classPrivateFieldGet(_m, _C_test, "f") + 1, "f")) { } } getInstance() { return new C(); } } -_test = new WeakMap(); +_C_test = new WeakMap(); diff --git a/tests/baselines/reference/privateNameFieldsESNext.errors.txt b/tests/baselines/reference/privateNameFieldsESNext.errors.txt index 5416ecb75a470..10288bc30085d 100644 --- a/tests/baselines/reference/privateNameFieldsESNext.errors.txt +++ b/tests/baselines/reference/privateNameFieldsESNext.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts(8,9): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts(11,5): error TS18019: 'static' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts(12,5): error TS18019: 'static' modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts(11,17): error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. -==== tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts (3 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts (2 errors) ==== class C { a = 123; #a = 10; @@ -17,11 +16,9 @@ tests/cases/conformance/classes/members/privateNames/privateNameFieldsESNext.ts( console.log(this.#b); } static #m = "test"; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. + ~~~~~~ +!!! error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. static #x; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. static test() { console.log(this.#m); console.log(this.#x = "test"); diff --git a/tests/baselines/reference/privateNameInLhsReceiverExpression.js b/tests/baselines/reference/privateNameInLhsReceiverExpression.js index 1f1fa882554c3..91dc82f992e8c 100644 --- a/tests/baselines/reference/privateNameInLhsReceiverExpression.js +++ b/tests/baselines/reference/privateNameInLhsReceiverExpression.js @@ -10,23 +10,21 @@ class Test { //// [privateNameInLhsReceiverExpression.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _y; +var _Test_y; class Test { constructor() { - _y.set(this, 123); + _Test_y.set(this, 123); } static something(obj) { var _x, _a, _x_1, _b, _c; @@ -37,7 +35,7 @@ class Test { } }, _x = new WeakMap(), - _a)).s], _y, 1); + _a)).s], _Test_y, 1, "f"); __classPrivateFieldSet(_c = obj[(new (_b = class { constructor() { _x_1.set(this, 1); @@ -45,7 +43,7 @@ class Test { } }, _x_1 = new WeakMap(), - _b)).s], _y, __classPrivateFieldGet(_c, _y) + 1); + _b)).s], _Test_y, __classPrivateFieldGet(_c, _Test_y, "f") + 1, "f"); } } -_y = new WeakMap(); +_Test_y = new WeakMap(); diff --git a/tests/baselines/reference/privateNameInObjectLiteral-3.errors.txt b/tests/baselines/reference/privateNameInObjectLiteral-3.errors.txt new file mode 100644 index 0000000000000..b93a8c149e491 --- /dev/null +++ b/tests/baselines/reference/privateNameInObjectLiteral-3.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts(2,9): error TS18016: Private identifiers are not allowed outside class bodies. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts (2 errors) ==== + const obj = { + get #foo() { + ~~~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + return "" + } + }; + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameInObjectLiteral-3.js b/tests/baselines/reference/privateNameInObjectLiteral-3.js new file mode 100644 index 0000000000000..e1394585ecca1 --- /dev/null +++ b/tests/baselines/reference/privateNameInObjectLiteral-3.js @@ -0,0 +1,14 @@ +//// [privateNameInObjectLiteral-3.ts] +const obj = { + get #foo() { + return "" + } +}; + + +//// [privateNameInObjectLiteral-3.js] +var obj = { + get () { + return ""; + } +}; diff --git a/tests/baselines/reference/privateNameInObjectLiteral-3.symbols b/tests/baselines/reference/privateNameInObjectLiteral-3.symbols new file mode 100644 index 0000000000000..190a94360eaf2 --- /dev/null +++ b/tests/baselines/reference/privateNameInObjectLiteral-3.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts === +const obj = { +>obj : Symbol(obj, Decl(privateNameInObjectLiteral-3.ts, 0, 5)) + + get #foo() { +>#foo : Symbol(#foo, Decl(privateNameInObjectLiteral-3.ts, 0, 13)) + + return "" + } +}; + diff --git a/tests/baselines/reference/privateNameInObjectLiteral-3.types b/tests/baselines/reference/privateNameInObjectLiteral-3.types new file mode 100644 index 0000000000000..20ec74dc18a36 --- /dev/null +++ b/tests/baselines/reference/privateNameInObjectLiteral-3.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts === +const obj = { +>obj : {} +>{ get #foo() { return "" }} : {} + + get #foo() { +>#foo : string + + return "" +>"" : "" + } +}; + diff --git a/tests/baselines/reference/privateNameJsBadDeclaration.errors.txt b/tests/baselines/reference/privateNameJsBadDeclaration.errors.txt index 206e257745708..858d9e96713fc 100644 --- a/tests/baselines/reference/privateNameJsBadDeclaration.errors.txt +++ b/tests/baselines/reference/privateNameJsBadDeclaration.errors.txt @@ -1,19 +1,41 @@ tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(3,3): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(7,3): error TS18016: Private identifiers are not allowed outside class bodies. -tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(11,10): error TS2339: Property '#z' does not exist on type 'C'. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(4,3): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(5,7): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(5,7): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(9,3): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(10,3): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(11,7): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(11,7): error TS18016: Private identifiers are not allowed outside class bodies. +tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js(15,10): error TS2339: Property '#z' does not exist on type 'C'. -==== tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js (3 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameJsPrototype.js (9 errors) ==== function A() { } A.prototype = { - #x: 1 // Error + #x: 1, // Error ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #m() {}, // Error + ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + get #p() { return "" } // Error + ~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } class B { } B.prototype = { - #y: 2 // Error + #y: 2, // Error ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + #m() {}, // Error + ~~ +!!! error TS18016: Private identifiers are not allowed outside class bodies. + get #p() { return "" } // Error + ~~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + ~~ !!! error TS18016: Private identifiers are not allowed outside class bodies. } class C { diff --git a/tests/baselines/reference/privateNameJsBadDeclaration.symbols b/tests/baselines/reference/privateNameJsBadDeclaration.symbols index 33a45250dcec5..53c99fe4238ee 100644 --- a/tests/baselines/reference/privateNameJsBadDeclaration.symbols +++ b/tests/baselines/reference/privateNameJsBadDeclaration.symbols @@ -7,25 +7,37 @@ A.prototype = { >A : Symbol(A, Decl(privateNameJsPrototype.js, 0, 0), Decl(privateNameJsPrototype.js, 0, 16)) >prototype : Symbol(A.prototype, Decl(privateNameJsPrototype.js, 0, 16)) - #x: 1 // Error + #x: 1, // Error >#x : Symbol(#x, Decl(privateNameJsPrototype.js, 1, 15)) + + #m() {}, // Error +>#m : Symbol(#m, Decl(privateNameJsPrototype.js, 2, 8)) + + get #p() { return "" } // Error +>#p : Symbol(#p, Decl(privateNameJsPrototype.js, 3, 10)) } class B { } ->B : Symbol(B, Decl(privateNameJsPrototype.js, 3, 1), Decl(privateNameJsPrototype.js, 4, 11)) +>B : Symbol(B, Decl(privateNameJsPrototype.js, 5, 1), Decl(privateNameJsPrototype.js, 6, 11)) B.prototype = { ->B.prototype : Symbol(B.prototype, Decl(privateNameJsPrototype.js, 4, 11)) ->B : Symbol(B, Decl(privateNameJsPrototype.js, 3, 1), Decl(privateNameJsPrototype.js, 4, 11)) ->prototype : Symbol(B.prototype, Decl(privateNameJsPrototype.js, 4, 11)) +>B.prototype : Symbol(B.prototype, Decl(privateNameJsPrototype.js, 6, 11)) +>B : Symbol(B, Decl(privateNameJsPrototype.js, 5, 1), Decl(privateNameJsPrototype.js, 6, 11)) +>prototype : Symbol(B.prototype, Decl(privateNameJsPrototype.js, 6, 11)) + + #y: 2, // Error +>#y : Symbol(#y, Decl(privateNameJsPrototype.js, 7, 15)) + + #m() {}, // Error +>#m : Symbol(#m, Decl(privateNameJsPrototype.js, 8, 8)) - #y: 2 // Error ->#y : Symbol(#y, Decl(privateNameJsPrototype.js, 5, 15)) + get #p() { return "" } // Error +>#p : Symbol(#p, Decl(privateNameJsPrototype.js, 9, 10)) } class C { ->C : Symbol(C, Decl(privateNameJsPrototype.js, 7, 1)) +>C : Symbol(C, Decl(privateNameJsPrototype.js, 11, 1)) constructor() { this.#z = 3; ->this : Symbol(C, Decl(privateNameJsPrototype.js, 7, 1)) +>this : Symbol(C, Decl(privateNameJsPrototype.js, 11, 1)) } } diff --git a/tests/baselines/reference/privateNameJsBadDeclaration.types b/tests/baselines/reference/privateNameJsBadDeclaration.types index 0ccbbeef0a9ba..9799d7e6ad3f0 100644 --- a/tests/baselines/reference/privateNameJsBadDeclaration.types +++ b/tests/baselines/reference/privateNameJsBadDeclaration.types @@ -3,29 +3,43 @@ function A() { } >A : typeof A A.prototype = { ->A.prototype = { #x: 1 // Error} : {} +>A.prototype = { #x: 1, // Error #m() {}, // Error get #p() { return "" } // Error} : {} >A.prototype : {} >A : typeof A >prototype : {} ->{ #x: 1 // Error} : {} +>{ #x: 1, // Error #m() {}, // Error get #p() { return "" } // Error} : {} - #x: 1 // Error + #x: 1, // Error >#x : number >1 : 1 + + #m() {}, // Error +>#m : () => void + + get #p() { return "" } // Error +>#p : string +>"" : "" } class B { } >B : B B.prototype = { ->B.prototype = { #y: 2 // Error} : {} +>B.prototype = { #y: 2, // Error #m() {}, // Error get #p() { return "" } // Error} : {} >B.prototype : B >B : typeof B >prototype : B ->{ #y: 2 // Error} : {} +>{ #y: 2, // Error #m() {}, // Error get #p() { return "" } // Error} : {} - #y: 2 // Error + #y: 2, // Error >#y : number >2 : 2 + + #m() {}, // Error +>#m : () => void + + get #p() { return "" } // Error +>#p : string +>"" : "" } class C { >C : C diff --git a/tests/baselines/reference/privateNameJsx.js b/tests/baselines/reference/privateNameJsx.js index 9b4098f1e196b..6cdf5be703879 100644 --- a/tests/baselines/reference/privateNameJsx.js +++ b/tests/baselines/reference/privateNameJsx.js @@ -9,14 +9,14 @@ class Test { //// [privateNameJsx.jsx] -var _prop; +var _Test_prop; var Test = /** @class */ (function () { function Test() { - _prop.set(this, function () { return
; }); + _Test_prop.set(this, function () { return
; }); } Test.prototype.render = function () { return ; }; return Test; }()); -_prop = new WeakMap(); +_Test_prop = new WeakMap(); diff --git a/tests/baselines/reference/privateNameMethod.errors.txt b/tests/baselines/reference/privateNameMethod.errors.txt new file mode 100644 index 0000000000000..92de4ef3f42cd --- /dev/null +++ b/tests/baselines/reference/privateNameMethod.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts(7,22): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. +tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts(8,14): error TS2554: Expected 1 arguments, but got 0. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts (2 errors) ==== + class A1 { + #method(param: string): string { + return ""; + } + constructor(name: string) { + this.#method("") + this.#method(1) // Error + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. + this.#method() // Error + ~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts:2:13: An argument for 'param' was not provided. + + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameMethod.js b/tests/baselines/reference/privateNameMethod.js new file mode 100644 index 0000000000000..21e6ff9b3cd54 --- /dev/null +++ b/tests/baselines/reference/privateNameMethod.js @@ -0,0 +1,33 @@ +//// [privateNameMethod.ts] +class A1 { + #method(param: string): string { + return ""; + } + constructor(name: string) { + this.#method("") + this.#method(1) // Error + this.#method() // Error + + } +} + + +//// [privateNameMethod.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 _A1_instances, _A1_method; +class A1 { + constructor(name) { + _A1_instances.add(this); + __classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(this, ""); + __classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(this, 1); // Error + __classPrivateFieldGet(this, _A1_instances, "m", _A1_method).call(this); // Error + } +} +_A1_instances = new WeakSet(), _A1_method = function _A1_method(param) { + return ""; +}; diff --git a/tests/baselines/reference/privateNameMethod.symbols b/tests/baselines/reference/privateNameMethod.symbols new file mode 100644 index 0000000000000..724dd0cbddb1e --- /dev/null +++ b/tests/baselines/reference/privateNameMethod.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts === +class A1 { +>A1 : Symbol(A1, Decl(privateNameMethod.ts, 0, 0)) + + #method(param: string): string { +>#method : Symbol(A1.#method, Decl(privateNameMethod.ts, 0, 10)) +>param : Symbol(param, Decl(privateNameMethod.ts, 1, 12)) + + return ""; + } + constructor(name: string) { +>name : Symbol(name, Decl(privateNameMethod.ts, 4, 16)) + + this.#method("") +>this.#method : Symbol(A1.#method, Decl(privateNameMethod.ts, 0, 10)) +>this : Symbol(A1, Decl(privateNameMethod.ts, 0, 0)) + + this.#method(1) // Error +>this.#method : Symbol(A1.#method, Decl(privateNameMethod.ts, 0, 10)) +>this : Symbol(A1, Decl(privateNameMethod.ts, 0, 0)) + + this.#method() // Error +>this.#method : Symbol(A1.#method, Decl(privateNameMethod.ts, 0, 10)) +>this : Symbol(A1, Decl(privateNameMethod.ts, 0, 0)) + + } +} + diff --git a/tests/baselines/reference/privateNameMethod.types b/tests/baselines/reference/privateNameMethod.types new file mode 100644 index 0000000000000..f28e54126790f --- /dev/null +++ b/tests/baselines/reference/privateNameMethod.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts === +class A1 { +>A1 : A1 + + #method(param: string): string { +>#method : (param: string) => string +>param : string + + return ""; +>"" : "" + } + constructor(name: string) { +>name : string + + this.#method("") +>this.#method("") : string +>this.#method : (param: string) => string +>this : this +>"" : "" + + this.#method(1) // Error +>this.#method(1) : string +>this.#method : (param: string) => string +>this : this +>1 : 1 + + this.#method() // Error +>this.#method() : string +>this.#method : (param: string) => string +>this : this + + } +} + diff --git a/tests/baselines/reference/privateNameMethodAccess.errors.txt b/tests/baselines/reference/privateNameMethodAccess.errors.txt new file mode 100644 index 0000000000000..4ee30c160f5ca --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAccess.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts(12,10): error TS18013: Property '#method' is not accessible outside class 'A2' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts(15,14): error TS18013: Property '#method' is not accessible outside class 'A2' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts(20,18): error TS18013: Property '#method' is not accessible outside class 'A2' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts (3 errors) ==== + class A2 { + #method() { return "" } + constructor() { + console.log(this.#method); + let a: A2 = this; + a.#method(); + function foo (){ + a.#method(); + } + } + } + new A2().#method(); // Error + ~~~~~~~ +!!! error TS18013: Property '#method' is not accessible outside class 'A2' because it has a private identifier. + + function foo (){ + new A2().#method(); // Error + ~~~~~~~ +!!! error TS18013: Property '#method' is not accessible outside class 'A2' because it has a private identifier. + } + + class B2 { + m() { + new A2().#method(); + ~~~~~~~ +!!! error TS18013: Property '#method' is not accessible outside class 'A2' because it has a private identifier. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameMethodAccess.js b/tests/baselines/reference/privateNameMethodAccess.js new file mode 100644 index 0000000000000..de9680a242698 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAccess.js @@ -0,0 +1,55 @@ +//// [privateNameMethodAccess.ts] +class A2 { + #method() { return "" } + constructor() { + console.log(this.#method); + let a: A2 = this; + a.#method(); + function foo (){ + a.#method(); + } + } +} +new A2().#method(); // Error + +function foo (){ + new A2().#method(); // Error +} + +class B2 { + m() { + new A2().#method(); + } +} + + +//// [privateNameMethodAccess.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 _A2_instances, _A2_method, _a; +class A2 { + constructor() { + _A2_instances.add(this); + console.log(__classPrivateFieldGet(this, _A2_instances, "m", _A2_method)); + let a = this; + __classPrivateFieldGet(a, _A2_instances, "m", _A2_method).call(a); + function foo() { + __classPrivateFieldGet(a, _A2_instances, "m", _A2_method).call(a); + } + } +} +_A2_instances = new WeakSet(), _A2_method = function _A2_method() { return ""; }; +(_a = new A2())..call(_a); // Error +function foo() { + var _a; + (_a = new A2())..call(_a); // Error +} +class B2 { + m() { + var _a; + (_a = new A2())..call(_a); + } +} diff --git a/tests/baselines/reference/privateNameMethodAccess.symbols b/tests/baselines/reference/privateNameMethodAccess.symbols new file mode 100644 index 0000000000000..7b1517bca05b8 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAccess.symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts === +class A2 { +>A2 : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) + + #method() { return "" } +>#method : Symbol(A2.#method, Decl(privateNameMethodAccess.ts, 0, 10)) + + constructor() { + console.log(this.#method); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#method : Symbol(A2.#method, Decl(privateNameMethodAccess.ts, 0, 10)) +>this : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) + + let a: A2 = this; +>a : Symbol(a, Decl(privateNameMethodAccess.ts, 4, 11)) +>A2 : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) +>this : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) + + a.#method(); +>a.#method : Symbol(A2.#method, Decl(privateNameMethodAccess.ts, 0, 10)) +>a : Symbol(a, Decl(privateNameMethodAccess.ts, 4, 11)) + + function foo (){ +>foo : Symbol(foo, Decl(privateNameMethodAccess.ts, 5, 20)) + + a.#method(); +>a.#method : Symbol(A2.#method, Decl(privateNameMethodAccess.ts, 0, 10)) +>a : Symbol(a, Decl(privateNameMethodAccess.ts, 4, 11)) + } + } +} +new A2().#method(); // Error +>A2 : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) + +function foo (){ +>foo : Symbol(foo, Decl(privateNameMethodAccess.ts, 11, 19)) + + new A2().#method(); // Error +>A2 : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) +} + +class B2 { +>B2 : Symbol(B2, Decl(privateNameMethodAccess.ts, 15, 1)) + + m() { +>m : Symbol(B2.m, Decl(privateNameMethodAccess.ts, 17, 10)) + + new A2().#method(); +>A2 : Symbol(A2, Decl(privateNameMethodAccess.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameMethodAccess.types b/tests/baselines/reference/privateNameMethodAccess.types new file mode 100644 index 0000000000000..9b126fe672c9a --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAccess.types @@ -0,0 +1,66 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts === +class A2 { +>A2 : A2 + + #method() { return "" } +>#method : () => string +>"" : "" + + constructor() { + console.log(this.#method); +>console.log(this.#method) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#method : () => string +>this : this + + let a: A2 = this; +>a : A2 +>this : this + + a.#method(); +>a.#method() : string +>a.#method : () => string +>a : A2 + + function foo (){ +>foo : () => void + + a.#method(); +>a.#method() : string +>a.#method : () => string +>a : A2 + } + } +} +new A2().#method(); // Error +>new A2().#method() : any +>new A2().#method : any +>new A2() : A2 +>A2 : typeof A2 + +function foo (){ +>foo : () => void + + new A2().#method(); // Error +>new A2().#method() : any +>new A2().#method : any +>new A2() : A2 +>A2 : typeof A2 +} + +class B2 { +>B2 : B2 + + m() { +>m : () => void + + new A2().#method(); +>new A2().#method() : any +>new A2().#method : any +>new A2() : A2 +>A2 : typeof A2 + } +} + diff --git a/tests/baselines/reference/privateNameMethodAssignment.errors.txt b/tests/baselines/reference/privateNameMethodAssignment.errors.txt new file mode 100644 index 0000000000000..41dc9f85464c2 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAssignment.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts(4,14): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts(5,11): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts(6,11): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts(7,20): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts(9,11): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts (5 errors) ==== + class A3 { + #method() { }; + constructor(a: A3, b: any) { + this.#method = () => {} // Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + a.#method = () => { }; // Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + b.#method = () => { } //Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + ({ x: this.#method } = { x: () => {}}); //Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + let x = this.#method; + b.#method++ //Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameMethodAssignment.js b/tests/baselines/reference/privateNameMethodAssignment.js new file mode 100644 index 0000000000000..c33e3406f9d9b --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAssignment.js @@ -0,0 +1,41 @@ +//// [privateNameMethodAssignment.ts] +class A3 { + #method() { }; + constructor(a: A3, b: any) { + this.#method = () => {} // Error, not writable + a.#method = () => { }; // Error, not writable + b.#method = () => { } //Error, not writable + ({ x: this.#method } = { x: () => {}}); //Error, not writable + let x = this.#method; + b.#method++ //Error, not writable + } +} + + +//// [privateNameMethodAssignment.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _A3_instances, _A3_method; +class A3 { + constructor(a, b) { + var _a, _b; + _A3_instances.add(this); + __classPrivateFieldSet(this, _A3_instances, () => { }, "m"); // Error, not writable + __classPrivateFieldSet(a, _A3_instances, () => { }, "m"); // Error, not writable + __classPrivateFieldSet(b, _A3_instances, () => { }, "m"); //Error, not writable + (_a = this, { x: ({ set value(_b) { __classPrivateFieldSet(_a, _A3_instances, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable + let x = __classPrivateFieldGet(this, _A3_instances, "m", _A3_method); + __classPrivateFieldSet(_b = b, _A3_instances, +__classPrivateFieldGet(_b, _A3_instances, "m", _A3_method) + 1, "m"); //Error, not writable + } + ; +} +_A3_instances = new WeakSet(), _A3_method = function _A3_method() { }; diff --git a/tests/baselines/reference/privateNameMethodAssignment.symbols b/tests/baselines/reference/privateNameMethodAssignment.symbols new file mode 100644 index 0000000000000..01a6b8c40877f --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAssignment.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts === +class A3 { +>A3 : Symbol(A3, Decl(privateNameMethodAssignment.ts, 0, 0)) + + #method() { }; +>#method : Symbol(A3.#method, Decl(privateNameMethodAssignment.ts, 0, 10)) + + constructor(a: A3, b: any) { +>a : Symbol(a, Decl(privateNameMethodAssignment.ts, 2, 16)) +>A3 : Symbol(A3, Decl(privateNameMethodAssignment.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameMethodAssignment.ts, 2, 22)) + + this.#method = () => {} // Error, not writable +>this.#method : Symbol(A3.#method, Decl(privateNameMethodAssignment.ts, 0, 10)) +>this : Symbol(A3, Decl(privateNameMethodAssignment.ts, 0, 0)) + + a.#method = () => { }; // Error, not writable +>a.#method : Symbol(A3.#method, Decl(privateNameMethodAssignment.ts, 0, 10)) +>a : Symbol(a, Decl(privateNameMethodAssignment.ts, 2, 16)) + + b.#method = () => { } //Error, not writable +>b : Symbol(b, Decl(privateNameMethodAssignment.ts, 2, 22)) + + ({ x: this.#method } = { x: () => {}}); //Error, not writable +>x : Symbol(x, Decl(privateNameMethodAssignment.ts, 6, 10)) +>this.#method : Symbol(A3.#method, Decl(privateNameMethodAssignment.ts, 0, 10)) +>this : Symbol(A3, Decl(privateNameMethodAssignment.ts, 0, 0)) +>x : Symbol(x, Decl(privateNameMethodAssignment.ts, 6, 32)) + + let x = this.#method; +>x : Symbol(x, Decl(privateNameMethodAssignment.ts, 7, 11)) +>this.#method : Symbol(A3.#method, Decl(privateNameMethodAssignment.ts, 0, 10)) +>this : Symbol(A3, Decl(privateNameMethodAssignment.ts, 0, 0)) + + b.#method++ //Error, not writable +>b : Symbol(b, Decl(privateNameMethodAssignment.ts, 2, 22)) + } +} + diff --git a/tests/baselines/reference/privateNameMethodAssignment.types b/tests/baselines/reference/privateNameMethodAssignment.types new file mode 100644 index 0000000000000..963ba0c718650 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAssignment.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts === +class A3 { +>A3 : A3 + + #method() { }; +>#method : () => void + + constructor(a: A3, b: any) { +>a : A3 +>b : any + + this.#method = () => {} // Error, not writable +>this.#method = () => {} : () => void +>this.#method : () => void +>this : this +>() => {} : () => void + + a.#method = () => { }; // Error, not writable +>a.#method = () => { } : () => void +>a.#method : () => void +>a : A3 +>() => { } : () => void + + b.#method = () => { } //Error, not writable +>b.#method = () => { } : () => void +>b.#method : any +>b : any +>() => { } : () => void + + ({ x: this.#method } = { x: () => {}}); //Error, not writable +>({ x: this.#method } = { x: () => {}}) : { x: () => void; } +>{ x: this.#method } = { x: () => {}} : { x: () => void; } +>{ x: this.#method } : { x: () => void; } +>x : () => void +>this.#method : () => void +>this : this +>{ x: () => {}} : { x: () => void; } +>x : () => void +>() => {} : () => void + + let x = this.#method; +>x : () => void +>this.#method : () => void +>this : this + + b.#method++ //Error, not writable +>b.#method++ : number +>b.#method : any +>b : any + } +} + diff --git a/tests/baselines/reference/privateNameMethodAsync.js b/tests/baselines/reference/privateNameMethodAsync.js new file mode 100644 index 0000000000000..71c5cef304ef1 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAsync.js @@ -0,0 +1,40 @@ +//// [privateNameMethodAsync.ts] +const C = class { + async #bar() { return await Promise.resolve(42); } + async foo() { + const b = await this.#bar(); + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); + } + *#baz() { yield 42; } + async *#qux() { + yield (await Promise.resolve(42)); + } +} + +new C().foo().then(console.log); + + +//// [privateNameMethodAsync.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _C_instances, _C_bar, _C_baz, _C_qux, _a; +const C = (_a = class { + constructor() { + _C_instances.add(this); + } + async foo() { + const b = await __classPrivateFieldGet(this, _C_instances, "m", _C_bar).call(this); + return b + (__classPrivateFieldGet(this, _C_instances, "m", _C_baz).call(this).next().value || 0) + ((await __classPrivateFieldGet(this, _C_instances, "m", _C_qux).call(this).next()).value || 0); + } + }, + _C_instances = new WeakSet(), + _C_bar = async function _C_bar() { return await Promise.resolve(42); }, + _C_baz = function* _C_baz() { yield 42; }, + _C_qux = async function* _C_qux() { + yield (await Promise.resolve(42)); + }, + _a); +new C().foo().then(console.log); diff --git a/tests/baselines/reference/privateNameMethodAsync.symbols b/tests/baselines/reference/privateNameMethodAsync.symbols new file mode 100644 index 0000000000000..f3c70cb19eda7 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAsync.symbols @@ -0,0 +1,56 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodAsync.ts === +const C = class { +>C : Symbol(C, Decl(privateNameMethodAsync.ts, 0, 5)) + + async #bar() { return await Promise.resolve(42); } +>#bar : Symbol(C.#bar, Decl(privateNameMethodAsync.ts, 0, 17)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + + async foo() { +>foo : Symbol(C.foo, Decl(privateNameMethodAsync.ts, 1, 54)) + + const b = await this.#bar(); +>b : Symbol(b, Decl(privateNameMethodAsync.ts, 3, 13)) +>this.#bar : Symbol(C.#bar, Decl(privateNameMethodAsync.ts, 0, 17)) +>this : Symbol(C, Decl(privateNameMethodAsync.ts, 0, 9)) + + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); +>b : Symbol(b, Decl(privateNameMethodAsync.ts, 3, 13)) +>this.#baz().next().value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>this.#baz().next : Symbol(Generator.next, Decl(lib.es2015.generator.d.ts, --, --)) +>this.#baz : Symbol(C.#baz, Decl(privateNameMethodAsync.ts, 5, 5)) +>this : Symbol(C, Decl(privateNameMethodAsync.ts, 0, 9)) +>next : Symbol(Generator.next, Decl(lib.es2015.generator.d.ts, --, --)) +>value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>(await this.#qux().next()).value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>this.#qux().next : Symbol(AsyncGenerator.next, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) +>this.#qux : Symbol(C.#qux, Decl(privateNameMethodAsync.ts, 6, 25)) +>this : Symbol(C, Decl(privateNameMethodAsync.ts, 0, 9)) +>next : Symbol(AsyncGenerator.next, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) +>value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + } + *#baz() { yield 42; } +>#baz : Symbol(C.#baz, Decl(privateNameMethodAsync.ts, 5, 5)) + + async *#qux() { +>#qux : Symbol(C.#qux, Decl(privateNameMethodAsync.ts, 6, 25)) + + yield (await Promise.resolve(42)); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + } +} + +new C().foo().then(console.log); +>new C().foo().then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>new C().foo : Symbol(C.foo, Decl(privateNameMethodAsync.ts, 1, 54)) +>C : Symbol(C, Decl(privateNameMethodAsync.ts, 0, 5)) +>foo : Symbol(C.foo, Decl(privateNameMethodAsync.ts, 1, 54)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + diff --git a/tests/baselines/reference/privateNameMethodAsync.types b/tests/baselines/reference/privateNameMethodAsync.types new file mode 100644 index 0000000000000..3ac547af0404c --- /dev/null +++ b/tests/baselines/reference/privateNameMethodAsync.types @@ -0,0 +1,86 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodAsync.ts === +const C = class { +>C : typeof C +>class { async #bar() { return await Promise.resolve(42); } async foo() { const b = await this.#bar(); return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); } *#baz() { yield 42; } async *#qux() { yield (await Promise.resolve(42)); }} : typeof C + + async #bar() { return await Promise.resolve(42); } +>#bar : () => Promise +>await Promise.resolve(42) : number +>Promise.resolve(42) : Promise +>Promise.resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>Promise : PromiseConstructor +>resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>42 : 42 + + async foo() { +>foo : () => Promise + + const b = await this.#bar(); +>b : number +>await this.#bar() : number +>this.#bar() : Promise +>this.#bar : () => Promise +>this : this + + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); +>b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0) : number +>b + (this.#baz().next().value || 0) : number +>b : number +>(this.#baz().next().value || 0) : number +>this.#baz().next().value || 0 : number +>this.#baz().next().value : number | void +>this.#baz().next() : IteratorResult +>this.#baz().next : (...args: [] | [unknown]) => IteratorResult +>this.#baz() : Generator +>this.#baz : () => Generator +>this : this +>next : (...args: [] | [unknown]) => IteratorResult +>value : number | void +>0 : 0 +>((await this.#qux().next()).value || 0) : number +>(await this.#qux().next()).value || 0 : number +>(await this.#qux().next()).value : number | void +>(await this.#qux().next()) : IteratorResult +>await this.#qux().next() : IteratorResult +>this.#qux().next() : Promise> +>this.#qux().next : (...args: [] | [unknown]) => Promise> +>this.#qux() : AsyncGenerator +>this.#qux : () => AsyncGenerator +>this : this +>next : (...args: [] | [unknown]) => Promise> +>value : number | void +>0 : 0 + } + *#baz() { yield 42; } +>#baz : () => Generator +>yield 42 : any +>42 : 42 + + async *#qux() { +>#qux : () => AsyncGenerator + + yield (await Promise.resolve(42)); +>yield (await Promise.resolve(42)) : any +>(await Promise.resolve(42)) : number +>await Promise.resolve(42) : number +>Promise.resolve(42) : Promise +>Promise.resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>Promise : PromiseConstructor +>resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>42 : 42 + } +} + +new C().foo().then(console.log); +>new C().foo().then(console.log) : Promise +>new C().foo().then : (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>new C().foo() : Promise +>new C().foo : () => Promise +>new C() : C +>C : typeof C +>foo : () => Promise +>then : (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void + diff --git a/tests/baselines/reference/privateNameMethodCallExpression.js b/tests/baselines/reference/privateNameMethodCallExpression.js new file mode 100644 index 0000000000000..caa5c421fc548 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodCallExpression.js @@ -0,0 +1,58 @@ +//// [privateNameMethodCallExpression.ts] +class AA { + #method() { this.x = 10; }; + #method2(a, ...b) {}; + x = 1; + test() { + this.#method(); + const func = this.#method; + func(); + new this.#method(); + + const arr = [ 1, 2 ]; + this.#method2(0, ...arr, 3); + + const b = new this.#method2(0, ...arr, 3); //Error + const str = this.#method2`head${1}middle${2}tail`; + this.getInstance().#method2`test${1}and${2}`; + + this.getInstance().#method2(0, ...arr, 3); + const b2 = new (this.getInstance().#method2)(0, ...arr, 3); //Error + const str2 = this.getInstance().#method2`head${1}middle${2}tail`; + } + getInstance() { return new AA(); } +} + + +//// [privateNameMethodCallExpression.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 _AA_instances, _AA_method, _AA_method2; +class AA { + constructor() { + _AA_instances.add(this); + this.x = 1; + } + ; + ; + test() { + var _a, _b, _c; + __classPrivateFieldGet(this, _AA_instances, "m", _AA_method).call(this); + const func = __classPrivateFieldGet(this, _AA_instances, "m", _AA_method); + func(); + new (__classPrivateFieldGet(this, _AA_instances, "m", _AA_method))(); + const arr = [1, 2]; + __classPrivateFieldGet(this, _AA_instances, "m", _AA_method2).call(this, 0, ...arr, 3); + const b = new (__classPrivateFieldGet(this, _AA_instances, "m", _AA_method2))(0, ...arr, 3); //Error + const str = __classPrivateFieldGet(this, _AA_instances, "m", _AA_method2).bind(this) `head${1}middle${2}tail`; + __classPrivateFieldGet((_a = this.getInstance()), _AA_instances, "m", _AA_method2).bind(_a) `test${1}and${2}`; + __classPrivateFieldGet((_b = this.getInstance()), _AA_instances, "m", _AA_method2).call(_b, 0, ...arr, 3); + const b2 = new (__classPrivateFieldGet(this.getInstance(), _AA_instances, "m", _AA_method2))(0, ...arr, 3); //Error + const str2 = __classPrivateFieldGet((_c = this.getInstance()), _AA_instances, "m", _AA_method2).bind(_c) `head${1}middle${2}tail`; + } + getInstance() { return new AA(); } +} +_AA_instances = new WeakSet(), _AA_method = function _AA_method() { this.x = 10; }, _AA_method2 = function _AA_method2(a, ...b) { }; diff --git a/tests/baselines/reference/privateNameMethodCallExpression.symbols b/tests/baselines/reference/privateNameMethodCallExpression.symbols new file mode 100644 index 0000000000000..668953b9b546e --- /dev/null +++ b/tests/baselines/reference/privateNameMethodCallExpression.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodCallExpression.ts === +class AA { +>AA : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) + + #method() { this.x = 10; }; +>#method : Symbol(AA.#method, Decl(privateNameMethodCallExpression.ts, 0, 10)) +>this.x : Symbol(AA.x, Decl(privateNameMethodCallExpression.ts, 2, 25)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>x : Symbol(AA.x, Decl(privateNameMethodCallExpression.ts, 2, 25)) + + #method2(a, ...b) {}; +>#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>a : Symbol(a, Decl(privateNameMethodCallExpression.ts, 2, 13)) +>b : Symbol(b, Decl(privateNameMethodCallExpression.ts, 2, 15)) + + x = 1; +>x : Symbol(AA.x, Decl(privateNameMethodCallExpression.ts, 2, 25)) + + test() { +>test : Symbol(AA.test, Decl(privateNameMethodCallExpression.ts, 3, 10)) + + this.#method(); +>this.#method : Symbol(AA.#method, Decl(privateNameMethodCallExpression.ts, 0, 10)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) + + const func = this.#method; +>func : Symbol(func, Decl(privateNameMethodCallExpression.ts, 6, 13)) +>this.#method : Symbol(AA.#method, Decl(privateNameMethodCallExpression.ts, 0, 10)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) + + func(); +>func : Symbol(func, Decl(privateNameMethodCallExpression.ts, 6, 13)) + + new this.#method(); +>this.#method : Symbol(AA.#method, Decl(privateNameMethodCallExpression.ts, 0, 10)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) + + const arr = [ 1, 2 ]; +>arr : Symbol(arr, Decl(privateNameMethodCallExpression.ts, 10, 13)) + + this.#method2(0, ...arr, 3); +>this.#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameMethodCallExpression.ts, 10, 13)) + + const b = new this.#method2(0, ...arr, 3); //Error +>b : Symbol(b, Decl(privateNameMethodCallExpression.ts, 13, 13)) +>this.#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameMethodCallExpression.ts, 10, 13)) + + const str = this.#method2`head${1}middle${2}tail`; +>str : Symbol(str, Decl(privateNameMethodCallExpression.ts, 14, 13)) +>this.#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) + + this.getInstance().#method2`test${1}and${2}`; +>this.getInstance().#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this.getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) + + this.getInstance().#method2(0, ...arr, 3); +>this.getInstance().#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this.getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>arr : Symbol(arr, Decl(privateNameMethodCallExpression.ts, 10, 13)) + + const b2 = new (this.getInstance().#method2)(0, ...arr, 3); //Error +>b2 : Symbol(b2, Decl(privateNameMethodCallExpression.ts, 18, 13)) +>this.getInstance().#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this.getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>arr : Symbol(arr, Decl(privateNameMethodCallExpression.ts, 10, 13)) + + const str2 = this.getInstance().#method2`head${1}middle${2}tail`; +>str2 : Symbol(str2, Decl(privateNameMethodCallExpression.ts, 19, 13)) +>this.getInstance().#method2 : Symbol(AA.#method2, Decl(privateNameMethodCallExpression.ts, 1, 31)) +>this.getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>this : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +>getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) + } + getInstance() { return new AA(); } +>getInstance : Symbol(AA.getInstance, Decl(privateNameMethodCallExpression.ts, 20, 5)) +>AA : Symbol(AA, Decl(privateNameMethodCallExpression.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/privateNameMethodCallExpression.types b/tests/baselines/reference/privateNameMethodCallExpression.types new file mode 100644 index 0000000000000..6937a06a63edd --- /dev/null +++ b/tests/baselines/reference/privateNameMethodCallExpression.types @@ -0,0 +1,132 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodCallExpression.ts === +class AA { +>AA : AA + + #method() { this.x = 10; }; +>#method : () => void +>this.x = 10 : 10 +>this.x : number +>this : this +>x : number +>10 : 10 + + #method2(a, ...b) {}; +>#method2 : (a: any, ...b: any[]) => void +>a : any +>b : any[] + + x = 1; +>x : number +>1 : 1 + + test() { +>test : () => void + + this.#method(); +>this.#method() : void +>this.#method : () => void +>this : this + + const func = this.#method; +>func : () => void +>this.#method : () => void +>this : this + + func(); +>func() : void +>func : () => void + + new this.#method(); +>new this.#method() : any +>this.#method : () => void +>this : this + + const arr = [ 1, 2 ]; +>arr : number[] +>[ 1, 2 ] : number[] +>1 : 1 +>2 : 2 + + this.#method2(0, ...arr, 3); +>this.#method2(0, ...arr, 3) : void +>this.#method2 : (a: any, ...b: any[]) => void +>this : this +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b = new this.#method2(0, ...arr, 3); //Error +>b : any +>new this.#method2(0, ...arr, 3) : any +>this.#method2 : (a: any, ...b: any[]) => void +>this : this +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str = this.#method2`head${1}middle${2}tail`; +>str : void +>this.#method2`head${1}middle${2}tail` : void +>this.#method2 : (a: any, ...b: any[]) => void +>this : this +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + + this.getInstance().#method2`test${1}and${2}`; +>this.getInstance().#method2`test${1}and${2}` : void +>this.getInstance().#method2 : (a: any, ...b: any[]) => void +>this.getInstance() : AA +>this.getInstance : () => AA +>this : this +>getInstance : () => AA +>`test${1}and${2}` : string +>1 : 1 +>2 : 2 + + this.getInstance().#method2(0, ...arr, 3); +>this.getInstance().#method2(0, ...arr, 3) : void +>this.getInstance().#method2 : (a: any, ...b: any[]) => void +>this.getInstance() : AA +>this.getInstance : () => AA +>this : this +>getInstance : () => AA +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b2 = new (this.getInstance().#method2)(0, ...arr, 3); //Error +>b2 : any +>new (this.getInstance().#method2)(0, ...arr, 3) : any +>(this.getInstance().#method2) : (a: any, ...b: any[]) => void +>this.getInstance().#method2 : (a: any, ...b: any[]) => void +>this.getInstance() : AA +>this.getInstance : () => AA +>this : this +>getInstance : () => AA +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str2 = this.getInstance().#method2`head${1}middle${2}tail`; +>str2 : void +>this.getInstance().#method2`head${1}middle${2}tail` : void +>this.getInstance().#method2 : (a: any, ...b: any[]) => void +>this.getInstance() : AA +>this.getInstance : () => AA +>this : this +>getInstance : () => AA +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + } + getInstance() { return new AA(); } +>getInstance : () => AA +>new AA() : AA +>AA : typeof AA +} + diff --git a/tests/baselines/reference/privateNameMethodClassExpression.errors.txt b/tests/baselines/reference/privateNameMethodClassExpression.errors.txt new file mode 100644 index 0000000000000..2b44629ccabbf --- /dev/null +++ b/tests/baselines/reference/privateNameMethodClassExpression.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class '(anonymous)' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class '(anonymous)' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts (2 errors) ==== + const C = class { + #field = this.#method(); + #method() { return 42; } + static getInstance() { return new C(); } + getField() { return this.#field }; + } + + console.log(C.getInstance().getField()); + C.getInstance().#method; // Error + ~~~~~~~ +!!! error TS18013: Property '#method' is not accessible outside class '(anonymous)' because it has a private identifier. + C.getInstance().#field; // Error + ~~~~~~ +!!! error TS18013: Property '#field' is not accessible outside class '(anonymous)' because it has a private identifier. + + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameMethodClassExpression.js b/tests/baselines/reference/privateNameMethodClassExpression.js new file mode 100644 index 0000000000000..85523a2af7e2d --- /dev/null +++ b/tests/baselines/reference/privateNameMethodClassExpression.js @@ -0,0 +1,37 @@ +//// [privateNameMethodClassExpression.ts] +const C = class { + #field = this.#method(); + #method() { return 42; } + static getInstance() { return new C(); } + getField() { return this.#field }; +} + +console.log(C.getInstance().getField()); +C.getInstance().#method; // Error +C.getInstance().#field; // Error + + + +//// [privateNameMethodClassExpression.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _C_instances, _C_field, _C_method, _a; +const C = (_a = class { + constructor() { + _C_instances.add(this); + _C_field.set(this, __classPrivateFieldGet(this, _C_instances, "m", _C_method).call(this)); + } + static getInstance() { return new C(); } + getField() { return __classPrivateFieldGet(this, _C_field, "f"); } + ; + }, + _C_field = new WeakMap(), + _C_instances = new WeakSet(), + _C_method = function _C_method() { return 42; }, + _a); +console.log(C.getInstance().getField()); +C.getInstance().; // Error +C.getInstance().; // Error diff --git a/tests/baselines/reference/privateNameMethodClassExpression.symbols b/tests/baselines/reference/privateNameMethodClassExpression.symbols new file mode 100644 index 0000000000000..b24d490bdebbb --- /dev/null +++ b/tests/baselines/reference/privateNameMethodClassExpression.symbols @@ -0,0 +1,43 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts === +const C = class { +>C : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 5)) + + #field = this.#method(); +>#field : Symbol(C.#field, Decl(privateNameMethodClassExpression.ts, 0, 17)) +>this.#method : Symbol(C.#method, Decl(privateNameMethodClassExpression.ts, 1, 28)) +>this : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 9)) + + #method() { return 42; } +>#method : Symbol(C.#method, Decl(privateNameMethodClassExpression.ts, 1, 28)) + + static getInstance() { return new C(); } +>getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) +>C : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 5)) + + getField() { return this.#field }; +>getField : Symbol(C.getField, Decl(privateNameMethodClassExpression.ts, 3, 44)) +>this.#field : Symbol(C.#field, Decl(privateNameMethodClassExpression.ts, 0, 17)) +>this : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 9)) +} + +console.log(C.getInstance().getField()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.getInstance().getField : Symbol(C.getField, Decl(privateNameMethodClassExpression.ts, 3, 44)) +>C.getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) +>C : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 5)) +>getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) +>getField : Symbol(C.getField, Decl(privateNameMethodClassExpression.ts, 3, 44)) + +C.getInstance().#method; // Error +>C.getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) +>C : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 5)) +>getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) + +C.getInstance().#field; // Error +>C.getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) +>C : Symbol(C, Decl(privateNameMethodClassExpression.ts, 0, 5)) +>getInstance : Symbol(C.getInstance, Decl(privateNameMethodClassExpression.ts, 2, 28)) + + diff --git a/tests/baselines/reference/privateNameMethodClassExpression.types b/tests/baselines/reference/privateNameMethodClassExpression.types new file mode 100644 index 0000000000000..4800eefe52279 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodClassExpression.types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts === +const C = class { +>C : typeof C +>class { #field = this.#method(); #method() { return 42; } static getInstance() { return new C(); } getField() { return this.#field };} : typeof C + + #field = this.#method(); +>#field : number +>this.#method() : number +>this.#method : () => number +>this : this + + #method() { return 42; } +>#method : () => number +>42 : 42 + + static getInstance() { return new C(); } +>getInstance : () => C +>new C() : C +>C : typeof C + + getField() { return this.#field }; +>getField : () => number +>this.#field : number +>this : this +} + +console.log(C.getInstance().getField()); +>console.log(C.getInstance().getField()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.getInstance().getField() : number +>C.getInstance().getField : () => number +>C.getInstance() : C +>C.getInstance : () => C +>C : typeof C +>getInstance : () => C +>getField : () => number + +C.getInstance().#method; // Error +>C.getInstance().#method : any +>C.getInstance() : C +>C.getInstance : () => C +>C : typeof C +>getInstance : () => C + +C.getInstance().#field; // Error +>C.getInstance().#field : any +>C.getInstance() : C +>C.getInstance : () => C +>C : typeof C +>getInstance : () => C + + diff --git a/tests/baselines/reference/privateNameMethodInStaticFieldInit.js b/tests/baselines/reference/privateNameMethodInStaticFieldInit.js new file mode 100644 index 0000000000000..199c1c17e0114 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodInStaticFieldInit.js @@ -0,0 +1,24 @@ +//// [privateNameMethodInStaticFieldInit.ts] +class C { + static s = new C().#method(); + #method() { return 42; } +} + +console.log(C.s); + + +//// [privateNameMethodInStaticFieldInit.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _C_instances, _C_method, _a; +class C { + constructor() { + _C_instances.add(this); + } +} +_C_instances = new WeakSet(), _C_method = function _C_method() { return 42; }; +C.s = __classPrivateFieldGet((_a = new C()), _C_instances, "m", _C_method).call(_a); +console.log(C.s); diff --git a/tests/baselines/reference/privateNameMethodInStaticFieldInit.symbols b/tests/baselines/reference/privateNameMethodInStaticFieldInit.symbols new file mode 100644 index 0000000000000..ad742e35da81c --- /dev/null +++ b/tests/baselines/reference/privateNameMethodInStaticFieldInit.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodInStaticFieldInit.ts === +class C { +>C : Symbol(C, Decl(privateNameMethodInStaticFieldInit.ts, 0, 0)) + + static s = new C().#method(); +>s : Symbol(C.s, Decl(privateNameMethodInStaticFieldInit.ts, 0, 9)) +>new C().#method : Symbol(C.#method, Decl(privateNameMethodInStaticFieldInit.ts, 1, 33)) +>C : Symbol(C, Decl(privateNameMethodInStaticFieldInit.ts, 0, 0)) + + #method() { return 42; } +>#method : Symbol(C.#method, Decl(privateNameMethodInStaticFieldInit.ts, 1, 33)) +} + +console.log(C.s); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.s : Symbol(C.s, Decl(privateNameMethodInStaticFieldInit.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameMethodInStaticFieldInit.ts, 0, 0)) +>s : Symbol(C.s, Decl(privateNameMethodInStaticFieldInit.ts, 0, 9)) + diff --git a/tests/baselines/reference/privateNameMethodInStaticFieldInit.types b/tests/baselines/reference/privateNameMethodInStaticFieldInit.types new file mode 100644 index 0000000000000..7319a1f3082a0 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodInStaticFieldInit.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodInStaticFieldInit.ts === +class C { +>C : C + + static s = new C().#method(); +>s : number +>new C().#method() : number +>new C().#method : () => number +>new C() : C +>C : typeof C + + #method() { return 42; } +>#method : () => number +>42 : 42 +} + +console.log(C.s); +>console.log(C.s) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.s : number +>C : typeof C +>s : number + diff --git a/tests/baselines/reference/privateNameMethodsDerivedClasses.errors.txt b/tests/baselines/reference/privateNameMethodsDerivedClasses.errors.txt new file mode 100644 index 0000000000000..62989cb6613a6 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodsDerivedClasses.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts(9,23): error TS18013: Property '#prop' is not accessible outside class 'Base' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts (1 errors) ==== + class Base { + #prop(): number{ return 123; } + static method(x: Derived) { + console.log(x.#prop()); + } + } + class Derived extends Base { + static method(x: Derived) { + console.log(x.#prop()); + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'Base' because it has a private identifier. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameMethodsDerivedClasses.js b/tests/baselines/reference/privateNameMethodsDerivedClasses.js new file mode 100644 index 0000000000000..b6b4027e749b1 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodsDerivedClasses.js @@ -0,0 +1,35 @@ +//// [privateNameMethodsDerivedClasses.ts] +class Base { + #prop(): number{ return 123; } + static method(x: Derived) { + console.log(x.#prop()); + } +} +class Derived extends Base { + static method(x: Derived) { + console.log(x.#prop()); + } +} + + +//// [privateNameMethodsDerivedClasses.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 _Base_instances, _Base_prop; +class Base { + constructor() { + _Base_instances.add(this); + } + static method(x) { + console.log(__classPrivateFieldGet(x, _Base_instances, "m", _Base_prop).call(x)); + } +} +_Base_instances = new WeakSet(), _Base_prop = function _Base_prop() { return 123; }; +class Derived extends Base { + static method(x) { + console.log(x..call(x)); + } +} diff --git a/tests/baselines/reference/privateNameMethodsDerivedClasses.symbols b/tests/baselines/reference/privateNameMethodsDerivedClasses.symbols new file mode 100644 index 0000000000000..472eef820a4ca --- /dev/null +++ b/tests/baselines/reference/privateNameMethodsDerivedClasses.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts === +class Base { +>Base : Symbol(Base, Decl(privateNameMethodsDerivedClasses.ts, 0, 0)) + + #prop(): number{ return 123; } +>#prop : Symbol(Base.#prop, Decl(privateNameMethodsDerivedClasses.ts, 0, 12)) + + static method(x: Derived) { +>method : Symbol(Base.method, Decl(privateNameMethodsDerivedClasses.ts, 1, 35)) +>x : Symbol(x, Decl(privateNameMethodsDerivedClasses.ts, 2, 18)) +>Derived : Symbol(Derived, Decl(privateNameMethodsDerivedClasses.ts, 5, 1)) + + console.log(x.#prop()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x.#prop : Symbol(Base.#prop, Decl(privateNameMethodsDerivedClasses.ts, 0, 12)) +>x : Symbol(x, Decl(privateNameMethodsDerivedClasses.ts, 2, 18)) + } +} +class Derived extends Base { +>Derived : Symbol(Derived, Decl(privateNameMethodsDerivedClasses.ts, 5, 1)) +>Base : Symbol(Base, Decl(privateNameMethodsDerivedClasses.ts, 0, 0)) + + static method(x: Derived) { +>method : Symbol(Derived.method, Decl(privateNameMethodsDerivedClasses.ts, 6, 28)) +>x : Symbol(x, Decl(privateNameMethodsDerivedClasses.ts, 7, 18)) +>Derived : Symbol(Derived, Decl(privateNameMethodsDerivedClasses.ts, 5, 1)) + + console.log(x.#prop()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameMethodsDerivedClasses.ts, 7, 18)) + } +} + diff --git a/tests/baselines/reference/privateNameMethodsDerivedClasses.types b/tests/baselines/reference/privateNameMethodsDerivedClasses.types new file mode 100644 index 0000000000000..9215984b7b023 --- /dev/null +++ b/tests/baselines/reference/privateNameMethodsDerivedClasses.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts === +class Base { +>Base : Base + + #prop(): number{ return 123; } +>#prop : () => number +>123 : 123 + + static method(x: Derived) { +>method : (x: Derived) => void +>x : Derived + + console.log(x.#prop()); +>console.log(x.#prop()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#prop() : number +>x.#prop : () => number +>x : Derived + } +} +class Derived extends Base { +>Derived : Derived +>Base : Base + + static method(x: Derived) { +>method : (x: Derived) => void +>x : Derived + + console.log(x.#prop()); +>console.log(x.#prop()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#prop() : any +>x.#prop : any +>x : Derived + } +} + diff --git a/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.errors.txt b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.errors.txt new file mode 100644 index 0000000000000..7fb1cf6151750 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts(7,31): error TS18014: The property '#x' cannot be accessed on type 'Base' within this class because it is shadowed by another private identifier with the same spelling. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts (1 errors) ==== + class Base { + get #x() { return 1; }; + constructor() { + class Derived { + get #x() { return 1; }; + testBase(x: Base) { + console.log(x.#x); + ~~ +!!! error TS18014: The property '#x' cannot be accessed on type 'Base' within this class because it is shadowed by another private identifier with the same spelling. +!!! related TS18017 tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts:5:17: The shadowing declaration of '#x' is defined here +!!! related TS18018 tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts:2:9: The declaration of '#x' that you probably intended to use is defined here + } + testDerived(x: Derived) { + console.log(x.#x); + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js new file mode 100644 index 0000000000000..05e47e8bc5337 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.js @@ -0,0 +1,45 @@ +//// [privateNameNestedClassAccessorsShadowing.ts] +class Base { + get #x() { return 1; }; + constructor() { + class Derived { + get #x() { return 1; }; + testBase(x: Base) { + console.log(x.#x); + } + testDerived(x: Derived) { + console.log(x.#x); + } + } + } +} + + +//// [privateNameNestedClassAccessorsShadowing.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 _Base_instances, _Base_x_get; +class Base { + constructor() { + var _Derived_instances, _Derived_x_get; + _Base_instances.add(this); + class Derived { + constructor() { + _Derived_instances.add(this); + } + ; + testBase(x) { + console.log(__classPrivateFieldGet(x, _Derived_instances, "a", _Derived_x_get)); + } + testDerived(x) { + console.log(__classPrivateFieldGet(x, _Derived_instances, "a", _Derived_x_get)); + } + } + _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/privateNameNestedClassAccessorsShadowing.symbols b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.symbols new file mode 100644 index 0000000000000..383c956598441 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts === +class Base { +>Base : Symbol(Base, Decl(privateNameNestedClassAccessorsShadowing.ts, 0, 0)) + + get #x() { return 1; }; +>#x : Symbol(Base.#x, Decl(privateNameNestedClassAccessorsShadowing.ts, 0, 12)) + + constructor() { + class Derived { +>Derived : Symbol(Derived, Decl(privateNameNestedClassAccessorsShadowing.ts, 2, 19)) + + get #x() { return 1; }; +>#x : Symbol(Derived.#x, Decl(privateNameNestedClassAccessorsShadowing.ts, 3, 23)) + + testBase(x: Base) { +>testBase : Symbol(Derived.testBase, Decl(privateNameNestedClassAccessorsShadowing.ts, 4, 35)) +>x : Symbol(x, Decl(privateNameNestedClassAccessorsShadowing.ts, 5, 21)) +>Base : Symbol(Base, Decl(privateNameNestedClassAccessorsShadowing.ts, 0, 0)) + + console.log(x.#x); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameNestedClassAccessorsShadowing.ts, 5, 21)) + } + testDerived(x: Derived) { +>testDerived : Symbol(Derived.testDerived, Decl(privateNameNestedClassAccessorsShadowing.ts, 7, 13)) +>x : Symbol(x, Decl(privateNameNestedClassAccessorsShadowing.ts, 8, 24)) +>Derived : Symbol(Derived, Decl(privateNameNestedClassAccessorsShadowing.ts, 2, 19)) + + console.log(x.#x); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x.#x : Symbol(Derived.#x, Decl(privateNameNestedClassAccessorsShadowing.ts, 3, 23)) +>x : Symbol(x, Decl(privateNameNestedClassAccessorsShadowing.ts, 8, 24)) + } + } + } +} + diff --git a/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.types b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.types new file mode 100644 index 0000000000000..fb2ad9d941439 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassAccessorsShadowing.types @@ -0,0 +1,44 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts === +class Base { +>Base : Base + + get #x() { return 1; }; +>#x : number +>1 : 1 + + constructor() { + class Derived { +>Derived : Derived + + get #x() { return 1; }; +>#x : number +>1 : 1 + + testBase(x: Base) { +>testBase : (x: Base) => void +>x : Base + + console.log(x.#x); +>console.log(x.#x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#x : any +>x : Base + } + testDerived(x: Derived) { +>testDerived : (x: Derived) => void +>x : Derived + + console.log(x.#x); +>console.log(x.#x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#x : number +>x : Derived + } + } + } +} + diff --git a/tests/baselines/reference/privateNameNestedClassFieldShadowing.js b/tests/baselines/reference/privateNameNestedClassFieldShadowing.js index ae661e3230b6a..f717f1d1801cc 100644 --- a/tests/baselines/reference/privateNameNestedClassFieldShadowing.js +++ b/tests/baselines/reference/privateNameNestedClassFieldShadowing.js @@ -16,29 +16,28 @@ class Base { //// [privateNameNestedClassFieldShadowing.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _x; +var _Base_x; class Base { constructor() { - var _x_1; - _x.set(this, void 0); + var _Derived_x; + _Base_x.set(this, void 0); class Derived { constructor() { - _x_1.set(this, void 0); + _Derived_x.set(this, void 0); } testBase(x) { - console.log(__classPrivateFieldGet(x, _x_1)); + console.log(__classPrivateFieldGet(x, _Derived_x, "f")); } testDerived(x) { - console.log(__classPrivateFieldGet(x, _x_1)); + console.log(__classPrivateFieldGet(x, _Derived_x, "f")); } } - _x_1 = new WeakMap(); + _Derived_x = new WeakMap(); } } -_x = new WeakMap(); +_Base_x = new WeakMap(); diff --git a/tests/baselines/reference/privateNameNestedClassMethodShadowing.errors.txt b/tests/baselines/reference/privateNameNestedClassMethodShadowing.errors.txt new file mode 100644 index 0000000000000..8f3f19a9fc5be --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassMethodShadowing.errors.txt @@ -0,0 +1,23 @@ +tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts(7,31): error TS18014: The property '#x' cannot be accessed on type 'Base' within this class because it is shadowed by another private identifier with the same spelling. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts (1 errors) ==== + class Base { + #x() { }; + constructor() { + class Derived { + #x() { }; + testBase(x: Base) { + console.log(x.#x); + ~~ +!!! error TS18014: The property '#x' cannot be accessed on type 'Base' within this class because it is shadowed by another private identifier with the same spelling. +!!! related TS18017 tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts:5:13: The shadowing declaration of '#x' is defined here +!!! related TS18018 tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts:2:5: The declaration of '#x' that you probably intended to use is defined here + } + testDerived(x: Derived) { + console.log(x.#x); + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameNestedClassMethodShadowing.js b/tests/baselines/reference/privateNameNestedClassMethodShadowing.js new file mode 100644 index 0000000000000..df19ceac68b07 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassMethodShadowing.js @@ -0,0 +1,45 @@ +//// [privateNameNestedClassMethodShadowing.ts] +class Base { + #x() { }; + constructor() { + class Derived { + #x() { }; + testBase(x: Base) { + console.log(x.#x); + } + testDerived(x: Derived) { + console.log(x.#x); + } + } + } +} + + +//// [privateNameNestedClassMethodShadowing.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 _Base_instances, _Base_x; +class Base { + constructor() { + var _Derived_instances, _Derived_x; + _Base_instances.add(this); + class Derived { + constructor() { + _Derived_instances.add(this); + } + ; + testBase(x) { + console.log(__classPrivateFieldGet(x, _Derived_instances, "m", _Derived_x)); + } + testDerived(x) { + console.log(__classPrivateFieldGet(x, _Derived_instances, "m", _Derived_x)); + } + } + _Derived_instances = new WeakSet(), _Derived_x = function _Derived_x() { }; + } + ; +} +_Base_instances = new WeakSet(), _Base_x = function _Base_x() { }; diff --git a/tests/baselines/reference/privateNameNestedClassMethodShadowing.symbols b/tests/baselines/reference/privateNameNestedClassMethodShadowing.symbols new file mode 100644 index 0000000000000..4a8b23726f9e1 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassMethodShadowing.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts === +class Base { +>Base : Symbol(Base, Decl(privateNameNestedClassMethodShadowing.ts, 0, 0)) + + #x() { }; +>#x : Symbol(Base.#x, Decl(privateNameNestedClassMethodShadowing.ts, 0, 12)) + + constructor() { + class Derived { +>Derived : Symbol(Derived, Decl(privateNameNestedClassMethodShadowing.ts, 2, 19)) + + #x() { }; +>#x : Symbol(Derived.#x, Decl(privateNameNestedClassMethodShadowing.ts, 3, 23)) + + testBase(x: Base) { +>testBase : Symbol(Derived.testBase, Decl(privateNameNestedClassMethodShadowing.ts, 4, 21)) +>x : Symbol(x, Decl(privateNameNestedClassMethodShadowing.ts, 5, 21)) +>Base : Symbol(Base, Decl(privateNameNestedClassMethodShadowing.ts, 0, 0)) + + console.log(x.#x); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameNestedClassMethodShadowing.ts, 5, 21)) + } + testDerived(x: Derived) { +>testDerived : Symbol(Derived.testDerived, Decl(privateNameNestedClassMethodShadowing.ts, 7, 13)) +>x : Symbol(x, Decl(privateNameNestedClassMethodShadowing.ts, 8, 24)) +>Derived : Symbol(Derived, Decl(privateNameNestedClassMethodShadowing.ts, 2, 19)) + + console.log(x.#x); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x.#x : Symbol(Derived.#x, Decl(privateNameNestedClassMethodShadowing.ts, 3, 23)) +>x : Symbol(x, Decl(privateNameNestedClassMethodShadowing.ts, 8, 24)) + } + } + } +} + diff --git a/tests/baselines/reference/privateNameNestedClassMethodShadowing.types b/tests/baselines/reference/privateNameNestedClassMethodShadowing.types new file mode 100644 index 0000000000000..66f4023d0de36 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedClassMethodShadowing.types @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts === +class Base { +>Base : Base + + #x() { }; +>#x : () => void + + constructor() { + class Derived { +>Derived : Derived + + #x() { }; +>#x : () => void + + testBase(x: Base) { +>testBase : (x: Base) => void +>x : Base + + console.log(x.#x); +>console.log(x.#x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#x : any +>x : Base + } + testDerived(x: Derived) { +>testDerived : (x: Derived) => void +>x : Derived + + console.log(x.#x); +>console.log(x.#x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#x : () => void +>x : Derived + } + } + } +} + diff --git a/tests/baselines/reference/privateNameNestedClassNameConflict.js b/tests/baselines/reference/privateNameNestedClassNameConflict.js index 23bbeeaae8838..5716c3ccb5327 100644 --- a/tests/baselines/reference/privateNameNestedClassNameConflict.js +++ b/tests/baselines/reference/privateNameNestedClassNameConflict.js @@ -10,17 +10,17 @@ class A { //// [privateNameNestedClassNameConflict.js] -var _foo; +var _A_foo; class A { constructor() { - var _foo_1; - _foo.set(this, void 0); + var _A_foo_1; + _A_foo.set(this, void 0); class A { constructor() { - _foo_1.set(this, void 0); + _A_foo_1.set(this, void 0); } } - _foo_1 = new WeakMap(); + _A_foo_1 = new WeakMap(); } } -_foo = new WeakMap(); +_A_foo = new WeakMap(); diff --git a/tests/baselines/reference/privateNameNestedMethodAccess.errors.txt b/tests/baselines/reference/privateNameNestedMethodAccess.errors.txt new file mode 100644 index 0000000000000..93c48aea734e1 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedMethodAccess.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts(11,25): error TS18014: The property '#bar' cannot be accessed on type 'C' within this class because it is shadowed by another private identifier with the same spelling. +tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts(19,19): error TS2339: Property '#unknown' does not exist on type 'any'. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts (2 errors) ==== + class C { + #foo = 42; + #bar() { new C().#baz; } + get #baz() { return 42; } + + m() { + return class D { + #bar() {} + constructor() { + new C().#foo; + new C().#bar; // Error + ~~~~ +!!! error TS18014: The property '#bar' cannot be accessed on type 'C' within this class because it is shadowed by another private identifier with the same spelling. +!!! related TS18017 tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts:8:13: The shadowing declaration of '#bar' is defined here +!!! related TS18018 tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts:3:5: The declaration of '#bar' that you probably intended to use is defined here + new C().#baz; + new D().#bar; + } + + n(x: any) { + x.#foo; + x.#bar; + x.#unknown; // Error + ~~~~~~~~ +!!! error TS2339: Property '#unknown' does not exist on type 'any'. + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameNestedMethodAccess.js b/tests/baselines/reference/privateNameNestedMethodAccess.js new file mode 100644 index 0000000000000..2bdd57e019e76 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedMethodAccess.js @@ -0,0 +1,60 @@ +//// [privateNameNestedMethodAccess.ts] +class C { + #foo = 42; + #bar() { new C().#baz; } + get #baz() { return 42; } + + m() { + return class D { + #bar() {} + constructor() { + new C().#foo; + new C().#bar; // Error + new C().#baz; + new D().#bar; + } + + n(x: any) { + x.#foo; + x.#bar; + x.#unknown; // Error + } + } + } +} + + +//// [privateNameNestedMethodAccess.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _C_instances, _C_foo, _C_bar, _C_baz_get; +class C { + constructor() { + _C_instances.add(this); + _C_foo.set(this, 42); + } + m() { + var _D_instances, _D_bar, _a; + return _a = class D { + constructor() { + _D_instances.add(this); + __classPrivateFieldGet(new C(), _C_foo, "f"); + __classPrivateFieldGet(new C(), _D_instances, "m", _D_bar); // Error + __classPrivateFieldGet(new C(), _C_instances, "a", _C_baz_get); + __classPrivateFieldGet(new D(), _D_instances, "m", _D_bar); + } + n(x) { + __classPrivateFieldGet(x, _C_foo, "f"); + __classPrivateFieldGet(x, _D_instances, "m", _D_bar); + x.; // Error + } + }, + _D_instances = new WeakSet(), + _D_bar = function _D_bar() { }, + _a; + } +} +_C_foo = new WeakMap(), _C_instances = new WeakSet(), _C_bar = function _C_bar() { __classPrivateFieldGet(new C(), _C_instances, "a", _C_baz_get); }, _C_baz_get = function _C_baz_get() { return 42; }; diff --git a/tests/baselines/reference/privateNameNestedMethodAccess.symbols b/tests/baselines/reference/privateNameNestedMethodAccess.symbols new file mode 100644 index 0000000000000..689923e5b9d98 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedMethodAccess.symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts === +class C { +>C : Symbol(C, Decl(privateNameNestedMethodAccess.ts, 0, 0)) + + #foo = 42; +>#foo : Symbol(C.#foo, Decl(privateNameNestedMethodAccess.ts, 0, 9)) + + #bar() { new C().#baz; } +>#bar : Symbol(C.#bar, Decl(privateNameNestedMethodAccess.ts, 1, 14)) +>new C().#baz : Symbol(C.#baz, Decl(privateNameNestedMethodAccess.ts, 2, 28)) +>C : Symbol(C, Decl(privateNameNestedMethodAccess.ts, 0, 0)) + + get #baz() { return 42; } +>#baz : Symbol(C.#baz, Decl(privateNameNestedMethodAccess.ts, 2, 28)) + + m() { +>m : Symbol(C.m, Decl(privateNameNestedMethodAccess.ts, 3, 29)) + + return class D { +>D : Symbol(D, Decl(privateNameNestedMethodAccess.ts, 6, 14)) + + #bar() {} +>#bar : Symbol(D.#bar, Decl(privateNameNestedMethodAccess.ts, 6, 24)) + + constructor() { + new C().#foo; +>new C().#foo : Symbol(C.#foo, Decl(privateNameNestedMethodAccess.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameNestedMethodAccess.ts, 0, 0)) + + new C().#bar; // Error +>C : Symbol(C, Decl(privateNameNestedMethodAccess.ts, 0, 0)) + + new C().#baz; +>new C().#baz : Symbol(C.#baz, Decl(privateNameNestedMethodAccess.ts, 2, 28)) +>C : Symbol(C, Decl(privateNameNestedMethodAccess.ts, 0, 0)) + + new D().#bar; +>new D().#bar : Symbol(D.#bar, Decl(privateNameNestedMethodAccess.ts, 6, 24)) +>D : Symbol(D, Decl(privateNameNestedMethodAccess.ts, 6, 14)) + } + + n(x: any) { +>n : Symbol(D.n, Decl(privateNameNestedMethodAccess.ts, 13, 13)) +>x : Symbol(x, Decl(privateNameNestedMethodAccess.ts, 15, 14)) + + x.#foo; +>x : Symbol(x, Decl(privateNameNestedMethodAccess.ts, 15, 14)) + + x.#bar; +>x : Symbol(x, Decl(privateNameNestedMethodAccess.ts, 15, 14)) + + x.#unknown; // Error +>x : Symbol(x, Decl(privateNameNestedMethodAccess.ts, 15, 14)) + } + } + } +} + diff --git a/tests/baselines/reference/privateNameNestedMethodAccess.types b/tests/baselines/reference/privateNameNestedMethodAccess.types new file mode 100644 index 0000000000000..1527391504f42 --- /dev/null +++ b/tests/baselines/reference/privateNameNestedMethodAccess.types @@ -0,0 +1,70 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts === +class C { +>C : C + + #foo = 42; +>#foo : number +>42 : 42 + + #bar() { new C().#baz; } +>#bar : () => void +>new C().#baz : number +>new C() : C +>C : typeof C + + get #baz() { return 42; } +>#baz : number +>42 : 42 + + m() { +>m : () => typeof D + + return class D { +>class D { #bar() {} constructor() { new C().#foo; new C().#bar; // Error new C().#baz; new D().#bar; } n(x: any) { x.#foo; x.#bar; x.#unknown; // Error } } : typeof D +>D : typeof D + + #bar() {} +>#bar : () => void + + constructor() { + new C().#foo; +>new C().#foo : number +>new C() : C +>C : typeof C + + new C().#bar; // Error +>new C().#bar : any +>new C() : C +>C : typeof C + + new C().#baz; +>new C().#baz : number +>new C() : C +>C : typeof C + + new D().#bar; +>new D().#bar : () => void +>new D() : D +>D : typeof D + } + + n(x: any) { +>n : (x: any) => void +>x : any + + x.#foo; +>x.#foo : any +>x : any + + x.#bar; +>x.#bar : any +>x : any + + x.#unknown; // Error +>x.#unknown : any +>x : any + } + } + } +} + diff --git a/tests/baselines/reference/privateNameNotAccessibleOutsideDefiningClass.js b/tests/baselines/reference/privateNameNotAccessibleOutsideDefiningClass.js index 3bb84305a4ac8..d2464aada4cdb 100644 --- a/tests/baselines/reference/privateNameNotAccessibleOutsideDefiningClass.js +++ b/tests/baselines/reference/privateNameNotAccessibleOutsideDefiningClass.js @@ -8,11 +8,11 @@ new A().#foo = 4; // Error //// [privateNameNotAccessibleOutsideDefiningClass.js] "use strict"; -var _foo; +var _A_foo; class A { constructor() { - _foo.set(this, 3); + _A_foo.set(this, 3); } } -_foo = new WeakMap(); +_A_foo = new WeakMap(); new A(). = 4; // Error diff --git a/tests/baselines/reference/privateNameReadonly.errors.txt b/tests/baselines/reference/privateNameReadonly.errors.txt new file mode 100644 index 0000000000000..a5e430833cbe6 --- /dev/null +++ b/tests/baselines/reference/privateNameReadonly.errors.txt @@ -0,0 +1,18 @@ +tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts(4,9): error TS2322: Type 'void' is not assignable to type '() => void'. +tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts(4,14): error TS2803: Cannot assign to private method '#bar'. Private methods are not writable. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts (2 errors) ==== + const C = class { + #bar() {} + foo() { + this.#bar = console.log("should log this then throw"); + ~~~~~~~~~ +!!! error TS2322: Type 'void' is not assignable to type '() => void'. + ~~~~ +!!! error TS2803: Cannot assign to private method '#bar'. Private methods are not writable. + } + } + + console.log(new C().foo()); + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameReadonly.js b/tests/baselines/reference/privateNameReadonly.js new file mode 100644 index 0000000000000..30c7378c25f8c --- /dev/null +++ b/tests/baselines/reference/privateNameReadonly.js @@ -0,0 +1,31 @@ +//// [privateNameReadonly.ts] +const C = class { + #bar() {} + foo() { + this.#bar = console.log("should log this then throw"); + } +} + +console.log(new C().foo()); + + +//// [privateNameReadonly.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var _C_instances, _C_bar, _a; +const C = (_a = class { + constructor() { + _C_instances.add(this); + } + foo() { + __classPrivateFieldSet(this, _C_instances, console.log("should log this then throw"), "m"); + } + }, + _C_instances = new WeakSet(), + _C_bar = function _C_bar() { }, + _a); +console.log(new C().foo()); diff --git a/tests/baselines/reference/privateNameReadonly.symbols b/tests/baselines/reference/privateNameReadonly.symbols new file mode 100644 index 0000000000000..1f4e58cdfd038 --- /dev/null +++ b/tests/baselines/reference/privateNameReadonly.symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts === +const C = class { +>C : Symbol(C, Decl(privateNameReadonly.ts, 0, 5)) + + #bar() {} +>#bar : Symbol(C.#bar, Decl(privateNameReadonly.ts, 0, 17)) + + foo() { +>foo : Symbol(C.foo, Decl(privateNameReadonly.ts, 1, 13)) + + this.#bar = console.log("should log this then throw"); +>this.#bar : Symbol(C.#bar, Decl(privateNameReadonly.ts, 0, 17)) +>this : Symbol(C, Decl(privateNameReadonly.ts, 0, 9)) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + } +} + +console.log(new C().foo()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>new C().foo : Symbol(C.foo, Decl(privateNameReadonly.ts, 1, 13)) +>C : Symbol(C, Decl(privateNameReadonly.ts, 0, 5)) +>foo : Symbol(C.foo, Decl(privateNameReadonly.ts, 1, 13)) + diff --git a/tests/baselines/reference/privateNameReadonly.types b/tests/baselines/reference/privateNameReadonly.types new file mode 100644 index 0000000000000..e4e460df3a51c --- /dev/null +++ b/tests/baselines/reference/privateNameReadonly.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts === +const C = class { +>C : typeof C +>class { #bar() {} foo() { this.#bar = console.log("should log this then throw"); }} : typeof C + + #bar() {} +>#bar : () => void + + foo() { +>foo : () => void + + this.#bar = console.log("should log this then throw"); +>this.#bar = console.log("should log this then throw") : void +>this.#bar : () => void +>this : this +>console.log("should log this then throw") : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>"should log this then throw" : "should log this then throw" + } +} + +console.log(new C().foo()); +>console.log(new C().foo()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>new C().foo() : void +>new C().foo : () => void +>new C() : C +>C : typeof C +>foo : () => void + diff --git a/tests/baselines/reference/privateNameSetterExprReturnValue.js b/tests/baselines/reference/privateNameSetterExprReturnValue.js new file mode 100644 index 0000000000000..2f4af65aff2ff --- /dev/null +++ b/tests/baselines/reference/privateNameSetterExprReturnValue.js @@ -0,0 +1,31 @@ +//// [privateNameSetterExprReturnValue.ts] +class C { + set #foo(a: number) {} + bar() { + let x = (this.#foo = 42 * 2); + console.log(x); // 84 + } +} + +new C().bar(); + + +//// [privateNameSetterExprReturnValue.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var _C_instances, _C_foo_set; +class C { + constructor() { + _C_instances.add(this); + } + bar() { + let x = (__classPrivateFieldSet(this, _C_instances, 42 * 2, "a", _C_foo_set)); + console.log(x); // 84 + } +} +_C_instances = new WeakSet(), _C_foo_set = function _C_foo_set(a) { }; +new C().bar(); diff --git a/tests/baselines/reference/privateNameSetterExprReturnValue.symbols b/tests/baselines/reference/privateNameSetterExprReturnValue.symbols new file mode 100644 index 0000000000000..56f6e1099bff2 --- /dev/null +++ b/tests/baselines/reference/privateNameSetterExprReturnValue.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameSetterExprReturnValue.ts === +class C { +>C : Symbol(C, Decl(privateNameSetterExprReturnValue.ts, 0, 0)) + + set #foo(a: number) {} +>#foo : Symbol(C.#foo, Decl(privateNameSetterExprReturnValue.ts, 0, 9)) +>a : Symbol(a, Decl(privateNameSetterExprReturnValue.ts, 1, 13)) + + bar() { +>bar : Symbol(C.bar, Decl(privateNameSetterExprReturnValue.ts, 1, 26)) + + let x = (this.#foo = 42 * 2); +>x : Symbol(x, Decl(privateNameSetterExprReturnValue.ts, 3, 11)) +>this.#foo : Symbol(C.#foo, Decl(privateNameSetterExprReturnValue.ts, 0, 9)) +>this : Symbol(C, Decl(privateNameSetterExprReturnValue.ts, 0, 0)) + + console.log(x); // 84 +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameSetterExprReturnValue.ts, 3, 11)) + } +} + +new C().bar(); +>new C().bar : Symbol(C.bar, Decl(privateNameSetterExprReturnValue.ts, 1, 26)) +>C : Symbol(C, Decl(privateNameSetterExprReturnValue.ts, 0, 0)) +>bar : Symbol(C.bar, Decl(privateNameSetterExprReturnValue.ts, 1, 26)) + diff --git a/tests/baselines/reference/privateNameSetterExprReturnValue.types b/tests/baselines/reference/privateNameSetterExprReturnValue.types new file mode 100644 index 0000000000000..2713756c0ab69 --- /dev/null +++ b/tests/baselines/reference/privateNameSetterExprReturnValue.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameSetterExprReturnValue.ts === +class C { +>C : C + + set #foo(a: number) {} +>#foo : number +>a : number + + bar() { +>bar : () => void + + let x = (this.#foo = 42 * 2); +>x : number +>(this.#foo = 42 * 2) : number +>this.#foo = 42 * 2 : number +>this.#foo : number +>this : this +>42 * 2 : number +>42 : 42 +>2 : 2 + + console.log(x); // 84 +>console.log(x) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x : number + } +} + +new C().bar(); +>new C().bar() : void +>new C().bar : () => void +>new C() : C +>C : typeof C +>bar : () => void + diff --git a/tests/baselines/reference/privateNameSetterNoGetter.errors.txt b/tests/baselines/reference/privateNameSetterNoGetter.errors.txt new file mode 100644 index 0000000000000..61523f9190f9f --- /dev/null +++ b/tests/baselines/reference/privateNameSetterNoGetter.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts(4,9): error TS2806: Private accessor was defined without a getter. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts (1 errors) ==== + const C = class { + set #x(x) {} + m() { + this.#x += 2; // Error + ~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + } + } + + console.log(new C().m()); + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameSetterNoGetter.js b/tests/baselines/reference/privateNameSetterNoGetter.js new file mode 100644 index 0000000000000..c3408a5dc8fd0 --- /dev/null +++ b/tests/baselines/reference/privateNameSetterNoGetter.js @@ -0,0 +1,36 @@ +//// [privateNameSetterNoGetter.ts] +const C = class { + set #x(x) {} + m() { + this.#x += 2; // Error + } +} + +console.log(new C().m()); + + +//// [privateNameSetterNoGetter.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 _C_instances, _C_x_set, _a; +const C = (_a = class { + constructor() { + _C_instances.add(this); + } + m() { + __classPrivateFieldSet(this, _C_instances, __classPrivateFieldGet(this, _C_instances, "a") + 2, "a", _C_x_set); // Error + } + }, + _C_instances = new WeakSet(), + _C_x_set = function _C_x_set(x) { }, + _a); +console.log(new C().m()); diff --git a/tests/baselines/reference/privateNameSetterNoGetter.symbols b/tests/baselines/reference/privateNameSetterNoGetter.symbols new file mode 100644 index 0000000000000..95f0f4f73e99f --- /dev/null +++ b/tests/baselines/reference/privateNameSetterNoGetter.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts === +const C = class { +>C : Symbol(C, Decl(privateNameSetterNoGetter.ts, 0, 5)) + + set #x(x) {} +>#x : Symbol(C.#x, Decl(privateNameSetterNoGetter.ts, 0, 17)) +>x : Symbol(x, Decl(privateNameSetterNoGetter.ts, 1, 11)) + + m() { +>m : Symbol(C.m, Decl(privateNameSetterNoGetter.ts, 1, 16)) + + this.#x += 2; // Error +>this.#x : Symbol(C.#x, Decl(privateNameSetterNoGetter.ts, 0, 17)) +>this : Symbol(C, Decl(privateNameSetterNoGetter.ts, 0, 9)) + } +} + +console.log(new C().m()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>new C().m : Symbol(C.m, Decl(privateNameSetterNoGetter.ts, 1, 16)) +>C : Symbol(C, Decl(privateNameSetterNoGetter.ts, 0, 5)) +>m : Symbol(C.m, Decl(privateNameSetterNoGetter.ts, 1, 16)) + diff --git a/tests/baselines/reference/privateNameSetterNoGetter.types b/tests/baselines/reference/privateNameSetterNoGetter.types new file mode 100644 index 0000000000000..542069f49ad5e --- /dev/null +++ b/tests/baselines/reference/privateNameSetterNoGetter.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts === +const C = class { +>C : typeof C +>class { set #x(x) {} m() { this.#x += 2; // Error }} : typeof C + + set #x(x) {} +>#x : any +>x : any + + m() { +>m : () => void + + this.#x += 2; // Error +>this.#x += 2 : any +>this.#x : any +>this : this +>2 : 2 + } +} + +console.log(new C().m()); +>console.log(new C().m()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>new C().m() : void +>new C().m : () => void +>new C() : C +>C : typeof C +>m : () => void + diff --git a/tests/baselines/reference/privateNameStaticAccessors.errors.txt b/tests/baselines/reference/privateNameStaticAccessors.errors.txt new file mode 100644 index 0000000000000..ad5c9cea1faba --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessors.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts(9,12): error TS2540: Cannot assign to '#roProp' because it is a read-only property. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts (1 errors) ==== + class A1 { + static get #prop() { return ""; } + static set #prop(param: string) { } + + static get #roProp() { return ""; } + + constructor(name: string) { + A1.#prop = ""; + A1.#roProp = ""; // Error + ~~~~~~~ +!!! error TS2540: Cannot assign to '#roProp' because it is a read-only property. + console.log(A1.#prop); + console.log(A1.#roProp); + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticAccessors.js b/tests/baselines/reference/privateNameStaticAccessors.js new file mode 100644 index 0000000000000..8859c2ca2b736 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessors.js @@ -0,0 +1,39 @@ +//// [privateNameStaticAccessors.ts] +class A1 { + static get #prop() { return ""; } + static set #prop(param: string) { } + + static get #roProp() { return ""; } + + constructor(name: string) { + A1.#prop = ""; + A1.#roProp = ""; // Error + console.log(A1.#prop); + console.log(A1.#roProp); + } +} + + +//// [privateNameStaticAccessors.js] +"use strict"; +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A1_prop_get, _A1_prop_set, _A1_roProp_get; +class A1 { + constructor(name) { + __classPrivateFieldSet(A1, _a, "", "a", _A1_prop_set); + __classPrivateFieldSet(A1, _a, "", "a"); // Error + console.log(__classPrivateFieldGet(A1, _a, "a", _A1_prop_get)); + console.log(__classPrivateFieldGet(A1, _a, "a", _A1_roProp_get)); + } +} +_a = A1, _A1_prop_get = function _A1_prop_get() { return ""; }, _A1_prop_set = function _A1_prop_set(param) { }, _A1_roProp_get = function _A1_roProp_get() { return ""; }; diff --git a/tests/baselines/reference/privateNameStaticAccessors.symbols b/tests/baselines/reference/privateNameStaticAccessors.symbols new file mode 100644 index 0000000000000..d43d930992ec8 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessors.symbols @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts === +class A1 { +>A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) + + static get #prop() { return ""; } +>#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) + + static set #prop(param: string) { } +>#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) +>param : Symbol(param, Decl(privateNameStaticAccessors.ts, 2, 21)) + + static get #roProp() { return ""; } +>#roProp : Symbol(A1.#roProp, Decl(privateNameStaticAccessors.ts, 2, 39)) + + constructor(name: string) { +>name : Symbol(name, Decl(privateNameStaticAccessors.ts, 6, 16)) + + A1.#prop = ""; +>A1.#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) +>A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) + + A1.#roProp = ""; // Error +>A1.#roProp : Symbol(A1.#roProp, Decl(privateNameStaticAccessors.ts, 2, 39)) +>A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) + + console.log(A1.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>A1.#prop : Symbol(A1.#prop, Decl(privateNameStaticAccessors.ts, 0, 10), Decl(privateNameStaticAccessors.ts, 1, 37)) +>A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) + + console.log(A1.#roProp); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>A1.#roProp : Symbol(A1.#roProp, Decl(privateNameStaticAccessors.ts, 2, 39)) +>A1 : Symbol(A1, Decl(privateNameStaticAccessors.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticAccessors.types b/tests/baselines/reference/privateNameStaticAccessors.types new file mode 100644 index 0000000000000..7a903c854282b --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessors.types @@ -0,0 +1,49 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts === +class A1 { +>A1 : A1 + + static get #prop() { return ""; } +>#prop : string +>"" : "" + + static set #prop(param: string) { } +>#prop : string +>param : string + + static get #roProp() { return ""; } +>#roProp : string +>"" : "" + + constructor(name: string) { +>name : string + + A1.#prop = ""; +>A1.#prop = "" : "" +>A1.#prop : string +>A1 : typeof A1 +>"" : "" + + A1.#roProp = ""; // Error +>A1.#roProp = "" : "" +>A1.#roProp : any +>A1 : typeof A1 +>"" : "" + + console.log(A1.#prop); +>console.log(A1.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>A1.#prop : string +>A1 : typeof A1 + + console.log(A1.#roProp); +>console.log(A1.#roProp) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>A1.#roProp : string +>A1 : typeof A1 + } +} + diff --git a/tests/baselines/reference/privateNameStaticAccessorsAccess.errors.txt b/tests/baselines/reference/privateNameStaticAccessorsAccess.errors.txt new file mode 100644 index 0000000000000..a41043d318791 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsAccess.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts(16,4): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts(19,8): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts(24,12): error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts (3 errors) ==== + export {} + class A2 { + static get #prop() { return ""; } + static set #prop(param: string) { } + + constructor() { + console.log(A2.#prop); + let a: typeof A2 = A2; + a.#prop; + function foo (){ + a.#prop; + } + } + } + + A2.#prop; // Error + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + + function foo (){ + A2.#prop; // Error + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + } + + class B2 { + m() { + A2.#prop; + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'A2' because it has a private identifier. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticAccessorsAccess.js b/tests/baselines/reference/privateNameStaticAccessorsAccess.js new file mode 100644 index 0000000000000..f79688892ec10 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsAccess.js @@ -0,0 +1,57 @@ +//// [privateNameStaticAccessorsAccess.ts] +export {} +class A2 { + static get #prop() { return ""; } + static set #prop(param: string) { } + + constructor() { + console.log(A2.#prop); + let a: typeof A2 = A2; + a.#prop; + function foo (){ + a.#prop; + } + } +} + +A2.#prop; // Error + +function foo (){ + A2.#prop; // Error +} + +class B2 { + m() { + A2.#prop; + } +} + + +//// [privateNameStaticAccessorsAccess.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A2_prop_get, _A2_prop_set; +class A2 { + constructor() { + console.log(__classPrivateFieldGet(A2, _a, "a", _A2_prop_get)); + let a = A2; + __classPrivateFieldGet(a, _a, "a", _A2_prop_get); + function foo() { + __classPrivateFieldGet(a, _a, "a", _A2_prop_get); + } + } +} +_a = A2, _A2_prop_get = function _A2_prop_get() { return ""; }, _A2_prop_set = function _A2_prop_set(param) { }; +A2.; // Error +function foo() { + A2.; // Error +} +class B2 { + m() { + A2.; + } +} +export {}; diff --git a/tests/baselines/reference/privateNameStaticAccessorsAccess.symbols b/tests/baselines/reference/privateNameStaticAccessorsAccess.symbols new file mode 100644 index 0000000000000..140f6e23aa10b --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsAccess.symbols @@ -0,0 +1,60 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts === +export {} +class A2 { +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) + + static get #prop() { return ""; } +>#prop : Symbol(A2.#prop, Decl(privateNameStaticAccessorsAccess.ts, 1, 10), Decl(privateNameStaticAccessorsAccess.ts, 2, 37)) + + static set #prop(param: string) { } +>#prop : Symbol(A2.#prop, Decl(privateNameStaticAccessorsAccess.ts, 1, 10), Decl(privateNameStaticAccessorsAccess.ts, 2, 37)) +>param : Symbol(param, Decl(privateNameStaticAccessorsAccess.ts, 3, 21)) + + constructor() { + console.log(A2.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>A2.#prop : Symbol(A2.#prop, Decl(privateNameStaticAccessorsAccess.ts, 1, 10), Decl(privateNameStaticAccessorsAccess.ts, 2, 37)) +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) + + let a: typeof A2 = A2; +>a : Symbol(a, Decl(privateNameStaticAccessorsAccess.ts, 7, 11)) +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) + + a.#prop; +>a.#prop : Symbol(A2.#prop, Decl(privateNameStaticAccessorsAccess.ts, 1, 10), Decl(privateNameStaticAccessorsAccess.ts, 2, 37)) +>a : Symbol(a, Decl(privateNameStaticAccessorsAccess.ts, 7, 11)) + + function foo (){ +>foo : Symbol(foo, Decl(privateNameStaticAccessorsAccess.ts, 8, 16)) + + a.#prop; +>a.#prop : Symbol(A2.#prop, Decl(privateNameStaticAccessorsAccess.ts, 1, 10), Decl(privateNameStaticAccessorsAccess.ts, 2, 37)) +>a : Symbol(a, Decl(privateNameStaticAccessorsAccess.ts, 7, 11)) + } + } +} + +A2.#prop; // Error +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) + +function foo (){ +>foo : Symbol(foo, Decl(privateNameStaticAccessorsAccess.ts, 15, 9)) + + A2.#prop; // Error +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) +} + +class B2 { +>B2 : Symbol(B2, Decl(privateNameStaticAccessorsAccess.ts, 19, 1)) + + m() { +>m : Symbol(B2.m, Decl(privateNameStaticAccessorsAccess.ts, 21, 10)) + + A2.#prop; +>A2 : Symbol(A2, Decl(privateNameStaticAccessorsAccess.ts, 0, 9)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticAccessorsAccess.types b/tests/baselines/reference/privateNameStaticAccessorsAccess.types new file mode 100644 index 0000000000000..71171d25f34c3 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsAccess.types @@ -0,0 +1,65 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts === +export {} +class A2 { +>A2 : A2 + + static get #prop() { return ""; } +>#prop : string +>"" : "" + + static set #prop(param: string) { } +>#prop : string +>param : string + + constructor() { + console.log(A2.#prop); +>console.log(A2.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>A2.#prop : string +>A2 : typeof A2 + + let a: typeof A2 = A2; +>a : typeof A2 +>A2 : typeof A2 +>A2 : typeof A2 + + a.#prop; +>a.#prop : string +>a : typeof A2 + + function foo (){ +>foo : () => void + + a.#prop; +>a.#prop : string +>a : typeof A2 + } + } +} + +A2.#prop; // Error +>A2.#prop : any +>A2 : typeof A2 + +function foo (){ +>foo : () => void + + A2.#prop; // Error +>A2.#prop : any +>A2 : typeof A2 +} + +class B2 { +>B2 : B2 + + m() { +>m : () => void + + A2.#prop; +>A2.#prop : any +>A2 : typeof A2 + } +} + diff --git a/tests/baselines/reference/privateNameStaticAccessorsCallExpression.js b/tests/baselines/reference/privateNameStaticAccessorsCallExpression.js new file mode 100644 index 0000000000000..b0f5eee7579e5 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsCallExpression.js @@ -0,0 +1,50 @@ +//// [privateNameStaticAccessorsCallExpression.ts] +class A { + static get #fieldFunc() { return function() { A.#x = 10; } } + static get #fieldFunc2() { return function(a, ...b) {}; } + static #x = 1; + static test() { + this.#fieldFunc(); + const func = this.#fieldFunc; + func(); + new this.#fieldFunc(); + + const arr = [ 1, 2 ]; + this.#fieldFunc2(0, ...arr, 3); + const b = new this.#fieldFunc2(0, ...arr, 3); + const str = this.#fieldFunc2`head${1}middle${2}tail`; + this.getClass().#fieldFunc2`test${1}and${2}`; + } + static getClass() { return A; } +} + +//// [privateNameStaticAccessorsCallExpression.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A_fieldFunc_get, _A_fieldFunc2_get, _A_x; +class A { + static test() { + var _b; + __classPrivateFieldGet(this, _a, "a", _A_fieldFunc_get).call(this); + const func = __classPrivateFieldGet(this, _a, "a", _A_fieldFunc_get); + func(); + new (__classPrivateFieldGet(this, _a, "a", _A_fieldFunc_get))(); + const arr = [1, 2]; + __classPrivateFieldGet(this, _a, "a", _A_fieldFunc2_get).call(this, 0, ...arr, 3); + const b = new (__classPrivateFieldGet(this, _a, "a", _A_fieldFunc2_get))(0, ...arr, 3); + const str = __classPrivateFieldGet(this, _a, "a", _A_fieldFunc2_get).bind(this) `head${1}middle${2}tail`; + __classPrivateFieldGet((_b = this.getClass()), _a, "a", _A_fieldFunc2_get).bind(_b) `test${1}and${2}`; + } + static getClass() { return A; } +} +_a = A, _A_fieldFunc_get = function _A_fieldFunc_get() { return function () { __classPrivateFieldSet(A, _a, 10, "f", _A_x); }; }, _A_fieldFunc2_get = function _A_fieldFunc2_get() { return function (a, ...b) { }; }; +_A_x = { value: 1 }; diff --git a/tests/baselines/reference/privateNameStaticAccessorsCallExpression.symbols b/tests/baselines/reference/privateNameStaticAccessorsCallExpression.symbols new file mode 100644 index 0000000000000..c11fd82677997 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsCallExpression.symbols @@ -0,0 +1,65 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsCallExpression.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) + + static get #fieldFunc() { return function() { A.#x = 10; } } +>#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 9)) +>A.#x : Symbol(A.#x, Decl(privateNameStaticAccessorsCallExpression.ts, 2, 62)) +>A : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) + + static get #fieldFunc2() { return function(a, ...b) {}; } +>#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticAccessorsCallExpression.ts, 1, 65)) +>a : Symbol(a, Decl(privateNameStaticAccessorsCallExpression.ts, 2, 48)) +>b : Symbol(b, Decl(privateNameStaticAccessorsCallExpression.ts, 2, 50)) + + static #x = 1; +>#x : Symbol(A.#x, Decl(privateNameStaticAccessorsCallExpression.ts, 2, 62)) + + static test() { +>test : Symbol(A.test, Decl(privateNameStaticAccessorsCallExpression.ts, 3, 18)) + + this.#fieldFunc(); +>this.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 9)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) + + const func = this.#fieldFunc; +>func : Symbol(func, Decl(privateNameStaticAccessorsCallExpression.ts, 6, 13)) +>this.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 9)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) + + func(); +>func : Symbol(func, Decl(privateNameStaticAccessorsCallExpression.ts, 6, 13)) + + new this.#fieldFunc(); +>this.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 9)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) + + const arr = [ 1, 2 ]; +>arr : Symbol(arr, Decl(privateNameStaticAccessorsCallExpression.ts, 10, 13)) + + this.#fieldFunc2(0, ...arr, 3); +>this.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticAccessorsCallExpression.ts, 1, 65)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameStaticAccessorsCallExpression.ts, 10, 13)) + + const b = new this.#fieldFunc2(0, ...arr, 3); +>b : Symbol(b, Decl(privateNameStaticAccessorsCallExpression.ts, 12, 13)) +>this.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticAccessorsCallExpression.ts, 1, 65)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameStaticAccessorsCallExpression.ts, 10, 13)) + + const str = this.#fieldFunc2`head${1}middle${2}tail`; +>str : Symbol(str, Decl(privateNameStaticAccessorsCallExpression.ts, 13, 13)) +>this.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticAccessorsCallExpression.ts, 1, 65)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) + + this.getClass().#fieldFunc2`test${1}and${2}`; +>this.getClass().#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticAccessorsCallExpression.ts, 1, 65)) +>this.getClass : Symbol(A.getClass, Decl(privateNameStaticAccessorsCallExpression.ts, 15, 5)) +>this : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticAccessorsCallExpression.ts, 15, 5)) + } + static getClass() { return A; } +>getClass : Symbol(A.getClass, Decl(privateNameStaticAccessorsCallExpression.ts, 15, 5)) +>A : Symbol(A, Decl(privateNameStaticAccessorsCallExpression.ts, 0, 0)) +} diff --git a/tests/baselines/reference/privateNameStaticAccessorsCallExpression.types b/tests/baselines/reference/privateNameStaticAccessorsCallExpression.types new file mode 100644 index 0000000000000..6ad27c928d045 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorsCallExpression.types @@ -0,0 +1,93 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsCallExpression.ts === +class A { +>A : A + + static get #fieldFunc() { return function() { A.#x = 10; } } +>#fieldFunc : () => void +>function() { A.#x = 10; } : () => void +>A.#x = 10 : 10 +>A.#x : number +>A : typeof A +>10 : 10 + + static get #fieldFunc2() { return function(a, ...b) {}; } +>#fieldFunc2 : (a: any, ...b: any[]) => void +>function(a, ...b) {} : (a: any, ...b: any[]) => void +>a : any +>b : any[] + + static #x = 1; +>#x : number +>1 : 1 + + static test() { +>test : () => void + + this.#fieldFunc(); +>this.#fieldFunc() : void +>this.#fieldFunc : () => void +>this : typeof A + + const func = this.#fieldFunc; +>func : () => void +>this.#fieldFunc : () => void +>this : typeof A + + func(); +>func() : void +>func : () => void + + new this.#fieldFunc(); +>new this.#fieldFunc() : any +>this.#fieldFunc : () => void +>this : typeof A + + const arr = [ 1, 2 ]; +>arr : number[] +>[ 1, 2 ] : number[] +>1 : 1 +>2 : 2 + + this.#fieldFunc2(0, ...arr, 3); +>this.#fieldFunc2(0, ...arr, 3) : void +>this.#fieldFunc2 : (a: any, ...b: any[]) => void +>this : typeof A +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b = new this.#fieldFunc2(0, ...arr, 3); +>b : any +>new this.#fieldFunc2(0, ...arr, 3) : any +>this.#fieldFunc2 : (a: any, ...b: any[]) => void +>this : typeof A +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str = this.#fieldFunc2`head${1}middle${2}tail`; +>str : void +>this.#fieldFunc2`head${1}middle${2}tail` : void +>this.#fieldFunc2 : (a: any, ...b: any[]) => void +>this : typeof A +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + + this.getClass().#fieldFunc2`test${1}and${2}`; +>this.getClass().#fieldFunc2`test${1}and${2}` : void +>this.getClass().#fieldFunc2 : (a: any, ...b: any[]) => void +>this.getClass() : typeof A +>this.getClass : () => typeof A +>this : typeof A +>getClass : () => typeof A +>`test${1}and${2}` : string +>1 : 1 +>2 : 2 + } + static getClass() { return A; } +>getClass : () => typeof A +>A : typeof A +} diff --git a/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.errors.txt b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.errors.txt new file mode 100644 index 0000000000000..0cbbfd03d4420 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts(4,23): error TS2339: Property '#prop' does not exist on type 'typeof Derived'. +tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts(9,23): error TS2339: Property '#prop' does not exist on type 'typeof Derived'. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts (2 errors) ==== + class Base { + static get #prop(): number { return 123; } + static method(x: typeof Derived) { + console.log(x.#prop); + ~~~~~ +!!! error TS2339: Property '#prop' does not exist on type 'typeof Derived'. + } + } + class Derived extends Base { + static method(x: typeof Derived) { + console.log(x.#prop); + ~~~~~ +!!! error TS2339: Property '#prop' does not exist on type 'typeof Derived'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.js b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.js new file mode 100644 index 0000000000000..dfcbb352150bf --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.js @@ -0,0 +1,32 @@ +//// [privateNameStaticAccessorssDerivedClasses.ts] +class Base { + static get #prop(): number { return 123; } + static method(x: typeof Derived) { + console.log(x.#prop); + } +} +class Derived extends Base { + static method(x: typeof Derived) { + console.log(x.#prop); + } +} + + +//// [privateNameStaticAccessorssDerivedClasses.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _Base_prop_get; +class Base { + static method(x) { + console.log(__classPrivateFieldGet(x, _a, "a", _Base_prop_get)); + } +} +_a = Base, _Base_prop_get = function _Base_prop_get() { return 123; }; +class Derived extends Base { + static method(x) { + console.log(x.); + } +} diff --git a/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.symbols b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.symbols new file mode 100644 index 0000000000000..c5f03fb577ae4 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts === +class Base { +>Base : Symbol(Base, Decl(privateNameStaticAccessorssDerivedClasses.ts, 0, 0)) + + static get #prop(): number { return 123; } +>#prop : Symbol(Base.#prop, Decl(privateNameStaticAccessorssDerivedClasses.ts, 0, 12)) + + static method(x: typeof Derived) { +>method : Symbol(Base.method, Decl(privateNameStaticAccessorssDerivedClasses.ts, 1, 47)) +>x : Symbol(x, Decl(privateNameStaticAccessorssDerivedClasses.ts, 2, 18)) +>Derived : Symbol(Derived, Decl(privateNameStaticAccessorssDerivedClasses.ts, 5, 1)) + + console.log(x.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameStaticAccessorssDerivedClasses.ts, 2, 18)) + } +} +class Derived extends Base { +>Derived : Symbol(Derived, Decl(privateNameStaticAccessorssDerivedClasses.ts, 5, 1)) +>Base : Symbol(Base, Decl(privateNameStaticAccessorssDerivedClasses.ts, 0, 0)) + + static method(x: typeof Derived) { +>method : Symbol(Derived.method, Decl(privateNameStaticAccessorssDerivedClasses.ts, 6, 28)) +>x : Symbol(x, Decl(privateNameStaticAccessorssDerivedClasses.ts, 7, 18)) +>Derived : Symbol(Derived, Decl(privateNameStaticAccessorssDerivedClasses.ts, 5, 1)) + + console.log(x.#prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(privateNameStaticAccessorssDerivedClasses.ts, 7, 18)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.types b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.types new file mode 100644 index 0000000000000..ef775104abfbc --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAccessorssDerivedClasses.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts === +class Base { +>Base : Base + + static get #prop(): number { return 123; } +>#prop : number +>123 : 123 + + static method(x: typeof Derived) { +>method : (x: typeof Derived) => void +>x : typeof Derived +>Derived : typeof Derived + + console.log(x.#prop); +>console.log(x.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#prop : any +>x : typeof Derived + } +} +class Derived extends Base { +>Derived : Derived +>Base : Base + + static method(x: typeof Derived) { +>method : (x: typeof Derived) => void +>x : typeof Derived +>Derived : typeof Derived + + console.log(x.#prop); +>console.log(x.#prop) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>x.#prop : any +>x : typeof Derived + } +} + diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).js b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).js new file mode 100644 index 0000000000000..13c17f4f97233 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).js @@ -0,0 +1,15 @@ +//// [privateNameStaticAndStaticInitializer.ts] +class A { + static #foo = 1; + static #prop = 2; +} + + + +//// [privateNameStaticAndStaticInitializer.js] +var _a, _A_foo, _A_prop; +class A { +} +_a = A; +_A_foo = { value: 1 }; +_A_prop = { value: 2 }; diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).symbols b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).symbols new file mode 100644 index 0000000000000..c0085bdc9b9c0 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticAndStaticInitializer.ts, 0, 0)) + + static #foo = 1; +>#foo : Symbol(A.#foo, Decl(privateNameStaticAndStaticInitializer.ts, 0, 9)) + + static #prop = 2; +>#prop : Symbol(A.#prop, Decl(privateNameStaticAndStaticInitializer.ts, 1, 18)) +} + + diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).types b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).types new file mode 100644 index 0000000000000..956a0474bfb07 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=es2015).types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts === +class A { +>A : A + + static #foo = 1; +>#foo : number +>1 : 1 + + static #prop = 2; +>#prop : number +>2 : 2 +} + + diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).errors.txt b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).errors.txt new file mode 100644 index 0000000000000..ae43b5335e8f9 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts(2,17): error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. +tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts(3,18): error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts (2 errors) ==== + class A { + static #foo = 1; + ~ +!!! error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + static #prop = 2; + ~ +!!! error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + } + + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).js b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).js new file mode 100644 index 0000000000000..2e3d168e42004 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).js @@ -0,0 +1,15 @@ +//// [privateNameStaticAndStaticInitializer.ts] +class A { + static #foo = 1; + static #prop = 2; +} + + + +//// [privateNameStaticAndStaticInitializer.js] +class A { + static #foo; + static #prop; +} +A.#foo = 1; +A.#prop = 2; diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).symbols b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).symbols new file mode 100644 index 0000000000000..c0085bdc9b9c0 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticAndStaticInitializer.ts, 0, 0)) + + static #foo = 1; +>#foo : Symbol(A.#foo, Decl(privateNameStaticAndStaticInitializer.ts, 0, 9)) + + static #prop = 2; +>#prop : Symbol(A.#prop, Decl(privateNameStaticAndStaticInitializer.ts, 1, 18)) +} + + diff --git a/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).types b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).types new file mode 100644 index 0000000000000..956a0474bfb07 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticAndStaticInitializer(target=esnext).types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts === +class A { +>A : A + + static #foo = 1; +>#foo : number +>1 : 1 + + static #prop = 2; +>#prop : number +>2 : 2 +} + + diff --git a/tests/baselines/reference/privateNameStaticEmitHelpers.errors.txt b/tests/baselines/reference/privateNameStaticEmitHelpers.errors.txt new file mode 100644 index 0000000000000..067e0d4b1a5dc --- /dev/null +++ b/tests/baselines/reference/privateNameStaticEmitHelpers.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/classes/members/privateNames/main.ts(3,19): error TS2807: This syntax requires an imported helper named '__classPrivateFieldSet' with 5 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. +tests/cases/conformance/classes/members/privateNames/main.ts(4,30): error TS2807: This syntax requires an imported helper named '__classPrivateFieldGet' with 4 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. + + +==== tests/cases/conformance/classes/members/privateNames/main.ts (2 errors) ==== + export class S { + static #a = 1; + static #b() { this.#a = 42; } + ~~~~~~~ +!!! error TS2807: This syntax requires an imported helper named '__classPrivateFieldSet' with 5 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. + static get #c() { return S.#b(); } + ~~~~ +!!! error TS2807: This syntax requires an imported helper named '__classPrivateFieldGet' with 4 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. + } + +==== tests/cases/conformance/classes/members/privateNames/tslib.d.ts (0 errors) ==== + // these are pre-TS4.3 versions of emit helpers, which only supported private instance fields + export declare function __classPrivateFieldGet(receiver: T, state: any): V; + export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticEmitHelpers.js b/tests/baselines/reference/privateNameStaticEmitHelpers.js new file mode 100644 index 0000000000000..0e57493d5342d --- /dev/null +++ b/tests/baselines/reference/privateNameStaticEmitHelpers.js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/classes/members/privateNames/privateNameStaticEmitHelpers.ts] //// + +//// [main.ts] +export class S { + static #a = 1; + static #b() { this.#a = 42; } + static get #c() { return S.#b(); } +} + +//// [tslib.d.ts] +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; + + +//// [main.js] +var _a, _S_a, _S_b, _S_c_get; +import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; +export class S { +} +_a = S, _S_b = function _S_b() { __classPrivateFieldSet(this, _a, 42, "f", _S_a); }, _S_c_get = function _S_c_get() { return __classPrivateFieldGet(S, _a, "m", _S_b).call(S); }; +_S_a = { value: 1 }; diff --git a/tests/baselines/reference/privateNameStaticEmitHelpers.symbols b/tests/baselines/reference/privateNameStaticEmitHelpers.symbols new file mode 100644 index 0000000000000..12678d86b50f8 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticEmitHelpers.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/classes/members/privateNames/main.ts === +export class S { +>S : Symbol(S, Decl(main.ts, 0, 0)) + + static #a = 1; +>#a : Symbol(S.#a, Decl(main.ts, 0, 16)) + + static #b() { this.#a = 42; } +>#b : Symbol(S.#b, Decl(main.ts, 1, 18)) +>this.#a : Symbol(S.#a, Decl(main.ts, 0, 16)) +>this : Symbol(S, Decl(main.ts, 0, 0)) + + static get #c() { return S.#b(); } +>#c : Symbol(S.#c, Decl(main.ts, 2, 33)) +>S.#b : Symbol(S.#b, Decl(main.ts, 1, 18)) +>S : Symbol(S, Decl(main.ts, 0, 0)) +} + +=== tests/cases/conformance/classes/members/privateNames/tslib.d.ts === +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +>__classPrivateFieldGet : Symbol(__classPrivateFieldGet, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) +>receiver : Symbol(receiver, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>state : Symbol(state, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) + +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; +>__classPrivateFieldSet : Symbol(__classPrivateFieldSet, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) +>receiver : Symbol(receiver, Decl(tslib.d.ts, --, --)) +>T : Symbol(T, Decl(tslib.d.ts, --, --)) +>state : Symbol(state, Decl(tslib.d.ts, --, --)) +>value : Symbol(value, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) +>V : Symbol(V, Decl(tslib.d.ts, --, --)) + diff --git a/tests/baselines/reference/privateNameStaticEmitHelpers.types b/tests/baselines/reference/privateNameStaticEmitHelpers.types new file mode 100644 index 0000000000000..c91637bcad3f4 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticEmitHelpers.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/classes/members/privateNames/main.ts === +export class S { +>S : S + + static #a = 1; +>#a : number +>1 : 1 + + static #b() { this.#a = 42; } +>#b : () => void +>this.#a = 42 : 42 +>this.#a : number +>this : typeof S +>42 : 42 + + static get #c() { return S.#b(); } +>#c : void +>S.#b() : void +>S.#b : () => void +>S : typeof S +} + +=== tests/cases/conformance/classes/members/privateNames/tslib.d.ts === +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +>__classPrivateFieldGet : (receiver: T, state: any) => V +>receiver : T +>state : any + +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; +>__classPrivateFieldSet : (receiver: T, state: any, value: V) => V +>receiver : T +>state : any +>value : V + diff --git a/tests/baselines/reference/privateNameStaticFieldAccess.errors.txt b/tests/baselines/reference/privateNameStaticFieldAccess.errors.txt new file mode 100644 index 0000000000000..cc1659560febd --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAccess.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts(5,26): error TS2339: Property '#myField' does not exist on type 'A'. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts (1 errors) ==== + class A { + static #myField = "hello world"; + constructor() { + console.log(A.#myField); //Ok + console.log(this.#myField); //Error + ~~~~~~~~ +!!! error TS2339: Property '#myField' does not exist on type 'A'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticFieldAccess.js b/tests/baselines/reference/privateNameStaticFieldAccess.js new file mode 100644 index 0000000000000..9c6e297cea9a8 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAccess.js @@ -0,0 +1,25 @@ +//// [privateNameStaticFieldAccess.ts] +class A { + static #myField = "hello world"; + constructor() { + console.log(A.#myField); //Ok + console.log(this.#myField); //Error + } +} + + +//// [privateNameStaticFieldAccess.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A_myField; +class A { + constructor() { + console.log(__classPrivateFieldGet(A, _a, "f", _A_myField)); //Ok + console.log(__classPrivateFieldGet(this, _a, "f", _A_myField)); //Error + } +} +_a = A; +_A_myField = { value: "hello world" }; diff --git a/tests/baselines/reference/privateNameStaticFieldAccess.symbols b/tests/baselines/reference/privateNameStaticFieldAccess.symbols new file mode 100644 index 0000000000000..e7a6bee379ee2 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAccess.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldAccess.ts, 0, 0)) + + static #myField = "hello world"; +>#myField : Symbol(A.#myField, Decl(privateNameStaticFieldAccess.ts, 0, 9)) + + constructor() { + console.log(A.#myField); //Ok +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>A.#myField : Symbol(A.#myField, Decl(privateNameStaticFieldAccess.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAccess.ts, 0, 0)) + + console.log(this.#myField); //Error +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(A, Decl(privateNameStaticFieldAccess.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldAccess.types b/tests/baselines/reference/privateNameStaticFieldAccess.types new file mode 100644 index 0000000000000..4d549b845bc39 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAccess.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts === +class A { +>A : A + + static #myField = "hello world"; +>#myField : string +>"hello world" : "hello world" + + constructor() { + console.log(A.#myField); //Ok +>console.log(A.#myField) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>A.#myField : string +>A : typeof A + + console.log(this.#myField); //Error +>console.log(this.#myField) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#myField : any +>this : this + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldAssignment.js b/tests/baselines/reference/privateNameStaticFieldAssignment.js new file mode 100644 index 0000000000000..9cb2ddab90a58 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAssignment.js @@ -0,0 +1,86 @@ +//// [privateNameStaticFieldAssignment.ts] +class A { + static #field = 0; + constructor() { + A.#field = 1; + A.#field += 2; + A.#field -= 3; + A.#field /= 4; + A.#field *= 5; + A.#field **= 6; + A.#field %= 7; + A.#field <<= 8; + A.#field >>= 9; + A.#field >>>= 10; + A.#field &= 11; + A.#field |= 12; + A.#field ^= 13; + A.getClass().#field = 1; + A.getClass().#field += 2; + A.getClass().#field -= 3; + A.getClass().#field /= 4; + A.getClass().#field *= 5; + A.getClass().#field **= 6; + A.getClass().#field %= 7; + A.getClass().#field <<= 8; + A.getClass().#field >>= 9; + A.getClass().#field >>>= 10; + A.getClass().#field &= 11; + A.getClass().#field |= 12; + A.getClass().#field ^= 13; + } + static getClass() { + return A; + } +} + + +//// [privateNameStaticFieldAssignment.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A_field; +class A { + constructor() { + var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; + __classPrivateFieldSet(A, _a, 1, "f", _A_field); + __classPrivateFieldSet(_b = A, _a, __classPrivateFieldGet(_b, _a, "f", _A_field) + 2, "f", _A_field); + __classPrivateFieldSet(_c = A, _a, __classPrivateFieldGet(_c, _a, "f", _A_field) - 3, "f", _A_field); + __classPrivateFieldSet(_d = A, _a, __classPrivateFieldGet(_d, _a, "f", _A_field) / 4, "f", _A_field); + __classPrivateFieldSet(_e = A, _a, __classPrivateFieldGet(_e, _a, "f", _A_field) * 5, "f", _A_field); + __classPrivateFieldSet(_f = A, _a, Math.pow(__classPrivateFieldGet(_f, _a, "f", _A_field), 6), "f", _A_field); + __classPrivateFieldSet(_g = A, _a, __classPrivateFieldGet(_g, _a, "f", _A_field) % 7, "f", _A_field); + __classPrivateFieldSet(_h = A, _a, __classPrivateFieldGet(_h, _a, "f", _A_field) << 8, "f", _A_field); + __classPrivateFieldSet(_j = A, _a, __classPrivateFieldGet(_j, _a, "f", _A_field) >> 9, "f", _A_field); + __classPrivateFieldSet(_k = A, _a, __classPrivateFieldGet(_k, _a, "f", _A_field) >>> 10, "f", _A_field); + __classPrivateFieldSet(_l = A, _a, __classPrivateFieldGet(_l, _a, "f", _A_field) & 11, "f", _A_field); + __classPrivateFieldSet(_m = A, _a, __classPrivateFieldGet(_m, _a, "f", _A_field) | 12, "f", _A_field); + __classPrivateFieldSet(_o = A, _a, __classPrivateFieldGet(_o, _a, "f", _A_field) ^ 13, "f", _A_field); + __classPrivateFieldSet(A.getClass(), _a, 1, "f", _A_field); + __classPrivateFieldSet(_p = A.getClass(), _a, __classPrivateFieldGet(_p, _a, "f", _A_field) + 2, "f", _A_field); + __classPrivateFieldSet(_q = A.getClass(), _a, __classPrivateFieldGet(_q, _a, "f", _A_field) - 3, "f", _A_field); + __classPrivateFieldSet(_r = A.getClass(), _a, __classPrivateFieldGet(_r, _a, "f", _A_field) / 4, "f", _A_field); + __classPrivateFieldSet(_s = A.getClass(), _a, __classPrivateFieldGet(_s, _a, "f", _A_field) * 5, "f", _A_field); + __classPrivateFieldSet(_t = A.getClass(), _a, Math.pow(__classPrivateFieldGet(_t, _a, "f", _A_field), 6), "f", _A_field); + __classPrivateFieldSet(_u = A.getClass(), _a, __classPrivateFieldGet(_u, _a, "f", _A_field) % 7, "f", _A_field); + __classPrivateFieldSet(_v = A.getClass(), _a, __classPrivateFieldGet(_v, _a, "f", _A_field) << 8, "f", _A_field); + __classPrivateFieldSet(_w = A.getClass(), _a, __classPrivateFieldGet(_w, _a, "f", _A_field) >> 9, "f", _A_field); + __classPrivateFieldSet(_x = A.getClass(), _a, __classPrivateFieldGet(_x, _a, "f", _A_field) >>> 10, "f", _A_field); + __classPrivateFieldSet(_y = A.getClass(), _a, __classPrivateFieldGet(_y, _a, "f", _A_field) & 11, "f", _A_field); + __classPrivateFieldSet(_z = A.getClass(), _a, __classPrivateFieldGet(_z, _a, "f", _A_field) | 12, "f", _A_field); + __classPrivateFieldSet(_0 = A.getClass(), _a, __classPrivateFieldGet(_0, _a, "f", _A_field) ^ 13, "f", _A_field); + } + static getClass() { + return A; + } +} +_a = A; +_A_field = { value: 0 }; diff --git a/tests/baselines/reference/privateNameStaticFieldAssignment.symbols b/tests/baselines/reference/privateNameStaticFieldAssignment.symbols new file mode 100644 index 0000000000000..1d11fc0aa603d --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAssignment.symbols @@ -0,0 +1,146 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAssignment.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + static #field = 0; +>#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) + + constructor() { + A.#field = 1; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field += 2; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field -= 3; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field /= 4; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field *= 5; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field **= 6; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field %= 7; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field <<= 8; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field >>= 9; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field >>>= 10; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field &= 11; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field |= 12; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.#field ^= 13; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + + A.getClass().#field = 1; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field += 2; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field -= 3; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field /= 4; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field *= 5; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field **= 6; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field %= 7; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field <<= 8; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field >>= 9; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field >>>= 10; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field &= 11; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field |= 12; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + A.getClass().#field ^= 13; +>A.getClass().#field : Symbol(A.#field, Decl(privateNameStaticFieldAssignment.ts, 0, 9)) +>A.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + } + static getClass() { +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldAssignment.ts, 29, 5)) + + return A; +>A : Symbol(A, Decl(privateNameStaticFieldAssignment.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldAssignment.types b/tests/baselines/reference/privateNameStaticFieldAssignment.types new file mode 100644 index 0000000000000..679df4ca7f352 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldAssignment.types @@ -0,0 +1,212 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAssignment.ts === +class A { +>A : A + + static #field = 0; +>#field : number +>0 : 0 + + constructor() { + A.#field = 1; +>A.#field = 1 : 1 +>A.#field : number +>A : typeof A +>1 : 1 + + A.#field += 2; +>A.#field += 2 : number +>A.#field : number +>A : typeof A +>2 : 2 + + A.#field -= 3; +>A.#field -= 3 : number +>A.#field : number +>A : typeof A +>3 : 3 + + A.#field /= 4; +>A.#field /= 4 : number +>A.#field : number +>A : typeof A +>4 : 4 + + A.#field *= 5; +>A.#field *= 5 : number +>A.#field : number +>A : typeof A +>5 : 5 + + A.#field **= 6; +>A.#field **= 6 : number +>A.#field : number +>A : typeof A +>6 : 6 + + A.#field %= 7; +>A.#field %= 7 : number +>A.#field : number +>A : typeof A +>7 : 7 + + A.#field <<= 8; +>A.#field <<= 8 : number +>A.#field : number +>A : typeof A +>8 : 8 + + A.#field >>= 9; +>A.#field >>= 9 : number +>A.#field : number +>A : typeof A +>9 : 9 + + A.#field >>>= 10; +>A.#field >>>= 10 : number +>A.#field : number +>A : typeof A +>10 : 10 + + A.#field &= 11; +>A.#field &= 11 : number +>A.#field : number +>A : typeof A +>11 : 11 + + A.#field |= 12; +>A.#field |= 12 : number +>A.#field : number +>A : typeof A +>12 : 12 + + A.#field ^= 13; +>A.#field ^= 13 : number +>A.#field : number +>A : typeof A +>13 : 13 + + A.getClass().#field = 1; +>A.getClass().#field = 1 : 1 +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>1 : 1 + + A.getClass().#field += 2; +>A.getClass().#field += 2 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>2 : 2 + + A.getClass().#field -= 3; +>A.getClass().#field -= 3 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>3 : 3 + + A.getClass().#field /= 4; +>A.getClass().#field /= 4 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>4 : 4 + + A.getClass().#field *= 5; +>A.getClass().#field *= 5 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>5 : 5 + + A.getClass().#field **= 6; +>A.getClass().#field **= 6 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>6 : 6 + + A.getClass().#field %= 7; +>A.getClass().#field %= 7 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>7 : 7 + + A.getClass().#field <<= 8; +>A.getClass().#field <<= 8 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>8 : 8 + + A.getClass().#field >>= 9; +>A.getClass().#field >>= 9 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>9 : 9 + + A.getClass().#field >>>= 10; +>A.getClass().#field >>>= 10 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>10 : 10 + + A.getClass().#field &= 11; +>A.getClass().#field &= 11 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>11 : 11 + + A.getClass().#field |= 12; +>A.getClass().#field |= 12 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>12 : 12 + + A.getClass().#field ^= 13; +>A.getClass().#field ^= 13 : number +>A.getClass().#field : number +>A.getClass() : typeof A +>A.getClass : () => typeof A +>A : typeof A +>getClass : () => typeof A +>13 : 13 + } + static getClass() { +>getClass : () => typeof A + + return A; +>A : typeof A + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldCallExpression.js b/tests/baselines/reference/privateNameStaticFieldCallExpression.js new file mode 100644 index 0000000000000..e2c00c8905510 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldCallExpression.js @@ -0,0 +1,52 @@ +//// [privateNameStaticFieldCallExpression.ts] +class A { + static #fieldFunc = function () { this.x = 10; }; + static #fieldFunc2 = function (a, ...b) {}; + x = 1; + test() { + A.#fieldFunc(); + A.#fieldFunc?.(); + const func = A.#fieldFunc; + func(); + new A.#fieldFunc(); + + const arr = [ 1, 2 ]; + A.#fieldFunc2(0, ...arr, 3); + const b = new A.#fieldFunc2(0, ...arr, 3); + const str = A.#fieldFunc2`head${1}middle${2}tail`; + this.getClass().#fieldFunc2`test${1}and${2}`; + } + getClass() { return A; } +} + + +//// [privateNameStaticFieldCallExpression.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A_fieldFunc, _A_fieldFunc2; +class A { + constructor() { + this.x = 1; + } + test() { + var _b; + var _c; + __classPrivateFieldGet(A, _a, "f", _A_fieldFunc).call(A); + (_b = __classPrivateFieldGet(A, _a, "f", _A_fieldFunc)) === null || _b === void 0 ? void 0 : _b.call(A); + const func = __classPrivateFieldGet(A, _a, "f", _A_fieldFunc); + func(); + new (__classPrivateFieldGet(A, _a, "f", _A_fieldFunc))(); + const arr = [1, 2]; + __classPrivateFieldGet(A, _a, "f", _A_fieldFunc2).call(A, 0, ...arr, 3); + const b = new (__classPrivateFieldGet(A, _a, "f", _A_fieldFunc2))(0, ...arr, 3); + const str = __classPrivateFieldGet(A, _a, "f", _A_fieldFunc2).bind(A) `head${1}middle${2}tail`; + __classPrivateFieldGet((_c = this.getClass()), _a, "f", _A_fieldFunc2).bind(_c) `test${1}and${2}`; + } + getClass() { return A; } +} +_a = A; +_A_fieldFunc = { value: function () { this.x = 10; } }; +_A_fieldFunc2 = { value: function (a, ...b) { } }; diff --git a/tests/baselines/reference/privateNameStaticFieldCallExpression.symbols b/tests/baselines/reference/privateNameStaticFieldCallExpression.symbols new file mode 100644 index 0000000000000..955ab2080b884 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldCallExpression.symbols @@ -0,0 +1,68 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldCallExpression.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) + + static #fieldFunc = function () { this.x = 10; }; +>#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticFieldCallExpression.ts, 0, 9)) + + static #fieldFunc2 = function (a, ...b) {}; +>#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticFieldCallExpression.ts, 1, 53)) +>a : Symbol(a, Decl(privateNameStaticFieldCallExpression.ts, 2, 35)) +>b : Symbol(b, Decl(privateNameStaticFieldCallExpression.ts, 2, 37)) + + x = 1; +>x : Symbol(A.x, Decl(privateNameStaticFieldCallExpression.ts, 2, 47)) + + test() { +>test : Symbol(A.test, Decl(privateNameStaticFieldCallExpression.ts, 3, 10)) + + A.#fieldFunc(); +>A.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticFieldCallExpression.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) + + A.#fieldFunc?.(); +>A.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticFieldCallExpression.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) + + const func = A.#fieldFunc; +>func : Symbol(func, Decl(privateNameStaticFieldCallExpression.ts, 7, 13)) +>A.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticFieldCallExpression.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) + + func(); +>func : Symbol(func, Decl(privateNameStaticFieldCallExpression.ts, 7, 13)) + + new A.#fieldFunc(); +>A.#fieldFunc : Symbol(A.#fieldFunc, Decl(privateNameStaticFieldCallExpression.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) + + const arr = [ 1, 2 ]; +>arr : Symbol(arr, Decl(privateNameStaticFieldCallExpression.ts, 11, 13)) + + A.#fieldFunc2(0, ...arr, 3); +>A.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticFieldCallExpression.ts, 1, 53)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameStaticFieldCallExpression.ts, 11, 13)) + + const b = new A.#fieldFunc2(0, ...arr, 3); +>b : Symbol(b, Decl(privateNameStaticFieldCallExpression.ts, 13, 13)) +>A.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticFieldCallExpression.ts, 1, 53)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameStaticFieldCallExpression.ts, 11, 13)) + + const str = A.#fieldFunc2`head${1}middle${2}tail`; +>str : Symbol(str, Decl(privateNameStaticFieldCallExpression.ts, 14, 13)) +>A.#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticFieldCallExpression.ts, 1, 53)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) + + this.getClass().#fieldFunc2`test${1}and${2}`; +>this.getClass().#fieldFunc2 : Symbol(A.#fieldFunc2, Decl(privateNameStaticFieldCallExpression.ts, 1, 53)) +>this.getClass : Symbol(A.getClass, Decl(privateNameStaticFieldCallExpression.ts, 16, 5)) +>this : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldCallExpression.ts, 16, 5)) + } + getClass() { return A; } +>getClass : Symbol(A.getClass, Decl(privateNameStaticFieldCallExpression.ts, 16, 5)) +>A : Symbol(A, Decl(privateNameStaticFieldCallExpression.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/privateNameStaticFieldCallExpression.types b/tests/baselines/reference/privateNameStaticFieldCallExpression.types new file mode 100644 index 0000000000000..45b26b4edd688 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldCallExpression.types @@ -0,0 +1,100 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldCallExpression.ts === +class A { +>A : A + + static #fieldFunc = function () { this.x = 10; }; +>#fieldFunc : () => void +>function () { this.x = 10; } : () => void +>this.x = 10 : 10 +>this.x : any +>this : any +>x : any +>10 : 10 + + static #fieldFunc2 = function (a, ...b) {}; +>#fieldFunc2 : (a: any, ...b: any[]) => void +>function (a, ...b) {} : (a: any, ...b: any[]) => void +>a : any +>b : any[] + + x = 1; +>x : number +>1 : 1 + + test() { +>test : () => void + + A.#fieldFunc(); +>A.#fieldFunc() : void +>A.#fieldFunc : () => void +>A : typeof A + + A.#fieldFunc?.(); +>A.#fieldFunc?.() : void +>A.#fieldFunc : () => void +>A : typeof A + + const func = A.#fieldFunc; +>func : () => void +>A.#fieldFunc : () => void +>A : typeof A + + func(); +>func() : void +>func : () => void + + new A.#fieldFunc(); +>new A.#fieldFunc() : any +>A.#fieldFunc : () => void +>A : typeof A + + const arr = [ 1, 2 ]; +>arr : number[] +>[ 1, 2 ] : number[] +>1 : 1 +>2 : 2 + + A.#fieldFunc2(0, ...arr, 3); +>A.#fieldFunc2(0, ...arr, 3) : void +>A.#fieldFunc2 : (a: any, ...b: any[]) => void +>A : typeof A +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b = new A.#fieldFunc2(0, ...arr, 3); +>b : any +>new A.#fieldFunc2(0, ...arr, 3) : any +>A.#fieldFunc2 : (a: any, ...b: any[]) => void +>A : typeof A +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str = A.#fieldFunc2`head${1}middle${2}tail`; +>str : void +>A.#fieldFunc2`head${1}middle${2}tail` : void +>A.#fieldFunc2 : (a: any, ...b: any[]) => void +>A : typeof A +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + + this.getClass().#fieldFunc2`test${1}and${2}`; +>this.getClass().#fieldFunc2`test${1}and${2}` : void +>this.getClass().#fieldFunc2 : (a: any, ...b: any[]) => void +>this.getClass() : typeof A +>this.getClass : () => typeof A +>this : this +>getClass : () => typeof A +>`test${1}and${2}` : string +>1 : 1 +>2 : 2 + } + getClass() { return A; } +>getClass : () => typeof A +>A : typeof A +} + diff --git a/tests/baselines/reference/privateNameStaticFieldClassExpression.js b/tests/baselines/reference/privateNameStaticFieldClassExpression.js new file mode 100644 index 0000000000000..7b159cdaebed2 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldClassExpression.js @@ -0,0 +1,52 @@ +//// [privateNameStaticFieldClassExpression.ts] +class B { + static #foo = class { + constructor() { + console.log("hello"); + new B.#foo2(); + } + static test = 123; + field = 10; + }; + static #foo2 = class Foo { + static otherClass = 123; + }; + + m() { + console.log(B.#foo.test) + B.#foo.test = 10; + new B.#foo().field; + } +} + + + + +//// [privateNameStaticFieldClassExpression.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _B_foo, _B_foo2, _b, _c; +class B { + m() { + console.log(__classPrivateFieldGet(B, _a, "f", _B_foo).test); + __classPrivateFieldGet(B, _a, "f", _B_foo).test = 10; + new (__classPrivateFieldGet(B, _a, "f", _B_foo))().field; + } +} +_a = B; +_B_foo = { value: (_b = class { + constructor() { + this.field = 10; + console.log("hello"); + new (__classPrivateFieldGet(B, _a, "f", _B_foo2))(); + } + }, + _b.test = 123, + _b) }; +_B_foo2 = { value: (_c = class Foo { + }, + _c.otherClass = 123, + _c) }; diff --git a/tests/baselines/reference/privateNameStaticFieldClassExpression.symbols b/tests/baselines/reference/privateNameStaticFieldClassExpression.symbols new file mode 100644 index 0000000000000..f6bee58f5f494 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldClassExpression.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldClassExpression.ts === +class B { +>B : Symbol(B, Decl(privateNameStaticFieldClassExpression.ts, 0, 0)) + + static #foo = class { +>#foo : Symbol(B.#foo, Decl(privateNameStaticFieldClassExpression.ts, 0, 9)) + + constructor() { + console.log("hello"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + + new B.#foo2(); +>B.#foo2 : Symbol(B.#foo2, Decl(privateNameStaticFieldClassExpression.ts, 8, 6)) +>B : Symbol(B, Decl(privateNameStaticFieldClassExpression.ts, 0, 0)) + } + static test = 123; +>test : Symbol((Anonymous class).test, Decl(privateNameStaticFieldClassExpression.ts, 5, 9)) + + field = 10; +>field : Symbol((Anonymous class).field, Decl(privateNameStaticFieldClassExpression.ts, 6, 26)) + + }; + static #foo2 = class Foo { +>#foo2 : Symbol(B.#foo2, Decl(privateNameStaticFieldClassExpression.ts, 8, 6)) +>Foo : Symbol(Foo, Decl(privateNameStaticFieldClassExpression.ts, 9, 18)) + + static otherClass = 123; +>otherClass : Symbol(Foo.otherClass, Decl(privateNameStaticFieldClassExpression.ts, 9, 30)) + + }; + + m() { +>m : Symbol(B.m, Decl(privateNameStaticFieldClassExpression.ts, 11, 6)) + + console.log(B.#foo.test) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>B.#foo.test : Symbol((Anonymous class).test, Decl(privateNameStaticFieldClassExpression.ts, 5, 9)) +>B.#foo : Symbol(B.#foo, Decl(privateNameStaticFieldClassExpression.ts, 0, 9)) +>B : Symbol(B, Decl(privateNameStaticFieldClassExpression.ts, 0, 0)) +>test : Symbol((Anonymous class).test, Decl(privateNameStaticFieldClassExpression.ts, 5, 9)) + + B.#foo.test = 10; +>B.#foo.test : Symbol((Anonymous class).test, Decl(privateNameStaticFieldClassExpression.ts, 5, 9)) +>B.#foo : Symbol(B.#foo, Decl(privateNameStaticFieldClassExpression.ts, 0, 9)) +>B : Symbol(B, Decl(privateNameStaticFieldClassExpression.ts, 0, 0)) +>test : Symbol((Anonymous class).test, Decl(privateNameStaticFieldClassExpression.ts, 5, 9)) + + new B.#foo().field; +>new B.#foo().field : Symbol((Anonymous class).field, Decl(privateNameStaticFieldClassExpression.ts, 6, 26)) +>B.#foo : Symbol(B.#foo, Decl(privateNameStaticFieldClassExpression.ts, 0, 9)) +>B : Symbol(B, Decl(privateNameStaticFieldClassExpression.ts, 0, 0)) +>field : Symbol((Anonymous class).field, Decl(privateNameStaticFieldClassExpression.ts, 6, 26)) + } +} + + + diff --git a/tests/baselines/reference/privateNameStaticFieldClassExpression.types b/tests/baselines/reference/privateNameStaticFieldClassExpression.types new file mode 100644 index 0000000000000..31ca3abe90f6a --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldClassExpression.types @@ -0,0 +1,73 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldClassExpression.ts === +class B { +>B : B + + static #foo = class { +>#foo : typeof (Anonymous class) +>class { constructor() { console.log("hello"); new B.#foo2(); } static test = 123; field = 10; } : typeof (Anonymous class) + + constructor() { + console.log("hello"); +>console.log("hello") : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>"hello" : "hello" + + new B.#foo2(); +>new B.#foo2() : Foo +>B.#foo2 : typeof Foo +>B : typeof B + } + static test = 123; +>test : number +>123 : 123 + + field = 10; +>field : number +>10 : 10 + + }; + static #foo2 = class Foo { +>#foo2 : typeof Foo +>class Foo { static otherClass = 123; } : typeof Foo +>Foo : typeof Foo + + static otherClass = 123; +>otherClass : number +>123 : 123 + + }; + + m() { +>m : () => void + + console.log(B.#foo.test) +>console.log(B.#foo.test) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>B.#foo.test : number +>B.#foo : typeof (Anonymous class) +>B : typeof B +>test : number + + B.#foo.test = 10; +>B.#foo.test = 10 : 10 +>B.#foo.test : number +>B.#foo : typeof (Anonymous class) +>B : typeof B +>test : number +>10 : 10 + + new B.#foo().field; +>new B.#foo().field : number +>new B.#foo() : (Anonymous class) +>B.#foo : typeof (Anonymous class) +>B : typeof B +>field : number + } +} + + + diff --git a/tests/baselines/reference/privateNameStaticFieldDerivedClasses.errors.txt b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.errors.txt new file mode 100644 index 0000000000000..8e845cdbcaee3 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts(4,17): error TS18013: Property '#derivedProp' is not accessible outside class 'Derived' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts(12,14): error TS18013: Property '#prop' is not accessible outside class 'Base' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts (2 errors) ==== + class Base { + static #prop: number = 123; + static method(x: Derived) { + Derived.#derivedProp // error + ~~~~~~~~~~~~ +!!! error TS18013: Property '#derivedProp' is not accessible outside class 'Derived' because it has a private identifier. + Base.#prop = 10; + } + } + class Derived extends Base { + static #derivedProp: number = 10; + static method(x: Derived) { + Derived.#derivedProp + Base.#prop = 10; // error + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'Base' because it has a private identifier. + } + } + + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticFieldDerivedClasses.js b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.js new file mode 100644 index 0000000000000..1b4dd4babb1c4 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.js @@ -0,0 +1,47 @@ +//// [privateNameStaticFieldDerivedClasses.ts] +class Base { + static #prop: number = 123; + static method(x: Derived) { + Derived.#derivedProp // error + Base.#prop = 10; + } +} +class Derived extends Base { + static #derivedProp: number = 10; + static method(x: Derived) { + Derived.#derivedProp + Base.#prop = 10; // error + } +} + + + +//// [privateNameStaticFieldDerivedClasses.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _Base_prop, _b, _Derived_derivedProp; +class Base { + static method(x) { + Derived.; // error + __classPrivateFieldSet(Base, _a, 10, "f", _Base_prop); + } +} +_a = Base; +_Base_prop = { value: 123 }; +class Derived extends Base { + static method(x) { + __classPrivateFieldGet(Derived, _b, "f", _Derived_derivedProp); + Base. = 10; // error + } +} +_b = Derived; +_Derived_derivedProp = { value: 10 }; diff --git a/tests/baselines/reference/privateNameStaticFieldDerivedClasses.symbols b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.symbols new file mode 100644 index 0000000000000..44da6b8ecaddd --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts === +class Base { +>Base : Symbol(Base, Decl(privateNameStaticFieldDerivedClasses.ts, 0, 0)) + + static #prop: number = 123; +>#prop : Symbol(Base.#prop, Decl(privateNameStaticFieldDerivedClasses.ts, 0, 12)) + + static method(x: Derived) { +>method : Symbol(Base.method, Decl(privateNameStaticFieldDerivedClasses.ts, 1, 31)) +>x : Symbol(x, Decl(privateNameStaticFieldDerivedClasses.ts, 2, 18)) +>Derived : Symbol(Derived, Decl(privateNameStaticFieldDerivedClasses.ts, 6, 1)) + + Derived.#derivedProp // error +>Derived : Symbol(Derived, Decl(privateNameStaticFieldDerivedClasses.ts, 6, 1)) + + Base.#prop = 10; +>Base.#prop : Symbol(Base.#prop, Decl(privateNameStaticFieldDerivedClasses.ts, 0, 12)) +>Base : Symbol(Base, Decl(privateNameStaticFieldDerivedClasses.ts, 0, 0)) + } +} +class Derived extends Base { +>Derived : Symbol(Derived, Decl(privateNameStaticFieldDerivedClasses.ts, 6, 1)) +>Base : Symbol(Base, Decl(privateNameStaticFieldDerivedClasses.ts, 0, 0)) + + static #derivedProp: number = 10; +>#derivedProp : Symbol(Derived.#derivedProp, Decl(privateNameStaticFieldDerivedClasses.ts, 7, 28)) + + static method(x: Derived) { +>method : Symbol(Derived.method, Decl(privateNameStaticFieldDerivedClasses.ts, 8, 37)) +>x : Symbol(x, Decl(privateNameStaticFieldDerivedClasses.ts, 9, 18)) +>Derived : Symbol(Derived, Decl(privateNameStaticFieldDerivedClasses.ts, 6, 1)) + + Derived.#derivedProp +>Derived.#derivedProp : Symbol(Derived.#derivedProp, Decl(privateNameStaticFieldDerivedClasses.ts, 7, 28)) +>Derived : Symbol(Derived, Decl(privateNameStaticFieldDerivedClasses.ts, 6, 1)) + + Base.#prop = 10; // error +>Base : Symbol(Base, Decl(privateNameStaticFieldDerivedClasses.ts, 0, 0)) + } +} + + diff --git a/tests/baselines/reference/privateNameStaticFieldDerivedClasses.types b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.types new file mode 100644 index 0000000000000..8db01be0a072b --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDerivedClasses.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts === +class Base { +>Base : Base + + static #prop: number = 123; +>#prop : number +>123 : 123 + + static method(x: Derived) { +>method : (x: Derived) => void +>x : Derived + + Derived.#derivedProp // error +>Derived.#derivedProp : any +>Derived : typeof Derived + + Base.#prop = 10; +>Base.#prop = 10 : 10 +>Base.#prop : number +>Base : typeof Base +>10 : 10 + } +} +class Derived extends Base { +>Derived : Derived +>Base : Base + + static #derivedProp: number = 10; +>#derivedProp : number +>10 : 10 + + static method(x: Derived) { +>method : (x: Derived) => void +>x : Derived + + Derived.#derivedProp +>Derived.#derivedProp : number +>Derived : typeof Derived + + Base.#prop = 10; // error +>Base.#prop = 10 : 10 +>Base.#prop : any +>Base : typeof Base +>10 : 10 + } +} + + diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js new file mode 100644 index 0000000000000..f5ddbe3a7856a --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).js @@ -0,0 +1,59 @@ +//// [privateNameStaticFieldDestructuredBinding.ts] +class A { + static #field = 1; + otherClass = A; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } + constructor() { + let y: number; + ({ x: A.#field, y } = this.testObject()); + ([A.#field, y] = this.testArray()); + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); + [A.#field, [A.#field]] = [1, [2]]; + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); + [A.#field = 2] = []; + [this.otherClass.#field = 2] = []; + } + static test(_a: typeof A) { + [_a.#field] = [2]; + } +} + + +//// [privateNameStaticFieldDestructuredBinding.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var _b, _A_field; +class A { + constructor() { + var _c; + this.otherClass = A; + let y; + ({ x: ({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value, y } = this.testObject()); + ([({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value, y] = this.testArray()); + ({ a: ({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value, b: [({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value] } = { a: 1, b: [2] }); + [({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value, [({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value]] = [1, [2]]; + ({ a: ({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value = 1, b: [({ set value(_b) { __classPrivateFieldSet(A, _b, _b, "f", _A_field); } }).value = 1] } = { b: [] }); + [({ 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]; + } +} +_b = A; +_A_field = { value: 1 }; diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).symbols b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).symbols new file mode 100644 index 0000000000000..a539e6833531e --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + static #field = 1; +>#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) + + otherClass = A; +>otherClass : Symbol(A.otherClass, Decl(privateNameStaticFieldDestructuredBinding.ts, 1, 22)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + testObject() { +>testObject : Symbol(A.testObject, Decl(privateNameStaticFieldDestructuredBinding.ts, 2, 19)) + + return { x: 10, y: 6 }; +>x : Symbol(x, Decl(privateNameStaticFieldDestructuredBinding.ts, 4, 16)) +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 4, 23)) + } + testArray() { +>testArray : Symbol(A.testArray, Decl(privateNameStaticFieldDestructuredBinding.ts, 5, 5)) + + return [10, 11]; + } + constructor() { + let y: number; +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 10, 11)) + + ({ x: A.#field, y } = this.testObject()); +>x : Symbol(x, Decl(privateNameStaticFieldDestructuredBinding.ts, 11, 10)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 11, 23)) +>this.testObject : Symbol(A.testObject, Decl(privateNameStaticFieldDestructuredBinding.ts, 2, 19)) +>this : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>testObject : Symbol(A.testObject, Decl(privateNameStaticFieldDestructuredBinding.ts, 2, 19)) + + ([A.#field, y] = this.testArray()); +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 10, 11)) +>this.testArray : Symbol(A.testArray, Decl(privateNameStaticFieldDestructuredBinding.ts, 5, 5)) +>this : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>testArray : Symbol(A.testArray, Decl(privateNameStaticFieldDestructuredBinding.ts, 5, 5)) + + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); +>a : Symbol(a, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 10)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 23)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>a : Symbol(a, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 43)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 49)) + + [A.#field, [A.#field]] = [1, [2]]; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); +>a : Symbol(a, Decl(privateNameStaticFieldDestructuredBinding.ts, 15, 10)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 15, 27)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 15, 51)) + + [A.#field = 2] = []; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + [this.otherClass.#field = 2] = []; +>this.otherClass.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>this.otherClass : Symbol(A.otherClass, Decl(privateNameStaticFieldDestructuredBinding.ts, 1, 22)) +>this : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>otherClass : Symbol(A.otherClass, Decl(privateNameStaticFieldDestructuredBinding.ts, 1, 22)) + } + static test(_a: typeof A) { +>test : Symbol(A.test, Decl(privateNameStaticFieldDestructuredBinding.ts, 18, 5)) +>_a : Symbol(_a, Decl(privateNameStaticFieldDestructuredBinding.ts, 19, 16)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + [_a.#field] = [2]; +>_a.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>_a : Symbol(_a, Decl(privateNameStaticFieldDestructuredBinding.ts, 19, 16)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).types b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).types new file mode 100644 index 0000000000000..ef8a216bdb295 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=es2015).types @@ -0,0 +1,144 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts === +class A { +>A : A + + static #field = 1; +>#field : number +>1 : 1 + + otherClass = A; +>otherClass : typeof A +>A : typeof A + + testObject() { +>testObject : () => { x: number; y: number; } + + return { x: 10, y: 6 }; +>{ x: 10, y: 6 } : { x: number; y: number; } +>x : number +>10 : 10 +>y : number +>6 : 6 + } + testArray() { +>testArray : () => number[] + + return [10, 11]; +>[10, 11] : number[] +>10 : 10 +>11 : 11 + } + constructor() { + let y: number; +>y : number + + ({ x: A.#field, y } = this.testObject()); +>({ x: A.#field, y } = this.testObject()) : { x: number; y: number; } +>{ x: A.#field, y } = this.testObject() : { x: number; y: number; } +>{ x: A.#field, y } : { x: number; y: number; } +>x : number +>A.#field : number +>A : typeof A +>y : number +>this.testObject() : { x: number; y: number; } +>this.testObject : () => { x: number; y: number; } +>this : this +>testObject : () => { x: number; y: number; } + + ([A.#field, y] = this.testArray()); +>([A.#field, y] = this.testArray()) : number[] +>[A.#field, y] = this.testArray() : number[] +>[A.#field, y] : [number, number] +>A.#field : number +>A : typeof A +>y : number +>this.testArray() : number[] +>this.testArray : () => number[] +>this : this +>testArray : () => number[] + + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); +>({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }) : { a: number; b: [number]; } +>{ a: A.#field, b: [A.#field] } = { a: 1, b: [2] } : { a: number; b: [number]; } +>{ a: A.#field, b: [A.#field] } : { a: number; b: [number]; } +>a : number +>A.#field : number +>A : typeof A +>b : [number] +>[A.#field] : [number] +>A.#field : number +>A : typeof A +>{ a: 1, b: [2] } : { a: number; b: [number]; } +>a : number +>1 : 1 +>b : [number] +>[2] : [number] +>2 : 2 + + [A.#field, [A.#field]] = [1, [2]]; +>[A.#field, [A.#field]] = [1, [2]] : [number, [number]] +>[A.#field, [A.#field]] : [number, [number]] +>A.#field : number +>A : typeof A +>[A.#field] : [number] +>A.#field : number +>A : typeof A +>[1, [2]] : [number, [number]] +>1 : 1 +>[2] : [number] +>2 : 2 + + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); +>({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }) : { b: []; a?: number; } +>{ a: A.#field = 1, b: [A.#field = 1] } = { b: [] } : { b: []; a?: number; } +>{ a: A.#field = 1, b: [A.#field = 1] } : { a?: number; b: [number]; } +>a : number +>A.#field = 1 : 1 +>A.#field : number +>A : typeof A +>1 : 1 +>b : [number] +>[A.#field = 1] : [number] +>A.#field = 1 : 1 +>A.#field : number +>A : typeof A +>1 : 1 +>{ b: [] } : { b: []; a?: number; } +>b : [] +>[] : [] + + [A.#field = 2] = []; +>[A.#field = 2] = [] : [] +>[A.#field = 2] : [number] +>A.#field = 2 : 2 +>A.#field : number +>A : typeof A +>2 : 2 +>[] : [] + + [this.otherClass.#field = 2] = []; +>[this.otherClass.#field = 2] = [] : [] +>[this.otherClass.#field = 2] : [number] +>this.otherClass.#field = 2 : 2 +>this.otherClass.#field : number +>this.otherClass : typeof A +>this : this +>otherClass : typeof A +>2 : 2 +>[] : [] + } + static test(_a: typeof A) { +>test : (_a: typeof A) => void +>_a : typeof A +>A : typeof A + + [_a.#field] = [2]; +>[_a.#field] = [2] : [number] +>[_a.#field] : [number] +>_a.#field : number +>_a : typeof A +>[2] : [number] +>2 : 2 + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).errors.txt b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).errors.txt new file mode 100644 index 0000000000000..f0932d7ba51aa --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts(2,21): error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts (1 errors) ==== + class A { + static #field = 1; + ~ +!!! error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + otherClass = A; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } + constructor() { + let y: number; + ({ x: A.#field, y } = this.testObject()); + ([A.#field, y] = this.testArray()); + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); + [A.#field, [A.#field]] = [1, [2]]; + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); + [A.#field = 2] = []; + [this.otherClass.#field = 2] = []; + } + static test(_a: typeof A) { + [_a.#field] = [2]; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js new file mode 100644 index 0000000000000..bbaf5cd7601ab --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).js @@ -0,0 +1,51 @@ +//// [privateNameStaticFieldDestructuredBinding.ts] +class A { + static #field = 1; + otherClass = A; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } + constructor() { + let y: number; + ({ x: A.#field, y } = this.testObject()); + ([A.#field, y] = this.testArray()); + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); + [A.#field, [A.#field]] = [1, [2]]; + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); + [A.#field = 2] = []; + [this.otherClass.#field = 2] = []; + } + static test(_a: typeof A) { + [_a.#field] = [2]; + } +} + + +//// [privateNameStaticFieldDestructuredBinding.js] +class A { + constructor() { + this.otherClass = A; + let y; + ({ x: A.#field, y } = this.testObject()); + ([A.#field, y] = this.testArray()); + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); + [A.#field, [A.#field]] = [1, [2]]; + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); + [A.#field = 2] = []; + [this.otherClass.#field = 2] = []; + } + static #field; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } + static test(_a) { + [_a.#field] = [2]; + } +} +A.#field = 1; diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).symbols b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).symbols new file mode 100644 index 0000000000000..a539e6833531e --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + static #field = 1; +>#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) + + otherClass = A; +>otherClass : Symbol(A.otherClass, Decl(privateNameStaticFieldDestructuredBinding.ts, 1, 22)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + testObject() { +>testObject : Symbol(A.testObject, Decl(privateNameStaticFieldDestructuredBinding.ts, 2, 19)) + + return { x: 10, y: 6 }; +>x : Symbol(x, Decl(privateNameStaticFieldDestructuredBinding.ts, 4, 16)) +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 4, 23)) + } + testArray() { +>testArray : Symbol(A.testArray, Decl(privateNameStaticFieldDestructuredBinding.ts, 5, 5)) + + return [10, 11]; + } + constructor() { + let y: number; +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 10, 11)) + + ({ x: A.#field, y } = this.testObject()); +>x : Symbol(x, Decl(privateNameStaticFieldDestructuredBinding.ts, 11, 10)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 11, 23)) +>this.testObject : Symbol(A.testObject, Decl(privateNameStaticFieldDestructuredBinding.ts, 2, 19)) +>this : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>testObject : Symbol(A.testObject, Decl(privateNameStaticFieldDestructuredBinding.ts, 2, 19)) + + ([A.#field, y] = this.testArray()); +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>y : Symbol(y, Decl(privateNameStaticFieldDestructuredBinding.ts, 10, 11)) +>this.testArray : Symbol(A.testArray, Decl(privateNameStaticFieldDestructuredBinding.ts, 5, 5)) +>this : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>testArray : Symbol(A.testArray, Decl(privateNameStaticFieldDestructuredBinding.ts, 5, 5)) + + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); +>a : Symbol(a, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 10)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 23)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>a : Symbol(a, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 43)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 13, 49)) + + [A.#field, [A.#field]] = [1, [2]]; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); +>a : Symbol(a, Decl(privateNameStaticFieldDestructuredBinding.ts, 15, 10)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 15, 27)) +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticFieldDestructuredBinding.ts, 15, 51)) + + [A.#field = 2] = []; +>A.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + [this.otherClass.#field = 2] = []; +>this.otherClass.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>this.otherClass : Symbol(A.otherClass, Decl(privateNameStaticFieldDestructuredBinding.ts, 1, 22)) +>this : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) +>otherClass : Symbol(A.otherClass, Decl(privateNameStaticFieldDestructuredBinding.ts, 1, 22)) + } + static test(_a: typeof A) { +>test : Symbol(A.test, Decl(privateNameStaticFieldDestructuredBinding.ts, 18, 5)) +>_a : Symbol(_a, Decl(privateNameStaticFieldDestructuredBinding.ts, 19, 16)) +>A : Symbol(A, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 0)) + + [_a.#field] = [2]; +>_a.#field : Symbol(A.#field, Decl(privateNameStaticFieldDestructuredBinding.ts, 0, 9)) +>_a : Symbol(_a, Decl(privateNameStaticFieldDestructuredBinding.ts, 19, 16)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).types b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).types new file mode 100644 index 0000000000000..ef8a216bdb295 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldDestructuredBinding(target=esnext).types @@ -0,0 +1,144 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts === +class A { +>A : A + + static #field = 1; +>#field : number +>1 : 1 + + otherClass = A; +>otherClass : typeof A +>A : typeof A + + testObject() { +>testObject : () => { x: number; y: number; } + + return { x: 10, y: 6 }; +>{ x: 10, y: 6 } : { x: number; y: number; } +>x : number +>10 : 10 +>y : number +>6 : 6 + } + testArray() { +>testArray : () => number[] + + return [10, 11]; +>[10, 11] : number[] +>10 : 10 +>11 : 11 + } + constructor() { + let y: number; +>y : number + + ({ x: A.#field, y } = this.testObject()); +>({ x: A.#field, y } = this.testObject()) : { x: number; y: number; } +>{ x: A.#field, y } = this.testObject() : { x: number; y: number; } +>{ x: A.#field, y } : { x: number; y: number; } +>x : number +>A.#field : number +>A : typeof A +>y : number +>this.testObject() : { x: number; y: number; } +>this.testObject : () => { x: number; y: number; } +>this : this +>testObject : () => { x: number; y: number; } + + ([A.#field, y] = this.testArray()); +>([A.#field, y] = this.testArray()) : number[] +>[A.#field, y] = this.testArray() : number[] +>[A.#field, y] : [number, number] +>A.#field : number +>A : typeof A +>y : number +>this.testArray() : number[] +>this.testArray : () => number[] +>this : this +>testArray : () => number[] + + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); +>({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }) : { a: number; b: [number]; } +>{ a: A.#field, b: [A.#field] } = { a: 1, b: [2] } : { a: number; b: [number]; } +>{ a: A.#field, b: [A.#field] } : { a: number; b: [number]; } +>a : number +>A.#field : number +>A : typeof A +>b : [number] +>[A.#field] : [number] +>A.#field : number +>A : typeof A +>{ a: 1, b: [2] } : { a: number; b: [number]; } +>a : number +>1 : 1 +>b : [number] +>[2] : [number] +>2 : 2 + + [A.#field, [A.#field]] = [1, [2]]; +>[A.#field, [A.#field]] = [1, [2]] : [number, [number]] +>[A.#field, [A.#field]] : [number, [number]] +>A.#field : number +>A : typeof A +>[A.#field] : [number] +>A.#field : number +>A : typeof A +>[1, [2]] : [number, [number]] +>1 : 1 +>[2] : [number] +>2 : 2 + + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); +>({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }) : { b: []; a?: number; } +>{ a: A.#field = 1, b: [A.#field = 1] } = { b: [] } : { b: []; a?: number; } +>{ a: A.#field = 1, b: [A.#field = 1] } : { a?: number; b: [number]; } +>a : number +>A.#field = 1 : 1 +>A.#field : number +>A : typeof A +>1 : 1 +>b : [number] +>[A.#field = 1] : [number] +>A.#field = 1 : 1 +>A.#field : number +>A : typeof A +>1 : 1 +>{ b: [] } : { b: []; a?: number; } +>b : [] +>[] : [] + + [A.#field = 2] = []; +>[A.#field = 2] = [] : [] +>[A.#field = 2] : [number] +>A.#field = 2 : 2 +>A.#field : number +>A : typeof A +>2 : 2 +>[] : [] + + [this.otherClass.#field = 2] = []; +>[this.otherClass.#field = 2] = [] : [] +>[this.otherClass.#field = 2] : [number] +>this.otherClass.#field = 2 : 2 +>this.otherClass.#field : number +>this.otherClass : typeof A +>this : this +>otherClass : typeof A +>2 : 2 +>[] : [] + } + static test(_a: typeof A) { +>test : (_a: typeof A) => void +>_a : typeof A +>A : typeof A + + [_a.#field] = [2]; +>[_a.#field] = [2] : [number] +>[_a.#field] : [number] +>_a.#field : number +>_a : typeof A +>[2] : [number] +>2 : 2 + } +} + diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).js b/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).js new file mode 100644 index 0000000000000..a9da2fa9aa41b --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).js @@ -0,0 +1,14 @@ +//// [privateNameStaticFieldInitializer.ts] +class A { + static #field = 10; + static #uninitialized; +} + + +//// [privateNameStaticFieldInitializer.js] +var _a, _A_field, _A_uninitialized; +class A { +} +_a = A; +_A_field = { value: 10 }; +_A_uninitialized = { value: void 0 }; diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).symbols b/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).symbols new file mode 100644 index 0000000000000..d503ebe5086a4 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldInitializer.ts, 0, 0)) + + static #field = 10; +>#field : Symbol(A.#field, Decl(privateNameStaticFieldInitializer.ts, 0, 9)) + + static #uninitialized; +>#uninitialized : Symbol(A.#uninitialized, Decl(privateNameStaticFieldInitializer.ts, 1, 23)) +} + diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).types b/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).types new file mode 100644 index 0000000000000..d50c9a2533f0c --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=es2015).types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts === +class A { +>A : A + + static #field = 10; +>#field : number +>10 : 10 + + static #uninitialized; +>#uninitialized : any +} + diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).errors.txt b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).errors.txt new file mode 100644 index 0000000000000..13dc546e2dd96 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts(2,21): error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts (1 errors) ==== + class A { + static #field = 10; + ~~ +!!! error TS2805: Static fields with private names can't have initializers when the '--useDefineForClassFields' flag is not specified with a '--target' of 'esnext'. Consider adding the '--useDefineForClassFields' flag. + static #uninitialized; + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).js b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).js new file mode 100644 index 0000000000000..fddf56e1754c5 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).js @@ -0,0 +1,13 @@ +//// [privateNameStaticFieldInitializer.ts] +class A { + static #field = 10; + static #uninitialized; +} + + +//// [privateNameStaticFieldInitializer.js] +class A { + static #field; + static #uninitialized; +} +A.#field = 10; diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).symbols b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).symbols new file mode 100644 index 0000000000000..d503ebe5086a4 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticFieldInitializer.ts, 0, 0)) + + static #field = 10; +>#field : Symbol(A.#field, Decl(privateNameStaticFieldInitializer.ts, 0, 9)) + + static #uninitialized; +>#uninitialized : Symbol(A.#uninitialized, Decl(privateNameStaticFieldInitializer.ts, 1, 23)) +} + diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).types b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).types new file mode 100644 index 0000000000000..d50c9a2533f0c --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer(target=esnext).types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts === +class A { +>A : A + + static #field = 10; +>#field : number +>10 : 10 + + static #uninitialized; +>#uninitialized : any +} + diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer.js b/tests/baselines/reference/privateNameStaticFieldInitializer.js new file mode 100644 index 0000000000000..e0eff7b616ba5 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer.js @@ -0,0 +1,13 @@ +//// [privateNameFieldInitializer-static.ts] +class A { + static #field = 10; + static #uninitialized; +} + + +//// [privateNameFieldInitializer-static.js] +var _A_field, _A_uninitialized; +class A { +} +_A_field = { value: 10 }; +_A_uninitialized = { value: void 0 }; diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer.symbols b/tests/baselines/reference/privateNameStaticFieldInitializer.symbols new file mode 100644 index 0000000000000..a3bbabd600f76 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameFieldInitializer-static.ts === +class A { +>A : Symbol(A, Decl(privateNameFieldInitializer-static.ts, 0, 0)) + + static #field = 10; +>#field : Symbol(A.#field, Decl(privateNameFieldInitializer-static.ts, 0, 9)) + + static #uninitialized; +>#uninitialized : Symbol(A.#uninitialized, Decl(privateNameFieldInitializer-static.ts, 1, 23)) +} + diff --git a/tests/baselines/reference/privateNameStaticFieldInitializer.types b/tests/baselines/reference/privateNameStaticFieldInitializer.types new file mode 100644 index 0000000000000..dd134ee706593 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldInitializer.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameFieldInitializer-static.ts === +class A { +>A : A + + static #field = 10; +>#field : number +>10 : 10 + + static #uninitialized; +>#uninitialized : any +} + diff --git a/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).js b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).js new file mode 100644 index 0000000000000..a2caf1c9fd25f --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).js @@ -0,0 +1,19 @@ +//// [privateNameStaticFieldNoInitializer.ts] +const C = class { + static #x; +} + +class C2 { + static #x; +} + +//// [privateNameStaticFieldNoInitializer.js] +var _a, _C_x, _b, _C2_x; +const C = (_a = class { + }, + _C_x = { value: void 0 }, + _a); +class C2 { +} +_b = C2; +_C2_x = { value: void 0 }; diff --git a/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).symbols b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).symbols new file mode 100644 index 0000000000000..282fbce172a80 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts === +const C = class { +>C : Symbol(C, Decl(privateNameStaticFieldNoInitializer.ts, 0, 5)) + + static #x; +>#x : Symbol(C.#x, Decl(privateNameStaticFieldNoInitializer.ts, 0, 17)) +} + +class C2 { +>C2 : Symbol(C2, Decl(privateNameStaticFieldNoInitializer.ts, 2, 1)) + + static #x; +>#x : Symbol(C2.#x, Decl(privateNameStaticFieldNoInitializer.ts, 4, 10)) +} diff --git a/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).types b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).types new file mode 100644 index 0000000000000..a9ecdc42725e9 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=es2015).types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts === +const C = class { +>C : typeof C +>class { static #x;} : typeof C + + static #x; +>#x : any +} + +class C2 { +>C2 : C2 + + static #x; +>#x : any +} diff --git a/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).js b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).js new file mode 100644 index 0000000000000..df9759b3ea594 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).js @@ -0,0 +1,16 @@ +//// [privateNameStaticFieldNoInitializer.ts] +const C = class { + static #x; +} + +class C2 { + static #x; +} + +//// [privateNameStaticFieldNoInitializer.js] +const C = class { + static #x; +}; +class C2 { + static #x; +} diff --git a/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).symbols b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).symbols new file mode 100644 index 0000000000000..282fbce172a80 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts === +const C = class { +>C : Symbol(C, Decl(privateNameStaticFieldNoInitializer.ts, 0, 5)) + + static #x; +>#x : Symbol(C.#x, Decl(privateNameStaticFieldNoInitializer.ts, 0, 17)) +} + +class C2 { +>C2 : Symbol(C2, Decl(privateNameStaticFieldNoInitializer.ts, 2, 1)) + + static #x; +>#x : Symbol(C2.#x, Decl(privateNameStaticFieldNoInitializer.ts, 4, 10)) +} diff --git a/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).types b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).types new file mode 100644 index 0000000000000..a9ecdc42725e9 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldNoInitializer(target=esnext).types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts === +const C = class { +>C : typeof C +>class { static #x;} : typeof C + + static #x; +>#x : any +} + +class C2 { +>C2 : C2 + + static #x; +>#x : any +} diff --git a/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js new file mode 100644 index 0000000000000..810c3df10b50c --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.js @@ -0,0 +1,75 @@ +//// [privateNameStaticFieldUnaryMutation.ts] +class C { + static #test: number = 24; + constructor() { + C.#test++; + C.#test--; + ++C.#test; + --C.#test; + const a = C.#test++; + const b = C.#test--; + const c = ++C.#test; + const d = --C.#test; + for (C.#test = 0; C.#test < 10; ++C.#test) {} + for (C.#test = 0; C.#test < 10; C.#test++) {} + } + test() { + this.getClass().#test++; + this.getClass().#test--; + ++this.getClass().#test; + --this.getClass().#test; + const a = this.getClass().#test++; + const b = this.getClass().#test--; + const c = ++this.getClass().#test; + const d = --this.getClass().#test; + for (this.getClass().#test = 0; this.getClass().#test < 10; ++this.getClass().#test) {} + for (this.getClass().#test = 0; this.getClass().#test < 10; this.getClass().#test++) {} + } + getClass() { return C; } +} + + +//// [privateNameStaticFieldUnaryMutation.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, _C_test; +class C { + constructor() { + var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; + __classPrivateFieldSet(_b = C, _a, +__classPrivateFieldGet(_b, _a, "f", _C_test) + 1, "f", _C_test); + __classPrivateFieldSet(_c = C, _a, +__classPrivateFieldGet(_c, _a, "f", _C_test) - 1, "f", _C_test); + __classPrivateFieldSet(_d = C, _a, +__classPrivateFieldGet(_d, _a, "f", _C_test) + 1, "f", _C_test); + __classPrivateFieldSet(_e = C, _a, +__classPrivateFieldGet(_e, _a, "f", _C_test) - 1, "f", _C_test); + const a = (__classPrivateFieldSet(_f = C, _a, (_g = +__classPrivateFieldGet(_f, _a, "f", _C_test)) + 1, "f", _C_test), _g); + const b = (__classPrivateFieldSet(_h = C, _a, (_j = +__classPrivateFieldGet(_h, _a, "f", _C_test)) - 1, "f", _C_test), _j); + const c = __classPrivateFieldSet(_k = C, _a, +__classPrivateFieldGet(_k, _a, "f", _C_test) + 1, "f", _C_test); + const d = __classPrivateFieldSet(_l = C, _a, +__classPrivateFieldGet(_l, _a, "f", _C_test) - 1, "f", _C_test); + for (__classPrivateFieldSet(C, _a, 0, "f", _C_test); __classPrivateFieldGet(C, _a, "f", _C_test) < 10; __classPrivateFieldSet(_m = C, _a, +__classPrivateFieldGet(_m, _a, "f", _C_test) + 1, "f", _C_test)) { } + for (__classPrivateFieldSet(C, _a, 0, "f", _C_test); __classPrivateFieldGet(C, _a, "f", _C_test) < 10; __classPrivateFieldSet(_o = C, _a, +__classPrivateFieldGet(_o, _a, "f", _C_test) + 1, "f", _C_test)) { } + } + test() { + var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; + __classPrivateFieldSet(_b = this.getClass(), _a, +__classPrivateFieldGet(_b, _a, "f", _C_test) + 1, "f", _C_test); + __classPrivateFieldSet(_c = this.getClass(), _a, +__classPrivateFieldGet(_c, _a, "f", _C_test) - 1, "f", _C_test); + __classPrivateFieldSet(_d = this.getClass(), _a, +__classPrivateFieldGet(_d, _a, "f", _C_test) + 1, "f", _C_test); + __classPrivateFieldSet(_e = this.getClass(), _a, +__classPrivateFieldGet(_e, _a, "f", _C_test) - 1, "f", _C_test); + const a = (__classPrivateFieldSet(_f = this.getClass(), _a, (_g = +__classPrivateFieldGet(_f, _a, "f", _C_test)) + 1, "f", _C_test), _g); + const b = (__classPrivateFieldSet(_h = this.getClass(), _a, (_j = +__classPrivateFieldGet(_h, _a, "f", _C_test)) - 1, "f", _C_test), _j); + const c = __classPrivateFieldSet(_k = this.getClass(), _a, +__classPrivateFieldGet(_k, _a, "f", _C_test) + 1, "f", _C_test); + const d = __classPrivateFieldSet(_l = this.getClass(), _a, +__classPrivateFieldGet(_l, _a, "f", _C_test) - 1, "f", _C_test); + for (__classPrivateFieldSet(this.getClass(), _a, 0, "f", _C_test); __classPrivateFieldGet(this.getClass(), _a, "f", _C_test) < 10; __classPrivateFieldSet(_m = this.getClass(), _a, +__classPrivateFieldGet(_m, _a, "f", _C_test) + 1, "f", _C_test)) { } + for (__classPrivateFieldSet(this.getClass(), _a, 0, "f", _C_test); __classPrivateFieldGet(this.getClass(), _a, "f", _C_test) < 10; __classPrivateFieldSet(_o = this.getClass(), _a, +__classPrivateFieldGet(_o, _a, "f", _C_test) + 1, "f", _C_test)) { } + } + getClass() { return C; } +} +_a = C; +_C_test = { value: 24 }; diff --git a/tests/baselines/reference/privateNameStaticFieldUnaryMutation.symbols b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.symbols new file mode 100644 index 0000000000000..dbc298bdcce2c --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.symbols @@ -0,0 +1,148 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldUnaryMutation.ts === +class C { +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + static #test: number = 24; +>#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) + + constructor() { + C.#test++; +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + C.#test--; +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + ++C.#test; +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + --C.#test; +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + const a = C.#test++; +>a : Symbol(a, Decl(privateNameStaticFieldUnaryMutation.ts, 7, 13)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + const b = C.#test--; +>b : Symbol(b, Decl(privateNameStaticFieldUnaryMutation.ts, 8, 13)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + const c = ++C.#test; +>c : Symbol(c, Decl(privateNameStaticFieldUnaryMutation.ts, 9, 13)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + const d = --C.#test; +>d : Symbol(d, Decl(privateNameStaticFieldUnaryMutation.ts, 10, 13)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + for (C.#test = 0; C.#test < 10; ++C.#test) {} +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + + for (C.#test = 0; C.#test < 10; C.#test++) {} +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>C.#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) + } + test() { +>test : Symbol(C.test, Decl(privateNameStaticFieldUnaryMutation.ts, 13, 5)) + + this.getClass().#test++; +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + this.getClass().#test--; +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + ++this.getClass().#test; +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + --this.getClass().#test; +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + const a = this.getClass().#test++; +>a : Symbol(a, Decl(privateNameStaticFieldUnaryMutation.ts, 19, 13)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + const b = this.getClass().#test--; +>b : Symbol(b, Decl(privateNameStaticFieldUnaryMutation.ts, 20, 13)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + const c = ++this.getClass().#test; +>c : Symbol(c, Decl(privateNameStaticFieldUnaryMutation.ts, 21, 13)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + const d = --this.getClass().#test; +>d : Symbol(d, Decl(privateNameStaticFieldUnaryMutation.ts, 22, 13)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + for (this.getClass().#test = 0; this.getClass().#test < 10; ++this.getClass().#test) {} +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + + for (this.getClass().#test = 0; this.getClass().#test < 10; this.getClass().#test++) {} +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this.getClass().#test : Symbol(C.#test, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 9)) +>this.getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>this : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) + } + getClass() { return C; } +>getClass : Symbol(C.getClass, Decl(privateNameStaticFieldUnaryMutation.ts, 25, 5)) +>C : Symbol(C, Decl(privateNameStaticFieldUnaryMutation.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/privateNameStaticFieldUnaryMutation.types b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.types new file mode 100644 index 0000000000000..893f9dd472bf8 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticFieldUnaryMutation.types @@ -0,0 +1,199 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldUnaryMutation.ts === +class C { +>C : C + + static #test: number = 24; +>#test : number +>24 : 24 + + constructor() { + C.#test++; +>C.#test++ : number +>C.#test : number +>C : typeof C + + C.#test--; +>C.#test-- : number +>C.#test : number +>C : typeof C + + ++C.#test; +>++C.#test : number +>C.#test : number +>C : typeof C + + --C.#test; +>--C.#test : number +>C.#test : number +>C : typeof C + + const a = C.#test++; +>a : number +>C.#test++ : number +>C.#test : number +>C : typeof C + + const b = C.#test--; +>b : number +>C.#test-- : number +>C.#test : number +>C : typeof C + + const c = ++C.#test; +>c : number +>++C.#test : number +>C.#test : number +>C : typeof C + + const d = --C.#test; +>d : number +>--C.#test : number +>C.#test : number +>C : typeof C + + for (C.#test = 0; C.#test < 10; ++C.#test) {} +>C.#test = 0 : 0 +>C.#test : number +>C : typeof C +>0 : 0 +>C.#test < 10 : boolean +>C.#test : number +>C : typeof C +>10 : 10 +>++C.#test : number +>C.#test : number +>C : typeof C + + for (C.#test = 0; C.#test < 10; C.#test++) {} +>C.#test = 0 : 0 +>C.#test : number +>C : typeof C +>0 : 0 +>C.#test < 10 : boolean +>C.#test : number +>C : typeof C +>10 : 10 +>C.#test++ : number +>C.#test : number +>C : typeof C + } + test() { +>test : () => void + + this.getClass().#test++; +>this.getClass().#test++ : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + this.getClass().#test--; +>this.getClass().#test-- : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + ++this.getClass().#test; +>++this.getClass().#test : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + --this.getClass().#test; +>--this.getClass().#test : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + const a = this.getClass().#test++; +>a : number +>this.getClass().#test++ : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + const b = this.getClass().#test--; +>b : number +>this.getClass().#test-- : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + const c = ++this.getClass().#test; +>c : number +>++this.getClass().#test : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + const d = --this.getClass().#test; +>d : number +>--this.getClass().#test : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + for (this.getClass().#test = 0; this.getClass().#test < 10; ++this.getClass().#test) {} +>this.getClass().#test = 0 : 0 +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C +>0 : 0 +>this.getClass().#test < 10 : boolean +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C +>10 : 10 +>++this.getClass().#test : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + + for (this.getClass().#test = 0; this.getClass().#test < 10; this.getClass().#test++) {} +>this.getClass().#test = 0 : 0 +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C +>0 : 0 +>this.getClass().#test < 10 : boolean +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C +>10 : 10 +>this.getClass().#test++ : number +>this.getClass().#test : number +>this.getClass() : typeof C +>this.getClass : () => typeof C +>this : this +>getClass : () => typeof C + } + getClass() { return C; } +>getClass : () => typeof C +>C : typeof C +} + diff --git a/tests/baselines/reference/privateNameStaticMethod.errors.txt b/tests/baselines/reference/privateNameStaticMethod.errors.txt new file mode 100644 index 0000000000000..c5f2e10bc0c56 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethod.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts(7,20): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts(8,12): error TS2554: Expected 1 arguments, but got 0. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts (2 errors) ==== + class A1 { + static #method(param: string): string { + return ""; + } + constructor() { + A1.#method("") + A1.#method(1) // Error + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. + A1.#method() // Error + ~~~~~~~~~ +!!! error TS2554: Expected 1 arguments, but got 0. +!!! related TS6210 tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts:2:20: An argument for 'param' was not provided. + + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticMethod.js b/tests/baselines/reference/privateNameStaticMethod.js new file mode 100644 index 0000000000000..1541a630095da --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethod.js @@ -0,0 +1,32 @@ +//// [privateNameStaticMethod.ts] +class A1 { + static #method(param: string): string { + return ""; + } + constructor() { + A1.#method("") + A1.#method(1) // Error + A1.#method() // Error + + } +} + + +//// [privateNameStaticMethod.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 _a, _A1_method; +class A1 { + constructor() { + __classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1, ""); + __classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1, 1); // Error + __classPrivateFieldGet(A1, _a, "m", _A1_method).call(A1); // Error + } +} +_a = A1, _A1_method = function _A1_method(param) { + return ""; +}; diff --git a/tests/baselines/reference/privateNameStaticMethod.symbols b/tests/baselines/reference/privateNameStaticMethod.symbols new file mode 100644 index 0000000000000..5773a754a476c --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethod.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts === +class A1 { +>A1 : Symbol(A1, Decl(privateNameStaticMethod.ts, 0, 0)) + + static #method(param: string): string { +>#method : Symbol(A1.#method, Decl(privateNameStaticMethod.ts, 0, 10)) +>param : Symbol(param, Decl(privateNameStaticMethod.ts, 1, 19)) + + return ""; + } + constructor() { + A1.#method("") +>A1.#method : Symbol(A1.#method, Decl(privateNameStaticMethod.ts, 0, 10)) +>A1 : Symbol(A1, Decl(privateNameStaticMethod.ts, 0, 0)) + + A1.#method(1) // Error +>A1.#method : Symbol(A1.#method, Decl(privateNameStaticMethod.ts, 0, 10)) +>A1 : Symbol(A1, Decl(privateNameStaticMethod.ts, 0, 0)) + + A1.#method() // Error +>A1.#method : Symbol(A1.#method, Decl(privateNameStaticMethod.ts, 0, 10)) +>A1 : Symbol(A1, Decl(privateNameStaticMethod.ts, 0, 0)) + + } +} + diff --git a/tests/baselines/reference/privateNameStaticMethod.types b/tests/baselines/reference/privateNameStaticMethod.types new file mode 100644 index 0000000000000..5e3455150d081 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethod.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts === +class A1 { +>A1 : A1 + + static #method(param: string): string { +>#method : (param: string) => string +>param : string + + return ""; +>"" : "" + } + constructor() { + A1.#method("") +>A1.#method("") : string +>A1.#method : (param: string) => string +>A1 : typeof A1 +>"" : "" + + A1.#method(1) // Error +>A1.#method(1) : string +>A1.#method : (param: string) => string +>A1 : typeof A1 +>1 : 1 + + A1.#method() // Error +>A1.#method() : string +>A1.#method : (param: string) => string +>A1 : typeof A1 + + } +} + diff --git a/tests/baselines/reference/privateNameStaticMethodAssignment.errors.txt b/tests/baselines/reference/privateNameStaticMethodAssignment.errors.txt new file mode 100644 index 0000000000000..7f416f5181be7 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAssignment.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts(4,12): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts(5,11): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts(6,11): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts(7,18): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts(9,11): error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts (5 errors) ==== + class A3 { + static #method() { }; + constructor(a: typeof A3, b: any) { + A3.#method = () => {} // Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + a.#method = () => { }; // Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + b.#method = () => { } //Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + ({ x: A3.#method } = { x: () => {}}); //Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + let x = A3.#method; + b.#method++ //Error, not writable + ~~~~~~~ +!!! error TS2803: Cannot assign to private method '#method'. Private methods are not writable. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticMethodAssignment.js b/tests/baselines/reference/privateNameStaticMethodAssignment.js new file mode 100644 index 0000000000000..48b6df46c24c8 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAssignment.js @@ -0,0 +1,40 @@ +//// [privateNameStaticMethodAssignment.ts] +class A3 { + static #method() { }; + constructor(a: typeof A3, b: any) { + A3.#method = () => {} // Error, not writable + a.#method = () => { }; // Error, not writable + b.#method = () => { } //Error, not writable + ({ x: A3.#method } = { x: () => {}}); //Error, not writable + let x = A3.#method; + b.#method++ //Error, not writable + } +} + + +//// [privateNameStaticMethodAssignment.js] +var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { + if (kind === "m") throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; +}; +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _A3_method; +class A3 { + constructor(a, b) { + var _b; + __classPrivateFieldSet(A3, _a, () => { }, "m"); // Error, not writable + __classPrivateFieldSet(a, _a, () => { }, "m"); // Error, not writable + __classPrivateFieldSet(b, _a, () => { }, "m"); //Error, not writable + ({ x: ({ set value(_b) { __classPrivateFieldSet(A3, _a, _b, "m"); } }).value } = { x: () => { } }); //Error, not writable + let x = __classPrivateFieldGet(A3, _a, "m", _A3_method); + __classPrivateFieldSet(_b = b, _a, +__classPrivateFieldGet(_b, _a, "m", _A3_method) + 1, "m"); //Error, not writable + } + ; +} +_a = A3, _A3_method = function _A3_method() { }; diff --git a/tests/baselines/reference/privateNameStaticMethodAssignment.symbols b/tests/baselines/reference/privateNameStaticMethodAssignment.symbols new file mode 100644 index 0000000000000..778730246452e --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAssignment.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts === +class A3 { +>A3 : Symbol(A3, Decl(privateNameStaticMethodAssignment.ts, 0, 0)) + + static #method() { }; +>#method : Symbol(A3.#method, Decl(privateNameStaticMethodAssignment.ts, 0, 10)) + + constructor(a: typeof A3, b: any) { +>a : Symbol(a, Decl(privateNameStaticMethodAssignment.ts, 2, 16)) +>A3 : Symbol(A3, Decl(privateNameStaticMethodAssignment.ts, 0, 0)) +>b : Symbol(b, Decl(privateNameStaticMethodAssignment.ts, 2, 29)) + + A3.#method = () => {} // Error, not writable +>A3.#method : Symbol(A3.#method, Decl(privateNameStaticMethodAssignment.ts, 0, 10)) +>A3 : Symbol(A3, Decl(privateNameStaticMethodAssignment.ts, 0, 0)) + + a.#method = () => { }; // Error, not writable +>a.#method : Symbol(A3.#method, Decl(privateNameStaticMethodAssignment.ts, 0, 10)) +>a : Symbol(a, Decl(privateNameStaticMethodAssignment.ts, 2, 16)) + + b.#method = () => { } //Error, not writable +>b : Symbol(b, Decl(privateNameStaticMethodAssignment.ts, 2, 29)) + + ({ x: A3.#method } = { x: () => {}}); //Error, not writable +>x : Symbol(x, Decl(privateNameStaticMethodAssignment.ts, 6, 10)) +>A3.#method : Symbol(A3.#method, Decl(privateNameStaticMethodAssignment.ts, 0, 10)) +>A3 : Symbol(A3, Decl(privateNameStaticMethodAssignment.ts, 0, 0)) +>x : Symbol(x, Decl(privateNameStaticMethodAssignment.ts, 6, 30)) + + let x = A3.#method; +>x : Symbol(x, Decl(privateNameStaticMethodAssignment.ts, 7, 11)) +>A3.#method : Symbol(A3.#method, Decl(privateNameStaticMethodAssignment.ts, 0, 10)) +>A3 : Symbol(A3, Decl(privateNameStaticMethodAssignment.ts, 0, 0)) + + b.#method++ //Error, not writable +>b : Symbol(b, Decl(privateNameStaticMethodAssignment.ts, 2, 29)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticMethodAssignment.types b/tests/baselines/reference/privateNameStaticMethodAssignment.types new file mode 100644 index 0000000000000..927ecd2de79c0 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAssignment.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts === +class A3 { +>A3 : A3 + + static #method() { }; +>#method : () => void + + constructor(a: typeof A3, b: any) { +>a : typeof A3 +>A3 : typeof A3 +>b : any + + A3.#method = () => {} // Error, not writable +>A3.#method = () => {} : () => void +>A3.#method : () => void +>A3 : typeof A3 +>() => {} : () => void + + a.#method = () => { }; // Error, not writable +>a.#method = () => { } : () => void +>a.#method : () => void +>a : typeof A3 +>() => { } : () => void + + b.#method = () => { } //Error, not writable +>b.#method = () => { } : () => void +>b.#method : any +>b : any +>() => { } : () => void + + ({ x: A3.#method } = { x: () => {}}); //Error, not writable +>({ x: A3.#method } = { x: () => {}}) : { x: () => void; } +>{ x: A3.#method } = { x: () => {}} : { x: () => void; } +>{ x: A3.#method } : { x: () => void; } +>x : () => void +>A3.#method : () => void +>A3 : typeof A3 +>{ x: () => {}} : { x: () => void; } +>x : () => void +>() => {} : () => void + + let x = A3.#method; +>x : () => void +>A3.#method : () => void +>A3 : typeof A3 + + b.#method++ //Error, not writable +>b.#method++ : number +>b.#method : any +>b : any + } +} + diff --git a/tests/baselines/reference/privateNameStaticMethodAsync.errors.txt b/tests/baselines/reference/privateNameStaticMethodAsync.errors.txt new file mode 100644 index 0000000000000..26cd65be3ceea --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAsync.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts(11,11): error TS1029: 'static' modifier must precede 'async' modifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts (1 errors) ==== + const C = class { + static async #bar() { return await Promise.resolve(42); } + static async foo() { + const b = await this.#bar(); + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); + } + static *#baz() { yield 42; } + static async *#qux() { + yield (await Promise.resolve(42)); + } + async static *#bazBad() { yield 42; } + ~~~~~~ +!!! error TS1029: 'static' modifier must precede 'async' modifier. + } + + + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticMethodAsync.js b/tests/baselines/reference/privateNameStaticMethodAsync.js new file mode 100644 index 0000000000000..541c1b18ad5f0 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAsync.js @@ -0,0 +1,37 @@ +//// [privateNameStaticMethodAsync.ts] +const C = class { + static async #bar() { return await Promise.resolve(42); } + static async foo() { + const b = await this.#bar(); + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); + } + static *#baz() { yield 42; } + static async *#qux() { + yield (await Promise.resolve(42)); + } + async static *#bazBad() { yield 42; } +} + + + + +//// [privateNameStaticMethodAsync.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _C_bar, _C_baz, _C_qux, _C_bazBad; +const C = (_a = class { + static async foo() { + const b = await __classPrivateFieldGet(this, _a, "m", _C_bar).call(this); + return b + (__classPrivateFieldGet(this, _a, "m", _C_baz).call(this).next().value || 0) + ((await __classPrivateFieldGet(this, _a, "m", _C_qux).call(this).next()).value || 0); + } + }, + _C_bar = async function _C_bar() { return await Promise.resolve(42); }, + _C_baz = function* _C_baz() { yield 42; }, + _C_qux = async function* _C_qux() { + yield (await Promise.resolve(42)); + }, + _C_bazBad = async function* _C_bazBad() { yield 42; }, + _a); diff --git a/tests/baselines/reference/privateNameStaticMethodAsync.symbols b/tests/baselines/reference/privateNameStaticMethodAsync.symbols new file mode 100644 index 0000000000000..0e13961283a06 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAsync.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts === +const C = class { +>C : Symbol(C, Decl(privateNameStaticMethodAsync.ts, 0, 5)) + + static async #bar() { return await Promise.resolve(42); } +>#bar : Symbol(C.#bar, Decl(privateNameStaticMethodAsync.ts, 0, 17)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + + static async foo() { +>foo : Symbol(C.foo, Decl(privateNameStaticMethodAsync.ts, 1, 61)) + + const b = await this.#bar(); +>b : Symbol(b, Decl(privateNameStaticMethodAsync.ts, 3, 13)) +>this.#bar : Symbol(C.#bar, Decl(privateNameStaticMethodAsync.ts, 0, 17)) +>this : Symbol(C, Decl(privateNameStaticMethodAsync.ts, 0, 9)) + + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); +>b : Symbol(b, Decl(privateNameStaticMethodAsync.ts, 3, 13)) +>this.#baz().next().value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>this.#baz().next : Symbol(Generator.next, Decl(lib.es2015.generator.d.ts, --, --)) +>this.#baz : Symbol(C.#baz, Decl(privateNameStaticMethodAsync.ts, 5, 5)) +>this : Symbol(C, Decl(privateNameStaticMethodAsync.ts, 0, 9)) +>next : Symbol(Generator.next, Decl(lib.es2015.generator.d.ts, --, --)) +>value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>(await this.#qux().next()).value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>this.#qux().next : Symbol(AsyncGenerator.next, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) +>this.#qux : Symbol(C.#qux, Decl(privateNameStaticMethodAsync.ts, 6, 32)) +>this : Symbol(C, Decl(privateNameStaticMethodAsync.ts, 0, 9)) +>next : Symbol(AsyncGenerator.next, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) +>value : Symbol(value, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + } + static *#baz() { yield 42; } +>#baz : Symbol(C.#baz, Decl(privateNameStaticMethodAsync.ts, 5, 5)) + + static async *#qux() { +>#qux : Symbol(C.#qux, Decl(privateNameStaticMethodAsync.ts, 6, 32)) + + yield (await Promise.resolve(42)); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + } + async static *#bazBad() { yield 42; } +>#bazBad : Symbol(C.#bazBad, Decl(privateNameStaticMethodAsync.ts, 9, 5)) +} + + + diff --git a/tests/baselines/reference/privateNameStaticMethodAsync.types b/tests/baselines/reference/privateNameStaticMethodAsync.types new file mode 100644 index 0000000000000..6da52fd602fc2 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodAsync.types @@ -0,0 +1,79 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts === +const C = class { +>C : typeof C +>class { static async #bar() { return await Promise.resolve(42); } static async foo() { const b = await this.#bar(); return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); } static *#baz() { yield 42; } static async *#qux() { yield (await Promise.resolve(42)); } async static *#bazBad() { yield 42; }} : typeof C + + static async #bar() { return await Promise.resolve(42); } +>#bar : () => Promise +>await Promise.resolve(42) : number +>Promise.resolve(42) : Promise +>Promise.resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>Promise : PromiseConstructor +>resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>42 : 42 + + static async foo() { +>foo : () => Promise + + const b = await this.#bar(); +>b : number +>await this.#bar() : number +>this.#bar() : Promise +>this.#bar : () => Promise +>this : typeof C + + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); +>b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0) : number +>b + (this.#baz().next().value || 0) : number +>b : number +>(this.#baz().next().value || 0) : number +>this.#baz().next().value || 0 : number +>this.#baz().next().value : number | void +>this.#baz().next() : IteratorResult +>this.#baz().next : (...args: [] | [unknown]) => IteratorResult +>this.#baz() : Generator +>this.#baz : () => Generator +>this : typeof C +>next : (...args: [] | [unknown]) => IteratorResult +>value : number | void +>0 : 0 +>((await this.#qux().next()).value || 0) : number +>(await this.#qux().next()).value || 0 : number +>(await this.#qux().next()).value : number | void +>(await this.#qux().next()) : IteratorResult +>await this.#qux().next() : IteratorResult +>this.#qux().next() : Promise> +>this.#qux().next : (...args: [] | [unknown]) => Promise> +>this.#qux() : AsyncGenerator +>this.#qux : () => AsyncGenerator +>this : typeof C +>next : (...args: [] | [unknown]) => Promise> +>value : number | void +>0 : 0 + } + static *#baz() { yield 42; } +>#baz : () => Generator +>yield 42 : any +>42 : 42 + + static async *#qux() { +>#qux : () => AsyncGenerator + + yield (await Promise.resolve(42)); +>yield (await Promise.resolve(42)) : any +>(await Promise.resolve(42)) : number +>await Promise.resolve(42) : number +>Promise.resolve(42) : Promise +>Promise.resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>Promise : PromiseConstructor +>resolve : { (): Promise; (value: T | PromiseLike): Promise; } +>42 : 42 + } + async static *#bazBad() { yield 42; } +>#bazBad : () => AsyncGenerator +>yield 42 : any +>42 : 42 +} + + + diff --git a/tests/baselines/reference/privateNameStaticMethodCallExpression.js b/tests/baselines/reference/privateNameStaticMethodCallExpression.js new file mode 100644 index 0000000000000..0495fc8873363 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodCallExpression.js @@ -0,0 +1,55 @@ +//// [privateNameStaticMethodCallExpression.ts] +class AA { + static #method() { this.x = 10; }; + static #method2(a, ...b) {}; + static x = 1; + test() { + AA.#method(); + const func = AA.#method; + func(); + new AA.#method(); + + const arr = [ 1, 2 ]; + AA.#method2(0, ...arr, 3); + + const b = new AA.#method2(0, ...arr, 3); //Error + const str = AA.#method2`head${1}middle${2}tail`; + AA.getClass().#method2`test${1}and${2}`; + + AA.getClass().#method2(0, ...arr, 3); + const b2 = new (AA.getClass().#method2)(0, ...arr, 3); //Error + const str2 = AA.getClass().#method2`head${1}middle${2}tail`; + } + static getClass() { return AA; } +} + + +//// [privateNameStaticMethodCallExpression.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _AA_method, _AA_method2; +class AA { + ; + ; + test() { + var _b, _c, _d; + __classPrivateFieldGet(AA, _a, "m", _AA_method).call(AA); + const func = __classPrivateFieldGet(AA, _a, "m", _AA_method); + func(); + new (__classPrivateFieldGet(AA, _a, "m", _AA_method))(); + const arr = [1, 2]; + __classPrivateFieldGet(AA, _a, "m", _AA_method2).call(AA, 0, ...arr, 3); + const b = new (__classPrivateFieldGet(AA, _a, "m", _AA_method2))(0, ...arr, 3); //Error + const str = __classPrivateFieldGet(AA, _a, "m", _AA_method2).bind(AA) `head${1}middle${2}tail`; + __classPrivateFieldGet((_b = AA.getClass()), _a, "m", _AA_method2).bind(_b) `test${1}and${2}`; + __classPrivateFieldGet((_c = AA.getClass()), _a, "m", _AA_method2).call(_c, 0, ...arr, 3); + const b2 = new (__classPrivateFieldGet(AA.getClass(), _a, "m", _AA_method2))(0, ...arr, 3); //Error + const str2 = __classPrivateFieldGet((_d = AA.getClass()), _a, "m", _AA_method2).bind(_d) `head${1}middle${2}tail`; + } + static getClass() { return AA; } +} +_a = AA, _AA_method = function _AA_method() { this.x = 10; }, _AA_method2 = function _AA_method2(a, ...b) { }; +AA.x = 1; diff --git a/tests/baselines/reference/privateNameStaticMethodCallExpression.symbols b/tests/baselines/reference/privateNameStaticMethodCallExpression.symbols new file mode 100644 index 0000000000000..b661493cd69cf --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodCallExpression.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodCallExpression.ts === +class AA { +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) + + static #method() { this.x = 10; }; +>#method : Symbol(AA.#method, Decl(privateNameStaticMethodCallExpression.ts, 0, 10)) +>this.x : Symbol(AA.x, Decl(privateNameStaticMethodCallExpression.ts, 2, 32)) +>this : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>x : Symbol(AA.x, Decl(privateNameStaticMethodCallExpression.ts, 2, 32)) + + static #method2(a, ...b) {}; +>#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>a : Symbol(a, Decl(privateNameStaticMethodCallExpression.ts, 2, 20)) +>b : Symbol(b, Decl(privateNameStaticMethodCallExpression.ts, 2, 22)) + + static x = 1; +>x : Symbol(AA.x, Decl(privateNameStaticMethodCallExpression.ts, 2, 32)) + + test() { +>test : Symbol(AA.test, Decl(privateNameStaticMethodCallExpression.ts, 3, 17)) + + AA.#method(); +>AA.#method : Symbol(AA.#method, Decl(privateNameStaticMethodCallExpression.ts, 0, 10)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) + + const func = AA.#method; +>func : Symbol(func, Decl(privateNameStaticMethodCallExpression.ts, 6, 13)) +>AA.#method : Symbol(AA.#method, Decl(privateNameStaticMethodCallExpression.ts, 0, 10)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) + + func(); +>func : Symbol(func, Decl(privateNameStaticMethodCallExpression.ts, 6, 13)) + + new AA.#method(); +>AA.#method : Symbol(AA.#method, Decl(privateNameStaticMethodCallExpression.ts, 0, 10)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) + + const arr = [ 1, 2 ]; +>arr : Symbol(arr, Decl(privateNameStaticMethodCallExpression.ts, 10, 13)) + + AA.#method2(0, ...arr, 3); +>AA.#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameStaticMethodCallExpression.ts, 10, 13)) + + const b = new AA.#method2(0, ...arr, 3); //Error +>b : Symbol(b, Decl(privateNameStaticMethodCallExpression.ts, 13, 13)) +>AA.#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>arr : Symbol(arr, Decl(privateNameStaticMethodCallExpression.ts, 10, 13)) + + const str = AA.#method2`head${1}middle${2}tail`; +>str : Symbol(str, Decl(privateNameStaticMethodCallExpression.ts, 14, 13)) +>AA.#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) + + AA.getClass().#method2`test${1}and${2}`; +>AA.getClass().#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA.getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) + + AA.getClass().#method2(0, ...arr, 3); +>AA.getClass().#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA.getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>arr : Symbol(arr, Decl(privateNameStaticMethodCallExpression.ts, 10, 13)) + + const b2 = new (AA.getClass().#method2)(0, ...arr, 3); //Error +>b2 : Symbol(b2, Decl(privateNameStaticMethodCallExpression.ts, 18, 13)) +>AA.getClass().#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA.getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>arr : Symbol(arr, Decl(privateNameStaticMethodCallExpression.ts, 10, 13)) + + const str2 = AA.getClass().#method2`head${1}middle${2}tail`; +>str2 : Symbol(str2, Decl(privateNameStaticMethodCallExpression.ts, 19, 13)) +>AA.getClass().#method2 : Symbol(AA.#method2, Decl(privateNameStaticMethodCallExpression.ts, 1, 38)) +>AA.getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +>getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) + } + static getClass() { return AA; } +>getClass : Symbol(AA.getClass, Decl(privateNameStaticMethodCallExpression.ts, 20, 5)) +>AA : Symbol(AA, Decl(privateNameStaticMethodCallExpression.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/privateNameStaticMethodCallExpression.types b/tests/baselines/reference/privateNameStaticMethodCallExpression.types new file mode 100644 index 0000000000000..09f0ca83fa16c --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodCallExpression.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodCallExpression.ts === +class AA { +>AA : AA + + static #method() { this.x = 10; }; +>#method : () => void +>this.x = 10 : 10 +>this.x : number +>this : typeof AA +>x : number +>10 : 10 + + static #method2(a, ...b) {}; +>#method2 : (a: any, ...b: any[]) => void +>a : any +>b : any[] + + static x = 1; +>x : number +>1 : 1 + + test() { +>test : () => void + + AA.#method(); +>AA.#method() : void +>AA.#method : () => void +>AA : typeof AA + + const func = AA.#method; +>func : () => void +>AA.#method : () => void +>AA : typeof AA + + func(); +>func() : void +>func : () => void + + new AA.#method(); +>new AA.#method() : any +>AA.#method : () => void +>AA : typeof AA + + const arr = [ 1, 2 ]; +>arr : number[] +>[ 1, 2 ] : number[] +>1 : 1 +>2 : 2 + + AA.#method2(0, ...arr, 3); +>AA.#method2(0, ...arr, 3) : void +>AA.#method2 : (a: any, ...b: any[]) => void +>AA : typeof AA +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b = new AA.#method2(0, ...arr, 3); //Error +>b : any +>new AA.#method2(0, ...arr, 3) : any +>AA.#method2 : (a: any, ...b: any[]) => void +>AA : typeof AA +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str = AA.#method2`head${1}middle${2}tail`; +>str : void +>AA.#method2`head${1}middle${2}tail` : void +>AA.#method2 : (a: any, ...b: any[]) => void +>AA : typeof AA +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + + AA.getClass().#method2`test${1}and${2}`; +>AA.getClass().#method2`test${1}and${2}` : void +>AA.getClass().#method2 : (a: any, ...b: any[]) => void +>AA.getClass() : typeof AA +>AA.getClass : () => typeof AA +>AA : typeof AA +>getClass : () => typeof AA +>`test${1}and${2}` : string +>1 : 1 +>2 : 2 + + AA.getClass().#method2(0, ...arr, 3); +>AA.getClass().#method2(0, ...arr, 3) : void +>AA.getClass().#method2 : (a: any, ...b: any[]) => void +>AA.getClass() : typeof AA +>AA.getClass : () => typeof AA +>AA : typeof AA +>getClass : () => typeof AA +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const b2 = new (AA.getClass().#method2)(0, ...arr, 3); //Error +>b2 : any +>new (AA.getClass().#method2)(0, ...arr, 3) : any +>(AA.getClass().#method2) : (a: any, ...b: any[]) => void +>AA.getClass().#method2 : (a: any, ...b: any[]) => void +>AA.getClass() : typeof AA +>AA.getClass : () => typeof AA +>AA : typeof AA +>getClass : () => typeof AA +>0 : 0 +>...arr : number +>arr : number[] +>3 : 3 + + const str2 = AA.getClass().#method2`head${1}middle${2}tail`; +>str2 : void +>AA.getClass().#method2`head${1}middle${2}tail` : void +>AA.getClass().#method2 : (a: any, ...b: any[]) => void +>AA.getClass() : typeof AA +>AA.getClass : () => typeof AA +>AA : typeof AA +>getClass : () => typeof AA +>`head${1}middle${2}tail` : string +>1 : 1 +>2 : 2 + } + static getClass() { return AA; } +>getClass : () => typeof AA +>AA : typeof AA +} + diff --git a/tests/baselines/reference/privateNameStaticMethodClassExpression.errors.txt b/tests/baselines/reference/privateNameStaticMethodClassExpression.errors.txt new file mode 100644 index 0000000000000..48a7ffe7f02df --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodClassExpression.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts(9,14): error TS18013: Property '#method' is not accessible outside class 'D' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts(10,14): error TS18013: Property '#field' is not accessible outside class 'D' because it has a private identifier. + + +==== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts (2 errors) ==== + const C = class D { + static #field = D.#method(); + static #method() { return 42; } + static getClass() { return D; } + static getField() { return C.#field }; + } + + console.log(C.getClass().getField()); + C.getClass().#method; // Error + ~~~~~~~ +!!! error TS18013: Property '#method' is not accessible outside class 'D' because it has a private identifier. + C.getClass().#field; // Error + ~~~~~~ +!!! error TS18013: Property '#field' is not accessible outside class 'D' because it has a private identifier. + + \ No newline at end of file diff --git a/tests/baselines/reference/privateNameStaticMethodClassExpression.js b/tests/baselines/reference/privateNameStaticMethodClassExpression.js new file mode 100644 index 0000000000000..cca04691e0928 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodClassExpression.js @@ -0,0 +1,32 @@ +//// [privateNameStaticMethodClassExpression.ts] +const C = class D { + static #field = D.#method(); + static #method() { return 42; } + static getClass() { return D; } + static getField() { return C.#field }; +} + +console.log(C.getClass().getField()); +C.getClass().#method; // Error +C.getClass().#field; // Error + + + +//// [privateNameStaticMethodClassExpression.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _D_field, _D_method; +const C = (_a = class D { + static getClass() { return D; } + static getField() { return __classPrivateFieldGet(C, _a, "f", _D_field); } + ; + }, + _D_method = function _D_method() { return 42; }, + _D_field = { value: __classPrivateFieldGet(_a, _a, "m", _D_method).call(_a) }, + _a); +console.log(C.getClass().getField()); +C.getClass().; // Error +C.getClass().; // Error diff --git a/tests/baselines/reference/privateNameStaticMethodClassExpression.symbols b/tests/baselines/reference/privateNameStaticMethodClassExpression.symbols new file mode 100644 index 0000000000000..1804076d049b0 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodClassExpression.symbols @@ -0,0 +1,44 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts === +const C = class D { +>C : Symbol(C, Decl(privateNameStaticMethodClassExpression.ts, 0, 5)) +>D : Symbol(D, Decl(privateNameStaticMethodClassExpression.ts, 0, 9)) + + static #field = D.#method(); +>#field : Symbol(D.#field, Decl(privateNameStaticMethodClassExpression.ts, 0, 19)) +>D.#method : Symbol(D.#method, Decl(privateNameStaticMethodClassExpression.ts, 1, 32)) +>D : Symbol(D, Decl(privateNameStaticMethodClassExpression.ts, 0, 9)) + + static #method() { return 42; } +>#method : Symbol(D.#method, Decl(privateNameStaticMethodClassExpression.ts, 1, 32)) + + static getClass() { return D; } +>getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) +>D : Symbol(D, Decl(privateNameStaticMethodClassExpression.ts, 0, 9)) + + static getField() { return C.#field }; +>getField : Symbol(D.getField, Decl(privateNameStaticMethodClassExpression.ts, 3, 35)) +>C.#field : Symbol(D.#field, Decl(privateNameStaticMethodClassExpression.ts, 0, 19)) +>C : Symbol(C, Decl(privateNameStaticMethodClassExpression.ts, 0, 5)) +} + +console.log(C.getClass().getField()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.getClass().getField : Symbol(D.getField, Decl(privateNameStaticMethodClassExpression.ts, 3, 35)) +>C.getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) +>C : Symbol(C, Decl(privateNameStaticMethodClassExpression.ts, 0, 5)) +>getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) +>getField : Symbol(D.getField, Decl(privateNameStaticMethodClassExpression.ts, 3, 35)) + +C.getClass().#method; // Error +>C.getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) +>C : Symbol(C, Decl(privateNameStaticMethodClassExpression.ts, 0, 5)) +>getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) + +C.getClass().#field; // Error +>C.getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) +>C : Symbol(C, Decl(privateNameStaticMethodClassExpression.ts, 0, 5)) +>getClass : Symbol(D.getClass, Decl(privateNameStaticMethodClassExpression.ts, 2, 35)) + + diff --git a/tests/baselines/reference/privateNameStaticMethodClassExpression.types b/tests/baselines/reference/privateNameStaticMethodClassExpression.types new file mode 100644 index 0000000000000..5144a6aeaf5b0 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodClassExpression.types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts === +const C = class D { +>C : typeof D +>class D { static #field = D.#method(); static #method() { return 42; } static getClass() { return D; } static getField() { return C.#field };} : typeof D +>D : typeof D + + static #field = D.#method(); +>#field : number +>D.#method() : number +>D.#method : () => number +>D : typeof D + + static #method() { return 42; } +>#method : () => number +>42 : 42 + + static getClass() { return D; } +>getClass : () => typeof D +>D : typeof D + + static getField() { return C.#field }; +>getField : () => number +>C.#field : number +>C : typeof D +} + +console.log(C.getClass().getField()); +>console.log(C.getClass().getField()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.getClass().getField() : number +>C.getClass().getField : () => number +>C.getClass() : typeof D +>C.getClass : () => typeof D +>C : typeof D +>getClass : () => typeof D +>getField : () => number + +C.getClass().#method; // Error +>C.getClass().#method : any +>C.getClass() : typeof D +>C.getClass : () => typeof D +>C : typeof D +>getClass : () => typeof D + +C.getClass().#field; // Error +>C.getClass().#field : any +>C.getClass() : typeof D +>C.getClass : () => typeof D +>C : typeof D +>getClass : () => typeof D + + diff --git a/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.js b/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.js new file mode 100644 index 0000000000000..1d2e16d722089 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.js @@ -0,0 +1,21 @@ +//// [privateNameStaticMethodInStaticFieldInit.ts] +class C { + static s = C.#method(); + static #method() { return 42; } +} + +console.log(C.s); + + +//// [privateNameStaticMethodInStaticFieldInit.js] +var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { + if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var _a, _C_method; +class C { +} +_a = C, _C_method = function _C_method() { return 42; }; +C.s = __classPrivateFieldGet(C, _a, "m", _C_method).call(C); +console.log(C.s); diff --git a/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.symbols b/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.symbols new file mode 100644 index 0000000000000..94f39eb67830d --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodInStaticFieldInit.ts === +class C { +>C : Symbol(C, Decl(privateNameStaticMethodInStaticFieldInit.ts, 0, 0)) + + static s = C.#method(); +>s : Symbol(C.s, Decl(privateNameStaticMethodInStaticFieldInit.ts, 0, 9)) +>C.#method : Symbol(C.#method, Decl(privateNameStaticMethodInStaticFieldInit.ts, 1, 27)) +>C : Symbol(C, Decl(privateNameStaticMethodInStaticFieldInit.ts, 0, 0)) + + static #method() { return 42; } +>#method : Symbol(C.#method, Decl(privateNameStaticMethodInStaticFieldInit.ts, 1, 27)) +} + +console.log(C.s); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>C.s : Symbol(C.s, Decl(privateNameStaticMethodInStaticFieldInit.ts, 0, 9)) +>C : Symbol(C, Decl(privateNameStaticMethodInStaticFieldInit.ts, 0, 0)) +>s : Symbol(C.s, Decl(privateNameStaticMethodInStaticFieldInit.ts, 0, 9)) + diff --git a/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.types b/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.types new file mode 100644 index 0000000000000..a251b7b41b0c2 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticMethodInStaticFieldInit.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodInStaticFieldInit.ts === +class C { +>C : C + + static s = C.#method(); +>s : number +>C.#method() : number +>C.#method : () => number +>C : typeof C + + static #method() { return 42; } +>#method : () => number +>42 : 42 +} + +console.log(C.s); +>console.log(C.s) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>C.s : number +>C : typeof C +>s : number + diff --git a/tests/baselines/reference/privateNameStaticsAndStaticMethods.js b/tests/baselines/reference/privateNameStaticsAndStaticMethods.js new file mode 100644 index 0000000000000..a2f814b593467 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticsAndStaticMethods.js @@ -0,0 +1,62 @@ +//// [privateNameStaticsAndStaticMethods.ts] +class A { + static #foo(a: number) {} + static async #bar(a: number) {} + static async *#baz(a: number) { + return 3; + } + static #_quux: number; + static get #quux (): number { + return this.#_quux; + } + static set #quux (val: number) { + 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: string) {} + constructor () { + super(); + B.#foo("str"); + } +} + + +//// [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) { + return 3; + } + static #_quux; + static get #quux() { + return this.#_quux; + } + static set #quux(val) { + this.#_quux = val; + } +} +class B extends A { + static #foo(a) { } + constructor() { + super(); + B.#foo("str"); + } +} diff --git a/tests/baselines/reference/privateNameStaticsAndStaticMethods.symbols b/tests/baselines/reference/privateNameStaticsAndStaticMethods.symbols new file mode 100644 index 0000000000000..b12f3fa4c464d --- /dev/null +++ b/tests/baselines/reference/privateNameStaticsAndStaticMethods.symbols @@ -0,0 +1,80 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticsAndStaticMethods.ts === +class A { +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + static #foo(a: number) {} +>#foo : Symbol(A.#foo, Decl(privateNameStaticsAndStaticMethods.ts, 0, 9)) +>a : Symbol(a, Decl(privateNameStaticsAndStaticMethods.ts, 1, 16)) + + static async #bar(a: number) {} +>#bar : Symbol(A.#bar, Decl(privateNameStaticsAndStaticMethods.ts, 1, 29)) +>a : Symbol(a, Decl(privateNameStaticsAndStaticMethods.ts, 2, 22)) + + static async *#baz(a: number) { +>#baz : Symbol(A.#baz, Decl(privateNameStaticsAndStaticMethods.ts, 2, 35)) +>a : Symbol(a, Decl(privateNameStaticsAndStaticMethods.ts, 3, 23)) + + return 3; + } + static #_quux: number; +>#_quux : Symbol(A.#_quux, Decl(privateNameStaticsAndStaticMethods.ts, 5, 5)) + + static get #quux (): number { +>#quux : Symbol(A.#quux, Decl(privateNameStaticsAndStaticMethods.ts, 6, 26), Decl(privateNameStaticsAndStaticMethods.ts, 9, 5)) + + return this.#_quux; +>this.#_quux : Symbol(A.#_quux, Decl(privateNameStaticsAndStaticMethods.ts, 5, 5)) +>this : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + } + static set #quux (val: number) { +>#quux : Symbol(A.#quux, Decl(privateNameStaticsAndStaticMethods.ts, 6, 26), Decl(privateNameStaticsAndStaticMethods.ts, 9, 5)) +>val : Symbol(val, Decl(privateNameStaticsAndStaticMethods.ts, 10, 22)) + + this.#_quux = val; +>this.#_quux : Symbol(A.#_quux, Decl(privateNameStaticsAndStaticMethods.ts, 5, 5)) +>this : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) +>val : Symbol(val, Decl(privateNameStaticsAndStaticMethods.ts, 10, 22)) + } + constructor () { + A.#foo(30); +>A.#foo : Symbol(A.#foo, Decl(privateNameStaticsAndStaticMethods.ts, 0, 9)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + A.#bar(30); +>A.#bar : Symbol(A.#bar, Decl(privateNameStaticsAndStaticMethods.ts, 1, 29)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + A.#bar(30); +>A.#bar : Symbol(A.#bar, Decl(privateNameStaticsAndStaticMethods.ts, 1, 29)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + A.#quux = A.#quux + 1; +>A.#quux : Symbol(A.#quux, Decl(privateNameStaticsAndStaticMethods.ts, 6, 26), Decl(privateNameStaticsAndStaticMethods.ts, 9, 5)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) +>A.#quux : Symbol(A.#quux, Decl(privateNameStaticsAndStaticMethods.ts, 6, 26), Decl(privateNameStaticsAndStaticMethods.ts, 9, 5)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + A.#quux++; +>A.#quux : Symbol(A.#quux, Decl(privateNameStaticsAndStaticMethods.ts, 6, 26), Decl(privateNameStaticsAndStaticMethods.ts, 9, 5)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + } +} + +class B extends A { +>B : Symbol(B, Decl(privateNameStaticsAndStaticMethods.ts, 20, 1)) +>A : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + static #foo(a: string) {} +>#foo : Symbol(B.#foo, Decl(privateNameStaticsAndStaticMethods.ts, 22, 19)) +>a : Symbol(a, Decl(privateNameStaticsAndStaticMethods.ts, 23, 16)) + + constructor () { + super(); +>super : Symbol(A, Decl(privateNameStaticsAndStaticMethods.ts, 0, 0)) + + B.#foo("str"); +>B.#foo : Symbol(B.#foo, Decl(privateNameStaticsAndStaticMethods.ts, 22, 19)) +>B : Symbol(B, Decl(privateNameStaticsAndStaticMethods.ts, 20, 1)) + } +} + diff --git a/tests/baselines/reference/privateNameStaticsAndStaticMethods.types b/tests/baselines/reference/privateNameStaticsAndStaticMethods.types new file mode 100644 index 0000000000000..c9e37e68f5134 --- /dev/null +++ b/tests/baselines/reference/privateNameStaticsAndStaticMethods.types @@ -0,0 +1,95 @@ +=== tests/cases/conformance/classes/members/privateNames/privateNameStaticsAndStaticMethods.ts === +class A { +>A : A + + static #foo(a: number) {} +>#foo : (a: number) => void +>a : number + + static async #bar(a: number) {} +>#bar : (a: number) => Promise +>a : number + + static async *#baz(a: number) { +>#baz : (a: number) => AsyncGenerator +>a : number + + return 3; +>3 : 3 + } + static #_quux: number; +>#_quux : number + + static get #quux (): number { +>#quux : number + + return this.#_quux; +>this.#_quux : number +>this : typeof A + } + static set #quux (val: number) { +>#quux : number +>val : number + + this.#_quux = val; +>this.#_quux = val : number +>this.#_quux : number +>this : typeof A +>val : number + } + constructor () { + A.#foo(30); +>A.#foo(30) : void +>A.#foo : (a: number) => void +>A : typeof A +>30 : 30 + + A.#bar(30); +>A.#bar(30) : Promise +>A.#bar : (a: number) => Promise +>A : typeof A +>30 : 30 + + A.#bar(30); +>A.#bar(30) : Promise +>A.#bar : (a: number) => Promise +>A : typeof A +>30 : 30 + + A.#quux = A.#quux + 1; +>A.#quux = A.#quux + 1 : number +>A.#quux : number +>A : typeof A +>A.#quux + 1 : number +>A.#quux : number +>A : typeof A +>1 : 1 + + A.#quux++; +>A.#quux++ : number +>A.#quux : number +>A : typeof A + } +} + +class B extends A { +>B : B +>A : A + + static #foo(a: string) {} +>#foo : (a: string) => void +>a : string + + constructor () { + super(); +>super() : void +>super : typeof A + + B.#foo("str"); +>B.#foo("str") : void +>B.#foo : (a: string) => void +>B : typeof B +>"str" : "str" + } +} + diff --git a/tests/baselines/reference/privateNameUnused.errors.txt b/tests/baselines/reference/privateNameUnused.errors.txt index cb4bd1853f0d9..02ecbc9e60047 100644 --- a/tests/baselines/reference/privateNameUnused.errors.txt +++ b/tests/baselines/reference/privateNameUnused.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts(3,5): error TS6133: '#unused' is declared but its value is never read. +tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts(11,5): error TS6133: '#unused' is declared but its value is never read. +tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts(21,9): error TS6133: '#unused' is declared but its value is never read. -==== tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts (1 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts (3 errors) ==== export class A { #used = "used"; #unused = "unused"; @@ -11,4 +13,26 @@ tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts(3,5): console.log(this.#used); } } - \ No newline at end of file + + export class A2 { + #used() { }; + #unused() { }; + ~~~~~~~ +!!! error TS6133: '#unused' is declared but its value is never read. + constructor () { + console.log(this.#used()); + } + } + + export class A3 { + get #used() { return 0 }; + set #used(value: number) { }; + + get #unused() { return 0 }; + ~~~~~~~ +!!! error TS6133: '#unused' is declared but its value is never read. + set #unused(value: number) { }; + constructor () { + console.log(this.#used); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/privateNameUnused.symbols b/tests/baselines/reference/privateNameUnused.symbols index 4b85303d6f2ed..d8b834bd92f69 100644 --- a/tests/baselines/reference/privateNameUnused.symbols +++ b/tests/baselines/reference/privateNameUnused.symbols @@ -18,3 +18,48 @@ export class A { } } +export class A2 { +>A2 : Symbol(A2, Decl(privateNameUnused.ts, 6, 1)) + + #used() { }; +>#used : Symbol(A2.#used, Decl(privateNameUnused.ts, 8, 17)) + + #unused() { }; +>#unused : Symbol(A2.#unused, Decl(privateNameUnused.ts, 9, 17)) + + constructor () { + console.log(this.#used()); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#used : Symbol(A2.#used, Decl(privateNameUnused.ts, 8, 17)) +>this : Symbol(A2, Decl(privateNameUnused.ts, 6, 1)) + } +} + +export class A3 { +>A3 : Symbol(A3, Decl(privateNameUnused.ts, 14, 1)) + + get #used() { return 0 }; +>#used : Symbol(A3.#used, Decl(privateNameUnused.ts, 16, 17), Decl(privateNameUnused.ts, 17, 29)) + + set #used(value: number) { }; +>#used : Symbol(A3.#used, Decl(privateNameUnused.ts, 16, 17), Decl(privateNameUnused.ts, 17, 29)) +>value : Symbol(value, Decl(privateNameUnused.ts, 18, 14)) + + get #unused() { return 0 }; +>#unused : Symbol(A3.#unused, Decl(privateNameUnused.ts, 18, 34), Decl(privateNameUnused.ts, 20, 31)) + + set #unused(value: number) { }; +>#unused : Symbol(A3.#unused, Decl(privateNameUnused.ts, 18, 34), Decl(privateNameUnused.ts, 20, 31)) +>value : Symbol(value, Decl(privateNameUnused.ts, 21, 16)) + + constructor () { + console.log(this.#used); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#used : Symbol(A3.#used, Decl(privateNameUnused.ts, 16, 17), Decl(privateNameUnused.ts, 17, 29)) +>this : Symbol(A3, Decl(privateNameUnused.ts, 14, 1)) + } +} diff --git a/tests/baselines/reference/privateNameUnused.types b/tests/baselines/reference/privateNameUnused.types index dc56a8f2a9e47..66ab9cf92e9be 100644 --- a/tests/baselines/reference/privateNameUnused.types +++ b/tests/baselines/reference/privateNameUnused.types @@ -21,3 +21,53 @@ export class A { } } +export class A2 { +>A2 : A2 + + #used() { }; +>#used : () => void + + #unused() { }; +>#unused : () => void + + constructor () { + console.log(this.#used()); +>console.log(this.#used()) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#used() : void +>this.#used : () => void +>this : this + } +} + +export class A3 { +>A3 : A3 + + get #used() { return 0 }; +>#used : number +>0 : 0 + + set #used(value: number) { }; +>#used : number +>value : number + + get #unused() { return 0 }; +>#unused : number +>0 : 0 + + set #unused(value: number) { }; +>#unused : number +>value : number + + constructor () { + console.log(this.#used); +>console.log(this.#used) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#used : number +>this : this + } +} diff --git a/tests/baselines/reference/privateNameWeakMapCollision.errors.txt b/tests/baselines/reference/privateNameWeakMapCollision.errors.txt index 6c4904cec79e1..7d76977a61311 100644 --- a/tests/baselines/reference/privateNameWeakMapCollision.errors.txt +++ b/tests/baselines/reference/privateNameWeakMapCollision.errors.txt @@ -1,11 +1,15 @@ tests/cases/compiler/privateNameWeakMapCollision.ts(2,9): error TS18027: Compiler reserves name 'WeakMap' when emitting private identifier downlevel. +tests/cases/compiler/privateNameWeakMapCollision.ts(3,9): error TS18027: Compiler reserves name 'WeakSet' when emitting private identifier downlevel. -==== tests/cases/compiler/privateNameWeakMapCollision.ts (1 errors) ==== +==== tests/cases/compiler/privateNameWeakMapCollision.ts (2 errors) ==== function test() { let WeakMap; ~~~~~~~ !!! error TS18027: Compiler reserves name 'WeakMap' when emitting private identifier downlevel. + let WeakSet; + ~~~~~~~ +!!! error TS18027: Compiler reserves name 'WeakSet' when emitting private identifier downlevel. class C { #x; } diff --git a/tests/baselines/reference/privateNameWeakMapCollision.js b/tests/baselines/reference/privateNameWeakMapCollision.js index 8b810f62240ae..969751b46aba9 100644 --- a/tests/baselines/reference/privateNameWeakMapCollision.js +++ b/tests/baselines/reference/privateNameWeakMapCollision.js @@ -1,6 +1,7 @@ //// [privateNameWeakMapCollision.ts] function test() { let WeakMap; + let WeakSet; class C { #x; } @@ -9,12 +10,13 @@ function test() { //// [privateNameWeakMapCollision.js] function test() { - var _x; + var _C_x; let WeakMap; + let WeakSet; class C { constructor() { - _x.set(this, void 0); + _C_x.set(this, void 0); } } - _x = new WeakMap(); + _C_x = new WeakMap(); } diff --git a/tests/baselines/reference/privateNameWeakMapCollision.symbols b/tests/baselines/reference/privateNameWeakMapCollision.symbols index 5bfd7d8070508..22f2cdb8304c1 100644 --- a/tests/baselines/reference/privateNameWeakMapCollision.symbols +++ b/tests/baselines/reference/privateNameWeakMapCollision.symbols @@ -5,11 +5,14 @@ function test() { let WeakMap; >WeakMap : Symbol(WeakMap, Decl(privateNameWeakMapCollision.ts, 1, 7)) + let WeakSet; +>WeakSet : Symbol(WeakSet, Decl(privateNameWeakMapCollision.ts, 2, 7)) + class C { ->C : Symbol(C, Decl(privateNameWeakMapCollision.ts, 1, 16)) +>C : Symbol(C, Decl(privateNameWeakMapCollision.ts, 2, 16)) #x; ->#x : Symbol(C.#x, Decl(privateNameWeakMapCollision.ts, 2, 13)) +>#x : Symbol(C.#x, Decl(privateNameWeakMapCollision.ts, 3, 13)) } } diff --git a/tests/baselines/reference/privateNameWeakMapCollision.types b/tests/baselines/reference/privateNameWeakMapCollision.types index 377c3f214c436..4475f6950d02d 100644 --- a/tests/baselines/reference/privateNameWeakMapCollision.types +++ b/tests/baselines/reference/privateNameWeakMapCollision.types @@ -5,6 +5,9 @@ function test() { let WeakMap; >WeakMap : any + let WeakSet; +>WeakSet : any + class C { >C : C diff --git a/tests/baselines/reference/privateNamesAndDecorators.errors.txt b/tests/baselines/reference/privateNamesAndDecorators.errors.txt index aea3772ca2e9d..a17770c1cb2a7 100644 --- a/tests/baselines/reference/privateNamesAndDecorators.errors.txt +++ b/tests/baselines/reference/privateNamesAndDecorators.errors.txt @@ -1,9 +1,8 @@ tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.ts(4,5): error TS1206: Decorators are not valid here. tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.ts(6,5): error TS1206: Decorators are not valid here. -tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.ts(7,5): error TS18022: A method cannot be named with a private identifier. -==== tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.ts (3 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.ts (2 errors) ==== declare function dec(target: T): T; class A { @@ -15,7 +14,5 @@ tests/cases/conformance/classes/members/privateNames/privateNamesAndDecorators.t ~ !!! error TS1206: Decorators are not valid here. #bar(): void { } - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. } \ No newline at end of file diff --git a/tests/baselines/reference/privateNamesAndDecorators.js b/tests/baselines/reference/privateNamesAndDecorators.js index 63183cf3df9ba..087ad2bb9a512 100644 --- a/tests/baselines/reference/privateNamesAndDecorators.js +++ b/tests/baselines/reference/privateNamesAndDecorators.js @@ -10,12 +10,12 @@ class A { //// [privateNamesAndDecorators.js] -var _foo; +var _A_instances, _A_foo, _A_bar; var A = /** @class */ (function () { function A() { - _foo.set(this, 1); + _A_instances.add(this); + _A_foo.set(this, 1); } - A.prototype. = function () { }; return A; }()); -_foo = new WeakMap(); +_A_foo = new WeakMap(), _A_instances = new WeakSet(), _A_bar = function _A_bar() { }; diff --git a/tests/baselines/reference/privateNamesAndFields.js b/tests/baselines/reference/privateNamesAndFields.js index 5af74f92ab9a0..69beae57f5d64 100644 --- a/tests/baselines/reference/privateNamesAndFields.js +++ b/tests/baselines/reference/privateNamesAndFields.js @@ -17,26 +17,25 @@ class B extends A { //// [privateNamesAndFields.js] "use strict"; -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _foo, _foo_1; +var _A_foo, _B_foo; class A { constructor() { - _foo.set(this, void 0); - __classPrivateFieldSet(this, _foo, 3); + _A_foo.set(this, void 0); + __classPrivateFieldSet(this, _A_foo, 3, "f"); } } -_foo = new WeakMap(); +_A_foo = new WeakMap(); class B extends A { constructor() { super(); - _foo_1.set(this, void 0); - __classPrivateFieldSet(this, _foo_1, "some string"); + _B_foo.set(this, void 0); + __classPrivateFieldSet(this, _B_foo, "some string", "f"); } } -_foo_1 = new WeakMap(); +_B_foo = new WeakMap(); diff --git a/tests/baselines/reference/privateNamesAndGenericClasses-2.errors.txt b/tests/baselines/reference/privateNamesAndGenericClasses-2.errors.txt index c44ec084989b9..c06298c2693a3 100644 --- a/tests/baselines/reference/privateNamesAndGenericClasses-2.errors.txt +++ b/tests/baselines/reference/privateNamesAndGenericClasses-2.errors.txt @@ -1,4 +1,3 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts(3,5): error TS18022: A method cannot be named with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts(24,3): error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts(25,1): error TS2322: Type 'C' is not assignable to type 'C'. Type 'string' is not assignable to type 'number'. @@ -6,12 +5,10 @@ tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClass Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts (4 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesAndGenericClasses-2.ts (3 errors) ==== class C { #foo: T; #bar(): T { - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. return this.#foo; } constructor(t: T) { diff --git a/tests/baselines/reference/privateNamesAndGenericClasses-2.js b/tests/baselines/reference/privateNamesAndGenericClasses-2.js index 0d62474bc636c..8e0d5c27c5619 100644 --- a/tests/baselines/reference/privateNamesAndGenericClasses-2.js +++ b/tests/baselines/reference/privateNamesAndGenericClasses-2.js @@ -29,37 +29,35 @@ b = a; // Error //// [privateNamesAndGenericClasses-2.js] "use strict"; -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo; +var _C_instances, _C_foo, _C_bar; class C { constructor(t) { - _foo.set(this, void 0); - __classPrivateFieldSet(this, _foo, t); - t = this..call(this); - } - () { - return __classPrivateFieldGet(this, _foo); + _C_instances.add(this); + _C_foo.set(this, void 0); + __classPrivateFieldSet(this, _C_foo, t, "f"); + t = __classPrivateFieldGet(this, _C_instances, "m", _C_bar).call(this); } set baz(t) { - __classPrivateFieldSet(this, _foo, t); + __classPrivateFieldSet(this, _C_foo, t, "f"); } get baz() { - return __classPrivateFieldGet(this, _foo); + return __classPrivateFieldGet(this, _C_foo, "f"); } } -_foo = new WeakMap(); +_C_foo = new WeakMap(), _C_instances = new WeakSet(), _C_bar = function _C_bar() { + return __classPrivateFieldGet(this, _C_foo, "f"); +}; let a = new C(3); let b = new C("hello"); a.baz = 5; // OK diff --git a/tests/baselines/reference/privateNamesAndIndexedAccess.js b/tests/baselines/reference/privateNamesAndIndexedAccess.js index 19487e81479cb..1b36a27bf0c11 100644 --- a/tests/baselines/reference/privateNamesAndIndexedAccess.js +++ b/tests/baselines/reference/privateNamesAndIndexedAccess.js @@ -14,11 +14,11 @@ class C { //// [privateNamesAndIndexedAccess.js] "use strict"; -var _bar; +var _C_bar; class C { constructor() { this.foo = 3; - _bar.set(this, 3); + _C_bar.set(this, 3); const ok = 3; // not supported yet, could support in future: const badForNow, #bar; @@ -27,4 +27,4 @@ class C { const badAlways = 3; // Error } } -_bar = new WeakMap(); +_C_bar = new WeakMap(); diff --git a/tests/baselines/reference/privateNamesAndMethods.errors.txt b/tests/baselines/reference/privateNamesAndMethods.errors.txt deleted file mode 100644 index a213c9911be49..0000000000000 --- a/tests/baselines/reference/privateNamesAndMethods.errors.txt +++ /dev/null @@ -1,51 +0,0 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts(2,5): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts(3,11): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts(4,12): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts(8,9): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts(11,9): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts(24,5): error TS18022: A method cannot be named with a private identifier. - - -==== tests/cases/conformance/classes/members/privateNames/privateNamesAndMethods.ts (6 errors) ==== - class A { - #foo(a: number) {} - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - async #bar(a: number) {} - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - async *#baz(a: number) { - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - return 3; - } - #_quux: number; - get #quux (): number { - ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. - return this.#_quux; - } - set #quux (val: number) { - ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. - 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: string) {} - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - constructor () { - super(); - this.#foo("str"); - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/privateNamesAndStaticFields.errors.txt b/tests/baselines/reference/privateNamesAndStaticFields.errors.txt index 4ff9fb50d9295..5efd57230d022 100644 --- a/tests/baselines/reference/privateNamesAndStaticFields.errors.txt +++ b/tests/baselines/reference/privateNamesAndStaticFields.errors.txt @@ -1,18 +1,11 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts(2,5): error TS18019: 'static' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts(3,5): error TS18019: 'static' modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts(6,11): error TS18013: Property '#foo' is not accessible outside class 'B' because it has a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts(7,11): error TS2339: Property '#bar' does not exist on type 'typeof B'. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts(12,5): error TS18019: 'static' modifier cannot be used with a private identifier. -==== tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts (5 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields.ts (2 errors) ==== class A { static #foo: number; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. static #bar: number; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. constructor () { A.#foo = 3; B.#foo; // Error @@ -26,8 +19,6 @@ tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticFields class B extends A { static #foo: string; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. constructor () { super(); B.#foo = "some string"; diff --git a/tests/baselines/reference/privateNamesAndStaticFields.js b/tests/baselines/reference/privateNamesAndStaticFields.js index 5b3458d049a7f..a9bba00f8e17a 100644 --- a/tests/baselines/reference/privateNamesAndStaticFields.js +++ b/tests/baselines/reference/privateNamesAndStaticFields.js @@ -24,35 +24,36 @@ const willErrorSomeDay: typeof A = class {}; // OK for now //// [privateNamesAndStaticFields.js] "use strict"; -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _bar, _foo_1; +var _a, _A_foo, _A_bar, _b, _B_foo; class A { constructor() { - __classPrivateFieldSet(A, _foo, 3); - __classPrivateFieldGet(B, _foo); // Error - __classPrivateFieldGet(B, _bar); // Error + __classPrivateFieldSet(A, _a, 3, "f", _A_foo); + __classPrivateFieldGet(B, _a, "f", _A_foo); // Error + __classPrivateFieldGet(B, _a, "f", _A_bar); // Error } } -_foo = new WeakMap(), _bar = new WeakMap(); +_a = A; +_A_foo = { value: void 0 }; +_A_bar = { value: void 0 }; class B extends A { constructor() { super(); - __classPrivateFieldSet(B, _foo_1, "some string"); + __classPrivateFieldSet(B, _b, "some string", "f", _B_foo); } } -_foo_1 = new WeakMap(); +_b = B; +_B_foo = { value: void 0 }; // We currently filter out static private identifier fields in `getUnmatchedProperties`. // We will need a more robust solution when we support static fields const willErrorSomeDay = class { diff --git a/tests/baselines/reference/privateNamesAndStaticMethods.errors.txt b/tests/baselines/reference/privateNamesAndStaticMethods.errors.txt deleted file mode 100644 index 795afd395fe6e..0000000000000 --- a/tests/baselines/reference/privateNamesAndStaticMethods.errors.txt +++ /dev/null @@ -1,54 +0,0 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(2,12): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(3,18): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(4,19): error TS18022: A method cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(7,5): error TS18019: 'static' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(8,16): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(11,16): error TS18023: An accessor cannot be named with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts(24,12): error TS18022: A method cannot be named with a private identifier. - - -==== tests/cases/conformance/classes/members/privateNames/privateNamesAndStaticMethods.ts (7 errors) ==== - class A { - static #foo(a: number) {} - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - static async #bar(a: number) {} - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - static async *#baz(a: number) { - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - return 3; - } - static #_quux: number; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. - static get #quux (): number { - ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. - return this.#_quux; - } - static set #quux (val: number) { - ~~~~~ -!!! error TS18023: An accessor cannot be named with a private identifier. - 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: string) {} - ~~~~ -!!! error TS18022: A method cannot be named with a private identifier. - constructor () { - super(); - B.#foo("str"); - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/privateNamesAndkeyof.errors.txt b/tests/baselines/reference/privateNamesAndkeyof.errors.txt new file mode 100644 index 0000000000000..eb8ee8b6426a5 --- /dev/null +++ b/tests/baselines/reference/privateNamesAndkeyof.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts(14,1): error TS2322: Type '"#fooField"' is not assignable to type 'keyof A'. +tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts(15,1): error TS2322: Type '"#fooMethod"' is not assignable to type 'keyof A'. +tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts(16,1): error TS2322: Type '"#fooProp"' is not assignable to type 'keyof A'. +tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts(18,1): error TS2322: Type '"fooField"' is not assignable to type 'keyof A'. +tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts(19,1): error TS2322: Type '"fooMethod"' is not assignable to type 'keyof A'. +tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts(20,1): error TS2322: Type '"fooProp"' is not assignable to type 'keyof A'. + + +==== tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts (6 errors) ==== + class A { + #fooField = 3; + #fooMethod() { }; + get #fooProp() { return 1; }; + set #fooProp(value: number) { }; + bar = 3; + baz = 3; + } + + // `keyof A` should not include '#foo*' + let k: keyof A = "bar"; // OK + k = "baz"; // OK + + k = "#fooField"; // Error + ~ +!!! error TS2322: Type '"#fooField"' is not assignable to type 'keyof A'. + k = "#fooMethod"; // Error + ~ +!!! error TS2322: Type '"#fooMethod"' is not assignable to type 'keyof A'. + k = "#fooProp"; // Error + ~ +!!! error TS2322: Type '"#fooProp"' is not assignable to type 'keyof A'. + + k = "fooField"; // Error + ~ +!!! error TS2322: Type '"fooField"' is not assignable to type 'keyof A'. + k = "fooMethod"; // Error + ~ +!!! error TS2322: Type '"fooMethod"' is not assignable to type 'keyof A'. + k = "fooProp"; // Error + ~ +!!! error TS2322: Type '"fooProp"' is not assignable to type 'keyof A'. + \ No newline at end of file diff --git a/tests/baselines/reference/privateNamesAndkeyof.js b/tests/baselines/reference/privateNamesAndkeyof.js index 46750f78874dd..8497493f65a37 100644 --- a/tests/baselines/reference/privateNamesAndkeyof.js +++ b/tests/baselines/reference/privateNamesAndkeyof.js @@ -1,21 +1,47 @@ //// [privateNamesAndkeyof.ts] class A { - #foo = 3; + #fooField = 3; + #fooMethod() { }; + get #fooProp() { return 1; }; + set #fooProp(value: number) { }; bar = 3; baz = 3; } -type T = keyof A // should not include '#foo' +// `keyof A` should not include '#foo*' +let k: keyof A = "bar"; // OK +k = "baz"; // OK + +k = "#fooField"; // Error +k = "#fooMethod"; // Error +k = "#fooProp"; // Error + +k = "fooField"; // Error +k = "fooMethod"; // Error +k = "fooProp"; // Error //// [privateNamesAndkeyof.js] "use strict"; -var _foo; +var _A_instances, _A_fooField, _A_fooMethod, _A_fooProp_get, _A_fooProp_set; class A { constructor() { - _foo.set(this, 3); + _A_instances.add(this); + _A_fooField.set(this, 3); this.bar = 3; this.baz = 3; } + ; + ; + ; } -_foo = new WeakMap(); +_A_fooField = new WeakMap(), _A_instances = new WeakSet(), _A_fooMethod = function _A_fooMethod() { }, _A_fooProp_get = function _A_fooProp_get() { return 1; }, _A_fooProp_set = function _A_fooProp_set(value) { }; +// `keyof A` should not include '#foo*' +let k = "bar"; // OK +k = "baz"; // OK +k = "#fooField"; // Error +k = "#fooMethod"; // Error +k = "#fooProp"; // Error +k = "fooField"; // Error +k = "fooMethod"; // Error +k = "fooProp"; // Error diff --git a/tests/baselines/reference/privateNamesAndkeyof.symbols b/tests/baselines/reference/privateNamesAndkeyof.symbols index dbad7e0aa748f..337b3ac32f246 100644 --- a/tests/baselines/reference/privateNamesAndkeyof.symbols +++ b/tests/baselines/reference/privateNamesAndkeyof.symbols @@ -2,17 +2,49 @@ class A { >A : Symbol(A, Decl(privateNamesAndkeyof.ts, 0, 0)) - #foo = 3; ->#foo : Symbol(A.#foo, Decl(privateNamesAndkeyof.ts, 0, 9)) + #fooField = 3; +>#fooField : Symbol(A.#fooField, Decl(privateNamesAndkeyof.ts, 0, 9)) + + #fooMethod() { }; +>#fooMethod : Symbol(A.#fooMethod, Decl(privateNamesAndkeyof.ts, 1, 18)) + + get #fooProp() { return 1; }; +>#fooProp : Symbol(A.#fooProp, Decl(privateNamesAndkeyof.ts, 2, 21), Decl(privateNamesAndkeyof.ts, 3, 33)) + + set #fooProp(value: number) { }; +>#fooProp : Symbol(A.#fooProp, Decl(privateNamesAndkeyof.ts, 2, 21), Decl(privateNamesAndkeyof.ts, 3, 33)) +>value : Symbol(value, Decl(privateNamesAndkeyof.ts, 4, 17)) bar = 3; ->bar : Symbol(A.bar, Decl(privateNamesAndkeyof.ts, 1, 13)) +>bar : Symbol(A.bar, Decl(privateNamesAndkeyof.ts, 4, 36)) baz = 3; ->baz : Symbol(A.baz, Decl(privateNamesAndkeyof.ts, 2, 12)) +>baz : Symbol(A.baz, Decl(privateNamesAndkeyof.ts, 5, 12)) } -type T = keyof A // should not include '#foo' ->T : Symbol(T, Decl(privateNamesAndkeyof.ts, 4, 1)) +// `keyof A` should not include '#foo*' +let k: keyof A = "bar"; // OK +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) >A : Symbol(A, Decl(privateNamesAndkeyof.ts, 0, 0)) +k = "baz"; // OK +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + +k = "#fooField"; // Error +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + +k = "#fooMethod"; // Error +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + +k = "#fooProp"; // Error +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + +k = "fooField"; // Error +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + +k = "fooMethod"; // Error +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + +k = "fooProp"; // Error +>k : Symbol(k, Decl(privateNamesAndkeyof.ts, 10, 3)) + diff --git a/tests/baselines/reference/privateNamesAndkeyof.types b/tests/baselines/reference/privateNamesAndkeyof.types index 3c063097dd464..dc5fa8297f83f 100644 --- a/tests/baselines/reference/privateNamesAndkeyof.types +++ b/tests/baselines/reference/privateNamesAndkeyof.types @@ -2,10 +2,21 @@ class A { >A : A - #foo = 3; ->#foo : number + #fooField = 3; +>#fooField : number >3 : 3 + #fooMethod() { }; +>#fooMethod : () => void + + get #fooProp() { return 1; }; +>#fooProp : number +>1 : 1 + + set #fooProp(value: number) { }; +>#fooProp : number +>value : number + bar = 3; >bar : number >3 : 3 @@ -15,6 +26,43 @@ class A { >3 : 3 } -type T = keyof A // should not include '#foo' ->T : keyof A +// `keyof A` should not include '#foo*' +let k: keyof A = "bar"; // OK +>k : keyof A +>"bar" : "bar" + +k = "baz"; // OK +>k = "baz" : "baz" +>k : keyof A +>"baz" : "baz" + +k = "#fooField"; // Error +>k = "#fooField" : "#fooField" +>k : keyof A +>"#fooField" : "#fooField" + +k = "#fooMethod"; // Error +>k = "#fooMethod" : "#fooMethod" +>k : keyof A +>"#fooMethod" : "#fooMethod" + +k = "#fooProp"; // Error +>k = "#fooProp" : "#fooProp" +>k : keyof A +>"#fooProp" : "#fooProp" + +k = "fooField"; // Error +>k = "fooField" : "fooField" +>k : keyof A +>"fooField" : "fooField" + +k = "fooMethod"; // Error +>k = "fooMethod" : "fooMethod" +>k : keyof A +>"fooMethod" : "fooMethod" + +k = "fooProp"; // Error +>k = "fooProp" : "fooProp" +>k : keyof A +>"fooProp" : "fooProp" diff --git a/tests/baselines/reference/privateNamesAssertion.js b/tests/baselines/reference/privateNamesAssertion.js index 66af365350b48..b6be4d5d4adf2 100644 --- a/tests/baselines/reference/privateNamesAssertion.js +++ b/tests/baselines/reference/privateNamesAssertion.js @@ -10,6 +10,18 @@ class Foo { v; } } + +class Foo2 { + #p1(v: any): asserts v is string { + if (typeof v !== "string") { + throw new Error(); + } + } + m1(v: unknown) { + this.#p1(v); + v; + } +} //// [privateNamesAssertion.js] @@ -28,3 +40,14 @@ class Foo { v; } } +class Foo2 { + #p1(v) { + if (typeof v !== "string") { + throw new Error(); + } + } + m1(v) { + this.#p1(v); + v; + } +} diff --git a/tests/baselines/reference/privateNamesAssertion.symbols b/tests/baselines/reference/privateNamesAssertion.symbols index 40d903912e734..2e0c423f2dd4d 100644 --- a/tests/baselines/reference/privateNamesAssertion.symbols +++ b/tests/baselines/reference/privateNamesAssertion.symbols @@ -29,3 +29,32 @@ class Foo { } } +class Foo2 { +>Foo2 : Symbol(Foo2, Decl(privateNamesAssertion.ts, 10, 1)) + + #p1(v: any): asserts v is string { +>#p1 : Symbol(Foo2.#p1, Decl(privateNamesAssertion.ts, 12, 12)) +>v : Symbol(v, Decl(privateNamesAssertion.ts, 13, 8)) +>v : Symbol(v, Decl(privateNamesAssertion.ts, 13, 8)) + + if (typeof v !== "string") { +>v : Symbol(v, Decl(privateNamesAssertion.ts, 13, 8)) + + throw new Error(); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + } + m1(v: unknown) { +>m1 : Symbol(Foo2.m1, Decl(privateNamesAssertion.ts, 17, 5)) +>v : Symbol(v, Decl(privateNamesAssertion.ts, 18, 7)) + + this.#p1(v); +>this.#p1 : Symbol(Foo2.#p1, Decl(privateNamesAssertion.ts, 12, 12)) +>this : Symbol(Foo2, Decl(privateNamesAssertion.ts, 10, 1)) +>v : Symbol(v, Decl(privateNamesAssertion.ts, 18, 7)) + + v; +>v : Symbol(v, Decl(privateNamesAssertion.ts, 18, 7)) + } +} + diff --git a/tests/baselines/reference/privateNamesAssertion.types b/tests/baselines/reference/privateNamesAssertion.types index ff0dd98d40219..44a052728e9eb 100644 --- a/tests/baselines/reference/privateNamesAssertion.types +++ b/tests/baselines/reference/privateNamesAssertion.types @@ -34,3 +34,36 @@ class Foo { } } +class Foo2 { +>Foo2 : Foo2 + + #p1(v: any): asserts v is string { +>#p1 : (v: any) => asserts v is string +>v : any + + if (typeof v !== "string") { +>typeof v !== "string" : boolean +>typeof v : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" +>v : any +>"string" : "string" + + throw new Error(); +>new Error() : Error +>Error : ErrorConstructor + } + } + m1(v: unknown) { +>m1 : (v: unknown) => void +>v : unknown + + this.#p1(v); +>this.#p1(v) : void +>this.#p1 : (v: any) => asserts v is string +>this : this +>v : unknown + + v; +>v : string + } +} + diff --git a/tests/baselines/reference/privateNamesConstructorChain-1.errors.txt b/tests/baselines/reference/privateNamesConstructorChain-1.errors.txt index badf4f2966f9e..a8d081a35662c 100644 --- a/tests/baselines/reference/privateNamesConstructorChain-1.errors.txt +++ b/tests/baselines/reference/privateNamesConstructorChain-1.errors.txt @@ -1,13 +1,10 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-1.ts(3,5): error TS18019: 'static' modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-1.ts(6,15): error TS2339: Property '#bar' does not exist on type 'typeof Child'. -==== tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-1.ts (2 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-1.ts (1 errors) ==== class Parent { #foo = 3; static #bar = 5; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. accessChildProps() { new Child().#foo; // OK (`#foo` was added when `Parent`'s constructor was called on `child`) Child.#bar; // Error: not found diff --git a/tests/baselines/reference/privateNamesConstructorChain-1.js b/tests/baselines/reference/privateNamesConstructorChain-1.js index dfba142f9aa53..cb4c1076945af 100644 --- a/tests/baselines/reference/privateNamesConstructorChain-1.js +++ b/tests/baselines/reference/privateNamesConstructorChain-1.js @@ -15,29 +15,28 @@ class Child extends Parent { //// [privateNamesConstructorChain-1.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _bar, _foo_1, _bar_1; +var _a, _Parent_foo, _Parent_bar, _Child_foo, _Child_bar; class Parent { constructor() { - _foo.set(this, 3); + _Parent_foo.set(this, 3); } accessChildProps() { - __classPrivateFieldGet(new Child(), _foo); // OK (`#foo` was added when `Parent`'s constructor was called on `child`) - __classPrivateFieldGet(Child, _bar); // Error: not found + __classPrivateFieldGet(new Child(), _Parent_foo, "f"); // OK (`#foo` was added when `Parent`'s constructor was called on `child`) + __classPrivateFieldGet(Child, _a, "f", _Parent_bar); // Error: not found } } -_foo = new WeakMap(), _bar = new WeakMap(); -_bar.set(Parent, 5); +_a = Parent, _Parent_foo = new WeakMap(); +_Parent_bar = { value: 5 }; class Child extends Parent { constructor() { super(...arguments); - _foo_1.set(this, "foo"); // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) - _bar_1.set(this, "bar"); // OK + _Child_foo.set(this, "foo"); // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) + _Child_bar.set(this, "bar"); // OK } } -_foo_1 = new WeakMap(), _bar_1 = new WeakMap(); +_Child_foo = new WeakMap(), _Child_bar = new WeakMap(); diff --git a/tests/baselines/reference/privateNamesConstructorChain-2.errors.txt b/tests/baselines/reference/privateNamesConstructorChain-2.errors.txt index b72ae5d84aea6..c9be71136b01c 100644 --- a/tests/baselines/reference/privateNamesConstructorChain-2.errors.txt +++ b/tests/baselines/reference/privateNamesConstructorChain-2.errors.txt @@ -1,13 +1,10 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-2.ts(3,5): error TS18019: 'static' modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-2.ts(6,15): error TS2339: Property '#bar' does not exist on type 'typeof Child'. -==== tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-2.ts (2 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesConstructorChain-2.ts (1 errors) ==== class Parent { #foo = 3; static #bar = 5; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. accessChildProps() { new Child().#foo; // OK (`#foo` was added when `Parent`'s constructor was called on `child`) Child.#bar; // Error: not found diff --git a/tests/baselines/reference/privateNamesConstructorChain-2.js b/tests/baselines/reference/privateNamesConstructorChain-2.js index 0d0069a47a9ad..80e569c8ab7bc 100644 --- a/tests/baselines/reference/privateNamesConstructorChain-2.js +++ b/tests/baselines/reference/privateNamesConstructorChain-2.js @@ -17,30 +17,29 @@ new Parent().accessChildProps(); //// [privateNamesConstructorChain-2.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _bar, _foo_1, _bar_1; +var _a, _Parent_foo, _Parent_bar, _Child_foo, _Child_bar; class Parent { constructor() { - _foo.set(this, 3); + _Parent_foo.set(this, 3); } accessChildProps() { - __classPrivateFieldGet(new Child(), _foo); // OK (`#foo` was added when `Parent`'s constructor was called on `child`) - __classPrivateFieldGet(Child, _bar); // Error: not found + __classPrivateFieldGet(new Child(), _Parent_foo, "f"); // OK (`#foo` was added when `Parent`'s constructor was called on `child`) + __classPrivateFieldGet(Child, _a, "f", _Parent_bar); // Error: not found } } -_foo = new WeakMap(), _bar = new WeakMap(); -_bar.set(Parent, 5); +_a = Parent, _Parent_foo = new WeakMap(); +_Parent_bar = { value: 5 }; class Child extends Parent { constructor() { super(...arguments); - _foo_1.set(this, "foo"); // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) - _bar_1.set(this, "bar"); // OK + _Child_foo.set(this, "foo"); // OK (Child's #foo does not conflict, as `Parent`'s `#foo` is not accessible) + _Child_bar.set(this, "bar"); // OK } } -_foo_1 = new WeakMap(), _bar_1 = new WeakMap(); +_Child_foo = new WeakMap(), _Child_bar = new WeakMap(); new Parent().accessChildProps(); diff --git a/tests/baselines/reference/privateNamesInGenericClasses.errors.txt b/tests/baselines/reference/privateNamesInGenericClasses.errors.txt index d617432535020..ece16935004da 100644 --- a/tests/baselines/reference/privateNamesInGenericClasses.errors.txt +++ b/tests/baselines/reference/privateNamesInGenericClasses.errors.txt @@ -1,16 +1,30 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(10,3): error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(11,1): error TS2322: Type 'C' is not assignable to type 'C'. +tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(22,3): error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(23,3): error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(24,3): error TS18013: Property '#prop' is not accessible outside class 'C' because it has a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(25,1): error TS2322: Type 'C' is not assignable to type 'C'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(12,1): error TS2322: Type 'C' is not assignable to type 'C'. +tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts(26,1): error TS2322: Type 'C' is not assignable to type 'C'. Type 'number' is not assignable to type 'string'. -==== tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts (3 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts (5 errors) ==== class C { #foo: T; + #method(): T { return this.#foo; } + get #prop(): T { return this.#foo; } + set #prop(value : T) { this.#foo = value; } + bar(x: C) { return x.#foo; } // OK + bar2(x: C) { return x.#method(); } // OK + bar3(x: C) { return x.#prop; } // OK + baz(x: C) { return x.#foo; } // OK + baz2(x: C) { return x.#method; } // OK + baz3(x: C) { return x.#prop; } // OK + quux(x: C) { return x.#foo; } // OK + quux2(x: C) { return x.#method; }// OK + quux3(x: C) { return x.#prop; } // OK } declare let a: C; @@ -18,6 +32,12 @@ tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasse a.#foo; // Error ~~~~ !!! error TS18013: Property '#foo' is not accessible outside class 'C' because it has a private identifier. + a.#method; // Error + ~~~~~~~ +!!! error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier. + a.#prop; // Error + ~~~~~ +!!! error TS18013: Property '#prop' is not accessible outside class 'C' because it has a private identifier. a = b; // Error ~ !!! error TS2322: Type 'C' is not assignable to type 'C'. diff --git a/tests/baselines/reference/privateNamesInGenericClasses.js b/tests/baselines/reference/privateNamesInGenericClasses.js index 27227fc0218e7..6817e938884e5 100644 --- a/tests/baselines/reference/privateNamesInGenericClasses.js +++ b/tests/baselines/reference/privateNamesInGenericClasses.js @@ -1,36 +1,64 @@ //// [privateNamesInGenericClasses.ts] class C { #foo: T; + #method(): T { return this.#foo; } + get #prop(): T { return this.#foo; } + set #prop(value : T) { this.#foo = value; } + bar(x: C) { return x.#foo; } // OK + bar2(x: C) { return x.#method(); } // OK + bar3(x: C) { return x.#prop; } // OK + baz(x: C) { return x.#foo; } // OK + baz2(x: C) { return x.#method; } // OK + baz3(x: C) { return x.#prop; } // OK + quux(x: C) { return x.#foo; } // OK + quux2(x: C) { return x.#method; }// OK + quux3(x: C) { return x.#prop; } // OK } declare let a: C; declare let b: C; a.#foo; // Error +a.#method; // Error +a.#prop; // Error a = b; // Error b = a; // Error //// [privateNamesInGenericClasses.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo; +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_instances, _C_foo, _C_method, _C_prop_get, _C_prop_set; class C { constructor() { - _foo.set(this, void 0); + _C_instances.add(this); + _C_foo.set(this, void 0); } - bar(x) { return __classPrivateFieldGet(x, _foo); } // OK - baz(x) { return __classPrivateFieldGet(x, _foo); } // OK - quux(x) { return __classPrivateFieldGet(x, _foo); } // OK + bar(x) { return __classPrivateFieldGet(x, _C_foo, "f"); } // OK + bar2(x) { return __classPrivateFieldGet(x, _C_instances, "m", _C_method).call(x); } // OK + bar3(x) { return __classPrivateFieldGet(x, _C_instances, "a", _C_prop_get); } // OK + baz(x) { return __classPrivateFieldGet(x, _C_foo, "f"); } // OK + baz2(x) { return __classPrivateFieldGet(x, _C_instances, "m", _C_method); } // OK + baz3(x) { return __classPrivateFieldGet(x, _C_instances, "a", _C_prop_get); } // OK + quux(x) { return __classPrivateFieldGet(x, _C_foo, "f"); } // OK + quux2(x) { return __classPrivateFieldGet(x, _C_instances, "m", _C_method); } // OK + quux3(x) { return __classPrivateFieldGet(x, _C_instances, "a", _C_prop_get); } // OK } -_foo = new WeakMap(); +_C_foo = new WeakMap(), _C_instances = new WeakSet(), _C_method = function _C_method() { return __classPrivateFieldGet(this, _C_foo, "f"); }, _C_prop_get = function _C_prop_get() { return __classPrivateFieldGet(this, _C_foo, "f"); }, _C_prop_set = function _C_prop_set(value) { __classPrivateFieldSet(this, _C_foo, value, "f"); }; +a.; // Error +a.; // Error a.; // Error a = b; // Error b = a; // Error diff --git a/tests/baselines/reference/privateNamesInGenericClasses.symbols b/tests/baselines/reference/privateNamesInGenericClasses.symbols index c697c06390869..9dac6c7484fa7 100644 --- a/tests/baselines/reference/privateNamesInGenericClasses.symbols +++ b/tests/baselines/reference/privateNamesInGenericClasses.symbols @@ -7,45 +7,115 @@ class C { >#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) >T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) + #method(): T { return this.#foo; } +>#method : Symbol(C.#method, Decl(privateNamesInGenericClasses.ts, 1, 12)) +>T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) +>this.#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) +>this : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) + + get #prop(): T { return this.#foo; } +>#prop : Symbol(C.#prop, Decl(privateNamesInGenericClasses.ts, 2, 38), Decl(privateNamesInGenericClasses.ts, 3, 40)) +>T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) +>this.#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) +>this : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) + + set #prop(value : T) { this.#foo = value; } +>#prop : Symbol(C.#prop, Decl(privateNamesInGenericClasses.ts, 2, 38), Decl(privateNamesInGenericClasses.ts, 3, 40)) +>value : Symbol(value, Decl(privateNamesInGenericClasses.ts, 4, 14)) +>T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) +>this.#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) +>this : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>value : Symbol(value, Decl(privateNamesInGenericClasses.ts, 4, 14)) + bar(x: C) { return x.#foo; } // OK ->bar : Symbol(C.bar, Decl(privateNamesInGenericClasses.ts, 1, 12)) ->x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 2, 8)) +>bar : Symbol(C.bar, Decl(privateNamesInGenericClasses.ts, 4, 47)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 6, 8)) >C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) >T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) >x.#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) ->x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 2, 8)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 6, 8)) + + bar2(x: C) { return x.#method(); } // OK +>bar2 : Symbol(C.bar2, Decl(privateNamesInGenericClasses.ts, 6, 35)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 7, 9)) +>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) +>x.#method : Symbol(C.#method, Decl(privateNamesInGenericClasses.ts, 1, 12)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 7, 9)) + + bar3(x: C) { return x.#prop; } // OK +>bar3 : Symbol(C.bar3, Decl(privateNamesInGenericClasses.ts, 7, 41)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 8, 9)) +>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8)) +>x.#prop : Symbol(C.#prop, Decl(privateNamesInGenericClasses.ts, 2, 38), Decl(privateNamesInGenericClasses.ts, 3, 40)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 8, 9)) baz(x: C) { return x.#foo; } // OK ->baz : Symbol(C.baz, Decl(privateNamesInGenericClasses.ts, 2, 35)) ->x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 3, 8)) +>baz : Symbol(C.baz, Decl(privateNamesInGenericClasses.ts, 8, 37)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 10, 8)) >C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) >x.#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) ->x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 3, 8)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 10, 8)) + + baz2(x: C) { return x.#method; } // OK +>baz2 : Symbol(C.baz2, Decl(privateNamesInGenericClasses.ts, 10, 40)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 11, 9)) +>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>x.#method : Symbol(C.#method, Decl(privateNamesInGenericClasses.ts, 1, 12)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 11, 9)) + + baz3(x: C) { return x.#prop; } // OK +>baz3 : Symbol(C.baz3, Decl(privateNamesInGenericClasses.ts, 11, 44)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 12, 9)) +>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>x.#prop : Symbol(C.#prop, Decl(privateNamesInGenericClasses.ts, 2, 38), Decl(privateNamesInGenericClasses.ts, 3, 40)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 12, 9)) quux(x: C) { return x.#foo; } // OK ->quux : Symbol(C.quux, Decl(privateNamesInGenericClasses.ts, 3, 40)) ->x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 4, 9)) +>quux : Symbol(C.quux, Decl(privateNamesInGenericClasses.ts, 12, 42)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 14, 9)) >C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) >x.#foo : Symbol(C.#foo, Decl(privateNamesInGenericClasses.ts, 0, 12)) ->x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 4, 9)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 14, 9)) + + quux2(x: C) { return x.#method; }// OK +>quux2 : Symbol(C.quux2, Decl(privateNamesInGenericClasses.ts, 14, 41)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 15, 10)) +>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>x.#method : Symbol(C.#method, Decl(privateNamesInGenericClasses.ts, 1, 12)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 15, 10)) + + quux3(x: C) { return x.#prop; } // OK +>quux3 : Symbol(C.quux3, Decl(privateNamesInGenericClasses.ts, 15, 45)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 16, 10)) +>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) +>x.#prop : Symbol(C.#prop, Decl(privateNamesInGenericClasses.ts, 2, 38), Decl(privateNamesInGenericClasses.ts, 3, 40)) +>x : Symbol(x, Decl(privateNamesInGenericClasses.ts, 16, 10)) } declare let a: C; ->a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 7, 11)) +>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11)) >C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) declare let b: C; ->b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 8, 11)) +>b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 20, 11)) >C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0)) a.#foo; // Error ->a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 7, 11)) +>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11)) + +a.#method; // Error +>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11)) + +a.#prop; // Error +>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11)) a = b; // Error ->a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 7, 11)) ->b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 8, 11)) +>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11)) +>b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 20, 11)) b = a; // Error ->b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 8, 11)) ->a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 7, 11)) +>b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 20, 11)) +>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11)) diff --git a/tests/baselines/reference/privateNamesInGenericClasses.types b/tests/baselines/reference/privateNamesInGenericClasses.types index e0a29a45492c1..c8f2b95121fd6 100644 --- a/tests/baselines/reference/privateNamesInGenericClasses.types +++ b/tests/baselines/reference/privateNamesInGenericClasses.types @@ -5,22 +5,77 @@ class C { #foo: T; >#foo : T + #method(): T { return this.#foo; } +>#method : () => T +>this.#foo : T +>this : this + + get #prop(): T { return this.#foo; } +>#prop : T +>this.#foo : T +>this : this + + set #prop(value : T) { this.#foo = value; } +>#prop : T +>value : T +>this.#foo = value : T +>this.#foo : T +>this : this +>value : T + bar(x: C) { return x.#foo; } // OK >bar : (x: C) => T >x : C >x.#foo : T +>x : C + + bar2(x: C) { return x.#method(); } // OK +>bar2 : (x: C) => T +>x : C +>x.#method() : T +>x.#method : () => T +>x : C + + bar3(x: C) { return x.#prop; } // OK +>bar3 : (x: C) => T +>x : C +>x.#prop : T >x : C baz(x: C) { return x.#foo; } // OK >baz : (x: C) => number >x : C >x.#foo : number +>x : C + + baz2(x: C) { return x.#method; } // OK +>baz2 : (x: C) => () => number +>x : C +>x.#method : () => number +>x : C + + baz3(x: C) { return x.#prop; } // OK +>baz3 : (x: C) => number +>x : C +>x.#prop : number >x : C quux(x: C) { return x.#foo; } // OK >quux : (x: C) => string >x : C >x.#foo : string +>x : C + + quux2(x: C) { return x.#method; }// OK +>quux2 : (x: C) => () => string +>x : C +>x.#method : () => string +>x : C + + quux3(x: C) { return x.#prop; } // OK +>quux3 : (x: C) => string +>x : C +>x.#prop : string >x : C } @@ -34,6 +89,14 @@ a.#foo; // Error >a.#foo : any >a : C +a.#method; // Error +>a.#method : any +>a : C + +a.#prop; // Error +>a.#prop : any +>a : C + a = b; // Error >a = b : C >a : C diff --git a/tests/baselines/reference/privateNamesInNestedClasses-1.js b/tests/baselines/reference/privateNamesInNestedClasses-1.js index 12804200745da..a40651375293d 100644 --- a/tests/baselines/reference/privateNamesInNestedClasses-1.js +++ b/tests/baselines/reference/privateNamesInNestedClasses-1.js @@ -28,35 +28,34 @@ new A().method(); //// [privateNamesInNestedClasses-1.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _bar; +var _A_foo, _A_bar; class A { constructor() { - _foo.set(this, "A's #foo"); - _bar.set(this, "A's #bar"); + _A_foo.set(this, "A's #foo"); + _A_bar.set(this, "A's #bar"); } method() { - var _foo_1; + var _B_foo; class B { constructor() { - _foo_1.set(this, "B's #foo"); + _B_foo.set(this, "B's #foo"); } bar(a) { - __classPrivateFieldGet(a, _foo_1); // OK, no compile-time error, don't know what `a` is + __classPrivateFieldGet(a, _B_foo, "f"); // OK, no compile-time error, don't know what `a` is } baz(a) { - __classPrivateFieldGet(a, _foo_1); // compile-time error, shadowed + __classPrivateFieldGet(a, _B_foo, "f"); // compile-time error, shadowed } quux(b) { - __classPrivateFieldGet(b, _foo_1); // OK + __classPrivateFieldGet(b, _B_foo, "f"); // OK } } - _foo_1 = new WeakMap(); + _B_foo = new WeakMap(); const a = new A(); new B().bar(a); new B().baz(a); @@ -64,5 +63,5 @@ class A { new B().quux(b); } } -_foo = new WeakMap(), _bar = new WeakMap(); +_A_foo = new WeakMap(), _A_bar = new WeakMap(); new A().method(); diff --git a/tests/baselines/reference/privateNamesInNestedClasses-2.errors.txt b/tests/baselines/reference/privateNamesInNestedClasses-2.errors.txt index 01c69f9b0f2ae..c9c8c78ce2c43 100644 --- a/tests/baselines/reference/privateNamesInNestedClasses-2.errors.txt +++ b/tests/baselines/reference/privateNamesInNestedClasses-2.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesInNestedClasses-2.ts(2,5): error TS18019: 'static' modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesInNestedClasses-2.ts(9,27): error TS18014: The property '#x' cannot be accessed on type 'typeof A' within this class because it is shadowed by another private identifier with the same spelling. -==== tests/cases/conformance/classes/members/privateNames/privateNamesInNestedClasses-2.ts (2 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesInNestedClasses-2.ts (1 errors) ==== class A { static #x = 5; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. constructor () { class B { #x = 5; diff --git a/tests/baselines/reference/privateNamesInNestedClasses-2.js b/tests/baselines/reference/privateNamesInNestedClasses-2.js index 896beb6308339..6b879f0c55cd1 100644 --- a/tests/baselines/reference/privateNamesInNestedClasses-2.js +++ b/tests/baselines/reference/privateNamesInNestedClasses-2.js @@ -18,28 +18,27 @@ class A { //// [privateNamesInNestedClasses-2.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _x; +var _a, _A_x; class A { constructor() { - var _x_1; + var _B_x; class B { constructor() { - _x_1.set(this, 5); + _B_x.set(this, 5); class C { constructor() { - __classPrivateFieldGet(A, _x_1); // error + __classPrivateFieldGet(A, _B_x, "f"); // error } } } } - _x_1 = new WeakMap(); + _B_x = new WeakMap(); } } -_x = new WeakMap(); -_x.set(A, 5); +_a = A; +_A_x = { value: 5 }; diff --git a/tests/baselines/reference/privateNamesIncompatibleModifiers.errors.txt b/tests/baselines/reference/privateNamesIncompatibleModifiers.errors.txt index 9aa840a2f49e5..f1f44a3d4f143 100644 --- a/tests/baselines/reference/privateNamesIncompatibleModifiers.errors.txt +++ b/tests/baselines/reference/privateNamesIncompatibleModifiers.errors.txt @@ -1,11 +1,30 @@ +error TS2318: Cannot find global type 'AsyncIterableIterator'. tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(2,5): error TS18010: An accessibility modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(3,5): error TS18010: An accessibility modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(4,5): error TS18010: An accessibility modifier cannot be used with a private identifier. tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(6,5): error TS18019: 'declare' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(10,5): error TS18019: 'abstract' modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(8,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(9,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(10,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(11,5): error TS1024: 'readonly' modifier can only appear on a property declaration or index signature. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(12,5): error TS1031: 'declare' modifier cannot appear on class elements of this kind. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(17,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(18,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(19,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(20,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(21,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(22,5): error TS18010: An accessibility modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(23,5): error TS1024: 'readonly' modifier can only appear on a property declaration or index signature. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(24,5): error TS1024: 'readonly' modifier can only appear on a property declaration or index signature. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(25,5): error TS1031: 'declare' modifier cannot appear on class elements of this kind. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(26,5): error TS1031: 'declare' modifier cannot appear on class elements of this kind. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(27,5): error TS1042: 'async' modifier cannot be used here. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(28,5): error TS1042: 'async' modifier cannot be used here. +tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts(32,5): error TS18019: 'abstract' modifier cannot be used with a private identifier. -==== tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts (5 errors) ==== +!!! error TS2318: Cannot find global type 'AsyncIterableIterator'. +==== tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts (22 errors) ==== class A { public #foo = 3; // Error ~~~~~~ @@ -20,6 +39,62 @@ tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleMod declare #what: number; // Error ~~~~~~~ !!! error TS18019: 'declare' modifier cannot be used with a private identifier. + + public #fooMethod() { return 3; } // Error + ~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + private #barMethod() { return 3; } // Error + ~~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + protected #bazMethod() { return 3; } // Error + ~~~~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + readonly #quxMethod() { return 3; } // Error + ~~~~~~~~ +!!! error TS1024: 'readonly' modifier can only appear on a property declaration or index signature. + declare #whatMethod() // Error + ~~~~~~~ +!!! error TS1031: 'declare' modifier cannot appear on class elements of this kind. + async #asyncMethod() { return 1; } //OK + *#genMethod() { return 1; } //OK + async *#asyncGenMethod() { return 1; } //OK + + public get #fooProp() { return 3; } // Error + ~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + public set #fooProp(value: number) { } // Error + ~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + private get #barProp() { return 3; } // Error + ~~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + private set #barProp(value: number) { } // Error + ~~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + protected get #bazProp() { return 3; } // Error + ~~~~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + protected set #bazProp(value: number) { } // Error + ~~~~~~~~~ +!!! error TS18010: An accessibility modifier cannot be used with a private identifier. + readonly get #quxProp() { return 3; } // Error + ~~~~~~~~ +!!! error TS1024: 'readonly' modifier can only appear on a property declaration or index signature. + readonly set #quxProp(value: number) { } // Error + ~~~~~~~~ +!!! error TS1024: 'readonly' modifier can only appear on a property declaration or index signature. + declare get #whatProp() // Error + ~~~~~~~ +!!! error TS1031: 'declare' modifier cannot appear on class elements of this kind. + declare set #whatProp(value: number) // Error + ~~~~~~~ +!!! error TS1031: 'declare' modifier cannot appear on class elements of this kind. + async get #asyncProp() { return 1; } // Error + ~~~~~ +!!! error TS1042: 'async' modifier cannot be used here. + async set #asyncProp(value: number) { } // Error + ~~~~~ +!!! error TS1042: 'async' modifier cannot be used here. } abstract class B { diff --git a/tests/baselines/reference/privateNamesIncompatibleModifiers.js b/tests/baselines/reference/privateNamesIncompatibleModifiers.js index f6e731d371d88..23a87dd94c8a9 100644 --- a/tests/baselines/reference/privateNamesIncompatibleModifiers.js +++ b/tests/baselines/reference/privateNamesIncompatibleModifiers.js @@ -5,6 +5,28 @@ class A { protected #baz = 3; // Error readonly #qux = 3; // OK declare #what: number; // Error + + public #fooMethod() { return 3; } // Error + private #barMethod() { return 3; } // Error + protected #bazMethod() { return 3; } // Error + readonly #quxMethod() { return 3; } // Error + declare #whatMethod() // Error + async #asyncMethod() { return 1; } //OK + *#genMethod() { return 1; } //OK + async *#asyncGenMethod() { return 1; } //OK + + public get #fooProp() { return 3; } // Error + public set #fooProp(value: number) { } // Error + private get #barProp() { return 3; } // Error + private set #barProp(value: number) { } // Error + protected get #bazProp() { return 3; } // Error + protected set #bazProp(value: number) { } // Error + readonly get #quxProp() { return 3; } // Error + readonly set #quxProp(value: number) { } // Error + declare get #whatProp() // Error + declare set #whatProp(value: number) // Error + async get #asyncProp() { return 1; } // Error + async set #asyncProp(value: number) { } // Error } abstract class B { @@ -14,15 +36,43 @@ abstract class B { //// [privateNamesIncompatibleModifiers.js] "use strict"; -var _foo, _bar, _baz, _qux; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +var _A_instances, _A_foo, _A_bar, _A_baz, _A_qux, _A_fooMethod, _A_barMethod, _A_bazMethod, _A_quxMethod, _A_asyncMethod, _A_genMethod, _A_asyncGenMethod, _A_fooProp_get, _A_fooProp_set, _A_barProp_get, _A_barProp_set, _A_bazProp_get, _A_bazProp_set, _A_quxProp_get, _A_quxProp_set, _A_whatProp_get, _A_whatProp_set, _A_asyncProp_get, _A_asyncProp_set; class A { constructor() { - _foo.set(this, 3); // Error - _bar.set(this, 3); // Error - _baz.set(this, 3); // Error - _qux.set(this, 3); // OK + _A_instances.add(this); + _A_foo.set(this, 3); // Error + _A_bar.set(this, 3); // Error + _A_baz.set(this, 3); // Error + _A_qux.set(this, 3); // OK } } -_foo = new WeakMap(), _bar = new WeakMap(), _baz = new WeakMap(), _qux = new WeakMap(); +_A_foo = new WeakMap(), _A_bar = new WeakMap(), _A_baz = new WeakMap(), _A_qux = new WeakMap(), _A_instances = new WeakSet(), _A_fooMethod = function _A_fooMethod() { return 3; }, _A_barMethod = function _A_barMethod() { return 3; }, _A_bazMethod = function _A_bazMethod() { return 3; }, _A_quxMethod = function _A_quxMethod() { return 3; }, _A_asyncMethod = function _A_asyncMethod() { + return __awaiter(this, void 0, void 0, function* () { return 1; }); +}, _A_genMethod = function* _A_genMethod() { return 1; }, _A_asyncGenMethod = function _A_asyncGenMethod() { return __asyncGenerator(this, arguments, function* _A_asyncGenMethod_1() { return yield __await(1); }); }, _A_fooProp_get = function _A_fooProp_get() { return 3; }, _A_fooProp_set = function _A_fooProp_set(value) { }, _A_barProp_get = function _A_barProp_get() { return 3; }, _A_barProp_set = function _A_barProp_set(value) { }, _A_bazProp_get = function _A_bazProp_get() { return 3; }, _A_bazProp_set = function _A_bazProp_set(value) { }, _A_quxProp_get = function _A_quxProp_get() { return 3; }, _A_quxProp_set = function _A_quxProp_set(value) { }, _A_whatProp_get = function _A_whatProp_get() { }, _A_whatProp_set = function _A_whatProp_set(value) { }, _A_asyncProp_get = function _A_asyncProp_get() { + return __awaiter(this, void 0, void 0, function* () { return 1; }); +}, _A_asyncProp_set = function _A_asyncProp_set(value) { + return __awaiter(this, void 0, void 0, function* () { }); +}; class B { } diff --git a/tests/baselines/reference/privateNamesIncompatibleModifiers.symbols b/tests/baselines/reference/privateNamesIncompatibleModifiers.symbols index 65d665cb1d107..ffc3c0244c59b 100644 --- a/tests/baselines/reference/privateNamesIncompatibleModifiers.symbols +++ b/tests/baselines/reference/privateNamesIncompatibleModifiers.symbols @@ -16,12 +16,78 @@ class A { declare #what: number; // Error >#what : Symbol(A.#what, Decl(privateNamesIncompatibleModifiers.ts, 4, 22)) + + public #fooMethod() { return 3; } // Error +>#fooMethod : Symbol(A.#fooMethod, Decl(privateNamesIncompatibleModifiers.ts, 5, 26)) + + private #barMethod() { return 3; } // Error +>#barMethod : Symbol(A.#barMethod, Decl(privateNamesIncompatibleModifiers.ts, 7, 38)) + + protected #bazMethod() { return 3; } // Error +>#bazMethod : Symbol(A.#bazMethod, Decl(privateNamesIncompatibleModifiers.ts, 8, 39)) + + readonly #quxMethod() { return 3; } // Error +>#quxMethod : Symbol(A.#quxMethod, Decl(privateNamesIncompatibleModifiers.ts, 9, 41)) + + declare #whatMethod() // Error +>#whatMethod : Symbol(A.#whatMethod, Decl(privateNamesIncompatibleModifiers.ts, 10, 40)) + + async #asyncMethod() { return 1; } //OK +>#asyncMethod : Symbol(A.#asyncMethod, Decl(privateNamesIncompatibleModifiers.ts, 11, 25)) + + *#genMethod() { return 1; } //OK +>#genMethod : Symbol(A.#genMethod, Decl(privateNamesIncompatibleModifiers.ts, 12, 38)) + + async *#asyncGenMethod() { return 1; } //OK +>#asyncGenMethod : Symbol(A.#asyncGenMethod, Decl(privateNamesIncompatibleModifiers.ts, 13, 31)) + + public get #fooProp() { return 3; } // Error +>#fooProp : Symbol(A.#fooProp, Decl(privateNamesIncompatibleModifiers.ts, 14, 42), Decl(privateNamesIncompatibleModifiers.ts, 16, 40)) + + public set #fooProp(value: number) { } // Error +>#fooProp : Symbol(A.#fooProp, Decl(privateNamesIncompatibleModifiers.ts, 14, 42), Decl(privateNamesIncompatibleModifiers.ts, 16, 40)) +>value : Symbol(value, Decl(privateNamesIncompatibleModifiers.ts, 17, 24)) + + private get #barProp() { return 3; } // Error +>#barProp : Symbol(A.#barProp, Decl(privateNamesIncompatibleModifiers.ts, 17, 43), Decl(privateNamesIncompatibleModifiers.ts, 18, 41)) + + private set #barProp(value: number) { } // Error +>#barProp : Symbol(A.#barProp, Decl(privateNamesIncompatibleModifiers.ts, 17, 43), Decl(privateNamesIncompatibleModifiers.ts, 18, 41)) +>value : Symbol(value, Decl(privateNamesIncompatibleModifiers.ts, 19, 25)) + + protected get #bazProp() { return 3; } // Error +>#bazProp : Symbol(A.#bazProp, Decl(privateNamesIncompatibleModifiers.ts, 19, 44), Decl(privateNamesIncompatibleModifiers.ts, 20, 43)) + + protected set #bazProp(value: number) { } // Error +>#bazProp : Symbol(A.#bazProp, Decl(privateNamesIncompatibleModifiers.ts, 19, 44), Decl(privateNamesIncompatibleModifiers.ts, 20, 43)) +>value : Symbol(value, Decl(privateNamesIncompatibleModifiers.ts, 21, 27)) + + readonly get #quxProp() { return 3; } // Error +>#quxProp : Symbol(A.#quxProp, Decl(privateNamesIncompatibleModifiers.ts, 21, 46), Decl(privateNamesIncompatibleModifiers.ts, 22, 42)) + + readonly set #quxProp(value: number) { } // Error +>#quxProp : Symbol(A.#quxProp, Decl(privateNamesIncompatibleModifiers.ts, 21, 46), Decl(privateNamesIncompatibleModifiers.ts, 22, 42)) +>value : Symbol(value, Decl(privateNamesIncompatibleModifiers.ts, 23, 26)) + + declare get #whatProp() // Error +>#whatProp : Symbol(A.#whatProp, Decl(privateNamesIncompatibleModifiers.ts, 23, 45), Decl(privateNamesIncompatibleModifiers.ts, 24, 27)) + + declare set #whatProp(value: number) // Error +>#whatProp : Symbol(A.#whatProp, Decl(privateNamesIncompatibleModifiers.ts, 23, 45), Decl(privateNamesIncompatibleModifiers.ts, 24, 27)) +>value : Symbol(value, Decl(privateNamesIncompatibleModifiers.ts, 25, 26)) + + async get #asyncProp() { return 1; } // Error +>#asyncProp : Symbol(A.#asyncProp, Decl(privateNamesIncompatibleModifiers.ts, 25, 40), Decl(privateNamesIncompatibleModifiers.ts, 26, 40)) + + async set #asyncProp(value: number) { } // Error +>#asyncProp : Symbol(A.#asyncProp, Decl(privateNamesIncompatibleModifiers.ts, 25, 40), Decl(privateNamesIncompatibleModifiers.ts, 26, 40)) +>value : Symbol(value, Decl(privateNamesIncompatibleModifiers.ts, 27, 25)) } abstract class B { ->B : Symbol(B, Decl(privateNamesIncompatibleModifiers.ts, 6, 1)) +>B : Symbol(B, Decl(privateNamesIncompatibleModifiers.ts, 28, 1)) abstract #quux = 3; // Error ->#quux : Symbol(B.#quux, Decl(privateNamesIncompatibleModifiers.ts, 8, 18)) +>#quux : Symbol(B.#quux, Decl(privateNamesIncompatibleModifiers.ts, 30, 18)) } diff --git a/tests/baselines/reference/privateNamesIncompatibleModifiers.types b/tests/baselines/reference/privateNamesIncompatibleModifiers.types index ac2f60f67ff18..2b4f2ac2a456a 100644 --- a/tests/baselines/reference/privateNamesIncompatibleModifiers.types +++ b/tests/baselines/reference/privateNamesIncompatibleModifiers.types @@ -20,6 +20,84 @@ class A { declare #what: number; // Error >#what : number + + public #fooMethod() { return 3; } // Error +>#fooMethod : () => number +>3 : 3 + + private #barMethod() { return 3; } // Error +>#barMethod : () => number +>3 : 3 + + protected #bazMethod() { return 3; } // Error +>#bazMethod : () => number +>3 : 3 + + readonly #quxMethod() { return 3; } // Error +>#quxMethod : () => number +>3 : 3 + + declare #whatMethod() // Error +>#whatMethod : () => any + + async #asyncMethod() { return 1; } //OK +>#asyncMethod : () => Promise +>1 : 1 + + *#genMethod() { return 1; } //OK +>#genMethod : () => Generator +>1 : 1 + + async *#asyncGenMethod() { return 1; } //OK +>#asyncGenMethod : () => {} +>1 : 1 + + public get #fooProp() { return 3; } // Error +>#fooProp : number +>3 : 3 + + public set #fooProp(value: number) { } // Error +>#fooProp : number +>value : number + + private get #barProp() { return 3; } // Error +>#barProp : number +>3 : 3 + + private set #barProp(value: number) { } // Error +>#barProp : number +>value : number + + protected get #bazProp() { return 3; } // Error +>#bazProp : number +>3 : 3 + + protected set #bazProp(value: number) { } // Error +>#bazProp : number +>value : number + + readonly get #quxProp() { return 3; } // Error +>#quxProp : number +>3 : 3 + + readonly set #quxProp(value: number) { } // Error +>#quxProp : number +>value : number + + declare get #whatProp() // Error +>#whatProp : number + + declare set #whatProp(value: number) // Error +>#whatProp : number +>value : number + + async get #asyncProp() { return 1; } // Error +>#asyncProp : number +>1 : 1 + + async set #asyncProp(value: number) { } // Error +>#asyncProp : number +>value : number } abstract class B { diff --git a/tests/baselines/reference/privateNamesInterfaceExtendingClass.js b/tests/baselines/reference/privateNamesInterfaceExtendingClass.js index f6bbc9fa54dc8..d43aaaa1b27b9 100644 --- a/tests/baselines/reference/privateNamesInterfaceExtendingClass.js +++ b/tests/baselines/reference/privateNamesInterfaceExtendingClass.js @@ -14,23 +14,22 @@ function func(x: I) { //// [privateNamesInterfaceExtendingClass.js] -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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 _prop; +var _C_prop; class C { constructor() { - _prop.set(this, void 0); + _C_prop.set(this, void 0); } func(x) { - __classPrivateFieldSet(x, _prop, 123); + __classPrivateFieldSet(x, _C_prop, 123, "f"); } } -_prop = new WeakMap(); +_C_prop = new WeakMap(); function func(x) { x. = 123; } diff --git a/tests/baselines/reference/privateNamesNoDelete.js b/tests/baselines/reference/privateNamesNoDelete.js index 22aecf24cca31..dc60d87edec5b 100644 --- a/tests/baselines/reference/privateNamesNoDelete.js +++ b/tests/baselines/reference/privateNamesNoDelete.js @@ -9,17 +9,16 @@ class A { //// [privateNamesNoDelete.js] "use strict"; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _v; +var _A_v; class A { constructor() { - _v.set(this, 1); - delete __classPrivateFieldGet(this, _v); // Error: The operand of a delete operator cannot be a private name. + _A_v.set(this, 1); + delete __classPrivateFieldGet(this, _A_v, "f"); // Error: The operand of a delete operator cannot be a private name. } } -_v = new WeakMap(); +_A_v = new WeakMap(); diff --git a/tests/baselines/reference/privateNamesUnique-1.js b/tests/baselines/reference/privateNamesUnique-1.js index 1fb8b7255c9bf..cab1354d7b004 100644 --- a/tests/baselines/reference/privateNamesUnique-1.js +++ b/tests/baselines/reference/privateNamesUnique-1.js @@ -12,17 +12,17 @@ const b: A = new B(); // Error: Property #foo is missing //// [privateNamesUnique-1.js] "use strict"; -var _foo, _foo_1; +var _A_foo, _B_foo; class A { constructor() { - _foo.set(this, void 0); + _A_foo.set(this, void 0); } } -_foo = new WeakMap(); +_A_foo = new WeakMap(); class B { constructor() { - _foo_1.set(this, void 0); + _B_foo.set(this, void 0); } } -_foo_1 = new WeakMap(); +_B_foo = new WeakMap(); const b = new B(); // Error: Property #foo is missing diff --git a/tests/baselines/reference/privateNamesUnique-2.js b/tests/baselines/reference/privateNamesUnique-2.js index 4f772551b544a..563007f6b8083 100644 --- a/tests/baselines/reference/privateNamesUnique-2.js +++ b/tests/baselines/reference/privateNamesUnique-2.js @@ -23,30 +23,29 @@ a.copy(b); // error //// [b.js] -var _x; +var _Foo_x; export class Foo { constructor() { - _x.set(this, void 0); + _Foo_x.set(this, void 0); } } -_x = new WeakMap(); +_Foo_x = new WeakMap(); //// [a.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _x; +var _Foo_x; export class Foo { constructor() { - _x.set(this, void 0); + _Foo_x.set(this, void 0); } copy(other) { - __classPrivateFieldGet(other, _x); // error + __classPrivateFieldGet(other, _Foo_x, "f"); // error } } -_x = new WeakMap(); +_Foo_x = new WeakMap(); //// [main.js] import { Foo as A } from "./a"; import { Foo as B } from "./b"; diff --git a/tests/baselines/reference/privateNamesUnique-3.errors.txt b/tests/baselines/reference/privateNamesUnique-3.errors.txt index 51084f4d40561..d77e1823388a5 100644 --- a/tests/baselines/reference/privateNamesUnique-3.errors.txt +++ b/tests/baselines/reference/privateNamesUnique-3.errors.txt @@ -1,25 +1,19 @@ -tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts(3,5): error TS18019: 'static' modifier cannot be used with a private identifier. -tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts(3,12): error TS2300: Duplicate identifier '#foo'. -tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts(9,5): error TS18019: 'static' modifier cannot be used with a private identifier. +tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts(3,12): error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts(11,11): error TS2339: Property '#foo' does not exist on type 'B'. -==== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts (4 errors) ==== +==== tests/cases/conformance/classes/members/privateNames/privateNamesUnique-3.ts (2 errors) ==== class A { #foo = 1; static #foo = true; // error (duplicate) - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. ~~~~ -!!! error TS2300: Duplicate identifier '#foo'. +!!! error TS2804: Duplicate identifier '#foo'. Static and instance elements cannot share the same private name. // because static and instance private names // share the same lexical scope // https://tc39.es/proposal-class-fields/#prod-ClassBody } class B { static #foo = true; - ~~~~~~ -!!! error TS18019: 'static' modifier cannot be used with a private identifier. test(x: B) { x.#foo; // error (#foo is a static property on B, not an instance property) ~~~~ diff --git a/tests/baselines/reference/privateNamesUnique-3.js b/tests/baselines/reference/privateNamesUnique-3.js index 9575d6d89c57d..5d4257eecd2c3 100644 --- a/tests/baselines/reference/privateNamesUnique-3.js +++ b/tests/baselines/reference/privateNamesUnique-3.js @@ -15,27 +15,28 @@ class B { //// [privateNamesUnique-3.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _foo_1, _foo_2; +var _a, _A_foo, _A_foo_1, _b, _B_foo; class A { constructor() { - _foo_1.set(this, 1); + _A_foo_1 = { value: 1 }; // because static and instance private names // share the same lexical scope // https://tc39.es/proposal-class-fields/#prod-ClassBody } + #foo = 1; + static #foo = true; // error (duplicate) } -_foo = new WeakMap(), _foo_1 = new WeakMap(); -_foo_1.set(A, true); // error (duplicate) +_a = A, _A_foo = new WeakMap(); +_A_foo_1 = { value: true }; // error (duplicate) class B { test(x) { - __classPrivateFieldGet(x, _foo_2); // error (#foo is a static property on B, not an instance property) + __classPrivateFieldGet(x, _b, "f", _B_foo); // error (#foo is a static property on B, not an instance property) } } -_foo_2 = new WeakMap(); -_foo_2.set(B, true); +_b = B; +_B_foo = { value: true }; diff --git a/tests/baselines/reference/privateNamesUnique-4.js b/tests/baselines/reference/privateNamesUnique-4.js index 38db50f3475bf..15ca00f318b01 100644 --- a/tests/baselines/reference/privateNamesUnique-4.js +++ b/tests/baselines/reference/privateNamesUnique-4.js @@ -8,13 +8,13 @@ const c: C = a; //// [privateNamesUnique-4.js] -var _something; +var _C_something; class A1 { } class C { constructor() { - _something.set(this, void 0); + _C_something.set(this, void 0); } } -_something = new WeakMap(); +_C_something = new WeakMap(); const c = a; diff --git a/tests/baselines/reference/privateNamesUnique-5.js b/tests/baselines/reference/privateNamesUnique-5.js index 75d378c1f1d03..fa8eb5639a966 100644 --- a/tests/baselines/reference/privateNamesUnique-5.js +++ b/tests/baselines/reference/privateNamesUnique-5.js @@ -16,17 +16,17 @@ const b: A2 = new B(); //// [privateNamesUnique-5.js] "use strict"; // same as privateNamesUnique-1, but with an interface -var _foo, _foo_1; +var _A_foo, _B_foo; class A { constructor() { - _foo.set(this, void 0); + _A_foo.set(this, void 0); } } -_foo = new WeakMap(); +_A_foo = new WeakMap(); class B { constructor() { - _foo_1.set(this, void 0); + _B_foo.set(this, void 0); } } -_foo_1 = new WeakMap(); +_B_foo = new WeakMap(); const b = new B(); diff --git a/tests/baselines/reference/privateNamesUseBeforeDef.errors.txt b/tests/baselines/reference/privateNamesUseBeforeDef.errors.txt index 7105d8d9481e8..fdf69c642e2c8 100644 --- a/tests/baselines/reference/privateNamesUseBeforeDef.errors.txt +++ b/tests/baselines/reference/privateNamesUseBeforeDef.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts(2,17): error TS2729: Property '#bar' is used before its initialization. -tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts(7,17): error TS2729: Property '#bar' is used before its initialization. +tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts(17,17): error TS2729: Property '#bar' is used before its initialization. ==== tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts (2 errors) ==== @@ -11,11 +11,21 @@ tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts #bar = 3; } + class A2 { + #foo = this.#bar(); // No Error + #bar() { return 3 }; + } + + class A3 { + #foo = this.#bar; // No Error + get #bar() { return 3 }; + } + class B { #foo = this.#bar; // Error ~~~~ !!! error TS2729: Property '#bar' is used before its initialization. -!!! related TS2728 tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts:8:5: '#bar' is declared here. +!!! related TS2728 tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts:18:5: '#bar' is declared here. #bar = this.#foo; } \ No newline at end of file diff --git a/tests/baselines/reference/privateNamesUseBeforeDef.js b/tests/baselines/reference/privateNamesUseBeforeDef.js index 06b5316189dce..3521d28206b07 100644 --- a/tests/baselines/reference/privateNamesUseBeforeDef.js +++ b/tests/baselines/reference/privateNamesUseBeforeDef.js @@ -4,6 +4,16 @@ class A { #bar = 3; } +class A2 { + #foo = this.#bar(); // No Error + #bar() { return 3 }; +} + +class A3 { + #foo = this.#bar; // No Error + get #bar() { return 3 }; +} + class B { #foo = this.#bar; // Error #bar = this.#foo; @@ -11,24 +21,39 @@ class B { //// [privateNamesUseBeforeDef.js] -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _foo, _bar, _foo_1, _bar_1; +var _A_foo, _A_bar, _A2_instances, _A2_foo, _A2_bar, _A3_instances, _A3_foo, _A3_bar_get, _B_foo, _B_bar; class A { constructor() { - _foo.set(this, __classPrivateFieldGet(this, _bar)); // Error - _bar.set(this, 3); + _A_foo.set(this, __classPrivateFieldGet(this, _A_bar, "f")); // Error + _A_bar.set(this, 3); + } +} +_A_foo = new WeakMap(), _A_bar = new WeakMap(); +class A2 { + constructor() { + _A2_instances.add(this); + _A2_foo.set(this, __classPrivateFieldGet(this, _A2_instances, "m", _A2_bar).call(this)); // No Error + } + ; +} +_A2_foo = new WeakMap(), _A2_instances = new WeakSet(), _A2_bar = function _A2_bar() { return 3; }; +class A3 { + constructor() { + _A3_instances.add(this); + _A3_foo.set(this, __classPrivateFieldGet(this, _A3_instances, "a", _A3_bar_get)); // No Error } + ; } -_foo = new WeakMap(), _bar = new WeakMap(); +_A3_foo = new WeakMap(), _A3_instances = new WeakSet(), _A3_bar_get = function _A3_bar_get() { return 3; }; class B { constructor() { - _foo_1.set(this, __classPrivateFieldGet(this, _bar_1)); // Error - _bar_1.set(this, __classPrivateFieldGet(this, _foo_1)); + _B_foo.set(this, __classPrivateFieldGet(this, _B_bar, "f")); // Error + _B_bar.set(this, __classPrivateFieldGet(this, _B_foo, "f")); } } -_foo_1 = new WeakMap(), _bar_1 = new WeakMap(); +_B_foo = new WeakMap(), _B_bar = new WeakMap(); diff --git a/tests/baselines/reference/privateNamesUseBeforeDef.symbols b/tests/baselines/reference/privateNamesUseBeforeDef.symbols index 21df1931d9760..025f8625c39c9 100644 --- a/tests/baselines/reference/privateNamesUseBeforeDef.symbols +++ b/tests/baselines/reference/privateNamesUseBeforeDef.symbols @@ -11,17 +11,41 @@ class A { >#bar : Symbol(A.#bar, Decl(privateNamesUseBeforeDef.ts, 1, 21)) } +class A2 { +>A2 : Symbol(A2, Decl(privateNamesUseBeforeDef.ts, 3, 1)) + + #foo = this.#bar(); // No Error +>#foo : Symbol(A2.#foo, Decl(privateNamesUseBeforeDef.ts, 5, 10)) +>this.#bar : Symbol(A2.#bar, Decl(privateNamesUseBeforeDef.ts, 6, 23)) +>this : Symbol(A2, Decl(privateNamesUseBeforeDef.ts, 3, 1)) + + #bar() { return 3 }; +>#bar : Symbol(A2.#bar, Decl(privateNamesUseBeforeDef.ts, 6, 23)) +} + +class A3 { +>A3 : Symbol(A3, Decl(privateNamesUseBeforeDef.ts, 8, 1)) + + #foo = this.#bar; // No Error +>#foo : Symbol(A3.#foo, Decl(privateNamesUseBeforeDef.ts, 10, 10)) +>this.#bar : Symbol(A3.#bar, Decl(privateNamesUseBeforeDef.ts, 11, 21)) +>this : Symbol(A3, Decl(privateNamesUseBeforeDef.ts, 8, 1)) + + get #bar() { return 3 }; +>#bar : Symbol(A3.#bar, Decl(privateNamesUseBeforeDef.ts, 11, 21)) +} + class B { ->B : Symbol(B, Decl(privateNamesUseBeforeDef.ts, 3, 1)) +>B : Symbol(B, Decl(privateNamesUseBeforeDef.ts, 13, 1)) #foo = this.#bar; // Error ->#foo : Symbol(B.#foo, Decl(privateNamesUseBeforeDef.ts, 5, 9)) ->this.#bar : Symbol(B.#bar, Decl(privateNamesUseBeforeDef.ts, 6, 21)) ->this : Symbol(B, Decl(privateNamesUseBeforeDef.ts, 3, 1)) +>#foo : Symbol(B.#foo, Decl(privateNamesUseBeforeDef.ts, 15, 9)) +>this.#bar : Symbol(B.#bar, Decl(privateNamesUseBeforeDef.ts, 16, 21)) +>this : Symbol(B, Decl(privateNamesUseBeforeDef.ts, 13, 1)) #bar = this.#foo; ->#bar : Symbol(B.#bar, Decl(privateNamesUseBeforeDef.ts, 6, 21)) ->this.#foo : Symbol(B.#foo, Decl(privateNamesUseBeforeDef.ts, 5, 9)) ->this : Symbol(B, Decl(privateNamesUseBeforeDef.ts, 3, 1)) +>#bar : Symbol(B.#bar, Decl(privateNamesUseBeforeDef.ts, 16, 21)) +>this.#foo : Symbol(B.#foo, Decl(privateNamesUseBeforeDef.ts, 15, 9)) +>this : Symbol(B, Decl(privateNamesUseBeforeDef.ts, 13, 1)) } diff --git a/tests/baselines/reference/privateNamesUseBeforeDef.types b/tests/baselines/reference/privateNamesUseBeforeDef.types index 4f43c5b48234c..d729927e47b8d 100644 --- a/tests/baselines/reference/privateNamesUseBeforeDef.types +++ b/tests/baselines/reference/privateNamesUseBeforeDef.types @@ -12,6 +12,33 @@ class A { >3 : 3 } +class A2 { +>A2 : A2 + + #foo = this.#bar(); // No Error +>#foo : number +>this.#bar() : number +>this.#bar : () => number +>this : this + + #bar() { return 3 }; +>#bar : () => number +>3 : 3 +} + +class A3 { +>A3 : A3 + + #foo = this.#bar; // No Error +>#foo : number +>this.#bar : number +>this : this + + get #bar() { return 3 }; +>#bar : number +>3 : 3 +} + class B { >B : B diff --git a/tests/baselines/reference/privateStaticNameShadowing.js b/tests/baselines/reference/privateStaticNameShadowing.js new file mode 100644 index 0000000000000..c300ba650e29a --- /dev/null +++ b/tests/baselines/reference/privateStaticNameShadowing.js @@ -0,0 +1,34 @@ +//// [privateStaticNameShadowing.ts] +class X { + static #f = X.#m(); + constructor() { + X.#m(); + } + static #m() { + const X: any = {}; // shadow the class + const _a: any = {}; // shadow the first generated var + X.#m(); // Should check with X as the receiver with _b as the class constructor + return 1; + } + } + + +//// [privateStaticNameShadowing.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 _b, _X_f, _X_m; +class X { + constructor() { + __classPrivateFieldGet(X, _b, "m", _X_m).call(X); + } +} +_b = X, _X_m = function _X_m() { + const X = {}; // shadow the class + const _a = {}; // shadow the first generated var + __classPrivateFieldGet(X, _b, "m", _X_m).call(X); // Should check with X as the receiver with _b as the class constructor + return 1; +}; +_X_f = { value: __classPrivateFieldGet(X, _b, "m", _X_m).call(X) }; diff --git a/tests/baselines/reference/privateStaticNameShadowing.symbols b/tests/baselines/reference/privateStaticNameShadowing.symbols new file mode 100644 index 0000000000000..95ad9ffc738bb --- /dev/null +++ b/tests/baselines/reference/privateStaticNameShadowing.symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/classes/members/privateNames/privateStaticNameShadowing.ts === +class X { +>X : Symbol(X, Decl(privateStaticNameShadowing.ts, 0, 0)) + + static #f = X.#m(); +>#f : Symbol(X.#f, Decl(privateStaticNameShadowing.ts, 0, 9)) +>X.#m : Symbol(X.#m, Decl(privateStaticNameShadowing.ts, 4, 5)) +>X : Symbol(X, Decl(privateStaticNameShadowing.ts, 0, 0)) + + constructor() { + X.#m(); +>X.#m : Symbol(X.#m, Decl(privateStaticNameShadowing.ts, 4, 5)) +>X : Symbol(X, Decl(privateStaticNameShadowing.ts, 0, 0)) + } + static #m() { +>#m : Symbol(X.#m, Decl(privateStaticNameShadowing.ts, 4, 5)) + + const X: any = {}; // shadow the class +>X : Symbol(X, Decl(privateStaticNameShadowing.ts, 6, 11)) + + const _a: any = {}; // shadow the first generated var +>_a : Symbol(_a, Decl(privateStaticNameShadowing.ts, 7, 11)) + + X.#m(); // Should check with X as the receiver with _b as the class constructor +>X : Symbol(X, Decl(privateStaticNameShadowing.ts, 6, 11)) + + return 1; + } + } + diff --git a/tests/baselines/reference/privateStaticNameShadowing.types b/tests/baselines/reference/privateStaticNameShadowing.types new file mode 100644 index 0000000000000..e636c4d063344 --- /dev/null +++ b/tests/baselines/reference/privateStaticNameShadowing.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/classes/members/privateNames/privateStaticNameShadowing.ts === +class X { +>X : X + + static #f = X.#m(); +>#f : number +>X.#m() : number +>X.#m : () => number +>X : typeof X + + constructor() { + X.#m(); +>X.#m() : number +>X.#m : () => number +>X : typeof X + } + static #m() { +>#m : () => number + + const X: any = {}; // shadow the class +>X : any +>{} : {} + + const _a: any = {}; // shadow the first generated var +>_a : any +>{} : {} + + X.#m(); // Should check with X as the receiver with _b as the class constructor +>X.#m() : any +>X.#m : any +>X : any + + return 1; +>1 : 1 + } + } + diff --git a/tests/baselines/reference/privateWriteOnlyAccessorRead.errors.txt b/tests/baselines/reference/privateWriteOnlyAccessorRead.errors.txt new file mode 100644 index 0000000000000..10153c7f55259 --- /dev/null +++ b/tests/baselines/reference/privateWriteOnlyAccessorRead.errors.txt @@ -0,0 +1,61 @@ +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(9,17): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(12,5): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(17,13): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(19,17): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(22,18): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(26,9): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(27,12): error TS2806: Private accessor was defined without a getter. +tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts(30,5): error TS2806: Private accessor was defined without a getter. + + +==== tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts (8 errors) ==== + class Test { + set #value(v: { foo: { bar: number } }) {} + set #valueRest(v: number[]) {} + set #valueOne(v: number) {} + set #valueCompound(v: number) {} + + m() { + const foo = { bar: 1 }; + console.log(this.#value); // error + ~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + this.#value = { foo }; // ok + this.#value = { foo }; // ok + this.#value.foo = foo; // error + ~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + + ({ o: this.#value } = { o: { foo } }); //ok + ({ ...this.#value } = { foo }); //ok + + ({ foo: this.#value.foo } = { foo }); //error + ~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + ({ + foo: { ...this.#value.foo }, + ~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + } = { foo }); //error + + let r = { o: this.#value }; //error + ~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + + [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; + let arr = [ + this.#valueOne, + ~~~~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + ...this.#valueRest + ~~~~~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + ]; + + this.#valueCompound += 3; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2806: Private accessor was defined without a getter. + } + } + new Test().m(); + \ No newline at end of file diff --git a/tests/baselines/reference/privateWriteOnlyAccessorRead.js b/tests/baselines/reference/privateWriteOnlyAccessorRead.js new file mode 100644 index 0000000000000..8761f3f667fa1 --- /dev/null +++ b/tests/baselines/reference/privateWriteOnlyAccessorRead.js @@ -0,0 +1,88 @@ +//// [privateWriteOnlyAccessorRead.ts] +class Test { + set #value(v: { foo: { bar: number } }) {} + set #valueRest(v: number[]) {} + set #valueOne(v: number) {} + set #valueCompound(v: number) {} + + m() { + const foo = { bar: 1 }; + console.log(this.#value); // error + this.#value = { foo }; // ok + this.#value = { foo }; // ok + this.#value.foo = foo; // error + + ({ o: this.#value } = { o: { foo } }); //ok + ({ ...this.#value } = { foo }); //ok + + ({ foo: this.#value.foo } = { foo }); //error + ({ + foo: { ...this.#value.foo }, + } = { foo }); //error + + let r = { o: this.#value }; //error + + [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; + let arr = [ + this.#valueOne, + ...this.#valueRest + ]; + + this.#valueCompound += 3; + } +} +new Test().m(); + + +//// [privateWriteOnlyAccessorRead.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 __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _Test_instances, _Test_value_set, _Test_valueRest_set, _Test_valueOne_set, _Test_valueCompound_set; +class Test { + constructor() { + _Test_instances.add(this); + } + m() { + var _a, _b, _c; + const foo = { bar: 1 }; + console.log(__classPrivateFieldGet(this, _Test_instances, "a")); // error + __classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok + __classPrivateFieldSet(this, _Test_instances, { foo }, "a", _Test_value_set); // ok + __classPrivateFieldGet(this, _Test_instances, "a").foo = foo; // error + (_a = this, { o: ({ set value(_d) { __classPrivateFieldSet(_a, _Test_instances, _d, "a", _Test_value_set); } }).value } = { o: { foo } }); //ok + (__classPrivateFieldGet(this, _Test_instances, "a") = __rest({ foo }, [])); //ok + ({ foo: __classPrivateFieldGet(this, _Test_instances, "a").foo } = { foo }); //error + ({ + foo: Object.assign({}, __classPrivateFieldGet(this, _Test_instances, "a").foo), + } = { foo }); //error + let r = { o: __classPrivateFieldGet(this, _Test_instances, "a") }; //error + _b = this, _c = this, [({ set value(_d) { __classPrivateFieldSet(_b, _Test_instances, _d, "a", _Test_valueOne_set); } }).value, ...({ set value(_d) { __classPrivateFieldSet(_c, _Test_instances, _d, "a", _Test_valueRest_set); } }).value] = [1, 2, 3]; + let arr = [ + __classPrivateFieldGet(this, _Test_instances, "a"), + ...__classPrivateFieldGet(this, _Test_instances, "a") + ]; + __classPrivateFieldSet(this, _Test_instances, __classPrivateFieldGet(this, _Test_instances, "a") + 3, "a", _Test_valueCompound_set); + } +} +_Test_instances = new WeakSet(), _Test_value_set = function _Test_value_set(v) { }, _Test_valueRest_set = function _Test_valueRest_set(v) { }, _Test_valueOne_set = function _Test_valueOne_set(v) { }, _Test_valueCompound_set = function _Test_valueCompound_set(v) { }; +new Test().m(); diff --git a/tests/baselines/reference/privateWriteOnlyAccessorRead.symbols b/tests/baselines/reference/privateWriteOnlyAccessorRead.symbols new file mode 100644 index 0000000000000..d422e533c316c --- /dev/null +++ b/tests/baselines/reference/privateWriteOnlyAccessorRead.symbols @@ -0,0 +1,119 @@ +=== tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts === +class Test { +>Test : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + + set #value(v: { foo: { bar: number } }) {} +>#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>v : Symbol(v, Decl(privateWriteOnlyAccessorRead.ts, 1, 13)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) +>bar : Symbol(bar, Decl(privateWriteOnlyAccessorRead.ts, 1, 24)) + + set #valueRest(v: number[]) {} +>#valueRest : Symbol(Test.#valueRest, Decl(privateWriteOnlyAccessorRead.ts, 1, 44)) +>v : Symbol(v, Decl(privateWriteOnlyAccessorRead.ts, 2, 17)) + + set #valueOne(v: number) {} +>#valueOne : Symbol(Test.#valueOne, Decl(privateWriteOnlyAccessorRead.ts, 2, 32)) +>v : Symbol(v, Decl(privateWriteOnlyAccessorRead.ts, 3, 16)) + + set #valueCompound(v: number) {} +>#valueCompound : Symbol(Test.#valueCompound, Decl(privateWriteOnlyAccessorRead.ts, 3, 29)) +>v : Symbol(v, Decl(privateWriteOnlyAccessorRead.ts, 4, 21)) + + m() { +>m : Symbol(Test.m, Decl(privateWriteOnlyAccessorRead.ts, 4, 34)) + + const foo = { bar: 1 }; +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 7, 9)) +>bar : Symbol(bar, Decl(privateWriteOnlyAccessorRead.ts, 7, 17)) + + console.log(this.#value); // error +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + + this.#value = { foo }; // ok +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 9, 19)) + + this.#value = { foo }; // ok +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 10, 19)) + + this.#value.foo = foo; // error +>this.#value.foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 7, 9)) + + ({ o: this.#value } = { o: { foo } }); //ok +>o : Symbol(o, Decl(privateWriteOnlyAccessorRead.ts, 13, 6)) +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>o : Symbol(o, Decl(privateWriteOnlyAccessorRead.ts, 13, 27)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 13, 32)) + + ({ ...this.#value } = { foo }); //ok +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 14, 27)) + + ({ foo: this.#value.foo } = { foo }); //error +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 16, 6)) +>this.#value.foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 16, 33)) + + ({ + foo: { ...this.#value.foo }, +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 17, 6)) +>this.#value.foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 1, 17)) + + } = { foo }); //error +>foo : Symbol(foo, Decl(privateWriteOnlyAccessorRead.ts, 19, 9)) + + let r = { o: this.#value }; //error +>r : Symbol(r, Decl(privateWriteOnlyAccessorRead.ts, 21, 7)) +>o : Symbol(o, Decl(privateWriteOnlyAccessorRead.ts, 21, 13)) +>this.#value : Symbol(Test.#value, Decl(privateWriteOnlyAccessorRead.ts, 0, 12)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + + [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; +>this.#valueOne : Symbol(Test.#valueOne, Decl(privateWriteOnlyAccessorRead.ts, 2, 32)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>this.#valueRest : Symbol(Test.#valueRest, Decl(privateWriteOnlyAccessorRead.ts, 1, 44)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + + let arr = [ +>arr : Symbol(arr, Decl(privateWriteOnlyAccessorRead.ts, 24, 7)) + + this.#valueOne, +>this.#valueOne : Symbol(Test.#valueOne, Decl(privateWriteOnlyAccessorRead.ts, 2, 32)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + + ...this.#valueRest +>this.#valueRest : Symbol(Test.#valueRest, Decl(privateWriteOnlyAccessorRead.ts, 1, 44)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + + ]; + + this.#valueCompound += 3; +>this.#valueCompound : Symbol(Test.#valueCompound, Decl(privateWriteOnlyAccessorRead.ts, 3, 29)) +>this : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) + } +} +new Test().m(); +>new Test().m : Symbol(Test.m, Decl(privateWriteOnlyAccessorRead.ts, 4, 34)) +>Test : Symbol(Test, Decl(privateWriteOnlyAccessorRead.ts, 0, 0)) +>m : Symbol(Test.m, Decl(privateWriteOnlyAccessorRead.ts, 4, 34)) + diff --git a/tests/baselines/reference/privateWriteOnlyAccessorRead.types b/tests/baselines/reference/privateWriteOnlyAccessorRead.types new file mode 100644 index 0000000000000..23e62fda4c6d9 --- /dev/null +++ b/tests/baselines/reference/privateWriteOnlyAccessorRead.types @@ -0,0 +1,160 @@ +=== tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts === +class Test { +>Test : Test + + set #value(v: { foo: { bar: number } }) {} +>#value : { foo: { bar: number;}; } +>v : { foo: { bar: number;}; } +>foo : { bar: number; } +>bar : number + + set #valueRest(v: number[]) {} +>#valueRest : number[] +>v : number[] + + set #valueOne(v: number) {} +>#valueOne : number +>v : number + + set #valueCompound(v: number) {} +>#valueCompound : number +>v : number + + m() { +>m : () => void + + const foo = { bar: 1 }; +>foo : { bar: number; } +>{ bar: 1 } : { bar: number; } +>bar : number +>1 : 1 + + console.log(this.#value); // error +>console.log(this.#value) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>this.#value : { foo: { bar: number; }; } +>this : this + + this.#value = { foo }; // ok +>this.#value = { foo } : { foo: { bar: number; }; } +>this.#value : { foo: { bar: number; }; } +>this : this +>{ foo } : { foo: { bar: number; }; } +>foo : { bar: number; } + + this.#value = { foo }; // ok +>this.#value = { foo } : { foo: { bar: number; }; } +>this.#value : { foo: { bar: number; }; } +>this : this +>{ foo } : { foo: { bar: number; }; } +>foo : { bar: number; } + + this.#value.foo = foo; // error +>this.#value.foo = foo : { bar: number; } +>this.#value.foo : { bar: number; } +>this.#value : { foo: { bar: number; }; } +>this : this +>foo : { bar: number; } +>foo : { bar: number; } + + ({ o: this.#value } = { o: { foo } }); //ok +>({ o: this.#value } = { o: { foo } }) : { o: { foo: { bar: number; }; }; } +>{ o: this.#value } = { o: { foo } } : { o: { foo: { bar: number; }; }; } +>{ o: this.#value } : { o: { foo: { bar: number; }; }; } +>o : { foo: { bar: number; }; } +>this.#value : { foo: { bar: number; }; } +>this : this +>{ o: { foo } } : { o: { foo: { bar: number; }; }; } +>o : { foo: { bar: number; }; } +>{ foo } : { foo: { bar: number; }; } +>foo : { bar: number; } + + ({ ...this.#value } = { foo }); //ok +>({ ...this.#value } = { foo }) : { foo: { bar: number; }; } +>{ ...this.#value } = { foo } : { foo: { bar: number; }; } +>{ ...this.#value } : { foo: { bar: number; }; } +>this.#value : { foo: { bar: number; }; } +>this : this +>{ foo } : { foo: { bar: number; }; } +>foo : { bar: number; } + + ({ foo: this.#value.foo } = { foo }); //error +>({ foo: this.#value.foo } = { foo }) : { foo: { bar: number; }; } +>{ foo: this.#value.foo } = { foo } : { foo: { bar: number; }; } +>{ foo: this.#value.foo } : { foo: { bar: number; }; } +>foo : { bar: number; } +>this.#value.foo : { bar: number; } +>this.#value : { foo: { bar: number; }; } +>this : this +>foo : { bar: number; } +>{ foo } : { foo: { bar: number; }; } +>foo : { bar: number; } + + ({ +>({ foo: { ...this.#value.foo }, } = { foo }) : { foo: { bar: number; }; } +>{ foo: { ...this.#value.foo }, } = { foo } : { foo: { bar: number; }; } +>{ foo: { ...this.#value.foo }, } : { foo: { bar: number; }; } + + foo: { ...this.#value.foo }, +>foo : { bar: number; } +>{ ...this.#value.foo } : { bar: number; } +>this.#value.foo : { bar: number; } +>this.#value : { foo: { bar: number; }; } +>this : this +>foo : { bar: number; } + + } = { foo }); //error +>{ foo } : { foo: { bar: number; }; } +>foo : { bar: number; } + + let r = { o: this.#value }; //error +>r : { o: { foo: { bar: number; }; }; } +>{ o: this.#value } : { o: { foo: { bar: number; }; }; } +>o : { foo: { bar: number; }; } +>this.#value : { foo: { bar: number; }; } +>this : this + + [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; +>[this.#valueOne, ...this.#valueRest] = [1, 2, 3] : [number, number, number] +>[this.#valueOne, ...this.#valueRest] : [number, ...number[]] +>this.#valueOne : number +>this : this +>...this.#valueRest : number +>this.#valueRest : number[] +>this : this +>[1, 2, 3] : [number, number, number] +>1 : 1 +>2 : 2 +>3 : 3 + + let arr = [ +>arr : number[] +>[ this.#valueOne, ...this.#valueRest ] : number[] + + this.#valueOne, +>this.#valueOne : number +>this : this + + ...this.#valueRest +>...this.#valueRest : number +>this.#valueRest : number[] +>this : this + + ]; + + this.#valueCompound += 3; +>this.#valueCompound += 3 : number +>this.#valueCompound : number +>this : this +>3 : 3 + } +} +new Test().m(); +>new Test().m() : void +>new Test().m : () => void +>new Test() : Test +>Test : typeof Test +>m : () => void + diff --git a/tests/baselines/reference/restPropertyWithBindingPattern.types b/tests/baselines/reference/restPropertyWithBindingPattern.types index b128042fb5b49..988d9b3c7afdc 100644 --- a/tests/baselines/reference/restPropertyWithBindingPattern.types +++ b/tests/baselines/reference/restPropertyWithBindingPattern.types @@ -17,15 +17,15 @@ ({...[]} = {}); >({...[]} = {}) : {} >{...[]} = {} : {} ->{...[]} : { [n: number]: undefined; length: number; toString(): string; toLocaleString(): string; pop(): undefined; push(...items: undefined[]): number; concat(...items: ConcatArray[]): undefined[]; concat(...items: ConcatArray[]): undefined[]; join(separator?: string): string; reverse(): undefined[]; shift(): undefined; slice(start?: number, end?: number): undefined[]; sort(compareFn?: (a: undefined, b: undefined) => number): undefined[]; splice(start: number, deleteCount?: number): undefined[]; splice(start: number, deleteCount: number, ...items: undefined[]): undefined[]; unshift(...items: undefined[]): number; indexOf(searchElement: undefined, fromIndex?: number): number; lastIndexOf(searchElement: undefined, fromIndex?: number): number; every(predicate: (value: undefined, index: number, array: undefined[]) => value is S, thisArg?: any): this is S[]; every(predicate: (value: undefined, index: number, array: undefined[]) => unknown, thisArg?: any): boolean; some(predicate: (value: undefined, index: number, array: undefined[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: undefined, index: number, array: undefined[]) => void, thisArg?: any): void; map(callbackfn: (value: undefined, index: number, array: undefined[]) => U, thisArg?: any): U[]; filter(predicate: (value: undefined, index: number, array: undefined[]) => value is S, thisArg?: any): S[]; filter(predicate: (value: undefined, index: number, array: undefined[]) => unknown, thisArg?: any): undefined[]; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduce(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduceRight(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; } ->[] : undefined[] +>{...[]} : { [n: number]: never; length: 0; toString(): string; toLocaleString(): string; pop(): never; push(...items: never[]): number; concat(...items: ConcatArray[]): never[]; concat(...items: ConcatArray[]): never[]; join(separator?: string): string; reverse(): never[]; shift(): never; slice(start?: number, end?: number): never[]; sort(compareFn?: (a: never, b: never) => number): []; splice(start: number, deleteCount?: number): never[]; splice(start: number, deleteCount: number, ...items: never[]): never[]; unshift(...items: never[]): number; indexOf(searchElement: never, fromIndex?: number): number; lastIndexOf(searchElement: never, fromIndex?: number): number; every(predicate: (value: never, index: number, array: never[]) => value is S, thisArg?: any): this is S[]; every(predicate: (value: never, index: number, array: never[]) => unknown, thisArg?: any): boolean; some(predicate: (value: never, index: number, array: never[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: never, index: number, array: never[]) => void, thisArg?: any): void; map(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any): U[]; filter(predicate: (value: never, index: number, array: never[]) => value is S, thisArg?: any): S[]; filter(predicate: (value: never, index: number, array: never[]) => unknown, thisArg?: any): never[]; reduce(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never): never; reduce(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never, initialValue: never): never; reduce(callbackfn: (previousValue: U, currentValue: never, currentIndex: number, array: never[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never): never; reduceRight(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never, initialValue: never): never; reduceRight(callbackfn: (previousValue: U, currentValue: never, currentIndex: number, array: never[]) => U, initialValue: U): U; } +>[] : [] >{} : {} ({...([])} = {}); >({...([])} = {}) : {} >{...([])} = {} : {} ->{...([])} : { [n: number]: undefined; length: number; toString(): string; toLocaleString(): string; pop(): undefined; push(...items: undefined[]): number; concat(...items: ConcatArray[]): undefined[]; concat(...items: ConcatArray[]): undefined[]; join(separator?: string): string; reverse(): undefined[]; shift(): undefined; slice(start?: number, end?: number): undefined[]; sort(compareFn?: (a: undefined, b: undefined) => number): undefined[]; splice(start: number, deleteCount?: number): undefined[]; splice(start: number, deleteCount: number, ...items: undefined[]): undefined[]; unshift(...items: undefined[]): number; indexOf(searchElement: undefined, fromIndex?: number): number; lastIndexOf(searchElement: undefined, fromIndex?: number): number; every(predicate: (value: undefined, index: number, array: undefined[]) => value is S, thisArg?: any): this is S[]; every(predicate: (value: undefined, index: number, array: undefined[]) => unknown, thisArg?: any): boolean; some(predicate: (value: undefined, index: number, array: undefined[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: undefined, index: number, array: undefined[]) => void, thisArg?: any): void; map(callbackfn: (value: undefined, index: number, array: undefined[]) => U, thisArg?: any): U[]; filter(predicate: (value: undefined, index: number, array: undefined[]) => value is S, thisArg?: any): S[]; filter(predicate: (value: undefined, index: number, array: undefined[]) => unknown, thisArg?: any): undefined[]; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduce(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduce(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined): undefined; reduceRight(callbackfn: (previousValue: undefined, currentValue: undefined, currentIndex: number, array: undefined[]) => undefined, initialValue: undefined): undefined; reduceRight(callbackfn: (previousValue: U, currentValue: undefined, currentIndex: number, array: undefined[]) => U, initialValue: U): U; } ->([]) : undefined[] ->[] : undefined[] +>{...([])} : { [n: number]: never; length: 0; toString(): string; toLocaleString(): string; pop(): never; push(...items: never[]): number; concat(...items: ConcatArray[]): never[]; concat(...items: ConcatArray[]): never[]; join(separator?: string): string; reverse(): never[]; shift(): never; slice(start?: number, end?: number): never[]; sort(compareFn?: (a: never, b: never) => number): []; splice(start: number, deleteCount?: number): never[]; splice(start: number, deleteCount: number, ...items: never[]): never[]; unshift(...items: never[]): number; indexOf(searchElement: never, fromIndex?: number): number; lastIndexOf(searchElement: never, fromIndex?: number): number; every(predicate: (value: never, index: number, array: never[]) => value is S, thisArg?: any): this is S[]; every(predicate: (value: never, index: number, array: never[]) => unknown, thisArg?: any): boolean; some(predicate: (value: never, index: number, array: never[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: never, index: number, array: never[]) => void, thisArg?: any): void; map(callbackfn: (value: never, index: number, array: never[]) => U, thisArg?: any): U[]; filter(predicate: (value: never, index: number, array: never[]) => value is S, thisArg?: any): S[]; filter(predicate: (value: never, index: number, array: never[]) => unknown, thisArg?: any): never[]; reduce(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never): never; reduce(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never, initialValue: never): never; reduce(callbackfn: (previousValue: U, currentValue: never, currentIndex: number, array: never[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never): never; reduceRight(callbackfn: (previousValue: never, currentValue: never, currentIndex: number, array: never[]) => never, initialValue: never): never; reduceRight(callbackfn: (previousValue: U, currentValue: never, currentIndex: number, array: never[]) => U, initialValue: U): U; } +>([]) : [] +>[] : [] >{} : {} diff --git a/tests/baselines/reference/strictPropertyInitialization.js b/tests/baselines/reference/strictPropertyInitialization.js index 86d29d3ad90f2..30867a3773de1 100644 --- a/tests/baselines/reference/strictPropertyInitialization.js +++ b/tests/baselines/reference/strictPropertyInitialization.js @@ -137,29 +137,27 @@ class C11 { //// [strictPropertyInitialization.js] "use strict"; // Properties with non-undefined types require initialization -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to set private field on non-instance"); - } - privateMap.set(receiver, value); - return value; +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, privateMap) { - if (!privateMap.has(receiver)) { - throw new TypeError("attempted to get private field on non-instance"); - } - return privateMap.get(receiver); +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 _f, _g, _h, _i, _d, _e, _f_1, _b, _b_1, _b_2, _d_1, _b_3; +var _C1_f, _C1_g, _C1_h, _C1_i, _C4_d, _C4_e, _C4_f, _C5_b, _C6_b, _C7_b, _C10_d, _C11_b; class C1 { constructor() { - _f.set(this, void 0); //Error - _g.set(this, void 0); - _h.set(this, void 0); //Error - _i.set(this, void 0); + _C1_f.set(this, void 0); //Error + _C1_g.set(this, void 0); + _C1_h.set(this, void 0); //Error + _C1_i.set(this, void 0); } } -_f = new WeakMap(), _g = new WeakMap(), _h = new WeakMap(), _i = new WeakMap(); +_C1_f = new WeakMap(), _C1_g = new WeakMap(), _C1_h = new WeakMap(), _C1_i = new WeakMap(); // No strict initialization checks for static members class C3 { } @@ -169,46 +167,46 @@ class C4 { this.a = 0; this.b = 0; this.c = "abc"; - _d.set(this, 0); - _e.set(this, 0); - _f_1.set(this, "abc"); + _C4_d.set(this, 0); + _C4_e.set(this, 0); + _C4_f.set(this, "abc"); } } -_d = new WeakMap(), _e = new WeakMap(), _f_1 = new WeakMap(); +_C4_d = new WeakMap(), _C4_e = new WeakMap(), _C4_f = new WeakMap(); // Assignment in constructor satisfies strict initialization check class C5 { constructor() { - _b.set(this, void 0); + _C5_b.set(this, void 0); this.a = 0; - __classPrivateFieldSet(this, _b, 0); + __classPrivateFieldSet(this, _C5_b, 0, "f"); } } -_b = new WeakMap(); +_C5_b = new WeakMap(); // All code paths must contain assignment class C6 { constructor(cond) { - _b_1.set(this, void 0); + _C6_b.set(this, void 0); if (cond) { return; } this.a = 0; - __classPrivateFieldSet(this, _b_1, 0); + __classPrivateFieldSet(this, _C6_b, 0, "f"); } } -_b_1 = new WeakMap(); +_C6_b = new WeakMap(); class C7 { constructor(cond) { - _b_2.set(this, void 0); + _C7_b.set(this, void 0); if (cond) { this.a = 1; - __classPrivateFieldSet(this, _b_2, 1); + __classPrivateFieldSet(this, _C7_b, 1, "f"); return; } this.a = 0; - __classPrivateFieldSet(this, _b_2, 1); + __classPrivateFieldSet(this, _C7_b, 1, "f"); } } -_b_2 = new WeakMap(); +_C7_b = new WeakMap(); // Properties with string literal names aren't checked class C8 { } @@ -219,24 +217,24 @@ class C9 { // within their constructor class C10 { constructor() { - _d_1.set(this, void 0); + _C10_d.set(this, void 0); let x = this.a; // Error this.a = this.b; // Error - this.b = __classPrivateFieldGet(this, _d_1); //Error + this.b = __classPrivateFieldGet(this, _C10_d, "f"); //Error this.b = x; - __classPrivateFieldSet(this, _d_1, x); + __classPrivateFieldSet(this, _C10_d, x, "f"); let y = this.c; } } -_d_1 = new WeakMap(); +_C10_d = new WeakMap(); class C11 { constructor() { - _b_3.set(this, void 0); + _C11_b.set(this, void 0); this.a = someValue(); - __classPrivateFieldSet(this, _b_3, someValue()); + __classPrivateFieldSet(this, _C11_b, someValue(), "f"); } } -_b_3 = new WeakMap(); +_C11_b = new WeakMap(); //// [strictPropertyInitialization.d.ts] diff --git a/tests/cases/compiler/importHelpersES6.ts b/tests/cases/compiler/importHelpersES6.ts index 36d9cba73178b..394c01e147841 100644 --- a/tests/cases/compiler/importHelpersES6.ts +++ b/tests/cases/compiler/importHelpersES6.ts @@ -17,5 +17,5 @@ export declare function __decorate(decorators: Function[], target: any, key?: st export declare function __param(paramIndex: number, decorator: Function): Function; export declare function __metadata(metadataKey: any, metadataValue: any): Function; export declare function __awaiter(thisArg: any, _arguments: any, P: Function, generator: Function): any; -export declare function __classPrivateFieldGet(): any; -export declare function __classPrivateFieldSet(): any; \ No newline at end of file +export declare function __classPrivateFieldGet(a: any, b: any, c: any, d: any): any; +export declare function __classPrivateFieldSet(a: any, b: any, c: any, d: any, e: any): any; diff --git a/tests/cases/compiler/privateNameWeakMapCollision.ts b/tests/cases/compiler/privateNameWeakMapCollision.ts index b9e91c5c15ac6..22f4af36bf8f0 100644 --- a/tests/cases/compiler/privateNameWeakMapCollision.ts +++ b/tests/cases/compiler/privateNameWeakMapCollision.ts @@ -2,6 +2,7 @@ function test() { let WeakMap; + let WeakSet; class C { #x; } diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts new file mode 100644 index 0000000000000..451d017fdca99 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAccessors.ts @@ -0,0 +1,16 @@ +// @strict: true +// @target: es6 + +class A1 { + get #prop() { return ""; } + set #prop(param: string) { } + + get #roProp() { return ""; } + + constructor(name: string) { + this.#prop = ""; + this.#roProp = ""; // Error + console.log(this.#prop); + console.log(this.#roProp); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts new file mode 100644 index 0000000000000..7480a87ce545e --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAccessorsAccess.ts @@ -0,0 +1,26 @@ +// @target: es2015 + +class A2 { + get #prop() { return ""; } + set #prop(param: string) { } + + constructor() { + console.log(this.#prop); + let a: A2 = this; + a.#prop; + function foo (){ + a.#prop; + } + } +} +new A2().#prop; // Error + +function foo (){ + new A2().#prop; // Error +} + +class B2 { + m() { + new A2().#prop; + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAccessorsCallExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAccessorsCallExpression.ts new file mode 100644 index 0000000000000..ce7dae715b6fa --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAccessorsCallExpression.ts @@ -0,0 +1,20 @@ +// @target: es2015 + +class A { + get #fieldFunc() { return function() { this.x = 10; } } + get #fieldFunc2() { return function(a, ...b) {}; } + x = 1; + test() { + this.#fieldFunc(); + const func = this.#fieldFunc; + func(); + new this.#fieldFunc(); + + const arr = [ 1, 2 ]; + this.#fieldFunc2(0, ...arr, 3); + const b = new this.#fieldFunc2(0, ...arr, 3); + const str = this.#fieldFunc2`head${1}middle${2}tail`; + this.getInstance().#fieldFunc2`test${1}and${2}`; + } + getInstance() { return new A(); } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts new file mode 100644 index 0000000000000..80140cf63d1dd --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAccessorssDerivedClasses.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +class Base { + get #prop(): number { return 123; } + static method(x: Derived) { + console.log(x.#prop); + } +} +class Derived extends Base { + static method(x: Derived) { + console.log(x.#prop); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts index 78fe2c9398452..a0d06e0aebdf6 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAndAny.ts @@ -2,19 +2,27 @@ // @target: es6 class A { - #foo = true; + #foo = true; + static #baz = 10; + static #m() {} method(thing: any) { thing.#foo; // OK + thing.#m(); + thing.#baz; thing.#bar; // Error thing.#foo(); } methodU(thing: unknown) { thing.#foo; + thing.#m(); + thing.#baz; thing.#bar; thing.#foo(); } methodN(thing: never) { thing.#foo; + thing.#m(); + thing.#baz; thing.#bar; thing.#foo(); } diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts index 9fed89d65499a..20185b3185c45 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAndObjectRestSpread.ts @@ -3,11 +3,17 @@ class C { #prop = 1; + static #propStatic = 1; method(other: C) { const obj = { ...other }; obj.#prop; const { ...rest } = other; rest.#prop; + + const statics = { ... C}; + statics.#propStatic + const { ...sRest } = C; + sRest.#propStatic; } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts b/tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts index fc6c20828556c..7df8691185114 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameAndPropertySignature.ts @@ -1,16 +1,20 @@ type A = { - #foo: string + #foo: string; + #bar(): string; } interface B { #foo: string; + #bar(): string; } declare const x: { #foo: number; bar: { #baz: string; + #taz(): string; } + #baz(): string; }; declare const y: [{ qux: { #quux: 3 } }]; diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts b/tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts index 2a8c589b11da9..b1b2c493e304b 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameBadDeclaration.ts @@ -1,10 +1,14 @@ function A() { } A.prototype = { - #x: 1 // Error + #x: 1, // Error + #m() {}, // Error + get #p() { return "" } // Error } class B { } B.prototype = { - #y: 2 // Error + #y: 2, // Error + #m() {}, // Error + get #p() { return "" } // Error } class C { constructor() { diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameClassExpressionLoop.ts b/tests/cases/conformance/classes/members/privateNames/privateNameClassExpressionLoop.ts index 222be787d0e67..333a69f79f570 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameClassExpressionLoop.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameClassExpressionLoop.ts @@ -3,5 +3,8 @@ const array = []; for (let i = 0; i < 10; ++i) { array.push(class C { #myField = "hello"; + #method() {} + get #accessor() { return 42; } + set #accessor(val) { } }); } diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts b/tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts index 45ed8f020d757..2813327ccecf1 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameDuplicateField.ts @@ -1,7 +1,405 @@ // @strict: true // @target: es6 -class A { - #foo = "foo"; - #foo = "foo"; +function Field() { + + // Error + class A_Field_Field { + #foo = "foo"; + #foo = "foo"; + } + + // Error + class A_Field_Method { + #foo = "foo"; + #foo() { } + } + + // Error + class A_Field_Getter { + #foo = "foo"; + get #foo() { return ""} + } + + // Error + class A_Field_Setter { + #foo = "foo"; + set #foo(value: string) { } + } + + // Error + class A_Field_StaticField { + #foo = "foo"; + static #foo = "foo"; + } + + // Error + class A_Field_StaticMethod { + #foo = "foo"; + static #foo() { } + } + + // Error + class A_Field_StaticGetter { + #foo = "foo"; + static get #foo() { return ""} + } + + // Error + class A_Field_StaticSetter { + #foo = "foo"; + static set #foo(value: string) { } + } +} + +function Method() { + // Error + class A_Method_Field { + #foo() { } + #foo = "foo"; + } + + // Error + class A_Method_Method { + #foo() { } + #foo() { } + } + + // Error + class A_Method_Getter { + #foo() { } + get #foo() { return ""} + } + + // Error + class A_Method_Setter { + #foo() { } + set #foo(value: string) { } + } + + // Error + class A_Method_StaticField { + #foo() { } + static #foo = "foo"; + } + + // Error + class A_Method_StaticMethod { + #foo() { } + static #foo() { } + } + + // Error + class A_Method_StaticGetter { + #foo() { } + static get #foo() { return ""} + } + + // Error + class A_Method_StaticSetter { + #foo() { } + static set #foo(value: string) { } + } +} + + +function Getter() { + // Error + class A_Getter_Field { + get #foo() { return ""} + #foo = "foo"; + } + + // Error + class A_Getter_Method { + get #foo() { return ""} + #foo() { } + } + + // Error + class A_Getter_Getter { + get #foo() { return ""} + get #foo() { return ""} + } + + //OK + class A_Getter_Setter { + get #foo() { return ""} + set #foo(value: string) { } + } + + // Error + class A_Getter_StaticField { + get #foo() { return ""} + static #foo() { } + } + + // Error + class A_Getter_StaticMethod { + get #foo() { return ""} + static #foo() { } + } + + // Error + class A_Getter_StaticGetter { + get #foo() { return ""} + static get #foo() { return ""} + } + + // Error + class A_Getter_StaticSetter { + get #foo() { return ""} + static set #foo(value: string) { } + } +} + +function Setter() { + // Error + class A_Setter_Field { + set #foo(value: string) { } + #foo = "foo"; + } + + // Error + class A_Setter_Method { + set #foo(value: string) { } + #foo() { } + } + + // OK + class A_Setter_Getter { + set #foo(value: string) { } + get #foo() { return ""} + } + + // Error + class A_Setter_Setter { + set #foo(value: string) { } + set #foo(value: string) { } + } + + // Error + class A_Setter_StaticField { + set #foo(value: string) { } + static #foo = "foo"; + } + + // Error + class A_Setter_StaticMethod { + set #foo(value: string) { } + static #foo() { } + } + + // Error + class A_Setter_StaticGetter { + set #foo(value: string) { } + static get #foo() { return ""} + } + + // Error + class A_Setter_StaticSetter { + set #foo(value: string) { } + static set #foo(value: string) { } + } +} + +function StaticField() { + // Error + class A_StaticField_Field { + static #foo = "foo"; + #foo = "foo"; + } + + // Error + class A_StaticField_Method { + static #foo = "foo"; + #foo() { } + } + + // Error + class A_StaticField_Getter { + static #foo = "foo"; + get #foo() { return ""} + } + + // Error + class A_StaticField_Setter { + static #foo = "foo"; + set #foo(value: string) { } + } + + // Error + class A_StaticField_StaticField { + static #foo = "foo"; + static #foo = "foo"; + } + + // Error + class A_StaticField_StaticMethod { + static #foo = "foo"; + static #foo() { } + } + + // Error + class A_StaticField_StaticGetter { + static #foo = "foo"; + static get #foo() { return ""} + } + + // Error + class A_StaticField_StaticSetter { + static #foo = "foo"; + static set #foo(value: string) { } + } +} + +function StaticMethod() { + // Error + class A_StaticMethod_Field { + static #foo() { } + #foo = "foo"; + } + + // Error + class A_StaticMethod_Method { + static #foo() { } + #foo() { } + } + + // Error + class A_StaticMethod_Getter { + static #foo() { } + get #foo() { return ""} + } + + // Error + class A_StaticMethod_Setter { + static #foo() { } + set #foo(value: string) { } + } + + // Error + class A_StaticMethod_StaticField { + static #foo() { } + static #foo = "foo"; + } + + // Error + class A_StaticMethod_StaticMethod { + static #foo() { } + static #foo() { } + } + + // Error + class A_StaticMethod_StaticGetter { + static #foo() { } + static get #foo() { return ""} + } + + // Error + class A_StaticMethod_StaticSetter { + static #foo() { } + static set #foo(value: string) { } + } +} + +function StaticGetter() { + + // Error + class A_StaticGetter_Field { + static get #foo() { return ""} + #foo = "foo"; + } + + // Error + class A_StaticGetter_Method { + static get #foo() { return ""} + #foo() { } + } + + // Error + class A_StaticGetter_Getter { + static get #foo() { return ""} + get #foo() { return ""} + } + + // Error + class A_StaticGetter_Setter { + static get #foo() { return ""} + set #foo(value: string) { } + } + + // Error + class A_StaticGetter_StaticField { + static get #foo() { return ""} + static #foo() { } + } + + // Error + class A_StaticGetter_StaticMethod { + static get #foo() { return ""} + static #foo() { } + } + + // Error + class A_StaticGetter_StaticGetter { + static get #foo() { return ""} + static get #foo() { return ""} + } + // OK + class A_StaticGetter_StaticSetter { + static get #foo() { return ""} + static set #foo(value: string) { } + } +} + +function StaticSetter() { + // Error + class A_StaticSetter_Field { + static set #foo(value: string) { } + #foo = "foo"; + } + + // Error + class A_StaticSetter_Method { + static set #foo(value: string) { } + #foo() { } + } + + + // Error + class A_StaticSetter_Getter { + static set #foo(value: string) { } + get #foo() { return ""} + } + + // Error + class A_StaticSetter_Setter { + static set #foo(value: string) { } + set #foo(value: string) { } + } + + // Error + class A_StaticSetter_StaticField { + static set #foo(value: string) { } + static #foo = "foo"; + } + + // Error + class A_StaticSetter_StaticMethod { + static set #foo(value: string) { } + static #foo() { } + } + + // OK + class A_StaticSetter_StaticGetter { + static set #foo(value: string) { } + static get #foo() { return ""} + } + + // Error + class A_StaticSetter_StaticSetter { + static set #foo(value: string) { } + static set #foo(value: string) { } + } } diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameEmitHelpers.ts b/tests/cases/conformance/classes/members/privateNames/privateNameEmitHelpers.ts new file mode 100644 index 0000000000000..82dc5693d42ba --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameEmitHelpers.ts @@ -0,0 +1,16 @@ +// @target: es2015 +// @importHelpers: true +// @isolatedModules: true + +// @filename: main.ts + +export class C { + #a = 1; + #b() { this.#c = 42; } + set #c(v: number) { this.#a += v; } +} + +// @filename: tslib.d.ts +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts b/tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts new file mode 100644 index 0000000000000..8323d7d18ff0a --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameInObjectLiteral-3.ts @@ -0,0 +1,5 @@ +const obj = { + get #foo() { + return "" + } +}; diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameJsBadDeclaration.ts b/tests/cases/conformance/classes/members/privateNames/privateNameJsBadDeclaration.ts index 90e6197c6b3cc..b26cd5a2bbd73 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameJsBadDeclaration.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameJsBadDeclaration.ts @@ -5,11 +5,15 @@ function A() { } A.prototype = { - #x: 1 // Error + #x: 1, // Error + #m() {}, // Error + get #p() { return "" } // Error } class B { } B.prototype = { - #y: 2 // Error + #y: 2, // Error + #m() {}, // Error + get #p() { return "" } // Error } class C { constructor() { diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts new file mode 100644 index 0000000000000..0104fc9fc4236 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethod.ts @@ -0,0 +1,14 @@ +// @strict: true +// @target: es6 + +class A1 { + #method(param: string): string { + return ""; + } + constructor(name: string) { + this.#method("") + this.#method(1) // Error + this.#method() // Error + + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts new file mode 100644 index 0000000000000..c2f5104c3101f --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodAccess.ts @@ -0,0 +1,24 @@ +// @target: es2015 + +class A2 { + #method() { return "" } + constructor() { + console.log(this.#method); + let a: A2 = this; + a.#method(); + function foo (){ + a.#method(); + } + } +} +new A2().#method(); // Error + +function foo (){ + new A2().#method(); // Error +} + +class B2 { + m() { + new A2().#method(); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts new file mode 100644 index 0000000000000..e0ae392458945 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodAssignment.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +class A3 { + #method() { }; + constructor(a: A3, b: any) { + this.#method = () => {} // Error, not writable + a.#method = () => { }; // Error, not writable + b.#method = () => { } //Error, not writable + ({ x: this.#method } = { x: () => {}}); //Error, not writable + let x = this.#method; + b.#method++ //Error, not writable + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodAsync.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodAsync.ts new file mode 100644 index 0000000000000..1b1cc59d99d42 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodAsync.ts @@ -0,0 +1,15 @@ +// @target: es2019 + +const C = class { + async #bar() { return await Promise.resolve(42); } + async foo() { + const b = await this.#bar(); + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); + } + *#baz() { yield 42; } + async *#qux() { + yield (await Promise.resolve(42)); + } +} + +new C().foo().then(console.log); diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodCallExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodCallExpression.ts new file mode 100644 index 0000000000000..d76deec97de3e --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodCallExpression.ts @@ -0,0 +1,25 @@ +// @target: es2015 + +class AA { + #method() { this.x = 10; }; + #method2(a, ...b) {}; + x = 1; + test() { + this.#method(); + const func = this.#method; + func(); + new this.#method(); + + const arr = [ 1, 2 ]; + this.#method2(0, ...arr, 3); + + const b = new this.#method2(0, ...arr, 3); //Error + const str = this.#method2`head${1}middle${2}tail`; + this.getInstance().#method2`test${1}and${2}`; + + this.getInstance().#method2(0, ...arr, 3); + const b2 = new (this.getInstance().#method2)(0, ...arr, 3); //Error + const str2 = this.getInstance().#method2`head${1}middle${2}tail`; + } + getInstance() { return new AA(); } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts new file mode 100644 index 0000000000000..503761c73414c --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodClassExpression.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +const C = class { + #field = this.#method(); + #method() { return 42; } + static getInstance() { return new C(); } + getField() { return this.#field }; +} + +console.log(C.getInstance().getField()); +C.getInstance().#method; // Error +C.getInstance().#field; // Error + diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodInStaticFieldInit.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodInStaticFieldInit.ts new file mode 100644 index 0000000000000..440ddb0cf1a71 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodInStaticFieldInit.ts @@ -0,0 +1,8 @@ +// @target: es2015 + +class C { + static s = new C().#method(); + #method() { return 42; } +} + +console.log(C.s); diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts b/tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts new file mode 100644 index 0000000000000..807826e5dceec --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameMethodsDerivedClasses.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +class Base { + #prop(): number{ return 123; } + static method(x: Derived) { + console.log(x.#prop()); + } +} +class Derived extends Base { + static method(x: Derived) { + console.log(x.#prop()); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts b/tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts new file mode 100644 index 0000000000000..b5d235f5a11e8 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameNestedClassAccessorsShadowing.ts @@ -0,0 +1,16 @@ +// @target: es2015 + +class Base { + get #x() { return 1; }; + constructor() { + class Derived { + get #x() { return 1; }; + testBase(x: Base) { + console.log(x.#x); + } + testDerived(x: Derived) { + console.log(x.#x); + } + } + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts b/tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts new file mode 100644 index 0000000000000..c05301955e438 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameNestedClassMethodShadowing.ts @@ -0,0 +1,16 @@ +// @target: es2015 + +class Base { + #x() { }; + constructor() { + class Derived { + #x() { }; + testBase(x: Base) { + console.log(x.#x); + } + testDerived(x: Derived) { + console.log(x.#x); + } + } + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts b/tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts new file mode 100644 index 0000000000000..0c10fbce59d29 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameNestedMethodAccess.ts @@ -0,0 +1,25 @@ +// @target: es2015 + +class C { + #foo = 42; + #bar() { new C().#baz; } + get #baz() { return 42; } + + m() { + return class D { + #bar() {} + constructor() { + new C().#foo; + new C().#bar; // Error + new C().#baz; + new D().#bar; + } + + n(x: any) { + x.#foo; + x.#bar; + x.#unknown; // Error + } + } + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts b/tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts new file mode 100644 index 0000000000000..b9e373f19e57d --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameReadonly.ts @@ -0,0 +1,10 @@ +// @target: es2015 + +const C = class { + #bar() {} + foo() { + this.#bar = console.log("should log this then throw"); + } +} + +console.log(new C().foo()); diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameSetterExprReturnValue.ts b/tests/cases/conformance/classes/members/privateNames/privateNameSetterExprReturnValue.ts new file mode 100644 index 0000000000000..c9def078b2994 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameSetterExprReturnValue.ts @@ -0,0 +1,11 @@ +// @target: es2019 + +class C { + set #foo(a: number) {} + bar() { + let x = (this.#foo = 42 * 2); + console.log(x); // 84 + } +} + +new C().bar(); diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts b/tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts new file mode 100644 index 0000000000000..ae0aeda5efd5e --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameSetterNoGetter.ts @@ -0,0 +1,10 @@ +// @target: es2015 + +const C = class { + set #x(x) {} + m() { + this.#x += 2; // Error + } +} + +console.log(new C().m()); diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts new file mode 100644 index 0000000000000..5f3c20210be0e --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessors.ts @@ -0,0 +1,16 @@ +// @strict: true +// @target: es6 + +class A1 { + static get #prop() { return ""; } + static set #prop(param: string) { } + + static get #roProp() { return ""; } + + constructor(name: string) { + A1.#prop = ""; + A1.#roProp = ""; // Error + console.log(A1.#prop); + console.log(A1.#roProp); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts new file mode 100644 index 0000000000000..d57ae7893813b --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsAccess.ts @@ -0,0 +1,27 @@ +// @target: es2015 +export {} +class A2 { + static get #prop() { return ""; } + static set #prop(param: string) { } + + constructor() { + console.log(A2.#prop); + let a: typeof A2 = A2; + a.#prop; + function foo (){ + a.#prop; + } + } +} + +A2.#prop; // Error + +function foo (){ + A2.#prop; // Error +} + +class B2 { + m() { + A2.#prop; + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsCallExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsCallExpression.ts new file mode 100644 index 0000000000000..ac5a5ade7e3d2 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorsCallExpression.ts @@ -0,0 +1,20 @@ +// @target: es2015 + +class A { + static get #fieldFunc() { return function() { A.#x = 10; } } + static get #fieldFunc2() { return function(a, ...b) {}; } + static #x = 1; + static test() { + this.#fieldFunc(); + const func = this.#fieldFunc; + func(); + new this.#fieldFunc(); + + const arr = [ 1, 2 ]; + this.#fieldFunc2(0, ...arr, 3); + const b = new this.#fieldFunc2(0, ...arr, 3); + const str = this.#fieldFunc2`head${1}middle${2}tail`; + this.getClass().#fieldFunc2`test${1}and${2}`; + } + static getClass() { return A; } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts new file mode 100644 index 0000000000000..80d81fed1f326 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAccessorssDerivedClasses.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +class Base { + static get #prop(): number { return 123; } + static method(x: typeof Derived) { + console.log(x.#prop); + } +} +class Derived extends Base { + static method(x: typeof Derived) { + console.log(x.#prop); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts new file mode 100644 index 0000000000000..f163ab8cf1263 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticAndStaticInitializer.ts @@ -0,0 +1,7 @@ +// @target: esnext, es2015 + +class A { + static #foo = 1; + static #prop = 2; +} + diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticEmitHelpers.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticEmitHelpers.ts new file mode 100644 index 0000000000000..b1261a039e563 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticEmitHelpers.ts @@ -0,0 +1,16 @@ +// @target: es2015 +// @importHelpers: true +// @isolatedModules: true + +// @filename: main.ts + +export class S { + static #a = 1; + static #b() { this.#a = 42; } + static get #c() { return S.#b(); } +} + +// @filename: tslib.d.ts +// these are pre-TS4.3 versions of emit helpers, which only supported private instance fields +export declare function __classPrivateFieldGet(receiver: T, state: any): V; +export declare function __classPrivateFieldSet(receiver: T, state: any, value: V): V; diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts new file mode 100644 index 0000000000000..8aea7860b7292 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAccess.ts @@ -0,0 +1,9 @@ +// @target: es2015 + +class A { + static #myField = "hello world"; + constructor() { + console.log(A.#myField); //Ok + console.log(this.#myField); //Error + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAssignment.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAssignment.ts new file mode 100644 index 0000000000000..76428f33cb435 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldAssignment.ts @@ -0,0 +1,36 @@ +// @target: es2015 + +class A { + static #field = 0; + constructor() { + A.#field = 1; + A.#field += 2; + A.#field -= 3; + A.#field /= 4; + A.#field *= 5; + A.#field **= 6; + A.#field %= 7; + A.#field <<= 8; + A.#field >>= 9; + A.#field >>>= 10; + A.#field &= 11; + A.#field |= 12; + A.#field ^= 13; + A.getClass().#field = 1; + A.getClass().#field += 2; + A.getClass().#field -= 3; + A.getClass().#field /= 4; + A.getClass().#field *= 5; + A.getClass().#field **= 6; + A.getClass().#field %= 7; + A.getClass().#field <<= 8; + A.getClass().#field >>= 9; + A.getClass().#field >>>= 10; + A.getClass().#field &= 11; + A.getClass().#field |= 12; + A.getClass().#field ^= 13; + } + static getClass() { + return A; + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldCallExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldCallExpression.ts new file mode 100644 index 0000000000000..723a36842c7f7 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldCallExpression.ts @@ -0,0 +1,21 @@ +// @target: es2015 + +class A { + static #fieldFunc = function () { this.x = 10; }; + static #fieldFunc2 = function (a, ...b) {}; + x = 1; + test() { + A.#fieldFunc(); + A.#fieldFunc?.(); + const func = A.#fieldFunc; + func(); + new A.#fieldFunc(); + + const arr = [ 1, 2 ]; + A.#fieldFunc2(0, ...arr, 3); + const b = new A.#fieldFunc2(0, ...arr, 3); + const str = A.#fieldFunc2`head${1}middle${2}tail`; + this.getClass().#fieldFunc2`test${1}and${2}`; + } + getClass() { return A; } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldClassExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldClassExpression.ts new file mode 100644 index 0000000000000..b57a64ca65adb --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldClassExpression.ts @@ -0,0 +1,23 @@ +// @target: es2015 + +class B { + static #foo = class { + constructor() { + console.log("hello"); + new B.#foo2(); + } + static test = 123; + field = 10; + }; + static #foo2 = class Foo { + static otherClass = 123; + }; + + m() { + console.log(B.#foo.test) + B.#foo.test = 10; + new B.#foo().field; + } +} + + diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts new file mode 100644 index 0000000000000..92024df3a074e --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDerivedClasses.ts @@ -0,0 +1,17 @@ +// @target: es2015 + +class Base { + static #prop: number = 123; + static method(x: Derived) { + Derived.#derivedProp // error + Base.#prop = 10; + } +} +class Derived extends Base { + static #derivedProp: number = 10; + static method(x: Derived) { + Derived.#derivedProp + Base.#prop = 10; // error + } +} + diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts new file mode 100644 index 0000000000000..2822bb8813ec9 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldDestructuredBinding.ts @@ -0,0 +1,25 @@ +// @target: esnext, es2015 + +class A { + static #field = 1; + otherClass = A; + testObject() { + return { x: 10, y: 6 }; + } + testArray() { + return [10, 11]; + } + constructor() { + let y: number; + ({ x: A.#field, y } = this.testObject()); + ([A.#field, y] = this.testArray()); + ({ a: A.#field, b: [A.#field] } = { a: 1, b: [2] }); + [A.#field, [A.#field]] = [1, [2]]; + ({ a: A.#field = 1, b: [A.#field = 1] } = { b: [] }); + [A.#field = 2] = []; + [this.otherClass.#field = 2] = []; + } + static test(_a: typeof A) { + [_a.#field] = [2]; + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts new file mode 100644 index 0000000000000..2866eb42eded8 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldInitializer.ts @@ -0,0 +1,6 @@ +// @target: es2015, esnext + +class A { + static #field = 10; + static #uninitialized; +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts new file mode 100644 index 0000000000000..815a5d40f632e --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldNoInitializer.ts @@ -0,0 +1,9 @@ +// @target: es2015, esnext + +const C = class { + static #x; +} + +class C2 { + static #x; +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldUnaryMutation.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldUnaryMutation.ts new file mode 100644 index 0000000000000..8d37986db42a6 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticFieldUnaryMutation.ts @@ -0,0 +1,30 @@ +// @target: es2015 + +class C { + static #test: number = 24; + constructor() { + C.#test++; + C.#test--; + ++C.#test; + --C.#test; + const a = C.#test++; + const b = C.#test--; + const c = ++C.#test; + const d = --C.#test; + for (C.#test = 0; C.#test < 10; ++C.#test) {} + for (C.#test = 0; C.#test < 10; C.#test++) {} + } + test() { + this.getClass().#test++; + this.getClass().#test--; + ++this.getClass().#test; + --this.getClass().#test; + const a = this.getClass().#test++; + const b = this.getClass().#test--; + const c = ++this.getClass().#test; + const d = --this.getClass().#test; + for (this.getClass().#test = 0; this.getClass().#test < 10; ++this.getClass().#test) {} + for (this.getClass().#test = 0; this.getClass().#test < 10; this.getClass().#test++) {} + } + getClass() { return C; } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts new file mode 100644 index 0000000000000..00b73232c4299 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethod.ts @@ -0,0 +1,14 @@ +// @strict: true +// @target: es6 + +class A1 { + static #method(param: string): string { + return ""; + } + constructor() { + A1.#method("") + A1.#method(1) // Error + A1.#method() // Error + + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts new file mode 100644 index 0000000000000..756fbe2feb59d --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAssignment.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +class A3 { + static #method() { }; + constructor(a: typeof A3, b: any) { + A3.#method = () => {} // Error, not writable + a.#method = () => { }; // Error, not writable + b.#method = () => { } //Error, not writable + ({ x: A3.#method } = { x: () => {}}); //Error, not writable + let x = A3.#method; + b.#method++ //Error, not writable + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts new file mode 100644 index 0000000000000..cdfc422e36252 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodAsync.ts @@ -0,0 +1,16 @@ +// @target: es2019 + +const C = class { + static async #bar() { return await Promise.resolve(42); } + static async foo() { + const b = await this.#bar(); + return b + (this.#baz().next().value || 0) + ((await this.#qux().next()).value || 0); + } + static *#baz() { yield 42; } + static async *#qux() { + yield (await Promise.resolve(42)); + } + async static *#bazBad() { yield 42; } +} + + diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodCallExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodCallExpression.ts new file mode 100644 index 0000000000000..8205599dc96ab --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodCallExpression.ts @@ -0,0 +1,25 @@ +// @target: es2015 + +class AA { + static #method() { this.x = 10; }; + static #method2(a, ...b) {}; + static x = 1; + test() { + AA.#method(); + const func = AA.#method; + func(); + new AA.#method(); + + const arr = [ 1, 2 ]; + AA.#method2(0, ...arr, 3); + + const b = new AA.#method2(0, ...arr, 3); //Error + const str = AA.#method2`head${1}middle${2}tail`; + AA.getClass().#method2`test${1}and${2}`; + + AA.getClass().#method2(0, ...arr, 3); + const b2 = new (AA.getClass().#method2)(0, ...arr, 3); //Error + const str2 = AA.getClass().#method2`head${1}middle${2}tail`; + } + static getClass() { return AA; } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts new file mode 100644 index 0000000000000..1b8a5c082cc00 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodClassExpression.ts @@ -0,0 +1,13 @@ +// @target: es2015 + +const C = class D { + static #field = D.#method(); + static #method() { return 42; } + static getClass() { return D; } + static getField() { return C.#field }; +} + +console.log(C.getClass().getField()); +C.getClass().#method; // Error +C.getClass().#field; // Error + diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodInStaticFieldInit.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodInStaticFieldInit.ts new file mode 100644 index 0000000000000..826cc72624029 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticMethodInStaticFieldInit.ts @@ -0,0 +1,8 @@ +// @target: es2015 + +class C { + static s = C.#method(); + static #method() { return 42; } +} + +console.log(C.s); diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameStaticsAndStaticMethods.ts b/tests/cases/conformance/classes/members/privateNames/privateNameStaticsAndStaticMethods.ts new file mode 100644 index 0000000000000..7cbf9f8f9992b --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateNameStaticsAndStaticMethods.ts @@ -0,0 +1,33 @@ +// @strict: true +// @target: esnext +// @lib: esnext + +class A { + static #foo(a: number) {} + static async #bar(a: number) {} + static async *#baz(a: number) { + return 3; + } + static #_quux: number; + static get #quux (): number { + return this.#_quux; + } + static set #quux (val: number) { + 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: string) {} + constructor () { + super(); + B.#foo("str"); + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts b/tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts index f7bb388043ac7..76365a4da449f 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNameUnused.ts @@ -9,3 +9,22 @@ export class A { console.log(this.#used); } } + +export class A2 { + #used() { }; + #unused() { }; + constructor () { + console.log(this.#used()); + } +} + +export class A3 { + get #used() { return 0 }; + set #used(value: number) { }; + + get #unused() { return 0 }; + set #unused(value: number) { }; + constructor () { + console.log(this.#used); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts b/tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts index 1ea2826e0470e..293dc6b03bafb 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNamesAndkeyof.ts @@ -2,9 +2,22 @@ // @target: es6 class A { - #foo = 3; + #fooField = 3; + #fooMethod() { }; + get #fooProp() { return 1; }; + set #fooProp(value: number) { }; bar = 3; baz = 3; } -type T = keyof A // should not include '#foo' +// `keyof A` should not include '#foo*' +let k: keyof A = "bar"; // OK +k = "baz"; // OK + +k = "#fooField"; // Error +k = "#fooMethod"; // Error +k = "#fooProp"; // Error + +k = "fooField"; // Error +k = "fooMethod"; // Error +k = "fooProp"; // Error diff --git a/tests/cases/conformance/classes/members/privateNames/privateNamesAssertion.ts b/tests/cases/conformance/classes/members/privateNames/privateNamesAssertion.ts index 69d552b6f0b65..acce5ff55a7f9 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNamesAssertion.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNamesAssertion.ts @@ -12,3 +12,15 @@ class Foo { v; } } + +class Foo2 { + #p1(v: any): asserts v is string { + if (typeof v !== "string") { + throw new Error(); + } + } + m1(v: unknown) { + this.#p1(v); + v; + } +} diff --git a/tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts b/tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts index 225a6d071980d..134b38c3b60a1 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts @@ -4,13 +4,27 @@ class C { #foo: T; + #method(): T { return this.#foo; } + get #prop(): T { return this.#foo; } + set #prop(value : T) { this.#foo = value; } + bar(x: C) { return x.#foo; } // OK + bar2(x: C) { return x.#method(); } // OK + bar3(x: C) { return x.#prop; } // OK + baz(x: C) { return x.#foo; } // OK + baz2(x: C) { return x.#method; } // OK + baz3(x: C) { return x.#prop; } // OK + quux(x: C) { return x.#foo; } // OK + quux2(x: C) { return x.#method; }// OK + quux3(x: C) { return x.#prop; } // OK } declare let a: C; declare let b: C; a.#foo; // Error +a.#method; // Error +a.#prop; // Error a = b; // Error b = a; // Error diff --git a/tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts b/tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts index ef4341ab56752..2db87b88945e5 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNamesIncompatibleModifiers.ts @@ -7,6 +7,28 @@ class A { protected #baz = 3; // Error readonly #qux = 3; // OK declare #what: number; // Error + + public #fooMethod() { return 3; } // Error + private #barMethod() { return 3; } // Error + protected #bazMethod() { return 3; } // Error + readonly #quxMethod() { return 3; } // Error + declare #whatMethod() // Error + async #asyncMethod() { return 1; } //OK + *#genMethod() { return 1; } //OK + async *#asyncGenMethod() { return 1; } //OK + + public get #fooProp() { return 3; } // Error + public set #fooProp(value: number) { } // Error + private get #barProp() { return 3; } // Error + private set #barProp(value: number) { } // Error + protected get #bazProp() { return 3; } // Error + protected set #bazProp(value: number) { } // Error + readonly get #quxProp() { return 3; } // Error + readonly set #quxProp(value: number) { } // Error + declare get #whatProp() // Error + declare set #whatProp(value: number) // Error + async get #asyncProp() { return 1; } // Error + async set #asyncProp(value: number) { } // Error } abstract class B { diff --git a/tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts b/tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts index cc0c3bf8980f9..c47e709c284f1 100644 --- a/tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts +++ b/tests/cases/conformance/classes/members/privateNames/privateNamesUseBeforeDef.ts @@ -5,6 +5,16 @@ class A { #bar = 3; } +class A2 { + #foo = this.#bar(); // No Error + #bar() { return 3 }; +} + +class A3 { + #foo = this.#bar; // No Error + get #bar() { return 3 }; +} + class B { #foo = this.#bar; // Error #bar = this.#foo; diff --git a/tests/cases/conformance/classes/members/privateNames/privateStaticNameShadowing.ts b/tests/cases/conformance/classes/members/privateNames/privateStaticNameShadowing.ts new file mode 100644 index 0000000000000..2d660f064cf23 --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateStaticNameShadowing.ts @@ -0,0 +1,15 @@ +// @target: es2015 + +class X { + static #f = X.#m(); + constructor() { + X.#m(); + } + static #m() { + const X: any = {}; // shadow the class + const _a: any = {}; // shadow the first generated var + X.#m(); // Should check with X as the receiver with _b as the class constructor + return 1; + } + } + \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts b/tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts new file mode 100644 index 0000000000000..e30ed282df94b --- /dev/null +++ b/tests/cases/conformance/classes/members/privateNames/privateWriteOnlyAccessorRead.ts @@ -0,0 +1,34 @@ +// @target: es2015 +class Test { + set #value(v: { foo: { bar: number } }) {} + set #valueRest(v: number[]) {} + set #valueOne(v: number) {} + set #valueCompound(v: number) {} + + m() { + const foo = { bar: 1 }; + console.log(this.#value); // error + this.#value = { foo }; // ok + this.#value = { foo }; // ok + this.#value.foo = foo; // error + + ({ o: this.#value } = { o: { foo } }); //ok + ({ ...this.#value } = { foo }); //ok + + ({ foo: this.#value.foo } = { foo }); //error + ({ + foo: { ...this.#value.foo }, + } = { foo }); //error + + let r = { o: this.#value }; //error + + [this.#valueOne, ...this.#valueRest] = [1, 2, 3]; + let arr = [ + this.#valueOne, + ...this.#valueRest + ]; + + this.#valueCompound += 3; + } +} +new Test().m(); diff --git a/tests/cases/fourslash/codeFixSpellingPrivatePropertyNameNotInScope.ts b/tests/cases/fourslash/codeFixSpellingPrivatePropertyNameNotInScope.ts new file mode 100644 index 0000000000000..6e219fa4d9733 --- /dev/null +++ b/tests/cases/fourslash/codeFixSpellingPrivatePropertyNameNotInScope.ts @@ -0,0 +1,15 @@ +/// + +////class A { +//// #foo: number; +//// constructor() { +//// } +////} +////let a = new A(); +////[|a.foo = 1;|] + +verify.codeFixAvailable([ + { description: "Declare property 'foo'" }, + { description: "Add index signature for property 'foo'" }, + { description: "Remove unused declaration for: '#foo'" } +]); diff --git a/tests/cases/fourslash/completionListPrivateNamesAccessors.ts b/tests/cases/fourslash/completionListPrivateNamesAccessors.ts new file mode 100644 index 0000000000000..1fc143eb836c6 --- /dev/null +++ b/tests/cases/fourslash/completionListPrivateNamesAccessors.ts @@ -0,0 +1,37 @@ +/// + +//// class Foo { +//// get #x() { return 1 }; +//// set #x(value: number) { }; +//// y() {}; +//// } +//// class Bar extends Foo { +//// get #z() { return 1 }; +//// set #z(value: number) { }; +//// t() {}; +//// l; +//// constructor() { +//// this./*1*/ +//// class Baz { +//// get #z() { return 1 }; +//// set #z(value: number) { }; +//// get #u() { return 1 }; +//// set #u(value: number) { }; +//// v() {}; +//// k; +//// constructor() { +//// this./*2*/ +//// new Bar()./*3*/ +//// } +//// } +//// } +//// } +//// +//// new Foo()./*4*/ + + + +verify.completions({ marker: "1", exact: ["#z", "t", "l", "y"] }); +verify.completions({ marker: "2", exact: ["#z", "#u", "v", "k"] }); +verify.completions({ marker: "3", exact: ["#z", "t", "l", "y"] }); +verify.completions({ marker: "4", exact: ["y"] }); diff --git a/tests/cases/fourslash/completionListPrivateNamesMethods.ts b/tests/cases/fourslash/completionListPrivateNamesMethods.ts new file mode 100644 index 0000000000000..d8005a2e7de4d --- /dev/null +++ b/tests/cases/fourslash/completionListPrivateNamesMethods.ts @@ -0,0 +1,31 @@ +/// + +//// class Foo { +//// #x() {}; +//// y() {}; +//// } +//// class Bar extends Foo { +//// #z() {}; +//// t() {}; +//// constructor() { +//// this./*1*/ +//// class Baz { +//// #z() {}; +//// #u() {}; +//// v() {}; +//// constructor() { +//// this./*2*/ +//// new Bar()./*3*/ +//// } +//// } +//// } +//// } +//// +//// new Foo()./*4*/ + + + +verify.completions({ marker: "1", exact: ["#z", "t", "y"] }); +verify.completions({ marker: "2", exact: ["#z", "#u", "v"] }); +verify.completions({ marker: "3", exact: ["#z", "t", "y"] }); +verify.completions({ marker: "4", exact: ["y"] }); diff --git a/tests/cases/fourslash/findAllRefsPrivateNameAccessors.ts b/tests/cases/fourslash/findAllRefsPrivateNameAccessors.ts new file mode 100644 index 0000000000000..5fc76f402407c --- /dev/null +++ b/tests/cases/fourslash/findAllRefsPrivateNameAccessors.ts @@ -0,0 +1,27 @@ +/// + +////class C { +//// [|get [|{|"isDefinition": true, "isWriteAccess":true, "contextRangeIndex": 0 |}#foo|](){ return 1; }|] +//// [|set [|{|"isDefinition": true, "isWriteAccess":true, "contextRangeIndex": 2 |}#foo|](value: number){ }|] +//// constructor() { +//// this.[|#foo|](); +//// } +////} +////class D extends C { +//// constructor() { +//// super() +//// this.#foo = 20; +//// } +////} +////class E { +//// [|get [|{|"isDefinition": true, "isWriteAccess":true, "contextRangeIndex": 5 |}#foo|](){ return 1; }|] +//// [|set [|{|"isDefinition": true, "isWriteAccess":true, "contextRangeIndex": 7 |}#foo|](value: number){ }|] +//// constructor() { +//// this.[|#foo|](); +//// } +////} + +const [rC0DefGet, rC0Get, rC0DefSet, rC0Set, rC1, + rE0GetDef, rE0Get, rE0SetDef, rE0Set, rE1] = test.ranges(); +verify.singleReferenceGroup("(property) C.#foo: number", [rC0Get, rC0Set, rC1]); +verify.singleReferenceGroup("(property) E.#foo: number", [rE0Get, rE0Set, rE1]); diff --git a/tests/cases/fourslash/findAllRefsPrivateNameMethods.ts b/tests/cases/fourslash/findAllRefsPrivateNameMethods.ts new file mode 100644 index 0000000000000..d90a7e3940f98 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsPrivateNameMethods.ts @@ -0,0 +1,24 @@ +/// + +////class C { +//// [|[|{|"isDefinition": true, "isWriteAccess":true, "contextRangeIndex": 0 |}#foo|](){ }|] +//// constructor() { +//// this.[|#foo|](); +//// } +////} +////class D extends C { +//// constructor() { +//// super() +//// this.#foo = 20; +//// } +////} +////class E { +//// [|[|{|"isDefinition": true, "isWriteAccess":true, "contextRangeIndex": 3 |}#foo|](){ }|] +//// constructor() { +//// this.[|#foo|](); +//// } +////} + +const [rC0Def, rC0, rC1, rE0Def, rE0, rE1] = test.ranges(); +verify.singleReferenceGroup("(method) C.#foo(): void", [rC0, rC1]); +verify.singleReferenceGroup("(method) E.#foo(): void", [rE0, rE1]); diff --git a/tests/cases/fourslash/goToDefinitionPrivateName.ts b/tests/cases/fourslash/goToDefinitionPrivateName.ts index 4524fca577c8d..6a551819569c5 100644 --- a/tests/cases/fourslash/goToDefinitionPrivateName.ts +++ b/tests/cases/fourslash/goToDefinitionPrivateName.ts @@ -1,12 +1,19 @@ /// //// class A { -//// [|/*pnDecl*/#foo|] = 3; +//// [|/*pnMethodDecl*/#method|]() { } +//// [|/*pnFieldDecl*/#foo|] = 3; +//// get [|/*pnPropGetDecl*/#prop|]() { return ""; } +//// set [|/*pnPropSetDecl*/#prop|](value: string) { } //// constructor() { -//// this.[|/*pnUse*/#foo|] +//// this.[|/*pnFieldUse*/#foo|] +//// this.[|/*pnMethodUse*/#method|] +//// this.[|/*pnPropUse*/#prop|] //// } //// } verify.goToDefinition({ - pnUse: "pnDecl", + pnFieldUse: "pnFieldDecl", + pnMethodUse: "pnMethodDecl", + pnPropUse: ["pnPropGetDecl", "pnPropSetDecl"] }); diff --git a/tests/cases/fourslash/navigationBarPrivateNameMethod.ts b/tests/cases/fourslash/navigationBarPrivateNameMethod.ts new file mode 100644 index 0000000000000..b97d8e282aa7d --- /dev/null +++ b/tests/cases/fourslash/navigationBarPrivateNameMethod.ts @@ -0,0 +1,109 @@ +/// + +//// class A { +//// #foo() { +//// class B { +//// #bar() { +//// function baz () { +//// } +//// } +//// } +//// } +//// } + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "A", + "kind": "class", + "childItems": [ + { + "text": "#foo", + "kind": "method", + "childItems": [ + { + "text": "B", + "kind": "class", + "childItems": [ + { + "text": "#bar", + "kind": "method", + "childItems": [ + { + "text": "baz", + "kind": "function" + } + ] + } + ] + } + ] + } + ] + }, + ] +}); + +verify.navigationBar([ + { + "text": "", + "kind": "script", + "childItems": [ + { + "text": "A", + "kind": "class" + } + ] + }, + { + "text": "A", + "kind": "class", + "childItems": [ + { + "text": "#foo", + "kind": "method" + } + ], + "indent": 1 + }, + { + "text": "#foo", + "kind": "method", + "childItems": [ + { + "text": "B", + "kind": "class" + } + ], + "indent": 2 + }, + { + "text": "B", + "kind": "class", + "childItems": [ + { + "text": "#bar", + "kind": "method" + } + ], + "indent": 3 + }, + { + "text": "#bar", + "kind": "method", + "childItems": [ + { + "text": "baz", + "kind": "function" + } + ], + "indent": 4 + }, + { + "text": "baz", + "kind": "function", + "indent": 5 + } +]); diff --git a/tests/cases/fourslash/renamePrivateAccessor.ts b/tests/cases/fourslash/renamePrivateAccessor.ts new file mode 100644 index 0000000000000..46a5cd39828d7 --- /dev/null +++ b/tests/cases/fourslash/renamePrivateAccessor.ts @@ -0,0 +1,14 @@ +/// + +////class Foo { +//// [|get [|{| "contextRangeIndex": 0 |}#foo|]() { return 1 }|] +//// [|set [|{| "contextRangeIndex": 2 |}#foo|](value: number) { }|] +//// retFoo() { +//// return this.[|#foo|]; +//// } +////} + +const ranges = test.rangesByText().get("#foo"); +verify.renameLocations(ranges, { + ranges +}); diff --git a/tests/cases/fourslash/renamePrivateMethod.ts b/tests/cases/fourslash/renamePrivateMethod.ts new file mode 100644 index 0000000000000..d0b7ba0aa9d51 --- /dev/null +++ b/tests/cases/fourslash/renamePrivateMethod.ts @@ -0,0 +1,13 @@ +/// + +////class Foo { +//// [|[|{| "contextRangeIndex": 0 |}#foo|]() { }|] +//// callFoo() { +//// return this.[|#foo|](); +//// } +////} + +const ranges = test.rangesByText().get("#foo"); +verify.renameLocations(ranges, { + ranges +});