@fedify/vocab-tools 2.1.0-dev.405 → 2.1.0-dev.406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/class.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { generateDecoder, generateEncoder } from "./codec.ts";
2
2
  import { generateCloner, generateConstructor } from "./constructor.ts";
3
3
  import { generateFields } from "./field.ts";
4
- import { generateInspector } from "./inspector.ts";
4
+ import { generateInspector, generateInspectorPostClass } from "./inspector.ts";
5
5
  import { generateProperties } from "./property.ts";
6
6
  import type { TypeSchema } from "./schema.ts";
7
7
  import { emitOverride } from "./type.ts";
@@ -104,6 +104,9 @@ async function* generateClass(
104
104
  for await (const code of generateDecoder(typeUri, types)) yield code;
105
105
  for await (const code of generateInspector(typeUri, types)) yield code;
106
106
  yield "}\n\n";
107
+ for await (const code of generateInspectorPostClass(typeUri, types)) {
108
+ yield code;
109
+ }
107
110
  }
108
111
 
109
112
  /**
package/src/generate.ts CHANGED
@@ -5,7 +5,7 @@ import { loadSchemaFiles } from "./schema.ts";
5
5
  export default async function generateVocab(
6
6
  schemaDir: string,
7
7
  generatedPath: string,
8
- ) {
8
+ ): Promise<void> {
9
9
  const types = await loadSchemaFiles(schemaDir);
10
10
  const encoder = new TextEncoder();
11
11
 
package/src/inspector.ts CHANGED
@@ -73,24 +73,44 @@ export async function* generateInspector(
73
73
  yield `
74
74
  return proxy;
75
75
  }
76
+ `;
77
+ }
76
78
 
77
- // @ts-ignore: suppressing TS4127
78
- ${emitOverride(typeUri, types)} [Symbol.for("Deno.customInspect")](
79
+ /**
80
+ * Generates code that must appear *after* the class closing brace: prototype
81
+ * assignments for the Deno and Node.js custom-inspect hooks.
82
+ *
83
+ * These are emitted outside the class body because computed property names
84
+ * using `Symbol.for()` are incompatible with `isolatedDeclarations` mode.
85
+ */
86
+ export async function* generateInspectorPostClass(
87
+ typeUri: string,
88
+ types: Record<string, TypeSchema>,
89
+ ): AsyncIterable<string> {
90
+ const type = types[typeUri];
91
+ const className = type.name;
92
+ yield `
93
+ // deno-lint-ignore no-explicit-any
94
+ (${className}.prototype as any)[Symbol.for("Deno.customInspect")] =
95
+ function (
96
+ this: ${className},
79
97
  inspect: typeof Deno.inspect,
80
98
  options: Deno.InspectOptions,
81
99
  ): string {
82
100
  const proxy = this._getCustomInspectProxy();
83
101
  return ${JSON.stringify(type.name + " ")} + inspect(proxy, options);
84
- }
102
+ };
85
103
 
86
- // @ts-ignore: suppressing TS4127
87
- ${emitOverride(typeUri, types)} [Symbol.for("nodejs.util.inspect.custom")](
104
+ // deno-lint-ignore no-explicit-any
105
+ (${className}.prototype as any)[Symbol.for("nodejs.util.inspect.custom")] =
106
+ function (
107
+ this: ${className},
88
108
  _depth: number,
89
109
  options: unknown,
90
110
  inspect: (value: unknown, options: unknown) => string,
91
111
  ): string {
92
112
  const proxy = this._getCustomInspectProxy();
93
113
  return ${JSON.stringify(type.name + " ")} + inspect(proxy, options);
94
- }
114
+ };
95
115
  `;
96
116
  }
package/tsdown.config.ts CHANGED
@@ -4,7 +4,7 @@ import { defineConfig } from "tsdown";
4
4
 
5
5
  export default defineConfig({
6
6
  entry: ["src/mod.ts"],
7
- dts: true,
7
+ dts: { compilerOptions: { isolatedDeclarations: true, declaration: true } },
8
8
  format: ["esm", "cjs"],
9
9
  platform: "neutral",
10
10
  external: [/^node:/],