CreateScriptRuntimeModule.js 852 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const RuntimeGlobals = require("../RuntimeGlobals");
  6. const Template = require("../Template");
  7. const HelperRuntimeModule = require("./HelperRuntimeModule");
  8. class CreateScriptRuntimeModule extends HelperRuntimeModule {
  9. constructor() {
  10. super("trusted types script");
  11. }
  12. /**
  13. * @returns {string} runtime code
  14. */
  15. generate() {
  16. const { compilation } = this;
  17. const { runtimeTemplate, outputOptions } = compilation;
  18. const { trustedTypes } = outputOptions;
  19. const fn = RuntimeGlobals.createScript;
  20. return Template.asString(
  21. `${fn} = ${runtimeTemplate.returningFunction(
  22. trustedTypes
  23. ? `${RuntimeGlobals.getTrustedTypesPolicy}().createScript(script)`
  24. : "script",
  25. "script"
  26. )};`
  27. );
  28. }
  29. }
  30. module.exports = CreateScriptRuntimeModule;