Skip to content

Commit

Permalink
Update typescript to 5.7 (solidjs#2382)
Browse files Browse the repository at this point in the history
* Update typescript to 5.7

* Create many-crabs-reply.md

---------

Co-authored-by: Ryan Carniato <[email protected]>
  • Loading branch information
thetarnav and ryansolid authored Jan 8, 2025
1 parent 9316baf commit fff8aed
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-crabs-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

Update typescript to 5.7
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"symlink-dir": "^5.0.1",
"tsconfig-replace-paths": "^0.0.11",
"turbo": "^1.3.1",
"typescript": "~5.5.2",
"typescript": "~5.7.2",
"vite-plugin-solid": "^2.6.1",
"vitest": "^2.1.2"
},
Expand Down
8 changes: 3 additions & 5 deletions packages/solid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ type JSXElement = JSX.Element;
export type { JSXElement, JSX };

// dev
import { registerGraph, writeSignal, DevHooks } from "./reactive/signal.js";
export const DEV = "_SOLID_DEV_"
? ({ hooks: DevHooks, writeSignal, registerGraph } as const)
: undefined;
import { registerGraph, writeSignal, DevHooks, IS_DEV } from "./reactive/signal.js";
export const DEV = IS_DEV ? ({ hooks: DevHooks, writeSignal, registerGraph } as const) : undefined;

// handle multiple instance check
declare global {
var Solid$$: boolean;
}

