Skip to content

update keyof tests and ?? #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ namespace ts {
}
else {
const expressions: Expression[] = [];
temp = temp ?? createClassTempVar ();
temp ||= createClassTempVar();
if (isClassWithConstructorReference) {
// record an alias as the class name is not in scope for statics.
enableSubstitutionForClassAliases();
Expand Down
42 changes: 42 additions & 0 deletions tests/baselines/reference/privateNamesAndkeyof.errors.txt
Original file line number Diff line number Diff line change
@@ -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'.

21 changes: 20 additions & 1 deletion tests/baselines/reference/privateNamesAndkeyof.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ class A {
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]
Expand All @@ -26,3 +36,12 @@ class A {
;
}
_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
26 changes: 24 additions & 2 deletions tests/baselines/reference/privateNamesAndkeyof.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,29 @@ class A {
>baz : Symbol(A.baz, Decl(privateNamesAndkeyof.ts, 5, 12))
}

type T = keyof A // should not include '#foo*'
>T : Symbol(T, Decl(privateNamesAndkeyof.ts, 7, 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))

41 changes: 39 additions & 2 deletions tests/baselines/reference/privateNamesAndkeyof.types
Original file line number Diff line number Diff line change
Expand Up @@ -26,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"

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@ class A {
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