Clean up code - rename functions and var names

pull/8442/head
Nguyen Tran 3 years ago
parent b56050b60a
commit 67663a56c6

@ -1007,7 +1007,7 @@ export default class Component {
return null; return null;
} }
rewrite_props(get_insert: (variable: Var) => Node[]) { rewrite_props_and_add_subscriptions(get_subscriptions: (variable: Var) => Node[]) {
if (!this.ast.instance) return; if (!this.ast.instance) return;
const component = this; const component = this;
@ -1031,7 +1031,7 @@ export default class Component {
if (node.type === 'VariableDeclaration') { if (node.type === 'VariableDeclaration') {
// NOTE: `var` does not follow block scoping // NOTE: `var` does not follow block scoping
if (node.kind === 'var' || scope === instance_scope) { if (node.kind === 'var' || scope === instance_scope) {
const inserts = []; const subscriptions = [];
const props = []; const props = [];
function add_new_props(exported, local, default_value) { function add_new_props(exported, local, default_value) {
@ -1067,7 +1067,7 @@ export default class Component {
function get_new_name(local) { function get_new_name(local) {
const variable = component.var_lookup.get(local.name); const variable = component.var_lookup.get(local.name);
if (variable.subscribable) { if (variable.subscribable) {
inserts.push(get_insert(variable)); subscriptions.push(get_subscriptions(variable));
} }
if (variable.export_name && variable.writable) { if (variable.export_name && variable.writable) {
@ -1133,7 +1133,7 @@ export default class Component {
node.declarations.splice(index--, 1); node.declarations.splice(index--, 1);
} }
if (variable.subscribable && (is_props || declarator.init)) { if (variable.subscribable && (is_props || declarator.init)) {
inserts.push(get_insert(variable)); subscriptions.push(get_subscriptions(variable));
} }
} }
} }
@ -1145,10 +1145,10 @@ export default class Component {
if (Array.isArray(parent[key])) { if (Array.isArray(parent[key])) {
// If the variable declaration is part of some block, that is, among an array of statements // If the variable declaration is part of some block, that is, among an array of statements
// then, we add the inserts and the $$props declaration after declaration // then, we add the subscriptions and the $$props declaration after declaration
if (inserts.length > 0) { if (subscriptions.length > 0) {
inserts.reverse().forEach((insert) => { subscriptions.reverse().forEach((subscription) => {
parent[key].splice(index + 1, 0, ...insert); parent[key].splice(index + 1, 0, ...subscription);
}); });
} }
if (props.length > 0) { if (props.length > 0) {
@ -1158,14 +1158,14 @@ export default class Component {
if (node.declarations.length == 0) { if (node.declarations.length == 0) {
parent[key].splice(index, 1); parent[key].splice(index, 1);
} }
} else if (inserts.length > 0) { } else if (subscriptions.length > 0) {
// If the variable declaration is not part of a block, we instead get a dummy variable setting // If the variable declaration is not part of a block, we instead get a dummy variable setting
// calling an immediately-invoked function expression containing all the subscription functions // calling an immediately-invoked function expression containing all the subscription functions
node.declarations.push({ node.declarations.push({
type: 'VariableDeclarator', type: 'VariableDeclarator',
id: component.get_unique_name('$$subscription_inserts', scope), id: component.get_unique_name('$$subscriptions', scope),
init: x`(() => { init: x`(() => {
${inserts} ${subscriptions}
})()` })()`
}); });
} }

@ -306,7 +306,7 @@ export default function dom(
} }
}); });
component.rewrite_props(({ name, reassigned, export_name }) => { component.rewrite_props_and_add_subscriptions(({ name, reassigned, export_name }) => {
const value = `$${name}`; const value = `$${name}`;
const i = renderer.context_lookup.get(`$${name}`).index; const i = renderer.context_lookup.get(`$${name}`).index;

@ -123,7 +123,7 @@ export default function ssr(
}); });
} }
component.rewrite_props(({ name, reassigned }) => { component.rewrite_props_and_add_subscriptions(({ name, reassigned }) => {
const value = `$${name}`; const value = `$${name}`;
let insert = reassigned let insert = reassigned

Loading…
Cancel
Save