diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 15782e13610..ddb1d371a14 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15929,12 +15929,16 @@ namespace ts { checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); case SyntaxKind.CommaToken: - if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && right.text!=="eval") { + 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 = diff --git a/tests/cases/compiler/evalAfter0.ts b/tests/cases/compiler/evalAfter0.ts index ff9a036faca..98c0ea78f7d 100644 --- a/tests/cases/compiler/evalAfter0.ts +++ b/tests/cases/compiler/evalAfter0.ts @@ -1,3 +1,3 @@ -(0,eval)("10"); +(0,eval)("10"); // fine: special case for eval -(0,alert)("10"); \ No newline at end of file +(0,alert)("10"); // error: no side effect left of comma (suspect of missing method name or something) \ No newline at end of file