Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflections in the root scope of a file are exported with --mode "file" #613

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/lib/converter/converter.ts
Expand Up @@ -11,6 +11,10 @@ import { CompilerHost } from './utils/compiler-host';
import { Component, Option, ChildableComponent, ComponentClass } from '../utils/component';
import { normalizePath } from '../utils/fs';

export enum SourceFileMode {
File, Modules
}

/**
* Result structure of the [[Converter.convert]] method.
*/
Expand Down Expand Up @@ -74,6 +78,18 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
})
excludePrivate: boolean;

@Option({
name: 'mode',
help: "Specifies the output mode the project is used to be compiled with: 'file' or 'modules'",
type: ParameterType.Map,
map: {
'file': SourceFileMode.File,
'modules': SourceFileMode.Modules
},
defaultValue: SourceFileMode.Modules
})
mode: SourceFileMode;

private compilerHost: CompilerHost;

private nodeConverters: {[syntaxKind: number]: ConverterNodeComponent<ts.Node>};
Expand Down
6 changes: 3 additions & 3 deletions src/lib/converter/factories/declaration.ts
@@ -1,8 +1,8 @@
import * as ts from 'typescript';

import { ReflectionKind, ReflectionFlag, ContainerReflection, DeclarationReflection } from '../../models/index';
import { ReflectionKind, ReflectionFlag, ContainerReflection, DeclarationReflection, ProjectReflection } from '../../models/index';
import { Context } from '../context';
import { Converter } from '../converter';
import { Converter, SourceFileMode } from '../converter';
import { createReferenceType } from './reference';

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ export function createDeclaration(context: Context, node: ts.Node, kind: Reflect
isExported = container.flags.isExported;
}

if (kind === ReflectionKind.ExternalModule) {
if (kind === ReflectionKind.ExternalModule || (container instanceof ProjectReflection && !context.isDeclaration && context.converter.mode === SourceFileMode.File)) {
isExported = true; // Always mark external modules as exported
} else if (node.parent && node.parent.kind === ts.SyntaxKind.VariableDeclarationList) {
const parentModifiers = ts.getCombinedModifierFlags(node.parent.parent);
Expand Down
21 changes: 2 additions & 19 deletions src/lib/converter/nodes/block.ts
Expand Up @@ -4,33 +4,16 @@ import { Reflection, ReflectionKind, ReflectionFlag } from '../../models/index';
import { createDeclaration } from '../factories/index';
import { Context } from '../context';
import { Component, ConverterNodeComponent } from '../components';
import { Option } from '../../utils/component';
import { ParameterType } from '../../utils/options/declaration';
import { SourceFileMode } from '../converter';

const prefered: ts.SyntaxKind[] = [
ts.SyntaxKind.ClassDeclaration,
ts.SyntaxKind.InterfaceDeclaration,
ts.SyntaxKind.EnumDeclaration
];

export enum SourceFileMode {
File, Modules
}

@Component({name: 'node:block'})
export class BlockConverter extends ConverterNodeComponent<ts.SourceFile|ts.Block|ts.ModuleBlock> {
@Option({
name: 'mode',
help: "Specifies the output mode the project is used to be compiled with: 'file' or 'modules'",
type: ParameterType.Map,
map: {
'file': SourceFileMode.File,
'modules': SourceFileMode.Modules
},
defaultValue: SourceFileMode.Modules
})
mode: number;

/**
* List of supported TypeScript syntax kinds.
*/
Expand Down Expand Up @@ -68,7 +51,7 @@ export class BlockConverter extends ConverterNodeComponent<ts.SourceFile|ts.Bloc
let result = context.scope;

context.withSourceFile(node, () => {
if (this.mode === SourceFileMode.Modules) {
if (this.owner.mode === SourceFileMode.Modules) {
result = createDeclaration(context, node, ReflectionKind.ExternalModule, node.fileName);
context.withScope(result, () => {
this.convertStatements(context, node);
Expand Down