Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missed bindings #62

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/babel/core/create-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ export function createRegistry(
const root = getRootStatementPath(path);
const identifier = path.scope.generateUidIdentifier(REGISTRY);

const [tmp] = root.insertBefore(
t.variableDeclaration('const', [
t.variableDeclarator(
identifier,
t.callExpression(getImportIdentifier(state, path, IMPORT_REGISTRY), []),
),
]),
root.scope.registerDeclaration(
root.insertBefore(
t.variableDeclaration('const', [
t.variableDeclarator(
identifier,
t.callExpression(
getImportIdentifier(state, path, IMPORT_REGISTRY),
[],
),
),
]),
)[0],
);
root.scope.registerDeclaration(tmp);
const pathToHot = getHotIdentifier(state);
const statements: t.Statement[] = [
t.expressionStatement(
Expand Down
29 changes: 13 additions & 16 deletions src/babel/core/get-import-identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@ export function getImportIdentifier(
return current;
}
const programParent = path.scope.getProgramParent();
const uid = programParent.generateUidIdentifier(
registration.kind === 'named' ? registration.name : 'default',
const uid = programParent.generateUidIdentifier(name);
programParent.registerDeclaration(
(programParent.path as babel.NodePath<t.Program>).unshiftContainer(
'body',
t.importDeclaration(
[
registration.kind === 'named'
? t.importSpecifier(uid, t.identifier(registration.name))
: t.importDefaultSpecifier(uid),
],
t.stringLiteral(registration.source),
),
)[0],
);
const newPath = (
programParent.path as babel.NodePath<t.Program>
).unshiftContainer(
'body',
t.importDeclaration(
[
registration.kind === 'named'
? t.importSpecifier(uid, t.identifier(registration.name))
: t.importDefaultSpecifier(uid),
],
t.stringLiteral(registration.source),
),
)[0];
programParent.registerDeclaration(newPath);
state.imports.set(target, uid);
return uid;
}
8 changes: 4 additions & 4 deletions src/babel/core/transform-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ export function transformJSX(
templateComp.loc = path.node.loc;
}

const [tmp] = rootPath.insertBefore(
t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]),
rootPath.scope.registerDeclaration(
rootPath.insertBefore(
t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]),
)[0],
);

rootPath.scope.registerDeclaration(tmp);

path.replaceWith(
skippableJSX(
t.jsxElement(
Expand Down
28 changes: 16 additions & 12 deletions src/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,22 @@ function transformFunctionDeclaration(
// have zero or one parameter
decl.params.length < 2
) {
const [tmp] = path.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(
decl.id,
wrapComponent(
state,
path,
path.scope.registerDeclaration(
path.replaceWith(
t.variableDeclaration('const', [
t.variableDeclarator(
decl.id,
t.functionExpression(decl.id, decl.params, decl.body),
decl,
wrapComponent(
state,
path,
decl.id,
t.functionExpression(decl.id, decl.params, decl.body),
decl,
),
),
),
]),
]),
)[0],
);
path.scope.registerDeclaration(tmp);
path.skip();
}
}
Expand Down Expand Up @@ -375,6 +376,9 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
transformFunctionDeclaration(state, path);
},
});
// TODO anything simpler than this?
// This is to fix an issue with webpack
programPath.scope.crawl();
},
},
};
Expand Down
Loading