Skip to content

Update JSX intrinsic element test to match babel’s #19946

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 4 commits into from
Nov 14, 2017
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
6 changes: 2 additions & 4 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2434,10 +2434,8 @@ namespace ts {
}

export function isIntrinsicJsxName(name: __String | string) {
// An escaped identifier had a leading underscore prior to being escaped, which would return true
// The escape adds an extra underscore which does not change the result
const ch = (name as string).substr(0, 1);
return ch.toLowerCase() === ch;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ch.toLowerCase() === ch || ch === "_" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah.. that is the opposite.. sorry..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ch = (name as string).charCodeAt(0);
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) ||
 ch == CharacterCodes._ ||
 (name as string).indexof("-") > 0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and avoid the creation of a regexp on every invocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhegazy good catch, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missed the comment before. Updating…

const ch = (name as string).charCodeAt(0);
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) || (name as string).indexOf("-") > -1;
}

function get16BitUnicodeEscapeSequence(charCode: number): string {
Expand Down
13 changes: 5 additions & 8 deletions tests/baselines/reference/doubleUnderscoreReactNamespace.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
//// [index.tsx]
declare global {
namespace JSX {
interface IntrinsicElements {
__foot: any;
}
}
function __make (params: object): any;
}

declare var __foot: any;

const thing = <__foot></__foot>;
const thing = <__foot />;

export {}
export {}


//// [index.js]
"use strict";
exports.__esModule = true;
var thing = __make("__foot", null);
var thing = __make(__foot, null);
24 changes: 8 additions & 16 deletions tests/baselines/reference/doubleUnderscoreReactNamespace.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@
declare global {
>global : Symbol(global, Decl(index.tsx, 0, 0))

namespace JSX {
>JSX : Symbol(JSX, Decl(index.tsx, 0, 16))

interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.tsx, 1, 19))

__foot: any;
>__foot : Symbol(IntrinsicElements.__foot, Decl(index.tsx, 2, 37))
}
}
function __make (params: object): any;
>__make : Symbol(__make, Decl(index.tsx, 5, 5))
>params : Symbol(params, Decl(index.tsx, 6, 21))
>__make : Symbol(__make, Decl(index.tsx, 0, 16))
>params : Symbol(params, Decl(index.tsx, 1, 21))
}

declare var __foot: any;
>__foot : Symbol(__foot, Decl(index.tsx, 4, 11))

const thing = <__foot></__foot>;
>thing : Symbol(thing, Decl(index.tsx, 10, 5))
>__foot : Symbol(JSX.IntrinsicElements.__foot, Decl(index.tsx, 2, 37))
>__foot : Symbol(JSX.IntrinsicElements.__foot, Decl(index.tsx, 2, 37))
const thing = <__foot />;
>thing : Symbol(thing, Decl(index.tsx, 6, 5))
>__foot : Symbol(__foot, Decl(index.tsx, 4, 11))

export {}

18 changes: 5 additions & 13 deletions tests/baselines/reference/doubleUnderscoreReactNamespace.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@
declare global {
>global : typeof global

namespace JSX {
>JSX : any

interface IntrinsicElements {
>IntrinsicElements : IntrinsicElements

__foot: any;
>__foot : any
}
}
function __make (params: object): any;
>__make : (params: object) => any
>params : object
}

declare var __foot: any;
>__foot : any

const thing = <__foot></__foot>;
const thing = <__foot />;
>thing : any
><__foot></__foot> : any
>__foot : any
><__foot /> : any
>__foot : any

export {}

4 changes: 2 additions & 2 deletions tests/baselines/reference/jsxEsprimaFbTestSuite.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ declare var props;
/>;

<日本語></日本語>;
>日本語 : Symbol(unknown)
>日本語 : Symbol(unknown)
>日本語 : Symbol(日本語, Decl(jsxEsprimaFbTestSuite.tsx, 1, 11))
>日本語 : Symbol(日本語, Decl(jsxEsprimaFbTestSuite.tsx, 1, 11))

<AbC_def
>AbC_def : Symbol(AbC_def, Decl(jsxEsprimaFbTestSuite.tsx, 2, 11))
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/jsxFactoryIdentifier.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/baselines/reference/jsxFactoryIdentifier.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ class A {
];
}
}

