Skip to content

Commit

Permalink
Fix missed bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Feb 16, 2024
1 parent f3d3570 commit fb3903a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 40 deletions.
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

0 comments on commit fb3903a

Please sign in to comment.