From 13a33a3499889b4abf3001cf505b08558e303eea Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Fri, 26 May 2023 15:44:19 -0700 Subject: [PATCH] feat: support indented comments outside of a parent tag --- .changeset/warm-olives-warn.md | 5 +++++ .../__snapshots__/bad-tag-indent.expected.txt | 5 ++++- src/__tests__/fixtures/bad-tag-indent/input.marko | 1 + src/states/CONCISE_HTML_CONTENT.ts | 14 ++++++++------ 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 .changeset/warm-olives-warn.md 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) {