remove more junk

pull/3539/head
Richard Harris 6 years ago
parent 0982fea5ac
commit 76053cf100

@ -233,12 +233,6 @@ export default class Component {
return this.aliases.get(name); return this.aliases.get(name);
} }
helper(name: string) {
const alias = this.alias(name);
this.helpers.set(name, alias);
return alias;
}
global(name: string) { global(name: string) {
const alias = this.alias(name); const alias = this.alias(name);
this.globals.set(name, alias); this.globals.set(name, alias);
@ -276,7 +270,8 @@ export default class Component {
} }
} }
const alias = this.helper(name); const alias = this.alias(name);
this.helpers.set(name, alias);
node.name = alias.name; node.name = alias.name;
} }
} }
@ -303,7 +298,7 @@ export default class Component {
([name, alias]) => name !== alias.name && { name, alias } ([name, alias]) => name !== alias.name && { name, alias }
).filter(Boolean); ).filter(Boolean);
if (referenced_globals.length) { if (referenced_globals.length) {
this.helper('globals'); this.helpers.set('globals', this.alias('globals'));
} }
const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({ const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({
name, name,

@ -676,7 +676,6 @@ export default class Element extends Node {
if (modifier === 'passive') { if (modifier === 'passive') {
if (passive_events.has(handler.name)) { if (passive_events.has(handler.name)) {
console.log('here', handler.name, handler.can_make_passive);
if (handler.can_make_passive) { if (handler.can_make_passive) {
component.warn(handler, { component.warn(handler, {
code: 'redundant-event-modifier', code: 'redundant-event-modifier',

@ -130,7 +130,6 @@ export default class Block {
const wrapper = this.wrappers[i]; const wrapper = this.wrappers[i];
if (!wrapper.var) continue; if (!wrapper.var) continue;
// if (wrapper.parent && wrapper.parent.can_use_innerhtml) continue;
if (seen.has(wrapper.var.name)) { if (seen.has(wrapper.var.name)) {
dupes.add(wrapper.var.name); dupes.add(wrapper.var.name);
@ -375,9 +374,6 @@ export default class Block {
d: ${properties.destroy} d: ${properties.destroy}
}`; }`;
// TODO should code-red do this automatically? probably
return_value.properties = return_value.properties.filter(prop => prop.value);
const body = b` const body = b`
${Array.from(this.variables.values()).map(({ id, init }) => { ${Array.from(this.variables.values()).map(({ id, init }) => {
return init return init
@ -447,15 +443,4 @@ export default class Block {
} }
} }
} }
// toString() {
// const local_key = this.key && this.get_unique_name('key');
// return deindent`
// ${this.comment && `// ${escape(this.comment, { only_escape_at_symbol: true })}`}
// function ${this.name}(${this.key ? `${local_key}, ` : ''}ctx) {
// ${this.get_contents(local_key)}
// }
// `;
// }
} }

@ -228,13 +228,11 @@ export default function dom(
return b`${`$$subscribe_${name}`}()`; return b`${`$$subscribe_${name}`}()`;
} }
const component_subscribe = component.helper('component_subscribe'); const callback = x`$$value => { $$invalidate('${value}', ${value} = $$value) }`;
const callback = x`$$value => { ${value} = $$value; $$invalidate('${value}', ${value}) }`;
let insert = b`${component_subscribe}($$self, ${name}, $${callback})`; let insert = b`@component_subscribe($$self, ${name}, $${callback})`;
if (component.compile_options.dev) { if (component.compile_options.dev) {
const validate_store = component.helper('validate_store'); insert = b`@validate_store(${name}, '${name}'); ${insert}`;
insert = b`${validate_store}(${name}, '${name}'); ${insert}`;
} }
return insert; return insert;
@ -260,7 +258,7 @@ export default function dom(
.filter(v => ((v.referenced || v.export_name) && !v.hoistable)) .filter(v => ((v.referenced || v.export_name) && !v.hoistable))
.map(v => p`${v.name}`); .map(v => p`${v.name}`);
if (uses_props) filtered_declarations.push(p`$$props: $$props = ${component.helper('exclude_internal_props')}($$props)`); if (uses_props) filtered_declarations.push(p`$$props: $$props = @exclude_internal_props($$props)`);
const filtered_props = props.filter(prop => { const filtered_props = props.filter(prop => {
const variable = component.var_lookup.get(prop.name); const variable = component.var_lookup.get(prop.name);

@ -149,9 +149,6 @@ export default class AwaitBlockWrapper extends Wrapper {
blocks: ${this.pending.block.has_outro_method && x`[,,,]`} blocks: ${this.pending.block.has_outro_method && x`[,,,]`}
}`; }`;
// TODO move this into code-red
info_props.properties = info_props.properties.filter(prop => prop.value);
block.chunks.init.push(b` block.chunks.init.push(b`
let ${info} = ${info_props}; let ${info} = ${info_props};
`); `);

@ -70,20 +70,6 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
renderer.add_string(`<${node.name}`); renderer.add_string(`<${node.name}`);
// if (slot && nearest_inline_component) {
// const slot = node.attributes.find((attribute) => attribute.name === 'slot');
// const slot_name = (slot.chunks[0] as Text).data;
// const lets = node.lets;
// const seen = new Set(lets.map(l => l.name.name));
// nearest_inline_component.lets.forEach(l => {
// if (!seen.has(l.name.name)) lets.push(l);
// });
// options.slot_scopes.set(slot_name, get_slot_scope(node.lets));
// }
const class_expression = node.classes.length > 0 && node.classes const class_expression = node.classes.length > 0 && node.classes
.map((class_directive: Class) => { .map((class_directive: Class) => {
const { expression, name } = class_directive; const { expression, name } = class_directive;

@ -49,12 +49,9 @@ export default function ssr(
component.rewrite_props(({ name }) => { component.rewrite_props(({ name }) => {
const value = `$${name}`; const value = `$${name}`;
const get_store_value = component.helper('get_store_value'); let insert = b`${value} = @get_store_value(${name})`;
let insert = b`${value} = ${get_store_value}(${name})`;
if (component.compile_options.dev) { if (component.compile_options.dev) {
const validate_store = component.helper('validate_store'); insert = b`@validate_store(${name}, '${name}'); ${insert}`;
insert = b`${validate_store}(${name}, '${name}'); ${insert}`;
} }
return insert; return insert;
@ -135,8 +132,7 @@ export default function ssr(
const store_name = name.slice(1); const store_name = name.slice(1);
const store = component.var_lookup.get(store_name); const store = component.var_lookup.get(store_name);
if (store && store.hoistable) { if (store && store.hoistable) {
const get_store_value = component.helper('get_store_value'); return b`let ${name} = @get_store_value(${store_name});`;
return b`let ${name} = ${get_store_value}(${store_name});`;
} }
return b`let ${name};`; return b`let ${name};`;
}), }),

@ -1,53 +0,0 @@
const start = /\n(\t+)/;
export default function deindent(
strings: TemplateStringsArray,
...values: any[]
) {
const indentation = start.exec(strings[0])[1];
const pattern = new RegExp(`^${indentation}`, 'gm');
let result = strings[0].replace(start, '').replace(pattern, '');
let current_indentation = get_current_indentation(result);
for (let i = 1; i < strings.length; i += 1) {
let expression = values[i - 1];
const string = strings[i].replace(pattern, '');
if (Array.isArray(expression)) {
expression = expression.length ? expression.join('\n') : null;
}
// discard empty codebuilders
if (expression && expression.is_empty && expression.is_empty()) {
expression = null;
}
if (expression || expression === '') {
const value = String(expression).replace(
/\n/g,
`\n${current_indentation}`
);
result += value + string;
} else {
let c = result.length;
while (/\s/.test(result[c - 1])) c -= 1;
result = result.slice(0, c) + string;
}
current_indentation = get_current_indentation(result);
}
return result.trim().replace(/\t+$/gm, '').replace(/{\n\n/gm, '{\n');
}
function get_current_indentation(str: string) {
let a = str.length;
while (a > 0 && str[a - 1] !== '\n') a -= 1;
let b = a;
while (b < str.length && /\s/.test(str[b])) b += 1;
return str.slice(a, b);
}

@ -199,47 +199,6 @@ export function showOutput(cwd, options = {}, compile = svelte.compile) {
}); });
} }
const start = /\n(\t+)/;
export function deindent(strings, ...values) {
const indentation = start.exec(strings[0])[1];
const pattern = new RegExp(`^${indentation}`, 'gm');
let result = strings[0].replace(start, '').replace(pattern, '');
let trailingIndentation = getTrailingIndentation(result);
for (let i = 1; i < strings.length; i += 1) {
let expression = values[i - 1];
const string = strings[i].replace(pattern, '');
if (Array.isArray(expression)) {
expression = expression.length ? expression.join('\n') : null;
}
if (expression || expression === '') {
const value = String(expression).replace(
/\n/g,
`\n${trailingIndentation}`
);
result += value + string;
} else {
let c = result.length;
while (/\s/.test(result[c - 1])) c -= 1;
result = result.slice(0, c) + string;
}
trailingIndentation = getTrailingIndentation(result);
}
return result.trim().replace(/\t+$/gm, '');
}
function getTrailingIndentation(str) {
let i = str.length;
while (str[i - 1] === ' ' || str[i - 1] === '\t') i -= 1;
return str.slice(i, str.length);
}
export function spaces(i) { export function spaces(i) {
let result = ''; let result = '';
while (i--) result += ' '; while (i--) result += ' ';

Loading…
Cancel
Save