-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I updated vite-plugin-solid
and now namespaces merged with components are no longer allowed
#145
Comments
Okay so it seems that It's a very weird edge case honestly, although I would've expected it to raise an error too if not for functions to be re-assignable, and if namespaces transformed into variable declarations. Not sure if this should be fixed. Besides assignment to |
update: Upon checking, since we convert every function component into a HOC (declared via a variable), it seems that TS compiles weirdly for it. Example: const A = () => {
};
namespace A {
export const hello = 'world';
} const A = () => {
};
var A;
(function (A) {
A.hello = 'world';
})(A || (A = {})); and since we rely on HOC to apply HMR, this is most likely a wontfix. However, I would recommend just assigning to the function directly. related: |
Isn't it possible to use var A = () => {
};
var A;
(function (A) {
A.hello = 'world';
})(A || (A = {})); |
@AFatNiBBa your example code shows why it won't work. |
Do you transform the function to make HMR work BEFORE or AFTER transpiling typescript? // ↓
export var A = _$$component(_REGISTRY, "A", function A() {
// ...
}, {
location: "..."
}); And if you're doing it before the transpiling because if you were to do it after you would not know where the JSX was, then you could mark the function in some way (Maybe with a comment?) in order to still find it at the end |
there's no TypeScript transpilation happening, as it is deferred to ESBuild.
I'm not sure I understood the suggestion. |
Don't worry, if the transformation must happen at the TypeScript level, the suggestion doesn't apply anyway |
Isn't it possible to change export var A = _$$component(_REGISTRY, "A", function A() {
// ...
}, {
location: "..."
}); Into import { createComponent } from "solid-js";
const RANDOM_NAME = _$$component(_REGISTRY, "A", function A() {
// ...
}, {
location: "..."
});
// Wrapper
export function A(x) {
return createComponent(RANDOM_NAME, x);
}
// Now this is allowed
export namespace A {
export const value = 56;
} |
No, that would introduce some new layer of issues. I'm sorry, this might be a no-fix as TS is to be blamed here for this inconsistency. I could recommend you dropping the namespace usage (since it's not even recommended anymore by majority) but that's just one workaround. |
TypeScript is not to blame this time in my opinion, because functions have always behaved differently from lambdas, It is the plugin's responsability to ensure that if I write a function then a function will come out instead of a lambda expression. I think you shouldn't give priority to this issue, but it's something that has to be done eventually |
I'm sorry but something about the current transform is never going to be touched, we haven't even solved the SSR problem with the current transform, we'll be digging a whole new level of complexity if we do this "component in a component" kind of thing (which btw, also ruins the dev experience at some point). |
Describe the bug
If I create a
.tsx
file with this contentIt throws this error when I load the page (Running
vite dev
)I tried downgrading
vite-plugin-solid
and it worked(On the playground it always works)
Your Example Website or App
(localhost)
Steps to Reproduce the Bug or Issue
vite dev
Expected behavior
I expected this allowed TS syntax to not stop working
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: