Skip to content

Commit

Permalink
Revert export generator changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 3, 2024
1 parent 96666c5 commit 8a4b7fc
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
.WithModifiers(TokenList(new[] { Token(SyntaxKind.StaticKeyword) }))
.WithBody(Block(registerStatements));

// HACK: protect the code from trimming by putting it behind a comparison we know
// will always evaluate to false at runtime, but the linker can't see through at
// build time. It seems there's no attribute to block trimming of a method?
// when we are running code generated by .NET8 on .NET7 runtime we need to auto initialize the assembly, because .NET7 doesn't call the registration from JS
// this also keeps the code protected from trimming
MemberDeclarationSyntax initializerMethod = MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(selfInitName))
.WithAttributeLists(List(new[]{
AttributeList(SingletonSeparatedList(Attribute(IdentifierName(Constants.ModuleInitializerAttributeGlobal)))),
Expand All @@ -254,8 +253,8 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
}))
.WithBody(Block(
IfStatement(BinaryExpression(SyntaxKind.EqualsExpression,
IdentifierName("System.Runtime.InteropServices.JavaScript.JSHost.GlobalThis"),
LiteralExpression(SyntaxKind.NullLiteralExpression)),
IdentifierName("Environment.Version.Major"),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(7))),
Block(SingletonList<StatementSyntax>(
ExpressionStatement(InvocationExpression(IdentifierName(initializerName))))))));

Expand Down

0 comments on commit 8a4b7fc

Please sign in to comment.