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

Function enter

packages/commonjs/src/transform-commonjs.js:112–420  ·  view source on GitHub ↗
(node, parent)

Source from the content-addressed store, hash-verified

110
111 walk(ast, {
112 enter(node, parent) {
113 if (skippedNodes.has(node)) {
114 this.skip();
115 return;
116 }
117
118 if (currentTryBlockEnd !== null && node.start > currentTryBlockEnd) {
119 currentTryBlockEnd = null;
120 }
121 if (currentConditionalNodeEnd !== null && node.start > currentConditionalNodeEnd) {
122 currentConditionalNodeEnd = null;
123 }
124 if (currentConditionalNodeEnd === null && conditionalNodes.has(node)) {
125 currentConditionalNodeEnd = node.end;
126 }
127
128 programDepth += 1;
129 if (node.scope) ({ scope } = node);
130 if (functionType.test(node.type)) lexicalDepth += 1;
131 if (sourceMap) {
132 magicString.addSourcemapLocation(node.start);
133 magicString.addSourcemapLocation(node.end);
134 }
135
136 // eslint-disable-next-line default-case
137 switch (node.type) {
138 case 'AssignmentExpression':
139 if (node.left.type === 'MemberExpression') {
140 const flattened = getKeypath(node.left);
141 if (!flattened || scope.contains(flattened.name)) return;
142
143 const exportsPatternMatch = exportsPattern.exec(flattened.keypath);
144 if (!exportsPatternMatch || flattened.keypath === 'exports') return;
145
146 const [, exportName] = exportsPatternMatch;
147 uses[flattened.name] = true;
148
149 // we're dealing with `module.exports = ...` or `[module.]exports.foo = ...` –
150 if (flattened.keypath === 'module.exports') {
151 moduleExportsAssignments.push(node);
152 if (programDepth > 3) {
153 moduleAccessScopes.add(scope);
154 } else if (!firstTopLevelModuleExportsAssignment) {
155 firstTopLevelModuleExportsAssignment = node;
156 }
157 } else if (exportName === KEY_COMPILED_ESM) {
158 if (programDepth > 3) {
159 shouldWrap = true;
160 } else {
161 // The "type" is either "module" or "exports" to discern
162 // assignments to module.exports vs exports if needed
163 topLevelDefineCompiledEsmExpressions.push({ node, type: flattened.name });
164 }
165 } else {
166 const exportsAssignments = exportsAssignmentsByName.get(exportName) || {
167 nodes: [],
168 scopes: new Set()
169 };

Callers

nothing calls this directly

Calls 15

getKeypathFunction · 0.90
extractAssignedNamesFunction · 0.90
getDefineCompiledEsmTypeFunction · 0.90
isRequireFunction · 0.90
isRequireExpressionFunction · 0.90
hasDynamicArgumentsFunction · 0.90
getRequireStringArgFunction · 0.90
isFalsyFunction · 0.90
isTruthyFunction · 0.90
isPropertyDefinitionKeyFunction · 0.90
isShorthandPropertyFunction · 0.90

Tested by

no test coverage detected