HasOwnPropertyRuntimeModule.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Sergey Melyukov @smelukov
  4. */
  5. "use strict";
  6. const RuntimeGlobals = require("../RuntimeGlobals");
  7. const RuntimeModule = require("../RuntimeModule");
  8. const Template = require("../Template");
  9. /** @import Compilation from "../Compilation" */
  10. class HasOwnPropertyRuntimeModule extends RuntimeModule {
  11. constructor() {
  12. super("hasOwnProperty shorthand");
  13. }
  14. /**
  15. * Returns true, if the runtime module should get it's own scope.
  16. * When false, `generate()` must emit complete statements ending with `;`
  17. * so a following runtime IIFE is not parsed as a call (ASI).
  18. * @returns {boolean} true, if the runtime module should get it's own scope
  19. */
  20. shouldIsolate() {
  21. return false;
  22. }
  23. /**
  24. * Generates runtime code for this runtime module.
  25. * @returns {string | null} runtime code
  26. */
  27. generate() {
  28. const compilation = /** @type {Compilation} */ (this.compilation);
  29. const { runtimeTemplate } = compilation;
  30. return Template.asString([
  31. `${RuntimeGlobals.hasOwnProperty} = ${runtimeTemplate.returningFunction(
  32. runtimeTemplate.objectHasOwn("obj", "prop"),
  33. "obj, prop"
  34. )};`
  35. ]);
  36. }
  37. }
  38. module.exports = HasOwnPropertyRuntimeModule;