Skip to content

empty deps should be handled differently to no deps #669

@neonstalwart

Description

@neonstalwart

i've noticed a subtle difference between requirejs and dojo's loader and i've come to the conclusion that it's a bug in requirejs.

for a module like this,

define([], function (a, b, c) { });

using dojo - a, b, c will be undefined. the module explicitly states that it has no dependencies so none are given
using requirejs - a, b, c, will be require, exports, module.

in dojo, if you want require, exports and module you would do this

define(function (require, exports, module) { });

which is the same for requirejs too.

this came up when https://github.com/kriszyp/put-selector/blob/v0.3.2/put.js#L3 failed to work when loaded via requirejs because it was assuming the behavior that is in dojo's loader.

the spec says:

The dependencies argument is optional. If omitted, it should default to ["require", "exports", "module"].

in the first case above, the dependencies argument is not omitted, it's explicitly empty, so this is why i came to the conclusion that it's a bug in requirejs.

it looks like https://github.com/jrburke/requirejs/blob/master/require.js#L1952-L1978 is what needs some adjusting. something along the lines of:

if (!isArray(deps)) {
  callback = deps;
  deps = [];
  // only do factory scanning if necessary
  if (isFunction(callback) && callback.length) {
    callback.toString()
    // continue with the rest of that block as it is
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy