From c73fdc87d046b97ab11ebcc005ac6070b0b18e54 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 31 Jul 2017 13:03:26 -0700 Subject: [PATCH] Allow JSXAttribute to be IdentifierName (#17466) * Add test * Fix #17452 - Allow JSXAttribute names to be IdentifierNames * Move check into isIdentifierName --- src/compiler/utilities.ts | 3 ++- .../reference/jsxPropsAsIdentifierNames.js | 16 ++++++++++++ .../jsxPropsAsIdentifierNames.symbols | 23 +++++++++++++++++ .../reference/jsxPropsAsIdentifierNames.types | 25 +++++++++++++++++++ .../compiler/jsxPropsAsIdentifierNames.tsx | 12 +++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsxPropsAsIdentifierNames.js create mode 100644 tests/baselines/reference/jsxPropsAsIdentifierNames.symbols create mode 100644 tests/baselines/reference/jsxPropsAsIdentifierNames.types create mode 100644 tests/cases/compiler/jsxPropsAsIdentifierNames.tsx diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fad2db307aa..24e0d59318b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1781,7 +1781,8 @@ namespace ts { // Property name in binding element or import specifier return (parent).propertyName === node; case SyntaxKind.ExportSpecifier: - // Any name in an export specifier + case SyntaxKind.JsxAttribute: + // Any name in an export specifier or JSX Attribute return true; } return false; diff --git a/tests/baselines/reference/jsxPropsAsIdentifierNames.js b/tests/baselines/reference/jsxPropsAsIdentifierNames.js new file mode 100644 index 00000000000..ef9d360b1dd --- /dev/null +++ b/tests/baselines/reference/jsxPropsAsIdentifierNames.js @@ -0,0 +1,16 @@ +//// [index.tsx] +declare namespace JSX { + interface Element { } + interface IntrinsicElements { + div: { + static?: boolean; + }; + } +} +export default
; + + +//// [index.jsx] +"use strict"; +exports.__esModule = true; +exports["default"] =
; diff --git a/tests/baselines/reference/jsxPropsAsIdentifierNames.symbols b/tests/baselines/reference/jsxPropsAsIdentifierNames.symbols new file mode 100644 index 00000000000..15df2efa0c9 --- /dev/null +++ b/tests/baselines/reference/jsxPropsAsIdentifierNames.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/index.tsx === +declare namespace JSX { +>JSX : Symbol(JSX, Decl(index.tsx, 0, 0)) + + interface Element { } +>Element : Symbol(Element, Decl(index.tsx, 0, 23)) + + interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.tsx, 1, 25)) + + div: { +>div : Symbol(IntrinsicElements.div, Decl(index.tsx, 2, 33)) + + static?: boolean; +>static : Symbol(static, Decl(index.tsx, 3, 14)) + + }; + } +} +export default
; +>div : Symbol(unknown) +>static : Symbol(static, Decl(index.tsx, 8, 19)) + diff --git a/tests/baselines/reference/jsxPropsAsIdentifierNames.types b/tests/baselines/reference/jsxPropsAsIdentifierNames.types new file mode 100644 index 00000000000..1d52871b419 --- /dev/null +++ b/tests/baselines/reference/jsxPropsAsIdentifierNames.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/index.tsx === +declare namespace JSX { +>JSX : any + + interface Element { } +>Element : Element + + interface IntrinsicElements { +>IntrinsicElements : IntrinsicElements + + div: { +>div : { static?: boolean; } + + static?: boolean; +>static : boolean + + }; + } +} +export default
; +>
: any +>div : any +>static : boolean +>true : true + diff --git a/tests/cases/compiler/jsxPropsAsIdentifierNames.tsx b/tests/cases/compiler/jsxPropsAsIdentifierNames.tsx new file mode 100644 index 00000000000..7f19b3d457d --- /dev/null +++ b/tests/cases/compiler/jsxPropsAsIdentifierNames.tsx @@ -0,0 +1,12 @@ +// @jsx: preserve + +// @filename: index.tsx +declare namespace JSX { + interface Element { } + interface IntrinsicElements { + div: { + static?: boolean; + }; + } +} +export default
;