diff --git a/src/transformers/JSXTransformer.ts b/src/transformers/JSXTransformer.ts index 09bac056..3e96524f 100644 --- a/src/transformers/JSXTransformer.ts +++ b/src/transformers/JSXTransformer.ts @@ -3,6 +3,7 @@ import {Options} from "../index"; import NameManager from "../NameManager"; import XHTMLEntities from "../parser/plugins/jsx/xhtml"; import {TokenType as tt} from "../parser/tokenizer/types"; +import {charCodes} from "../parser/util/charcodes"; import TokenProcessor from "../TokenProcessor"; import getJSXPragmaInfo, {JSXPragmaInfo} from "../util/getJSXPragmaInfo"; import RootTransformer from "./RootTransformer"; @@ -252,7 +253,8 @@ export default class JSXTransformer extends Transformer { } export function startsWithLowerCase(s: string): boolean { - return s[0] === s[0].toLowerCase(); + const firstChar = s.charCodeAt(0); + return firstChar >= charCodes.lowercaseA && firstChar <= charCodes.lowercaseZ; } /** 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( `