Skip to content

Commit

Permalink
Use process.env.BABEL_8_BREAKING flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 10, 2020
1 parent af624fd commit 54e783d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/babel-generator/src/generators/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,16 @@ export function StringLiteral(node: Object) {
}

// ensure the output is ASCII-safe
const opts = this.format.jsescOption;
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
4 changes: 4 additions & 0 deletions packages/babel-generator/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,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,
"jsescOption": { "json": true }
}

0 comments on commit 54e783d

Please sign in to comment.