Repository navigation
Conversation
Changelog🐛 Bug fix
Semantic Diff4 commits · Full page Print a line break after raw code that ends with a line commentb8484a6 · mununki · Nov 22, 2026, 04:48 UTC
JS modified (raw code ending with a line comment) let add = (a, b) => a + b
let f: int => int = %raw(`x => x + 1 // add one`)
let two = add(%raw(`1 // one`), 1)
-let f = (x => x + 1 // add one);
+let f = (x => x + 1 // add one
+);
-let two = 1 // one + 1 | 0;
+let two = 1 // one
+ + 1 | 0;Review
Look for a line comment after the last line feed only8cdb399 · mununki · Nov 22, 2026, 05:00 UTC The scan only spares the parse for code that cannot end in a line comment, and one that runs to the end starts after the last line feed. Codecov found the carriage return case untested, and the parse already ends a line comment there, so code whose last line break is a lone carriage return is now parsed, and the output does not change. Find a line comment at the end of raw code in the parse that classifies itc0f01c5 · mununki · Nov 28, 2026, 13:02 UTC
Tests: Review
✨ Drop the case of raw code without a token from the line comment check53524f8 · mununki · Nov 28, 2026, 13:15 UTC · new Codecov found the case for code without a token untested. Such code, a raw expression that is only a comment, does not parse as an expression, so the check already counts it as ending in a line comment through its parse errors, before it looks at the comments. The case never ran. The output does not change: |
✅ Compiler benchmarksAllocated wordsIn total: 655,712,969 → 655,721,036 (±0.00%). Generated projects: 629,286,110 → 629,286,479 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,224,546,906 → 9,224,108,275 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 26,662,166 → 26,662,491 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 53524f8 compared with base 83cf1de in this run. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9374 +/- ##
==========================================
+ Coverage 82.21% 82.34% +0.13%
==========================================
Files 460 462 +2
Lines 65551 65817 +266
==========================================
+ Hits 53891 54198 +307
+ Misses 11660 11619 -41
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9374 |
Why:
A `%raw` expression is printed on the same line as what follows it, so
a line comment at its end commented that out: the parenthesis that
closes raw code, which gave a syntax error, or the rest of an
expression after a raw literal, which gave another value without an
error. A line break at the end of the code does not help, since
`E.raw_js_code` trims it. `Js_dump` now prints a line break after the
code when `Classify_function.ends_in_line_comment` finds that a line
comment runs to its end: its last line holds "//", and the code
followed by `)` does not parse.
JS modified (raw code ending with a line comment):
Example:
let add = (a, b) => a + b
let f: int => int = %raw(`x => x + 1 // add one`)
let two = add(%raw(`1 // one`), 1)
Before (js):
let f = (x => x + 1 // add one);
let two = 1 // one + 1 | 0;
After (js):
let f = (x => x + 1 // add one
);
let two = 1 // one
+ 1 | 0;
Review: Why parse the code? A "//" on the last line may be in a string,
a template or a regular expression, as in the string literal
`"http://example.com"`, which is printed as before. Only code whose
last line holds "//" is parsed, and code that the Flow parser rejects
gets the line break.
Review: What about `%%raw`? A raw statement is already printed on lines of
its own.
Review: Which checked-in outputs change? None.
Signed-off-by: mununki <woonki.moon@gmail.com>
The scan only spares the parse for code that cannot end in a line comment, and one that runs to the end starts after the last line feed. Codecov found the carriage return case untested, and the parse already ends a line comment there, so code whose last line break is a lone carriage return is now parsed, and the output does not change. Signed-off-by: mununki <woonki.moon@gmail.com>
49656f2 to
8cdb399
Compare
|
This review was written by Claude (Claude Code). The fix looks right to me, and adding the line break only when it's needed is better than always adding one (as One suggestion on how the comment is found. let ends_in_line_comment code =
let open Parser_flow in
let env = Parser_env.init_env None code in
let _ = do_parse env Parse.expression false in
let last_token = Parser_env.last_loc env in
(* Eat EOF so that the comments before it reach [comments]. *)
Parser_env.Eat.token env;
match (Parser_env.comments env, last_token) with
| (loc, {Flow_ast.Comment.kind = Line}) :: _, Some last ->
Loc.pos_cmp loc.start last._end >= 0
| (_, {Flow_ast.Comment.kind = Line}) :: _, None -> true
| _ -> falseBetter still, do this inside I checked this against the vendored parser. Besides your test cases, it also gives the right answer for Optional: a test with |
…es it `Classify_function.ends_in_line_comment` looked for "//" on the last line of a raw expression and then parsed the code once more, in parentheses, as `Js_dump` prints it, taking a parse error for a comment that runs to the end. That was a third parse of the code, after `Ast_raw_validate` and `classify`. The lexer of the Flow parser already records each comment with its kind and location, so `classify_raw` now reads them in the parse that classifies the code: it ends in a line comment when the last comment is a line comment that starts after the last token. `translcore` keeps the result in the new field `ends_in_line_comment` of `Js_raw_info.t`, and `Js_dump` reads it instead of parsing, as the review of #9374 suggested. Tests: `raw_line_comment_test.res` adds a line comment after a block comment, one after a carriage return, which the code of `afterReturn` holds, and a "//" in a block comment. All checked-in outputs, these cases included, are the same with the previous commit. Review: Does the format of `.cmj` files change? Yes: `Js_raw_info.t` is part of the Lambda that a `.cmj` keeps for inlining, as with any other change to Lambda. A `.cmj` has no magic number, and a build makes it again when the compiler changes. Signed-off-by: mununki <woonki.moon@gmail.com>
|
Thanks for the review and the snippet. Done in c0f01c5, as you suggest: The test now also has |
Codecov found the case for code without a token untested. Such code, a raw expression that is only a comment, does not parse as an expression, so the check already counts it as ending in a line comment through its parse errors, before it looks at the comments. The case never ran. The output does not change: `%raw(`// only a comment`)` still gets a line break, after the warning that the code does not parse. Signed-off-by: mununki <woonki.moon@gmail.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes: #9354
A
%rawexpression is printed on the same line as what follows it, so a line comment at its end commented that out. Around raw code, the closing parenthesis was lost, a syntax error:%raw(`x => x + 1 // add one`)compiled to(x => x + 1 // add one). After a raw literal, which is printed without parentheses, the rest of the expression was lost without an error:add(%raw(`1 // one`), 1)compiled to1 // one + 1 | 0and returned1. A line break at the end of the code does not help, sinceE.raw_js_codetrims it.Js_dumpnow prints a line break after raw code that a line comment runs to the end of.Classify_function.classify_rawfinds it in the parse that classifies the code, from the comments that the Flow lexer records: the last one is a line comment that starts after the last token.translcorekeeps the result in the new fieldends_in_line_commentofJs_raw_info.t, whichJs_dumpreads without parsing again.//in a string, a template, a regular expression or a block comment is not a comment, so the string literal"http://example.com"is printed as before. A line comment ends at any line terminator, a carriage return included. Code that the Flow parser rejects gets the line break.%%rawstatements are already printed on lines of their own.Js_raw_info.tis part of the Lambda that a.cmjkeeps for inlining, so the format of.cmjfiles changes, as with other changes to Lambda.Tests:
raw_line_comment_test.reschecks a raw function, a raw literal as an argument, a called raw function, a line comment before the last line, a line comment after a block comment and after a carriage return, and a string, a regular expression and a block comment holding//. Compiled with master, the module fails to load with aSyntaxError, and without the cases that give one, the raw literals as arguments that end in a line comment return1instead of2.Checklist
changes/README.md), or no release notes are needed and a maintainer should applychangelog:skip.CONTRIBUTING.md).git commit -s).