@geastack/compiler 1.0.48 → 1.0.62
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/README.md +57 -19
- package/dist/cli.js +2 -1
- package/dist/compiler.d.ts +1 -1
- package/dist/compiler.js +13 -6
- package/dist/conversion/derive.js +5 -0
- package/dist/conversion/native-field-view.d.ts +7 -0
- package/dist/conversion/native-field-view.js +50 -0
- package/dist/conversion/native-record-products.js +1 -0
- package/dist/conversion/native-view-origins.d.ts +1 -1
- package/dist/conversion/native-view-origins.js +5 -4
- package/dist/conversion/nodes.d.ts +9 -0
- package/dist/conversion/nodes.js +18 -0
- package/dist/conversion/record-view.d.ts +25 -1
- package/dist/conversion/record-view.js +61 -2
- package/dist/conversion/structural-plan.js +7 -6
- package/dist/ir/borrowed-field-reads.d.ts +30 -0
- package/dist/ir/borrowed-field-reads.js +218 -0
- package/dist/ir/borrowed-window-cells.d.ts +35 -0
- package/dist/ir/borrowed-window-cells.js +117 -0
- package/dist/ir/call-dispatch.js +21 -4
- package/dist/ir/callable-class-flow.js +269 -43
- package/dist/ir/captures.js +18 -1
- package/dist/ir/certify.js +14 -1
- package/dist/ir/construction-only-fields.d.ts +15 -1
- package/dist/ir/construction-only-fields.js +71 -3
- package/dist/ir/dead-logical-merge.d.ts +4 -0
- package/dist/ir/dead-logical-merge.js +89 -18
- package/dist/ir/dense-loops.d.ts +38 -4
- package/dist/ir/dense-loops.js +112 -17
- package/dist/ir/dense-read-windows.d.ts +42 -0
- package/dist/ir/dense-read-windows.js +137 -0
- package/dist/ir/facts.d.ts +12 -0
- package/dist/ir/facts.js +18 -2
- package/dist/ir/field-read-reuse.d.ts +71 -0
- package/dist/ir/field-read-reuse.js +430 -0
- package/dist/ir/hoist.d.ts +19 -2
- package/dist/ir/hoist.js +143 -24
- package/dist/ir/lower-narrow.js +19 -1
- package/dist/ir/model.d.ts +19 -0
- package/dist/ir/native-field-view-domains.d.ts +12 -2
- package/dist/ir/native-field-view-domains.js +51 -15
- package/dist/ir/native-field-view-facts.js +5 -2
- package/dist/ir/native-method-frames.js +15 -2
- package/dist/ir/plain-field-read.d.ts +31 -0
- package/dist/ir/plain-field-read.js +51 -0
- package/dist/ir/program-facts.d.ts +14 -0
- package/dist/ir/program-facts.js +85 -2
- package/dist/ir/proven-branches.js +8 -1
- package/dist/ir/publish-conversion-recipes.js +5 -1
- package/dist/ir/short-circuit-threading.d.ts +12 -4
- package/dist/ir/short-circuit-threading.js +124 -12
- package/dist/ir/stable-cell-reads.d.ts +24 -1
- package/dist/ir/stable-cell-reads.js +65 -42
- package/dist/ir/write-effects.d.ts +42 -0
- package/dist/ir/write-effects.js +208 -0
- package/dist/plugins/gea/contract.d.ts +3 -2
- package/dist/plugins/gea/contract.js +3 -1
- package/dist/plugins/gea/host.d.ts +7 -2
- package/dist/plugins/gea/host.js +25 -5
- package/dist/project-preparation.d.ts +11 -0
- package/dist/project-preparation.js +44 -0
- package/dist/projection/classes.d.ts +8 -0
- package/dist/projection/classes.js +112 -12
- package/dist/projection/dispatch.d.ts +24 -4
- package/dist/projection/dispatch.js +71 -2
- package/dist/projection/fields.js +2 -2
- package/dist/representation/model.d.ts +3 -0
- package/dist/representation/model.js +3 -0
- package/dist/representation/value-records.js +22 -0
- package/dist/semantics/frontend-timing.d.ts +9 -0
- package/dist/semantics/frontend-timing.js +43 -2
- package/dist/semantics/frontend.js +103 -7
- package/dist/semantics/model/operations.d.ts +7 -0
- package/dist/semantics/normalize/binding-fixpoint.js +7 -2
- package/dist/semantics/normalize/callable-data-write.js +6 -2
- package/dist/semantics/normalize/field-bindings.js +151 -111
- package/dist/semantics/normalize/flow/callable-reach.js +27 -0
- package/dist/semantics/normalize/flow/component-solver.js +23 -5
- package/dist/semantics/normalize/flow/source-record-data.js +6 -2
- package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
- package/dist/semantics/normalize/flow/source-value-session.js +207 -65
- package/dist/semantics/normalize/global-host-mutations.js +162 -1
- package/dist/semantics/normalize/parameter-bindings.js +16 -1
- package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
- package/dist/semantics/normalize/producers/erasure.js +13 -8
- package/dist/semantics/subclass-member-overlay-transform.d.ts +3 -2
- package/dist/semantics/subclass-member-overlay-transform.js +416 -316
- package/dist/semantics/typescript-tsgo.d.ts +20 -0
- package/dist/semantics/typescript-tsgo.js +832 -0
- package/dist/semantics/typescript.d.ts +0 -9
- package/dist/semantics/typescript.js +4 -1
- package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
- package/dist/targets/cpp/borrowed-call-entry.js +12 -2
- package/dist/targets/cpp/captures.js +4 -0
- package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
- package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
- package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
- package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
- package/dist/targets/cpp/conversions.js +1 -0
- package/dist/targets/cpp/emit-arrays.d.ts +5 -0
- package/dist/targets/cpp/emit-arrays.js +60 -10
- package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
- package/dist/targets/cpp/emit-binding-reference.js +26 -8
- package/dist/targets/cpp/emit-bindings.js +22 -0
- package/dist/targets/cpp/emit-callable.js +133 -16
- package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
- package/dist/targets/cpp/emit-carrier-members.js +24 -2
- package/dist/targets/cpp/emit-context.d.ts +97 -1
- package/dist/targets/cpp/emit-context.js +52 -0
- package/dist/targets/cpp/emit-equality.js +3 -0
- package/dist/targets/cpp/emit-narrowing.js +9 -0
- package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
- package/dist/targets/cpp/emit-native-field-view.js +87 -8
- package/dist/targets/cpp/emit-properties.js +139 -16
- package/dist/targets/cpp/emit-record-view.js +49 -22
- package/dist/targets/cpp/emit-return.js +5 -1
- package/dist/targets/cpp/emit-tonumber.js +4 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +4 -1
- package/dist/targets/cpp/emit.js +148 -6
- package/dist/targets/cpp/reactive-dependencies.js +100 -28
- package/dist/targets/cpp/translation-unit.js +71 -17
- package/dist/targets/cpp/virtual-methods.d.ts +2 -2
- package/dist/targets/cpp/virtual-methods.js +11 -3
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_runtime.h +400 -21
|
@@ -271,6 +271,15 @@ const sourceFilesByRoot = new Map();
|
|
|
271
271
|
* became a no-op for them. The fix is not to stop skipping `test` -- that
|
|
272
272
|
* would re-admit a real package's own test fixtures into its class index --
|
|
273
273
|
* it is to never skip an ancestor of the file actually being compiled.
|
|
274
|
+
*
|
|
275
|
+
* What such a directory is let in for is that program, not everything beside
|
|
276
|
+
* it: `test/runtime` holds some 1,600 independent programs, and indexing all
|
|
277
|
+
* of them as one package let a neighbour's class of the same name (dropped as
|
|
278
|
+
* a duplicate) or a neighbour's subclass (widening the union) change the
|
|
279
|
+
* overlay -- and the text, and every identity after it -- of a program that
|
|
280
|
+
* never mentions the neighbour. So the files found only through this override
|
|
281
|
+
* are `confined` (see `collectSourceFiles`) and indexed only when they belong
|
|
282
|
+
* to the compilation's own module graph (`programGraph`).
|
|
274
283
|
*/
|
|
275
284
|
const ancestryBetween = (root, filePath) => {
|
|
276
285
|
const stop = resolve(root);
|
|
@@ -300,14 +309,19 @@ const indexKey = (root, neverSkip) => neverSkip.size === 0 ? root : `${root}${[
|
|
|
300
309
|
* comment), so a `neverSkip` override must be part of the key -- keying on
|
|
301
310
|
* `root` alone would let the FIRST program compiled from a directory decide,
|
|
302
311
|
* for every later one, whether `test/runtime` exists.
|
|
312
|
+
*
|
|
313
|
+
* A file below a directory descended into only because of `neverSkip` is
|
|
314
|
+
* returned in `confined`, not `files`: whether it is indexed depends on the
|
|
315
|
+
* program being compiled (`buildPackageIndex`), not on the package.
|
|
303
316
|
*/
|
|
304
317
|
const collectSourceFiles = (root, neverSkip) => {
|
|
305
318
|
const key = indexKey(root, neverSkip);
|
|
306
319
|
const known = sourceFilesByRoot.get(key);
|
|
307
320
|
if (known)
|
|
308
321
|
return known;
|
|
309
|
-
const
|
|
310
|
-
const
|
|
322
|
+
const files = [];
|
|
323
|
+
const confined = [];
|
|
324
|
+
const walk = (dir, admitted) => {
|
|
311
325
|
let entries;
|
|
312
326
|
try {
|
|
313
327
|
entries = readdirSync(dir, { withFileTypes: true, encoding: 'utf8' });
|
|
@@ -320,18 +334,21 @@ const collectSourceFiles = (root, neverSkip) => {
|
|
|
320
334
|
continue;
|
|
321
335
|
if (entry.isDirectory()) {
|
|
322
336
|
const childPath = join(dir, entry.name);
|
|
323
|
-
|
|
337
|
+
const skipped = SKIP_DIRS.has(entry.name);
|
|
338
|
+
if (skipped && !neverSkip.has(childPath))
|
|
324
339
|
continue;
|
|
325
|
-
walk(childPath);
|
|
340
|
+
walk(childPath, admitted || skipped);
|
|
326
341
|
}
|
|
327
342
|
else if (/\.m?js$/.test(entry.name)) {
|
|
328
|
-
|
|
343
|
+
;
|
|
344
|
+
(admitted ? confined : files).push(join(dir, entry.name));
|
|
329
345
|
}
|
|
330
346
|
}
|
|
331
347
|
};
|
|
332
|
-
walk(root);
|
|
333
|
-
|
|
334
|
-
|
|
348
|
+
walk(root, false);
|
|
349
|
+
const found = { files, confined };
|
|
350
|
+
sourceFilesByRoot.set(key, found);
|
|
351
|
+
return found;
|
|
335
352
|
};
|
|
336
353
|
/**
|
|
337
354
|
* JSDoc's own vague-object special case, spelled as plain text: `{Object}`
|
|
@@ -642,7 +659,7 @@ const memberTypeTextsOf = (klass, file) => {
|
|
|
642
659
|
else if (entry.kind === 'object')
|
|
643
660
|
objectShape.set(name, entry.shape);
|
|
644
661
|
}
|
|
645
|
-
return { declaredNames, text, objectShape };
|
|
662
|
+
return { declaredNames, callableNames: methodNames, text, objectShape };
|
|
646
663
|
};
|
|
647
664
|
const readerCaches = new WeakMap();
|
|
648
665
|
const cachesFor = (read) => {
|
|
@@ -770,6 +787,7 @@ const scanPackageFile = (filePath, text) => {
|
|
|
770
787
|
exportName: classExportName(file, statement),
|
|
771
788
|
baseName,
|
|
772
789
|
declaredNames: evidence.declaredNames,
|
|
790
|
+
callableNames: evidence.callableNames,
|
|
773
791
|
ownMembers: evidence.text,
|
|
774
792
|
ownObjectShapes: evidence.objectShape
|
|
775
793
|
});
|
|
@@ -839,8 +857,24 @@ const compactScan = (scan) => {
|
|
|
839
857
|
return EMPTY_SCAN;
|
|
840
858
|
return { ...scan, externallyReadNames: [...new Set(scan.externallyReadNames)].map(sharedName) };
|
|
841
859
|
};
|
|
842
|
-
const buildPackageIndex = (root, read, neverSkip) => {
|
|
843
|
-
const
|
|
860
|
+
const buildPackageIndex = (root, read, neverSkip, graph, compiled) => {
|
|
861
|
+
const found = collectSourceFiles(root, neverSkip);
|
|
862
|
+
// a confined file is the program's own or not indexed at all (see `ancestryBetween`)
|
|
863
|
+
const confined = found.confined.filter((filePath) => graph.has(resolve(filePath)));
|
|
864
|
+
// A program that itself lives in a skipped directory is not the package it
|
|
865
|
+
// sits in: the package's other files are its scenery exactly as its
|
|
866
|
+
// directory's neighbours are, so they too are indexed only from its graph.
|
|
867
|
+
// Without this, any `.js` elsewhere under the root -- an untracked fixture,
|
|
868
|
+
// a vendored suite -- declaring a class of the same name dropped the
|
|
869
|
+
// program's own class as a duplicate, and a checkout holding such files
|
|
870
|
+
// emitted different text and identities than a clean one.
|
|
871
|
+
const programIsConfined = found.confined.some((filePath) => resolve(filePath) === compiled);
|
|
872
|
+
const files = programIsConfined ? found.files.filter((filePath) => graph.has(resolve(filePath))) : found.files;
|
|
873
|
+
const key = programIsConfined
|
|
874
|
+
? `${indexKey(root, neverSkip)}\n\n${[...files, ...confined].join('\n')}`
|
|
875
|
+
: confined.length === 0
|
|
876
|
+
? indexKey(root, neverSkip)
|
|
877
|
+
: `${indexKey(root, neverSkip)}\n${confined.join('\n')}`;
|
|
844
878
|
const cached = cachesFor(read).index.get(key);
|
|
845
879
|
if (cached)
|
|
846
880
|
return cached;
|
|
@@ -851,7 +885,7 @@ const buildPackageIndex = (root, read, neverSkip) => {
|
|
|
851
885
|
const externallyReadNames = new Set();
|
|
852
886
|
const constantDomainsByName = new Map();
|
|
853
887
|
const duplicateConstants = new Set();
|
|
854
|
-
for (const filePath of
|
|
888
|
+
for (const filePath of [...files, ...confined]) {
|
|
855
889
|
let text;
|
|
856
890
|
try {
|
|
857
891
|
text = read(filePath);
|
|
@@ -1169,334 +1203,400 @@ const joinedObjectRecordText = (index, shapes, ctx) => {
|
|
|
1169
1203
|
}
|
|
1170
1204
|
return fields.length > 0 ? `{${fields.join('; ')}}` : null;
|
|
1171
1205
|
};
|
|
1206
|
+
/**
|
|
1207
|
+
* The compilation's own module graph: its root files and every module they
|
|
1208
|
+
* import at runtime, as absolute paths. The files a skipped directory is let
|
|
1209
|
+
* in for (`ancestryBetween`) are indexed only from here, so what a program's
|
|
1210
|
+
* overlay reads depends on that program alone, whatever else shares its
|
|
1211
|
+
* directory.
|
|
1212
|
+
*/
|
|
1213
|
+
const programGraph = (roots, read) => {
|
|
1214
|
+
const graph = new Set();
|
|
1215
|
+
for (const rootFile of roots) {
|
|
1216
|
+
const start = resolve(rootFile);
|
|
1217
|
+
graph.add(start);
|
|
1218
|
+
for (const reached of modulesReachableFrom(start, read))
|
|
1219
|
+
graph.add(reached);
|
|
1220
|
+
}
|
|
1221
|
+
return graph;
|
|
1222
|
+
};
|
|
1172
1223
|
/**
|
|
1173
1224
|
* The overlay, reading declarers through `read` -- see `DeclarerReader`.
|
|
1174
1225
|
* `compiler.ts` builds one per compilation with that compilation's plugin
|
|
1175
|
-
* transforms; a caller with no plugins may pass `readFileSync`
|
|
1226
|
+
* transforms and root files; a caller with no plugins may pass `readFileSync`
|
|
1227
|
+
* itself. Without `roots`, the file being transformed stands for the program.
|
|
1176
1228
|
*/
|
|
1177
|
-
export const createSubclassMemberOverlayTransform = (read
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1229
|
+
export const createSubclassMemberOverlayTransform = (read, roots = []) => {
|
|
1230
|
+
let rootsGraph = null;
|
|
1231
|
+
const graphFor = (fileName) => {
|
|
1232
|
+
if (roots.length === 0)
|
|
1233
|
+
return programGraph([fileName], read);
|
|
1234
|
+
if (rootsGraph === null)
|
|
1235
|
+
rootsGraph = programGraph(roots, read);
|
|
1236
|
+
return rootsGraph;
|
|
1237
|
+
};
|
|
1238
|
+
return (input) => {
|
|
1239
|
+
if (!/\.m?js$/.test(input.fileName))
|
|
1240
|
+
return null;
|
|
1241
|
+
const root = packageRootFor(input.fileName);
|
|
1242
|
+
if (!root)
|
|
1243
|
+
return null;
|
|
1244
|
+
const here = resolve(input.fileName);
|
|
1245
|
+
const file = ts.createSourceFile(input.fileName, input.text, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
1246
|
+
// Every edit below is made at a top-level named class, and the index is
|
|
1247
|
+
// read nowhere else. Building it reads and transforms every source file of
|
|
1248
|
+
// the package, so a file declaring no class does not pay for it.
|
|
1249
|
+
if (!file.statements.some((statement) => ts.isClassDeclaration(statement) && statement.name !== undefined))
|
|
1250
|
+
return null;
|
|
1251
|
+
const index = buildPackageIndex(root, read, ancestryBetween(root, input.fileName), graphFor(input.fileName), here);
|
|
1252
|
+
const boundHere = new Set();
|
|
1253
|
+
let leadingImportEnd = 0;
|
|
1254
|
+
let stillLeading = true;
|
|
1255
|
+
for (const statement of file.statements) {
|
|
1256
|
+
if (ts.isImportDeclaration(statement)) {
|
|
1257
|
+
if (stillLeading)
|
|
1258
|
+
leadingImportEnd = statement.getEnd();
|
|
1259
|
+
if (statement.importClause) {
|
|
1260
|
+
const bindings = statement.importClause.namedBindings;
|
|
1261
|
+
if (bindings && ts.isNamedImports(bindings))
|
|
1262
|
+
for (const element of bindings.elements)
|
|
1263
|
+
boundHere.add(element.name.text);
|
|
1264
|
+
if (statement.importClause.name)
|
|
1265
|
+
boundHere.add(statement.importClause.name.text);
|
|
1266
|
+
}
|
|
1267
|
+
continue;
|
|
1268
|
+
}
|
|
1269
|
+
stillLeading = false;
|
|
1270
|
+
if ((ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement)) && statement.name)
|
|
1271
|
+
boundHere.add(statement.name.text);
|
|
1272
|
+
else if (ts.isVariableStatement(statement)) {
|
|
1273
|
+
for (const declaration of statement.declarationList.declarations)
|
|
1274
|
+
if (ts.isIdentifier(declaration.name))
|
|
1275
|
+
boundHere.add(declaration.name.text);
|
|
1205
1276
|
}
|
|
1206
|
-
continue;
|
|
1207
|
-
}
|
|
1208
|
-
stillLeading = false;
|
|
1209
|
-
if ((ts.isClassDeclaration(statement) || ts.isFunctionDeclaration(statement)) && statement.name)
|
|
1210
|
-
boundHere.add(statement.name.text);
|
|
1211
|
-
else if (ts.isVariableStatement(statement)) {
|
|
1212
|
-
for (const declaration of statement.declarationList.declarations)
|
|
1213
|
-
if (ts.isIdentifier(declaration.name))
|
|
1214
|
-
boundHere.add(declaration.name.text);
|
|
1215
1277
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1278
|
+
// TypeScript does not attach a field's JSDoc when its comment starts on
|
|
1279
|
+
// the class opening-brace line. Every member insertion starts a new line
|
|
1280
|
+
// so the first generated field retains the type this transform states.
|
|
1281
|
+
const edits = [];
|
|
1282
|
+
const importLines = new Map();
|
|
1283
|
+
/**
|
|
1284
|
+
* RESTATE what this class declares for itself.
|
|
1285
|
+
*
|
|
1286
|
+
* The overlay above writes a member onto an ANCESTOR, and TypeScript treats
|
|
1287
|
+
* a JS `this.x = ...` whose base declares `x` as an ASSIGNMENT rather than
|
|
1288
|
+
* a declaration -- so the ancestor's field silently replaces the declarer's
|
|
1289
|
+
* own `@type` as the answer for the declarer's own reads. With a
|
|
1290
|
+
* near-universal `Emitter` as that ancestor, `Item.id`
|
|
1291
|
+
* (`@type {string}`) read back `string | undefined` and `Item.origin`
|
|
1292
|
+
* (`@type {?Point}`) read back `Point | null | undefined` -- the
|
|
1293
|
+
* `| undefined` this module adds for soundness at a BASE-typed read,
|
|
1294
|
+
* charged to a class where the constructor assigns the member
|
|
1295
|
+
* unconditionally and it can never be absent.
|
|
1296
|
+
*
|
|
1297
|
+
* A class may redeclare an inherited property with a narrower type, so
|
|
1298
|
+
* both facts can be stated at once: the base keeps the union that makes a
|
|
1299
|
+
* base-typed read resolve, and the declarer restates its own, which is
|
|
1300
|
+
* what its own reads then see. Only a member with ONE unambiguous text and
|
|
1301
|
+
* no unresolvable or not-yet-imported name in it -- this adds no `@import`
|
|
1302
|
+
* of its own, so a name must already be in scope in the declarer's file.
|
|
1303
|
+
*
|
|
1304
|
+
* Only a field can be redeclared that way. A member an ancestor declares as
|
|
1305
|
+
* an accessor or a method stays the ancestor's: `this.texture = ...` in a
|
|
1306
|
+
* subclass of a class with `get texture()`/`set texture()` assigns through
|
|
1307
|
+
* the setter, and a restated `texture;` field is a checker error (an
|
|
1308
|
+
* accessor overridden as an instance property) that leaves the program
|
|
1309
|
+
* uncertified.
|
|
1310
|
+
*/
|
|
1311
|
+
const restatementsFor = (statement, info) => {
|
|
1312
|
+
if (process.env['GEA_NO_RESTATE'])
|
|
1313
|
+
return [];
|
|
1314
|
+
if (!info.baseName || !index.classesByName.has(info.baseName))
|
|
1315
|
+
return [];
|
|
1316
|
+
if (index.untrustedClassNames.has(info.name))
|
|
1317
|
+
return [];
|
|
1318
|
+
const declaredHere = new Set(statement.members.map((member) => (member.name && ts.isIdentifier(member.name) ? member.name.text : '')));
|
|
1319
|
+
const inheritedCallables = new Set();
|
|
1320
|
+
// a heritage cycle (two classes naming each other) ends the walk rather than looping
|
|
1321
|
+
const walked = new Set([info.name]);
|
|
1322
|
+
for (let ancestorName = info.baseName; ancestorName !== null && !walked.has(ancestorName);) {
|
|
1323
|
+
walked.add(ancestorName);
|
|
1324
|
+
const ancestor = index.classesByName.get(ancestorName);
|
|
1325
|
+
if (!ancestor)
|
|
1326
|
+
break;
|
|
1327
|
+
for (const name of ancestor.callableNames)
|
|
1328
|
+
inheritedCallables.add(name);
|
|
1329
|
+
ancestorName = ancestor.baseName;
|
|
1330
|
+
}
|
|
1331
|
+
const out = [];
|
|
1332
|
+
for (const name of [...info.ownMembers.keys()].sort()) {
|
|
1333
|
+
if (!index.externallyReadNames.has(name))
|
|
1334
|
+
continue;
|
|
1335
|
+
if (declaredHere.has(name) || inheritedCallables.has(name))
|
|
1336
|
+
continue;
|
|
1337
|
+
const texts = info.ownMembers.get(name);
|
|
1338
|
+
if (!texts || texts.length !== 1)
|
|
1339
|
+
continue;
|
|
1340
|
+
const text = texts[0];
|
|
1341
|
+
if (text.length === 0 || text.includes('*/'))
|
|
1342
|
+
continue;
|
|
1343
|
+
const foreign = foreignNamesIn(text);
|
|
1344
|
+
if (!foreign.every((foreignName) => index.classesByName.has(foreignName) && boundHere.has(foreignName)))
|
|
1345
|
+
continue;
|
|
1346
|
+
out.push(`\t/** @type {${text}} */\n\t${name};\n`);
|
|
1347
|
+
}
|
|
1348
|
+
// An object literal the class assigns (`this.parameters = { width: width }`) is its own record just the same:
|
|
1349
|
+
// restated in the literal's own property order, so the record keeps the layout the literal gives it.
|
|
1350
|
+
for (const name of [...info.ownObjectShapes.keys()].sort()) {
|
|
1351
|
+
if (!index.externallyReadNames.has(name))
|
|
1352
|
+
continue;
|
|
1353
|
+
if (declaredHere.has(name) || inheritedCallables.has(name))
|
|
1354
|
+
continue;
|
|
1355
|
+
const shape = info.ownObjectShapes.get(name);
|
|
1356
|
+
if (!shape || shape.size === 0)
|
|
1357
|
+
continue;
|
|
1358
|
+
const properties = [...shape].map(([property, text]) => `${property}: ${text}`);
|
|
1359
|
+
const text = `{${properties.join('; ')}}`;
|
|
1360
|
+
if (text.includes('*/'))
|
|
1361
|
+
continue;
|
|
1362
|
+
const foreign = foreignNamesIn([...shape.values()].join(' '));
|
|
1363
|
+
if (!foreign.every((foreignName) => index.classesByName.has(foreignName) && boundHere.has(foreignName)))
|
|
1364
|
+
continue;
|
|
1365
|
+
out.push(`\t/** @type {${text}} */\n\t${name};\n`);
|
|
1366
|
+
}
|
|
1367
|
+
return out;
|
|
1368
|
+
};
|
|
1369
|
+
for (const statement of file.statements) {
|
|
1370
|
+
if (!ts.isClassDeclaration(statement) || !statement.name)
|
|
1259
1371
|
continue;
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1372
|
+
const baseInfo = index.classesByName.get(statement.name.text);
|
|
1373
|
+
if (!baseInfo || resolve(baseInfo.filePath) !== here)
|
|
1262
1374
|
continue;
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1375
|
+
const restated = restatementsFor(statement, baseInfo);
|
|
1376
|
+
const descendants = transitiveSubclassesOf(index, statement.name.text);
|
|
1377
|
+
if (descendants.length === 0) {
|
|
1378
|
+
if (restated.length > 0)
|
|
1379
|
+
edits.push({ at: statement.members.pos, text: '\n' + restated.join('') });
|
|
1265
1380
|
continue;
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
const restated = restatementsFor(statement, baseInfo);
|
|
1277
|
-
const descendants = transitiveSubclassesOf(index, statement.name.text);
|
|
1278
|
-
if (descendants.length === 0) {
|
|
1279
|
-
if (restated.length > 0)
|
|
1280
|
-
edits.push({ at: statement.members.pos, text: '\n' + restated.join('') });
|
|
1281
|
-
continue;
|
|
1282
|
-
}
|
|
1283
|
-
// Refuse the WHOLE base when its own name or a descendant's could be the
|
|
1284
|
-
// target of a heritage clause this scan could not resolve -- there may
|
|
1285
|
-
// be a subclass in this hierarchy it never found.
|
|
1286
|
-
const hierarchyNames = [statement.name.text, ...descendants.map((d) => d.name)];
|
|
1287
|
-
const refusedHierarchy = index.unresolvedHeritageTexts.some((text) => hierarchyNames.some((name) => wholeWordPresent(text, name))) ||
|
|
1288
|
-
index.untrustedClassNames.has(statement.name.text);
|
|
1289
|
-
if (refusedHierarchy) {
|
|
1290
|
-
if (restated.length > 0)
|
|
1291
|
-
edits.push({ at: statement.members.pos, text: '\n' + restated.join('') });
|
|
1292
|
-
continue;
|
|
1293
|
-
}
|
|
1294
|
-
const liveEvidence = memberTypeTextsOf(statement, file);
|
|
1295
|
-
const alreadyDeclared = new Set([
|
|
1296
|
-
...liveEvidence.declaredNames,
|
|
1297
|
-
...baseInfo.declaredNames,
|
|
1298
|
-
...liveEvidence.text.keys(),
|
|
1299
|
-
...liveEvidence.objectShape.keys(),
|
|
1300
|
-
...baseInfo.ownMembers.keys(),
|
|
1301
|
-
...baseInfo.ownObjectShapes.keys()
|
|
1302
|
-
]);
|
|
1303
|
-
// A member an ancestor already declares is already readable through this
|
|
1304
|
-
// class. Re-declaring it here from a descendant's writes does more than
|
|
1305
|
-
// make that evidence visible: it shadows the inherited declaration with
|
|
1306
|
-
// the descendant union. A `Sprite` was given
|
|
1307
|
-
// `autoUpdate: false | undefined` from one specialized descendant,
|
|
1308
|
-
// replacing `Item.autoUpdate: boolean` and making every Sprite
|
|
1309
|
-
// structurally incompatible with Item. Walk the real heritage chain
|
|
1310
|
-
// and keep those inherited declarations authoritative at every
|
|
1311
|
-
// intermediate class.
|
|
1312
|
-
let ancestorName = baseInfo.baseName;
|
|
1313
|
-
while (ancestorName) {
|
|
1314
|
-
const ancestor = index.classesByName.get(ancestorName);
|
|
1315
|
-
if (!ancestor)
|
|
1316
|
-
break;
|
|
1317
|
-
for (const name of ancestor.declaredNames)
|
|
1318
|
-
alreadyDeclared.add(name);
|
|
1319
|
-
for (const name of ancestor.ownMembers.keys())
|
|
1320
|
-
alreadyDeclared.add(name);
|
|
1321
|
-
for (const name of ancestor.ownObjectShapes.keys())
|
|
1322
|
-
alreadyDeclared.add(name);
|
|
1323
|
-
ancestorName = ancestor.baseName;
|
|
1324
|
-
}
|
|
1325
|
-
const candidateNames = new Set();
|
|
1326
|
-
for (const descendant of descendants) {
|
|
1327
|
-
if (index.untrustedClassNames.has(descendant.name))
|
|
1381
|
+
}
|
|
1382
|
+
// Refuse the WHOLE base when its own name or a descendant's could be the
|
|
1383
|
+
// target of a heritage clause this scan could not resolve -- there may
|
|
1384
|
+
// be a subclass in this hierarchy it never found.
|
|
1385
|
+
const hierarchyNames = [statement.name.text, ...descendants.map((d) => d.name)];
|
|
1386
|
+
const refusedHierarchy = index.unresolvedHeritageTexts.some((text) => hierarchyNames.some((name) => wholeWordPresent(text, name))) ||
|
|
1387
|
+
index.untrustedClassNames.has(statement.name.text);
|
|
1388
|
+
if (refusedHierarchy) {
|
|
1389
|
+
if (restated.length > 0)
|
|
1390
|
+
edits.push({ at: statement.members.pos, text: '\n' + restated.join('') });
|
|
1328
1391
|
continue;
|
|
1329
|
-
for (const name of descendant.ownMembers.keys()) {
|
|
1330
|
-
if (index.externallyReadNames.has(name))
|
|
1331
|
-
candidateNames.add(name);
|
|
1332
1392
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1393
|
+
const liveEvidence = memberTypeTextsOf(statement, file);
|
|
1394
|
+
const alreadyDeclared = new Set([
|
|
1395
|
+
...liveEvidence.declaredNames,
|
|
1396
|
+
...baseInfo.declaredNames,
|
|
1397
|
+
...liveEvidence.text.keys(),
|
|
1398
|
+
...liveEvidence.objectShape.keys(),
|
|
1399
|
+
...baseInfo.ownMembers.keys(),
|
|
1400
|
+
...baseInfo.ownObjectShapes.keys()
|
|
1401
|
+
]);
|
|
1402
|
+
// A member an ancestor already declares is already readable through this
|
|
1403
|
+
// class. Re-declaring it here from a descendant's writes does more than
|
|
1404
|
+
// make that evidence visible: it shadows the inherited declaration with
|
|
1405
|
+
// the descendant union. A `Sprite` was given
|
|
1406
|
+
// `autoUpdate: false | undefined` from one specialized descendant,
|
|
1407
|
+
// replacing `Item.autoUpdate: boolean` and making every Sprite
|
|
1408
|
+
// structurally incompatible with Item. Walk the real heritage chain
|
|
1409
|
+
// and keep those inherited declarations authoritative at every
|
|
1410
|
+
// intermediate class.
|
|
1411
|
+
let ancestorName = baseInfo.baseName;
|
|
1412
|
+
while (ancestorName) {
|
|
1413
|
+
const ancestor = index.classesByName.get(ancestorName);
|
|
1414
|
+
if (!ancestor)
|
|
1415
|
+
break;
|
|
1416
|
+
for (const name of ancestor.declaredNames)
|
|
1417
|
+
alreadyDeclared.add(name);
|
|
1418
|
+
for (const name of ancestor.ownMembers.keys())
|
|
1419
|
+
alreadyDeclared.add(name);
|
|
1420
|
+
for (const name of ancestor.ownObjectShapes.keys())
|
|
1421
|
+
alreadyDeclared.add(name);
|
|
1422
|
+
ancestorName = ancestor.baseName;
|
|
1336
1423
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
if (objectShapeDescendants.length > 0 && textShapeDescendants.length > 0)
|
|
1356
|
-
continue;
|
|
1357
|
-
if (objectShapeDescendants.length > 0) {
|
|
1358
|
-
const joined = joinedObjectRecordText(index, objectShapeDescendants.map((d) => d.ownObjectShapes.get(name)), { read, boundHere, importLines, hereDir, here });
|
|
1359
|
-
if (joined)
|
|
1360
|
-
fieldTexts.push(`\t/** @type {${joined} | undefined}\n\t * @geaSubclassMemberOverlay */\n\t${name};\n`);
|
|
1424
|
+
const candidateNames = new Set();
|
|
1425
|
+
for (const descendant of descendants) {
|
|
1426
|
+
if (index.untrustedClassNames.has(descendant.name))
|
|
1427
|
+
continue;
|
|
1428
|
+
for (const name of descendant.ownMembers.keys()) {
|
|
1429
|
+
if (index.externallyReadNames.has(name))
|
|
1430
|
+
candidateNames.add(name);
|
|
1431
|
+
}
|
|
1432
|
+
for (const name of descendant.ownObjectShapes.keys()) {
|
|
1433
|
+
if (index.externallyReadNames.has(name))
|
|
1434
|
+
candidateNames.add(name);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
for (const name of alreadyDeclared)
|
|
1438
|
+
candidateNames.delete(name);
|
|
1439
|
+
if (candidateNames.size === 0) {
|
|
1440
|
+
if (restated.length > 0)
|
|
1441
|
+
edits.push({ at: statement.members.pos, text: '\n' + restated.join('') });
|
|
1361
1442
|
continue;
|
|
1362
1443
|
}
|
|
1363
|
-
const
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
// what that declarer actually assigns.
|
|
1375
|
-
//
|
|
1376
|
-
// Measured: `Item.parent` is `@type {?Item}`, and that
|
|
1377
|
-
// candidate is refused by `modulesReachableFrom` (importing `Item`
|
|
1378
|
-
// into `Emitter.js` closes a cycle) -- while an unrelated
|
|
1379
|
-
// class's boolean `parent` survives. The overlay wrote `/** @type
|
|
1380
|
-
// {boolean | undefined} */ parent;` onto `Emitter`, and because
|
|
1381
|
-
// TypeScript treats a JS `this.x = ...` whose base declares `x` as an
|
|
1382
|
-
// ASSIGNMENT rather than a declaration, `Item`'s own
|
|
1383
|
-
// `@type {?Item}` stopped meaning anything: `this.parent` in
|
|
1384
|
-
// `Item.js` typed `boolean | undefined`. Not a widening -- a wrong
|
|
1385
|
-
// answer, and one no downstream census can see is wrong.
|
|
1386
|
-
//
|
|
1387
|
-
// The header already stated the intended rule for the whole-member case
|
|
1388
|
-
// ("if EVERY declarer refuses, the member is left exactly as `any`");
|
|
1389
|
-
// this is the same rule applied to a PARTIAL refusal, which is the only
|
|
1390
|
-
// reading under which the union is still the fact the header claims.
|
|
1391
|
-
let refusedDeclarer = false;
|
|
1392
|
-
for (const descendant of descendants) {
|
|
1393
|
-
const texts = descendant.ownMembers.get(name);
|
|
1394
|
-
if (!texts)
|
|
1444
|
+
const hereDir = dirname(here);
|
|
1445
|
+
const fieldTexts = [...restated];
|
|
1446
|
+
for (const name of [...candidateNames].sort()) {
|
|
1447
|
+
const objectShapeDescendants = descendants.filter((d) => !index.untrustedClassNames.has(d.name) && d.ownObjectShapes.has(name));
|
|
1448
|
+
const textShapeDescendants = descendants.filter((d) => !index.untrustedClassNames.has(d.name) && d.ownMembers.has(name));
|
|
1449
|
+
// Mixed evidence -- some declarer states a scalar/reference, another
|
|
1450
|
+
// an object literal, for the same name -- is ambiguous the same way a
|
|
1451
|
+
// second differently-shaped assignment within ONE class is
|
|
1452
|
+
// (`memberTypeTextsOf`'s own `recordObjectLiteral`): refuse rather
|
|
1453
|
+
// than guess which shape a caller reaching the member actually sees.
|
|
1454
|
+
if (objectShapeDescendants.length > 0 && textShapeDescendants.length > 0)
|
|
1395
1455
|
continue;
|
|
1396
|
-
if (
|
|
1397
|
-
|
|
1456
|
+
if (objectShapeDescendants.length > 0) {
|
|
1457
|
+
const joined = joinedObjectRecordText(index, objectShapeDescendants.map((d) => d.ownObjectShapes.get(name)), { read, boundHere, importLines, hereDir, here });
|
|
1458
|
+
if (joined)
|
|
1459
|
+
fieldTexts.push(`\t/** @type {${joined} | undefined}\n\t * @geaSubclassMemberOverlay */\n\t${name};\n`);
|
|
1398
1460
|
continue;
|
|
1399
1461
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1462
|
+
const typeParts = [];
|
|
1463
|
+
const neededImports = [];
|
|
1464
|
+
// ALL-OR-NONE.
|
|
1465
|
+
//
|
|
1466
|
+
// Every per-candidate refusal below used to `continue` and let the
|
|
1467
|
+
// REMAINING declarers form the union. That is not the smaller answer it
|
|
1468
|
+
// reads as -- it is a DIFFERENT one. The fact this module states is
|
|
1469
|
+
// "the member holds what SOME declarer put there, or `undefined`", and
|
|
1470
|
+
// it is sound only as an over-approximation; dropping a declarer makes
|
|
1471
|
+
// it a SUBSET, and the field it writes onto `Base` then shadows every
|
|
1472
|
+
// declarer's own precise declaration with a type that does not contain
|
|
1473
|
+
// what that declarer actually assigns.
|
|
1474
|
+
//
|
|
1475
|
+
// Measured: `Item.parent` is `@type {?Item}`, and that
|
|
1476
|
+
// candidate is refused by `modulesReachableFrom` (importing `Item`
|
|
1477
|
+
// into `Emitter.js` closes a cycle) -- while an unrelated
|
|
1478
|
+
// class's boolean `parent` survives. The overlay wrote `/** @type
|
|
1479
|
+
// {boolean | undefined} */ parent;` onto `Emitter`, and because
|
|
1480
|
+
// TypeScript treats a JS `this.x = ...` whose base declares `x` as an
|
|
1481
|
+
// ASSIGNMENT rather than a declaration, `Item`'s own
|
|
1482
|
+
// `@type {?Item}` stopped meaning anything: `this.parent` in
|
|
1483
|
+
// `Item.js` typed `boolean | undefined`. Not a widening -- a wrong
|
|
1484
|
+
// answer, and one no downstream census can see is wrong.
|
|
1485
|
+
//
|
|
1486
|
+
// The header already stated the intended rule for the whole-member case
|
|
1487
|
+
// ("if EVERY declarer refuses, the member is left exactly as `any`");
|
|
1488
|
+
// this is the same rule applied to a PARTIAL refusal, which is the only
|
|
1489
|
+
// reading under which the union is still the fact the header claims.
|
|
1490
|
+
let refusedDeclarer = false;
|
|
1491
|
+
for (const descendant of descendants) {
|
|
1492
|
+
const texts = descendant.ownMembers.get(name);
|
|
1493
|
+
if (!texts)
|
|
1419
1494
|
continue;
|
|
1420
|
-
|
|
1421
|
-
// An import edge this candidate would need must not close a cycle:
|
|
1422
|
-
// if the class the candidate names is a file that can ALREADY
|
|
1423
|
-
// reach `here` (this base's own file) through the package's real
|
|
1424
|
-
// runtime imports, adding the reverse edge closes a loop and the
|
|
1425
|
-
// checker answers `any` for everything caught in it -- see
|
|
1426
|
-
// `modulesReachableFrom`'s own comment. Refuses just this ONE
|
|
1427
|
-
// candidate, the same granularity as the unresolvable-name check
|
|
1428
|
-
// above: a different candidate for the same member that names an
|
|
1429
|
-
// acyclic type is unaffected.
|
|
1430
|
-
if (foreignTypeNames.some((foreignName) => {
|
|
1431
|
-
const info = index.classesByName.get(foreignName);
|
|
1432
|
-
if (!info)
|
|
1433
|
-
return false;
|
|
1434
|
-
const targetPath = resolve(info.filePath);
|
|
1435
|
-
return targetPath !== here && modulesReachableFrom(targetPath, read).has(here);
|
|
1436
|
-
})) {
|
|
1495
|
+
if (index.untrustedClassNames.has(descendant.name)) {
|
|
1437
1496
|
refusedDeclarer = true;
|
|
1438
1497
|
continue;
|
|
1439
1498
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
|
|
1499
|
+
for (const statedText of texts) {
|
|
1500
|
+
const candidateText = withConstantDomains(index, statedText);
|
|
1501
|
+
const foreignTypeNames = foreignNamesIn(candidateText);
|
|
1502
|
+
// Every foreign name the text ITSELF mentions (a boolean literal
|
|
1503
|
+
// mentions none) must resolve to a class this package actually
|
|
1504
|
+
// declares -- an unresolvable one (an external library type, a
|
|
1505
|
+
// type alias, a generic parameter) refuses just this ONE
|
|
1506
|
+
// candidate rather than guessing at it. The declaring subclass's
|
|
1507
|
+
// OWN name is never needed here: the text names what the field
|
|
1508
|
+
// holds, not who assigned it.
|
|
1509
|
+
if (!foreignTypeNames.every((foreignName) => {
|
|
1510
|
+
const info = index.classesByName.get(foreignName);
|
|
1511
|
+
return info !== undefined && (resolve(info.filePath) === here || info.exportName !== null);
|
|
1512
|
+
})) {
|
|
1513
|
+
refusedDeclarer = true;
|
|
1514
|
+
continue;
|
|
1515
|
+
}
|
|
1516
|
+
if (foreignTypeNames.some((foreignName) => boundHere.has(foreignName) && !importLines.has(foreignName))) {
|
|
1517
|
+
refusedDeclarer = true;
|
|
1518
|
+
continue;
|
|
1519
|
+
}
|
|
1520
|
+
// An import edge this candidate would need must not close a cycle:
|
|
1521
|
+
// if the class the candidate names is a file that can ALREADY
|
|
1522
|
+
// reach `here` (this base's own file) through the package's real
|
|
1523
|
+
// runtime imports, adding the reverse edge closes a loop and the
|
|
1524
|
+
// checker answers `any` for everything caught in it -- see
|
|
1525
|
+
// `modulesReachableFrom`'s own comment. Refuses just this ONE
|
|
1526
|
+
// candidate, the same granularity as the unresolvable-name check
|
|
1527
|
+
// above: a different candidate for the same member that names an
|
|
1528
|
+
// acyclic type is unaffected.
|
|
1529
|
+
if (foreignTypeNames.some((foreignName) => {
|
|
1530
|
+
const info = index.classesByName.get(foreignName);
|
|
1531
|
+
if (!info)
|
|
1532
|
+
return false;
|
|
1533
|
+
const targetPath = resolve(info.filePath);
|
|
1534
|
+
return targetPath !== here && modulesReachableFrom(targetPath, read).has(here);
|
|
1535
|
+
})) {
|
|
1536
|
+
refusedDeclarer = true;
|
|
1537
|
+
continue;
|
|
1538
|
+
}
|
|
1539
|
+
typeParts.push(candidateText);
|
|
1540
|
+
for (const className of foreignTypeNames) {
|
|
1541
|
+
const info = index.classesByName.get(className);
|
|
1542
|
+
if (info)
|
|
1543
|
+
neededImports.push(info);
|
|
1544
|
+
}
|
|
1445
1545
|
}
|
|
1446
1546
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
if (!shareCommonAncestor(index, neededImports.map((entry) => entry.name)))
|
|
1475
|
-
continue;
|
|
1476
|
-
for (const info of neededImports) {
|
|
1477
|
-
if (resolve(info.filePath) === here || importLines.has(info.name))
|
|
1547
|
+
if (refusedDeclarer || typeParts.length === 0)
|
|
1548
|
+
continue;
|
|
1549
|
+
// A reference-typed candidate is sound to STATE (the union over-
|
|
1550
|
+
// approximates, per this file's own header) but is only sound to
|
|
1551
|
+
// ADD to Base without also corrupting what its OWN declaring
|
|
1552
|
+
// subclasses read: TypeScript's checker gives an unannotated
|
|
1553
|
+
// `this.x = ...` in a subclass the type Base now declares, not the
|
|
1554
|
+
// narrower type that assignment's own shape implies. When every
|
|
1555
|
+
// declarer of this member is drawn from the SAME inheritance lineage
|
|
1556
|
+
// (`shareCommonAncestor`), a caller reaching the member through any
|
|
1557
|
+
// union member still resolves the SAME inherited method -- no
|
|
1558
|
+
// precision lost, no signature ambiguity. When two declarers are
|
|
1559
|
+
// UNRELATED classes that merely reuse a member NAME
|
|
1560
|
+
// (`Item.transform: Transform3` vs `Image.transform: Transform2` --
|
|
1561
|
+
// both root classes, both direct descendants of a near-universal
|
|
1562
|
+
// `Emitter`, sharing a name by coincidence, not a relationship),
|
|
1563
|
+
// each contributes its own same-named method with a different
|
|
1564
|
+
// signature; overlaying the union onto `Emitter` silently
|
|
1565
|
+
// widens `Item`'s own `this.transform` from a precise `Transform3` to
|
|
1566
|
+
// `Transform2 | Transform3 | undefined`, and calling a method
|
|
1567
|
+
// through that union asks `derive.ts` for a carrier no nominal class
|
|
1568
|
+
// reduction covers -- `unresolved-reaches-materialization` fires,
|
|
1569
|
+
// correctly (measured before this check existed: new violations at every
|
|
1570
|
+
// `.transform.copy`/`.transform.multiply` call site). This is
|
|
1571
|
+
// a purely structural class-hierarchy test -- see
|
|
1572
|
+
// `shareCommonAncestor`'s own comment -- never a name or library check.
|
|
1573
|
+
if (!shareCommonAncestor(index, neededImports.map((entry) => entry.name)))
|
|
1478
1574
|
continue;
|
|
1479
|
-
|
|
1575
|
+
for (const info of neededImports) {
|
|
1576
|
+
if (resolve(info.filePath) === here || importLines.has(info.name))
|
|
1577
|
+
continue;
|
|
1578
|
+
importLines.set(info.name, classImportLine(info, hereDir));
|
|
1579
|
+
}
|
|
1580
|
+
typeParts.push('undefined');
|
|
1581
|
+
fieldTexts.push(`\t/** @type {${typeParts.join(' | ')}}\n\t * @geaSubclassMemberOverlay */\n\t${name};\n`);
|
|
1480
1582
|
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1583
|
+
if (fieldTexts.length === 0)
|
|
1584
|
+
continue;
|
|
1585
|
+
edits.push({ at: statement.members.pos, text: '\n' + fieldTexts.join('') });
|
|
1483
1586
|
}
|
|
1484
|
-
if (
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
for (const edit of edits)
|
|
1500
|
-
text = text.slice(0, edit.at) + edit.text + text.slice(edit.at);
|
|
1501
|
-
return text;
|
|
1587
|
+
if (edits.length === 0)
|
|
1588
|
+
return null;
|
|
1589
|
+
if (importLines.size > 0) {
|
|
1590
|
+
const block = `\n/**\n${[...importLines.values()]
|
|
1591
|
+
.sort()
|
|
1592
|
+
.map((line) => ` * ${line}`)
|
|
1593
|
+
.join('\n')}\n */\n`;
|
|
1594
|
+
edits.push({ at: leadingImportEnd, text: block });
|
|
1595
|
+
}
|
|
1596
|
+
edits.sort((a, b) => b.at - a.at);
|
|
1597
|
+
let text = input.text;
|
|
1598
|
+
for (const edit of edits)
|
|
1599
|
+
text = text.slice(0, edit.at) + edit.text + text.slice(edit.at);
|
|
1600
|
+
return text;
|
|
1601
|
+
};
|
|
1502
1602
|
};
|