AMDRuntimeModules.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const RuntimeGlobals = require("../RuntimeGlobals");
  6. const RuntimeModule = require("../RuntimeModule");
  7. const Template = require("../Template");
  8. class AMDDefineRuntimeModule extends RuntimeModule {
  9. constructor() {
  10. super("amd define");
  11. }
  12. /**
  13. * @returns {string} runtime code
  14. */
  15. generate() {
  16. return Template.asString([
  17. `${RuntimeGlobals.amdDefine} = function () {`,
  18. Template.indent("throw new Error('define cannot be used indirect');"),
  19. "};"
  20. ]);
  21. }
  22. }
  23. class AMDOptionsRuntimeModule extends RuntimeModule {
  24. /**
  25. * @param {Record<string, boolean | number | string>} options the AMD options
  26. */
  27. constructor(options) {
  28. super("amd options");
  29. this.options = options;
  30. }
  31. /**
  32. * @returns {string} runtime code
  33. */
  34. generate() {
  35. return Template.asString([
  36. `${RuntimeGlobals.amdOptions} = ${JSON.stringify(this.options)};`
  37. ]);
  38. }
  39. }
  40. exports.AMDDefineRuntimeModule = AMDDefineRuntimeModule;
  41. exports.AMDOptionsRuntimeModule = AMDOptionsRuntimeModule;