[babel 8] Remove the jsonCompatibleStrings option (#12477)
Co-authored-by: Tan Li Hau <tanhauhau@users.noreply.github.com>
This commit is contained in:
parent
4f3fcf1110
commit
e8176de528
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
2
packages/babel-generator/test/fixtures/escapes/jsonEscape-babel-7/input.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/escapes/jsonEscape-babel-7/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
0; // Not a directive
|
||||
"©";
|
||||
5
packages/babel-generator/test/fixtures/escapes/jsonEscape-babel-7/options.json
vendored
Normal file
5
packages/babel-generator/test/fixtures/escapes/jsonEscape-babel-7/options.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": false,
|
||||
"minified": true,
|
||||
"jsonCompatibleStrings": true
|
||||
}
|
||||
2
packages/babel-generator/test/fixtures/escapes/jsonEscape-babel-7/output.js
vendored
Normal file
2
packages/babel-generator/test/fixtures/escapes/jsonEscape-babel-7/output.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
0;// Not a directive
|
||||
"\u00A9";
|
||||
@ -1,4 +1,5 @@
|
||||
{
|
||||
"BABEL_8_BREAKING": true,
|
||||
"minified": true,
|
||||
"jsonCompatibleStrings": true
|
||||
"jsescOption": { "json": true }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user