Skip to content

Commit

Permalink
chore: import type
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiahao committed Apr 21, 2023
1 parent 602c25d commit e92ae69
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as recast from "recast";
import { proxifyFunctionCall } from "./proxy/function-call";
import { proxifyNewExpression } from "./proxy/new-expression";
import { literalToAst } from "./proxy/_utils";
import { Proxified } from "./types";
import type { Proxified } from "./types";
import { parseExpression } from "./code";

const b = recast.types.builders;
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTNode } from "./types";
import type { ASTNode } from "./types";

export interface MagicastErrorOptions {
ast?: ASTNode;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProxifiedModule } from "../types";
import type { ProxifiedModule } from "../types";

export function getDefaultExportOptions(magicast: ProxifiedModule<any>) {
return magicast.exports.default.$type === "function-call"
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/deep-merge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Proxified } from "../types";
import type { Proxified } from "../types";

export function deepMergeObject(magicast: Proxified<any>, object: any) {
if (typeof object === "object") {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/nuxt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProxifiedModule } from "../proxy/types";
import type { ProxifiedModule } from "../proxy/types";
import { getDefaultExportOptions } from "./config";
import { deepMergeObject } from "./deep-merge";

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/vite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ProxifiedFunctionCall, ProxifiedModule } from "../proxy/types";
import { builders } from "../builders";
import { ProxifiedFunctionCall, ProxifiedModule } from "../proxy/types";
import { getDefaultExportOptions } from "./config";
import { deepMergeObject } from "./deep-merge";

Expand Down
2 changes: 1 addition & 1 deletion src/proxy/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as recast from "recast";
import { MagicastError } from "../error";
import type { ASTNode } from "../types";
import { MagicastError } from "../error";

export const LITERALS_AST = new Set([
"Literal",
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/array.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ASTNode } from "../types";
import type { ASTNode } from "../types";
import type { ProxifiedArray, ProxifiedModule } from "./types";
import { literalToAst, createProxy } from "./_utils";
import { proxify } from "./proxify";
import { ProxifiedArray, ProxifiedModule } from "./types";

export function proxifyArrayElements<T extends any[]>(
node: ASTNode,
Expand Down
12 changes: 6 additions & 6 deletions src/proxy/exports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as recast from "recast";
import { Program } from "@babel/types";
import type { Program } from "@babel/types";
import type { ProxifiedModule } from "./types";
import { createProxy, literalToAst } from "./_utils";
import { proxify } from "./proxify";
import { ProxifiedModule } from "./types";

const b = recast.types.builders;

Expand Down Expand Up @@ -51,10 +51,10 @@ export function createExportsProxy(root: Program, mod: ProxifiedModule) {
key === "default"
? b.exportDefaultDeclaration(node)
: (b.exportNamedDeclaration(
b.variableDeclaration("const", [
b.variableDeclarator(b.identifier(key), node),
])
) as any)
b.variableDeclaration("const", [
b.variableDeclarator(b.identifier(key), node),
])
) as any)
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/proxy/function-call.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ASTNode } from "../types";
import type { ASTNode } from "../types";
import type { ProxifiedFunctionCall, ProxifiedModule } from "./types";
import { MagicastError } from "../error";
import { createProxy } from "./_utils";
import { proxifyArrayElements } from "./array";
import { ProxifiedFunctionCall, ProxifiedModule } from "./types";

export function proxifyFunctionCall<T extends []>(
node: ASTNode,
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/identifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTNode, ProxifiedIdentifier } from "../types";
import type { ASTNode, ProxifiedIdentifier } from "../types";
import { MagicastError } from "../error";
import { createProxy } from "./_utils";

