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

Reduce verbosity in template.stylesheets generated code #4151

Open
nolanlawson opened this issue Apr 15, 2024 · 0 comments
Open

Reduce verbosity in template.stylesheets generated code #4151

nolanlawson opened this issue Apr 15, 2024 · 0 comments

Comments

@nolanlawson
Copy link
Contributor

Currently our generated code for templates looks like this:

tmpl.stylesheets = [];
if (_implicitStylesheets) {
  tmpl.stylesheets.push.apply(tmpl.stylesheets, _implicitStylesheets);
}
if (_implicitScopedStylesheets) {
  tmpl.stylesheets.push.apply(tmpl.stylesheets, _implicitScopedStylesheets);
}

This is a lot of boilerplate. Now that all our supported browsers support rest/spread, we can probably do something like this instead:

tmpl.stylesheets = [
  ...(_implicitStylesheets ?? EmptyArray),
  ...(_implicitScopedStylesheets ?? EmptyArray)
];

(where EmptyArray is some shared constant that resolves to [] – to avoid excessive GC).

This might have some mild perf and compat considerations, so this would need to be done carefully.

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

No branches or pull requests

1 participant