mirror of https://github.com/sveltejs/svelte
parent
ec543cf9b6
commit
3595470305
@ -1,5 +1,22 @@
|
||||
import * as namespaces from '../../../utils/namespaces.js';
|
||||
import FuzzySet from '../utils/FuzzySet.js';
|
||||
|
||||
const fuzzySet = new FuzzySet( namespaces.validNamespaces );
|
||||
const valid = new Set( namespaces.validNamespaces );
|
||||
|
||||
export default function namespace ( validator, prop ) {
|
||||
if ( prop.value.type !== 'Literal' || typeof prop.value.value !== 'string' ) {
|
||||
const ns = prop.value.value;
|
||||
|
||||
if ( prop.value.type !== 'Literal' || typeof ns !== 'string' ) {
|
||||
validator.error( `The 'namespace' property must be a string literal representing a valid namespace`, prop.start );
|
||||
}
|
||||
|
||||
if ( !valid.has( ns ) ) {
|
||||
const matches = fuzzySet.get( ns );
|
||||
if ( matches && matches[0] && matches[0][0] > 0.7 ) {
|
||||
validator.error( `Invalid namespace '${ns}' (did you mean '${matches[0][1]}'?)`, prop.start );
|
||||
} else {
|
||||
validator.error( `Invalid namespace '${ns}'`, prop.start );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
[{
|
||||
"message": "Invalid namespace 'http://www.w3.org/1999/svg' (did you mean 'http://www.w3.org/2000/svg'?)",
|
||||
"pos": 29,
|
||||
"loc": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
}
|
||||
}]
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export default {
|
||||
namespace: 'http://www.w3.org/1999/svg'
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue