Add support for using tagged templates as strings.

Review Request #11024 — Created May 16, 2020 and submitted

chipx86
babel-plugin-django-gettext
master
beanbag-misc

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 a gettext-like call or an interpolate 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 resulting interpolate
or gettext-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
Add support for using tagged templates as strings.
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Loading...