@@ -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
}
@@ -152,30 +152,28 @@ export default function dom(
152
152
const constructorBody = deindent `
153
153
${ options . dev && `this._debugName = '${ debugName } ';` }
154
154
${ options . dev && ! generator . customElement &&
155
- `if ( !options || (!options.target && !options._root) ) throw new Error( "'target' is a required option" );` }
155
+ `if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");` }
156
156
this.options = options;
157
157
${ generator . usesRefs && `this.refs = {};` }
158
158
this._state = ${ templateProperties . data
159
- ? `@assign( @template.data(), options.data )`
159
+ ? `@assign(@template.data(), options.data)`
160
160
: `options.data || {}` } ;
161
161
${ generator . metaBindings }
162
- ${ computations . length && `this._recompute( {}, this._state, {}, true );` }
162
+ ${ computations . length && `this._recompute({}, this._state, {}, true);` }
163
163
${ options . dev &&
164
164
Array . from ( generator . expectedProperties ) . map (
165
165
prop =>
166
- `if ( !( '${ prop } ' in this._state ) ) console.warn( "${ debugName } was created without expected data property '${ prop } '" );`
166
+ `if (!( '${ prop } ' in this._state) ) console.warn("${ debugName } was created without expected data property '${ prop } '");`
167
167
) }
168
168
${ generator . bindingGroups . length &&
169
- `this._bindingGroups = [ ${ Array ( generator . bindingGroups . length )
170
- . fill ( '[]' )
171
- . join ( ', ' ) } ];`}
169
+ `this._bindingGroups = [${ Array ( generator . bindingGroups . length ) . fill ( '[]' ) . join ( ', ' ) } ];` }
172
170
173
171
this._observers = {
174
- pre: Object.create( null ),
175
- post: Object.create( null )
172
+ pre: Object.create(null),
173
+ post: Object.create(null)
176
174
};
177
175
178
- this._handlers = Object.create( null );
176
+ this._handlers = Object.create(null);
179
177
${ templateProperties . ondestroy && `this._handlers.destroy = [@template.ondestroy]` }
180
178
181
179
this._root = options._root || this;
@@ -189,13 +187,13 @@ export default function dom(
189
187
${ css && `this.shadowRoot.innerHTML = \`<style>${ options . dev ? `${ css } \n/*# sourceMappingURL=${ cssMap . toUrl ( ) } */` : css } </style>\`;` }
190
188
` :
191
189
( generator . stylesheet . hasStyles && options . css !== false &&
192
- `if ( !document.getElementById( ' ${ generator . stylesheet . id } -style' ) ) @add_css();` )
190
+ `if (!document.getElementById(" ${ generator . stylesheet . id } -style") ) @add_css();` )
193
191
}
194
192
195
- ${ templateProperties . oncreate && `var oncreate = @template.oncreate.bind( this );` }
193
+ ${ templateProperties . oncreate && `var oncreate = @template.oncreate.bind(this);` }
196
194
197
195
${ ( templateProperties . oncreate || generator . hasComponents || generator . hasComplexBindings || generator . hasIntroTransitions ) && deindent `
198
- if ( !options._root ) {
196
+ if (!options._root) {
199
197
this._oncreate = [${ templateProperties . oncreate && `oncreate` } ];
200
198
${ ( generator . hasComponents || generator . hasComplexBindings ) && `this._beforecreate = [];` }
201
199
${ ( generator . hasComponents || generator . hasIntroTransitions ) && `this._aftercreate = [];` }
@@ -208,22 +206,22 @@ export default function dom(
208
206
209
207
${ generator . slots . size && `this.slots = {};` }
210
208
211
- this._fragment = @create_main_fragment( this._state, this );
209
+ this._fragment = @create_main_fragment(this._state, this);
212
210
213
- if ( options.target ) {
211
+ if (options.target) {
214
212
${ generator . hydratable
215
213
? deindent `
216
- var nodes = @children( options.target );
217
- options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create();
218
- nodes.forEach( @detachNode );
214
+ var nodes = @children(options.target);
215
+ options.hydrate ? this._fragment.claim(nodes) : this._fragment.create();
216
+ nodes.forEach(@detachNode);
219
217
` :
220
218
deindent `
221
- ${ options . dev && `if ( options.hydrate ) throw new Error( ' options.hydrate only works if the component was compiled with the \`hydratable: true\` option' );` }
219
+ ${ options . dev && `if (options.hydrate) throw new Error(" options.hydrate only works if the component was compiled with the \`hydratable: true\` option" );` }
222
220
this._fragment.create();
223
221
` }
224
222
${ generator . customElement ?
225
- `this._mount( options.target, options.anchor || null );` :
226
- `this._fragment.${ block . hasIntroMethod ? 'intro' : 'mount' } ( options.target, options.anchor || null );` }
223
+ `this._mount(options.target, options.anchor || null);` :
224
+ `this._fragment.${ block . hasIntroMethod ? 'intro' : 'mount' } (options.target, options.anchor || null);` }
227
225
228
226
${ ( generator . hasComponents || generator . hasComplexBindings || templateProperties . oncreate || generator . hasIntroTransitions ) && deindent `
229
227
${ generator . hasComponents && `this._lock = true;` }
@@ -266,13 +264,13 @@ export default function dom(
266
264
});
267
265
}` }
268
266
269
- attributeChangedCallback ( attr, oldValue, newValue ) {
267
+ attributeChangedCallback( attr, oldValue, newValue) {
270
268
this.set({ [attr]: newValue });
271
269
}
272
270
}
273
271
274
- customElements.define(' ${ generator . tag } ' , ${ name } );
275
- @assign( ${ prototypeBase } , ${ proto } , {
272
+ customElements.define(" ${ generator . tag } " , ${ name } );
273
+ @assign(${ prototypeBase } , ${ proto } , {
276
274
_mount(target, anchor) {
277
275
this._fragment.${ block . hasIntroMethod ? 'intro' : 'mount' } (this.shadowRoot, null);
278
276
target.insertBefore(this, anchor);
@@ -285,31 +283,31 @@ export default function dom(
285
283
` ) ;
286
284
} else {
287
285
builder . addBlock ( deindent `
288
- function ${ name } ( options ) {
286
+ function ${ name } ( options) {
289
287
${ constructorBody }
290
288
}
291
289
292
- @assign( ${ prototypeBase } , ${ proto } );
290
+ @assign(${ prototypeBase } , ${ proto } );
293
291
` ) ;
294
292
}
295
293
296
294
builder . addBlock ( deindent `
297
295
${ options . dev && deindent `
298
- ${ name } .prototype._checkReadOnly = function _checkReadOnly ( newState ) {
296
+ ${ name } .prototype._checkReadOnly = function _checkReadOnly( newState) {
299
297
${ Array . from ( generator . readonly ) . map (
300
298
prop =>
301
- `if ( '${ prop } ' in newState && !this._updatingReadonlyProperty ) throw new Error( "${ debugName } : Cannot set read-only property '${ prop } '" );`
299
+ `if ('${ prop } ' in newState && !this._updatingReadonlyProperty) throw new Error("${ debugName } : Cannot set read-only property '${ prop } '");`
302
300
) }
303
301
};
304
302
` }
305
303
306
304
${ computations . length ? deindent `
307
- ${ name } .prototype._recompute = function _recompute ( changed, state, oldState, isInitial ) {
305
+ ${ name } .prototype._recompute = function _recompute( changed, state, oldState, isInitial) {
308
306
${ computationBuilder }
309
307
}
310
308
` : ( ! sharedPath && `${ name } .prototype._recompute = @noop;` ) }
311
309
312
- ${ templateProperties . setup && `@template.setup( ${ name } );` }
310
+ ${ templateProperties . setup && `@template.setup(${ name } );` }
313
311
` ) ;
314
312
315
313
const usedHelpers = new Set ( ) ;
@@ -342,7 +340,7 @@ export default function dom(
342
340
343
341
else if ( format === 'cjs' ) {
344
342
const SHARED = '__shared' ;
345
- let requires = `var ${ SHARED } = require( ${ JSON . stringify ( sharedPath ) } );` ;
343
+ let requires = `var ${ SHARED } = require(${ JSON . stringify ( sharedPath ) } );` ;
346
344
used . forEach ( name => {
347
345
const alias = generator . alias ( name ) ;
348
346
requires += `\nvar ${ alias } = ${ SHARED } .${ name } ;` ;
@@ -392,9 +390,7 @@ export default function dom(
392
390
// special case
393
391
const global = `_svelteTransitionManager` ;
394
392
395
- result += `\n\nvar ${ generator . alias (
396
- 'transitionManager'
397
- ) } = window.${ global } || ( window.${ global } = ${ code } );`;
393
+ result += `\n\nvar ${ generator . alias ( 'transitionManager' ) } = window.${ global } || (window.${ global } = ${ code } );` ;
398
394
} else {
399
395
const alias = generator . alias ( expression . id . name ) ;
400
396
if ( alias !== expression . id . name )
0 commit comments