mirror of
https://github.com/quinton-ashley/java2js
synced 2024-12-29 10:11:54 +01:00
1.2.9
This commit is contained in:
parent
d1dbf3b6f2
commit
bafdc47b1d
98
jdk.js
98
jdk.js
@ -221,8 +221,24 @@
|
||||
|
||||
let packageName = (file.match(/package\s+([^;]+)/gm) || [])[1] || 'default';
|
||||
|
||||
let trans = await java_to_javascript(file);
|
||||
let trans;
|
||||
|
||||
let workerPath = this.root.split('/').slice(0, -1).join('/') + '/transpile_worker.js';
|
||||
try {
|
||||
let worker = new Worker(workerPath);
|
||||
worker.postMessage(file);
|
||||
await new Promise((resolve, reject) => {
|
||||
worker.onmessage = (e) => {
|
||||
trans = e.data;
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
} catch (ror) {
|
||||
console.warn(
|
||||
'Due to a likely CORS error, java2js was unable to transpile with multithreaded worker: ' + workerPath
|
||||
);
|
||||
trans = java_to_javascript(file);
|
||||
}
|
||||
// log(trans);
|
||||
|
||||
// TODO fix this by adding real support for lambda
|
||||
@ -19572,59 +19588,55 @@
|
||||
* @return {string} - Converted JavaScript
|
||||
*/
|
||||
const javaToJavascript = (javaString, options = {}, progress) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof javaString !== 'string') {
|
||||
reject('java-to-javascript: First argument must be a string');
|
||||
}
|
||||
if (typeof javaString !== 'string') {
|
||||
throw 'java-to-javascript: First argument must be a string';
|
||||
}
|
||||
|
||||
// Reset opts parameters
|
||||
Object.assign(opts, DEFAULT_OPTIONS);
|
||||
// Reset opts parameters
|
||||
Object.assign(opts, DEFAULT_OPTIONS);
|
||||
|
||||
if (options.globalVars) opts.globalVars = options.globalVars;
|
||||
if (options.globalScope) opts.globalScope = options.globalScope;
|
||||
if (options.ugly) opts.separator = '';
|
||||
if (options.p5) {
|
||||
Object.assign(opts.globalVars, p5_options.globalVars, opts.globalVars);
|
||||
if (!opts.globalScope) opts.globalScope = 'p5';
|
||||
}
|
||||
if (options.globalVars) opts.globalVars = options.globalVars;
|
||||
if (options.globalScope) opts.globalScope = options.globalScope;
|
||||
if (options.ugly) opts.separator = '';
|
||||
if (options.p5) {
|
||||
Object.assign(opts.globalVars, p5_options.globalVars, opts.globalVars);
|
||||
if (!opts.globalScope) opts.globalScope = 'p5';
|
||||
}
|
||||
|
||||
if (progress) progress(0, 'Parsing Java');
|
||||
if (progress) progress(0, 'Parsing Java');
|
||||
|
||||
if (options.p5) javaString = `class JavaJsTemp__ {${fixP5(javaString)}}`;
|
||||
if (options.p5) javaString = `class JavaJsTemp__ {${fixP5(javaString)}}`;
|
||||
|
||||
let javaAST$$1;
|
||||
try {
|
||||
javaAST$$1 = javaAST.parse(javaString);
|
||||
} catch (e) {
|
||||
let line = e.location.start.line;
|
||||
if (e.location) reject(`on line ${line}: \n\n${javaString.split('\n')[line - 1].trim()}\n\n${e.stack}`);
|
||||
else reject(e);
|
||||
}
|
||||
let javaAST$$1;
|
||||
try {
|
||||
javaAST$$1 = javaAST.parse(javaString);
|
||||
} catch (e) {
|
||||
let line = e.location.start.line;
|
||||
if (e.location) throw `on line ${line}: \n\n${javaString.split('\n')[line - 1].trim()}\n\n${e.stack}`;
|
||||
else throw e;
|
||||
}
|
||||
|
||||
if (progress) progress(0.5, 'Converting to JavaScript');
|
||||
if (progress) progress(0.5, 'Converting to JavaScript');
|
||||
|
||||
let jsString;
|
||||
if (options.p5) {
|
||||
jsString = globalsToJs(parseClass(javaAST$$1.types[0], true));
|
||||
} else {
|
||||
jsString = javaAST$$1.types
|
||||
.map((globalClass) => classToJs(parseClass(globalClass)))
|
||||
.join(opts.separator);
|
||||
}
|
||||
let jsString;
|
||||
if (options.p5) {
|
||||
jsString = globalsToJs(parseClass(javaAST$$1.types[0], true));
|
||||
} else {
|
||||
jsString = javaAST$$1.types.map((globalClass) => classToJs(parseClass(globalClass))).join(opts.separator);
|
||||
}
|
||||
|
||||
if (progress) progress(0.75, 'Beautifying');
|
||||
if (progress) progress(0.75, 'Beautifying');
|
||||
|
||||
if (!options.ugly) {
|
||||
jsString =
|
||||
beautify$2(jsString, {
|
||||
indent_size: 2
|
||||
}) + '\n';
|
||||
}
|
||||
if (!options.ugly) {
|
||||
jsString =
|
||||
beautify$2(jsString, {
|
||||
indent_size: 2
|
||||
}) + '\n';
|
||||
}
|
||||
|
||||
if (progress) progress(1.0, 'Success');
|
||||
if (progress) progress(1.0, 'Success');
|
||||
|
||||
resolve(jsString);
|
||||
});
|
||||
return jsString;
|
||||
};
|
||||
|
||||
var lib = javaToJavascript;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "java2js",
|
||||
"version": "1.2.8",
|
||||
"version": "1.2.9",
|
||||
"description": "Converts Java to JavaScript and runs it with a JS JDK",
|
||||
"main": "jdk.js",
|
||||
"scripts": {
|
||||
|
19404
transpile_worker.js
Normal file
19404
transpile_worker.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user