From b0259581738ce73a5f161c7c82bcbf90d65cf11d Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 29 Jun 2024 15:41:04 -0400 Subject: [PATCH] comments in minifier --- build/safemin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/safemin.py b/build/safemin.py index 4f354a2..b1b710c 100644 --- a/build/safemin.py +++ b/build/safemin.py @@ -34,12 +34,13 @@ def minify(path: str): # - this minification is intended to be 100% safe, so working with multiline comments is asking for trouble # - the project doesn't use them as of writing this (except in test/), and it might as well stay that way raise Exception(f"no multiline comments allowed! (offending file: {path})") - + if re.search(r'\\$', contents, flags=re.MULTILINE) != None: # '\' allows for multiline strings, which would require reverting to processing syntax line by line to support them raise Exception(f"no escaping newlines! (offending file: {path})") - # drop the comments + # drop the comments, unless the line has quotes, because quotes are scary + # (quotes are scary since we could actually be inside a string: "-- ..." shouldn't get deleted) # -> whitespace before '--' and anything after that, which includes '---' comments minified = re.sub(r'\s*--+(?!.*[\'"]).*', '', contents)