mirror of https://github.com/sveltejs/svelte
parent
98079fb782
commit
9dcab952af
@ -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);
|
||||
}
|
@ -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...
|
@ -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`
|
||||
});
|
@ -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`
|
||||
});
|
@ -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);
|
||||
}
|
@ -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`
|
||||
});
|
@ -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`
|
||||
});
|
@ -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`
|
||||
});
|
@ -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);
|
||||
}
|
@ -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`
|
||||
});
|
@ -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);
|
||||
}
|
@ -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`
|
||||
});
|
@ -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...
|
||||
}
|
@ -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`
|
||||
});
|
@ -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...
|
||||
}
|
@ -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`
|
||||
});
|
@ -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...
|
@ -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`
|
||||
});
|
@ -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`
|
||||
});
|
@ -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;
|
@ -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<string, Node>;
|
||||
components: Map<string, Node>;
|
||||
methods: Map<string, Node>;
|
||||
helpers: Map<string, Node>;
|
||||
animations: Map<string, Node>;
|
||||
transitions: Map<string, Node>;
|
||||
actions: Map<string, Node>;
|
||||
slots: Set<string>;
|
||||
|
||||
used: {
|
||||
components: Set<string>;
|
||||
helpers: Set<string>;
|
||||
events: Set<string>;
|
||||
animations: Set<string>;
|
||||
transitions: Set<string>;
|
||||
actions: Set<string>;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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...
|
||||
}
|
@ -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...
|
||||
}
|
Loading…
Reference in new issue