sveld 0.37.3 → 0.37.4
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 +14 -2
- package/lib/browser.d.ts +32 -4
- package/lib/browser.js +150 -136
- package/lib/chunk-49hdrj4n.js +6 -0
- package/lib/chunk-7e36grhy.js +1 -0
- package/lib/{chunk-m2bfvdte.js → chunk-nxa0q3f3.js} +5 -5
- package/lib/chunk-rftengvg.js +331 -0
- package/lib/chunk-w37f2cq2.js +1 -0
- package/lib/{chunk-s4f6b34h.js → chunk-yzb9k33r.js} +1 -1
- package/lib/cli-entry.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/schema/component-api.schema.json +20 -1
- package/lib/chunk-ag202nwj.js +0 -317
- package/lib/chunk-n14td14g.js +0 -1
- package/lib/chunk-te52wx32.js +0 -1
- package/lib/chunk-v4be4g6y.js +0 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{T,A}from"./chunk-rftengvg.js";export{T as TemplateParseNotImplementedError,A as parse};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{e}from"./chunk-
|
|
1
|
+
import{e}from"./chunk-rftengvg.js";import{existsSync as N,readdirSync as O,readFileSync as D,statSync as j}from"node:fs";import{createRequire as M}from"node:module";import f from"node:path";var F="__sveld_resolved_props__",k="__SveldResolvedProps__",L=/ \| undefined$/,G=/[^A-Za-z0-9_-]/g,U=/[^A-Za-z0-9_$]/g,B=/^[0-9]/,q=2,I=7,E=`TypeScript ${I} or later, which provides \`typescript/unstable/async\``;function z(t){if(!t)return!1;let n=Number.parseInt(t,10);return Number.isFinite(n)&&n>=I}async function X(t){let n;try{let i=M(f.join(t,"package.json")).resolve("typescript/package.json");n=JSON.parse(D(i,"utf8")).version}catch{return{installed:!1}}if(!z(n))return{installed:!0,version:n};try{let s=await import("./chunk-nxa0q3f3.js");return{installed:!0,version:n,module:s}}catch{return{installed:!0,version:n}}}class A{api;symbolFlags;typeFlags;tsconfigPath;cwd;overlay=new Map;pendingOverlayDeletions=new Set;constructor(t,n,s,i,o){this.api=t,this.symbolFlags=n,this.typeFlags=s,this.tsconfigPath=i,this.cwd=o}static async create(t=process.cwd(),{importTs:n=X}={}){let s=await n(t);if(!s.installed)return{ok:!1,reason:"not-installed",message:`requires the \`typescript\` package to be installed (${E}); none was found`};if(!s.module)return{ok:!1,reason:"unsupported-version",message:`requires ${E}; found \`typescript@${s.version??"unknown"}\` installed, which does not expose that module`};let i=Q(t);if(!i)return{ok:!1,reason:"no-tsconfig",message:`could not locate a tsconfig.json starting from "${t}"`};let o=s.module,r=new A(null,o.SymbolFlags,o.TypeFlags,i,t),a=new o.API({cwd:t,fs:r.createFileSystem()});return r.api=a,{ok:!0,resolver:r}}async expandAll(t){let n=new Map;if(t.length===0)return n;let s=new Map;for(let o of t){if(!o.metadata.canonicalPropsType)continue;if(o.metadata.referencesComponentGenerics)continue;let r=this.virtualFileName(o.filePath,o.moduleName);this.overlay.set(r,V(o.metadata)),s.set(r,o)}if(s.size===0)return n;let i=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:Array.from(s.keys())}});try{let[o]=s.keys(),r=await i.getDefaultProjectForFile(o);if(!r)return n;let a=r.checker,y=await Promise.all(Array.from(s,async([c,u])=>{let p=this.overlay.get(c);if(!p)return null;let d=Z(p),l=await a.getTypeAtPosition(c,d);if(!l)return null;let m=new Map,b=await a.getPropertiesOfType(l);for(let v of b){if(!v.name||v.name.startsWith("__"))continue;m.set(v.name,{name:v.name,symbols:[v],forceOptional:!1})}if((l.flags&this.typeFlags.Union)!==0){let v=await l.getTypes(),C=await Promise.all(v.map((R)=>a.getPropertiesOfType(R)));for(let R of C)for(let T of R){if(!T.name||T.name.startsWith("__")||m.has(T.name))continue;let w=m.get(T.name);if(w)w.symbols.push(T);else m.set(T.name,{name:T.name,symbols:[T],forceOptional:!0})}}return{filePath:u.filePath,groups:Array.from(m.values())}})),g=[],P=[];y.forEach((c,u)=>{if(!c)return;c.groups.forEach((p,d)=>{for(let l of p.symbols)g.push(l),P.push({fileIndex:u,groupIndex:d})})});let S=g.length>0?await a.getTypeOfSymbol(g):[],x=await Promise.all(S.map((c)=>c?a.typeToString(c):Promise.resolve("any"))),h=new Map;g.forEach((c,u)=>{let{fileIndex:p,groupIndex:d}=P[u],l=(c.flags&this.symbolFlags.Optional)!==0,m=x[u];if(l)m=m.replace(L,"");let b=h.get(p)??new Map,_=b.get(d)??[];_.push(m),b.set(d,_),h.set(p,b)}),y.forEach((c,u)=>{if(!c)return;let p=h.get(u),d=c.groups.map((l,m)=>{let b=p?.get(m)??[],_=!(l.forceOptional||l.symbols.some((v)=>(v.flags&this.symbolFlags.Optional)!==0));return{name:l.name,type:Array.from(new Set(b)).join(" | "),isRequired:_}});d.sort((l,m)=>l.name.localeCompare(m.name)),n.set(c.filePath,d)})}finally{await i.dispose?.()}return n}async checkExamples(t){let n=new Map;if(t.length===0)return n;let s=[];for(let o of t)for(let r of o.sources){let a=this.exampleFileName(o.filePath,o.moduleName,r.id);this.overlay.set(a,H(r)),s.push({filePath:o.filePath,source:r,file:a})}if(s.length===0)return n;let i=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:s.map((o)=>o.file)}});try{let[o]=s,r=await i.getDefaultProjectForFile(o.file);if(!r)return n;await Promise.all(s.map(async({filePath:a,source:y,file:g})=>{let[P,S]=await Promise.all([r.program.getSyntacticDiagnostics(g),r.program.getSemanticDiagnostics(g)]),x=[...P,...S];if(x.length===0)return;let h=this.overlay.get(g)??"",c=x.map((p)=>J(p,h)).sort((p,d)=>p.line-d.line).map((p)=>`Line ${p.line}: ${p.text}`).join(`
|
|
2
2
|
`),u=n.get(a)??[];u.push({id:y.id,name:y.name,message:c}),n.set(a,u)}))}finally{await i.dispose?.()}return n}forgetOverlayFiles(t){for(let n of t)if(this.overlay.delete(n))this.pendingOverlayDeletions.add(n)}async openBareTypeSession(t){for(let[r,a]of t)this.overlay.set(r,a);let n=Array.from(this.pendingOverlayDeletions).filter((r)=>!t.has(r));this.pendingOverlayDeletions.clear();let s=await this.api.updateSnapshot({openProject:this.tsconfigPath,fileChanges:{created:Array.from(t.keys()),deleted:n}}),i=`${e(f.join(this.cwd,"node_modules"))}/`;return{resolveAt:async(r,a)=>{let y=await s.getDefaultProjectForFile(r);if(!y)return{kind:"unresolved"};let g=y.checker,P=await g.getSymbolAtPosition(r,a);if(!P)return{kind:"unresolved"};let S=await g.getAliasedSymbol(P);if(await g.isUnknownSymbol(S))return{kind:"unresolved"};let x=S.declarations??[];if(x.length===0)return{kind:"unresolved"};let h=await Promise.all(x.map((l)=>l.resolve())),c=h.findIndex((l)=>l&&e(l.getSourceFile().fileName).startsWith(i)),u=c===-1?h.findIndex((l)=>l!==void 0):c,p=u===-1?void 0:h[u];if(!p)return{kind:"unresolved"};let d=p.getSourceFile();if(await y.program.isSourceFileDefaultLibrary(d))return{kind:"default-lib"};return{kind:"resolved",filePath:d.fileName,declaredName:S.name}},dispose:()=>s.dispose?.()??Promise.resolve()}}async dispose(){this.overlay.clear(),await this.api?.close?.()}createFileSystem(){return{readFile:(t)=>this.overlay.get(e(t)),fileExists:(t)=>this.overlay.has(e(t))?!0:void 0,getAccessibleEntries:(t)=>{let n=e(t),s=Array.from(this.overlay.keys()).filter((r)=>e(f.dirname(r))===n);if(s.length===0)return;let i=[],o=[];try{for(let r of O(t)){let a=f.join(t,r);try{(j(a).isDirectory()?o:i).push(r)}catch{}}}catch{}for(let r of s){let a=f.basename(r);if(!i.includes(a))i.push(a)}return{files:i,directories:o}}}}virtualFileName(t,n){let s=f.dirname(f.resolve(t));return e(f.join(s,`__sveld_resolved_${n}.ts`))}exampleFileName(t,n,s){let i=f.dirname(f.resolve(t)),o=s.replace(G,"_");return e(f.join(i,`__sveld_example_${n}_${o}.ts`))}}function V(t){return[...t.typeImportStatements,...t.localTypeDeclarations,`type ${k} = ${t.canonicalPropsType};`,`declare const ${F}: ${k};`].join(`
|
|
3
3
|
`)}function W(t){let n=t.replace(U,"_");if(n===""||B.test(n))return`_${n}`;return n}function H(t){return`const ${W(t.name)} = null as unknown as (${t.type});
|
|
4
4
|
${t.code}
|
package/lib/cli-entry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ie}from"./chunk-rftengvg.js";export{ie as cli};
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j,F,J,q,
|
|
1
|
+
import{j,F,J,q,ue,V,o,Ce,H,M,ne,Pe,se,D,De,_,E,G,N,I,b,S,k,z,_e,ve,w,ie}from"./chunk-rftengvg.js";import{i}from"./chunk-49hdrj4n.js";async function f(s){if(s&&"input"in s)throw Error("sveld: the `input` option was renamed to `entry`.");let{entry:m,...u}=s??{},a=await _(),n=D(m??a.entry);if(n===null)throw Error('sveld: could not resolve a Svelte entry point. Set package.json#svelte, or pass the "entry" option.');let e=G(E(a,u,{entry:n}));N(e),I(e.quiet===!0);let t=await S(n,e.glob===!0,b(e)),p;if(e.check)p=await M(t.components,H(e),{entryExports:t.entryExports});if(await w(t,e,n),!e.dryRun)t.cache?.save();let c=e.reportDiagnostics||e.strict,r=F(t.diagnostics,c);if(c&&r.length>0)if(e.format==="json")process.stderr.write(V(r));else console.error(q(r));let l=0;if(p?.bump==="major")l=3;else if(J(r,e.strict).length>0)l=4;return{diagnostics:r,check:p,errors:t.errors,exitCode:l}}export{Pe as CHECK_REPORT_SCHEMA_VERSION,i as ComponentParser,ue as DIAGNOSTICS_SCHEMA_VERSION,j as DIAGNOSTIC_CODES,o as buildComponentApiDocument,ie as cli,ve as default,De as defineConfig,Ce as diffApiDocuments,ne as formatCheckReport,se as formatCheckReportJson,z as getWriter,_e as listWriters,k as registerWriter,M as runCheck,f as sveld};
|
package/package.json
CHANGED
|
@@ -202,7 +202,8 @@
|
|
|
202
202
|
"name": { "type": "string" },
|
|
203
203
|
"localName": { "type": "string" },
|
|
204
204
|
"kind": {
|
|
205
|
-
"enum": ["let", "const", "function"]
|
|
205
|
+
"enum": ["let", "const", "function", "re-export"],
|
|
206
|
+
"description": "`re-export` is module-export only: `export { x } from \"...\"`, `export * from \"...\"`, or `export { x }` of an imported binding."
|
|
206
207
|
},
|
|
207
208
|
"constant": { "type": "boolean" },
|
|
208
209
|
"type": { "type": "string" },
|
|
@@ -217,6 +218,10 @@
|
|
|
217
218
|
"items": { "$ref": "#/$defs/propParam" }
|
|
218
219
|
},
|
|
219
220
|
"returnType": { "type": "string" },
|
|
221
|
+
"typeParameters": {
|
|
222
|
+
"type": "string",
|
|
223
|
+
"description": "A function's own type parameter list from its `@template` tags, without angle brackets."
|
|
224
|
+
},
|
|
220
225
|
"isFunction": { "type": "boolean" },
|
|
221
226
|
"isFunctionDeclaration": { "type": "boolean" },
|
|
222
227
|
"isRequired": { "type": "boolean" },
|
|
@@ -233,9 +238,23 @@
|
|
|
233
238
|
"type": "array",
|
|
234
239
|
"items": { "$ref": "#/$defs/jsdocTag" }
|
|
235
240
|
},
|
|
241
|
+
"reExport": { "$ref": "#/$defs/reExport" },
|
|
236
242
|
"source": { "$ref": "#/$defs/sourceRange" }
|
|
237
243
|
}
|
|
238
244
|
},
|
|
245
|
+
"reExport": {
|
|
246
|
+
"type": "object",
|
|
247
|
+
"required": ["from", "imported"],
|
|
248
|
+
"additionalProperties": false,
|
|
249
|
+
"description": "Where a `kind: \"re-export\"` module export's binding comes from.",
|
|
250
|
+
"properties": {
|
|
251
|
+
"from": { "type": "string", "description": "Module specifier as written in the source." },
|
|
252
|
+
"imported": {
|
|
253
|
+
"type": "string",
|
|
254
|
+
"description": "Name the source module exports: `default` for a default import, `*` for `export *` or a namespace import."
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
},
|
|
239
258
|
"defaultValue": {
|
|
240
259
|
"type": "object",
|
|
241
260
|
"required": ["raw", "kind"],
|