Skip to content
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

TypeScript not being processed when no filename is given #488

Closed
bfanger opened this issue Feb 24, 2022 · 3 comments · Fixed by #640
Closed

TypeScript not being processed when no filename is given #488

bfanger opened this issue Feb 24, 2022 · 3 comments · Fixed by #640

Comments

@bfanger
Copy link
Contributor

bfanger commented Feb 24, 2022

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.

@Conduitry
Copy link
Member

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.

@bfanger
Copy link
Contributor Author

bfanger commented Feb 24, 2022

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

@Gildedter
Copy link

Gildedter commented Jun 24, 2022

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

dummdidumm added a commit that referenced this issue Jun 12, 2024

Verified

This commit was signed with the committer’s verified signature.
m1guelpf Miguel Piedrafita
fixes #488
dummdidumm added a commit that referenced this issue Jun 12, 2024

Verified

This commit was signed with the committer’s verified signature.
m1guelpf Miguel Piedrafita
- breaking: remove TS mixed imports support, require TS 5.0 or higher
- breaking: require Svelte 4+, Node 18+
- breaking: add exports map
- fix: adjust type import
- fix: remove pug types from dependencies
- fix: allow TS filename to be undefined, fixes #488
- chore: replace jest with vitest
- chore: relax eslint config
- chore: bump peer deps, fixes #553, closes#635 
- chore: update CI, closes #638
- chore: get rid of magic-string as it's no longer used, bump node types
- docs: migration info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants