MCPcopy Index your code
hub / github.com/dropbox/ts-transform-react-constant-elements

github.com/dropbox/ts-transform-react-constant-elements @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
16 symbols 31 edges 7 files 5 documented · 31% updated 2y ago★ 44
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ts-transform-react-constant-elements

build status

This is a TypeScript AST Transformer that can speed up reconciliation and reduce garbage collection pressure by hoisting React elements to the highest possible scope, preventing multiple unnecessary reinstantiations, similar to babel-plugin-transform-react-constant-elements.

Example:

const Hr = () => {
  return <hr className="hr" />;
};

// becomes 
const _ref = <hr className="hr" />;

const Hr = () => {
  return _ref;
};

This is especially useful for hoisting static but expensive content such as SVG.

Usage

First of all, you need some level of familiarity with the TypeScript Compiler API.

compile.ts & tests should have examples of how this works. The available options are:

verbose?: boolean

Enabling this will allow this transformer to log out which nodes are hoisted.

License

Copyright (c) 2018 Dropbox, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Extension points exported contracts — how you extend this code

Props (Interface)
(no doc)
test/fixture/ConstantEl.tsx
Opts (Interface)
(no doc)
src/transform.ts
Props (Interface)
(no doc)
test/fixture/MultipleConstantEl.tsx
Props (Interface)
(no doc)
test/fixture/EmptyEl.tsx

Core symbols most depended-on inside this repo

compile
called by 3
compile.ts
isNotPrologueDirective
called by 1
src/transform.ts
isReactImport
called by 1
src/transform.ts
isConstantElement
called by 1
src/transform.ts
constantElementVisitor
called by 1
src/transform.ts
visitSourceFile
called by 1
src/transform.ts
Foo
called by 0
test/fixture/ConstantEl.tsx
Foo
called by 0
test/fixture/MultipleConstantEl.tsx

Shape

Function 12
Interface 4

Languages

TypeScript100%

Modules by API surface

src/transform.ts9 symbols
test/fixture/MultipleConstantEl.tsx2 symbols
test/fixture/EmptyEl.tsx2 symbols
test/fixture/ConstantEl.tsx2 symbols
compile.ts1 symbols

For agents

$ claude mcp add ts-transform-react-constant-elements \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact