From d229ae4be50b6acddb2d52a4deeb220bca1b975e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 8 Oct 2015 11:28:18 -0700 Subject: [PATCH] Escape quotes when emitting React --- src/compiler/emitter.ts | 4 ++-- tests/baselines/reference/tsxReactEmit6.js | 6 ++++++ tests/baselines/reference/tsxReactEmit6.symbols | 7 +++++++ tests/baselines/reference/tsxReactEmit6.types | 8 ++++++++ tests/cases/conformance/jsx/tsxReactEmit6.tsx | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 312ea42eefb..7440c905566 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6848,7 +6848,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (isLineBreak(c)) { if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) { let part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1); - result = (result ? result + "\" + ' ' + \"" : "") + part; + result = (result ? result + "\" + ' ' + \"" : "") + escapeString(part); } firstNonWhitespace = -1; } @@ -6862,7 +6862,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi if (firstNonWhitespace !== -1) { let part = text.substr(firstNonWhitespace); - result = (result ? result + "\" + ' ' + \"" : "") + part; + result = (result ? result + "\" + ' ' + \"" : "") + escapeString(part); } if (result) { diff --git a/tests/baselines/reference/tsxReactEmit6.js b/tests/baselines/reference/tsxReactEmit6.js index d20ef7051e0..4f583929004 100644 --- a/tests/baselines/reference/tsxReactEmit6.js +++ b/tests/baselines/reference/tsxReactEmit6.js @@ -19,7 +19,11 @@ namespace M { // and M.React.__spread var foo; var spread1 =
; + + // Quotes + var x =
This "quote" thing
; } + //// [file.js] @@ -33,4 +37,6 @@ var M; // and M.React.__spread var foo; var spread1 = M.React.createElement("div", M.React.__spread({x: ''}, foo, {y: ''})); + // Quotes + var x = M.React.createElement("div", null, "This \"quote\" thing"); })(M || (M = {})); diff --git a/tests/baselines/reference/tsxReactEmit6.symbols b/tests/baselines/reference/tsxReactEmit6.symbols index fd717ee4a5b..8eb0561e185 100644 --- a/tests/baselines/reference/tsxReactEmit6.symbols +++ b/tests/baselines/reference/tsxReactEmit6.symbols @@ -36,5 +36,12 @@ namespace M { >x : Symbol(unknown) >foo : Symbol(foo, Decl(react-consumer.tsx, 7, 4)) >y : Symbol(unknown) + + // Quotes + var x =
This "quote" thing
; +>x : Symbol(x, Decl(react-consumer.tsx, 11, 4)) +>div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 2, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 2, 22)) } + diff --git a/tests/baselines/reference/tsxReactEmit6.types b/tests/baselines/reference/tsxReactEmit6.types index 1b16b84fcc7..b8a307eb9d7 100644 --- a/tests/baselines/reference/tsxReactEmit6.types +++ b/tests/baselines/reference/tsxReactEmit6.types @@ -37,5 +37,13 @@ namespace M { >x : any >foo : any >y : any + + // Quotes + var x =
This "quote" thing
; +>x : JSX.Element +>
This "quote" thing
: JSX.Element +>div : any +>div : any } + diff --git a/tests/cases/conformance/jsx/tsxReactEmit6.tsx b/tests/cases/conformance/jsx/tsxReactEmit6.tsx index 2782f90e503..0e8c772a3f1 100644 --- a/tests/cases/conformance/jsx/tsxReactEmit6.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmit6.tsx @@ -19,4 +19,8 @@ namespace M { // and M.React.__spread var foo; var spread1 =
; + + // Quotes + var x =
This "quote" thing
; } +