File tree 4 files changed +28
-1
lines changed
4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -15929,12 +15929,16 @@ namespace ts {
15929
15929
checkAssignmentOperator(rightType);
15930
15930
return getRegularTypeOfObjectLiteral(rightType);
15931
15931
case SyntaxKind.CommaToken:
15932
- if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left)) {
15932
+ if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right) ) {
15933
15933
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
15934
15934
}
15935
15935
return rightType;
15936
15936
}
15937
15937
15938
+ function isEvalNode(node: Expression) {
15939
+ return node.kind === SyntaxKind.Identifier && (node as Identifier).text === "eval";
15940
+ }
15941
+
15938
15942
// Return true if there was no error, false if there was an error.
15939
15943
function checkForDisallowedESSymbolOperand(operator: SyntaxKind): boolean {
15940
15944
const offendingSymbolOperand =
Original file line number Diff line number Diff line change
1
+ tests/cases/compiler/evalAfter0.ts(4,2): error TS2695: Left side of comma operator is unused and has no side effects.
2
+
3
+
4
+ ==== tests/cases/compiler/evalAfter0.ts (1 errors) ====
5
+ (0,eval)("10"); // fine: special case for eval
6
+
7
+ declare var eva;
8
+ (0,eva)("10"); // error: no side effect left of comma (suspect of missing method name or something)
9
+ ~
10
+ !!! error TS2695: Left side of comma operator is unused and has no side effects.
Original file line number Diff line number Diff line change
1
+ //// [evalAfter0.ts]
2
+ ( 0 , eval ) ( "10" ) ; // fine: special case for eval
3
+
4
+ declare var eva ;
5
+ ( 0 , eva ) ( "10" ) ; // error: no side effect left of comma (suspect of missing method name or something)
6
+
7
+ //// [evalAfter0.js]
8
+ ( 0 , eval ) ( "10" ) ; // fine: special case for eval
9
+ ( 0 , eva ) ( "10" ) ; // error: no side effect left of comma (suspect of missing method name or something)
Original file line number Diff line number Diff line change
1
+ ( 0 , eval ) ( "10" ) ; // fine: special case for eval
2
+
3
+ declare var eva ;
4
+ ( 0 , eva ) ( "10" ) ; // error: no side effect left of comma (suspect of missing method name or something)
You can’t perform that action at this time.
0 commit comments