diff --git a/apps/oxlint/src-js/plugins/context.ts b/apps/oxlint/src-js/plugins/context.ts index 55639187e935e..ce416797eccf2 100644 --- a/apps/oxlint/src-js/plugins/context.ts +++ b/apps/oxlint/src-js/plugins/context.ts @@ -36,7 +36,7 @@ import type { RuleAndContext } from './load.ts'; import type { SourceCode } from './source_code.ts'; import type { Location, Ranged } from './types.ts'; -const { hasOwn, keys: ObjectKeys, freeze } = Object; +const { hasOwn, keys: ObjectKeys, freeze, assign: ObjectAssign, create: ObjectCreate } = Object; // Diagnostic in form passed by user to `Context#report()` export type Diagnostic = DiagnosticWithNode | DiagnosticWithLoc; @@ -134,6 +134,17 @@ const FILE_CONTEXT = freeze({ if (settings === null) initSettings(); return settings; }, + + /** + * Create a new object with the current object as the prototype and + * the specified properties as its own properties. + * @param extension - The properties to add to the new object. + * @returns A new object with the current object as the prototype + * and the specified properties as its own properties. + */ + extend(this: FileContext, extension: Record): FileContext { + return freeze(ObjectAssign(ObjectCreate(this), extension)); + }, }); type FileContext = typeof FILE_CONTEXT;