es6-module-transpiler
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -1,2 +0,2 @@ | ||
(function(){function require(e,t){for(var n=[],r=e.split("/"),i,s,o=0;s=r[o++];)".."==s?n.pop():"."!=s&&n.push(s);n=n.join("/"),o=require,s=o.m[t||0],i=s[n+".js"]||s[n+"/index.js"]||s[n];if(s=i.c)i=o.m[t=s][e=i.m];return i.exports||i(i,i.exports={},function(n){return o("."!=n.charAt(0)?n:e+"/../"+n,t)}),i.exports}; | ||
(function(){function require(e,t){for(var n=[],r=e.split("/"),i,s,o=0;(s=r[o++])!=null;)".."==s?n.pop():"."!=s&&n.push(s);n=n.join("/"),o=require,s=o.m[t||0],i=s[n+".js"]||s[n+"/index.js"]||s[n],r='Cannot require("'+n+'")';if(!i)throw Error(r);if(s=i.c)i=o.m[t=s][e=i.m];if(!i)throw Error(r);return i.exports||i(i,i.exports={},function(n){return o("."!=n.charAt(0)?n:e+"/../"+n,t)}),i.exports}; | ||
require.m = []; | ||
@@ -6,3 +6,3 @@ require.m[0] = { "abstract_compiler.js": function(module, exports, require){(function() { | ||
var AbstractCompiler, CoffeeScriptBuilder, CompileError, JavaScriptBuilder, | ||
var AbstractCompiler, CoffeeScriptBuilder, CompileError, JavaScriptBuilder, isEmpty, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -17,2 +17,4 @@ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
isEmpty = require("./utils").isEmpty; | ||
AbstractCompiler = (function() { | ||
@@ -24,5 +26,5 @@ | ||
this.exports = compiler.exports; | ||
this.exportAs = compiler.exportAs; | ||
this.exportDefault = compiler.exportDefault; | ||
this.imports = compiler.imports; | ||
this.importAs = compiler.importAs; | ||
this.importDefault = compiler.importDefault; | ||
this.moduleName = compiler.moduleName; | ||
@@ -39,3 +41,3 @@ this.lines = compiler.lines; | ||
} | ||
_ref1 = this.importAs; | ||
_ref1 = this.importDefault; | ||
for (name in _ref1) { | ||
@@ -51,4 +53,4 @@ if (!__hasProp.call(_ref1, name)) continue; | ||
AbstractCompiler.prototype.assertValid = function() { | ||
if (this.exportAs && this.exports.length > 0) { | ||
throw new CompileError("You cannot use both `export =` and `export` in the same module"); | ||
if (this.exportDefault && !isEmpty(this.exports)) { | ||
throw new CompileError("You cannot use both `export default` and `export` in the same module"); | ||
} | ||
@@ -68,4 +70,4 @@ }; | ||
name = names[_i]; | ||
if (name in _this.importAs) { | ||
_results.push(args.push(_this.importAs[name])); | ||
if (name in _this.importDefault) { | ||
_results.push(args.push(_this.importDefault[name])); | ||
} else { | ||
@@ -94,8 +96,9 @@ dependency = deps.next(); | ||
AbstractCompiler.prototype.buildImportsForPreamble = function(builder, imports_, dependencyName) { | ||
var import_, _i, _len, _results; | ||
var alias, name, _results; | ||
_results = []; | ||
for (_i = 0, _len = imports_.length; _i < _len; _i++) { | ||
import_ = imports_[_i]; | ||
_results.push(builder["var"](import_, function() { | ||
return builder.prop(dependencyName, import_); | ||
for (name in imports_) { | ||
if (!__hasProp.call(imports_, name)) continue; | ||
alias = imports_[name]; | ||
_results.push(builder["var"](alias, function() { | ||
return builder.prop(dependencyName, name); | ||
})); | ||
@@ -117,3 +120,3 @@ } | ||
var AMDCompiler, AbstractCompiler, | ||
var AMDCompiler, AbstractCompiler, isEmpty, path, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -124,2 +127,6 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
path = require("path"); | ||
isEmpty = require("./utils").isEmpty; | ||
AMDCompiler = (function(_super) { | ||
@@ -136,8 +143,14 @@ | ||
return this.build(function(s) { | ||
var preamble, wrapperArgs, _ref; | ||
var dependency, i, preamble, wrapperArgs, _ref; | ||
_ref = _this.buildPreamble(_this.dependencyNames), wrapperArgs = _ref[0], preamble = _ref[1]; | ||
if (_this.exports.length !== 0) { | ||
if (!isEmpty(_this.exports)) { | ||
_this.dependencyNames.push('exports'); | ||
wrapperArgs.push('__exports__'); | ||
} | ||
for (i in _this.dependencyNames) { | ||
dependency = _this.dependencyNames[i]; | ||
if (/^\./.test(dependency)) { | ||
_this.dependencyNames[i] = path.join(_this.moduleName, '..', dependency).replace(/[\\]/g, '/'); | ||
} | ||
} | ||
return s.line(function() { | ||
@@ -153,3 +166,3 @@ return s.call('define', function(arg) { | ||
return s["function"](wrapperArgs, function() { | ||
var export_, _i, _len, _ref1; | ||
var exportName, exportValue, _ref1; | ||
s.useStrict(); | ||
@@ -161,8 +174,8 @@ if (preamble) { | ||
_ref1 = _this.exports; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
export_ = _ref1[_i]; | ||
s.line("__exports__." + export_ + " = " + export_); | ||
for (exportName in _ref1) { | ||
exportValue = _ref1[exportName]; | ||
s.line("__exports__." + exportName + " = " + exportValue); | ||
} | ||
if (_this.exportAs) { | ||
return s.line("return " + _this.exportAs); | ||
if (_this.exportDefault) { | ||
return s.line("return " + _this.exportDefault); | ||
} | ||
@@ -204,3 +217,3 @@ }); | ||
return this.build(function(s) { | ||
var dependency, deps, doImport, export_, import_, name, variables, _i, _j, _len, _len1, _ref, _ref1, _ref2, _results; | ||
var alias, dependency, deps, doImport, exportName, exportValue, import_, name, variables, _ref, _ref1, _ref2, _results; | ||
doImport = function(name, import_, prop) { | ||
@@ -221,3 +234,3 @@ var req, rhs; | ||
deps = s.unique('dependency'); | ||
_ref = _this.importAs; | ||
_ref = _this.importDefault; | ||
for (import_ in _ref) { | ||
@@ -232,11 +245,16 @@ if (!__hasProp.call(_ref, import_)) continue; | ||
variables = _ref1[import_]; | ||
if (variables.length === 1) { | ||
name = variables[0]; | ||
doImport(name, import_, name); | ||
if (Object.keys(variables).length === 1) { | ||
name = Object.keys(variables)[0]; | ||
doImport(variables[name], import_, name); | ||
} else { | ||
dependency = deps.next(); | ||
doImport(dependency, import_); | ||
for (_i = 0, _len = variables.length; _i < _len; _i++) { | ||
name = variables[_i]; | ||
s["var"](name, "" + dependency + "." + name); | ||
for (name in variables) { | ||
if (!__hasProp.call(variables, name)) continue; | ||
alias = variables[name]; | ||
if (name === 'default') { | ||
s["var"](alias, "" + dependency); | ||
} else { | ||
s["var"](alias, "" + dependency + "." + name); | ||
} | ||
} | ||
@@ -246,10 +264,10 @@ } | ||
s.append.apply(s, _this.lines); | ||
if (_this.exportAs) { | ||
s.line("module.exports = " + _this.exportAs); | ||
if (_this.exportDefault) { | ||
s.line("module.exports = " + _this.exportDefault); | ||
} | ||
_ref2 = _this.exports; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
export_ = _ref2[_j]; | ||
_results.push(s.line("exports." + export_ + " = " + export_)); | ||
for (exportName in _ref2) { | ||
exportValue = _ref2[exportName]; | ||
_results.push(s.line("exports." + exportName + " = " + exportValue)); | ||
} | ||
@@ -457,3 +475,3 @@ return _results; | ||
ext = path.extname(filename); | ||
moduleName = path.join(path.dirname(filename), path.basename(filename, ext)); | ||
moduleName = path.join(path.dirname(filename), path.basename(filename, ext)).replace(/[\\]/g, '/'); | ||
output = _this._compile(input, moduleName, options.type, { | ||
@@ -463,3 +481,3 @@ coffee: ext === '.coffee', | ||
}); | ||
outputFilename = path.join(options.to, filename); | ||
outputFilename = path.join(options.to, filename).replace(/[\\]/g, '/'); | ||
_this._mkdirp(path.dirname(outputFilename)); | ||
@@ -587,4 +605,3 @@ return _this.fs.writeFile(outputFilename, output, 'utf8', function(err) { | ||
var AMDCompiler, CJSCompiler, Compiler, EXPORT, EXPORT_AS, GlobalsCompiler, IMPORT, IMPORT_AS, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
var AMDCompiler, CJSCompiler, COMMENT_CS_TOGGLE, COMMENT_END, COMMENT_START, Compiler, EXPORT, EXPORT_DEFAULT, EXPORT_FUNCTION, EXPORT_VAR, GlobalsCompiler, IMPORT, IMPORT_AS, RE_EXPORT, Unique, getNames; | ||
@@ -597,10 +614,39 @@ AMDCompiler = require("./amd_compiler"); | ||
Unique = require("./utils").Unique; | ||
EXPORT = /^\s*export\s+(.*?)\s*(;)?\s*$/; | ||
EXPORT_AS = /^\s*export\s*=\s*(.*?)\s*(;)?\s*$/; | ||
EXPORT_DEFAULT = /^\s*export\s*default\s*(.*?)\s*(;)?\s*$/; | ||
EXPORT_FUNCTION = /^\s*export\s+function\s+(\w+)\s*(\(.*)$/; | ||
EXPORT_VAR = /^\s*export\s+var\s+(\w+)\s*=\s*(.*)$/; | ||
IMPORT = /^\s*import\s+(.*)\s+from\s+(?:"([^"]+?)"|'([^']+?)')\s*(;)?\s*$/; | ||
IMPORT_AS = /^\s*import\s+(?:"([^"]+?)"|'([^']+?)')\s*as\s+(.*?)\s*(;)?\s*$/; | ||
IMPORT_AS = /^\s*(.*)\s+as\s+(.*)\s*$/; | ||
RE_EXPORT = /^export\s+({.*})\s+from\s+(?:"([^"]+?)"|'([^']+?)')\s*(;)?\s*$/; | ||
COMMENT_START = new RegExp("/\\*"); | ||
COMMENT_END = new RegExp("\\*/"); | ||
COMMENT_CS_TOGGLE = /^###/; | ||
getNames = function(string) { | ||
var name, _i, _len, _ref, _results; | ||
if (string[0] === '{' && string[string.length - 1] === '}') { | ||
_ref = string.slice(1, -1).split(','); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
name = _ref[_i]; | ||
_results.push(name.trim()); | ||
} | ||
return _results; | ||
} else { | ||
return [string.trim()]; | ||
} | ||
}; | ||
Compiler = (function() { | ||
@@ -619,6 +665,16 @@ | ||
this.imports = {}; | ||
this.importAs = {}; | ||
this.exports = []; | ||
this.exportAs = null; | ||
this.importDefault = {}; | ||
this.exports = {}; | ||
this.exportDefault = null; | ||
this.lines = []; | ||
this.id = 0; | ||
this.inBlockComment = false; | ||
this.reExportUnique = new Unique('reexport'); | ||
if (!this.options.coffee) { | ||
this.commentStart = COMMENT_START; | ||
this.commentEnd = COMMENT_END; | ||
} else { | ||
this.commentStart = COMMENT_CS_TOGGLE; | ||
this.commentEnd = COMMENT_CS_TOGGLE; | ||
} | ||
this.parse(); | ||
@@ -639,12 +695,26 @@ } | ||
var match; | ||
if (match = this.matchLine(line, EXPORT_AS)) { | ||
return this.processExportAs(match); | ||
} else if (match = this.matchLine(line, EXPORT)) { | ||
return this.processExport(match); | ||
} else if (match = this.matchLine(line, IMPORT_AS)) { | ||
return this.processImportAs(match); | ||
} else if (match = this.matchLine(line, IMPORT)) { | ||
return this.processImport(match); | ||
if (!this.inBlockComment) { | ||
if (match = this.matchLine(line, EXPORT_DEFAULT)) { | ||
return this.processExportDefault(match); | ||
} else if (match = this.matchLine(line, EXPORT_FUNCTION)) { | ||
return this.processExportFunction(match); | ||
} else if (match = this.matchLine(line, EXPORT_VAR)) { | ||
return this.processExportVar(match); | ||
} else if (match = this.matchLine(line, RE_EXPORT)) { | ||
return this.processReexport(match); | ||
} else if (match = this.matchLine(line, EXPORT)) { | ||
return this.processExport(match); | ||
} else if (match = this.matchLine(line, IMPORT)) { | ||
return this.processImport(match); | ||
} else if (match = this.matchLine(line, this.commentStart)) { | ||
return this.processEnterComment(line); | ||
} else { | ||
return this.processLine(line); | ||
} | ||
} else { | ||
return this.processLine(line); | ||
if (match = this.matchLine(line, this.commentEnd)) { | ||
return this.processExitComment(line); | ||
} else { | ||
return this.processLine(line); | ||
} | ||
} | ||
@@ -662,22 +732,13 @@ }; | ||
Compiler.prototype.processExportAs = function(match) { | ||
return this.exportAs = match[1]; | ||
Compiler.prototype.processExportDefault = function(match) { | ||
return this.exportDefault = match[1]; | ||
}; | ||
Compiler.prototype.processExport = function(match) { | ||
var ex, exports, _i, _len, _ref, _results; | ||
exports = match[1]; | ||
if (exports[0] === '{' && exports[exports.length - 1] === '}') { | ||
exports = exports.slice(1, -1); | ||
} | ||
_ref = exports.split(/\s*,\s*/); | ||
var ex, _i, _len, _ref, _results; | ||
_ref = getNames(match[1]); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
ex = _ref[_i]; | ||
ex = ex.trim(); | ||
if (__indexOf.call(this.exports, ex) < 0) { | ||
_results.push(this.exports.push(ex)); | ||
} else { | ||
_results.push(void 0); | ||
} | ||
_results.push(this.exports[ex] = ex); | ||
} | ||
@@ -687,25 +748,62 @@ return _results; | ||
Compiler.prototype.processImportAs = function(match) { | ||
return this.importAs[match[1] || match[2]] = match[3]; | ||
Compiler.prototype.processExportFunction = function(match) { | ||
var body, name; | ||
name = match[1]; | ||
body = match[2]; | ||
this.lines.push("function " + name + body); | ||
return this.exports[name] = name; | ||
}; | ||
Compiler.prototype.processExportVar = function(match) { | ||
var name, value; | ||
name = match[1]; | ||
value = match[2]; | ||
this.lines.push("var " + name + " = " + value); | ||
return this.exports[name] = name; | ||
}; | ||
Compiler.prototype.processImport = function(match) { | ||
var importNames, name, pattern; | ||
var asMatch, importSpecifiers, imports, name, pattern, _i, _len; | ||
pattern = match[1]; | ||
if (pattern[0] === '{' && pattern[pattern.length - 1] === '}') { | ||
pattern = pattern.slice(1, -1); | ||
importSpecifiers = (function() { | ||
var _i, _len, _ref, _results; | ||
_ref = pattern.split(/\s*,\s*/); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
name = _ref[_i]; | ||
_results.push(name.trim()); | ||
} | ||
return _results; | ||
})(); | ||
imports = {}; | ||
for (_i = 0, _len = importSpecifiers.length; _i < _len; _i++) { | ||
name = importSpecifiers[_i]; | ||
if (asMatch = name.match(IMPORT_AS)) { | ||
imports[asMatch[1]] = asMatch[2]; | ||
} else { | ||
imports[name] = name; | ||
} | ||
} | ||
return this.imports[match[2] || match[3]] = imports; | ||
} else { | ||
return this.importDefault[match[2] || match[3]] = match[1]; | ||
} | ||
importNames = (function() { | ||
var _i, _len, _ref, _results; | ||
_ref = pattern.split(/\s*,\s*/); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
name = _ref[_i]; | ||
_results.push(name.trim()); | ||
} | ||
return _results; | ||
})(); | ||
return this.imports[match[2] || match[3]] = importNames; | ||
}; | ||
Compiler.prototype.processReexport = function(match) { | ||
var importLocal, importPath, name, names, _i, _len, _results; | ||
names = getNames(match[1]); | ||
importPath = match[2] || match[3]; | ||
importLocal = this.reExportUnique.next(); | ||
this.importDefault[importPath] = importLocal; | ||
_results = []; | ||
for (_i = 0, _len = names.length; _i < _len; _i++) { | ||
name = names[_i]; | ||
_results.push(this.exports[name] = "" + importLocal + "." + name); | ||
} | ||
return _results; | ||
}; | ||
Compiler.prototype.processLine = function(line) { | ||
@@ -715,2 +813,14 @@ return this.lines.push(line); | ||
Compiler.prototype.processEnterComment = function(line) { | ||
if (!this.matchLine(line, COMMENT_END)) { | ||
this.inBlockComment = true; | ||
} | ||
return this.lines.push(line); | ||
}; | ||
Compiler.prototype.processExitComment = function(line) { | ||
this.inBlockComment = false; | ||
return this.lines.push(line); | ||
}; | ||
Compiler.prototype.toAMD = function() { | ||
@@ -739,3 +849,3 @@ return new AMDCompiler(this, this.options).stringify(); | ||
var AbstractCompiler, GlobalsCompiler, | ||
var AbstractCompiler, GlobalsCompiler, isEmpty, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -746,2 +856,4 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
isEmpty = require("./utils").isEmpty; | ||
GlobalsCompiler = (function(_super) { | ||
@@ -758,9 +870,9 @@ | ||
return this.build(function(s) { | ||
var args, globalImport, import_, into, locals, name, passedArgs, receivedArgs, wrapper, _i, _j, _len, _len1, _ref, _ref1; | ||
var alias, args, globalImport, into, locals, name, passedArgs, receivedArgs, wrapper, _i, _len, _ref, _ref1; | ||
passedArgs = []; | ||
receivedArgs = []; | ||
locals = {}; | ||
into = _this.options.into || _this.exportAs; | ||
if (_this.exports.length > 0 || _this.exportAs) { | ||
passedArgs.push(_this.exportAs ? s.global : into ? "" + s.global + "." + into + " = {}" : s.global); | ||
into = _this.options.into || _this.exportDefault; | ||
if (!isEmpty(_this.exports) || _this.exportDefault) { | ||
passedArgs.push(_this.exportDefault ? s.global : into ? "" + s.global + "." + into + " = {}" : s.global); | ||
receivedArgs.push('exports'); | ||
@@ -773,10 +885,11 @@ } | ||
passedArgs.push("" + s.global + "." + globalImport); | ||
if (name in _this.importAs) { | ||
receivedArgs.push(_this.importAs[name]); | ||
if (name in _this.importDefault) { | ||
receivedArgs.push(_this.importDefault[name]); | ||
} else { | ||
receivedArgs.push(globalImport); | ||
_ref1 = _this.imports[name]; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
import_ = _ref1[_j]; | ||
locals[import_] = "" + globalImport + "." + import_; | ||
for (name in _ref1) { | ||
if (!__hasProp.call(_ref1, name)) continue; | ||
alias = _ref1[name]; | ||
locals[alias] = "" + globalImport + "." + name; | ||
} | ||
@@ -787,3 +900,3 @@ } | ||
return s["function"](receivedArgs, function() { | ||
var export_, lhs, rhs, _k, _len2, _ref2, _results; | ||
var exportName, exportValue, lhs, rhs, _ref2, _results; | ||
s.useStrict(); | ||
@@ -796,10 +909,10 @@ for (lhs in locals) { | ||
s.append.apply(s, _this.lines); | ||
if (_this.exportAs) { | ||
return s.set("exports." + into, _this.exportAs); | ||
if (_this.exportDefault) { | ||
return s.set("exports." + into, _this.exportDefault); | ||
} else { | ||
_ref2 = _this.exports; | ||
_results = []; | ||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | ||
export_ = _ref2[_k]; | ||
_results.push(s.set("exports." + export_, export_)); | ||
for (exportName in _ref2) { | ||
exportValue = _ref2[exportName]; | ||
_results.push(s.set("exports." + exportName, exportValue)); | ||
} | ||
@@ -811,6 +924,6 @@ return _results; | ||
args = function(arg) { | ||
var passedArg, _k, _len2, _results; | ||
var passedArg, _j, _len1, _results; | ||
_results = []; | ||
for (_k = 0, _len2 = passedArgs.length; _k < _len2; _k++) { | ||
passedArg = passedArgs[_k]; | ||
for (_j = 0, _len1 = passedArgs.length; _j < _len1; _j++) { | ||
passedArg = passedArgs[_j]; | ||
_results.push(arg(passedArg)); | ||
@@ -884,2 +997,64 @@ } | ||
}, | ||
"require_support.js": function(module, exports, require){(function() { | ||
"use strict"; | ||
var Compiler, compile, defaultCoffeeHandler, defaultJSHandler, disable, enable, enabled, es6CoffeeRequireHandler, es6JSRequireHandler, fs, loadES6Script, path, vm; | ||
vm = require("vm"); | ||
fs = require("fs"); | ||
path = require("path"); | ||
Compiler = require("./compiler"); | ||
compile = require("coffee-script").compile; | ||
enabled = false; | ||
defaultJSHandler = require.extensions['.js']; | ||
defaultCoffeeHandler = require.extensions['.coffee']; | ||
enable = function() { | ||
if (enabled) { | ||
return; | ||
} | ||
enabled = true; | ||
require.extensions['.js'] = es6JSRequireHandler; | ||
return require.extensions['.coffee'] = es6CoffeeRequireHandler; | ||
}; | ||
disable = function() { | ||
if (!enabled) { | ||
return; | ||
} | ||
enabled = false; | ||
require.extensions['.js'] = defaultJSHandler; | ||
return require.extensions['.coffee'] = defaultCoffeeHandler; | ||
}; | ||
es6JSRequireHandler = function(module, filename) { | ||
return module._compile(loadES6Script(filename)); | ||
}; | ||
es6CoffeeRequireHandler = function(module, filename) { | ||
return module._compile(compile(loadES6Script(filename))); | ||
}; | ||
loadES6Script = function(filename) { | ||
var content, extname; | ||
content = fs.readFileSync(filename, 'utf8'); | ||
extname = path.extname(filename); | ||
return new Compiler(content, path.basename(filename, extname), { | ||
coffee: extname === '.coffee' | ||
}).toCJS(); | ||
}; | ||
exports.enable = enable; | ||
exports.disable = disable; | ||
}).call(this); | ||
}, | ||
"script_builder.js": function(module, exports, require){(function() { | ||
@@ -891,2 +1066,4 @@ "use strict"; | ||
Unique = require("./utils").Unique; | ||
INDENT = { | ||
@@ -1076,2 +1253,19 @@ indent: true | ||
module.exports = ScriptBuilder; | ||
}).call(this); | ||
}, | ||
"utils.js": function(module, exports, require){(function() { | ||
"use strict"; | ||
var Unique, isEmpty; | ||
isEmpty = function(object) { | ||
var foo; | ||
for (foo in object) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
Unique = (function() { | ||
@@ -1092,4 +1286,6 @@ | ||
module.exports = ScriptBuilder; | ||
exports.isEmpty = isEmpty; | ||
exports.Unique = Unique; | ||
}).call(this); | ||
@@ -1096,0 +1292,0 @@ }}; |
@@ -1,1 +0,1 @@ | ||
(function(){function require(e,t){for(var n=[],r=e.split("/"),i,s,o=0;s=r[o++];)".."==s?n.pop():"."!=s&&n.push(s);n=n.join("/"),o=require,s=o.m[t||0],i=s[n+".js"]||s[n+"/index.js"]||s[n];if(s=i.c)i=o.m[t=s][e=i.m];return i.exports||i(i,i.exports={},function(n){return o("."!=n.charAt(0)?n:e+"/../"+n,t)}),i.exports}require.m=[];require.m[0]={"abstract_compiler.js":function(module,exports,require){(function(){"use strict";var AbstractCompiler,CoffeeScriptBuilder,CompileError,JavaScriptBuilder,__hasProp={}.hasOwnProperty,__indexOf=[].indexOf||function(item){for(var i=0,l=this.length;i<l;i++){if(i in this&&this[i]===item)return i}return-1};CompileError=require("./compile_error");JavaScriptBuilder=require("./java_script_builder");CoffeeScriptBuilder=require("./coffee_script_builder");AbstractCompiler=function(){function AbstractCompiler(compiler,options){var name,_ref,_ref1;this.compiler=compiler;this.exports=compiler.exports;this.exportAs=compiler.exportAs;this.imports=compiler.imports;this.importAs=compiler.importAs;this.moduleName=compiler.moduleName;this.lines=compiler.lines;this.options=options;this.dependencyNames=[];_ref=this.imports;for(name in _ref){if(!__hasProp.call(_ref,name))continue;if(__indexOf.call(this.dependencyNames,name)<0){this.dependencyNames.push(name)}}_ref1=this.importAs;for(name in _ref1){if(!__hasProp.call(_ref1,name))continue;if(__indexOf.call(this.dependencyNames,name)<0){this.dependencyNames.push(name)}}this.assertValid()}AbstractCompiler.prototype.assertValid=function(){if(this.exportAs&&this.exports.length>0){throw new CompileError("You cannot use both `export =` and `export` in the same module")}};AbstractCompiler.prototype.buildPreamble=function(names){var args,preamble,_this=this;args=[];preamble=this.build(function(s){var dependency,deps,name,number,_i,_len,_results;number=0;deps=s.unique("dependency");_results=[];for(_i=0,_len=names.length;_i<_len;_i++){name=names[_i];if(name in _this.importAs){_results.push(args.push(_this.importAs[name]))}else{dependency=deps.next();args.push(dependency);_results.push(_this.buildImportsForPreamble(s,_this.imports[name],dependency))}}return _results});return[args,preamble]};AbstractCompiler.prototype.build=function(fn){var builder;if(this.options.coffee){builder=new CoffeeScriptBuilder}else{builder=new JavaScriptBuilder}fn(builder);return builder.toString()};AbstractCompiler.prototype.buildImportsForPreamble=function(builder,imports_,dependencyName){var import_,_i,_len,_results;_results=[];for(_i=0,_len=imports_.length;_i<_len;_i++){import_=imports_[_i];_results.push(builder["var"](import_,function(){return builder.prop(dependencyName,import_)}))}return _results};return AbstractCompiler}();module.exports=AbstractCompiler}).call(this)},"amd_compiler.js":function(module,exports,require){(function(){"use strict";var AMDCompiler,AbstractCompiler,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};AbstractCompiler=require("./abstract_compiler");AMDCompiler=function(_super){__extends(AMDCompiler,_super);function AMDCompiler(){return AMDCompiler.__super__.constructor.apply(this,arguments)}AMDCompiler.prototype.stringify=function(){var _this=this;return this.build(function(s){var preamble,wrapperArgs,_ref;_ref=_this.buildPreamble(_this.dependencyNames),wrapperArgs=_ref[0],preamble=_ref[1];if(_this.exports.length!==0){_this.dependencyNames.push("exports");wrapperArgs.push("__exports__")}return s.line(function(){return s.call("define",function(arg){if(_this.moduleName){arg(s.print(_this.moduleName))}arg(s["break"]);arg(s.print(_this.dependencyNames));arg(s["break"]);return arg(function(){return s["function"](wrapperArgs,function(){var export_,_i,_len,_ref1;s.useStrict();if(preamble){s.append(preamble)}s.append.apply(s,_this.lines);_ref1=_this.exports;for(_i=0,_len=_ref1.length;_i<_len;_i++){export_=_ref1[_i];s.line("__exports__."+export_+" = "+export_)}if(_this.exportAs){return s.line("return "+_this.exportAs)}})})})})})};return AMDCompiler}(AbstractCompiler);module.exports=AMDCompiler}).call(this)},"cjs_compiler.js":function(module,exports,require){(function(){"use strict";var AbstractCompiler,CJSCompiler,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};AbstractCompiler=require("./abstract_compiler");CJSCompiler=function(_super){__extends(CJSCompiler,_super);function CJSCompiler(){return CJSCompiler.__super__.constructor.apply(this,arguments)}CJSCompiler.prototype.stringify=function(){var _this=this;return this.build(function(s){var dependency,deps,doImport,export_,import_,name,variables,_i,_j,_len,_len1,_ref,_ref1,_ref2,_results;doImport=function(name,import_,prop){var req,rhs;if(prop==null){prop=null}req=function(){return s.call("require",[s.print(import_)])};rhs=prop?function(){return s.prop(req,prop)}:req;return s["var"](name,rhs)};s.useStrict();deps=s.unique("dependency");_ref=_this.importAs;for(import_ in _ref){if(!__hasProp.call(_ref,import_))continue;name=_ref[import_];doImport(name,import_)}_ref1=_this.imports;for(import_ in _ref1){if(!__hasProp.call(_ref1,import_))continue;variables=_ref1[import_];if(variables.length===1){name=variables[0];doImport(name,import_,name)}else{dependency=deps.next();doImport(dependency,import_);for(_i=0,_len=variables.length;_i<_len;_i++){name=variables[_i];s["var"](name,""+dependency+"."+name)}}}s.append.apply(s,_this.lines);if(_this.exportAs){s.line("module.exports = "+_this.exportAs)}_ref2=_this.exports;_results=[];for(_j=0,_len1=_ref2.length;_j<_len1;_j++){export_=_ref2[_j];_results.push(s.line("exports."+export_+" = "+export_))}return _results})};return CJSCompiler}(AbstractCompiler);module.exports=CJSCompiler}).call(this)},"cli.js":function(module,exports,require){(function(){"use strict";var CLI,Compiler,fs,optimist,path;optimist=require("optimist");fs=require("fs");path=require("path");Compiler=require("./compiler");CLI=function(){CLI.start=function(argv,stdin,stdout,fs_){if(stdin==null){stdin=process.stdin}if(stdout==null){stdout=process.stdout}if(fs_==null){fs_=fs}return new this(stdin,stdout,fs_).start(argv)};function CLI(stdin,stdout,fs){this.stdin=stdin!=null?stdin:process.stdin;this.stdout=stdout!=null?stdout:process.stdout;this.fs=fs!=null?fs:fs}CLI.prototype.start=function(argv){var filename,options,_i,_len,_ref;options=this.parseArgs(argv);if(options.help){this.argParser(argv).showHelp();return}if(options.stdio){this.processStdio(options)}else{_ref=options._;for(_i=0,_len=_ref.length;_i<_len;_i++){filename=_ref[_i];this.processPath(filename,options)}}return null};CLI.prototype.parseArgs=function(argv){var args,global,imports,pair,requirePath,_i,_len,_ref,_ref1;args=this.argParser(argv).argv;if(args.imports){imports={};_ref=args.imports.split(",");for(_i=0,_len=_ref.length;_i<_len;_i++){pair=_ref[_i];_ref1=pair.split(":"),requirePath=_ref1[0],global=_ref1[1];imports[requirePath]=global}args.imports=imports}if(args.global){args.into=args.global}return args};CLI.prototype.argParser=function(argv){return optimist(argv).usage("compile-modules usage:\n\n Using files:\n compile-modules INPUT --to DIR [--anonymous] [--type TYPE] [--imports PATH:GLOBAL]\n\n Using stdio:\n compile-modules --stdio [--coffee] [--type TYPE] [--imports PATH:GLOBAL] (--module-name MOD|--anonymous)").options({type:{"default":"amd",describe:'The type of output (one of "amd", "cjs", or "globals")'},to:{describe:"A directory in which to write the resulting files"},imports:{describe:"A list of path:global pairs, comma separated (e.g. jquery:$,ember:Ember)"},anonymous:{"default":false,type:"boolean",describe:"Do not include a module name"},"module-name":{describe:"The name of the outputted module",alias:"m"},stdio:{"default":false,type:"boolean",alias:"s",describe:"Use stdin and stdout to process a file"},coffee:{"default":false,type:"boolean",describe:"Process stdin as CoffeeScript (requires --stdio)"},global:{describe:"When the type is `globals`, the name of the global to export into"},help:{"default":false,type:"boolean",alias:"h",describe:"Shows this help message"}}).check(function(args){var _ref;return(_ref=args.type)==="amd"||_ref==="cjs"||_ref==="globals"}).check(function(args){return!(args.anonymous&&args.m)}).check(function(args){if(args.stdio&&args.type==="amd"){return args.anonymous||args.m||false}else{return true}}).check(function(args){return!(args.coffee&&!args.stdio)}).check(function(args){return args.stdio||args.to||args.help}).check(function(args){if(args.imports){return args.type==="globals"}else{return true}})};CLI.prototype.processStdio=function(options){var input,_this=this;input="";this.stdin.resume();this.stdin.setEncoding("utf8");this.stdin.on("data",function(data){return input+=data});return this.stdin.on("end",function(){var output;output=_this._compile(input,options.m,options.type,options);return _this.stdout.write(output)})};CLI.prototype.processPath=function(filename,options){var _this=this;return this.fs.stat(filename,function(err,stat){if(err){console.error(err.message);return process.exit(1)}else if(stat.isDirectory()){return _this.processDirectory(filename,options)}else{return _this.processFile(filename,options)}})};CLI.prototype.processDirectory=function(dirname,options){var _this=this;return this.fs.readdir(dirname,function(err,children){var child,_i,_len,_results;if(err){console.error(err.message);process.exit(1)}_results=[];for(_i=0,_len=children.length;_i<_len;_i++){child=children[_i];_results.push(_this.processPath(path.join(dirname,child),options))}return _results})};CLI.prototype.processFile=function(filename,options){var _this=this;return this.fs.readFile(filename,"utf8",function(err,input){var ext,moduleName,output,outputFilename;ext=path.extname(filename);moduleName=path.join(path.dirname(filename),path.basename(filename,ext));output=_this._compile(input,moduleName,options.type,{coffee:ext===".coffee",imports:options.imports});outputFilename=path.join(options.to,filename);_this._mkdirp(path.dirname(outputFilename));return _this.fs.writeFile(outputFilename,output,"utf8",function(err){if(err){console.error(err.message);return process.exit(1)}})})};CLI.prototype._compile=function(input,moduleName,type,options){var compiler,method;type={amd:"AMD",cjs:"CJS",globals:"Globals"}[type];compiler=new Compiler(input,moduleName,options);method="to"+type;return compiler[method]()};CLI.prototype._mkdirp=function(directory){var prefix;if(this.fs.existsSync(directory)){return}prefix=path.dirname(directory);if(prefix!=="."&&prefix!=="/"){this._mkdirp(prefix)}return this.fs.mkdirSync(directory)};return CLI}();module.exports=CLI}).call(this)},"coffee_script_builder.js":function(module,exports,require){(function(){"use strict";var CoffeeScriptBuilder,ScriptBuilder,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};ScriptBuilder=require("./script_builder");CoffeeScriptBuilder=function(_super){__extends(CoffeeScriptBuilder,_super);function CoffeeScriptBuilder(){return CoffeeScriptBuilder.__super__.constructor.apply(this,arguments)}CoffeeScriptBuilder.prototype.eol="";CoffeeScriptBuilder.prototype["var"]=function(lhs,rhs){return this.set(lhs,rhs)};CoffeeScriptBuilder.prototype._prepareArgsForCall=function(args){var arg,_i,_len;args=CoffeeScriptBuilder.__super__._prepareArgsForCall.call(this,args).slice();for(_i=0,_len=args.length;_i<_len;_i++){arg=args[_i];if(arg===this["break"]){if(args[args.length-1]!==this["break"]){args.push(this["break"])}break}}return args};CoffeeScriptBuilder.prototype._functionHeader=function(args){if(args.length){return"("+args.join(", ")+") ->"}else{return"->"}};return CoffeeScriptBuilder}(ScriptBuilder);module.exports=CoffeeScriptBuilder}).call(this)},"compile_error.js":function(module,exports,require){(function(){"use strict";var CompileError,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};CompileError=function(_super){__extends(CompileError,_super);function CompileError(){return CompileError.__super__.constructor.apply(this,arguments)}return CompileError}(Error);module.exports=CompileError}).call(this)},"compiler.js":function(module,exports,require){(function(){"use strict";var AMDCompiler,CJSCompiler,Compiler,EXPORT,EXPORT_AS,GlobalsCompiler,IMPORT,IMPORT_AS,__indexOf=[].indexOf||function(item){for(var i=0,l=this.length;i<l;i++){if(i in this&&this[i]===item)return i}return-1};AMDCompiler=require("./amd_compiler");CJSCompiler=require("./cjs_compiler");GlobalsCompiler=require("./globals_compiler");EXPORT=/^\s*export\s+(.*?)\s*(;)?\s*$/;EXPORT_AS=/^\s*export\s*=\s*(.*?)\s*(;)?\s*$/;IMPORT=/^\s*import\s+(.*)\s+from\s+(?:"([^"]+?)"|'([^']+?)')\s*(;)?\s*$/;IMPORT_AS=/^\s*import\s+(?:"([^"]+?)"|'([^']+?)')\s*as\s+(.*?)\s*(;)?\s*$/;Compiler=function(){function Compiler(string,moduleName,options){if(moduleName==null){moduleName=null}if(options==null){options={}}this.string=string;this.moduleName=moduleName;this.options=options;this.imports={};this.importAs={};this.exports=[];this.exportAs=null;this.lines=[];this.parse()}Compiler.prototype.parse=function(){var line,_i,_len,_ref;_ref=this.string.split("\n");for(_i=0,_len=_ref.length;_i<_len;_i++){line=_ref[_i];this.parseLine(line)}return null};Compiler.prototype.parseLine=function(line){var match;if(match=this.matchLine(line,EXPORT_AS)){return this.processExportAs(match)}else if(match=this.matchLine(line,EXPORT)){return this.processExport(match)}else if(match=this.matchLine(line,IMPORT_AS)){return this.processImportAs(match)}else if(match=this.matchLine(line,IMPORT)){return this.processImport(match)}else{return this.processLine(line)}};Compiler.prototype.matchLine=function(line,pattern){var match;match=line.match(pattern);if(match&&!this.options.coffee&&!match[match.length-1]){return null}return match};Compiler.prototype.processExportAs=function(match){return this.exportAs=match[1]};Compiler.prototype.processExport=function(match){var ex,exports,_i,_len,_ref,_results;exports=match[1];if(exports[0]==="{"&&exports[exports.length-1]==="}"){exports=exports.slice(1,-1)}_ref=exports.split(/\s*,\s*/);_results=[];for(_i=0,_len=_ref.length;_i<_len;_i++){ex=_ref[_i];ex=ex.trim();if(__indexOf.call(this.exports,ex)<0){_results.push(this.exports.push(ex))}else{_results.push(void 0)}}return _results};Compiler.prototype.processImportAs=function(match){return this.importAs[match[1]||match[2]]=match[3]};Compiler.prototype.processImport=function(match){var importNames,name,pattern;pattern=match[1];if(pattern[0]==="{"&&pattern[pattern.length-1]==="}"){pattern=pattern.slice(1,-1)}importNames=function(){var _i,_len,_ref,_results;_ref=pattern.split(/\s*,\s*/);_results=[];for(_i=0,_len=_ref.length;_i<_len;_i++){name=_ref[_i];_results.push(name.trim())}return _results}();return this.imports[match[2]||match[3]]=importNames};Compiler.prototype.processLine=function(line){return this.lines.push(line)};Compiler.prototype.toAMD=function(){return new AMDCompiler(this,this.options).stringify()};Compiler.prototype.toCJS=function(){return new CJSCompiler(this,this.options).stringify()};Compiler.prototype.toGlobals=function(){return new GlobalsCompiler(this,this.options).stringify()};return Compiler}();module.exports=Compiler}).call(this)},"globals_compiler.js":function(module,exports,require){(function(){"use strict";var AbstractCompiler,GlobalsCompiler,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};AbstractCompiler=require("./abstract_compiler");GlobalsCompiler=function(_super){__extends(GlobalsCompiler,_super);function GlobalsCompiler(){return GlobalsCompiler.__super__.constructor.apply(this,arguments)}GlobalsCompiler.prototype.stringify=function(){var _this=this;return this.build(function(s){var args,globalImport,import_,into,locals,name,passedArgs,receivedArgs,wrapper,_i,_j,_len,_len1,_ref,_ref1;passedArgs=[];receivedArgs=[];locals={};into=_this.options.into||_this.exportAs;if(_this.exports.length>0||_this.exportAs){passedArgs.push(_this.exportAs?s.global:into?""+s.global+"."+into+" = {}":s.global);receivedArgs.push("exports")}_ref=_this.dependencyNames;for(_i=0,_len=_ref.length;_i<_len;_i++){name=_ref[_i];globalImport=_this.options.imports[name];passedArgs.push(""+s.global+"."+globalImport);if(name in _this.importAs){receivedArgs.push(_this.importAs[name])}else{receivedArgs.push(globalImport);_ref1=_this.imports[name];for(_j=0,_len1=_ref1.length;_j<_len1;_j++){import_=_ref1[_j];locals[import_]=""+globalImport+"."+import_}}}wrapper=function(){return s["function"](receivedArgs,function(){var export_,lhs,rhs,_k,_len2,_ref2,_results;s.useStrict();for(lhs in locals){if(!__hasProp.call(locals,lhs))continue;rhs=locals[lhs];s["var"](lhs,rhs)}s.append.apply(s,_this.lines);if(_this.exportAs){return s.set("exports."+into,_this.exportAs)}else{_ref2=_this.exports;_results=[];for(_k=0,_len2=_ref2.length;_k<_len2;_k++){export_=_ref2[_k];_results.push(s.set("exports."+export_,export_))}return _results}})};args=function(arg){var passedArg,_k,_len2,_results;_results=[];for(_k=0,_len2=passedArgs.length;_k<_len2;_k++){passedArg=passedArgs[_k];_results.push(arg(passedArg))}return _results};return s.line(function(){return s.call(wrapper,args)})})};return GlobalsCompiler}(AbstractCompiler);module.exports=GlobalsCompiler}).call(this)},"index.js":function(module,exports,require){(function(){"use strict";var Compiler;Compiler=require("./compiler");exports.Compiler=Compiler}).call(this)},"java_script_builder.js":function(module,exports,require){(function(){"use strict";var JavaScriptBuilder,ScriptBuilder,__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};ScriptBuilder=require("./script_builder");JavaScriptBuilder=function(_super){__extends(JavaScriptBuilder,_super);function JavaScriptBuilder(){return JavaScriptBuilder.__super__.constructor.apply(this,arguments)}JavaScriptBuilder.prototype.eol=";";JavaScriptBuilder.prototype["var"]=function(lhs,rhs){return this.line("var "+this.capture(lhs)+" = "+this.capture(rhs))};JavaScriptBuilder.prototype._functionHeader=function(args){return"function("+args.join(", ")+") {"};JavaScriptBuilder.prototype._functionTail=function(){return"}"};return JavaScriptBuilder}(ScriptBuilder);module.exports=JavaScriptBuilder}).call(this)},"script_builder.js":function(module,exports,require){(function(){"use strict";var BREAK,INDENT,OUTDENT,ScriptBuilder,Unique,__slice=[].slice;INDENT={indent:true};OUTDENT={outdent:true};BREAK={"break":true};ScriptBuilder=function(){ScriptBuilder.prototype["break"]=BREAK;ScriptBuilder.prototype.global="window";function ScriptBuilder(){this.buffer=[]}ScriptBuilder.prototype.useStrict=function(){return this.line('"use strict"')};ScriptBuilder.prototype.set=function(lhs,rhs){return this.line(""+this.capture(lhs)+" = "+this.capture(rhs))};ScriptBuilder.prototype.call=function(fn,args){var arg,end,i,indented,result,_i,_len;fn=this._wrapCallable(fn);args=this._prepareArgsForCall(args);end=args.length-1;while(args[end]===BREAK){end--}result=""+fn+"(";indented=false;for(i=_i=0,_len=args.length;_i<_len;i=++_i){arg=args[i];if(arg===BREAK){this.append(result);if(!indented){indented=true;this.indent()}result=""}else{result+=arg;if(i<end){result+=",";if(args[i+1]!==BREAK){result+=" "}}}}result+=")";this.append(result);if(indented){return this.outdent()}};ScriptBuilder.prototype._prepareArgsForCall=function(args){var result,_this=this;if(typeof args==="function"){result=[];args(function(arg){return result.push(_this.capture(arg))});args=result}return args};ScriptBuilder.prototype._wrapCallable=function(fn){var functionCalled,functionImpl,result,_this=this;if(typeof fn!=="function"){return fn}functionImpl=this["function"];functionCalled=false;this["function"]=function(){var args;args=1<=arguments.length?__slice.call(arguments,0):[];functionCalled=true;return functionImpl.call.apply(functionImpl,[_this].concat(__slice.call(args)))};result=this.capture(fn);this["function"]=functionImpl;if(functionCalled){result="("+result+(this._functionTail!=null?"":"\n")+")"}return result};ScriptBuilder.prototype["function"]=function(args,body){this.append(this._functionHeader(args));this.indent();body();this.outdent();if(this._functionTail!=null){return this.append(this._functionTail())}};ScriptBuilder.prototype.print=function(value){return JSON.stringify(this.capture(value))};ScriptBuilder.prototype.prop=function(object,prop){return this.append(""+this.capture(object)+"."+this.capture(prop))};ScriptBuilder.prototype.unique=function(prefix){return new Unique(prefix)};ScriptBuilder.prototype.line=function(code){return this.append(this.capture(code)+this.eol)};ScriptBuilder.prototype.append=function(){var code,_ref;code=1<=arguments.length?__slice.call(arguments,0):[];return(_ref=this.buffer).push.apply(_ref,code)};ScriptBuilder.prototype.indent=function(){return this.buffer.push(INDENT)};ScriptBuilder.prototype.outdent=function(){return this.buffer.push(OUTDENT)};ScriptBuilder.prototype.capture=function(fn){var buffer,result;if(typeof fn!=="function"){return fn}buffer=this.buffer;this.buffer=[];fn();result=this.toString();this.buffer=buffer;return result};ScriptBuilder.prototype.toString=function(){var chunk,indent,line,result,_i,_j,_len,_len1,_ref,_ref1;indent=0;result=[];_ref=this.buffer;for(_i=0,_len=_ref.length;_i<_len;_i++){chunk=_ref[_i];if(chunk===INDENT){indent++}else if(chunk===OUTDENT){indent--}else{_ref1=chunk.split("\n");for(_j=0,_len1=_ref1.length;_j<_len1;_j++){line=_ref1[_j];if(/^\s*$/.test(line)){result.push(line)}else{result.push(new Array(indent+1).join(" ")+line)}}}}return result.join("\n")};return ScriptBuilder}();Unique=function(){function Unique(prefix){this.prefix=prefix;this.index=1}Unique.prototype.next=function(){return"__"+this.prefix+this.index++ +"__"};return Unique}();module.exports=ScriptBuilder}).call(this)}};ModuleTranspiler=require("index.js")})(); | ||
!function(){function a(b,c){for(var d,e,f=[],g=b.split("/"),h=0;null!=(e=g[h++]);)".."==e?f.pop():"."!=e&&f.push(e);if(f=f.join("/"),h=a,e=h.m[c||0],d=e[f+".js"]||e[f+"/index.js"]||e[f],g='Cannot require("'+f+'")',!d)throw Error(g);if((e=d.c)&&(d=h.m[c=e][b=d.m]),!d)throw Error(g);return d.exports||d(d,d.exports={},function(a){return h("."!=a.charAt(0)?a:b+"/../"+a,c)}),d.exports}a.m=[],a.m[0]={"abstract_compiler.js":function(a,b,c){!function(){"use strict";var b,d,e,f,g,h={}.hasOwnProperty,i=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};e=c("./compile_error"),f=c("./java_script_builder"),d=c("./coffee_script_builder"),g=c("./utils").isEmpty,b=function(){function a(a,b){var c,d,e;this.compiler=a,this.exports=a.exports,this.exportDefault=a.exportDefault,this.imports=a.imports,this.importDefault=a.importDefault,this.moduleName=a.moduleName,this.lines=a.lines,this.options=b,this.dependencyNames=[],d=this.imports;for(c in d)h.call(d,c)&&i.call(this.dependencyNames,c)<0&&this.dependencyNames.push(c);e=this.importDefault;for(c in e)h.call(e,c)&&i.call(this.dependencyNames,c)<0&&this.dependencyNames.push(c);this.assertValid()}return a.prototype.assertValid=function(){if(this.exportDefault&&!g(this.exports))throw new e("You cannot use both `export default` and `export` in the same module")},a.prototype.buildPreamble=function(a){var b,c,d=this;return b=[],c=this.build(function(c){var e,f,g,h,i,j,k;for(h=0,f=c.unique("dependency"),k=[],i=0,j=a.length;j>i;i++)g=a[i],g in d.importDefault?k.push(b.push(d.importDefault[g])):(e=f.next(),b.push(e),k.push(d.buildImportsForPreamble(c,d.imports[g],e)));return k}),[b,c]},a.prototype.build=function(a){var b;return b=this.options.coffee?new d:new f,a(b),b.toString()},a.prototype.buildImportsForPreamble=function(a,b,c){var d,e,f;f=[];for(e in b)h.call(b,e)&&(d=b[e],f.push(a["var"](d,function(){return a.prop(c,e)})));return f},a}(),a.exports=b}.call(this)},"amd_compiler.js":function(a,b,c){!function(){"use strict";var b,d,e,f,g={}.hasOwnProperty,h=function(a,b){function c(){this.constructor=a}for(var d in b)g.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};d=c("./abstract_compiler"),f=c("path"),e=c("./utils").isEmpty,b=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return h(b,a),b.prototype.stringify=function(){var a=this;return this.build(function(b){var c,d,g,h,i;i=a.buildPreamble(a.dependencyNames),h=i[0],g=i[1],e(a.exports)||(a.dependencyNames.push("exports"),h.push("__exports__"));for(d in a.dependencyNames)c=a.dependencyNames[d],/^\./.test(c)&&(a.dependencyNames[d]=f.join(a.moduleName,"..",c).replace(/[\\]/g,"/"));return b.line(function(){return b.call("define",function(c){return a.moduleName&&c(b.print(a.moduleName)),c(b["break"]),c(b.print(a.dependencyNames)),c(b["break"]),c(function(){return b["function"](h,function(){var c,d,e;b.useStrict(),g&&b.append(g),b.append.apply(b,a.lines),e=a.exports;for(c in e)d=e[c],b.line("__exports__."+c+" = "+d);return a.exportDefault?b.line("return "+a.exportDefault):void 0})})})})})},b}(d),a.exports=b}.call(this)},"cjs_compiler.js":function(a,b,c){!function(){"use strict";var b,d,e={}.hasOwnProperty,f=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};b=c("./abstract_compiler"),d=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return f(b,a),b.prototype.stringify=function(){var a=this;return this.build(function(b){var c,d,f,g,h,i,j,k,l,m,n,o,p;g=function(a,c,d){var e,f;return null==d&&(d=null),e=function(){return b.call("require",[b.print(c)])},f=d?function(){return b.prop(e,d)}:e,b["var"](a,f)},b.useStrict(),f=b.unique("dependency"),m=a.importDefault;for(j in m)e.call(m,j)&&(k=m[j],g(k,j));n=a.imports;for(j in n)if(e.call(n,j))if(l=n[j],1===Object.keys(l).length)k=Object.keys(l)[0],g(l[k],j,k);else{d=f.next(),g(d,j);for(k in l)e.call(l,k)&&(c=l[k],"default"===k?b["var"](c,""+d):b["var"](c,""+d+"."+k))}b.append.apply(b,a.lines),a.exportDefault&&b.line("module.exports = "+a.exportDefault),o=a.exports,p=[];for(h in o)i=o[h],p.push(b.line("exports."+h+" = "+i));return p})},b}(b),a.exports=d}.call(this)},"cli.js":function(a,b,c){!function(){"use strict";var b,d,e,f,g;f=c("optimist"),e=c("fs"),g=c("path"),d=c("./compiler"),b=function(){function a(a,b,c){this.stdin=null!=a?a:process.stdin,this.stdout=null!=b?b:process.stdout,this.fs=null!=c?c:c}return a.start=function(a,b,c,d){return null==b&&(b=process.stdin),null==c&&(c=process.stdout),null==d&&(d=e),new this(b,c,d).start(a)},a.prototype.start=function(a){var b,c,d,e,f;if(c=this.parseArgs(a),c.help)return this.argParser(a).showHelp(),void 0;if(c.stdio)this.processStdio(c);else for(f=c._,d=0,e=f.length;e>d;d++)b=f[d],this.processPath(b,c);return null},a.prototype.parseArgs=function(a){var b,c,d,e,f,g,h,i,j;if(b=this.argParser(a).argv,b.imports){for(d={},i=b.imports.split(","),g=0,h=i.length;h>g;g++)e=i[g],j=e.split(":"),f=j[0],c=j[1],d[f]=c;b.imports=d}return b.global&&(b.into=b.global),b},a.prototype.argParser=function(a){return f(a).usage("compile-modules usage:\n\n Using files:\n compile-modules INPUT --to DIR [--anonymous] [--type TYPE] [--imports PATH:GLOBAL]\n\n Using stdio:\n compile-modules --stdio [--coffee] [--type TYPE] [--imports PATH:GLOBAL] (--module-name MOD|--anonymous)").options({type:{"default":"amd",describe:'The type of output (one of "amd", "cjs", or "globals")'},to:{describe:"A directory in which to write the resulting files"},imports:{describe:"A list of path:global pairs, comma separated (e.g. jquery:$,ember:Ember)"},anonymous:{"default":!1,type:"boolean",describe:"Do not include a module name"},"module-name":{describe:"The name of the outputted module",alias:"m"},stdio:{"default":!1,type:"boolean",alias:"s",describe:"Use stdin and stdout to process a file"},coffee:{"default":!1,type:"boolean",describe:"Process stdin as CoffeeScript (requires --stdio)"},global:{describe:"When the type is `globals`, the name of the global to export into"},help:{"default":!1,type:"boolean",alias:"h",describe:"Shows this help message"}}).check(function(a){var b;return"amd"===(b=a.type)||"cjs"===b||"globals"===b}).check(function(a){return!(a.anonymous&&a.m)}).check(function(a){return a.stdio&&"amd"===a.type?a.anonymous||a.m||!1:!0}).check(function(a){return!(a.coffee&&!a.stdio)}).check(function(a){return a.stdio||a.to||a.help}).check(function(a){return a.imports?"globals"===a.type:!0})},a.prototype.processStdio=function(a){var b,c=this;return b="",this.stdin.resume(),this.stdin.setEncoding("utf8"),this.stdin.on("data",function(a){return b+=a}),this.stdin.on("end",function(){var d;return d=c._compile(b,a.m,a.type,a),c.stdout.write(d)})},a.prototype.processPath=function(a,b){var c=this;return this.fs.stat(a,function(d,e){return d?(console.error(d.message),process.exit(1)):e.isDirectory()?c.processDirectory(a,b):c.processFile(a,b)})},a.prototype.processDirectory=function(a,b){var c=this;return this.fs.readdir(a,function(d,e){var f,h,i,j;for(d&&(console.error(d.message),process.exit(1)),j=[],h=0,i=e.length;i>h;h++)f=e[h],j.push(c.processPath(g.join(a,f),b));return j})},a.prototype.processFile=function(a,b){var c=this;return this.fs.readFile(a,"utf8",function(d,e){var f,h,i,j;return f=g.extname(a),h=g.join(g.dirname(a),g.basename(a,f)).replace(/[\\]/g,"/"),i=c._compile(e,h,b.type,{coffee:".coffee"===f,imports:b.imports}),j=g.join(b.to,a).replace(/[\\]/g,"/"),c._mkdirp(g.dirname(j)),c.fs.writeFile(j,i,"utf8",function(a){return a?(console.error(a.message),process.exit(1)):void 0})})},a.prototype._compile=function(a,b,c,e){var f,g;return c={amd:"AMD",cjs:"CJS",globals:"Globals"}[c],f=new d(a,b,e),g="to"+c,f[g]()},a.prototype._mkdirp=function(a){var b;if(!this.fs.existsSync(a))return b=g.dirname(a),"."!==b&&"/"!==b&&this._mkdirp(b),this.fs.mkdirSync(a)},a}(),a.exports=b}.call(this)},"coffee_script_builder.js":function(a,b,c){!function(){"use strict";var b,d,e={}.hasOwnProperty,f=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};d=c("./script_builder"),b=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return f(b,a),b.prototype.eol="",b.prototype["var"]=function(a,b){return this.set(a,b)},b.prototype._prepareArgsForCall=function(a){var c,d,e;for(a=b.__super__._prepareArgsForCall.call(this,a).slice(),d=0,e=a.length;e>d;d++)if(c=a[d],c===this["break"]){a[a.length-1]!==this["break"]&&a.push(this["break"]);break}return a},b.prototype._functionHeader=function(a){return a.length?"("+a.join(", ")+") ->":"->"},b}(d),a.exports=b}.call(this)},"compile_error.js":function(a){!function(){"use strict";var b,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};b=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return d(b,a),b}(Error),a.exports=b}.call(this)},"compiler.js":function(a,b,c){!function(){"use strict";var b,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;b=c("./amd_compiler"),d=c("./cjs_compiler"),m=c("./globals_compiler"),q=c("./utils").Unique,i=/^\s*export\s+(.*?)\s*(;)?\s*$/,j=/^\s*export\s*default\s*(.*?)\s*(;)?\s*$/,k=/^\s*export\s+function\s+(\w+)\s*(\(.*)$/,l=/^\s*export\s+var\s+(\w+)\s*=\s*(.*)$/,n=/^\s*import\s+(.*)\s+from\s+(?:"([^"]+?)"|'([^']+?)')\s*(;)?\s*$/,o=/^\s*(.*)\s+as\s+(.*)\s*$/,p=/^export\s+({.*})\s+from\s+(?:"([^"]+?)"|'([^']+?)')\s*(;)?\s*$/,g=new RegExp("/\\*"),f=new RegExp("\\*/"),e=/^###/,r=function(a){var b,c,d,e,f;if("{"===a[0]&&"}"===a[a.length-1]){for(e=a.slice(1,-1).split(","),f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(b.trim());return f}return[a.trim()]},h=function(){function a(a,b,c){null==b&&(b=null),null==c&&(c={}),this.string=a,this.moduleName=b,this.options=c,this.imports={},this.importDefault={},this.exports={},this.exportDefault=null,this.lines=[],this.id=0,this.inBlockComment=!1,this.reExportUnique=new q("reexport"),this.options.coffee?(this.commentStart=e,this.commentEnd=e):(this.commentStart=g,this.commentEnd=f),this.parse()}return a.prototype.parse=function(){var a,b,c,d;for(d=this.string.split("\n"),b=0,c=d.length;c>b;b++)a=d[b],this.parseLine(a);return null},a.prototype.parseLine=function(a){var b;return this.inBlockComment?(b=this.matchLine(a,this.commentEnd))?this.processExitComment(a):this.processLine(a):(b=this.matchLine(a,j))?this.processExportDefault(b):(b=this.matchLine(a,k))?this.processExportFunction(b):(b=this.matchLine(a,l))?this.processExportVar(b):(b=this.matchLine(a,p))?this.processReexport(b):(b=this.matchLine(a,i))?this.processExport(b):(b=this.matchLine(a,n))?this.processImport(b):(b=this.matchLine(a,this.commentStart))?this.processEnterComment(a):this.processLine(a)},a.prototype.matchLine=function(a,b){var c;return c=a.match(b),!c||this.options.coffee||c[c.length-1]?c:null},a.prototype.processExportDefault=function(a){return this.exportDefault=a[1]},a.prototype.processExport=function(a){var b,c,d,e,f;for(e=r(a[1]),f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(this.exports[b]=b);return f},a.prototype.processExportFunction=function(a){var b,c;return c=a[1],b=a[2],this.lines.push("function "+c+b),this.exports[c]=c},a.prototype.processExportVar=function(a){var b,c;return b=a[1],c=a[2],this.lines.push("var "+b+" = "+c),this.exports[b]=b},a.prototype.processImport=function(a){var b,c,d,e,f,g,h;if(f=a[1],"{"===f[0]&&"}"===f[f.length-1]){for(f=f.slice(1,-1),c=function(){var a,b,c,d;for(c=f.split(/\s*,\s*/),d=[],a=0,b=c.length;b>a;a++)e=c[a],d.push(e.trim());return d}(),d={},g=0,h=c.length;h>g;g++)e=c[g],(b=e.match(o))?d[b[1]]=b[2]:d[e]=e;return this.imports[a[2]||a[3]]=d}return this.importDefault[a[2]||a[3]]=a[1]},a.prototype.processReexport=function(a){var b,c,d,e,f,g,h;for(e=r(a[1]),c=a[2]||a[3],b=this.reExportUnique.next(),this.importDefault[c]=b,h=[],f=0,g=e.length;g>f;f++)d=e[f],h.push(this.exports[d]=""+b+"."+d);return h},a.prototype.processLine=function(a){return this.lines.push(a)},a.prototype.processEnterComment=function(a){return this.matchLine(a,f)||(this.inBlockComment=!0),this.lines.push(a)},a.prototype.processExitComment=function(a){return this.inBlockComment=!1,this.lines.push(a)},a.prototype.toAMD=function(){return new b(this,this.options).stringify()},a.prototype.toCJS=function(){return new d(this,this.options).stringify()},a.prototype.toGlobals=function(){return new m(this,this.options).stringify()},a}(),a.exports=h}.call(this)},"globals_compiler.js":function(a,b,c){!function(){"use strict";var b,d,e,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};b=c("./abstract_compiler"),e=c("./utils").isEmpty,d=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return g(b,a),b.prototype.stringify=function(){var a=this;return this.build(function(b){var c,d,g,h,i,j,k,l,m,n,o,p,q;for(k=[],l=[],i={},h=a.options.into||a.exportDefault,(!e(a.exports)||a.exportDefault)&&(k.push(a.exportDefault?b.global:h?""+b.global+"."+h+" = {}":b.global),l.push("exports")),p=a.dependencyNames,n=0,o=p.length;o>n;n++)if(j=p[n],g=a.options.imports[j],k.push(""+b.global+"."+g),j in a.importDefault)l.push(a.importDefault[j]);else{l.push(g),q=a.imports[j];for(j in q)f.call(q,j)&&(c=q[j],i[c]=""+g+"."+j)}return m=function(){return b["function"](l,function(){var c,d,e,g,j,k;b.useStrict();for(e in i)f.call(i,e)&&(g=i[e],b["var"](e,g));if(b.append.apply(b,a.lines),a.exportDefault)return b.set("exports."+h,a.exportDefault);j=a.exports,k=[];for(c in j)d=j[c],k.push(b.set("exports."+c,d));return k})},d=function(a){var b,c,d,e;for(e=[],c=0,d=k.length;d>c;c++)b=k[c],e.push(a(b));return e},b.line(function(){return b.call(m,d)})})},b}(b),a.exports=d}.call(this)},"index.js":function(a,b,c){!function(){"use strict";var a;a=c("./compiler"),b.Compiler=a}.call(this)},"java_script_builder.js":function(a,b,c){!function(){"use strict";var b,d,e={}.hasOwnProperty,f=function(a,b){function c(){this.constructor=a}for(var d in b)e.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};d=c("./script_builder"),b=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return f(b,a),b.prototype.eol=";",b.prototype["var"]=function(a,b){return this.line("var "+this.capture(a)+" = "+this.capture(b))},b.prototype._functionHeader=function(a){return"function("+a.join(", ")+") {"},b.prototype._functionTail=function(){return"}"},b}(d),a.exports=b}.call(this)},"require_support.js":function(a,b,c){!function(){"use strict";var a,d,e,f,g,h,i,j,k,l,m,n,o;o=c("vm"),l=c("fs"),n=c("path"),a=c("./compiler"),d=c("coffee-script").compile,i=!1,f=c.extensions[".js"],e=c.extensions[".coffee"],h=function(){return i?void 0:(i=!0,c.extensions[".js"]=k,c.extensions[".coffee"]=j)},g=function(){return i?(i=!1,c.extensions[".js"]=f,c.extensions[".coffee"]=e):void 0},k=function(a,b){return a._compile(m(b))},j=function(a,b){return a._compile(d(m(b)))},m=function(b){var c,d;return c=l.readFileSync(b,"utf8"),d=n.extname(b),new a(c,n.basename(b,d),{coffee:".coffee"===d}).toCJS()},b.enable=h,b.disable=g}.call(this)},"script_builder.js":function(a,b,c){!function(){"use strict";var b,d,e,f,g,h=[].slice;g=c("./utils").Unique,d={indent:!0},e={outdent:!0},b={"break":!0},f=function(){function a(){this.buffer=[]}return a.prototype["break"]=b,a.prototype.global="window",a.prototype.useStrict=function(){return this.line('"use strict"')},a.prototype.set=function(a,b){return this.line(""+this.capture(a)+" = "+this.capture(b))},a.prototype.call=function(a,c){var d,e,f,g,h,i,j;for(a=this._wrapCallable(a),c=this._prepareArgsForCall(c),e=c.length-1;c[e]===b;)e--;for(h=""+a+"(",g=!1,f=i=0,j=c.length;j>i;f=++i)d=c[f],d===b?(this.append(h),g||(g=!0,this.indent()),h=""):(h+=d,e>f&&(h+=",",c[f+1]!==b&&(h+=" ")));return h+=")",this.append(h),g?this.outdent():void 0},a.prototype._prepareArgsForCall=function(a){var b,c=this;return"function"==typeof a&&(b=[],a(function(a){return b.push(c.capture(a))}),a=b),a},a.prototype._wrapCallable=function(a){var b,c,d,e=this;return"function"!=typeof a?a:(c=this["function"],b=!1,this["function"]=function(){var a;return a=1<=arguments.length?h.call(arguments,0):[],b=!0,c.call.apply(c,[e].concat(h.call(a)))},d=this.capture(a),this["function"]=c,b&&(d="("+d+(null!=this._functionTail?"":"\n")+")"),d)},a.prototype["function"]=function(a,b){return this.append(this._functionHeader(a)),this.indent(),b(),this.outdent(),null!=this._functionTail?this.append(this._functionTail()):void 0},a.prototype.print=function(a){return JSON.stringify(this.capture(a))},a.prototype.prop=function(a,b){return this.append(""+this.capture(a)+"."+this.capture(b))},a.prototype.unique=function(a){return new g(a)},a.prototype.line=function(a){return this.append(this.capture(a)+this.eol)},a.prototype.append=function(){var a,b;return a=1<=arguments.length?h.call(arguments,0):[],(b=this.buffer).push.apply(b,a)},a.prototype.indent=function(){return this.buffer.push(d)},a.prototype.outdent=function(){return this.buffer.push(e)},a.prototype.capture=function(a){var b,c;return"function"!=typeof a?a:(b=this.buffer,this.buffer=[],a(),c=this.toString(),this.buffer=b,c)},a.prototype.toString=function(){var a,b,c,f,g,h,i,j,k,l;for(b=0,f=[],k=this.buffer,g=0,i=k.length;i>g;g++)if(a=k[g],a===d)b++;else if(a===e)b--;else for(l=a.split("\n"),h=0,j=l.length;j>h;h++)c=l[h],/^\s*$/.test(c)?f.push(c):f.push(new Array(b+1).join(" ")+c);return f.join("\n")},a}(),a.exports=f}.call(this)},"utils.js":function(a,b){!function(){"use strict";var a,c;c=function(a){var b;for(b in a)return!1;return!0},a=function(){function a(a){this.prefix=a,this.index=1}return a.prototype.next=function(){return"__"+this.prefix+this.index++ +"__"},a}(),b.isEmpty=c,b.Unique=a}.call(this)}},ModuleTranspiler=a("index.js")}(); |
@@ -22,5 +22,5 @@ (function() { | ||
this.exports = compiler.exports; | ||
this.exportAs = compiler.exportAs; | ||
this.exportDefault = compiler.exportDefault; | ||
this.imports = compiler.imports; | ||
this.importAs = compiler.importAs; | ||
this.importDefault = compiler.importDefault; | ||
this.moduleName = compiler.moduleName; | ||
@@ -37,3 +37,3 @@ this.lines = compiler.lines; | ||
} | ||
_ref1 = this.importAs; | ||
_ref1 = this.importDefault; | ||
for (name in _ref1) { | ||
@@ -49,4 +49,4 @@ if (!__hasProp.call(_ref1, name)) continue; | ||
AbstractCompiler.prototype.assertValid = function() { | ||
if (this.exportAs && !isEmpty(this.exports)) { | ||
throw new CompileError("You cannot use both `export =` and `export` in the same module"); | ||
if (this.exportDefault && !isEmpty(this.exports)) { | ||
throw new CompileError("You cannot use both `export default` and `export` in the same module"); | ||
} | ||
@@ -66,4 +66,4 @@ }; | ||
name = names[_i]; | ||
if (name in _this.importAs) { | ||
_results.push(args.push(_this.importAs[name])); | ||
if (name in _this.importDefault) { | ||
_results.push(args.push(_this.importDefault[name])); | ||
} else { | ||
@@ -92,8 +92,9 @@ dependency = deps.next(); | ||
AbstractCompiler.prototype.buildImportsForPreamble = function(builder, imports_, dependencyName) { | ||
var import_, _i, _len, _results; | ||
var alias, name, _results; | ||
_results = []; | ||
for (_i = 0, _len = imports_.length; _i < _len; _i++) { | ||
import_ = imports_[_i]; | ||
_results.push(builder["var"](import_, function() { | ||
return builder.prop(dependencyName, import_); | ||
for (name in imports_) { | ||
if (!__hasProp.call(imports_, name)) continue; | ||
alias = imports_[name]; | ||
_results.push(builder["var"](alias, function() { | ||
return builder.prop(dependencyName, name); | ||
})); | ||
@@ -100,0 +101,0 @@ } |
@@ -34,3 +34,3 @@ (function() { | ||
if (/^\./.test(dependency)) { | ||
_this.dependencyNames[i] = path.join(_this.moduleName, '..', dependency); | ||
_this.dependencyNames[i] = path.join(_this.moduleName, '..', dependency).replace(/[\\]/g, '/'); | ||
} | ||
@@ -59,4 +59,4 @@ } | ||
} | ||
if (_this.exportAs) { | ||
return s.line("return " + _this.exportAs); | ||
if (_this.exportDefault) { | ||
return s.line("return " + _this.exportDefault); | ||
} | ||
@@ -63,0 +63,0 @@ }); |
@@ -21,3 +21,3 @@ (function() { | ||
return this.build(function(s) { | ||
var dependency, deps, doImport, exportName, exportValue, import_, name, variables, _i, _len, _ref, _ref1, _ref2, _results; | ||
var alias, dependency, deps, doImport, exportName, exportValue, import_, name, variables, _ref, _ref1, _ref2, _results; | ||
doImport = function(name, import_, prop) { | ||
@@ -38,3 +38,3 @@ var req, rhs; | ||
deps = s.unique('dependency'); | ||
_ref = _this.importAs; | ||
_ref = _this.importDefault; | ||
for (import_ in _ref) { | ||
@@ -49,11 +49,16 @@ if (!__hasProp.call(_ref, import_)) continue; | ||
variables = _ref1[import_]; | ||
if (variables.length === 1) { | ||
name = variables[0]; | ||
doImport(name, import_, name); | ||
if (Object.keys(variables).length === 1) { | ||
name = Object.keys(variables)[0]; | ||
doImport(variables[name], import_, name); | ||
} else { | ||
dependency = deps.next(); | ||
doImport(dependency, import_); | ||
for (_i = 0, _len = variables.length; _i < _len; _i++) { | ||
name = variables[_i]; | ||
s["var"](name, "" + dependency + "." + name); | ||
for (name in variables) { | ||
if (!__hasProp.call(variables, name)) continue; | ||
alias = variables[name]; | ||
if (name === 'default') { | ||
s["var"](alias, "" + dependency); | ||
} else { | ||
s["var"](alias, "" + dependency + "." + name); | ||
} | ||
} | ||
@@ -63,4 +68,4 @@ } | ||
s.append.apply(s, _this.lines); | ||
if (_this.exportAs) { | ||
s.line("module.exports = " + _this.exportAs); | ||
if (_this.exportDefault) { | ||
s.line("module.exports = " + _this.exportDefault); | ||
} | ||
@@ -67,0 +72,0 @@ _ref2 = _this.exports; |
@@ -190,3 +190,3 @@ (function() { | ||
ext = path.extname(filename); | ||
moduleName = path.join(path.dirname(filename), path.basename(filename, ext)); | ||
moduleName = path.join(path.dirname(filename), path.basename(filename, ext)).replace(/[\\]/g, '/'); | ||
output = _this._compile(input, moduleName, options.type, { | ||
@@ -196,3 +196,3 @@ coffee: ext === '.coffee', | ||
}); | ||
outputFilename = path.join(options.to, filename); | ||
outputFilename = path.join(options.to, filename).replace(/[\\]/g, '/'); | ||
_this._mkdirp(path.dirname(outputFilename)); | ||
@@ -199,0 +199,0 @@ return _this.fs.writeFile(outputFilename, output, 'utf8', function(err) { |
(function() { | ||
"use strict"; | ||
var AMDCompiler, CJSCompiler, COMMENT_CS_TOGGLE, COMMENT_END, COMMENT_START, Compiler, EXPORT, EXPORT_AS, EXPORT_FUNCTION, EXPORT_VAR, GlobalsCompiler, IMPORT, IMPORT_AS; | ||
var AMDCompiler, CJSCompiler, COMMENT_CS_TOGGLE, COMMENT_END, COMMENT_START, Compiler, EXPORT, EXPORT_DEFAULT, EXPORT_FUNCTION, EXPORT_VAR, GlobalsCompiler, IMPORT, IMPORT_AS, RE_EXPORT, Unique, getNames; | ||
@@ -12,5 +12,7 @@ AMDCompiler = require("./amd_compiler"); | ||
Unique = require("./utils").Unique; | ||
EXPORT = /^\s*export\s+(.*?)\s*(;)?\s*$/; | ||
EXPORT_AS = /^\s*export\s*=\s*(.*?)\s*(;)?\s*$/; | ||
EXPORT_DEFAULT = /^\s*export\s*default\s*(.*?)\s*(;)?\s*$/; | ||
@@ -23,4 +25,6 @@ EXPORT_FUNCTION = /^\s*export\s+function\s+(\w+)\s*(\(.*)$/; | ||
IMPORT_AS = /^\s*import\s+(?:"([^"]+?)"|'([^']+?)')\s*as\s+(.*?)\s*(;)?\s*$/; | ||
IMPORT_AS = /^\s*(.*)\s+as\s+(.*)\s*$/; | ||
RE_EXPORT = /^export\s+({.*})\s+from\s+(?:"([^"]+?)"|'([^']+?)')\s*(;)?\s*$/; | ||
COMMENT_START = new RegExp("/\\*"); | ||
@@ -32,2 +36,17 @@ | ||
getNames = function(string) { | ||
var name, _i, _len, _ref, _results; | ||
if (string[0] === '{' && string[string.length - 1] === '}') { | ||
_ref = string.slice(1, -1).split(','); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
name = _ref[_i]; | ||
_results.push(name.trim()); | ||
} | ||
return _results; | ||
} else { | ||
return [string.trim()]; | ||
} | ||
}; | ||
Compiler = (function() { | ||
@@ -46,8 +65,9 @@ | ||
this.imports = {}; | ||
this.importAs = {}; | ||
this.importDefault = {}; | ||
this.exports = {}; | ||
this.exportAs = null; | ||
this.exportDefault = null; | ||
this.lines = []; | ||
this.id = 0; | ||
this.inBlockComment = false; | ||
this.reExportUnique = new Unique('reexport'); | ||
if (!this.options.coffee) { | ||
@@ -76,4 +96,4 @@ this.commentStart = COMMENT_START; | ||
if (!this.inBlockComment) { | ||
if (match = this.matchLine(line, EXPORT_AS)) { | ||
return this.processExportAs(match); | ||
if (match = this.matchLine(line, EXPORT_DEFAULT)) { | ||
return this.processExportDefault(match); | ||
} else if (match = this.matchLine(line, EXPORT_FUNCTION)) { | ||
@@ -83,6 +103,6 @@ return this.processExportFunction(match); | ||
return this.processExportVar(match); | ||
} else if (match = this.matchLine(line, RE_EXPORT)) { | ||
return this.processReexport(match); | ||
} else if (match = this.matchLine(line, EXPORT)) { | ||
return this.processExport(match); | ||
} else if (match = this.matchLine(line, IMPORT_AS)) { | ||
return this.processImportAs(match); | ||
} else if (match = this.matchLine(line, IMPORT)) { | ||
@@ -113,17 +133,12 @@ return this.processImport(match); | ||
Compiler.prototype.processExportAs = function(match) { | ||
return this.exportAs = match[1]; | ||
Compiler.prototype.processExportDefault = function(match) { | ||
return this.exportDefault = match[1]; | ||
}; | ||
Compiler.prototype.processExport = function(match) { | ||
var ex, exports, _i, _len, _ref, _results; | ||
exports = match[1]; | ||
if (exports[0] === '{' && exports[exports.length - 1] === '}') { | ||
exports = exports.slice(1, -1); | ||
} | ||
_ref = exports.split(/\s*,\s*/); | ||
var ex, _i, _len, _ref, _results; | ||
_ref = getNames(match[1]); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
ex = _ref[_i]; | ||
ex = ex.trim(); | ||
_results.push(this.exports[ex] = ex); | ||
@@ -150,25 +165,46 @@ } | ||
Compiler.prototype.processImportAs = function(match) { | ||
return this.importAs[match[1] || match[2]] = match[3]; | ||
}; | ||
Compiler.prototype.processImport = function(match) { | ||
var importNames, name, pattern; | ||
var asMatch, importSpecifiers, imports, name, pattern, _i, _len; | ||
pattern = match[1]; | ||
if (pattern[0] === '{' && pattern[pattern.length - 1] === '}') { | ||
pattern = pattern.slice(1, -1); | ||
importSpecifiers = (function() { | ||
var _i, _len, _ref, _results; | ||
_ref = pattern.split(/\s*,\s*/); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
name = _ref[_i]; | ||
_results.push(name.trim()); | ||
} | ||
return _results; | ||
})(); | ||
imports = {}; | ||
for (_i = 0, _len = importSpecifiers.length; _i < _len; _i++) { | ||
name = importSpecifiers[_i]; | ||
if (asMatch = name.match(IMPORT_AS)) { | ||
imports[asMatch[1]] = asMatch[2]; | ||
} else { | ||
imports[name] = name; | ||
} | ||
} | ||
return this.imports[match[2] || match[3]] = imports; | ||
} else { | ||
return this.importDefault[match[2] || match[3]] = match[1]; | ||
} | ||
importNames = (function() { | ||
var _i, _len, _ref, _results; | ||
_ref = pattern.split(/\s*,\s*/); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
name = _ref[_i]; | ||
_results.push(name.trim()); | ||
} | ||
return _results; | ||
})(); | ||
return this.imports[match[2] || match[3]] = importNames; | ||
}; | ||
Compiler.prototype.processReexport = function(match) { | ||
var importLocal, importPath, name, names, _i, _len, _results; | ||
names = getNames(match[1]); | ||
importPath = match[2] || match[3]; | ||
importLocal = this.reExportUnique.next(); | ||
this.importDefault[importPath] = importLocal; | ||
_results = []; | ||
for (_i = 0, _len = names.length; _i < _len; _i++) { | ||
name = names[_i]; | ||
_results.push(this.exports[name] = "" + importLocal + "." + name); | ||
} | ||
return _results; | ||
}; | ||
Compiler.prototype.processLine = function(line) { | ||
@@ -175,0 +211,0 @@ return this.lines.push(line); |
@@ -23,9 +23,9 @@ (function() { | ||
return this.build(function(s) { | ||
var args, globalImport, import_, into, locals, name, passedArgs, receivedArgs, wrapper, _i, _j, _len, _len1, _ref, _ref1; | ||
var alias, args, globalImport, into, locals, name, passedArgs, receivedArgs, wrapper, _i, _len, _ref, _ref1; | ||
passedArgs = []; | ||
receivedArgs = []; | ||
locals = {}; | ||
into = _this.options.into || _this.exportAs; | ||
if (!isEmpty(_this.exports) || _this.exportAs) { | ||
passedArgs.push(_this.exportAs ? s.global : into ? "" + s.global + "." + into + " = {}" : s.global); | ||
into = _this.options.into || _this.exportDefault; | ||
if (!isEmpty(_this.exports) || _this.exportDefault) { | ||
passedArgs.push(_this.exportDefault ? s.global : into ? "" + s.global + "." + into + " = {}" : s.global); | ||
receivedArgs.push('exports'); | ||
@@ -38,10 +38,11 @@ } | ||
passedArgs.push("" + s.global + "." + globalImport); | ||
if (name in _this.importAs) { | ||
receivedArgs.push(_this.importAs[name]); | ||
if (name in _this.importDefault) { | ||
receivedArgs.push(_this.importDefault[name]); | ||
} else { | ||
receivedArgs.push(globalImport); | ||
_ref1 = _this.imports[name]; | ||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { | ||
import_ = _ref1[_j]; | ||
locals[import_] = "" + globalImport + "." + import_; | ||
for (name in _ref1) { | ||
if (!__hasProp.call(_ref1, name)) continue; | ||
alias = _ref1[name]; | ||
locals[alias] = "" + globalImport + "." + name; | ||
} | ||
@@ -60,4 +61,4 @@ } | ||
s.append.apply(s, _this.lines); | ||
if (_this.exportAs) { | ||
return s.set("exports." + into, _this.exportAs); | ||
if (_this.exportDefault) { | ||
return s.set("exports." + into, _this.exportDefault); | ||
} else { | ||
@@ -75,6 +76,6 @@ _ref2 = _this.exports; | ||
args = function(arg) { | ||
var passedArg, _k, _len2, _results; | ||
var passedArg, _j, _len1, _results; | ||
_results = []; | ||
for (_k = 0, _len2 = passedArgs.length; _k < _len2; _k++) { | ||
passedArg = passedArgs[_k]; | ||
for (_j = 0, _len1 = passedArgs.length; _j < _len1; _j++) { | ||
passedArg = passedArgs[_j]; | ||
_results.push(arg(passedArg)); | ||
@@ -81,0 +82,0 @@ } |
@@ -7,2 +7,4 @@ (function() { | ||
Unique = require("./utils").Unique; | ||
INDENT = { | ||
@@ -192,19 +194,4 @@ indent: true | ||
Unique = (function() { | ||
function Unique(prefix) { | ||
this.prefix = prefix; | ||
this.index = 1; | ||
} | ||
Unique.prototype.next = function() { | ||
return "__" + this.prefix + (this.index++) + "__"; | ||
}; | ||
return Unique; | ||
})(); | ||
module.exports = ScriptBuilder; | ||
}).call(this); |
(function() { | ||
"use strict"; | ||
var isEmpty; | ||
var Unique, isEmpty; | ||
@@ -14,4 +14,21 @@ isEmpty = function(object) { | ||
Unique = (function() { | ||
function Unique(prefix) { | ||
this.prefix = prefix; | ||
this.index = 1; | ||
} | ||
Unique.prototype.next = function() { | ||
return "__" + this.prefix + (this.index++) + "__"; | ||
}; | ||
return Unique; | ||
})(); | ||
exports.isEmpty = isEmpty; | ||
exports.Unique = Unique; | ||
}).call(this); |
{ | ||
"name": "es6-module-transpiler", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "es6-module-transpiler is an experimental compiler that allows you to write your JavaScript or CoffeeScript using a subset of the current ES6 module syntax, and compile it into AMD, CommonJS, and globals styles.", | ||
@@ -31,7 +31,6 @@ "homepage": "http://square.github.com/es6-module-transpiler", | ||
"scripts": { | ||
"test": "grunt && jasmine-node --coffee spec", | ||
"package": "npm run-script test && gluejs --basepath lib --include . --exclude 'require_support' --out ../dist/es6-module-transpiler.js --global ModuleTranspiler && uglifyjs dist/es6-module-transpiler.js > dist/es6-module-transpiler.min.js" | ||
"test": "grunt" | ||
}, | ||
"devDependencies": { | ||
"gluejs": "~0.2.0", | ||
"gluejs": "~0.2.2", | ||
"uglify-js": "~2.2.4", | ||
@@ -41,4 +40,6 @@ "grunt": "~0.4.1", | ||
"jasmine-node": "~1.8.0", | ||
"grunt-jasmine-node": "~0.1.0" | ||
"grunt-jasmine-node": "~0.1.0", | ||
"grunt-contrib-uglify": "~0.2.2", | ||
"grunt-contrib-gluejs": "0.0.3" | ||
} | ||
} |
@@ -18,2 +18,4 @@ # ES6 Module Transpiler | ||
See the [CHANGELOG](./CHANGELOG.md) for the latest updates. | ||
## Usage | ||
@@ -152,3 +154,3 @@ | ||
export = jQuery; | ||
export default jQuery; | ||
``` | ||
@@ -165,6 +167,6 @@ | ||
To import a module that set its export using `export =`, you use this syntax: | ||
To import a module that set its export using `export default`, you use this syntax: | ||
```javascript | ||
import "jquery" as jQuery; | ||
import jQuery from "jquery"; | ||
``` | ||
@@ -228,3 +230,3 @@ | ||
export = jQuery; | ||
export default jQuery; | ||
``` | ||
@@ -274,3 +276,3 @@ | ||
```javascript | ||
import "jquery" as jQuery; | ||
import jQuery from "jquery"; | ||
``` | ||
@@ -297,3 +299,3 @@ | ||
// mymodule.js | ||
import "jquery" as jQuery; | ||
import jQuery from "jquery"; | ||
export jQuery; | ||
@@ -310,3 +312,6 @@ | ||
You can install the [grunt-es6-module-transpiler](http://github.com/joefiorini/grunt-es6-module-transpiler) plugin to run the transpiler as part of your [Grunt.js](http://gruntjs.com) build task. See the README on the plugin's Github page for more information. | ||
You can install the | ||
[grunt-es6-module-transpiler](http://github.com/joefiorini/grunt-es6-module-transpiler) | ||
plugin to run the transpiler as part of your [Grunt.js](http://gruntjs.com) | ||
build task. See the README on the plugin's Github page for more information. | ||
@@ -313,0 +318,0 @@ ## Installation |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
161230
45
2103
2
350
8