Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6299 - Throw a compile error when passing an empty directive name #6300

Merged
merged 4 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
tanhauhau marked this conversation as resolved.
Show resolved Hide resolved
}

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>