@typespec/compiler 1.16.0-dev.7 → 1.16.0-dev.9
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/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +117 -0
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/features.d.ts +3 -0
- package/dist/src/core/features.d.ts.map +1 -1
- package/dist/src/core/features.js +3 -0
- package/dist/src/core/features.js.map +1 -1
- package/dist/src/core/messages.d.ts +43 -2
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +13 -0
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +10 -0
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/semantic-walker.d.ts.map +1 -1
- package/dist/src/core/semantic-walker.js +3 -0
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/types.d.ts +27 -0
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/experimental/mutators.js +1 -0
- package/dist/src/experimental/mutators.js.map +1 -1
- package/dist/src/formatter/print/comment-handler.d.ts.map +1 -1
- package/dist/src/formatter/print/comment-handler.js +34 -60
- package/dist/src/formatter/print/comment-handler.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +76 -12
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/server/completion.js +10 -1
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/tmlanguage.d.ts.map +1 -1
- package/dist/src/server/tmlanguage.js +16 -1
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/typespec.tmLanguage +36 -0
- package/package.json +16 -16
package/dist/manifest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../src/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createChecker(program, resolver) {
|
|
|
834
834
|
isTypeReferenceContextDeprecated(node.parent)));
|
|
835
835
|
case SyntaxKind.InterfaceStatement:
|
|
836
836
|
return checkDeprecatedNode(node);
|
|
837
|
+
case SyntaxKind.UnionStatement:
|
|
838
|
+
return checkDeprecatedNode(node);
|
|
837
839
|
case SyntaxKind.IntersectionExpression:
|
|
838
840
|
case SyntaxKind.UnionExpression:
|
|
839
841
|
case SyntaxKind.ModelProperty:
|
|
@@ -5771,6 +5773,12 @@ export function createChecker(program, resolver) {
|
|
|
5771
5773
|
}
|
|
5772
5774
|
if (ctx.mapper === undefined) {
|
|
5773
5775
|
checkModifiers(program, node);
|
|
5776
|
+
if (node.extends && !isCompilerFeatureEnabled(program, "union-extends", node)) {
|
|
5777
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
5778
|
+
code: "union-extends-disabled",
|
|
5779
|
+
target: node.extends,
|
|
5780
|
+
}));
|
|
5781
|
+
}
|
|
5774
5782
|
}
|
|
5775
5783
|
checkTemplateDeclaration(ctx, node);
|
|
5776
5784
|
const variants = createRekeyableMap();
|
|
@@ -5787,6 +5795,9 @@ export function createChecker(program, resolver) {
|
|
|
5787
5795
|
expression: false,
|
|
5788
5796
|
});
|
|
5789
5797
|
linkType(ctx, links, unionType);
|
|
5798
|
+
if (node.extends) {
|
|
5799
|
+
unionType.baseType = checkUnionBaseType(ctx, node, unionType, node.extends);
|
|
5800
|
+
}
|
|
5790
5801
|
unionType.decorators = checkDecorators(ctx, unionType, node);
|
|
5791
5802
|
checkUnionVariants(ctx, unionType, node, variants);
|
|
5792
5803
|
linkMapper(unionType, ctx.mapper);
|
|
@@ -5812,8 +5823,114 @@ export function createChecker(program, resolver) {
|
|
|
5812
5823
|
continue;
|
|
5813
5824
|
}
|
|
5814
5825
|
variants.set(variantType.name, variantType);
|
|
5826
|
+
checkUnionVariantAgainstBaseType(ctx, parentUnion, variantNode, variantType);
|
|
5815
5827
|
}
|
|
5816
5828
|
}
|
|
5829
|
+
/**
|
|
5830
|
+
* Validate that a union variant satisfies the constraint declared by the union `extends` clause.
|
|
5831
|
+
* Skipped inside of an uninstantiated template declaration where variant types are still
|
|
5832
|
+
* unresolved template parameters. Each instantiation is checked instead.
|
|
5833
|
+
*/
|
|
5834
|
+
function checkUnionVariantAgainstBaseType(ctx, parentUnion, variantNode, variantType) {
|
|
5835
|
+
const baseType = parentUnion.baseType;
|
|
5836
|
+
if (baseType === undefined || ctx.hasFlags(CheckFlags.InTemplateDeclaration)) {
|
|
5837
|
+
return;
|
|
5838
|
+
}
|
|
5839
|
+
if (isErrorType(variantType.type)) {
|
|
5840
|
+
return;
|
|
5841
|
+
}
|
|
5842
|
+
checkTypeAssignable(variantType.type, baseType, variantNode.value);
|
|
5843
|
+
}
|
|
5844
|
+
/**
|
|
5845
|
+
* Resolve the type referenced by a union `extends` clause.
|
|
5846
|
+
*
|
|
5847
|
+
* The resulting type is only a constraint on the union variants: it doesn't create any
|
|
5848
|
+
* inheritance relationship, it doesn't add anything to the union and it doesn't make the
|
|
5849
|
+
* union extensible.
|
|
5850
|
+
*/
|
|
5851
|
+
function checkUnionBaseType(ctx, union, unionType, extendsRef) {
|
|
5852
|
+
const unionSymId = getNodeSym(union);
|
|
5853
|
+
pendingResolutions.start(unionSymId, ResolutionKind.BaseType);
|
|
5854
|
+
try {
|
|
5855
|
+
const target = resolver.getNodeLinks(extendsRef).resolvedSymbol;
|
|
5856
|
+
if (target && pendingResolutions.has(target, ResolutionKind.BaseType)) {
|
|
5857
|
+
if (ctx.mapper === undefined) {
|
|
5858
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
5859
|
+
code: "circular-base-type",
|
|
5860
|
+
format: { typeName: target.name },
|
|
5861
|
+
target: target,
|
|
5862
|
+
}));
|
|
5863
|
+
}
|
|
5864
|
+
return undefined;
|
|
5865
|
+
}
|
|
5866
|
+
const baseType = getTypeForNode(extendsRef, ctx);
|
|
5867
|
+
if (isErrorType(baseType)) {
|
|
5868
|
+
// Should already have reported an error when resolving the expression.
|
|
5869
|
+
return undefined;
|
|
5870
|
+
}
|
|
5871
|
+
// `extends` accepts an arbitrary expression so, unlike `model`/`scalar`, the union can
|
|
5872
|
+
// also reference itself through a union expression (e.g. `union a extends a | string` or
|
|
5873
|
+
// `union a extends b` with `alias b = a | string`). Those don't go through a symbol that
|
|
5874
|
+
// `pendingResolutions` can observe so they are detected on the resolved type instead.
|
|
5875
|
+
if (unionExpressionReferences(baseType, unionType)) {
|
|
5876
|
+
if (ctx.mapper === undefined) {
|
|
5877
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
5878
|
+
code: "circular-base-type",
|
|
5879
|
+
format: { typeName: union.id.sv },
|
|
5880
|
+
target: extendsRef,
|
|
5881
|
+
}));
|
|
5882
|
+
}
|
|
5883
|
+
return undefined;
|
|
5884
|
+
}
|
|
5885
|
+
if (ctx.hasFlags(CheckFlags.InTemplateDeclaration) &&
|
|
5886
|
+
(baseType.kind === "TemplateParameter" || baseType.kind === "TemplateParameterAccess")) {
|
|
5887
|
+
return undefined;
|
|
5888
|
+
}
|
|
5889
|
+
if (baseType.kind === "Model" && baseType.node?.kind === SyntaxKind.ModelExpression) {
|
|
5890
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
5891
|
+
code: "extend-union",
|
|
5892
|
+
messageId: "modelExpression",
|
|
5893
|
+
target: extendsRef,
|
|
5894
|
+
}));
|
|
5895
|
+
return undefined;
|
|
5896
|
+
}
|
|
5897
|
+
if (!isUnionBaseType(baseType)) {
|
|
5898
|
+
reportCheckerDiagnostic(createDiagnostic({ code: "extend-union", target: extendsRef }));
|
|
5899
|
+
return undefined;
|
|
5900
|
+
}
|
|
5901
|
+
return baseType;
|
|
5902
|
+
}
|
|
5903
|
+
finally {
|
|
5904
|
+
pendingResolutions.finish(unionSymId, ResolutionKind.BaseType);
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
function isUnionBaseType(type) {
|
|
5908
|
+
return (type.kind === "Model" ||
|
|
5909
|
+
type.kind === "Scalar" ||
|
|
5910
|
+
type.kind === "Enum" ||
|
|
5911
|
+
type.kind === "Union");
|
|
5912
|
+
}
|
|
5913
|
+
/**
|
|
5914
|
+
* Check whether `target` is reachable from `type` through union expressions only.
|
|
5915
|
+
*
|
|
5916
|
+
* Traversal deliberately stops at anything else (named unions, models, arrays, ...): a union
|
|
5917
|
+
* referencing itself from those positions builds a perfectly valid cyclic type graph, exactly
|
|
5918
|
+
* like `model Foo { foo: Foo }` does, and must not be reported. Only union expressions are
|
|
5919
|
+
* followed, which is a finite syntactic structure, so this always terminates.
|
|
5920
|
+
*/
|
|
5921
|
+
function unionExpressionReferences(type, target) {
|
|
5922
|
+
if (type === target) {
|
|
5923
|
+
return true;
|
|
5924
|
+
}
|
|
5925
|
+
if (type.kind === "Union" && type.expression) {
|
|
5926
|
+
for (const variant of type.variants.values()) {
|
|
5927
|
+
if (unionExpressionReferences(variant.type, target)) {
|
|
5928
|
+
return true;
|
|
5929
|
+
}
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5932
|
+
return false;
|
|
5933
|
+
}
|
|
5817
5934
|
function checkUnionVariant(ctx, variantNode) {
|
|
5818
5935
|
const links = getSymbolLinksForMember(variantNode);
|
|
5819
5936
|
if (links && links.declaredType && ctx.mapper === undefined) {
|