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

CJS-to-AMD transpilation does not lift dependencies to factory function #132

Open
rjgotten opened this issue Mar 8, 2018 · 2 comments
Open

Comments

@rjgotten
Copy link

rjgotten commented Mar 8, 2018

Given

var foo = require('./foo');
var bar = require('./bar');
module.exports = [ foo, bar ];

The output when transpiled to AMD is

define([
  'require',
  'exports',
  'module',
  './foo',
  './bar'
], function( require, exports, module ) {
  var foo = require('./foo');
  var bar = require('./bar');
  module.exports = [ foo, bar ];
});

Expected output, following AMD conventions instead of CJS-inside-AMD compatibility syntax, would be

define([
  './foo',
  './bar'
], function( foo, bar ) {
  return [ foo, bar ];
});
@matthewp
Copy link
Member

matthewp commented Mar 8, 2018

Does this present a problem some where? I thought all AMD loaders supported the CJS compat syntax, is that wrong?

@rjgotten
Copy link
Author

rjgotten commented Mar 9, 2018

Does this present a problem some where?

Non-functionally speaking; AMD syntax proper offers better minification.

There may also be issues with optimization / production-build tooling that attempts to analyze module source code to find CJS-style require calls and translate them, which in this case would give unexpected results. So there's also a potential compat problem there. (Not sure if that is still an issue, actually. But it definitely used to be a problem because of limited analysis.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants