Repository: penpot/penpot
File: frontend/src/app/main/data/style_dictionary.cljs (ClojureScript)

Code before:
  (let [missing-references (seq (some cto/find-token-value-references line-height-value))
        error
        (cond
          missing-references
          {:errors [(wte/error-with-value :error.style-dictionary/missing-reference missing-references)]
           :references missing-references}

          (or
           (not font-size-value)
           (seq font-size-errors))
          {:errors [(wte/error-with-value :error.style-dictionary/composite-line-height-needs-font-size font-size-value)]
           :font-size-value font-size-value})]
    (or error
        (try
          (when-let [{:keys [unit value]} (cft/parse-token-value line-height-value)]
            (case unit
              "%" (/ value 100)
              "px" (/ value font-size-value)
              nil value
              nil))
          (catch :default _ nil))
        {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value line-height-value)]})))

(defn- parse-sd-token-font-family-value
  [value]
  (let [missing-references (seq (some cto/find-token-value-references value))]
    (cond
      missing-references
      {:errors [(wte/error-with-value :error.style-dictionary/missing-reference missing-references)]
       :references missing-references}

      :else
      {:value (-> (js->clj value) (flatten))})))

(defn parse-atomic-typography-value [token-type token-value]
  (case token-type
    :font-size (parse-sd-token-general-value token-value)
    :font-family (parse-sd-token-font-family-value token-value)
    :font-weight (parse-sd-token-font-weight-value token-value)
    :letter-spacing (parse-sd-token-letter-spacing-value token-value)
    :text-case (parse-sd-token-text-case-value token-value)
    :text-decoration (parse-sd-token-text-decoration-value token-value)
    nil))

(defn- parse-composite-typography-value
  "Parses composite typography `value` map.
  Processes the `:line-height` based on the `:font-size` value in the map."
  [value]
  (let [missing-references
        (when (string? value)
          (seq (cto/find-token-value-references value)))]

Review comment (bug):
js->clj + flatten usually indicates bad pattern.
js->clj as general rule should be used for debug/develop purpose

I merge it in any way as style-dictionary code is going to be replaced

Code after:
  (let [missing-references (seq (some cto/find-token-value-references line-height-value))
        error
        (cond
          missing-references
          {:errors [(wte/error-with-value :error.style-dictionary/missing-reference missing-references)]
           :references missing-references}

          (or
           (not font-size-value)
           (seq font-size-errors))
          {:errors [(wte/error-with-value :error.style-dictionary/composite-line-height-needs-font-size font-size-value)]
           :font-size-value font-size-value})]
    (or error
        (try
          (when-let [{:keys [unit value]} (cft/parse-token-value line-height-value)]
            (case unit
              "%" (/ value 100)
              "px" (/ value font-size-value)
              nil value
              nil))
          (catch :default _ nil))
        {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value line-height-value)]})))

(defn- parse-sd-token-font-family-value
  [value]
  (let [value (-> (js->clj value) (flatten))
        valid-font-family (or (string? value) (every? string? value))
        missing-references (seq (some cto/find-token-value-references value))]
    (cond
      (not valid-font-family)
      {:errors [(wte/error-with-value :error.style-dictionary/invalid-token-value-font-family value)]}

      missing-references
      {:errors [(wte/error-with-value :error.style-dictionary/missing-reference missing-references)]
       :references missing-references}

      :else
      {:value value})))

(defn parse-atomic-typography-value [token-type token-value]
  (case token-type
    :font-size (parse-sd-token-general-value token-value)
    :font-family (parse-sd-token-font-family-value token-value)
    :font-weight (parse-sd-token-font-weight-value token-value)
    :letter-spacing (parse-sd-token-letter-spacing-value token-value)
    :text-case (parse-sd-token-text-case-value token-value)
    :text-decoration (parse-sd-token-text-decoration-value token-value)
    nil))

(defn- parse-composite-typography-value
  "Parses composite typography `value` map.