tjanczuk/edge — pull request #132 by atifaziz (2014-05-02 14:17:53+00:00)
Title: Allow trailing ws after source as JS comment

When an Edge function is created from source in a JS comment and there's trailing white space between the end of the comment and the closing brace of the function, like:

var getTop10Products = edge.func('sql', function () {
/*
select top 10 * from Products
*/
});

then you get the following run-time error message:

> If .NET source is provided as JavaScript function, function body must be a /* ... */ comment.

This change proposes to allow trailing space. Not only is it friendlier to formatting style differences but also *transcompilers* like TypeScript. For example, the following in TypeScript:

var getTop10Products = edge.func('sql', () => {/*
SELECT TOP 10 * FROM Series
*/});

doesn't work as it produces the following JavaScript:

var getTop10Products = edge.func('sql', function () {
});

To get the comment to appear in the output JavaScript, the `/*` need to go on the next line:

var getTop10Products = edge.func('sql', () => {
/*
SELECT TOP 10 * FROM Series
*/});

but now this yields white space around the comment in the output:

var getTop10Products = edge.func('sql', function () {
/*
SELECT TOP 10 * FROM Series
*/
});

Relaxing the regular expression used to extract the foreign source to allow trailing white space avoids unnecessary surprises, especially with transcompilers where the output formatting of the JavaScript may not be in control of the developer.