@typespec/compiler 0.45.0-dev.2 → 0.45.0-dev.23
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/core/checker.d.ts +2 -2
- package/dist/core/checker.d.ts.map +1 -1
- package/dist/core/checker.js +177 -36
- package/dist/core/checker.js.map +1 -1
- package/dist/core/cli/args.d.ts +1 -1
- package/dist/core/cli/args.d.ts.map +1 -1
- package/dist/core/cli/args.js +10 -8
- package/dist/core/cli/args.js.map +1 -1
- package/dist/core/cli/cli.js +13 -6
- package/dist/core/cli/cli.js.map +1 -1
- package/dist/core/decorator-utils.js +1 -1
- package/dist/core/decorator-utils.js.map +1 -1
- package/dist/core/entrypoint-resolution.d.ts +10 -0
- package/dist/core/entrypoint-resolution.d.ts.map +1 -0
- package/dist/core/entrypoint-resolution.js +39 -0
- package/dist/core/entrypoint-resolution.js.map +1 -0
- package/dist/core/fetch.d.ts +11 -0
- package/dist/core/fetch.d.ts.map +1 -0
- package/dist/core/fetch.js +38 -0
- package/dist/core/fetch.js.map +1 -0
- package/dist/core/helpers/type-name-utils.d.ts +2 -2
- package/dist/core/helpers/type-name-utils.d.ts.map +1 -1
- package/dist/core/helpers/type-name-utils.js +2 -0
- package/dist/core/helpers/type-name-utils.js.map +1 -1
- package/dist/core/messages.d.ts +7 -25
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +2 -8
- package/dist/core/messages.js.map +1 -1
- package/dist/core/module-resolver.d.ts +1 -0
- package/dist/core/module-resolver.d.ts.map +1 -1
- package/dist/core/module-resolver.js.map +1 -1
- package/dist/core/node-host.js +2 -2
- package/dist/core/node-host.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +18 -3
- package/dist/core/parser.js.map +1 -1
- package/dist/core/program.d.ts.map +1 -1
- package/dist/core/program.js +4 -54
- package/dist/core/program.js.map +1 -1
- package/dist/core/projector.d.ts.map +1 -1
- package/dist/core/projector.js +2 -7
- package/dist/core/projector.js.map +1 -1
- package/dist/core/scanner.d.ts +9 -8
- package/dist/core/scanner.d.ts.map +1 -1
- package/dist/core/scanner.js +16 -13
- package/dist/core/scanner.js.map +1 -1
- package/dist/core/type-utils.d.ts +4 -1
- package/dist/core/type-utils.d.ts.map +1 -1
- package/dist/core/type-utils.js +17 -0
- package/dist/core/type-utils.js.map +1 -1
- package/dist/core/types.d.ts +64 -48
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +44 -43
- package/dist/core/types.js.map +1 -1
- package/dist/formatter/parser.js +1 -1
- package/dist/formatter/parser.js.map +1 -1
- package/dist/formatter/print/comment-handler.js +1 -0
- package/dist/formatter/print/comment-handler.js.map +1 -1
- package/dist/formatter/print/printer.d.ts +2 -1
- package/dist/formatter/print/printer.d.ts.map +1 -1
- package/dist/formatter/print/printer.js +6 -0
- package/dist/formatter/print/printer.js.map +1 -1
- package/dist/init/init.d.ts.map +1 -1
- package/dist/init/init.js +9 -7
- package/dist/init/init.js.map +1 -1
- package/dist/lib/decorators.d.ts +27 -1
- package/dist/lib/decorators.d.ts.map +1 -1
- package/dist/lib/decorators.js +42 -13
- package/dist/lib/decorators.js.map +1 -1
- package/dist/manifest.js +1 -1
- package/dist/server/completion.js +2 -2
- package/dist/server/completion.js.map +1 -1
- package/dist/server/serverlib.d.ts.map +1 -1
- package/dist/server/serverlib.js +141 -71
- package/dist/server/serverlib.js.map +1 -1
- package/dist/server/tmlanguage.d.ts.map +1 -1
- package/dist/server/tmlanguage.js +11 -0
- package/dist/server/tmlanguage.js.map +1 -1
- package/dist/server/type-details.d.ts +1 -10
- package/dist/server/type-details.d.ts.map +1 -1
- package/dist/server/type-details.js +43 -27
- package/dist/server/type-details.js.map +1 -1
- package/dist/server/type-signature.js +21 -3
- package/dist/server/type-signature.js.map +1 -1
- package/dist/testing/test-host.d.ts.map +1 -1
- package/dist/testing/test-host.js +2 -1
- package/dist/testing/test-host.js.map +1 -1
- package/dist/typespec.tmLanguage +28 -0
- package/lib/decorators.tsp +33 -24
- package/lib/lib.tsp +16 -4
- package/package.json +1 -2
package/dist/core/checker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypeNameOptions } from "./helpers/index.js";
|
|
2
2
|
import { Program, ProjectedProgram } from "./program.js";
|
|
3
|
-
import { BooleanLiteral, BooleanLiteralNode, Diagnostic, DiagnosticTarget, ErrorType, FunctionType, IdentifierNode, IntrinsicScalarName, JsSourceFileNode, LiteralNode, LiteralType, Model, ModelProperty, Namespace, NamespaceStatementNode, NeverType, Node, NumericLiteral, NumericLiteralNode, ProjectionNode, ProjectionStatementNode, Scalar, StdTypeName, StdTypes, StringLiteral, StringLiteralNode, Sym, Type, TypeReferenceNode, TypeSpecScriptNode, UnknownType, VoidType } from "./types.js";
|
|
3
|
+
import { BooleanLiteral, BooleanLiteralNode, Diagnostic, DiagnosticTarget, ErrorType, FunctionType, IdentifierNode, IntrinsicScalarName, JsSourceFileNode, LiteralNode, LiteralType, Model, ModelProperty, Namespace, NamespaceStatementNode, NeverType, Node, NumericLiteral, NumericLiteralNode, ProjectionNode, ProjectionStatementNode, Scalar, StdTypeName, StdTypes, StringLiteral, StringLiteralNode, Sym, Type, TypeReferenceNode, TypeSpecScriptNode, UnknownType, ValueType, VoidType } from "./types.js";
|
|
4
4
|
export type CreateTypeProps = Omit<Type, "isFinished" | keyof TypePrototype>;
|
|
5
5
|
export interface Checker {
|
|
6
6
|
typePrototype: TypePrototype;
|
|
@@ -49,7 +49,7 @@ export interface Checker {
|
|
|
49
49
|
* @param diagnosticTarget Target for the diagnostic, unless something better can be inferred.
|
|
50
50
|
* @returns [related, list of diagnostics]
|
|
51
51
|
*/
|
|
52
|
-
isTypeAssignableTo(source: Type, target: Type, diagnosticTarget: DiagnosticTarget): [boolean, Diagnostic[]];
|
|
52
|
+
isTypeAssignableTo(source: Type | ValueType, target: Type | ValueType, diagnosticTarget: DiagnosticTarget): [boolean, readonly Diagnostic[]];
|
|
53
53
|
/**
|
|
54
54
|
* Check if the given type is one of the built-in standard TypeSpec Types.
|
|
55
55
|
* @param type Type to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../core/checker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAqC,MAAM,oBAAoB,CAAC;AAGxF,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../core/checker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAqC,MAAM,oBAAoB,CAAC;AAGxF,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUzD,OAAO,EAIL,cAAc,EACd,kBAAkB,EAQlB,UAAU,EACV,gBAAgB,EAMhB,SAAS,EAKT,YAAY,EAEZ,cAAc,EAId,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,WAAW,EAOX,KAAK,EAGL,aAAa,EAKb,SAAS,EACT,sBAAsB,EACtB,SAAS,EACT,IAAI,EAEJ,cAAc,EACd,kBAAkB,EAiBlB,cAAc,EAGd,uBAAuB,EAIvB,MAAM,EAEN,WAAW,EACX,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,GAAG,EAYH,IAAI,EAIJ,iBAAiB,EACjB,kBAAkB,EAMlB,WAAW,EAEX,SAAS,EACT,QAAQ,EACT,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,aAAa,CAAC,CAAC;AAE7E,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,aAAa,CAAC;IAE7B,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACjC,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACjD,YAAY,IAAI,IAAI,CAAC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KAAK,EAAE,KAAK,EACZ,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,GAC5C,KAAK,CAyEP;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,GAAG,gBAAgB,EACnC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,GAC3C,KAAK,CAmCP;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAcxF;AAED;;;;;;;GAOG;AACH,wBAAiB,uBAAuB,CAAC,KAAK,EAAE,KAAK,2CAapD;AAYD,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAEpF"}
|
package/dist/core/checker.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { getDeprecated, getIndexer } from "../lib/decorators.js";
|
|
1
|
+
import { $docFromComment, getDeprecated, getIndexer } from "../lib/decorators.js";
|
|
2
2
|
import { createSymbol, createSymbolTable } from "./binder.js";
|
|
3
|
-
import { ProjectionError, compilerAssert } from "./diagnostics.js";
|
|
3
|
+
import { ProjectionError, compilerAssert, reportDeprecated } from "./diagnostics.js";
|
|
4
4
|
import { validateInheritanceDiscriminatedUnions } from "./helpers/discriminator-utils.js";
|
|
5
5
|
import { getNamespaceFullName, getTypeName } from "./helpers/index.js";
|
|
6
6
|
import { createDiagnostic } from "./messages.js";
|
|
7
7
|
import { getIdentifierContext, hasParseError, visitChildren } from "./parser.js";
|
|
8
8
|
import { createProjectionMembers } from "./projection-members.js";
|
|
9
|
-
import { getParentTemplateNode, isNeverType, isTemplateInstance, isUnknownType, isVoidType, } from "./type-utils.js";
|
|
9
|
+
import { getFullyQualifiedSymbolName, getParentTemplateNode, isNeverType, isTemplateInstance, isUnknownType, isVoidType, } from "./type-utils.js";
|
|
10
10
|
import { IdentifierKind, SyntaxKind, } from "./types.js";
|
|
11
11
|
import { MultiKeyMap, createRekeyableMap, isArray, mutate } from "./util.js";
|
|
12
12
|
/**
|
|
@@ -380,23 +380,6 @@ export function createChecker(program) {
|
|
|
380
380
|
// bubbles out somewhere its not supposed to be.
|
|
381
381
|
return errorType;
|
|
382
382
|
}
|
|
383
|
-
function getFullyQualifiedSymbolName(sym, options) {
|
|
384
|
-
if (!sym)
|
|
385
|
-
return "";
|
|
386
|
-
if (sym.symbolSource)
|
|
387
|
-
sym = sym.symbolSource;
|
|
388
|
-
const parent = sym.parent && !(sym.parent.flags & 2097152 /* SymbolFlags.SourceFile */) ? sym.parent : undefined;
|
|
389
|
-
const name = sym.flags & 16384 /* SymbolFlags.Decorator */ ? sym.name.slice(1) : sym.name;
|
|
390
|
-
if (parent === null || parent === void 0 ? void 0 : parent.name) {
|
|
391
|
-
return `${getFullyQualifiedSymbolName(parent)}.${name}`;
|
|
392
|
-
}
|
|
393
|
-
else if (options === null || options === void 0 ? void 0 : options.useGlobalPrefixAtTopLevel) {
|
|
394
|
-
return `global.${name}`;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
return name;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
383
|
/**
|
|
401
384
|
* Return a fully qualified id of node
|
|
402
385
|
*/
|
|
@@ -442,7 +425,7 @@ export function createChecker(program) {
|
|
|
442
425
|
node: node,
|
|
443
426
|
});
|
|
444
427
|
if (node.constraint) {
|
|
445
|
-
type.constraint =
|
|
428
|
+
type.constraint = getTypeOrValueTypeForNode(node.constraint);
|
|
446
429
|
}
|
|
447
430
|
if (node.default) {
|
|
448
431
|
type.default = checkTemplateParameterDefault(node.default, parentNode.templateParameters, index, type.constraint);
|
|
@@ -535,7 +518,7 @@ export function createChecker(program) {
|
|
|
535
518
|
return args;
|
|
536
519
|
}
|
|
537
520
|
function checkTemplateInstantiationArgs(node, args, declarations) {
|
|
538
|
-
var _a;
|
|
521
|
+
var _a, _b, _c;
|
|
539
522
|
if (args.length > declarations.length) {
|
|
540
523
|
reportCheckerDiagnostic(createDiagnostic({
|
|
541
524
|
code: "invalid-template-args",
|
|
@@ -555,7 +538,9 @@ export function createChecker(program) {
|
|
|
555
538
|
let [valueNode, value] = args[i];
|
|
556
539
|
if (declaredType.constraint) {
|
|
557
540
|
if (!checkTypeAssignable(value, declaredType.constraint, valueNode)) {
|
|
558
|
-
|
|
541
|
+
// TODO-TIM check if we expose this below
|
|
542
|
+
value =
|
|
543
|
+
((_a = declaredType.constraint) === null || _a === void 0 ? void 0 : _a.kind) === "Value" ? unknownType : declaredType.constraint;
|
|
559
544
|
}
|
|
560
545
|
}
|
|
561
546
|
values.push(value);
|
|
@@ -568,7 +553,11 @@ export function createChecker(program) {
|
|
|
568
553
|
}
|
|
569
554
|
else {
|
|
570
555
|
tooFew = true;
|
|
571
|
-
values.push(
|
|
556
|
+
values.push(
|
|
557
|
+
// TODO-TIM check if we expose this below
|
|
558
|
+
((_b = declaredType.constraint) === null || _b === void 0 ? void 0 : _b.kind) === "Value"
|
|
559
|
+
? unknownType
|
|
560
|
+
: (_c = declaredType.constraint) !== null && _c !== void 0 ? _c : unknownType);
|
|
572
561
|
}
|
|
573
562
|
}
|
|
574
563
|
}
|
|
@@ -800,6 +789,13 @@ export function createChecker(program) {
|
|
|
800
789
|
}
|
|
801
790
|
return unionType;
|
|
802
791
|
}
|
|
792
|
+
function checkValueOfExpression(node, mapper) {
|
|
793
|
+
const target = getTypeForNode(node.target, mapper);
|
|
794
|
+
return {
|
|
795
|
+
kind: "Value",
|
|
796
|
+
target,
|
|
797
|
+
};
|
|
798
|
+
}
|
|
803
799
|
/**
|
|
804
800
|
* Intersection produces a model type from the properties of its operands.
|
|
805
801
|
* So this doesn't work if we don't have a known set of properties (e.g.
|
|
@@ -874,10 +870,14 @@ export function createChecker(program) {
|
|
|
874
870
|
if (links.declaredType) {
|
|
875
871
|
return links.declaredType;
|
|
876
872
|
}
|
|
877
|
-
if (node.rest &&
|
|
873
|
+
if (node.rest &&
|
|
874
|
+
node.type &&
|
|
875
|
+
!(node.type.kind === SyntaxKind.ArrayExpression ||
|
|
876
|
+
(node.type.kind === SyntaxKind.ValueOfExpression &&
|
|
877
|
+
node.type.target.kind === SyntaxKind.ArrayExpression))) {
|
|
878
878
|
reportCheckerDiagnostic(createDiagnostic({ code: "rest-parameter-array", target: node.type }));
|
|
879
879
|
}
|
|
880
|
-
const type = node.type ?
|
|
880
|
+
const type = node.type ? getTypeOrValueTypeForNode(node.type) : unknownType;
|
|
881
881
|
const parameterType = createType({
|
|
882
882
|
kind: "FunctionParameter",
|
|
883
883
|
node,
|
|
@@ -890,6 +890,12 @@ export function createChecker(program) {
|
|
|
890
890
|
linkType(links, parameterType, mapper);
|
|
891
891
|
return parameterType;
|
|
892
892
|
}
|
|
893
|
+
function getTypeOrValueTypeForNode(node, mapper) {
|
|
894
|
+
if (node.kind === SyntaxKind.ValueOfExpression) {
|
|
895
|
+
return checkValueOfExpression(node, mapper);
|
|
896
|
+
}
|
|
897
|
+
return getTypeForNode(node, mapper);
|
|
898
|
+
}
|
|
893
899
|
function mergeModelTypes(node, options, mapper) {
|
|
894
900
|
const properties = createRekeyableMap();
|
|
895
901
|
const intersection = createType({
|
|
@@ -1107,6 +1113,9 @@ export function createChecker(program) {
|
|
|
1107
1113
|
sourceOperation,
|
|
1108
1114
|
interface: parentInterface,
|
|
1109
1115
|
});
|
|
1116
|
+
if (links) {
|
|
1117
|
+
linkType(links, operationType, mapper);
|
|
1118
|
+
}
|
|
1110
1119
|
decorators.push(...checkDecorators(operationType, node, mapper));
|
|
1111
1120
|
operationType.parameters.namespace = namespace;
|
|
1112
1121
|
const parent = node.parent;
|
|
@@ -1125,9 +1134,6 @@ export function createChecker(program) {
|
|
|
1125
1134
|
namespace === null || namespace === void 0 ? void 0 : namespace.operations.set(name, operationType);
|
|
1126
1135
|
}
|
|
1127
1136
|
}
|
|
1128
|
-
if (links) {
|
|
1129
|
-
linkType(links, operationType, mapper);
|
|
1130
|
-
}
|
|
1131
1137
|
return operationType;
|
|
1132
1138
|
}
|
|
1133
1139
|
function checkOperationIs(operation, opReference, mapper) {
|
|
@@ -2179,6 +2185,7 @@ export function createChecker(program) {
|
|
|
2179
2185
|
}
|
|
2180
2186
|
}
|
|
2181
2187
|
function checkModelProperty(prop, mapper) {
|
|
2188
|
+
var _a, _b, _c;
|
|
2182
2189
|
const links = getSymbolLinksForMember(prop);
|
|
2183
2190
|
if (links && links.declaredType && mapper === undefined) {
|
|
2184
2191
|
return links.declaredType;
|
|
@@ -2202,6 +2209,16 @@ export function createChecker(program) {
|
|
|
2202
2209
|
const parentTemplate = getParentTemplateNode(prop);
|
|
2203
2210
|
linkMapper(type, mapper);
|
|
2204
2211
|
if (!parentTemplate || shouldCreateTypeForTemplate(parentTemplate, mapper)) {
|
|
2212
|
+
if (((_b = (_a = prop.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.kind) === SyntaxKind.OperationSignatureDeclaration &&
|
|
2213
|
+
((_c = prop.parent.parent.parent) === null || _c === void 0 ? void 0 : _c.kind) === SyntaxKind.OperationStatement) {
|
|
2214
|
+
const doc = extractParamDoc(prop.parent.parent.parent, type.name);
|
|
2215
|
+
if (doc) {
|
|
2216
|
+
type.decorators.unshift({
|
|
2217
|
+
decorator: $docFromComment,
|
|
2218
|
+
args: [{ value: createLiteralType(doc), jsValue: doc }],
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2205
2222
|
finishType(type);
|
|
2206
2223
|
}
|
|
2207
2224
|
return type;
|
|
@@ -2251,7 +2268,7 @@ export function createChecker(program) {
|
|
|
2251
2268
|
return undefined;
|
|
2252
2269
|
}
|
|
2253
2270
|
const symbolLinks = getSymbolLinks(sym);
|
|
2254
|
-
|
|
2271
|
+
let args = checkDecoratorArguments(decNode, mapper);
|
|
2255
2272
|
let hasError = false;
|
|
2256
2273
|
if (symbolLinks.declaredType === undefined) {
|
|
2257
2274
|
const decoratorDeclNode = sym.declarations.find((x) => x.kind === SyntaxKind.DecoratorDeclarationStatement);
|
|
@@ -2262,19 +2279,20 @@ export function createChecker(program) {
|
|
|
2262
2279
|
if (symbolLinks.declaredType) {
|
|
2263
2280
|
compilerAssert(symbolLinks.declaredType.kind === "Decorator", "Expected to find a decorator type.");
|
|
2264
2281
|
// Means we have a decorator declaration.
|
|
2265
|
-
hasError = checkDecoratorUsage(targetType, symbolLinks.declaredType, args, decNode);
|
|
2282
|
+
[hasError, args] = checkDecoratorUsage(targetType, symbolLinks.declaredType, args, decNode);
|
|
2266
2283
|
}
|
|
2267
2284
|
if (hasError) {
|
|
2268
2285
|
return undefined;
|
|
2269
2286
|
}
|
|
2270
2287
|
return {
|
|
2288
|
+
definition: symbolLinks.declaredType,
|
|
2271
2289
|
decorator: (_a = sym.value) !== null && _a !== void 0 ? _a : ((...args) => { }),
|
|
2272
2290
|
node: decNode,
|
|
2273
2291
|
args,
|
|
2274
2292
|
};
|
|
2275
2293
|
}
|
|
2276
2294
|
function checkDecoratorUsage(targetType, declaration, args, decoratorNode) {
|
|
2277
|
-
var _a
|
|
2295
|
+
var _a;
|
|
2278
2296
|
let hasError = false;
|
|
2279
2297
|
const [targetValid] = isTypeAssignableTo(targetType, declaration.target.type, decoratorNode);
|
|
2280
2298
|
if (!targetValid) {
|
|
@@ -2312,13 +2330,18 @@ export function createChecker(program) {
|
|
|
2312
2330
|
}));
|
|
2313
2331
|
}
|
|
2314
2332
|
}
|
|
2333
|
+
const resolvedArgs = [];
|
|
2315
2334
|
for (const [index, parameter] of declaration.parameters.entries()) {
|
|
2316
2335
|
if (parameter.rest) {
|
|
2317
|
-
const restType = parameter.type.kind === "
|
|
2336
|
+
const restType = getIndexType(parameter.type.kind === "Value" ? parameter.type.target : parameter.type);
|
|
2318
2337
|
if (restType) {
|
|
2319
2338
|
for (let i = index; i < args.length; i++) {
|
|
2320
2339
|
const arg = args[i];
|
|
2321
2340
|
if (arg && arg.value) {
|
|
2341
|
+
resolvedArgs.push({
|
|
2342
|
+
...arg,
|
|
2343
|
+
jsValue: resolveDecoratorArgJsValue(arg.value, parameter.type.kind === "Value"),
|
|
2344
|
+
});
|
|
2322
2345
|
if (!checkArgumentAssignable(arg.value, restType, arg.node)) {
|
|
2323
2346
|
hasError = true;
|
|
2324
2347
|
}
|
|
@@ -2329,12 +2352,28 @@ export function createChecker(program) {
|
|
|
2329
2352
|
}
|
|
2330
2353
|
const arg = args[index];
|
|
2331
2354
|
if (arg && arg.value) {
|
|
2355
|
+
resolvedArgs.push({
|
|
2356
|
+
...arg,
|
|
2357
|
+
jsValue: resolveDecoratorArgJsValue(arg.value, parameter.type.kind === "Value"),
|
|
2358
|
+
});
|
|
2332
2359
|
if (!checkArgumentAssignable(arg.value, parameter.type, arg.node)) {
|
|
2333
2360
|
hasError = true;
|
|
2334
2361
|
}
|
|
2335
2362
|
}
|
|
2336
2363
|
}
|
|
2337
|
-
return hasError;
|
|
2364
|
+
return [hasError, resolvedArgs];
|
|
2365
|
+
}
|
|
2366
|
+
function getIndexType(type) {
|
|
2367
|
+
var _a;
|
|
2368
|
+
return type.kind === "Model" ? (_a = type.indexer) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
2369
|
+
}
|
|
2370
|
+
function resolveDecoratorArgJsValue(value, valueOf) {
|
|
2371
|
+
if (valueOf) {
|
|
2372
|
+
if (value.kind === "Boolean" || value.kind === "String" || value.kind === "Number") {
|
|
2373
|
+
return literalTypeToValue(value);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
return value;
|
|
2338
2377
|
}
|
|
2339
2378
|
function checkArgumentAssignable(argumentType, parameterType, diagnosticTarget) {
|
|
2340
2379
|
const [valid] = isTypeAssignableTo(argumentType, parameterType, diagnosticTarget);
|
|
@@ -2372,6 +2411,7 @@ export function createChecker(program) {
|
|
|
2372
2411
|
const type = getTypeForNode(argNode, mapper);
|
|
2373
2412
|
return {
|
|
2374
2413
|
value: type,
|
|
2414
|
+
jsValue: type,
|
|
2375
2415
|
node: argNode,
|
|
2376
2416
|
};
|
|
2377
2417
|
});
|
|
@@ -3436,9 +3476,18 @@ export function createChecker(program) {
|
|
|
3436
3476
|
type = createType({ kind: "Boolean", value });
|
|
3437
3477
|
break;
|
|
3438
3478
|
case "number":
|
|
3479
|
+
let valueAsString;
|
|
3480
|
+
if (node) {
|
|
3481
|
+
compilerAssert(node.kind === SyntaxKind.NumericLiteral, "Must pass numeric literal node or undefined when creating a numeric literal type");
|
|
3482
|
+
valueAsString = node.valueAsString;
|
|
3483
|
+
}
|
|
3484
|
+
else {
|
|
3485
|
+
valueAsString = String(value);
|
|
3486
|
+
}
|
|
3439
3487
|
type = createType({
|
|
3440
3488
|
kind: "Number",
|
|
3441
3489
|
value,
|
|
3490
|
+
valueAsString,
|
|
3442
3491
|
});
|
|
3443
3492
|
break;
|
|
3444
3493
|
}
|
|
@@ -3571,11 +3620,26 @@ export function createChecker(program) {
|
|
|
3571
3620
|
*/
|
|
3572
3621
|
function isTypeAssignableTo(source, target, diagnosticTarget) {
|
|
3573
3622
|
var _a;
|
|
3623
|
+
// BACKCOMPAT: Added May 2023 sprint, to be removed by June 2023 sprint
|
|
3624
|
+
if (source.kind === "TemplateParameter" && source.constraint && target.kind === "Value") {
|
|
3625
|
+
const [assignable] = isTypeAssignableTo(source.constraint, target.target, diagnosticTarget);
|
|
3626
|
+
if (assignable) {
|
|
3627
|
+
const constraint = getTypeName(source.constraint);
|
|
3628
|
+
reportDeprecated(program, `Template constrainted to '${constraint}' will not be assignable to '${getTypeName(target)}' in the future. Update the constraint to be 'valueof ${constraint}'`, diagnosticTarget);
|
|
3629
|
+
return [true, []];
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3574
3632
|
if (source.kind === "TemplateParameter") {
|
|
3575
3633
|
source = (_a = source.constraint) !== null && _a !== void 0 ? _a : unknownType;
|
|
3576
3634
|
}
|
|
3577
3635
|
if (source === target)
|
|
3578
3636
|
return [true, []];
|
|
3637
|
+
if (target.kind === "Value") {
|
|
3638
|
+
return isAssignableToValueType(source, target, diagnosticTarget);
|
|
3639
|
+
}
|
|
3640
|
+
if (source.kind === "Value") {
|
|
3641
|
+
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3642
|
+
}
|
|
3579
3643
|
const isSimpleTypeRelated = isSimpleTypeAssignableTo(source, target);
|
|
3580
3644
|
if (isSimpleTypeRelated === true) {
|
|
3581
3645
|
return [true, []];
|
|
@@ -3592,7 +3656,27 @@ export function createChecker(program) {
|
|
|
3592
3656
|
}
|
|
3593
3657
|
return [true, []];
|
|
3594
3658
|
}
|
|
3595
|
-
if (target.kind === "Model" &&
|
|
3659
|
+
if (target.kind === "Model" &&
|
|
3660
|
+
source.kind === "Model" &&
|
|
3661
|
+
target.name !== "object" &&
|
|
3662
|
+
target.indexer === undefined &&
|
|
3663
|
+
source.indexer &&
|
|
3664
|
+
source.indexer.key.name === "integer") {
|
|
3665
|
+
return [
|
|
3666
|
+
false,
|
|
3667
|
+
[
|
|
3668
|
+
createDiagnostic({
|
|
3669
|
+
code: "missing-index",
|
|
3670
|
+
format: {
|
|
3671
|
+
indexType: getTypeName(source.indexer.key),
|
|
3672
|
+
sourceType: getTypeName(target),
|
|
3673
|
+
},
|
|
3674
|
+
target: diagnosticTarget,
|
|
3675
|
+
}),
|
|
3676
|
+
],
|
|
3677
|
+
];
|
|
3678
|
+
}
|
|
3679
|
+
else if (target.kind === "Model" && target.indexer !== undefined && source.kind === "Model") {
|
|
3596
3680
|
return isIndexerValid(source, target, diagnosticTarget);
|
|
3597
3681
|
}
|
|
3598
3682
|
else if (target.kind === "Model" && source.kind === "Model") {
|
|
@@ -3618,6 +3702,19 @@ export function createChecker(program) {
|
|
|
3618
3702
|
}
|
|
3619
3703
|
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3620
3704
|
}
|
|
3705
|
+
function isAssignableToValueType(source, target, diagnosticTarget) {
|
|
3706
|
+
if (source.kind === "Value") {
|
|
3707
|
+
return isTypeAssignableTo(source.target, target.target, diagnosticTarget);
|
|
3708
|
+
}
|
|
3709
|
+
const [assignable, diagnostics] = isTypeAssignableTo(source, target.target, diagnosticTarget);
|
|
3710
|
+
if (!assignable) {
|
|
3711
|
+
return [assignable, diagnostics];
|
|
3712
|
+
}
|
|
3713
|
+
if (!isValueType(source)) {
|
|
3714
|
+
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3715
|
+
}
|
|
3716
|
+
return [true, []];
|
|
3717
|
+
}
|
|
3621
3718
|
function isReflectionType(type) {
|
|
3622
3719
|
var _a, _b, _c;
|
|
3623
3720
|
return (type.kind === "Model" &&
|
|
@@ -3685,6 +3782,10 @@ export function createChecker(program) {
|
|
|
3685
3782
|
}
|
|
3686
3783
|
if (target.name === "numeric")
|
|
3687
3784
|
return true;
|
|
3785
|
+
if (target.name === "decimal")
|
|
3786
|
+
return true;
|
|
3787
|
+
if (target.name === "decimal128")
|
|
3788
|
+
return true;
|
|
3688
3789
|
const isInt = Number.isInteger(source.value);
|
|
3689
3790
|
if (target.name === "integer")
|
|
3690
3791
|
return isInt;
|
|
@@ -4094,8 +4195,48 @@ function linkMapper(typeDef, mapper) {
|
|
|
4094
4195
|
typeDef.templateArguments = mapper.args;
|
|
4095
4196
|
}
|
|
4096
4197
|
}
|
|
4198
|
+
function extractMainDoc(type) {
|
|
4199
|
+
var _a;
|
|
4200
|
+
if (((_a = type.node) === null || _a === void 0 ? void 0 : _a.docs) === undefined) {
|
|
4201
|
+
return undefined;
|
|
4202
|
+
}
|
|
4203
|
+
let mainDoc = "";
|
|
4204
|
+
for (const doc of type.node.docs) {
|
|
4205
|
+
mainDoc += getDocContent(doc.content);
|
|
4206
|
+
}
|
|
4207
|
+
const trimmed = mainDoc.trim();
|
|
4208
|
+
return trimmed === "" ? undefined : trimmed;
|
|
4209
|
+
}
|
|
4210
|
+
function extractParamDoc(node, paramName) {
|
|
4211
|
+
if (node.docs === undefined) {
|
|
4212
|
+
return undefined;
|
|
4213
|
+
}
|
|
4214
|
+
for (const doc of node.docs) {
|
|
4215
|
+
for (const tag of doc.tags) {
|
|
4216
|
+
if (tag.kind === SyntaxKind.DocParamTag && tag.paramName.sv === paramName) {
|
|
4217
|
+
return getDocContent(tag.content);
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
return undefined;
|
|
4222
|
+
}
|
|
4223
|
+
function getDocContent(content) {
|
|
4224
|
+
const docs = [];
|
|
4225
|
+
for (const node of content) {
|
|
4226
|
+
compilerAssert(node.kind === SyntaxKind.DocText, "No other doc content node kinds exist yet. Update this code appropriately when more are added.");
|
|
4227
|
+
docs.push(node.text);
|
|
4228
|
+
}
|
|
4229
|
+
return docs.join("");
|
|
4230
|
+
}
|
|
4097
4231
|
function finishTypeForProgramAndChecker(program, typePrototype, typeDef) {
|
|
4098
4232
|
if ("decorators" in typeDef) {
|
|
4233
|
+
const docComment = extractMainDoc(typeDef);
|
|
4234
|
+
if (docComment) {
|
|
4235
|
+
typeDef.decorators.unshift({
|
|
4236
|
+
decorator: $docFromComment,
|
|
4237
|
+
args: [{ value: program.checker.createLiteralType(docComment), jsValue: docComment }],
|
|
4238
|
+
});
|
|
4239
|
+
}
|
|
4099
4240
|
for (const decApp of typeDef.decorators) {
|
|
4100
4241
|
applyDecoratorToType(program, decApp, typeDef);
|
|
4101
4242
|
}
|
|
@@ -4115,7 +4256,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4115
4256
|
}
|
|
4116
4257
|
// peel `fn` off to avoid setting `this`.
|
|
4117
4258
|
try {
|
|
4118
|
-
const args =
|
|
4259
|
+
const args = decApp.args.map((x) => x.jsValue);
|
|
4119
4260
|
const fn = decApp.decorator;
|
|
4120
4261
|
const context = createDecoratorContext(program, decApp);
|
|
4121
4262
|
fn(context, target, ...args);
|