@zenstackhq/language 3.4.0-beta.1 → 3.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7737,11 +7737,7 @@ var ZModelCodeGenerator = class {
7737
7737
  return `${this.quote}${trimmedVal}${this.quote}`;
7738
7738
  }
7739
7739
  _generateModel(ast) {
7740
- return `${ast.imports.map((d) => this.generate(d)).join("\n")}${ast.imports.length > 0 ? "\n\n" : ""}${ast.declarations.sort((a, b) => {
7741
- if (a.$type === "Enum" && b.$type !== "Enum") return 1;
7742
- if (a.$type !== "Enum" && b.$type === "Enum") return -1;
7743
- return 0;
7744
- }).map((d) => this.generate(d)).join("\n\n")}`;
7740
+ return `${ast.imports.map((d) => this.generate(d)).join("\n")}${ast.imports.length > 0 ? "\n\n" : ""}${ast.declarations.map((d) => this.generate(d)).join("\n\n")}`;
7745
7741
  }
7746
7742
  _generateDataSource(ast) {
7747
7743
  return `datasource ${ast.name} {
@@ -7752,12 +7748,20 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
7752
7748
  return `import ${this.quotedStr(ast.path)}`;
7753
7749
  }
7754
7750
  _generateEnum(ast) {
7755
- return `enum ${ast.name} {
7751
+ const comments = `${ast.comments.join("\n")}
7752
+ `;
7753
+ return `${ast.comments.length > 0 ? comments : ""}enum ${ast.name} {
7756
7754
  ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
7757
7755
  }`;
7758
7756
  }
7759
7757
  _generateEnumField(ast) {
7760
- return `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
7758
+ const fieldLine = `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
7759
+ if (ast.comments.length === 0) {
7760
+ return fieldLine;
7761
+ }
7762
+ const commentLines = ast.comments.map((c, i) => i === 0 ? c : this.indent + c);
7763
+ return `${commentLines.join("\n")}
7764
+ ${this.indent}${fieldLine}`;
7761
7765
  }
7762
7766
  _generateGenerator(ast) {
7763
7767
  return `generator ${ast.name} {