|
|
@ -35,12 +35,10 @@ function sort_const_tags(nodes, state) {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @typedef {{
|
|
|
|
* @typedef {{
|
|
|
|
* node: import('#compiler').ConstTag;
|
|
|
|
* node: import('#compiler').ConstTag;
|
|
|
|
* ids: import('#compiler').Binding[];
|
|
|
|
|
|
|
|
* deps: Set<import('#compiler').Binding>;
|
|
|
|
* deps: Set<import('#compiler').Binding>;
|
|
|
|
* }} Tag
|
|
|
|
* }} Tag
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const const_tags = [];
|
|
|
|
|
|
|
|
const other = [];
|
|
|
|
const other = [];
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {Map<import('#compiler').Binding, Tag>} */
|
|
|
|
/** @type {Map<import('#compiler').Binding, Tag>} */
|
|
|
@ -52,19 +50,12 @@ function sort_const_tags(nodes, state) {
|
|
|
|
if (node.type === 'ConstTag') {
|
|
|
|
if (node.type === 'ConstTag') {
|
|
|
|
const declaration = node.declaration.declarations[0];
|
|
|
|
const declaration = node.declaration.declarations[0];
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {Tag} */
|
|
|
|
const bindings = extract_identifiers(declaration.id).map((id) => {
|
|
|
|
const tag = {
|
|
|
|
return /** @type {import('#compiler').Binding} */ (state.scope.get(id.name));
|
|
|
|
node,
|
|
|
|
});
|
|
|
|
ids: extract_identifiers(declaration.id).map((id) => {
|
|
|
|
|
|
|
|
return /** @type {import('#compiler').Binding} */ (state.scope.get(id.name));
|
|
|
|
/** @type {Set<import('#compiler').Binding>} */
|
|
|
|
}),
|
|
|
|
const deps = new Set();
|
|
|
|
/** @type {Set<import('#compiler').Binding>} */
|
|
|
|
|
|
|
|
deps: new Set()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const id of tag.ids) {
|
|
|
|
|
|
|
|
tags.set(id, tag);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
walk(declaration.init, state, {
|
|
|
|
walk(declaration.init, state, {
|
|
|
|
_,
|
|
|
|
_,
|
|
|
@ -73,30 +64,30 @@ function sort_const_tags(nodes, state) {
|
|
|
|
|
|
|
|
|
|
|
|
if (is_reference(node, parent)) {
|
|
|
|
if (is_reference(node, parent)) {
|
|
|
|
const binding = context.state.scope.get(node.name);
|
|
|
|
const binding = context.state.scope.get(node.name);
|
|
|
|
if (binding) tag.deps.add(binding);
|
|
|
|
if (binding) deps.add(binding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const_tags.push(tag);
|
|
|
|
for (const binding of bindings) {
|
|
|
|
|
|
|
|
tags.set(binding, { node, deps });
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
other.push(node);
|
|
|
|
other.push(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (const_tags.length === 0) {
|
|
|
|
if (tags.size === 0) {
|
|
|
|
return nodes;
|
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {Array<[import('#compiler').Binding, import('#compiler').Binding]>} */
|
|
|
|
/** @type {Array<[import('#compiler').Binding, import('#compiler').Binding]>} */
|
|
|
|
const edges = [];
|
|
|
|
const edges = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (const tag of const_tags) {
|
|
|
|
for (const [id, tag] of tags) {
|
|
|
|
for (const id of tag.ids) {
|
|
|
|
for (const dep of tag.deps) {
|
|
|
|
for (const dep of tag.deps) {
|
|
|
|
if (tags.has(dep)) {
|
|
|
|
if (tags.has(dep)) {
|
|
|
|
edges.push([id, dep]);
|
|
|
|
edges.push([id, dep]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,7 +115,7 @@ function sort_const_tags(nodes, state) {
|
|
|
|
sorted.push(tag.node);
|
|
|
|
sorted.push(tag.node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const tag of const_tags) {
|
|
|
|
for (const tag of tags.values()) {
|
|
|
|
add(tag);
|
|
|
|
add(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|