add validation logic, error on dimension bindings for SVG elements

pull/1386/head
Rich Harris 7 years ago
parent 1bacad1087
commit fe4637305b

@ -158,7 +158,19 @@ export default function validateElement(
message: `'${name}' binding can only be used with <audio> or <video>`
});
}
} else if (!dimensions.test(name)) {
} else if (dimensions.test(name)) {
if (node.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) {
validator.error(attribute, {
code: 'invalid-binding',
message: `'${attribute.name}' is not a valid binding on <svg>. Use '${name.replace('offset', 'client')}' instead`
});
} else if (svg.test(node.name)) {
validator.error(attribute, {
code: 'invalid-binding',
message: `'${attribute.name}' is not a valid binding on SVG elements`
});
}
} else {
validator.error(attribute, {
code: `invalid-binding`,
message: `'${attribute.name}' is not a valid binding`

@ -0,0 +1,15 @@
[{
"code": "invalid-binding",
"message": "'offsetWidth' is not a valid binding on SVG elements",
"pos": 13,
"start": {
"line": 2,
"column": 7,
"character": 13
},
"end": {
"line": 2,
"column": 23,
"character": 29
}
}]

@ -0,0 +1,3 @@
<svg>
<text bind:offsetWidth>some text</text>
</svg>

After

Width:  |  Height:  |  Size: 53 B

@ -0,0 +1,15 @@
[{
"code": "invalid-binding",
"message": "'offsetWidth' is not a valid binding on <svg>. Use 'clientWidth' instead",
"pos": 5,
"start": {
"line": 1,
"column": 5,
"character": 5
},
"end": {
"line": 1,
"column": 21,
"character": 21
}
}]

@ -0,0 +1 @@
<svg bind:offsetWidth></svg>

After

Width:  |  Height:  |  Size: 28 B

Loading…
Cancel
Save