Skip to content

Commit

Permalink
Loop LocalAssignmentExpression declarative keyword fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeloD2022 committed Aug 30, 2022
1 parent bdcf325 commit 51f884b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/jsxer/nodes/ListExpression.cpp
@@ -1,4 +1,5 @@
#include "ListExpression.h"
#include "LocalAssignmentExpression.h"

void ListExpression::parse() {
arguments = decoders::d_children(reader);
Expand All @@ -16,6 +17,10 @@ string ListExpression::to_string() {

// TODO: fix declarations
for (int i = 0; i < arguments.size(); ++i) {
if (for_loop && i > 0){
((LocalAssignmentExpression *) arguments[i])->suppress_declarative_keyword(true);
}

result += arguments[i]->to_string() + (i + 1 == arguments.size() ? "" : delimiter);
}

Expand Down
8 changes: 6 additions & 2 deletions src/jsxer/nodes/LocalAssignmentExpression.cpp
Expand Up @@ -10,7 +10,7 @@ void LocalAssignmentExpression::parse() {
}

string LocalAssignmentExpression::to_string() {
string result = declaration ? "var " : "";
string result = (declaration && !declarative_suppress) ? "var " : "";

if (shorthand) {
auto* b = (BinaryExpression*) expression;
Expand All @@ -25,4 +25,8 @@ string LocalAssignmentExpression::to_string() {
}

return result;
}
}

void LocalAssignmentExpression::suppress_declarative_keyword(bool value) {
declarative_suppress = value;
}
3 changes: 3 additions & 0 deletions src/jsxer/nodes/LocalAssignmentExpression.h
Expand Up @@ -19,10 +19,13 @@ namespace jsxer { namespace nodes {

string to_string() override;

void suppress_declarative_keyword(bool value);

private:
string var_name;
string literal;
AstNode* expression = nullptr;
bool declarative_suppress = false;
bool shorthand = false;
bool declaration = false;
};
Expand Down

1 comment on commit 51f884b

@WeedyWeedSmoker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit breaks decompilation of some more complex jsxbin scripts with a segmentation fault

Please sign in to comment.