Skip to content
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
6 changes: 5 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15929,12 +15929,16 @@ namespace ts {
checkAssignmentOperator(rightType);
return getRegularTypeOfObjectLiteral(rightType);
case SyntaxKind.CommaToken:
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left)) {
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) {
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
}
return rightType;
}

function isEvalNode(node: Expression) {
return node.kind === SyntaxKind.Identifier && (node as Identifier).text === "eval";
}

// Return true if there was no error, false if there was an error.
function checkForDisallowedESSymbolOperand(operator: SyntaxKind): boolean {
const offendingSymbolOperand =
Expand Down
10 changes: 10 additions & 0 deletions tests/baselines/reference/evalAfter0.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests/cases/compiler/evalAfter0.ts(4,2): error TS2695: Left side of comma operator is unused and has no side effects.


==== tests/cases/compiler/evalAfter0.ts (1 errors) ====
(0,eval)("10"); // fine: special case for eval

declare var eva;
(0,eva)("10"); // error: no side effect left of comma (suspect of missing method name or something)
~
!!! error TS2695: Left side of comma operator is unused and has no side effects.
9 changes: 9 additions & 0 deletions tests/baselines/reference/evalAfter0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [evalAfter0.ts]
(0,eval)("10"); // fine: special case for eval

declare var eva;
(0,eva)("10"); // error: no side effect left of comma (suspect of missing method name or something)

//// [evalAfter0.js]
(0, eval)("10"); // fine: special case for eval
(0, eva)("10"); // error: no side effect left of comma (suspect of missing method name or something)
4 changes: 4 additions & 0 deletions tests/cases/compiler/evalAfter0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(0,eval)("10"); // fine: special case for eval

declare var eva;
(0,eva)("10"); // error: no side effect left of comma (suspect of missing method name or something)