Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: mark all symbol inits as pure to allow treeshake #469

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/runtime/node/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ export const getUnpackedSettings: typeof nodeHttp2.getUnpackedSettings =
return Object.create({});
};

export const sensitiveHeaders: typeof nodeHttp2.sensitiveHeaders = Symbol(
"nodejs.http2.sensitiveHeaders",
);
export const sensitiveHeaders: typeof nodeHttp2.sensitiveHeaders =
/*@__PURE__*/ Symbol("nodejs.http2.sensitiveHeaders");

export default {
constants,
Expand Down
16 changes: 11 additions & 5 deletions src/runtime/node/internal/async_hooks/async-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import type nodeAsyncHooks from "node:async_hooks";

type NodeAsyncHook = ReturnType<typeof nodeAsyncHooks.createHook>;

const kInit = /*@__PURE__*/ Symbol("init");
const kBefore = /*@__PURE__*/ Symbol("before");
const kAfter = /*@__PURE__*/ Symbol("after");
const kDestroy = /*@__PURE__*/ Symbol("destroy");
const kPromiseResolve = /*@__PURE__*/ Symbol("promiseResolve");

class _AsyncHook implements NodeAsyncHook {
readonly __unenv__ = true;

Expand All @@ -24,23 +30,23 @@ class _AsyncHook implements NodeAsyncHook {
return this;
}

get [Symbol("init")]() {
get [kInit]() {
return this._callbacks.init;
}

get [Symbol("before")]() {
get [kBefore]() {
return this._callbacks.before;
}

get [Symbol("after")]() {
get [kAfter]() {
return this._callbacks.after;
}

get [Symbol("destroy")]() {
get [kDestroy]() {
return this._callbacks.destroy;
}

get [Symbol("promiseResolve")]() {
get [kPromiseResolve]() {
return this._callbacks.promiseResolve;
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/runtime/node/internal/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,24 @@ const AbortError = Error;
const genericNodeError = Error;

// Symbols
const kRejection = Symbol.for("nodejs.rejection");
const kCapture = Symbol.for("kCapture");
const kErrorMonitor = Symbol.for("events.errorMonitor");
const kShapeMode = Symbol.for("shapeMode");
const kMaxEventTargetListeners = Symbol.for("events.maxEventTargetListeners");
const kEnhanceStackBeforeInspector = Symbol.for("kEnhanceStackBeforeInspector");
const kWatermarkData = Symbol.for("nodejs.watermarkData");
const kEventEmitter = Symbol.for("kEventEmitter");
const kAsyncResource = Symbol.for("kAsyncResource");
const kFirstEventParam = Symbol.for("kFirstEventParam");
const kResistStopPropagation = Symbol.for("kResistStopPropagation");
const kMaxEventTargetListenersWarned = Symbol.for(
const kRejection = /*@__PURE__*/ Symbol.for("nodejs.rejection");
const kCapture = /*@__PURE__*/ Symbol.for("kCapture");
const kErrorMonitor = /*@__PURE__*/ Symbol.for("events.errorMonitor");
const kShapeMode = /*@__PURE__*/ Symbol.for("shapeMode");
const kMaxEventTargetListeners = /*@__PURE__*/ Symbol.for(
"events.maxEventTargetListeners",
);
const kEnhanceStackBeforeInspector = /*@__PURE__*/ Symbol.for(
"kEnhanceStackBeforeInspector",
);
const kWatermarkData = /*@__PURE__*/ Symbol.for("nodejs.watermarkData");
const kEventEmitter = /*@__PURE__*/ Symbol.for("kEventEmitter");
const kAsyncResource = /*@__PURE__*/ Symbol.for("kAsyncResource");
const kFirstEventParam = /*@__PURE__*/ Symbol.for("kFirstEventParam");
const kResistStopPropagation = /*@__PURE__*/ Symbol.for(
"kResistStopPropagation",
);
const kMaxEventTargetListenersWarned = /*@__PURE__*/ Symbol.for(
"events.maxEventTargetListenersWarned",
);

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export * as constants from "./internal/vm/constants.ts";
export const compileFunction: typeof nodeVm.compileFunction =
/*@__PURE__*/ notImplemented("vm.compileFunction");

const _contextSymbol = Symbol("uenv.vm.context");
const _contextSymbol = /*@__PURE__*/ Symbol("uenv.vm.context");

export const createContext: typeof nodeVm.createContext =
function createContext() {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/worker_threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const parentPort: typeof nodeWorkerThreads.parentPort = null;
export const receiveMessageOnPort: typeof nodeWorkerThreads.receiveMessageOnPort =
() => undefined;

export const SHARE_ENV = Symbol.for(
export const SHARE_ENV = /*@__PURE__*/ Symbol.for(
"nodejs.worker_threads.SHARE_ENV",
) as typeof nodeWorkerThreads.SHARE_ENV;

Expand Down