From 0bac644b25a09d6f02ae90d58152e9dbbc9bef4b Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Wed, 27 Feb 2019 18:30:46 -0800 Subject: [PATCH] Allow component names to start with _ Fixes #424 --- src/transformers/JSXTransformer.ts | 2 +- test/jsx-test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/transformers/JSXTransformer.ts b/src/transformers/JSXTransformer.ts index 09bac056..c53d82bd 100644 --- a/src/transformers/JSXTransformer.ts +++ b/src/transformers/JSXTransformer.ts @@ -252,7 +252,7 @@ export default class JSXTransformer extends Transformer { } export function startsWithLowerCase(s: string): boolean { - return s[0] === s[0].toLowerCase(); + return s[0] !== s[0].toUpperCase(); } /** diff --git a/test/jsx-test.ts b/test/jsx-test.ts index d8f237ba..b5c9044d 100644 --- a/test/jsx-test.ts +++ b/test/jsx-test.ts @@ -37,6 +37,17 @@ describe("transform JSX", () => { ); }); + it("handles component names starting with _", () => { + assertResult( + ` + <_Foo /> + `, + `${JSX_PREFIX} + React.createElement(_Foo, {${devProps(2)}} ) + `, + ); + }); + it("transforms nested JSX elements", () => { assertResult( `