Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump swc #901

Merged
merged 4 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/waku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
"dependencies": {
"@hono/node-server": "1.12.2",
"@swc/core": "1.6.7",
"@swc/core": "1.7.28",
"@vitejs/plugin-react": "4.3.1",
"dotenv": "16.4.5",
"hono": "4.6.1",
Expand All @@ -88,7 +88,7 @@
},
"devDependencies": {
"@netlify/functions": "^2.8.1",
"@swc/cli": "^0.4.0",
"@swc/cli": "0.4.1-nightly.20240914",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it conflict if we keep using 0.4.0?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it is the latest.

"rollup": "^4.21.3",
"ts-expect": "^1.3.0",
"vitest": "^2.0.5"
Expand Down
56 changes: 38 additions & 18 deletions packages/waku/src/lib/plugins/vite-plugin-rsc-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,26 @@ export ${name === 'default' ? name : `const ${name} =`} createServerReference('$
}
};

export const createEmptySpan = (): swc.Span =>
({
start: 0,
end: 0,
}) as swc.Span;

const createIdentifier = (value: string): swc.Identifier => ({
type: 'Identifier',
value,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
ctxt: 0,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, we need it in this position... So, if swc fixes the TS type, the @ts-expect-error will be gone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

optional: false,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, does it work if this is span: { start: 0, end: 0 }? Or, does TS complain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

span: { start: 0, end: 0 }. swc type is broken

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it likely that swc will fix this type issue sometime soon-ish?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});

const createStringLiteral = (value: string): swc.StringLiteral => ({
type: 'StringLiteral',
value,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
});

const createCallExpression = (
Expand All @@ -90,8 +99,11 @@ const createCallExpression = (
): swc.CallExpression => ({
type: 'CallExpression',
callee,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
ctxt: 0,
arguments: args.map((expression) => ({ expression })),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
});

const serverInitCode = swc.parseSync(`
Expand Down Expand Up @@ -137,7 +149,7 @@ const transformExportedServerActions = (
createStringLiteral(name),
],
),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
mod.body.splice(++i, 0, stmt);
};
Expand Down Expand Up @@ -182,7 +194,7 @@ const transformExportedServerActions = (
const decl: swc.ExportDefaultExpression = {
type: 'ExportDefaultExpression',
expression: callExp,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
replaceNode(item, decl);
}
Expand Down Expand Up @@ -227,8 +239,9 @@ const prependArgsToFn = <Fn extends FunctionWithBlockBody>(
params: [...args.map(createIdentifier), ...fn.params],
body: {
type: 'BlockStatement',
ctxt: 0,
stmts: fn.body.stmts.filter((stmt) => !isUseServerDirective(stmt)),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
};
}
Expand All @@ -238,14 +251,15 @@ const prependArgsToFn = <Fn extends FunctionWithBlockBody>(
...args.map((arg) => ({
type: 'Parameter',
pat: createIdentifier(arg),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
})),
...fn.params,
],
body: {
type: 'BlockStatement',
ctxt: 0,
stmts: fn.body.stmts.filter((stmt) => !isUseServerDirective(stmt)),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
};
};
Expand Down Expand Up @@ -290,7 +304,7 @@ const collectLocalNames = (
{
type: 'ReturnStatement',
argument: fn.body,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
];
}
Expand Down Expand Up @@ -343,7 +357,7 @@ const transformInlineServerActions = (
type: 'MemberExpression',
object: createIdentifier(name),
property: createIdentifier('bind'),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
[
createIdentifier('null'),
Expand All @@ -361,16 +375,19 @@ const transformInlineServerActions = (
type: 'VariableDeclaration',
kind: 'const',
declare: false,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
ctxt: 0,
declarations: [
{
type: 'VariableDeclarator',
id: createIdentifier(decl.identifier.value),
init: callExp,
definite: false,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
],
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
replaceNode(decl, newDecl);
}
Expand Down Expand Up @@ -399,7 +416,7 @@ const transformInlineServerActions = (
const decl: swc.ExportDefaultExpression = {
type: 'ExportDefaultExpression',
expression: callExp,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
replaceNode(item, decl);
return;
Expand Down Expand Up @@ -444,7 +461,7 @@ const transformInlineServerActions = (
const stmt1: swc.ExportDeclaration = {
type: 'ExportDeclaration',
declaration: prependArgsToFn(actionFn, closureVars),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
const stmt2: swc.ExpressionStatement = {
type: 'ExpressionStatement',
Expand All @@ -456,7 +473,7 @@ const transformInlineServerActions = (
createStringLiteral('__waku_action' + actionIndex),
],
),
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
return [stmt1, stmt2];
} else {
Expand All @@ -466,6 +483,9 @@ const transformInlineServerActions = (
type: 'VariableDeclaration',
kind: 'const',
declare: false,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
ctxt: 0,
declarations: [
{
type: 'VariableDeclarator',
Expand All @@ -479,12 +499,12 @@ const transformInlineServerActions = (
],
),
definite: false,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
],
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
},
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
};
return [stmt];
}
Expand Down
Loading
Loading