-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Make constants.js have no side effects #5140
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
Make constants.js have no side effects #5140
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except specific points below and:
- Some of these files now definitely have invalid
goog.requiresordering. I've noted a couple of these below, but there are several more. Do you want to fix them in this PR? An open issue to fix this problem globally would be an acceptable alternative. - Have you run
clang-formaton the affected files (at leastcore/constants.jsandcore/internal_constants.js)?
I've filed #5158 to track breaking up and removing core/internal_constants.js in due course.
Aside: I found this PR a bit difficult to review. Part of this was just that it is a bit larger than the usual migrations, but it didn't help that some of the intermediate commits left it in an obviously-broken state. I think I'd have preferred if it had been presented with the first commit creating internal_constants.js and doing all of the associated changes to other files (including updating deps.js) without changing line breaks / indentation, followed by the usual sequence of commits for updating constants.js to goog.module and named requires, then a final clang-format of everything.
| /** | ||
| * @fileoverview Module that provides constants for use inside Blockly. Do not | ||
| * use these constants outside of the core library. | ||
| * @author fenichel@google.com (Rachel Fenichel) | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the whole file should be declared @package—see e.g..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| /** | ||
| * Lookup table for determining the opposite type of a connection. | ||
| * @const | ||
| */ | ||
| const OPPOSITE_TYPE = []; | ||
| OPPOSITE_TYPE[connectionTypes.INPUT_VALUE] = connectionTypes.OUTPUT_VALUE; | ||
| OPPOSITE_TYPE[connectionTypes.OUTPUT_VALUE] = connectionTypes.INPUT_VALUE; | ||
| OPPOSITE_TYPE[connectionTypes.NEXT_STATEMENT] = | ||
| connectionTypes.PREVIOUS_STATEMENT; | ||
| OPPOSITE_TYPE[connectionTypes.PREVIOUS_STATEMENT] = | ||
| connectionTypes.NEXT_STATEMENT; | ||
|
|
||
| exports.OPPOSITE_TYPE = OPPOSITE_TYPE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this clearly belongs in connection_type.js and it should probably have a better name. This is what motivated me to file #5158.
| if (blockA == blockB) { | ||
| return Connection.REASON_SELF_CONNECTION; | ||
| } else if (b.type != Blockly.OPPOSITE_TYPE[a.type]) { | ||
| } else if (b.type != OPPOSITE_TYPE[a.type]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks weird to me, but I've made a suggestion to fix it in #5158 so I don't think it merits further change in this PR.
| goog.require('Blockly.Block'); | ||
| /** @suppress {extraRequire} */ | ||
| goog.require('Blockly.constants'); | ||
| goog.require('Blockly.internalConstants'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require ordering.
| goog.require('Blockly.Events'); | ||
| /** @suppress {extraRequire} */ | ||
| goog.require('Blockly.Events.Click'); | ||
| goog.require('Blockly.internalConstants'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require ordering.
I have clang-format set to run on changed lines, which is something we as a team were doing before this big migration, but it sounds like that made things more confusing here. Since we're applying formatting to all files as we go, maybe I should turn it off for per-line changes and only run it in bulk on each file. I did not do a bulk clang-format of all of the files i touched--I left that to be done on a per-file basis as we do updates. |
9688dcc to
12636da
Compare
rachel-fenichel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased and made requested changes. I did not try to fix require orders in any file that had not yet been converted to named requires and did not clang-format those files, since that will all be done in per-file PRs.
I did run clang-format on constants.js and internal_constants.js.
| /** | ||
| * @fileoverview Module that provides constants for use inside Blockly. Do not | ||
| * use these constants outside of the core library. | ||
| * @author fenichel@google.com (Rachel Fenichel) | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Ordinarily I think that's a great idea (I have emacs configured to
Yes, sensible enough (and a good cause for me to pipe down about the format changes that did get made in these files, as I'd otherwise be complaining about them being left with overly-long lines). Can you confirm that what is left of |
|
(Oh, sorry: overnight my browser window had updated with your first reply but not the second one, and I forgot to hit reload. Thanks for confirming that the two migrated files are formatted!) |
The basics
goog_modulegoog_moduleconversion guide
npm test.The details
Resolves
Part of #5026
Proposed Changes
core/constants.jsto a module with es6 const/let.constants.js(any assignments to properties on theBlocklyobject).Blockly.internalConstants.blockly.jsfor all of these properties.Blockly.internalConstantsand use properties exported there.blocks/orgenerators/, as those are outside of core.goog.require('Blockly.constants')that were tagged with@suppress extraRequireAdditional Information
Follow-up work includes:
blockly.js) to decide which ones are not actually public, if any.