webpack/lib/dependencies/HarmonyImportSpecifierDepen...

42 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-01-13 00:45:30 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var NullDependency = require("./NullDependency");
function HarmonyImportSpecifierDependency(importDependency, importedVar, id, name, range) {
2015-01-13 00:45:30 +08:00
NullDependency.call(this);
this.importDependency = importDependency;
2015-01-13 00:45:30 +08:00
this.importedVar = importedVar;
this.id = id;
this.name = name;
this.range = range;
}
module.exports = HarmonyImportSpecifierDependency;
HarmonyImportSpecifierDependency.prototype = Object.create(NullDependency.prototype);
2015-10-18 16:44:51 +08:00
HarmonyImportSpecifierDependency.prototype.constructor = HarmonyImportSpecifierDependency;
2015-01-13 00:45:30 +08:00
HarmonyImportSpecifierDependency.prototype.type = "harmony import specifier";
HarmonyImportSpecifierDependency.prototype.getReference = function() {
if(!this.importDependency.module) return null;
return {
module: this.importDependency.module,
importedNames: this.id ? [this.id] : true
};
}
2015-01-13 00:45:30 +08:00
HarmonyImportSpecifierDependency.Template = function HarmonyImportSpecifierDependencyTemplate() {};
HarmonyImportSpecifierDependency.Template.prototype.apply = function(dep, source) {
var content;
2016-01-07 06:50:12 +08:00
if(dep.id === "default" && !(dep.importDependency.module.meta && dep.importDependency.module.meta.harmonyModule)) {
content = "/* harmony import */ " + dep.importedVar + "_default.a";
} else if(dep.id) {
content = "/* harmony import */ " + dep.importedVar + "[" + JSON.stringify(dep.id) + "]";
2015-01-13 00:45:30 +08:00
} else {
content = "/* harmony namespace import */ " + dep.importedVar;
2015-01-13 00:45:30 +08:00
}
source.replace(dep.range[0], dep.range[1] - 1, content);
2015-01-13 00:45:30 +08:00
};