browserify / common-shakeify

browserify tree shaking plugin using `common-shake`
https://www.npmjs.com/package/common-shakeify
MIT License
105 stars 18 forks source link

require('os') is broken #24

Closed dy closed 5 years ago

dy commented 5 years ago
// a.js
var _ = require('./b')
// b.js
exports.a = exports.b = function () {}

browserify -p common-shakeify a.js produces

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
/* common-shake removed: exports.a = */ /* common-shake removed: exports.b = */ function () {}

},{}],2:[function(require,module,exports){
var a = require( './b' )

},{"./b":1}]},{},[2]);

Which is Uncaught SyntaxError: Unexpected token (.

Because we can't just do function () {} in javascript.

@goto-bus-stop

goto-bus-stop commented 5 years ago

oh right, this was the case that prepending void 0, was solving. maybe that condition needs a tweak so it would be added in this case?

dy commented 5 years ago

That seems to affect only functions, I wonder if there there are the other cases