update some js tests

pull/1839/head
Rich Harris 7 years ago
parent 91d2d00eef
commit ec4010672d

@ -6,6 +6,7 @@ import Renderer from './Renderer';
import { CompileOptions } from '../../interfaces'; import { CompileOptions } from '../../interfaces';
import { walk } from 'estree-walker'; import { walk } from 'estree-walker';
import flattenReference from '../../utils/flattenReference'; import flattenReference from '../../utils/flattenReference';
import stringifyProps from '../../utils/stringifyProps';
export default function dom( export default function dom(
component: Component, component: Component,
@ -201,7 +202,7 @@ export default function dom(
${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')} ${component.partly_hoisted.length > 0 && component.partly_hoisted.join('\n\n')}
$$self.$$.get = () => ({ ${component.declarations.join(', ')} }); $$self.$$.get = () => (${stringifyProps(component.declarations)});
${set && `$$self.$$.set = ${set};`} ${set && `$$self.$$.set = ${set};`}

@ -108,7 +108,11 @@ export default class InlineComponentWrapper extends Wrapper {
); );
if (this.node.attributes.length || this.node.bindings.length) { if (this.node.attributes.length || this.node.bindings.length) {
componentInitProperties.push(`props: ${props}`); if (!usesSpread && this.node.bindings.length === 0) {
componentInitProperties.push(`props: ${attributeObject}`);
} else {
componentInitProperties.push(`props: ${props}`);
}
} }
if (component.options.dev) { if (component.options.dev) {

@ -19,6 +19,11 @@ export default function deindent(
expression = expression.length ? expression.join('\n') : null; expression = expression.length ? expression.join('\n') : null;
} }
// discard empty codebuilders
if (expression && expression.isEmpty && expression.isEmpty()) {
expression = null;
}
if (expression || expression === '') { if (expression || expression === '') {
const value = String(expression).replace( const value = String(expression).replace(
/\n/g, /\n/g,

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { loadConfig, svelte } from "../helpers.js"; import { loadConfig, svelte } from "../helpers.js";
describe("js", () => { describe.only("js", () => {
fs.readdirSync("test/js/samples").forEach(dir => { fs.readdirSync("test/js/samples").forEach(dir => {
if (dir[0] === ".") return; if (dir[0] === ".") return;

@ -21,7 +21,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -46,7 +46,7 @@ function create_fragment(component, ctx) {
}; };
} }
function define($$self, $$props, $$make_dirty) { function define($$self, $$props) {
let { foo = 42 } = $$props; let { foo = 42 } = $$props;
$$self.$$.get = () => ({ foo }); $$self.$$.get = () => ({ foo });

@ -24,7 +24,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -24,7 +24,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -24,7 +24,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -2,19 +2,12 @@
import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_equal } from "svelte/internal.js"; import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_equal } from "svelte/internal.js";
function create_fragment(component, ctx) { function create_fragment(component, ctx) {
var current;
return { return {
c: noop, c: noop,
m: noop, m: noop,
p: noop, p: noop,
i: noop, i: noop,
o: run, o: run,
d: noop d: noop
}; };
} }

@ -26,7 +26,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -20,7 +20,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -40,7 +40,6 @@ function create_fragment(component, ctx) {
i: function intro(target, anchor) { i: function intro(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -123,7 +123,6 @@ function create_fragment(component, ctx) {
i: function intro(target, anchor) { i: function intro(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -123,7 +123,6 @@ function create_fragment(component, ctx) {
i: function intro(target, anchor) { i: function intro(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -90,7 +90,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -39,7 +39,6 @@ function create_fragment(component, ctx) {
i: function intro(target, anchor) { i: function intro(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -28,7 +28,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -28,7 +28,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -28,7 +28,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -26,7 +26,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -129,7 +129,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -105,7 +105,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -75,7 +75,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -24,7 +24,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -43,7 +43,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -24,7 +24,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -79,7 +79,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -55,7 +55,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -28,7 +28,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -23,7 +23,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -26,7 +26,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -25,7 +25,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -19,7 +19,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -36,7 +36,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -27,7 +27,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -50,7 +50,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z-alpha1 */ /* generated by Svelte vX.Y.Z-alpha1 */
import { SvelteComponent as SvelteComponent_1, init, noop, run, safe_not_equal } from "svelte/internal.js"; import { SvelteComponent as SvelteComponent_1, init, noop, run, safe_not_equal } from "svelte/internal.js";
export const SOME_CONSTANT = 42; const SOME_CONSTANT = 42;
function foo(bar) { function foo(bar) {
console.log(bar); console.log(bar);
@ -29,4 +29,5 @@ class SvelteComponent extends SvelteComponent_1 {
} }
} }
export default SvelteComponent; export default SvelteComponent;
export { SOME_CONSTANT };

@ -1,4 +1,5 @@
/* generated by Svelte vX.Y.Z-alpha1 */ /* generated by Svelte vX.Y.Z-alpha1 */
import { create_ssr_component } from "svelte/internal.js";
import { onMount, onDestroy } from "svelte"; import { onMount, onDestroy } from "svelte";
function preload(input) { function preload(input) {
@ -13,7 +14,7 @@ function swipe(node, callback) {
// TODO implement // TODO implement
} }
function define($$props) { const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
onMount(() => { onMount(() => {
console.log('onMount'); console.log('onMount');
}); });
@ -22,46 +23,8 @@ function define($$props) {
console.log('onDestroy'); console.log('onDestroy');
}); });
return {};
}
var SvelteComponent = {};
SvelteComponent.render = function(props = {}, options = {}) {
var components = new Set();
function addComponent(component) {
components.add(component);
}
var result = { head: '', addComponent };
var html = SvelteComponent.$$render(result, props, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
return {
html,
head: result.head,
css: { code: cssCode, map: null },
toString() {
return html;
}
};
}
SvelteComponent.$$render = function($$result, props, options) {
const ctx = define(props);
$$result.addComponent(SvelteComponent);
return ``; return ``;
}; });
SvelteComponent.css = {
code: '',
map: null
};
var warned = false;
export default SvelteComponent; export default SvelteComponent;
export { preload }; export { preload };

@ -1,42 +1,10 @@
/* generated by Svelte vX.Y.Z-alpha1 */ /* generated by Svelte vX.Y.Z-alpha1 */
import { create_ssr_component } from "svelte/internal.js";
var SvelteComponent = {}; const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
SvelteComponent.render = function(props = {}, options = {}) {
var components = new Set();
function addComponent(component) {
components.add(component);
}
var result = { head: '', addComponent };
var html = SvelteComponent.$$render(result, props, options);
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n');
return {
html,
head: result.head,
css: { code: cssCode, map: null },
toString() {
return html;
}
};
}
SvelteComponent.$$render = function($$result, ctx, options) {
$$result.addComponent(SvelteComponent);
return `<div>content</div> return `<div>content</div>
<!-- comment --> <!-- comment -->
<div>more content</div>`; <div>more content</div>`;
}; });
SvelteComponent.css = {
code: '',
map: null
};
var warned = false;
export default SvelteComponent; export default SvelteComponent;

@ -22,7 +22,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -223,7 +223,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

@ -38,7 +38,6 @@ function create_fragment(component, ctx) {
i(target, anchor) { i(target, anchor) {
if (current) return; if (current) return;
this.m(target, anchor); this.m(target, anchor);
}, },

Loading…
Cancel
Save