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) {
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) {
body.push(deindent`
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) {
body.push(deindent`
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) {
body.push(deindent`
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 || {}`};
${expected.map(prop => deindent`
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) {
unknown_props_check = deindent`
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}'\`);
});
`;

@ -142,7 +142,7 @@ export default class AwaitBlockWrapper extends Wrapper {
this.catch.block.name && `catch: ${this.catch.block.name}`,
this.then.block.name && `value: '${this.node.value}'`,
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);
block.builders.init.add_block(deindent`
@ -230,4 +230,4 @@ export default class AwaitBlockWrapper extends Wrapper {
branch.fragment.render(branch.block, null, 'nodes');
});
}
}
}

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

@ -52,7 +52,7 @@ export default function(node: InlineComponent, renderer: Renderer, options: Rend
let props;
if (uses_spread) {
props = `Object.assign(${
props = `@Object.assign(${
node.attributes
.map(attribute => {
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 './await-block';
export * from './dom';
export * from './globals';
export * from './keyed-each';
export * from './lifecycle';
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
? () => window.performance.now()

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save