* 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>
223 lines
5.6 KiB
TypeScript
223 lines
5.6 KiB
TypeScript
//// [privateNameInInExpression.ts]
|
|
class Foo {
|
|
#field = 1;
|
|
static #staticField = 2;
|
|
#method() {}
|
|
static #staticMethod() {}
|
|
|
|
goodRhs(v: any) {
|
|
const a = #field in v;
|
|
|
|
const b = #field in v.p1.p2;
|
|
|
|
const c = #field in (v as {});
|
|
|
|
const d = #field in (v as Foo);
|
|
|
|
const e = #field in (v as never);
|
|
|
|
for (let f in #field in v as any) { /**/ } // unlikely but valid
|
|
}
|
|
badRhs(v: any) {
|
|
const a = #field in (v as unknown); // Bad - RHS of in must be object type or any
|
|
|
|
const b = #fiel in v; // Bad - typo in privateID
|
|
|
|
const c = (#field) in v; // Bad - privateID is not an expression on its own
|
|
|
|
for (#field in v) { /**/ } // Bad - 'in' not allowed
|
|
|
|
for (let d in #field in v) { /**/ } // Bad - rhs of in should be a object/any
|
|
}
|
|
whitespace(v: any) {
|
|
const a = v && /*0*/#field/*1*/
|
|
/*2*/in/*3*/
|
|
/*4*/v/*5*/
|
|
}
|
|
flow(u: unknown, n: never, fb: Foo | Bar, fs: FooSub, b: Bar, fsb: FooSub | Bar, fsfb: Foo | FooSub | Bar) {
|
|
|
|
if (typeof u === 'object') {
|
|
if (#field in n) {
|
|
n; // good n is never
|
|
}
|
|
|
|
if (#field in u) {
|
|
u; // good u is Foo
|
|
} else {
|
|
u; // good u is object | null
|
|
}
|
|
|
|
if (u !== null) {
|
|
if (#field in u) {
|
|
u; // good u is Foo
|
|
} else {
|
|
u; // good u is object
|
|
}
|
|
|
|
if (#method in u) {
|
|
u; // good u is Foo
|
|
}
|
|
|
|
if (#staticField in u) {
|
|
u; // good u is typeof Foo
|
|
}
|
|
|
|
if (#staticMethod in u) {
|
|
u; // good u is typeof Foo
|
|
}
|
|
}
|
|
}
|
|
|
|
if (#field in fb) {
|
|
fb; // good fb is Foo
|
|
} else {
|
|
fb; // good fb is Bar
|
|
}
|
|
|
|
if (#field in fs) {
|
|
fs; // good fs is FooSub
|
|
} else {
|
|
fs; // good fs is never
|
|
}
|
|
|
|
if (#field in b) {
|
|
b; // good b is 'Bar & Foo'
|
|
} else {
|
|
b; // good b is Bar
|
|
}
|
|
|
|
if (#field in fsb) {
|
|
fsb; // good fsb is FooSub
|
|
} else {
|
|
fsb; // good fsb is Bar
|
|
}
|
|
|
|
if (#field in fsfb) {
|
|
fsfb; // good fsfb is 'Foo | FooSub'
|
|
} else {
|
|
fsfb; // good fsfb is Bar
|
|
}
|
|
|
|
class Nested {
|
|
m(v: any) {
|
|
if (#field in v) {
|
|
v; // good v is Foo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class FooSub extends Foo { subTypeOfFoo = true }
|
|
class Bar { notFoo = true }
|
|
|
|
function badSyntax(v: Foo) {
|
|
return #field in v; // Bad - outside of class
|
|
}
|
|
|
|
|
|
//// [privateNameInInExpression.js]
|
|
"use strict";
|
|
class Foo {
|
|
#field = 1;
|
|
static #staticField = 2;
|
|
#method() { }
|
|
static #staticMethod() { }
|
|
goodRhs(v) {
|
|
const a = #field in v;
|
|
const b = #field in v.p1.p2;
|
|
const c = #field in v;
|
|
const d = #field in v;
|
|
const e = #field in v;
|
|
for (let f in #field in v) { /**/ } // unlikely but valid
|
|
}
|
|
badRhs(v) {
|
|
const a = #field in v; // Bad - RHS of in must be object type or any
|
|
const b = #fiel in v; // Bad - typo in privateID
|
|
const c = (#field) in v; // Bad - privateID is not an expression on its own
|
|
for (#field in v) { /**/ } // Bad - 'in' not allowed
|
|
for (let d in #field in v) { /**/ } // Bad - rhs of in should be a object/any
|
|
}
|
|
whitespace(v) {
|
|
const a = v && /*0*/ #field /*1*/
|
|
/*2*/ in /*3*/
|
|
/*4*/ v; /*5*/
|
|
}
|
|
flow(u, n, fb, fs, b, fsb, fsfb) {
|
|
if (typeof u === 'object') {
|
|
if (#field in n) {
|
|
n; // good n is never
|
|
}
|
|
if (#field in u) {
|
|
u; // good u is Foo
|
|
}
|
|
else {
|
|
u; // good u is object | null
|
|
}
|
|
if (u !== null) {
|
|
if (#field in u) {
|
|
u; // good u is Foo
|
|
}
|
|
else {
|
|
u; // good u is object
|
|
}
|
|
if (#method in u) {
|
|
u; // good u is Foo
|
|
}
|
|
if (#staticField in u) {
|
|
u; // good u is typeof Foo
|
|
}
|
|
if (#staticMethod in u) {
|
|
u; // good u is typeof Foo
|
|
}
|
|
}
|
|
}
|
|
if (#field in fb) {
|
|
fb; // good fb is Foo
|
|
}
|
|
else {
|
|
fb; // good fb is Bar
|
|
}
|
|
if (#field in fs) {
|
|
fs; // good fs is FooSub
|
|
}
|
|
else {
|
|
fs; // good fs is never
|
|
}
|
|
if (#field in b) {
|
|
b; // good b is 'Bar & Foo'
|
|
}
|
|
else {
|
|
b; // good b is Bar
|
|
}
|
|
if (#field in fsb) {
|
|
fsb; // good fsb is FooSub
|
|
}
|
|
else {
|
|
fsb; // good fsb is Bar
|
|
}
|
|
if (#field in fsfb) {
|
|
fsfb; // good fsfb is 'Foo | FooSub'
|
|
}
|
|
else {
|
|
fsfb; // good fsfb is Bar
|
|
}
|
|
class Nested {
|
|
m(v) {
|
|
if (#field in v) {
|
|
v; // good v is Foo
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
class FooSub extends Foo {
|
|
subTypeOfFoo = true;
|
|
}
|
|
class Bar {
|
|
notFoo = true;
|
|
}
|
|
function badSyntax(v) {
|
|
return #field in v; // Bad - outside of class
|
|
}
|