Skip to content

Improve diagnostics and add code fixes for top-level await - #36173

Merged
Ron Buckton (rbuckton) merged 3 commits into
masterfrom
topLevelAwaitDiagnostics
Jan 18, 2020
Merged

Improve diagnostics and add code fixes for top-level await#36173
Ron Buckton (rbuckton) merged 3 commits into
masterfrom
topLevelAwaitDiagnostics

Conversation

@rbuckton

Copy link
Copy Markdown
Contributor

This improves the diagnostic messages for top-level await and adds several code-fixes to improve the experience.

In addition, this fixes a small bug in our textChanges algorithm to ensure we correctly add new-lines when inserting nodes at the top of a class body/object literal (and elide trailing commas in an object literal when they aren't needed.

Fixes #36036
Fixes #36171

@DanielRosenwasser

Copy link
Copy Markdown
Member

Looks like there's a merge conflict.


TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 14, 2020

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 80b065f. You can monitor the build here. It should now contribute to this PR's status checks.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Jan 14, 2020

Copy link
Copy Markdown
Member

The message improvements look good.

I would suggest always keeping the trailing comma to be honest - but I happen to be especially prone to adding new fields after members that lack a comma.

@rbuckton

Copy link
Copy Markdown
Contributor Author

Daniel Rosenwasser (@DanielRosenwasser): Trailing comma is illegal in JSON, so if we ever have a codefix that affects package.json, it would make that file invalid. I'd rather trim the trailing comma to be safe.

Comment thread src/compiler/core.ts Outdated
@DanielRosenwasser

Copy link
Copy Markdown
Member

Would it be too much trouble to have the codefix check if it's in ES3 or working under JSON?

@DanielRosenwasser

Copy link
Copy Markdown
Member

or have the printer "do the right thing" under either mode?

# Conflicts:
#	src/services/textChanges.ts
# Conflicts:
#	src/compiler/diagnosticMessages.json
@rbuckton

Copy link
Copy Markdown
Contributor Author

I've updated it so that it only elides the trailing comma when the source file is a .json file (since there's no way to tell whether it's a normal .json or a non-standard .json like our tsconfig files).

@rbuckton
Ron Buckton (rbuckton) merged commit 50adabe into master Jan 18, 2020
@rbuckton
Ron Buckton (rbuckton) deleted the topLevelAwaitDiagnostics branch January 18, 2020 20:37
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Implement interface" codefix missing newline after first member Top-level await error message is extremely unclear

4 participants