Don’t use spaces when amending module wrapper

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
This commit is contained in:
David Aurelio 2016-12-05 16:40:22 -08:00 committed by Martin Konicek
parent 88409f6bda
commit 6df804c8b0
2 changed files with 12 additions and 4 deletions

View File

@ -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});`);
});
});

View File

@ -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)
);