HarmonyTopLevelThisParserPlugin.js 715 B

123456789101112131415161718192021222324252627
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Florent Cailhol @ooflorent
  4. */
  5. "use strict";
  6. const ConstDependency = require("./ConstDependency");
  7. const HarmonyExports = require("./HarmonyExports");
  8. class HarmonyTopLevelThisParserPlugin {
  9. apply(parser) {
  10. parser.hooks.expression
  11. .for("this")
  12. .tap("HarmonyTopLevelThisParserPlugin", node => {
  13. if (!parser.scope.topLevelScope) return;
  14. if (HarmonyExports.isEnabled(parser.state)) {
  15. const dep = new ConstDependency("undefined", node.range, null);
  16. dep.loc = node.loc;
  17. parser.state.module.addPresentationalDependency(dep);
  18. return this;
  19. }
  20. });
  21. }
  22. }
  23. module.exports = HarmonyTopLevelThisParserPlugin;