Commit Graph

246 Commits

Author SHA1 Message Date
Aaron Dodson
b8f71b83b7 Merge branch 'rc/v12.0.0' into develop-v12-merge 2025-03-11 09:42:25 -07:00
michaela-mm
d016801089 fix: Fix bug in IF block generators. (#8780) 2025-02-24 14:35:33 +00:00
Aaron Dodson
9fcd5a3037 release: Merge branch 'rc/v11.2.0' into rc/v12.0.0 2024-12-04 12:06:12 -08:00
Christopher Allen
ce22f42868 chore: Organise imports (#8527)
* chore(deps): Add pretter-plugin-organize-imports

* chore: Remove insignificant blank lines in import sections

  Since prettier-plugin-organize-imports sorts imports within
  sections separated by blank lines, but preserves the section
  divisions, remove any blank lines that are not dividing imports
  into meaningful sections.

  Do not remove blank lines separating side-effect-only imports
  from main imports.

* chore: Remove unneded eslint-disable directives

* chore: Organise imports
2024-08-15 03:16:14 +01:00
Aaron Dodson
294ef74d1b refactor: Use IVariableModel instead of VariableModel. (#8400)
* refactor: Use IVariableModel methods instead of directly accessing properties.

* refactor: replace references to VariableModel with IVariableModel.
2024-07-19 14:58:04 -07:00
Maribeth Bottorff
b7cdeffccd chore: merge develop into rc/v11 2024-04-01 14:57:19 -07:00
Neil Fraser
5a6f22f0f3 feat!: Throw errors on missing inputs (#7969)
Previously generators could generate code from inputs that didn't exist and get back the empty string.  This silent failure was causing problems for diagnosing issues.  This PR changes the behaviour so that an error is thrown.

This will break generators which rely on the previous behaviour.  Several of our demo blocks needed editing to accomodate this change.

Resolves #7665
2024-03-28 23:53:57 +01:00
Neil Fraser
2ea9e21e6d chore: Clean up variable assignment. (#7962)
* chore: Clean up variable assignment.

* fix: variable now const as a result of prev commit
2024-03-26 19:13:52 +01:00
Christopher Allen
10ffcb706d release: Merge branch 'develop' into rc/v11.0.0 2024-03-18 19:57:04 +00:00
Christopher Allen
a6208d78b7 fix(generators): Make scrub_ public (#7940)
Fixes #2156.

In PRs #7602, #7616, #7646, #7647 and #7654 the @protected
access modifier on scrub_ on the CodeGenerator subclasses
was not transcribed to the new typescript signature.  I was
going to re-add it, but this breaks some of the procedure
block generator functions which rely on it, and then
@BeksOmega pointed out that this might be one of the
CodeGenerator API functions which we had already decided
should be public—and lo and behold I found #2156.

Per discussion amongst team, I am not renaming it to
scrub at this time.
2024-03-15 22:01:46 +00:00
Neil Fraser
0ecbcde9fc chore: Use .includes and .startsWith, not .indexOf (#7936)
Easier to read than the diverse collection of `=== 0` and `!== -1` and `> -1` tests.
2024-03-15 00:03:55 +01:00
Rachel Fenichel
67c3aae76c feat!: delete angle, colour, and multiline input fields and blocks (#7932)
* chore: delete mocha tests for angle field

* feat! : delete angle field

* chore(tests): delete colour tests from generator tests and golden files

* chore: delete colour blocks and associated generators

* chore: remove colour blocks from playgrounds

* chore: delete mocha tests for colour fields

* chore: fix incorrect comment

* chore: delete colour field from core

* chore: delete multiline input tests from generators tests and golden files

* chore: delete multiline text block and associated generators

* chore: remove multiline text block from playgrounds

* chore: delete mocha tests for multiline input field

* chore: delete multiline input field from core
2024-03-13 13:28:26 -07:00
Beka Westberg
ad0c0e36bd fix: lua generators using None instead of nil (#7837) 2024-02-07 10:00:09 -08:00
Christopher Allen
7bda30924a refactor(generators): Migrate PHP generators to TypeScript (#7647)
* refactor(generators): Migrate dart_generator.js to TypeScript

* refactor(generators): Simplify getAdjusted

  Slightly simplify the implementation of getAdjusted, in part to
  make it more readable.  Also improve its JSDoc comment.

* refactor(generators): Migrate generators/php/* to TypeScript

  First pass doing very mechanistic migration, not attempting to fix
  all the resulting type errors.

* fix(generators): Fix type errors in generator functions

  This consists almost entirely of adding casts, so the code output
  by tsc should be as similar as possible to the pre-migration .js
  source files.

* fix(generators): Fix more minor inconsistencies in JS and Python

  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.)

* refactor(generators): Migrate generators/php.js to TypeScript

  The way the generator functions are added to
  phpGenerator.forBlock has been modified so that incorrect
  generator function signatures will cause tsc to generate a type
  error.

* chore(generator): Format

  One block protected with // prettier-ignore to preserve careful
  comment formatting.

  Where there are repeated concatenations prettier has made a pretty
  mess of things, but the correct fix is probably to use template
  literals instead (rather than just locally disabling prettier).
  This is one of the items in the to-do list in #7600.

* docs(generators): @fileoverview -> @file

  With an update to the wording for generators/php.ts.

* fix(generators): Fixes for PR #7647.

  - Don't declare unused wherePascalCase dictionary.
  - Don't allow null in OPERATOR dictionary when not needed.
  - Fix return type (and documentation thereof) of getAdjusted.
2023-11-28 16:59:19 +00:00
Christopher Allen
b198e2f4ae fix(generators): Improve consistency of migrated language generators (#7662)
* docs(generators): @fileoverview -> @file; delete @suppress

* fix(generators): Fix return type of getAdjusted

  And improve its documentation too.

  Fix the @returns doc for PythonGenerator's getAdjustedInt but
  (for now) don't change the type because it does actually
  return numbers in some circumstances.
2023-11-28 16:57:31 +00:00
Blake Thomas Williams
dc61e487b4 refactor(generators): Migrate Lua generators to TypeScript (#7654)
* refactor(generators): Migrate lua_generator.js to TypeScript

* refactor(generators): Migrate generators/lua/* to TypeScript

* fix(generators): Fix type errors in generator functions

* refactor(generators): Migrate generators/lua.js to TypeScript

* chore(generator): Format

* chore(generators): JSDoc and formatting tweaks for PR #7654

---------

Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2023-11-20 18:46:32 +00:00
Christopher Allen
81b427f4ad refactor(generators): Migrate Dart generators to TypeScript (#7646)
* refactor(generators): Migrate dart_generator.js to TypeScript

* refactor(generators): Simplify getAdjusted

  Slightly simplify the implementation of getAdjusted, in part to
  make it more readable.  Also improve its JSDoc comment.

* refactor(generators): Migrate generators/dart/* to TypeScript

  First pass doing very mechanistic migration, not attempting to fix
  all the resulting type errors.

* fix(generators): Fix type errors in generator functions

  This consists almost entirely of adding casts, so the code output
  by tsc should be as similar as possible to the pre-migration .js
  source files.

* fix(generators): Fix minor inconsistencies in JS and Python

  The migration of the JavaScript and Python generators
  inadvertently introduced some inconsistencies in the code,
  e.g.:

  - Incorrect import ordering.
  - Putting executable code before the initial comment line that
    most generator functions begin with, and/or deleting or
    replacing these comments.
    -  N.B. however that these inline comments should have been
       JSDocs; a task to convert them has been added to #7600.

* refactor(generators): Migrate generators/dart.js to TypeScript

  The way the generator functions are added to
  dartGenerator.forBlock has been modified so that incorrect
  generator function signatures will cause tsc to generate a type
  error.

* chore(generator): Format

  One block protected with // prettier-ignore to preserve careful
  comment formatting.

  Where there are repeated concatenations prettier has made a pretty
  mess of things, but the correct fix is probably to use template
  literals instead (rather than just locally disabling prettier).
  This is one of the items in the to-do list in #7600.

* fix(generators): Fix for PR #7646
2023-11-14 16:13:50 +00:00
Christopher Allen
b418907e41 refactor(generators): Migrate Python generators to TypeScript #7602 (#7617)
* refactor(generators): Migrate python_generator.js to TypeScript

* refactor(generators): Migrate generators/python/* to TypeScript

  First pass doing very mechanistic migration, not attempting to fix
  all the resulting type errors.

* fix(generators): Fix type errors in generator functions

  This consists almost entirely of adding casts, so the code output
  by tsc should be as similar as possible to the pre-migration .js
  source files.

* refactor(generators): Migrate generators/python.js to TypeScript

  The way the generator functions are added to
  pythonGenerator.forBlock has been modified so that incorrect
  generator function signatures will cause tsc to generate a type
  error.

* chore(generator): Format

  One block protected with // prettier-ignore to preserve careful
  comment formatting.

  Where there are repeated concatenations prettier has made a pretty
  mess of things, but the correct fix is probably to use template
  literals instead (rather than just locally disabling prettier).
  This is one of the items in the to-do list in #7600.
2023-11-11 18:03:35 +00:00
Christopher Allen
4ab8d00099 refactor(generators): Migrate JavaScript generators to TypeScript (#7602)
* refactor(generators): Migrate javascript_generator.js to TypeScript

* refactor(generators): Simplify getAdjusted

  Slightly simplify the implementation of getAdjusted, in part to
  make it more readable.  Also improve its JSDoc comment.

* refactor(generators): Migrate generators/javascript/* to TypeScript

  First pass doing very mechanistic migration, not attempting to fix
  all the resulting type errors.

* fix(generators): Fix type errors in generator functions

  This consists almost entirely of adding casts, so the code output
  by tsc should be as similar as possible to the pre-migration .js
  source files.

* refactor(generators): Migrate generators/javascript.js to TypeScript

  The way the generator functions are added to
  javascriptGenerator.forBlock has been modified so that incorrect
  generator function signatures will cause tsc to generate a type
  error.

* chore(generator): Format

  One block protected with // prettier-ignore to preserve careful
  comment formatting.

  Where there are repeated concatenations prettier has made a pretty
  mess of things, but the correct fix is probably to use template
  literals instead (rather than just locally disabling prettier).
  This has been added to the to-do list in #7600.

* fix(generators): Fixes for PR #7602

* fix(generators): Fix syntax error
2023-10-30 08:16:13 +00:00
Maribeth Bottorff
68261e5dd9 feat: add getVariableName and getProcedureName to CodeGenerator (#7445)
* feat: add getVariableName and getProcedureName to CodeGenerator

* feat: make nameDB_ public

* feat: update block code generators to use new APIs

* chore: fix build

* chore: remove unused imports
2023-08-31 10:49:17 -07:00
Christopher Allen
b0a7c004a9 refactor(build): Delete Closure Library (#7415)
* fix(build): Restore erroneously-deleted filter function

  This was deleted in PR #7406 as it was mainly being used to
  filter core/ vs. test/mocha/ deps into separate deps files -
  but it turns out also to be used for filtering error
  messages too.  Oops.

* refactor(tests): Migrate advanced compilation test to ES Modules

* refactor(build): Migrate main.js to TypeScript

  This turns out to be pretty straight forward, even if it would
  cause crashing if one actually tried to import this module
  instead of just feeding it to Closure Compiler.

* chore(build): Remove goog.declareModuleId calls

  Replace goog.declareModuleId calls with a comment recording the
  former module ID for posterity (or at least until we decide
  how to reformat the renamings file.

* chore(tests): Delete closure/goog/*

  For the moment we still need something to serve as base.js for
  the benefit of closure-make-deps, so we keep a vestigial
  base.js around, containing only the @provideGoog declaration.

* refactor(build): Remove vestigial base.js

  By changing slightly the command line arguments to
  closure-make-deps and closure-calculate-chunks the need to have
  any base.js is eliminated.

* chore: Typo fix for PR #7415
2023-08-31 00:24:47 +01:00
Beka Westberg
a0301a217a feat: make generator quoting methods public (#7392)
* feat: make quoting methods public

* feat: add quote and multilineQuote methods

* fix: update code generators to use new methods

* chore: remove aliases

* chore: revert changes to generators
2023-08-21 09:05:23 -07:00
Christopher Allen
d503fbb409 fix(generators): Changes to exports and access controls for TypeScript compatibility (#7295)
* fix(generators): Add missing declarations for Order enums

* chore(generators): Remove spurious whitespace

* fix(generators): Make provideFunction_ etc. public

  Remove the protected declaration on provideFunction_ and
  FUNCTION_NAME_PLACEHOLDER_ so they can be used from generator
  functions written in TypeScript.

  Not strictly part of #7283, but closely related and required to
  fixing the related issue google/blockly-samples#1785.

* chore(generators): format
2023-07-17 20:40:27 +01:00
Christopher Allen
130989763c refactor(generators): Restructure generator modules to contain side effects (#7173)
* refactor(generators): Move lang.js -> lang/lang_gernator.js

  Move the LangGenerator definitions into their respective
  subdirectories and add a _generator suffix to their filenames,
  i.e. generators/javascript.js  becomes
  generators/javascript/javascript_generator.js.

  This is to keep related code together and allow the `lang/all.js`
  entrypoints to be moved to the top level generators/ directory.

  No goog module IDs were changed, so playground and test code
  that accesses this modules by filename does not need to be modified.

* refactor(generators) Move lang/all.js -> lang.js

  - Move the entrypoints in generators/*/all.js to correspondingly-named
    files in generators/ instead—i.e., generators/javascript/all.js
    becomes generators/javascript.js.

  - Update build_tasks.js accordingly.

* fix(generators): Add missing exports for LuaGenerator, PhpGenerator

  These were inadvertently omitted from #7161 and #7162, respectively.

* refactor(generators): Make block generator modules side-effect free

  - Move declaration of <lang>Generator instance from
    generators/<lang>/<lang>_generator.js to generators/<lang>.js.
  - Move .addReservedWords() calls from generators/<lang>/*.js to
    generators/<lang>.js
  - Modify generators/<lang>/*.js to export block generator functions
    individually, rather than installing on <lang>Generator instance.
  - Modify generators/<lang>.js to import and install block generator
    functions on <lang>Generator instance.

* fix(tests): Fix tests broken by restructuring of generators

  Where these tests needed block generator functions preinstalled
  they should have been importing the Blockly.<Lang>.all module.

  Where they do not need the provided block generator functions
  they can now create their own empty <Lang>Generator instances.

* chore: Update renamings file

  - Fix a malformation in previous entries that was not detected by
    the renaming file validator test.
  - Add entries describing the work done in this and related recent
    PRs.

* fix: Correct minor errors in PR #7173

  - Fix a search-and-replace error in renamings.json5
  - Fix an incorrect-but-usable import in generator_test.js
2023-06-20 23:22:44 +01:00
Christopher Allen
a3458871db refactor(generators)!: Pass this CodeGenerator to individual generator functions (#7168)
* feat(generators): Pass this CodeGenerator to generator functions

  This implements option 1A of proposal 1 of #7086.

  This commit is not by itself a breaking change, except in the unlikely event that
  developers' custom generator functions take an (optional) second argument of a
  dfferent type.

* feat(generators): Accept generator argument in block functions

  Accept a CodeGenerator instance as parameter two of every
  per-block-type generator function.

* fix(generators): Pass generator when calling other generator functions

  Make sure to pass generator to any other block functions that are
  called recursively.

* refactor(generators)!: Use generator argument in generator functions

  Refactor per-block-type generator functions to use the provided
  generator argument to make recursive calls, rather than depending
  on the closed-over <lang>Generator instance.

  This allows generator functions to be moved between CodeGenerator
  instances (of the same language, at least).

  This commit was created by search-and-replace and addresses most
  but not all recursive references; remaining uses will require
  manual attention and will be dealt with in a following commit.

  BREAKING CHANGE: This commit makes the generator functions we provide
  dependent on the new generator parameter.  Although
  CodeGenerator.prototype.blockToCode has been modified to supply this,
  so this change will not affect most developers, this change will be a
  breaking change where developers make direct calls to these generator
  functions without supplying the generator parameter.  See previous
  commit for an example of the update required.

* refactor(generators): Manual fix for remaining uses of langGenerator

  Manually replace remaining uses of <lang>Generator in block
  generator functions.

* fix(generators): Delete duplicate procedures_callnoreturn generator

  For some reason the generator function for procedures_callnoreturn
  appears twice in generators/javascript/procedures.js.  Delete the
  first copy (since the second one overwrote it anyway).

* chore(generators): Format
2023-06-14 23:25:36 +01:00
Christopher Allen
12b91ae49c chore(generators): Fix nits (#7166)
Addresses various nits that escaped previous PRs:

* Add TSDoc for `BlockGenerator` in `core/generator.ts` for PR #7150.
* Fix bad formating in `generators/javascript.js` from PR #7153.
* Add missing `@enum` tag that should have been included in PR #7160.
* Delete obsolete comment from `generators/python.js` for PR #7163.
2023-06-14 22:17:38 +01:00
Christopher Allen
a11419d6b7 refactor(generators): Introduce LuaGenerator class, Order enum (#7161)
* refactor(generators): Introduce LuaGenerator class, Order enum

* refactor(generators): Use Order.* instead of .ORDER_*

* refactor(generators): Don't rename luaGenerator
2023-06-14 09:11:37 -07:00
Christopher Allen
eeb89194c4 refactor(generators): Introduce PhpGenerator class, Order enum (#7162)
* refactor(generators): Introduce PhpGenerator class, Order enum

* refactor(generators): Use Order.* instead of .ORDER_*

* refactor(generators): Don't rename phpGenerator
2023-06-14 09:09:52 -07:00
Christopher Allen
2f89c0dd09 refactor(generators): Introduce PythonGenerator class, Order enum (#7163)
* refactor(generators): Introduce PhpGenerator class, Order enum

* refactor(generators): Use Order.* instead of .ORDER_*

* refactor(generators): Don't rename pythonGenerator
2023-06-14 08:51:15 -07:00
Christopher Allen
26901654ea refactor(generators): Introduce DartGenerator class, Order enum (#7160)
* refactor(generators): Introduce DartGenerator class, Order enum

* refactor(generators): Use Order.* instead of .ORDER_*

* refactor(generators): Don't rename dartGenerator
2023-06-14 00:39:12 +01:00
Christopher Allen
22a7a7bbab chore(generators): Comment tweak for PR #7153 (#7156) 2023-06-13 21:14:11 +00:00
Christopher Allen
306eb80216 refactor(generators): Introduce JavascriptGenerator class, Order enum (#7153)
* refactor(generators): Introduce class JavascriptGenerator

  Also fix an import ordering error.

* refactor(generators): Use Order.* instead of .ORDER_*

* refactor(generators): Don't rename javascriptGenerator
2023-06-13 21:30:37 +01:00
Christopher Allen
f9c865b1b3 refactor(generators)!: CodeGenerator per-block-type generator function dictionary (#7150)
* feat(generators): Add block generator function dictionary

  Add a dictionary of block generator functions, provisionally
  called .forBlock.  Look up generator functions there first, but
  fall back to looking up on 'this' (with deprecation notice)
  for backwards compatibility.

  Also tweak error message generation to use template literal.

* refactor(generators)!: Update generator definitions to use dictionary

* fix(tests): Have blockToCodeTest clean up after itself

  Have the blockToCodeTest helper function delete the block generator
  functions it adds to generator once the test is done.

* refactor(tests): Use generator dictionary in insertion marker test

  The use of generators in insertion_marker_test.js was overlooked
  in the earlier commit making such updates, and some test here
  were failing due to lack of cleanup in
  cleanup in the generator_test.js.

BREAKING CHANGE: this PR moves the generator functions we provide
from their previous location directly on the CodeGenerator instances
to the new .forBlock dictionary on each instance. This does not oblige
external developers to do the same for their custom generators, but
they will need to update any code that references the generator
functions we provide (in generators/*/*, i.e. on javascriptGenerator,
dartGenerator etc.) e.g. to replace the implementation or reuse the
implementation for a different block type.
2023-06-13 20:41:14 +01:00
Christopher Allen
4d2201a427 chore(generators): Migrate generators to ES Modules (#7103)
* feat(j2ts): Add support for migrating renaming imports

  Convert
      const {foo: bar} = require(/*...*/);
  into
      import {foo as bar} from /*...*/;
              ^^^^^^^^^^

  Also fix a bug that caused relative paths to ESM in the same
  directory to be missing a leading "./".

* fix(build): Fix trivial error exports for generators

  The UMD wrapper was inadvertently exporting the contents of (e.g.)
  the Blockly.JavaScript closure module rather than the intended
  export of Blockly.JavaScript.all module - which went unnoticed
  because the latter just reexported the former - but we are
  about to convert the former to ESM.

* chore(generators): Migrate language generators to ESM

  Migrate the main language generators in generators/*.js to ESM.

  This was done by running js2ts on the files, renaming them back
  to .js, and commenting out "import type" statements, which are
  legal TS but not needed in JS (at least if you are not actually
  letting Closure Compiler do type checking, which we are not.)

* chore(generators): Migrate block generators to ESM

  Migrate generators/*/*.js (except all.js) to ESM.

  This was done by running js2ts on the files, renaming them back
  to .js, and removing now-spurious @suppress {extraRequire}
  directives.

* chores(generators): Migrate generator chunk entrypoints to ESM

  This was done by running js2ts on the files, renaming them back
  to .js, and manually fixing the export statements.

  An additional change to the chunk exports configuration in
  build_tasks.js was necessary in order for the UMD wrapper to
  find the new module object, which is given a different name
  than the old exports object.
2023-05-19 23:09:37 +01:00
Neil Fraser
42fde0f81b chore: Reduce delta on ports to blockly-samples (#6886)
* Reduce usage of obsolete .keyCode property.
* Rename private properties/methods which violate eslint rules.
* Use arrays of bound events rather than individual properties.
* Improve typing info.
* Also fix O(n^2) recursive performance issue in theme's getComponentStyle function.
* And replace String(...) with '${...}' (smaller, faster).
* .toString() is considered harmful.
2023-03-15 13:28:57 -07:00
Neil Fraser
e90aba9273 fix: Rename Generator to CodeGenerator (#6585)
Stops collisions with ES6's Generator.
The old Blockly.Generator still exists as a name, but is now deprecated.
2022-10-28 01:59:00 +02:00
Maribeth Bottorff
224af0aa6b fix: remove deprecated use of objectUtils from generators (#6499) 2022-10-06 13:05:00 -07:00
Neil Fraser
5612e13824 fix: Remove float() coercion in Python loops (#6259)
Coercion to a float is a very JavaScript thing to do, Python is not JavaScript.

From this discussion:
https://groups.google.com/g/blockly/c/OF_j9rKQgpI
2022-07-06 08:46:10 -07:00
Christopher Allen
f947b3f4f6 refactor!: Remove remaining use of goog.module.declareLegacyNamespace. (#6254)
* fix(build): Minor corrections to build_tasks.js

  - Use TSC_OUTPUT_DIR to find goog/goog.js when suppressing warnings.
  - Remove unnecessary trailing semicolons.

* refactor(blocks): Remove declareLegacyNamespace

  Remove the call to goog.module.declareLegacyNamespace from
  Blockly.libraryBlocks.  This entails:

  - Changes to the UMD wrapper to be able to find the exports object.
  - Changes to tests/bootstrap_helper.js to save the exports object
    in the libraryBlocks global variable.
  - As a precaution, renaming the tests/compile/test_blocks.js module
    so that goog.provide does not touch Blockly or
    Blockly.libraryBlocks, which may not exist / be writable.

  * feat(build): Add support named exports from chunks

  We need to convert the generators to named exports.  For backwards
  compatibility we still want e.g. Blockly.JavaScript to point at
  the generator object when the chunk is loaded using a script tag.

  Modify chunkWrapper to honour a .reexportOnly property in the
  chunks table and generate suitable additional code in the UMD
  wrapper.

* refactor(generators): Migrate JavaScript generator to named export

  - Export the JavaScript generator object as javascriptGenerator
    from the Blockly.JavaScript module(generators/javascript.js).

  - Modify the Blockly.JavaScript.all module
    (generators/javascript/all.js) to reexport the exports from
    Blockly.JavaScript.

  - Update chunk configuration so the generator object remains
    available as Blockly.JavaScript when loading
    javascript_compressed.js via a <script> tag.

    (N.B. it is otherwise necessary to destructure the require
    / import.)

  - Modify bootstrap_helper.js to store that export as
    window.javascriptGenerator for use in test code.

  - Modify test code to use javascriptGenerator instead of
    Blockly.JavaScript.

  - Modify .eslintrc.json so that javascriptGenerator is allowed
    as a global in test/.  (Also restrict use of Blockly global
    to test/.)

  N.B. that demo code in demos/code/code.js uses <script> tag
  loading and so will continue to access Blockly.JavaScript.

* refactor(generators): Migrate Lua generator to named export

* refactor(generators): Migrate PHP generator to named export

* refactor(generators): Migrate Python generator to named export

* refactor(generators): Remove declareLegacyNamespace calls

  Remove the goog.module.declareLegacyNamespace calls from the
  generators.

  This turns out to have the unexpected side-effect of causing the
  compiler to rename the core/blockly.js exports object from
  $.Blockly to just Blockly in blockly_compressed.js - presumably
  because it no longer needs to be accessed in any subsequent chunk
  because they no longer add properties to it.  This requires
  some changes (mainly simplification) to the chunkWrapper function
  in build_tasks.js.

* refactor(core): Remove declareLegacyNamespace from blockly.js

  So easy to do _now_: just need to:

  - Make sure the UMD wrapper for the first chunk knows where the
    exports object is.
  - Use that same value to set the Blockly.VERSION @define.
  - Have bootstrap_helper.js set window.Blockly to the exports
    object.
  - Fix tests/compile/test_blocks.js to not assume a Blockly
    global variable, by converting it to a goog.module so we
    can use a named require.
2022-06-30 19:53:32 +01:00
gregdyke
706c2bfd41 fix: provide initial values to reduce functions in generated js (#6178) 2022-05-31 09:22:34 -07:00
Christopher Allen
3e19aded39 chore(generators): Don't add unnecessary escapes (#6161)
Closure Compiler was complaining about unnecessary backslashes in
template literals, so remove them.
2022-05-12 16:50:01 +01:00
Neil Fraser
b7cd2e187b chore: Remove Blockly.utils.global (#6120)
The Closure Compiler creates globalThis as a pollyfill.
2022-04-28 12:39:52 -07:00
Neil Fraser
1f6a1bd8d9 chore: Use ES6 template strings in CSS and code generators (#5902)
* Unindent CSS, save 3 kb of code.
* Convert generator functions to template strings. 
This resolves #5761.
2022-01-28 17:58:43 -08:00
Richard Doherty
a31003fab9 fix(generators): Fix an operator precedence issue in the math_number_property generators to remove extra parentheses (#5685)
* Fixed issue where the mathIsPrime function inserted extra parenthesis around certain blocks.
* Added tests to generated JS
* Updated generated code in Lua
* Updated Generated code for tests in Dart
* Updated generated code for tests in PHP
* Updated generated code for tests in Python
* Also changed var to const and let.

Co-authored-by: jeremyjacob123 <43049656+jeremyjacob123@users.noreply.github.com>
Co-authored-by: LouisCatala <86700310+LouisCatala@users.noreply.github.com>
Co-authored-by: jeremyjacob123 <43049656+jeremyjacob123@users.noreply.github.com>
2022-01-27 15:54:05 +00:00
Rachel Fenichel
931499295e refactor: convert python block generators to goog.module (#5771)
* refactor: convert generators/python/colour.js to goog.module

* refactor: convert generators/python/colour.js to named requires

* chore: run clang-format

* refactor: convert generators/python/lists.js to goog.module

* refactor: convert generators/python/lists.js to named requires

* chore: run clang-format

* refactor: convert generators/python/logic.js to goog.module

* refactor: convert generators/python/logic.js to named requires

* chore: run clang-format

* refactor: convert generators/python/loops.js to goog.module

* refactor: convert generators/python/loops.js to named requires

* chore: run clang-format

* refactor: convert generators/python/math.js to goog.module

* refactor: convert generators/python/math.js to named requires

* chore: run clang-format

* refactor: convert generators/python/procedures.js to goog.module

* refactor: convert generators/python/procedures.js to named requires

* chore: run clang-format

* refactor: convert generators/python/text.js to goog.module

* refactor: convert generators/python/text.js to named requires

* chore: run clang-format

* refactor: convert generators/python/variables_dynamic.js to named requires

* refactor: convert generators/python/variables.js to named requires

* chore: run clang-format

* refactor: convert generators/python.js to goog.module

* refactor: convert generators/python.js to named requires

* chore: run clang-format

* chore: remove spurious @private annotations

* chore: rebuild
2021-12-01 20:43:08 -08:00
Rachel Fenichel
c0517ea360 refactor: convert some block generators to goog.module (#5770)
* refactor: convert generators/lua.js to goog.module

* refactor: convert generator/lua.js to named requires

* chore: run clang-format

* refactor: convert generators/php/colour.js to goog.module

* refactor: convert generators/php/colour.js to named requires

* chore: run clang-format

* refactor: convert generators/php/lists.js to goog.module

* refactor: convert generators/php/lists.js to named requires

* chore: run clang-format

* refactor: convert generators/php/logic.js to goog.module

* refactor: convert generators/php/logic.js to named requires

* chore: run clang-format

* refactor: convert generators/php/loops.js to goog.module

* refactor: convert generators/php/loops.js to named requires

* chore: run clang-format

* refactor: convert generators/php/math.js to goog.module

* refactor: convert generators/php/math.js to named requires

* chore: run clang-format

* refactor: convert generators/php/procedures.js to goog.module

* refactor: convert generators/php/procedures.js to named requires

* chore: run clang-format

* refactor: convert generators/php/text.js to goog.module

* refactor: convert generators/php/text.js to named requires

* chore: run clang-format

* refactor: convert generators/php/variables.js to goog.module

* refactor: convert generators/php/variables.js to named requires

* chore: run clang-format

* refactor: convert generators/php/variables_dynamic.js to goog.module

* refactor: convert generators/php/variables_dynamic.js to named requires

* refactor: convert generators/php.js to goog.module

* refactor: convert generators/php.js to named requires

* chore: run clang-format

* chore: rebuild deps.js
2021-12-01 17:59:20 -08:00
Rachel Fenichel
a939fec53b refactor: convert some block generators to goog.module (#5769)
* refactor: convert generators/lua/colour.js to goog.module

* refactor: convert generators/lua/colour.js to named requires

* chore: run clang-format

* refactor: convert generators/lua/lists.js to goog.module

* refactor: convert generators/lua/lists.js to named requires

* chore: run clang-format

* fix: use getListIndex helper function in lua list generators

* refactor: convert generators/lua/logic.js to goog.module

* refactor: convert generators/lua/logic.js to named requires

* chore: run clang-format

* refactor: convert generators/lua/loops.js to goog.module

* refactor: convert generators/lua/loops.js to named requires

* chore: run clang-format

* refactor: convert generators/lua/math.js to goog.module

* refactor: convert generators/lua/math.js to named requires

* chore: run clang-format

* refcator: convert generators/lua/procedures.js to goog.module

* refactor: convert generators/lua/procedures.js to named requires

* chore: run clang-format

* chore: rebuild deps.js

* refactor: convert generators/lua/text.js to goog.module

* refactor: convert generators/lua/text.js to named requires

* refactor: convert generators/lua/variables_dynamic.js to goog.module

* refactor: convert generators/lua/variables_dynamic.js to named requires

* chore: run clang-format on text.js

* refactor: convert generators/lua/variables.js to goog.module

* refactor: convert generators/lua/variables.js to named requires

* chore: run clang-format

* chore: make a lua generator function internal

* chore: rebuild deps.js
2021-12-01 14:57:21 -08:00
Rachel Fenichel
37a1e9725c refactor: convert some block generators to goog.module (#5762)
* refactor: convert generators/javascript.js to goog.module

* refactor: convert generators/javascript.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/variables.js to goog.module

* refactor: convert generators/dart/variables.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/variables_dynamic.js to goog.module

* refactor: convert generators/dart/variables_dynamic.js to named requires

* refactor: convert generators/dart/text.js to goog.module

* refactor: convert generators/dart/text.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/procedures.js to goog.module

* refactor: convert generators/dart/procedures.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/math.js to goog.module

* refactor: convert generators/dart/math.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/loops.js to goog.module

* refactor: convert generators/dart/loops.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/logic.js to goog.module

* refactor: convert generators/dart/logic.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/lists.js to goog.module

* refactor: convert generators/dart/lists.js to named requires

* chore: run clang-format

* refactor: convert generators/dart/colour.js to goog.module

* refactor: convert generators/dart/colour.js to named requires

* chore: rebuild deps.js

* chore: lint
2021-12-01 10:42:08 -08:00
Rachel Fenichel
93a1bce1ac refactor: convert generators/javascript/loops.js to goog.module (#5758)
* refactor: convert generators/javascript/loops.js to goog.module

* refactor: convert generators/javascript/loops.js to named requires

* chore: run clang-format

* chore: rebuild deps.js
2021-11-30 18:51:11 -08:00
Rachel Fenichel
e11fe348b2 refactor: convert some js block generators to goog.module (#5756)
* refactor: convert generators/javascript/colour.js to goog.module

* refactor: convert generators/javascript/colour.js to named requires

* chore: run clang-format

* refactor: convert generators/javascript/lists.js to goog.module

* refactor: convert generators/javascript/lists.js to named requires

* chore: run clang-format

* refactor: convert generators/javascript/logic.js to goog.module

* refactor: convert generators/javascript/logic.js to named requires

* chore: run clang-format

* refactor: convert genereators/javascript/math.js to goog.module

* refactor: convert generators/javascript/math.js to named requires

* chore: rebuild deps.js
2021-11-30 17:31:55 -08:00