-
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
use ES6 syntax #125
use ES6 syntax #125
Conversation
lib/doctest.js
Outdated
common.sanitizeFileContents (fs.readFileSync (path, 'utf8')) | ||
(fs.readFileSync (path, 'utf8') | ||
.replace (/\r\n?/g, '\n') | ||
.replace (/^#!.*/, '')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to duplicate this small amount of code to allow lib/common.js to be deleted. Template strings obviate the need for unlines
, so sanitizeFileContents
was the only remaining shared function.
lib/doctest.js
Outdated
// iifeWrap :: String -> String | ||
function iifeWrap(s) { | ||
return 'void function() {\n' + indentN (2, s) + '}.call(this);'; | ||
} | ||
// arrowWrap :: String -> String | ||
const arrowWrap = s => `void (() => {\n${indentN (2, s)}})();`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see any reason not to use an immediately invoked arrow function rather than an immediately invoked function expression?
repr = '! ' + name + | ||
(expected.message && message.replace (/^(?!$)/, ': ')); | ||
repr = `! ${expected.message === '' ? name : either.value}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we want to use the <name>: <message>
format we can simply use `! ${either.value}`
, since Error.prototype.toString
uses this format.
Every version of Node.js we now target supports ES6 features. This means we can now use arrow functions, template strings, and
const
to simplify and improve the codebase.Strictly speaking this is a breaking change, due to changes to
--print
output. In practice, though, users should be unaffected.Edit: This pull request now changes the JavaScript interface from
doctest (path, options)
todoctest (options) (path)
.