mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
[app] Add support ReasonML/Rescript #77
This commit is contained in:
parent
e693de128f
commit
424769d1d5
35
app.js
35
app.js
|
@ -211,7 +211,7 @@ function require(FN) {
|
|||
return pos < 0 ? '.' : FN.substr(pos);
|
||||
})(FN.lastIndexOf('.'));
|
||||
|
||||
if ('.js$.coffee$.ls$.ts$'.indexOf(suffix + '$') < 0) FN += ".js";
|
||||
if ('.js$.coffee$.ls$.ts$.re$'.indexOf(suffix + '$') < 0) FN += ".js";
|
||||
if (cache[FN]) return cache[FN];
|
||||
|
||||
// get file and directory name
|
||||
|
@ -219,10 +219,10 @@ function require(FN) {
|
|||
var __dirname__ = require.__getDirName__(__filename__);
|
||||
var T = require.__load__(FN);
|
||||
|
||||
// pre-compile if use Transpiler
|
||||
// transpile
|
||||
switch (suffix) {
|
||||
case '.coffee': // CoffeeScript 2
|
||||
T = require.__msie9__("app/assets/js/coffeescript-legacy-2.7.0.min", [T], function(p, w, d) {
|
||||
T = require.__msie9__("app/assets/js/coffeescript-legacy-2.7.0.min", [T], function(p, w, d, l) {
|
||||
return w.CoffeeScript.compile(p[0], {
|
||||
"header": true,
|
||||
"sourceMap": false,
|
||||
|
@ -232,7 +232,7 @@ function require(FN) {
|
|||
break;
|
||||
|
||||
case ".ls": // LiveScript
|
||||
T = require.__msie9__("app/assets/js/livescript-1.6.1.min", [T, "app/assets/ls/prelude.ls"], function(p, w, d) {
|
||||
T = require.__msie9__("app/assets/js/livescript-1.6.1.min", [T, "app/assets/ls/prelude.ls"], function(p, w, d, l) {
|
||||
return w.require("livescript").compile(require.__load__(p[1]) + "\n\n" + p[0], {
|
||||
"header": true,
|
||||
"bare": true
|
||||
|
@ -241,10 +241,18 @@ function require(FN) {
|
|||
break;
|
||||
|
||||
case ".ts": // TypeScript
|
||||
T = require.__modernie__("app/assets/js/typescript-4.9.4", [T], function(p, w, d) {
|
||||
T = require.__modernie__("app/assets/js/typescript-4.9.4", [T], function(p, w, d, l) {
|
||||
return w.ts.transpile(p[0]);
|
||||
});
|
||||
break;
|
||||
|
||||
case ".re": // Rescript (aka. BuckleScript, ReasonML)
|
||||
T = require.__modernie__("app/assets/js/rescript-compiler-10.1.2", [T], function(p, w, d, l) {
|
||||
var compiler = w.rescript_compiler.make();
|
||||
var result = compiler.rescript.compile(p[0]);
|
||||
return result.js_code;
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
// compile
|
||||
|
@ -294,6 +302,9 @@ require.__getCurrentScriptDirectory__ = function() {
|
|||
}
|
||||
};
|
||||
require.__load__ = function(FN) {
|
||||
// if empty
|
||||
if (FN == '') return '';
|
||||
|
||||
// get filename
|
||||
var __filename__ = require.__getCurrentScriptDirectory__() + "\\" + FN;
|
||||
|
||||
|
@ -315,7 +326,8 @@ require.__load__ = function(FN) {
|
|||
return T;
|
||||
};
|
||||
require.__msie9__ = function(FN, params, callback) {
|
||||
if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
|
||||
if (typeof FN !== "string" || FN == null) FN = '';
|
||||
else if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
|
||||
|
||||
var exports = null;
|
||||
try {
|
||||
|
@ -345,7 +357,8 @@ require.__msie9__ = function(FN, params, callback) {
|
|||
return exports;
|
||||
};
|
||||
require.__modernie__ = function(FN, params, callback) {
|
||||
if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
|
||||
if (typeof FN !== "string" || FN == null) FN = '';
|
||||
else if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
|
||||
|
||||
var exports = null;
|
||||
try {
|
||||
|
@ -369,11 +382,11 @@ require.__modernie__ = function(FN, params, callback) {
|
|||
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + T + '\n//]]>--></script>');
|
||||
|
||||
if (typeof callback === "function") {
|
||||
var loadScript = function(FN) {
|
||||
if (FN.indexOf('://') > -1) {
|
||||
htmlfile.write('<script type="text/javascript" src="' + FN + '"></script>');
|
||||
var loadScript = function(src) {
|
||||
if (src.indexOf('://') > -1) {
|
||||
htmlfile.write('<script type="text/javascript" src="' + src + '"></script>');
|
||||
} else {
|
||||
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + require.__load__(FN) + '\n//]]>--></script>');
|
||||
htmlfile.write('<script type="text/javascript">//<!--<![CDATA[\n' + require.__load__(src) + '\n//]]>--></script>');
|
||||
}
|
||||
};
|
||||
//console.log(htmlfile.parentWindow.navigator.userAgent);
|
||||
|
|
48981
app/assets/js/rescript-compiler-10.1.2.js
Normal file
48981
app/assets/js/rescript-compiler-10.1.2.js
Normal file
File diff suppressed because one or more lines are too long
5
helloworld.re
Normal file
5
helloworld.re
Normal file
|
@ -0,0 +1,5 @@
|
|||
let greet = (name) => "Hello " ++ name
|
||||
let add = (x, y, z) => x + y + z
|
||||
|
||||
Js.log(greet("world!")) // "Hello world!"
|
||||
Js.log(add(1, 2, 3)) // 6
|
Loading…
Reference in New Issue
Block a user