Skip to content

Commit

Permalink
Allow component names to start with _
Browse files Browse the repository at this point in the history
Fixes #424
  • Loading branch information
yang committed Feb 28, 2019
1 parent 4593c51 commit f9f5e36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/transformers/JSXTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/jsx-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
Expand Down

0 comments on commit f9f5e36

Please sign in to comment.