Skip to content

Fixing error with assigning to undeclared variable sourceIsEvt - #23

Merged
Amndeep7 merged 1 commit into
masterfrom
sourceIsEvt
Aug 23, 2023
Merged

Amndeep7 merged 1 commit into
masterfrom
sourceIsEvt

Conversation

@charleshu-8

Copy link
Copy Markdown
  • Fixes error that occurs when using Jsonix due to sourceIsEvt being undeclared before use in script.

@charleshu-8 charleshu-8 added the bug Something isn't working label Aug 22, 2023
@charleshu-8 charleshu-8 self-assigned this Aug 22, 2023
Comment thread nodejs/scripts/jsonix.js
// REWORK
// Node.js
sourceIsEvt = typeof window !== 'undefined' && window !== null && typeof window.Event === "function" && source instanceof window.Event;
var sourceIsEvt = typeof window !== 'undefined' && window !== null && typeof window.Event === "function" && source instanceof window.Event;

@Amndeep7 Amndeep7 Aug 22, 2023 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error occurred that prompted you to make this fix? What are the implications of declaring this variable? (Keep in mind that 'use "strict"' does not seem to be set here, so is the introduction of scope as opposed to it automatically being global causing an issue?)

Why did this commit in the weird other js dir do basically the opposite of what you're trying to do now? 8de7f1c

This change was also explicitly made in this commit in this same file: e6e58e6#diff-b77f70d3beb1864de2c1fb848006899f2f2a87b33e72c43980065cef33db3564

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Undeclared_var

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict mode is detecting a reference to an undeclared variable and is throwing this (it references the same error as the MDN page you linked):

Screenshot 2023-08-23 at 8 18 56 AM

I'm not sure why the opposite was performed in the original repo, but I see no reason why restricting its scope is detrimental given that it's only ever used in that one instance (albeit I don't know the implications of why it even is global to begin with).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it is true that the original author of the library explicitly removed the var declaration on this line of code. Other forks have added this back:

There are 7 forks having activity in the last two years (not counting ours). Of those, 5 forks have commits beyond the original. Of those 5 forks, 4 have updated this line to include the declaration.

All this to say, I do not see an issue with adding the declaration.

It would require a release to update .

@Amndeep7
Amndeep7 requested a review from Hookwitz August 22, 2023 20:35
Comment thread nodejs/scripts/jsonix.js
// REWORK
// Node.js
sourceIsEvt = typeof window !== 'undefined' && window !== null && typeof window.Event === "function" && source instanceof window.Event;
var sourceIsEvt = typeof window !== 'undefined' && window !== null && typeof window.Event === "function" && source instanceof window.Event;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it is true that the original author of the library explicitly removed the var declaration on this line of code. Other forks have added this back:

There are 7 forks having activity in the last two years (not counting ours). Of those, 5 forks have commits beyond the original. Of those 5 forks, 4 have updated this line to include the declaration.

All this to say, I do not see an issue with adding the declaration.

It would require a release to update .

@Amndeep7
Amndeep7 merged commit 030262a into master Aug 23, 2023
@Amndeep7
Amndeep7 deleted the sourceIsEvt branch August 23, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants