babel-generator: keep double quotes in StringLiteral for JSX parent (fixes T6859)

This commit is contained in:
Henry Zhu
2015-12-19 22:12:11 -05:00
parent b79ff75c31
commit 379be365d6
3 changed files with 22 additions and 4 deletions

View File

@@ -115,11 +115,11 @@ export function NumericLiteral(node: Object) {
this.push(node.value + "");
}
export function StringLiteral(node: Object) {
this.push(this._stringLiteral(node.value));
export function StringLiteral(node: Object, parent: Object) {
this.push(this._stringLiteral(node.value, parent));
}
export function _stringLiteral(val: string): string {
export function _stringLiteral(val: string, parent: Object): string {
val = JSON.stringify(val);
// escape illegal js but valid json unicode characters
@@ -127,7 +127,7 @@ export function _stringLiteral(val: string): string {
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
});
if (this.format.quotes === "single") {
if (this.format.quotes === "single" && !t.isJSX(parent)) {
// remove double quotes
val = val.slice(1, -1);

View File

@@ -0,0 +1,9 @@
var single = 'quotes';
var outnumber = 'double';
var moreSingleQuotesThanDouble = '!';
React.createClass({
render() {
return <View multiple="attributes" attribute="If parent is JSX keep double quote" />;
}
});

View File

@@ -0,0 +1,9 @@
var single = 'quotes';
var outnumber = 'double';
var moreSingleQuotesThanDouble = '!';
React.createClass({
render() {
return <View multiple="attributes" attribute="If parent is JSX keep double quote" />;
}
});