aboutsummaryrefslogtreecommitdiff
path: root/examples/macros/matchInFile.tsx
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-27 01:34:12 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-27 01:34:12 -0700
commit9e0511995ab516cc73bfb54d4b6a9721de2ce823 (patch)
tree24653d460492fbff8afe90cbfa0566042cef6b04 /examples/macros/matchInFile.tsx
parenta113603f1009e6ee8bf64ea4453e9513b72b4350 (diff)
parent62d51f7d2e636099f03abcb879475d1193c4022d (diff)
downloadbun-9e0511995ab516cc73bfb54d4b6a9721de2ce823.tar.gz
bun-9e0511995ab516cc73bfb54d4b6a9721de2ce823.tar.zst
bun-9e0511995ab516cc73bfb54d4b6a9721de2ce823.zip
Merge branch 'jarred/ast-again'bun-v0.0.25
Diffstat (limited to 'examples/macros/matchInFile.tsx')
-rw-r--r--examples/macros/matchInFile.tsx20
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/macros/matchInFile.tsx b/examples/macros/matchInFile.tsx
new file mode 100644
index 000000000..a73f7ee8b
--- /dev/null
+++ b/examples/macros/matchInFile.tsx
@@ -0,0 +1,20 @@
+// macro code
+export function matchInFile(callExpression) {
+ const [filePathNode, matcherNode] = callExpression.arguments;
+ const filePath: string = filePathNode.get();
+ const matcher: RegExp = matcherNode.get();
+ const file: string = Bun.readFile(Bun.cwd + filePath);
+
+ return (
+ <array>
+ {file
+ .split("\n")
+ .map((line) => line.match(matcher))
+ .filter(Boolean)
+ .reverse()
+ .map((line) => (
+ <string value={line[0]} />
+ ))}
+ </array>
+ );
+}