various fixes and test updates

pull/1839/head
Rich Harris 7 years ago
parent 3ec39e6eab
commit d31bd771cf

@ -523,6 +523,7 @@ export default class Component {
// TODO unindent // TODO unindent
this.extract_imports_and_exports(script.content, this.imports, this.module_exports); this.extract_imports_and_exports(script.content, this.imports, this.module_exports);
remove_indentation(this.code, script.content);
this.module_javascript = this.extract_javascript(script); this.module_javascript = this.extract_javascript(script);
} }

@ -65,6 +65,10 @@ export default function ssr(
map: ${css.map ? stringify(css.map.toString()) : 'null'} map: ${css.map ? stringify(css.map.toString()) : 'null'}
};`} };`}
${component.module_javascript}
${component.fully_hoisted.length > 0 && component.fully_hoisted.join('\n\n')}
const ${name} = @create_ssr_component(($$result, $$props, $$bindings, $$slots) => { const ${name} = @create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
${setup} ${setup}

@ -16,18 +16,14 @@ export function remove_indentation(code: MagicString, node: Node) {
} }
}); });
let dirty = false; const str = code.original.slice(node.start, node.end);
const str = code.original let match;
.slice(node.start, node.end) while (match = pattern.exec(str)) {
.replace(pattern, (match, i) => { const index = node.start + match.index;
const index = node.start + i; while (excluded[0] && excluded[0].end < index) excluded.shift();
while (excluded[0] && excluded[0].end < index) excluded.shift(); if (excluded[0] && excluded[0].start < index) continue;
if (excluded[0] && excluded[0].start < index) return match;
dirty = true; code.remove(index, index + indent.length);
return ''; }
});
if (dirty) code.overwrite(node.start, node.end, str);
} }

@ -2,6 +2,8 @@
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,

@ -3,6 +3,8 @@ import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_
import { onMount } from "svelte"; import { onMount } from "svelte";
function create_fragment(component, ctx) { function create_fragment(component, ctx) {
var current;
return { return {
c: noop, c: noop,
m: noop, m: noop,

@ -1,13 +1,9 @@
/* 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";
const SOME_CONSTANT = 42;
function foo(bar) {
console.log(bar);
}
function create_fragment(component, ctx) { function create_fragment(component, ctx) {
var current;
return { return {
c: noop, c: noop,
m: noop, m: noop,
@ -18,10 +14,16 @@ function create_fragment(component, ctx) {
}; };
} }
const SOME_CONSTANT = 42;
function foo(bar) {
console.log(bar);
}
class SvelteComponent extends SvelteComponent_1 { class SvelteComponent extends SvelteComponent_1 {
constructor(options) { constructor(options) {
super(); super();
init(this, options, define, create_fragment, safe_not_equal); init(this, options, noop, create_fragment, safe_not_equal);
} }
get foo() { get foo() {

@ -1,6 +1,6 @@
/* generated by Svelte vX.Y.Z-alpha1 */ /* generated by Svelte vX.Y.Z-alpha1 */
import { create_ssr_component } from "svelte/internal.js"; import { create_ssr_component } from "svelte/internal.js";
import { onMount, onDestroy } from "svelte"; import { onDestroy, onMount } from "svelte";
function preload(input) { function preload(input) {
return output; return output;
@ -23,6 +23,10 @@ const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$s
console.log('onDestroy'); console.log('onDestroy');
}); });
/* HOISTED */
/* HOISTED */
return ``; return ``;
}); });

@ -9,32 +9,38 @@
"end": 61, "end": 61,
"type": "Element", "type": "Element",
"name": "textarea", "name": "textarea",
"attributes": [], "attributes": [
"children": [
{ {
"start": 10, "type": "Attribute",
"end": 40, "name": "value",
"type": "Text", "value": [
"data": "\n\t<p>not actually an element. " {
}, "start": 10,
{ "end": 40,
"start": 40, "type": "Text",
"end": 45, "data": "\n\t<p>not actually an element. "
"type": "MustacheTag", },
"expression": { {
"type": "Identifier", "start": 40,
"start": 41, "end": 45,
"end": 44, "type": "MustacheTag",
"name": "foo" "expression": {
} "type": "Identifier",
}, "start": 41,
{ "end": 44,
"start": 45, "name": "foo"
"end": 50, }
"type": "Text", },
"data": "</p>\n" {
"start": 45,
"end": 50,
"type": "Text",
"data": "</p>\n"
}
]
} }
] ],
"children": []
} }
] ]
}, },

Loading…
Cancel
Save