Skip to content

Commit

Permalink
chore(generators): Fix nits
Browse files Browse the repository at this point in the history
Addresses various nits that escaped previous PRs:

* Add TSDoc for `BlockGenerator` in `core/generator.ts` for PR google#7150.
* Fix bad formating in `generators/javascript.js` from PR google#7153.
* Add missing `@enum` tag that should have been included in PR google#7160.
* Delete obsolete comment from `generators/python.js` for PR google#7163.
  • Loading branch information
cpcallen committed Jun 14, 2023
1 parent 438df87 commit fccdd41
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ import {Names, NameType} from './names.js';
import type {Workspace} from './workspace.js';
import {warn} from './utils/deprecation.js';

/**
* Type declaration for per-block-type generator functions.
*
* @see {@link https://developers.google.com/blockly/guides/create-custom-blocks/generating-code}
* @param block The Block instance to generate code for.
* @returns A string containing the generated code (for statement blocks),
* or a [code, precedence] tuple (for value/expression blocks), or
* null if no code should be emitted for block.
*/
export type BlockGenerator = (block: Block) => [string, number] | string | null;

/**
Expand Down
1 change: 1 addition & 0 deletions generators/dart.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {inputTypes} from '../core/inputs/input_types.js';
/**
* Order of operation ENUMs.
* https://dart.dev/guides/language/language-tour#operators
* @enum {number}
*/
export const Order = {
ATOMIC: 0, // 0 "" ...
Expand Down
9 changes: 6 additions & 3 deletions generators/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export class JavascriptGenerator extends CodeGenerator {
// Add user variables, but only ones that are being used.
const variables = Variables.allUsedVarModels(workspace);
for (let i = 0; i < variables.length; i++) {
defvars.push(this.nameDB_.getName(variables[i].getId(), NameType.VARIABLE));
defvars.push(
this.nameDB_.getName(variables[i].getId(), NameType.VARIABLE));
}

// Declare all of the variables.
Expand Down Expand Up @@ -236,7 +237,8 @@ export class JavascriptGenerator extends CodeGenerator {
* Calls any statements following this block.
* @param {!Block} block The current block.
* @param {string} code The JavaScript code created for this block.
* @param {boolean=} opt_thisOnly True to generate code for only this statement.
* @param {boolean=} opt_thisOnly True to generate code for only this
* statement.
* @return {string} JavaScript code with comments and subsequent blocks added.
* @protected
*/
Expand Down Expand Up @@ -264,7 +266,8 @@ export class JavascriptGenerator extends CodeGenerator {
}
}
}
const nextBlock = block.nextConnection && block.nextConnection.targetBlock();
const nextBlock =
block.nextConnection && block.nextConnection.targetBlock();
const nextCode = opt_thisOnly ? '' : this.blockToCode(nextBlock);
return commentCode + code + nextCode;
}
Expand Down
1 change: 0 additions & 1 deletion generators/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export class PythonGenerator extends CodeGenerator {
* @protected
*/
quote_(string) {
// Can't use goog.string.quote since % must also be escaped.
string = string.replace(/\\/g, '\\\\').replace(/\n/g, '\\\n');

// Follow the CPython behaviour of repr() for a non-byte string.
Expand Down

0 comments on commit fccdd41

Please sign in to comment.