-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Flag middle comma SEF operands #33648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
RyanCavanaugh
wants to merge
3
commits into
microsoft:master
from
RyanCavanaugh:flagMiddleCommaSefOperands
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests/cases/compiler/comma-sef-operand.ts(2,16): error TS2695: Left side of comma operator is unused and has no side effects. | ||
|
||
|
||
==== tests/cases/compiler/comma-sef-operand.ts (1 errors) ==== | ||
declare const obj: any; | ||
console.log(`${JSON.stringify(obj), undefined, 2}`); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2695: Left side of comma operator is unused and has no side effects. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//// [comma-sef-operand.ts] | ||
declare const obj: any; | ||
console.log(`${JSON.stringify(obj), undefined, 2}`); | ||
|
||
|
||
//// [comma-sef-operand.js] | ||
console.log("" + (JSON.stringify(obj), undefined, 2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
=== tests/cases/compiler/comma-sef-operand.ts === | ||
declare const obj: any; | ||
>obj : Symbol(obj, Decl(comma-sef-operand.ts, 0, 13)) | ||
|
||
console.log(`${JSON.stringify(obj), undefined, 2}`); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(comma-sef-operand.ts, 0, 13)) | ||
>undefined : Symbol(undefined) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
=== tests/cases/compiler/comma-sef-operand.ts === | ||
declare const obj: any; | ||
>obj : any | ||
|
||
console.log(`${JSON.stringify(obj), undefined, 2}`); | ||
>console.log(`${JSON.stringify(obj), undefined, 2}`) : void | ||
>console.log : (message?: any, ...optionalParams: any[]) => void | ||
>console : Console | ||
>log : (message?: any, ...optionalParams: any[]) => void | ||
>`${JSON.stringify(obj), undefined, 2}` : string | ||
>JSON.stringify(obj), undefined, 2 : 2 | ||
>JSON.stringify(obj), undefined : undefined | ||
>JSON.stringify(obj) : string | ||
>JSON.stringify : { (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } | ||
>JSON : JSON | ||
>stringify : { (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } | ||
>obj : any | ||
>undefined : undefined | ||
>2 : 2 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
declare const obj: any; | ||
console.log(`${JSON.stringify(obj), undefined, 2}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is less
isSideEffectFree
and morecontainsSideEffectFree
now, right? Since technically the comma operator itself would only actually be side-effect free if everything it executed was free of side effects?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
f() + 4
contains a non-side-effect-free expression, but is side-effect-free due to the addition operator itself not being something that can produce side effects*Upon thinking about this more, I think the correct fix is just to return
true
if the operator in a binary expression isn't an assignment operator. The expression[(f(), 4, 2)]
is equally wrong as[(f() + 4, 2)]
; the comma is a red herring. I'll try this on Monday.* let's continue to pretend
valueOf
doesn't exist, per convention