Skip to content
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

chore(generators): Fix nits #7166

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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