Comments (6)
_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.
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.
An option to ignore dynamic imports would be great, too! :)
from sucrase.
@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.
@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.
#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)
- Question: strict mode HOT 2
- Add option to disable TS import/export elision
- Allow arbitrary Sucrase configuration in sucrase/register and the CLI HOT 1
- Transpilation bug, changes `;` to `,` HOT 2
- Constructor return type annotations produce invalid JS syntax HOT 1
- (plugin commonjs--resolver) Syntax Error when importing file with json import HOT 1
- TypeScript: `x < y >= z` is incorrectly interpreted as a type argument list HOT 1
- Incorrect elision of `import {}` with TS transform disabled HOT 1
- TypeScript type-only re-exports not always properly elided
- TypeScript automatic named export elision incorrectly happens for re-export
- Incorrect elision of named import if typings of a callback function contains a parameter with the same name HOT 1
- Sucrase SyntaxError - (7:3) HOT 2
- jest.mock hoisting breaks when using @jest/globals
- Option to just compile JSX to object literal HOT 2
- Unexpected output from an exported mergeable enum HOT 2
- glob lib dependency, depends on Inflight lib which is now introducing a security vulnerability HOT 2
- Exporting declaration after function invocation misses semi
- Empty template spans break sourcemaps HOT 1
- Dont remove `export interface` , instead rename it to something else. HOT 4
- support absolute import with baseUrl HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sucrase.