* 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 <kahvecikubilay@gmail.com> * Rename shouldTransformPrivateFields Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Accept baseline Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Use a single WeakSet for brand-check Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Accept baseline Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Add a test for using private methods in static field initializers Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Add breaking checker test Private methods inside class expressions should not error. Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Add to instances once per-instance Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Accept baseline Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: evaluate receiver and rhs expressions before throwing on readonly assignment Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Add a test for evaluating rhs before readonly assignment Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Transpile private accessors Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Accept baseline Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: handle readonly/writeonly accessors Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * accept baseline Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * add a test for private setter without a getter Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: getAllUnscopedEmitHelpers Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: better handling of duplicate names Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Fixed wrong error message for private methods in class expressions. * change error message Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * add a test for async private methods with a higher target Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: setter assignment returns rhs value Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * add a test for setter assignment return value Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: handle duplicate accessors Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * add tests for duplicate accessors Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * docs: add missing parameter docs Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * Fixed failing test. * baseline-accept: ordering changes Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * fix: attach weakSetName to property declaration Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * add a test for nested private methods Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * add a test with any Signed-off-by: Kubilay Kahveci <kahvecikubilay@gmail.com> * 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 <kahvecikubilay@gmail.com>
122 lines
6.2 KiB
Plaintext
122 lines
6.2 KiB
Plaintext
=== tests/cases/conformance/classes/members/privateNames/privateNamesInGenericClasses.ts ===
|
|
class C<T> {
|
|
>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0))
|
|
>T : Symbol(T, Decl(privateNamesInGenericClasses.ts, 0, 8))
|
|
|
|
#foo: T;
|
|
>#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<T>) { return x.#foo; } // OK
|
|
>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, 6, 8))
|
|
|
|
bar2(x: C<T>) { 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<T>) { 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<number>) { return x.#foo; } // OK
|
|
>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, 10, 8))
|
|
|
|
baz2(x: C<number>) { 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<number>) { 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<string>) { return x.#foo; } // OK
|
|
>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, 14, 9))
|
|
|
|
quux2(x: C<string>) { 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<string>) { 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<number>;
|
|
>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11))
|
|
>C : Symbol(C, Decl(privateNamesInGenericClasses.ts, 0, 0))
|
|
|
|
declare let b: C<string>;
|
|
>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, 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, 19, 11))
|
|
>b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 20, 11))
|
|
|
|
b = a; // Error
|
|
>b : Symbol(b, Decl(privateNamesInGenericClasses.ts, 20, 11))
|
|
>a : Symbol(a, Decl(privateNamesInGenericClasses.ts, 19, 11))
|
|
|