Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add minification to fold and squash implicit returns away

+50 -1
+50 -1
scripts/minify-bucklescript-plugin.js
··· 110 110 }; 111 111 } 112 112 113 + function squashImplicitUnitReturn({ types: t }) { 114 + return { 115 + visitor: { 116 + ReturnStatement(path) { 117 + if ( 118 + t.isCallExpression(path.node.argument) && 119 + t.isIdentifier(path.node.argument.callee) && 120 + (path.node.argument.callee.name === 'sink' || path.node.argument.callee.name === 'source') 121 + ) { 122 + path.replaceWithMultiple([ 123 + t.expressionStatement(path.node.argument), 124 + t.returnStatement(), 125 + ]); 126 + } 127 + }, 128 + Function: { 129 + exit(functionPath) { 130 + if (t.isIdentifier(functionPath.id) && functionPath.id.name === 'valFromOption') return; 131 + 132 + let hasEmptyReturn = false; 133 + let hasCallReturnOnly = true; 134 + functionPath.traverse({ 135 + Function(innerPath) { 136 + innerPath.skip(); 137 + }, 138 + ReturnStatement: { 139 + enter(path) { 140 + if (path.node.argument === null) { 141 + hasEmptyReturn = true; 142 + } else if (!t.isCallExpression(path.node.argument)) { 143 + hasCallReturnOnly = false; 144 + } 145 + }, 146 + exit(path) { 147 + if (hasEmptyReturn && hasCallReturnOnly && path.node.argument !== null) { 148 + path.replaceWithMultiple([ 149 + t.expressionStatement(path.node.argument), 150 + t.returnStatement(), 151 + ]); 152 + } 153 + }, 154 + }, 155 + }); 156 + }, 157 + }, 158 + }, 159 + }; 160 + } 161 + 113 162 function cleanup(opts = {}) { 114 163 const filter = createFilter(opts.include, opts.exclude, { 115 164 resolve: false, ··· 124 173 } 125 174 126 175 return transform(code, { 127 - plugins: [unwrapStatePlugin, curryGuaranteePlugin], 176 + plugins: [unwrapStatePlugin, curryGuaranteePlugin, squashImplicitUnitReturn], 128 177 babelrc: false, 129 178 }); 130 179 },