@typespec/html-program-viewer 0.65.0-dev.1 → 0.65.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.
@@ -353,7 +353,7 @@ function getDebugClassNames(lookupItem, parentLookupItem, parentDebugClassNames,
353
353
  });
354
354
  }
355
355
 
356
- function getAtomicDebugSequenceTree(debugSequenceHash, parentNode) {
356
+ function getDebugTree(debugSequenceHash, parentNode) {
357
357
  const lookupItem = DEFINITION_LOOKUP_TABLE[debugSequenceHash];
358
358
  if (lookupItem === undefined) {
359
359
  return undefined;
@@ -369,7 +369,7 @@ function getAtomicDebugSequenceTree(debugSequenceHash, parentNode) {
369
369
  const childrenSequences = debugData.getChildrenSequences(node.sequenceHash);
370
370
  childrenSequences.reverse() // first process the overriding children that are merged last
371
371
  .forEach(sequence => {
372
- const child = getAtomicDebugSequenceTree(sequence, node);
372
+ const child = getDebugTree(sequence, node);
373
373
  if (child) {
374
374
  node.children.push(child);
375
375
  }
@@ -394,53 +394,6 @@ function getAtomicDebugSequenceTree(debugSequenceHash, parentNode) {
394
394
  return node;
395
395
  }
396
396
 
397
- function getResetDebugSequence(debugSequenceHash) {
398
- const resetClass = DEBUG_RESET_CLASSES[debugSequenceHash];
399
- if (resetClass === undefined) {
400
- return undefined;
401
- }
402
- const debugClassNames = [{
403
- className: debugSequenceHash
404
- }];
405
- const node = {
406
- sequenceHash: debugSequenceHash,
407
- direction: 'ltr',
408
- children: [],
409
- debugClassNames
410
- };
411
- node.rules = {};
412
- node.slot = 'makeResetStyles()';
413
- const [{
414
- className
415
- }] = node.debugClassNames;
416
- const cssRules = debugData.getCSSRules().filter(cssRule => {
417
- return cssRule.includes(`.${className}`);
418
- });
419
- node.rules[className] = cssRules.join('');
420
- return node;
421
- }
422
-
423
- function mergeDebugSequence(atomicClases, resetClassName) {
424
- const debugResultRootAtomic = atomicClases ? getAtomicDebugSequenceTree(atomicClases) : undefined;
425
- const debugResultRootReset = resetClassName ? getResetDebugSequence(resetClassName) : undefined;
426
- if (!debugResultRootAtomic && !debugResultRootReset) {
427
- return undefined;
428
- }
429
- if (!debugResultRootAtomic) {
430
- return debugResultRootReset;
431
- }
432
- if (!debugResultRootReset) {
433
- return debugResultRootAtomic;
434
- }
435
- const debugResultRoot = {
436
- sequenceHash: debugResultRootAtomic.sequenceHash + debugResultRootReset.sequenceHash,
437
- direction: debugResultRootAtomic.direction,
438
- children: [debugResultRootAtomic, debugResultRootReset],
439
- debugClassNames: [...debugResultRootAtomic.debugClassNames, ...debugResultRootReset.debugClassNames]
440
- };
441
- return debugResultRoot;
442
- }
443
-
444
397
  function injectDevTools(document) {
445
398
  const window = document.defaultView;
446
399
  if (!window || window.__GRIFFEL_DEVTOOLS__) {
@@ -448,18 +401,11 @@ function injectDevTools(document) {
448
401
  }
449
402
  const devtools = {
450
403
  getInfo: element => {
451
- let rootDebugSequenceHash;
452
- let rootResetDebugClassName;
453
- for (const className of element.classList) {
454
- if (className.startsWith(SEQUENCE_PREFIX)) {
455
- rootDebugSequenceHash = className;
456
- return;
457
- }
458
- if (DEBUG_RESET_CLASSES[className]) {
459
- rootResetDebugClassName = className;
460
- }
404
+ const rootDebugSequenceHash = Array.from(element.classList).find(className => className.startsWith(SEQUENCE_PREFIX));
405
+ if (rootDebugSequenceHash === undefined) {
406
+ return undefined;
461
407
  }
462
- return mergeDebugSequence(rootDebugSequenceHash, rootResetDebugClassName);
408
+ return getDebugTree(rootDebugSequenceHash);
463
409
  }
464
410
  };
465
411
  Object.defineProperty(window, '__GRIFFEL_DEVTOOLS__', {
@@ -0,0 +1,6 @@
1
+ const manifest = {
2
+ "version": "0.65.0",
3
+ "commit": "ef04080e69155401e5047cff69e5b50c1844d5dc"
4
+ };
5
+
6
+ export { manifest as default };
@@ -17889,6 +17889,82 @@ function normalizeSlashes(path) {
17889
17889
  return path.replace(backslashRegExp, directorySeparator);
17890
17890
  }
17891
17891
 
17892
+ function createSourceFile(text, path) {
17893
+ let lineStarts = undefined;
17894
+ return {
17895
+ text,
17896
+ path,
17897
+ getLineStarts,
17898
+ getLineAndCharacterOfPosition,
17899
+ };
17900
+ function getLineStarts() {
17901
+ return (lineStarts = lineStarts ?? scanLineStarts(text));
17902
+ }
17903
+ function getLineAndCharacterOfPosition(position) {
17904
+ const starts = getLineStarts();
17905
+ let line = binarySearch(starts, position);
17906
+ // When binarySearch returns < 0 indicating that the value was not found, it
17907
+ // returns the bitwise complement of the index where the value would need to
17908
+ // be inserted to keep the array sorted. So flipping the bits back to this
17909
+ // positive index tells us what the line number would be if we were to
17910
+ // create a new line starting at the given position, and subtracting 1 from
17911
+ // that therefore gives us the line number we're after.
17912
+ if (line < 0) {
17913
+ line = ~line - 1;
17914
+ }
17915
+ return {
17916
+ line,
17917
+ character: position - starts[line],
17918
+ };
17919
+ }
17920
+ }
17921
+ function scanLineStarts(text) {
17922
+ const starts = [];
17923
+ let start = 0;
17924
+ let pos = 0;
17925
+ while (pos < text.length) {
17926
+ const ch = text.charCodeAt(pos);
17927
+ pos++;
17928
+ switch (ch) {
17929
+ case 13 /* CharCode.CarriageReturn */:
17930
+ if (text.charCodeAt(pos) === 10 /* CharCode.LineFeed */) {
17931
+ pos++;
17932
+ }
17933
+ // fallthrough
17934
+ case 10 /* CharCode.LineFeed */:
17935
+ starts.push(start);
17936
+ start = pos;
17937
+ break;
17938
+ }
17939
+ }
17940
+ starts.push(start);
17941
+ return starts;
17942
+ }
17943
+ /**
17944
+ * Search sorted array of numbers for the given value. If found, return index
17945
+ * in array where value was found. If not found, return a negative number that
17946
+ * is the bitwise complement of the index where value would need to be inserted
17947
+ * to keep the array sorted.
17948
+ */
17949
+ function binarySearch(array, value) {
17950
+ let low = 0;
17951
+ let high = array.length - 1;
17952
+ while (low <= high) {
17953
+ const middle = low + ((high - low) >> 1);
17954
+ const v = array[middle];
17955
+ if (v < value) {
17956
+ low = middle + 1;
17957
+ }
17958
+ else if (v > value) {
17959
+ high = middle - 1;
17960
+ }
17961
+ else {
17962
+ return middle;
17963
+ }
17964
+ }
17965
+ return ~low;
17966
+ }
17967
+
17892
17968
  var ResolutionResultFlags;
17893
17969
  (function (ResolutionResultFlags) {
17894
17970
  ResolutionResultFlags[ResolutionResultFlags["None"] = 0] = "None";
@@ -18034,7 +18110,7 @@ let manifest;
18034
18110
  try {
18035
18111
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18036
18112
  // @ts-ignore
18037
- manifest = (await import('../manifest-BVCtXeEX.js')).default;
18113
+ manifest = (await import('../manifest-BNuBm9Cd.js')).default;
18038
18114
  }
18039
18115
  catch {
18040
18116
  const name = "../dist/manifest.js";
@@ -18879,12 +18955,6 @@ const diagnostics = {
18879
18955
  required: "dec first parameter must be required.",
18880
18956
  },
18881
18957
  },
18882
- "projections-are-experimental": {
18883
- severity: "warning",
18884
- messages: {
18885
- default: "Projections are experimental - your code will need to change as this feature evolves.",
18886
- },
18887
- },
18888
18958
  "mixed-string-template": {
18889
18959
  severity: "error",
18890
18960
  messages: {
@@ -28203,6 +28273,67 @@ function findYamlNode(file, path, kind = "value") {
28203
28273
  return current ?? undefined;
28204
28274
  }
28205
28275
 
28276
+ function getSourceLocation(target, options = {}) {
28277
+ if (target === NoTarget || target === undefined) {
28278
+ return undefined;
28279
+ }
28280
+ if ("file" in target) {
28281
+ return target;
28282
+ }
28283
+ if (!("kind" in target) && !("entityKind" in target)) {
28284
+ // TemplateInstanceTarget
28285
+ if (!("declarations" in target)) {
28286
+ return getSourceLocationOfNode(target.node, options);
28287
+ }
28288
+ // symbol
28289
+ if (target.flags & 32768 /* SymbolFlags.Using */) {
28290
+ target = target.symbolSource;
28291
+ }
28292
+ if (!target.declarations[0]) {
28293
+ return createSyntheticSourceLocation();
28294
+ }
28295
+ return getSourceLocationOfNode(target.declarations[0], options);
28296
+ }
28297
+ else if ("kind" in target && typeof target.kind === "number") {
28298
+ // node
28299
+ return getSourceLocationOfNode(target, options);
28300
+ }
28301
+ else {
28302
+ // type
28303
+ const targetNode = target.node;
28304
+ if (targetNode) {
28305
+ return getSourceLocationOfNode(targetNode, options);
28306
+ }
28307
+ return createSyntheticSourceLocation();
28308
+ }
28309
+ }
28310
+ function createSyntheticSourceLocation(loc = "<unknown location>") {
28311
+ return {
28312
+ file: createSourceFile("", loc),
28313
+ pos: 0,
28314
+ end: 0,
28315
+ isSynthetic: true,
28316
+ };
28317
+ }
28318
+ function getSourceLocationOfNode(node, options) {
28319
+ let root = node;
28320
+ while (root.parent !== undefined) {
28321
+ root = root.parent;
28322
+ }
28323
+ if (root.kind !== SyntaxKind.TypeSpecScript && root.kind !== SyntaxKind.JsSourceFile) {
28324
+ return createSyntheticSourceLocation(node.flags & 8 /* NodeFlags.Synthetic */
28325
+ ? undefined
28326
+ : "<unknown location - cannot obtain source location of unbound node - file bug at https://github.com/microsoft/typespec>");
28327
+ }
28328
+ if (options.locateId && "id" in node && node.id !== undefined) {
28329
+ node = node.id;
28330
+ }
28331
+ return {
28332
+ file: root.file,
28333
+ pos: node.pos,
28334
+ end: node.end,
28335
+ };
28336
+ }
28206
28337
  /**
28207
28338
  * Use this to report bugs in the compiler, and not errors in the source code
28208
28339
  * being compiled.
@@ -28218,6 +28349,20 @@ function compilerAssert(condition, message, target) {
28218
28349
  if (condition) {
28219
28350
  return;
28220
28351
  }
28352
+ if (target) {
28353
+ let location;
28354
+ try {
28355
+ location = getSourceLocation(target);
28356
+ }
28357
+ catch (err) { }
28358
+ if (location) {
28359
+ const pos = location.file.getLineAndCharacterOfPosition(location.pos);
28360
+ const file = location.file.path;
28361
+ const line = pos.line + 1;
28362
+ const col = pos.character + 1;
28363
+ message += `\nOccurred while compiling code in ${file} near line ${line}, column ${col}`;
28364
+ }
28365
+ }
28221
28366
  throw new Error(message);
28222
28367
  }
28223
28368
  /**
@@ -28454,24 +28599,36 @@ deepFreeze({
28454
28599
  });
28455
28600
  createJSONSchemaValidator(TypeSpecConfigJsonSchema);
28456
28601
 
28457
- // Contains all intrinsic data setter or getter
28458
- // Anything that the TypeSpec check might should be here.
28459
- function createStateSymbol$1(name) {
28602
+ /**
28603
+ * Filters the properties of a model by removing them from the model instance if
28604
+ * a given `filter` predicate is not satisfied.
28605
+ *
28606
+ * @param model - the model to filter properties on
28607
+ * @param filter - the predicate to filter properties with
28608
+ */
28609
+ /**
28610
+ * Creates a unique symbol for storing state on objects
28611
+ * @param name The name/description of the state
28612
+ */
28613
+ function createStateSymbol(name) {
28460
28614
  return Symbol.for(`TypeSpec.${name}`);
28461
28615
  }
28616
+
28617
+ // Contains all intrinsic data setter or getter
28618
+ // Anything that the TypeSpec check might should be here.
28462
28619
  const stateKeys = {
28463
- minValues: createStateSymbol$1("minValues"),
28464
- maxValues: createStateSymbol$1("maxValues"),
28465
- minValueExclusive: createStateSymbol$1("minValueExclusive"),
28466
- maxValueExclusive: createStateSymbol$1("maxValueExclusive"),
28467
- minLength: createStateSymbol$1("minLengthValues"),
28468
- maxLength: createStateSymbol$1("maxLengthValues"),
28469
- minItems: createStateSymbol$1("minItems"),
28470
- maxItems: createStateSymbol$1("maxItems"),
28471
- docs: createStateSymbol$1("docs"),
28472
- returnDocs: createStateSymbol$1("returnsDocs"),
28473
- errorsDocs: createStateSymbol$1("errorDocs"),
28474
- discriminator: createStateSymbol$1("discriminator"),
28620
+ minValues: createStateSymbol("minValues"),
28621
+ maxValues: createStateSymbol("maxValues"),
28622
+ minValueExclusive: createStateSymbol("minValueExclusive"),
28623
+ maxValueExclusive: createStateSymbol("maxValueExclusive"),
28624
+ minLength: createStateSymbol("minLengthValues"),
28625
+ maxLength: createStateSymbol("maxLengthValues"),
28626
+ minItems: createStateSymbol("minItems"),
28627
+ maxItems: createStateSymbol("maxItems"),
28628
+ docs: createStateSymbol("docs"),
28629
+ returnDocs: createStateSymbol("returnsDocs"),
28630
+ errorsDocs: createStateSymbol("errorDocs"),
28631
+ discriminator: createStateSymbol("discriminator"),
28475
28632
  };
28476
28633
  function getDocKey(target) {
28477
28634
  switch (target) {
@@ -29652,6 +29809,35 @@ var ListKind;
29652
29809
  };
29653
29810
  })(ListKind || (ListKind = {}));
29654
29811
 
29812
+ const deprecatedKey = createStateSymbol("deprecated");
29813
+ /**
29814
+ * Returns complete deprecation details for the given type or node
29815
+ * @param program Program
29816
+ * @param typeOrNode A Type or Node to check for deprecation
29817
+ */
29818
+ function getDeprecationDetails(program, typeOrNode) {
29819
+ function isType(maybeType) {
29820
+ return typeof maybeType.kind === "string";
29821
+ }
29822
+ // If we're looking at a type, pull the deprecation details from the state map
29823
+ if (isType(typeOrNode)) {
29824
+ return program.stateMap(deprecatedKey).get(typeOrNode);
29825
+ }
29826
+ else {
29827
+ // Look at the node for a deprecation directive
29828
+ const deprecatedDirective = (typeOrNode.directives ?? []).find((directive) => directive.target.sv === "deprecated");
29829
+ if (deprecatedDirective?.arguments[0].kind === SyntaxKind.StringLiteral) {
29830
+ return {
29831
+ message: deprecatedDirective.arguments[0].value,
29832
+ };
29833
+ }
29834
+ }
29835
+ return undefined;
29836
+ }
29837
+
29838
+ function isErrorType(type) {
29839
+ return "kind" in type && type.kind === "Intrinsic" && type.name === "ErrorType";
29840
+ }
29655
29841
  function isType(entity) {
29656
29842
  return entity.entityKind === "Type";
29657
29843
  }
@@ -30119,6 +30305,7 @@ NumericPrototype.toString = function () {
30119
30305
  ],
30120
30306
  });
30121
30307
 
30308
+ /* eslint-disable @typescript-eslint/no-deprecated */
30122
30309
  var Related;
30123
30310
  (function (Related) {
30124
30311
  Related[Related["false"] = 0] = "false";
@@ -30127,6 +30314,274 @@ var Related;
30127
30314
  })(Related || (Related = {}));
30128
30315
  // #endregion
30129
30316
 
30317
+ /* eslint-disable @typescript-eslint/no-deprecated */
30318
+ /**
30319
+ * Find all named models that could have been the source of the given
30320
+ * property. This includes the named parents of all property sources in a
30321
+ * chain.
30322
+ */
30323
+ function getNamedSourceModels(property) {
30324
+ if (!property.sourceProperty) {
30325
+ return undefined;
30326
+ }
30327
+ const set = new Set();
30328
+ for (let p = property; p; p = p.sourceProperty) {
30329
+ if (p.model?.name) {
30330
+ set.add(p.model);
30331
+ }
30332
+ }
30333
+ return set;
30334
+ }
30335
+ /**
30336
+ * Find derived types of `models` in `possiblyDerivedModels` and add them to
30337
+ * `models`.
30338
+ */
30339
+ function addDerivedModels(models, possiblyDerivedModels) {
30340
+ for (const element of possiblyDerivedModels) {
30341
+ if (!models.has(element)) {
30342
+ for (let t = element.baseModel; t; t = t.baseModel) {
30343
+ if (models.has(t)) {
30344
+ models.add(element);
30345
+ break;
30346
+ }
30347
+ }
30348
+ }
30349
+ }
30350
+ }
30351
+ /**
30352
+ * If the input is anonymous (or the provided filter removes properties)
30353
+ * and there exists a named model with the same set of properties
30354
+ * (ignoring filtered properties), then return that named model.
30355
+ * Otherwise, return the input unchanged.
30356
+ *
30357
+ * This can be used by emitters to find a better name for a set of
30358
+ * properties after filtering. For example, given `{ @metadata prop:
30359
+ * string} & SomeName`, and an emitter that wishes to discard properties
30360
+ * marked with `@metadata`, the emitter can use this to recover that the
30361
+ * best name for the remaining properties is `SomeName`.
30362
+ *
30363
+ * @param model The input model
30364
+ * @param filter An optional filter to apply to the input model's
30365
+ * properties.
30366
+ */
30367
+ function getEffectiveModelType(program, model, filter) {
30368
+ if (filter) {
30369
+ model = filterModelProperties(program, model, filter);
30370
+ }
30371
+ if (model.name) {
30372
+ // named model
30373
+ return model;
30374
+ }
30375
+ // We would need to change the algorithm if this doesn't hold. We
30376
+ // assume model has no inherited properties below.
30377
+ compilerAssert(!model.baseModel, "Anonymous model with base model.");
30378
+ if (model.properties.size === 0) {
30379
+ // empty model
30380
+ return model;
30381
+ }
30382
+ // Find the candidate set of named model types that could have been the
30383
+ // source of every property in the model.
30384
+ let candidates;
30385
+ for (const property of model.properties.values()) {
30386
+ const sources = getNamedSourceModels(property);
30387
+ if (!sources) {
30388
+ // unsourced property: no possible match
30389
+ return model;
30390
+ }
30391
+ if (!candidates) {
30392
+ // first sourced property: initialize candidates to its sources
30393
+ candidates = sources;
30394
+ continue;
30395
+ }
30396
+ // Add derived sources as we encounter them. If a model is sourced from
30397
+ // a base property, then it can also be sourced from a derived model.
30398
+ //
30399
+ // (Unless it is overridden, but then the presence of the overridden
30400
+ // property will still cause the the base model to be excluded from the
30401
+ // candidates.)
30402
+ //
30403
+ // Note: We depend on the order of that spread and intersect source
30404
+ // properties here, which is that we see properties sourced from derived
30405
+ // types before properties sourced from their base types.
30406
+ addDerivedModels(sources, candidates);
30407
+ // remove candidates that are not common to this property.
30408
+ for (const candidate of candidates) {
30409
+ if (!sources.has(candidate)) {
30410
+ candidates.delete(candidate);
30411
+ }
30412
+ }
30413
+ }
30414
+ // Search for a candidate that has no additional properties (ignoring
30415
+ // filtered properties). If so, it is effectively the same type as the
30416
+ // input model. Consider a candidate that meets this test without
30417
+ // ignoring filtering as a better match than one that requires filtering
30418
+ // to meet this test.
30419
+ let match;
30420
+ for (const candidate of candidates ?? []) {
30421
+ if (model.properties.size === countPropertiesInherited(candidate)) {
30422
+ match = candidate;
30423
+ break; // exact match
30424
+ }
30425
+ if (filter && !match && model.properties.size === countPropertiesInherited(candidate, filter)) {
30426
+ match = candidate;
30427
+ continue; // match with filter: keep searching for exact match
30428
+ }
30429
+ }
30430
+ return match ?? model;
30431
+ }
30432
+ /**
30433
+ * Applies a filter to the properties of a given type. If no properties
30434
+ * are filtered out, then return the input unchanged. Otherwise, return
30435
+ * a new anonymous model with only the filtered properties.
30436
+ *
30437
+ * @param model The input model to filter.
30438
+ * @param filter The filter to apply. Properties are kept when this returns true.
30439
+ */
30440
+ function filterModelProperties(program, model, filter) {
30441
+ let filtered = false;
30442
+ for (const property of walkPropertiesInherited(model)) {
30443
+ if (!filter(property)) {
30444
+ filtered = true;
30445
+ break;
30446
+ }
30447
+ }
30448
+ if (!filtered) {
30449
+ return model;
30450
+ }
30451
+ const properties = createRekeyableMap();
30452
+ const newModel = program.checker.createType({
30453
+ kind: "Model",
30454
+ node: undefined,
30455
+ name: "",
30456
+ indexer: undefined,
30457
+ properties,
30458
+ decorators: [],
30459
+ derivedModels: [],
30460
+ sourceModels: [{ usage: "spread", model }],
30461
+ });
30462
+ for (const property of walkPropertiesInherited(model)) {
30463
+ if (filter(property)) {
30464
+ const newProperty = program.checker.cloneType(property, {
30465
+ sourceProperty: property,
30466
+ model: newModel,
30467
+ });
30468
+ properties.set(property.name, newProperty);
30469
+ }
30470
+ }
30471
+ return finishTypeForProgram(program, newModel);
30472
+ }
30473
+ /**
30474
+ * Enumerates the properties declared by model or inherited from its base.
30475
+ *
30476
+ * Properties declared by more derived types are enumerated before properties
30477
+ * of less derived types.
30478
+ *
30479
+ * Properties that are overridden are not enumerated.
30480
+ */
30481
+ function* walkPropertiesInherited(model) {
30482
+ const returned = new Set();
30483
+ for (let current = model; current; current = current.baseModel) {
30484
+ for (const property of current.properties.values()) {
30485
+ if (returned.has(property.name)) {
30486
+ // skip properties that have been overridden
30487
+ continue;
30488
+ }
30489
+ returned.add(property.name);
30490
+ yield property;
30491
+ }
30492
+ }
30493
+ }
30494
+ function countPropertiesInherited(model, filter) {
30495
+ let count = 0;
30496
+ for (const property of walkPropertiesInherited(model)) {
30497
+ if (!filter || filter(property)) {
30498
+ count++;
30499
+ }
30500
+ }
30501
+ return count;
30502
+ }
30503
+ function finishTypeForProgram(program, typeDef) {
30504
+ return finishTypeForProgramAndChecker(program, program.checker.typePrototype, typeDef);
30505
+ }
30506
+ function finishTypeForProgramAndChecker(program, typePrototype, typeDef) {
30507
+ if ("decorators" in typeDef) {
30508
+ for (const decApp of typeDef.decorators) {
30509
+ applyDecoratorToType(program, decApp, typeDef);
30510
+ }
30511
+ }
30512
+ Object.setPrototypeOf(typeDef, typePrototype);
30513
+ typeDef.isFinished = true;
30514
+ return typeDef;
30515
+ }
30516
+ function reportDeprecation(program, target, message, reportFunc) {
30517
+ if (program.compilerOptions.ignoreDeprecated !== true) {
30518
+ reportFunc(createDiagnostic({
30519
+ code: "deprecated",
30520
+ format: {
30521
+ message,
30522
+ },
30523
+ target,
30524
+ }));
30525
+ }
30526
+ }
30527
+ function applyDecoratorToType(program, decApp, target) {
30528
+ compilerAssert("decorators" in target, "Cannot apply decorator to non-decoratable type", target);
30529
+ for (const arg of decApp.args) {
30530
+ if (isType(arg.value) && isErrorType(arg.value)) {
30531
+ // If one of the decorator argument is an error don't run it.
30532
+ return;
30533
+ }
30534
+ }
30535
+ // Is the decorator definition deprecated?
30536
+ if (decApp.definition) {
30537
+ const deprecation = getDeprecationDetails(program, decApp.definition);
30538
+ if (deprecation !== undefined) {
30539
+ reportDeprecation(program, decApp.node ?? target, deprecation.message, program.reportDiagnostic);
30540
+ }
30541
+ }
30542
+ // peel `fn` off to avoid setting `this`.
30543
+ try {
30544
+ const args = decApp.args.map((x) => x.jsValue);
30545
+ const fn = decApp.decorator;
30546
+ const context = createDecoratorContext(program, decApp);
30547
+ fn(context, target, ...args);
30548
+ }
30549
+ catch (error) {
30550
+ // do not fail the language server for exceptions in decorators
30551
+ if (program.compilerOptions.designTimeBuild) {
30552
+ program.reportDiagnostic(createDiagnostic({
30553
+ code: "decorator-fail",
30554
+ format: { decoratorName: decApp.decorator.name, error: error.stack },
30555
+ target: decApp.node ?? target,
30556
+ }));
30557
+ }
30558
+ else {
30559
+ throw error;
30560
+ }
30561
+ }
30562
+ }
30563
+ function createDecoratorContext(program, decApp) {
30564
+ function createPassThruContext(program, decApp) {
30565
+ return {
30566
+ program,
30567
+ decoratorTarget: decApp.node,
30568
+ getArgumentTarget: () => decApp.node,
30569
+ call: (decorator, target, ...args) => {
30570
+ return decorator(createPassThruContext(program, decApp), target, ...args);
30571
+ },
30572
+ };
30573
+ }
30574
+ return {
30575
+ program,
30576
+ decoratorTarget: decApp.node,
30577
+ getArgumentTarget: (index) => {
30578
+ return decApp.args[index]?.node;
30579
+ },
30580
+ call: (decorator, target, ...args) => {
30581
+ return decorator(createPassThruContext(program, decApp), target, ...args);
30582
+ },
30583
+ };
30584
+ }
30130
30585
  var ResolutionKind;
30131
30586
  (function (ResolutionKind) {
30132
30587
  ResolutionKind[ResolutionKind["Value"] = 0] = "Value";
@@ -30136,7 +30591,9 @@ var ResolutionKind;
30136
30591
  })(ResolutionKind || (ResolutionKind = {}));
30137
30592
 
30138
30593
  function isIntrinsicType(program, type, kind) {
30139
- return ignoreDiagnostics(program.checker.isTypeAssignableTo(type.projectionBase ?? type, program.checker.getStdType(kind), type));
30594
+ return ignoreDiagnostics(program.checker.isTypeAssignableTo(
30595
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
30596
+ type.projectionBase ?? type, program.checker.getStdType(kind), type));
30140
30597
  }
30141
30598
 
30142
30599
  var yu=Object.create;var vt=Object.defineProperty;var Au=Object.getOwnPropertyDescriptor;var vu=Object.getOwnPropertyNames;var Bu=Object.getPrototypeOf,wu=Object.prototype.hasOwnProperty;var fr=e=>{throw TypeError(e)};var dr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Bt=(e,t)=>{for(var r in t)vt(e,r,{get:t[r],enumerable:true});},_u=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of vu(t))!wu.call(e,u)&&u!==r&&vt(e,u,{get:()=>t[u],enumerable:!(n=Au(t,u))||n.enumerable});return e};var Me=(e,t,r)=>(r=e!=null?yu(Bu(e)):{},_u(vt(r,"default",{value:e,enumerable:true}),e));var xu=(e,t,r)=>t.has(e)||fr("Cannot "+r);var pr=(e,t,r)=>t.has(e)?fr("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r);var pe=(e,t,r)=>(xu(e,t,"access private method"),r);var st=dr((na,Fn)=>{var pn=new Proxy(String,{get:()=>pn});Fn.exports=pn;});var Wn=dr(nr=>{Object.defineProperty(nr,"__esModule",{value:true});function Bi(){return new Proxy({},{get:()=>e=>e})}var Hn=/\r\n|[\n\r\u2028\u2029]/;function wi(e,t,r){let n=Object.assign({column:0,line:-1},e.start),u=Object.assign({},n,e.end),{linesAbove:i=2,linesBelow:o=3}=r||{},s=n.line,a=n.column,D=u.line,l=u.column,p=Math.max(s-(i+1),0),f=Math.min(t.length,D+o);s===-1&&(p=0),D===-1&&(f=t.length);let d=D-s,c={};if(d)for(let F=0;F<=d;F++){let m=F+s;if(!a)c[m]=true;else if(F===0){let h=t[m-1].length;c[m]=[a,h-a+1];}else if(F===d)c[m]=[0,l];else {let h=t[m-F].length;c[m]=[0,h];}}else a===l?a?c[s]=[a,0]:c[s]=true:c[s]=[a,l-a];return {start:p,end:f,markerLines:c}}function _i(e,t,r={}){let u=Bi(),i=e.split(Hn),{start:o,end:s,markerLines:a}=wi(t,i,r),D=t.start&&typeof t.start.column=="number",l=String(s).length,f=e.split(Hn,s).slice(o,s).map((d,c)=>{let F=o+1+c,h=` ${` ${F}`.slice(-l)} |`,C=a[F],v=!a[F+1];if(C){let E="";if(Array.isArray(C)){let g=d.slice(0,Math.max(C[0]-1,0)).replace(/[^\t]/g," "),j=C[1]||1;E=[`
@@ -31561,6 +32018,11 @@ class Realm {
31561
32018
  _a.realmForType.set(clone, this);
31562
32019
  return clone;
31563
32020
  }
32021
+ // TODO better way?
32022
+ /** @internal */
32023
+ get types() {
32024
+ return this.#types;
32025
+ }
31564
32026
  static #knownRealms = new Map();
31565
32027
  static realmForKey(key, parentRealm) {
31566
32028
  return this.#knownRealms.get(key);
@@ -31640,21 +32102,13 @@ defineKit({
31640
32102
  },
31641
32103
  });
31642
32104
 
31643
- /** @experimental */
31644
- function unsafe_useStateMap(key) {
32105
+ function useStateMap(key) {
31645
32106
  const getter = (program, target) => program.stateMap(key).get(target);
31646
32107
  const setter = (program, target, value) => program.stateMap(key).set(target, value);
31647
32108
  const mapGetter = (program) => program.stateMap(key);
31648
32109
  return [getter, setter, mapGetter];
31649
32110
  }
31650
32111
 
31651
- function createStateSymbol(name) {
31652
- return Symbol.for(`TypeSpec.${name}`);
31653
- }
31654
- function useStateMap(key) {
31655
- return unsafe_useStateMap(typeof key === "string" ? createStateSymbol(key) : key);
31656
- }
31657
-
31658
32112
  // Copyright (c) Microsoft Corporation
31659
32113
  // Licensed under the MIT license.
31660
32114
  // TypeSpec Visibility System
@@ -31678,11 +32132,11 @@ function useStateMap(key) {
31678
32132
  *
31679
32133
  * This store is used to track the visibility modifiers
31680
32134
  */
31681
- const [getVisibilityStore, setVisibilityStore] = useStateMap("visibilityStore");
32135
+ const [getVisibilityStore, setVisibilityStore] = useStateMap(createStateSymbol("visibilityStore"));
31682
32136
  /**
31683
32137
  * Stores the default modifier set for a given visibility class.
31684
32138
  */
31685
- const [getDefaultModifiers, setDefaultModifiers] = useStateMap("defaultVisibilityModifiers");
32139
+ const [getDefaultModifiers, setDefaultModifiers] = useStateMap(createStateSymbol("defaultVisibilityModifiers"));
31686
32140
  /**
31687
32141
  * Gets the default modifier set for a visibility class. If no default modifier set has been set, this function will
31688
32142
  * initialize the default modifier set to ALL the visibility class's members.
@@ -31755,8 +32209,8 @@ function getDoc(program, target) {
31755
32209
  return getDocDataInternal(program, target, "self")?.value;
31756
32210
  }
31757
32211
  // -- @format decorator ---------------------
31758
- const [getFormat, setFormat] = useStateMap("format");
31759
- const [getEncode, setEncodeData] = useStateMap("encode");
32212
+ const [getFormat, setFormat] = useStateMap(createStateSymbol("format"));
32213
+ const [getEncode, setEncodeData] = useStateMap(createStateSymbol("encode"));
31760
32214
 
31761
32215
  defineKit({
31762
32216
  modelProperty: {
@@ -31833,6 +32287,9 @@ defineKit({
31833
32287
  is(type) {
31834
32288
  return type.kind === "Model";
31835
32289
  },
32290
+ getEffectiveModel(model, filter) {
32291
+ return getEffectiveModelType(this.program, model, filter);
32292
+ },
31836
32293
  },
31837
32294
  });
31838
32295
 
@@ -31936,6 +32393,7 @@ defineKit({
31936
32393
  clone = this.program.checker.createType({
31937
32394
  ...type,
31938
32395
  decorators: [...type.decorators],
32396
+ derivedModels: [...type.derivedModels],
31939
32397
  properties: copyMap(type.properties),
31940
32398
  indexer: type.indexer ? { ...type.indexer } : undefined,
31941
32399
  });
@@ -31960,6 +32418,7 @@ defineKit({
31960
32418
  case "Enum":
31961
32419
  clone = this.program.checker.createType({
31962
32420
  ...type,
32421
+ decorators: [...type.decorators],
31963
32422
  members: copyMap(type.members),
31964
32423
  });
31965
32424
  break;
@@ -31970,35 +32429,25 @@ defineKit({
31970
32429
  instantiationParameters: type.instantiationParameters
31971
32430
  ? [...type.instantiationParameters]
31972
32431
  : undefined,
32432
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
31973
32433
  projections: [...type.projections],
32434
+ models: copyMap(type.models),
32435
+ decoratorDeclarations: copyMap(type.decoratorDeclarations),
32436
+ enums: copyMap(type.enums),
32437
+ unions: copyMap(type.unions),
32438
+ operations: copyMap(type.operations),
32439
+ interfaces: copyMap(type.interfaces),
32440
+ functionDeclarations: copyMap(type.functionDeclarations),
32441
+ namespaces: copyMap(type.namespaces),
32442
+ scalars: copyMap(type.scalars),
31974
32443
  });
31975
- const clonedNamespace = clone;
31976
- clonedNamespace.decoratorDeclarations = cloneTypeCollection(this, type.decoratorDeclarations, {
31977
- namespace: clonedNamespace,
31978
- });
31979
- clonedNamespace.models = cloneTypeCollection(this, type.models, {
31980
- namespace: clonedNamespace,
31981
- });
31982
- clonedNamespace.enums = cloneTypeCollection(this, type.enums, {
31983
- namespace: clonedNamespace,
31984
- });
31985
- clonedNamespace.functionDeclarations = cloneTypeCollection(this, type.functionDeclarations, {
31986
- namespace: clonedNamespace,
31987
- });
31988
- clonedNamespace.interfaces = cloneTypeCollection(this, type.interfaces, {
31989
- namespace: clonedNamespace,
31990
- });
31991
- clonedNamespace.namespaces = cloneTypeCollection(this, type.namespaces, {
31992
- namespace: clonedNamespace,
31993
- });
31994
- clonedNamespace.operations = cloneTypeCollection(this, type.operations, {
31995
- namespace: clonedNamespace,
31996
- });
31997
- clonedNamespace.scalars = cloneTypeCollection(this, type.scalars, {
31998
- namespace: clonedNamespace,
31999
- });
32000
- clonedNamespace.unions = cloneTypeCollection(this, type.unions, {
32001
- namespace: clonedNamespace,
32444
+ break;
32445
+ case "Scalar":
32446
+ clone = this.program.checker.createType({
32447
+ ...type,
32448
+ decorators: [...type.decorators],
32449
+ derivedScalars: [...type.derivedScalars],
32450
+ constructors: copyMap(type.constructors),
32002
32451
  });
32003
32452
  break;
32004
32453
  default:
@@ -32013,17 +32462,6 @@ defineKit({
32013
32462
  },
32014
32463
  },
32015
32464
  });
32016
- function cloneTypeCollection(kit, collection, options = {}) {
32017
- const cloneCollection = new Map();
32018
- for (const [key, type] of collection) {
32019
- const clone = kit.type.clone(type);
32020
- if ("namespace" in clone && options.namespace) {
32021
- clone.namespace = options.namespace;
32022
- }
32023
- cloneCollection.set(key, clone);
32024
- }
32025
- return cloneCollection;
32026
- }
32027
32465
 
32028
32466
  defineKit({
32029
32467
  unionVariant: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/html-program-viewer",
3
- "version": "0.65.0-dev.1",
3
+ "version": "0.65.0",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec library for emitting an html view of the program.",
6
6
  "homepage": "https://typespec.io",
@@ -36,7 +36,7 @@
36
36
  "!dist/test/**"
37
37
  ],
38
38
  "peerDependencies": {
39
- "@typespec/compiler": "~0.64.0 || >=0.65.0-dev <0.65.0"
39
+ "@typespec/compiler": "~0.65.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@fluentui/react-components": "~9.57.0",
@@ -51,12 +51,11 @@
51
51
  "@testing-library/dom": "^10.4.0",
52
52
  "@testing-library/jest-dom": "^6.6.3",
53
53
  "@testing-library/react": "^16.2.0",
54
- "@types/node": "~22.10.7",
54
+ "@types/node": "~22.10.10",
55
55
  "@types/react": "~18.3.11",
56
56
  "@types/react-dom": "~18.3.0",
57
- "@typespec/compiler": "~0.64.0 || >=0.65.0-dev <0.65.0",
58
57
  "@vitejs/plugin-react": "~4.3.4",
59
- "@vitest/coverage-v8": "^3.0.3",
58
+ "@vitest/coverage-v8": "^3.0.4",
60
59
  "@vitest/ui": "^3.0.3",
61
60
  "c8": "^10.1.3",
62
61
  "rimraf": "~6.0.1",
@@ -64,7 +63,8 @@
64
63
  "vite": "^6.0.11",
65
64
  "vite-plugin-checker": "^0.8.0",
66
65
  "vite-plugin-dts": "4.5.0",
67
- "vitest": "^3.0.3",
66
+ "vitest": "^3.0.5",
67
+ "@typespec/compiler": "~0.65.0",
68
68
  "@typespec/react-components": "~0.57.0"
69
69
  },
70
70
  "scripts": {
@@ -1,6 +0,0 @@
1
- const manifest = {
2
- "version": "0.64.0",
3
- "commit": "34e32f95aa2a3ccc26b2afad21db11a822a265d6"
4
- };
5
-
6
- export { manifest as default };