Skip to content

Commit

Permalink
Fix binding check for constant folding
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Mar 12, 2024
1 parent 385a0e0 commit 9f7ea33
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/forgetti/src/core/inline-expressions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as babel from '@babel/core';
import * as t from '@babel/types';
import { isPathValid } from './utils/checks';
import type { ComponentNode } from './types';
import { isPathValid } from './utils/checks';

function isInValidExpression(path: babel.NodePath): boolean {
let current = path.parentPath;
Expand Down Expand Up @@ -35,7 +35,11 @@ function inlineExpression(
isPathValid(path, t.isIdentifier)
) {
const binding = path.scope.getBinding(path.node.name);
if (binding?.referenced && binding.referencePaths.length === 1) {
if (!binding) {
return;
}
const total = binding.references + binding.constantViolations.length;
if (total === 1) {
switch (binding.kind) {
case 'const':
case 'let':
Expand Down

0 comments on commit 9f7ea33

Please sign in to comment.