From a8881b41a7b9d860fcc254df77edaa67011d7977 Mon Sep 17 00:00:00 2001 From: Vincent Ogloblinsky Date: Fri, 12 Oct 2018 15:50:22 -0400 Subject: [PATCH] fix(deps): unnamed function fix #668 --- src/app/application.ts | 128 ++++++++++++------ src/app/compiler/angular-dependencies.ts | 3 +- test/src/cli/cli-generation-big-app.spec.ts | 5 + .../shared/miscellaneous/unnamed-function.ts | 14 ++ 4 files changed, 104 insertions(+), 46 deletions(-) create mode 100644 test/src/todomvc-ng2/src/app/shared/miscellaneous/unnamed-function.ts diff --git a/src/app/application.ts b/src/app/application.ts index 7e7b1047..4bb35abb 100644 --- a/src/app/application.ts +++ b/src/app/application.ts @@ -2528,56 +2528,84 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`); if (errorCopy) { logger.error('Error during resources copy ', errorCopy); } else { - if (this.configuration.mainData.extTheme) { - fs.copy( - path.resolve( - process.cwd() + path.sep + this.configuration.mainData.extTheme - ), - path.resolve(finalOutput + '/styles/'), - function(errorCopyTheme) { - if (errorCopyTheme) { - logger.error( - 'Error during external styling theme copy ', - errorCopyTheme - ); - } else { - logger.info('External styling theme copy succeeded'); - onComplete(); - } + + const extThemePromise = new Promise( + (extThemeResolve, extThemeReject) => { + if (this.configuration.mainData.extTheme) { + fs.copy( + path.resolve( + process.cwd() + + path.sep + + this.configuration.mainData.extTheme + ), + path.resolve(finalOutput + '/styles/'), + function(errorCopyTheme) { + if (errorCopyTheme) { + logger.error( + 'Error during external styling theme copy ', + errorCopyTheme + ); + extThemeReject(); + } else { + logger.info( + 'External styling theme copy succeeded' + ); + extThemeResolve(); + } + } + ); + } else { + extThemeResolve(); } - ); - } else { - if (this.configuration.mainData.customFavicon !== '') { - logger.info(`Custom favicon supplied`); - fs.copy( - path.resolve( - process.cwd() + - path.sep + - this.configuration.mainData.customFavicon - ), - path.resolve(finalOutput + '/images/favicon.ico'), - errorCopyFavicon => { - // tslint:disable-line - if (errorCopyFavicon) { - logger.error( - 'Error during resources copy of favicon', - errorCopyFavicon - ); - } else { - onComplete(); + } + ); + + const customFaviconPromise = new Promise( + (customFaviconResolve, customFaviconReject) => { + if ( + this.configuration.mainData.customFavicon !== '' + ) { + logger.info(`Custom favicon supplied`); + fs.copy( + path.resolve( + process.cwd() + + path.sep + + this.configuration.mainData + .customFavicon + ), + path.resolve( + finalOutput + '/images/favicon.ico' + ), + errorCopyFavicon => { + // tslint:disable-line + if (errorCopyFavicon) { + logger.error( + 'Error during resources copy of favicon', + errorCopyFavicon + ); + customFaviconReject(); + } else { + logger.info( + 'External custom favicon copy succeeded' + ); + customFaviconResolve(); + } } - } - ); - } else { - onComplete(); + ); + } else { + customFaviconResolve(); + } } + ); + + const customLogoPromise = new Promise((customLogoResolve, customLogoReject) => { if (this.configuration.mainData.customLogo !== '') { logger.info(`Custom logo supplied`); fs.copy( path.resolve( process.cwd() + - path.sep + - this.configuration.mainData.customLogo + path.sep + + this.configuration.mainData.customLogo ), path.resolve(finalOutput + '/images/logo.png'), errorCopyLogo => { @@ -2587,15 +2615,25 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`); 'Error during resources copy of logo', errorCopyLogo ); + customLogoReject(); } else { - onComplete(); + logger.info('External custom logo copy succeeded'); + customLogoResolve(); } } ); } else { - onComplete(); + customLogoResolve(); } - } + }); + + Promise.all([ + extThemePromise, + customFaviconPromise, + customLogoPromise + ]).then(() => { + onComplete(); + }); } } ); diff --git a/src/app/compiler/angular-dependencies.ts b/src/app/compiler/angular-dependencies.ts index 497dd808..dc9e02d2 100644 --- a/src/app/compiler/angular-dependencies.ts +++ b/src/app/compiler/angular-dependencies.ts @@ -1046,8 +1046,9 @@ export class AngularDependencies extends FrameworkDependencies { } private visitFunctionDeclaration(method: ts.FunctionDeclaration) { + let methodName = method.name ? method.name.text : 'Unnamed function'; let result: any = { - name: method.name.text, + name: methodName, args: method.parameters ? method.parameters.map(prop => this.visitArgument(prop)) : [] }; let jsdoctags = this.jsdocParserUtil.getJSDocs(method); diff --git a/test/src/cli/cli-generation-big-app.spec.ts b/test/src/cli/cli-generation-big-app.spec.ts index 1d1048c2..c67fd202 100644 --- a/test/src/cli/cli-generation-big-app.spec.ts +++ b/test/src/cli/cli-generation-big-app.spec.ts @@ -725,4 +725,9 @@ describe('CLI simple generation - big app', () => { let file = read(distFolder + '/components/AppComponent.html'); expect(file).to.contain('openSomeDialog(model,'); }); + + it('correct support unnamed function', () => { + let file = read(distFolder + '/miscellaneous/functions.html'); + expect(file).to.contain('Unnamed'); + }); }); diff --git a/test/src/todomvc-ng2/src/app/shared/miscellaneous/unnamed-function.ts b/test/src/todomvc-ng2/src/app/shared/miscellaneous/unnamed-function.ts new file mode 100644 index 00000000..19bfec4f --- /dev/null +++ b/test/src/todomvc-ng2/src/app/shared/miscellaneous/unnamed-function.ts @@ -0,0 +1,14 @@ +export default function(value) { + const hexTable = []; + for (let i = 0; i < 256; i++) { + hexTable[i] = (i <= 15 ? '0' : '') + i.toString(16); + } + + const id = Object.keys(value.id).map(key => value.id[key]); + + let hexString = ''; + for (const el of id) { + hexString += hexTable[el]; + } + return hexString; +}