if ("_SOLID_DEV_" && globalThis) {
if (IS_DEV && globalThis) {
if (!globalThis.Solid$$) globalThis.Solid$$ = true;
else
console.warn(
Expand Down
7 changes: 4 additions & 3 deletions packages/solid/src/reactive/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
createSignal,
Accessor,
Setter,
$TRACK
$TRACK,
IS_DEV
} from "./signal.js";

const FALLBACK = Symbol("fallback");
Expand Down Expand Up @@ -166,7 +167,7 @@ export function mapArray<T, U>(
function mapper(disposer: () => void) {
disposers[j] = disposer;
if (indexes) {
const [s, set] = "_SOLID_DEV_" ? createSignal(j, { name: "index" }) : createSignal(j);
const [s, set] = IS_DEV ? createSignal(j, { name: "index" }) : createSignal(j);
indexes[j] = set;
return mapFn(newItems[j], s);
}
Expand Down Expand Up @@ -243,7 +244,7 @@ export function indexArray<T, U>(
});
function mapper(disposer: () => void) {
disposers[i] = disposer;
const [s, set] = "_SOLID_DEV_"
const [s, set] = IS_DEV
? createSignal(newItems[i], { name: "value" })
: createSignal(newItems[i]);
signals[i] = set;
Expand Down
53 changes: 27 additions & 26 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { setHydrateContext, sharedConfig } from "../render/hydration.js";
import type { JSX } from "../jsx.js";
import type { FlowComponent, FlowProps } from "../render/index.js";

// replaced during build
export const IS_DEV = "_SOLID_DEV_" as string | boolean;

export const equalFn = <T>(a: T, b: T) => a === b;
export const $PROXY = Symbol("solid-proxy");
export const SUPPORTS_PROXY = typeof Proxy === "function";
Expand Down Expand Up @@ -145,7 +148,7 @@ export function createRoot<T>(fn: RootFunction<T>, detachedOwner?: typeof Owner)
unowned = fn.length === 0,
current = detachedOwner === undefined ? owner : detachedOwner,
root: Owner = unowned
? "_SOLID_DEV_"
? IS_DEV
? { owned: null, cleanups: null, context: null, owner: null }
: UNOWNED
: {
Expand All @@ -155,15 +158,15 @@ export function createRoot<T>(fn: RootFunction<T>, detachedOwner?: typeof Owner)
owner: current
},
updateFn = unowned
? "_SOLID_DEV_"
? IS_DEV
? () =>
fn(() => {
throw new Error("Dispose method must be an explicit argument to createRoot function");
})
: fn
: () => fn(() => untrack(() => cleanNode(root)));

if ("_SOLID_DEV_") DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(root);
if (IS_DEV) DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(root);

Owner = root;
Listener = null;
Expand Down Expand Up @@ -231,7 +234,7 @@ export function createSignal<T>(
comparator: options.equals || undefined
};

if ("_SOLID_DEV_") {
if (IS_DEV) {
if (options.name) s.name = options.name;
if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s);
if (!options.internal) registerGraph(s);
Expand Down Expand Up @@ -288,7 +291,7 @@ export function createComputed<Next, Init>(
value?: Init,
options?: EffectOptions
): void {
const c = createComputation(fn, value!, true, STALE, "_SOLID_DEV_" ? options : undefined);
const c = createComputation(fn, value!, true, STALE, IS_DEV ? options : undefined);
if (Scheduler && Transition && Transition.running) Updates!.push(c);
else updateComputation(c);
}
Expand Down Expand Up @@ -319,7 +322,7 @@ export function createRenderEffect<Next, Init>(
value?: Init,
options?: EffectOptions
): void {
const c = createComputation(fn, value!, false, STALE, "_SOLID_DEV_" ? options : undefined);
const c = createComputation(fn, value!, false, STALE, IS_DEV ? options : undefined);
if (Scheduler && Transition && Transition.running) Updates!.push(c);
else updateComputation(c);
}
Expand Down Expand Up @@ -351,7 +354,7 @@ export function createEffect<Next, Init>(
options?: EffectOptions & { render?: boolean }
): void {
runEffects = runUserEffects;
const c = createComputation(fn, value!, false, STALE, "_SOLID_DEV_" ? options : undefined),
const c = createComputation(fn, value!, false, STALE, IS_DEV ? options : undefined),
s = SuspenseContext && useContext(SuspenseContext);
if (s) c.suspense = s;
if (!options || !options.render) c.user = true;
Expand Down Expand Up @@ -381,7 +384,7 @@ export function createReaction(onInvalidate: () => void, options?: EffectOptions
undefined,
false,
0,
"_SOLID_DEV_" ? options : undefined
IS_DEV ? options : undefined
),
s = SuspenseContext && useContext(SuspenseContext);
if (s) c.suspense = s;
Expand Down Expand Up @@ -439,7 +442,7 @@ export function createMemo<Next extends Prev, Init, Prev>(
value!,
true,
0,
"_SOLID_DEV_" ? options : undefined
IS_DEV ? options : undefined
) as Partial<Memo<Init, Next>>;

c.observers = null;
Expand Down Expand Up @@ -829,7 +832,7 @@ export function createSelector<T, U = T>(
undefined,
true,
STALE,
"_SOLID_DEV_" ? options : undefined
IS_DEV ? options : undefined
) as Memo<any>;
updateComputation(node);
return (key: U) => {
Expand All @@ -839,8 +842,8 @@ export function createSelector<T, U = T>(
if ((l = subs.get(key))) l.add(listener);
else subs.set(key, (l = new Set([listener])));
onCleanup(() => {
l!.delete(listener!);
!l!.size && subs.delete(key);
l.delete(listener);
!l.size && subs.delete(key);
});
}
return fn(
Expand Down Expand Up @@ -982,8 +985,7 @@ export function onMount(fn: () => void) {
*/
export function onCleanup<T extends () => any>(fn: T): T {
if (Owner === null)
"_SOLID_DEV_" &&
console.warn("cleanups created outside a `createRoot` or `render` will never be run");
IS_DEV && console.warn("cleanups created outside a `createRoot` or `render` will never be run");
else if (Owner.cleanups === null) Owner.cleanups = [fn];
else Owner.cleanups.push(fn);
return fn;
Expand Down Expand Up @@ -1207,7 +1209,7 @@ export type ChildrenReturn = Accessor<ResolvedChildren> & { toArray: () => Resol
*/
export function children(fn: Accessor<JSX.Element>): ChildrenReturn {
const children = createMemo(fn);
const memo = "_SOLID_DEV_"
const memo = IS_DEV
? createMemo(() => resolveChildren(children()), undefined, { name: "children" })
: createMemo(() => resolveChildren(children()));
(memo as ChildrenReturn).toArray = () => {
Expand Down Expand Up @@ -1329,7 +1331,7 @@ export function writeSignal(node: SignalState<any> | Memo<any>, value: any, isCo
}
if (Updates!.length > 10e5) {
Updates = [];
if ("_SOLID_DEV_") throw new Error("Potential Infinite Loop Detected.");
if (IS_DEV) throw new Error("Potential Infinite Loop Detected.");
throw new Error();
}
}, false);
Expand Down Expand Up @@ -1426,7 +1428,7 @@ function createComputation<Next, Init = unknown>(
}

if (Owner === null)
"_SOLID_DEV_" &&
IS_DEV &&
console.warn(
"computations created outside a `createRoot` or `render` will never be disposed"
);
Expand All @@ -1440,7 +1442,7 @@ function createComputation<Next, Init = unknown>(
}
}

if ("_SOLID_DEV_" && options && options.name) c.name = options.name;
if (IS_DEV && options && options.name) c.name = options.name;

if (ExternalSourceConfig && c.fn) {
const [track, trigger] = createSignal<void>(undefined, { equals: false });
Expand All @@ -1455,7 +1457,7 @@ function createComputation<Next, Init = unknown>(
};
}

if ("_SOLID_DEV_") DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(c);
if (IS_DEV) DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(c);

return c;
}
Expand All @@ -1464,8 +1466,7 @@ function runTop(node: Computation<any>) {
const runningTransition = Transition && Transition.running;
if ((runningTransition ? node.tState : node.state) === 0) return;
if ((runningTransition ? node.tState : node.state) === PENDING) return lookUpstream(node);
if (node.suspense && untrack(node.suspense.inFallback!))
return node!.suspense.effects!.push(node!);
if (node.suspense && untrack(node.suspense.inFallback!)) return node.suspense.effects!.push(node);
const ancestors = [node];
while (
(node = node.owner as Computation<any>) &&
Expand Down Expand Up @@ -1557,8 +1558,8 @@ function completeUpdates(wait: boolean) {
}
const e = Effects!;
Effects = null;
if (e!.length) runUpdates(() => runEffects(e), false);
else if ("_SOLID_DEV_") DevHooks.afterUpdate && DevHooks.afterUpdate();
if (e.length) runUpdates(() => runEffects(e), false);
else if (IS_DEV) DevHooks.afterUpdate && DevHooks.afterUpdate();
if (res) res();
}

Expand Down Expand Up @@ -1675,7 +1676,7 @@ function cleanNode(node: Owner) {
}
if (Transition && Transition.running) (node as Computation<any>).tState = 0;
else (node as Computation<any>).state = 0;
"_SOLID_DEV_" && delete node.sourceMap;
IS_DEV && delete node.sourceMap;
}

function reset(node: Computation<any>, top?: boolean) {
Expand Down Expand Up @@ -1707,7 +1708,7 @@ function handleError(err: unknown, owner = Owner) {
if (!fns) throw error;

if (Effects)
Effects!.push({
Effects.push({
fn() {
runErrors(error, fns, owner);
},
Expand Down Expand Up @@ -1759,7 +1760,7 @@ type TODO = any;
export function onError(fn: (err: Error) => void): void {
ERROR || (ERROR = Symbol("error"));
if (Owner === null)
"_SOLID_DEV_" &&
IS_DEV &&
console.warn("error handlers created outside a `createRoot` or `render` will never be run");
else if (Owner.context === null || !Owner.context[ERROR]) {
// terrible de-opt
Expand Down
9 changes: 5 additions & 4 deletions packages/solid/src/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
$PROXY,
SUPPORTS_PROXY,
$DEVCOMP,
EffectFunction
EffectFunction,
IS_DEV
} from "../reactive/signal.js";
import { sharedConfig, nextHydrateContext, setHydrateContext } from "./hydration.js";
import type { JSX } from "../jsx.js";
Expand Down Expand Up @@ -99,14 +100,14 @@ export function createComponent<T extends Record<string, any>>(
if (sharedConfig.context) {
const c = sharedConfig.context;
setHydrateContext(nextHydrateContext());
const r = "_SOLID_DEV_"
const r = IS_DEV
? devComponent(Comp, props || ({} as T))
: untrack(() => Comp(props || ({} as T)));
setHydrateContext(c);
return r;
}
}
if ("_SOLID_DEV_") return devComponent(Comp, props || ({} as T));
if (IS_DEV) return devComponent(Comp, props || ({} as T));
return untrack(() => Comp(props || ({} as T)));
}

Expand Down Expand Up @@ -376,7 +377,7 @@ export function lazy<T extends Component<any>>(
return createMemo(() =>
(Comp = comp())
? untrack(() => {
if ("_SOLID_DEV_") Object.assign(Comp!, { [$DEVCOMP]: true });
if (IS_DEV) Object.assign(Comp!, { [$DEVCOMP]: true });
if (!ctx || sharedConfig.done) return Comp!(props);
const c = sharedConfig.context;
setHydrateContext(ctx);
Expand Down
Loading

0 comments on commit fff8aed

Please sign in to comment.