Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improve jsonCompatibleStrings deprecation #15480

Merged
merged 2 commits into from Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions packages/babel-generator/src/generators/types.ts
Expand Up @@ -209,15 +209,7 @@ export function StringLiteral(this: Printer, node: t.StringLiteral) {
return;
}

const val = jsesc(
node.value,
process.env.BABEL_8_BREAKING
? this.format.jsescOption
: Object.assign(
this.format.jsescOption,
this.format.jsonCompatibleStrings && { json: true },
),
);
const val = jsesc(node.value, this.format.jsescOption);

return this.token(val);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-generator/src/index.ts
Expand Up @@ -78,6 +78,9 @@ function normalizeOptions(
if (!process.env.BABEL_8_BREAKING) {
format.decoratorsBeforeExport = opts.decoratorsBeforeExport;
format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
if (format.jsonCompatibleStrings) {
format.jsescOption.json = true;
}
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved
}

if (format.minified) {
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -64,6 +64,9 @@ export type Format = {
};
recordAndTupleSyntaxType: RecordAndTuplePluginOptions["syntaxType"];
jsescOption: jsescOptions;
/**
* @deprecated Removed in Babel 8, use `jsescOption` instead
*/
jsonCompatibleStrings?: boolean;
/**
* For use with the Hack-style pipe operator.
Expand Down