Upload folder using huggingface_hub (part 50)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tools/ui/node_modules/svelte-ast-print/LICENSE.md +19 -0
- tools/ui/node_modules/svelte-ast-print/README.md +248 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/LICENSE +7 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/README.md +57 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/package.json +39 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/src/handlers.js +1265 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/src/index.js +179 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/src/types.d.ts +53 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/types/index.d.ts +16 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/esrap/types/index.d.ts.map +14 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/LICENSE +21 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/README.md +180 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/package.json +34 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/src/index.d.ts +2 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/src/types.d.ts +21 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/src/walk.js +159 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/types/index.d.ts +28 -0
- tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/types/index.d.ts.map +19 -0
- tools/ui/node_modules/svelte-ast-print/package.json +130 -0
- tools/ui/node_modules/svelte-ast-print/src/mod.js +1587 -0
- tools/ui/node_modules/svelte-ast-print/src/nodes.js +247 -0
- tools/ui/node_modules/svelte-ast-print/src/options.js +107 -0
- tools/ui/node_modules/svelte-ast-print/types/mod.d.ts +142 -0
- tools/ui/node_modules/svelte-ast-print/types/mod.d.ts.map +30 -0
- tools/ui/node_modules/svelte-check/LICENSE +7 -0
- tools/ui/node_modules/svelte-check/README.md +136 -0
- tools/ui/node_modules/svelte-check/bin/svelte-check +2 -0
- tools/ui/node_modules/svelte-check/dist/src/index.js +0 -0
- tools/ui/node_modules/svelte-check/dist/src/svelte-jsx-v4.d.ts +230 -0
- tools/ui/node_modules/svelte-check/dist/src/svelte-jsx.d.ts +1492 -0
- tools/ui/node_modules/svelte-check/dist/src/svelte-native-jsx.d.ts +32 -0
- tools/ui/node_modules/svelte-check/dist/src/svelte-shims-v4.d.ts +290 -0
- tools/ui/node_modules/svelte-check/dist/src/svelte-shims.d.ts +305 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/LICENSE +21 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/README.md +305 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/handler.d.ts +90 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/handler.js +629 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/index.d.ts +215 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/index.js +798 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/package.json +1 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/handler.d.ts +90 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/handler.js +635 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/index.d.ts +215 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/index.js +804 -0
- tools/ui/node_modules/svelte-check/node_modules/chokidar/package.json +69 -0
- tools/ui/node_modules/svelte-check/node_modules/readdirp/LICENSE +21 -0
- tools/ui/node_modules/svelte-check/node_modules/readdirp/README.md +120 -0
- tools/ui/node_modules/svelte-check/node_modules/readdirp/esm/index.d.ts +108 -0
- tools/ui/node_modules/svelte-check/node_modules/readdirp/esm/index.js +257 -0
- tools/ui/node_modules/svelte-check/node_modules/readdirp/esm/package.json +1 -0
tools/ui/node_modules/svelte-ast-print/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024-present [these people](https://github.com/xeho91/svelte-ast-print/graphs/contributors)
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge,
|
| 6 |
+
to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
| 7 |
+
to deal in the Software without restriction,
|
| 8 |
+
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 9 |
+
and/or sell copies of the Software,
|
| 10 |
+
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 13 |
+
|
| 14 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
| 15 |
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 17 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 18 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
| 19 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
tools/ui/node_modules/svelte-ast-print/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# `svelte-ast-print`
|
| 2 |
+
|
| 3 |
+

|
| 4 |
+
|
| 5 |
+
Print **Svelte [AST]** nodes as a string.\
|
| 6 |
+
A.k.a. [`parse`] in reverse.
|
| 7 |
+
|
| 8 |
+
This is what you need to create [codemods] - e.g. for migration between Svelte versions syntaxes.
|
| 9 |
+
|
| 10 |
+
## Documentation
|
| 11 |
+
|
| 12 |
+
<https://xeho91.github.io/svelte-ast-print>
|
| 13 |
+
|
| 14 |
+
## Acknowledgements
|
| 15 |
+
|
| 16 |
+
This package depends on:
|
| 17 |
+
|
| 18 |
+
1. [`esrap`] for printing [ESTree] specification-compliant [AST] nodes
|
| 19 |
+
1. [`zimmerframe`] for walking on the [AST] nodes
|
| 20 |
+
|
| 21 |
+
## Limitations
|
| 22 |
+
|
| 23 |
+
> [!WARNING]
|
| 24 |
+
> **TypeScript isn't supported**, yet.\
|
| 25 |
+
> See & subscribe to progress on [issue #86 - Add support for TypeScript](https://github.com/xeho91/svelte-ast-print/issues/86).
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
> [!IMPORTANT]
|
| 30 |
+
> **It ignores any previous formatting**.\
|
| 31 |
+
> The current focus is to be able to write codemods as soon as possible - because right now, there are no alternatives.
|
| 32 |
+
>
|
| 33 |
+
> If you need to format modified and stringified Svelte AST, use available formatters for Svelte:
|
| 34 |
+
>
|
| 35 |
+
> - [Biome](https://github.com/biomejs/biome) - _⚠️ has partial support_
|
| 36 |
+
> - [Prettier](https://github.com/prettier/prettier) with [`prettier-plugin-svelte`](https://github.com/sveltejs/prettier-plugin-svelte)
|
| 37 |
+
>
|
| 38 |
+
> See [Formatting](#formatting) section for examples.
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
> [!NOTE]
|
| 43 |
+
> **This package is in beta stage.**\
|
| 44 |
+
> See [Roadmap](https://github.com/xeho91/svelte-ast-print/discussions/2)
|
| 45 |
+
|
| 46 |
+
## Getting started
|
| 47 |
+
|
| 48 |
+
1. Use the package manager of your choice to install this package:
|
| 49 |
+
|
| 50 |
+
<details>
|
| 51 |
+
<summary>npm</summary>
|
| 52 |
+
|
| 53 |
+
```sh
|
| 54 |
+
npm install svelte-ast-print
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
</details>
|
| 58 |
+
|
| 59 |
+
<details>
|
| 60 |
+
<summary>yarn</summary>
|
| 61 |
+
|
| 62 |
+
```sh
|
| 63 |
+
yarn add svelte-ast-print
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
</details>
|
| 67 |
+
|
| 68 |
+
<details>
|
| 69 |
+
<summary>pnpm</summary>
|
| 70 |
+
|
| 71 |
+
```sh
|
| 72 |
+
pnpm add svelte-ast-print
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
</details>
|
| 76 |
+
|
| 77 |
+
<details>
|
| 78 |
+
<summary>bun</summary>
|
| 79 |
+
|
| 80 |
+
```sh
|
| 81 |
+
bun add svelte-ast-print
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
</details>
|
| 85 |
+
|
| 86 |
+
1. Incorporate it into your project, for example using Node.js and with the Svelte [`parse`] method:
|
| 87 |
+
|
| 88 |
+
```ts
|
| 89 |
+
import fs from "node:fs";
|
| 90 |
+
|
| 91 |
+
import { print } from "svelte-ast-print";
|
| 92 |
+
import { parse } from "svelte/compiler";
|
| 93 |
+
|
| 94 |
+
const originalSvelteCode = fs.readFileSync("src/App.svelte", "utf-8");
|
| 95 |
+
let svelteAST = parse(originalSvelteCode, { modern: true });
|
| 96 |
+
// 👆 For now, only modern is supported.
|
| 97 |
+
// By default is 'false'.
|
| 98 |
+
// Is it planned to be 'true' from Svelte v6+
|
| 99 |
+
|
| 100 |
+
// ...
|
| 101 |
+
// Do some modifications on this AST...
|
| 102 |
+
// e.g. transform `<slot />` to `{@render children()}`
|
| 103 |
+
// ...
|
| 104 |
+
|
| 105 |
+
const output = print(svelteAST); // AST is now a stringified code output! 🎉
|
| 106 |
+
|
| 107 |
+
fs.writeFileSync("src/App.svelte", output, { encoding: " utf-8" });
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
> [!IMPORTANT]
|
| 111 |
+
> When using [`parse`] from `svelte`, please remember about passing `modern: true` to options _(second argument)_.
|
| 112 |
+
> This option is only available starting `svelte@5`\
|
| 113 |
+
> Example:
|
| 114 |
+
>
|
| 115 |
+
> ```js
|
| 116 |
+
> import { parse } from "svelte/compiler";
|
| 117 |
+
>
|
| 118 |
+
> parse(code, { modern: true });
|
| 119 |
+
> // 👆 Don't forget about this
|
| 120 |
+
> ```
|
| 121 |
+
>
|
| 122 |
+
> You can omit it from Svelte `v6` - [source](https://github.com/sveltejs/svelte/blob/5a05f6371a994286626a44168cb2c02f8a2ad567/packages/svelte/src/compiler/index.js#L99-L100).
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## Formatting
|
| 127 |
+
|
| 128 |
+
Until the package will support formatting feature option... below are the current and **simplified** workaround examples
|
| 129 |
+
on how to get printed output formatted to your needs.
|
| 130 |
+
|
| 131 |
+
### Prettier
|
| 132 |
+
|
| 133 |
+
Two dependencies are required:
|
| 134 |
+
|
| 135 |
+
1. [`prettier`](https://github.com/prettier/prettier)
|
| 136 |
+
1. [`prettier-plugin-svelte`](https://github.com/sveltejs/prettier-plugin-svelte)
|
| 137 |
+
|
| 138 |
+
Follow `prettier-plugin-svelte` [Setup guide](https://github.com/sveltejs/prettier-plugin-svelte?tab=readme-ov-file#setup)
|
| 139 |
+
on how to configure Prettier for Svelte.
|
| 140 |
+
|
| 141 |
+
#### Using Prettier API
|
| 142 |
+
|
| 143 |
+
```js
|
| 144 |
+
import { format } from "prettier";
|
| 145 |
+
import { parse } from "svelte/compiler";
|
| 146 |
+
import { print } from "svelte-ast-print";
|
| 147 |
+
|
| 148 |
+
let code = "..." // 👈 Raw Svelte code
|
| 149 |
+
let ast = parse(code, { modern: true });
|
| 150 |
+
// 👆 Don't forget about this, you can omit in Svelte v6
|
| 151 |
+
|
| 152 |
+
// .. work with AST - transformations, etc. ...
|
| 153 |
+
|
| 154 |
+
const output = print(ast);
|
| 155 |
+
const formatted = await format(output {
|
| 156 |
+
// Two ways to provide options:
|
| 157 |
+
|
| 158 |
+
// 1. provide file path to prettier config
|
| 159 |
+
filepath: "path/to/your/prettier/config/file",
|
| 160 |
+
|
| 161 |
+
// or..
|
| 162 |
+
|
| 163 |
+
// 2. See `prettier-plugin-svelte` Setup guide for more info
|
| 164 |
+
parser: "svelte",
|
| 165 |
+
plugins: ["svelte-plugin-prettier"]
|
| 166 |
+
});
|
| 167 |
+
```
|
| 168 |
+
|
| 169 |
+
#### Using Prettier CLI
|
| 170 |
+
|
| 171 |
+
... and Node.js API.
|
| 172 |
+
|
| 173 |
+
```js
|
| 174 |
+
import fs from "node:fs";
|
| 175 |
+
import childProcess from "node:child_process";
|
| 176 |
+
|
| 177 |
+
import { parse } from "svelte/compiler";
|
| 178 |
+
import { print } from "svelte-ast-print";
|
| 179 |
+
|
| 180 |
+
const code = fs.readFileSync("./Button.svelte", "utf-8");
|
| 181 |
+
let ast = parse(code, { modern: true });
|
| 182 |
+
// 👆 Don't forget about this, you can omit in Svelte v6
|
| 183 |
+
|
| 184 |
+
// .. work with AST - transformations, etc. ...
|
| 185 |
+
|
| 186 |
+
const output = print(ast);
|
| 187 |
+
|
| 188 |
+
fs.writeFileSync("./Button.svelte", output, "utf-8");
|
| 189 |
+
childProcess.spawnSync("prettier", ["./Button.svelte", "--write"], {
|
| 190 |
+
stdio: "inherit",
|
| 191 |
+
encoding: "utf-8",
|
| 192 |
+
});
|
| 193 |
+
```
|
| 194 |
+
|
| 195 |
+
### Biome
|
| 196 |
+
|
| 197 |
+
> [!WARNING]
|
| 198 |
+
> This sub-section is incomplete. Feel free to contribute!
|
| 199 |
+
|
| 200 |
+
---
|
| 201 |
+
|
| 202 |
+
## Contributing
|
| 203 |
+
|
| 204 |
+
Take a look at [contributing guide](./.github/CONTRIBUTING.md).
|
| 205 |
+
|
| 206 |
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
|
| 207 |
+
**Contributions of any kind are welcome!**
|
| 208 |
+
|
| 209 |
+
💌 to these people:
|
| 210 |
+
|
| 211 |
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
| 212 |
+
<!-- prettier-ignore-start -->
|
| 213 |
+
<!-- markdownlint-disable -->
|
| 214 |
+
<table>
|
| 215 |
+
<tr>
|
| 216 |
+
<td align="center"><a href="https://github.com/xeho91"><img src="https://avatars.githubusercontent.com/u/18627568?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mateusz Kadlubowski</b></sub></a><br /><a href="https://github.com/xeho91/svelte-ast-print/commits?author=xeho91" title="Code">💻</a> <a href="#maintenance-xeho91" title="Maintenance">🚧</a> <a href="https://github.com/xeho91/svelte-ast-print/commits?author=xeho91" title="Documentation">📖</a> <a href="#infra-xeho91" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/xeho91/svelte-ast-print/commits?author=xeho91" title="Tests">⚠️</a></td>
|
| 217 |
+
<td align="center"><a href="https://github.com/manuel3108"><img src="https://avatars.githubusercontent.com/u/30698007?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Manuel</b></sub></a><br /><a href="https://github.com/xeho91/svelte-ast-print/commits?author=manuel3108" title="Documentation">📖</a></td>
|
| 218 |
+
<td align="center"><a href="https://reinhold.is/"><img src="https://avatars.githubusercontent.com/u/5678122?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeppe Reinhold</b></sub></a><br /><a href="https://github.com/xeho91/svelte-ast-print/commits?author=JReinhold" title="Code">💻</a></td>
|
| 219 |
+
</tr>
|
| 220 |
+
</table>
|
| 221 |
+
|
| 222 |
+
<!-- markdownlint-restore -->
|
| 223 |
+
<!-- prettier-ignore-end -->
|
| 224 |
+
|
| 225 |
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
| 226 |
+
|
| 227 |
+
## Support
|
| 228 |
+
|
| 229 |
+
If you don't have time, but you need this project to work, or resolve an existing issue, consider sponsorship.
|
| 230 |
+
|
| 231 |
+
## Author
|
| 232 |
+
|
| 233 |
+
Mateusz "[xeho91](https://github.com/xeho91)" Kadlubowski
|
| 234 |
+
|
| 235 |
+
## License
|
| 236 |
+
|
| 237 |
+

|
| 238 |
+
|
| 239 |
+
This project is licensed under the [MIT License](./LICENSE.md).
|
| 240 |
+
|
| 241 |
+
<!-- links -->
|
| 242 |
+
|
| 243 |
+
[`esrap`]: https://github.com/rich-harris/esrap
|
| 244 |
+
[`zimmerframe`]: https://github.com/rich-harris/zimmerframe
|
| 245 |
+
[ESTree]: https://github.com/estree/estree
|
| 246 |
+
[codemods]: https://codemod.com/blog/what-are-codemods#ill-find-replace-whats-the-issue-hint-a-lot
|
| 247 |
+
[`parse`]: https://svelte.dev/docs/svelte-compiler#parse
|
| 248 |
+
[AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2023 [these people](https://github.com/Rich-Harris/esrap/graphs/contributors)
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 4 |
+
|
| 5 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 6 |
+
|
| 7 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# esrap
|
| 2 |
+
|
| 3 |
+
Parse in reverse. AST goes in, code comes out.
|
| 4 |
+
|
| 5 |
+
## Usage
|
| 6 |
+
|
| 7 |
+
```js
|
| 8 |
+
import { print } from 'esrap';
|
| 9 |
+
|
| 10 |
+
const { code, map } = print({
|
| 11 |
+
type: 'Program',
|
| 12 |
+
body: [
|
| 13 |
+
{
|
| 14 |
+
type: 'ExpressionStatement',
|
| 15 |
+
expression: {
|
| 16 |
+
callee: {
|
| 17 |
+
type: 'Identifier',
|
| 18 |
+
name: 'alert'
|
| 19 |
+
},
|
| 20 |
+
arguments: [
|
| 21 |
+
{
|
| 22 |
+
type: 'Literal',
|
| 23 |
+
value: 'hello world!'
|
| 24 |
+
}
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
]
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
console.log(code); // alert('hello world!');
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
If the nodes of the input AST have `loc` properties (e.g. the AST was generated with [`acorn`](https://github.com/acornjs/acorn/tree/master/acorn/#interface) with the `locations` option set), sourcemap mappings will be created.
|
| 35 |
+
|
| 36 |
+
## Options
|
| 37 |
+
|
| 38 |
+
You can pass information that will be added to the resulting sourcemap (note that the AST is assumed to come from a single file):
|
| 39 |
+
|
| 40 |
+
```js
|
| 41 |
+
const { code, map } = print(ast, {
|
| 42 |
+
sourceMapSource: 'input.js',
|
| 43 |
+
sourceMapContent: fs.readFileSync('input.js', 'utf-8')
|
| 44 |
+
});
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Why not just use Prettier?
|
| 48 |
+
|
| 49 |
+
Because it's ginormous.
|
| 50 |
+
|
| 51 |
+
## Developing
|
| 52 |
+
|
| 53 |
+
This repo uses [Bun](https://bun.sh/). Once it's installed, do `bun install` to install dependencies, and `bun test` to run the tests.
|
| 54 |
+
|
| 55 |
+
## License
|
| 56 |
+
|
| 57 |
+
[MIT](LICENSE)
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "esrap",
|
| 3 |
+
"version": "1.2.2",
|
| 4 |
+
"description": "Parse in reverse",
|
| 5 |
+
"repository": {
|
| 6 |
+
"type": "git",
|
| 7 |
+
"url": "https://github.com/Rich-Harris/esrap"
|
| 8 |
+
},
|
| 9 |
+
"type": "module",
|
| 10 |
+
"files": [
|
| 11 |
+
"src",
|
| 12 |
+
"types"
|
| 13 |
+
],
|
| 14 |
+
"exports": {
|
| 15 |
+
".": {
|
| 16 |
+
"types": "./types/index.d.ts",
|
| 17 |
+
"default": "./src/index.js"
|
| 18 |
+
}
|
| 19 |
+
},
|
| 20 |
+
"types": "./types/index.d.ts",
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"acorn": "^8.10.0",
|
| 23 |
+
"bun-types": "^1.0.9",
|
| 24 |
+
"dts-buddy": "^0.2.4",
|
| 25 |
+
"prettier": "^3.0.3",
|
| 26 |
+
"typescript": "^5.2.2",
|
| 27 |
+
"zimmerframe": "^1.0.0"
|
| 28 |
+
},
|
| 29 |
+
"scripts": {
|
| 30 |
+
"check": "tsc",
|
| 31 |
+
"prepublishOnly": "bun test && dts-buddy",
|
| 32 |
+
"sandbox": "bun run test/sandbox/index.js"
|
| 33 |
+
},
|
| 34 |
+
"license": "MIT",
|
| 35 |
+
"dependencies": {
|
| 36 |
+
"@jridgewell/sourcemap-codec": "^1.4.15",
|
| 37 |
+
"@types/estree": "^1.0.1"
|
| 38 |
+
}
|
| 39 |
+
}
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/src/handlers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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('./types').Newline} */
|
| 2 |
+
const newline = { type: 'Newline' };
|
| 3 |
+
|
| 4 |
+
/** @type {import('./types').Indent} */
|
| 5 |
+
const indent = { type: 'Indent' };
|
| 6 |
+
|
| 7 |
+
/** @type {import('./types').Dedent} */
|
| 8 |
+
const dedent = { type: 'Dedent' };
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* @param {import('./types').Command[]} children
|
| 12 |
+
* @returns {import('./types').Sequence}
|
| 13 |
+
*/
|
| 14 |
+
function create_sequence(...children) {
|
| 15 |
+
return { type: 'Sequence', children };
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Rough estimate of the combined width of a group of commands
|
| 20 |
+
* @param {import('./types').Command[]} commands
|
| 21 |
+
* @param {number} from
|
| 22 |
+
* @param {number} to
|
| 23 |
+
*/
|
| 24 |
+
function measure(commands, from, to = commands.length) {
|
| 25 |
+
let total = 0;
|
| 26 |
+
for (let i = from; i < to; i += 1) {
|
| 27 |
+
const command = commands[i];
|
| 28 |
+
if (typeof command === 'string') {
|
| 29 |
+
total += command.length;
|
| 30 |
+
} else if (command.type === 'Chunk') {
|
| 31 |
+
total += command.content.length;
|
| 32 |
+
} else if (command.type === 'Sequence') {
|
| 33 |
+
// assume this is ', '
|
| 34 |
+
total += 2;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return total;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* @param {import('estree').Node} node
|
| 43 |
+
* @param {import('./types').State} state
|
| 44 |
+
*/
|
| 45 |
+
export function handle(node, state) {
|
| 46 |
+
const handler = handlers[node.type];
|
| 47 |
+
|
| 48 |
+
if (!handler) {
|
| 49 |
+
throw new Error(`Not implemented ${node.type}`);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (node.leadingComments) {
|
| 53 |
+
prepend_comments(node.leadingComments, state, false);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// @ts-expect-error
|
| 57 |
+
handler(node, state);
|
| 58 |
+
|
| 59 |
+
if (node.trailingComments) {
|
| 60 |
+
state.comments.push(node.trailingComments[0]); // there is only ever one
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* @param {string} content
|
| 66 |
+
* @param {import('estree').Node} node
|
| 67 |
+
* @returns {import('./types').Chunk}
|
| 68 |
+
*/
|
| 69 |
+
function c(content, node) {
|
| 70 |
+
return {
|
| 71 |
+
type: 'Chunk',
|
| 72 |
+
content,
|
| 73 |
+
loc: node?.loc ?? null
|
| 74 |
+
};
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
/**
|
| 78 |
+
* @param {import('estree').Comment[]} comments
|
| 79 |
+
* @param {import('./types').State} state
|
| 80 |
+
* @param {boolean} newlines
|
| 81 |
+
*/
|
| 82 |
+
function prepend_comments(comments, state, newlines) {
|
| 83 |
+
for (const comment of comments) {
|
| 84 |
+
state.commands.push({ type: 'Comment', comment });
|
| 85 |
+
|
| 86 |
+
if (newlines || comment.type === 'Line' || /\n/.test(comment.value)) {
|
| 87 |
+
state.commands.push(newline);
|
| 88 |
+
} else {
|
| 89 |
+
state.commands.push(' ');
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
const OPERATOR_PRECEDENCE = {
|
| 95 |
+
'||': 2,
|
| 96 |
+
'&&': 3,
|
| 97 |
+
'??': 4,
|
| 98 |
+
'|': 5,
|
| 99 |
+
'^': 6,
|
| 100 |
+
'&': 7,
|
| 101 |
+
'==': 8,
|
| 102 |
+
'!=': 8,
|
| 103 |
+
'===': 8,
|
| 104 |
+
'!==': 8,
|
| 105 |
+
'<': 9,
|
| 106 |
+
'>': 9,
|
| 107 |
+
'<=': 9,
|
| 108 |
+
'>=': 9,
|
| 109 |
+
in: 9,
|
| 110 |
+
instanceof: 9,
|
| 111 |
+
'<<': 10,
|
| 112 |
+
'>>': 10,
|
| 113 |
+
'>>>': 10,
|
| 114 |
+
'+': 11,
|
| 115 |
+
'-': 11,
|
| 116 |
+
'*': 12,
|
| 117 |
+
'%': 12,
|
| 118 |
+
'/': 12,
|
| 119 |
+
'**': 13
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
/** @type {Record<import('estree').Expression['type'] | 'Super' | 'RestElement', number>} */
|
| 123 |
+
const EXPRESSIONS_PRECEDENCE = {
|
| 124 |
+
ArrayExpression: 20,
|
| 125 |
+
TaggedTemplateExpression: 20,
|
| 126 |
+
ThisExpression: 20,
|
| 127 |
+
Identifier: 20,
|
| 128 |
+
Literal: 18,
|
| 129 |
+
TemplateLiteral: 20,
|
| 130 |
+
Super: 20,
|
| 131 |
+
SequenceExpression: 20,
|
| 132 |
+
MemberExpression: 19,
|
| 133 |
+
MetaProperty: 19,
|
| 134 |
+
CallExpression: 19,
|
| 135 |
+
ChainExpression: 19,
|
| 136 |
+
ImportExpression: 19,
|
| 137 |
+
NewExpression: 19,
|
| 138 |
+
AwaitExpression: 17,
|
| 139 |
+
ClassExpression: 17,
|
| 140 |
+
FunctionExpression: 17,
|
| 141 |
+
ObjectExpression: 17,
|
| 142 |
+
UpdateExpression: 16,
|
| 143 |
+
UnaryExpression: 15,
|
| 144 |
+
BinaryExpression: 14,
|
| 145 |
+
LogicalExpression: 13,
|
| 146 |
+
ConditionalExpression: 4,
|
| 147 |
+
ArrowFunctionExpression: 3,
|
| 148 |
+
AssignmentExpression: 3,
|
| 149 |
+
YieldExpression: 2,
|
| 150 |
+
RestElement: 1
|
| 151 |
+
};
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
*
|
| 155 |
+
* @param {import('estree').Expression} node
|
| 156 |
+
* @param {import('estree').BinaryExpression | import('estree').LogicalExpression} parent
|
| 157 |
+
* @param {boolean} is_right
|
| 158 |
+
* @returns
|
| 159 |
+
*/
|
| 160 |
+
function needs_parens(node, parent, is_right) {
|
| 161 |
+
// special case where logical expressions and coalesce expressions cannot be mixed,
|
| 162 |
+
// either of them need to be wrapped with parentheses
|
| 163 |
+
if (
|
| 164 |
+
node.type === 'LogicalExpression' &&
|
| 165 |
+
parent.type === 'LogicalExpression' &&
|
| 166 |
+
((parent.operator === '??' && node.operator !== '??') ||
|
| 167 |
+
(parent.operator !== '??' && node.operator === '??'))
|
| 168 |
+
) {
|
| 169 |
+
return true;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
const precedence = EXPRESSIONS_PRECEDENCE[node.type];
|
| 173 |
+
const parent_precedence = EXPRESSIONS_PRECEDENCE[parent.type];
|
| 174 |
+
|
| 175 |
+
if (precedence !== parent_precedence) {
|
| 176 |
+
// Different node types
|
| 177 |
+
return (
|
| 178 |
+
(!is_right && precedence === 15 && parent_precedence === 14 && parent.operator === '**') ||
|
| 179 |
+
precedence < parent_precedence
|
| 180 |
+
);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
if (precedence !== 13 && precedence !== 14) {
|
| 184 |
+
// Not a `LogicalExpression` or `BinaryExpression`
|
| 185 |
+
return false;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
if (
|
| 189 |
+
/** @type {import('estree').BinaryExpression} */ (node).operator === '**' &&
|
| 190 |
+
parent.operator === '**'
|
| 191 |
+
) {
|
| 192 |
+
// Exponentiation operator has right-to-left associativity
|
| 193 |
+
return !is_right;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
if (is_right) {
|
| 197 |
+
// Parenthesis are used if both operators have the same precedence
|
| 198 |
+
return (
|
| 199 |
+
OPERATOR_PRECEDENCE[/** @type {import('estree').BinaryExpression} */ (node).operator] <=
|
| 200 |
+
OPERATOR_PRECEDENCE[parent.operator]
|
| 201 |
+
);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
return (
|
| 205 |
+
OPERATOR_PRECEDENCE[/** @type {import('estree').BinaryExpression} */ (node).operator] <
|
| 206 |
+
OPERATOR_PRECEDENCE[parent.operator]
|
| 207 |
+
);
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/** @param {import('estree').Node} node */
|
| 211 |
+
function has_call_expression(node) {
|
| 212 |
+
while (node) {
|
| 213 |
+
if (node.type === 'CallExpression') {
|
| 214 |
+
return true;
|
| 215 |
+
} else if (node.type === 'MemberExpression') {
|
| 216 |
+
node = node.object;
|
| 217 |
+
} else {
|
| 218 |
+
return false;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
const grouped_expression_types = [
|
| 224 |
+
'ImportDeclaration',
|
| 225 |
+
'VariableDeclaration',
|
| 226 |
+
'ExportDefaultDeclaration',
|
| 227 |
+
'ExportNamedDeclaration'
|
| 228 |
+
];
|
| 229 |
+
|
| 230 |
+
/**
|
| 231 |
+
* @param {import('estree').Node[]} nodes
|
| 232 |
+
* @param {import('./types').State} state
|
| 233 |
+
*/
|
| 234 |
+
const handle_body = (nodes, state) => {
|
| 235 |
+
let last_statement = /** @type {import('estree').Node} */ ({ type: 'EmptyStatement' });
|
| 236 |
+
let first = true;
|
| 237 |
+
let needs_margin = false;
|
| 238 |
+
|
| 239 |
+
for (const statement of nodes) {
|
| 240 |
+
if (statement.type === 'EmptyStatement') continue;
|
| 241 |
+
|
| 242 |
+
const margin = create_sequence();
|
| 243 |
+
|
| 244 |
+
if (!first) state.commands.push(margin, newline);
|
| 245 |
+
first = false;
|
| 246 |
+
|
| 247 |
+
const leadingComments = statement.leadingComments;
|
| 248 |
+
delete statement.leadingComments;
|
| 249 |
+
|
| 250 |
+
if (leadingComments && leadingComments.length > 0) {
|
| 251 |
+
prepend_comments(leadingComments, state, true);
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
const child_state = { ...state, multiline: false };
|
| 255 |
+
handle(statement, child_state);
|
| 256 |
+
|
| 257 |
+
if (
|
| 258 |
+
child_state.multiline ||
|
| 259 |
+
needs_margin ||
|
| 260 |
+
((grouped_expression_types.includes(statement.type) ||
|
| 261 |
+
grouped_expression_types.includes(last_statement.type)) &&
|
| 262 |
+
last_statement.type !== statement.type)
|
| 263 |
+
) {
|
| 264 |
+
margin.children.push('\n');
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
let add_newline = false;
|
| 268 |
+
|
| 269 |
+
while (state.comments.length) {
|
| 270 |
+
const comment = /** @type {import('estree').Comment} */ (state.comments.shift());
|
| 271 |
+
|
| 272 |
+
state.commands.push(add_newline ? newline : ' ', { type: 'Comment', comment });
|
| 273 |
+
add_newline = comment.type === 'Line';
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
needs_margin = child_state.multiline;
|
| 277 |
+
last_statement = statement;
|
| 278 |
+
}
|
| 279 |
+
};
|
| 280 |
+
|
| 281 |
+
/**
|
| 282 |
+
* @param {import('estree').VariableDeclaration} node
|
| 283 |
+
* @param {import('./types').State} state
|
| 284 |
+
*/
|
| 285 |
+
const handle_var_declaration = (node, state) => {
|
| 286 |
+
const index = state.commands.length;
|
| 287 |
+
|
| 288 |
+
const open = create_sequence();
|
| 289 |
+
const join = create_sequence();
|
| 290 |
+
const child_state = { ...state, multiline: false };
|
| 291 |
+
|
| 292 |
+
state.commands.push(`${node.kind} `, open);
|
| 293 |
+
|
| 294 |
+
let first = true;
|
| 295 |
+
|
| 296 |
+
for (const d of node.declarations) {
|
| 297 |
+
if (!first) state.commands.push(join);
|
| 298 |
+
first = false;
|
| 299 |
+
|
| 300 |
+
handle(d, child_state);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
const multiline =
|
| 304 |
+
child_state.multiline || (node.declarations.length > 1 && measure(state.commands, index) > 50);
|
| 305 |
+
|
| 306 |
+
if (multiline) {
|
| 307 |
+
state.multiline = true;
|
| 308 |
+
if (node.declarations.length > 1) open.children.push(indent);
|
| 309 |
+
join.children.push(',', newline);
|
| 310 |
+
if (node.declarations.length > 1) state.commands.push(dedent);
|
| 311 |
+
} else {
|
| 312 |
+
join.children.push(', ');
|
| 313 |
+
}
|
| 314 |
+
};
|
| 315 |
+
|
| 316 |
+
/**
|
| 317 |
+
* @template {import('estree').Node} T
|
| 318 |
+
* @param {Array<T | null>} nodes
|
| 319 |
+
* @param {import('./types').State} state
|
| 320 |
+
* @param {boolean} spaces
|
| 321 |
+
* @param {(node: T, state: import('./types').State) => void} fn
|
| 322 |
+
*/
|
| 323 |
+
function sequence(nodes, state, spaces, fn) {
|
| 324 |
+
if (nodes.length === 0) return;
|
| 325 |
+
|
| 326 |
+
const index = state.commands.length;
|
| 327 |
+
|
| 328 |
+
const open = create_sequence();
|
| 329 |
+
const join = create_sequence();
|
| 330 |
+
const close = create_sequence();
|
| 331 |
+
|
| 332 |
+
state.commands.push(open);
|
| 333 |
+
|
| 334 |
+
const child_state = { ...state, multiline: false };
|
| 335 |
+
|
| 336 |
+
let prev;
|
| 337 |
+
|
| 338 |
+
for (let i = 0; i < nodes.length; i += 1) {
|
| 339 |
+
const node = nodes[i];
|
| 340 |
+
const is_first = i === 0;
|
| 341 |
+
const is_last = i === nodes.length - 1;
|
| 342 |
+
|
| 343 |
+
if (node) {
|
| 344 |
+
if (!is_first && !prev) {
|
| 345 |
+
state.commands.push(join);
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
fn(node, child_state);
|
| 349 |
+
|
| 350 |
+
if (!is_last) {
|
| 351 |
+
state.commands.push(',');
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
if (state.comments.length > 0) {
|
| 355 |
+
state.commands.push(' ');
|
| 356 |
+
|
| 357 |
+
while (state.comments.length) {
|
| 358 |
+
const comment = /** @type {import('estree').Comment} */ (state.comments.shift());
|
| 359 |
+
state.commands.push({ type: 'Comment', comment });
|
| 360 |
+
if (!is_last) state.commands.push(join);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
child_state.multiline = true;
|
| 364 |
+
} else {
|
| 365 |
+
if (!is_last) state.commands.push(join);
|
| 366 |
+
}
|
| 367 |
+
} else {
|
| 368 |
+
// This is only used for ArrayPattern and ArrayExpression, but
|
| 369 |
+
// it makes more sense to have the logic here than there, because
|
| 370 |
+
// otherwise we'd duplicate a lot more stuff
|
| 371 |
+
state.commands.push(',');
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
prev = node;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
state.commands.push(close);
|
| 378 |
+
|
| 379 |
+
const multiline = child_state.multiline || measure(state.commands, index) > 50;
|
| 380 |
+
|
| 381 |
+
if (multiline) {
|
| 382 |
+
state.multiline = true;
|
| 383 |
+
|
| 384 |
+
open.children.push(indent, newline);
|
| 385 |
+
join.children.push(newline);
|
| 386 |
+
close.children.push(dedent, newline);
|
| 387 |
+
} else {
|
| 388 |
+
if (spaces) open.children.push(' ');
|
| 389 |
+
join.children.push(' ');
|
| 390 |
+
if (spaces) close.children.push(' ');
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
/** @satisfies {Record<string, (node: any, state: import('./types').State) => undefined>} */
|
| 395 |
+
const shared = {
|
| 396 |
+
/**
|
| 397 |
+
* @param {import('estree').ArrayExpression | import('estree').ArrayPattern} node
|
| 398 |
+
* @param {import('./types').State} state
|
| 399 |
+
*/
|
| 400 |
+
'ArrayExpression|ArrayPattern': (node, state) => {
|
| 401 |
+
state.commands.push('[');
|
| 402 |
+
sequence(/** @type {import('estree').Node[]} */ (node.elements), state, false, handle);
|
| 403 |
+
state.commands.push(']');
|
| 404 |
+
},
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* @param {import('estree').BinaryExpression | import('estree').LogicalExpression} node
|
| 408 |
+
* @param {import('./types').State} state
|
| 409 |
+
*/
|
| 410 |
+
'BinaryExpression|LogicalExpression': (node, state) => {
|
| 411 |
+
// TODO
|
| 412 |
+
// const is_in = node.operator === 'in';
|
| 413 |
+
// if (is_in) {
|
| 414 |
+
// // Avoids confusion in `for` loops initializers
|
| 415 |
+
// chunks.push(c('('));
|
| 416 |
+
// }
|
| 417 |
+
|
| 418 |
+
if (needs_parens(node.left, node, false)) {
|
| 419 |
+
state.commands.push('(');
|
| 420 |
+
handle(node.left, state);
|
| 421 |
+
state.commands.push(')');
|
| 422 |
+
} else {
|
| 423 |
+
handle(node.left, state);
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
state.commands.push(` ${node.operator} `);
|
| 427 |
+
|
| 428 |
+
if (needs_parens(node.right, node, true)) {
|
| 429 |
+
state.commands.push('(');
|
| 430 |
+
handle(node.right, state);
|
| 431 |
+
state.commands.push(')');
|
| 432 |
+
} else {
|
| 433 |
+
handle(node.right, state);
|
| 434 |
+
}
|
| 435 |
+
},
|
| 436 |
+
|
| 437 |
+
/**
|
| 438 |
+
* @param {import('estree').BlockStatement | import('estree').ClassBody} node
|
| 439 |
+
* @param {import('./types').State} state
|
| 440 |
+
*/
|
| 441 |
+
'BlockStatement|ClassBody': (node, state) => {
|
| 442 |
+
if (node.body.length === 0) {
|
| 443 |
+
state.commands.push('{}');
|
| 444 |
+
return;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
state.multiline = true;
|
| 448 |
+
|
| 449 |
+
state.commands.push('{', indent, newline);
|
| 450 |
+
handle_body(node.body, state);
|
| 451 |
+
state.commands.push(dedent, newline, '}');
|
| 452 |
+
},
|
| 453 |
+
|
| 454 |
+
/**
|
| 455 |
+
* @param {import('estree').CallExpression | import('estree').NewExpression} node
|
| 456 |
+
* @param {import('./types').State} state
|
| 457 |
+
*/
|
| 458 |
+
'CallExpression|NewExpression': (node, state) => {
|
| 459 |
+
const index = state.commands.length;
|
| 460 |
+
|
| 461 |
+
if (node.type === 'NewExpression') {
|
| 462 |
+
state.commands.push('new ');
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
const needs_parens =
|
| 466 |
+
EXPRESSIONS_PRECEDENCE[node.callee.type] < EXPRESSIONS_PRECEDENCE.CallExpression ||
|
| 467 |
+
(node.type === 'NewExpression' && has_call_expression(node.callee));
|
| 468 |
+
|
| 469 |
+
if (needs_parens) {
|
| 470 |
+
state.commands.push('(');
|
| 471 |
+
handle(node.callee, state);
|
| 472 |
+
state.commands.push(')');
|
| 473 |
+
} else {
|
| 474 |
+
handle(node.callee, state);
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
if (/** @type {import('estree').SimpleCallExpression} */ (node).optional) {
|
| 478 |
+
state.commands.push('?.');
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
const open = create_sequence();
|
| 482 |
+
const join = create_sequence();
|
| 483 |
+
const close = create_sequence();
|
| 484 |
+
|
| 485 |
+
state.commands.push('(', open);
|
| 486 |
+
|
| 487 |
+
// if the final argument is multiline, it doesn't need to force all the
|
| 488 |
+
// other arguments to also be multiline
|
| 489 |
+
const child_state = { ...state, multiline: false };
|
| 490 |
+
const final_state = { ...state, multiline: false };
|
| 491 |
+
|
| 492 |
+
for (let i = 0; i < node.arguments.length; i += 1) {
|
| 493 |
+
if (i > 0) {
|
| 494 |
+
if (state.comments.length > 0) {
|
| 495 |
+
state.commands.push(', ');
|
| 496 |
+
|
| 497 |
+
while (state.comments.length) {
|
| 498 |
+
const comment = /** @type {import('estree').Comment} */ (state.comments.shift());
|
| 499 |
+
|
| 500 |
+
state.commands.push({ type: 'Comment', comment });
|
| 501 |
+
|
| 502 |
+
if (comment.type === 'Line') {
|
| 503 |
+
child_state.multiline = true;
|
| 504 |
+
state.commands.push(newline);
|
| 505 |
+
} else {
|
| 506 |
+
state.commands.push(' ');
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
} else {
|
| 510 |
+
state.commands.push(join);
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
const p = node.arguments[i];
|
| 515 |
+
|
| 516 |
+
handle(p, i === node.arguments.length - 1 ? final_state : child_state);
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
state.commands.push(close, ')');
|
| 520 |
+
|
| 521 |
+
const multiline = child_state.multiline;
|
| 522 |
+
|
| 523 |
+
if (multiline || final_state.multiline) {
|
| 524 |
+
state.multiline = true;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
if (multiline) {
|
| 528 |
+
open.children.push(indent, newline);
|
| 529 |
+
join.children.push(',', newline);
|
| 530 |
+
close.children.push(dedent, newline);
|
| 531 |
+
} else {
|
| 532 |
+
join.children.push(', ');
|
| 533 |
+
}
|
| 534 |
+
},
|
| 535 |
+
|
| 536 |
+
/**
|
| 537 |
+
* @param {import('estree').ClassDeclaration | import('estree').ClassExpression} node
|
| 538 |
+
* @param {import('./types').State} state
|
| 539 |
+
*/
|
| 540 |
+
'ClassDeclaration|ClassExpression': (node, state) => {
|
| 541 |
+
state.commands.push('class ');
|
| 542 |
+
|
| 543 |
+
if (node.id) {
|
| 544 |
+
handle(node.id, state);
|
| 545 |
+
state.commands.push(' ');
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
if (node.superClass) {
|
| 549 |
+
state.commands.push('extends ');
|
| 550 |
+
handle(node.superClass, state);
|
| 551 |
+
state.commands.push(' ');
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
handle(node.body, state);
|
| 555 |
+
},
|
| 556 |
+
|
| 557 |
+
/**
|
| 558 |
+
* @param {import('estree').ForInStatement | import('estree').ForOfStatement} node
|
| 559 |
+
* @param {import('./types').State} state
|
| 560 |
+
*/
|
| 561 |
+
'ForInStatement|ForOfStatement': (node, state) => {
|
| 562 |
+
state.commands.push('for ');
|
| 563 |
+
if (node.type === 'ForOfStatement' && node.await) state.commands.push('await ');
|
| 564 |
+
state.commands.push('(');
|
| 565 |
+
|
| 566 |
+
if (node.left.type === 'VariableDeclaration') {
|
| 567 |
+
handle_var_declaration(node.left, state);
|
| 568 |
+
} else {
|
| 569 |
+
handle(node.left, state);
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
state.commands.push(node.type === 'ForInStatement' ? ` in ` : ` of `);
|
| 573 |
+
handle(node.right, state);
|
| 574 |
+
state.commands.push(') ');
|
| 575 |
+
handle(node.body, state);
|
| 576 |
+
},
|
| 577 |
+
|
| 578 |
+
/**
|
| 579 |
+
* @param {import('estree').FunctionDeclaration | import('estree').FunctionExpression} node
|
| 580 |
+
* @param {import('./types').State} state
|
| 581 |
+
*/
|
| 582 |
+
'FunctionDeclaration|FunctionExpression': (node, state) => {
|
| 583 |
+
if (node.async) state.commands.push('async ');
|
| 584 |
+
state.commands.push(node.generator ? 'function* ' : 'function ');
|
| 585 |
+
if (node.id) handle(node.id, state);
|
| 586 |
+
|
| 587 |
+
state.commands.push('(');
|
| 588 |
+
sequence(node.params, state, false, handle);
|
| 589 |
+
state.commands.push(') ');
|
| 590 |
+
|
| 591 |
+
handle(node.body, state);
|
| 592 |
+
},
|
| 593 |
+
|
| 594 |
+
/**
|
| 595 |
+
* @param {import('estree').RestElement | import('estree').SpreadElement} node
|
| 596 |
+
* @param {import('./types').State} state
|
| 597 |
+
*/
|
| 598 |
+
'RestElement|SpreadElement': (node, state) => {
|
| 599 |
+
state.commands.push('...');
|
| 600 |
+
handle(node.argument, state);
|
| 601 |
+
}
|
| 602 |
+
};
|
| 603 |
+
|
| 604 |
+
/** @type {import('./types').Handlers} */
|
| 605 |
+
const handlers = {
|
| 606 |
+
ArrayExpression: shared['ArrayExpression|ArrayPattern'],
|
| 607 |
+
|
| 608 |
+
ArrayPattern: shared['ArrayExpression|ArrayPattern'],
|
| 609 |
+
|
| 610 |
+
ArrowFunctionExpression: (node, state) => {
|
| 611 |
+
if (node.async) state.commands.push('async ');
|
| 612 |
+
|
| 613 |
+
state.commands.push('(');
|
| 614 |
+
sequence(node.params, state, false, handle);
|
| 615 |
+
state.commands.push(') => ');
|
| 616 |
+
|
| 617 |
+
if (
|
| 618 |
+
node.body.type === 'ObjectExpression' ||
|
| 619 |
+
(node.body.type === 'AssignmentExpression' && node.body.left.type === 'ObjectPattern') ||
|
| 620 |
+
(node.body.type === 'LogicalExpression' && node.body.left.type === 'ObjectExpression') ||
|
| 621 |
+
(node.body.type === 'ConditionalExpression' && node.body.test.type === 'ObjectExpression')
|
| 622 |
+
) {
|
| 623 |
+
state.commands.push('(');
|
| 624 |
+
handle(node.body, state);
|
| 625 |
+
state.commands.push(')');
|
| 626 |
+
} else {
|
| 627 |
+
handle(node.body, state);
|
| 628 |
+
}
|
| 629 |
+
},
|
| 630 |
+
|
| 631 |
+
AssignmentExpression(node, state) {
|
| 632 |
+
handle(node.left, state);
|
| 633 |
+
state.commands.push(` ${node.operator} `);
|
| 634 |
+
handle(node.right, state);
|
| 635 |
+
},
|
| 636 |
+
|
| 637 |
+
AssignmentPattern(node, state) {
|
| 638 |
+
handle(node.left, state);
|
| 639 |
+
state.commands.push(' = ');
|
| 640 |
+
handle(node.right, state);
|
| 641 |
+
},
|
| 642 |
+
|
| 643 |
+
AwaitExpression(node, state) {
|
| 644 |
+
if (node.argument) {
|
| 645 |
+
const precedence = EXPRESSIONS_PRECEDENCE[node.argument.type];
|
| 646 |
+
|
| 647 |
+
if (precedence && precedence < EXPRESSIONS_PRECEDENCE.AwaitExpression) {
|
| 648 |
+
state.commands.push('await (');
|
| 649 |
+
handle(node.argument, state);
|
| 650 |
+
state.commands.push(')');
|
| 651 |
+
} else {
|
| 652 |
+
state.commands.push('await ');
|
| 653 |
+
handle(node.argument, state);
|
| 654 |
+
}
|
| 655 |
+
} else {
|
| 656 |
+
state.commands.push('await');
|
| 657 |
+
}
|
| 658 |
+
},
|
| 659 |
+
|
| 660 |
+
BinaryExpression: shared['BinaryExpression|LogicalExpression'],
|
| 661 |
+
|
| 662 |
+
BlockStatement: shared['BlockStatement|ClassBody'],
|
| 663 |
+
|
| 664 |
+
BreakStatement(node, state) {
|
| 665 |
+
if (node.label) {
|
| 666 |
+
state.commands.push('break ');
|
| 667 |
+
handle(node.label, state);
|
| 668 |
+
state.commands.push(';');
|
| 669 |
+
} else {
|
| 670 |
+
state.commands.push('break;');
|
| 671 |
+
}
|
| 672 |
+
},
|
| 673 |
+
|
| 674 |
+
CallExpression: shared['CallExpression|NewExpression'],
|
| 675 |
+
|
| 676 |
+
ChainExpression(node, state) {
|
| 677 |
+
handle(node.expression, state);
|
| 678 |
+
},
|
| 679 |
+
|
| 680 |
+
ClassBody: shared['BlockStatement|ClassBody'],
|
| 681 |
+
|
| 682 |
+
ClassDeclaration: shared['ClassDeclaration|ClassExpression'],
|
| 683 |
+
|
| 684 |
+
ClassExpression: shared['ClassDeclaration|ClassExpression'],
|
| 685 |
+
|
| 686 |
+
ConditionalExpression(node, state) {
|
| 687 |
+
if (EXPRESSIONS_PRECEDENCE[node.test.type] > EXPRESSIONS_PRECEDENCE.ConditionalExpression) {
|
| 688 |
+
handle(node.test, state);
|
| 689 |
+
} else {
|
| 690 |
+
state.commands.push('(');
|
| 691 |
+
handle(node.test, state);
|
| 692 |
+
state.commands.push(')');
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
const if_true = create_sequence();
|
| 696 |
+
const if_false = create_sequence();
|
| 697 |
+
|
| 698 |
+
const child_state = { ...state, multiline: false };
|
| 699 |
+
|
| 700 |
+
state.commands.push(if_true);
|
| 701 |
+
handle(node.consequent, child_state);
|
| 702 |
+
state.commands.push(if_false);
|
| 703 |
+
handle(node.alternate, child_state);
|
| 704 |
+
|
| 705 |
+
const multiline = child_state.multiline;
|
| 706 |
+
|
| 707 |
+
if (multiline) {
|
| 708 |
+
if_true.children.push(indent, newline, '? ');
|
| 709 |
+
if_false.children.push(newline, ': ');
|
| 710 |
+
state.commands.push(dedent);
|
| 711 |
+
} else {
|
| 712 |
+
if_true.children.push(' ? ');
|
| 713 |
+
if_false.children.push(' : ');
|
| 714 |
+
}
|
| 715 |
+
},
|
| 716 |
+
|
| 717 |
+
ContinueStatement(node, state) {
|
| 718 |
+
if (node.label) {
|
| 719 |
+
state.commands.push('continue ');
|
| 720 |
+
handle(node.label, state);
|
| 721 |
+
state.commands.push(';');
|
| 722 |
+
} else {
|
| 723 |
+
state.commands.push('continue;');
|
| 724 |
+
}
|
| 725 |
+
},
|
| 726 |
+
|
| 727 |
+
DebuggerStatement(node, state) {
|
| 728 |
+
state.commands.push(c('debugger', node), ';');
|
| 729 |
+
},
|
| 730 |
+
|
| 731 |
+
DoWhileStatement(node, state) {
|
| 732 |
+
state.commands.push('do ');
|
| 733 |
+
handle(node.body, state);
|
| 734 |
+
state.commands.push(' while (');
|
| 735 |
+
handle(node.test, state);
|
| 736 |
+
state.commands.push(');');
|
| 737 |
+
},
|
| 738 |
+
|
| 739 |
+
EmptyStatement(node, state) {
|
| 740 |
+
state.commands.push(';');
|
| 741 |
+
},
|
| 742 |
+
|
| 743 |
+
ExportAllDeclaration(node, state) {
|
| 744 |
+
state.commands.push('export * from ');
|
| 745 |
+
handle(node.source, state);
|
| 746 |
+
state.commands.push(';');
|
| 747 |
+
},
|
| 748 |
+
|
| 749 |
+
ExportDefaultDeclaration(node, state) {
|
| 750 |
+
state.commands.push('export default ');
|
| 751 |
+
|
| 752 |
+
handle(node.declaration, state);
|
| 753 |
+
|
| 754 |
+
if (node.declaration.type !== 'FunctionDeclaration') {
|
| 755 |
+
state.commands.push(';');
|
| 756 |
+
}
|
| 757 |
+
},
|
| 758 |
+
|
| 759 |
+
ExportNamedDeclaration(node, state) {
|
| 760 |
+
state.commands.push('export ');
|
| 761 |
+
|
| 762 |
+
if (node.declaration) {
|
| 763 |
+
handle(node.declaration, state);
|
| 764 |
+
return;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
state.commands.push('{');
|
| 768 |
+
sequence(node.specifiers, state, true, (s, state) => {
|
| 769 |
+
handle(s.local, state);
|
| 770 |
+
|
| 771 |
+
if (s.local.name !== s.exported.name) {
|
| 772 |
+
state.commands.push(' as ');
|
| 773 |
+
handle(s.exported, state);
|
| 774 |
+
}
|
| 775 |
+
});
|
| 776 |
+
state.commands.push('}');
|
| 777 |
+
|
| 778 |
+
if (node.source) {
|
| 779 |
+
state.commands.push(' from ');
|
| 780 |
+
handle(node.source, state);
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
state.commands.push(';');
|
| 784 |
+
},
|
| 785 |
+
|
| 786 |
+
ExpressionStatement(node, state) {
|
| 787 |
+
if (
|
| 788 |
+
node.expression.type === 'AssignmentExpression' &&
|
| 789 |
+
node.expression.left.type === 'ObjectPattern'
|
| 790 |
+
) {
|
| 791 |
+
// is an AssignmentExpression to an ObjectPattern
|
| 792 |
+
state.commands.push('(');
|
| 793 |
+
handle(node.expression, state);
|
| 794 |
+
state.commands.push(');');
|
| 795 |
+
return;
|
| 796 |
+
}
|
| 797 |
+
|
| 798 |
+
handle(node.expression, state);
|
| 799 |
+
state.commands.push(';');
|
| 800 |
+
},
|
| 801 |
+
|
| 802 |
+
ForStatement: (node, state) => {
|
| 803 |
+
state.commands.push('for (');
|
| 804 |
+
|
| 805 |
+
if (node.init) {
|
| 806 |
+
if (node.init.type === 'VariableDeclaration') {
|
| 807 |
+
handle_var_declaration(node.init, state);
|
| 808 |
+
} else {
|
| 809 |
+
handle(node.init, state);
|
| 810 |
+
}
|
| 811 |
+
}
|
| 812 |
+
|
| 813 |
+
state.commands.push('; ');
|
| 814 |
+
if (node.test) handle(node.test, state);
|
| 815 |
+
state.commands.push('; ');
|
| 816 |
+
if (node.update) handle(node.update, state);
|
| 817 |
+
|
| 818 |
+
state.commands.push(') ');
|
| 819 |
+
handle(node.body, state);
|
| 820 |
+
},
|
| 821 |
+
|
| 822 |
+
ForInStatement: shared['ForInStatement|ForOfStatement'],
|
| 823 |
+
|
| 824 |
+
ForOfStatement: shared['ForInStatement|ForOfStatement'],
|
| 825 |
+
|
| 826 |
+
FunctionDeclaration: shared['FunctionDeclaration|FunctionExpression'],
|
| 827 |
+
|
| 828 |
+
FunctionExpression: shared['FunctionDeclaration|FunctionExpression'],
|
| 829 |
+
|
| 830 |
+
Identifier(node, state) {
|
| 831 |
+
let name = node.name;
|
| 832 |
+
state.commands.push(c(name, node));
|
| 833 |
+
},
|
| 834 |
+
|
| 835 |
+
IfStatement(node, state) {
|
| 836 |
+
state.commands.push('if (');
|
| 837 |
+
handle(node.test, state);
|
| 838 |
+
state.commands.push(') ');
|
| 839 |
+
handle(node.consequent, state);
|
| 840 |
+
|
| 841 |
+
if (node.alternate) {
|
| 842 |
+
state.commands.push(' else ');
|
| 843 |
+
handle(node.alternate, state);
|
| 844 |
+
}
|
| 845 |
+
},
|
| 846 |
+
|
| 847 |
+
ImportDeclaration(node, state) {
|
| 848 |
+
if (node.specifiers.length === 0) {
|
| 849 |
+
state.commands.push('import ');
|
| 850 |
+
handle(node.source, state);
|
| 851 |
+
state.commands.push(';');
|
| 852 |
+
return;
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
/** @type {import('estree').ImportNamespaceSpecifier | null} */
|
| 856 |
+
let namespace_specifier = null;
|
| 857 |
+
|
| 858 |
+
/** @type {import('estree').ImportDefaultSpecifier | null} */
|
| 859 |
+
let default_specifier = null;
|
| 860 |
+
|
| 861 |
+
/** @type {import('estree').ImportSpecifier[]} */
|
| 862 |
+
const named_specifiers = [];
|
| 863 |
+
|
| 864 |
+
for (const s of node.specifiers) {
|
| 865 |
+
if (s.type === 'ImportNamespaceSpecifier') {
|
| 866 |
+
namespace_specifier = s;
|
| 867 |
+
} else if (s.type === 'ImportDefaultSpecifier') {
|
| 868 |
+
default_specifier = s;
|
| 869 |
+
} else {
|
| 870 |
+
named_specifiers.push(s);
|
| 871 |
+
}
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
state.commands.push('import ');
|
| 875 |
+
|
| 876 |
+
if (default_specifier) {
|
| 877 |
+
state.commands.push(c(default_specifier.local.name, default_specifier));
|
| 878 |
+
if (namespace_specifier || named_specifiers.length > 0) state.commands.push(', ');
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
if (namespace_specifier) {
|
| 882 |
+
state.commands.push(c('* as ' + namespace_specifier.local.name, namespace_specifier));
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
if (named_specifiers.length > 0) {
|
| 886 |
+
state.commands.push('{');
|
| 887 |
+
sequence(named_specifiers, state, true, (s, state) => {
|
| 888 |
+
if (s.local.name !== s.imported.name) {
|
| 889 |
+
handle(s.imported, state);
|
| 890 |
+
state.commands.push(' as ');
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
handle(s.local, state);
|
| 894 |
+
});
|
| 895 |
+
state.commands.push('}');
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
state.commands.push(' from ');
|
| 899 |
+
handle(node.source, state);
|
| 900 |
+
state.commands.push(';');
|
| 901 |
+
},
|
| 902 |
+
|
| 903 |
+
ImportExpression(node, state) {
|
| 904 |
+
state.commands.push('import(');
|
| 905 |
+
handle(node.source, state);
|
| 906 |
+
state.commands.push(')');
|
| 907 |
+
},
|
| 908 |
+
|
| 909 |
+
LabeledStatement(node, state) {
|
| 910 |
+
handle(node.label, state);
|
| 911 |
+
state.commands.push(': ');
|
| 912 |
+
handle(node.body, state);
|
| 913 |
+
},
|
| 914 |
+
|
| 915 |
+
Literal(node, state) {
|
| 916 |
+
// TODO do we need to handle weird unicode characters somehow?
|
| 917 |
+
// str.replace(/\\u(\d{4})/g, (m, n) => String.fromCharCode(+n))
|
| 918 |
+
const value =
|
| 919 |
+
node.raw ??
|
| 920 |
+
(typeof node.value === 'string' ? JSON.stringify(node.value) : String(node.value));
|
| 921 |
+
|
| 922 |
+
state.commands.push(c(value, node));
|
| 923 |
+
},
|
| 924 |
+
|
| 925 |
+
LogicalExpression: shared['BinaryExpression|LogicalExpression'],
|
| 926 |
+
|
| 927 |
+
MemberExpression(node, state) {
|
| 928 |
+
if (EXPRESSIONS_PRECEDENCE[node.object.type] < EXPRESSIONS_PRECEDENCE.MemberExpression) {
|
| 929 |
+
state.commands.push('(');
|
| 930 |
+
handle(node.object, state);
|
| 931 |
+
state.commands.push(')');
|
| 932 |
+
} else {
|
| 933 |
+
handle(node.object, state);
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
if (node.computed) {
|
| 937 |
+
if (node.optional) {
|
| 938 |
+
state.commands.push('?.');
|
| 939 |
+
}
|
| 940 |
+
state.commands.push('[');
|
| 941 |
+
handle(node.property, state);
|
| 942 |
+
state.commands.push(']');
|
| 943 |
+
} else {
|
| 944 |
+
state.commands.push(node.optional ? '?.' : '.');
|
| 945 |
+
handle(node.property, state);
|
| 946 |
+
}
|
| 947 |
+
},
|
| 948 |
+
|
| 949 |
+
MetaProperty(node, state) {
|
| 950 |
+
handle(node.meta, state);
|
| 951 |
+
state.commands.push('.');
|
| 952 |
+
handle(node.property, state);
|
| 953 |
+
},
|
| 954 |
+
|
| 955 |
+
MethodDefinition(node, state) {
|
| 956 |
+
if (node.static) {
|
| 957 |
+
state.commands.push('static ');
|
| 958 |
+
}
|
| 959 |
+
|
| 960 |
+
if (node.kind === 'get' || node.kind === 'set') {
|
| 961 |
+
// Getter or setter
|
| 962 |
+
state.commands.push(node.kind + ' ');
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
if (node.value.async) {
|
| 966 |
+
state.commands.push('async ');
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
+
if (node.value.generator) {
|
| 970 |
+
state.commands.push('*');
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
if (node.computed) state.commands.push('[');
|
| 974 |
+
handle(node.key, state);
|
| 975 |
+
if (node.computed) state.commands.push(']');
|
| 976 |
+
|
| 977 |
+
state.commands.push('(');
|
| 978 |
+
sequence(node.value.params, state, false, handle);
|
| 979 |
+
state.commands.push(') ');
|
| 980 |
+
|
| 981 |
+
handle(node.value.body, state);
|
| 982 |
+
},
|
| 983 |
+
|
| 984 |
+
NewExpression: shared['CallExpression|NewExpression'],
|
| 985 |
+
|
| 986 |
+
ObjectExpression(node, state) {
|
| 987 |
+
state.commands.push('{');
|
| 988 |
+
sequence(node.properties, state, true, (p, state) => {
|
| 989 |
+
if (p.type === 'Property' && p.value.type === 'FunctionExpression') {
|
| 990 |
+
const fn = /** @type {import('estree').FunctionExpression} */ (p.value);
|
| 991 |
+
|
| 992 |
+
if (p.kind === 'get' || p.kind === 'set') {
|
| 993 |
+
state.commands.push(p.kind + ' ');
|
| 994 |
+
} else {
|
| 995 |
+
if (fn.async) state.commands.push('async ');
|
| 996 |
+
if (fn.generator) state.commands.push('*');
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
if (p.computed) state.commands.push('[');
|
| 1000 |
+
handle(p.key, state);
|
| 1001 |
+
if (p.computed) state.commands.push(']');
|
| 1002 |
+
|
| 1003 |
+
state.commands.push('(');
|
| 1004 |
+
sequence(fn.params, state, false, handle);
|
| 1005 |
+
state.commands.push(') ');
|
| 1006 |
+
|
| 1007 |
+
handle(fn.body, state);
|
| 1008 |
+
} else {
|
| 1009 |
+
handle(p, state);
|
| 1010 |
+
}
|
| 1011 |
+
});
|
| 1012 |
+
state.commands.push('}');
|
| 1013 |
+
},
|
| 1014 |
+
|
| 1015 |
+
ObjectPattern(node, state) {
|
| 1016 |
+
state.commands.push('{');
|
| 1017 |
+
sequence(node.properties, state, true, handle);
|
| 1018 |
+
state.commands.push('}');
|
| 1019 |
+
},
|
| 1020 |
+
|
| 1021 |
+
// @ts-expect-error this isn't a real node type, but Acorn produces it
|
| 1022 |
+
ParenthesizedExpression(node, state) {
|
| 1023 |
+
return handle(node.expression, state);
|
| 1024 |
+
},
|
| 1025 |
+
|
| 1026 |
+
PrivateIdentifier(node, state) {
|
| 1027 |
+
state.commands.push('#', c(node.name, node));
|
| 1028 |
+
},
|
| 1029 |
+
|
| 1030 |
+
Program(node, state) {
|
| 1031 |
+
handle_body(node.body, state);
|
| 1032 |
+
},
|
| 1033 |
+
|
| 1034 |
+
Property(node, state) {
|
| 1035 |
+
const value = node.value.type === 'AssignmentPattern' ? node.value.left : node.value;
|
| 1036 |
+
|
| 1037 |
+
const shorthand =
|
| 1038 |
+
!node.computed &&
|
| 1039 |
+
node.kind === 'init' &&
|
| 1040 |
+
node.key.type === 'Identifier' &&
|
| 1041 |
+
value.type === 'Identifier' &&
|
| 1042 |
+
node.key.name === value.name;
|
| 1043 |
+
|
| 1044 |
+
if (shorthand) {
|
| 1045 |
+
handle(node.value, state);
|
| 1046 |
+
return;
|
| 1047 |
+
}
|
| 1048 |
+
|
| 1049 |
+
if (node.computed) state.commands.push('[');
|
| 1050 |
+
handle(node.key, state);
|
| 1051 |
+
state.commands.push(node.computed ? ']: ' : ': ');
|
| 1052 |
+
handle(node.value, state);
|
| 1053 |
+
},
|
| 1054 |
+
|
| 1055 |
+
PropertyDefinition(node, state) {
|
| 1056 |
+
if (node.static) {
|
| 1057 |
+
state.commands.push('static ');
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
if (node.computed) {
|
| 1061 |
+
state.commands.push('[');
|
| 1062 |
+
handle(node.key, state);
|
| 1063 |
+
state.commands.push(']');
|
| 1064 |
+
} else {
|
| 1065 |
+
handle(node.key, state);
|
| 1066 |
+
}
|
| 1067 |
+
|
| 1068 |
+
if (node.value) {
|
| 1069 |
+
state.commands.push(' = ');
|
| 1070 |
+
|
| 1071 |
+
handle(node.value, state);
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
state.commands.push(';');
|
| 1075 |
+
},
|
| 1076 |
+
|
| 1077 |
+
RestElement: shared['RestElement|SpreadElement'],
|
| 1078 |
+
|
| 1079 |
+
ReturnStatement(node, state) {
|
| 1080 |
+
if (node.argument) {
|
| 1081 |
+
const contains_comment =
|
| 1082 |
+
node.argument.leadingComments &&
|
| 1083 |
+
node.argument.leadingComments.some((comment) => comment.type === 'Line');
|
| 1084 |
+
|
| 1085 |
+
state.commands.push(contains_comment ? 'return (' : 'return ');
|
| 1086 |
+
handle(node.argument, state);
|
| 1087 |
+
state.commands.push(contains_comment ? ');' : ';');
|
| 1088 |
+
} else {
|
| 1089 |
+
state.commands.push('return;');
|
| 1090 |
+
}
|
| 1091 |
+
},
|
| 1092 |
+
|
| 1093 |
+
SequenceExpression(node, state) {
|
| 1094 |
+
state.commands.push('(');
|
| 1095 |
+
sequence(node.expressions, state, false, handle);
|
| 1096 |
+
state.commands.push(')');
|
| 1097 |
+
},
|
| 1098 |
+
|
| 1099 |
+
SpreadElement: shared['RestElement|SpreadElement'],
|
| 1100 |
+
|
| 1101 |
+
StaticBlock(node, state) {
|
| 1102 |
+
state.commands.push(indent, 'static {', newline);
|
| 1103 |
+
|
| 1104 |
+
handle_body(node.body, state);
|
| 1105 |
+
|
| 1106 |
+
state.commands.push(dedent, newline, '}');
|
| 1107 |
+
},
|
| 1108 |
+
|
| 1109 |
+
Super(node, state) {
|
| 1110 |
+
state.commands.push(c('super', node));
|
| 1111 |
+
},
|
| 1112 |
+
|
| 1113 |
+
SwitchStatement(node, state) {
|
| 1114 |
+
state.commands.push('switch (');
|
| 1115 |
+
handle(node.discriminant, state);
|
| 1116 |
+
state.commands.push(') {', indent);
|
| 1117 |
+
|
| 1118 |
+
let first = true;
|
| 1119 |
+
|
| 1120 |
+
for (const block of node.cases) {
|
| 1121 |
+
if (!first) state.commands.push('\n');
|
| 1122 |
+
first = false;
|
| 1123 |
+
|
| 1124 |
+
if (block.test) {
|
| 1125 |
+
state.commands.push(newline, `case `);
|
| 1126 |
+
handle(block.test, state);
|
| 1127 |
+
state.commands.push(':');
|
| 1128 |
+
} else {
|
| 1129 |
+
state.commands.push(newline, `default:`);
|
| 1130 |
+
}
|
| 1131 |
+
|
| 1132 |
+
state.commands.push(indent);
|
| 1133 |
+
|
| 1134 |
+
for (const statement of block.consequent) {
|
| 1135 |
+
state.commands.push(newline);
|
| 1136 |
+
handle(statement, state);
|
| 1137 |
+
}
|
| 1138 |
+
|
| 1139 |
+
state.commands.push(dedent);
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
state.commands.push(dedent, newline, `}`);
|
| 1143 |
+
},
|
| 1144 |
+
|
| 1145 |
+
TaggedTemplateExpression(node, state) {
|
| 1146 |
+
handle(node.tag, state);
|
| 1147 |
+
handle(node.quasi, state);
|
| 1148 |
+
},
|
| 1149 |
+
|
| 1150 |
+
TemplateLiteral(node, state) {
|
| 1151 |
+
state.commands.push('`');
|
| 1152 |
+
|
| 1153 |
+
const { quasis, expressions } = node;
|
| 1154 |
+
|
| 1155 |
+
for (let i = 0; i < expressions.length; i++) {
|
| 1156 |
+
const raw = quasis[i].value.raw;
|
| 1157 |
+
|
| 1158 |
+
state.commands.push(raw, '${');
|
| 1159 |
+
handle(expressions[i], state);
|
| 1160 |
+
state.commands.push('}');
|
| 1161 |
+
|
| 1162 |
+
if (/\n/.test(raw)) state.multiline = true;
|
| 1163 |
+
}
|
| 1164 |
+
|
| 1165 |
+
const raw = quasis[quasis.length - 1].value.raw;
|
| 1166 |
+
|
| 1167 |
+
state.commands.push(raw, '`');
|
| 1168 |
+
if (/\n/.test(raw)) state.multiline = true;
|
| 1169 |
+
},
|
| 1170 |
+
|
| 1171 |
+
ThisExpression(node, state) {
|
| 1172 |
+
state.commands.push(c('this', node));
|
| 1173 |
+
},
|
| 1174 |
+
|
| 1175 |
+
ThrowStatement(node, state) {
|
| 1176 |
+
state.commands.push('throw ');
|
| 1177 |
+
handle(node.argument, state);
|
| 1178 |
+
state.commands.push(';');
|
| 1179 |
+
},
|
| 1180 |
+
|
| 1181 |
+
TryStatement(node, state) {
|
| 1182 |
+
state.commands.push('try ');
|
| 1183 |
+
handle(node.block, state);
|
| 1184 |
+
|
| 1185 |
+
if (node.handler) {
|
| 1186 |
+
if (node.handler.param) {
|
| 1187 |
+
state.commands.push(' catch(');
|
| 1188 |
+
handle(node.handler.param, state);
|
| 1189 |
+
state.commands.push(') ');
|
| 1190 |
+
} else {
|
| 1191 |
+
state.commands.push(' catch ');
|
| 1192 |
+
}
|
| 1193 |
+
|
| 1194 |
+
handle(node.handler.body, state);
|
| 1195 |
+
}
|
| 1196 |
+
|
| 1197 |
+
if (node.finalizer) {
|
| 1198 |
+
state.commands.push(' finally ');
|
| 1199 |
+
handle(node.finalizer, state);
|
| 1200 |
+
}
|
| 1201 |
+
},
|
| 1202 |
+
|
| 1203 |
+
UnaryExpression(node, state) {
|
| 1204 |
+
state.commands.push(node.operator);
|
| 1205 |
+
|
| 1206 |
+
if (node.operator.length > 1) {
|
| 1207 |
+
state.commands.push(' ');
|
| 1208 |
+
}
|
| 1209 |
+
|
| 1210 |
+
if (EXPRESSIONS_PRECEDENCE[node.argument.type] < EXPRESSIONS_PRECEDENCE.UnaryExpression) {
|
| 1211 |
+
state.commands.push('(');
|
| 1212 |
+
handle(node.argument, state);
|
| 1213 |
+
state.commands.push(')');
|
| 1214 |
+
} else {
|
| 1215 |
+
handle(node.argument, state);
|
| 1216 |
+
}
|
| 1217 |
+
},
|
| 1218 |
+
|
| 1219 |
+
UpdateExpression(node, state) {
|
| 1220 |
+
if (node.prefix) {
|
| 1221 |
+
state.commands.push(node.operator);
|
| 1222 |
+
handle(node.argument, state);
|
| 1223 |
+
} else {
|
| 1224 |
+
handle(node.argument, state);
|
| 1225 |
+
state.commands.push(node.operator);
|
| 1226 |
+
}
|
| 1227 |
+
},
|
| 1228 |
+
|
| 1229 |
+
VariableDeclaration(node, state) {
|
| 1230 |
+
handle_var_declaration(node, state);
|
| 1231 |
+
state.commands.push(';');
|
| 1232 |
+
},
|
| 1233 |
+
|
| 1234 |
+
VariableDeclarator(node, state) {
|
| 1235 |
+
handle(node.id, state);
|
| 1236 |
+
|
| 1237 |
+
if (node.init) {
|
| 1238 |
+
state.commands.push(' = ');
|
| 1239 |
+
handle(node.init, state);
|
| 1240 |
+
}
|
| 1241 |
+
},
|
| 1242 |
+
|
| 1243 |
+
WhileStatement(node, state) {
|
| 1244 |
+
state.commands.push('while (');
|
| 1245 |
+
handle(node.test, state);
|
| 1246 |
+
state.commands.push(') ');
|
| 1247 |
+
handle(node.body, state);
|
| 1248 |
+
},
|
| 1249 |
+
|
| 1250 |
+
WithStatement(node, state) {
|
| 1251 |
+
state.commands.push('with (');
|
| 1252 |
+
handle(node.object, state);
|
| 1253 |
+
state.commands.push(') ');
|
| 1254 |
+
handle(node.body, state);
|
| 1255 |
+
},
|
| 1256 |
+
|
| 1257 |
+
YieldExpression(node, state) {
|
| 1258 |
+
if (node.argument) {
|
| 1259 |
+
state.commands.push(node.delegate ? `yield* ` : `yield `);
|
| 1260 |
+
handle(node.argument, state);
|
| 1261 |
+
} else {
|
| 1262 |
+
state.commands.push(node.delegate ? `yield*` : `yield`);
|
| 1263 |
+
}
|
| 1264 |
+
}
|
| 1265 |
+
};
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/src/index.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { handle } from './handlers.js';
|
| 2 |
+
import { encode } from '@jridgewell/sourcemap-codec';
|
| 3 |
+
|
| 4 |
+
/** @type {(str: string) => string} str */
|
| 5 |
+
let btoa = () => {
|
| 6 |
+
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
| 7 |
+
};
|
| 8 |
+
|
| 9 |
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
| 10 |
+
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
|
| 11 |
+
// @ts-expect-error
|
| 12 |
+
} else if (typeof Buffer === 'function') {
|
| 13 |
+
// @ts-expect-error
|
| 14 |
+
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @typedef {{
|
| 19 |
+
* sourceMapSource?: string;
|
| 20 |
+
* sourceMapContent?: string;
|
| 21 |
+
* sourceMapEncodeMappings?: boolean; // default true
|
| 22 |
+
* }} PrintOptions
|
| 23 |
+
*/
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* @param {import('estree').Node} node
|
| 27 |
+
* @param {PrintOptions} opts
|
| 28 |
+
* @returns {{ code: string, map: any }} // TODO
|
| 29 |
+
*/
|
| 30 |
+
export function print(node, opts = {}) {
|
| 31 |
+
if (Array.isArray(node)) {
|
| 32 |
+
return print(
|
| 33 |
+
{
|
| 34 |
+
type: 'Program',
|
| 35 |
+
body: node,
|
| 36 |
+
sourceType: 'module'
|
| 37 |
+
},
|
| 38 |
+
opts
|
| 39 |
+
);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/** @type {import('./types').State} */
|
| 43 |
+
const state = {
|
| 44 |
+
commands: [],
|
| 45 |
+
comments: [],
|
| 46 |
+
multiline: false
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
handle(node, state);
|
| 50 |
+
|
| 51 |
+
/** @typedef {[number, number, number, number]} Segment */
|
| 52 |
+
|
| 53 |
+
let code = '';
|
| 54 |
+
let current_column = 0;
|
| 55 |
+
|
| 56 |
+
/** @type {Segment[][]} */
|
| 57 |
+
let mappings = [];
|
| 58 |
+
|
| 59 |
+
/** @type {Segment[]} */
|
| 60 |
+
let current_line = [];
|
| 61 |
+
|
| 62 |
+
/** @param {string} str */
|
| 63 |
+
function append(str) {
|
| 64 |
+
code += str;
|
| 65 |
+
|
| 66 |
+
for (let i = 0; i < str.length; i += 1) {
|
| 67 |
+
if (str[i] === '\n') {
|
| 68 |
+
mappings.push(current_line);
|
| 69 |
+
current_line = [];
|
| 70 |
+
current_column = 0;
|
| 71 |
+
} else {
|
| 72 |
+
current_column += 1;
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
let newline = '\n';
|
| 78 |
+
|
| 79 |
+
/** @param {import('./types').Command} command */
|
| 80 |
+
function run(command) {
|
| 81 |
+
if (typeof command === 'string') {
|
| 82 |
+
append(command);
|
| 83 |
+
return;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
switch (command.type) {
|
| 87 |
+
case 'Chunk':
|
| 88 |
+
const loc = command.loc;
|
| 89 |
+
|
| 90 |
+
if (loc) {
|
| 91 |
+
current_line.push([
|
| 92 |
+
current_column,
|
| 93 |
+
0, // source index is always zero
|
| 94 |
+
loc.start.line - 1,
|
| 95 |
+
loc.start.column
|
| 96 |
+
]);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
append(command.content);
|
| 100 |
+
|
| 101 |
+
if (loc) {
|
| 102 |
+
current_line.push([
|
| 103 |
+
current_column,
|
| 104 |
+
0, // source index is always zero
|
| 105 |
+
loc.end.line - 1,
|
| 106 |
+
loc.end.column
|
| 107 |
+
]);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
break;
|
| 111 |
+
|
| 112 |
+
case 'Newline':
|
| 113 |
+
append(newline);
|
| 114 |
+
break;
|
| 115 |
+
|
| 116 |
+
case 'Indent':
|
| 117 |
+
newline += '\t';
|
| 118 |
+
break;
|
| 119 |
+
|
| 120 |
+
case 'Dedent':
|
| 121 |
+
newline = newline.slice(0, -1);
|
| 122 |
+
break;
|
| 123 |
+
|
| 124 |
+
case 'Sequence':
|
| 125 |
+
for (let i = 0; i < command.children.length; i += 1) {
|
| 126 |
+
run(command.children[i]);
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
break;
|
| 130 |
+
|
| 131 |
+
case 'Comment':
|
| 132 |
+
if (command.comment.type === 'Line') {
|
| 133 |
+
append(`//${command.comment.value}`);
|
| 134 |
+
} else {
|
| 135 |
+
append(`/*${command.comment.value.replace(/\n/g, newline)}*/`);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
break;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
for (let i = 0; i < state.commands.length; i += 1) {
|
| 143 |
+
run(state.commands[i]);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
mappings.push(current_line);
|
| 147 |
+
|
| 148 |
+
const map = {
|
| 149 |
+
version: 3,
|
| 150 |
+
/** @type {string[]} */
|
| 151 |
+
names: [],
|
| 152 |
+
sources: [opts.sourceMapSource || null],
|
| 153 |
+
sourcesContent: [opts.sourceMapContent || null],
|
| 154 |
+
mappings:
|
| 155 |
+
opts.sourceMapEncodeMappings == undefined || opts.sourceMapEncodeMappings
|
| 156 |
+
? encode(mappings)
|
| 157 |
+
: mappings
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
Object.defineProperties(map, {
|
| 161 |
+
toString: {
|
| 162 |
+
enumerable: false,
|
| 163 |
+
value: function toString() {
|
| 164 |
+
return JSON.stringify(this);
|
| 165 |
+
}
|
| 166 |
+
},
|
| 167 |
+
toUrl: {
|
| 168 |
+
enumerable: false,
|
| 169 |
+
value: function toUrl() {
|
| 170 |
+
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
});
|
| 174 |
+
|
| 175 |
+
return {
|
| 176 |
+
code,
|
| 177 |
+
map
|
| 178 |
+
};
|
| 179 |
+
}
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/src/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Comment, Node } from 'estree';
|
| 2 |
+
|
| 3 |
+
type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
|
| 4 |
+
|
| 5 |
+
type Handler<T> = (node: T, state: State) => undefined;
|
| 6 |
+
|
| 7 |
+
export type Handlers = {
|
| 8 |
+
[K in Node['type']]: Handler<NodeOf<K, Node>>;
|
| 9 |
+
};
|
| 10 |
+
|
| 11 |
+
export interface State {
|
| 12 |
+
commands: Command[];
|
| 13 |
+
comments: Comment[];
|
| 14 |
+
multiline: boolean;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export interface Chunk {
|
| 18 |
+
type: 'Chunk';
|
| 19 |
+
content: string;
|
| 20 |
+
loc: null | {
|
| 21 |
+
start: { line: number; column: number };
|
| 22 |
+
end: { line: number; column: number };
|
| 23 |
+
};
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
export interface Newline {
|
| 27 |
+
type: 'Newline';
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
export interface Indent {
|
| 31 |
+
type: 'Indent';
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
export interface Dedent {
|
| 35 |
+
type: 'Dedent';
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export interface IndentChange {
|
| 39 |
+
type: 'IndentChange';
|
| 40 |
+
offset: number;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export interface Sequence {
|
| 44 |
+
type: 'Sequence';
|
| 45 |
+
children: Command[];
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
export interface CommentChunk {
|
| 49 |
+
type: 'Comment';
|
| 50 |
+
comment: Comment;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export type Command = string | Chunk | Newline | Indent | Dedent | Sequence | CommentChunk;
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/types/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module 'esrap' {
|
| 2 |
+
/**
|
| 3 |
+
* @returns // TODO
|
| 4 |
+
*/
|
| 5 |
+
export function print(node: import('estree').Node, opts?: PrintOptions): {
|
| 6 |
+
code: string;
|
| 7 |
+
map: any;
|
| 8 |
+
};
|
| 9 |
+
export type PrintOptions = {
|
| 10 |
+
sourceMapSource?: string;
|
| 11 |
+
sourceMapContent?: string;
|
| 12 |
+
sourceMapEncodeMappings?: boolean;
|
| 13 |
+
};
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
//# sourceMappingURL=index.d.ts.map
|
tools/ui/node_modules/svelte-ast-print/node_modules/esrap/types/index.d.ts.map
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 3,
|
| 3 |
+
"file": "index.d.ts",
|
| 4 |
+
"names": [
|
| 5 |
+
"print"
|
| 6 |
+
],
|
| 7 |
+
"sources": [
|
| 8 |
+
"../src/index.js"
|
| 9 |
+
],
|
| 10 |
+
"sourcesContent": [
|
| 11 |
+
null
|
| 12 |
+
],
|
| 13 |
+
"mappings": ";;;;iBA6BgBA,KAAKA"
|
| 14 |
+
}
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2023 [these people](https://github.com/Rich-Harris/zimmerframe/graphs/contributors)
|
| 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.
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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is an object with a `type: string`. This includes [ESTree](https://github.com/estree/estree) nodes, such as you might generate with [Acorn](https://github.com/acornjs/acorn) or [Meriyah](https://github.com/meriyah/meriyah), but also includes things like [CSSTree](https://github.com/csstree/csstree) or an arbitrary AST of your own devising.
|
| 6 |
+
|
| 7 |
+
## Usage
|
| 8 |
+
|
| 9 |
+
```ts
|
| 10 |
+
import { walk } from 'zimmerframe';
|
| 11 |
+
import { parse } from 'acorn';
|
| 12 |
+
import { Node } from 'estree';
|
| 13 |
+
|
| 14 |
+
const program = parse(`
|
| 15 |
+
let message = 'hello';
|
| 16 |
+
console.log(message);
|
| 17 |
+
|
| 18 |
+
if (true) {
|
| 19 |
+
let answer = 42;
|
| 20 |
+
console.log(answer);
|
| 21 |
+
}
|
| 22 |
+
`);
|
| 23 |
+
|
| 24 |
+
// You can pass in arbitrary state
|
| 25 |
+
const state = {
|
| 26 |
+
declarations: [],
|
| 27 |
+
depth: 0
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
const transformed = walk(program as Node, state, {
|
| 31 |
+
_(node, { state, next }) {
|
| 32 |
+
// the `_` visitor is 'universal' — if provided,
|
| 33 |
+
// it will run for every node, before deferring
|
| 34 |
+
// to specialised visitors. you can pass a new
|
| 35 |
+
// `state` object to `next`
|
| 36 |
+
next({ ...state, answer: 42 });
|
| 37 |
+
},
|
| 38 |
+
VariableDeclarator(node, { state }) {
|
| 39 |
+
// `state` is passed into each visitor
|
| 40 |
+
if (node.id.type === 'Identifier') {
|
| 41 |
+
state.declarations.push({
|
| 42 |
+
depth: state.depth,
|
| 43 |
+
name: node.id.name
|
| 44 |
+
});
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
BlockStatement(node, { state, next, stop }) {
|
| 48 |
+
// you must call `next()` or `next(childState)`
|
| 49 |
+
// to visit child nodes
|
| 50 |
+
console.log('entering BlockStatement');
|
| 51 |
+
next({ ...state, depth: state.depth + 1 });
|
| 52 |
+
console.log('leaving BlockStatement');
|
| 53 |
+
},
|
| 54 |
+
Literal(node) {
|
| 55 |
+
// if you return something, it will replace
|
| 56 |
+
// the current node
|
| 57 |
+
if (node.value === 'hello') {
|
| 58 |
+
return {
|
| 59 |
+
...node,
|
| 60 |
+
value: 'goodbye'
|
| 61 |
+
};
|
| 62 |
+
}
|
| 63 |
+
},
|
| 64 |
+
IfStatement(node, { visit }) {
|
| 65 |
+
// normally, returning a value will halt
|
| 66 |
+
// traversal into child nodes. you can
|
| 67 |
+
// transform children with the current
|
| 68 |
+
// visitors using `visit(node, state?)`
|
| 69 |
+
if (node.test.type === 'Literal' && node.test.value === true) {
|
| 70 |
+
return visit(node.consequent);
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
});
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
The `transformed` AST would look like this:
|
| 77 |
+
|
| 78 |
+
```js
|
| 79 |
+
let message = 'goodbye';
|
| 80 |
+
console.log(message);
|
| 81 |
+
|
| 82 |
+
{
|
| 83 |
+
let answer = 42;
|
| 84 |
+
console.log(answer);
|
| 85 |
+
}
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Types
|
| 89 |
+
|
| 90 |
+
The type of `node` in each visitor is inferred from the visitor's name. For example:
|
| 91 |
+
|
| 92 |
+
```ts
|
| 93 |
+
walk(ast as estree.Node, state, {
|
| 94 |
+
ArrowFunctionExpression(node) {
|
| 95 |
+
// `node` is of type estree.ArrowFunctionExpression
|
| 96 |
+
}
|
| 97 |
+
});
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
For this to work, the first argument should be casted to an union of all the types you plan to visit.
|
| 101 |
+
|
| 102 |
+
You can import types from 'zimmerframe':
|
| 103 |
+
|
| 104 |
+
```ts
|
| 105 |
+
import {
|
| 106 |
+
walk,
|
| 107 |
+
type Visitor,
|
| 108 |
+
type Visitors,
|
| 109 |
+
type Context
|
| 110 |
+
} from 'zimmerframe';
|
| 111 |
+
import type { Node } from 'estree';
|
| 112 |
+
|
| 113 |
+
interface State {...}
|
| 114 |
+
|
| 115 |
+
const node: Node = {...};
|
| 116 |
+
const state: State = {...};
|
| 117 |
+
const visitors: Visitors<Node, State> = {...}
|
| 118 |
+
|
| 119 |
+
walk(node, state, visitors);
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
## Context
|
| 123 |
+
|
| 124 |
+
Each visitor receives a second argument, `context`, which is an object with the following properties and methods:
|
| 125 |
+
|
| 126 |
+
- `next(state?: State): void` — a function that allows you to control when child nodes are visited, and which state they are visited with. If child visitors transform their inputs, this will return the transformed node (if not, returns `undefined`)
|
| 127 |
+
- `path: Node[]` — an array of parent nodes. For example, to get the root node you would do `path.at(0)`; to get the current node's immediate parent you would do `path.at(-1)`
|
| 128 |
+
- `state: State` — an object of the same type as the second argument to `walk`. Visitors can pass new state objects to their children with `next(childState)` or `visit(node, childState)`
|
| 129 |
+
- `stop(): void` — prevents any subsequent traversal
|
| 130 |
+
- `visit(node: Node, state?: State): Node` — returns the result of visiting `node` with the current set of visitors. If no `state` is provided, children will inherit the current state
|
| 131 |
+
|
| 132 |
+
## Immutability
|
| 133 |
+
|
| 134 |
+
ASTs are regarded as immutable. If you return a transformed node from a visitor, then all parents of the node will be replaced with clones, but unchanged subtrees will reuse the existing nodes.
|
| 135 |
+
|
| 136 |
+
For example in this case, no transformation takes place, meaning that the returned value is identical to the original AST:
|
| 137 |
+
|
| 138 |
+
```js
|
| 139 |
+
const transformed = walk(original, state, {
|
| 140 |
+
Literal(node) {
|
| 141 |
+
console.log(node.value);
|
| 142 |
+
}
|
| 143 |
+
});
|
| 144 |
+
|
| 145 |
+
transformed === original; // true
|
| 146 |
+
```
|
| 147 |
+
|
| 148 |
+
In this case, however, we replace one of the nodes:
|
| 149 |
+
|
| 150 |
+
```js
|
| 151 |
+
const original = {
|
| 152 |
+
type: 'BinaryExpression',
|
| 153 |
+
operator: '+',
|
| 154 |
+
left: {
|
| 155 |
+
type: 'Identifier',
|
| 156 |
+
name: 'foo'
|
| 157 |
+
},
|
| 158 |
+
left: {
|
| 159 |
+
type: 'Identifier',
|
| 160 |
+
name: 'bar'
|
| 161 |
+
}
|
| 162 |
+
};
|
| 163 |
+
|
| 164 |
+
const transformed = walk(original, state, {
|
| 165 |
+
Identifier(node) {
|
| 166 |
+
if (node.name === 'bar') {
|
| 167 |
+
return { ...node, name: 'baz' };
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
});
|
| 171 |
+
|
| 172 |
+
transformed === original; // false, the BinaryExpression node is cloned
|
| 173 |
+
transformed.left === original.left; // true, we can safely reuse this node
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
This makes it very easy to transform parts of your AST without incurring the performance and memory overhead of cloning the entire thing, and without the footgun of mutating it in place.
|
| 177 |
+
|
| 178 |
+
## License
|
| 179 |
+
|
| 180 |
+
MIT
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "zimmerframe",
|
| 3 |
+
"description": "A tool for walking ASTs",
|
| 4 |
+
"version": "1.1.2",
|
| 5 |
+
"repository": {
|
| 6 |
+
"type": "git",
|
| 7 |
+
"url": "https://github.com/Rich-Harris/zimmerframe"
|
| 8 |
+
},
|
| 9 |
+
"type": "module",
|
| 10 |
+
"exports": {
|
| 11 |
+
".": {
|
| 12 |
+
"types": "./types/index.d.ts",
|
| 13 |
+
"import": "./src/walk.js"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"types": "./types/index.d.ts",
|
| 17 |
+
"files": [
|
| 18 |
+
"src",
|
| 19 |
+
"types"
|
| 20 |
+
],
|
| 21 |
+
"devDependencies": {
|
| 22 |
+
"dts-buddy": "^0.1.13",
|
| 23 |
+
"typescript": "^5.1.6",
|
| 24 |
+
"vitest": "^0.34.2"
|
| 25 |
+
},
|
| 26 |
+
"scripts": {
|
| 27 |
+
"prepublishOnly": "dts-buddy -m zimmerframe:src/index.d.ts",
|
| 28 |
+
"check": "tsc",
|
| 29 |
+
"test": "vitest --run",
|
| 30 |
+
"test:watch": "vitest"
|
| 31 |
+
},
|
| 32 |
+
"license": "MIT",
|
| 33 |
+
"packageManager": "pnpm@8.6.12"
|
| 34 |
+
}
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/src/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from './walk.js';
|
| 2 |
+
export * from './types.d.ts';
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/src/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
type BaseNode = { type: string };
|
| 2 |
+
|
| 3 |
+
type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
|
| 4 |
+
|
| 5 |
+
type SpecialisedVisitors<T extends BaseNode, U> = {
|
| 6 |
+
[K in T['type']]?: Visitor<NodeOf<K, T>, U, T>;
|
| 7 |
+
};
|
| 8 |
+
|
| 9 |
+
export type Visitor<T, U, V> = (node: T, context: Context<V, U>) => V | void;
|
| 10 |
+
|
| 11 |
+
export type Visitors<T extends BaseNode, U> = T['type'] extends '_'
|
| 12 |
+
? never
|
| 13 |
+
: SpecialisedVisitors<T, U> & { _?: Visitor<T, U, T> };
|
| 14 |
+
|
| 15 |
+
export interface Context<T, U> {
|
| 16 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @template {{type: string}} T
|
| 3 |
+
* @template {Record<string, any> | null} U
|
| 4 |
+
* @param {T} node
|
| 5 |
+
* @param {U} state
|
| 6 |
+
* @param {import('./types').Visitors<T, U>} visitors
|
| 7 |
+
*/
|
| 8 |
+
export function walk(node, state, visitors) {
|
| 9 |
+
const universal = visitors._;
|
| 10 |
+
|
| 11 |
+
let stopped = false;
|
| 12 |
+
|
| 13 |
+
/** @type {import('./types').Visitor<T, U, T>} _ */
|
| 14 |
+
function default_visitor(_, { next, state }) {
|
| 15 |
+
next(state);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* @param {T} node
|
| 20 |
+
* @param {T[]} path
|
| 21 |
+
* @param {U} state
|
| 22 |
+
* @returns {T | undefined}
|
| 23 |
+
*/
|
| 24 |
+
function visit(node, path, state) {
|
| 25 |
+
// Don't return the node here or it could lead to false-positive mutation detection
|
| 26 |
+
if (stopped) return;
|
| 27 |
+
if (!node.type) return;
|
| 28 |
+
|
| 29 |
+
/** @type {T | void} */
|
| 30 |
+
let result;
|
| 31 |
+
|
| 32 |
+
/** @type {Record<string, any>} */
|
| 33 |
+
const mutations = {};
|
| 34 |
+
|
| 35 |
+
/** @type {import('./types').Context<T, U>} */
|
| 36 |
+
const context = {
|
| 37 |
+
path,
|
| 38 |
+
state,
|
| 39 |
+
next: (next_state = state) => {
|
| 40 |
+
path.push(node);
|
| 41 |
+
for (const key in node) {
|
| 42 |
+
if (key === 'type') continue;
|
| 43 |
+
|
| 44 |
+
const child_node = node[key];
|
| 45 |
+
if (child_node && typeof child_node === 'object') {
|
| 46 |
+
if (Array.isArray(child_node)) {
|
| 47 |
+
/** @type {Record<number, T>} */
|
| 48 |
+
const array_mutations = {};
|
| 49 |
+
|
| 50 |
+
child_node.forEach((node, i) => {
|
| 51 |
+
if (node && typeof node === 'object') {
|
| 52 |
+
const result = visit(node, path, next_state);
|
| 53 |
+
if (result) array_mutations[i] = result;
|
| 54 |
+
}
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
if (Object.keys(array_mutations).length > 0) {
|
| 58 |
+
mutations[key] = child_node.map(
|
| 59 |
+
(node, i) => array_mutations[i] ?? node
|
| 60 |
+
);
|
| 61 |
+
}
|
| 62 |
+
} else {
|
| 63 |
+
const result = visit(
|
| 64 |
+
/** @type {T} */ (child_node),
|
| 65 |
+
path,
|
| 66 |
+
next_state
|
| 67 |
+
);
|
| 68 |
+
|
| 69 |
+
// @ts-ignore
|
| 70 |
+
if (result) {
|
| 71 |
+
mutations[key] = result;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
path.pop();
|
| 77 |
+
|
| 78 |
+
if (Object.keys(mutations).length > 0) {
|
| 79 |
+
return apply_mutations(node, mutations);
|
| 80 |
+
}
|
| 81 |
+
},
|
| 82 |
+
stop: () => {
|
| 83 |
+
stopped = true;
|
| 84 |
+
},
|
| 85 |
+
visit: (next_node, next_state = state) => {
|
| 86 |
+
path.push(node);
|
| 87 |
+
const result = visit(next_node, path, next_state) ?? next_node;
|
| 88 |
+
path.pop();
|
| 89 |
+
return result;
|
| 90 |
+
}
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
let visitor = /** @type {import('./types').Visitor<T, U, T>} */ (
|
| 94 |
+
visitors[/** @type {T['type']} */ (node.type)] ?? default_visitor
|
| 95 |
+
);
|
| 96 |
+
|
| 97 |
+
if (universal) {
|
| 98 |
+
/** @type {T | void} */
|
| 99 |
+
let inner_result;
|
| 100 |
+
|
| 101 |
+
result = universal(node, {
|
| 102 |
+
...context,
|
| 103 |
+
/** @param {U} next_state */
|
| 104 |
+
next: (next_state = state) => {
|
| 105 |
+
state = next_state; // make it the default for subsequent specialised visitors
|
| 106 |
+
|
| 107 |
+
inner_result = visitor(node, {
|
| 108 |
+
...context,
|
| 109 |
+
state: next_state
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
return inner_result;
|
| 113 |
+
}
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
// @ts-expect-error TypeScript doesn't understand that `context.next(...)` is called immediately
|
| 117 |
+
if (!result && inner_result) {
|
| 118 |
+
result = inner_result;
|
| 119 |
+
}
|
| 120 |
+
} else {
|
| 121 |
+
result = visitor(node, context);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if (!result) {
|
| 125 |
+
if (Object.keys(mutations).length > 0) {
|
| 126 |
+
result = apply_mutations(node, mutations);
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
if (result) {
|
| 131 |
+
return result;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
return visit(node, [], state) ?? node;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/**
|
| 139 |
+
* @template {Record<string, any>} T
|
| 140 |
+
* @param {T} node
|
| 141 |
+
* @param {Record<string, any>} mutations
|
| 142 |
+
* @returns {T}
|
| 143 |
+
*/
|
| 144 |
+
function apply_mutations(node, mutations) {
|
| 145 |
+
/** @type {Record<string, any>} */
|
| 146 |
+
const obj = {};
|
| 147 |
+
|
| 148 |
+
const descriptors = Object.getOwnPropertyDescriptors(node);
|
| 149 |
+
|
| 150 |
+
for (const key in descriptors) {
|
| 151 |
+
Object.defineProperty(obj, key, descriptors[key]);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
for (const key in mutations) {
|
| 155 |
+
obj[key] = mutations[key];
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
return /** @type {T} */ (obj);
|
| 159 |
+
}
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/types/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module 'zimmerframe' {
|
| 2 |
+
export function walk<T extends {
|
| 3 |
+
type: string;
|
| 4 |
+
}, U extends Record<string, any> | null>(node: T, state: U, visitors: Visitors<T, U>): T;
|
| 5 |
+
type BaseNode = { type: string };
|
| 6 |
+
|
| 7 |
+
type NodeOf<T extends string, X> = X extends { type: T } ? X : never;
|
| 8 |
+
|
| 9 |
+
type SpecialisedVisitors<T extends BaseNode, U> = {
|
| 10 |
+
[K in T['type']]?: Visitor<NodeOf<K, T>, U, T>;
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
export type Visitor<T, U, V> = (node: T, context: Context<V, U>) => V | void;
|
| 14 |
+
|
| 15 |
+
export type Visitors<T extends BaseNode, U> = T['type'] extends '_'
|
| 16 |
+
? never
|
| 17 |
+
: SpecialisedVisitors<T, U> & { _?: Visitor<T, U, T> };
|
| 18 |
+
|
| 19 |
+
export interface Context<T, U> {
|
| 20 |
+
next: (state?: U) => T | void;
|
| 21 |
+
path: T[];
|
| 22 |
+
state: U;
|
| 23 |
+
stop: () => void;
|
| 24 |
+
visit: (node: T, state?: U) => T;
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
//# sourceMappingURL=index.d.ts.map
|
tools/ui/node_modules/svelte-ast-print/node_modules/zimmerframe/types/index.d.ts.map
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 3,
|
| 3 |
+
"file": "index.d.ts",
|
| 4 |
+
"names": [
|
| 5 |
+
"walk",
|
| 6 |
+
"Visitor",
|
| 7 |
+
"Visitors",
|
| 8 |
+
"Context"
|
| 9 |
+
],
|
| 10 |
+
"sources": [
|
| 11 |
+
"../src/walk.js",
|
| 12 |
+
"../src/types.d.ts"
|
| 13 |
+
],
|
| 14 |
+
"sourcesContent": [
|
| 15 |
+
null,
|
| 16 |
+
null
|
| 17 |
+
],
|
| 18 |
+
"mappings": ";iBAOgBA,IAAIA;;;;;;;;;;;aCCRC,OAAOA;;aAEPC,QAAQA;;;;kBAIHC,OAAOA"
|
| 19 |
+
}
|
tools/ui/node_modules/svelte-ast-print/package.json
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json.schemastore.org/package",
|
| 3 |
+
"name": "svelte-ast-print",
|
| 4 |
+
"version": "0.4.2",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"description": "Print Svelte AST nodes as a string. Aka parse in reverse.",
|
| 7 |
+
"keywords": [
|
| 8 |
+
"svelte",
|
| 9 |
+
"ast",
|
| 10 |
+
"print"
|
| 11 |
+
],
|
| 12 |
+
"license": "MIT",
|
| 13 |
+
"author": {
|
| 14 |
+
"name": "Mateusz Kadlubowski",
|
| 15 |
+
"email": "xeho91@pm.me",
|
| 16 |
+
"url": "https://github.com/xeho91"
|
| 17 |
+
},
|
| 18 |
+
"homepage": "https://github.com/xeho91/svelte-ast-print",
|
| 19 |
+
"repository": {
|
| 20 |
+
"type": "git",
|
| 21 |
+
"url": "git+https://github.com/xeho91/svelte-ast-print.git"
|
| 22 |
+
},
|
| 23 |
+
"bugs": "https://github.com/xeho91/svelte-ast-print/issues",
|
| 24 |
+
"funding": [
|
| 25 |
+
{
|
| 26 |
+
"type": "github",
|
| 27 |
+
"url": "https://github.com/sponsors/xeho91"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"type": "opencollective",
|
| 31 |
+
"url": "https://opencollective.com/xeho91"
|
| 32 |
+
}
|
| 33 |
+
],
|
| 34 |
+
"publishConfig": {
|
| 35 |
+
"access": "public",
|
| 36 |
+
"provenance": true
|
| 37 |
+
},
|
| 38 |
+
"engines": {
|
| 39 |
+
"node": ">=18"
|
| 40 |
+
},
|
| 41 |
+
"files": [
|
| 42 |
+
"src/",
|
| 43 |
+
"types/"
|
| 44 |
+
],
|
| 45 |
+
"imports": {
|
| 46 |
+
"#tests/*": {
|
| 47 |
+
"types": "./tests/*.ts",
|
| 48 |
+
"development": "./tests/*.ts"
|
| 49 |
+
},
|
| 50 |
+
"#*": {
|
| 51 |
+
"types": "./src/*.js",
|
| 52 |
+
"development": "./src/*.js",
|
| 53 |
+
"default": "./src/*.js"
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
"exports": {
|
| 57 |
+
".": {
|
| 58 |
+
"types": "./types/mod.d.ts",
|
| 59 |
+
"default": "./src/mod.js"
|
| 60 |
+
},
|
| 61 |
+
"./package.json": "./package.json"
|
| 62 |
+
},
|
| 63 |
+
"types": "./types/mod.d.ts",
|
| 64 |
+
"packageManager": "pnpm@9.9.0+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1",
|
| 65 |
+
"scripts": {
|
| 66 |
+
"build": "pnpm run \"/^build:.*/\" ",
|
| 67 |
+
"build:doc": "typedoc",
|
| 68 |
+
"build:types": "dts-buddy",
|
| 69 |
+
"clean": "pnpm run \"/^clean:.*/\"; rm -rf \"./**/node_modules\" ",
|
| 70 |
+
"clean:cache": "rm -rf \"./node_modules/.cache\" ",
|
| 71 |
+
"clean:doc": "rm -rf \"./docs\" ",
|
| 72 |
+
"clean:test": "rm -rf \"./coverage\" ",
|
| 73 |
+
"clean:types": "rm -rf \"./types\" ",
|
| 74 |
+
"dev": "pnpm run \"/^dev:.*/\" ",
|
| 75 |
+
"dev:doc": "typedoc --watch",
|
| 76 |
+
"dev:test": "pnpm vitest watch --passWithNoTests --ui",
|
| 77 |
+
"fix": "pnpm run \"/^fix:.*/\" ",
|
| 78 |
+
"fix:biome": "biome check . --verbose --write",
|
| 79 |
+
"fix:format": "biome format . --verbose --write",
|
| 80 |
+
"fix:js": "biome lint . --verbose --fix --unsafe",
|
| 81 |
+
"fix:md": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\" \"#./CHANGELOG.md\" --fix",
|
| 82 |
+
"fix:typos": "typos --verbose --write-changes",
|
| 83 |
+
"lint": "pnpm run \"/^lint:.*/\" ",
|
| 84 |
+
"lint:biome": "biome check . --verbose",
|
| 85 |
+
"lint:format": "biome format . --verbose",
|
| 86 |
+
"lint:js": "biome lint . --verbose",
|
| 87 |
+
"lint:md": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\" \"#./CHANGELOG.md\" ",
|
| 88 |
+
"lint:ts": "tsc --noEmit",
|
| 89 |
+
"lint:typos": "typos --verbose",
|
| 90 |
+
"prepare": "pnpm build:types",
|
| 91 |
+
"prepublishOnly": "pnpm test && pnpm build:types",
|
| 92 |
+
"release": "pnpm build:types && pnpm auto shipit",
|
| 93 |
+
"serve:doc": "serve \"./docs\" ",
|
| 94 |
+
"test": "vitest run . --passWithNoTests"
|
| 95 |
+
},
|
| 96 |
+
"dependencies": {
|
| 97 |
+
"esrap": "1.2.2",
|
| 98 |
+
"zimmerframe": "1.1.2"
|
| 99 |
+
},
|
| 100 |
+
"devDependencies": {
|
| 101 |
+
"@auto-it/all-contributors": "11.3.0",
|
| 102 |
+
"@auto-it/conventional-commits": "11.3.0",
|
| 103 |
+
"@auto-it/first-time-contributor": "11.3.0",
|
| 104 |
+
"@auto-it/npm": "11.3.0",
|
| 105 |
+
"@auto-it/released": "11.3.0",
|
| 106 |
+
"@biomejs/biome": "1.9.4",
|
| 107 |
+
"@total-typescript/ts-reset": "0.6.1",
|
| 108 |
+
"@total-typescript/tsconfig": "1.0.4",
|
| 109 |
+
"@types/estree": "1.0.6",
|
| 110 |
+
"@types/node": "22.8.4",
|
| 111 |
+
"@vitest/coverage-v8": "2.1.4",
|
| 112 |
+
"@vitest/ui": "2.1.4",
|
| 113 |
+
"all-contributors-cli": "6.26.1",
|
| 114 |
+
"auto": "11.3.0",
|
| 115 |
+
"dedent": "1.5.3",
|
| 116 |
+
"dts-buddy": "0.5.3",
|
| 117 |
+
"markdownlint-cli2": "0.14.0",
|
| 118 |
+
"serve": "14.2.4",
|
| 119 |
+
"svelte": "5.1.4",
|
| 120 |
+
"type-fest": "4.26.1",
|
| 121 |
+
"typedoc": "0.26.10",
|
| 122 |
+
"typedoc-plugin-coverage": "3.3.0",
|
| 123 |
+
"typedoc-plugin-mdn-links": "3.3.5",
|
| 124 |
+
"typescript": "5.6.3",
|
| 125 |
+
"vitest": "2.1.4"
|
| 126 |
+
},
|
| 127 |
+
"peerDependencies": {
|
| 128 |
+
"svelte": "^5.0.0"
|
| 129 |
+
}
|
| 130 |
+
}
|
tools/ui/node_modules/svelte-ast-print/src/mod.js
ADDED
|
@@ -0,0 +1,1587 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @import * as EstreeAST from "estree";
|
| 3 |
+
* @import { AST as SvelteAST } from "svelte/compiler";
|
| 4 |
+
* @import { Context } from "zimmerframe";
|
| 5 |
+
*
|
| 6 |
+
* @import { Node, SvelteNode } from "./nodes.js";
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
import { print as print_es } from "esrap";
|
| 10 |
+
import { walk } from "zimmerframe";
|
| 11 |
+
|
| 12 |
+
import { is_attribute_like_node, is_element_like_node, is_svelte_node } from "./nodes.js";
|
| 13 |
+
import { Options } from "./options.js";
|
| 14 |
+
|
| 15 |
+
export {
|
| 16 |
+
is_attribute_like_node as isAttributeLikeNode,
|
| 17 |
+
is_block_node as isBlockNode,
|
| 18 |
+
is_css_node as isCssNode,
|
| 19 |
+
is_element_like_node as isElementLikeNode,
|
| 20 |
+
is_html_node as isHtmlNode,
|
| 21 |
+
is_svelte_node as isSvelteNode,
|
| 22 |
+
is_tag_node as isTagNode,
|
| 23 |
+
is_template_node as isTemplateNode,
|
| 24 |
+
} from "./nodes.js";
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Print AST {@link SvelteAST.BaseNode} as a string.
|
| 28 |
+
* Aka parse in reverse.
|
| 29 |
+
*
|
| 30 |
+
* ## How does it work under the hood?
|
| 31 |
+
*
|
| 32 |
+
* 1. Firstly, it determines whether the provided AST node is unique node for Svelte {@link SvelteAST.Node}.
|
| 33 |
+
* 2. Based on type check guard from above:
|
| 34 |
+
* - it uses either this package's {@link Printer} to print Svelte AST node,
|
| 35 |
+
* - otherwise it uses `esrap` {@link print_es} to print ESTree specification-complaint AST node
|
| 36 |
+
*
|
| 37 |
+
* ## How to use it?
|
| 38 |
+
*
|
| 39 |
+
* @example writing a codemode using Node.js
|
| 40 |
+
```js
|
| 41 |
+
import fs from "node:fs";
|
| 42 |
+
|
| 43 |
+
import { print } from "svelte-ast-print";
|
| 44 |
+
import { parse } from "svelte/compiler";
|
| 45 |
+
|
| 46 |
+
const originalSvelteCode = fs.readFileSync("src/App.svelte", "utf-8");
|
| 47 |
+
let svelteAST = parse(originalSvelteCode, { modern: true });
|
| 48 |
+
// 👆 For now, only modern is supported.
|
| 49 |
+
// By default is 'false'.
|
| 50 |
+
// Is it planned to be 'true' from Svelte v6+
|
| 51 |
+
|
| 52 |
+
// ...
|
| 53 |
+
// Do some modifications on this AST...
|
| 54 |
+
// e.g. transform `<slot />` to `{@render children()}`
|
| 55 |
+
// ...
|
| 56 |
+
|
| 57 |
+
const output = print(svelteAST); // AST is now a stringified code output! 🎉
|
| 58 |
+
|
| 59 |
+
fs.writeFileSync("src/App.svelte", output, { encoding: " utf-8" });
|
| 60 |
+
```
|
| 61 |
+
*
|
| 62 |
+
* @param {Node} node - Svelte or ESTree AST node
|
| 63 |
+
* @param {Partial<ConstructorParameters<typeof Options>[0]>} options - printing options
|
| 64 |
+
* @returns {string} Stringified Svelte AST node
|
| 65 |
+
* TODO: Ask Svelte maintainers if `Script` and `SvelteOptions` were omittted from `SvelteNode` intentionally - possibly forgotten to include
|
| 66 |
+
*/
|
| 67 |
+
export function print(node, options = {}) {
|
| 68 |
+
if (is_svelte_node(node)) {
|
| 69 |
+
return new Printer(node, new Options(options)).toString();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
return print_es(node).code;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
class Printer {
|
| 76 |
+
/**
|
| 77 |
+
* @type {SvelteNode}
|
| 78 |
+
*/
|
| 79 |
+
#node;
|
| 80 |
+
/**
|
| 81 |
+
* @type {Options}
|
| 82 |
+
*/
|
| 83 |
+
#options;
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* @type {number}
|
| 87 |
+
*/
|
| 88 |
+
#depth = 0;
|
| 89 |
+
/**
|
| 90 |
+
* @type {string}
|
| 91 |
+
*/
|
| 92 |
+
#output = "";
|
| 93 |
+
/**
|
| 94 |
+
* @type {Set<string>}
|
| 95 |
+
*/
|
| 96 |
+
#attributes = new Set();
|
| 97 |
+
/**
|
| 98 |
+
* @type {boolean}
|
| 99 |
+
*/
|
| 100 |
+
#has_template_literal = false;
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* @param {Node} node - Svelte or ESTree AST node
|
| 104 |
+
* @param {Options} options - transformed options
|
| 105 |
+
*/
|
| 106 |
+
constructor(node, options) {
|
| 107 |
+
this.#node = node;
|
| 108 |
+
this.#options = options;
|
| 109 |
+
this.#produce();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/**
|
| 113 |
+
* @returns {string}
|
| 114 |
+
*/
|
| 115 |
+
toString() {
|
| 116 |
+
if (is_attribute_like_node(this.#node)) {
|
| 117 |
+
return this.#stringified_attributes;
|
| 118 |
+
}
|
| 119 |
+
return this.#output;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* @param {string} code
|
| 124 |
+
* @returns {void}
|
| 125 |
+
*/
|
| 126 |
+
#print(code) {
|
| 127 |
+
this.#output += code;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* @returns {void}
|
| 132 |
+
*/
|
| 133 |
+
#print_new_line() {
|
| 134 |
+
this.#output += "\n";
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
#print_opening_new_line() {
|
| 138 |
+
if (this.#is_last_output_script_closing_tag) {
|
| 139 |
+
this.#print_new_line();
|
| 140 |
+
this.#print_new_line();
|
| 141 |
+
} else if (
|
| 142 |
+
this.#is_last_output_closing_block ||
|
| 143 |
+
this.#is_last_output_closing_comment ||
|
| 144 |
+
this.#is_last_output_opening_element_like ||
|
| 145 |
+
this.#is_last_output_closing_element_like
|
| 146 |
+
) {
|
| 147 |
+
this.#print_new_line();
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/**
|
| 152 |
+
* @returns {void}
|
| 153 |
+
*/
|
| 154 |
+
#print_space() {
|
| 155 |
+
this.#output += " ";
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Depth aware indent
|
| 160 |
+
* @returns {string}
|
| 161 |
+
*/
|
| 162 |
+
get #indent() {
|
| 163 |
+
const { indent } = this.#options;
|
| 164 |
+
return Array(this.#depth).fill(indent).join("");
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
/**
|
| 168 |
+
* @returns {void}
|
| 169 |
+
*/
|
| 170 |
+
#print_indent() {
|
| 171 |
+
this.#output += this.#indent;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
get #stringified_attributes() {
|
| 175 |
+
// TODO: Determine what join should be, space or new line, based on options.
|
| 176 |
+
if (this.#attributes.size > 0) {
|
| 177 |
+
return [...this.#attributes].join(" ");
|
| 178 |
+
}
|
| 179 |
+
return "";
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/**
|
| 183 |
+
* @typedef PrintEsNodeOptions
|
| 184 |
+
* @property {boolean} [skip_indent]
|
| 185 |
+
*/
|
| 186 |
+
|
| 187 |
+
/**
|
| 188 |
+
* @param {Parameters<typeof print_es>[0]} node
|
| 189 |
+
* @param {Partial<PrintEsNodeOptions> | undefined} options
|
| 190 |
+
* @returns {void}
|
| 191 |
+
*/
|
| 192 |
+
#print_es_node(node, options = {}) {
|
| 193 |
+
const { skip_indent = false } = options;
|
| 194 |
+
let { code } = print_es(node);
|
| 195 |
+
if (skip_indent) this.#output += code;
|
| 196 |
+
else {
|
| 197 |
+
code = code.replace(/^(?=.+)/gm, this.#indent);
|
| 198 |
+
this.#output += code.replace(
|
| 199 |
+
// NOTE: This temporary solution is supposed to remove auto-indentation from the content inside
|
| 200 |
+
// `TemplateLiteral`.
|
| 201 |
+
// Reference: https://github.com/storybookjs/addon-svelte-csf/issues/227
|
| 202 |
+
/`[^`].*[^`]*`/g,
|
| 203 |
+
(match) => {
|
| 204 |
+
return match.replace(new RegExp(this.#indent, "g"), "");
|
| 205 |
+
},
|
| 206 |
+
);
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
/**
|
| 211 |
+
* By default we assume everything starts with an indent or new line
|
| 212 |
+
* @type {boolean}
|
| 213 |
+
*/
|
| 214 |
+
#was_last_text_indent_or_space_only = true;
|
| 215 |
+
|
| 216 |
+
/**
|
| 217 |
+
* @param {SvelteAST.Text} node
|
| 218 |
+
* @returns {boolean}
|
| 219 |
+
*/
|
| 220 |
+
#is_text_new_line_or_indents_only(node) {
|
| 221 |
+
// TODO: Refactor, there's probably a smarter regex to achieve it
|
| 222 |
+
const { raw } = node;
|
| 223 |
+
if (raw === " ") return this.#was_last_text_indent_or_space_only;
|
| 224 |
+
if (this.#depth === 0) return /^(?: {1,}|\t|\n)*$/.test(raw);
|
| 225 |
+
return /^(?: {2,}|\t|\n)*$/.test(raw);
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
/**
|
| 229 |
+
* @param {SvelteAST.Fragment} fragment
|
| 230 |
+
* @returns {boolean}
|
| 231 |
+
*/
|
| 232 |
+
#has_fragment_element_like_node(fragment) {
|
| 233 |
+
const { nodes } = fragment;
|
| 234 |
+
for (const node of nodes) {
|
| 235 |
+
if (is_element_like_node(node)) return true;
|
| 236 |
+
if (node.type === "Text" && this.#is_text_new_line_or_indents_only(node)) continue;
|
| 237 |
+
break;
|
| 238 |
+
}
|
| 239 |
+
return false;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* @param {SvelteAST.Fragment} fragment
|
| 244 |
+
* @returns {boolean}
|
| 245 |
+
*/
|
| 246 |
+
#is_fragment_empty(fragment) {
|
| 247 |
+
return fragment.nodes.length === 0;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/**
|
| 251 |
+
* @param {"await" | "each" | "if" | "key" | "snippet"} name
|
| 252 |
+
* @param {string} content
|
| 253 |
+
* @returns {void}
|
| 254 |
+
*/
|
| 255 |
+
#print_block_opening_tag(name, content) {
|
| 256 |
+
this.#print_opening_new_line();
|
| 257 |
+
this.#print_indent();
|
| 258 |
+
this.#print("{");
|
| 259 |
+
this.#print("#");
|
| 260 |
+
this.#print(name);
|
| 261 |
+
this.#print_space();
|
| 262 |
+
this.#print(content);
|
| 263 |
+
this.#print("}");
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
/**
|
| 267 |
+
* @param {"then" | "catch" | "else if" | "else"} name
|
| 268 |
+
* @param {string} [content]
|
| 269 |
+
* @returns {void}
|
| 270 |
+
*/
|
| 271 |
+
#print_block_middle_tag(name, content) {
|
| 272 |
+
this.#print_opening_new_line();
|
| 273 |
+
if (this.#is_last_output_new_line) this.#print_indent();
|
| 274 |
+
this.#print("{:");
|
| 275 |
+
this.#print(name);
|
| 276 |
+
if (content) {
|
| 277 |
+
this.#print_space();
|
| 278 |
+
this.#print(content);
|
| 279 |
+
}
|
| 280 |
+
this.#print("}");
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
/**
|
| 284 |
+
* @param {"await" | "each" | "if" | "key" | "snippet"} name
|
| 285 |
+
* @returns {void}
|
| 286 |
+
*/
|
| 287 |
+
#print_block_closing_tag(name) {
|
| 288 |
+
this.#print_new_line();
|
| 289 |
+
this.#print_indent();
|
| 290 |
+
this.#print("{/");
|
| 291 |
+
this.#print(name);
|
| 292 |
+
this.#print("}");
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
/**
|
| 296 |
+
* @param {SvelteAST.Fragment} node
|
| 297 |
+
* @param {Context<Node, typeof this>} context
|
| 298 |
+
* @returns {void}
|
| 299 |
+
*/
|
| 300 |
+
#print_block_fragment(node, context) {
|
| 301 |
+
const { visit } = context;
|
| 302 |
+
this.#print_new_line();
|
| 303 |
+
this.#depth++;
|
| 304 |
+
visit(node, this);
|
| 305 |
+
if (this.#depth > 0) this.#depth--;
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
/**
|
| 309 |
+
* @typedef PrintElementLikeOpeningTagOptions
|
| 310 |
+
* @property {boolean}[self_close]
|
| 311 |
+
*/
|
| 312 |
+
|
| 313 |
+
/**
|
| 314 |
+
* @param {string} name
|
| 315 |
+
* @param {Partial<PrintElementLikeOpeningTagOptions>} [options]
|
| 316 |
+
* @returns {void}
|
| 317 |
+
*/
|
| 318 |
+
#print_element_like_opening_tag(name, options = {}) {
|
| 319 |
+
const { self_close = false } = options;
|
| 320 |
+
this.#print_opening_new_line();
|
| 321 |
+
if (this.#is_last_output_new_line) this.#print_indent();
|
| 322 |
+
this.#print("<");
|
| 323 |
+
this.#print(name);
|
| 324 |
+
if (this.#attributes.size > 0) {
|
| 325 |
+
this.#print_space();
|
| 326 |
+
this.#print(this.#stringified_attributes);
|
| 327 |
+
this.#attributes.clear();
|
| 328 |
+
}
|
| 329 |
+
if (self_close) {
|
| 330 |
+
if (!this.#is_last_output_new_line) this.#print_space();
|
| 331 |
+
this.#print("/");
|
| 332 |
+
}
|
| 333 |
+
this.#print(">");
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
/**
|
| 337 |
+
* @param {string} name
|
| 338 |
+
* @returns {void}
|
| 339 |
+
*/
|
| 340 |
+
#print_element_like_closing_tag(name) {
|
| 341 |
+
if (this.#is_last_output_closing_element_like || this.#is_last_output_closing_block) this.#print_new_line();
|
| 342 |
+
if (this.#is_last_output_new_line) this.#print_indent();
|
| 343 |
+
this.#print("<");
|
| 344 |
+
this.#print("/");
|
| 345 |
+
this.#print(name);
|
| 346 |
+
this.#print(">");
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
/**
|
| 350 |
+
* @param {SvelteAST.Fragment} node
|
| 351 |
+
* @param {Context<Node, typeof this>} context
|
| 352 |
+
* @returns {void}
|
| 353 |
+
*/
|
| 354 |
+
#print_element_like_fragment(node, context) {
|
| 355 |
+
const { visit } = context;
|
| 356 |
+
if (this.#has_fragment_element_like_node(node)) this.#print_new_line();
|
| 357 |
+
visit(node, this);
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
/**
|
| 361 |
+
* @param {SvelteAST.ElementLike} node
|
| 362 |
+
* @param {Context<Node, typeof this>} context
|
| 363 |
+
* @returns {void}
|
| 364 |
+
*/
|
| 365 |
+
#print_element_like(node, context) {
|
| 366 |
+
const { attributes, fragment, name } = node;
|
| 367 |
+
const { state, visit } = context;
|
| 368 |
+
const is_self_closing = this.#is_fragment_empty(fragment);
|
| 369 |
+
for (const attribute_like of attributes) {
|
| 370 |
+
visit(attribute_like, state);
|
| 371 |
+
}
|
| 372 |
+
this.#print_element_like_opening_tag(name, { self_close: is_self_closing });
|
| 373 |
+
if (fragment && !is_self_closing) {
|
| 374 |
+
this.#depth++;
|
| 375 |
+
this.#print_element_like_fragment(fragment, context);
|
| 376 |
+
this.#depth--;
|
| 377 |
+
this.#print_element_like_closing_tag(name);
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
/**
|
| 382 |
+
* @param {SvelteAST.ExpressionTag} node
|
| 383 |
+
* @returns {string}
|
| 384 |
+
*/
|
| 385 |
+
#serialize_expression_tag(node) {
|
| 386 |
+
const { expression } = node;
|
| 387 |
+
return `{${print_es(expression).code}}`;
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
/**
|
| 391 |
+
* @param {SvelteAST.Text | SvelteAST.ExpressionTag} node
|
| 392 |
+
* @returns {string}
|
| 393 |
+
*/
|
| 394 |
+
#serialize_attribute_like_text_or_expression_tag(node) {
|
| 395 |
+
if (node.type === "Text") {
|
| 396 |
+
const { raw } = node;
|
| 397 |
+
return `"${raw}"`;
|
| 398 |
+
}
|
| 399 |
+
return this.#serialize_expression_tag(node);
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
/**
|
| 403 |
+
* @typedef StringifyDirectiveParams
|
| 404 |
+
* @property {"animate" | "bind" | "class" | "let" | "on" | "style" | "in" | "out" | "transition" | "use"} directive
|
| 405 |
+
* @property {string} name
|
| 406 |
+
* @property {EstreeAST.Expression | EstreeAST.MemberExpression | null} expression
|
| 407 |
+
* @property {string[]} [modifiers]
|
| 408 |
+
*/
|
| 409 |
+
|
| 410 |
+
/**
|
| 411 |
+
* @param {StringifyDirectiveParams["directive"]} directive
|
| 412 |
+
* @param {StringifyDirectiveParams["name"]} name
|
| 413 |
+
* @returns {string}
|
| 414 |
+
*/
|
| 415 |
+
#stringify_directive_name(directive, name) {
|
| 416 |
+
return `${directive}:${name}`;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
/**
|
| 420 |
+
* @param {NonNullable<StringifyDirectiveParams["modifiers"]>} modifiers
|
| 421 |
+
* @returns {string}
|
| 422 |
+
*/
|
| 423 |
+
#stringify_directive_modifiers(modifiers) {
|
| 424 |
+
let results = "";
|
| 425 |
+
if (modifiers?.length > 0) {
|
| 426 |
+
results += "|";
|
| 427 |
+
results += modifiers.join("|");
|
| 428 |
+
}
|
| 429 |
+
return results;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
/**
|
| 433 |
+
* @param {StringifyDirectiveParams} params
|
| 434 |
+
* @returns {string}
|
| 435 |
+
*/
|
| 436 |
+
#stringify_directive(params) {
|
| 437 |
+
const { directive, name, expression, modifiers } = params;
|
| 438 |
+
const is_shorthand = expression?.type === "Identifier" && expression.name === name;
|
| 439 |
+
let results = this.#stringify_directive_name(directive, name);
|
| 440 |
+
if (modifiers) results += this.#stringify_directive_modifiers(modifiers);
|
| 441 |
+
if (!is_shorthand && expression) {
|
| 442 |
+
results += "=";
|
| 443 |
+
results += "{";
|
| 444 |
+
results += print_es(expression).code;
|
| 445 |
+
results += "}";
|
| 446 |
+
}
|
| 447 |
+
return results;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
/**
|
| 451 |
+
* @param {true | SvelteAST.ExpressionTag | (SvelteAST.Text | SvelteAST.ExpressionTag)[]} node
|
| 452 |
+
* @param {string} name
|
| 453 |
+
* @returns {boolean}
|
| 454 |
+
*/
|
| 455 |
+
#is_attribute_shorthand_expression_tag(node, name) {
|
| 456 |
+
if (node === true) return false;
|
| 457 |
+
if (Array.isArray(node)) {
|
| 458 |
+
if (!node[0]) return false;
|
| 459 |
+
if (node[0].type === "Text") return node[0].raw === name;
|
| 460 |
+
const { expression } = node[0];
|
| 461 |
+
return expression.type === "Identifier" && expression.name === name;
|
| 462 |
+
}
|
| 463 |
+
const { expression } = node;
|
| 464 |
+
return expression.type === "Identifier" && expression.name === name;
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
/**
|
| 468 |
+
* @returns {boolean}
|
| 469 |
+
*/
|
| 470 |
+
get #is_last_output_closing_block() {
|
| 471 |
+
return /\{\/\w*\}$$/.test(this.#output);
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
/**
|
| 475 |
+
* @returns {boolean}
|
| 476 |
+
*/
|
| 477 |
+
get #is_last_output_opening_element_like() {
|
| 478 |
+
return /<(?!\/).*>$/s.test(this.#output);
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
/**
|
| 482 |
+
* @returns {boolean}
|
| 483 |
+
*/
|
| 484 |
+
get #is_last_output_closing_element_like() {
|
| 485 |
+
return /(<\/[^>:]+(:[^>]+)?>|\/>)$/.test(this.#output);
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
/**
|
| 489 |
+
* @returns {boolean}
|
| 490 |
+
*/
|
| 491 |
+
get #is_last_output_closing_comment() {
|
| 492 |
+
return /-->$/.test(this.#output);
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
/**
|
| 496 |
+
* @returns {boolean}
|
| 497 |
+
*/
|
| 498 |
+
get #is_last_output_new_line() {
|
| 499 |
+
return /\n$/.test(this.#output);
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
/**
|
| 503 |
+
* @returns {boolean}
|
| 504 |
+
*/
|
| 505 |
+
get #is_last_output_script_closing_tag() {
|
| 506 |
+
return /<\/script>$/.test(this.#output);
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
/**
|
| 510 |
+
* @returns {void}
|
| 511 |
+
*/
|
| 512 |
+
#produce() {
|
| 513 |
+
walk(this.#node, this, {
|
| 514 |
+
_(_node, context) {
|
| 515 |
+
const { next, state } = context;
|
| 516 |
+
next(state);
|
| 517 |
+
},
|
| 518 |
+
|
| 519 |
+
Root(node, context) {
|
| 520 |
+
const { state, stop, visit } = context;
|
| 521 |
+
const { order } = state.#options;
|
| 522 |
+
for (const name of order) {
|
| 523 |
+
const root_node = node[name];
|
| 524 |
+
if (name === "options" && node.options) {
|
| 525 |
+
// @ts-ignore FIXME: This is likely a bug - at runtime Svelte AST node `SvelteOptions` _(aliased as SvelteOptionsRaw)_ doesn't have 'type' & 'name' entry
|
| 526 |
+
visit({ ...node.options, type: "SvelteOptions", name: "svelte:options" }, state);
|
| 527 |
+
// @ts-ignore FIXME: Typing issue `SvelteOptions` and `SvelteOptionsRaw` are incompatible
|
| 528 |
+
} else if (root_node) visit(root_node, state);
|
| 529 |
+
}
|
| 530 |
+
// NOTE: There can't be anything next to Root
|
| 531 |
+
stop();
|
| 532 |
+
},
|
| 533 |
+
|
| 534 |
+
Script(/** @type {SvelteAST.Script} */ node, context) {
|
| 535 |
+
const { attributes, content } = node;
|
| 536 |
+
const { state, visit } = context;
|
| 537 |
+
state.#print_opening_new_line();
|
| 538 |
+
for (const attribute of attributes) {
|
| 539 |
+
visit(attribute, state);
|
| 540 |
+
}
|
| 541 |
+
state.#print_element_like_opening_tag("script");
|
| 542 |
+
state.#print_new_line();
|
| 543 |
+
state.#depth++;
|
| 544 |
+
state.#print_es_node(content);
|
| 545 |
+
state.#depth--;
|
| 546 |
+
state.#print_new_line();
|
| 547 |
+
state.#print_element_like_closing_tag("script");
|
| 548 |
+
},
|
| 549 |
+
|
| 550 |
+
Fragment(node, context) {
|
| 551 |
+
const { nodes } = node;
|
| 552 |
+
const { state, visit } = context;
|
| 553 |
+
for (const node of nodes) {
|
| 554 |
+
visit(node, state);
|
| 555 |
+
}
|
| 556 |
+
},
|
| 557 |
+
|
| 558 |
+
/**
|
| 559 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Comment}
|
| 560 |
+
*
|
| 561 |
+
* @example pattern
|
| 562 |
+
* ```html
|
| 563 |
+
* <!--data-->
|
| 564 |
+
* ```
|
| 565 |
+
*/
|
| 566 |
+
Comment(node, context) {
|
| 567 |
+
const { data } = node;
|
| 568 |
+
const { state } = context;
|
| 569 |
+
if (state.#is_last_output_script_closing_tag) {
|
| 570 |
+
state.#print_new_line();
|
| 571 |
+
state.#print_new_line();
|
| 572 |
+
} else if (
|
| 573 |
+
state.#is_last_output_closing_block ||
|
| 574 |
+
state.#is_last_output_closing_comment ||
|
| 575 |
+
state.#is_last_output_closing_element_like
|
| 576 |
+
) {
|
| 577 |
+
state.#print_new_line();
|
| 578 |
+
}
|
| 579 |
+
if (state.#is_last_output_new_line) state.#print_indent();
|
| 580 |
+
state.#print("<!--");
|
| 581 |
+
state.#print(data);
|
| 582 |
+
state.#print("-->");
|
| 583 |
+
},
|
| 584 |
+
|
| 585 |
+
Text(node, context) {
|
| 586 |
+
const { raw } = node;
|
| 587 |
+
const { state } = context;
|
| 588 |
+
if (state.#is_text_new_line_or_indents_only(node)) {
|
| 589 |
+
state.#was_last_text_indent_or_space_only = true;
|
| 590 |
+
} else {
|
| 591 |
+
state.#was_last_text_indent_or_space_only = false;
|
| 592 |
+
state.#print(raw);
|
| 593 |
+
}
|
| 594 |
+
},
|
| 595 |
+
|
| 596 |
+
Attribute(node, context) {
|
| 597 |
+
const { name, value } = node;
|
| 598 |
+
const { state } = context;
|
| 599 |
+
const is_shorthand_expression_tag = state.#is_attribute_shorthand_expression_tag(value, name);
|
| 600 |
+
let stringified = "";
|
| 601 |
+
if (!is_shorthand_expression_tag) stringified += name;
|
| 602 |
+
if (value !== true && Array.isArray(value)) {
|
| 603 |
+
if (!is_shorthand_expression_tag) stringified += "=";
|
| 604 |
+
const is_single_expression_tag = value.length === 1 && value[0].type === "ExpressionTag";
|
| 605 |
+
if (!is_single_expression_tag) stringified += '"';
|
| 606 |
+
for (const text_or_expression_tag of value) {
|
| 607 |
+
if (text_or_expression_tag.type === "Text") stringified += text_or_expression_tag.raw;
|
| 608 |
+
else stringified += state.#serialize_expression_tag(text_or_expression_tag);
|
| 609 |
+
}
|
| 610 |
+
if (!is_single_expression_tag) stringified += '"';
|
| 611 |
+
}
|
| 612 |
+
// NOTE: This is e.g. `<button disabled />`,
|
| 613 |
+
// so its a shorthand - we don't need to append anything
|
| 614 |
+
if (value !== true && !Array.isArray(value) && value.type === "ExpressionTag") {
|
| 615 |
+
if (!is_shorthand_expression_tag) stringified += "=";
|
| 616 |
+
stringified += state.#serialize_expression_tag(value);
|
| 617 |
+
}
|
| 618 |
+
state.#attributes.add(stringified);
|
| 619 |
+
},
|
| 620 |
+
|
| 621 |
+
/**
|
| 622 |
+
* @see {@link https://svelte.dev/docs/basic-markup#attributes-and-props}
|
| 623 |
+
*
|
| 624 |
+
* @example
|
| 625 |
+
* ```svelte
|
| 626 |
+
* <Widget {...things} />
|
| 627 |
+
* ```
|
| 628 |
+
*/
|
| 629 |
+
SpreadAttribute(node, context) {
|
| 630 |
+
const { expression } = node;
|
| 631 |
+
const { state } = context;
|
| 632 |
+
let stringified = "{";
|
| 633 |
+
stringified += "...";
|
| 634 |
+
stringified += print_es(expression).code;
|
| 635 |
+
stringified += "}";
|
| 636 |
+
state.#attributes.add(stringified);
|
| 637 |
+
},
|
| 638 |
+
|
| 639 |
+
/**
|
| 640 |
+
* @see {@link https://svelte.dev/docs/element-directives#animate-fn}
|
| 641 |
+
*
|
| 642 |
+
* @example with expression
|
| 643 |
+
* ```svelte
|
| 644 |
+
* animate:name={expression}
|
| 645 |
+
* ```
|
| 646 |
+
*
|
| 647 |
+
* @example shorthand - when variable - expression as identifier - name is same
|
| 648 |
+
* ```svelte
|
| 649 |
+
* animate:name
|
| 650 |
+
* ```
|
| 651 |
+
*/
|
| 652 |
+
AnimateDirective(node, context) {
|
| 653 |
+
const { name, expression } = node;
|
| 654 |
+
const { state } = context;
|
| 655 |
+
const stringified = state.#stringify_directive({ directive: "animate", name, expression });
|
| 656 |
+
state.#attributes.add(stringified);
|
| 657 |
+
},
|
| 658 |
+
|
| 659 |
+
/**
|
| 660 |
+
* @see {@link https://svelte.dev/docs/element-directives#bind-property}
|
| 661 |
+
*
|
| 662 |
+
* @example with expression
|
| 663 |
+
* ```svelte
|
| 664 |
+
* bind:name={variable}
|
| 665 |
+
* ```
|
| 666 |
+
*
|
| 667 |
+
* @example shorthand - when variable - expression as identifier - name is same
|
| 668 |
+
* ```svelte
|
| 669 |
+
* bind:name
|
| 670 |
+
* ```
|
| 671 |
+
*/
|
| 672 |
+
BindDirective(node, context) {
|
| 673 |
+
const { name, expression } = node;
|
| 674 |
+
const { state } = context;
|
| 675 |
+
const stringified = state.#stringify_directive({ directive: "bind", name, expression });
|
| 676 |
+
state.#attributes.add(stringified);
|
| 677 |
+
},
|
| 678 |
+
|
| 679 |
+
/**
|
| 680 |
+
* @see {@link https://svelte.dev/docs/element-directives#class-name}
|
| 681 |
+
*
|
| 682 |
+
* @example with expression
|
| 683 |
+
* ```svelte
|
| 684 |
+
* class:name={expression}
|
| 685 |
+
* ```
|
| 686 |
+
*
|
| 687 |
+
* @example shorthand - when variable - expression as identifier - name is same
|
| 688 |
+
* ```svelte
|
| 689 |
+
* class:name
|
| 690 |
+
* ```
|
| 691 |
+
*/
|
| 692 |
+
ClassDirective(node, context) {
|
| 693 |
+
const { name, expression } = node;
|
| 694 |
+
const { state } = context;
|
| 695 |
+
const stringified = state.#stringify_directive({ directive: "class", name, expression });
|
| 696 |
+
state.#attributes.add(stringified);
|
| 697 |
+
},
|
| 698 |
+
|
| 699 |
+
/**
|
| 700 |
+
* @see {@link https://svelte.dev/docs/special-elements#slot-slot-key-value}
|
| 701 |
+
*
|
| 702 |
+
* @example with expression
|
| 703 |
+
* ```svelte
|
| 704 |
+
* let:name={expression}
|
| 705 |
+
* ```
|
| 706 |
+
*
|
| 707 |
+
* @example shorthand - when variable - expression as identifier - name is same
|
| 708 |
+
* ```svelte
|
| 709 |
+
* let:name
|
| 710 |
+
* ```
|
| 711 |
+
*/
|
| 712 |
+
LetDirective(node, context) {
|
| 713 |
+
const { name, expression } = node;
|
| 714 |
+
const { state } = context;
|
| 715 |
+
const stringified = state.#stringify_directive({ directive: "let", name, expression });
|
| 716 |
+
state.#attributes.add(stringified);
|
| 717 |
+
},
|
| 718 |
+
|
| 719 |
+
/**
|
| 720 |
+
* @see {@link https://svelte.dev/docs/special-elements#on-eventname}
|
| 721 |
+
*
|
| 722 |
+
* @example without modifiers
|
| 723 |
+
* ```svelte
|
| 724 |
+
* on:name={expression}
|
| 725 |
+
* ```
|
| 726 |
+
*
|
| 727 |
+
* @example with modifiers
|
| 728 |
+
* ```svelte
|
| 729 |
+
* on:name|modifiers={handler}
|
| 730 |
+
* ```
|
| 731 |
+
*/
|
| 732 |
+
OnDirective(node, context) {
|
| 733 |
+
const { name, expression, modifiers } = node;
|
| 734 |
+
const { state } = context;
|
| 735 |
+
const stringified = state.#stringify_directive({ directive: "on", name, expression, modifiers });
|
| 736 |
+
state.#attributes.add(stringified);
|
| 737 |
+
},
|
| 738 |
+
|
| 739 |
+
/**
|
| 740 |
+
* @see {@link https://svelte.dev/docs/element-directives#style-property}
|
| 741 |
+
*
|
| 742 |
+
* @example with expression tag
|
| 743 |
+
* ```svelte
|
| 744 |
+
* style:name={value}
|
| 745 |
+
* ```
|
| 746 |
+
*
|
| 747 |
+
* @example with text expression
|
| 748 |
+
* ```svelte
|
| 749 |
+
* style:name="text"
|
| 750 |
+
* ```
|
| 751 |
+
*
|
| 752 |
+
* @example without expression
|
| 753 |
+
* ```svelte
|
| 754 |
+
* style:name
|
| 755 |
+
* ```
|
| 756 |
+
*
|
| 757 |
+
* @example with modifiers
|
| 758 |
+
* ```svelte
|
| 759 |
+
* style:name|modifiers="text"
|
| 760 |
+
*/
|
| 761 |
+
StyleDirective(node, context) {
|
| 762 |
+
const { name, modifiers, value } = node;
|
| 763 |
+
const { state } = context;
|
| 764 |
+
let stringified = state.#stringify_directive_name("style", name);
|
| 765 |
+
stringified += state.#stringify_directive_modifiers(modifiers);
|
| 766 |
+
if (value.type === "ExpressionTag") {
|
| 767 |
+
stringified += "=";
|
| 768 |
+
stringified += state.#serialize_attribute_like_text_or_expression_tag(value);
|
| 769 |
+
}
|
| 770 |
+
if (Array.isArray(value) && (value[0].type === "ExpressionTag" || value[0]?.type === "Text")) {
|
| 771 |
+
stringified += "=";
|
| 772 |
+
stringified += state.#serialize_attribute_like_text_or_expression_tag(value[0]);
|
| 773 |
+
}
|
| 774 |
+
state.#attributes.add(stringified);
|
| 775 |
+
},
|
| 776 |
+
|
| 777 |
+
/**
|
| 778 |
+
* @see {@link https://svelte.dev/docs/element-directives#transition-fn}
|
| 779 |
+
* @see {@link https://svelte.dev/docs/element-directives#in-fn-out-fn}
|
| 780 |
+
*
|
| 781 |
+
* @example without expression
|
| 782 |
+
* ```svelte
|
| 783 |
+
* transition|in|out:name
|
| 784 |
+
* ```
|
| 785 |
+
*
|
| 786 |
+
* @example with expression
|
| 787 |
+
* ```svelte
|
| 788 |
+
* transition|in|out:name={expression}
|
| 789 |
+
* ```
|
| 790 |
+
*
|
| 791 |
+
* @example with global modifier and without expression
|
| 792 |
+
* ```svelte
|
| 793 |
+
* transition|in|out:name|global
|
| 794 |
+
* ```
|
| 795 |
+
*
|
| 796 |
+
* @example with global modifier and with expression
|
| 797 |
+
* ```svelte
|
| 798 |
+
* transition|in|out:name|global={expression}
|
| 799 |
+
* ```
|
| 800 |
+
*
|
| 801 |
+
* @example with local modifier and without expression
|
| 802 |
+
* ```svelte
|
| 803 |
+
* transition|in|out:name|local
|
| 804 |
+
* ```
|
| 805 |
+
*
|
| 806 |
+
* @example with local modifier and with expression
|
| 807 |
+
* ```svelte
|
| 808 |
+
* transition|in|out:name|local={expression}
|
| 809 |
+
* ```
|
| 810 |
+
*/
|
| 811 |
+
TransitionDirective(node, context) {
|
| 812 |
+
const { expression, intro, modifiers, name, outro } = node;
|
| 813 |
+
const { state } = context;
|
| 814 |
+
/** @type {"in" | "out" | "transition"} */
|
| 815 |
+
let directive;
|
| 816 |
+
if (intro && !outro) directive = "in";
|
| 817 |
+
else if (!intro && outro) directive = "out";
|
| 818 |
+
else directive = "transition";
|
| 819 |
+
const stringified = state.#stringify_directive({ directive, name, expression, modifiers });
|
| 820 |
+
state.#attributes.add(stringified);
|
| 821 |
+
},
|
| 822 |
+
|
| 823 |
+
/**
|
| 824 |
+
* @see {@link https://svelte.dev/docs/element-directives#use-action}
|
| 825 |
+
*
|
| 826 |
+
* @example with expression
|
| 827 |
+
* ```svelte
|
| 828 |
+
* use:name={expression}
|
| 829 |
+
* ```
|
| 830 |
+
*
|
| 831 |
+
* @example shorthand - when variable - expression as identifier - name is same
|
| 832 |
+
* ```svelte
|
| 833 |
+
* use:name
|
| 834 |
+
* ```
|
| 835 |
+
*/
|
| 836 |
+
UseDirective(node, context) {
|
| 837 |
+
const { expression, name } = node;
|
| 838 |
+
const { state } = context;
|
| 839 |
+
const stringified = state.#stringify_directive({ directive: "use", name, expression });
|
| 840 |
+
state.#attributes.add(stringified);
|
| 841 |
+
},
|
| 842 |
+
|
| 843 |
+
/**
|
| 844 |
+
* @see {@link https://svelte.dev/docs/logic-blocks#await}
|
| 845 |
+
*
|
| 846 |
+
* @example standard
|
| 847 |
+
* ```svelte
|
| 848 |
+
* {#await expression}...{:then name}...{:catch name}...{/await}
|
| 849 |
+
* ```
|
| 850 |
+
*
|
| 851 |
+
* @example without catch
|
| 852 |
+
* ```svelte
|
| 853 |
+
* {#if expression}...{:else if expression}...{/if}
|
| 854 |
+
* ```
|
| 855 |
+
*
|
| 856 |
+
* @example without pending body
|
| 857 |
+
* ```svelte
|
| 858 |
+
* {#await expression then name}...{/await}
|
| 859 |
+
* ```
|
| 860 |
+
*
|
| 861 |
+
* @example with catch body only
|
| 862 |
+
* ```svelte
|
| 863 |
+
* {#await expression catch name}...{/await}
|
| 864 |
+
* ```
|
| 865 |
+
*/
|
| 866 |
+
AwaitBlock(node, context) {
|
| 867 |
+
const name = "await";
|
| 868 |
+
const { catch: catch_, error, expression, pending, then, value } = node;
|
| 869 |
+
const { state } = context;
|
| 870 |
+
let await_block_content = print_es(expression).code;
|
| 871 |
+
if (then && !pending) {
|
| 872 |
+
await_block_content += " then";
|
| 873 |
+
if (value) {
|
| 874 |
+
await_block_content += " ";
|
| 875 |
+
await_block_content += print_es(value).code;
|
| 876 |
+
}
|
| 877 |
+
}
|
| 878 |
+
if (catch_ && !pending) {
|
| 879 |
+
await_block_content += " catch";
|
| 880 |
+
if (error) {
|
| 881 |
+
await_block_content += " ";
|
| 882 |
+
await_block_content += print_es(error).code;
|
| 883 |
+
}
|
| 884 |
+
}
|
| 885 |
+
state.#print_block_opening_tag(name, await_block_content);
|
| 886 |
+
if (pending) {
|
| 887 |
+
state.#print_block_fragment(pending, context);
|
| 888 |
+
}
|
| 889 |
+
if (then) {
|
| 890 |
+
if (pending) {
|
| 891 |
+
const then_block_content = value ? print_es(value).code : undefined;
|
| 892 |
+
state.#print_block_middle_tag("then", then_block_content);
|
| 893 |
+
}
|
| 894 |
+
state.#print_block_fragment(then, context);
|
| 895 |
+
}
|
| 896 |
+
if (catch_) {
|
| 897 |
+
if (pending) {
|
| 898 |
+
const catch_block_content = error ? print_es(error).code : undefined;
|
| 899 |
+
state.#print_block_middle_tag("catch", catch_block_content);
|
| 900 |
+
}
|
| 901 |
+
state.#print_block_fragment(catch_, context);
|
| 902 |
+
}
|
| 903 |
+
state.#print_block_closing_tag(name);
|
| 904 |
+
},
|
| 905 |
+
|
| 906 |
+
/**
|
| 907 |
+
* @see {@link https://svelte.dev/docs/logic-blocks#each}
|
| 908 |
+
*
|
| 909 |
+
* @example simple
|
| 910 |
+
* ```svelte
|
| 911 |
+
* {#each expression as name}...{/each}
|
| 912 |
+
* ```
|
| 913 |
+
*
|
| 914 |
+
* @example with index
|
| 915 |
+
* ```svelte
|
| 916 |
+
* {#each expression as name, index}...{/each}
|
| 917 |
+
* ```
|
| 918 |
+
*
|
| 919 |
+
* @example keyed
|
| 920 |
+
* ```svelte
|
| 921 |
+
* {#each expression as name (key)}...{/each}
|
| 922 |
+
* ```
|
| 923 |
+
*
|
| 924 |
+
* @example with index and keyed
|
| 925 |
+
* ```svelte
|
| 926 |
+
* {#each expression as name, index (key)}...{/each}
|
| 927 |
+
* ```
|
| 928 |
+
*
|
| 929 |
+
* @example with else clause for when list is empty
|
| 930 |
+
* ```svelte
|
| 931 |
+
* {#each expression as name}...{:else}...{/each}
|
| 932 |
+
* ```
|
| 933 |
+
*/
|
| 934 |
+
EachBlock(node, context) {
|
| 935 |
+
const name = "each";
|
| 936 |
+
const { body, context: node_context, expression, fallback, index, key } = node;
|
| 937 |
+
const { state } = context;
|
| 938 |
+
let content = print_es(expression).code;
|
| 939 |
+
content += " as ";
|
| 940 |
+
content += print_es(node_context).code;
|
| 941 |
+
if (index) {
|
| 942 |
+
content += ",";
|
| 943 |
+
content += " ";
|
| 944 |
+
content += index;
|
| 945 |
+
}
|
| 946 |
+
if (key) {
|
| 947 |
+
content += " ";
|
| 948 |
+
content += "(";
|
| 949 |
+
content += print_es(key).code;
|
| 950 |
+
content += ")";
|
| 951 |
+
}
|
| 952 |
+
state.#print_block_opening_tag(name, content);
|
| 953 |
+
state.#print_block_fragment(body, context);
|
| 954 |
+
if (fallback) {
|
| 955 |
+
state.#print_block_middle_tag("else");
|
| 956 |
+
state.#print_block_fragment(fallback, context);
|
| 957 |
+
}
|
| 958 |
+
state.#print_block_closing_tag(name);
|
| 959 |
+
},
|
| 960 |
+
|
| 961 |
+
/**
|
| 962 |
+
* @see {@link https://svelte.dev/docs/logic-blocks#if}
|
| 963 |
+
*
|
| 964 |
+
* @example simple
|
| 965 |
+
* ```svelte
|
| 966 |
+
* {#if expression}...{/if}
|
| 967 |
+
* ```
|
| 968 |
+
*
|
| 969 |
+
* @example with else if
|
| 970 |
+
* ```svelte
|
| 971 |
+
* {#if expression}...{:else if expression}...{/if}
|
| 972 |
+
* ```
|
| 973 |
+
*
|
| 974 |
+
* @example with else
|
| 975 |
+
* ```svelte
|
| 976 |
+
* {#if expression}...{:else}...{/if}
|
| 977 |
+
* ```
|
| 978 |
+
*
|
| 979 |
+
* @example with else if and else
|
| 980 |
+
* ```svelte
|
| 981 |
+
* {#if expression}...{:else if expression}...{:else}...{/if}
|
| 982 |
+
* ```
|
| 983 |
+
*
|
| 984 |
+
* @example with multiple else if and else
|
| 985 |
+
* ```svelte
|
| 986 |
+
* {#if expression}...{:else if expression}...{:else if expression}...{:else}...{/if}
|
| 987 |
+
* ```
|
| 988 |
+
*/
|
| 989 |
+
IfBlock(node, context) {
|
| 990 |
+
const name = "if";
|
| 991 |
+
const { alternate, consequent, elseif, test } = node;
|
| 992 |
+
const { state } = context;
|
| 993 |
+
/** @param {SvelteAST.Fragment} node */
|
| 994 |
+
const has_alternate_else_if = (node) => node.nodes.some((n) => n.type === "IfBlock");
|
| 995 |
+
if (elseif) {
|
| 996 |
+
state.#depth--;
|
| 997 |
+
state.#print_block_middle_tag("else if", print_es(test).code);
|
| 998 |
+
// FIXME: Temporary workaround - needs refactor when working on formatting features
|
| 999 |
+
if (consequent.nodes.length === 1 && consequent.nodes[0].type === "Text") {
|
| 1000 |
+
consequent.nodes[0].raw = consequent.nodes[0].raw.replace(/\n/g, "");
|
| 1001 |
+
}
|
| 1002 |
+
state.#print_block_fragment(consequent, context);
|
| 1003 |
+
if (alternate) {
|
| 1004 |
+
if (!has_alternate_else_if(alternate)) {
|
| 1005 |
+
// FIXME: Temporary workaround - needs refactor when working on formatting features
|
| 1006 |
+
state.#print_new_line();
|
| 1007 |
+
state.#print_block_middle_tag("else");
|
| 1008 |
+
}
|
| 1009 |
+
// FIXME: Temporary workaround - needs refactor when working on formatting features
|
| 1010 |
+
if (alternate.nodes.length === 1 && alternate.nodes[0].type === "Text") {
|
| 1011 |
+
alternate.nodes[0].raw = alternate.nodes[0].raw.replace(/\n/g, "");
|
| 1012 |
+
}
|
| 1013 |
+
state.#print_block_fragment(alternate, context);
|
| 1014 |
+
}
|
| 1015 |
+
state.#depth++;
|
| 1016 |
+
} else {
|
| 1017 |
+
state.#print_block_opening_tag("if", print_es(test).code);
|
| 1018 |
+
// FIXME: Temporary workaround - needs refactor when working on formatting features
|
| 1019 |
+
if (consequent.nodes.length === 1 && consequent.nodes[0].type === "Text") {
|
| 1020 |
+
consequent.nodes[0].raw = consequent.nodes[0].raw.replace(/\n/g, "");
|
| 1021 |
+
}
|
| 1022 |
+
state.#print_block_fragment(consequent, context);
|
| 1023 |
+
if (alternate) {
|
| 1024 |
+
if (!has_alternate_else_if(alternate)) {
|
| 1025 |
+
state.#print_block_middle_tag("else");
|
| 1026 |
+
}
|
| 1027 |
+
if (alternate.nodes.length === 1 && alternate.nodes[0].type === "Text") {
|
| 1028 |
+
alternate.nodes[0].raw = alternate.nodes[0].raw.replace(/\n/g, "");
|
| 1029 |
+
}
|
| 1030 |
+
state.#print_block_fragment(alternate, context);
|
| 1031 |
+
}
|
| 1032 |
+
state.#print_block_closing_tag(name);
|
| 1033 |
+
}
|
| 1034 |
+
},
|
| 1035 |
+
|
| 1036 |
+
/**
|
| 1037 |
+
*
|
| 1038 |
+
* @see {@link https://svelte.dev/docs/logic-blocks#key}
|
| 1039 |
+
*
|
| 1040 |
+
* @example pattern
|
| 1041 |
+
* ```svelte
|
| 1042 |
+
* {#key expression}...{/key}
|
| 1043 |
+
* ```
|
| 1044 |
+
*/
|
| 1045 |
+
KeyBlock(node, context) {
|
| 1046 |
+
const name = "key";
|
| 1047 |
+
const { expression, fragment } = node;
|
| 1048 |
+
const { state } = context;
|
| 1049 |
+
state.#print_block_opening_tag(name, print_es(expression).code);
|
| 1050 |
+
state.#print_block_fragment(fragment, context);
|
| 1051 |
+
state.#print_block_closing_tag(name);
|
| 1052 |
+
},
|
| 1053 |
+
|
| 1054 |
+
/**
|
| 1055 |
+
*
|
| 1056 |
+
* TODO: Update link to the official doc once Svelte v5 is released
|
| 1057 |
+
* @see {@link https://svelte-5-preview.vercel.app/docs/snippets}
|
| 1058 |
+
*
|
| 1059 |
+
* @example pattern
|
| 1060 |
+
* ```svelte
|
| 1061 |
+
* {#snippet expression(parameters)}...{/snippet}
|
| 1062 |
+
* ```
|
| 1063 |
+
*/
|
| 1064 |
+
SnippetBlock(node, context) {
|
| 1065 |
+
const name = "snippet";
|
| 1066 |
+
const { body, expression, parameters } = node;
|
| 1067 |
+
const { state } = context;
|
| 1068 |
+
let content = print_es(expression).code;
|
| 1069 |
+
content += "(";
|
| 1070 |
+
content += parameters.map((pattern) => print_es(pattern).code).join(", ");
|
| 1071 |
+
content += ")";
|
| 1072 |
+
state.#print_block_opening_tag(name, content);
|
| 1073 |
+
state.#print_block_fragment(body, context);
|
| 1074 |
+
state.#print_block_closing_tag(name);
|
| 1075 |
+
},
|
| 1076 |
+
|
| 1077 |
+
/**
|
| 1078 |
+
* @see {@link https://svelte.dev/docs/svelte-components}
|
| 1079 |
+
*/
|
| 1080 |
+
Component(node, context) {
|
| 1081 |
+
const { state } = context;
|
| 1082 |
+
state.#print_element_like(node, context);
|
| 1083 |
+
},
|
| 1084 |
+
|
| 1085 |
+
/**
|
| 1086 |
+
* @see {@link https://svelte.dev/docs/svelte-components}
|
| 1087 |
+
*/
|
| 1088 |
+
RegularElement(node, context) {
|
| 1089 |
+
const { state } = context;
|
| 1090 |
+
state.#print_element_like(node, context);
|
| 1091 |
+
},
|
| 1092 |
+
|
| 1093 |
+
/**
|
| 1094 |
+
* @see {@link https://svelte.dev/docs/special-elements#slot}
|
| 1095 |
+
*/
|
| 1096 |
+
SlotElement(node, context) {
|
| 1097 |
+
const { state } = context;
|
| 1098 |
+
state.#print_element_like(node, context);
|
| 1099 |
+
},
|
| 1100 |
+
|
| 1101 |
+
/**
|
| 1102 |
+
*
|
| 1103 |
+
* @see {@link https://svelte.dev/docs/special-elements#svelte-body}
|
| 1104 |
+
*
|
| 1105 |
+
* @example
|
| 1106 |
+
* ```svelte
|
| 1107 |
+
* <svelte:body on:event={handler} />
|
| 1108 |
+
* ```
|
| 1109 |
+
*/
|
| 1110 |
+
SvelteBody(node, context) {
|
| 1111 |
+
const { state } = context;
|
| 1112 |
+
state.#print_element_like(node, context);
|
| 1113 |
+
},
|
| 1114 |
+
|
| 1115 |
+
/**
|
| 1116 |
+
*
|
| 1117 |
+
* @see {@link https://svelte.dev/docs/special-elements#svelte-component}
|
| 1118 |
+
*
|
| 1119 |
+
* @example
|
| 1120 |
+
* ```svelte
|
| 1121 |
+
* <svelte:component this={currentSelection.component} foo={bar} />
|
| 1122 |
+
* ```
|
| 1123 |
+
*/
|
| 1124 |
+
SvelteComponent(node, context) {
|
| 1125 |
+
const { state } = context;
|
| 1126 |
+
state.#print_element_like(node, context);
|
| 1127 |
+
},
|
| 1128 |
+
|
| 1129 |
+
/**
|
| 1130 |
+
* @see {@link https://svelte.dev/docs/special-elements#svelte-document}
|
| 1131 |
+
*
|
| 1132 |
+
* @example
|
| 1133 |
+
* ```svelte
|
| 1134 |
+
* <svelte:document bind:prop={value} on:visibilitychange={handleVisibilityChange} use:someAction />
|
| 1135 |
+
* ```
|
| 1136 |
+
*/
|
| 1137 |
+
SvelteDocument(node, context) {
|
| 1138 |
+
const { state } = context;
|
| 1139 |
+
state.#print_element_like(node, context);
|
| 1140 |
+
},
|
| 1141 |
+
|
| 1142 |
+
/**
|
| 1143 |
+
* @see {@link https://svelte.dev/docs/special-elements#svelte-element}
|
| 1144 |
+
*
|
| 1145 |
+
* @example
|
| 1146 |
+
* ```svelte
|
| 1147 |
+
* <svelte:element this={tag} on:click={handler}>Foo</svelte:element>
|
| 1148 |
+
* ```
|
| 1149 |
+
*/
|
| 1150 |
+
SvelteElement(node, context) {
|
| 1151 |
+
const { attributes, fragment, name, tag } = node;
|
| 1152 |
+
const { state, visit } = context;
|
| 1153 |
+
// WARN: Workaround to convert `this` into attribute
|
| 1154 |
+
visit(
|
| 1155 |
+
{
|
| 1156 |
+
type: "Attribute",
|
| 1157 |
+
name: "this",
|
| 1158 |
+
value: [
|
| 1159 |
+
{
|
| 1160 |
+
type: "ExpressionTag",
|
| 1161 |
+
expression: tag,
|
| 1162 |
+
},
|
| 1163 |
+
],
|
| 1164 |
+
},
|
| 1165 |
+
state,
|
| 1166 |
+
);
|
| 1167 |
+
for (const attribute_like of attributes) {
|
| 1168 |
+
visit(attribute_like, state);
|
| 1169 |
+
}
|
| 1170 |
+
const is_self_closing = state.#is_fragment_empty(fragment);
|
| 1171 |
+
state.#print_element_like_opening_tag(name, { self_close: is_self_closing });
|
| 1172 |
+
if (!is_self_closing && fragment) {
|
| 1173 |
+
state.#depth++;
|
| 1174 |
+
state.#print_element_like_fragment(fragment, context);
|
| 1175 |
+
state.#depth--;
|
| 1176 |
+
state.#print_element_like_closing_tag(name);
|
| 1177 |
+
}
|
| 1178 |
+
},
|
| 1179 |
+
|
| 1180 |
+
/**
|
| 1181 |
+
* @see {@link https://svelte.dev/docs/special-fragments#svelte-fragment}
|
| 1182 |
+
*
|
| 1183 |
+
* @example
|
| 1184 |
+
* ```svelte
|
| 1185 |
+
* <svelte:fragment slot="footer">
|
| 1186 |
+
* <p>All rights reserved.</p>
|
| 1187 |
+
* <p>Copyright (c) 2019 Svelte Industries</p>
|
| 1188 |
+
* </svelte:fragment>
|
| 1189 |
+
* ```
|
| 1190 |
+
*/
|
| 1191 |
+
SvelteFragment(node, context) {
|
| 1192 |
+
const { state } = context;
|
| 1193 |
+
state.#print_element_like(node, context);
|
| 1194 |
+
},
|
| 1195 |
+
|
| 1196 |
+
/**
|
| 1197 |
+
* @see {@link https://svelte.dev/docs/special-heads#svelte-head}
|
| 1198 |
+
*
|
| 1199 |
+
* @example
|
| 1200 |
+
* ```svelte
|
| 1201 |
+
* <svelte:head>
|
| 1202 |
+
* <title>Hello world!</title>
|
| 1203 |
+
* <meta name="description" content="This is where the description goes for SEO" />
|
| 1204 |
+
* </svelte:head>
|
| 1205 |
+
* ```
|
| 1206 |
+
*/
|
| 1207 |
+
SvelteHead(node, context) {
|
| 1208 |
+
const { state } = context;
|
| 1209 |
+
state.#print_element_like(node, context);
|
| 1210 |
+
},
|
| 1211 |
+
|
| 1212 |
+
/**
|
| 1213 |
+
* @see {@link https://svelte.dev/docs/special-optionss#svelte-options}
|
| 1214 |
+
*
|
| 1215 |
+
* @example
|
| 1216 |
+
* ```svelte
|
| 1217 |
+
* <svelte:options option={value} />
|
| 1218 |
+
* ```
|
| 1219 |
+
*
|
| 1220 |
+
* WARN: This one is different, because it can be extracted only from {@link SvelteAST.Root}
|
| 1221 |
+
*/
|
| 1222 |
+
SvelteOptions(node, context) {
|
| 1223 |
+
const { attributes, name } = node;
|
| 1224 |
+
const { state, visit } = context;
|
| 1225 |
+
for (const attribute_like of attributes) {
|
| 1226 |
+
visit(attribute_like, state);
|
| 1227 |
+
}
|
| 1228 |
+
state.#print_element_like_opening_tag(name, { self_close: true });
|
| 1229 |
+
},
|
| 1230 |
+
|
| 1231 |
+
/**
|
| 1232 |
+
*
|
| 1233 |
+
* @see {@link https://svelte.dev/docs/special-selfs#svelte-self}
|
| 1234 |
+
*
|
| 1235 |
+
* @example
|
| 1236 |
+
* ```svelte
|
| 1237 |
+
* <svelte:self count={count - 1} />
|
| 1238 |
+
* ```
|
| 1239 |
+
*/
|
| 1240 |
+
SvelteSelf(node, context) {
|
| 1241 |
+
const { state } = context;
|
| 1242 |
+
state.#print_element_like(node, context);
|
| 1243 |
+
},
|
| 1244 |
+
|
| 1245 |
+
/**
|
| 1246 |
+
*
|
| 1247 |
+
* @see {@link https://svelte.dev/docs/special-windows#svelte-window}
|
| 1248 |
+
*
|
| 1249 |
+
* @example
|
| 1250 |
+
* ```svelte
|
| 1251 |
+
* <svelte:window bind:prop={value} on:keydown={handleKeydown} />
|
| 1252 |
+
* ```
|
| 1253 |
+
*/
|
| 1254 |
+
SvelteWindow(node, context) {
|
| 1255 |
+
const { state } = context;
|
| 1256 |
+
state.#print_element_like(node, context);
|
| 1257 |
+
},
|
| 1258 |
+
|
| 1259 |
+
/**
|
| 1260 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title}
|
| 1261 |
+
*/
|
| 1262 |
+
TitleElement(node, context) {
|
| 1263 |
+
const { state } = context;
|
| 1264 |
+
state.#print_element_like(node, context);
|
| 1265 |
+
},
|
| 1266 |
+
|
| 1267 |
+
/**
|
| 1268 |
+
*
|
| 1269 |
+
* @see {@link https://svelte.dev/docs/special-tags#const}
|
| 1270 |
+
*
|
| 1271 |
+
* @example pattern
|
| 1272 |
+
* ```svelte
|
| 1273 |
+
* {@const assignment}
|
| 1274 |
+
* ```
|
| 1275 |
+
*/
|
| 1276 |
+
ConstTag(node, context) {
|
| 1277 |
+
const { declaration } = node;
|
| 1278 |
+
const { state } = context;
|
| 1279 |
+
state.#print("{@");
|
| 1280 |
+
// NOTE: This is unique, because we need to remove a semicolon at the end.
|
| 1281 |
+
state.#print(print_es(declaration).code.slice(0, -1));
|
| 1282 |
+
state.#print("}");
|
| 1283 |
+
},
|
| 1284 |
+
|
| 1285 |
+
/**
|
| 1286 |
+
*/
|
| 1287 |
+
DebugTag(node, context) {
|
| 1288 |
+
const { identifiers } = node;
|
| 1289 |
+
const { state } = context;
|
| 1290 |
+
state.#print("{@debug");
|
| 1291 |
+
identifiers.forEach((identifier, index) => {
|
| 1292 |
+
state.#print_space();
|
| 1293 |
+
state.#print_es_node(identifier);
|
| 1294 |
+
if (identifiers[index + 1]) {
|
| 1295 |
+
state.#print(",");
|
| 1296 |
+
state.#print_space();
|
| 1297 |
+
}
|
| 1298 |
+
});
|
| 1299 |
+
state.#print("}");
|
| 1300 |
+
},
|
| 1301 |
+
|
| 1302 |
+
/**
|
| 1303 |
+
* Print Svelte AST node {@link ExpressionTag} as string.
|
| 1304 |
+
*
|
| 1305 |
+
* @example expression - a possibly reactive template expression
|
| 1306 |
+
* ```svelte
|
| 1307 |
+
* {...}
|
| 1308 |
+
* ```
|
| 1309 |
+
*/
|
| 1310 |
+
ExpressionTag(node, context) {
|
| 1311 |
+
const { expression } = node;
|
| 1312 |
+
const { state } = context;
|
| 1313 |
+
state.#print("{");
|
| 1314 |
+
state.#print_es_node(expression, { skip_indent: true });
|
| 1315 |
+
state.#print("}");
|
| 1316 |
+
},
|
| 1317 |
+
|
| 1318 |
+
/**
|
| 1319 |
+
*/
|
| 1320 |
+
HtmlTag(node, context) {
|
| 1321 |
+
const { expression } = node;
|
| 1322 |
+
const { state } = context;
|
| 1323 |
+
state.#print("{@html");
|
| 1324 |
+
state.#print_space();
|
| 1325 |
+
state.#print_es_node(expression);
|
| 1326 |
+
state.#print("}");
|
| 1327 |
+
},
|
| 1328 |
+
|
| 1329 |
+
/**
|
| 1330 |
+
* Print Svelte AST node {@link RenderTag} as string.
|
| 1331 |
+
* TODO: Update link once Svelte v5 is released
|
| 1332 |
+
* @see {@link https://svelte.dev/docs/special-tags#html}
|
| 1333 |
+
*
|
| 1334 |
+
* @example pattern
|
| 1335 |
+
* ```svelte
|
| 1336 |
+
* {@render expression}
|
| 1337 |
+
* ```
|
| 1338 |
+
*/
|
| 1339 |
+
RenderTag(node, context) {
|
| 1340 |
+
const { expression } = node;
|
| 1341 |
+
const { state } = context;
|
| 1342 |
+
state.#print("{@render");
|
| 1343 |
+
state.#print_space();
|
| 1344 |
+
state.#print_es_node(expression);
|
| 1345 |
+
state.#print("}");
|
| 1346 |
+
},
|
| 1347 |
+
|
| 1348 |
+
/**
|
| 1349 |
+
* @see {@link https://svelte.dev/docs/svelte-components#style}
|
| 1350 |
+
*/
|
| 1351 |
+
StyleSheet(node, context) {
|
| 1352 |
+
const { attributes, children } = node;
|
| 1353 |
+
const { state, visit } = context;
|
| 1354 |
+
if (state.#is_last_output_closing_element_like) {
|
| 1355 |
+
state.#print_new_line();
|
| 1356 |
+
state.#print_new_line();
|
| 1357 |
+
}
|
| 1358 |
+
for (const attribute of attributes) {
|
| 1359 |
+
visit(attribute, state);
|
| 1360 |
+
}
|
| 1361 |
+
state.#print_element_like_opening_tag("style");
|
| 1362 |
+
state.#print_new_line();
|
| 1363 |
+
state.#depth++;
|
| 1364 |
+
children.forEach((child, index) => {
|
| 1365 |
+
if (index > 0) state.#print_new_line();
|
| 1366 |
+
state.#print_indent();
|
| 1367 |
+
visit(child, state);
|
| 1368 |
+
if (children[index + 1]) state.#print_new_line();
|
| 1369 |
+
});
|
| 1370 |
+
state.#depth--;
|
| 1371 |
+
state.#print_new_line();
|
| 1372 |
+
state.#print_element_like_closing_tag("style");
|
| 1373 |
+
},
|
| 1374 |
+
|
| 1375 |
+
Atrule(node, context) {
|
| 1376 |
+
const { block, name, prelude } = node;
|
| 1377 |
+
const { state, visit } = context;
|
| 1378 |
+
state.#print("@");
|
| 1379 |
+
state.#print(name);
|
| 1380 |
+
state.#print_space();
|
| 1381 |
+
state.#print(prelude);
|
| 1382 |
+
if (block) {
|
| 1383 |
+
state.#print_space();
|
| 1384 |
+
visit(block, state);
|
| 1385 |
+
}
|
| 1386 |
+
},
|
| 1387 |
+
|
| 1388 |
+
/**
|
| 1389 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors}
|
| 1390 |
+
*
|
| 1391 |
+
* @example syntax
|
| 1392 |
+
* ```css
|
| 1393 |
+
* [name<?matcher><?"value"> flags?]
|
| 1394 |
+
* ```
|
| 1395 |
+
*/
|
| 1396 |
+
AttributeSelector(node, context) {
|
| 1397 |
+
const { flags, matcher, name, value } = node;
|
| 1398 |
+
const { state } = context;
|
| 1399 |
+
state.#print("[");
|
| 1400 |
+
state.#print(name);
|
| 1401 |
+
if (matcher) state.#print(matcher);
|
| 1402 |
+
if (value) {
|
| 1403 |
+
state.#print('"');
|
| 1404 |
+
state.#print(value);
|
| 1405 |
+
state.#print('"');
|
| 1406 |
+
}
|
| 1407 |
+
if (flags) {
|
| 1408 |
+
state.#print_space();
|
| 1409 |
+
state.#print(flags);
|
| 1410 |
+
}
|
| 1411 |
+
state.#print("]");
|
| 1412 |
+
},
|
| 1413 |
+
|
| 1414 |
+
Block(node, context) {
|
| 1415 |
+
const { children } = node;
|
| 1416 |
+
const { state, visit } = context;
|
| 1417 |
+
state.#print("{");
|
| 1418 |
+
state.#print_new_line();
|
| 1419 |
+
state.#depth++;
|
| 1420 |
+
for (const child of children) {
|
| 1421 |
+
state.#print_indent();
|
| 1422 |
+
visit(child, state);
|
| 1423 |
+
state.#print_new_line();
|
| 1424 |
+
}
|
| 1425 |
+
state.#depth--;
|
| 1426 |
+
state.#print_indent();
|
| 1427 |
+
state.#print("}");
|
| 1428 |
+
},
|
| 1429 |
+
|
| 1430 |
+
/**
|
| 1431 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors}
|
| 1432 |
+
*
|
| 1433 |
+
* @example simple
|
| 1434 |
+
* ```css
|
| 1435 |
+
* .class_name { style properties }
|
| 1436 |
+
* ```
|
| 1437 |
+
*
|
| 1438 |
+
* @example equivalent
|
| 1439 |
+
* ```css
|
| 1440 |
+
* [class~=class_name] { style properties }
|
| 1441 |
+
* ```
|
| 1442 |
+
*/
|
| 1443 |
+
ClassSelector(node, context) {
|
| 1444 |
+
const { name } = node;
|
| 1445 |
+
const { state } = context;
|
| 1446 |
+
state.#print(".");
|
| 1447 |
+
state.#print(name);
|
| 1448 |
+
},
|
| 1449 |
+
|
| 1450 |
+
/**
|
| 1451 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors/Selectors_and_combinators#combinators}
|
| 1452 |
+
*/
|
| 1453 |
+
Combinator(node, context) {
|
| 1454 |
+
const { name } = node;
|
| 1455 |
+
const { state } = context;
|
| 1456 |
+
state.#print(name);
|
| 1457 |
+
},
|
| 1458 |
+
|
| 1459 |
+
ComplexSelector(node, context) {
|
| 1460 |
+
const { children } = node;
|
| 1461 |
+
const { state, visit } = context;
|
| 1462 |
+
for (const relative_selector of children) {
|
| 1463 |
+
visit(relative_selector, state);
|
| 1464 |
+
}
|
| 1465 |
+
},
|
| 1466 |
+
|
| 1467 |
+
/**
|
| 1468 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/CSS_Declaration}
|
| 1469 |
+
*/
|
| 1470 |
+
Declaration(node, context) {
|
| 1471 |
+
const { property, value } = node;
|
| 1472 |
+
const { state } = context;
|
| 1473 |
+
state.#print(property);
|
| 1474 |
+
state.#print(":");
|
| 1475 |
+
state.#print_space();
|
| 1476 |
+
// NOTE: It removes any existing indentation, because output will look uglier
|
| 1477 |
+
state.#print(value.split(/[\s\t\n]+/).join(" "));
|
| 1478 |
+
state.#print(";");
|
| 1479 |
+
},
|
| 1480 |
+
|
| 1481 |
+
/**
|
| 1482 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors}
|
| 1483 |
+
*
|
| 1484 |
+
* @example pattern
|
| 1485 |
+
* ```css
|
| 1486 |
+
* #name
|
| 1487 |
+
* ```
|
| 1488 |
+
*/
|
| 1489 |
+
IdSelector(node, context) {
|
| 1490 |
+
const { name } = node;
|
| 1491 |
+
const { state } = context;
|
| 1492 |
+
state.#print("#");
|
| 1493 |
+
state.#print(name);
|
| 1494 |
+
},
|
| 1495 |
+
|
| 1496 |
+
NestingSelector(node, context) {
|
| 1497 |
+
const { name } = node;
|
| 1498 |
+
const { state } = context;
|
| 1499 |
+
state.#print(name);
|
| 1500 |
+
},
|
| 1501 |
+
|
| 1502 |
+
/**
|
| 1503 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child}
|
| 1504 |
+
*
|
| 1505 |
+
* @example pattern
|
| 1506 |
+
* ```css
|
| 1507 |
+
* :nth-child(<nth> [of <complex-selector-list>]?) { }
|
| 1508 |
+
*/
|
| 1509 |
+
Nth(node, context) {
|
| 1510 |
+
const { value } = node;
|
| 1511 |
+
const { state } = context;
|
| 1512 |
+
state.#print(":nth-child(");
|
| 1513 |
+
state.#print(value);
|
| 1514 |
+
state.#print(")");
|
| 1515 |
+
},
|
| 1516 |
+
|
| 1517 |
+
Percentage(node, context) {
|
| 1518 |
+
const { value } = node;
|
| 1519 |
+
const { state } = context;
|
| 1520 |
+
state.#print(value);
|
| 1521 |
+
},
|
| 1522 |
+
|
| 1523 |
+
/**
|
| 1524 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes}
|
| 1525 |
+
*/
|
| 1526 |
+
PseudoClassSelector(node, context) {
|
| 1527 |
+
const { args, name } = node;
|
| 1528 |
+
const { state, visit } = context;
|
| 1529 |
+
state.#print(":");
|
| 1530 |
+
state.#print(name);
|
| 1531 |
+
if (args) {
|
| 1532 |
+
state.#print("(");
|
| 1533 |
+
visit(args, state);
|
| 1534 |
+
state.#print(")");
|
| 1535 |
+
}
|
| 1536 |
+
},
|
| 1537 |
+
|
| 1538 |
+
/**
|
| 1539 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements}
|
| 1540 |
+
* WARN: It doesn't support args, e.g. `::part()` or `::slotted()`
|
| 1541 |
+
*/
|
| 1542 |
+
PseudoElementSelector(node, context) {
|
| 1543 |
+
const { name } = node;
|
| 1544 |
+
const { state } = context;
|
| 1545 |
+
state.#print("::");
|
| 1546 |
+
state.#print(name);
|
| 1547 |
+
},
|
| 1548 |
+
|
| 1549 |
+
Rule(node, context) {
|
| 1550 |
+
const { block, prelude } = node;
|
| 1551 |
+
const { state, visit } = context;
|
| 1552 |
+
visit(prelude, state);
|
| 1553 |
+
state.#print_space();
|
| 1554 |
+
visit(block, state);
|
| 1555 |
+
},
|
| 1556 |
+
|
| 1557 |
+
RelativeSelector(node, context) {
|
| 1558 |
+
const { combinator, selectors } = node;
|
| 1559 |
+
const { state, visit } = context;
|
| 1560 |
+
if (combinator) {
|
| 1561 |
+
state.#print_space();
|
| 1562 |
+
visit(combinator, state);
|
| 1563 |
+
}
|
| 1564 |
+
for (const selector of selectors) {
|
| 1565 |
+
visit(selector, state);
|
| 1566 |
+
}
|
| 1567 |
+
},
|
| 1568 |
+
|
| 1569 |
+
SelectorList(node, context) {
|
| 1570 |
+
const { children } = node;
|
| 1571 |
+
const { state, visit } = context;
|
| 1572 |
+
for (const complex_selector of children) {
|
| 1573 |
+
visit(complex_selector, state);
|
| 1574 |
+
}
|
| 1575 |
+
},
|
| 1576 |
+
|
| 1577 |
+
/**
|
| 1578 |
+
* @see {@link https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors}
|
| 1579 |
+
*/
|
| 1580 |
+
TypeSelector(node, context) {
|
| 1581 |
+
const { name } = node;
|
| 1582 |
+
const { state } = context;
|
| 1583 |
+
state.#print(name);
|
| 1584 |
+
},
|
| 1585 |
+
});
|
| 1586 |
+
}
|
| 1587 |
+
}
|
tools/ui/node_modules/svelte-ast-print/src/nodes.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @import * as _reset from "@total-typescript/ts-reset";
|
| 3 |
+
* @import { Node as ESTreeNode } from "estree";
|
| 4 |
+
* @import { AST, Css, parse } from "svelte/compiler";
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L514
|
| 9 |
+
* FIXME: Include `Css.Node` when exposed to public
|
| 10 |
+
* @typedef {ESTreeNode | TemplateNode | AST.Fragment} SvelteNode
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L476
|
| 15 |
+
* @typedef {AST.AnimateDirective | AST.BindDirective | AST.ClassDirective | AST.LetDirective | AST.OnDirective | AST.SpreadAttribute | AST.StyleDirective | AST.TransitionDirective | AST.UseDirective} Directive
|
| 16 |
+
*/
|
| 17 |
+
|
| 18 |
+
/** @typedef {AST.Attribute | AST.SpreadAttribute | Directive} AttributeLike */
|
| 19 |
+
const ATTRIBUTE_LIKE_NODE_NAMES = new Set(
|
| 20 |
+
/** @type {const} */ ([
|
| 21 |
+
"AnimateDirective",
|
| 22 |
+
"Attribute",
|
| 23 |
+
"BindDirective",
|
| 24 |
+
"ClassDirective",
|
| 25 |
+
"LetDirective",
|
| 26 |
+
"OnDirective",
|
| 27 |
+
"SpreadAttribute",
|
| 28 |
+
"StyleDirective",
|
| 29 |
+
"TransitionDirective",
|
| 30 |
+
"UseDirective",
|
| 31 |
+
]),
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Type check guard to see if provided AST node is {@link AttributeLike}.
|
| 36 |
+
*
|
| 37 |
+
* - Standard attribute _({@link AST.Attribute})_ - {@link https://developer.mozilla.org/en-US/docs/Glossary/Attribute}
|
| 38 |
+
* - Spread attribute _({@link AST.SpreadAttribute})_ - {@link https://svelte.dev/docs/basic-markup#attributes-and-props}
|
| 39 |
+
* - Directive _({@link AST.Directive})_ - can be for:
|
| 40 |
+
* - component - {@link https://svelte.dev/docs/component-directives}
|
| 41 |
+
* - element - {@link https://svelte.dev/docs/element-directives}
|
| 42 |
+
*
|
| 43 |
+
* @param {SvelteNode} node - Supported AST node to narrow down its inferred type
|
| 44 |
+
* @returns {node is AttributeLike}
|
| 45 |
+
*/
|
| 46 |
+
export const is_attribute_like_node = (node) => ATTRIBUTE_LIKE_NODE_NAMES.has(node.type);
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L486
|
| 50 |
+
* @typedef {AST.EachBlock | AST.IfBlock | AST.AwaitBlock | AST.KeyBlock | AST.SnippetBlock} Block
|
| 51 |
+
*/
|
| 52 |
+
|
| 53 |
+
const BLOCK_NODE_NAMES = new Set(
|
| 54 |
+
/** @type {const} */ ([
|
| 55 |
+
//
|
| 56 |
+
"AwaitBlock",
|
| 57 |
+
"Block",
|
| 58 |
+
"EachBlock",
|
| 59 |
+
"IfBlock",
|
| 60 |
+
"KeyBlock",
|
| 61 |
+
"SnippetBlock",
|
| 62 |
+
]),
|
| 63 |
+
);
|
| 64 |
+
|
| 65 |
+
/**
|
| 66 |
+
* Type check guard to see if provided AST node is a logic block {@link Block}.
|
| 67 |
+
*
|
| 68 |
+
* @see {@link https://svelte.dev/docs/logic-blocks}
|
| 69 |
+
*
|
| 70 |
+
* NOTE: Svelte v5 includes a new block {@link AST.SnippetBlock}
|
| 71 |
+
* @see {@link https://svelte-5-preview.vercel.app/docs/snippets}
|
| 72 |
+
*
|
| 73 |
+
* @param {SvelteNode} node - Supported AST node to narrow down its inferred type
|
| 74 |
+
* @returns {node is Block}
|
| 75 |
+
*/
|
| 76 |
+
export const is_block_node = (node) => BLOCK_NODE_NAMES.has(node.type);
|
| 77 |
+
|
| 78 |
+
const CSS_AST_NODE_NAMES = new Set(
|
| 79 |
+
/** @type {const} */ ([
|
| 80 |
+
"Atrule",
|
| 81 |
+
"AttributeSelector",
|
| 82 |
+
"Block",
|
| 83 |
+
"ClassSelector",
|
| 84 |
+
"Combinator",
|
| 85 |
+
"ComplexSelector",
|
| 86 |
+
"Declaration",
|
| 87 |
+
"IdSelector",
|
| 88 |
+
"NestingSelector",
|
| 89 |
+
"Nth",
|
| 90 |
+
"Percentage",
|
| 91 |
+
"PseudoClassSelector",
|
| 92 |
+
"PseudoElementSelector",
|
| 93 |
+
"RelativeSelector",
|
| 94 |
+
"Rule",
|
| 95 |
+
"SelectorList",
|
| 96 |
+
"StyleSheet",
|
| 97 |
+
"TypeSelector",
|
| 98 |
+
]),
|
| 99 |
+
);
|
| 100 |
+
/**
|
| 101 |
+
* FIXME: `Css` is not exported
|
| 102 |
+
* Type check guard to see if provided AST node is a CSS based {@link Css.Node}.
|
| 103 |
+
*
|
| 104 |
+
* WARN: Good to know: they're not same _(complaint)_ with `css-tree`!
|
| 105 |
+
*
|
| 106 |
+
* @param {SvelteNode} node - Supported AST node to narrow down its inferred type
|
| 107 |
+
* @returns {node is AST.Css.Node}
|
| 108 |
+
*/
|
| 109 |
+
export const is_css_node = (node) => CSS_AST_NODE_NAMES.has(node.type);
|
| 110 |
+
|
| 111 |
+
/**
|
| 112 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L488
|
| 113 |
+
* @typedef {AST.Component | AST.TitleElement | AST.SlotElement | AST.RegularElement | AST.SvelteBody | AST.SvelteComponent | AST.SvelteDocument | AST.SvelteElement | AST.SvelteFragment | AST.SvelteHead | AST.SvelteOptionsRaw | AST.SvelteSelf | AST.SvelteWindow} ElementLike */
|
| 114 |
+
|
| 115 |
+
const ELEMENT_LIKE_NODE_NAMES = new Set(
|
| 116 |
+
/** @type {const} */ ([
|
| 117 |
+
"Component",
|
| 118 |
+
"RegularElement",
|
| 119 |
+
"SlotElement",
|
| 120 |
+
"SvelteBody",
|
| 121 |
+
"SvelteComponent",
|
| 122 |
+
"SvelteDocument",
|
| 123 |
+
"SvelteElement",
|
| 124 |
+
"SvelteFragment",
|
| 125 |
+
"SvelteHead",
|
| 126 |
+
"SvelteOptionsRaw",
|
| 127 |
+
"SvelteSelf",
|
| 128 |
+
"SvelteWindow",
|
| 129 |
+
"TitleElement",
|
| 130 |
+
]),
|
| 131 |
+
);
|
| 132 |
+
/**
|
| 133 |
+
* Type check guard to see if provided AST node is "element-like" {@link ElementLike}.
|
| 134 |
+
*
|
| 135 |
+
* Those are:
|
| 136 |
+
*
|
| 137 |
+
* - standard Svelte-based component - {@link AST.Component}
|
| 138 |
+
* - regular element _(HTML based)_ - {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element}
|
| 139 |
+
* - special Svelte elements - {@link https://svelte.dev/docs/special-elements}
|
| 140 |
+
*
|
| 141 |
+
* @param {SvelteNode} node - Supported AST node to narrow down its inferred type
|
| 142 |
+
* @returns {node is ElementLike}
|
| 143 |
+
*/
|
| 144 |
+
export const is_element_like_node = (node) => ELEMENT_LIKE_NODE_NAMES.has(node.type);
|
| 145 |
+
|
| 146 |
+
/** @typedef {AST.Comment | AST.Text} HtmlNode */
|
| 147 |
+
|
| 148 |
+
const HTML_NODE_NAMES = new Set(
|
| 149 |
+
/** @type {const} */ ([
|
| 150 |
+
//
|
| 151 |
+
"Comment",
|
| 152 |
+
"Text",
|
| 153 |
+
]),
|
| 154 |
+
);
|
| 155 |
+
/**
|
| 156 |
+
* Type check guard to see if provided AST node is standard HTML node {@link HtmlNode}.
|
| 157 |
+
*
|
| 158 |
+
* Those are:
|
| 159 |
+
*
|
| 160 |
+
* - text that is included between HTML tags - {@link AST.Text}
|
| 161 |
+
* - HTML comment - {@link AST.Comment}
|
| 162 |
+
*
|
| 163 |
+
* @param {SvelteNode} node
|
| 164 |
+
* @returns {node is HtmlNode}
|
| 165 |
+
*/
|
| 166 |
+
export const is_html_node = (node) => HTML_NODE_NAMES.has(node.type);
|
| 167 |
+
|
| 168 |
+
const TAG_NODE_NAMES = new Set(
|
| 169 |
+
/** @type {const} */ ([
|
| 170 |
+
//
|
| 171 |
+
"ExpressionTag",
|
| 172 |
+
"HtmlTag",
|
| 173 |
+
"ConstTag",
|
| 174 |
+
"DebugTag",
|
| 175 |
+
"RenderTag",
|
| 176 |
+
]),
|
| 177 |
+
);
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L474
|
| 181 |
+
* @typedef {AST.ExpressionTag | AST.HtmlTag | AST.ConstTag | AST.DebugTag | AST.RenderTag} Tag
|
| 182 |
+
*/
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* Type check guard to see if provided AST node is "tag-like" {@link Tag}.
|
| 186 |
+
*
|
| 187 |
+
* @see {@link https://svelte.dev/docs/special-tags}
|
| 188 |
+
*
|
| 189 |
+
* Not included in the documentation:
|
| 190 |
+
*
|
| 191 |
+
* - expression tag _({@link AST.ExpressionTag})_
|
| 192 |
+
* - render tag _({@link AST.RenderTag})_ - part of Svelte v5
|
| 193 |
+
*
|
| 194 |
+
* @param {SvelteNode} node - Supported AST node to narrow down its inferred type
|
| 195 |
+
* @returns {node is Tag}
|
| 196 |
+
*/
|
| 197 |
+
export const is_tag_node = (node) => TAG_NODE_NAMES.has(node.type);
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L503
|
| 201 |
+
* @typedef {AST.Root | AST.Text | Tag | ElementLike | AST.Attribute | AST.SpreadAttribute | Directive | AST.Comment | Block} TemplateNode
|
| 202 |
+
*/
|
| 203 |
+
|
| 204 |
+
/**
|
| 205 |
+
* Type check guard to see if provided AST node is part of node used for templating {@link TemplateNode}.
|
| 206 |
+
*
|
| 207 |
+
* Those are:
|
| 208 |
+
*
|
| 209 |
+
* - root - what you obtain from the results of from using {@link parse}
|
| 210 |
+
* - text that is included between HTML tags - {@link AST.Text}
|
| 211 |
+
* - HTML comment - {@link AST.Comment}
|
| 212 |
+
*
|
| 213 |
+
* @param {SvelteNode} node - Supported AST node to narrow down its inferred type
|
| 214 |
+
* @returns {node is TemplateNode}
|
| 215 |
+
*/
|
| 216 |
+
export const is_template_node = (node) =>
|
| 217 |
+
node.type === "Root" ||
|
| 218 |
+
node.type === "Fragment" ||
|
| 219 |
+
is_attribute_like_node(node) ||
|
| 220 |
+
is_block_node(node) ||
|
| 221 |
+
is_css_node(node) ||
|
| 222 |
+
is_element_like_node(node) ||
|
| 223 |
+
is_html_node(node) ||
|
| 224 |
+
is_tag_node(node);
|
| 225 |
+
|
| 226 |
+
// TODO: Ask Svelte maintainers if `Script` and `SvelteOptions` were omittted from `SvelteNode` intentionally
|
| 227 |
+
/**
|
| 228 |
+
* Not all of the nodes are bundled together with {@link AST.BaseNode}.
|
| 229 |
+
* This type wraps them together as supported ones for printing.
|
| 230 |
+
*
|
| 231 |
+
* @typedef {AST.Script | AST.BaseNode | AST.SvelteOptionsRaw | SvelteNode} SupportedSvelteNode
|
| 232 |
+
*/
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* Bundle together Svelte and ESTree specification complaint nodes, so we can support printing both.
|
| 236 |
+
*
|
| 237 |
+
* @typedef {ESTreeNode | SupportedSvelteNode} Node
|
| 238 |
+
*/
|
| 239 |
+
|
| 240 |
+
/**
|
| 241 |
+
* Type check guard to see if provided AST node is unique to Svelte AST only {@link SupportedSvelteNode}.
|
| 242 |
+
*
|
| 243 |
+
* @param {Node} node - ESTree or Svelte AST node
|
| 244 |
+
* @returns {node is SupportedSvelteNode}
|
| 245 |
+
*/
|
| 246 |
+
export const is_svelte_node = (node) =>
|
| 247 |
+
node.type === "SvelteOptions" || node.type === "Script" || is_template_node(node);
|
tools/ui/node_modules/svelte-ast-print/src/options.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* @import { Css, Fragment, Root, Script, SvelteOptionsRaw } from "svelte/compiler";
|
| 3 |
+
* @import { IterableElement, ReadonlyTuple } from "type-fest";
|
| 4 |
+
*
|
| 5 |
+
* @import { print } from "./mod.js";
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Options for {@link print} defined by user.
|
| 10 |
+
*
|
| 11 |
+
* @typedef PrintOptions
|
| 12 |
+
* @property {Partial<FormatOptions>} [format] - formatting options
|
| 13 |
+
* @property {Partial<RootOptions>} [root] - Svelte AST node {@link Root} based options
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* Name _(alias)_ for indentation type. This package will automatically determine a desired indent.
|
| 18 |
+
* @typedef {IterableElement<typeof Options.INDENT>[0]} IndentName
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @satisfies {IndentName}
|
| 23 |
+
*/
|
| 24 |
+
export const DEFAULT_INDENT = "tab";
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Options related to formatting.
|
| 28 |
+
* Provided for building a stable API - gives an space for expansion on future improvements/features.
|
| 29 |
+
*
|
| 30 |
+
* @typedef FormatOptions
|
| 31 |
+
* @property {IndentName} [indent] - defaults to {@link DEFAULT_INDENT}
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* @typedef {Extract<keyof Root, "css" | "fragment" | "instance" | "module" | "options">} RootNode
|
| 36 |
+
*/
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Specified order of {@link Root} child AST nodes to print out.
|
| 40 |
+
*
|
| 41 |
+
* ## Legend
|
| 42 |
+
*
|
| 43 |
+
* - `"options"` - {@link SvelteOptionsRaw}
|
| 44 |
+
* - `"module"` - {@link Script}
|
| 45 |
+
* - `"instance"` - {@link Script}
|
| 46 |
+
* - `"fragment"` - {@link Fragment}
|
| 47 |
+
* - `"css"` - {@link Css.StyleSheet}
|
| 48 |
+
*
|
| 49 |
+
* @typedef {ReadonlyTuple<RootNode, 5>} RootOrder
|
| 50 |
+
*/
|
| 51 |
+
|
| 52 |
+
// TODO: Use generic type parameter, so we use it only when passed node is {@link Root}
|
| 53 |
+
/**
|
| 54 |
+
* Options related to {@link Root} Svelte AST node.
|
| 55 |
+
* @typedef RootOptions
|
| 56 |
+
* @property {RootOrder} [order] - defaults to {@link DEFAULT_ORDER}
|
| 57 |
+
*/
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* @satisfies {ReadonlyTuple<RootNode, 5>}
|
| 61 |
+
*/
|
| 62 |
+
export const DEFAULT_ORDER = /** @type {const} */ (["options", "module", "instance", "fragment", "css"]);
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* This class is for internal use only.
|
| 66 |
+
* Give sa a better control on transforming passed options to the second argument of {@link print}
|
| 67 |
+
*
|
| 68 |
+
* @private
|
| 69 |
+
* @internal
|
| 70 |
+
*/
|
| 71 |
+
export class Options {
|
| 72 |
+
static INDENT = new Map(
|
| 73 |
+
/** @type {const} */ ([
|
| 74 |
+
["tab", "\t"],
|
| 75 |
+
["2-space", " "],
|
| 76 |
+
["4-space", " "],
|
| 77 |
+
]),
|
| 78 |
+
);
|
| 79 |
+
|
| 80 |
+
/**
|
| 81 |
+
* @type {PrintOptions} raw options - _(before transformation)_ - for better DX
|
| 82 |
+
*/
|
| 83 |
+
#raw;
|
| 84 |
+
|
| 85 |
+
/**
|
| 86 |
+
* @param {PrintOptions} raw - provided options by user - before transformation
|
| 87 |
+
*/
|
| 88 |
+
constructor(raw) {
|
| 89 |
+
this.#raw = raw;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
get indent() {
|
| 93 |
+
const { format } = this.#raw;
|
| 94 |
+
const transformed = Options.INDENT.get(format?.indent ?? DEFAULT_INDENT);
|
| 95 |
+
if (!transformed) {
|
| 96 |
+
throw new Error(`Unrecognized indent name - ${format?.indent}, allowed are: ${[...Options.INDENT.keys()]}`);
|
| 97 |
+
}
|
| 98 |
+
return transformed;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/** @type {RootOrder} */
|
| 102 |
+
get order() {
|
| 103 |
+
const { root } = this.#raw;
|
| 104 |
+
|
| 105 |
+
return root?.order ?? DEFAULT_ORDER;
|
| 106 |
+
}
|
| 107 |
+
}
|
tools/ui/node_modules/svelte-ast-print/types/mod.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module 'svelte-ast-print' {
|
| 2 |
+
import type { Node as ESTreeNode } from 'estree';
|
| 3 |
+
import type { AST } from 'svelte/compiler';
|
| 4 |
+
/**
|
| 5 |
+
* Print AST {@link SvelteAST.BaseNode} as a string.
|
| 6 |
+
* Aka parse in reverse.
|
| 7 |
+
*
|
| 8 |
+
* ## How does it work under the hood?
|
| 9 |
+
*
|
| 10 |
+
* 1. Firstly, it determines whether the provided AST node is unique node for Svelte {@link SvelteAST.Node}.
|
| 11 |
+
* 2. Based on type check guard from above:
|
| 12 |
+
* - it uses either this package's {@link Printer} to print Svelte AST node,
|
| 13 |
+
* - otherwise it uses `esrap` {@link print_es} to print ESTree specification-complaint AST node
|
| 14 |
+
*
|
| 15 |
+
* ## How to use it?
|
| 16 |
+
*
|
| 17 |
+
* @example writing a codemode using Node.js
|
| 18 |
+
```js
|
| 19 |
+
import fs from "node:fs";
|
| 20 |
+
|
| 21 |
+
import { print } from "svelte-ast-print";
|
| 22 |
+
import { parse } from "svelte/compiler";
|
| 23 |
+
|
| 24 |
+
const originalSvelteCode = fs.readFileSync("src/App.svelte", "utf-8");
|
| 25 |
+
let svelteAST = parse(originalSvelteCode, { modern: true });
|
| 26 |
+
// 👆 For now, only modern is supported.
|
| 27 |
+
// By default is 'false'.
|
| 28 |
+
// Is it planned to be 'true' from Svelte v6+
|
| 29 |
+
|
| 30 |
+
// ...
|
| 31 |
+
// Do some modifications on this AST...
|
| 32 |
+
// e.g. transform `<slot />` to `{@render children()}`
|
| 33 |
+
// ...
|
| 34 |
+
|
| 35 |
+
const output = print(svelteAST); // AST is now a stringified code output! 🎉
|
| 36 |
+
|
| 37 |
+
fs.writeFileSync("src/App.svelte", output, { encoding: " utf-8" });
|
| 38 |
+
```
|
| 39 |
+
*
|
| 40 |
+
* @param node - Svelte or ESTree AST node
|
| 41 |
+
* @param options - printing options
|
| 42 |
+
* @returns Stringified Svelte AST node
|
| 43 |
+
* TODO: Ask Svelte maintainers if `Script` and `SvelteOptions` were omittted from `SvelteNode` intentionally - possibly forgotten to include
|
| 44 |
+
*/
|
| 45 |
+
export function print(node: Node, options?: Partial<ConstructorParameters<typeof Options>[0]>): string;
|
| 46 |
+
export function isAttributeLikeNode(node: SvelteNode): node is AttributeLike;
|
| 47 |
+
export function isBlockNode(node: SvelteNode): node is Block;
|
| 48 |
+
export function isCssNode(node: SvelteNode): node is AST.Css.Node;
|
| 49 |
+
export function isElementLikeNode(node: SvelteNode): node is ElementLike;
|
| 50 |
+
export function isHtmlNode(node: SvelteNode): node is HtmlNode;
|
| 51 |
+
export function isTagNode(node: SvelteNode): node is Tag;
|
| 52 |
+
export function isTemplateNode(node: SvelteNode): node is TemplateNode;
|
| 53 |
+
export function isSvelteNode(node: Node): node is SupportedSvelteNode;
|
| 54 |
+
/**
|
| 55 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L514
|
| 56 |
+
* FIXME: Include `Css.Node` when exposed to public
|
| 57 |
+
*/
|
| 58 |
+
type SvelteNode = ESTreeNode | TemplateNode | AST.Fragment;
|
| 59 |
+
/**
|
| 60 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L476
|
| 61 |
+
*/
|
| 62 |
+
type Directive = AST.AnimateDirective | AST.BindDirective | AST.ClassDirective | AST.LetDirective | AST.OnDirective | AST.SpreadAttribute | AST.StyleDirective | AST.TransitionDirective | AST.UseDirective;
|
| 63 |
+
type AttributeLike = AST.Attribute | AST.SpreadAttribute | Directive;
|
| 64 |
+
/**
|
| 65 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L486
|
| 66 |
+
*/
|
| 67 |
+
type Block = AST.EachBlock | AST.IfBlock | AST.AwaitBlock | AST.KeyBlock | AST.SnippetBlock;
|
| 68 |
+
/**
|
| 69 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L488
|
| 70 |
+
*/
|
| 71 |
+
type ElementLike = AST.Component | AST.TitleElement | AST.SlotElement | AST.RegularElement | AST.SvelteBody | AST.SvelteComponent | AST.SvelteDocument | AST.SvelteElement | AST.SvelteFragment | AST.SvelteHead | AST.SvelteOptionsRaw | AST.SvelteSelf | AST.SvelteWindow;
|
| 72 |
+
type HtmlNode = AST.Comment | AST.Text;
|
| 73 |
+
/**
|
| 74 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L474
|
| 75 |
+
*/
|
| 76 |
+
type Tag = AST.ExpressionTag | AST.HtmlTag | AST.ConstTag | AST.DebugTag | AST.RenderTag;
|
| 77 |
+
/**
|
| 78 |
+
* TODO: Svelte could expose this type to public too: https://github.com/sveltejs/svelte/blob/2b362ddc63e930726b67a1010d2829a3a4f6bb85/packages/svelte/src/compiler/types/template.d.ts#L503
|
| 79 |
+
*/
|
| 80 |
+
type TemplateNode = AST.Root | AST.Text | Tag | ElementLike | AST.Attribute | AST.SpreadAttribute | Directive | AST.Comment | Block;
|
| 81 |
+
/**
|
| 82 |
+
* Not all of the nodes are bundled together with {@link AST.BaseNode}.
|
| 83 |
+
* This type wraps them together as supported ones for printing.
|
| 84 |
+
*/
|
| 85 |
+
type SupportedSvelteNode = AST.Script | AST.BaseNode | AST.SvelteOptionsRaw | SvelteNode;
|
| 86 |
+
/**
|
| 87 |
+
* Bundle together Svelte and ESTree specification complaint nodes, so we can support printing both.
|
| 88 |
+
*/
|
| 89 |
+
type Node = ESTreeNode | SupportedSvelteNode;
|
| 90 |
+
/**
|
| 91 |
+
* This class is for internal use only.
|
| 92 |
+
* Give sa a better control on transforming passed options to the second argument of {@link print}
|
| 93 |
+
*
|
| 94 |
+
* */
|
| 95 |
+
class Options {
|
| 96 |
+
static INDENT: Map<"tab" | "2-space" | "4-space", "\t" | " " | " ">;
|
| 97 |
+
/**
|
| 98 |
+
* @param raw - provided options by user - before transformation
|
| 99 |
+
*/
|
| 100 |
+
constructor(raw: PrintOptions);
|
| 101 |
+
get indent(): "\t" | " " | " ";
|
| 102 |
+
|
| 103 |
+
get order(): readonly [never, never, never, never, never];
|
| 104 |
+
#private;
|
| 105 |
+
}
|
| 106 |
+
/**
|
| 107 |
+
* Options for {@link print} defined by user.
|
| 108 |
+
*/
|
| 109 |
+
type PrintOptions = {
|
| 110 |
+
/**
|
| 111 |
+
* - formatting options
|
| 112 |
+
*/
|
| 113 |
+
format?: Partial<FormatOptions> | undefined;
|
| 114 |
+
/**
|
| 115 |
+
* - Svelte AST node {@link Root} based options
|
| 116 |
+
*/
|
| 117 |
+
root?: Partial<RootOptions> | undefined;
|
| 118 |
+
};
|
| 119 |
+
/**
|
| 120 |
+
* Options related to formatting.
|
| 121 |
+
* Provided for building a stable API - gives an space for expansion on future improvements/features.
|
| 122 |
+
*/
|
| 123 |
+
type FormatOptions = {
|
| 124 |
+
/**
|
| 125 |
+
* - defaults to {@link DEFAULT_INDENT}
|
| 126 |
+
*/
|
| 127 |
+
indent?: "tab" | "2-space" | "4-space" | undefined;
|
| 128 |
+
};
|
| 129 |
+
/**
|
| 130 |
+
* Options related to {@link Root} Svelte AST node.
|
| 131 |
+
*/
|
| 132 |
+
type RootOptions = {
|
| 133 |
+
/**
|
| 134 |
+
* - defaults to {@link DEFAULT_ORDER}
|
| 135 |
+
*/
|
| 136 |
+
order?: readonly [never, never, never, never, never] | undefined;
|
| 137 |
+
};
|
| 138 |
+
|
| 139 |
+
export {};
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
//# sourceMappingURL=mod.d.ts.map
|
tools/ui/node_modules/svelte-ast-print/types/mod.d.ts.map
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 3,
|
| 3 |
+
"file": "mod.d.ts",
|
| 4 |
+
"names": [
|
| 5 |
+
"print",
|
| 6 |
+
"SvelteNode",
|
| 7 |
+
"Directive",
|
| 8 |
+
"AttributeLike",
|
| 9 |
+
"Block",
|
| 10 |
+
"ElementLike",
|
| 11 |
+
"HtmlNode",
|
| 12 |
+
"Tag",
|
| 13 |
+
"TemplateNode",
|
| 14 |
+
"SupportedSvelteNode",
|
| 15 |
+
"Node",
|
| 16 |
+
"Options"
|
| 17 |
+
],
|
| 18 |
+
"sources": [
|
| 19 |
+
"../src/mod.js",
|
| 20 |
+
"../src/nodes.js",
|
| 21 |
+
"../src/options.js"
|
| 22 |
+
],
|
| 23 |
+
"sourcesContent": [
|
| 24 |
+
null,
|
| 25 |
+
null,
|
| 26 |
+
null
|
| 27 |
+
],
|
| 28 |
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAkEgBA,KAAKA;;;;;;;;;;;;;MCzDkCC,UAAUA;;;;MAKwIC,SAASA;MAGnJC,aAAaA;;;;MAgCiBC,KAAKA;;;;MA+DqKC,WAAWA;MAiC5OC,QAAQA;;;;MAmC8CC,GAAGA;;;;MAoB+BC,YAAYA;;;;;MA8B9DC,mBAAmBA;;;;MAMhDC,IAAIA;;;;;;OCtKtCC,OAAOA",
|
| 29 |
+
"ignoreList": []
|
| 30 |
+
}
|
tools/ui/node_modules/svelte-check/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2020-Present [these people](https://github.com/sveltejs/language-tools/graphs/contributors)
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
| 4 |
+
|
| 5 |
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
| 6 |
+
|
| 7 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
tools/ui/node_modules/svelte-check/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Check your code with svelte-check
|
| 2 |
+
|
| 3 |
+
Provides CLI diagnostics checks for:
|
| 4 |
+
|
| 5 |
+
- Unused CSS
|
| 6 |
+
- Svelte A11y hints
|
| 7 |
+
- JavaScript/TypeScript compiler errors
|
| 8 |
+
|
| 9 |
+
Requires Node 16 or later.
|
| 10 |
+
|
| 11 |
+
### Usage:
|
| 12 |
+
|
| 13 |
+
#### Local / in your project
|
| 14 |
+
|
| 15 |
+
Installation:
|
| 16 |
+
|
| 17 |
+
`npm i svelte-check --save-dev`
|
| 18 |
+
|
| 19 |
+
Package.json:
|
| 20 |
+
|
| 21 |
+
```json
|
| 22 |
+
{
|
| 23 |
+
// ...
|
| 24 |
+
"scripts": {
|
| 25 |
+
"svelte-check": "svelte-check"
|
| 26 |
+
// ...
|
| 27 |
+
},
|
| 28 |
+
// ...
|
| 29 |
+
"devDependencies": {
|
| 30 |
+
"svelte-check": "..."
|
| 31 |
+
// ...
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
Usage:
|
| 37 |
+
|
| 38 |
+
`npm run svelte-check`
|
| 39 |
+
|
| 40 |
+
#### Global (not recommended)
|
| 41 |
+
|
| 42 |
+
Installation:
|
| 43 |
+
|
| 44 |
+
`npm i svelte-check svelte -g`
|
| 45 |
+
|
| 46 |
+
Usage:
|
| 47 |
+
|
| 48 |
+
1. Go to folder where to start checking
|
| 49 |
+
2. `svelte-check`
|
| 50 |
+
|
| 51 |
+
### Args:
|
| 52 |
+
|
| 53 |
+
| Flag | Description |
|
| 54 |
+
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| 55 |
+
| `--workspace <path>` | Path to your workspace. All subdirectories except node_modules and those listed in `--ignore` are checked |
|
| 56 |
+
| `--output <human\|human-verbose\|machine\|machine-verbose>` |
|
| 57 |
+
| `--watch` | Will not exit after one pass but keep watching files for changes and rerun diagnostics |
|
| 58 |
+
| `--preserveWatchOutput` | Do not clear the screen in watch mode |
|
| 59 |
+
| `--tsconfig <path>` | Pass a path to a tsconfig or jsconfig file. The path can be relative to the workspace path or absolute. Doing this means that only files matched by the files/include/exclude pattern of the config file are diagnosed. It also means that errors from TypeScript and JavaScript files are reported. If not given, will do an upwards traversal looking for the next jsconfig/tsconfig.json |
|
| 60 |
+
| `--no-tsconfig` | Use this if you only want to check the Svelte files found in the current directory and below and ignore any JS/TS files (they will not be type-checked) |
|
| 61 |
+
| `--ignore <path1,path2>` | Can only be used in conjunction with `--no-tsconfig`. Files/folders to ignore - relative to workspace root, comma-separated, inside quotes. Example: `--ignore "dist,build"`. |
|
| 62 |
+
| `--fail-on-warnings` | Will also exit with error code when there are warnings |
|
| 63 |
+
| `--compiler-warnings <code1:error\|ignore,code2:error\|ignore>` | A list of Svelte compiler warning codes. Each entry defines whether that warning should be ignored or treated as an error. Warnings are comma-separated, between warning code and error level is a colon; all inside quotes. Example: `--compiler-warnings "css-unused-selector:ignore,unused-export-let:error"` |
|
| 64 |
+
| `--diagnostic-sources <js,svelte,css>` | A list of diagnostic sources which should run diagnostics on your code. Possible values are `js` (includes TS), `svelte`, `css`. Comma-separated, inside quotes. By default all are active. Example: `--diagnostic-sources "js,svelte"` |
|
| 65 |
+
| `--threshold <error\|warning>` | Filters the diagnostics to display. `error` will output only errors while `warning` will output warnings and errors. |
|
| 66 |
+
| `--incremental` | Opts into TypeScript's incremental build cache, which speeds up subsequent runs. Saved within `.svelte-kit` or if not available within `.svelte-check`. This might result in slightly different type check outcomes, and certain patterns are not supported. Specifically, anything that is not in the root dir of your tsconfig.json and is a Svelte file will not be properly loaded and type-checked. |
|
| 67 |
+
| `--tsgo` | Use TypeScript's Go implementation. Needs to have `@typescript/native-preview` installed. Subject to the same limitations as `--incremental` |
|
| 68 |
+
|
| 69 |
+
### FAQ
|
| 70 |
+
|
| 71 |
+
#### Why is there no option to only check specific files (for example only staged files)?
|
| 72 |
+
|
| 73 |
+
`svelte-check` needs to know the whole project to do valid checks. Imagine you alter a component property `export let foo` to `export let bar`, but you don't update any of the component usages. They all have errors now but you would not catch them if you only run checks on changed files.
|
| 74 |
+
|
| 75 |
+
### More docs, preprocessor setup and troubleshooting
|
| 76 |
+
|
| 77 |
+
[See here](/docs/README.md).
|
| 78 |
+
|
| 79 |
+
### Machine-Readable Output
|
| 80 |
+
|
| 81 |
+
Setting the `--output` to `machine` or `machine-verbose` will format output in a way that is easier to read
|
| 82 |
+
by machines, e.g. inside CI pipelines, for code quality checks, etc.
|
| 83 |
+
|
| 84 |
+
Each row corresponds to a new record. Rows are made up of columns that are separated by a
|
| 85 |
+
single space character. The first column of every row contains a timestamp in milliseconds
|
| 86 |
+
which can be used for monitoring purposes. The second column gives us the "row type", based
|
| 87 |
+
on which the number and types of subsequent columns may differ.
|
| 88 |
+
|
| 89 |
+
The first row is of type `START` and contains the workspace folder (wrapped in quotes).
|
| 90 |
+
|
| 91 |
+
###### Example:
|
| 92 |
+
|
| 93 |
+
```
|
| 94 |
+
1590680325583 START "/home/user/language-tools/packages/language-server/test/plugins/typescript/testfiles"
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
Any number of `ERROR` or `WARNING` records may follow. Their structure is identical and depends on the output argoument.
|
| 98 |
+
|
| 99 |
+
If the argument is `machine` it will tell us the filename, the starting line and column numbers, and the error message. The filename is relative to the workspace directory. The filename and the message are both wrapped in quotes.
|
| 100 |
+
|
| 101 |
+
###### Example:
|
| 102 |
+
|
| 103 |
+
```
|
| 104 |
+
1590680326283 ERROR "codeactions.svelte" 1:16 "Cannot find module 'blubb' or its corresponding type declarations."
|
| 105 |
+
1590680326778 WARNING "imported-file.svelte" 0:37 "Component has unused export property 'prop'. If it is for external reference only, please consider using `export const prop`"
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
If the argument is `machine-verbose` it will tell us the filename, the starting line and column numbers, the ending line and column numbers, the error message, the code of diagnostic, the human-friendly description of the code and the human-friendly source of the diagnostic (eg. svelte/typescript). The filename is relative to the workspace directory. Each diagnostic is represented as an [ndjson](https://en.wikipedia.org/wiki/JSON_streaming#Newline-Delimited_JSON) line prefixed by the timestamp of the log.
|
| 109 |
+
|
| 110 |
+
###### Example:
|
| 111 |
+
|
| 112 |
+
```
|
| 113 |
+
1590680326283 {"type":"ERROR","fn":"codeaction.svelte","start":{"line":1,"character":16},"end":{"line":1,"character":23},"message":"Cannot find module 'blubb' or its corresponding type declarations.","code":2307,"source":"js"}
|
| 114 |
+
1590680326778 {"type":"WARNING","filename":"imported-file.svelte","start":{"line":0,"character":37},"end":{"line":0,"character":51},"message":"Component has unused export property 'prop'. If it is for external reference only, please consider using `export
|
| 115 |
+
const prop`","code":"unused-export-let","source":"svelte"}
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
The output concludes with a `COMPLETED` message that summarizes total numbers of files, errors and warnings that were encountered during the check.
|
| 119 |
+
|
| 120 |
+
###### Example:
|
| 121 |
+
|
| 122 |
+
```
|
| 123 |
+
1590680326807 COMPLETED 20 FILES 21 ERRORS 1 WARNINGS 3 FILES_WITH_PROBLEMS
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
If the application experiences a runtime error, this error will appear as a `FAILURE` record.
|
| 127 |
+
|
| 128 |
+
###### Example:
|
| 129 |
+
|
| 130 |
+
```
|
| 131 |
+
1590680328921 FAILURE "Connection closed"
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
### Credits
|
| 135 |
+
|
| 136 |
+
- Vue's [VTI](https://github.com/vuejs/vetur/tree/master/vti) which laid the foundation for `svelte-check`
|
tools/ui/node_modules/svelte-check/bin/svelte-check
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env node
|
| 2 |
+
require('../dist/src/index.js');
|
tools/ui/node_modules/svelte-check/dist/src/index.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tools/ui/node_modules/svelte-check/dist/src/svelte-jsx-v4.d.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// <reference lib="dom" />
|
| 2 |
+
|
| 3 |
+
declare namespace svelteHTML {
|
| 4 |
+
|
| 5 |
+
// Every namespace eligible for use needs to implement the following two functions
|
| 6 |
+
/**
|
| 7 |
+
* @internal do not use
|
| 8 |
+
*/
|
| 9 |
+
function mapElementTag<K extends keyof ElementTagNameMap>(
|
| 10 |
+
tag: K
|
| 11 |
+
): ElementTagNameMap[K];
|
| 12 |
+
function mapElementTag<K extends keyof SVGElementTagNameMap>(
|
| 13 |
+
tag: K
|
| 14 |
+
): SVGElementTagNameMap[K];
|
| 15 |
+
function mapElementTag(
|
| 16 |
+
tag: any
|
| 17 |
+
): any; // needs to be any because used in context of <svelte:element>
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* @internal do not use
|
| 21 |
+
*/
|
| 22 |
+
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
|
| 23 |
+
// "undefined | null" because of <svelte:element>
|
| 24 |
+
element: Key | undefined | null, attrs: string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]
|
| 25 |
+
): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
|
| 26 |
+
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements, T>(
|
| 27 |
+
// "undefined | null" because of <svelte:element>
|
| 28 |
+
element: Key | undefined | null, attrsEnhancers: T, attrs: (string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]) & T
|
| 29 |
+
): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
|
| 30 |
+
|
| 31 |
+
// For backwards-compatibility and ease-of-use, in case someone enhanced the typings from import('svelte/elements').HTMLAttributes/SVGAttributes
|
| 32 |
+
interface HTMLAttributes<T extends EventTarget = any> {}
|
| 33 |
+
interface SVGAttributes<T extends EventTarget = any> {}
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* @internal do not use
|
| 37 |
+
*/
|
| 38 |
+
type HTMLProps<Property extends string, Override> =
|
| 39 |
+
Omit<import('svelte/elements').SvelteHTMLElements[Property], keyof Override> & Override;
|
| 40 |
+
|
| 41 |
+
interface IntrinsicElements {
|
| 42 |
+
a: HTMLProps<'a', HTMLAttributes>;
|
| 43 |
+
abbr: HTMLProps<'abbr', HTMLAttributes>;
|
| 44 |
+
address: HTMLProps<'address', HTMLAttributes>;
|
| 45 |
+
area: HTMLProps<'area', HTMLAttributes>;
|
| 46 |
+
article: HTMLProps<'article', HTMLAttributes>;
|
| 47 |
+
aside: HTMLProps<'aside', HTMLAttributes>;
|
| 48 |
+
audio: HTMLProps<'audio', HTMLAttributes>;
|
| 49 |
+
b: HTMLProps<'b', HTMLAttributes>;
|
| 50 |
+
base: HTMLProps<'base', HTMLAttributes>;
|
| 51 |
+
bdi: HTMLProps<'bdi', HTMLAttributes>;
|
| 52 |
+
bdo: HTMLProps<'bdo', HTMLAttributes>;
|
| 53 |
+
big: HTMLProps<'big', HTMLAttributes>;
|
| 54 |
+
blockquote: HTMLProps<'blockquote', HTMLAttributes>;
|
| 55 |
+
body: HTMLProps<'body', HTMLAttributes>;
|
| 56 |
+
br: HTMLProps<'br', HTMLAttributes>;
|
| 57 |
+
button: HTMLProps<'button', HTMLAttributes>;
|
| 58 |
+
canvas: HTMLProps<'canvas', HTMLAttributes>;
|
| 59 |
+
caption: HTMLProps<'caption', HTMLAttributes>;
|
| 60 |
+
cite: HTMLProps<'cite', HTMLAttributes>;
|
| 61 |
+
code: HTMLProps<'code', HTMLAttributes>;
|
| 62 |
+
col: HTMLProps<'col', HTMLAttributes>;
|
| 63 |
+
colgroup: HTMLProps<'colgroup', HTMLAttributes>;
|
| 64 |
+
data: HTMLProps<'data', HTMLAttributes>;
|
| 65 |
+
datalist: HTMLProps<'datalist', HTMLAttributes>;
|
| 66 |
+
dd: HTMLProps<'dd', HTMLAttributes>;
|
| 67 |
+
del: HTMLProps<'del', HTMLAttributes>;
|
| 68 |
+
details: HTMLProps<'details', HTMLAttributes>;
|
| 69 |
+
dfn: HTMLProps<'dfn', HTMLAttributes>;
|
| 70 |
+
dialog: HTMLProps<'dialog', HTMLAttributes>;
|
| 71 |
+
div: HTMLProps<'div', HTMLAttributes>;
|
| 72 |
+
dl: HTMLProps<'dl', HTMLAttributes>;
|
| 73 |
+
dt: HTMLProps<'dt', HTMLAttributes>;
|
| 74 |
+
em: HTMLProps<'em', HTMLAttributes>;
|
| 75 |
+
embed: HTMLProps<'embed', HTMLAttributes>;
|
| 76 |
+
fieldset: HTMLProps<'fieldset', HTMLAttributes>;
|
| 77 |
+
figcaption: HTMLProps<'figcaption', HTMLAttributes>;
|
| 78 |
+
figure: HTMLProps<'figure', HTMLAttributes>;
|
| 79 |
+
footer: HTMLProps<'footer', HTMLAttributes>;
|
| 80 |
+
form: HTMLProps<'form', HTMLAttributes>;
|
| 81 |
+
h1: HTMLProps<'h1', HTMLAttributes>;
|
| 82 |
+
h2: HTMLProps<'h2', HTMLAttributes>;
|
| 83 |
+
h3: HTMLProps<'h3', HTMLAttributes>;
|
| 84 |
+
h4: HTMLProps<'h4', HTMLAttributes>;
|
| 85 |
+
h5: HTMLProps<'h5', HTMLAttributes>;
|
| 86 |
+
h6: HTMLProps<'h6', HTMLAttributes>;
|
| 87 |
+
head: HTMLProps<'head', HTMLAttributes>;
|
| 88 |
+
header: HTMLProps<'header', HTMLAttributes>;
|
| 89 |
+
hgroup: HTMLProps<'hgroup', HTMLAttributes>;
|
| 90 |
+
hr: HTMLProps<'hr', HTMLAttributes>;
|
| 91 |
+
html: HTMLProps<'html', HTMLAttributes>;
|
| 92 |
+
i: HTMLProps<'i', HTMLAttributes>;
|
| 93 |
+
iframe: HTMLProps<'iframe', HTMLAttributes>;
|
| 94 |
+
img: HTMLProps<'img', HTMLAttributes>;
|
| 95 |
+
input: HTMLProps<'input', HTMLAttributes>;
|
| 96 |
+
ins: HTMLProps<'ins', HTMLAttributes>;
|
| 97 |
+
kbd: HTMLProps<'kbd', HTMLAttributes>;
|
| 98 |
+
keygen: HTMLProps<'keygen', HTMLAttributes>;
|
| 99 |
+
label: HTMLProps<'label', HTMLAttributes>;
|
| 100 |
+
legend: HTMLProps<'legend', HTMLAttributes>;
|
| 101 |
+
li: HTMLProps<'li', HTMLAttributes>;
|
| 102 |
+
link: HTMLProps<'link', HTMLAttributes>;
|
| 103 |
+
main: HTMLProps<'main', HTMLAttributes>;
|
| 104 |
+
map: HTMLProps<'map', HTMLAttributes>;
|
| 105 |
+
mark: HTMLProps<'mark', HTMLAttributes>;
|
| 106 |
+
menu: HTMLProps<'menu', HTMLAttributes>;
|
| 107 |
+
menuitem: HTMLProps<'menuitem', HTMLAttributes>;
|
| 108 |
+
meta: HTMLProps<'meta', HTMLAttributes>;
|
| 109 |
+
meter: HTMLProps<'meter', HTMLAttributes>;
|
| 110 |
+
nav: HTMLProps<'nav', HTMLAttributes>;
|
| 111 |
+
noscript: HTMLProps<'noscript', HTMLAttributes>;
|
| 112 |
+
object: HTMLProps<'object', HTMLAttributes>;
|
| 113 |
+
ol: HTMLProps<'ol', HTMLAttributes>;
|
| 114 |
+
optgroup: HTMLProps<'optgroup', HTMLAttributes>;
|
| 115 |
+
option: HTMLProps<'option', HTMLAttributes>;
|
| 116 |
+
output: HTMLProps<'output', HTMLAttributes>;
|
| 117 |
+
p: HTMLProps<'p', HTMLAttributes>;
|
| 118 |
+
param: HTMLProps<'param', HTMLAttributes>;
|
| 119 |
+
picture: HTMLProps<'picture', HTMLAttributes>;
|
| 120 |
+
pre: HTMLProps<'pre', HTMLAttributes>;
|
| 121 |
+
progress: HTMLProps<'progress', HTMLAttributes>;
|
| 122 |
+
q: HTMLProps<'q', HTMLAttributes>;
|
| 123 |
+
rp: HTMLProps<'rp', HTMLAttributes>;
|
| 124 |
+
rt: HTMLProps<'rt', HTMLAttributes>;
|
| 125 |
+
ruby: HTMLProps<'ruby', HTMLAttributes>;
|
| 126 |
+
s: HTMLProps<'s', HTMLAttributes>;
|
| 127 |
+
samp: HTMLProps<'samp', HTMLAttributes>;
|
| 128 |
+
slot: HTMLProps<'slot', HTMLAttributes>;
|
| 129 |
+
script: HTMLProps<'script', HTMLAttributes>;
|
| 130 |
+
section: HTMLProps<'section', HTMLAttributes>;
|
| 131 |
+
select: HTMLProps<'select', HTMLAttributes>;
|
| 132 |
+
small: HTMLProps<'small', HTMLAttributes>;
|
| 133 |
+
source: HTMLProps<'source', HTMLAttributes>;
|
| 134 |
+
span: HTMLProps<'span', HTMLAttributes>;
|
| 135 |
+
strong: HTMLProps<'strong', HTMLAttributes>;
|
| 136 |
+
style: HTMLProps<'style', HTMLAttributes>;
|
| 137 |
+
sub: HTMLProps<'sub', HTMLAttributes>;
|
| 138 |
+
summary: HTMLProps<'summary', HTMLAttributes>;
|
| 139 |
+
sup: HTMLProps<'sup', HTMLAttributes>;
|
| 140 |
+
table: HTMLProps<'table', HTMLAttributes>;
|
| 141 |
+
template: HTMLProps<'template', HTMLAttributes>;
|
| 142 |
+
tbody: HTMLProps<'tbody', HTMLAttributes>;
|
| 143 |
+
td: HTMLProps<'td', HTMLAttributes>;
|
| 144 |
+
textarea: HTMLProps<'textarea', HTMLAttributes>;
|
| 145 |
+
tfoot: HTMLProps<'tfoot', HTMLAttributes>;
|
| 146 |
+
th: HTMLProps<'th', HTMLAttributes>;
|
| 147 |
+
thead: HTMLProps<'thead', HTMLAttributes>;
|
| 148 |
+
time: HTMLProps<'time', HTMLAttributes>;
|
| 149 |
+
title: HTMLProps<'title', HTMLAttributes>;
|
| 150 |
+
tr: HTMLProps<'tr', HTMLAttributes>;
|
| 151 |
+
track: HTMLProps<'track', HTMLAttributes>;
|
| 152 |
+
u: HTMLProps<'u', HTMLAttributes>;
|
| 153 |
+
ul: HTMLProps<'ul', HTMLAttributes>;
|
| 154 |
+
var: HTMLProps<'var', HTMLAttributes>;
|
| 155 |
+
video: HTMLProps<'video', HTMLAttributes>;
|
| 156 |
+
wbr: HTMLProps<'wbr', HTMLAttributes>;
|
| 157 |
+
webview: HTMLProps<'webview', HTMLAttributes>;
|
| 158 |
+
// SVG
|
| 159 |
+
svg: HTMLProps<'svg', SVGAttributes>;
|
| 160 |
+
|
| 161 |
+
animate: HTMLProps<'animate', SVGAttributes>;
|
| 162 |
+
animateMotion: HTMLProps<'animateMotion', SVGAttributes>;
|
| 163 |
+
animateTransform: HTMLProps<'animateTransform', SVGAttributes>;
|
| 164 |
+
circle: HTMLProps<'circle', SVGAttributes>;
|
| 165 |
+
clipPath: HTMLProps<'clipPath', SVGAttributes>;
|
| 166 |
+
defs: HTMLProps<'defs', SVGAttributes>;
|
| 167 |
+
desc: HTMLProps<'desc', SVGAttributes>;
|
| 168 |
+
ellipse: HTMLProps<'ellipse', SVGAttributes>;
|
| 169 |
+
feBlend: HTMLProps<'feBlend', SVGAttributes>;
|
| 170 |
+
feColorMatrix: HTMLProps<'feColorMatrix', SVGAttributes>;
|
| 171 |
+
feComponentTransfer: HTMLProps<'feComponentTransfer', SVGAttributes>;
|
| 172 |
+
feComposite: HTMLProps<'feComposite', SVGAttributes>;
|
| 173 |
+
feConvolveMatrix: HTMLProps<'feConvolveMatrix', SVGAttributes>;
|
| 174 |
+
feDiffuseLighting: HTMLProps<'feDiffuseLighting', SVGAttributes>;
|
| 175 |
+
feDisplacementMap: HTMLProps<'feDisplacementMap', SVGAttributes>;
|
| 176 |
+
feDistantLight: HTMLProps<'feDistantLight', SVGAttributes>;
|
| 177 |
+
feDropShadow: HTMLProps<'feDropShadow', SVGAttributes>;
|
| 178 |
+
feFlood: HTMLProps<'feFlood', SVGAttributes>;
|
| 179 |
+
feFuncA: HTMLProps<'feFuncA', SVGAttributes>;
|
| 180 |
+
feFuncB: HTMLProps<'feFuncB', SVGAttributes>;
|
| 181 |
+
feFuncG: HTMLProps<'feFuncG', SVGAttributes>;
|
| 182 |
+
feFuncR: HTMLProps<'feFuncR', SVGAttributes>;
|
| 183 |
+
feGaussianBlur: HTMLProps<'feGaussianBlur', SVGAttributes>;
|
| 184 |
+
feImage: HTMLProps<'feImage', SVGAttributes>;
|
| 185 |
+
feMerge: HTMLProps<'feMerge', SVGAttributes>;
|
| 186 |
+
feMergeNode: HTMLProps<'feMergeNode', SVGAttributes>;
|
| 187 |
+
feMorphology: HTMLProps<'feMorphology', SVGAttributes>;
|
| 188 |
+
feOffset: HTMLProps<'feOffset', SVGAttributes>;
|
| 189 |
+
fePointLight: HTMLProps<'fePointLight', SVGAttributes>;
|
| 190 |
+
feSpecularLighting: HTMLProps<'feSpecularLighting', SVGAttributes>;
|
| 191 |
+
feSpotLight: HTMLProps<'feSpotLight', SVGAttributes>;
|
| 192 |
+
feTile: HTMLProps<'feTile', SVGAttributes>;
|
| 193 |
+
feTurbulence: HTMLProps<'feTurbulence', SVGAttributes>;
|
| 194 |
+
filter: HTMLProps<'filter', SVGAttributes>;
|
| 195 |
+
foreignObject: HTMLProps<'foreignObject', SVGAttributes>;
|
| 196 |
+
g: HTMLProps<'g', SVGAttributes>;
|
| 197 |
+
image: HTMLProps<'image', SVGAttributes>;
|
| 198 |
+
line: HTMLProps<'line', SVGAttributes>;
|
| 199 |
+
linearGradient: HTMLProps<'linearGradient', SVGAttributes>;
|
| 200 |
+
marker: HTMLProps<'marker', SVGAttributes>;
|
| 201 |
+
mask: HTMLProps<'mask', SVGAttributes>;
|
| 202 |
+
metadata: HTMLProps<'metadata', SVGAttributes>;
|
| 203 |
+
mpath: HTMLProps<'mpath', SVGAttributes>;
|
| 204 |
+
path: HTMLProps<'path', SVGAttributes>;
|
| 205 |
+
pattern: HTMLProps<'pattern', SVGAttributes>;
|
| 206 |
+
polygon: HTMLProps<'polygon', SVGAttributes>;
|
| 207 |
+
polyline: HTMLProps<'polyline', SVGAttributes>;
|
| 208 |
+
radialGradient: HTMLProps<'radialGradient', SVGAttributes>;
|
| 209 |
+
rect: HTMLProps<'rect', SVGAttributes>;
|
| 210 |
+
stop: HTMLProps<'stop', SVGAttributes>;
|
| 211 |
+
switch: HTMLProps<'switch', SVGAttributes>;
|
| 212 |
+
symbol: HTMLProps<'symbol', SVGAttributes>;
|
| 213 |
+
text: HTMLProps<'text', SVGAttributes>;
|
| 214 |
+
textPath: HTMLProps<'textPath', SVGAttributes>;
|
| 215 |
+
tspan: HTMLProps<'tspan', SVGAttributes>;
|
| 216 |
+
use: HTMLProps<'use', SVGAttributes>;
|
| 217 |
+
view: HTMLProps<'view', SVGAttributes>;
|
| 218 |
+
|
| 219 |
+
// Svelte specific
|
| 220 |
+
'svelte:window': HTMLProps<'svelte:window', HTMLAttributes>;
|
| 221 |
+
'svelte:body': HTMLProps<'svelte:body', HTMLAttributes>;
|
| 222 |
+
'svelte:document': HTMLProps<'svelte:document', HTMLAttributes>;
|
| 223 |
+
'svelte:fragment': { slot?: string };
|
| 224 |
+
'svelte:options': { [name: string]: any };
|
| 225 |
+
'svelte:head': { [name: string]: any };
|
| 226 |
+
|
| 227 |
+
[name: string]: { [name: string]: any };
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
}
|
tools/ui/node_modules/svelte-check/dist/src/svelte-jsx.d.ts
ADDED
|
@@ -0,0 +1,1492 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// <reference lib="dom" />
|
| 2 |
+
// @ts-nocheck
|
| 3 |
+
// nocheck because we don't want to adjust this anymore (only used for Svelte 3)
|
| 4 |
+
|
| 5 |
+
declare namespace svelteHTML {
|
| 6 |
+
|
| 7 |
+
// Every namespace eligible for use needs to implement the following two functions
|
| 8 |
+
/**
|
| 9 |
+
* @internal do not use
|
| 10 |
+
*/
|
| 11 |
+
function mapElementTag<K extends keyof ElementTagNameMap>(
|
| 12 |
+
tag: K
|
| 13 |
+
): ElementTagNameMap[K];
|
| 14 |
+
function mapElementTag<K extends keyof SVGElementTagNameMap>(
|
| 15 |
+
tag: K
|
| 16 |
+
): SVGElementTagNameMap[K];
|
| 17 |
+
function mapElementTag(
|
| 18 |
+
tag: any
|
| 19 |
+
): any; // needs to be any because used in context of <svelte:element>
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @internal do not use
|
| 23 |
+
*/
|
| 24 |
+
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
|
| 25 |
+
// "undefined | null" because of <svelte:element>
|
| 26 |
+
element: Key | undefined | null, attrs: string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]
|
| 27 |
+
): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
|
| 28 |
+
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements, T>(
|
| 29 |
+
// "undefined | null" because of <svelte:element>
|
| 30 |
+
element: Key | undefined | null, attrsEnhancers: T, attrs: (string extends Key ? import('svelte/elements').HTMLAttributes<any> : Elements[Key]) & T
|
| 31 |
+
): Key extends keyof ElementTagNameMap ? ElementTagNameMap[Key] : Key extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[Key] : any;
|
| 32 |
+
|
| 33 |
+
// For backwards-compatibility and ease-of-use, in case someone enhanced the typings from import('svelte/elements').HTMLAttributes/SVGAttributes
|
| 34 |
+
interface HTMLAttributes<T extends EventTarget = any> {}
|
| 35 |
+
interface SVGAttributes<T extends EventTarget = any> {}
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* @internal do not use
|
| 39 |
+
*/
|
| 40 |
+
type EventsWithColon<T> = {[Property in keyof T as Property extends `on${infer Key}` ? `on:${Key}` : Property]?: T[Property] }
|
| 41 |
+
/**
|
| 42 |
+
* @internal do not use
|
| 43 |
+
*/
|
| 44 |
+
type HTMLProps<Property extends string, Override> =
|
| 45 |
+
// This omit chain ensures that properties manually defined in the new transformation take precedence
|
| 46 |
+
// over those manually defined in the old, taking precendence over the defaults, to make sth like this possible
|
| 47 |
+
// https://github.com/sveltejs/language-tools/issues/1352#issuecomment-1248627516
|
| 48 |
+
// The AttributeNames Omit is necessary because the old transformation only has HTMLAttributes on which types for all
|
| 49 |
+
// elements are defined, which would silence type errors in the new transformation.
|
| 50 |
+
Omit<
|
| 51 |
+
Omit<import('svelte/elements').SvelteHTMLElements[Property], keyof EventsWithColon<Omit<svelte.JSX.IntrinsicElements[Property & string], svelte.JSX.AttributeNames>>> & EventsWithColon<Omit<svelte.JSX.IntrinsicElements[Property & string], svelte.JSX.AttributeNames>>,
|
| 52 |
+
keyof Override
|
| 53 |
+
> & Override;
|
| 54 |
+
/**
|
| 55 |
+
* @internal do not use
|
| 56 |
+
*/
|
| 57 |
+
type RemoveIndex<T> = {
|
| 58 |
+
[ K in keyof T as string extends K ? never : K ] : T[K]
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
// the following type construct makes sure that we can use the new typings while maintaining backwards-compatibility in case someone enhanced the old typings
|
| 62 |
+
interface IntrinsicElements extends Omit<RemoveIndex<svelte.JSX.IntrinsicElements>, keyof RemoveIndex<import('svelte/elements').SvelteHTMLElements>> {
|
| 63 |
+
a: HTMLProps<'a', HTMLAttributes>;
|
| 64 |
+
abbr: HTMLProps<'abbr', HTMLAttributes>;
|
| 65 |
+
address: HTMLProps<'address', HTMLAttributes>;
|
| 66 |
+
area: HTMLProps<'area', HTMLAttributes>;
|
| 67 |
+
article: HTMLProps<'article', HTMLAttributes>;
|
| 68 |
+
aside: HTMLProps<'aside', HTMLAttributes>;
|
| 69 |
+
audio: HTMLProps<'audio', HTMLAttributes>;
|
| 70 |
+
b: HTMLProps<'b', HTMLAttributes>;
|
| 71 |
+
base: HTMLProps<'base', HTMLAttributes>;
|
| 72 |
+
bdi: HTMLProps<'bdi', HTMLAttributes>;
|
| 73 |
+
bdo: HTMLProps<'bdo', HTMLAttributes>;
|
| 74 |
+
big: HTMLProps<'big', HTMLAttributes>;
|
| 75 |
+
blockquote: HTMLProps<'blockquote', HTMLAttributes>;
|
| 76 |
+
body: HTMLProps<'body', HTMLAttributes>;
|
| 77 |
+
br: HTMLProps<'br', HTMLAttributes>;
|
| 78 |
+
button: HTMLProps<'button', HTMLAttributes>;
|
| 79 |
+
canvas: HTMLProps<'canvas', HTMLAttributes>;
|
| 80 |
+
caption: HTMLProps<'caption', HTMLAttributes>;
|
| 81 |
+
cite: HTMLProps<'cite', HTMLAttributes>;
|
| 82 |
+
code: HTMLProps<'code', HTMLAttributes>;
|
| 83 |
+
col: HTMLProps<'col', HTMLAttributes>;
|
| 84 |
+
colgroup: HTMLProps<'colgroup', HTMLAttributes>;
|
| 85 |
+
data: HTMLProps<'data', HTMLAttributes>;
|
| 86 |
+
datalist: HTMLProps<'datalist', HTMLAttributes>;
|
| 87 |
+
dd: HTMLProps<'dd', HTMLAttributes>;
|
| 88 |
+
del: HTMLProps<'del', HTMLAttributes>;
|
| 89 |
+
details: HTMLProps<'details', HTMLAttributes>;
|
| 90 |
+
dfn: HTMLProps<'dfn', HTMLAttributes>;
|
| 91 |
+
dialog: HTMLProps<'dialog', HTMLAttributes>;
|
| 92 |
+
div: HTMLProps<'div', HTMLAttributes>;
|
| 93 |
+
dl: HTMLProps<'dl', HTMLAttributes>;
|
| 94 |
+
dt: HTMLProps<'dt', HTMLAttributes>;
|
| 95 |
+
em: HTMLProps<'em', HTMLAttributes>;
|
| 96 |
+
embed: HTMLProps<'embed', HTMLAttributes>;
|
| 97 |
+
fieldset: HTMLProps<'fieldset', HTMLAttributes>;
|
| 98 |
+
figcaption: HTMLProps<'figcaption', HTMLAttributes>;
|
| 99 |
+
figure: HTMLProps<'figure', HTMLAttributes>;
|
| 100 |
+
footer: HTMLProps<'footer', HTMLAttributes>;
|
| 101 |
+
form: HTMLProps<'form', HTMLAttributes>;
|
| 102 |
+
h1: HTMLProps<'h1', HTMLAttributes>;
|
| 103 |
+
h2: HTMLProps<'h2', HTMLAttributes>;
|
| 104 |
+
h3: HTMLProps<'h3', HTMLAttributes>;
|
| 105 |
+
h4: HTMLProps<'h4', HTMLAttributes>;
|
| 106 |
+
h5: HTMLProps<'h5', HTMLAttributes>;
|
| 107 |
+
h6: HTMLProps<'h6', HTMLAttributes>;
|
| 108 |
+
head: HTMLProps<'head', HTMLAttributes>;
|
| 109 |
+
header: HTMLProps<'header', HTMLAttributes>;
|
| 110 |
+
hgroup: HTMLProps<'hgroup', HTMLAttributes>;
|
| 111 |
+
hr: HTMLProps<'hr', HTMLAttributes>;
|
| 112 |
+
html: HTMLProps<'html', HTMLAttributes>;
|
| 113 |
+
i: HTMLProps<'i', HTMLAttributes>;
|
| 114 |
+
iframe: HTMLProps<'iframe', HTMLAttributes>;
|
| 115 |
+
img: HTMLProps<'img', HTMLAttributes>;
|
| 116 |
+
input: HTMLProps<'input', HTMLAttributes>;
|
| 117 |
+
ins: HTMLProps<'ins', HTMLAttributes>;
|
| 118 |
+
kbd: HTMLProps<'kbd', HTMLAttributes>;
|
| 119 |
+
keygen: HTMLProps<'keygen', HTMLAttributes>;
|
| 120 |
+
label: HTMLProps<'label', HTMLAttributes>;
|
| 121 |
+
legend: HTMLProps<'legend', HTMLAttributes>;
|
| 122 |
+
li: HTMLProps<'li', HTMLAttributes>;
|
| 123 |
+
link: HTMLProps<'link', HTMLAttributes>;
|
| 124 |
+
main: HTMLProps<'main', HTMLAttributes>;
|
| 125 |
+
map: HTMLProps<'map', HTMLAttributes>;
|
| 126 |
+
mark: HTMLProps<'mark', HTMLAttributes>;
|
| 127 |
+
menu: HTMLProps<'menu', HTMLAttributes>;
|
| 128 |
+
menuitem: HTMLProps<'menuitem', HTMLAttributes>;
|
| 129 |
+
meta: HTMLProps<'meta', HTMLAttributes>;
|
| 130 |
+
meter: HTMLProps<'meter', HTMLAttributes>;
|
| 131 |
+
nav: HTMLProps<'nav', HTMLAttributes>;
|
| 132 |
+
noscript: HTMLProps<'noscript', HTMLAttributes>;
|
| 133 |
+
object: HTMLProps<'object', HTMLAttributes>;
|
| 134 |
+
ol: HTMLProps<'ol', HTMLAttributes>;
|
| 135 |
+
optgroup: HTMLProps<'optgroup', HTMLAttributes>;
|
| 136 |
+
option: HTMLProps<'option', HTMLAttributes>;
|
| 137 |
+
output: HTMLProps<'output', HTMLAttributes>;
|
| 138 |
+
p: HTMLProps<'p', HTMLAttributes>;
|
| 139 |
+
param: HTMLProps<'param', HTMLAttributes>;
|
| 140 |
+
picture: HTMLProps<'picture', HTMLAttributes>;
|
| 141 |
+
pre: HTMLProps<'pre', HTMLAttributes>;
|
| 142 |
+
progress: HTMLProps<'progress', HTMLAttributes>;
|
| 143 |
+
q: HTMLProps<'q', HTMLAttributes>;
|
| 144 |
+
rp: HTMLProps<'rp', HTMLAttributes>;
|
| 145 |
+
rt: HTMLProps<'rt', HTMLAttributes>;
|
| 146 |
+
ruby: HTMLProps<'ruby', HTMLAttributes>;
|
| 147 |
+
s: HTMLProps<'s', HTMLAttributes>;
|
| 148 |
+
samp: HTMLProps<'samp', HTMLAttributes>;
|
| 149 |
+
slot: HTMLProps<'slot', HTMLAttributes>;
|
| 150 |
+
script: HTMLProps<'script', HTMLAttributes>;
|
| 151 |
+
section: HTMLProps<'section', HTMLAttributes>;
|
| 152 |
+
select: HTMLProps<'select', HTMLAttributes>;
|
| 153 |
+
small: HTMLProps<'small', HTMLAttributes>;
|
| 154 |
+
source: HTMLProps<'source', HTMLAttributes>;
|
| 155 |
+
span: HTMLProps<'span', HTMLAttributes>;
|
| 156 |
+
strong: HTMLProps<'strong', HTMLAttributes>;
|
| 157 |
+
style: HTMLProps<'style', HTMLAttributes>;
|
| 158 |
+
sub: HTMLProps<'sub', HTMLAttributes>;
|
| 159 |
+
summary: HTMLProps<'summary', HTMLAttributes>;
|
| 160 |
+
sup: HTMLProps<'sup', HTMLAttributes>;
|
| 161 |
+
table: HTMLProps<'table', HTMLAttributes>;
|
| 162 |
+
template: HTMLProps<'template', HTMLAttributes>;
|
| 163 |
+
tbody: HTMLProps<'tbody', HTMLAttributes>;
|
| 164 |
+
td: HTMLProps<'td', HTMLAttributes>;
|
| 165 |
+
textarea: HTMLProps<'textarea', HTMLAttributes>;
|
| 166 |
+
tfoot: HTMLProps<'tfoot', HTMLAttributes>;
|
| 167 |
+
th: HTMLProps<'th', HTMLAttributes>;
|
| 168 |
+
thead: HTMLProps<'thead', HTMLAttributes>;
|
| 169 |
+
time: HTMLProps<'time', HTMLAttributes>;
|
| 170 |
+
title: HTMLProps<'title', HTMLAttributes>;
|
| 171 |
+
tr: HTMLProps<'tr', HTMLAttributes>;
|
| 172 |
+
track: HTMLProps<'track', HTMLAttributes>;
|
| 173 |
+
u: HTMLProps<'u', HTMLAttributes>;
|
| 174 |
+
ul: HTMLProps<'ul', HTMLAttributes>;
|
| 175 |
+
var: HTMLProps<'var', HTMLAttributes>;
|
| 176 |
+
video: HTMLProps<'video', HTMLAttributes>;
|
| 177 |
+
wbr: HTMLProps<'wbr', HTMLAttributes>;
|
| 178 |
+
webview: HTMLProps<'webview', HTMLAttributes>;
|
| 179 |
+
// SVG
|
| 180 |
+
svg: HTMLProps<'svg', SVGAttributes>;
|
| 181 |
+
|
| 182 |
+
animate: HTMLProps<'animate', SVGAttributes>;
|
| 183 |
+
animateMotion: HTMLProps<'animateMotion', SVGAttributes>;
|
| 184 |
+
animateTransform: HTMLProps<'animateTransform', SVGAttributes>;
|
| 185 |
+
circle: HTMLProps<'circle', SVGAttributes>;
|
| 186 |
+
clipPath: HTMLProps<'clipPath', SVGAttributes>;
|
| 187 |
+
defs: HTMLProps<'defs', SVGAttributes>;
|
| 188 |
+
desc: HTMLProps<'desc', SVGAttributes>;
|
| 189 |
+
ellipse: HTMLProps<'ellipse', SVGAttributes>;
|
| 190 |
+
feBlend: HTMLProps<'feBlend', SVGAttributes>;
|
| 191 |
+
feColorMatrix: HTMLProps<'feColorMatrix', SVGAttributes>;
|
| 192 |
+
feComponentTransfer: HTMLProps<'feComponentTransfer', SVGAttributes>;
|
| 193 |
+
feComposite: HTMLProps<'feComposite', SVGAttributes>;
|
| 194 |
+
feConvolveMatrix: HTMLProps<'feConvolveMatrix', SVGAttributes>;
|
| 195 |
+
feDiffuseLighting: HTMLProps<'feDiffuseLighting', SVGAttributes>;
|
| 196 |
+
feDisplacementMap: HTMLProps<'feDisplacementMap', SVGAttributes>;
|
| 197 |
+
feDistantLight: HTMLProps<'feDistantLight', SVGAttributes>;
|
| 198 |
+
feDropShadow: HTMLProps<'feDropShadow', SVGAttributes>;
|
| 199 |
+
feFlood: HTMLProps<'feFlood', SVGAttributes>;
|
| 200 |
+
feFuncA: HTMLProps<'feFuncA', SVGAttributes>;
|
| 201 |
+
feFuncB: HTMLProps<'feFuncB', SVGAttributes>;
|
| 202 |
+
feFuncG: HTMLProps<'feFuncG', SVGAttributes>;
|
| 203 |
+
feFuncR: HTMLProps<'feFuncR', SVGAttributes>;
|
| 204 |
+
feGaussianBlur: HTMLProps<'feGaussianBlur', SVGAttributes>;
|
| 205 |
+
feImage: HTMLProps<'feImage', SVGAttributes>;
|
| 206 |
+
feMerge: HTMLProps<'feMerge', SVGAttributes>;
|
| 207 |
+
feMergeNode: HTMLProps<'feMergeNode', SVGAttributes>;
|
| 208 |
+
feMorphology: HTMLProps<'feMorphology', SVGAttributes>;
|
| 209 |
+
feOffset: HTMLProps<'feOffset', SVGAttributes>;
|
| 210 |
+
fePointLight: HTMLProps<'fePointLight', SVGAttributes>;
|
| 211 |
+
feSpecularLighting: HTMLProps<'feSpecularLighting', SVGAttributes>;
|
| 212 |
+
feSpotLight: HTMLProps<'feSpotLight', SVGAttributes>;
|
| 213 |
+
feTile: HTMLProps<'feTile', SVGAttributes>;
|
| 214 |
+
feTurbulence: HTMLProps<'feTurbulence', SVGAttributes>;
|
| 215 |
+
filter: HTMLProps<'filter', SVGAttributes>;
|
| 216 |
+
foreignObject: HTMLProps<'foreignObject', SVGAttributes>;
|
| 217 |
+
g: HTMLProps<'g', SVGAttributes>;
|
| 218 |
+
image: HTMLProps<'image', SVGAttributes>;
|
| 219 |
+
line: HTMLProps<'line', SVGAttributes>;
|
| 220 |
+
linearGradient: HTMLProps<'linearGradient', SVGAttributes>;
|
| 221 |
+
marker: HTMLProps<'marker', SVGAttributes>;
|
| 222 |
+
mask: HTMLProps<'mask', SVGAttributes>;
|
| 223 |
+
metadata: HTMLProps<'metadata', SVGAttributes>;
|
| 224 |
+
mpath: HTMLProps<'mpath', SVGAttributes>;
|
| 225 |
+
path: HTMLProps<'path', SVGAttributes>;
|
| 226 |
+
pattern: HTMLProps<'pattern', SVGAttributes>;
|
| 227 |
+
polygon: HTMLProps<'polygon', SVGAttributes>;
|
| 228 |
+
polyline: HTMLProps<'polyline', SVGAttributes>;
|
| 229 |
+
radialGradient: HTMLProps<'radialGradient', SVGAttributes>;
|
| 230 |
+
rect: HTMLProps<'rect', SVGAttributes>;
|
| 231 |
+
stop: HTMLProps<'stop', SVGAttributes>;
|
| 232 |
+
switch: HTMLProps<'switch', SVGAttributes>;
|
| 233 |
+
symbol: HTMLProps<'symbol', SVGAttributes>;
|
| 234 |
+
text: HTMLProps<'text', SVGAttributes>;
|
| 235 |
+
textPath: HTMLProps<'textPath', SVGAttributes>;
|
| 236 |
+
tspan: HTMLProps<'tspan', SVGAttributes>;
|
| 237 |
+
use: HTMLProps<'use', SVGAttributes>;
|
| 238 |
+
view: HTMLProps<'view', SVGAttributes>;
|
| 239 |
+
|
| 240 |
+
// Svelte specific
|
| 241 |
+
'svelte:window': HTMLProps<'svelte:window', HTMLAttributes>;
|
| 242 |
+
'svelte:body': HTMLProps<'svelte:body', HTMLAttributes>;
|
| 243 |
+
'svelte:document': HTMLProps<'svelte:document', HTMLAttributes>;
|
| 244 |
+
'svelte:fragment': { slot?: string };
|
| 245 |
+
'svelte:options': { [name: string]: any };
|
| 246 |
+
'svelte:head': { [name: string]: any };
|
| 247 |
+
|
| 248 |
+
[name: string]: { [name: string]: any };
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
// Keep svelte.JSX for backwards compatibility, in case someone enhanced it with their own typings,
|
| 254 |
+
// which we can transform to the new svelteHTML namespace.
|
| 255 |
+
/**
|
| 256 |
+
* @deprecated use the types from `svelte/elements` instead, or the `svelteHTML` namespace.
|
| 257 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 258 |
+
*/
|
| 259 |
+
declare namespace svelte.JSX {
|
| 260 |
+
|
| 261 |
+
/* svelte specific */
|
| 262 |
+
interface ElementClass {
|
| 263 |
+
$$prop_def: any;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
interface ElementAttributesProperty {
|
| 267 |
+
$$prop_def: any; // specify the property name to use
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
/* html jsx */
|
| 271 |
+
|
| 272 |
+
interface IntrinsicAttributes {
|
| 273 |
+
slot?: string;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
//
|
| 277 |
+
// Event Handler Types
|
| 278 |
+
// ----------------------------------------------------------------------
|
| 279 |
+
type EventHandler<E extends Event = Event, T extends EventTarget = HTMLElement> =
|
| 280 |
+
(event: E & { currentTarget: EventTarget & T}) => any;
|
| 281 |
+
|
| 282 |
+
type ClipboardEventHandler<T extends EventTarget> = EventHandler<ClipboardEvent, T>;
|
| 283 |
+
type CompositionEventHandler<T extends EventTarget> = EventHandler<CompositionEvent, T>;
|
| 284 |
+
type DragEventHandler<T extends EventTarget> = EventHandler<DragEvent, T>;
|
| 285 |
+
type FocusEventHandler<T extends EventTarget> = EventHandler<FocusEvent, T>;
|
| 286 |
+
type FormEventHandler<T extends EventTarget> = EventHandler<Event, T>;
|
| 287 |
+
type ChangeEventHandler<T extends EventTarget> = EventHandler<Event, T>;
|
| 288 |
+
type KeyboardEventHandler<T extends EventTarget> = EventHandler<KeyboardEvent, T>;
|
| 289 |
+
type MouseEventHandler<T extends EventTarget> = EventHandler<MouseEvent, T>;
|
| 290 |
+
type TouchEventHandler<T extends EventTarget> = EventHandler<TouchEvent, T>;
|
| 291 |
+
type PointerEventHandler<T extends EventTarget> = EventHandler<PointerEvent, T>;
|
| 292 |
+
type UIEventHandler<T extends EventTarget> = EventHandler<UIEvent, T>;
|
| 293 |
+
type WheelEventHandler<T extends EventTarget> = EventHandler<WheelEvent, T>;
|
| 294 |
+
type AnimationEventHandler<T extends EventTarget> = EventHandler<AnimationEvent, T>;
|
| 295 |
+
type TransitionEventHandler<T extends EventTarget> = EventHandler<TransitionEvent, T>;
|
| 296 |
+
type MessageEventHandler<T extends EventTarget> = EventHandler<MessageEvent, T>;
|
| 297 |
+
|
| 298 |
+
/** @deprecated DO NOT USE, WILL BE REMOVED SOON */
|
| 299 |
+
type AttributeNames =
|
| 300 |
+
|'oncopy'
|
| 301 |
+
|'oncut'
|
| 302 |
+
|'onpaste'
|
| 303 |
+
|'oncompositionend'
|
| 304 |
+
|'oncompositionstart'
|
| 305 |
+
|'oncompositionupdate'
|
| 306 |
+
|'onfocus'
|
| 307 |
+
|'onfocusin'
|
| 308 |
+
|'onfocusout'
|
| 309 |
+
|'onblur'
|
| 310 |
+
|'onchange'
|
| 311 |
+
|'oninput'
|
| 312 |
+
|'onreset'
|
| 313 |
+
|'onsubmit'
|
| 314 |
+
|'oninvalid'
|
| 315 |
+
|'onbeforeinput'
|
| 316 |
+
|'onload'
|
| 317 |
+
|'onerror'
|
| 318 |
+
|'ontoggle'
|
| 319 |
+
|'onkeydown'
|
| 320 |
+
|'onkeypress'
|
| 321 |
+
|'onkeyup'
|
| 322 |
+
|'onabort'
|
| 323 |
+
|'oncanplay'
|
| 324 |
+
|'oncanplaythrough'
|
| 325 |
+
|'oncuechange'
|
| 326 |
+
|'ondurationchange'
|
| 327 |
+
|'onemptied'
|
| 328 |
+
|'onencrypted'
|
| 329 |
+
|'onended'
|
| 330 |
+
|'onloadeddata'
|
| 331 |
+
|'onloadedmetadata'
|
| 332 |
+
|'onloadstart'
|
| 333 |
+
|'onpause'
|
| 334 |
+
|'onplay'
|
| 335 |
+
|'onplaying'
|
| 336 |
+
|'onprogress'
|
| 337 |
+
|'onratechange'
|
| 338 |
+
|'onseeked'
|
| 339 |
+
|'onseeking'
|
| 340 |
+
|'onstalled'
|
| 341 |
+
|'onsuspend'
|
| 342 |
+
|'ontimeupdate'
|
| 343 |
+
|'onvolumechange'
|
| 344 |
+
|'onwaiting'
|
| 345 |
+
|'onauxclick'
|
| 346 |
+
|'onclick'
|
| 347 |
+
|'oncontextmenu'
|
| 348 |
+
|'ondblclick'
|
| 349 |
+
|'ondrag'
|
| 350 |
+
|'ondragend'
|
| 351 |
+
|'ondragenter'
|
| 352 |
+
|'ondragexit'
|
| 353 |
+
|'ondragleave'
|
| 354 |
+
|'ondragover'
|
| 355 |
+
|'ondragstart'
|
| 356 |
+
|'ondrop'
|
| 357 |
+
|'onmousedown'
|
| 358 |
+
|'onmouseenter'
|
| 359 |
+
|'onmouseleave'
|
| 360 |
+
|'onmousemove'
|
| 361 |
+
|'onmouseout'
|
| 362 |
+
|'onmouseover'
|
| 363 |
+
|'onmouseup'
|
| 364 |
+
|'onselect'
|
| 365 |
+
|'onselectionchange'
|
| 366 |
+
|'onselectstart'
|
| 367 |
+
|'ontouchcancel'
|
| 368 |
+
|'ontouchend'
|
| 369 |
+
|'ontouchmove'
|
| 370 |
+
|'ontouchstart'
|
| 371 |
+
|'ongotpointercapture'
|
| 372 |
+
|'onpointercancel'
|
| 373 |
+
|'onpointerdown'
|
| 374 |
+
|'onpointerenter'
|
| 375 |
+
|'onpointerleave'
|
| 376 |
+
|'onpointermove'
|
| 377 |
+
|'onpointerout'
|
| 378 |
+
|'onpointerover'
|
| 379 |
+
|'onpointerup'
|
| 380 |
+
|'onlostpointercapture'
|
| 381 |
+
|'onscroll'
|
| 382 |
+
|'onresize'
|
| 383 |
+
|'onwheel'
|
| 384 |
+
|'onanimationstart'
|
| 385 |
+
|'onanimationend'
|
| 386 |
+
|'onanimationiteration'
|
| 387 |
+
|'ontransitionstart'
|
| 388 |
+
|'ontransitionrun'
|
| 389 |
+
|'ontransitionend'
|
| 390 |
+
|'ontransitioncancel'
|
| 391 |
+
|'onoutrostart'
|
| 392 |
+
|'onoutroend'
|
| 393 |
+
|'onintrostart'
|
| 394 |
+
|'onintroend'
|
| 395 |
+
|'onmessage'
|
| 396 |
+
|'onmessageerror'
|
| 397 |
+
|'oncancel'
|
| 398 |
+
|'onclose'
|
| 399 |
+
|'onfullscreenchange'
|
| 400 |
+
|'onfullscreenerror'
|
| 401 |
+
|'class'
|
| 402 |
+
|'dataset'
|
| 403 |
+
|'accept'
|
| 404 |
+
|'acceptcharset'
|
| 405 |
+
|'accesskey'
|
| 406 |
+
|'action'
|
| 407 |
+
|'allow'
|
| 408 |
+
|'allowfullscreen'
|
| 409 |
+
|'allowtransparency'
|
| 410 |
+
|'allowpaymentrequest'
|
| 411 |
+
|'alt'
|
| 412 |
+
|'as'
|
| 413 |
+
|'async'
|
| 414 |
+
|'autocomplete'
|
| 415 |
+
|'autofocus'
|
| 416 |
+
|'autoplay'
|
| 417 |
+
|'capture'
|
| 418 |
+
|'cellpadding'
|
| 419 |
+
|'cellspacing'
|
| 420 |
+
|'charset'
|
| 421 |
+
|'challenge'
|
| 422 |
+
|'checked'
|
| 423 |
+
|'cite'
|
| 424 |
+
|'classid'
|
| 425 |
+
|'cols'
|
| 426 |
+
|'colspan'
|
| 427 |
+
|'content'
|
| 428 |
+
|'contenteditable'
|
| 429 |
+
|'innerHTML'
|
| 430 |
+
|'textContent'
|
| 431 |
+
|'contextmenu'
|
| 432 |
+
|'controls'
|
| 433 |
+
|'coords'
|
| 434 |
+
|'crossorigin'
|
| 435 |
+
|'currenttime'
|
| 436 |
+
|'decoding'
|
| 437 |
+
|'data'
|
| 438 |
+
|'datetime'
|
| 439 |
+
|'default'
|
| 440 |
+
|'defaultmuted'
|
| 441 |
+
|'defaultplaybackrate'
|
| 442 |
+
|'defer'
|
| 443 |
+
|'dir'
|
| 444 |
+
|'dirname'
|
| 445 |
+
|'disabled'
|
| 446 |
+
|'download'
|
| 447 |
+
|'draggable'
|
| 448 |
+
|'enctype'
|
| 449 |
+
|'enterkeyhint'
|
| 450 |
+
|'for'
|
| 451 |
+
|'form'
|
| 452 |
+
|'formaction'
|
| 453 |
+
|'formenctype'
|
| 454 |
+
|'formmethod'
|
| 455 |
+
|'formnovalidate'
|
| 456 |
+
|'formtarget'
|
| 457 |
+
|'frameborder'
|
| 458 |
+
|'headers'
|
| 459 |
+
|'height'
|
| 460 |
+
|'hidden'
|
| 461 |
+
|'high'
|
| 462 |
+
|'href'
|
| 463 |
+
|'hreflang'
|
| 464 |
+
|'htmlfor'
|
| 465 |
+
|'httpequiv'
|
| 466 |
+
|'id'
|
| 467 |
+
|'inputmode'
|
| 468 |
+
|'integrity'
|
| 469 |
+
|'is'
|
| 470 |
+
|'ismap'
|
| 471 |
+
|'keyparams'
|
| 472 |
+
|'keytype'
|
| 473 |
+
|'kind'
|
| 474 |
+
|'label'
|
| 475 |
+
|'lang'
|
| 476 |
+
|'list'
|
| 477 |
+
|'loading'
|
| 478 |
+
|'loop'
|
| 479 |
+
|'low'
|
| 480 |
+
|'manifest'
|
| 481 |
+
|'marginheight'
|
| 482 |
+
|'marginwidth'
|
| 483 |
+
|'max'
|
| 484 |
+
|'maxlength'
|
| 485 |
+
|'media'
|
| 486 |
+
|'mediagroup'
|
| 487 |
+
|'method'
|
| 488 |
+
|'min'
|
| 489 |
+
|'minlength'
|
| 490 |
+
|'multiple'
|
| 491 |
+
|'muted'
|
| 492 |
+
|'name'
|
| 493 |
+
|'nonce'
|
| 494 |
+
|'novalidate'
|
| 495 |
+
|'open'
|
| 496 |
+
|'optimum'
|
| 497 |
+
|'part'
|
| 498 |
+
|'pattern'
|
| 499 |
+
|'placeholder'
|
| 500 |
+
|'playsinline'
|
| 501 |
+
|'ping'
|
| 502 |
+
|'poster'
|
| 503 |
+
|'preload'
|
| 504 |
+
|'radiogroup'
|
| 505 |
+
|'readonly'
|
| 506 |
+
|'referrerpolicy'
|
| 507 |
+
|'rel'
|
| 508 |
+
|'required'
|
| 509 |
+
|'reversed'
|
| 510 |
+
|'role'
|
| 511 |
+
|'rows'
|
| 512 |
+
|'rowspan'
|
| 513 |
+
|'sandbox'
|
| 514 |
+
|'scope'
|
| 515 |
+
|'scoped'
|
| 516 |
+
|'scrolling'
|
| 517 |
+
|'seamless'
|
| 518 |
+
|'selected'
|
| 519 |
+
|'shape'
|
| 520 |
+
|'size'
|
| 521 |
+
|'sizes'
|
| 522 |
+
|'slot'
|
| 523 |
+
|'span'
|
| 524 |
+
|'spellcheck'
|
| 525 |
+
|'src'
|
| 526 |
+
|'srcdoc'
|
| 527 |
+
|'srclang'
|
| 528 |
+
|'srcset'
|
| 529 |
+
|'start'
|
| 530 |
+
|'step'
|
| 531 |
+
|'style'
|
| 532 |
+
|'summary'
|
| 533 |
+
|'tabindex'
|
| 534 |
+
|'target'
|
| 535 |
+
|'title'
|
| 536 |
+
|'translate'
|
| 537 |
+
|'type'
|
| 538 |
+
|'usemap'
|
| 539 |
+
|'value'
|
| 540 |
+
|'volume'
|
| 541 |
+
|'width'
|
| 542 |
+
|'wmode'
|
| 543 |
+
|'wrap'
|
| 544 |
+
|'about'
|
| 545 |
+
|'datatype'
|
| 546 |
+
|'inlist'
|
| 547 |
+
|'prefix'
|
| 548 |
+
|'property'
|
| 549 |
+
|'resource'
|
| 550 |
+
|'typeof'
|
| 551 |
+
|'vocab'
|
| 552 |
+
|'autocapitalize'
|
| 553 |
+
|'autocorrect'
|
| 554 |
+
|'autosave'
|
| 555 |
+
|'color'
|
| 556 |
+
|'controlslist'
|
| 557 |
+
|'inert'
|
| 558 |
+
|'itemprop'
|
| 559 |
+
|'itemscope'
|
| 560 |
+
|'itemtype'
|
| 561 |
+
|'itemid'
|
| 562 |
+
|'itemref'
|
| 563 |
+
|'results'
|
| 564 |
+
|'security'
|
| 565 |
+
|'unselectable';
|
| 566 |
+
|
| 567 |
+
/**
|
| 568 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 569 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 570 |
+
*/
|
| 571 |
+
interface DOMAttributes<T extends EventTarget> {
|
| 572 |
+
oncopy?: ClipboardEventHandler<T> | undefined | null;
|
| 573 |
+
oncut?: ClipboardEventHandler<T> | undefined | null;
|
| 574 |
+
onpaste?: ClipboardEventHandler<T> | undefined | null;
|
| 575 |
+
oncompositionend?: CompositionEventHandler<T> | undefined | null;
|
| 576 |
+
oncompositionstart?: CompositionEventHandler<T> | undefined | null;
|
| 577 |
+
oncompositionupdate?: CompositionEventHandler<T> | undefined | null;
|
| 578 |
+
onfocus?: FocusEventHandler<T> | undefined | null;
|
| 579 |
+
onfocusin?: FocusEventHandler<T> | undefined | null;
|
| 580 |
+
onfocusout?: FocusEventHandler<T> | undefined | null;
|
| 581 |
+
onblur?: FocusEventHandler<T> | undefined | null;
|
| 582 |
+
onchange?: FormEventHandler<T> | undefined | null;
|
| 583 |
+
oninput?: FormEventHandler<T> | undefined | null;
|
| 584 |
+
onreset?: FormEventHandler<T> | undefined | null;
|
| 585 |
+
onsubmit?: EventHandler<SubmitEvent, T> | undefined | null;
|
| 586 |
+
oninvalid?: EventHandler<Event, T> | undefined | null;
|
| 587 |
+
onbeforeinput?: EventHandler<InputEvent, T> | undefined | null;
|
| 588 |
+
onload?: EventHandler | undefined | null;
|
| 589 |
+
onerror?: EventHandler | undefined | null; // also a Media Event
|
| 590 |
+
ontoggle?: EventHandler<Event, T> | undefined | null;
|
| 591 |
+
onkeydown?: KeyboardEventHandler<T> | undefined | null;
|
| 592 |
+
onkeypress?: KeyboardEventHandler<T> | undefined | null;
|
| 593 |
+
onkeyup?: KeyboardEventHandler<T> | undefined | null;
|
| 594 |
+
onabort?: EventHandler<Event, T> | undefined | null;
|
| 595 |
+
oncanplay?: EventHandler<Event, T> | undefined | null;
|
| 596 |
+
oncanplaythrough?: EventHandler<Event, T> | undefined | null;
|
| 597 |
+
oncuechange?: EventHandler<Event, T> | undefined | null;
|
| 598 |
+
ondurationchange?: EventHandler<Event, T> | undefined | null;
|
| 599 |
+
onemptied?: EventHandler<Event, T> | undefined | null;
|
| 600 |
+
onencrypted?: EventHandler<Event, T> | undefined | null;
|
| 601 |
+
onended?: EventHandler<Event, T> | undefined | null;
|
| 602 |
+
onloadeddata?: EventHandler<Event, T> | undefined | null;
|
| 603 |
+
onloadedmetadata?: EventHandler<Event, T> | undefined | null;
|
| 604 |
+
onloadstart?: EventHandler<Event, T> | undefined | null;
|
| 605 |
+
onpause?: EventHandler<Event, T> | undefined | null;
|
| 606 |
+
onplay?: EventHandler<Event, T> | undefined | null;
|
| 607 |
+
onplaying?: EventHandler<Event, T> | undefined | null;
|
| 608 |
+
onprogress?: EventHandler<Event, T> | undefined | null;
|
| 609 |
+
onratechange?: EventHandler<Event, T> | undefined | null;
|
| 610 |
+
onseeked?: EventHandler<Event, T> | undefined | null;
|
| 611 |
+
onseeking?: EventHandler<Event, T> | undefined | null;
|
| 612 |
+
onstalled?: EventHandler<Event, T> | undefined | null;
|
| 613 |
+
onsuspend?: EventHandler<Event, T> | undefined | null;
|
| 614 |
+
ontimeupdate?: EventHandler<Event, T> | undefined | null;
|
| 615 |
+
onvolumechange?: EventHandler<Event, T> | undefined | null;
|
| 616 |
+
onwaiting?: EventHandler<Event, T> | undefined | null;
|
| 617 |
+
onauxclick?: MouseEventHandler<T> | undefined | null;
|
| 618 |
+
onclick?: MouseEventHandler<T> | undefined | null;
|
| 619 |
+
oncontextmenu?: MouseEventHandler<T> | undefined | null;
|
| 620 |
+
ondblclick?: MouseEventHandler<T> | undefined | null;
|
| 621 |
+
ondrag?: DragEventHandler<T> | undefined | null;
|
| 622 |
+
ondragend?: DragEventHandler<T> | undefined | null;
|
| 623 |
+
ondragenter?: DragEventHandler<T> | undefined | null;
|
| 624 |
+
ondragexit?: DragEventHandler<T> | undefined | null;
|
| 625 |
+
ondragleave?: DragEventHandler<T> | undefined | null;
|
| 626 |
+
ondragover?: DragEventHandler<T> | undefined | null;
|
| 627 |
+
ondragstart?: DragEventHandler<T> | undefined | null;
|
| 628 |
+
ondrop?: DragEventHandler<T> | undefined | null;
|
| 629 |
+
onmousedown?: MouseEventHandler<T> | undefined | null;
|
| 630 |
+
onmouseenter?: MouseEventHandler<T> | undefined | null;
|
| 631 |
+
onmouseleave?: MouseEventHandler<T> | undefined | null;
|
| 632 |
+
onmousemove?: MouseEventHandler<T> | undefined | null;
|
| 633 |
+
onmouseout?: MouseEventHandler<T> | undefined | null;
|
| 634 |
+
onmouseover?: MouseEventHandler<T> | undefined | null;
|
| 635 |
+
onmouseup?: MouseEventHandler<T> | undefined | null;
|
| 636 |
+
onselect?: EventHandler<Event, T> | undefined | null;
|
| 637 |
+
onselectionchange?: EventHandler<Event, T> | undefined | null;
|
| 638 |
+
onselectstart?: EventHandler<Event, T> | undefined | null;
|
| 639 |
+
ontouchcancel?: TouchEventHandler<T> | undefined | null;
|
| 640 |
+
ontouchend?: TouchEventHandler<T> | undefined | null;
|
| 641 |
+
ontouchmove?: TouchEventHandler<T> | undefined | null;
|
| 642 |
+
ontouchstart?: TouchEventHandler<T> | undefined | null;
|
| 643 |
+
ongotpointercapture?: PointerEventHandler<T> | undefined | null;
|
| 644 |
+
onpointercancel?: PointerEventHandler<T> | undefined | null;
|
| 645 |
+
onpointerdown?: PointerEventHandler<T> | undefined | null;
|
| 646 |
+
onpointerenter?: PointerEventHandler<T> | undefined | null;
|
| 647 |
+
onpointerleave?: PointerEventHandler<T> | undefined | null;
|
| 648 |
+
onpointermove?: PointerEventHandler<T> | undefined | null;
|
| 649 |
+
onpointerout?: PointerEventHandler<T> | undefined | null;
|
| 650 |
+
onpointerover?: PointerEventHandler<T> | undefined | null;
|
| 651 |
+
onpointerup?: PointerEventHandler<T> | undefined | null;
|
| 652 |
+
onlostpointercapture?: PointerEventHandler<T> | undefined | null;
|
| 653 |
+
onscroll?: UIEventHandler<T> | undefined | null;
|
| 654 |
+
onresize?: UIEventHandler<T> | undefined | null;
|
| 655 |
+
onwheel?: WheelEventHandler<T> | undefined | null;
|
| 656 |
+
onanimationstart?: AnimationEventHandler<T> | undefined | null;
|
| 657 |
+
onanimationend?: AnimationEventHandler<T> | undefined | null;
|
| 658 |
+
onanimationiteration?: AnimationEventHandler<T> | undefined | null;
|
| 659 |
+
ontransitionstart?: TransitionEventHandler<T> | undefined | null;
|
| 660 |
+
ontransitionrun?: TransitionEventHandler<T> | undefined | null;
|
| 661 |
+
ontransitionend?: TransitionEventHandler<T> | undefined | null;
|
| 662 |
+
ontransitioncancel?: TransitionEventHandler<T> | undefined | null;
|
| 663 |
+
onoutrostart?: EventHandler<CustomEvent<null>, T> | undefined | null;
|
| 664 |
+
onoutroend?: EventHandler<CustomEvent<null>, T> | undefined | null;
|
| 665 |
+
onintrostart?: EventHandler<CustomEvent<null>, T> | undefined | null;
|
| 666 |
+
onintroend?: EventHandler<CustomEvent<null>, T> | undefined | null;
|
| 667 |
+
onmessage?: MessageEventHandler<T> | undefined | null;
|
| 668 |
+
onmessageerror?: MessageEventHandler<T> | undefined | null;
|
| 669 |
+
oncancel?: EventHandler<Event, T> | undefined | null;
|
| 670 |
+
onclose?: EventHandler<Event, T> | undefined | null;
|
| 671 |
+
onfullscreenchange?: EventHandler<Event, T> | undefined | null;
|
| 672 |
+
onfullscreenerror?: EventHandler<Event, T> | undefined | null;
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
/**
|
| 676 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 677 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 678 |
+
*/
|
| 679 |
+
interface AriaAttributes {
|
| 680 |
+
'aria-activedescendant'?: string | undefined | null;
|
| 681 |
+
'aria-atomic'?: boolean | 'false' | 'true' | undefined | null;
|
| 682 |
+
'aria-autocomplete'?: 'none' | 'inline' | 'list' | 'both' | undefined | null;
|
| 683 |
+
'aria-busy'?: boolean | 'false' | 'true' | undefined | null;
|
| 684 |
+
'aria-checked'?: boolean | 'false' | 'mixed' | 'true' | undefined | null;
|
| 685 |
+
'aria-colcount'?: number | undefined | null;
|
| 686 |
+
'aria-colindex'?: number | undefined | null;
|
| 687 |
+
'aria-colspan'?: number | undefined | null;
|
| 688 |
+
'aria-controls'?: string | undefined | null;
|
| 689 |
+
'aria-current'?: boolean | 'false' | 'true' | 'page' | 'step' | 'location' | 'date' | 'time' | undefined | null;
|
| 690 |
+
'aria-describedby'?: string | undefined | null;
|
| 691 |
+
'aria-details'?: string | undefined | null;
|
| 692 |
+
'aria-disabled'?: boolean | 'false' | 'true' | undefined | null;
|
| 693 |
+
'aria-dropeffect'?: 'none' | 'copy' | 'execute' | 'link' | 'move' | 'popup' | undefined | null;
|
| 694 |
+
'aria-errormessage'?: string | undefined | null;
|
| 695 |
+
'aria-expanded'?: boolean | 'false' | 'true' | undefined | null;
|
| 696 |
+
'aria-flowto'?: string | undefined | null;
|
| 697 |
+
'aria-grabbed'?: boolean | 'false' | 'true' | undefined | null;
|
| 698 |
+
'aria-haspopup'?: boolean | 'false' | 'true' | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog' | undefined | null;
|
| 699 |
+
'aria-hidden'?: boolean | 'false' | 'true' | undefined | null;
|
| 700 |
+
'aria-invalid'?: boolean | 'false' | 'true' | 'grammar' | 'spelling' | undefined | null;
|
| 701 |
+
'aria-keyshortcuts'?: string | undefined | null;
|
| 702 |
+
'aria-label'?: string | undefined | null;
|
| 703 |
+
'aria-labelledby'?: string | undefined | null;
|
| 704 |
+
'aria-level'?: number | undefined | null;
|
| 705 |
+
'aria-live'?: 'off' | 'assertive' | 'polite' | undefined | null;
|
| 706 |
+
'aria-modal'?: boolean | 'false' | 'true' | undefined | null;
|
| 707 |
+
'aria-multiline'?: boolean | 'false' | 'true' | undefined | null;
|
| 708 |
+
'aria-multiselectable'?: boolean | 'false' | 'true' | undefined | null;
|
| 709 |
+
'aria-orientation'?: 'horizontal' | 'vertical' | undefined | null;
|
| 710 |
+
'aria-owns'?: string | undefined | null;
|
| 711 |
+
'aria-placeholder'?: string | undefined | null;
|
| 712 |
+
'aria-posinset'?: number | undefined | null;
|
| 713 |
+
'aria-pressed'?: boolean | 'false' | 'mixed' | 'true' | undefined | null;
|
| 714 |
+
'aria-readonly'?: boolean | 'false' | 'true' | undefined | null;
|
| 715 |
+
'aria-relevant'?: 'additions' | 'additions removals' | 'additions text' | 'all' | 'removals' | 'removals additions' | 'removals text' | 'text' | 'text additions' | 'text removals' | undefined | null;
|
| 716 |
+
'aria-required'?: boolean | 'false' | 'true' | undefined | null;
|
| 717 |
+
'aria-roledescription'?: string | undefined | null;
|
| 718 |
+
'aria-rowcount'?: number | undefined | null;
|
| 719 |
+
'aria-rowindex'?: number | undefined | null;
|
| 720 |
+
'aria-rowspan'?: number | undefined | null;
|
| 721 |
+
'aria-selected'?: boolean | 'false' | 'true' | undefined | null;
|
| 722 |
+
'aria-setsize'?: number | undefined | null;
|
| 723 |
+
'aria-sort'?: 'none' | 'ascending' | 'descending' | 'other' | undefined | null;
|
| 724 |
+
'aria-valuemax'?: number | undefined | null;
|
| 725 |
+
'aria-valuemin'?: number | undefined | null;
|
| 726 |
+
'aria-valuenow'?: number | undefined | null;
|
| 727 |
+
'aria-valuetext'?: string | undefined | null;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
/**
|
| 731 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 732 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 733 |
+
*/
|
| 734 |
+
interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, DOMAttributes<T> {
|
| 735 |
+
class?: string | undefined | null;
|
| 736 |
+
dataset?: object | undefined | null;
|
| 737 |
+
accept?: string | undefined | null;
|
| 738 |
+
acceptcharset?: string | undefined | null;
|
| 739 |
+
accesskey?: string | undefined | null;
|
| 740 |
+
action?: string | undefined | null;
|
| 741 |
+
allow?: string | undefined | null;
|
| 742 |
+
allowfullscreen?: boolean | undefined | null;
|
| 743 |
+
allowtransparency?: boolean | undefined | null;
|
| 744 |
+
allowpaymentrequest?: boolean | undefined | null;
|
| 745 |
+
alt?: string | undefined | null;
|
| 746 |
+
as?: string | undefined | null;
|
| 747 |
+
async?: boolean | undefined | null;
|
| 748 |
+
autocomplete?: string | undefined | null;
|
| 749 |
+
autofocus?: boolean | undefined | null;
|
| 750 |
+
autoplay?: boolean | undefined | null;
|
| 751 |
+
capture?: 'environment' | 'user' | boolean | undefined | null;
|
| 752 |
+
cellpadding?: number | string | undefined | null;
|
| 753 |
+
cellspacing?: number | string | undefined | null;
|
| 754 |
+
charset?: string | undefined | null;
|
| 755 |
+
challenge?: string | undefined | null;
|
| 756 |
+
checked?: boolean | undefined | null;
|
| 757 |
+
cite?: string | undefined | null;
|
| 758 |
+
classid?: string | undefined | null;
|
| 759 |
+
cols?: number | undefined | null;
|
| 760 |
+
colspan?: number | undefined | null;
|
| 761 |
+
content?: string | undefined | null;
|
| 762 |
+
contenteditable?: 'true' | 'false' | boolean | undefined | null;
|
| 763 |
+
innerHTML?: string | undefined | null;
|
| 764 |
+
textContent?: string | undefined | null;
|
| 765 |
+
contextmenu?: string | undefined | null;
|
| 766 |
+
controls?: boolean | undefined | null;
|
| 767 |
+
coords?: string | undefined | null;
|
| 768 |
+
crossorigin?: string | undefined | null;
|
| 769 |
+
currenttime?: number | undefined | null;
|
| 770 |
+
decoding?: 'async' | 'sync' | 'auto' | undefined | null;
|
| 771 |
+
data?: string | undefined | null;
|
| 772 |
+
datetime?: string | undefined | null;
|
| 773 |
+
default?: boolean | undefined | null;
|
| 774 |
+
defaultmuted?: boolean | undefined | null;
|
| 775 |
+
defaultplaybackrate?: number | undefined | null;
|
| 776 |
+
defer?: boolean | undefined | null;
|
| 777 |
+
dir?: string | undefined | null;
|
| 778 |
+
dirname?: string | undefined | null;
|
| 779 |
+
disabled?: boolean | undefined | null;
|
| 780 |
+
download?: any | undefined | null;
|
| 781 |
+
draggable?: boolean | 'true' | 'false' | undefined | null;
|
| 782 |
+
enctype?: string | undefined | null;
|
| 783 |
+
enterkeyhint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' | undefined | null;
|
| 784 |
+
for?: string | undefined | null;
|
| 785 |
+
form?: string | undefined | null;
|
| 786 |
+
formaction?: string | undefined | null;
|
| 787 |
+
formenctype?: string | undefined | null;
|
| 788 |
+
formmethod?: string | undefined | null;
|
| 789 |
+
formnovalidate?: boolean | undefined | null;
|
| 790 |
+
formtarget?: string | undefined | null;
|
| 791 |
+
frameborder?: number | string | undefined | null;
|
| 792 |
+
headers?: string | undefined | null;
|
| 793 |
+
height?: number | string | undefined | null;
|
| 794 |
+
hidden?: boolean | undefined | null;
|
| 795 |
+
high?: number | undefined | null;
|
| 796 |
+
href?: string | undefined | null;
|
| 797 |
+
hreflang?: string | undefined | null;
|
| 798 |
+
htmlfor?: string | undefined | null;
|
| 799 |
+
httpequiv?: string | undefined | null;
|
| 800 |
+
id?: string | undefined | null;
|
| 801 |
+
inputmode?: string | undefined | null;
|
| 802 |
+
integrity?: string | undefined | null;
|
| 803 |
+
is?: string | undefined | null;
|
| 804 |
+
ismap?: boolean | undefined | null;
|
| 805 |
+
keyparams?: string | undefined | null;
|
| 806 |
+
keytype?: string | undefined | null;
|
| 807 |
+
kind?: string | undefined | null;
|
| 808 |
+
label?: string | undefined | null;
|
| 809 |
+
lang?: string | undefined | null;
|
| 810 |
+
list?: string | undefined | null;
|
| 811 |
+
loading?: string | undefined | null;
|
| 812 |
+
loop?: boolean | undefined | null;
|
| 813 |
+
low?: number | undefined | null;
|
| 814 |
+
manifest?: string | undefined | null;
|
| 815 |
+
marginheight?: number | undefined | null;
|
| 816 |
+
marginwidth?: number | undefined | null;
|
| 817 |
+
max?: number | string | undefined | null;
|
| 818 |
+
maxlength?: number | undefined | null;
|
| 819 |
+
media?: string | undefined | null;
|
| 820 |
+
mediagroup?: string | undefined | null;
|
| 821 |
+
method?: string | undefined | null;
|
| 822 |
+
min?: number | string | undefined | null;
|
| 823 |
+
minlength?: number | undefined | null;
|
| 824 |
+
multiple?: boolean | undefined | null;
|
| 825 |
+
muted?: boolean | undefined | null;
|
| 826 |
+
name?: string | undefined | null;
|
| 827 |
+
nonce?: string | undefined | null;
|
| 828 |
+
novalidate?: boolean | undefined | null;
|
| 829 |
+
open?: boolean | undefined | null;
|
| 830 |
+
optimum?: number | undefined | null;
|
| 831 |
+
part?: string | undefined | null;
|
| 832 |
+
pattern?: string | undefined | null;
|
| 833 |
+
placeholder?: string | undefined | null;
|
| 834 |
+
playsinline?: boolean | undefined | null;
|
| 835 |
+
ping?: string | undefined | null;
|
| 836 |
+
poster?: string | undefined | null;
|
| 837 |
+
preload?: string | undefined | null;
|
| 838 |
+
radiogroup?: string | undefined | null;
|
| 839 |
+
readonly?: boolean | undefined | null;
|
| 840 |
+
referrerpolicy?: string | undefined | null;
|
| 841 |
+
rel?: string | undefined | null;
|
| 842 |
+
required?: boolean | undefined | null;
|
| 843 |
+
reversed?: boolean | undefined | null;
|
| 844 |
+
role?: string | undefined | null;
|
| 845 |
+
rows?: number | undefined | null;
|
| 846 |
+
rowspan?: number | undefined | null;
|
| 847 |
+
sandbox?: string | undefined | null;
|
| 848 |
+
scope?: string | undefined | null;
|
| 849 |
+
scoped?: boolean | undefined | null;
|
| 850 |
+
scrolling?: string | undefined | null;
|
| 851 |
+
seamless?: boolean | undefined | null;
|
| 852 |
+
selected?: boolean | undefined | null;
|
| 853 |
+
shape?: string | undefined | null;
|
| 854 |
+
size?: number | undefined | null;
|
| 855 |
+
sizes?: string | undefined | null;
|
| 856 |
+
slot?: string | undefined | null;
|
| 857 |
+
span?: number | undefined | null;
|
| 858 |
+
spellcheck?: boolean | 'true' | 'false' | undefined | null;
|
| 859 |
+
src?: string | undefined | null;
|
| 860 |
+
srcdoc?: string | undefined | null;
|
| 861 |
+
srclang?: string | undefined | null;
|
| 862 |
+
srcset?: string | undefined | null;
|
| 863 |
+
start?: number | undefined | null;
|
| 864 |
+
step?: number | string | undefined | null;
|
| 865 |
+
style?: string | undefined | null;
|
| 866 |
+
summary?: string | undefined | null;
|
| 867 |
+
tabindex?: number | undefined | null;
|
| 868 |
+
target?: string | undefined | null;
|
| 869 |
+
title?: string | undefined | null;
|
| 870 |
+
translate?: "yes" | "no" | "" | undefined | null;
|
| 871 |
+
type?: string | undefined | null;
|
| 872 |
+
usemap?: string | undefined | null;
|
| 873 |
+
value?: any | undefined | null;
|
| 874 |
+
volume?: number | undefined | null;
|
| 875 |
+
width?: number | string | undefined | null;
|
| 876 |
+
wmode?: string | undefined | null;
|
| 877 |
+
wrap?: string | undefined | null;
|
| 878 |
+
about?: string | undefined | null;
|
| 879 |
+
datatype?: string | undefined | null;
|
| 880 |
+
inlist?: any | undefined | null;
|
| 881 |
+
prefix?: string | undefined | null;
|
| 882 |
+
property?: string | undefined | null;
|
| 883 |
+
resource?: string | undefined | null;
|
| 884 |
+
typeof?: string | undefined | null;
|
| 885 |
+
vocab?: string | undefined | null;
|
| 886 |
+
autocapitalize?: string | undefined | null;
|
| 887 |
+
autocorrect?: string | undefined | null;
|
| 888 |
+
autosave?: string | undefined | null;
|
| 889 |
+
color?: string | undefined | null;
|
| 890 |
+
controlslist?: 'nodownload' | 'nofullscreen' | 'noplaybackrate' | 'noremoteplayback';
|
| 891 |
+
inert?: boolean | undefined | null;
|
| 892 |
+
itemprop?: string | undefined | null;
|
| 893 |
+
itemscope?: boolean | undefined | null;
|
| 894 |
+
itemtype?: string | undefined | null;
|
| 895 |
+
itemid?: string | undefined | null;
|
| 896 |
+
itemref?: string | undefined | null;
|
| 897 |
+
results?: number | undefined | null;
|
| 898 |
+
security?: string | undefined | null;
|
| 899 |
+
unselectable?: boolean | undefined | null;
|
| 900 |
+
|
| 901 |
+
'data-sveltekit-keepfocus'?: true | '' | 'off' | undefined | null;
|
| 902 |
+
'data-sveltekit-noscroll'?: true | '' | 'off' | undefined | null;
|
| 903 |
+
'data-sveltekit-preload-code'?: true | '' | 'eager' | 'viewport' | 'hover' | 'tap' | 'off' | undefined | null;
|
| 904 |
+
'data-sveltekit-preload-data'?: true | '' | 'hover' | 'tap' | 'off' | undefined | null;
|
| 905 |
+
'data-sveltekit-reload'?: true | '' | 'off' | undefined | null;
|
| 906 |
+
'data-sveltekit-replacestate'?: true | '' | 'off' | undefined | null;
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
/**
|
| 910 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 911 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 912 |
+
*/
|
| 913 |
+
interface SVGAttributes<T extends EventTarget> extends AriaAttributes, DOMAttributes<T> {
|
| 914 |
+
className?: string | undefined | null;
|
| 915 |
+
class?: string | undefined | null;
|
| 916 |
+
color?: string | undefined | null;
|
| 917 |
+
height?: number | string | undefined | null;
|
| 918 |
+
id?: string | undefined | null;
|
| 919 |
+
lang?: string | undefined | null;
|
| 920 |
+
max?: number | string | undefined | null;
|
| 921 |
+
media?: string | undefined | null;
|
| 922 |
+
method?: string | undefined | null;
|
| 923 |
+
min?: number | string | undefined | null;
|
| 924 |
+
name?: string | undefined | null;
|
| 925 |
+
style?: string | undefined | null;
|
| 926 |
+
target?: string | undefined | null;
|
| 927 |
+
type?: string | undefined | null;
|
| 928 |
+
width?: number | string | undefined | null;
|
| 929 |
+
role?: string | undefined | null;
|
| 930 |
+
tabindex?: number | undefined | null;
|
| 931 |
+
crossorigin?: 'anonymous' | 'use-credentials' | '' | undefined | null;
|
| 932 |
+
'accent-height'?: number | string | undefined | null;
|
| 933 |
+
accumulate?: 'none' | 'sum' | undefined | null;
|
| 934 |
+
additive?: 'replace' | 'sum' | undefined | null;
|
| 935 |
+
'alignment-baseline'?: 'auto' | 'baseline' | 'before-edge' | 'text-before-edge' | 'middle' |
|
| 936 |
+
'central' | 'after-edge' | 'text-after-edge' | 'ideographic' | 'alphabetic' | 'hanging' |
|
| 937 |
+
'mathematical' | 'inherit' | undefined | null;
|
| 938 |
+
allowReorder?: 'no' | 'yes' | undefined | null;
|
| 939 |
+
alphabetic?: number | string | undefined | null;
|
| 940 |
+
amplitude?: number | string | undefined | null;
|
| 941 |
+
'arabic-form'?: 'initial' | 'medial' | 'terminal' | 'isolated' | undefined | null;
|
| 942 |
+
ascent?: number | string | undefined | null;
|
| 943 |
+
attributeName?: string | undefined | null;
|
| 944 |
+
attributeType?: string | undefined | null;
|
| 945 |
+
autoReverse?: number | string | undefined | null;
|
| 946 |
+
azimuth?: number | string | undefined | null;
|
| 947 |
+
baseFrequency?: number | string | undefined | null;
|
| 948 |
+
'baseline-shift'?: number | string | undefined | null;
|
| 949 |
+
baseProfile?: number | string | undefined | null;
|
| 950 |
+
bbox?: number | string | undefined | null;
|
| 951 |
+
begin?: number | string | undefined | null;
|
| 952 |
+
bias?: number | string | undefined | null;
|
| 953 |
+
by?: number | string | undefined | null;
|
| 954 |
+
calcMode?: number | string | undefined | null;
|
| 955 |
+
'cap-height'?: number | string | undefined | null;
|
| 956 |
+
clip?: number | string | undefined | null;
|
| 957 |
+
'clip-path'?: string | undefined | null;
|
| 958 |
+
clipPathUnits?: number | string | undefined | null;
|
| 959 |
+
'clip-rule'?: number | string | undefined | null;
|
| 960 |
+
'color-interpolation'?: number | string | undefined | null;
|
| 961 |
+
'color-interpolation-filters'?: 'auto' | 'sRGB' | 'linearRGB' | 'inherit' | undefined | null;
|
| 962 |
+
'color-profile'?: number | string | undefined | null;
|
| 963 |
+
'color-rendering'?: number | string | undefined | null;
|
| 964 |
+
contentScriptType?: number | string | undefined | null;
|
| 965 |
+
contentStyleType?: number | string | undefined | null;
|
| 966 |
+
cursor?: number | string | undefined | null;
|
| 967 |
+
cx?: number | string | undefined | null;
|
| 968 |
+
cy?: number | string | undefined | null;
|
| 969 |
+
d?: string | undefined | null;
|
| 970 |
+
decelerate?: number | string | undefined | null;
|
| 971 |
+
descent?: number | string | undefined | null;
|
| 972 |
+
diffuseConstant?: number | string | undefined | null;
|
| 973 |
+
direction?: number | string | undefined | null;
|
| 974 |
+
display?: number | string | undefined | null;
|
| 975 |
+
divisor?: number | string | undefined | null;
|
| 976 |
+
'dominant-baseline'?: number | string | undefined | null;
|
| 977 |
+
dur?: number | string | undefined | null;
|
| 978 |
+
dx?: number | string | undefined | null;
|
| 979 |
+
dy?: number | string | undefined | null;
|
| 980 |
+
edgeMode?: number | string | undefined | null;
|
| 981 |
+
elevation?: number | string | undefined | null;
|
| 982 |
+
'enable-background'?: number | string | undefined | null;
|
| 983 |
+
end?: number | string | undefined | null;
|
| 984 |
+
exponent?: number | string | undefined | null;
|
| 985 |
+
externalResourcesRequired?: number | string | undefined | null;
|
| 986 |
+
fill?: string | undefined | null;
|
| 987 |
+
'fill-opacity'?: number | string | undefined | null;
|
| 988 |
+
'fill-rule'?: 'nonzero' | 'evenodd' | 'inherit' | undefined | null;
|
| 989 |
+
filter?: string | undefined | null;
|
| 990 |
+
filterRes?: number | string | undefined | null;
|
| 991 |
+
filterUnits?: number | string | undefined | null;
|
| 992 |
+
'flood-color'?: number | string | undefined | null;
|
| 993 |
+
'flood-opacity'?: number | string | undefined | null;
|
| 994 |
+
focusable?: number | string | undefined | null;
|
| 995 |
+
'font-family'?: string | undefined | null;
|
| 996 |
+
'font-size'?: number | string | undefined | null;
|
| 997 |
+
'font-size-adjust'?: number | string | undefined | null;
|
| 998 |
+
'font-stretch'?: number | string | undefined | null;
|
| 999 |
+
'font-style'?: number | string | undefined | null;
|
| 1000 |
+
'font-variant'?: number | string | undefined | null;
|
| 1001 |
+
'font-weight'?: number | string | undefined | null;
|
| 1002 |
+
format?: number | string | undefined | null;
|
| 1003 |
+
from?: number | string | undefined | null;
|
| 1004 |
+
fx?: number | string | undefined | null;
|
| 1005 |
+
fy?: number | string | undefined | null;
|
| 1006 |
+
g1?: number | string | undefined | null;
|
| 1007 |
+
g2?: number | string | undefined | null;
|
| 1008 |
+
'glyph-name'?: number | string | undefined | null;
|
| 1009 |
+
'glyph-orientation-horizontal'?: number | string | undefined | null;
|
| 1010 |
+
'glyph-orientation-vertical'?: number | string | undefined | null;
|
| 1011 |
+
glyphRef?: number | string | undefined | null;
|
| 1012 |
+
gradientTransform?: string | undefined | null;
|
| 1013 |
+
gradientUnits?: string | undefined | null;
|
| 1014 |
+
hanging?: number | string | undefined | null;
|
| 1015 |
+
href?: string | undefined | null;
|
| 1016 |
+
'horiz-adv-x'?: number | string | undefined | null;
|
| 1017 |
+
'horiz-origin-x'?: number | string | undefined | null;
|
| 1018 |
+
ideographic?: number | string | undefined | null;
|
| 1019 |
+
'image-rendering'?: number | string | undefined | null;
|
| 1020 |
+
in2?: number | string | undefined | null;
|
| 1021 |
+
in?: string | undefined | null;
|
| 1022 |
+
intercept?: number | string | undefined | null;
|
| 1023 |
+
k1?: number | string | undefined | null;
|
| 1024 |
+
k2?: number | string | undefined | null;
|
| 1025 |
+
k3?: number | string | undefined | null;
|
| 1026 |
+
k4?: number | string | undefined | null;
|
| 1027 |
+
k?: number | string | undefined | null;
|
| 1028 |
+
kernelMatrix?: number | string | undefined | null;
|
| 1029 |
+
kernelUnitLength?: number | string | undefined | null;
|
| 1030 |
+
kerning?: number | string | undefined | null;
|
| 1031 |
+
keyPoints?: number | string | undefined | null;
|
| 1032 |
+
keySplines?: number | string | undefined | null;
|
| 1033 |
+
keyTimes?: number | string | undefined | null;
|
| 1034 |
+
lengthAdjust?: number | string | undefined | null;
|
| 1035 |
+
'letter-spacing'?: number | string | undefined | null;
|
| 1036 |
+
'lighting-color'?: number | string | undefined | null;
|
| 1037 |
+
limitingConeAngle?: number | string | undefined | null;
|
| 1038 |
+
local?: number | string | undefined | null;
|
| 1039 |
+
'marker-end'?: string | undefined | null;
|
| 1040 |
+
markerHeight?: number | string | undefined | null;
|
| 1041 |
+
'marker-mid'?: string | undefined | null;
|
| 1042 |
+
'marker-start'?: string | undefined | null;
|
| 1043 |
+
markerUnits?: number | string | undefined | null;
|
| 1044 |
+
markerWidth?: number | string | undefined | null;
|
| 1045 |
+
mask?: string | undefined | null;
|
| 1046 |
+
maskContentUnits?: number | string | undefined | null;
|
| 1047 |
+
maskUnits?: number | string | undefined | null;
|
| 1048 |
+
mathematical?: number | string | undefined | null;
|
| 1049 |
+
mode?: number | string | undefined | null;
|
| 1050 |
+
numOctaves?: number | string | undefined | null;
|
| 1051 |
+
offset?: number | string | undefined | null;
|
| 1052 |
+
opacity?: number | string | undefined | null;
|
| 1053 |
+
operator?: number | string | undefined | null;
|
| 1054 |
+
order?: number | string | undefined | null;
|
| 1055 |
+
orient?: number | string | undefined | null;
|
| 1056 |
+
orientation?: number | string | undefined | null;
|
| 1057 |
+
origin?: number | string | undefined | null;
|
| 1058 |
+
overflow?: number | string | undefined | null;
|
| 1059 |
+
'overline-position'?: number | string | undefined | null;
|
| 1060 |
+
'overline-thickness'?: number | string | undefined | null;
|
| 1061 |
+
'paint-order'?: number | string | undefined | null;
|
| 1062 |
+
'panose-1'?: number | string | undefined | null;
|
| 1063 |
+
path?: string | undefined | null;
|
| 1064 |
+
pathLength?: number | string | undefined | null;
|
| 1065 |
+
patternContentUnits?: string | undefined | null;
|
| 1066 |
+
patternTransform?: number | string | undefined | null;
|
| 1067 |
+
patternUnits?: string | undefined | null;
|
| 1068 |
+
'pointer-events'?: number | string | undefined | null;
|
| 1069 |
+
points?: string | undefined | null;
|
| 1070 |
+
pointsAtX?: number | string | undefined | null;
|
| 1071 |
+
pointsAtY?: number | string | undefined | null;
|
| 1072 |
+
pointsAtZ?: number | string | undefined | null;
|
| 1073 |
+
preserveAlpha?: number | string | undefined | null;
|
| 1074 |
+
preserveAspectRatio?: string | undefined | null;
|
| 1075 |
+
primitiveUnits?: number | string | undefined | null;
|
| 1076 |
+
r?: number | string | undefined | null;
|
| 1077 |
+
radius?: number | string | undefined | null;
|
| 1078 |
+
refX?: number | string | undefined | null;
|
| 1079 |
+
refY?: number | string | undefined | null;
|
| 1080 |
+
'rendering-intent'?: number | string | undefined | null;
|
| 1081 |
+
repeatCount?: number | string | undefined | null;
|
| 1082 |
+
repeatDur?: number | string | undefined | null;
|
| 1083 |
+
requiredExtensions?: number | string | undefined | null;
|
| 1084 |
+
requiredFeatures?: number | string | undefined | null;
|
| 1085 |
+
restart?: number | string | undefined | null;
|
| 1086 |
+
result?: string | undefined | null;
|
| 1087 |
+
rotate?: number | string | undefined | null;
|
| 1088 |
+
rx?: number | string | undefined | null;
|
| 1089 |
+
ry?: number | string | undefined | null;
|
| 1090 |
+
scale?: number | string | undefined | null;
|
| 1091 |
+
seed?: number | string | undefined | null;
|
| 1092 |
+
'shape-rendering'?: number | string | undefined | null;
|
| 1093 |
+
slope?: number | string | undefined | null;
|
| 1094 |
+
spacing?: number | string | undefined | null;
|
| 1095 |
+
specularConstant?: number | string | undefined | null;
|
| 1096 |
+
specularExponent?: number | string | undefined | null;
|
| 1097 |
+
speed?: number | string | undefined | null;
|
| 1098 |
+
spreadMethod?: string | undefined | null;
|
| 1099 |
+
startOffset?: number | string | undefined | null;
|
| 1100 |
+
stdDeviation?: number | string | undefined | null;
|
| 1101 |
+
stemh?: number | string | undefined | null;
|
| 1102 |
+
stemv?: number | string | undefined | null;
|
| 1103 |
+
stitchTiles?: number | string | undefined | null;
|
| 1104 |
+
'stop-color'?: string | undefined | null;
|
| 1105 |
+
'stop-opacity'?: number | string | undefined | null;
|
| 1106 |
+
'strikethrough-position'?: number | string | undefined | null;
|
| 1107 |
+
'strikethrough-thickness'?: number | string | undefined | null;
|
| 1108 |
+
string?: number | string | undefined | null;
|
| 1109 |
+
stroke?: string | undefined | null;
|
| 1110 |
+
'stroke-dasharray'?: string | number | undefined | null;
|
| 1111 |
+
'stroke-dashoffset'?: string | number | undefined | null;
|
| 1112 |
+
'stroke-linecap'?: 'butt' | 'round' | 'square' | 'inherit' | undefined | null;
|
| 1113 |
+
'stroke-linejoin'?: 'miter' | 'round' | 'bevel' | 'inherit' | undefined | null;
|
| 1114 |
+
'stroke-miterlimit'?: string | undefined | null;
|
| 1115 |
+
'stroke-opacity'?: number | string | undefined | null;
|
| 1116 |
+
'stroke-width'?: number | string | undefined | null;
|
| 1117 |
+
surfaceScale?: number | string | undefined | null;
|
| 1118 |
+
systemLanguage?: number | string | undefined | null;
|
| 1119 |
+
tableValues?: number | string | undefined | null;
|
| 1120 |
+
targetX?: number | string | undefined | null;
|
| 1121 |
+
targetY?: number | string | undefined | null;
|
| 1122 |
+
'text-anchor'?: string | undefined | null;
|
| 1123 |
+
'text-decoration'?: number | string | undefined | null;
|
| 1124 |
+
textLength?: number | string | undefined | null;
|
| 1125 |
+
'text-rendering'?: number | string | undefined | null;
|
| 1126 |
+
to?: number | string | undefined | null;
|
| 1127 |
+
transform?: string | undefined | null;
|
| 1128 |
+
u1?: number | string | undefined | null;
|
| 1129 |
+
u2?: number | string | undefined | null;
|
| 1130 |
+
'underline-position'?: number | string | undefined | null;
|
| 1131 |
+
'underline-thickness'?: number | string | undefined | null;
|
| 1132 |
+
unicode?: number | string | undefined | null;
|
| 1133 |
+
'unicode-bidi'?: number | string | undefined | null;
|
| 1134 |
+
'unicode-range'?: number | string | undefined | null;
|
| 1135 |
+
'units-per-em'?: number | string | undefined | null;
|
| 1136 |
+
'v-alphabetic'?: number | string | undefined | null;
|
| 1137 |
+
values?: string | undefined | null;
|
| 1138 |
+
'vector-effect'?: number | string | undefined | null;
|
| 1139 |
+
version?: string | undefined | null;
|
| 1140 |
+
'vert-adv-y'?: number | string | undefined | null;
|
| 1141 |
+
'vert-origin-x'?: number | string | undefined | null;
|
| 1142 |
+
'vert-origin-y'?: number | string | undefined | null;
|
| 1143 |
+
'v-hanging'?: number | string | undefined | null;
|
| 1144 |
+
'v-ideographic'?: number | string | undefined | null;
|
| 1145 |
+
viewBox?: string | undefined | null;
|
| 1146 |
+
viewTarget?: number | string | undefined | null;
|
| 1147 |
+
visibility?: number | string | undefined | null;
|
| 1148 |
+
'v-mathematical'?: number | string | undefined | null;
|
| 1149 |
+
widths?: number | string | undefined | null;
|
| 1150 |
+
'word-spacing'?: number | string | undefined | null;
|
| 1151 |
+
'writing-mode'?: number | string | undefined | null;
|
| 1152 |
+
x1?: number | string | undefined | null;
|
| 1153 |
+
x2?: number | string | undefined | null;
|
| 1154 |
+
x?: number | string | undefined | null;
|
| 1155 |
+
xChannelSelector?: string | undefined | null;
|
| 1156 |
+
'x-height'?: number | string | undefined | null;
|
| 1157 |
+
xlinkActuate?: string | undefined | null;
|
| 1158 |
+
xlinkArcrole?: string | undefined | null;
|
| 1159 |
+
xlinkHref?: string | undefined | null;
|
| 1160 |
+
xlinkRole?: string | undefined | null;
|
| 1161 |
+
xlinkShow?: string | undefined | null;
|
| 1162 |
+
xlinkTitle?: string | undefined | null;
|
| 1163 |
+
xlinkType?: string | undefined | null;
|
| 1164 |
+
xmlBase?: string | undefined | null;
|
| 1165 |
+
xmlLang?: string | undefined | null;
|
| 1166 |
+
xmlns?: string | undefined | null;
|
| 1167 |
+
xmlnsXlink?: string | undefined | null;
|
| 1168 |
+
xmlSpace?: string | undefined | null;
|
| 1169 |
+
y1?: number | string | undefined | null;
|
| 1170 |
+
y2?: number | string | undefined | null;
|
| 1171 |
+
y?: number | string | undefined | null;
|
| 1172 |
+
yChannelSelector?: string | undefined | null;
|
| 1173 |
+
z?: number | string | undefined | null;
|
| 1174 |
+
zoomAndPan?: string | undefined | null;
|
| 1175 |
+
}
|
| 1176 |
+
|
| 1177 |
+
/**
|
| 1178 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1179 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1180 |
+
*/
|
| 1181 |
+
interface HTMLProps<T extends EventTarget> extends HTMLAttributes<T> {}
|
| 1182 |
+
/**
|
| 1183 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1184 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1185 |
+
*/
|
| 1186 |
+
interface SVGProps<T extends EventTarget> extends SVGAttributes<T> {}
|
| 1187 |
+
|
| 1188 |
+
/**
|
| 1189 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1190 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1191 |
+
*/
|
| 1192 |
+
interface SvelteInputProps extends HTMLProps<HTMLInputElement> {
|
| 1193 |
+
group?: any | undefined | null;
|
| 1194 |
+
files?: FileList | undefined | null;
|
| 1195 |
+
indeterminate?: boolean | undefined | null;
|
| 1196 |
+
}
|
| 1197 |
+
|
| 1198 |
+
/**
|
| 1199 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1200 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1201 |
+
*/
|
| 1202 |
+
interface SvelteWindowProps {
|
| 1203 |
+
readonly innerWidth?: Window['innerWidth'] | undefined | null;
|
| 1204 |
+
readonly innerHeight?: Window['innerHeight'] | undefined | null;
|
| 1205 |
+
readonly outerWidth?: Window['outerWidth'] | undefined | null;
|
| 1206 |
+
readonly outerHeight?: Window['outerHeight'] | undefined | null;
|
| 1207 |
+
scrollX?: Window['scrollX'] | undefined | null;
|
| 1208 |
+
scrollY?: Window['scrollY'] | undefined | null;
|
| 1209 |
+
readonly online?: Window['navigator']['onLine'] | undefined | null;
|
| 1210 |
+
|
| 1211 |
+
// Transformed from on:sveltekit:xy
|
| 1212 |
+
'onsveltekit:start'?: EventHandler<CustomEvent, Window> | undefined | null;
|
| 1213 |
+
'onsveltekit:navigation-start'?: EventHandler<CustomEvent, Window> | undefined | null;
|
| 1214 |
+
'onsveltekit:navigation-end'?: EventHandler<CustomEvent, Window> | undefined | null;
|
| 1215 |
+
|
| 1216 |
+
ondevicelight?: EventHandler<Event, Window> | undefined | null;
|
| 1217 |
+
onbeforeinstallprompt?: EventHandler<Event, Window> | undefined | null;
|
| 1218 |
+
ondeviceproximity?: EventHandler<Event, Window> | undefined | null;
|
| 1219 |
+
onpaint?: EventHandler<Event, Window> | undefined | null;
|
| 1220 |
+
onuserproximity?: EventHandler<Event, Window> | undefined | null;
|
| 1221 |
+
onbeforeprint?: EventHandler<Event, Window> | undefined | null;
|
| 1222 |
+
onafterprint?: EventHandler<Event, Window> | undefined | null;
|
| 1223 |
+
onlanguagechange?: EventHandler<Event, Window> | undefined | null;
|
| 1224 |
+
onorientationchange?: EventHandler<Event, Window> | undefined | null;
|
| 1225 |
+
onmessage?: EventHandler<MessageEvent, Window> | undefined | null;
|
| 1226 |
+
onmessageerror?: EventHandler<MessageEvent, Window> | undefined | null;
|
| 1227 |
+
onoffline?: EventHandler<Event, Window> | undefined | null;
|
| 1228 |
+
ononline?: EventHandler<Event, Window> | undefined | null;
|
| 1229 |
+
onbeforeunload?: EventHandler<BeforeUnloadEvent, Window> | undefined | null;
|
| 1230 |
+
onunload?: EventHandler<Event, Window> | undefined | null;
|
| 1231 |
+
onstorage?: EventHandler<StorageEvent, Window> | undefined | null;
|
| 1232 |
+
onhashchange?: EventHandler<HashChangeEvent, Window> | undefined | null;
|
| 1233 |
+
onpagehide?: EventHandler<PageTransitionEvent, Window> | undefined | null;
|
| 1234 |
+
onpageshow?: EventHandler<PageTransitionEvent, Window> | undefined | null;
|
| 1235 |
+
onpopstate?: EventHandler<PopStateEvent, Window> | undefined | null;
|
| 1236 |
+
ondevicemotion?: EventHandler<DeviceMotionEvent> | undefined | null;
|
| 1237 |
+
ondeviceorientation?: EventHandler<DeviceOrientationEvent, Window> | undefined | null;
|
| 1238 |
+
ondeviceorientationabsolute?: EventHandler<DeviceOrientationEvent, Window> | undefined | null;
|
| 1239 |
+
onunhandledrejection?: EventHandler<PromiseRejectionEvent, Window> | undefined | null;
|
| 1240 |
+
onrejectionhandled?: EventHandler<PromiseRejectionEvent, Window> | undefined | null;
|
| 1241 |
+
}
|
| 1242 |
+
|
| 1243 |
+
/**
|
| 1244 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1245 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1246 |
+
*/
|
| 1247 |
+
interface SapperAnchorProps {
|
| 1248 |
+
// transformed from sapper:noscroll so it should be camel case
|
| 1249 |
+
sapperNoscroll?: true | undefined | null;
|
| 1250 |
+
sapperPrefetch?: true | undefined | null;
|
| 1251 |
+
}
|
| 1252 |
+
|
| 1253 |
+
/**
|
| 1254 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1255 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1256 |
+
*/
|
| 1257 |
+
interface SvelteMediaTimeRange {
|
| 1258 |
+
start: number;
|
| 1259 |
+
end: number;
|
| 1260 |
+
}
|
| 1261 |
+
|
| 1262 |
+
/**
|
| 1263 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1264 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1265 |
+
*/
|
| 1266 |
+
interface SvelteMediaProps {
|
| 1267 |
+
readonly duration?: number | undefined | null;
|
| 1268 |
+
readonly buffered?: SvelteMediaTimeRange[] | undefined | null;
|
| 1269 |
+
readonly played?: SvelteMediaTimeRange[] | undefined | null;
|
| 1270 |
+
readonly seekable?: SvelteMediaTimeRange[] | undefined | null;
|
| 1271 |
+
readonly seeking?: boolean | undefined | null;
|
| 1272 |
+
readonly ended?: boolean | undefined | null;
|
| 1273 |
+
|
| 1274 |
+
/**
|
| 1275 |
+
* the current playback time in the video, in seconds
|
| 1276 |
+
*/
|
| 1277 |
+
currentTime?: number | undefined | null;
|
| 1278 |
+
/**
|
| 1279 |
+
* the current playback time in the video, in seconds
|
| 1280 |
+
*/
|
| 1281 |
+
currenttime?: number | undefined | null;
|
| 1282 |
+
// Doesn't work when used as HTML Attribute
|
| 1283 |
+
/**
|
| 1284 |
+
* how fast or slow to play the video, where 1 is 'normal'
|
| 1285 |
+
*/
|
| 1286 |
+
playbackRate?: number | undefined | null;
|
| 1287 |
+
|
| 1288 |
+
paused?: boolean | undefined | null;
|
| 1289 |
+
}
|
| 1290 |
+
|
| 1291 |
+
/**
|
| 1292 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1293 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1294 |
+
*/
|
| 1295 |
+
interface SvelteVideoProps extends SvelteMediaProps {
|
| 1296 |
+
// Binding only, don't need lowercase variant
|
| 1297 |
+
readonly videoWidth?: number | undefined | null;
|
| 1298 |
+
readonly videoHeight?: number | undefined | null;
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
/**
|
| 1302 |
+
* @deprecated use the types from `svelte/elements` instead
|
| 1303 |
+
* For more info see https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings
|
| 1304 |
+
*/
|
| 1305 |
+
interface IntrinsicElements {
|
| 1306 |
+
// HTML
|
| 1307 |
+
a: HTMLProps<HTMLAnchorElement> & SapperAnchorProps;
|
| 1308 |
+
abbr: HTMLProps<HTMLElement>;
|
| 1309 |
+
address: HTMLProps<HTMLElement>;
|
| 1310 |
+
area: HTMLProps<HTMLAreaElement>;
|
| 1311 |
+
article: HTMLProps<HTMLElement>;
|
| 1312 |
+
aside: HTMLProps<HTMLElement>;
|
| 1313 |
+
audio: HTMLProps<HTMLAudioElement> & SvelteMediaProps;
|
| 1314 |
+
b: HTMLProps<HTMLElement>;
|
| 1315 |
+
base: HTMLProps<HTMLBaseElement>;
|
| 1316 |
+
bdi: HTMLProps<HTMLElement>;
|
| 1317 |
+
bdo: HTMLProps<HTMLElement>;
|
| 1318 |
+
big: HTMLProps<HTMLElement>;
|
| 1319 |
+
blockquote: HTMLProps<HTMLElement>;
|
| 1320 |
+
body: HTMLProps<HTMLBodyElement>;
|
| 1321 |
+
br: HTMLProps<HTMLBRElement>;
|
| 1322 |
+
button: HTMLProps<HTMLButtonElement>;
|
| 1323 |
+
canvas: HTMLProps<HTMLCanvasElement>;
|
| 1324 |
+
caption: HTMLProps<HTMLElement>;
|
| 1325 |
+
cite: HTMLProps<HTMLElement>;
|
| 1326 |
+
code: HTMLProps<HTMLElement>;
|
| 1327 |
+
col: HTMLProps<HTMLTableColElement>;
|
| 1328 |
+
colgroup: HTMLProps<HTMLTableColElement>;
|
| 1329 |
+
data: HTMLProps<HTMLElement>;
|
| 1330 |
+
datalist: HTMLProps<HTMLDataListElement>;
|
| 1331 |
+
dd: HTMLProps<HTMLElement>;
|
| 1332 |
+
del: HTMLProps<HTMLElement>;
|
| 1333 |
+
details: HTMLProps<HTMLElement>;
|
| 1334 |
+
dfn: HTMLProps<HTMLElement>;
|
| 1335 |
+
dialog: HTMLProps<HTMLElement>;
|
| 1336 |
+
div: HTMLProps<HTMLDivElement>;
|
| 1337 |
+
dl: HTMLProps<HTMLDListElement>;
|
| 1338 |
+
dt: HTMLProps<HTMLElement>;
|
| 1339 |
+
em: HTMLProps<HTMLElement>;
|
| 1340 |
+
embed: HTMLProps<HTMLEmbedElement>;
|
| 1341 |
+
fieldset: HTMLProps<HTMLFieldSetElement>;
|
| 1342 |
+
figcaption: HTMLProps<HTMLElement>;
|
| 1343 |
+
figure: HTMLProps<HTMLElement>;
|
| 1344 |
+
footer: HTMLProps<HTMLElement>;
|
| 1345 |
+
form: HTMLProps<HTMLFormElement>;
|
| 1346 |
+
h1: HTMLProps<HTMLHeadingElement>;
|
| 1347 |
+
h2: HTMLProps<HTMLHeadingElement>;
|
| 1348 |
+
h3: HTMLProps<HTMLHeadingElement>;
|
| 1349 |
+
h4: HTMLProps<HTMLHeadingElement>;
|
| 1350 |
+
h5: HTMLProps<HTMLHeadingElement>;
|
| 1351 |
+
h6: HTMLProps<HTMLHeadingElement>;
|
| 1352 |
+
head: HTMLProps<HTMLHeadElement>;
|
| 1353 |
+
header: HTMLProps<HTMLElement>;
|
| 1354 |
+
hgroup: HTMLProps<HTMLElement>;
|
| 1355 |
+
hr: HTMLProps<HTMLHRElement>;
|
| 1356 |
+
html: HTMLProps<HTMLHtmlElement>;
|
| 1357 |
+
i: HTMLProps<HTMLElement>;
|
| 1358 |
+
iframe: HTMLProps<HTMLIFrameElement>;
|
| 1359 |
+
img: HTMLProps<HTMLImageElement>;
|
| 1360 |
+
input: SvelteInputProps;
|
| 1361 |
+
ins: HTMLProps<HTMLModElement>;
|
| 1362 |
+
kbd: HTMLProps<HTMLElement>;
|
| 1363 |
+
keygen: HTMLProps<HTMLElement>;
|
| 1364 |
+
label: HTMLProps<HTMLLabelElement>;
|
| 1365 |
+
legend: HTMLProps<HTMLLegendElement>;
|
| 1366 |
+
li: HTMLProps<HTMLLIElement>;
|
| 1367 |
+
link: HTMLProps<HTMLLinkElement>;
|
| 1368 |
+
main: HTMLProps<HTMLElement>;
|
| 1369 |
+
map: HTMLProps<HTMLMapElement>;
|
| 1370 |
+
mark: HTMLProps<HTMLElement>;
|
| 1371 |
+
menu: HTMLProps<HTMLElement>;
|
| 1372 |
+
menuitem: HTMLProps<HTMLElement>;
|
| 1373 |
+
meta: HTMLProps<HTMLMetaElement>;
|
| 1374 |
+
meter: HTMLProps<HTMLElement>;
|
| 1375 |
+
nav: HTMLProps<HTMLElement>;
|
| 1376 |
+
noindex: HTMLProps<HTMLElement>;
|
| 1377 |
+
noscript: HTMLProps<HTMLElement>;
|
| 1378 |
+
object: HTMLProps<HTMLObjectElement>;
|
| 1379 |
+
ol: HTMLProps<HTMLOListElement>;
|
| 1380 |
+
optgroup: HTMLProps<HTMLOptGroupElement>;
|
| 1381 |
+
option: HTMLProps<HTMLOptionElement>;
|
| 1382 |
+
output: HTMLProps<HTMLElement>;
|
| 1383 |
+
p: HTMLProps<HTMLParagraphElement>;
|
| 1384 |
+
param: HTMLProps<HTMLParamElement>;
|
| 1385 |
+
picture: HTMLProps<HTMLElement>;
|
| 1386 |
+
pre: HTMLProps<HTMLPreElement>;
|
| 1387 |
+
progress: HTMLProps<HTMLProgressElement>;
|
| 1388 |
+
q: HTMLProps<HTMLQuoteElement>;
|
| 1389 |
+
rp: HTMLProps<HTMLElement>;
|
| 1390 |
+
rt: HTMLProps<HTMLElement>;
|
| 1391 |
+
ruby: HTMLProps<HTMLElement>;
|
| 1392 |
+
s: HTMLProps<HTMLElement>;
|
| 1393 |
+
samp: HTMLProps<HTMLElement>;
|
| 1394 |
+
script: HTMLProps<HTMLElement>;
|
| 1395 |
+
section: HTMLProps<HTMLElement>;
|
| 1396 |
+
select: HTMLProps<HTMLSelectElement>;
|
| 1397 |
+
small: HTMLProps<HTMLElement>;
|
| 1398 |
+
source: HTMLProps<HTMLSourceElement>;
|
| 1399 |
+
span: HTMLProps<HTMLSpanElement>;
|
| 1400 |
+
strong: HTMLProps<HTMLElement>;
|
| 1401 |
+
style: HTMLProps<HTMLStyleElement>;
|
| 1402 |
+
sub: HTMLProps<HTMLElement>;
|
| 1403 |
+
summary: HTMLProps<HTMLElement>;
|
| 1404 |
+
sup: HTMLProps<HTMLElement>;
|
| 1405 |
+
table: HTMLProps<HTMLTableElement>;
|
| 1406 |
+
tbody: HTMLProps<HTMLTableSectionElement>;
|
| 1407 |
+
td: HTMLProps<HTMLTableDataCellElement>;
|
| 1408 |
+
textarea: HTMLProps<HTMLTextAreaElement>;
|
| 1409 |
+
tfoot: HTMLProps<HTMLTableSectionElement>;
|
| 1410 |
+
th: HTMLProps<HTMLTableHeaderCellElement>;
|
| 1411 |
+
thead: HTMLProps<HTMLTableSectionElement>;
|
| 1412 |
+
time: HTMLProps<HTMLElement>;
|
| 1413 |
+
title: HTMLProps<HTMLTitleElement>;
|
| 1414 |
+
tr: HTMLProps<HTMLTableRowElement>;
|
| 1415 |
+
track: HTMLProps<HTMLTrackElement>;
|
| 1416 |
+
u: HTMLProps<HTMLElement>;
|
| 1417 |
+
ul: HTMLProps<HTMLUListElement>;
|
| 1418 |
+
var: HTMLProps<HTMLElement>;
|
| 1419 |
+
video: HTMLProps<HTMLVideoElement> & SvelteVideoProps;
|
| 1420 |
+
wbr: HTMLProps<HTMLElement>;
|
| 1421 |
+
|
| 1422 |
+
svg: SVGProps<SVGSVGElement>;
|
| 1423 |
+
|
| 1424 |
+
animate: SVGProps<SVGElement>; // @TODO: It is SVGAnimateElement but not in dom.d.ts for now.
|
| 1425 |
+
circle: SVGProps<SVGCircleElement>;
|
| 1426 |
+
clipPath: SVGProps<SVGClipPathElement>;
|
| 1427 |
+
defs: SVGProps<SVGDefsElement>;
|
| 1428 |
+
desc: SVGProps<SVGDescElement>;
|
| 1429 |
+
ellipse: SVGProps<SVGEllipseElement>;
|
| 1430 |
+
feBlend: SVGProps<SVGFEBlendElement>;
|
| 1431 |
+
feColorMatrix: SVGProps<SVGFEColorMatrixElement>;
|
| 1432 |
+
feComponentTransfer: SVGProps<SVGFEComponentTransferElement>;
|
| 1433 |
+
feComposite: SVGProps<SVGFECompositeElement>;
|
| 1434 |
+
feConvolveMatrix: SVGProps<SVGFEConvolveMatrixElement>;
|
| 1435 |
+
feDiffuseLighting: SVGProps<SVGFEDiffuseLightingElement>;
|
| 1436 |
+
feDisplacementMap: SVGProps<SVGFEDisplacementMapElement>;
|
| 1437 |
+
feDistantLight: SVGProps<SVGFEDistantLightElement>;
|
| 1438 |
+
feFlood: SVGProps<SVGFEFloodElement>;
|
| 1439 |
+
feFuncA: SVGProps<SVGFEFuncAElement>;
|
| 1440 |
+
feFuncB: SVGProps<SVGFEFuncBElement>;
|
| 1441 |
+
feFuncG: SVGProps<SVGFEFuncGElement>;
|
| 1442 |
+
feFuncR: SVGProps<SVGFEFuncRElement>;
|
| 1443 |
+
feGaussianBlur: SVGProps<SVGFEGaussianBlurElement>;
|
| 1444 |
+
feImage: SVGProps<SVGFEImageElement>;
|
| 1445 |
+
feMerge: SVGProps<SVGFEMergeElement>;
|
| 1446 |
+
feMergeNode: SVGProps<SVGFEMergeNodeElement>;
|
| 1447 |
+
feMorphology: SVGProps<SVGFEMorphologyElement>;
|
| 1448 |
+
feOffset: SVGProps<SVGFEOffsetElement>;
|
| 1449 |
+
fePointLight: SVGProps<SVGFEPointLightElement>;
|
| 1450 |
+
feSpecularLighting: SVGProps<SVGFESpecularLightingElement>;
|
| 1451 |
+
feSpotLight: SVGProps<SVGFESpotLightElement>;
|
| 1452 |
+
feTile: SVGProps<SVGFETileElement>;
|
| 1453 |
+
feTurbulence: SVGProps<SVGFETurbulenceElement>;
|
| 1454 |
+
filter: SVGProps<SVGFilterElement>;
|
| 1455 |
+
foreignObject: SVGProps<SVGForeignObjectElement>;
|
| 1456 |
+
g: SVGProps<SVGGElement>;
|
| 1457 |
+
image: SVGProps<SVGImageElement>;
|
| 1458 |
+
line: SVGProps<SVGLineElement>;
|
| 1459 |
+
linearGradient: SVGProps<SVGLinearGradientElement>;
|
| 1460 |
+
marker: SVGProps<SVGMarkerElement>;
|
| 1461 |
+
mask: SVGProps<SVGMaskElement>;
|
| 1462 |
+
metadata: SVGProps<SVGMetadataElement>;
|
| 1463 |
+
path: SVGProps<SVGPathElement>;
|
| 1464 |
+
pattern: SVGProps<SVGPatternElement>;
|
| 1465 |
+
polygon: SVGProps<SVGPolygonElement>;
|
| 1466 |
+
polyline: SVGProps<SVGPolylineElement>;
|
| 1467 |
+
radialGradient: SVGProps<SVGRadialGradientElement>;
|
| 1468 |
+
rect: SVGProps<SVGRectElement>;
|
| 1469 |
+
stop: SVGProps<SVGStopElement>;
|
| 1470 |
+
switch: SVGProps<SVGSwitchElement>;
|
| 1471 |
+
symbol: SVGProps<SVGSymbolElement>;
|
| 1472 |
+
text: SVGProps<SVGTextElement>;
|
| 1473 |
+
textPath: SVGProps<SVGTextPathElement>;
|
| 1474 |
+
tspan: SVGProps<SVGTSpanElement>;
|
| 1475 |
+
use: SVGProps<SVGUseElement>;
|
| 1476 |
+
view: SVGProps<SVGViewElement>;
|
| 1477 |
+
|
| 1478 |
+
// Svelte specific
|
| 1479 |
+
sveltewindow: HTMLProps<Window> & SvelteWindowProps;
|
| 1480 |
+
sveltebody: HTMLProps<HTMLElement>;
|
| 1481 |
+
sveltefragment: { slot?: string; };
|
| 1482 |
+
svelteoptions: { [name: string]: any };
|
| 1483 |
+
sveltehead: { [name: string]: any };
|
| 1484 |
+
svelteelement: { 'this': string | undefined | null; } & HTMLProps<any> & SVGProps<any> & SapperAnchorProps;
|
| 1485 |
+
// Needed due to backwards compatibility type which hits these
|
| 1486 |
+
'svelte:window': HTMLProps<Window> & SvelteWindowProps;
|
| 1487 |
+
'svelte:body': HTMLProps<HTMLElement>;
|
| 1488 |
+
'svelte:fragment': { slot?: string; };
|
| 1489 |
+
'svelte:options': { [name: string]: any };
|
| 1490 |
+
'svelte:head': { [name: string]: any };
|
| 1491 |
+
}
|
| 1492 |
+
}
|
tools/ui/node_modules/svelte-check/dist/src/svelte-native-jsx.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare namespace svelteNative.JSX {
|
| 2 |
+
|
| 3 |
+
// Every namespace eligible for use needs to implement the following two functions
|
| 4 |
+
function mapElementTag(
|
| 5 |
+
tag: string
|
| 6 |
+
): any;
|
| 7 |
+
|
| 8 |
+
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements>(
|
| 9 |
+
element: Key | undefined | null, attrs: Elements[Key]
|
| 10 |
+
): any;
|
| 11 |
+
function createElement<Elements extends IntrinsicElements, Key extends keyof Elements, T>(
|
| 12 |
+
element: Key | undefined | null, attrEnhancers: T, attrs: Elements[Key] & T
|
| 13 |
+
): any;
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
/* svelte specific */
|
| 17 |
+
interface ElementClass {
|
| 18 |
+
$$prop_def: any;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
interface ElementAttributesProperty {
|
| 22 |
+
$$prop_def: any; // specify the property name to use
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
// Add empty IntrinsicAttributes to prevent fallback to the one in the JSX namespace
|
| 26 |
+
interface IntrinsicAttributes {
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
interface IntrinsicElements {
|
| 30 |
+
[name: string]: { [name: string]: any };
|
| 31 |
+
}
|
| 32 |
+
}
|
tools/ui/node_modules/svelte-check/dist/src/svelte-shims-v4.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Whenever a ambient declaration changes, its number should be increased
|
| 2 |
+
// This way, we avoid the situation where multiple ambient versions of svelte2tsx
|
| 3 |
+
// are loaded and their declarations conflict each other
|
| 4 |
+
// See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
|
| 5 |
+
// If you change anything in this file, think about whether or not it should be backported to svelte-shims.d.ts
|
| 6 |
+
|
| 7 |
+
type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
|
| 8 |
+
|
| 9 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 10 |
+
type SvelteActionReturnType = {
|
| 11 |
+
update?: (args: any) => void,
|
| 12 |
+
destroy?: () => void
|
| 13 |
+
} | void
|
| 14 |
+
|
| 15 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 16 |
+
type SvelteTransitionConfig = {
|
| 17 |
+
delay?: number,
|
| 18 |
+
duration?: number,
|
| 19 |
+
easing?: (t: number) => number,
|
| 20 |
+
css?: (t: number, u: number) => string,
|
| 21 |
+
tick?: (t: number, u: number) => void
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 25 |
+
type SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)
|
| 26 |
+
|
| 27 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 28 |
+
type SvelteAnimationReturnType = {
|
| 29 |
+
delay?: number,
|
| 30 |
+
duration?: number,
|
| 31 |
+
easing?: (t: number) => number,
|
| 32 |
+
css?: (t: number, u: number) => string,
|
| 33 |
+
tick?: (t: number, u: number) => void
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 37 |
+
type SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;
|
| 38 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 39 |
+
type SvelteAllProps = { [index: string]: any }
|
| 40 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 41 |
+
type SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}
|
| 42 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 43 |
+
type SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}
|
| 44 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 45 |
+
type SvelteRestProps = { [index: string]: any }
|
| 46 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 47 |
+
type SvelteSlots = { [index: string]: any }
|
| 48 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 49 |
+
type SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }
|
| 50 |
+
|
| 51 |
+
// Forces TypeScript to look into the type which results in a better representation of it
|
| 52 |
+
// which helps for error messages and is necessary for d.ts file transformation so that
|
| 53 |
+
// no ambient type references are left in the output
|
| 54 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 55 |
+
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
| 56 |
+
|
| 57 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 58 |
+
type KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]
|
| 59 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 60 |
+
declare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}
|
| 61 |
+
|
| 62 |
+
declare function __sveltets_2_ensureRightProps<Props>(props: Props): {};
|
| 63 |
+
declare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;
|
| 64 |
+
declare function __sveltets_2_allPropsType(): SvelteAllProps
|
| 65 |
+
declare function __sveltets_2_restPropsType(): SvelteRestProps
|
| 66 |
+
declare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;
|
| 67 |
+
|
| 68 |
+
// Overload of the following two functions is necessary.
|
| 69 |
+
// An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.
|
| 70 |
+
// optionalProps need to be first or its type cannot be infered correctly.
|
| 71 |
+
|
| 72 |
+
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
| 73 |
+
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 74 |
+
): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
| 75 |
+
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(
|
| 76 |
+
optionalProps: OptionalProps[],
|
| 77 |
+
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 78 |
+
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
| 79 |
+
|
| 80 |
+
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
| 81 |
+
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 82 |
+
): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
| 83 |
+
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string, OptionalProps extends keyof Props = any>(
|
| 84 |
+
optionalProps: OptionalProps[],
|
| 85 |
+
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 86 |
+
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>>, exports?: Exports, bindings?: Bindings }
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
declare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
| 90 |
+
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 91 |
+
): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 92 |
+
|
| 93 |
+
declare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}, Exports = {}, Bindings = string>(
|
| 94 |
+
render: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 95 |
+
): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots, exports?: Exports, bindings?: Bindings }
|
| 96 |
+
|
| 97 |
+
declare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T
|
| 98 |
+
declare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;
|
| 99 |
+
declare function __sveltets_2_any(dummy: any): any;
|
| 100 |
+
declare function __sveltets_2_invalidate<T>(getValue: () => T): T
|
| 101 |
+
|
| 102 |
+
declare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(
|
| 103 |
+
event: K
|
| 104 |
+
): HTMLBodyElementEventMap[K];
|
| 105 |
+
declare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(
|
| 106 |
+
event: K
|
| 107 |
+
): WindowEventMap[K];
|
| 108 |
+
declare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(
|
| 109 |
+
event: K
|
| 110 |
+
): HTMLElementEventMap[K];
|
| 111 |
+
|
| 112 |
+
declare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(
|
| 113 |
+
events: Events, eventKey: K
|
| 114 |
+
): Events[K];
|
| 115 |
+
declare function __sveltets_2_bubbleEventDef(
|
| 116 |
+
events: any, eventKey: string
|
| 117 |
+
): any;
|
| 118 |
+
|
| 119 |
+
declare const __sveltets_2_customEvent: CustomEvent<any>;
|
| 120 |
+
declare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};
|
| 121 |
+
|
| 122 |
+
declare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;
|
| 123 |
+
declare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;
|
| 124 |
+
declare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
|
| 125 |
+
declare function __sveltets_2_unionType(...types: any[]): any;
|
| 126 |
+
|
| 127 |
+
declare function __sveltets_2_createSvelte2TsxComponent<Props extends {}, Events extends {}, Slots extends {}>(
|
| 128 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 129 |
+
): typeof import("svelte").SvelteComponent<Props, Events, Slots>;
|
| 130 |
+
|
| 131 |
+
declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
|
| 132 |
+
declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
|
| 133 |
+
|
| 134 |
+
// v2
|
| 135 |
+
declare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;
|
| 136 |
+
declare function __sveltets_2_createComponentAny(props: Record<string, any>): import("svelte").SvelteComponent<any, any, any>;
|
| 137 |
+
|
| 138 |
+
declare function __sveltets_2_any(...dummy: any[]): any;
|
| 139 |
+
declare function __sveltets_2_empty(...dummy: any[]): {};
|
| 140 |
+
declare 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;
|
| 141 |
+
declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;
|
| 142 |
+
|
| 143 |
+
declare function __sveltets_2_cssProp(prop: Record<string, any>): {};
|
| 144 |
+
|
| 145 |
+
// @ts-ignore Svelte v3/v4 don't have this
|
| 146 |
+
declare function __sveltets_2_ensureSnippet(val: ReturnType<import('svelte').Snippet> | undefined | null): any;
|
| 147 |
+
|
| 148 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 149 |
+
type __sveltets_2_SvelteAnimationReturnType = {
|
| 150 |
+
delay?: number,
|
| 151 |
+
duration?: number,
|
| 152 |
+
easing?: (t: number) => number,
|
| 153 |
+
css?: (t: number, u: number) => string,
|
| 154 |
+
tick?: (t: number, u: number) => void
|
| 155 |
+
}
|
| 156 |
+
declare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }
|
| 157 |
+
declare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};
|
| 158 |
+
|
| 159 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 160 |
+
type __sveltets_2_SvelteActionReturnType = {
|
| 161 |
+
update?: (args: any) => void,
|
| 162 |
+
destroy?: () => void,
|
| 163 |
+
$$_attributes?: Record<string, any>,
|
| 164 |
+
} | void
|
| 165 |
+
declare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};
|
| 166 |
+
|
| 167 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 168 |
+
type __sveltets_2_SvelteTransitionConfig = {
|
| 169 |
+
delay?: number,
|
| 170 |
+
duration?: number,
|
| 171 |
+
easing?: (t: number) => number,
|
| 172 |
+
css?: (t: number, u: number) => string,
|
| 173 |
+
tick?: (t: number, u: number) => void
|
| 174 |
+
}
|
| 175 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 176 |
+
type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)
|
| 177 |
+
declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};
|
| 178 |
+
|
| 179 |
+
// Includes undefined and null for all types as all usages also allow these
|
| 180 |
+
declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};
|
| 181 |
+
declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};
|
| 182 |
+
|
| 183 |
+
// The following is necessary because there are two clashing errors that can't be solved at the same time
|
| 184 |
+
// when using Svelte2TsxComponent, more precisely the event typings in
|
| 185 |
+
// __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;
|
| 186 |
+
// If we type it as "any", we have an error when using sth like {a: CustomEvent<any>}
|
| 187 |
+
// If we type it as "{}", we have an error when using sth like {[evt: string]: CustomEvent<any>}
|
| 188 |
+
// If we type it as "unknown", we get all kinds of follow up errors which we want to avoid
|
| 189 |
+
// Therefore introduce two more base classes just for this case.
|
| 190 |
+
/**
|
| 191 |
+
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT
|
| 192 |
+
*/
|
| 193 |
+
declare type ATypedSvelteComponent = {
|
| 194 |
+
/**
|
| 195 |
+
* @internal This is for type checking capabilities only
|
| 196 |
+
* and does not exist at runtime. Don't use this property.
|
| 197 |
+
*/
|
| 198 |
+
$$prop_def: any;
|
| 199 |
+
/**
|
| 200 |
+
* @internal This is for type checking capabilities only
|
| 201 |
+
* and does not exist at runtime. Don't use this property.
|
| 202 |
+
*/
|
| 203 |
+
$$events_def: any;
|
| 204 |
+
/**
|
| 205 |
+
* @internal This is for type checking capabilities only
|
| 206 |
+
* and does not exist at runtime. Don't use this property.
|
| 207 |
+
*/
|
| 208 |
+
$$slot_def: any;
|
| 209 |
+
|
| 210 |
+
$on(event: string, handler: any): () => void;
|
| 211 |
+
}
|
| 212 |
+
/**
|
| 213 |
+
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
|
| 214 |
+
*
|
| 215 |
+
* If you're looking for the type of a Svelte Component, use `SvelteComponent` and `ComponentType` instead:
|
| 216 |
+
*
|
| 217 |
+
* ```ts
|
| 218 |
+
* import type { ComponentType, SvelteComponent } from "svelte";
|
| 219 |
+
* let myComponentConstructor: ComponentType<SvelteComponent> = ..;
|
| 220 |
+
* ```
|
| 221 |
+
*/
|
| 222 |
+
declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
|
| 223 |
+
// Usage note: Cannot properly transform generic function components to class components due to TypeScript limitations
|
| 224 |
+
declare function __sveltets_2_ensureComponent<
|
| 225 |
+
T extends
|
| 226 |
+
| ConstructorOfATypedSvelteComponent
|
| 227 |
+
| (typeof import('svelte') extends { mount: any }
|
| 228 |
+
? // @ts-ignore svelte.Component doesn't exist in Svelte 4
|
| 229 |
+
import('svelte').Component<any, any, any>
|
| 230 |
+
: never)
|
| 231 |
+
| null
|
| 232 |
+
| undefined
|
| 233 |
+
>(
|
| 234 |
+
type: T
|
| 235 |
+
): NonNullable<
|
| 236 |
+
T extends ConstructorOfATypedSvelteComponent
|
| 237 |
+
? T
|
| 238 |
+
: typeof import('svelte') extends { mount: any }
|
| 239 |
+
? // @ts-ignore svelte.Component doesn't exist in Svelte 4
|
| 240 |
+
T extends import('svelte').Component<
|
| 241 |
+
infer Props extends Record<string, any>,
|
| 242 |
+
infer Exports extends Record<string, any>,
|
| 243 |
+
infer Bindings extends string
|
| 244 |
+
>
|
| 245 |
+
? new (
|
| 246 |
+
options: import('svelte').ComponentConstructorOptions<Props>
|
| 247 |
+
) => import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> &
|
| 248 |
+
Exports & { $$bindings: Bindings }
|
| 249 |
+
: never
|
| 250 |
+
: never
|
| 251 |
+
>;
|
| 252 |
+
|
| 253 |
+
declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown> | Iterable<unknown>>(
|
| 254 |
+
// Svelte 5 allows undefined or null here, Svelte 4 doesn't
|
| 255 |
+
array: T | (typeof import('svelte') extends { mount: any } ? (undefined | null) : never)
|
| 256 |
+
): T extends ArrayLike<infer U> ? U[] : T extends Iterable<infer U> ? Iterable<U> : any[];
|
| 257 |
+
|
| 258 |
+
type __sveltets_2_PropsWithChildren<Props, Slots> = Props &
|
| 259 |
+
(Slots extends { default: any }
|
| 260 |
+
// This is unfortunate because it means "accepts no props" turns into "accepts any prop"
|
| 261 |
+
// but the alternative is non-fixable type errors because of the way TypeScript index
|
| 262 |
+
// signatures work (they will always take precedence and make an impossible-to-satisfy children type).
|
| 263 |
+
? Props extends Record<string, never>
|
| 264 |
+
? any
|
| 265 |
+
: { children?: any }
|
| 266 |
+
: {});
|
| 267 |
+
declare function __sveltets_2_runes_constructor<Props extends {}>(render: {props: Props }): import("svelte").ComponentConstructorOptions<Props>;
|
| 268 |
+
|
| 269 |
+
declare function __sveltets_2_get_set_binding<T>(get: (() => T) | null | undefined, set: (t: T) => void): T;
|
| 270 |
+
|
| 271 |
+
declare function __sveltets_$$bindings<Bindings extends string[]>(...bindings: Bindings): Bindings[number];
|
| 272 |
+
|
| 273 |
+
declare function __sveltets_2_fn_component<
|
| 274 |
+
Props extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
|
| 275 |
+
// @ts-ignore Svelte 5 only
|
| 276 |
+
>(klass: {props: Props, exports?: Exports, bindings?: Bindings }): import('svelte').Component<Props, Exports, Bindings>;
|
| 277 |
+
|
| 278 |
+
interface __sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
| 279 |
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & { $$bindings?: Bindings } & Exports;
|
| 280 |
+
(internal: unknown, props: Props extends Record<string, never> ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any };
|
| 281 |
+
z_$$bindings?: Bindings;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
declare function __sveltets_2_isomorphic_component<
|
| 285 |
+
Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
|
| 286 |
+
>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<Props, Events, Slots, Exports, Bindings>;
|
| 287 |
+
|
| 288 |
+
declare function __sveltets_2_isomorphic_component_slots<
|
| 289 |
+
Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
|
| 290 |
+
>(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;
|
tools/ui/node_modules/svelte-check/dist/src/svelte-shims.d.ts
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @ts-nocheck
|
| 2 |
+
// nocheck because we don't want to adjust this anymore (only used for Svelte 3)
|
| 3 |
+
// Whenever a ambient declaration changes, its number should be increased
|
| 4 |
+
// This way, we avoid the situation where multiple ambient versions of svelte2tsx
|
| 5 |
+
// are loaded and their declarations conflict each other
|
| 6 |
+
// See https://github.com/sveltejs/language-tools/issues/1059 for an example bug that stems from it
|
| 7 |
+
// If you change anything in this file, think about whether or not it should also be added to svelte-shims-v4.d.ts
|
| 8 |
+
|
| 9 |
+
// -- start svelte-ls-remove --
|
| 10 |
+
declare module '*.svelte' {
|
| 11 |
+
type _SvelteComponent<Props=any,Events=any,Slots=any> = import("svelte").SvelteComponentTyped<Props,Events,Slots>;
|
| 12 |
+
export default _SvelteComponent
|
| 13 |
+
}
|
| 14 |
+
// -- end svelte-ls-remove --
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* @deprecated This will be removed soon. Use `SvelteComponentTyped` instead:
|
| 18 |
+
* ```ts
|
| 19 |
+
* import type { SvelteComponentTyped } from 'svelte';
|
| 20 |
+
* ```
|
| 21 |
+
*/
|
| 22 |
+
declare class Svelte2TsxComponent<
|
| 23 |
+
Props extends {} = {},
|
| 24 |
+
Events extends {} = {},
|
| 25 |
+
Slots extends {} = {}
|
| 26 |
+
> {
|
| 27 |
+
// svelte2tsx-specific
|
| 28 |
+
/**
|
| 29 |
+
* @internal This is for type checking capabilities only
|
| 30 |
+
* and does not exist at runtime. Don't use this property.
|
| 31 |
+
*/
|
| 32 |
+
$$prop_def: Props;
|
| 33 |
+
/**
|
| 34 |
+
* @internal This is for type checking capabilities only
|
| 35 |
+
* and does not exist at runtime. Don't use this property.
|
| 36 |
+
*/
|
| 37 |
+
$$events_def: Events;
|
| 38 |
+
/**
|
| 39 |
+
* @internal This is for type checking capabilities only
|
| 40 |
+
* and does not exist at runtime. Don't use this property.
|
| 41 |
+
*/
|
| 42 |
+
$$slot_def: Slots;
|
| 43 |
+
// https://svelte.dev/docs#Client-side_component_API
|
| 44 |
+
constructor(options: Svelte2TsxComponentConstructorParameters<Props>);
|
| 45 |
+
/**
|
| 46 |
+
* Causes the callback function to be called whenever the component dispatches an event.
|
| 47 |
+
* A function is returned that will remove the event listener when called.
|
| 48 |
+
*/
|
| 49 |
+
$on<K extends keyof Events & string>(event: K, handler: ((e: Events[K]) => any) | null | undefined): () => void;
|
| 50 |
+
/**
|
| 51 |
+
* Removes a component from the DOM and triggers any `onDestroy` handlers.
|
| 52 |
+
*/
|
| 53 |
+
$destroy(): void;
|
| 54 |
+
/**
|
| 55 |
+
* Programmatically sets props on an instance.
|
| 56 |
+
* `component.$set({ x: 1 })` is equivalent to `x = 1` inside the component's `<script>` block.
|
| 57 |
+
* Calling this method schedules an update for the next microtask — the DOM is __not__ updated synchronously.
|
| 58 |
+
*/
|
| 59 |
+
$set(props?: Partial<Props>): void;
|
| 60 |
+
// From SvelteComponent(Dev) definition
|
| 61 |
+
$$: any;
|
| 62 |
+
$capture_state(): void;
|
| 63 |
+
$inject_state(): void;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/** @deprecated PRIVATE API, DO NOT USE, REMOVED SOON */
|
| 67 |
+
interface Svelte2TsxComponentConstructorParameters<Props extends {}> {
|
| 68 |
+
/**
|
| 69 |
+
* An HTMLElement to render to. This option is required.
|
| 70 |
+
*/
|
| 71 |
+
target: Element | Document | ShadowRoot;
|
| 72 |
+
/**
|
| 73 |
+
* A child of `target` to render the component immediately before.
|
| 74 |
+
*/
|
| 75 |
+
anchor?: Element;
|
| 76 |
+
/**
|
| 77 |
+
* An object of properties to supply to the component.
|
| 78 |
+
*/
|
| 79 |
+
props?: Props;
|
| 80 |
+
context?: Map<any, any>;
|
| 81 |
+
hydrate?: boolean;
|
| 82 |
+
intro?: boolean;
|
| 83 |
+
$$inline?: boolean;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
|
| 87 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 88 |
+
type SvelteComponentConstructor<T, U extends import('svelte').ComponentConstructorOptions<any>> = new (options: U) => T;
|
| 89 |
+
|
| 90 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 91 |
+
type SvelteActionReturnType = {
|
| 92 |
+
update?: (args: any) => void,
|
| 93 |
+
destroy?: () => void
|
| 94 |
+
} | void
|
| 95 |
+
|
| 96 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 97 |
+
type SvelteTransitionConfig = {
|
| 98 |
+
delay?: number,
|
| 99 |
+
duration?: number,
|
| 100 |
+
easing?: (t: number) => number,
|
| 101 |
+
css?: (t: number, u: number) => string,
|
| 102 |
+
tick?: (t: number, u: number) => void
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 106 |
+
type SvelteTransitionReturnType = SvelteTransitionConfig | (() => SvelteTransitionConfig)
|
| 107 |
+
|
| 108 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 109 |
+
type SvelteAnimationReturnType = {
|
| 110 |
+
delay?: number,
|
| 111 |
+
duration?: number,
|
| 112 |
+
easing?: (t: number) => number,
|
| 113 |
+
css?: (t: number, u: number) => string,
|
| 114 |
+
tick?: (t: number, u: number) => void
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 118 |
+
type SvelteWithOptionalProps<Props, Keys extends keyof Props> = Omit<Props, Keys> & Partial<Pick<Props, Keys>>;
|
| 119 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 120 |
+
type SvelteAllProps = { [index: string]: any }
|
| 121 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 122 |
+
type SveltePropsAnyFallback<Props> = {[K in keyof Props]: Props[K] extends never ? never : Props[K] extends undefined ? any : Props[K]}
|
| 123 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 124 |
+
type SvelteSlotsAnyFallback<Slots> = {[K in keyof Slots]: {[S in keyof Slots[K]]: Slots[K][S] extends undefined ? any : Slots[K][S]}}
|
| 125 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 126 |
+
type SvelteRestProps = { [index: string]: any }
|
| 127 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 128 |
+
type SvelteSlots = { [index: string]: any }
|
| 129 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 130 |
+
type SvelteStore<T> = { subscribe: (run: (value: T) => any, invalidate?: any) => any }
|
| 131 |
+
|
| 132 |
+
// Forces TypeScript to look into the type which results in a better representation of it
|
| 133 |
+
// which helps for error messages and is necessary for d.ts file transformation so that
|
| 134 |
+
// no ambient type references are left in the output
|
| 135 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 136 |
+
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
| 137 |
+
|
| 138 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 139 |
+
type KeysMatching<Obj, V> = {[K in keyof Obj]-?: Obj[K] extends V ? K : never}[keyof Obj]
|
| 140 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 141 |
+
declare type __sveltets_2_CustomEvents<T> = {[K in KeysMatching<T, CustomEvent>]: T[K] extends CustomEvent ? T[K]['detail']: T[K]}
|
| 142 |
+
|
| 143 |
+
declare function __sveltets_2_ensureRightProps<Props>(props: Props): {};
|
| 144 |
+
declare function __sveltets_2_instanceOf<T = any>(type: AConstructorTypeOf<T>): T;
|
| 145 |
+
declare function __sveltets_2_allPropsType(): SvelteAllProps
|
| 146 |
+
declare function __sveltets_2_restPropsType(): SvelteRestProps
|
| 147 |
+
declare function __sveltets_2_slotsType<Slots, Key extends keyof Slots>(slots: Slots): Record<Key, boolean>;
|
| 148 |
+
|
| 149 |
+
// Overload of the following two functions is necessary.
|
| 150 |
+
// An empty array of optionalProps makes OptionalProps type any, which means we lose the prop typing.
|
| 151 |
+
// optionalProps need to be first or its type cannot be infered correctly.
|
| 152 |
+
|
| 153 |
+
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}>(
|
| 154 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 155 |
+
): {props: Expand<SveltePropsAnyFallback<Props>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
| 156 |
+
declare function __sveltets_2_partial<Props = {}, Events = {}, Slots = {}, OptionalProps extends keyof Props = any>(
|
| 157 |
+
optionalProps: OptionalProps[],
|
| 158 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 159 |
+
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps>>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
| 160 |
+
|
| 161 |
+
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}>(
|
| 162 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 163 |
+
): {props: Expand<SveltePropsAnyFallback<Props> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
| 164 |
+
declare function __sveltets_2_partial_with_any<Props = {}, Events = {}, Slots = {}, OptionalProps extends keyof Props = any>(
|
| 165 |
+
optionalProps: OptionalProps[],
|
| 166 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 167 |
+
): {props: Expand<SvelteWithOptionalProps<SveltePropsAnyFallback<Props>, OptionalProps> & SvelteAllProps>, events: Events, slots: Expand<SvelteSlotsAnyFallback<Slots>> }
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
declare function __sveltets_2_with_any<Props = {}, Events = {}, Slots = {}>(
|
| 171 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 172 |
+
): {props: Expand<Props & SvelteAllProps>, events: Events, slots: Slots }
|
| 173 |
+
|
| 174 |
+
declare function __sveltets_2_with_any_event<Props = {}, Events = {}, Slots = {}>(
|
| 175 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 176 |
+
): {props: Props, events: Events & {[evt: string]: CustomEvent<any>;}, slots: Slots }
|
| 177 |
+
|
| 178 |
+
declare function __sveltets_2_store_get<T = any>(store: SvelteStore<T>): T
|
| 179 |
+
declare function __sveltets_2_store_get<Store extends SvelteStore<any> | undefined | null>(store: Store): Store extends SvelteStore<infer T> ? T : Store;
|
| 180 |
+
declare function __sveltets_2_any(dummy: any): any;
|
| 181 |
+
// declare function __sveltets_1_empty(...dummy: any[]): {};
|
| 182 |
+
// declare function __sveltets_1_componentType(): AConstructorTypeOf<import("svelte").SvelteComponentTyped<any, any, any>>
|
| 183 |
+
declare function __sveltets_2_invalidate<T>(getValue: () => T): T
|
| 184 |
+
|
| 185 |
+
declare function __sveltets_2_mapWindowEvent<K extends keyof HTMLBodyElementEventMap>(
|
| 186 |
+
event: K
|
| 187 |
+
): HTMLBodyElementEventMap[K];
|
| 188 |
+
declare function __sveltets_2_mapBodyEvent<K extends keyof WindowEventMap>(
|
| 189 |
+
event: K
|
| 190 |
+
): WindowEventMap[K];
|
| 191 |
+
declare function __sveltets_2_mapElementEvent<K extends keyof HTMLElementEventMap>(
|
| 192 |
+
event: K
|
| 193 |
+
): HTMLElementEventMap[K];
|
| 194 |
+
|
| 195 |
+
declare function __sveltets_2_bubbleEventDef<Events, K extends keyof Events>(
|
| 196 |
+
events: Events, eventKey: K
|
| 197 |
+
): Events[K];
|
| 198 |
+
declare function __sveltets_2_bubbleEventDef(
|
| 199 |
+
events: any, eventKey: string
|
| 200 |
+
): any;
|
| 201 |
+
|
| 202 |
+
declare const __sveltets_2_customEvent: CustomEvent<any>;
|
| 203 |
+
declare function __sveltets_2_toEventTypings<Typings>(): {[Key in keyof Typings]: CustomEvent<Typings[Key]>};
|
| 204 |
+
|
| 205 |
+
declare function __sveltets_2_unionType<T1, T2>(t1: T1, t2: T2): T1 | T2;
|
| 206 |
+
declare function __sveltets_2_unionType<T1, T2, T3>(t1: T1, t2: T2, t3: T3): T1 | T2 | T3;
|
| 207 |
+
declare function __sveltets_2_unionType<T1, T2, T3, T4>(t1: T1, t2: T2, t3: T3, t4: T4): T1 | T2 | T3 | T4;
|
| 208 |
+
declare function __sveltets_2_unionType(...types: any[]): any;
|
| 209 |
+
|
| 210 |
+
declare function __sveltets_2_createSvelte2TsxComponent<Props, Events, Slots>(
|
| 211 |
+
render: {props: Props, events: Events, slots: Slots }
|
| 212 |
+
): SvelteComponentConstructor<import("svelte").SvelteComponentTyped<Props, Events, Slots>,import('svelte').ComponentConstructorOptions<Props>>;
|
| 213 |
+
|
| 214 |
+
declare function __sveltets_2_unwrapArr<T>(arr: ArrayLike<T>): T
|
| 215 |
+
declare function __sveltets_2_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T
|
| 216 |
+
|
| 217 |
+
// v2
|
| 218 |
+
declare function __sveltets_2_createCreateSlot<Slots = Record<string, Record<string, any>>>(): <SlotName extends keyof Slots>(slotName: SlotName, attrs: Slots[SlotName]) => Record<string, any>;
|
| 219 |
+
declare function __sveltets_2_createComponentAny(props: Record<string, any>): import("svelte").SvelteComponentTyped<any, any, any>;
|
| 220 |
+
|
| 221 |
+
declare function __sveltets_2_any(...dummy: any[]): any;
|
| 222 |
+
declare function __sveltets_2_empty(...dummy: any[]): {};
|
| 223 |
+
declare 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;
|
| 224 |
+
declare function __sveltets_2_nonNullable<T>(type: T): NonNullable<T>;
|
| 225 |
+
|
| 226 |
+
declare function __sveltets_2_cssProp(prop: Record<string, any>): {};
|
| 227 |
+
|
| 228 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 229 |
+
type __sveltets_2_SvelteAnimationReturnType = {
|
| 230 |
+
delay?: number,
|
| 231 |
+
duration?: number,
|
| 232 |
+
easing?: (t: number) => number,
|
| 233 |
+
css?: (t: number, u: number) => string,
|
| 234 |
+
tick?: (t: number, u: number) => void
|
| 235 |
+
}
|
| 236 |
+
declare var __sveltets_2_AnimationMove: { from: DOMRect, to: DOMRect }
|
| 237 |
+
declare function __sveltets_2_ensureAnimation(animationCall: __sveltets_2_SvelteAnimationReturnType): {};
|
| 238 |
+
|
| 239 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 240 |
+
type __sveltets_2_SvelteActionReturnType = {
|
| 241 |
+
update?: (args: any) => void,
|
| 242 |
+
destroy?: () => void,
|
| 243 |
+
$$_attributes?: Record<string, any>,
|
| 244 |
+
} | void
|
| 245 |
+
declare function __sveltets_2_ensureAction<T extends __sveltets_2_SvelteActionReturnType>(actionCall: T): T extends {$$_attributes?: any} ? T['$$_attributes'] : {};
|
| 246 |
+
|
| 247 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 248 |
+
type __sveltets_2_SvelteTransitionConfig = {
|
| 249 |
+
delay?: number,
|
| 250 |
+
duration?: number,
|
| 251 |
+
easing?: (t: number) => number,
|
| 252 |
+
css?: (t: number, u: number) => string,
|
| 253 |
+
tick?: (t: number, u: number) => void
|
| 254 |
+
}
|
| 255 |
+
/** @internal PRIVATE API, DO NOT USE */
|
| 256 |
+
type __sveltets_2_SvelteTransitionReturnType = __sveltets_2_SvelteTransitionConfig | (() => __sveltets_2_SvelteTransitionConfig)
|
| 257 |
+
declare function __sveltets_2_ensureTransition(transitionCall: __sveltets_2_SvelteTransitionReturnType): {};
|
| 258 |
+
|
| 259 |
+
// Includes undefined and null for all types as all usages also allow these
|
| 260 |
+
declare function __sveltets_2_ensureType<T>(type: AConstructorTypeOf<T>, el: T | undefined | null): {};
|
| 261 |
+
declare function __sveltets_2_ensureType<T1, T2>(type1: AConstructorTypeOf<T1>, type2: AConstructorTypeOf<T2>, el: T1 | T2 | undefined | null): {};
|
| 262 |
+
|
| 263 |
+
// The following is necessary because there are two clashing errors that can't be solved at the same time
|
| 264 |
+
// when using Svelte2TsxComponent, more precisely the event typings in
|
| 265 |
+
// __sveltets_2_ensureComponent<T extends new (..) => _SvelteComponent<any,||any||<-this,any>>(type: T): T;
|
| 266 |
+
// If we type it as "any", we have an error when using sth like {a: CustomEvent<any>}
|
| 267 |
+
// If we type it as "{}", we have an error when using sth like {[evt: string]: CustomEvent<any>}
|
| 268 |
+
// If we type it as "unknown", we get all kinds of follow up errors which we want to avoid
|
| 269 |
+
// Therefore introduce two more base classes just for this case.
|
| 270 |
+
/**
|
| 271 |
+
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT
|
| 272 |
+
*/
|
| 273 |
+
declare type ATypedSvelteComponent = {
|
| 274 |
+
/**
|
| 275 |
+
* @internal This is for type checking capabilities only
|
| 276 |
+
* and does not exist at runtime. Don't use this property.
|
| 277 |
+
*/
|
| 278 |
+
$$prop_def: any;
|
| 279 |
+
/**
|
| 280 |
+
* @internal This is for type checking capabilities only
|
| 281 |
+
* and does not exist at runtime. Don't use this property.
|
| 282 |
+
*/
|
| 283 |
+
$$events_def: any;
|
| 284 |
+
/**
|
| 285 |
+
* @internal This is for type checking capabilities only
|
| 286 |
+
* and does not exist at runtime. Don't use this property.
|
| 287 |
+
*/
|
| 288 |
+
$$slot_def: any;
|
| 289 |
+
|
| 290 |
+
$on(event: string, handler: ((e: any) => any) | null | undefined): () => void;
|
| 291 |
+
}
|
| 292 |
+
/**
|
| 293 |
+
* Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
|
| 294 |
+
*
|
| 295 |
+
* If you're looking for the type of a Svelte Component, use `SvelteComponentTyped` and `ComponentType` instead:
|
| 296 |
+
*
|
| 297 |
+
* ```ts
|
| 298 |
+
* import type { ComponentType, SvelteComponentTyped } from "svelte";
|
| 299 |
+
* let myComponentConstructor: ComponentType<SvelteComponentTyped> = ..;
|
| 300 |
+
* ```
|
| 301 |
+
*/
|
| 302 |
+
declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
|
| 303 |
+
declare function __sveltets_2_ensureComponent<T extends ConstructorOfATypedSvelteComponent | null | undefined>(type: T): NonNullable<T>;
|
| 304 |
+
|
| 305 |
+
declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown>>(array: T): T extends ArrayLike<infer U> ? U[] : any[];
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2012 Paul Miller (https://paulmillr.com), Elan Shanker
|
| 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
|
| 13 |
+
all 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
|
| 21 |
+
THE SOFTWARE.
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Chokidar [](https://github.com/paulmillr/chokidar)
|
| 2 |
+
|
| 3 |
+
> Minimal and efficient cross-platform file watching library
|
| 4 |
+
|
| 5 |
+
## Why?
|
| 6 |
+
|
| 7 |
+
There are many reasons to prefer Chokidar to raw fs.watch / fs.watchFile in 2024:
|
| 8 |
+
|
| 9 |
+
- Events are properly reported
|
| 10 |
+
- macOS events report filenames
|
| 11 |
+
- events are not reported twice
|
| 12 |
+
- changes are reported as add / change / unlink instead of useless `rename`
|
| 13 |
+
- Atomic writes are supported, using `atomic` option
|
| 14 |
+
- Some file editors use them
|
| 15 |
+
- Chunked writes are supported, using `awaitWriteFinish` option
|
| 16 |
+
- Large files are commonly written in chunks
|
| 17 |
+
- File / dir filtering is supported
|
| 18 |
+
- Symbolic links are supported
|
| 19 |
+
- Recursive watching is always supported, instead of partial when using raw events
|
| 20 |
+
- Includes a way to limit recursion depth
|
| 21 |
+
|
| 22 |
+
Chokidar relies on the Node.js core `fs` module, but when using
|
| 23 |
+
`fs.watch` and `fs.watchFile` for watching, it normalizes the events it
|
| 24 |
+
receives, often checking for truth by getting file stats and/or dir contents.
|
| 25 |
+
The `fs.watch`-based implementation is the default, which
|
| 26 |
+
avoids polling and keeps CPU usage down. Be advised that chokidar will initiate
|
| 27 |
+
watchers recursively for everything within scope of the paths that have been
|
| 28 |
+
specified, so be judicious about not wasting system resources by watching much
|
| 29 |
+
more than needed. For some cases, `fs.watchFile`, which utilizes polling and uses more resources, is used.
|
| 30 |
+
|
| 31 |
+
Made for [Brunch](https://brunch.io/) in 2012,
|
| 32 |
+
it is now used in [~30 million repositories](https://www.npmjs.com/browse/depended/chokidar) and
|
| 33 |
+
has proven itself in production environments.
|
| 34 |
+
|
| 35 |
+
**Sep 2024 update:** v4 is out! It decreases dependency count from 13 to 1, removes
|
| 36 |
+
support for globs, adds support for ESM / Common.js modules, and bumps minimum node.js version from v8 to v14.
|
| 37 |
+
Check out [upgrading](#upgrading).
|
| 38 |
+
|
| 39 |
+
## Getting started
|
| 40 |
+
|
| 41 |
+
Install with npm:
|
| 42 |
+
|
| 43 |
+
```sh
|
| 44 |
+
npm install chokidar
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
Use it in your code:
|
| 48 |
+
|
| 49 |
+
```javascript
|
| 50 |
+
import chokidar from 'chokidar';
|
| 51 |
+
|
| 52 |
+
// One-liner for current directory
|
| 53 |
+
chokidar.watch('.').on('all', (event, path) => {
|
| 54 |
+
console.log(event, path);
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
// Extended options
|
| 59 |
+
// ----------------
|
| 60 |
+
|
| 61 |
+
// Initialize watcher.
|
| 62 |
+
const watcher = chokidar.watch('file, dir, or array', {
|
| 63 |
+
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
|
| 64 |
+
persistent: true
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
// Something to use when events are received.
|
| 68 |
+
const log = console.log.bind(console);
|
| 69 |
+
// Add event listeners.
|
| 70 |
+
watcher
|
| 71 |
+
.on('add', path => log(`File ${path} has been added`))
|
| 72 |
+
.on('change', path => log(`File ${path} has been changed`))
|
| 73 |
+
.on('unlink', path => log(`File ${path} has been removed`));
|
| 74 |
+
|
| 75 |
+
// More possible events.
|
| 76 |
+
watcher
|
| 77 |
+
.on('addDir', path => log(`Directory ${path} has been added`))
|
| 78 |
+
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
| 79 |
+
.on('error', error => log(`Watcher error: ${error}`))
|
| 80 |
+
.on('ready', () => log('Initial scan complete. Ready for changes'))
|
| 81 |
+
.on('raw', (event, path, details) => { // internal
|
| 82 |
+
log('Raw event info:', event, path, details);
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
// 'add', 'addDir' and 'change' events also receive stat() results as second
|
| 86 |
+
// argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats
|
| 87 |
+
watcher.on('change', (path, stats) => {
|
| 88 |
+
if (stats) console.log(`File ${path} changed size to ${stats.size}`);
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
// Watch new files.
|
| 92 |
+
watcher.add('new-file');
|
| 93 |
+
watcher.add(['new-file-2', 'new-file-3']);
|
| 94 |
+
|
| 95 |
+
// Get list of actual paths being watched on the filesystem
|
| 96 |
+
let watchedPaths = watcher.getWatched();
|
| 97 |
+
|
| 98 |
+
// Un-watch some files.
|
| 99 |
+
await watcher.unwatch('new-file');
|
| 100 |
+
|
| 101 |
+
// Stop watching. The method is async!
|
| 102 |
+
await watcher.close().then(() => console.log('closed'));
|
| 103 |
+
|
| 104 |
+
// Full list of options. See below for descriptions.
|
| 105 |
+
// Do not use this example!
|
| 106 |
+
chokidar.watch('file', {
|
| 107 |
+
persistent: true,
|
| 108 |
+
|
| 109 |
+
// ignore .txt files
|
| 110 |
+
ignored: (file) => file.endsWith('.txt'),
|
| 111 |
+
// watch only .txt files
|
| 112 |
+
// ignored: (file, _stats) => _stats?.isFile() && !file.endsWith('.txt'),
|
| 113 |
+
|
| 114 |
+
awaitWriteFinish: true, // emit single event when chunked writes are completed
|
| 115 |
+
atomic: true, // emit proper events when "atomic writes" (mv _tmp file) are used
|
| 116 |
+
|
| 117 |
+
// The options also allow specifying custom intervals in ms
|
| 118 |
+
// awaitWriteFinish: {
|
| 119 |
+
// stabilityThreshold: 2000,
|
| 120 |
+
// pollInterval: 100
|
| 121 |
+
// },
|
| 122 |
+
// atomic: 100,
|
| 123 |
+
|
| 124 |
+
interval: 100,
|
| 125 |
+
binaryInterval: 300,
|
| 126 |
+
|
| 127 |
+
cwd: '.',
|
| 128 |
+
depth: 99,
|
| 129 |
+
|
| 130 |
+
followSymlinks: true,
|
| 131 |
+
ignoreInitial: false,
|
| 132 |
+
ignorePermissionErrors: false,
|
| 133 |
+
usePolling: false,
|
| 134 |
+
alwaysStat: false,
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
`chokidar.watch(paths, [options])`
|
| 140 |
+
|
| 141 |
+
* `paths` (string or array of strings). Paths to files, dirs to be watched
|
| 142 |
+
recursively.
|
| 143 |
+
* `options` (object) Options object as defined below:
|
| 144 |
+
|
| 145 |
+
#### Persistence
|
| 146 |
+
|
| 147 |
+
* `persistent` (default: `true`). Indicates whether the process
|
| 148 |
+
should continue to run as long as files are being watched.
|
| 149 |
+
|
| 150 |
+
#### Path filtering
|
| 151 |
+
|
| 152 |
+
* `ignored` function, regex, or path. Defines files/paths to be ignored.
|
| 153 |
+
The whole relative or absolute path is tested, not just filename. If a function with two arguments
|
| 154 |
+
is provided, it gets called twice per path - once with a single argument (the path), second
|
| 155 |
+
time with two arguments (the path and the
|
| 156 |
+
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
| 157 |
+
object of that path).
|
| 158 |
+
* `ignoreInitial` (default: `false`). If set to `false` then `add`/`addDir` events are also emitted for matching paths while
|
| 159 |
+
instantiating the watching as chokidar discovers these file paths (before the `ready` event).
|
| 160 |
+
* `followSymlinks` (default: `true`). When `false`, only the
|
| 161 |
+
symlinks themselves will be watched for changes instead of following
|
| 162 |
+
the link references and bubbling events through the link's path.
|
| 163 |
+
* `cwd` (no default). The base directory from which watch `paths` are to be
|
| 164 |
+
derived. Paths emitted with events will be relative to this.
|
| 165 |
+
|
| 166 |
+
#### Performance
|
| 167 |
+
|
| 168 |
+
* `usePolling` (default: `false`).
|
| 169 |
+
Whether to use fs.watchFile (backed by polling), or fs.watch. If polling
|
| 170 |
+
leads to high CPU utilization, consider setting this to `false`. It is
|
| 171 |
+
typically necessary to **set this to `true` to successfully watch files over
|
| 172 |
+
a network**, and it may be necessary to successfully watch files in other
|
| 173 |
+
non-standard situations. Setting to `true` explicitly on MacOS overrides the
|
| 174 |
+
`useFsEvents` default. You may also set the CHOKIDAR_USEPOLLING env variable
|
| 175 |
+
to true (1) or false (0) in order to override this option.
|
| 176 |
+
* _Polling-specific settings_ (effective when `usePolling: true`)
|
| 177 |
+
* `interval` (default: `100`). Interval of file system polling, in milliseconds. You may also
|
| 178 |
+
set the CHOKIDAR_INTERVAL env variable to override this option.
|
| 179 |
+
* `binaryInterval` (default: `300`). Interval of file system
|
| 180 |
+
polling for binary files.
|
| 181 |
+
([see list of binary extensions](https://github.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
|
| 182 |
+
* `alwaysStat` (default: `false`). If relying upon the
|
| 183 |
+
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
| 184 |
+
object that may get passed with `add`, `addDir`, and `change` events, set
|
| 185 |
+
this to `true` to ensure it is provided even in cases where it wasn't
|
| 186 |
+
already available from the underlying watch events.
|
| 187 |
+
* `depth` (default: `undefined`). If set, limits how many levels of
|
| 188 |
+
subdirectories will be traversed.
|
| 189 |
+
* `awaitWriteFinish` (default: `false`).
|
| 190 |
+
By default, the `add` event will fire when a file first appears on disk, before
|
| 191 |
+
the entire file has been written. Furthermore, in some cases some `change`
|
| 192 |
+
events will be emitted while the file is being written. In some cases,
|
| 193 |
+
especially when watching for large files there will be a need to wait for the
|
| 194 |
+
write operation to finish before responding to a file creation or modification.
|
| 195 |
+
Setting `awaitWriteFinish` to `true` (or a truthy value) will poll file size,
|
| 196 |
+
holding its `add` and `change` events until the size does not change for a
|
| 197 |
+
configurable amount of time. The appropriate duration setting is heavily
|
| 198 |
+
dependent on the OS and hardware. For accurate detection this parameter should
|
| 199 |
+
be relatively high, making file watching much less responsive.
|
| 200 |
+
Use with caution.
|
| 201 |
+
* *`options.awaitWriteFinish` can be set to an object in order to adjust
|
| 202 |
+
timing params:*
|
| 203 |
+
* `awaitWriteFinish.stabilityThreshold` (default: 2000). Amount of time in
|
| 204 |
+
milliseconds for a file size to remain constant before emitting its event.
|
| 205 |
+
* `awaitWriteFinish.pollInterval` (default: 100). File size polling interval, in milliseconds.
|
| 206 |
+
|
| 207 |
+
#### Errors
|
| 208 |
+
|
| 209 |
+
* `ignorePermissionErrors` (default: `false`). Indicates whether to watch files
|
| 210 |
+
that don't have read permissions if possible. If watching fails due to `EPERM`
|
| 211 |
+
or `EACCES` with this set to `true`, the errors will be suppressed silently.
|
| 212 |
+
* `atomic` (default: `true` if `useFsEvents` and `usePolling` are `false`).
|
| 213 |
+
Automatically filters out artifacts that occur when using editors that use
|
| 214 |
+
"atomic writes" instead of writing directly to the source file. If a file is
|
| 215 |
+
re-added within 100 ms of being deleted, Chokidar emits a `change` event
|
| 216 |
+
rather than `unlink` then `add`. If the default of 100 ms does not work well
|
| 217 |
+
for you, you can override it by setting `atomic` to a custom value, in
|
| 218 |
+
milliseconds.
|
| 219 |
+
|
| 220 |
+
### Methods & Events
|
| 221 |
+
|
| 222 |
+
`chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:
|
| 223 |
+
|
| 224 |
+
* `.add(path / paths)`: Add files, directories for tracking.
|
| 225 |
+
Takes an array of strings or just one string.
|
| 226 |
+
* `.on(event, callback)`: Listen for an FS event.
|
| 227 |
+
Available events: `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `ready`,
|
| 228 |
+
`raw`, `error`.
|
| 229 |
+
Additionally `all` is available which gets emitted with the underlying event
|
| 230 |
+
name and path for every event other than `ready`, `raw`, and `error`. `raw` is internal, use it carefully.
|
| 231 |
+
* `.unwatch(path / paths)`: Stop watching files or directories.
|
| 232 |
+
Takes an array of strings or just one string.
|
| 233 |
+
* `.close()`: **async** Removes all listeners from watched files. Asynchronous, returns Promise. Use with `await` to ensure bugs don't happen.
|
| 234 |
+
* `.getWatched()`: Returns an object representing all the paths on the file
|
| 235 |
+
system being watched by this `FSWatcher` instance. The object's keys are all the
|
| 236 |
+
directories (using absolute paths unless the `cwd` option was used), and the
|
| 237 |
+
values are arrays of the names of the items contained in each directory.
|
| 238 |
+
|
| 239 |
+
### CLI
|
| 240 |
+
|
| 241 |
+
Check out third party [chokidar-cli](https://github.com/open-cli-tools/chokidar-cli),
|
| 242 |
+
which allows to execute a command on each change, or get a stdio stream of change events.
|
| 243 |
+
|
| 244 |
+
## Troubleshooting
|
| 245 |
+
|
| 246 |
+
Sometimes, Chokidar runs out of file handles, causing `EMFILE` and `ENOSP` errors:
|
| 247 |
+
|
| 248 |
+
* `bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell`
|
| 249 |
+
* `Error: watch /home/ ENOSPC`
|
| 250 |
+
|
| 251 |
+
There are two things that can cause it.
|
| 252 |
+
|
| 253 |
+
1. Exhausted file handles for generic fs operations
|
| 254 |
+
- Can be solved by using [graceful-fs](https://www.npmjs.com/package/graceful-fs),
|
| 255 |
+
which can monkey-patch native `fs` module used by chokidar: `let fs = require('fs'); let grfs = require('graceful-fs'); grfs.gracefulify(fs);`
|
| 256 |
+
- Can also be solved by tuning OS: `echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`.
|
| 257 |
+
2. Exhausted file handles for `fs.watch`
|
| 258 |
+
- Can't seem to be solved by graceful-fs or OS tuning
|
| 259 |
+
- It's possible to start using `usePolling: true`, which will switch backend to resource-intensive `fs.watchFile`
|
| 260 |
+
|
| 261 |
+
All fsevents-related issues (`WARN optional dep failed`, `fsevents is not a constructor`) are solved by upgrading to v4+.
|
| 262 |
+
|
| 263 |
+
## Changelog
|
| 264 |
+
|
| 265 |
+
- **v4 (Sep 2024):** remove glob support and bundled fsevents. Decrease dependency count from 13 to 1. Rewrite in typescript. Bumps minimum node.js requirement to v14+
|
| 266 |
+
- **v3 (Apr 2019):** massive CPU & RAM consumption improvements; reduces deps / package size by a factor of 17x and bumps Node.js requirement to v8.16+.
|
| 267 |
+
- **v2 (Dec 2017):** globs are now posix-style-only. Tons of bugfixes.
|
| 268 |
+
- **v1 (Apr 2015):** glob support, symlink support, tons of bugfixes. Node 0.8+ is supported
|
| 269 |
+
- **v0.1 (Apr 2012):** Initial release, extracted from [Brunch](https://github.com/brunch/brunch/blob/9847a065aea300da99bd0753f90354cde9de1261/src/helpers.coffee#L66)
|
| 270 |
+
|
| 271 |
+
### Upgrading
|
| 272 |
+
|
| 273 |
+
If you've used globs before and want do replicate the functionality with v4:
|
| 274 |
+
|
| 275 |
+
```js
|
| 276 |
+
// v3
|
| 277 |
+
chok.watch('**/*.js');
|
| 278 |
+
chok.watch("./directory/**/*");
|
| 279 |
+
|
| 280 |
+
// v4
|
| 281 |
+
chok.watch('.', {
|
| 282 |
+
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
|
| 283 |
+
});
|
| 284 |
+
chok.watch('./directory');
|
| 285 |
+
|
| 286 |
+
// other way
|
| 287 |
+
import { glob } from 'node:fs/promises';
|
| 288 |
+
const watcher = watch(await Array.fromAsync(glob('**/*.js')));
|
| 289 |
+
|
| 290 |
+
// unwatching
|
| 291 |
+
// v3
|
| 292 |
+
chok.unwatch('**/*.js');
|
| 293 |
+
// v4
|
| 294 |
+
chok.unwatch(await glob('**/*.js'));
|
| 295 |
+
```
|
| 296 |
+
|
| 297 |
+
## Also
|
| 298 |
+
|
| 299 |
+
Why was chokidar named this way? What's the meaning behind it?
|
| 300 |
+
|
| 301 |
+
>Chowkidar is a transliteration of a Hindi word meaning 'watchman, gatekeeper', चौकीदार. This ultimately comes from Sanskrit _ चतुष्क_ (crossway, quadrangle, consisting-of-four). This word is also used in other languages like Urdu as (چوکیدار) which is widely used in Pakistan and India.
|
| 302 |
+
|
| 303 |
+
## License
|
| 304 |
+
|
| 305 |
+
MIT (c) Paul Miller (<https://paulmillr.com>), see [LICENSE](LICENSE) file.
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/handler.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
|
| 2 |
+
import type { FSWatcher, WatchHelper, Throttler } from './index.js';
|
| 3 |
+
import type { EntryInfo } from 'readdirp';
|
| 4 |
+
export type Path = string;
|
| 5 |
+
export declare const STR_DATA = "data";
|
| 6 |
+
export declare const STR_END = "end";
|
| 7 |
+
export declare const STR_CLOSE = "close";
|
| 8 |
+
export declare const EMPTY_FN: () => void;
|
| 9 |
+
export declare const IDENTITY_FN: (val: unknown) => unknown;
|
| 10 |
+
export declare const isWindows: boolean;
|
| 11 |
+
export declare const isMacos: boolean;
|
| 12 |
+
export declare const isLinux: boolean;
|
| 13 |
+
export declare const isFreeBSD: boolean;
|
| 14 |
+
export declare const isIBMi: boolean;
|
| 15 |
+
export declare const EVENTS: {
|
| 16 |
+
readonly ALL: "all";
|
| 17 |
+
readonly READY: "ready";
|
| 18 |
+
readonly ADD: "add";
|
| 19 |
+
readonly CHANGE: "change";
|
| 20 |
+
readonly ADD_DIR: "addDir";
|
| 21 |
+
readonly UNLINK: "unlink";
|
| 22 |
+
readonly UNLINK_DIR: "unlinkDir";
|
| 23 |
+
readonly RAW: "raw";
|
| 24 |
+
readonly ERROR: "error";
|
| 25 |
+
};
|
| 26 |
+
export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
|
| 27 |
+
export type FsWatchContainer = {
|
| 28 |
+
listeners: (path: string) => void | Set<any>;
|
| 29 |
+
errHandlers: (err: unknown) => void | Set<any>;
|
| 30 |
+
rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
|
| 31 |
+
watcher: NativeFsWatcher;
|
| 32 |
+
watcherUnusable?: boolean;
|
| 33 |
+
};
|
| 34 |
+
export interface WatchHandlers {
|
| 35 |
+
listener: (path: string) => void;
|
| 36 |
+
errHandler: (err: unknown) => void;
|
| 37 |
+
rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
|
| 38 |
+
}
|
| 39 |
+
/**
|
| 40 |
+
* @mixin
|
| 41 |
+
*/
|
| 42 |
+
export declare class NodeFsHandler {
|
| 43 |
+
fsw: FSWatcher;
|
| 44 |
+
_boundHandleError: (error: unknown) => void;
|
| 45 |
+
constructor(fsW: FSWatcher);
|
| 46 |
+
/**
|
| 47 |
+
* Watch file for changes with fs_watchFile or fs_watch.
|
| 48 |
+
* @param path to file or dir
|
| 49 |
+
* @param listener on fs change
|
| 50 |
+
* @returns closer for the watcher instance
|
| 51 |
+
*/
|
| 52 |
+
_watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
|
| 53 |
+
/**
|
| 54 |
+
* Watch a file and emit add event if warranted.
|
| 55 |
+
* @returns closer for the watcher instance
|
| 56 |
+
*/
|
| 57 |
+
_handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
|
| 58 |
+
/**
|
| 59 |
+
* Handle symlinks encountered while reading a dir.
|
| 60 |
+
* @param entry returned by readdirp
|
| 61 |
+
* @param directory path of dir being read
|
| 62 |
+
* @param path of this item
|
| 63 |
+
* @param item basename of this item
|
| 64 |
+
* @returns true if no more processing is needed for this entry.
|
| 65 |
+
*/
|
| 66 |
+
_handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
|
| 67 |
+
_handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
|
| 68 |
+
/**
|
| 69 |
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
| 70 |
+
* @param dir fs path
|
| 71 |
+
* @param stats
|
| 72 |
+
* @param initialAdd
|
| 73 |
+
* @param depth relative to user-supplied path
|
| 74 |
+
* @param target child path targeted for watch
|
| 75 |
+
* @param wh Common watch helpers for this path
|
| 76 |
+
* @param realpath
|
| 77 |
+
* @returns closer for the watcher instance.
|
| 78 |
+
*/
|
| 79 |
+
_handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
|
| 80 |
+
/**
|
| 81 |
+
* Handle added file, directory, or glob pattern.
|
| 82 |
+
* Delegates call to _handleFile / _handleDir after checks.
|
| 83 |
+
* @param path to file or ir
|
| 84 |
+
* @param initialAdd was the file added at watch instantiation?
|
| 85 |
+
* @param priorWh depth relative to user-supplied path
|
| 86 |
+
* @param depth Child path actually targeted for watch
|
| 87 |
+
* @param target Child path actually targeted for watch
|
| 88 |
+
*/
|
| 89 |
+
_addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
|
| 90 |
+
}
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/handler.js
ADDED
|
@@ -0,0 +1,629 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
import { watchFile, unwatchFile, watch as fs_watch } from 'fs';
|
| 2 |
+
import { open, stat, lstat, realpath as fsrealpath } from 'fs/promises';
|
| 3 |
+
import * as sysPath from 'path';
|
| 4 |
+
import { type as osType } from 'os';
|
| 5 |
+
export const STR_DATA = 'data';
|
| 6 |
+
export const STR_END = 'end';
|
| 7 |
+
export const STR_CLOSE = 'close';
|
| 8 |
+
export const EMPTY_FN = () => { };
|
| 9 |
+
export const IDENTITY_FN = (val) => val;
|
| 10 |
+
const pl = process.platform;
|
| 11 |
+
export const isWindows = pl === 'win32';
|
| 12 |
+
export const isMacos = pl === 'darwin';
|
| 13 |
+
export const isLinux = pl === 'linux';
|
| 14 |
+
export const isFreeBSD = pl === 'freebsd';
|
| 15 |
+
export const isIBMi = osType() === 'OS400';
|
| 16 |
+
export const EVENTS = {
|
| 17 |
+
ALL: 'all',
|
| 18 |
+
READY: 'ready',
|
| 19 |
+
ADD: 'add',
|
| 20 |
+
CHANGE: 'change',
|
| 21 |
+
ADD_DIR: 'addDir',
|
| 22 |
+
UNLINK: 'unlink',
|
| 23 |
+
UNLINK_DIR: 'unlinkDir',
|
| 24 |
+
RAW: 'raw',
|
| 25 |
+
ERROR: 'error',
|
| 26 |
+
};
|
| 27 |
+
const EV = EVENTS;
|
| 28 |
+
const THROTTLE_MODE_WATCH = 'watch';
|
| 29 |
+
const statMethods = { lstat, stat };
|
| 30 |
+
const KEY_LISTENERS = 'listeners';
|
| 31 |
+
const KEY_ERR = 'errHandlers';
|
| 32 |
+
const KEY_RAW = 'rawEmitters';
|
| 33 |
+
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
| 34 |
+
// prettier-ignore
|
| 35 |
+
const binaryExtensions = new Set([
|
| 36 |
+
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
| 37 |
+
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
| 38 |
+
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
| 39 |
+
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
| 40 |
+
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
| 41 |
+
'dtshd', 'dvb', 'dwg', 'dxf',
|
| 42 |
+
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
| 43 |
+
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
| 44 |
+
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
| 45 |
+
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
| 46 |
+
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
| 47 |
+
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
| 48 |
+
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
| 49 |
+
'mobi', 'mov', 'movie', 'mp3',
|
| 50 |
+
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
| 51 |
+
'nef', 'npx', 'numbers', 'nupkg',
|
| 52 |
+
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
| 53 |
+
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
| 54 |
+
'potx', 'ppa', 'ppam',
|
| 55 |
+
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
| 56 |
+
'qt',
|
| 57 |
+
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
| 58 |
+
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
| 59 |
+
'stl', 'suo', 'sub', 'swf',
|
| 60 |
+
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
| 61 |
+
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
| 62 |
+
'viv', 'vob',
|
| 63 |
+
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
| 64 |
+
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
| 65 |
+
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
| 66 |
+
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
| 67 |
+
'z', 'zip', 'zipx',
|
| 68 |
+
]);
|
| 69 |
+
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
| 70 |
+
// TODO: emit errors properly. Example: EMFILE on Macos.
|
| 71 |
+
const foreach = (val, fn) => {
|
| 72 |
+
if (val instanceof Set) {
|
| 73 |
+
val.forEach(fn);
|
| 74 |
+
}
|
| 75 |
+
else {
|
| 76 |
+
fn(val);
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
const addAndConvert = (main, prop, item) => {
|
| 80 |
+
let container = main[prop];
|
| 81 |
+
if (!(container instanceof Set)) {
|
| 82 |
+
main[prop] = container = new Set([container]);
|
| 83 |
+
}
|
| 84 |
+
container.add(item);
|
| 85 |
+
};
|
| 86 |
+
const clearItem = (cont) => (key) => {
|
| 87 |
+
const set = cont[key];
|
| 88 |
+
if (set instanceof Set) {
|
| 89 |
+
set.clear();
|
| 90 |
+
}
|
| 91 |
+
else {
|
| 92 |
+
delete cont[key];
|
| 93 |
+
}
|
| 94 |
+
};
|
| 95 |
+
const delFromSet = (main, prop, item) => {
|
| 96 |
+
const container = main[prop];
|
| 97 |
+
if (container instanceof Set) {
|
| 98 |
+
container.delete(item);
|
| 99 |
+
}
|
| 100 |
+
else if (container === item) {
|
| 101 |
+
delete main[prop];
|
| 102 |
+
}
|
| 103 |
+
};
|
| 104 |
+
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
| 105 |
+
const FsWatchInstances = new Map();
|
| 106 |
+
/**
|
| 107 |
+
* Instantiates the fs_watch interface
|
| 108 |
+
* @param path to be watched
|
| 109 |
+
* @param options to be passed to fs_watch
|
| 110 |
+
* @param listener main event handler
|
| 111 |
+
* @param errHandler emits info about errors
|
| 112 |
+
* @param emitRaw emits raw event data
|
| 113 |
+
* @returns {NativeFsWatcher}
|
| 114 |
+
*/
|
| 115 |
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
| 116 |
+
const handleEvent = (rawEvent, evPath) => {
|
| 117 |
+
listener(path);
|
| 118 |
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
| 119 |
+
// emit based on events occurring for files from a directory's watcher in
|
| 120 |
+
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
| 121 |
+
if (evPath && path !== evPath) {
|
| 122 |
+
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
| 123 |
+
}
|
| 124 |
+
};
|
| 125 |
+
try {
|
| 126 |
+
return fs_watch(path, {
|
| 127 |
+
persistent: options.persistent,
|
| 128 |
+
}, handleEvent);
|
| 129 |
+
}
|
| 130 |
+
catch (error) {
|
| 131 |
+
errHandler(error);
|
| 132 |
+
return undefined;
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
/**
|
| 136 |
+
* Helper for passing fs_watch event data to a collection of listeners
|
| 137 |
+
* @param fullPath absolute path bound to fs_watch instance
|
| 138 |
+
*/
|
| 139 |
+
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
| 140 |
+
const cont = FsWatchInstances.get(fullPath);
|
| 141 |
+
if (!cont)
|
| 142 |
+
return;
|
| 143 |
+
foreach(cont[listenerType], (listener) => {
|
| 144 |
+
listener(val1, val2, val3);
|
| 145 |
+
});
|
| 146 |
+
};
|
| 147 |
+
/**
|
| 148 |
+
* Instantiates the fs_watch interface or binds listeners
|
| 149 |
+
* to an existing one covering the same file system entry
|
| 150 |
+
* @param path
|
| 151 |
+
* @param fullPath absolute path
|
| 152 |
+
* @param options to be passed to fs_watch
|
| 153 |
+
* @param handlers container for event listener functions
|
| 154 |
+
*/
|
| 155 |
+
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
| 156 |
+
const { listener, errHandler, rawEmitter } = handlers;
|
| 157 |
+
let cont = FsWatchInstances.get(fullPath);
|
| 158 |
+
let watcher;
|
| 159 |
+
if (!options.persistent) {
|
| 160 |
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
| 161 |
+
if (!watcher)
|
| 162 |
+
return;
|
| 163 |
+
return watcher.close.bind(watcher);
|
| 164 |
+
}
|
| 165 |
+
if (cont) {
|
| 166 |
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
| 167 |
+
addAndConvert(cont, KEY_ERR, errHandler);
|
| 168 |
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
| 169 |
+
}
|
| 170 |
+
else {
|
| 171 |
+
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
| 172 |
+
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
| 173 |
+
if (!watcher)
|
| 174 |
+
return;
|
| 175 |
+
watcher.on(EV.ERROR, async (error) => {
|
| 176 |
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
| 177 |
+
if (cont)
|
| 178 |
+
cont.watcherUnusable = true; // documented since Node 10.4.1
|
| 179 |
+
// Workaround for https://github.com/joyent/node/issues/4337
|
| 180 |
+
if (isWindows && error.code === 'EPERM') {
|
| 181 |
+
try {
|
| 182 |
+
const fd = await open(path, 'r');
|
| 183 |
+
await fd.close();
|
| 184 |
+
broadcastErr(error);
|
| 185 |
+
}
|
| 186 |
+
catch (err) {
|
| 187 |
+
// do nothing
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
else {
|
| 191 |
+
broadcastErr(error);
|
| 192 |
+
}
|
| 193 |
+
});
|
| 194 |
+
cont = {
|
| 195 |
+
listeners: listener,
|
| 196 |
+
errHandlers: errHandler,
|
| 197 |
+
rawEmitters: rawEmitter,
|
| 198 |
+
watcher,
|
| 199 |
+
};
|
| 200 |
+
FsWatchInstances.set(fullPath, cont);
|
| 201 |
+
}
|
| 202 |
+
// const index = cont.listeners.indexOf(listener);
|
| 203 |
+
// removes this instance's listeners and closes the underlying fs_watch
|
| 204 |
+
// instance if there are no more listeners left
|
| 205 |
+
return () => {
|
| 206 |
+
delFromSet(cont, KEY_LISTENERS, listener);
|
| 207 |
+
delFromSet(cont, KEY_ERR, errHandler);
|
| 208 |
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
| 209 |
+
if (isEmptySet(cont.listeners)) {
|
| 210 |
+
// Check to protect against issue gh-730.
|
| 211 |
+
// if (cont.watcherUnusable) {
|
| 212 |
+
cont.watcher.close();
|
| 213 |
+
// }
|
| 214 |
+
FsWatchInstances.delete(fullPath);
|
| 215 |
+
HANDLER_KEYS.forEach(clearItem(cont));
|
| 216 |
+
// @ts-ignore
|
| 217 |
+
cont.watcher = undefined;
|
| 218 |
+
Object.freeze(cont);
|
| 219 |
+
}
|
| 220 |
+
};
|
| 221 |
+
};
|
| 222 |
+
// fs_watchFile helpers
|
| 223 |
+
// object to hold per-process fs_watchFile instances
|
| 224 |
+
// (may be shared across chokidar FSWatcher instances)
|
| 225 |
+
const FsWatchFileInstances = new Map();
|
| 226 |
+
/**
|
| 227 |
+
* Instantiates the fs_watchFile interface or binds listeners
|
| 228 |
+
* to an existing one covering the same file system entry
|
| 229 |
+
* @param path to be watched
|
| 230 |
+
* @param fullPath absolute path
|
| 231 |
+
* @param options options to be passed to fs_watchFile
|
| 232 |
+
* @param handlers container for event listener functions
|
| 233 |
+
* @returns closer
|
| 234 |
+
*/
|
| 235 |
+
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
| 236 |
+
const { listener, rawEmitter } = handlers;
|
| 237 |
+
let cont = FsWatchFileInstances.get(fullPath);
|
| 238 |
+
// let listeners = new Set();
|
| 239 |
+
// let rawEmitters = new Set();
|
| 240 |
+
const copts = cont && cont.options;
|
| 241 |
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
| 242 |
+
// "Upgrade" the watcher to persistence or a quicker interval.
|
| 243 |
+
// This creates some unlikely edge case issues if the user mixes
|
| 244 |
+
// settings in a very weird way, but solving for those cases
|
| 245 |
+
// doesn't seem worthwhile for the added complexity.
|
| 246 |
+
// listeners = cont.listeners;
|
| 247 |
+
// rawEmitters = cont.rawEmitters;
|
| 248 |
+
unwatchFile(fullPath);
|
| 249 |
+
cont = undefined;
|
| 250 |
+
}
|
| 251 |
+
if (cont) {
|
| 252 |
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
| 253 |
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
| 254 |
+
}
|
| 255 |
+
else {
|
| 256 |
+
// TODO
|
| 257 |
+
// listeners.add(listener);
|
| 258 |
+
// rawEmitters.add(rawEmitter);
|
| 259 |
+
cont = {
|
| 260 |
+
listeners: listener,
|
| 261 |
+
rawEmitters: rawEmitter,
|
| 262 |
+
options,
|
| 263 |
+
watcher: watchFile(fullPath, options, (curr, prev) => {
|
| 264 |
+
foreach(cont.rawEmitters, (rawEmitter) => {
|
| 265 |
+
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
| 266 |
+
});
|
| 267 |
+
const currmtime = curr.mtimeMs;
|
| 268 |
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
| 269 |
+
foreach(cont.listeners, (listener) => listener(path, curr));
|
| 270 |
+
}
|
| 271 |
+
}),
|
| 272 |
+
};
|
| 273 |
+
FsWatchFileInstances.set(fullPath, cont);
|
| 274 |
+
}
|
| 275 |
+
// const index = cont.listeners.indexOf(listener);
|
| 276 |
+
// Removes this instance's listeners and closes the underlying fs_watchFile
|
| 277 |
+
// instance if there are no more listeners left.
|
| 278 |
+
return () => {
|
| 279 |
+
delFromSet(cont, KEY_LISTENERS, listener);
|
| 280 |
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
| 281 |
+
if (isEmptySet(cont.listeners)) {
|
| 282 |
+
FsWatchFileInstances.delete(fullPath);
|
| 283 |
+
unwatchFile(fullPath);
|
| 284 |
+
cont.options = cont.watcher = undefined;
|
| 285 |
+
Object.freeze(cont);
|
| 286 |
+
}
|
| 287 |
+
};
|
| 288 |
+
};
|
| 289 |
+
/**
|
| 290 |
+
* @mixin
|
| 291 |
+
*/
|
| 292 |
+
export class NodeFsHandler {
|
| 293 |
+
constructor(fsW) {
|
| 294 |
+
this.fsw = fsW;
|
| 295 |
+
this._boundHandleError = (error) => fsW._handleError(error);
|
| 296 |
+
}
|
| 297 |
+
/**
|
| 298 |
+
* Watch file for changes with fs_watchFile or fs_watch.
|
| 299 |
+
* @param path to file or dir
|
| 300 |
+
* @param listener on fs change
|
| 301 |
+
* @returns closer for the watcher instance
|
| 302 |
+
*/
|
| 303 |
+
_watchWithNodeFs(path, listener) {
|
| 304 |
+
const opts = this.fsw.options;
|
| 305 |
+
const directory = sysPath.dirname(path);
|
| 306 |
+
const basename = sysPath.basename(path);
|
| 307 |
+
const parent = this.fsw._getWatchedDir(directory);
|
| 308 |
+
parent.add(basename);
|
| 309 |
+
const absolutePath = sysPath.resolve(path);
|
| 310 |
+
const options = {
|
| 311 |
+
persistent: opts.persistent,
|
| 312 |
+
};
|
| 313 |
+
if (!listener)
|
| 314 |
+
listener = EMPTY_FN;
|
| 315 |
+
let closer;
|
| 316 |
+
if (opts.usePolling) {
|
| 317 |
+
const enableBin = opts.interval !== opts.binaryInterval;
|
| 318 |
+
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
| 319 |
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
| 320 |
+
listener,
|
| 321 |
+
rawEmitter: this.fsw._emitRaw,
|
| 322 |
+
});
|
| 323 |
+
}
|
| 324 |
+
else {
|
| 325 |
+
closer = setFsWatchListener(path, absolutePath, options, {
|
| 326 |
+
listener,
|
| 327 |
+
errHandler: this._boundHandleError,
|
| 328 |
+
rawEmitter: this.fsw._emitRaw,
|
| 329 |
+
});
|
| 330 |
+
}
|
| 331 |
+
return closer;
|
| 332 |
+
}
|
| 333 |
+
/**
|
| 334 |
+
* Watch a file and emit add event if warranted.
|
| 335 |
+
* @returns closer for the watcher instance
|
| 336 |
+
*/
|
| 337 |
+
_handleFile(file, stats, initialAdd) {
|
| 338 |
+
if (this.fsw.closed) {
|
| 339 |
+
return;
|
| 340 |
+
}
|
| 341 |
+
const dirname = sysPath.dirname(file);
|
| 342 |
+
const basename = sysPath.basename(file);
|
| 343 |
+
const parent = this.fsw._getWatchedDir(dirname);
|
| 344 |
+
// stats is always present
|
| 345 |
+
let prevStats = stats;
|
| 346 |
+
// if the file is already being watched, do nothing
|
| 347 |
+
if (parent.has(basename))
|
| 348 |
+
return;
|
| 349 |
+
const listener = async (path, newStats) => {
|
| 350 |
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
| 351 |
+
return;
|
| 352 |
+
if (!newStats || newStats.mtimeMs === 0) {
|
| 353 |
+
try {
|
| 354 |
+
const newStats = await stat(file);
|
| 355 |
+
if (this.fsw.closed)
|
| 356 |
+
return;
|
| 357 |
+
// Check that change event was not fired because of changed only accessTime.
|
| 358 |
+
const at = newStats.atimeMs;
|
| 359 |
+
const mt = newStats.mtimeMs;
|
| 360 |
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
| 361 |
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
| 362 |
+
}
|
| 363 |
+
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
| 364 |
+
this.fsw._closeFile(path);
|
| 365 |
+
prevStats = newStats;
|
| 366 |
+
const closer = this._watchWithNodeFs(file, listener);
|
| 367 |
+
if (closer)
|
| 368 |
+
this.fsw._addPathCloser(path, closer);
|
| 369 |
+
}
|
| 370 |
+
else {
|
| 371 |
+
prevStats = newStats;
|
| 372 |
+
}
|
| 373 |
+
}
|
| 374 |
+
catch (error) {
|
| 375 |
+
// Fix issues where mtime is null but file is still present
|
| 376 |
+
this.fsw._remove(dirname, basename);
|
| 377 |
+
}
|
| 378 |
+
// add is about to be emitted if file not already tracked in parent
|
| 379 |
+
}
|
| 380 |
+
else if (parent.has(basename)) {
|
| 381 |
+
// Check that change event was not fired because of changed only accessTime.
|
| 382 |
+
const at = newStats.atimeMs;
|
| 383 |
+
const mt = newStats.mtimeMs;
|
| 384 |
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
| 385 |
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
| 386 |
+
}
|
| 387 |
+
prevStats = newStats;
|
| 388 |
+
}
|
| 389 |
+
};
|
| 390 |
+
// kick off the watcher
|
| 391 |
+
const closer = this._watchWithNodeFs(file, listener);
|
| 392 |
+
// emit an add event if we're supposed to
|
| 393 |
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
| 394 |
+
if (!this.fsw._throttle(EV.ADD, file, 0))
|
| 395 |
+
return;
|
| 396 |
+
this.fsw._emit(EV.ADD, file, stats);
|
| 397 |
+
}
|
| 398 |
+
return closer;
|
| 399 |
+
}
|
| 400 |
+
/**
|
| 401 |
+
* Handle symlinks encountered while reading a dir.
|
| 402 |
+
* @param entry returned by readdirp
|
| 403 |
+
* @param directory path of dir being read
|
| 404 |
+
* @param path of this item
|
| 405 |
+
* @param item basename of this item
|
| 406 |
+
* @returns true if no more processing is needed for this entry.
|
| 407 |
+
*/
|
| 408 |
+
async _handleSymlink(entry, directory, path, item) {
|
| 409 |
+
if (this.fsw.closed) {
|
| 410 |
+
return;
|
| 411 |
+
}
|
| 412 |
+
const full = entry.fullPath;
|
| 413 |
+
const dir = this.fsw._getWatchedDir(directory);
|
| 414 |
+
if (!this.fsw.options.followSymlinks) {
|
| 415 |
+
// watch symlink directly (don't follow) and detect changes
|
| 416 |
+
this.fsw._incrReadyCount();
|
| 417 |
+
let linkPath;
|
| 418 |
+
try {
|
| 419 |
+
linkPath = await fsrealpath(path);
|
| 420 |
+
}
|
| 421 |
+
catch (e) {
|
| 422 |
+
this.fsw._emitReady();
|
| 423 |
+
return true;
|
| 424 |
+
}
|
| 425 |
+
if (this.fsw.closed)
|
| 426 |
+
return;
|
| 427 |
+
if (dir.has(item)) {
|
| 428 |
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
| 429 |
+
this.fsw._symlinkPaths.set(full, linkPath);
|
| 430 |
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
else {
|
| 434 |
+
dir.add(item);
|
| 435 |
+
this.fsw._symlinkPaths.set(full, linkPath);
|
| 436 |
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
| 437 |
+
}
|
| 438 |
+
this.fsw._emitReady();
|
| 439 |
+
return true;
|
| 440 |
+
}
|
| 441 |
+
// don't follow the same symlink more than once
|
| 442 |
+
if (this.fsw._symlinkPaths.has(full)) {
|
| 443 |
+
return true;
|
| 444 |
+
}
|
| 445 |
+
this.fsw._symlinkPaths.set(full, true);
|
| 446 |
+
}
|
| 447 |
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
| 448 |
+
// Normalize the directory name on Windows
|
| 449 |
+
directory = sysPath.join(directory, '');
|
| 450 |
+
throttler = this.fsw._throttle('readdir', directory, 1000);
|
| 451 |
+
if (!throttler)
|
| 452 |
+
return;
|
| 453 |
+
const previous = this.fsw._getWatchedDir(wh.path);
|
| 454 |
+
const current = new Set();
|
| 455 |
+
let stream = this.fsw._readdirp(directory, {
|
| 456 |
+
fileFilter: (entry) => wh.filterPath(entry),
|
| 457 |
+
directoryFilter: (entry) => wh.filterDir(entry),
|
| 458 |
+
});
|
| 459 |
+
if (!stream)
|
| 460 |
+
return;
|
| 461 |
+
stream
|
| 462 |
+
.on(STR_DATA, async (entry) => {
|
| 463 |
+
if (this.fsw.closed) {
|
| 464 |
+
stream = undefined;
|
| 465 |
+
return;
|
| 466 |
+
}
|
| 467 |
+
const item = entry.path;
|
| 468 |
+
let path = sysPath.join(directory, item);
|
| 469 |
+
current.add(item);
|
| 470 |
+
if (entry.stats.isSymbolicLink() &&
|
| 471 |
+
(await this._handleSymlink(entry, directory, path, item))) {
|
| 472 |
+
return;
|
| 473 |
+
}
|
| 474 |
+
if (this.fsw.closed) {
|
| 475 |
+
stream = undefined;
|
| 476 |
+
return;
|
| 477 |
+
}
|
| 478 |
+
// Files that present in current directory snapshot
|
| 479 |
+
// but absent in previous are added to watch list and
|
| 480 |
+
// emit `add` event.
|
| 481 |
+
if (item === target || (!target && !previous.has(item))) {
|
| 482 |
+
this.fsw._incrReadyCount();
|
| 483 |
+
// ensure relativeness of path is preserved in case of watcher reuse
|
| 484 |
+
path = sysPath.join(dir, sysPath.relative(dir, path));
|
| 485 |
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
| 486 |
+
}
|
| 487 |
+
})
|
| 488 |
+
.on(EV.ERROR, this._boundHandleError);
|
| 489 |
+
return new Promise((resolve, reject) => {
|
| 490 |
+
if (!stream)
|
| 491 |
+
return reject();
|
| 492 |
+
stream.once(STR_END, () => {
|
| 493 |
+
if (this.fsw.closed) {
|
| 494 |
+
stream = undefined;
|
| 495 |
+
return;
|
| 496 |
+
}
|
| 497 |
+
const wasThrottled = throttler ? throttler.clear() : false;
|
| 498 |
+
resolve(undefined);
|
| 499 |
+
// Files that absent in current directory snapshot
|
| 500 |
+
// but present in previous emit `remove` event
|
| 501 |
+
// and are removed from @watched[directory].
|
| 502 |
+
previous
|
| 503 |
+
.getChildren()
|
| 504 |
+
.filter((item) => {
|
| 505 |
+
return item !== directory && !current.has(item);
|
| 506 |
+
})
|
| 507 |
+
.forEach((item) => {
|
| 508 |
+
this.fsw._remove(directory, item);
|
| 509 |
+
});
|
| 510 |
+
stream = undefined;
|
| 511 |
+
// one more time for any missed in case changes came in extremely quickly
|
| 512 |
+
if (wasThrottled)
|
| 513 |
+
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
| 514 |
+
});
|
| 515 |
+
});
|
| 516 |
+
}
|
| 517 |
+
/**
|
| 518 |
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
| 519 |
+
* @param dir fs path
|
| 520 |
+
* @param stats
|
| 521 |
+
* @param initialAdd
|
| 522 |
+
* @param depth relative to user-supplied path
|
| 523 |
+
* @param target child path targeted for watch
|
| 524 |
+
* @param wh Common watch helpers for this path
|
| 525 |
+
* @param realpath
|
| 526 |
+
* @returns closer for the watcher instance.
|
| 527 |
+
*/
|
| 528 |
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
| 529 |
+
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
| 530 |
+
const tracked = parentDir.has(sysPath.basename(dir));
|
| 531 |
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
| 532 |
+
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
| 533 |
+
}
|
| 534 |
+
// ensure dir is tracked (harmless if redundant)
|
| 535 |
+
parentDir.add(sysPath.basename(dir));
|
| 536 |
+
this.fsw._getWatchedDir(dir);
|
| 537 |
+
let throttler;
|
| 538 |
+
let closer;
|
| 539 |
+
const oDepth = this.fsw.options.depth;
|
| 540 |
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
| 541 |
+
if (!target) {
|
| 542 |
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
| 543 |
+
if (this.fsw.closed)
|
| 544 |
+
return;
|
| 545 |
+
}
|
| 546 |
+
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
| 547 |
+
// if current directory is removed, do nothing
|
| 548 |
+
if (stats && stats.mtimeMs === 0)
|
| 549 |
+
return;
|
| 550 |
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
| 551 |
+
});
|
| 552 |
+
}
|
| 553 |
+
return closer;
|
| 554 |
+
}
|
| 555 |
+
/**
|
| 556 |
+
* Handle added file, directory, or glob pattern.
|
| 557 |
+
* Delegates call to _handleFile / _handleDir after checks.
|
| 558 |
+
* @param path to file or ir
|
| 559 |
+
* @param initialAdd was the file added at watch instantiation?
|
| 560 |
+
* @param priorWh depth relative to user-supplied path
|
| 561 |
+
* @param depth Child path actually targeted for watch
|
| 562 |
+
* @param target Child path actually targeted for watch
|
| 563 |
+
*/
|
| 564 |
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
| 565 |
+
const ready = this.fsw._emitReady;
|
| 566 |
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
| 567 |
+
ready();
|
| 568 |
+
return false;
|
| 569 |
+
}
|
| 570 |
+
const wh = this.fsw._getWatchHelpers(path);
|
| 571 |
+
if (priorWh) {
|
| 572 |
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
| 573 |
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
| 574 |
+
}
|
| 575 |
+
// evaluate what is at the path we're being asked to watch
|
| 576 |
+
try {
|
| 577 |
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
| 578 |
+
if (this.fsw.closed)
|
| 579 |
+
return;
|
| 580 |
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
| 581 |
+
ready();
|
| 582 |
+
return false;
|
| 583 |
+
}
|
| 584 |
+
const follow = this.fsw.options.followSymlinks;
|
| 585 |
+
let closer;
|
| 586 |
+
if (stats.isDirectory()) {
|
| 587 |
+
const absPath = sysPath.resolve(path);
|
| 588 |
+
const targetPath = follow ? await fsrealpath(path) : path;
|
| 589 |
+
if (this.fsw.closed)
|
| 590 |
+
return;
|
| 591 |
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
| 592 |
+
if (this.fsw.closed)
|
| 593 |
+
return;
|
| 594 |
+
// preserve this symlink's target path
|
| 595 |
+
if (absPath !== targetPath && targetPath !== undefined) {
|
| 596 |
+
this.fsw._symlinkPaths.set(absPath, targetPath);
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
else if (stats.isSymbolicLink()) {
|
| 600 |
+
const targetPath = follow ? await fsrealpath(path) : path;
|
| 601 |
+
if (this.fsw.closed)
|
| 602 |
+
return;
|
| 603 |
+
const parent = sysPath.dirname(wh.watchPath);
|
| 604 |
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
| 605 |
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
| 606 |
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
| 607 |
+
if (this.fsw.closed)
|
| 608 |
+
return;
|
| 609 |
+
// preserve this symlink's target path
|
| 610 |
+
if (targetPath !== undefined) {
|
| 611 |
+
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
| 612 |
+
}
|
| 613 |
+
}
|
| 614 |
+
else {
|
| 615 |
+
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
| 616 |
+
}
|
| 617 |
+
ready();
|
| 618 |
+
if (closer)
|
| 619 |
+
this.fsw._addPathCloser(path, closer);
|
| 620 |
+
return false;
|
| 621 |
+
}
|
| 622 |
+
catch (error) {
|
| 623 |
+
if (this.fsw._handleError(error)) {
|
| 624 |
+
ready();
|
| 625 |
+
return path;
|
| 626 |
+
}
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
| 2 |
+
import { Stats } from 'fs';
|
| 3 |
+
import { EventEmitter } from 'events';
|
| 4 |
+
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp';
|
| 5 |
+
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js';
|
| 6 |
+
type AWF = {
|
| 7 |
+
stabilityThreshold: number;
|
| 8 |
+
pollInterval: number;
|
| 9 |
+
};
|
| 10 |
+
type BasicOpts = {
|
| 11 |
+
persistent: boolean;
|
| 12 |
+
ignoreInitial: boolean;
|
| 13 |
+
followSymlinks: boolean;
|
| 14 |
+
cwd?: string;
|
| 15 |
+
usePolling: boolean;
|
| 16 |
+
interval: number;
|
| 17 |
+
binaryInterval: number;
|
| 18 |
+
alwaysStat?: boolean;
|
| 19 |
+
depth?: number;
|
| 20 |
+
ignorePermissionErrors: boolean;
|
| 21 |
+
atomic: boolean | number;
|
| 22 |
+
};
|
| 23 |
+
export type Throttler = {
|
| 24 |
+
timeoutObject: NodeJS.Timeout;
|
| 25 |
+
clear: () => void;
|
| 26 |
+
count: number;
|
| 27 |
+
};
|
| 28 |
+
export type ChokidarOptions = Partial<BasicOpts & {
|
| 29 |
+
ignored: Matcher | Matcher[];
|
| 30 |
+
awaitWriteFinish: boolean | Partial<AWF>;
|
| 31 |
+
}>;
|
| 32 |
+
export type FSWInstanceOptions = BasicOpts & {
|
| 33 |
+
ignored: Matcher[];
|
| 34 |
+
awaitWriteFinish: false | AWF;
|
| 35 |
+
};
|
| 36 |
+
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
|
| 37 |
+
export type EmitArgs = [path: Path, stats?: Stats];
|
| 38 |
+
export type EmitErrorArgs = [error: Error, stats?: Stats];
|
| 39 |
+
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
|
| 40 |
+
export type MatchFunction = (val: string, stats?: Stats) => boolean;
|
| 41 |
+
export interface MatcherObject {
|
| 42 |
+
path: string;
|
| 43 |
+
recursive?: boolean;
|
| 44 |
+
}
|
| 45 |
+
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
|
| 46 |
+
/**
|
| 47 |
+
* Directory entry.
|
| 48 |
+
*/
|
| 49 |
+
declare class DirEntry {
|
| 50 |
+
path: Path;
|
| 51 |
+
_removeWatcher: (dir: string, base: string) => void;
|
| 52 |
+
items: Set<Path>;
|
| 53 |
+
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
|
| 54 |
+
add(item: string): void;
|
| 55 |
+
remove(item: string): Promise<void>;
|
| 56 |
+
has(item: string): boolean | undefined;
|
| 57 |
+
getChildren(): string[];
|
| 58 |
+
dispose(): void;
|
| 59 |
+
}
|
| 60 |
+
export declare class WatchHelper {
|
| 61 |
+
fsw: FSWatcher;
|
| 62 |
+
path: string;
|
| 63 |
+
watchPath: string;
|
| 64 |
+
fullWatchPath: string;
|
| 65 |
+
dirParts: string[][];
|
| 66 |
+
followSymlinks: boolean;
|
| 67 |
+
statMethod: 'stat' | 'lstat';
|
| 68 |
+
constructor(path: string, follow: boolean, fsw: FSWatcher);
|
| 69 |
+
entryPath(entry: EntryInfo): Path;
|
| 70 |
+
filterPath(entry: EntryInfo): boolean;
|
| 71 |
+
filterDir(entry: EntryInfo): boolean;
|
| 72 |
+
}
|
| 73 |
+
export interface FSWatcherKnownEventMap {
|
| 74 |
+
[EV.READY]: [];
|
| 75 |
+
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
|
| 76 |
+
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
|
| 77 |
+
[EV.ALL]: [event: EventName, ...EmitArgs];
|
| 78 |
+
}
|
| 79 |
+
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
|
| 80 |
+
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
|
| 81 |
+
};
|
| 82 |
+
/**
|
| 83 |
+
* Watches files & directories for changes. Emitted events:
|
| 84 |
+
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
| 85 |
+
*
|
| 86 |
+
* new FSWatcher()
|
| 87 |
+
* .add(directories)
|
| 88 |
+
* .on('add', path => log('File', path, 'was added'))
|
| 89 |
+
*/
|
| 90 |
+
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
|
| 91 |
+
closed: boolean;
|
| 92 |
+
options: FSWInstanceOptions;
|
| 93 |
+
_closers: Map<string, Array<any>>;
|
| 94 |
+
_ignoredPaths: Set<Matcher>;
|
| 95 |
+
_throttled: Map<ThrottleType, Map<any, any>>;
|
| 96 |
+
_streams: Set<ReaddirpStream>;
|
| 97 |
+
_symlinkPaths: Map<Path, string | boolean>;
|
| 98 |
+
_watched: Map<string, DirEntry>;
|
| 99 |
+
_pendingWrites: Map<string, any>;
|
| 100 |
+
_pendingUnlinks: Map<string, EmitArgsWithName>;
|
| 101 |
+
_readyCount: number;
|
| 102 |
+
_emitReady: () => void;
|
| 103 |
+
_closePromise?: Promise<void>;
|
| 104 |
+
_userIgnored?: MatchFunction;
|
| 105 |
+
_readyEmitted: boolean;
|
| 106 |
+
_emitRaw: WatchHandlers['rawEmitter'];
|
| 107 |
+
_boundRemove: (dir: string, item: string) => void;
|
| 108 |
+
_nodeFsHandler: NodeFsHandler;
|
| 109 |
+
constructor(_opts?: ChokidarOptions);
|
| 110 |
+
_addIgnoredPath(matcher: Matcher): void;
|
| 111 |
+
_removeIgnoredPath(matcher: Matcher): void;
|
| 112 |
+
/**
|
| 113 |
+
* Adds paths to be watched on an existing FSWatcher instance.
|
| 114 |
+
* @param paths_ file or file list. Other arguments are unused
|
| 115 |
+
*/
|
| 116 |
+
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
|
| 117 |
+
/**
|
| 118 |
+
* Close watchers or start ignoring events from specified paths.
|
| 119 |
+
*/
|
| 120 |
+
unwatch(paths_: Path | Path[]): FSWatcher;
|
| 121 |
+
/**
|
| 122 |
+
* Close watchers and remove all listeners from watched paths.
|
| 123 |
+
*/
|
| 124 |
+
close(): Promise<void>;
|
| 125 |
+
/**
|
| 126 |
+
* Expose list of watched paths
|
| 127 |
+
* @returns for chaining
|
| 128 |
+
*/
|
| 129 |
+
getWatched(): Record<string, string[]>;
|
| 130 |
+
emitWithAll(event: EventName, args: EmitArgs): void;
|
| 131 |
+
/**
|
| 132 |
+
* Normalize and emit events.
|
| 133 |
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
| 134 |
+
* @param event Type of event
|
| 135 |
+
* @param path File or directory path
|
| 136 |
+
* @param stats arguments to be passed with event
|
| 137 |
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 138 |
+
*/
|
| 139 |
+
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
|
| 140 |
+
/**
|
| 141 |
+
* Common handler for errors
|
| 142 |
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 143 |
+
*/
|
| 144 |
+
_handleError(error: Error): Error | boolean;
|
| 145 |
+
/**
|
| 146 |
+
* Helper utility for throttling
|
| 147 |
+
* @param actionType type being throttled
|
| 148 |
+
* @param path being acted upon
|
| 149 |
+
* @param timeout duration of time to suppress duplicate actions
|
| 150 |
+
* @returns tracking object or false if action should be suppressed
|
| 151 |
+
*/
|
| 152 |
+
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
|
| 153 |
+
_incrReadyCount(): number;
|
| 154 |
+
/**
|
| 155 |
+
* Awaits write operation to finish.
|
| 156 |
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
| 157 |
+
* @param path being acted upon
|
| 158 |
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
| 159 |
+
* @param event
|
| 160 |
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
| 161 |
+
*/
|
| 162 |
+
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
|
| 163 |
+
/**
|
| 164 |
+
* Determines whether user has asked to ignore this path.
|
| 165 |
+
*/
|
| 166 |
+
_isIgnored(path: Path, stats?: Stats): boolean;
|
| 167 |
+
_isntIgnored(path: Path, stat?: Stats): boolean;
|
| 168 |
+
/**
|
| 169 |
+
* Provides a set of common helpers and properties relating to symlink handling.
|
| 170 |
+
* @param path file or directory pattern being watched
|
| 171 |
+
*/
|
| 172 |
+
_getWatchHelpers(path: Path): WatchHelper;
|
| 173 |
+
/**
|
| 174 |
+
* Provides directory tracking objects
|
| 175 |
+
* @param directory path of the directory
|
| 176 |
+
*/
|
| 177 |
+
_getWatchedDir(directory: string): DirEntry;
|
| 178 |
+
/**
|
| 179 |
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
| 180 |
+
*/
|
| 181 |
+
_hasReadPermissions(stats: Stats): boolean;
|
| 182 |
+
/**
|
| 183 |
+
* Handles emitting unlink events for
|
| 184 |
+
* files and directories, and via recursion, for
|
| 185 |
+
* files and directories within directories that are unlinked
|
| 186 |
+
* @param directory within which the following item is located
|
| 187 |
+
* @param item base path of item/directory
|
| 188 |
+
*/
|
| 189 |
+
_remove(directory: string, item: string, isDirectory?: boolean): void;
|
| 190 |
+
/**
|
| 191 |
+
* Closes all watchers for a path
|
| 192 |
+
*/
|
| 193 |
+
_closePath(path: Path): void;
|
| 194 |
+
/**
|
| 195 |
+
* Closes only file-specific watchers
|
| 196 |
+
*/
|
| 197 |
+
_closeFile(path: Path): void;
|
| 198 |
+
_addPathCloser(path: Path, closer: () => void): void;
|
| 199 |
+
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
|
| 200 |
+
}
|
| 201 |
+
/**
|
| 202 |
+
* Instantiates watcher with paths to be tracked.
|
| 203 |
+
* @param paths file / directory paths
|
| 204 |
+
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
| 205 |
+
* @returns an instance of FSWatcher for chaining.
|
| 206 |
+
* @example
|
| 207 |
+
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
| 208 |
+
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
| 209 |
+
*/
|
| 210 |
+
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
|
| 211 |
+
declare const _default: {
|
| 212 |
+
watch: typeof watch;
|
| 213 |
+
FSWatcher: typeof FSWatcher;
|
| 214 |
+
};
|
| 215 |
+
export default _default;
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/index.js
ADDED
|
@@ -0,0 +1,798 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
| 2 |
+
import { stat as statcb } from 'fs';
|
| 3 |
+
import { stat, readdir } from 'fs/promises';
|
| 4 |
+
import { EventEmitter } from 'events';
|
| 5 |
+
import * as sysPath from 'path';
|
| 6 |
+
import { readdirp } from 'readdirp';
|
| 7 |
+
import { NodeFsHandler, EVENTS as EV, isWindows, isIBMi, EMPTY_FN, STR_CLOSE, STR_END, } from './handler.js';
|
| 8 |
+
const SLASH = '/';
|
| 9 |
+
const SLASH_SLASH = '//';
|
| 10 |
+
const ONE_DOT = '.';
|
| 11 |
+
const TWO_DOTS = '..';
|
| 12 |
+
const STRING_TYPE = 'string';
|
| 13 |
+
const BACK_SLASH_RE = /\\/g;
|
| 14 |
+
const DOUBLE_SLASH_RE = /\/\//;
|
| 15 |
+
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
| 16 |
+
const REPLACER_RE = /^\.[/\\]/;
|
| 17 |
+
function arrify(item) {
|
| 18 |
+
return Array.isArray(item) ? item : [item];
|
| 19 |
+
}
|
| 20 |
+
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
| 21 |
+
function createPattern(matcher) {
|
| 22 |
+
if (typeof matcher === 'function')
|
| 23 |
+
return matcher;
|
| 24 |
+
if (typeof matcher === 'string')
|
| 25 |
+
return (string) => matcher === string;
|
| 26 |
+
if (matcher instanceof RegExp)
|
| 27 |
+
return (string) => matcher.test(string);
|
| 28 |
+
if (typeof matcher === 'object' && matcher !== null) {
|
| 29 |
+
return (string) => {
|
| 30 |
+
if (matcher.path === string)
|
| 31 |
+
return true;
|
| 32 |
+
if (matcher.recursive) {
|
| 33 |
+
const relative = sysPath.relative(matcher.path, string);
|
| 34 |
+
if (!relative) {
|
| 35 |
+
return false;
|
| 36 |
+
}
|
| 37 |
+
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
| 38 |
+
}
|
| 39 |
+
return false;
|
| 40 |
+
};
|
| 41 |
+
}
|
| 42 |
+
return () => false;
|
| 43 |
+
}
|
| 44 |
+
function normalizePath(path) {
|
| 45 |
+
if (typeof path !== 'string')
|
| 46 |
+
throw new Error('string expected');
|
| 47 |
+
path = sysPath.normalize(path);
|
| 48 |
+
path = path.replace(/\\/g, '/');
|
| 49 |
+
let prepend = false;
|
| 50 |
+
if (path.startsWith('//'))
|
| 51 |
+
prepend = true;
|
| 52 |
+
const DOUBLE_SLASH_RE = /\/\//;
|
| 53 |
+
while (path.match(DOUBLE_SLASH_RE))
|
| 54 |
+
path = path.replace(DOUBLE_SLASH_RE, '/');
|
| 55 |
+
if (prepend)
|
| 56 |
+
path = '/' + path;
|
| 57 |
+
return path;
|
| 58 |
+
}
|
| 59 |
+
function matchPatterns(patterns, testString, stats) {
|
| 60 |
+
const path = normalizePath(testString);
|
| 61 |
+
for (let index = 0; index < patterns.length; index++) {
|
| 62 |
+
const pattern = patterns[index];
|
| 63 |
+
if (pattern(path, stats)) {
|
| 64 |
+
return true;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
return false;
|
| 68 |
+
}
|
| 69 |
+
function anymatch(matchers, testString) {
|
| 70 |
+
if (matchers == null) {
|
| 71 |
+
throw new TypeError('anymatch: specify first argument');
|
| 72 |
+
}
|
| 73 |
+
// Early cache for matchers.
|
| 74 |
+
const matchersArray = arrify(matchers);
|
| 75 |
+
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
| 76 |
+
if (testString == null) {
|
| 77 |
+
return (testString, stats) => {
|
| 78 |
+
return matchPatterns(patterns, testString, stats);
|
| 79 |
+
};
|
| 80 |
+
}
|
| 81 |
+
return matchPatterns(patterns, testString);
|
| 82 |
+
}
|
| 83 |
+
const unifyPaths = (paths_) => {
|
| 84 |
+
const paths = arrify(paths_).flat();
|
| 85 |
+
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
| 86 |
+
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
| 87 |
+
}
|
| 88 |
+
return paths.map(normalizePathToUnix);
|
| 89 |
+
};
|
| 90 |
+
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
| 91 |
+
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
| 92 |
+
const toUnix = (string) => {
|
| 93 |
+
let str = string.replace(BACK_SLASH_RE, SLASH);
|
| 94 |
+
let prepend = false;
|
| 95 |
+
if (str.startsWith(SLASH_SLASH)) {
|
| 96 |
+
prepend = true;
|
| 97 |
+
}
|
| 98 |
+
while (str.match(DOUBLE_SLASH_RE)) {
|
| 99 |
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
| 100 |
+
}
|
| 101 |
+
if (prepend) {
|
| 102 |
+
str = SLASH + str;
|
| 103 |
+
}
|
| 104 |
+
return str;
|
| 105 |
+
};
|
| 106 |
+
// Our version of upath.normalize
|
| 107 |
+
// TODO: this is not equal to path-normalize module - investigate why
|
| 108 |
+
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
| 109 |
+
// TODO: refactor
|
| 110 |
+
const normalizeIgnored = (cwd = '') => (path) => {
|
| 111 |
+
if (typeof path === 'string') {
|
| 112 |
+
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
| 113 |
+
}
|
| 114 |
+
else {
|
| 115 |
+
return path;
|
| 116 |
+
}
|
| 117 |
+
};
|
| 118 |
+
const getAbsolutePath = (path, cwd) => {
|
| 119 |
+
if (sysPath.isAbsolute(path)) {
|
| 120 |
+
return path;
|
| 121 |
+
}
|
| 122 |
+
return sysPath.join(cwd, path);
|
| 123 |
+
};
|
| 124 |
+
const EMPTY_SET = Object.freeze(new Set());
|
| 125 |
+
/**
|
| 126 |
+
* Directory entry.
|
| 127 |
+
*/
|
| 128 |
+
class DirEntry {
|
| 129 |
+
constructor(dir, removeWatcher) {
|
| 130 |
+
this.path = dir;
|
| 131 |
+
this._removeWatcher = removeWatcher;
|
| 132 |
+
this.items = new Set();
|
| 133 |
+
}
|
| 134 |
+
add(item) {
|
| 135 |
+
const { items } = this;
|
| 136 |
+
if (!items)
|
| 137 |
+
return;
|
| 138 |
+
if (item !== ONE_DOT && item !== TWO_DOTS)
|
| 139 |
+
items.add(item);
|
| 140 |
+
}
|
| 141 |
+
async remove(item) {
|
| 142 |
+
const { items } = this;
|
| 143 |
+
if (!items)
|
| 144 |
+
return;
|
| 145 |
+
items.delete(item);
|
| 146 |
+
if (items.size > 0)
|
| 147 |
+
return;
|
| 148 |
+
const dir = this.path;
|
| 149 |
+
try {
|
| 150 |
+
await readdir(dir);
|
| 151 |
+
}
|
| 152 |
+
catch (err) {
|
| 153 |
+
if (this._removeWatcher) {
|
| 154 |
+
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
has(item) {
|
| 159 |
+
const { items } = this;
|
| 160 |
+
if (!items)
|
| 161 |
+
return;
|
| 162 |
+
return items.has(item);
|
| 163 |
+
}
|
| 164 |
+
getChildren() {
|
| 165 |
+
const { items } = this;
|
| 166 |
+
if (!items)
|
| 167 |
+
return [];
|
| 168 |
+
return [...items.values()];
|
| 169 |
+
}
|
| 170 |
+
dispose() {
|
| 171 |
+
this.items.clear();
|
| 172 |
+
this.path = '';
|
| 173 |
+
this._removeWatcher = EMPTY_FN;
|
| 174 |
+
this.items = EMPTY_SET;
|
| 175 |
+
Object.freeze(this);
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
const STAT_METHOD_F = 'stat';
|
| 179 |
+
const STAT_METHOD_L = 'lstat';
|
| 180 |
+
export class WatchHelper {
|
| 181 |
+
constructor(path, follow, fsw) {
|
| 182 |
+
this.fsw = fsw;
|
| 183 |
+
const watchPath = path;
|
| 184 |
+
this.path = path = path.replace(REPLACER_RE, '');
|
| 185 |
+
this.watchPath = watchPath;
|
| 186 |
+
this.fullWatchPath = sysPath.resolve(watchPath);
|
| 187 |
+
this.dirParts = [];
|
| 188 |
+
this.dirParts.forEach((parts) => {
|
| 189 |
+
if (parts.length > 1)
|
| 190 |
+
parts.pop();
|
| 191 |
+
});
|
| 192 |
+
this.followSymlinks = follow;
|
| 193 |
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
| 194 |
+
}
|
| 195 |
+
entryPath(entry) {
|
| 196 |
+
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
| 197 |
+
}
|
| 198 |
+
filterPath(entry) {
|
| 199 |
+
const { stats } = entry;
|
| 200 |
+
if (stats && stats.isSymbolicLink())
|
| 201 |
+
return this.filterDir(entry);
|
| 202 |
+
const resolvedPath = this.entryPath(entry);
|
| 203 |
+
// TODO: what if stats is undefined? remove !
|
| 204 |
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
| 205 |
+
}
|
| 206 |
+
filterDir(entry) {
|
| 207 |
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
/**
|
| 211 |
+
* Watches files & directories for changes. Emitted events:
|
| 212 |
+
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
| 213 |
+
*
|
| 214 |
+
* new FSWatcher()
|
| 215 |
+
* .add(directories)
|
| 216 |
+
* .on('add', path => log('File', path, 'was added'))
|
| 217 |
+
*/
|
| 218 |
+
export class FSWatcher extends EventEmitter {
|
| 219 |
+
// Not indenting methods for history sake; for now.
|
| 220 |
+
constructor(_opts = {}) {
|
| 221 |
+
super();
|
| 222 |
+
this.closed = false;
|
| 223 |
+
this._closers = new Map();
|
| 224 |
+
this._ignoredPaths = new Set();
|
| 225 |
+
this._throttled = new Map();
|
| 226 |
+
this._streams = new Set();
|
| 227 |
+
this._symlinkPaths = new Map();
|
| 228 |
+
this._watched = new Map();
|
| 229 |
+
this._pendingWrites = new Map();
|
| 230 |
+
this._pendingUnlinks = new Map();
|
| 231 |
+
this._readyCount = 0;
|
| 232 |
+
this._readyEmitted = false;
|
| 233 |
+
const awf = _opts.awaitWriteFinish;
|
| 234 |
+
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
| 235 |
+
const opts = {
|
| 236 |
+
// Defaults
|
| 237 |
+
persistent: true,
|
| 238 |
+
ignoreInitial: false,
|
| 239 |
+
ignorePermissionErrors: false,
|
| 240 |
+
interval: 100,
|
| 241 |
+
binaryInterval: 300,
|
| 242 |
+
followSymlinks: true,
|
| 243 |
+
usePolling: false,
|
| 244 |
+
// useAsync: false,
|
| 245 |
+
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
| 246 |
+
..._opts,
|
| 247 |
+
// Change format
|
| 248 |
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
| 249 |
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
| 250 |
+
};
|
| 251 |
+
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
| 252 |
+
if (isIBMi)
|
| 253 |
+
opts.usePolling = true;
|
| 254 |
+
// Editor atomic write normalization enabled by default with fs.watch
|
| 255 |
+
if (opts.atomic === undefined)
|
| 256 |
+
opts.atomic = !opts.usePolling;
|
| 257 |
+
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
| 258 |
+
// Global override. Useful for developers, who need to force polling for all
|
| 259 |
+
// instances of chokidar, regardless of usage / dependency depth
|
| 260 |
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
| 261 |
+
if (envPoll !== undefined) {
|
| 262 |
+
const envLower = envPoll.toLowerCase();
|
| 263 |
+
if (envLower === 'false' || envLower === '0')
|
| 264 |
+
opts.usePolling = false;
|
| 265 |
+
else if (envLower === 'true' || envLower === '1')
|
| 266 |
+
opts.usePolling = true;
|
| 267 |
+
else
|
| 268 |
+
opts.usePolling = !!envLower;
|
| 269 |
+
}
|
| 270 |
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
| 271 |
+
if (envInterval)
|
| 272 |
+
opts.interval = Number.parseInt(envInterval, 10);
|
| 273 |
+
// This is done to emit ready only once, but each 'add' will increase that?
|
| 274 |
+
let readyCalls = 0;
|
| 275 |
+
this._emitReady = () => {
|
| 276 |
+
readyCalls++;
|
| 277 |
+
if (readyCalls >= this._readyCount) {
|
| 278 |
+
this._emitReady = EMPTY_FN;
|
| 279 |
+
this._readyEmitted = true;
|
| 280 |
+
// use process.nextTick to allow time for listener to be bound
|
| 281 |
+
process.nextTick(() => this.emit(EV.READY));
|
| 282 |
+
}
|
| 283 |
+
};
|
| 284 |
+
this._emitRaw = (...args) => this.emit(EV.RAW, ...args);
|
| 285 |
+
this._boundRemove = this._remove.bind(this);
|
| 286 |
+
this.options = opts;
|
| 287 |
+
this._nodeFsHandler = new NodeFsHandler(this);
|
| 288 |
+
// You’re frozen when your heart’s not open.
|
| 289 |
+
Object.freeze(opts);
|
| 290 |
+
}
|
| 291 |
+
_addIgnoredPath(matcher) {
|
| 292 |
+
if (isMatcherObject(matcher)) {
|
| 293 |
+
// return early if we already have a deeply equal matcher object
|
| 294 |
+
for (const ignored of this._ignoredPaths) {
|
| 295 |
+
if (isMatcherObject(ignored) &&
|
| 296 |
+
ignored.path === matcher.path &&
|
| 297 |
+
ignored.recursive === matcher.recursive) {
|
| 298 |
+
return;
|
| 299 |
+
}
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
this._ignoredPaths.add(matcher);
|
| 303 |
+
}
|
| 304 |
+
_removeIgnoredPath(matcher) {
|
| 305 |
+
this._ignoredPaths.delete(matcher);
|
| 306 |
+
// now find any matcher objects with the matcher as path
|
| 307 |
+
if (typeof matcher === 'string') {
|
| 308 |
+
for (const ignored of this._ignoredPaths) {
|
| 309 |
+
// TODO (43081j): make this more efficient.
|
| 310 |
+
// probably just make a `this._ignoredDirectories` or some
|
| 311 |
+
// such thing.
|
| 312 |
+
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
| 313 |
+
this._ignoredPaths.delete(ignored);
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
// Public methods
|
| 319 |
+
/**
|
| 320 |
+
* Adds paths to be watched on an existing FSWatcher instance.
|
| 321 |
+
* @param paths_ file or file list. Other arguments are unused
|
| 322 |
+
*/
|
| 323 |
+
add(paths_, _origAdd, _internal) {
|
| 324 |
+
const { cwd } = this.options;
|
| 325 |
+
this.closed = false;
|
| 326 |
+
this._closePromise = undefined;
|
| 327 |
+
let paths = unifyPaths(paths_);
|
| 328 |
+
if (cwd) {
|
| 329 |
+
paths = paths.map((path) => {
|
| 330 |
+
const absPath = getAbsolutePath(path, cwd);
|
| 331 |
+
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
| 332 |
+
return absPath;
|
| 333 |
+
});
|
| 334 |
+
}
|
| 335 |
+
paths.forEach((path) => {
|
| 336 |
+
this._removeIgnoredPath(path);
|
| 337 |
+
});
|
| 338 |
+
this._userIgnored = undefined;
|
| 339 |
+
if (!this._readyCount)
|
| 340 |
+
this._readyCount = 0;
|
| 341 |
+
this._readyCount += paths.length;
|
| 342 |
+
Promise.all(paths.map(async (path) => {
|
| 343 |
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
| 344 |
+
if (res)
|
| 345 |
+
this._emitReady();
|
| 346 |
+
return res;
|
| 347 |
+
})).then((results) => {
|
| 348 |
+
if (this.closed)
|
| 349 |
+
return;
|
| 350 |
+
results.forEach((item) => {
|
| 351 |
+
if (item)
|
| 352 |
+
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
| 353 |
+
});
|
| 354 |
+
});
|
| 355 |
+
return this;
|
| 356 |
+
}
|
| 357 |
+
/**
|
| 358 |
+
* Close watchers or start ignoring events from specified paths.
|
| 359 |
+
*/
|
| 360 |
+
unwatch(paths_) {
|
| 361 |
+
if (this.closed)
|
| 362 |
+
return this;
|
| 363 |
+
const paths = unifyPaths(paths_);
|
| 364 |
+
const { cwd } = this.options;
|
| 365 |
+
paths.forEach((path) => {
|
| 366 |
+
// convert to absolute path unless relative path already matches
|
| 367 |
+
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
| 368 |
+
if (cwd)
|
| 369 |
+
path = sysPath.join(cwd, path);
|
| 370 |
+
path = sysPath.resolve(path);
|
| 371 |
+
}
|
| 372 |
+
this._closePath(path);
|
| 373 |
+
this._addIgnoredPath(path);
|
| 374 |
+
if (this._watched.has(path)) {
|
| 375 |
+
this._addIgnoredPath({
|
| 376 |
+
path,
|
| 377 |
+
recursive: true,
|
| 378 |
+
});
|
| 379 |
+
}
|
| 380 |
+
// reset the cached userIgnored anymatch fn
|
| 381 |
+
// to make ignoredPaths changes effective
|
| 382 |
+
this._userIgnored = undefined;
|
| 383 |
+
});
|
| 384 |
+
return this;
|
| 385 |
+
}
|
| 386 |
+
/**
|
| 387 |
+
* Close watchers and remove all listeners from watched paths.
|
| 388 |
+
*/
|
| 389 |
+
close() {
|
| 390 |
+
if (this._closePromise) {
|
| 391 |
+
return this._closePromise;
|
| 392 |
+
}
|
| 393 |
+
this.closed = true;
|
| 394 |
+
// Memory management.
|
| 395 |
+
this.removeAllListeners();
|
| 396 |
+
const closers = [];
|
| 397 |
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
| 398 |
+
const promise = closer();
|
| 399 |
+
if (promise instanceof Promise)
|
| 400 |
+
closers.push(promise);
|
| 401 |
+
}));
|
| 402 |
+
this._streams.forEach((stream) => stream.destroy());
|
| 403 |
+
this._userIgnored = undefined;
|
| 404 |
+
this._readyCount = 0;
|
| 405 |
+
this._readyEmitted = false;
|
| 406 |
+
this._watched.forEach((dirent) => dirent.dispose());
|
| 407 |
+
this._closers.clear();
|
| 408 |
+
this._watched.clear();
|
| 409 |
+
this._streams.clear();
|
| 410 |
+
this._symlinkPaths.clear();
|
| 411 |
+
this._throttled.clear();
|
| 412 |
+
this._closePromise = closers.length
|
| 413 |
+
? Promise.all(closers).then(() => undefined)
|
| 414 |
+
: Promise.resolve();
|
| 415 |
+
return this._closePromise;
|
| 416 |
+
}
|
| 417 |
+
/**
|
| 418 |
+
* Expose list of watched paths
|
| 419 |
+
* @returns for chaining
|
| 420 |
+
*/
|
| 421 |
+
getWatched() {
|
| 422 |
+
const watchList = {};
|
| 423 |
+
this._watched.forEach((entry, dir) => {
|
| 424 |
+
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
| 425 |
+
const index = key || ONE_DOT;
|
| 426 |
+
watchList[index] = entry.getChildren().sort();
|
| 427 |
+
});
|
| 428 |
+
return watchList;
|
| 429 |
+
}
|
| 430 |
+
emitWithAll(event, args) {
|
| 431 |
+
this.emit(event, ...args);
|
| 432 |
+
if (event !== EV.ERROR)
|
| 433 |
+
this.emit(EV.ALL, event, ...args);
|
| 434 |
+
}
|
| 435 |
+
// Common helpers
|
| 436 |
+
// --------------
|
| 437 |
+
/**
|
| 438 |
+
* Normalize and emit events.
|
| 439 |
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
| 440 |
+
* @param event Type of event
|
| 441 |
+
* @param path File or directory path
|
| 442 |
+
* @param stats arguments to be passed with event
|
| 443 |
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 444 |
+
*/
|
| 445 |
+
async _emit(event, path, stats) {
|
| 446 |
+
if (this.closed)
|
| 447 |
+
return;
|
| 448 |
+
const opts = this.options;
|
| 449 |
+
if (isWindows)
|
| 450 |
+
path = sysPath.normalize(path);
|
| 451 |
+
if (opts.cwd)
|
| 452 |
+
path = sysPath.relative(opts.cwd, path);
|
| 453 |
+
const args = [path];
|
| 454 |
+
if (stats != null)
|
| 455 |
+
args.push(stats);
|
| 456 |
+
const awf = opts.awaitWriteFinish;
|
| 457 |
+
let pw;
|
| 458 |
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
| 459 |
+
pw.lastChange = new Date();
|
| 460 |
+
return this;
|
| 461 |
+
}
|
| 462 |
+
if (opts.atomic) {
|
| 463 |
+
if (event === EV.UNLINK) {
|
| 464 |
+
this._pendingUnlinks.set(path, [event, ...args]);
|
| 465 |
+
setTimeout(() => {
|
| 466 |
+
this._pendingUnlinks.forEach((entry, path) => {
|
| 467 |
+
this.emit(...entry);
|
| 468 |
+
this.emit(EV.ALL, ...entry);
|
| 469 |
+
this._pendingUnlinks.delete(path);
|
| 470 |
+
});
|
| 471 |
+
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
| 472 |
+
return this;
|
| 473 |
+
}
|
| 474 |
+
if (event === EV.ADD && this._pendingUnlinks.has(path)) {
|
| 475 |
+
event = EV.CHANGE;
|
| 476 |
+
this._pendingUnlinks.delete(path);
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
if (awf && (event === EV.ADD || event === EV.CHANGE) && this._readyEmitted) {
|
| 480 |
+
const awfEmit = (err, stats) => {
|
| 481 |
+
if (err) {
|
| 482 |
+
event = EV.ERROR;
|
| 483 |
+
args[0] = err;
|
| 484 |
+
this.emitWithAll(event, args);
|
| 485 |
+
}
|
| 486 |
+
else if (stats) {
|
| 487 |
+
// if stats doesn't exist the file must have been deleted
|
| 488 |
+
if (args.length > 1) {
|
| 489 |
+
args[1] = stats;
|
| 490 |
+
}
|
| 491 |
+
else {
|
| 492 |
+
args.push(stats);
|
| 493 |
+
}
|
| 494 |
+
this.emitWithAll(event, args);
|
| 495 |
+
}
|
| 496 |
+
};
|
| 497 |
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
| 498 |
+
return this;
|
| 499 |
+
}
|
| 500 |
+
if (event === EV.CHANGE) {
|
| 501 |
+
const isThrottled = !this._throttle(EV.CHANGE, path, 50);
|
| 502 |
+
if (isThrottled)
|
| 503 |
+
return this;
|
| 504 |
+
}
|
| 505 |
+
if (opts.alwaysStat &&
|
| 506 |
+
stats === undefined &&
|
| 507 |
+
(event === EV.ADD || event === EV.ADD_DIR || event === EV.CHANGE)) {
|
| 508 |
+
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
| 509 |
+
let stats;
|
| 510 |
+
try {
|
| 511 |
+
stats = await stat(fullPath);
|
| 512 |
+
}
|
| 513 |
+
catch (err) {
|
| 514 |
+
// do nothing
|
| 515 |
+
}
|
| 516 |
+
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
| 517 |
+
if (!stats || this.closed)
|
| 518 |
+
return;
|
| 519 |
+
args.push(stats);
|
| 520 |
+
}
|
| 521 |
+
this.emitWithAll(event, args);
|
| 522 |
+
return this;
|
| 523 |
+
}
|
| 524 |
+
/**
|
| 525 |
+
* Common handler for errors
|
| 526 |
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 527 |
+
*/
|
| 528 |
+
_handleError(error) {
|
| 529 |
+
const code = error && error.code;
|
| 530 |
+
if (error &&
|
| 531 |
+
code !== 'ENOENT' &&
|
| 532 |
+
code !== 'ENOTDIR' &&
|
| 533 |
+
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
| 534 |
+
this.emit(EV.ERROR, error);
|
| 535 |
+
}
|
| 536 |
+
return error || this.closed;
|
| 537 |
+
}
|
| 538 |
+
/**
|
| 539 |
+
* Helper utility for throttling
|
| 540 |
+
* @param actionType type being throttled
|
| 541 |
+
* @param path being acted upon
|
| 542 |
+
* @param timeout duration of time to suppress duplicate actions
|
| 543 |
+
* @returns tracking object or false if action should be suppressed
|
| 544 |
+
*/
|
| 545 |
+
_throttle(actionType, path, timeout) {
|
| 546 |
+
if (!this._throttled.has(actionType)) {
|
| 547 |
+
this._throttled.set(actionType, new Map());
|
| 548 |
+
}
|
| 549 |
+
const action = this._throttled.get(actionType);
|
| 550 |
+
if (!action)
|
| 551 |
+
throw new Error('invalid throttle');
|
| 552 |
+
const actionPath = action.get(path);
|
| 553 |
+
if (actionPath) {
|
| 554 |
+
actionPath.count++;
|
| 555 |
+
return false;
|
| 556 |
+
}
|
| 557 |
+
// eslint-disable-next-line prefer-const
|
| 558 |
+
let timeoutObject;
|
| 559 |
+
const clear = () => {
|
| 560 |
+
const item = action.get(path);
|
| 561 |
+
const count = item ? item.count : 0;
|
| 562 |
+
action.delete(path);
|
| 563 |
+
clearTimeout(timeoutObject);
|
| 564 |
+
if (item)
|
| 565 |
+
clearTimeout(item.timeoutObject);
|
| 566 |
+
return count;
|
| 567 |
+
};
|
| 568 |
+
timeoutObject = setTimeout(clear, timeout);
|
| 569 |
+
const thr = { timeoutObject, clear, count: 0 };
|
| 570 |
+
action.set(path, thr);
|
| 571 |
+
return thr;
|
| 572 |
+
}
|
| 573 |
+
_incrReadyCount() {
|
| 574 |
+
return this._readyCount++;
|
| 575 |
+
}
|
| 576 |
+
/**
|
| 577 |
+
* Awaits write operation to finish.
|
| 578 |
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
| 579 |
+
* @param path being acted upon
|
| 580 |
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
| 581 |
+
* @param event
|
| 582 |
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
| 583 |
+
*/
|
| 584 |
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
| 585 |
+
const awf = this.options.awaitWriteFinish;
|
| 586 |
+
if (typeof awf !== 'object')
|
| 587 |
+
return;
|
| 588 |
+
const pollInterval = awf.pollInterval;
|
| 589 |
+
let timeoutHandler;
|
| 590 |
+
let fullPath = path;
|
| 591 |
+
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
| 592 |
+
fullPath = sysPath.join(this.options.cwd, path);
|
| 593 |
+
}
|
| 594 |
+
const now = new Date();
|
| 595 |
+
const writes = this._pendingWrites;
|
| 596 |
+
function awaitWriteFinishFn(prevStat) {
|
| 597 |
+
statcb(fullPath, (err, curStat) => {
|
| 598 |
+
if (err || !writes.has(path)) {
|
| 599 |
+
if (err && err.code !== 'ENOENT')
|
| 600 |
+
awfEmit(err);
|
| 601 |
+
return;
|
| 602 |
+
}
|
| 603 |
+
const now = Number(new Date());
|
| 604 |
+
if (prevStat && curStat.size !== prevStat.size) {
|
| 605 |
+
writes.get(path).lastChange = now;
|
| 606 |
+
}
|
| 607 |
+
const pw = writes.get(path);
|
| 608 |
+
const df = now - pw.lastChange;
|
| 609 |
+
if (df >= threshold) {
|
| 610 |
+
writes.delete(path);
|
| 611 |
+
awfEmit(undefined, curStat);
|
| 612 |
+
}
|
| 613 |
+
else {
|
| 614 |
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
| 615 |
+
}
|
| 616 |
+
});
|
| 617 |
+
}
|
| 618 |
+
if (!writes.has(path)) {
|
| 619 |
+
writes.set(path, {
|
| 620 |
+
lastChange: now,
|
| 621 |
+
cancelWait: () => {
|
| 622 |
+
writes.delete(path);
|
| 623 |
+
clearTimeout(timeoutHandler);
|
| 624 |
+
return event;
|
| 625 |
+
},
|
| 626 |
+
});
|
| 627 |
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
| 628 |
+
}
|
| 629 |
+
}
|
| 630 |
+
/**
|
| 631 |
+
* Determines whether user has asked to ignore this path.
|
| 632 |
+
*/
|
| 633 |
+
_isIgnored(path, stats) {
|
| 634 |
+
if (this.options.atomic && DOT_RE.test(path))
|
| 635 |
+
return true;
|
| 636 |
+
if (!this._userIgnored) {
|
| 637 |
+
const { cwd } = this.options;
|
| 638 |
+
const ign = this.options.ignored;
|
| 639 |
+
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
| 640 |
+
const ignoredPaths = [...this._ignoredPaths];
|
| 641 |
+
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
| 642 |
+
this._userIgnored = anymatch(list, undefined);
|
| 643 |
+
}
|
| 644 |
+
return this._userIgnored(path, stats);
|
| 645 |
+
}
|
| 646 |
+
_isntIgnored(path, stat) {
|
| 647 |
+
return !this._isIgnored(path, stat);
|
| 648 |
+
}
|
| 649 |
+
/**
|
| 650 |
+
* Provides a set of common helpers and properties relating to symlink handling.
|
| 651 |
+
* @param path file or directory pattern being watched
|
| 652 |
+
*/
|
| 653 |
+
_getWatchHelpers(path) {
|
| 654 |
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
| 655 |
+
}
|
| 656 |
+
// Directory helpers
|
| 657 |
+
// -----------------
|
| 658 |
+
/**
|
| 659 |
+
* Provides directory tracking objects
|
| 660 |
+
* @param directory path of the directory
|
| 661 |
+
*/
|
| 662 |
+
_getWatchedDir(directory) {
|
| 663 |
+
const dir = sysPath.resolve(directory);
|
| 664 |
+
if (!this._watched.has(dir))
|
| 665 |
+
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
| 666 |
+
return this._watched.get(dir);
|
| 667 |
+
}
|
| 668 |
+
// File helpers
|
| 669 |
+
// ------------
|
| 670 |
+
/**
|
| 671 |
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
| 672 |
+
*/
|
| 673 |
+
_hasReadPermissions(stats) {
|
| 674 |
+
if (this.options.ignorePermissionErrors)
|
| 675 |
+
return true;
|
| 676 |
+
return Boolean(Number(stats.mode) & 0o400);
|
| 677 |
+
}
|
| 678 |
+
/**
|
| 679 |
+
* Handles emitting unlink events for
|
| 680 |
+
* files and directories, and via recursion, for
|
| 681 |
+
* files and directories within directories that are unlinked
|
| 682 |
+
* @param directory within which the following item is located
|
| 683 |
+
* @param item base path of item/directory
|
| 684 |
+
*/
|
| 685 |
+
_remove(directory, item, isDirectory) {
|
| 686 |
+
// if what is being deleted is a directory, get that directory's paths
|
| 687 |
+
// for recursive deleting and cleaning of watched object
|
| 688 |
+
// if it is not a directory, nestedDirectoryChildren will be empty array
|
| 689 |
+
const path = sysPath.join(directory, item);
|
| 690 |
+
const fullPath = sysPath.resolve(path);
|
| 691 |
+
isDirectory =
|
| 692 |
+
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
| 693 |
+
// prevent duplicate handling in case of arriving here nearly simultaneously
|
| 694 |
+
// via multiple paths (such as _handleFile and _handleDir)
|
| 695 |
+
if (!this._throttle('remove', path, 100))
|
| 696 |
+
return;
|
| 697 |
+
// if the only watched file is removed, watch for its return
|
| 698 |
+
if (!isDirectory && this._watched.size === 1) {
|
| 699 |
+
this.add(directory, item, true);
|
| 700 |
+
}
|
| 701 |
+
// This will create a new entry in the watched object in either case
|
| 702 |
+
// so we got to do the directory check beforehand
|
| 703 |
+
const wp = this._getWatchedDir(path);
|
| 704 |
+
const nestedDirectoryChildren = wp.getChildren();
|
| 705 |
+
// Recursively remove children directories / files.
|
| 706 |
+
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
| 707 |
+
// Check if item was on the watched list and remove it
|
| 708 |
+
const parent = this._getWatchedDir(directory);
|
| 709 |
+
const wasTracked = parent.has(item);
|
| 710 |
+
parent.remove(item);
|
| 711 |
+
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
| 712 |
+
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
| 713 |
+
// but never removed from the map in case the path was deleted.
|
| 714 |
+
// This leads to an incorrect state if the path was recreated:
|
| 715 |
+
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
| 716 |
+
if (this._symlinkPaths.has(fullPath)) {
|
| 717 |
+
this._symlinkPaths.delete(fullPath);
|
| 718 |
+
}
|
| 719 |
+
// If we wait for this file to be fully written, cancel the wait.
|
| 720 |
+
let relPath = path;
|
| 721 |
+
if (this.options.cwd)
|
| 722 |
+
relPath = sysPath.relative(this.options.cwd, path);
|
| 723 |
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
| 724 |
+
const event = this._pendingWrites.get(relPath).cancelWait();
|
| 725 |
+
if (event === EV.ADD)
|
| 726 |
+
return;
|
| 727 |
+
}
|
| 728 |
+
// The Entry will either be a directory that just got removed
|
| 729 |
+
// or a bogus entry to a file, in either case we have to remove it
|
| 730 |
+
this._watched.delete(path);
|
| 731 |
+
this._watched.delete(fullPath);
|
| 732 |
+
const eventName = isDirectory ? EV.UNLINK_DIR : EV.UNLINK;
|
| 733 |
+
if (wasTracked && !this._isIgnored(path))
|
| 734 |
+
this._emit(eventName, path);
|
| 735 |
+
// Avoid conflicts if we later create another file with the same name
|
| 736 |
+
this._closePath(path);
|
| 737 |
+
}
|
| 738 |
+
/**
|
| 739 |
+
* Closes all watchers for a path
|
| 740 |
+
*/
|
| 741 |
+
_closePath(path) {
|
| 742 |
+
this._closeFile(path);
|
| 743 |
+
const dir = sysPath.dirname(path);
|
| 744 |
+
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
| 745 |
+
}
|
| 746 |
+
/**
|
| 747 |
+
* Closes only file-specific watchers
|
| 748 |
+
*/
|
| 749 |
+
_closeFile(path) {
|
| 750 |
+
const closers = this._closers.get(path);
|
| 751 |
+
if (!closers)
|
| 752 |
+
return;
|
| 753 |
+
closers.forEach((closer) => closer());
|
| 754 |
+
this._closers.delete(path);
|
| 755 |
+
}
|
| 756 |
+
_addPathCloser(path, closer) {
|
| 757 |
+
if (!closer)
|
| 758 |
+
return;
|
| 759 |
+
let list = this._closers.get(path);
|
| 760 |
+
if (!list) {
|
| 761 |
+
list = [];
|
| 762 |
+
this._closers.set(path, list);
|
| 763 |
+
}
|
| 764 |
+
list.push(closer);
|
| 765 |
+
}
|
| 766 |
+
_readdirp(root, opts) {
|
| 767 |
+
if (this.closed)
|
| 768 |
+
return;
|
| 769 |
+
const options = { type: EV.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
| 770 |
+
let stream = readdirp(root, options);
|
| 771 |
+
this._streams.add(stream);
|
| 772 |
+
stream.once(STR_CLOSE, () => {
|
| 773 |
+
stream = undefined;
|
| 774 |
+
});
|
| 775 |
+
stream.once(STR_END, () => {
|
| 776 |
+
if (stream) {
|
| 777 |
+
this._streams.delete(stream);
|
| 778 |
+
stream = undefined;
|
| 779 |
+
}
|
| 780 |
+
});
|
| 781 |
+
return stream;
|
| 782 |
+
}
|
| 783 |
+
}
|
| 784 |
+
/**
|
| 785 |
+
* Instantiates watcher with paths to be tracked.
|
| 786 |
+
* @param paths file / directory paths
|
| 787 |
+
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
| 788 |
+
* @returns an instance of FSWatcher for chaining.
|
| 789 |
+
* @example
|
| 790 |
+
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
| 791 |
+
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
| 792 |
+
*/
|
| 793 |
+
export function watch(paths, options = {}) {
|
| 794 |
+
const watcher = new FSWatcher(options);
|
| 795 |
+
watcher.add(paths);
|
| 796 |
+
return watcher;
|
| 797 |
+
}
|
| 798 |
+
export default { watch, FSWatcher };
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{ "type": "module", "sideEffects": false }
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/handler.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
|
| 2 |
+
import type { FSWatcher, WatchHelper, Throttler } from './index.js';
|
| 3 |
+
import type { EntryInfo } from 'readdirp';
|
| 4 |
+
export type Path = string;
|
| 5 |
+
export declare const STR_DATA = "data";
|
| 6 |
+
export declare const STR_END = "end";
|
| 7 |
+
export declare const STR_CLOSE = "close";
|
| 8 |
+
export declare const EMPTY_FN: () => void;
|
| 9 |
+
export declare const IDENTITY_FN: (val: unknown) => unknown;
|
| 10 |
+
export declare const isWindows: boolean;
|
| 11 |
+
export declare const isMacos: boolean;
|
| 12 |
+
export declare const isLinux: boolean;
|
| 13 |
+
export declare const isFreeBSD: boolean;
|
| 14 |
+
export declare const isIBMi: boolean;
|
| 15 |
+
export declare const EVENTS: {
|
| 16 |
+
readonly ALL: "all";
|
| 17 |
+
readonly READY: "ready";
|
| 18 |
+
readonly ADD: "add";
|
| 19 |
+
readonly CHANGE: "change";
|
| 20 |
+
readonly ADD_DIR: "addDir";
|
| 21 |
+
readonly UNLINK: "unlink";
|
| 22 |
+
readonly UNLINK_DIR: "unlinkDir";
|
| 23 |
+
readonly RAW: "raw";
|
| 24 |
+
readonly ERROR: "error";
|
| 25 |
+
};
|
| 26 |
+
export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
|
| 27 |
+
export type FsWatchContainer = {
|
| 28 |
+
listeners: (path: string) => void | Set<any>;
|
| 29 |
+
errHandlers: (err: unknown) => void | Set<any>;
|
| 30 |
+
rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
|
| 31 |
+
watcher: NativeFsWatcher;
|
| 32 |
+
watcherUnusable?: boolean;
|
| 33 |
+
};
|
| 34 |
+
export interface WatchHandlers {
|
| 35 |
+
listener: (path: string) => void;
|
| 36 |
+
errHandler: (err: unknown) => void;
|
| 37 |
+
rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
|
| 38 |
+
}
|
| 39 |
+
/**
|
| 40 |
+
* @mixin
|
| 41 |
+
*/
|
| 42 |
+
export declare class NodeFsHandler {
|
| 43 |
+
fsw: FSWatcher;
|
| 44 |
+
_boundHandleError: (error: unknown) => void;
|
| 45 |
+
constructor(fsW: FSWatcher);
|
| 46 |
+
/**
|
| 47 |
+
* Watch file for changes with fs_watchFile or fs_watch.
|
| 48 |
+
* @param path to file or dir
|
| 49 |
+
* @param listener on fs change
|
| 50 |
+
* @returns closer for the watcher instance
|
| 51 |
+
*/
|
| 52 |
+
_watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
|
| 53 |
+
/**
|
| 54 |
+
* Watch a file and emit add event if warranted.
|
| 55 |
+
* @returns closer for the watcher instance
|
| 56 |
+
*/
|
| 57 |
+
_handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
|
| 58 |
+
/**
|
| 59 |
+
* Handle symlinks encountered while reading a dir.
|
| 60 |
+
* @param entry returned by readdirp
|
| 61 |
+
* @param directory path of dir being read
|
| 62 |
+
* @param path of this item
|
| 63 |
+
* @param item basename of this item
|
| 64 |
+
* @returns true if no more processing is needed for this entry.
|
| 65 |
+
*/
|
| 66 |
+
_handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
|
| 67 |
+
_handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
|
| 68 |
+
/**
|
| 69 |
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
| 70 |
+
* @param dir fs path
|
| 71 |
+
* @param stats
|
| 72 |
+
* @param initialAdd
|
| 73 |
+
* @param depth relative to user-supplied path
|
| 74 |
+
* @param target child path targeted for watch
|
| 75 |
+
* @param wh Common watch helpers for this path
|
| 76 |
+
* @param realpath
|
| 77 |
+
* @returns closer for the watcher instance.
|
| 78 |
+
*/
|
| 79 |
+
_handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
|
| 80 |
+
/**
|
| 81 |
+
* Handle added file, directory, or glob pattern.
|
| 82 |
+
* Delegates call to _handleFile / _handleDir after checks.
|
| 83 |
+
* @param path to file or ir
|
| 84 |
+
* @param initialAdd was the file added at watch instantiation?
|
| 85 |
+
* @param priorWh depth relative to user-supplied path
|
| 86 |
+
* @param depth Child path actually targeted for watch
|
| 87 |
+
* @param target Child path actually targeted for watch
|
| 88 |
+
*/
|
| 89 |
+
_addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
|
| 90 |
+
}
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/handler.js
ADDED
|
@@ -0,0 +1,635 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.NodeFsHandler = exports.EVENTS = exports.isIBMi = exports.isFreeBSD = exports.isLinux = exports.isMacos = exports.isWindows = exports.IDENTITY_FN = exports.EMPTY_FN = exports.STR_CLOSE = exports.STR_END = exports.STR_DATA = void 0;
|
| 4 |
+
const fs_1 = require("fs");
|
| 5 |
+
const promises_1 = require("fs/promises");
|
| 6 |
+
const sysPath = require("path");
|
| 7 |
+
const os_1 = require("os");
|
| 8 |
+
exports.STR_DATA = 'data';
|
| 9 |
+
exports.STR_END = 'end';
|
| 10 |
+
exports.STR_CLOSE = 'close';
|
| 11 |
+
const EMPTY_FN = () => { };
|
| 12 |
+
exports.EMPTY_FN = EMPTY_FN;
|
| 13 |
+
const IDENTITY_FN = (val) => val;
|
| 14 |
+
exports.IDENTITY_FN = IDENTITY_FN;
|
| 15 |
+
const pl = process.platform;
|
| 16 |
+
exports.isWindows = pl === 'win32';
|
| 17 |
+
exports.isMacos = pl === 'darwin';
|
| 18 |
+
exports.isLinux = pl === 'linux';
|
| 19 |
+
exports.isFreeBSD = pl === 'freebsd';
|
| 20 |
+
exports.isIBMi = (0, os_1.type)() === 'OS400';
|
| 21 |
+
exports.EVENTS = {
|
| 22 |
+
ALL: 'all',
|
| 23 |
+
READY: 'ready',
|
| 24 |
+
ADD: 'add',
|
| 25 |
+
CHANGE: 'change',
|
| 26 |
+
ADD_DIR: 'addDir',
|
| 27 |
+
UNLINK: 'unlink',
|
| 28 |
+
UNLINK_DIR: 'unlinkDir',
|
| 29 |
+
RAW: 'raw',
|
| 30 |
+
ERROR: 'error',
|
| 31 |
+
};
|
| 32 |
+
const EV = exports.EVENTS;
|
| 33 |
+
const THROTTLE_MODE_WATCH = 'watch';
|
| 34 |
+
const statMethods = { lstat: promises_1.lstat, stat: promises_1.stat };
|
| 35 |
+
const KEY_LISTENERS = 'listeners';
|
| 36 |
+
const KEY_ERR = 'errHandlers';
|
| 37 |
+
const KEY_RAW = 'rawEmitters';
|
| 38 |
+
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
| 39 |
+
// prettier-ignore
|
| 40 |
+
const binaryExtensions = new Set([
|
| 41 |
+
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
| 42 |
+
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
| 43 |
+
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
| 44 |
+
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
| 45 |
+
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
| 46 |
+
'dtshd', 'dvb', 'dwg', 'dxf',
|
| 47 |
+
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
| 48 |
+
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
| 49 |
+
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
| 50 |
+
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
| 51 |
+
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
| 52 |
+
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
| 53 |
+
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
| 54 |
+
'mobi', 'mov', 'movie', 'mp3',
|
| 55 |
+
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
| 56 |
+
'nef', 'npx', 'numbers', 'nupkg',
|
| 57 |
+
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
| 58 |
+
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
| 59 |
+
'potx', 'ppa', 'ppam',
|
| 60 |
+
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
| 61 |
+
'qt',
|
| 62 |
+
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
| 63 |
+
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
| 64 |
+
'stl', 'suo', 'sub', 'swf',
|
| 65 |
+
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
| 66 |
+
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
| 67 |
+
'viv', 'vob',
|
| 68 |
+
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
| 69 |
+
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
| 70 |
+
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
| 71 |
+
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
| 72 |
+
'z', 'zip', 'zipx',
|
| 73 |
+
]);
|
| 74 |
+
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
| 75 |
+
// TODO: emit errors properly. Example: EMFILE on Macos.
|
| 76 |
+
const foreach = (val, fn) => {
|
| 77 |
+
if (val instanceof Set) {
|
| 78 |
+
val.forEach(fn);
|
| 79 |
+
}
|
| 80 |
+
else {
|
| 81 |
+
fn(val);
|
| 82 |
+
}
|
| 83 |
+
};
|
| 84 |
+
const addAndConvert = (main, prop, item) => {
|
| 85 |
+
let container = main[prop];
|
| 86 |
+
if (!(container instanceof Set)) {
|
| 87 |
+
main[prop] = container = new Set([container]);
|
| 88 |
+
}
|
| 89 |
+
container.add(item);
|
| 90 |
+
};
|
| 91 |
+
const clearItem = (cont) => (key) => {
|
| 92 |
+
const set = cont[key];
|
| 93 |
+
if (set instanceof Set) {
|
| 94 |
+
set.clear();
|
| 95 |
+
}
|
| 96 |
+
else {
|
| 97 |
+
delete cont[key];
|
| 98 |
+
}
|
| 99 |
+
};
|
| 100 |
+
const delFromSet = (main, prop, item) => {
|
| 101 |
+
const container = main[prop];
|
| 102 |
+
if (container instanceof Set) {
|
| 103 |
+
container.delete(item);
|
| 104 |
+
}
|
| 105 |
+
else if (container === item) {
|
| 106 |
+
delete main[prop];
|
| 107 |
+
}
|
| 108 |
+
};
|
| 109 |
+
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
| 110 |
+
const FsWatchInstances = new Map();
|
| 111 |
+
/**
|
| 112 |
+
* Instantiates the fs_watch interface
|
| 113 |
+
* @param path to be watched
|
| 114 |
+
* @param options to be passed to fs_watch
|
| 115 |
+
* @param listener main event handler
|
| 116 |
+
* @param errHandler emits info about errors
|
| 117 |
+
* @param emitRaw emits raw event data
|
| 118 |
+
* @returns {NativeFsWatcher}
|
| 119 |
+
*/
|
| 120 |
+
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
| 121 |
+
const handleEvent = (rawEvent, evPath) => {
|
| 122 |
+
listener(path);
|
| 123 |
+
emitRaw(rawEvent, evPath, { watchedPath: path });
|
| 124 |
+
// emit based on events occurring for files from a directory's watcher in
|
| 125 |
+
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
| 126 |
+
if (evPath && path !== evPath) {
|
| 127 |
+
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
| 128 |
+
}
|
| 129 |
+
};
|
| 130 |
+
try {
|
| 131 |
+
return (0, fs_1.watch)(path, {
|
| 132 |
+
persistent: options.persistent,
|
| 133 |
+
}, handleEvent);
|
| 134 |
+
}
|
| 135 |
+
catch (error) {
|
| 136 |
+
errHandler(error);
|
| 137 |
+
return undefined;
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
/**
|
| 141 |
+
* Helper for passing fs_watch event data to a collection of listeners
|
| 142 |
+
* @param fullPath absolute path bound to fs_watch instance
|
| 143 |
+
*/
|
| 144 |
+
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
| 145 |
+
const cont = FsWatchInstances.get(fullPath);
|
| 146 |
+
if (!cont)
|
| 147 |
+
return;
|
| 148 |
+
foreach(cont[listenerType], (listener) => {
|
| 149 |
+
listener(val1, val2, val3);
|
| 150 |
+
});
|
| 151 |
+
};
|
| 152 |
+
/**
|
| 153 |
+
* Instantiates the fs_watch interface or binds listeners
|
| 154 |
+
* to an existing one covering the same file system entry
|
| 155 |
+
* @param path
|
| 156 |
+
* @param fullPath absolute path
|
| 157 |
+
* @param options to be passed to fs_watch
|
| 158 |
+
* @param handlers container for event listener functions
|
| 159 |
+
*/
|
| 160 |
+
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
| 161 |
+
const { listener, errHandler, rawEmitter } = handlers;
|
| 162 |
+
let cont = FsWatchInstances.get(fullPath);
|
| 163 |
+
let watcher;
|
| 164 |
+
if (!options.persistent) {
|
| 165 |
+
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
| 166 |
+
if (!watcher)
|
| 167 |
+
return;
|
| 168 |
+
return watcher.close.bind(watcher);
|
| 169 |
+
}
|
| 170 |
+
if (cont) {
|
| 171 |
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
| 172 |
+
addAndConvert(cont, KEY_ERR, errHandler);
|
| 173 |
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
| 174 |
+
}
|
| 175 |
+
else {
|
| 176 |
+
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
| 177 |
+
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
| 178 |
+
if (!watcher)
|
| 179 |
+
return;
|
| 180 |
+
watcher.on(EV.ERROR, async (error) => {
|
| 181 |
+
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
| 182 |
+
if (cont)
|
| 183 |
+
cont.watcherUnusable = true; // documented since Node 10.4.1
|
| 184 |
+
// Workaround for https://github.com/joyent/node/issues/4337
|
| 185 |
+
if (exports.isWindows && error.code === 'EPERM') {
|
| 186 |
+
try {
|
| 187 |
+
const fd = await (0, promises_1.open)(path, 'r');
|
| 188 |
+
await fd.close();
|
| 189 |
+
broadcastErr(error);
|
| 190 |
+
}
|
| 191 |
+
catch (err) {
|
| 192 |
+
// do nothing
|
| 193 |
+
}
|
| 194 |
+
}
|
| 195 |
+
else {
|
| 196 |
+
broadcastErr(error);
|
| 197 |
+
}
|
| 198 |
+
});
|
| 199 |
+
cont = {
|
| 200 |
+
listeners: listener,
|
| 201 |
+
errHandlers: errHandler,
|
| 202 |
+
rawEmitters: rawEmitter,
|
| 203 |
+
watcher,
|
| 204 |
+
};
|
| 205 |
+
FsWatchInstances.set(fullPath, cont);
|
| 206 |
+
}
|
| 207 |
+
// const index = cont.listeners.indexOf(listener);
|
| 208 |
+
// removes this instance's listeners and closes the underlying fs_watch
|
| 209 |
+
// instance if there are no more listeners left
|
| 210 |
+
return () => {
|
| 211 |
+
delFromSet(cont, KEY_LISTENERS, listener);
|
| 212 |
+
delFromSet(cont, KEY_ERR, errHandler);
|
| 213 |
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
| 214 |
+
if (isEmptySet(cont.listeners)) {
|
| 215 |
+
// Check to protect against issue gh-730.
|
| 216 |
+
// if (cont.watcherUnusable) {
|
| 217 |
+
cont.watcher.close();
|
| 218 |
+
// }
|
| 219 |
+
FsWatchInstances.delete(fullPath);
|
| 220 |
+
HANDLER_KEYS.forEach(clearItem(cont));
|
| 221 |
+
// @ts-ignore
|
| 222 |
+
cont.watcher = undefined;
|
| 223 |
+
Object.freeze(cont);
|
| 224 |
+
}
|
| 225 |
+
};
|
| 226 |
+
};
|
| 227 |
+
// fs_watchFile helpers
|
| 228 |
+
// object to hold per-process fs_watchFile instances
|
| 229 |
+
// (may be shared across chokidar FSWatcher instances)
|
| 230 |
+
const FsWatchFileInstances = new Map();
|
| 231 |
+
/**
|
| 232 |
+
* Instantiates the fs_watchFile interface or binds listeners
|
| 233 |
+
* to an existing one covering the same file system entry
|
| 234 |
+
* @param path to be watched
|
| 235 |
+
* @param fullPath absolute path
|
| 236 |
+
* @param options options to be passed to fs_watchFile
|
| 237 |
+
* @param handlers container for event listener functions
|
| 238 |
+
* @returns closer
|
| 239 |
+
*/
|
| 240 |
+
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
| 241 |
+
const { listener, rawEmitter } = handlers;
|
| 242 |
+
let cont = FsWatchFileInstances.get(fullPath);
|
| 243 |
+
// let listeners = new Set();
|
| 244 |
+
// let rawEmitters = new Set();
|
| 245 |
+
const copts = cont && cont.options;
|
| 246 |
+
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
| 247 |
+
// "Upgrade" the watcher to persistence or a quicker interval.
|
| 248 |
+
// This creates some unlikely edge case issues if the user mixes
|
| 249 |
+
// settings in a very weird way, but solving for those cases
|
| 250 |
+
// doesn't seem worthwhile for the added complexity.
|
| 251 |
+
// listeners = cont.listeners;
|
| 252 |
+
// rawEmitters = cont.rawEmitters;
|
| 253 |
+
(0, fs_1.unwatchFile)(fullPath);
|
| 254 |
+
cont = undefined;
|
| 255 |
+
}
|
| 256 |
+
if (cont) {
|
| 257 |
+
addAndConvert(cont, KEY_LISTENERS, listener);
|
| 258 |
+
addAndConvert(cont, KEY_RAW, rawEmitter);
|
| 259 |
+
}
|
| 260 |
+
else {
|
| 261 |
+
// TODO
|
| 262 |
+
// listeners.add(listener);
|
| 263 |
+
// rawEmitters.add(rawEmitter);
|
| 264 |
+
cont = {
|
| 265 |
+
listeners: listener,
|
| 266 |
+
rawEmitters: rawEmitter,
|
| 267 |
+
options,
|
| 268 |
+
watcher: (0, fs_1.watchFile)(fullPath, options, (curr, prev) => {
|
| 269 |
+
foreach(cont.rawEmitters, (rawEmitter) => {
|
| 270 |
+
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
| 271 |
+
});
|
| 272 |
+
const currmtime = curr.mtimeMs;
|
| 273 |
+
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
| 274 |
+
foreach(cont.listeners, (listener) => listener(path, curr));
|
| 275 |
+
}
|
| 276 |
+
}),
|
| 277 |
+
};
|
| 278 |
+
FsWatchFileInstances.set(fullPath, cont);
|
| 279 |
+
}
|
| 280 |
+
// const index = cont.listeners.indexOf(listener);
|
| 281 |
+
// Removes this instance's listeners and closes the underlying fs_watchFile
|
| 282 |
+
// instance if there are no more listeners left.
|
| 283 |
+
return () => {
|
| 284 |
+
delFromSet(cont, KEY_LISTENERS, listener);
|
| 285 |
+
delFromSet(cont, KEY_RAW, rawEmitter);
|
| 286 |
+
if (isEmptySet(cont.listeners)) {
|
| 287 |
+
FsWatchFileInstances.delete(fullPath);
|
| 288 |
+
(0, fs_1.unwatchFile)(fullPath);
|
| 289 |
+
cont.options = cont.watcher = undefined;
|
| 290 |
+
Object.freeze(cont);
|
| 291 |
+
}
|
| 292 |
+
};
|
| 293 |
+
};
|
| 294 |
+
/**
|
| 295 |
+
* @mixin
|
| 296 |
+
*/
|
| 297 |
+
class NodeFsHandler {
|
| 298 |
+
constructor(fsW) {
|
| 299 |
+
this.fsw = fsW;
|
| 300 |
+
this._boundHandleError = (error) => fsW._handleError(error);
|
| 301 |
+
}
|
| 302 |
+
/**
|
| 303 |
+
* Watch file for changes with fs_watchFile or fs_watch.
|
| 304 |
+
* @param path to file or dir
|
| 305 |
+
* @param listener on fs change
|
| 306 |
+
* @returns closer for the watcher instance
|
| 307 |
+
*/
|
| 308 |
+
_watchWithNodeFs(path, listener) {
|
| 309 |
+
const opts = this.fsw.options;
|
| 310 |
+
const directory = sysPath.dirname(path);
|
| 311 |
+
const basename = sysPath.basename(path);
|
| 312 |
+
const parent = this.fsw._getWatchedDir(directory);
|
| 313 |
+
parent.add(basename);
|
| 314 |
+
const absolutePath = sysPath.resolve(path);
|
| 315 |
+
const options = {
|
| 316 |
+
persistent: opts.persistent,
|
| 317 |
+
};
|
| 318 |
+
if (!listener)
|
| 319 |
+
listener = exports.EMPTY_FN;
|
| 320 |
+
let closer;
|
| 321 |
+
if (opts.usePolling) {
|
| 322 |
+
const enableBin = opts.interval !== opts.binaryInterval;
|
| 323 |
+
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
| 324 |
+
closer = setFsWatchFileListener(path, absolutePath, options, {
|
| 325 |
+
listener,
|
| 326 |
+
rawEmitter: this.fsw._emitRaw,
|
| 327 |
+
});
|
| 328 |
+
}
|
| 329 |
+
else {
|
| 330 |
+
closer = setFsWatchListener(path, absolutePath, options, {
|
| 331 |
+
listener,
|
| 332 |
+
errHandler: this._boundHandleError,
|
| 333 |
+
rawEmitter: this.fsw._emitRaw,
|
| 334 |
+
});
|
| 335 |
+
}
|
| 336 |
+
return closer;
|
| 337 |
+
}
|
| 338 |
+
/**
|
| 339 |
+
* Watch a file and emit add event if warranted.
|
| 340 |
+
* @returns closer for the watcher instance
|
| 341 |
+
*/
|
| 342 |
+
_handleFile(file, stats, initialAdd) {
|
| 343 |
+
if (this.fsw.closed) {
|
| 344 |
+
return;
|
| 345 |
+
}
|
| 346 |
+
const dirname = sysPath.dirname(file);
|
| 347 |
+
const basename = sysPath.basename(file);
|
| 348 |
+
const parent = this.fsw._getWatchedDir(dirname);
|
| 349 |
+
// stats is always present
|
| 350 |
+
let prevStats = stats;
|
| 351 |
+
// if the file is already being watched, do nothing
|
| 352 |
+
if (parent.has(basename))
|
| 353 |
+
return;
|
| 354 |
+
const listener = async (path, newStats) => {
|
| 355 |
+
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
| 356 |
+
return;
|
| 357 |
+
if (!newStats || newStats.mtimeMs === 0) {
|
| 358 |
+
try {
|
| 359 |
+
const newStats = await (0, promises_1.stat)(file);
|
| 360 |
+
if (this.fsw.closed)
|
| 361 |
+
return;
|
| 362 |
+
// Check that change event was not fired because of changed only accessTime.
|
| 363 |
+
const at = newStats.atimeMs;
|
| 364 |
+
const mt = newStats.mtimeMs;
|
| 365 |
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
| 366 |
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
| 367 |
+
}
|
| 368 |
+
if ((exports.isMacos || exports.isLinux || exports.isFreeBSD) && prevStats.ino !== newStats.ino) {
|
| 369 |
+
this.fsw._closeFile(path);
|
| 370 |
+
prevStats = newStats;
|
| 371 |
+
const closer = this._watchWithNodeFs(file, listener);
|
| 372 |
+
if (closer)
|
| 373 |
+
this.fsw._addPathCloser(path, closer);
|
| 374 |
+
}
|
| 375 |
+
else {
|
| 376 |
+
prevStats = newStats;
|
| 377 |
+
}
|
| 378 |
+
}
|
| 379 |
+
catch (error) {
|
| 380 |
+
// Fix issues where mtime is null but file is still present
|
| 381 |
+
this.fsw._remove(dirname, basename);
|
| 382 |
+
}
|
| 383 |
+
// add is about to be emitted if file not already tracked in parent
|
| 384 |
+
}
|
| 385 |
+
else if (parent.has(basename)) {
|
| 386 |
+
// Check that change event was not fired because of changed only accessTime.
|
| 387 |
+
const at = newStats.atimeMs;
|
| 388 |
+
const mt = newStats.mtimeMs;
|
| 389 |
+
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
| 390 |
+
this.fsw._emit(EV.CHANGE, file, newStats);
|
| 391 |
+
}
|
| 392 |
+
prevStats = newStats;
|
| 393 |
+
}
|
| 394 |
+
};
|
| 395 |
+
// kick off the watcher
|
| 396 |
+
const closer = this._watchWithNodeFs(file, listener);
|
| 397 |
+
// emit an add event if we're supposed to
|
| 398 |
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
| 399 |
+
if (!this.fsw._throttle(EV.ADD, file, 0))
|
| 400 |
+
return;
|
| 401 |
+
this.fsw._emit(EV.ADD, file, stats);
|
| 402 |
+
}
|
| 403 |
+
return closer;
|
| 404 |
+
}
|
| 405 |
+
/**
|
| 406 |
+
* Handle symlinks encountered while reading a dir.
|
| 407 |
+
* @param entry returned by readdirp
|
| 408 |
+
* @param directory path of dir being read
|
| 409 |
+
* @param path of this item
|
| 410 |
+
* @param item basename of this item
|
| 411 |
+
* @returns true if no more processing is needed for this entry.
|
| 412 |
+
*/
|
| 413 |
+
async _handleSymlink(entry, directory, path, item) {
|
| 414 |
+
if (this.fsw.closed) {
|
| 415 |
+
return;
|
| 416 |
+
}
|
| 417 |
+
const full = entry.fullPath;
|
| 418 |
+
const dir = this.fsw._getWatchedDir(directory);
|
| 419 |
+
if (!this.fsw.options.followSymlinks) {
|
| 420 |
+
// watch symlink directly (don't follow) and detect changes
|
| 421 |
+
this.fsw._incrReadyCount();
|
| 422 |
+
let linkPath;
|
| 423 |
+
try {
|
| 424 |
+
linkPath = await (0, promises_1.realpath)(path);
|
| 425 |
+
}
|
| 426 |
+
catch (e) {
|
| 427 |
+
this.fsw._emitReady();
|
| 428 |
+
return true;
|
| 429 |
+
}
|
| 430 |
+
if (this.fsw.closed)
|
| 431 |
+
return;
|
| 432 |
+
if (dir.has(item)) {
|
| 433 |
+
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
| 434 |
+
this.fsw._symlinkPaths.set(full, linkPath);
|
| 435 |
+
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
else {
|
| 439 |
+
dir.add(item);
|
| 440 |
+
this.fsw._symlinkPaths.set(full, linkPath);
|
| 441 |
+
this.fsw._emit(EV.ADD, path, entry.stats);
|
| 442 |
+
}
|
| 443 |
+
this.fsw._emitReady();
|
| 444 |
+
return true;
|
| 445 |
+
}
|
| 446 |
+
// don't follow the same symlink more than once
|
| 447 |
+
if (this.fsw._symlinkPaths.has(full)) {
|
| 448 |
+
return true;
|
| 449 |
+
}
|
| 450 |
+
this.fsw._symlinkPaths.set(full, true);
|
| 451 |
+
}
|
| 452 |
+
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
| 453 |
+
// Normalize the directory name on Windows
|
| 454 |
+
directory = sysPath.join(directory, '');
|
| 455 |
+
throttler = this.fsw._throttle('readdir', directory, 1000);
|
| 456 |
+
if (!throttler)
|
| 457 |
+
return;
|
| 458 |
+
const previous = this.fsw._getWatchedDir(wh.path);
|
| 459 |
+
const current = new Set();
|
| 460 |
+
let stream = this.fsw._readdirp(directory, {
|
| 461 |
+
fileFilter: (entry) => wh.filterPath(entry),
|
| 462 |
+
directoryFilter: (entry) => wh.filterDir(entry),
|
| 463 |
+
});
|
| 464 |
+
if (!stream)
|
| 465 |
+
return;
|
| 466 |
+
stream
|
| 467 |
+
.on(exports.STR_DATA, async (entry) => {
|
| 468 |
+
if (this.fsw.closed) {
|
| 469 |
+
stream = undefined;
|
| 470 |
+
return;
|
| 471 |
+
}
|
| 472 |
+
const item = entry.path;
|
| 473 |
+
let path = sysPath.join(directory, item);
|
| 474 |
+
current.add(item);
|
| 475 |
+
if (entry.stats.isSymbolicLink() &&
|
| 476 |
+
(await this._handleSymlink(entry, directory, path, item))) {
|
| 477 |
+
return;
|
| 478 |
+
}
|
| 479 |
+
if (this.fsw.closed) {
|
| 480 |
+
stream = undefined;
|
| 481 |
+
return;
|
| 482 |
+
}
|
| 483 |
+
// Files that present in current directory snapshot
|
| 484 |
+
// but absent in previous are added to watch list and
|
| 485 |
+
// emit `add` event.
|
| 486 |
+
if (item === target || (!target && !previous.has(item))) {
|
| 487 |
+
this.fsw._incrReadyCount();
|
| 488 |
+
// ensure relativeness of path is preserved in case of watcher reuse
|
| 489 |
+
path = sysPath.join(dir, sysPath.relative(dir, path));
|
| 490 |
+
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
| 491 |
+
}
|
| 492 |
+
})
|
| 493 |
+
.on(EV.ERROR, this._boundHandleError);
|
| 494 |
+
return new Promise((resolve, reject) => {
|
| 495 |
+
if (!stream)
|
| 496 |
+
return reject();
|
| 497 |
+
stream.once(exports.STR_END, () => {
|
| 498 |
+
if (this.fsw.closed) {
|
| 499 |
+
stream = undefined;
|
| 500 |
+
return;
|
| 501 |
+
}
|
| 502 |
+
const wasThrottled = throttler ? throttler.clear() : false;
|
| 503 |
+
resolve(undefined);
|
| 504 |
+
// Files that absent in current directory snapshot
|
| 505 |
+
// but present in previous emit `remove` event
|
| 506 |
+
// and are removed from @watched[directory].
|
| 507 |
+
previous
|
| 508 |
+
.getChildren()
|
| 509 |
+
.filter((item) => {
|
| 510 |
+
return item !== directory && !current.has(item);
|
| 511 |
+
})
|
| 512 |
+
.forEach((item) => {
|
| 513 |
+
this.fsw._remove(directory, item);
|
| 514 |
+
});
|
| 515 |
+
stream = undefined;
|
| 516 |
+
// one more time for any missed in case changes came in extremely quickly
|
| 517 |
+
if (wasThrottled)
|
| 518 |
+
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
| 519 |
+
});
|
| 520 |
+
});
|
| 521 |
+
}
|
| 522 |
+
/**
|
| 523 |
+
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
| 524 |
+
* @param dir fs path
|
| 525 |
+
* @param stats
|
| 526 |
+
* @param initialAdd
|
| 527 |
+
* @param depth relative to user-supplied path
|
| 528 |
+
* @param target child path targeted for watch
|
| 529 |
+
* @param wh Common watch helpers for this path
|
| 530 |
+
* @param realpath
|
| 531 |
+
* @returns closer for the watcher instance.
|
| 532 |
+
*/
|
| 533 |
+
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
| 534 |
+
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
| 535 |
+
const tracked = parentDir.has(sysPath.basename(dir));
|
| 536 |
+
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
| 537 |
+
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
| 538 |
+
}
|
| 539 |
+
// ensure dir is tracked (harmless if redundant)
|
| 540 |
+
parentDir.add(sysPath.basename(dir));
|
| 541 |
+
this.fsw._getWatchedDir(dir);
|
| 542 |
+
let throttler;
|
| 543 |
+
let closer;
|
| 544 |
+
const oDepth = this.fsw.options.depth;
|
| 545 |
+
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
| 546 |
+
if (!target) {
|
| 547 |
+
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
| 548 |
+
if (this.fsw.closed)
|
| 549 |
+
return;
|
| 550 |
+
}
|
| 551 |
+
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
| 552 |
+
// if current directory is removed, do nothing
|
| 553 |
+
if (stats && stats.mtimeMs === 0)
|
| 554 |
+
return;
|
| 555 |
+
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
| 556 |
+
});
|
| 557 |
+
}
|
| 558 |
+
return closer;
|
| 559 |
+
}
|
| 560 |
+
/**
|
| 561 |
+
* Handle added file, directory, or glob pattern.
|
| 562 |
+
* Delegates call to _handleFile / _handleDir after checks.
|
| 563 |
+
* @param path to file or ir
|
| 564 |
+
* @param initialAdd was the file added at watch instantiation?
|
| 565 |
+
* @param priorWh depth relative to user-supplied path
|
| 566 |
+
* @param depth Child path actually targeted for watch
|
| 567 |
+
* @param target Child path actually targeted for watch
|
| 568 |
+
*/
|
| 569 |
+
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
| 570 |
+
const ready = this.fsw._emitReady;
|
| 571 |
+
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
| 572 |
+
ready();
|
| 573 |
+
return false;
|
| 574 |
+
}
|
| 575 |
+
const wh = this.fsw._getWatchHelpers(path);
|
| 576 |
+
if (priorWh) {
|
| 577 |
+
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
| 578 |
+
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
| 579 |
+
}
|
| 580 |
+
// evaluate what is at the path we're being asked to watch
|
| 581 |
+
try {
|
| 582 |
+
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
| 583 |
+
if (this.fsw.closed)
|
| 584 |
+
return;
|
| 585 |
+
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
| 586 |
+
ready();
|
| 587 |
+
return false;
|
| 588 |
+
}
|
| 589 |
+
const follow = this.fsw.options.followSymlinks;
|
| 590 |
+
let closer;
|
| 591 |
+
if (stats.isDirectory()) {
|
| 592 |
+
const absPath = sysPath.resolve(path);
|
| 593 |
+
const targetPath = follow ? await (0, promises_1.realpath)(path) : path;
|
| 594 |
+
if (this.fsw.closed)
|
| 595 |
+
return;
|
| 596 |
+
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
| 597 |
+
if (this.fsw.closed)
|
| 598 |
+
return;
|
| 599 |
+
// preserve this symlink's target path
|
| 600 |
+
if (absPath !== targetPath && targetPath !== undefined) {
|
| 601 |
+
this.fsw._symlinkPaths.set(absPath, targetPath);
|
| 602 |
+
}
|
| 603 |
+
}
|
| 604 |
+
else if (stats.isSymbolicLink()) {
|
| 605 |
+
const targetPath = follow ? await (0, promises_1.realpath)(path) : path;
|
| 606 |
+
if (this.fsw.closed)
|
| 607 |
+
return;
|
| 608 |
+
const parent = sysPath.dirname(wh.watchPath);
|
| 609 |
+
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
| 610 |
+
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
| 611 |
+
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
| 612 |
+
if (this.fsw.closed)
|
| 613 |
+
return;
|
| 614 |
+
// preserve this symlink's target path
|
| 615 |
+
if (targetPath !== undefined) {
|
| 616 |
+
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
| 617 |
+
}
|
| 618 |
+
}
|
| 619 |
+
else {
|
| 620 |
+
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
| 621 |
+
}
|
| 622 |
+
ready();
|
| 623 |
+
if (closer)
|
| 624 |
+
this.fsw._addPathCloser(path, closer);
|
| 625 |
+
return false;
|
| 626 |
+
}
|
| 627 |
+
catch (error) {
|
| 628 |
+
if (this.fsw._handleError(error)) {
|
| 629 |
+
ready();
|
| 630 |
+
return path;
|
| 631 |
+
}
|
| 632 |
+
}
|
| 633 |
+
}
|
| 634 |
+
}
|
| 635 |
+
exports.NodeFsHandler = NodeFsHandler;
|
tools/ui/node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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
| 2 |
+
import { Stats } from 'fs';
|
| 3 |
+
import { EventEmitter } from 'events';
|
| 4 |
+
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp';
|
| 5 |
+
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js';
|
| 6 |
+
type AWF = {
|
| 7 |
+
stabilityThreshold: number;
|
| 8 |
+
pollInterval: number;
|
| 9 |
+
};
|
| 10 |
+
type BasicOpts = {
|
| 11 |
+
persistent: boolean;
|
| 12 |
+
ignoreInitial: boolean;
|
| 13 |
+
followSymlinks: boolean;
|
| 14 |
+
cwd?: string;
|
| 15 |
+
usePolling: boolean;
|
| 16 |
+
interval: number;
|
| 17 |
+
binaryInterval: number;
|
| 18 |
+
alwaysStat?: boolean;
|
| 19 |
+
depth?: number;
|
| 20 |
+
ignorePermissionErrors: boolean;
|
| 21 |
+
atomic: boolean | number;
|
| 22 |
+
};
|
| 23 |
+
export type Throttler = {
|
| 24 |
+
timeoutObject: NodeJS.Timeout;
|
| 25 |
+
clear: () => void;
|
| 26 |
+
count: number;
|
| 27 |
+
};
|
| 28 |
+
export type ChokidarOptions = Partial<BasicOpts & {
|
| 29 |
+
ignored: Matcher | Matcher[];
|
| 30 |
+
awaitWriteFinish: boolean | Partial<AWF>;
|
| 31 |
+
}>;
|
| 32 |
+
export type FSWInstanceOptions = BasicOpts & {
|
| 33 |
+
ignored: Matcher[];
|
| 34 |
+
awaitWriteFinish: false | AWF;
|
| 35 |
+
};
|
| 36 |
+
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
|
| 37 |
+
export type EmitArgs = [path: Path, stats?: Stats];
|
| 38 |
+
export type EmitErrorArgs = [error: Error, stats?: Stats];
|
| 39 |
+
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
|
| 40 |
+
export type MatchFunction = (val: string, stats?: Stats) => boolean;
|
| 41 |
+
export interface MatcherObject {
|
| 42 |
+
path: string;
|
| 43 |
+
recursive?: boolean;
|
| 44 |
+
}
|
| 45 |
+
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
|
| 46 |
+
/**
|
| 47 |
+
* Directory entry.
|
| 48 |
+
*/
|
| 49 |
+
declare class DirEntry {
|
| 50 |
+
path: Path;
|
| 51 |
+
_removeWatcher: (dir: string, base: string) => void;
|
| 52 |
+
items: Set<Path>;
|
| 53 |
+
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
|
| 54 |
+
add(item: string): void;
|
| 55 |
+
remove(item: string): Promise<void>;
|
| 56 |
+
has(item: string): boolean | undefined;
|
| 57 |
+
getChildren(): string[];
|
| 58 |
+
dispose(): void;
|
| 59 |
+
}
|
| 60 |
+
export declare class WatchHelper {
|
| 61 |
+
fsw: FSWatcher;
|
| 62 |
+
path: string;
|
| 63 |
+
watchPath: string;
|
| 64 |
+
fullWatchPath: string;
|
| 65 |
+
dirParts: string[][];
|
| 66 |
+
followSymlinks: boolean;
|
| 67 |
+
statMethod: 'stat' | 'lstat';
|
| 68 |
+
constructor(path: string, follow: boolean, fsw: FSWatcher);
|
| 69 |
+
entryPath(entry: EntryInfo): Path;
|
| 70 |
+
filterPath(entry: EntryInfo): boolean;
|
| 71 |
+
filterDir(entry: EntryInfo): boolean;
|
| 72 |
+
}
|
| 73 |
+
export interface FSWatcherKnownEventMap {
|
| 74 |
+
[EV.READY]: [];
|
| 75 |
+
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
|
| 76 |
+
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
|
| 77 |
+
[EV.ALL]: [event: EventName, ...EmitArgs];
|
| 78 |
+
}
|
| 79 |
+
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
|
| 80 |
+
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
|
| 81 |
+
};
|
| 82 |
+
/**
|
| 83 |
+
* Watches files & directories for changes. Emitted events:
|
| 84 |
+
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
| 85 |
+
*
|
| 86 |
+
* new FSWatcher()
|
| 87 |
+
* .add(directories)
|
| 88 |
+
* .on('add', path => log('File', path, 'was added'))
|
| 89 |
+
*/
|
| 90 |
+
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
|
| 91 |
+
closed: boolean;
|
| 92 |
+
options: FSWInstanceOptions;
|
| 93 |
+
_closers: Map<string, Array<any>>;
|
| 94 |
+
_ignoredPaths: Set<Matcher>;
|
| 95 |
+
_throttled: Map<ThrottleType, Map<any, any>>;
|
| 96 |
+
_streams: Set<ReaddirpStream>;
|
| 97 |
+
_symlinkPaths: Map<Path, string | boolean>;
|
| 98 |
+
_watched: Map<string, DirEntry>;
|
| 99 |
+
_pendingWrites: Map<string, any>;
|
| 100 |
+
_pendingUnlinks: Map<string, EmitArgsWithName>;
|
| 101 |
+
_readyCount: number;
|
| 102 |
+
_emitReady: () => void;
|
| 103 |
+
_closePromise?: Promise<void>;
|
| 104 |
+
_userIgnored?: MatchFunction;
|
| 105 |
+
_readyEmitted: boolean;
|
| 106 |
+
_emitRaw: WatchHandlers['rawEmitter'];
|
| 107 |
+
_boundRemove: (dir: string, item: string) => void;
|
| 108 |
+
_nodeFsHandler: NodeFsHandler;
|
| 109 |
+
constructor(_opts?: ChokidarOptions);
|
| 110 |
+
_addIgnoredPath(matcher: Matcher): void;
|
| 111 |
+
_removeIgnoredPath(matcher: Matcher): void;
|
| 112 |
+
/**
|
| 113 |
+
* Adds paths to be watched on an existing FSWatcher instance.
|
| 114 |
+
* @param paths_ file or file list. Other arguments are unused
|
| 115 |
+
*/
|
| 116 |
+
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
|
| 117 |
+
/**
|
| 118 |
+
* Close watchers or start ignoring events from specified paths.
|
| 119 |
+
*/
|
| 120 |
+
unwatch(paths_: Path | Path[]): FSWatcher;
|
| 121 |
+
/**
|
| 122 |
+
* Close watchers and remove all listeners from watched paths.
|
| 123 |
+
*/
|
| 124 |
+
close(): Promise<void>;
|
| 125 |
+
/**
|
| 126 |
+
* Expose list of watched paths
|
| 127 |
+
* @returns for chaining
|
| 128 |
+
*/
|
| 129 |
+
getWatched(): Record<string, string[]>;
|
| 130 |
+
emitWithAll(event: EventName, args: EmitArgs): void;
|
| 131 |
+
/**
|
| 132 |
+
* Normalize and emit events.
|
| 133 |
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
| 134 |
+
* @param event Type of event
|
| 135 |
+
* @param path File or directory path
|
| 136 |
+
* @param stats arguments to be passed with event
|
| 137 |
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 138 |
+
*/
|
| 139 |
+
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
|
| 140 |
+
/**
|
| 141 |
+
* Common handler for errors
|
| 142 |
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 143 |
+
*/
|
| 144 |
+
_handleError(error: Error): Error | boolean;
|
| 145 |
+
/**
|
| 146 |
+
* Helper utility for throttling
|
| 147 |
+
* @param actionType type being throttled
|
| 148 |
+
* @param path being acted upon
|
| 149 |
+
* @param timeout duration of time to suppress duplicate actions
|
| 150 |
+
* @returns tracking object or false if action should be suppressed
|
| 151 |
+
*/
|
| 152 |
+
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
|
| 153 |
+
_incrReadyCount(): number;
|
| 154 |
+
/**
|
| 155 |
+
* Awaits write operation to finish.
|
| 156 |
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
| 157 |
+
* @param path being acted upon
|
| 158 |
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
| 159 |
+
* @param event
|
| 160 |
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
| 161 |
+
*/
|
| 162 |
+
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
|
| 163 |
+
/**
|
| 164 |
+
* Determines whether user has asked to ignore this path.
|
| 165 |
+
*/
|
| 166 |
+
_isIgnored(path: Path, stats?: Stats): boolean;
|
| 167 |
+
_isntIgnored(path: Path, stat?: Stats): boolean;
|
| 168 |
+
/**
|
| 169 |
+
* Provides a set of common helpers and properties relating to symlink handling.
|
| 170 |
+
* @param path file or directory pattern being watched
|
| 171 |
+
*/
|
| 172 |
+
_getWatchHelpers(path: Path): WatchHelper;
|
| 173 |
+
/**
|
| 174 |
+
* Provides directory tracking objects
|
| 175 |
+
* @param directory path of the directory
|
| 176 |
+
*/
|
| 177 |
+
_getWatchedDir(directory: string): DirEntry;
|
| 178 |
+
/**
|
| 179 |
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
| 180 |
+
*/
|
| 181 |
+
_hasReadPermissions(stats: Stats): boolean;
|
| 182 |
+
/**
|
| 183 |
+
* Handles emitting unlink events for
|
| 184 |
+
* files and directories, and via recursion, for
|
| 185 |
+
* files and directories within directories that are unlinked
|
| 186 |
+
* @param directory within which the following item is located
|
| 187 |
+
* @param item base path of item/directory
|
| 188 |
+
*/
|
| 189 |
+
_remove(directory: string, item: string, isDirectory?: boolean): void;
|
| 190 |
+
/**
|
| 191 |
+
* Closes all watchers for a path
|
| 192 |
+
*/
|
| 193 |
+
_closePath(path: Path): void;
|
| 194 |
+
/**
|
| 195 |
+
* Closes only file-specific watchers
|
| 196 |
+
*/
|
| 197 |
+
_closeFile(path: Path): void;
|
| 198 |
+
_addPathCloser(path: Path, closer: () => void): void;
|
| 199 |
+
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
|
| 200 |
+
}
|
| 201 |
+
/**
|
| 202 |
+
* Instantiates watcher with paths to be tracked.
|
| 203 |
+
* @param paths file / directory paths
|
| 204 |
+
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
| 205 |
+
* @returns an instance of FSWatcher for chaining.
|
| 206 |
+
* @example
|
| 207 |
+
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
| 208 |
+
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
| 209 |
+
*/
|
| 210 |
+
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
|
| 211 |
+
declare const _default: {
|
| 212 |
+
watch: typeof watch;
|
| 213 |
+
FSWatcher: typeof FSWatcher;
|
| 214 |
+
};
|
| 215 |
+
export default _default;
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/index.js
ADDED
|
@@ -0,0 +1,804 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
Object.defineProperty(exports, "__esModule", { value: true });
|
| 3 |
+
exports.FSWatcher = exports.WatchHelper = void 0;
|
| 4 |
+
exports.watch = watch;
|
| 5 |
+
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
| 6 |
+
const fs_1 = require("fs");
|
| 7 |
+
const promises_1 = require("fs/promises");
|
| 8 |
+
const events_1 = require("events");
|
| 9 |
+
const sysPath = require("path");
|
| 10 |
+
const readdirp_1 = require("readdirp");
|
| 11 |
+
const handler_js_1 = require("./handler.js");
|
| 12 |
+
const SLASH = '/';
|
| 13 |
+
const SLASH_SLASH = '//';
|
| 14 |
+
const ONE_DOT = '.';
|
| 15 |
+
const TWO_DOTS = '..';
|
| 16 |
+
const STRING_TYPE = 'string';
|
| 17 |
+
const BACK_SLASH_RE = /\\/g;
|
| 18 |
+
const DOUBLE_SLASH_RE = /\/\//;
|
| 19 |
+
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
| 20 |
+
const REPLACER_RE = /^\.[/\\]/;
|
| 21 |
+
function arrify(item) {
|
| 22 |
+
return Array.isArray(item) ? item : [item];
|
| 23 |
+
}
|
| 24 |
+
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
| 25 |
+
function createPattern(matcher) {
|
| 26 |
+
if (typeof matcher === 'function')
|
| 27 |
+
return matcher;
|
| 28 |
+
if (typeof matcher === 'string')
|
| 29 |
+
return (string) => matcher === string;
|
| 30 |
+
if (matcher instanceof RegExp)
|
| 31 |
+
return (string) => matcher.test(string);
|
| 32 |
+
if (typeof matcher === 'object' && matcher !== null) {
|
| 33 |
+
return (string) => {
|
| 34 |
+
if (matcher.path === string)
|
| 35 |
+
return true;
|
| 36 |
+
if (matcher.recursive) {
|
| 37 |
+
const relative = sysPath.relative(matcher.path, string);
|
| 38 |
+
if (!relative) {
|
| 39 |
+
return false;
|
| 40 |
+
}
|
| 41 |
+
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
| 42 |
+
}
|
| 43 |
+
return false;
|
| 44 |
+
};
|
| 45 |
+
}
|
| 46 |
+
return () => false;
|
| 47 |
+
}
|
| 48 |
+
function normalizePath(path) {
|
| 49 |
+
if (typeof path !== 'string')
|
| 50 |
+
throw new Error('string expected');
|
| 51 |
+
path = sysPath.normalize(path);
|
| 52 |
+
path = path.replace(/\\/g, '/');
|
| 53 |
+
let prepend = false;
|
| 54 |
+
if (path.startsWith('//'))
|
| 55 |
+
prepend = true;
|
| 56 |
+
const DOUBLE_SLASH_RE = /\/\//;
|
| 57 |
+
while (path.match(DOUBLE_SLASH_RE))
|
| 58 |
+
path = path.replace(DOUBLE_SLASH_RE, '/');
|
| 59 |
+
if (prepend)
|
| 60 |
+
path = '/' + path;
|
| 61 |
+
return path;
|
| 62 |
+
}
|
| 63 |
+
function matchPatterns(patterns, testString, stats) {
|
| 64 |
+
const path = normalizePath(testString);
|
| 65 |
+
for (let index = 0; index < patterns.length; index++) {
|
| 66 |
+
const pattern = patterns[index];
|
| 67 |
+
if (pattern(path, stats)) {
|
| 68 |
+
return true;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
return false;
|
| 72 |
+
}
|
| 73 |
+
function anymatch(matchers, testString) {
|
| 74 |
+
if (matchers == null) {
|
| 75 |
+
throw new TypeError('anymatch: specify first argument');
|
| 76 |
+
}
|
| 77 |
+
// Early cache for matchers.
|
| 78 |
+
const matchersArray = arrify(matchers);
|
| 79 |
+
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
| 80 |
+
if (testString == null) {
|
| 81 |
+
return (testString, stats) => {
|
| 82 |
+
return matchPatterns(patterns, testString, stats);
|
| 83 |
+
};
|
| 84 |
+
}
|
| 85 |
+
return matchPatterns(patterns, testString);
|
| 86 |
+
}
|
| 87 |
+
const unifyPaths = (paths_) => {
|
| 88 |
+
const paths = arrify(paths_).flat();
|
| 89 |
+
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
| 90 |
+
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
| 91 |
+
}
|
| 92 |
+
return paths.map(normalizePathToUnix);
|
| 93 |
+
};
|
| 94 |
+
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
| 95 |
+
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
| 96 |
+
const toUnix = (string) => {
|
| 97 |
+
let str = string.replace(BACK_SLASH_RE, SLASH);
|
| 98 |
+
let prepend = false;
|
| 99 |
+
if (str.startsWith(SLASH_SLASH)) {
|
| 100 |
+
prepend = true;
|
| 101 |
+
}
|
| 102 |
+
while (str.match(DOUBLE_SLASH_RE)) {
|
| 103 |
+
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
| 104 |
+
}
|
| 105 |
+
if (prepend) {
|
| 106 |
+
str = SLASH + str;
|
| 107 |
+
}
|
| 108 |
+
return str;
|
| 109 |
+
};
|
| 110 |
+
// Our version of upath.normalize
|
| 111 |
+
// TODO: this is not equal to path-normalize module - investigate why
|
| 112 |
+
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
| 113 |
+
// TODO: refactor
|
| 114 |
+
const normalizeIgnored = (cwd = '') => (path) => {
|
| 115 |
+
if (typeof path === 'string') {
|
| 116 |
+
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
| 117 |
+
}
|
| 118 |
+
else {
|
| 119 |
+
return path;
|
| 120 |
+
}
|
| 121 |
+
};
|
| 122 |
+
const getAbsolutePath = (path, cwd) => {
|
| 123 |
+
if (sysPath.isAbsolute(path)) {
|
| 124 |
+
return path;
|
| 125 |
+
}
|
| 126 |
+
return sysPath.join(cwd, path);
|
| 127 |
+
};
|
| 128 |
+
const EMPTY_SET = Object.freeze(new Set());
|
| 129 |
+
/**
|
| 130 |
+
* Directory entry.
|
| 131 |
+
*/
|
| 132 |
+
class DirEntry {
|
| 133 |
+
constructor(dir, removeWatcher) {
|
| 134 |
+
this.path = dir;
|
| 135 |
+
this._removeWatcher = removeWatcher;
|
| 136 |
+
this.items = new Set();
|
| 137 |
+
}
|
| 138 |
+
add(item) {
|
| 139 |
+
const { items } = this;
|
| 140 |
+
if (!items)
|
| 141 |
+
return;
|
| 142 |
+
if (item !== ONE_DOT && item !== TWO_DOTS)
|
| 143 |
+
items.add(item);
|
| 144 |
+
}
|
| 145 |
+
async remove(item) {
|
| 146 |
+
const { items } = this;
|
| 147 |
+
if (!items)
|
| 148 |
+
return;
|
| 149 |
+
items.delete(item);
|
| 150 |
+
if (items.size > 0)
|
| 151 |
+
return;
|
| 152 |
+
const dir = this.path;
|
| 153 |
+
try {
|
| 154 |
+
await (0, promises_1.readdir)(dir);
|
| 155 |
+
}
|
| 156 |
+
catch (err) {
|
| 157 |
+
if (this._removeWatcher) {
|
| 158 |
+
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
has(item) {
|
| 163 |
+
const { items } = this;
|
| 164 |
+
if (!items)
|
| 165 |
+
return;
|
| 166 |
+
return items.has(item);
|
| 167 |
+
}
|
| 168 |
+
getChildren() {
|
| 169 |
+
const { items } = this;
|
| 170 |
+
if (!items)
|
| 171 |
+
return [];
|
| 172 |
+
return [...items.values()];
|
| 173 |
+
}
|
| 174 |
+
dispose() {
|
| 175 |
+
this.items.clear();
|
| 176 |
+
this.path = '';
|
| 177 |
+
this._removeWatcher = handler_js_1.EMPTY_FN;
|
| 178 |
+
this.items = EMPTY_SET;
|
| 179 |
+
Object.freeze(this);
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
const STAT_METHOD_F = 'stat';
|
| 183 |
+
const STAT_METHOD_L = 'lstat';
|
| 184 |
+
class WatchHelper {
|
| 185 |
+
constructor(path, follow, fsw) {
|
| 186 |
+
this.fsw = fsw;
|
| 187 |
+
const watchPath = path;
|
| 188 |
+
this.path = path = path.replace(REPLACER_RE, '');
|
| 189 |
+
this.watchPath = watchPath;
|
| 190 |
+
this.fullWatchPath = sysPath.resolve(watchPath);
|
| 191 |
+
this.dirParts = [];
|
| 192 |
+
this.dirParts.forEach((parts) => {
|
| 193 |
+
if (parts.length > 1)
|
| 194 |
+
parts.pop();
|
| 195 |
+
});
|
| 196 |
+
this.followSymlinks = follow;
|
| 197 |
+
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
| 198 |
+
}
|
| 199 |
+
entryPath(entry) {
|
| 200 |
+
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
| 201 |
+
}
|
| 202 |
+
filterPath(entry) {
|
| 203 |
+
const { stats } = entry;
|
| 204 |
+
if (stats && stats.isSymbolicLink())
|
| 205 |
+
return this.filterDir(entry);
|
| 206 |
+
const resolvedPath = this.entryPath(entry);
|
| 207 |
+
// TODO: what if stats is undefined? remove !
|
| 208 |
+
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
| 209 |
+
}
|
| 210 |
+
filterDir(entry) {
|
| 211 |
+
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
exports.WatchHelper = WatchHelper;
|
| 215 |
+
/**
|
| 216 |
+
* Watches files & directories for changes. Emitted events:
|
| 217 |
+
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
| 218 |
+
*
|
| 219 |
+
* new FSWatcher()
|
| 220 |
+
* .add(directories)
|
| 221 |
+
* .on('add', path => log('File', path, 'was added'))
|
| 222 |
+
*/
|
| 223 |
+
class FSWatcher extends events_1.EventEmitter {
|
| 224 |
+
// Not indenting methods for history sake; for now.
|
| 225 |
+
constructor(_opts = {}) {
|
| 226 |
+
super();
|
| 227 |
+
this.closed = false;
|
| 228 |
+
this._closers = new Map();
|
| 229 |
+
this._ignoredPaths = new Set();
|
| 230 |
+
this._throttled = new Map();
|
| 231 |
+
this._streams = new Set();
|
| 232 |
+
this._symlinkPaths = new Map();
|
| 233 |
+
this._watched = new Map();
|
| 234 |
+
this._pendingWrites = new Map();
|
| 235 |
+
this._pendingUnlinks = new Map();
|
| 236 |
+
this._readyCount = 0;
|
| 237 |
+
this._readyEmitted = false;
|
| 238 |
+
const awf = _opts.awaitWriteFinish;
|
| 239 |
+
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
| 240 |
+
const opts = {
|
| 241 |
+
// Defaults
|
| 242 |
+
persistent: true,
|
| 243 |
+
ignoreInitial: false,
|
| 244 |
+
ignorePermissionErrors: false,
|
| 245 |
+
interval: 100,
|
| 246 |
+
binaryInterval: 300,
|
| 247 |
+
followSymlinks: true,
|
| 248 |
+
usePolling: false,
|
| 249 |
+
// useAsync: false,
|
| 250 |
+
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
| 251 |
+
..._opts,
|
| 252 |
+
// Change format
|
| 253 |
+
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
| 254 |
+
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
| 255 |
+
};
|
| 256 |
+
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
| 257 |
+
if (handler_js_1.isIBMi)
|
| 258 |
+
opts.usePolling = true;
|
| 259 |
+
// Editor atomic write normalization enabled by default with fs.watch
|
| 260 |
+
if (opts.atomic === undefined)
|
| 261 |
+
opts.atomic = !opts.usePolling;
|
| 262 |
+
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
| 263 |
+
// Global override. Useful for developers, who need to force polling for all
|
| 264 |
+
// instances of chokidar, regardless of usage / dependency depth
|
| 265 |
+
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
| 266 |
+
if (envPoll !== undefined) {
|
| 267 |
+
const envLower = envPoll.toLowerCase();
|
| 268 |
+
if (envLower === 'false' || envLower === '0')
|
| 269 |
+
opts.usePolling = false;
|
| 270 |
+
else if (envLower === 'true' || envLower === '1')
|
| 271 |
+
opts.usePolling = true;
|
| 272 |
+
else
|
| 273 |
+
opts.usePolling = !!envLower;
|
| 274 |
+
}
|
| 275 |
+
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
| 276 |
+
if (envInterval)
|
| 277 |
+
opts.interval = Number.parseInt(envInterval, 10);
|
| 278 |
+
// This is done to emit ready only once, but each 'add' will increase that?
|
| 279 |
+
let readyCalls = 0;
|
| 280 |
+
this._emitReady = () => {
|
| 281 |
+
readyCalls++;
|
| 282 |
+
if (readyCalls >= this._readyCount) {
|
| 283 |
+
this._emitReady = handler_js_1.EMPTY_FN;
|
| 284 |
+
this._readyEmitted = true;
|
| 285 |
+
// use process.nextTick to allow time for listener to be bound
|
| 286 |
+
process.nextTick(() => this.emit(handler_js_1.EVENTS.READY));
|
| 287 |
+
}
|
| 288 |
+
};
|
| 289 |
+
this._emitRaw = (...args) => this.emit(handler_js_1.EVENTS.RAW, ...args);
|
| 290 |
+
this._boundRemove = this._remove.bind(this);
|
| 291 |
+
this.options = opts;
|
| 292 |
+
this._nodeFsHandler = new handler_js_1.NodeFsHandler(this);
|
| 293 |
+
// You’re frozen when your heart’s not open.
|
| 294 |
+
Object.freeze(opts);
|
| 295 |
+
}
|
| 296 |
+
_addIgnoredPath(matcher) {
|
| 297 |
+
if (isMatcherObject(matcher)) {
|
| 298 |
+
// return early if we already have a deeply equal matcher object
|
| 299 |
+
for (const ignored of this._ignoredPaths) {
|
| 300 |
+
if (isMatcherObject(ignored) &&
|
| 301 |
+
ignored.path === matcher.path &&
|
| 302 |
+
ignored.recursive === matcher.recursive) {
|
| 303 |
+
return;
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
this._ignoredPaths.add(matcher);
|
| 308 |
+
}
|
| 309 |
+
_removeIgnoredPath(matcher) {
|
| 310 |
+
this._ignoredPaths.delete(matcher);
|
| 311 |
+
// now find any matcher objects with the matcher as path
|
| 312 |
+
if (typeof matcher === 'string') {
|
| 313 |
+
for (const ignored of this._ignoredPaths) {
|
| 314 |
+
// TODO (43081j): make this more efficient.
|
| 315 |
+
// probably just make a `this._ignoredDirectories` or some
|
| 316 |
+
// such thing.
|
| 317 |
+
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
| 318 |
+
this._ignoredPaths.delete(ignored);
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
// Public methods
|
| 324 |
+
/**
|
| 325 |
+
* Adds paths to be watched on an existing FSWatcher instance.
|
| 326 |
+
* @param paths_ file or file list. Other arguments are unused
|
| 327 |
+
*/
|
| 328 |
+
add(paths_, _origAdd, _internal) {
|
| 329 |
+
const { cwd } = this.options;
|
| 330 |
+
this.closed = false;
|
| 331 |
+
this._closePromise = undefined;
|
| 332 |
+
let paths = unifyPaths(paths_);
|
| 333 |
+
if (cwd) {
|
| 334 |
+
paths = paths.map((path) => {
|
| 335 |
+
const absPath = getAbsolutePath(path, cwd);
|
| 336 |
+
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
| 337 |
+
return absPath;
|
| 338 |
+
});
|
| 339 |
+
}
|
| 340 |
+
paths.forEach((path) => {
|
| 341 |
+
this._removeIgnoredPath(path);
|
| 342 |
+
});
|
| 343 |
+
this._userIgnored = undefined;
|
| 344 |
+
if (!this._readyCount)
|
| 345 |
+
this._readyCount = 0;
|
| 346 |
+
this._readyCount += paths.length;
|
| 347 |
+
Promise.all(paths.map(async (path) => {
|
| 348 |
+
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
| 349 |
+
if (res)
|
| 350 |
+
this._emitReady();
|
| 351 |
+
return res;
|
| 352 |
+
})).then((results) => {
|
| 353 |
+
if (this.closed)
|
| 354 |
+
return;
|
| 355 |
+
results.forEach((item) => {
|
| 356 |
+
if (item)
|
| 357 |
+
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
| 358 |
+
});
|
| 359 |
+
});
|
| 360 |
+
return this;
|
| 361 |
+
}
|
| 362 |
+
/**
|
| 363 |
+
* Close watchers or start ignoring events from specified paths.
|
| 364 |
+
*/
|
| 365 |
+
unwatch(paths_) {
|
| 366 |
+
if (this.closed)
|
| 367 |
+
return this;
|
| 368 |
+
const paths = unifyPaths(paths_);
|
| 369 |
+
const { cwd } = this.options;
|
| 370 |
+
paths.forEach((path) => {
|
| 371 |
+
// convert to absolute path unless relative path already matches
|
| 372 |
+
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
| 373 |
+
if (cwd)
|
| 374 |
+
path = sysPath.join(cwd, path);
|
| 375 |
+
path = sysPath.resolve(path);
|
| 376 |
+
}
|
| 377 |
+
this._closePath(path);
|
| 378 |
+
this._addIgnoredPath(path);
|
| 379 |
+
if (this._watched.has(path)) {
|
| 380 |
+
this._addIgnoredPath({
|
| 381 |
+
path,
|
| 382 |
+
recursive: true,
|
| 383 |
+
});
|
| 384 |
+
}
|
| 385 |
+
// reset the cached userIgnored anymatch fn
|
| 386 |
+
// to make ignoredPaths changes effective
|
| 387 |
+
this._userIgnored = undefined;
|
| 388 |
+
});
|
| 389 |
+
return this;
|
| 390 |
+
}
|
| 391 |
+
/**
|
| 392 |
+
* Close watchers and remove all listeners from watched paths.
|
| 393 |
+
*/
|
| 394 |
+
close() {
|
| 395 |
+
if (this._closePromise) {
|
| 396 |
+
return this._closePromise;
|
| 397 |
+
}
|
| 398 |
+
this.closed = true;
|
| 399 |
+
// Memory management.
|
| 400 |
+
this.removeAllListeners();
|
| 401 |
+
const closers = [];
|
| 402 |
+
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
| 403 |
+
const promise = closer();
|
| 404 |
+
if (promise instanceof Promise)
|
| 405 |
+
closers.push(promise);
|
| 406 |
+
}));
|
| 407 |
+
this._streams.forEach((stream) => stream.destroy());
|
| 408 |
+
this._userIgnored = undefined;
|
| 409 |
+
this._readyCount = 0;
|
| 410 |
+
this._readyEmitted = false;
|
| 411 |
+
this._watched.forEach((dirent) => dirent.dispose());
|
| 412 |
+
this._closers.clear();
|
| 413 |
+
this._watched.clear();
|
| 414 |
+
this._streams.clear();
|
| 415 |
+
this._symlinkPaths.clear();
|
| 416 |
+
this._throttled.clear();
|
| 417 |
+
this._closePromise = closers.length
|
| 418 |
+
? Promise.all(closers).then(() => undefined)
|
| 419 |
+
: Promise.resolve();
|
| 420 |
+
return this._closePromise;
|
| 421 |
+
}
|
| 422 |
+
/**
|
| 423 |
+
* Expose list of watched paths
|
| 424 |
+
* @returns for chaining
|
| 425 |
+
*/
|
| 426 |
+
getWatched() {
|
| 427 |
+
const watchList = {};
|
| 428 |
+
this._watched.forEach((entry, dir) => {
|
| 429 |
+
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
| 430 |
+
const index = key || ONE_DOT;
|
| 431 |
+
watchList[index] = entry.getChildren().sort();
|
| 432 |
+
});
|
| 433 |
+
return watchList;
|
| 434 |
+
}
|
| 435 |
+
emitWithAll(event, args) {
|
| 436 |
+
this.emit(event, ...args);
|
| 437 |
+
if (event !== handler_js_1.EVENTS.ERROR)
|
| 438 |
+
this.emit(handler_js_1.EVENTS.ALL, event, ...args);
|
| 439 |
+
}
|
| 440 |
+
// Common helpers
|
| 441 |
+
// --------------
|
| 442 |
+
/**
|
| 443 |
+
* Normalize and emit events.
|
| 444 |
+
* Calling _emit DOES NOT MEAN emit() would be called!
|
| 445 |
+
* @param event Type of event
|
| 446 |
+
* @param path File or directory path
|
| 447 |
+
* @param stats arguments to be passed with event
|
| 448 |
+
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 449 |
+
*/
|
| 450 |
+
async _emit(event, path, stats) {
|
| 451 |
+
if (this.closed)
|
| 452 |
+
return;
|
| 453 |
+
const opts = this.options;
|
| 454 |
+
if (handler_js_1.isWindows)
|
| 455 |
+
path = sysPath.normalize(path);
|
| 456 |
+
if (opts.cwd)
|
| 457 |
+
path = sysPath.relative(opts.cwd, path);
|
| 458 |
+
const args = [path];
|
| 459 |
+
if (stats != null)
|
| 460 |
+
args.push(stats);
|
| 461 |
+
const awf = opts.awaitWriteFinish;
|
| 462 |
+
let pw;
|
| 463 |
+
if (awf && (pw = this._pendingWrites.get(path))) {
|
| 464 |
+
pw.lastChange = new Date();
|
| 465 |
+
return this;
|
| 466 |
+
}
|
| 467 |
+
if (opts.atomic) {
|
| 468 |
+
if (event === handler_js_1.EVENTS.UNLINK) {
|
| 469 |
+
this._pendingUnlinks.set(path, [event, ...args]);
|
| 470 |
+
setTimeout(() => {
|
| 471 |
+
this._pendingUnlinks.forEach((entry, path) => {
|
| 472 |
+
this.emit(...entry);
|
| 473 |
+
this.emit(handler_js_1.EVENTS.ALL, ...entry);
|
| 474 |
+
this._pendingUnlinks.delete(path);
|
| 475 |
+
});
|
| 476 |
+
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
| 477 |
+
return this;
|
| 478 |
+
}
|
| 479 |
+
if (event === handler_js_1.EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
| 480 |
+
event = handler_js_1.EVENTS.CHANGE;
|
| 481 |
+
this._pendingUnlinks.delete(path);
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
if (awf && (event === handler_js_1.EVENTS.ADD || event === handler_js_1.EVENTS.CHANGE) && this._readyEmitted) {
|
| 485 |
+
const awfEmit = (err, stats) => {
|
| 486 |
+
if (err) {
|
| 487 |
+
event = handler_js_1.EVENTS.ERROR;
|
| 488 |
+
args[0] = err;
|
| 489 |
+
this.emitWithAll(event, args);
|
| 490 |
+
}
|
| 491 |
+
else if (stats) {
|
| 492 |
+
// if stats doesn't exist the file must have been deleted
|
| 493 |
+
if (args.length > 1) {
|
| 494 |
+
args[1] = stats;
|
| 495 |
+
}
|
| 496 |
+
else {
|
| 497 |
+
args.push(stats);
|
| 498 |
+
}
|
| 499 |
+
this.emitWithAll(event, args);
|
| 500 |
+
}
|
| 501 |
+
};
|
| 502 |
+
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
| 503 |
+
return this;
|
| 504 |
+
}
|
| 505 |
+
if (event === handler_js_1.EVENTS.CHANGE) {
|
| 506 |
+
const isThrottled = !this._throttle(handler_js_1.EVENTS.CHANGE, path, 50);
|
| 507 |
+
if (isThrottled)
|
| 508 |
+
return this;
|
| 509 |
+
}
|
| 510 |
+
if (opts.alwaysStat &&
|
| 511 |
+
stats === undefined &&
|
| 512 |
+
(event === handler_js_1.EVENTS.ADD || event === handler_js_1.EVENTS.ADD_DIR || event === handler_js_1.EVENTS.CHANGE)) {
|
| 513 |
+
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
| 514 |
+
let stats;
|
| 515 |
+
try {
|
| 516 |
+
stats = await (0, promises_1.stat)(fullPath);
|
| 517 |
+
}
|
| 518 |
+
catch (err) {
|
| 519 |
+
// do nothing
|
| 520 |
+
}
|
| 521 |
+
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
| 522 |
+
if (!stats || this.closed)
|
| 523 |
+
return;
|
| 524 |
+
args.push(stats);
|
| 525 |
+
}
|
| 526 |
+
this.emitWithAll(event, args);
|
| 527 |
+
return this;
|
| 528 |
+
}
|
| 529 |
+
/**
|
| 530 |
+
* Common handler for errors
|
| 531 |
+
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
| 532 |
+
*/
|
| 533 |
+
_handleError(error) {
|
| 534 |
+
const code = error && error.code;
|
| 535 |
+
if (error &&
|
| 536 |
+
code !== 'ENOENT' &&
|
| 537 |
+
code !== 'ENOTDIR' &&
|
| 538 |
+
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
| 539 |
+
this.emit(handler_js_1.EVENTS.ERROR, error);
|
| 540 |
+
}
|
| 541 |
+
return error || this.closed;
|
| 542 |
+
}
|
| 543 |
+
/**
|
| 544 |
+
* Helper utility for throttling
|
| 545 |
+
* @param actionType type being throttled
|
| 546 |
+
* @param path being acted upon
|
| 547 |
+
* @param timeout duration of time to suppress duplicate actions
|
| 548 |
+
* @returns tracking object or false if action should be suppressed
|
| 549 |
+
*/
|
| 550 |
+
_throttle(actionType, path, timeout) {
|
| 551 |
+
if (!this._throttled.has(actionType)) {
|
| 552 |
+
this._throttled.set(actionType, new Map());
|
| 553 |
+
}
|
| 554 |
+
const action = this._throttled.get(actionType);
|
| 555 |
+
if (!action)
|
| 556 |
+
throw new Error('invalid throttle');
|
| 557 |
+
const actionPath = action.get(path);
|
| 558 |
+
if (actionPath) {
|
| 559 |
+
actionPath.count++;
|
| 560 |
+
return false;
|
| 561 |
+
}
|
| 562 |
+
// eslint-disable-next-line prefer-const
|
| 563 |
+
let timeoutObject;
|
| 564 |
+
const clear = () => {
|
| 565 |
+
const item = action.get(path);
|
| 566 |
+
const count = item ? item.count : 0;
|
| 567 |
+
action.delete(path);
|
| 568 |
+
clearTimeout(timeoutObject);
|
| 569 |
+
if (item)
|
| 570 |
+
clearTimeout(item.timeoutObject);
|
| 571 |
+
return count;
|
| 572 |
+
};
|
| 573 |
+
timeoutObject = setTimeout(clear, timeout);
|
| 574 |
+
const thr = { timeoutObject, clear, count: 0 };
|
| 575 |
+
action.set(path, thr);
|
| 576 |
+
return thr;
|
| 577 |
+
}
|
| 578 |
+
_incrReadyCount() {
|
| 579 |
+
return this._readyCount++;
|
| 580 |
+
}
|
| 581 |
+
/**
|
| 582 |
+
* Awaits write operation to finish.
|
| 583 |
+
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
| 584 |
+
* @param path being acted upon
|
| 585 |
+
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
| 586 |
+
* @param event
|
| 587 |
+
* @param awfEmit Callback to be called when ready for event to be emitted.
|
| 588 |
+
*/
|
| 589 |
+
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
| 590 |
+
const awf = this.options.awaitWriteFinish;
|
| 591 |
+
if (typeof awf !== 'object')
|
| 592 |
+
return;
|
| 593 |
+
const pollInterval = awf.pollInterval;
|
| 594 |
+
let timeoutHandler;
|
| 595 |
+
let fullPath = path;
|
| 596 |
+
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
| 597 |
+
fullPath = sysPath.join(this.options.cwd, path);
|
| 598 |
+
}
|
| 599 |
+
const now = new Date();
|
| 600 |
+
const writes = this._pendingWrites;
|
| 601 |
+
function awaitWriteFinishFn(prevStat) {
|
| 602 |
+
(0, fs_1.stat)(fullPath, (err, curStat) => {
|
| 603 |
+
if (err || !writes.has(path)) {
|
| 604 |
+
if (err && err.code !== 'ENOENT')
|
| 605 |
+
awfEmit(err);
|
| 606 |
+
return;
|
| 607 |
+
}
|
| 608 |
+
const now = Number(new Date());
|
| 609 |
+
if (prevStat && curStat.size !== prevStat.size) {
|
| 610 |
+
writes.get(path).lastChange = now;
|
| 611 |
+
}
|
| 612 |
+
const pw = writes.get(path);
|
| 613 |
+
const df = now - pw.lastChange;
|
| 614 |
+
if (df >= threshold) {
|
| 615 |
+
writes.delete(path);
|
| 616 |
+
awfEmit(undefined, curStat);
|
| 617 |
+
}
|
| 618 |
+
else {
|
| 619 |
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
| 620 |
+
}
|
| 621 |
+
});
|
| 622 |
+
}
|
| 623 |
+
if (!writes.has(path)) {
|
| 624 |
+
writes.set(path, {
|
| 625 |
+
lastChange: now,
|
| 626 |
+
cancelWait: () => {
|
| 627 |
+
writes.delete(path);
|
| 628 |
+
clearTimeout(timeoutHandler);
|
| 629 |
+
return event;
|
| 630 |
+
},
|
| 631 |
+
});
|
| 632 |
+
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
| 633 |
+
}
|
| 634 |
+
}
|
| 635 |
+
/**
|
| 636 |
+
* Determines whether user has asked to ignore this path.
|
| 637 |
+
*/
|
| 638 |
+
_isIgnored(path, stats) {
|
| 639 |
+
if (this.options.atomic && DOT_RE.test(path))
|
| 640 |
+
return true;
|
| 641 |
+
if (!this._userIgnored) {
|
| 642 |
+
const { cwd } = this.options;
|
| 643 |
+
const ign = this.options.ignored;
|
| 644 |
+
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
| 645 |
+
const ignoredPaths = [...this._ignoredPaths];
|
| 646 |
+
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
| 647 |
+
this._userIgnored = anymatch(list, undefined);
|
| 648 |
+
}
|
| 649 |
+
return this._userIgnored(path, stats);
|
| 650 |
+
}
|
| 651 |
+
_isntIgnored(path, stat) {
|
| 652 |
+
return !this._isIgnored(path, stat);
|
| 653 |
+
}
|
| 654 |
+
/**
|
| 655 |
+
* Provides a set of common helpers and properties relating to symlink handling.
|
| 656 |
+
* @param path file or directory pattern being watched
|
| 657 |
+
*/
|
| 658 |
+
_getWatchHelpers(path) {
|
| 659 |
+
return new WatchHelper(path, this.options.followSymlinks, this);
|
| 660 |
+
}
|
| 661 |
+
// Directory helpers
|
| 662 |
+
// -----------------
|
| 663 |
+
/**
|
| 664 |
+
* Provides directory tracking objects
|
| 665 |
+
* @param directory path of the directory
|
| 666 |
+
*/
|
| 667 |
+
_getWatchedDir(directory) {
|
| 668 |
+
const dir = sysPath.resolve(directory);
|
| 669 |
+
if (!this._watched.has(dir))
|
| 670 |
+
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
| 671 |
+
return this._watched.get(dir);
|
| 672 |
+
}
|
| 673 |
+
// File helpers
|
| 674 |
+
// ------------
|
| 675 |
+
/**
|
| 676 |
+
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
| 677 |
+
*/
|
| 678 |
+
_hasReadPermissions(stats) {
|
| 679 |
+
if (this.options.ignorePermissionErrors)
|
| 680 |
+
return true;
|
| 681 |
+
return Boolean(Number(stats.mode) & 0o400);
|
| 682 |
+
}
|
| 683 |
+
/**
|
| 684 |
+
* Handles emitting unlink events for
|
| 685 |
+
* files and directories, and via recursion, for
|
| 686 |
+
* files and directories within directories that are unlinked
|
| 687 |
+
* @param directory within which the following item is located
|
| 688 |
+
* @param item base path of item/directory
|
| 689 |
+
*/
|
| 690 |
+
_remove(directory, item, isDirectory) {
|
| 691 |
+
// if what is being deleted is a directory, get that directory's paths
|
| 692 |
+
// for recursive deleting and cleaning of watched object
|
| 693 |
+
// if it is not a directory, nestedDirectoryChildren will be empty array
|
| 694 |
+
const path = sysPath.join(directory, item);
|
| 695 |
+
const fullPath = sysPath.resolve(path);
|
| 696 |
+
isDirectory =
|
| 697 |
+
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
| 698 |
+
// prevent duplicate handling in case of arriving here nearly simultaneously
|
| 699 |
+
// via multiple paths (such as _handleFile and _handleDir)
|
| 700 |
+
if (!this._throttle('remove', path, 100))
|
| 701 |
+
return;
|
| 702 |
+
// if the only watched file is removed, watch for its return
|
| 703 |
+
if (!isDirectory && this._watched.size === 1) {
|
| 704 |
+
this.add(directory, item, true);
|
| 705 |
+
}
|
| 706 |
+
// This will create a new entry in the watched object in either case
|
| 707 |
+
// so we got to do the directory check beforehand
|
| 708 |
+
const wp = this._getWatchedDir(path);
|
| 709 |
+
const nestedDirectoryChildren = wp.getChildren();
|
| 710 |
+
// Recursively remove children directories / files.
|
| 711 |
+
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
| 712 |
+
// Check if item was on the watched list and remove it
|
| 713 |
+
const parent = this._getWatchedDir(directory);
|
| 714 |
+
const wasTracked = parent.has(item);
|
| 715 |
+
parent.remove(item);
|
| 716 |
+
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
| 717 |
+
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
| 718 |
+
// but never removed from the map in case the path was deleted.
|
| 719 |
+
// This leads to an incorrect state if the path was recreated:
|
| 720 |
+
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
| 721 |
+
if (this._symlinkPaths.has(fullPath)) {
|
| 722 |
+
this._symlinkPaths.delete(fullPath);
|
| 723 |
+
}
|
| 724 |
+
// If we wait for this file to be fully written, cancel the wait.
|
| 725 |
+
let relPath = path;
|
| 726 |
+
if (this.options.cwd)
|
| 727 |
+
relPath = sysPath.relative(this.options.cwd, path);
|
| 728 |
+
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
| 729 |
+
const event = this._pendingWrites.get(relPath).cancelWait();
|
| 730 |
+
if (event === handler_js_1.EVENTS.ADD)
|
| 731 |
+
return;
|
| 732 |
+
}
|
| 733 |
+
// The Entry will either be a directory that just got removed
|
| 734 |
+
// or a bogus entry to a file, in either case we have to remove it
|
| 735 |
+
this._watched.delete(path);
|
| 736 |
+
this._watched.delete(fullPath);
|
| 737 |
+
const eventName = isDirectory ? handler_js_1.EVENTS.UNLINK_DIR : handler_js_1.EVENTS.UNLINK;
|
| 738 |
+
if (wasTracked && !this._isIgnored(path))
|
| 739 |
+
this._emit(eventName, path);
|
| 740 |
+
// Avoid conflicts if we later create another file with the same name
|
| 741 |
+
this._closePath(path);
|
| 742 |
+
}
|
| 743 |
+
/**
|
| 744 |
+
* Closes all watchers for a path
|
| 745 |
+
*/
|
| 746 |
+
_closePath(path) {
|
| 747 |
+
this._closeFile(path);
|
| 748 |
+
const dir = sysPath.dirname(path);
|
| 749 |
+
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
| 750 |
+
}
|
| 751 |
+
/**
|
| 752 |
+
* Closes only file-specific watchers
|
| 753 |
+
*/
|
| 754 |
+
_closeFile(path) {
|
| 755 |
+
const closers = this._closers.get(path);
|
| 756 |
+
if (!closers)
|
| 757 |
+
return;
|
| 758 |
+
closers.forEach((closer) => closer());
|
| 759 |
+
this._closers.delete(path);
|
| 760 |
+
}
|
| 761 |
+
_addPathCloser(path, closer) {
|
| 762 |
+
if (!closer)
|
| 763 |
+
return;
|
| 764 |
+
let list = this._closers.get(path);
|
| 765 |
+
if (!list) {
|
| 766 |
+
list = [];
|
| 767 |
+
this._closers.set(path, list);
|
| 768 |
+
}
|
| 769 |
+
list.push(closer);
|
| 770 |
+
}
|
| 771 |
+
_readdirp(root, opts) {
|
| 772 |
+
if (this.closed)
|
| 773 |
+
return;
|
| 774 |
+
const options = { type: handler_js_1.EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
| 775 |
+
let stream = (0, readdirp_1.readdirp)(root, options);
|
| 776 |
+
this._streams.add(stream);
|
| 777 |
+
stream.once(handler_js_1.STR_CLOSE, () => {
|
| 778 |
+
stream = undefined;
|
| 779 |
+
});
|
| 780 |
+
stream.once(handler_js_1.STR_END, () => {
|
| 781 |
+
if (stream) {
|
| 782 |
+
this._streams.delete(stream);
|
| 783 |
+
stream = undefined;
|
| 784 |
+
}
|
| 785 |
+
});
|
| 786 |
+
return stream;
|
| 787 |
+
}
|
| 788 |
+
}
|
| 789 |
+
exports.FSWatcher = FSWatcher;
|
| 790 |
+
/**
|
| 791 |
+
* Instantiates watcher with paths to be tracked.
|
| 792 |
+
* @param paths file / directory paths
|
| 793 |
+
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
| 794 |
+
* @returns an instance of FSWatcher for chaining.
|
| 795 |
+
* @example
|
| 796 |
+
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
| 797 |
+
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
| 798 |
+
*/
|
| 799 |
+
function watch(paths, options = {}) {
|
| 800 |
+
const watcher = new FSWatcher(options);
|
| 801 |
+
watcher.add(paths);
|
| 802 |
+
return watcher;
|
| 803 |
+
}
|
| 804 |
+
exports.default = { watch, FSWatcher };
|
tools/ui/node_modules/svelte-check/node_modules/chokidar/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "chokidar",
|
| 3 |
+
"description": "Minimal and efficient cross-platform file watching library",
|
| 4 |
+
"version": "4.0.3",
|
| 5 |
+
"homepage": "https://github.com/paulmillr/chokidar",
|
| 6 |
+
"author": "Paul Miller (https://paulmillr.com)",
|
| 7 |
+
"files": [
|
| 8 |
+
"index.js",
|
| 9 |
+
"index.d.ts",
|
| 10 |
+
"handler.js",
|
| 11 |
+
"handler.d.ts",
|
| 12 |
+
"esm"
|
| 13 |
+
],
|
| 14 |
+
"main": "./index.js",
|
| 15 |
+
"module": "./esm/index.js",
|
| 16 |
+
"types": "./index.d.ts",
|
| 17 |
+
"exports": {
|
| 18 |
+
".": {
|
| 19 |
+
"import": "./esm/index.js",
|
| 20 |
+
"require": "./index.js"
|
| 21 |
+
},
|
| 22 |
+
"./handler.js": {
|
| 23 |
+
"import": "./esm/handler.js",
|
| 24 |
+
"require": "./handler.js"
|
| 25 |
+
}
|
| 26 |
+
},
|
| 27 |
+
"dependencies": {
|
| 28 |
+
"readdirp": "^4.0.1"
|
| 29 |
+
},
|
| 30 |
+
"devDependencies": {
|
| 31 |
+
"@paulmillr/jsbt": "0.2.1",
|
| 32 |
+
"@types/node": "20.14.8",
|
| 33 |
+
"chai": "4.3.4",
|
| 34 |
+
"prettier": "3.1.1",
|
| 35 |
+
"rimraf": "5.0.5",
|
| 36 |
+
"sinon": "12.0.1",
|
| 37 |
+
"sinon-chai": "3.7.0",
|
| 38 |
+
"typescript": "5.5.2",
|
| 39 |
+
"upath": "2.0.1"
|
| 40 |
+
},
|
| 41 |
+
"sideEffects": false,
|
| 42 |
+
"engines": {
|
| 43 |
+
"node": ">= 14.16.0"
|
| 44 |
+
},
|
| 45 |
+
"repository": {
|
| 46 |
+
"type": "git",
|
| 47 |
+
"url": "git+https://github.com/paulmillr/chokidar.git"
|
| 48 |
+
},
|
| 49 |
+
"bugs": {
|
| 50 |
+
"url": "https://github.com/paulmillr/chokidar/issues"
|
| 51 |
+
},
|
| 52 |
+
"license": "MIT",
|
| 53 |
+
"scripts": {
|
| 54 |
+
"build": "tsc && tsc -p tsconfig.esm.json",
|
| 55 |
+
"lint": "prettier --check src",
|
| 56 |
+
"format": "prettier --write src",
|
| 57 |
+
"test": "node --test"
|
| 58 |
+
},
|
| 59 |
+
"keywords": [
|
| 60 |
+
"fs",
|
| 61 |
+
"watch",
|
| 62 |
+
"watchFile",
|
| 63 |
+
"watcher",
|
| 64 |
+
"watching",
|
| 65 |
+
"file",
|
| 66 |
+
"fsevents"
|
| 67 |
+
],
|
| 68 |
+
"funding": "https://paulmillr.com/funding/"
|
| 69 |
+
}
|
tools/ui/node_modules/svelte-check/node_modules/readdirp/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com)
|
| 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.
|
tools/ui/node_modules/svelte-check/node_modules/readdirp/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# readdirp [](https://github.com/paulmillr/readdirp)
|
| 2 |
+
|
| 3 |
+
Recursive version of fs.readdir. Exposes a **stream API** (with small RAM & CPU footprint) and a **promise API**.
|
| 4 |
+
|
| 5 |
+
```sh
|
| 6 |
+
npm install readdirp
|
| 7 |
+
jsr add jsr:@paulmillr/readdirp
|
| 8 |
+
```
|
| 9 |
+
|
| 10 |
+
```javascript
|
| 11 |
+
// Use streams to achieve small RAM & CPU footprint.
|
| 12 |
+
// 1) Streams example with for-await.
|
| 13 |
+
import readdirp from 'readdirp';
|
| 14 |
+
for await (const entry of readdirp('.')) {
|
| 15 |
+
const {path} = entry;
|
| 16 |
+
console.log(`${JSON.stringify({path})}`);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
// 2) Streams example, non for-await.
|
| 20 |
+
// Print out all JS files along with their size within the current folder & subfolders.
|
| 21 |
+
import readdirp from 'readdirp';
|
| 22 |
+
readdirp('.', {alwaysStat: true, fileFilter: (f) => f.basename.endsWith('.js')})
|
| 23 |
+
.on('data', (entry) => {
|
| 24 |
+
const {path, stats: {size}} = entry;
|
| 25 |
+
console.log(`${JSON.stringify({path, size})}`);
|
| 26 |
+
})
|
| 27 |
+
// Optionally call stream.destroy() in `warn()` in order to abort and cause 'close' to be emitted
|
| 28 |
+
.on('warn', error => console.error('non-fatal error', error))
|
| 29 |
+
.on('error', error => console.error('fatal error', error))
|
| 30 |
+
.on('end', () => console.log('done'));
|
| 31 |
+
|
| 32 |
+
// 3) Promise example. More RAM and CPU than streams / for-await.
|
| 33 |
+
import { readdirpPromise } from 'readdirp';
|
| 34 |
+
const files = await readdirpPromise('.');
|
| 35 |
+
console.log(files.map(file => file.path));
|
| 36 |
+
|
| 37 |
+
// Other options.
|
| 38 |
+
import readdirp from 'readdirp';
|
| 39 |
+
readdirp('test', {
|
| 40 |
+
fileFilter: (f) => f.basename.endsWith('.js'),
|
| 41 |
+
directoryFilter: (d) => d.basename !== '.git',
|
| 42 |
+
// directoryFilter: (di) => di.basename.length === 9
|
| 43 |
+
type: 'files_directories',
|
| 44 |
+
depth: 1
|
| 45 |
+
});
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## API
|
| 49 |
+
|
| 50 |
+
`const stream = readdirp(root[, options])` — **Stream API**
|
| 51 |
+
|
| 52 |
+
- Reads given root recursively and returns a `stream` of [entry infos](#entryinfo)
|
| 53 |
+
- Optionally can be used like `for await (const entry of stream)` with node.js 10+ (`asyncIterator`).
|
| 54 |
+
- `on('data', (entry) => {})` [entry info](#entryinfo) for every file / dir.
|
| 55 |
+
- `on('warn', (error) => {})` non-fatal `Error` that prevents a file / dir from being processed. Example: inaccessible to the user.
|
| 56 |
+
- `on('error', (error) => {})` fatal `Error` which also ends the stream. Example: illegal options where passed.
|
| 57 |
+
- `on('end')` — we are done. Called when all entries were found and no more will be emitted.
|
| 58 |
+
- `on('close')` — stream is destroyed via `stream.destroy()`.
|
| 59 |
+
Could be useful if you want to manually abort even on a non fatal error.
|
| 60 |
+
At that point the stream is no longer `readable` and no more entries, warning or errors are emitted
|
| 61 |
+
- To learn more about streams, consult the very detailed [nodejs streams documentation](https://nodejs.org/api/stream.html)
|
| 62 |
+
or the [stream-handbook](https://github.com/substack/stream-handbook)
|
| 63 |
+
|
| 64 |
+
`const entries = await readdirp.promise(root[, options])` — **Promise API**. Returns a list of [entry infos](#entryinfo).
|
| 65 |
+
|
| 66 |
+
First argument is awalys `root`, path in which to start reading and recursing into subdirectories.
|
| 67 |
+
|
| 68 |
+
### options
|
| 69 |
+
|
| 70 |
+
- `fileFilter`: filter to include or exclude files
|
| 71 |
+
- **Function**: a function that takes an entry info as a parameter and returns true to include or false to exclude the entry
|
| 72 |
+
- `directoryFilter`: filter to include/exclude directories found and to recurse into. Directories that do not pass a filter will not be recursed into.
|
| 73 |
+
- `depth: 5`: depth at which to stop recursing even if more subdirectories are found
|
| 74 |
+
- `type: 'files'`: determines if data events on the stream should be emitted for `'files'` (default), `'directories'`, `'files_directories'`, or `'all'`. Setting to `'all'` will also include entries for other types of file descriptors like character devices, unix sockets and named pipes.
|
| 75 |
+
- `alwaysStat: false`: always return `stats` property for every file. Default is `false`, readdirp will return `Dirent` entries. Setting it to `true` can double readdir execution time - use it only when you need file `size`, `mtime` etc. Cannot be enabled on node <10.10.0.
|
| 76 |
+
- `lstat: false`: include symlink entries in the stream along with files. When `true`, `fs.lstat` would be used instead of `fs.stat`
|
| 77 |
+
|
| 78 |
+
### `EntryInfo`
|
| 79 |
+
|
| 80 |
+
Has the following properties:
|
| 81 |
+
|
| 82 |
+
- `path: 'assets/javascripts/react.js'`: path to the file/directory (relative to given root)
|
| 83 |
+
- `fullPath: '/Users/dev/projects/app/assets/javascripts/react.js'`: full path to the file/directory found
|
| 84 |
+
- `basename: 'react.js'`: name of the file/directory
|
| 85 |
+
- `dirent: fs.Dirent`: built-in [dir entry object](https://nodejs.org/api/fs.html#fs_class_fs_dirent) - only with `alwaysStat: false`
|
| 86 |
+
- `stats: fs.Stats`: built in [stat object](https://nodejs.org/api/fs.html#fs_class_fs_stats) - only with `alwaysStat: true`
|
| 87 |
+
|
| 88 |
+
## Changelog
|
| 89 |
+
|
| 90 |
+
- 4.0 (Aug 25, 2024) rewritten in typescript, producing hybrid common.js / esm module.
|
| 91 |
+
- Remove glob support and all dependencies
|
| 92 |
+
- Make sure you're using `let {readdirp} = require('readdirp')` in common.js
|
| 93 |
+
- 3.5 (Oct 13, 2020) disallows recursive directory-based symlinks.
|
| 94 |
+
Before, it could have entered infinite loop.
|
| 95 |
+
- 3.4 (Mar 19, 2020) adds support for directory-based symlinks.
|
| 96 |
+
- 3.3 (Dec 6, 2019) stabilizes RAM consumption and enables perf management with `highWaterMark` option. Fixes race conditions related to `for-await` looping.
|
| 97 |
+
- 3.2 (Oct 14, 2019) improves performance by 250% and makes streams implementation more idiomatic.
|
| 98 |
+
- 3.1 (Jul 7, 2019) brings `bigint` support to `stat` output on Windows. This is backwards-incompatible for some cases. Be careful. It you use it incorrectly, you'll see "TypeError: Cannot mix BigInt and other types, use explicit conversions".
|
| 99 |
+
- 3.0 brings huge performance improvements and stream backpressure support.
|
| 100 |
+
- Upgrading 2.x to 3.x:
|
| 101 |
+
- Signature changed from `readdirp(options)` to `readdirp(root, options)`
|
| 102 |
+
- Replaced callback API with promise API.
|
| 103 |
+
- Renamed `entryType` option to `type`
|
| 104 |
+
- Renamed `entryType: 'both'` to `'files_directories'`
|
| 105 |
+
- `EntryInfo`
|
| 106 |
+
- Renamed `stat` to `stats`
|
| 107 |
+
- Emitted only when `alwaysStat: true`
|
| 108 |
+
- `dirent` is emitted instead of `stats` by default with `alwaysStat: false`
|
| 109 |
+
- Renamed `name` to `basename`
|
| 110 |
+
- Removed `parentDir` and `fullParentDir` properties
|
| 111 |
+
- Supported node.js versions:
|
| 112 |
+
- 4.x: node 14+
|
| 113 |
+
- 3.x: node 8+
|
| 114 |
+
- 2.x: node 0.6+
|
| 115 |
+
|
| 116 |
+
## License
|
| 117 |
+
|
| 118 |
+
Copyright (c) 2012-2019 Thorsten Lorenz, Paul Miller (<https://paulmillr.com>)
|
| 119 |
+
|
| 120 |
+
MIT License, see [LICENSE](LICENSE) file.
|
tools/ui/node_modules/svelte-check/node_modules/readdirp/esm/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Recursive version of readdir. Exposes a streaming API and promise API.
|
| 3 |
+
* Streaming API allows to use a small amount of RAM.
|
| 4 |
+
*
|
| 5 |
+
* @module
|
| 6 |
+
* @example
|
| 7 |
+
```js
|
| 8 |
+
import readdirp from 'readdirp';
|
| 9 |
+
for await (const entry of readdirp('.')) {
|
| 10 |
+
const {path} = entry;
|
| 11 |
+
console.log(`${JSON.stringify({path})}`);
|
| 12 |
+
}
|
| 13 |
+
```
|
| 14 |
+
*/
|
| 15 |
+
/*! readdirp - MIT License (c) 2012-2019 Thorsten Lorenz, Paul Miller (https://paulmillr.com) */
|
| 16 |
+
import type { Stats, Dirent } from 'node:fs';
|
| 17 |
+
import { Readable } from 'node:stream';
|
| 18 |
+
/** Path in file system. */
|
| 19 |
+
export type Path = string;
|
| 20 |
+
/** Emitted entry. Contains relative & absolute path, basename, and either stats or dirent. */
|
| 21 |
+
export interface EntryInfo {
|
| 22 |
+
path: string;
|
| 23 |
+
fullPath: string;
|
| 24 |
+
stats?: Stats;
|
| 25 |
+
dirent?: Dirent;
|
| 26 |
+
basename: string;
|
| 27 |
+
}
|
| 28 |
+
/** Path or dir entries (files) */
|
| 29 |
+
export type PathOrDirent = Dirent | Path;
|
| 30 |
+
/** Filterer for files */
|
| 31 |
+
export type Tester = (entryInfo: EntryInfo) => boolean;
|
| 32 |
+
export type Predicate = string[] | string | Tester;
|
| 33 |
+
export declare const EntryTypes: {
|
| 34 |
+
readonly FILE_TYPE: "files";
|
| 35 |
+
readonly DIR_TYPE: "directories";
|
| 36 |
+
readonly FILE_DIR_TYPE: "files_directories";
|
| 37 |
+
readonly EVERYTHING_TYPE: "all";
|
| 38 |
+
};
|
| 39 |
+
export type EntryType = (typeof EntryTypes)[keyof typeof EntryTypes];
|
| 40 |
+
/**
|
| 41 |
+
* Options for readdirp.
|
| 42 |
+
* * type: files, directories, or both
|
| 43 |
+
* * lstat: whether to use symlink-friendly stat
|
| 44 |
+
* * depth: max depth
|
| 45 |
+
* * alwaysStat: whether to use stat (more resources) or dirent
|
| 46 |
+
* * highWaterMark: streaming param, specifies max amount of resources per entry
|
| 47 |
+
*/
|
| 48 |
+
export type ReaddirpOptions = {
|
| 49 |
+
root: string;
|
| 50 |
+
fileFilter?: Predicate;
|
| 51 |
+
directoryFilter?: Predicate;
|
| 52 |
+
type?: EntryType;
|
| 53 |
+
lstat?: boolean;
|
| 54 |
+
depth?: number;
|
| 55 |
+
alwaysStat?: boolean;
|
| 56 |
+
highWaterMark?: number;
|
| 57 |
+
};
|
| 58 |
+
/** Directory entry. Contains path, depth count, and files. */
|
| 59 |
+
export interface DirEntry {
|
| 60 |
+
files: PathOrDirent[];
|
| 61 |
+
depth: number;
|
| 62 |
+
path: Path;
|
| 63 |
+
}
|
| 64 |
+
/** Readable readdir stream, emitting new files as they're being listed. */
|
| 65 |
+
export declare class ReaddirpStream extends Readable {
|
| 66 |
+
parents: any[];
|
| 67 |
+
reading: boolean;
|
| 68 |
+
parent?: DirEntry;
|
| 69 |
+
_stat: Function;
|
| 70 |
+
_maxDepth: number;
|
| 71 |
+
_wantsDir: boolean;
|
| 72 |
+
_wantsFile: boolean;
|
| 73 |
+
_wantsEverything: boolean;
|
| 74 |
+
_root: Path;
|
| 75 |
+
_isDirent: boolean;
|
| 76 |
+
_statsProp: 'dirent' | 'stats';
|
| 77 |
+
_rdOptions: {
|
| 78 |
+
encoding: 'utf8';
|
| 79 |
+
withFileTypes: boolean;
|
| 80 |
+
};
|
| 81 |
+
_fileFilter: Tester;
|
| 82 |
+
_directoryFilter: Tester;
|
| 83 |
+
constructor(options?: Partial<ReaddirpOptions>);
|
| 84 |
+
_read(batch: number): Promise<void>;
|
| 85 |
+
_exploreDir(path: Path, depth: number): Promise<{
|
| 86 |
+
files: string[] | undefined;
|
| 87 |
+
depth: number;
|
| 88 |
+
path: string;
|
| 89 |
+
}>;
|
| 90 |
+
_formatEntry(dirent: PathOrDirent, path: Path): Promise<EntryInfo | undefined>;
|
| 91 |
+
_onError(err: Error): void;
|
| 92 |
+
_getEntryType(entry: EntryInfo): Promise<void | '' | 'file' | 'directory'>;
|
| 93 |
+
_includeAsFile(entry: EntryInfo): boolean | undefined;
|
| 94 |
+
}
|
| 95 |
+
/**
|
| 96 |
+
* Streaming version: Reads all files and directories in given root recursively.
|
| 97 |
+
* Consumes ~constant small amount of RAM.
|
| 98 |
+
* @param root Root directory
|
| 99 |
+
* @param options Options to specify root (start directory), filters and recursion depth
|
| 100 |
+
*/
|
| 101 |
+
export declare function readdirp(root: Path, options?: Partial<ReaddirpOptions>): ReaddirpStream;
|
| 102 |
+
/**
|
| 103 |
+
* Promise version: Reads all files and directories in given root recursively.
|
| 104 |
+
* Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
|
| 105 |
+
* @returns array of paths and their entry infos
|
| 106 |
+
*/
|
| 107 |
+
export declare function readdirpPromise(root: Path, options?: Partial<ReaddirpOptions>): Promise<EntryInfo[]>;
|
| 108 |
+
export default readdirp;
|
tools/ui/node_modules/svelte-check/node_modules/readdirp/esm/index.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
| 1 |
+
import { stat, lstat, readdir, realpath } from 'node:fs/promises';
|
| 2 |
+
import { Readable } from 'node:stream';
|
| 3 |
+
import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from 'node:path';
|
| 4 |
+
export const EntryTypes = {
|
| 5 |
+
FILE_TYPE: 'files',
|
| 6 |
+
DIR_TYPE: 'directories',
|
| 7 |
+
FILE_DIR_TYPE: 'files_directories',
|
| 8 |
+
EVERYTHING_TYPE: 'all',
|
| 9 |
+
};
|
| 10 |
+
const defaultOptions = {
|
| 11 |
+
root: '.',
|
| 12 |
+
fileFilter: (_entryInfo) => true,
|
| 13 |
+
directoryFilter: (_entryInfo) => true,
|
| 14 |
+
type: EntryTypes.FILE_TYPE,
|
| 15 |
+
lstat: false,
|
| 16 |
+
depth: 2147483648,
|
| 17 |
+
alwaysStat: false,
|
| 18 |
+
highWaterMark: 4096,
|
| 19 |
+
};
|
| 20 |
+
Object.freeze(defaultOptions);
|
| 21 |
+
const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
|
| 22 |
+
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
|
| 23 |
+
const ALL_TYPES = [
|
| 24 |
+
EntryTypes.DIR_TYPE,
|
| 25 |
+
EntryTypes.EVERYTHING_TYPE,
|
| 26 |
+
EntryTypes.FILE_DIR_TYPE,
|
| 27 |
+
EntryTypes.FILE_TYPE,
|
| 28 |
+
];
|
| 29 |
+
const DIR_TYPES = new Set([
|
| 30 |
+
EntryTypes.DIR_TYPE,
|
| 31 |
+
EntryTypes.EVERYTHING_TYPE,
|
| 32 |
+
EntryTypes.FILE_DIR_TYPE,
|
| 33 |
+
]);
|
| 34 |
+
const FILE_TYPES = new Set([
|
| 35 |
+
EntryTypes.EVERYTHING_TYPE,
|
| 36 |
+
EntryTypes.FILE_DIR_TYPE,
|
| 37 |
+
EntryTypes.FILE_TYPE,
|
| 38 |
+
]);
|
| 39 |
+
const isNormalFlowError = (error) => NORMAL_FLOW_ERRORS.has(error.code);
|
| 40 |
+
const wantBigintFsStats = process.platform === 'win32';
|
| 41 |
+
const emptyFn = (_entryInfo) => true;
|
| 42 |
+
const normalizeFilter = (filter) => {
|
| 43 |
+
if (filter === undefined)
|
| 44 |
+
return emptyFn;
|
| 45 |
+
if (typeof filter === 'function')
|
| 46 |
+
return filter;
|
| 47 |
+
if (typeof filter === 'string') {
|
| 48 |
+
const fl = filter.trim();
|
| 49 |
+
return (entry) => entry.basename === fl;
|
| 50 |
+
}
|
| 51 |
+
if (Array.isArray(filter)) {
|
| 52 |
+
const trItems = filter.map((item) => item.trim());
|
| 53 |
+
return (entry) => trItems.some((f) => entry.basename === f);
|
| 54 |
+
}
|
| 55 |
+
return emptyFn;
|
| 56 |
+
};
|
| 57 |
+
/** Readable readdir stream, emitting new files as they're being listed. */
|
| 58 |
+
export class ReaddirpStream extends Readable {
|
| 59 |
+
constructor(options = {}) {
|
| 60 |
+
super({
|
| 61 |
+
objectMode: true,
|
| 62 |
+
autoDestroy: true,
|
| 63 |
+
highWaterMark: options.highWaterMark,
|
| 64 |
+
});
|
| 65 |
+
const opts = { ...defaultOptions, ...options };
|
| 66 |
+
const { root, type } = opts;
|
| 67 |
+
this._fileFilter = normalizeFilter(opts.fileFilter);
|
| 68 |
+
this._directoryFilter = normalizeFilter(opts.directoryFilter);
|
| 69 |
+
const statMethod = opts.lstat ? lstat : stat;
|
| 70 |
+
// Use bigint stats if it's windows and stat() supports options (node 10+).
|
| 71 |
+
if (wantBigintFsStats) {
|
| 72 |
+
this._stat = (path) => statMethod(path, { bigint: true });
|
| 73 |
+
}
|
| 74 |
+
else {
|
| 75 |
+
this._stat = statMethod;
|
| 76 |
+
}
|
| 77 |
+
this._maxDepth = opts.depth ?? defaultOptions.depth;
|
| 78 |
+
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
| 79 |
+
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
| 80 |
+
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
| 81 |
+
this._root = presolve(root);
|
| 82 |
+
this._isDirent = !opts.alwaysStat;
|
| 83 |
+
this._statsProp = this._isDirent ? 'dirent' : 'stats';
|
| 84 |
+
this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
|
| 85 |
+
// Launch stream with one parent, the root dir.
|
| 86 |
+
this.parents = [this._exploreDir(root, 1)];
|
| 87 |
+
this.reading = false;
|
| 88 |
+
this.parent = undefined;
|
| 89 |
+
}
|
| 90 |
+
async _read(batch) {
|
| 91 |
+
if (this.reading)
|
| 92 |
+
return;
|
| 93 |
+
this.reading = true;
|
| 94 |
+
try {
|
| 95 |
+
while (!this.destroyed && batch > 0) {
|
| 96 |
+
const par = this.parent;
|
| 97 |
+
const fil = par && par.files;
|
| 98 |
+
if (fil && fil.length > 0) {
|
| 99 |
+
const { path, depth } = par;
|
| 100 |
+
const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path));
|
| 101 |
+
const awaited = await Promise.all(slice);
|
| 102 |
+
for (const entry of awaited) {
|
| 103 |
+
if (!entry)
|
| 104 |
+
continue;
|
| 105 |
+
if (this.destroyed)
|
| 106 |
+
return;
|
| 107 |
+
const entryType = await this._getEntryType(entry);
|
| 108 |
+
if (entryType === 'directory' && this._directoryFilter(entry)) {
|
| 109 |
+
if (depth <= this._maxDepth) {
|
| 110 |
+
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
| 111 |
+
}
|
| 112 |
+
if (this._wantsDir) {
|
| 113 |
+
this.push(entry);
|
| 114 |
+
batch--;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
else if ((entryType === 'file' || this._includeAsFile(entry)) &&
|
| 118 |
+
this._fileFilter(entry)) {
|
| 119 |
+
if (this._wantsFile) {
|
| 120 |
+
this.push(entry);
|
| 121 |
+
batch--;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
else {
|
| 127 |
+
const parent = this.parents.pop();
|
| 128 |
+
if (!parent) {
|
| 129 |
+
this.push(null);
|
| 130 |
+
break;
|
| 131 |
+
}
|
| 132 |
+
this.parent = await parent;
|
| 133 |
+
if (this.destroyed)
|
| 134 |
+
return;
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
catch (error) {
|
| 139 |
+
this.destroy(error);
|
| 140 |
+
}
|
| 141 |
+
finally {
|
| 142 |
+
this.reading = false;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
async _exploreDir(path, depth) {
|
| 146 |
+
let files;
|
| 147 |
+
try {
|
| 148 |
+
files = await readdir(path, this._rdOptions);
|
| 149 |
+
}
|
| 150 |
+
catch (error) {
|
| 151 |
+
this._onError(error);
|
| 152 |
+
}
|
| 153 |
+
return { files, depth, path };
|
| 154 |
+
}
|
| 155 |
+
async _formatEntry(dirent, path) {
|
| 156 |
+
let entry;
|
| 157 |
+
const basename = this._isDirent ? dirent.name : dirent;
|
| 158 |
+
try {
|
| 159 |
+
const fullPath = presolve(pjoin(path, basename));
|
| 160 |
+
entry = { path: prelative(this._root, fullPath), fullPath, basename };
|
| 161 |
+
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
| 162 |
+
}
|
| 163 |
+
catch (err) {
|
| 164 |
+
this._onError(err);
|
| 165 |
+
return;
|
| 166 |
+
}
|
| 167 |
+
return entry;
|
| 168 |
+
}
|
| 169 |
+
_onError(err) {
|
| 170 |
+
if (isNormalFlowError(err) && !this.destroyed) {
|
| 171 |
+
this.emit('warn', err);
|
| 172 |
+
}
|
| 173 |
+
else {
|
| 174 |
+
this.destroy(err);
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
async _getEntryType(entry) {
|
| 178 |
+
// entry may be undefined, because a warning or an error were emitted
|
| 179 |
+
// and the statsProp is undefined
|
| 180 |
+
if (!entry && this._statsProp in entry) {
|
| 181 |
+
return '';
|
| 182 |
+
}
|
| 183 |
+
const stats = entry[this._statsProp];
|
| 184 |
+
if (stats.isFile())
|
| 185 |
+
return 'file';
|
| 186 |
+
if (stats.isDirectory())
|
| 187 |
+
return 'directory';
|
| 188 |
+
if (stats && stats.isSymbolicLink()) {
|
| 189 |
+
const full = entry.fullPath;
|
| 190 |
+
try {
|
| 191 |
+
const entryRealPath = await realpath(full);
|
| 192 |
+
const entryRealPathStats = await lstat(entryRealPath);
|
| 193 |
+
if (entryRealPathStats.isFile()) {
|
| 194 |
+
return 'file';
|
| 195 |
+
}
|
| 196 |
+
if (entryRealPathStats.isDirectory()) {
|
| 197 |
+
const len = entryRealPath.length;
|
| 198 |
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === psep) {
|
| 199 |
+
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
| 200 |
+
// @ts-ignore
|
| 201 |
+
recursiveError.code = RECURSIVE_ERROR_CODE;
|
| 202 |
+
return this._onError(recursiveError);
|
| 203 |
+
}
|
| 204 |
+
return 'directory';
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
catch (error) {
|
| 208 |
+
this._onError(error);
|
| 209 |
+
return '';
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
_includeAsFile(entry) {
|
| 214 |
+
const stats = entry && entry[this._statsProp];
|
| 215 |
+
return stats && this._wantsEverything && !stats.isDirectory();
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
/**
|
| 219 |
+
* Streaming version: Reads all files and directories in given root recursively.
|
| 220 |
+
* Consumes ~constant small amount of RAM.
|
| 221 |
+
* @param root Root directory
|
| 222 |
+
* @param options Options to specify root (start directory), filters and recursion depth
|
| 223 |
+
*/
|
| 224 |
+
export function readdirp(root, options = {}) {
|
| 225 |
+
// @ts-ignore
|
| 226 |
+
let type = options.entryType || options.type;
|
| 227 |
+
if (type === 'both')
|
| 228 |
+
type = EntryTypes.FILE_DIR_TYPE; // backwards-compatibility
|
| 229 |
+
if (type)
|
| 230 |
+
options.type = type;
|
| 231 |
+
if (!root) {
|
| 232 |
+
throw new Error('readdirp: root argument is required. Usage: readdirp(root, options)');
|
| 233 |
+
}
|
| 234 |
+
else if (typeof root !== 'string') {
|
| 235 |
+
throw new TypeError('readdirp: root argument must be a string. Usage: readdirp(root, options)');
|
| 236 |
+
}
|
| 237 |
+
else if (type && !ALL_TYPES.includes(type)) {
|
| 238 |
+
throw new Error(`readdirp: Invalid type passed. Use one of ${ALL_TYPES.join(', ')}`);
|
| 239 |
+
}
|
| 240 |
+
options.root = root;
|
| 241 |
+
return new ReaddirpStream(options);
|
| 242 |
+
}
|
| 243 |
+
/**
|
| 244 |
+
* Promise version: Reads all files and directories in given root recursively.
|
| 245 |
+
* Compared to streaming version, will consume a lot of RAM e.g. when 1 million files are listed.
|
| 246 |
+
* @returns array of paths and their entry infos
|
| 247 |
+
*/
|
| 248 |
+
export function readdirpPromise(root, options = {}) {
|
| 249 |
+
return new Promise((resolve, reject) => {
|
| 250 |
+
const files = [];
|
| 251 |
+
readdirp(root, options)
|
| 252 |
+
.on('data', (entry) => files.push(entry))
|
| 253 |
+
.on('end', () => resolve(files))
|
| 254 |
+
.on('error', (error) => reject(error));
|
| 255 |
+
});
|
| 256 |
+
}
|
| 257 |
+
export default readdirp;
|
tools/ui/node_modules/svelte-check/node_modules/readdirp/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{ "type": "module", "sideEffects": false }
|