[babel 8] Remove the jsonCompatibleStrings option (#12477)

Co-authored-by: Tan Li Hau <tanhauhau@users.noreply.github.com>
This commit is contained in:
Nicolò Ribaudo 2020-12-10 18:14:13 +01:00 committed by GitHub
parent 4f3fcf1110
commit e8176de528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 7 deletions

View File

@ -204,11 +204,16 @@ export function StringLiteral(node: Object) {
}
// ensure the output is ASCII-safe
const opts = this.format.jsescOption;
if (this.format.jsonCompatibleStrings) {
opts.json = true;
}
const val = jsesc(node.value, opts);
const val = jsesc(
node.value,
process.env.BABEL_8_BREAKING
? this.format.jsescOption
: Object.assign(
this.format.jsescOption,
this.format.jsonCompatibleStrings && { json: true },
),
);
return this.token(val);
}

View File

@ -46,7 +46,6 @@ function normalizeOptions(code, opts): Format {
compact: opts.compact,
minified: opts.minified,
concise: opts.concise,
jsonCompatibleStrings: opts.jsonCompatibleStrings,
indent: {
adjustMultilineComment: true,
style: " ",
@ -61,6 +60,10 @@ function normalizeOptions(code, opts): Format {
recordAndTupleSyntaxType: opts.recordAndTupleSyntaxType,
};
if (!process.env.BABEL_8_BREAKING) {
format.jsonCompatibleStrings = opts.jsonCompatibleStrings;
}
if (format.minified) {
format.compact = true;

View File

@ -0,0 +1,2 @@
0; // Not a directive
"©";

View File

@ -0,0 +1,5 @@
{
"BABEL_8_BREAKING": false,
"minified": true,
"jsonCompatibleStrings": true
}

View File

@ -0,0 +1,2 @@
0;// Not a directive
"\u00A9";

View File

@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": true,
"minified": true,
"jsonCompatibleStrings": true
"jsescOption": { "json": true }
}