diff --git a/tools/@angular/tsc-wrapped/src/collector.ts b/tools/@angular/tsc-wrapped/src/collector.ts index 694814dcaa..6534dd310e 100644 --- a/tools/@angular/tsc-wrapped/src/collector.ts +++ b/tools/@angular/tsc-wrapped/src/collector.ts @@ -377,7 +377,7 @@ export class MetadataCollector { // Record functions that return a single value. Record the parameter // names substitution will be performed by the StaticReflector. const functionDeclaration = node; - if (isExported(functionDeclaration)) { + if (isExported(functionDeclaration) && functionDeclaration.name) { if (!metadata) metadata = {}; const name = exportedName(functionDeclaration); const maybeFunc = maybeGetSimpleFunction(functionDeclaration); diff --git a/tools/@angular/tsc-wrapped/test/collector.spec.ts b/tools/@angular/tsc-wrapped/test/collector.spec.ts index 89e8caee87..7ff8d70750 100644 --- a/tools/@angular/tsc-wrapped/test/collector.spec.ts +++ b/tools/@angular/tsc-wrapped/test/collector.spec.ts @@ -634,10 +634,6 @@ describe('Collector', () => { }); describe('with interpolations', () => { - function createSource(text: string): ts.SourceFile { - return ts.createSourceFile('', text, ts.ScriptTarget.Latest, true); - } - function e(expr: string, prefix?: string) { const source = createSource(`${prefix || ''} export let value = ${expr};`); const metadata = collector.getMetadata(source); @@ -821,17 +817,53 @@ describe('Collector', () => { describe('regerssion', () => { it('should be able to collect a short-hand property value', () => { - const source = ts.createSourceFile( - '', ` + const source = createSource(` const children = { f1: 1 }; export const r = [ {path: ':locale', children} ]; - `, - ts.ScriptTarget.Latest, true); + `); const metadata = collector.getMetadata(source); expect(metadata.metadata).toEqual({r: [{path: ':locale', children: {f1: 1}}]}); }); + + // #17518 + it('should skip a default function', () => { + const source = createSource(` + export default function () { + + const mainRoutes = [ + {name: 'a', abstract: true, component: 'main'}, + + {name: 'a.welcome', url: '/welcome', component: 'welcome'} + ]; + + return mainRoutes; + + }`); + const metadata = collector.getMetadata(source); + expect(metadata).toBeUndefined(); + }); + + it('should skip a named default export', () => { + const source = createSource(` + function mainRoutes() { + + const mainRoutes = [ + {name: 'a', abstract: true, component: 'main'}, + + {name: 'a.welcome', url: '/welcome', component: 'welcome'} + ]; + + return mainRoutes; + + } + + exports = foo; + `); + const metadata = collector.getMetadata(source); + expect(metadata).toBeUndefined(); + }); }); function override(fileName: string, content: string) { @@ -1321,3 +1353,7 @@ const FILES: Directory = { } } }; + +function createSource(text: string): ts.SourceFile { + return ts.createSourceFile('', text, ts.ScriptTarget.Latest, true); +}