-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jinja-style tests #1033
Jinja-style tests #1033
Conversation
…lla#1015. - adds 21 Jinja2-style boolean tests - updates node list, parser and compiler to interpret and properly compile `Is` nodes - adds tests for tests, parser and compiler changes/additions - no changes to existing tests - adds `addTest`/`getTest` methods to the environment - CAVEAT: changes lexer to interpret "null" as `null` instead of a lookup to "null" in the context. this was necessary to make the test `null is null` pass - CAVEAT: adds dependency on ES6 Symbols, Maps and Sets for `iterable` and `mapping` tests. These may need to be removed if we're not okay with dumping IE. The tests for these tests require ES6 features and would need to be removed as well.
- improved test coverage - removed accidental console.info in test file - added JSDoc information for test functions
This is fantastic, thank you! I have no feedback because everything here looks perfect, down to following the inconsistent indentation level between different files (As an aside, I'd love to fix that at some point, probably settling on 2 spaces since that seems to have become a de facto standard in node projects; the only reason I've held off is concern over merge conflicts with PRs). |
Happy to help! Thoughts on the caveats? - I'm mostly concerned about the compatibility ramifications of a new null primitive. If someone had decided to use Also, one last thing I forgot to mention - I don't know Jinja's operator precedence; I stuck it between |
So, this means that something like this is no longer legit? {% set null = 'Hey' %}
Well, this sounds a bit bad. From one point, it is fixed by babel. It is used almost everywhere anyway. To make it even less important, for frontend React or Vue definitely a better candidate. We tried to use Nunjucks in past, but it seems to be messy and unreasonable. However, from another point, if we want to make it "right", it should be a optional thing. Want this functionality and can sacrifice IE support or use babel? Enable it. Otherwise leave it off. Or, in this case, I'd say that it should on by default, but have an option to disable for older browsers.
standard with |
Re: null - that is correct. The alternative is having the following evaluate to {{ null is not null }} ...which I'd imagine to be fairly confusing to most users Naturally, I'd be happy to postpone that semantic change for a major version bump. Re: IE8 support, I'm probably being overly cautious about potential compatibility issues - the "problems" are with two runtime test calls, to Long-term, I think Babel + ESLint + AirBNB + Prettier are a pretty solid bet. But that's probably best left to another issue. |
I think the answer to this thing is quite easy — how does it behave in Jinja2? And yeap, since it is potentially breaking change, a major bump needed.
Okey, looked into the code. Fallbacks seems to be reasonable. I only hope that we didn't miss any edge cases. I'd say that normally if you try to use However, in those cases without |
Mm, regarding |
Also, will |
My understanding is that it treats null as a variable, because the
Great. I can add that.
It does. We can add a test. |
Hey, don't take my words for granted! :) I'm not that experienced with compilers, and didn't work with Jinja2. It is only my assumption that in Jinja and Nunjucks any dict should be treated as iterable... |
I would imagine that anyone still supporting IE 8, but using open-source javascript libraries, has polyfills in place for a lot of newer browser features. And they're also probably fairly conservative about upgrading libraries. My inclination is to not worry too much about it, and address it if we inadvertently break support and someone opens a ticket. It might very well be the case that nobody would actually be affected, since barely anything else works in IE 8 out-of-the-box anymore. With regard to |
As far as I can tell, you put |
I just wonder, is |
Worth adding that |
According to CONTRIBUTING.md, Nunjucks should support IE8, so long as the ES5 shim is present. I mean, I'm not sure that that doesn't need updating, but it's not a figure of speech. And re: nulls, I checked Jinja2. For the record:
|
I meant that even if we drop IE8, there are still other browsers, which not much better than IE8 in some regards without babel or other polyfills. Sorry for confusion, my bad.
Than personally I don't see anything against depreciating |
Summary
I've got most of the docs changes ready to go, but I figured this would be something worth discussing before I spend time polishing them.
Is
nodesaddTest
/getTest
methods to the Environmentnull
instead of a lookup to "null" in the context. this was necessary to make the testnull is null
pass — this may be a compatibility issueiterable
andmapping
tests. The whole thing shouldn't explode / degrades gracefully if they're not available, but I don't currently have the ability to test that in an non-evergreen environment, so I can't say if we'd still have IE8 compat.Addresses #532, #879 and #1015 .
Checklist
I've completed the checklist below to ensure I didn't forget anything. This makes reviewing this PR as easy as possible for the maintainers. And it gets this change released as soon as possible.