Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn off deadcode removal #729

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions packages/build/src/js-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,29 @@ const babelSyntaxPlugins = [
require('@babel/plugin-syntax-import-meta'),
];

const babelPresetMinify = require('babel-preset-minify')({}, {
// Disable the minify-constant-folding plugin because it has a bug relating to
// invalid substitution of constant values into export specifiers:
// https://github.com/babel/minify/issues/820
evaluate: false,

// TODO(aomarks) Find out why we disabled this plugin.
simplifyComparisons: false,

// Disable the simplify plugin because it can eat some statements preceeding
// loops. https://github.com/babel/minify/issues/824
simplify: false,

// This is breaking ES6 output. https://github.com/Polymer/tools/issues/261
mangle: false,
});
// Process as a method so that the options can be used to determine
// whether to eliminate dead code or not. As per
// https://github.com/Polymer/tools/issues/724 compiling to `es5` when
// removing dead code can cause live code to be erroneously removed.
function babelPresetMinify(options: JsTransformOptions) {
return require('babel-preset-minify')({}, {
// Disable the minify-constant-folding plugin because it has a bug relating to
// invalid substitution of constant values into export specifiers:
// https://github.com/babel/minify/issues/820
evaluate: false,

// TODO(aomarks) Find out why we disabled this plugin.
simplifyComparisons: false,

// Disable the simplify plugin because it can eat some statements preceeding
// loops. https://github.com/babel/minify/issues/824
simplify: false,
deadcode: !(options.compile === true || options.compile === 'es5'),

// This is breaking ES6 output. https://github.com/Polymer/tools/issues/261
mangle: false,
});
}

/**
* Options for jsTransform.
Expand Down Expand Up @@ -186,7 +193,7 @@ export function jsTransform(js: string, options: JsTransformOptions): string {
if (options.minify) {
doBabelTransform = true;
// Minify last, so push first.
presets.push(babelPresetMinify);
presets.push(babelPresetMinify(options));
}
if (options.compile === true || options.compile === 'es5') {
doBabelTransform = true;
Expand Down