3
/*jslint strict: false, plusplus: false */
4
/*global define: false, require: false, XMLHttpRequest: false, ActiveXObject: false,
5
window: false, Packages: false, java: false, process: false */
8
//Load the text plugin, so that the XHR calls can be made.
9
var buildMap = {}, fetchText, fs,
10
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
12
function createXhr() {
13
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
15
if (typeof XMLHttpRequest !== "undefined") {
16
return new XMLHttpRequest();
18
for (i = 0; i < 3; i++) {
21
xhr = new ActiveXObject(progId);
25
progIds = [progId]; // so faster next time
32
throw new Error("require.getXhr(): XMLHttpRequest not available");
38
if (typeof window !== "undefined" && window.navigator && window.document) {
39
fetchText = function (url, callback) {
40
var xhr = createXhr();
41
xhr.open('GET', url, true);
42
xhr.onreadystatechange = function (evt) {
43
//Do not explicitly handle errors, those should be
44
//visible via console output in the browser.
45
if (xhr.readyState === 4) {
46
callback(xhr.responseText);
51
} else if (typeof process !== "undefined" &&
53
!!process.versions.node) {
54
//Using special require.nodeRequire, something added by r.js.
55
fs = require.nodeRequire('fs');
57
fetchText = function (url, callback) {
58
callback(fs.readFileSync(url, 'utf8'));
60
} else if (typeof Packages !== 'undefined') {
61
//Why Java, why is this so awkward?
62
fetchText = function (url, callback) {
63
var encoding = "utf-8",
64
file = new java.io.File(url),
65
lineSeparator = java.lang.System.getProperty("line.separator"),
66
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
70
stringBuffer = new java.lang.StringBuffer();
71
line = input.readLine();
73
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
74
// http://www.unicode.org/faq/utf_bom.html
76
// 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:
77
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
78
if (line && line.length() && line.charAt(0) === 0xfeff) {
79
// Eat the BOM, since we've already found the encoding on this file,
80
// and we plan to concatenating this buffer with others; the BOM should
81
// only appear at the top of a file.
82
line = line.substring(1);
85
stringBuffer.append(line);
87
while ((line = input.readLine()) !== null) {
88
stringBuffer.append(lineSeparator);
89
stringBuffer.append(line);
91
//Make sure we return a JavaScript string and not a Java string.
92
content = String(stringBuffer.toString()); //String
100
define('refine',[],function () {
102
load: function (name, parentRequire, load, config) {
103
var url = parentRequire.toUrl(name + '.refine');
104
fetchText(url, function (text) {
105
text = text.replace(/refine\s*\(/g, 'define(');
107
if (config.isBuild) {
108
buildMap[name] = text;
111
//Add in helpful debug line
112
text += "\r\n//@ sourceURL=" + url;
116
parentRequire([name], function (value) {
122
write: function (pluginName, name, write) {
123
if (name in buildMap) {
124
var text = buildMap[name];
125
write.asModule(pluginName + "!" + name, text);
133
define('refine!c',['refine!a', 'exports'], function (a, exports) {
138
define('refine!b',['refine!c', 'exports'], function (c, exports) {
143
define('refine!a',['refine!b', 'exports'], function (b, exports) {
148
define('refine!e',['refine!d'], function(d) {
150
return e.name + require('refine!d').name;
157
define('refine!d',['refine!e'], function(e) {
159
return require('refine!e')();
167
baseUrl: requirejs.isBrowser ? './' : './circular/transpiler',
169
'text': '../../../../text/text',
170
'refine': '../../plugins/fromText/refine'
173
["require", "refine!a", "refine!b", "refine!d"],
174
function(require, a, b, d) {
176
"circularTranspiler",
178
function circularTranspiler(t) {
181
t.is("c", a.b.c.name);
192
define("transpiler-tests", function(){});