UNPKG

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