From 27f6d560b5a790d6a38e90cca2170dd85ddbb20e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 11 Feb 2018 16:04:15 -0500 Subject: [PATCH] remove some unused code etc --- src/generators/Generator.ts | 45 ++++++++----------- src/generators/dom/Block.ts | 2 +- src/generators/dom/index.ts | 4 +- .../expected-bundle.js | 2 +- .../each-block-changed-check/expected.js | 2 +- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 2463c33325..d5c779a5f4 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -242,29 +242,24 @@ export default class Generator { if (name === 'event' && isEventHandler) { // noop } else if (contexts.has(name)) { - // if (self.constructor.name === 'DomGenerator') { // TODO filthy, temporary hack - const contextName = contexts.get(name); - if (contextName !== name) { - // this is true for 'reserved' names like `state` and `component`, - // also destructured contexts - - code.overwrite( - node.start, - node.start + name.length, - contextName, - { storeName: true, contentOnly: false } - ); - - const destructuredName = contextName.replace(/\[\d+\]/, ''); - if (destructuredName !== contextName) { - // so that hoisting the context works correctly - usedContexts.add(destructuredName); - } + const contextName = contexts.get(name); + if (contextName !== name) { + // this is true for 'reserved' names like `state` and `component`, + // also destructured contexts + + code.overwrite( + node.start, + node.start + name.length, + contextName, + { storeName: true, contentOnly: false } + ); + + const destructuredName = contextName.replace(/\[\d+\]/, ''); + if (destructuredName !== contextName) { + // so that hoisting the context works correctly + usedContexts.add(destructuredName); } - - // TODO filthy, temporary hack - // if (!isEventHandler) code.prependRight(node.start, `state.`); - // } + } usedContexts.add(name); } else if (helpers.has(name)) { @@ -274,8 +269,6 @@ export default class Generator { const alias = self.templateVars.get(`helpers-${name}`); if (alias !== name) code.overwrite(object.start, object.end, alias); } else if (indexes.has(name)) { - if (self.constructor.name === 'DomGenerator' && !isEventHandler) code.prependRight(node.start, `state.`); - const context = indexes.get(name); usedContexts.add(context); // TODO is this right? usedIndexes.add(name); @@ -381,8 +374,8 @@ export default class Generator { return alias; } - getUniqueNameMaker(params: string[]) { - const localUsedNames = new Set(params); + getUniqueNameMaker() { + const localUsedNames = new Set(); function add(name: string) { localUsedNames.add(name); diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 07fb763f82..0d786752dc 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -114,7 +114,7 @@ export default class Block { this.aliases = new Map(); this.variables = new Map(); - this.getUniqueName = this.generator.getUniqueNameMaker([]); // TODO this is wrong... we probably don't need this any more + this.getUniqueName = this.generator.getUniqueNameMaker(); this.hasUpdateMethod = false; // determined later } diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 090dffbf3e..2f88185fff 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -49,8 +49,8 @@ export class DomGenerator extends Generator { this.metaBindings = []; } - getUniqueNameMaker(params: string[]) { - const localUsedNames = new Set(params); // TODO is this ever called with params? + getUniqueNameMaker() { + const localUsedNames = new Set(); function add(name: string) { localUsedNames.add(name); diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 3b76fb9ad7..cc8a394ac1 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -291,7 +291,7 @@ function create_each_block(component, state) { c: function create() { div = createElement("div"); strong = createElement("strong"); - text = createText(state.i); + text = createText(i); text_1 = createText("\n\n\t\t"); span = createElement("span"); text_2 = createText(text_2_value); diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index c86a3a2edf..2eb66567a6 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -91,7 +91,7 @@ function create_each_block(component, state) { c: function create() { div = createElement("div"); strong = createElement("strong"); - text = createText(state.i); + text = createText(i); text_1 = createText("\n\n\t\t"); span = createElement("span"); text_2 = createText(text_2_value);