Skip to content

Commit

Permalink
fix null reference parsing nonexported abstract class (#716)
Browse files Browse the repository at this point in the history
closes #691
  • Loading branch information
aciccarello committed Mar 5, 2018
1 parent b5984be commit e60ef6e
Show file tree
Hide file tree
Showing 5 changed files with 1,128 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/lib/converter/nodes/class.ts
Expand Up @@ -30,7 +30,7 @@ export class ClassConverter extends ConverterNodeComponent<ts.ClassDeclaration>
} else {
reflection = createDeclaration(context, node, ReflectionKind.Class);
// set possible abstract flag here, where node is not the inherited parent
if (node.modifiers && node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
if (reflection && node.modifiers && node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
reflection.setFlag(ReflectionFlag.Abstract, true);
}
}
Expand Down
40 changes: 30 additions & 10 deletions src/test/converter.ts
Expand Up @@ -100,7 +100,8 @@ describe('Converter', function() {

describe('Converter with excludeNotExported=true', function() {
const base = Path.join(__dirname, 'converter');
const path = Path.join(base, 'export-with-local');
const exportWithLocalDir = Path.join(base, 'export-with-local');
const classDir = Path.join(base, 'class');
let app: Application;

it('constructs', function() {
Expand All @@ -117,17 +118,36 @@ describe('Converter with excludeNotExported=true', function() {

let result: ProjectReflection;

it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([path]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
describe('export-with-local', () => {
it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([exportWithLocalDir]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
});

it('matches specs', function() {
const specs = JSON.parse(FS.readFileSync(Path.join(exportWithLocalDir, 'specs-without-exported.json')).toString());
let data = JSON.stringify(result.toObject(), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
});
});

it('matches specs', function() {
const specs = JSON.parse(FS.readFileSync(Path.join(path, 'specs-without-exported.json')).toString());
let data = JSON.stringify(result.toObject(), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');
describe('class', () => {
it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([classDir]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
});

it('matches specs', function() {
const specs = JSON.parse(FS.readFileSync(Path.join(classDir, 'specs-without-exported.json')).toString());
let data = JSON.stringify(result.toObject(), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
compareReflections(JSON.parse(data), specs);
});
});

});
26 changes: 17 additions & 9 deletions src/test/converter/class/class.ts
Expand Up @@ -10,18 +10,17 @@ export class TestClass {
/**
* publicProperty short text.
*/
public publicProperty:string;
public publicProperty: string;

/**
* privateProperty short text.
*/
private privateProperty:number[];
private privateProperty: number[];

/**
* privateProperty short text.
*/
static staticProperty:TestClass;

static staticProperty: TestClass;

/**
* Constructor short text.
Expand Down Expand Up @@ -49,9 +48,7 @@ export class TestClass {
static staticMethod() {}
}


export class TestSubClass extends TestClass
{
export class TestSubClass extends TestClass {
/**
* publicMethod short text.
*/
Expand All @@ -75,7 +72,6 @@ export class TestSubClass extends TestClass
}
}


export abstract class TestAbstractClass {
abstract myAbstractProperty: string;

Expand All @@ -86,4 +82,16 @@ export class TestAbstractClassImplementation extends TestAbstractClass {
myAbstractProperty: string;

protected myAbstractMethod(): void { }
}
}

/**
* This class will not appear when `excludeNotExported=true`
*/
abstract class NotExportedClass {
/**
* Adds two numbers
*/
add(a: number, b: number) {
a + b;
}
}

0 comments on commit e60ef6e

Please sign in to comment.