Skip to content

Commit

Permalink
feat: throw errors when using statement tags if not at concise root
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 1, 2022
1 parent 89bbe69 commit 631da3a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/states/TAG_NAME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,27 @@ export const TAG_NAME: StateDefinition<TagNameMeta> = {
if (tagName.expressions.length === 0) {
if (this.matchAnyAtPos(tagName, ONLY_OPEN_TAGS)) {
tag.openTagOnly = true;
} else if (
tag.concise &&
this.blockStack[0] === tag &&
this.matchAnyAtPos(tagName, EXPRESSION_TAGS)
) {
} else if (this.matchAnyAtPos(tagName, EXPRESSION_TAGS)) {
if (!tag.concise) {
return this.emitError(
tagName,
"RESERVED_TAG_NAME",
`The "${this.read(
tagName
)}" tag is reserved as a statement and cannot be used as an HTML tag.`
);
}

if (this.blockStack[0] !== tag) {
return this.emitError(
tagName,
"ROOT_TAG_ONLY",
`The "${this.read(
tagName
)}" statement can only be used at the root of the template.`
);
}

tag.statement = true;
tag.openTagOnly = true;
this.enterState(STATE.EXPRESSION, { terminatedByEOL: true });
Expand Down
1 change: 1 addition & 0 deletions test/autotest/statement-concise-only/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error:"The \"static\" tag is reserved as a statement and cannot be used as an HTML tag." (code: "RESERVED_TAG_NAME")
1 change: 1 addition & 0 deletions test/autotest/statement-concise-only/input.htmljs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<static const x = 1/>
3 changes: 3 additions & 0 deletions test/autotest/statement-root-only/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
error:"The \"static\" statement can only be used at the root of the template." (code: "ROOT_TAG_ONLY")
</div>
2 changes: 2 additions & 0 deletions test/autotest/statement-root-only/input.htmljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
div
static const x = 1

0 comments on commit 631da3a

Please sign in to comment.