Skip to content

Commit

Permalink
prevent name collisions with each block index - fixes #1254
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 18, 2018
1 parent 4cb8eff commit 4b5d465
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/generators/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export default class EachBlock extends Node {
this.block.contextTypes.set(this.context, 'each');
this.block.indexNames.set(this.context, indexName);
this.block.listNames.set(this.context, listName);

if (this.index) {
this.block.getUniqueName(this.index); // this prevents name collisions (#1254)
this.block.indexes.set(this.index, this.context);
this.block.changeableIndexes.set(this.index, this.key)
this.block.changeableIndexes.set(this.index, this.key); // TODO is this right?
}

const context = this.block.getUniqueName(this.context);
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function capitalise(str) {
return str[0].toUpperCase() + str.slice(1);
}

export function showOutput(cwd, options = {}, s = svelte) {
export function showOutput(cwd, options = {}, compile = svelte.compile) {
glob.sync('**/*.html', { cwd }).forEach(file => {
if (file[0] === '_') return;

Expand All @@ -183,7 +183,7 @@ export function showOutput(cwd, options = {}, s = svelte) {
.replace(/^\d/, '_$&')
.replace(/[^a-zA-Z0-9_$]/g, '');

const { code } = s.compile(
const { code } = compile(
fs.readFileSync(`${cwd}/${file}`, 'utf-8'),
Object.assign(options, {
filename: file,
Expand Down
10 changes: 5 additions & 5 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function getName(filename) {

describe("runtime", () => {
before(() => {
svelte$ = loadSvelte(true);
svelte = loadSvelte(false);
svelte$ = loadSvelte(true);

require.extensions[".html"] = function(module, filename) {
const options = Object.assign(
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("runtime", () => {
if (err.frame) {
console.error(chalk.red(err.frame)); // eslint-disable-line no-console
}
showOutput(cwd, { shared, format: 'cjs', store: !!compileOptions.store }, svelte$); // eslint-disable-line no-console
showOutput(cwd, { shared, format: 'cjs', store: !!compileOptions.store }, compile); // eslint-disable-line no-console
throw err;
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ describe("runtime", () => {
try {
SvelteComponent = require(`./samples/${dir}/main.html`);
} catch (err) {
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte$); // eslint-disable-line no-console
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile); // eslint-disable-line no-console
throw err;
}

Expand Down Expand Up @@ -203,12 +203,12 @@ describe("runtime", () => {
config.error(assert, err);
} else {
failed.add(dir);
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte$); // eslint-disable-line no-console
showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile); // eslint-disable-line no-console
throw err;
}
})
.then(() => {
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, svelte$);
if (config.show) showOutput(cwd, { shared, format: 'cjs', hydratable: hydrate, store: !!compileOptions.store }, compile);
});
});
}
Expand Down
3 changes: 0 additions & 3 deletions test/runtime/samples/deconflict-elements-indexes/_config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export default {
solo: true,
show: true,

html: `
<div>
<i>one</i>
Expand Down

0 comments on commit 4b5d465

Please sign in to comment.