Skip to content

Commit

Permalink
fix: comment value for legacy mode and multi line tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 1, 2022
1 parent f20e52e commit 3728e3e
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/core/TempParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class TempParser {
type: "comment",
pos: data.start,
endPos: data.end,
value: parser.read(data),
value: parser.read(data.value),
});
break;
case EventTypes.Placeholder:
Expand Down Expand Up @@ -174,7 +174,11 @@ export class TempParser {
parser.read({ start: curTagName!.start, end: data.end }),
attributes: (curAttrs || []).map((attr) => ({
default: attr.name?.default,
name: attr.name && parser.read(attr.name),
name: attr.name
? attr.name.default
? "default"
: parser.read(attr.name)
: undefined,
pos: attr.name?.start ?? attr.value?.start,
endPos: attr.value?.end ?? attr.name?.end,
value: attr.value && parser.read(attr.value),
Expand Down Expand Up @@ -240,5 +244,7 @@ export class TempParser {
break;
}
}

this._handlers.onfinish?.();
}
}
3 changes: 2 additions & 1 deletion src/states/TAG_NAME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export const TAG_NAME: StateDefinition<TagNameMeta> = {
},

eol() {
if (this.isConcise) this.exitState(); // TODO: is concise guard needed?
this.activeTag!.shorthandEnd = this.pos;
this.exitState();
},

eof() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>
comment:"/*\n This is a\n multiline comment\n */"
comment:"\n This is a\n multiline comment\n "
error:"In concise mode a javascript comment block can only be followed by whitespace characters and a newline." (code: "INVALID_CHARACTER")
</p>
2 changes: 1 addition & 1 deletion test/autotest/comment-concise-js-block/expected.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>
comment:"/*\n This is a\n multiline comment\n */"
comment:"\n This is a\n multiline comment\n "
text:"This is the body of the p tag"
</p>
2 changes: 1 addition & 1 deletion test/autotest/comment-concise-js-line/expected.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div>
comment:"// This is a single line comment"
comment:" This is a single line comment"
text:"This is the body of the div tag"
</div>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
comment:"<!-- Copyright ${date} -->"
comment:" Copyright ${date} "
2 changes: 1 addition & 1 deletion test/autotest/html-comments/expected.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<a>
comment:"<!--<b></b>-->"
comment:"<b></b>"
</a>
4 changes: 2 additions & 2 deletions test/autotest/mixed-comment/expected.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p class=("foo")>
comment:"<!--\n A multiline HTML comment\n should be okay\n -->"
comment:"\n A multiline HTML comment\n should be okay\n "
</p>
<div class=("bar")>
comment:"<!-- test -->"
comment:" test "
</div>
2 changes: 2 additions & 0 deletions test/autotest/multi-line-attrs/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<custom-tag data-attr-a=(EMPTY) data-attr-b=(EMPTY) data-attr-c=(EMPTY) data-attr-d=(EMPTY) data-attr-e=(EMPTY) preserve-attr-a=(EMPTY) not-preserve-attr-a=(EMPTY) SELF_CLOSED>
</custom-tag>
9 changes: 9 additions & 0 deletions test/autotest/multi-line-attrs/input.htmljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<custom-tag
data-attr-a
data-attr-b
data-attr-c
data-attr-d
data-attr-e
preserve-attr-a
not-preserve-attr-a
/>
6 changes: 3 additions & 3 deletions test/autotest/text-after-semicolon/expected.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<span>
comment:"// Hello World"
comment:" Hello World"
</span>
<span>
comment:"/* Hello World */"
comment:" Hello World "
</span>
<span>
comment:"<!-- Hello World -->"
comment:" Hello World "
</span>
<span>
error:"A semicolon indicates the end of a line. Only comments may follow it." (code: "INVALID_CODE_AFTER_SEMICOLON")
Expand Down

0 comments on commit 3728e3e

Please sign in to comment.