Skip to content

Commit ba5a49d

Browse files
committed
Make function bubbling phase to be general
1 parent 211f29d commit ba5a49d

2 files changed

Lines changed: 4 additions & 23 deletions

File tree

packages/start/src/directives/plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function traceBinding(path: babel.NodePath, name: string): Binding | undefined {
149149
}
150150

151151
// Only valid for functions
152-
const func = unwrapPath(current.path.get('init'), isValidFunction);
152+
const func = unwrapPath(current.path.get("init"), isValidFunction);
153153
if (func) {
154154
return current;
155155
}
@@ -361,9 +361,9 @@ export function directivesPlugin(): babel.PluginObj<State> {
361361
// First, bubble up function declarations
362362
program.traverse({
363363
FunctionDeclaration(child) {
364-
if (isFunctionDirectiveValid(ctx.opts, child)) {
365-
bubbleFunctionDeclaration(child);
366-
}
364+
// if (isFunctionDirectiveValid(ctx.opts, child)) {
365+
bubbleFunctionDeclaration(child);
366+
// }
367367
},
368368
});
369369
program.scope.crawl();

packages/start/src/directives/remove-unused-variables.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type * as babel from "@babel/core";
22
import * as t from "@babel/types";
3-
import { generateUniqueName } from "./generate-unique-name.ts";
43
import { isPathValid } from "./paths.ts";
54

65
export function removeUnusedVariables(program: babel.NodePath<t.Program>) {
@@ -32,24 +31,6 @@ export function removeUnusedVariables(program: babel.NodePath<t.Program>) {
3231
} else {
3332
binding.path.remove();
3433
}
35-
36-
/**
37-
* TODO (Alexis):
38-
* For some reason, we can't directly remove function declarations,
39-
* Babel yields an error that is entirely on its fault.
40-
*
41-
* For now, we replace this with an unused variable and that variable
42-
* will then get removed on the next cycle.
43-
*
44-
* (Although weirdly enough, this should've been a variable
45-
* in the first phase during the earlier function bubbling phase)
46-
*/
47-
} else if (binding.kind === 'hoisted') {
48-
binding.path.replaceWith(
49-
t.variableDeclaration("const", [
50-
t.variableDeclarator(generateUniqueName(binding.path, "var")),
51-
]),
52-
);
5334
} else {
5435
binding.path.remove();
5536
}

0 commit comments

Comments
 (0)