mirror of
https://github.com/ritz078/transform.git
synced 2026-11-21 00:32:56 +03:00
moved prettier to worker
This commit is contained in:
1 parent
b0eecc6483
commit
abf42b23b0
1 file changed
+36
@@ -0,0 +1,36 @@
|
||||
try {
|
||||
importScripts('https://bundle.run/prettier@1.6.1')
|
||||
} catch (e) {
|
||||
self.postMessage({ available: false })
|
||||
}
|
||||
|
||||
const prettierParsers = {
|
||||
css: "postcss",
|
||||
javascript: "babylon",
|
||||
jsx: "babylon",
|
||||
graphql: "graphql",
|
||||
json: "json",
|
||||
typescript: "typescript",
|
||||
flow: "flow"
|
||||
};
|
||||
|
||||
if (self.prettier) {
|
||||
postMessage({ available: true })
|
||||
}
|
||||
|
||||
onmessage = function ({ data }) {
|
||||
const {code, mode, section } = data
|
||||
|
||||
const prettyCode = self.prettier &&
|
||||
prettierParsers[mode] &&
|
||||
code ? (
|
||||
self.prettier.format(code, {
|
||||
parser: prettierParsers[mode],
|
||||
printWidth: 70
|
||||
})
|
||||
) : (
|
||||
code
|
||||
)
|
||||
|
||||
postMessage({ available: !!self.prettier, prettyCode, section })
|
||||
}
|
||||
Reference in new issue
Block a user