svelte-preprocess
svelte-preprocess copied to clipboard
TypeScript not being processed when no filename is given
Describe the bug
if (filename == null) return { code: content };
in svelte-preprocess/src/transformers/typescript.ts line 497 is the issue.
To Reproduce
Call svelte.preprocess(code, processor)
manually without providing the third optional parameter ( omitting the filename )
https://github.com/wangjia184/svelte-parser/blob/master/src/worker.ts (not mine, not small)
Expected behavior
when inputing const x : number = 1
the output to be const x = 1
, even when no filename was provided.
Additional context
When you provide a weird filename like " "
then the preprocessor will work and remove the type annotations.
Is the request that the preprocessor blindly strip types without any checking of there is no filename? I'm not sure what else it could do. I'm also not sure whether that could cause problems with enums or any other language features.
That would be an improvement over leaving the annotation in and getting Unexpected token
errors when trying to execute or parse the resulting code.
Not sure if my issue relates to this but when I do this:
// script
import { Status, type Period, type IStuff} from "$lib/types"; // types.d.ts
// html
// custom component
<LabelInput
label="Status"
id={`${id}-status`}
name={`${id}-status`}
required
value={Status[currentStatus]} // enum
{disabled}
/>
then load the parent component, I get this error:
Loading module from “https://localhost:PORT/src/lib/types” was blocked because of a disallowed MIME type (“text/html”).
Edit 1: nvm, fixed the issue by renaming types.d.ts
-> types.ts