Skip to content

Commit

Permalink
Don't export generic "Texts" constant from Texts.ts if there are no T…
Browse files Browse the repository at this point in the history
…exts class with NestedLocalTexts attribute, and there is another XYZTexts class with no prefix
  • Loading branch information
volkanceylan committed Nov 2, 2024
1 parent 619ffa1 commit a5e0efa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace texts {

}

export const Texts: typeof texts = proxyTexts({}, '', {
const Texts: typeof texts = proxyTexts({}, '', {
Db: {
Northwind: {
Category: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace texts {

}

export const Texts: typeof texts = proxyTexts({}, '', {
const Texts: typeof texts = proxyTexts({}, '', {
Db: {
Common: {
UserPreference: {}
Expand Down
1 change: 0 additions & 1 deletion common-features/src/extensions/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ declare namespace texts {
const PasswordStrengthRequireUppercase: string;
}
}
export declare const Texts: typeof texts;
export declare const BasicProgressDialogTexts: typeof texts.Site.BasicProgressDialog;
export declare const BulkServiceActionTexts: typeof texts.Site.BulkServiceAction;
export declare const ChangePasswordFormTexts: typeof texts.Forms.Membership.ChangePassword;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ protected void PreVisitTypeForTexts(TypeDefinition fromType)
#endif

AddNestedLocalTexts(fromType, prefix ?? "");
if (fromType.Name != "Texts" &&
fromType.Name.EndsWith("Texts", StringComparison.Ordinal) &&
if (fromType.Name.EndsWith("Texts", StringComparison.Ordinal) &&
!localTextNestedClasses.ContainsKey(fromType.Name))
{
localTextNestedClasses.Add(fromType.Name, prefix ?? "");
Expand Down Expand Up @@ -108,6 +107,10 @@ protected void GenerateTexts()
x.Split('.').All(p => SqlSyntax.IsValidIdentifier(p)))
.ToList();

bool exportTexts = localTextNestedClasses.ContainsKey("Texts") ||
(!localTextNestedClasses.ContainsKey("Texts") &&
!localTextNestedClasses.Any(x => string.IsNullOrEmpty(x.Value)));

if (list.Count > 0)
{
list.Sort(string.CompareOrdinal);
Expand Down Expand Up @@ -210,17 +213,19 @@ protected void GenerateTexts()
sb.AppendLine();
var proxyTexts = ImportFromQ("proxyTexts");

sb.Append($"export const Texts: typeof texts = {proxyTexts}({{}}, '', ");
sb.Append($"{(exportTexts ? "export ": "")}const Texts: typeof texts = {proxyTexts}({{}}, '', ");
jw.Flush();
sb.Append(string.Join("\n", jwBuilder.ToString().Split('\n')));
sb.AppendLine(") as any;");
}
else
{
sb.AppendLine($"export const Texts = {{}} as const;");
sb.AppendLine($"{(exportTexts ? "export " : "")}const Texts = {{}} as const;");
}

foreach (var nested in localTextNestedClasses.OrderBy(x => x.Key, StringComparer.InvariantCultureIgnoreCase))
foreach (var nested in localTextNestedClasses
.Where(x => x.Key != "Texts")
.OrderBy(x => x.Key, StringComparer.InvariantCultureIgnoreCase))
{
if (string.IsNullOrEmpty(nested.Value))
{
Expand Down

0 comments on commit a5e0efa

Please sign in to comment.