From 7261ff0acf6ac1366b9016d96e500e7d57312633 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Tue, 9 Aug 2022 07:24:48 +0200 Subject: [PATCH] small refactor --- src/compiler/compile/nodes/Element.ts | 2 +- src/compiler/compile/nodes/shared/AbstractBlock.ts | 2 +- src/compiler/compile/utils/hash.ts | 4 ++-- src/compiler/utils/mapped_code.ts | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 7eabfefaad..0315a67b98 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -203,7 +203,7 @@ function is_valid_aria_attribute_value(schema: ARIAPropertyDefinition, value: st } } -const regex_any_repeated_whitespace = /[\s\n\t]+/g; +const regex_any_repeated_whitespace = /[\s]+/g; export default class Element extends Node { type: 'Element'; diff --git a/src/compiler/compile/nodes/shared/AbstractBlock.ts b/src/compiler/compile/nodes/shared/AbstractBlock.ts index 04917f5a6b..1f03bac05c 100644 --- a/src/compiler/compile/nodes/shared/AbstractBlock.ts +++ b/src/compiler/compile/nodes/shared/AbstractBlock.ts @@ -17,7 +17,7 @@ export default class AbstractBlock extends Node { const child = this.children[0]; - if (!child || (child.type === 'Text' && !/[^ \r\n\f\v\t]/.test(child.data))) { + if (!child || (child.type === 'Text' && !/[^\s]/.test(child.data))) { this.component.warn(this, compiler_warnings.empty_block); } } diff --git a/src/compiler/compile/utils/hash.ts b/src/compiler/compile/utils/hash.ts index 2896926f9d..d5b5a20609 100644 --- a/src/compiler/compile/utils/hash.ts +++ b/src/compiler/compile/utils/hash.ts @@ -1,9 +1,9 @@ // https://github.com/darkskyapp/string-hash/blob/master/index.js -const const_return_characters = /\r/g; +const regex_return_characters = /\r/g; export default function hash(str: string): string { - str = str.replace(const_return_characters, ''); + str = str.replace(regex_return_characters, ''); let hash = 5381; let i = str.length; diff --git a/src/compiler/utils/mapped_code.ts b/src/compiler/utils/mapped_code.ts index b816ae8b83..bf7b016fc5 100644 --- a/src/compiler/utils/mapped_code.ts +++ b/src/compiler/utils/mapped_code.ts @@ -61,6 +61,8 @@ function merge_tables(this_table: T[], other_table: T[]): [T[], number[], boo return [new_table, idx_map, val_changed, idx_changed]; } +const regex_line_token = /([^\d\w\s]|\s+)/g; + export class MappedCode { string: string; map: DecodedSourceMap; @@ -182,8 +184,6 @@ export class MappedCode { return new MappedCode(string, map); } - private static regex_line_token = /([^\d\w\s]|\s+)/g; - static from_source({ source, file_basename, get_location }: Source): MappedCode { let offset: SourceLocation = get_location(0); @@ -197,7 +197,7 @@ export class MappedCode { const line_list = source.split('\n'); for (let line = 0; line < line_list.length; line++) { map.mappings.push([]); - const token_list = line_list[line].split(this.regex_line_token); + const token_list = line_list[line].split(regex_line_token); for (let token = 0, column = 0; token < token_list.length; token++) { if (token_list[token] == '') continue; map.mappings[line].push([column, 0, offset.line + line, column]);