Skip to content

Commit 6a88cf0

Browse files
committed
Better check for right.text, more comments in test
1 parent 27675fc commit 6a88cf0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15929,12 +15929,16 @@ namespace ts {
1592915929
checkAssignmentOperator(rightType);
1593015930
return getRegularTypeOfObjectLiteral(rightType);
1593115931
case SyntaxKind.CommaToken:
15932-
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && right.text!=="eval") {
15932+
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) {
1593315933
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
1593415934
}
1593515935
return rightType;
1593615936
}
1593715937

15938+
function isEvalNode(node: Expression) {
15939+
return node.kind === SyntaxKind.Identifier && (node as Identifier).text === "eval";
15940+
}
15941+
1593815942
// Return true if there was no error, false if there was an error.
1593915943
function checkForDisallowedESSymbolOperand(operator: SyntaxKind): boolean {
1594015944
const offendingSymbolOperand =

tests/cases/compiler/evalAfter0.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(0,eval)("10");
1+
(0,eval)("10"); // fine: special case for eval
22

3-
(0,alert)("10");
3+
(0,alert)("10"); // error: no side effect left of comma (suspect of missing method name or something)

0 commit comments

Comments
 (0)