Fixed added error handling tests

pull/6585/head
rster20002 5 years ago
parent 648c62790d
commit ad2aba861b

@ -404,16 +404,20 @@ export default class Block {
} }
}); });
console.log("H");
this.chunks.init.forEach(node => { this.chunks.init.forEach(node => {
if (Array.isArray(node) && node[0].type === "VariableDeclaration") { if (Array.isArray(node)) {
node[0].declarations.forEach(({ id, init }) => { node.forEach((declaration: any) => { // TODO add type to this
console.log(id); if (declaration.declarations) {
init_declarations.push(b`let ${id};`); declaration.declarations.forEach(({ id, init }) => {
init_statements.push(b`${id} = ${init}`); init_declarations.push(b`let ${id}`);
init_statements.push(b`${id} = ${init}`);
});
} else {
init_statements.push(declaration);
}
}); });
} else { } else {
init_declarations.push(node); init_statements.push(node);
} }
}); });
@ -428,6 +432,7 @@ export default class Block {
${init_statements} ${init_statements}
} catch (e) { } catch (e) {
@handle_error(@get_current_component(), e); @handle_error(@get_current_component(), e);
return;
}` }`
: '' : ''
} }

@ -453,7 +453,7 @@ export default function dom(
}; };
let instance_javascript_with_ctx = []; let instance_javascript_with_ctx = [];
let initializedIdentifiers = []; const initializedIdentifiers = [];
if (instance_javascript === null) { if (instance_javascript === null) {
instance_javascript_with_ctx = instance_javascript; instance_javascript_with_ctx = instance_javascript;
@ -461,11 +461,11 @@ export default function dom(
instance_javascript.forEach(node => { instance_javascript.forEach(node => {
instance_javascript_with_ctx.push(node); instance_javascript_with_ctx.push(node);
if (Array.isArray(node) && node[0].type === "VariableDeclaration" ) { if (Array.isArray(node) && node[0].type === 'VariableDeclaration') {
walk(node[0], { walk(node[0], {
enter(declaration: Identifier) { enter(declaration: Identifier) {
if (declaration.type === 'Identifier' && !initializedIdentifiers.includes(declaration.name)) { if (declaration.type === 'Identifier' && !initializedIdentifiers.includes(declaration.name)) {
let index = renderer.initial_context.findIndex(member => member.name === declaration.name); const index = renderer.initial_context.findIndex(member => member.name === declaration.name);
if (index >= 0) { if (index >= 0) {
node.push(x`#return_values[${index}] = ${declaration}`); node.push(x`#return_values[${index}] = ${declaration}`);
@ -476,9 +476,9 @@ export default function dom(
}); });
} }
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); const 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}`);

@ -203,7 +203,9 @@ export function insert_hydration(target: NodeEx, node: NodeEx, anchor?: NodeEx)
} }
export function detach(node: Node) { export function detach(node: Node) {
node.parentNode.removeChild(node); if (node.parentNode !== null) {
node.parentNode.removeChild(node);
}
} }
export function destroy_each(iterations, detaching) { export function destroy_each(iterations, detaching) {

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

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

@ -7,4 +7,4 @@ export default {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

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

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -8,4 +8,4 @@ export default {
assert.equal(component.error, true); assert.equal(component.error, true);
assert.equal(component.that, button); assert.equal(component.that, button);
} }
} };

@ -7,4 +7,4 @@ export default {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -7,4 +7,4 @@ export default {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -7,4 +7,4 @@ export default {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -7,4 +7,4 @@ export default {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

@ -2,4 +2,4 @@ export default {
test({ assert, component }) { test({ assert, component }) {
assert.equal(component.error, true); assert.equal(component.error, true);
} }
} };

Loading…
Cancel
Save