Skip to content

Commit

Permalink
deconflict with builtins (#3724)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and Conduitry committed Oct 21, 2019
1 parent e3953b2 commit fca35de
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/compiler/compile/render_dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ export default class Block {

if (!wrapper.var) continue;

let suffix = '';
if (dupes.has(wrapper.var.name)) {
const i = counts.get(wrapper.var.name) || 0;
counts.set(wrapper.var.name, i + 1);
wrapper.var.name = this.get_unique_name(wrapper.var.name + i).name;
suffix = i;
}
wrapper.var.name = this.get_unique_name(wrapper.var.name + suffix).name;
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/debug-no-dependencies/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function create_each_block(ctx) {
}

function create_fragment(ctx) {
let each_anchor;
let each_1_anchor;
let each_value = things;
let each_blocks = [];

Expand All @@ -74,7 +74,7 @@ function create_fragment(ctx) {
each_blocks[i].c();
}

each_anchor = empty();
each_1_anchor = empty();
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
Expand All @@ -84,7 +84,7 @@ function create_fragment(ctx) {
each_blocks[i].m(target, anchor);
}

insert_dev(target, each_anchor, anchor);
insert_dev(target, each_1_anchor, anchor);
},
p: function update(changed, ctx) {
if (changed.things) {
Expand All @@ -99,7 +99,7 @@ function create_fragment(ctx) {
} else {
each_blocks[i] = create_each_block(child_ctx);
each_blocks[i].c();
each_blocks[i].m(each_anchor.parentNode, each_anchor);
each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
}
}

Expand All @@ -114,7 +114,7 @@ function create_fragment(ctx) {
o: noop,
d: function destroy(detaching) {
destroy_each(each_blocks, detaching);
if (detaching) detach_dev(each_anchor);
if (detaching) detach_dev(each_1_anchor);
}
};

Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/deconflict-builtins/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function create_each_block(ctx) {
}

function create_fragment(ctx) {
let each_anchor;
let each_1_anchor;
let each_value = ctx.createElement;
let each_blocks = [];

Expand All @@ -57,14 +57,14 @@ function create_fragment(ctx) {
each_blocks[i].c();
}

each_anchor = empty();
each_1_anchor = empty();
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
}

insert(target, each_anchor, anchor);
insert(target, each_1_anchor, anchor);
},
p(changed, ctx) {
if (changed.createElement) {
Expand All @@ -79,7 +79,7 @@ function create_fragment(ctx) {
} else {
each_blocks[i] = create_each_block(child_ctx);
each_blocks[i].c();
each_blocks[i].m(each_anchor.parentNode, each_anchor);
each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
}
}

Expand All @@ -94,7 +94,7 @@ function create_fragment(ctx) {
o: noop,
d(detaching) {
destroy_each(each_blocks, detaching);
if (detaching) detach(each_anchor);
if (detaching) detach(each_1_anchor);
}
};
}
Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/each-block-array-literal/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function create_each_block(ctx) {
}

function create_fragment(ctx) {
let each_anchor;
let each_1_anchor;
let each_value = [ctx.a, ctx.b, ctx.c, ctx.d, ctx.e];
let each_blocks = [];

Expand All @@ -57,14 +57,14 @@ function create_fragment(ctx) {
each_blocks[i].c();
}

each_anchor = empty();
each_1_anchor = empty();
},
m(target, anchor) {
for (let i = 0; i < 5; i += 1) {
each_blocks[i].m(target, anchor);
}

insert(target, each_anchor, anchor);
insert(target, each_1_anchor, anchor);
},
p(changed, ctx) {
if (changed.a || changed.b || changed.c || changed.d || changed.e) {
Expand All @@ -79,7 +79,7 @@ function create_fragment(ctx) {
} else {
each_blocks[i] = create_each_block(child_ctx);
each_blocks[i].c();
each_blocks[i].m(each_anchor.parentNode, each_anchor);
each_blocks[i].m(each_1_anchor.parentNode, each_1_anchor);
}
}

Expand All @@ -92,7 +92,7 @@ function create_fragment(ctx) {
o: noop,
d(detaching) {
destroy_each(each_blocks, detaching);
if (detaching) detach(each_anchor);
if (detaching) detach(each_1_anchor);
}
};
}
Expand Down
14 changes: 7 additions & 7 deletions test/js/samples/each-block-keyed-animated/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ function create_each_block(key_1, ctx) {

function create_fragment(ctx) {
let each_blocks = [];
let each_lookup = new Map();
let each_anchor;
let each_1_lookup = new Map();
let each_1_anchor;
let each_value = ctx.things;
const get_key = ctx => ctx.thing.id;

for (let i = 0; i < each_value.length; i += 1) {
let child_ctx = get_each_context(ctx, each_value, i);
let key = get_key(child_ctx);
each_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
}

return {
Expand All @@ -80,19 +80,19 @@ function create_fragment(ctx) {
each_blocks[i].c();
}

each_anchor = empty();
each_1_anchor = empty();
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
}

insert(target, each_anchor, anchor);
insert(target, each_1_anchor, anchor);
},
p(changed, ctx) {
const each_value = ctx.things;
for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].r();
each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, fix_and_destroy_block, create_each_block, each_anchor, get_each_context);
each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, fix_and_destroy_block, create_each_block, each_1_anchor, get_each_context);
for (let i = 0; i < each_blocks.length; i += 1) each_blocks[i].a();
},
i: noop,
Expand All @@ -102,7 +102,7 @@ function create_fragment(ctx) {
each_blocks[i].d(detaching);
}

if (detaching) detach(each_anchor);
if (detaching) detach(each_1_anchor);
}
};
}
Expand Down
14 changes: 7 additions & 7 deletions test/js/samples/each-block-keyed/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ function create_each_block(key_1, ctx) {

function create_fragment(ctx) {
let each_blocks = [];
let each_lookup = new Map();
let each_anchor;
let each_1_lookup = new Map();
let each_1_anchor;
let each_value = ctx.things;
const get_key = ctx => ctx.thing.id;

for (let i = 0; i < each_value.length; i += 1) {
let child_ctx = get_each_context(ctx, each_value, i);
let key = get_key(child_ctx);
each_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
each_1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx));
}

return {
Expand All @@ -65,18 +65,18 @@ function create_fragment(ctx) {
each_blocks[i].c();
}

each_anchor = empty();
each_1_anchor = empty();
},
m(target, anchor) {
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].m(target, anchor);
}

insert(target, each_anchor, anchor);
insert(target, each_1_anchor, anchor);
},
p(changed, ctx) {
const each_value = ctx.things;
each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_lookup, each_anchor.parentNode, destroy_block, create_each_block, each_anchor, get_each_context);
each_blocks = update_keyed_each(each_blocks, changed, get_key, 1, ctx, each_value, each_1_lookup, each_1_anchor.parentNode, destroy_block, create_each_block, each_1_anchor, get_each_context);
},
i: noop,
o: noop,
Expand All @@ -85,7 +85,7 @@ function create_fragment(ctx) {
each_blocks[i].d(detaching);
}

if (detaching) detach(each_anchor);
if (detaching) detach(each_1_anchor);
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions test/runtime/samples/deconflict-builtins-2/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
html: `<text>hello world</text>`,
preserveIdentifiers: true,
};
5 changes: 5 additions & 0 deletions test/runtime/samples/deconflict-builtins-2/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
let foo = 'hello world'
</script>

<text>{foo}</text>

0 comments on commit fca35de

Please sign in to comment.