Liking cljdoc? Tell your friends :D
Mostly cljs.
Exceptions indicated.

devtools.munging

cljs

This namespace implements various heuristics to map Javascript names back to corresponding ClojureScript names. The functionality here heavily depends on observed ClojureScript compiler and runtime behaviour (fragile!). Answers given by functions in this namespace cannot be perfect because generated Javascript naming schemes produced by ClojureScript compiler were not designed with easy reversibility in mind. We recommend this functionality to be used for presentation in the UI only. The goal here is to provide user with more familiar view of runtime state of her app in most common cases (on best effort basis).

Our main weapons in this uneven fight are:

  1. munged function names as they appear in Javascript (generated by ClojureScript)
  2. we can also analyze function sources accessible via .toString
  3. special cljs$core$IFn$_invoke protocol props generated for multi-arity functions

We can also cheat and look at runtime state of browser environment to determine some answers about namespaces.

This code can be used only in non-advanced builds!

If you discovered breakage or a new case which should be covered by this code, please open an issue: https://github.com/binaryage/cljs-devtools/issues

This namespace implements various heuristics to map Javascript names back to corresponding ClojureScript names.
The functionality here heavily depends on observed ClojureScript compiler and runtime behaviour (fragile!).
Answers given by functions in this namespace cannot be perfect because generated Javascript naming schemes produced by
ClojureScript compiler were not designed with easy reversibility in mind. We recommend this functionality to be used for
presentation in the UI only. The goal here is to provide user with more familiar view of runtime state of her app
in most common cases (on best effort basis).

Our main weapons in this uneven fight are:
  1. munged function names as they appear in Javascript (generated by ClojureScript)
  2. we can also analyze function sources accessible via .toString
  3. special cljs$core$IFn$_invoke protocol props generated for multi-arity functions

We can also cheat and look at runtime state of browser environment to determine some answers about namespaces.

This code can be used only in non-advanced builds!

If you discovered breakage or a new case which should be covered by this code, please open an issue:
  https://github.com/binaryage/cljs-devtools/issues
raw docstring

args-lists-to-stringscljs

(args-lists-to-strings args-lists spacer-symbol multi-arity-symbol rest-symbol)

Converts a list of arguments lists into a list of strings suitable for UI presentation.

Converts a list of arguments lists into a list of strings suitable for UI presentation.
sourceraw docstring

arities-key-comparatorcljs

(arities-key-comparator x y)

numbers go first (ordered), then keywords (ordered by name), and then ::variadic sticks last

numbers go first (ordered), then keywords (ordered by name), and then ::variadic sticks last
sourceraw docstring

arities-to-args-listscljs

(arities-to-args-lists arities & [humanize?])

Given a map of arity functions. Tries to parse individual functions and prepare an arguments list for each arity. Returned list of arguments list is sorted by arity count, variadic arity goes last if available.

The function also optionally humanizes argument names in each arguments list if requested.

Given a map of arity functions. Tries to parse individual functions and prepare an arguments list for each arity.
Returned list of arguments list is sorted by arity count, variadic arity goes last if available.

The function also optionally humanizes argument names in each arguments list if requested.
sourceraw docstring

arities-to-args-lists*cljs

(arities-to-args-lists* arities)
source

arity-keywords-comparatorcljs

(arity-keywords-comparator x y)

::variadic goes last, other keywords compare by name.

::variadic goes last, other keywords compare by name.
sourceraw docstring

break-and-demunge-namecljs

(break-and-demunge-name munged-name)
(break-and-demunge-name munged-name ns-detector)

Given a munged-name from Javascript lands attempts to break it into a namespace part and remaining short name. Then applies appropriate demunging on them and returns ClojureScript versions of the names.

Given a munged-name from Javascript lands attempts to break it into a namespace part and remaining short name.
Then applies appropriate demunging on them and returns ClojureScript versions of the names.
sourceraw docstring

break-munged-namecljs

(break-munged-name munged-name)
(break-munged-name munged-name ns-detector)

Given a munged-name from Javascript lands attempts to break it into: [fn-ns fn-name protocol-ns protocol-name protocol-method arity].

Protocol and arity elements are optional. Function elements are always present or "".

examples for input: cljs$core$rest => ['cljs.core', 'rest'] cljs.core.reduce$cljs$core$IFn$_invoke$arity$3 => ['cljs.core' 'reduce' 'cljs.core' 'IFn' '_invoke' 3]

Given a munged-name from Javascript lands attempts to break it into:
[fn-ns fn-name protocol-ns protocol-name protocol-method arity].

Protocol and arity elements are optional. Function elements are always present or "".

examples for input:
  cljs$core$rest => ['cljs.core', 'rest']
  cljs.core.reduce$cljs$core$IFn$_invoke$arity$3 => ['cljs.core' 'reduce' 'cljs.core' 'IFn' '_invoke' 3]
sourceraw docstring

char-to-subscriptcljs

(char-to-subscript char)

Given a character with a single digit converts it into a subscript character. Zero character maps to unicode 'SUBSCRIPT ZERO' (U+2080).

Given a character with a single digit converts it into a subscript character.
Zero character maps to unicode 'SUBSCRIPT ZERO' (U+2080).
sourceraw docstring

char-to-superscriptcljs

(char-to-superscript char)

Given a character with a single digit converts it into a superscript character. Zero character maps to unicode 'SUPERSCRIPT ZERO' (U+2070).

Given a character with a single digit converts it into a superscript character.
Zero character maps to unicode 'SUPERSCRIPT ZERO' (U+2070).
sourceraw docstring

cljs-fn-name?cljs

(cljs-fn-name? munged-name)

Given a Javascript name answers if the name was likely generated by ClojureScript. We use a simple heuristic here: The name must contain at least two separate dollars because we assume two-segment namespaces.

Given a Javascript name answers if the name was likely generated by ClojureScript.
We use a simple heuristic here:
  The name must contain at least two separate dollars because we assume two-segment namespaces.
sourceraw docstring

cljs-fn?cljs

(cljs-fn? f)

Given a Javascript function object returns true if the function looks like a ClojureScript function.

Uses various heuristics:

  1. must be fn? (is javascript function or satisfies Fn and IFn protocols)
  2. and name must be cljs-fn-name? (name can come from f.name or parsed out of function source)
  3. or if anonymous function, must be non-trivial
Given a Javascript function object returns true if the function looks like a ClojureScript function.

Uses various heuristics:
  1. must be fn? (is javascript function or satisfies Fn and IFn protocols)
  2. and name must be cljs-fn-name? (name can come from f.name or parsed out of function source)
  3. or if anonymous function, must be non-trivial
sourceraw docstring

collect-fn-aritiescljs

(collect-fn-arities f)

Given a Javascript function object, tries to inspect known arity properties generated by ClojureScript compiler and collects all available arity functions into a map. Arities are keyed by arity count and variadic arity gets ::variadic key.

Given a Javascript function object, tries to inspect known arity properties generated by ClojureScript compiler and
collects all available arity functions into a map. Arities are keyed by arity count and variadic arity gets ::variadic key.
sourceraw docstring

collect-fn-fixed-aritiescljs

(collect-fn-fixed-arities f max-arity)
source

collect-fn-variadic-aritiescljs

(collect-fn-variadic-arities f)
source

collect-protocol-methodscljs

(collect-protocol-methods obj protocol-selector)
source

common-protocol?cljs

(common-protocol? protocol-ns protocol-name)
source

convert-to-protocol-descriptorcljs

(convert-to-protocol-descriptor fast? [ns name selector])
source

demunge-protocol-selectorcljs

(demunge-protocol-selector protocol-selector)
source

detect-namespace-prefixcljs

(detect-namespace-prefix tokens & [ns-detector])

Given a name broken into namespace parts returns [detected-ns remaining-parts], where detected-ns is a string representing longest detected existing namespace and remaining-parts is a vector of remaining input parts not included in the detected-ns concatenation.

For given input ["cljs" "core" "first"] returns ["cljs.core" ["first"]] (assuming cljs.core exists)

Given a name broken into namespace parts returns [detected-ns remaining-parts],
where detected-ns is a string representing longest detected existing namespace and
remaining-parts is a vector of remaining input parts not included in the detected-ns concatenation.

For given input ["cljs" "core" "first"] returns ["cljs.core" ["first"]] (assuming cljs.core exists)
sourceraw docstring

dollar-preserving-demungecljs

(dollar-preserving-demunge munged-name)

Standard cljs.core/demunge is too aggressive in replacing dollars. This wrapper function works around it by leaving dollars intact.

Standard cljs.core/demunge is too aggressive in replacing dollars.
This wrapper function works around it by leaving dollars intact.
sourceraw docstring

dollar-replacementcljs

source

extract-aritiescljs

(extract-arities f humanize? spacer-symbol multi-arity-symbol rest-symbol)
source

fast-path-protocols-lookup-tablecljs

source

find-index-of-human-prefixcljs

(find-index-of-human-prefix name)

