improve multiline expression eval

This commit is contained in:
Yanzhen Yu 2022-02-04 17:01:45 +08:00
parent 46fa447432
commit e92ee94203
2 changed files with 17 additions and 1 deletions

View File

@ -22,6 +22,19 @@ describe('parseExpression function', () => {
[' input1.value '],
'!',
]);
const multiline = parseExpression(`{{
{ id: 1 }
}}`);
expect(multiline).toMatchInlineSnapshot(`
Array [
Array [
"
{ id: 1 }
",
],
]
`);
});
it('can parse $listItem expression', () => {

View File

@ -43,7 +43,10 @@ export class StateManager {
const evalText = expChunk.map(ex => this.evalExp(ex, scopeObject)).join('');
let evaled;
try {
evaled = new Function(`with(this) { return ${evalText} }`).call({
evaled = new Function(
// trim leading space and newline
`with(this) { return ${evalText.replace(/^\s+/g, '')} }`
).call({
...this.store,
...this.dependencies,
...scopeObject,