diff --git a/packages/compiler-cli/src/metadata/collector.ts b/packages/compiler-cli/src/metadata/collector.ts index b9b5f3a45b..218f8f8a8a 100644 --- a/packages/compiler-cli/src/metadata/collector.ts +++ b/packages/compiler-cli/src/metadata/collector.ts @@ -12,16 +12,7 @@ import {Evaluator, errorSymbol} from './evaluator'; import {ClassMetadata, ConstructorMetadata, FunctionMetadata, InterfaceMetadata, MemberMetadata, MetadataEntry, MetadataError, MetadataMap, MetadataSymbolicBinaryExpression, MetadataSymbolicCallExpression, MetadataSymbolicExpression, MetadataSymbolicIfExpression, MetadataSymbolicIndexExpression, MetadataSymbolicPrefixExpression, MetadataSymbolicReferenceExpression, MetadataSymbolicSelectExpression, MetadataSymbolicSpreadExpression, MetadataValue, MethodMetadata, ModuleExportMetadata, ModuleMetadata, VERSION, isClassMetadata, isConstructorMetadata, isFunctionMetadata, isMetadataError, isMetadataGlobalReferenceExpression, isMetadataSymbolicExpression, isMetadataSymbolicReferenceExpression, isMetadataSymbolicSelectExpression, isMethodMetadata} from './schema'; import {Symbols} from './symbols'; -// In TypeScript 2.1 these flags moved -// These helpers work for both 2.0 and 2.1. -const isExport = (ts as any).ModifierFlags ? - ((node: ts.Node) => - !!((ts as any).getCombinedModifierFlags(node) & (ts as any).ModifierFlags.Export)) : - ((node: ts.Node) => !!((node.flags & (ts as any).NodeFlags.Export))); -const isStatic = (ts as any).ModifierFlags ? - ((node: ts.Node) => - !!((ts as any).getCombinedModifierFlags(node) & (ts as any).ModifierFlags.Static)) : - ((node: ts.Node) => !!((node.flags & (ts as any).NodeFlags.Static))); +const isStatic = (node: ts.Node) => ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static; /** * A set of collector options to use when collecting metadata. @@ -284,6 +275,8 @@ export class MetadataCollector { } }); + const isExport = (node: ts.Node) => + sourceFile.isDeclarationFile || ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export; const isExportedIdentifier = (identifier?: ts.Identifier) => identifier && exportMap.has(identifier.text); const isExported = diff --git a/packages/compiler-cli/test/metadata/collector_spec.ts b/packages/compiler-cli/test/metadata/collector_spec.ts index 5282067278..e753e839b4 100644 --- a/packages/compiler-cli/test/metadata/collector_spec.ts +++ b/packages/compiler-cli/test/metadata/collector_spec.ts @@ -30,6 +30,7 @@ describe('Collector', () => { '/unsupported-2.ts', '/unsupported-3.ts', 'class-arity.ts', + 'declarations.d.ts', 'import-star.ts', 'exported-classes.ts', 'exported-functions.ts', @@ -67,6 +68,19 @@ describe('Collector', () => { expect(metadata).toBeUndefined(); }); + it('should treat all symbols of .d.ts files as exported', () => { + const sourceFile = program.getSourceFile('declarations.d.ts'); + const metadata = collector.getMetadata(sourceFile); + expect(metadata).toEqual({ + __symbolic: 'module', + version: 3, + metadata: { + DeclaredClass: {__symbolic: 'class'}, + declaredFn: {__symbolic: 'function'}, + } + }); + }); + it('should return an interface reference for types', () => { const sourceFile = program.getSourceFile('/exported-type.ts'); const metadata = collector.getMetadata(sourceFile); @@ -1237,6 +1251,10 @@ const FILES: Directory = { constructor(private f: common.NgFor) {} } `, + 'declarations.d.ts': ` + declare class DeclaredClass {} + declare function declaredFn(); + `, 'exported-classes.ts': ` export class SimpleClass {} export abstract class AbstractClass {}