Skip to content

Commit

Permalink
Simplified generated code for enum on decode-minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril-CdV committed Feb 7, 2025
1 parent 7a7dff0 commit 51b717c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,17 @@ function buildEnum(ref, enm) {
comment.push((config.forceEnumString ? "@property {string} " : "@property {number} ") + key + "=" + val + " " + (enm.comments[key] || key + " value"));
});
pushComment(comment);
if (!ref && config.es6)
push("export const " + escapeName(enm.name) + " = " + escapeName(ref) + "." + escapeName(enm.name) + " = (() => {");
else
push(escapeName(ref) + "." + escapeName(enm.name) + " = (function() {");
++indent;

if (!config["decode-minimal"]) {
if (!ref && config.es6)
push("export const " + escapeName(enm.name) + " = " + escapeName(ref) + "." + escapeName(enm.name) + " = (() => {");
else
push(escapeName(ref) + "." + escapeName(enm.name) + " = (function() {");

++indent;
push((config.es6 ? "const" : "var") + " valuesById = {}, values = Object.create(valuesById);");
var aliased = [];
Object.keys(enm.values).forEach(function(key) {
Object.keys(enm.values).forEach(function (key) {
var valueId = enm.values[key];
var val = config.forceEnumString ? JSON.stringify(key) : valueId;
if (aliased.indexOf(valueId) > -1)
Expand All @@ -847,6 +850,7 @@ function buildEnum(ref, enm) {
}
});
push("return values;");
--indent;
push("})();");
--indent;
push("})();");
}
}

0 comments on commit 51b717c

Please sign in to comment.