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

Should we allow struct expressions? #58

Open
JLHwung opened this issue Nov 14, 2024 · 0 comments
Open

Should we allow struct expressions? #58

JLHwung opened this issue Nov 14, 2024 · 0 comments

Comments

@JLHwung
Copy link

JLHwung commented Nov 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant