forked from dabbott/javascript-playgrounds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel-worker.js
More file actions
34 lines (29 loc) · 766 Bytes
/
babel-worker.js
File metadata and controls
34 lines (29 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Babel = require('babel-core')
// Ensure consistency with react-native's babel plugins by directly using
// the babel-preset-react-native. It's intended for usage in node, so we
// have to require it slightly differently to get it to work in the browser.
import plugins from './utils/BabelPlugins'
onmessage = function(event) {
const {code: value, filename, options} = event.data
let output
try {
const code = Babel.transform(value, {
plugins,
...options,
}).code
output = {
filename,
type: 'code',
code,
}
} catch (e) {
output = {
filename,
type: 'error',
error: {
message: e.message.replace('unknown', e.name),
},
}
}
postMessage(JSON.stringify(output))
}