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
Destructured locals have to be specified at compile time. All other locals need to be accessed via locals (or whatever ejs.localsName is set to).
This works for KumaScript, where the only locals are API namespaces and macro arguments $$ (all arguments array) and $0-$9, which don’t change between macros or API invocations.
Since this is opt-in, wouldn't it make more sense just to destructure everything in locals, as a strict-mode safe alternative to using with? Why bother asking the user to specify particular keys?
Could we get a test that involves multiple destructured variables, instead of just one key?
Otherwise awesome. This looks like a really useful path forward to avoid verbosity without having to resort to using with.
This is because locals are passed at execution time, whereas the locals to destructure are specified at compile time.
Because of this, it’s impossible to know what exactly locals will have at execution time, so you have to specify variables to destructure at compile time.
And if you’re only compiling, immediately executing and discarding code, you can always just do Object.keys(locals).
Oh, duh, sorry. I tend to overlook the precompile use-case. This makes good sense. If you could beef up the tests a bit, and update the README, I'll be happy to merge this, and then plug the same documentation into the EJS site.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes and closes #450.
Destructured locals have to be specified at compile time. All other locals need to be accessed via
locals(or whateverejs.localsNameis set to).This works for KumaScript, where the only locals are API namespaces and macro arguments
$$(all arguments array) and$0-$9, which don’t change between macros or API invocations.review?(@mde)