Giter Club home page Giter Club logo

Comments (12)

gfranko avatar gfranko commented on July 24, 2024

For this particular case, I think you will want to set the globalObject option to true. This will be the output when using it:

AMD

define('testing', function (require) {
    var Q = require('Q');
});

Standard JavaScript

var amdclean = {};
amdclean['testing'] = function () {
    var Q = amdclean['Q'];
}();

from amdclean.

amatiasq avatar amatiasq commented on July 24, 2024

Maybe a note in the documentation may help other people not to face the same issue and think the program doesn't work?

I don't see how findNestedDependencies will help here :\

from amdclean.

gfranko avatar gfranko commented on July 24, 2024

Should I add it to the Frequently Asked Questions in the README? Where do you think I should put it?

Also, you're right about the findNestedDependencies option not being applicable in this situation. My bad!

from amdclean.

amatiasq avatar amatiasq commented on July 24, 2024

I think in README.md, where CJS wrapper support is listed. I can make a pull request if you wish.

from amdclean.

gfranko avatar gfranko commented on July 24, 2024

That would be great. Much appreciated.

from amdclean.

gfranko avatar gfranko commented on July 24, 2024

Note: The globalObject option is going to be removed in the AMDClean 2.0.0 release. More details to come shortly...

from amdclean.

amatiasq avatar amatiasq commented on July 24, 2024

But there will be an alternative solution for this, right?

from amdclean.

gfranko avatar gfranko commented on July 24, 2024

Yea, basically in the 2.0.0 version, your code would be converted to this:

var testing,
  Q;
// Q is set to whatever it returns
Q = function() {};
testing = function () {
    // Your local Q is no longer needed and will be removed
    // Whatever else is in this function block will appear next
}();

All module variable instantiations will be hoisted to prevent scoping issues and duplicate local variables inside of modules will be removed in favor of the higher scoped instantiations.

from amdclean.

amatiasq avatar amatiasq commented on July 24, 2024

It's and edge case but this can create conflict because on AMD you can have variables called like a module

define('helper', function() { ... });
define('foo', function(require) {
    var _ = require('helper');
    function helper() { ... } 
});

If I get it right the new conversion will be

var helper, foo;
helper = function() { ... }();
foo = function() {
  // ups! hoisting...
  var _ = helper;
  function helper() { ... }
}();

This is not an CommonJS wrapper issue since it can be written on simple AMD

define('helper', [], function() { ... });
define('foo', ['helper'], function(_) {
  function helper() { ... }
});

The same can happen with something like

define('tools', function() { ... });
define('foo', function(require) {
  var inherit = require('tools').inherit;
  var tools = { ... };
});

from amdclean.

gfranko avatar gfranko commented on July 24, 2024

Actually, now that I think about it some more, I don't see this as a problem. It is fine that you overwrite the local scope, since the global variable scope will remain intact.

from amdclean.

amatiasq avatar amatiasq commented on July 24, 2024

Yes it will only make fail the module than does this, it's an edge case but for me the problem is than it produces a silent but than will be hard to spot.

from amdclean.

gfranko avatar gfranko commented on July 24, 2024

I'm still okay with it, but may change my mind in the future.

from amdclean.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.