Skip to content

Commit

Permalink
fix: infer noSvelteComponentTyped from svelteShimsPath for emitDts
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Jul 6, 2023
1 parent ab08ed6 commit dfcfacf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/svelte2tsx/src/emitDts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,19 @@ interface SvelteMap {
* early on when we first need to look at the file contents and can read
* those transformed source later on.
*/
async function createSvelteMap(config): Promise<SvelteMap> {
async function createSvelteMap(config: EmitDtsConfig): Promise<SvelteMap> {
const svelteFiles = new Map();

function add(path: string): boolean {
const code = ts.sys.readFile(path, 'utf-8');
const isTsFile = // svelte-preprocess allows default languages
['ts', 'typescript'].includes(config.preprocess?.defaultLanguages?.script) ||
/<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(code);
const isTsFile = /<script\s+[^>]*?lang=('|")(ts|typescript)('|")/.test(code);
const transformed = svelte2tsx(code, {
filename: path,
isTsFile,
mode: 'dts'
mode: 'dts',
noSvelteComponentTyped: config.svelteShimsPath
.replace(/\\/g, '/')
.endsWith('svelte2tsx/svelte-shims-v4.d.ts')
}).code;
svelteFiles.set(path, transformed);
return isTsFile;
Expand Down

0 comments on commit dfcfacf

Please sign in to comment.