-
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.
feat: support error when comparing with object/array literals (#45978)
* feat: support error when comparing with object/array literals * chore: include regexp, function and class literal * chore: include regexp, function and class literal * test: update baseline * fix: baseline
- Loading branch information
1 parent
da00ba6
commit b689cd0
Showing
12 changed files
with
768 additions
and
3 deletions.
There are no files selected for viewing
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
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
130 changes: 130 additions & 0 deletions
130
tests/baselines/reference/conditionalEqualityOnLiteralObjects.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,130 @@ | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(4,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(6,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(8,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(10,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(12,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(14,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(17,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(19,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(21,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(23,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(25,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(27,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(30,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(32,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(34,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(36,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(38,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(40,5): error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(43,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(45,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(47,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(49,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(51,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts(53,5): error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
|
||
|
||
==== tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts (24 errors) ==== | ||
const a = { a: 1 } | ||
const b = [1] | ||
|
||
if ({ a: 1 } === { a: 1 }) { | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] === [1]) { | ||
~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if (a === { a: 1 }) { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if (b === [1]) { | ||
~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if ({ a: 1 } === a) { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] === b) { | ||
~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
|
||
if ({ a: 1 } !== { a: 1 }) { | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] !== [1]) { | ||
~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if (a !== { a: 1 }) { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if (b !== [1]) { | ||
~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if ({ a: 1 } !== a) { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] !== b) { | ||
~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
|
||
if ({ a: 1 } == { a: 1 }) { | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] == [1]) { | ||
~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if (a == { a: 1 }) { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if (b == [1]) { | ||
~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if ({ a: 1 } == a) { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] == b) { | ||
~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'false' since JavaScript compares objects by reference, not value. | ||
} | ||
|
||
if ({ a: 1 } != { a: 1 }) { | ||
~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] != [1]) { | ||
~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if (a != { a: 1 }) { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if (b != [1]) { | ||
~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if ({ a: 1 } != a) { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
if ([1] != b) { | ||
~~~~~~~~ | ||
!!! error TS2839: This condition will always return 'true' since JavaScript compares objects by reference, not value. | ||
} | ||
|
108 changes: 108 additions & 0 deletions
108
tests/baselines/reference/conditionalEqualityOnLiteralObjects.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,108 @@ | ||
//// [conditionalEqualityOnLiteralObjects.ts] | ||
const a = { a: 1 } | ||
const b = [1] | ||
|
||
if ({ a: 1 } === { a: 1 }) { | ||
} | ||
if ([1] === [1]) { | ||
} | ||
if (a === { a: 1 }) { | ||
} | ||
if (b === [1]) { | ||
} | ||
if ({ a: 1 } === a) { | ||
} | ||
if ([1] === b) { | ||
} | ||
|
||
if ({ a: 1 } !== { a: 1 }) { | ||
} | ||
if ([1] !== [1]) { | ||
} | ||
if (a !== { a: 1 }) { | ||
} | ||
if (b !== [1]) { | ||
} | ||
if ({ a: 1 } !== a) { | ||
} | ||
if ([1] !== b) { | ||
} | ||
|
||
if ({ a: 1 } == { a: 1 }) { | ||
} | ||
if ([1] == [1]) { | ||
} | ||
if (a == { a: 1 }) { | ||
} | ||
if (b == [1]) { | ||
} | ||
if ({ a: 1 } == a) { | ||
} | ||
if ([1] == b) { | ||
} | ||
|
||
if ({ a: 1 } != { a: 1 }) { | ||
} | ||
if ([1] != [1]) { | ||
} | ||
if (a != { a: 1 }) { | ||
} | ||
if (b != [1]) { | ||
} | ||
if ({ a: 1 } != a) { | ||
} | ||
if ([1] != b) { | ||
} | ||
|
||
|
||
//// [conditionalEqualityOnLiteralObjects.js] | ||
var a = { a: 1 }; | ||
var b = [1]; | ||
if ({ a: 1 } === { a: 1 }) { | ||
} | ||
if ([1] === [1]) { | ||
} | ||
if (a === { a: 1 }) { | ||
} | ||
if (b === [1]) { | ||
} | ||
if ({ a: 1 } === a) { | ||
} | ||
if ([1] === b) { | ||
} | ||
if ({ a: 1 } !== { a: 1 }) { | ||
} | ||
if ([1] !== [1]) { | ||
} | ||
if (a !== { a: 1 }) { | ||
} | ||
if (b !== [1]) { | ||
} | ||
if ({ a: 1 } !== a) { | ||
} | ||
if ([1] !== b) { | ||
} | ||
if ({ a: 1 } == { a: 1 }) { | ||
} | ||
if ([1] == [1]) { | ||
} | ||
if (a == { a: 1 }) { | ||
} | ||
if (b == [1]) { | ||
} | ||
if ({ a: 1 } == a) { | ||
} | ||
if ([1] == b) { | ||
} | ||
if ({ a: 1 } != { a: 1 }) { | ||
} | ||
if ([1] != [1]) { | ||
} | ||
if (a != { a: 1 }) { | ||
} | ||
if (b != [1]) { | ||
} | ||
if ({ a: 1 } != a) { | ||
} | ||
if ([1] != b) { | ||
} |
92 changes: 92 additions & 0 deletions
92
tests/baselines/reference/conditionalEqualityOnLiteralObjects.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,92 @@ | ||
=== tests/cases/compiler/conditionalEqualityOnLiteralObjects.ts === | ||
const a = { a: 1 } | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 11)) | ||
|
||
const b = [1] | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
|
||
if ({ a: 1 } === { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 3, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 3, 18)) | ||
} | ||
if ([1] === [1]) { | ||
} | ||
if (a === { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 7, 11)) | ||
} | ||
if (b === [1]) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
if ({ a: 1 } === a) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 11, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
} | ||
if ([1] === b) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
|
||
if ({ a: 1 } !== { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 16, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 16, 18)) | ||
} | ||
if ([1] !== [1]) { | ||
} | ||
if (a !== { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 20, 11)) | ||
} | ||
if (b !== [1]) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
if ({ a: 1 } !== a) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 24, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
} | ||
if ([1] !== b) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
|
||
if ({ a: 1 } == { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 29, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 29, 17)) | ||
} | ||
if ([1] == [1]) { | ||
} | ||
if (a == { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 33, 10)) | ||
} | ||
if (b == [1]) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
if ({ a: 1 } == a) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 37, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
} | ||
if ([1] == b) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
|
||
if ({ a: 1 } != { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 42, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 42, 17)) | ||
} | ||
if ([1] != [1]) { | ||
} | ||
if (a != { a: 1 }) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 46, 10)) | ||
} | ||
if (b != [1]) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
if ({ a: 1 } != a) { | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 50, 5)) | ||
>a : Symbol(a, Decl(conditionalEqualityOnLiteralObjects.ts, 0, 5)) | ||
} | ||
if ([1] != b) { | ||
>b : Symbol(b, Decl(conditionalEqualityOnLiteralObjects.ts, 1, 5)) | ||
} | ||
|
Oops, something went wrong.