Skip to content

fix: use getVariableName in JavaScript and Dart generator init - #10602

Closed
Jojoussef wants to merge 1 commit into
RaspberryPiFoundation:mainfrom
Jojoussef:fix/2506-generator-variable-names
Closed

Jojoussef wants to merge 1 commit into
RaspberryPiFoundation:mainfrom
Jojoussef:fix/2506-generator-variable-names

Conversation

@Jojoussef

Copy link
Copy Markdown

The basics

The details

Resolves

Fixes #2506

Proposed Changes

In JavascriptGenerator.prototype.init and DartGenerator.prototype.init, use this.getVariableName(variables[i].getId()) instead of directly querying this.nameDB_.getName(variables[i].getId(), NameType.VARIABLE).

Reason for Changes

When a developer subclasses JavascriptGenerator or DartGenerator and overrides getVariableName() to customize how variable identifiers are formatted or generated, the variable declaration list (var ...;) in init() was previously bypassing getVariableName() and reading from nameDB_ directly.
This change ensures that variable declarations respect getVariableName(), aligning JavaScript and Dart generators with the existing pattern already used in PythonGenerator.prototype.init.

Test Coverage

Added unit tests in packages/blockly/tests/mocha/generator_test.js:

  • Subclassed JavascriptGenerator, DartGenerator, and PythonGenerator with an overridden getVariableName().
  • Verified that variable declarations generated in init() use the custom names returned by getVariableName().
  • Verified all 25 mocha generator tests pass.
  • Verified npm run lint and npm run format pass cleanly.

Documentation

None needed; internal generator consistency fix preserving existing public APIs.

Additional Information

Prepared with AI assistance on behalf of Youssef Benatti.

@Jojoussef
Jojoussef requested a review from a team as a code owner October 20, 2026 22:49
@Jojoussef
Jojoussef requested a review from lizschwab October 20, 2026 22:49
@github-actions github-actions Bot added the PR: fix Fixes a bug label Oct 20, 2026

@github-actions github-actions Bot left a comment

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.

Welcome! It looks like this is your first pull request in Blockly, so here are a couple of tips:

  • You can find tips about contributing to Blockly and how to validate your changes on our developer site.
  • We use conventional commits to make versioning the package easier. Make sure your commit message is in the proper format or learn how to fix it.
  • If any of the other checks on this PR fail, you can click on them to learn why. It might be that your change caused a test failure, or that you need to double-check the style guide.
    Thank you for opening this PR! A member of the Blockly team will review it soon.

@zspriggs zspriggs self-assigned this Oct 21, 2026
@zspriggs

Copy link
Copy Markdown
Contributor

Hi @Jojoussef, thank you for your interest in contributing to Blockly! Unfortunately, we do not allow AI preparation of PRs that resolve a good first issue. For more information, please read our AI policy. Feel free to open another PR for this issue if you'd like to try to write it yourself. Thanks!

@zspriggs zspriggs closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow developers to create separate display names and generated names for variables

3 participants