ClojureScript

Self-host: Protocol prefixing broken for three- (or more) segment namespaces

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: 1.7.145
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

There is a protocol-prefix method in core.cljc (and also, in compiler.cljc) which employs .replace. In Java, this ends up replacing all occurrences of the old character with the new character, while in JavaScript, the same call only replaces the first character.

This results in breakage if attempting to make use of protocols in three- (or more) segment namespaces under self-host as the resulting emitted JavaScript will have some . characters in the namespace not converted to $ characters as desired.

Take for example the following REPL interaction

cljs.user=> (ns three.seg.core)
nil
three.seg.core=> (defprotocol IFoo (baz [x]))
nil
three.seg.core=> (deftype Foo [z] three.seg.core/IFoo (baz [x] z))

This will work fine in, say, noderepljs, where a line like the following appears in the emitted JavaScript:

three.seg.core.Foo.prototype.three$seg$core$IFoo$ = true;

but in a self-host REPL, this will cause JavaScript to be emitted that looks like this:

three.seg.core.Foo.prototype.three$seg.core$IFoo$ = true;

which will fail to be evaluated properly.

Activity

Hide
Mike Fikes added a comment -

Attached a patch that address the self-host issue.

Show
Mike Fikes added a comment - Attached a patch that address the self-host issue.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: