Skip to content

Commit

Permalink
Fixed added error handling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rster2002 committed Aug 3, 2021
1 parent 648c627 commit ad2aba8
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 41 deletions.
19 changes: 12 additions & 7 deletions src/compiler/compile/render_dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,20 @@ export default class Block {
}
});

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}`);
if (Array.isArray(node)) {
node.forEach((declaration: any) => { // TODO add type to this
if (declaration.declarations) {
declaration.declarations.forEach(({ id, init }) => {
init_declarations.push(b`let ${id}`);
init_statements.push(b`${id} = ${init}`);
});
} else {
init_statements.push(declaration);
}
});
} else {
init_declarations.push(node);
init_statements.push(node);
}
});

Expand All @@ -428,6 +432,7 @@ export default class Block {
${init_statements}
} catch (e) {
@handle_error(@get_current_component(), e);
return;
}`
: ''
}
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/compile/render_dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,19 @@ export default function dom(
};

let instance_javascript_with_ctx = [];
let initializedIdentifiers = [];
const initializedIdentifiers = [];

if (instance_javascript === null) {
instance_javascript_with_ctx = instance_javascript;
} else {
instance_javascript.forEach(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], {
enter(declaration: Identifier) {
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) {
node.push(x`#return_values[${index}] = ${declaration}`);
Expand All @@ -476,9 +476,9 @@ export default function dom(
});
}

if (node.type === "FunctionDeclaration") {
if (node.type === 'FunctionDeclaration') {
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) {
instance_javascript_with_ctx.push(x`#return_values[${index}] = ${node.id.name}`);
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ export function insert_hydration(target: NodeEx, node: NodeEx, anchor?: NodeEx)
}

export function detach(node: Node) {
node.parentNode.removeChild(node);
if (node.parentNode !== null) {
node.parentNode.removeChild(node);
}
}

export function destroy_each(iterations, detaching) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
<script>
import { onError } from "svelte";
var a = [1, 2, 3];
var a = {}
export var error = false;
onError(e => {
error = true;
});
function handleClick() {
a = 10;
}
</script>

{#each a as item}
{#each a.b.c as item}
{item}
{/each}

<button on:click={handleClick}></button>
{/each}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {

assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<script>
import { onError } from "svelte";
var a = {}
var a = [1, 2, 3];
export var error = false;
onError(e => {
error = true;
});
function handleClick() {
a = 10;
}
</script>

{#each a.b.c as item}
{#each a as item}
{item}
{/each}
{/each}

<button on:click={handleClick}></button>
2 changes: 1 addition & 1 deletion test/runtime/samples/error-handling-each-block/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
assert.equal(component.error, true);
assert.equal(component.that, button);
}
}
};
2 changes: 1 addition & 1 deletion test/runtime/samples/error-handling-event/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {

assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {

assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {

assert.equal(component.error, true);
}
}
};
2 changes: 1 addition & 1 deletion test/runtime/samples/error-handling-if-block/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export default {

assert.equal(component.error, true);
}
}
};
2 changes: 1 addition & 1 deletion test/runtime/samples/error-handling-template/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
test({ assert, component }) {
assert.equal(component.error, true);
}
}
};

0 comments on commit ad2aba8

Please sign in to comment.