Skip to content

Commit

Permalink
Update evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
horita-yuya committed Nov 20, 2024
1 parent 008892a commit 6f9138a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 15 additions & 1 deletion compute-type-value/evaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "node:fs";
import { describe, expect, it } from "vitest";
import { evaluate } from "./evaluate";

describe("evaluate type", () => {
describe("evaluate type .ts", () => {
it("standard", () => {
const type = `
export type Handler = 1;
Expand Down Expand Up @@ -46,3 +46,17 @@ describe("evaluate type", () => {
expect(r2).toBe(1);
});
});

describe("evaluate type .d.ts", () => {
it("standard", () => {
const type = `
export type Handler = 1;
`.trim();
const fileName = `/tmp/${randomUUID()}.d.ts`;
fs.writeFileSync(fileName, type);

const result = evaluate(fileName, "Handler", {});

expect(result).toBe(1);
});
});
6 changes: 1 addition & 5 deletions compute-type-value/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ import {
type LiteralType,
ModuleKind,
NewLineKind,
NodeBuilderFlags,
NodeFlags,
type PseudoBigInt,
ScriptTarget,
SyntaxKind,
TypeFormatFlags,
createCompilerHost,
createPrinter,
createProgram,
createSourceFile,
factory,
isLiteralTypeNode,
isTypeAliasDeclaration,
} from "typescript";

Expand Down Expand Up @@ -43,7 +39,7 @@ function createMain(
),
]),
),
factory.createStringLiteral(entryFile),
factory.createStringLiteral(entryFile.replace(/\.[^/.]+$/, "")),
),
factory.createTypeAliasDeclaration(
undefined,
Expand Down
2 changes: 1 addition & 1 deletion compute-type-value/sampleIndex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Sum } from "./sampleSum";
import type { Sum } from "./sampleSum.d.ts";

type Event = {
n1: number;
Expand Down

0 comments on commit 6f9138a

Please sign in to comment.