Skip to content

Commit

Permalink
Fix pre-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Jan 24, 2024
1 parent effd173 commit 666a7e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/babel/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface StateContext {
identifiers: Map<t.Identifier, ImportIdentifierSpecifier>;
namespaces: Map<t.Identifier, ImportIdentifierSpecifier[]>;
};
processed: boolean;
filename: string | undefined;
bundler: RuntimeType;
fixRender: boolean;
Expand Down
14 changes: 7 additions & 7 deletions src/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,29 @@ function setupProgram(
state: StateContext,
path: babel.NodePath<t.Program>,
comments: t.Comment[] | undefined | null,
): void {
): boolean {
let shouldSkip = false;
let isDone = false;
if (comments) {
for (const { value: comment } of comments) {
if (/^\s*@refresh skip\s*$/.test(comment)) {
state.processed = true;
isDone = true;
shouldSkip = true;
break;
}
if (/^\s*@refresh reload\s*$/.test(comment)) {
state.processed = true;
isDone = true;
path.pushContainer('body', getHMRDeclineCall(state, path));
break;
}
}
}

captureIdentifiers(state, path);
if (!shouldSkip && state.fixRender) {
captureIdentifiers(state, path);
fixRenderCalls(state, path);
}
return isDone;
}

function isStatementTopLevel(path: babel.NodePath<t.Statement>): boolean {
Expand Down Expand Up @@ -346,13 +348,11 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
identifiers: new Map(),
namespaces: new Map(),
},
processed: false,
filename: context.filename,
bundler: context.opts.bundler || 'standard',
fixRender: context.opts.fixRender ?? true,
};
setupProgram(state, programPath, context.file.ast.comments);
if (state.processed) {
if (setupProgram(state, programPath, context.file.ast.comments)) {
return;
}
programPath.traverse({
Expand Down

0 comments on commit 666a7e0

Please sign in to comment.