Skip to content

Commit 52c5a71

Browse files
committed
chore: typecheck scripts
1 parent fd942b7 commit 52c5a71

File tree

3 files changed

+44
-24
lines changed

3 files changed

+44
-24
lines changed

packages/svelte/scripts/check-treeshakeability.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import virtual from '@rollup/plugin-virtual';
55
import { nodeResolve } from '@rollup/plugin-node-resolve';
66
import { compile } from 'svelte/compiler';
77

8+
/**
9+
* @param {string} entry
10+
*/
811
async function bundle_code(entry) {
912
const bundle = await rollup({
1013
input: '__entry__',

packages/svelte/scripts/process-messages/index.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,23 @@ for (const category of fs.readdirSync('messages')) {
5454
}
5555
}
5656

57+
/**
58+
* @param {string} name
59+
* @param {string} dest
60+
*/
5761
function transform(name, dest) {
5862
const source = fs
5963
.readFileSync(new URL(`./templates/${name}.js`, import.meta.url), 'utf-8')
6064
.replace(/\r\n/g, '\n');
6165

66+
/**
67+
* @type {Array<{
68+
* type: string;
69+
* value: string;
70+
* start: number;
71+
* end: number
72+
* }>}
73+
*/
6274
const comments = [];
6375

6476
let ast = acorn.parse(source, {
@@ -135,6 +147,7 @@ function transform(name, dest) {
135147

136148
for (const code in category) {
137149
const { messages } = category[code];
150+
/** @type {string[]} */
138151
const vars = [];
139152

140153
const group = messages.map((text, i) => {
@@ -227,29 +240,31 @@ function transform(name, dest) {
227240

228241
const value = node.value
229242
.split('\n')
230-
.map((line) => {
231-
if (line === ' * MESSAGE') {
232-
return messages[messages.length - 1]
233-
.split('\n')
234-
.map((line) => ` * ${line}`)
235-
.join('\n');
243+
.map(
244+
/** @param {string} line */ (line) => {
245+
if (line === ' * MESSAGE') {
246+
return messages[messages.length - 1]
247+
.split('\n')
248+
.map((line) => ` * ${line}`)
249+
.join('\n');
250+
}
251+
252+
if (line.includes('PARAMETER')) {
253+
return vars
254+
.map((name, i) => {
255+
const optional = i >= group[0].vars.length;
256+
257+
return optional
258+
? ` * @param {string | undefined | null} [${name}]`
259+
: ` * @param {string} ${name}`;
260+
})
261+
.join('\n');
262+
}
263+
264+
return line;
236265
}
237-
238-
if (line.includes('PARAMETER')) {
239-
return vars
240-
.map((name, i) => {
241-
const optional = i >= group[0].vars.length;
242-
243-
return optional
244-
? ` * @param {string | undefined | null} [${name}]`
245-
: ` * @param {string} ${name}`;
246-
})
247-
.join('\n');
248-
}
249-
250-
return line;
251-
})
252-
.filter((x) => x !== '')
266+
)
267+
.filter(/** @param {string} x */ (x) => x !== '')
253268
.join('\n');
254269

255270
if (value !== node.value) {

packages/svelte/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
}
3232
},
3333
"include": [
34-
"./src",
34+
"./*.js",
35+
"./scripts/",
36+
"./src/",
3537
"./tests/*/test.ts",
3638
"./tests/runtime-browser/test-ssr.ts",
3739
"./tests/*/samples/*/_config.js"
3840
],
39-
"exclude": ["./src/compiler/optimizer"]
41+
"exclude": ["./scripts/process-messages/templates/", "./src/compiler/optimizer/"]
4042
}

0 commit comments

Comments
 (0)