From 52bc27a3f3e79dd516a984bd225e4605c4c82176 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Mon, 8 Jun 2026 15:40:08 +0100 Subject: [PATCH] refactor(build): Use a separate property for each chunk's exports The existing code results in each chunk overwriting the same well-known property ($.__chunkExports__). Since these properties are only expected to be read once, in the same chunk's wrapper's factory function, this isn't strictly wrong - but it made understanding the minified bundles produced by PR #9912 a bit confusing. --- .../blockly/scripts/gulpfiles/build_tasks.mjs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/blockly/scripts/gulpfiles/build_tasks.mjs b/packages/blockly/scripts/gulpfiles/build_tasks.mjs index be8017782..f8be51bda 100644 --- a/packages/blockly/scripts/gulpfiles/build_tasks.mjs +++ b/packages/blockly/scripts/gulpfiles/build_tasks.mjs @@ -87,12 +87,12 @@ const NAMESPACE_VARIABLE = '$'; const NAMESPACE_PROPERTY = '__namespace__'; /** - * Property on the shared namespace object where each chunk's export - * object is stored before the UMD wrapper returns it. A string literal - * is used so that Closure Compiler will not rename it when - * assume_function_wrapper is enabled (see issue #5795). + * Prefix for properties that will be used to store each chunk's + * export object on the namespace object. + * + * See buildChunkExporters for additional information. */ -const CHUNK_EXPORT_PROPERTY = '__chunkExport__'; +const CHUNK_EXPORTS_PREFIX = '__chunk_'; /** * A list of chunks. Order matters: later chunks can depend on @@ -226,7 +226,7 @@ async function buildChunkExporters() { `/** @fileoverview @suppress {undefinedVars} */ import * as exports from '${importPath}'; -${NAMESPACE_VARIABLE}['${CHUNK_EXPORT_PROPERTY}'] = exports; +${NAMESPACE_VARIABLE}['${CHUNK_EXPORTS_PREFIX}${chunk.name}'] = exports; `, ); }), @@ -495,6 +495,11 @@ function chunkWrapper(chunk) { ); } + // Expression evaluating to the location on the namespace object at + // which the chunk exporter will have saved the chunk's exports + // object. (See buildChunkExporters.) + const exportsObject = `${NAMESPACE_VARIABLE}.${CHUNK_EXPORTS_PREFIX}${chunk.name}`; + // Note that when loading in a browser the base of the exported path // (e.g. Blockly.blocks.all - see issue #5932) might not exist // before factory has been executed, so calling factory() and @@ -514,8 +519,8 @@ function chunkWrapper(chunk) { }(this, function(${factoryArgs}) { var ${NAMESPACE_VARIABLE}=${namespaceExpr}; %output% -${NAMESPACE_VARIABLE}['${CHUNK_EXPORT_PROPERTY}'].${NAMESPACE_PROPERTY}=${NAMESPACE_VARIABLE}; -return ${NAMESPACE_VARIABLE}['${CHUNK_EXPORT_PROPERTY}']; +${exportsObject}.${NAMESPACE_PROPERTY}=${NAMESPACE_VARIABLE}; +return ${exportsObject}; })); `; }