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.22.0 to 0.22.1

typescript/mocks/tsParser/nodeToString.test.ts

9

CHANGELOG.md
# Changelog
# 0.22.1 23 November 2017
## Fixes
* **typescript**: remove comments from re-rendered code 0be17b9a
# 0.22.0 9 October 2017
## Fixes
* **typescript**: handle property accessors correctly f72b69e5f

@@ -16,2 +22,3 @@

## Reverts
* **typescript**: handle property accessors correctly a4be78add

@@ -25,2 +32,3 @@

## Fixes
* **typescript**: handle property accessors correctly 75fafcf7

@@ -31,2 +39,3 @@

## Features
* **typescript**:

@@ -33,0 +42,0 @@ - add isReadonly flag to member docs 62bc5333

2

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

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

@@ -26,1 +26,10 @@ export class TestClass {}

}
export type TestType2 = {
a: number; // line comment
/* block comment before */
b: string;
/* block comment after */
} & {
a: string;
};

@@ -193,3 +193,3 @@ "use strict";

var foo = docs.find(function (doc) { return doc.name === 'foo'; });
expect(foo.parameters).toEqual(['num1: number|string', 'num2?: number']);
expect(foo.parameters).toEqual(['num1: number | string', 'num2?: number']);
var overloads = foo.overloads;

@@ -217,3 +217,3 @@ expect(overloads.map(function (overload) { return overload.parameters; })).toEqual([

var foo = docs.find(function (doc) { return doc.name === 'constructor'; });
expect(foo.parameters).toEqual(['x: string', 'y: number|string', 'z?: number']);
expect(foo.parameters).toEqual(['x: string', 'y: number | string', 'z?: number']);
var overloads = foo.overloads;

@@ -264,8 +264,12 @@ expect(overloads.map(function (overload) { return overload.parameters; })).toEqual([

var propDocs = docs.filter(function (doc) { return doc.name === 'someProp'; });
expect(propDocs[0].type).toEqual('{\n' +
' foo: \'bar\',\n' +
' }');
expect(propDocs[1].type).toEqual('Object.assign(this.someProp, {\n' +
' bar: \'baz\'\n' +
' })');
expect(propDocs[0].type).toEqual([
'{',
' foo: \'bar\'',
'}',
].join('\n'));
expect(propDocs[1].type).toEqual([
'Object.assign(this.someProp, {',
' bar: \'baz\'',
'})',
].join('\n'));
});

@@ -272,0 +276,0 @@ });

@@ -1,3 +0,3 @@

import { Declaration } from 'typescript';
import { Declaration, Node } from 'typescript';
export declare function getDeclarationTypeText(declaration: Declaration, namespacesToInclude: string[]): string;
export declare function getInitializerText(declaration: Declaration): string;
export declare function getInitializer(declaration: Declaration): Node;

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

var getTypeText_1 = require("./getTypeText");
var nodeToString_1 = require("./nodeToString");
function getDeclarationTypeText(declaration, namespacesToInclude) {

@@ -13,6 +14,7 @@ // if the declaration has an explicit type then use that

if (declaration.kind === typescript_1.SyntaxKind.TypeParameter) {
return declaration.getText();
return nodeToString_1.nodeToString(declaration);
}
// if the declaration is being initialized then use the initialization value
return getInitializerText(declaration);
var initializer = getInitializer(declaration);
return initializer ? nodeToString_1.nodeToString(initializer) : '';
}

@@ -23,7 +25,6 @@ exports.getDeclarationTypeText = getDeclarationTypeText;

}
function getInitializerText(declaration) {
var initializer = declaration.initializer;
return initializer ? initializer.getText() : '';
function getInitializer(declaration) {
return declaration.initializer;
}
exports.getInitializerText = getInitializerText;
exports.getInitializer = getInitializer;
//# sourceMappingURL=getDeclarationTypeText.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var typescript_1 = require("typescript");
var nodeToString_1 = require("./nodeToString");
function getDecorators(declaration) {

@@ -15,3 +16,3 @@ if (declaration.decorators) {

isCallExpression: true,
name: callExpression.expression.getText(),
name: nodeToString_1.nodeToString(callExpression.expression),
};

@@ -23,3 +24,3 @@ }

isCallExpression: false,
name: decorator.expression.getText(),
name: nodeToString_1.nodeToString(decorator.expression),
};

@@ -40,3 +41,3 @@ }

if (property.kind === typescript_1.SyntaxKind.PropertyAssignment) {
result[property.name.getText()] = parseArgument(property.initializer);
result[nodeToString_1.nodeToString(property.name)] = parseArgument(property.initializer);
}

@@ -51,6 +52,6 @@ });

if (argument.kind === typescript_1.SyntaxKind.ArrayLiteralExpression) {
return argument.elements.map(function (element) { return element.getText(); });
return argument.elements.map(function (element) { return nodeToString_1.nodeToString(element); });
}
return argument.getText();
return nodeToString_1.nodeToString(argument);
}
//# sourceMappingURL=getDecorators.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var typescript_1 = require("typescript");
var nodeToString_1 = require("./nodeToString");
function getHeritageClause(declaration) {

@@ -12,3 +13,3 @@ var heritageString = '';

heritageString += ' implements';
heritageString += heritage.types.map(function (typ) { return typ.getFullText(); }).join(',');
heritageString += heritage.types.map(function (typ) { return ' ' + nodeToString_1.nodeToString(typ); }).join(',');
});

@@ -15,0 +16,0 @@ }

@@ -5,6 +5,7 @@ "use strict";

var getTypeText_1 = require("./getTypeText");
var nodeToString_1 = require("./nodeToString");
function getParameters(declaration, namespacesToInclude) {
var parameters = getParameterDeclarations(declaration);
if (!parameters) {
var name = declaration.name ? declaration.name.getText() : 'unknown';
var name = declaration.name ? nodeToString_1.nodeToString(declaration.name) : 'unknown';
throw new Error("Missing declaration parameters for \"" + name + "\" in " + declaration.getSourceFile().fileName + " at line " + declaration.getStart());

@@ -16,3 +17,3 @@ }

paramText += '...';
paramText += parameter.name.getText();
paramText += nodeToString_1.nodeToString(parameter.name);
if (parameter.questionToken)

@@ -24,5 +25,5 @@ paramText += '?';

}
var initializer = getDeclarationTypeText_1.getInitializerText(parameter);
var initializer = getDeclarationTypeText_1.getInitializer(parameter);
if (initializer) {
paramText += ' = ' + initializer;
paramText += ' = ' + nodeToString_1.nodeToString(initializer);
}

@@ -29,0 +30,0 @@ return paramText.trim();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var typescript_1 = require("typescript");
var nodeToString_1 = require("./nodeToString");
function getTypeText(type, namespacesToInclude) {

@@ -11,3 +12,3 @@ if (type.kind === typescript_1.SyntaxKind.TypeReference) {

// we have a straightforward type
return type.getText();
return nodeToString_1.nodeToString(type);
}

@@ -28,3 +29,3 @@ }

while (name.kind === typescript_1.SyntaxKind.QualifiedName) {
var qualification = name.left.getText();
var qualification = nodeToString_1.nodeToString(name.left);
if (namespacesToInclude.indexOf(qualification) !== -1) {

@@ -35,5 +36,5 @@ nameParts.push(qualification);

}
nameParts.push(name.getText());
nameParts.push(nodeToString_1.nodeToString(name));
return nameParts.join('.');
}
//# sourceMappingURL=getTypeText.js.map

@@ -21,3 +21,8 @@ "use strict";

expect(getTypeText_1.getTypeText(getType(moduleExports[5]), [])).toEqual('TestClass | string');
expect(getTypeText_1.getTypeText(getType(moduleExports[6]), [])).toEqual('{ x: number, y: string }');
expect(getTypeText_1.getTypeText(getType(moduleExports[6]), [])).toEqual([
'{',
' x: number;',
' y: string;',
'}',
].join('\n'));
expect(getTypeText_1.getTypeText(getType(moduleExports[7]), [])).toEqual('Array<string>');

