Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Aug 8, 2018

Fixes #26279

@ghost ghost requested a review from sandersn August 8, 2018 00:17
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a couple of small cleanup items.

}

function isSpreadableProperty(prop: Symbol): boolean {
// We approximate own properties as non-methods plus methods that are inside the object literal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment should be jsdoc.

const isPrivate = getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected);
const isSetOnlyAccessor = prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor);
if (!inNamesToRemove && !isPrivate && !isClassMethod(prop) && !isSetOnlyAccessor) {
if (!names.has(prop.escapedName) && !(getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected)) && isSpreadableProperty(prop)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to wrap this line. It’s not readable on github’s default style sheet.

// We approximate own properties as non-methods plus methods that are inside the object literal
return prop.flags & (SymbolFlags.Method | SymbolFlags.GetAccessor)
? !prop.declarations.some(decl => isClassLike(decl.parent))
: !(prop.flags & SymbolFlags.SetAccessor); // Setter without getter is not spreadable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Setter is actually spreadable and results in undefined:

({
    foo: 1,
    ...{set foo(v) {}}
}).foo === undefined;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open a new issue for that? It’s different from skipping things that come from classes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. It seemed to me like this condition was added in this PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I thought so too, but it's just adding accessors to the list of things that are skipped when they come from a class declaration.

@ghost ghost merged commit 639fdcc into master Aug 9, 2018
@ghost ghost deleted the spreadClassGetter branch August 9, 2018 22:34
errendir added a commit to errendir/TypeScript that referenced this pull request Aug 11, 2018
* origin/master: (283 commits)
  Don't error on destructure of private property with computed property syntax (microsoft#26360)
  getDefaultExportInfo: Use `getImmediateAliasedSymbol` instead of `getAliasedSymbol` (microsoft#26364)
  review comments
  restore old algorithm
  Dont use baseURL relative absolute paths in declaration emit, use absolute paths in bundle emit (microsoft#26341)
  Update user baselines (microsoft#26358)
  Don't store @template constraint in a TypeParameterDeclaration node (microsoft#26283)
  fixAddMissingMember: Support interface and don't crash on type parameter (microsoft#25995)
  Don't include class getter in spread type (microsoft#26287)
  Don't crash on computed property in destructure (microsoft#26334)
  Check the ambientness of a symbol name before attempting to trim it (microsoft#26312)
  Still generate signatures in SkipContextSensitive mode just to match on return types (microsoft#25937)
  fix handling if there is no commonPrefix
  Actually add sorting of elaboration text to user baselines
  Ping ryan instead of mohammed for user PRs now
  handle failed lookups
  make it work for root directory
  really, really fix test(?)
  add test
  fix commonPrefix handling
  ...
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants