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 init_statements = Array.from(this.variables.values()).filter(({ init }) => init !== undefined).map(({ id, init }) => {
return b`${id} = ${init}`;
const init_declarations = [];
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`
${this.chunks.declarations}
${Array.from(this.variables.values()).map(({ id }) => {
return b`let ${id}`;
})}
${init_declarations}
${init_statements.length > 0
? b`
@ -414,8 +432,6 @@ export default class Block {
: ''
}
${this.chunks.init}
${dev
? b`
const ${block} = ${return_value};

@ -454,35 +454,41 @@ export default function dom(
let instance_javascript_with_ctx = [];
let initializedIdentifiers = [];
instance_javascript.forEach(node => {
instance_javascript_with_ctx.push(node);
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);
if (index >= 0) {
node.push(x`#return_values[${index}] = ${declaration}`);
initializedIdentifiers.push(declaration.name);
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" ) {
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);
if (index >= 0) {
node.push(x`#return_values[${index}] = ${declaration}`);
initializedIdentifiers.push(declaration.name);
}
}
}
}
});
}
if (node.type === "FunctionDeclaration") {
if (!initializedIdentifiers.includes(node.id.name)) {
let 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}`);
initializedIdentifiers.push(node.id.name);
});
}
if (node.type === "FunctionDeclaration") {
if (!initializedIdentifiers.includes(node.id.name)) {
let 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}`);
initializedIdentifiers.push(node.id.name);
}
}
}
}
});
});
}
const instance_try_block: any = b`
try {

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