mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:05:10 +00:00
LibJS: Add function default arguments
Adds the ability for function arguments to have default values. This works for standard functions as well as arrow functions. Default values are not printed in a <function>.toString() call, as nodes cannot print their source string representation.
This commit is contained in:
parent
751f813f6a
commit
5e66f1900b
8 changed files with 184 additions and 35 deletions
|
@ -670,17 +670,27 @@ void NullLiteral::dump(int indent) const
|
|||
|
||||
void FunctionNode::dump(int indent, const char* class_name) const
|
||||
{
|
||||
StringBuilder parameters_builder;
|
||||
parameters_builder.join(',', parameters());
|
||||
|
||||
print_indent(indent);
|
||||
printf("%s '%s(%s)'\n", class_name, name().characters(), parameters_builder.build().characters());
|
||||
printf("%s '%s'\n", class_name, name().characters());
|
||||
if (!m_parameters.is_empty()) {
|
||||
print_indent(indent + 1);
|
||||
printf("(Parameters)\n");
|
||||
|
||||
for (auto& parameter : m_parameters) {
|
||||
print_indent(indent + 2);
|
||||
printf("%s\n", parameter.name.characters());
|
||||
if (parameter.default_value) {
|
||||
parameter.default_value->dump(indent + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m_variables.is_empty()) {
|
||||
print_indent(indent + 1);
|
||||
printf("(Variables)\n");
|
||||
|
||||
for (auto& variable : m_variables)
|
||||
variable.dump(indent + 2);
|
||||
}
|
||||
for (auto& variable : m_variables)
|
||||
variable.dump(indent + 2);
|
||||
print_indent(indent + 1);
|
||||
printf("(Body)\n");
|
||||
body().dump(indent + 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue