mirror of
https://github.com/zadam/trilium.git
synced 2026-01-03 13:14:24 +01:00
test(script/jsx): basic JSX processing
This commit is contained in:
parent
22a83d9f82
commit
645557b505
@ -1,9 +1,11 @@
|
||||
import { trimIndentation } from "@triliumnext/commons";
|
||||
|
||||
import becca from "../becca/becca.js";
|
||||
import { note, NoteBuilder } from "../test/becca_mocking.js";
|
||||
import cls from "./cls.js";
|
||||
import { executeBundle, getScriptBundle } from "./script.js";
|
||||
import BBranch from "../becca/entities/bbranch.js";
|
||||
import BNote from "../becca/entities/bnote.js";
|
||||
import { note, NoteBuilder } from "../test/becca_mocking.js";
|
||||
import cls from "./cls.js";
|
||||
import { buildJsx, executeBundle, getScriptBundle } from "./script.js";
|
||||
|
||||
|
||||
describe("Script", () => {
|
||||
@ -84,3 +86,19 @@ describe("Script", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("JSX building", () => {
|
||||
it("processes basic JSX", () => {
|
||||
const script = trimIndentation`\
|
||||
function MyComponent() {
|
||||
return <p>Hello world.</p>;
|
||||
}
|
||||
`;
|
||||
const expected = trimIndentation`\
|
||||
const _jsxFileName = "";function MyComponent() {
|
||||
return api.preact.h('p', {__self: this, __source: {fileName: _jsxFileName, lineNumber: 2}}, "Hello world." );
|
||||
}
|
||||
`;
|
||||
expect(buildJsx(script).code).toStrictEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@ -198,8 +198,7 @@ export function getScriptBundle(note: BNote, root: boolean = true, scriptEnv: st
|
||||
let scriptContent = note.getContent();
|
||||
|
||||
if (note.isJsx()) {
|
||||
console.log("GOT JSX!!!");
|
||||
scriptContent = buildJsx(note).code;
|
||||
scriptContent = buildJsx(scriptContent).code;
|
||||
}
|
||||
|
||||
bundle.script += `
|
||||
@ -219,8 +218,7 @@ return module.exports;
|
||||
return bundle;
|
||||
}
|
||||
|
||||
function buildJsx(jsxNote: BNote) {
|
||||
const contentRaw = jsxNote.getContent();
|
||||
export function buildJsx(contentRaw: string | Buffer) {
|
||||
const content = Buffer.isBuffer(contentRaw) ? contentRaw.toString("utf-8") : contentRaw;
|
||||
return transform(content, {
|
||||
transforms: ["jsx"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user