Skip to content

feat(minifier): fold complicated array literals passed to unary +#8944

Merged
graphite-app[bot] merged 1 commit intomainfrom
02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_
Feb 7, 2025
Merged

feat(minifier): fold complicated array literals passed to unary +#8944
graphite-app[bot] merged 1 commit intomainfrom
02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Feb 7, 2025

Array literals never have Symbol.toPrimitive / toString / valueOf overriden (assuming the prototype is not modified).
So for array literals Array::toString is used for ToPrimitive. Array::toString calls Array::join.
If there's only one element, Array::join returns the stringified first element. If there's more than one element, the return value of it always contains , .

References

Copy link
Member Author

sapphi-red commented Feb 7, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Feb 7, 2025
@sapphi-red sapphi-red marked this pull request as ready for review February 7, 2025 05:32
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 7, 2025

CodSpeed Performance Report

Merging #8944 will not alter performance

Comparing 02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_ (56575b2) with main (2c4f004)

Summary

✅ 33 untouched benchmarks

@sapphi-red sapphi-red marked this pull request as draft February 7, 2025 05:35
@sapphi-red sapphi-red marked this pull request as ready for review February 7, 2025 05:49
@sapphi-red sapphi-red force-pushed the 02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_ branch from d744f22 to 93a3d46 Compare February 7, 2025 05:52
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Feb 7, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 7, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 02-06-feat_minifier_fold_simple_literals_passed_to_unary_ branch from 2b20341 to 6357a2b Compare February 7, 2025 13:31
graphite-app bot pushed a commit that referenced this pull request Feb 7, 2025
…8944)

Array literals never have `Symbol.toPrimitive` / `toString` / `valueOf` overriden (assuming the prototype is not modified).
So for array literals `Array::toString` is used for `ToPrimitive`. `Array::toString` calls `Array::join`.
If there's only one element, `Array::join` returns the stringified first element. If there's more than one element, the return value of it always contains `,` .

**References**
- [Spec of unary `+`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-unary-plus-operator-runtime-semantics-evaluation)
- [Spec of `ToPrimitive`](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toprimitive)
- [Spec of `Array::toString`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.tostring)
- [Spec of `Array::join`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join)
@graphite-app graphite-app bot force-pushed the 02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_ branch from 93a3d46 to cdc62a0 Compare February 7, 2025 13:32
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 7, 2025
sapphi-red added a commit that referenced this pull request Feb 7, 2025
…8944)

Array literals never have `Symbol.toPrimitive` / `toString` / `valueOf` overriden (assuming the prototype is not modified).
So for array literals `Array::toString` is used for `ToPrimitive`. `Array::toString` calls `Array::join`.
If there's only one element, `Array::join` returns the stringified first element. If there's more than one element, the return value of it always contains `,` .

**References**
- [Spec of unary `+`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-unary-plus-operator-runtime-semantics-evaluation)
- [Spec of `ToPrimitive`](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toprimitive)
- [Spec of `Array::toString`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.tostring)
- [Spec of `Array::join`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join)
@sapphi-red sapphi-red force-pushed the 02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_ branch from cdc62a0 to c280d23 Compare February 7, 2025 15:13
@sapphi-red sapphi-red force-pushed the 02-06-feat_minifier_fold_simple_literals_passed_to_unary_ branch from 6357a2b to 7ec8a28 Compare February 7, 2025 15:13
…8944)

Array literals never have `Symbol.toPrimitive` / `toString` / `valueOf` overriden (assuming the prototype is not modified).
So for array literals `Array::toString` is used for `ToPrimitive`. `Array::toString` calls `Array::join`.
If there's only one element, `Array::join` returns the stringified first element. If there's more than one element, the return value of it always contains `,` .

**References**
- [Spec of unary `+`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-unary-plus-operator-runtime-semantics-evaluation)
- [Spec of `ToPrimitive`](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toprimitive)
- [Spec of `Array::toString`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.tostring)
- [Spec of `Array::join`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join)
@graphite-app graphite-app bot force-pushed the 02-06-feat_minifier_fold_simple_literals_passed_to_unary_ branch from 7ec8a28 to 14462be Compare February 7, 2025 15:36
@graphite-app graphite-app bot force-pushed the 02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_ branch from c280d23 to 56575b2 Compare February 7, 2025 15:36
Base automatically changed from 02-06-feat_minifier_fold_simple_literals_passed_to_unary_ to main February 7, 2025 15:42
@graphite-app graphite-app bot merged commit 56575b2 into main Feb 7, 2025
26 checks passed
@graphite-app graphite-app bot deleted the 02-06-feat_minifier_fold_complicated_array_literals_passed_to_unary_ branch February 7, 2025 15:45
Dunqing pushed a commit that referenced this pull request Feb 10, 2025
…8944)

Array literals never have `Symbol.toPrimitive` / `toString` / `valueOf` overriden (assuming the prototype is not modified).
So for array literals `Array::toString` is used for `ToPrimitive`. `Array::toString` calls `Array::join`.
If there's only one element, `Array::join` returns the stringified first element. If there's more than one element, the return value of it always contains `,` .

**References**
- [Spec of unary `+`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-unary-plus-operator-runtime-semantics-evaluation)
- [Spec of `ToPrimitive`](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toprimitive)
- [Spec of `Array::toString`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.tostring)
- [Spec of `Array::join`](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant