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) { if (type) {
const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); 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 = { const directive = {
start, start,
end, 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": { "end": {
"line": 1, "line": 1,
"column": 52, "column": 50,
"character": 52 "character": 50
}, },
"pos": 5 "pos": 5
}] }]

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

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

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