@thyn/vite-plugin 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export declare function extractImportTokens(imports: any): Set<string>;
@@ -0,0 +1,37 @@
1
+ import * as acorn from "acorn";
2
+ export function extractImportTokens(imports) {
3
+ const tokens = new Set();
4
+ for (const importStatement of imports) {
5
+ try {
6
+ // Parse the import statement as a statement, not expression
7
+ const ast = acorn.parse(importStatement, {
8
+ ecmaVersion: 2022,
9
+ sourceType: "module",
10
+ });
11
+ // Get the import declaration (first statement in the parsed AST)
12
+ const importDecl = ast.body[0];
13
+ if (importDecl.type === "ImportDeclaration") {
14
+ // Process each specifier in the import
15
+ for (const specifier of importDecl.specifiers) {
16
+ if (specifier.type === "ImportSpecifier") {
17
+ // For named imports like { foo } or { bar as baz }
18
+ // Use the local name (what it's imported as)
19
+ tokens.add(specifier.local.name);
20
+ }
21
+ else if (specifier.type === "ImportDefaultSpecifier") {
22
+ // For default imports like import foo from './file'
23
+ tokens.add(specifier.local.name);
24
+ }
25
+ else if (specifier.type === "ImportNamespaceSpecifier") {
26
+ // For namespace imports like import * as foo from './file'
27
+ tokens.add(specifier.local.name);
28
+ }
29
+ }
30
+ }
31
+ }
32
+ catch (error) {
33
+ console.warn(`Failed to parse import: ${importStatement}`, error);
34
+ }
35
+ }
36
+ return tokens;
37
+ }
@@ -0,0 +1,24 @@
1
+ export declare function transformSFC(source: string, id: string): {
2
+ output: string;
3
+ sourceMap: import("magic-string").SourceMap;
4
+ scopedStyle: any;
5
+ scriptLang: string;
6
+ };
7
+ export declare function compileSFC(source: string, id: string): Promise<{
8
+ js: string;
9
+ css: any;
10
+ cssModuleId: string;
11
+ map: import("magic-string").SourceMap;
12
+ }>;
13
+ export default function thyn(): {
14
+ name: string;
15
+ enforce: string;
16
+ configResolved(config: any): void;
17
+ buildStart(): void;
18
+ transform(code: any, id: any): Promise<{
19
+ code: string;
20
+ map: import("magic-string").SourceMap;
21
+ }>;
22
+ transformIndexHtml(html: any): any;
23
+ generateBundle(): Promise<void>;
24
+ };