@typespec/compiler 1.14.0-dev.1 → 1.14.0-dev.3
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/auto-decorator.d.ts +26 -0
- package/dist/src/core/auto-decorator.d.ts.map +1 -0
- package/dist/src/core/auto-decorator.js +85 -0
- package/dist/src/core/auto-decorator.js.map +1 -0
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +16 -3
- 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 +31 -2
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +9 -0
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/modifiers.d.ts.map +1 -1
- package/dist/src/core/modifiers.js +42 -8
- package/dist/src/core/modifiers.js.map +1 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +13 -0
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +11 -43
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/scanner.d.ts +41 -41
- package/dist/src/core/scanner.d.ts.map +1 -1
- package/dist/src/core/scanner.js +46 -47
- package/dist/src/core/scanner.js.map +1 -1
- package/dist/src/core/suppression-tracking.d.ts +21 -0
- package/dist/src/core/suppression-tracking.d.ts.map +1 -0
- package/dist/src/core/suppression-tracking.js +139 -0
- package/dist/src/core/suppression-tracking.js.map +1 -0
- package/dist/src/core/types.d.ts +10 -3
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +2 -1
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +2 -0
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +24 -0
- package/dist/src/server/serverlib.js.map +1 -1
- package/package.json +1 -1
package/dist/manifest.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Program } from "./program.js";
|
|
2
|
+
import type { Type } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Check if an auto decorator has been applied to a target.
|
|
5
|
+
* @param program - The current program.
|
|
6
|
+
* @param decoratorFqn - The fully-qualified name of the decorator (e.g., "MyLib.myDec").
|
|
7
|
+
* @param target - The type to check.
|
|
8
|
+
*/
|
|
9
|
+
export declare function hasAutoDecorator(program: Program, decoratorFqn: string, target: Type): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Get the stored value for an auto decorator applied to a target.
|
|
12
|
+
* Always returns a record of `{ paramName: value }` (empty record `{}` for no-arg decorators).
|
|
13
|
+
* @param program - The current program.
|
|
14
|
+
* @param decoratorFqn - The fully-qualified name of the decorator (e.g., "MyLib.myDec").
|
|
15
|
+
* @param target - The type to get the value for.
|
|
16
|
+
* @returns The stored record, or `undefined` if the decorator was not applied.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getAutoDecoratorValue(program: Program, decoratorFqn: string, target: Type): Record<string, unknown> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Get all targets that have a specific auto decorator applied, along with their stored values.
|
|
21
|
+
* @param program - The current program.
|
|
22
|
+
* @param decoratorFqn - The fully-qualified name of the decorator (e.g., "MyLib.myDec").
|
|
23
|
+
* @returns A map of target types to their stored values.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAutoDecoratorTargets(program: Program, decoratorFqn: string): Map<Type, unknown>;
|
|
26
|
+
//# sourceMappingURL=auto-decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-decorator.d.ts","sourceRoot":"","sources":["../../../src/core/auto-decorator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,EAA4D,IAAI,EAAE,MAAM,YAAY,CAAC;AAyDjG;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAG9F;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,IAAI,GACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAGrC;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,MAAM,GACnB,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAGpB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { validateDecoratorUniqueOnNode } from "./decorator-utils.js";
|
|
4
|
+
import { getFullyQualifiedSymbolName } from "./type-utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Get the state key for an auto decorator given its fully-qualified name.
|
|
7
|
+
* Uses `dec:` prefix so the state key is based on decorator identity,
|
|
8
|
+
* not declaration style — allows seamless migration from auto to extern.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export function getAutoDecoratorStateKey(decoratorFqn) {
|
|
12
|
+
return Symbol.for(`dec:${decoratorFqn}`);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Build the auto-generated implementation for an `auto dec` declaration.
|
|
16
|
+
*
|
|
17
|
+
* The returned function stores its arguments as a uniform `{ paramName: value }`
|
|
18
|
+
* record in the program state map keyed by the decorator's fully-qualified name,
|
|
19
|
+
* and warns (last-write-wins, like extern decorators) on duplicate application.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export function createAutoDecoratorImplementation(symbol, node) {
|
|
23
|
+
const fqn = getFullyQualifiedSymbolName(symbol);
|
|
24
|
+
const stateKey = getAutoDecoratorStateKey(fqn);
|
|
25
|
+
const paramNames = node.parameters.map((p) => p.id.sv);
|
|
26
|
+
const lastParamIsRest = node.parameters.length > 0 && node.parameters[node.parameters.length - 1].rest;
|
|
27
|
+
const impl = (context, target, ...args) => {
|
|
28
|
+
// Warn (but still store, so duplicates are last-write-wins like extern
|
|
29
|
+
// decorators) if the same auto decorator is applied twice on the same node.
|
|
30
|
+
if ("decorators" in target) {
|
|
31
|
+
validateDecoratorUniqueOnNode(context, target, impl);
|
|
32
|
+
}
|
|
33
|
+
const data = {};
|
|
34
|
+
if (lastParamIsRest) {
|
|
35
|
+
for (let i = 0; i < paramNames.length - 1; i++) {
|
|
36
|
+
data[paramNames[i]] = args[i];
|
|
37
|
+
}
|
|
38
|
+
// The rest parameter collects all remaining arguments into an array.
|
|
39
|
+
data[paramNames[paramNames.length - 1]] = args.slice(paramNames.length - 1);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
43
|
+
data[paramNames[i]] = args[i];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
context.program.stateMap(stateKey).set(target, data);
|
|
47
|
+
};
|
|
48
|
+
// The function name drives the `@<name>` text in the duplicate-decorator
|
|
49
|
+
// diagnostic; mirror the extern `$name` convention so the helper strips it.
|
|
50
|
+
Object.defineProperty(impl, "name", { value: `$${node.id.sv}` });
|
|
51
|
+
return impl;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if an auto decorator has been applied to a target.
|
|
55
|
+
* @param program - The current program.
|
|
56
|
+
* @param decoratorFqn - The fully-qualified name of the decorator (e.g., "MyLib.myDec").
|
|
57
|
+
* @param target - The type to check.
|
|
58
|
+
*/
|
|
59
|
+
export function hasAutoDecorator(program, decoratorFqn, target) {
|
|
60
|
+
const key = getAutoDecoratorStateKey(decoratorFqn);
|
|
61
|
+
return program.stateMap(key).has(target);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get the stored value for an auto decorator applied to a target.
|
|
65
|
+
* Always returns a record of `{ paramName: value }` (empty record `{}` for no-arg decorators).
|
|
66
|
+
* @param program - The current program.
|
|
67
|
+
* @param decoratorFqn - The fully-qualified name of the decorator (e.g., "MyLib.myDec").
|
|
68
|
+
* @param target - The type to get the value for.
|
|
69
|
+
* @returns The stored record, or `undefined` if the decorator was not applied.
|
|
70
|
+
*/
|
|
71
|
+
export function getAutoDecoratorValue(program, decoratorFqn, target) {
|
|
72
|
+
const key = getAutoDecoratorStateKey(decoratorFqn);
|
|
73
|
+
return program.stateMap(key).get(target);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get all targets that have a specific auto decorator applied, along with their stored values.
|
|
77
|
+
* @param program - The current program.
|
|
78
|
+
* @param decoratorFqn - The fully-qualified name of the decorator (e.g., "MyLib.myDec").
|
|
79
|
+
* @returns A map of target types to their stored values.
|
|
80
|
+
*/
|
|
81
|
+
export function getAutoDecoratorTargets(program, decoratorFqn) {
|
|
82
|
+
const key = getAutoDecoratorStateKey(decoratorFqn);
|
|
83
|
+
return program.stateMap(key);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=auto-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-decorator.js","sourceRoot":"","sources":["../../../src/core/auto-decorator.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAElC,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAErE,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAG9D;;;;;GAKG;AACH,MAAM,UAAU,wBAAw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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../src/core/checker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../../src/core/checker.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAY5C,OAAO,EAML,cAAc,EACd,kBAAkB,EAqClB,mBAAmB,EAanB,KAAK,EAGL,aAAa,EAOb,IAAI,EAGJ,cAAc,EACd,kBAAkB,EASlB,MAAM,EAMN,WAAW,EACX,QAAQ,EACR,aAAa,EACb,iBAAiB,EAUjB,GAAG,EAcH,IAAI,EAcJ,KAAK,EAGN,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,GAAG,MAAM,aAAa,CAAC,CAAC;AA+I5F,MAAM,WAAW,OAAO;IAGtB;;;OAGG;IACH,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAgBjC,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,eAAe,CAAC,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAAE,GAAG,CAAC,CAAC;IAKnF,UAAU,CAAC,CAAC,SAAS,IAAI,SAAS,GAAG,GAAG,eAAe,GAAG,KAAK,EAC7D,OAAO,EAAE,CAAC,GACT,CAAC,GAAG,aAAa,GAAG;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5E,mBAAmB,CAAC,CAAC,SAAS,IAAI,SAAS,GAAG,GAAG,eAA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K,GAAG,IAAI,GAAG,SAAS,CAAC;CAuCnD;AAED,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,aAAa;CAAG;AAE1B,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,GAAG,CAAC;IAET;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AASD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CA8rP/E;AAgED;;;;;;;;;;;;;;;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,EAChB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,GAC3C,KAAK,CAqCP;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAcxF;AAED;;;;;;;GAOG;AACH,wBAAiB,uBAAuB,CAAC,KAAK,EAAE,KAAK,2CAapD"}
|
package/dist/src/core/checker.js
CHANGED
|
@@ -3,6 +3,7 @@ import { docFromCommentDecorator, getIndexer } from "../lib/intrinsic/decorators
|
|
|
3
3
|
import { $ } from "../typekit/index.js";
|
|
4
4
|
import { DuplicateTracker } from "../utils/duplicate-tracker.js";
|
|
5
5
|
import { MultiKeyMap, createRekeyableMap, isArray, mutate } from "../utils/misc.js";
|
|
6
|
+
import { createAutoDecoratorImplementation } from "./auto-decorator.js";
|
|
6
7
|
import { createSymbol, getSymNode } from "./binder.js";
|
|
7
8
|
import { createChangeIdentifierCodeFix } from "./compiler-code-fixes/change-identifier.codefix.js";
|
|
8
9
|
import { createModelToObjectValueCodeFix, createTupleToArrayValueCodeFix, } from "./compiler-code-fixes/convert-to-value.codefix.js";
|
|
@@ -1371,8 +1372,18 @@ export function createChecker(program, resolver) {
|
|
|
1371
1372
|
const namespace = getParentNamespaceType(node);
|
|
1372
1373
|
compilerAssert(namespace, `Decorator ${node.id.sv} should have resolved a namespace or found the global namespace.`);
|
|
1373
1374
|
const name = node.id.sv;
|
|
1374
|
-
const
|
|
1375
|
-
if (
|
|
1375
|
+
const isAuto = (node.modifierFlags & 8 /* ModifierFlags.Auto */) !== 0;
|
|
1376
|
+
if (isAuto && !isCompilerFeatureEnabled(program, "auto-decorators", node)) {
|
|
1377
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
1378
|
+
code: "auto-decorator-disabled",
|
|
1379
|
+
target: node,
|
|
1380
|
+
}));
|
|
1381
|
+
}
|
|
1382
|
+
let implementation = symbol.value;
|
|
1383
|
+
if (isAuto) {
|
|
1384
|
+
implementation = createAutoDecoratorImplementation(symbol, node);
|
|
1385
|
+
}
|
|
1386
|
+
else if (implementation === undefined) {
|
|
1376
1387
|
reportCheckerDiagnostic(createDiagnostic({ code: "missing-implementation", target: node }));
|
|
1377
1388
|
}
|
|
1378
1389
|
const decoratorType = createType({
|
|
@@ -1383,6 +1394,7 @@ export function createChecker(program, resolver) {
|
|
|
1383
1394
|
target: checkFunctionParameter(ctx, node.target, true),
|
|
1384
1395
|
parameters: node.parameters.map((param) => checkFunctionParameter(ctx, param, true)),
|
|
1385
1396
|
implementation: implementation ?? (() => { }),
|
|
1397
|
+
declarationKind: isAuto ? "auto" : "extern",
|
|
1386
1398
|
});
|
|
1387
1399
|
namespace.decoratorDeclarations.set(name, decoratorType);
|
|
1388
1400
|
linkType(ctx, links, decoratorType);
|
|
@@ -5086,9 +5098,10 @@ export function createChecker(program, resolver) {
|
|
|
5086
5098
|
if (hasError || argsHaveError) {
|
|
5087
5099
|
return undefined;
|
|
5088
5100
|
}
|
|
5101
|
+
const impl = sym.value ?? symbolLinks.declaredType?.implementation;
|
|
5089
5102
|
return {
|
|
5090
5103
|
definition: symbolLinks.declaredType,
|
|
5091
|
-
decorator:
|
|
5104
|
+
decorator: impl ?? ((...args) => { }),
|
|
5092
5105
|
node: decNode,
|
|
5093
5106
|
args,
|
|
5094
5107
|
};
|