Compare commits

..

6 Commits

Author SHA1 Message Date
bleck9999
b0233b796e Merge pull request #78 from FlyingBananaTree/patch-1
Add 16.0.0 pkg1
2023-02-21 21:25:49 +00:00
FlyingBananaTree
99b45cac7b Correct indent 2023-02-21 20:44:30 +00:00
FlyingBananaTree
ee212a5156 Add 16.0.0 pkg1 2023-02-21 19:50:24 +00:00
suchmememanyskill
dfe42c3991 Merge pull request #71 from FlyingBananaTree/patch-1
Add 15.0.0 pkg1
2022-10-11 23:32:33 +02:00
FlyingBananaTree
c895266f34 Add 15.0.0 pkg1
Just a quick pr for new pkg1
2022-10-11 16:01:54 +01:00
bleck9999
6881075fc8 fix auto-replace breaking byte arrays
also sneak some wording changes in
2022-04-30 19:58:42 +01:00
2 changed files with 14 additions and 9 deletions

View File

@@ -44,7 +44,9 @@ static const pkg1_id_t _pkg1_ids[] = {
{ "20210607", 11}, //12.1.0
{ "20210805", 12}, //13.0.0 - 13.2.0
{ "20220105", 12}, //13.2.1
{ "20220209", 13}, //14.0.0+
{ "20220209", 13}, //14.0.0 - 14.1.2
{ "20220801", 14}, //15.0.0 - 15.0.1
{ "20230111", 15}, //16.0.0+
{ NULL } //End.
};

View File

@@ -1,7 +1,6 @@
# Copyright (c) 2021 bleck9999
# https://github.com/bleck9999/ts-minifier
# Version: e276c417
# Version: 49befe92
import argparse
import itertools
import logging
@@ -153,12 +152,12 @@ def minify(script: Code, userobjects, usages):
# minus the amount of characters it would take to define an alias (len(alias)+len(func)+2), with the 2 being for the
# equals and the whitespace needed for a definition
# the same principle also applies to introducing a variable for string literals, though since a literal requires
# having "s around it then it's uses*(len(str)+2) - (len(minName)+len(str)+4)
# having "s around it then it's uses*(len(str)+2) - (len(minName)+len(str)+4) instead
# ^ 2 for = and whitespace, 2 for ""
#
# obviously for a rename you're already defining it so it's just the difference between lengths multiplied by uses
short_idents = [x for x in (ascii_letters + '_')] + [x[0] + x[1] for x in
itertools.product(ascii_letters + '_', repeat=2)]
short_idents = [x for x in (ascii_letters + '_')] + \
[x[0] + x[1] for x in itertools.product(ascii_letters + '_', repeat=2)]
short_idents.pop(short_idents.index("if"))
mcode = script.rawcode
aliases = []
@@ -267,6 +266,10 @@ def minify(script: Code, userobjects, usages):
logging.info("Introducing variables for reused literals" if auto_replace else
"Checking for reused literals")
for string in str_reuse:
if string == '"BYTE[]"':
# the type specifier for byte arrays is special because it has to be a literal
# if it's a variable then it tries to treat it as a string array then shits the bed if the other items are not strings
continue
tmpcode = ""
candidates = short_idents
minName = ""
@@ -341,13 +344,13 @@ def minify(script: Code, userobjects, usages):
mcode = tmpcode + mcode[bound + diff + len(minName):]
aliases.append(f"{minName}={uint} ")
else:
logging.warning(f"Not introducing variable for string {uint} reused {uses} times "
logging.warning(f"Not introducing variable for integer {uint} reused {uses} times "
f"(would save {savings} bytes)")
else:
logging.info(f"Not introducing variable for string {uint} reused {uses} times "
logging.info(f"Not introducing variable for integer {uint} reused {uses} times "
f"(would save {savings} bytes)")
else:
logging.info(f"Not introducing variable for int {uint} (only used once)")
logging.info(f"Not introducing variable for integer {uint} (only used once)")
logging.info("Reintroducing REQUIREs")
mcode = "".join([x[2] for x in script.comments]) + "".join(aliases) + mcode