add umd globals export - fixes #375
This commit is contained in:
parent
22b88487ee
commit
76573093bd
@ -78,9 +78,10 @@ var exportsVisitor = traverse.explode({
|
||||
|
||||
export default class DefaultFormatter {
|
||||
constructor(file) {
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
this.defaultIds = object();
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
|
||||
this.hasNonDefaultExports = false;
|
||||
|
||||
|
||||
@ -69,8 +69,13 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
}
|
||||
|
||||
importSpecifier(specifier, node, nodes) {
|
||||
var key = node.source.value;
|
||||
var ref = this.getExternalReference(node);
|
||||
|
||||
if (t.isImportNamespaceSpecifier(specifier) || t.isImportDefaultSpecifier(specifier)) {
|
||||
this.defaultIds[key] = specifier.local;
|
||||
}
|
||||
|
||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
this.ids[node.source.value] = ref;
|
||||
|
||||
@ -10,7 +10,7 @@ export default class UMDFormatter extends AMDFormatter {
|
||||
// build an array of module names
|
||||
|
||||
var names = [];
|
||||
for (var name in this.ids) {
|
||||
for (let name in this.ids) {
|
||||
names.push(t.literal(name));
|
||||
}
|
||||
|
||||
@ -44,7 +44,13 @@ export default class UMDFormatter extends AMDFormatter {
|
||||
|
||||
// globals
|
||||
|
||||
//var umdArgs = [];
|
||||
var browserArgs = [t.memberExpression(t.identifier("module"), t.identifier("exports"))];
|
||||
if (this.passModuleArg) browserArgs.push(t.identifier("module"));
|
||||
|
||||
for (let name in this.ids) {
|
||||
var id = this.defaultIds[name] || t.identifier(t.toIdentifier(name));
|
||||
browserArgs.push(t.memberExpression(t.identifier("global"), id));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -54,12 +60,15 @@ export default class UMDFormatter extends AMDFormatter {
|
||||
var runner = util.template("umd-runner-body", {
|
||||
AMD_ARGUMENTS: defineArgs,
|
||||
COMMON_TEST: commonTests,
|
||||
COMMON_ARGUMENTS: commonArgs
|
||||
COMMON_ARGUMENTS: commonArgs,
|
||||
BROWSER_ARGUMENTS: browserArgs,
|
||||
GLOBAL_ARG: t.identifier(t.toIdentifier(this.file.opts.basename))
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
var call = t.callExpression(runner, [factory]);
|
||||
program.body = [t.expressionStatement(call)];
|
||||
program.body = [t.expressionStatement(
|
||||
t.callExpression(runner, [t.thisExpression(), factory])
|
||||
)];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
} else if (typeof exports === "object") {
|
||||
factory(COMMON_ARGUMENTS);
|
||||
} else {
|
||||
factory(BROWSER_ARGUMENTS);
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
} else if (COMMON_TEST) {
|
||||
factory(COMMON_ARGUMENTS);
|
||||
} else {
|
||||
var module = { exports: {} };
|
||||
factory(BROWSER_ARGUMENTS);
|
||||
global.GLOBAL_ARG = module.exports;
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "module"], factory);
|
||||
} else if (typeof exports !== "undefined" && typeof module !== "undefined") {
|
||||
factory(exports, module);
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, module);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, module) {
|
||||
})(this, function (exports, module) {
|
||||
"use strict";
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo) {
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
|
||||
@ -24,4 +30,4 @@
|
||||
exports["default"] = _foo.foo;
|
||||
exports["default"] = _foo.foo;
|
||||
exports.bar = _foo.bar;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports);
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports) {
|
||||
})(this, function (exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
@ -17,4 +23,4 @@
|
||||
exports["default"] = foo;
|
||||
exports["default"] = foo;
|
||||
exports.bar = bar;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports);
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports) {
|
||||
})(this, function (exports) {
|
||||
"use strict";
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define("my custom module name", ["exports"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports);
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports) {
|
||||
})(this, function (exports) {
|
||||
"use strict";
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "./evens"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("./evens"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.evens);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _evens) {
|
||||
})(this, function (exports, _evens) {
|
||||
"use strict";
|
||||
|
||||
exports.nextOdd = nextOdd;
|
||||
@ -23,4 +29,4 @@
|
||||
};
|
||||
})(isEven);
|
||||
exports.isOdd = isOdd;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo) {
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
||||
@ -12,4 +18,4 @@
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
var foo2 = _interopRequire(_foo);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,11 +1,17 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo) {
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var foo = _foo;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo) {
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
||||
@ -12,4 +18,4 @@
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
var xyz = _foo.baz;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo) {
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var bar = _foo.bar;
|
||||
@ -13,4 +19,4 @@
|
||||
var baz2 = _foo.bar;
|
||||
var baz3 = _foo.bar;
|
||||
var xyz = _foo.xyz;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo, global.fooBar, global.directoryFooBar);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
})(this, function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
"use strict";
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define("es6.modules-umd/module-name/expected", ["exports"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports);
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports) {
|
||||
})(this, function (exports) {
|
||||
"use strict";
|
||||
|
||||
foobar();
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo2, global.fooBar, global.directoryFooBar);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
})(this, function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
|
||||
@ -23,4 +29,4 @@
|
||||
|
||||
exports.test2 = test2;
|
||||
exports["default"] = test;
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports);
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports) {
|
||||
})(this, function (exports) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
@ -20,4 +26,4 @@
|
||||
test = 3;
|
||||
test++;
|
||||
})();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
(function (factory) {
|
||||
(function (global, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports", "foo", "babel-runtime/es5/helpers/interop-require"], factory);
|
||||
} else if (typeof exports !== "undefined") {
|
||||
factory(exports, require("foo"), require("babel-runtime/es5/helpers/interop-require"));
|
||||
} else {
|
||||
var module = {
|
||||
exports: {}
|
||||
};
|
||||
factory(module.exports, global.foo, global._interopRequire);
|
||||
global.actual = module.exports;
|
||||
}
|
||||
})(function (exports, _foo, _babelRuntimeEs5HelpersInteropRequire) {
|
||||
})(this, function (exports, _foo, _babelRuntimeEs5HelpersInteropRequire) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = _babelRuntimeEs5HelpersInteropRequire["default"];
|
||||
|
||||
var foo = _interopRequire(_foo);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user