Skip to content

Commit

Permalink
feat(evasive-transform): Preserve format with Babel
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Sep 3, 2024
1 parent a0aa5ec commit 1fef37d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 12 additions & 6 deletions packages/evasive-transform/src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ export const generate =
// TODO Use options?.sourceUrl when resolved:
// https://github.com/Agoric/agoric-sdk/issues/8671
const sourceUrl = options ? options.sourceUrl : undefined;
const result = generator(ast, {
sourceFileName: sourceUrl,
sourceMaps: Boolean(sourceUrl),
retainLines: true,
compact: true,
});
const source = options ? options.source : undefined;
const result = generator(
ast,
{
sourceFileName: sourceUrl,
sourceMaps: Boolean(sourceUrl),
retainLines: true,
preserveFormat: true,
compact: true,
},
source,
);

if (sourceUrl) {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/evasive-transform/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function evadeCensorSync(source, options) {
if (sourceUrl) {
return generate(ast, { sourceUrl });
}
return generate(ast);
return generate(ast, { source });
}

/**
Expand Down
8 changes: 6 additions & 2 deletions packages/evasive-transform/src/parse-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const { parse: parseBabel } = babelParser;
* @param {ParseAstOptions} [opts] - Options for underlying parser
* @internal
*/
export function parseAst(source, opts) {
export function parseAst(source, opts = {}) {
// Might not want to pass `opts` verbatim, but also might not matter!
return parseBabel(source, opts);
return parseBabel(source, {
tokens: true,
createParenthesizedExpression: true,
...opts,
});
}

0 comments on commit 1fef37d

Please sign in to comment.