@defold-typescript/types 0.40.0 → 0.42.0
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/api-availability.json +3963 -772
- package/api-migrations.json +27 -0
- package/api-signatures.json +18069 -10240
- package/api-targets.json +448 -11
- package/examples/translations.json +560 -89
- package/fixtures/messages_doc.json +96 -0
- package/generated/b2d.d.ts +680 -4
- package/generated/b2d_body.d.ts +29 -103
- package/generated/b2d_chain.d.ts +5 -6
- package/generated/b2d_fixture.d.ts +34 -38
- package/generated/b2d_joint.d.ts +503 -25
- package/generated/b2d_shape.d.ts +183 -20
- package/generated/b2d_world.d.ts +57 -63
- package/generated/buffer.d.ts +16 -15
- package/generated/builtin-messages.d.ts +7 -1
- package/generated/bullet3d.d.ts +91 -0
- package/generated/bullet3d_collision_object.d.ts +433 -0
- package/generated/bullet3d_constraint.d.ts +818 -0
- package/generated/bullet3d_rigid_body.d.ts +429 -0
- package/generated/bullet3d_shape.d.ts +123 -0
- package/generated/bullet3d_world.d.ts +492 -0
- package/generated/camera.d.ts +29 -32
- package/generated/collectionfactory.d.ts +15 -18
- package/generated/collectionproxy.d.ts +22 -6
- package/generated/compute.d.ts +12 -238
- package/generated/crash.d.ts +24 -10
- package/generated/editor-vm/http.d.ts +90 -7
- package/generated/editor-vm/image.d.ts +7 -7
- package/generated/editor-vm/json.d.ts +11 -0
- package/generated/editor-vm/localization.d.ts +7 -7
- package/generated/editor-vm/tilemap_tiles.d.ts +56 -10
- package/generated/editor-vm/zip.d.ts +28 -0
- package/generated/editor.d.ts +1496 -430
- package/generated/factory.d.ts +21 -25
- package/generated/font.d.ts +64 -22
- package/generated/go.d.ts +235 -182
- package/generated/graphics.d.ts +335 -97
- package/generated/gui.d.ts +240 -471
- package/generated/html5.d.ts +2 -2
- package/generated/http.d.ts +28 -35
- package/generated/image.d.ts +105 -72
- package/generated/json.d.ts +34 -16
- package/generated/kinds/gui-script.d.ts +7 -0
- package/generated/kinds/render-script.d.ts +7 -0
- package/generated/kinds/script.d.ts +7 -0
- package/generated/label.d.ts +77 -7
- package/generated/liveupdate.d.ts +13 -10
- package/generated/material.d.ts +312 -360
- package/generated/model.d.ts +40 -39
- package/generated/particlefx.d.ts +19 -28
- package/generated/physics.d.ts +365 -133
- package/generated/profiler.d.ts +13 -23
- package/generated/render.d.ts +237 -297
- package/generated/resource.d.ts +664 -583
- package/generated/socket.d.ts +120 -133
- package/generated/sound.d.ts +62 -31
- package/generated/sprite.d.ts +31 -17
- package/generated/sys.d.ts +234 -190
- package/generated/tilemap.d.ts +21 -16
- package/generated/timer.d.ts +34 -21
- package/generated/versions/defold-1.12.4/b2d_body.d.ts +0 -7
- package/generated/versions/defold-1.12.4/buffer.d.ts +1 -3
- package/generated/versions/defold-1.12.4/camera.d.ts +21 -21
- package/generated/versions/defold-1.12.4/collectionfactory.d.ts +9 -9
- package/generated/versions/defold-1.12.4/collectionproxy.d.ts +2 -2
- package/generated/versions/defold-1.12.4/crash.d.ts +2 -2
- package/generated/versions/defold-1.12.4/factory.d.ts +15 -16
- package/generated/versions/defold-1.12.4/go.d.ts +6 -12
- package/generated/versions/defold-1.12.4/gui.d.ts +77 -175
- package/generated/versions/defold-1.12.4/html5.d.ts +1 -1
- package/generated/versions/defold-1.12.4/http.d.ts +0 -13
- package/generated/versions/defold-1.12.4/image.d.ts +16 -33
- package/generated/versions/defold-1.12.4/index.d.ts +1 -0
- package/generated/versions/defold-1.12.4/json.d.ts +10 -6
- package/generated/versions/defold-1.12.4/label.d.ts +2 -3
- package/generated/versions/defold-1.12.4/liveupdate.d.ts +5 -3
- package/generated/versions/defold-1.12.4/model.d.ts +2 -10
- package/generated/versions/defold-1.12.4/particlefx.d.ts +2 -5
- package/generated/versions/defold-1.12.4/physics.d.ts +69 -67
- package/generated/versions/defold-1.12.4/profiler.d.ts +2 -5
- package/generated/versions/defold-1.12.4/render.d.ts +99 -128
- package/generated/versions/defold-1.12.4/resource.d.ts +120 -148
- package/generated/versions/defold-1.12.4/socket.d.ts +34 -60
- package/generated/versions/defold-1.12.4/sound.d.ts +8 -8
- package/generated/versions/defold-1.12.4/sprite.d.ts +15 -5
- package/generated/versions/defold-1.12.4/sys.d.ts +37 -71
- package/generated/versions/defold-1.12.4/tilemap.d.ts +18 -11
- package/generated/versions/defold-1.12.4/timer.d.ts +5 -3
- package/generated/versions/defold-1.12.4/vmath.d.ts +0 -21
- package/generated/versions/defold-1.12.4/window.d.ts +1 -16
- package/generated/versions/defold-1.13.0/b2d_body.d.ts +10 -55
- package/generated/versions/defold-1.13.0/b2d_fixture.d.ts +25 -25
- package/generated/versions/defold-1.13.0/b2d_shape.d.ts +169 -8
- package/generated/versions/defold-1.13.0/b2d_world.d.ts +16 -10
- package/generated/versions/defold-1.13.0/buffer.d.ts +1 -3
- package/generated/versions/defold-1.13.0/camera.d.ts +25 -25
- package/generated/versions/defold-1.13.0/collectionfactory.d.ts +9 -9
- package/generated/versions/defold-1.13.0/collectionproxy.d.ts +2 -2
- package/generated/versions/defold-1.13.0/compute.d.ts +0 -69
- package/generated/versions/defold-1.13.0/crash.d.ts +2 -2
- package/generated/versions/defold-1.13.0/editor-vm/tilemap_tiles.d.ts +3 -3
- package/generated/versions/defold-1.13.0/editor.d.ts +34 -24
- package/generated/versions/defold-1.13.0/factory.d.ts +15 -16
- package/generated/versions/defold-1.13.0/go.d.ts +6 -12
- package/generated/versions/defold-1.13.0/graphics.d.ts +73 -37
- package/generated/versions/defold-1.13.0/gui.d.ts +77 -175
- package/generated/versions/defold-1.13.0/html5.d.ts +1 -1
- package/generated/versions/defold-1.13.0/http.d.ts +0 -13
- package/generated/versions/defold-1.13.0/image.d.ts +16 -33
- package/generated/versions/defold-1.13.0/index.d.ts +1 -0
- package/generated/versions/defold-1.13.0/json.d.ts +10 -6
- package/generated/versions/defold-1.13.0/label.d.ts +2 -3
- package/generated/versions/defold-1.13.0/liveupdate.d.ts +7 -5
- package/generated/versions/defold-1.13.0/material.d.ts +68 -106
- package/generated/versions/defold-1.13.0/model.d.ts +2 -10
- package/generated/versions/defold-1.13.0/particlefx.d.ts +2 -5
- package/generated/versions/defold-1.13.0/physics.d.ts +69 -67
- package/generated/versions/defold-1.13.0/profiler.d.ts +2 -5
- package/generated/versions/defold-1.13.0/render.d.ts +99 -128
- package/generated/versions/defold-1.13.0/resource.d.ts +126 -150
- package/generated/versions/defold-1.13.0/socket.d.ts +34 -60
- package/generated/versions/defold-1.13.0/sound.d.ts +8 -8
- package/generated/versions/defold-1.13.0/sprite.d.ts +15 -5
- package/generated/versions/defold-1.13.0/sys.d.ts +37 -71
- package/generated/versions/defold-1.13.0/tilemap.d.ts +18 -11
- package/generated/versions/defold-1.13.0/timer.d.ts +5 -3
- package/generated/versions/defold-1.13.0/vmath.d.ts +0 -21
- package/generated/versions/defold-1.13.0/window.d.ts +1 -16
- package/generated/versions/defold-1.13.1/b2d.d.ts +33 -0
- package/generated/versions/defold-1.13.1/b2d_body.d.ts +636 -0
- package/generated/versions/defold-1.13.1/b2d_chain.d.ts +106 -0
- package/generated/versions/defold-1.13.1/b2d_fixture.d.ts +157 -0
- package/generated/versions/defold-1.13.1/b2d_joint.d.ts +823 -0
- package/generated/versions/defold-1.13.1/b2d_shape.d.ts +400 -0
- package/generated/versions/defold-1.13.1/b2d_world.d.ts +320 -0
- package/generated/versions/defold-1.13.1/buffer.d.ts +189 -0
- package/generated/versions/defold-1.13.1/camera.d.ts +303 -0
- package/generated/versions/defold-1.13.1/collectionfactory.d.ts +151 -0
- package/generated/versions/defold-1.13.1/collectionproxy.d.ts +93 -0
- package/generated/versions/defold-1.13.1/compute.d.ts +237 -0
- package/generated/versions/defold-1.13.1/crash.d.ts +143 -0
- package/generated/versions/defold-1.13.1/editor-vm/http.d.ts +56 -0
- package/generated/versions/defold-1.13.1/editor-vm/image.d.ts +48 -0
- package/generated/versions/defold-1.13.1/editor-vm/json.d.ts +10 -0
- package/generated/versions/defold-1.13.1/editor-vm/localization.d.ts +42 -0
- package/generated/versions/defold-1.13.1/editor-vm/tilemap_tiles.d.ts +80 -0
- package/generated/versions/defold-1.13.1/editor-vm/zip.d.ts +10 -0
- package/generated/versions/defold-1.13.1/editor-vm/zlib.d.ts +24 -0
- package/generated/versions/defold-1.13.1/editor.d.ts +1121 -0
- package/generated/versions/defold-1.13.1/factory.d.ts +124 -0
- package/generated/versions/defold-1.13.1/font.d.ts +81 -0
- package/generated/versions/defold-1.13.1/go.d.ts +1107 -0
- package/generated/versions/defold-1.13.1/graphics.d.ts +411 -0
- package/generated/versions/defold-1.13.1/gui.d.ts +2353 -0
- package/generated/versions/defold-1.13.1/html5.d.ts +55 -0
- package/generated/versions/defold-1.13.1/http.d.ts +77 -0
- package/generated/versions/defold-1.13.1/image.d.ts +131 -0
- package/generated/versions/defold-1.13.1/index.d.ts +57 -0
- package/generated/versions/defold-1.13.1/json.d.ts +80 -0
- package/generated/versions/defold-1.13.1/kinds/editor-script.d.ts +14 -0
- package/generated/versions/defold-1.13.1/label.d.ts +93 -0
- package/generated/versions/defold-1.13.1/liveupdate.d.ts +142 -0
- package/generated/versions/defold-1.13.1/material.d.ts +408 -0
- package/generated/versions/defold-1.13.1/model.d.ts +272 -0
- package/generated/versions/defold-1.13.1/msg.d.ts +10 -0
- package/generated/versions/defold-1.13.1/particlefx.d.ts +163 -0
- package/generated/versions/defold-1.13.1/physics.d.ts +559 -0
- package/generated/versions/defold-1.13.1/profiler.d.ts +235 -0
- package/generated/versions/defold-1.13.1/render.d.ts +1190 -0
- package/generated/versions/defold-1.13.1/resource.d.ts +1523 -0
- package/generated/versions/defold-1.13.1/socket.d.ts +784 -0
- package/generated/versions/defold-1.13.1/sound.d.ts +292 -0
- package/generated/versions/defold-1.13.1/sprite.d.ts +175 -0
- package/generated/versions/defold-1.13.1/sys.d.ts +678 -0
- package/generated/versions/defold-1.13.1/tilemap.d.ts +208 -0
- package/generated/versions/defold-1.13.1/timer.d.ts +125 -0
- package/generated/versions/defold-1.13.1/types.d.ts +61 -0
- package/generated/versions/defold-1.13.1/vmath.d.ts +774 -0
- package/generated/versions/defold-1.13.1/window.d.ts +183 -0
- package/generated/versions/defold-1.13.1/zlib.d.ts +41 -0
- package/generated/vmath.d.ts +1 -21
- package/generated/window.d.ts +71 -71
- package/identity-vocabulary.json +561 -0
- package/index.d.ts +7 -0
- package/package.json +18 -2
- package/scripts/example-store-io.ts +12 -1
- package/scripts/extension-goldens.ts +1 -0
- package/scripts/fidelity-baseline.json +146 -46
- package/scripts/generate-api-availability.ts +90 -12
- package/scripts/generate-api-signatures.ts +12 -2
- package/scripts/import-defold-release.ts +106 -26
- package/scripts/prose-constants.ts +77 -16
- package/scripts/regen.ts +391 -77
- package/scripts/shared-handle-methods.ts +53 -0
- package/scripts/signature-store-fs.ts +1 -0
- package/scripts/sync-api-docs.ts +48 -10
- package/src/api-availability.ts +0 -0
- package/src/api-doc.ts +201 -3
- package/src/api-identity.ts +252 -0
- package/src/core-types.ts +26 -3
- package/src/correction-pins.ts +49 -0
- package/src/doc-comment.ts +104 -11
- package/src/doc-corrections.ts +108 -0
- package/src/editor-vm-globals.d.ts +5 -2
- package/src/emit-dts.ts +2064 -281
- package/src/emit-messages.ts +52 -0
- package/src/example-store.ts +125 -14
- package/src/field-correction-coverage.ts +204 -0
- package/src/fnv1a.ts +16 -0
- package/src/go-overloads.d.ts +25 -6
- package/src/index-base-table.ts +145 -0
- package/src/index-slot-classifications.ts +588 -0
- package/src/index.ts +38 -5
- package/src/library-index-slot-classifications.ts +332 -0
- package/src/lifecycle.ts +61 -199
- package/src/luals-type-expr.ts +354 -0
- package/src/msg-overloads.d.ts +0 -1
- package/src/param-correction-provenance.ts +8 -11
- package/src/render-overloads.d.ts +0 -15
- package/src/return-correction-provenance.ts +58 -16
- package/src/sys-overloads.d.ts +48 -0
- package/src/vmath-overloads.d.ts +27 -1
- package/src/window-event-guard.d.ts +6 -9
- package/url-parameters.json +1 -2
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import type { ApiFunction, ApiModule, ApiParameter } from "./api-doc";
|
|
2
|
+
import { DEFOLD_TYPE_MAP } from "./core-types";
|
|
3
|
+
import { pinMatches } from "./correction-pins";
|
|
4
|
+
import { splitTopLevel } from "./luals-type-expr";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A type correction as identity applies it: where the slot still declares one of
|
|
8
|
+
* `pins`, its values are the declared ones less `removes` plus `adds`, or
|
|
9
|
+
* `replaces` outright. Every list is written in ref-doc or TypeScript spelling;
|
|
10
|
+
* both canonicalize to the same values.
|
|
11
|
+
*/
|
|
12
|
+
export interface IdentityCorrection {
|
|
13
|
+
readonly pins: readonly (readonly string[])[];
|
|
14
|
+
readonly adds?: readonly string[];
|
|
15
|
+
readonly removes?: readonly string[];
|
|
16
|
+
readonly replaces?: readonly string[];
|
|
17
|
+
/** A return correction's slot name, when it rewrites one of several returns. */
|
|
18
|
+
readonly slot?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The corrections this repo records from verified engine behavior. Identity
|
|
23
|
+
* follows them rather than each release's markup, so a release whose ref-doc
|
|
24
|
+
* starts stating what a correction already did is not a change.
|
|
25
|
+
*/
|
|
26
|
+
export interface IdentityCorrections {
|
|
27
|
+
/** `<element>:param:<slot>` keys a correction makes optional. */
|
|
28
|
+
readonly optionalSlots: readonly string[];
|
|
29
|
+
/** `<element>:param:<slot>` keys a correction keeps required. */
|
|
30
|
+
readonly requiredSlots: readonly string[];
|
|
31
|
+
/** Keyed `<element>:param:<slot>`. */
|
|
32
|
+
readonly parameterCorrections: Readonly<Record<string, IdentityCorrection>>;
|
|
33
|
+
/** Keyed by element. */
|
|
34
|
+
readonly returnCorrections: Readonly<Record<string, IdentityCorrection>>;
|
|
35
|
+
/** Constant-family aliases a correction may name (`window.DimModeStateSettable`), with members. */
|
|
36
|
+
readonly constantFamilies: Readonly<Record<string, readonly string[]>>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The names a ref-doc type token may refer to, gathered across every committed
|
|
41
|
+
* target so each release's spelling resolves the same way, plus the corrections.
|
|
42
|
+
* A name keeps its kind across releases: a 1.13.2 `STRUCT` is a table wherever
|
|
43
|
+
* it appears.
|
|
44
|
+
*/
|
|
45
|
+
export interface IdentityVocabulary extends Omit<IdentityCorrections, "constantFamilies"> {
|
|
46
|
+
/** `STRUCT` names: a table at runtime. */
|
|
47
|
+
readonly tables: readonly string[];
|
|
48
|
+
/** `ENUM` names and constant families, with the runtime type of their members. */
|
|
49
|
+
readonly enums: Readonly<Record<string, "number" | "string">>;
|
|
50
|
+
/** Constants whose value is a string; every other constant is a number. */
|
|
51
|
+
readonly stringConstants: readonly string[];
|
|
52
|
+
/** Non-handle `TYPEDEF` names and the tokens they alias. */
|
|
53
|
+
readonly aliases: Readonly<Record<string, readonly string[]>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const NO_IDENTITY_CORRECTIONS: IdentityCorrections = {
|
|
57
|
+
optionalSlots: [],
|
|
58
|
+
requiredSlots: [],
|
|
59
|
+
parameterCorrections: {},
|
|
60
|
+
returnCorrections: {},
|
|
61
|
+
constantFamilies: {},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const sortedRecord = <T>(entries: Iterable<[string, T]>): Record<string, T> =>
|
|
65
|
+
Object.fromEntries([...entries].sort(([a], [b]) => a.localeCompare(b)));
|
|
66
|
+
|
|
67
|
+
export function buildIdentityVocabulary(
|
|
68
|
+
modules: readonly ApiModule[],
|
|
69
|
+
corrections: IdentityCorrections = NO_IDENTITY_CORRECTIONS,
|
|
70
|
+
): IdentityVocabulary {
|
|
71
|
+
const tables = new Set<string>();
|
|
72
|
+
const stringConstants = new Set<string>();
|
|
73
|
+
const aliases = new Map<string, readonly string[]>();
|
|
74
|
+
const enumMembers = new Map<string, readonly string[]>(
|
|
75
|
+
Object.entries(corrections.constantFamilies),
|
|
76
|
+
);
|
|
77
|
+
for (const module of modules) {
|
|
78
|
+
for (const struct of module.structs ?? []) tables.add(struct.name);
|
|
79
|
+
for (const constant of module.constants) {
|
|
80
|
+
if (constant.valueType === "string") stringConstants.add(constant.name);
|
|
81
|
+
}
|
|
82
|
+
for (const enumeration of module.enums ?? []) {
|
|
83
|
+
enumMembers.set(enumeration.name, enumeration.members);
|
|
84
|
+
}
|
|
85
|
+
for (const typedef of module.typedefs) {
|
|
86
|
+
const aliasOf = typedef.aliasOf;
|
|
87
|
+
if (aliasOf === undefined || (aliasOf.length === 1 && aliasOf[0] === "userdata")) continue;
|
|
88
|
+
aliases.set(typedef.name, aliasOf);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const enums = [...enumMembers].map(([name, members]): [string, "number" | "string"] => [
|
|
92
|
+
name,
|
|
93
|
+
members.length > 0 && members.every((member) => stringConstants.has(member))
|
|
94
|
+
? "string"
|
|
95
|
+
: "number",
|
|
96
|
+
]);
|
|
97
|
+
return {
|
|
98
|
+
tables: [...tables].sort(),
|
|
99
|
+
enums: sortedRecord(enums),
|
|
100
|
+
stringConstants: [...stringConstants].sort(),
|
|
101
|
+
aliases: sortedRecord(aliases),
|
|
102
|
+
optionalSlots: [...corrections.optionalSlots].sort(),
|
|
103
|
+
requiredSlots: [...corrections.requiredSlots].sort(),
|
|
104
|
+
parameterCorrections: sortedRecord(Object.entries(corrections.parameterCorrections)),
|
|
105
|
+
returnCorrections: sortedRecord(Object.entries(corrections.returnCorrections)),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Tokens a later release renamed without changing what they denote.
|
|
110
|
+
const RENAMED_TOKENS: Readonly<Record<string, string>> = {
|
|
111
|
+
// 1.13.2 names the lifecycle callbacks' `self` after what it is.
|
|
112
|
+
script_instance: "userdata",
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const CONSTANT_FQN = /^[a-z_][\w.]*\.[A-Z][A-Z0-9_]*$/;
|
|
116
|
+
const NUMERIC_LITERAL = /^-?\d+(\.\d+)?$/;
|
|
117
|
+
const STRING_LITERAL = /^(".*"|'.*')$/;
|
|
118
|
+
// The TypeScript table types a correction writes.
|
|
119
|
+
const TS_TABLE = /^(Record|LuaMap|ReadonlyLuaMap|LuaTable)\b/;
|
|
120
|
+
|
|
121
|
+
function canonicalLeaves(
|
|
122
|
+
token: string,
|
|
123
|
+
vocabulary: IdentityVocabulary,
|
|
124
|
+
expanding: ReadonlySet<string>,
|
|
125
|
+
): string[] {
|
|
126
|
+
const trimmed = token.trim();
|
|
127
|
+
const arms = splitTopLevel(trimmed, "|");
|
|
128
|
+
if (arms.length > 1) return arms.flatMap((arm) => canonicalLeaves(arm, vocabulary, expanding));
|
|
129
|
+
if (trimmed.endsWith("?")) {
|
|
130
|
+
return [...canonicalLeaves(trimmed.slice(0, -1), vocabulary, expanding), "nil"];
|
|
131
|
+
}
|
|
132
|
+
if (/^(fun|function)\b/.test(trimmed) || trimmed.includes("=>")) return ["function"];
|
|
133
|
+
if (trimmed.startsWith("(") && trimmed.endsWith(")")) {
|
|
134
|
+
return canonicalLeaves(trimmed.slice(1, -1), vocabulary, expanding);
|
|
135
|
+
}
|
|
136
|
+
if (trimmed.startsWith("typeof ")) {
|
|
137
|
+
return canonicalLeaves(trimmed.slice("typeof ".length), vocabulary, expanding);
|
|
138
|
+
}
|
|
139
|
+
if (trimmed === "nil" || trimmed === "undefined") return ["nil"];
|
|
140
|
+
// Every table shape — a bare or typed `table`, a list, an inline record, a
|
|
141
|
+
// struct, a built-in message payload — is one Lua table at runtime; its
|
|
142
|
+
// documented fields are not part of what identifies the call.
|
|
143
|
+
if (
|
|
144
|
+
trimmed === "table" ||
|
|
145
|
+
trimmed.startsWith("table<") ||
|
|
146
|
+
trimmed.startsWith("{") ||
|
|
147
|
+
trimmed.endsWith("[]") ||
|
|
148
|
+
trimmed.startsWith("message.") ||
|
|
149
|
+
TS_TABLE.test(trimmed) ||
|
|
150
|
+
vocabulary.tables.includes(trimmed)
|
|
151
|
+
) {
|
|
152
|
+
return ["table"];
|
|
153
|
+
}
|
|
154
|
+
if (STRING_LITERAL.test(trimmed)) return ["string"];
|
|
155
|
+
if (NUMERIC_LITERAL.test(trimmed)) return ["number"];
|
|
156
|
+
if (trimmed === "true" || trimmed === "false") return ["boolean"];
|
|
157
|
+
// An enum, one of its constants, or the untyped `constant` older releases
|
|
158
|
+
// wrote are all the value the engine registered: a number unless declared a
|
|
159
|
+
// string.
|
|
160
|
+
const enumType = vocabulary.enums[trimmed];
|
|
161
|
+
if (enumType !== undefined) return [enumType];
|
|
162
|
+
if (vocabulary.stringConstants.includes(trimmed)) return ["string"];
|
|
163
|
+
if (trimmed === "constant" || CONSTANT_FQN.test(trimmed)) return ["number"];
|
|
164
|
+
const aliasOf = vocabulary.aliases[trimmed];
|
|
165
|
+
if (aliasOf !== undefined && !expanding.has(trimmed)) {
|
|
166
|
+
const next = new Set(expanding).add(trimmed);
|
|
167
|
+
return aliasOf.flatMap((aliased) => canonicalLeaves(aliased, vocabulary, next));
|
|
168
|
+
}
|
|
169
|
+
const renamed = RENAMED_TOKENS[trimmed] ?? trimmed;
|
|
170
|
+
// Primitive synonyms (`integer` and `number`, `buffer_data` and `buffer`) are
|
|
171
|
+
// the tokens the engine vocabulary maps to one TypeScript type.
|
|
172
|
+
return [
|
|
173
|
+
Object.hasOwn(DEFOLD_TYPE_MAP, renamed)
|
|
174
|
+
? ((DEFOLD_TYPE_MAP as Readonly<Record<string, string>>)[renamed] as string)
|
|
175
|
+
: renamed,
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A slot's ref-doc tokens in a vocabulary-neutral form: the runtime values the
|
|
181
|
+
* slot takes, sorted and without duplicates, so a release that only respells a
|
|
182
|
+
* slot keeps its identity while one that changes what it takes does not.
|
|
183
|
+
*/
|
|
184
|
+
export function canonicalIdentityTypes(
|
|
185
|
+
types: readonly string[],
|
|
186
|
+
vocabulary: IdentityVocabulary,
|
|
187
|
+
): string[] {
|
|
188
|
+
return [
|
|
189
|
+
...new Set(types.flatMap((token) => canonicalLeaves(token, vocabulary, new Set()))),
|
|
190
|
+
].sort();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function correctedTypes(
|
|
194
|
+
types: readonly string[],
|
|
195
|
+
correction: IdentityCorrection | undefined,
|
|
196
|
+
vocabulary: IdentityVocabulary,
|
|
197
|
+
): string[] {
|
|
198
|
+
if (correction === undefined || !pinMatches(types, correction.pins)) {
|
|
199
|
+
return canonicalIdentityTypes(types, vocabulary);
|
|
200
|
+
}
|
|
201
|
+
if (correction.replaces !== undefined) {
|
|
202
|
+
return canonicalIdentityTypes(correction.replaces, vocabulary);
|
|
203
|
+
}
|
|
204
|
+
const removed = new Set(canonicalIdentityTypes(correction.removes ?? [], vocabulary));
|
|
205
|
+
return [
|
|
206
|
+
...new Set([
|
|
207
|
+
...canonicalIdentityTypes(types, vocabulary).filter((value) => !removed.has(value)),
|
|
208
|
+
...canonicalIdentityTypes(correction.adds ?? [], vocabulary),
|
|
209
|
+
]),
|
|
210
|
+
].sort();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface IdentitySlot {
|
|
214
|
+
readonly types: readonly string[];
|
|
215
|
+
readonly isOptional: boolean;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** A parameter as identity reads it: its corrected values and effective optionality. */
|
|
219
|
+
export function identityParameter(
|
|
220
|
+
fn: ApiFunction,
|
|
221
|
+
parameter: ApiParameter,
|
|
222
|
+
vocabulary: IdentityVocabulary,
|
|
223
|
+
): IdentitySlot {
|
|
224
|
+
const key = `${fn.name}:param:${parameter.name}`;
|
|
225
|
+
const types = correctedTypes(parameter.types, vocabulary.parameterCorrections[key], vocabulary);
|
|
226
|
+
// A slot a correction keeps required may still take an explicit nil, which
|
|
227
|
+
// stays part of what it takes; anywhere else, taking nil is being omissible.
|
|
228
|
+
if (vocabulary.requiredSlots.includes(key)) return { types, isOptional: false };
|
|
229
|
+
return {
|
|
230
|
+
types: types.filter((value) => value !== "nil"),
|
|
231
|
+
isOptional:
|
|
232
|
+
parameter.isOptional || types.includes("nil") || vocabulary.optionalSlots.includes(key),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** A return value as identity reads it, with a return correction applied where it holds. */
|
|
237
|
+
export function identityReturn(
|
|
238
|
+
fn: ApiFunction,
|
|
239
|
+
returned: ApiParameter,
|
|
240
|
+
vocabulary: IdentityVocabulary,
|
|
241
|
+
): IdentitySlot {
|
|
242
|
+
const correction = vocabulary.returnCorrections[fn.name];
|
|
243
|
+
const applies =
|
|
244
|
+
correction !== undefined &&
|
|
245
|
+
(correction.slot === undefined
|
|
246
|
+
? fn.returnValues.length === 1
|
|
247
|
+
: correction.slot === returned.name);
|
|
248
|
+
return {
|
|
249
|
+
types: correctedTypes(returned.types, applies ? correction : undefined, vocabulary),
|
|
250
|
+
isOptional: returned.isOptional,
|
|
251
|
+
};
|
|
252
|
+
}
|
package/src/core-types.ts
CHANGED
|
@@ -188,6 +188,10 @@ export interface Url {
|
|
|
188
188
|
readonly fragment: Hash | undefined;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
const BUFFER_TYPE = 'Opaque<"buffer">';
|
|
192
|
+
const BUFFERSTREAM_TYPE =
|
|
193
|
+
'Opaque<"bufferstream"> & { [index: number]: number; length: LuaLengthMethod<number> }';
|
|
194
|
+
|
|
191
195
|
export const DEFOLD_TYPE_MAP: Readonly<Record<string, string>> = {
|
|
192
196
|
number: "number",
|
|
193
197
|
int: "number",
|
|
@@ -216,9 +220,8 @@ export const DEFOLD_TYPE_MAP: Readonly<Record<string, string>> = {
|
|
|
216
220
|
constant: 'Opaque<"constant">',
|
|
217
221
|
constant_buffer:
|
|
218
222
|
'Opaque<"constant_buffer"> & { [name: string]: Vector4 | Matrix4 | Vector4[] | Matrix4[] }',
|
|
219
|
-
buffer:
|
|
220
|
-
bufferstream:
|
|
221
|
-
'Opaque<"bufferstream"> & { [index: number]: number; length: LuaLengthMethod<number> }',
|
|
223
|
+
buffer: BUFFER_TYPE,
|
|
224
|
+
bufferstream: BUFFERSTREAM_TYPE,
|
|
222
225
|
userdata: 'Opaque<"userdata">',
|
|
223
226
|
// Vocabulary, not a shipped brand: no current ref-doc fixture types a slot
|
|
224
227
|
// `resource`, so nothing hand-written may name `Opaque<"resource">`. Kept so a
|
|
@@ -232,6 +235,10 @@ export const DEFOLD_TYPE_MAP: Readonly<Record<string, string>> = {
|
|
|
232
235
|
b2ContactEdge: 'Opaque<"b2ContactEdge">',
|
|
233
236
|
b2MassData: 'Opaque<"b2MassData">',
|
|
234
237
|
b2Transform: 'Opaque<"b2Transform">',
|
|
238
|
+
// bullet3d's collision-object functions also take a rigid body (its docs say
|
|
239
|
+
// so), so that handle's brand admits both; a rigid-body slot keeps its own.
|
|
240
|
+
btCollisionObject: 'Opaque<"btCollisionObject" | "btRigidBody">',
|
|
241
|
+
btRigidBody: 'Opaque<"btRigidBody">',
|
|
235
242
|
b2BodyType:
|
|
236
243
|
'(number & { readonly __brand: "b2d.body.B2_DYNAMIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_KINEMATIC_BODY" }) | (number & { readonly __brand: "b2d.body.B2_STATIC_BODY" })',
|
|
237
244
|
// socket handle types resolve to the method-bearing `interface <receiver>`
|
|
@@ -243,4 +250,20 @@ export const DEFOLD_TYPE_MAP: Readonly<Record<string, string>> = {
|
|
|
243
250
|
server: "server",
|
|
244
251
|
unconnected: "unconnected",
|
|
245
252
|
any: "unknown",
|
|
253
|
+
// 1.13.2 renames of the leaves above, same slots. Upstream declares each only as
|
|
254
|
+
// a `userdata`/`number` handle TYPEDEF, so each keeps its 1.13.1 mapping, with
|
|
255
|
+
// two exceptions: `script_instance` is the untyped `self` a callback recovery
|
|
256
|
+
// emits, and `resource_data` (1.13.1 `resource`, only in the hand-authored
|
|
257
|
+
// `go.get`/`go.set`/`go.property` slots) is a path hash.
|
|
258
|
+
buffer_data: BUFFER_TYPE,
|
|
259
|
+
buffer_stream: BUFFERSTREAM_TYPE,
|
|
260
|
+
script_instance: "unknown",
|
|
261
|
+
resource_data: "Hash",
|
|
262
|
+
timer_handle: "number",
|
|
263
|
+
render_predicate: "number",
|
|
264
|
+
socket_client: "client",
|
|
265
|
+
socket_connected: "connected",
|
|
266
|
+
socket_master: "master",
|
|
267
|
+
socket_server: "server",
|
|
268
|
+
socket_unconnected: "unconnected",
|
|
246
269
|
} as const;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A slot-level type correction records the upstream spelling it contradicts
|
|
2
|
+
// (`upstream`) and any later spelling of the same defect a newer release
|
|
3
|
+
// declares (`retypedUpstream`). The emitter applies the correction only while
|
|
4
|
+
// the slot being emitted still declares one of them, and the provenance tests
|
|
5
|
+
// ask the same question of every retained target, so one table serves every
|
|
6
|
+
// release and neither side can drift from the other.
|
|
7
|
+
export interface PinnedCorrection {
|
|
8
|
+
readonly upstream: readonly string[];
|
|
9
|
+
readonly retypedUpstream?: readonly (readonly string[])[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// `nil` is optionality, which `isDocOptional` owns (and, for a return, the
|
|
13
|
+
// return lane's own `nil` verdict); a correction rewrites only the concrete
|
|
14
|
+
// tokens, so only those are evidence.
|
|
15
|
+
export function baseTokens(tokens: readonly string[]): string {
|
|
16
|
+
return tokens.filter((token) => token !== "nil").join("|");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function correctionPins(correction: PinnedCorrection): readonly (readonly string[])[] {
|
|
20
|
+
return [correction.upstream, ...(correction.retypedUpstream ?? [])];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function pinMatches(
|
|
24
|
+
declared: readonly string[],
|
|
25
|
+
pins: readonly (readonly string[])[],
|
|
26
|
+
): boolean {
|
|
27
|
+
const base = baseTokens(declared);
|
|
28
|
+
return pins.some((pin) => baseTokens(pin) === base);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// A property pins the text of its `<span class="type">`, split the way
|
|
32
|
+
// `parseProperty` splits it.
|
|
33
|
+
export function spanTokens(span: string): string[] {
|
|
34
|
+
return span
|
|
35
|
+
.split("|")
|
|
36
|
+
.map((token) => token.trim())
|
|
37
|
+
.filter((token) => token.length > 0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PinnedPropertyCorrection {
|
|
41
|
+
readonly upstream: string;
|
|
42
|
+
readonly retypedUpstream?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function propertyCorrectionPins(
|
|
46
|
+
correction: PinnedPropertyCorrection,
|
|
47
|
+
): readonly (readonly string[])[] {
|
|
48
|
+
return [correction.upstream, ...(correction.retypedUpstream ?? [])].map(spanTokens);
|
|
49
|
+
}
|
package/src/doc-comment.ts
CHANGED
|
@@ -39,6 +39,12 @@ function codePointOr(code: number, fallback: string): string {
|
|
|
39
39
|
return code <= 0x10ffff ? String.fromCodePoint(code) : fallback;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// One level of list nesting while `htmlToDocText` runs its whitespace pass,
|
|
43
|
+
// which would otherwise strip leading spaces.
|
|
44
|
+
const LIST_INDENT = "";
|
|
45
|
+
const STRANDED_MARKER = /^(*)-$/;
|
|
46
|
+
const LIST_ITEM = /^*- /;
|
|
47
|
+
|
|
42
48
|
/**
|
|
43
49
|
* Join a list marker left alone on its line back onto the item's first content
|
|
44
50
|
* line. Upstream prose puts a newline between `<li>` and the item's first word,
|
|
@@ -57,7 +63,8 @@ function weldStrandedListMarkers(text: string): string {
|
|
|
57
63
|
out.push(line);
|
|
58
64
|
continue;
|
|
59
65
|
}
|
|
60
|
-
|
|
66
|
+
const stranded = STRANDED_MARKER.exec(line);
|
|
67
|
+
if (inFence || !stranded) {
|
|
61
68
|
out.push(line);
|
|
62
69
|
continue;
|
|
63
70
|
}
|
|
@@ -66,35 +73,90 @@ function weldStrandedListMarkers(text: string): string {
|
|
|
66
73
|
const content = lines[ahead];
|
|
67
74
|
if (
|
|
68
75
|
content === undefined ||
|
|
69
|
-
content
|
|
70
|
-
|
|
76
|
+
STRANDED_MARKER.test(content) ||
|
|
77
|
+
LIST_ITEM.test(content) ||
|
|
71
78
|
content.startsWith("```")
|
|
72
79
|
) {
|
|
73
80
|
// No value to weld onto — drop the marker and the blank run behind it.
|
|
74
81
|
index = ahead - 1;
|
|
75
82
|
continue;
|
|
76
83
|
}
|
|
77
|
-
out.push(
|
|
84
|
+
out.push(`${stranded[1]}- ${content}`);
|
|
78
85
|
index = ahead;
|
|
79
86
|
}
|
|
80
87
|
return out.join("\n").trim();
|
|
81
88
|
}
|
|
82
89
|
|
|
90
|
+
// Upstream Markdown indented one level too deep is highlighted as code while
|
|
91
|
+
// still reading as Markdown: every line opens on a backtick-quoted name, as in
|
|
92
|
+
// the field table `graphics.get_adapter_info` documents under `limits`. That
|
|
93
|
+
// doc is replaced whole by a `DOC_CORRECTIONS` entry, so no vendored ref-doc
|
|
94
|
+
// reaches this rule today. It is the fallback for when upstream rewords such a
|
|
95
|
+
// doc without fixing it — the correction's hash stops matching and this still
|
|
96
|
+
// yields a readable list, not a mislabelled `lua` fence — and for any other doc
|
|
97
|
+
// that repeats the mistake.
|
|
98
|
+
const MISREAD_MARKDOWN_LINE = /^\s*`[^`]+`/;
|
|
99
|
+
|
|
100
|
+
// A `<pre>` body as Markdown. Misread Markdown becomes a bullet per line, its
|
|
101
|
+
// `[type:X]` marker reduced to the bare type the way a `<span class="type">` is.
|
|
102
|
+
// Otherwise it is a fence: a `<code>` inside marks highlighted source, Lua
|
|
103
|
+
// unless its class names another language, and a bare `<pre>` is a
|
|
104
|
+
// preformatted diagram. Upstream indents some samples by a uniform margin,
|
|
105
|
+
// which is dropped.
|
|
106
|
+
function preToMarkdown(inner: string): string {
|
|
107
|
+
const lines = htmlToCodeText(inner).split("\n");
|
|
108
|
+
const filled = lines.filter((line) => line.trim() !== "");
|
|
109
|
+
if (filled.every((line) => MISREAD_MARKDOWN_LINE.test(line))) {
|
|
110
|
+
return filled
|
|
111
|
+
.map(
|
|
112
|
+
(line) =>
|
|
113
|
+
`- ${line
|
|
114
|
+
.trim()
|
|
115
|
+
.replace(/\[type:([^\]]+)\]/g, "$1")
|
|
116
|
+
.replace(/\s+/g, " ")}`,
|
|
117
|
+
)
|
|
118
|
+
.join("\n");
|
|
119
|
+
}
|
|
120
|
+
const lang =
|
|
121
|
+
inner.match(/class="language-([A-Za-z0-9_+-]+)"/)?.[1] ??
|
|
122
|
+
(/<code\b/i.test(inner) ? "lua" : "text");
|
|
123
|
+
const margin = Math.min(
|
|
124
|
+
...lines.filter((line) => line.trim() !== "").map((line) => line.match(/^ */)?.[0].length ?? 0),
|
|
125
|
+
);
|
|
126
|
+
const body = lines.map((line) => line.slice(Number.isFinite(margin) ? margin : 0)).join("\n");
|
|
127
|
+
return `\`\`\`${lang}\n${body}\n\`\`\``;
|
|
128
|
+
}
|
|
129
|
+
|
|
83
130
|
/**
|
|
84
131
|
* Convert a ref-doc HTML fragment to clean Markdown/plain text suitable for a
|
|
85
132
|
* JSDoc comment body. Pure and free of any `ApiModule` dependency so the emit
|
|
86
133
|
* slices and any future surface can reuse it.
|
|
87
134
|
*/
|
|
88
135
|
export function htmlToDocText(html: string): string {
|
|
136
|
+
// Lift each `<pre>` out before the whitespace pass, which would flatten an
|
|
137
|
+
// ASCII diagram or a code sample into one line, and put it back as Markdown.
|
|
138
|
+
const fences: string[] = [];
|
|
139
|
+
// A list item's marker carries one `LIST_INDENT` per enclosing list beyond
|
|
140
|
+
// the first, which the whitespace pass leaves alone; each becomes two spaces,
|
|
141
|
+
// the content column of the parent `- ` marker, once that pass is done.
|
|
142
|
+
let listDepth = 0;
|
|
89
143
|
let text = html
|
|
144
|
+
.replace(/<pre\b[^>]*>([\s\S]*?)<\/pre>/gi, (_, inner: string) => {
|
|
145
|
+
fences.push(preToMarkdown(inner));
|
|
146
|
+
return `\n\n\uE000${fences.length - 1}\uE000\n\n`;
|
|
147
|
+
})
|
|
90
148
|
.replace(/<code>([\s\S]*?)<\/code>/gi, "`$1`")
|
|
91
149
|
.replace(/<(?:em|i)>([\s\S]*?)<\/(?:em|i)>/gi, "*$1*")
|
|
92
150
|
.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, "$1")
|
|
93
|
-
.replace(/<li
|
|
94
|
-
|
|
151
|
+
.replace(/<(\/?)(ul|ol|li)\b[^>]*>/gi, (_, close: string, tag: string) => {
|
|
152
|
+
if (tag.toLowerCase() !== "li") {
|
|
153
|
+
listDepth = Math.max(0, listDepth + (close ? -1 : 1));
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
return close ? "" : `\n${LIST_INDENT.repeat(Math.max(0, listDepth - 1))}- `;
|
|
157
|
+
})
|
|
95
158
|
.replace(/<br\s*\/?>/gi, "\n")
|
|
96
159
|
.replace(/<\/p>/gi, "\n\n")
|
|
97
|
-
.replace(/<\/?pre>/gi, "\n")
|
|
98
160
|
.replace(/<[^>]+>/g, "");
|
|
99
161
|
|
|
100
162
|
text = decodeEntities(text);
|
|
@@ -109,7 +171,12 @@ export function htmlToDocText(html: string): string {
|
|
|
109
171
|
.replace(/\n{3,}/g, "\n\n")
|
|
110
172
|
.trim();
|
|
111
173
|
|
|
112
|
-
|
|
174
|
+
// A blank line between two items would make the list loose, spacing every
|
|
175
|
+
// item apart like a paragraph.
|
|
176
|
+
text = weldStrandedListMarkers(text)
|
|
177
|
+
.replace(/(?<=^*- .*)\n\n(?=*- )/gm, "\n")
|
|
178
|
+
.replaceAll(LIST_INDENT, " ")
|
|
179
|
+
.replace(/\uE000(\d+)\uE000/g, (_, i: string) => fences[Number(i)] ?? "");
|
|
113
180
|
|
|
114
181
|
// Upstream prose can open a fence and end mid-body; left open it swallows the
|
|
115
182
|
// rest of the JSDoc block and everything after it on the rendered page.
|
|
@@ -161,7 +228,7 @@ function scanExampleRegions(html: string): { matched: boolean; regions: ExampleR
|
|
|
161
228
|
let matched = false;
|
|
162
229
|
for (let match = blocks.exec(html); match !== null; match = blocks.exec(html)) {
|
|
163
230
|
matched = true;
|
|
164
|
-
regions.push(
|
|
231
|
+
regions.push(...proseRegions(html.slice(lastIndex, match.index)));
|
|
165
232
|
const inner = match[1] ?? "";
|
|
166
233
|
regions.push({
|
|
167
234
|
kind: "code",
|
|
@@ -171,10 +238,28 @@ function scanExampleRegions(html: string): { matched: boolean; regions: ExampleR
|
|
|
171
238
|
lastIndex = match.index + match[0].length;
|
|
172
239
|
}
|
|
173
240
|
if (!matched) return { matched: false, regions: [{ kind: "code", html, lang: "lua" }] };
|
|
174
|
-
regions.push(
|
|
241
|
+
regions.push(...proseRegions(html.slice(lastIndex)));
|
|
175
242
|
return { matched: true, regions };
|
|
176
243
|
}
|
|
177
244
|
|
|
245
|
+
// Upstream Markdown ```` ```lua ```` fences sometimes reach the ref-doc as
|
|
246
|
+
// `<code>lua\n...</code>`: a language token, a newline, then source. Read as
|
|
247
|
+
// prose it welds the code into the surrounding sentences, so each one is lifted
|
|
248
|
+
// into a code region of its own. Inline `<code>` spans carry no such newline.
|
|
249
|
+
const MANGLED_FENCE = /<code>([A-Za-z0-9_+-]+)\n([\s\S]*?)<\/code>/g;
|
|
250
|
+
|
|
251
|
+
function proseRegions(html: string): ExampleRegion[] {
|
|
252
|
+
const regions: ExampleRegion[] = [];
|
|
253
|
+
let lastIndex = 0;
|
|
254
|
+
for (const match of html.matchAll(MANGLED_FENCE)) {
|
|
255
|
+
regions.push({ kind: "prose", html: html.slice(lastIndex, match.index), lang: "lua" });
|
|
256
|
+
regions.push({ kind: "code", html: match[2] ?? "", lang: match[1] ?? "lua" });
|
|
257
|
+
lastIndex = match.index + match[0].length;
|
|
258
|
+
}
|
|
259
|
+
regions.push({ kind: "prose", html: html.slice(lastIndex), lang: "lua" });
|
|
260
|
+
return regions;
|
|
261
|
+
}
|
|
262
|
+
|
|
178
263
|
/**
|
|
179
264
|
* Convert a ref-doc `examples` HTML fragment — prose interleaved with one or
|
|
180
265
|
* more `<div class="codehilite">…</div>` syntax-highlight blocks — into Markdown,
|
|
@@ -223,7 +308,8 @@ export interface ExampleSegmentation {
|
|
|
223
308
|
* Carve an `examples` HTML fragment into one segment per example it carries.
|
|
224
309
|
*
|
|
225
310
|
* A `<div class="codehilite">` block is a code region and the markup between
|
|
226
|
-
* two of them is a prose region
|
|
311
|
+
* two of them is a prose region, less any mangled `<code>lang\n...</code>`
|
|
312
|
+
* fence lifted out of it as a code region; inside either, a ` ``` ` line switches between
|
|
227
313
|
* code and prose, and an opener reached while already in code ends the running
|
|
228
314
|
* example and starts the next. Upstream writes several examples both ways — as
|
|
229
315
|
* several blocks, and as its own Markdown fences inside one block — so both
|
|
@@ -303,6 +389,13 @@ function trimBlankEdges(lines: readonly string[]): string[] {
|
|
|
303
389
|
return out;
|
|
304
390
|
}
|
|
305
391
|
|
|
392
|
+
// Prefer the full `description`; fall back to the one-line `brief` when prose is
|
|
393
|
+
// absent. Shared by every documented member kind so the summary source is
|
|
394
|
+
// consistent across functions, constants, variables, and properties.
|
|
395
|
+
export function summaryFor(brief: string, description: string): string {
|
|
396
|
+
return description.trim() !== "" ? description : brief;
|
|
397
|
+
}
|
|
398
|
+
|
|
306
399
|
export interface DocCommentParts {
|
|
307
400
|
summary: string;
|
|
308
401
|
// Present exactly when the source carried a deprecation tag; `""` is the bare
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { fnv1a64 } from "./fnv1a";
|
|
2
|
+
|
|
3
|
+
// A function slot whose upstream doc HTML is malformed badly enough to misread,
|
|
4
|
+
// replaced wholesale with authored HTML that keeps upstream's wording, or a
|
|
5
|
+
// property description that contradicts what the engine does. Each
|
|
6
|
+
// entry is pinned by the FNV-1a hash of the exact upstream HTML it replaces: the
|
|
7
|
+
// parse applies it only while the vendored doc still hashes to that value, so a
|
|
8
|
+
// fixed or reworded upstream doc wins by itself, and
|
|
9
|
+
// `doc-correction-provenance.test.ts` reds until the stale entry is deleted.
|
|
10
|
+
//
|
|
11
|
+
// Keyed `<function>#param:<name>`, `<function>#return:<name>`, or
|
|
12
|
+
// `<namespace>#property:<name>` (the ref-doc `PROPERTY` element's bare name).
|
|
13
|
+
export interface DocCorrection {
|
|
14
|
+
readonly upstreamHash: string;
|
|
15
|
+
readonly html: string;
|
|
16
|
+
readonly reason: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const li = (name: string, type: string, doc: string) =>
|
|
20
|
+
`<li><code>${name}</code> <span class="type">${type}</span> ${doc}</li>`;
|
|
21
|
+
|
|
22
|
+
export const DOC_CORRECTIONS: ReadonlyMap<string, DocCorrection> = new Map([
|
|
23
|
+
[
|
|
24
|
+
"graphics.get_adapter_info#return:info",
|
|
25
|
+
{
|
|
26
|
+
upstreamHash: "77028e82ec2d15bd",
|
|
27
|
+
reason:
|
|
28
|
+
"script_graphics.cpp indents the field table as preformatted text: the top-level fields run together as one paragraph, and the `limits` and `features` sub-tables are highlighted as code",
|
|
29
|
+
html: [
|
|
30
|
+
"table with the following fields:",
|
|
31
|
+
"<ul>",
|
|
32
|
+
li("family", "string", 'adapter family name (e.g. "opengl", "vulkan")'),
|
|
33
|
+
li("version_major", "number", "adapter API major version (e.g. 1 for Vulkan 1.4)"),
|
|
34
|
+
li("version_minor", "number", "adapter API minor version (e.g. 4 for Vulkan 1.4)"),
|
|
35
|
+
`<li><code>limits</code> <span class="type">table</span> hardware/driver limits:<ul>`,
|
|
36
|
+
li("max_texture_size_2d", "number", "max 2D texture dimension in texels"),
|
|
37
|
+
li("max_texture_size_3d", "number", "max 3D (volume) texture dimension in texels"),
|
|
38
|
+
li("max_texture_size_cube", "number", "max cube map face dimension in texels"),
|
|
39
|
+
li("max_texture_array_layers", "number", "max layers in an array texture"),
|
|
40
|
+
li("max_framebuffer_width", "number", "max framebuffer width in pixels"),
|
|
41
|
+
li("max_framebuffer_height", "number", "max framebuffer height in pixels"),
|
|
42
|
+
li("max_color_attachments", "number", "max simultaneous color attachments"),
|
|
43
|
+
li("max_samplers_per_stage", "number", "max texture samplers per shader stage"),
|
|
44
|
+
li("max_textures_per_stage", "number", "max sampled textures per shader stage"),
|
|
45
|
+
li("max_vertex_attributes", "number", "max vertex attributes"),
|
|
46
|
+
li("max_vertex_buffers", "number", "max vertex buffer bindings"),
|
|
47
|
+
li("max_compute_workgroup_size_x", "number", "max compute workgroup size (X)"),
|
|
48
|
+
li("max_compute_workgroup_size_y", "number", "max compute workgroup size (Y)"),
|
|
49
|
+
li("max_compute_workgroup_size_z", "number", "max compute workgroup size (Z)"),
|
|
50
|
+
li("max_compute_workgroup_invocations", "number", "max invocations per compute workgroup"),
|
|
51
|
+
li(
|
|
52
|
+
"max_compute_shared_memory_size",
|
|
53
|
+
"number",
|
|
54
|
+
"max shared memory per compute workgroup (bytes)",
|
|
55
|
+
),
|
|
56
|
+
li("max_uniform_buffer_range", "number", "max bindable uniform buffer range (bytes)"),
|
|
57
|
+
li("max_storage_buffer_range", "number", "max bindable storage buffer range (bytes)"),
|
|
58
|
+
"</ul></li>",
|
|
59
|
+
li("extensions", "table", "array of driver-reported extension name strings"),
|
|
60
|
+
`<li><code>features</code> <span class="type">table</span> array of supported context feature ids:<ul>`,
|
|
61
|
+
"<li><code>graphics.CONTEXT_FEATURE_MULTI_TARGET_RENDERING</code> multi-target rendering</li>",
|
|
62
|
+
"<li><code>graphics.CONTEXT_FEATURE_TEXTURE_ARRAY</code> texture arrays</li>",
|
|
63
|
+
"<li><code>graphics.CONTEXT_FEATURE_COMPUTE_SHADER</code> compute shaders</li>",
|
|
64
|
+
"<li><code>graphics.CONTEXT_FEATURE_STORAGE_BUFFER</code> storage buffers</li>",
|
|
65
|
+
"<li><code>graphics.CONTEXT_FEATURE_VSYNC</code> vertical sync</li>",
|
|
66
|
+
"<li><code>graphics.CONTEXT_FEATURE_INSTANCING</code> hardware instancing</li>",
|
|
67
|
+
"<li><code>graphics.CONTEXT_FEATURE_3D_TEXTURES</code> 3D (volume) textures</li>",
|
|
68
|
+
"<li><code>graphics.CONTEXT_FEATURE_ASTC_ARRAY_TEXTURES</code> ASTC compressed 2D array textures</li>",
|
|
69
|
+
"<li><code>graphics.CONTEXT_FEATURE_BLEND_EQUATION_MIN_MAX</code> min/max blend equations</li>",
|
|
70
|
+
"</ul></li>",
|
|
71
|
+
"</ul>",
|
|
72
|
+
].join("\n"),
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
"go#property:scale",
|
|
77
|
+
{
|
|
78
|
+
upstreamHash: "a7f5ba1b125d1fae",
|
|
79
|
+
reason:
|
|
80
|
+
"upstream calls it a uniform number, but the engine reads a vector3 back from `go.get` and applies a written number as a uniform scale",
|
|
81
|
+
html: "The scale of the game object. <code>go.get</code> returns a vector3; <code>go.set</code> and <code>go.animate</code> also take a number, which sets a uniform scale.",
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"label#property:scale",
|
|
86
|
+
{
|
|
87
|
+
upstreamHash: "5a15760073a8629d",
|
|
88
|
+
reason:
|
|
89
|
+
'upstream says a number is accepted, but `go.set` raises "must be a vmath.vector3" on one; only `go.animate` takes a number',
|
|
90
|
+
html: "The scale of the label. <code>go.get</code> returns and <code>go.set</code> takes a vector3; <code>go.animate</code> also takes a number, which sets a uniform scale.",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
export function docCorrectionKey(
|
|
96
|
+
owner: string,
|
|
97
|
+
slot: "param" | "return" | "property",
|
|
98
|
+
name: string,
|
|
99
|
+
): string {
|
|
100
|
+
return `${owner}#${slot}:${name}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The slot's doc with its correction applied, or `doc` itself when the slot has
|
|
104
|
+
// no entry or upstream no longer matches the pinned hash.
|
|
105
|
+
export function correctedDoc(key: string, doc: string): string {
|
|
106
|
+
const correction = DOC_CORRECTIONS.get(key);
|
|
107
|
+
return correction && fnv1a64(doc) === correction.upstreamHash ? correction.html : doc;
|
|
108
|
+
}
|