@typespec/compiler 0.52.0-dev.0 → 0.52.0-dev.10
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/.scripts/build-init-templates.d.ts +2 -0
- package/dist/.scripts/build-init-templates.d.ts.map +1 -0
- package/dist/.scripts/build-init-templates.js +38 -0
- package/dist/.scripts/build-init-templates.js.map +1 -0
- package/dist/.scripts/helpers.d.ts +4 -0
- package/dist/.scripts/helpers.d.ts.map +1 -0
- package/dist/.scripts/helpers.js +44 -0
- package/dist/.scripts/helpers.js.map +1 -0
- package/dist/manifest.js +2 -2
- package/dist/src/config/config-interpolation.js.map +1 -1
- package/dist/src/config/config-loader.d.ts.map +1 -1
- package/dist/src/config/config-loader.js +1 -1
- package/dist/src/config/config-loader.js.map +1 -1
- package/dist/src/config/config-schema.js +1 -1
- package/dist/src/config/config-schema.js.map +1 -1
- package/dist/src/config/config-to-options.js.map +1 -1
- package/dist/src/core/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +1 -1
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/charcode.d.ts +1 -1
- package/dist/src/core/charcode.d.ts.map +1 -1
- package/dist/src/core/charcode.js.map +1 -1
- package/dist/src/core/checker.d.ts +4 -0
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +155 -65
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/actions/compile/args.js.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.js.map +1 -1
- package/dist/src/core/cli/actions/compile/watch.js.map +1 -1
- package/dist/src/core/cli/actions/format.js +1 -1
- package/dist/src/core/cli/actions/format.js.map +1 -1
- package/dist/src/core/cli/actions/init.d.ts +1 -0
- package/dist/src/core/cli/actions/init.d.ts.map +1 -1
- package/dist/src/core/cli/actions/init.js +1 -1
- package/dist/src/core/cli/actions/init.js.map +1 -1
- package/dist/src/core/cli/actions/vs.js.map +1 -1
- package/dist/src/core/cli/actions/vscode.js.map +1 -1
- package/dist/src/core/cli/cli.js +6 -1
- package/dist/src/core/cli/cli.js.map +1 -1
- package/dist/src/core/cli/install-vsix.js.map +1 -1
- package/dist/src/core/cli/utils.d.ts.map +1 -1
- package/dist/src/core/cli/utils.js +3 -0
- package/dist/src/core/cli/utils.js.map +1 -1
- package/dist/src/core/decorator-utils.js.map +1 -1
- package/dist/src/core/deprecation.js.map +1 -1
- package/dist/src/core/diagnostic-creator.d.ts +11 -0
- package/dist/src/core/diagnostic-creator.d.ts.map +1 -0
- package/dist/src/core/diagnostic-creator.js +48 -0
- package/dist/src/core/diagnostic-creator.js.map +1 -0
- package/dist/src/core/diagnostics.d.ts +2 -11
- package/dist/src/core/diagnostics.d.ts.map +1 -1
- package/dist/src/core/diagnostics.js +3 -52
- package/dist/src/core/diagnostics.js.map +1 -1
- package/dist/src/core/entrypoint-resolution.js.map +1 -1
- package/dist/src/core/external-error.js.map +1 -1
- package/dist/src/core/fetch.js.map +1 -1
- package/dist/src/core/formatter-fs.d.ts +1 -1
- package/dist/src/core/formatter-fs.d.ts.map +1 -1
- package/dist/src/core/formatter-fs.js +1 -1
- package/dist/src/core/formatter-fs.js.map +1 -1
- package/dist/src/core/helpers/discriminator-utils.js.map +1 -1
- package/dist/src/core/helpers/location-context.js +1 -1
- package/dist/src/core/helpers/location-context.js.map +1 -1
- package/dist/src/core/helpers/operation-utils.js.map +1 -1
- package/dist/src/core/helpers/path-interpolation.js.map +1 -1
- package/dist/src/core/helpers/projected-names-utils.js.map +1 -1
- package/dist/src/core/helpers/string-template-utils.js.map +1 -1
- package/dist/src/core/helpers/type-name-utils.js.map +1 -1
- package/dist/src/core/helpers/usage-resolver.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -1
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +1 -1
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/install.js.map +1 -1
- package/dist/src/core/library.d.ts +4 -3
- package/dist/src/core/library.d.ts.map +1 -1
- package/dist/src/core/library.js +14 -15
- package/dist/src/core/library.js.map +1 -1
- package/dist/src/core/linter.d.ts.map +1 -1
- package/dist/src/core/linter.js +12 -6
- package/dist/src/core/linter.js.map +1 -1
- package/dist/src/core/logger/console-sink.js.map +1 -1
- package/dist/src/core/logger/logger.d.ts +1 -1
- package/dist/src/core/logger/logger.d.ts.map +1 -1
- package/dist/src/core/logger/logger.js.map +1 -1
- package/dist/src/core/logger/tracer.js.map +1 -1
- package/dist/src/core/messages.d.ts +41 -8
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +12 -3
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/module-resolver.js.map +1 -1
- package/dist/src/core/node-host.d.ts.map +1 -1
- package/dist/src/core/node-host.js +4 -3
- package/dist/src/core/node-host.js.map +1 -1
- package/dist/src/core/param-message.d.ts +3 -0
- package/dist/src/core/param-message.d.ts.map +1 -0
- package/dist/src/core/param-message.js +16 -0
- package/dist/src/core/param-message.js.map +1 -0
- package/dist/src/core/parser.d.ts +5 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +56 -2
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/path-utils.js.map +1 -1
- package/dist/src/core/program.js +8 -5
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/projection-members.js +2 -2
- package/dist/src/core/projection-members.js.map +1 -1
- package/dist/src/core/projector.js.map +1 -1
- package/dist/src/core/scanner.js.map +1 -1
- package/dist/src/core/schema-validator.js.map +1 -1
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/type-utils.js.map +1 -1
- package/dist/src/core/types.d.ts +31 -15
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +7 -5
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/core/util.d.ts +1 -2
- package/dist/src/core/util.d.ts.map +1 -1
- package/dist/src/core/util.js +2 -3
- package/dist/src/core/util.js.map +1 -1
- package/dist/src/emitter-framework/asset-emitter.js.map +1 -1
- package/dist/src/emitter-framework/builders/array-builder.js.map +1 -1
- package/dist/src/emitter-framework/builders/object-builder.js.map +1 -1
- package/dist/src/emitter-framework/builders/string-builder.js.map +1 -1
- package/dist/src/emitter-framework/custom-key-map.js.map +1 -1
- package/dist/src/emitter-framework/placeholder.js.map +1 -1
- package/dist/src/emitter-framework/ref-scope.js.map +1 -1
- package/dist/src/emitter-framework/reference-cycle.d.ts +1 -1
- package/dist/src/emitter-framework/reference-cycle.d.ts.map +1 -1
- package/dist/src/emitter-framework/reference-cycle.js +1 -1
- package/dist/src/emitter-framework/reference-cycle.js.map +1 -1
- package/dist/src/emitter-framework/type-emitter.js.map +1 -1
- package/dist/src/emitter-framework/types.js.map +1 -1
- package/dist/src/formatter/parser.js.map +1 -1
- package/dist/src/formatter/print/comment-handler.js.map +1 -1
- package/dist/src/formatter/print/needs-parens.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts +2 -1
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +12 -0
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/init/core-templates.d.ts +6 -0
- package/dist/src/init/core-templates.d.ts.map +1 -0
- package/dist/src/init/core-templates.js +11 -0
- package/dist/src/init/core-templates.js.map +1 -0
- package/dist/src/init/file-templating.d.ts +25 -0
- package/dist/src/init/file-templating.d.ts.map +1 -0
- package/dist/src/init/file-templating.js +39 -0
- package/dist/src/init/file-templating.js.map +1 -0
- package/dist/src/init/init-template.d.ts +3 -3
- package/dist/src/init/init-template.d.ts.map +1 -1
- package/dist/src/init/init-template.js +4 -3
- package/dist/src/init/init-template.js.map +1 -1
- package/dist/src/init/init.d.ts +11 -47
- package/dist/src/init/init.d.ts.map +1 -1
- package/dist/src/init/init.js +32 -190
- package/dist/src/init/init.js.map +1 -1
- package/dist/src/init/scaffold.d.ts +39 -0
- package/dist/src/init/scaffold.d.ts.map +1 -0
- package/dist/src/init/scaffold.js +132 -0
- package/dist/src/init/scaffold.js.map +1 -0
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/manifest.d.ts.map +1 -1
- package/dist/src/manifest.js +10 -3
- package/dist/src/manifest.js.map +1 -1
- package/dist/src/runner.js.map +1 -1
- package/dist/src/server/completion.js +3 -3
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/server-utils.js.map +1 -1
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +4 -0
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/server/symbol-structure.js.map +1 -1
- package/dist/src/server/tmlanguage.js +5 -5
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/src/server/type-details.js.map +1 -1
- package/dist/src/server/type-signature.js.map +1 -1
- package/dist/src/testing/expect.js.map +1 -1
- package/dist/src/testing/test-host.js +2 -2
- package/dist/src/testing/test-host.js.map +1 -1
- package/dist/src/testing/test-server-host.js +1 -1
- package/dist/src/testing/test-server-host.js.map +1 -1
- package/dist/src/testing/test-utils.d.ts +2 -0
- package/dist/src/testing/test-utils.d.ts.map +1 -1
- package/dist/src/testing/test-utils.js +8 -3
- package/dist/src/testing/test-utils.js.map +1 -1
- package/dist/src/yaml/diagnostics.js.map +1 -1
- package/dist/src/yaml/parser.js.map +1 -1
- package/dist/typespec.tmLanguage +8 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.e2e.d.ts +3 -0
- package/dist/vitest.config.e2e.d.ts.map +1 -0
- package/dist/vitest.config.e2e.js +16 -0
- package/dist/vitest.config.e2e.js.map +1 -0
- package/dist/vitest.config.js +15 -0
- package/dist/vitest.config.js.map +1 -0
- package/lib/decorators.tsp +3 -3
- package/lib/lib.tsp +30 -25
- package/package.json +25 -22
- package/templates/__snapshots__/emitter-ts/.eslintrc.yml +14 -0
- package/templates/__snapshots__/emitter-ts/package.json +37 -0
- package/templates/__snapshots__/emitter-ts/prettierrc.yaml +8 -0
- package/templates/__snapshots__/emitter-ts/src/emitter.ts +10 -0
- package/templates/__snapshots__/emitter-ts/src/index.ts +2 -0
- package/templates/__snapshots__/emitter-ts/src/lib.ts +8 -0
- package/templates/__snapshots__/emitter-ts/src/testing/index.ts +10 -0
- package/templates/__snapshots__/emitter-ts/test/hello.test.ts +10 -0
- package/templates/__snapshots__/emitter-ts/test/test-host.ts +47 -0
- package/templates/__snapshots__/emitter-ts/tsconfig.json +17 -0
- package/templates/emitter-ts/.eslintrc.yml +14 -0
- package/templates/emitter-ts/package.json +37 -0
- package/templates/emitter-ts/prettierrc.yaml +8 -0
- package/templates/emitter-ts/src/emitter.ts +10 -0
- package/templates/emitter-ts/src/index.ts +2 -0
- package/templates/emitter-ts/src/lib.ts +8 -0
- package/templates/emitter-ts/src/testing/index.ts +10 -0
- package/templates/emitter-ts/test/hello.test.ts +10 -0
- package/templates/emitter-ts/test/test-host.ts.mu +47 -0
- package/templates/emitter-ts/tsconfig.json +17 -0
- package/templates/scaffolding.json +79 -0
package/dist/src/core/checker.js
CHANGED
|
@@ -12,7 +12,7 @@ import { validateInheritanceDiscriminatedUnions } from "./helpers/discriminator-
|
|
|
12
12
|
import { getNamespaceFullName, getTypeName, stringTemplateToString, } from "./helpers/index.js";
|
|
13
13
|
import { isStringTemplateSerializable } from "./helpers/string-template-utils.js";
|
|
14
14
|
import { createDiagnostic } from "./messages.js";
|
|
15
|
-
import { getIdentifierContext, hasParseError, visitChildren } from "./parser.js";
|
|
15
|
+
import { exprIsBareIdentifier, getIdentifierContext, hasParseError, visitChildren, } from "./parser.js";
|
|
16
16
|
import { createProjectionMembers } from "./projection-members.js";
|
|
17
17
|
import { getFullyQualifiedSymbolName, getParentTemplateNode, isNeverType, isTemplateInstance, isUnknownType, isVoidType, } from "./type-utils.js";
|
|
18
18
|
import { IdentifierKind, SyntaxKind, } from "./types.js";
|
|
@@ -372,6 +372,8 @@ export function createChecker(program) {
|
|
|
372
372
|
return checkFunctionDeclaration(node, mapper);
|
|
373
373
|
case SyntaxKind.TypeReference:
|
|
374
374
|
return checkTypeReference(node, mapper);
|
|
375
|
+
case SyntaxKind.TemplateArgument:
|
|
376
|
+
return checkTemplateArgument(node, mapper);
|
|
375
377
|
case SyntaxKind.TemplateParameterDeclaration:
|
|
376
378
|
return checkTemplateParameterDeclaration(node, mapper);
|
|
377
379
|
case SyntaxKind.ProjectionStatement:
|
|
@@ -498,6 +500,9 @@ export function createChecker(program) {
|
|
|
498
500
|
const type = checkTypeReferenceSymbol(sym, node, mapper, instantiateTemplate);
|
|
499
501
|
return type;
|
|
500
502
|
}
|
|
503
|
+
function checkTemplateArgument(node, mapper) {
|
|
504
|
+
return getTypeForNode(node.argument, mapper);
|
|
505
|
+
}
|
|
501
506
|
function resolveTypeReference(node) {
|
|
502
507
|
const oldDiagnosticHook = onCheckerDiagnostic;
|
|
503
508
|
const diagnostics = [];
|
|
@@ -560,69 +565,117 @@ export function createChecker(program) {
|
|
|
560
565
|
return false;
|
|
561
566
|
}
|
|
562
567
|
}
|
|
563
|
-
function
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
568
|
+
function checkTemplateInstantiationArgs(node, args, decls, mapper) {
|
|
569
|
+
var _a, _b, _c, _d;
|
|
570
|
+
var _e;
|
|
571
|
+
const params = new Map();
|
|
572
|
+
const positional = [];
|
|
573
|
+
const initMap = new Map(decls.map(function (decl) {
|
|
574
|
+
const declaredType = getTypeForNode(decl);
|
|
575
|
+
positional.push(declaredType);
|
|
576
|
+
params.set(decl.id.sv, declaredType);
|
|
577
|
+
return [
|
|
578
|
+
declaredType,
|
|
579
|
+
{
|
|
580
|
+
decl,
|
|
581
|
+
checkArgument: null,
|
|
582
|
+
},
|
|
583
|
+
];
|
|
584
|
+
}));
|
|
585
|
+
let named = false;
|
|
586
|
+
for (const [arg, idx] of args.map((v, i) => [v, i])) {
|
|
587
|
+
function deferredCheck() {
|
|
588
|
+
return [arg, getTypeForNode(arg.argument, mapper)];
|
|
589
|
+
}
|
|
590
|
+
if (arg.name) {
|
|
591
|
+
named = true;
|
|
592
|
+
const param = params.get(arg.name.sv);
|
|
593
|
+
if (!param) {
|
|
594
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
595
|
+
code: "invalid-template-args",
|
|
596
|
+
messageId: "unknownName",
|
|
597
|
+
format: {
|
|
598
|
+
name: arg.name.sv,
|
|
599
|
+
},
|
|
600
|
+
target: arg,
|
|
601
|
+
}));
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (initMap.get(param).checkArgument !== null) {
|
|
605
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
606
|
+
code: "invalid-template-args",
|
|
607
|
+
messageId: "specifiedAgain",
|
|
608
|
+
format: {
|
|
609
|
+
name: arg.name.sv,
|
|
610
|
+
},
|
|
611
|
+
target: arg,
|
|
612
|
+
}));
|
|
613
|
+
continue;
|
|
599
614
|
}
|
|
600
|
-
|
|
615
|
+
initMap.get(param).checkArgument = deferredCheck;
|
|
601
616
|
}
|
|
602
617
|
else {
|
|
603
|
-
|
|
604
|
-
|
|
618
|
+
if (named) {
|
|
619
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
620
|
+
code: "invalid-template-args",
|
|
621
|
+
messageId: "positionalAfterNamed",
|
|
622
|
+
target: arg,
|
|
623
|
+
}));
|
|
624
|
+
// we just throw this arg away. any missing args will be filled with ErrorType
|
|
625
|
+
}
|
|
626
|
+
if (idx >= positional.length) {
|
|
627
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
628
|
+
code: "invalid-template-args",
|
|
629
|
+
messageId: "tooMany",
|
|
630
|
+
target: node,
|
|
631
|
+
}));
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
const param = positional[idx];
|
|
635
|
+
(_a = (_e = initMap.get(param)).checkArgument) !== null && _a !== void 0 ? _a : (_e.checkArgument = deferredCheck);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
const finalMap = initMap;
|
|
639
|
+
const mapperParams = [];
|
|
640
|
+
const mapperArgs = [];
|
|
641
|
+
for (const [param, { decl, checkArgument: init }] of [...initMap]) {
|
|
642
|
+
function commit(param, type) {
|
|
643
|
+
finalMap.set(param, type);
|
|
644
|
+
mapperParams.push(param);
|
|
645
|
+
mapperArgs.push(type);
|
|
646
|
+
}
|
|
647
|
+
if (init === null) {
|
|
648
|
+
const argumentMapper = createTypeMapper(mapperParams, mapperArgs);
|
|
649
|
+
const defaultValue = getResolvedTypeParameterDefault(param, decl, argumentMapper);
|
|
605
650
|
if (defaultValue) {
|
|
606
|
-
|
|
651
|
+
commit(param, defaultValue);
|
|
607
652
|
}
|
|
608
653
|
else {
|
|
609
|
-
|
|
610
|
-
|
|
654
|
+
reportCheckerDiagnostic(createDiagnostic({
|
|
655
|
+
code: "invalid-template-args",
|
|
656
|
+
messageId: "missing",
|
|
657
|
+
format: {
|
|
658
|
+
name: decl.id.sv,
|
|
659
|
+
},
|
|
660
|
+
target: node,
|
|
661
|
+
}));
|
|
611
662
|
// TODO-TIM check if we expose this below
|
|
612
|
-
((_b =
|
|
613
|
-
? unknownType
|
|
614
|
-
: (_c = declaredType.constraint) !== null && _c !== void 0 ? _c : unknownType);
|
|
663
|
+
commit(param, ((_b = param.constraint) === null || _b === void 0 ? void 0 : _b.kind) === "Value" ? unknownType : (_c = param.constraint) !== null && _c !== void 0 ? _c : unknownType);
|
|
615
664
|
}
|
|
665
|
+
continue;
|
|
616
666
|
}
|
|
667
|
+
const [argNode, type] = init();
|
|
668
|
+
if (param.constraint) {
|
|
669
|
+
if (!checkTypeAssignable(type, param.constraint, argNode)) {
|
|
670
|
+
// TODO-TIM check if we expose this below
|
|
671
|
+
const effectiveType = ((_d = param.constraint) === null || _d === void 0 ? void 0 : _d.kind) === "Value" ? unknownType : param.constraint;
|
|
672
|
+
commit(param, effectiveType);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
commit(param, type);
|
|
617
677
|
}
|
|
618
|
-
|
|
619
|
-
reportCheckerDiagnostic(createDiagnostic({
|
|
620
|
-
code: "invalid-template-args",
|
|
621
|
-
messageId: "tooFew",
|
|
622
|
-
target: node,
|
|
623
|
-
}));
|
|
624
|
-
}
|
|
625
|
-
return [params, values];
|
|
678
|
+
return finalMap;
|
|
626
679
|
}
|
|
627
680
|
/**
|
|
628
681
|
* Check and resolve the type for the given symbol + node.
|
|
@@ -641,9 +694,9 @@ export function createChecker(program) {
|
|
|
641
694
|
reportCheckerDiagnostic(createDiagnostic({ code: "invalid-type-ref", messageId: "function", target: sym }));
|
|
642
695
|
return errorType;
|
|
643
696
|
}
|
|
697
|
+
const argumentNodes = node.kind === SyntaxKind.TypeReference ? node.arguments : [];
|
|
644
698
|
const symbolLinks = getSymbolLinks(sym);
|
|
645
699
|
let baseType;
|
|
646
|
-
const args = checkTypeReferenceArgs(node, mapper);
|
|
647
700
|
if (sym.flags &
|
|
648
701
|
(2 /* SymbolFlags.Model */ |
|
|
649
702
|
8 /* SymbolFlags.Scalar */ |
|
|
@@ -653,7 +706,7 @@ export function createChecker(program) {
|
|
|
653
706
|
512 /* SymbolFlags.Union */)) {
|
|
654
707
|
const decl = sym.declarations[0];
|
|
655
708
|
if (!isTemplatedNode(decl)) {
|
|
656
|
-
if (
|
|
709
|
+
if (argumentNodes.length > 0) {
|
|
657
710
|
reportCheckerDiagnostic(createDiagnostic({
|
|
658
711
|
code: "invalid-template-args",
|
|
659
712
|
messageId: "notTemplate",
|
|
@@ -677,13 +730,13 @@ export function createChecker(program) {
|
|
|
677
730
|
else {
|
|
678
731
|
const declaredType = getOrCheckDeclaredType(sym, decl, mapper);
|
|
679
732
|
const templateParameters = decl.templateParameters;
|
|
680
|
-
const
|
|
681
|
-
baseType = getOrInstantiateTemplate(decl,
|
|
733
|
+
const instantiation = checkTemplateInstantiationArgs(node, argumentNodes, templateParameters, mapper);
|
|
734
|
+
baseType = getOrInstantiateTemplate(decl, [...instantiation.keys()], [...instantiation.values()], declaredType.templateMapper, instantiateTemplates);
|
|
682
735
|
}
|
|
683
736
|
}
|
|
684
737
|
else {
|
|
685
738
|
// some other kind of reference
|
|
686
|
-
if (
|
|
739
|
+
if (argumentNodes.length > 0) {
|
|
687
740
|
reportCheckerDiagnostic(createDiagnostic({
|
|
688
741
|
code: "invalid-template-args",
|
|
689
742
|
messageId: "notTemplate",
|
|
@@ -1356,16 +1409,30 @@ export function createChecker(program) {
|
|
|
1356
1409
|
}
|
|
1357
1410
|
sym = resolveTypeReferenceSym(ref, mapper, resolveDecorator);
|
|
1358
1411
|
break;
|
|
1412
|
+
case IdentifierKind.TemplateArgument:
|
|
1413
|
+
const templates = getTemplateDeclarationsForArgument(node, mapper);
|
|
1414
|
+
const firstMatchingParameter = templates
|
|
1415
|
+
.flatMap((t) => t.templateParameters)
|
|
1416
|
+
.find((p) => p.id.sv === id.sv);
|
|
1417
|
+
if (firstMatchingParameter) {
|
|
1418
|
+
sym = getMergedSymbol(firstMatchingParameter.symbol);
|
|
1419
|
+
}
|
|
1420
|
+
break;
|
|
1359
1421
|
default:
|
|
1360
1422
|
const _assertNever = kind;
|
|
1361
1423
|
compilerAssert(false, "Unreachable");
|
|
1362
1424
|
}
|
|
1363
1425
|
return (_c = sym === null || sym === void 0 ? void 0 : sym.symbolSource) !== null && _c !== void 0 ? _c : sym;
|
|
1364
1426
|
}
|
|
1427
|
+
function getTemplateDeclarationsForArgument(node, mapper) {
|
|
1428
|
+
var _a;
|
|
1429
|
+
const resolved = resolveTypeReferenceSym(node.parent, mapper, false);
|
|
1430
|
+
return ((_a = resolved === null || resolved === void 0 ? void 0 : resolved.declarations.filter((n) => isTemplatedNode(n))) !== null && _a !== void 0 ? _a : []);
|
|
1431
|
+
}
|
|
1365
1432
|
function resolveCompletions(identifier) {
|
|
1366
|
-
var _a, _b;
|
|
1433
|
+
var _a, _b, _c;
|
|
1367
1434
|
const completions = new Map();
|
|
1368
|
-
const { kind } = getIdentifierContext(identifier);
|
|
1435
|
+
const { kind, node: ancestor } = getIdentifierContext(identifier);
|
|
1369
1436
|
switch (kind) {
|
|
1370
1437
|
case IdentifierKind.Using:
|
|
1371
1438
|
case IdentifierKind.Decorator:
|
|
@@ -1376,6 +1443,15 @@ export function createChecker(program) {
|
|
|
1376
1443
|
return completions; // not implemented
|
|
1377
1444
|
case IdentifierKind.Declaration:
|
|
1378
1445
|
return completions; // cannot complete, name can be chosen arbitrarily
|
|
1446
|
+
case IdentifierKind.TemplateArgument: {
|
|
1447
|
+
const templates = getTemplateDeclarationsForArgument(ancestor, undefined);
|
|
1448
|
+
for (const template of templates) {
|
|
1449
|
+
for (const param of template.templateParameters) {
|
|
1450
|
+
addCompletion(param.id.sv, param.symbol);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return completions;
|
|
1454
|
+
}
|
|
1379
1455
|
default:
|
|
1380
1456
|
const _assertNever = kind;
|
|
1381
1457
|
compilerAssert(false, "Unreachable");
|
|
@@ -1399,6 +1475,19 @@ export function createChecker(program) {
|
|
|
1399
1475
|
}
|
|
1400
1476
|
}
|
|
1401
1477
|
else {
|
|
1478
|
+
// We will only add template arguments if the template isn't already named
|
|
1479
|
+
// to avoid completing the name of the argument again.
|
|
1480
|
+
if (kind === IdentifierKind.TypeReference &&
|
|
1481
|
+
exprIsBareIdentifier(ancestor) &&
|
|
1482
|
+
((_c = ancestor.parent) === null || _c === void 0 ? void 0 : _c.kind) === SyntaxKind.TemplateArgument &&
|
|
1483
|
+
ancestor.parent.name === undefined) {
|
|
1484
|
+
const templates = getTemplateDeclarationsForArgument(ancestor.parent, undefined);
|
|
1485
|
+
for (const template of templates) {
|
|
1486
|
+
for (const param of template.templateParameters) {
|
|
1487
|
+
addCompletion(param.id.sv, param.symbol, { suffix: " = " });
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1402
1491
|
let scope = identifier.parent;
|
|
1403
1492
|
while (scope && scope.kind !== SyntaxKind.TypeSpecScript) {
|
|
1404
1493
|
if (scope.symbol && scope.symbol.exports) {
|
|
@@ -1444,7 +1533,7 @@ export function createChecker(program) {
|
|
|
1444
1533
|
}
|
|
1445
1534
|
}
|
|
1446
1535
|
}
|
|
1447
|
-
function addCompletion(key, sym) {
|
|
1536
|
+
function addCompletion(key, sym, options = {}) {
|
|
1448
1537
|
if (sym.symbolSource) {
|
|
1449
1538
|
sym = sym.symbolSource;
|
|
1450
1539
|
}
|
|
@@ -1455,7 +1544,7 @@ export function createChecker(program) {
|
|
|
1455
1544
|
key = key.slice(1);
|
|
1456
1545
|
}
|
|
1457
1546
|
if (!completions.has(key)) {
|
|
1458
|
-
completions.set(key, { sym });
|
|
1547
|
+
completions.set(key, { ...options, sym });
|
|
1459
1548
|
}
|
|
1460
1549
|
}
|
|
1461
1550
|
function shouldAddCompletion(sym) {
|
|
@@ -1469,6 +1558,8 @@ export function createChecker(program) {
|
|
|
1469
1558
|
case IdentifierKind.TypeReference:
|
|
1470
1559
|
// Do not return functions or decorators when completing types
|
|
1471
1560
|
return !(sym.flags & (131072 /* SymbolFlags.Function */ | 16384 /* SymbolFlags.Decorator */));
|
|
1561
|
+
case IdentifierKind.TemplateArgument:
|
|
1562
|
+
return !!(sym.flags & 32768 /* SymbolFlags.TemplateParameter */);
|
|
1472
1563
|
default:
|
|
1473
1564
|
compilerAssert(false, "We should have bailed up-front on other kinds.");
|
|
1474
1565
|
}
|
|
@@ -2086,7 +2177,6 @@ export function createChecker(program) {
|
|
|
2086
2177
|
switch (node.value.kind) {
|
|
2087
2178
|
case SyntaxKind.MemberExpression:
|
|
2088
2179
|
case SyntaxKind.TypeReference:
|
|
2089
|
-
case SyntaxKind.Identifier:
|
|
2090
2180
|
const resolvedSym = resolveTypeReferenceSym(node.value, undefined);
|
|
2091
2181
|
if (resolvedSym && resolvedSym.flags & 2048 /* SymbolFlags.Alias */) {
|
|
2092
2182
|
return resolveAliasedSymbol(resolvedSym);
|
|
@@ -2635,7 +2725,7 @@ export function createChecker(program) {
|
|
|
2635
2725
|
const decorators = [];
|
|
2636
2726
|
const augmentDecoratorNodes = (_b = augmentDecoratorsForSym.get(sym)) !== null && _b !== void 0 ? _b : [];
|
|
2637
2727
|
const decoratorNodes = [
|
|
2638
|
-
...augmentDecoratorNodes,
|
|
2728
|
+
...augmentDecoratorNodes, // the first decorator will be executed at last, so augmented decorator should be placed at first.
|
|
2639
2729
|
...node.decorators,
|
|
2640
2730
|
];
|
|
2641
2731
|
for (const decNode of decoratorNodes) {
|