mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
Merge pull request #14324 from mihailik/master
Special-case (0,eval) for side-effect-free 0 left of comma
This commit is contained in:
commit
36eb1ced1d
@ -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 =
|
||||
|
||||
10
tests/baselines/reference/evalAfter0.errors.txt
Normal file
10
tests/baselines/reference/evalAfter0.errors.txt
Normal file
@ -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
tests/baselines/reference/evalAfter0.js
Normal file
9
tests/baselines/reference/evalAfter0.js
Normal file
@ -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
tests/cases/compiler/evalAfter0.ts
Normal file
4
tests/cases/compiler/evalAfter0.ts
Normal file
@ -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)
|
||||
Loading…
x
Reference in New Issue
Block a user