svelte-typecheck 0.1.5 → 0.1.6
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 +4 -1
- package/cli.js +2 -2
- package/index.d.ts +5 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/shared-2xseck5b.js +1 -0
- package/shared-ky3xz37f.js +2 -0
- package/{shared-0bqrrt0s.js → shared-rv2wrjaa.js} +276 -32
- package/shared-hmmvdprg.js +0 -1
- package/shared-zgnhwdjy.js +0 -2
- package/shims/shims.d.ts +0 -426
- package/shims/svelte3-elements.d.ts +0 -1651
package/README.md
CHANGED
|
@@ -129,8 +129,11 @@ What svelte-typecheck does that svelte-check doesn't:
|
|
|
129
129
|
- **`--tsgo-experimental-api`** is accepted, and does what `--tsgo` does.
|
|
130
130
|
- **tsconfig option errors** that only matter to an emitting build, such as a JS file that `tsc` would overwrite, aren't reported: the checker runs with `noEmit`.
|
|
131
131
|
- **A union's members** can print in another order, as TypeScript orders them by when it first meets each type: `Element | Document` where svelte-check has `Document | Element`.
|
|
132
|
+
The same order picks what a generic call infers from a union: `render(cond ? A : B, …)` with two components can be an error in one tool and not the other, as each checks its files, and so meets the types, in its own order.
|
|
132
133
|
- **A syntax error in a TS or JS file** stops `tsc` and the other CLI checkers from type-checking at all, so only syntax errors are reported until it's fixed; svelte-check's language service reports the type errors in other files too. A component's syntax errors don't do this.
|
|
133
134
|
- **Svelte 3 and 4 with `lang="ts"` and no preprocessors**: svelte-check strips the types with a fallback preprocessor and reports the compiler's warnings; here the compiler can't read the script, so there are none.
|
|
135
|
+
- **Svelte 3's element types** are Svelte 4's, read from the project's `svelte/elements`, without svelte2tsx's deprecated `svelte.JSX` namespace: a project that augments or references `svelte.JSX` should move to `svelteHTML` or `svelte/elements`. An ARIA attribute's type prints as `Booleanish` where svelte-check spells out `boolean | "true" | "false"`.
|
|
136
|
+
- **Slot content for a Svelte 5 component without a `children` prop** is reported at the tag's name. svelte-check places the error where svelte2tsx's text rewriting happens to anchor its inserted `children`: an attribute's opening quote, the start of a line, or after an attribute.
|
|
134
137
|
- **`--out-dir` outside the project** can't find its packages from the generated code; the default is inside `node_modules`.
|
|
135
138
|
- **`<svelte:element this={tag}>` whose tag may be any element**, such as a component's generic `Tag extends keyof HTMLElementTagNameMap`: svelte-check reports TypeScript's "union type too complex" and checks none of the element's attributes; here its attributes are checked as an element's. An attribute error on it names the attributes' type with the tag widened: `keyof HTMLElementTagNameMap extends Tag ? string : Tag`.
|
|
136
139
|
|
|
@@ -196,7 +199,7 @@ Any version works as long as it reads a tsconfig and prints `tsc`'s format: to p
|
|
|
196
199
|
|
|
197
200
|
1. **Find the project.** The tsconfig svelte-check would use (the nearer of tsconfig.json and jsconfig.json from the workspace up), and the components its `include` names.
|
|
198
201
|
2. **Parse.** [sveast](https://github.com/metonym/sveast) parses each component and resolves its scopes: props, `$:` declarations, runes, stores, `{#each}`, `let:` and snippet scopes, every read and write.
|
|
199
|
-
3. **Generate.** Each component becomes TypeScript (or JS with JSDoc) the way svelte2tsx writes it, with a map from each piece back to its source. The code, the helper types it calls
|
|
202
|
+
3. **Generate.** Each component becomes TypeScript (or JS with JSDoc) the way svelte2tsx writes it, with a map from each piece back to its source. The code, the helper types it calls and a tsconfig that extends yours go to `node_modules/.cache/svelte-typecheck`. The helpers are svelte-typecheck's own, except the few names a message prints, which keep svelte2tsx's (MIT) so messages read as svelte-check's do.
|
|
200
203
|
4. **Check and compile, at once.** One checker process type-checks the whole program while Svelte's compiler reports its warnings beside it.
|
|
201
204
|
5. **Map and order.** Each error maps back to its `.svelte` line, with svelte-check's rewrites and filters, in the order svelte-check prints them.
|
|
202
205
|
6. **Keep.** What each step learned is kept for the next run.
|
package/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import"./shared-
|
|
2
|
+
import"./shared-ky3xz37f.js";import{EmitError,typecheck2,watch2,createBaseline2,applyBaseline2}from"./shared-rv2wrjaa.js";import{readFileSync as readFileSync2,writeFileSync}from"node:fs";import{resolve}from"node:path";import{parseArgs}from"node:util";import{readFileSync}from"node:fs";import{relative,sep}from"node:path";var OUTPUT_FORMATS=["human","human-verbose","machine","machine-verbose"];function colors(force){let env=process.env,enabled=force??(env.FORCE_COLOR!==void 0?env.FORCE_COLOR!=="0":env.NO_COLOR===void 0&&Boolean(process.stdout.isTTY)&&env.TERM!=="dumb"),paint=(open,close)=>(text)=>enabled?`\x1B[${open}m${text}\x1B[${close}m`:text;return{red:paint(31,39),yellow:paint(33,39),green:paint(32,39),cyan:paint(36,39),magenta:paint(35,39)}}function lineOf(text,line){return text.split(`
|
|
3
3
|
`)[line-1]??""}function codeFrame(d,c){let text;try{text=readFileSync(d.file,"utf-8")}catch{return""}let endLine=d.endLine??d.line,endColumn=d.endColumn??d.column,first=lineOf(text,d.line),last=lineOf(text,endLine),middle=d.line===endLine?first.slice(0,d.column-1)+c.magenta(first.slice(d.column-1,endColumn-1))+first.slice(endColumn-1):first.slice(0,d.column-1)+c.magenta([first.slice(d.column-1),...text.split(`
|
|
4
4
|
`).slice(d.line,endLine-1),last.slice(0,endColumn-1)].join(`
|
|
5
5
|
`))+last.slice(endColumn-1),before=d.line>1?`${lineOf(text,d.line-1)}
|
|
@@ -70,6 +70,6 @@ svelte-typecheck's own:
|
|
|
70
70
|
|
|
71
71
|
Exits 1 on an error, or a warning with --fail-on-warnings.`;async function main(argv){let values;try{values=parse(argv).values}catch(error){return console.error(`${error.message}
|
|
72
72
|
|
|
73
|
-
${HELP}`),1}if(values.help)return console.log(HELP),0;if(values.version){let{version}=await import("./shared-
|
|
73
|
+
${HELP}`),1}if(values.help)return console.log(HELP),0;if(values.version){let{version}=await import("./shared-2xseck5b.js");return console.log(version),0}let format=formatOf(values.output),out=writer(format,(text)=>process.stdout.write(text),colors(colorFlag(values.color,values["no-color"]))),options={workspace:values.workspace??".",tsconfig:values["no-tsconfig"]?!1:values.tsconfig,ignore:values.ignore?.split(","),config:values.config,checker:values.checker??(values.tsgo||values["tsgo-experimental-api"]?"tsgo":void 0),components:values.components,outDir:values["out-dir"],declarations:!values["no-declarations"],svelte:values.svelte,diagnosticSources:values["diagnostic-sources"]?.split(",").map((source)=>source.trim()),compilerWarnings:parseCompilerWarnings(values["compiler-warnings"]),incremental:!values["no-incremental"]};if(values.changed||values.since)try{options.only=changedFiles(process.cwd(),values.since)}catch(error){return out.failure(error),1}let baselinePath=values.baseline&&resolve(values.baseline);if(values["update-baseline"]&&!baselinePath)return out.failure(Error("--update-baseline needs --baseline <file>")),1;let strict=values["strict-baseline"];if(strict&&!baselinePath)return out.failure(Error("--strict-baseline needs --baseline <file>")),1;for(let flag of["update-baseline","strict-baseline"])if(values[flag]&&(values.changed||values.since))return out.failure(Error(`--${flag} takes every file's: drop --changed`)),1;let baseline;if(baselinePath&&!values["update-baseline"])try{baseline=JSON.parse(readFileSync2(baselinePath,"utf-8"))}catch{return out.failure(Error(`No baseline at ${baselinePath}: write one with --update-baseline`)),1}let errorsOnly=values.threshold==="error",failOnWarnings=values["fail-on-warnings"],report=(result,watching)=>{if(result instanceof Error)return out.failure(result instanceof EmitError?Error(`${result.message}
|
|
74
74
|
This is a svelte-typecheck bug; please report it.`):result),1;if(baselinePath&&values["update-baseline"]){let written=createBaseline2(result.diagnostics,result.workspace);return writeFileSync(baselinePath,`${JSON.stringify(written,null,2)}
|
|
75
75
|
`),out.note(`Wrote ${result.diagnostics.length} diagnostics to ${baselinePath}`),0}let known=baseline?applyBaseline2(result.diagnostics,baseline,result.workspace):void 0,shown=known?known.diagnostics:result.diagnostics;out.start(result.workspace,watching&&!values.preserveWatchOutput);for(let d of shown)if(!errorsOnly||d.severity==="error")out.diagnostic(d,result.workspace);for(let f of result.failed)out.failure(Error(`${f.file}: failed to parse: ${f.message}`));let summary=summarize(shown,result.components);if(known?.known)out.note(`${known.known} more in the baseline, not shown`);if(known?.fixed)out.note(`${known.fixed} in the baseline are fixed: --update-baseline drops them`);if(result.skipped>0)out.note(`${result.skipped} more in files the changes don't reach, not shown`);return out.completion(summary,watching),summary.errors>0||result.failed.length>0||failOnWarnings&&summary.warnings>0||strict&&(known?.fixed??0)>0?1:0};if(values.watch)return watch2(options,(result)=>report(result,!0)),new Promise(()=>{});try{return report(await typecheck2(options),!1)}catch(error){return report(error,!1)}}function formatOf(output){if(output&&OUTPUT_FORMATS.includes(output))return output;return process.env.CLAUDECODE==="1"?"machine":"human-verbose"}function parse(argv){return parseArgs({args:argv,options:{workspace:{type:"string"},output:{type:"string"},tsconfig:{type:"string"},"no-tsconfig":{type:"boolean",default:!1},ignore:{type:"string"},config:{type:"string"},"diagnostic-sources":{type:"string"},threshold:{type:"string"},"compiler-warnings":{type:"string"},"fail-on-warnings":{type:"boolean",default:!1},color:{type:"boolean",default:!1},"no-color":{type:"boolean",default:!1},tsgo:{type:"boolean",default:!1},incremental:{type:"boolean",default:!1},"no-incremental":{type:"boolean",default:!1},watch:{type:"boolean",default:!1},preserveWatchOutput:{type:"boolean",default:!1},"tsgo-experimental-api":{type:"boolean",default:!1},checker:{type:"string"},components:{type:"string",multiple:!0},"out-dir":{type:"string"},"no-declarations":{type:"boolean",default:!1},svelte:{type:"string"},changed:{type:"boolean",default:!1},baseline:{type:"string"},"update-baseline":{type:"boolean",default:!1},"strict-baseline":{type:"boolean",default:!1},since:{type:"string"},help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",short:"v",default:!1}}})}function parseCompilerWarnings(list){if(!list)return;let levels={};for(let entry of list.split(",")){let[code,level]=entry.trim().split(":");if(code&&(level==="ignore"||level==="error"))levels[code]=level}return levels}function colorFlag(on,off){if(on)return!0;if(off)return!1;return}process.exitCode=await main(process.argv.slice(2));
|
package/index.d.ts
CHANGED
|
@@ -99,7 +99,11 @@ export interface TypecheckResult {
|
|
|
99
99
|
dropped: Diagnostic[];
|
|
100
100
|
/** Components that failed to parse. */
|
|
101
101
|
failed: { file: string; message: string }[];
|
|
102
|
-
|
|
102
|
+
/**
|
|
103
|
+
* The checker that ran. Unset when only the compiler's diagnostics were
|
|
104
|
+
* asked for and no checker is installed.
|
|
105
|
+
*/
|
|
106
|
+
checker?: Checker;
|
|
103
107
|
/** The checker's version, when its package says. */
|
|
104
108
|
checkerVersion?: string;
|
|
105
109
|
/** Milliseconds spent emitting, type-checking and compiling. */
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./shared-
|
|
1
|
+
import"./shared-ky3xz37f.js";import{compilerDiagnostics2,typecheck2,watch2,createBaseline2,applyBaseline2}from"./shared-rv2wrjaa.js";export{applyBaseline2 as applyBaseline,compilerDiagnostics2 as compilerDiagnostics,createBaseline2 as createBaseline,typecheck2 as typecheck,watch2 as watch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-typecheck",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "A drop-in svelte-check replacement that checks with tsc, tsgo, tsrs or bun check. Up to 11x faster, zero dependencies.",
|
|
6
6
|
"author": "Eric Liu (https://github.com/metonym)",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{version2,package_default}from"./shared-ky3xz37f.js";export{package_default as default,version2 as version};
|