Permalink
Browse files

Removed AMD loader

  • Loading branch information...
1 parent 501b363 commit 98dc76a0b696d7537f3fab2db8779a7678511d54 @xcambar committed Apr 16, 2012
View
@@ -1205,79 +1205,9 @@
},
name: "require"
};
- } else if (name === "amd") {
- var wrapperName = "define";
- return {
- name: wrapperName,
- fn: function wrapperFn(name, deps, factory) {
- var _n, _d, _f;
- switch (arguments.length) {
- case 1:
- _n = conf.name;
- _f = name;
- break;
- case 2:
- _d = name;
- _f = deps;
- break;
- default:
- _n = name;
- _d = deps;
- _f = factory;
- }
- if (_d) {
- var newDeps = {};
- for (var i = 0, _l = _d.length; i < _l; i++) {
- newDeps[_d[i]] = {
- format: "amd",
- ref: _d[i]
- };
- }
- _d = newDeps;
- }
- var modConf = {};
- _d && (modConf.import = _d);
- _n && (modConf.name = _n);
- _f && (modConf.fn = _f);
- modConf.src = conf.src;
- applyConfiguration(modConf, function applyCallback(parsedConf) {
- throw new Error("AMD not handled yet");
- loadModule(parsedConf);
- });
- }
- };
}
}
function parse(declaration, conf) {
- function pluginDeclaration(decl) {
- var plugins = decl.split(";"), pluginRe = /^\s*([a-zA-Z_$][0-9a-zA-Z_$]*)\!([a-zA-Z_$][0-9a-zA-Z_$]*)\s*$/;
- for (var i = 0; i < plugins.length; i++) {
- if (!plugins[i]) {
- continue;
- }
- var plugin = plugins[i], match = plugin.match(pluginRe);
- if (match) {
- var pluginName = match[1];
- argument = match[2];
- if (!_plugins[pluginName]) {
- return 'Unknown plugin "' + pluginName + '"';
- }
- var pluginResult = _plugins[pluginName](argument);
- if (is(pluginResult, "string") || !pluginResult) {
- return pluginResult;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- var moduleObj = conf || {}, isPlugin = pluginDeclaration(declaration);
- if (is(isPlugin, "string")) {
- return isPlugin;
- } else if (isPlugin) {
- return moduleObj;
- }
try {
var module = parser.parse(declaration);
return module;
@@ -1373,7 +1303,7 @@
me.s6d[extDepIndex] = function(exports) {
if (exports) {
delete me.s6d[extDepIndex];
- var _err = _registerModule(module, moduleConf._internals.src, moduleConf.name);
+ var _err = _registerModule(exports, moduleConf._internals.src, moduleConf.name);
if (_err) {
return _err;
}
@@ -1418,7 +1348,7 @@
return require(arg);
};
var returnStatement = moduleConf.exports ? moduleConf.exports.map(function(v) {
- return "returns." + v.dest + " = " + v.src;
+ return "returns." + v.dest + " = " + [ "exports." + v.src, "module.exports." + v.src, v.src ].join("||");
}).join(";\n") : "";
vm.runInNewContext(contents + ";\n" + returnStatement, context, moduleConf._internals.src + ".vm");
module = context.returns;
View
Oops, something went wrong.
View
@@ -1,4 +0,0 @@
-define(['dep.js'], function (dep) {
- console.log(arguments);
- console.log(dep);
-});
View
@@ -1,4 +0,0 @@
-define(function () {
- debugger
- return 'Yipeeeee!';
-})
View
@@ -1,22 +0,0 @@
-<!doctype html>
-<html>
- <head>
- <title>Loading AMD modules</title>
- <script type="text/javascript" src="/shepherd.js"></script>
- <script type="text/shepherd-js" data-src="/examples/AMD/main.js"></script>
-
- <style type="text/css">
- body {padding: 0;margin:0;}
- .info {border-bottom: 3px solid orange;background: #FFD39B;text-align: center;font-size: 1.05em;padding-top: 5px;}
- .info pre {font-size: 1.2em;border: 1px solid #999;background: #DDD;display: inline;padding: 3px 20px;}
- </style>
- </head>
- <body>
- <div class='info'>
- <b>Note</b>: This demo uses a modified version of Underscore.<br />
- The modification consists on a one-line addition of the following text (quotes included): <br /><br />
- <pre>"export this._;";</pre><br /><br />
- </div>
- <ul class='methods'></ul>
- </body>
-</html>
View
@@ -1,5 +0,0 @@
-"module { ";
-" amd!import _ from '/examples/AMD/AMD.js'; ";
-"}; ";
-
-console.log(_)
View
@@ -1,3 +1 @@
-var s6d = require('../../shepherd.js');
-
-s6d('bootstrap.js');
+require('../../build/shepherd.dev.js').call(this, 'bootstrap.js');
@@ -1,5 +1,8 @@
-"module { ";
-" module fs from util; ";
-" import _ from '../libs/underscore.min.js'; ";
-"} ";
-console.log(_);
+/*
+module nodeJSExample {
+ module fs is util;
+ import _ from '../libs/underscore.min.js';
+}
+*/
+
+console.log(_);
View
@@ -72,47 +72,6 @@
},
name: 'require'
};
- } else if (name === 'amd') {
- /**
- * Wraps the AMD's define function
- */
- var wrapperName = 'define';
- return {
- name: wrapperName,
- fn: function wrapperFn (name, deps, factory) {
- var _n, _d, _f;
- switch (arguments.length) {
- case 1:
- _n = conf.name;
- _f = name;
- break;
- case 2:
- _d = name;
- _f = deps;
- break;
- default:
- _n = name;
- _d = deps;
- _f = factory;
- }
- if (_d) {
- var newDeps = {};
- for (var i = 0, _l = _d.length; i < _l; i++) {
- newDeps[_d[i]] = {format: 'amd', ref: _d[i]};
- }
- _d = newDeps;
- }
- var modConf = {};
- _d && (modConf.import = _d);
- _n && (modConf.name = _n);
- _f && (modConf.fn = _f);
- modConf.src = conf.src;
- applyConfiguration(modConf, function applyCallback (parsedConf) {
- throw new Error('AMD not handled yet');
- loadModule(parsedConf);
- });
- }
- };
}
}
@@ -128,37 +87,6 @@
* @return {Object|String} Returns the module's evaluated execution context or an error string
*/
function parse (declaration, conf) {
- function pluginDeclaration (decl) {
- var plugins = decl.split(';'),
- pluginRe = /^\s*([a-zA-Z_$][0-9a-zA-Z_$]*)\!([a-zA-Z_$][0-9a-zA-Z_$]*)\s*$/;
- for(var i = 0; i < plugins.length; i++) {
- if (!plugins[i]) { continue; }
- var plugin = plugins[i],
- match = plugin.match(pluginRe);
- if (match) {
- var pluginName = match[1];
- argument = match[2];
- if (!_plugins[pluginName]) {
- return 'Unknown plugin "' + pluginName + '"';
- }
- var pluginResult = _plugins[pluginName](argument);
- if (is(pluginResult, 'string') || !pluginResult) {
- return pluginResult;
- }
- } else {
- return false;
- }
- }
- return true;
- }
- var moduleObj = conf || {},
- isPlugin = pluginDeclaration(declaration);
-
- if (is(isPlugin, 'string')) {
- return isPlugin;
- } else if (isPlugin) {
- return moduleObj;
- }
try {
var module = parser.parse(declaration);
return module;
@@ -272,7 +200,7 @@
me.s6d[extDepIndex] = function (exports) {
if (exports) {
delete me.s6d[extDepIndex];
- var _err = _registerModule(module, moduleConf._internals.src, moduleConf.name);
+ var _err = _registerModule(exports, moduleConf._internals.src, moduleConf.name);
if (_err) {
return _err;
}
@@ -315,7 +243,7 @@
}
return require(arg);
};
- var returnStatement = moduleConf.exports ? moduleConf.exports.map(function (v) {return 'returns.' + v.dest + ' = ' + v.src}).join(';\n') : '';
+ var returnStatement = moduleConf.exports ? moduleConf.exports.map(function (v) {return 'returns.' + v.dest + ' = ' + ['exports.' + v.src, 'module.exports.' + v.src, v.src].join('||')}).join(';\n') : '';
vm.runInNewContext(contents + ';\n' + returnStatement, context, moduleConf._internals.src + '.vm');
module = context.returns;

0 comments on commit 98dc76a

Please sign in to comment.