-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
object spread: also drop non-nullish constants (e.g. { ...true }
)
#1141
object spread: also drop non-nullish constants (e.g. { ...true }
)
#1141
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec says:
PropertyDefinition : ... AssignmentExpression
- Let exprValue be the result of evaluating AssignmentExpression.
- Let fromValue be ? GetValue(exprValue).
- Let excludedNames be a new empty List.
- Return ? CopyDataProperties(object, fromValue, excludedNames).
CopyDataProperties
says
7.3.26 CopyDataProperties ( target, source, excludedItems )
The abstract operation CopyDataProperties takes arguments target (an Object), source (an ECMAScript language value), and excludedItems (a List of property keys). It performs the following steps when called:
- If source is undefined or null, return target.
- Let from be ! ToObject(source).
- Let keys be ? from.[[OwnPropertyKeys]]().
- For each element nextKey of keys, do
a. Let excluded be false.
b. For each element e of excludedItems, do
i. If SameValue(e, nextKey) is true, then- Set excluded to true.
c. If excluded is false, then
i. Let desc be ? from.[[GetOwnProperty]](nextKey).
ii. If desc is not undefined and desc.[[Enumerable]] is true, then - Let propValue be ? Get(from, nextKey).
- Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
- Set excluded to true.
- Return target.
The important part is:
2. Let from be ! [ToObject](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-toobject)(source).
3. Let keys be ? from.[[OwnPropertyKeys]]().
ToObject
of a primitive returns a new object instance (eg, new Number(1)
, which is a Number
instance and not a number primitive). This also applies when spreading a "string"
, and String
instances are the only primitive class which has an own-property, which is what spread operator is iterating over.
Just realized that it stopped droping |
51646fc
to
07b8d32
Compare
Alright, I've decided to update it so that it also drops |
This is a follow-up to 6f04338 (terser#1004)
07b8d32
to
2e226c1
Compare
This looks great, is it good to merge @jridgewell ? |
So, what's the plan for this MR? |
This looks good. I kind of dropped the ball here, sorry! |
This is a follow-up to 6f04338 (#1004)
Note, as I said in #1004, I have not yet found where in the spec it says how spreading constants other than
undefined
&null
should be handled.