How to use escodegen

Comprehensive escodegen code examples:

How to use escodegen.attachComments:

151
152
153
154
155
156
157
158
159
160
// Return a beautified representation of the code (cleaning up indentation, etc.)
beautify(rawCode, aether) {
  let ast;
  try {
    ast = esprima.parse(rawCode, {range: true, tokens: true, comment: true, tolerant: true});
    ast = escodegen.attachComments(ast, ast.comments, ast.tokens);
  } catch (e) {
    console.log('got error beautifying', e);
    ast = acorn_loose.parse_dammit(rawCode, {tabSize: 4, ecmaVersion: 5});
  }

How to use escodegen.generate:

157
158
159
160
161
162
163
164
165
166
						});
				}
			}
		},
	});
	return changed ? escodegen.generate(program) : content;
}

// utility to lookup unique XML dependencies
// eslint-disable-next-line jsdoc/require-jsdoc