Add support for using tagged templates as strings.
Review Request #11024 — Created May 16, 2020 and submitted
This introduces compatibility with other tagged template plugins, like
babel-plugin-dedent
, which is useful for constructing strings that
are further processed through some other means.When a tagged template is encountered as a string, it will be preserved
(well, rebuilt) and left for Babel to later process. The rebuilt tagged
template will have its contents replaced with a normalized version of
the string that would normally go into the gettext function. That means
that if the tagged template were to reference other variables or
expressions (using${...}
syntax), those would be replaced in the
rebuilt one with the gettext interpolated%(...)s
markers.In order to make any of this work, we had to change how we prevented
further processing of nodes. We had previously walled off any resulting
nodes (which may be agettext
-like call or aninterpolate
call) from
further processing, so that we wouldn't end up with an infinite loop of
processing these functions, and we skipped children. Now, to allow Babel
to reach down into the strings, we now mark any resultinginterpolate
orgettext
-like function as having been transformed, and we simply
don't re-transform those nodes, but don't skip processing of children
either.Unit tests and documentation were updated for the new support.
Unit tests passed.
Manually tested with some code in Review Board.
Viewed the docs and checked the generated output.
Summary | ID |
---|---|
34b22ccf94356d1856d79079a47b9069908d9e26 |