HasOwnPropertyRuntimeModule.js 858 B

1234567891011121314151617181920212223242526272829303132333435
  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. /** @typedef {import("../Compilation")} Compilation */
  10. class HasOwnPropertyRuntimeModule extends RuntimeModule {
  11. constructor() {
  12. super("hasOwnProperty shorthand");
  13. }
  14. /**
  15. * @returns {string | null} runtime code
  16. */
  17. generate() {
  18. const compilation = /** @type {Compilation} */ (this.compilation);
  19. const { runtimeTemplate } = compilation;
  20. return Template.asString([
  21. `${RuntimeGlobals.hasOwnProperty} = ${runtimeTemplate.returningFunction(
  22. "Object.prototype.hasOwnProperty.call(obj, prop)",
  23. "obj, prop"
  24. )}`
  25. ]);
  26. }
  27. }
  28. module.exports = HasOwnPropertyRuntimeModule;