Git Product home page Git Product logo

Comments (5)

mbostock avatar mbostock commented on July 24, 2024

The code I passed to d3-bundler to test is:

import {event, select, selectAll} from "d3-selection";
export {event, select, selectAll};

The resulting output was:

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
    typeof define === 'function' && define.amd ? define(['exports'], factory) :
    factory((global.d3 = {}));
}(this, function (exports) { 'use strict';
    
    var event = null;

    function listenerOf(listener, ancestors, args) {
      return function(event1) {
        var i = ancestors.length, event0 = event; // Events can be reentrant (e.g., focus).
        while (--i >= 0) args[i << 1] = ancestors[i].__data__;
        event = event1;
        try {
          listener.apply(ancestors[0], args);
        } finally {
          event = event0;
        }
      };
    }
    
    exports.event = event;
    
}));

from rollup.

Rich-Harris avatar Rich-Harris commented on July 24, 2024

Ah, yes - will need to implement this. IIRC Esperanto replaces all assignments to an exported value foo that take place a) after the export declaration or b) inside a function body with exports.foo = ....

I was wondering what would happen to d3.event. In d3-jsnext I had to cheat and use a global. Having it only be assigned to within selection-event will make life much easier, since it's illegal to assign to an imported binding.

from rollup.

mbostock avatar mbostock commented on July 24, 2024

FWIW, this is no longer blocking me because I’ve changed (yet again) the d3-bundler strategy to export a default object rather than use named exports. The new build looks like this:

import {
  event,
  select,
  selectAll
} from "d3-selection";

export default {
  get event() { return event; },
  select: select,
  selectAll: selectAll
};

And this works fine with Rollup just setting the local event directly.

from rollup.

Rich-Harris avatar Rich-Harris commented on July 24, 2024

I've changed some of the rewriting behaviour so that exported vars (or lets) are always rewritten as export.foo = .... Involves a little bit of dancing around, but I think it's the best solution. Hopefully I didn't introduce any bugs in the process.

Just so you're aware, using a default export will mean that Rollup wouldn't be able to (say) import select but not selectAll - it will always have to import the entire module. (Though it will look identical as far as UMD consumers are concerned.)

from rollup.

mbostock avatar mbostock commented on July 24, 2024

using a default export will mean that Rollup wouldn't be able to (say) import select but not selectAll

Right, but this module definition is the “end of the line” as far as composition goes: its only purpose is to generate UMD (or whatever), not to serve as another ES6 module to be imported elsewhere.

from rollup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.