Skip to content

Commit dc48ae6

Browse files
authoredSep 3, 2017
Merge pull request #813 from sveltejs/tidy-up
more consistent style for generated code
2 parents 0e80248 + e993ae0 commit dc48ae6

File tree

62 files changed

+1357
-1388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1357
-1388
lines changed
 

‎src/generators/Generator.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ export default class Generator {
210210
}
211211

212212
if (globalWhitelist.has(name)) {
213-
code.prependRight(node.start, `( '${name}' in state ? state.`);
213+
code.prependRight(node.start, `('${name}' in state ? state.`);
214214
code.appendLeft(
215215
node.object ? node.object.end : node.end,
216-
` : ${name} )`
216+
` : ${name})`
217217
);
218218
} else {
219219
code.prependRight(node.start, `state.`);
@@ -337,7 +337,7 @@ export default class Generator {
337337

338338
if (defaultImport) {
339339
statements.push(
340-
`${name} = ( ${name} && ${name}.__esModule ) ? ${name}['default'] : ${name};`
340+
`${name} = (${name} && ${name}.__esModule) ? ${name}['default'] : ${name};`
341341
);
342342
}
343343
});
@@ -629,8 +629,8 @@ export default class Generator {
629629
// user code gets wrapped in an IIFE
630630
if (js.content.body.length) {
631631
const prefix = hasDefaultExport
632-
? `var ${this.alias('template')} = (function () {`
633-
: `(function () {`;
632+
? `var ${this.alias('template')} = (function() {`
633+
: `(function() {`;
634634
this.code
635635
.prependRight(js.content.start, prefix)
636636
.appendLeft(js.content.end, '}());');

‎src/generators/dom/Block.ts

+19-21
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default class Block {
135135
this.mount(name, parentNode);
136136

137137
if (isToplevel) {
138-
this.builders.unmount.addLine(`@detachNode( ${name} );`);
138+
this.builders.unmount.addLine(`@detachNode(${name});`);
139139
}
140140
}
141141

@@ -180,9 +180,9 @@ export default class Block {
180180

181181
mount(name: string, parentNode: string) {
182182
if (parentNode) {
183-
this.builders.mount.addLine(`@appendNode( ${name}, ${parentNode} );`);
183+
this.builders.mount.addLine(`@appendNode(${name}, ${parentNode});`);
184184
} else {
185-
this.builders.mount.addLine(`@insertNode( ${name}, #target, anchor );`);
185+
this.builders.mount.addLine(`@insertNode(${name}, #target, anchor);`);
186186
}
187187
}
188188

@@ -225,7 +225,7 @@ export default class Block {
225225
properties.addBlock(`create: @noop,`);
226226
} else {
227227
properties.addBlock(deindent`
228-
create: function () {
228+
create: function() {
229229
${this.builders.create}
230230
${!this.builders.hydrate.isEmpty() && `this.hydrate();`}
231231
},
@@ -237,7 +237,7 @@ export default class Block {
237237
properties.addBlock(`claim: @noop,`);
238238
} else {
239239
properties.addBlock(deindent`
240-
claim: function ( nodes ) {
240+
claim: function(nodes) {
241241
${this.builders.claim}
242242
${!this.builders.hydrate.isEmpty() && `this.hydrate();`}
243243
},
@@ -247,7 +247,7 @@ export default class Block {
247247

248248
if (!this.builders.hydrate.isEmpty()) {
249249
properties.addBlock(deindent`
250-
hydrate: function ( nodes ) {
250+
hydrate: function(nodes) {
251251
${this.builders.hydrate}
252252
},
253253
`);
@@ -257,7 +257,7 @@ export default class Block {
257257
properties.addBlock(`mount: @noop,`);
258258
} else {
259259
properties.addBlock(deindent`
260-
mount: function ( #target, anchor ) {
260+
mount: function(#target, anchor) {
261261
${this.builders.mount}
262262
},
263263
`);
@@ -268,7 +268,7 @@ export default class Block {
268268
properties.addBlock(`update: @noop,`);
269269
} else {
270270
properties.addBlock(deindent`
271-
update: function ( changed, ${this.params.join(', ')} ) {
271+
update: function(changed, ${this.params.join(', ')}) {
272272
${this.builders.update}
273273
},
274274
`);
@@ -278,20 +278,20 @@ export default class Block {
278278
if (this.hasIntroMethod) {
279279
if (hasIntros) {
280280
properties.addBlock(deindent`
281-
intro: function ( #target, anchor ) {
282-
if ( ${introing} ) return;
281+
intro: function(#target, anchor) {
282+
if (${introing}) return;
283283
${introing} = true;
284284
${hasOutros && `${outroing} = false;`}
285285
286286
${this.builders.intro}
287287
288-
this.mount( #target, anchor );
288+
this.mount(#target, anchor);
289289
},
290290
`);
291291
} else {
292292
properties.addBlock(deindent`
293-
intro: function ( #target, anchor ) {
294-
this.mount( #target, anchor );
293+
intro: function(#target, anchor) {
294+
this.mount(#target, anchor);
295295
},
296296
`);
297297
}
@@ -300,8 +300,8 @@ export default class Block {
300300
if (this.hasOutroMethod) {
301301
if (hasOutros) {
302302
properties.addBlock(deindent`
303-
outro: function ( ${this.alias('outrocallback')} ) {
304-
if ( ${outroing} ) return;
303+
outro: function(${this.alias('outrocallback')}) {
304+
if (${outroing}) return;
305305
${outroing} = true;
306306
${hasIntros && `${introing} = false;`}
307307
@@ -312,7 +312,7 @@ export default class Block {
312312
`);
313313
} else {
314314
properties.addBlock(deindent`
315-
outro: function ( outrocallback ) {
315+
outro: function(outrocallback) {
316316
outrocallback();
317317
},
318318
`);
@@ -323,7 +323,7 @@ export default class Block {
323323
properties.addBlock(`unmount: @noop,`);
324324
} else {
325325
properties.addBlock(deindent`
326-
unmount: function () {
326+
unmount: function() {
327327
${this.builders.unmount}
328328
},
329329
`);
@@ -333,16 +333,14 @@ export default class Block {
333333
properties.addBlock(`destroy: @noop`);
334334
} else {
335335
properties.addBlock(deindent`
336-
destroy: function () {
336+
destroy: function() {
337337
${this.builders.destroy}
338338
}
339339
`);
340340
}
341341

342342
return deindent`
343-
function ${this.name} ( ${this.params.join(', ')}, #component${this.key
344-
? `, ${localKey}`
345-
: ''} ) {
343+
function ${this.name}(${this.params.join(', ')}, #component${this.key ? `, ${localKey}` : ''}) {
346344
${this.variables.size > 0 &&
347345
`var ${Array.from(this.variables.keys())
348346
.map(key => {

0 commit comments

Comments
 (0)