Given a demunged ClojureScript parameter name. Tries to detect human readable part and returns the index where it ends. Returns nil if no prefix can be detected.

The idea is to convert macro-generated parameters and other generated names to more friendly names. We observed that param names generated by gensym have prefix followed by big numbers. Other generated names contain two dashes after prefix (originally probably using underscores).

Given a demunged ClojureScript parameter name. Tries to detect human readable part and returns the index where it ends.
Returns nil if no prefix can be detected.

The idea is to convert macro-generated parameters and other generated names to more friendly names.
We observed that param names generated by gensym have prefix followed by big numbers.
Other generated names contain two dashes after prefix (originally probably using underscores).
sourceraw docstring

get-basiscljs

(get-basis f)
source

get-fast-path-protocol-partitions-countclj/smacro

(get-fast-path-protocol-partitions-count)
source

get-fast-path-protocolsclj/smacro

(get-fast-path-protocols)
source

get-fast-path-protocols-lookup-tableclj/smacro

(get-fast-path-protocols-lookup-table)
source

get-fn-fixed-aritycljs

(get-fn-fixed-arity f n)
source

get-fn-max-fixed-aritycljs

(get-fn-max-fixed-arity f)
source

get-fn-source-safelycljs

(get-fn-source-safely f)
source

get-fn-variadic-aritycljs

(get-fn-variadic-arity f)
source

get-global-scopecljs

(get-global-scope)
source

get-protocol-infoclj

(get-protocol-info protocol)
source

get-protocol-objectcljs

(get-protocol-object protocol-selector)
source

get-protocol-selectorcljs

(get-protocol-selector key)
source

get-type-namecljs

(get-type-name t)
source

humanize-namecljs

(humanize-name state name)

Given a name and intermediate state. Convert name to a human readable version by keeping human readable prefix with optional subscript postfix and store it in ::result. Subscript number is picked based on state. State keeps track of previously assigned subscripts. Returns a new state.

Given a name and intermediate state. Convert name to a human readable version by keeping human readable prefix with
optional subscript postfix and store it in ::result. Subscript number is picked based on state. State keeps track of
previously assigned subscripts. Returns a new state.
sourceraw docstring

humanize-namescljs

(humanize-names names)

Given a list of names, returns a list of human-readable versions of those names. It detects human-readable prefix using a simple heuristics. When names repeat it assigns simple subscripts starting with 2. Subscripts are assigned left-to-right.

Given ["p--a" "p--b" "x" "p--c"] returns ["p" "p₂" "x" "p₃"]

Given a list of names, returns a list of human-readable versions of those names.
It detects human-readable prefix using a simple heuristics. When names repeat it assigns simple subscripts starting with 2.
Subscripts are assigned left-to-right.

Given ["p--a" "p--b" "x" "p--c"] returns ["p" "p₂" "x" "p₃"]
sourceraw docstring

js-reserved?cljs

(js-reserved? x)
source

key-for-protocol-partitioncljs

(key-for-protocol-partition partition)
source

make-protocol-descriptorcljs

(make-protocol-descriptor ns name selector fast?)
source

make-subscriptcljs

(make-subscript subscript)

Given a subscript number converts it into a string representation consisting of unicode subscript characters (digits).

Given a subscript number converts it into a string representation consisting of unicode subscript characters (digits).
sourceraw docstring

make-superscriptcljs

(make-superscript superscript)

Given a superscript number converts it into a string representation consisting of unicode superscript characters (digits).

Given a superscript number converts it into a string representation consisting of unicode superscript characters (digits).
sourceraw docstring

max-fixed-arity-to-scancljs

source

normalize-aritycljs

(normalize-arity arity-tokens)
source

ns-exists?cljs

(ns-exists? ns-module-name)
source

parse-constructor-infocljs

(parse-constructor-info f)

Given a Javascript constructor function tries to retrieve [ns name basis]. Returns nil if not a cljs type.

Given a Javascript constructor function tries to retrieve [ns name basis]. Returns nil if not a cljs type.
sourceraw docstring

parse-fn-infocljs

(parse-fn-info f)

Given Javascript function object tries to retrieve [ns name & args] as in parse-fn-source-info (on best effort basis).

Given Javascript function object tries to retrieve [ns name & args] as in parse-fn-source-info (on best effort basis).
sourceraw docstring

parse-fn-info-deepcljs

(parse-fn-info-deep f)

Given a Javascript function object tries to retrieve [ns name & args] as in parse-fn-info (on best effort basis).

