From 6df804c8b0887d13388b488865cb24242e6a43e9 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Mon, 5 Dec 2016 16:40:22 -0800 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20spaces=20when=20amending?= =?UTF-8?q?=20module=20wrapper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: since we use the same module wrapper amendment function for dev and prod builds, and code is already minified at this point, we minify ourselves by leaving out space. Reviewed By: cpojer Differential Revision: D4265967 fbshipit-source-id: 719a3bbfbc02c9af1bb3fa08317b2f1b92c141a5 --- .../src/ModuleGraph/output/__tests__/util-test.js | 4 ++-- .../react-packager/src/ModuleGraph/output/util.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js b/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js index 5704a90f33f..6984b76f35f 100644 --- a/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js +++ b/packager/react-packager/src/ModuleGraph/output/__tests__/util-test.js @@ -40,13 +40,13 @@ describe('`addModuleIdsToModuleWrapper`:', () => { .withArgs(match({path: dependencies[1].path})).returns(6); expect(addModuleIdsToModuleWrapper(module, idForPath)) - .toEqual('__d(function(){}, 12, [345, 6]);'); + .toEqual('__d(function(){},12,[345,6]);'); }); it('omits the array of dependency IDs if it is empty', () => { const module = createModule(); expect(addModuleIdsToModuleWrapper(module, () => 98)) - .toEqual(`__d(function(){}, ${98});`); + .toEqual(`__d(function(){},${98});`); }); }); diff --git a/packager/react-packager/src/ModuleGraph/output/util.js b/packager/react-packager/src/ModuleGraph/output/util.js index d883a748d0f..23065d2453c 100644 --- a/packager/react-packager/src/ModuleGraph/output/util.js +++ b/packager/react-packager/src/ModuleGraph/output/util.js @@ -26,11 +26,19 @@ exports.addModuleIdsToModuleWrapper = ( const {dependencies, file} = module; const {code} = file; const index = code.lastIndexOf(')'); + + // calling `idForPath` on the module itself first gives us a lower module id + // for the file itself than for its dependencies. That reflects their order + // in the bundle. + const fileId = idForPath(file); + + // This code runs for both development and production builds, after + // minification. That's why we leave out all spaces. const depencyIds = - dependencies.length ? `, [${dependencies.map(idForPath).join(', ')}]` : ''; + dependencies.length ? `,[${dependencies.map(idForPath).join(',')}]` : ''; return ( code.slice(0, index) + - `, ${idForPath(file)}` + + `,${fileId}` + depencyIds + code.slice(index) );