Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed JavaScript assignment operators generating error statements #250

Merged
merged 3 commits into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ public JavaScriptCodeGenerator() {
};

private static final String[] BINARY_TOKENS = {
"!=", "!==", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "+=", ",",
"-", "-=", "/", "/=", "<", "<<", ">>=", "<=", "=", "==", "===",
">", ">=", ">>", ">>=", ">>>", ">>>=", "^", "^=", "|", "|=", "||",
"!=", "!==", "%", "&", "&&", "*", "+", ",",
"-", "/", "<", "<<", "<=", "=", "==", "===",
">", ">=", ">>", ">>>", "^", "|", "||",
"in", "instanceof"
};

private static final String[] ASSIGNMENT_TOKENS = {
"=", "+=", "-=", "*=", "/=", "%=", "**=", "<<=", ">>=", ">>>=", "&=", "^=", "|=", "&&=",
"||=", "??=",
};


@Override
public String generate(SourceOfRandomness random, GenerationStatus status) {
this.status = status;
Expand Down Expand Up @@ -117,7 +123,8 @@ private String generateExpression(SourceOfRandomness random) {
this::generateFunctionNode,
this::generatePropertyNode,
this::generateIndexNode,
this::generateArrowFunctionNode
this::generateArrowFunctionNode,
this::generateAssignmentNode
)).apply(random);
}
expressionDepth--;
Expand Down Expand Up @@ -330,4 +337,15 @@ private String generateVarNode(SourceOfRandomness random) {
private String generateWhileNode(SourceOfRandomness random) {
return "while (" + generateExpression(random) + ")" + generateBlock(random);
}

private String generateAssignmentNode(SourceOfRandomness random) {
String token = random.choose(ASSIGNMENT_TOKENS);
String lhs = random.choose(Arrays.<Function<SourceOfRandomness, String>>asList(
this::generateIdentNode,
this::generateIndexNode,
this::generatePropertyNode
)).apply(random);
String rhs = generateExpression(random);
return lhs + " " + token + " " + rhs + ";";
}
}
Loading