Skip to content

Enable DCE by avoiding ^:export for cljs use. #191

@rauhs

Description

@rauhs

The ^:export declaration are only necessary for the javascript build of datascript. But this eliminates any dead code elimination by the Google Closure compiler which would be nice for people not using certain features. For instance, I don't use FilteredDB.

By making the javascript build a little more involved, we could remove those export declaration for cljs use. cljsee can be used to process the datascript files:

(cljsee.parse/process-source-code
  ;; The first tag will be output if it's in the features list:
 "#?(
  :js   (def ^:export datom? db/datom?)
  :cljs (def datom? db/datom?)
 )"
 #{:cljs :js})

This could allow even more fine grained code generation. Not sure if the trouble is worth it though.

A good enough solution would be to just change the code in datascript.core to:

(goog-define datascript-export-js-api true)

(def datom db/datom)
(when ^boolean datascript-export-js-api
  (goog/exportSymbol "datom" datom))

And allow cljs-only folks to define datascript-export-js-api to false.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions