svelte-docinfo 0.14.0 → 0.15.0
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 +3 -1
- package/dist/analyze-core.d.ts +2 -2
- package/dist/diagnostics.d.ts +26 -1
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +18 -0
- package/dist/svelte-scripts.d.ts +12 -0
- package/dist/svelte-scripts.d.ts.map +1 -1
- package/dist/svelte-scripts.js +23 -0
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +71 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,9 @@ Given a project with a `tsconfig.json` (at or above the project root) and two fi
|
|
|
64
64
|
* @param b - second number
|
|
65
65
|
* @returns the sum
|
|
66
66
|
*/
|
|
67
|
-
export
|
|
67
|
+
export function add(a: number, b: number): number {
|
|
68
|
+
return a + b;
|
|
69
|
+
}
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
and `src/lib/Calculator.svelte`:
|
package/dist/analyze-core.d.ts
CHANGED
|
@@ -65,14 +65,14 @@ import { type FileExists, type IsEmittedFile } from './typescript-extract-shared
|
|
|
65
65
|
export type OnDuplicates = 'diagnostic' | 'warn' | 'throw';
|
|
66
66
|
declare const AnalyzeResultJsonEntries: v.StrictObjectSchema<{
|
|
67
67
|
readonly modules: v.OptionalSchema<v.ArraySchema<import("./types.js").ModuleJsonSchema, undefined>, () => never[]>;
|
|
68
|
-
readonly diagnostics: v.OptionalSchema<v.ArraySchema<v.VariantSchema<"kind", [import("./diagnostics.js").TypeExtractionDiagnosticSchema, import("./diagnostics.js").SignatureAnalysisDiagnosticSchema, import("./diagnostics.js").ClassMemberDiagnosticSchema, import("./diagnostics.js").SveltePropDiagnosticSchema, import("./diagnostics.js").ModuleSkippedDiagnosticSchema, import("./diagnostics.js").ModuleUnreadableDiagnosticSchema, import("./diagnostics.js").ImportParseDiagnosticSchema, import("./diagnostics.js").DuplicateCommentDiagnosticSchema, import("./diagnostics.js").MisplacedTagDiagnosticSchema, import("./diagnostics.js").UnknownParamDiagnosticSchema, import("./diagnostics.js").SourceMapFailedDiagnosticSchema, import("./diagnostics.js").DuplicateDeclarationDiagnosticSchema, import("./diagnostics.js").TransformFailedDiagnosticSchema, import("./diagnostics.js").ResolverFailedDiagnosticSchema, import("./diagnostics.js").AliasLostDiagnosticSchema], undefined>, undefined>, () => never[]>;
|
|
68
|
+
readonly diagnostics: v.OptionalSchema<v.ArraySchema<v.VariantSchema<"kind", [import("./diagnostics.js").TypeExtractionDiagnosticSchema, import("./diagnostics.js").SignatureAnalysisDiagnosticSchema, import("./diagnostics.js").ClassMemberDiagnosticSchema, import("./diagnostics.js").SveltePropDiagnosticSchema, import("./diagnostics.js").ModuleSkippedDiagnosticSchema, import("./diagnostics.js").ModuleUnreadableDiagnosticSchema, import("./diagnostics.js").ImportParseDiagnosticSchema, import("./diagnostics.js").DuplicateCommentDiagnosticSchema, import("./diagnostics.js").ComponentCommentMismatchDiagnosticSchema, import("./diagnostics.js").MisplacedTagDiagnosticSchema, import("./diagnostics.js").UnknownParamDiagnosticSchema, import("./diagnostics.js").SourceMapFailedDiagnosticSchema, import("./diagnostics.js").DuplicateDeclarationDiagnosticSchema, import("./diagnostics.js").TransformFailedDiagnosticSchema, import("./diagnostics.js").ResolverFailedDiagnosticSchema, import("./diagnostics.js").AliasLostDiagnosticSchema], undefined>, undefined>, () => never[]>;
|
|
69
69
|
}, undefined>;
|
|
70
70
|
/** @nodocs */
|
|
71
71
|
export interface AnalyzeResultJsonEntriesInput extends Named<v.InferInput<typeof AnalyzeResultJsonEntries>> {
|
|
72
72
|
}
|
|
73
73
|
declare const AnalyzeResultJsonImpl: v.SchemaWithPipe<readonly [v.CustomSchema<AnalyzeResultJsonEntriesInput, v.ErrorMessage<v.CustomIssue> | undefined>, v.StrictObjectSchema<{
|
|
74
74
|
readonly modules: v.OptionalSchema<v.ArraySchema<import("./types.js").ModuleJsonSchema, undefined>, () => never[]>;
|
|
75
|
-
readonly diagnostics: v.OptionalSchema<v.ArraySchema<v.VariantSchema<"kind", [import("./diagnostics.js").TypeExtractionDiagnosticSchema, import("./diagnostics.js").SignatureAnalysisDiagnosticSchema, import("./diagnostics.js").ClassMemberDiagnosticSchema, import("./diagnostics.js").SveltePropDiagnosticSchema, import("./diagnostics.js").ModuleSkippedDiagnosticSchema, import("./diagnostics.js").ModuleUnreadableDiagnosticSchema, import("./diagnostics.js").ImportParseDiagnosticSchema, import("./diagnostics.js").DuplicateCommentDiagnosticSchema, import("./diagnostics.js").MisplacedTagDiagnosticSchema, import("./diagnostics.js").UnknownParamDiagnosticSchema, import("./diagnostics.js").SourceMapFailedDiagnosticSchema, import("./diagnostics.js").DuplicateDeclarationDiagnosticSchema, import("./diagnostics.js").TransformFailedDiagnosticSchema, import("./diagnostics.js").ResolverFailedDiagnosticSchema, import("./diagnostics.js").AliasLostDiagnosticSchema], undefined>, undefined>, () => never[]>;
|
|
75
|
+
readonly diagnostics: v.OptionalSchema<v.ArraySchema<v.VariantSchema<"kind", [import("./diagnostics.js").TypeExtractionDiagnosticSchema, import("./diagnostics.js").SignatureAnalysisDiagnosticSchema, import("./diagnostics.js").ClassMemberDiagnosticSchema, import("./diagnostics.js").SveltePropDiagnosticSchema, import("./diagnostics.js").ModuleSkippedDiagnosticSchema, import("./diagnostics.js").ModuleUnreadableDiagnosticSchema, import("./diagnostics.js").ImportParseDiagnosticSchema, import("./diagnostics.js").DuplicateCommentDiagnosticSchema, import("./diagnostics.js").ComponentCommentMismatchDiagnosticSchema, import("./diagnostics.js").MisplacedTagDiagnosticSchema, import("./diagnostics.js").UnknownParamDiagnosticSchema, import("./diagnostics.js").SourceMapFailedDiagnosticSchema, import("./diagnostics.js").DuplicateDeclarationDiagnosticSchema, import("./diagnostics.js").TransformFailedDiagnosticSchema, import("./diagnostics.js").ResolverFailedDiagnosticSchema, import("./diagnostics.js").AliasLostDiagnosticSchema], undefined>, undefined>, () => never[]>;
|
|
76
76
|
}, undefined>]>;
|
|
77
77
|
/** @nodocs */
|
|
78
78
|
export interface AnalyzeResultJsonSchema extends Named<typeof AnalyzeResultJsonImpl> {
|
package/dist/diagnostics.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export type DiagnosticSeverity = v.InferOutput<typeof DiagnosticSeverity>;
|
|
|
80
80
|
* Severity is a stable per-kind property: `transform_failed` and
|
|
81
81
|
* `module_unreadable` are always `error`, every other kind always `warning`.
|
|
82
82
|
*/
|
|
83
|
-
export declare const DiagnosticKind: v.PicklistSchema<["type_extraction_failed", "signature_analysis_failed", "class_member_failed", "svelte_prop_failed", "module_skipped", "module_unreadable", "import_parse_failed", "duplicate_comment", "misplaced_tag", "unknown_param", "source_map_failed", "duplicate_declaration", "transform_failed", "resolver_failed", "alias_lost"], undefined>;
|
|
83
|
+
export declare const DiagnosticKind: v.PicklistSchema<["type_extraction_failed", "signature_analysis_failed", "class_member_failed", "svelte_prop_failed", "module_skipped", "module_unreadable", "import_parse_failed", "duplicate_comment", "component_comment_mismatch", "misplaced_tag", "unknown_param", "source_map_failed", "duplicate_declaration", "transform_failed", "resolver_failed", "alias_lost"], undefined>;
|
|
84
84
|
export type DiagnosticKind = v.InferOutput<typeof DiagnosticKind>;
|
|
85
85
|
declare const TypeExtractionDiagnosticImpl: v.StrictObjectSchema<{
|
|
86
86
|
/** Name of the symbol whose type couldn't be extracted. */
|
|
@@ -257,6 +257,30 @@ export interface DuplicateCommentDiagnosticSchema extends Named<typeof Duplicate
|
|
|
257
257
|
*/
|
|
258
258
|
export declare const DuplicateCommentDiagnostic: DuplicateCommentDiagnosticSchema;
|
|
259
259
|
export type DuplicateCommentDiagnostic = v.InferOutput<typeof DuplicateCommentDiagnostic>;
|
|
260
|
+
declare const ComponentCommentMismatchDiagnosticImpl: v.StrictObjectSchema<{
|
|
261
|
+
readonly file: v.StringSchema<undefined>;
|
|
262
|
+
readonly line: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
|
|
263
|
+
readonly column: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>, undefined>;
|
|
264
|
+
readonly message: v.StringSchema<undefined>;
|
|
265
|
+
readonly severity: v.PicklistSchema<["error", "warning"], undefined>;
|
|
266
|
+
readonly kind: v.LiteralSchema<"component_comment_mismatch", undefined>;
|
|
267
|
+
}, undefined>;
|
|
268
|
+
/** @nodocs */
|
|
269
|
+
export interface ComponentCommentMismatchDiagnosticSchema extends Named<typeof ComponentCommentMismatchDiagnosticImpl> {
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* svelte2tsx, and so editor hover, documents a component with a different
|
|
273
|
+
* HTML comment than the analyzer does.
|
|
274
|
+
*
|
|
275
|
+
* The analyzer reads the first HTML comment with a line starting
|
|
276
|
+
* `@component`; svelte2tsx takes the last one containing `@component`
|
|
277
|
+
* anywhere, so a second component comment or a mid-prose mention (a
|
|
278
|
+
* backticked `@component` in a module comment) takes its slot. `line` is the
|
|
279
|
+
* comment svelte2tsx picks; reword its `@component` to agree. Not emitted
|
|
280
|
+
* when in-script JSDoc supplies the component's doc.
|
|
281
|
+
*/
|
|
282
|
+
export declare const ComponentCommentMismatchDiagnostic: ComponentCommentMismatchDiagnosticSchema;
|
|
283
|
+
export type ComponentCommentMismatchDiagnostic = v.InferOutput<typeof ComponentCommentMismatchDiagnostic>;
|
|
260
284
|
declare const MisplacedTagDiagnosticImpl: v.StrictObjectSchema<{
|
|
261
285
|
/**
|
|
262
286
|
* The tag name without the `@` prefix (e.g., `'example'`, `'deprecated'`).
|
|
@@ -484,6 +508,7 @@ export declare const Diagnostic: v.VariantSchema<'kind', [
|
|
|
484
508
|
typeof ModuleUnreadableDiagnostic,
|
|
485
509
|
typeof ImportParseDiagnostic,
|
|
486
510
|
typeof DuplicateCommentDiagnostic,
|
|
511
|
+
typeof ComponentCommentMismatchDiagnostic,
|
|
487
512
|
typeof MisplacedTagDiagnostic,
|
|
488
513
|
typeof UnknownParamDiagnostic,
|
|
489
514
|
typeof SourceMapFailedDiagnostic,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAI3D;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,mDAAmC,CAAC;AACnE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAI1E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAI3D;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,mDAAmC,CAAC;AACnE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAI1E;;;;;GAKG;AACH,eAAO,MAAM,cAAc,yXAiBzB,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC;AAiDlE,QAAA,MAAM,4BAA4B;IAGjC,2DAA2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parse_failed',
|
|
92
92
|
'duplicate_comment',
|
|
93
|
+
'component_comment_mismatch',
|
|
93
94
|
'misplaced_tag',
|
|
94
95
|
'unknown_param',
|
|
95
96
|
'source_map_failed',
|
|
@@ -254,6 +255,22 @@ const DuplicateCommentDiagnosticImpl = v.strictObject({
|
|
|
254
255
|
* or both HTML `@component` and JSDoc for component `docComment`).
|
|
255
256
|
*/
|
|
256
257
|
export const DuplicateCommentDiagnostic = DuplicateCommentDiagnosticImpl;
|
|
258
|
+
const ComponentCommentMismatchDiagnosticImpl = v.strictObject({
|
|
259
|
+
kind: v.literal('component_comment_mismatch'),
|
|
260
|
+
...baseDiagnosticFields
|
|
261
|
+
});
|
|
262
|
+
/**
|
|
263
|
+
* svelte2tsx, and so editor hover, documents a component with a different
|
|
264
|
+
* HTML comment than the analyzer does.
|
|
265
|
+
*
|
|
266
|
+
* The analyzer reads the first HTML comment with a line starting
|
|
267
|
+
* `@component`; svelte2tsx takes the last one containing `@component`
|
|
268
|
+
* anywhere, so a second component comment or a mid-prose mention (a
|
|
269
|
+
* backticked `@component` in a module comment) takes its slot. `line` is the
|
|
270
|
+
* comment svelte2tsx picks; reword its `@component` to agree. Not emitted
|
|
271
|
+
* when in-script JSDoc supplies the component's doc.
|
|
272
|
+
*/
|
|
273
|
+
export const ComponentCommentMismatchDiagnostic = ComponentCommentMismatchDiagnosticImpl;
|
|
257
274
|
const MisplacedTagDiagnosticImpl = v.strictObject({
|
|
258
275
|
kind: v.literal('misplaced_tag'),
|
|
259
276
|
...baseDiagnosticFields,
|
|
@@ -440,6 +457,7 @@ export const Diagnostic = v.variant('kind', [
|
|
|
440
457
|
ModuleUnreadableDiagnostic,
|
|
441
458
|
ImportParseDiagnostic,
|
|
442
459
|
DuplicateCommentDiagnostic,
|
|
460
|
+
ComponentCommentMismatchDiagnostic,
|
|
443
461
|
MisplacedTagDiagnostic,
|
|
444
462
|
UnknownParamDiagnostic,
|
|
445
463
|
SourceMapFailedDiagnostic,
|
package/dist/svelte-scripts.d.ts
CHANGED
|
@@ -33,6 +33,18 @@ export interface ScannedScriptTag extends SvelteScriptTag {
|
|
|
33
33
|
*/
|
|
34
34
|
provenTopLevel: boolean;
|
|
35
35
|
}
|
|
36
|
+
/** An HTML comment's raw content (between `<!--` and `-->`) and where the comment starts. */
|
|
37
|
+
export interface HtmlComment {
|
|
38
|
+
content: string;
|
|
39
|
+
/** Offset of the `<!--` in the Svelte source. */
|
|
40
|
+
start: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Collect the HTML comments (`<!-- ... -->`) in Svelte source, in source
|
|
44
|
+
* order, skipping script and style text, as Svelte's parser and svelte2tsx do:
|
|
45
|
+
* a `<!--` in a script's string literal isn't a comment.
|
|
46
|
+
*/
|
|
47
|
+
export declare const findHtmlComments: (svelteSource: string) => Array<HtmlComment>;
|
|
36
48
|
/**
|
|
37
49
|
* Scan Svelte source for script tags with content, in source order, and mark
|
|
38
50
|
* the ones the scan itself proves top-level.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte-scripts.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte-scripts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC/B,wEAAwE;IACxE,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,6FAA6F;IAC7F,KAAK,EAAE,MAAM,CAAC;CACd;AAED,yFAAyF;AACzF,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACxD,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"svelte-scripts.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte-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AAC;AAUnF;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEhE,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC/B,oDAAoD;IACpD,IAAI,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7B,SAAS,EAAE,kBAAkB,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,qBAAqB;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,cAAc,GAC1B,cAAc,MAAM,EACpB,UAAU,qBAAqB,KAC7B,eAwBF,CAAC"}
|
package/dist/svelte-scripts.js
CHANGED
|
@@ -27,6 +27,29 @@ import { parse } from 'svelte/compiler';
|
|
|
27
27
|
const SCRIPT_TAG_MATCHER = /<!--[^]*?-->|<script((?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*)(?:\/>|>([^]*?)<\/script\s*>)/dg;
|
|
28
28
|
/** `SCRIPT_TAG_MATCHER` for style tags, whose content is blanked before parsing. */
|
|
29
29
|
const STYLE_TAG_MATCHER = /<!--[^]*?-->|<style(?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*>([^]*?)<\/style\s*>/dg;
|
|
30
|
+
/**
|
|
31
|
+
* Matches, left to right, an HTML comment (its content captured), a script
|
|
32
|
+
* tag, or a style tag. The tag alternatives are `SCRIPT_TAG_MATCHER`'s and
|
|
33
|
+
* `STYLE_TAG_MATCHER`'s, uncaptured: they consume the tags' raw text, where
|
|
34
|
+
* a `<!--` doesn't start a comment.
|
|
35
|
+
*/
|
|
36
|
+
const HTML_COMMENT_MATCHER = /<!--([^]*?)-->|<script(?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*(?:\/>|>[^]*?<\/script\s*>)|<style(?:\s+[^=>'"/\s]+=(?:"[^"]*"|'[^']*'|[^>\s]+)|\s+[^=>'"/\s]+)*\s*>[^]*?<\/style\s*>/g;
|
|
37
|
+
/**
|
|
38
|
+
* Collect the HTML comments (`<!-- ... -->`) in Svelte source, in source
|
|
39
|
+
* order, skipping script and style text, as Svelte's parser and svelte2tsx do:
|
|
40
|
+
* a `<!--` in a script's string literal isn't a comment.
|
|
41
|
+
*/
|
|
42
|
+
export const findHtmlComments = (svelteSource) => {
|
|
43
|
+
const comments = [];
|
|
44
|
+
HTML_COMMENT_MATCHER.lastIndex = 0;
|
|
45
|
+
let match;
|
|
46
|
+
while ((match = HTML_COMMENT_MATCHER.exec(svelteSource)) !== null) {
|
|
47
|
+
const content = match[1];
|
|
48
|
+
if (content !== undefined)
|
|
49
|
+
comments.push({ content, start: match.index });
|
|
50
|
+
}
|
|
51
|
+
return comments;
|
|
52
|
+
};
|
|
30
53
|
/**
|
|
31
54
|
* The attribute spellings the scan's proof accepts: names of word characters,
|
|
32
55
|
* values double-quoted, single-quoted, or bare word characters, whitespace
|
package/dist/svelte.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,QAAQ,EAAuB,MAAM,2BAA2B,CAAC;AAG1E,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EAGX,kBAAkB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACX,oBAAoB,EAEpB,cAAc,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,
|
|
1
|
+
{"version":3,"file":"svelte.d.ts","sourceRoot":"../src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;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,GAAI,YAAY,KAAK,CAAC,kBAAkB,CAAC,KAAG,MAKtF,CAAC;AAudF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,mBAAmB,GAC/B,YAAY,cAAc,GAAG;IAAE,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAAE,EACnE,YAAY,MAAM,EAClB,SAAS,EAAE,CAAC,WAAW,EACvB,SAAS,mBAAmB,EAC5B,aAAa,KAAK,CAAC,UAAU,CAAC,EAC9B,SAAS,EAAE,CAAC,OAAO,EACnB,aAAa,iBAAiB,EAC9B,gBAAgB,aAAa,EAC7B,gBAAgB,aAAa,EAC7B,aAAa,UAAU,KACrB,cAAc,GAAG,SA8VnB,CAAC"}
|
package/dist/svelte.js
CHANGED
|
@@ -28,18 +28,18 @@ import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping';
|
|
|
28
28
|
import { VERSION } from 'svelte/compiler';
|
|
29
29
|
import { svelte2tsx } from 'svelte2tsx';
|
|
30
30
|
import ts from 'typescript';
|
|
31
|
-
import { parseComment, applyToDeclaration, hasDocContent, hasModuleTag, parseModuleComment, toModuleDocFields } from './tsdoc.js';
|
|
31
|
+
import { parseComment, applyToDeclaration, hasDocContent, hasModuleTag, parseCommentText, parseModuleComment, toModuleDocFields } from './tsdoc.js';
|
|
32
32
|
import { parseGenericParam, filterDocumentedProperties, getTypeSignature, createExtractContext, optionalWidened, extractSignatureParameters, applyReturnType, isExternalSignature } from './typescript-extract-shared.js';
|
|
33
33
|
import { referenceSymbolName, resolveTypeInfo, restElementForms, tupleElementName, tupleElements } from './typescript-extract-type-json.js';
|
|
34
34
|
import { extractModuleComment, analyzeExports, warnModuleCommentTags } from './typescript-exports.js';
|
|
35
|
-
import { getComponentName, isSvelte2tsxGeneratedExport,
|
|
35
|
+
import { getComponentName, isSvelte2tsxGeneratedExport, SVELTE_VIRTUAL_SUFFIX } from './source.js';
|
|
36
36
|
import { extractDependencies } from './source-config.js';
|
|
37
37
|
import { compareStrings } from './postprocess.js';
|
|
38
38
|
import {} from './diagnostics.js';
|
|
39
39
|
import { toErrorMessage } from './error.js';
|
|
40
40
|
import { toPosixPath } from './paths.js';
|
|
41
41
|
import { resolveLegacyPropsAnchor, scanLegacyExports } from './svelte-legacy.js';
|
|
42
|
-
import { findScriptTags, isModuleScript } from './svelte-scripts.js';
|
|
42
|
+
import { findHtmlComments, findScriptTags, isModuleScript } from './svelte-scripts.js';
|
|
43
43
|
/**
|
|
44
44
|
* Pre-transform a Svelte source file via svelte2tsx.
|
|
45
45
|
*
|
|
@@ -139,9 +139,7 @@ const SVELTE2TSX_IDENTIFIERS = {
|
|
|
139
139
|
/** Identifier for `$props()` rune. */
|
|
140
140
|
PROPS_RUNE: '$props',
|
|
141
141
|
/** Identifier for `$bindable()` rune. */
|
|
142
|
-
BINDABLE_RUNE: '$bindable'
|
|
143
|
-
/** Suffix on the synthesized component const/type alias (shared constant — `isSvelte2tsxInternal` in `source.ts` filters on it too). */
|
|
144
|
-
COMPONENT_ALIAS_SUFFIX: SVELTE_COMPONENT_ALIAS_SUFFIX
|
|
142
|
+
BINDABLE_RUNE: '$bindable'
|
|
145
143
|
};
|
|
146
144
|
/**
|
|
147
145
|
* Lazily validated Svelte major version.
|
|
@@ -179,11 +177,6 @@ const findComponentNodes = (virtualSource) => {
|
|
|
179
177
|
nodes.renderClass = statement;
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
|
-
else if (ts.isVariableStatement(statement) &&
|
|
183
|
-
statement.declarationList.declarations.some((declaration) => ts.isIdentifier(declaration.name) &&
|
|
184
|
-
declaration.name.text.endsWith(SVELTE2TSX_IDENTIFIERS.COMPONENT_ALIAS_SUFFIX))) {
|
|
185
|
-
nodes.componentAlias = statement;
|
|
186
|
-
}
|
|
187
180
|
}
|
|
188
181
|
return nodes;
|
|
189
182
|
};
|
|
@@ -348,16 +341,6 @@ export const extractScriptContent = (svelteSource) => findScriptTags(svelteSourc
|
|
|
348
341
|
* @returns the module script tag content, or undefined if no module script is found
|
|
349
342
|
*/
|
|
350
343
|
export const extractModuleScriptContent = (svelteSource) => findScriptTags(svelteSource).tags.find((tag) => isModuleScript(tag.attributes))?.content;
|
|
351
|
-
/** Collect the raw content of each HTML comment (`<!-- ... -->`) in source order. */
|
|
352
|
-
const findHtmlComments = (svelteSource) => {
|
|
353
|
-
const commentRegex = /<!--([^]*?)-->/g;
|
|
354
|
-
const contents = [];
|
|
355
|
-
let match;
|
|
356
|
-
while ((match = commentRegex.exec(svelteSource)) !== null) {
|
|
357
|
-
contents.push(match[1]);
|
|
358
|
-
}
|
|
359
|
-
return contents;
|
|
360
|
-
};
|
|
361
344
|
/**
|
|
362
345
|
* Parse script-tag content as standalone TypeScript for syntactic scans.
|
|
363
346
|
*
|
|
@@ -422,8 +405,8 @@ const dedentHtmlComment = (rawContent) => {
|
|
|
422
405
|
* comment is found or it holds nothing but `@module`
|
|
423
406
|
*/
|
|
424
407
|
export const extractHtmlModuleComment = (svelteSource) => {
|
|
425
|
-
for (const
|
|
426
|
-
const cleaned = dedentHtmlComment(
|
|
408
|
+
for (const { content } of findHtmlComments(svelteSource)) {
|
|
409
|
+
const cleaned = dedentHtmlComment(content);
|
|
427
410
|
if (cleaned && hasModuleTag(cleaned))
|
|
428
411
|
return parseModuleComment(cleaned);
|
|
429
412
|
}
|
|
@@ -441,37 +424,63 @@ export const extractHtmlModuleComment = (svelteSource) => {
|
|
|
441
424
|
* @returns the parsed module comment, or undefined if none is found
|
|
442
425
|
*/
|
|
443
426
|
export const extractSvelteModuleComment = (scriptContent) => extractModuleComment(parseScriptContent(scriptContent));
|
|
427
|
+
/** A line that starts with the `@component` tag, as opposed to a mention in prose. */
|
|
428
|
+
const COMPONENT_TAG_LINE = /^(\s*)@component\b[ \t]*/;
|
|
444
429
|
/**
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
430
|
+
* The HTML component comment: the first HTML comment with a line starting
|
|
431
|
+
* `@component`, the rule `@module` follows. A backticked or mid-prose mention
|
|
432
|
+
* doesn't count.
|
|
433
|
+
*
|
|
434
|
+
* svelte2tsx, and so editor hover, picks differently: the *last* HTML comment
|
|
435
|
+
* containing `@component` anywhere (`svelte2tsxComponentComment`), which
|
|
436
|
+
* `analyzeSvelteModule` warns about as `component_comment_mismatch` when the
|
|
437
|
+
* two disagree.
|
|
449
438
|
*/
|
|
450
|
-
const
|
|
439
|
+
const findHtmlComponentComment = (comments) => comments.find(({ content }) => dedentHtmlComment(content)
|
|
440
|
+
.split('\n')
|
|
441
|
+
.some((line) => COMPONENT_TAG_LINE.test(line)));
|
|
442
|
+
/** The comment svelte2tsx documents the component with: the last one containing `@component`. */
|
|
443
|
+
const svelte2tsxComponentComment = (comments) => comments.findLast(({ content }) => content.includes('@component'));
|
|
444
|
+
/**
|
|
445
|
+
* Parse an HTML component comment with `parseCommentText`, after removing the
|
|
446
|
+
* `@component` tag from each line it starts. Text after the tag on its line
|
|
447
|
+
* stays prose (`<!-- @component A button. -->`), and the lines' common
|
|
448
|
+
* indentation is stripped (`dedentHtmlComment`), as for an HTML module comment.
|
|
449
|
+
*/
|
|
450
|
+
const parseHtmlComponentComment = (comment) => {
|
|
451
|
+
const text = dedentHtmlComment(comment.content)
|
|
452
|
+
.split('\n')
|
|
453
|
+
.map((line) => line.replace(COMPONENT_TAG_LINE, '$1'))
|
|
454
|
+
.join('\n')
|
|
455
|
+
.trim();
|
|
456
|
+
const parsed = parseCommentText(text);
|
|
457
|
+
return parsed && hasDocContent(parsed) ? parsed : undefined;
|
|
458
|
+
};
|
|
451
459
|
/**
|
|
452
|
-
* Extract component-level TSDoc comment
|
|
460
|
+
* Extract the component-level TSDoc comment.
|
|
453
461
|
*
|
|
454
462
|
* Two authoring forms reach here, searched in precedence order:
|
|
455
463
|
*
|
|
456
|
-
* 1. in-script JSDoc
|
|
457
|
-
* `$$render()` function, so the comment
|
|
458
|
-
* earlier statement in that body)
|
|
459
|
-
* 2. the HTML `@component` comment
|
|
460
|
-
*
|
|
464
|
+
* 1. in-script JSDoc, read from the svelte2tsx output — the instance
|
|
465
|
+
* `<script>` becomes the body of the `$$render()` function, so the comment
|
|
466
|
+
* rides the props destructuring (or an earlier statement in that body)
|
|
467
|
+
* 2. the HTML `@component` comment, read from the original source
|
|
468
|
+
* (`findHtmlComponentComment`), not from the JSDoc svelte2tsx re-emits for
|
|
469
|
+
* it, since svelte2tsx picks the comment by a looser rule
|
|
461
470
|
*
|
|
462
|
-
* Scoping the search to
|
|
463
|
-
* its declarations hoist above `$$render`, and a whole-file walk would
|
|
464
|
-
* first one's JSDoc — which documents that export, not the component.
|
|
471
|
+
* Scoping the in-script search to `$$render` is what keeps `<script module>`
|
|
472
|
+
* out: its declarations hoist above `$$render`, and a whole-file walk would
|
|
473
|
+
* take the first one's JSDoc — which documents that export, not the component.
|
|
465
474
|
*/
|
|
466
|
-
const extractComponentTsdoc = (nodes, sourceFile) => {
|
|
475
|
+
const extractComponentTsdoc = (nodes, sourceFile, htmlComponentComment) => {
|
|
467
476
|
const renderBody = nodes.renderFunction?.body;
|
|
468
477
|
if (renderBody) {
|
|
469
478
|
const tsdoc = findInstanceTsdoc(renderBody, sourceFile);
|
|
470
479
|
if (tsdoc)
|
|
471
480
|
return { tsdoc, source: 'script' };
|
|
472
481
|
}
|
|
473
|
-
if (
|
|
474
|
-
const tsdoc =
|
|
482
|
+
if (htmlComponentComment) {
|
|
483
|
+
const tsdoc = parseHtmlComponentComment(htmlComponentComment);
|
|
475
484
|
if (tsdoc)
|
|
476
485
|
return { tsdoc, source: 'html' };
|
|
477
486
|
}
|
|
@@ -1448,15 +1457,32 @@ export const analyzeSvelteModule = (sourceFile, modulePath, checker, options, di
|
|
|
1448
1457
|
if (genericParams?.length) {
|
|
1449
1458
|
componentDecl.genericParams = genericParams;
|
|
1450
1459
|
}
|
|
1451
|
-
// Extract component-level TSDoc from virtual source
|
|
1452
|
-
|
|
1460
|
+
// Extract component-level TSDoc: in-script JSDoc from the virtual source,
|
|
1461
|
+
// else the HTML `@component` comment from the original
|
|
1462
|
+
const htmlComments = findHtmlComments(sourceFile.content);
|
|
1463
|
+
const htmlComponentComment = findHtmlComponentComment(htmlComments);
|
|
1464
|
+
const componentTsdoc = extractComponentTsdoc(componentNodes, virtualTsSource, htmlComponentComment);
|
|
1453
1465
|
applyToDeclaration(componentDecl, componentTsdoc?.tsdoc);
|
|
1454
1466
|
// Extract source line via source map (maps $$render back to <script> tag)
|
|
1455
1467
|
componentDecl.sourceLine = extractComponentSourceLine(componentNodes, virtualTsSource, virtualFile.sourceMap);
|
|
1468
|
+
// Warn when svelte2tsx (and so editor hover) would document the component
|
|
1469
|
+
// with a different HTML comment than the one read here; moot when in-script
|
|
1470
|
+
// JSDoc supplies the doc
|
|
1471
|
+
const svelte2tsxComment = svelte2tsxComponentComment(htmlComments);
|
|
1472
|
+
if (componentTsdoc?.source !== 'script' && svelte2tsxComment !== htmlComponentComment) {
|
|
1473
|
+
const svelte2tsxLine = lineOfOffset(sourceFile.content, svelte2tsxComment.start);
|
|
1474
|
+
diagnostics.push({
|
|
1475
|
+
kind: 'component_comment_mismatch',
|
|
1476
|
+
file: diagnosticFile,
|
|
1477
|
+
line: svelte2tsxLine,
|
|
1478
|
+
message: htmlComponentComment
|
|
1479
|
+
? `svelte2tsx and editor hover document the component with the HTML comment at line ${svelte2tsxLine}, the last one containing @component; using the one at line ${lineOfOffset(sourceFile.content, htmlComponentComment.start)}, the first with @component at a line start.`
|
|
1480
|
+
: `The HTML comment at line ${svelte2tsxLine} mentions @component, so svelte2tsx and editor hover use it as the component's docs; no line starts with @component, so the component has none here.`,
|
|
1481
|
+
severity: 'warning'
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1456
1484
|
// Warn if both HTML @component and script JSDoc provide docComment
|
|
1457
|
-
if (componentDecl.docComment &&
|
|
1458
|
-
componentTsdoc?.source === 'script' &&
|
|
1459
|
-
hasHtmlComponentComment(sourceFile.content)) {
|
|
1485
|
+
if (componentDecl.docComment && componentTsdoc?.source === 'script' && htmlComponentComment) {
|
|
1460
1486
|
diagnostics.push({
|
|
1461
1487
|
kind: 'duplicate_comment',
|
|
1462
1488
|
commentType: 'doc_comment',
|