@@ -38,2 +43,14 @@ expect(getTypeText_1.getTypeText(getType(moduleExports[8]), [])).toEqual('Array<T>');

});
it('should remove comments from the rendered text', function () {
var parseInfo = parser.parse(['tsParser/getTypeText.test.ts'], basePath);
var moduleExports = parseInfo.moduleSymbols[0].exportArray;
expect(getTypeText_1.getTypeText(getType(moduleExports[12]), [])).toEqual([
'{',
' a: number;',
' b: string;',
'} & {',
' a: string;',
'}',
].join('\n'));
});
});

@@ -40,0 +57,0 @@ function getType(symbol) {

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

const foo: MethodMemberDoc = docs.find(doc => doc.name === 'foo');
expect(foo.parameters).toEqual(['num1: number|string', 'num2?: number']);
expect(foo.parameters).toEqual(['num1: number | string', 'num2?: number']);
const overloads = foo.overloads;

@@ -271,3 +271,3 @@ expect(overloads.map(overload => overload.parameters)).toEqual([

const foo: MethodMemberDoc = docs.find(doc => doc.name === 'constructor');
expect(foo.parameters).toEqual(['x: string', 'y: number|string', 'z?: number']);
expect(foo.parameters).toEqual(['x: string', 'y: number | string', 'z?: number']);
const overloads = foo.overloads;

@@ -323,8 +323,12 @@ expect(overloads.map(overload => overload.parameters)).toEqual([

const propDocs = docs.filter(doc => doc.name === 'someProp');
expect(propDocs[0].type).toEqual('{\n' +
' foo: \'bar\',\n' +
' }');
expect(propDocs[1].type).toEqual('Object.assign(this.someProp, {\n' +
' bar: \'baz\'\n' +
' })');
expect(propDocs[0].type).toEqual([
'{',
' foo: \'bar\'',
'}',
].join('\n'));
expect(propDocs[1].type).toEqual([
'Object.assign(this.someProp, {',
' bar: \'baz\'',
'})',
].join('\n'));
});

@@ -331,0 +335,0 @@ });

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

import { Declaration, Expression, SyntaxKind, TypeNode, TypeParameterDeclaration } from 'typescript';
import { Declaration, Node, SyntaxKind, TypeNode, TypeParameterDeclaration } from 'typescript';
import { getTypeText } from './getTypeText';
import { nodeToString } from './nodeToString';

@@ -11,7 +12,8 @@ export function getDeclarationTypeText(declaration: Declaration, namespacesToInclude: string[]) {

if (declaration.kind === SyntaxKind.TypeParameter ) {
return declaration.getText();
return nodeToString(declaration);
}
// if the declaration is being initialized then use the initialization value
return getInitializerText(declaration);
const initializer = getInitializer(declaration);
return initializer ? nodeToString(initializer) : '';
}

@@ -23,5 +25,4 @@

export function getInitializerText(declaration: Declaration) {
const initializer = (declaration as any).initializer as Expression;
return initializer ? initializer.getText() : '';
export function getInitializer(declaration: Declaration) {
return (declaration as any).initializer as Node;
}
import { ArrayLiteralExpression, CallExpression, createPrinter, Declaration, Decorator, EmitHint, Expression, ObjectLiteralElement, ObjectLiteralExpression, PropertyAssignment, SyntaxKind } from 'typescript';
import { nodeToString } from './nodeToString';

@@ -24,3 +25,3 @@ export type ArgumentInfo = string | string[] | { [key: string]: ArgumentInfo };

isCallExpression: true,
name: callExpression.expression.getText(),
name: nodeToString(callExpression.expression),
};

@@ -31,3 +32,3 @@ } else {

isCallExpression: false,
name: decorator.expression.getText(),
name: nodeToString(decorator.expression),
};

@@ -49,3 +50,3 @@ }

if (property.kind === SyntaxKind.PropertyAssignment) {
result[property.name!.getText()] = parseArgument((property as PropertyAssignment).initializer);
result[nodeToString(property.name!)] = parseArgument((property as PropertyAssignment).initializer);
}

@@ -61,5 +62,5 @@ });

if (argument.kind === SyntaxKind.ArrayLiteralExpression) {
return (argument as ArrayLiteralExpression).elements.map(element => element.getText());
return (argument as ArrayLiteralExpression).elements.map(element => nodeToString(element));
}
return argument.getText();
return nodeToString(argument);
}
import { ClassDeclaration, InterfaceDeclaration, SyntaxKind } from 'typescript';
import { nodeToString } from './nodeToString';

