Skip to content

Allow trailing newline to have fake position#18298

Merged
weswigham merged 4 commits into
microsoft:masterfrom
weswigham:pretty-harness
Sep 7, 2017
Merged

Allow trailing newline to have fake position#18298
weswigham merged 4 commits into
microsoft:masterfrom
weswigham:pretty-harness

Conversation

@weswigham

Copy link
Copy Markdown
Member

In #17121, an assertion was added to catch when we calculated a position outside a file's bounds; however the pretty diagnostic printer relies on the fact that for a trailing newline we calculate a position one after the actual bounds of the file as the position for the first (nonexistant) character on that last line. An alternative was to adjust computeLineStarts to not include trailing newlines in the list of things calculated, then also adjust the baseline code to not consider trailing newlines as lines for writing errors on, then updating all the baselines; but that seemed a little less elegant than just allowing the one-character overflow; seeing as the calculated position always works as intended with substring.

Also modifies the test harness a little bit to allow it to baseline pretty-formatted diagnostics. They don't look terribly pretty in the baseline since they have ANSI escapes, but so be it.

Fixes #18216

Comment thread src/compiler/scanner.ts Outdated
if (res === debugText.length) {
return res; // Allow single character overflow for trailing newline
}
Debug.assert(res < debugText.length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just use <= for the same effect? Currently this says: If res is len, return res, else assert that res < len and return res anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; this just made it more explicit and less like an unintentional off-by-one error.

@@ -0,0 +1,12 @@

2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@weswigham weswigham merged commit 6695255 into microsoft:master Sep 7, 2017
@alexeagle

Copy link
Copy Markdown
Contributor

Will there be another 2.5 bugfix release? This one is getting in my way of open-sourcing another part of the bazel typescript rules.

@mhegazy

mhegazy commented Nov 6, 2017

Copy link
Copy Markdown
Contributor

We have no plans for a 2.5 release at the moment. is this a blocking issue for you? can you move to 2.6?

@alexeagle

alexeagle commented Nov 8, 2017 via email

Copy link
Copy Markdown
Contributor

@weswigham weswigham deleted the pretty-harness branch November 8, 2017 22:03
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
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.

4 participants