fix(bash): keep heredoc continuations highlighted#4415
Conversation
| contains: [ | ||
| ARITHMETIC, | ||
| COMMENT, | ||
| PATH_MODE, | ||
| QUOTE_STRING, | ||
| ESCAPED_QUOTE, | ||
| APOS_STRING, | ||
| ESCAPED_APOS, | ||
| VAR |
There was a problem hiding this comment.
All of this is because of the pipe and piping the string into any sequence of bash, right?
There was a problem hiding this comment.
Not only pipes. The same split is needed for any shell syntax after the delimiter word, for example <<EOF >out or <<EOF && echo queued. The body should start at the following newline; everything before that newline should remain normal Bash.
| const HERE_DOC_BODY = { | ||
| className: 'string', | ||
| begin: /\n/, | ||
| end: /^\t*(\w+)$/m, |
There was a problem hiding this comment.
What is the requirement for heredoc naming in Bash? Could this be tightened up any further than \w+?
There was a problem hiding this comment.
I think this needs broadening rather than tightening. Bash takes a word after << and applies quote removal; it is not limited to \w+.
For example, this branch captures only END here and never finds the real terminator, so echo done stays inside the string:
cat <<END-OF | cat
hello
END-OF
echo done
<<'EOF' is valid too, but is not recognized as a heredoc by this matcher. Could we add both as markup cases before settling on the delimiter match?
There was a problem hiding this comment.
Sure. Add all the cases we know of, then try to get the highlighted correctly - that's the way to do it.
|
Nice rust escaping coverage. Could you include minimal unit case for escaped quotes/backslashes in char literals to aid review traceability? |
Fixes #4377.
Summary
<<-EOF | cat.Tests
EOF | catinside the heredoc string span, socatwas not highlighted as a command.ONLY_LANGUAGES=bash npm run test-markupnpx eslint --no-eslintrc -c .eslintrc.lang.js src/languages/bash.jsnpm run buildgit diff --checkNote: I also ran the full
npm run test-markup; it reached 537 passing tests and then hit the existing 2s Mocha timeout onhttp/default, unrelated to the Bash fixture. The Bash markup suite passed in both focused runs.