svelte-preprocess icon indicating copy to clipboard operation
svelte-preprocess copied to clipboard

TypeScript not being processed when no filename is given

Open bfanger opened this issue 2 years ago • 3 comments

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.

bfanger avatar Feb 24 '22 21:02 bfanger

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.

Conduitry avatar Feb 24 '22 21:02 Conduitry

That would be an improvement over leaving the annotation in and getting Unexpected token errors when trying to execute or parse the resulting code.

bfanger avatar Feb 24 '22 21:02 bfanger

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

Gildedter avatar Jun 24 '22 00:06 Gildedter