Fix the issue 15232 (#16004)

This commit is contained in:
Yui 2017-05-23 10:26:07 -07:00 committed by Mohamed Hegazy
parent e4aa515191
commit 1c3cdf11b5
5 changed files with 192 additions and 2 deletions

View file

@ -58,8 +58,10 @@ namespace ts {
}
const isEmittedNode = node.kind !== SyntaxKind.NotEmittedStatement;
const skipLeadingComments = pos < 0 || (emitFlags & EmitFlags.NoLeadingComments) !== 0;
const skipTrailingComments = end < 0 || (emitFlags & EmitFlags.NoTrailingComments) !== 0;
// We have to explicitly check that the node is JsxText because if the compilerOptions.jsx is "preserve" we will not do any transformation.
// It is expensive to walk entire tree just to set one kind of node to have no comments.
const skipLeadingComments = pos < 0 || (emitFlags & EmitFlags.NoLeadingComments) !== 0 || node.kind === SyntaxKind.JsxText;
const skipTrailingComments = end < 0 || (emitFlags & EmitFlags.NoTrailingComments) !== 0 || node.kind === SyntaxKind.JsxText;
// Emit leading comments if the position is not synthesized and the node
// has not opted out from emitting leading comments.

View file

@ -0,0 +1,57 @@
//// [file.tsx]
import React = require('react');
<div>
// Not Comment
</div>;
<div>
// Not Comment
{
//Comment just Fine
}
// Another not Comment
</div>;
<div>
// Not Comment
{
//Comment just Fine
"Hi"
}
// Another not Comment
</div>;
<div>
/* Not Comment */
{
//Comment just Fine
"Hi"
}
</div>;
//// [file.jsx]
"use strict";
exports.__esModule = true;
var React = require("react");
<div>
// Not Comment
</div>;
<div>
// Not Comment
// Another not Comment
</div>;
<div>
// Not Comment
{
//Comment just Fine
"Hi"}
// Another not Comment
</div>;
<div>
/* Not Comment */
{
//Comment just Fine
"Hi"}
</div>;

View file

@ -0,0 +1,45 @@
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react');
>React : Symbol(React, Decl(file.tsx, 0, 0))
<div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
// Not Comment
</div>;
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
<div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
// Not Comment
{
//Comment just Fine
}
// Another not Comment
</div>;
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
<div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
// Not Comment
{
//Comment just Fine
"Hi"
}
// Another not Comment
</div>;
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
<div>
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))
/* Not Comment */
{
//Comment just Fine
"Hi"
}
</div>;
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2399, 45))

View file

@ -0,0 +1,51 @@
=== tests/cases/conformance/jsx/file.tsx ===
import React = require('react');
>React : typeof React
<div>
><div> // Not Comment</div> : JSX.Element
>div : any
// Not Comment
</div>;
>div : any
<div>
><div> // Not Comment { //Comment just Fine } // Another not Comment</div> : JSX.Element
>div : any
// Not Comment
{
//Comment just Fine
}
// Another not Comment
</div>;
>div : any
<div>
><div> // Not Comment { //Comment just Fine "Hi" } // Another not Comment</div> : JSX.Element
>div : any
// Not Comment
{
//Comment just Fine
"Hi"
>"Hi" : "Hi"
}
// Another not Comment
</div>;
>div : any
<div>
><div> /* Not Comment */ { //Comment just Fine "Hi" }</div> : JSX.Element
>div : any
/* Not Comment */
{
//Comment just Fine
"Hi"
>"Hi" : "Hi"
}
</div>;
>div : any

View file

@ -0,0 +1,35 @@
// @filename: file.tsx
// @jsx: preserve
// @noLib: true
// @libFiles: react.d.ts,lib.d.ts
import React = require('react');
<div>
// Not Comment
</div>;
<div>
// Not Comment
{
//Comment just Fine
}
// Another not Comment
</div>;
<div>
// Not Comment
{
//Comment just Fine
"Hi"
}
// Another not Comment
</div>;
<div>
/* Not Comment */
{
//Comment just Fine
"Hi"
}
</div>;