Skip to content

Commit dbe83c6

Browse files
committed
fix modifier context (ii)
1 parent db7e4a7 commit dbe83c6

File tree

6 files changed

+388
-370
lines changed

6 files changed

+388
-370
lines changed

packages/get/src/calls.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ export async function callModifier(
1616
) {
1717
const entry = await registry.importMod(mod)
1818
if (entry) {
19-
let ctx: any
20-
if (entry?.useContext) {
21-
if (context && entry.materialize) {
22-
ctx = materialize(context)
23-
} else {
24-
ctx = context?.data
25-
}
19+
let ctx: any = {}
20+
if (entry.useContext && context) {
21+
ctx = entry.materialize ? materialize(context) : context.data
2622
}
2723
return entry.mod(ctx, args)
2824
}

packages/get/src/registry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ export class Registry {
9090
const info = analyze(ast)
9191
const imports = [...info.imports]
9292
const contextMods: string[] = []
93-
for (const mod of info.modifiers) {
93+
for (const mod of info.modifiers.keys()) {
9494
const entry = await this.importMod(mod)
9595
if (entry?.useContext ?? true) {
9696
contextMods.push(mod)
9797
}
9898
}
99-
const isMacro = info.hasUnboundSelector || contextMods.length > 0
99+
const isMacro =
100+
info.hasUnboundSelector ||
101+
contextMods.some(mod => info.modifiers.get(mod))
100102
return { ast, imports, contextMods, isMacro }
101103
})
102104
return this.info[module]

packages/parser/src/passes/analyze.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function analyze(ast: Program) {
55
const scope = new ScopeTracker()
66
const inputs = new Set<string>()
77
const calls = new Set<string>()
8-
const modifiers = new Set<string>()
8+
const modifiers = new Map<string, boolean>()
99
const imports = new Set<string>()
1010
let hasUnboundSelector = false
1111

@@ -22,7 +22,10 @@ export function analyze(ast: Program) {
2222
hasUnboundSelector ||= !scope.context
2323
},
2424
ModifierExpr(node) {
25-
modifiers.add(node.modifier.value)
25+
const mod = node.modifier.value
26+
if (!modifiers.get(mod)) {
27+
modifiers.set(mod, !scope.context)
28+
}
2629
},
2730
})
2831

0 commit comments

Comments
 (0)