Skip to content

Commit

Permalink
Compile error when passing empty directive names
Browse files Browse the repository at this point in the history
  • Loading branch information
qurafi committed May 4, 2021
1 parent 086cff2 commit ac8718b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 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 @@ -378,6 +378,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);
}

if (type === 'Binding' && directive_name !== 'this') {
check_unique(directive_name);
} else if (type !== 'EventHandler' && type !== 'Action') {
Expand All @@ -391,13 +398,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
10 changes: 0 additions & 10 deletions test/parser/samples/error-empty-classname-binding/error.json

This file was deleted.

This file was deleted.

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": 7,
"character": 7
},
"pos": 7
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1 use:>Hello</h1>

0 comments on commit ac8718b

Please sign in to comment.