@typespec/compiler 0.62.0-dev.11 → 0.62.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/generated-defs/TypeSpec.Prototypes.d.ts +6 -0
- package/dist/generated-defs/TypeSpec.Prototypes.d.ts.map +1 -0
- package/dist/generated-defs/TypeSpec.Prototypes.js +2 -0
- package/dist/generated-defs/TypeSpec.Prototypes.js.map +1 -0
- package/dist/generated-defs/TypeSpec.Prototypes.ts-test.d.ts +2 -0
- package/dist/generated-defs/TypeSpec.Prototypes.ts-test.d.ts.map +1 -0
- package/dist/generated-defs/TypeSpec.Prototypes.ts-test.js +5 -0
- package/dist/generated-defs/TypeSpec.Prototypes.ts-test.js.map +1 -0
- package/dist/manifest.js +2 -2
- package/dist/src/core/binder.d.ts +8 -0
- package/dist/src/core/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +107 -43
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts +3 -7
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +319 -814
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/diagnostics.js +2 -2
- package/dist/src/core/diagnostics.js.map +1 -1
- package/dist/src/core/helpers/operation-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/operation-utils.js +4 -1
- package/dist/src/core/helpers/operation-utils.js.map +1 -1
- package/dist/src/core/helpers/syntax-utils.d.ts +2 -0
- package/dist/src/core/helpers/syntax-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/syntax-utils.js +11 -0
- package/dist/src/core/helpers/syntax-utils.js.map +1 -1
- package/dist/src/core/inspector/node.d.ts +2 -0
- package/dist/src/core/inspector/node.d.ts.map +1 -0
- package/dist/src/core/inspector/node.js +35 -0
- package/dist/src/core/inspector/node.js.map +1 -0
- package/dist/src/core/inspector/symbol.d.ts +3 -0
- package/dist/src/core/inspector/symbol.d.ts.map +1 -0
- package/dist/src/core/inspector/symbol.js +84 -0
- package/dist/src/core/inspector/symbol.js.map +1 -0
- package/dist/src/core/messages.d.ts +17 -43
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +3 -13
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/name-resolver.d.ts +107 -0
- package/dist/src/core/name-resolver.d.ts.map +1 -0
- package/dist/src/core/name-resolver.js +989 -0
- package/dist/src/core/name-resolver.js.map +1 -0
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +9 -5
- 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 +3 -1
- package/dist/src/core/semantic-walker.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 +140 -34
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +9 -0
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +13 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/intrinsic/decorators.d.ts +5 -0
- package/dist/src/lib/intrinsic/decorators.d.ts.map +1 -0
- package/dist/src/lib/intrinsic/decorators.js +25 -0
- package/dist/src/lib/intrinsic/decorators.js.map +1 -0
- package/dist/src/lib/intrinsic/tsp-index.d.ts +9 -0
- package/dist/src/lib/intrinsic/tsp-index.d.ts.map +1 -0
- package/dist/src/lib/intrinsic/tsp-index.js +11 -0
- package/dist/src/lib/intrinsic/tsp-index.js.map +1 -0
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js +7 -6
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/type-details.js +3 -2
- package/dist/src/server/type-details.js.map +1 -1
- package/dist/src/server/type-signature.js +2 -1
- package/dist/src/server/type-signature.js.map +1 -1
- package/dist/src/testing/test-host.js +1 -1
- package/dist/src/testing/test-host.js.map +1 -1
- package/dist/src/testing/test-utils.d.ts +6 -0
- package/dist/src/testing/test-utils.d.ts.map +1 -1
- package/dist/src/testing/test-utils.js +19 -1
- package/dist/src/testing/test-utils.js.map +1 -1
- package/dist/src/utils/misc.d.ts +2 -4
- package/dist/src/utils/misc.d.ts.map +1 -1
- package/dist/src/utils/misc.js.map +1 -1
- package/lib/intrinsics.tsp +2 -1
- package/lib/prototypes.tsp +18 -0
- package/package.json +3 -4
- package/dist/src/lib/intrinsic-decorators.d.ts +0 -6
- package/dist/src/lib/intrinsic-decorators.d.ts.map +0 -1
- package/dist/src/lib/intrinsic-decorators.js +0 -17
- package/dist/src/lib/intrinsic-decorators.js.map +0 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The name resolver is responsible for resolving identifiers to symbols and
|
|
3
|
+
* creating symbols for types that become known during this process. After name
|
|
4
|
+
* resolution, we can do some limited analysis of the reference graph in order
|
|
5
|
+
* to support e.g. augment decorators.
|
|
6
|
+
*
|
|
7
|
+
* Name resolution does not alter any AST nodes or attached symbols in order to
|
|
8
|
+
* ensure AST nodes and attached symbols can be trivially reused between
|
|
9
|
+
* compilations. Instead, symbols created here are either stored in augmented
|
|
10
|
+
* symbol tables or as merged symbols. Any metadata about symbols and nodes are
|
|
11
|
+
* stored in symbol links and node links respectively. The resolver provides
|
|
12
|
+
* APIs for managing this metadata which is useful during later phases.
|
|
13
|
+
*
|
|
14
|
+
* While we resolve some identifiers to symbols during this phase, we often
|
|
15
|
+
* cannot say for sure that an identifier does not exist. Some symbols must be
|
|
16
|
+
* late-bound because the symbol does not become known until after the program
|
|
17
|
+
* has been checked. A common example is members of a model template which often
|
|
18
|
+
* cannot be known until the template is instantiated. Instead, we mark that the
|
|
19
|
+
* reference is unknown and will resolve the symbol (or report an error if it
|
|
20
|
+
* doesn't exist) in later phases. These unknown references cannot be used as
|
|
21
|
+
* the target of an augment decorator.
|
|
22
|
+
*
|
|
23
|
+
* There are some errors we can detect because we have complete symbol
|
|
24
|
+
* information, but we do not report them from here. For example, because we
|
|
25
|
+
* know all namespace bindings and all the declarations inside of them, we could
|
|
26
|
+
* in principle report an error when we attempt to `using` something that isn't
|
|
27
|
+
* a namespace. However, giving a good error message sometimes requires knowing
|
|
28
|
+
* what type was mistakenly referenced, so we merely mark that resolution has
|
|
29
|
+
* failed and move on. Even in cases where we could give a good error we chose
|
|
30
|
+
* not to in order to uniformly handle error reporting in the checker.
|
|
31
|
+
*
|
|
32
|
+
* Name resolution has three sub-phases:
|
|
33
|
+
*
|
|
34
|
+
* 1. Merge namespace symbols and decorator implementation/declaration symbols
|
|
35
|
+
* 2. Resolve using references to namespaces and create namespace-local bindings
|
|
36
|
+
* for used symbols
|
|
37
|
+
* 3. Resolve type references and bind members
|
|
38
|
+
*
|
|
39
|
+
* The reference resolution and member binding phase implements a deferred
|
|
40
|
+
* resolution strategy. Often we cannot resolve a reference without binding
|
|
41
|
+
* members, but we often cannot bind members without resolving references. In
|
|
42
|
+
* such situations, we stop resolving or binding the current reference or type
|
|
43
|
+
* and attempt to resolve or bind the reference or type it depends on. Once we
|
|
44
|
+
* have done so, we return to the original reference or type and complete our
|
|
45
|
+
* work.
|
|
46
|
+
*
|
|
47
|
+
* This is accomplished by doing a depth-first traversal of the reference graph.
|
|
48
|
+
* On the way down, we discover any dependencies that need to be resolved or
|
|
49
|
+
* bound for the current node, and recurse into the AST nodes, so that on the
|
|
50
|
+
* way back up, all of our dependencies are bound and resolved and we can
|
|
51
|
+
* complete. So while we start with a depth-first traversal of the ASTs in order
|
|
52
|
+
* to discover work to do, most of the actual work is done while following the
|
|
53
|
+
* reference graph, binding and resolving along the way. Circular references are
|
|
54
|
+
* discovered during the reference graph walk and marked as such. Symbol and
|
|
55
|
+
* node links are used to ensure we never resolve the same reference twice. The
|
|
56
|
+
* checker implements a very similar algorithm to evaluate the types of the
|
|
57
|
+
* program.
|
|
58
|
+
**/
|
|
59
|
+
import { Mutable } from "../utils/misc.js";
|
|
60
|
+
import { Program } from "./program.js";
|
|
61
|
+
import { AugmentDecoratorStatementNode, IdentifierNode, MemberExpressionNode, Node, NodeLinks, ResolutionResult, Sym, SymbolLinks, SymbolTable, TypeReferenceNode } from "./types.js";
|
|
62
|
+
export interface NameResolver {
|
|
63
|
+
/**
|
|
64
|
+
* Resolve all static symbol links in the program.
|
|
65
|
+
*/
|
|
66
|
+
resolveProgram(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get the merged symbol or itself if not merged.
|
|
69
|
+
* This is the case for Namespace which have multiple nodes and symbol but all reference the same merged one.
|
|
70
|
+
*/
|
|
71
|
+
getMergedSymbol(sym: Sym): Sym;
|
|
72
|
+
/**
|
|
73
|
+
* Get augmented symbol table.
|
|
74
|
+
*/
|
|
75
|
+
getAugmentedSymbolTable(table: SymbolTable): Mutable<SymbolTable>;
|
|
76
|
+
/**
|
|
77
|
+
* Get node links for the given syntax node.
|
|
78
|
+
* This returns links to which symbol the node reference if applicable(TypeReference, Identifier nodes)
|
|
79
|
+
*/
|
|
80
|
+
getNodeLinks(node: Node): NodeLinks;
|
|
81
|
+
/** Get symbol links for the given symbol */
|
|
82
|
+
getSymbolLinks(symbol: Sym): SymbolLinks;
|
|
83
|
+
/** Return augment decorator nodes that are bound to this symbol */
|
|
84
|
+
getAugmentDecoratorsForSym(symbol: Sym): AugmentDecoratorStatementNode[];
|
|
85
|
+
/**
|
|
86
|
+
* Resolve the member expression using the given symbol as base.
|
|
87
|
+
* This can be used to follow the name resolution for template instance which are not statically linked.
|
|
88
|
+
*/
|
|
89
|
+
resolveMemberExpressionForSym(sym: Sym, node: MemberExpressionNode, options?: ResolveTypReferenceOptions): ResolutionResult;
|
|
90
|
+
/** Get the meta member by name */
|
|
91
|
+
resolveMetaMemberByName(sym: Sym, name: string): ResolutionResult;
|
|
92
|
+
/** Resolve the given type reference. This should only need to be called on dynamically created nodes that want to resolve which symbol they reference */
|
|
93
|
+
resolveTypeReference(node: TypeReferenceNode | IdentifierNode | MemberExpressionNode): ResolutionResult;
|
|
94
|
+
/** Built-in symbols. */
|
|
95
|
+
readonly symbols: {
|
|
96
|
+
/** Symbol for the global namespace */
|
|
97
|
+
readonly global: Sym;
|
|
98
|
+
/** Symbol for the null type */
|
|
99
|
+
readonly null: Sym;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
interface ResolveTypReferenceOptions {
|
|
103
|
+
resolveDecorators?: boolean;
|
|
104
|
+
}
|
|
105
|
+
export declare function createResolver(program: Program): NameResolver;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=name-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name-resolver.d.ts","sourceRoot":"","sources":["../../../src/core/name-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAyDI;AAEJ,OAAO,EAAE,OAAO,EAAU,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAEL,6BAA6B,EAI7B,cAAc,EAGd,oBAAoB,EAKpB,IAAI,EAEJ,SAAS,EAIT,gBAAgB,EAGhB,GAAG,EAEH,WAAW,EACX,WAAW,EAGX,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,cAAc,IAAI,IAAI,CAAC;IAEvB;;;OAGG;IACH,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC;IAE/B;;OAEG;IACH,uBAAuB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAClE;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IAEpC,4CAA4C;IAC5C,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAAC;IAEzC,mEAAmE;IACnE,0BAA0B,CAAC,MAAM,EAAE,GAAG,GAAG,6BAA6B,EAAE,CAAC;IAEzE;;;OAGG;IACH,6BAA6B,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,oBAAoB,EAC1B,OAAO,CAAC,EAAE,0BAA0B,GACnC,gBAAgB,CAAC;IAEpB,kCAAkC;IAClC,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAElE,yJAAyJ;IACzJ,oBAAoB,CAClB,IAAI,EAAE,iBAAiB,GAAG,cAAc,GAAG,oBAAoB,GAC9D,gBAAgB,CAAC;IAEpB,wBAAwB;IACxB,QAAQ,CAAC,OAAO,EAAE;QAChB,sCAAsC;QACtC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC;QAErB,+BAA+B;QAC/B,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;KACpB,CAAC;CACH;AAED,UAAU,0BAA0B;IAClC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAMD,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,CAwmC7D"}
|