more tidying up

pull/2252/head
Richard Harris 7 years ago
parent a236794763
commit f21c3b7136

@ -1,4 +1,4 @@
import { stringify } from '../../utils/stringify';
import { stringify } from '../utils/stringify';
import add_to_set from '../utils/add_to_set';
import Component from '../Component';
import Node from './shared/Node';

@ -1,5 +1,5 @@
import deindent from '../utils/deindent';
import { stringify, escape } from '../../utils/stringify';
import { stringify, escape } from '../utils/stringify';
import CodeBuilder from '../utils/CodeBuilder';
import Component from '../Component';
import Renderer from './Renderer';

@ -2,7 +2,7 @@ import Attribute from '../../../nodes/Attribute';
import Block from '../../Block';
import fix_attribute_casing from './fix_attribute_casing';
import ElementWrapper from './index';
import { stringify } from '../../../../utils/stringify';
import { stringify } from '../../../utils/stringify';
import deindent from '../../../utils/deindent';
export default class AttributeWrapper {

@ -3,7 +3,7 @@ import Block from '../../Block';
import AttributeWrapper from './Attribute';
import Node from '../../../nodes/shared/Node';
import ElementWrapper from '.';
import { stringify } from '../../../../utils/stringify';
import { stringify } from '../../../utils/stringify';
import add_to_set from '../../../utils/add_to_set';
export interface StyleProp {

@ -5,7 +5,7 @@ import Block from '../../Block';
import Node from '../../../nodes/shared/Node';
import { is_void, quote_prop_if_necessary, quote_name_if_necessary, sanitize } from '../../../../utils/names';
import FragmentWrapper from '../Fragment';
import { stringify, escapeHTML, escape } from '../../../../utils/stringify';
import { stringify, escape_html, escape } from '../../../utils/stringify';
import TextWrapper from '../Text';
import fix_attribute_casing from './fix_attribute_casing';
import deindent from '../../../utils/deindent';
@ -323,7 +323,7 @@ export default class ElementWrapper extends Wrapper {
return raw
? wrapper.node.data
: escapeHTML(wrapper.node.data)
: escape_html(wrapper.node.data)
.replace(/\\/g, '\\\\')
.replace(/`/g, '\\`')
.replace(/\$/g, '\\$');

@ -2,8 +2,7 @@ import Renderer from '../Renderer';
import Block from '../Block';
import Text from '../../nodes/Text';
import Wrapper from './shared/Wrapper';
import { CompileOptions } from '../../../interfaces';
import { stringify } from '../../../utils/stringify';
import { stringify } from '../../utils/stringify';
// Whitespace inside one of these elements will not result in
// a whitespace node being created in any circumstances. (This

@ -2,8 +2,7 @@ import Wrapper from './shared/Wrapper';
import Renderer from '../Renderer';
import Block from '../Block';
import Title from '../../nodes/Title';
import FragmentWrapper from './Fragment';
import { stringify } from '../../../utils/stringify';
import { stringify } from '../../utils/stringify';
import add_to_set from '../../utils/add_to_set';
export default class TitleWrapper extends Wrapper {

@ -1,6 +1,6 @@
import Renderer from '../Renderer';
import { CompileOptions } from '../../../interfaces';
import { snip } from '../../../utils/snip';
import { snip } from '../../utils/snip';
export default function(node, renderer: Renderer, options: CompileOptions) {
renderer.append('${(function(__value) { if(@isPromise(__value)) return `');

@ -1,4 +1,4 @@
import { stringify } from '../../../utils/stringify';
import { stringify } from '../../utils/stringify';
export default function(node, renderer, options) {
if (!options.dev) return;

@ -1,4 +1,4 @@
import { snip } from '../../../utils/snip';
import { snip } from '../../utils/snip';
export default function(node, renderer, options) {
const snippet = snip(node.expression);

@ -1,8 +1,8 @@
import { is_void, quote_prop_if_necessary, quote_name_if_necessary } from '../../../utils/names';
import Attribute from '../../nodes/Attribute';
import Node from '../../nodes/shared/Node';
import { snip } from '../../../utils/snip';
import { stringify_attribute } from '../../../utils/stringify_attribute';
import { snip } from '../../utils/snip';
import { stringify_attribute } from '../../utils/stringify_attribute';
import { get_slot_scope } from './shared/get_slot_scope';
// source: https://gist.github.com/ArjanSchouten/0b8574a6ad7f5065a5e7

@ -1,4 +1,4 @@
import { snip } from '../../../utils/snip';
import { snip } from '../../utils/snip';
export default function(node, renderer, options) {
renderer.append('${' + snip(node.expression) + '}');

@ -1,4 +1,4 @@
import { snip } from '../../../utils/snip';
import { snip } from '../../utils/snip';
export default function(node, renderer, options) {
const snippet = snip(node.expression);

@ -1,6 +1,6 @@
import { escape, escapeTemplate, stringify } from '../../../utils/stringify';
import { escape, escape_template, stringify } from '../../utils/stringify';
import { quote_name_if_necessary } from '../../../utils/names';
import { snip } from '../../../utils/snip';
import { snip } from '../../utils/snip';
import Renderer from '../Renderer';
import { stringify_props } from '../../utils/stringify_props';
import { get_slot_scope } from './shared/get_slot_scope';
@ -9,7 +9,7 @@ type AppendTarget = any; // TODO
function stringifyAttribute(chunk: Node) {
if (chunk.type === 'Text') {
return escapeTemplate(escape(chunk.data));
return escape_template(escape(chunk.data));
}
return '${@escape( ' + snip(chunk) + ')}';

@ -1,4 +1,4 @@
import { snip } from '../../../utils/snip';
import { snip } from '../../utils/snip';
export default function(node, renderer, options) {
const snippet = snip(node.expression);

@ -1,4 +1,4 @@
import { escapeHTML, escapeTemplate, escape } from '../../../utils/stringify';
import { escape_html, escape_template, escape } from '../../utils/stringify';
export default function(node, renderer, options) {
let text = node.data;
@ -8,7 +8,7 @@ export default function(node, renderer, options) {
(node.parent.name !== 'script' && node.parent.name !== 'style')
) {
// unless this Text node is inside a <script> or <style> element, escape &,<,>
text = escapeHTML(text);
text = escape_html(text);
}
renderer.append(escape(escapeTemplate(text)));
renderer.append(escape(escape_template(text)));
}

@ -1,7 +1,7 @@
import deindent from '../utils/deindent';
import Component from '../Component';
import { CompileOptions } from '../../interfaces';
import { stringify } from '../../utils/stringify';
import { stringify } from '../utils/stringify';
import Renderer from './Renderer';
export default function ssr(

@ -1,5 +1,5 @@
import { snip } from '../../utils/snip';
import { stringify_attribute } from '../../utils/stringify_attribute';
import { snip } from './snip';
import { stringify_attribute } from './stringify_attribute';
export default function get_slot_data(attributes, is_ssr: boolean) {
return attributes

@ -14,10 +14,10 @@ const escaped = {
'>': '&gt;',
};
export function escapeHTML(html) {
export function escape_html(html) {
return String(html).replace(/[&<>]/g, match => escaped[match]);
}
export function escapeTemplate(str) {
export function escape_template(str) {
return str.replace(/(\${|`|\\)/g, '\\$1');
}

@ -1,13 +1,13 @@
import Attribute from '../compile/nodes/Attribute';
import Node from '../compile/nodes/shared/Node';
import { escapeTemplate, escape } from './stringify';
import Attribute from '../nodes/Attribute';
import Node from '../nodes/shared/Node';
import { escape_template, escape } from './stringify';
import { snip } from './snip';
export function stringify_attribute(attribute: Attribute, is_ssr: boolean) {
return attribute.chunks
.map((chunk: Node) => {
if (chunk.type === 'Text') {
return escapeTemplate(escape(chunk.data).replace(/"/g, '&quot;'));
return escape_template(escape(chunk.data).replace(/"/g, '&quot;'));
}
return is_ssr
Loading…
Cancel
Save