Better check for right.text, more comments in test

This commit is contained in:
Oleg Mihailik 2017-02-26 23:13:50 +00:00
parent 27675fc96e
commit 6a88cf0edf
2 changed files with 7 additions and 3 deletions

View File

@ -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 =

View File

@ -1,3 +1,3 @@
(0,eval)("10");
(0,eval)("10"); // fine: special case for eval
(0,alert)("10");
(0,alert)("10"); // error: no side effect left of comma (suspect of missing method name or something)