@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/cli.js CHANGED
@@ -2487,6 +2487,8 @@ import {
2487
2487
  getBuildLogger,
2488
2488
  getBroadeningLogger,
2489
2489
  getSyntheticLogger as getSyntheticLogger2,
2490
+ getTypedParserLogger,
2491
+ parseTagArgument,
2490
2492
  describeTypeKind,
2491
2493
  elapsedMicros,
2492
2494
  nowMicros,
@@ -2642,6 +2644,7 @@ function processConstraintTag(tagName, text, parsedTag, provenance, node, source
2642
2644
  sourceFile,
2643
2645
  tagName,
2644
2646
  parsedTag,
2647
+ text,
2645
2648
  provenance,
2646
2649
  supportingDeclarations,
2647
2650
  options
@@ -2669,6 +2672,9 @@ function renderSyntheticArgumentExpression(valueKind, argumentText) {
2669
2672
  case "number":
2670
2673
  case "integer":
2671
2674
  case "signedInteger":
2675
+ if (trimmed === "Infinity" || trimmed === "-Infinity" || trimmed === "NaN") {
2676
+ return trimmed;
2677
+ }
2672
2678
  return Number.isFinite(Number(trimmed)) ? trimmed : JSON.stringify(trimmed);
2673
2679
  case "string":
2674
2680
  return JSON.stringify(argumentText);
@@ -2878,7 +2884,7 @@ function hasBuiltinConstraintBroadening(tagName, options) {
2878
2884
  const broadenedTypeId = getBroadenedCustomTypeId(options?.fieldType);
2879
2885
  return broadenedTypeId !== void 0 && options?.extensionRegistry?.findBuiltinConstraintBroadening(broadenedTypeId, tagName) !== void 0;
2880
2886
  }
2881
- function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, provenance, supportingDeclarations, options) {
2887
+ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, parsedTag, rawText, provenance, supportingDeclarations, options) {
2882
2888
  if (!isBuiltinConstraintName(tagName)) {
2883
2889
  return [];
2884
2890
  }
@@ -2899,8 +2905,10 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
2899
2905
  const log2 = getBuildLogger();
2900
2906
  const broadeningLog = getBroadeningLogger();
2901
2907
  const syntheticLog = getSyntheticLogger2();
2908
+ const typedParserLog = getTypedParserLogger();
2902
2909
  const logsEnabled = log2 !== noopLogger4 || broadeningLog !== noopLogger4;
2903
2910
  const syntheticTraceEnabled = syntheticLog !== noopLogger4;
2911
+ const typedParserTraceEnabled = typedParserLog !== noopLogger4;
2904
2912
  const logStart = logsEnabled ? nowMicros() : 0;
2905
2913
  const subjectTypeKind = logsEnabled ? describeTypeKind(subjectType, checker) : "";
2906
2914
  function emit(outcome, result2) {
@@ -3008,16 +3016,57 @@ function buildCompilerBackedConstraintDiagnostics(node, sourceFile, tagName, par
3008
3016
  ]);
3009
3017
  }
3010
3018
  }
3011
- const argumentExpression = renderSyntheticArgumentExpression(
3012
- definition.valueKind,
3013
- parsedTag?.argumentText ?? ""
3014
- );
3015
- if (definition.requiresArgument && argumentExpression === null) {
3016
- return emit("A-pass", []);
3017
- }
3019
+ const effectiveArgumentText = parsedTag !== null ? parseTagSyntax(tagName, rawText).argumentText : rawText;
3018
3020
  if (hasBroadening) {
3019
3021
  return emit("bypass", []);
3020
3022
  }
3023
+ const typedParseResult = parseTagArgument(tagName, effectiveArgumentText, "build");
3024
+ if (!typedParseResult.ok) {
3025
+ if (typedParserTraceEnabled) {
3026
+ typedParserLog.trace("typed-parser C-reject", {
3027
+ consumer: "build",
3028
+ tag: tagName,
3029
+ placement: nonNullPlacement,
3030
+ subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
3031
+ roleOutcome: "C-reject",
3032
+ diagnosticCode: typedParseResult.diagnostic.code
3033
+ });
3034
+ }
3035
+ let mappedCode;
3036
+ switch (typedParseResult.diagnostic.code) {
3037
+ case "MISSING_TAG_ARGUMENT":
3038
+ mappedCode = "MISSING_TAG_ARGUMENT";
3039
+ break;
3040
+ case "INVALID_TAG_ARGUMENT":
3041
+ mappedCode = "INVALID_TAG_ARGUMENT";
3042
+ break;
3043
+ case "UNKNOWN_TAG":
3044
+ throw new Error(
3045
+ `Unexpected UNKNOWN_TAG from parseTagArgument("${tagName}") \u2014 tag was resolved via getTagDefinition.`
3046
+ );
3047
+ default: {
3048
+ const _exhaustive = typedParseResult.diagnostic.code;
3049
+ throw new Error(`Unknown diagnostic code: ${String(_exhaustive)}`);
3050
+ }
3051
+ }
3052
+ return emit("C-reject", [
3053
+ makeDiagnostic(mappedCode, typedParseResult.diagnostic.message, provenance)
3054
+ ]);
3055
+ }
3056
+ if (typedParserTraceEnabled) {
3057
+ typedParserLog.trace("typed-parser C-pass", {
3058
+ consumer: "build",
3059
+ tag: tagName,
3060
+ placement: nonNullPlacement,
3061
+ subjectTypeKind: subjectTypeKind !== "" ? subjectTypeKind : "-",
3062
+ roleOutcome: "C-pass",
3063
+ valueKind: typedParseResult.value.kind
3064
+ });
3065
+ }
3066
+ const argumentExpression = renderSyntheticArgumentExpression(
3067
+ definition.valueKind,
3068
+ effectiveArgumentText
3069
+ );
3021
3070
  const subjectTypeText = checker.typeToString(subjectType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);
3022
3071
  const hostType = options?.hostType ?? subjectType;
3023
3072
  const hostTypeText = checker.typeToString(hostType, node, SYNTHETIC_TYPE_FORMAT_FLAGS);