GithubHelp home page GithubHelp logo

jugglinmike / amdclean Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gfranko/amdclean

5.0 5.0 0.0 1.24 MB

An AMD build tool that converts AMD code to standard JavaScript

Home Page: http://gregfranko.com/amdclean/

License: MIT License

JavaScript 100.00%

amdclean's People

Contributors

jugglinmike avatar tbranyen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

amdclean's Issues

Deeply nested defines.

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.

Additional tests.

  • Renaming of CommonJS arguments (you only need to match the first argument require to tell it it's CommonJS the rest can be named whatever).
  • module.exports vs return value (module.exports will take precedence in a truthy tie, otherwise, whichever is truthy module.exports || retVal).
  • Shim configuration (RequireJS/R.js specific).
  • require transformations.
  • Linking require correctly to define.
  • Relative module requires.
  • namespace[identifier] format.

Original proof of concept. Save forever and ever.

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);

Eliminate unnecessary functions for literals.

defines 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;

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.