The next step!
Pre-release
Pre-release
This is a pre-release. Please help the development of common-tags by testing the common-tags@next version.
Version 2.0.0 is coming. Before it is released however, there are some things to be done - eg. the documentation needs to be rewritten properly for clarity. Maybe the package will be also rewritten into TypeScript? Who knows.
Breaking changes
TemplateTag
no longer detects whether the argument is a function and subsequently calls it. This may have been a bit convenient, but at the cost of code clarity, and it was also adding extra complication to the core function that should be as lean as possible: (declandewet/common-tags@0c1c971)- Arguments in transformers are now checked on initialization as opposed to inside the hooks. This makes errors detectable earlier (declandewet/common-tags@1811baa)
New stuff
createTag
is introduced as a replacement forTemplateTag
. The days of addingnew
each time you want to combine some tags are over (declandewet/common-tags@74d1076)- Each of the hooks (
onString
,onSubstitution
,onEndResult
) now gets and additional argument:context
. You can initialize its value in the newgetInitialContext
hook. This replaces the previously suggested practice of doing something like assigning tothis
in a hook. For more insight I recommend reading the tests in the linked commit (declandewet/common-tags@c17c2f0) - A new tag is added:
id
. It just returns whatever it receives. Again, for more examples for now look into tests in the following commit (declandewet/common-tags@52120bb) - Tags are now composable; previously this feat was impossible, as tags are functions and would've just been called. After the breaking change you can stuff other tags inside
createTag
without a problem (declandewet/common-tags@e393195) - Smart trimming was introduced as a remedy to a long-standing issue and is now used in
stripIndent
andstripIndents
(https://github.com/declandewet/common-tags/pull/165) - Nesting code inside other code when using
html
(akasource aka
codeBlock`) should not cause nasty surprises anymore (https://github.com/declandewet/common-tags/pull/182)
Deprecations
- As a result of the introduction of
createTag
,TemplateTag
is now soft-deprecated. That means you can still use it, but it will print a helpful message that will guide you to the new API (declandewet/common-tags@3ad1946)