Skip to content

Commit cded754

Browse files
committed
pick changes
1 parent 51ef837 commit cded754

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34767,8 +34767,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3476734767
case SyntaxKind.EqualsEqualsEqualsToken:
3476834768
case SyntaxKind.ExclamationEqualsEqualsToken:
3476934769
if (isLiteralExpressionOfObject(left) || isLiteralExpressionOfObject(right)) {
34770-
const eqType = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken;
34771-
error(errorNode, Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value, eqType ? "false" : "true");
34770+
if (isInJSFile(left) && (operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken)) {
34771+
// we skip the emit for {} == {} in JS files
34772+
}
34773+
else {
34774+
const eqType = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.EqualsEqualsEqualsToken;
34775+
error(errorNode, Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value, eqType ? "false" : "true");
34776+
}
3477234777
}
3477334778
checkNaNEquality(errorNode, operator, left, right);
3477434779
reportOperatorErrorUnless((left, right) => isTypeEqualityComparableTo(left, right) || isTypeEqualityComparableTo(right, left));

src/compiler/program.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ export const plainJSErrors: Set<number> = new Set([
10591059
Diagnostics.Class_constructor_may_not_be_a_generator.code,
10601060
Diagnostics.Class_constructor_may_not_be_an_accessor.code,
10611061
Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules.code,
1062+
// Type errors
1063+
Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value.code,
10621064
]);
10631065

10641066
/**
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
=== tests/cases/conformance/salsa/plainJSTypeErrors.js ===
2+
23
// should error
3-
No type information for this code.if ({} === {}) {}
4-
No type information for this code.
5-
No type information for this code.// should not error
6-
No type information for this code.if ({} == {}) {}
7-
No type information for this code.
8-
No type information for this code.
4+
if ({} === {}) {}
5+
6+
// should not error
7+
if ({} == {}) {}
8+

0 commit comments

Comments
 (0)