Skip to content

Commit 42283ab

Browse files
authored
Fix missed bindings (#62)
1 parent f3d3570 commit 42283ab

File tree

4 files changed

+45
-40
lines changed

4 files changed

+45
-40
lines changed

src/babel/core/create-registry.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ export function createRegistry(
2020
const root = getRootStatementPath(path);
2121
const identifier = path.scope.generateUidIdentifier(REGISTRY);
2222

23-
const [tmp] = root.insertBefore(
24-
t.variableDeclaration('const', [
25-
t.variableDeclarator(
26-
identifier,
27-
t.callExpression(getImportIdentifier(state, path, IMPORT_REGISTRY), []),
28-
),
29-
]),
23+
root.scope.registerDeclaration(
24+
root.insertBefore(
25+
t.variableDeclaration('const', [
26+
t.variableDeclarator(
27+
identifier,
28+
t.callExpression(
29+
getImportIdentifier(state, path, IMPORT_REGISTRY),
30+
[],
31+
),
32+
),
33+
]),
34+
)[0],
3035
);
31-
root.scope.registerDeclaration(tmp);
3236
const pathToHot = getHotIdentifier(state);
3337
const statements: t.Statement[] = [
3438
t.expressionStatement(

src/babel/core/get-import-identifier.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@ export function getImportIdentifier(
1414
return current;
1515
}
1616
const programParent = path.scope.getProgramParent();
17-
const uid = programParent.generateUidIdentifier(
18-
registration.kind === 'named' ? registration.name : 'default',
17+
const uid = programParent.generateUidIdentifier(name);
18+
programParent.registerDeclaration(
19+
(programParent.path as babel.NodePath<t.Program>).unshiftContainer(
20+
'body',
21+
t.importDeclaration(
22+
[
23+
registration.kind === 'named'
24+
? t.importSpecifier(uid, t.identifier(registration.name))
25+
: t.importDefaultSpecifier(uid),
26+
],
27+
t.stringLiteral(registration.source),
28+
),
29+
)[0],
1930
);
20-
const newPath = (
21-
programParent.path as babel.NodePath<t.Program>
22-
).unshiftContainer(
23-
'body',
24-
t.importDeclaration(
25-
[
26-
registration.kind === 'named'
27-
? t.importSpecifier(uid, t.identifier(registration.name))
28-
: t.importDefaultSpecifier(uid),
29-
],
30-
t.stringLiteral(registration.source),
31-
),
32-
)[0];
33-
programParent.registerDeclaration(newPath);
3431
state.imports.set(target, uid);
3532
return uid;
3633
}

src/babel/core/transform-jsx.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ export function transformJSX(
300300
templateComp.loc = path.node.loc;
301301
}
302302

303-
const [tmp] = rootPath.insertBefore(
304-
t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]),
303+
rootPath.scope.registerDeclaration(
304+
rootPath.insertBefore(
305+
t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]),
306+
)[0],
305307
);
306308

307-
rootPath.scope.registerDeclaration(tmp);
308-
309309
path.replaceWith(
310310
skippableJSX(
311311
t.jsxElement(

src/babel/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,22 @@ function transformFunctionDeclaration(
268268
// have zero or one parameter
269269
decl.params.length < 2
270270
) {
271-
const [tmp] = path.replaceWith(
272-
t.variableDeclaration('const', [
273-
t.variableDeclarator(
274-
decl.id,
275-
wrapComponent(
276-
state,
277-
path,
271+
path.scope.registerDeclaration(
272+
path.replaceWith(
273+
t.variableDeclaration('const', [
274+
t.variableDeclarator(
278275
decl.id,
279-
t.functionExpression(decl.id, decl.params, decl.body),
280-
decl,
276+
wrapComponent(
277+
state,
278+
path,
279+
decl.id,
280+
t.functionExpression(decl.id, decl.params, decl.body),
281+
decl,
282+
),
281283
),
282-
),
283-
]),
284+
]),
285+
)[0],
284286
);
285-
path.scope.registerDeclaration(tmp);
286287
path.skip();
287288
}
288289
}
@@ -375,6 +376,9 @@ export default function solidRefreshPlugin(): babel.PluginObj<State> {
375376
transformFunctionDeclaration(state, path);
376377
},
377378
});
379+
// TODO anything simpler than this?
380+
// This is to fix an issue with webpack
381+
programPath.scope.crawl();
378382
},
379383
},
380384
};

0 commit comments

Comments
 (0)