pull/4742/head
pushkine 6 years ago
parent 796c8c6be6
commit ff6144a3a5

@ -88,7 +88,7 @@ export default function dom(component: Component, options: CompileOptions): { js
${
uses_any &&
b`
${!uses_rest && x`let #k;`}
${!uses_rest && `let #k`}
for (#k in $$new_props) if ($$new_props[#k][0] !== '$') $$props[k] = $$new_props[k];
${uses_rest && compute_rest}
${renderer.invalidate(uses_props ? '$$props' : '$$restProps')}
@ -264,7 +264,7 @@ export default function dom(component: Component, options: CompileOptions): { js
const insert =
reassigned || export_name
? b`${`$$subscribe_${name}`}();`
: b`$$self.$$.on_destroy.push(@subscribe(${name}, #value => $$invalidate(${i}, ${value} = #value)));`;
: b`$$self.$$.on_destroy.push(@subscribe(${name}, (#value) => $$invalidate(${i}, ${value} = #value)));`;
if (component.compile_options.dev) {
return b`@validate_store_dev(${name}, '${name}'); ${insert}`;
@ -343,9 +343,9 @@ export default function dom(component: Component, options: CompileOptions): { js
.map(
({ name }) => b`
${component.compile_options.dev && b`@validate_store_dev(${name.slice(1)}, '${name.slice(1)}');`}
$$self.$$.on_destroy.push(@subscribe(${name.slice(1)}, #value => $$invalidate(${
renderer.context_lookup.get(name).index
}, ${name} = #value));
$$self.$$.on_destroy.push(@subscribe(${name.slice(1)}, (#value) => {
$$invalidate(${renderer.context_lookup.get(name).index}, (${name} = #value));
});
`
);
@ -466,7 +466,12 @@ export default function dom(component: Component, options: CompileOptions): { js
${fixed_reactive_declarations}
${uses_props && b`let #k;for (#k in $$props) if ($$props[#k][0] === '$') delete $$props[#k];`}
${
uses_props &&
b`
let #k;
for (#k in $$props) if ($$props[#k][0] === '$') delete $$props[#k];`
}
return ${return_value};
}

@ -725,7 +725,7 @@ export default class ElementWrapper extends Wrapper {
block.add_variable(outro_var, x`@noop`);
let start_outro = b`${outro_var} = @run_transition(${node}, ${transitionFn}, 2, ${params});`;
if (intro.is_local) start_outro = b`if (#local) ${start_outro};`;
if (outro.is_local) start_outro = b`if (#local) ${start_outro};`;
block.chunks.outro.push(start_outro);
block.chunks.destroy.push(b`if (detaching) ${outro_var}();`);

@ -242,7 +242,7 @@ export default class InlineComponentWrapper extends Wrapper {
initial_props.push(value);
change_object =
attr.expression.node.type !== 'ObjectExpression'
? x`(typeof ${value} === 'object' && ${value} !== null ? ${value} : {})`
? b`(typeof ${value} === 'object' && ${value} !== null ? ${value} : {})`
: value;
} else {
const obj = x`{ ${name}: ${attr.get_value(block)} }`;

@ -1,6 +1,6 @@
import { noop } from '../internal/utils';
export const is_browser = typeof window !== 'undefined';
export const is_iframe = /*#__PURE__*/ is_browser && window.self !== window.top;
export const is_iframe = is_browser && window.self !== window.top;
export const is_cors =
is_iframe &&
/*#__PURE__*/ (() => {
@ -17,8 +17,8 @@ declare var global: any;
export const globals = is_browser ? window : typeof globalThis !== 'undefined' ? globalThis : global;
export const resolved_promise = Promise.resolve();
export let now = /*#__PURE__*/ is_browser ? performance.now.bind(performance) : Date.now.bind(Date);
export let raf = /*#__PURE__*/ __TEST__ ? () => {} : is_browser ? requestAnimationFrame : noop;
export let now = is_browser ? () => performance.now() : Date.now.bind(Date);
export let raf = is_browser ? requestAnimationFrame : noop;
export let framerate = 1000 / 60;
/*#__PURE__*/ raf((t1) => {
raf((d) => {
@ -29,5 +29,5 @@ export let framerate = 1000 / 60;
});
/* tests only */
export const test$set_now = (fn) => void (now = fn);
export const test$set_raf = (fn) => void (raf = fn);
export const set_now = (fn) => void (now = fn);
export const set_raf = (fn) => void (raf = fn);

@ -212,7 +212,7 @@ export function select_value(select) {
}
export function select_multiple_value(select) {
return [].map.call(select.querySelectorAll(':checked'), (option) => option.__value);
return [].map.call(select.querySelectorAll(':checked'), (option: any) => option.__value);
}
export function add_resize_listener(node: HTMLElement, fn: () => void) {

@ -107,4 +107,4 @@ export const onEachFrame = (
/** tests only */
export const clear_loops = () =>
void (next_frame.length = running_frame.length = timed_tasks.length = pending_insert_timed.length = n = +(running_timed = pending_inserts = false));
void (next_frame.length = running_frame.length = timed_tasks.length = pending_insert_timed.length = n = i = j = +(running_timed = pending_inserts = false));

@ -47,8 +47,8 @@ export function tryToReadFile(file) {
export function cleanRequireCache() {
Object.keys(require.cache)
.filter(x => x.endsWith('.svelte'))
.forEach(file => delete require.cache[file]);
.filter((x) => x.endsWith('.svelte'))
.forEach((file) => delete require.cache[file]);
}
const virtualConsole = new jsdom.VirtualConsole();
@ -88,23 +88,19 @@ function cleanChildren(node) {
return a.name < b.name ? -1 : 1;
});
attributes.forEach(attr => {
attributes.forEach((attr) => {
node.removeAttribute(attr.name);
});
attributes.forEach(attr => {
attributes.forEach((attr) => {
node.setAttribute(attr.name, attr.value);
});
// recurse
[...node.childNodes].forEach(child => {
[...node.childNodes].forEach((child) => {
if (child.nodeType === 3) {
// text
if (
node.namespaceURI === 'http://www.w3.org/2000/svg' &&
node.tagName !== 'text' &&
node.tagName !== 'tspan'
) {
if (node.namespaceURI === 'http://www.w3.org/2000/svg' && node.tagName !== 'text' && node.tagName !== 'tspan') {
node.removeChild(child);
}
@ -154,11 +150,7 @@ export function setupHtmlEqual() {
const window = env();
assert.htmlEqual = (actual, expected, message) => {
assert.deepEqual(
normalizeHtml(window, actual),
normalizeHtml(window, expected),
message
);
assert.deepEqual(normalizeHtml(window, actual), normalizeHtml(window, expected), message);
};
}
@ -185,27 +177,25 @@ export function addLineNumbers(code) {
i = String(i + 1);
while (i.length < 3) i = ` ${i}`;
return (
colors.gray(` ${i}: `) +
line.replace(/^\t+/, match => match.split('\t').join(' '))
);
return colors.gray(` ${i}: `) + line.replace(/^\t+/, (match) => match.split('\t').join(' '));
})
.join('\n');
}
export function showOutput(cwd, options = {}, compile = svelte.compile) {
glob('**/*.svelte', { cwd }).forEach(file => {
glob('**/*.svelte', { cwd }).forEach((file) => {
if (file[0] === '_') return;
try {
const { js } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
Object.assign(options, {
filename: file
filename: file,
})
);
console.log( // eslint-disable-line no-console
console.log(
// eslint-disable-line no-console
`\n>> ${colors.cyan().bold(file)}\n${addLineNumbers(js.code)}\n<< ${colors.cyan().bold(file)}`
);
} catch (err) {
@ -236,13 +226,13 @@ export function useFakeTimers() {
return {
flush() {
callbacks.forEach(fn => fn());
callbacks.forEach((fn) => fn());
callbacks.splice(0, callbacks.length);
},
removeFakeTimers() {
callbacks.splice(0, callbacks.length);
global.setTimeout = original_set_timeout;
}
},
};
}

@ -4,7 +4,8 @@ import * as fs from 'fs';
import { rollup } from 'rollup';
import * as virtual from '@rollup/plugin-virtual';
import * as glob from 'tiny-glob/sync.js';
import { clear_loops, flush, set_now, set_raf } from '../../internal';
import { clear_loops, flush } from '../../internal';
import { set_now, set_raf } from '../../environment';
import { showOutput, loadConfig, loadSvelte, cleanRequireCache, env, setupHtmlEqual, mkdirp } from '../helpers.js';

Loading…
Cancel
Save