You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently String.prototype.readMacroParams helper [1] calls .parseParams method with noNames == true. It was probably coded this way as the calculated [2] params argument passed to a macro handler is meant to contain no param names. However, this approach causes errors. Here's a number of tests that you can copy to a TW and see the results:
In short, the 1st and the 3d lines don't cause any error while the other three cause the
Unable to evaluate {{DDn{b}}: SyntaxError: missing ; before statement
error. What's the reason?
The thing is, when .parseParams is called with noNames == true, it "thinks" that in
name:[[a {{DDn{b}}}]]
the first argument matches unQuoted [3] name:[[a and then the next match starts from {{ resulting in dblBrace matching {{DDn{b}}.
The solution
Now, after some analysis I've come to a simple solution: as this separation was not intended, we can simply call
var p = this.parseParams("_default",null,!notAllowEval);
in String.prototype.readMacroParams (instead of doing it like in the line 172) and then, because only p[t].value is pushed to results (name is omitted), the function works nicely (as expected, backward compatible) with "correctly used" macro params, but also doesn't cause any of the mentioned errors.
I've made a plugin that overwrites String.prototype.readMacroParams with the one containing the mentioned change, and it works nicely for me. But this looks like a core problem, so my proposal is to embed this into the core.
The problem
Currently
String.prototype.readMacroParams
helper [1] calls.parseParams
method withnoNames == true
. It was probably coded this way as the calculated [2]params
argument passed to a macro handler is meant to contain no param names. However, this approach causes errors. Here's a number of tests that you can copy to a TW and see the results:In short, the 1st and the 3d lines don't cause any error while the other three cause the
error. What's the reason?
The thing is, when
.parseParams
is called withnoNames == true
, it "thinks" that inthe first argument matches
unQuoted
[3]name:[[a
and then the next match starts from{{
resulting indblBrace
matching{{DDn{b}}
.The solution
Now, after some analysis I've come to a simple solution: as this separation was not intended, we can simply call
in
String.prototype.readMacroParams
(instead of doing it like in the line 172) and then, because onlyp[t].value
is pushed to results (name is omitted), the function works nicely (as expected, backward compatible) with "correctly used" macro params, but also doesn't cause any of the mentioned errors.I've made a plugin that overwrites
String.prototype.readMacroParams
with the one containing the mentioned change, and it works nicely for me. But this looks like a core problem, so my proposal is to embed this into the core.Best regards,
Yakov.
[1] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Strings.js#L170
[2] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Macros.js#L20
[3] https://github.com/TiddlyWiki/tiddlywiki/blob/master/js/Strings.js#L128
The text was updated successfully, but these errors were encountered: