@typespec/compiler 0.45.0-dev.9 → 0.46.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/checker.d.ts +2 -2
- package/dist/core/checker.d.ts.map +1 -1
- package/dist/core/checker.js +129 -38
- package/dist/core/checker.js.map +1 -1
- package/dist/core/cli/cli.js +1 -1
- package/dist/core/cli/cli.js.map +1 -1
- 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/parser.d.ts +1 -0
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +17 -8
- package/dist/core/parser.js.map +1 -1
- package/dist/core/program.d.ts.map +1 -1
- package/dist/core/program.js +0 -15
- 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/emitter-framework/type-emitter.d.ts.map +1 -1
- package/dist/emitter-framework/type-emitter.js +2 -1
- package/dist/emitter-framework/type-emitter.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/lib/decorators.d.ts +3 -2
- package/dist/lib/decorators.d.ts.map +1 -1
- package/dist/lib/decorators.js +10 -5
- package/dist/lib/decorators.js.map +1 -1
- package/dist/manifest.js +2 -2
- 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 +158 -74
- 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 +38 -22
- 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 +2 -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,EA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12 +1,12 @@
|
|
|
1
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) {
|
|
@@ -2209,7 +2215,7 @@ export function createChecker(program) {
|
|
|
2209
2215
|
if (doc) {
|
|
2210
2216
|
type.decorators.unshift({
|
|
2211
2217
|
decorator: $docFromComment,
|
|
2212
|
-
args: [{ value: createLiteralType(doc) }],
|
|
2218
|
+
args: [{ value: createLiteralType(doc), jsValue: doc }],
|
|
2213
2219
|
});
|
|
2214
2220
|
}
|
|
2215
2221
|
}
|
|
@@ -2262,7 +2268,7 @@ export function createChecker(program) {
|
|
|
2262
2268
|
return undefined;
|
|
2263
2269
|
}
|
|
2264
2270
|
const symbolLinks = getSymbolLinks(sym);
|
|
2265
|
-
|
|
2271
|
+
let args = checkDecoratorArguments(decNode, mapper);
|
|
2266
2272
|
let hasError = false;
|
|
2267
2273
|
if (symbolLinks.declaredType === undefined) {
|
|
2268
2274
|
const decoratorDeclNode = sym.declarations.find((x) => x.kind === SyntaxKind.DecoratorDeclarationStatement);
|
|
@@ -2273,19 +2279,20 @@ export function createChecker(program) {
|
|
|
2273
2279
|
if (symbolLinks.declaredType) {
|
|
2274
2280
|
compilerAssert(symbolLinks.declaredType.kind === "Decorator", "Expected to find a decorator type.");
|
|
2275
2281
|
// Means we have a decorator declaration.
|
|
2276
|
-
hasError = checkDecoratorUsage(targetType, symbolLinks.declaredType, args, decNode);
|
|
2282
|
+
[hasError, args] = checkDecoratorUsage(targetType, symbolLinks.declaredType, args, decNode);
|
|
2277
2283
|
}
|
|
2278
2284
|
if (hasError) {
|
|
2279
2285
|
return undefined;
|
|
2280
2286
|
}
|
|
2281
2287
|
return {
|
|
2288
|
+
definition: symbolLinks.declaredType,
|
|
2282
2289
|
decorator: (_a = sym.value) !== null && _a !== void 0 ? _a : ((...args) => { }),
|
|
2283
2290
|
node: decNode,
|
|
2284
2291
|
args,
|
|
2285
2292
|
};
|
|
2286
2293
|
}
|
|
2287
2294
|
function checkDecoratorUsage(targetType, declaration, args, decoratorNode) {
|
|
2288
|
-
var _a
|
|
2295
|
+
var _a;
|
|
2289
2296
|
let hasError = false;
|
|
2290
2297
|
const [targetValid] = isTypeAssignableTo(targetType, declaration.target.type, decoratorNode);
|
|
2291
2298
|
if (!targetValid) {
|
|
@@ -2323,13 +2330,18 @@ export function createChecker(program) {
|
|
|
2323
2330
|
}));
|
|
2324
2331
|
}
|
|
2325
2332
|
}
|
|
2333
|
+
const resolvedArgs = [];
|
|
2326
2334
|
for (const [index, parameter] of declaration.parameters.entries()) {
|
|
2327
2335
|
if (parameter.rest) {
|
|
2328
|
-
const restType = parameter.type.kind === "
|
|
2336
|
+
const restType = getIndexType(parameter.type.kind === "Value" ? parameter.type.target : parameter.type);
|
|
2329
2337
|
if (restType) {
|
|
2330
2338
|
for (let i = index; i < args.length; i++) {
|
|
2331
2339
|
const arg = args[i];
|
|
2332
2340
|
if (arg && arg.value) {
|
|
2341
|
+
resolvedArgs.push({
|
|
2342
|
+
...arg,
|
|
2343
|
+
jsValue: resolveDecoratorArgJsValue(arg.value, parameter.type.kind === "Value"),
|
|
2344
|
+
});
|
|
2333
2345
|
if (!checkArgumentAssignable(arg.value, restType, arg.node)) {
|
|
2334
2346
|
hasError = true;
|
|
2335
2347
|
}
|
|
@@ -2340,12 +2352,28 @@ export function createChecker(program) {
|
|
|
2340
2352
|
}
|
|
2341
2353
|
const arg = args[index];
|
|
2342
2354
|
if (arg && arg.value) {
|
|
2355
|
+
resolvedArgs.push({
|
|
2356
|
+
...arg,
|
|
2357
|
+
jsValue: resolveDecoratorArgJsValue(arg.value, parameter.type.kind === "Value"),
|
|
2358
|
+
});
|
|
2343
2359
|
if (!checkArgumentAssignable(arg.value, parameter.type, arg.node)) {
|
|
2344
2360
|
hasError = true;
|
|
2345
2361
|
}
|
|
2346
2362
|
}
|
|
2347
2363
|
}
|
|
2348
|
-
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;
|
|
2349
2377
|
}
|
|
2350
2378
|
function checkArgumentAssignable(argumentType, parameterType, diagnosticTarget) {
|
|
2351
2379
|
const [valid] = isTypeAssignableTo(argumentType, parameterType, diagnosticTarget);
|
|
@@ -2383,6 +2411,7 @@ export function createChecker(program) {
|
|
|
2383
2411
|
const type = getTypeForNode(argNode, mapper);
|
|
2384
2412
|
return {
|
|
2385
2413
|
value: type,
|
|
2414
|
+
jsValue: type,
|
|
2386
2415
|
node: argNode,
|
|
2387
2416
|
};
|
|
2388
2417
|
});
|
|
@@ -3447,9 +3476,18 @@ export function createChecker(program) {
|
|
|
3447
3476
|
type = createType({ kind: "Boolean", value });
|
|
3448
3477
|
break;
|
|
3449
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
|
+
}
|
|
3450
3487
|
type = createType({
|
|
3451
3488
|
kind: "Number",
|
|
3452
3489
|
value,
|
|
3490
|
+
valueAsString,
|
|
3453
3491
|
});
|
|
3454
3492
|
break;
|
|
3455
3493
|
}
|
|
@@ -3582,11 +3620,26 @@ export function createChecker(program) {
|
|
|
3582
3620
|
*/
|
|
3583
3621
|
function isTypeAssignableTo(source, target, diagnosticTarget) {
|
|
3584
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
|
+
}
|
|
3585
3632
|
if (source.kind === "TemplateParameter") {
|
|
3586
3633
|
source = (_a = source.constraint) !== null && _a !== void 0 ? _a : unknownType;
|
|
3587
3634
|
}
|
|
3588
3635
|
if (source === target)
|
|
3589
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
|
+
}
|
|
3590
3643
|
const isSimpleTypeRelated = isSimpleTypeAssignableTo(source, target);
|
|
3591
3644
|
if (isSimpleTypeRelated === true) {
|
|
3592
3645
|
return [true, []];
|
|
@@ -3603,7 +3656,27 @@ export function createChecker(program) {
|
|
|
3603
3656
|
}
|
|
3604
3657
|
return [true, []];
|
|
3605
3658
|
}
|
|
3606
|
-
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") {
|
|
3607
3680
|
return isIndexerValid(source, target, diagnosticTarget);
|
|
3608
3681
|
}
|
|
3609
3682
|
else if (target.kind === "Model" && source.kind === "Model") {
|
|
@@ -3629,6 +3702,19 @@ export function createChecker(program) {
|
|
|
3629
3702
|
}
|
|
3630
3703
|
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3631
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
|
+
}
|
|
3632
3718
|
function isReflectionType(type) {
|
|
3633
3719
|
var _a, _b, _c;
|
|
3634
3720
|
return (type.kind === "Model" &&
|
|
@@ -3696,6 +3782,10 @@ export function createChecker(program) {
|
|
|
3696
3782
|
}
|
|
3697
3783
|
if (target.name === "numeric")
|
|
3698
3784
|
return true;
|
|
3785
|
+
if (target.name === "decimal")
|
|
3786
|
+
return true;
|
|
3787
|
+
if (target.name === "decimal128")
|
|
3788
|
+
return true;
|
|
3699
3789
|
const isInt = Number.isInteger(source.value);
|
|
3700
3790
|
if (target.name === "integer")
|
|
3701
3791
|
return isInt;
|
|
@@ -4114,7 +4204,8 @@ function extractMainDoc(type) {
|
|
|
4114
4204
|
for (const doc of type.node.docs) {
|
|
4115
4205
|
mainDoc += getDocContent(doc.content);
|
|
4116
4206
|
}
|
|
4117
|
-
|
|
4207
|
+
const trimmed = mainDoc.trim();
|
|
4208
|
+
return trimmed === "" ? undefined : trimmed;
|
|
4118
4209
|
}
|
|
4119
4210
|
function extractParamDoc(node, paramName) {
|
|
4120
4211
|
if (node.docs === undefined) {
|
|
@@ -4143,7 +4234,7 @@ function finishTypeForProgramAndChecker(program, typePrototype, typeDef) {
|
|
|
4143
4234
|
if (docComment) {
|
|
4144
4235
|
typeDef.decorators.unshift({
|
|
4145
4236
|
decorator: $docFromComment,
|
|
4146
|
-
args: [{ value: program.checker.createLiteralType(docComment) }],
|
|
4237
|
+
args: [{ value: program.checker.createLiteralType(docComment), jsValue: docComment }],
|
|
4147
4238
|
});
|
|
4148
4239
|
}
|
|
4149
4240
|
for (const decApp of typeDef.decorators) {
|
|
@@ -4165,7 +4256,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4165
4256
|
}
|
|
4166
4257
|
// peel `fn` off to avoid setting `this`.
|
|
4167
4258
|
try {
|
|
4168
|
-
const args =
|
|
4259
|
+
const args = decApp.args.map((x) => x.jsValue);
|
|
4169
4260
|
const fn = decApp.decorator;
|
|
4170
4261
|
const context = createDecoratorContext(program, decApp);
|
|
4171
4262
|
fn(context, target, ...args);
|