From 66ed7c1f30d1ba6569efa114c9d90ccac45fb86a Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 26 Sep 2021 00:14:15 -0700 Subject: Basic macro impl --- examples/macros/example.js | 4 ++++ examples/macros/mystery-box.tsx | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 examples/macros/example.js create mode 100644 examples/macros/mystery-box.tsx (limited to 'examples') diff --git a/examples/macros/example.js b/examples/macros/example.js new file mode 100644 index 000000000..d612c1fa4 --- /dev/null +++ b/examples/macros/example.js @@ -0,0 +1,4 @@ +// source code +import { mysteryBox } from "macro:./mystery-box"; + +export default "You roll! " + mysteryBox(123); diff --git a/examples/macros/mystery-box.tsx b/examples/macros/mystery-box.tsx new file mode 100644 index 000000000..9e72ee1c0 --- /dev/null +++ b/examples/macros/mystery-box.tsx @@ -0,0 +1,15 @@ +// macro code: +export function mysteryBox(node) { + const dice = Math.round(Math.random() * 100); + if (dice < 25) { + return ; + } else if (dice < 50) { + return ; + } else if (dice < 75) { + return ; + } else if (dice < 90) { + return ; + } else { + return ; + } +} -- cgit v1.2.3