rename some variables

pull/7716/head
Ivan Hofer 4 years ago committed by tanhauhau
parent 445fe983ac
commit 4475106a1b

@ -6,7 +6,7 @@ import { Identifier } from 'estree';
import TemplateScope from './shared/TemplateScope'; import TemplateScope from './shared/TemplateScope';
import { TemplateNode } from '../../interfaces'; import { TemplateNode } from '../../interfaces';
const regex_FunctionExpression = /FunctionExpression/; const regex_contains_FunctionExpression = /FunctionExpression/;
export default class EventHandler extends Node { export default class EventHandler extends Node {
type: 'EventHandler'; type: 'EventHandler';
@ -27,7 +27,7 @@ export default class EventHandler extends Node {
this.expression = new Expression(component, this, template_scope, info.expression); this.expression = new Expression(component, this, template_scope, info.expression);
this.uses_context = this.expression.uses_context; this.uses_context = this.expression.uses_context;
if (regex_FunctionExpression.test(info.expression.type) && info.expression.params.length === 0) { if (regex_contains_FunctionExpression.test(info.expression.type) && info.expression.params.length === 0) {
// TODO make this detection more accurate — if `event.preventDefault` isn't called, and // TODO make this detection more accurate — if `event.preventDefault` isn't called, and
// `event` is passed to another function, we can make it passive // `event` is passed to another function, we can make it passive
this.can_make_passive = true; this.can_make_passive = true;
@ -57,7 +57,7 @@ export default class EventHandler extends Node {
} }
const node = this.expression.node; const node = this.expression.node;
if (regex_FunctionExpression.test(node.type)) { if (regex_contains_FunctionExpression.test(node.type)) {
return false; return false;
} }

@ -21,7 +21,7 @@ import compiler_errors from '../../compiler_errors';
type Owner = INode; type Owner = INode;
const regex_FunctionExpression = /FunctionExpression/; const regex_contains_FunctionExpression = /FunctionExpression/;
export default class Expression { export default class Expression {
type: 'Expression' = 'Expression'; type: 'Expression' = 'Expression';
@ -74,7 +74,7 @@ export default class Expression {
scope = map.get(node); scope = map.get(node);
} }
if (!function_expression && regex_FunctionExpression.test(node.type)) { if (!function_expression && regex_contains_FunctionExpression.test(node.type)) {
function_expression = node; function_expression = node;
} }

@ -46,7 +46,7 @@ export class BaseAttributeWrapper {
} }
const regex_minus_sign = /-/; const regex_minus_sign = /-/;
const regex_invalid_variable_identifier_characters = /[^a-zA-Z_$]/g; // is 0-9 missing? const regex_invalid_variable_identifier_characters = /[^a-zA-Z_$]/g;
const regex_double_quotes = /"/g; const regex_double_quotes = /"/g;
export default class AttributeWrapper extends BaseAttributeWrapper { export default class AttributeWrapper extends BaseAttributeWrapper {
@ -385,7 +385,7 @@ function should_cache(attribute: AttributeWrapper) {
return attribute.is_src || attribute.node.should_cache(); return attribute.is_src || attribute.node.should_cache();
} }
const regex_checked_or_group = /checked|group/; const regex_contains_checked_or_group = /checked|group/;
function is_indirectly_bound_value(attribute: AttributeWrapper) { function is_indirectly_bound_value(attribute: AttributeWrapper) {
const element = attribute.parent; const element = attribute.parent;
@ -393,6 +393,6 @@ function is_indirectly_bound_value(attribute: AttributeWrapper) {
(element.node.name === 'option' || // TODO check it's actually bound (element.node.name === 'option' || // TODO check it's actually bound
(element.node.name === 'input' && (element.node.name === 'input' &&
element.node.bindings.some( element.node.bindings.some(
(binding) => regex_checked_or_group.test(binding.name) (binding) => regex_contains_checked_or_group.test(binding.name)
))); )));
} }

@ -109,7 +109,7 @@ function optimize_style(value: Array<Text | Expression>) {
} }
const regex_important_flag = /\s*!important\s*$/; const regex_important_flag = /\s*!important\s*$/;
const regex_semicolon_or_Whitespace = /[;\s]/; const regex_semicolon_or_whitespace = /[;\s]/;
function get_style_value(chunks: Array<Text | Expression>) { function get_style_value(chunks: Array<Text | Expression>) {
const value: Array<Text | Expression> = []; const value: Array<Text | Expression> = [];
@ -156,7 +156,7 @@ function get_style_value(chunks: Array<Text | Expression>) {
} as Text); } as Text);
} }
while (regex_semicolon_or_Whitespace.test(chunk.data[c])) c += 1; while (regex_semicolon_or_whitespace.test(chunk.data[c])) c += 1;
const remaining_data = chunk.data.slice(c); const remaining_data = chunk.data.slice(c);
if (remaining_data) { if (remaining_data) {

@ -34,8 +34,8 @@ interface BindingGroup {
bindings: Binding[]; bindings: Binding[];
} }
const regex_radio_or_checkbox_or_file = /radio|checkbox|file/; const regex_contains_radio_or_checkbox_or_file = /radio|checkbox|file/;
const regex_radio_or_checkbox_or_range_or_file = /radio|checkbox|range|file/; const regex_contains_radio_or_checkbox_or_range_or_file = /radio|checkbox|range|file/;
const events = [ const events = [
{ {
@ -43,7 +43,7 @@ const events = [
filter: (node: Element, _name: string) => filter: (node: Element, _name: string) =>
node.name === 'textarea' || node.name === 'textarea' ||
node.name === 'input' && node.name === 'input' &&
!regex_radio_or_checkbox_or_range_or_file.test(node.get_static_attribute_value('type') as string) !regex_contains_radio_or_checkbox_or_range_or_file.test(node.get_static_attribute_value('type') as string)
}, },
{ {
event_names: ['input'], event_names: ['input'],
@ -56,7 +56,7 @@ const events = [
filter: (node: Element, _name: string) => filter: (node: Element, _name: string) =>
node.name === 'select' || node.name === 'select' ||
node.name === 'input' && node.name === 'input' &&
regex_radio_or_checkbox_or_file.test(node.get_static_attribute_value('type') as string) regex_contains_radio_or_checkbox_or_file.test(node.get_static_attribute_value('type') as string)
}, },
{ {
event_names: ['change', 'input'], event_names: ['change', 'input'],
@ -1145,6 +1145,10 @@ export default class ElementWrapper extends Wrapper {
} }
} }
const regex_backslashes = /\\/g;
const regex_backticks = /`/g;
const regex_dollar_signs = /\$/g;
function to_html(wrappers: Array<ElementWrapper | TextWrapper | MustacheTagWrapper | RawMustacheTagWrapper>, block: Block, literal: any, state: any, can_use_raw_text?: boolean) { function to_html(wrappers: Array<ElementWrapper | TextWrapper | MustacheTagWrapper | RawMustacheTagWrapper>, block: Block, literal: any, state: any, can_use_raw_text?: boolean) {
wrappers.forEach(wrapper => { wrappers.forEach(wrapper => {
if (wrapper instanceof TextWrapper) { if (wrapper instanceof TextWrapper) {
@ -1161,10 +1165,6 @@ function to_html(wrappers: Array<ElementWrapper | TextWrapper | MustacheTagWrapp
can_use_raw_text can_use_raw_text
); );
const regex_backslashes = /\\/g;
const regex_backticks = /`/g;
const regex_dollar_signs = /\$/g;
state.quasi.value.raw += (raw ? wrapper.data : escape_html(wrapper.data)) state.quasi.value.raw += (raw ? wrapper.data : escape_html(wrapper.data))
.replace(regex_backslashes, '\\\\') .replace(regex_backslashes, '\\\\')
.replace(regex_backticks, '\\`') .replace(regex_backticks, '\\`')

@ -24,7 +24,7 @@ import { namespaces } from '../../../../utils/namespaces';
type SlotDefinition = { block: Block; scope: TemplateScope; get_context?: Node; get_changes?: Node }; type SlotDefinition = { block: Block; scope: TemplateScope; get_context?: Node; get_changes?: Node };
const regex_invalid_variable_identifier_characters = /[^a-zA-Z_$]/g; // is 0-9 missing? const regex_invalid_variable_identifier_characters = /[^a-zA-Z_$]/g;
export default class InlineComponentWrapper extends Wrapper { export default class InlineComponentWrapper extends Wrapper {
var: Identifier; var: Identifier;

Loading…
Cancel
Save