@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/deno.json +1 -1
- package/dist/mod.cjs +25 -8
- package/dist/mod.d.cts +100 -100
- package/dist/mod.d.ts +100 -100
- package/dist/mod.js +25 -8
- package/package.json +1 -1
- package/src/__snapshots__/class.test.ts.deno.snap +858 -594
- package/src/__snapshots__/class.test.ts.node.snap +858 -594
- package/src/__snapshots__/class.test.ts.snap +858 -594
- package/src/class.ts +4 -1
- package/src/generate.ts +1 -1
- package/src/inspector.ts +26 -6
- package/tsdown.config.ts +1 -1
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
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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