99import * as ts from 'typescript' ;
1010
1111import { Evaluator , errorSymbol , isPrimitive } from './evaluator' ;
12- import { ClassMetadata , ConstructorMetadata , FunctionMetadata , MemberMetadata , MetadataEntry , MetadataError , MetadataMap , MetadataObject , 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' ;
12+ import { ClassMetadata , ConstructorMetadata , FunctionMetadata , 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' ;
1313import { Symbols } from './symbols' ;
1414
1515
@@ -234,6 +234,7 @@ export class MetadataCollector {
234234 }
235235 }
236236 break ;
237+
237238 case ts . SyntaxKind . FunctionDeclaration :
238239 if ( ! ( node . flags & ts . NodeFlags . Export ) ) {
239240 // Report references to this function as an error.
@@ -249,22 +250,36 @@ export class MetadataCollector {
249250 break ;
250251 }
251252 } ) ;
253+
252254 ts . forEachChild ( sourceFile , node => {
253255 switch ( node . kind ) {
254256 case ts . SyntaxKind . ExportDeclaration :
255257 // Record export declarations
256258 const exportDeclaration = < ts . ExportDeclaration > node ;
257- const moduleSpecifier = exportDeclaration . moduleSpecifier ;
259+ const { moduleSpecifier, exportClause} = exportDeclaration ;
260+
261+ if ( ! moduleSpecifier ) {
262+ // no module specifier -> export {propName as name};
263+ if ( exportClause ) {
264+ exportClause . elements . forEach ( spec => {
265+ const name = spec . name . text ;
266+ const propNode = spec . propertyName || spec . name ;
267+ const value : MetadataValue = evaluator . evaluateNode ( propNode ) ;
268+ if ( ! metadata ) metadata = { } ;
269+ metadata [ name ] = recordEntry ( value , node ) ;
270+ } ) ;
271+ }
272+ }
273+
258274 if ( moduleSpecifier && moduleSpecifier . kind == ts . SyntaxKind . StringLiteral ) {
259275 // Ignore exports that don't have string literals as exports.
260276 // This is allowed by the syntax but will be flagged as an error by the type checker.
261277 const from = ( < ts . StringLiteral > moduleSpecifier ) . text ;
262278 const moduleExport : ModuleExportMetadata = { from} ;
263- if ( exportDeclaration . exportClause ) {
264- moduleExport . export = exportDeclaration . exportClause . elements . map (
265- element => element . propertyName ?
266- { name : element . propertyName . text , as : element . name . text } :
267- element . name . text ) ;
279+ if ( exportClause ) {
280+ moduleExport . export = exportClause . elements . map (
281+ spec => spec . propertyName ? { name : spec . propertyName . text , as : spec . name . text } :
282+ spec . name . text ) ;
268283 }
269284 if ( ! exports ) exports = [ ] ;
270285 exports . push ( moduleExport ) ;
@@ -281,6 +296,7 @@ export class MetadataCollector {
281296 }
282297 // Otherwise don't record metadata for the class.
283298 break ;
299+
284300 case ts . SyntaxKind . FunctionDeclaration :
285301 // Record functions that return a single value. Record the parameter
286302 // names substitution will be performed by the StaticReflector.
@@ -297,6 +313,7 @@ export class MetadataCollector {
297313 }
298314 }
299315 break ;
316+
300317 case ts . SyntaxKind . EnumDeclaration :
301318 if ( node . flags & ts . NodeFlags . Export ) {
302319 const enumDeclaration = < ts . EnumDeclaration > node ;
@@ -332,14 +349,15 @@ export class MetadataCollector {
332349 } else {
333350 nextDefaultValue =
334351 recordEntry ( errorSym ( 'Unsuppported enum member name' , member . name ) , node ) ;
335- } ;
352+ }
336353 }
337354 if ( writtenMembers ) {
338355 if ( ! metadata ) metadata = { } ;
339356 metadata [ enumName ] = recordEntry ( enumValueHolder , node ) ;
340357 }
341358 }
342359 break ;
360+
343361 case ts . SyntaxKind . VariableStatement :
344362 const variableStatement = < ts . VariableStatement > node ;
345363 for ( const variableDeclaration of variableStatement . declarationList . declarations ) {
@@ -373,7 +391,7 @@ export class MetadataCollector {
373391 }
374392 } else {
375393 // Destructuring (or binding) declarations are not supported,
376- // var {<identifier>[, <identifer >]+} = <expression>;
394+ // var {<identifier>[, <identifier >]+} = <expression>;
377395 // or
378396 // var [<identifier>[, <identifier }+] = <expression>;
379397 // are not supported.
0 commit comments