-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
426 additions
and
12 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
tests/baselines/reference/discriminantNarrowingCouldBeCircular.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
discriminantNarrowingCouldBeCircular.ts(13,53): error TS2304: Cannot find name 'Element'. | ||
discriminantNarrowingCouldBeCircular.ts(13,63): error TS2304: Cannot find name 'Element'. | ||
discriminantNarrowingCouldBeCircular.ts(15,39): error TS2304: Cannot find name 'Element'. | ||
discriminantNarrowingCouldBeCircular.ts(16,17): error TS2304: Cannot find name 'Element'. | ||
|
||
|
||
==== discriminantNarrowingCouldBeCircular.ts (4 errors) ==== | ||
// #57705, 57690 | ||
declare function is<T>(v: T): v is T; | ||
const o: Record<string, string> | undefined = {}; | ||
if (o) { | ||
for (const key in o) { | ||
const value = o[key]; | ||
if (is<string>(value)) { | ||
} | ||
} | ||
} | ||
|
||
declare const kPresentationInheritanceParents: { [tagName: string]: string[] }; | ||
declare function parentElementOrShadowHost(element: Element): Element | undefined; | ||
~~~~~~~ | ||
!!! error TS2304: Cannot find name 'Element'. | ||
~~~~~~~ | ||
!!! error TS2304: Cannot find name 'Element'. | ||
|
||
function getImplicitAriaRole(element: Element) { | ||
~~~~~~~ | ||
!!! error TS2304: Cannot find name 'Element'. | ||
let ancestor: Element | null = element; | ||
~~~~~~~ | ||
!!! error TS2304: Cannot find name 'Element'. | ||
while (ancestor) { | ||
const parent = parentElementOrShadowHost(ancestor); | ||
const parents = kPresentationInheritanceParents[ancestor.tagName]; | ||
if (!parents || !parent || !parents.includes(parent.tagName)) | ||
break; | ||
ancestor = parent; | ||
} | ||
} | ||
|
||
declare function isPlainObject2<T>( | ||
data: unknown, | ||
): data is Record<PropertyKey, unknown>; | ||
|
||
declare const myObj2: unknown; | ||
if (isPlainObject2(myObj2)) { | ||
for (const key of ["a", "b", "c"]) { | ||
const deeper = myObj2[key]; | ||
const deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
} | ||
} | ||
|
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/discriminantNarrowingCouldBeCircular.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//// [tests/cases/compiler/discriminantNarrowingCouldBeCircular.ts] //// | ||
|
||
//// [discriminantNarrowingCouldBeCircular.ts] | ||
// #57705, 57690 | ||
declare function is<T>(v: T): v is T; | ||
const o: Record<string, string> | undefined = {}; | ||
if (o) { | ||
for (const key in o) { | ||
const value = o[key]; | ||
if (is<string>(value)) { | ||
} | ||
} | ||
} | ||
|
||
declare const kPresentationInheritanceParents: { [tagName: string]: string[] }; | ||
declare function parentElementOrShadowHost(element: Element): Element | undefined; | ||
|
||
function getImplicitAriaRole(element: Element) { | ||
let ancestor: Element | null = element; | ||
while (ancestor) { | ||
const parent = parentElementOrShadowHost(ancestor); | ||
const parents = kPresentationInheritanceParents[ancestor.tagName]; | ||
if (!parents || !parent || !parents.includes(parent.tagName)) | ||
break; | ||
ancestor = parent; | ||
} | ||
} | ||
|
||
declare function isPlainObject2<T>( | ||
data: unknown, | ||
): data is Record<PropertyKey, unknown>; | ||
|
||
declare const myObj2: unknown; | ||
if (isPlainObject2(myObj2)) { | ||
for (const key of ["a", "b", "c"]) { | ||
const deeper = myObj2[key]; | ||
const deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
} | ||
} | ||
|
||
|
||
//// [discriminantNarrowingCouldBeCircular.js] | ||
"use strict"; | ||
var o = {}; | ||
if (o) { | ||
for (var key in o) { | ||
var value = o[key]; | ||
if (is(value)) { | ||
} | ||
} | ||
} | ||
function getImplicitAriaRole(element) { | ||
var ancestor = element; | ||
while (ancestor) { | ||
var parent = parentElementOrShadowHost(ancestor); | ||
var parents = kPresentationInheritanceParents[ancestor.tagName]; | ||
if (!parents || !parent || !parents.includes(parent.tagName)) | ||
break; | ||
ancestor = parent; | ||
} | ||
} | ||
if (isPlainObject2(myObj2)) { | ||
for (var _i = 0, _a = ["a", "b", "c"]; _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var deeper = myObj2[key]; | ||
var deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
tests/baselines/reference/discriminantNarrowingCouldBeCircular.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
//// [tests/cases/compiler/discriminantNarrowingCouldBeCircular.ts] //// | ||
|
||
=== discriminantNarrowingCouldBeCircular.ts === | ||
// #57705, 57690 | ||
declare function is<T>(v: T): v is T; | ||
>is : Symbol(is, Decl(discriminantNarrowingCouldBeCircular.ts, 0, 0)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 20)) | ||
>v : Symbol(v, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 23)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 20)) | ||
>v : Symbol(v, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 23)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 1, 20)) | ||
|
||
const o: Record<string, string> | undefined = {}; | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
|
||
if (o) { | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
|
||
for (const key in o) { | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 4, 12)) | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
|
||
const value = o[key]; | ||
>value : Symbol(value, Decl(discriminantNarrowingCouldBeCircular.ts, 5, 9)) | ||
>o : Symbol(o, Decl(discriminantNarrowingCouldBeCircular.ts, 2, 5)) | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 4, 12)) | ||
|
||
if (is<string>(value)) { | ||
>is : Symbol(is, Decl(discriminantNarrowingCouldBeCircular.ts, 0, 0)) | ||
>value : Symbol(value, Decl(discriminantNarrowingCouldBeCircular.ts, 5, 9)) | ||
} | ||
} | ||
} | ||
|
||
declare const kPresentationInheritanceParents: { [tagName: string]: string[] }; | ||
>kPresentationInheritanceParents : Symbol(kPresentationInheritanceParents, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 13)) | ||
>tagName : Symbol(tagName, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 50)) | ||
|
||
declare function parentElementOrShadowHost(element: Element): Element | undefined; | ||
>parentElementOrShadowHost : Symbol(parentElementOrShadowHost, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 79)) | ||
>element : Symbol(element, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 43)) | ||
>Element : Symbol(Element) | ||
>Element : Symbol(Element) | ||
|
||
function getImplicitAriaRole(element: Element) { | ||
>getImplicitAriaRole : Symbol(getImplicitAriaRole, Decl(discriminantNarrowingCouldBeCircular.ts, 12, 82)) | ||
>element : Symbol(element, Decl(discriminantNarrowingCouldBeCircular.ts, 14, 29)) | ||
>Element : Symbol(Element) | ||
|
||
let ancestor: Element | null = element; | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 5)) | ||
>Element : Symbol(Element) | ||
>element : Symbol(element, Decl(discriminantNarrowingCouldBeCircular.ts, 14, 29)) | ||
|
||
while (ancestor) { | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 5)) | ||
|
||
const parent = parentElementOrShadowHost(ancestor); | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 17, 9)) | ||
>parentElementOrShadowHost : Symbol(parentElementOrShadowHost, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 79)) | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 5)) | ||
|
||
const parents = kPresentationInheritanceParents[ancestor.tagName]; | ||
>parents : Symbol(parents, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
>kPresentationInheritanceParents : Symbol(kPresentationInheritanceParents, Decl(discriminantNarrowingCouldBeCircular.ts, 11, 13)) | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 5)) | ||
|
||
if (!parents || !parent || !parents.includes(parent.tagName)) | ||
>parents : Symbol(parents, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 17, 9)) | ||
>parents.includes : Symbol(Array.includes, Decl(lib.es2016.array.include.d.ts, --, --)) | ||
>parents : Symbol(parents, Decl(discriminantNarrowingCouldBeCircular.ts, 18, 9)) | ||
>includes : Symbol(Array.includes, Decl(lib.es2016.array.include.d.ts, --, --)) | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 17, 9)) | ||
|
||
break; | ||
ancestor = parent; | ||
>ancestor : Symbol(ancestor, Decl(discriminantNarrowingCouldBeCircular.ts, 15, 5)) | ||
>parent : Symbol(parent, Decl(discriminantNarrowingCouldBeCircular.ts, 17, 9)) | ||
} | ||
} | ||
|
||
declare function isPlainObject2<T>( | ||
>isPlainObject2 : Symbol(isPlainObject2, Decl(discriminantNarrowingCouldBeCircular.ts, 23, 1)) | ||
>T : Symbol(T, Decl(discriminantNarrowingCouldBeCircular.ts, 25, 32)) | ||
|
||
data: unknown, | ||
>data : Symbol(data, Decl(discriminantNarrowingCouldBeCircular.ts, 25, 35)) | ||
|
||
): data is Record<PropertyKey, unknown>; | ||
>data : Symbol(data, Decl(discriminantNarrowingCouldBeCircular.ts, 25, 35)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) | ||
|
||
declare const myObj2: unknown; | ||
>myObj2 : Symbol(myObj2, Decl(discriminantNarrowingCouldBeCircular.ts, 29, 15)) | ||
|
||
if (isPlainObject2(myObj2)) { | ||
>isPlainObject2 : Symbol(isPlainObject2, Decl(discriminantNarrowingCouldBeCircular.ts, 23, 1)) | ||
>myObj2 : Symbol(myObj2, Decl(discriminantNarrowingCouldBeCircular.ts, 29, 15)) | ||
|
||
for (const key of ["a", "b", "c"]) { | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 31, 16)) | ||
|
||
const deeper = myObj2[key]; | ||
>deeper : Symbol(deeper, Decl(discriminantNarrowingCouldBeCircular.ts, 32, 13)) | ||
>myObj2 : Symbol(myObj2, Decl(discriminantNarrowingCouldBeCircular.ts, 29, 15)) | ||
>key : Symbol(key, Decl(discriminantNarrowingCouldBeCircular.ts, 31, 16)) | ||
|
||
const deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
>deeperKeys : Symbol(deeperKeys, Decl(discriminantNarrowingCouldBeCircular.ts, 33, 13)) | ||
>isPlainObject2 : Symbol(isPlainObject2, Decl(discriminantNarrowingCouldBeCircular.ts, 23, 1)) | ||
>deeper : Symbol(deeper, Decl(discriminantNarrowingCouldBeCircular.ts, 32, 13)) | ||
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
>deeper : Symbol(deeper, Decl(discriminantNarrowingCouldBeCircular.ts, 32, 13)) | ||
} | ||
} | ||
|
134 changes: 134 additions & 0 deletions
134
tests/baselines/reference/discriminantNarrowingCouldBeCircular.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
//// [tests/cases/compiler/discriminantNarrowingCouldBeCircular.ts] //// | ||
|
||
=== discriminantNarrowingCouldBeCircular.ts === | ||
// #57705, 57690 | ||
declare function is<T>(v: T): v is T; | ||
>is : <T>(v: T) => v is T | ||
>v : T | ||
|
||
const o: Record<string, string> | undefined = {}; | ||
>o : Record<string, string> | undefined | ||
>{} : {} | ||
|
||
if (o) { | ||
>o : Record<string, string> | ||
|
||
for (const key in o) { | ||
>key : string | ||
>o : Record<string, string> | ||
|
||
const value = o[key]; | ||
>value : string | ||
>o[key] : string | ||
>o : Record<string, string> | ||
>key : string | ||
|
||
if (is<string>(value)) { | ||
>is<string>(value) : boolean | ||
>is : <T>(v: T) => v is T | ||
>value : string | ||
} | ||
} | ||
} | ||
|
||
declare const kPresentationInheritanceParents: { [tagName: string]: string[] }; | ||
>kPresentationInheritanceParents : { [tagName: string]: string[]; } | ||
>tagName : string | ||
|
||
declare function parentElementOrShadowHost(element: Element): Element | undefined; | ||
>parentElementOrShadowHost : (element: Element) => Element | undefined | ||
>element : Element | ||
|
||
function getImplicitAriaRole(element: Element) { | ||
>getImplicitAriaRole : (element: Element) => void | ||
>element : Element | ||
|
||
let ancestor: Element | null = element; | ||
>ancestor : any | ||
>element : Element | ||
|
||
while (ancestor) { | ||
>ancestor : any | ||
|
||
const parent = parentElementOrShadowHost(ancestor); | ||
>parent : any | ||
>parentElementOrShadowHost(ancestor) : any | ||
>parentElementOrShadowHost : (element: Element) => any | ||
>ancestor : any | ||
|
||
const parents = kPresentationInheritanceParents[ancestor.tagName]; | ||
>parents : string[] | ||
>kPresentationInheritanceParents[ancestor.tagName] : string[] | ||
>kPresentationInheritanceParents : { [tagName: string]: string[]; } | ||
>ancestor.tagName : any | ||
>ancestor : any | ||
>tagName : any | ||
|
||
if (!parents || !parent || !parents.includes(parent.tagName)) | ||
>!parents || !parent || !parents.includes(parent.tagName) : boolean | ||
>!parents || !parent : boolean | ||
>!parents : false | ||
>parents : string[] | ||
>!parent : boolean | ||
>parent : any | ||
>!parents.includes(parent.tagName) : boolean | ||
>parents.includes(parent.tagName) : boolean | ||
>parents.includes : (searchElement: string, fromIndex?: number | undefined) => boolean | ||
>parents : string[] | ||
>includes : (searchElement: string, fromIndex?: number | undefined) => boolean | ||
>parent.tagName : any | ||
>parent : any | ||
>tagName : any | ||
|
||
break; | ||
ancestor = parent; | ||
>ancestor = parent : any | ||
>ancestor : any | ||
>parent : any | ||
} | ||
} | ||
|
||
declare function isPlainObject2<T>( | ||
>isPlainObject2 : <T>(data: unknown) => data is Record<PropertyKey, unknown> | ||
|
||
data: unknown, | ||
>data : unknown | ||
|
||
): data is Record<PropertyKey, unknown>; | ||
|
||
declare const myObj2: unknown; | ||
>myObj2 : unknown | ||
|
||
if (isPlainObject2(myObj2)) { | ||
>isPlainObject2(myObj2) : boolean | ||
>isPlainObject2 : <T>(data: unknown) => data is Record<PropertyKey, unknown> | ||
>myObj2 : unknown | ||
|
||
for (const key of ["a", "b", "c"]) { | ||
>key : string | ||
>["a", "b", "c"] : string[] | ||
>"a" : "a" | ||
>"b" : "b" | ||
>"c" : "c" | ||
|
||
const deeper = myObj2[key]; | ||
>deeper : unknown | ||
>myObj2[key] : unknown | ||
>myObj2 : Record<PropertyKey, unknown> | ||
>key : string | ||
|
||
const deeperKeys = isPlainObject2(deeper) ? Object.keys(deeper) : []; | ||
>deeperKeys : string[] | ||
>isPlainObject2(deeper) ? Object.keys(deeper) : [] : string[] | ||
>isPlainObject2(deeper) : boolean | ||
>isPlainObject2 : <T>(data: unknown) => data is Record<PropertyKey, unknown> | ||
>deeper : unknown | ||
>Object.keys(deeper) : string[] | ||
>Object.keys : { (o: object): string[]; (o: {}): string[]; } | ||
>Object : ObjectConstructor | ||
>keys : { (o: object): string[]; (o: {}): string[]; } | ||
>deeper : Record<PropertyKey, unknown> | ||
>[] : never[] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.