@typespec/compiler 0.67.0-dev.10 → 0.67.0-dev.12
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/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +17 -130
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts +3 -8
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +30 -674
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/cli.js +8 -2
- package/dist/src/core/cli/cli.js.map +1 -1
- package/dist/src/core/decorator-utils.d.ts.map +1 -1
- package/dist/src/core/decorator-utils.js +1 -3
- package/dist/src/core/decorator-utils.js.map +1 -1
- package/dist/src/core/diagnostic-error.d.ts +7 -0
- package/dist/src/core/diagnostic-error.d.ts.map +1 -0
- package/dist/src/core/diagnostic-error.js +9 -0
- package/dist/src/core/diagnostic-error.js.map +1 -0
- package/dist/src/core/diagnostics.d.ts +0 -6
- package/dist/src/core/diagnostics.d.ts.map +1 -1
- package/dist/src/core/diagnostics.js +2 -11
- package/dist/src/core/diagnostics.js.map +1 -1
- package/dist/src/core/inspector/symbol.d.ts.map +1 -1
- package/dist/src/core/inspector/symbol.js +9 -11
- package/dist/src/core/inspector/symbol.js.map +1 -1
- package/dist/src/core/messages.d.ts +20 -40
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +6 -10
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/name-resolver.d.ts.map +1 -1
- package/dist/src/core/name-resolver.js +12 -23
- package/dist/src/core/name-resolver.js.map +1 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +0 -642
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.d.ts +1 -10
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +2 -7
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/semantic-walker.d.ts.map +1 -1
- package/dist/src/core/semantic-walker.js +0 -9
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/state-accessors.d.ts +53 -12
- package/dist/src/core/state-accessors.d.ts.map +1 -1
- package/dist/src/core/state-accessors.js +75 -48
- package/dist/src/core/state-accessors.js.map +1 -1
- package/dist/src/core/type-relation-checker.d.ts.map +1 -1
- package/dist/src/core/type-relation-checker.js +3 -6
- package/dist/src/core/type-relation-checker.js.map +1 -1
- package/dist/src/core/type-utils.js +2 -2
- package/dist/src/core/type-utils.js.map +1 -1
- package/dist/src/core/types.d.ts +41 -274
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +24 -55
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/core/visibility/lifecycle.d.ts.map +1 -1
- package/dist/src/core/visibility/lifecycle.js +2 -11
- package/dist/src/core/visibility/lifecycle.js.map +1 -1
- package/dist/src/experimental/freeze-graph.d.ts.map +1 -1
- package/dist/src/experimental/freeze-graph.js +0 -3
- package/dist/src/experimental/freeze-graph.js.map +1 -1
- package/dist/src/experimental/mutators.d.ts +2 -2
- package/dist/src/experimental/mutators.d.ts.map +1 -1
- package/dist/src/experimental/mutators.js +0 -6
- package/dist/src/experimental/mutators.js.map +1 -1
- package/dist/src/experimental/typekit/kits/type.js +0 -3
- package/dist/src/experimental/typekit/kits/type.js.map +1 -1
- package/dist/src/formatter/print/needs-parens.d.ts.map +1 -1
- package/dist/src/formatter/print/needs-parens.js +0 -4
- package/dist/src/formatter/print/needs-parens.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts +4 -12
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +0 -187
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/index.d.ts +3 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/init.d.ts.map +1 -1
- package/dist/src/init/init.js +6 -2
- package/dist/src/init/init.js.map +1 -1
- package/dist/src/install/config.d.ts +9 -0
- package/dist/src/install/config.d.ts.map +1 -0
- package/dist/src/install/config.js +16 -0
- package/dist/src/install/config.js.map +1 -0
- package/dist/src/install/install.d.ts +14 -0
- package/dist/src/install/install.d.ts.map +1 -0
- package/dist/src/install/install.js +159 -0
- package/dist/src/install/install.js.map +1 -0
- package/dist/src/install/spec.d.ts +39 -0
- package/dist/src/install/spec.d.ts.map +1 -0
- package/dist/src/install/spec.js +152 -0
- package/dist/src/install/spec.js.map +1 -0
- package/dist/src/lib/decorators.d.ts +3 -3
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +14 -29
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/examples.js +1 -5
- package/dist/src/lib/examples.js.map +1 -1
- package/dist/src/lib/tsp-index.d.ts.map +1 -1
- package/dist/src/lib/tsp-index.js +0 -1
- package/dist/src/lib/tsp-index.js.map +1 -1
- package/dist/src/package-manger/npm-registry-utils.d.ts +83 -0
- package/dist/src/package-manger/npm-registry-utils.d.ts.map +1 -0
- package/dist/src/package-manger/npm-registry-utils.js +42 -0
- package/dist/src/package-manger/npm-registry-utils.js.map +1 -0
- package/dist/src/server/classify.d.ts.map +1 -1
- package/dist/src/server/classify.js +0 -26
- package/dist/src/server/classify.js.map +1 -1
- package/dist/src/server/completion.js +1 -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 +0 -125
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/src/server/type-signature.js +0 -11
- package/dist/src/server/type-signature.js.map +1 -1
- package/dist/src/types/package-json.d.ts +14 -0
- package/dist/src/types/package-json.d.ts.map +1 -1
- package/dist/src/utils/fs-utils.d.ts +3 -0
- package/dist/src/utils/fs-utils.d.ts.map +1 -0
- package/dist/src/utils/fs-utils.js +19 -0
- package/dist/src/utils/fs-utils.js.map +1 -0
- package/dist/typespec.tmLanguage +0 -342
- package/package.json +3 -3
- package/dist/src/core/helpers/projected-names-utils.d.ts +0 -20
- package/dist/src/core/helpers/projected-names-utils.d.ts.map +0 -1
- package/dist/src/core/helpers/projected-names-utils.js +0 -42
- package/dist/src/core/helpers/projected-names-utils.js.map +0 -1
- package/dist/src/core/install.d.ts +0 -3
- package/dist/src/core/install.d.ts.map +0 -1
- package/dist/src/core/install.js +0 -60
- package/dist/src/core/install.js.map +0 -1
- package/dist/src/core/projected-program.d.ts +0 -3
- package/dist/src/core/projected-program.d.ts.map +0 -1
- package/dist/src/core/projected-program.js +0 -4
- package/dist/src/core/projected-program.js.map +0 -1
- package/dist/src/core/projection-members.d.ts +0 -8
- package/dist/src/core/projection-members.d.ts.map +0 -1
- package/dist/src/core/projection-members.js +0 -382
- package/dist/src/core/projection-members.js.map +0 -1
- package/dist/src/core/projector.d.ts +0 -26
- package/dist/src/core/projector.d.ts.map +0 -1
- package/dist/src/core/projector.js +0 -572
- package/dist/src/core/projector.js.map +0 -1
package/dist/src/core/checker.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
1
|
import { Realm } from "../experimental/realm.js";
|
|
3
2
|
import { $ } from "../experimental/typekit/index.js";
|
|
4
3
|
import { docFromCommentDecorator, getIndexer } from "../lib/intrinsic/decorators.js";
|
|
@@ -8,7 +7,7 @@ import { createSymbol, getSymNode } from "./binder.js";
|
|
|
8
7
|
import { createChangeIdentifierCodeFix } from "./compiler-code-fixes/change-identifier.codefix.js";
|
|
9
8
|
import { createModelToObjectValueCodeFix, createTupleToArrayValueCodeFix, } from "./compiler-code-fixes/convert-to-value.codefix.js";
|
|
10
9
|
import { getDeprecationDetails, markDeprecated } from "./deprecation.js";
|
|
11
|
-
import {
|
|
10
|
+
import { compilerAssert, ignoreDiagnostics } from "./diagnostics.js";
|
|
12
11
|
import { validateInheritanceDiscriminatedUnions } from "./helpers/discriminator-utils.js";
|
|
13
12
|
import { getLocationContext } from "./helpers/location-context.js";
|
|
14
13
|
import { explainStringTemplateNotSerializable } from "./helpers/string-template-utils.js";
|
|
@@ -18,7 +17,6 @@ import { legacyMarshallTypeForJS, marshallTypeForJS } from "./js-marshaller.js";
|
|
|
18
17
|
import { createDiagnostic } from "./messages.js";
|
|
19
18
|
import { Numeric } from "./numeric.js";
|
|
20
19
|
import { exprIsBareIdentifier, getFirstAncestor, getIdentifierContext, hasParseError, visitChildren, } from "./parser.js";
|
|
21
|
-
import { createProjectionMembers } from "./projection-members.js";
|
|
22
20
|
import { createTypeRelationChecker } from "./type-relation-checker.js";
|
|
23
21
|
import { getFullyQualifiedSymbolName, getParentTemplateNode, isArrayModelType, isErrorType, isNullType, isTemplateInstance, isType, isValue, } from "./type-utils.js";
|
|
24
22
|
import { IdentifierKind, ResolutionResultFlags, SyntaxKind, } from "./types.js";
|
|
@@ -36,14 +34,7 @@ export function createChecker(program, resolver) {
|
|
|
36
34
|
let onCheckerDiagnostic = (x) => {
|
|
37
35
|
program.reportDiagnostic(x);
|
|
38
36
|
};
|
|
39
|
-
const typePrototype = {
|
|
40
|
-
get projections() {
|
|
41
|
-
return (projectionsByTypeKind.get(this.kind) || []).concat(projectionsByType.get(this) || []);
|
|
42
|
-
},
|
|
43
|
-
projectionsByName(name) {
|
|
44
|
-
return this.projections.filter((p) => p.id.sv === name);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
37
|
+
const typePrototype = {};
|
|
47
38
|
const globalNamespaceType = createGlobalNamespaceType();
|
|
48
39
|
// Caches the deprecation test of nodes in the program
|
|
49
40
|
const nodeDeprecationMap = new Map();
|
|
@@ -52,23 +43,6 @@ export function createChecker(program, resolver) {
|
|
|
52
43
|
const neverType = createType({ kind: "Intrinsic", name: "never" });
|
|
53
44
|
const unknownType = createType({ kind: "Intrinsic", name: "unknown" });
|
|
54
45
|
const nullType = createType({ kind: "Intrinsic", name: "null" });
|
|
55
|
-
const projectionsByTypeKind = new Map([
|
|
56
|
-
["Model", []],
|
|
57
|
-
["ModelProperty", []],
|
|
58
|
-
["Scalar", []],
|
|
59
|
-
["Union", []],
|
|
60
|
-
["UnionVariant", []],
|
|
61
|
-
["Operation", []],
|
|
62
|
-
["Interface", []],
|
|
63
|
-
["Enum", []],
|
|
64
|
-
["EnumMember", []],
|
|
65
|
-
]);
|
|
66
|
-
const projectionsByType = new Map();
|
|
67
|
-
// whether we've checked this specific projection statement before
|
|
68
|
-
// and added it to the various projection maps.
|
|
69
|
-
const processedProjections = new Set();
|
|
70
|
-
// interpreter state
|
|
71
|
-
let currentProjectionDirection;
|
|
72
46
|
/**
|
|
73
47
|
* Set keeping track of node pending type resolution.
|
|
74
48
|
* Key is the SymId of a node. It can be retrieved with getNodeSymId(node)
|
|
@@ -78,7 +52,6 @@ export function createChecker(program, resolver) {
|
|
|
78
52
|
if (typespecNamespaceBinding) {
|
|
79
53
|
initializeTypeSpecIntrinsics();
|
|
80
54
|
}
|
|
81
|
-
let evalContext = undefined;
|
|
82
55
|
/**
|
|
83
56
|
* Tracking the template parameters used or not.
|
|
84
57
|
*/
|
|
@@ -92,8 +65,6 @@ export function createChecker(program, resolver) {
|
|
|
92
65
|
cloneType,
|
|
93
66
|
resolveRelatedSymbols,
|
|
94
67
|
resolveCompletions,
|
|
95
|
-
evalProjection,
|
|
96
|
-
project,
|
|
97
68
|
neverType,
|
|
98
69
|
errorType,
|
|
99
70
|
nullType,
|
|
@@ -102,7 +73,6 @@ export function createChecker(program, resolver) {
|
|
|
102
73
|
typePrototype,
|
|
103
74
|
createType,
|
|
104
75
|
createAndFinishType,
|
|
105
|
-
createFunctionType,
|
|
106
76
|
createLiteralType,
|
|
107
77
|
finishType,
|
|
108
78
|
isStdType,
|
|
@@ -116,7 +86,6 @@ export function createChecker(program, resolver) {
|
|
|
116
86
|
};
|
|
117
87
|
const relation = createTypeRelationChecker(program, checker);
|
|
118
88
|
checker.isTypeAssignableTo = relation.isTypeAssignableTo;
|
|
119
|
-
const projectionMembers = createProjectionMembers(checker);
|
|
120
89
|
return checker;
|
|
121
90
|
function getTemplateParameterUsageMap() {
|
|
122
91
|
return templateParameterUsageMap;
|
|
@@ -141,10 +110,10 @@ export function createChecker(program, resolver) {
|
|
|
141
110
|
function initializeTypeSpecIntrinsics() {
|
|
142
111
|
// a utility function to log strings or numbers
|
|
143
112
|
mutate(typespecNamespaceBinding.exports).set("log", {
|
|
144
|
-
flags:
|
|
113
|
+
flags: 2048 /* SymbolFlags.Function */,
|
|
145
114
|
name: "log",
|
|
146
115
|
value(p, ...strs) {
|
|
147
|
-
program.trace("
|
|
116
|
+
program.trace("log", strs.join(" "));
|
|
148
117
|
return voidType;
|
|
149
118
|
},
|
|
150
119
|
declarations: [],
|
|
@@ -543,8 +512,6 @@ export function createChecker(program, resolver) {
|
|
|
543
512
|
return checkTemplateArgument(node, mapper);
|
|
544
513
|
case SyntaxKind.TemplateParameterDeclaration:
|
|
545
514
|
return checkTemplateParameterDeclaration(node, mapper);
|
|
546
|
-
case SyntaxKind.ProjectionStatement:
|
|
547
|
-
return checkProjectionDeclaration(node);
|
|
548
515
|
case SyntaxKind.VoidKeyword:
|
|
549
516
|
return voidType;
|
|
550
517
|
case SyntaxKind.NeverKeyword:
|
|
@@ -583,9 +550,7 @@ export function createChecker(program, resolver) {
|
|
|
583
550
|
* Check if the given namespace is the standard library `TypeSpec` namespace.
|
|
584
551
|
*/
|
|
585
552
|
function isTypeSpecNamespace(namespace) {
|
|
586
|
-
return
|
|
587
|
-
(namespace.namespace === globalNamespaceType ||
|
|
588
|
-
namespace.namespace?.projectionBase === globalNamespaceType));
|
|
553
|
+
return namespace.name === "TypeSpec" && namespace.namespace === globalNamespaceType;
|
|
589
554
|
}
|
|
590
555
|
/**
|
|
591
556
|
* Check if the given type is defined right in the TypeSpec namespace.
|
|
@@ -934,14 +899,14 @@ export function createChecker(program, resolver) {
|
|
|
934
899
|
return entity;
|
|
935
900
|
}
|
|
936
901
|
function checkTypeOrValueReferenceSymbolWorker(sym, node, mapper, instantiateTemplates = true) {
|
|
937
|
-
if (sym.flags &
|
|
902
|
+
if (sym.flags & 131072 /* SymbolFlags.Const */) {
|
|
938
903
|
return getValueForNode(sym.declarations[0], mapper);
|
|
939
904
|
}
|
|
940
|
-
if (sym.flags &
|
|
905
|
+
if (sym.flags & 512 /* SymbolFlags.Decorator */) {
|
|
941
906
|
reportCheckerDiagnostic(createDiagnostic({ code: "invalid-type-ref", messageId: "decorator", target: sym }));
|
|
942
907
|
return errorType;
|
|
943
908
|
}
|
|
944
|
-
if (sym.flags &
|
|
909
|
+
if (sym.flags & 2048 /* SymbolFlags.Function */) {
|
|
945
910
|
reportCheckerDiagnostic(createDiagnostic({ code: "invalid-type-ref", messageId: "function", target: sym }));
|
|
946
911
|
return errorType;
|
|
947
912
|
}
|
|
@@ -972,7 +937,7 @@ export function createChecker(program, resolver) {
|
|
|
972
937
|
else if (symbolLinks.declaredType) {
|
|
973
938
|
baseType = symbolLinks.declaredType;
|
|
974
939
|
}
|
|
975
|
-
else if (sym.flags &
|
|
940
|
+
else if (sym.flags & 65536 /* SymbolFlags.Member */) {
|
|
976
941
|
baseType = checkMemberSym(sym, mapper);
|
|
977
942
|
}
|
|
978
943
|
else {
|
|
@@ -1000,7 +965,7 @@ export function createChecker(program, resolver) {
|
|
|
1000
965
|
compilerAssert(sym.type, `Expected late bound symbol to have type`);
|
|
1001
966
|
return sym.type;
|
|
1002
967
|
}
|
|
1003
|
-
else if (sym.flags &
|
|
968
|
+
else if (sym.flags & 1024 /* SymbolFlags.TemplateParameter */) {
|
|
1004
969
|
const mapped = checkTemplateParameterDeclaration(symNode, mapper);
|
|
1005
970
|
baseType = mapped;
|
|
1006
971
|
}
|
|
@@ -1012,7 +977,7 @@ export function createChecker(program, resolver) {
|
|
|
1012
977
|
baseType = symbolLinks.declaredType;
|
|
1013
978
|
}
|
|
1014
979
|
else {
|
|
1015
|
-
if (sym.flags &
|
|
980
|
+
if (sym.flags & 65536 /* SymbolFlags.Member */) {
|
|
1016
981
|
baseType = checkMemberSym(sym, mapper);
|
|
1017
982
|
}
|
|
1018
983
|
else {
|
|
@@ -1054,7 +1019,7 @@ export function createChecker(program, resolver) {
|
|
|
1054
1019
|
compilerAssert(sym.type, "Expected late bound symbol to have type");
|
|
1055
1020
|
return sym.type;
|
|
1056
1021
|
}
|
|
1057
|
-
if (sym.flags &
|
|
1022
|
+
if (sym.flags & 65536 /* SymbolFlags.Member */) {
|
|
1058
1023
|
return checkMemberSym(sym, mapper);
|
|
1059
1024
|
}
|
|
1060
1025
|
else {
|
|
@@ -1266,34 +1231,8 @@ export function createChecker(program, resolver) {
|
|
|
1266
1231
|
return decoratorType;
|
|
1267
1232
|
}
|
|
1268
1233
|
function checkFunctionDeclaration(node, mapper) {
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
if (links.declaredType && mapper === undefined) {
|
|
1272
|
-
// we're not instantiating this operation and we've already checked it
|
|
1273
|
-
return links.declaredType;
|
|
1274
|
-
}
|
|
1275
|
-
const namespace = getParentNamespaceType(node);
|
|
1276
|
-
compilerAssert(namespace, `Decorator ${node.id.sv} should have resolved a namespace or found the global namespace.`);
|
|
1277
|
-
const name = node.id.sv;
|
|
1278
|
-
if (!(node.modifierFlags & 2 /* ModifierFlags.Extern */)) {
|
|
1279
|
-
reportCheckerDiagnostic(createDiagnostic({ code: "function-extern", target: node }));
|
|
1280
|
-
}
|
|
1281
|
-
const implementation = symbol.value;
|
|
1282
|
-
if (implementation === undefined) {
|
|
1283
|
-
reportCheckerDiagnostic(createDiagnostic({ code: "missing-implementation", target: node }));
|
|
1284
|
-
}
|
|
1285
|
-
const functionType = createType({
|
|
1286
|
-
kind: "Function",
|
|
1287
|
-
name,
|
|
1288
|
-
namespace,
|
|
1289
|
-
node,
|
|
1290
|
-
parameters: node.parameters.map((x) => checkFunctionParameter(x, mapper, true)),
|
|
1291
|
-
returnType: node.returnType ? getTypeForNode(node.returnType, mapper) : unknownType,
|
|
1292
|
-
implementation: implementation ?? (() => { }),
|
|
1293
|
-
});
|
|
1294
|
-
namespace.functionDeclarations.set(name, functionType);
|
|
1295
|
-
linkType(links, functionType, mapper);
|
|
1296
|
-
return functionType;
|
|
1234
|
+
reportCheckerDiagnostic(createDiagnostic({ code: "function-unsupported", target: node }));
|
|
1235
|
+
return errorType;
|
|
1297
1236
|
}
|
|
1298
1237
|
function checkFunctionParameter(node, mapper, mixed) {
|
|
1299
1238
|
const links = getSymbolLinks(node.symbol);
|
|
@@ -2118,10 +2057,10 @@ export function createChecker(program, resolver) {
|
|
|
2118
2057
|
}
|
|
2119
2058
|
table = resolver.getAugmentedSymbolTable(table);
|
|
2120
2059
|
for (const [key, sym] of table) {
|
|
2121
|
-
if (sym.flags &
|
|
2060
|
+
if (sym.flags & 16384 /* SymbolFlags.DuplicateUsing */) {
|
|
2122
2061
|
const duplicates = table.duplicates.get(sym);
|
|
2123
2062
|
for (const duplicate of duplicates) {
|
|
2124
|
-
if (duplicate.flags &
|
|
2063
|
+
if (duplicate.flags & 8192 /* SymbolFlags.Using */) {
|
|
2125
2064
|
const fqn = getFullyQualifiedSymbolName(duplicate.symbolSource);
|
|
2126
2065
|
addCompletion(fqn, duplicate);
|
|
2127
2066
|
}
|
|
@@ -2151,18 +2090,18 @@ export function createChecker(program, resolver) {
|
|
|
2151
2090
|
case IdentifierKind.ModelExpressionProperty:
|
|
2152
2091
|
case IdentifierKind.ModelStatementProperty:
|
|
2153
2092
|
case IdentifierKind.ObjectLiteralProperty:
|
|
2154
|
-
return !!(sym.flags &
|
|
2093
|
+
return !!(sym.flags & 65536 /* SymbolFlags.Member */);
|
|
2155
2094
|
case IdentifierKind.Decorator:
|
|
2156
2095
|
// Only return decorators and namespaces when completing decorator
|
|
2157
|
-
return !!(sym.flags & (
|
|
2096
|
+
return !!(sym.flags & (512 /* SymbolFlags.Decorator */ | 256 /* SymbolFlags.Namespace */));
|
|
2158
2097
|
case IdentifierKind.Using:
|
|
2159
2098
|
// Only return namespaces when completing using
|
|
2160
2099
|
return !!(sym.flags & 256 /* SymbolFlags.Namespace */);
|
|
2161
2100
|
case IdentifierKind.TypeReference:
|
|
2162
2101
|
// Do not return functions or decorators when completing types
|
|
2163
|
-
return !(sym.flags & (
|
|
2102
|
+
return !(sym.flags & (2048 /* SymbolFlags.Function */ | 512 /* SymbolFlags.Decorator */));
|
|
2164
2103
|
case IdentifierKind.TemplateArgument:
|
|
2165
|
-
return !!(sym.flags &
|
|
2104
|
+
return !!(sym.flags & 1024 /* SymbolFlags.TemplateParameter */);
|
|
2166
2105
|
default:
|
|
2167
2106
|
compilerAssert(false, "We should have bailed up-front on other kinds.");
|
|
2168
2107
|
}
|
|
@@ -2274,7 +2213,7 @@ export function createChecker(program, resolver) {
|
|
|
2274
2213
|
target: node,
|
|
2275
2214
|
}));
|
|
2276
2215
|
}
|
|
2277
|
-
else if (base.flags &
|
|
2216
|
+
else if (base.flags & 512 /* SymbolFlags.Decorator */) {
|
|
2278
2217
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2279
2218
|
code: "invalid-ref",
|
|
2280
2219
|
messageId: "inDecorator",
|
|
@@ -2282,7 +2221,7 @@ export function createChecker(program, resolver) {
|
|
|
2282
2221
|
target: node,
|
|
2283
2222
|
}));
|
|
2284
2223
|
}
|
|
2285
|
-
else if (base.flags &
|
|
2224
|
+
else if (base.flags & 2048 /* SymbolFlags.Function */) {
|
|
2286
2225
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2287
2226
|
code: "invalid-ref",
|
|
2288
2227
|
messageId: "node",
|
|
@@ -3301,27 +3240,27 @@ export function createChecker(program, resolver) {
|
|
|
3301
3240
|
switch (type.kind) {
|
|
3302
3241
|
case "Model":
|
|
3303
3242
|
for (const prop of walkPropertiesInherited(type)) {
|
|
3304
|
-
lateBindMember(prop,
|
|
3243
|
+
lateBindMember(prop, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3305
3244
|
}
|
|
3306
3245
|
break;
|
|
3307
3246
|
case "Scalar":
|
|
3308
3247
|
for (const member of type.constructors.values()) {
|
|
3309
|
-
lateBindMember(member,
|
|
3248
|
+
lateBindMember(member, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3310
3249
|
}
|
|
3311
3250
|
break;
|
|
3312
3251
|
case "Enum":
|
|
3313
3252
|
for (const member of type.members.values()) {
|
|
3314
|
-
lateBindMember(member,
|
|
3253
|
+
lateBindMember(member, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3315
3254
|
}
|
|
3316
3255
|
break;
|
|
3317
3256
|
case "Interface":
|
|
3318
3257
|
for (const member of type.operations.values()) {
|
|
3319
|
-
lateBindMember(member,
|
|
3258
|
+
lateBindMember(member, 65536 /* SymbolFlags.Member */ | 8 /* SymbolFlags.Operation */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3320
3259
|
}
|
|
3321
3260
|
break;
|
|
3322
3261
|
case "Union":
|
|
3323
3262
|
for (const variant of type.variants.values()) {
|
|
3324
|
-
lateBindMember(variant,
|
|
3263
|
+
lateBindMember(variant, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3325
3264
|
}
|
|
3326
3265
|
break;
|
|
3327
3266
|
}
|
|
@@ -3567,7 +3506,7 @@ export function createChecker(program, resolver) {
|
|
|
3567
3506
|
// Error should already have been reported above
|
|
3568
3507
|
return undefined;
|
|
3569
3508
|
}
|
|
3570
|
-
if (!(sym.flags &
|
|
3509
|
+
if (!(sym.flags & 512 /* SymbolFlags.Decorator */)) {
|
|
3571
3510
|
reportCheckerDiagnostic(createDiagnostic({
|
|
3572
3511
|
code: "invalid-decorator",
|
|
3573
3512
|
format: { id: sym.name },
|
|
@@ -3819,7 +3758,7 @@ export function createChecker(program, resolver) {
|
|
|
3819
3758
|
}
|
|
3820
3759
|
else if (links.finalSymbol?.flags &&
|
|
3821
3760
|
~links.finalSymbol.flags & 1048576 /* SymbolFlags.Declaration */ &&
|
|
3822
|
-
~links.finalSymbol.flags &
|
|
3761
|
+
~links.finalSymbol.flags & 65536 /* SymbolFlags.Member */) {
|
|
3823
3762
|
program.reportDiagnostic(createDiagnostic({
|
|
3824
3763
|
code: "augment-decorator-target",
|
|
3825
3764
|
messageId: links.finalSymbol.flags & 2 /* SymbolFlags.Model */
|
|
@@ -4269,7 +4208,7 @@ export function createChecker(program, resolver) {
|
|
|
4269
4208
|
return variantType;
|
|
4270
4209
|
}
|
|
4271
4210
|
function isMemberNode(node) {
|
|
4272
|
-
return node.symbol && !!(node.symbol.flags &
|
|
4211
|
+
return node.symbol && !!(node.symbol.flags & 65536 /* SymbolFlags.Member */);
|
|
4273
4212
|
}
|
|
4274
4213
|
function getMemberSymbol(parentSym, name) {
|
|
4275
4214
|
return parentSym ? resolver.getAugmentedSymbolTable(parentSym.members).get(name) : undefined;
|
|
@@ -4383,8 +4322,6 @@ export function createChecker(program, resolver) {
|
|
|
4383
4322
|
}
|
|
4384
4323
|
/**
|
|
4385
4324
|
* Given the own-properties of a type, returns a fully-initialized type.
|
|
4386
|
-
* So far, that amounts to setting the prototype to typePrototype which
|
|
4387
|
-
* contains the `projections` getter.
|
|
4388
4325
|
*/
|
|
4389
4326
|
function createType(typeDef) {
|
|
4390
4327
|
Object.setPrototypeOf(typeDef, typePrototype);
|
|
@@ -4526,10 +4463,6 @@ export function createChecker(program, resolver) {
|
|
|
4526
4463
|
if (type.isFinished) {
|
|
4527
4464
|
clone = finishType(clone);
|
|
4528
4465
|
}
|
|
4529
|
-
const projection = projectionsByType.get(type);
|
|
4530
|
-
if (projection) {
|
|
4531
|
-
projectionsByType.set(clone, projection);
|
|
4532
|
-
}
|
|
4533
4466
|
compilerAssert(clone.kind === type.kind, "cloneType must not change type kind");
|
|
4534
4467
|
return clone;
|
|
4535
4468
|
}
|
|
@@ -4557,472 +4490,6 @@ export function createChecker(program, resolver) {
|
|
|
4557
4490
|
compilerAssert(clone.kind === type.kind, "cloneType must not change type kind");
|
|
4558
4491
|
return clone;
|
|
4559
4492
|
}
|
|
4560
|
-
function checkProjectionDeclaration(node) {
|
|
4561
|
-
// todo: check for duplicate projection decls on individual types
|
|
4562
|
-
// right now you can declare the same projection on a specific type
|
|
4563
|
-
// this could maybe go in the binder? But right now we don't know
|
|
4564
|
-
// what an identifier resolves to until check time.
|
|
4565
|
-
const links = getSymbolLinks(node.symbol);
|
|
4566
|
-
if (processedProjections.has(node)) {
|
|
4567
|
-
return links.declaredType;
|
|
4568
|
-
}
|
|
4569
|
-
processedProjections.add(node);
|
|
4570
|
-
reportCheckerDiagnostic(createDiagnostic({
|
|
4571
|
-
code: "deprecated",
|
|
4572
|
-
format: { message: "Projection are deprecated and will be removed in next version" },
|
|
4573
|
-
target: node,
|
|
4574
|
-
}));
|
|
4575
|
-
let type;
|
|
4576
|
-
if (links.declaredType) {
|
|
4577
|
-
type = links.declaredType;
|
|
4578
|
-
}
|
|
4579
|
-
else {
|
|
4580
|
-
type = links.declaredType = createType({
|
|
4581
|
-
kind: "Projection",
|
|
4582
|
-
node: undefined,
|
|
4583
|
-
nodeByKind: new Map(),
|
|
4584
|
-
nodeByType: new Map(),
|
|
4585
|
-
});
|
|
4586
|
-
}
|
|
4587
|
-
switch (node.selector.kind) {
|
|
4588
|
-
case SyntaxKind.ProjectionModelSelector:
|
|
4589
|
-
projectionsByTypeKind.get("Model").push(node);
|
|
4590
|
-
type.nodeByKind.set("Model", node);
|
|
4591
|
-
break;
|
|
4592
|
-
case SyntaxKind.ProjectionModelPropertySelector:
|
|
4593
|
-
projectionsByTypeKind.get("ModelProperty").push(node);
|
|
4594
|
-
type.nodeByKind.set("ModelProperty", node);
|
|
4595
|
-
break;
|
|
4596
|
-
case SyntaxKind.ProjectionScalarSelector:
|
|
4597
|
-
projectionsByTypeKind.get("Scalar").push(node);
|
|
4598
|
-
type.nodeByKind.set("Scalar", node);
|
|
4599
|
-
break;
|
|
4600
|
-
case SyntaxKind.ProjectionOperationSelector:
|
|
4601
|
-
projectionsByTypeKind.get("Operation").push(node);
|
|
4602
|
-
type.nodeByKind.set("Operation", node);
|
|
4603
|
-
break;
|
|
4604
|
-
case SyntaxKind.ProjectionUnionSelector:
|
|
4605
|
-
projectionsByTypeKind.get("Union").push(node);
|
|
4606
|
-
type.nodeByKind.set("Union", node);
|
|
4607
|
-
break;
|
|
4608
|
-
case SyntaxKind.ProjectionUnionVariantSelector:
|
|
4609
|
-
projectionsByTypeKind.get("UnionVariant").push(node);
|
|
4610
|
-
type.nodeByKind.set("UnionVariant", node);
|
|
4611
|
-
break;
|
|
4612
|
-
case SyntaxKind.ProjectionInterfaceSelector:
|
|
4613
|
-
projectionsByTypeKind.get("Interface").push(node);
|
|
4614
|
-
type.nodeByKind.set("Interface", node);
|
|
4615
|
-
break;
|
|
4616
|
-
case SyntaxKind.ProjectionEnumSelector:
|
|
4617
|
-
projectionsByTypeKind.get("Enum").push(node);
|
|
4618
|
-
type.nodeByKind.set("Enum", node);
|
|
4619
|
-
break;
|
|
4620
|
-
case SyntaxKind.ProjectionEnumMemberSelector:
|
|
4621
|
-
projectionsByTypeKind.get("EnumMember").push(node);
|
|
4622
|
-
type.nodeByKind.set("EnumMember", node);
|
|
4623
|
-
break;
|
|
4624
|
-
default:
|
|
4625
|
-
const projected = checkTypeReference(node.selector, undefined);
|
|
4626
|
-
let current = projectionsByType.get(projected);
|
|
4627
|
-
if (!current) {
|
|
4628
|
-
current = [];
|
|
4629
|
-
projectionsByType.set(projected, current);
|
|
4630
|
-
}
|
|
4631
|
-
current.push(node);
|
|
4632
|
-
type.nodeByType.set(projected, node);
|
|
4633
|
-
break;
|
|
4634
|
-
}
|
|
4635
|
-
return type;
|
|
4636
|
-
}
|
|
4637
|
-
function evalProjectionNode(node) {
|
|
4638
|
-
switch (node.kind) {
|
|
4639
|
-
case SyntaxKind.ProjectionExpressionStatement:
|
|
4640
|
-
return evalProjectionExpressionStatement(node);
|
|
4641
|
-
case SyntaxKind.ProjectionCallExpression:
|
|
4642
|
-
return evalProjectionCallExpression(node);
|
|
4643
|
-
case SyntaxKind.ProjectionMemberExpression:
|
|
4644
|
-
return evalProjectionMemberExpression(node);
|
|
4645
|
-
case SyntaxKind.ProjectionDecoratorReferenceExpression:
|
|
4646
|
-
return evalProjectionDecoratorReference(node);
|
|
4647
|
-
case SyntaxKind.Identifier:
|
|
4648
|
-
return evalProjectionIdentifier(node);
|
|
4649
|
-
case SyntaxKind.ProjectionLambdaExpression:
|
|
4650
|
-
return evalProjectionLambdaExpression(node);
|
|
4651
|
-
case SyntaxKind.StringLiteral:
|
|
4652
|
-
return evalStringLiteral(node);
|
|
4653
|
-
case SyntaxKind.NumericLiteral:
|
|
4654
|
-
return evalNumericLiteral(node);
|
|
4655
|
-
case SyntaxKind.BooleanLiteral:
|
|
4656
|
-
return evalBooleanLiteral(node);
|
|
4657
|
-
case SyntaxKind.ProjectionBlockExpression:
|
|
4658
|
-
return evalProjectionBlockExpression(node);
|
|
4659
|
-
case SyntaxKind.ProjectionArithmeticExpression:
|
|
4660
|
-
return evalProjectionArithmeticExpression(node);
|
|
4661
|
-
case SyntaxKind.ProjectionIfExpression:
|
|
4662
|
-
return evalProjectionIfExpression(node);
|
|
4663
|
-
case SyntaxKind.ProjectionEqualityExpression:
|
|
4664
|
-
return evalProjectionEqualityExpression(node);
|
|
4665
|
-
case SyntaxKind.ProjectionUnaryExpression:
|
|
4666
|
-
return evalProjectionUnaryExpression(node);
|
|
4667
|
-
case SyntaxKind.ProjectionRelationalExpression:
|
|
4668
|
-
return evalProjectionRelationalExpression(node);
|
|
4669
|
-
case SyntaxKind.ProjectionModelExpression:
|
|
4670
|
-
return evalProjectionModelExpression(node);
|
|
4671
|
-
case SyntaxKind.VoidKeyword:
|
|
4672
|
-
return voidType;
|
|
4673
|
-
case SyntaxKind.NeverKeyword:
|
|
4674
|
-
return neverType;
|
|
4675
|
-
case SyntaxKind.UnknownKeyword:
|
|
4676
|
-
return unknownType;
|
|
4677
|
-
case SyntaxKind.Return:
|
|
4678
|
-
return evalReturnKeyword(node);
|
|
4679
|
-
default:
|
|
4680
|
-
compilerAssert(false, `Can't eval the node ${SyntaxKind[node.kind]}`);
|
|
4681
|
-
}
|
|
4682
|
-
}
|
|
4683
|
-
function evalReturnKeyword(node) {
|
|
4684
|
-
const value = evalProjectionNode(node.value);
|
|
4685
|
-
if (value.kind === "Return") {
|
|
4686
|
-
return value;
|
|
4687
|
-
}
|
|
4688
|
-
return {
|
|
4689
|
-
kind: "Return",
|
|
4690
|
-
value,
|
|
4691
|
-
};
|
|
4692
|
-
}
|
|
4693
|
-
function evalProjectionModelExpression(node) {
|
|
4694
|
-
const modelType = createType({
|
|
4695
|
-
kind: "Model",
|
|
4696
|
-
name: "",
|
|
4697
|
-
node: node,
|
|
4698
|
-
decorators: [],
|
|
4699
|
-
properties: createRekeyableMap(),
|
|
4700
|
-
derivedModels: [],
|
|
4701
|
-
sourceModels: [],
|
|
4702
|
-
});
|
|
4703
|
-
for (const propNode of node.properties) {
|
|
4704
|
-
if (propNode.kind === SyntaxKind.ProjectionModelProperty) {
|
|
4705
|
-
const prop = evalProjectionModelProperty(propNode, modelType);
|
|
4706
|
-
if (prop.kind === "Return") {
|
|
4707
|
-
return prop;
|
|
4708
|
-
}
|
|
4709
|
-
modelType.properties.set(prop.name, prop);
|
|
4710
|
-
}
|
|
4711
|
-
else {
|
|
4712
|
-
const props = evalProjectionModelSpreadProperty(propNode);
|
|
4713
|
-
if (!Array.isArray(props)) {
|
|
4714
|
-
// return record
|
|
4715
|
-
return props;
|
|
4716
|
-
}
|
|
4717
|
-
for (const newProp of props) {
|
|
4718
|
-
modelType.properties.set(newProp.name, newProp);
|
|
4719
|
-
}
|
|
4720
|
-
}
|
|
4721
|
-
}
|
|
4722
|
-
return modelType;
|
|
4723
|
-
}
|
|
4724
|
-
function evalProjectionModelProperty(node, model) {
|
|
4725
|
-
const type = evalProjectionNode(node.value);
|
|
4726
|
-
if (type.kind === "Return") {
|
|
4727
|
-
return type;
|
|
4728
|
-
}
|
|
4729
|
-
return createType({
|
|
4730
|
-
kind: "ModelProperty",
|
|
4731
|
-
name: node.id.sv,
|
|
4732
|
-
node: node,
|
|
4733
|
-
decorators: [],
|
|
4734
|
-
optional: node.optional,
|
|
4735
|
-
type,
|
|
4736
|
-
model,
|
|
4737
|
-
});
|
|
4738
|
-
}
|
|
4739
|
-
function evalProjectionModelSpreadProperty(node) {
|
|
4740
|
-
const target = evalProjectionNode(node.target);
|
|
4741
|
-
if (target.kind === "Return") {
|
|
4742
|
-
return target;
|
|
4743
|
-
}
|
|
4744
|
-
if (target.kind !== "Model") {
|
|
4745
|
-
throw new ProjectionError(`Can only spread models`);
|
|
4746
|
-
}
|
|
4747
|
-
const props = [];
|
|
4748
|
-
// copy each property
|
|
4749
|
-
for (const prop of walkPropertiesInherited(target)) {
|
|
4750
|
-
const newProp = cloneType(prop, { sourceProperty: prop });
|
|
4751
|
-
props.push(newProp);
|
|
4752
|
-
}
|
|
4753
|
-
return props;
|
|
4754
|
-
}
|
|
4755
|
-
function evalProjectionRelationalExpression(node) {
|
|
4756
|
-
const left = evalProjectionNode(node.left);
|
|
4757
|
-
if (left.kind === "Return") {
|
|
4758
|
-
return left;
|
|
4759
|
-
}
|
|
4760
|
-
else if (left.kind !== "Number" && left.kind !== "String") {
|
|
4761
|
-
throw new ProjectionError("Can only compare numbers or strings");
|
|
4762
|
-
}
|
|
4763
|
-
const right = evalProjectionNode(node.right);
|
|
4764
|
-
if (right.kind === "Return") {
|
|
4765
|
-
return right;
|
|
4766
|
-
}
|
|
4767
|
-
else if (right.kind !== "Number" && right.kind !== "String") {
|
|
4768
|
-
throw new ProjectionError("Can only compare numbers or strings");
|
|
4769
|
-
}
|
|
4770
|
-
if (left.kind !== right.kind) {
|
|
4771
|
-
throw new ProjectionError("Can't compare numbers and strings");
|
|
4772
|
-
}
|
|
4773
|
-
switch (node.op) {
|
|
4774
|
-
case "<":
|
|
4775
|
-
return createLiteralType(left.value < right.value);
|
|
4776
|
-
case "<=":
|
|
4777
|
-
return createLiteralType(left.value <= right.value);
|
|
4778
|
-
case ">":
|
|
4779
|
-
return createLiteralType(left.value > right.value);
|
|
4780
|
-
case ">=":
|
|
4781
|
-
return createLiteralType(left.value >= right.value);
|
|
4782
|
-
}
|
|
4783
|
-
}
|
|
4784
|
-
function evalProjectionUnaryExpression(node) {
|
|
4785
|
-
const target = evalProjectionNode(node.target);
|
|
4786
|
-
if (target.kind !== "Boolean") {
|
|
4787
|
-
throw new ProjectionError("Can't negate a non-boolean");
|
|
4788
|
-
}
|
|
4789
|
-
switch (node.op) {
|
|
4790
|
-
case "!":
|
|
4791
|
-
return createLiteralType(!target.value);
|
|
4792
|
-
}
|
|
4793
|
-
}
|
|
4794
|
-
function evalProjectionEqualityExpression(node) {
|
|
4795
|
-
const left = evalProjectionNode(node.left);
|
|
4796
|
-
if (left.kind === "Return") {
|
|
4797
|
-
return left;
|
|
4798
|
-
}
|
|
4799
|
-
else if (left.kind !== "Number" && left.kind !== "String") {
|
|
4800
|
-
throw new ProjectionError("Comparisons must be strings or numbers");
|
|
4801
|
-
}
|
|
4802
|
-
const right = evalProjectionNode(node.right);
|
|
4803
|
-
if (right.kind === "Return") {
|
|
4804
|
-
return right;
|
|
4805
|
-
}
|
|
4806
|
-
else if (right.kind !== "Number" && right.kind !== "String") {
|
|
4807
|
-
throw new ProjectionError("Comparisons must be strings or numbers");
|
|
4808
|
-
}
|
|
4809
|
-
if (right.kind !== left.kind) {
|
|
4810
|
-
throw new ProjectionError("Can't compare number and string");
|
|
4811
|
-
}
|
|
4812
|
-
switch (node.op) {
|
|
4813
|
-
case "==":
|
|
4814
|
-
return createLiteralType(left.value === right.value);
|
|
4815
|
-
case "!=":
|
|
4816
|
-
return createLiteralType(left.value !== right.value);
|
|
4817
|
-
}
|
|
4818
|
-
}
|
|
4819
|
-
function evalProjectionIfExpression(node) {
|
|
4820
|
-
let ifExpr = node;
|
|
4821
|
-
while (ifExpr) {
|
|
4822
|
-
const test = evalProjectionNode(ifExpr.test);
|
|
4823
|
-
if (test.kind === "Return") {
|
|
4824
|
-
return test;
|
|
4825
|
-
}
|
|
4826
|
-
if (typeIsTruthy(test)) {
|
|
4827
|
-
return evalProjectionBlockExpression(ifExpr.consequent);
|
|
4828
|
-
}
|
|
4829
|
-
else if (ifExpr.alternate &&
|
|
4830
|
-
ifExpr.alternate.kind === SyntaxKind.ProjectionBlockExpression) {
|
|
4831
|
-
return evalProjectionBlockExpression(ifExpr.alternate);
|
|
4832
|
-
}
|
|
4833
|
-
else {
|
|
4834
|
-
ifExpr = ifExpr.alternate;
|
|
4835
|
-
}
|
|
4836
|
-
}
|
|
4837
|
-
return voidType;
|
|
4838
|
-
}
|
|
4839
|
-
function typeIsTruthy(t) {
|
|
4840
|
-
switch (t.kind) {
|
|
4841
|
-
case "Boolean":
|
|
4842
|
-
return t.value;
|
|
4843
|
-
case "Number":
|
|
4844
|
-
return !!t.value;
|
|
4845
|
-
case "String":
|
|
4846
|
-
return !!t.value;
|
|
4847
|
-
default:
|
|
4848
|
-
return true;
|
|
4849
|
-
}
|
|
4850
|
-
}
|
|
4851
|
-
function createEvalContext(node, parent) {
|
|
4852
|
-
return {
|
|
4853
|
-
node,
|
|
4854
|
-
locals: new Map(),
|
|
4855
|
-
parent,
|
|
4856
|
-
};
|
|
4857
|
-
}
|
|
4858
|
-
function evalProjectionBlockExpression(node) {
|
|
4859
|
-
let lastVal = voidType;
|
|
4860
|
-
for (const stmt of node.statements) {
|
|
4861
|
-
const stmtValue = evalProjectionNode(stmt);
|
|
4862
|
-
if (stmtValue.kind === "Return") {
|
|
4863
|
-
return stmtValue;
|
|
4864
|
-
}
|
|
4865
|
-
lastVal = stmtValue;
|
|
4866
|
-
}
|
|
4867
|
-
return lastVal;
|
|
4868
|
-
}
|
|
4869
|
-
function evalProjectionArithmeticExpression(node) {
|
|
4870
|
-
const lhs = evalProjectionNode(node.left);
|
|
4871
|
-
if (lhs.kind === "Return") {
|
|
4872
|
-
return lhs;
|
|
4873
|
-
}
|
|
4874
|
-
if (lhs.kind !== "Number" && lhs.kind !== "String") {
|
|
4875
|
-
throw new ProjectionError(`Operator ${node.op} can only apply to strings or numbers`);
|
|
4876
|
-
}
|
|
4877
|
-
const rhs = evalProjectionNode(node.right);
|
|
4878
|
-
if (rhs.kind === "Return") {
|
|
4879
|
-
return rhs;
|
|
4880
|
-
}
|
|
4881
|
-
if (rhs.kind !== "Number" && rhs.kind !== "String") {
|
|
4882
|
-
throw new ProjectionError(`Operator ${node.op} can only apply to strings or numbers`);
|
|
4883
|
-
}
|
|
4884
|
-
if (rhs.kind !== lhs.kind) {
|
|
4885
|
-
throw new ProjectionError(`Operator ${node.op}'s operands need to be the same type`);
|
|
4886
|
-
}
|
|
4887
|
-
if (lhs.kind === "String") {
|
|
4888
|
-
return createLiteralType(lhs.value + rhs.value);
|
|
4889
|
-
}
|
|
4890
|
-
else {
|
|
4891
|
-
return createLiteralType(lhs.value + rhs.value);
|
|
4892
|
-
}
|
|
4893
|
-
}
|
|
4894
|
-
function evalProjection(node, target, args) {
|
|
4895
|
-
if (node.direction === "<error>") {
|
|
4896
|
-
throw new ProjectionError("Cannot evaluate projection with invalid direction.");
|
|
4897
|
-
}
|
|
4898
|
-
let topLevelProjection = false;
|
|
4899
|
-
if (!currentProjectionDirection) {
|
|
4900
|
-
topLevelProjection = true;
|
|
4901
|
-
currentProjectionDirection = node.direction;
|
|
4902
|
-
}
|
|
4903
|
-
if (currentProjectionDirection === "from" && !target.projectionSource) {
|
|
4904
|
-
// this model wasn't projected, so we'll just return the target
|
|
4905
|
-
return target;
|
|
4906
|
-
}
|
|
4907
|
-
const originalContext = evalContext;
|
|
4908
|
-
evalContext = createEvalContext(node);
|
|
4909
|
-
for (const [i, param] of node.parameters.entries()) {
|
|
4910
|
-
if (!args[i]) {
|
|
4911
|
-
throw new ProjectionError("need argument for parameter " + SyntaxKind[node.parameters[i].kind]);
|
|
4912
|
-
}
|
|
4913
|
-
const argVal = args[i];
|
|
4914
|
-
let typeVal;
|
|
4915
|
-
if (typeof argVal === "number" || typeof argVal === "string" || typeof argVal === "boolean") {
|
|
4916
|
-
typeVal = createLiteralType(argVal);
|
|
4917
|
-
}
|
|
4918
|
-
else {
|
|
4919
|
-
typeVal = argVal;
|
|
4920
|
-
}
|
|
4921
|
-
evalContext.locals.set(param.id.sv, typeVal);
|
|
4922
|
-
}
|
|
4923
|
-
evalContext.locals.set("self", target);
|
|
4924
|
-
let lastVal = voidType;
|
|
4925
|
-
for (const item of node.body) {
|
|
4926
|
-
lastVal = evalProjectionNode(item);
|
|
4927
|
-
if (lastVal.kind === "Return") {
|
|
4928
|
-
break;
|
|
4929
|
-
}
|
|
4930
|
-
}
|
|
4931
|
-
if (topLevelProjection) {
|
|
4932
|
-
currentProjectionDirection = undefined;
|
|
4933
|
-
}
|
|
4934
|
-
const selfResult = evalContext.locals.get("self");
|
|
4935
|
-
evalContext = originalContext;
|
|
4936
|
-
if (lastVal.kind === "Return") {
|
|
4937
|
-
return lastVal.value;
|
|
4938
|
-
}
|
|
4939
|
-
else {
|
|
4940
|
-
return selfResult;
|
|
4941
|
-
}
|
|
4942
|
-
}
|
|
4943
|
-
function evalProjectionExpressionStatement(node) {
|
|
4944
|
-
return evalProjectionNode(node.expr);
|
|
4945
|
-
}
|
|
4946
|
-
function evalProjectionCallExpression(node) {
|
|
4947
|
-
const target = evalProjectionNode(node.target);
|
|
4948
|
-
if (!target)
|
|
4949
|
-
throw new ProjectionError("target undefined");
|
|
4950
|
-
const args = [];
|
|
4951
|
-
for (const arg of node.arguments) {
|
|
4952
|
-
args.push(evalProjectionNode(arg));
|
|
4953
|
-
}
|
|
4954
|
-
if (target.kind !== "Function") {
|
|
4955
|
-
throw new ProjectionError("Can't call non-function, got type " + target.kind);
|
|
4956
|
-
}
|
|
4957
|
-
return target.implementation(...args);
|
|
4958
|
-
}
|
|
4959
|
-
function evalProjectionMemberExpression(node) {
|
|
4960
|
-
const base = evalProjectionNode(node.base);
|
|
4961
|
-
if (base.kind === "Return") {
|
|
4962
|
-
return base;
|
|
4963
|
-
}
|
|
4964
|
-
const member = node.id.sv;
|
|
4965
|
-
const selector = node.selector;
|
|
4966
|
-
if (selector === ".") {
|
|
4967
|
-
switch (base.kind) {
|
|
4968
|
-
case "Namespace":
|
|
4969
|
-
const sym = base.node.symbol.exports.get(member);
|
|
4970
|
-
if (sym) {
|
|
4971
|
-
const links = getSymbolLinks(sym);
|
|
4972
|
-
return links.declaredType || links.type || errorType;
|
|
4973
|
-
}
|
|
4974
|
-
else {
|
|
4975
|
-
throw new ProjectionError(`Namespace doesn't have member ${member}`);
|
|
4976
|
-
}
|
|
4977
|
-
case "Model":
|
|
4978
|
-
const prop = base.properties.get(member);
|
|
4979
|
-
if (!prop) {
|
|
4980
|
-
throw new ProjectionError(`Model doesn't have property ${member}`);
|
|
4981
|
-
}
|
|
4982
|
-
return prop;
|
|
4983
|
-
case "Enum":
|
|
4984
|
-
const enumMember = base.members.get(member);
|
|
4985
|
-
if (!enumMember) {
|
|
4986
|
-
throw new ProjectionError(`Enum doesn't have member ${member}`);
|
|
4987
|
-
}
|
|
4988
|
-
return enumMember;
|
|
4989
|
-
case "Union":
|
|
4990
|
-
const variant = base.variants.get(member);
|
|
4991
|
-
if (!variant) {
|
|
4992
|
-
throw new ProjectionError(`Union doesn't have variant ${member}`);
|
|
4993
|
-
}
|
|
4994
|
-
return variant;
|
|
4995
|
-
default:
|
|
4996
|
-
throw new ProjectionError(`Can't get member "${member}" of type ${base.kind} because it has no members. Did you mean to use "::" instead of "."?`);
|
|
4997
|
-
}
|
|
4998
|
-
}
|
|
4999
|
-
switch (base.kind) {
|
|
5000
|
-
case "Object":
|
|
5001
|
-
return base.properties[member] || errorType;
|
|
5002
|
-
default:
|
|
5003
|
-
const typeOps = projectionMembers[base.kind];
|
|
5004
|
-
if (!typeOps) {
|
|
5005
|
-
throw new ProjectionError(`${base.kind} doesn't have an object model member named ${member}`);
|
|
5006
|
-
}
|
|
5007
|
-
// any cast needed to ensure we don't get a too complex union error on the call
|
|
5008
|
-
// to op further down.
|
|
5009
|
-
const op = typeOps[member];
|
|
5010
|
-
if (!op) {
|
|
5011
|
-
throw new ProjectionError(`${base.kind} doesn't have an object model member named ${member}`);
|
|
5012
|
-
}
|
|
5013
|
-
return op(base);
|
|
5014
|
-
}
|
|
5015
|
-
}
|
|
5016
|
-
function createFunctionType(fn) {
|
|
5017
|
-
const parameters = [];
|
|
5018
|
-
return createType({
|
|
5019
|
-
kind: "Function",
|
|
5020
|
-
name: "",
|
|
5021
|
-
parameters,
|
|
5022
|
-
returnType: unknownType,
|
|
5023
|
-
implementation: fn,
|
|
5024
|
-
});
|
|
5025
|
-
}
|
|
5026
4493
|
function createLiteralType(value, node) {
|
|
5027
4494
|
if (program.literalTypes.has(value)) {
|
|
5028
4495
|
return program.literalTypes.get(value);
|
|
@@ -5055,101 +4522,6 @@ export function createChecker(program, resolver) {
|
|
|
5055
4522
|
program.literalTypes.set(value, type);
|
|
5056
4523
|
return type;
|
|
5057
4524
|
}
|
|
5058
|
-
function evalProjectionDecoratorReference(node) {
|
|
5059
|
-
const ref = resolveTypeReferenceSym(node.target, undefined, true);
|
|
5060
|
-
if (!ref)
|
|
5061
|
-
throw new ProjectionError("Can't find decorator.");
|
|
5062
|
-
compilerAssert(ref.flags & 1024 /* SymbolFlags.Decorator */, "should only resolve decorator symbols");
|
|
5063
|
-
return createFunctionType((...args) => {
|
|
5064
|
-
ref.value({ program }, ...args.map(unsafe_projectionArgumentMarshalForJS));
|
|
5065
|
-
return voidType;
|
|
5066
|
-
});
|
|
5067
|
-
}
|
|
5068
|
-
function evalProjectionIdentifier(node) {
|
|
5069
|
-
// first check the eval context
|
|
5070
|
-
let currentContext = evalContext;
|
|
5071
|
-
while (currentContext) {
|
|
5072
|
-
if (currentContext.locals.has(node.sv)) {
|
|
5073
|
-
return currentContext.locals.get(node.sv);
|
|
5074
|
-
}
|
|
5075
|
-
currentContext = currentContext.parent;
|
|
5076
|
-
}
|
|
5077
|
-
// next, resolve outside
|
|
5078
|
-
const { finalSymbol: ref } = resolver.resolveTypeReference(node);
|
|
5079
|
-
if (!ref)
|
|
5080
|
-
throw new ProjectionError("Unknown identifier " + node.sv);
|
|
5081
|
-
if (ref.flags & 1024 /* SymbolFlags.Decorator */) {
|
|
5082
|
-
// shouldn't ever resolve a decorator symbol here (without passing
|
|
5083
|
-
// true to resolveTypeReference)
|
|
5084
|
-
return errorType;
|
|
5085
|
-
}
|
|
5086
|
-
else if (ref.flags & 8192 /* SymbolFlags.Function */) {
|
|
5087
|
-
// TODO: store this in a symbol link probably?
|
|
5088
|
-
const t = createFunctionType((...args) => {
|
|
5089
|
-
const retval = ref.value(program, ...args.map(unsafe_projectionArgumentMarshalForJS));
|
|
5090
|
-
return marshalProjectionReturn(retval, { functionName: node.sv });
|
|
5091
|
-
});
|
|
5092
|
-
return t;
|
|
5093
|
-
}
|
|
5094
|
-
else {
|
|
5095
|
-
const links = getSymbolLinks(ref);
|
|
5096
|
-
compilerAssert(links.declaredType, "Should have checked all types by now");
|
|
5097
|
-
return links.declaredType;
|
|
5098
|
-
}
|
|
5099
|
-
}
|
|
5100
|
-
function marshalProjectionReturn(value, options = {}) {
|
|
5101
|
-
if (typeof value === "boolean" || typeof value === "string" || typeof value === "number") {
|
|
5102
|
-
return createLiteralType(value);
|
|
5103
|
-
}
|
|
5104
|
-
if (typeof value === "object" && value !== null) {
|
|
5105
|
-
if ("kind" in value) {
|
|
5106
|
-
return value;
|
|
5107
|
-
}
|
|
5108
|
-
else {
|
|
5109
|
-
// this could probably be more robust
|
|
5110
|
-
return createType({
|
|
5111
|
-
kind: "Object",
|
|
5112
|
-
properties: value,
|
|
5113
|
-
});
|
|
5114
|
-
}
|
|
5115
|
-
}
|
|
5116
|
-
if (options.functionName) {
|
|
5117
|
-
throw new ProjectionError(`Can't marshal value "${value}" returned from JS function "${options.functionName}" into typespec`);
|
|
5118
|
-
}
|
|
5119
|
-
else {
|
|
5120
|
-
throw new ProjectionError(`Can't marshal value "${value}" into typespec`);
|
|
5121
|
-
}
|
|
5122
|
-
}
|
|
5123
|
-
function evalProjectionLambdaExpression(node) {
|
|
5124
|
-
return createFunctionType((...args) => {
|
|
5125
|
-
return callLambdaExpression(node, args);
|
|
5126
|
-
});
|
|
5127
|
-
}
|
|
5128
|
-
function callLambdaExpression(node, args) {
|
|
5129
|
-
const originalContext = evalContext;
|
|
5130
|
-
evalContext = createEvalContext(node, originalContext);
|
|
5131
|
-
for (const [i, param] of node.parameters.entries()) {
|
|
5132
|
-
evalContext.locals.set(param.id.sv, args[i]);
|
|
5133
|
-
}
|
|
5134
|
-
const retval = evalProjectionBlockExpression(node.body);
|
|
5135
|
-
evalContext = originalContext;
|
|
5136
|
-
if (retval.kind === "Return") {
|
|
5137
|
-
return retval.value;
|
|
5138
|
-
}
|
|
5139
|
-
return retval;
|
|
5140
|
-
}
|
|
5141
|
-
function evalStringLiteral(node) {
|
|
5142
|
-
return createLiteralType(node.value, node);
|
|
5143
|
-
}
|
|
5144
|
-
function evalNumericLiteral(node) {
|
|
5145
|
-
return createLiteralType(node.value, node);
|
|
5146
|
-
}
|
|
5147
|
-
function evalBooleanLiteral(node) {
|
|
5148
|
-
return createLiteralType(node.value, node);
|
|
5149
|
-
}
|
|
5150
|
-
function project(target, projection, args = []) {
|
|
5151
|
-
return evalProjection(projection, target, args.map((x) => marshalProjectionReturn(x)));
|
|
5152
|
-
}
|
|
5153
4525
|
/**
|
|
5154
4526
|
* Check if the source type can be assigned to the target type and emit diagnostics
|
|
5155
4527
|
* @param source Type of a value
|
|
@@ -5196,7 +4568,6 @@ export function createChecker(program, resolver) {
|
|
|
5196
4568
|
return related;
|
|
5197
4569
|
}
|
|
5198
4570
|
function isStdType(type, stdType) {
|
|
5199
|
-
type = type.projectionBase ?? type;
|
|
5200
4571
|
if ((type.kind !== "Model" && type.kind !== "Scalar") ||
|
|
5201
4572
|
type.namespace === undefined ||
|
|
5202
4573
|
!isTypeSpecNamespace(type.namespace))
|
|
@@ -5624,21 +4995,6 @@ const defaultSymbolResolutionOptions = {
|
|
|
5624
4995
|
resolveDecorators: false,
|
|
5625
4996
|
checkTemplateTypes: true,
|
|
5626
4997
|
};
|
|
5627
|
-
/**
|
|
5628
|
-
* Convert LEGACY for projection.
|
|
5629
|
-
* THIS IS BROKEN. Some decorators will not receive the correct type.
|
|
5630
|
-
* It has been broken since the introduction of valueof.
|
|
5631
|
-
* As projection as put on hold as long as versioning works we are in a good state.
|
|
5632
|
-
*/
|
|
5633
|
-
function unsafe_projectionArgumentMarshalForJS(arg) {
|
|
5634
|
-
if (arg.kind === "Boolean" || arg.kind === "String" || arg.kind === "Number") {
|
|
5635
|
-
return arg.value;
|
|
5636
|
-
}
|
|
5637
|
-
else if (arg.kind === "StringTemplate") {
|
|
5638
|
-
return arg.stringValue;
|
|
5639
|
-
}
|
|
5640
|
-
return arg;
|
|
5641
|
-
}
|
|
5642
4998
|
function printTypeReferenceNode(node) {
|
|
5643
4999
|
switch (node.kind) {
|
|
5644
5000
|
case SyntaxKind.MemberExpression:
|