@typespec/compiler 0.45.0-dev.20 → 0.45.0-dev.24
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/core/checker.d.ts +2 -2
- package/dist/core/checker.d.ts.map +1 -1
- package/dist/core/checker.js +89 -15
- package/dist/core/checker.js.map +1 -1
- package/dist/core/helpers/type-name-utils.d.ts +2 -2
- package/dist/core/helpers/type-name-utils.d.ts.map +1 -1
- package/dist/core/helpers/type-name-utils.js +2 -0
- package/dist/core/helpers/type-name-utils.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +14 -0
- package/dist/core/parser.js.map +1 -1
- package/dist/core/projector.d.ts.map +1 -1
- package/dist/core/projector.js +2 -7
- package/dist/core/projector.js.map +1 -1
- package/dist/core/scanner.d.ts +9 -8
- package/dist/core/scanner.d.ts.map +1 -1
- package/dist/core/scanner.js +16 -13
- package/dist/core/scanner.js.map +1 -1
- package/dist/core/types.d.ts +61 -47
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +44 -43
- package/dist/core/types.js.map +1 -1
- package/dist/emitter-framework/type-emitter.d.ts.map +1 -1
- package/dist/emitter-framework/type-emitter.js +2 -1
- package/dist/emitter-framework/type-emitter.js.map +1 -1
- package/dist/formatter/print/printer.d.ts +2 -1
- package/dist/formatter/print/printer.d.ts.map +1 -1
- package/dist/formatter/print/printer.js +6 -0
- package/dist/formatter/print/printer.js.map +1 -1
- package/dist/lib/decorators.d.ts +2 -1
- package/dist/lib/decorators.d.ts.map +1 -1
- package/dist/lib/decorators.js +5 -3
- package/dist/lib/decorators.js.map +1 -1
- package/dist/manifest.js +1 -1
- package/dist/server/tmlanguage.d.ts.map +1 -1
- package/dist/server/tmlanguage.js +11 -0
- package/dist/server/tmlanguage.js.map +1 -1
- package/dist/server/type-signature.js +2 -0
- package/dist/server/type-signature.js.map +1 -1
- package/dist/testing/test-host.d.ts.map +1 -1
- package/dist/testing/test-host.js +2 -1
- package/dist/testing/test-host.js.map +1 -1
- package/dist/typespec.tmLanguage +28 -0
- package/lib/decorators.tsp +27 -23
- package/lib/lib.tsp +1 -1
- package/package.json +1 -1
package/dist/core/checker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TypeNameOptions } from "./helpers/index.js";
|
|
2
2
|
import { Program, ProjectedProgram } from "./program.js";
|
|
3
|
-
import { BooleanLiteral, BooleanLiteralNode, Diagnostic, DiagnosticTarget, ErrorType, FunctionType, IdentifierNode, IntrinsicScalarName, JsSourceFileNode, LiteralNode, LiteralType, Model, ModelProperty, Namespace, NamespaceStatementNode, NeverType, Node, NumericLiteral, NumericLiteralNode, ProjectionNode, ProjectionStatementNode, Scalar, StdTypeName, StdTypes, StringLiteral, StringLiteralNode, Sym, Type, TypeReferenceNode, TypeSpecScriptNode, UnknownType, VoidType } from "./types.js";
|
|
3
|
+
import { BooleanLiteral, BooleanLiteralNode, Diagnostic, DiagnosticTarget, ErrorType, FunctionType, IdentifierNode, IntrinsicScalarName, JsSourceFileNode, LiteralNode, LiteralType, Model, ModelProperty, Namespace, NamespaceStatementNode, NeverType, Node, NumericLiteral, NumericLiteralNode, ProjectionNode, ProjectionStatementNode, Scalar, StdTypeName, StdTypes, StringLiteral, StringLiteralNode, Sym, Type, TypeReferenceNode, TypeSpecScriptNode, UnknownType, ValueType, VoidType } from "./types.js";
|
|
4
4
|
export type CreateTypeProps = Omit<Type, "isFinished" | keyof TypePrototype>;
|
|
5
5
|
export interface Checker {
|
|
6
6
|
typePrototype: TypePrototype;
|
|
@@ -49,7 +49,7 @@ export interface Checker {
|
|
|
49
49
|
* @param diagnosticTarget Target for the diagnostic, unless something better can be inferred.
|
|
50
50
|
* @returns [related, list of diagnostics]
|
|
51
51
|
*/
|
|
52
|
-
isTypeAssignableTo(source: Type, target: Type, diagnosticTarget: DiagnosticTarget): [boolean, Diagnostic[]];
|
|
52
|
+
isTypeAssignableTo(source: Type | ValueType, target: Type | ValueType, diagnosticTarget: DiagnosticTarget): [boolean, readonly Diagnostic[]];
|
|
53
53
|
/**
|
|
54
54
|
* Check if the given type is one of the built-in standard TypeSpec Types.
|
|
55
55
|
* @param type Type to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../core/checker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAqC,MAAM,oBAAoB,CAAC;AAGxF,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,EACnB,gBAAgB,EAChB,WAAW,EACX,WAAW,EAOX,KAAK,EAGL,aAAa,EAKb,SAAS,EACT,sBAAsB,EACtB,SAAS,EACT,IAAI,EAEJ,cAAc,EACd,kBAAkB,EAiBlB,cAAc,EAGd,uBAAuB,EAIvB,MAAM,EAEN,WAAW,EACX,QAAQ,EACR,aAAa,EACb,iBAAiB,EACjB,GAAG,EAYH,IAAI,EAIJ,iBAAiB,EACjB,kBAAkB,EAMlB,WAAW,
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../../core/checker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAqC,MAAM,oBAAoB,CAAC;AAGxF,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,EACnB,gBAAgB,EAChB,WAAW,EACX,WAAW,EAOX,KAAK,EAGL,aAAa,EAKb,SAAS,EACT,sBAAsB,EACtB,SAAS,EACT,IAAI,EAEJ,cAAc,EACd,kBAAkB,EAiBlB,cAAc,EAGd,uBAAuB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E,WAAW,CAAC;CACtB;AAED,UAAU,aAAa;IACrB,WAAW,EAAE,uBAAuB,EAAE,CAAC;IACvC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,EAAE,CAAC;CAC5D;AAED,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAExD,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,GAAG,CAAC;IAET;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAaD,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CA+uJvD;AAqFD;;;;;;;;;;;;;;;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,GAAG,gBAAgB,EACnC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,OAAO,GAC3C,KAAK,CAmCP;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS,CAcxF;AAED;;;;;;;GAOG;AACH,wBAAiB,uBAAuB,CAAC,KAAK,EAAE,KAAK,2CAapD;AAYD,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAEpF"}
|
package/dist/core/checker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $docFromComment, getDeprecated, getIndexer } from "../lib/decorators.js";
|
|
2
2
|
import { createSymbol, createSymbolTable } from "./binder.js";
|
|
3
|
-
import { ProjectionError, compilerAssert } from "./diagnostics.js";
|
|
3
|
+
import { ProjectionError, compilerAssert, reportDeprecated } from "./diagnostics.js";
|
|
4
4
|
import { validateInheritanceDiscriminatedUnions } from "./helpers/discriminator-utils.js";
|
|
5
5
|
import { getNamespaceFullName, getTypeName } from "./helpers/index.js";
|
|
6
6
|
import { createDiagnostic } from "./messages.js";
|
|
@@ -425,7 +425,7 @@ export function createChecker(program) {
|
|
|
425
425
|
node: node,
|
|
426
426
|
});
|
|
427
427
|
if (node.constraint) {
|
|
428
|
-
type.constraint =
|
|
428
|
+
type.constraint = getTypeOrValueTypeForNode(node.constraint);
|
|
429
429
|
}
|
|
430
430
|
if (node.default) {
|
|
431
431
|
type.default = checkTemplateParameterDefault(node.default, parentNode.templateParameters, index, type.constraint);
|
|
@@ -518,7 +518,7 @@ export function createChecker(program) {
|
|
|
518
518
|
return args;
|
|
519
519
|
}
|
|
520
520
|
function checkTemplateInstantiationArgs(node, args, declarations) {
|
|
521
|
-
var _a;
|
|
521
|
+
var _a, _b, _c;
|
|
522
522
|
if (args.length > declarations.length) {
|
|
523
523
|
reportCheckerDiagnostic(createDiagnostic({
|
|
524
524
|
code: "invalid-template-args",
|
|
@@ -538,7 +538,9 @@ export function createChecker(program) {
|
|
|
538
538
|
let [valueNode, value] = args[i];
|
|
539
539
|
if (declaredType.constraint) {
|
|
540
540
|
if (!checkTypeAssignable(value, declaredType.constraint, valueNode)) {
|
|
541
|
-
|
|
541
|
+
// TODO-TIM check if we expose this below
|
|
542
|
+
value =
|
|
543
|
+
((_a = declaredType.constraint) === null || _a === void 0 ? void 0 : _a.kind) === "Value" ? unknownType : declaredType.constraint;
|
|
542
544
|
}
|
|
543
545
|
}
|
|
544
546
|
values.push(value);
|
|
@@ -551,7 +553,11 @@ export function createChecker(program) {
|
|
|
551
553
|
}
|
|
552
554
|
else {
|
|
553
555
|
tooFew = true;
|
|
554
|
-
values.push(
|
|
556
|
+
values.push(
|
|
557
|
+
// TODO-TIM check if we expose this below
|
|
558
|
+
((_b = declaredType.constraint) === null || _b === void 0 ? void 0 : _b.kind) === "Value"
|
|
559
|
+
? unknownType
|
|
560
|
+
: (_c = declaredType.constraint) !== null && _c !== void 0 ? _c : unknownType);
|
|
555
561
|
}
|
|
556
562
|
}
|
|
557
563
|
}
|
|
@@ -783,6 +789,13 @@ export function createChecker(program) {
|
|
|
783
789
|
}
|
|
784
790
|
return unionType;
|
|
785
791
|
}
|
|
792
|
+
function checkValueOfExpression(node, mapper) {
|
|
793
|
+
const target = getTypeForNode(node.target, mapper);
|
|
794
|
+
return {
|
|
795
|
+
kind: "Value",
|
|
796
|
+
target,
|
|
797
|
+
};
|
|
798
|
+
}
|
|
786
799
|
/**
|
|
787
800
|
* Intersection produces a model type from the properties of its operands.
|
|
788
801
|
* So this doesn't work if we don't have a known set of properties (e.g.
|
|
@@ -857,10 +870,14 @@ export function createChecker(program) {
|
|
|
857
870
|
if (links.declaredType) {
|
|
858
871
|
return links.declaredType;
|
|
859
872
|
}
|
|
860
|
-
if (node.rest &&
|
|
873
|
+
if (node.rest &&
|
|
874
|
+
node.type &&
|
|
875
|
+
!(node.type.kind === SyntaxKind.ArrayExpression ||
|
|
876
|
+
(node.type.kind === SyntaxKind.ValueOfExpression &&
|
|
877
|
+
node.type.target.kind === SyntaxKind.ArrayExpression))) {
|
|
861
878
|
reportCheckerDiagnostic(createDiagnostic({ code: "rest-parameter-array", target: node.type }));
|
|
862
879
|
}
|
|
863
|
-
const type = node.type ?
|
|
880
|
+
const type = node.type ? getTypeOrValueTypeForNode(node.type) : unknownType;
|
|
864
881
|
const parameterType = createType({
|
|
865
882
|
kind: "FunctionParameter",
|
|
866
883
|
node,
|
|
@@ -873,6 +890,12 @@ export function createChecker(program) {
|
|
|
873
890
|
linkType(links, parameterType, mapper);
|
|
874
891
|
return parameterType;
|
|
875
892
|
}
|
|
893
|
+
function getTypeOrValueTypeForNode(node, mapper) {
|
|
894
|
+
if (node.kind === SyntaxKind.ValueOfExpression) {
|
|
895
|
+
return checkValueOfExpression(node, mapper);
|
|
896
|
+
}
|
|
897
|
+
return getTypeForNode(node, mapper);
|
|
898
|
+
}
|
|
876
899
|
function mergeModelTypes(node, options, mapper) {
|
|
877
900
|
const properties = createRekeyableMap();
|
|
878
901
|
const intersection = createType({
|
|
@@ -2192,7 +2215,7 @@ export function createChecker(program) {
|
|
|
2192
2215
|
if (doc) {
|
|
2193
2216
|
type.decorators.unshift({
|
|
2194
2217
|
decorator: $docFromComment,
|
|
2195
|
-
args: [{ value: createLiteralType(doc) }],
|
|
2218
|
+
args: [{ value: createLiteralType(doc), jsValue: doc }],
|
|
2196
2219
|
});
|
|
2197
2220
|
}
|
|
2198
2221
|
}
|
|
@@ -2245,7 +2268,7 @@ export function createChecker(program) {
|
|
|
2245
2268
|
return undefined;
|
|
2246
2269
|
}
|
|
2247
2270
|
const symbolLinks = getSymbolLinks(sym);
|
|
2248
|
-
|
|
2271
|
+
let args = checkDecoratorArguments(decNode, mapper);
|
|
2249
2272
|
let hasError = false;
|
|
2250
2273
|
if (symbolLinks.declaredType === undefined) {
|
|
2251
2274
|
const decoratorDeclNode = sym.declarations.find((x) => x.kind === SyntaxKind.DecoratorDeclarationStatement);
|
|
@@ -2256,19 +2279,20 @@ export function createChecker(program) {
|
|
|
2256
2279
|
if (symbolLinks.declaredType) {
|
|
2257
2280
|
compilerAssert(symbolLinks.declaredType.kind === "Decorator", "Expected to find a decorator type.");
|
|
2258
2281
|
// Means we have a decorator declaration.
|
|
2259
|
-
hasError = checkDecoratorUsage(targetType, symbolLinks.declaredType, args, decNode);
|
|
2282
|
+
[hasError, args] = checkDecoratorUsage(targetType, symbolLinks.declaredType, args, decNode);
|
|
2260
2283
|
}
|
|
2261
2284
|
if (hasError) {
|
|
2262
2285
|
return undefined;
|
|
2263
2286
|
}
|
|
2264
2287
|
return {
|
|
2288
|
+
definition: symbolLinks.declaredType,
|
|
2265
2289
|
decorator: (_a = sym.value) !== null && _a !== void 0 ? _a : ((...args) => { }),
|
|
2266
2290
|
node: decNode,
|
|
2267
2291
|
args,
|
|
2268
2292
|
};
|
|
2269
2293
|
}
|
|
2270
2294
|
function checkDecoratorUsage(targetType, declaration, args, decoratorNode) {
|
|
2271
|
-
var _a
|
|
2295
|
+
var _a;
|
|
2272
2296
|
let hasError = false;
|
|
2273
2297
|
const [targetValid] = isTypeAssignableTo(targetType, declaration.target.type, decoratorNode);
|
|
2274
2298
|
if (!targetValid) {
|
|
@@ -2306,13 +2330,18 @@ export function createChecker(program) {
|
|
|
2306
2330
|
}));
|
|
2307
2331
|
}
|
|
2308
2332
|
}
|
|
2333
|
+
const resolvedArgs = [];
|
|
2309
2334
|
for (const [index, parameter] of declaration.parameters.entries()) {
|
|
2310
2335
|
if (parameter.rest) {
|
|
2311
|
-
const restType = parameter.type.kind === "
|
|
2336
|
+
const restType = getIndexType(parameter.type.kind === "Value" ? parameter.type.target : parameter.type);
|
|
2312
2337
|
if (restType) {
|
|
2313
2338
|
for (let i = index; i < args.length; i++) {
|
|
2314
2339
|
const arg = args[i];
|
|
2315
2340
|
if (arg && arg.value) {
|
|
2341
|
+
resolvedArgs.push({
|
|
2342
|
+
...arg,
|
|
2343
|
+
jsValue: resolveDecoratorArgJsValue(arg.value, parameter.type.kind === "Value"),
|
|
2344
|
+
});
|
|
2316
2345
|
if (!checkArgumentAssignable(arg.value, restType, arg.node)) {
|
|
2317
2346
|
hasError = true;
|
|
2318
2347
|
}
|
|
@@ -2323,12 +2352,28 @@ export function createChecker(program) {
|
|
|
2323
2352
|
}
|
|
2324
2353
|
const arg = args[index];
|
|
2325
2354
|
if (arg && arg.value) {
|
|
2355
|
+
resolvedArgs.push({
|
|
2356
|
+
...arg,
|
|
2357
|
+
jsValue: resolveDecoratorArgJsValue(arg.value, parameter.type.kind === "Value"),
|
|
2358
|
+
});
|
|
2326
2359
|
if (!checkArgumentAssignable(arg.value, parameter.type, arg.node)) {
|
|
2327
2360
|
hasError = true;
|
|
2328
2361
|
}
|
|
2329
2362
|
}
|
|
2330
2363
|
}
|
|
2331
|
-
return hasError;
|
|
2364
|
+
return [hasError, resolvedArgs];
|
|
2365
|
+
}
|
|
2366
|
+
function getIndexType(type) {
|
|
2367
|
+
var _a;
|
|
2368
|
+
return type.kind === "Model" ? (_a = type.indexer) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
2369
|
+
}
|
|
2370
|
+
function resolveDecoratorArgJsValue(value, valueOf) {
|
|
2371
|
+
if (valueOf) {
|
|
2372
|
+
if (value.kind === "Boolean" || value.kind === "String" || value.kind === "Number") {
|
|
2373
|
+
return literalTypeToValue(value);
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
return value;
|
|
2332
2377
|
}
|
|
2333
2378
|
function checkArgumentAssignable(argumentType, parameterType, diagnosticTarget) {
|
|
2334
2379
|
const [valid] = isTypeAssignableTo(argumentType, parameterType, diagnosticTarget);
|
|
@@ -2366,6 +2411,7 @@ export function createChecker(program) {
|
|
|
2366
2411
|
const type = getTypeForNode(argNode, mapper);
|
|
2367
2412
|
return {
|
|
2368
2413
|
value: type,
|
|
2414
|
+
jsValue: type,
|
|
2369
2415
|
node: argNode,
|
|
2370
2416
|
};
|
|
2371
2417
|
});
|
|
@@ -3574,11 +3620,26 @@ export function createChecker(program) {
|
|
|
3574
3620
|
*/
|
|
3575
3621
|
function isTypeAssignableTo(source, target, diagnosticTarget) {
|
|
3576
3622
|
var _a;
|
|
3623
|
+
// BACKCOMPAT: Added May 2023 sprint, to be removed by June 2023 sprint
|
|
3624
|
+
if (source.kind === "TemplateParameter" && source.constraint && target.kind === "Value") {
|
|
3625
|
+
const [assignable] = isTypeAssignableTo(source.constraint, target.target, diagnosticTarget);
|
|
3626
|
+
if (assignable) {
|
|
3627
|
+
const constraint = getTypeName(source.constraint);
|
|
3628
|
+
reportDeprecated(program, `Template constrainted to '${constraint}' will not be assignable to '${getTypeName(target)}' in the future. Update the constraint to be 'valueof ${constraint}'`, diagnosticTarget);
|
|
3629
|
+
return [true, []];
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3577
3632
|
if (source.kind === "TemplateParameter") {
|
|
3578
3633
|
source = (_a = source.constraint) !== null && _a !== void 0 ? _a : unknownType;
|
|
3579
3634
|
}
|
|
3580
3635
|
if (source === target)
|
|
3581
3636
|
return [true, []];
|
|
3637
|
+
if (target.kind === "Value") {
|
|
3638
|
+
return isAssignableToValueType(source, target, diagnosticTarget);
|
|
3639
|
+
}
|
|
3640
|
+
if (source.kind === "Value") {
|
|
3641
|
+
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3642
|
+
}
|
|
3582
3643
|
const isSimpleTypeRelated = isSimpleTypeAssignableTo(source, target);
|
|
3583
3644
|
if (isSimpleTypeRelated === true) {
|
|
3584
3645
|
return [true, []];
|
|
@@ -3641,6 +3702,19 @@ export function createChecker(program) {
|
|
|
3641
3702
|
}
|
|
3642
3703
|
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3643
3704
|
}
|
|
3705
|
+
function isAssignableToValueType(source, target, diagnosticTarget) {
|
|
3706
|
+
if (source.kind === "Value") {
|
|
3707
|
+
return isTypeAssignableTo(source.target, target.target, diagnosticTarget);
|
|
3708
|
+
}
|
|
3709
|
+
const [assignable, diagnostics] = isTypeAssignableTo(source, target.target, diagnosticTarget);
|
|
3710
|
+
if (!assignable) {
|
|
3711
|
+
return [assignable, diagnostics];
|
|
3712
|
+
}
|
|
3713
|
+
if (!isValueType(source)) {
|
|
3714
|
+
return [false, [createUnassignableDiagnostic(source, target, diagnosticTarget)]];
|
|
3715
|
+
}
|
|
3716
|
+
return [true, []];
|
|
3717
|
+
}
|
|
3644
3718
|
function isReflectionType(type) {
|
|
3645
3719
|
var _a, _b, _c;
|
|
3646
3720
|
return (type.kind === "Model" &&
|
|
@@ -4160,7 +4234,7 @@ function finishTypeForProgramAndChecker(program, typePrototype, typeDef) {
|
|
|
4160
4234
|
if (docComment) {
|
|
4161
4235
|
typeDef.decorators.unshift({
|
|
4162
4236
|
decorator: $docFromComment,
|
|
4163
|
-
args: [{ value: program.checker.createLiteralType(docComment) }],
|
|
4237
|
+
args: [{ value: program.checker.createLiteralType(docComment), jsValue: docComment }],
|
|
4164
4238
|
});
|
|
4165
4239
|
}
|
|
4166
4240
|
for (const decApp of typeDef.decorators) {
|
|
@@ -4182,7 +4256,7 @@ function applyDecoratorToType(program, decApp, target) {
|
|
|
4182
4256
|
}
|
|
4183
4257
|
// peel `fn` off to avoid setting `this`.
|
|
4184
4258
|
try {
|
|
4185
|
-
const args =
|
|
4259
|
+
const args = decApp.args.map((x) => x.jsValue);
|
|
4186
4260
|
const fn = decApp.decorator;
|
|
4187
4261
|
const context = createDecoratorContext(program, decApp);
|
|
4188
4262
|
fn(context, target, ...args);
|