Merge pull request #9971 from smelukov/deprecation-codes

Add deprecation codes
This commit is contained in:
Tobias Koppers 2019-11-15 12:04:47 +01:00 committed by GitHub
commit accd66c3ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 209 additions and 99 deletions

2
declarations.d.ts vendored
View File

@ -12,7 +12,7 @@ declare module "util" {
function deprecate<T extends Function>(
fn: T,
message: string,
code?: string
code: string
): T;
}

View File

@ -101,7 +101,8 @@ class Chunk {
const entryModules = Array.from(
ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.entryModule"
"Chunk.entryModule",
"DEP_WEBPACK_CHUNK_ENTRY_MODULE"
).getChunkEntryModulesIterable(this)
);
if (entryModules.length === 0) {
@ -122,7 +123,8 @@ class Chunk {
return (
ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.hasEntryModule"
"Chunk.hasEntryModule",
"DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE"
).getNumberOfEntryModules(this) > 0
);
}
@ -134,7 +136,8 @@ class Chunk {
addModule(module) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.addModule"
"Chunk.addModule",
"DEP_WEBPACK_CHUNK_ADD_MODULE"
);
if (chunkGraph.isModuleInChunk(module, this)) return false;
chunkGraph.connectChunkAndModule(this, module);
@ -148,7 +151,8 @@ class Chunk {
removeModule(module) {
ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.removeModule"
"Chunk.removeModule",
"DEP_WEBPACK_CHUNK_REMOVE_MODULE"
).disconnectChunkAndModule(this, module);
}
@ -158,14 +162,16 @@ class Chunk {
getNumberOfModules() {
return ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.getNumberOfModules"
"Chunk.getNumberOfModules",
"DEP_WEBPACK_CHUNK_GET_NUMBER_OF_MODULES"
).getNumberOfChunkModules(this);
}
get modulesIterable() {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.modulesIterable"
"Chunk.modulesIterable",
"DEP_WEBPACK_CHUNK_MODULES_ITERABLE"
);
return chunkGraph.getOrderedChunkModulesIterable(
this,
@ -180,7 +186,8 @@ class Chunk {
compareTo(otherChunk) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.compareTo"
"Chunk.compareTo",
"DEP_WEBPACK_CHUNK_COMPARE_TO"
);
return chunkGraph.compareChunks(this, otherChunk);
}
@ -192,7 +199,8 @@ class Chunk {
containsModule(module) {
return ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.containsModule"
"Chunk.containsModule",
"DEP_WEBPACK_CHUNK_CONTAINS_MODULE"
).isModuleInChunk(module, this);
}
@ -202,7 +210,8 @@ class Chunk {
getModules() {
return ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.getModules"
"Chunk.getModules",
"DEP_WEBPACK_CHUNK_GET_MODULES"
).getChunkModules(this);
}
@ -210,7 +219,11 @@ class Chunk {
* @returns {void}
*/
remove() {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(this, "Chunk.remove");
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.remove",
"DEP_WEBPACK_CHUNK_REMOVE"
);
chunkGraph.disconnectChunk(this);
this.disconnectFromGroups();
}
@ -223,7 +236,8 @@ class Chunk {
moveModule(module, otherChunk) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.moveModule"
"Chunk.moveModule",
"DEP_WEBPACK_CHUNK_MOVE_MODULE"
);
chunkGraph.disconnectChunkAndModule(this, module);
chunkGraph.connectChunkAndModule(otherChunk, module);
@ -236,7 +250,8 @@ class Chunk {
integrate(otherChunk) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.integrate"
"Chunk.integrate",
"DEP_WEBPACK_CHUNK_INTEGRATE"
);
if (chunkGraph.canChunksBeIntegrated(this, otherChunk)) {
chunkGraph.integrateChunks(this, otherChunk);
@ -253,7 +268,8 @@ class Chunk {
canBeIntegrated(otherChunk) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.canBeIntegrated"
"Chunk.canBeIntegrated",
"DEP_WEBPACK_CHUNK_CAN_BE_INTEGRATED"
);
return chunkGraph.canChunksBeIntegrated(this, otherChunk);
}
@ -262,7 +278,11 @@ class Chunk {
* @returns {boolean} true, if this chunk contains no module
*/
isEmpty() {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(this, "Chunk.isEmpty");
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.isEmpty",
"DEP_WEBPACK_CHUNK_IS_EMPTY"
);
return chunkGraph.getNumberOfChunkModules(this) === 0;
}
@ -272,7 +292,8 @@ class Chunk {
modulesSize() {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.modulesSize"
"Chunk.modulesSize",
"DEP_WEBPACK_CHUNK_MODULES_SIZE"
);
return chunkGraph.getChunkModulesSize(this);
}
@ -282,7 +303,11 @@ class Chunk {
* @returns {number} total size of this chunk
*/
size(options = {}) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(this, "Chunk.size");
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.size",
"DEP_WEBPACK_CHUNK_SIZE"
);
return chunkGraph.getChunkSize(this, options);
}
@ -294,7 +319,8 @@ class Chunk {
integratedSize(otherChunk, options) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.integratedSize"
"Chunk.integratedSize",
"DEP_WEBPACK_CHUNK_INTEGRATED_SIZE"
);
return chunkGraph.getIntegratedChunksSize(this, otherChunk, options);
}
@ -306,7 +332,8 @@ class Chunk {
getChunkModuleMaps(filterFn) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.getChunkModuleMaps"
"Chunk.getChunkModuleMaps",
"DEP_WEBPACK_CHUNK_GET_CHUNK_MODULE_MAPS"
);
return chunkGraph.getChunkModuleMaps(this, filterFn);
}
@ -319,7 +346,8 @@ class Chunk {
hasModuleInGraph(filterFn, filterChunkFn) {
const chunkGraph = ChunkGraph.getChunkGraphForChunk(
this,
"Chunk.hasModuleInGraph"
"Chunk.hasModuleInGraph",
"DEP_WEBPACK_CHUNK_HAS_MODULE_IN_GRAPH"
);
return chunkGraph.hasModuleInGraph(this, filterFn, filterChunkFn);
}

View File

@ -1141,9 +1141,10 @@ class ChunkGraph {
/**
* @param {Module} module the module
* @param {string} deprecateMessage message for the deprecation message
* @param {string} deprecationCode code for the deprecation
* @returns {ChunkGraph} the chunk graph
*/
static getChunkGraphForModule(module, deprecateMessage) {
static getChunkGraphForModule(module, deprecateMessage, deprecationCode) {
const fn = deprecateGetChunkGraphForModuleMap.get(deprecateMessage);
if (fn) return fn(module);
const newFn = util.deprecate(
@ -1160,7 +1161,8 @@ class ChunkGraph {
);
return chunkGraph;
},
deprecateMessage + ": Use new ChunkGraph API"
deprecateMessage + ": Use new ChunkGraph API",
deprecationCode
);
deprecateGetChunkGraphForModuleMap.set(deprecateMessage, newFn);
return newFn(module);
@ -1180,9 +1182,10 @@ class ChunkGraph {
/**
* @param {Chunk} chunk the chunk
* @param {string} deprecateMessage message for the deprecation message
* @param {string} deprecationCode code for the deprecation
* @returns {ChunkGraph} the chunk graph
*/
static getChunkGraphForChunk(chunk, deprecateMessage) {
static getChunkGraphForChunk(chunk, deprecateMessage, deprecationCode) {
const fn = deprecateGetChunkGraphForChunkMap.get(deprecateMessage);
if (fn) return fn(chunk);
const newFn = util.deprecate(
@ -1199,7 +1202,8 @@ class ChunkGraph {
);
return chunkGraph;
},
deprecateMessage + ": Use new ChunkGraph API"
deprecateMessage + ": Use new ChunkGraph API",
deprecationCode
);
deprecateGetChunkGraphForChunkMap.set(deprecateMessage, newFn);
return newFn(chunk);

View File

@ -550,12 +550,14 @@ class ChunkGroup {
ChunkGroup.prototype.getModuleIndex = util.deprecate(
ChunkGroup.prototype.getModulePreOrderIndex,
"ChunkGroup.getModuleIndex was renamed to getModulePreOrderIndex"
"ChunkGroup.getModuleIndex was renamed to getModulePreOrderIndex",
"DEP_WEBPACK_CHUNK_GROUP_GET_MODULE_INDEX"
);
ChunkGroup.prototype.getModuleIndex2 = util.deprecate(
ChunkGroup.prototype.getModulePostOrderIndex,
"ChunkGroup.getModuleIndex2 was renamed to getModulePostOrderIndex"
"ChunkGroup.getModuleIndex2 was renamed to getModulePostOrderIndex",
"DEP_WEBPACK_CHUNK_GROUP_GET_MODULE_INDEX_2"
);
module.exports = ChunkGroup;

View File

@ -184,9 +184,13 @@ const { arrayToSetDeprecation } = require("./util/deprecation");
*/
// TODO webpack 6: remove
const deprecatedNormalModuleLoaderHook = util.deprecate(compilation => {
return require("./NormalModule").getCompilationHooks(compilation).loader;
}, "Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader");
const deprecatedNormalModuleLoaderHook = util.deprecate(
compilation => {
return require("./NormalModule").getCompilationHooks(compilation).loader;
},
"Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader",
"DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK"
);
const byId = compareSelect(
/**
@ -2173,8 +2177,7 @@ class Compilation {
emitAsset(file, source, assetInfo = {}) {
if (this.assets[file]) {
if (!isSourceEqual(this.assets[file], source)) {
// TODO webpack 5: make this an error instead
this.warnings.push(
this.errors.push(
new WebpackError(
`Conflict: Multiple assets emit different content to the same filename ${file}`
)

View File

@ -5,9 +5,19 @@
"use strict";
const util = require("util");
const ExternalModule = require("./ExternalModule");
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9]+ /;
// TODO webpack 6 remove this
const callDeprecatedExternals = util.deprecate(
(externalsFunction, context, request, cb) => {
externalsFunction.call(null, context, request, cb);
},
"The externals-function should be defined like ({context, request}, cb) => { ... }",
"DEP_WEBPACK_EXTERNALS_FUNCTION_PARAMETERS"
);
class ExternalModuleFactoryPlugin {
constructor(type, externals) {
this.type = type;
@ -104,9 +114,13 @@ class ExternalModuleFactoryPlugin {
}
};
if (externals.length === 3) {
// TODO webpack 5 insert deprecation message here
// TODO webpack 6 remove this
externals.call(null, context, dependency.request, cb);
callDeprecatedExternals(
externals,
context,
dependency.request,
cb
);
} else {
externals(
{

View File

@ -127,9 +127,11 @@ class Module extends DependenciesBlock {
// TODO remove in webpack 6
// BACKWARD-COMPAT START
get id() {
return ChunkGraph.getChunkGraphForModule(this, "Module.id").getModuleId(
this
);
return ChunkGraph.getChunkGraphForModule(
this,
"Module.id",
"DEP_WEBPACK_MODULE_ID"
).getModuleId(this);
}
set id(value) {
@ -137,19 +139,22 @@ class Module extends DependenciesBlock {
this.needId = false;
return;
}
ChunkGraph.getChunkGraphForModule(this, "Module.id").setModuleId(
ChunkGraph.getChunkGraphForModule(
this,
value
);
"Module.id",
"DEP_WEBPACK_MODULE_ID"
).setModuleId(this, value);
}
/**
* @returns {string} the hash of the module
*/
get hash() {
return ChunkGraph.getChunkGraphForModule(this, "Module.hash").getModuleHash(
this
);
return ChunkGraph.getChunkGraphForModule(
this,
"Module.hash",
"DEP_WEBPACK_MODULE_HASH"
).getModuleHash(this);
}
/**
@ -158,102 +163,122 @@ class Module extends DependenciesBlock {
get renderedHash() {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.renderedHash"
"Module.renderedHash",
"DEP_WEBPACK_MODULE_RENDERED_HASHED"
).getRenderedModuleHash(this);
}
get profile() {
return ModuleGraph.getModuleGraphForModule(
this,
"Module.profile"
"Module.profile",
"DEP_WEBPACK_MODULE_PROFILE"
).getProfile(this);
}
set profile(value) {
ModuleGraph.getModuleGraphForModule(this, "Module.profile").setProfile(
ModuleGraph.getModuleGraphForModule(
this,
value
);
"Module.profile",
"DEP_WEBPACK_MODULE_PROFILE"
).setProfile(this, value);
}
get index() {
return ModuleGraph.getModuleGraphForModule(
this,
"Module.index"
"Module.index",
"DEP_WEBPACK_MODULE_INDEX"
).getPreOrderIndex(this);
}
set index(value) {
ModuleGraph.getModuleGraphForModule(this, "Module.index").setPreOrderIndex(
ModuleGraph.getModuleGraphForModule(
this,
value
);
"Module.index",
"DEP_WEBPACK_MODULE_INDEX"
).setPreOrderIndex(this, value);
}
get index2() {
return ModuleGraph.getModuleGraphForModule(
this,
"Module.index2"
"Module.index2",
"DEP_WEBPACK_MODULE_INDEX2"
).getPostOrderIndex(this);
}
set index2(value) {
ModuleGraph.getModuleGraphForModule(
this,
"Module.index2"
"Module.index2",
"DEP_WEBPACK_MODULE_INDEX2"
).setPostOrderIndex(this, value);
}
get depth() {
return ModuleGraph.getModuleGraphForModule(this, "Module.depth").getDepth(
this
);
return ModuleGraph.getModuleGraphForModule(
this,
"Module.depth",
"DEP_WEBPACK_MODULE_DEPTH"
).getDepth(this);
}
set depth(value) {
ModuleGraph.getModuleGraphForModule(this, "Module.depth").setDepth(
ModuleGraph.getModuleGraphForModule(
this,
value
);
"Module.depth",
"DEP_WEBPACK_MODULE_DEPTH"
).setDepth(this, value);
}
get issuer() {
return ModuleGraph.getModuleGraphForModule(this, "Module.issuer").getIssuer(
this
);
return ModuleGraph.getModuleGraphForModule(
this,
"Module.issuer",
"DEP_WEBPACK_MODULE_ISSUER"
).getIssuer(this);
}
set issuer(value) {
ModuleGraph.getModuleGraphForModule(this, "Module.issuer").setIssuer(
ModuleGraph.getModuleGraphForModule(
this,
value
);
"Module.issuer",
"DEP_WEBPACK_MODULE_ISSUER"
).setIssuer(this, value);
}
get usedExports() {
return ModuleGraph.getModuleGraphForModule(
this,
"Module.usedExports"
"Module.usedExports",
"DEP_WEBPACK_MODULE_USED_EXPORTS"
).getUsedExports(this);
}
get optimizationBailout() {
return ModuleGraph.getModuleGraphForModule(
this,
"Module.optimizationBailout"
"Module.optimizationBailout",
"DEP_WEBPACK_MODULE_OPTIMIZATION_BAILOUT"
).getOptimizationBailout(this);
}
get optional() {
return this.isOptional(
ModuleGraph.getModuleGraphForModule(this, "Module.optional")
ModuleGraph.getModuleGraphForModule(
this,
"Module.optional",
"DEP_WEBPACK_MODULE_OPTIONAL"
)
);
}
addChunk(chunk) {
const chunkGraph = ChunkGraph.getChunkGraphForModule(
this,
"Module.addChunk"
"Module.addChunk",
"DEP_WEBPACK_MODULE_ADD_CHUNK"
);
if (chunkGraph.isModuleInChunk(this, chunk)) return false;
chunkGraph.connectChunkAndModule(chunk, this);
@ -263,42 +288,48 @@ class Module extends DependenciesBlock {
removeChunk(chunk) {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.removeChunk"
"Module.removeChunk",
"DEP_WEBPACK_MODULE_REMOVE_CHUNK"
).disconnectChunkAndModule(chunk, this);
}
isInChunk(chunk) {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.isInChunk"
"Module.isInChunk",
"DEP_WEBPACK_MODULE_IS_IN_CHUNK"
).isModuleInChunk(this, chunk);
}
isEntryModule() {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.isEntryModule"
"Module.isEntryModule",
"DEP_WEBPACK_MODULE_IS_ENTRY_MODULE"
).isEntryModule(this);
}
getChunks() {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.getChunks"
"Module.getChunks",
"DEP_WEBPACK_MODULE_GET_CHUNKS"
).getModuleChunks(this);
}
getNumberOfChunks() {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.getNumberOfChunks"
"Module.getNumberOfChunks",
"DEP_WEBPACK_MODULE_GET_NUMBER_OF_CHUNKS"
).getNumberOfModuleChunks(this);
}
get chunksIterable() {
return ChunkGraph.getChunkGraphForModule(
this,
"Module.chunksIterable"
"Module.chunksIterable",
"DEP_WEBPACK_MODULE_CHUNKS_ITERABLE"
).getOrderedModuleChunksIterable(this, compareChunksById);
}
@ -311,7 +342,8 @@ class Module extends DependenciesBlock {
isProvided(exportName) {
return ModuleGraph.getModuleGraphForModule(
this,
"Module.usedExports"
"Module.usedExports",
"DEP_WEBPACK_MODULE_USED_EXPORTS"
).isExportProvided(this, exportName);
}
// BACKWARD-COMPAT END
@ -559,7 +591,11 @@ class Module extends DependenciesBlock {
*/
updateHash(
hash,
chunkGraph = ChunkGraph.getChunkGraphForModule(this, "Module.updateHash")
chunkGraph = ChunkGraph.getChunkGraphForModule(
this,
"Module.updateHash",
"DEP_WEBPACK_MODULE_UPDATE_HASH"
)
) {
hash.update(`${chunkGraph.getModuleId(this)}`);
const exportsInfo = chunkGraph.moduleGraph.getExportsInfo(this);

View File

@ -1272,9 +1272,10 @@ class ModuleGraph {
/**
* @param {Module} module the module
* @param {string} deprecateMessage message for the deprecation message
* @param {string} deprecationCode code for the deprecation
* @returns {ModuleGraph} the module graph
*/
static getModuleGraphForModule(module, deprecateMessage) {
static getModuleGraphForModule(module, deprecateMessage, deprecationCode) {
const fn = deprecateMap.get(deprecateMessage);
if (fn) return fn(module);
const newFn = util.deprecate(
@ -1291,7 +1292,8 @@ class ModuleGraph {
);
return moduleGraph;
},
deprecateMessage + ": Use new ModuleGraph API"
deprecateMessage + ": Use new ModuleGraph API",
deprecationCode
);
deprecateMap.set(deprecateMessage, newFn);
return newFn(module);

View File

@ -67,10 +67,10 @@ const replacer = (value, allowEmpty) => {
const deprecationCache = new Map();
const deprecatedFunction = (() => () => {})();
const deprecated = (fn, message) => {
const deprecated = (fn, message, code) => {
let d = deprecationCache.get(message);
if (d === undefined) {
d = util.deprecate(deprecatedFunction, message);
d = util.deprecate(deprecatedFunction, message, code);
deprecationCache.set(message, d);
}
return (...args) => {
@ -130,7 +130,11 @@ const replacePathVariables = (path, data, assetInfo) => {
// Legacy
replacements.set(
"filebase",
deprecated(replacer(base), "[filebase] is now [base]")
deprecated(
replacer(base),
"[filebase] is now [base]",
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
)
);
}
}
@ -158,7 +162,8 @@ const replacePathVariables = (path, data, assetInfo) => {
"hash",
deprecated(
hashReplacer,
"[hash] is now [fullhash] (also consider using [chunkhash] or [contenthash], see documentation for details)"
"[hash] is now [fullhash] (also consider using [chunkhash] or [contenthash], see documentation for details)",
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_HASH"
)
);
}
@ -237,11 +242,19 @@ const replacePathVariables = (path, data, assetInfo) => {
// Legacy
replacements.set(
"moduleid",
deprecated(idReplacer, "[moduleid] is now [id]")
deprecated(
idReplacer,
"[moduleid] is now [id]",
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_MODULE_ID"
)
);
replacements.set(
"modulehash",
deprecated(hashReplacer, "[modulehash] is now [hash]")
deprecated(
hashReplacer,
"[modulehash] is now [hash]",
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_MODULE_HASH"
)
);
}

View File

@ -78,7 +78,8 @@ exportPlugins(module.exports, {
RuntimeModule: () => require("./RuntimeModule"),
SingleEntryPlugin: util.deprecate(
() => require("./EntryPlugin"),
"SingleEntryPlugin was renamed to EntryPlugin"
"SingleEntryPlugin was renamed to EntryPlugin",
"DEP_WEBPACK_SINGLE_ENTRY_PLUGIN"
),
SetVarTemplatePlugin: () => require("./SetVarTemplatePlugin"),
SourceMapDevToolPlugin: () => require("./SourceMapDevToolPlugin"),
@ -112,7 +113,8 @@ exportPlugins((module.exports.optimize = {}), {
AggressiveMergingPlugin: () => require("./optimize/AggressiveMergingPlugin"),
AggressiveSplittingPlugin: util.deprecate(
() => require("./optimize/AggressiveSplittingPlugin"),
"AggressiveSplittingPlugin is deprecated in favor of SplitChunksPlugin"
"AggressiveSplittingPlugin is deprecated in favor of SplitChunksPlugin",
"DEP_WEBPACK_AGGRESSIVE_SPLITTING_PLUGIN"
),
LimitChunkCountPlugin: () => require("./optimize/LimitChunkCountPlugin"),
MinChunkSizePlugin: () => require("./optimize/MinChunkSizePlugin"),

View File

@ -25,7 +25,8 @@ const InitFragment = require("../InitFragment");
const deprecatedGetInitFragments = util.deprecate(
(template, dependency, templateContext) =>
template.getInitFragments(dependency, templateContext),
"DependencyTemplate.getInitFragment is deprecated (use apply(dep, source, { initFragments }) instead)"
"DependencyTemplate.getInitFragment is deprecated (use apply(dep, source, { initFragments }) instead)",
"DEP_WEBPACK_JAVASCRIPT_GENERATOR_GET_INIT_FRAGMENTS"
);
const TYPES = new Set(["javascript"]);

View File

@ -12,12 +12,17 @@ const deprecationCache = new Map();
/**
* @param {string} message deprecation message
* @param {string} code deprecation code
* @returns {Function} function to trigger deprecation
*/
const createDeprecation = message => {
const createDeprecation = (message, code) => {
const cached = deprecationCache.get(message);
if (cached !== undefined) return cached;
const fn = util.deprecate(() => {}, message);
const fn = util.deprecate(
() => {},
message,
"DEP_WEBPACK_DEPRECATION_" + code
);
deprecationCache.set(message, fn);
return fn;
};
@ -61,7 +66,8 @@ exports.arrayToSetDeprecation = (set, name) => {
for (const method of COPY_METHODS) {
if (set[method]) continue;
const d = createDeprecation(
`${name} was changed from Array to Set (using Array method '${method}' is deprecated)`
`${name} was changed from Array to Set (using Array method '${method}' is deprecated)`,
"ARRAY_TO_SET"
);
/**
* @deprecated
@ -75,13 +81,16 @@ exports.arrayToSetDeprecation = (set, name) => {
};
}
const dPush = createDeprecation(
`${name} was changed from Array to Set (using Array method 'push' is deprecated)`
`${name} was changed from Array to Set (using Array method 'push' is deprecated)`,
"ARRAY_TO_SET_PUSH"
);
const dLength = createDeprecation(
`${name} was changed from Array to Set (using Array property 'length' is deprecated)`
`${name} was changed from Array to Set (using Array property 'length' is deprecated)`,
"ARRAY_TO_SET_LENGTH"
);
const dIndexer = createDeprecation(
`${name} was changed from Array to Set (indexing Array is deprecated)`
`${name} was changed from Array to Set (indexing Array is deprecated)`,
"ARRAY_TO_SET_INDEXER"
);
/**
* @deprecated

View File

@ -414,11 +414,7 @@ class WebAssemblyGenerator extends Generator {
* @returns {Source} generated code
*/
generate(module, { moduleGraph }) {
const source = module.originalSource().source();
// TODO remove this casts when webpack-sources is fixed
// source() should have return type (string | Buffer)
const sourceAsAny = /** @type {TODO} */ (source);
const bin = /** @type {Buffer} */ (sourceAsAny);
const bin = module.originalSource().source();
const initFuncId = t.identifier("");