fix: import dispatch version guard for successful PDA actions
This commit is contained in:
@@ -30,7 +30,12 @@ function page(dependencies = {}) {
|
||||
const original = deps[api]; if (!original) continue
|
||||
deps[api] = (...args) => { lastCommand = { dispatchNo: args[0], action, body: args.at(-1) }; return original(...args) }
|
||||
}
|
||||
const definition = new Function(...Object.keys(deps), source.replace(/^\s*import .*$/gm, '').replace('export default', 'return'))(...Object.values(deps))
|
||||
// Only bind dependencies actually imported by the page; injecting every mock
|
||||
// would hide missing production imports behind successful workflow tests.
|
||||
const importedNames = new Set([...source.matchAll(/^\s*import\s+(?:\{([^}]+)\}|(\w+))\s+from\s+/gm)]
|
||||
.flatMap(match => (match[1] || match[2]).split(',').map(name => name.trim().split(/\s+as\s+/).at(-1))))
|
||||
const bindings = Object.entries(deps).filter(([name]) => importedNames.has(name))
|
||||
const definition = new Function(...bindings.map(([name]) => name), source.replace(/^\s*import .*$/gm, '').replace('export default', 'return'))(...bindings.map(([, value]) => value))
|
||||
const state = { ...definition.data(), current: task() }
|
||||
for (const [name, method] of Object.entries(definition.methods)) state[name] = method.bind(state)
|
||||
for (const [name, getter] of Object.entries(definition.computed)) Object.defineProperty(state, name, { get: () => getter.call(state) })
|
||||
|
||||
Reference in New Issue
Block a user