diff --git a/.changeset/warm-olives-warn.md b/.changeset/warm-olives-warn.md new file mode 100644 index 00000000..ab93e6fe --- /dev/null +++ b/.changeset/warm-olives-warn.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": minor +--- + +Allow indented javascript style comments that are not under a parent tag in concise mode. diff --git a/src/__tests__/fixtures/bad-tag-indent/__snapshots__/bad-tag-indent.expected.txt b/src/__tests__/fixtures/bad-tag-indent/__snapshots__/bad-tag-indent.expected.txt index 40bb2e07..c912be10 100644 --- a/src/__tests__/fixtures/bad-tag-indent/__snapshots__/bad-tag-indent.expected.txt +++ b/src/__tests__/fixtures/bad-tag-indent/__snapshots__/bad-tag-indent.expected.txt @@ -1,2 +1,5 @@ -1╭─ var colors=['red', 'green', 'blue'] +1╭─ // I am indented, and that is OK, but the following is not + │ │ ╰─ comment.value " I am indented, and that is OK, but the following is not" + ╰─ ╰─ comment "// I am indented, and that is OK, but the following is not" +2╭─ var colors=['red', 'green', 'blue'] ╰─ ╰─ error(INVALID_INDENTATION:Line has extra indentation at the beginning) \ No newline at end of file diff --git a/src/__tests__/fixtures/bad-tag-indent/input.marko b/src/__tests__/fixtures/bad-tag-indent/input.marko index f8609de9..7711047b 100644 --- a/src/__tests__/fixtures/bad-tag-indent/input.marko +++ b/src/__tests__/fixtures/bad-tag-indent/input.marko @@ -1 +1,2 @@ + // I am indented, and that is OK, but the following is not var colors=['red', 'green', 'blue'] \ No newline at end of file diff --git a/src/states/CONCISE_HTML_CONTENT.ts b/src/states/CONCISE_HTML_CONTENT.ts index eebfb6f7..18fd0854 100644 --- a/src/states/CONCISE_HTML_CONTENT.ts +++ b/src/states/CONCISE_HTML_CONTENT.ts @@ -39,12 +39,14 @@ export const CONCISE_HTML_CONTENT: StateDefinition = { } if (!parentTag && curIndent) { - this.emitError( - this.pos, - ErrorCode.INVALID_INDENTATION, - "Line has extra indentation at the beginning" - ); - return; + if (code !== CODE.FORWARD_SLASH) { + this.emitError( + this.pos, + ErrorCode.INVALID_INDENTATION, + "Line has extra indentation at the beginning" + ); + return; + } } if (parentTag) {