Skip to content

Commit

Permalink
Fixed issue where nested object literals were getting skipped with --…
Browse files Browse the repository at this point in the history
…excludeNotExported
  • Loading branch information
alalonde committed Oct 1, 2019
1 parent 09a37f2 commit fd4f66f
Show file tree
Hide file tree
Showing 5 changed files with 759 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/converter/factories/declaration.ts
Expand Up @@ -56,6 +56,10 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
let isExported: boolean;
if (container.kindOf([ReflectionKind.Module, ReflectionKind.ExternalModule])) {
isExported = false; // Don't inherit exported state in modules and namespaces
} else if (container.kindOf([ReflectionKind.TypeLiteral]) && context.converter.excludeNotExported) {
// If the container for this is a type literal, it never had the
// isExported flag set on it. See https://github.com/TypeStrong/typedoc/issues/953
isExported = true;
} else {
isExported = container.flags.isExported;
}
Expand Down Expand Up @@ -108,7 +112,7 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
child.setFlag(ReflectionFlag.Static, isStatic);
child.setFlag(ReflectionFlag.Private, isPrivate);
child.setFlag(ReflectionFlag.ConstructorProperty, isConstructorProperty);
child.setFlag(ReflectionFlag.Exported, isExported);
child.setFlag(ReflectionFlag.Exported, isExported);
child = setupDeclaration(context, child, node);

if (child) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/converter.test.ts
Expand Up @@ -156,6 +156,7 @@ describe('Converter with excludeNotExported=true', function() {
const base = Path.join(__dirname, 'converter');
const exportWithLocalDir = Path.join(base, 'export-with-local');
const classDir = Path.join(base, 'class');
const literalsDir = Path.join(base, 'export-literals');
let app: Application;

before('constructs', function() {
Expand Down Expand Up @@ -204,4 +205,19 @@ describe('Converter with excludeNotExported=true', function() {
});
});

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

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

compareReflections(JSON.parse(data), specs);
});
});
});
20 changes: 20 additions & 0 deletions src/test/converter/export-literals/export-literals.ts
@@ -0,0 +1,20 @@
export interface INestedInterface
{
nestedOptional?: {
innerMember: string;
};

nested: {
isIncluded: boolean;
};
}

export function func(param: {nested: string}): boolean {
return param.nested === 'yes';
}

export function createSomething() {
return {
foo: 'bar'
};
}

0 comments on commit fd4f66f

Please sign in to comment.