Convert src/compiler/compile/nodes/shared/is_contextual.ts to JavaScript

pull/8569/head
Simon Holthausen 3 years ago
parent 58a4034ade
commit 98673c1dd1

@ -8,17 +8,17 @@ import compiler_errors from '../../compiler_errors.js';
* @param {import('../../Component.js').default} component * @param {import('../../Component.js').default} component
* @param {import('../interfaces.js').INodeAllowConstTag} node * @param {import('../interfaces.js').INodeAllowConstTag} node
* @param {import('../interfaces.js').INode} parent * @param {import('../interfaces.js').INode} parent
* @returns {[import('../../../interfaces.js').ConstTag[], never[]]} * @returns {[ConstTag[], Array<Exclude<import('../interfaces.js').INode, ConstTag>>]}
*/ */
export default function get_const_tags(children, component, node, parent) { export default function get_const_tags(children, component, node, parent) {
/** @type {ConstTagType[]} */ /** @type {import('../../../interfaces.js').ConstTag[]} */
const const_tags = []; const const_tags = [];
/** @type {Array<Exclude<import('../../../interfaces.js').TemplateNode, ConstTagType>>} */ /** @type {Array<Exclude<import('../../../interfaces.js').TemplateNode, import('../../../interfaces.js').ConstTag>>} */
const others = []; const others = [];
for (const child of children) { for (const child of children) {
if (child.type === 'ConstTag') { if (child.type === 'ConstTag') {
const_tags.push(/** @type {ConstTagType} */ (child)); const_tags.push(/** @type {import('../../../interfaces.js').ConstTag} */ (child));
} else { } else {
others.push(child); others.push(child);
} }
@ -31,17 +31,17 @@ export default function get_const_tags(children, component, node, parent) {
const children_nodes = map_children(component, parent, node.scope, others); const children_nodes = map_children(component, parent, node.scope, others);
return [ return [
sorted_consts_nodes, sorted_consts_nodes,
/** @type {Array<Exclude<import('../interfaces.js').INode, import('../../../interfaces.js').ConstTag>>} */ ( /** @type {Array<Exclude<import('../interfaces.js').INode, ConstTag>>} */ (children_nodes)
children_nodes
)
]; ];
} }
/** /**
* @param {import('../../../interfaces.js').ConstTag[]} consts_nodes * @param {ConstTag[]} consts_nodes
* @param {import('../../Component.js').default} component * @param {import('../../Component.js').default} component
*/ */
function sort_consts_nodes(consts_nodes, component) { function sort_consts_nodes(consts_nodes, component) {
/** @typedef {{ assignees: Set<string>; dependencies: Set<string>; node: ConstTag; }} ConstNode */
/** @type {ConstNode[]} */ /** @type {ConstNode[]} */
const sorted_consts_nodes = []; const sorted_consts_nodes = [];

@ -1,18 +1,24 @@
import Component from '../../Component'; import { is_reserved_keyword } from '../../utils/reserved_keywords.js';
import TemplateScope from './TemplateScope';
import { is_reserved_keyword } from '../../utils/reserved_keywords';
export default function is_contextual(component: Component, scope: TemplateScope, name: string) { /**
if (is_reserved_keyword(name)) return true; * @param {import('../../Component.js').default} component
* @param {import('./TemplateScope.js').default} scope
* @param {string} name
*/
export default function is_contextual(component, scope, name) {
if (is_reserved_keyword(name))
return true;
// if it's a name below root scope, it's contextual
if (!scope.is_top_level(name))
return true;
const variable = component.var_lookup.get(name);
// hoistables, module declarations, and imports are non-contextual
if (!variable || variable.hoistable)
return false;
// assume contextual
return true;
}
// if it's a name below root scope, it's contextual
if (!scope.is_top_level(name)) return true;
const variable = component.var_lookup.get(name);
// hoistables, module declarations, and imports are non-contextual
if (!variable || variable.hoistable) return false;
// assume contextual
return true;
}

Loading…
Cancel
Save