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

global is undefined in strict mode #324

Open
stkevintan opened this issue Jan 10, 2018 · 3 comments · May be fixed by #411 or #516
Open

global is undefined in strict mode #324

stkevintan opened this issue Jan 10, 2018 · 3 comments · May be fixed by #411 or #516

Comments

@stkevintan
Copy link

stkevintan commented Jan 10, 2018

I'm using lunr with es6 syntax which need babel to compile. but babel will always enable the strict mode which will make an error in following source code:

lunr.utils.warn = (function (global) {
  /* eslint-disable no-console */
  return function (message) {
    if (global.console && console.warn) {
      console.warn(message);
    }
  }
  /* eslint-enable no-console */
})(this);

this in strict mode will be undefined instead of the window object .

By the way, I don't understand why using global.console instead of console, is it necessary for some edge case?

@olivernn
Copy link
Owner

Sorry for the delay. I think the reason there is so much ceremony around a simple console.warn is to protect against environments that do not have access to console.

Without using global checking for the presence of console is difficult, e.g. just doing the following will lead to a ReferenceError:

if (console && console.warn) {
  // ..snip...
}

If there is a way to perform this check without being broken by strict mode?

@millette
Copy link

@olivernn

if ((typeof console !== 'undefined') && console.warn) {
  // ...
}

aciccarello added a commit to TypeStrong/typedoc-default-themes that referenced this issue Apr 28, 2019
aciccarello added a commit to TypeStrong/typedoc-default-themes that referenced this issue Apr 28, 2019
* add file references to ensure concat order

* remove strict modes

fixes lunr error
olivernn/lunr.js#324
@thealjey
Copy link

will this be addressed any time soon?

@indo-dev-0 indo-dev-0 linked a pull request Jul 28, 2019 that will close this issue
irnc added a commit to irnc/lunr.js that referenced this issue May 14, 2022
Fixes olivernn#324 (allowing lunr.js import as module and usage in other strict environments) by switching lunr itself to strict mode and fixing `this` usage.

`wrapper_end` was updated to the latest version of template, which uses `self` to access window and thus works in strict mode.

`lurn.utils.warn` was changed as in olivernn#411

Tests added work both in Node and browser.
@irnc irnc linked a pull request May 14, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants