HarmonyTopLevelThisParserPlugin.js 719 B

1234567891011121314151617181920212223242526
  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. class HarmonyTopLevelThisParserPlugin {
  8. apply(parser) {
  9. parser.hooks.expression
  10. .for("this")
  11. .tap("HarmonyTopLevelThisParserPlugin", node => {
  12. if (!parser.scope.topLevelScope) return;
  13. const module = parser.state.module;
  14. const isHarmony = !!(module.buildMeta && module.buildMeta.exportsType);
  15. if (isHarmony) {
  16. const dep = new ConstDependency("undefined", node.range, false);
  17. dep.loc = node.loc;
  18. parser.state.current.addDependency(dep);
  19. }
  20. });
  21. }
  22. }
  23. module.exports = HarmonyTopLevelThisParserPlugin;