diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 733bb68490..ff58a4e947 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -128,14 +128,12 @@ export default class Block { this.addVariable(name); this.builders.create.addLine(`${name} = ${renderStatement};`); - this.builders.claim.addLine(`${name} = ${claimStatement};`) + this.builders.claim.addLine(`${name} = ${claimStatement};`); this.mount(name, parentNode); if (isToplevel) { - this.builders.unmount.addLine( - `@detachNode( ${name} );` - ); + this.builders.unmount.addLine(`@detachNode( ${name} );`); } } @@ -180,13 +178,9 @@ export default class Block { mount(name: string, parentNode: string) { if (parentNode) { - this.builders.mount.addLine( - `@appendNode( ${name}, ${parentNode} );` - ); + this.builders.mount.addLine(`@appendNode( ${name}, ${parentNode} );`); } else { - this.builders.mount.addLine( - `@insertNode( ${name}, #target, anchor );` - ); + this.builders.mount.addLine(`@insertNode( ${name}, #target, anchor );`); } } @@ -222,7 +216,7 @@ export default class Block { if (this.first) { properties.addBlock(`first: null,`); - this.builders.hydrate.addLine( `this.first = ${this.first};` ); + this.builders.hydrate.addLine(`this.first = ${this.first};`); } if (this.builders.create.isEmpty()) { @@ -347,11 +341,13 @@ export default class Block { function ${this.name} ( ${this.params.join(', ')}, #component${this.key ? `, ${localKey}` : ''} ) { - ${this.variables.size > 0 && ( - `var ${Array.from(this.variables.keys()).map(key => { - const init = this.variables.get(key); - return init !== undefined ? `${key} = ${init}` : key; - }).join(', ')};`)} + ${this.variables.size > 0 && + `var ${Array.from(this.variables.keys()) + .map(key => { + const init = this.variables.get(key); + return init !== undefined ? `${key} = ${init}` : key; + }) + .join(', ')};`} ${!this.builders.init.isEmpty() && this.builders.init} diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index c82ffbc792..a65226497e 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -86,7 +86,9 @@ export default function dom( `( '${dep}' in newState && @differs( state.${dep}, oldState.${dep} ) )` ) .join(' || ')}`; - const statement = `state.${key} = newState.${key} = @template.computed.${key}( ${deps.map(dep => `state.${dep}`).join(', ')} );`; + const statement = `state.${key} = newState.${key} = @template.computed.${key}( ${deps + .map(dep => `state.${dep}`) + .join(', ')} );`; computationBuilder.addConditionalLine(condition, statement); }); @@ -113,7 +115,8 @@ export default function dom( var oldState = this._state; this._state = @assign( {}, oldState, newState ); - ${computations.length && `@recompute( this._state, newState, oldState, false )`} + ${computations.length && + `@recompute( this._state, newState, oldState, false )`} @dispatchObservers( this, this._observers.pre, newState, oldState ); ${block.hasUpdateMethod && `this._fragment.update( newState, this._state );`} @dispatchObservers( this, this._observers.post, newState, oldState ); @@ -124,9 +127,7 @@ export default function dom( `; if (hasJs) { - builder.addBlock( - `[✂${parsed.js.content.start}-${parsed.js.content.end}✂]` - ); + builder.addBlock(`[✂${parsed.js.content.start}-${parsed.js.content.end}✂]`); } if (generator.css && options.css !== false) { @@ -150,9 +151,7 @@ export default function dom( const prototypeBase = `${name}.prototype` + - (templateProperties.methods - ? `, @template.methods` - : ''); + (templateProperties.methods ? `, @template.methods` : ''); const proto = sharedPath ? `@proto ` : deindent` @@ -173,8 +172,7 @@ export default function dom( ? `@assign( @template.data(), options.data )` : `options.data || {}`}; ${generator.metaBindings} - ${computations.length && - `@recompute( this._state, this._state, {}, true );`} + ${computations.length && `@recompute( this._state, this._state, {}, true );`} ${options.dev && Array.from(generator.expectedProperties).map( prop => @@ -206,13 +204,13 @@ export default function dom( this._fragment = @create_main_fragment( this._state, this ); if ( options.target ) { - ${generator.hydratable ? - deindent` + ${generator.hydratable + ? deindent` var nodes = @children( options.target ); options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create(); nodes.forEach( @detachNode ); - ` : - deindent` + ` + : deindent` this._fragment.create(); `} this._fragment.mount( options.target, null ); @@ -241,8 +239,7 @@ export default function dom( ${name}.prototype.teardown = ${name}.prototype.destroy = function destroy ( detach ) { this.fire( 'destroy' ); - ${templateProperties.ondestroy && - `@template.ondestroy.call( this );`} + ${templateProperties.ondestroy && `@template.ondestroy.call( this );`} if ( detach !== false ) this._fragment.unmount(); this._fragment.destroy(); @@ -255,7 +252,8 @@ export default function dom( const usedHelpers = new Set(); - let result = builder.toString() + let result = builder + .toString() .replace(/@(\w+)\b/g, (match: string, name: string) => { if (name in shared) { if (options.dev && `${name}Dev` in shared) name = `${name}Dev`; @@ -277,7 +275,9 @@ export default function dom( : name; }); - result = `import { ${names.join(', ')} } from ${stringify(sharedPath)};\n\n` + result; + result = + `import { ${names.join(', ')} } from ${stringify(sharedPath)};\n\n` + + result; } else { usedHelpers.forEach(key => { const str = shared[key]; diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index d9600cea61..9e46a8869b 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -12,7 +12,12 @@ function isElseIf(node: Node) { } function getChildState(parent: State, child = {}) { - return assign({}, parent, { name: null, parentNode: null, parentNodes: 'nodes' }, child || {}); + return assign( + {}, + parent, + { name: null, parentNode: null, parentNodes: 'nodes' }, + child || {} + ); } // Whitespace inside one of these elements will not result in @@ -225,7 +230,11 @@ const preprocessors = { block.addDependencies(dependencies); // special case —