MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / applyImportAndExportNameChanges

Function applyImportAndExportNameChanges

tools/acorn-optimizer.mjs:466–499  ·  view source on GitHub ↗
(ast)

Source from the content-addressed store, hash-verified

464
465// Apply import/export name changes (after minifying them)
466function applyImportAndExportNameChanges(ast) {
467 const mapping = extraInfo.mapping;
468 fullWalk(ast, (node) => {
469 if (isWasmImportsAssign(node)) {
470 const assignedObject = getWasmImportsValue(node);
471 assignedObject.properties.forEach((item) => {
472 if (mapping[item.key.name]) {
473 item.key.name = mapping[item.key.name];
474 }
475 });
476 } else if (node.type === 'AssignmentExpression') {
477 const value = node.right;
478 if (isExportUse(value)) {
479 const name = value.property.value;
480 if (mapping[name]) {
481 setLiteralValue(value.property, mapping[name]);
482 }
483 }
484 } else if (node.type === 'CallExpression' && isExportUse(node.callee)) {
485 // wasmExports["___wasm_call_ctors"](); -> wasmExports["M"]();
486 const callee = node.callee;
487 const name = callee.property.value;
488 if (mapping[name]) {
489 setLiteralValue(callee.property, mapping[name]);
490 }
491 } else if (isExportUse(node)) {
492 const prop = node.property;
493 const name = prop.value;
494 if (mapping[name]) {
495 setLiteralValue(prop, mapping[name]);
496 }
497 }
498 });
499}
500
501// A static dyncall is dynCall('vii', ..), which is actually static even
502// though we call dynCall() - we see the string signature statically.

Callers

nothing calls this directly

Calls 6

fullWalkFunction · 0.85
isWasmImportsAssignFunction · 0.85
getWasmImportsValueFunction · 0.85
isExportUseFunction · 0.85
setLiteralValueFunction · 0.85
forEachMethod · 0.80

Tested by

no test coverage detected