import globals from helpers (#2612) (#2947)

pull/2963/head
Conduitry 6 years ago
parent 52b5e05ead
commit 2ac5993571

@ -57,7 +57,7 @@ export default function dom(
if (options.dev && !options.hydratable) { if (options.dev && !options.hydratable) {
block.builders.claim.add_line( block.builders.claim.add_line(
'throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");' 'throw new @Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");'
); );
} }
@ -106,7 +106,7 @@ export default function dom(
} else if (component.compile_options.dev) { } else if (component.compile_options.dev) {
body.push(deindent` body.push(deindent`
get ${x.export_name}() { get ${x.export_name}() {
throw new Error("<${component.tag}>: Props cannot be read directly from the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'"); throw new @Error("<${component.tag}>: Props cannot be read directly from the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
} }
`); `);
} }
@ -122,14 +122,14 @@ export default function dom(
} else if (component.compile_options.dev) { } else if (component.compile_options.dev) {
body.push(deindent` body.push(deindent`
set ${x.export_name}(value) { set ${x.export_name}(value) {
throw new Error("<${component.tag}>: Cannot set read-only property '${x.export_name}'"); throw new @Error("<${component.tag}>: Cannot set read-only property '${x.export_name}'");
} }
`); `);
} }
} else if (component.compile_options.dev) { } else if (component.compile_options.dev) {
body.push(deindent` body.push(deindent`
set ${x.export_name}(value) { set ${x.export_name}(value) {
throw new Error("<${component.tag}>: Props cannot be set directly on the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'"); throw new @Error("<${component.tag}>: Props cannot be set directly on the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
} }
`); `);
} }
@ -145,7 +145,7 @@ export default function dom(
const props = ${options.customElement ? `this.attributes` : `options.props || {}`}; const props = ${options.customElement ? `this.attributes` : `options.props || {}`};
${expected.map(prop => deindent` ${expected.map(prop => deindent`
if (ctx.${prop.name} === undefined && !('${prop.export_name}' in props)) { if (ctx.${prop.name} === undefined && !('${prop.export_name}' in props)) {
console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'"); @console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'");
}`)} }`)}
`; `;
} }
@ -402,7 +402,7 @@ export default function dom(
if (component.compile_options.dev && !component.var_lookup.has('$$props') && writable_props.length) { if (component.compile_options.dev && !component.var_lookup.has('$$props') && writable_props.length) {
unknown_props_check = deindent` unknown_props_check = deindent`
const writable_props = [${writable_props.map(prop => `'${prop.export_name}'`).join(', ')}]; const writable_props = [${writable_props.map(prop => `'${prop.export_name}'`).join(', ')}];
Object.keys($$props).forEach(key => { @Object.keys($$props).forEach(key => {
if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`); if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`);
}); });
`; `;

@ -142,7 +142,7 @@ export default class AwaitBlockWrapper extends Wrapper {
this.catch.block.name && `catch: ${this.catch.block.name}`, this.catch.block.name && `catch: ${this.catch.block.name}`,
this.then.block.name && `value: '${this.node.value}'`, this.then.block.name && `value: '${this.node.value}'`,
this.catch.block.name && `error: '${this.node.error}'`, this.catch.block.name && `error: '${this.node.error}'`,
this.pending.block.has_outro_method && `blocks: Array(3)` this.pending.block.has_outro_method && `blocks: [,,,]`
].filter(Boolean); ].filter(Boolean);
block.builders.init.add_block(deindent` block.builders.init.add_block(deindent`

@ -190,7 +190,7 @@ export default class EachBlockWrapper extends Wrapper {
renderer.blocks.push(deindent` renderer.blocks.push(deindent`
function ${this.vars.get_each_context}(ctx, list, i) { function ${this.vars.get_each_context}(ctx, list, i) {
const child_ctx = Object.create(ctx); const child_ctx = @Object.create(ctx);
${this.context_props} ${this.context_props}
return child_ctx; return child_ctx;
} }
@ -296,7 +296,7 @@ export default class EachBlockWrapper extends Wrapper {
const lookup = block.get_unique_name(`${this.var}_lookup`); const lookup = block.get_unique_name(`${this.var}_lookup`);
block.add_variable(iterations, '[]'); block.add_variable(iterations, '[]');
block.add_variable(lookup, `new Map()`); block.add_variable(lookup, `new @Map()`);
if (this.fragment.nodes[0].is_dom_node()) { if (this.fragment.nodes[0].is_dom_node()) {
this.block.first = this.fragment.nodes[0].var; this.block.first = this.fragment.nodes[0].var;

@ -52,7 +52,7 @@ export default function(node: InlineComponent, renderer: Renderer, options: Rend
let props; let props;
if (uses_spread) { if (uses_spread) {
props = `Object.assign(${ props = `@Object.assign(${
node.attributes node.attributes
.map(attribute => { .map(attribute => {
if (attribute.is_spread) { if (attribute.is_spread) {

@ -0,0 +1,5 @@
import { is_client } from './utils';
const { console, Error, Map, Object } = (is_client ? window : global) as { console, Error, Map, Object };
export { console, Error, Map, Object };

@ -1,6 +1,7 @@
export * from './animations'; export * from './animations';
export * from './await-block'; export * from './await-block';
export * from './dom'; export * from './dom';
export * from './globals';
export * from './keyed-each'; export * from './keyed-each';
export * from './lifecycle'; export * from './lifecycle';
export * from './loop'; export * from './loop';

@ -90,7 +90,7 @@ export function once(fn) {
} }
} }
const is_client = typeof window !== 'undefined'; export const is_client = typeof window !== 'undefined';
export let now: () => number = is_client export let now: () => number = is_client
? () => window.performance.now() ? () => window.performance.now()

@ -1,8 +1,11 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Error,
Object,
SvelteComponentDev, SvelteComponentDev,
add_location, add_location,
append, append,
console,
detach, detach,
element, element,
init, init,

@ -1,8 +1,11 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Error,
Object,
SvelteComponentDev, SvelteComponentDev,
add_location, add_location,
append, append,
console,
destroy_each, destroy_each,
detach, detach,
element, element,

@ -1,8 +1,11 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Error,
Object,
SvelteComponentDev, SvelteComponentDev,
add_location, add_location,
append, append,
console,
destroy_each, destroy_each,
detach, detach,
element, element,

@ -1,5 +1,6 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Error,
SvelteComponentDev, SvelteComponentDev,
init, init,
noop, noop,

@ -1,5 +1,6 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Object,
SvelteComponent, SvelteComponent,
append, append,
destroy_each, destroy_each,

@ -1,8 +1,11 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Error,
Object,
SvelteComponentDev, SvelteComponentDev,
add_location, add_location,
append, append,
console,
detach, detach,
element, element,
init, init,

@ -1,5 +1,6 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Object,
SvelteComponent, SvelteComponent,
append, append,
destroy_each, destroy_each,

@ -1,5 +1,6 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Object,
SvelteComponent, SvelteComponent,
append, append,
destroy_each, destroy_each,

@ -1,5 +1,7 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Map,
Object,
SvelteComponent, SvelteComponent,
append, append,
create_animation, create_animation,

@ -1,5 +1,7 @@
/* generated by Svelte vX.Y.Z */ /* generated by Svelte vX.Y.Z */
import { import {
Map,
Object,
SvelteComponent, SvelteComponent,
append, append,
destroy_block, destroy_block,

@ -125,6 +125,7 @@ describe("runtime", () => {
// Put things we need on window for testing // Put things we need on window for testing
window.SvelteComponent = SvelteComponent; window.SvelteComponent = SvelteComponent;
window.Error = global.Error;
const target = window.document.querySelector("main"); const target = window.document.querySelector("main");

Loading…
Cancel
Save