tangled
alpha
login
or
join now
danabra.mov
/
typelex
56
fork
atom
An experimental TypeSpec syntax for Lexicon
56
fork
atom
overview
issues
1
pulls
2
pipelines
wip
danabra.mov
5 months ago
19b341cf
2359e07c
+20
-10
2 changed files
expand all
collapse all
unified
split
packages
emitter
src
decorators.ts
emitter.ts
+4
-2
packages/emitter/src/decorators.ts
···
229
229
if ((errorModel as any).kind !== "Model") {
230
230
context.program.reportDiagnostic({
231
231
code: "invalid-error-type",
232
232
+
severity: "error",
232
233
message: "@errors decorator only accepts model types",
233
234
target: errorModel,
234
234
-
} as any);
235
235
+
});
235
236
continue;
236
237
}
237
238
···
241
242
if (model.properties && model.properties.size > 0) {
242
243
context.program.reportDiagnostic({
243
244
code: "error-model-not-empty",
245
245
+
severity: "error",
244
246
message: "Error models must be empty (only @doc decorator allowed)",
245
247
target: errorModel,
246
246
-
} as any);
248
248
+
});
247
249
continue;
248
250
}
249
251
+16
-8
packages/emitter/src/emitter.ts
···
323
323
if (model.name && model.name[0] !== model.name[0].toUpperCase()) {
324
324
this.program.reportDiagnostic({
325
325
code: "invalid-model-name",
326
326
+
severity: "error",
326
327
message: `Model name "${model.name}" must use PascalCase. Did you mean "${model.name[0].toUpperCase() + model.name.slice(1)}"?`,
327
328
target: model,
328
328
-
} as any);
329
329
+
});
329
330
return;
330
331
}
331
332
···
525
526
if (paramCount > 2) {
526
527
this.program.reportDiagnostic({
527
528
code: "procedure-too-many-params",
529
529
+
severity: "error",
528
530
message:
529
531
"Procedures can have at most 2 parameters (input and/or parameters)",
530
532
target: operation,
531
531
-
} as any);
533
533
+
});
532
534
} else if (paramCount === 1) {
533
535
// Single param: must be named "input"
534
536
const [paramName, param] = params[0] as [string, any];
···
536
538
if (paramName !== "input") {
537
539
this.program.reportDiagnostic({
538
540
code: "procedure-invalid-param-name",
541
541
+
severity: "error",
539
542
message: `Procedure parameter must be named "input", got "${paramName}"`,
540
543
target: param,
541
541
-
} as any);
544
544
+
});
542
545
}
543
546
544
547
// Treat as input
···
558
561
if (param1Name !== "input") {
559
562
this.program.reportDiagnostic({
560
563
code: "procedure-invalid-first-param",
564
564
+
severity: "error",
561
565
message: `First parameter must be named "input", got "${param1Name}"`,
562
566
target: param1,
563
563
-
} as any);
567
567
+
});
564
568
}
565
569
566
570
if (param2Name !== "parameters") {
567
571
this.program.reportDiagnostic({
568
572
code: "procedure-invalid-second-param",
573
573
+
severity: "error",
569
574
message: `Second parameter must be named "parameters", got "${param2Name}"`,
570
575
target: param2,
571
571
-
} as any);
576
576
+
});
572
577
}
573
578
574
579
// Validate that parameters is a plain object (not a model reference)
575
580
if (param2.type.kind !== "Model" || (param2.type as any).name) {
576
581
this.program.reportDiagnostic({
577
582
code: "procedure-parameters-not-object",
583
583
+
severity: "error",
578
584
message:
579
585
"The 'parameters' parameter must be a plain object, not a model reference",
580
586
target: param2,
581
581
-
} as any);
587
587
+
});
582
588
}
583
589
584
590
// Handle input (first param)
···
696
702
) {
697
703
this.program.reportDiagnostic({
698
704
code: "subscription-return-not-union",
705
705
+
severity: "error",
699
706
message: "Subscription return type must be a union",
700
707
target: operation,
701
701
-
} as any);
708
708
+
});
702
709
}
703
710
704
711
// Handle errors
···
1236
1243
if (hasUnknown) {
1237
1244
this.program.reportDiagnostic({
1238
1245
code: "closed-open-union",
1246
1246
+
severity: "error",
1239
1247
message:
1240
1248
"@closed decorator cannot be used on open unions (unions containing 'unknown' or 'never'). Remove the @closed decorator or make the union closed by removing 'unknown'/'never'.",
1241
1249
target: unionType,
1242
1242
-
} as any);
1250
1250
+
});
1243
1251
} else {
1244
1252
unionDef.closed = true;
1245
1253
}