MCPcopy
hub / github.com/webpack/webpack / isUndefinedMemberAccess

Method isUndefinedMemberAccess

lib/DefinePlugin.js:786–813  ·  view source on GitHub ↗
(members, deps)

Source from the content-addressed store, hash-verified

784 * @returns {boolean} true when the access resolves to `undefined`
785 */
786 const isUndefinedMemberAccess = (members, deps) => {
787 if (members.length <= chainPrefix.length) return false;
788 for (let i = 0; i < chainPrefix.length; i++) {
789 if (members[i] !== chainPrefix[i]) return false;
790 }
791 /** @type {CodeValue} */
792 let value = /** @type {CodeValue} */ (obj);
793 let path = key;
794 for (let i = chainPrefix.length; i < members.length; i++) {
795 // a leaf with members left is a real property access on a value
796 if (!isObjectDefinition(value)) return false;
797 const member = members[i];
798 const nextPath = `${path}.${member}`;
799 if (member in value) {
800 value = value[member];
801 } else if (
802 Object.prototype.hasOwnProperty.call(definitions, nextPath)
803 ) {
804 // defined via a dotted sibling key, e.g. `OBJECT.SUB2`
805 deps.push(nextPath);
806 value = definitions[nextPath];
807 } else {
808 return true;
809 }
810 path = nextPath;
811 }
812 return false;
813 };
814 parser.hooks.expressionMemberChain
815 .for(chainRoot)
816 .tap(PLUGIN_NAME, (expr, members) => {

Callers

nothing calls this directly

Calls 3

isObjectDefinitionFunction · 0.85
callMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected