MCPcopy
hub / github.com/webpack/webpack / walkDefinitionsForKeys

Method walkDefinitionsForKeys

lib/DefinePlugin.js:899–933  ·  lib/DefinePlugin.js::DefinePlugin.walkDefinitionsForKeys
(definitions)

Source from the content-addressed store, hash-verified

897 * @returns {void}
898 */
899 const walkDefinitionsForKeys = (definitions) => {
900 /**
901 * Adds the provided map to the define plugin.
902 * @param {Map<string, Set<string>>} map Map
903 * @param {string} key key
904 * @param {string} value v
905 * @returns {void}
906 */
907 const addToMap = (map, key, value) => {
908 if (map.has(key)) {
909 /** @type {Set<string>} */
910 (map.get(key)).add(value);
911 } else {
912 map.set(key, new Set([value]));
913 }
914 };
915 for (const key of Object.keys(definitions)) {
916 const code = definitions[key];
917 if (
918 !code ||
919 typeof code === class="st">"object" ||
920 TYPEOF_OPERATOR_REGEXP.test(key)
921 ) {
922 continue;
923 }
924 const idx = key.lastIndexOf(class="st">".");
925 if (idx <= 0 || idx >= key.length - 1) {
926 continue;
927 }
928 const nested = key.slice(0, idx);
929 const final = key.slice(idx + 1);
930 addToMap(finalByNestedKey, nested, final);
931 addToMap(nestedByFinalKey, final, nested);
932 }
933 };
934
935 walkDefinitionsForKeys(definitions);
936 walkDefinitionsForValues(definitions, class="st">"");

Callers

nothing calls this directly

Calls 3

sliceMethod · 0.80
keysMethod · 0.65
testMethod · 0.45

Tested by

no test coverage detected