Add test case for #2115 and possible fix

pull/2233/head
Mikhail Korepanov 6 years ago
parent d618c238f5
commit 57897d468e

@ -86,14 +86,14 @@ export default class Attribute extends Node {
return Array.from(dependencies);
}
getValue() {
getValue(block) {
if (this.isTrue) return true;
if (this.chunks.length === 0) return `""`;
if (this.chunks.length === 1) {
return this.chunks[0].type === 'Text'
? stringify(this.chunks[0].data)
: this.chunks[0].render();
: this.chunks[0].render(block);
}
return (this.chunks[0].type === 'Text' ? '' : `"" + `) +
@ -117,4 +117,4 @@ export default class Attribute extends Node {
? this.chunks[0].data
: '';
}
}
}

@ -179,7 +179,7 @@ export default class AttributeWrapper {
);
}
} else {
const value = this.node.getValue();
const value = this.node.getValue(block);
const statement = (
isLegacyInputType

@ -579,7 +579,7 @@ export default class ElementWrapper extends Wrapper {
updates.push(condition ? `${condition} && ${snippet}` : snippet);
} else {
const snippet = `{ ${quoteNameIfNecessary(attr.name)}: ${attr.getValue()} }`;
const snippet = `{ ${quoteNameIfNecessary(attr.name)}: ${attr.getValue(block)} }`;
initialProps.push(snippet);
updates.push(condition ? `${condition} && ${snippet}` : snippet);
@ -846,4 +846,4 @@ export default class ElementWrapper extends Wrapper {
);
}
}
}
}

@ -118,7 +118,7 @@ export default class InlineComponentWrapper extends Wrapper {
const attributeObject = usesSpread
? stringifyProps(slot_props)
: stringifyProps(
this.node.attributes.map(attr => `${quoteNameIfNecessary(attr.name)}: ${attr.getValue()}`).concat(slot_props)
this.node.attributes.map(attr => `${quoteNameIfNecessary(attr.name)}: ${attr.getValue(block)}`).concat(slot_props)
);
if (this.node.attributes.length || this.node.bindings.length || slot_props.length) {
@ -190,7 +190,7 @@ export default class InlineComponentWrapper extends Wrapper {
changes.push(condition ? `${condition} && ${value}` : value);
} else {
const obj = `{ ${quoteNameIfNecessary(name)}: ${attr.getValue()} }`;
const obj = `{ ${quoteNameIfNecessary(name)}: ${attr.getValue(block)} }`;
initialProps.push(obj);
changes.push(condition ? `${condition} && ${obj}` : obj);
@ -224,7 +224,7 @@ export default class InlineComponentWrapper extends Wrapper {
updates.push(deindent`
if (${[...attribute.dependencies]
.map(dependency => `changed.${dependency}`)
.join(' || ')}) ${name_changes}${quotePropIfNecessary(attribute.name)} = ${attribute.getValue()};
.join(' || ')}) ${name_changes}${quotePropIfNecessary(attribute.name)} = ${attribute.getValue(block)};
`);
}
});

@ -0,0 +1,97 @@
/* generated by Svelte vX.Y.Z */
import { SvelteComponent as SvelteComponent_1, createComment, createElement, destroyEach, detachNode, init, insert, noop, safe_not_equal, setAttribute } from "svelte/internal";
function get_each_context(ctx, list, i) {
const child_ctx = Object.create(ctx);
child_ctx.item = list[i];
return child_ctx;
}
// (1:0) {#each Array(1) as item}
function create_each_block(ctx) {
var boo;
function func() {
return ctx.func(ctx);
}
return {
c() {
boo = createElement("boo");
setAttribute(boo, "cb", func);
},
m(target, anchor) {
insert(target, boo, anchor);
},
p(changed, new_ctx) {
ctx = new_ctx;
},
d(detach) {
if (detach) {
detachNode(boo);
}
}
};
}
function create_fragment(ctx) {
var each_anchor;
var each_value = Array(1);
var each_blocks = [];
for (var i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
}
return {
c() {
for (var i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
each_anchor = createComment();
},
m(target, anchor) {
for (var i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
}
insert(target, each_anchor, anchor);
},
p: noop,
i: noop,
o: noop,
d(detach) {
destroyEach(each_blocks, detach);
if (detach) {
detachNode(each_anchor);
}
}
};
}
function instance($$self) {
function func({ item }) {
return item;
}
return { func };
}
class SvelteComponent extends SvelteComponent_1 {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal);
}
}
export default SvelteComponent;

@ -0,0 +1,3 @@
{#each Array(1) as item}
<boo cb="{() => item}" />
{/each}
Loading…
Cancel
Save