refactor(workbox-build): remove useWith from Eta template configuration#3513
refactor(workbox-build): remove useWith from Eta template configuration#3513rtritto wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
FYI @jayaddison |
|
Thanks @rtritto. Could we enable strict mode for the template evaluation? |
|
Nice catch, I did the commit |
|
Removed the commit.
|
This PR refactors the Eta template rendering configuration within
workbox-buildby removing theuseWith: trueoption.Using
with () { ... }blocks (whichuseWithrelies on) is generally considered bad practice in modern JavaScript due to performance implications, potential scoping issues, and incompatibility with Strict Mode.To accommodate this change, the service worker template (
sw-template.ts) has been updated to explicitly reference injected variables using the defaultit.object property, ensuring compatibility and cleaner variable resolution during template compilation.Changes
packages/workbox-build/src/lib/populate-sw-template.ts: RemoveduseWith: truefrom the Eta initialization options.packages/workbox-build/src/templates/sw-template.ts: Updated all template variable interpolations (e.g.,<%= importScripts %>,<%= use(...) %>) to use the explicitit.prefix (e.g.,<%= it.importScripts %>,<%= it.use(...) %>).Reference
with () {} in JavaScript slows down execution and can cause confusing bugsfrom https://dev.to/bgub/i-built-a-js-template-engine-3x-faster-than-ejs-lj8