From 6a88cf0edf01730cb656cb1e97fad9972c2a4fb2 Mon Sep 17 00:00:00 2001 From: Oleg Mihailik Date: Sun, 26 Feb 2017 23:13:50 +0000 Subject: [PATCH] Better check for right.text, more comments in test --- src/compiler/checker.ts | 6 +++++- tests/cases/compiler/evalAfter0.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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