Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

dgeni-packages

Package Overview
Dependencies
118
Maintainers
2
Versions
147
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.21.4 to 0.21.5

typescript/api-doc-types/AccessorInfoDoc.d.ts

6

CHANGELOG.md
# Changelog
# 0.21.5 8 October 2017
## Fixes
* **typescript**: handle property accessors correctly 75fafcf7
# 0.21.4 28 September 2017

@@ -4,0 +10,0 @@

2

package.json
{
"name": "dgeni-packages",
"version": "0.21.4",
"version": "0.21.5",
"description": "A collection of dgeni packages for generating documentation from source code",

@@ -5,0 +5,0 @@ "scripts": {

@@ -51,6 +51,14 @@ "use strict";

var memberDoc = null;
var getAccessorDeclaration = null;
var setAccessorDeclaration = null;
for (var _i = 0, _a = member.getDeclarations(); _i < _a.length; _i++) {
var declaration = _a[_i];
if (flags & MethodMemberFlags) {
if (declaration.body) {
if (declaration.kind === typescript_1.SyntaxKind.GetAccessor) {
getAccessorDeclaration = declaration;
}
else if (declaration.kind === typescript_1.SyntaxKind.SetAccessor) {
setAccessorDeclaration = declaration;
}
else if (declaration.body) {
// This is the "real" declaration of the method

@@ -65,3 +73,3 @@ memberDoc = new MethodMemberDoc_1.MethodMemberDoc(_this, member, declaration, _this.basePath, _this.namespacesToInclude, isStatic, overloads);

else if (flags & PropertyMemberFlags) {
memberDoc = new PropertyMemberDoc_1.PropertyMemberDoc(_this, member, declaration, _this.basePath, _this.namespacesToInclude, isStatic);
memberDoc = new PropertyMemberDoc_1.PropertyMemberDoc(_this, member, declaration, null, null, _this.basePath, _this.namespacesToInclude, isStatic);
}

@@ -72,2 +80,6 @@ else {

}
// If at least one of the declarations was an accessor then the whole member is a property.
if (getAccessorDeclaration || setAccessorDeclaration) {
memberDoc = new PropertyMemberDoc_1.PropertyMemberDoc(_this, member, null, getAccessorDeclaration, setAccessorDeclaration, _this.basePath, _this.namespacesToInclude, false);
}
// If there is no member doc then we are in an interface or abstract class and we just take the first overload

@@ -74,0 +86,0 @@ // as the primary one.

@@ -0,1 +1,4 @@

import { Declaration, GetAccessorDeclaration, SetAccessorDeclaration, Symbol } from 'typescript';
import { AccessorInfoDoc } from './AccessorInfoDoc';
import { ContainerExportDoc } from './ContainerExportDoc';
import { MemberDoc } from './MemberDoc';

@@ -7,2 +10,5 @@ export declare class PropertyMemberDoc extends MemberDoc {

aliases: string[];
getAccessor: AccessorInfoDoc | null;
setAccessor: AccessorInfoDoc | null;
constructor(containerDoc: ContainerExportDoc, symbol: Symbol, declaration: Declaration | null, getAccessorDeclaration: GetAccessorDeclaration | null, setAccessorDeclaration: SetAccessorDeclaration | null, basePath: string, namespacesToInclude: string[], isStatic: boolean);
}

@@ -14,7 +14,8 @@ "use strict";

var encodeAnchor_1 = require("../utils/encodeAnchor");
var AccessorInfoDoc_1 = require("./AccessorInfoDoc");
var MemberDoc_1 = require("./MemberDoc");
var PropertyMemberDoc = (function (_super) {
__extends(PropertyMemberDoc, _super);
function PropertyMemberDoc() {
var _this = _super !== null && _super.apply(this, arguments) || this;
function PropertyMemberDoc(containerDoc, symbol, declaration, getAccessorDeclaration, setAccessorDeclaration, basePath, namespacesToInclude, isStatic) {
var _this = _super.call(this, containerDoc, symbol, (declaration || getAccessorDeclaration || setAccessorDeclaration), basePath, namespacesToInclude, isStatic) || this;
_this.name = _this.symbol.name;

@@ -24,2 +25,7 @@ _this.anchor = encodeAnchor_1.encodeAnchor(_this.name);

_this.aliases = _this.containerDoc.aliases.map(function (alias) { return alias + "." + _this.name; });
// If this property has accessors then compute the type based on that instead
_this.getAccessor = getAccessorDeclaration && new AccessorInfoDoc_1.AccessorInfoDoc('get', _this, getAccessorDeclaration, basePath, namespacesToInclude);
_this.setAccessor = setAccessorDeclaration && new AccessorInfoDoc_1.AccessorInfoDoc('set', _this, setAccessorDeclaration, basePath, namespacesToInclude);
_this.type = _this.type || _this.setAccessor && _this.setAccessor.parameters[0].split(/:\s?/)[1] || '';
_this.content = _this.content || _this.setAccessor && _this.setAccessor.content || '';
return _this;

@@ -26,0 +32,0 @@ }

@@ -12,2 +12,3 @@ "use strict";

var ModuleDoc_1 = require("../../api-doc-types/ModuleDoc");
var PropertyMemberDoc_1 = require("../../api-doc-types/PropertyMemberDoc");
var TypeAliasExportDoc_1 = require("../../api-doc-types/TypeAliasExportDoc");

@@ -132,2 +133,8 @@ var SourcePattern_1 = require("./SourcePattern");

member.overloads.forEach(function (overloadDoc) { return docs.push(overloadDoc); });
if (member instanceof PropertyMemberDoc_1.PropertyMemberDoc) {
if (member.getAccessor)
docs.push(member.getAccessor);
if (member.setAccessor)
docs.push(member.setAccessor);
}
});

@@ -134,0 +141,0 @@ };

@@ -281,2 +281,96 @@ "use strict";

});
describe('getters and setters', function () {
var docs;
var foo1;
var foo1Getter;
var foo1Setter;
var foo2;
var foo2Getter;
var foo2Setter;
var bar;
var barGetter;
var barSetter;
var qux;
var quxGetter;
var quxSetter;
var noType;
var noTypeGetter;
var noTypeSetter;
beforeEach(function () {
processor.sourceFiles = ['gettersAndSetters.ts'];
docs = [];
processor.$process(docs);
foo1 = docs.find(function (doc) { return doc.name === 'foo1'; });
foo2 = docs.find(function (doc) { return doc.name === 'foo2'; });
bar = docs.find(function (doc) { return doc.name === 'bar'; });
qux = docs.find(function (doc) { return doc.name === 'qux'; });
noType = docs.find(function (doc) { return doc.name === 'noType'; });
foo1Getter = docs.find(function (doc) { return doc.name === 'foo1:get'; });
foo1Setter = docs.find(function (doc) { return doc.name === 'foo1:set'; });
foo2Getter = docs.find(function (doc) { return doc.name === 'foo2:get'; });
foo2Setter = docs.find(function (doc) { return doc.name === 'foo2:set'; });
barGetter = docs.find(function (doc) { return doc.name === 'bar:get'; });
barSetter = docs.find(function (doc) { return doc.name === 'bar:set'; });
quxGetter = docs.find(function (doc) { return doc.name === 'qux:get'; });
quxSetter = docs.find(function (doc) { return doc.name === 'qux:set'; });
noTypeGetter = docs.find(function (doc) { return doc.name === 'noType:get'; });
noTypeSetter = docs.find(function (doc) { return doc.name === 'noType:set'; });
});
it('should create a property member doc for property that has accessors', function () {
expect(foo1).toBeDefined();
expect(foo1.docType).toBe('member');
expect(foo2).toBeDefined();
expect(foo2.docType).toBe('member');
expect(bar).toBeDefined();
expect(bar.docType).toBe('member');
expect(qux).toBeDefined();
expect(qux.docType).toBe('member');
});
it('should create a doc for each accessor of a property', function () {
expect(foo1Getter).toBeDefined();
expect(foo1Getter.docType).toBe('get-accessor-info');
expect(foo1Getter.content).toEqual('');
expect(foo1Setter).toBeDefined();
expect(foo1Setter.docType).toBe('set-accessor-info');
expect(foo1Setter.content).toEqual('foo1 setter');
expect(foo2Getter).toBeDefined();
expect(foo2Getter.docType).toBe('get-accessor-info');
expect(foo2Getter.content).toEqual('foo2 getter');
expect(foo2Setter).toBeDefined();
expect(foo2Setter.docType).toBe('set-accessor-info');
expect(foo2Setter.content).toEqual('');
expect(barGetter).toBeDefined();
expect(barGetter.docType).toBe('get-accessor-info');
expect(barGetter.content).toEqual('bar getter');
expect(barSetter).toBeUndefined();
expect(quxGetter).toBeUndefined();
expect(quxSetter).toBeDefined();
expect(quxSetter.docType).toBe('set-accessor-info');
expect(quxSetter.content).toEqual('qux setter');
});
it('should compute the type of the property from its accessors', function () {
expect(foo1.type).toEqual('string');
expect(foo2.type).toEqual('string');
expect(bar.type).toEqual('number');
expect(qux.type).toEqual('object');
expect(noType.type).toEqual('string');
});
it('should compute the content of the property from its accessors', function () {
expect(foo1.content).toEqual('foo1 setter');
expect(foo2.content).toEqual('foo2 getter');
expect(bar.content).toEqual('bar getter');
expect(qux.content).toEqual('qux setter');
expect(noType.content).toEqual('This has no explicit getter return type');
});
it('should attach each accessor doc to its property doc', function () {
expect(foo1.getAccessor).toBe(foo1Getter);
expect(foo1.setAccessor).toBe(foo1Setter);
expect(foo2.getAccessor).toBe(foo2Getter);
expect(foo2.setAccessor).toBe(foo2Setter);
expect(bar.getAccessor).toBe(barGetter);
expect(bar.setAccessor).toBe(null);
expect(qux.getAccessor).toBe(null);
expect(qux.setAccessor).toBe(quxSetter);
});
});
});

@@ -283,0 +377,0 @@ describe('strip namespaces', function () {

/* tslint:disable:no-bitwise */
import { FunctionLikeDeclaration, Map, Symbol, SymbolFlags } from 'typescript';
import { FunctionLikeDeclaration, GetAccessorDeclaration, Map, SetAccessorDeclaration, Symbol, SymbolFlags, SyntaxKind } from 'typescript';
import { FileInfo } from "../services/TsParser/FileInfo";
import { getAccessibility } from "../services/TsParser/getAccessibility";
import { AccessorInfoDoc } from './AccessorInfoDoc';
import { ExportDoc } from './ExportDoc' ;

@@ -41,6 +42,12 @@ import { MemberDoc } from './MemberDoc' ;

let memberDoc: MemberDoc|null = null;
let getAccessorDeclaration: GetAccessorDeclaration | null = null;
let setAccessorDeclaration: SetAccessorDeclaration | null = null;
for (const declaration of member.getDeclarations()!) {
if (flags & MethodMemberFlags) {
if ((declaration as FunctionLikeDeclaration).body) {
if (declaration.kind === SyntaxKind.GetAccessor) {
getAccessorDeclaration = declaration as GetAccessorDeclaration;
} else if (declaration.kind === SyntaxKind.SetAccessor) {
setAccessorDeclaration = declaration as SetAccessorDeclaration;
} else if ((declaration as FunctionLikeDeclaration).body) {
// This is the "real" declaration of the method

@@ -53,3 +60,3 @@ memberDoc = new MethodMemberDoc(this, member, declaration, this.basePath, this.namespacesToInclude, isStatic, overloads);

} else if (flags & PropertyMemberFlags) {
memberDoc = new PropertyMemberDoc(this, member, declaration, this.basePath, this.namespacesToInclude, isStatic);
memberDoc = new PropertyMemberDoc(this, member, declaration, null, null, this.basePath, this.namespacesToInclude, isStatic);
} else {

@@ -59,2 +66,8 @@ throw new Error(`Unknown member type for member ${member.name}`);

}
// If at least one of the declarations was an accessor then the whole member is a property.
if (getAccessorDeclaration || setAccessorDeclaration) {
memberDoc = new PropertyMemberDoc(this, member, null, getAccessorDeclaration, setAccessorDeclaration, this.basePath, this.namespacesToInclude, false);
}
// If there is no member doc then we are in an interface or abstract class and we just take the first overload

@@ -61,0 +74,0 @@ // as the primary one.

@@ -0,2 +1,7 @@

import { Declaration, GetAccessorDeclaration, SetAccessorDeclaration, SignatureDeclaration, Symbol, SyntaxKind } from 'typescript';
import { getDeclarationTypeText } from "../services/TsParser/getDeclarationTypeText";
import { getParameters } from '../services/TsParser/getParameters';
import { encodeAnchor } from '../utils/encodeAnchor';
import { AccessorInfoDoc } from './AccessorInfoDoc';
import { ContainerExportDoc } from './ContainerExportDoc';
import { MemberDoc } from './MemberDoc';

@@ -9,2 +14,23 @@

aliases = this.containerDoc.aliases.map(alias => `${alias}.${this.name}` );
getAccessor: AccessorInfoDoc | null;
setAccessor: AccessorInfoDoc | null;
constructor(
containerDoc: ContainerExportDoc,
symbol: Symbol,
declaration: Declaration | null,
getAccessorDeclaration: GetAccessorDeclaration | null,
setAccessorDeclaration: SetAccessorDeclaration | null,
basePath: string,
namespacesToInclude: string[],
isStatic: boolean,
) {
super(containerDoc, symbol, (declaration || getAccessorDeclaration || setAccessorDeclaration)!, basePath, namespacesToInclude, isStatic);
// If this property has accessors then compute the type based on that instead
this.getAccessor = getAccessorDeclaration && new AccessorInfoDoc('get', this, getAccessorDeclaration, basePath, namespacesToInclude);
this.setAccessor = setAccessorDeclaration && new AccessorInfoDoc('set', this, setAccessorDeclaration, basePath, namespacesToInclude);
this.type = this.type || this.setAccessor && this.setAccessor.parameters[0].split(/:\s?/)[1] || '';
this.content = this.content || this.setAccessor && this.setAccessor.content || '';
}
}

@@ -5,2 +5,3 @@ import {Dgeni, DocCollection} from 'dgeni';

import {ReadTypeScriptModules} from '.';
import {AccessorInfoDoc} from '../../api-doc-types/AccessorInfoDoc';
import {ClassExportDoc} from '../../api-doc-types/ClassExportDoc';

@@ -11,2 +12,3 @@ import {ExportDoc} from '../../api-doc-types/ExportDoc';

import {ModuleDoc} from '../../api-doc-types/ModuleDoc';
import {PropertyMemberDoc} from '../../api-doc-types/PropertyMemberDoc';
const mockPackage = require('../../mocks/mockPackage');

@@ -341,2 +343,109 @@ const path = require('canonical-path');

});
describe('getters and setters', () => {
let docs: DocCollection;
let foo1: PropertyMemberDoc;
let foo1Getter: AccessorInfoDoc;
let foo1Setter: AccessorInfoDoc;
let foo2: PropertyMemberDoc;
let foo2Getter: AccessorInfoDoc;
let foo2Setter: AccessorInfoDoc;
let bar: PropertyMemberDoc;
let barGetter: AccessorInfoDoc;
let barSetter: AccessorInfoDoc;
let qux: PropertyMemberDoc;
let quxGetter: AccessorInfoDoc;
let quxSetter: AccessorInfoDoc;
let noType: PropertyMemberDoc;
let noTypeGetter: AccessorInfoDoc;
let noTypeSetter: AccessorInfoDoc;
beforeEach(() => {
processor.sourceFiles = ['gettersAndSetters.ts'];
docs = [];
processor.$process(docs);
foo1 = docs.find(doc => doc.name === 'foo1');
foo2 = docs.find(doc => doc.name === 'foo2');
bar = docs.find(doc => doc.name === 'bar');
qux = docs.find(doc => doc.name === 'qux');
noType = docs.find(doc => doc.name === 'noType');
foo1Getter = docs.find(doc => doc.name === 'foo1:get');
foo1Setter = docs.find(doc => doc.name === 'foo1:set');
foo2Getter = docs.find(doc => doc.name === 'foo2:get');
foo2Setter = docs.find(doc => doc.name === 'foo2:set');
barGetter = docs.find(doc => doc.name === 'bar:get');
barSetter = docs.find(doc => doc.name === 'bar:set');
quxGetter = docs.find(doc => doc.name === 'qux:get');
quxSetter = docs.find(doc => doc.name === 'qux:set');
noTypeGetter = docs.find(doc => doc.name === 'noType:get');
noTypeSetter = docs.find(doc => doc.name === 'noType:set');
});
it('should create a property member doc for property that has accessors', () => {
expect(foo1).toBeDefined();
expect(foo1.docType).toBe('member');
expect(foo2).toBeDefined();
expect(foo2.docType).toBe('member');
expect(bar).toBeDefined();
expect(bar.docType).toBe('member');
expect(qux).toBeDefined();
expect(qux.docType).toBe('member');
});
it('should create a doc for each accessor of a property', () => {
expect(foo1Getter).toBeDefined();
expect(foo1Getter.docType).toBe('get-accessor-info');
expect(foo1Getter.content).toEqual('');
expect(foo1Setter).toBeDefined();
expect(foo1Setter.docType).toBe('set-accessor-info');
expect(foo1Setter.content).toEqual('foo1 setter');
expect(foo2Getter).toBeDefined();
expect(foo2Getter.docType).toBe('get-accessor-info');
expect(foo2Getter.content).toEqual('foo2 getter');
expect(foo2Setter).toBeDefined();
expect(foo2Setter.docType).toBe('set-accessor-info');
expect(foo2Setter.content).toEqual('');
expect(barGetter).toBeDefined();
expect(barGetter.docType).toBe('get-accessor-info');
expect(barGetter.content).toEqual('bar getter');
expect(barSetter).toBeUndefined();
expect(quxGetter).toBeUndefined();
expect(quxSetter).toBeDefined();
expect(quxSetter.docType).toBe('set-accessor-info');
expect(quxSetter.content).toEqual('qux setter');
});
it('should compute the type of the property from its accessors', () => {
expect(foo1.type).toEqual('string');
expect(foo2.type).toEqual('string');
expect(bar.type).toEqual('number');
expect(qux.type).toEqual('object');
expect(noType.type).toEqual('string');
});
it('should compute the content of the property from its accessors', () => {
expect(foo1.content).toEqual('foo1 setter');
expect(foo2.content).toEqual('foo2 getter');
expect(bar.content).toEqual('bar getter');
expect(qux.content).toEqual('qux setter');
expect(noType.content).toEqual('This has no explicit getter return type');
});
it('should attach each accessor doc to its property doc', () => {
expect(foo1.getAccessor).toBe(foo1Getter);
expect(foo1.setAccessor).toBe(foo1Setter);
expect(foo2.getAccessor).toBe(foo2Getter);
expect(foo2.setAccessor).toBe(foo2Setter);
expect(bar.getAccessor).toBe(barGetter);
expect(bar.setAccessor).toBe(null);
expect(qux.getAccessor).toBe(null);
expect(qux.setAccessor).toBe(quxSetter);
});
});
});

@@ -343,0 +452,0 @@

@@ -19,2 +19,3 @@ const path = require('canonical-path');

import { ModuleDoc } from '../../api-doc-types/ModuleDoc';
import { PropertyMemberDoc } from '../../api-doc-types/PropertyMemberDoc';
import { TypeAliasExportDoc } from '../../api-doc-types/TypeAliasExportDoc';

@@ -155,2 +156,6 @@

if (member instanceof MethodMemberDoc) member.overloads.forEach(overloadDoc => docs.push(overloadDoc));
if (member instanceof PropertyMemberDoc) {
if (member.getAccessor) docs.push(member.getAccessor);
if (member.setAccessor) docs.push(member.setAccessor);
}
});

@@ -157,0 +162,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc