fix(compiler): collect non exported symbols in d.ts files (#19301)
TS treats all symbols in d.ts files as exported, whether they have an `export` keyword or not. PR Close #19301
This commit is contained in:
parent
b826e0c636
commit
62602b9bd8
@ -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 {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';
|
import {Symbols} from './symbols';
|
||||||
|
|
||||||
// In TypeScript 2.1 these flags moved
|
const isStatic = (node: ts.Node) => ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Static;
|
||||||
// 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)));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of collector options to use when collecting metadata.
|
* 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) =>
|
const isExportedIdentifier = (identifier?: ts.Identifier) =>
|
||||||
identifier && exportMap.has(identifier.text);
|
identifier && exportMap.has(identifier.text);
|
||||||
const isExported =
|
const isExported =
|
||||||
|
@ -30,6 +30,7 @@ describe('Collector', () => {
|
|||||||
'/unsupported-2.ts',
|
'/unsupported-2.ts',
|
||||||
'/unsupported-3.ts',
|
'/unsupported-3.ts',
|
||||||
'class-arity.ts',
|
'class-arity.ts',
|
||||||
|
'declarations.d.ts',
|
||||||
'import-star.ts',
|
'import-star.ts',
|
||||||
'exported-classes.ts',
|
'exported-classes.ts',
|
||||||
'exported-functions.ts',
|
'exported-functions.ts',
|
||||||
@ -67,6 +68,19 @@ describe('Collector', () => {
|
|||||||
expect(metadata).toBeUndefined();
|
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', () => {
|
it('should return an interface reference for types', () => {
|
||||||
const sourceFile = program.getSourceFile('/exported-type.ts');
|
const sourceFile = program.getSourceFile('/exported-type.ts');
|
||||||
const metadata = collector.getMetadata(sourceFile);
|
const metadata = collector.getMetadata(sourceFile);
|
||||||
@ -1237,6 +1251,10 @@ const FILES: Directory = {
|
|||||||
constructor(private f: common.NgFor) {}
|
constructor(private f: common.NgFor) {}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
|
'declarations.d.ts': `
|
||||||
|
declare class DeclaredClass {}
|
||||||
|
declare function declaredFn();
|
||||||
|
`,
|
||||||
'exported-classes.ts': `
|
'exported-classes.ts': `
|
||||||
export class SimpleClass {}
|
export class SimpleClass {}
|
||||||
export abstract class AbstractClass {}
|
export abstract class AbstractClass {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user