Skip to content

Commit

Permalink
Add variable JS
Browse files Browse the repository at this point in the history
  • Loading branch information
uga-rosa committed Dec 23, 2023
1 parent 7afbd9b commit 9493831
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions denops/denippet/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,11 @@ register("VIM", async (denops, text) => {
register("LUA", async (denops, text) => {
return String(await denops.call("luaeval", text).catch(() => ""));
});

register("JS", (_denops, text) => {
try {
return String(eval(text));
} catch {
return "";
}
});
8 changes: 8 additions & 0 deletions denops/denippet/variable_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,13 @@ test({
},
});
}

await t.step({
name: "JS",
fn: async () => {
const actual = await V.call(denops, "JS", "(() => 1 + 1)()");
assertEquals(actual, "2");
},
});
},
});
4 changes: 4 additions & 0 deletions doc/denippet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ Variables ~
${LUA:math.floor(1.234)}
// -> 1
<
- JS Eval default string as JavaScript. >
${JS:(() => 1 + 1)()}
// -> 2
<

Transformer ~

Expand Down

0 comments on commit 9493831

Please sign in to comment.