MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / runOnJsText

Function runOnJsText

tools/unsafe_optimizations.mjs:209–231  ·  view source on GitHub ↗
(js, pretty = false)

Source from the content-addressed store, hash-verified

207}
208
209function runOnJsText(js, pretty = false) {
210 const ast = acorn.parse(js, {ecmaVersion: 2021});
211
212 optPassRemoveRedundantOperatorNews(ast);
213
214 let progress = true;
215 while (progress) {
216 progress = optPassMergeVarDeclarations(ast);
217 progress = progress || optPassMergeVarInitializationAssignments(ast);
218 progress = progress || optPassMergeEmptyVarDeclarators(ast);
219 }
220
221 optPassSimplifyModularizeFunction(ast);
222
223 const terserAst = terser.AST_Node.from_mozilla_ast(ast);
224 const output = terserAst.print_to_string({
225 wrap_func_args: false,
226 beautify: pretty,
227 indent_level: pretty ? 2 : 0,
228 });
229
230 return output;
231}
232
233function runOnFile(input, pretty = false, output = null) {
234 let js = fs.readFileSync(input).toString();

Callers 2

runOnFileFunction · 0.85
testFunction · 0.85

Tested by 1

testFunction · 0.68