diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 656b004403..a3108aeabc 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -163,7 +163,7 @@ export default class Component { if (!compile_options.customElement) this.stylesheet.reify(); - this.stylesheet.warnOnUnusedSelectors(this); + this.stylesheet.warn_on_unused_selectors(this); } add_var(variable: Var) { diff --git a/src/compile/css/Selector.ts b/src/compile/css/Selector.ts index 3a631f55e1..c530d1f309 100644 --- a/src/compile/css/Selector.ts +++ b/src/compile/css/Selector.ts @@ -210,7 +210,7 @@ const operators = { '*=': (value: string, flags: string) => new RegExp(value, flags) }; -function attribute_matches(node: Node, name: string, expected_value: string, operator: string, caseInsensitive: boolean) { +function attribute_matches(node: Node, name: string, expected_value: string, operator: string, case_insensitive: boolean) { const spread = node.attributes.find(attr => attr.type === 'Spread'); if (spread) return true; @@ -220,7 +220,7 @@ function attribute_matches(node: Node, name: string, expected_value: string, ope if (attr.chunks.length > 1) return true; if (!expected_value) return true; - const pattern = operators[operator](expected_value, caseInsensitive ? 'i' : ''); + const pattern = operators[operator](expected_value, case_insensitive ? 'i' : ''); const value = attr.chunks[0]; if (!value) return false; diff --git a/src/compile/css/Stylesheet.ts b/src/compile/css/Stylesheet.ts index 6e72a86d28..f2b12ab611 100644 --- a/src/compile/css/Stylesheet.ts +++ b/src/compile/css/Stylesheet.ts @@ -391,7 +391,7 @@ export default class Stylesheet { }); } - warnOnUnusedSelectors(component: Component) { + warn_on_unused_selectors(component: Component) { this.children.forEach(child => { child.warn_on_unused_selector((selector: Selector) => { component.warn(selector.node, { diff --git a/src/compile/index.ts b/src/compile/index.ts index 35816fdc7a..c3c3ed5912 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -1,8 +1,8 @@ import { assign } from '../internal'; import Stats from '../Stats'; import parse from '../parse/index'; -import renderDOM from './render-dom/index'; -import renderSSR from './render-ssr/index'; +import render_dom from './render-dom/index'; +import render_ssr from './render-ssr/index'; import { CompileOptions, Ast, Warning } from '../interfaces'; import Component from './Component'; import fuzzymatch from '../utils/fuzzymatch'; @@ -100,8 +100,8 @@ export default function compile(source: string, options: CompileOptions = {}) { const js = options.generate === false ? null : options.generate === 'ssr' - ? renderSSR(component, options) - : renderDOM(component, options); + ? render_ssr(component, options) + : render_dom(component, options); return component.generate(js); } \ No newline at end of file diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index 399c9aae3a..0a4f4af848 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -27,8 +27,8 @@ export default class Slot extends Element { }); } - const slotName = attr.value[0].data; - if (slotName === 'default') { + const slot_name = attr.value[0].data; + if (slot_name === 'default') { component.error(attr, { code: `invalid-slot-name`, message: `default is a reserved word — it cannot be used as a slot name` @@ -39,11 +39,11 @@ export default class Slot extends Element { // TODO should duplicate slots be disallowed? Feels like it's more likely to be a // bug than anything. Perhaps it should be a warning - // if (validator.slots.has(slotName)) { - // validator.error(`duplicate '${slotName}' element`, nameAttribute.start); + // if (validator.slots.has(slot_name)) { + // validator.error(`duplicate '${slot_name}' element`, nameAttribute.start); // } - // validator.slots.add(slotName); + // validator.slots.add(slot_name); }); // if (node.attributes.length === 0) && validator.slots.has('default')) { diff --git a/src/compile/nodes/shared/Expression.ts b/src/compile/nodes/shared/Expression.ts index 8eb55dda31..4d8e831078 100644 --- a/src/compile/nodes/shared/Expression.ts +++ b/src/compile/nodes/shared/Expression.ts @@ -13,7 +13,7 @@ import get_object from '../../utils/get_object'; import { nodes_match } from '../../../utils/nodes_match'; import Block from '../../render-dom/Block'; -const binaryOperators: Record = { +const binary_operators: Record = { '**': 15, '*': 14, '/': 14, @@ -38,7 +38,7 @@ const binaryOperators: Record = { '|': 7 }; -const logicalOperators: Record = { +const logical_operators: Record = { '&&': 6, '||': 5 }; @@ -52,8 +52,8 @@ const precedence: Record number> = { CallExpression: () => 19, UpdateExpression: () => 17, UnaryExpression: () => 16, - BinaryExpression: (node: Node) => binaryOperators[node.operator], - LogicalExpression: (node: Node) => logicalOperators[node.operator], + BinaryExpression: (node: Node) => binary_operators[node.operator], + LogicalExpression: (node: Node) => logical_operators[node.operator], ConditionalExpression: () => 4, AssignmentExpression: () => 3, YieldExpression: () => 2, diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 31bbc436d9..5b37ac031c 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -35,7 +35,7 @@ export default function dom( const css = component.stylesheet.render(options.filename, !options.customElement); const styles = component.stylesheet.has_styles && stringify(options.dev ? `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */` : - css.code, { onlyEscapeAtSymbol: true }); + css.code, { only_escape_at_symbol: true }); if (styles && component.compile_options.css !== false && !options.customElement) { builder.add_block(deindent` @@ -417,7 +417,7 @@ export default function dom( constructor(options) { super(); - ${css.code && `this.shadowRoot.innerHTML = \`\`;`} + ${css.code && `this.shadowRoot.innerHTML = \`\`;`} @init(this, { target: this.shadowRoot }, ${definition}, create_fragment, ${not_equal}, ${prop_names}); diff --git a/src/compile/render-dom/wrappers/Element/Binding.ts b/src/compile/render-dom/wrappers/Element/Binding.ts index 64b25377f6..8657a1b054 100644 --- a/src/compile/render-dom/wrappers/Element/Binding.ts +++ b/src/compile/render-dom/wrappers/Element/Binding.ts @@ -91,8 +91,8 @@ export default class BindingWrapper { this.node.expression.dependencies.forEach((prop: string) => { const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(prop); if (indirect_dependencies) { - indirect_dependencies.forEach(indirectDependency => { - dependencies.add(indirectDependency); + indirect_dependencies.forEach(indirect_dependency => { + dependencies.add(indirect_dependency); }); } }); @@ -127,14 +127,14 @@ export default class BindingWrapper { // special cases switch (this.node.name) { case 'group': - const bindingGroup = get_binding_group(parent.renderer, this.node.expression.node); + const binding_group = get_binding_group(parent.renderer, this.node.expression.node); block.builders.hydrate.add_line( - `ctx.$$binding_groups[${bindingGroup}].push(${parent.var});` + `ctx.$$binding_groups[${binding_group}].push(${parent.var});` ); block.builders.destroy.add_line( - `ctx.$$binding_groups[${bindingGroup}].splice(ctx.$$binding_groups[${bindingGroup}].indexOf(${parent.var}), 1);` + `ctx.$$binding_groups[${binding_group}].splice(ctx.$$binding_groups[${binding_group}].indexOf(${parent.var}), 1);` ); break; @@ -295,9 +295,9 @@ function get_value_from_dom( // if (name === 'group') { - const bindingGroup = get_binding_group(renderer, binding.node.expression.node); + const binding_group = get_binding_group(renderer, binding.node.expression.node); if (type === 'checkbox') { - return `@get_binding_group_value($$binding_groups[${bindingGroup}])`; + return `@get_binding_group_value($$binding_groups[${binding_group}])`; } return `this.__value`; diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index d946d3e056..d54a66dffa 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -777,8 +777,8 @@ export default class ElementWrapper extends Wrapper { } add_classes(block: Block) { - this.node.classes.forEach(classDir => { - const { expression, name } = classDir; + this.node.classes.forEach(class_directive => { + const { expression, name } = class_directive; let snippet, dependencies; if (expression) { snippet = expression.render(block); @@ -821,16 +821,16 @@ export default class ElementWrapper extends Wrapper { return null; } - add_css_class(className = this.component.stylesheet.id) { + add_css_class(class_name = this.component.stylesheet.id) { const class_attribute = this.attributes.find(a => a.name === 'class'); if (class_attribute && !class_attribute.is_true) { if (class_attribute.chunks.length === 1 && class_attribute.chunks[0].type === 'Text') { - (class_attribute.chunks[0] as Text).data += ` ${className}`; + (class_attribute.chunks[0] as Text).data += ` ${class_name}`; } else { (class_attribute.chunks as Node[]).push( new Text(this.component, this, this.scope, { type: 'Text', - data: ` ${className}` + data: ` ${class_name}` }) ); } @@ -839,7 +839,7 @@ export default class ElementWrapper extends Wrapper { new Attribute(this.component, this, this.scope, { type: 'Attribute', name: 'class', - value: [{ type: 'Text', data: className }] + value: [{ type: 'Text', data: class_name }] }) ); } diff --git a/src/compile/render-dom/wrappers/Fragment.ts b/src/compile/render-dom/wrappers/Fragment.ts index d923cee31d..8d955b6d01 100644 --- a/src/compile/render-dom/wrappers/Fragment.ts +++ b/src/compile/render-dom/wrappers/Fragment.ts @@ -139,9 +139,9 @@ export default class FragmentWrapper { } } - render(block: Block, parentNode: string, parent_nodes: string) { + render(block: Block, parent_node: string, parent_nodes: string) { for (let i = 0; i < this.nodes.length; i += 1) { - this.nodes[i].render(block, parentNode, parent_nodes); + this.nodes[i].render(block, parent_node, parent_nodes); } } } diff --git a/src/compile/render-dom/wrappers/InlineComponent/index.ts b/src/compile/render-dom/wrappers/InlineComponent/index.ts index c79d39b141..958a98bcb5 100644 --- a/src/compile/render-dom/wrappers/InlineComponent/index.ts +++ b/src/compile/render-dom/wrappers/InlineComponent/index.ts @@ -100,7 +100,7 @@ export default class InlineComponentWrapper extends Wrapper { render( block: Block, - parentNode: string, + parent_node: string, parent_nodes: string ) { const { renderer } = this; @@ -122,7 +122,7 @@ export default class InlineComponentWrapper extends Wrapper { const slot_props = Array.from(this.slots).map(([name, slot]) => `$$slot_${sanitize(name)}: [${slot.block.name}${slot.fn ? `, ${slot.fn}` : ''}]`); if (slot_props.length > 0) slot_props.push(`$$scope: { ctx }`); - const attributeObject = uses_spread + const attribute_object = uses_spread ? stringify_props(slot_props) : stringify_props( this.node.attributes.map(attr => `${quote_name_if_necessary(attr.name)}: ${attr.get_value(block)}`).concat(slot_props) @@ -130,7 +130,7 @@ export default class InlineComponentWrapper extends Wrapper { if (this.node.attributes.length || this.node.bindings.length || slot_props.length) { if (!uses_spread && this.node.bindings.length === 0) { - component_opts.push(`props: ${attributeObject}`); + component_opts.push(`props: ${attribute_object}`); } else { props = block.get_unique_name(`${name}_props`); component_opts.push(`props: ${props}`); @@ -375,7 +375,7 @@ export default class InlineComponentWrapper extends Wrapper { function ${switch_props}(ctx) { ${(this.node.attributes.length || this.node.bindings.length) && deindent` - ${props && `let ${props} = ${attributeObject};`}`} + ${props && `let ${props} = ${attribute_object};`}`} ${statements} return ${stringify_props(component_opts)}; } @@ -400,11 +400,11 @@ export default class InlineComponentWrapper extends Wrapper { block.builders.mount.add_block(deindent` if (${name}) { - @mount_component(${name}, ${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'}); + @mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'}); } `); - const anchor = this.get_or_create_anchor(block, parentNode, parent_nodes); + const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes); const update_mount_node = this.get_update_mount_node(anchor); if (updates.length) { @@ -458,7 +458,7 @@ export default class InlineComponentWrapper extends Wrapper { `if (${name}) ${name}.$$.fragment.o(#local);` ); - block.builders.destroy.add_line(`if (${name}) ${name}.$destroy(${parentNode ? '' : 'detaching'});`); + block.builders.destroy.add_line(`if (${name}) ${name}.$destroy(${parent_node ? '' : 'detaching'});`); } else { const expression = this.node.name === 'svelte:self' ? '__svelte:self__' // TODO conflict-proof this @@ -466,7 +466,7 @@ export default class InlineComponentWrapper extends Wrapper { block.builders.init.add_block(deindent` ${(this.node.attributes.length || this.node.bindings.length) && deindent` - ${props && `let ${props} = ${attributeObject};`}`} + ${props && `let ${props} = ${attribute_object};`}`} ${statements} var ${name} = new ${expression}(${stringify_props(component_opts)}); @@ -483,7 +483,7 @@ export default class InlineComponentWrapper extends Wrapper { } block.builders.mount.add_line( - `@mount_component(${name}, ${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});` + `@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});` ); block.builders.intro.add_block(deindent` @@ -499,7 +499,7 @@ export default class InlineComponentWrapper extends Wrapper { } block.builders.destroy.add_block(deindent` - ${name}.$destroy(${parentNode ? '' : 'detaching'}); + ${name}.$destroy(${parent_node ? '' : 'detaching'}); `); block.builders.outro.add_line( diff --git a/src/compile/render-dom/wrappers/Slot.ts b/src/compile/render-dom/wrappers/Slot.ts index 4930729190..e21baaa717 100644 --- a/src/compile/render-dom/wrappers/Slot.ts +++ b/src/compile/render-dom/wrappers/Slot.ts @@ -99,7 +99,7 @@ export default class SlotWrapper extends Wrapper { const ${slot} = @create_slot(${slot_definition}, ctx, ${get_slot_context}); `); - let mountBefore = block.builders.mount.toString(); + let mount_before = block.builders.mount.toString(); block.builders.create.push_condition(`!${slot}`); block.builders.hydrate.push_condition(`!${slot}`); @@ -127,7 +127,7 @@ export default class SlotWrapper extends Wrapper { `if (${slot}) ${slot}.l(${parent_nodes});` ); - const mount_leadin = block.builders.mount.toString() !== mountBefore + const mount_leadin = block.builders.mount.toString() !== mount_before ? `else` : `if (${slot})`; diff --git a/src/compile/render-ssr/Renderer.ts b/src/compile/render-ssr/Renderer.ts index d22d84696b..73f89dba22 100644 --- a/src/compile/render-ssr/Renderer.ts +++ b/src/compile/render-ssr/Renderer.ts @@ -46,8 +46,8 @@ export default class Renderer { append(code: string) { if (this.targets.length) { const target = this.targets[this.targets.length - 1]; - const slotName = target.slot_stack[target.slot_stack.length - 1]; - target.slots[slotName] += code; + const slot_name = target.slot_stack[target.slot_stack.length - 1]; + target.slots[slot_name] += code; } else { this.code += code; } diff --git a/src/compile/render-ssr/handlers/Element.ts b/src/compile/render-ssr/handlers/Element.ts index 16950eafca..0c2cdc489e 100644 --- a/src/compile/render-ssr/handlers/Element.ts +++ b/src/compile/render-ssr/handlers/Element.ts @@ -53,12 +53,12 @@ export default function(node, renderer, options) { const slot = node.get_static_attribute_value('slot'); if (slot && node.has_ancestor('InlineComponent')) { const slot = node.attributes.find((attribute: Node) => attribute.name === 'slot'); - const slotName = slot.chunks[0].data; + const slot_name = slot.chunks[0].data; const target = renderer.targets[renderer.targets.length - 1]; - target.slot_stack.push(slotName); - target.slots[slotName] = ''; + target.slot_stack.push(slot_name); + target.slots[slot_name] = ''; - options.slot_scopes.set(slotName, get_slot_scope(node.lets)); + options.slot_scopes.set(slot_name, get_slot_scope(node.lets)); } const class_expression = node.classes.map((class_directive: Class) => { diff --git a/src/compile/utils/CodeBuilder.ts b/src/compile/utils/CodeBuilder.ts index eb033a63a2..b930368143 100644 --- a/src/compile/utils/CodeBuilder.ts +++ b/src/compile/utils/CodeBuilder.ts @@ -74,9 +74,9 @@ function find_line(chunk: BlockChunk) { return false; } -function chunk_to_string(chunk: Chunk, level: number = 0, lastBlock?: boolean, first?: boolean): string { +function chunk_to_string(chunk: Chunk, level: number = 0, last_block?: boolean, first?: boolean): string { if (chunk.type === 'line') { - return `${lastBlock || (!first && chunk.block) ? '\n' : ''}${chunk.line.replace(/^/gm, repeat('\t', level))}`; + return `${last_block || (!first && chunk.block) ? '\n' : ''}${chunk.line.replace(/^/gm, repeat('\t', level))}`; } else if (chunk.type === 'condition') { let t = false; const lines = chunk.children.map((c, i) => { @@ -87,7 +87,7 @@ function chunk_to_string(chunk: Chunk, level: number = 0, lastBlock?: boolean, f if (!lines.length) return ''; - return `${lastBlock || (!first) ? '\n' : ''}${repeat('\t', level)}if (${chunk.condition}) {\n${lines.join('\n')}\n${repeat('\t', level)}}`; + return `${last_block || (!first) ? '\n' : ''}${repeat('\t', level)}if (${chunk.condition}) {\n${lines.join('\n')}\n${repeat('\t', level)}}`; } else if (chunk.type === 'root') { let t = false; const lines = chunk.children.map((c, i) => { diff --git a/src/compile/utils/flatten_reference.ts b/src/compile/utils/flatten_reference.ts index 3ff9594189..e7d66d01ca 100644 --- a/src/compile/utils/flatten_reference.ts +++ b/src/compile/utils/flatten_reference.ts @@ -4,7 +4,7 @@ export default function flatten_reference(node: Node) { if (node.type === 'Expression') throw new Error('bad'); const nodes = []; const parts = []; - const propEnd = node.end; + const prop_end = node.end; while (node.type === 'MemberExpression') { if (node.computed) return null; @@ -15,7 +15,7 @@ export default function flatten_reference(node: Node) { node = node.object; } - const propStart = node.end; + const prop_start = node.end; const name = node.type === 'Identifier' ? node.name : node.type === 'ThisExpression' ? 'this' : null; @@ -25,5 +25,5 @@ export default function flatten_reference(node: Node) { parts.unshift(name); nodes.unshift(node); - return { name, nodes, parts, keypath: `${name}[✂${propStart}-${propEnd}✂]` }; + return { name, nodes, parts, keypath: `${name}[✂${prop_start}-${prop_end}✂]` }; } diff --git a/src/compile/utils/stringify.ts b/src/compile/utils/stringify.ts index a9c487a7a8..cd478b90ff 100644 --- a/src/compile/utils/stringify.ts +++ b/src/compile/utils/stringify.ts @@ -2,8 +2,8 @@ export function stringify(data: string, options = {}) { return JSON.stringify(escape(data, options)); } -export function escape(data: string, { onlyEscapeAtSymbol = false } = {}) { - return data.replace(onlyEscapeAtSymbol ? /@+/g : /(@+|#+)/g, (match: string) => { +export function escape(data: string, { only_escape_at_symbol = false } = {}) { + return data.replace(only_escape_at_symbol ? /@+/g : /(@+|#+)/g, (match: string) => { return match + match[0]; }); } diff --git a/src/interfaces.ts b/src/interfaces.ts index d9a48a98f2..ff10c4b13a 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -2,7 +2,7 @@ export interface Node { start: number; end: number; type: string; - [propName: string]: any; + [prop_name: string]: any; } export interface Parser { diff --git a/src/internal/animations.js b/src/internal/animations.js index 912e3d5516..388110babb 100644 --- a/src/internal/animations.js +++ b/src/internal/animations.js @@ -22,11 +22,11 @@ export function create_animation(node, from, fn, params) { let started = false; let name; - const cssText = node.style.cssText; + const css_text = node.style.cssText; function start() { if (css) { - if (delay) node.style.cssText = cssText; // TODO create delayed animation instead? + if (delay) node.style.cssText = css_text; // TODO create delayed animation instead? name = create_rule(node, 0, 1, duration, 0, easing, css); } diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 238c742885..1acae36c9c 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -8,25 +8,25 @@ import { Node } from '../../interfaces'; function trim_whitespace(block: Node, trim_before: boolean, trim_after: boolean) { if (!block.children || block.children.length === 0) return; // AwaitBlock - const firstChild = block.children[0]; - const lastChild = block.children[block.children.length - 1]; + const first_child = block.children[0]; + const last_child = block.children[block.children.length - 1]; - if (firstChild.type === 'Text' && trim_before) { - firstChild.data = trim_start(firstChild.data); - if (!firstChild.data) block.children.shift(); + if (first_child.type === 'Text' && trim_before) { + first_child.data = trim_start(first_child.data); + if (!first_child.data) block.children.shift(); } - if (lastChild.type === 'Text' && trim_after) { - lastChild.data = trim_end(lastChild.data); - if (!lastChild.data) block.children.pop(); + if (last_child.type === 'Text' && trim_after) { + last_child.data = trim_end(last_child.data); + if (!last_child.data) block.children.pop(); } if (block.else) { trim_whitespace(block.else, trim_before, trim_after); } - if (firstChild.elseif) { - trim_whitespace(firstChild, trim_before, trim_after); + if (first_child.elseif) { + trim_whitespace(first_child, trim_before, trim_after); } } @@ -310,9 +310,9 @@ export default function mustache(parser: Parser) { parser.stack.push(block); if (type === 'AwaitBlock') { - const childBlock = await_block_shorthand ? block.then : block.pending; - childBlock.start = parser.index; - parser.stack.push(childBlock); + const child_block = await_block_shorthand ? block.then : block.pending; + child_block.start = parser.index; + parser.stack.push(child_block); } } else if (parser.eat('@html')) { // {@html content} tag diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 8cfd1bf062..dc7c0c3d5a 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -185,7 +185,7 @@ export default function tag(parser: Parser) { const unique_names = new Set(); let attribute; - while ((attribute = readAttribute(parser, unique_names))) { + while ((attribute = read_attribute(parser, unique_names))) { element.attributes.push(attribute); parser.allow_whitespace(); } @@ -314,7 +314,7 @@ function read_tag_name(parser: Parser) { return name; } -function readAttribute(parser: Parser, unique_names: Set) { +function read_attribute(parser: Parser, unique_names: Set) { const start = parser.index; if (parser.eat('{')) { diff --git a/src/preprocess/index.ts b/src/preprocess/index.ts index 1f8207bec6..8538a65acc 100644 --- a/src/preprocess/index.ts +++ b/src/preprocess/index.ts @@ -58,14 +58,14 @@ async function replace_async(str: string, re: RegExp, func: (...any) => Promise< return ''; }); let out = ''; - let lastEnd = 0; + let last_end = 0; for (const { offset, length, replacement } of await Promise.all( replacements )) { - out += str.slice(lastEnd, offset) + replacement; - lastEnd = offset + length; + out += str.slice(last_end, offset) + replacement; + last_end = offset + length; } - out += str.slice(lastEnd); + out += str.slice(last_end); return out; } diff --git a/src/utils/fuzzymatch.ts b/src/utils/fuzzymatch.ts index 4ed36fc1a9..89d98fe1c1 100644 --- a/src/utils/fuzzymatch.ts +++ b/src/utils/fuzzymatch.ts @@ -202,11 +202,11 @@ class FuzzySet { let match_score; // build a results list of [score, str] - for (const matchIndex in matches) { - match_score = matches[matchIndex]; + for (const match_index in matches) { + match_score = matches[match_index]; results.push([ - match_score / (vector_normal * items[matchIndex][0]), - items[matchIndex][1], + match_score / (vector_normal * items[match_index][0]), + items[match_index][1], ]); } diff --git a/src/utils/get_code_frame.ts b/src/utils/get_code_frame.ts index 3048479915..b15378be2c 100644 --- a/src/utils/get_code_frame.ts +++ b/src/utils/get_code_frame.ts @@ -1,6 +1,6 @@ import repeat from './repeat'; -function tabsToSpaces(str: string) { +function tabs_to_spaces(str: string) { return str.replace(/^\t+/, match => match.split('\t').join(' ')); } @@ -11,26 +11,26 @@ export default function get_code_frame( ) { const lines = source.split('\n'); - const frameStart = Math.max(0, line - 2); - const frameEnd = Math.min(line + 3, lines.length); + const frame_start = Math.max(0, line - 2); + const frame_end = Math.min(line + 3, lines.length); - const digits = String(frameEnd + 1).length; + const digits = String(frame_end + 1).length; return lines - .slice(frameStart, frameEnd) + .slice(frame_start, frame_end) .map((str, i) => { - const isErrorLine = frameStart + i === line; + const isErrorLine = frame_start + i === line; - let lineNum = String(i + frameStart + 1); - while (lineNum.length < digits) lineNum = ` ${lineNum}`; + let line_num = String(i + frame_start + 1); + while (line_num.length < digits) line_num = ` ${line_num}`; if (isErrorLine) { const indicator = - repeat(' ', digits + 2 + tabsToSpaces(str.slice(0, column)).length) + '^'; - return `${lineNum}: ${tabsToSpaces(str)}\n${indicator}`; + repeat(' ', digits + 2 + tabs_to_spaces(str.slice(0, column)).length) + '^'; + return `${line_num}: ${tabs_to_spaces(str)}\n${indicator}`; } - return `${lineNum}: ${tabsToSpaces(str)}`; + return `${line_num}: ${tabs_to_spaces(str)}`; }) .join('\n'); }