Fix stop running decorators on partially instantiated operations (#3227)
fix [#2619](https://github.com/microsoft/typespec/issues/2619)
This commit is contained in:
Родитель
0a83800065
Коммит
32a25ecb94
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
|
||||
changeKind: fix
|
||||
packages:
|
||||
- "@typespec/compiler"
|
||||
---
|
||||
|
||||
Stop running decorators on partially instantiated operations(When interface is instantiated but not the operation)
|
|
@ -2865,7 +2865,7 @@ export function createChecker(program: Program): Checker {
|
|||
}
|
||||
|
||||
// Some of the mapper args are still template parameter so we shouldn't create the type.
|
||||
return mapper.args.every((t) => t.kind !== "TemplateParameter");
|
||||
return !mapper.partial && mapper.args.every((t) => t.kind !== "TemplateParameter");
|
||||
}
|
||||
|
||||
function checkModelExpression(node: ModelExpressionNode, mapper: TypeMapper | undefined) {
|
||||
|
|
|
@ -416,7 +416,9 @@ export function createProjector(
|
|||
projectedOp.namespace = projectedNamespaceScope();
|
||||
}
|
||||
|
||||
finishTypeForProgram(projectedProgram, projectedOp);
|
||||
if (op.isFinished) {
|
||||
finishTypeForProgram(projectedProgram, projectedOp);
|
||||
}
|
||||
if (op.interface) {
|
||||
projectedOp.interface = projectType(op.interface) as Interface;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { deepStrictEqual, notStrictEqual, ok, strictEqual } from "assert";
|
||||
import { beforeEach, describe, it } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { isTemplateDeclaration } from "../../src/core/type-utils.js";
|
||||
import { Interface, Model, Operation, Type } from "../../src/core/types.js";
|
||||
import { getDoc } from "../../src/index.js";
|
||||
|
@ -410,6 +410,25 @@ describe("compiler: interfaces", () => {
|
|||
strictEqual(returnType.name, "int32");
|
||||
});
|
||||
|
||||
it("instantiating an templated interface doesn't finish template operation inside", async () => {
|
||||
const $track = vi.fn();
|
||||
testHost.addJsFile("dec.js", { $track });
|
||||
testHost.addTypeSpecFile(
|
||||
"main.tsp",
|
||||
`
|
||||
import "./dec.js";
|
||||
|
||||
interface Base<A> {
|
||||
@track bar<B>(input: A): B;
|
||||
}
|
||||
|
||||
alias My = Base<string>;
|
||||
`
|
||||
);
|
||||
await testHost.compile("./");
|
||||
expect($track).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("emit warning if shadowing parent templated type", async () => {
|
||||
const diagnostics = await runner.diagnose(`
|
||||
interface Base<A> {
|
||||
|
|
Загрузка…
Ссылка в новой задаче