Preserve type of function with metadata

Description

Currently, IWithMeta is implemented for functions by wrapping the function in a MetaFn type.

However, this breaks certain expectations about the typeof of the meta-fied value:

The primary case when this is not ideal is when interoping with JS code that does checks using typeof, like React does:

Ideally, with-meta would preserve the typeof value when possible.

Environment

N/A

Activity

Show:
Will Acton
December 15, 2018, 10:10 PM

There's a separate issue about MetaFn's and varargs, https://dev.clojure.org/jira/browse/CLJS-2446, whose proposed implementation also solves this particular edge case.

Will Acton
December 16, 2018, 1:00 AM

Attached patch:

  • replaces `MetaFn` type with `meta-fn` helper that creates new fn
    with IMeta specify!'d on it.

  • Also fixes CLJS-2446: with-meta doesn't work for variable arguments functions

  • Adds tests for metadata and fns

Assignee

Unassigned

Reporter

Will Acton

Labels

Approval

None

Patch

None

Affects versions

Priority

Minor