Skip to content

Commit 240f541

Browse files
authoredNov 9, 2020
Curly brace cleanup and enforcement (#5647)
1 parent 9745b61 commit 240f541

16 files changed

+31
-85
lines changed
 

‎package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@rollup/plugin-sucrase": "^3.0.0",
6464
"@rollup/plugin-typescript": "^2.0.1",
6565
"@rollup/plugin-virtual": "^2.0.0",
66-
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.5.0",
66+
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.6.0",
6767
"@types/mocha": "^7.0.0",
6868
"@types/node": "^8.10.53",
6969
"@typescript-eslint/eslint-plugin": "^3.0.2",

‎src/compiler/compile/Component.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,13 @@ export default class Component {
267267
this.helpers.set(name, alias);
268268
node.name = alias.name;
269269
}
270-
}
271-
272-
else if (node.name[0] !== '#' && !is_valid(node.name)) {
270+
} else if (node.name[0] !== '#' && !is_valid(node.name)) {
273271
// this hack allows x`foo.${bar}` where bar could be invalid
274272
const literal: Literal = { type: 'Literal', value: node.name };
275273

276274
if (parent.type === 'Property' && key === 'key') {
277275
parent.key = literal;
278-
}
279-
280-
else if (parent.type === 'MemberExpression' && key === 'property') {
276+
} else if (parent.type === 'MemberExpression' && key === 'property') {
281277
parent.property = literal;
282278
parent.computed = true;
283279
}

‎src/compiler/compile/css/Selector.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,17 @@ function block_might_apply_to_node(block: Block, node: Element): BlockAppliesToN
248248

249249
if (selector.type === 'ClassSelector') {
250250
if (!attribute_matches(node, 'class', name, '~=', false) && !node.classes.some(c => c.name === name)) return BlockAppliesToNode.NotPossible;
251-
}
252-
253-
else if (selector.type === 'IdSelector') {
251+
} else if (selector.type === 'IdSelector') {
254252
if (!attribute_matches(node, 'id', name, '=', false)) return BlockAppliesToNode.NotPossible;
255-
}
256-
257-
else if (selector.type === 'AttributeSelector') {
253+
} else if (selector.type === 'AttributeSelector') {
258254
if (
259255
!(whitelist_attribute_selector.has(node.name.toLowerCase()) && whitelist_attribute_selector.get(node.name.toLowerCase()).has(selector.name.name.toLowerCase())) &&
260256
!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags)) {
261257
return BlockAppliesToNode.NotPossible;
262258
}
263-
}
264-
265-
else if (selector.type === 'TypeSelector') {
259+
} else if (selector.type === 'TypeSelector') {
266260
if (node.name.toLowerCase() !== name.toLowerCase() && name !== '*') return BlockAppliesToNode.NotPossible;
267-
}
268-
269-
else {
261+
} else {
270262
return BlockAppliesToNode.UnknownSelectorType;
271263
}
272264
}

