Skip to content

Allow for variable declarations in readonly-generated code#9659

Merged
Hamms merged 3 commits into
stagingfrom
variable-declarations-in-readonly-code
Jul 22, 2016
Merged

Allow for variable declarations in readonly-generated code#9659
Hamms merged 3 commits into
stagingfrom
variable-declarations-in-readonly-code

Conversation

@Hamms

@Hamms Hamms commented Jul 21, 2016

Copy link
Copy Markdown
Contributor

When generating code directly from XML, we use a helper that initializes
a new readonly blockspace, populates it with blocks, and generates code
from there. We would formerly accomplish this by populating the user's
working blockspace with the blocks, generating the code, and then
replacing the user's original blockspace, but this had some problems.

Unfortunately, the code generator, when scanning the code for variables
whose declaration it wants to pull up into the top of the block, only
considers the blocks in the main block space when looking for those
variables. This can lead to problems, as with course 4, stage 18

The simple fix is to have the generator directly scan for variables in
the blocks that it's using.

…[test all]

When generating code directly from XML, we use a helper that initializes
a new readonly blockspace, populates it with blocks, and generates code
from there. We would formerly accomplish this by populating the user's
working blockspace with the blocks, generating the code, and then
replacing the user's original blockspace, but this had some problems.

Unfortunately, the code generator, when scanning the code for variables
whose declaration it wants to pull up into the top of the block, only
considers the blocks in the main block space when looking for those
variables. This can lead to problems, as with [course 4, stage 18][1]

The simple fix is to have the generator directly scan for variables in
the blocks that it's using.

[1]: https://studio.code.org/s/course4/stage/18/puzzle/2
@Hamms Hamms force-pushed the variable-declarations-in-readonly-code branch from e3015c9 to 6b923cc Compare July 21, 2016 22:52
Comment thread blockly-core/generators/javascript.js Outdated

/**
* Initialise the database of variable names.
* @param {Array.<Blockly.Block>} opt_blocks Optional blocks to query for

@bcjordan bcjordan Jul 22, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Think you could bracket this like: [opt_blocks] to mark it optional in jsdoc

@bcjordan

Copy link
Copy Markdown
Contributor

LGTM

@Hamms

Hamms commented Jul 22, 2016

Copy link
Copy Markdown
Contributor Author

(manually canceled test run since I forgot to [ci skip] my documentation change)

Thanks!

@Hamms Hamms merged commit 143a94c into staging Jul 22, 2016
@Hamms Hamms deleted the variable-declarations-in-readonly-code branch July 22, 2016 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants