diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 241a2c05d4..9001d09f68 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -34,6 +34,8 @@ import { apply_preprocessor_sourcemap } from '../utils/mapped_code'; import Element from './nodes/Element'; import { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping/dist/types/types'; import { clone } from '../utils/clone'; +import compiler_warnings from './compiler_warnings'; +import compiler_errors from './compiler_errors'; interface ComponentOptions { namespace?: string; @@ -161,10 +163,7 @@ export default class Component { const svelteOptions = ast.html.children.find( child => child.name === 'svelte:options' ) || { start: 0, end: 0 }; - this.warn(svelteOptions, { - code: 'custom-element-no-tag', - message: 'No custom element \'tag\' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. . To hide this warning, use ' - }); + this.warn(svelteOptions, compiler_warnings.custom_element_no_tag); } this.tag = this.component_options.tag || compile_options.tag; } else { @@ -478,18 +477,12 @@ export default class Component { extract_exports(node) { if (node.type === 'ExportDefaultDeclaration') { - this.error(node, { - code: 'default-export', - message: 'A component cannot have a default export' - }); + this.error(node, compiler_errors.default_export); } if (node.type === 'ExportNamedDeclaration') { if (node.source) { - this.error(node, { - code: 'not-implemented', - message: 'A component currently cannot have an export ... from' - }); + this.error(node, compiler_errors.not_implemented); } if (node.declaration) { if (node.declaration.type === 'VariableDeclaration') { @@ -498,10 +491,7 @@ export default class Component { const variable = this.var_lookup.get(name); variable.export_name = name; if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) { - this.warn(declarator, { - code: 'unused-export-let', - message: `${this.name.name} has unused export property '${name}'. If it is for external reference only, please consider using \`export const ${name}\`` - }); + this.warn(declarator, compiler_warnings.unused_export_let(this.name.name, name)); } }); }); @@ -521,10 +511,7 @@ export default class Component { variable.export_name = specifier.exported.name; if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) { - this.warn(specifier, { - code: 'unused-export-let', - message: `${this.name.name} has unused export property '${specifier.exported.name}'. If it is for external reference only, please consider using \`export const ${specifier.exported.name}\`` - }); + this.warn(specifier, compiler_warnings.unused_export_let(this.name.name, specifier.exported.name)); } } }); @@ -555,10 +542,7 @@ export default class Component { walk(script.content, { enter(node: Node) { if (node.type === 'LabeledStatement' && node.label.name === '$') { - component.warn(node as any, { - code: 'module-script-reactive-declaration', - message: '$: has no effect in a module script' - }); + component.warn(node as any, compiler_warnings.module_script_reactive_declaration); } } }); @@ -568,10 +552,7 @@ export default class Component { scope.declarations.forEach((node, name) => { if (name[0] === '$') { - this.error(node as any, { - code: 'illegal-declaration', - message: 'The $ prefix is reserved, and cannot be used for variable and import names' - }); + this.error(node as any, compiler_errors.illegal_declaration); } const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let'); @@ -586,10 +567,7 @@ export default class Component { globals.forEach((node, name) => { if (name[0] === '$') { - this.error(node as any, { - code: 'illegal-subscription', - message: 'Cannot reference store value inside