MCPcopy Create free account
hub / github.com/rollup/plugins / getDefinePropertyCallName

Function getDefinePropertyCallName

packages/commonjs/src/ast-utils.js:91–124  ·  view source on GitHub ↗
(node, targetName)

Source from the content-addressed store, hash-verified

89}
90
91function getDefinePropertyCallName(node, targetName) {
92 const {
93 callee: { object, property }
94 } = node;
95 if (!object || object.type !== 'Identifier' || object.name !== 'Object') return;
96 if (!property || property.type !== 'Identifier' || property.name !== 'defineProperty') return;
97 if (node.arguments.length !== 3) return;
98
99 const targetNames = targetName.split('.');
100 const [target, key, value] = node.arguments;
101 if (targetNames.length === 1) {
102 if (target.type !== 'Identifier' || target.name !== targetNames[0]) {
103 return;
104 }
105 }
106
107 if (targetNames.length === 2) {
108 if (
109 target.type !== 'MemberExpression' ||
110 target.object.name !== targetNames[0] ||
111 target.property.name !== targetNames[1]
112 ) {
113 return;
114 }
115 }
116
117 if (value.type !== 'ObjectExpression' || !value.properties) return;
118
119 const valueProperty = value.properties.find((p) => p.key && p.key.name === 'value');
120 if (!valueProperty || !valueProperty.value) return;
121
122 // eslint-disable-next-line consistent-return
123 return { key: key.value, value: valueProperty.value };
124}
125
126export function isShorthandProperty(parent) {
127 return parent && parent.type === 'Property' && parent.shorthand;

Callers 1

getDefineCompiledEsmTypeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected