webpack/lib/dependencies/HarmonyTopLevelThisParserPl...

28 lines
684 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Florent Cailhol @ooflorent
*/
2018-07-30 23:08:51 +08:00
"use strict";
const ConstDependency = require("./ConstDependency");
class HarmonyTopLevelThisParserPlugin {
apply(parser) {
2018-02-25 09:00:20 +08:00
parser.hooks.expression
.for("this")
.tap("HarmonyTopLevelThisParserPlugin", node => {
if (!parser.scope.topLevelScope) return;
const isHarmony = parser.state.harmonyModule;
2018-02-25 09:00:20 +08:00
if (isHarmony) {
2018-12-06 02:21:18 +08:00
const dep = new ConstDependency("undefined", node.range, null);
2018-02-25 09:00:20 +08:00
dep.loc = node.loc;
parser.state.module.addPresentationalDependency(dep);
return this;
2018-02-25 09:00:20 +08:00
}
});
}
}
module.exports = HarmonyTopLevelThisParserPlugin;