MCPcopy
hub / github.com/webpack/webpack / setModuleConstant

Method setModuleConstant

lib/NodeStuffPlugin.js:132–156  ·  view source on GitHub ↗
(parser, expressionName, fn, property)

Source from the content-addressed store, hash-verified

130 * @returns {void}
131 */
132 const setModuleConstant = (parser, expressionName, fn, property) => {
133 parser.hooks.expression
134 .for(expressionName)
135 .tap(PLUGIN_NAME, (expr) => {
136 const dep = new ConstDependency(
137 fn(parser.state.module),
138 /** @type {Range} */
139 (expr.range)
140 );
141 dep.loc = /** @type {DependencyLocation} */ (expr.loc);
142 parser.state.module.addPresentationalDependency(dep);
143 return true;
144 });
145
146 if (
147 expressionName === IMPORT_META_FILENAME ||
148 expressionName === IMPORT_META_DIRNAME
149 ) {
150 hooks.propertyInDestructuring.tap(PLUGIN_NAME, (usingProperty) => {
151 if (usingProperty.id === property) {
152 return `${property}: ${fn(parser.state.module)},`;
153 }
154 });
155 }
156 };
157
158 /**
159 * Sets cached module constant.

Callers

nothing calls this directly

Calls 3

tapMethod · 0.80
fnFunction · 0.50

Tested by

no test coverage detected