Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect typeof checks in a few places causing unintended behaviour #5483

Closed
jokeyrhyme opened this issue May 1, 2020 · 2 comments
Closed

Comments

@jokeyrhyme
Copy link

Describe the bug

moment's code include incorrect uses of typeof that are causing the Symbol support check to fail in Node.js 0.10.x, and maybe causing issues with the use of __dirname

moment.js
2093:                    (typeof __dirname !== undefined ? __dirname : '.') +
4917:    if (typeof Symbol !== undefined && Symbol.for != null) {

min/moment-with-locales.js
2087:                    (typeof __dirname !== undefined ? __dirname : '.') +
4911:    if (typeof Symbol !== undefined && Symbol.for != null) {

src/lib/moment/prototype.js
61:if (typeof Symbol !== undefined && Symbol.for != null) {

src/lib/locale/locales.js
79:                (typeof __dirname !== undefined ? __dirname : '.') +

Note that typeof returns a string, and the above checks are comparing the result of typeof against the undefined value, not the "undefined" string

To Reproduce
Steps to reproduce the behavior:

  1. require('moment') using a version of Node.js that doesn't implement Symbol
  2. observe the following error:
if (typeof Symbol !== undefined && Symbol.for != null) {
ReferenceError: Symbol is not defined

Expected behavior
This should load just fine without any exceptions or errors

Screenshots
n/a

@jokeyrhyme
Copy link
Author

ESLint has a rule to check for invalid uses of typeof that you may find useful: https://eslint.org/docs/rules/valid-typeof

@ichernev
Copy link
Contributor

ichernev commented May 1, 2020

@jokeyrhyme we have eslint and we use "extends": "eslint:recommended" and it still didn't catch it. Maybe you can investigate.

I'll fix the typeof problems and release shortly.

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

No branches or pull requests

2 participants