Skip to content

Commit

Permalink
#6299 - Throw a compile error when passing an empty directive name (#…
Browse files Browse the repository at this point in the history
…6300)

* Compile error when passing empty directive names

* Revert "Compile error when passing empty directive names"

This reverts commit ac8718b.

* Compile error when passing empty directive names

* Adjust empty-directive-name error offset
  • Loading branch information
qurafi authored Jun 28, 2021
1 parent 2357e64 commit 1b33248
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/compiler/parse/state/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
if (type) {
const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');

if (directive_name === '') {
parser.error({
code: 'empty-directive-name',
message: `${type} name cannot be empty`
}, start + colon_index + 1);
}

if (type === 'Binding' && directive_name !== 'this') {
check_unique(directive_name);
} else if (type !== 'EventHandler' && type !== 'Action') {
Expand All @@ -398,13 +405,6 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
}, start);
}

if (type === 'Class' && directive_name === '') {
parser.error({
code: 'invalid-class-directive',
message: 'Class binding name cannot be empty'
}, start + colon_index + 1);
}

if (value[0]) {
if ((value as any[]).length > 1 || value[0].type === 'Text') {
parser.error({
Expand Down
4 changes: 2 additions & 2 deletions test/parser/samples/error-empty-classname-binding/error.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"code": "invalid-class-directive",
"message": "Class binding name cannot be empty",
"code": "empty-directive-name",
"message": "Class name cannot be empty",
"start": {
"line": 1,
"column": 10,
Expand Down
10 changes: 10 additions & 0 deletions test/parser/samples/error-empty-directive-name/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"code": "empty-directive-name",
"message": "Action name cannot be empty",
"start": {
"line": 1,
"column": 8,
"character": 8
},
"pos": 8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1 use:>Hello</h1>

0 comments on commit 1b33248

Please sign in to comment.