Skip to content

Commit

Permalink
Use op is Sig syntax instead of previous op: Sig syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
daviwil committed Jun 1, 2022
1 parent f87ce33 commit 952d6ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/compiler/core/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export function parse(code: string | SourceFile, options: ParseOptions = {}): Ca
const templateParameters = inInterface ? [] : parseTemplateParameterList();

// Make sure the next token is one that is expected
const token = expectTokenIsOneOf(Token.OpenParen, Token.Colon);
const token = expectTokenIsOneOf(Token.OpenParen, Token.IsKeyword);

// Check if we're parsing a declaration or reuse of another operation
let signature: OperationSignature;
Expand All @@ -622,7 +622,7 @@ export function parse(code: string | SourceFile, options: ParseOptions = {}): Ca
...finishNode(signaturePos),
};
} else {
parseExpected(Token.Colon);
parseExpected(Token.IsKeyword);
const opReference = parseReferenceExpression();

signature = {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/formatter/print/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ export function printOperationSignatureReference(
options: CadlPrettierOptions,
print: PrettierChildPrint
) {
return [": ", path.call(print, "baseOperation")];
return [" is ", path.call(print, "baseOperation")];
}

export function printOperationStatement(
Expand Down
32 changes: 16 additions & 16 deletions packages/compiler/test/checker/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe("cadl: operations", () => {
it("can be templated and referenced to define other operations", async () => {
testHost.addCadlFile(
"main.cadl",
`op foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
`op Foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
@test
op newFoo: foo<string, string>;`
op newFoo is Foo<string, string>;`
);

const [result, diagnostics] = await testHost.compileAndDiagnose("./main.cadl");
Expand All @@ -47,11 +47,11 @@ describe("cadl: operations", () => {
it("can be defined based on other operation references", async () => {
testHost.addCadlFile(
"main.cadl",
`op foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
op newFooBase<TPayload>: foo<string, TPayload>;
`op Foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
op NewFooBase<TPayload> is Foo<string, TPayload>;
@test
op newFoo: newFooBase<string>;`
op newFoo is NewFooBase<string>;`
);

const [result, diagnostics] = await testHost.compileAndDiagnose("./main.cadl");
Expand All @@ -70,11 +70,11 @@ describe("cadl: operations", () => {
it("can reference an operation when being defined in an interface", async () => {
testHost.addCadlFile(
"main.cadl",
`op foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
`op Foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
interface Test {
@test
newFoo: foo<string, string>;
newFoo is Foo<string, string>;
}`
);

Expand All @@ -94,7 +94,7 @@ describe("cadl: operations", () => {
it("applies the decorators of the referenced operation and its transitive references", async () => {
const alphaTargets = new Map<Type, Type>();
const betaTargets = new Set<Type>();
const kappaTargets = new Set<Type>();
const gammaTargets = new Set<Type>();

testHost.addJsFile("test.js", {
$alpha(context: DecoratorContext, target: Type, param: Type) {
Expand All @@ -105,8 +105,8 @@ describe("cadl: operations", () => {
betaTargets.add(target);
},

$kappa(context: DecoratorContext, target: Type) {
kappaTargets.add(target);
$gamma(context: DecoratorContext, target: Type) {
gammaTargets.add(target);
},
});

Expand All @@ -115,14 +115,14 @@ describe("cadl: operations", () => {
`
import "./test.js";
@alpha(TPayload)
op foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
op Foo<TName, TPayload>(name: TName, payload: TPayload): boolean;
@beta
op newFooBase<TPayload>: foo<string, TPayload>;
op NewFooBase<TPayload> is Foo<string, TPayload>;
@test
@kappa
op newFoo: newFooBase<string>;`
@gamma
op newFoo is NewFooBase<string>;`
);

const [result, diagnostics] = await testHost.compileAndDiagnose("./main.cadl");
Expand All @@ -134,7 +134,7 @@ describe("cadl: operations", () => {
// Check that the decorators were applied correctly to `newFoo`
strictEqual(alphaTargets.get(newFoo)?.kind, "Model");
ok(betaTargets.has(newFoo));
ok(kappaTargets.has(newFoo));
ok(gammaTargets.has(newFoo));
});

it("prevents the definition of a templated operation in an interface", async () => {
Expand All @@ -150,7 +150,7 @@ describe("cadl: operations", () => {
expectDiagnostics(diagnostics, [
{
code: "token-expected",
message: `'(', or ':' expected.`,
message: `'(', or 'is' expected.`,
},
{
code: "token-expected",
Expand Down
12 changes: 6 additions & 6 deletions packages/samples/signatures/signatures.cadl
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ model AccountProfile {
@get
@doc("Reads an instance of the {name} resource.", TResource)
op ResourceReadBase<TResource, TError>(@path name: string): TResource | TError;
op ResourceRead<TResource>: ResourceReadBase<TResource, ErrorDetails>;
op ResourceRead<TResource> is ResourceReadBase<TResource, ErrorDetails>;

@post
@doc("Reads an instance of the {name} resource.", TResource)
op ResourceCreateBase<TResource, TError>(@body resource: TResource): TResource | TError;
op ResourceCreate<TResource>: ResourceCreateBase<TResource, ErrorDetails>;
op ResourceCreate<TResource> is ResourceCreateBase<TResource, ErrorDetails>;

@route("codeSignAccounts")
interface CodeSignAccounts {
get: ResourceRead<CodeSignAccount>;
create: ResourceCreate<CodeSignAccount>;
get is ResourceRead<CodeSignAccount>;
create is ResourceCreate<CodeSignAccount>;
}

interface ResourceOperations<TResource> {
get: ResourceRead<TResource>;
create: ResourceCreate<TResource>;
get is ResourceRead<TResource>;
create is ResourceCreate<TResource>;
}

@route("accountProfiles")
Expand Down

0 comments on commit 952d6ea

Please sign in to comment.