af689cc5d5
* es private fields in in (#52) add support for the 'private-fields-in-in' TC39 proposal Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [fixup] include inToken when walking forEachChild(node, cb) * [squash] re-accept lib definition baseline changes * [squash] reduce if/else to ternary Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] drop 'originalName' and rename parameter instead Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] extend spelling suggestion to all privateIdentifiers Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] revert the added lexical spelling suggestions logic Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] update baseline Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] inline variable as per PR suggestion Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] test targets both esnext and es2020 as per PR comment Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * switch to using a binary expression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] PrivateIdentifier now extends PrimaryExpression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] accept public api baseline changes Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] classPrivateFieldInHelper now has documentation Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] type-check now follows existing in-expression path Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] parser now follows existing binaryExpression path Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] correct typo in comment Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] no longer use esNext flag Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] swap 'reciever, state' helper params Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] remove change to parenthesizerRules Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] apply suggested changes to checker Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] remove need for assertion in fixSpelling Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] improve comment hint in test Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] fix comment typos Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] add flow-test for Foo | FooSub | Bar Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] add checkExternalEmitHelpers call and new test case Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] simplify and correct parser Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] move most of the added checker logic to expression level Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] always error when privateId could not be resolved Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] reword comment Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] fix codeFixSpelling test Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] do less work Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * store symbol by priateId not binaryExpression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * moved parsePrivateIdentifier into parsePrimaryExpression Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] checkInExpressionn bails out early on silentNeverType Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] more detailed error messages Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] resolves conflict in diagnosticMessages.json Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] update baseline for importHelpersES6 Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] remove redundent if and comment from parser Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] split up grammar/check/symbolLookup Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com> * [squash] reword message for existing left side of in-expression error Signed-off-by: Ashley Claymore <acutmore@users.noreply.github.com>
270 lines
11 KiB
Plaintext
270 lines
11 KiB
Plaintext
=== tests/cases/conformance/classes/members/privateNames/privateNameInInExpression.ts ===
|
|
class Foo {
|
|
>Foo : Symbol(Foo, Decl(privateNameInInExpression.ts, 0, 0))
|
|
|
|
#field = 1;
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
|
|
static #staticField = 2;
|
|
>#staticField : Symbol(Foo.#staticField, Decl(privateNameInInExpression.ts, 1, 15))
|
|
|
|
#method() {}
|
|
>#method : Symbol(Foo.#method, Decl(privateNameInInExpression.ts, 2, 28))
|
|
|
|
static #staticMethod() {}
|
|
>#staticMethod : Symbol(Foo.#staticMethod, Decl(privateNameInInExpression.ts, 3, 16))
|
|
|
|
goodRhs(v: any) {
|
|
>goodRhs : Symbol(Foo.goodRhs, Decl(privateNameInInExpression.ts, 4, 29))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
|
|
const a = #field in v;
|
|
>a : Symbol(a, Decl(privateNameInInExpression.ts, 7, 13))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
|
|
const b = #field in v.p1.p2;
|
|
>b : Symbol(b, Decl(privateNameInInExpression.ts, 9, 13))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
|
|
const c = #field in (v as {});
|
|
>c : Symbol(c, Decl(privateNameInInExpression.ts, 11, 13))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
|
|
const d = #field in (v as Foo);
|
|
>d : Symbol(d, Decl(privateNameInInExpression.ts, 13, 13))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
>Foo : Symbol(Foo, Decl(privateNameInInExpression.ts, 0, 0))
|
|
|
|
const e = #field in (v as never);
|
|
>e : Symbol(e, Decl(privateNameInInExpression.ts, 15, 13))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
|
|
for (let f in #field in v as any) { /**/ } // unlikely but valid
|
|
>f : Symbol(f, Decl(privateNameInInExpression.ts, 17, 16))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 6, 12))
|
|
}
|
|
badRhs(v: any) {
|
|
>badRhs : Symbol(Foo.badRhs, Decl(privateNameInInExpression.ts, 18, 5))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 19, 11))
|
|
|
|
const a = #field in (v as unknown); // Bad - RHS of in must be object type or any
|
|
>a : Symbol(a, Decl(privateNameInInExpression.ts, 20, 13))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 19, 11))
|
|
|
|
const b = #fiel in v; // Bad - typo in privateID
|
|
>b : Symbol(b, Decl(privateNameInInExpression.ts, 22, 13))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 19, 11))
|
|
|
|
const c = (#field) in v; // Bad - privateID is not an expression on its own
|
|
>c : Symbol(c, Decl(privateNameInInExpression.ts, 24, 13))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 19, 11))
|
|
|
|
for (#field in v) { /**/ } // Bad - 'in' not allowed
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 19, 11))
|
|
|
|
for (let d in #field in v) { /**/ } // Bad - rhs of in should be a object/any
|
|
>d : Symbol(d, Decl(privateNameInInExpression.ts, 28, 16))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 19, 11))
|
|
}
|
|
whitespace(v: any) {
|
|
>whitespace : Symbol(Foo.whitespace, Decl(privateNameInInExpression.ts, 29, 5))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 30, 15))
|
|
|
|
const a = v && /*0*/#field/*1*/
|
|
>a : Symbol(a, Decl(privateNameInInExpression.ts, 31, 13))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 30, 15))
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
|
|
/*2*/in/*3*/
|
|
/*4*/v/*5*/
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 30, 15))
|
|
}
|
|
flow(u: unknown, n: never, fb: Foo | Bar, fs: FooSub, b: Bar, fsb: FooSub | Bar, fsfb: Foo | FooSub | Bar) {
|
|
>flow : Symbol(Foo.flow, Decl(privateNameInInExpression.ts, 34, 5))
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
>n : Symbol(n, Decl(privateNameInInExpression.ts, 35, 20))
|
|
>fb : Symbol(fb, Decl(privateNameInInExpression.ts, 35, 30))
|
|
>Foo : Symbol(Foo, Decl(privateNameInInExpression.ts, 0, 0))
|
|
>Bar : Symbol(Bar, Decl(privateNameInInExpression.ts, 109, 48))
|
|
>fs : Symbol(fs, Decl(privateNameInInExpression.ts, 35, 45))
|
|
>FooSub : Symbol(FooSub, Decl(privateNameInInExpression.ts, 107, 1))
|
|
>b : Symbol(b, Decl(privateNameInInExpression.ts, 35, 57))
|
|
>Bar : Symbol(Bar, Decl(privateNameInInExpression.ts, 109, 48))
|
|
>fsb : Symbol(fsb, Decl(privateNameInInExpression.ts, 35, 65))
|
|
>FooSub : Symbol(FooSub, Decl(privateNameInInExpression.ts, 107, 1))
|
|
>Bar : Symbol(Bar, Decl(privateNameInInExpression.ts, 109, 48))
|
|
>fsfb : Symbol(fsfb, Decl(privateNameInInExpression.ts, 35, 84))
|
|
>Foo : Symbol(Foo, Decl(privateNameInInExpression.ts, 0, 0))
|
|
>FooSub : Symbol(FooSub, Decl(privateNameInInExpression.ts, 107, 1))
|
|
>Bar : Symbol(Bar, Decl(privateNameInInExpression.ts, 109, 48))
|
|
|
|
if (typeof u === 'object') {
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
if (#field in n) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>n : Symbol(n, Decl(privateNameInInExpression.ts, 35, 20))
|
|
|
|
n; // good n is never
|
|
>n : Symbol(n, Decl(privateNameInInExpression.ts, 35, 20))
|
|
}
|
|
|
|
if (#field in u) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
u; // good u is Foo
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
} else {
|
|
u; // good u is object | null
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
}
|
|
|
|
if (u !== null) {
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
if (#field in u) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
u; // good u is Foo
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
} else {
|
|
u; // good u is object
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
}
|
|
|
|
if (#method in u) {
|
|
>#method : Symbol(Foo.#method, Decl(privateNameInInExpression.ts, 2, 28))
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
u; // good u is Foo
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
}
|
|
|
|
if (#staticField in u) {
|
|
>#staticField : Symbol(Foo.#staticField, Decl(privateNameInInExpression.ts, 1, 15))
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
u; // good u is typeof Foo
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
}
|
|
|
|
if (#staticMethod in u) {
|
|
>#staticMethod : Symbol(Foo.#staticMethod, Decl(privateNameInInExpression.ts, 3, 16))
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
|
|
u; // good u is typeof Foo
|
|
>u : Symbol(u, Decl(privateNameInInExpression.ts, 35, 9))
|
|
}
|
|
}
|
|
}
|
|
|
|
if (#field in fb) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>fb : Symbol(fb, Decl(privateNameInInExpression.ts, 35, 30))
|
|
|
|
fb; // good fb is Foo
|
|
>fb : Symbol(fb, Decl(privateNameInInExpression.ts, 35, 30))
|
|
|
|
} else {
|
|
fb; // good fb is Bar
|
|
>fb : Symbol(fb, Decl(privateNameInInExpression.ts, 35, 30))
|
|
}
|
|
|
|
if (#field in fs) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>fs : Symbol(fs, Decl(privateNameInInExpression.ts, 35, 45))
|
|
|
|
fs; // good fs is FooSub
|
|
>fs : Symbol(fs, Decl(privateNameInInExpression.ts, 35, 45))
|
|
|
|
} else {
|
|
fs; // good fs is never
|
|
>fs : Symbol(fs, Decl(privateNameInInExpression.ts, 35, 45))
|
|
}
|
|
|
|
if (#field in b) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>b : Symbol(b, Decl(privateNameInInExpression.ts, 35, 57))
|
|
|
|
b; // good b is 'Bar & Foo'
|
|
>b : Symbol(b, Decl(privateNameInInExpression.ts, 35, 57))
|
|
|
|
} else {
|
|
b; // good b is Bar
|
|
>b : Symbol(b, Decl(privateNameInInExpression.ts, 35, 57))
|
|
}
|
|
|
|
if (#field in fsb) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>fsb : Symbol(fsb, Decl(privateNameInInExpression.ts, 35, 65))
|
|
|
|
fsb; // good fsb is FooSub
|
|
>fsb : Symbol(fsb, Decl(privateNameInInExpression.ts, 35, 65))
|
|
|
|
} else {
|
|
fsb; // good fsb is Bar
|
|
>fsb : Symbol(fsb, Decl(privateNameInInExpression.ts, 35, 65))
|
|
}
|
|
|
|
if (#field in fsfb) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>fsfb : Symbol(fsfb, Decl(privateNameInInExpression.ts, 35, 84))
|
|
|
|
fsfb; // good fsfb is 'Foo | FooSub'
|
|
>fsfb : Symbol(fsfb, Decl(privateNameInInExpression.ts, 35, 84))
|
|
|
|
} else {
|
|
fsfb; // good fsfb is Bar
|
|
>fsfb : Symbol(fsfb, Decl(privateNameInInExpression.ts, 35, 84))
|
|
}
|
|
|
|
class Nested {
|
|
>Nested : Symbol(Nested, Decl(privateNameInInExpression.ts, 97, 9))
|
|
|
|
m(v: any) {
|
|
>m : Symbol(Nested.m, Decl(privateNameInInExpression.ts, 99, 22))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 100, 14))
|
|
|
|
if (#field in v) {
|
|
>#field : Symbol(Foo.#field, Decl(privateNameInInExpression.ts, 0, 11))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 100, 14))
|
|
|
|
v; // good v is Foo
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 100, 14))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class FooSub extends Foo { subTypeOfFoo = true }
|
|
>FooSub : Symbol(FooSub, Decl(privateNameInInExpression.ts, 107, 1))
|
|
>Foo : Symbol(Foo, Decl(privateNameInInExpression.ts, 0, 0))
|
|
>subTypeOfFoo : Symbol(FooSub.subTypeOfFoo, Decl(privateNameInInExpression.ts, 109, 26))
|
|
|
|
class Bar { notFoo = true }
|
|
>Bar : Symbol(Bar, Decl(privateNameInInExpression.ts, 109, 48))
|
|
>notFoo : Symbol(Bar.notFoo, Decl(privateNameInInExpression.ts, 110, 11))
|
|
|
|
function badSyntax(v: Foo) {
|
|
>badSyntax : Symbol(badSyntax, Decl(privateNameInInExpression.ts, 110, 27))
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 112, 19))
|
|
>Foo : Symbol(Foo, Decl(privateNameInInExpression.ts, 0, 0))
|
|
|
|
return #field in v; // Bad - outside of class
|
|
>v : Symbol(v, Decl(privateNameInInExpression.ts, 112, 19))
|
|
}
|
|
|