Add jsonCompatibleStrings option to generator (#4827)

This commit is contained in:
Juriy Zaytsev 2016-11-15 12:03:41 -08:00 committed by Henry Zhu
parent 8475b6ec02
commit cf3a38fb40
5 changed files with 13 additions and 2 deletions

View File

@ -143,10 +143,14 @@ export function StringLiteral(node: Object, parent: Object) {
}
// ensure the output is ASCII-safe
let val = jsesc(node.value, {
const opts = {
quotes: t.isJSX(parent) ? "double" : this.format.quotes,
wrap: true
});
};
if (this.format.jsonCompatibleStrings) {
opts.json = true;
}
let val = jsesc(node.value, opts);
return this.token(val);
}

View File

@ -59,6 +59,7 @@ function normalizeOptions(code, opts, tokens): Format {
minified: opts.minified,
concise: opts.concise,
quotes: opts.quotes || findCommonStringDelimiter(code, tokens),
jsonCompatibleStrings: opts.jsonCompatibleStrings,
indent: {
adjustMultilineComment: true,
style: style,

View File

@ -0,0 +1 @@
"©";

View File

@ -0,0 +1 @@
"\u00A9";

View File

@ -0,0 +1,4 @@
{
"minified": true,
"jsonCompatibleStrings": true
}