@@ -91,9 +91,9 @@ export default function dom(
91
91
92
92
const condition = `isInitial || ${ deps . map ( dep => `changed.${ dep } ` ) . join ( ' || ' ) } ` ;
93
93
94
- const statement = `if ( @differs( ( state.${ key } = @template.computed.${ key } ( ${ deps
94
+ const statement = `if (@differs(( state.${ key } = @template.computed.${ key } (${ deps
95
95
. map ( dep => `state.${ dep } ` )
96
- . join ( ', ' ) } ) ), oldState.${ key } ) ) changed.${ key } = true;`;
96
+ . join ( ', ' ) } ) ), oldState.${ key } ) ) changed.${ key } = true;`;
97
97
98
98
computationBuilder . addConditional ( condition , statement ) ;
99
99
} ) ;
@@ -105,8 +105,8 @@ export default function dom(
105
105
106
106
if ( generator . needsEncapsulateHelper ) {
107
107
builder . addBlock ( deindent `
108
- function @encapsulateStyles ( node ) {
109
- @setAttribute( node, ' ${ generator . stylesheet . id } ', '' );
108
+ function @encapsulateStyles( node) {
109
+ @setAttribute(node, " ${ generator . stylesheet . id } ", "" );
110
110
}
111
111
` ) ;
112
112
}
@@ -118,11 +118,11 @@ export default function dom(
118
118
119
119
if ( styles && generator . options . css !== false && ! generator . customElement ) {
120
120
builder . addBlock ( deindent `
121
- function @add_css () {
122
- var style = @createElement( ' style' );
121
+ function @add_css() {
122
+ var style = @createElement(" style" );
123
123
style.id = '${ generator . stylesheet . id } -style';
124
124
style.textContent = ${ styles } ;
125
- @appendNode( style, document.head );
125
+ @appendNode(style, document.head);
126
126
}
127
127
` ) ;
128
128
}
@@ -149,30 +149,28 @@ export default function dom(
149
149
150
150
const constructorBody = deindent `
151
151
${ options . dev && ! generator . customElement &&
152
- `if ( !options || (!options.target && !options._root) ) throw new Error( "'target' is a required option" );` }
152
+ `if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");` }
153
153
this.options = options;
154
154
${ generator . usesRefs && `this.refs = {};` }
155
155
this._state = ${ templateProperties . data
156
- ? `@assign( @template.data(), options.data )`
156
+ ? `@assign(@template.data(), options.data)`
157
157
: `options.data || {}` } ;
158
158
${ generator . metaBindings }
159
- ${ computations . length && `this._recompute( {}, this._state, {}, true );` }
159
+ ${ computations . length && `this._recompute({}, this._state, {}, true);` }
160
160
${ options . dev &&
161
161
Array . from ( generator . expectedProperties ) . map (
162
162
prop =>
163
- `if ( !( '${ prop } ' in this._state ) ) console.warn( "Component was created without expected data property '${ prop } '" );`
163
+ `if (!( '${ prop } ' in this._state) ) console.warn("Component was created without expected data property '${ prop } '");`
164
164
) }
165
165
${ generator . bindingGroups . length &&
166
- `this._bindingGroups = [ ${ Array ( generator . bindingGroups . length )
167
- . fill ( '[]' )
168
- . join ( ', ' ) } ];`}
166
+ `this._bindingGroups = [${ Array ( generator . bindingGroups . length ) . fill ( '[]' ) . join ( ', ' ) } ];` }
169
167
170
168
this._observers = {
171
- pre: Object.create( null ),
172
- post: Object.create( null )
169
+ pre: Object.create(null),
170
+ post: Object.create(null)
173
171
};
174
172
175
- this._handlers = Object.create( null );
173
+ this._handlers = Object.create(null);
176
174
${ templateProperties . ondestroy && `this._handlers.destroy = [@template.ondestroy]` }
177
175
178
176
this._root = options._root || this;
@@ -186,13 +184,13 @@ export default function dom(
186
184
${ css && `this.shadowRoot.innerHTML = \`<style>${ options . dev ? `${ css } \n/*# sourceMappingURL=${ cssMap . toUrl ( ) } */` : css } </style>\`;` }
187
185
` :
188
186
( generator . stylesheet . hasStyles && options . css !== false &&
189
- `if ( !document.getElementById( ' ${ generator . stylesheet . id } -style' ) ) @add_css();` )
187
+ `if (!document.getElementById(" ${ generator . stylesheet . id } -style") ) @add_css();` )
190
188
}
191
189
192
- ${ templateProperties . oncreate && `var oncreate = @template.oncreate.bind( this );` }
190
+ ${ templateProperties . oncreate && `var oncreate = @template.oncreate.bind(this);` }
193
191
194
192
${ ( templateProperties . oncreate || generator . hasComponents || generator . hasComplexBindings || generator . hasIntroTransitions ) && deindent `
195
- if ( !options._root ) {
193
+ if (!options._root) {
196
194
this._oncreate = [${ templateProperties . oncreate && `oncreate` } ];
197
195
${ ( generator . hasComponents || generator . hasComplexBindings ) && `this._beforecreate = [];` }
198
196
${ ( generator . hasComponents || generator . hasIntroTransitions ) && `this._aftercreate = [];` }
@@ -205,22 +203,22 @@ export default function dom(
205
203
206
204
${ generator . slots . size && `this.slots = {};` }
207
205
208
- this._fragment = @create_main_fragment( this._state, this );
206
+ this._fragment = @create_main_fragment(this._state, this);
209
207
210
- if ( options.target ) {
208
+ if (options.target) {
211
209
${ generator . hydratable
212
210
? deindent `
213
- var nodes = @children( options.target );
214
- options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create();
215
- nodes.forEach( @detachNode );
211
+ var nodes = @children(options.target);
212
+ options.hydrate ? this._fragment.claim(nodes) : this._fragment.create();
213
+ nodes.forEach(@detachNode);
216
214
` :
217
215
deindent `
218
- ${ options . dev && `if ( options.hydrate ) throw new Error( ' options.hydrate only works if the component was compiled with the \`hydratable: true\` option' );` }
216
+ ${ options . dev && `if (options.hydrate) throw new Error(" options.hydrate only works if the component was compiled with the \`hydratable: true\` option" );` }
219
217
this._fragment.create();
220
218
` }
221
219
${ generator . customElement ?
222
- `this._mount( options.target, options.anchor || null );` :
223
- `this._fragment.${ block . hasIntroMethod ? 'intro' : 'mount' } ( options.target, options.anchor || null );` }
220
+ `this._mount(options.target, options.anchor || null);` :
221
+ `this._fragment.${ block . hasIntroMethod ? 'intro' : 'mount' } (options.target, options.anchor || null);` }
224
222
225
223
${ ( generator . hasComponents || generator . hasComplexBindings || templateProperties . oncreate || generator . hasIntroTransitions ) && deindent `
226
224
${ generator . hasComponents && `this._lock = true;` }
@@ -263,13 +261,13 @@ export default function dom(
263
261
});
264
262
}` }
265
263
266
- attributeChangedCallback ( attr, oldValue, newValue ) {
264
+ attributeChangedCallback( attr, oldValue, newValue) {
267
265
this.set({ [attr]: newValue });
268
266
}
269
267
}
270
268
271
- customElements.define(' ${ generator . tag } ' , ${ name } );
272
- @assign( ${ prototypeBase } , ${ proto } , {
269
+ customElements.define(" ${ generator . tag } " , ${ name } );
270
+ @assign(${ prototypeBase } , ${ proto } , {
273
271
_mount(target, anchor) {
274
272
this._fragment.${ block . hasIntroMethod ? 'intro' : 'mount' } (this.shadowRoot, null);
275
273
target.insertBefore(this, anchor);
@@ -282,32 +280,32 @@ export default function dom(
282
280
` ) ;
283
281
} else {
284
282
builder . addBlock ( deindent `
285
- function ${ name } ( options ) {
283
+ function ${ name } ( options) {
286
284
${ constructorBody }
287
285
}
288
286
289
- @assign( ${ prototypeBase } , ${ proto } );
287
+ @assign(${ prototypeBase } , ${ proto } );
290
288
` ) ;
291
289
}
292
290
293
291
// TODO deprecate component.teardown()
294
292
builder . addBlock ( deindent `
295
293
${ options . dev && deindent `
296
- ${ name } .prototype._checkReadOnly = function _checkReadOnly ( newState ) {
294
+ ${ name } .prototype._checkReadOnly = function _checkReadOnly( newState) {
297
295
${ Array . from ( generator . readonly ) . map (
298
296
prop =>
299
- `if ( '${ prop } ' in newState && !this._updatingReadonlyProperty ) throw new Error( "Cannot set read-only property '${ prop } '" );`
297
+ `if ('${ prop } ' in newState && !this._updatingReadonlyProperty) throw new Error("Cannot set read-only property '${ prop } '");`
300
298
) }
301
299
};
302
300
` }
303
301
304
302
${ computations . length ? deindent `
305
- ${ name } .prototype._recompute = function _recompute ( changed, state, oldState, isInitial ) {
303
+ ${ name } .prototype._recompute = function _recompute( changed, state, oldState, isInitial) {
306
304
${ computationBuilder }
307
305
}
308
306
` : ( ! sharedPath && `${ name } .prototype._recompute = @noop;` ) }
309
307
310
- ${ templateProperties . setup && `@template.setup( ${ name } );` }
308
+ ${ templateProperties . setup && `@template.setup(${ name } );` }
311
309
` ) ;
312
310
313
311
const usedHelpers = new Set ( ) ;
@@ -340,7 +338,7 @@ export default function dom(
340
338
341
339
else if ( format === 'cjs' ) {
342
340
const SHARED = '__shared' ;
343
- let requires = `var ${ SHARED } = require( ${ JSON . stringify ( sharedPath ) } );` ;
341
+ let requires = `var ${ SHARED } = require(${ JSON . stringify ( sharedPath ) } );` ;
344
342
used . forEach ( name => {
345
343
const alias = generator . alias ( name ) ;
346
344
requires += `\nvar ${ alias } = ${ SHARED } .${ name } ;` ;
@@ -390,9 +388,7 @@ export default function dom(
390
388
// special case
391
389
const global = `_svelteTransitionManager` ;
392
390
393
- result += `\n\nvar ${ generator . alias (
394
- 'transitionManager'
395
- ) } = window.${ global } || ( window.${ global } = ${ code } );`;
391
+ result += `\n\nvar ${ generator . alias ( 'transitionManager' ) } = window.${ global } || (window.${ global } = ${ code } );` ;
396
392
} else {
397
393
const alias = generator . alias ( expression . id . name ) ;
398
394
if ( alias !== expression . id . name )
0 commit comments