From f317a6c2eb0ba8bffb6d42bf159e18c0163fdfa9 Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Tue, 10 Jan 2023 16:04:35 +0900 Subject: [PATCH 1/2] add svelte and vue support --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0d9de9d..8222848 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,12 @@ const give = (data) => const init = async () => { const [path, filetype] = process.argv.slice(2); - const lang = filetype[0] === "t" ? Lang.TYPESCRIPT : Lang.JAVASCRIPT; + const lang = (() => { + if (filetype === "svelte") return Lang.SVELTE; + if (filetype === "vue") return Lang.VUE; + if (filetype[0] === "t") return Lang.TYPESCRIPT; + return Lang.JAVASCRIPT; + })(); const contents = await receive(); const emitter = importCost(path, contents, lang); From 141f271eb1afdea3b8af1fc880fcdba0a86dcde5 Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Thu, 12 Jan 2023 09:56:53 +0900 Subject: [PATCH 2/2] fix detecting lang --- index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 8222848..74154c2 100644 --- a/index.js +++ b/index.js @@ -14,14 +14,16 @@ const receive = async () => { const give = (data) => process.nextTick(() => process.stdout.write(`${JSON.stringify(data)}|`)); +const filetypes = new Map([ + ["j", Lang.JAVASCRIPT], + ["s", Lang.SVELTE], + ["t", Lang.TYPESCRIPT], + ["v", Lang.VUE], +]); + const init = async () => { const [path, filetype] = process.argv.slice(2); - const lang = (() => { - if (filetype === "svelte") return Lang.SVELTE; - if (filetype === "vue") return Lang.VUE; - if (filetype[0] === "t") return Lang.TYPESCRIPT; - return Lang.JAVASCRIPT; - })(); + const lang = filetypes.get(filetype[0]); const contents = await receive(); const emitter = importCost(path, contents, lang);