better dynamic imports/data
This commit is contained in:
parent
b7b2845160
commit
878a7ada06
@ -13,8 +13,12 @@ var _ = require("lodash");
|
|||||||
|
|
||||||
function File(opts) {
|
function File(opts) {
|
||||||
this.dynamicImports = [];
|
this.dynamicImports = [];
|
||||||
|
this.dynamicImported = [];
|
||||||
this.dynamicImportIds = {};
|
this.dynamicImportIds = {};
|
||||||
|
|
||||||
|
this.dynamicData = {};
|
||||||
this.data = {};
|
this.data = {};
|
||||||
|
|
||||||
this.opts = File.normaliseOptions(opts);
|
this.opts = File.normaliseOptions(opts);
|
||||||
this.transformers = this.getTransformers();
|
this.transformers = this.getTransformers();
|
||||||
this.ast = {};
|
this.ast = {};
|
||||||
@ -179,11 +183,23 @@ File.prototype.parseShebang = function (code) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.set = function (key, val) {
|
File.prototype.set = function (key, val) {
|
||||||
this.data[key] = val;
|
return this.data[key] = val;
|
||||||
|
};
|
||||||
|
|
||||||
|
File.prototype.setDynamic = function (key, fn) {
|
||||||
|
this.dynamicData[key] = fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.get = function (key) {
|
File.prototype.get = function (key) {
|
||||||
return this.data[key];
|
var data = this.data[key];
|
||||||
|
if (data) {
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
|
var dynamic = this.dynamicData[key];
|
||||||
|
if (dynamic) {
|
||||||
|
return this.set(key, dynamic());
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.addImport = function (source, name) {
|
File.prototype.addImport = function (source, name) {
|
||||||
@ -196,7 +212,9 @@ File.prototype.addImport = function (source, name) {
|
|||||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||||
declar._blockHoist = 3;
|
declar._blockHoist = 3;
|
||||||
this.dynamicImports.push(declar);
|
this.dynamicImported.push(declar);
|
||||||
|
|
||||||
|
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user