Skip to content

Commit

Permalink
fix(babel): broken detection of identifier declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Sep 11, 2023
1 parent 521d6c8 commit 2438ed3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import { join } from 'path';
import * as babel from '@babel/core';
import type { NodePath } from '@babel/core';
import generator from '@babel/generator';
import type { File as FileNode } from '@babel/types';
import dedent from 'dedent';

import type { MissedBabelCoreTypes } from '@linaria/babel-preset';
import { removeWithRelated } from '@linaria/utils';
import { removeWithRelated } from '../scopeHelpers';

type MissedBabelCoreTypes = {
File: new (
options: { filename: string },
file: { ast: FileNode; code: string }
) => { path: NodePath<FileNode> };
};

const { File } = babel as typeof babel & MissedBabelCoreTypes;

Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/findIdentifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const checkers: Record<
any: (ex) => isBindingIdentifier(ex) || isReferencedIdentifier(ex),
binding: (ex) => isBindingIdentifier(ex),
declaration: (ex) =>
isBindingIdentifier(ex) && ex.scope.getBinding(ex.node.name)?.path === ex,
isBindingIdentifier(ex) &&
ex.scope.getBinding(ex.node.name)?.identifier === ex.node,
reference: (ex) => isReferencedIdentifier(ex),
};

Expand Down

0 comments on commit 2438ed3

Please sign in to comment.