1 change: 1 addition & 0 deletions tests/baselines/reference/jsxFactoryIdentifier.types
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ class A {
];
}
}

3 changes: 3 additions & 0 deletions tests/baselines/reference/reactNamespaceJSXEmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
declare var myReactLib: any;
declare var foo: any;
declare var Bar: any;
declare var _Bar: any;
declare var x: any;

<foo data/>;
<Bar x={x} />;
<x-component />;
<Bar {...x} />;
<Bar { ...x } y={2} />;
<_Bar { ...x } />;


//// [reactNamespaceJSXEmit.js]
Expand All @@ -25,3 +27,4 @@ myReactLib.createElement(Bar, { x: x });
myReactLib.createElement("x-component", null);
myReactLib.createElement(Bar, __assign({}, x));
myReactLib.createElement(Bar, __assign({}, x, { y: 2 }));
myReactLib.createElement(_Bar, __assign({}, x));
21 changes: 14 additions & 7 deletions tests/baselines/reference/reactNamespaceJSXEmit.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,34 @@ declare var foo: any;
declare var Bar: any;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 2, 11))

declare var _Bar: any;
>_Bar : Symbol(_Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))

declare var x: any;
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))

<foo data/>;
>foo : Symbol(unknown)
>data : Symbol(data, Decl(reactNamespaceJSXEmit.tsx, 5, 4))
>data : Symbol(data, Decl(reactNamespaceJSXEmit.tsx, 6, 4))

<Bar x={x} />;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 2, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 6, 4))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 7, 4))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))

<x-component />;
>x-component : Symbol(unknown)

<Bar {...x} />;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 2, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))

<Bar { ...x } y={2} />;
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 2, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>y : Symbol(y, Decl(reactNamespaceJSXEmit.tsx, 9, 13))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
>y : Symbol(y, Decl(reactNamespaceJSXEmit.tsx, 10, 13))

<_Bar { ...x } />;
>_Bar : Symbol(_Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))

8 changes: 8 additions & 0 deletions tests/baselines/reference/reactNamespaceJSXEmit.types
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ declare var foo: any;
declare var Bar: any;
>Bar : any

declare var _Bar: any;
>_Bar : any

declare var x: any;
>x : any

Expand Down Expand Up @@ -38,3 +41,8 @@ declare var x: any;
>y : number
>2 : 2

<_Bar { ...x } />;
><_Bar { ...x } /> : any
>_Bar : any
>x : any

10 changes: 3 additions & 7 deletions tests/cases/compiler/doubleUnderscoreReactNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
// @filename: index.tsx

declare global {
namespace JSX {
interface IntrinsicElements {
__foot: any;
}
}
function __make (params: object): any;
}

declare var __foot: any;

const thing = <__foot></__foot>;
const thing = <__foot />;

export {}
export {}
22 changes: 11 additions & 11 deletions tests/cases/compiler/jsxFactoryIdentifier.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//@jsx: react
//@target: es6
//@module: commonjs
//@jsxFactory: createElement
//@sourcemap: true
// @filename: Element.ts
//@jsx: react
//@target: es6
//@module: commonjs
//@jsxFactory: createElement
//@sourcemap: true

// @filename: Element.ts
declare namespace JSX {
interface Element {
name: string;
Expand Down Expand Up @@ -33,9 +33,9 @@ export let createElement = Element.createElement;

function toCamelCase(text: string): string {
return text[0].toLowerCase() + text.substring(1);
}
// @filename: test.tsx
}

// @filename: test.tsx
import { Element} from './Element';
let createElement = Element.createElement;
let c: {
Expand All @@ -51,4 +51,4 @@ class A {
<meta content={c.a!.b}></meta>
];
}
}
}
2 changes: 2 additions & 0 deletions tests/cases/compiler/reactNamespaceJSXEmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
declare var myReactLib: any;
declare var foo: any;
declare var Bar: any;
declare var _Bar: any;
declare var x: any;

<foo data/>;
<Bar x={x} />;
<x-component />;
<Bar {...x} />;
<Bar { ...x } y={2} />;
<_Bar { ...x } />;