-
Notifications
You must be signed in to change notification settings - Fork 63
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
Chore: upgrade remark-parse to 9.0.0 #171
Conversation
This comment has been minimized.
This comment has been minimized.
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.
@aduh95 thank you for opening this PR. It led me to a fix in v7 of the parser that fixes two long-outstanding bugs! v8 also appears to produce the same results as v7 including the fixes. v9 being a complete rewrite makes me a bit nervous, however, and I commented on two places that might have issues.
@@ -199,7 +199,7 @@ describe("processor", () => { | |||
|
|||
assert.strictEqual(blocks.length, 1); | |||
assert.strictEqual(blocks[0].filename, "0.js"); | |||
assert.strictEqual(blocks[0].text, "\n\n \n \n"); | |||
assert.strictEqual(blocks[0].text, "\n\n\n \n \n"); |
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.
Aha! This reminded me of both #77 and #78. After some digging, it turns out [email protected]
includes remarkjs/remark#423, which fixes both of those issues. I opened #175 with a few additional tests specifically demonstrating those fixes.
@@ -362,7 +362,7 @@ describe("processor", () => { | |||
const blocks = processor.preprocess(code); | |||
|
|||
assert.strictEqual(blocks[0].filename, "0.js"); | |||
assert.strictEqual(blocks[0].text, "var answer = 6 * 7;\nconsole.log(answer);\n"); | |||
assert.strictEqual(blocks[0].text, "var answer = 6 * 7;\r\nconsole.log(answer);\n"); |
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.
This test is... strange. It says it "preserves" the original line endings, yet the assertion normalized them to \n
. However, it was consistent. Here I see there's one \r\n
and another \n
. Any idea why that is? If v9 of the parser now preserves original line endings, I'd expect both to be \r\n
. If this behavior changes, I'll want to add some autofix tests that span lines to make sure we're using correct substitutions. That'd be a likely place to have an off-by-one error that causes syntax errors in the output.
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.
Yep, I agree it's weird. I think the last line of the code block is always normalized to \n
, while the other line endings are preserved. It can be observed by adding another line inside the code block. Looks like an upstream issue.
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.
Oh no, it's actually due to this:
It always adds a blank line and to the node value, and use \n
without checking if it's relevant. I'm not sure why we add a blank line here…
For reference, here's the snippet I used to check the upstream implementation is working as expected:
console.log(
require('mdast-util-from-markdown')([
"```js",
"var answer = 6 * 7;",
"console.log(answer);",
"```"
].join("\r\n")).children[0].value
); // 'var answer = 6 * 7;\r\nconsole.log(answer);'
@@ -286,7 +286,7 @@ function adjustBlock(block) { | |||
|
|||
const out = { | |||
line: lineInCode + blockStart, | |||
column: message.column + block.position.indent[lineInCode - 1] - 1 | |||
column: message.column + block.baseIndentText.length |
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 this change is valid in the case of "negative" indents, i.e. lines of code in a code block that are less indented than the opening fence. The parser previously gave us those on a per-line basis so we could make the correct adjustment. That shows up in the change to the "should translate indented column numbers" test, where one of the messages' columns (4) is now greater than the line length (2).
Can we support Besides, should |
Update on this: I really want to at least get to v7 to fix those two bugs you made me realize were related. I'm waiting for feedback from the rest of the team in the discussion for #175, which demonstrates those exact fixes, about how comfortable we are bumping parser major versions in a semver-minor release of
As long as we're comfortable bumping the dependency to at least v7 in a semver-minor release (hypothetically
That's lower priority than upgrading |
I just merged #175, which includes the two fixes for #77 and #78 that you discovered, so thank you! Some of the changes with the new parser in |
Changelog: https://github.com/remarkjs/remark/releases