Skip to content

Commit 8a9bbfc

Browse files
authored
fix: various types (#747)
1 parent 8db02f6 commit 8a9bbfc

18 files changed

Lines changed: 63 additions & 45 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"source-map": "catalog:default",
4040
"type-fest": "catalog:default",
4141
"vitest": "catalog:default",
42-
"wait-on": "catalog:default"
42+
"wait-on": "catalog:default",
43+
"typescript": "catalog:default"
4344
},
4445
"dependencies": {
4546
"@types/eslint": "catalog:default"

packages/compat-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"ripple": "workspace:*"
2121
},
2222
"devDependencies": {
23+
"@types/node": "catalog:default",
2324
"@types/react": "^19.2.2",
2425
"@types/react-dom": "^19.2.2",
2526
"typescript": "catalog:default"

packages/compat-react/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"./tests/**/*.test.ripple",
2424
"./tests/**/*.d.ts",
2525
"./tests/**/*.js"
26-
]
26+
],
27+
"exclude": ["node_modules", "dist"]
2728
}

packages/eslint-parser/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"rootDir": "./src",
1111
"strict": true,
1212
"esModuleInterop": true,
13-
"skipLibCheck": true,
1413
"forceConsistentCasingInFileNames": true,
1514
"resolveJsonModule": true,
1615
"isolatedModules": true

packages/eslint-plugin/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"rootDir": "./src",
1111
"strict": true,
1212
"esModuleInterop": true,
13-
"skipLibCheck": true,
1413
"forceConsistentCasingInFileNames": true,
1514
"resolveJsonModule": true,
1615
"isolatedModules": true

packages/language-server/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"resolveJsonModule": true,
1212
"types": []
1313
},
14-
"include": ["src/**/*.js", "index.js", "bin/**/*.js"]
14+
"include": ["src/**/*.js", "index.js", "bin/**/*.js"],
15+
"exclude": ["node_modules", "dist"]
1516
}

packages/prettier-plugin/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"noEmit": true,
1313
"types": ["vitest/globals"]
1414
},
15-
"include": ["./*.js", "./src/", "vitest-extensions.d.ts"]
15+
"include": ["./*.js", "./src/", "vitest-extensions.d.ts"],
16+
"exclude": ["node_modules", "dist"]
1617
}

packages/ripple/src/compiler/phases/3-transform/client/index.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,11 @@ const visitors = {
18771877
]),
18781878
);
18791879

1880+
func.metadata = {
1881+
...func.metadata,
1882+
is_component: true,
1883+
};
1884+
18801885
return func;
18811886
},
18821887

@@ -4748,7 +4753,7 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
47484753

47494754
const program = /** @type {AST.Program} */ (walk(analysis.ast, { ...state }, visitors));
47504755

4751-
/** @type {AST.Statement[]} */
4756+
/** @type {AST.RippleProgram['body']} */
47524757
let body = [];
47534758

47544759
for (const import_node of state.imports) {
@@ -4784,15 +4789,15 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
47844789
// Walk the body to find components and inject HMR wrapping.
47854790
// After the walk, Component nodes become FunctionExpression nodes
47864791
// (via b.function() which creates FunctionExpression).
4787-
/** @type {AST.Statement[]} */
4792+
/** @type {AST.RippleProgram['body']} */
47884793
const hmr_body = [];
47894794

47904795
for (const node of body) {
47914796
hmr_body.push(node);
47924797

47934798
if (node.type === 'ExportDefaultDeclaration') {
4794-
const decl = node.declaration;
4795-
if (decl.type === 'FunctionExpression' && decl.id && component_names.has(decl.id.name)) {
4799+
const decl = /** @type {AST.FunctionExpression} */ (node.declaration);
4800+
if (decl.metadata?.is_component && decl.id && component_names.has(decl.id.name)) {
47964801
const name = decl.id.name;
47974802
exported_components.push({ name, export_type: 'default' });
47984803
// Replace ExportDefaultDeclaration with plain FunctionExpression (printed as function declaration)
@@ -4803,13 +4808,8 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
48034808
hmr_body.push(b.export_default(b.id(name)));
48044809
}
48054810
} else if (node.type === 'ExportNamedDeclaration') {
4806-
const decl = node.declaration;
4807-
if (
4808-
decl &&
4809-
decl.type === 'FunctionExpression' &&
4810-
decl.id &&
4811-
component_names.has(decl.id.name)
4812-
) {
4811+
const decl = /** @type {AST.FunctionExpression | null | undefined} */ (node.declaration);
4812+
if (decl && decl.metadata?.is_component && decl.id && component_names.has(decl.id.name)) {
48134813
const name = decl.id.name;
48144814
exported_components.push({ name, export_type: 'named' });
48154815
// Replace ExportNamedDeclaration with plain FunctionExpression (printed as function declaration)
@@ -4830,6 +4830,7 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
48304830
}
48314831
} else if (
48324832
node.type === 'FunctionExpression' &&
4833+
node.metadata?.is_component &&
48334834
node.id &&
48344835
component_names.has(node.id.name)
48354836
) {
@@ -4859,7 +4860,7 @@ export function transform_client(filename, source, analysis, to_ts, minify_css,
48594860
body = hmr_body;
48604861
}
48614862

4862-
program.body = body;
4863+
/** @type {AST.RippleProgram['body']} */ (program.body) = body;
48634864

48644865
const language_handler = to_ts
48654866
? create_tsx_with_typescript_support(analysis.comments)

packages/ripple/src/compiler/phases/3-transform/server/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,16 @@ const visitors = {
418418

419419
if (metadata.await) {
420420
const parent = context.path.at(-1);
421-
/** @type {any[] | null} */
421+
/** @type {AST.RippleProgram['body'] | null} */
422422
let body = null;
423-
/** @type {any} */
423+
/** @type {AST.Component | AST.ExportNamedDeclaration} */
424424
let target_node = node;
425425
if (parent?.type === 'Program' || parent?.type === 'BlockStatement') {
426-
body = /** @type {AST.RippleProgram} */ (parent).body;
426+
body = parent.body;
427427
} else if (parent?.type === 'ExportNamedDeclaration') {
428428
const grandparent = context.path.at(-2);
429429
if (grandparent?.type === 'Program' || grandparent?.type === 'BlockStatement') {
430-
body = /** @type {AST.RippleProgram} */ (grandparent).body;
430+
body = grandparent.body;
431431
target_node = parent;
432432
}
433433
}
@@ -1401,7 +1401,7 @@ const visitors = {
14011401
});
14021402
context.state.init?.push(
14031403
b.var(
1404-
b.id(pending_position_name),
1404+
b.id(/** @type {string} */ (pending_position_name)),
14051405
b.member(b.member(b.id('__output'), b.id('body')), b.id('length')),
14061406
),
14071407
);
@@ -1443,7 +1443,7 @@ const visitors = {
14431443
b.call(
14441444
b.member(b.member(b.id('__output'), b.id('body')), b.id('slice')),
14451445
b.literal(0),
1446-
b.id(pending_position_name),
1446+
b.id(/** @type {string} */ (pending_position_name)),
14471447
),
14481448
),
14491449
),

packages/ripple/src/compiler/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ declare module 'estree' {
383383
* Ripple's extended Program with Component support
384384
*/
385385
interface RippleProgram extends Omit<Program, 'body'> {
386-
body: (Program['body'][number] | Component)[];
386+
body: (Program['body'][number] | Component | FunctionExpression)[];
387387
}
388388

389389
interface RippleMethodDefinition extends Omit<AST.MethodDefinition, 'value'> {

0 commit comments

Comments
 (0)