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

Better try statement tree shaking #3166

Merged
merged 8 commits into from Oct 18, 2019
151 changes: 112 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -73,23 +73,23 @@
"@types/micromatch": "^3.1.0",
"@types/minimist": "^1.2.0",
"acorn-import-meta": "^1.0.0",
"acorn-jsx": "^5.0.2",
"acorn-jsx": "^5.1.0",
"acorn-walk": "^7.0.0",
"buble": "^0.19.8",
"chokidar": "^2.1.8",
"codecov": "^3.6.1",
"console-group": "^0.3.3",
"core-js": "^3.2.1",
"core-js": "^3.3.2",
"cross-os": "^1.3.0",
"date-time": "^3.1.0",
"es5-shim": "^4.5.13",
"es6-shim": "^0.35.5",
"eslint": "^6.5.1",
"eslint-plugin-import": "^2.18.2",
"execa": "^2.1.0",
"execa": "^3.1.0",
"fixturify": "^1.2.0",
"hash.js": "^1.1.7",
"husky": "^3.0.8",
"husky": "^3.0.9",
"is-reference": "^1.1.4",
"lint-staged": "^9.4.2",
"locate-character": "^2.0.5",
Expand All @@ -104,7 +104,7 @@
"pretty-ms": "^5.0.0",
"require-relative": "^0.8.7",
"requirejs": "^2.3.6",
"rollup": "^1.23.1",
"rollup": "^1.24.0",
"rollup-plugin-alias": "^2.0.1",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-commonjs": "^10.1.0",
Expand All @@ -122,8 +122,8 @@
"source-map": "^0.6.1",
"source-map-support": "^0.5.13",
"sourcemap-codec": "^1.4.6",
"systemjs": "^6.1.3",
"terser": "^4.3.8",
"systemjs": "^6.1.4",
"terser": "^4.3.9",
"tslib": "^1.10.0",
"tslint": "^5.20.0",
"turbocolor": "^2.6.1",
Expand Down
24 changes: 13 additions & 11 deletions rollup.config.js
Expand Up @@ -95,18 +95,20 @@ function generateLicenseFile(dependencies) {
return text;
})
.join('\n---------------------------------------\n\n');
fs.writeFileSync(
'LICENSE.md',
const licenseText =
`# Rollup core license\n` +
`Rollup is released under the MIT license:\n\n` +
coreLicense +
`\n# Licenses of bundled dependencies\n` +
`The published Rollup artifact additionally contains code with the following licenses:\n` +
`${Array.from(licenses).join(', ')}\n\n` +
`# Bundled dependencies:\n` +
dependencyLicenseTexts
);
console.log('LICENSE.md updated.');
`Rollup is released under the MIT license:\n\n` +
coreLicense +
`\n# Licenses of bundled dependencies\n` +
`The published Rollup artifact additionally contains code with the following licenses:\n` +
`${Array.from(licenses).join(', ')}\n\n` +
`# Bundled dependencies:\n` +
dependencyLicenseTexts;
const existingLicenseText = fs.readFileSync('LICENSE.md', 'utf8');
if (existingLicenseText !== licenseText) {
fs.writeFileSync('LICENSE.md', licenseText);
console.warn('LICENSE.md updated. You should commit the updated file.');
}
}

const expectedAcornImport = "import acorn__default, { Parser } from 'acorn';";
Expand Down
6 changes: 4 additions & 2 deletions src/ast/ExecutionContext.ts
Expand Up @@ -3,7 +3,8 @@ import { PathTracker } from './utils/PathTracker';
import ThisVariable from './variables/ThisVariable';

interface ExecutionContextIgnore {
breakStatements: boolean;
breaks: boolean;
continues: boolean;
labels: Set<string>;
returnAwaitYield: boolean;
}
Expand Down Expand Up @@ -39,7 +40,8 @@ export function createHasEffectsContext(): HasEffectsContext {
breakFlow: BREAKFLOW_NONE,
called: new PathTracker(),
ignore: {
breakStatements: false,
breaks: false,
continues: false,
labels: new Set(),
returnAwaitYield: false
},
Expand Down
3 changes: 2 additions & 1 deletion src/ast/nodes/ArrowFunctionExpression.ts
Expand Up @@ -58,7 +58,8 @@ export default class ArrowFunctionExpression extends NodeBase {
}
const { ignore, breakFlow } = context;
context.ignore = {
breakStatements: false,
breaks: false,
continues: false,
labels: new Set(),
returnAwaitYield: true
};
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/BreakStatement.ts
Expand Up @@ -8,7 +8,7 @@ export default class BreakStatement extends StatementBase {
type!: NodeType.tBreakStatement;

hasEffects(context: HasEffectsContext) {
if (!(this.label ? context.ignore.labels.has(this.label.name) : context.ignore.breakStatements))
if (!(this.label ? context.ignore.labels.has(this.label.name) : context.ignore.breaks))
return true;
context.breakFlow = new Set([this.label && this.label.name]);
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/ContinueStatement.ts
Expand Up @@ -8,7 +8,7 @@ export default class ContinueStatement extends StatementBase {
type!: NodeType.tContinueStatement;

hasEffects(context: HasEffectsContext) {
if (!(this.label ? context.ignore.labels.has(this.label.name) : context.ignore.breakStatements))
if (!(this.label ? context.ignore.labels.has(this.label.name) : context.ignore.continues))
return true;
context.breakFlow = new Set([this.label && this.label.name]);
return false;
Expand Down
8 changes: 5 additions & 3 deletions src/ast/nodes/DoWhileStatement.ts
Expand Up @@ -11,11 +11,13 @@ export default class DoWhileStatement extends StatementBase {
if (this.test.hasEffects(context)) return true;
const {
breakFlow,
ignore: { breakStatements }
ignore: { breaks, continues }
} = context;
context.ignore.breakStatements = true;
context.ignore.breaks = true;
context.ignore.continues = true;
if (this.body.hasEffects(context)) return true;
context.ignore.breakStatements = breakStatements;
context.ignore.breaks = breaks;
context.ignore.continues = continues;
if (context.breakFlow instanceof Set && context.breakFlow.has(null)) {
context.breakFlow = breakFlow;
}
Expand Down