Added more specific tests

Temp

temp
pull/6585/head
rster20002 5 years ago
parent 967e14e0ad
commit 648c62790d

@ -393,16 +393,34 @@ export default class Block {
const block = dev && this.get_unique_name('block'); const block = dev && this.get_unique_name('block');
const init_statements = Array.from(this.variables.values()).filter(({ init }) => init !== undefined).map(({ id, init }) => { const init_declarations = [];
return b`${id} = ${init}`; const init_statements = [];
Array.from(this.variables.values()).forEach(({ id, init }) => {
init_declarations.push(b`let ${id};`);
if (init) {
init_statements.push(b`${id} = ${init}`);
}
});
console.log("H");
this.chunks.init.forEach(node => {
if (Array.isArray(node) && node[0].type === "VariableDeclaration") {
node[0].declarations.forEach(({ id, init }) => {
console.log(id);
init_declarations.push(b`let ${id};`);
init_statements.push(b`${id} = ${init}`);
});
} else {
init_declarations.push(node);
}
}); });
const body = b` const body = b`
${this.chunks.declarations} ${this.chunks.declarations}
${Array.from(this.variables.values()).map(({ id }) => { ${init_declarations}
return b`let ${id}`;
})}
${init_statements.length > 0 ${init_statements.length > 0
? b` ? b`
@ -414,8 +432,6 @@ export default class Block {
: '' : ''
} }
${this.chunks.init}
${dev ${dev
? b` ? b`
const ${block} = ${return_value}; const ${block} = ${return_value};

@ -454,35 +454,41 @@ export default function dom(
let instance_javascript_with_ctx = []; let instance_javascript_with_ctx = [];
let initializedIdentifiers = []; let initializedIdentifiers = [];
instance_javascript.forEach(node => {
instance_javascript_with_ctx.push(node); if (instance_javascript === null) {
instance_javascript_with_ctx = instance_javascript;
if (Array.isArray(node) && node[0].type === "VariableDeclaration" ) { } else {
walk(node[0], { instance_javascript.forEach(node => {
enter(declaration: Identifier) { instance_javascript_with_ctx.push(node);
if (declaration.type === 'Identifier' && !initializedIdentifiers.includes(declaration.name)) {
let index = renderer.initial_context.findIndex(member => member.name === declaration.name); if (Array.isArray(node) && node[0].type === "VariableDeclaration" ) {
walk(node[0], {
if (index >= 0) { enter(declaration: Identifier) {
node.push(x`#return_values[${index}] = ${declaration}`); if (declaration.type === 'Identifier' && !initializedIdentifiers.includes(declaration.name)) {
initializedIdentifiers.push(declaration.name); let index = renderer.initial_context.findIndex(member => member.name === declaration.name);
if (index >= 0) {
node.push(x`#return_values[${index}] = ${declaration}`);
initializedIdentifiers.push(declaration.name);
}
} }
} }
} });
}); }
}
if (node.type === "FunctionDeclaration") {
if (node.type === "FunctionDeclaration") { if (!initializedIdentifiers.includes(node.id.name)) {
if (!initializedIdentifiers.includes(node.id.name)) { let index = renderer.initial_context.findIndex(member => member.name === node.id.name);
let index = renderer.initial_context.findIndex(member => member.name === node.id.name);
if (index >= 0) {
if (index >= 0) { instance_javascript_with_ctx.push(x`#return_values[${index}] = ${node.id.name}`);
instance_javascript_with_ctx.push(x`#return_values[${index}] = ${node.id.name}`); initializedIdentifiers.push(node.id.name);
initializedIdentifiers.push(node.id.name); }
} }
} }
} });
}); }
const instance_try_block: any = b` const instance_try_block: any = b`
try { try {

@ -182,11 +182,13 @@ export default function ssr(
return $$rendered; return $$rendered;
` `
: b` : b`
${reactive_declarations} try {
${instance_javascript}
${reactive_store_unsubscriptions} ${reactive_declarations}
${reactive_store_unsubscriptions}
try {
return ${literal}; return ${literal};
} catch (e) { } catch (e) {
@handle_error(@get_current_component(), e); @handle_error(@get_current_component(), e);
@ -198,13 +200,13 @@ export default function ssr(
slots, slots,
...reactive_store_declarations, ...reactive_store_declarations,
...reactive_store_subscriptions, ...reactive_store_subscriptions,
b` // b`
try { // try {
${instance_javascript} // ${instance_javascript}
} catch (e) { // } catch (e) {
@handle_error(@get_current_component(), e); // @handle_error(@get_current_component(), e);
} // }
`, // `,
...parent_bindings, ...parent_bindings,
css.code && b`$$result.css.add(#css);`, css.code && b`$$result.css.add(#css);`,
main main

@ -0,0 +1,5 @@
export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}

@ -0,0 +1,4 @@
<script>
var a = {};
console.log(a.b.c);
</script>

@ -0,0 +1,12 @@
<script>
import Child from "./child.svelte";
import { onError } from "svelte";
export var error = false;
onError(e => {
error = true;
});
</script>
<svelte:component this={Child} />

@ -0,0 +1,5 @@
export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}

@ -0,0 +1,20 @@
<script>
import { onError } from "svelte";
var a = [1, 2, 3];
export var error = false;
onError(e => {
error = true;
});
function handleClick() {
a = 10;
}
</script>
{#each a as item}
{item}
{/each}
<button on:click={handleClick}></button>

@ -0,0 +1,10 @@
export default {
async test({ assert, component, target, window }) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
await button.dispatchEvent(event);
assert.equal(component.error, true);
}
}

@ -0,0 +1,14 @@
<script>
import { onError } from "svelte";
var a = {}
export var error = false;
onError(e => {
error = true;
});
</script>
{#each a.b.c as item}
{item}
{/each}

@ -0,0 +1,5 @@
export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}

@ -0,0 +1,14 @@
<script>
import { onError } from "svelte";
var a = {}
export var error = false;
onError(e => {
error = true;
});
</script>
{#each a.b.c as item}
{item}
{/each}

@ -0,0 +1,10 @@
export default {
async test({ assert, component, target, window }) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
await button.dispatchEvent(event);
assert.equal(component.error, true);
}
}

@ -0,0 +1,24 @@
<script>
import { onError } from "svelte";
var a = {
b: {
c: false
}
};
export var error = false;
onError(e => {
error = true;
});
function clickEvent() {
a = {};
}
</script>
<button on:click={clickEvent}></button>
{#if a.b.c === true}
Hello world
{/if}

@ -0,0 +1,10 @@
export default {
async test({ assert, component, target, window }) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
await button.dispatchEvent(event);
assert.equal(component.error, true);
}
}

@ -0,0 +1,4 @@
<script>
var a = {};
console.log(a.b.c);
</script>

@ -0,0 +1,21 @@
<script>
import Child from "./child.svelte";
import { onError } from "svelte";
var show = false;
export var error = false;
onError(e => {
error = true;
});
function clickEvent() {
show = true;
}
</script>
<button on:click={clickEvent}></button>
{#if show}
<Child />
{/if}

@ -0,0 +1,5 @@
export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}

@ -0,0 +1,14 @@
<script>
import { onError } from "svelte";
var a = {};
export var error = false;
onError(e => {
error = true;
});
</script>
{#if a.b.c === true}
Hello world
{/if}

@ -0,0 +1,5 @@
export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}

@ -0,0 +1,4 @@
<script>
var a = {};
console.log(a.b.c);
</script>

@ -0,0 +1,15 @@
<script>
import Wrapper from "./wrapper.svelte";
import Child from "./child.svelte";
import { onError } from "svelte";
export var error = false;
onError(e => {
error = true;
});
</script>
<Wrapper>
<Child />
</Wrapper>

@ -0,0 +1,7 @@
<script>
import { onError } from "svelte";
onError(e => {});
</script>
<slot />
Loading…
Cancel
Save