From 9dcab952afce98d9ec8030283dcec2d8e815be06 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 15 Sep 2018 15:55:32 -0400 Subject: [PATCH] move some files over --- src/compile/Component.ts | 8 +- src/compile/nodes/Element.ts | 2 +- src/compile/nodes/Window.ts | 2 +- .../validate/js/propValidators/actions.ts | 16 ++ .../validate/js/propValidators/animations.ts | 12 +- .../validate/js/propValidators/components.ts | 22 +-- .../validate/js/propValidators/computed.ts | 37 ++-- .../validate/js/propValidators/data.ts | 8 +- .../validate/js/propValidators/events.ts | 16 ++ .../validate/js/propValidators/helpers.ts | 23 ++- .../validate/js/propValidators/immutable.ts | 8 +- .../validate/js/propValidators/index.ts | 0 .../validate/js/propValidators/methods.ts | 20 +-- .../validate/js/propValidators/namespace.ts | 16 +- .../validate/js/propValidators/oncreate.ts | 8 +- .../validate/js/propValidators/ondestroy.ts | 8 +- .../validate/js/propValidators/onrender.ts | 12 ++ .../validate/js/propValidators/onstate.ts | 8 +- .../validate/js/propValidators/onteardown.ts | 12 ++ .../validate/js/propValidators/onupdate.ts | 8 +- .../validate/js/propValidators/preload.ts | 6 + .../validate/js/propValidators/props.ts | 12 +- .../validate/js/propValidators/setup.ts | 8 +- .../validate/js/propValidators/store.ts | 6 + .../validate/js/propValidators/tag.ts | 12 +- .../validate/js/propValidators/transitions.ts | 12 +- .../validate/js/utils/checkForAccessors.ts | 8 +- .../validate/js/utils/checkForComputedKeys.ts | 8 +- .../validate/js/utils/checkForDupes.ts | 10 +- .../validate/js/utils/usesThisOrArguments.ts | 2 +- src/{ => compile}/validate/utils/FuzzySet.ts | 0 .../validate/utils/fuzzymatch.ts | 0 src/css/Selector.ts | 8 +- src/css/Stylesheet.ts | 14 +- src/validate/index.ts | 170 ------------------ src/validate/js/index.ts | 99 ---------- src/validate/js/propValidators/actions.ts | 16 -- src/validate/js/propValidators/events.ts | 16 -- src/validate/js/propValidators/onrender.ts | 12 -- src/validate/js/propValidators/onteardown.ts | 12 -- src/validate/js/propValidators/preload.ts | 6 - src/validate/js/propValidators/store.ts | 6 - 42 files changed, 209 insertions(+), 480 deletions(-) create mode 100644 src/compile/validate/js/propValidators/actions.ts rename src/{ => compile}/validate/js/propValidators/animations.ts (60%) rename src/{ => compile}/validate/js/propValidators/components.ts (55%) rename src/{ => compile}/validate/js/propValidators/computed.ts (68%) rename src/{ => compile}/validate/js/propValidators/data.ts (60%) create mode 100644 src/compile/validate/js/propValidators/events.ts rename src/{ => compile}/validate/js/propValidators/helpers.ts (68%) rename src/{ => compile}/validate/js/propValidators/immutable.ts (50%) rename src/{ => compile}/validate/js/propValidators/index.ts (100%) rename src/{ => compile}/validate/js/propValidators/methods.ts (67%) rename src/{ => compile}/validate/js/propValidators/namespace.ts (64%) rename src/{ => compile}/validate/js/propValidators/oncreate.ts (63%) rename src/{ => compile}/validate/js/propValidators/ondestroy.ts (63%) create mode 100644 src/compile/validate/js/propValidators/onrender.ts rename src/{ => compile}/validate/js/propValidators/onstate.ts (63%) create mode 100644 src/compile/validate/js/propValidators/onteardown.ts rename src/{ => compile}/validate/js/propValidators/onupdate.ts (63%) create mode 100644 src/compile/validate/js/propValidators/preload.ts rename src/{ => compile}/validate/js/propValidators/props.ts (57%) rename src/{ => compile}/validate/js/propValidators/setup.ts (60%) create mode 100644 src/compile/validate/js/propValidators/store.ts rename src/{ => compile}/validate/js/propValidators/tag.ts (54%) rename src/{ => compile}/validate/js/propValidators/transitions.ts (60%) rename src/{ => compile}/validate/js/utils/checkForAccessors.ts (63%) rename src/{ => compile}/validate/js/utils/checkForComputedKeys.ts (60%) rename src/{ => compile}/validate/js/utils/checkForDupes.ts (60%) rename src/{ => compile}/validate/js/utils/usesThisOrArguments.ts (92%) rename src/{ => compile}/validate/utils/FuzzySet.ts (100%) rename src/{ => compile}/validate/utils/fuzzymatch.ts (100%) delete mode 100644 src/validate/index.ts delete mode 100644 src/validate/js/index.ts delete mode 100644 src/validate/js/propValidators/actions.ts delete mode 100644 src/validate/js/propValidators/events.ts delete mode 100644 src/validate/js/propValidators/onrender.ts delete mode 100644 src/validate/js/propValidators/onteardown.ts delete mode 100644 src/validate/js/propValidators/preload.ts delete mode 100644 src/validate/js/propValidators/store.ts diff --git a/src/compile/Component.ts b/src/compile/Component.ts index c704147cf7..e153fc6b6d 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -22,10 +22,10 @@ import { SsrTarget } from './ssr'; import { Node, GenerateOptions, ShorthandImport, Ast, CompileOptions, CustomElementOptions } from '../interfaces'; import error from '../utils/error'; import getCodeFrame from '../utils/getCodeFrame'; -import checkForComputedKeys from '../validate/js/utils/checkForComputedKeys'; -import checkForDupes from '../validate/js/utils/checkForDupes'; -import propValidators from '../validate/js/propValidators'; -import fuzzymatch from '../validate/utils/fuzzymatch'; +import checkForComputedKeys from './validate/js/utils/checkForComputedKeys'; +import checkForDupes from './validate/js/utils/checkForDupes'; +import propValidators from './validate/js/propValidators'; +import fuzzymatch from './validate/utils/fuzzymatch'; import flattenReference from '../utils/flattenReference'; interface Computation { diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index 23e118fd43..32f0b04e37 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -20,7 +20,7 @@ import Text from './Text'; import * as namespaces from '../../utils/namespaces'; import mapChildren from './shared/mapChildren'; import { dimensions } from '../../utils/patterns'; -import fuzzymatch from '../../validate/utils/fuzzymatch'; +import fuzzymatch from '../validate/utils/fuzzymatch'; import Ref from './Ref'; // source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7 diff --git a/src/compile/nodes/Window.ts b/src/compile/nodes/Window.ts index 05336799a5..fc0f02cdd7 100644 --- a/src/compile/nodes/Window.ts +++ b/src/compile/nodes/Window.ts @@ -4,7 +4,7 @@ import Block from '../dom/Block'; import Binding from './Binding'; import EventHandler from './EventHandler'; import flattenReference from '../../utils/flattenReference'; -import fuzzymatch from '../../validate/utils/fuzzymatch'; +import fuzzymatch from '../validate/utils/fuzzymatch'; import list from '../../utils/list'; const associatedEvents = { diff --git a/src/compile/validate/js/propValidators/actions.ts b/src/compile/validate/js/propValidators/actions.ts new file mode 100644 index 0000000000..ff3dd2a7ac --- /dev/null +++ b/src/compile/validate/js/propValidators/actions.ts @@ -0,0 +1,16 @@ +import checkForDupes from '../utils/checkForDupes'; +import checkForComputedKeys from '../utils/checkForComputedKeys'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; + +export default function actions(component: Component, prop: Node) { + if (prop.value.type !== 'ObjectExpression') { + component.error(prop, { + code: `invalid-actions`, + message: `The 'actions' property must be an object literal` + }); + } + + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); +} diff --git a/src/validate/js/propValidators/animations.ts b/src/compile/validate/js/propValidators/animations.ts similarity index 60% rename from src/validate/js/propValidators/animations.ts rename to src/compile/validate/js/propValidators/animations.ts index a124e192f4..9dea632d9a 100644 --- a/src/validate/js/propValidators/animations.ts +++ b/src/compile/validate/js/propValidators/animations.ts @@ -1,18 +1,18 @@ import checkForDupes from '../utils/checkForDupes'; import checkForComputedKeys from '../utils/checkForComputedKeys'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function transitions(validator: Validator, prop: Node) { +export default function transitions(component: Component, prop: Node) { if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { + component.error(prop, { code: `invalid-transitions-property`, message: `The 'transitions' property must be an object literal` }); } - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); prop.value.properties.forEach(() => { // TODO probably some validation that can happen here... diff --git a/src/validate/js/propValidators/components.ts b/src/compile/validate/js/propValidators/components.ts similarity index 55% rename from src/validate/js/propValidators/components.ts rename to src/compile/validate/js/propValidators/components.ts index 758b84e86f..47b0495d71 100644 --- a/src/validate/js/propValidators/components.ts +++ b/src/compile/validate/js/propValidators/components.ts @@ -1,33 +1,33 @@ import checkForDupes from '../utils/checkForDupes'; import checkForComputedKeys from '../utils/checkForComputedKeys'; -import getName from '../../../utils/getName'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import getName from '../../../../utils/getName'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function components(validator: Validator, prop: Node) { +export default function components(component: Component, prop: Node) { if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { + component.error(prop, { code: `invalid-components-property`, message: `The 'components' property must be an object literal` }); } - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); - prop.value.properties.forEach((component: Node) => { - const name = getName(component.key); + prop.value.properties.forEach((node: Node) => { + const name = getName(node.key); if (name === 'state') { // TODO is this still true? - validator.error(component, { + component.error(node, { code: `invalid-name`, message: `Component constructors cannot be called 'state' due to technical limitations` }); } if (!/^[A-Z]/.test(name)) { - validator.error(component, { + component.error(node, { code: `component-lowercase`, message: `Component names must be capitalised` }); diff --git a/src/validate/js/propValidators/computed.ts b/src/compile/validate/js/propValidators/computed.ts similarity index 68% rename from src/validate/js/propValidators/computed.ts rename to src/compile/validate/js/propValidators/computed.ts index d86f1d2650..ae2422e41a 100644 --- a/src/validate/js/propValidators/computed.ts +++ b/src/compile/validate/js/propValidators/computed.ts @@ -1,50 +1,49 @@ import checkForDupes from '../utils/checkForDupes'; import checkForComputedKeys from '../utils/checkForComputedKeys'; -import getName from '../../../utils/getName'; -import isValidIdentifier from '../../../utils/isValidIdentifier'; -import reservedNames from '../../../utils/reservedNames'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; -import walkThroughTopFunctionScope from '../../../utils/walkThroughTopFunctionScope'; -import isThisGetCallExpression from '../../../utils/isThisGetCallExpression'; -import validCalleeObjects from '../../../utils/validCalleeObjects'; +import getName from '../../../../utils/getName'; +import isValidIdentifier from '../../../../utils/isValidIdentifier'; +import reservedNames from '../../../../utils/reservedNames'; +import { Node } from '../../../../interfaces'; +import walkThroughTopFunctionScope from '../../../../utils/walkThroughTopFunctionScope'; +import isThisGetCallExpression from '../../../../utils/isThisGetCallExpression'; +import Component from '../../../Component'; const isFunctionExpression = new Set([ 'FunctionExpression', 'ArrowFunctionExpression', ]); -export default function computed(validator: Validator, prop: Node) { +export default function computed(component: Component, prop: Node) { if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { + component.error(prop, { code: `invalid-computed-property`, message: `The 'computed' property must be an object literal` }); } - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); prop.value.properties.forEach((computation: Node) => { const name = getName(computation.key); if (!isValidIdentifier(name)) { const suggestion = name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&'); - validator.error(computation.key, { + component.error(computation.key, { code: `invalid-computed-name`, message: `Computed property name '${name}' is invalid — must be a valid identifier such as ${suggestion}` }); } if (reservedNames.has(name)) { - validator.error(computation.key, { + component.error(computation.key, { code: `invalid-computed-name`, message: `Computed property name '${name}' is invalid — cannot be a JavaScript reserved word` }); } if (!isFunctionExpression.has(computation.value.type)) { - validator.error(computation.value, { + component.error(computation.value, { code: `invalid-computed-value`, message: `Computed properties can be function expressions or arrow function expressions` }); @@ -54,14 +53,14 @@ export default function computed(validator: Validator, prop: Node) { walkThroughTopFunctionScope(body, (node: Node) => { if (isThisGetCallExpression(node) && !node.callee.property.computed) { - validator.error(node, { + component.error(node, { code: `impure-computed`, message: `Cannot use this.get(...) — values must be passed into the function as arguments` }); } if (node.type === 'ThisExpression') { - validator.error(node, { + component.error(node, { 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'?` }); @@ -69,14 +68,14 @@ export default function computed(validator: Validator, prop: Node) { }); if (params.length === 0) { - validator.error(computation.value, { + component.error(computation.value, { code: `impure-computed`, message: `A computed value must depend on at least one property` }); } if (params.length > 1) { - validator.error(computation.value, { + component.error(computation.value, { code: `invalid-computed-arguments`, message: `Computed properties must take a single argument` }); diff --git a/src/validate/js/propValidators/data.ts b/src/compile/validate/js/propValidators/data.ts similarity index 60% rename from src/validate/js/propValidators/data.ts rename to src/compile/validate/js/propValidators/data.ts index bf718d1745..e1f1a65cd9 100644 --- a/src/validate/js/propValidators/data.ts +++ b/src/compile/validate/js/propValidators/data.ts @@ -1,13 +1,13 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; const disallowed = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']); -export default function data(validator: Validator, prop: Node) { +export default function data(component: Component, prop: Node) { while (prop.type === 'ParenthesizedExpression') prop = prop.expression; if (disallowed.has(prop.value.type)) { - validator.error(prop.value, { + component.error(prop.value, { code: `invalid-data-property`, message: `'data' must be a function` }); diff --git a/src/compile/validate/js/propValidators/events.ts b/src/compile/validate/js/propValidators/events.ts new file mode 100644 index 0000000000..3fe459eff7 --- /dev/null +++ b/src/compile/validate/js/propValidators/events.ts @@ -0,0 +1,16 @@ +import checkForDupes from '../utils/checkForDupes'; +import checkForComputedKeys from '../utils/checkForComputedKeys'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; + +export default function events(component: Component, prop: Node) { + if (prop.value.type !== 'ObjectExpression') { + component.error(prop, { + code: `invalid-events-property`, + message: `The 'events' property must be an object literal` + }); + } + + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); +} diff --git a/src/validate/js/propValidators/helpers.ts b/src/compile/validate/js/propValidators/helpers.ts similarity index 68% rename from src/validate/js/propValidators/helpers.ts rename to src/compile/validate/js/propValidators/helpers.ts index 0fb14aabb8..01c9167fd9 100644 --- a/src/validate/js/propValidators/helpers.ts +++ b/src/compile/validate/js/propValidators/helpers.ts @@ -1,21 +1,20 @@ import checkForDupes from '../utils/checkForDupes'; import checkForComputedKeys from '../utils/checkForComputedKeys'; -import { walk } from 'estree-walker'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; -import walkThroughTopFunctionScope from '../../../utils/walkThroughTopFunctionScope'; -import isThisGetCallExpression from '../../../utils/isThisGetCallExpression'; +import { Node } from '../../../../interfaces'; +import walkThroughTopFunctionScope from '../../../../utils/walkThroughTopFunctionScope'; +import isThisGetCallExpression from '../../../../utils/isThisGetCallExpression'; +import Component from '../../../Component'; -export default function helpers(validator: Validator, prop: Node) { +export default function helpers(component: Component, prop: Node) { if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { + component.error(prop, { code: `invalid-helpers-property`, message: `The 'helpers' property must be an object literal` }); } - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); prop.value.properties.forEach((prop: Node) => { if (!/FunctionExpression/.test(prop.value.type)) return; @@ -24,14 +23,14 @@ export default function helpers(validator: Validator, prop: Node) { walkThroughTopFunctionScope(prop.value.body, (node: Node) => { if (isThisGetCallExpression(node) && !node.callee.property.computed) { - validator.error(node, { + component.error(node, { code: `impure-helper`, message: `Cannot use this.get(...) — values must be passed into the helper function as arguments` }); } if (node.type === 'ThisExpression') { - validator.error(node, { + component.error(node, { 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'?` }); @@ -41,7 +40,7 @@ export default function helpers(validator: Validator, prop: Node) { }); if (prop.value.params.length === 0 && !usesArguments) { - validator.warn(prop, { + component.warn(prop, { code: `impure-helper`, message: `Helpers should be pure functions, with at least one argument` }); diff --git a/src/validate/js/propValidators/immutable.ts b/src/compile/validate/js/propValidators/immutable.ts similarity index 50% rename from src/validate/js/propValidators/immutable.ts rename to src/compile/validate/js/propValidators/immutable.ts index d445b79b1f..f686ec2950 100644 --- a/src/validate/js/propValidators/immutable.ts +++ b/src/compile/validate/js/propValidators/immutable.ts @@ -1,9 +1,9 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function immutable(validator: Validator, prop: Node) { +export default function immutable(component: Component, prop: Node) { if (prop.value.type !== 'Literal' || typeof prop.value.value !== 'boolean') { - validator.error(prop.value, { + component.error(prop.value, { code: `invalid-immutable-property`, message: `'immutable' must be a boolean literal` }); diff --git a/src/validate/js/propValidators/index.ts b/src/compile/validate/js/propValidators/index.ts similarity index 100% rename from src/validate/js/propValidators/index.ts rename to src/compile/validate/js/propValidators/index.ts diff --git a/src/validate/js/propValidators/methods.ts b/src/compile/validate/js/propValidators/methods.ts similarity index 67% rename from src/validate/js/propValidators/methods.ts rename to src/compile/validate/js/propValidators/methods.ts index cef7095a82..74562ac8c5 100644 --- a/src/validate/js/propValidators/methods.ts +++ b/src/compile/validate/js/propValidators/methods.ts @@ -2,29 +2,29 @@ import checkForAccessors from '../utils/checkForAccessors'; import checkForDupes from '../utils/checkForDupes'; import checkForComputedKeys from '../utils/checkForComputedKeys'; import usesThisOrArguments from '../utils/usesThisOrArguments'; -import getName from '../../../utils/getName'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import getName from '../../../../utils/getName'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; const builtin = new Set(['set', 'get', 'on', 'fire', 'destroy']); -export default function methods(validator: Validator, prop: Node) { +export default function methods(component: Component, prop: Node) { if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { + component.error(prop, { code: `invalid-methods-property`, message: `The 'methods' property must be an object literal` }); } - checkForAccessors(validator, prop.value.properties, 'Methods'); - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); + checkForAccessors(component, prop.value.properties, 'Methods'); + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); prop.value.properties.forEach((prop: Node) => { const name = getName(prop.key); if (builtin.has(name)) { - validator.error(prop, { + component.error(prop, { code: `invalid-method-name`, message: `Cannot overwrite built-in method '${name}'` }); @@ -32,7 +32,7 @@ export default function methods(validator: Validator, prop: Node) { if (prop.value.type === 'ArrowFunctionExpression') { if (usesThisOrArguments(prop.value.body)) { - validator.error(prop, { + component.error(prop, { code: `invalid-method-value`, message: `Method '${prop.key.name}' should be a function expression, not an arrow function expression` }); diff --git a/src/validate/js/propValidators/namespace.ts b/src/compile/validate/js/propValidators/namespace.ts similarity index 64% rename from src/validate/js/propValidators/namespace.ts rename to src/compile/validate/js/propValidators/namespace.ts index 1e0e05b04b..54111204dc 100644 --- a/src/validate/js/propValidators/namespace.ts +++ b/src/compile/validate/js/propValidators/namespace.ts @@ -1,16 +1,16 @@ -import * as namespaces from '../../../utils/namespaces'; -import nodeToString from '../../../utils/nodeToString' +import * as namespaces from '../../../../utils/namespaces'; +import nodeToString from '../../../../utils/nodeToString' import fuzzymatch from '../../utils/fuzzymatch'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; const valid = new Set(namespaces.validNamespaces); -export default function namespace(validator: Validator, prop: Node) { +export default function namespace(component: Component, prop: Node) { const ns = nodeToString(prop.value); if (typeof ns !== 'string') { - validator.error(prop, { + component.error(prop, { code: `invalid-namespace-property`, message: `The 'namespace' property must be a string literal representing a valid namespace` }); @@ -19,12 +19,12 @@ export default function namespace(validator: Validator, prop: Node) { if (!valid.has(ns)) { const match = fuzzymatch(ns, namespaces.validNamespaces); if (match) { - validator.error(prop, { + component.error(prop, { code: `invalid-namespace-property`, message: `Invalid namespace '${ns}' (did you mean '${match}'?)` }); } else { - validator.error(prop, { + component.error(prop, { code: `invalid-namespace-property`, message: `Invalid namespace '${ns}'` }); diff --git a/src/validate/js/propValidators/oncreate.ts b/src/compile/validate/js/propValidators/oncreate.ts similarity index 63% rename from src/validate/js/propValidators/oncreate.ts rename to src/compile/validate/js/propValidators/oncreate.ts index 1dc231ca25..28c0d17f12 100644 --- a/src/validate/js/propValidators/oncreate.ts +++ b/src/compile/validate/js/propValidators/oncreate.ts @@ -1,11 +1,11 @@ import usesThisOrArguments from '../utils/usesThisOrArguments'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function oncreate(validator: Validator, prop: Node) { +export default function oncreate(component: Component, prop: Node) { if (prop.value.type === 'ArrowFunctionExpression') { if (usesThisOrArguments(prop.value.body)) { - validator.error(prop, { + component.error(prop, { code: `invalid-oncreate-property`, message: `'oncreate' should be a function expression, not an arrow function expression` }); diff --git a/src/validate/js/propValidators/ondestroy.ts b/src/compile/validate/js/propValidators/ondestroy.ts similarity index 63% rename from src/validate/js/propValidators/ondestroy.ts rename to src/compile/validate/js/propValidators/ondestroy.ts index 90ccd0dfd1..ab21c68033 100644 --- a/src/validate/js/propValidators/ondestroy.ts +++ b/src/compile/validate/js/propValidators/ondestroy.ts @@ -1,11 +1,11 @@ import usesThisOrArguments from '../utils/usesThisOrArguments'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function ondestroy(validator: Validator, prop: Node) { +export default function ondestroy(component: Component, prop: Node) { if (prop.value.type === 'ArrowFunctionExpression') { if (usesThisOrArguments(prop.value.body)) { - validator.error(prop, { + component.error(prop, { code: `invalid-ondestroy-property`, message: `'ondestroy' should be a function expression, not an arrow function expression` }); diff --git a/src/compile/validate/js/propValidators/onrender.ts b/src/compile/validate/js/propValidators/onrender.ts new file mode 100644 index 0000000000..05526fb576 --- /dev/null +++ b/src/compile/validate/js/propValidators/onrender.ts @@ -0,0 +1,12 @@ +import oncreate from './oncreate'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; + +export default function onrender(component: Component, prop: Node) { + component.warn(prop, { + code: `deprecated-onrender`, + message: `'onrender' has been deprecated in favour of 'oncreate', and will cause an error in Svelte 2.x` + }); + + oncreate(component, prop); +} diff --git a/src/validate/js/propValidators/onstate.ts b/src/compile/validate/js/propValidators/onstate.ts similarity index 63% rename from src/validate/js/propValidators/onstate.ts rename to src/compile/validate/js/propValidators/onstate.ts index c8aa1f5127..1e981de98d 100644 --- a/src/validate/js/propValidators/onstate.ts +++ b/src/compile/validate/js/propValidators/onstate.ts @@ -1,11 +1,11 @@ import usesThisOrArguments from '../utils/usesThisOrArguments'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function onstate(validator: Validator, prop: Node) { +export default function onstate(component: Component, prop: Node) { if (prop.value.type === 'ArrowFunctionExpression') { if (usesThisOrArguments(prop.value.body)) { - validator.error(prop, { + component.error(prop, { code: `invalid-onstate-property`, message: `'onstate' should be a function expression, not an arrow function expression` }); diff --git a/src/compile/validate/js/propValidators/onteardown.ts b/src/compile/validate/js/propValidators/onteardown.ts new file mode 100644 index 0000000000..d4ea666e48 --- /dev/null +++ b/src/compile/validate/js/propValidators/onteardown.ts @@ -0,0 +1,12 @@ +import ondestroy from './ondestroy'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; + +export default function onteardown(component: Component, prop: Node) { + component.warn(prop, { + code: `deprecated-onteardown`, + message: `'onteardown' has been deprecated in favour of 'ondestroy', and will cause an error in Svelte 2.x` + }); + + ondestroy(component, prop); +} diff --git a/src/validate/js/propValidators/onupdate.ts b/src/compile/validate/js/propValidators/onupdate.ts similarity index 63% rename from src/validate/js/propValidators/onupdate.ts rename to src/compile/validate/js/propValidators/onupdate.ts index 5fd649d947..34aa05fcf4 100644 --- a/src/validate/js/propValidators/onupdate.ts +++ b/src/compile/validate/js/propValidators/onupdate.ts @@ -1,11 +1,11 @@ import usesThisOrArguments from '../utils/usesThisOrArguments'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function onupdate(validator: Validator, prop: Node) { +export default function onupdate(component: Component, prop: Node) { if (prop.value.type === 'ArrowFunctionExpression') { if (usesThisOrArguments(prop.value.body)) { - validator.error(prop, { + component.error(prop, { code: `invalid-onupdate-property`, message: `'onupdate' should be a function expression, not an arrow function expression` }); diff --git a/src/compile/validate/js/propValidators/preload.ts b/src/compile/validate/js/propValidators/preload.ts new file mode 100644 index 0000000000..bed262249c --- /dev/null +++ b/src/compile/validate/js/propValidators/preload.ts @@ -0,0 +1,6 @@ +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; + +export default function preload(component: Component, prop: Node) { + // not sure there's anything we need to check here... +} diff --git a/src/validate/js/propValidators/props.ts b/src/compile/validate/js/propValidators/props.ts similarity index 57% rename from src/validate/js/propValidators/props.ts rename to src/compile/validate/js/propValidators/props.ts index 482d44652c..418a491557 100644 --- a/src/validate/js/propValidators/props.ts +++ b/src/compile/validate/js/propValidators/props.ts @@ -1,10 +1,10 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; -import nodeToString from '../../../utils/nodeToString'; +import { Node } from '../../../../interfaces'; +import nodeToString from '../../../../utils/nodeToString'; +import Component from '../../../Component'; -export default function props(validator: Validator, prop: Node) { +export default function props(component: Component, prop: Node) { if (prop.value.type !== 'ArrayExpression') { - validator.error(prop.value, { + component.error(prop.value, { code: `invalid-props-property`, message: `'props' must be an array expression, if specified` }); @@ -12,7 +12,7 @@ export default function props(validator: Validator, prop: Node) { prop.value.elements.forEach((element: Node) => { if (typeof nodeToString(element) !== 'string') { - validator.error(element, { + component.error(element, { code: `invalid-props-property`, message: `'props' must be an array of string literals` }); diff --git a/src/validate/js/propValidators/setup.ts b/src/compile/validate/js/propValidators/setup.ts similarity index 60% rename from src/validate/js/propValidators/setup.ts rename to src/compile/validate/js/propValidators/setup.ts index 023c9ccf38..f983101faf 100644 --- a/src/validate/js/propValidators/setup.ts +++ b/src/compile/validate/js/propValidators/setup.ts @@ -1,13 +1,13 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; const disallowed = new Set(['Literal', 'ObjectExpression', 'ArrayExpression']); -export default function setup(validator: Validator, prop: Node) { +export default function setup(component: Component, prop: Node) { while (prop.type === 'ParenthesizedExpression') prop = prop.expression; if (disallowed.has(prop.value.type)) { - validator.error(prop.value, { + component.error(prop.value, { code: `invalid-setup-property`, message: `'setup' must be a function` }); diff --git a/src/compile/validate/js/propValidators/store.ts b/src/compile/validate/js/propValidators/store.ts new file mode 100644 index 0000000000..85f7a96e9e --- /dev/null +++ b/src/compile/validate/js/propValidators/store.ts @@ -0,0 +1,6 @@ +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; + +export default function store(component: Component, prop: Node) { + // not sure there's anything we need to check here... +} diff --git a/src/validate/js/propValidators/tag.ts b/src/compile/validate/js/propValidators/tag.ts similarity index 54% rename from src/validate/js/propValidators/tag.ts rename to src/compile/validate/js/propValidators/tag.ts index dc9b2438e4..dda1c0d650 100644 --- a/src/validate/js/propValidators/tag.ts +++ b/src/compile/validate/js/propValidators/tag.ts @@ -1,18 +1,18 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; -import nodeToString from '../../../utils/nodeToString'; +import { Node } from '../../../../interfaces'; +import nodeToString from '../../../../utils/nodeToString'; +import Component from '../../../Component'; -export default function tag(validator: Validator, prop: Node) { +export default function tag(component: Component, prop: Node) { const tag = nodeToString(prop.value); if (typeof tag !== 'string') { - validator.error(prop.value, { + component.error(prop.value, { code: `invalid-tag-property`, message: `'tag' must be a string literal` }); } if (!/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) { - validator.error(prop.value, { + component.error(prop.value, { code: `invalid-tag-property`, message: `tag name must be two or more words joined by the '-' character` }); diff --git a/src/validate/js/propValidators/transitions.ts b/src/compile/validate/js/propValidators/transitions.ts similarity index 60% rename from src/validate/js/propValidators/transitions.ts rename to src/compile/validate/js/propValidators/transitions.ts index a124e192f4..9dea632d9a 100644 --- a/src/validate/js/propValidators/transitions.ts +++ b/src/compile/validate/js/propValidators/transitions.ts @@ -1,18 +1,18 @@ import checkForDupes from '../utils/checkForDupes'; import checkForComputedKeys from '../utils/checkForComputedKeys'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; -export default function transitions(validator: Validator, prop: Node) { +export default function transitions(component: Component, prop: Node) { if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { + component.error(prop, { code: `invalid-transitions-property`, message: `The 'transitions' property must be an object literal` }); } - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); + checkForDupes(component, prop.value.properties); + checkForComputedKeys(component, prop.value.properties); prop.value.properties.forEach(() => { // TODO probably some validation that can happen here... diff --git a/src/validate/js/utils/checkForAccessors.ts b/src/compile/validate/js/utils/checkForAccessors.ts similarity index 63% rename from src/validate/js/utils/checkForAccessors.ts rename to src/compile/validate/js/utils/checkForAccessors.ts index 10a88b8f36..6208a33e0c 100644 --- a/src/validate/js/utils/checkForAccessors.ts +++ b/src/compile/validate/js/utils/checkForAccessors.ts @@ -1,14 +1,14 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; export default function checkForAccessors( - validator: Validator, + component: Component, properties: Node[], label: string ) { properties.forEach(prop => { if (prop.kind !== 'init') { - validator.error(prop, { + component.error(prop, { code: `illegal-accessor`, message: `${label} cannot use getters and setters` }); diff --git a/src/validate/js/utils/checkForComputedKeys.ts b/src/compile/validate/js/utils/checkForComputedKeys.ts similarity index 60% rename from src/validate/js/utils/checkForComputedKeys.ts rename to src/compile/validate/js/utils/checkForComputedKeys.ts index 026f1a849d..8ae323b5e6 100644 --- a/src/validate/js/utils/checkForComputedKeys.ts +++ b/src/compile/validate/js/utils/checkForComputedKeys.ts @@ -1,13 +1,13 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; +import Component from '../../../Component'; export default function checkForComputedKeys( - validator: Validator, + component: Component, properties: Node[] ) { properties.forEach(prop => { if (prop.key.computed) { - validator.error(prop, { + component.error(prop, { code: `computed-key`, message: `Cannot use computed keys` }); diff --git a/src/validate/js/utils/checkForDupes.ts b/src/compile/validate/js/utils/checkForDupes.ts similarity index 60% rename from src/validate/js/utils/checkForDupes.ts rename to src/compile/validate/js/utils/checkForDupes.ts index 2629d7d10f..d53e80a5ab 100644 --- a/src/validate/js/utils/checkForDupes.ts +++ b/src/compile/validate/js/utils/checkForDupes.ts @@ -1,9 +1,9 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; -import getName from '../../../utils/getName'; +import { Node } from '../../../../interfaces'; +import getName from '../../../../utils/getName'; +import Component from '../../../Component'; export default function checkForDupes( - validator: Validator, + component: Component, properties: Node[] ) { const seen = new Set(); @@ -12,7 +12,7 @@ export default function checkForDupes( const name = getName(prop.key); if (seen.has(name)) { - validator.error(prop, { + component.error(prop, { code: `duplicate-property`, message: `Duplicate property '${name}'` }); diff --git a/src/validate/js/utils/usesThisOrArguments.ts b/src/compile/validate/js/utils/usesThisOrArguments.ts similarity index 92% rename from src/validate/js/utils/usesThisOrArguments.ts rename to src/compile/validate/js/utils/usesThisOrArguments.ts index b727ed387b..ac8b2225ed 100644 --- a/src/validate/js/utils/usesThisOrArguments.ts +++ b/src/compile/validate/js/utils/usesThisOrArguments.ts @@ -1,6 +1,6 @@ import { walk } from 'estree-walker'; import isReference from 'is-reference'; -import { Node } from '../../../interfaces'; +import { Node } from '../../../../interfaces'; export default function usesThisOrArguments(node: Node) { let result = false; diff --git a/src/validate/utils/FuzzySet.ts b/src/compile/validate/utils/FuzzySet.ts similarity index 100% rename from src/validate/utils/FuzzySet.ts rename to src/compile/validate/utils/FuzzySet.ts diff --git a/src/validate/utils/fuzzymatch.ts b/src/compile/validate/utils/fuzzymatch.ts similarity index 100% rename from src/validate/utils/fuzzymatch.ts rename to src/compile/validate/utils/fuzzymatch.ts diff --git a/src/css/Selector.ts b/src/css/Selector.ts index 6246e55bf3..d6323c6efe 100644 --- a/src/css/Selector.ts +++ b/src/css/Selector.ts @@ -1,8 +1,8 @@ import MagicString from 'magic-string'; import Stylesheet from './Stylesheet'; import { gatherPossibleValues, UNKNOWN } from './gatherPossibleValues'; -import { Validator } from '../validate/index'; import { Node } from '../interfaces'; +import Component from '../compile/Component'; export default class Selector { node: Node; @@ -97,13 +97,13 @@ export default class Selector { }); } - validate(validator: Validator) { + validate(component: Component) { this.blocks.forEach((block) => { let i = block.selectors.length; while (i-- > 1) { const selector = block.selectors[i]; if (selector.type === 'PseudoClassSelector' && selector.name === 'global') { - validator.error(selector, { + component.error(selector, { code: `css-invalid-global`, message: `:global(...) must be the first element in a compound selector` }); @@ -124,7 +124,7 @@ export default class Selector { for (let i = start; i < end; i += 1) { if (this.blocks[i].global) { - validator.error(this.blocks[i].selectors[0], { + component.error(this.blocks[i].selectors[0], { code: `css-invalid-global`, message: `:global(...) can be at the start or end of a selector sequence, but not in the middle` }); diff --git a/src/css/Stylesheet.ts b/src/css/Stylesheet.ts index 32052f50d5..3edb6fd856 100644 --- a/src/css/Stylesheet.ts +++ b/src/css/Stylesheet.ts @@ -6,8 +6,8 @@ import getCodeFrame from '../utils/getCodeFrame'; import hash from '../utils/hash'; import removeCSSPrefix from '../utils/removeCSSPrefix'; import Element from '../compile/nodes/Element'; -import { Validator } from '../validate/index'; import { Node, Ast, Warning } from '../interfaces'; +import Component from '../compile/Component'; const isKeyframesNode = (node: Node) => removeCSSPrefix(node.name) === 'keyframes' @@ -78,9 +78,9 @@ class Rule { this.declarations.forEach(declaration => declaration.transform(code, keyframes)); } - validate(validator: Validator) { + validate(component: Component) { this.selectors.forEach(selector => { - selector.validate(validator); + selector.validate(component); }); } @@ -220,9 +220,9 @@ class Atrule { }) } - validate(validator: Validator) { + validate(component: Component) { this.children.forEach(child => { - child.validate(validator); + child.validate(component); }); } @@ -388,9 +388,9 @@ export default class Stylesheet { }; } - validate(validator: Validator) { + validate(component: Component) { this.children.forEach(child => { - child.validate(validator); + child.validate(component); }); } diff --git a/src/validate/index.ts b/src/validate/index.ts deleted file mode 100644 index 71ae8af7e8..0000000000 --- a/src/validate/index.ts +++ /dev/null @@ -1,170 +0,0 @@ -import validateJs from './js/index'; -import { getLocator, Location } from 'locate-character'; -import getCodeFrame from '../utils/getCodeFrame'; -import Stats from '../Stats'; -import error from '../utils/error'; -import Stylesheet from '../css/Stylesheet'; -import { Node, Ast, CompileOptions, Warning } from '../interfaces'; - -export class Validator { - readonly source: string; - readonly filename: string; - readonly stats: Stats; - - options: CompileOptions; - locator?: (pos: number) => Location; - - namespace: string; - defaultExport: Node; - properties: Map; - components: Map; - methods: Map; - helpers: Map; - animations: Map; - transitions: Map; - actions: Map; - slots: Set; - - used: { - components: Set; - helpers: Set; - events: Set; - animations: Set; - transitions: Set; - actions: Set; - }; - - constructor(ast: Ast, source: string, stats: Stats, options: CompileOptions) { - this.source = source; - this.stats = stats; - - this.filename = options.filename; - this.options = options; - - this.namespace = null; - this.defaultExport = null; - - this.properties = new Map(); - this.components = new Map(); - this.methods = new Map(); - this.helpers = new Map(); - this.animations = new Map(); - this.transitions = new Map(); - this.actions = new Map(); - this.slots = new Set(); - - this.used = { - components: new Set(), - helpers: new Set(), - events: new Set(), - animations: new Set(), - transitions: new Set(), - actions: new Set(), - }; - } - - error(pos: { start: number, end: number }, { code, message } : { code: string, message: string }) { - error(message, { - name: 'ValidationError', - code, - source: this.source, - start: pos.start, - end: pos.end, - filename: this.filename - }); - } - - warn(pos: { start: number, end: number }, { code, message }: { code: string, message: string }) { - if (!this.locator) this.locator = getLocator(this.source, { offsetLine: 1 }); - const start = this.locator(pos.start); - const end = this.locator(pos.end); - - const frame = getCodeFrame(this.source, start.line - 1, start.column); - - this.stats.warn({ - code, - message, - frame, - start, - end, - pos: pos.start, - filename: this.filename, - toString: () => `${message} (${start.line + 1}:${start.column})\n${frame}`, - }); - } -} - -export default function validate( - ast: Ast, - source: string, - stylesheet: Stylesheet, - stats: Stats, - options: CompileOptions -) { - const { onerror, name, filename, dev, parser } = options; - - try { - if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) { - const error = new Error(`options.name must be a valid identifier (got '${name}')`); - throw error; - } - - if (name && /^[a-z]/.test(name)) { - const message = `options.name should be capitalised`; - stats.warn({ - code: `options-lowercase-name`, - message, - filename, - toString: () => message, - }); - } - - const validator = new Validator(ast, source, stats, { - name, - filename, - dev, - parser - }); - - if (ast.js) { - validateJs(validator, ast.js); - } - - if (ast.css) { - stylesheet.validate(validator); - } - - // need to do a second pass of the JS, now that we've analysed the markup - if (ast.js && validator.defaultExport) { - const categories = { - components: 'component', - // TODO helpers require a bit more work — need to analyse all expressions - // helpers: 'helper', - events: 'event definition', - transitions: 'transition', - actions: 'actions', - }; - - Object.keys(categories).forEach(category => { - const definitions = validator.defaultExport.declaration.properties.find(prop => prop.key.name === category); - if (definitions) { - definitions.value.properties.forEach(prop => { - const { name } = prop.key; - if (!validator.used[category].has(name)) { - validator.warn(prop, { - code: `unused-${category.slice(0, -1)}`, - message: `The '${name}' ${categories[category]} is unused` - }); - } - }); - } - }); - } - } catch (err) { - if (onerror) { - onerror(err); - } else { - throw err; - } - } -} diff --git a/src/validate/js/index.ts b/src/validate/js/index.ts deleted file mode 100644 index eb9e40be1f..0000000000 --- a/src/validate/js/index.ts +++ /dev/null @@ -1,99 +0,0 @@ -import propValidators from './propValidators/index'; -import fuzzymatch from '../utils/fuzzymatch'; -import checkForDupes from './utils/checkForDupes'; -import checkForComputedKeys from './utils/checkForComputedKeys'; -import namespaces from '../../utils/namespaces'; -import nodeToString from '../../utils/nodeToString'; -import getName from '../../utils/getName'; -import { Validator } from '../'; -import { Node } from '../../interfaces'; - -const validPropList = Object.keys(propValidators); - -export default function validateJs(validator: Validator, js: Node) { - js.content.body.forEach((node: Node) => { - // check there are no named exports - if (node.type === 'ExportNamedDeclaration') { - validator.error(node, { - code: `named-export`, - message: `A component can only have a default export` - }); - } - - if (node.type === 'ExportDefaultDeclaration') { - if (node.declaration.type !== 'ObjectExpression') { - validator.error(node.declaration, { - code: `invalid-default-export`, - message: `Default export must be an object literal` - }); - } - - checkForComputedKeys(validator, node.declaration.properties); - checkForDupes(validator, node.declaration.properties); - - const props = validator.properties; - - node.declaration.properties.forEach((prop: Node) => { - props.set(getName(prop.key), prop); - }); - - // Remove these checks in version 2 - if (props.has('oncreate') && props.has('onrender')) { - validator.error(props.get('onrender'), { - code: `duplicate-oncreate`, - message: 'Cannot have both oncreate and onrender' - }); - } - - if (props.has('ondestroy') && props.has('onteardown')) { - validator.error(props.get('onteardown'), { - code: `duplicate-ondestroy`, - message: 'Cannot have both ondestroy and onteardown' - }); - } - - // ensure all exported props are valid - node.declaration.properties.forEach((prop: Node) => { - const name = getName(prop.key); - const propValidator = propValidators[name]; - - if (propValidator) { - propValidator(validator, prop); - } else { - const match = fuzzymatch(name, validPropList); - if (match) { - validator.error(prop, { - code: `unexpected-property`, - message: `Unexpected property '${name}' (did you mean '${match}'?)` - }); - } else if (/FunctionExpression/.test(prop.value.type)) { - validator.error(prop, { - code: `unexpected-property`, - message: `Unexpected property '${name}' (did you mean to include it in 'methods'?)` - }); - } else { - validator.error(prop, { - code: `unexpected-property`, - message: `Unexpected property '${name}'` - }); - } - } - }); - - if (props.has('namespace')) { - const ns = nodeToString(props.get('namespace').value); - validator.namespace = namespaces[ns] || ns; - } - - validator.defaultExport = node; - } - }); - - ['components', 'methods', 'helpers', 'transitions', 'animations', 'actions'].forEach(key => { - if (validator.properties.has(key)) { - validator.properties.get(key).value.properties.forEach((prop: Node) => { - validator[key].set(getName(prop.key), prop.value); - }); - } - }); -} diff --git a/src/validate/js/propValidators/actions.ts b/src/validate/js/propValidators/actions.ts deleted file mode 100644 index 063a1b06b1..0000000000 --- a/src/validate/js/propValidators/actions.ts +++ /dev/null @@ -1,16 +0,0 @@ -import checkForDupes from '../utils/checkForDupes'; -import checkForComputedKeys from '../utils/checkForComputedKeys'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; - -export default function actions(validator: Validator, prop: Node) { - if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { - code: `invalid-actions`, - message: `The 'actions' property must be an object literal` - }); - } - - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); -} diff --git a/src/validate/js/propValidators/events.ts b/src/validate/js/propValidators/events.ts deleted file mode 100644 index 52a7790fa2..0000000000 --- a/src/validate/js/propValidators/events.ts +++ /dev/null @@ -1,16 +0,0 @@ -import checkForDupes from '../utils/checkForDupes'; -import checkForComputedKeys from '../utils/checkForComputedKeys'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; - -export default function events(validator: Validator, prop: Node) { - if (prop.value.type !== 'ObjectExpression') { - validator.error(prop, { - code: `invalid-events-property`, - message: `The 'events' property must be an object literal` - }); - } - - checkForDupes(validator, prop.value.properties); - checkForComputedKeys(validator, prop.value.properties); -} diff --git a/src/validate/js/propValidators/onrender.ts b/src/validate/js/propValidators/onrender.ts deleted file mode 100644 index 23b07823c5..0000000000 --- a/src/validate/js/propValidators/onrender.ts +++ /dev/null @@ -1,12 +0,0 @@ -import oncreate from './oncreate'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; - -export default function onrender(validator: Validator, prop: Node) { - validator.warn(prop, { - code: `deprecated-onrender`, - message: `'onrender' has been deprecated in favour of 'oncreate', and will cause an error in Svelte 2.x` - }); - - oncreate(validator, prop); -} diff --git a/src/validate/js/propValidators/onteardown.ts b/src/validate/js/propValidators/onteardown.ts deleted file mode 100644 index fe4e3a67b1..0000000000 --- a/src/validate/js/propValidators/onteardown.ts +++ /dev/null @@ -1,12 +0,0 @@ -import ondestroy from './ondestroy'; -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; - -export default function onteardown(validator: Validator, prop: Node) { - validator.warn(prop, { - code: `deprecated-onteardown`, - message: `'onteardown' has been deprecated in favour of 'ondestroy', and will cause an error in Svelte 2.x` - }); - - ondestroy(validator, prop); -} diff --git a/src/validate/js/propValidators/preload.ts b/src/validate/js/propValidators/preload.ts deleted file mode 100644 index 8b93ce8ec8..0000000000 --- a/src/validate/js/propValidators/preload.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; - -export default function preload(validator: Validator, prop: Node) { - // not sure there's anything we need to check here... -} diff --git a/src/validate/js/propValidators/store.ts b/src/validate/js/propValidators/store.ts deleted file mode 100644 index 48a1de6573..0000000000 --- a/src/validate/js/propValidators/store.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Validator } from '../../index'; -import { Node } from '../../../interfaces'; - -export default function store(validator: Validator, prop: Node) { - // not sure there's anything we need to check here... -}