Unverified Commit 38c67eb6 authored by Hong Minhee's avatar Hong Minhee
Browse files

Preparing for Deno 2.0

parent f8be416b
Loading
Loading
Loading
Loading
+855 −855

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import { generateFields } from "./field.ts";
import { generateInspector } from "./inspector.ts";
import { generateProperties } from "./property.ts";
import type { TypeSchema } from "./schema.ts";
import { emitOverride } from "./type.ts";

/**
 * Sorts the given types topologically so that the base types come before the
@@ -66,7 +67,7 @@ async function* generateClass(
    /**
     * The type URI of {@link ${type.name}}: \`${typeUri}\`.
     */
    static get typeId(): URL {
    static ${emitOverride(typeUri, types)} get typeId(): URL {
      return new URL(${JSON.stringify(typeUri)});
    }
  `;
+4 −3
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import { generateField, getFieldName } from "./field.ts";
import type { TypeSchema } from "./schema.ts";
import {
  areAllScalarTypes,
  emitOverride,
  getAllProperties,
  getDecoder,
  getDecoders,
@@ -26,7 +27,7 @@ export async function* generateEncoder(
                      when \`format\` is set to \`'expand'\`.
   * @returns The JSON-LD representation of this object.
   */
  async toJsonLd(options: {
  ${emitOverride(typeUri, types)} async toJsonLd(options: {
    format?: "compact" | "expand",
    contextLoader?: DocumentLoader,
    context?: string | Record<string, string> | (string | Record<string, string>)[],
@@ -240,7 +241,7 @@ export async function* generateEncoder(
    return compacted;
  }

  protected isCompactable(): boolean {
  protected ${emitOverride(typeUri, types)} isCompactable(): boolean {
`;
  for (const property of type.properties) {
    if (!property.range.every((r) => isCompactableType(r, types))) {
@@ -270,7 +271,7 @@ export async function* generateDecoder(
   * @returns The object of this type.
   * @throws {TypeError} If the given \`json\` is invalid.
   */
  static async fromJsonLd(
  static ${emitOverride(typeUri, types)} async fromJsonLd(
    json: unknown,
    options: {
      documentLoader?: DocumentLoader,
+7 −2
Original line number Diff line number Diff line
import { getFieldName } from "./field.ts";
import type { PropertySchema, TypeSchema } from "./schema.ts";
import { areAllScalarTypes, getTypeGuards, getTypeNames } from "./type.ts";
import {
  areAllScalarTypes,
  emitOverride,
  getTypeGuards,
  getTypeNames,
} from "./type.ts";

function generateParameterType(
  property: PropertySchema,
@@ -184,7 +189,7 @@ export async function* generateCloner(
   * @options The options to use for cloning.
   * @returns The cloned instance.
   */
  clone(
  ${emitOverride(typeUri, types)} clone(
    values:
  `;
  for await (const code of generateParametersType(typeUri, types)) yield code;
+6 −3
Original line number Diff line number Diff line
import { getFieldName } from "./field.ts";
import type { TypeSchema } from "./schema.ts";
import { emitOverride } from "./type.ts";

export async function* generateInspector(
  typeUri: string,
@@ -7,7 +8,9 @@ export async function* generateInspector(
): AsyncIterable<string> {
  const type = types[typeUri];
  yield `
  protected _getCustomInspectProxy(): Record<string, unknown> {
  protected ${
    emitOverride(typeUri, types)
  } _getCustomInspectProxy(): Record<string, unknown> {
  `;
  if (type.extends == null) {
    yield `
@@ -70,7 +73,7 @@ export async function* generateInspector(
    return proxy;
  }

  [Symbol.for("Deno.customInspect")](
  ${emitOverride(typeUri, types)} [Symbol.for("Deno.customInspect")](
    inspect: typeof Deno.inspect,
    options: Deno.InspectOptions,
  ): string {
@@ -78,7 +81,7 @@ export async function* generateInspector(
    return ${JSON.stringify(type.name + " ")} + inspect(proxy, options);
  }

  [Symbol.for("nodejs.util.inspect.custom")](
  ${emitOverride(typeUri, types)} [Symbol.for("nodejs.util.inspect.custom")](
    _depth: number,
    options: unknown,
    inspect: (value: unknown, options: unknown) => string,
Loading