Lazy-initialize external helper template.

This commit is contained in:
Logan Smyth 2017-12-01 17:11:38 -08:00
parent dffcef785a
commit 600106b9cb

View File

@ -3,7 +3,10 @@ import generator from "@babel/generator";
import template from "@babel/template"; import template from "@babel/template";
import * as t from "@babel/types"; import * as t from "@babel/types";
const buildUmdWrapper = template(` // Wrapped to avoid wasting time parsing this when almost no-one uses
// build-external-helpers.
const buildUmdWrapper = replacements =>
template`
(function (root, factory) { (function (root, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(AMD_ARGUMENTS, factory); define(AMD_ARGUMENTS, factory);
@ -15,7 +18,7 @@ const buildUmdWrapper = template(`
})(UMD_ROOT, function (FACTORY_PARAMETERS) { })(UMD_ROOT, function (FACTORY_PARAMETERS) {
FACTORY_BODY FACTORY_BODY
}); });
`); `(replacements);
function buildGlobal(whitelist) { function buildGlobal(whitelist) {
const namespace = t.identifier("babelHelpers"); const namespace = t.identifier("babelHelpers");