Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 26, 2020
1 parent 90c5613 commit ca05b26
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/ModuleLoader.ts
Expand Up @@ -6,7 +6,6 @@ import {
GetManualChunk,
HasModuleSideEffects,
NormalizedInputOptions,
NormalizedTreeshakingOptions,
ResolvedId,
ResolveIdResult,
SourceDescription
Expand Down Expand Up @@ -51,8 +50,9 @@ export class ModuleLoader {
private readonly options: NormalizedInputOptions,
private readonly pluginDriver: PluginDriver
) {
this.hasModuleSideEffects =
(options.treeshake as NormalizedTreeshakingOptions)?.moduleSideEffects || (() => true);
this.hasModuleSideEffects = options.treeshake
? options.treeshake.moduleSideEffects
: () => true;
}

async addEntryModules(
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/CallExpression.ts
Expand Up @@ -155,7 +155,7 @@ export default class CallExpression extends NodeBase implements DeoptimizableEnt
if (argument.hasEffects(context)) return true;
}
if (
(this.context.options.treeshake as NormalizedTreeshakingOptions)?.annotations &&
(this.context.options.treeshake as NormalizedTreeshakingOptions).annotations &&
this.annotatedPure
)
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/NewExpression.ts
Expand Up @@ -26,7 +26,7 @@ export default class NewExpression extends NodeBase {
if (argument.hasEffects(context)) return true;
}
if (
(this.context.options.treeshake as NormalizedTreeshakingOptions)?.annotations &&
(this.context.options.treeshake as NormalizedTreeshakingOptions).annotations &&
this.annotatedPure
)
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/TryStatement.ts
Expand Up @@ -15,7 +15,7 @@ export default class TryStatement extends StatementBase {

hasEffects(context: HasEffectsContext): boolean {
return (
((this.context.options.treeshake as NormalizedTreeshakingOptions)?.tryCatchDeoptimization
((this.context.options.treeshake as NormalizedTreeshakingOptions).tryCatchDeoptimization
? this.block.body.length > 0
: this.block.hasEffects(context)) ||
(this.finalizer !== null && this.finalizer.hasEffects(context))
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/_expected/amd.js
Expand Up @@ -45,6 +45,10 @@ define(['exports', 'external'], function (exports, external) { 'use strict';
}
});

try {
const x = 1;
} catch {}

exports.create = create;
exports.getPrototypeOf = getPrototypeOf;
exports.quux = quux;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/_expected/cjs.js
Expand Up @@ -49,6 +49,10 @@ test({
}
});

try {
const x = 1;
} catch {}

exports.create = create;
exports.getPrototypeOf = getPrototypeOf;
exports.quux = quux;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/_expected/es.js
Expand Up @@ -45,4 +45,8 @@ test({
}
});

try {
const x = 1;
} catch {}

export { create, getPrototypeOf, quux, quux as strange };
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/_expected/iife.js
Expand Up @@ -46,6 +46,10 @@ var stirred = (function (exports, external) {
}
});

try {
const x = 1;
} catch {}

exports.create = create;
exports.getPrototypeOf = getPrototypeOf;
exports.quux = quux;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/_expected/system.js
Expand Up @@ -52,6 +52,10 @@ System.register('stirred', ['external'], function (exports) {
}
});

try {
const x = 1;
} catch {}

}
};
});
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/_expected/umd.js
Expand Up @@ -49,6 +49,10 @@
}
});

try {
const x = 1;
} catch {}

exports.create = create;
exports.getPrototypeOf = getPrototypeOf;
exports.quux = quux;
Expand Down
4 changes: 4 additions & 0 deletions test/form/samples/no-treeshake/main.js
Expand Up @@ -42,3 +42,7 @@ test({
var unused = 1;
}
});

try {
const x = 1;
} catch {}

0 comments on commit ca05b26

Please sign in to comment.