Skip to content

Commit 21ecd6e

Browse files
author
AzureAD\ErikvanOorspronk
committed
418: Fixed issue where 2 getters with the same name where 1 of the getters is static resulted in "JS1323: Duplicate class element name"
1 parent 3844d64 commit 21ecd6e

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.21.13 (24 February 2025)
4+
- Fixed issue where 2 getters with the same name where 1 of the getters is static resulted in "JS1323: Duplicate class element name"
5+
36
## v1.21.12 (21 February 2025)
47
- Fixed issue where null coalescing operator combined with "||" or "&&" resulted in syntax errors.
58

src/NUglify.Tests/JavaScript/Classes.cs

+6
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ public void ClassErrors()
4343
{
4444
TestHelper.Instance.RunErrorTest(JSError.NoIdentifier, JSError.NoIdentifier, JSError.NoLeftCurly, JSError.NoRightCurly);
4545
}
46+
47+
[Test]
48+
public void ClassNormalAndStaticProperty()
49+
{
50+
TestHelper.Instance.RunErrorTest();
51+
}
4652
}
4753
}

src/NUglify.Tests/NUglify.Tests.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,9 @@
17111711
<Content Include="TestData\JS\Expected\Classes\ClassExpr.js">
17121712
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17131713
</Content>
1714+
<Content Include="TestData\JS\Expected\Classes\ClassNormalAndStaticProperty.js">
1715+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1716+
</Content>
17141717
<Content Include="TestData\JS\Expected\Comprehensions\ArrayComp.js">
17151718
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17161719
</Content>
@@ -3151,6 +3154,9 @@
31513154
<Content Include="TestData\JS\Input\Classes\ClassExpr.js">
31523155
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31533156
</Content>
3157+
<Content Include="TestData\JS\Input\Classes\ClassNormalAndStaticProperty.js">
3158+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3159+
</Content>
31543160
<Content Include="TestData\JS\Input\Comprehensions\ArrayComp.js">
31553161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31563162
</Content>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Foo{static get bar(){return""}get bar(){return Foo.bar()}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo
2+
{
3+
static get bar() { return ""; }
4+
get bar() { return Foo.bar(); }
5+
}

src/NUglify/JavaScript/Visitors/AnalyzeNodeVisitor.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -2026,17 +2026,13 @@ public override void Visit(ClassNode node)
20262026

20272027
static string ClassElementKeyName(FunctionType funcType, string name, bool isStatic)
20282028
{
2029-
switch (funcType)
2030-
{
2031-
case FunctionType.Getter:
2032-
return "get_" + name;
2033-
2034-
case FunctionType.Setter:
2035-
return "set_" + name;
2029+
var funcTypeName = funcType switch {
2030+
FunctionType.Getter => "get_",
2031+
FunctionType.Setter => "set_",
2032+
_ => "method_"
2033+
};
20362034

2037-
default:
2038-
return (isStatic ? "static_" : string.Empty) + "method_" + name;
2039-
}
2035+
return $"{(isStatic ? "static_" : string.Empty)}{funcTypeName}{name}";
20402036
}
20412037

20422038
public override void Visit(ComprehensionNode node)

src/NUglify/NUglify.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<RepositoryType>git</RepositoryType>
1919
<RepositoryUrl>git://github.com/trullock/NUglify</RepositoryUrl>
2020
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.0</NetStandardImplicitPackageVersion>
21-
<Version>1.21.12</Version>
21+
<Version>1.21.13</Version>
2222
<PackageLicenseExpression></PackageLicenseExpression>
2323
<LangVersion>latest</LangVersion>
2424
</PropertyGroup>

0 commit comments

Comments
 (0)