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");
|
|
|
|
|
2015-10-22 03:05:01 +08:00
|
|
|
function HarmonyImportSpecifierDependency(importDependency, importedVar, id, name, range) {
|
2015-01-13 00:45:30 +08:00
|
|
|
NullDependency.call(this);
|
2015-10-22 03:05:01 +08:00
|
|
|
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";
|
|
|
|
|
2015-10-22 03:05:01 +08:00
|
|
|
HarmonyImportSpecifierDependency.prototype.getReference = function() {
|
|
|
|
if(!this.importDependency.module) return null;
|
|
|
|
return {
|
|
|
|
module: this.importDependency.module,
|
|
|
|
importedNames: this.id ? [this.id] : true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-02-04 07:06:16 +08:00
|
|
|
HarmonyImportSpecifierDependency.prototype.updateHash = function(hash) {
|
|
|
|
NullDependency.prototype.updateHash.call(this, hash);
|
2016-02-04 16:59:28 +08:00
|
|
|
var importedModule = this.importDependency.module;
|
|
|
|
hash.update((importedModule && importedModule.id) + "");
|
|
|
|
hash.update((importedModule && (importedModule.used + JSON.stringify(importedModule.usedExports))) + "");
|
2016-02-04 07:06:16 +08:00
|
|
|
};
|
|
|
|
|
2015-01-13 00:45:30 +08:00
|
|
|
HarmonyImportSpecifierDependency.Template = function HarmonyImportSpecifierDependencyTemplate() {};
|
|
|
|
|
2015-04-28 02:22:13 +08:00
|
|
|
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)) {
|
2016-02-13 17:00:47 +08:00
|
|
|
content = "/* harmony import */" + dep.importedVar + "_default.a";
|
2015-10-31 22:28:13 +08:00
|
|
|
} else if(dep.id) {
|
2016-02-04 06:40:41 +08:00
|
|
|
var used = dep.importDependency.module.isUsed(dep.id);
|
2016-02-13 17:00:47 +08:00
|
|
|
content = "/* harmony import */" + dep.importedVar + "[" + JSON.stringify(used) + "]";
|
2015-01-13 00:45:30 +08:00
|
|
|
} else {
|
2015-04-28 02:22:13 +08:00
|
|
|
content = "/* harmony namespace import */ " + dep.importedVar;
|
2015-01-13 00:45:30 +08:00
|
|
|
}
|
2016-02-13 17:00:47 +08:00
|
|
|
if(dep.call) {
|
|
|
|
content = "" + content + ".bind(undefined)";
|
|
|
|
}
|
2015-04-28 02:22:13 +08:00
|
|
|
source.replace(dep.range[0], dep.range[1] - 1, content);
|
2015-01-13 00:45:30 +08:00
|
|
|
};
|