@typespec/prettier-plugin-typespec 1.10.0-dev.0 → 1.10.0

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/index.js CHANGED
@@ -316,6 +316,14 @@ var diagnostics = {
316
316
  /**
317
317
  * Checker
318
318
  */
319
+ "experimental-feature": {
320
+ severity: "warning",
321
+ messages: {
322
+ default: paramMessage`${"feature"} is an experimental feature. It may change in the future or be removed. Use with caution and consider providing feedback on this feature.`,
323
+ functionDeclarations: "Function declarations are an experimental feature that may change in the future. Use with caution and consider providing feedback to the TypeSpec team.",
324
+ internal: `Internal symbols are experimental and may be changed in a future release. Use with caution. Suppress this message ('#suppress "experimental-feature"') to silence this warning.`
325
+ }
326
+ },
319
327
  "using-invalid-ref": {
320
328
  severity: "error",
321
329
  messages: {
@@ -390,7 +398,8 @@ var diagnostics = {
390
398
  underNamespace: paramMessage`Namespace ${"namespace"} doesn't have member ${"id"}`,
391
399
  member: paramMessage`${"kind"} doesn't have member ${"id"}`,
392
400
  metaProperty: paramMessage`${"kind"} doesn't have meta property ${"id"}`,
393
- node: paramMessage`Cannot resolve '${"id"}' in node ${"nodeName"} since it has no members. Did you mean to use "::" instead of "."?`
401
+ node: paramMessage`Cannot resolve '${"id"}' in node ${"nodeName"} since it has no members. Did you mean to use "::" instead of "."?`,
402
+ internal: paramMessage`Symbol '${"id"}' is internal and can only be accessed from within its declaring package.`
394
403
  }
395
404
  },
396
405
  "duplicate-property": {
@@ -459,13 +468,15 @@ var diagnostics = {
459
468
  model: paramMessage`${"name"} refers to a model type, but is being used as a value here. Use #{} to create an object value.`,
460
469
  modelExpression: `Is a model expression type, but is being used as a value here. Use #{} to create an object value.`,
461
470
  tuple: `Is a tuple type, but is being used as a value here. Use #[] to create an array value.`,
462
- templateConstraint: paramMessage`${"name"} template parameter can be a type but is being used as a value here.`
471
+ templateConstraint: paramMessage`${"name"} template parameter can be a type but is being used as a value here.`,
472
+ functionReturn: paramMessage`Function returned a type, but a value was expected.`
463
473
  }
464
474
  },
465
475
  "non-callable": {
466
476
  severity: "error",
467
477
  messages: {
468
- default: paramMessage`Type ${"type"} is not is not callable.`
478
+ default: paramMessage`Type ${"type"} is not is not callable.`,
479
+ templateParameter: paramMessage`Template parameter '${"name"} extends ${"constraint"}' is not callable. Ensure it is constrained to a function value or callable type (scalar or scalar constructor).`
469
480
  }
470
481
  },
471
482
  "named-init-required": {
@@ -505,6 +516,14 @@ var diagnostics = {
505
516
  default: paramMessage`Property '${"propName"}' is required in type '${"targetType"}' but here is optional.`
506
517
  }
507
518
  },
519
+ "parameter-required": {
520
+ severity: "error",
521
+ messages: {
522
+ default: paramMessage`Parameter '${"paramName"}' is required, but optional in the target function.`,
523
+ missing: paramMessage`Parameter '${"paramName"}' is required, but missing in the target function.`,
524
+ "rest-to-required": paramMessage`Parameter '${"paramName"}' is required and not satisfied by a rest parameter, as rest parameters are effectively optional.`
525
+ }
526
+ },
508
527
  "value-in-type": {
509
528
  severity: "error",
510
529
  messages: {
@@ -591,22 +610,26 @@ var diagnostics = {
591
610
  default: "A rest parameter must be of an array type."
592
611
  }
593
612
  },
594
- "decorator-extern": {
613
+ "invalid-modifier": {
595
614
  severity: "error",
596
615
  messages: {
597
- default: "A decorator declaration must be prefixed with the 'extern' modifier."
616
+ default: paramMessage`Modifier '${"modifier"}' is invalid.`,
617
+ "missing-required": paramMessage`Declaration of type '${"nodeKind"}' is missing required modifier '${"modifier"}'.`,
618
+ "not-allowed": paramMessage`Modifier '${"modifier"}' cannot be used on declarations of type '${"nodeKind"}'.`
598
619
  }
599
620
  },
600
- "function-extern": {
621
+ "function-return": {
601
622
  severity: "error",
602
623
  messages: {
603
- default: "A function declaration must be prefixed with the 'extern' modifier."
624
+ default: "Function implementation returned an invalid result.",
625
+ "invalid-value": paramMessage`Function implementation returned invalid JS value '${"value"}'.`,
626
+ unassignable: paramMessage`Implementation of '${"name"}' returned ${"entityKind"} '${"return"}', which is not assignable to the declared return type '${"type"}'.`
604
627
  }
605
628
  },
606
- "function-unsupported": {
629
+ "fn-in-union-expression": {
607
630
  severity: "error",
608
631
  messages: {
609
- default: "Function are currently not supported."
632
+ default: "Function types in anonymous union expressions must be parenthesized."
610
633
  }
611
634
  },
612
635
  "missing-implementation": {
@@ -1261,6 +1284,8 @@ var SyntaxKind;
1261
1284
  SyntaxKind2[SyntaxKind2["ConstStatement"] = 67] = "ConstStatement";
1262
1285
  SyntaxKind2[SyntaxKind2["CallExpression"] = 68] = "CallExpression";
1263
1286
  SyntaxKind2[SyntaxKind2["ScalarConstructor"] = 69] = "ScalarConstructor";
1287
+ SyntaxKind2[SyntaxKind2["InternalKeyword"] = 70] = "InternalKeyword";
1288
+ SyntaxKind2[SyntaxKind2["FunctionTypeExpression"] = 71] = "FunctionTypeExpression";
1264
1289
  })(SyntaxKind || (SyntaxKind = {}));
1265
1290
  var IdentifierKind;
1266
1291
  (function(IdentifierKind2) {
@@ -2855,6 +2880,52 @@ function lookupInNonAsciiMap(codePoint, map) {
2855
2880
  return false;
2856
2881
  }
2857
2882
 
2883
+ // ../compiler/dist/src/core/modifiers.js
2884
+ var DEFAULT_COMPATIBILITY = {
2885
+ allowed: 4,
2886
+ required: 0
2887
+ };
2888
+ var NO_MODIFIERS = {
2889
+ allowed: 0,
2890
+ required: 0
2891
+ };
2892
+ var SYNTAX_MODIFIERS = {
2893
+ [SyntaxKind.NamespaceStatement]: NO_MODIFIERS,
2894
+ [SyntaxKind.OperationStatement]: DEFAULT_COMPATIBILITY,
2895
+ [SyntaxKind.ModelStatement]: DEFAULT_COMPATIBILITY,
2896
+ [SyntaxKind.ScalarStatement]: DEFAULT_COMPATIBILITY,
2897
+ [SyntaxKind.InterfaceStatement]: DEFAULT_COMPATIBILITY,
2898
+ [SyntaxKind.UnionStatement]: DEFAULT_COMPATIBILITY,
2899
+ [SyntaxKind.EnumStatement]: DEFAULT_COMPATIBILITY,
2900
+ [SyntaxKind.AliasStatement]: DEFAULT_COMPATIBILITY,
2901
+ [SyntaxKind.ConstStatement]: DEFAULT_COMPATIBILITY,
2902
+ [SyntaxKind.DecoratorDeclarationStatement]: {
2903
+ allowed: 6,
2904
+ required: 2
2905
+ },
2906
+ [SyntaxKind.FunctionDeclarationStatement]: {
2907
+ allowed: 6,
2908
+ required: 2
2909
+ }
2910
+ };
2911
+ function modifiersToFlags(modifiers) {
2912
+ let flags = 0;
2913
+ for (const modifier of modifiers) {
2914
+ flags |= modifierToFlag(modifier);
2915
+ }
2916
+ return flags;
2917
+ }
2918
+ function modifierToFlag(modifier) {
2919
+ switch (modifier.kind) {
2920
+ case SyntaxKind.ExternKeyword:
2921
+ return 2;
2922
+ case SyntaxKind.InternalKeyword:
2923
+ return 4;
2924
+ default:
2925
+ compilerAssert(false, `Unknown modifier kind: ${modifier.kind}`);
2926
+ }
2927
+ }
2928
+
2858
2929
  // ../compiler/dist/src/core/helpers/syntax-utils.js
2859
2930
  function printIdentifier(sv, context = "disallow-reserved") {
2860
2931
  if (needBacktick(sv, context)) {
@@ -2868,8 +2939,14 @@ function needBacktick(sv, context) {
2868
2939
  if (sv.length === 0) {
2869
2940
  return false;
2870
2941
  }
2871
- if (context === "allow-reserved" && ReservedKeywords.has(sv)) {
2872
- return false;
2942
+ if (context === "allow-reserved") {
2943
+ if (ReservedKeywords.has(sv)) {
2944
+ return false;
2945
+ }
2946
+ const kwToken = Keywords.get(sv);
2947
+ if (kwToken !== void 0 && isModifier(kwToken)) {
2948
+ return false;
2949
+ }
2873
2950
  }
2874
2951
  if (Keywords.has(sv)) {
2875
2952
  return true;
@@ -3037,60 +3114,60 @@ var Token;
3037
3114
  Token2[Token2["ElseKeyword"] = 64] = "ElseKeyword";
3038
3115
  Token2[Token2["IfKeyword"] = 65] = "IfKeyword";
3039
3116
  Token2[Token2["DecKeyword"] = 66] = "DecKeyword";
3040
- Token2[Token2["FnKeyword"] = 67] = "FnKeyword";
3041
- Token2[Token2["ConstKeyword"] = 68] = "ConstKeyword";
3042
- Token2[Token2["InitKeyword"] = 69] = "InitKeyword";
3043
- Token2[Token2["__EndStatementKeyword"] = 70] = "__EndStatementKeyword";
3044
- Token2[Token2["__StartModifierKeyword"] = 70] = "__StartModifierKeyword";
3045
- Token2[Token2["ExternKeyword"] = 70] = "ExternKeyword";
3117
+ Token2[Token2["ConstKeyword"] = 67] = "ConstKeyword";
3118
+ Token2[Token2["InitKeyword"] = 68] = "InitKeyword";
3119
+ Token2[Token2["__EndStatementKeyword"] = 69] = "__EndStatementKeyword";
3120
+ Token2[Token2["__StartModifierKeyword"] = 69] = "__StartModifierKeyword";
3121
+ Token2[Token2["ExternKeyword"] = 69] = "ExternKeyword";
3122
+ Token2[Token2["InternalKeyword"] = 70] = "InternalKeyword";
3046
3123
  Token2[Token2["__EndModifierKeyword"] = 71] = "__EndModifierKeyword";
3047
3124
  Token2[Token2["ExtendsKeyword"] = 71] = "ExtendsKeyword";
3048
- Token2[Token2["TrueKeyword"] = 72] = "TrueKeyword";
3049
- Token2[Token2["FalseKeyword"] = 73] = "FalseKeyword";
3050
- Token2[Token2["ReturnKeyword"] = 74] = "ReturnKeyword";
3051
- Token2[Token2["VoidKeyword"] = 75] = "VoidKeyword";
3052
- Token2[Token2["NeverKeyword"] = 76] = "NeverKeyword";
3053
- Token2[Token2["UnknownKeyword"] = 77] = "UnknownKeyword";
3054
- Token2[Token2["ValueOfKeyword"] = 78] = "ValueOfKeyword";
3055
- Token2[Token2["TypeOfKeyword"] = 79] = "TypeOfKeyword";
3056
- Token2[Token2["__EndKeyword"] = 80] = "__EndKeyword";
3057
- Token2[Token2["__StartReservedKeyword"] = 80] = "__StartReservedKeyword";
3058
- Token2[Token2["StatemachineKeyword"] = 80] = "StatemachineKeyword";
3059
- Token2[Token2["MacroKeyword"] = 81] = "MacroKeyword";
3060
- Token2[Token2["PackageKeyword"] = 82] = "PackageKeyword";
3061
- Token2[Token2["MetadataKeyword"] = 83] = "MetadataKeyword";
3062
- Token2[Token2["EnvKeyword"] = 84] = "EnvKeyword";
3063
- Token2[Token2["ArgKeyword"] = 85] = "ArgKeyword";
3064
- Token2[Token2["DeclareKeyword"] = 86] = "DeclareKeyword";
3065
- Token2[Token2["ArrayKeyword"] = 87] = "ArrayKeyword";
3066
- Token2[Token2["StructKeyword"] = 88] = "StructKeyword";
3067
- Token2[Token2["RecordKeyword"] = 89] = "RecordKeyword";
3068
- Token2[Token2["ModuleKeyword"] = 90] = "ModuleKeyword";
3069
- Token2[Token2["ModKeyword"] = 91] = "ModKeyword";
3070
- Token2[Token2["SymKeyword"] = 92] = "SymKeyword";
3071
- Token2[Token2["ContextKeyword"] = 93] = "ContextKeyword";
3072
- Token2[Token2["PropKeyword"] = 94] = "PropKeyword";
3073
- Token2[Token2["PropertyKeyword"] = 95] = "PropertyKeyword";
3074
- Token2[Token2["ScenarioKeyword"] = 96] = "ScenarioKeyword";
3075
- Token2[Token2["PubKeyword"] = 97] = "PubKeyword";
3076
- Token2[Token2["SubKeyword"] = 98] = "SubKeyword";
3077
- Token2[Token2["TypeRefKeyword"] = 99] = "TypeRefKeyword";
3078
- Token2[Token2["TraitKeyword"] = 100] = "TraitKeyword";
3079
- Token2[Token2["ThisKeyword"] = 101] = "ThisKeyword";
3080
- Token2[Token2["SelfKeyword"] = 102] = "SelfKeyword";
3081
- Token2[Token2["SuperKeyword"] = 103] = "SuperKeyword";
3082
- Token2[Token2["KeyofKeyword"] = 104] = "KeyofKeyword";
3083
- Token2[Token2["WithKeyword"] = 105] = "WithKeyword";
3084
- Token2[Token2["ImplementsKeyword"] = 106] = "ImplementsKeyword";
3085
- Token2[Token2["ImplKeyword"] = 107] = "ImplKeyword";
3086
- Token2[Token2["SatisfiesKeyword"] = 108] = "SatisfiesKeyword";
3087
- Token2[Token2["FlagKeyword"] = 109] = "FlagKeyword";
3088
- Token2[Token2["AutoKeyword"] = 110] = "AutoKeyword";
3089
- Token2[Token2["PartialKeyword"] = 111] = "PartialKeyword";
3090
- Token2[Token2["PrivateKeyword"] = 112] = "PrivateKeyword";
3091
- Token2[Token2["PublicKeyword"] = 113] = "PublicKeyword";
3092
- Token2[Token2["ProtectedKeyword"] = 114] = "ProtectedKeyword";
3093
- Token2[Token2["InternalKeyword"] = 115] = "InternalKeyword";
3125
+ Token2[Token2["FnKeyword"] = 72] = "FnKeyword";
3126
+ Token2[Token2["TrueKeyword"] = 73] = "TrueKeyword";
3127
+ Token2[Token2["FalseKeyword"] = 74] = "FalseKeyword";
3128
+ Token2[Token2["ReturnKeyword"] = 75] = "ReturnKeyword";
3129
+ Token2[Token2["VoidKeyword"] = 76] = "VoidKeyword";
3130
+ Token2[Token2["NeverKeyword"] = 77] = "NeverKeyword";
3131
+ Token2[Token2["UnknownKeyword"] = 78] = "UnknownKeyword";
3132
+ Token2[Token2["ValueOfKeyword"] = 79] = "ValueOfKeyword";
3133
+ Token2[Token2["TypeOfKeyword"] = 80] = "TypeOfKeyword";
3134
+ Token2[Token2["__EndKeyword"] = 81] = "__EndKeyword";
3135
+ Token2[Token2["__StartReservedKeyword"] = 81] = "__StartReservedKeyword";
3136
+ Token2[Token2["StatemachineKeyword"] = 81] = "StatemachineKeyword";
3137
+ Token2[Token2["MacroKeyword"] = 82] = "MacroKeyword";
3138
+ Token2[Token2["PackageKeyword"] = 83] = "PackageKeyword";
3139
+ Token2[Token2["MetadataKeyword"] = 84] = "MetadataKeyword";
3140
+ Token2[Token2["EnvKeyword"] = 85] = "EnvKeyword";
3141
+ Token2[Token2["ArgKeyword"] = 86] = "ArgKeyword";
3142
+ Token2[Token2["DeclareKeyword"] = 87] = "DeclareKeyword";
3143
+ Token2[Token2["ArrayKeyword"] = 88] = "ArrayKeyword";
3144
+ Token2[Token2["StructKeyword"] = 89] = "StructKeyword";
3145
+ Token2[Token2["RecordKeyword"] = 90] = "RecordKeyword";
3146
+ Token2[Token2["ModuleKeyword"] = 91] = "ModuleKeyword";
3147
+ Token2[Token2["ModKeyword"] = 92] = "ModKeyword";
3148
+ Token2[Token2["SymKeyword"] = 93] = "SymKeyword";
3149
+ Token2[Token2["ContextKeyword"] = 94] = "ContextKeyword";
3150
+ Token2[Token2["PropKeyword"] = 95] = "PropKeyword";
3151
+ Token2[Token2["PropertyKeyword"] = 96] = "PropertyKeyword";
3152
+ Token2[Token2["ScenarioKeyword"] = 97] = "ScenarioKeyword";
3153
+ Token2[Token2["PubKeyword"] = 98] = "PubKeyword";
3154
+ Token2[Token2["SubKeyword"] = 99] = "SubKeyword";
3155
+ Token2[Token2["TypeRefKeyword"] = 100] = "TypeRefKeyword";
3156
+ Token2[Token2["TraitKeyword"] = 101] = "TraitKeyword";
3157
+ Token2[Token2["ThisKeyword"] = 102] = "ThisKeyword";
3158
+ Token2[Token2["SelfKeyword"] = 103] = "SelfKeyword";
3159
+ Token2[Token2["SuperKeyword"] = 104] = "SuperKeyword";
3160
+ Token2[Token2["KeyofKeyword"] = 105] = "KeyofKeyword";
3161
+ Token2[Token2["WithKeyword"] = 106] = "WithKeyword";
3162
+ Token2[Token2["ImplementsKeyword"] = 107] = "ImplementsKeyword";
3163
+ Token2[Token2["ImplKeyword"] = 108] = "ImplKeyword";
3164
+ Token2[Token2["SatisfiesKeyword"] = 109] = "SatisfiesKeyword";
3165
+ Token2[Token2["FlagKeyword"] = 110] = "FlagKeyword";
3166
+ Token2[Token2["AutoKeyword"] = 111] = "AutoKeyword";
3167
+ Token2[Token2["PartialKeyword"] = 112] = "PartialKeyword";
3168
+ Token2[Token2["PrivateKeyword"] = 113] = "PrivateKeyword";
3169
+ Token2[Token2["PublicKeyword"] = 114] = "PublicKeyword";
3170
+ Token2[Token2["ProtectedKeyword"] = 115] = "ProtectedKeyword";
3094
3171
  Token2[Token2["SealedKeyword"] = 116] = "SealedKeyword";
3095
3172
  Token2[Token2["LocalKeyword"] = 117] = "LocalKeyword";
3096
3173
  Token2[Token2["AsyncKeyword"] = 118] = "AsyncKeyword";
@@ -3248,6 +3325,7 @@ var Keywords = /* @__PURE__ */ new Map([
3248
3325
  ["never", Token.NeverKeyword],
3249
3326
  ["unknown", Token.UnknownKeyword],
3250
3327
  ["extern", Token.ExternKeyword],
3328
+ ["internal", Token.InternalKeyword],
3251
3329
  // Reserved keywords
3252
3330
  ["statemachine", Token.StatemachineKeyword],
3253
3331
  ["macro", Token.MacroKeyword],
@@ -3284,7 +3362,6 @@ var Keywords = /* @__PURE__ */ new Map([
3284
3362
  ["private", Token.PrivateKeyword],
3285
3363
  ["public", Token.PublicKeyword],
3286
3364
  ["protected", Token.ProtectedKeyword],
3287
- ["internal", Token.InternalKeyword],
3288
3365
  ["sealed", Token.SealedKeyword],
3289
3366
  ["local", Token.LocalKeyword],
3290
3367
  ["async", Token.AsyncKeyword]
@@ -3323,7 +3400,6 @@ var ReservedKeywords = /* @__PURE__ */ new Map([
3323
3400
  ["private", Token.PrivateKeyword],
3324
3401
  ["public", Token.PublicKeyword],
3325
3402
  ["protected", Token.ProtectedKeyword],
3326
- ["internal", Token.InternalKeyword],
3327
3403
  ["sealed", Token.SealedKeyword],
3328
3404
  ["local", Token.LocalKeyword],
3329
3405
  ["async", Token.AsyncKeyword]
@@ -3353,6 +3429,9 @@ function isReservedKeyword(token) {
3353
3429
  function isPunctuation(token) {
3354
3430
  return token >= Token.__StartPunctuation && token < Token.__EndPunctuation;
3355
3431
  }
3432
+ function isModifier(token) {
3433
+ return token >= Token.__StartModifierKeyword && token < Token.__EndModifierKeyword;
3434
+ }
3356
3435
  function isStatementKeyword(token) {
3357
3436
  return token >= Token.__StartStatementKeyword && token < Token.__EndStatementKeyword;
3358
3437
  }
@@ -4052,14 +4131,13 @@ function createScanner(source, diagnosticHandler) {
4052
4131
  }
4053
4132
  function scanIdentifierOrKeyword() {
4054
4133
  let count = 0;
4055
- let ch = input.charCodeAt(position);
4056
4134
  while (true) {
4057
4135
  position++;
4058
4136
  count++;
4059
4137
  if (eof()) {
4060
4138
  break;
4061
4139
  }
4062
- ch = input.charCodeAt(position);
4140
+ const ch = input.charCodeAt(position);
4063
4141
  if (count < 12 && isLowercaseAsciiLetter(ch)) {
4064
4142
  continue;
4065
4143
  }
@@ -4405,35 +4483,6 @@ function createParser(code, options = {}) {
4405
4483
  reportInvalidDecorators(decorators, "import statement");
4406
4484
  item = parseImportStatement();
4407
4485
  break;
4408
- case Token.ModelKeyword:
4409
- item = parseModelStatement(pos, decorators);
4410
- break;
4411
- case Token.ScalarKeyword:
4412
- item = parseScalarStatement(pos, decorators);
4413
- break;
4414
- case Token.NamespaceKeyword:
4415
- item = parseNamespaceStatement(pos, decorators, docs, directives);
4416
- break;
4417
- case Token.InterfaceKeyword:
4418
- item = parseInterfaceStatement(pos, decorators);
4419
- break;
4420
- case Token.UnionKeyword:
4421
- item = parseUnionStatement(pos, decorators);
4422
- break;
4423
- case Token.OpKeyword:
4424
- item = parseOperationStatement(pos, decorators);
4425
- break;
4426
- case Token.EnumKeyword:
4427
- item = parseEnumStatement(pos, decorators);
4428
- break;
4429
- case Token.AliasKeyword:
4430
- reportInvalidDecorators(decorators, "alias statement");
4431
- item = parseAliasStatement(pos);
4432
- break;
4433
- case Token.ConstKeyword:
4434
- reportInvalidDecorators(decorators, "const statement");
4435
- item = parseConstStatement(pos);
4436
- break;
4437
4486
  case Token.UsingKeyword:
4438
4487
  reportInvalidDecorators(decorators, "using statement");
4439
4488
  item = parseUsingStatement(pos);
@@ -4443,10 +4492,20 @@ function createParser(code, options = {}) {
4443
4492
  item = parseEmptyStatement(pos);
4444
4493
  break;
4445
4494
  // Start of declaration with modifiers
4495
+ case Token.NamespaceKeyword:
4496
+ case Token.ModelKeyword:
4497
+ case Token.ScalarKeyword:
4498
+ case Token.InterfaceKeyword:
4499
+ case Token.UnionKeyword:
4500
+ case Token.OpKeyword:
4501
+ case Token.EnumKeyword:
4502
+ case Token.AliasKeyword:
4503
+ case Token.ConstKeyword:
4446
4504
  case Token.ExternKeyword:
4505
+ case Token.InternalKeyword:
4447
4506
  case Token.FnKeyword:
4448
4507
  case Token.DecKeyword:
4449
- item = parseDeclaration(pos);
4508
+ item = parseDeclaration(pos, decorators, docs, directives);
4450
4509
  break;
4451
4510
  default:
4452
4511
  item = parseInvalidStatement(pos, decorators);
@@ -4493,47 +4552,24 @@ function createParser(code, options = {}) {
4493
4552
  item = parseImportStatement();
4494
4553
  error({ code: "import-first", messageId: "topLevel", target: item });
4495
4554
  break;
4496
- case Token.ModelKeyword:
4497
- item = parseModelStatement(pos, decorators);
4555
+ case Token.UsingKeyword:
4556
+ reportInvalidDecorators(decorators, "using statement");
4557
+ item = parseUsingStatement(pos);
4498
4558
  break;
4559
+ case Token.ModelKeyword:
4499
4560
  case Token.ScalarKeyword:
4500
- item = parseScalarStatement(pos, decorators);
4501
- break;
4502
4561
  case Token.NamespaceKeyword:
4503
- const ns = parseNamespaceStatement(pos, decorators, docs, directives);
4504
- if (isBlocklessNamespace(ns)) {
4505
- error({ code: "blockless-namespace-first", messageId: "topLevel", target: ns });
4506
- }
4507
- item = ns;
4508
- break;
4509
4562
  case Token.InterfaceKeyword:
4510
- item = parseInterfaceStatement(pos, decorators);
4511
- break;
4512
4563
  case Token.UnionKeyword:
4513
- item = parseUnionStatement(pos, decorators);
4514
- break;
4515
4564
  case Token.OpKeyword:
4516
- item = parseOperationStatement(pos, decorators);
4517
- break;
4518
4565
  case Token.EnumKeyword:
4519
- item = parseEnumStatement(pos, decorators);
4520
- break;
4521
4566
  case Token.AliasKeyword:
4522
- reportInvalidDecorators(decorators, "alias statement");
4523
- item = parseAliasStatement(pos);
4524
- break;
4525
4567
  case Token.ConstKeyword:
4526
- reportInvalidDecorators(decorators, "const statement");
4527
- item = parseConstStatement(pos);
4528
- break;
4529
- case Token.UsingKeyword:
4530
- reportInvalidDecorators(decorators, "using statement");
4531
- item = parseUsingStatement(pos);
4532
- break;
4533
4568
  case Token.ExternKeyword:
4569
+ case Token.InternalKeyword:
4534
4570
  case Token.FnKeyword:
4535
4571
  case Token.DecKeyword:
4536
- item = parseDeclaration(pos);
4572
+ item = parseDeclaration(pos, decorators, docs, directives);
4537
4573
  break;
4538
4574
  case Token.EndOfFile:
4539
4575
  parseExpected(Token.CloseBrace);
@@ -4546,6 +4582,9 @@ function createParser(code, options = {}) {
4546
4582
  item = parseInvalidStatement(pos, decorators);
4547
4583
  break;
4548
4584
  }
4585
+ if (isBlocklessNamespace(item)) {
4586
+ error({ code: "blockless-namespace-first", messageId: "topLevel", target: item });
4587
+ }
4549
4588
  mutate(item).directives = directives;
4550
4589
  if (tok !== Token.NamespaceKeyword) {
4551
4590
  mutate(item).docs = docs;
@@ -4568,7 +4607,7 @@ function createParser(code, options = {}) {
4568
4607
  }
4569
4608
  return directives;
4570
4609
  }
4571
- function parseNamespaceStatement(pos, decorators, docs, directives) {
4610
+ function parseNamespaceStatement(pos, decorators, modifiers, docs, directives) {
4572
4611
  parseExpected(Token.NamespaceKeyword);
4573
4612
  let currentName = parseIdentifierOrMemberExpression();
4574
4613
  const nsSegments = [];
@@ -4591,6 +4630,8 @@ function createParser(code, options = {}) {
4591
4630
  locals: void 0,
4592
4631
  statements,
4593
4632
  directives,
4633
+ modifiers,
4634
+ modifierFlags: modifiersToFlags(modifiers),
4594
4635
  ...finishNode(pos)
4595
4636
  };
4596
4637
  for (let i = 1; i < nsSegments.length; i++) {
@@ -4601,12 +4642,14 @@ function createParser(code, options = {}) {
4601
4642
  id: nsSegments[i],
4602
4643
  statements: outerNs,
4603
4644
  locals: void 0,
4645
+ modifiers: [],
4646
+ modifierFlags: 0,
4604
4647
  ...finishNode(pos)
4605
4648
  };
4606
4649
  }
4607
4650
  return outerNs;
4608
4651
  }
4609
- function parseInterfaceStatement(pos, decorators) {
4652
+ function parseInterfaceStatement(pos, decorators, modifiers) {
4610
4653
  parseExpected(Token.InterfaceKeyword);
4611
4654
  const id = parseIdentifier();
4612
4655
  const { items: templateParameters, range: templateParametersRange } = parseTemplateParameterList();
@@ -4618,7 +4661,13 @@ function createParser(code, options = {}) {
4618
4661
  error({ code: "token-expected", format: { token: "'extends' or '{'" } });
4619
4662
  nextToken();
4620
4663
  }
4621
- const { items: operations, range: bodyRange } = parseList(ListKind.InterfaceMembers, (pos2, decorators2) => parseOperationStatement(pos2, decorators2, true));
4664
+ const { items: operations, range: bodyRange } = parseList(ListKind.InterfaceMembers, (pos2, decorators2) => parseOperationStatement(
4665
+ pos2,
4666
+ decorators2,
4667
+ /* modifiers */
4668
+ void 0,
4669
+ true
4670
+ ));
4622
4671
  return {
4623
4672
  kind: SyntaxKind.InterfaceStatement,
4624
4673
  id,
@@ -4628,6 +4677,8 @@ function createParser(code, options = {}) {
4628
4677
  bodyRange,
4629
4678
  extends: extendList.items,
4630
4679
  decorators,
4680
+ modifiers,
4681
+ modifierFlags: modifiersToFlags(modifiers),
4631
4682
  ...finishNode(pos)
4632
4683
  };
4633
4684
  }
@@ -4645,7 +4696,7 @@ function createParser(code, options = {}) {
4645
4696
  }
4646
4697
  return detail;
4647
4698
  }
4648
- function parseUnionStatement(pos, decorators) {
4699
+ function parseUnionStatement(pos, decorators, modifiers) {
4649
4700
  parseExpected(Token.UnionKeyword);
4650
4701
  const id = parseIdentifier();
4651
4702
  const { items: templateParameters, range: templateParametersRange } = parseTemplateParameterList();
@@ -4656,6 +4707,8 @@ function createParser(code, options = {}) {
4656
4707
  templateParameters,
4657
4708
  templateParametersRange,
4658
4709
  decorators,
4710
+ modifiers,
4711
+ modifierFlags: modifiersToFlags(modifiers),
4659
4712
  options: options2,
4660
4713
  ...finishNode(pos)
4661
4714
  };
@@ -4663,10 +4716,14 @@ function createParser(code, options = {}) {
4663
4716
  function parseIdOrValueForVariant() {
4664
4717
  const nextToken2 = token();
4665
4718
  let id;
4666
- if (isReservedKeyword(nextToken2)) {
4719
+ if (isReservedKeyword(nextToken2) || isModifier(nextToken2)) {
4667
4720
  id = parseIdentifier({ allowReservedIdentifier: true });
4668
4721
  if (token() !== Token.Colon) {
4669
- error({ code: "reserved-identifier", messageId: "future", format: { name: id.sv } });
4722
+ if (isReservedKeyword(nextToken2)) {
4723
+ error({ code: "reserved-identifier", messageId: "future", format: { name: id.sv } });
4724
+ } else {
4725
+ error({ code: "reserved-identifier" });
4726
+ }
4670
4727
  }
4671
4728
  return {
4672
4729
  kind: SyntaxKind.TypeReference,
@@ -4725,10 +4782,13 @@ function createParser(code, options = {}) {
4725
4782
  ...finishNode(pos)
4726
4783
  };
4727
4784
  }
4728
- function parseOperationStatement(pos, decorators, inInterface) {
4785
+ function parseOperationStatement(pos, decorators, _modifiers, inInterface) {
4786
+ let modifiers;
4729
4787
  if (inInterface) {
4788
+ modifiers = parseModifiers();
4730
4789
  parseOptional(Token.OpKeyword);
4731
4790
  } else {
4791
+ modifiers = _modifiers;
4732
4792
  parseExpected(Token.OpKeyword);
4733
4793
  }
4734
4794
  const id = parseIdentifier();
@@ -4765,6 +4825,8 @@ function createParser(code, options = {}) {
4765
4825
  templateParametersRange,
4766
4826
  signature,
4767
4827
  decorators,
4828
+ modifiers,
4829
+ modifierFlags: modifiersToFlags(modifiers),
4768
4830
  ...finishNode(pos)
4769
4831
  };
4770
4832
  }
@@ -4779,7 +4841,7 @@ function createParser(code, options = {}) {
4779
4841
  };
4780
4842
  return parameters;
4781
4843
  }
4782
- function parseModelStatement(pos, decorators) {
4844
+ function parseModelStatement(pos, decorators, modifiers) {
4783
4845
  parseExpected(Token.ModelKeyword);
4784
4846
  const id = parseIdentifier();
4785
4847
  const { items: templateParameters, range: templateParametersRange } = parseTemplateParameterList();
@@ -4807,6 +4869,8 @@ function createParser(code, options = {}) {
4807
4869
  decorators,
4808
4870
  properties: propDetail.items,
4809
4871
  bodyRange: propDetail.range,
4872
+ modifiers,
4873
+ modifierFlags: modifiersToFlags(modifiers),
4810
4874
  ...finishNode(pos)
4811
4875
  };
4812
4876
  }
@@ -4827,7 +4891,7 @@ function createParser(code, options = {}) {
4827
4891
  const id = parseIdentifier();
4828
4892
  let constraint;
4829
4893
  if (parseOptional(Token.ExtendsKeyword)) {
4830
- constraint = parseMixedParameterConstraint();
4894
+ constraint = parseMixedConstraint();
4831
4895
  }
4832
4896
  let def;
4833
4897
  if (parseOptional(Token.Equals)) {
@@ -4845,13 +4909,13 @@ function createParser(code, options = {}) {
4845
4909
  if (token() === Token.ValueOfKeyword) {
4846
4910
  return parseValueOfExpression();
4847
4911
  } else if (parseOptional(Token.OpenParen)) {
4848
- const expr = parseMixedParameterConstraint();
4912
+ const expr = parseMixedConstraint();
4849
4913
  parseExpected(Token.CloseParen);
4850
4914
  return expr;
4851
4915
  }
4852
4916
  return parseIntersectionExpressionOrHigher();
4853
4917
  }
4854
- function parseMixedParameterConstraint() {
4918
+ function parseMixedConstraint() {
4855
4919
  const pos = tokenPos();
4856
4920
  parseOptional(Token.Bar);
4857
4921
  const node = parseValueOfExpressionOrIntersectionOrHigher();
@@ -4930,7 +4994,7 @@ function createParser(code, options = {}) {
4930
4994
  ...finishNode(pos)
4931
4995
  };
4932
4996
  }
4933
- function parseScalarStatement(pos, decorators) {
4997
+ function parseScalarStatement(pos, decorators, modifiers) {
4934
4998
  parseExpected(Token.ScalarKeyword);
4935
4999
  const id = parseIdentifier();
4936
5000
  const { items: templateParameters, range: templateParametersRange } = parseTemplateParameterList();
@@ -4945,6 +5009,8 @@ function createParser(code, options = {}) {
4945
5009
  members,
4946
5010
  bodyRange,
4947
5011
  decorators,
5012
+ modifiers,
5013
+ modifierFlags: modifiersToFlags(modifiers),
4948
5014
  ...finishNode(pos)
4949
5015
  };
4950
5016
  }
@@ -4974,7 +5040,7 @@ function createParser(code, options = {}) {
4974
5040
  ...finishNode(pos)
4975
5041
  };
4976
5042
  }
4977
- function parseEnumStatement(pos, decorators) {
5043
+ function parseEnumStatement(pos, decorators, modifiers) {
4978
5044
  parseExpected(Token.EnumKeyword);
4979
5045
  const id = parseIdentifier();
4980
5046
  const { items: members } = parseList(ListKind.EnumMembers, parseEnumMemberOrSpread);
@@ -4982,6 +5048,8 @@ function createParser(code, options = {}) {
4982
5048
  kind: SyntaxKind.EnumStatement,
4983
5049
  id,
4984
5050
  decorators,
5051
+ modifiers,
5052
+ modifierFlags: modifiersToFlags(modifiers),
4985
5053
  members,
4986
5054
  ...finishNode(pos)
4987
5055
  };
@@ -5024,7 +5092,7 @@ function createParser(code, options = {}) {
5024
5092
  ...finishNode(pos)
5025
5093
  };
5026
5094
  }
5027
- function parseAliasStatement(pos) {
5095
+ function parseAliasStatement(pos, modifiers) {
5028
5096
  parseExpected(Token.AliasKeyword);
5029
5097
  const id = parseIdentifier();
5030
5098
  const { items: templateParameters, range: templateParametersRange } = parseTemplateParameterList();
@@ -5037,10 +5105,12 @@ function createParser(code, options = {}) {
5037
5105
  templateParameters,
5038
5106
  templateParametersRange,
5039
5107
  value,
5108
+ modifiers,
5109
+ modifierFlags: modifiersToFlags(modifiers),
5040
5110
  ...finishNode(pos)
5041
5111
  };
5042
5112
  }
5043
- function parseConstStatement(pos) {
5113
+ function parseConstStatement(pos, modifiers) {
5044
5114
  parseExpected(Token.ConstKeyword);
5045
5115
  const id = parseIdentifier();
5046
5116
  const type = parseOptionalTypeAnnotation();
@@ -5052,6 +5122,8 @@ function createParser(code, options = {}) {
5052
5122
  id,
5053
5123
  value,
5054
5124
  type,
5125
+ modifiers,
5126
+ modifierFlags: modifiersToFlags(modifiers),
5055
5127
  ...finishNode(pos)
5056
5128
  };
5057
5129
  }
@@ -5076,6 +5148,14 @@ function createParser(code, options = {}) {
5076
5148
  const expr = parseIntersectionExpressionOrHigher();
5077
5149
  options2.push(expr);
5078
5150
  }
5151
+ for (const fnVariant of options2.filter((n) => n.kind === SyntaxKind.FunctionTypeExpression)) {
5152
+ if (!fnVariant.parenthesized) {
5153
+ error({
5154
+ code: "fn-in-union-expression",
5155
+ target: fnVariant
5156
+ });
5157
+ }
5158
+ }
5079
5159
  return {
5080
5160
  kind: SyntaxKind.UnionExpression,
5081
5161
  options: options2,
@@ -5166,6 +5246,19 @@ function createParser(code, options = {}) {
5166
5246
  }
5167
5247
  }
5168
5248
  }
5249
+ function parseFunctionTypeExpression() {
5250
+ const pos = tokenPos();
5251
+ parseExpected(Token.FnKeyword);
5252
+ const { items: parameters } = parseFunctionParameters();
5253
+ const optionalReturnType = parseOptional(Token.EqualsGreaterThan);
5254
+ const returnType = optionalReturnType ? parseMixedConstraint() : void 0;
5255
+ return {
5256
+ kind: SyntaxKind.FunctionTypeExpression,
5257
+ parameters,
5258
+ returnType,
5259
+ ...finishNode(pos)
5260
+ };
5261
+ }
5169
5262
  function parseReferenceExpression(message) {
5170
5263
  const pos = tokenPos();
5171
5264
  const target = parseIdentifierOrMemberExpression({
@@ -5391,6 +5484,8 @@ function createParser(code, options = {}) {
5391
5484
  switch (token()) {
5392
5485
  case Token.TypeOfKeyword:
5393
5486
  return parseTypeOfExpression();
5487
+ case Token.FnKeyword:
5488
+ return parseFunctionTypeExpression();
5394
5489
  case Token.Identifier:
5395
5490
  return parseCallOrReferenceExpression();
5396
5491
  case Token.StringLiteral:
@@ -5439,6 +5534,14 @@ function createParser(code, options = {}) {
5439
5534
  ...finishNode(pos)
5440
5535
  };
5441
5536
  }
5537
+ function parseInternalKeyword() {
5538
+ const pos = tokenPos();
5539
+ parseExpected(Token.InternalKeyword);
5540
+ return {
5541
+ kind: SyntaxKind.InternalKeyword,
5542
+ ...finishNode(pos)
5543
+ };
5544
+ }
5442
5545
  function parseVoidKeyword() {
5443
5546
  const pos = tokenPos();
5444
5547
  parseExpected(Token.VoidKeyword);
@@ -5468,7 +5571,7 @@ function createParser(code, options = {}) {
5468
5571
  parseExpected(Token.OpenParen);
5469
5572
  const expr = parseExpression();
5470
5573
  parseExpected(Token.CloseParen);
5471
- return { ...expr, ...finishNode(pos) };
5574
+ return { parenthesized: true, ...expr, ...finishNode(pos) };
5472
5575
  }
5473
5576
  function parseTupleExpression() {
5474
5577
  const pos = tokenPos();
@@ -5623,8 +5726,10 @@ function createParser(code, options = {}) {
5623
5726
  }
5624
5727
  function parseIdentifier(options2) {
5625
5728
  if (isKeyword(token())) {
5626
- error({ code: "reserved-identifier" });
5627
- return createMissingIdentifier();
5729
+ if (!(isModifier(token()) && options2?.allowReservedIdentifier)) {
5730
+ error({ code: "reserved-identifier" });
5731
+ return createMissingIdentifier();
5732
+ }
5628
5733
  } else if (isReservedKeyword(token())) {
5629
5734
  if (!options2?.allowReservedIdentifier) {
5630
5735
  error({ code: "reserved-identifier", messageId: "future", format: { name: tokenValue() } });
@@ -5642,9 +5747,29 @@ function createParser(code, options = {}) {
5642
5747
  ...finishNode(pos)
5643
5748
  };
5644
5749
  }
5645
- function parseDeclaration(pos) {
5750
+ function parseDeclaration(pos, decorators, docs, directives) {
5646
5751
  const modifiers = parseModifiers();
5647
5752
  switch (token()) {
5753
+ case Token.ModelKeyword:
5754
+ return parseModelStatement(pos, decorators, modifiers);
5755
+ case Token.ScalarKeyword:
5756
+ return parseScalarStatement(pos, decorators, modifiers);
5757
+ case Token.NamespaceKeyword:
5758
+ return parseNamespaceStatement(pos, decorators, modifiers, docs, directives);
5759
+ case Token.InterfaceKeyword:
5760
+ return parseInterfaceStatement(pos, decorators, modifiers);
5761
+ case Token.UnionKeyword:
5762
+ return parseUnionStatement(pos, decorators, modifiers);
5763
+ case Token.OpKeyword:
5764
+ return parseOperationStatement(pos, decorators, modifiers);
5765
+ case Token.EnumKeyword:
5766
+ return parseEnumStatement(pos, decorators, modifiers);
5767
+ case Token.AliasKeyword:
5768
+ reportInvalidDecorators(decorators, "alias statement");
5769
+ return parseAliasStatement(pos, modifiers);
5770
+ case Token.ConstKeyword:
5771
+ reportInvalidDecorators(decorators, "const statement");
5772
+ return parseConstStatement(pos, modifiers);
5648
5773
  case Token.DecKeyword:
5649
5774
  return parseDecoratorDeclarationStatement(pos, modifiers);
5650
5775
  case Token.FnKeyword:
@@ -5664,6 +5789,8 @@ function createParser(code, options = {}) {
5664
5789
  switch (token()) {
5665
5790
  case Token.ExternKeyword:
5666
5791
  return parseExternKeyword();
5792
+ case Token.InternalKeyword:
5793
+ return parseInternalKeyword();
5667
5794
  default:
5668
5795
  return void 0;
5669
5796
  }
@@ -5706,7 +5833,7 @@ function createParser(code, options = {}) {
5706
5833
  const { items: parameters } = parseFunctionParameters();
5707
5834
  let returnType;
5708
5835
  if (parseOptional(Token.Colon)) {
5709
- returnType = parseExpression();
5836
+ returnType = parseMixedConstraint();
5710
5837
  }
5711
5838
  parseExpected(Token.Semicolon);
5712
5839
  return {
@@ -5746,7 +5873,7 @@ function createParser(code, options = {}) {
5746
5873
  const optional = parseOptional(Token.Question);
5747
5874
  let type;
5748
5875
  if (parseOptional(Token.Colon)) {
5749
- type = parseMixedParameterConstraint();
5876
+ type = parseMixedConstraint();
5750
5877
  }
5751
5878
  return {
5752
5879
  kind: SyntaxKind.FunctionParameter,
@@ -5757,17 +5884,6 @@ function createParser(code, options = {}) {
5757
5884
  ...finishNode(pos)
5758
5885
  };
5759
5886
  }
5760
- function modifiersToFlags(modifiers) {
5761
- let flags = 0;
5762
- for (const modifier of modifiers) {
5763
- switch (modifier.kind) {
5764
- case SyntaxKind.ExternKeyword:
5765
- flags |= 2;
5766
- break;
5767
- }
5768
- }
5769
- return flags;
5770
- }
5771
5887
  function parseRange(mode, range, callback) {
5772
5888
  const savedMode = currentMode;
5773
5889
  const result = scanner.scanRange(range, () => {
@@ -6301,15 +6417,15 @@ function visitChildren(node, cb) {
6301
6417
  case SyntaxKind.ImportStatement:
6302
6418
  return visitNode(cb, node.path);
6303
6419
  case SyntaxKind.OperationStatement:
6304
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitNode(cb, node.signature);
6420
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitNode(cb, node.signature);
6305
6421
  case SyntaxKind.OperationSignatureDeclaration:
6306
6422
  return visitNode(cb, node.parameters) || visitNode(cb, node.returnType);
6307
6423
  case SyntaxKind.OperationSignatureReference:
6308
6424
  return visitNode(cb, node.baseOperation);
6309
6425
  case SyntaxKind.NamespaceStatement:
6310
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || (isArray(node.statements) ? visitEach(cb, node.statements) : visitNode(cb, node.statements));
6426
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || (isArray(node.statements) ? visitEach(cb, node.statements) : visitNode(cb, node.statements));
6311
6427
  case SyntaxKind.InterfaceStatement:
6312
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitEach(cb, node.extends) || visitEach(cb, node.operations);
6428
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitEach(cb, node.extends) || visitEach(cb, node.operations);
6313
6429
  case SyntaxKind.UsingStatement:
6314
6430
  return visitNode(cb, node.name);
6315
6431
  case SyntaxKind.IntersectionExpression:
@@ -6323,29 +6439,31 @@ function visitChildren(node, cb) {
6323
6439
  case SyntaxKind.ModelSpreadProperty:
6324
6440
  return visitNode(cb, node.target);
6325
6441
  case SyntaxKind.ModelStatement:
6326
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitNode(cb, node.extends) || visitNode(cb, node.is) || visitEach(cb, node.properties);
6442
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitNode(cb, node.extends) || visitNode(cb, node.is) || visitEach(cb, node.properties);
6327
6443
  case SyntaxKind.ScalarStatement:
6328
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitEach(cb, node.members) || visitNode(cb, node.extends);
6444
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitEach(cb, node.members) || visitNode(cb, node.extends);
6329
6445
  case SyntaxKind.ScalarConstructor:
6330
6446
  return visitNode(cb, node.id) || visitEach(cb, node.parameters);
6331
6447
  case SyntaxKind.UnionStatement:
6332
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitEach(cb, node.options);
6448
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitEach(cb, node.options);
6333
6449
  case SyntaxKind.UnionVariant:
6334
6450
  return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitNode(cb, node.value);
6335
6451
  case SyntaxKind.EnumStatement:
6336
- return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.members);
6452
+ return visitEach(cb, node.modifiers) || visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitEach(cb, node.members);
6337
6453
  case SyntaxKind.EnumMember:
6338
6454
  return visitEach(cb, node.decorators) || visitNode(cb, node.id) || visitNode(cb, node.value);
6339
6455
  case SyntaxKind.EnumSpreadMember:
6340
6456
  return visitNode(cb, node.target);
6341
6457
  case SyntaxKind.AliasStatement:
6342
- return visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitNode(cb, node.value);
6458
+ return visitEach(cb, node.modifiers) || visitNode(cb, node.id) || visitEach(cb, node.templateParameters) || visitNode(cb, node.value);
6343
6459
  case SyntaxKind.ConstStatement:
6344
- return visitNode(cb, node.id) || visitNode(cb, node.value) || visitNode(cb, node.type);
6460
+ return visitEach(cb, node.modifiers) || visitNode(cb, node.id) || visitNode(cb, node.value) || visitNode(cb, node.type);
6345
6461
  case SyntaxKind.DecoratorDeclarationStatement:
6346
6462
  return visitEach(cb, node.modifiers) || visitNode(cb, node.id) || visitNode(cb, node.target) || visitEach(cb, node.parameters);
6347
6463
  case SyntaxKind.FunctionDeclarationStatement:
6348
6464
  return visitEach(cb, node.modifiers) || visitNode(cb, node.id) || visitEach(cb, node.parameters) || visitNode(cb, node.returnType);
6465
+ case SyntaxKind.FunctionTypeExpression:
6466
+ return visitEach(cb, node.parameters) || visitNode(cb, node.returnType);
6349
6467
  case SyntaxKind.FunctionParameter:
6350
6468
  return visitNode(cb, node.id) || visitNode(cb, node.type);
6351
6469
  case SyntaxKind.TypeReference:
@@ -6399,6 +6517,7 @@ function visitChildren(node, cb) {
6399
6517
  case SyntaxKind.VoidKeyword:
6400
6518
  case SyntaxKind.NeverKeyword:
6401
6519
  case SyntaxKind.ExternKeyword:
6520
+ case SyntaxKind.InternalKeyword:
6402
6521
  case SyntaxKind.UnknownKeyword:
6403
6522
  case SyntaxKind.JsSourceFile:
6404
6523
  case SyntaxKind.JsNamespaceDeclaration:
@@ -6680,10 +6799,14 @@ function printNode(path, options, print) {
6680
6799
  return printDecoratorDeclarationStatement(path, options, print);
6681
6800
  case SyntaxKind.FunctionDeclarationStatement:
6682
6801
  return printFunctionDeclarationStatement(path, options, print);
6802
+ case SyntaxKind.FunctionTypeExpression:
6803
+ return printFunctionTypeExpression(path, options, print);
6683
6804
  case SyntaxKind.FunctionParameter:
6684
6805
  return printFunctionParameterDeclaration(path, options, print);
6685
6806
  case SyntaxKind.ExternKeyword:
6686
6807
  return "extern";
6808
+ case SyntaxKind.InternalKeyword:
6809
+ return "internal";
6687
6810
  case SyntaxKind.VoidKeyword:
6688
6811
  return "void";
6689
6812
  case SyntaxKind.NeverKeyword:
@@ -6743,13 +6866,29 @@ function printTypeSpecScript(path, options, print) {
6743
6866
  function printAliasStatement(path, options, print) {
6744
6867
  const id = path.call(print, "id");
6745
6868
  const template = printTemplateParameters(path, options, print, "templateParameters");
6746
- return ["alias ", id, template, " = ", path.call(print, "value"), ";"];
6869
+ return [
6870
+ printModifiers(path, options, print),
6871
+ "alias ",
6872
+ id,
6873
+ template,
6874
+ " = ",
6875
+ path.call(print, "value"),
6876
+ ";"
6877
+ ];
6747
6878
  }
6748
6879
  function printConstStatement(path, options, print) {
6749
6880
  const node = path.node;
6750
6881
  const id = path.call(print, "id");
6751
6882
  const type = node.type ? [": ", path.call(print, "type")] : "";
6752
- return ["const ", id, type, " = ", path.call(print, "value"), ";"];
6883
+ return [
6884
+ printModifiers(path, options, print),
6885
+ "const ",
6886
+ id,
6887
+ type,
6888
+ " = ",
6889
+ path.call(print, "value"),
6890
+ ";"
6891
+ ];
6753
6892
  }
6754
6893
  function printCallExpression(path, options, print) {
6755
6894
  const args = printCallLikeArgs(path, options, print);
@@ -6907,7 +7046,14 @@ function printDirectiveArgs(path, options, print) {
6907
7046
  function printEnumStatement(path, options, print) {
6908
7047
  const { decorators } = printDecorators(path, options, print, { tryInline: false });
6909
7048
  const id = path.call(print, "id");
6910
- return [decorators, "enum ", id, " ", printEnumBlock(path, options, print)];
7049
+ return [
7050
+ decorators,
7051
+ printModifiers(path, options, print),
7052
+ "enum ",
7053
+ id,
7054
+ " ",
7055
+ printEnumBlock(path, options, print)
7056
+ ];
6911
7057
  }
6912
7058
  function printEnumBlock(path, options, print) {
6913
7059
  const node = path.node;
@@ -6933,7 +7079,15 @@ function printUnionStatement(path, options, print) {
6933
7079
  const id = path.call(print, "id");
6934
7080
  const { decorators } = printDecorators(path, options, print, { tryInline: false });
6935
7081
  const generic = printTemplateParameters(path, options, print, "templateParameters");
6936
- return [decorators, "union ", id, generic, " ", printUnionVariantsBlock(path, options, print)];
7082
+ return [
7083
+ decorators,
7084
+ printModifiers(path, options, print),
7085
+ "union ",
7086
+ id,
7087
+ generic,
7088
+ " ",
7089
+ printUnionVariantsBlock(path, options, print)
7090
+ ];
6937
7091
  }
6938
7092
  function printUnionVariantsBlock(path, options, print) {
6939
7093
  const node = path.node;
@@ -6957,6 +7111,7 @@ function printInterfaceStatement(path, options, print) {
6957
7111
  const extendList = printInterfaceExtends(path, options, print);
6958
7112
  return [
6959
7113
  decorators,
7114
+ printModifiers(path, options, print),
6960
7115
  "interface ",
6961
7116
  id,
6962
7117
  generic,
@@ -7112,6 +7267,7 @@ function printModelStatement(path, options, print) {
7112
7267
  const body = shouldPrintBody ? [" ", printModelPropertiesBlock(path, options, print)] : ";";
7113
7268
  return [
7114
7269
  printDecorators(path, options, print, { tryInline: false }).decorators,
7270
+ printModifiers(path, options, print),
7115
7271
  "model ",
7116
7272
  id,
7117
7273
  generic,
@@ -7218,6 +7374,7 @@ function printScalarStatement(path, options, print) {
7218
7374
  const members = shouldPrintBody ? [" ", printScalarBody(path, options, print)] : ";";
7219
7375
  return [
7220
7376
  printDecorators(path, options, print, { tryInline: false }).decorators,
7377
+ printModifiers(path, options, print),
7221
7378
  "scalar ",
7222
7379
  id,
7223
7380
  template,
@@ -7274,6 +7431,7 @@ function printOperationStatement(path, options, print) {
7274
7431
  });
7275
7432
  return [
7276
7433
  decorators,
7434
+ printModifiers(path, options, print),
7277
7435
  inInterface ? "" : "op ",
7278
7436
  path.call(print, "id"),
7279
7437
  templateParams,
@@ -7391,6 +7549,17 @@ function printFunctionDeclarationStatement(path, options, print) {
7391
7549
  const returnType = node.returnType ? [": ", path.call(print, "returnType")] : "";
7392
7550
  return [printModifiers(path, options, print), "fn ", id, "(", parameters, ")", returnType, ";"];
7393
7551
  }
7552
+ function printFunctionTypeExpression(path, options, print) {
7553
+ const node = path.node;
7554
+ const parameters = [
7555
+ group([
7556
+ indent(join(", ", path.map((arg) => [softline, print(arg)], "parameters"))),
7557
+ softline
7558
+ ])
7559
+ ];
7560
+ const returnType = node.returnType ? [" => ", path.call(print, "returnType")] : "";
7561
+ return ["fn", "(", parameters, ")", returnType];
7562
+ }
7394
7563
  function printFunctionParameterDeclaration(path, options, print) {
7395
7564
  const node = path.node;
7396
7565
  const id = printIdentifier2(node.id, "allow-reserved");
@@ -7405,7 +7574,7 @@ function printFunctionParameterDeclaration(path, options, print) {
7405
7574
  }
7406
7575
  function printModifiers(path, options, print) {
7407
7576
  const node = path.node;
7408
- if (node.modifiers.length === 0) {
7577
+ if (node.modifiers === void 0 || node.modifiers.length === 0) {
7409
7578
  return "";
7410
7579
  }
7411
7580
  return path.map((x) => [print(x), " "], "modifiers");