Skip to content

fix(37456): Incomplete type cleanup with jsx set to preserve #37739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3542,6 +3542,10 @@ namespace ts {
case SyntaxKind.ElementAccessExpression:
return computeElementAccess(<ElementAccessExpression>node, subtreeFlags);

case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.JsxOpeningElement:
return computeJsxOpeningLikeElement(<JsxOpeningLikeElement>node, subtreeFlags);

default:
return computeOther(node, kind, subtreeFlags);
}
Expand Down Expand Up @@ -3591,6 +3595,15 @@ namespace ts {
return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes;
}

function computeJsxOpeningLikeElement(node: JsxOpeningLikeElement, subtreeFlags: TransformFlags) {
let transformFlags = subtreeFlags | TransformFlags.AssertJsx;
if (node.typeArguments) {
transformFlags |= TransformFlags.AssertTypeScript;
}
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
return transformFlags & ~TransformFlags.NodeExcludes;
}

function computeBinaryExpression(node: BinaryExpression, subtreeFlags: TransformFlags) {
let transformFlags = subtreeFlags;
const operatorTokenKind = node.operatorToken.kind;
Expand Down Expand Up @@ -4124,8 +4137,6 @@ namespace ts {
break;

case SyntaxKind.JsxElement:
case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.JsxOpeningElement:
case SyntaxKind.JsxText:
case SyntaxKind.JsxClosingElement:
case SyntaxKind.JsxFragment:
Expand Down
22 changes: 22 additions & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,12 @@ namespace ts {
// TypeScript namespace or external module import.
return visitImportEqualsDeclaration(<ImportEqualsDeclaration>node);

case SyntaxKind.JsxSelfClosingElement:
return visitJsxSelfClosingElement(<JsxSelfClosingElement>node);

case SyntaxKind.JsxOpeningElement:
return visitJsxJsxOpeningElement(<JsxOpeningElement>node);

default:
// node contains some other TypeScript syntax
return visitEachChild(node, visitor, context);
Expand Down Expand Up @@ -2271,6 +2277,22 @@ namespace ts {
visitNode(node.template, visitor, isExpression));
}

function visitJsxSelfClosingElement(node: JsxSelfClosingElement) {
return updateJsxSelfClosingElement(
node,
visitNode(node.tagName, visitor, isJsxTagNameExpression),
/*typeArguments*/ undefined,
visitNode(node.attributes, visitor, isJsxAttributes));
}

function visitJsxJsxOpeningElement(node: JsxOpeningElement) {
return updateJsxOpeningElement(
node,
visitNode(node.tagName, visitor, isJsxTagNameExpression),
/*typeArguments*/ undefined,
visitNode(node.attributes, visitor, isJsxAttributes));
}

/**
* Determines whether to emit an enum declaration.
*
Expand Down
42 changes: 42 additions & 0 deletions tests/baselines/reference/tsxTypeArgumentsJsxPreserveOutput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//// [foo.tsx]
import React = require('react');

type TypeProps = { foo?: boolean; };
interface InterfaceProps { foo?: boolean; }

function Foo<T>() {
return null;
}

<>
<Foo<unknown> />
<Foo<string> />
<Foo<boolean> />
<Foo<object> />
<Foo<null> />
<Foo<any> />
<Foo<never> />
<Foo<undefined> />
<Foo<TypeProps> />
<Foo<InterfaceProps> />
</>

//// [foo.jsx]
"use strict";
exports.__esModule = true;
var React = require("react");
function Foo() {
return null;
}
<>
<Foo />
<Foo />
<Foo />
<Foo />
<Foo />
<Foo />
<Foo />
<Foo />
<Foo />
<Foo />
</>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
=== tests/cases/conformance/jsx/foo.tsx ===
import React = require('react');
>React : Symbol(React, Decl(foo.tsx, 0, 0))

type TypeProps = { foo?: boolean; };
>TypeProps : Symbol(TypeProps, Decl(foo.tsx, 0, 32))
>foo : Symbol(foo, Decl(foo.tsx, 2, 18))

interface InterfaceProps { foo?: boolean; }
>InterfaceProps : Symbol(InterfaceProps, Decl(foo.tsx, 2, 36))
>foo : Symbol(InterfaceProps.foo, Decl(foo.tsx, 3, 26))

function Foo<T>() {
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))
>T : Symbol(T, Decl(foo.tsx, 5, 13))

return null;
}

<>
<Foo<unknown> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<string> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<boolean> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<object> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<null> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<any> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<never> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<undefined> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))

<Foo<TypeProps> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))
>TypeProps : Symbol(TypeProps, Decl(foo.tsx, 0, 32))

<Foo<InterfaceProps> />
>Foo : Symbol(Foo, Decl(foo.tsx, 3, 43))
>InterfaceProps : Symbol(InterfaceProps, Decl(foo.tsx, 2, 36))

</>
63 changes: 63 additions & 0 deletions tests/baselines/reference/tsxTypeArgumentsJsxPreserveOutput.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
=== tests/cases/conformance/jsx/foo.tsx ===
import React = require('react');
>React : typeof React

type TypeProps = { foo?: boolean; };
>TypeProps : TypeProps
>foo : boolean

interface InterfaceProps { foo?: boolean; }
>foo : boolean

function Foo<T>() {
>Foo : <T>() => any

return null;
>null : null
}

<>
><> <Foo<unknown> /> <Foo<string> /> <Foo<boolean> /> <Foo<object> /> <Foo<null> /> <Foo<any> /> <Foo<never> /> <Foo<undefined> /> <Foo<TypeProps> /> <Foo<InterfaceProps> /></> : JSX.Element

<Foo<unknown> />
><Foo<unknown> /> : JSX.Element
>Foo : <T>() => any

<Foo<string> />
><Foo<string> /> : JSX.Element
>Foo : <T>() => any

<Foo<boolean> />
><Foo<boolean> /> : JSX.Element
>Foo : <T>() => any

<Foo<object> />
><Foo<object> /> : JSX.Element
>Foo : <T>() => any

<Foo<null> />
><Foo<null> /> : JSX.Element
>Foo : <T>() => any
>null : null

<Foo<any> />
><Foo<any> /> : JSX.Element
>Foo : <T>() => any

<Foo<never> />
><Foo<never> /> : JSX.Element
>Foo : <T>() => any

<Foo<undefined> />
><Foo<undefined> /> : JSX.Element
>Foo : <T>() => any

<Foo<TypeProps> />
><Foo<TypeProps> /> : JSX.Element
>Foo : <T>() => any

<Foo<InterfaceProps> />
><Foo<InterfaceProps> /> : JSX.Element
>Foo : <T>() => any

</>
27 changes: 27 additions & 0 deletions tests/cases/conformance/jsx/tsxTypeArgumentsJsxPreserveOutput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @filename: foo.tsx
// @jsx: preserve
// @noLib: true
// @skipLibCheck: true
// @libFiles: react.d.ts,lib.d.ts

import React = require('react');

type TypeProps = { foo?: boolean; };
interface InterfaceProps { foo?: boolean; }

function Foo<T>() {
return null;
}

<>
<Foo<unknown> />
<Foo<string> />
<Foo<boolean> />
<Foo<object> />
<Foo<null> />
<Foo<any> />
<Foo<never> />
<Foo<undefined> />
<Foo<TypeProps> />
<Foo<InterfaceProps> />
</>