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

* Update JSX intrinsic element test to match babel’s

* Update baseline

* Move regex out of isIntrinsicJsxName

* Switch to non-regex intrinsic name test
This commit is contained in:
meyer 2017-11-14 09:40:32 -08:00 committed by Mohamed Hegazy
parent 9c771958ab
commit 36ce7eac5a
14 changed files with 68 additions and 70 deletions

View file

@ -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;
const ch = (name as string).charCodeAt(0);
return (ch >= CharacterCodes.a && ch <= CharacterCodes.z) || (name as string).indexOf("-") > -1;
}
function get16BitUnicodeEscapeSequence(charCode: number): string {

View file

@ -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);

View file

@ -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 {}

View file

@ -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
}
const thing = <__foot></__foot>;
>thing : any
><__foot></__foot> : any
declare var __foot: any;
>__foot : any
const thing = <__foot />;
>thing : any
><__foot /> : any
>__foot : any
export {}

View file

@ -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))

View file

@ -47,7 +47,8 @@ class A {
<meta content={c.a!.b}></meta>
];
}
}
}
//// [Element.js]
"use strict";

View file

@ -122,3 +122,4 @@ class A {
];
}
}

View file

@ -137,3 +137,4 @@ class A {
];
}
}

View file

@ -2,6 +2,7 @@
declare var myReactLib: any;
declare var foo: any;
declare var Bar: any;
declare var _Bar: any;
declare var x: any;
<foo data/>;
@ -9,6 +10,7 @@ declare var x: any;
<x-component />;
<Bar {...x} />;
<Bar { ...x } y={2} />;
<_Bar { ...x } />;
//// [reactNamespaceJSXEmit.js]
@ -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));

View file

@ -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))

View file

@ -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
@ -38,3 +41,8 @@ declare var x: any;
>y : number
>2 : 2
<_Bar { ...x } />;
><_Bar { ...x } /> : any
>_Bar : any
>x : any

View file

@ -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 {}

View file

@ -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;
@ -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: {
@ -51,4 +51,4 @@ class A {
<meta content={c.a!.b}></meta>
];
}
}
}

View file

@ -4,6 +4,7 @@
declare var myReactLib: any;
declare var foo: any;
declare var Bar: any;
declare var _Bar: any;
declare var x: any;
<foo data/>;
@ -11,3 +12,4 @@ declare var x: any;
<x-component />;
<Bar {...x} />;
<Bar { ...x } y={2} />;
<_Bar { ...x } />;