SystemRuntimeModule.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Florent Cailhol @ooflorent
  4. */
  5. "use strict";
  6. const RuntimeGlobals = require("../RuntimeGlobals");
  7. const RuntimeModule = require("../RuntimeModule");
  8. const Template = require("../Template");
  9. class SystemRuntimeModule extends RuntimeModule {
  10. constructor() {
  11. super("system");
  12. }
  13. /**
  14. * Returns true, if the runtime module should get it's own scope.
  15. * When false, `generate()` must emit complete statements ending with `;`
  16. * so a following runtime IIFE is not parsed as a call (ASI).
  17. * @returns {boolean} true, if the runtime module should get it's own scope
  18. */
  19. shouldIsolate() {
  20. return false;
  21. }
  22. /**
  23. * Generates runtime code for this runtime module.
  24. * @returns {string | null} runtime code
  25. */
  26. generate() {
  27. return Template.asString([
  28. `${RuntimeGlobals.system} = {`,
  29. Template.indent([
  30. "import: function () {",
  31. Template.indent(
  32. "throw new Error('System.import cannot be used indirectly');"
  33. ),
  34. "}"
  35. ]),
  36. "};"
  37. ]);
  38. }
  39. }
  40. module.exports = SystemRuntimeModule;