Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects versions: 1.7.145
    • Fix versions: 1.9.671
    • Labels:

      Description

      Currently, defrecord instances print similar to how they do in clojure

      > (pr-str (garden.units/px 5))
      #garden.types.CSSUnit{:unit :px, :magnitude 5}
      

      This representation cannot be read by the compiler, nor at runtime by cljs.reader/read-string

      > #garden.types.CSSUnit{:unit :px, :magnitude 5}
      clojure.lang.ExceptionInfo: garden.types.CSSUnit {:type :reader-exception, :line 1, :column 22, :file "NO_SOURCE_FILE"}
      ...
      > (cljs.reader/read-string "#garden.types.CSSUnit{:unit :px, :magnitude 5}")
      #<Error: Could not find tag parser for garden.types.CSSUnit in ("inst" "uuid" "queue" "js")>
      ...
      

      Analysis

      The two requirements - using record literals in cljs source code and supporting runtime reading - can be addressed by using the analyzer to find defrecords and registering them with the two respective reader libraries.

      Record literals

      Since clojurescript reads and compiles a file at a time, clojure's behavior for literals is hard to exactly mimic. That is, to be able to use the literal in the same file where the record is defined.
      A reasonable compromise might be to update the record tag table after each file has been analyzed. Thus the literal form of a record could be used only in requiring files.

      EDIT: Record literals can also go into the constant pool

      cljs.reader

      To play well with minification, the ^:export annotation could be reused on defrecords, to publish the corresponding reader tag to cljs.reader.

      Related Tickets

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bendlas Herwig Hochleitner
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: