Skip to content

Commit ae790f2

Browse files
committed
Remove @babel/helper-module-imports
1 parent 4e26227 commit ae790f2

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import type * as babel from '@babel/core';
2-
import { addNamed } from '@babel/helper-module-imports';
3-
import type * as t from '@babel/types';
2+
import * as t from '@babel/types';
43
import type { StateContext } from '../types';
54

6-
export default function getImportIdentifier(
7-
ctx: StateContext,
5+
export function getImportIdentifier(
6+
state: StateContext,
87
path: babel.NodePath,
98
source: string,
109
name: string,
1110
): t.Identifier {
1211
const target = `${source}[${name}]`;
13-
const current = ctx.hooks.get(target);
12+
const current = state.hooks.get(target);
1413
if (current) {
1514
return current;
1615
}
17-
const newID = addNamed(path, name, source);
18-
ctx.hooks.set(target, newID);
19-
return newID;
16+
const programParent = path.scope.getProgramParent();
17+
const uid = programParent.generateUidIdentifier(name);
18+
const newPath = (
19+
programParent.path as babel.NodePath<t.Program>
20+
).unshiftContainer(
21+
'body',
22+
t.importDeclaration(
23+
[t.importSpecifier(uid, t.identifier(name))],
24+
t.stringLiteral(source),
25+
),
26+
)[0];
27+
programParent.registerDeclaration(newPath);
28+
state.hooks.set(target, uid);
29+
return uid;
2030
}

packages/solid-styled/compiler/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
TAGGED_TEMPLATE,
1111
VARS_ID,
1212
} from './core/constants';
13-
import getImportIdentifier from './core/get-import-identifier';
13+
import { getImportIdentifier } from './core/get-import-identifier';
1414
import { getImportSpecifierKey } from './core/checks';
1515
import processCSSTemplate from './core/process-css-template';
1616
import { getUniqueId, getPrefix } from './core/utils';

packages/solid-styled/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"license": "MIT",
3333
"devDependencies": {
3434
"@types/babel__core": "^7.20.5",
35-
"@types/babel__helper-module-imports": "^7.18.3",
3635
"@types/babel__traverse": "^7.20.5",
3736
"@types/node": "^20.11.1",
3837
"pridepack": "2.6.0",
@@ -46,7 +45,6 @@
4645
},
4746
"dependencies": {
4847
"@babel/core": "^7.23.7",
49-
"@babel/helper-module-imports": "^7.22.15",
5048
"@babel/traverse": "^7.23.7",
5149
"@babel/types": "^7.23.6",
5250
"@types/css-tree": "^2.3.5",

pnpm-lock.yaml

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)