svelte-typecheck 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -196
- package/cli.js +2 -2
- package/compile-worker.js +1 -0
- package/index.d.ts +0 -5
- package/index.js +1 -1
- package/package.json +1 -1
- package/shared-2ek7s6xw.js +1 -0
- package/shared-7cvnvjc0.js +2 -0
- package/shared-8badht7e.js +4 -0
- package/shared-atsj8zxq.js +4 -0
- package/shared-ebbnnbmn.js +19 -0
- package/shared-exams0w3.js +6 -0
- package/shared-g75sf85w.js +47 -0
- package/shared-msaa239m.js +263 -0
- package/shared-xcpj2ac7.js +1 -0
- package/shared-2xseck5b.js +0 -1
- package/shared-ky3xz37f.js +0 -2
- package/shared-rv2wrjaa.js +0 -334
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import{version2}from"./shared-7cvnvjc0.js";import{lexImportsExports,configFingerprint,svelteDirOf,compileAll,compileOffThread}from"./shared-exams0w3.js";import{lexComponent2}from"./shared-8badht7e.js";import{createLocator}from"./shared-atsj8zxq.js";import{spawn}from"node:child_process";import{createHash}from"node:crypto";import{existsSync as existsSync3,readFileSync as readFileSync3,statSync}from"node:fs";import{mkdir,readFile,rm,writeFile}from"node:fs/promises";import{createRequire as createRequire2}from"node:module";import{basename as basename2,dirname as dirname3,join as join4,relative as relative2,resolve as resolve2,sep as sep2}from"node:path";import{existsSync,readFileSync}from"node:fs";import{delimiter,dirname,join}from"node:path";var CHECKERS=["tsc","tsgo","tsrs","bun"],PACKAGES={tsc:["typescript","tsc"],tsgo:["@typescript/native-preview","tsgo"],tsrs:["tsrs","tsrs"]},NODE_SHEBANG=/^#!.*\bnode\b/,WINDOWS_SHIM=/\.(cmd|bat)$/i;function onPath(name,platform=process.platform){let extensions=platform==="win32"?(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).flatMap((ext)=>[ext.toLowerCase(),ext]):[""];for(let dir of(process.env.PATH??"").split(delimiter)){if(!dir)continue;for(let ext of extensions){let candidate=join(dir,name+ext);if(existsSync(candidate))return candidate}}return}function packageDir(name,cwd){for(let dir=cwd;;dir=dirname(dir)){let candidate=join(dir,"node_modules",name);if(existsSync(join(candidate,"package.json")))return candidate;if(dirname(dir)===dir)return}}function checkerCommand(checker,cwd){if(checker==="bun"){let bun=process.versions.bun?process.execPath:onPath("bun");return bun?{command:bun,prefix:[],version:process.versions.bun}:void 0}let[name,bin]=PACKAGES[checker],dir=packageDir(name,cwd);if(dir){let pkg=JSON.parse(readFileSync(join(dir,"package.json"),"utf-8")),relative=typeof pkg.bin==="string"?pkg.bin:pkg.bin?.[bin];if(relative){let path=join(dir,relative),head=readFileSync(path,"utf-8").slice(0,100);return NODE_SHEBANG.test(head)?{command:process.execPath,prefix:[path],version:pkg.version}:{command:path,prefix:[],version:pkg.version}}}let found=onPath(bin);if(!found)return;return WINDOWS_SHIM.test(found)?{command:found,prefix:[],shell:!0}:{command:found,prefix:[]}}function checkerArgs(checker,tsconfig){return checker==="bun"?["check","-p",tsconfig,"--no-pretty","--all"]:["-p",tsconfig,"--pretty","false"]}import{readdirSync}from"node:fs";import{join as join2}from"node:path";var GLOB_LITERAL=/[.+^$()|[\]\\]/g,LEADING_DOT_SLASH=/^\.\//;function globToRegExp(pattern){let source="";for(let i=0;i<pattern.length;i++){let char=pattern[i]??"";if(char==="*"&&pattern[i+1]==="*"){let slash=pattern[i+2]==="/";source+=slash?"(?:.*/)?":".*",i+=slash?2:1}else if(char==="*")source+="[^/]*";else if(char==="?")source+="[^/]";else if(char==="{")source+="(?:";else if(char==="}")source+=")";else if(char===",")source+="|";else source+=char.replace(GLOB_LITERAL,String.raw`\$&`)}return new RegExp(`^${source}$`)}function matcher(globs){if(globs.length===0)return()=>!1;let res=globs.map((pattern)=>globToRegExp(pattern.replace(LEADING_DOT_SLASH,"")));return(path)=>res.some((re)=>re.test(path))}function glob(root,globs){let matches=matcher(globs),dotFolders=globs.some((g)=>g.startsWith(".")||g.includes("/.")),found=[],walk=(dir,prefix)=>{for(let entry of readdirSync(dir,{withFileTypes:!0})){let rel=prefix+entry.name;if(entry.isDirectory()){if(entry.name==="node_modules")continue;if(entry.name.startsWith(".")&&!dotFolders)continue;walk(join2(dir,entry.name),`${rel}/`)}else if(matches(rel))found.push(rel)}};return walk(root,""),found.sort()}import{existsSync as existsSync2,readFileSync as readFileSync2}from"node:fs";import{createRequire}from"node:module";import{basename,dirname as dirname2,isAbsolute,join as join3,relative,resolve,sep}from"node:path";var LINE_COMMENT=/\/\/[^\n]*/g,BLOCK_COMMENT=/\/\*[\s\S]*?\*\//g,TRAILING_COMMA=/,(\s*[}\]])/g,STRING=/"(?:[^"\\]|\\.)*"/g,PLACEHOLDER=/"\0(\d+)"/g,WILDCARD=/[*?{]/,HAS_EXTENSION=/\.[^/\\]+$/,NODE_MODULES_JS=/\/node_modules\/.+\.[cm]?js$/,DEFAULT_EXCLUDE=["node_modules","bower_components","jspm_packages"],CONFIG_DIR="${configDir}";function parseJsonc(text){let strings=[],stripped=text.replace(STRING,(s)=>`"\x00${strings.push(s)-1}"`).replace(LINE_COMMENT,"").replace(BLOCK_COMMENT,"").replace(TRAILING_COMMA,"$1").replaceAll(PLACEHOLDER,(_,i)=>strings[Number(i)]??"");return JSON.parse(stripped)}function readInputs(path,read=[]){read.push(path);let config=parseJsonc(readFileSync2(path,"utf-8")),dir=dirname2(path),absolute=(list)=>list?.map((p)=>resolve(dir,p)),inputs={},bases=typeof config.extends==="string"?[config.extends]:config.extends;for(let base of bases??[]){let basePath=base.startsWith(".")?resolve(dir,base):createRequire(path).resolve(base),baseInputs=readInputs(basePath,read),difference=toPosix(relative(dir,dirname2(basePath))),rebase=(specs)=>specs?.map((spec)=>difference&&!isAbsolute(spec)&&!spec.startsWith(CONFIG_DIR)?`${difference}/${spec}`:spec);inputs={...inputs,...defined({...baseInputs,includeSpecs:rebase(baseInputs.includeSpecs),excludeSpecs:rebase(baseInputs.excludeSpecs)})}}let options=config.compilerOptions,baseUrl=options?.baseUrl?resolve(dir,options.baseUrl):void 0,pathsBase=baseUrl??inputs.baseUrl??dir;return{...inputs,...defined({include:absolute(config.include),exclude:absolute(config.exclude),files:absolute(config.files),rootDirs:absolute(options?.rootDirs),checkJs:options?.checkJs,allowJs:options?.allowJs,skipLibCheck:options?.skipLibCheck,moduleResolution:options?.moduleResolution,includeSpecs:config.include,excludeSpecs:config.exclude,outDir:options?.outDir&&resolve(dir,options.outDir),declarationDir:options?.declarationDir&&resolve(dir,options.declarationDir),baseUrl,paths:options?.paths&&Object.fromEntries(Object.entries(options.paths).map(([key,targets])=>[key,targets.map((t)=>resolve(pathsBase,t))]))})}}function defined(inputs){return Object.fromEntries(Object.entries(inputs).filter(([,value])=>value!==void 0))}function findUp(from,name){for(let dir=from;;dir=dirname2(dir)){let path=join3(dir,name);if(existsSync2(path))return path;if(dirname2(dir)===dir)return}}function findTsconfig(dir){let ts=findUp(dir,"tsconfig.json"),js=findUp(dir,"jsconfig.json");return ts&&(!js||ts.length>=js.length)?ts:js}var toPosix=(path)=>path.split(sep).join("/"),asTypeScriptPath=(path)=>toPosix(path).replace(/^[A-Z]:/,(drive)=>drive.toLowerCase());function splitGlob(pattern){let parts=toPosix(pattern).split("/"),at=parts.findIndex((part)=>WILDCARD.test(part));if(at===-1)return[pattern,""];return[parts.slice(0,at).join("/")||"/",parts.slice(at).join("/")]}function svelteGlobOf(pattern){if(pattern.endsWith(".svelte"))return pattern;if(WILDCARD.test(pattern))return pattern.endsWith("*")?`${pattern.slice(0,-1)}*.svelte`:void 0;return HAS_EXTENSION.test(pattern)?void 0:`${pattern}/**/*.svelte`}function absoluteMatcher(patterns){let globs=patterns.flatMap((p)=>{let posix=toPosix(p);return WILDCARD.test(posix)?[posix]:[posix,`${posix}/**`]}),matches=matcher(globs.map((g)=>g.replace(/^\//,"")));return(path)=>matches(toPosix(path).replace(/^\//,""))}function projectOf(options){let{workspace}=options,tsconfig=tsconfigOf(workspace,options.tsconfig);if(options.tsconfig&&tsconfig&&!existsSync2(tsconfig))throw Error(`Could not find tsconfig/jsconfig file at ${tsconfig}`);if(!tsconfig){let isIgnored=ignoreMatcher(options.ignore??[]);return{components:glob(workspace,options.components??["**/*.svelte"]).filter((rel)=>!isIgnored(rel)).map((rel)=>join3(workspace,rel)),files:[],include:[],exclude:[],rootDirs:[],configFiles:[],paths:{},checkJs:!0,allowJs:!0,skipLibCheck:!0,selfExports:{},raw:{},reports:()=>!1}}let configFiles=[],inputs=readInputs(tsconfig,configFiles),raw=parseJsonc(readFileSync2(tsconfig,"utf-8")),include=inputs.include??(inputs.files?[]:[join3(dirname2(tsconfig),"**/*")]),exclude=inputs.exclude??DEFAULT_EXCLUDE.map((p)=>join3(dirname2(tsconfig),p)),files=new Set(inputs.files??[]),isExcluded=absoluteMatcher(exclude),components;if(options.components)components=glob(workspace,options.components).map((rel)=>join3(workspace,rel));else{let found=new Set([...files].filter((f)=>f.endsWith(".svelte")));for(let pattern of include){let svelteGlob=svelteGlobOf(pattern);if(!svelteGlob)continue;let[base,rest]=splitGlob(svelteGlob);if(!rest){if(existsSync2(base))found.add(base);continue}if(!existsSync2(base))continue;for(let rel of glob(base,[rest]))found.add(join3(base,rel))}components=[...found].sort()}return components=components.filter((path)=>!isExcluded(path)),{tsconfig,components,files:inputs.files??[],include,exclude,rootDirs:inputs.rootDirs??[],configFiles,paths:{...importsOf(dirname2(tsconfig)),...inputs.paths},checkJs:inputs.checkJs??!1,allowJs:inputs.allowJs??basename(tsconfig)==="jsconfig.json",skipLibCheck:inputs.skipLibCheck??!1,selfExports:LEGACY_RESOLUTION.test(inputs.moduleResolution??"")?{}:exportsOf(dirname2(tsconfig)),raw,inputSpecs:inputs.files||raw.references?void 0:{include:inputs.includeSpecs??["**/*"],exclude:inputs.excludeSpecs??[inputs.outDir,inputs.declarationDir].flatMap((dir)=>dir?[asTypeScriptPath(dir)]:[])},reports:(path)=>!NODE_MODULES_JS.test(toPosix(path))}}function importsOf(dir){let path=findUp(dir,"package.json");if(!path)return{};let imports;try{({imports}=JSON.parse(readFileSync2(path,"utf-8")))}catch{return{}}let paths={};for(let[key,value]of Object.entries(imports??{})){let target=importTarget(value);if(key.startsWith("#")&&target?.startsWith("./"))paths[key]=[resolve(dirname2(path),target)]}return paths}function exportsOf(dir){let path=findUp(dir,"package.json");if(!path)return{};let name,exports;try{({name,exports}=JSON.parse(readFileSync2(path,"utf-8")))}catch{return{}}if(typeof name!=="string"||exports==null)return{};let subpaths=typeof exports==="object"&&!Array.isArray(exports)&&Object.keys(exports).some((key)=>key.startsWith("."))?exports:{".":exports},paths={};for(let[key,value]of Object.entries(subpaths)){if(!key.startsWith("."))continue;let targets=exportTargets(value).filter((target)=>target.startsWith("./")).map((target)=>resolve(dirname2(path),target));if(targets.length>0)paths[key==="."?name:`${name}/${key.slice(2)}`]=targets}return paths}function exportTargets(value){if(typeof value==="string")return[value];if(Array.isArray(value))return value.flatMap(exportTargets);if(!value||typeof value!=="object")return[];return Object.entries(value).flatMap(([condition,target])=>EXPORT_CONDITIONS.has(condition)?exportTargets(target):[])}var EXPORT_CONDITIONS=new Set(["types","import","default"]),LEGACY_RESOLUTION=/^(node|node10|classic)$/i;function importTarget(value){if(typeof value==="string")return value;if(Array.isArray(value))return importTarget(value[0]);if(!value||typeof value!=="object")return;let conditions=value;for(let condition of["types","import","default"])if(condition in conditions)return importTarget(conditions[condition]);return importTarget(Object.values(conditions)[0])}var PROGRAM_FILE=/\.(svelte|[cm]?[jt]sx?)$/,JS_FILE=/\.[cm]?jsx?$/;function byFolder(a,b){let pa=a.split(sep),pb=b.split(sep);for(let i=0;i<Math.min(pa.length,pb.length);i++){if(pa[i]===pb[i])continue;let aFile=i===pa.length-1,bFile=i===pb.length-1;if(aFile!==bFile)return aFile?-1:1;return(pa[i]??"")<(pb[i]??"")?-1:1}return pa.length-pb.length}function programFiles(project){let isExcluded=absoluteMatcher(project.exclude),found=new Set(project.files);for(let pattern of project.include){let fileGlob=WILDCARD.test(pattern)||HAS_EXTENSION.test(pattern)?pattern:`${pattern}/**/*`,[base,rest]=splitGlob(fileGlob);if(!rest){if(existsSync2(base)&&PROGRAM_FILE.test(base)&&(project.allowJs||!JS_FILE.test(base)))found.add(base);continue}if(!existsSync2(base))continue;let matched=glob(base,[rest]).map((rel)=>join3(base,rel)).filter((path)=>PROGRAM_FILE.test(path)&&(project.allowJs||!JS_FILE.test(path))&&!isExcluded(path)).sort(byFolder);for(let path of matched)found.add(path)}return[...found]}function scriptsOf(project,test){let isExcluded=absoluteMatcher(project.exclude),found=new Set;for(let pattern of project.include){let scriptGlob=WILDCARD.test(pattern)||HAS_EXTENSION.test(pattern)?pattern:`${pattern}/**/*`,[base,rest]=splitGlob(scriptGlob);if(!rest){if(existsSync2(base)&&test(base))found.add(base);continue}if(!existsSync2(base))continue;for(let rel of glob(base,[rest])){let path=join3(base,rel);if(test(path)&&!isExcluded(path))found.add(path)}}return[...found].sort()}function relativeTo(from,path){let rel=toPosix(relative(from,path));return rel.startsWith(".")||isAbsolute(rel)?rel:`./${rel}`}function ignoreMatcher(patterns){let tests=patterns.map((raw)=>{let pattern=raw.trim();if(pattern.endsWith("**"))pattern=pattern.slice(0,-2);if(pattern.startsWith("**")){let rest=pattern.slice(2);if(rest.includes("*"))throw Error(INVALID_IGNORE);return(path)=>path.includes(rest)}if(pattern.includes("*"))throw Error(INVALID_IGNORE);return(path)=>path.startsWith(pattern)});return(path)=>tests.some((test)=>test(path))}var INVALID_IGNORE="Invalid --ignore pattern: only ** at the start or end is supported";function tsconfigOf(workspace,option){if(option===!1)return;if(option)return resolve(workspace,option);return findTsconfig(workspace)}var SHIMS={"shims.d.ts":`type SvelteStore<T> = {
|
|
2
|
+
subscribe: (run: (value: T) => any, invalidate?: any) => any;
|
|
3
|
+
};
|
|
4
|
+
type __sveltets_2_SvelteActionReturnType = {
|
|
5
|
+
update?: (args: any) => void;
|
|
6
|
+
destroy?: () => void;
|
|
7
|
+
$$_attributes?: Record<string, any>;
|
|
8
|
+
} | void;
|
|
9
|
+
type __sveltets_2_SvelteTransitionConfig = {
|
|
10
|
+
delay?: number;
|
|
11
|
+
duration?: number;
|
|
12
|
+
easing?: (t: number) => number;
|
|
13
|
+
css?: (t: number, u: number) => string;
|
|
14
|
+
tick?: (t: number, u: number) => void;
|
|
15
|
+
};
|
|
16
|
+
type __sveltets_2_SvelteTransitionReturnType =
|
|
17
|
+
| __sveltets_2_SvelteTransitionConfig
|
|
18
|
+
| (() => __sveltets_2_SvelteTransitionConfig);
|
|
19
|
+
type __sveltets_2_SvelteAnimationReturnType = {
|
|
20
|
+
delay?: number;
|
|
21
|
+
duration?: number;
|
|
22
|
+
easing?: (t: number) => number;
|
|
23
|
+
css?: (t: number, u: number) => string;
|
|
24
|
+
tick?: (t: number, u: number) => void;
|
|
25
|
+
};
|
|
26
|
+
declare type ConstructorOfATypedSvelteComponent = new (args: {
|
|
27
|
+
target: any;
|
|
28
|
+
props?: any;
|
|
29
|
+
}) => $$check.Typed;
|
|
30
|
+
interface __sveltets_2_IsomorphicComponent<
|
|
31
|
+
Props extends Record<string, any> = any,
|
|
32
|
+
Events extends Record<string, any> = any,
|
|
33
|
+
Slots extends Record<string, any> = any,
|
|
34
|
+
Exports = {},
|
|
35
|
+
Bindings = string,
|
|
36
|
+
> {
|
|
37
|
+
new (
|
|
38
|
+
options: import("svelte").ComponentConstructorOptions<Props>,
|
|
39
|
+
): import("svelte").SvelteComponent<Props, Events, Slots> & {
|
|
40
|
+
$$bindings?: Bindings;
|
|
41
|
+
} & Exports;
|
|
42
|
+
(
|
|
43
|
+
internal: unknown,
|
|
44
|
+
props: Props extends Record<string, never>
|
|
45
|
+
? { $$events?: Events; $$slots?: Slots }
|
|
46
|
+
: Props & { $$events?: Events; $$slots?: Slots },
|
|
47
|
+
): Exports & { $set?: any; $on?: any };
|
|
48
|
+
z_$$bindings?: Bindings;
|
|
49
|
+
}
|
|
50
|
+
type __sveltets_2_PropsWithChildren<Props, Slots> = Props &
|
|
51
|
+
(Slots extends { default: any }
|
|
52
|
+
? Props extends Record<string, never>
|
|
53
|
+
? any
|
|
54
|
+
: { children?: any }
|
|
55
|
+
: {});
|
|
56
|
+
declare namespace $$check {
|
|
57
|
+
function any(...checked: any[]): any;
|
|
58
|
+
function none(...checked: any[]): {};
|
|
59
|
+
function props(): { [index: string]: any };
|
|
60
|
+
function reactive<T>(value: () => T): T;
|
|
61
|
+
function store<T = any>(store: SvelteStore<T>): T;
|
|
62
|
+
function store<Store extends SvelteStore<any> | undefined | null>(
|
|
63
|
+
store: Store,
|
|
64
|
+
): Store extends SvelteStore<infer T> ? T : Store;
|
|
65
|
+
function each<T extends ArrayLike<unknown> | Iterable<unknown>>(
|
|
66
|
+
array:
|
|
67
|
+
| T
|
|
68
|
+
| (typeof import("svelte") extends { mount: any }
|
|
69
|
+
? undefined | null
|
|
70
|
+
: never),
|
|
71
|
+
): T extends ArrayLike<infer U>
|
|
72
|
+
? U[]
|
|
73
|
+
: T extends Iterable<infer U>
|
|
74
|
+
? Iterable<U>
|
|
75
|
+
: any[];
|
|
76
|
+
function item<T>(array: ArrayLike<T>): T;
|
|
77
|
+
function action<T extends __sveltets_2_SvelteActionReturnType>(
|
|
78
|
+
returned: T,
|
|
79
|
+
): T extends { $$_attributes?: any } ? T["$$_attributes"] : {};
|
|
80
|
+
function attributes<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
|
|
81
|
+
t1: T1,
|
|
82
|
+
t2?: T2,
|
|
83
|
+
t3?: T3,
|
|
84
|
+
t4?: T4,
|
|
85
|
+
t5?: T5,
|
|
86
|
+
t6?: T6,
|
|
87
|
+
t7?: T7,
|
|
88
|
+
t8?: T8,
|
|
89
|
+
t9?: T9,
|
|
90
|
+
t10?: T10,
|
|
91
|
+
): T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10;
|
|
92
|
+
function transition(returned: __sveltets_2_SvelteTransitionReturnType): {};
|
|
93
|
+
function animation(returned: __sveltets_2_SvelteAnimationReturnType): {};
|
|
94
|
+
const move: { from: DOMRect; to: DOMRect };
|
|
95
|
+
function domEvent<K extends keyof HTMLElementEventMap>(
|
|
96
|
+
event: K,
|
|
97
|
+
): HTMLElementEventMap[K];
|
|
98
|
+
function getSet<T>(get: (() => T) | null | undefined, set: (t: T) => void): T;
|
|
99
|
+
function elementTag<T extends string>(
|
|
100
|
+
tag: T | undefined | null,
|
|
101
|
+
): keyof HTMLElementTagNameMap extends T ? string : T;
|
|
102
|
+
function snippet(
|
|
103
|
+
// @ts-ignore Svelte 5 only
|
|
104
|
+
rendered: ReturnType<import("svelte").Snippet> | undefined | null,
|
|
105
|
+
): any;
|
|
106
|
+
function matches<Props>(props: Props): {};
|
|
107
|
+
type Details<T> = {
|
|
108
|
+
[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent
|
|
109
|
+
? T[K]["detail"]
|
|
110
|
+
: T[K];
|
|
111
|
+
};
|
|
112
|
+
type KeysMatching<T, V> = {
|
|
113
|
+
[K in keyof T]-?: T[K] extends V ? K : never;
|
|
114
|
+
}[keyof T];
|
|
115
|
+
function dispatched<Typings>(): {
|
|
116
|
+
[K in keyof Typings]: CustomEvent<Typings[K]>;
|
|
117
|
+
};
|
|
118
|
+
function slots<Slots = Record<string, Record<string, any>>>(): <
|
|
119
|
+
Name extends keyof Slots,
|
|
120
|
+
>(
|
|
121
|
+
slotName: Name,
|
|
122
|
+
attrs: Slots[Name],
|
|
123
|
+
) => Record<string, any>;
|
|
124
|
+
type Typed = {
|
|
125
|
+
$$prop_def: any;
|
|
126
|
+
$$events_def: any;
|
|
127
|
+
$$slot_def: any;
|
|
128
|
+
$on(event: string, handler: any): () => void;
|
|
129
|
+
};
|
|
130
|
+
function component<
|
|
131
|
+
T extends
|
|
132
|
+
| ConstructorOfATypedSvelteComponent
|
|
133
|
+
| (typeof import("svelte") extends { mount: any }
|
|
134
|
+
? // @ts-ignore svelte.Component doesn't exist in Svelte 4
|
|
135
|
+
import("svelte").Component<any, any, any>
|
|
136
|
+
: never)
|
|
137
|
+
| null
|
|
138
|
+
| undefined,
|
|
139
|
+
>(
|
|
140
|
+
type: T,
|
|
141
|
+
): NonNullable<
|
|
142
|
+
T extends ConstructorOfATypedSvelteComponent
|
|
143
|
+
? T
|
|
144
|
+
: typeof import("svelte") extends { mount: any }
|
|
145
|
+
? // @ts-ignore svelte.Component doesn't exist in Svelte 4
|
|
146
|
+
T extends import("svelte").Component<
|
|
147
|
+
infer Props extends Record<string, any>,
|
|
148
|
+
infer Exports extends Record<string, any>,
|
|
149
|
+
infer Bindings extends string
|
|
150
|
+
>
|
|
151
|
+
? new (
|
|
152
|
+
options: import("svelte").ComponentConstructorOptions<Props>,
|
|
153
|
+
) => import("svelte").SvelteComponent<
|
|
154
|
+
Props,
|
|
155
|
+
Props["$$events"],
|
|
156
|
+
Props["$$slots"]
|
|
157
|
+
> &
|
|
158
|
+
Exports & { $$bindings: Bindings }
|
|
159
|
+
: never
|
|
160
|
+
: never
|
|
161
|
+
>;
|
|
162
|
+
function bindings<B extends string[]>(...bindings: B): B[number];
|
|
163
|
+
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
164
|
+
type Loose<Props> = {
|
|
165
|
+
[K in keyof Props]: Props[K] extends never
|
|
166
|
+
? never
|
|
167
|
+
: Props[K] extends undefined
|
|
168
|
+
? any
|
|
169
|
+
: Props[K];
|
|
170
|
+
};
|
|
171
|
+
type LooseSlots<Slots> = {
|
|
172
|
+
[K in keyof Slots]: {
|
|
173
|
+
[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S];
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
type WithOptional<Props, Keys extends keyof Props> = Omit<Props, Keys> &
|
|
177
|
+
Partial<Pick<Props, Keys>>;
|
|
178
|
+
}`,"svelte3-elements.d.ts":`/// <reference lib="dom" />
|
|
179
|
+
// @ts-nocheck
|
|
180
|
+
declare namespace svelteHTML {
|
|
181
|
+
function mapElementTag<K extends keyof ElementTagNameMap>(
|
|
182
|
+
tag: K,
|
|
183
|
+
): ElementTagNameMap[K];
|
|
184
|
+
function mapElementTag<K extends keyof SVGElementTagNameMap>(
|
|
185
|
+
tag: K,
|
|
186
|
+
): SVGElementTagNameMap[K];
|
|
187
|
+
function mapElementTag(tag: any): any;
|
|
188
|
+
function createElement<
|
|
189
|
+
Elements extends IntrinsicElements,
|
|
190
|
+
Key extends keyof Elements,
|
|
191
|
+
>(
|
|
192
|
+
element: Key | undefined | null,
|
|
193
|
+
attrs: string extends Key
|
|
194
|
+
? import("svelte/elements").HTMLAttributes<any>
|
|
195
|
+
: Elements[Key],
|
|
196
|
+
): Key extends keyof ElementTagNameMap
|
|
197
|
+
? ElementTagNameMap[Key]
|
|
198
|
+
: Key extends keyof SVGElementTagNameMap
|
|
199
|
+
? SVGElementTagNameMap[Key]
|
|
200
|
+
: any;
|
|
201
|
+
function createElement<
|
|
202
|
+
Elements extends IntrinsicElements,
|
|
203
|
+
Key extends keyof Elements,
|
|
204
|
+
T,
|
|
205
|
+
>(
|
|
206
|
+
element: Key | undefined | null,
|
|
207
|
+
attrsEnhancers: T,
|
|
208
|
+
attrs: (string extends Key
|
|
209
|
+
? import("svelte/elements").HTMLAttributes<any>
|
|
210
|
+
: Elements[Key]) &
|
|
211
|
+
T,
|
|
212
|
+
): Key extends keyof ElementTagNameMap
|
|
213
|
+
? ElementTagNameMap[Key]
|
|
214
|
+
: Key extends keyof SVGElementTagNameMap
|
|
215
|
+
? SVGElementTagNameMap[Key]
|
|
216
|
+
: any;
|
|
217
|
+
interface HTMLAttributes<T extends EventTarget = any> {}
|
|
218
|
+
interface SVGAttributes<T extends EventTarget = any> {}
|
|
219
|
+
type HTMLProps<Property, Override> = Omit<
|
|
220
|
+
import("svelte/elements").SvelteHTMLElements[Property],
|
|
221
|
+
keyof Override
|
|
222
|
+
> &
|
|
223
|
+
Override;
|
|
224
|
+
type MappedElements = {
|
|
225
|
+
[
|
|
226
|
+
K in keyof import("svelte/elements").SvelteHTMLElements
|
|
227
|
+
]: K extends \`svelte:\${string}\`
|
|
228
|
+
? import("svelte/elements").SvelteHTMLElements[K]
|
|
229
|
+
: HTMLProps<
|
|
230
|
+
K,
|
|
231
|
+
K extends keyof HTMLElementTagNameMap
|
|
232
|
+
? HTMLAttributes
|
|
233
|
+
: K extends keyof SVGElementTagNameMap
|
|
234
|
+
? SVGAttributes
|
|
235
|
+
: HTMLAttributes
|
|
236
|
+
>;
|
|
237
|
+
};
|
|
238
|
+
interface IntrinsicElements extends MappedElements {}
|
|
239
|
+
}`};function shim(file){return SHIMS[file]}var DIAGNOSTIC=/^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/,CONTINUATION=/^\s+\S/,GLOBAL_DIAGNOSTIC=/^error (TS\d+): (.*)$/,TS_MODULE=/\.[cm]?tsx?$/,IDENTIFIER=/^[A-Za-z_$][\w$]*$/,DECLARATION_FILE=/\.d\.[cm]?ts$/,TS_DIRECTIVE=/^\s*\/\/\s*@ts-(ignore|expect-error)\b/,LINE_BREAK=/\r?\n/,JS_FILE2=/\.[cm]?jsx?$/,SYNTAX_CODE=/^TS[18]\d{3}$/,STOPPED=/Stopped before type checking/,TS_SCRIPT=/<script\b[^>]*\blang=["']?(ts|typescript)\b/,GENERATED_NAME=/(?:\+\+)?([^/\\]+?)(?:\.d\.svelte(?:\.ts)?|\.svelte\.[jt]s)$/,DRIVE_PATH=/\b[A-Z]:\//g,toPosix2=(path)=>path.split(sep2).join("/"),escapeRegExp=(text)=>text.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),TYPE_CODE=/^TS[2-7]\d{3}$/,TOKEN=/^(?:[\w$]+|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|`[^`]*`)/,STORE_ERROR=/^TS(2769|2345)$/,REACTIVE_NOISE=/^TS(7028|2695)$/,CACHE_FORMAT=2,RESULT_CACHE="result.json",EMIT_CACHE="emit-cache.json",COMPILE_CACHE="compile-cache.json",hash=(text)=>createHash("sha1").update(text).digest("hex"),OFF_THREAD_AT=16,MANIFEST="manifest.json",DEFAULT_COMPILER_OPTIONS={allowJs:!0,noEmit:!0,declaration:!1,skipLibCheck:!0,maxNodeModuleJsDepth:2,allowSyntheticDefaultImports:!0,target:"esnext",module:"esnext",moduleResolution:"bundler"};class EmitError extends Error{}var SHELL_SPECIAL=/[\s"&|<>^()%!]/,quote=(arg)=>SHELL_SPECIAL.test(arg)?`"${arg.replaceAll('"','""')}"`:arg;function run(command,args,cwd,shell=!1){return new Promise((done,fail)=>{let env={...process.env,PWD:cwd},child=shell?spawn(quote(command),args.map(quote),{cwd,env,shell:!0}):spawn(command,args,{cwd,env}),output="";child.stdout.on("data",(chunk)=>{output+=chunk}),child.stderr.on("data",(chunk)=>{output+=chunk}),child.on("error",fail),child.on("close",()=>done(output))})}function parseDiagnostics(text){let found=[],continues=!1;for(let line of text.split(LINE_BREAK)){let m=DIAGNOSTIC.exec(line),global=m?null:GLOBAL_DIAGNOSTIC.exec(line);if(m)found.push({file:m[1]??"",line:Number(m[2]),column:Number(m[3]),code:m[4]??"",message:m[5]??""});else if(global)found.push({file:"",line:1,column:1,code:global[1]??"",message:global[2]??""});else if(continues&&CONTINUATION.test(line)){let last=found.at(-1);if(last)last.message+=`
|
|
240
|
+
${line}`}continues=m!==null||global!==null||continues&&line.trim()!==""}return found}var STATIC_IMPORT=/(?:\bfrom\s*|^\s*import\s*)["']([^"']+)["']/gm,DYNAMIC_IMPORT=/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g,JS_EXTENSION=/\.([cm]?)js(x?)$/;function programOrder(roots,specifiersOf,resolveImport,imports=new Map){let order=new Map,next=0,visit=(path)=>{if(order.has(path))return;order.set(path,Number.POSITIVE_INFINITY);for(let specifier of specifiersOf(path)){let target=resolveImport(path,specifier);if(!target)continue;imports.set(path,(imports.get(path)??new Set).add(target)),visit(target)}order.set(path,next++)};for(let root of roots)visit(root);return order}function importResolver(rootDirs,paths){let exists=new Map,isFile=(path)=>{let found=exists.get(path);if(found===void 0)found=statSync(path,{throwIfNoEntry:!1})?.isFile()??!1,exists.set(path,found);return found},fileAt=(target)=>[target,`${target}.ts`,`${target}.d.ts`,`${target}.js`,target.replace(JS_EXTENSION,".$1ts$2"),target.replace(JS_EXTENSION,".d.$1ts"),join4(target,"index.ts"),join4(target,"index.js")].find((path)=>!path.includes(`${sep2}node_modules${sep2}`)&&isFile(path)),throughRootDirs=(target)=>{let from=rootDirs.filter((dir)=>target.startsWith(`${dir}${sep2}`)).sort((a,b)=>b.length-a.length)[0];if(!from)return;let suffix=relative2(from,target);for(let dir of rootDirs){if(dir===from)continue;let found=fileAt(join4(dir,suffix));if(found)return found}return},patterns=Object.entries(paths).map(([key,targets])=>{let star=key.indexOf("*");return{key,star,targets}});return(from,specifier)=>{if(specifier.startsWith(".")){let target=resolve2(dirname3(from),specifier);return fileAt(target)??throughRootDirs(target)}for(let{key,star,targets}of patterns){let rest;if(star===-1){if(specifier!==key)continue;rest=""}else{let prefix=key.slice(0,star),suffix=key.slice(star+1);if(!specifier.startsWith(prefix)||!specifier.endsWith(suffix)||specifier.length<prefix.length+suffix.length)continue;rest=specifier.slice(prefix.length,specifier.length-suffix.length)}for(let target of targets){let found=fileAt(target.replace("*",rest));if(found)return found}}return}}var NON_BINDABLE=`Cannot use 'bind:' with this property. It is declared as non-bindable inside the component.
|
|
241
|
+
`;function withHint(d,svelteMajor){if(d.code==="TS2345"&&d.message.includes("ConstructorOfATypedSvelteComponent"))return{...d,message:`${d.message}
|
|
242
|
+
|
|
243
|
+
Possible causes:
|
|
244
|
+
- You use the instance type of a component where you should use the constructor type
|
|
245
|
+
- Type definitions are missing for this Svelte Component. ${svelteMajor>=5?"":`If you are using Svelte 3.31+, use SvelteComponentTyped to add a definition:
|
|
246
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
247
|
+
class ComponentName extends SvelteComponentTyped<{propertyName: string;}> {}`}`};if(d.code==="TS1184")return{...d,message:`${d.message}
|
|
248
|
+
If this is a declare statement, move it into <script context="module">..</script>`};return d}function nonBindableMessage(message){if(message.startsWith("Type '")&&message.includes("is not assignable to type '")){let at=message.indexOf(`Type '"`)+7,prop=message.slice(at,message.indexOf('"',at));return`${NON_BINDABLE}To mark a property as bindable: 'let { ${prop} = $bindable() } = $props()'`}return`${NON_BINDABLE}To mark a property as bindable: 'let { prop = $bindable() } = $props()'
|
|
249
|
+
|
|
250
|
+
${message}`}var NOTHING_EMITTED={reactive:[],transitions:[],storeDeclarations:[],bindingChecks:[]};function kitMajor(root){try{let path=createRequire2(join4(root,"package.json")).resolve("@sveltejs/kit/package.json"),{version}=JSON.parse(readFileSync3(path,"utf-8"));return Number.parseInt(version,10)}catch{return 0}}function commonDir(paths){let common=paths[0]??sep2;for(let path of paths)while(!`${path}${sep2}`.startsWith(`${common}${sep2}`)&&common!==sep2)common=dirname3(common);return common}async function typecheck2(options={}){let cwd=resolve2(options.cwd??process.cwd()),workspace=resolve2(cwd,options.workspace??"."),project=projectOf({workspace,tsconfig:options.tsconfig,ignore:options.ignore,components:options.components}),outDir=resolve2(cwd,options.outDir??join4("node_modules/.cache/svelte-typecheck",relative2(cwd,workspace))),genDir=join4(outDir,"svelte"),declarations=options.declarations??!0,svelteDir=svelteDirOf(cwd,options.svelte),sources=new Set(options.diagnosticSources??["js","svelte"]),errorsOnly=options.threshold==="error",{version}=JSON.parse(readFileSync3(join4(svelteDir,"package.json"),"utf-8")),svelteMajor=Number(version.split(".")[0]),svelteHtml=svelteMajor===3?join4(outDir,"svelte-html.d.ts"):join4(svelteDir,"svelte-html.d.ts"),checker=options.checker??CHECKERS.find((c)=>checkerCommand(c,workspace)!==void 0),command=checker&&checkerCommand(checker,workspace);if(sources.has("js")&&!(checker&&command))throw Error(`No type checker found: install \`typescript\` (or one of ${CHECKERS.slice(1).join(", ")}), or name one with \`checker\`.`);let started=performance.now(),incremental=options.incremental??!0,previous=incremental?await readFile(join4(outDir,MANIFEST),"utf-8").then((text)=>new Set(JSON.parse(text))).catch(()=>new Set):new Set;if(!incremental)await rm(outDir,{recursive:!0,force:!0});let files=project.components,listedFiles=project.tsconfig?programFiles(project):[...files].sort(byFolder),configDir=options.config?dirname3(resolve2(workspace,options.config)):workspace,configFile=options.config?resolve2(workspace,options.config):void 0,resultPath=join4(outDir,RESULT_CACHE),projectDir=project.tsconfig?dirname3(project.tsconfig):workspace,last=incremental?await readFile(resultPath,"utf-8").then((text)=>JSON.parse(text)).catch(()=>{return}):void 0,runKey=incremental?hash(JSON.stringify([version2,CACHE_FORMAT,version,checker,command?.version,cwd,options,configFingerprint(configDir,configFile),statsOf([...files,...listedFiles,...project.configFiles,...project.rootDirs.flatMap((dir)=>`${projectDir}${sep2}`.startsWith(`${dir}${sep2}`)||outDir.startsWith(`${dir}${sep2}`)||!existsSync3(dir)?[]:glob(dir,["**/*"]).map((rel)=>join4(dir,rel))),...packageFilesOf(projectDir)])])):"";if(last?.key===runKey&&Array.isArray(last.inputs)&&hash(JSON.stringify(statsOf(last.inputs)))===last.inputsKey)return{...last.result,timings:{emit:0,check:0,compile:0}};let texts=await Promise.all(files.map((path)=>readFile(path,"utf-8"))),root=commonDir([project.tsconfig?dirname3(project.tsconfig):workspace,...files.map((file)=>dirname3(file))]),cachePath=join4(outDir,COMPILE_CACHE),fingerprint=hash(JSON.stringify([version2,CACHE_FORMAT,version,configFingerprint(configDir,configFile)])),cache=incremental?await readFile(cachePath,"utf-8").then((text)=>JSON.parse(text)).then((c)=>c.fingerprint===fingerprint?c:void 0).catch(()=>{return})??{fingerprint,entries:{}}:{fingerprint,entries:{}},keys=files.map((path,i)=>hash(`${relative2(cwd,path)}\x00${texts[i]??""}`)),missing=sources.has("svelte")?files.map((_,i)=>i).filter((i)=>cache.entries[keys[i]??""]===void 0):[],compileRequest={svelteDir,configDir,configFile,components:missing.map((i)=>({source:texts[i]??"",filename:relative2(cwd,files[i]??"")}))},compilingOffThread=missing.length>=OFF_THREAD_AT&&sources.has("js")?compileOffThread(compileRequest):void 0;compilingOffThread?.catch(()=>{});let outputs=new Map,writes=[],written=new Set,generated=new Map,folders=new Map,folder=(dir)=>{let made=folders.get(dir);if(!made)made=mkdir(dir,{recursive:!0}),folders.set(dir,made);return made},write=(path,content)=>{written.add(path),generated.set(path,content),writes.push((incremental?readFile(path,"utf-8").catch(()=>{return}):Promise.resolve(void 0)).then(async(old)=>{if(old===content)return;await folder(dirname3(path)),await writeFile(path,content)}))},failed=[],parseErrors=[],under=(path,dir)=>path.startsWith(`${dir}${sep2}`),tsconfig=join4(outDir,"tsconfig.json"),fileFacts=await factsCache(join4(outDir,FACTS_CACHE),incremental),untypedImports=(()=>{if(!(sources.has("js")&&project.tsconfig&&!project.allowJs))return[];let untyped=new Set(files.filter((path,i)=>!TS_SCRIPT.test(texts[i]??"")&&!existsSync3(`${path}.d.ts`)));if(untyped.size===0)return[];let resolvePath=importResolver([root,...project.rootDirs],project.paths),resolveSelf=importResolver([],project.selfExports);return[...files.filter((_,i)=>TS_SCRIPT.test(texts[i]??"")),...listedFiles.filter((path)=>TS_MODULE.test(path))].flatMap((path)=>fileFacts.of(path,"svelteImports",(content)=>svelteImportsOf(content,path.endsWith(".svelte"))).flatMap((i)=>{let target=resolvePath(path,i.specifier)??resolveSelf(path,i.specifier);return target&&untyped.has(target)?[{...i,path,target}]:[]}))})();if(sources.has("js")){let[{emit},{isKitFile,isKitRouteFile,kitFile}]=await Promise.all([import("./shared-g75sf85w.js"),import("./shared-xcpj2ac7.js")]),emitCachePath=join4(outDir,EMIT_CACHE),emitFingerprint=hash(JSON.stringify([version2,CACHE_FORMAT,svelteMajor,project.checkJs,project.allowJs,declarations,root,genDir])),emitCache=(incremental?await readFile(emitCachePath,"utf-8").then((text)=>JSON.parse(text)).then((c)=>c.fingerprint===emitFingerprint?c:void 0).catch(()=>{return}):void 0)??{fingerprint:emitFingerprint,entries:{}},nextEmitCache={fingerprint:emitFingerprint,entries:{}},emitFor=(i)=>{let path=files[i]??"",genFrom=join4(genDir,relative2(root,dirname3(path)));return emit(texts[i]??"",{svelte:svelteMajor,basename:basename2(path),checkJs:project.checkJs,rewriteImport(specifier){if(!specifier.startsWith("."))return;let target=resolve2(dirname3(path),specifier);if(target.startsWith(`${root}${sep2}`))return;return relativeTo(genFrom,target)}})},lazyOutput=(i,lang)=>{let result,get=()=>(result??=emitFor(i),result);return{source:texts[i]??"",svelte:files[i]??"",isTs:lang==="ts",get output(){return get().out},get emitted(){return get()}}};for(let[i,path]of files.entries()){let genFrom=join4(genDir,relative2(root,dirname3(path))),name=path.slice(path.lastIndexOf(sep2)+1,-7),typed=declarations&&!existsSync3(`${path}.d.ts`),key=hash(`${path}\x00${typed}\x00${texts[i]??""}`),cached=emitCache.entries[key];if(cached&&(!cached.genPath||existsSync3(cached.genPath))){for(let file of cached.files)written.add(file);if(parseErrors.push(...cached.diagnostics),cached.genPath&&cached.lang)outputs.set(cached.genPath,lazyOutput(i,cached.lang));nextEmitCache.entries[key]=cached;continue}let effects={files:[],diagnostics:[]};nextEmitCache.entries[key]=effects;let put=(file,content)=>{effects.files.push(file),write(file,content)},result;try{result=emitFor(i)}catch(error){let e=error;if(!e.start){failed.push({file:path,message:e.message}),delete nextEmitCache.entries[key];continue}let isTs=TS_SCRIPT.test(texts[i]??"");effects.diagnostics.push({file:path,line:e.start.line,column:e.start.column+1,endLine:e.start.line,endColumn:e.start.column+1,severity:"error",source:isTs?"ts":"js",code:"-1",message:e.message});let lexed=lexComponent2(texts[i]??""),stub=[lexed.instance,lexed.module].some((script)=>script&&lexImportsExports((texts[i]??"").slice(script.content.start,script.content.end)).length>0)?`export {};
|
|
251
|
+
`:"";if(put(join4(genFrom,`++${name}.svelte.${isTs?"ts":"js"}`),stub),declarations)put(join4(genFrom,`${name}.d.svelte.ts`),stub);parseErrors.push(...effects.diagnostics);continue}let locate=createLocator(texts[i]??"");for(let t of result.tsInJs){let at=locate.position(t.at);effects.diagnostics.push({file:path,line:at.line,column:at.column,severity:"error",source:"js",code:t.code,message:t.message})}if(parseErrors.push(...effects.diagnostics),result.lang==="js"&&!project.allowJs)continue;let genPath=join4(genFrom,`++${name}.svelte.${result.isTs?"ts":"js"}`);if(effects.genPath=genPath,effects.lang=result.lang==="ts"?"ts":"js",outputs.set(genPath,{output:result.out,source:texts[i]??"",svelte:path,isTs:result.lang==="ts",emitted:result}),put(genPath,result.out.code),typed)put(join4(genFrom,`${name}.d.svelte.ts`),`export { default } from "./++${name}.svelte.js";
|
|
252
|
+
export * from "./++${name}.svelte.js";
|
|
253
|
+
`)}if(incremental)write(emitCachePath,JSON.stringify(nextEmitCache));let untypedNames=new Map;for(let i of untypedImports){let names=untypedNames.get(i.target)??new Set;for(let name of i.names)names.add(name);untypedNames.set(i.target,names)}let untypedDeclarationOf=(target)=>join4(genDir,relative2(root,dirname3(target)),`${basename2(target,".svelte")}.d.svelte.ts`);if(declarations)for(let[target,names]of untypedNames)write(untypedDeclarationOf(target),untypedDeclaration(names));let mirror=(path)=>join4(genDir,relative2(root,path)),kitProject=project.tsconfig!==void 0&&(project.rootDirs.some((dir)=>dir.includes(".svelte-kit"))||files.some((path)=>isKitRouteFile(basename2(path)))),replaced=[];if(kitProject){let hooksModule=kitMajor(root)>=3?"@sveltejs/kit/hooks":"@sveltejs/kit";for(let path of scriptsOf(project,isKitFile)){if(!under(path,root))continue;let source=readFileSync3(path,"utf-8"),output=kitFile(path,source,hooksModule);if(!output)continue;replaced.push(path),outputs.set(mirror(path),{output,source,svelte:path,isTs:!JS_FILE2.test(path),emitted:NOTHING_EMITTED,kit:!0}),write(mirror(path),output.code)}}let rootDirs=[];for(let dir of project.rootDirs){if(dir===root||under(dir,outDir))continue;if(!(kitProject&&under(dir,root)&&existsSync3(dir))){rootDirs.push(dir);continue}replaced.push(dir),rootDirs.push(mirror(dir));for(let file of glob(dir,["**/*.{ts,js}"]))write(mirror(join4(dir,file)),readFileSync3(join4(dir,file),"utf-8"))}let paths=Object.fromEntries(Object.entries(project.paths).map(([key,targets])=>[key,targets.flatMap((t)=>under(t,root)?[mirror(t),t]:[t])]));if(declarations){for(let i of untypedImports)if(!i.specifier.startsWith("."))paths[i.specifier]=[untypedDeclarationOf(i.target)]}let shims=join4(outDir,"shims.d.ts");if(write(shims,shim("shims.d.ts")),svelteMajor===3)write(svelteHtml,shim("svelte3-elements.d.ts"));let rel=(path)=>relativeTo(outDir,path),generatedFor=new Map([...outputs].map(([genPath,gen])=>[gen.svelte,genPath])),replacedSet=new Set(replaced),rootFiles=[...new Set([...listedFiles.filter((path)=>path.endsWith(".svelte")).map((path)=>generatedFor.get(path)).filter((path)=>path!==void 0),...[...outputs].filter(([,gen])=>!gen.kit).map(([genPath])=>genPath),...listedFiles.filter((path)=>!path.endsWith(".svelte")).map((path)=>{if(replacedSet.has(path))return generatedFor.get(path);return replaced.find((d)=>under(path,d))?mirror(path):path}).filter((path)=>path!==void 0)])];write(tsconfig,JSON.stringify({...project.tsconfig?{extends:rel(project.tsconfig)}:{},compilerOptions:{...project.tsconfig?{}:DEFAULT_COMPILER_OPTIONS,rootDirs:[rel(root),"svelte",...rootDirs.map(rel)],...Object.keys(paths).length>0?{paths:Object.fromEntries(Object.entries(paths).map(([key,targets])=>[key,targets.map(rel)]))}:{},allowArbitraryExtensions:!0,noEmit:!0,composite:!1,incremental,...incremental?{tsBuildInfoFile:"./tsbuildinfo"}:{}},files:[...rootFiles,shims,svelteHtml,...svelteMajor>=5?[join4(svelteDir,"types/index.d.ts")]:[]].map(rel),include:[]},null,2)),write(join4(outDir,MANIFEST),JSON.stringify([...written].sort()));for(let path of previous)if(!written.has(path))writes.push(rm(path,{force:!0}))}if(await Promise.all(writes),incremental)await mkdir(outDir,{recursive:!0});let emitted=performance.now(),checking=checker&&command&&sources.has("js")?run(command.command,[...command.prefix,...checkerArgs(checker,tsconfig)],cwd,command.shell).then((output)=>({output,at:performance.now()})):Promise.resolve({output:"",at:emitted}),compiled=[],perFile=[];if(sources.has("svelte")){if(missing.length>0){let fresh=await compilingOffThread??await compileAll(compileRequest);for(let[n,i]of missing.entries())cache.entries[keys[i]??""]=fresh[n]??[]}for(let key of keys)perFile.push(cache.entries[key]??[]);if(incremental){let kept=Object.fromEntries(keys.map((key)=>[key,cache.entries[key]??[]]));await writeFile(cachePath,JSON.stringify({fingerprint,entries:kept}))}}for(let[i,path]of files.entries())for(let d of perFile[i]??[]){let level=options.compilerWarnings?.[d.code];if(d.severity==="warning"&&level==="ignore")continue;compiled.push({file:path,...d,severity:level==="error"?"error":d.severity,source:"svelte"})}let compiledAt=performance.now(),{output:text,at:checked}=await checking,raw=parseDiagnostics(text),inOutput=(file)=>resolve2(cwd,file).startsWith(`${outDir}${sep2}`),syntax=raw.some((d)=>TYPE_CODE.test(d.code))?[]:raw.filter((d)=>inOutput(d.file)&&SYNTAX_CODE.test(d.code)&&!outputs.get(resolve2(cwd,d.file))?.kit);if(syntax.length>0||STOPPED.test(text))throw new EmitError(`Generated code has syntax errors:
|
|
254
|
+
${syntax.slice(0,20).map((d)=>`${d.file}(${d.line},${d.column}): ${d.code} ${d.message}`).join(`
|
|
255
|
+
`)}`);let locators=new Map,locator=(key,content)=>{let found=locators.get(key);if(!found)found=createLocator(content()),locators.set(key,found);return found},endOf=(source,offset,file)=>{let length=TOKEN.exec(source.slice(offset))?.[0].length??0,end=locator(file,()=>source).position(offset+length);return{endLine:end.line,endColumn:end.column}},diagnostics=[],dropped=[],storeErrors=[],seen=new Set;for(let d of raw){if(d.file===""){if(d.message.includes(outDir))throw new EmitError(`${d.code}: ${d.message}`);diagnostics.push({...d,file:project.tsconfig??workspace,severity:"error",source:"ts"});continue}let abs=resolve2(cwd,d.file),gen=outputs.get(abs),mapped;if(gen){let offset=locator(abs,()=>gen.output.code).offset(d.line,d.column),source=gen.output.toSource(offset);if(source===null){let store=STORE_ERROR.test(d.code)?gen.emitted.storeDeclarations.find((s)=>s.start<=offset&&offset<s.end):void 0;if(store){for(let use of store.uses){let at=locator(gen.svelte,()=>gen.source).position(use),end=locator(gen.svelte,()=>gen.source).position(use+store.name.length+1);storeErrors.push({...d,file:gen.svelte,line:at.line,column:at.column,endLine:end.line,endColumn:end.column,severity:"error",source:gen.isTs?"ts":"js",message:`Cannot use '${store.name}' as a store. '${store.name}' needs to be an object with a subscribe method on it.
|
|
256
|
+
|
|
257
|
+
${d.message}`})}continue}let binding=d.code==="TS2322"?gen.emitted.bindingChecks.find((b)=>b.start<=offset&&offset<b.end):void 0;if(binding){let at=locator(gen.svelte,()=>gen.source).position(binding.from),end=locator(gen.svelte,()=>gen.source).position(binding.to);diagnostics.push({...d,file:gen.svelte,line:at.line,column:at.column,endLine:end.line,endColumn:end.column,severity:"error",source:gen.isTs?"ts":"js",message:nonBindableMessage(d.message)});continue}dropped.push({...d,file:abs,severity:"error",source:"ts"});continue}let within=(ranges)=>ranges.some(([from,to])=>from<=source&&source<to);if(REACTIVE_NOISE.test(d.code)&&within(gen.emitted.reactive)||d.code==="TS2554"&&d.message.startsWith("Expected 3 arguments")&&within(gen.emitted.transitions))continue;let start=locator(gen.svelte,()=>gen.source).position(source);mapped=withHint({...d,file:gen.svelte,line:start.line,column:start.column,...endOf(gen.source,source,gen.svelte),severity:"error",source:gen.isTs?"ts":"js"},svelteMajor)}else if(inOutput(d.file)||!project.reports(abs)){if(inOutput(d.file))dropped.push({...d,file:abs,severity:"error",source:"ts"});continue}else{let content=readFileSync3(abs,"utf-8"),offset=locator(abs,()=>content).offset(d.line,d.column);mapped={...d,file:abs,...endOf(content,offset,abs),severity:"error",source:JS_FILE2.test(abs)?"js":"ts"}}let key=`${mapped.file}:${mapped.line}:${mapped.column}:${mapped.code}`;if(seen.has(key))continue;seen.add(key),diagnostics.push(mapped)}diagnostics.push(...storeErrors);let generatedPath=new RegExp(`${escapeRegExp(`${toPosix2(genDir)}/`)}[^"'\\s]*`,"gi");for(let d of diagnostics)if(d.message=d.message.replace(generatedPath,(path)=>asTypeScriptPath(join4(root,relative2(toPosix2(genDir),path)).replace(GENERATED_NAME,"$1.svelte"))),process.platform==="win32")d.message=d.message.replace(DRIVE_PATH,(drive)=>drive.toLowerCase());if(diagnostics.push(...compiled),sources.has("js"))diagnostics.push(...parseErrors);if(untypedImports.length>0){let expected=new Set,untypedErrors=[];for(let i of untypedImports){if(project.skipLibCheck&&DECLARATION_FILE.test(i.path))continue;if(i.directive){if(i.directive==="expect-error")expected.add(`${i.path}:${i.line-1}`);continue}untypedErrors.push({file:i.path,line:i.line,column:i.column,severity:"error",source:"ts",code:"TS7016",message:`Could not find a declaration file for module '${i.specifier}'. '${asTypeScriptPath(i.target)}' implicitly has an 'any' type.`})}if(diagnostics.unshift(...untypedErrors),expected.size>0){let kept=diagnostics.filter((d)=>!(d.code==="TS2578"&&expected.has(`${d.file}:${d.line}`)));diagnostics.length=0,diagnostics.push(...kept)}}if(project.tsconfig&&project.inputSpecs&&listedFiles.length===0)diagnostics.push({file:project.tsconfig,line:1,column:1,severity:"error",source:"ts",code:"TS18003",message:`No inputs were found in config file '${asTypeScriptPath(project.tsconfig)}'. Specified 'include' paths were '${JSON.stringify(project.inputSpecs.include)}' and 'exclude' paths were '${JSON.stringify(project.inputSpecs.exclude)}'.`});else if(project.tsconfig&&!options.components&&files.length===0)diagnostics.push({file:project.tsconfig,line:1,column:1,endLine:1,endColumn:1,severity:"warning",source:"svelte",code:"100001",message:`No svelte input files were found in config file '${asTypeScriptPath(project.tsconfig)}'. Did you forget to add svelte files to the 'include' in your ${basename2(project.tsconfig)}? Specified 'include' paths were '${JSON.stringify(project.raw.include)}' and 'exclude' paths were '${JSON.stringify(project.raw.exclude)}'`});let reported=errorsOnly?diagnostics.filter((d)=>d.severity==="error"):diagnostics,generatedOf=new Map([...outputs].map(([genPath,gen])=>[gen.svelte,genPath])),listed=listedFiles,listedSet=new Set(listed),imports=new Map,order=programOrder([...listed,...[...new Set(reported.map((d)=>d.file))].filter((file)=>!listedSet.has(file)).sort(byFolder)],(file)=>{let path=generatedOf.get(file)??file;return fileFacts.of(path,"specifiers",(code)=>[...code.matchAll(STATIC_IMPORT),...code.matchAll(DYNAMIC_IMPORT)].map((m)=>m[1]??""),generated.get(path))},importResolver([root,...project.rootDirs],project.paths),imports),skipped=0;if(options.only){let shown=new Set(options.only.map((path)=>resolve2(cwd,path)));for(let[file,targets]of imports)for(let target of targets)if(options.only.some((path)=>resolve2(cwd,path)===target))shown.add(file);let kept=reported.filter((d)=>shown.has(d.file));skipped=reported.length-kept.length,reported.length=0,reported.push(...kept)}let sourceRank=(d)=>d.source==="svelte"?0:1;reported.sort((a,b)=>(order.get(a.file)??0)-(order.get(b.file)??0)||sourceRank(a)-sourceRank(b));let result={diagnostics:reported,workspace,tsconfig:project.tsconfig,components:files.length,skipped,dropped,failed,checker,checkerVersion:command?.version,timings:{emit:emitted-started,check:checked-emitted,compile:compiledAt-emitted}},inputs=[...order.keys()].filter((path)=>!under(path,outDir)).flatMap((path)=>[path,...declarationsBeside(path)]);if(incremental)await fileFacts.save();if(incremental)await writeFile(resultPath,JSON.stringify({key:runKey,inputs,inputsKey:hash(JSON.stringify(statsOf(inputs))),result}));return result}var FACTS_CACHE="files.json";function svelteImportsOf(content,component){if(!content.includes(".svelte"))return[];let lexed=component?lexComponent2(content):void 0,ranges=lexed?[lexed.module,lexed.instance].flatMap((script)=>script?[[script.content.start,script.content.end]]:[]):[[0,content.length]],locate=createLocator(content),lines=content.split(`
|
|
258
|
+
`);return ranges.flatMap(([start,end])=>lexImportsExports(content.slice(start,end)).flatMap((statement)=>{let specifier=statement.source?.value;if(!specifier?.endsWith(".svelte"))return[];let at=locate.position(start+(statement.source?.start??0)),directive=TS_DIRECTIVE.exec(lines[at.line-2]??"")?.[1];return[{specifier,line:at.line,column:at.column,directive:directive==="ignore"||directive==="expect-error"?directive:null,names:statement.specifiers.flatMap((spec)=>{let name="imported"in spec?spec.imported:spec.local;return name==="*"?[]:[name]})}]}))}function untypedDeclaration(names){let declare=(name)=>`declare const ${name}: any;
|
|
259
|
+
type ${name}<${UNTYPED_PARAMS}> = any & [${UNTYPED_ARGS}];
|
|
260
|
+
`,named=[...names].filter((name)=>name!=="default"&&IDENTIFIER.test(name));return`${[UNTYPED,...named].map(declare).join("")}export default ${UNTYPED};
|
|
261
|
+
${named.length>0?`export { ${named.join(", ")} };
|
|
262
|
+
`:""}`}var UNTYPED="$$untyped",UNTYPED_ARGS="A, B, C, D, E, F, G, H",UNTYPED_PARAMS=UNTYPED_ARGS.split(", ").map((p)=>`${p} = any`).join(", ");async function factsCache(path,enabled){let entries=enabled?await readFile(path,"utf-8").then((text)=>{let cache=JSON.parse(text);return cache.format===CACHE_FORMAT?cache.entries:{}}).catch(()=>({})):{},used={};return{of(file,kind,compute,text){let stat=statsOf([file])[0]??"",facts=used[file]??entries[file];if(facts?.stat!==stat)facts={stat};return used[file]=facts,facts[kind]??=compute(text??readFileSync3(file,"utf-8")),facts[kind]},save:()=>writeFile(path,JSON.stringify({format:CACHE_FORMAT,entries:used}))}}function declarationsBeside(path){return JS_EXTENSION.test(path)?[path.replace(JS_EXTENSION,".d.$1ts")]:[]}function statsOf(paths){return paths.map((path)=>{let stat=statSync(path,{throwIfNoEntry:!1});return stat?`${path}:${stat.size}:${stat.mtimeMs}`:`${path}:-`})}var PACKAGE_FILES=["package.json","bun.lock","bun.lockb","package-lock.json","pnpm-lock.yaml","yarn.lock"];function packageFilesOf(dir){let found=[];for(let at=dir;;at=dirname3(at))if(found.push(...PACKAGE_FILES.map((name)=>join4(at,name))),dirname3(at)===at)return found}import{watch as watchFiles}from"node:fs";import{resolve as resolve3,sep as sep3}from"node:path";var WATCHED=/\.(?:svelte|[cm]?[jt]sx?|json)$/,DEBOUNCE_MS=100;function watch2(options,onResult){let cwd=resolve3(options.cwd??process.cwd()),workspace=resolve3(cwd,options.workspace??"."),run={...options,cwd,incremental:!0},timer,running=!1,again=!1,check=async()=>{if(running){again=!0;return}running=!0;try{onResult(await typecheck2(run))}catch(error){onResult(error)}if(running=!1,again)again=!1,await check()},ignored=(path)=>path.split(sep3).some((part)=>part==="node_modules"||part.startsWith(".")),watcher=watchFiles(workspace,{recursive:!0},(_,filename)=>{if(!filename||ignored(filename)||!WATCHED.test(filename))return;clearTimeout(timer),timer=setTimeout(check,DEBOUNCE_MS)});return check(),()=>{clearTimeout(timer),watcher.close()}}import{readFileSync as readFileSync4}from"node:fs";import{relative as relative3,sep as sep4}from"node:path";var LINE_BREAK2=/\r?\n/;function keyer(workspace){let lines=new Map,lineOf=(d)=>{let text=lines.get(d.file);if(!text){try{text=readFileSync4(d.file,"utf-8").split(LINE_BREAK2)}catch{text=[]}lines.set(d.file,text)}return(text[d.line-1]??"").trim()},prefix=`${workspace}${sep4}`;return(d)=>({file:relative3(workspace,d.file).split(sep4).join("/"),code:d.code,message:d.message.replaceAll(prefix,""),line:lineOf(d)})}var keyOf=(e)=>JSON.stringify([e.file,e.code,e.message,e.line]);function createBaseline2(diagnostics,workspace){let toEntry=keyer(workspace),entries=new Map;for(let d of diagnostics){let entry=toEntry(d),key=keyOf(entry),found=entries.get(key);if(found)found.count++;else entries.set(key,{...entry,count:1})}return{version:1,diagnostics:[...entries.entries()].sort(([a],[b])=>a<b?-1:Number(a>b)).map(([,entry])=>entry)}}function applyBaseline2(diagnostics,baseline,workspace){let toEntry=keyer(workspace),left=new Map(baseline.diagnostics.map((e)=>[keyOf(e),e.count])),fresh=[],known=0;for(let d of diagnostics){let key=keyOf(toEntry(d)),count=left.get(key)??0;if(count>0)left.set(key,count-1),known++;else fresh.push(d)}let fixed=0;for(let count of left.values())fixed+=count;return{diagnostics:fresh,known,fixed}}
|
|
263
|
+
export{EmitError,typecheck2,watch2,createBaseline2,applyBaseline2};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isKitRouteFile2,isKitErrorFile2,isKitFile2,kitFile2,kitPropType2,kitRuneProp2}from"./shared-ebbnnbmn.js";export{isKitErrorFile2 as isKitErrorFile,isKitFile2 as isKitFile,isKitRouteFile2 as isKitRouteFile,kitFile2 as kitFile,kitPropType2 as kitPropType,kitRuneProp2 as kitRuneProp};
|
package/shared-2xseck5b.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{version2,package_default}from"./shared-ky3xz37f.js";export{package_default as default,version2 as version};
|
package/shared-ky3xz37f.js
DELETED