Lint and format src/compiler/compile/nodes/shared/TemplateScope.js

pull/8569/head
Simon Holthausen 3 years ago
parent b1f5d03c04
commit 181a23ee6c

@ -1,76 +1,76 @@
export default class TemplateScope { export default class TemplateScope {
/** @type {Set<string>} */
names;
/** @type {Set<string>} */ /** @type {Map<string, Set<string>>} */
names; dependencies_for_name;
/** @type {Map<string, Set<string>>} */ /** @type {Map<string, NodeWithScope>} */
dependencies_for_name; owners = new Map();
/** @type {Map<string, NodeWithScope>} */ /** @type {TemplateScope} */
owners = new Map(); parent;
/** @type {TemplateScope} */ /** @param {TemplateScope} [parent] undefined */
parent; constructor(parent) {
this.parent = parent;
this.names = new Set(parent ? parent.names : []);
this.dependencies_for_name = new Map(parent ? parent.dependencies_for_name : []);
}
/** @param {TemplateScope} [parent] undefined */ /**
constructor(parent) { * @param {any} name
this.parent = parent; * @param {Set<string>} dependencies
this.names = new Set(parent ? parent.names : []); * @param {any} owner
this.dependencies_for_name = new Map(parent ? parent.dependencies_for_name : []); */
} add(name, dependencies, owner) {
this.names.add(name);
this.dependencies_for_name.set(name, dependencies);
this.owners.set(name, owner);
return this;
}
child() {
const child = new TemplateScope(this);
return child;
}
/** /** @param {string} name */
* @param {any} name is_top_level(name) {
* @param {Set<string>} dependencies return !this.parent || (!this.names.has(name) && this.parent.is_top_level(name));
* @param {any} owner }
*/
add(name, dependencies, owner) {
this.names.add(name);
this.dependencies_for_name.set(name, dependencies);
this.owners.set(name, owner);
return this;
}
child() {
const child = new TemplateScope(this);
return child;
}
/** @param {string} name */ /**
is_top_level(name) { * @param {string} name
return !this.parent || (!this.names.has(name) && this.parent.is_top_level(name)); * @returns {any}
} */
get_owner(name) {
return this.owners.get(name) || (this.parent && this.parent.get_owner(name));
}
/** /** @param {string} name */
* @param {string} name is_let(name) {
* @returns {any} const owner = this.get_owner(name);
*/ return (
get_owner(name) { owner &&
return this.owners.get(name) || (this.parent && this.parent.get_owner(name)); (owner.type === 'Element' ||
} owner.type === 'InlineComponent' ||
owner.type === 'SlotTemplate')
);
}
/** @param {string} name */ /** @param {string} name */
is_let(name) { is_await(name) {
const owner = this.get_owner(name); const owner = this.get_owner(name);
return (owner && return owner && (owner.type === 'ThenBlock' || owner.type === 'CatchBlock');
(owner.type === 'Element' || }
owner.type === 'InlineComponent' ||
owner.type === 'SlotTemplate'));
}
/** @param {string} name */ /** @param {string} name */
is_await(name) { is_const(name) {
const owner = this.get_owner(name); const owner = this.get_owner(name);
return owner && (owner.type === 'ThenBlock' || owner.type === 'CatchBlock'); return owner && owner.type === 'ConstTag';
} }
/** @param {string} name */
is_const(name) {
const owner = this.get_owner(name);
return owner && owner.type === 'ConstTag';
}
} }
/** /**
* @typedef {| EachBlock * @typedef {| EachBlock
* | ThenBlock * | ThenBlock
@ -80,4 +80,3 @@ export default class TemplateScope {
* | SlotTemplate * | SlotTemplate
* | ConstTag} NodeWithScope * | ConstTag} NodeWithScope
*/ */

Loading…
Cancel
Save