Merge pull request #314 from webzard-io/fix/eval

fix the bug that expression will re-eval everytime after store updating
This commit is contained in:
yz-yu 2022-02-28 16:22:33 +08:00 committed by GitHub
commit 4d377630ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,15 +44,12 @@ export class StateManager {
const evalText = expChunk.map(ex => this.evalExp(ex, scopeObject)).join('');
let evaled;
try {
// eslint-disable-next-line no-new-func
// eslint-disable-next-line no-useless-call, no-new-func
evaled = new Function(
'store, dependencies, scopeObject',
// trim leading space and newline
`with(this) { return ${evalText.replace(/^\s+/g, '')} }`
).call({
...this.store,
...this.dependencies,
...scopeObject,
});
`with(store) { with(dependencies) { with(scopeObject) { return ${evalText.replace(/^\s+/g, '')} } } }`
).call(null, this.store, this.dependencies, scopeObject);
} catch (e: any) {
return `{{ ${evalText} }}`;
}