Adjust scanning of keywordy jsx namespace names, add grammar error for jsx dotted names containing namespace names (#43104)

This commit is contained in:
Wesley Wigham 2021-03-22 10:28:43 -07:00 committed by GitHub
parent 865cec3ece
commit 9a256a1935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 159 additions and 1 deletions

View File

@ -40728,6 +40728,7 @@ namespace ts {
}
function checkGrammarJsxElement(node: JsxOpeningLikeElement) {
checkGrammarJsxName(node.tagName);
checkGrammarTypeArguments(node, node.typeArguments);
const seen = new Map<__String, boolean>();
@ -40750,6 +40751,29 @@ namespace ts {
}
}
function checkGrammarJsxName(node: JsxTagNameExpression) {
if (isPropertyAccessExpression(node)) {
let propName: JsxTagNameExpression = node;
do {
const check = checkGrammarJsxNestedIdentifier(propName.name);
if (check) {
return check;
}
propName = propName.expression;
} while (isPropertyAccessExpression(propName));
const check = checkGrammarJsxNestedIdentifier(propName);
if (check) {
return check;
}
}
function checkGrammarJsxNestedIdentifier(name: MemberName | ThisExpression) {
if (isIdentifier(name) && idText(name).indexOf(":") !== -1) {
return grammarErrorOnNode(name, Diagnostics.JSX_property_access_expressions_cannot_include_JSX_namespace_names);
}
}
}
function checkGrammarJsxExpression(node: JsxExpression) {
if (node.expression && isCommaSequence(node.expression)) {
return grammarErrorOnNode(node.expression, Diagnostics.JSX_expressions_may_not_use_the_comma_operator_Did_you_mean_to_write_an_array);

View File

@ -2674,6 +2674,10 @@
"category": "Error",
"code": 2632
},
"JSX property access expressions cannot include JSX namespace names": {
"category": "Error",
"code": 2633
},
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
"category": "Error",

View File

@ -2335,6 +2335,7 @@ namespace ts {
tokenValue += ":";
pos++;
namespaceSeparator = true;
token = SyntaxKind.Identifier; // swap from keyword kind to identifier kind
continue;
}
const oldPos = pos;

View File

@ -0,0 +1,25 @@
tests/cases/conformance/jsx/checkJsxNamespaceNamesQuestionableForms.tsx(12,2): error TS2304: Cannot find name 'b:c'.
tests/cases/conformance/jsx/checkJsxNamespaceNamesQuestionableForms.tsx(12,2): error TS2633: JSX property access expressions cannot include JSX namespace names
tests/cases/conformance/jsx/checkJsxNamespaceNamesQuestionableForms.tsx(12,10): error TS2304: Cannot find name 'b:c'.
==== tests/cases/conformance/jsx/checkJsxNamespaceNamesQuestionableForms.tsx (3 errors) ====
declare namespace JSX {
interface IntrinsicElements {
'this:b': any;
'b:c': {
x: any
};
'a:b': any;
}
}
<a:b></a:b>;
<b:c.x></b:c.x>;
~~~
!!! error TS2304: Cannot find name 'b:c'.
~~~
!!! error TS2633: JSX property access expressions cannot include JSX namespace names
~~~
!!! error TS2304: Cannot find name 'b:c'.
<this:b></this:b>;

View File

@ -0,0 +1,19 @@
//// [checkJsxNamespaceNamesQuestionableForms.tsx]
declare namespace JSX {
interface IntrinsicElements {
'this:b': any;
'b:c': {
x: any
};
'a:b': any;
}
}
<a:b></a:b>;
<b:c.x></b:c.x>;
<this:b></this:b>;
//// [checkJsxNamespaceNamesQuestionableForms.jsx]
<a:b></a:b>;
<b:c.x></b:c.x>;
<this:b></this:b>;

View File

@ -0,0 +1,31 @@
=== tests/cases/conformance/jsx/checkJsxNamespaceNamesQuestionableForms.tsx ===
declare namespace JSX {
>JSX : Symbol(JSX, Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 0, 0))
interface IntrinsicElements {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 0, 23))
'this:b': any;
>'this:b' : Symbol(IntrinsicElements['this:b'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 1, 33))
'b:c': {
>'b:c' : Symbol(IntrinsicElements['b:c'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 2, 22))
x: any
>x : Symbol(x, Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 3, 16))
};
'a:b': any;
>'a:b' : Symbol(IntrinsicElements['a:b'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 5, 10))
}
}
<a:b></a:b>;
>a:b : Symbol(JSX.IntrinsicElements['a:b'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 5, 10))
>a:b : Symbol(JSX.IntrinsicElements['a:b'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 5, 10))
<b:c.x></b:c.x>;
<this:b></this:b>;
>this:b : Symbol(JSX.IntrinsicElements['this:b'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 1, 33))
>this:b : Symbol(JSX.IntrinsicElements['this:b'], Decl(checkJsxNamespaceNamesQuestionableForms.tsx, 1, 33))

View File

@ -0,0 +1,37 @@
=== tests/cases/conformance/jsx/checkJsxNamespaceNamesQuestionableForms.tsx ===
declare namespace JSX {
interface IntrinsicElements {
'this:b': any;
>'this:b' : any
'b:c': {
>'b:c' : { x: any; }
x: any
>x : any
};
'a:b': any;
>'a:b' : any
}
}
<a:b></a:b>;
><a:b></a:b> : any
>a:b : any
>a:b : any
<b:c.x></b:c.x>;
><b:c.x></b:c.x> : any
>b:c.x : any
>b:c : any
>x : any
>b:c.x : any
>b:c : any
>x : any
<this:b></this:b>;
><this:b></this:b> : any
>this:b : any
>this:b : any

View File

@ -77,6 +77,7 @@ tests/cases/conformance/jsx/6.tsx(1,4): error TS17002: Expected corresponding JS
tests/cases/conformance/jsx/7.tsx(1,13): error TS1002: Unterminated string literal.
tests/cases/conformance/jsx/8.tsx(1,6): error TS17002: Expected corresponding JSX closing tag for 'a:b'.
tests/cases/conformance/jsx/9.tsx(1,2): error TS2304: Cannot find name 'a:b'.
tests/cases/conformance/jsx/9.tsx(1,2): error TS2633: JSX property access expressions cannot include JSX namespace names
tests/cases/conformance/jsx/9.tsx(1,10): error TS2304: Cannot find name 'a:b'.
@ -128,10 +129,12 @@ tests/cases/conformance/jsx/9.tsx(1,10): error TS2304: Cannot find name 'a:b'.
<a:b></b>;
~~~~
!!! error TS17002: Expected corresponding JSX closing tag for 'a:b'.
==== tests/cases/conformance/jsx/9.tsx (2 errors) ====
==== tests/cases/conformance/jsx/9.tsx (3 errors) ====
<a:b.c></a:b.c>;
~~~
!!! error TS2304: Cannot find name 'a:b'.
~~~
!!! error TS2633: JSX property access expressions cannot include JSX namespace names
~~~
!!! error TS2304: Cannot find name 'a:b'.
==== tests/cases/conformance/jsx/10.tsx (6 errors) ====

View File

@ -0,0 +1,14 @@
// @jsx: preserve
declare namespace JSX {
interface IntrinsicElements {
'this:b': any;
'b:c': {
x: any
};
'a:b': any;
}
}
<a:b></a:b>;
<b:c.x></b:c.x>;
<this:b></this:b>;