-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revamp based on @lubieowoce https://github.com/lubieowoce/tangle/blob…
- Loading branch information
1 parent
bb3ade4
commit 03b27b3
Showing
20 changed files
with
2,882 additions
and
2,678 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as assert from "node:assert/strict"; | ||
import { describe, test } from "node:test"; | ||
|
||
import { parse } from "@babel/core"; | ||
|
||
import type { ClientTransformOptions } from "./client-transform.js"; | ||
import { clientTransform } from "./client-transform.js"; | ||
|
||
const js = String.raw; | ||
|
||
function assertAST(actual: string, expected: string, log?: boolean) { | ||
function replacer(key: string, value: unknown) { | ||
if (key === "start" || key === "end" || key === "loc") { | ||
return undefined; | ||
} | ||
return value; | ||
} | ||
|
||
if (log) { | ||
console.log("---------- ACTUAL ----------"); | ||
console.log(actual); | ||
console.log("----------------------------"); | ||
} | ||
|
||
assert.deepEqual( | ||
JSON.parse(JSON.stringify(parse(actual)?.program, replacer)), | ||
JSON.parse(JSON.stringify(parse(expected)?.program, replacer)) | ||
); | ||
} | ||
|
||
const transformOptions: ClientTransformOptions = { | ||
id: (filename, directive) => `${directive}:${filename}`, | ||
importFrom: "mwap/runtime/client", | ||
importServer: "$$server", | ||
}; | ||
|
||
describe("use server replaces modules", () => { | ||
test("with annotated exports", () => { | ||
const code = js` | ||
"use server"; | ||
import { Imported } from "third-party-imported"; | ||
export { Exported } from "third-party-exported"; | ||
export { Imported }; | ||
export const varDeclaration = "varDeclaration"; | ||
export const functionDeclaration = function functionDeclaration() {}; | ||
export function Component() {} | ||
`; | ||
|
||
console.log({ | ||
code: clientTransform(code, "use-server.js", transformOptions).code, | ||
}); | ||
console.log(clientTransform(code, "use-server.js", transformOptions).code); | ||
assertAST( | ||
clientTransform(code, "use-server.js", transformOptions).code, | ||
js` | ||
import { $$server as _$$server } from "mwap/runtime/client"; | ||
export const Exported = _$$server({}, "use server:use-server.js", "Exported"); | ||
export const Imported = _$$server({}, "use server:use-server.js", "Imported"); | ||
export const varDeclaration = _$$server({}, "use server:use-server.js", "varDeclaration"); | ||
export const functionDeclaration = _$$server({}, "use server:use-server.js", "functionDeclaration"); | ||
export const Component = _$$server({}, "use server:use-server.js", "Component"); | ||
` | ||
); | ||
}); | ||
}); |
Oops, something went wrong.