From 38038d710ba67d8b9d13a0228cb2e5d126463b14 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Wed, 3 Nov 2021 10:40:28 +0300 Subject: [PATCH] fix comment removal --- index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 887b30b..d39bb71 100644 --- a/index.js +++ b/index.js @@ -41,6 +41,13 @@ function transpile(parsed, indent, prefix) { return ''; } +function removeComments(code) { + // remove /* */ style comments, for now + code = code.replace(/\/\*(.*?)\*\//gs, ''); + code = code.split('\n').filter(c => !c.trim().startsWith('//')).join('\n'); + return code; +} + /** * @param {string} code */ @@ -52,9 +59,7 @@ function parse(code) { // were gonna end up with an ast of sorts anyways as a result, which we can then use instead of declares // sanitize stuff - code = code.split('\n').filter(c => !c.trim().startsWith('//')).join('\n'); - // remove /* */ style comments, for now - code = code.replace(/\/\*(.*?)(?=\*\/)/gs, ''); + code = removeComments(code); const elements = [];