mirror of
https://github.com/hi-language/transpiler.git
synced 2026-01-14 16:48:39 +00:00
Refactor: Use ES Module import in browser app
This commit is contained in:
31
browser/app.js
Normal file
31
browser/app.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { hi2js } from '../transpiler.js';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const hiInput = document.getElementById('hi-input');
|
||||
const jsOutput = document.getElementById('js-output');
|
||||
|
||||
const transpile = () => {
|
||||
const hiCode = hiInput.value;
|
||||
try {
|
||||
const jsCode = hi2js(hiCode);
|
||||
jsOutput.value = jsCode;
|
||||
jsOutput.style.color = '#333';
|
||||
} catch (e) {
|
||||
jsOutput.value = `Error: ${e.message}`;
|
||||
jsOutput.style.color = 'red';
|
||||
}
|
||||
};
|
||||
|
||||
hiInput.addEventListener('input', transpile);
|
||||
|
||||
hiInput.value = `// Welcome, Master.
|
||||
message: "Hello from the browser!"
|
||||
_(message)
|
||||
|
||||
// Try changing the value
|
||||
count: 10
|
||||
count = count + 5
|
||||
_("The new count is", count)
|
||||
`;
|
||||
transpile();
|
||||
});
|
||||
Reference in New Issue
Block a user