Repository navigation
feat(js): one typo hid every other error, and none came with a frame - #216
Open
jamesconwaydev wants to merge 2 commits into
Open
jamesconwaydev wants to merge 2 commits into
jamesconwaydev wants to merge 2 commits into
Conversation
A syntax error ended the parse, so a file with three mistakes showed one, and the diagnostic was a code and a byte range: nothing pointed at the `(` left open or the first of two declarations, and nothing turned it into lines a person reads. - parsec-base: `Diagnostic::render` prints a code frame: a gutter of line numbers, the lines the error and its labels are on, carets and dashes under them, tabs expanded, wide characters two columns, control and bidi characters replaced, and a long line cut to a window around the marks. - parsec-js: `parse_recovering` skips a statement that fails to the next `;`, to the `}` closing its block, or to a statement keyword on a new line, and reports every error. The first is the one `parse` gives; limits still stop it. `parse` itself only checks a flag per statement. - Labels on the second place an error involves: the bracket still open, and the first of two labels, defaults, constructors, bindings, exports, attributes and private names. - `parsec_js::diagnostics` lists every code with its meaning and the ECMAScript 2025 section, and a test fails if a code is missing. - tests/diagnostics.rs compares the frames for 53 test262 negatives with tests/snapshots/diagnostics.txt, and checks that recovery leaves good programs' trees alone. The parse fuzz target compares `parse` with `parse_recovering`.
Git on Windows checks the snapshot out with CRLF line ends, and the frames are compared with LF ones. Read it with CRLF turned to LF.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #166.
Problem. A syntax error ended the parse. A file with three mistakes showed one, and fixing it showed the next. The error itself was a code and a byte range: for
if (ready {nothing pointed back at the(left open, for a duplicate label nothing pointed at the first, and there was no way to turn it into the lines a person reads. The codes were stable in practice but listed nowhere.Change.
parsec-base:Diagnostic::render(src, &LineIndex, &RenderOptions)prints a code frame. A gutter of line numbers, the lines the error and its labels are on (a line between two is shown, a longer gap is...),^under the error and-under each label, the rightmost label's message inline and the others hanging below. Tabs expand totab_width, East Asian wide characters and most emoji count two columns, combining marks none, and control and bidi characters print as U+FFFD so a frame can't reorder or drive the terminal. A line longer thanmax_width(100), like a bundle's, is cut to a window around the marks with…. No new dependencies.parsec-js:parse_recoveringgoes on after an error. A statement that fails is skipped past the next;, to the}that closes its block, or to a statement keyword at the start of a line, with braces and template substitutions it opened counted, so an error inside an object or a template doesn't stop at its own}. Every error comes back; the first is the oneparsegives.too-deepandstep-budgetstill stop it.this ( is still open(and[,{) on a missing closer, and the first of two labels,defaults, constructors, bindings, exports, import attributes and private names;continue Lpoints at a label that isn't on a loop,"use strict"with complex parameters at the directive, a legacy octal escape at the"use strict"after it, and a line-brokenthrowat thethrow.parsec_js::diagnosticsdocuments every code: what's wrong and the ECMAScript 2025 section, linked. A unit test reads the sources and fails if a code is missing from the table or the table lists one nothing gives.Trade-off. Recovery doesn't count
(and[: one left open by a typo would otherwise hide every statement after it. The cost is a follow-on error now and then, like)after({};).Tests.
test262_code_framesrenders every error for 53 test262 negatives, one or two per kind, and compares them withtests/snapshots/diagnostics.txt. I read each frame;PARSEC_BLESS=1rewrites the file.recovery_reports_each_statement,recovery_resyncs_at_a_statement_keyword_on_a_new_line,recovery_skips_braces_templates_and_regexps_whole,recovery_inside_functions_and_blocks: each fails without recovery, which reports only the first error.recovery_stops_at_limits: a depth or step limit still ends the parse.recovery_changes_nothing_for_good_programs: a sample of 2,000+ test262 files that should parse give the same ESTree, comments and warnings either way.labels_point_back: one case per label.render::testsinparsec-base: carets, paths and warnings, an empty span at the end, labels on other lines and the...gap, hanging labels, tabs, wide and combining characters, control and bidi characters, windowed long lines, multi-line spans, CR, CRLF and U+2028 lines, and spans past the end.parsefuzz target now comparesparsewithparse_recoveringand renders every error: 266,773 runs in 3 minutes, nothing found.Parse speed on the
jsbench, before and after: typescript.js 280 and 279 MB/s, all sources 289 and 287 MB/s, inside the run-to-run noise (oxc moved 363 to 359 in the same runs).Passed locally:
cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all --check,RUSTDOCFLAGS=-D warnings cargo doc,scripts/check-headers.sh.