solive-solc
Version:
Solidity Contract Compiler Tool - Browser Supported
33 lines (31 loc) • 1.02 kB
JavaScript
import setupMethods from 'solc/wrapper';
globalThis.addEventListener('message', function (_ref) {
var data = _ref.data;
if (data === 'fetch-compiler-versions') {
fetch('https://binaries.soliditylang.org/bin/list.json').then(function (response) {
return response.json();
}).then(function (result) {
// @ts-ignore
globalThis.postMessage(result);
});
} else if (data.type === 'init-solc') {
globalThis.importScripts(data.version);
} else {
// version find in https://github.com/ethereum/solc-bin/tree/gh-pages/bin
var compiler = setupMethods(globalThis);
try {
var output = compiler.compile(data.input);
globalThis.postMessage({
output: JSON.parse(output),
input: data.input && JSON.parse(data.input)
});
} catch (exception) {
globalThis.postMessage({
output: {
error: "Uncaught JavaScript exception:\n".concat(exception)
},
input: data.input && JSON.parse(data.input)
});
}
}
});