Skip to content
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

Merged
merged 1 commit into from
Jul 18, 2020
Merged

use ES6 syntax #125

merged 1 commit into from
Jul 18, 2020

Conversation

davidchambers
Copy link
Owner

@davidchambers davidchambers commented Jun 17, 2020

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) to doctest (options) (path).

lib/doctest.js Outdated
Comment on lines 69 to 63
common.sanitizeFileContents (fs.readFileSync (path, 'utf8'))
(fs.readFileSync (path, 'utf8')
.replace (/\r\n?/g, '\n')
.replace (/^#!.*/, ''))
Copy link
Owner Author

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
Comment on lines 126 to 108
// 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)}})();`;
Copy link
Owner Author

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?

Comment on lines -552 to +533
repr = '! ' + name +
(expected.message && message.replace (/^(?!$)/, ': '));
repr = `! ${expected.message === '' ? name : either.value}`;
Copy link
Owner Author

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant