Skip to content

Commit

Permalink
fix(generators): Fix more minor inconsistencies in JS and Python
Browse files Browse the repository at this point in the history
The migration of the JavaScript and Python generators
inadvertently introduced some inconsistencies in the code,
e.g. putting executable code before the initial comment line that
most generator functions begin with.  This fixes another instance
of this (but n.b. that these inline comments should have been
JSDocs and a task has been added to #7600 to convert them).

Additionally, I noticed while doing the PHP migration that
ORDER_OVERRIDES was not typed as specifically as it could be,
in previous migrations, so this is fixed here (along with the
formatting of the associated JSDoc, which can fit on one line
now.)
  • Loading branch information
cpcallen committed Nov 13, 2023
1 parent e2100eb commit 40ede09
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions generators/javascript/javascript_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ export enum Order {
* JavaScript code generator class.
*/
export class JavascriptGenerator extends CodeGenerator {
/**
* List of outer-inner pairings that do NOT require parentheses.
*/
ORDER_OVERRIDES: number[][] = [
/** List of outer-inner pairings that do NOT require parentheses. */
ORDER_OVERRIDES: [Order, Order][] = [
// (foo()).bar -> foo().bar
// (foo())[0] -> foo()[0]
[Order.FUNCTION_CALL, Order.MEMBER],
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export function lists_getSublist(
block: Block,
generator: JavascriptGenerator,
): [string, Order] {
// Get sublist.
// Dictionary of WHEREn field choices and their CamelCase equivalents.
const wherePascalCase = {
'FIRST': 'First',
Expand All @@ -311,7 +312,6 @@ export function lists_getSublist(
'FROM_END': 'FromEnd',
};
type WhereOption = keyof typeof wherePascalCase;
// Get sublist.
const list = generator.valueToCode(block, 'LIST', Order.MEMBER) || '[]';
const where1 = block.getFieldValue('WHERE1') as WhereOption;
const where2 = block.getFieldValue('WHERE2') as WhereOption;
Expand Down
6 changes: 2 additions & 4 deletions generators/python/python_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ export enum Order {
* PythonScript code generator class.
*/
export class PythonGenerator extends CodeGenerator {
/**
* List of outer-inner pairings that do NOT require parentheses.
*/
ORDER_OVERRIDES: number[][] = [
/** List of outer-inner pairings that do NOT require parentheses. */
ORDER_OVERRIDES: [Order, Order][] = [
// (foo()).bar -> foo().bar
// (foo())[0] -> foo()[0]
[Order.FUNCTION_CALL, Order.MEMBER],
Expand Down

0 comments on commit 40ede09

Please sign in to comment.