ClojureScript

In JavaScript ES2015 modules default export name is munged to default$

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: 1.9.908
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Screened

Description

When using a foreign lib which is ES2015 module with default export, the value which is being exported is assigned to a property default on a namespace object. In ClojureScript code this means one should call to default var of that namespace. However in complied output of ClojureScript code the name default is getting munged to default$.

export default function inc(v) {
  return v + 1;
}
(ns cljs-example.core
  (:require [lib.inc :as lib]))

(lib/default 0)
goog.provide("module$lib$inc");
function inc$$module$lib$inc(v){return v+1}
module$lib$inc.default=inc$$module$lib$inc
// Compiled by ClojureScript 1.8.40 {}
goog.provide('cljs_example.core');
goog.require('cljs.core');
goog.require('module$lib$inc');
module$lib$inc.default$.call(null,(0));

//# sourceMappingURL=core.js.map
  1. CLJS-1620.patch
    30/Jul/17 5:09 PM
    16 kB
    António Nuno Monteiro
  2. CLJS-1620-2.patch
    01/Aug/17 3:11 PM
    24 kB
    António Nuno Monteiro

Activity

Hide
David Nolen added a comment - - edited

One possible path around this is to respect the Closure Compiler language setting when munging instead of blindly munging ECMA-262 keywords. A patch that adopts this approach would be welcome.

Show
David Nolen added a comment - - edited One possible path around this is to respect the Closure Compiler language setting when munging instead of blindly munging ECMA-262 keywords. A patch that adopts this approach would be welcome.
Hide
António Nuno Monteiro added a comment -

Patch attached following the suggested approach.

Show
António Nuno Monteiro added a comment - Patch attached following the suggested approach.
Hide
David Nolen added a comment -

I reviewed the patch, I'm not sure I really understand the rationale behind the approach. It seems if any JS module exists is :es6 then ES6 keywords rules apply. However what I had in mind was to use Closure Compiler `:language-out` to manage this.

That said, the bits of patch to make `:js-module-index` richer in structure doesn't seem like a bad idea.

Show
David Nolen added a comment - I reviewed the patch, I'm not sure I really understand the rationale behind the approach. It seems if any JS module exists is :es6 then ES6 keywords rules apply. However what I had in mind was to use Closure Compiler `:language-out` to manage this. That said, the bits of patch to make `:js-module-index` richer in structure doesn't seem like a bad idea.
Hide
António Nuno Monteiro added a comment -

Attached patch with suggested changes.

Show
António Nuno Monteiro added a comment - Attached patch with suggested changes.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: