You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
719 B

4 years ago
  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;