Uh oh!
There was an error while loading. Please reload this page.
refactor(generators)!: CodeGenerator per-block-type generator function dictionary - #7150
Merged
Merged
Conversation
Add a dictionary of block generator functions, provisionally called .forBlock. Look up generator functions there first, but fall back to looking up on 'this' (with deprecation notice) for backwards compatibility. Also tweak error message generation to use template literal.
cpcallen
commented
Jun 12, 2023
CollaboratorAuthor
Investigating test failure, which reproduces locally. I am slightly confused because it is caused by the change to |
cpcallen
commented
Jun 13, 2023
CollaboratorAuthor
Turns out test in |
BREAKING CHANGE: this PR moves the generator functions we provide from their previous location directly on the CodeGenerator instances to the new .forBlock dictionary on each instance. The change in the previous commit does not oblige external developers to do the same for their custom generators, but they will need to update any code that references the generator functions we provide in generators/*/* (e.g. to reuse one of our functions for a different block type).
Have the blockToCodeTest helper function delete the block generator functions it adds to generator once the test is done.
The use of generators in insertion_marker_test.js was overlooked in the earlier commit making such updates, and some test here were failing due to lack of cleanup in cleanup in the generator_test.js.
CodeGenerator per-block-type generator function dictionaryCodeGenerator per-block-type generator function dictionarycpcallen
commented
Jun 13, 2023
CollaboratorAuthor
Force-push (and title edit) to make commits conventional. |
maribethb
approved these changes
Jun 13, 2023
Uh oh!
There was an error while loading. Please reload this page.
4 tasks
cpcallen added a commit
to cpcallen/blockly
that referenced
this pull request
Jun 14, 2023
Addresses various nits that escaped previous PRs: * Add TSDoc for `BlockGenerator` in `core/generator.ts` for PR RaspberryPiFoundation#7150. * Fix bad formating in `generators/javascript.js` from PR RaspberryPiFoundation#7153. * Add missing `@enum` tag that should have been included in PR RaspberryPiFoundation#7160. * Delete obsolete comment from `generators/python.js` for PR RaspberryPiFoundation#7163.
cpcallen added a commit
that referenced
this pull request
Jun 14, 2023
Addresses various nits that escaped previous PRs: * Add TSDoc for `BlockGenerator` in `core/generator.ts` for PR #7150. * Fix bad formating in `generators/javascript.js` from PR #7153. * Add missing `@enum` tag that should have been included in PR #7160. * Delete obsolete comment from `generators/python.js` for PR #7163.
cpcallen added a commit
to cpcallen/blockly
that referenced
this pull request
Jun 27, 2023
This is mostly just chore updating to the new import names (e.g. BlocklyJavaScript -> javascript.javascriptGenerator), but the change to Code.checkAllGeneratorFunctionsDefined is a necessary fix due to the breaking change in PR RaspberryPiFoundation#7150, implementing the .forBlock dictionary.
4 tasks
cpcallen added a commit
that referenced
this pull request
Jun 27, 2023
This is mostly just chore updating to the new import names (e.g. BlocklyJavaScript -> javascript.javascriptGenerator), but the change to Code.checkAllGeneratorFunctionsDefined is a necessary fix due to the breaking change in PR #7150, implementing the .forBlock dictionary.
4 tasks
8 tasks
Merged
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The basics
npm run formatandnpm run lintThe details
Resolves
Fixes#7084
Proposed Changes
Implements per-block-type generator function dictionary, per proposal #7084.
Behaviour Before Change
CodeGenerator.prototype.blockToCodeuses generator function atthis[block_type].Behaviour After Change
CodeGenerator.prototype.blockToCodepreferentially uses generator function atthis.forBlock[block_type], falling back tothis[block_type]if the former does not exist (and issuing a deprecation warning if the latter does).Code in
generators/*/*is updated to install generator functions at the new location.Reason for Changes
See #7084.
Test Coverage
No changes to manual test procedures anticipated.
Documentation
We should update our generator demos/codelabs to use the new dictionary.
Additional Information
DEPRECATION: as of this PR, adding per-block generator function directly to
CodeGeneratorinstances is deprecated; they should instead be added to the generator's.forBlockdictionary—i.e., existing code of the form:should be updated to:
although the former style will continue to be supported at least until until Blockly v11.
BREAKING CHANGE: this PR prioritises the new
.forBlockdictionary when doing lookups, and moves the generator functions we provide from their previous location directly on theCodeGeneratorinstances to the new.forBlockdictionary on each instance.Most existing custom generator code should continue to work unchanged for the time being, but any code that references the generator functions we provide—e.g. to replace an implementation we provide or to reuse the implementation for a different block type—will need to be updated:
must be updated to: