jugglinmike / amdclean Goto Github PK
View Code? Open in Web Editor NEWThis project forked from gfranko/amdclean
An AMD build tool that converts AMD code to standard JavaScript
Home Page: http://gregfranko.com/amdclean/
License: MIT License
This project forked from gfranko/amdclean
An AMD build tool that converts AMD code to standard JavaScript
Home Page: http://gregfranko.com/amdclean/
License: MIT License
In cases where external libraries that define AMD have deeply nested defines, the replacement mechanism using var __DEFINE_X__
will not work as expected.
Example with Lo-Dash:
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
// Expose Lo-Dash to the global object even when an AMD loader is present in
// case Lo-Dash was injected by a third-party script and not intended to be
// loaded as a module. The global assignment can be reverted in the Lo-Dash
// module by its `noConflict()` method.
root._ = lodash;
// define as an anonymous module so, through path mapping, it can be
// referenced as the "underscore" module
var __DEFINE_0__ = (function(){
return lodash;
})();
}
I do not want us to utilize globals, but maybe we can utilize a module cache to store references in?
The question would also be how do we inject our own cache to not become global. Perhaps we advocate to use start and end files to handle it.
Edit: Upon further inspection that code path would never be hit and subsequently never normalized. I think this could be even more problematic.
For those using this to generate a reusable library.
Update context to be a constructor that contains instance-specific module registrations.
module.exports
vs return value (module.exports
will take precedence in a truthy tie, otherwise, whichever is truthy module.exports || retVal
).require
transformations.namespace[identifier]
format.https://github.com/mozilla/source-map
Since we are directly modifying the source code, we'll need to record the state prior to calling node.update
.
This would be very interesting for post-install/install
hooks.
Instead of rewriting libraries that use AMD, simply transpile when installed via NPM.
Run the moduleName
through a function that can generate a pretty and valid JavaScript identifier. This will help avoid the need to mangle the identifier for uniqueness.
var parseAST = require("burrito");
// Rewrite anonymous define.
var res = parseAST(fixture, function(token) {
// Find all anonymous define functions.
if (token.name === "call" && token.node[1][1] === "define") {
token.node[1][1] = "var __DEFINE_" + (count++) + "__ = ";
}
});
console.log(res);
We should provide options to make it easier to wrap your final build in a highly consumable UMD wrapper.
define
s that use literals should not be converted to IIFE that return the value, we should just directly assign.
Example:
define(1234);
which currently compiles to:
var __AMDCLEAN0__ = (function() {
return 1234;
})();
but, should be optimized to:
var __AMDCLEAN0__ = 1234;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.