maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
727 stars 58 forks source link

Grunt task support for runtime build option -I #130

Closed singggum3b closed 9 years ago

singggum3b commented 9 years ago

Is there any way to pass -I build option (like none,browsify, window,.etc) to iced compiler using API? Currently i'm using grunt task to build iced files,but it's producing node js version .

maxtaco commented 9 years ago

Should work as follows:

ics = require 'iced-coffee-script'
ics.compile("await setTimeout defer(), 1000", {runtime : 'inline'})

This will output the inline runtime as below. The other options for runtime are as you listed them.

(function() {
  var iced, __iced_deferrals, __iced_k, __iced_k_noop,
    __slice = [].slice;

  iced = {
    Deferrals: (function() {
      function _Class(_arg) {
        this.continuation = _arg;
        this.count = 1;
        this.ret = null;
      }

      _Class.prototype._fulfill = function() {
        if (!--this.count) {
          return this.continuation(this.ret);
        }
      };

      _Class.prototype.defer = function(defer_params) {
        ++this.count;
        return (function(_this) {
          return function() {
            var inner_params, _ref;
            inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
            if (defer_params != null) {
              if ((_ref = defer_params.assign_fn) != null) {
                _ref.apply(null, inner_params);
              }
            }
            return _this._fulfill();
          };
        })(this);
      };

      return _Class;

    })(),
    findDeferral: function() {
      return null;
    },
    trampoline: function(_fn) {
      return _fn();
    }
  };
  __iced_k = __iced_k_noop = function() {};

  __iced_deferrals = new iced.Deferrals(__iced_k, {});
  setTimeout(__iced_deferrals.defer({
    lineno: 0
  }), 1000);
  __iced_deferrals._fulfill();

}).call(this);
singggum3b commented 9 years ago

Thanks @maxtaco