From 7f84bf5029a2a224fdd64fbf1169ba949fc80c51 Mon Sep 17 00:00:00 2001 From: Severin Ibarluzea Date: Tue, 2 Dec 2025 10:47:09 -0800 Subject: [PATCH] Add tslib to pre-supplied imports --- lib/eval/execution-context.ts | 2 ++ package.json | 1 + tests/features/presupplied-imports.test.ts | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/features/presupplied-imports.test.ts diff --git a/lib/eval/execution-context.ts b/lib/eval/execution-context.ts index 0c1e3b59..812c99af 100644 --- a/lib/eval/execution-context.ts +++ b/lib/eval/execution-context.ts @@ -7,6 +7,7 @@ import * as tscircuitMathUtils from "@tscircuit/math-utils" import type { PlatformConfig } from "@tscircuit/props" import { getPlatformConfig } from "lib/getPlatformConfig" import type { TsConfig } from "lib/runner/tsconfigPaths" +import * as tslib from "tslib" import Debug from "debug" const debug = Debug("tsci:eval:execution-context") @@ -79,6 +80,7 @@ export function createExecutionContext( react: React, "react/jsx-runtime": ReactJsxRuntime, debug: Debug, + tslib, // This is usually used as a type import, we can remove the shim when we // ignore type imports in getImportsFromCode diff --git a/package.json b/package.json index bdd6680f..454478de 100644 --- a/package.json +++ b/package.json @@ -121,6 +121,7 @@ "sucrase": "^3.35.0", "ts-expect": "^1.3.0", "tsup": "^8.2.4", + "tslib": "^2.8.1", "@tscircuit/common": "^0.0.20", "@tscircuit/copper-pour-solver": "^0.0.14" }, diff --git a/tests/features/presupplied-imports.test.ts b/tests/features/presupplied-imports.test.ts new file mode 100644 index 00000000..e9e269ad --- /dev/null +++ b/tests/features/presupplied-imports.test.ts @@ -0,0 +1,18 @@ +import { expect, test } from "bun:test" +import { CircuitRunner } from "lib/runner/CircuitRunner" + +test("tslib is added to pre-supplied imports", async () => { + const runner = new CircuitRunner() + + await runner.execute(` + import { __assign } from "tslib" + + const dimensions = __assign({ width: "10mm" }, { height: "10mm" }) + + circuit.add() + `) + + await runner.renderUntilSettled() + + expect(runner._executionContext?.preSuppliedImports.tslib).toBeDefined() +})