Skip to content

Commit e60ef6e

Browse files
authored
fix null reference parsing nonexported abstract class (#716)
closes #691
1 parent b5984be commit e60ef6e

File tree

5 files changed

+1128
-39
lines changed

5 files changed

+1128
-39
lines changed

src/lib/converter/nodes/class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ClassConverter extends ConverterNodeComponent<ts.ClassDeclaration>
3030
} else {
3131
reflection = createDeclaration(context, node, ReflectionKind.Class);
3232
// set possible abstract flag here, where node is not the inherited parent
33-
if (node.modifiers && node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
33+
if (reflection && node.modifiers && node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
3434
reflection.setFlag(ReflectionFlag.Abstract, true);
3535
}
3636
}

src/test/converter.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ describe('Converter', function() {
100100

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

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

118119
let result: ProjectReflection;
119120

120-
it('converts fixtures', function() {
121-
resetReflectionID();
122-
result = app.convert(app.expandInputFiles([path]));
123-
Assert(result instanceof ProjectReflection, 'No reflection returned');
121+
describe('export-with-local', () => {
122+
it('converts fixtures', function() {
123+
resetReflectionID();
124+
result = app.convert(app.expandInputFiles([exportWithLocalDir]));
125+
Assert(result instanceof ProjectReflection, 'No reflection returned');
126+
});
127+
128+
it('matches specs', function() {
129+
const specs = JSON.parse(FS.readFileSync(Path.join(exportWithLocalDir, 'specs-without-exported.json')).toString());
130+
let data = JSON.stringify(result.toObject(), null, ' ');
131+
data = data.split(normalizePath(base)).join('%BASE%');
132+
133+
compareReflections(JSON.parse(data), specs);
134+
});
124135
});
125136

126-
it('matches specs', function() {
127-
const specs = JSON.parse(FS.readFileSync(Path.join(path, 'specs-without-exported.json')).toString());
128-
let data = JSON.stringify(result.toObject(), null, ' ');
129-
data = data.split(normalizePath(base)).join('%BASE%');
137+
describe('class', () => {
138+
it('converts fixtures', function() {
139+
resetReflectionID();
140+
result = app.convert(app.expandInputFiles([classDir]));
141+
Assert(result instanceof ProjectReflection, 'No reflection returned');
142+
});
143+
144+
it('matches specs', function() {
145+
const specs = JSON.parse(FS.readFileSync(Path.join(classDir, 'specs-without-exported.json')).toString());
146+
let data = JSON.stringify(result.toObject(), null, ' ');
147+
data = data.split(normalizePath(base)).join('%BASE%');
130148

131-
compareReflections(JSON.parse(data), specs);
149+
compareReflections(JSON.parse(data), specs);
150+
});
132151
});
152+
133153
});

src/test/converter/class/class.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ export class TestClass {
1010
/**
1111
* publicProperty short text.
1212
*/
13-
public publicProperty:string;
13+
public publicProperty: string;
1414

1515
/**
1616
* privateProperty short text.
1717
*/
18-
private privateProperty:number[];
18+
private privateProperty: number[];
1919

2020
/**
2121
* privateProperty short text.
2222
*/
23-
static staticProperty:TestClass;
24-
23+
static staticProperty: TestClass;
2524

2625
/**
2726
* Constructor short text.
@@ -49,9 +48,7 @@ export class TestClass {
4948
static staticMethod() {}
5049
}
5150

52-
53-
export class TestSubClass extends TestClass
54-
{
51+
export class TestSubClass extends TestClass {
5552
/**
5653
* publicMethod short text.
5754
*/
@@ -75,7 +72,6 @@ export class TestSubClass extends TestClass
7572
}
7673
}
7774

78-
7975
export abstract class TestAbstractClass {
8076
abstract myAbstractProperty: string;
8177

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

8884
protected myAbstractMethod(): void { }
89-
}
85+
}
86+
87+
/**
88+
* This class will not appear when `excludeNotExported=true`
89+
*/
90+
abstract class NotExportedClass {
91+
/**
92+
* Adds two numbers
93+
*/
94+
add(a: number, b: number) {
95+
a + b;
96+
}
97+
}

0 commit comments

Comments
 (0)