@typespec/compiler 0.56.0-dev.2 → 0.56.0-dev.3
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.js +79 -134
- 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/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 +8 -11
- 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 +1 -1
- 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/numeric.d.ts +22 -0
- package/dist/src/core/numeric.d.ts.map +1 -0
- package/dist/src/core/numeric.js +162 -0
- package/dist/src/core/numeric.js.map +1 -0
- package/dist/src/core/parser.js +8 -11
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.js +28 -37
- 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/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.js +19 -35
- 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/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.js +7 -10
- 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.js +24 -33
- 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 +3 -4
- 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 +6 -6
- 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 +5 -5
- 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/package.json +1 -1
package/dist/src/core/checker.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
1
|
import { $docFromComment, getIndexer, isArrayModelType } from "../lib/decorators.js";
|
|
8
2
|
import { MultiKeyMap, createRekeyableMap, isArray, mutate } from "../utils/misc.js";
|
|
9
3
|
import { createSymbol, createSymbolTable } from "./binder.js";
|
|
@@ -151,12 +145,11 @@ export function createChecker(program) {
|
|
|
151
145
|
getSymbolLinks(nullSym).type = nullType;
|
|
152
146
|
}
|
|
153
147
|
function getStdType(name) {
|
|
154
|
-
var _a;
|
|
155
148
|
const type = stdTypes[name];
|
|
156
149
|
if (type !== undefined) {
|
|
157
150
|
return type;
|
|
158
151
|
}
|
|
159
|
-
const sym =
|
|
152
|
+
const sym = typespecNamespaceBinding?.exports?.get(name);
|
|
160
153
|
if (sym && sym.flags & 2 /* SymbolFlags.Model */) {
|
|
161
154
|
checkModelStatement(sym.declarations[0], undefined);
|
|
162
155
|
}
|
|
@@ -295,10 +288,9 @@ export function createChecker(program) {
|
|
|
295
288
|
* @returns Checked type for the given member symbol.
|
|
296
289
|
*/
|
|
297
290
|
function checkMemberSym(sym, mapper) {
|
|
298
|
-
var _a;
|
|
299
291
|
const symbolLinks = getSymbolLinks(sym);
|
|
300
292
|
const memberContainer = getTypeForNode(sym.parent.declarations[0], mapper);
|
|
301
|
-
const type =
|
|
293
|
+
const type = symbolLinks.declaredType ?? symbolLinks.type;
|
|
302
294
|
if (type) {
|
|
303
295
|
return type;
|
|
304
296
|
}
|
|
@@ -397,22 +389,20 @@ export function createChecker(program) {
|
|
|
397
389
|
* Return a fully qualified id of node
|
|
398
390
|
*/
|
|
399
391
|
function getNodeSymId(node) {
|
|
400
|
-
var _a;
|
|
401
392
|
const symbol = node.kind === SyntaxKind.OperationStatement &&
|
|
402
|
-
|
|
393
|
+
node.parent?.kind === SyntaxKind.InterfaceStatement
|
|
403
394
|
? getSymbolForMember(node)
|
|
404
395
|
: node.symbol;
|
|
405
396
|
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
|
406
|
-
return symbol
|
|
397
|
+
return symbol?.id;
|
|
407
398
|
}
|
|
408
399
|
/**
|
|
409
400
|
* Check if the given namespace is the standard library `TypeSpec` namespace.
|
|
410
401
|
*/
|
|
411
402
|
function isTypeSpecNamespace(namespace) {
|
|
412
|
-
var _a;
|
|
413
403
|
return (namespace.name === "TypeSpec" &&
|
|
414
404
|
(namespace.namespace === globalNamespaceType ||
|
|
415
|
-
|
|
405
|
+
namespace.namespace?.projectionBase === globalNamespaceType));
|
|
416
406
|
}
|
|
417
407
|
/**
|
|
418
408
|
* Check if the given type is defined right in the TypeSpec namespace.
|
|
@@ -421,7 +411,6 @@ export function createChecker(program) {
|
|
|
421
411
|
return Boolean(type.namespace && isTypeSpecNamespace(type.namespace));
|
|
422
412
|
}
|
|
423
413
|
function checkTemplateParameterDeclaration(node, mapper) {
|
|
424
|
-
var _a;
|
|
425
414
|
const parentNode = node.parent;
|
|
426
415
|
const grandParentNode = parentNode.parent;
|
|
427
416
|
const links = getSymbolLinks(node.symbol);
|
|
@@ -438,7 +427,7 @@ export function createChecker(program) {
|
|
|
438
427
|
let type = links.declaredType;
|
|
439
428
|
if (type === undefined) {
|
|
440
429
|
if (grandParentNode) {
|
|
441
|
-
if (
|
|
430
|
+
if (grandParentNode.locals?.has(node.id.sv)) {
|
|
442
431
|
reportCheckerDiagnostic(createDiagnostic({
|
|
443
432
|
code: "shadow",
|
|
444
433
|
format: { name: node.id.sv },
|
|
@@ -472,7 +461,6 @@ export function createChecker(program) {
|
|
|
472
461
|
return getTypeForNode(node.default, mapper);
|
|
473
462
|
}
|
|
474
463
|
function checkTemplateParameterDefault(nodeDefault, templateParameters, index, constraint) {
|
|
475
|
-
var _a;
|
|
476
464
|
function visit(node) {
|
|
477
465
|
const type = getTypeForNode(node);
|
|
478
466
|
let hasError = false;
|
|
@@ -493,7 +481,7 @@ export function createChecker(program) {
|
|
|
493
481
|
});
|
|
494
482
|
return hasError ? undefined : type;
|
|
495
483
|
}
|
|
496
|
-
const type =
|
|
484
|
+
const type = visit(nodeDefault) ?? errorType;
|
|
497
485
|
if (!isErrorType(type) && constraint) {
|
|
498
486
|
checkTypeAssignable(type, constraint, nodeDefault);
|
|
499
487
|
}
|
|
@@ -546,13 +534,12 @@ export function createChecker(program) {
|
|
|
546
534
|
}
|
|
547
535
|
function isTypeReferenceContextDeprecated(node) {
|
|
548
536
|
function checkDeprecatedNode(node) {
|
|
549
|
-
var _a;
|
|
550
537
|
// Perform a simple check if the parent node is deprecated. We do this
|
|
551
538
|
// out of band because `checkDirectives` usually gets called on the parent
|
|
552
539
|
// type after child types have already been checked (including their
|
|
553
540
|
// deprecations).
|
|
554
541
|
if (!nodeDeprecationMap.has(node)) {
|
|
555
|
-
nodeDeprecationMap.set(node, (
|
|
542
|
+
nodeDeprecationMap.set(node, (node.directives ?? []).findIndex((d) => d.target.sv === "deprecated") >= 0);
|
|
556
543
|
}
|
|
557
544
|
return nodeDeprecationMap.get(node);
|
|
558
545
|
}
|
|
@@ -580,8 +567,6 @@ export function createChecker(program) {
|
|
|
580
567
|
}
|
|
581
568
|
}
|
|
582
569
|
function checkTemplateInstantiationArgs(node, args, decls, mapper) {
|
|
583
|
-
var _a, _b, _c, _d;
|
|
584
|
-
var _e;
|
|
585
570
|
const params = new Map();
|
|
586
571
|
const positional = [];
|
|
587
572
|
const initMap = new Map(decls.map(function (decl) {
|
|
@@ -646,7 +631,7 @@ export function createChecker(program) {
|
|
|
646
631
|
continue;
|
|
647
632
|
}
|
|
648
633
|
const param = positional[idx];
|
|
649
|
-
|
|
634
|
+
initMap.get(param).checkArgument ??= deferredCheck;
|
|
650
635
|
}
|
|
651
636
|
}
|
|
652
637
|
const finalMap = initMap;
|
|
@@ -674,7 +659,7 @@ export function createChecker(program) {
|
|
|
674
659
|
target: node,
|
|
675
660
|
}));
|
|
676
661
|
// TODO-TIM check if we expose this below
|
|
677
|
-
commit(param,
|
|
662
|
+
commit(param, param.constraint?.kind === "Value" ? unknownType : param.constraint ?? unknownType);
|
|
678
663
|
}
|
|
679
664
|
continue;
|
|
680
665
|
}
|
|
@@ -685,7 +670,7 @@ export function createChecker(program) {
|
|
|
685
670
|
: param.constraint;
|
|
686
671
|
if (!checkTypeAssignable(type, constraint, argNode)) {
|
|
687
672
|
// TODO-TIM check if we expose this below
|
|
688
|
-
const effectiveType =
|
|
673
|
+
const effectiveType = param.constraint?.kind === "Value" ? unknownType : param.constraint;
|
|
689
674
|
commit(param, effectiveType);
|
|
690
675
|
continue;
|
|
691
676
|
}
|
|
@@ -794,7 +779,7 @@ export function createChecker(program) {
|
|
|
794
779
|
// Check for deprecations here, first on symbol, then on type. However,
|
|
795
780
|
// don't raise deprecation when the usage site is also a deprecated
|
|
796
781
|
// declaration.
|
|
797
|
-
const declarationNode = sym
|
|
782
|
+
const declarationNode = sym?.declarations[0];
|
|
798
783
|
if (declarationNode && mapper === undefined) {
|
|
799
784
|
if (!isTypeReferenceContextDeprecated(node.parent)) {
|
|
800
785
|
checkDeprecated(baseType, declarationNode, node);
|
|
@@ -846,7 +831,6 @@ export function createChecker(program) {
|
|
|
846
831
|
: checkUnion(node, mapper);
|
|
847
832
|
}
|
|
848
833
|
function getOrInstantiateTemplate(templateNode, params, args, parentMapper, instantiateTempalates = true) {
|
|
849
|
-
var _a;
|
|
850
834
|
const symbolLinks = templateNode.kind === SyntaxKind.OperationStatement &&
|
|
851
835
|
templateNode.parent.kind === SyntaxKind.InterfaceStatement
|
|
852
836
|
? getSymbolLinksForMember(templateNode)
|
|
@@ -862,7 +846,7 @@ export function createChecker(program) {
|
|
|
862
846
|
}
|
|
863
847
|
}
|
|
864
848
|
const mapper = createTypeMapper(params, args, parentMapper);
|
|
865
|
-
const cached =
|
|
849
|
+
const cached = symbolLinks.instantiations?.get(mapper.args);
|
|
866
850
|
if (cached) {
|
|
867
851
|
return cached;
|
|
868
852
|
}
|
|
@@ -968,7 +952,7 @@ export function createChecker(program) {
|
|
|
968
952
|
node,
|
|
969
953
|
target: checkFunctionParameter(node.target, mapper),
|
|
970
954
|
parameters: node.parameters.map((x) => checkFunctionParameter(x, mapper)),
|
|
971
|
-
implementation: implementation
|
|
955
|
+
implementation: implementation ?? (() => { }),
|
|
972
956
|
});
|
|
973
957
|
namespace.decoratorDeclarations.set(name, decoratorType);
|
|
974
958
|
linkType(links, decoratorType, mapper);
|
|
@@ -998,7 +982,7 @@ export function createChecker(program) {
|
|
|
998
982
|
node,
|
|
999
983
|
parameters: node.parameters.map((x) => checkFunctionParameter(x, mapper)),
|
|
1000
984
|
returnType: node.returnType ? getTypeForNode(node.returnType, mapper) : unknownType,
|
|
1001
|
-
implementation: implementation
|
|
985
|
+
implementation: implementation ?? (() => { }),
|
|
1002
986
|
});
|
|
1003
987
|
namespace.functionDeclarations.set(name, functionType);
|
|
1004
988
|
linkType(links, functionType, mapper);
|
|
@@ -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) {
|
|
@@ -1294,7 +1277,7 @@ export function createChecker(program) {
|
|
|
1294
1277
|
finishType(operationType);
|
|
1295
1278
|
}
|
|
1296
1279
|
if (mapper === undefined) {
|
|
1297
|
-
namespace
|
|
1280
|
+
namespace?.operations.set(name, operationType);
|
|
1298
1281
|
}
|
|
1299
1282
|
}
|
|
1300
1283
|
return operationType;
|
|
@@ -1366,11 +1349,10 @@ export function createChecker(program) {
|
|
|
1366
1349
|
return s.id;
|
|
1367
1350
|
}
|
|
1368
1351
|
function resolveIdentifierInTable(node, table, options) {
|
|
1369
|
-
var _a, _b;
|
|
1370
1352
|
if (!table) {
|
|
1371
1353
|
return undefined;
|
|
1372
1354
|
}
|
|
1373
|
-
table =
|
|
1355
|
+
table = augmentedSymbolTables.get(table) ?? table;
|
|
1374
1356
|
let sym;
|
|
1375
1357
|
if (options.resolveDecorators) {
|
|
1376
1358
|
sym = table.get("@" + node.sv);
|
|
@@ -1381,7 +1363,7 @@ export function createChecker(program) {
|
|
|
1381
1363
|
if (!sym)
|
|
1382
1364
|
return sym;
|
|
1383
1365
|
if (sym.flags & 1048576 /* SymbolFlags.DuplicateUsing */) {
|
|
1384
|
-
reportAmbiguousIdentifier(node, [...(
|
|
1366
|
+
reportAmbiguousIdentifier(node, [...(table.duplicates.get(sym) ?? [])]);
|
|
1385
1367
|
return sym;
|
|
1386
1368
|
}
|
|
1387
1369
|
return getMergedSymbol(sym);
|
|
@@ -1395,7 +1377,6 @@ export function createChecker(program) {
|
|
|
1395
1377
|
}));
|
|
1396
1378
|
}
|
|
1397
1379
|
function resolveIdentifier(id, mapper) {
|
|
1398
|
-
var _a, _b, _c;
|
|
1399
1380
|
let sym;
|
|
1400
1381
|
const { node, kind } = getIdentifierContext(id);
|
|
1401
1382
|
switch (kind) {
|
|
@@ -1418,7 +1399,7 @@ export function createChecker(program) {
|
|
|
1418
1399
|
return undefined;
|
|
1419
1400
|
}
|
|
1420
1401
|
lateBindMembers(containerType, container);
|
|
1421
|
-
sym = resolveIdentifierInTable(id,
|
|
1402
|
+
sym = resolveIdentifierInTable(id, container.exports ?? container.members, defaultSymbolResolutionOptions);
|
|
1422
1403
|
break;
|
|
1423
1404
|
case IdentifierKind.Other:
|
|
1424
1405
|
return undefined;
|
|
@@ -1428,7 +1409,7 @@ export function createChecker(program) {
|
|
|
1428
1409
|
case IdentifierKind.TypeReference:
|
|
1429
1410
|
let ref = id;
|
|
1430
1411
|
let resolveDecorator = kind === IdentifierKind.Decorator;
|
|
1431
|
-
if (
|
|
1412
|
+
if (id.parent?.kind === SyntaxKind.MemberExpression) {
|
|
1432
1413
|
if (id.parent.id === id) {
|
|
1433
1414
|
// If the identifier is Y in X.Y, then resolve (X.Y).
|
|
1434
1415
|
ref = id.parent;
|
|
@@ -1454,15 +1435,13 @@ export function createChecker(program) {
|
|
|
1454
1435
|
const _assertNever = kind;
|
|
1455
1436
|
compilerAssert(false, "Unreachable");
|
|
1456
1437
|
}
|
|
1457
|
-
return
|
|
1438
|
+
return sym?.symbolSource ?? sym;
|
|
1458
1439
|
}
|
|
1459
1440
|
function getTemplateDeclarationsForArgument(node, mapper) {
|
|
1460
|
-
var _a;
|
|
1461
1441
|
const resolved = resolveTypeReferenceSym(node.parent, mapper, false);
|
|
1462
|
-
return (
|
|
1442
|
+
return (resolved?.declarations.filter((n) => isTemplatedNode(n)) ?? []);
|
|
1463
1443
|
}
|
|
1464
1444
|
function resolveCompletions(identifier) {
|
|
1465
|
-
var _a, _b, _c;
|
|
1466
1445
|
const completions = new Map();
|
|
1467
1446
|
const { kind, node: ancestor } = getIdentifierContext(identifier);
|
|
1468
1447
|
switch (kind) {
|
|
@@ -1496,13 +1475,13 @@ export function createChecker(program) {
|
|
|
1496
1475
|
}
|
|
1497
1476
|
if (base) {
|
|
1498
1477
|
if (isTemplatedNode(base.declarations[0])) {
|
|
1499
|
-
const type =
|
|
1478
|
+
const type = base.type ?? getTypeForNode(base.declarations[0], undefined);
|
|
1500
1479
|
if (isTemplateInstance(type)) {
|
|
1501
1480
|
lateBindMemberContainer(type);
|
|
1502
1481
|
lateBindMembers(type, base);
|
|
1503
1482
|
}
|
|
1504
1483
|
}
|
|
1505
|
-
addCompletions(
|
|
1484
|
+
addCompletions(base.exports ?? base.members);
|
|
1506
1485
|
}
|
|
1507
1486
|
}
|
|
1508
1487
|
}
|
|
@@ -1511,7 +1490,7 @@ export function createChecker(program) {
|
|
|
1511
1490
|
// to avoid completing the name of the argument again.
|
|
1512
1491
|
if (kind === IdentifierKind.TypeReference &&
|
|
1513
1492
|
exprIsBareIdentifier(ancestor) &&
|
|
1514
|
-
|
|
1493
|
+
ancestor.parent?.kind === SyntaxKind.TemplateArgument &&
|
|
1515
1494
|
ancestor.parent.name === undefined) {
|
|
1516
1495
|
const templates = getTemplateDeclarationsForArgument(ancestor.parent, undefined);
|
|
1517
1496
|
for (const template of templates) {
|
|
@@ -1545,11 +1524,10 @@ export function createChecker(program) {
|
|
|
1545
1524
|
}
|
|
1546
1525
|
return completions;
|
|
1547
1526
|
function addCompletions(table) {
|
|
1548
|
-
var _a;
|
|
1549
1527
|
if (!table) {
|
|
1550
1528
|
return;
|
|
1551
1529
|
}
|
|
1552
|
-
table =
|
|
1530
|
+
table = augmentedSymbolTables.get(table) ?? table;
|
|
1553
1531
|
for (const [key, sym] of table) {
|
|
1554
1532
|
if (sym.flags & 1048576 /* SymbolFlags.DuplicateUsing */) {
|
|
1555
1533
|
const duplicates = table.duplicates.get(sym);
|
|
@@ -1598,8 +1576,7 @@ export function createChecker(program) {
|
|
|
1598
1576
|
}
|
|
1599
1577
|
}
|
|
1600
1578
|
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.");
|
|
1579
|
+
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
1580
|
if (hasParseError(node)) {
|
|
1604
1581
|
// Don't report synthetic identifiers used for parser error recovery.
|
|
1605
1582
|
// The parse error is the root cause and will already have been logged.
|
|
@@ -1665,7 +1642,7 @@ export function createChecker(program) {
|
|
|
1665
1642
|
function resolveTypeReferenceSym(node, mapper, options) {
|
|
1666
1643
|
const resolvedOptions = typeof options === "boolean"
|
|
1667
1644
|
? { ...defaultSymbolResolutionOptions, resolveDecorators: options }
|
|
1668
|
-
: { ...defaultSymbolResolutionOptions, ...(options
|
|
1645
|
+
: { ...defaultSymbolResolutionOptions, ...(options ?? {}) };
|
|
1669
1646
|
if (mapper === undefined && resolvedOptions.checkTemplateTypes && referenceSymCache.has(node)) {
|
|
1670
1647
|
return referenceSymCache.get(node);
|
|
1671
1648
|
}
|
|
@@ -1819,7 +1796,6 @@ export function createChecker(program) {
|
|
|
1819
1796
|
* instantiation) we late bind the container which creates the symbol that will hold its members.
|
|
1820
1797
|
*/
|
|
1821
1798
|
function getAliasedSymbol(aliasSymbol, mapper, options) {
|
|
1822
|
-
var _a;
|
|
1823
1799
|
let current = aliasSymbol;
|
|
1824
1800
|
while (current.flags & 2048 /* SymbolFlags.Alias */) {
|
|
1825
1801
|
const node = current.declarations[0];
|
|
@@ -1853,7 +1829,7 @@ export function createChecker(program) {
|
|
|
1853
1829
|
default:
|
|
1854
1830
|
// get the symbol from the node aliased type's node, or just return the base
|
|
1855
1831
|
// if it doesn't have a symbol (which will likely result in an error later on)
|
|
1856
|
-
return
|
|
1832
|
+
return getMergedSymbol(aliasType.node.symbol) ?? aliasSymbol;
|
|
1857
1833
|
}
|
|
1858
1834
|
}
|
|
1859
1835
|
function checkStringTemplateExpresion(node, mapper) {
|
|
@@ -1895,7 +1871,6 @@ export function createChecker(program) {
|
|
|
1895
1871
|
return getLiteralType(bool);
|
|
1896
1872
|
}
|
|
1897
1873
|
function checkProgram() {
|
|
1898
|
-
var _a, _b;
|
|
1899
1874
|
program.reportDuplicateSymbols(globalNamespaceNode.symbol.exports);
|
|
1900
1875
|
for (const file of program.sourceFiles.values()) {
|
|
1901
1876
|
bindAllMembers(file);
|
|
@@ -1905,7 +1880,7 @@ export function createChecker(program) {
|
|
|
1905
1880
|
}
|
|
1906
1881
|
for (const file of program.sourceFiles.values()) {
|
|
1907
1882
|
for (const ns of file.namespaces) {
|
|
1908
|
-
const exports =
|
|
1883
|
+
const exports = mergedSymbols.get(ns.symbol)?.exports ?? ns.symbol.exports;
|
|
1909
1884
|
program.reportDuplicateSymbols(exports);
|
|
1910
1885
|
initializeTypeForNamespace(ns);
|
|
1911
1886
|
}
|
|
@@ -1967,7 +1942,6 @@ export function createChecker(program) {
|
|
|
1967
1942
|
}
|
|
1968
1943
|
}
|
|
1969
1944
|
function checkModelStatement(node, mapper) {
|
|
1970
|
-
var _a;
|
|
1971
1945
|
const links = getSymbolLinks(node.symbol);
|
|
1972
1946
|
if (links.declaredType && mapper === undefined) {
|
|
1973
1947
|
// we're not instantiating this model and we've already checked it
|
|
@@ -2020,7 +1994,7 @@ export function createChecker(program) {
|
|
|
2020
1994
|
// Hold on to the model type that's being defined so that it
|
|
2021
1995
|
// can be referenced
|
|
2022
1996
|
if (mapper === undefined) {
|
|
2023
|
-
|
|
1997
|
+
type.namespace?.models.set(type.name, type);
|
|
2024
1998
|
}
|
|
2025
1999
|
// Evaluate the properties after
|
|
2026
2000
|
checkModelProperties(node, type.properties, type, mapper);
|
|
@@ -2170,7 +2144,7 @@ export function createChecker(program) {
|
|
|
2170
2144
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2171
2145
|
code: "duplicate-property",
|
|
2172
2146
|
format: { propName: newProp.name },
|
|
2173
|
-
target: diagnosticTarget
|
|
2147
|
+
target: diagnosticTarget ?? newProp,
|
|
2174
2148
|
}));
|
|
2175
2149
|
return;
|
|
2176
2150
|
}
|
|
@@ -2183,7 +2157,7 @@ export function createChecker(program) {
|
|
|
2183
2157
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2184
2158
|
code: "override-property-mismatch",
|
|
2185
2159
|
format: { propName: newProp.name, propType: newPropType, parentType: parentType },
|
|
2186
|
-
target: diagnosticTarget
|
|
2160
|
+
target: diagnosticTarget ?? newProp,
|
|
2187
2161
|
}));
|
|
2188
2162
|
return;
|
|
2189
2163
|
}
|
|
@@ -2289,8 +2263,7 @@ export function createChecker(program) {
|
|
|
2289
2263
|
}
|
|
2290
2264
|
}
|
|
2291
2265
|
function copyMembers(table) {
|
|
2292
|
-
|
|
2293
|
-
const members = (_a = augmentedSymbolTables.get(table)) !== null && _a !== void 0 ? _a : table;
|
|
2266
|
+
const members = augmentedSymbolTables.get(table) ?? table;
|
|
2294
2267
|
for (const member of members.values()) {
|
|
2295
2268
|
bindMember(member.name, member.declarations[0], member.flags);
|
|
2296
2269
|
}
|
|
@@ -2298,14 +2271,13 @@ export function createChecker(program) {
|
|
|
2298
2271
|
function bindMember(name, node, kind) {
|
|
2299
2272
|
const sym = createSymbol(node, name, kind, containerSym);
|
|
2300
2273
|
compilerAssert(containerSym.members, "containerSym.members is undefined");
|
|
2301
|
-
containerMembers
|
|
2274
|
+
containerMembers ??= getOrCreateAugmentedSymbolTable(containerSym.members);
|
|
2302
2275
|
containerMembers.set(name, sym);
|
|
2303
2276
|
}
|
|
2304
2277
|
}
|
|
2305
2278
|
}
|
|
2306
2279
|
function copyMembersToContainer(targetContainerSym, table) {
|
|
2307
|
-
|
|
2308
|
-
const members = (_a = augmentedSymbolTables.get(table)) !== null && _a !== void 0 ? _a : table;
|
|
2280
|
+
const members = augmentedSymbolTables.get(table) ?? table;
|
|
2309
2281
|
compilerAssert(targetContainerSym.members, "containerSym.members is undefined");
|
|
2310
2282
|
const containerMembers = getOrCreateAugmentedSymbolTable(targetContainerSym.members);
|
|
2311
2283
|
for (const member of members.values()) {
|
|
@@ -2320,7 +2292,6 @@ export function createChecker(program) {
|
|
|
2320
2292
|
function bindMetaTypes(node) {
|
|
2321
2293
|
const visited = new Set();
|
|
2322
2294
|
function visit(node, symbol) {
|
|
2323
|
-
var _a;
|
|
2324
2295
|
if (visited.has(node)) {
|
|
2325
2296
|
return;
|
|
2326
2297
|
}
|
|
@@ -2337,7 +2308,7 @@ export function createChecker(program) {
|
|
|
2337
2308
|
break;
|
|
2338
2309
|
}
|
|
2339
2310
|
case SyntaxKind.OperationStatement: {
|
|
2340
|
-
const sym =
|
|
2311
|
+
const sym = symbol ?? node.symbol ?? getSymbolForMember(node);
|
|
2341
2312
|
const table = getOrCreateAugmentedSymbolTable(sym.metatypeMembers);
|
|
2342
2313
|
if (node.signature.kind === SyntaxKind.OperationSignatureDeclaration) {
|
|
2343
2314
|
table.set("parameters", node.signature.parameters.symbol);
|
|
@@ -2424,7 +2395,7 @@ export function createChecker(program) {
|
|
|
2424
2395
|
const sym = createSymbol(member.node, member.name, kind | 16777216 /* SymbolFlags.LateBound */, containerSym);
|
|
2425
2396
|
mutate(sym).type = member;
|
|
2426
2397
|
compilerAssert(containerSym.members, "containerSym.members is undefined");
|
|
2427
|
-
containerMembers
|
|
2398
|
+
containerMembers ??= getOrCreateAugmentedSymbolTable(containerSym.members);
|
|
2428
2399
|
containerMembers.set(member.name, sym);
|
|
2429
2400
|
}
|
|
2430
2401
|
}
|
|
@@ -2581,7 +2552,6 @@ export function createChecker(program) {
|
|
|
2581
2552
|
}
|
|
2582
2553
|
}
|
|
2583
2554
|
function checkModelProperty(prop, mapper) {
|
|
2584
|
-
var _a, _b, _c;
|
|
2585
2555
|
const symId = getSymbolId(getSymbolForMember(prop));
|
|
2586
2556
|
const links = getSymbolLinksForMember(prop);
|
|
2587
2557
|
if (links && links.declaredType && mapper === undefined) {
|
|
@@ -2616,8 +2586,8 @@ export function createChecker(program) {
|
|
|
2616
2586
|
const parentTemplate = getParentTemplateNode(prop);
|
|
2617
2587
|
linkMapper(type, mapper);
|
|
2618
2588
|
if (!parentTemplate || shouldCreateTypeForTemplate(parentTemplate, mapper)) {
|
|
2619
|
-
if (
|
|
2620
|
-
|
|
2589
|
+
if (prop.parent?.parent?.kind === SyntaxKind.OperationSignatureDeclaration &&
|
|
2590
|
+
prop.parent.parent.parent?.kind === SyntaxKind.OperationStatement) {
|
|
2621
2591
|
const doc = extractParamDoc(prop.parent.parent.parent, type.name);
|
|
2622
2592
|
if (doc) {
|
|
2623
2593
|
type.decorators.unshift(createDocFromCommentDecorator("self", doc));
|
|
@@ -2674,7 +2644,6 @@ export function createChecker(program) {
|
|
|
2674
2644
|
}
|
|
2675
2645
|
}
|
|
2676
2646
|
function checkDecorator(targetType, decNode, mapper) {
|
|
2677
|
-
var _a;
|
|
2678
2647
|
const sym = resolveTypeReferenceSym(decNode.target, undefined, true);
|
|
2679
2648
|
if (!sym) {
|
|
2680
2649
|
reportCheckerDiagnostic(createDiagnostic({
|
|
@@ -2710,13 +2679,12 @@ export function createChecker(program) {
|
|
|
2710
2679
|
}
|
|
2711
2680
|
return {
|
|
2712
2681
|
definition: symbolLinks.declaredType,
|
|
2713
|
-
decorator:
|
|
2682
|
+
decorator: sym.value ?? ((...args) => { }),
|
|
2714
2683
|
node: decNode,
|
|
2715
2684
|
args,
|
|
2716
2685
|
};
|
|
2717
2686
|
}
|
|
2718
2687
|
function checkDecoratorUsage(targetType, declaration, args, decoratorNode) {
|
|
2719
|
-
var _a;
|
|
2720
2688
|
let hasError = false;
|
|
2721
2689
|
const [targetValid] = isTypeAssignableTo(targetType, declaration.target.type, decoratorNode);
|
|
2722
2690
|
if (!targetValid) {
|
|
@@ -2733,7 +2701,7 @@ export function createChecker(program) {
|
|
|
2733
2701
|
}));
|
|
2734
2702
|
}
|
|
2735
2703
|
const minArgs = declaration.parameters.filter((x) => !x.optional && !x.rest).length;
|
|
2736
|
-
const maxArgs =
|
|
2704
|
+
const maxArgs = declaration.parameters[declaration.parameters.length - 1]?.rest
|
|
2737
2705
|
? undefined
|
|
2738
2706
|
: declaration.parameters.length;
|
|
2739
2707
|
if (args.length < minArgs || (maxArgs !== undefined && args.length > maxArgs)) {
|
|
@@ -2793,8 +2761,7 @@ export function createChecker(program) {
|
|
|
2793
2761
|
return [hasError, resolvedArgs];
|
|
2794
2762
|
}
|
|
2795
2763
|
function getIndexType(type) {
|
|
2796
|
-
|
|
2797
|
-
return type.kind === "Model" ? (_a = type.indexer) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
2764
|
+
return type.kind === "Model" ? type.indexer?.value : undefined;
|
|
2798
2765
|
}
|
|
2799
2766
|
function resolveDecoratorArgJsValue(value, valueOf) {
|
|
2800
2767
|
if (valueOf) {
|
|
@@ -2822,8 +2789,7 @@ export function createChecker(program) {
|
|
|
2822
2789
|
return valid;
|
|
2823
2790
|
}
|
|
2824
2791
|
function checkAugmentDecorators(sym, targetType, mapper) {
|
|
2825
|
-
|
|
2826
|
-
const augmentDecoratorNodes = (_a = augmentDecoratorsForSym.get(sym)) !== null && _a !== void 0 ? _a : [];
|
|
2792
|
+
const augmentDecoratorNodes = augmentDecoratorsForSym.get(sym) ?? [];
|
|
2827
2793
|
const decorators = [];
|
|
2828
2794
|
for (const decNode of augmentDecoratorNodes) {
|
|
2829
2795
|
const decorator = checkDecorator(targetType, decNode, mapper);
|
|
@@ -2834,10 +2800,9 @@ export function createChecker(program) {
|
|
|
2834
2800
|
return decorators;
|
|
2835
2801
|
}
|
|
2836
2802
|
function checkDecorators(targetType, node, mapper) {
|
|
2837
|
-
|
|
2838
|
-
const sym = isMemberNode(node) ? (_a = getSymbolForMember(node)) !== null && _a !== void 0 ? _a : node.symbol : node.symbol;
|
|
2803
|
+
const sym = isMemberNode(node) ? getSymbolForMember(node) ?? node.symbol : node.symbol;
|
|
2839
2804
|
const decorators = [];
|
|
2840
|
-
const augmentDecoratorNodes =
|
|
2805
|
+
const augmentDecoratorNodes = augmentDecoratorsForSym.get(sym) ?? [];
|
|
2841
2806
|
const decoratorNodes = [
|
|
2842
2807
|
...augmentDecoratorNodes, // the first decorator will be executed at last, so augmented decorator should be placed at first.
|
|
2843
2808
|
...node.decorators,
|
|
@@ -2875,7 +2840,6 @@ export function createChecker(program) {
|
|
|
2875
2840
|
});
|
|
2876
2841
|
}
|
|
2877
2842
|
function checkScalar(node, mapper) {
|
|
2878
|
-
var _a;
|
|
2879
2843
|
const links = getSymbolLinks(node.symbol);
|
|
2880
2844
|
if (links.declaredType && mapper === undefined) {
|
|
2881
2845
|
// we're not instantiating this model and we've already checked it
|
|
@@ -2901,7 +2865,7 @@ export function createChecker(program) {
|
|
|
2901
2865
|
}
|
|
2902
2866
|
decorators.push(...checkDecorators(type, node, mapper));
|
|
2903
2867
|
if (mapper === undefined) {
|
|
2904
|
-
|
|
2868
|
+
type.namespace?.scalars.set(type.name, type);
|
|
2905
2869
|
}
|
|
2906
2870
|
linkMapper(type, mapper);
|
|
2907
2871
|
if (shouldCreateTypeForTemplate(node, mapper)) {
|
|
@@ -2966,7 +2930,6 @@ export function createChecker(program) {
|
|
|
2966
2930
|
return type;
|
|
2967
2931
|
}
|
|
2968
2932
|
function checkEnum(node, mapper) {
|
|
2969
|
-
var _a;
|
|
2970
2933
|
const links = getSymbolLinks(node.symbol);
|
|
2971
2934
|
if (!links.type) {
|
|
2972
2935
|
const enumType = (links.type = createType({
|
|
@@ -3001,7 +2964,7 @@ export function createChecker(program) {
|
|
|
3001
2964
|
}
|
|
3002
2965
|
const namespace = getParentNamespaceType(node);
|
|
3003
2966
|
enumType.namespace = namespace;
|
|
3004
|
-
|
|
2967
|
+
enumType.namespace?.enums.set(enumType.name, enumType);
|
|
3005
2968
|
enumType.decorators = checkDecorators(enumType, node, mapper);
|
|
3006
2969
|
linkMapper(enumType, mapper);
|
|
3007
2970
|
finishType(enumType);
|
|
@@ -3009,7 +2972,6 @@ export function createChecker(program) {
|
|
|
3009
2972
|
return links.type;
|
|
3010
2973
|
}
|
|
3011
2974
|
function checkInterface(node, mapper) {
|
|
3012
|
-
var _a;
|
|
3013
2975
|
const links = getSymbolLinks(node.symbol);
|
|
3014
2976
|
if (links.declaredType && mapper === undefined) {
|
|
3015
2977
|
// we're not instantiating this interface and we've already checked it
|
|
@@ -3063,7 +3025,7 @@ export function createChecker(program) {
|
|
|
3063
3025
|
finishType(interfaceType);
|
|
3064
3026
|
}
|
|
3065
3027
|
if (mapper === undefined) {
|
|
3066
|
-
|
|
3028
|
+
interfaceType.namespace?.interfaces.set(interfaceType.name, interfaceType);
|
|
3067
3029
|
}
|
|
3068
3030
|
return interfaceType;
|
|
3069
3031
|
}
|
|
@@ -3086,7 +3048,6 @@ export function createChecker(program) {
|
|
|
3086
3048
|
return ownMembers;
|
|
3087
3049
|
}
|
|
3088
3050
|
function checkUnion(node, mapper) {
|
|
3089
|
-
var _a;
|
|
3090
3051
|
const links = getSymbolLinks(node.symbol);
|
|
3091
3052
|
if (links.declaredType && mapper === undefined) {
|
|
3092
3053
|
// we're not instantiating this union and we've already checked it
|
|
@@ -3114,7 +3075,7 @@ export function createChecker(program) {
|
|
|
3114
3075
|
finishType(unionType);
|
|
3115
3076
|
}
|
|
3116
3077
|
if (mapper === undefined) {
|
|
3117
|
-
|
|
3078
|
+
unionType.namespace?.unions.set(unionType.name, unionType);
|
|
3118
3079
|
}
|
|
3119
3080
|
return unionType;
|
|
3120
3081
|
}
|
|
@@ -3169,12 +3130,11 @@ export function createChecker(program) {
|
|
|
3169
3130
|
return parentSym ? getOrCreateAugmentedSymbolTable(parentSym.members).get(name) : undefined;
|
|
3170
3131
|
}
|
|
3171
3132
|
function getSymbolForMember(node) {
|
|
3172
|
-
var _a;
|
|
3173
3133
|
if (!node.id) {
|
|
3174
3134
|
return undefined;
|
|
3175
3135
|
}
|
|
3176
3136
|
const name = node.id.sv;
|
|
3177
|
-
const parentSym =
|
|
3137
|
+
const parentSym = node.parent?.symbol;
|
|
3178
3138
|
return parentSym ? getOrCreateAugmentedSymbolTable(parentSym.members).get(name) : undefined;
|
|
3179
3139
|
}
|
|
3180
3140
|
function getSymbolLinksForMember(node) {
|
|
@@ -3184,7 +3144,7 @@ export function createChecker(program) {
|
|
|
3184
3144
|
function checkEnumMember(node, mapper, parentEnum) {
|
|
3185
3145
|
const name = node.id.sv;
|
|
3186
3146
|
const links = getSymbolLinksForMember(node);
|
|
3187
|
-
if (links
|
|
3147
|
+
if (links?.type) {
|
|
3188
3148
|
return links.type;
|
|
3189
3149
|
}
|
|
3190
3150
|
compilerAssert(parentEnum, "Enum member should already have been checked.");
|
|
@@ -3235,9 +3195,8 @@ export function createChecker(program) {
|
|
|
3235
3195
|
return members;
|
|
3236
3196
|
}
|
|
3237
3197
|
function checkDirectives(node, type) {
|
|
3238
|
-
var _a;
|
|
3239
3198
|
let hasDeprecation = false;
|
|
3240
|
-
for (const directive of
|
|
3199
|
+
for (const directive of node.directives ?? []) {
|
|
3241
3200
|
if (directive.target.sv === "deprecated") {
|
|
3242
3201
|
const message = directive.arguments[0];
|
|
3243
3202
|
if (message === undefined) {
|
|
@@ -4174,7 +4133,6 @@ export function createChecker(program) {
|
|
|
4174
4133
|
return [result, diagnostics];
|
|
4175
4134
|
}
|
|
4176
4135
|
function isTypeAssignableToWorker(source, target, diagnosticTarget, relationCache) {
|
|
4177
|
-
var _a;
|
|
4178
4136
|
// BACKCOMPAT: Added May 2023 sprint, to be removed by June 2023 sprint
|
|
4179
4137
|
if (source.kind === "TemplateParameter" && source.constraint && target.kind === "Value") {
|
|
4180
4138
|
const [assignable] = isTypeAssignableToInternal(source.constraint, target.target, diagnosticTarget, relationCache);
|
|
@@ -4185,7 +4143,7 @@ export function createChecker(program) {
|
|
|
4185
4143
|
}
|
|
4186
4144
|
}
|
|
4187
4145
|
while (source.kind === "TemplateParameter" && source.constraint !== source) {
|
|
4188
|
-
source =
|
|
4146
|
+
source = source.constraint ?? unknownType;
|
|
4189
4147
|
}
|
|
4190
4148
|
if (source === target)
|
|
4191
4149
|
return [Related.true, []];
|
|
@@ -4271,10 +4229,9 @@ export function createChecker(program) {
|
|
|
4271
4229
|
return [Related.true, []];
|
|
4272
4230
|
}
|
|
4273
4231
|
function isReflectionType(type) {
|
|
4274
|
-
var _a, _b, _c;
|
|
4275
4232
|
return (type.kind === "Model" &&
|
|
4276
|
-
|
|
4277
|
-
|
|
4233
|
+
type.namespace?.name === "Reflection" &&
|
|
4234
|
+
type.namespace?.namespace?.name === "TypeSpec");
|
|
4278
4235
|
}
|
|
4279
4236
|
function isRelatedToScalar(source, target) {
|
|
4280
4237
|
switch (source.kind) {
|
|
@@ -4382,8 +4339,8 @@ export function createChecker(program) {
|
|
|
4382
4339
|
return [diagnostics.length === 0 ? Related.true : Related.false, diagnostics];
|
|
4383
4340
|
}
|
|
4384
4341
|
function getProperty(model, name) {
|
|
4385
|
-
|
|
4386
|
-
|
|
4342
|
+
return (model.properties.get(name) ??
|
|
4343
|
+
(model.baseModel !== undefined ? getProperty(model.baseModel, name) : undefined));
|
|
4387
4344
|
}
|
|
4388
4345
|
function isIndexerValid(source, target, diagnosticTarget, relationCache) {
|
|
4389
4346
|
// Model expressions should be able to be assigned.
|
|
@@ -4496,8 +4453,7 @@ export function createChecker(program) {
|
|
|
4496
4453
|
});
|
|
4497
4454
|
}
|
|
4498
4455
|
function isStdType(type, stdType) {
|
|
4499
|
-
|
|
4500
|
-
type = (_a = type.projectionBase) !== null && _a !== void 0 ? _a : type;
|
|
4456
|
+
type = type.projectionBase ?? type;
|
|
4501
4457
|
if ((type.kind !== "Model" && type.kind !== "Scalar") ||
|
|
4502
4458
|
type.namespace === undefined ||
|
|
4503
4459
|
!isTypeSpecNamespace(type.namespace))
|
|
@@ -4538,13 +4494,12 @@ const numericRanges = {
|
|
|
4538
4494
|
* chain.
|
|
4539
4495
|
*/
|
|
4540
4496
|
function getNamedSourceModels(property) {
|
|
4541
|
-
var _a;
|
|
4542
4497
|
if (!property.sourceProperty) {
|
|
4543
4498
|
return undefined;
|
|
4544
4499
|
}
|
|
4545
4500
|
const set = new Set();
|
|
4546
4501
|
for (let p = property; p; p = p.sourceProperty) {
|
|
4547
|
-
if (
|
|
4502
|
+
if (p.model?.name) {
|
|
4548
4503
|
set.add(p.model);
|
|
4549
4504
|
}
|
|
4550
4505
|
}
|
|
@@ -4567,17 +4522,15 @@ function addDerivedModels(models, possiblyDerivedModels) {
|
|
|
4567
4522
|
}
|
|
4568
4523
|
}
|
|
4569
4524
|
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 : []);
|
|
4525
|
+
const map = new Map(parentMapper?.map ?? []);
|
|
4572
4526
|
for (const [index, param] of parameters.entries()) {
|
|
4573
4527
|
map.set(param, args[index]);
|
|
4574
4528
|
}
|
|
4575
4529
|
return {
|
|
4576
4530
|
partial: false,
|
|
4577
|
-
args: [...(
|
|
4531
|
+
args: [...(parentMapper?.args ?? []), ...args],
|
|
4578
4532
|
getMappedType: (type) => {
|
|
4579
|
-
|
|
4580
|
-
return (_a = map.get(type)) !== null && _a !== void 0 ? _a : type;
|
|
4533
|
+
return map.get(type) ?? type;
|
|
4581
4534
|
},
|
|
4582
4535
|
map,
|
|
4583
4536
|
};
|
|
@@ -4651,7 +4604,7 @@ export function getEffectiveModelType(program, model, filter) {
|
|
|
4651
4604
|
// ignoring filtering as a better match than one that requires filtering
|
|
4652
4605
|
// to meet this test.
|
|
4653
4606
|
let match;
|
|
4654
|
-
for (const candidate of candidates
|
|
4607
|
+
for (const candidate of candidates ?? []) {
|
|
4655
4608
|
if (model.properties.size === countPropertiesInherited(candidate)) {
|
|
4656
4609
|
match = candidate;
|
|
4657
4610
|
break; // exact match
|
|
@@ -4661,7 +4614,7 @@ export function getEffectiveModelType(program, model, filter) {
|
|
|
4661
4614
|
continue; // match with filter: keep searching for exact match
|
|
4662
4615
|
}
|
|
4663
4616
|
}
|
|
4664
|
-
return match
|
|
4617
|
+
return match ?? model;
|
|
4665
4618
|
}
|
|
4666
4619
|
/**
|
|
4667
4620
|
* Applies a filter to the properties of a given type. If no properties
|
|
@@ -4758,8 +4711,7 @@ function linkMapper(typeDef, mapper) {
|
|
|
4758
4711
|
}
|
|
4759
4712
|
}
|
|
4760
4713
|
function extractMainDoc(type) {
|
|
4761
|
-
|
|
4762
|
-
if (((_a = type.node) === null || _a === void 0 ? void 0 : _a.docs) === undefined) {
|
|
4714
|
+
if (type.node?.docs === undefined) {
|
|
4763
4715
|
return undefined;
|
|
4764
4716
|
}
|
|
4765
4717
|
let mainDoc = "";
|
|
@@ -4770,12 +4722,11 @@ function extractMainDoc(type) {
|
|
|
4770
4722
|
return trimmed === "" ? undefined : trimmed;
|
|
4771
4723
|
}
|
|
4772
4724
|
function extractReturnsDocs(type) {
|
|
4773
|
-
var _a;
|
|
4774
4725
|
const result = {
|
|
4775
4726
|
returns: undefined,
|
|
4776
4727
|
errors: undefined,
|
|
4777
4728
|
};
|
|
4778
|
-
if (
|
|
4729
|
+
if (type.node?.docs === undefined) {
|
|
4779
4730
|
return result;
|
|
4780
4731
|
}
|
|
4781
4732
|
for (const doc of type.node.docs) {
|
|
@@ -4833,7 +4784,6 @@ function reportDeprecation(program, target, message, reportFunc) {
|
|
|
4833
4784
|
}
|
|
4834
4785
|
}
|
|
4835
4786
|
function applyDecoratorToType(program, decApp, target) {
|
|
4836
|
-
var _a, _b;
|
|
4837
4787
|
compilerAssert("decorators" in target, "Cannot apply decorator to non-decoratable type", target);
|
|
4838
4788
|
for (const arg of decApp.args) {
|
|
4839
4789
|
if (isErrorType(arg.value)) {
|
|
@@ -4845,7 +4795,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4845
4795
|
if (decApp.definition) {
|
|
4846
4796
|
const deprecation = getDeprecationDetails(program, decApp.definition);
|
|
4847
4797
|
if (deprecation !== undefined) {
|
|
4848
|
-
reportDeprecation(program,
|
|
4798
|
+
reportDeprecation(program, decApp.node ?? target, deprecation.message, program.reportDiagnostic);
|
|
4849
4799
|
}
|
|
4850
4800
|
}
|
|
4851
4801
|
// peel `fn` off to avoid setting `this`.
|
|
@@ -4861,7 +4811,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4861
4811
|
program.reportDiagnostic(createDiagnostic({
|
|
4862
4812
|
code: "decorator-fail",
|
|
4863
4813
|
format: { decoratorName: decApp.decorator.name, error: error.stack },
|
|
4864
|
-
target:
|
|
4814
|
+
target: decApp.node ?? target,
|
|
4865
4815
|
}));
|
|
4866
4816
|
}
|
|
4867
4817
|
else {
|
|
@@ -4884,8 +4834,7 @@ function createDecoratorContext(program, decApp) {
|
|
|
4884
4834
|
program,
|
|
4885
4835
|
decoratorTarget: decApp.node,
|
|
4886
4836
|
getArgumentTarget: (index) => {
|
|
4887
|
-
|
|
4888
|
-
return (_a = decApp.args[index]) === null || _a === void 0 ? void 0 : _a.node;
|
|
4837
|
+
return decApp.args[index]?.node;
|
|
4889
4838
|
},
|
|
4890
4839
|
call: (decorator, target, ...args) => {
|
|
4891
4840
|
return decorator(createPassThruContext(program, decApp), target, ...args);
|
|
@@ -4937,33 +4886,29 @@ var ResolutionKind;
|
|
|
4937
4886
|
ResolutionKind[ResolutionKind["Constraint"] = 2] = "Constraint";
|
|
4938
4887
|
})(ResolutionKind || (ResolutionKind = {}));
|
|
4939
4888
|
class PendingResolutions {
|
|
4940
|
-
|
|
4941
|
-
_PendingResolutions_data.set(this, new Map());
|
|
4942
|
-
}
|
|
4889
|
+
#data = new Map();
|
|
4943
4890
|
start(symId, kind) {
|
|
4944
|
-
let existing =
|
|
4891
|
+
let existing = this.#data.get(symId);
|
|
4945
4892
|
if (existing === undefined) {
|
|
4946
4893
|
existing = new Set();
|
|
4947
|
-
|
|
4894
|
+
this.#data.set(symId, existing);
|
|
4948
4895
|
}
|
|
4949
4896
|
existing.add(kind);
|
|
4950
4897
|
}
|
|
4951
4898
|
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;
|
|
4899
|
+
return this.#data.get(symId)?.has(kind) ?? false;
|
|
4954
4900
|
}
|
|
4955
4901
|
finish(symId, kind) {
|
|
4956
|
-
const existing =
|
|
4902
|
+
const existing = this.#data.get(symId);
|
|
4957
4903
|
if (existing === undefined) {
|
|
4958
4904
|
return;
|
|
4959
4905
|
}
|
|
4960
|
-
existing
|
|
4906
|
+
existing?.delete(kind);
|
|
4961
4907
|
if (existing.size === 0) {
|
|
4962
|
-
|
|
4908
|
+
this.#data.delete(symId);
|
|
4963
4909
|
}
|
|
4964
4910
|
}
|
|
4965
4911
|
}
|
|
4966
|
-
_PendingResolutions_data = new WeakMap();
|
|
4967
4912
|
var Related;
|
|
4968
4913
|
(function (Related) {
|
|
4969
4914
|
Related[Related["false"] = 0] = "false";
|