some more variables

pull/7716/head
Ivan Hofer 4 years ago committed by tanhauhau
parent 14584bbbd3
commit f2b557f8af

@ -47,6 +47,8 @@ interface ComponentOptions {
preserveWhitespace?: boolean; preserveWhitespace?: boolean;
} }
const regex_leading_directory_separator = /^[/\\]/;
export default class Component { export default class Component {
stats: Stats; stats: Stats;
warnings: Warning[]; warnings: Warning[];
@ -136,7 +138,7 @@ export default class Component {
(typeof process !== 'undefined' (typeof process !== 'undefined'
? compile_options.filename ? compile_options.filename
.replace(process.cwd(), '') .replace(process.cwd(), '')
.replace(/^[/\\]/, '') .replace(regex_leading_directory_separator, '')
: compile_options.filename); : compile_options.filename);
this.locate = getLocator(this.source, { offsetLine: 1 }); this.locate = getLocator(this.source, { offsetLine: 1 });

@ -281,12 +281,14 @@ function apply_selector(blocks: Block[], node: Element, to_encapsulate: Array<{
return true; return true;
} }
const regex_backslash_and_following_character = /\\(.)/g;
function block_might_apply_to_node(block: Block, node: Element): BlockAppliesToNode { function block_might_apply_to_node(block: Block, node: Element): BlockAppliesToNode {
let i = block.selectors.length; let i = block.selectors.length;
while (i--) { while (i--) {
const selector = block.selectors[i]; const selector = block.selectors[i];
const name = typeof selector.name === 'string' && selector.name.replace(/\\(.)/g, '$1'); const name = typeof selector.name === 'string' && selector.name.replace(regex_backslash_and_following_character, '$1');
if (selector.type === 'PseudoClassSelector' && (name === 'host' || name === 'root')) { if (selector.type === 'PseudoClassSelector' && (name === 'host' || name === 'root')) {
return BlockAppliesToNode.NotPossible; return BlockAppliesToNode.NotPossible;

@ -10,8 +10,10 @@ import compiler_warnings from '../compiler_warnings';
import { extract_ignores_above_position } from '../../utils/extract_svelte_ignore'; import { extract_ignores_above_position } from '../../utils/extract_svelte_ignore';
import { push_array } from '../../utils/push_array'; import { push_array } from '../../utils/push_array';
const regex_css_browser_prefix = /^-((webkit)|(moz)|(o)|(ms))-/;
function remove_css_prefix(name: string): string { function remove_css_prefix(name: string): string {
return name.replace(/^-((webkit)|(moz)|(o)|(ms))-/, ''); return name.replace(regex_css_browser_prefix, '');
} }
const is_keyframes_node = (node: CssNode) => const is_keyframes_node = (node: CssNode) =>

@ -988,7 +988,7 @@ export default class Element extends Node {
if (attribute && !attribute.is_true) { if (attribute && !attribute.is_true) {
attribute.chunks.forEach((chunk, index) => { attribute.chunks.forEach((chunk, index) => {
if (chunk.type === 'Text') { if (chunk.type === 'Text') {
let data = chunk.data.replace(/[\s\n\t]+/g, ' '); let data = chunk.data.replace(regex_any_repeated_whitespace, ' ');
if (index === 0) { if (index === 0) {
data = data.trimLeft(); data = data.trimLeft();
} else if (index === attribute.chunks.length - 1) { } else if (index === attribute.chunks.length - 1) {
@ -1002,12 +1002,16 @@ export default class Element extends Node {
} }
} }
const regex_any_repeated_whitespace = /[\s\n\t]+/g;
const regex_starts_with_vovel = /^[aeiou]/;
function should_have_attribute( function should_have_attribute(
node, node,
attributes: string[], attributes: string[],
name = node.name name = node.name
) { ) {
const article = /^[aeiou]/.test(attributes[0]) ? 'an' : 'a'; const article = regex_starts_with_vovel.test(attributes[0]) ? 'an' : 'a';
const sequence = attributes.length > 1 ? const sequence = attributes.length > 1 ?
attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}` : attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}` :
attributes[0]; attributes[0];

@ -45,6 +45,8 @@ export class BaseAttributeWrapper {
render(_block: Block) {} render(_block: Block) {}
} }
const regex_minus_sign = /-/;
export default class AttributeWrapper extends BaseAttributeWrapper { export default class AttributeWrapper extends BaseAttributeWrapper {
node: Attribute; node: Attribute;
parent: ElementWrapper; parent: ElementWrapper;
@ -115,7 +117,7 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
// xlink is a special case... we could maybe extend this to generic // xlink is a special case... we could maybe extend this to generic
// namespaced attributes but I'm not sure that's applicable in // namespaced attributes but I'm not sure that's applicable in
// HTML5? // HTML5?
const method = /-/.test(element.node.name) const method = regex_minus_sign.test(element.node.name)
? '@set_custom_element_data' ? '@set_custom_element_data'
: name.slice(0, 6) === 'xlink:' : name.slice(0, 6) === 'xlink:'
? '@xlink_attr' ? '@xlink_attr'

@ -69,6 +69,8 @@ export default class StyleAttributeWrapper extends AttributeWrapper {
} }
} }
const regex_style_prop_key = /^\s*([\w-]+):\s*/;
function optimize_style(value: Array<Text | Expression>) { function optimize_style(value: Array<Text | Expression>) {
const props: StyleProp[] = []; const props: StyleProp[] = [];
let chunks = value.slice(); let chunks = value.slice();
@ -78,7 +80,7 @@ function optimize_style(value: Array<Text | Expression>) {
if (chunk.type !== 'Text') return null; if (chunk.type !== 'Text') return null;
const key_match = /^\s*([\w-]+):\s*/.exec(chunk.data); const key_match = regex_style_prop_key.exec(chunk.data);
if (!key_match) return null; if (!key_match) return null;
const key = key_match[1]; const key = key_match[1];

Loading…
Cancel
Save