Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/green-wings-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@getlang/parser": patch
"@getlang/get": patch
---

fix modifier context (ii)
10 changes: 3 additions & 7 deletions packages/get/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ export async function callModifier(
) {
const entry = await registry.importMod(mod)
if (entry) {
let ctx: any
if (entry?.useContext) {
if (context && entry.materialize) {
ctx = materialize(context)
} else {
ctx = context?.data
}
let ctx: any = {}
if (entry.useContext && context) {
ctx = entry.materialize ? materialize(context) : context.data
}
return entry.mod(ctx, args)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/get/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ export class Registry {
const info = analyze(ast)
const imports = [...info.imports]
const contextMods: string[] = []
for (const mod of info.modifiers) {
for (const mod of info.modifiers.keys()) {
const entry = await this.importMod(mod)
if (entry?.useContext ?? true) {
contextMods.push(mod)
}
}
const isMacro = info.hasUnboundSelector || contextMods.length > 0
const isMacro =
info.hasUnboundSelector ||
contextMods.some(mod => info.modifiers.get(mod))
return { ast, imports, contextMods, isMacro }
})
return this.info[module]
Expand Down
7 changes: 5 additions & 2 deletions packages/parser/src/passes/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function analyze(ast: Program) {
const scope = new ScopeTracker()
const inputs = new Set<string>()
const calls = new Set<string>()
const modifiers = new Set<string>()
const modifiers = new Map<string, boolean>()
const imports = new Set<string>()
let hasUnboundSelector = false

Expand All @@ -22,7 +22,10 @@ export function analyze(ast: Program) {
hasUnboundSelector ||= !scope.context
},
ModifierExpr(node) {
modifiers.add(node.modifier.value)
const mod = node.modifier.value
if (!modifiers.get(mod)) {
modifiers.set(mod, !scope.context)
}
},
})

Expand Down
Loading