@formspec/build 0.1.0-alpha.57 → 0.1.0-alpha.58

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
@@ -2388,6 +2388,8 @@ import {
2388
2388
  getBuildLogger,
2389
2389
  getBroadeningLogger,
2390
2390
  getSyntheticLogger as getSyntheticLogger2,
2391
+ getTypedParserLogger,
2392
+ parseTagArgument,
2391
2393
  describeTypeKind,
2392
2394
  elapsedMicros,
2393
2395
  nowMicros,
@@ -2544,6 +2546,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
2544
2546
  sourceFile,
2545
2547
  tagName,
2546
2548
  parsedTag,
2549
+ text,
2547
2550
  provenance,
2548
2551
  supportingDeclarations,
2549
2552
  options
@@ -2571,6 +2574,9 @@ function renderSyntheticArgumentExpression(valueKind, argumentText) {
2571
2574
  case "number":
2572
2575
  case "integer":
2573
2576
  case "signedInteger":
2577
+ if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
2578
+ return trimmed;
2579
+ }
2574
2580
  return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
2575
2581
  case "string":
2576
2582
  return JSON.stringify(argumentText);
@@ -2782,7 +2788,7 @@ function hasBuiltinConstraintBroadening(tagName, options) {
2782
2788
  const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
2783
2789
  return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
2784
2790
  }
2785
- function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, provenance, supportingDeclarations, options) {
2791
+ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, supportingDeclarations, options) {
2786
2792
  if (!isBuiltinConstraintName(tagName)) {
2787
2793
  return [];
2788
2794
  }
@@ -2803,8 +2809,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
2803
2809
  const log = getBuildLogger();
2804
2810
  const broadeningLog = getBroadeningLogger();
2805
2811
  const syntheticLog = getSyntheticLogger2();
2812
+ const typedParserLog = getTypedParserLogger();
2806
2813
  const logsEnabled = log !== noopLogger3 || broadeningLog !== noopLogger3;
2807
2814
  const syntheticTraceEnabled = syntheticLog !== noopLogger3;
2815
+ const typedParserTraceEnabled = typedParserLog !== noopLogger3;
2808
2816
  const logStart = logsEnabled ? nowMicros() : 0;
2809
2817
  const subjectTypeKind = logsEnabled ? describeTypeKind(subjectType, checker) : "";
2810
2818
  function emit(outcome, result2) {
@@ -2912,16 +2920,57 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
2912
2920
  ]);
2913
2921
  }
2914
2922
  }
2915
- const argumentExpression = renderSyntheticArgumentExpression(
2916
- definition.valueKind,
2917
- parsedTag?.argumentText ?? ""
2918
- );
2919
- if (definition.requiresArgument && argumentExpression === null) {
2920
- return emit("A-pass", []);
2921
- }
2923
+ const effectiveArgumentText = parsedTag !== null ? parseTagSyntax(tagName, rawText).argumentText : rawText;
2922
2924
  if (hasBroadening) {
2923
2925
  return emit("bypass", []);
2924
2926
  }
2927
+ const typedParseResult = parseTagArgument(tagName, effectiveArgumentText, "build");
2928
+ if (!typedParseResult.ok) {
2929
+ if (typedParserTraceEnabled) {
2930
+ typedParserLog.trace("typed-parser C-reject", {
2931
+ consumer: "build",
2932
+ tag: tagName,
2933
+ placement: nonNullPlacement,
2934
+ subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
2935
+ roleOutcome: "C-reject",
2936
+ diagnosticCode: typedParseResult.diagnostic.code
2937
+ });
2938
+ }
2939
+ let mappedCode;
2940
+ switch (typedParseResult.diagnostic.code) {
2941
+ case "MISSING_TAG_ARGUMENT":
2942
+ mappedCode = "MISSING_TAG_ARGUMENT";
2943
+ break;
2944
+ case "INVALID_TAG_ARGUMENT":
2945
+ mappedCode = "INVALID_TAG_ARGUMENT";
2946
+ break;
2947
+ case "UNKNOWN_TAG":
2948
+ throw new Error(
2949
+ `Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
2950
+ );
2951
+ default: {
2952
+ const _exhaustive = typedParseResult.diagnostic.code;
2953
+ throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
2954
+ }
2955
+ }
2956
+ return emit("C-reject", [
2957
+ makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
2958
+ ]);
2959
+ }
2960
+ if (typedParserTraceEnabled) {
2961
+ typedParserLog.trace("typed-parser C-pass", {
2962
+ consumer: "build",
2963
+ tag: tagName,
2964
+ placement: nonNullPlacement,
2965
+ subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
2966
+ roleOutcome: "C-pass",
2967
+ valueKind: typedParseResult.value.kind
2968
+ });
2969
+ }
2970
+ const argumentExpression = renderSyntheticArgumentExpression(
2971
+ definition.valueKind,
2972
+ effectiveArgumentText
2973
+ );
2925
2974
  const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
2926
2975
  const hostType = options?.hostType ?? subjectType;
2927
2976
  const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);