‎src/compiler/compile/css/Stylesheet.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ class Atrule {
167167
this.children.forEach(child => {
168168
child.apply(node);
169169
});
170-
}
171-
172-
else if (is_keyframes_node(this.node)) {
170+
} else if (is_keyframes_node(this.node)) {
173171
this.children.forEach((rule: Rule) => {
174172
rule.selectors.forEach(selector => {
175173
selector.used = true;

‎src/compiler/compile/css/gather_possible_values.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ export const UNKNOWN = {};
55
export function gather_possible_values(node: Node, set: Set<string|{}>) {
66
if (node.type === 'Literal') {
77
set.add(node.value);
8-
}
9-
10-
else if (node.type === 'ConditionalExpression') {
8+
} else if (node.type === 'ConditionalExpression') {
119
gather_possible_values(node.consequent, set);
1210
gather_possible_values(node.alternate, set);
13-
}
14-
15-
else {
11+
} else {
1612
set.add(UNKNOWN);
1713
}
1814
}

‎src/compiler/compile/nodes/Attribute.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ export default class Attribute extends Node {
3838
this.chunks = null;
3939

4040
this.is_static = false;
41-
}
42-
43-
else {
41+
} else {
4442
this.name = info.name;
4543
this.is_true = info.value === true;
4644
this.is_static = true;

‎src/compiler/compile/nodes/Body.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ export default class Body extends Node {
1313
info.attributes.forEach(node => {
1414
if (node.type === 'EventHandler') {
1515
this.handlers.push(new EventHandler(component, this, scope, node));
16-
}
17-
18-
else {
16+
} else {
1917
// TODO there shouldn't be anything else here...
2018
}
2119
});

‎src/compiler/compile/nodes/Window.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export default class Window extends Node {
2828
info.attributes.forEach(node => {
2929
if (node.type === 'EventHandler') {
3030
this.handlers.push(new EventHandler(component, this, scope, node));
31-
}
32-
33-
else if (node.type === 'Binding') {
31+
} else if (node.type === 'Binding') {
3432
if (node.expression.type !== 'Identifier') {
3533
const { parts } = flatten_reference(node.expression);
3634

@@ -64,13 +62,9 @@ export default class Window extends Node {
6462
}
6563

6664
this.bindings.push(new Binding(component, this, scope, node));
67-
}
68-
69-
else if (node.type === 'Action') {
65+
} else if (node.type === 'Action') {
7066
this.actions.push(new Action(component, this, scope, node));
71-
}
72-
73-
else {
67+
} else {
7468
// TODO there shouldn't be anything else here...
7569
}
7670
});

‎src/compiler/compile/nodes/shared/Expression.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,13 @@ export default class Expression {
261261
hoistable: true,
262262
referenced: true
263263
});
264-
}
265-
266-
else if (contextual_dependencies.size === 0) {
264+
} else if (contextual_dependencies.size === 0) {
267265
// function can be hoisted inside the component init
268266
component.partly_hoisted.push(declaration);
269267

270268
block.renderer.add_to_context(id.name);
271269
this.replace(block.renderer.reference(id));
272-
}
273-
274-
else {
270+
} else {
275271
// we need a combo block/init recipe
276272
const deps = Array.from(contextual_dependencies);
277273
const function_expression = node as FunctionExpression;

‎src/compiler/compile/render_dom/wrappers/Element/StyleAttribute.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ function get_style_value(chunks: Array<Text | Expression>) {
164164

165165
break;
166166
}
167-
}
168-
169-
else {
167+
} else {
170168
value.push(chunk);
171169
}
172170
}

‎src/compiler/compile/render_dom/wrappers/Element/index.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,7 @@ export default class ElementWrapper extends Wrapper {
745745
}
746746

747747
block.chunks.destroy.push(b`if (detaching && ${name}) ${name}.end();`);
748-
}
749-
750-
else {
748+
} else {
751749
const intro_name = intro && block.get_unique_name(`${this.var.name}_intro`);
752750
const outro_name = outro && block.get_unique_name(`${this.var.name}_outro`);
753751

@@ -920,22 +918,16 @@ function to_html(wrappers: Array<ElementWrapper | TextWrapper | MustacheTagWrapp
920918
.replace(/\\/g, '\\\\')
921919
.replace(/`/g, '\\`')
922920
.replace(/\$/g, '\\$');
923-
}
924-
925-
else if (wrapper instanceof MustacheTagWrapper || wrapper instanceof RawMustacheTagWrapper) {
921+
} else if (wrapper instanceof MustacheTagWrapper || wrapper instanceof RawMustacheTagWrapper) {
926922
literal.quasis.push(state.quasi);
927923
literal.expressions.push(wrapper.node.expression.manipulate(block));
928924
state.quasi = {
929925
type: 'TemplateElement',
930926
value: { raw: '' }
931927
};
932-
}
933-
934-
else if (wrapper.node.name === 'noscript') {
928+
} else if (wrapper.node.name === 'noscript') {
935929
// do nothing
936-
}
937-
938-
else {
930+
} else {
939931
// element
940932
state.quasi.value.raw += `<${wrapper.node.name}`;
941933

‎src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export default class RawMustacheTagWrapper extends Tag {
3636
);
3737

3838
block.chunks.mount.push(insert(init));
39-
}
40-
41-
else {
39+
} else {
4240
const needs_anchor = in_head || (this.next ? !this.next.is_dom_node() : (!this.parent || !this.parent.is_dom_node()));
4341

4442
const html_tag = block.get_unique_name('html_tag');

‎src/compiler/parse/state/mustache.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,8 @@ export default function mustache(parser: Parser) {
142142
};
143143

144144
parser.stack.push(block.else.children[0]);
145-
}
146-
147-
// :else
148-
else {
145+
} else {
146+
// :else
149147
const block = parser.current();
150148
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
151149
parser.error({

‎src/runtime/internal/keyed_each.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,13 @@ export function update_keyed_each(old_blocks, dirty, get_key, dynamic, ctx, list
7373
next = new_block.first;
7474
o--;
7575
n--;
76-
}
77-
78-
else if (!new_lookup.has(old_key)) {
76+
} else if (!new_lookup.has(old_key)) {
7977
// remove old block
8078
destroy(old_block, lookup);
8179
o--;
82-
}
83-
84-
else if (!lookup.has(new_key) || will_move.has(new_key)) {
80+
} else if (!lookup.has(new_key) || will_move.has(new_key)) {
8581
insert(new_block);
86-
}
87-
88-
else if (did_move.has(old_key)) {
82+
} else if (did_move.has(old_key)) {
8983
o--;
9084

9185
} else if (deltas.get(new_key) > deltas.get(old_key)) {

‎src/runtime/internal/transitions.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline
318318
}
319319

320320
running_program = null;
321-
}
322-
323-
else if (now >= running_program.start) {
321+
} else if (now >= running_program.start) {
324322
const p = now - running_program.start;
325323
t = running_program.a + running_program.d * easing(p / running_program.duration);
326324
tick(t, 1 - t);

0 commit comments

Comments
 (0)