Skip to content

Commit

Permalink
[babel 8] Remove the jsonCompatibleStrings option (#12477)
Browse files Browse the repository at this point in the history
Co-authored-by: Tan Li Hau <tanhauhau@users.noreply.github.com>
  • Loading branch information
nicolo-ribaudo and tanhauhau committed Dec 10, 2020
1 parent 4f3fcf1 commit e8176de
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
15 changes: 10 additions & 5 deletions packages/babel-generator/src/generators/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/babel-generator/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: " ",
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0; // Not a directive
"漏";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"BABEL_8_BREAKING": false,
"minified": true,
"jsonCompatibleStrings": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0;// Not a directive
"\u00A9";
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"BABEL_8_BREAKING": true,
"minified": true,
"jsonCompatibleStrings": true
"jsescOption": { "json": true }
}

0 comments on commit e8176de

Please sign in to comment.