{
  "version": 3,
  "sources": ["../../../../../src/functions/text/len/len.ts"],
  "sourcesContent": [
    "import {\n  FormulaError,\n  type CellAddress,\n  type FunctionDefinition,\n  type FunctionEvaluationResult\n} from \"../../../core/types.cjs\";\nimport type { EvaluationContext } from \"../../../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../../../evaluator/formula-evaluator.cjs\";\n\n/**\n * LEN function - Returns the length of a text string\n *\n * Usage: LEN(text)\n *\n * text: The text string whose length you want to find.\n *\n * Example: LEN(\"Hello World\") returns 11\n *\n * Note:\n * - Supports dynamic arrays (spilled values) for the text argument\n * - Strict type checking: text must be string\n * - Returns the number of characters in the text string\n */\nexport const LEN: FunctionDefinition = {\n  name: \"LEN\",\n  evaluate: function (node, context): FunctionEvaluationResult {\n    if (node.args.length !== 1) {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"LEN function takes exactly 1 argument\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    // Evaluate the text argument\n    const textResult = this.evaluateNode(node.args[0]!, context);\n    if (\n      textResult.type === \"error\" ||\n      textResult.type === \"awaiting-evaluation\"\n    ) {\n      return textResult;\n    }\n\n    // Handle spilled-values input\n    if (textResult.type === \"spilled-values\") {\n      return createLenSpilledResult.call(this, {\n        textResult,\n        context,\n      });\n    }\n\n    // Strict type checking - no coercion\n    if (textResult.result.type !== \"string\") {\n      return {\n        type: \"error\",\n        err: FormulaError.VALUE,\n        message: \"Text argument must be a string\",\n        errAddress: context.dependencyNode,\n      };\n    }\n\n    if (textResult.result.type === \"string\") {\n      return {\n        type: \"value\",\n        result: { type: \"number\", value: textResult.result.value.length },\n      };\n    }\n\n    return {\n      type: \"error\",\n      err: FormulaError.VALUE,\n      message: \"LEN operation failed\",\n      errAddress: context.dependencyNode,\n    };\n  },\n};\n\n/**\n * Helper for creating spilled-values result for LEN function\n */\nfunction createLenSpilledResult(\n  this: FormulaEvaluator,\n  {\n    textResult,\n    context,\n  }: {\n    textResult: FunctionEvaluationResult;\n    context: EvaluationContext;\n  }\n): FunctionEvaluationResult {\n  if (textResult.type !== \"spilled-values\") {\n    return {\n      type: \"error\",\n      err: FormulaError.VALUE,\n      message: \"createLenSpilledResult called without spilled values\",\n      errAddress: context.dependencyNode,\n    };\n  }\n\n  return {\n    type: \"spilled-values\",\n    spillArea: (origin: CellAddress) => textResult.spillArea(origin),\n    source: \"LEN with spilled text values\",\n    evaluate: (spillOffset, evalContext) => {\n      const spillTextResult = textResult.evaluate(spillOffset, evalContext);\n      if (\n        !spillTextResult ||\n        spillTextResult.type === \"error\" ||\n        spillTextResult.type === \"awaiting-evaluation\"\n      ) {\n        return spillTextResult;\n      }\n\n      if (\n        spillTextResult.type !== \"value\" ||\n        spillTextResult.result.type !== \"string\"\n      ) {\n        return {\n          type: \"error\",\n          err: FormulaError.VALUE,\n          message: \"LEN operation failed\",\n          errAddress: context.dependencyNode,\n        };\n      }\n\n      return {\n        type: \"value\",\n        result: { type: \"number\", value: spillTextResult.result.value.length },\n      };\n    },\n    evaluateAllCells: (intersectingRange) => {\n      throw new Error(\"WIP: evaluateAllCells for LEN is not implemented\");\n    },\n  };\n}\n"
  ],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IALP;AAuBO,IAAM,MAA0B;AAAA,EACrC,MAAM;AAAA,EACN,UAAU,QAAS,CAAC,MAAM,SAAmC;AAAA,IAC3D,IAAI,KAAK,KAAK,WAAW,GAAG;AAAA,MAC1B,OAAO;AAAA,QACL,MAAM;AAAA,QACN,KAAK,0BAAa;AAAA,QAClB,SAAS;AAAA,QACT,YAAY,QAAQ;AAAA,MACtB;AAAA,IACF;AAAA,IAGA,MAAM,aAAa,KAAK,aAAa,KAAK,KAAK,IAAK,OAAO;AAAA,IAC3D,IACE,WAAW,SAAS,WACpB,WAAW,SAAS,uBACpB;AAAA,MACA,OAAO;AAAA,IACT;AAAA,IAGA,IAAI,WAAW,SAAS,kBAAkB;AAAA,M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