Giter Club home page Giter Club logo

Comments (9)

noname0310 avatar noname0310 commented on June 8, 2024

I think it will be possible only if we solve the cjs export.

from js-sdsl.

noname0310 avatar noname0310 commented on June 8, 2024

How about applying export default only to esm?

@ZLY201

from js-sdsl.

ZLY201 avatar ZLY201 commented on June 8, 2024

How about applying export default only to esm?

@ZLY201

What do you mean?

from js-sdsl.

noname0310 avatar noname0310 commented on June 8, 2024

provide export default only to users who use esm.

from js-sdsl.

ZLY201 avatar ZLY201 commented on June 8, 2024

Do you mean:

import OrderedSet from 'ordered-set';
const { OrderedSet } = require('ordered-set');

from js-sdsl.

noname0310 avatar noname0310 commented on June 8, 2024

yes

from js-sdsl.

ZLY201 avatar ZLY201 commented on June 8, 2024

yes

Why cjs cannot transform to const OrderedSet = require('ordered-set')?

from js-sdsl.

noname0310 avatar noname0310 commented on June 8, 2024

The problem is when the named export exists together with default export.

If you use named export, the value you received in require becomes an object.

However, it is generally impossible to be an object and a constructor of an object(a.k.a class) at the same time, so if you do default export at the same time as named export, one side is ignored.

// lib.ts
class Foo { }
class Bar { }
class Baz { }

export { Foo, Bar };
export default Baz; // this will be ignored in CJS
// index.ts

// This value will be { "Foo": [object Object], "Bar": [object Object] } 
const lib = require('./lib.js');

// Because of the Destructuring, it seems like it is the same as a named export. But what the `require` returned was just an object
const { Foo, Bar } = require('./lib.js');

from js-sdsl.

ZLY201 avatar ZLY201 commented on June 8, 2024

I think there must be some way to transform export default xxx to exports = xxx.

I'll promise the single file like OrderedSet.ts will export only one class member.

Consider this tool: https://www.npmjs.com/package/ts-transform-default-export.

from js-sdsl.

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.