@mdsvex/language-core 0.0.0 → 0.1.0-next.1
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/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/package.json +27 -7
- package/src/_svelte_shims.ts +1 -0
- package/src/completions.ts +242 -0
- package/src/config.ts +521 -0
- package/src/index.ts +31 -0
- package/src/language_plugin.ts +556 -0
- package/src/svelte_plugin.ts +183 -0
- package/test/completions.spec.ts +179 -0
- package/test/config.spec.ts +304 -0
- package/test/language_plugin.spec.ts +236 -0
- package/test/language_service.spec.ts +314 -0
- package/test/ts_harness.ts +168 -0
- package/tsconfig.json +11 -0
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @mdsvex/language-core
|
|
2
|
+
|
|
3
|
+
## 0.1.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#887](https://github.com/pngwn/MDsveX/pull/887) [`ffaf805`](https://github.com/pngwn/MDsveX/commit/ffaf805cd7ac2ebb07c1b5a33896c36e53dc6c67) Thanks [@pngwn](https://github.com/pngwn)! - The editor now knows your templates, replacement components and directives. The Vite plugin writes what it resolved to `node_modules/.mdsvex/manifest.json` and the editor reads it, falling back to an `mdsvex.config.json` like the playground's:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"templates": { "docs": "#lib/templates/Docs.svelte" },
|
|
12
|
+
"components": "#lib/markdown.ts"
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Hovering a replaced element or directive shows its component, and go to definition opens it. The frontmatter `template` key is typed as your template names or `false`. Completions offer template names, the template's props as frontmatter keys and their literal values, and a directive's props as args with their values. Directive args and the frontmatter of a templated document are type-checked against the component's props, and `metadata` is typed by the same YAML parser `compile()` uses. Compile errors such as an unknown template show on their line, and `.svx` files are supported alongside `.pfm`.
|
|
17
|
+
|
|
18
|
+
- [#895](https://github.com/pngwn/MDsveX/pull/895) [`57ecb44`](https://github.com/pngwn/MDsveX/commit/57ecb446b292a3406dcf62550986ed15e1aa2b80) Thanks [@pngwn](https://github.com/pngwn)! - The editor reads live expressions in code as references, so type errors, hover, rename and the unused check work on them. It highlights code as the Vite plugin does unless the plugin renders code plain, and `mdsvex.config.json` takes `highlight: false`. A half-typed live expression is an error on that fence rather than on the whole document.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`60da683`](https://github.com/pngwn/MDsveX/commit/60da68313df11747bdd6235dffc325c30af60cb2), [`8ede5e2`](https://github.com/pngwn/MDsveX/commit/8ede5e2b409511978562fcec3271e7f5182789db), [`b249bf0`](https://github.com/pngwn/MDsveX/commit/b249bf0dbbfdef330e0e78739b7d44176f9c98b9), [`c81604f`](https://github.com/pngwn/MDsveX/commit/c81604f77f7e2662f42db2dcfb1c2a29a594e726), [`ffaf805`](https://github.com/pngwn/MDsveX/commit/ffaf805cd7ac2ebb07c1b5a33896c36e53dc6c67), [`69b6c62`](https://github.com/pngwn/MDsveX/commit/69b6c624256f1e8fb1cf8e5f348980a043f2c1db), [`fa297f9`](https://github.com/pngwn/MDsveX/commit/fa297f9b3fda7cc11c3f4274ba0b0cc27acedf9a), [`311902d`](https://github.com/pngwn/MDsveX/commit/311902de7c606430e3899440d37def14f5190b6c), [`79bebc9`](https://github.com/pngwn/MDsveX/commit/79bebc937b5c51d7fb50d06ff09f83bf23d44a87), [`6c64d8b`](https://github.com/pngwn/MDsveX/commit/6c64d8b7c13c876dc03668123a9dbfcc9520b885), [`ffaf805`](https://github.com/pngwn/MDsveX/commit/ffaf805cd7ac2ebb07c1b5a33896c36e53dc6c67), [`57ecb44`](https://github.com/pngwn/MDsveX/commit/57ecb446b292a3406dcf62550986ed15e1aa2b80), [`1219ceb`](https://github.com/pngwn/MDsveX/commit/1219ceb0c6805ac8b169dadb13694f354d96a619), [`98a1b87`](https://github.com/pngwn/MDsveX/commit/98a1b87b1c45f192c93bf3b910d6ebc8284b94f4), [`31aa6e2`](https://github.com/pngwn/MDsveX/commit/31aa6e20390c6fa656845add1d19e0439dda48c7), [`fd54579`](https://github.com/pngwn/MDsveX/commit/fd5457966ce23d1eb29a7935a550394adf4498e4), [`8bd14fe`](https://github.com/pngwn/MDsveX/commit/8bd14fe77aed1ff532757a06e934fa6238ecb2da), [`98a1b87`](https://github.com/pngwn/MDsveX/commit/98a1b87b1c45f192c93bf3b910d6ebc8284b94f4), [`045aca9`](https://github.com/pngwn/MDsveX/commit/045aca94077183b8b58bb59c45813f0aa4f33cde), [`59bbad3`](https://github.com/pngwn/MDsveX/commit/59bbad3d1905ea378b8745d916af0dca3e63b042), [`f2ff5fe`](https://github.com/pngwn/MDsveX/commit/f2ff5fe144a9009a79e0aa7a6f08f1bed5a7696c), [`57ecb44`](https://github.com/pngwn/MDsveX/commit/57ecb446b292a3406dcf62550986ed15e1aa2b80), [`fd54579`](https://github.com/pngwn/MDsveX/commit/fd5457966ce23d1eb29a7935a550394adf4498e4), [`4c55f5e`](https://github.com/pngwn/MDsveX/commit/4c55f5eea023e687202fa97626b401f09bffd6f7), [`e708e1d`](https://github.com/pngwn/MDsveX/commit/e708e1d4c66478efd8606fa2e1ff2fee40e0732a), [`4927fd8`](https://github.com/pngwn/MDsveX/commit/4927fd87ef00ae106f081cf4315e425ec71a790c), [`98a1b87`](https://github.com/pngwn/MDsveX/commit/98a1b87b1c45f192c93bf3b910d6ebc8284b94f4), [`60da683`](https://github.com/pngwn/MDsveX/commit/60da68313df11747bdd6235dffc325c30af60cb2), [`2867d9b`](https://github.com/pngwn/MDsveX/commit/2867d9b0df02ae44f0475403ce62393bca4f64b9), [`266f24d`](https://github.com/pngwn/MDsveX/commit/266f24d652a2bf03795b5397696790eb016890b4), [`8ede5e2`](https://github.com/pngwn/MDsveX/commit/8ede5e2b409511978562fcec3271e7f5182789db), [`b35c5ff`](https://github.com/pngwn/MDsveX/commit/b35c5ff2011f9b35515edd24a11027c7a410ba56), [`1dceed1`](https://github.com/pngwn/MDsveX/commit/1dceed1b863e202066c943d7b3e463db7e8fdb05), [`c56db79`](https://github.com/pngwn/MDsveX/commit/c56db798f4f43e437956bb3afb2919c09076cd6e), [`57ecb44`](https://github.com/pngwn/MDsveX/commit/57ecb446b292a3406dcf62550986ed15e1aa2b80), [`2927382`](https://github.com/pngwn/MDsveX/commit/29273823dc39bf4ab9b422210ee8acd867c29bc9), [`69b6c62`](https://github.com/pngwn/MDsveX/commit/69b6c624256f1e8fb1cf8e5f348980a043f2c1db), [`ed11417`](https://github.com/pngwn/MDsveX/commit/ed11417775290f85a0b14dda03d1c11d48bbd239)]:
|
|
23
|
+
- @mdsvex/render@1.0.0-next.1
|
|
24
|
+
- mdsvex@1.0.0-next.1
|
|
25
|
+
- @mdsvex/source-map@0.1.0-next.1
|
|
26
|
+
|
|
27
|
+
## 0.1.0-next.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- [#799](https://github.com/pngwn/MDsveX/pull/799) [`5b54692`](https://github.com/pngwn/MDsveX/commit/5b54692d6c895f02c947ce620a46c7a9beb856e9) Thanks [@pngwn](https://github.com/pngwn)! - Add language tools
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [[`6ac3826`](https://github.com/pngwn/MDsveX/commit/6ac382615eb410230e8423d5ca4202005588869e), [`e5b7abe`](https://github.com/pngwn/MDsveX/commit/e5b7abe1ebf868b1df1e934fb96e1e363696f3e9), [`5b54692`](https://github.com/pngwn/MDsveX/commit/5b54692d6c895f02c947ce620a46c7a9beb856e9)]:
|
|
36
|
+
- @mdsvex/render@1.0.0-next.0
|
|
37
|
+
- @mdsvex/source-map@0.1.0-next.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 pngwn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdsvex/language-core",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Placeholder release so npm trusted publishing can be configured.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"homepage": "https://mdsvex.pngwn.io",
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
7
4
|
"repository": {
|
|
8
5
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/pngwn/MDsveX",
|
|
6
|
+
"url": "git+https://github.com/pngwn/MDsveX.git",
|
|
10
7
|
"directory": "language-tools/language-core"
|
|
11
8
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
9
|
+
"description": "PFM Volar LanguagePlugin — teaches Volar how to handle .pfm files",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./src/index.ts",
|
|
14
|
+
"types": "./src/index.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@volar/language-core": "^2.4.28",
|
|
19
|
+
"@volar/typescript": "^2.4.28",
|
|
20
|
+
"svelte2tsx": "^0.7.53",
|
|
21
|
+
"@mdsvex/source-map": "0.1.0-next.1",
|
|
22
|
+
"@mdsvex/render": "1.0.0-next.1",
|
|
23
|
+
"mdsvex": "1.0.0-next.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"svelte": "^5.0.0",
|
|
27
|
+
"typescript": "^5.0.0"
|
|
28
|
+
},
|
|
29
|
+
"author": "pngwn <hello@pngwn.io>",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "vitest --disableConsoleIntercept",
|
|
33
|
+
"test:run": "vitest run --silent"
|
|
14
34
|
}
|
|
15
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SVELTE_SHIMS = "// Whenever a ambient declaration changes, its number should be increased\n// This way, we avoid the situation where multiple ambient versions of svelte2tsx\n// are loaded and their declarations conflict each other\n// See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it\n// If you change anything in this file, think about whether or not it should be backported to svelte-shims.d.ts\n\ntype AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;\n\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteActionReturnType = {\n\tupdate?: (args: any) => void,\n\tdestroy?: () => void\n} | void\n\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteTransitionConfig = {\n delay?: number,\n duration?: number,\n easing?: (t: number) => number,\n css?: (t: number, u: number) => string,\n tick?: (t: number, u: number) => void\n}\n\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)\n\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteAnimationReturnType = {\n delay?: number,\n duration?: number,\n easing?: (t: number) => number,\n css?: (t: number, u: number) => string,\n tick?: (t: number, u: number) => void\n}\n\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteAllProps = { [index: string]: any }\n/** @internal PRIVATE API, DO NOT USE */\ntype SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteRestProps = { [index: string]: any }\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteSlots = { [index: string]: any }\n/** @internal PRIVATE API, DO NOT USE */\ntype SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }\n\n// Forces TypeScript to look into the type which results in a better representation of it\n// which helps for error messages and is necessary for d.ts file transformation so that\n// no ambient type references are left in the output\n/** @internal PRIVATE API, DO NOT USE */\ntype Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;\n\n/** @internal PRIVATE API, DO NOT USE */\ntype KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]\n/** @internal PRIVATE API, DO NOT USE */\ndeclare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}\n\ndeclare function __sveltets_2_ensureRightProps<Props>(props: Props): {};\ndeclare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;\ndeclare function __sveltets_2_allPropsType(): SvelteAllProps\ndeclare function __sveltets_2_restPropsType(): SvelteRestProps\ndeclare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;\n\n// Overload of the following two functions is necessary.\n// An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.\n// optionalProps need to be first or its type cannot be infered correctly.\n\ndeclare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(\n render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }\ndeclare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(\n optionalProps: OptionalProps[],\n render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }\n\ndeclare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(\n render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }\ndeclare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(\n optionalProps: OptionalProps[],\n render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }\n\n\ndeclare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(\n render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n\ndeclare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(\n render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }\n): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots, exports?: Exports, bindings?: Bindings }\n\ndeclare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T\ndeclare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;\ndeclare function __sveltets_2_any(dummy: any): any;\ndeclare function __sveltets_2_invalidate<T>(getValue: () => T): T\n\ndeclare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(\n event: K\n): HTMLBodyElementEventMap[K];\ndeclare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(\n event: K\n): WindowEventMap[K];\ndeclare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(\n event: K\n): HTMLElementEventMap[K];\n\ndeclare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(\n events: Events, eventKey: K\n): Events[K];\ndeclare function __sveltets_2_bubbleEventDef(\n events: any, eventKey: string\n): any;\n\ndeclare const __sveltets_2_customEvent: CustomEvent<any>;\ndeclare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};\n\ndeclare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;\ndeclare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;\ndeclare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;\ndeclare function __sveltets_2_unionType(...types: any[]): any;\n\ndeclare function __sveltets_2_createSvelte2TsxComponent<Props extends {}, Events extends {}, Slots extends {}>(\n render: {props: Props, events: Events, slots: Slots }\n): typeof import(\"svelte\").SvelteComponent<Props, Events, Slots>;\n\ndeclare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T\ndeclare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T\n\n// v2\ndeclare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;\ndeclare function __sveltets_2_createComponentAny(props: Record<string, any>): import(\"svelte\").SvelteComponent<any, any, any>;\n\ndeclare function __sveltets_2_any(...dummy: any[]): any;\ndeclare function __sveltets_2_empty(...dummy: any[]): {};\ndeclare function __sveltets_2_union<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(t1:T1,t2?:T2,t3?:T3,t4?:T4,t5?:T5,t6?:T6,t7?:T7,t8?:T8,t9?:T9,t10?:T10): T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 & T9 & T10;\ndeclare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;\n\ndeclare function __sveltets_2_cssProp(prop: Record<string, any>): {};\n\n// @ts-ignore Svelte v3/v4 don't have this\ndeclare function __sveltets_2_ensureSnippet(val: ReturnType<import('svelte').Snippet> | undefined | null): any;\n\n/** @internal PRIVATE API, DO NOT USE */\ntype __sveltets_2_SvelteAnimationReturnType = {\n delay?: number,\n duration?: number,\n easing?: (t: number) => number,\n css?: (t: number, u: number) => string,\n tick?: (t: number, u: number) => void\n}\ndeclare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }\ndeclare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};\n\n/** @internal PRIVATE API, DO NOT USE */\ntype __sveltets_2_SvelteActionReturnType = {\n\tupdate?: (args: any) => void,\n\tdestroy?: () => void,\n $$_attributes?: Record<string, any>,\n} | void\ndeclare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};\n\n/** @internal PRIVATE API, DO NOT USE */\ntype __sveltets_2_SvelteTransitionConfig = {\n delay?: number,\n duration?: number,\n easing?: (t: number) => number,\n css?: (t: number, u: number) => string,\n tick?: (t: number, u: number) => void\n}\n/** @internal PRIVATE API, DO NOT USE */\ntype __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)\ndeclare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};\n\n// Includes undefined and null for all types as all usages also allow these\ndeclare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};\ndeclare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};\n\n// The following is necessary because there are two clashing errors that can't be solved at the same time\n// when using Svelte2TsxComponent, more precisely the event typings in\n// __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;\n// If we type it as \"any\", we have an error when using sth like {a: CustomEvent<any>}\n// If we type it as \"{}\", we have an error when using sth like {[evt: string]: CustomEvent<any>}\n// If we type it as \"unknown\", we get all kinds of follow up errors which we want to avoid\n// Therefore introduce two more base classes just for this case.\n/**\n * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT\n */\ndeclare type ATypedSvelteComponent = {\n /**\n * @internal This is for type checking capabilities only\n * and does not exist at runtime. Don't use this property.\n */\n $$prop_def: any;\n /**\n * @internal This is for type checking capabilities only\n * and does not exist at runtime. Don't use this property.\n */\n $$events_def: any;\n /**\n * @internal This is for type checking capabilities only\n * and does not exist at runtime. Don't use this property.\n */\n $$slot_def: any;\n\n $on(event: string, handler: any): () => void;\n}\n/**\n * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.\n * \n * If you're looking for the type of a Svelte Component, use `SvelteComponent` and `ComponentType` instead:\n *\n * ```ts\n * import type { ComponentType, SvelteComponent } from \"svelte\";\n * let myComponentConstructor: ComponentType<SvelteComponent> = ..;\n * ```\n */\ndeclare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent\n// Usage note: Cannot properly transform generic function components to class components due to TypeScript limitations\ndeclare function __sveltets_2_ensureComponent<\n T extends\n | ConstructorOfATypedSvelteComponent\n | (typeof import('svelte') extends { mount: any }\n ? // @ts-ignore svelte.Component doesn't exist in Svelte 4\n import('svelte').Component<any, any, any>\n : never)\n | null\n | undefined\n>(\n type: T\n): NonNullable<\n T extends ConstructorOfATypedSvelteComponent\n ? T\n : typeof import('svelte') extends { mount: any }\n ? // @ts-ignore svelte.Component doesn't exist in Svelte 4\n T extends import('svelte').Component<\n infer Props extends Record<string, any>,\n infer Exports extends Record<string, any>,\n infer Bindings extends string\n >\n ? new (\n options: import('svelte').ComponentConstructorOptions<Props>\n ) => import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> &\n Exports & { $$bindings: Bindings }\n : never\n : never\n>;\n\ndeclare function __sveltets_2_ensureArray<T extends ArrayLike<unknown> | Iterable<unknown>>(\n // Svelte 5 allows undefined or null here, Svelte 4 doesn't\n array: T | (typeof import('svelte') extends { mount: any } ? (undefined | null) : never)\n): T extends ArrayLike<infer U> ? U[] : T extends Iterable<infer U> ? Iterable<U> : any[];\n\ntype __sveltets_2_PropsWithChildren<Props, Slots> = Props &\n (Slots extends { default: any }\n // This is unfortunate because it means \"accepts no props\" turns into \"accepts any prop\"\n // but the alternative is non-fixable type errors because of the way TypeScript index\n // signatures work (they will always take precedence and make an impossible-to-satisfy children type).\n ? Props extends Record<string, never>\n ? any\n : { children?: any }\n : {});\ndeclare function __sveltets_2_runes_constructor<Props extends {}>(render: {props: Props }): import(\"svelte\").ComponentConstructorOptions<Props>;\n\ndeclare function __sveltets_2_get_set_binding<T>(get: (() => T) | null | undefined, set: (t: T) => void): T;\n\ndeclare function __sveltets_$$bindings<Bindings extends string[]>(...bindings: Bindings): Bindings[number];\n\ndeclare function __sveltets_2_fn_component<\n Props extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string\n // @ts-ignore Svelte 5 only\n>(klass: {props: Props, exports?: Exports, bindings?: Bindings }): import('svelte').Component<Props, Exports, Bindings>;\n\ninterface __sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {\n new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & { $$bindings?: Bindings } & Exports;\n (internal: unknown, props: Props extends Record<string, never> ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any };\n z_$$bindings?: Bindings;\n}\n\ndeclare function __sveltets_2_isomorphic_component<\n Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string\n>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<Props, Events, Slots, Exports, Bindings>;\n\ndeclare function __sveltets_2_isomorphic_component_slots<\n Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string\n>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;\n";
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* what to complete in frontmatter and directive args, the props come from
|
|
3
|
+
* the type alias pfm_to_svelte emits for each template and directive
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type * as TS from 'typescript';
|
|
7
|
+
import { template_value_at, yaml_keys } from '@mdsvex/source-map/pfm-to-svelte';
|
|
8
|
+
import type { PropsProbe } from '@mdsvex/source-map/pfm-to-svelte';
|
|
9
|
+
|
|
10
|
+
interface Range {
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type CompletionContext =
|
|
16
|
+
| { kind: 'template'; range: Range }
|
|
17
|
+
| { kind: 'frontmatter_key'; range: Range; existing: string[] }
|
|
18
|
+
| { kind: 'frontmatter_value'; key: string; range: Range }
|
|
19
|
+
| {
|
|
20
|
+
kind: 'arg_key';
|
|
21
|
+
directive: string;
|
|
22
|
+
inline: boolean;
|
|
23
|
+
range: Range;
|
|
24
|
+
existing: string[];
|
|
25
|
+
}
|
|
26
|
+
| { kind: 'arg_value'; directive: string; key: string; range: Range };
|
|
27
|
+
|
|
28
|
+
const WORD = /[\w$-]/;
|
|
29
|
+
|
|
30
|
+
function word_end(source: string, at: number): number {
|
|
31
|
+
while (at < source.length && WORD.test(source[at])) at++;
|
|
32
|
+
return at;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function line_of(source: string, offset: number) {
|
|
36
|
+
const start = source.lastIndexOf('\n', offset - 1) + 1;
|
|
37
|
+
let end = source.indexOf('\n', offset);
|
|
38
|
+
if (end < 0) end = source.length;
|
|
39
|
+
return { start, end };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the end of a value token from start, before a comment, separator or space */
|
|
43
|
+
function value_end(source: string, start: number, stop: RegExp): number {
|
|
44
|
+
let at = start;
|
|
45
|
+
const q = source[at];
|
|
46
|
+
if (q === '"' || q === "'") {
|
|
47
|
+
const close = source.indexOf(q, at + 1);
|
|
48
|
+
return close < 0 ? at + 1 : close + 1;
|
|
49
|
+
}
|
|
50
|
+
while (at < source.length && !stop.test(source[at])) at++;
|
|
51
|
+
return at;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// a directive name and label, then the open paren of its args
|
|
55
|
+
const DIRECTIVE =
|
|
56
|
+
/(?<![\w:])(:{1,3})([A-Za-z_][\w-]*)\[(?:[^[\]\n\\]|\\.|\[[^[\]\n]*\])*\]\(/g;
|
|
57
|
+
|
|
58
|
+
/** what the offset completes, null for nothing this module offers */
|
|
59
|
+
export function completion_context(
|
|
60
|
+
source: string,
|
|
61
|
+
offset: number,
|
|
62
|
+
frontmatter: Range | null
|
|
63
|
+
): CompletionContext | null {
|
|
64
|
+
if (
|
|
65
|
+
frontmatter !== null &&
|
|
66
|
+
offset >= frontmatter.start &&
|
|
67
|
+
offset <= frontmatter.end
|
|
68
|
+
) {
|
|
69
|
+
const template = template_value_at(source, offset, frontmatter);
|
|
70
|
+
if (template !== null) return { kind: 'template', range: template };
|
|
71
|
+
const line = line_of(source, offset);
|
|
72
|
+
const before = source.slice(line.start, offset);
|
|
73
|
+
if (/^[A-Za-z_$][\w$-]*$|^$/.test(before)) {
|
|
74
|
+
const end = word_end(source, offset);
|
|
75
|
+
// a key already written on this line takes a value, not a new key
|
|
76
|
+
if (/^[ \t]*:/.test(source.slice(end, line.end))) return null;
|
|
77
|
+
const keys = yaml_keys(
|
|
78
|
+
source.slice(frontmatter.start, frontmatter.end),
|
|
79
|
+
frontmatter.start
|
|
80
|
+
);
|
|
81
|
+
const existing = [...keys.keys()].filter(
|
|
82
|
+
(k) => keys.get(k)!.start !== line.start
|
|
83
|
+
);
|
|
84
|
+
return {
|
|
85
|
+
kind: 'frontmatter_key',
|
|
86
|
+
range: { start: line.start, end },
|
|
87
|
+
existing,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const pair = /^([A-Za-z_$][\w$-]*)[ \t]*:[ \t]*(\S*)$/.exec(before);
|
|
91
|
+
if (pair === null) return null;
|
|
92
|
+
const start = offset - pair[2].length;
|
|
93
|
+
return {
|
|
94
|
+
kind: 'frontmatter_value',
|
|
95
|
+
key: pair[1],
|
|
96
|
+
range: {
|
|
97
|
+
start,
|
|
98
|
+
end: Math.max(offset, value_end(source, start, /[\s#]/)),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const line = line_of(source, offset);
|
|
104
|
+
const text = source.slice(line.start, line.end);
|
|
105
|
+
DIRECTIVE.lastIndex = 0;
|
|
106
|
+
let m: RegExpExecArray | null;
|
|
107
|
+
while ((m = DIRECTIVE.exec(text)) !== null) {
|
|
108
|
+
const args_start = line.start + m.index + m[0].length;
|
|
109
|
+
const close = text.indexOf(')', args_start - line.start);
|
|
110
|
+
const args_end = close < 0 ? line.end : line.start + close;
|
|
111
|
+
if (offset < args_start || offset > args_end) continue;
|
|
112
|
+
const args = source.slice(args_start, args_end);
|
|
113
|
+
const before = source.slice(args_start, offset);
|
|
114
|
+
const segment_start = args_start + before.lastIndexOf(',') + 1;
|
|
115
|
+
const segment = source.slice(segment_start, offset);
|
|
116
|
+
const eq = segment.indexOf('=');
|
|
117
|
+
if (eq >= 0) {
|
|
118
|
+
let start = segment_start + eq + 1;
|
|
119
|
+
while (start < offset && /[ \t]/.test(source[start])) start++;
|
|
120
|
+
return {
|
|
121
|
+
kind: 'arg_value',
|
|
122
|
+
directive: m[2],
|
|
123
|
+
key: segment.slice(0, eq).trim(),
|
|
124
|
+
range: {
|
|
125
|
+
start,
|
|
126
|
+
end: Math.max(offset, value_end(source, start, /[\s,)]/)),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
let start = segment_start;
|
|
131
|
+
while (start < offset && /[ \t]/.test(source[start])) start++;
|
|
132
|
+
const existing: string[] = [];
|
|
133
|
+
for (const k of args.matchAll(/([A-Za-z_][\w-]*)[ \t]*=/g))
|
|
134
|
+
if (args_start + k.index! !== start) existing.push(k[1]);
|
|
135
|
+
return {
|
|
136
|
+
kind: 'arg_key',
|
|
137
|
+
directive: m[2],
|
|
138
|
+
inline: m[1].length === 1,
|
|
139
|
+
range: { start, end: word_end(source, offset) },
|
|
140
|
+
existing,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** the template a frontmatter names, undefined when it names none */
|
|
147
|
+
export function template_named(
|
|
148
|
+
source: string,
|
|
149
|
+
frontmatter: Range | null
|
|
150
|
+
): string | false | undefined {
|
|
151
|
+
if (frontmatter === null) return undefined;
|
|
152
|
+
const m =
|
|
153
|
+
/^(["']?)template\1[ \t]*:[ \t]*(["']?)([^"'#\n]*?)\2[ \t]*(?:#.*)?$/m.exec(
|
|
154
|
+
source.slice(frontmatter.start, frontmatter.end)
|
|
155
|
+
);
|
|
156
|
+
if (m === null || m[3] === '') return undefined;
|
|
157
|
+
return m[3] === 'false' ? false : m[3];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** the probe of a template, or of a directive in the scope of a template */
|
|
161
|
+
export function probe_for(
|
|
162
|
+
probes: PropsProbe[],
|
|
163
|
+
kind: PropsProbe['kind'],
|
|
164
|
+
name: string,
|
|
165
|
+
template: string | undefined
|
|
166
|
+
): PropsProbe | undefined {
|
|
167
|
+
if (kind === 'template')
|
|
168
|
+
return probes.find((p) => p.kind === 'template' && p.name === name);
|
|
169
|
+
return (
|
|
170
|
+
probes.find(
|
|
171
|
+
(p) =>
|
|
172
|
+
p.kind === 'directive' && p.name === name && p.template === template
|
|
173
|
+
) ??
|
|
174
|
+
probes.find(
|
|
175
|
+
(p) =>
|
|
176
|
+
p.kind === 'directive' && p.name === name && p.template === undefined
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface Prop {
|
|
182
|
+
name: string;
|
|
183
|
+
/** the type as typescript prints it */
|
|
184
|
+
type: string;
|
|
185
|
+
optional: boolean;
|
|
186
|
+
documentation: string;
|
|
187
|
+
/** the literal values the type allows, as yaml or an arg writes them */
|
|
188
|
+
values: string[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** the props a probe names, null when the program does not hold it */
|
|
192
|
+
export function props_of(
|
|
193
|
+
ts: typeof TS,
|
|
194
|
+
program: TS.Program,
|
|
195
|
+
file: string,
|
|
196
|
+
alias: string
|
|
197
|
+
): Prop[] | null {
|
|
198
|
+
const sf = program.getSourceFile(file);
|
|
199
|
+
if (sf === undefined) return null;
|
|
200
|
+
let found: TS.TypeAliasDeclaration | undefined;
|
|
201
|
+
const visit = (node: TS.Node): void => {
|
|
202
|
+
if (found) return;
|
|
203
|
+
if (ts.isTypeAliasDeclaration(node) && node.name.text === alias)
|
|
204
|
+
found = node;
|
|
205
|
+
else ts.forEachChild(node, visit);
|
|
206
|
+
};
|
|
207
|
+
visit(sf);
|
|
208
|
+
if (found === undefined) return null;
|
|
209
|
+
const checker = program.getTypeChecker();
|
|
210
|
+
const type = checker.getTypeFromTypeNode(found.type);
|
|
211
|
+
if (type.flags & ts.TypeFlags.Any) return null;
|
|
212
|
+
const props: Prop[] = [];
|
|
213
|
+
for (const symbol of checker.getPropertiesOfType(type)) {
|
|
214
|
+
const prop_type = checker.getTypeOfSymbolAtLocation(symbol, found);
|
|
215
|
+
props.push({
|
|
216
|
+
name: symbol.name,
|
|
217
|
+
type: checker.typeToString(
|
|
218
|
+
checker.getNonNullableType(prop_type),
|
|
219
|
+
found,
|
|
220
|
+
ts.TypeFormatFlags.NoTruncation
|
|
221
|
+
),
|
|
222
|
+
optional: (symbol.flags & ts.SymbolFlags.Optional) !== 0,
|
|
223
|
+
documentation: ts.displayPartsToString(
|
|
224
|
+
symbol.getDocumentationComment(checker)
|
|
225
|
+
),
|
|
226
|
+
values: literal_values(ts, prop_type),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return props;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function literal_values(ts: typeof TS, type: TS.Type): string[] {
|
|
233
|
+
const parts = type.isUnion() ? type.types : [type];
|
|
234
|
+
const values: string[] = [];
|
|
235
|
+
for (const t of parts) {
|
|
236
|
+
if (t.isStringLiteral()) values.push(t.value);
|
|
237
|
+
else if (t.isNumberLiteral()) values.push(String(t.value));
|
|
238
|
+
else if (t.flags & ts.TypeFlags.BooleanLiteral)
|
|
239
|
+
values.push((t as { intrinsicName?: string }).intrinsicName ?? '');
|
|
240
|
+
}
|
|
241
|
+
return values.filter((v) => v !== '');
|
|
242
|
+
}
|