Comments (4)
Hi @renhiyama, unfortunately your suggestion of export const <var> = 0;
is out of scope for Sucrase. Sucrase tries to match the behavior of TypeScript transpileModule
as closely as possible (with minor exceptions), since it's meant to be a faster drop-in replacement. Babel, swc, and esbuild take the same approach, so this issue you're raising is a general issue (which already has some solutions, see below), not specific to Sucrase. See this playground link for how the output compares. If Sucrase did produce a runtime-visible export, it cause bugs for code iterating through a *
import, or might conflict with an explicit value export.
The typical way to avoid the error you're seeing is to ensure that the code is removed on the import
side. There are two historical ways this has been done:
- Automatic import elision. The default behavior for both TypeScript and Sucrase is to detect that
GlobOptions
is only used as a type, and to remove that import line (or just the one named import) in the resulting JS. TheisolatedModules
TypeScript option can help flag some issues like re-exports that can cause issues here. - Explicit
type
syntax in the import. With SucrasekeepUnusedImports
and TypeScriptverbatimModuleSyntax
(and its deprecated alternatives), the way to remove type imports is to explicitly writetype GlobOptions
.
Happy to reconsider if I'm overlooking a case where TypeScript (or another tool) emits a const
declaration like you're talking about, but generally Sucrase follows TypeScript's lead on how file-by-file transpilation should work.
from sucrase.
Can't you just import types explicitly as types import { type GlobOptions } from "..."
?
from sucrase.
Can't you just import types explicitly as types
import { type GlobOptions } from "..."
?
that's not what this issue is about. Sucrase seems to break any code that exports interfaces when converting any typescript code to javascript. In order to not break any compability issues, my suggestion posted above is the only solution.
Your suggestion doesn't make sense because sucrase's point is to make stuff work, without needing much changes, nor break anything up.
from sucrase.
@alangpierce could you please look at this issue asap?
from sucrase.
Related Issues (20)
- 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
- support absolute import with baseUrl HOT 1
- Is Sucrase support targeting ES3? HOT 1
- Certain syntax errors have poor position recovery
- Using --project switch incorrectly outputs to include base folder name
- Using --project switch breaks when `tsconfig.json` does not specify `outDir`
- When specifying a folder to compile, empty js files are output for `.d.ts` declaration files
- tsconfig.json parsing using JSON.parse which does not support all features that tsc does
- Support JSX xml-namespaced attributes HOT 4
- const enums are not transformed correctly 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.