Skip to content

Should we allow struct expressions? #58

Description

@JLHwung

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions