small refactor

pull/7716/head
Ivan Hofer 4 years ago committed by tanhauhau
parent 5dde25d6b1
commit 7261ff0acf

@ -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 { export default class Element extends Node {
type: 'Element'; type: 'Element';

@ -17,7 +17,7 @@ export default class AbstractBlock extends Node {
const child = this.children[0]; 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); this.component.warn(this, compiler_warnings.empty_block);
} }
} }

@ -1,9 +1,9 @@
// https://github.com/darkskyapp/string-hash/blob/master/index.js // 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 { export default function hash(str: string): string {
str = str.replace(const_return_characters, ''); str = str.replace(regex_return_characters, '');
let hash = 5381; let hash = 5381;
let i = str.length; let i = str.length;

@ -61,6 +61,8 @@ function merge_tables<T>(this_table: T[], other_table: T[]): [T[], number[], boo
return [new_table, idx_map, val_changed, idx_changed]; return [new_table, idx_map, val_changed, idx_changed];
} }
const regex_line_token = /([^\d\w\s]|\s+)/g;
export class MappedCode { export class MappedCode {
string: string; string: string;
map: DecodedSourceMap; map: DecodedSourceMap;
@ -182,8 +184,6 @@ export class MappedCode {
return new MappedCode(string, map); 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 { static from_source({ source, file_basename, get_location }: Source): MappedCode {
let offset: SourceLocation = get_location(0); let offset: SourceLocation = get_location(0);
@ -197,7 +197,7 @@ export class MappedCode {
const line_list = source.split('\n'); const line_list = source.split('\n');
for (let line = 0; line < line_list.length; line++) { for (let line = 0; line < line_list.length; line++) {
map.mappings.push([]); 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++) { for (let token = 0, column = 0; token < token_list.length; token++) {
if (token_list[token] == '') continue; if (token_list[token] == '') continue;
map.mappings[line].push([column, 0, offset.line + line, column]); map.mappings[line].push([column, 0, offset.line + line, column]);

Loading…
Cancel
Save