Skip to content

Commit

Permalink
fix(facade/lang): support Node 6 and Windows environments (#182)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aciccarello authored and Hotell committed Dec 12, 2016
1 parent 1abcac3 commit 821b772
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions test/facade/lang.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {' );

} );

Expand Down

0 comments on commit 821b772

Please sign in to comment.