/var/www/cobraambalaj/node_modules/webpack/lib
NameSizeModeActions
asset/-0755rm
async-modules/-0755rm
cache/-0755rm
config/-0755rm
container/-0755rm
debug/-0755rm
dependencies/-0755rm
electron/-0755rm
errors/-0755rm
hmr/-0755rm
ids/-0755rm
javascript/-0755rm
json/-0755rm
library/-0755rm
logging/-0755rm
node/-0755rm
optimize/-0755rm
performance/-0755rm
prefetch/-0755rm
rules/-0755rm
runtime/-0755rm
schemes/-0755rm
serialization/-0755rm
sharing/-0755rm
stats/-0755rm
util/-0755rm
wasm/-0755rm
wasm-async/-0755rm
wasm-sync/-0755rm
web/-0755rm
webworker/-0755rm
AbstractMethodError.js11330644editdlrm
APIPlugin.js57190644editdlrm
AsyncDependenciesBlock.js27330644editdlrm
AsyncDependencyToInitialChunkError.js9650644editdlrm
AutomaticPrefetchPlugin.js14910644editdlrm
BannerPlugin.js26470644editdlrm
buildChunkGraph.js429040644editdlrm
Cache.js39670644editdlrm
CacheFacade.js84330644editdlrm
CaseSensitiveModulesWarning.js21460644editdlrm
Chunk.js200420644editdlrm
ChunkGraph.js460710644editdlrm
ChunkGroup.js151210644editdlrm
ChunkRenderError.js7090644editdlrm
ChunkTemplate.js39920644editdlrm
CleanPlugin.js99400644editdlrm
cli.js156030644editdlrm
CodeGenerationError.js6710644editdlrm
CodeGenerationResults.js42660644editdlrm
CommentCompilationWarning.js7810644editdlrm
CompatibilityPlugin.js41810644editdlrm
Compilation.js1220130644editdlrm
Compiler.js316430644editdlrm
ConcatenationScope.js46350644editdlrm
ConcurrentCompilationError.js4930644editdlrm
ConditionalInitFragment.js35370644editdlrm
ConstPlugin.js147690644editdlrm
ContextExclusionPlugin.js7970644editdlrm
ContextModule.js321710644editdlrm
ContextModuleFactory.js110890644editdlrm
ContextReplacementPlugin.js47110644editdlrm
DefinePlugin.js99700644editdlrm
DelegatedModule.js70430644editdlrm
DelegatedModuleFactoryPlugin.js23370644editdlrm
DelegatedPlugin.js10150644editdlrm
DependenciesBlock.js23790644editdlrm
Dependency.js66940644editdlrm
DependencyTemplate.js19900644editdlrm
DependencyTemplates.js15270644editdlrm
DllEntryPlugin.js12770644editdlrm
DllModule.js43130644editdlrm
DllModuleFactory.js10080644editdlrm
DllPlugin.js15970644editdlrm
DllReferencePlugin.js50700644editdlrm
DynamicEntryPlugin.js20350644editdlrm
EntryOptionPlugin.js27470644editdlrm
EntryPlugin.js17380644editdlrm
Entrypoint.js30250644editdlrm
EnvironmentPlugin.js17430644editdlrm
ErrorHelpers.js14540644editdlrm
EvalDevToolModulePlugin.js32350644editdlrm
EvalSourceMapDevToolPlugin.js62390644editdlrm
ExportsInfo.js426600644editdlrm
ExportsInfoApiPlugin.js20720644editdlrm
ExternalModule.js148400644editdlrm
ExternalModuleFactoryPlugin.js72050644editdlrm
ExternalsPlugin.js8990644editdlrm
FileSystemInfo.js815140644editdlrm
FlagAllModulesAsUsedPlugin.js14510644editdlrm
FlagDependencyExportsPlugin.js116030644editdlrm
FlagDependencyUsagePlugin.js107800644editdlrm
FlagEntryExportAsUsedPlugin.js13730644editdlrm
formatLocation.js17810644editdlrm
Generator.js45710644editdlrm
GraphHelpers.js10740644editdlrm
HarmonyLinkingError.js4090644editdlrm
HookWebpackError.js21210644editdlrm
HotModuleReplacementPlugin.js255260644editdlrm
HotUpdateChunk.js3530644editdlrm
IgnoreErrorModuleFactory.js10480644editdlrm
IgnorePlugin.js21440644editdlrm
IgnoreWarningsPlugin.js9640644editdlrm
index.js140630644editdlrm
InitFragment.js36590644editdlrm
InvalidDependenciesModuleWarning.js19260644editdlrm
JavascriptMetaInfoPlugin.js18850644editdlrm
LibManifestPlugin.js31160644editdlrm
LibraryTemplatePlugin.js15880644editdlrm
LoaderOptionsPlugin.js17430644editdlrm
LoaderTargetPlugin.js7470644editdlrm
MainTemplate.js103770644editdlrm
Module.js285360644editdlrm
ModuleBuildError.js16780644editdlrm
ModuleDependencyError.js11590644editdlrm
ModuleDependencyWarning.js12740644editdlrm
ModuleError.js12540644editdlrm
ModuleFactory.js13630644editdlrm
ModuleFilenameHelpers.js74300644editdlrm
ModuleGraph.js218860644editdlrm
ModuleGraphConnection.js52030644editdlrm
ModuleInfoHeaderPlugin.js71820644editdlrm
ModuleNotFoundError.js26620644editdlrm
ModuleParseError.js33840644editdlrm
ModuleProfile.js24400644editdlrm
ModuleRestoreError.js10090644editdlrm
ModuleStoreError.js10030644editdlrm
ModuleTemplate.js43370644editdlrm
ModuleWarning.js13320644editdlrm
MultiCompiler.js144700644editdlrm
MultiStats.js42220644editdlrm
MultiWatching.js14660644editdlrm
NodeStuffPlugin.js40160644editdlrm
NoEmitOnErrorsPlugin.js7130644editdlrm
NoModeWarning.js7150644editdlrm
NormalModule.js343240644editdlrm
NormalModuleFactory.js291220644editdlrm
NormalModuleReplacementPlugin.js18830644editdlrm
NullFactory.js6280644editdlrm
OptimizationStages.js2040644editdlrm
OptionsApply.js2010644editdlrm
Parser.js9300644editdlrm
PrefetchPlugin.js10480644editdlrm
ProgressPlugin.js171450644editdlrm
ProvidePlugin.js28900644editdlrm
RawModule.js42750644editdlrm
RecordIdsPlugin.js67750644editdlrm
RequestShortener.js7550644editdlrm
RequireJsStuffPlugin.js19040644editdlrm
ResolverFactory.js49380644editdlrm
RuntimeGlobals.js75690644editdlrm
RuntimeModule.js55200644editdlrm
RuntimePlugin.js118420644editdlrm
RuntimeTemplate.js276560644editdlrm
SelfModuleFactory.js3840644editdlrm
SingleEntryPlugin.js1610644editdlrm
SizeFormatHelpers.js5830644editdlrm
SourceMapDevToolModuleOptionsPlugin.js13250644editdlrm
SourceMapDevToolPlugin.js166310644editdlrm
Stats.js20030644editdlrm
Template.js127010644editdlrm
TemplatedPathPlugin.js80360644editdlrm
UnhandledSchemeError.js8330644editdlrm
UnsupportedFeatureWarning.js8320644editdlrm
UseStrictPlugin.js16450644editdlrm
validateSchema.js63760644editdlrm
WarnCaseSensitiveModulesPlugin.js12120644editdlrm
WarnDeprecatedOptionPlugin.js13270644editdlrm
WarnNoModeSetPlugin.js5450644editdlrm
WatchIgnorePlugin.js28160644editdlrm
Watching.js103350644editdlrm
webpack.js47220644editdlrm
WebpackError.js14290644editdlrm
WebpackIsIncludedPlugin.js24200644editdlrm
WebpackOptionsApply.js226510644editdlrm
WebpackOptionsDefaulter.js4700644editdlrm
Edit: /var/www/cobraambalaj/node_modules/webpack/lib/ConstPlugin.js (14769B)
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const CachedConstDependency = require("./dependencies/CachedConstDependency"); const ConstDependency = require("./dependencies/ConstDependency"); const { evaluateToString } = require("./javascript/JavascriptParserHelpers"); const { parseResource } = require("./util/identifier"); /** @typedef {import("estree").Expression} ExpressionNode */ /** @typedef {import("estree").Super} SuperNode */ /** @typedef {import("./Compiler")} Compiler */ const collectDeclaration = (declarations, pattern) => { const stack = [pattern]; while (stack.length > 0) { const node = stack.pop(); switch (node.type) { case "Identifier": declarations.add(node.name); break; case "ArrayPattern": for (const element of node.elements) { if (element) { stack.push(element); } } break; case "AssignmentPattern": stack.push(node.left); break; case "ObjectPattern": for (const property of node.properties) { stack.push(property.value); } break; case "RestElement": stack.push(node.argument); break; } } }; const getHoistedDeclarations = (branch, includeFunctionDeclarations) => { const declarations = new Set(); const stack = [branch]; while (stack.length > 0) { const node = stack.pop(); // Some node could be `null` or `undefined`. if (!node) continue; switch (node.type) { // Walk through control statements to look for hoisted declarations. // Some branches are skipped since they do not allow declarations. case "BlockStatement": for (const stmt of node.body) { stack.push(stmt); } break; case "IfStatement": stack.push(node.consequent); stack.push(node.alternate); break; case "ForStatement": stack.push(node.init); stack.push(node.body); break; case "ForInStatement": case "ForOfStatement": stack.push(node.left); stack.push(node.body); break; case "DoWhileStatement": case "WhileStatement": case "LabeledStatement": stack.push(node.body); break; case "SwitchStatement": for (const cs of node.cases) { for (const consequent of cs.consequent) { stack.push(consequent); } } break; case "TryStatement": stack.push(node.block); if (node.handler) { stack.push(node.handler.body); } stack.push(node.finalizer); break; case "FunctionDeclaration": if (includeFunctionDeclarations) { collectDeclaration(declarations, node.id); } break; case "VariableDeclaration": if (node.kind === "var") { for (const decl of node.declarations) { collectDeclaration(declarations, decl.id); } } break; } } return Array.from(declarations); }; class ConstPlugin { /** * Apply the plugin * @param {Compiler} compiler the compiler instance * @returns {void} */ apply(compiler) { const cachedParseResource = parseResource.bindCache(compiler.root); compiler.hooks.compilation.tap( "ConstPlugin", (compilation, { normalModuleFactory }) => { compilation.dependencyTemplates.set( ConstDependency, new ConstDependency.Template() ); compilation.dependencyTemplates.set( CachedConstDependency, new CachedConstDependency.Template() ); const handler = parser => { parser.hooks.statementIf.tap("ConstPlugin", statement => { if (parser.scope.isAsmJs) return; const param = parser.evaluateExpression(statement.test); const bool = param.asBool(); if (typeof bool === "boolean") { if (!param.couldHaveSideEffects()) { const dep = new ConstDependency(`${bool}`, param.range); dep.loc = statement.loc; parser.state.module.addPresentationalDependency(dep); } else { parser.walkExpression(statement.test); } const branchToRemove = bool ? statement.alternate : statement.consequent; if (branchToRemove) { // Before removing the dead branch, the hoisted declarations // must be collected. // // Given the following code: // // if (true) f() else g() // if (false) { // function f() {} // const g = function g() {} // if (someTest) { // let a = 1 // var x, {y, z} = obj // } // } else { // … // } // // the generated code is: // // if (true) f() else {} // if (false) { // var f, x, y, z; (in loose mode) // var x, y, z; (in strict mode) // } else { // … // } // // NOTE: When code runs in strict mode, `var` declarations // are hoisted but `function` declarations don't. // let declarations; if (parser.scope.isStrict) { // If the code runs in strict mode, variable declarations // using `var` must be hoisted. declarations = getHoistedDeclarations(branchToRemove, false); } else { // Otherwise, collect all hoisted declaration. declarations = getHoistedDeclarations(branchToRemove, true); } let replacement; if (declarations.length > 0) { replacement = `{ var ${declarations.join(", ")}; }`; } else { replacement = "{}"; } const dep = new ConstDependency( replacement, branchToRemove.range ); dep.loc = branchToRemove.loc; parser.state.module.addPresentationalDependency(dep); } return bool; } }); parser.hooks.expressionConditionalOperator.tap( "ConstPlugin", expression => { if (parser.scope.isAsmJs) return; const param = parser.evaluateExpression(expression.test); const bool = param.asBool(); if (typeof bool === "boolean") { if (!param.couldHaveSideEffects()) { const dep = new ConstDependency(` ${bool}`, param.range); dep.loc = expression.loc; parser.state.module.addPresentationalDependency(dep); } else { parser.walkExpression(expression.test); } // Expressions do not hoist. // It is safe to remove the dead branch. // // Given the following code: // // false ? someExpression() : otherExpression(); // // the generated code is: // // false ? 0 : otherExpression(); // const branchToRemove = bool ? expression.alternate : expression.consequent; const dep = new ConstDependency("0", branchToRemove.range); dep.loc = branchToRemove.loc; parser.state.module.addPresentationalDependency(dep); return bool; } } ); parser.hooks.expressionLogicalOperator.tap( "ConstPlugin", expression => { if (parser.scope.isAsmJs) return; if ( expression.operator === "&&" || expression.operator === "||" ) { const param = parser.evaluateExpression(expression.left); const bool = param.asBool(); if (typeof bool === "boolean") { // Expressions do not hoist. // It is safe to remove the dead branch. // // ------------------------------------------ // // Given the following code: // // falsyExpression() && someExpression(); // // the generated code is: // // falsyExpression() && false; // // ------------------------------------------ // // Given the following code: // // truthyExpression() && someExpression(); // // the generated code is: // // true && someExpression(); // // ------------------------------------------ // // Given the following code: // // truthyExpression() || someExpression(); // // the generated code is: // // truthyExpression() || false; // // ------------------------------------------ // // Given the following code: // // falsyExpression() || someExpression(); // // the generated code is: // // false && someExpression(); // const keepRight = (expression.operator === "&&" && bool) || (expression.operator === "||" && !bool); if ( !param.couldHaveSideEffects() && (param.isBoolean() || keepRight) ) { // for case like // // return'development'===process.env.NODE_ENV&&'foo' // // we need a space before the bool to prevent result like // // returnfalse&&'foo' // const dep = new ConstDependency(` ${bool}`, param.range); dep.loc = expression.loc; parser.state.module.addPresentationalDependency(dep); } else { parser.walkExpression(expression.left); } if (!keepRight) { const dep = new ConstDependency( "0", expression.right.range ); dep.loc = expression.loc; parser.state.module.addPresentationalDependency(dep); } return keepRight; } } else if (expression.operator === "??") { const param = parser.evaluateExpression(expression.left); const keepRight = param && param.asNullish(); if (typeof keepRight === "boolean") { // ------------------------------------------ // // Given the following code: // // nonNullish ?? someExpression(); // // the generated code is: // // nonNullish ?? 0; // // ------------------------------------------ // // Given the following code: // // nullish ?? someExpression(); // // the generated code is: // // null ?? someExpression(); // if (!param.couldHaveSideEffects() && keepRight) { // cspell:word returnnull // for case like // // return('development'===process.env.NODE_ENV&&null)??'foo' // // we need a space before the bool to prevent result like // // returnnull??'foo' // const dep = new ConstDependency(" null", param.range); dep.loc = expression.loc; parser.state.module.addPresentationalDependency(dep); } else { const dep = new ConstDependency( "0", expression.right.range ); dep.loc = expression.loc; parser.state.module.addPresentationalDependency(dep); parser.walkExpression(expression.left); } return keepRight; } } } ); parser.hooks.optionalChaining.tap("ConstPlugin", expr => { /** @type {ExpressionNode[]} */ const optionalExpressionsStack = []; /** @type {ExpressionNode|SuperNode} */ let next = expr.expression; while ( next.type === "MemberExpression" || next.type === "CallExpression" ) { if (next.type === "MemberExpression") { if (next.optional) { // SuperNode can not be optional optionalExpressionsStack.push( /** @type {ExpressionNode} */ (next.object) ); } next = next.object; } else { if (next.optional) { // SuperNode can not be optional optionalExpressionsStack.push( /** @type {ExpressionNode} */ (next.callee) ); } next = next.callee; } } while (optionalExpressionsStack.length) { const expression = optionalExpressionsStack.pop(); const evaluated = parser.evaluateExpression(expression); if (evaluated && evaluated.asNullish()) { // ------------------------------------------ // // Given the following code: // // nullishMemberChain?.a.b(); // // the generated code is: // // undefined; // // ------------------------------------------ // const dep = new ConstDependency(" undefined", expr.range); dep.loc = expr.loc; parser.state.module.addPresentationalDependency(dep); return true; } } }); parser.hooks.evaluateIdentifier .for("__resourceQuery") .tap("ConstPlugin", expr => { if (parser.scope.isAsmJs) return; if (!parser.state.module) return; return evaluateToString( cachedParseResource(parser.state.module.resource).query )(expr); }); parser.hooks.expression .for("__resourceQuery") .tap("ConstPlugin", expr => { if (parser.scope.isAsmJs) return; if (!parser.state.module) return; const dep = new CachedConstDependency( JSON.stringify( cachedParseResource(parser.state.module.resource).query ), expr.range, "__resourceQuery" ); dep.loc = expr.loc; parser.state.module.addPresentationalDependency(dep); return true; }); parser.hooks.evaluateIdentifier .for("__resourceFragment") .tap("ConstPlugin", expr => { if (parser.scope.isAsmJs) return; if (!parser.state.module) return; return evaluateToString( cachedParseResource(parser.state.module.resource).fragment )(expr); }); parser.hooks.expression .for("__resourceFragment") .tap("ConstPlugin", expr => { if (parser.scope.isAsmJs) return; if (!parser.state.module) return; const dep = new CachedConstDependency( JSON.stringify( cachedParseResource(parser.state.module.resource).fragment ), expr.range, "__resourceFragment" ); dep.loc = expr.loc; parser.state.module.addPresentationalDependency(dep); return true; }); }; normalModuleFactory.hooks.parser .for("javascript/auto") .tap("ConstPlugin", handler); normalModuleFactory.hooks.parser .for("javascript/dynamic") .tap("ConstPlugin", handler); normalModuleFactory.hooks.parser .for("javascript/esm") .tap("ConstPlugin", handler); } ); } } module.exports = ConstPlugin;