* 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
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
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.
* 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
* 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.
* 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.
* 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>
* 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
* 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.
* 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
* 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
* 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
* 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
* 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
* 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
* 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
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.
* refactor(generators): Introduce class JavascriptGenerator
Also fix an import ordering error.
* refactor(generators): Use Order.* instead of .ORDER_*
* refactor(generators): Don't rename javascriptGenerator
* 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.
* 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.
* 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.
* 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.
* 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
* 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
* 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
* 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
* 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