Skip to content

Commit

Permalink
Add jsx option (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc authored Feb 15, 2024
1 parent 69d8070 commit f3d3570
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,13 @@ You can define custom `render`/`createContext` calls by using the `imports` opti
],
}
```

## Other Configs

### Granular Mode

Granular mode for HMR (which allows independent HMR for components and templates) is enabled by default. You can disable this by adding `granular: false`.

### JSX HMR

JSX, by default, is moved to a separate component to perform granular HMR. To disable this, add `jsx: false`.
2 changes: 2 additions & 0 deletions src/babel/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type ImportDefinition = DefaultImportDefinition | NamedImportDefinition;

export interface Options {
granular?: boolean;
jsx?: boolean;
bundler?: RuntimeType;
fixRender?: boolean;
imports?: {
Expand All @@ -32,6 +33,7 @@ export interface ImportIdentifierSpecifier {
}

export interface StateContext {
jsx: boolean;
granular: boolean;
opts: Options;
specifiers: ImportIdentifierSpecifier[];
Expand Down
19 changes: 11 additions & 8 deletions src/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
visitor: {
Program(programPath, context) {
const state: StateContext = {
jsx: context.opts.jsx ?? true,
granular: context.opts.granular ?? true,
opts: context.opts,
specifiers: [...IMPORT_SPECIFIERS],
Expand All @@ -356,14 +357,16 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
bubbleFunctionDeclaration(programPath, path);
},
});
programPath.traverse({
JSXElement(path) {
transformJSX(path);
},
JSXFragment(path) {
transformJSX(path);
},
});
if (state.jsx) {
programPath.traverse({
JSXElement(path) {
transformJSX(path);
},
JSXFragment(path) {
transformJSX(path);
},
});
}
programPath.traverse({
VariableDeclarator(path) {
transformVariableDeclarator(state, path);
Expand Down

0 comments on commit f3d3570

Please sign in to comment.