Expand Down
12 changes: 6 additions & 6 deletions src/proxy/imports.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* eslint-disable unicorn/no-nested-ternary */
import * as recast from "recast";
import {
import type {
ImportDeclaration,
ImportDefaultSpecifier,
ImportNamespaceSpecifier,
ImportSpecifier,
Program,
} from "@babel/types";
import { MagicastError } from "../error";
import { createProxy } from "./_utils";
import {
import type {
ImportItemInput,
ProxifiedImportItem,
ProxifiedImportsMap,
ProxifiedModule,
} from "./types";
import { MagicastError } from "../error";
import { createProxy } from "./_utils";

const b = recast.types.builders;
const _importProxyCache = new WeakMap<any, ProxifiedImportItem>();
Expand Down Expand Up @@ -146,8 +146,8 @@ export function createImportsProxy(
value.imported === "default"
? b.importDefaultSpecifier(b.identifier(local))
: value.imported === "*"
? b.importNamespaceSpecifier(b.identifier(local))
: b.importSpecifier(b.identifier(value.imported), b.identifier(local));
? b.importNamespaceSpecifier(b.identifier(local))
: b.importSpecifier(b.identifier(value.imported), b.identifier(local));

const declaration = imports.find(
(i) => i.from === value.from
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable unicorn/no-nested-ternary */
import { ParsedFileNode } from "../types";
import type { ParsedFileNode } from "../types";
import type { ProxifiedModule } from "./types";
import { MagicastError } from "../error";
import { generateCode } from "../code";
import { ProxifiedModule } from "./types";
import { createImportsProxy } from "./imports";
import { createExportsProxy } from "./exports";
import { createProxy } from "./_utils";
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/new-expression.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ASTNode } from "../types";
import type { ASTNode } from "../types";
import type { ProxifiedModule, ProxifiedNewExpression } from "./types";
import { MagicastError } from "../error";
import { createProxy } from "./_utils";
import { proxifyArrayElements } from "./array";
import { ProxifiedModule, ProxifiedNewExpression } from "./types";

export function proxifyNewExpression<T extends []>(
node: ASTNode,
Expand Down
4 changes: 2 additions & 2 deletions src/proxy/object.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as recast from "recast";
import { ASTNode } from "../types";
import type { ASTNode } from "../types";
import type { ProxifiedModule, ProxifiedObject } from "./types";
import { MagicastError } from "../error";
import { literalToAst, createProxy, isValidPropName } from "./_utils";
import { proxify } from "./proxify";
import { ProxifiedModule, ProxifiedObject } from "./types";

const b = recast.types.builders;

Expand Down
4 changes: 2 additions & 2 deletions src/proxy/proxify.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Proxified, ProxifiedModule, ProxifiedValue } from "./types";
import type { ASTNode } from "../types";
import { MagicastError } from "../error";
import { ASTNode } from "../types";
import { proxifyArray } from "./array";
import { proxifyFunctionCall } from "./function-call";
import { proxifyObject } from "./object";
import { proxifyNewExpression } from "./new-expression";
import { proxifyIdentifier } from "./identifier";
import { Proxified, ProxifiedModule, ProxifiedValue } from "./types";
import { LITERALS_AST, LITERALS_TYPEOF } from "./_utils";

const _cache = new WeakMap<ASTNode, any>();
Expand Down
28 changes: 14 additions & 14 deletions src/proxy/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
import type {
ImportDeclaration,
ImportDefaultSpecifier,
ImportNamespaceSpecifier,
ImportSpecifier,
} from "@babel/types";
import { ASTNode, GenerateOptions } from "../types";
import type { ASTNode, GenerateOptions } from "../types";

export interface ProxyBase {
$ast: ASTNode;
Expand All @@ -13,8 +13,8 @@ export interface ProxyBase {
export type ProxifiedArray<T extends any[] = unknown[]> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
};
$type: "array";
};

export type ProxifiedFunctionCall<Args extends any[] = unknown[]> =
ProxyBase & {
Expand All @@ -33,8 +33,8 @@ export type ProxifiedNewExpression<Args extends any[] = unknown[]> =
export type ProxifiedObject<T extends object = object> = {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "object";
};
$type: "object";
};

export type ProxifiedIdentifier = ProxyBase & {
$type: "identifier";
Expand All @@ -52,16 +52,16 @@ export type Proxified<T = any> = T extends
? T
: T extends any[]
? {
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
}
[K in keyof T]: Proxified<T[K]>;
} & ProxyBase & {
$type: "array";
}
: T extends object
? ProxyBase & {
[K in keyof T]: Proxified<T[K]>;
} & {
$type: "object";
}
[K in keyof T]: Proxified<T[K]>;
} & {
$type: "object";
}
: T;

export type ProxifiedModule<T extends object = Record<string, any>> =
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Program } from "@babel/types";
import { Options as ParseOptions } from "recast";
import { CodeFormatOptions } from "./format";
export type { Node as ASTNode } from "@babel/types";

export type { Node as ASTNode } from "@babel/types";
export * from "./proxy/types";

export interface Loc {
Expand Down

0 comments on commit e92ae69

Please sign in to comment.