refactor meta -> buildMeta, add factoryMeta

add compat layer to Module.meta
This commit is contained in:
Tobias Koppers 2017-12-06 12:09:17 +01:00
parent 2bb95a3b93
commit ffb977fed4
29 changed files with 133 additions and 101 deletions

View File

@ -1426,11 +1426,11 @@ class Compilation extends Tapable {
for(let indexModule = 0; indexModule < modules.length; indexModule++) {
const module = modules[indexModule];
if(module.fileDependencies) {
addAllToSet(this.fileDependencies, module.fileDependencies);
if(module.buildInfo.fileDependencies) {
addAllToSet(this.fileDependencies, module.buildInfo.fileDependencies);
}
if(module.contextDependencies) {
addAllToSet(this.contextDependencies, module.contextDependencies);
if(module.buildInfo.contextDependencies) {
addAllToSet(this.contextDependencies, module.buildInfo.contextDependencies);
}
}
this.errors.forEach(error => {
@ -1514,10 +1514,11 @@ class Compilation extends Tapable {
createModuleAssets() {
for(let i = 0; i < this.modules.length; i++) {
const module = this.modules[i];
if(module.assets) {
Object.keys(module.assets).forEach((assetName) => {
if(!module.buildInfo) console.log(module);
if(module.buildInfo.assets) {
Object.keys(module.buildInfo.assets).forEach((assetName) => {
const fileName = this.getPath(assetName);
this.assets[fileName] = module.assets[assetName];
this.assets[fileName] = module.buildInfo.assets[assetName];
this.hooks.moduleAsset.call(module, fileName);
});
}

View File

@ -40,8 +40,7 @@ class ContextModule extends Module {
this.resolveOptions = options.resolveOptions;
// Info from Build
this.builtTime = undefined;
this.contextDependencies = new Set([this.context]);
this._contextDependencies = new Set([this.context]);
if(typeof options.mode !== "string")
throw new Error("options.mode is a required option");
@ -136,12 +135,16 @@ class ContextModule extends Module {
return true;
}
return ts >= this.builtTime;
return ts >= this.buildInfo.builtTime;
}
build(options, compilation, resolver, fs, callback) {
this.built = true;
this.builtTime = Date.now();
this.buildMeta = {};
this.buildInfo = {
builtTime: Date.now(),
contextDependencies: this._contextDependencies
};
this.resolveDependencies(fs, this.options, (err, dependencies) => {
if(err) return callback(err);
@ -238,7 +241,7 @@ class ContextModule extends Module {
.sort((a, b) => {
return b.module.id - a.module.id;
}).reduce((map, dep) => {
const harmonyModule = dep.module.meta && dep.module.meta.harmonyModule;
const harmonyModule = dep.module.buildMeta && dep.module.buildMeta.harmonyModule;
if(!harmonyModule) hasNonHarmony = true;
if(harmonyModule) hasHarmony = true;
map[dep.module.id] = harmonyModule ? 1 : 0;

View File

@ -18,7 +18,6 @@ class DelegatedModule extends Module {
// Info from Factory
this.sourceRequest = sourceRequest;
this.request = data.id;
this.meta = data.meta;
this.type = type;
this.userRequest = userRequest;
this.originalRequest = originalRequest;
@ -43,6 +42,8 @@ class DelegatedModule extends Module {
build(options, compilation, resolver, fs, callback) {
this.built = true;
this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
this.buildInfo = {};
this.dependencies.length = 0;
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true));

View File

@ -28,6 +28,8 @@ class DllModule extends Module {
build(options, compilation, resolver, fs, callback) {
this.built = true;
this.buildMeta = {};
this.buildInfo = {};
return callback();
}

View File

@ -42,6 +42,8 @@ class ExternalModule extends Module {
build(options, compilation, resolver, fs, callback) {
this.built = true;
this.buildMeta = {};
this.buildInfo = {};
callback();
}

View File

@ -105,7 +105,7 @@ class FlagDependencyExportsPlugin {
module = queue.dequeue();
if(module.providedExports !== true) {
moduleWithExports = module.meta && module.meta.harmonyModule;
moduleWithExports = module.buildMeta && module.buildMeta.harmonyModule;
moduleProvidedExports = Array.isArray(module.providedExports) ? new Set(module.providedExports) : new Set();
processDependenciesBlock(module);
if(!moduleWithExports) {

View File

@ -41,7 +41,7 @@ class FlagDependencyUsagePlugin {
// for a module without side effects we stop tracking usage here when no export is used
// This module won't be evaluated in this case
if(module.sideEffectFree) {
if(module.factoryMeta.sideEffectFree) {
if(module.usedExports === false) return;
if(Array.isArray(module.usedExports) && module.usedExports.length === 0) return;
}

View File

@ -24,7 +24,7 @@ class FunctionModuleTemplatePlugin {
args.push(module.exportsArgument, "__webpack_require__");
}
source.add("/***/ (function(" + args.join(", ") + ") {\n\n");
if(module.strict) source.add("\"use strict\";\n");
if(module.buildInfo.strict) source.add("\"use strict\";\n");
source.add(moduleSource);
source.add("\n\n/***/ })");
return source;

View File

@ -40,7 +40,7 @@ class LibManifestPlugin {
ident,
data: {
id: module.id,
meta: module.meta,
buildMeta: module.buildMeta,
exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
}
};

View File

@ -59,18 +59,13 @@ class Module extends DependenciesBlock {
// TODO refactor: pass as constructor argument
this.context = null;
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
this.factoryMeta = {};
// Info from Build
this.sideEffectFree = false;
this.warnings = [];
this.errors = [];
this.strict = false;
this.meta = {};
this.exportsArgument = "exports";
this.moduleArgument = "module";
this.assets = null;
this.fileDependencies = undefined;
this.contextDependencies = undefined;
this.buildMeta = undefined;
this.buildInfo = undefined;
// Graph (per Compilation)
this.reasons = [];
@ -96,6 +91,14 @@ class Module extends DependenciesBlock {
this._rewriteChunkInReasons = undefined;
}
get exportsArgument() {
return this.buildInfo && this.buildInfo.exportsArgument || "exports";
}
get moduleArgument() {
return this.buildInfo && this.buildInfo.moduleArgument || "module";
}
disconnect() {
this.hash = undefined;
this.renderedHash = undefined;
@ -288,6 +291,8 @@ class Module extends DependenciesBlock {
}
unbuild() {
this.buildMeta = undefined;
this.buildInfo = undefined;
this.disconnect();
}
@ -320,6 +325,16 @@ Object.defineProperty(Module.prototype, "chunks", {
}
});
Object.defineProperty(Module.prototype, "meta", {
configurable: false,
get: util.deprecate(function() {
return this.buildMeta;
}, "Module.meta was renamed to Module.buildMeta"),
set: util.deprecate(function(value) {
this.buildMeta = value;
}, "Module.meta was renamed to Module.buildMeta"),
});
Module.prototype.identifier = null;
Module.prototype.readableIdentifier = null;
Module.prototype.build = null;

View File

@ -29,6 +29,8 @@ class MultiModule extends Module {
build(options, compilation, resolver, fs, callback) {
this.built = true;
this.buildMeta = {};
this.buildInfo = {};
return callback();
}

View File

@ -75,14 +75,14 @@ class NodeStuffPlugin {
parser.plugin("expression module.id", ParserHelpers.toConstantDependency("module.i"));
parser.plugin("expression module.exports", () => {
const module = parser.state.module;
const isHarmony = module.meta && module.meta.harmonyModule;
const isHarmony = module.buildMeta && module.buildMeta.harmonyModule;
if(!isHarmony)
return true;
});
parser.plugin("evaluate Identifier module.hot", ParserHelpers.evaluateToIdentifier("module.hot", false));
parser.plugin("expression module", () => {
const module = parser.state.module;
const isHarmony = module.meta && module.meta.harmonyModule;
const isHarmony = module.buildMeta && module.buildMeta.harmonyModule;
let moduleJsPath = path.join(__dirname, "..", "buildin", isHarmony ? "harmony-module.js" : "module.js");
if(module.context) {
moduleJsPath = path.relative(parser.state.module.context, moduleJsPath);

View File

@ -81,12 +81,9 @@ class NormalModule extends Module {
this.resolveOptions = resolveOptions;
// Info from Build
this.fileDependencies = new Set();
this.contextDependencies = new Set();
this.error = null;
this._source = null;
this.buildTimestamp = undefined;
this.cacheable = false;
this._cachedSource = undefined;
this._cachedSourceHash = undefined;
@ -150,8 +147,8 @@ class NormalModule extends Module {
resolver.resolve({}, context, request, callback);
},
emitFile: (name, content, sourceMap) => {
if(!this.assets) this.assets = Object.create(null);
this.assets[name] = this.createSourceForAsset(name, content, sourceMap);
if(!this.buildInfo.assets) this.buildInfo.assets = Object.create(null);
this.buildInfo.assets[name] = this.createSourceForAsset(name, content, sourceMap);
},
rootContext: options.context,
webpack: true,
@ -195,7 +192,6 @@ class NormalModule extends Module {
}
doBuild(options, compilation, resolver, fs, callback) {
this.cacheable = false;
const loaderContext = this.createLoaderContext(resolver, options, compilation, fs);
runLoaders({
@ -205,9 +201,9 @@ class NormalModule extends Module {
readResource: fs.readFile.bind(fs)
}, (err, result) => {
if(result) {
this.cacheable = result.cacheable;
this.fileDependencies = new Set(result.fileDependencies);
this.contextDependencies = new Set(result.contextDependencies);
this.buildInfo.cacheable = result.cacheable;
this.buildInfo.fileDependencies = new Set(result.fileDependencies);
this.buildInfo.contextDependencies = new Set(result.contextDependencies);
}
if(err) {
@ -232,7 +228,6 @@ class NormalModule extends Module {
}
markModuleAsErrored(error) {
this.meta = null;
this.error = error;
this.errors.push(this.error);
this._source = new RawSource("throw new Error(" + JSON.stringify(this.error.message) + ");");
@ -288,7 +283,12 @@ class NormalModule extends Module {
this.error = null;
this.errors.length = 0;
this.warnings.length = 0;
this.meta = {};
this.buildMeta = {};
this.buildInfo = {
cacheable: false,
fileDependencies: new Set(),
contextDependencies: new Set(),
};
return this.doBuild(options, compilation, resolver, fs, (err) => {
this.dependencies.length = 0;
@ -516,17 +516,17 @@ class NormalModule extends Module {
if(this.error) return true;
// always rebuild when module is not cacheable
if(!this.cacheable) return true;
if(!this.buildInfo.cacheable) return true;
// Check timestamps of all dependencies
// Missing timestamp -> need rebuild
// Timestamp bigger than buildTimestamp -> need rebuild
for(const file of this.fileDependencies) {
for(const file of this.buildInfo.fileDependencies) {
const timestamp = fileTimestamps[file];
if(!timestamp) return true;
if(timestamp >= this.buildTimestamp) return true;
}
for(const file of this.contextDependencies) {
for(const file of this.buildInfo.contextDependencies) {
const timestamp = contextTimestamps[file];
if(!timestamp) return true;
if(timestamp >= this.buildTimestamp) return true;
@ -550,7 +550,7 @@ class NormalModule extends Module {
updateHashWithMeta(hash) {
hash.update("meta");
hash.update(JSON.stringify(this.meta));
hash.update(JSON.stringify(this.buildMeta));
}
updateHash(hash) {

View File

@ -15,7 +15,6 @@ module.exports = class RawModule extends Module {
this.sourceStr = source;
this.identifierStr = identifier || this.sourceStr;
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
this.cacheable = true;
this.built = false;
}
@ -37,6 +36,10 @@ module.exports = class RawModule extends Module {
build(options, compilations, resolver, fs, callback) {
this.built = true;
this.buildMeta = {};
this.buildInfo = {
cacheable: true
};
callback();
}

View File

@ -330,7 +330,7 @@ class Stats {
index: module.index,
index2: module.index2,
size: module.size(),
cacheable: module.cacheable,
cacheable: module.buildInfo.cacheable,
built: !!module.built,
optional: module.optional,
prefetched: module.prefetched,

View File

@ -25,7 +25,7 @@ class UseStrictPlugin {
const dep = new ConstDependency("", firstNode.range);
dep.loc = firstNode.loc;
parserInstance.state.current.addDependency(dep);
parserInstance.state.module.strict = true;
parserInstance.state.module.buildInfo.strict = true;
}
});
});

View File

@ -96,9 +96,9 @@ class AMDRequireDependenciesBlockParserPlugin {
if(param.string === "require") {
dep = new ConstDependency("__webpack_require__", param.string);
} else if(param.string === "module") {
dep = new ConstDependency(parser.state.module.moduleArgument, param.range);
dep = new ConstDependency(parser.state.module.buildInfo.moduleArgument, param.range);
} else if(param.string === "exports") {
dep = new ConstDependency(parser.state.module.exportsArgument, param.range);
dep = new ConstDependency(parser.state.module.buildInfo.exportsArgument, param.range);
} else if(localModule = LocalModulesHelpers.getLocalModule(parser.state, param.string)) { // eslint-disable-line no-cond-assign
dep = new LocalModuleDependency(localModule, param.range);
} else {

View File

@ -43,25 +43,25 @@ module.exports = class HarmonyDetectionParserPlugin {
};
module.addDependency(initDep);
parser.state.harmonyParserScope = parser.state.harmonyParserScope || {};
module.meta.harmonyModule = true;
module.strict = true;
module.exportsArgument = "__webpack_exports__";
module.buildMeta.harmonyModule = true;
module.buildInfo.strict = true;
module.buildInfo.exportsArgument = "__webpack_exports__";
if(isStrictHarmony) {
module.meta.strictHarmonyModule = true;
module.moduleArgument = "__webpack_module__";
module.buildMeta.strictHarmonyModule = true;
module.buildInfo.moduleArgument = "__webpack_module__";
}
}
});
const skipInHarmony = () => {
const module = parser.state.module;
if(module && module.meta && module.meta.harmonyModule)
if(module && module.buildMeta && module.buildMeta.harmonyModule)
return true;
};
const nullInHarmony = () => {
const module = parser.state.module;
if(module && module.meta && module.meta.harmonyModule)
if(module && module.buildMeta && module.buildMeta.harmonyModule)
return null;
};

View File

@ -40,8 +40,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
};
}
const isNotAHarmonyModule = importedModule.meta && !importedModule.meta.harmonyModule;
const strictHarmonyModule = this.originModule.meta.strictHarmonyModule;
const isNotAHarmonyModule = importedModule.buildMeta && !importedModule.buildMeta.harmonyModule;
const strictHarmonyModule = this.originModule.buildMeta.strictHarmonyModule;
if(name && id === "default" && isNotAHarmonyModule) {
if(strictHarmonyModule) {
return {
@ -269,14 +269,14 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
}
getWarnings() {
if(this.strictExportPresence || this.originModule.meta.strictHarmonyModule) {
if(this.strictExportPresence || this.originModule.buildMeta.strictHarmonyModule) {
return [];
}
return this._getErrors();
}
getErrors() {
if(this.strictExportPresence || this.originModule.meta.strictHarmonyModule) {
if(this.strictExportPresence || this.originModule.buildMeta.strictHarmonyModule) {
return this._getErrors();
}
return [];
@ -288,9 +288,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
return;
}
if(!importedModule.meta || !importedModule.meta.harmonyModule) {
if(!importedModule.buildMeta || !importedModule.buildMeta.harmonyModule) {
// It's not an harmony module
if(this.originModule.meta.strictHarmonyModule && this.id !== "default") {
if(this.originModule.buildMeta.strictHarmonyModule && this.id !== "default") {
// In strict harmony modules we only support the default export
const exportName = this.id ? `the named export '${this.id}'` : "the namespace object";
const err = new Error(`Can't reexport ${exportName} from non EcmaScript module (only default export is available)`);

View File

@ -48,9 +48,9 @@ class HarmonyImportDependency extends ModuleDependency {
const importVar = this.getImportVar();
if(importVar) {
const isHarmonyModule = module.meta && module.meta.harmonyModule;
const isHarmonyModule = module.buildMeta && module.buildMeta.harmonyModule;
const content = `/* harmony import */ ${optDeclaration}${importVar} = __webpack_require__(${comment}${JSON.stringify(module.id)});${optNewline}`;
if(isHarmonyModule || this.originModule.meta.strictHarmonyModule) {
if(isHarmonyModule || this.originModule.buildMeta.strictHarmonyModule) {
return content;
}
return `${content}/* harmony import */ ${optDeclaration}${importVar}_default = /*#__PURE__*/__webpack_require__.n(${importVar});${optNewline}`;
@ -62,7 +62,7 @@ class HarmonyImportDependency extends ModuleDependency {
updateHash(hash) {
super.updateHash(hash);
const importedModule = this.module;
hash.update((importedModule && (!importedModule.meta || importedModule.meta.harmonyModule)) + "");
hash.update((importedModule && (!importedModule.buildMeta || importedModule.buildMeta.harmonyModule)) + "");
hash.update((importedModule && importedModule.id) + "");
}
}

View File

@ -11,7 +11,7 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
}
getReference() {
if(this.module && this.module.sideEffectFree) return null;
if(this.module && this.module.factoryMeta.sideEffectFree) return null;
return super.getReference();
}
@ -23,7 +23,7 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
HarmonyImportSideEffectDependency.Template = class HarmonyImportSideEffectDependencyTemplate extends HarmonyImportDependency.Template {
getHarmonyInitOrder(dep) {
if(dep.module && dep.module.sideEffectFree) return NaN;
if(dep.module && dep.module.factoryMeta.sideEffectFree) return NaN;
return super.getHarmonyInitOrder(dep);
}
};

View File

@ -31,14 +31,14 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
}
getWarnings() {
if(this.strictExportPresence || this.originModule.meta.strictHarmonyModule) {
if(this.strictExportPresence || this.originModule.buildMeta.strictHarmonyModule) {
return [];
}
return this._getErrors();
}
getErrors() {
if(this.strictExportPresence || this.originModule.meta.strictHarmonyModule) {
if(this.strictExportPresence || this.originModule.buildMeta.strictHarmonyModule) {
return this._getErrors();
}
return [];
@ -50,9 +50,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
return;
}
if(!importedModule.meta || !importedModule.meta.harmonyModule) {
if(!importedModule.buildMeta || !importedModule.buildMeta.harmonyModule) {
// It's not an harmony module
if(this.originModule.meta.strictHarmonyModule && this.id !== "default") {
if(this.originModule.buildMeta.strictHarmonyModule && this.id !== "default") {
// In strict harmony modules we only support the default export
const exportName = this.id ? `the named export '${this.id}'` : "the namespace object";
const err = new Error(`Can't import ${exportName} from non EcmaScript module (only default export is available)`);
@ -89,7 +89,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
const importedModule = this.module;
hash.update((importedModule && this.id) + "");
hash.update((importedModule && this.id && importedModule.isUsed(this.id)) + "");
hash.update((importedModule && (!importedModule.meta || importedModule.meta.harmonyModule)) + "");
hash.update((importedModule && (!importedModule.buildMeta || importedModule.buildMeta.harmonyModule)) + "");
hash.update((importedModule && (importedModule.used + JSON.stringify(importedModule.usedExports))) + "");
}
}
@ -104,7 +104,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
getContent(dep, importedVar) {
const importedModule = dep.module;
const nonHarmonyImport = !(importedModule && (!importedModule.meta || importedModule.meta.harmonyModule));
const nonHarmonyImport = !(importedModule && (!importedModule.buildMeta || importedModule.buildMeta.harmonyModule));
const importedVarSuffix = this.getImportVarSuffix(dep.id, importedModule);
const shortHandPrefix = dep.shorthand ? `${dep.name}: ` : "";
@ -112,7 +112,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
if(nonHarmonyImport) {
const defaultExport = dep.id === "default";
if(dep.originModule.meta.strictHarmonyModule) {
if(dep.originModule.buildMeta.strictHarmonyModule) {
if(defaultExport) {
return `${shortHandPrefix}${importedVar}`;
}

View File

@ -35,9 +35,9 @@ ImportDependency.Template = class ImportDependencyTemplate {
if(dep.module) {
const stringifiedId = JSON.stringify(dep.module.id);
if(dep.module.meta && dep.module.meta.harmonyModule) {
if(dep.module.buildMeta && dep.module.buildMeta.harmonyModule) {
getModuleFunction = `__webpack_require__.bind(null, ${comment}${stringifiedId})`;
} else if(dep.originModule.meta.strictHarmonyModule) {
} else if(dep.originModule.buildMeta.strictHarmonyModule) {
getModuleFunction = `function() { return /* fake namespace object */ { "default": __webpack_require__(${comment}${stringifiedId}) }; }`;
} else {
getModuleFunction = `function() { var module = __webpack_require__(${comment}${stringifiedId}); return typeof module === "object" && module && module.__esModule ? module : /* fake namespace object */ { "default": module }; }`;

View File

@ -90,7 +90,7 @@ class ImportParserPlugin {
include,
exclude,
mode,
namespaceObject: parser.state.module.meta.strictHarmonyModule ? "strict" : true
namespaceObject: parser.state.module.buildMeta.strictHarmonyModule ? "strict" : true
});
if(!dep) return;
dep.loc = expr.loc;

View File

@ -190,12 +190,17 @@ class ConcatenatedModule extends Module {
this.optimizationBailout = rootModule.optimizationBailout;
// Info from Build
this.buildInfo = {
strict: true,
cacheable: modules.every(m => m.buildInfo.cacheable),
moduleArgument: rootModule.buildInfo.moduleArgument,
exportsArgument: rootModule.buildInfo.exportsArgument,
fileDependencies: new Set(),
contextDependencies: new Set(),
assets: undefined
};
this.built = modules.some(m => m.built);
this.cacheable = modules.every(m => m.cacheable);
this.meta = rootModule.meta;
this.moduleArgument = rootModule.moduleArgument;
this.exportsArgument = rootModule.exportsArgument;
this.strict = true;
this.buildMeta = rootModule.buildMeta;
// Caching
this._numberOfConcatenatedModules = modules.length;
@ -205,11 +210,9 @@ class ConcatenatedModule extends Module {
this.reasons = rootModule.reasons.filter(reason => !(reason.dependency instanceof HarmonyImportDependency) || !modulesSet.has(reason.module));
this.dependencies = [];
this.fileDependencies = new Set();
this.contextDependencies = new Set();
this.warnings = [];
this.errors = [];
this.assets = undefined;
this._orderedConcatenationList = this._createOrderedConcatenationList(rootModule, modulesSet);
for(const info of this._orderedConcatenationList) {
if(info.type === "concatenated") {
@ -219,18 +222,18 @@ class ConcatenatedModule extends Module {
m.dependencies.filter(dep => !(dep instanceof HarmonyImportDependency) || !modulesSet.has(dep.module))
.forEach(d => this.dependencies.push(d));
// populate file dependencies
if(m.fileDependencies) m.fileDependencies.forEach(file => this.fileDependencies.add(file));
if(m.buildInfo.fileDependencies) m.buildInfo.fileDependencies.forEach(file => this.buildInfo.fileDependencies.add(file));
// populate context dependencies
if(m.contextDependencies) m.contextDependencies.forEach(context => this.contextDependencies.add(context));
if(m.buildInfo.contextDependencies) m.buildInfo.contextDependencies.forEach(context => this.buildInfo.contextDependencies.add(context));
// populate warnings
m.warnings.forEach(warning => this.warnings.push(warning));
// populate errors
m.errors.forEach(error => this.errors.push(error));
if(m.assets) {
if(this.assets === undefined)
this.assets = Object.create(null);
Object.assign(this.assets, m.assets);
if(m.buildInfo.assets) {
if(this.buildInfo.assets === undefined)
this.buildInfo.assets = Object.create(null);
Object.assign(this.buildInfo.assets, m.buildInfo.assets);
}
}
}
@ -578,7 +581,7 @@ class ConcatenatedModule extends Module {
}
case "external":
{
info.interop = info.module.meta && !info.module.meta.harmonyModule;
info.interop = info.module.buildMeta && !info.module.buildMeta.harmonyModule;
const externalName = this.findNewName("", allUsedNames, null, info.module.readableIdentifier(requestShortener));
allUsedNames.add(externalName);
info.name = externalName;
@ -729,7 +732,7 @@ class HarmonyImportSpecifierDependencyConcatenatedTemplate {
}
let content;
const callFlag = dep.call ? "_call" : "";
const strictFlag = dep.originModule.meta.strictHarmonyModule ? "_strict" : "";
const strictFlag = dep.originModule.buildMeta.strictHarmonyModule ? "_strict" : "";
if(dep.id === null) {
content = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
} else if(dep.namespaceObjectAsContext) {
@ -894,7 +897,7 @@ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
source.insert(-1, `/* unused concated harmony import ${dep.name} */\n`);
}
let finalName;
const strictFlag = dep.originModule.meta.strictHarmonyModule ? "_strict" : "";
const strictFlag = dep.originModule.buildMeta.strictHarmonyModule ? "_strict" : "";
if(def.id === true) {
finalName = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
} else {

View File

@ -27,7 +27,7 @@ class ModuleConcatenationPlugin {
}) => {
normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], (parser, parserOptions) => {
parser.plugin("call eval", () => {
parser.state.module.meta.hasEval = true;
parser.state.module.buildMeta.hasEval = true;
});
});
const bailoutReasonMap = new Map();
@ -48,13 +48,13 @@ class ModuleConcatenationPlugin {
const possibleInners = new Set();
for(const module of modules) {
// Only harmony modules are valid for optimization
if(!module.meta || !module.meta.harmonyModule || !module.dependencies.some(d => d instanceof HarmonyCompatibilityDependency)) {
if(!module.buildMeta || !module.buildMeta.harmonyModule || !module.dependencies.some(d => d instanceof HarmonyCompatibilityDependency)) {
setBailoutReason(module, "Module is not an ECMAScript module");
continue;
}
// Because of variable renaming we can't use modules with eval
if(module.meta && module.meta.hasEval) {
if(module.buildMeta && module.buildMeta.hasEval) {
setBailoutReason(module, "Module uses eval()");
continue;
}
@ -247,7 +247,7 @@ class ModuleConcatenationPlugin {
for(const reason of module.reasons) {
// Modules that are not used can be ignored
if(reason.module.sideEffectFree && reason.module.used === false) continue;
if(reason.module.factoryMeta.sideEffectFree && reason.module.used === false) continue;
const problem = this.tryToAdd(testConfig, reason.module, possibleModules, failureCache);
if(problem) {

View File

@ -18,7 +18,7 @@ class SideEffectsFlagPlugin {
const sideEffects = resolveData.descriptionFileData.sideEffects;
const isSideEffectFree = sideEffects === false; // TODO allow more complex expressions
if(isSideEffectFree) {
module.sideEffectFree = true;
module.factoryMeta.sideEffectFree = true;
}
}
@ -34,11 +34,11 @@ class SideEffectsFlagPlugin {
const removeDependencies = [];
for(const dep of module.dependencies) {
if(dep instanceof HarmonyImportSideEffectDependency) {
if(dep.module && dep.module.sideEffectFree) {
if(dep.module && dep.module.factoryMeta.sideEffectFree) {
removeDependencies.push(dep);
}
} else if(dep instanceof HarmonyExportImportedSpecifierDependency) {
if(module.sideEffectFree) {
if(module.factoryMeta.sideEffectFree) {
const mode = dep.getMode(true);
if(mode.type === "safe-reexport") {
let map = reexportMaps.get(module);

View File

@ -7,7 +7,7 @@ module.exports = {
content: {
"./module": {
id: 1,
meta: {
buildMeta: {
harmonyModule: true
},
exports: ["default"]

View File

@ -7,7 +7,7 @@ module.exports = {
content: {
"./module": {
id: 1,
meta: {
buildMeta: {
harmonyModule: true
},
exports: ["default"]