Open
Description
In #38 we removed the struct expressions for grammar conflict case, however, I do believe the non-shared StructExpression would be useful:
For example it can serve as a parameter initializer:
function parse(
input,
options = struct DefaultOption {
static scriptType = guessScriptType(input);
static version = 'es2025';
}
) { }
Note that because the DefaultOption
struct depends on the input
, it can't be hoisted to the top level. A workaround is to move it into the function body, which basically desugars the parameter initializer, plus we can't use ternary operator because struct expression is currently not a thing:
function parse(
input,
options
) {
if (options === undefined) {
struct DefaultOption {
static scriptType = guessScriptType(input);
static version = 'es2025';
}
options = DefaultOption;
}
}
In practise, the options
could be accessed frequently, so a fixed layout will definitely benefit the performance, and avoid performance regression from polymorphism.
Metadata
Metadata
Assignees
Labels
No labels