Optional braces for model is (#673)
This commit is contained in:
Родитель
20fcc3b52c
Коммит
2d4333da91
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@cadl-lang/compiler",
|
||||
"comment": "Allow omitting braces from model is statements",
|
||||
"type": "minor"
|
||||
}
|
||||
],
|
||||
"packageName": "@cadl-lang/compiler"
|
||||
}
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -674,7 +674,18 @@ export function parse(code: string | SourceFile, options: ParseOptions = {}): Ca
|
|||
|
||||
const optionalExtends: TypeReferenceNode | undefined = parseOptionalModelExtends();
|
||||
const optionalIs = optionalExtends ? undefined : parseOptionalModelIs();
|
||||
const properties = parseList(ListKind.ModelProperties, parseModelPropertyOrSpread);
|
||||
|
||||
let properties: (ModelPropertyNode | ModelSpreadPropertyNode)[] = [];
|
||||
if (optionalIs) {
|
||||
const tok = expectTokenIsOneOf(Token.Semicolon, Token.OpenBrace);
|
||||
if (tok === Token.Semicolon) {
|
||||
nextToken();
|
||||
} else {
|
||||
properties = parseList(ListKind.ModelProperties, parseModelPropertyOrSpread);
|
||||
}
|
||||
} else {
|
||||
properties = parseList(ListKind.ModelProperties, parseModelPropertyOrSpread);
|
||||
}
|
||||
|
||||
return {
|
||||
kind: SyntaxKind.ModelStatement,
|
||||
|
|
|
@ -93,6 +93,8 @@ describe("compiler: syntax", () => {
|
|||
"model Car { ... A.B, ... C<D> }",
|
||||
|
||||
"model Car is Vehicle { }",
|
||||
|
||||
"model Car is Vehicle;",
|
||||
]);
|
||||
|
||||
parseErrorEach([
|
||||
|
@ -105,6 +107,9 @@ describe("compiler: syntax", () => {
|
|||
[/Cannot use default with non optional properties/],
|
||||
],
|
||||
["model", [/Identifier expected/]],
|
||||
["model Car is Vehicle", [/';', or '{' expected/]],
|
||||
["model Car;", [/'{', '=', 'extends', or 'is' expected/]],
|
||||
["model Car extends Foo;", [/'{' expected/]],
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
|
@ -283,12 +283,19 @@ UsingStatement :
|
|||
`using` IdentifierOrMemberExpression `;`
|
||||
|
||||
ModelStatement :
|
||||
DecoratorList? `model` Identifier TemplateParameters? IsModelHeritage `;`
|
||||
DecoratorList? `model` Identifier TemplateParameters? ModelHeritage? `{` ModelBody? `}`
|
||||
|
||||
ModelHeritage :
|
||||
`extends` ReferenceExpression
|
||||
IsModelHeritage :
|
||||
`is` ReferenceExpression
|
||||
|
||||
ExtendsModelHeritage :
|
||||
`extends` ReferenceExpression
|
||||
|
||||
ModelHeritage :
|
||||
IsModelHeritage
|
||||
ExtendsModelHeritage
|
||||
|
||||
ModelBody :
|
||||
ModelPropertyList `,`?
|
||||
ModelPropertyList `;`?
|
||||
|
|
Загрузка…
Ссылка в новой задаче