From 821b7723b479fb8e9ff00bd57afc0d01c5e62529 Mon Sep 17 00:00:00 2001 From: Anthony Ciccarello Date: Mon, 12 Dec 2016 14:35:18 -0700 Subject: [PATCH] fix(facade/lang): support Node 6 and Windows environments (#182) Node 6 tries to name anonymous functions if assigned to a variable Windows adds a carriage return character to the end of line which shoud not be included by stringify --- src/facade/lang.ts | 2 +- test/facade/lang.spec.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/facade/lang.ts b/src/facade/lang.ts index 2de1b2f..d1b58dd 100644 --- a/src/facade/lang.ts +++ b/src/facade/lang.ts @@ -171,7 +171,7 @@ export function stringify( token ): string { var newLineIndex = res.indexOf( "\n" ); return (newLineIndex === -1) ? res - : res.substring( 0, newLineIndex ); + : res.substring( 0, newLineIndex ).replace('\r', ''); } /** diff --git a/test/facade/lang.spec.ts b/test/facade/lang.spec.ts index f0710e8..a29df45 100644 --- a/test/facade/lang.spec.ts +++ b/test/facade/lang.spec.ts @@ -72,14 +72,14 @@ describe( `facade/lang`, ()=> { it( 'should return first line string of function definition if the function is anonymous', ()=> { - let anonFn = function () {}; - let anonFnMultiLine = function () { + let anonFn = stringify(function () {}); + let anonFnMultiLine = stringify(function () { console.log( 'yoo' ); return null; - }; + }); - expect( stringify(anonFn) ).to.equal( 'function () { }' ); - expect( stringify(anonFnMultiLine) ).to.equal( 'function () {' ); + expect( anonFn ).to.equal( 'function () { }' ); + expect( anonFnMultiLine ).to.equal( 'function () {' ); } );