MCPcopy
hub / github.com/webpack/webpack / accessorAccess

Function accessorAccess

lib/library/UmdLibraryPlugin.js:45–59  ·  view source on GitHub ↗
(base, accessor, joinWith = ", ")

Source from the content-addressed store, hash-verified

43 * @returns {string} the path
44 */
45const accessorAccess = (base, accessor, joinWith = ", ") => {
46 const accessors = Array.isArray(accessor) ? accessor : [accessor];
47 return accessors
48 .map((_, idx) => {
49 const a = base
50 ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
51 : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
52 if (idx === accessors.length - 1) return a;
53 if (idx === 0 && base === undefined) {
54 return `${a} = typeof ${a} === "object" ? ${a} : {}`;
55 }
56 return `${a} = ${a} || {}`;
57 })
58 .join(joinWith);
59};
60
61/**
62 * Defines the umd library plugin options type used by this module.

Callers 1

renderMethod · 0.85

Calls 3

accessorToObjectAccessFunction · 0.85
isArrayMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected