disallow non-expression directive values

pull/1839/head
Rich Harris 7 years ago
parent 61e2896f33
commit f4bee21793

@ -390,6 +390,15 @@ function readAttribute(parser: Parser, uniqueNames: Set<string>) {
if (type) {
const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
if (value[0]) {
if (value.length > 1 || value[0].type === 'Text') {
parser.error({
code: `invalid-directive-value`,
message: `Directive value must be a JavaScript expression enclosed in curly braces`
}, value[0].start);
}
}
const directive = {
start,
end,

@ -1 +1 @@
<div class:one="true"></div>
<div class:one={true}></div>

@ -0,0 +1,15 @@
[{
"code": "invalid-directive-value",
"message": "Directive value must be a JavaScript expression enclosed in curly braces",
"pos": 15,
"start": {
"line": 1,
"column": 15,
"character": 15
},
"end": {
"line": 1,
"column": 15,
"character": 15
}
}]

@ -8,8 +8,8 @@
},
"end": {
"line": 1,
"column": 52,
"character": 52
"column": 50,
"character": 50
},
"pos": 5
}]

@ -1,3 +1,3 @@
<div on:wheel|passive|preventDefault="handleWheel()">
<div on:wheel|passive|preventDefault={handleWheel}>
oops
</div>

@ -8,8 +8,8 @@
},
"end": {
"line": 1,
"column": 36,
"character": 36
"column": 34,
"character": 34
},
"pos": 8
}]

@ -1 +1 @@
<button on:click|stop|bad="doThat()"></button>
<button on:click|stop|bad={doThat}></button>
Loading…
Cancel
Save