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

Modernize JavaScript code #264

Open
emaxx-google opened this issue Nov 11, 2020 · 1 comment
Open

Modernize JavaScript code #264

emaxx-google opened this issue Nov 11, 2020 · 1 comment

Comments

@emaxx-google
Copy link
Collaborator

Currently, the JavaScript code in this repository follows pretty old guidelines (in some aspects, a few-years-old one). The code doesn't conform to the current Google JavaScript Style Guide (https://google.github.io/styleguide/jsguide.html) in several aspects, most notably:

  • Instead of modules, the goog.require+goog.provide combination is used.
  • Instead of const/let, var is used.
  • Instead of JavaScript classes, functions with the @constructor annotations are used.
@emaxx-google
Copy link
Collaborator Author

Besides just cleaning up the code, fixing this will also allow us to update to recent versions of Closure Compiler and Closure Library. Currently we're blocked, since the recent versions of Closure Compiler require the usage of JS modules.

emaxx-google added a commit that referenced this issue Jul 23, 2021
Add missing goog.require() statements into the JS code where needed.
Older versions of Closure Compiler were somewhat relaxed in requiring
these imports, but newer do require all of them to be explicitly
require()'ed.

This contributes to the JS modernization effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 26, 2021
Add missing goog.require() statements into the JS code where needed.
Older versions of Closure Compiler were somewhat relaxed in requiring
these imports, but newer do require all of them to be explicitly
require()'ed.

This contributes to the JS modernization effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 26, 2021
Change the format-code.shdeveloper script to also automatically reformat
any change JavaScript file.

In the past, all JS code written in this repository was formatted
manually. The plan is to switch to the clang-based automatic formatting,
and the first step on this route is to apply it to every changed file.

This contributes to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 27, 2021
Change the format-code.sh developer script to also automatically reformat
any change JavaScript file.

In the past, all JS code written in this repository was formatted
manually. The plan is to switch to the clang-based automatic formatting,
and the first step on this route is to apply it to every changed file.

This contributes to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 27, 2021
Modernize the JavaScript code by using "let"/"const" instead
of "var".

This is intended to be a non-functional change that contributes
to the effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 27, 2021
Reformat all JavaScript code written in this repository to use the
clang-format's "Chromium" formatting style.

This is intended to be a non-functional change that contributes
to the effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 27, 2021
Reformat all JavaScript code written in this repository to use the
clang-format's "Chromium" formatting style.

This is intended to be a non-functional change that contributes
to the effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 27, 2021
Refactor JavaScript code to use Array.isArray() instead of
goog.isArray().

goog.isArray() got deprecated and removed from the Closure Library.

This contributes to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 27, 2021
Refactor JavaScript code to use goog.functions.isFunction()
instead of goog.isFunction().

goog.isFunction() got deprecated and removed from the recent
versions of the Closure Library; for whatever reason, they decided to
add a synonym "goog.functions.isFunction".

This change contributes to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 28, 2021
Refactor JavaScript code to use Array.isArray() instead of
goog.isArray().

goog.isArray() got deprecated and removed from the recent
versions of the Closure Library.

This is intended to be a non-functional change that contributes
to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 28, 2021
Refactor JavaScript code to use goog.functions.isFunction()
instead of goog.isFunction().

goog.isFunction() got deprecated and removed from the recent
versions of the Closure Library; for whatever reason, they decided to
add a synonym "goog.functions.isFunction".

This change contributes to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 28, 2021
Refactor JavaScript code to use goog.functions.isFunction()
instead of goog.isFunction().

goog.isFunction() got deprecated and removed from the recent
versions of the Closure Library; for whatever reason, they decided to
add a synonym "goog.functions.isFunction".

This is expected to be a non-functional change that contributes
to the refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 28, 2021
Refactor JavaScript code to specify "@const" for all class attributes
that are never reassigned. Also promote the "jsdocMissingConst" Closure
Compiler diagnostic, which complained about private properties that can
be marked as @const, to be an error.

This is intended to be a non-function change, contributing to the
refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 28, 2021
Fix a couple of occasions in the JavaScript code where a private member
wasn't marked as such (via @Private).

This is expected to be a non-function change, which contributes to the
refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 29, 2021
Fix a couple of occasions in the JavaScript code where a private member
wasn't marked as such (via "@Private").

This is expected to be a non-function change, which contributes to the
refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 29, 2021
Refactor JavaScript code to specify "@const" for all class attributes
that are never reassigned. Also promote the "jsdocMissingConst" Closure
Compiler diagnostic, which complained about private properties that can
be marked as @const, to be an error.

This is intended to be a non-function change, contributing to the
refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jul 29, 2021
Stop using the old-style Closure Compiler classes and switch to modern
ES6 classes. Code was *not* reformatted, in order to make the diff
readable; later there'll be a separate commit that'll apply clang-tidy.

A brief overview of the changes:
* Instead of declaring the class by marking a function with
  "@constructor", the "class" ES6 keyword is used.
* Instead of using goog.inherits() for declaring the inheritance, the
  "extends" ES6 keyword is used.
* Static properties are first defined as file-global constants and only
  then copied into the class; this allows using them in the class code,
  since the old-style "this.someConstant" access doesn't work anymore.
  (A side note: ES6 class static properties aren't supported by Closure
  Compiler yet.)
* Calls to the parent class' methods are done via super() instead of the
  Closure Compiler's base() method.

This is expected to be a non-functional change. It contributes to the
refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Aug 4, 2021
Stop using the old-style Closure Compiler classes and switch to modern
ES6 classes. Code was *not* reformatted, in order to make the diff
readable; later there'll be a separate commit that'll apply clang-format.

A brief overview of the changes done here:
* Instead of declaring the class by marking a function with
  "@constructor", the "class" ES6 keyword is used.
* Instead of using goog.inherits() for declaring the inheritance, the
  "extends" ES6 keyword is used.
* Static properties are first defined as file-global constants and only
  then copied into the class; this allows using them in the class code,
  since the old-style "this.someConstant" access doesn't work anymore.
  (A side note: ES6 class static properties aren't supported by Closure
  Compiler yet.)
* Calls to the parent class' methods are done via super() instead of the
  Closure Compiler's base() method.
* Nested classes are moved outside to be separate classes, since
  nesting isn't supported in ES6 classes.

This is expected to be a non-functional change. It contributes to the
refactoring effort tracked by #264.
emaxx-google added a commit that referenced this issue Jan 26, 2022
Refactor the UserPromptingChecker JavaScript class to use
"async"/"await", which greatly simplifies the asynchronous code in this
code.

This contributes to the JS modernization effort tracked by #264.
emaxx-google added a commit that referenced this issue Jan 26, 2022
Refactor the UserPromptingChecker JavaScript class to use
"async"/"await", which greatly simplifies the asynchronous code in this
code.

This contributes to the JS modernization effort tracked by #264.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant