remove a bunch more validation tests

pull/1866/head
Rich Harris 7 years ago
parent dc787d3e3e
commit 6bb5c79ad7

@ -2,7 +2,7 @@ import * as assert from 'assert';
import * as fs from 'fs';
import { svelte, tryToLoadJson } from '../helpers.js';
describe.only('parse', () => {
describe('parse', () => {
fs.readdirSync('test/parser/samples').forEach(dir => {
if (dir[0] === '.') return;

@ -1,7 +1,7 @@
import * as assert from 'assert';
import { svelte } from '../helpers.js';
describe.only('preprocess', () => {
describe('preprocess', () => {
it('preprocesses entire component', () => {
const source = `
<h1>Hello __NAME__!</h1>

@ -5,7 +5,7 @@ import { loadConfig, svelte } from "../helpers.js";
import { SourceMapConsumer } from "source-map";
import { getLocator } from "locate-character";
describe.only("sourcemaps", () => {
describe("sourcemaps", () => {
fs.readdirSync("test/sourcemaps/samples").forEach(dir => {
if (dir[0] === ".") return;

@ -1,15 +0,0 @@
[{
"code": "impure-computed",
"message": "Computed properties 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": 81,
"start": {
"line": 7,
"column": 4,
"character": 81
},
"end": {
"line": 7,
"column": 8,
"character": 85
}
}]

@ -1,11 +0,0 @@
<button>{foo}</button>
<script>
export default {
computed: {
foo () {
this.set({ foo: true });
}
}
}
</script>

@ -1,15 +0,0 @@
[{
"code": "impure-computed",
"message": "Cannot use this.get(...) — values must be passed into the function as arguments",
"pos": 71,
"start": {
"line": 7,
"column": 11,
"character": 71
},
"end": {
"line": 7,
"column": 28,
"character": 88
}
}]

@ -1,11 +0,0 @@
{foo}
<script>
export default {
computed: {
foo () {
return this.get( 'bar' );
}
}
}
</script>

@ -1,15 +0,0 @@
[{
"code": "parse-error",
"message": "Duplicate export 'default'",
"pos": 37,
"start": {
"line": 3,
"column": 8,
"character": 37
},
"end": {
"line": 3,
"column": 8,
"character": 37
}
}]

@ -1,4 +0,0 @@
<script>
export default {};
export default {};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-default-export",
"message": "Default export must be an object literal",
"pos": 25,
"start": {
"line": 2,
"column": 16,
"character": 25
},
"end": {
"line": 2,
"column": 22,
"character": 31
}
}]

@ -1,3 +0,0 @@
<script>
export default potato;
</script>

@ -1,15 +0,0 @@
[{
"code": "impure-helper",
"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,
"start": {
"line": 7,
"column": 4,
"character": 95
},
"end": {
"line": 7,
"column": 8,
"character": 99
}
}]

@ -1,11 +0,0 @@
<button on:click='foo()'>foo</button>
<script>
export default {
helpers: {
foo () {
this.set({ foo: true });
}
}
}
</script>

@ -1,15 +0,0 @@
[{
"code": "impure-helper",
"message": "Cannot use this.get(...) — values must be passed into the helper function as arguments",
"pos": 72,
"start": {
"line": 7,
"column": 11,
"character": 72
},
"end": {
"line": 7,
"column": 28,
"character": 89
}
}]

@ -1,11 +0,0 @@
{foo()}
<script>
export default {
helpers: {
foo () {
return this.get( 'bar' );
}
}
}
</script>

@ -1,9 +0,0 @@
<script>
function sum() {
var total = '';
for ( var i = 0; i < arguments.length; i += 1 ) total += arguments[i];
return total;
}
</script>
{sum(1, 2, 3)}

@ -1,9 +0,0 @@
<button on:click='foo()'></button>
<script>
export default {
methods: {
foo: () => console.log( 'foo' )
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-method-value",
"message": "Method 'foo' should be a function expression, not an arrow function expression",
"pos": 79,
"start": {
"line": 6,
"column": 3,
"character": 79
},
"end": {
"line": 8,
"column": 4,
"character": 120
}
}]

@ -1,11 +0,0 @@
<button on:click='foo()'></button>
<script>
export default {
methods: {
foo: () => {
this.set({ a: 1 });
}
}
};
</script>

@ -1,11 +0,0 @@
<script>
function bar() {
// ...
}
function foo(x) {
return x;
}
</script>
<button on:click='{foo}'></button>

@ -1,32 +0,0 @@
[
{
"code": "invalid-callee",
"message": "'foo' is an invalid callee (should be one of this.*, refs.*, event.*, options.*, console.*, set, fire, destroy or bar). 'foo' exists on 'helpers', did you put it in the wrong place?",
"pos": 18,
"start": {
"line": 1,
"column": 18,
"character": 18
},
"end": {
"line": 1,
"column": 23,
"character": 23
}
},
{
"code": "unused-helper",
"message": "The 'foo' helper is unused",
"start": {
"line": 12,
"column": 3,
"character": 126
},
"end": {
"line": 14,
"column": 4,
"character": 156
},
"pos": 126
}
]

@ -1,7 +0,0 @@
<script>
function bar() {
// ...
}
</script>
<button on:click='{foo}'></button>

@ -1,15 +0,0 @@
[{
"code": "invalid-callee",
"message": "'foo' is an invalid callee (should be one of this.*, refs.*, event.*, options.*, console.*, set, fire, destroy or bar)",
"pos": 18,
"start": {
"line": 1,
"column": 18,
"character": 18
},
"end": {
"line": 1,
"column": 23,
"character": 23
}
}]

@ -1,10 +0,0 @@
<button on:click='foo()'></button>
<script>
export default {
methods: {
'foo': () => {},
'bar': () => {}
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-components-property",
"message": "The 'components' property must be an object literal",
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 3,
"column": 37,
"character": 64
},
"pos": 29
}]

@ -1,5 +0,0 @@
<script>
export default {
components: 'not an object literal'
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-events-property",
"message": "The 'events' property must be an object literal",
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 3,
"column": 33,
"character": 60
},
"pos": 29
}]

@ -1,5 +0,0 @@
<script>
export default {
events: 'not an object literal'
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-helpers-property",
"message": "The 'helpers' property must be an object literal",
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 3,
"column": 34,
"character": 61
},
"pos": 29
}]

@ -1,5 +0,0 @@
<script>
export default {
helpers: 'not an object literal'
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-methods-property",
"message": "The 'methods' property must be an object literal",
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 3,
"column": 34,
"character": 61
},
"pos": 29
}]

@ -1,5 +0,0 @@
<script>
export default {
methods: 'not an object literal'
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-transitions-property",
"message": "The 'transitions' property must be an object literal",
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 3,
"column": 38,
"character": 65
},
"pos": 29
}]

@ -1,5 +0,0 @@
<script>
export default {
transitions: 'not an object literal'
};
</script>

@ -1,5 +0,0 @@
<script>
import { onMount } from 'svelte';
onMount(() => console.log( 'rendering' ));
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-oncreate-property",
"message": "'oncreate' should be a function expression, not an arrow function expression",
"pos": 29,
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 5,
"column": 3,
"character": 73
}
}]

@ -1,7 +0,0 @@
<script>
export default {
oncreate: () => {
this.set({ a: 1 });
}
};
</script>

@ -1,5 +0,0 @@
<script>
import { onDestroy } from 'svelte';
onDestroy(() => console.log( 'tearing down' ));
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-onDestroy-property",
"message": "'onDestroy' should be a function expression, not an arrow function expression",
"pos": 29,
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 5,
"column": 3,
"character": 74
}
}]

@ -1,7 +0,0 @@
<script>
export default {
onDestroy: () => {
this.set({ a: 1 });
}
};
</script>

@ -1,5 +0,0 @@
<script>
import { beforeUpdate } from 'svelte';
beforeUpdate(() => console.log('updating'));
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-onstate-property",
"message": "'onstate' should be a function expression, not an arrow function expression",
"pos": 29,
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 5,
"column": 3,
"character": 72
}
}]

@ -1,7 +0,0 @@
<script>
export default {
onstate: () => {
this.set({ a: 1 });
}
};
</script>

@ -1,5 +0,0 @@
<script>
import { afterUpdate } from 'svelte';
afterUpdate(() => console.log('updating'));
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-afterUpdate-property",
"message": "'afterUpdate' should be a function expression, not an arrow function expression",
"pos": 29,
"start": {
"line": 3,
"column": 2,
"character": 29
},
"end": {
"line": 5,
"column": 3,
"character": 73
}
}]

@ -1,7 +0,0 @@
<script>
export default {
afterUpdate: () => {
this.set({ a: 1 });
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "component-lowercase",
"message": "Component names must be capitalised",
"start": {
"line": 6,
"column": 3,
"character": 59
},
"end": {
"line": 6,
"column": 6,
"character": 62
},
"pos": 59
}]

@ -1,9 +0,0 @@
<foo></foo>
<script>
export default {
components: {
foo
}
};
</script>

@ -1,16 +0,0 @@
[{
"code": "invalid-computed-name",
"message":
"Computed property name 'new' is invalid — cannot be a JavaScript reserved word",
"start": {
"line": 9,
"column": 3,
"character": 87
},
"end": {
"line": 9,
"column": 6,
"character": 90
},
"pos": 87
}]

@ -1,12 +0,0 @@
<script>
export default {
data() {
return {
a: 1
};
},
computed: {
new: ({ a }) => a * 2
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-computed-property",
"message": "The 'computed' property must be an object literal",
"start": {
"line": 5,
"column": 2,
"character": 42
},
"end": {
"line": 5,
"column": 23,
"character": 63
},
"pos": 42
}]

@ -1,7 +0,0 @@
<div></div>
<script>
export default {
computed: notAnObject
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-computed-value",
"message": "Computed properties can be function expressions or arrow function expressions",
"start": {
"line": 6,
"column": 8,
"character": 62
},
"end": {
"line": 6,
"column": 20,
"character": 74
},
"pos": 62
}]

@ -1,9 +0,0 @@
<div></div>
<script>
export default {
computed: {
foo: notAFunction
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-computed-name",
"message": "Computed property name 'with-hyphen' is invalid — must be a valid identifier such as with_hyphen",
"start": {
"line": 9,
"column": 3,
"character": 87
},
"end": {
"line": 9,
"column": 16,
"character": 100
},
"pos": 87
}]

@ -1,12 +0,0 @@
<script>
export default {
data() {
return {
a: 1
};
},
computed: {
"with-hyphen": ({ a }) => a * 2
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "impure-computed",
"message": "A computed value must depend on at least one property",
"pos": 49,
"start": {
"line": 4,
"column": 8,
"character": 49
},
"end": {
"line": 4,
"column": 16,
"character": 57
}
}]

@ -1,7 +0,0 @@
<script>
export default {
computed: {
foo: () => {}
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-data-property",
"message": "'data' must be a function",
"start": {
"line": 5,
"column": 8,
"character": 48
},
"end": {
"line": 7,
"column": 3,
"character": 64
},
"pos": 48
}]

@ -1,9 +0,0 @@
<div></div>
<script>
export default {
data: {
foo: 42
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "duplicate-property",
"message": "Duplicate property 'methods'",
"start": {
"line": 9,
"column": 2,
"character": 74
},
"end": {
"line": 11,
"column": 3,
"character": 101
},
"pos": 74
}]

@ -1,13 +0,0 @@
<div></div>
<script>
export default {
methods: {
foo () {}
},
methods: {
bar () {}
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "illegal-accessor",
"message": "Methods cannot use getters and setters",
"start": {
"line": 4,
"column": 3,
"character": 43
},
"end": {
"line": 6,
"column": 4,
"character": 61
},
"pos": 43
}]

@ -1,9 +0,0 @@
<script>
export default {
methods: {
get foo () {
}
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-props-property",
"message": "'props' must be an array expression, if specified",
"start": {
"line": 5,
"column": 9,
"character": 49
},
"end": {
"line": 5,
"column": 11,
"character": 51
},
"pos": 49
}]

@ -1,7 +0,0 @@
<div></div>
<script>
export default {
props: {}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "invalid-props-property",
"message": "'props' must be an array of string literals",
"start": {
"line": 5,
"column": 10,
"character": 50
},
"end": {
"line": 5,
"column": 12,
"character": 52
},
"pos": 50
}]

@ -1,7 +0,0 @@
<div></div>
<script>
export default {
props: [{}]
};
</script>

@ -1,15 +0,0 @@
[{
"code": "unexpected-property",
"message": "Unexpected property 'doSomething' (did you mean to include it in 'methods'?)",
"start": {
"line": 5,
"column": 2,
"character": 42
},
"end": {
"line": 7,
"column": 3,
"character": 81
},
"pos": 42
}]

@ -1,9 +0,0 @@
<div></div>
<script>
export default {
doSomething () {
alert( 'boo' );
}
};
</script>

@ -1,15 +0,0 @@
[{
"code": "unexpected-property",
"message": "Unexpected property 'dada' (did you mean 'data'?)",
"start": {
"line": 5,
"column": 2,
"character": 42
},
"end": {
"line": 9,
"column": 3,
"character": 84
},
"pos": 42
}]

@ -1,11 +0,0 @@
<div></div>
<script>
export default {
dada () {
return {
foo: 42
}
}
};
</script>

@ -1 +0,0 @@
<button on:click="{() => store.set({ foo: 'bar' })}">click me</button>

@ -1,15 +0,0 @@
[{
"code": "invalid-callee",
"message": "'store.set' is an invalid callee (did you mean '$set(...)'?)",
"pos": 18,
"start": {
"line": 1,
"column": 18,
"character": 18
},
"end": {
"line": 1,
"column": 43,
"character": 43
}
}]
Loading…
Cancel
Save