3.0 source code

This commit is contained in:
agolybev
2015-04-28 17:59:00 +03:00
parent c69fd34bdd
commit 7b3b2248e5
16311 changed files with 1445974 additions and 3108429 deletions

View File

@@ -0,0 +1,6 @@
//Note the use of window instead of var a = {},
//since the var will be created in the scope of the eval call,
//which is not global.
window.a = {
name: 'a'
};

View File

@@ -0,0 +1,18 @@
require({
baseUrl: requirejs.isBrowser ? './' : './plugins/fromText',
paths: {
'text': '../../../../text/text'
}
}, ['refine!a'],
function () {
doh.register(
'pluginsFromTextNoDefine',
[
function pluginsFromTextNoDefine(t){
t.is('a', a.name);
}
]
);
doh.run();
});

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: fromText Plugin No Define Test</title>
<script type="text/javascript" src="../../doh/runner.js"></script>
<script type="text/javascript" src="../../doh/_browserRunner.js"></script>
<script type="text/javascript" data-main="fromTextNoDefine-tests.js" src="../../../require.js"></script>
</head>
<body>
<h1>require.js: fromText Plugin No Define Test</h1>
<p>Tests that a plugin that transpiles to JS but does not call
define still works. More info:
<a href="https://github.com/jrburke/requirejs/issues/313">313</a>.
<p>Check console for messages</p>
</body>
</html>

View File

@@ -0,0 +1,130 @@
/*jslint strict: false, plusplus: false */
/*global define: false, require: false, XMLHttpRequest: false, ActiveXObject: false,
window: false, Packages: false, java: false, process: false */
(function () {
//Load the text plugin, so that the XHR calls can be made.
var buildMap = {}, fetchText, fs,
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
function createXhr() {
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
var xhr, i, progId;
if (typeof XMLHttpRequest !== "undefined") {
return new XMLHttpRequest();
} else {
for (i = 0; i < 3; i++) {
progId = progIds[i];
try {
xhr = new ActiveXObject(progId);
} catch (e) {}
if (xhr) {
progIds = [progId]; // so faster next time
break;
}
}
}
if (!xhr) {
throw new Error("require.getXhr(): XMLHttpRequest not available");
}
return xhr;
}
if (typeof window !== "undefined" && window.navigator && window.document) {
fetchText = function (url, callback) {
var xhr = createXhr();
xhr.open('GET', url, true);
xhr.onreadystatechange = function (evt) {
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
if (xhr.readyState === 4) {
callback(xhr.responseText);
}
};
xhr.send(null);
};
} else if (typeof process !== "undefined" &&
process.versions &&
!!process.versions.node) {
//Using special require.nodeRequire, something added by r.js.
fs = require.nodeRequire('fs');
fetchText = function (url, callback) {
callback(fs.readFileSync(url, 'utf8'));
};
} else if (typeof Packages !== 'undefined') {
//Why Java, why is this so awkward?
fetchText = function (url, callback) {
var encoding = "utf-8",
file = new java.io.File(url),
lineSeparator = java.lang.System.getProperty("line.separator"),
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
stringBuffer, line,
content = '';
try {
stringBuffer = new java.lang.StringBuffer();
line = input.readLine();
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
// http://www.unicode.org/faq/utf_bom.html
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
if (line && line.length() && line.charAt(0) === 0xfeff) {
// Eat the BOM, since we've already found the encoding on this file,
// and we plan to concatenating this buffer with others; the BOM should
// only appear at the top of a file.
line = line.substring(1);
}
stringBuffer.append(line);
while ((line = input.readLine()) !== null) {
stringBuffer.append(lineSeparator);
stringBuffer.append(line);
}
//Make sure we return a JavaScript string and not a Java string.
content = String(stringBuffer.toString()); //String
} finally {
input.close();
}
callback(content);
};
}
define(function () {
return {
load: function (name, parentRequire, load, config) {
var url = parentRequire.toUrl(name + '.refine');
fetchText(url, function (text) {
text = text.replace(/refine/g, 'define');
if (config.isBuild) {
buildMap[name] = text;
}
//Add in helpful debug line
text += "\r\n//@ sourceURL=" + url;
load.fromText(name, text);
parentRequire([name], function (value) {
load(value);
});
});
},
write: function (pluginName, name, write) {
if (name in buildMap) {
var text = buildMap[name];
write.asModule(pluginName + "!" + name, text);
}
}
};
});
}());