@typespec/compiler 0.58.0-dev.9 → 0.59.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/generated-defs/TypeSpec.d.ts +28 -1
- package/dist/generated-defs/TypeSpec.d.ts.map +1 -1
- package/dist/generated-defs/TypeSpec.ts-test.js +3 -1
- package/dist/generated-defs/TypeSpec.ts-test.js.map +1 -1
- package/dist/manifest.js +2 -2
- package/dist/src/core/checker.d.ts +11 -1
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +53 -20
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/formatter.d.ts +0 -1
- package/dist/src/core/formatter.d.ts.map +1 -1
- package/dist/src/core/formatter.js +0 -1
- package/dist/src/core/formatter.js.map +1 -1
- package/dist/src/core/helpers/index.d.ts +1 -0
- package/dist/src/core/helpers/index.d.ts.map +1 -1
- package/dist/src/core/helpers/index.js +1 -0
- package/dist/src/core/helpers/index.js.map +1 -1
- package/dist/src/core/helpers/syntax-utils.d.ts +13 -0
- package/dist/src/core/helpers/syntax-utils.d.ts.map +1 -0
- package/dist/src/core/helpers/syntax-utils.js +45 -0
- package/dist/src/core/helpers/syntax-utils.js.map +1 -0
- package/dist/src/core/helpers/type-name-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/type-name-utils.js +2 -2
- package/dist/src/core/helpers/type-name-utils.js.map +1 -1
- package/dist/src/core/messages.d.ts +5 -0
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +1 -0
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts +3 -4
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +9 -37
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/init/scaffold.js +8 -4
- package/dist/src/init/scaffold.js.map +1 -1
- package/dist/src/lib/decorators.d.ts +18 -2
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +76 -1
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/examples.d.ts +9 -0
- package/dist/src/lib/examples.d.ts.map +1 -0
- package/dist/src/lib/examples.js +137 -0
- package/dist/src/lib/examples.js.map +1 -0
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js +2 -3
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/type-signature.js +7 -7
- package/dist/src/server/type-signature.js.map +1 -1
- package/lib/std/decorators.tsp +60 -0
- package/package.json +4 -3
- package/templates/scaffolding.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DecoratorContext, Enum, Interface, Model, ModelProperty, Namespace, Numeric, Operation, Scalar, Type, Union } from "../src/index.js";
|
|
1
|
+
import type { DecoratorContext, Enum, Interface, Model, ModelProperty, Namespace, Numeric, Operation, Scalar, Type, Union, UnionVariant } from "../src/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Specify how to encode the target type.
|
|
4
4
|
*
|
|
@@ -406,6 +406,33 @@ export type EncodedNameDecorator = (context: DecoratorContext, target: Type, mim
|
|
|
406
406
|
* ```
|
|
407
407
|
*/
|
|
408
408
|
export type DiscriminatorDecorator = (context: DecoratorContext, target: Model | Union, propertyName: string) => void;
|
|
409
|
+
/**
|
|
410
|
+
* Provide an example value for a data type.
|
|
411
|
+
*
|
|
412
|
+
* @param example Example value.
|
|
413
|
+
* @param options Optional metadata for the example.
|
|
414
|
+
* @example
|
|
415
|
+
* ```tsp
|
|
416
|
+
* @example(#{name: "Fluffy", age: 2})
|
|
417
|
+
* model Pet {
|
|
418
|
+
* name: string;
|
|
419
|
+
* age: int32;
|
|
420
|
+
* }
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
export type ExampleDecorator = (context: DecoratorContext, target: Model | Enum | Scalar | Union | ModelProperty | UnionVariant, example: unknown, options?: unknown) => void;
|
|
424
|
+
/**
|
|
425
|
+
* Provide example values for an operation's parameters and corresponding return type.
|
|
426
|
+
*
|
|
427
|
+
* @param example Example value.
|
|
428
|
+
* @param options Optional metadata for the example.
|
|
429
|
+
* @example
|
|
430
|
+
* ```tsp
|
|
431
|
+
* @example(#{parameters: #{name: "Fluffy", age: 2}, returnType: #{name: "Fluffy", age: 2, id: "abc"})
|
|
432
|
+
* op createPet(pet: Pet): Pet;
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
export type OpExampleDecorator = (context: DecoratorContext, target: Operation, example: unknown, options?: unknown) => void;
|
|
409
436
|
/**
|
|
410
437
|
* Indicates that a property is only considered to be present or applicable ("visible") with
|
|
411
438
|
* the in the given named contexts ("visibilities"). When a property has no visibilities applied
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSpec.d.ts","sourceRoot":"","sources":["../../generated-defs/TypeSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,SAAS,EACT,KAAK,EACL,aAAa,EACb,SAAS,EACT,OAAO,EACP,SAAS,EACT,MAAM,EACN,IAAI,EACJ,KAAK,
|
|
1
|
+
{"version":3,"file":"TypeSpec.d.ts","sourceRoot":"","sources":["../../generated-defs/TypeSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,SAAS,EACT,KAAK,EACL,aAAa,EACb,SAAS,EACT,OAAO,EACP,SAAS,EACT,MAAM,EACN,IAAI,EACJ,KAAK,EACL,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,QAAQ,EAAE,IAAI,EACd,SAAS,CAAC,EAAE,MAAM,KACf,IAAI,CAAC;AAEV;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,OA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AAY,EAAE,MAAM,EAAE,KACtB,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAC1C,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,SAAS,EACjB,GAAG,YAAY,EAAE,MAAM,EAAE,KACtB,IAAI,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** An error here would mean that the decorator is not exported or doesn't have the right name. */
|
|
2
|
-
import { $deprecated, $discriminator, $doc, $encode, $encodedName, $error, $errorsDoc, $format, $friendlyName, $inspectType, $inspectTypeName, $key, $knownValues, $list, $maxItems, $maxLength, $maxValue, $maxValueExclusive, $minItems, $minLength, $minValue, $minValueExclusive, $overload, $parameterVisibility, $pattern, $projectedName, $returnTypeVisibility, $returnsDoc, $secret, $service, $summary, $tag, $visibility, $withDefaultKeyVisibility, $withOptionalProperties, $withPickedProperties, $withUpdateableProperties, $withVisibility, $withoutDefaultValues, $withoutOmittedProperties, } from "../src/index.js";
|
|
2
|
+
import { $deprecated, $discriminator, $doc, $encode, $encodedName, $error, $errorsDoc, $example, $format, $friendlyName, $inspectType, $inspectTypeName, $key, $knownValues, $list, $maxItems, $maxLength, $maxValue, $maxValueExclusive, $minItems, $minLength, $minValue, $minValueExclusive, $opExample, $overload, $parameterVisibility, $pattern, $projectedName, $returnTypeVisibility, $returnsDoc, $secret, $service, $summary, $tag, $visibility, $withDefaultKeyVisibility, $withOptionalProperties, $withPickedProperties, $withUpdateableProperties, $withVisibility, $withoutDefaultValues, $withoutOmittedProperties, } from "../src/index.js";
|
|
3
3
|
/** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */
|
|
4
4
|
const _ = {
|
|
5
5
|
$encode,
|
|
@@ -36,6 +36,8 @@ const _ = {
|
|
|
36
36
|
$projectedName,
|
|
37
37
|
$encodedName,
|
|
38
38
|
$discriminator,
|
|
39
|
+
$example,
|
|
40
|
+
$opExample,
|
|
39
41
|
$visibility,
|
|
40
42
|
$withVisibility,
|
|
41
43
|
$inspectType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeSpec.ts-test.js","sourceRoot":"","sources":["../../generated-defs/TypeSpec.ts-test.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,EACL,WAAW,EACX,cAAc,EACd,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,MAAM,EACN,UAAU,EACV,OAAO,EACP,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"TypeSpec.ts-test.js","sourceRoot":"","sources":["../../generated-defs/TypeSpec.ts-test.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,EACL,WAAW,EACX,cAAc,EACd,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,MAAM,EACN,UAAU,EACV,QAAQ,EACR,OAAO,EACP,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAC;AA2FzB,qKAAqK;AACrK,MAAM,CAAC,GAAe;IACpB,OAAO;IACP,IAAI;IACJ,uBAAuB;IACvB,yBAAyB;IACzB,yBAAyB;IACzB,qBAAqB;IACrB,qBAAqB;IACrB,yBAAyB;IACzB,QAAQ;IACR,WAAW;IACX,UAAU;IACV,WAAW;IACX,QAAQ;IACR,MAAM;IACN,OAAO;IACP,QAAQ;IACR,UAAU;IACV,UAAU;IACV,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,kBAAkB;IAClB,kBAAkB;IAClB,OAAO;IACP,KAAK;IACL,IAAI;IACJ,aAAa;IACb,YAAY;IACZ,IAAI;IACJ,SAAS;IACT,cAAc;IACd,YAAY;IACZ,cAAc;IACd,QAAQ;IACR,UAAU;IACV,WAAW;IACX,eAAe;IACf,YAAY;IACZ,gBAAgB;IAChB,oBAAoB;IACpB,qBAAqB;CACtB,CAAC"}
|
package/dist/manifest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TypeNameOptions } from "./helpers/type-name-utils.js";
|
|
2
2
|
import type { Program, ProjectedProgram } from "./program.js";
|
|
3
|
-
import { BooleanLiteral, BooleanLiteralNode, Diagnostic, DiagnosticTarget, Entity, ErrorType, FunctionType, IdentifierNode, IntrinsicScalarName, JsSourceFileNode, LiteralNode, LiteralType, Model, ModelProperty, Namespace, NamespaceStatementNode, NeverType, Node, NullType, NumericLiteral, NumericLiteralNode, ProjectionNode, ProjectionStatementNode, Scalar, StdTypeName, StdTypes, StringLiteral, StringLiteralNode, Sym, Type, TypeReferenceNode, TypeSpecScriptNode, UnknownType, VoidType } from "./types.js";
|
|
3
|
+
import { BooleanLiteral, BooleanLiteralNode, Diagnostic, DiagnosticTarget, Entity, ErrorType, FunctionType, IdentifierNode, IntrinsicScalarName, JsSourceFileNode, LiteralNode, LiteralType, Model, ModelProperty, Namespace, NamespaceStatementNode, NeverType, Node, NullType, NumericLiteral, NumericLiteralNode, ProjectionNode, ProjectionStatementNode, Scalar, StdTypeName, StdTypes, StringLiteral, StringLiteralNode, Sym, Type, TypeReferenceNode, TypeSpecScriptNode, UnknownType, Value, VoidType } from "./types.js";
|
|
4
4
|
export type CreateTypeProps = Omit<Type, "isFinished" | "entityKind" | keyof TypePrototype>;
|
|
5
5
|
export interface Checker {
|
|
6
6
|
typePrototype: TypePrototype;
|
|
@@ -67,6 +67,16 @@ export interface Checker {
|
|
|
67
67
|
* @param name Name
|
|
68
68
|
*/
|
|
69
69
|
getStdType<T extends keyof StdTypes>(name: T): StdTypes[T];
|
|
70
|
+
/**
|
|
71
|
+
* Return the exact type of a value.
|
|
72
|
+
*
|
|
73
|
+
* ```tsp
|
|
74
|
+
* const a: string = "hello";
|
|
75
|
+
* ```
|
|
76
|
+
* calling `getValueExactType` on the value of a would give the string literal "hello".
|
|
77
|
+
* @param value
|
|
78
|
+
*/
|
|
79
|
+
getValueExactType(value: Value): Type | undefined;
|
|
70
80
|
/**
|
|
71
81
|
* Check and resolve a type for the given type reference node.
|
|
72
82
|
* @param node Node.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../src/core/checker.ts"],"names":[],"mappings":"AAgBA,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,8BAA8B,CAAC;AA0BtC,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAe9D,OAAO,EAOL,cAAc,EACd,kBAAkB,EAYlB,UAAU,EACV,gBAAgB,EAEhB,MAAM,EAMN,SAAS,EAKT,YAAY,EAEZ,cAAc,EAKd,mBAAmB,EAEnB,gBAAgB,EAChB,WAAW,EACX,WAAW,EAQX,KAAK,EAGL,aAAa,EAIb,SAAS,EACT,sBAAsB,EACtB,SAAS,EACT,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AC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAaD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAosPvD;AAkED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,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,CAoCP;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/src/core/checker.js
CHANGED
|
@@ -33,6 +33,7 @@ export function createChecker(program) {
|
|
|
33
33
|
const augmentDecoratorsForSym = new Map();
|
|
34
34
|
const augmentedSymbolTables = new Map();
|
|
35
35
|
const referenceSymCache = new WeakMap();
|
|
36
|
+
const valueExactTypes = new WeakMap();
|
|
36
37
|
let onCheckerDiagnostic = (x) => {
|
|
37
38
|
program.reportDiagnostic(x);
|
|
38
39
|
};
|
|
@@ -127,6 +128,7 @@ export function createChecker(program) {
|
|
|
127
128
|
resolveTypeReference,
|
|
128
129
|
getValueForNode,
|
|
129
130
|
getTypeOrValueForNode,
|
|
131
|
+
getValueExactType,
|
|
130
132
|
};
|
|
131
133
|
const projectionMembers = createProjectionMembers(checker);
|
|
132
134
|
return checker;
|
|
@@ -530,6 +532,10 @@ export function createChecker(program) {
|
|
|
530
532
|
values,
|
|
531
533
|
};
|
|
532
534
|
}
|
|
535
|
+
function canTryLegacyCast(target, constraint) {
|
|
536
|
+
return Boolean(constraint?.valueType &&
|
|
537
|
+
!(constraint.type && ignoreDiagnostics(isTypeAssignableTo(target, constraint.type, target))));
|
|
538
|
+
}
|
|
533
539
|
/**
|
|
534
540
|
* Gets a type or value depending on the node and current constraint.
|
|
535
541
|
* For nodes that can be both type or values(e.g. string), the value will be returned if the constraint expect a value of that type even if the constrain also allows the type.
|
|
@@ -542,7 +548,7 @@ export function createChecker(program) {
|
|
|
542
548
|
return entity;
|
|
543
549
|
}
|
|
544
550
|
else if (isType(entity)) {
|
|
545
|
-
if (
|
|
551
|
+
if (canTryLegacyCast(entity, constraint?.constraint)) {
|
|
546
552
|
return legacy_tryTypeToValueCast(entity, valueConstraint, node);
|
|
547
553
|
}
|
|
548
554
|
else {
|
|
@@ -958,7 +964,7 @@ export function createChecker(program) {
|
|
|
958
964
|
const constraint = param.constraint.type?.kind === "TemplateParameter"
|
|
959
965
|
? finalMap.get(param.constraint.type)
|
|
960
966
|
: param.constraint;
|
|
961
|
-
if (isType(type) && param.constraint
|
|
967
|
+
if (isType(type) && canTryLegacyCast(type, param.constraint)) {
|
|
962
968
|
const converted = legacy_tryTypeToValueCast(type, { kind: "argument", type: param.constraint.valueType }, argNode);
|
|
963
969
|
// If we manage to convert it means this might be convertable so we skip type checking.
|
|
964
970
|
// However we still return the original entity
|
|
@@ -2943,13 +2949,13 @@ export function createChecker(program) {
|
|
|
2943
2949
|
if (constraint && !checkTypeOfValueMatchConstraint(preciseType, constraint, node)) {
|
|
2944
2950
|
return null;
|
|
2945
2951
|
}
|
|
2946
|
-
return {
|
|
2952
|
+
return createValue({
|
|
2947
2953
|
entityKind: "Value",
|
|
2948
2954
|
valueKind: "ObjectValue",
|
|
2949
2955
|
node: node,
|
|
2950
2956
|
properties,
|
|
2951
2957
|
type: constraint ? constraint.type : preciseType,
|
|
2952
|
-
};
|
|
2958
|
+
}, preciseType);
|
|
2953
2959
|
}
|
|
2954
2960
|
function createTypeForObjectValue(node, properties) {
|
|
2955
2961
|
const model = createType({
|
|
@@ -3028,13 +3034,25 @@ export function createChecker(program) {
|
|
|
3028
3034
|
if (constraint && !checkTypeOfValueMatchConstraint(preciseType, constraint, node)) {
|
|
3029
3035
|
return null;
|
|
3030
3036
|
}
|
|
3031
|
-
return {
|
|
3037
|
+
return createValue({
|
|
3032
3038
|
entityKind: "Value",
|
|
3033
3039
|
valueKind: "ArrayValue",
|
|
3034
3040
|
node: node,
|
|
3035
3041
|
values: values,
|
|
3036
3042
|
type: constraint ? constraint.type : preciseType,
|
|
3037
|
-
};
|
|
3043
|
+
}, preciseType);
|
|
3044
|
+
}
|
|
3045
|
+
function createValue(value, preciseType) {
|
|
3046
|
+
valueExactTypes.set(value, preciseType);
|
|
3047
|
+
return value;
|
|
3048
|
+
}
|
|
3049
|
+
function copyValue(value, overrides) {
|
|
3050
|
+
const newValue = { ...value, ...overrides };
|
|
3051
|
+
const preciseType = valueExactTypes.get(value);
|
|
3052
|
+
if (preciseType) {
|
|
3053
|
+
valueExactTypes.set(newValue, preciseType);
|
|
3054
|
+
}
|
|
3055
|
+
return newValue;
|
|
3038
3056
|
}
|
|
3039
3057
|
function createTypeForArrayValue(node, values) {
|
|
3040
3058
|
return createAndFinishType({
|
|
@@ -3098,61 +3116,61 @@ export function createChecker(program) {
|
|
|
3098
3116
|
value = literalType.value;
|
|
3099
3117
|
}
|
|
3100
3118
|
const scalar = inferScalarForPrimitiveValue(constraint?.type, literalType);
|
|
3101
|
-
return {
|
|
3119
|
+
return createValue({
|
|
3102
3120
|
entityKind: "Value",
|
|
3103
3121
|
valueKind: "StringValue",
|
|
3104
3122
|
value,
|
|
3105
3123
|
type: constraint ? constraint.type : literalType,
|
|
3106
3124
|
scalar,
|
|
3107
|
-
};
|
|
3125
|
+
}, literalType);
|
|
3108
3126
|
}
|
|
3109
3127
|
function checkNumericValue(literalType, constraint, node) {
|
|
3110
3128
|
if (constraint && !checkTypeOfValueMatchConstraint(literalType, constraint, node)) {
|
|
3111
3129
|
return null;
|
|
3112
3130
|
}
|
|
3113
3131
|
const scalar = inferScalarForPrimitiveValue(constraint?.type, literalType);
|
|
3114
|
-
return {
|
|
3132
|
+
return createValue({
|
|
3115
3133
|
entityKind: "Value",
|
|
3116
3134
|
valueKind: "NumericValue",
|
|
3117
3135
|
value: Numeric(literalType.valueAsString),
|
|
3118
3136
|
type: constraint ? constraint.type : literalType,
|
|
3119
3137
|
scalar,
|
|
3120
|
-
};
|
|
3138
|
+
}, literalType);
|
|
3121
3139
|
}
|
|
3122
3140
|
function checkBooleanValue(literalType, constraint, node) {
|
|
3123
3141
|
if (constraint && !checkTypeOfValueMatchConstraint(literalType, constraint, node)) {
|
|
3124
3142
|
return null;
|
|
3125
3143
|
}
|
|
3126
3144
|
const scalar = inferScalarForPrimitiveValue(constraint?.type, literalType);
|
|
3127
|
-
return {
|
|
3145
|
+
return createValue({
|
|
3128
3146
|
entityKind: "Value",
|
|
3129
3147
|
valueKind: "BooleanValue",
|
|
3130
3148
|
value: literalType.value,
|
|
3131
3149
|
type: constraint ? constraint.type : literalType,
|
|
3132
3150
|
scalar,
|
|
3133
|
-
};
|
|
3151
|
+
}, literalType);
|
|
3134
3152
|
}
|
|
3135
3153
|
function checkNullValue(literalType, constraint, node) {
|
|
3136
3154
|
if (constraint && !checkTypeOfValueMatchConstraint(literalType, constraint, node)) {
|
|
3137
3155
|
return null;
|
|
3138
3156
|
}
|
|
3139
|
-
return {
|
|
3157
|
+
return createValue({
|
|
3140
3158
|
entityKind: "Value",
|
|
3141
3159
|
valueKind: "NullValue",
|
|
3142
3160
|
type: constraint ? constraint.type : literalType,
|
|
3143
3161
|
value: null,
|
|
3144
|
-
};
|
|
3162
|
+
}, literalType);
|
|
3145
3163
|
}
|
|
3146
3164
|
function checkEnumValue(literalType, constraint, node) {
|
|
3147
3165
|
if (constraint && !checkTypeOfValueMatchConstraint(literalType, constraint, node)) {
|
|
3148
3166
|
return null;
|
|
3149
3167
|
}
|
|
3150
|
-
return {
|
|
3168
|
+
return createValue({
|
|
3151
3169
|
entityKind: "Value",
|
|
3152
3170
|
valueKind: "EnumValue",
|
|
3153
3171
|
type: constraint ? constraint.type : literalType,
|
|
3154
3172
|
value: literalType,
|
|
3155
|
-
};
|
|
3173
|
+
}, literalType);
|
|
3156
3174
|
}
|
|
3157
3175
|
function checkCallExpressionTarget(node, mapper) {
|
|
3158
3176
|
const target = checkTypeReference(node.target, mapper);
|
|
@@ -3194,7 +3212,7 @@ export function createChecker(program) {
|
|
|
3194
3212
|
if (!checkValueOfType(value, scalar, argNode)) {
|
|
3195
3213
|
return null;
|
|
3196
3214
|
}
|
|
3197
|
-
return
|
|
3215
|
+
return copyValue(value, { scalar, type: scalar });
|
|
3198
3216
|
}
|
|
3199
3217
|
function createScalarValue(node, mapper, declaration) {
|
|
3200
3218
|
let hasError = false;
|
|
@@ -3379,14 +3397,26 @@ export function createChecker(program) {
|
|
|
3379
3397
|
const [isAssignable, _] = isTypeAssignableTo(newProp.type, overriddenProp.type, newProp);
|
|
3380
3398
|
const parentType = getTypeName(overriddenProp.type);
|
|
3381
3399
|
const newPropType = getTypeName(newProp.type);
|
|
3400
|
+
let invalid = false;
|
|
3382
3401
|
if (!isAssignable) {
|
|
3383
3402
|
reportCheckerDiagnostic(createDiagnostic({
|
|
3384
3403
|
code: "override-property-mismatch",
|
|
3385
3404
|
format: { propName: newProp.name, propType: newPropType, parentType: parentType },
|
|
3386
3405
|
target: diagnosticTarget ?? newProp,
|
|
3387
3406
|
}));
|
|
3388
|
-
|
|
3407
|
+
invalid = true;
|
|
3389
3408
|
}
|
|
3409
|
+
if (!overriddenProp.optional && newProp.optional) {
|
|
3410
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
3411
|
+
code: "override-property-mismatch",
|
|
3412
|
+
messageId: "disallowedOptionalOverride",
|
|
3413
|
+
format: { propName: overriddenProp.name },
|
|
3414
|
+
target: diagnosticTarget ?? newProp,
|
|
3415
|
+
}));
|
|
3416
|
+
invalid = true;
|
|
3417
|
+
}
|
|
3418
|
+
if (invalid)
|
|
3419
|
+
return;
|
|
3390
3420
|
}
|
|
3391
3421
|
properties.set(newProp.name, newProp);
|
|
3392
3422
|
}
|
|
@@ -4335,7 +4365,7 @@ export function createChecker(program) {
|
|
|
4335
4365
|
links.value = null;
|
|
4336
4366
|
return links.value;
|
|
4337
4367
|
}
|
|
4338
|
-
links.value = type ?
|
|
4368
|
+
links.value = type ? copyValue(value, { type }) : copyValue(value);
|
|
4339
4369
|
return links.value;
|
|
4340
4370
|
}
|
|
4341
4371
|
function inferScalarsFromConstraints(value, type) {
|
|
@@ -4345,7 +4375,7 @@ export function createChecker(program) {
|
|
|
4345
4375
|
case "NumericValue":
|
|
4346
4376
|
if (value.scalar === undefined) {
|
|
4347
4377
|
const scalar = inferScalarForPrimitiveValue(type, value.type);
|
|
4348
|
-
return
|
|
4378
|
+
return copyValue(value, { scalar });
|
|
4349
4379
|
}
|
|
4350
4380
|
return value;
|
|
4351
4381
|
case "ArrayValue":
|
|
@@ -6131,6 +6161,9 @@ export function createChecker(program) {
|
|
|
6131
6161
|
return stdType === undefined || stdType === type.name;
|
|
6132
6162
|
return false;
|
|
6133
6163
|
}
|
|
6164
|
+
function getValueExactType(value) {
|
|
6165
|
+
return valueExactTypes.get(value);
|
|
6166
|
+
}
|
|
6134
6167
|
}
|
|
6135
6168
|
function isAnonymous(type) {
|
|
6136
6169
|
return !("name" in type) || typeof type.name !== "string" || !type.name;
|