Skip to content

Commit

Permalink
chore: bump swc (#901)
Browse files Browse the repository at this point in the history
Fixes: #845

---------

Co-authored-by: Daishi Kato <[email protected]>
  • Loading branch information
himself65 and dai-shi authored Sep 28, 2024
1 parent 09289da commit 49d1ae7
Show file tree
Hide file tree
Showing 3 changed files with 535 additions and 411 deletions.
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",
"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,
optional: false,
span: { start: 0, end: 0, ctxt: 0 },
span: createEmptySpan(),
});

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

0 comments on commit 49d1ae7

Please sign in to comment.