Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/lib/converter/nodes/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,23 @@ export class VariableConverter extends ConverterNodeComponent<ts.VariableDeclara
const kind = scope.kind & ReflectionKind.ClassOrInterface ? ReflectionKind.Property : ReflectionKind.Variable;
const variable = createDeclaration(context, node, kind, name);

switch (kind) {
case ReflectionKind.Variable:
if (node.parent.flags & ts.NodeFlags.Const) {
variable.setFlag(ReflectionFlag.Const, true);
} else if (node.parent.flags & ts.NodeFlags.Let) {
variable.setFlag(ReflectionFlag.Let, true);
}
break;
case ReflectionKind.Property:
if (variable // child inheriting will return null on createDeclaration
&& node.modifiers
&& node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
// The variable can be null if `excludeNotExported` is `true`
if (variable) {
switch (kind) {
case ReflectionKind.Variable:
if (node.parent.flags & ts.NodeFlags.Const) {
variable.setFlag(ReflectionFlag.Const, true);
} else if (node.parent.flags & ts.NodeFlags.Let) {
variable.setFlag(ReflectionFlag.Let, true);
}
break;
case ReflectionKind.Property:
if (node.modifiers
&& node.modifiers.some( m => m.kind === ts.SyntaxKind.AbstractKeyword )) {
variable.setFlag(ReflectionFlag.Abstract, true);
}
break;
}
break;
}
}

context.withScope(variable, () => {
Expand Down
34 changes: 34 additions & 0 deletions src/test/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,37 @@ describe('Converter', function() {
});
});
});

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

it('constructs', function() {
app = new Application({
mode: 'Modules',
logger: 'none',
target: 'ES5',
module: 'CommonJS',
experimentalDecorators: true,
excludeNotExported: true,
jsx: 'react'
});
});

let result: ProjectReflection;

it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([path]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
});

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%');

compareReflections(JSON.parse(data), specs);
});
});
13 changes: 13 additions & 0 deletions src/test/converter/export-with-local/export-with-local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const x = 5;

export function add(x: number, y: number) {
return x + y;
}

// Add a local var/function to make sure typedoc won't choke
// if excludeNotExported is true
let localVar = 'local';

function times(x: number, y: number) {
return x * y;
}
127 changes: 127 additions & 0 deletions src/test/converter/export-with-local/specs-without-exported.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"id": 0,
"name": "typedoc",
"kind": 0,
"flags": {},
"children": [
{
"id": 1,
"name": "\"export-with-local\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/export-with-local/export-with-local.ts",
"children": [
{
"id": 2,
"name": "x",
"kind": 32,
"kindString": "Variable",
"flags": {
"isExported": true,
"isConst": true
},
"sources": [
{
"fileName": "export-with-local.ts",
"line": 1,
"character": 14
}
],
"type": {
"type": "unknown",
"name": "5"
},
"defaultValue": "5"
},
{
"id": 3,
"name": "add",
"kind": 64,
"kindString": "Function",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 4,
"name": "add",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 5,
"name": "x",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 6,
"name": "y",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"sources": [
{
"fileName": "export-with-local.ts",
"line": 3,
"character": 19
}
]
}
],
"groups": [
{
"title": "Variables",
"kind": 32,
"children": [
2
]
},
{
"title": "Functions",
"kind": 64,
"children": [
3
]
}
],
"sources": [
{
"fileName": "export-with-local.ts",
"line": 1,
"character": 0
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
1
]
}
]
}
Loading