Skip to content

Commit debcf16

Browse files
authored
Mangle exported symbols (microsoft#182935)
* Mangle exported functions For microsoft#180461 This prototype tries to mangle exported functions, saving a further 440kb from the bundle size * Fix missing call * Also try mangling top level exported consts too * Fixing errors * Don't run on build files * Skip a few more manglings and revert change to namespace * Skip a few more monaco files * Also mangle consts that shadow types This increases savings up to 3325 * Also mangle exported classes * Skip mangling more localization functions for now * Opt out pfs * Update build script * Run find locations task in parallel This should speed up compile * Cleanup before close * Limit workers to avoid hitting memory limit * Limit pool size * Skip one more mangling * Exclude entrypoints from mangling * Try to fix web build and clean up code * Exempt a few more projects * Exempt another file * Also exempt html * Skip mangling ext entrypoints * Use prefix that can't be confused with rpc calls * Fix max call stack error * Switch prefixes * Don't mangle ambient declarations * Use correct way of checking modifier flags * Workaround getCombinedModifierFlags not doing what I'd expect Maybe needs the checker to be enabled too? Just check parent chain instead for now * Clean up code and add logic showing how enum mangling could work * Remove a few more skipMangles Use entrypoints instead * Fix entrypoint name
1 parent 79c4092 commit debcf16

File tree

22 files changed

+1337
-133
lines changed

22 files changed

+1337
-133
lines changed

build/lib/compilation.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/compilation.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as os from 'os';
1717
import ts = require('typescript');
1818
import * as File from 'vinyl';
1919
import * as task from './task';
20-
import { Mangler } from './mangleTypeScript';
20+
import { Mangler } from './mangle/index';
2121
import { RawSourceMap } from 'source-map';
2222
const watch = require('./watch');
2323

@@ -124,21 +124,22 @@ export function compileTask(src: string, out: string, build: boolean, options: {
124124
// mangle: TypeScript to TypeScript
125125
let mangleStream = es.through();
126126
if (build && !options.disableMangle) {
127-
let ts2tsMangler = new Mangler(compile.projectPath, (...data) => fancyLog(ansiColors.blue('[mangler]'), ...data));
127+
let ts2tsMangler = new Mangler(compile.projectPath, (...data) => fancyLog(ansiColors.blue('[mangler]'), ...data), { mangleExports: true, manglePrivateFields: true });
128128
const newContentsByFileName = ts2tsMangler.computeNewFileContents(new Set(['saveState']));
129-
mangleStream = es.through(function write(data: File & { sourceMap?: RawSourceMap }) {
129+
mangleStream = es.through(async function write(data: File & { sourceMap?: RawSourceMap }) {
130130
type TypeScriptExt = typeof ts & { normalizePath(path: string): string };
131131
const tsNormalPath = (<TypeScriptExt>ts).normalizePath(data.path);
132-
const newContents = newContentsByFileName.get(tsNormalPath);
132+
const newContents = (await newContentsByFileName).get(tsNormalPath);
133133
if (newContents !== undefined) {
134134
data.contents = Buffer.from(newContents.out);
135135
data.sourceMap = newContents.sourceMap && JSON.parse(newContents.sourceMap);
136136
}
137137
this.push(data);
138-
}, function end() {
139-
this.push(null);
138+
}, async function end() {
140139
// free resources
141-
newContentsByFileName.clear();
140+
(await newContentsByFileName).clear();
141+
142+
this.push(null);
142143
(<any>ts2tsMangler) = undefined;
143144
});
144145
}

0 commit comments

Comments
 (0)