Skip to content

Commit

Permalink
Add special minification case for source calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed May 1, 2020
1 parent 14fe9f6 commit 835f467
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/minify-bucklescript-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ function curryGuaranteePlugin({ types: t }) {
const callFn = path.node.arguments[0];
const callArgs = path.node.arguments.slice(1);

// Check whether the value of the call is unused
if (t.isExpressionStatement(path.parent)) {
path.replaceWith(t.callExpression(callFn, callArgs));
return;
}

// Check whether the callee is a local function definition whose arity matches
if (t.isIdentifier(callFn) && path.scope.hasBinding(callFn.name)) {
const callFnDefinition = path.scope.getBinding(callFn.name).path.node;
if (
Expand All @@ -78,6 +80,16 @@ function curryGuaranteePlugin({ types: t }) {
}
}

// Special case since sources don't return any value
if (
t.isIdentifier(callFn) &&
callFn.name === 'source' &&
t.isReturnStatement(path.parent)
) {
path.replaceWith(t.callExpression(callFn, callArgs));
return;
}

const arityLiteral = t.numericLiteral(callArgs.length);
const argIds = callArgs.map((init) => {
if (t.isIdentifier(init)) return init;
Expand Down

0 comments on commit 835f467

Please sign in to comment.