forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker-1.16.4.js
More file actions
188 lines (172 loc) · 5.33 KB
/
worker-1.16.4.js
File metadata and controls
188 lines (172 loc) · 5.33 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* eslint-env worker */
/* eslint no-var: off, vars-on-top: off, strict: off, no-use-before-define: off */
/* globals prettier prettierPlugins */
var imported = Object.create(null);
function importScriptOnce(url) {
if (!imported[url]) {
imported[url] = true;
importScripts(url);
}
}
// this is required to only load parsers when we need them
var parsers = {
// JS - Babel
get babel() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.babel;
},
get "babel-flow"() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers["babel-flow"];
},
// backward compatibility
get babylon() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.babylon;
},
get json() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.json;
},
get json5() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.json5;
},
get "json-stringify"() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers["json-stringify"];
},
get __js_expression() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.__js_expression;
},
get __vue_expression() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.__vue_expression;
},
get __vue_event_binding() {
importScriptOnce("/static/js/prettier/1.16.4/parser-babylon.js");
return prettierPlugins.babylon.parsers.__vue_event_binding;
},
// JS - Flow
get flow() {
importScriptOnce("/static/js/prettier/1.16.4/parser-flow.js");
return prettierPlugins.flow.parsers.flow;
},
// JS - TypeScript
get typescript() {
importScriptOnce("/static/js/prettier/1.16.4/parser-typescript.js");
return prettierPlugins.typescript.parsers.typescript;
},
// JS - Angular Action
get __ng_action() {
importScriptOnce("/static/js/prettier/1.16.4/parser-angular.js");
return prettierPlugins.angular.parsers.__ng_action;
},
// JS - Angular Binding
get __ng_binding() {
importScriptOnce("/static/js/prettier/1.16.4/parser-angular.js");
return prettierPlugins.angular.parsers.__ng_binding;
},
// JS - Angular Interpolation
get __ng_interpolation() {
importScriptOnce("/static/js/prettier/1.16.4/parser-angular.js");
return prettierPlugins.angular.parsers.__ng_interpolation;
},
// JS - Angular Directive
get __ng_directive() {
importScriptOnce("/static/js/prettier/1.16.4/parser-angular.js");
return prettierPlugins.angular.parsers.__ng_directive;
},
// CSS
get css() {
importScriptOnce("/static/js/prettier/1.16.4/parser-postcss.js");
return prettierPlugins.postcss.parsers.css;
},
get less() {
importScriptOnce("/static/js/prettier/1.16.4/parser-postcss.js");
return prettierPlugins.postcss.parsers.css;
},
get scss() {
importScriptOnce("/static/js/prettier/1.16.4/parser-postcss.js");
return prettierPlugins.postcss.parsers.css;
},
// GraphQL
get graphql() {
importScriptOnce("/static/js/prettier/1.16.4/parser-graphql.js");
return prettierPlugins.graphql.parsers.graphql;
},
// Markdown
get markdown() {
importScriptOnce("/static/js/prettier/1.16.4/parser-markdown.js");
return prettierPlugins.markdown.parsers.remark;
},
get mdx() {
importScriptOnce("/static/js/prettier/1.16.4/parser-markdown.js");
return prettierPlugins.markdown.parsers.mdx;
},
// YAML
get yaml() {
importScriptOnce("/static/js/prettier/1.16.4/parser-yaml.js");
return prettierPlugins.yaml.parsers.yaml;
},
// Handlebars
get glimmer() {
importScriptOnce("/static/js/prettier/1.16.4/parser-glimmer.js");
return prettierPlugins.glimmer.parsers.glimmer;
},
// HTML
get html() {
importScriptOnce("/static/js/prettier/1.16.4/parser-html.js");
return prettierPlugins.html.parsers.html;
},
// Vue
get vue() {
importScriptOnce("/static/js/prettier/1.16.4/parser-html.js");
return prettierPlugins.html.parsers.vue;
},
// Angular
get angular() {
importScriptOnce("/static/js/prettier/1.16.4/parser-html.js");
return prettierPlugins.html.parsers.angular;
},
// Lightning Web Components
get lwc() {
importScriptOnce("/static/js/prettier/1.16.4/parser-html.js");
return prettierPlugins.html.parsers.lwc;
}
};
importScripts("/static/js/prettier/1.16.4/standalone.js");
self.onmessage = function(event) {
const message = handleMessage(event.data);
self.postMessage({
uid: event.data.uid,
result: message,
text: event.data.text
});
};
function handleMessage(message) {
var options = message.options || {};
delete options.ast;
delete options.doc;
delete options.output2;
var plugins = [{ parsers }];
options.plugins = plugins;
var response = {
formatted: formatCode(message.text, options),
debug: {
ast: null,
doc: null,
reformatted: null
}
};
return response;
}
function formatCode(text, options) {
try {
return prettier.format(text, options);
} catch (e) {
self.postMessage({ error: e.message, text });
return undefined
}
}