mirror of https://github.com/sveltejs/svelte
commit
d4d7f6c53e
@ -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 ) {
|
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 );
|
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,11 @@
|
|||||||
|
{{foo()}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
helpers: {
|
||||||
|
foo () {
|
||||||
|
return Math.random();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,8 @@
|
|||||||
|
[{
|
||||||
|
"message": "Helpers should be pure functions, with at least one argument",
|
||||||
|
"pos": 54,
|
||||||
|
"loc": {
|
||||||
|
"line": 6,
|
||||||
|
"column": 3
|
||||||
|
}
|
||||||
|
}]
|
@ -0,0 +1,8 @@
|
|||||||
|
[{
|
||||||
|
"message": "Helpers should be pure functions — they do not have access to the component instance and cannot use 'this'. Did you mean to put this in 'methods'?",
|
||||||
|
"pos": 95,
|
||||||
|
"loc": {
|
||||||
|
"line": 7,
|
||||||
|
"column": 4
|
||||||
|
}
|
||||||
|
}]
|
@ -0,0 +1,11 @@
|
|||||||
|
<button on:click='foo()'>foo</button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
helpers: {
|
||||||
|
foo () {
|
||||||
|
this.set({ foo: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,8 @@
|
|||||||
|
[{
|
||||||
|
"message": "Cannot use this.get(...) — it must be passed into the helper function as an argument",
|
||||||
|
"pos": 74,
|
||||||
|
"loc": {
|
||||||
|
"line": 7,
|
||||||
|
"column": 11
|
||||||
|
}
|
||||||
|
}]
|
@ -0,0 +1,11 @@
|
|||||||
|
{{foo()}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
helpers: {
|
||||||
|
foo () {
|
||||||
|
return this.get( 'bar' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1,13 @@
|
|||||||
|
{{sum(1, 2, 3)}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
helpers: {
|
||||||
|
sum () {
|
||||||
|
var total = '';
|
||||||
|
for ( var i = 0; i < arguments.length; i += 1 ) total += arguments[i];
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
@ -0,0 +1 @@
|
|||||||
|
[]
|
@ -0,0 +1,8 @@
|
|||||||
|
[{
|
||||||
|
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire or bar). 'foo' exists on 'helpers', did you put it in the wrong place?",
|
||||||
|
"pos": 18,
|
||||||
|
"loc": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 18
|
||||||
|
}
|
||||||
|
}]
|
@ -0,0 +1,17 @@
|
|||||||
|
<button on:click='foo()'></button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
bar () {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
helpers: {
|
||||||
|
foo ( x ) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -0,0 +1,8 @@
|
|||||||
|
[{
|
||||||
|
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire or bar)",
|
||||||
|
"pos": 18,
|
||||||
|
"loc": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 18
|
||||||
|
}
|
||||||
|
}]
|
@ -0,0 +1,11 @@
|
|||||||
|
<button on:click='foo()'></button>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
bar () {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
@ -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