@@ -9,3 +10,3 @@ export function getHeritageClause(declaration: ClassDeclaration | InterfaceDeclaration) {

if (heritage.token === SyntaxKind.ImplementsKeyword) heritageString += ' implements';
heritageString += heritage.types.map(typ => typ.getFullText()).join(',');
heritageString += heritage.types.map(typ => ' ' + nodeToString(typ)).join(',');
});

@@ -12,0 +13,0 @@ }

import { Declaration, ParameterDeclaration, SignatureDeclaration } from 'typescript';
import { getInitializerText } from './getDeclarationTypeText';
import { getInitializer } from './getDeclarationTypeText';
import { getTypeText } from './getTypeText';
import { nodeToString } from './nodeToString';

@@ -8,3 +9,3 @@ export function getParameters(declaration: SignatureDeclaration, namespacesToInclude: string[]) {

if (!parameters) {
const name = declaration.name ? declaration.name.getText() : 'unknown';
const name = declaration.name ? nodeToString(declaration.name) : 'unknown';
throw new Error(`Missing declaration parameters for "${name}" in ${declaration.getSourceFile().fileName} at line ${declaration.getStart()}`);

@@ -18,3 +19,3 @@ }

paramText += parameter.name.getText();
paramText += nodeToString(parameter.name);

@@ -28,5 +29,5 @@ if (parameter.questionToken) paramText += '?';

const initializer = getInitializerText(parameter);
const initializer = getInitializer(parameter);
if (initializer) {
paramText += ' = ' + initializer;
paramText += ' = ' + nodeToString(initializer);
}

@@ -33,0 +34,0 @@

@@ -23,3 +23,8 @@ import { Declaration, Symbol, TypeNode } from 'typescript';

expect(getTypeText(getType(moduleExports[5]), [])).toEqual('TestClass | string');
expect(getTypeText(getType(moduleExports[6]), [])).toEqual('{ x: number, y: string }');
expect(getTypeText(getType(moduleExports[6]), [])).toEqual([
'{',
' x: number;',
' y: string;',
'}',
].join('\n'));
expect(getTypeText(getType(moduleExports[7]), [])).toEqual('Array<string>');

@@ -42,2 +47,15 @@ expect(getTypeText(getType(moduleExports[8]), [])).toEqual('Array<T>');

});
it('should remove comments from the rendered text', () => {
const parseInfo = parser.parse(['tsParser/getTypeText.test.ts'], basePath);
const moduleExports = parseInfo.moduleSymbols[0].exportArray;
expect(getTypeText(getType(moduleExports[12]), [])).toEqual([
'{',
' a: number;',
' b: string;',
'} & {',
' a: string;',
'}',
].join('\n'));
});
});

@@ -44,0 +62,0 @@

@@ -1,11 +0,12 @@

import { EntityName, Identifier, SyntaxKind, TypeNode, TypeReferenceNode } from 'typescript';
import { createPrinter, EntityName, Identifier, SyntaxKind, TypeNode, TypeReferenceNode } from 'typescript';
import { nodeToString } from './nodeToString';
export function getTypeText(type: TypeNode, namespacesToInclude: string[]): string {
if (type.kind === SyntaxKind.TypeReference) {
// we have a type reference, so recurse down to find the unqualified name
return getTypeReferenceText(type as TypeReferenceNode, namespacesToInclude);
} else {
// we have a straightforward type
return type.getText();
}
if (type.kind === SyntaxKind.TypeReference) {
// we have a type reference, so recurse down to find the unqualified name
return getTypeReferenceText(type as TypeReferenceNode, namespacesToInclude);
} else {
// we have a straightforward type
return nodeToString(type);
}
}

@@ -26,3 +27,3 @@

while (name.kind === SyntaxKind.QualifiedName) {
const qualification = name.left.getText();
const qualification = nodeToString(name.left);
if (namespacesToInclude.indexOf(qualification) !== -1) {

@@ -33,4 +34,4 @@ nameParts.push(qualification);

}
nameParts.push(name.getText());
nameParts.push(nodeToString(name));
return nameParts.join('.');
}

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

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc