Skip to content

Commit

Permalink
analyzer: merge property info from constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Oct 17, 2018
1 parent 6c56e19 commit a1d60e7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

<!-- ## Unreleased -->
<!-- Add new, unreleased changes here. -->
## Unreleased
* Merge property information from constructors into associated scanned
properties when scanning classes

## [3.1.3] - 2018-10-15
* Make `HtmlDocument#stringify()` faster by only cloning the ast and stringifing
Expand Down
19 changes: 18 additions & 1 deletion packages/analyzer/src/javascript/class-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,24 @@ export function extractPropertiesFromClass(
for (const prop of esutil
.extractPropertiesFromClassOrObjectBody(astNode, document)
.values()) {
properties.set(prop.name, prop);
const existing = properties.get(prop.name);

if (!existing) {
properties.set(prop.name, prop);
} else {
properties.set(prop.name, {
name: prop.name,
astNode: prop.astNode,
type: prop.type || existing.type,
jsdoc: prop.jsdoc,
sourceRange: prop.sourceRange,
description: prop.description || existing.description,
privacy: prop.privacy || existing.privacy,
warnings: prop.warnings,
readOnly: prop.readOnly === undefined ?
existing.readOnly : prop.readOnly
});
}
}

return properties;
Expand Down
8 changes: 8 additions & 0 deletions packages/analyzer/src/test/javascript/class-scanner_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ suite('Class', () => {
cls.properties.get('__customPropertyOnProtoPrivate'),
{name: '__customPropertyOnProtoPrivate', privacy: 'private'});

assert.deepInclude(
cls.properties.get('constructorJSDocGetter'),
{
name: 'constructorJSDocGetter',
description: 'a getter with constructor jsdoc'
});

assert.deepEqual(await getTestProps(cls), {
name: 'Class',
constructorMethod: {description: '', name: 'constructor'},
Expand All @@ -232,6 +239,7 @@ suite('Class', () => {
properties: [
{name: 'customPropertyWithValue'},
{name: 'customPropertyWithJSDoc'},
{name: 'constructorJSDocGetter'},
{name: 'customPropertyGetter'},
{name: 'customPropertyGetterType'},
{name: 'customPropertyWithGetterSetter'},
Expand Down
4 changes: 4 additions & 0 deletions packages/analyzer/src/test/static/class/class-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class Class {
this.customPropertyWithValue = 5;
/** @public a jsdoc property */
this.customPropertyWithJSDoc;
/** @public a getter with constructor jsdoc */
this.constructorJSDocGetter;
}

get constructorJSDocGetter() { return true; }
}

/** @type {string} */
Expand Down

0 comments on commit a1d60e7

Please # to comment.