Comments (2)
As an example, given:
const comp = <>
<div>
<Foo bar={qux}/>
</div>
</>;
it would become:
const comp = {
_isJsx: true,
tag: '',
attrs: null,
children: [
{
_isJsx: true,
tag: 'div',
attrs: null,
children: [
{
_isJsx: true,
tag: Foo,
attrs: { qux },
children: []
}
]
}
]
}
from sucrase.
Hey @sdegutis , sorry for the delay. Unfortunately I think I'll need to call this request out of scope for Sucrase, at least for now. The goal of Sucrase is to take the most common and well-established transforms and re-implement them in a way that's lighter-weight and more specialized. Part of what makes that reasonable to maintain is to focus on a small number of options rather than allowing lots of configuration in how the transform behaves. I personally would really love it if the community standardized on a new JSX strategy that simply converted it to an object literal, but the current auto-imported function call is what we have today, and it's not the place of the Sucrase project to define a new standard. Of course, if other transpilers started implementing a transform like this, then Sucrase would as well.
I realize I'm responding a bit late, but I read about your specific issues and a few thoughts that came to mind that might be helpful:
- Supposedly the standard way to make
import {jsx as _jsx} from "core/jsx-runtime";
(with no file extension) work in the browser is to use import maps. I haven't played around with it myself, but it might be something to explore if you haven't. - Another thought about the auto-import is that you could just use the
classic
runtime, which doesn't auto-generate any imports. You could setjsxPragma
to some function that you define inline in the transformed code, for example. The automatic runtime is actually harder to work with when you're building tooling since it falls back tocreateElement
(the classic runtime) in some cases (see link in the next bullet), so it basically has all the complexity ofcreateElement
plus more complexity. - As mentioned in this comment, the long-term goal of the automatic runtime is actually to act as a transition period toward a transform that just creates a plain object literal (or at least calls a function that returns an object literal). To my knowledge, there hasn't really been any additional progress there, but I'm hoping for things to become simpler in the long term.
- Regarding replacing
.jsx
with.js
, the convention I'm aware of at least for TypeScript is to have imports reference the compiled filename (or, if you're using compile-on-the-fly or a bundler, the hypothetical compiled equivalent of the file), so basically always.js
. Consistent with TypeScript's stance to not rewrite import statements, Sucrase doesn't rewrite import statements. Of course, that requires tooling (like IDE autocomplete and navigation) to cooperate.
Hope that's useful. I'll close this issue for now since I think the main request is out of scope for Sucrase.
from sucrase.
Related Issues (20)
- TypeScript 5.0 support
- 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
- 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
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.