Closed cossssmin closed 3 years ago
Maybe same here:
or here:
I guess what I mean is if strictMode: false
, the plugin should be more forgiving of the user's mistakes and/or incorrect data types.
Hmm, just realized that this:
... could use a try/catch to avoid breaking when evaluating code fails:
- const target = vm.runInContext(loopParams.expression, ctx)
+ const target = () => {
+ try {
+ return vm.runInContext(loopParams.expression, ctx)
+ } catch() {
+ return ctx
+ }
+ }
This way, we'd always return the ctx
object, either ran in context or the original.
I think this might have to depend on strictMode
though? I mean, the normal behavior should be "strict" and invalid code should break things, then strictMode: false
could prevent it:
const target = () => {
if (strictMode) {
return vm.runInContext(loopParams.expression, ctx)
}
else {
try {
return vm.runInContext(loopParams.expression, ctx)
} catch() {
return ctx
}
}
}
What do you think @Scrum?
EDIT: lol was writing at the same time, https://github.com/posthtml/posthtml-expressions/commit/d14fbbb683460fad4f8b2edb649f9ef759b89038 is perfect
@cossssmin publish v1.6.2
Still having issues with each loops, using posthtml inside maizzle email templating framework.
I'll leave a link to a repo that reproduces the bug here.
It would be enough to add extra condition here ( && opts.strictMode )
https://github.com/posthtml/posthtml-expressions/blob/bc94d52d3b496ded658cdc758eebe9cbed0ebc62/lib/index.js#L354
Maybe there would be even a better solution, but this seems to work as it should work.
@Scrum please consider @schirliuradu's comment above after merging #109, maybe we could include it and release a feature version.
I'll leave a link to a repo that reproduces the bug here.
i couldn't deploy your project to get error
It would be enough to add extra condition here
( && opts.strictMode )
@cossssmin I'll add this, but I need to understand the case to write tests for this.
It would be enough to add extra condition here
( && opts.strictMode )
@cossssmin I'll add this, but I need to understand the case to write tests for this.
Ok, i'll try to send a link to another repo, a bit later @Scrum
Ok, i'll try to send a link to another repo, a bit later
I made a fix on posthtml-expressions
try reinstall and try
https://github.com/posthtml/posthtml-expressions/blob/5a883311929ad53b44f3b51b9bd05af7f1eb0ef2/lib/index.js#L346-L349
@Scrum I think we could do a check for
strictMode
here?Something like this will fail if
items
isundefined
(or not an object for that matter), even thoughstrictMode
is set tofalse
:Ref: https://github.com/maizzle/framework/issues/354