From ad2aba861be981f1c97dced335e9531c2d486500 Mon Sep 17 00:00:00 2001 From: rster20002 Date: Tue, 3 Aug 2021 10:41:49 +0200 Subject: [PATCH] Fixed added error handling tests --- src/compiler/compile/render_dom/Block.ts | 19 ++++++++++++------- src/compiler/compile/render_dom/index.ts | 10 +++++----- src/runtime/internal/dom.ts | 4 +++- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../main.svelte | 12 +++--------- .../_config.js | 2 +- .../main.svelte | 12 +++++++++--- .../error-handling-each-block/_config.js | 2 +- .../_config.js | 2 +- .../samples/error-handling-event/_config.js | 2 +- .../_config.js | 2 +- .../_config.js | 2 +- .../error-handling-if-block/_config.js | 2 +- .../_config.js | 2 +- .../child.svelte | 0 .../main.svelte | 0 .../_config.js | 2 +- .../_config.js | 2 +- .../error-handling-template/_config.js | 2 +- 23 files changed, 48 insertions(+), 41 deletions(-) rename test/runtime/samples/{error-handling-bubble-to-parent-manually => error-handling-manually-bubble-to-parent}/_config.js (97%) rename test/runtime/samples/{error-handling-bubble-to-parent-manually => error-handling-manually-bubble-to-parent}/child.svelte (100%) rename test/runtime/samples/{error-handling-bubble-to-parent-manually => error-handling-manually-bubble-to-parent}/main.svelte (100%) diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index d568461b10..5ff5139b38 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -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); } }); @@ -428,6 +432,7 @@ export default class Block { ${init_statements} } catch (e) { @handle_error(@get_current_component(), e); + return; }` : '' } diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index dd1fba8f7a..226a0d5828 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -453,7 +453,7 @@ export default function dom( }; let instance_javascript_with_ctx = []; - let initializedIdentifiers = []; + const initializedIdentifiers = []; if (instance_javascript === null) { instance_javascript_with_ctx = instance_javascript; @@ -461,11 +461,11 @@ export default function dom( 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}`); @@ -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}`); diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index f563f6d099..8768435d4b 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -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) { diff --git a/test/runtime/samples/error-handling-bubble-to-parent/_config.js b/test/runtime/samples/error-handling-bubble-to-parent/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-bubble-to-parent/_config.js +++ b/test/runtime/samples/error-handling-bubble-to-parent/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-catch-after-error/_config.js b/test/runtime/samples/error-handling-catch-after-error/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-catch-after-error/_config.js +++ b/test/runtime/samples/error-handling-catch-after-error/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-catch-before-error/_config.js b/test/runtime/samples/error-handling-catch-before-error/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-catch-before-error/_config.js +++ b/test/runtime/samples/error-handling-catch-before-error/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-dynamic-component/_config.js b/test/runtime/samples/error-handling-dynamic-component/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-dynamic-component/_config.js +++ b/test/runtime/samples/error-handling-dynamic-component/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-each-block-non-array/_config.js b/test/runtime/samples/error-handling-each-block-non-array/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-each-block-non-array/_config.js +++ b/test/runtime/samples/error-handling-each-block-non-array/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-each-block-non-array/main.svelte b/test/runtime/samples/error-handling-each-block-non-array/main.svelte index b4fb0abca4..0a39d8a0b7 100644 --- a/test/runtime/samples/error-handling-each-block-non-array/main.svelte +++ b/test/runtime/samples/error-handling-each-block-non-array/main.svelte @@ -1,20 +1,14 @@ -{#each a as item} +{#each a.b.c as item} {item} -{/each} - - \ No newline at end of file +{/each} \ No newline at end of file diff --git a/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js b/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js index edd0bd074b..773299e415 100644 --- a/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js +++ b/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js @@ -7,4 +7,4 @@ export default { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte b/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte index 0a39d8a0b7..b4fb0abca4 100644 --- a/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte +++ b/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte @@ -1,14 +1,20 @@ -{#each a.b.c as item} +{#each a as item} {item} -{/each} \ No newline at end of file +{/each} + + \ No newline at end of file diff --git a/test/runtime/samples/error-handling-each-block/_config.js b/test/runtime/samples/error-handling-each-block/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-each-block/_config.js +++ b/test/runtime/samples/error-handling-each-block/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-event-correct-this/_config.js b/test/runtime/samples/error-handling-event-correct-this/_config.js index 3f90d0b5cc..3a1e25bd22 100644 --- a/test/runtime/samples/error-handling-event-correct-this/_config.js +++ b/test/runtime/samples/error-handling-event-correct-this/_config.js @@ -8,4 +8,4 @@ export default { assert.equal(component.error, true); assert.equal(component.that, button); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-event/_config.js b/test/runtime/samples/error-handling-event/_config.js index edd0bd074b..773299e415 100644 --- a/test/runtime/samples/error-handling-event/_config.js +++ b/test/runtime/samples/error-handling-event/_config.js @@ -7,4 +7,4 @@ export default { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-if-block-reactive/_config.js b/test/runtime/samples/error-handling-if-block-reactive/_config.js index edd0bd074b..773299e415 100644 --- a/test/runtime/samples/error-handling-if-block-reactive/_config.js +++ b/test/runtime/samples/error-handling-if-block-reactive/_config.js @@ -7,4 +7,4 @@ export default { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-if-block-show-component/_config.js b/test/runtime/samples/error-handling-if-block-show-component/_config.js index edd0bd074b..773299e415 100644 --- a/test/runtime/samples/error-handling-if-block-show-component/_config.js +++ b/test/runtime/samples/error-handling-if-block-show-component/_config.js @@ -7,4 +7,4 @@ export default { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-if-block/_config.js b/test/runtime/samples/error-handling-if-block/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-if-block/_config.js +++ b/test/runtime/samples/error-handling-if-block/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-bubble-to-parent-manually/_config.js b/test/runtime/samples/error-handling-manually-bubble-to-parent/_config.js similarity index 97% rename from test/runtime/samples/error-handling-bubble-to-parent-manually/_config.js rename to test/runtime/samples/error-handling-manually-bubble-to-parent/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-bubble-to-parent-manually/_config.js +++ b/test/runtime/samples/error-handling-manually-bubble-to-parent/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-bubble-to-parent-manually/child.svelte b/test/runtime/samples/error-handling-manually-bubble-to-parent/child.svelte similarity index 100% rename from test/runtime/samples/error-handling-bubble-to-parent-manually/child.svelte rename to test/runtime/samples/error-handling-manually-bubble-to-parent/child.svelte diff --git a/test/runtime/samples/error-handling-bubble-to-parent-manually/main.svelte b/test/runtime/samples/error-handling-manually-bubble-to-parent/main.svelte similarity index 100% rename from test/runtime/samples/error-handling-bubble-to-parent-manually/main.svelte rename to test/runtime/samples/error-handling-manually-bubble-to-parent/main.svelte diff --git a/test/runtime/samples/error-handling-slotted-component/_config.js b/test/runtime/samples/error-handling-slotted-component/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-slotted-component/_config.js +++ b/test/runtime/samples/error-handling-slotted-component/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-template-reactive/_config.js b/test/runtime/samples/error-handling-template-reactive/_config.js index edd0bd074b..773299e415 100644 --- a/test/runtime/samples/error-handling-template-reactive/_config.js +++ b/test/runtime/samples/error-handling-template-reactive/_config.js @@ -7,4 +7,4 @@ export default { assert.equal(component.error, true); } -} \ No newline at end of file +}; diff --git a/test/runtime/samples/error-handling-template/_config.js b/test/runtime/samples/error-handling-template/_config.js index acd4e2a2f0..fab5d76ee6 100644 --- a/test/runtime/samples/error-handling-template/_config.js +++ b/test/runtime/samples/error-handling-template/_config.js @@ -2,4 +2,4 @@ export default { test({ assert, component }) { assert.equal(component.error, true); } -} \ No newline at end of file +};