Giter Club home page Giter Club logo

Comments (6)

alangpierce avatar alangpierce commented on May 14, 2024

_interopRequireWildcard and _interopRequireDefault are included regardless of whether an import statement exists in the source. I would like to avoid this.

Makes sense. I've viewed that as low priority since it's not a correctness issue and it seems rare to write JavaScript these days without any import statements, but it certainly seems reasonable to avoid emitting unused functions.

To be clear, regardless of whether your code has import statements, Sucrase always assumes your code is a module. Most notably, that means it always parses in strict mode. (The JS spec defines each file as a "script" or a "module", and module parsing is slightly different, generally stricter. Anything with an import/export is always a module, and new codebases should probably be almost entirely modules.)

Also, I would like the option to exclude those functions entirely, because I will include them manually after concatenating sources.

Interesting, could you explain your build setup? Do you use a module bundler? Is the idea that each module would end up in its own closure, and you want to declare _interopRequireWildcard and _interopRequireDefault in the top-level scope? Or by "concatenating", do you mean literally just concatenating all of the files one after the other? If so, you might be able to concat the files and then run Sucrase on the result.

Is the idea here to reduce bundle size? You might consider using Sucrase for development builds (where bundle size presumably isn't important and build times are important) and Babel for production builds.

Generally I'm hesitant to add more options unless there's a reasonably strong justification, both because I want the configuration to be non-intimidating and because I want to avoid the inherent complexity from more config options.

from sucrase.

aleclarson avatar aleclarson commented on May 14, 2024

Modules are wrapped in their own closures. I prefer not to run sucrase on the entire bundle, because that would mean re-transforming the entire bundle whenever a file changes. And I would prefer my bundler not have a dependency on babel, so I'm using sucrase for both development and production builds.

The option can be undocumented, since anyone who needs it (probably rare) will find this issue. :)

from sucrase.

aleclarson avatar aleclarson commented on May 14, 2024

An option to ignore dynamic imports would be great, too! :)

from sucrase.

alangpierce avatar alangpierce commented on May 14, 2024

@aleclarson which module bundler are you using? Maybe you don't need to run the imports transform at all? I thought most module bundlers support import/export syntax natively now.

The imports transform is one of the uglier parts of Sucrase (and Babel/TypeScript, for that matter), and I'm excited for the eventual future when CommonJS is rare enough that the transform isn't necessary. Unfortunately, Node.js ESM support is still behind a flag, so at least for node, it'll be needed for a while.

from sucrase.

aleclarson avatar aleclarson commented on May 14, 2024

@alangpierce I'm making a bundler. I suppose I could just reference sucrase and implement it myself if it's not something you see value in.

edit: I'm going to fork sucrase for the time being.

from sucrase.

aleclarson avatar aleclarson commented on May 14, 2024

#237 has been merged, which addresses the first concern.

The requests for options.skipDynamicImports and options.omitHelpers should be considered low priority. I will open new issues for them at a later date, probably. Or just submit a PR when I need them.

from sucrase.

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.