@typespec/compiler 0.56.0-dev.2 → 0.56.0-dev.20
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/dist/manifest.js +2 -2
- package/dist/src/config/config-interpolation.js +4 -7
- package/dist/src/config/config-interpolation.js.map +1 -1
- package/dist/src/config/config-loader.js +5 -7
- package/dist/src/config/config-loader.js.map +1 -1
- package/dist/src/config/config-to-options.js +8 -10
- package/dist/src/config/config-to-options.js.map +1 -1
- package/dist/src/core/binder.js +8 -8
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +192 -214
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/actions/compile/args.js +3 -6
- package/dist/src/core/cli/actions/compile/args.js.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.js +2 -2
- package/dist/src/core/cli/actions/compile/compile.js.map +1 -1
- package/dist/src/core/cli/actions/compile/watch.js +1 -2
- package/dist/src/core/cli/actions/compile/watch.js.map +1 -1
- package/dist/src/core/cli/actions/info.js +1 -2
- package/dist/src/core/cli/actions/info.js.map +1 -1
- package/dist/src/core/cli/actions/vs.js +1 -2
- package/dist/src/core/cli/actions/vs.js.map +1 -1
- package/dist/src/core/cli/install-vsix.js +1 -2
- package/dist/src/core/cli/install-vsix.js.map +1 -1
- package/dist/src/core/cli/utils.js +7 -9
- package/dist/src/core/cli/utils.js.map +1 -1
- package/dist/src/core/decorator-utils.js +6 -12
- package/dist/src/core/decorator-utils.js.map +1 -1
- package/dist/src/core/deprecation.js +2 -3
- package/dist/src/core/deprecation.js.map +1 -1
- package/dist/src/core/diagnostic-creator.js +1 -2
- package/dist/src/core/diagnostic-creator.js.map +1 -1
- package/dist/src/core/entrypoint-resolution.js +1 -1
- package/dist/src/core/entrypoint-resolution.js.map +1 -1
- package/dist/src/core/external-error.js +4 -5
- package/dist/src/core/external-error.js.map +1 -1
- package/dist/src/core/fetch.d.ts.map +1 -1
- package/dist/src/core/fetch.js +6 -6
- package/dist/src/core/fetch.js.map +1 -1
- package/dist/src/core/formatter-fs.js +2 -2
- package/dist/src/core/formatter-fs.js.map +1 -1
- package/dist/src/core/helpers/discriminator-utils.js +2 -4
- package/dist/src/core/helpers/discriminator-utils.js.map +1 -1
- package/dist/src/core/helpers/operation-utils.js +1 -2
- package/dist/src/core/helpers/operation-utils.js.map +1 -1
- package/dist/src/core/helpers/type-name-utils.js +18 -12
- package/dist/src/core/helpers/type-name-utils.js.map +1 -1
- package/dist/src/core/helpers/usage-resolver.js +2 -4
- package/dist/src/core/helpers/usage-resolver.js.map +1 -1
- package/dist/src/core/install.js +3 -3
- package/dist/src/core/install.js.map +1 -1
- package/dist/src/core/library.js +2 -3
- package/dist/src/core/library.js.map +1 -1
- package/dist/src/core/linter.js +4 -7
- package/dist/src/core/linter.js.map +1 -1
- package/dist/src/core/logger/console-sink.js +2 -3
- package/dist/src/core/logger/console-sink.js.map +1 -1
- package/dist/src/core/logger/tracer.js +1 -1
- package/dist/src/core/logger/tracer.js.map +1 -1
- package/dist/src/core/module-resolver.js +3 -4
- package/dist/src/core/module-resolver.js.map +1 -1
- package/dist/src/core/node-host.js +1 -1
- package/dist/src/core/node-host.js.map +1 -1
- package/dist/src/core/numeric.d.ts +26 -0
- package/dist/src/core/numeric.d.ts.map +1 -0
- package/dist/src/core/numeric.js +171 -0
- package/dist/src/core/numeric.js.map +1 -0
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +14 -15
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +36 -40
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/projection-members.js +2 -2
- package/dist/src/core/projection-members.js.map +1 -1
- package/dist/src/core/projector.js +3 -8
- package/dist/src/core/projector.js.map +1 -1
- package/dist/src/core/scanner.js +1 -1
- package/dist/src/core/scanner.js.map +1 -1
- package/dist/src/core/schema-validator.js +1 -2
- package/dist/src/core/schema-validator.js.map +1 -1
- package/dist/src/core/semantic-walker.js +2 -4
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/source-file.js +1 -1
- package/dist/src/core/source-file.js.map +1 -1
- package/dist/src/core/type-utils.js +2 -2
- package/dist/src/core/type-utils.js.map +1 -1
- package/dist/src/core/types.d.ts +15 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/emitter-framework/asset-emitter.js +10 -14
- package/dist/src/emitter-framework/asset-emitter.js.map +1 -1
- package/dist/src/emitter-framework/builders/array-builder.js +7 -17
- package/dist/src/emitter-framework/builders/array-builder.js.map +1 -1
- package/dist/src/emitter-framework/builders/object-builder.js +1 -0
- package/dist/src/emitter-framework/builders/object-builder.js.map +1 -1
- package/dist/src/emitter-framework/builders/string-builder.js +23 -31
- package/dist/src/emitter-framework/builders/string-builder.js.map +1 -1
- package/dist/src/emitter-framework/custom-key-map.js +6 -19
- package/dist/src/emitter-framework/custom-key-map.js.map +1 -1
- package/dist/src/emitter-framework/placeholder.js +3 -12
- package/dist/src/emitter-framework/placeholder.js.map +1 -1
- package/dist/src/emitter-framework/ref-scope.js +1 -2
- package/dist/src/emitter-framework/ref-scope.js.map +1 -1
- package/dist/src/emitter-framework/reference-cycle.js +11 -19
- package/dist/src/emitter-framework/reference-cycle.js.map +1 -1
- package/dist/src/emitter-framework/type-emitter.js +1 -0
- package/dist/src/emitter-framework/type-emitter.js.map +1 -1
- package/dist/src/emitter-framework/types.js +10 -8
- package/dist/src/emitter-framework/types.js.map +1 -1
- package/dist/src/formatter/parser.js +4 -3
- package/dist/src/formatter/parser.js.map +1 -1
- package/dist/src/formatter/print/comment-handler.js +3 -4
- package/dist/src/formatter/print/comment-handler.js.map +1 -1
- package/dist/src/formatter/print/printer.js +5 -8
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/init/init.js +2 -2
- package/dist/src/init/init.js.map +1 -1
- package/dist/src/init/scaffold.js +11 -17
- package/dist/src/init/scaffold.js.map +1 -1
- package/dist/src/lib/decorators.d.ts +1 -3
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +41 -45
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/encoded-names.js +3 -5
- package/dist/src/lib/encoded-names.js.map +1 -1
- package/dist/src/lib/intrinsic-decorators.d.ts +6 -0
- package/dist/src/lib/intrinsic-decorators.d.ts.map +1 -0
- package/dist/src/lib/intrinsic-decorators.js +10 -0
- package/dist/src/lib/intrinsic-decorators.js.map +1 -0
- package/dist/src/lib/service.js +3 -5
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/server/compile-service.js +6 -7
- package/dist/src/server/compile-service.js.map +1 -1
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js +15 -18
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/file-service.js +2 -4
- package/dist/src/server/file-service.js.map +1 -1
- package/dist/src/server/server.js +2 -4
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +25 -34
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/server/symbol-structure.js +2 -4
- package/dist/src/server/symbol-structure.js.map +1 -1
- package/dist/src/server/type-details.js +5 -9
- package/dist/src/server/type-details.js.map +1 -1
- package/dist/src/server/type-signature.js +4 -6
- package/dist/src/server/type-signature.js.map +1 -1
- package/dist/src/server/update-manager.js +15 -28
- package/dist/src/server/update-manager.js.map +1 -1
- package/dist/src/testing/rule-tester.js +2 -3
- package/dist/src/testing/rule-tester.js.map +1 -1
- package/dist/src/testing/test-host.js +8 -8
- package/dist/src/testing/test-host.js.map +1 -1
- package/dist/src/testing/test-server-host.js +7 -11
- package/dist/src/testing/test-server-host.js.map +1 -1
- package/dist/src/testing/test-utils.js +6 -6
- package/dist/src/testing/test-utils.js.map +1 -1
- package/dist/src/testing/types.js +1 -0
- package/dist/src/testing/types.js.map +1 -1
- package/dist/src/utils/duplicate-tracker.js +4 -13
- package/dist/src/utils/duplicate-tracker.js.map +1 -1
- package/dist/src/utils/misc.js +53 -75
- package/dist/src/utils/misc.js.map +1 -1
- package/dist/src/yaml/diagnostics.js +4 -5
- package/dist/src/yaml/diagnostics.js.map +1 -1
- package/lib/{lib.tsp → intrinsics.tsp} +3 -75
- package/lib/{decorators.tsp → std/decorators.tsp} +1 -1
- package/lib/std/main.tsp +5 -0
- package/lib/std/types.tsp +76 -0
- package/package.json +10 -10
- package/lib/main.tsp +0 -4
- /package/lib/{projected-names.tsp → std/projected-names.tsp} +0 -0
- /package/lib/{reflection.tsp → std/reflection.tsp} +0 -0
package/dist/src/core/checker.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _PendingResolutions_data;
|
|
7
|
-
import { $docFromComment, getIndexer, isArrayModelType } from "../lib/decorators.js";
|
|
1
|
+
import { $docFromComment, isArrayModelType } from "../lib/decorators.js";
|
|
2
|
+
import { getIndexer } from "../lib/intrinsic-decorators.js";
|
|
8
3
|
import { MultiKeyMap, createRekeyableMap, isArray, mutate } from "../utils/misc.js";
|
|
9
4
|
import { createSymbol, createSymbolTable } from "./binder.js";
|
|
10
5
|
import { createChangeIdentifierCodeFix } from "./compiler-code-fixes/change-identifier.codefix.js";
|
|
@@ -82,9 +77,6 @@ export function createChecker(program) {
|
|
|
82
77
|
}
|
|
83
78
|
const typespecNamespaceBinding = globalNamespaceNode.symbol.exports.get("TypeSpec");
|
|
84
79
|
if (typespecNamespaceBinding) {
|
|
85
|
-
// the TypeSpec namespace binding will be absent if we've passed
|
|
86
|
-
// the no-std-lib option.
|
|
87
|
-
// the first declaration here is the JS file for the TypeSpec script.
|
|
88
80
|
initializeTypeSpecIntrinsics();
|
|
89
81
|
for (const file of program.sourceFiles.values()) {
|
|
90
82
|
addUsingSymbols(typespecNamespaceBinding.exports, file.locals);
|
|
@@ -151,12 +143,11 @@ export function createChecker(program) {
|
|
|
151
143
|
getSymbolLinks(nullSym).type = nullType;
|
|
152
144
|
}
|
|
153
145
|
function getStdType(name) {
|
|
154
|
-
var _a;
|
|
155
146
|
const type = stdTypes[name];
|
|
156
147
|
if (type !== undefined) {
|
|
157
148
|
return type;
|
|
158
149
|
}
|
|
159
|
-
const sym =
|
|
150
|
+
const sym = typespecNamespaceBinding?.exports?.get(name);
|
|
160
151
|
if (sym && sym.flags & 2 /* SymbolFlags.Model */) {
|
|
161
152
|
checkModelStatement(sym.declarations[0], undefined);
|
|
162
153
|
}
|
|
@@ -295,10 +286,9 @@ export function createChecker(program) {
|
|
|
295
286
|
* @returns Checked type for the given member symbol.
|
|
296
287
|
*/
|
|
297
288
|
function checkMemberSym(sym, mapper) {
|
|
298
|
-
var _a;
|
|
299
289
|
const symbolLinks = getSymbolLinks(sym);
|
|
300
290
|
const memberContainer = getTypeForNode(sym.parent.declarations[0], mapper);
|
|
301
|
-
const type =
|
|
291
|
+
const type = symbolLinks.declaredType ?? symbolLinks.type;
|
|
302
292
|
if (type) {
|
|
303
293
|
return type;
|
|
304
294
|
}
|
|
@@ -397,22 +387,20 @@ export function createChecker(program) {
|
|
|
397
387
|
* Return a fully qualified id of node
|
|
398
388
|
*/
|
|
399
389
|
function getNodeSymId(node) {
|
|
400
|
-
var _a;
|
|
401
390
|
const symbol = node.kind === SyntaxKind.OperationStatement &&
|
|
402
|
-
|
|
391
|
+
node.parent?.kind === SyntaxKind.InterfaceStatement
|
|
403
392
|
? getSymbolForMember(node)
|
|
404
393
|
: node.symbol;
|
|
405
394
|
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
406
|
-
return symbol
|
|
395
|
+
return symbol?.id;
|
|
407
396
|
}
|
|
408
397
|
/**
|
|
409
398
|
* Check if the given namespace is the standard library `TypeSpec` namespace.
|
|
410
399
|
*/
|
|
411
400
|
function isTypeSpecNamespace(namespace) {
|
|
412
|
-
var _a;
|
|
413
401
|
return (namespace.name === "TypeSpec" &&
|
|
414
402
|
(namespace.namespace === globalNamespaceType ||
|
|
415
|
-
|
|
403
|
+
namespace.namespace?.projectionBase === globalNamespaceType));
|
|
416
404
|
}
|
|
417
405
|
/**
|
|
418
406
|
* Check if the given type is defined right in the TypeSpec namespace.
|
|
@@ -421,7 +409,6 @@ export function createChecker(program) {
|
|
|
421
409
|
return Boolean(type.namespace && isTypeSpecNamespace(type.namespace));
|
|
422
410
|
}
|
|
423
411
|
function checkTemplateParameterDeclaration(node, mapper) {
|
|
424
|
-
var _a;
|
|
425
412
|
const parentNode = node.parent;
|
|
426
413
|
const grandParentNode = parentNode.parent;
|
|
427
414
|
const links = getSymbolLinks(node.symbol);
|
|
@@ -438,7 +425,7 @@ export function createChecker(program) {
|
|
|
438
425
|
let type = links.declaredType;
|
|
439
426
|
if (type === undefined) {
|
|
440
427
|
if (grandParentNode) {
|
|
441
|
-
if (
|
|
428
|
+
if (grandParentNode.locals?.has(node.id.sv)) {
|
|
442
429
|
reportCheckerDiagnostic(createDiagnostic({
|
|
443
430
|
code: "shadow",
|
|
444
431
|
format: { name: node.id.sv },
|
|
@@ -472,7 +459,6 @@ export function createChecker(program) {
|
|
|
472
459
|
return getTypeForNode(node.default, mapper);
|
|
473
460
|
}
|
|
474
461
|
function checkTemplateParameterDefault(nodeDefault, templateParameters, index, constraint) {
|
|
475
|
-
var _a;
|
|
476
462
|
function visit(node) {
|
|
477
463
|
const type = getTypeForNode(node);
|
|
478
464
|
let hasError = false;
|
|
@@ -493,7 +479,7 @@ export function createChecker(program) {
|
|
|
493
479
|
});
|
|
494
480
|
return hasError ? undefined : type;
|
|
495
481
|
}
|
|
496
|
-
const type =
|
|
482
|
+
const type = visit(nodeDefault) ?? errorType;
|
|
497
483
|
if (!isErrorType(type) && constraint) {
|
|
498
484
|
checkTypeAssignable(type, constraint, nodeDefault);
|
|
499
485
|
}
|
|
@@ -546,13 +532,12 @@ export function createChecker(program) {
|
|
|
546
532
|
}
|
|
547
533
|
function isTypeReferenceContextDeprecated(node) {
|
|
548
534
|
function checkDeprecatedNode(node) {
|
|
549
|
-
var _a;
|
|
550
535
|
// Perform a simple check if the parent node is deprecated. We do this
|
|
551
536
|
// out of band because `checkDirectives` usually gets called on the parent
|
|
552
537
|
// type after child types have already been checked (including their
|
|
553
538
|
// deprecations).
|
|
554
539
|
if (!nodeDeprecationMap.has(node)) {
|
|
555
|
-
nodeDeprecationMap.set(node, (
|
|
540
|
+
nodeDeprecationMap.set(node, (node.directives ?? []).findIndex((d) => d.target.sv === "deprecated") >= 0);
|
|
556
541
|
}
|
|
557
542
|
return nodeDeprecationMap.get(node);
|
|
558
543
|
}
|
|
@@ -580,8 +565,6 @@ export function createChecker(program) {
|
|
|
580
565
|
}
|
|
581
566
|
}
|
|
582
567
|
function checkTemplateInstantiationArgs(node, args, decls, mapper) {
|
|
583
|
-
var _a, _b, _c, _d;
|
|
584
|
-
var _e;
|
|
585
568
|
const params = new Map();
|
|
586
569
|
const positional = [];
|
|
587
570
|
const initMap = new Map(decls.map(function (decl) {
|
|
@@ -646,7 +629,7 @@ export function createChecker(program) {
|
|
|
646
629
|
continue;
|
|
647
630
|
}
|
|
648
631
|
const param = positional[idx];
|
|
649
|
-
|
|
632
|
+
initMap.get(param).checkArgument ??= deferredCheck;
|
|
650
633
|
}
|
|
651
634
|
}
|
|
652
635
|
const finalMap = initMap;
|
|
@@ -674,7 +657,7 @@ export function createChecker(program) {
|
|
|
674
657
|
target: node,
|
|
675
658
|
}));
|
|
676
659
|
// TODO-TIM check if we expose this below
|
|
677
|
-
commit(param,
|
|
660
|
+
commit(param, param.constraint?.kind === "Value" ? unknownType : param.constraint ?? unknownType);
|
|
678
661
|
}
|
|
679
662
|
continue;
|
|
680
663
|
}
|
|
@@ -685,7 +668,7 @@ export function createChecker(program) {
|
|
|
685
668
|
: param.constraint;
|
|
686
669
|
if (!checkTypeAssignable(type, constraint, argNode)) {
|
|
687
670
|
// TODO-TIM check if we expose this below
|
|
688
|
-
const effectiveType =
|
|
671
|
+
const effectiveType = param.constraint?.kind === "Value" ? unknownType : param.constraint;
|
|
689
672
|
commit(param, effectiveType);
|
|
690
673
|
continue;
|
|
691
674
|
}
|
|
@@ -794,7 +777,7 @@ export function createChecker(program) {
|
|
|
794
777
|
// Check for deprecations here, first on symbol, then on type. However,
|
|
795
778
|
// don't raise deprecation when the usage site is also a deprecated
|
|
796
779
|
// declaration.
|
|
797
|
-
const declarationNode = sym
|
|
780
|
+
const declarationNode = sym?.declarations[0];
|
|
798
781
|
if (declarationNode && mapper === undefined) {
|
|
799
782
|
if (!isTypeReferenceContextDeprecated(node.parent)) {
|
|
800
783
|
checkDeprecated(baseType, declarationNode, node);
|
|
@@ -846,7 +829,6 @@ export function createChecker(program) {
|
|
|
846
829
|
: checkUnion(node, mapper);
|
|
847
830
|
}
|
|
848
831
|
function getOrInstantiateTemplate(templateNode, params, args, parentMapper, instantiateTempalates = true) {
|
|
849
|
-
var _a;
|
|
850
832
|
const symbolLinks = templateNode.kind === SyntaxKind.OperationStatement &&
|
|
851
833
|
templateNode.parent.kind === SyntaxKind.InterfaceStatement
|
|
852
834
|
? getSymbolLinksForMember(templateNode)
|
|
@@ -862,7 +844,7 @@ export function createChecker(program) {
|
|
|
862
844
|
}
|
|
863
845
|
}
|
|
864
846
|
const mapper = createTypeMapper(params, args, parentMapper);
|
|
865
|
-
const cached =
|
|
847
|
+
const cached = symbolLinks.instantiations?.get(mapper.args);
|
|
866
848
|
if (cached) {
|
|
867
849
|
return cached;
|
|
868
850
|
}
|
|
@@ -968,7 +950,7 @@ export function createChecker(program) {
|
|
|
968
950
|
node,
|
|
969
951
|
target: checkFunctionParameter(node.target, mapper),
|
|
970
952
|
parameters: node.parameters.map((x) => checkFunctionParameter(x, mapper)),
|
|
971
|
-
implementation: implementation
|
|
953
|
+
implementation: implementation ?? (() => { }),
|
|
972
954
|
});
|
|
973
955
|
namespace.decoratorDeclarations.set(name, decoratorType);
|
|
974
956
|
linkType(links, decoratorType, mapper);
|
|
@@ -998,7 +980,7 @@ export function createChecker(program) {
|
|
|
998
980
|
node,
|
|
999
981
|
parameters: node.parameters.map((x) => checkFunctionParameter(x, mapper)),
|
|
1000
982
|
returnType: node.returnType ? getTypeForNode(node.returnType, mapper) : unknownType,
|
|
1001
|
-
implementation: implementation
|
|
983
|
+
implementation: implementation ?? (() => { }),
|
|
1002
984
|
});
|
|
1003
985
|
namespace.functionDeclarations.set(name, functionType);
|
|
1004
986
|
linkType(links, functionType, mapper);
|
|
@@ -1045,6 +1027,7 @@ export function createChecker(program) {
|
|
|
1045
1027
|
properties: properties,
|
|
1046
1028
|
decorators: [],
|
|
1047
1029
|
derivedModels: [],
|
|
1030
|
+
sourceModels: [],
|
|
1048
1031
|
});
|
|
1049
1032
|
const indexers = [];
|
|
1050
1033
|
const modelOptions = options.filter((entry) => {
|
|
@@ -1073,6 +1056,7 @@ export function createChecker(program) {
|
|
|
1073
1056
|
}
|
|
1074
1057
|
}
|
|
1075
1058
|
for (const [_, option] of modelOptions) {
|
|
1059
|
+
intersection.sourceModels.push({ usage: "intersection", model: option });
|
|
1076
1060
|
const allProps = walkPropertiesInherited(option);
|
|
1077
1061
|
for (const prop of allProps) {
|
|
1078
1062
|
if (properties.has(prop.name)) {
|
|
@@ -1161,7 +1145,7 @@ export function createChecker(program) {
|
|
|
1161
1145
|
type.decorators = type.decorators.concat(checkDecorators(type, sourceNode, undefined));
|
|
1162
1146
|
}
|
|
1163
1147
|
finishType(type);
|
|
1164
|
-
namespace
|
|
1148
|
+
namespace?.namespaces.set(name, type);
|
|
1165
1149
|
}
|
|
1166
1150
|
return symbolLinks.type;
|
|
1167
1151
|
}
|
|
@@ -1214,8 +1198,7 @@ export function createChecker(program) {
|
|
|
1214
1198
|
return symbolLinks.type;
|
|
1215
1199
|
}
|
|
1216
1200
|
function checkOperation(node, mapper, parentInterface) {
|
|
1217
|
-
|
|
1218
|
-
const inInterface = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.kind) === SyntaxKind.InterfaceStatement;
|
|
1201
|
+
const inInterface = node.parent?.kind === SyntaxKind.InterfaceStatement;
|
|
1219
1202
|
const symbol = inInterface ? getSymbolForMember(node) : node.symbol;
|
|
1220
1203
|
const links = symbol && getSymbolLinks(symbol);
|
|
1221
1204
|
if (links) {
|
|
@@ -1225,7 +1208,7 @@ export function createChecker(program) {
|
|
|
1225
1208
|
}
|
|
1226
1209
|
}
|
|
1227
1210
|
if (mapper === undefined && inInterface) {
|
|
1228
|
-
compilerAssert(parentInterface, "Operation in interface should already have been checked.");
|
|
1211
|
+
compilerAssert(parentInterface, "Operation in interface should already have been checked.", node.parent);
|
|
1229
1212
|
}
|
|
1230
1213
|
checkTemplateDeclaration(node, mapper);
|
|
1231
1214
|
// If we are instantating operation inside of interface
|
|
@@ -1240,26 +1223,37 @@ export function createChecker(program) {
|
|
|
1240
1223
|
if (node.signature.kind === SyntaxKind.OperationSignatureReference) {
|
|
1241
1224
|
// Attempt to resolve the operation
|
|
1242
1225
|
const baseOperation = checkOperationIs(node, node.signature.baseOperation, mapper);
|
|
1243
|
-
if (
|
|
1244
|
-
|
|
1226
|
+
if (baseOperation) {
|
|
1227
|
+
sourceOperation = baseOperation;
|
|
1228
|
+
const parameterModelSym = getOrCreateAugmentedSymbolTable(symbol.metatypeMembers).get("parameters");
|
|
1229
|
+
// Reference the same return type and create the parameters type
|
|
1230
|
+
const clone = initializeClone(baseOperation.parameters, {
|
|
1231
|
+
properties: createRekeyableMap(),
|
|
1232
|
+
});
|
|
1233
|
+
clone.properties = createRekeyableMap(Array.from(baseOperation.parameters.properties.entries()).map(([key, prop]) => [
|
|
1234
|
+
key,
|
|
1235
|
+
cloneTypeForSymbol(getMemberSymbol(parameterModelSym, prop.name), prop, {
|
|
1236
|
+
model: clone,
|
|
1237
|
+
sourceProperty: prop,
|
|
1238
|
+
}),
|
|
1239
|
+
]));
|
|
1240
|
+
parameters = finishType(clone);
|
|
1241
|
+
returnType = baseOperation.returnType;
|
|
1242
|
+
// Copy decorators from the base operation, inserting the base decorators first
|
|
1243
|
+
decorators = [...baseOperation.decorators];
|
|
1244
|
+
}
|
|
1245
|
+
else {
|
|
1246
|
+
// If we can't resolve the signature we return an empty model.
|
|
1247
|
+
parameters = createAndFinishType({
|
|
1248
|
+
kind: "Model",
|
|
1249
|
+
name: "",
|
|
1250
|
+
decorators: [],
|
|
1251
|
+
properties: createRekeyableMap(),
|
|
1252
|
+
derivedModels: [],
|
|
1253
|
+
sourceModels: [],
|
|
1254
|
+
});
|
|
1255
|
+
returnType = voidType;
|
|
1245
1256
|
}
|
|
1246
|
-
sourceOperation = baseOperation;
|
|
1247
|
-
const parameterModelSym = getOrCreateAugmentedSymbolTable(symbol.metatypeMembers).get("parameters");
|
|
1248
|
-
// Reference the same return type and create the parameters type
|
|
1249
|
-
const clone = initializeClone(baseOperation.parameters, {
|
|
1250
|
-
properties: createRekeyableMap(),
|
|
1251
|
-
});
|
|
1252
|
-
clone.properties = createRekeyableMap(Array.from(baseOperation.parameters.properties.entries()).map(([key, prop]) => [
|
|
1253
|
-
key,
|
|
1254
|
-
cloneTypeForSymbol(getMemberSymbol(parameterModelSym, prop.name), prop, {
|
|
1255
|
-
model: clone,
|
|
1256
|
-
sourceProperty: prop,
|
|
1257
|
-
}),
|
|
1258
|
-
]));
|
|
1259
|
-
parameters = finishType(clone);
|
|
1260
|
-
returnType = baseOperation.returnType;
|
|
1261
|
-
// Copy decorators from the base operation, inserting the base decorators first
|
|
1262
|
-
decorators = [...baseOperation.decorators];
|
|
1263
1257
|
}
|
|
1264
1258
|
else {
|
|
1265
1259
|
parameters = getTypeForNode(node.signature.parameters, mapper);
|
|
@@ -1294,7 +1288,7 @@ export function createChecker(program) {
|
|
|
1294
1288
|
finishType(operationType);
|
|
1295
1289
|
}
|
|
1296
1290
|
if (mapper === undefined) {
|
|
1297
|
-
namespace
|
|
1291
|
+
namespace?.operations.set(name, operationType);
|
|
1298
1292
|
}
|
|
1299
1293
|
}
|
|
1300
1294
|
return operationType;
|
|
@@ -1366,11 +1360,10 @@ export function createChecker(program) {
|
|
|
1366
1360
|
return s.id;
|
|
1367
1361
|
}
|
|
1368
1362
|
function resolveIdentifierInTable(node, table, options) {
|
|
1369
|
-
var _a, _b;
|
|
1370
1363
|
if (!table) {
|
|
1371
1364
|
return undefined;
|
|
1372
1365
|
}
|
|
1373
|
-
table =
|
|
1366
|
+
table = augmentedSymbolTables.get(table) ?? table;
|
|
1374
1367
|
let sym;
|
|
1375
1368
|
if (options.resolveDecorators) {
|
|
1376
1369
|
sym = table.get("@" + node.sv);
|
|
@@ -1381,7 +1374,7 @@ export function createChecker(program) {
|
|
|
1381
1374
|
if (!sym)
|
|
1382
1375
|
return sym;
|
|
1383
1376
|
if (sym.flags & 1048576 /* SymbolFlags.DuplicateUsing */) {
|
|
1384
|
-
reportAmbiguousIdentifier(node, [...(
|
|
1377
|
+
reportAmbiguousIdentifier(node, [...(table.duplicates.get(sym) ?? [])]);
|
|
1385
1378
|
return sym;
|
|
1386
1379
|
}
|
|
1387
1380
|
return getMergedSymbol(sym);
|
|
@@ -1395,7 +1388,6 @@ export function createChecker(program) {
|
|
|
1395
1388
|
}));
|
|
1396
1389
|
}
|
|
1397
1390
|
function resolveIdentifier(id, mapper) {
|
|
1398
|
-
var _a, _b, _c;
|
|
1399
1391
|
let sym;
|
|
1400
1392
|
const { node, kind } = getIdentifierContext(id);
|
|
1401
1393
|
switch (kind) {
|
|
@@ -1418,7 +1410,7 @@ export function createChecker(program) {
|
|
|
1418
1410
|
return undefined;
|
|
1419
1411
|
}
|
|
1420
1412
|
lateBindMembers(containerType, container);
|
|
1421
|
-
sym = resolveIdentifierInTable(id,
|
|
1413
|
+
sym = resolveIdentifierInTable(id, container.exports ?? container.members, defaultSymbolResolutionOptions);
|
|
1422
1414
|
break;
|
|
1423
1415
|
case IdentifierKind.Other:
|
|
1424
1416
|
return undefined;
|
|
@@ -1428,7 +1420,7 @@ export function createChecker(program) {
|
|
|
1428
1420
|
case IdentifierKind.TypeReference:
|
|
1429
1421
|
let ref = id;
|
|
1430
1422
|
let resolveDecorator = kind === IdentifierKind.Decorator;
|
|
1431
|
-
if (
|
|
1423
|
+
if (id.parent?.kind === SyntaxKind.MemberExpression) {
|
|
1432
1424
|
if (id.parent.id === id) {
|
|
1433
1425
|
// If the identifier is Y in X.Y, then resolve (X.Y).
|
|
1434
1426
|
ref = id.parent;
|
|
@@ -1454,15 +1446,13 @@ export function createChecker(program) {
|
|
|
1454
1446
|
const _assertNever = kind;
|
|
1455
1447
|
compilerAssert(false, "Unreachable");
|
|
1456
1448
|
}
|
|
1457
|
-
return
|
|
1449
|
+
return sym?.symbolSource ?? sym;
|
|
1458
1450
|
}
|
|
1459
1451
|
function getTemplateDeclarationsForArgument(node, mapper) {
|
|
1460
|
-
var _a;
|
|
1461
1452
|
const resolved = resolveTypeReferenceSym(node.parent, mapper, false);
|
|
1462
|
-
return (
|
|
1453
|
+
return (resolved?.declarations.filter((n) => isTemplatedNode(n)) ?? []);
|
|
1463
1454
|
}
|
|
1464
1455
|
function resolveCompletions(identifier) {
|
|
1465
|
-
var _a, _b, _c;
|
|
1466
1456
|
const completions = new Map();
|
|
1467
1457
|
const { kind, node: ancestor } = getIdentifierContext(identifier);
|
|
1468
1458
|
switch (kind) {
|
|
@@ -1496,13 +1486,13 @@ export function createChecker(program) {
|
|
|
1496
1486
|
}
|
|
1497
1487
|
if (base) {
|
|
1498
1488
|
if (isTemplatedNode(base.declarations[0])) {
|
|
1499
|
-
const type =
|
|
1489
|
+
const type = base.type ?? getTypeForNode(base.declarations[0], undefined);
|
|
1500
1490
|
if (isTemplateInstance(type)) {
|
|
1501
1491
|
lateBindMemberContainer(type);
|
|
1502
1492
|
lateBindMembers(type, base);
|
|
1503
1493
|
}
|
|
1504
1494
|
}
|
|
1505
|
-
addCompletions(
|
|
1495
|
+
addCompletions(base.exports ?? base.members);
|
|
1506
1496
|
}
|
|
1507
1497
|
}
|
|
1508
1498
|
}
|
|
@@ -1511,7 +1501,7 @@ export function createChecker(program) {
|
|
|
1511
1501
|
// to avoid completing the name of the argument again.
|
|
1512
1502
|
if (kind === IdentifierKind.TypeReference &&
|
|
1513
1503
|
exprIsBareIdentifier(ancestor) &&
|
|
1514
|
-
|
|
1504
|
+
ancestor.parent?.kind === SyntaxKind.TemplateArgument &&
|
|
1515
1505
|
ancestor.parent.name === undefined) {
|
|
1516
1506
|
const templates = getTemplateDeclarationsForArgument(ancestor.parent, undefined);
|
|
1517
1507
|
for (const template of templates) {
|
|
@@ -1545,11 +1535,10 @@ export function createChecker(program) {
|
|
|
1545
1535
|
}
|
|
1546
1536
|
return completions;
|
|
1547
1537
|
function addCompletions(table) {
|
|
1548
|
-
var _a;
|
|
1549
1538
|
if (!table) {
|
|
1550
1539
|
return;
|
|
1551
1540
|
}
|
|
1552
|
-
table =
|
|
1541
|
+
table = augmentedSymbolTables.get(table) ?? table;
|
|
1553
1542
|
for (const [key, sym] of table) {
|
|
1554
1543
|
if (sym.flags & 1048576 /* SymbolFlags.DuplicateUsing */) {
|
|
1555
1544
|
const duplicates = table.duplicates.get(sym);
|
|
@@ -1598,8 +1587,7 @@ export function createChecker(program) {
|
|
|
1598
1587
|
}
|
|
1599
1588
|
}
|
|
1600
1589
|
function resolveIdentifierInScope(node, mapper, options) {
|
|
1601
|
-
|
|
1602
|
-
compilerAssert(((_a = node.parent) === null || _a === void 0 ? void 0 : _a.kind) !== SyntaxKind.MemberExpression || node.parent.id !== node, "This function should not be used to resolve Y in member expression X.Y. Use resolveIdentifier() to resolve an arbitrary identifier.");
|
|
1590
|
+
compilerAssert(node.parent?.kind !== SyntaxKind.MemberExpression || node.parent.id !== node, "This function should not be used to resolve Y in member expression X.Y. Use resolveIdentifier() to resolve an arbitrary identifier.");
|
|
1603
1591
|
if (hasParseError(node)) {
|
|
1604
1592
|
// Don't report synthetic identifiers used for parser error recovery.
|
|
1605
1593
|
// The parse error is the root cause and will already have been logged.
|
|
@@ -1665,7 +1653,7 @@ export function createChecker(program) {
|
|
|
1665
1653
|
function resolveTypeReferenceSym(node, mapper, options) {
|
|
1666
1654
|
const resolvedOptions = typeof options === "boolean"
|
|
1667
1655
|
? { ...defaultSymbolResolutionOptions, resolveDecorators: options }
|
|
1668
|
-
: { ...defaultSymbolResolutionOptions, ...(options
|
|
1656
|
+
: { ...defaultSymbolResolutionOptions, ...(options ?? {}) };
|
|
1669
1657
|
if (mapper === undefined && resolvedOptions.checkTemplateTypes && referenceSymCache.has(node)) {
|
|
1670
1658
|
return referenceSymCache.get(node);
|
|
1671
1659
|
}
|
|
@@ -1691,10 +1679,22 @@ export function createChecker(program) {
|
|
|
1691
1679
|
}
|
|
1692
1680
|
// when resolving a type reference based on an alias, unwrap the alias.
|
|
1693
1681
|
if (base.flags & 2048 /* SymbolFlags.Alias */) {
|
|
1694
|
-
|
|
1695
|
-
if (!
|
|
1682
|
+
const aliasedSym = getAliasedSymbol(base, mapper, options);
|
|
1683
|
+
if (!aliasedSym) {
|
|
1684
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
1685
|
+
code: "invalid-ref",
|
|
1686
|
+
messageId: "node",
|
|
1687
|
+
format: {
|
|
1688
|
+
id: node.id.sv,
|
|
1689
|
+
nodeName: base.declarations[0]
|
|
1690
|
+
? SyntaxKind[base.declarations[0].kind]
|
|
1691
|
+
: "Unknown node",
|
|
1692
|
+
},
|
|
1693
|
+
target: node,
|
|
1694
|
+
}));
|
|
1696
1695
|
return undefined;
|
|
1697
1696
|
}
|
|
1697
|
+
base = aliasedSym;
|
|
1698
1698
|
}
|
|
1699
1699
|
if (node.selector === ".") {
|
|
1700
1700
|
return resolveMemberInContainer(node, base, mapper, options);
|
|
@@ -1819,16 +1819,22 @@ export function createChecker(program) {
|
|
|
1819
1819
|
* instantiation) we late bind the container which creates the symbol that will hold its members.
|
|
1820
1820
|
*/
|
|
1821
1821
|
function getAliasedSymbol(aliasSymbol, mapper, options) {
|
|
1822
|
-
var _a;
|
|
1823
1822
|
let current = aliasSymbol;
|
|
1824
1823
|
while (current.flags & 2048 /* SymbolFlags.Alias */) {
|
|
1825
1824
|
const node = current.declarations[0];
|
|
1826
1825
|
const targetNode = node.kind === SyntaxKind.AliasStatement ? node.value : node;
|
|
1827
|
-
|
|
1828
|
-
|
|
1826
|
+
if (targetNode.kind === SyntaxKind.TypeReference ||
|
|
1827
|
+
targetNode.kind === SyntaxKind.MemberExpression ||
|
|
1828
|
+
targetNode.kind === SyntaxKind.Identifier) {
|
|
1829
|
+
const sym = resolveTypeReferenceSymInternal(targetNode, mapper, options);
|
|
1830
|
+
if (sym === undefined) {
|
|
1831
|
+
return undefined;
|
|
1832
|
+
}
|
|
1833
|
+
current = sym;
|
|
1834
|
+
}
|
|
1835
|
+
else {
|
|
1829
1836
|
return undefined;
|
|
1830
1837
|
}
|
|
1831
|
-
current = sym;
|
|
1832
1838
|
}
|
|
1833
1839
|
const sym = current;
|
|
1834
1840
|
const node = aliasSymbol.declarations[0];
|
|
@@ -1853,7 +1859,7 @@ export function createChecker(program) {
|
|
|
1853
1859
|
default:
|
|
1854
1860
|
// get the symbol from the node aliased type's node, or just return the base
|
|
1855
1861
|
// if it doesn't have a symbol (which will likely result in an error later on)
|
|
1856
|
-
return
|
|
1862
|
+
return getMergedSymbol(aliasType.node.symbol) ?? aliasSymbol;
|
|
1857
1863
|
}
|
|
1858
1864
|
}
|
|
1859
1865
|
function checkStringTemplateExpresion(node, mapper) {
|
|
@@ -1895,7 +1901,6 @@ export function createChecker(program) {
|
|
|
1895
1901
|
return getLiteralType(bool);
|
|
1896
1902
|
}
|
|
1897
1903
|
function checkProgram() {
|
|
1898
|
-
var _a, _b;
|
|
1899
1904
|
program.reportDuplicateSymbols(globalNamespaceNode.symbol.exports);
|
|
1900
1905
|
for (const file of program.sourceFiles.values()) {
|
|
1901
1906
|
bindAllMembers(file);
|
|
@@ -1905,7 +1910,7 @@ export function createChecker(program) {
|
|
|
1905
1910
|
}
|
|
1906
1911
|
for (const file of program.sourceFiles.values()) {
|
|
1907
1912
|
for (const ns of file.namespaces) {
|
|
1908
|
-
const exports =
|
|
1913
|
+
const exports = mergedSymbols.get(ns.symbol)?.exports ?? ns.symbol.exports;
|
|
1909
1914
|
program.reportDuplicateSymbols(exports);
|
|
1910
1915
|
initializeTypeForNamespace(ns);
|
|
1911
1916
|
}
|
|
@@ -1967,7 +1972,6 @@ export function createChecker(program) {
|
|
|
1967
1972
|
}
|
|
1968
1973
|
}
|
|
1969
1974
|
function checkModelStatement(node, mapper) {
|
|
1970
|
-
var _a;
|
|
1971
1975
|
const links = getSymbolLinks(node.symbol);
|
|
1972
1976
|
if (links.declaredType && mapper === undefined) {
|
|
1973
1977
|
// we're not instantiating this model and we've already checked it
|
|
@@ -1982,12 +1986,14 @@ export function createChecker(program) {
|
|
|
1982
1986
|
properties: createRekeyableMap(),
|
|
1983
1987
|
namespace: getParentNamespaceType(node),
|
|
1984
1988
|
decorators,
|
|
1989
|
+
sourceModels: [],
|
|
1985
1990
|
derivedModels: [],
|
|
1986
1991
|
});
|
|
1987
1992
|
linkType(links, type, mapper);
|
|
1988
1993
|
const isBase = checkModelIs(node, node.is, mapper);
|
|
1989
1994
|
if (isBase) {
|
|
1990
1995
|
type.sourceModel = isBase;
|
|
1996
|
+
type.sourceModels.push({ usage: "is", model: isBase });
|
|
1991
1997
|
// copy decorators
|
|
1992
1998
|
decorators.push(...isBase.decorators);
|
|
1993
1999
|
if (isBase.indexer) {
|
|
@@ -2020,7 +2026,7 @@ export function createChecker(program) {
|
|
|
2020
2026
|
// Hold on to the model type that's being defined so that it
|
|
2021
2027
|
// can be referenced
|
|
2022
2028
|
if (mapper === undefined) {
|
|
2023
|
-
|
|
2029
|
+
type.namespace?.models.set(type.name, type);
|
|
2024
2030
|
}
|
|
2025
2031
|
// Evaluate the properties after
|
|
2026
2032
|
checkModelProperties(node, type.properties, type, mapper);
|
|
@@ -2063,6 +2069,7 @@ export function createChecker(program) {
|
|
|
2063
2069
|
namespace: getParentNamespaceType(node),
|
|
2064
2070
|
decorators: [],
|
|
2065
2071
|
derivedModels: [],
|
|
2072
|
+
sourceModels: [],
|
|
2066
2073
|
});
|
|
2067
2074
|
checkModelProperties(node, properties, type, mapper);
|
|
2068
2075
|
return finishType(type);
|
|
@@ -2170,7 +2177,7 @@ export function createChecker(program) {
|
|
|
2170
2177
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2171
2178
|
code: "duplicate-property",
|
|
2172
2179
|
format: { propName: newProp.name },
|
|
2173
|
-
target: diagnosticTarget
|
|
2180
|
+
target: diagnosticTarget ?? newProp,
|
|
2174
2181
|
}));
|
|
2175
2182
|
return;
|
|
2176
2183
|
}
|
|
@@ -2183,7 +2190,7 @@ export function createChecker(program) {
|
|
|
2183
2190
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2184
2191
|
code: "override-property-mismatch",
|
|
2185
2192
|
format: { propName: newProp.name, propType: newPropType, parentType: parentType },
|
|
2186
|
-
target: diagnosticTarget
|
|
2193
|
+
target: diagnosticTarget ?? newProp,
|
|
2187
2194
|
}));
|
|
2188
2195
|
return;
|
|
2189
2196
|
}
|
|
@@ -2289,8 +2296,7 @@ export function createChecker(program) {
|
|
|
2289
2296
|
}
|
|
2290
2297
|
}
|
|
2291
2298
|
function copyMembers(table) {
|
|
2292
|
-
|
|
2293
|
-
const members = (_a = augmentedSymbolTables.get(table)) !== null && _a !== void 0 ? _a : table;
|
|
2299
|
+
const members = augmentedSymbolTables.get(table) ?? table;
|
|
2294
2300
|
for (const member of members.values()) {
|
|
2295
2301
|
bindMember(member.name, member.declarations[0], member.flags);
|
|
2296
2302
|
}
|
|
@@ -2298,14 +2304,13 @@ export function createChecker(program) {
|
|
|
2298
2304
|
function bindMember(name, node, kind) {
|
|
2299
2305
|
const sym = createSymbol(node, name, kind, containerSym);
|
|
2300
2306
|
compilerAssert(containerSym.members, "containerSym.members is undefined");
|
|
2301
|
-
containerMembers
|
|
2307
|
+
containerMembers ??= getOrCreateAugmentedSymbolTable(containerSym.members);
|
|
2302
2308
|
containerMembers.set(name, sym);
|
|
2303
2309
|
}
|
|
2304
2310
|
}
|
|
2305
2311
|
}
|
|
2306
2312
|
function copyMembersToContainer(targetContainerSym, table) {
|
|
2307
|
-
|
|
2308
|
-
const members = (_a = augmentedSymbolTables.get(table)) !== null && _a !== void 0 ? _a : table;
|
|
2313
|
+
const members = augmentedSymbolTables.get(table) ?? table;
|
|
2309
2314
|
compilerAssert(targetContainerSym.members, "containerSym.members is undefined");
|
|
2310
2315
|
const containerMembers = getOrCreateAugmentedSymbolTable(targetContainerSym.members);
|
|
2311
2316
|
for (const member of members.values()) {
|
|
@@ -2320,7 +2325,6 @@ export function createChecker(program) {
|
|
|
2320
2325
|
function bindMetaTypes(node) {
|
|
2321
2326
|
const visited = new Set();
|
|
2322
2327
|
function visit(node, symbol) {
|
|
2323
|
-
var _a;
|
|
2324
2328
|
if (visited.has(node)) {
|
|
2325
2329
|
return;
|
|
2326
2330
|
}
|
|
@@ -2337,7 +2341,7 @@ export function createChecker(program) {
|
|
|
2337
2341
|
break;
|
|
2338
2342
|
}
|
|
2339
2343
|
case SyntaxKind.OperationStatement: {
|
|
2340
|
-
const sym =
|
|
2344
|
+
const sym = symbol ?? node.symbol ?? getSymbolForMember(node);
|
|
2341
2345
|
const table = getOrCreateAugmentedSymbolTable(sym.metatypeMembers);
|
|
2342
2346
|
if (node.signature.kind === SyntaxKind.OperationSignatureDeclaration) {
|
|
2343
2347
|
table.set("parameters", node.signature.parameters.symbol);
|
|
@@ -2424,7 +2428,7 @@ export function createChecker(program) {
|
|
|
2424
2428
|
const sym = createSymbol(member.node, member.name, kind | 16777216 /* SymbolFlags.LateBound */, containerSym);
|
|
2425
2429
|
mutate(sym).type = member;
|
|
2426
2430
|
compilerAssert(containerSym.members, "containerSym.members is undefined");
|
|
2427
|
-
containerMembers
|
|
2431
|
+
containerMembers ??= getOrCreateAugmentedSymbolTable(containerSym.members);
|
|
2428
2432
|
containerMembers.set(member.name, sym);
|
|
2429
2433
|
}
|
|
2430
2434
|
}
|
|
@@ -2548,6 +2552,7 @@ export function createChecker(program) {
|
|
|
2548
2552
|
target: targetNode,
|
|
2549
2553
|
}));
|
|
2550
2554
|
}
|
|
2555
|
+
parentModel.sourceModels.push({ usage: "spread", model: targetType });
|
|
2551
2556
|
const props = [];
|
|
2552
2557
|
// copy each property
|
|
2553
2558
|
for (const prop of walkPropertiesInherited(targetType)) {
|
|
@@ -2581,7 +2586,6 @@ export function createChecker(program) {
|
|
|
2581
2586
|
}
|
|
2582
2587
|
}
|
|
2583
2588
|
function checkModelProperty(prop, mapper) {
|
|
2584
|
-
var _a, _b, _c;
|
|
2585
2589
|
const symId = getSymbolId(getSymbolForMember(prop));
|
|
2586
2590
|
const links = getSymbolLinksForMember(prop);
|
|
2587
2591
|
if (links && links.declaredType && mapper === undefined) {
|
|
@@ -2616,8 +2620,8 @@ export function createChecker(program) {
|
|
|
2616
2620
|
const parentTemplate = getParentTemplateNode(prop);
|
|
2617
2621
|
linkMapper(type, mapper);
|
|
2618
2622
|
if (!parentTemplate || shouldCreateTypeForTemplate(parentTemplate, mapper)) {
|
|
2619
|
-
if (
|
|
2620
|
-
|
|
2623
|
+
if (prop.parent?.parent?.kind === SyntaxKind.OperationSignatureDeclaration &&
|
|
2624
|
+
prop.parent.parent.parent?.kind === SyntaxKind.OperationStatement) {
|
|
2621
2625
|
const doc = extractParamDoc(prop.parent.parent.parent, type.name);
|
|
2622
2626
|
if (doc) {
|
|
2623
2627
|
type.decorators.unshift(createDocFromCommentDecorator("self", doc));
|
|
@@ -2674,7 +2678,6 @@ export function createChecker(program) {
|
|
|
2674
2678
|
}
|
|
2675
2679
|
}
|
|
2676
2680
|
function checkDecorator(targetType, decNode, mapper) {
|
|
2677
|
-
var _a;
|
|
2678
2681
|
const sym = resolveTypeReferenceSym(decNode.target, undefined, true);
|
|
2679
2682
|
if (!sym) {
|
|
2680
2683
|
reportCheckerDiagnostic(createDiagnostic({
|
|
@@ -2697,7 +2700,7 @@ export function createChecker(program) {
|
|
|
2697
2700
|
if (symbolLinks.declaredType === undefined) {
|
|
2698
2701
|
const decoratorDeclNode = sym.declarations.find((x) => x.kind === SyntaxKind.DecoratorDeclarationStatement);
|
|
2699
2702
|
if (decoratorDeclNode) {
|
|
2700
|
-
checkDecoratorDeclaration(decoratorDeclNode,
|
|
2703
|
+
checkDecoratorDeclaration(decoratorDeclNode, undefined);
|
|
2701
2704
|
}
|
|
2702
2705
|
}
|
|
2703
2706
|
if (symbolLinks.declaredType) {
|
|
@@ -2710,13 +2713,12 @@ export function createChecker(program) {
|
|
|
2710
2713
|
}
|
|
2711
2714
|
return {
|
|
2712
2715
|
definition: symbolLinks.declaredType,
|
|
2713
|
-
decorator:
|
|
2716
|
+
decorator: sym.value ?? ((...args) => { }),
|
|
2714
2717
|
node: decNode,
|
|
2715
2718
|
args,
|
|
2716
2719
|
};
|
|
2717
2720
|
}
|
|
2718
2721
|
function checkDecoratorUsage(targetType, declaration, args, decoratorNode) {
|
|
2719
|
-
var _a;
|
|
2720
2722
|
let hasError = false;
|
|
2721
2723
|
const [targetValid] = isTypeAssignableTo(targetType, declaration.target.type, decoratorNode);
|
|
2722
2724
|
if (!targetValid) {
|
|
@@ -2733,7 +2735,7 @@ export function createChecker(program) {
|
|
|
2733
2735
|
}));
|
|
2734
2736
|
}
|
|
2735
2737
|
const minArgs = declaration.parameters.filter((x) => !x.optional && !x.rest).length;
|
|
2736
|
-
const maxArgs =
|
|
2738
|
+
const maxArgs = declaration.parameters[declaration.parameters.length - 1]?.rest
|
|
2737
2739
|
? undefined
|
|
2738
2740
|
: declaration.parameters.length;
|
|
2739
2741
|
if (args.length < minArgs || (maxArgs !== undefined && args.length > maxArgs)) {
|
|
@@ -2793,8 +2795,7 @@ export function createChecker(program) {
|
|
|
2793
2795
|
return [hasError, resolvedArgs];
|
|
2794
2796
|
}
|
|
2795
2797
|
function getIndexType(type) {
|
|
2796
|
-
|
|
2797
|
-
return type.kind === "Model" ? (_a = type.indexer) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
2798
|
+
return type.kind === "Model" ? type.indexer?.value : undefined;
|
|
2798
2799
|
}
|
|
2799
2800
|
function resolveDecoratorArgJsValue(value, valueOf) {
|
|
2800
2801
|
if (valueOf) {
|
|
@@ -2822,8 +2823,7 @@ export function createChecker(program) {
|
|
|
2822
2823
|
return valid;
|
|
2823
2824
|
}
|
|
2824
2825
|
function checkAugmentDecorators(sym, targetType, mapper) {
|
|
2825
|
-
|
|
2826
|
-
const augmentDecoratorNodes = (_a = augmentDecoratorsForSym.get(sym)) !== null && _a !== void 0 ? _a : [];
|
|
2826
|
+
const augmentDecoratorNodes = augmentDecoratorsForSym.get(sym) ?? [];
|
|
2827
2827
|
const decorators = [];
|
|
2828
2828
|
for (const decNode of augmentDecoratorNodes) {
|
|
2829
2829
|
const decorator = checkDecorator(targetType, decNode, mapper);
|
|
@@ -2834,10 +2834,9 @@ export function createChecker(program) {
|
|
|
2834
2834
|
return decorators;
|
|
2835
2835
|
}
|
|
2836
2836
|
function checkDecorators(targetType, node, mapper) {
|
|
2837
|
-
|
|
2838
|
-
const sym = isMemberNode(node) ? (_a = getSymbolForMember(node)) !== null && _a !== void 0 ? _a : node.symbol : node.symbol;
|
|
2837
|
+
const sym = isMemberNode(node) ? getSymbolForMember(node) ?? node.symbol : node.symbol;
|
|
2839
2838
|
const decorators = [];
|
|
2840
|
-
const augmentDecoratorNodes =
|
|
2839
|
+
const augmentDecoratorNodes = augmentDecoratorsForSym.get(sym) ?? [];
|
|
2841
2840
|
const decoratorNodes = [
|
|
2842
2841
|
...augmentDecoratorNodes, // the first decorator will be executed at last, so augmented decorator should be placed at first.
|
|
2843
2842
|
...node.decorators,
|
|
@@ -2875,7 +2874,6 @@ export function createChecker(program) {
|
|
|
2875
2874
|
});
|
|
2876
2875
|
}
|
|
2877
2876
|
function checkScalar(node, mapper) {
|
|
2878
|
-
var _a;
|
|
2879
2877
|
const links = getSymbolLinks(node.symbol);
|
|
2880
2878
|
if (links.declaredType && mapper === undefined) {
|
|
2881
2879
|
// we're not instantiating this model and we've already checked it
|
|
@@ -2901,7 +2899,7 @@ export function createChecker(program) {
|
|
|
2901
2899
|
}
|
|
2902
2900
|
decorators.push(...checkDecorators(type, node, mapper));
|
|
2903
2901
|
if (mapper === undefined) {
|
|
2904
|
-
|
|
2902
|
+
type.namespace?.scalars.set(type.name, type);
|
|
2905
2903
|
}
|
|
2906
2904
|
linkMapper(type, mapper);
|
|
2907
2905
|
if (shouldCreateTypeForTemplate(node, mapper)) {
|
|
@@ -2966,7 +2964,6 @@ export function createChecker(program) {
|
|
|
2966
2964
|
return type;
|
|
2967
2965
|
}
|
|
2968
2966
|
function checkEnum(node, mapper) {
|
|
2969
|
-
var _a;
|
|
2970
2967
|
const links = getSymbolLinks(node.symbol);
|
|
2971
2968
|
if (!links.type) {
|
|
2972
2969
|
const enumType = (links.type = createType({
|
|
@@ -3001,7 +2998,7 @@ export function createChecker(program) {
|
|
|
3001
2998
|
}
|
|
3002
2999
|
const namespace = getParentNamespaceType(node);
|
|
3003
3000
|
enumType.namespace = namespace;
|
|
3004
|
-
|
|
3001
|
+
enumType.namespace?.enums.set(enumType.name, enumType);
|
|
3005
3002
|
enumType.decorators = checkDecorators(enumType, node, mapper);
|
|
3006
3003
|
linkMapper(enumType, mapper);
|
|
3007
3004
|
finishType(enumType);
|
|
@@ -3009,7 +3006,6 @@ export function createChecker(program) {
|
|
|
3009
3006
|
return links.type;
|
|
3010
3007
|
}
|
|
3011
3008
|
function checkInterface(node, mapper) {
|
|
3012
|
-
var _a;
|
|
3013
3009
|
const links = getSymbolLinks(node.symbol);
|
|
3014
3010
|
if (links.declaredType && mapper === undefined) {
|
|
3015
3011
|
// we're not instantiating this interface and we've already checked it
|
|
@@ -3063,7 +3059,7 @@ export function createChecker(program) {
|
|
|
3063
3059
|
finishType(interfaceType);
|
|
3064
3060
|
}
|
|
3065
3061
|
if (mapper === undefined) {
|
|
3066
|
-
|
|
3062
|
+
interfaceType.namespace?.interfaces.set(interfaceType.name, interfaceType);
|
|
3067
3063
|
}
|
|
3068
3064
|
return interfaceType;
|
|
3069
3065
|
}
|
|
@@ -3071,22 +3067,19 @@ export function createChecker(program) {
|
|
|
3071
3067
|
const ownMembers = new Map();
|
|
3072
3068
|
for (const opNode of node.operations) {
|
|
3073
3069
|
const opType = checkOperation(opNode, mapper, interfaceType);
|
|
3074
|
-
if (opType.
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
continue;
|
|
3082
|
-
}
|
|
3083
|
-
ownMembers.set(opType.name, opType);
|
|
3070
|
+
if (ownMembers.has(opType.name)) {
|
|
3071
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
3072
|
+
code: "interface-duplicate",
|
|
3073
|
+
format: { name: opType.name },
|
|
3074
|
+
target: opNode,
|
|
3075
|
+
}));
|
|
3076
|
+
continue;
|
|
3084
3077
|
}
|
|
3078
|
+
ownMembers.set(opType.name, opType);
|
|
3085
3079
|
}
|
|
3086
3080
|
return ownMembers;
|
|
3087
3081
|
}
|
|
3088
3082
|
function checkUnion(node, mapper) {
|
|
3089
|
-
var _a;
|
|
3090
3083
|
const links = getSymbolLinks(node.symbol);
|
|
3091
3084
|
if (links.declaredType && mapper === undefined) {
|
|
3092
3085
|
// we're not instantiating this union and we've already checked it
|
|
@@ -3114,7 +3107,7 @@ export function createChecker(program) {
|
|
|
3114
3107
|
finishType(unionType);
|
|
3115
3108
|
}
|
|
3116
3109
|
if (mapper === undefined) {
|
|
3117
|
-
|
|
3110
|
+
unionType.namespace?.unions.set(unionType.name, unionType);
|
|
3118
3111
|
}
|
|
3119
3112
|
return unionType;
|
|
3120
3113
|
}
|
|
@@ -3169,12 +3162,11 @@ export function createChecker(program) {
|
|
|
3169
3162
|
return parentSym ? getOrCreateAugmentedSymbolTable(parentSym.members).get(name) : undefined;
|
|
3170
3163
|
}
|
|
3171
3164
|
function getSymbolForMember(node) {
|
|
3172
|
-
var _a;
|
|
3173
3165
|
if (!node.id) {
|
|
3174
3166
|
return undefined;
|
|
3175
3167
|
}
|
|
3176
3168
|
const name = node.id.sv;
|
|
3177
|
-
const parentSym =
|
|
3169
|
+
const parentSym = node.parent?.symbol;
|
|
3178
3170
|
return parentSym ? getOrCreateAugmentedSymbolTable(parentSym.members).get(name) : undefined;
|
|
3179
3171
|
}
|
|
3180
3172
|
function getSymbolLinksForMember(node) {
|
|
@@ -3184,7 +3176,7 @@ export function createChecker(program) {
|
|
|
3184
3176
|
function checkEnumMember(node, mapper, parentEnum) {
|
|
3185
3177
|
const name = node.id.sv;
|
|
3186
3178
|
const links = getSymbolLinksForMember(node);
|
|
3187
|
-
if (links
|
|
3179
|
+
if (links?.type) {
|
|
3188
3180
|
return links.type;
|
|
3189
3181
|
}
|
|
3190
3182
|
compilerAssert(parentEnum, "Enum member should already have been checked.");
|
|
@@ -3235,9 +3227,8 @@ export function createChecker(program) {
|
|
|
3235
3227
|
return members;
|
|
3236
3228
|
}
|
|
3237
3229
|
function checkDirectives(node, type) {
|
|
3238
|
-
var _a;
|
|
3239
3230
|
let hasDeprecation = false;
|
|
3240
|
-
for (const directive of
|
|
3231
|
+
for (const directive of node.directives ?? []) {
|
|
3241
3232
|
if (directive.target.sv === "deprecated") {
|
|
3242
3233
|
const message = directive.arguments[0];
|
|
3243
3234
|
if (message === undefined) {
|
|
@@ -3681,6 +3672,7 @@ export function createChecker(program) {
|
|
|
3681
3672
|
decorators: [],
|
|
3682
3673
|
properties: createRekeyableMap(),
|
|
3683
3674
|
derivedModels: [],
|
|
3675
|
+
sourceModels: [],
|
|
3684
3676
|
});
|
|
3685
3677
|
for (const propNode of node.properties) {
|
|
3686
3678
|
if (propNode.kind === SyntaxKind.ProjectionModelProperty) {
|
|
@@ -4174,7 +4166,6 @@ export function createChecker(program) {
|
|
|
4174
4166
|
return [result, diagnostics];
|
|
4175
4167
|
}
|
|
4176
4168
|
function isTypeAssignableToWorker(source, target, diagnosticTarget, relationCache) {
|
|
4177
|
-
var _a;
|
|
4178
4169
|
// BACKCOMPAT: Added May 2023 sprint, to be removed by June 2023 sprint
|
|
4179
4170
|
if (source.kind === "TemplateParameter" && source.constraint && target.kind === "Value") {
|
|
4180
4171
|
const [assignable] = isTypeAssignableToInternal(source.constraint, target.target, diagnosticTarget, relationCache);
|
|
@@ -4185,7 +4176,7 @@ export function createChecker(program) {
|
|
|
4185
4176
|
}
|
|
4186
4177
|
}
|
|
4187
4178
|
while (source.kind === "TemplateParameter" && source.constraint !== source) {
|
|
4188
|
-
source =
|
|
4179
|
+
source = source.constraint ?? unknownType;
|
|
4189
4180
|
}
|
|
4190
4181
|
if (source === target)
|
|
4191
4182
|
return [Related.true, []];
|
|
@@ -4231,8 +4222,10 @@ export function createChecker(program) {
|
|
|
4231
4222
|
],
|
|
4232
4223
|
];
|
|
4233
4224
|
}
|
|
4234
|
-
else if (target.kind === "Model" &&
|
|
4235
|
-
|
|
4225
|
+
else if (target.kind === "Model" &&
|
|
4226
|
+
isArrayModelType(program, target) &&
|
|
4227
|
+
source.kind === "Model") {
|
|
4228
|
+
return hasIndexAndIsAssignableTo(source, target, diagnosticTarget, relationCache);
|
|
4236
4229
|
}
|
|
4237
4230
|
else if (target.kind === "Model" && source.kind === "Model") {
|
|
4238
4231
|
return isModelRelatedTo(source, target, diagnosticTarget, relationCache);
|
|
@@ -4271,10 +4264,9 @@ export function createChecker(program) {
|
|
|
4271
4264
|
return [Related.true, []];
|
|
4272
4265
|
}
|
|
4273
4266
|
function isReflectionType(type) {
|
|
4274
|
-
var _a, _b, _c;
|
|
4275
4267
|
return (type.kind === "Model" &&
|
|
4276
|
-
|
|
4277
|
-
|
|
4268
|
+
type.namespace?.name === "Reflection" &&
|
|
4269
|
+
type.namespace?.namespace?.name === "TypeSpec");
|
|
4278
4270
|
}
|
|
4279
4271
|
function isRelatedToScalar(source, target) {
|
|
4280
4272
|
switch (source.kind) {
|
|
@@ -4357,6 +4349,7 @@ export function createChecker(program) {
|
|
|
4357
4349
|
function isModelRelatedTo(source, target, diagnosticTarget, relationCache) {
|
|
4358
4350
|
relationCache.set([source, target], Related.maybe);
|
|
4359
4351
|
const diagnostics = [];
|
|
4352
|
+
const remainingProperties = new Map(source.properties);
|
|
4360
4353
|
for (const prop of walkPropertiesInherited(target)) {
|
|
4361
4354
|
const sourceProperty = getProperty(source, prop.name);
|
|
4362
4355
|
if (sourceProperty === undefined) {
|
|
@@ -4373,62 +4366,58 @@ export function createChecker(program) {
|
|
|
4373
4366
|
}
|
|
4374
4367
|
}
|
|
4375
4368
|
else {
|
|
4369
|
+
remainingProperties.delete(prop.name);
|
|
4376
4370
|
const [related, propDiagnostics] = isTypeAssignableToInternal(sourceProperty.type, prop.type, diagnosticTarget, relationCache);
|
|
4377
4371
|
if (!related) {
|
|
4378
4372
|
diagnostics.push(...propDiagnostics);
|
|
4379
4373
|
}
|
|
4380
4374
|
}
|
|
4381
4375
|
}
|
|
4376
|
+
if (target.indexer) {
|
|
4377
|
+
const [_, indexerDiagnostics] = arePropertiesAssignableToIndexer(remainingProperties, target.indexer.value, diagnosticTarget, relationCache);
|
|
4378
|
+
diagnostics.push(...indexerDiagnostics);
|
|
4379
|
+
// For anonymous models we don't need an indexer
|
|
4380
|
+
if (source.name !== "" && target.indexer.key.name !== "integer") {
|
|
4381
|
+
const [related, indexDiagnostics] = hasIndexAndIsAssignableTo(source, target, diagnosticTarget, relationCache);
|
|
4382
|
+
if (!related) {
|
|
4383
|
+
diagnostics.push(...indexDiagnostics);
|
|
4384
|
+
}
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4382
4387
|
return [diagnostics.length === 0 ? Related.true : Related.false, diagnostics];
|
|
4383
4388
|
}
|
|
4384
4389
|
function getProperty(model, name) {
|
|
4385
|
-
|
|
4386
|
-
|
|
4390
|
+
return (model.properties.get(name) ??
|
|
4391
|
+
(model.baseModel !== undefined ? getProperty(model.baseModel, name) : undefined));
|
|
4387
4392
|
}
|
|
4388
|
-
function
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
return isIndexConstraintValid(target.indexer.value, source, diagnosticTarget, relationCache);
|
|
4392
|
-
}
|
|
4393
|
-
else {
|
|
4394
|
-
if (source.indexer === undefined || source.indexer.key !== target.indexer.key) {
|
|
4395
|
-
return [
|
|
4396
|
-
Related.false,
|
|
4397
|
-
[
|
|
4398
|
-
createDiagnostic({
|
|
4399
|
-
code: "missing-index",
|
|
4400
|
-
format: {
|
|
4401
|
-
indexType: getTypeName(target.indexer.key),
|
|
4402
|
-
sourceType: getTypeName(source),
|
|
4403
|
-
},
|
|
4404
|
-
target: diagnosticTarget,
|
|
4405
|
-
}),
|
|
4406
|
-
],
|
|
4407
|
-
];
|
|
4408
|
-
}
|
|
4409
|
-
return isTypeAssignableToInternal(source.indexer.value, target.indexer.value, diagnosticTarget, relationCache);
|
|
4410
|
-
}
|
|
4411
|
-
}
|
|
4412
|
-
/**
|
|
4413
|
-
* @param constraintType Type of the constraints(All properties must have this type).
|
|
4414
|
-
* @param type Type of the model that should be respecting the constraint.
|
|
4415
|
-
* @param diagnosticTarget Diagnostic target unless something better can be inferred.
|
|
4416
|
-
*/
|
|
4417
|
-
function isIndexConstraintValid(constraintType, type, diagnosticTarget, relationCache) {
|
|
4418
|
-
for (const prop of type.properties.values()) {
|
|
4419
|
-
const [related, diagnostics] = isTypeAssignableTo(prop.type, constraintType, diagnosticTarget);
|
|
4420
|
-
if (!related) {
|
|
4421
|
-
return [Related.false, diagnostics];
|
|
4422
|
-
}
|
|
4423
|
-
}
|
|
4424
|
-
if (type.baseModel) {
|
|
4425
|
-
const [related, diagnostics] = isIndexConstraintValid(constraintType, type.baseModel, diagnosticTarget, relationCache);
|
|
4393
|
+
function arePropertiesAssignableToIndexer(properties, indexerConstaint, diagnosticTarget, relationCache) {
|
|
4394
|
+
for (const prop of properties.values()) {
|
|
4395
|
+
const [related, diagnostics] = isTypeAssignableToInternal(prop.type, indexerConstaint, diagnosticTarget, relationCache);
|
|
4426
4396
|
if (!related) {
|
|
4427
4397
|
return [Related.false, diagnostics];
|
|
4428
4398
|
}
|
|
4429
4399
|
}
|
|
4430
4400
|
return [Related.true, []];
|
|
4431
4401
|
}
|
|
4402
|
+
/** Check that the source model has an index, the index key match and the value of the source index is assignable to the target index. */
|
|
4403
|
+
function hasIndexAndIsAssignableTo(source, target, diagnosticTarget, relationCache) {
|
|
4404
|
+
if (source.indexer === undefined || source.indexer.key !== target.indexer.key) {
|
|
4405
|
+
return [
|
|
4406
|
+
Related.false,
|
|
4407
|
+
[
|
|
4408
|
+
createDiagnostic({
|
|
4409
|
+
code: "missing-index",
|
|
4410
|
+
format: {
|
|
4411
|
+
indexType: getTypeName(target.indexer.key),
|
|
4412
|
+
sourceType: getTypeName(source),
|
|
4413
|
+
},
|
|
4414
|
+
target: diagnosticTarget,
|
|
4415
|
+
}),
|
|
4416
|
+
],
|
|
4417
|
+
];
|
|
4418
|
+
}
|
|
4419
|
+
return isTypeAssignableToInternal(source.indexer.value, target.indexer.value, diagnosticTarget, relationCache);
|
|
4420
|
+
}
|
|
4432
4421
|
function isTupleAssignableToTuple(source, target, diagnosticTarget, relationCache) {
|
|
4433
4422
|
if (source.values.length !== target.values.length) {
|
|
4434
4423
|
return [
|
|
@@ -4496,8 +4485,7 @@ export function createChecker(program) {
|
|
|
4496
4485
|
});
|
|
4497
4486
|
}
|
|
4498
4487
|
function isStdType(type, stdType) {
|
|
4499
|
-
|
|
4500
|
-
type = (_a = type.projectionBase) !== null && _a !== void 0 ? _a : type;
|
|
4488
|
+
type = type.projectionBase ?? type;
|
|
4501
4489
|
if ((type.kind !== "Model" && type.kind !== "Scalar") ||
|
|
4502
4490
|
type.namespace === undefined ||
|
|
4503
4491
|
!isTypeSpecNamespace(type.namespace))
|
|
@@ -4538,13 +4526,12 @@ const numericRanges = {
|
|
|
4538
4526
|
* chain.
|
|
4539
4527
|
*/
|
|
4540
4528
|
function getNamedSourceModels(property) {
|
|
4541
|
-
var _a;
|
|
4542
4529
|
if (!property.sourceProperty) {
|
|
4543
4530
|
return undefined;
|
|
4544
4531
|
}
|
|
4545
4532
|
const set = new Set();
|
|
4546
4533
|
for (let p = property; p; p = p.sourceProperty) {
|
|
4547
|
-
if (
|
|
4534
|
+
if (p.model?.name) {
|
|
4548
4535
|
set.add(p.model);
|
|
4549
4536
|
}
|
|
4550
4537
|
}
|
|
@@ -4567,17 +4554,15 @@ function addDerivedModels(models, possiblyDerivedModels) {
|
|
|
4567
4554
|
}
|
|
4568
4555
|
}
|
|
4569
4556
|
function createTypeMapper(parameters, args, parentMapper) {
|
|
4570
|
-
|
|
4571
|
-
const map = new Map((_a = parentMapper === null || parentMapper === void 0 ? void 0 : parentMapper.map) !== null && _a !== void 0 ? _a : []);
|
|
4557
|
+
const map = new Map(parentMapper?.map ?? []);
|
|
4572
4558
|
for (const [index, param] of parameters.entries()) {
|
|
4573
4559
|
map.set(param, args[index]);
|
|
4574
4560
|
}
|
|
4575
4561
|
return {
|
|
4576
4562
|
partial: false,
|
|
4577
|
-
args: [...(
|
|
4563
|
+
args: [...(parentMapper?.args ?? []), ...args],
|
|
4578
4564
|
getMappedType: (type) => {
|
|
4579
|
-
|
|
4580
|
-
return (_a = map.get(type)) !== null && _a !== void 0 ? _a : type;
|
|
4565
|
+
return map.get(type) ?? type;
|
|
4581
4566
|
},
|
|
4582
4567
|
map,
|
|
4583
4568
|
};
|
|
@@ -4651,7 +4636,7 @@ export function getEffectiveModelType(program, model, filter) {
|
|
|
4651
4636
|
// ignoring filtering as a better match than one that requires filtering
|
|
4652
4637
|
// to meet this test.
|
|
4653
4638
|
let match;
|
|
4654
|
-
for (const candidate of candidates
|
|
4639
|
+
for (const candidate of candidates ?? []) {
|
|
4655
4640
|
if (model.properties.size === countPropertiesInherited(candidate)) {
|
|
4656
4641
|
match = candidate;
|
|
4657
4642
|
break; // exact match
|
|
@@ -4661,7 +4646,7 @@ export function getEffectiveModelType(program, model, filter) {
|
|
|
4661
4646
|
continue; // match with filter: keep searching for exact match
|
|
4662
4647
|
}
|
|
4663
4648
|
}
|
|
4664
|
-
return match
|
|
4649
|
+
return match ?? model;
|
|
4665
4650
|
}
|
|
4666
4651
|
/**
|
|
4667
4652
|
* Applies a filter to the properties of a given type. If no properties
|
|
@@ -4691,6 +4676,7 @@ export function filterModelProperties(program, model, filter) {
|
|
|
4691
4676
|
properties,
|
|
4692
4677
|
decorators: [],
|
|
4693
4678
|
derivedModels: [],
|
|
4679
|
+
sourceModels: [{ usage: "spread", model }],
|
|
4694
4680
|
});
|
|
4695
4681
|
for (const property of walkPropertiesInherited(model)) {
|
|
4696
4682
|
if (filter(property)) {
|
|
@@ -4758,8 +4744,7 @@ function linkMapper(typeDef, mapper) {
|
|
|
4758
4744
|
}
|
|
4759
4745
|
}
|
|
4760
4746
|
function extractMainDoc(type) {
|
|
4761
|
-
|
|
4762
|
-
if (((_a = type.node) === null || _a === void 0 ? void 0 : _a.docs) === undefined) {
|
|
4747
|
+
if (type.node?.docs === undefined) {
|
|
4763
4748
|
return undefined;
|
|
4764
4749
|
}
|
|
4765
4750
|
let mainDoc = "";
|
|
@@ -4770,12 +4755,11 @@ function extractMainDoc(type) {
|
|
|
4770
4755
|
return trimmed === "" ? undefined : trimmed;
|
|
4771
4756
|
}
|
|
4772
4757
|
function extractReturnsDocs(type) {
|
|
4773
|
-
var _a;
|
|
4774
4758
|
const result = {
|
|
4775
4759
|
returns: undefined,
|
|
4776
4760
|
errors: undefined,
|
|
4777
4761
|
};
|
|
4778
|
-
if (
|
|
4762
|
+
if (type.node?.docs === undefined) {
|
|
4779
4763
|
return result;
|
|
4780
4764
|
}
|
|
4781
4765
|
for (const doc of type.node.docs) {
|
|
@@ -4833,7 +4817,6 @@ function reportDeprecation(program, target, message, reportFunc) {
|
|
|
4833
4817
|
}
|
|
4834
4818
|
}
|
|
4835
4819
|
function applyDecoratorToType(program, decApp, target) {
|
|
4836
|
-
var _a, _b;
|
|
4837
4820
|
compilerAssert("decorators" in target, "Cannot apply decorator to non-decoratable type", target);
|
|
4838
4821
|
for (const arg of decApp.args) {
|
|
4839
4822
|
if (isErrorType(arg.value)) {
|
|
@@ -4845,7 +4828,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4845
4828
|
if (decApp.definition) {
|
|
4846
4829
|
const deprecation = getDeprecationDetails(program, decApp.definition);
|
|
4847
4830
|
if (deprecation !== undefined) {
|
|
4848
|
-
reportDeprecation(program,
|
|
4831
|
+
reportDeprecation(program, decApp.node ?? target, deprecation.message, program.reportDiagnostic);
|
|
4849
4832
|
}
|
|
4850
4833
|
}
|
|
4851
4834
|
// peel `fn` off to avoid setting `this`.
|
|
@@ -4861,7 +4844,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4861
4844
|
program.reportDiagnostic(createDiagnostic({
|
|
4862
4845
|
code: "decorator-fail",
|
|
4863
4846
|
format: { decoratorName: decApp.decorator.name, error: error.stack },
|
|
4864
|
-
target:
|
|
4847
|
+
target: decApp.node ?? target,
|
|
4865
4848
|
}));
|
|
4866
4849
|
}
|
|
4867
4850
|
else {
|
|
@@ -4884,8 +4867,7 @@ function createDecoratorContext(program, decApp) {
|
|
|
4884
4867
|
program,
|
|
4885
4868
|
decoratorTarget: decApp.node,
|
|
4886
4869
|
getArgumentTarget: (index) => {
|
|
4887
|
-
|
|
4888
|
-
return (_a = decApp.args[index]) === null || _a === void 0 ? void 0 : _a.node;
|
|
4870
|
+
return decApp.args[index]?.node;
|
|
4889
4871
|
},
|
|
4890
4872
|
call: (decorator, target, ...args) => {
|
|
4891
4873
|
return decorator(createPassThruContext(program, decApp), target, ...args);
|
|
@@ -4937,33 +4919,29 @@ var ResolutionKind;
|
|
|
4937
4919
|
ResolutionKind[ResolutionKind["Constraint"] = 2] = "Constraint";
|
|
4938
4920
|
})(ResolutionKind || (ResolutionKind = {}));
|
|
4939
4921
|
class PendingResolutions {
|
|
4940
|
-
|
|
4941
|
-
_PendingResolutions_data.set(this, new Map());
|
|
4942
|
-
}
|
|
4922
|
+
#data = new Map();
|
|
4943
4923
|
start(symId, kind) {
|
|
4944
|
-
let existing =
|
|
4924
|
+
let existing = this.#data.get(symId);
|
|
4945
4925
|
if (existing === undefined) {
|
|
4946
4926
|
existing = new Set();
|
|
4947
|
-
|
|
4927
|
+
this.#data.set(symId, existing);
|
|
4948
4928
|
}
|
|
4949
4929
|
existing.add(kind);
|
|
4950
4930
|
}
|
|
4951
4931
|
has(symId, kind) {
|
|
4952
|
-
|
|
4953
|
-
return (_b = (_a = __classPrivateFieldGet(this, _PendingResolutions_data, "f").get(symId)) === null || _a === void 0 ? void 0 : _a.has(kind)) !== null && _b !== void 0 ? _b : false;
|
|
4932
|
+
return this.#data.get(symId)?.has(kind) ?? false;
|
|
4954
4933
|
}
|
|
4955
4934
|
finish(symId, kind) {
|
|
4956
|
-
const existing =
|
|
4935
|
+
const existing = this.#data.get(symId);
|
|
4957
4936
|
if (existing === undefined) {
|
|
4958
4937
|
return;
|
|
4959
4938
|
}
|
|
4960
|
-
existing
|
|
4939
|
+
existing?.delete(kind);
|
|
4961
4940
|
if (existing.size === 0) {
|
|
4962
|
-
|
|
4941
|
+
this.#data.delete(symId);
|
|
4963
4942
|
}
|
|
4964
4943
|
}
|
|
4965
4944
|
}
|
|
4966
|
-
_PendingResolutions_data = new WeakMap();
|
|
4967
4945
|
var Related;
|
|
4968
4946
|
(function (Related) {
|
|
4969
4947
|
Related[Related["false"] = 0] = "false";
|