Skip to content

Commit

Permalink
Remove @babel/helper-module-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Jan 27, 2024
1 parent 4e26227 commit ae790f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
26 changes: 18 additions & 8 deletions packages/solid-styled/compiler/core/get-import-identifier.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import type * as babel from '@babel/core';
import { addNamed } from '@babel/helper-module-imports';
import type * as t from '@babel/types';
import * as t from '@babel/types';
import type { StateContext } from '../types';

export default function getImportIdentifier(
ctx: StateContext,
export function getImportIdentifier(
state: StateContext,
path: babel.NodePath,
source: string,
name: string,
): t.Identifier {
const target = `${source}[${name}]`;
const current = ctx.hooks.get(target);
const current = state.hooks.get(target);
if (current) {
return current;
}
const newID = addNamed(path, name, source);
ctx.hooks.set(target, newID);
return newID;
const programParent = path.scope.getProgramParent();
const uid = programParent.generateUidIdentifier(name);
const newPath = (
programParent.path as babel.NodePath<t.Program>
).unshiftContainer(
'body',
t.importDeclaration(
[t.importSpecifier(uid, t.identifier(name))],
t.stringLiteral(source),
),
)[0];
programParent.registerDeclaration(newPath);
state.hooks.set(target, uid);
return uid;
}
2 changes: 1 addition & 1 deletion packages/solid-styled/compiler/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TAGGED_TEMPLATE,
VARS_ID,
} from './core/constants';
import getImportIdentifier from './core/get-import-identifier';
import { getImportIdentifier } from './core/get-import-identifier';
import { getImportSpecifierKey } from './core/checks';
import processCSSTemplate from './core/process-css-template';
import { getUniqueId, getPrefix } from './core/utils';
Expand Down
2 changes: 0 additions & 2 deletions packages/solid-styled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"license": "MIT",
"devDependencies": {
"@types/babel__core": "^7.20.5",
"@types/babel__helper-module-imports": "^7.18.3",
"@types/babel__traverse": "^7.20.5",
"@types/node": "^20.11.1",
"pridepack": "2.6.0",
Expand All @@ -46,7 +45,6 @@
},
"dependencies": {
"@babel/core": "^7.23.7",
"@babel/helper-module-imports": "^7.22.15",
"@babel/traverse": "^7.23.7",
"@babel/types": "^7.23.6",
"@types/css-tree": "^2.3.5",
Expand Down
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae790f2

Please sign in to comment.