@typespec/compiler 0.54.0-dev.18 → 0.54.0-dev.20
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 +85 -24
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/messages.d.ts +20 -2
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +6 -0
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/projector.d.ts.map +1 -1
- package/dist/src/core/projector.js +3 -2
- package/dist/src/core/projector.js.map +1 -1
- package/package.json +1 -1
package/dist/manifest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../src/core/checker.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAS5B,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,EAEnB,gBAAgB,EAChB,WAAW,EACX,WAAW,EAOX,KAAK,EAGL,aAAa,
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../src/core/checker.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAS5B,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,EAEnB,gBAAgB,EAChB,WAAW,EACX,WAAW,EAOX,KAAK,EAGL,aAAa,EAIb,SAAS,EACT,s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ateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _PendingResolutions_data;
|
|
7
|
-
import { $docFromComment, getIndexer } from "../lib/decorators.js";
|
|
7
|
+
import { $docFromComment, getIndexer, isArrayModelType } from "../lib/decorators.js";
|
|
8
8
|
import { MultiKeyMap, createRekeyableMap, isArray, mutate } from "../utils/misc.js";
|
|
9
9
|
import { createSymbol, createSymbolTable } from "./binder.js";
|
|
10
10
|
import { getDeprecationDetails, markDeprecated } from "./deprecation.js";
|
|
@@ -1045,14 +1045,18 @@ export function createChecker(program) {
|
|
|
1045
1045
|
derivedModels: [],
|
|
1046
1046
|
});
|
|
1047
1047
|
const indexers = [];
|
|
1048
|
-
|
|
1048
|
+
const modelOptions = options.filter((entry) => {
|
|
1049
|
+
const [optionNode, option] = entry;
|
|
1049
1050
|
if (option.kind === "TemplateParameter") {
|
|
1050
|
-
|
|
1051
|
+
return false;
|
|
1051
1052
|
}
|
|
1052
1053
|
if (option.kind !== "Model") {
|
|
1053
1054
|
reportCheckerDiagnostic(createDiagnostic({ code: "intersect-non-model", target: optionNode }));
|
|
1054
|
-
|
|
1055
|
+
return false;
|
|
1055
1056
|
}
|
|
1057
|
+
return true;
|
|
1058
|
+
});
|
|
1059
|
+
for (const [optionNode, option] of modelOptions) {
|
|
1056
1060
|
if (option.indexer) {
|
|
1057
1061
|
if (option.indexer.key.name === "integer") {
|
|
1058
1062
|
reportCheckerDiagnostic(createDiagnostic({
|
|
@@ -1065,15 +1069,8 @@ export function createChecker(program) {
|
|
|
1065
1069
|
indexers.push(option.indexer);
|
|
1066
1070
|
}
|
|
1067
1071
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
}
|
|
1071
|
-
else if (indexers.length > 1) {
|
|
1072
|
-
intersection.indexer = {
|
|
1073
|
-
key: indexers[0].key,
|
|
1074
|
-
value: mergeModelTypes(node, indexers.map((x) => [x.value.node, x.value]), mapper),
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1072
|
+
}
|
|
1073
|
+
for (const [_, option] of modelOptions) {
|
|
1077
1074
|
const allProps = walkPropertiesInherited(option);
|
|
1078
1075
|
for (const prop of allProps) {
|
|
1079
1076
|
if (properties.has(prop.name)) {
|
|
@@ -1089,8 +1086,20 @@ export function createChecker(program) {
|
|
|
1089
1086
|
model: intersection,
|
|
1090
1087
|
});
|
|
1091
1088
|
properties.set(prop.name, newPropType);
|
|
1089
|
+
for (const indexer of indexers.filter((x) => x !== option.indexer)) {
|
|
1090
|
+
checkPropertyCompatibleWithIndexer(indexer, prop, node);
|
|
1091
|
+
}
|
|
1092
1092
|
}
|
|
1093
1093
|
}
|
|
1094
|
+
if (indexers.length === 1) {
|
|
1095
|
+
intersection.indexer = indexers[0];
|
|
1096
|
+
}
|
|
1097
|
+
else if (indexers.length > 1) {
|
|
1098
|
+
intersection.indexer = {
|
|
1099
|
+
key: indexers[0].key,
|
|
1100
|
+
value: mergeModelTypes(node, indexers.map((x) => [x.value.node, x.value]), mapper),
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1094
1103
|
linkMapper(intersection, mapper);
|
|
1095
1104
|
return finishType(intersection);
|
|
1096
1105
|
}
|
|
@@ -2054,11 +2063,14 @@ export function createChecker(program) {
|
|
|
2054
2063
|
}
|
|
2055
2064
|
return undefined;
|
|
2056
2065
|
}
|
|
2057
|
-
function
|
|
2066
|
+
function checkPropertyCompatibleWithModelIndexer(parentModel, property, diagnosticTarget) {
|
|
2058
2067
|
const indexer = findIndexer(parentModel);
|
|
2059
2068
|
if (indexer === undefined) {
|
|
2060
2069
|
return;
|
|
2061
2070
|
}
|
|
2071
|
+
return checkPropertyCompatibleWithIndexer(indexer, property, diagnosticTarget);
|
|
2072
|
+
}
|
|
2073
|
+
function checkPropertyCompatibleWithIndexer(indexer, property, diagnosticTarget) {
|
|
2062
2074
|
if (indexer.key.name === "integer") {
|
|
2063
2075
|
reportCheckerDiagnostics([
|
|
2064
2076
|
createDiagnostic({
|
|
@@ -2068,30 +2080,75 @@ export function createChecker(program) {
|
|
|
2068
2080
|
]);
|
|
2069
2081
|
return;
|
|
2070
2082
|
}
|
|
2071
|
-
const [valid, diagnostics] = isTypeAssignableTo(property.type, indexer.value, diagnosticTarget
|
|
2072
|
-
? diagnosticTarget
|
|
2073
|
-
: diagnosticTarget.value);
|
|
2083
|
+
const [valid, diagnostics] = isTypeAssignableTo(property.type, indexer.value, diagnosticTarget);
|
|
2074
2084
|
if (!valid)
|
|
2075
|
-
|
|
2085
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
2086
|
+
code: "incompatible-indexer",
|
|
2087
|
+
format: { message: diagnostics.map((x) => ` ${x.message}`).join("\n") },
|
|
2088
|
+
target: diagnosticTarget.kind === SyntaxKind.ModelProperty
|
|
2089
|
+
? diagnosticTarget.value
|
|
2090
|
+
: diagnosticTarget,
|
|
2091
|
+
}));
|
|
2076
2092
|
}
|
|
2077
2093
|
function checkModelProperties(node, properties, parentModel, mapper) {
|
|
2094
|
+
let spreadIndexers;
|
|
2078
2095
|
for (const prop of node.properties) {
|
|
2079
2096
|
if ("id" in prop) {
|
|
2080
2097
|
const newProp = checkModelProperty(prop, mapper);
|
|
2081
2098
|
newProp.model = parentModel;
|
|
2082
|
-
|
|
2099
|
+
checkPropertyCompatibleWithModelIndexer(parentModel, newProp, prop);
|
|
2083
2100
|
defineProperty(properties, newProp);
|
|
2084
2101
|
}
|
|
2085
2102
|
else {
|
|
2086
2103
|
// spread property
|
|
2087
|
-
const newProperties = checkSpreadProperty(node.symbol, prop.target, parentModel, mapper);
|
|
2104
|
+
const [newProperties, additionalIndexer] = checkSpreadProperty(node.symbol, prop.target, parentModel, mapper);
|
|
2105
|
+
if (additionalIndexer) {
|
|
2106
|
+
if (spreadIndexers) {
|
|
2107
|
+
spreadIndexers.push(additionalIndexer);
|
|
2108
|
+
}
|
|
2109
|
+
else {
|
|
2110
|
+
spreadIndexers = [additionalIndexer];
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2088
2113
|
for (const newProp of newProperties) {
|
|
2089
2114
|
linkIndirectMember(node, newProp, mapper);
|
|
2090
|
-
|
|
2115
|
+
checkPropertyCompatibleWithModelIndexer(parentModel, newProp, prop);
|
|
2091
2116
|
defineProperty(properties, newProp, prop);
|
|
2092
2117
|
}
|
|
2093
2118
|
}
|
|
2094
2119
|
}
|
|
2120
|
+
if (spreadIndexers) {
|
|
2121
|
+
const value = spreadIndexers.length === 1
|
|
2122
|
+
? spreadIndexers[0].value
|
|
2123
|
+
: createUnion(spreadIndexers.map((i) => i.value));
|
|
2124
|
+
parentModel.indexer = {
|
|
2125
|
+
key: spreadIndexers[0].key,
|
|
2126
|
+
value: value,
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
function createUnion(options) {
|
|
2131
|
+
const variants = createRekeyableMap();
|
|
2132
|
+
const union = createAndFinishType({
|
|
2133
|
+
kind: "Union",
|
|
2134
|
+
node: undefined,
|
|
2135
|
+
options,
|
|
2136
|
+
decorators: [],
|
|
2137
|
+
variants,
|
|
2138
|
+
expression: true,
|
|
2139
|
+
});
|
|
2140
|
+
for (const option of options) {
|
|
2141
|
+
const name = Symbol("indexer-union-variant");
|
|
2142
|
+
variants.set(name, createAndFinishType({
|
|
2143
|
+
kind: "UnionVariant",
|
|
2144
|
+
node: undefined,
|
|
2145
|
+
type: option,
|
|
2146
|
+
name,
|
|
2147
|
+
union,
|
|
2148
|
+
decorators: [],
|
|
2149
|
+
}));
|
|
2150
|
+
}
|
|
2151
|
+
return union;
|
|
2095
2152
|
}
|
|
2096
2153
|
function defineProperty(properties, newProp, diagnosticTarget) {
|
|
2097
2154
|
if (properties.has(newProp.name)) {
|
|
@@ -2459,11 +2516,15 @@ export function createChecker(program) {
|
|
|
2459
2516
|
function checkSpreadProperty(parentModelSym, targetNode, parentModel, mapper) {
|
|
2460
2517
|
const targetType = getTypeForNode(targetNode, mapper);
|
|
2461
2518
|
if (targetType.kind === "TemplateParameter" || isErrorType(targetType)) {
|
|
2462
|
-
return [];
|
|
2519
|
+
return [[], undefined];
|
|
2463
2520
|
}
|
|
2464
2521
|
if (targetType.kind !== "Model") {
|
|
2465
2522
|
reportCheckerDiagnostic(createDiagnostic({ code: "spread-model", target: targetNode }));
|
|
2466
|
-
return [];
|
|
2523
|
+
return [[], undefined];
|
|
2524
|
+
}
|
|
2525
|
+
if (isArrayModelType(program, targetType)) {
|
|
2526
|
+
reportCheckerDiagnostic(createDiagnostic({ code: "spread-model", target: targetNode }));
|
|
2527
|
+
return [[], undefined];
|
|
2467
2528
|
}
|
|
2468
2529
|
if (parentModel === targetType) {
|
|
2469
2530
|
reportCheckerDiagnostic(createDiagnostic({
|
|
@@ -2481,7 +2542,7 @@ export function createChecker(program) {
|
|
|
2481
2542
|
model: parentModel,
|
|
2482
2543
|
}));
|
|
2483
2544
|
}
|
|
2484
|
-
return props;
|
|
2545
|
+
return [props, targetType.indexer];
|
|
2485
2546
|
}
|
|
2486
2547
|
/**
|
|
2487
2548
|
* Link an indirect model property(included via spread or model is) to its model member symbols.
|