The difference from parse-fn-info is that this function prefers to read args from arities if available. It recurse arbitrary deep following IFn protocol leads.

If we hit multi-arity situation in leaf, we don't attempt to list arguments and return ::multi-arity placeholder instead.

The reason for reading arities is that it gives more accurate parameter names in some cases. We observed that variadic functions don't always contain original parameter names, but individual IFn arity functions do.

Given a Javascript function object tries to retrieve [ns name & args] as in parse-fn-info (on best effort basis).

The difference from parse-fn-info is that this function prefers to read args from arities if available.
It recurse arbitrary deep following IFn protocol leads.

If we hit multi-arity situation in leaf, we don't attempt to list arguments and return ::multi-arity placeholder instead.

The reason for reading arities is that it gives more accurate parameter names in some cases.
We observed that variadic functions don't always contain original parameter names, but individual IFn arity functions do.
sourceraw docstring

parse-fn-sourcecljs

(parse-fn-source fn-source)

Given a function source code parses out [name args]. Note that both strings are still munged. Suitable for further processing.

For example for input below the function will return ["devtools_sample$core$hello" "name, unused_param"]:

function devtools_sample$core$hello(name, unused_param){ return [cljs.core.str("hello, "),cljs.core.str(name),cljs.core.str("!")].join(''); }

Given a function source code parses out [name args]. Note that both strings are still munged.
Suitable for further processing.

For example for input below the function will return ["devtools_sample$core$hello" "name, unused_param"]:

function devtools_sample$core$hello(name, unused_param){
  return [cljs.core.str("hello, "),cljs.core.str(name),cljs.core.str("!")].join('');
}
sourceraw docstring

parse-fn-source-infocljs

(parse-fn-source-info fn-source)

Given function source code tries to retrieve [ns name & args] on best effort basis, where ns is demunged namespace part of the function name (or "" if namespace cannot be detected) name is demunged short name (or "" if function is anonymous or name cannot be retrieved) args is optional number of demunged argument names.

Please note that this function always returns a vector with something. In worst cases ["" ""].

Given function source code tries to retrieve [ns name & args] on best effort basis, where
ns is demunged namespace part of the function name (or "" if namespace cannot be detected)
name is demunged short name (or "" if function is anonymous or name cannot be retrieved)
args is optional number of demunged argument names.

Please note that this function always returns a vector with something. In worst cases ["" ""].
sourceraw docstring

parse-protocolcljs

(parse-protocol tokens detector)
source

present-fn-partcljs

(present-fn-part fn-ns fn-name include-ns?)
source

present-function-namecljs

(present-function-name munged-name options)

Given javascript function name tries to present it as plain string for display in UI on best effort basis.

Given javascript function name tries to present it as plain string for display in UI on best effort basis.
sourceraw docstring

present-protocol-partcljs

(present-protocol-part protocol-ns
                       protocol-name
                       protocol-method
                       include-protocol-ns?)
source

proper-arg-demungecljs

(proper-arg-demunge munged-arg-name)
source

proper-demungecljs

(proper-demunge munged-name)
source

proper-ns-demungecljs

(proper-ns-demunge munged-ns-name)
source

protocol-descriptors-comparatorcljs

(protocol-descriptors-comparator a b)
source

protocol-exists?cljs

(protocol-exists? protocol-selector)
source

protocol-pathcljs

(protocol-path protocol-selector)
source

reserved-aware-demungecljs

(reserved-aware-demunge munged-name)
source

revert-reservedcljs

(revert-reserved s)
source

review-aritiescljs

(review-arities arities)

Some arities can be marked as fixed arity but in fact point to a variadic-arity function. We want to detect this case and turn such improperly categorized arities to ::variadic.

Some arities can be marked as fixed arity but in fact point to a variadic-arity function. We want to detect this case
and turn such improperly categorized arities to ::variadic.
sourceraw docstring

review-aritycljs

(review-arity [arity arity-fn])
source

scan-fast-path-protocolscljs

(scan-fast-path-protocols obj)
source

scan-fast-path-protocols-partitioncljs

(scan-fast-path-protocols-partition obj partition)
source

scan-protocolscljs

(scan-protocols obj)
source

scan-slow-path-protocolscljs

(scan-slow-path-protocols obj)
source

steal-fast-path-protocol-partitions-countclj

(steal-fast-path-protocol-partitions-count)
source

steal-fast-path-protocolsclj

(steal-fast-path-protocols)
source

strip-aritycljs

(strip-arity tokens)
source

trivial-fn-source?cljs

(trivial-fn-source? fn-source)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close