Commit Graph

362 Commits

Author SHA1 Message Date
Christopher Allen
5078dcbc6d refactor(blocks)!: Rename Blockly.blocks.* modules to Blockly.libraryBlocks.* (#5953)
...and rename Blockly.blocks.all (blocks/all.js) to
Blockly.libraryBlocks (blocks/blocks.js

BREAKING CHANGE: (only) because the exports object from the
`blocks_compressed.js` chunk will be accessed as
`Blockly.libraryBlocks` instead of `Blockly.blocks.all` when the
chunk is loaded in a browser via a `<script>` tag.  There will
be no changes visible when the chunk is loaded via ES module
`import` or CJS `require`.
2022-02-23 21:25:52 +00:00
alschmiedt
4b5733e7c8 refactor!: allows previously internal constants to be configurable (#5897) 2022-02-09 09:46:34 -08:00
Christopher Allen
ffb8907db8 feature(blocks): Export block definitions (#5908)
* refactor: Provide a BlockDefinition type

* refactor: Split defineBlocksWithJsonArray

  Split defineBlocksWithJsonArray into:

  - createBlockDefinitionsFromJsonArray, which creates BlockDefinitions
    from a (possibly JSON-originated) POJsO array, having no side-effects
    except possibly issuing warnings to the console.
  - defineBlocks, which add any dictionary of BlockDefinitions to
    the Blocks dictionary.

* feat(blocks): Export block definitions per-module

  - Define all blocks in a local blocks dictionary, often using
    createBlockDefinitionFromJsonArray, without registering them.
  - Separately, use defineBlocks to register the exported
    BlockDefinitions at the end of each Blockly.blocks.*
    module.
  - In Blockly.blocks.all, create a blocks export that combines all
    of the blocks exports from the individual blocks modules.

* chore: have format script run clang-format on blocks/ too
2022-01-31 21:41:29 +00:00
Christopher Allen
74ef1cbf52 fix!: Export loopTypes from Blockly.blocks.loops (#5900)
* refactor(blocks): Make loopTypes a Set

  This is likely to slightly improve performance, especially if there
  are many entries.

* refactor(blocks): Re-export individual block modules from Blockly.blocks.all

* fix!(blocks): Have blocks_compressed.js export Blockly.blocks.all

  Previously the value obtained by

      const blocks = require('blockly/blocks');  // Node.js

  or

      import blocks from 'blockly/blocks.js';  // ES Modules

  would be the block definitions dictionary (Blockly.Blocks).

  Change this so that it is instead the export object from
  Blockly.blocks.all.

  This means you can now access loopTypes via:

      import blocks from 'blockly/blocks.js';
      blocks.loops.loopTypes.add('my_loop_blocktype');

  This is a breaking change for any code which depended on the value
  that was exported by blocks_compressed.js.

BREAKING CHANGE: the exports provided by blocks_compressed.js (and
therefore by `import ... from 'blockly/blocks'`) have changed; see above.
2022-01-31 18:36:10 +00:00
Christopher Allen
b52c0179cb chore: Fix inadvertent block migration inconsistencies (#5780)
* chore: Fix inadvertent block migration inconsistencies

  - Reinstate `goog.require`s-for-side-effects that were inadvertently
    removed.
  - Always use a destructuring import for `defineBlocksWithJsonArray`.
  - Consistently use `CONSTANT_CASE` names for block-common objects.
    (We could alternatively always use `camelCase` names, but since
    all the `MIXIN`s and `EXTENSIONS` remain all-uppercase this seems
    the more consistent.)

* chore: Fix import ordering
2021-12-03 02:45:47 +00:00
Christopher Allen
b08187cd0a refactor: Migrate blocks/variables_dynamic.js to goog.module syntax (#5779)
* refactor: Migrate blocks/variables_dynamic.js to goog.module

* refactor: Migrate blocks/variables_dynamic.js named requires

* chore: clang-format blocks/variables_dynamic.js
2021-12-03 02:36:14 +00:00
Christopher Allen
7d7bd75c3a refactor: Migrate blocks/variables.js to goog.module syntax (#5774)
* refactor: Migrate blocks/variables.js to goog.module

* refactor: Migrate blocks/variables.js named requires

* chore: clang-format blocks/variables.js

* chore: JSDoc grammar correction
2021-12-02 19:06:48 +00:00
Christopher Allen
da16a66f33 refactor: msg.js: use named export, remove declareLegacyNamespace (#5768) 2021-12-02 16:47:27 +00:00
Christopher Allen
ee18553035 refactor: Migrate blocks/text.js to goog.module syntax (#5766)
* refactor: Migrate blocks/text.js to goog.module

* refactor: Migrate blocks/text.js named requires

* refactor: Factor out common properties of text_prompt* blocks

* clang-format blocks/text.js

* fix: Fix lint warnings for PR #5766
2021-12-02 11:23:31 +00:00
Christopher Allen
d7b82cddfc refactor: Migrate blocks/math.js to goog.module syntax (#5765)
* refactor: Migrate blocks/math.js to goog.module

* refactor: Migrate blocks/math.js named requires

* chore: clang-format blocks/math.js
2021-12-01 19:41:14 +00:00
alschmiedt
47c821018e fix: procedure callers now remove inputs properly (#5751) 2021-11-30 16:03:18 -08:00
Christopher Allen
208d2008a3 refactor: Migrate blocks/loops.js to goog.module syntax (#5755)
* refactor: Turn .getSurroundLoop into a (Block) method

  This considerably simplifies the code in the genrators, obviating
  the need for generators to import Blockly.Constants.Loops, and
  allowing the compiler to remove blocks/loops.js from the first
  (Blockly) chunk of the compilation.

  (The latter could and should have been arranged by making the
  generator chunks depend on the blocks chunk, but that is no longer
  necessary.)

* refactor: Migrate blocks/loops.js to goog.module

* refactor: Migrate blocks/loops.js named requires

* chore: clang-format blocks/loops.js
2021-11-30 23:51:27 +00:00
alschmiedt
780198e0c0 chore: revert #5730 (#5740)
* chore: revert #5730

* fix: Fix compile failure due to incorrect visibility

The CONTROL_FLOW_IN_LOOP_CHECK_MIXIN is intended to be used outside of
blocks/ (it is, in particular, used in generators/) so it should have
been marked @public from the beginning.
2021-11-30 19:27:19 +00:00
Christopher Allen
2ca6740758 refactor: Migrate blocks/logic.js to goog.module syntax (#5748)
* refactor: Migrate blocks/logic.js to goog.module

* refactor: Migrate blocks/logic.js named requires

* chore: clang-format blocks/logic.js
2021-11-30 17:43:35 +00:00
Christopher Allen
1a992386ae refactor: Migrate blocks/lists.js to goog.module syntax (#5746)
* Migrate blocks/lists.js to goog.module

* Migrate blocks/lists.js named requires

* clang-format blocks/lists.js
2021-11-30 16:23:00 +00:00
Christopher Allen
b21130aef8 refactor: Migrate blocks/procedures.js to goog.module syntax (#5736)
* Migrate blocks/procedures.js to goog.module

* Migrate blocks/procedures.js named requires

* clang-format blocks/procedures.js

* chore: Factor common methods out of block definitions

  Addressing comments on PR #5736.
2021-11-30 16:19:47 +00:00
Christopher Allen
25a4561e21 Migrate blocks/colour.js to goog.module syntax (#5738)
* Migrate blocks/colour.js to goog.module

* Migrate blocks/colour.js named requires

This causes an apparently harmless reordering of the files for the
first chunk.

* clang-format blocks/colour.js
2021-11-29 22:51:06 +00:00
Christopher Allen
985af10f6e chore(build): Use chunked compilation (#5721)
* chore(build): Add "all" modules for blocks & generators

These modules (Blockly.blocks.all and Blockly.<Generator>.all) will
be the entry points for the corresponding chunks.

They also make it easier to pull in all the modules in each package
(e.g. for playground and tests).

It is necessary to set the Closure Compiler dependency_mode to
SORT_ONLY as otherwise it tries to compile the "all" modules before
their dependencies, which fails.

The only impact on the _compressed.js files is the addition of a short
string to the very end of each file, e.g.:

    var module$exports$Blockly$JavaScript$all={};

* chore(deps): Add devDependency on closure-calculate-chunks

* feat(build): First pass at chunked complation

Add a new buildCompiled gulp target (npm run build:compiled) that
uses closure-calculate-chunks to do chunked compliation of core/,
blocks/ and generators/ all in a single pass.

This work is incomplete: the resulting *_compressed.js files don't
(yet) have UMD wrappers.

* chore(build): Generate chunk wrappers

A first pass; this does not have support for a namespace object yet.

* refactor(build): Use chunked compilation by default

Remove old "compressed" gulp tasks in favour of new "compiled" task.

* chore(build): Remove cruft from buildCompiled

Remove unneeded `done` parameter and commented-out options that had
been cargo-culted from the old build pipeline.

* fix(build): Fix test failures caused by new build pipeline

- Exclude closure/goog/base.js from compiler input; use
  externs/goog-externs.js instead.

- Have the build:debug and build:strict targets only build the first
  chunk (blockly_compressed.js).

- Fix namespace entries for blocks and generators.

* fix(build): Fix build failures on node v12

closure-calculate-chunks requires node.js v14 or later.

When running on node.js v14 or later have getChunkOptions save
the output of closure-calculate-chunks to
scripts/gulpfiles/chunks.json.  When running on older versions of
node.js have it use this checked-in, cached output instead of
attempting to run closure-calculate-chunks.

* chore(build): enable --rename_prefix_namespace

This will allow modules in blocks/ and generators/ to use
goog.require to obtain the exports object of goog.modules from
core/.

* fix(build): Always build all chunks

The previous commit enabled --rename_prefix_namespace option to
Closure Compiler, and this causes the buildCompressed target to
work fine when run without --debug or --strict, but adding either
of those flags (as for example when `npm test` runs
`npm run build:debug`) causes an issue:

- Because of many compiler errors in blocks/ and generators/,
  a previous commit added a hack to only build the first chunk
  when doing debug/strict builds.

- When asked to build only one chunk, Closure Compiler ignores the
  --rename_prefix_namespace flag, because it 'correctly' infers
  that there are no later chunks that will need to access global
  variables from the first chunk.

- This causes a test failure, because `npm test` first runs
  `npm run build`, which generates a valid blockly_compressed.js,
  but this is then overrwritten by an invalid one when it next runs
  `npm run build:debug`.

  (The invalid one is missing all `$.` prefixes on 'global' variables,
  including on Blockly, so the wrapper's last two lines -
  "$.Blockly.internal_ = $;" and "return $.Blockly" - fail.)

The fix is to add appropriate @suppress annotations to blocks/*.js and
generators/**/*.js and then remove the first-chunk-only hack.

* refactor(build): Just build once

Since the previous commit caused `npm run build:debug` to do
everything that `... build:compressed` does - and to produce
byte-for-byte identical output - it doesn't make sense to run
both when testing.  To that end:

- Replace the build:debug and build:strict package scripts that
  did `gulp buildCompressed --...` with new scripts build-debug
  and build-strict that do `gulp build --...` instead.

  (The target names are changed so as to extend our existing naming
  convention as follows: a target named "foo:bar" does some sub-part
  of the job done by target "foo", but a target named "foo-bar" does
  all the work of the target "foo" with some extra options.)

- build:debug:log and build:strict:log are similarly replaced with
  build-debug-log and build-strict-log.

- Modify run_all_tests.js to just do `npm run build-debug` instead of
  doing both `npm run build` and `npm run build:debug`.

- Also remove the 'build:blocks' script that should have been removed
  when the buildBlocks gulp task was deleted previously.

* refactor(build): Compile with base_minimal.js instead of base.js

Introduce a (very!) cut-down version of closure/goog/base.js named
base_minimal.js that is used as input to the compiler as an
alternative to using externs/goog-externs.js (which will be deleted
once the buildAdvancedCompilationTest target has been updated).

This will allow use of goog.setTestOnly since it will now exist in
compiled mode, and allows the changes made in 5b112db to filter
base.js out of the files for the first chunk to be reverted.
(It also obliges a change to the compiled-mode check in blockly.js.)

* fix(build): Fix buildAdvanceCompilationTest

- In build_tasks.js:
  - Replace the old compile() function with a new one factored out of
    buildCompiled().
  - Update buildAdvancedCompilationTest to use the new compile()
    and other helpers created in the meantime.
  - Remove no-longer-used maybeAddClosureLibrary().

- Remove externs/{block,generator,goog}-externs.js, which are no longer
  used by any compile pipeline.

- Update core/blockly.js to fix issue with detection of compiled mode
  when using ADVANCED_OPTIMISATIONS.

- Update only other use of globalThis, in core/utils/xml.js, to
  consistently treat it as a dictionary object.

- Update instructions in tests/compile/index.html.

This commit is sort-of-a-prerequisite to #5602; test:compile:advanced
was previously working but the generated `main_compresed.js` would
throw errors upon loading.
2021-11-29 17:50:17 +00:00
alschmiedt
308253bfdf chore: moves the public loop mixin into its own file (#5730) 2021-11-24 15:57:28 -08:00
Rachel Fenichel
5deed5a194 chore: fix or ignore remaining lint (#5709)
* chore: fix or ignore remaining lint

* chore: fix bad annotations

* chore: use push for array concatenation

* chore: revert use of spread for array operations
2021-11-17 08:39:00 -08:00
Christopher Allen
335ff199d7 refactor: Update uncompiled-mode dependency loading for playground, tests (#5715)
* chore: rename module Blockly.blocks.Lists to ....lists

All the other Blockly.blocks modules have lower-case names.  This
one being named with an upper-case initial appears to have been a
typo on my part.

This module name is not mentioned anywhere else in the source code
(though it will be soon!) so no other files need to be edited.
Further, it does not appear anywhere in the last release (which
before PR #5696) so it is not necessary to add an entry in
renamings.js for this change.

* chore(build): Rationalise deps.js, deps.mocha.js

* Include blocks/*.js (Blockly.blocks.*) in tests/deps.js, since
  these modules are used in the playground.  (They are goog.provide
  modules loaded via <script> tags, so their absence from deps.js
  does not cause errors - but it will when they are migrated to
  goog.module and must be loaded via goog.require.)

* Filter the entries in deps.mocha.js so that it includes only the
  additional mocha test modules (i.e. those not mentioned in deps.js
  already).

* refactor: Load blocks and generators using goog.require
2021-11-17 00:04:45 +00:00
Neil Fraser
1fcae953fc fix: Quote Msg prop name to survive compile (#5703) 2021-11-10 12:45:19 -08:00
Rachel Fenichel
f14a1c8034 chore: fix more lint (#5676)
* chore: fix assorted lint

* chore: clang-format

* chore: clang-format
2021-11-08 16:41:52 -08:00
Christopher Allen
beefe361a3 fix!(blocks): Rename Blockly.Blocks.* modules to Blockly.blocks.* (#5696)
Use Blockly.blocks.* for blocks modules, leaving the Blockly.Blocks
name for the block dictionary object.

This resolves a problem with advanced compilation of Blockly Games,
 where, in the compressed output, (the minified name of)
 Blockly.Blocks gets overwritten, with the dictionary object defined in
 core/blocks.js being replaced by an empty namespace object
 created by the provides of Blockly.Blocks.* in blocks/*.js. Without
 this fix, some block definitions end up being created in the
 dictionary and some on the namespace object—with chaos
 predictably ensuing.
2021-11-08 18:35:38 +00:00
Rachel Fenichel
c75e944f06 chore: remove references to JSON extraction (#5683) 2021-11-05 18:28:52 -07:00
Rachel Fenichel
6dc0f90959 chore: replace var with const and let in blocks directory (#5626)
* chore: use const and let in blocks/lists.js

* chore: use const and let in blocks/logic.js

* chore: use const and let in blocks/loops.js

* chore: use const and let in blocks/math.js

* chore: use const and let in blocks/procedures.js

* chore: use const and let in blocks/text.js

* chore: use const and let in blocks/variables_dynamic.js

* chore: use const and let in blocks/variables.js

* fix: updateShape_ variable scoping

* fix: declarations in switch clauses

* other: change while loops to for loops

* fix: fix violation of no-cond-assign
2021-10-21 14:25:37 -07:00
Rachel Fenichel
e8d6f7f408 chore: auto-fix violations of comma-dangle rule (#5625) 2021-10-21 09:01:51 -07:00
Neil Fraser
90b3f75d82 Remove @author tags (#5601)
Our files are up to a decade old, and have churned so much, that the initial author of the file no longer has much meaning.

Furthermore, this will encourage developers to post to the developer group, rather than emailing Googlers (usually me) directly.
2021-10-15 09:50:46 -07:00
Neil Fraser
c929b3015b chore: Convert == to === and != to !== where possible. (#5599) 2021-10-15 09:17:04 -07:00
Christopher Allen
16b6d4526a refactor: Rename Blockly.Blocks, migrate to named exports (#5515)
* Rename Blockly.Blocks to Blockly.blocks
  Because it does not export a type as its default export.

  Part of #5073.

* Name default export of Blockly.blocks Blocks.

  Use named exports in Blockly.blocks by giving the former default
  export the name Blocks.

  Part of #5153.

* Reexport Blockly.blocks from blockly.js

* Document the format of renamings.js better.
2021-09-24 19:12:03 +01:00
kozbial
6fc90213a6 Merge branch 'develop' into merge-develop-to-goog_module 2021-09-21 16:04:33 -07:00
Beka Westberg
ee78b41987 feat: upgrade block defs to have JSO serialization hooks (#5329)
* Respect nulls from blocks.save

* Upgrade list blocks to use JSO serialization

* Upgrade logic blocks to use JSO serialization

* Upgrade math blocks to use JSO serialization

* Upgrade text blocks to use JSO serialization

* Upgrade procedure blocks to use JSO serialization

* Add more mutator tests

* Fix firing enabled events

* PR Comments
2021-09-20 13:08:35 -07:00
Neil Fraser
ae39fb9e23 Add supressPrefixSuffix to if/else block
Alternatively, this could be done by using an extension, rather than JSON.  I have no preference.
Issue #5268.
2021-08-04 10:19:25 -07:00
Christopher Allen
1197afcee7 Fix JSDoc type annotations causing closure-make-deps warnings
Some type annotations were missing curly brackets, which makes
closure-make-deps emit uninteresting warnings.  Now any output
from the command will be informative and related to whatever
one is presently working on.
2021-07-12 03:17:14 +01:00
Neil Fraser
d919b0af21 Update JSDoc from Array.<> to Array<>
Same with Object.
2021-05-27 21:30:26 -07:00
Grayson Nix
3d22f8401e Issue #4475 fix (#4758)
* Issue #4475 fix
2021-04-08 16:01:16 -07:00
Maribeth Bottorff
55a453dab9 update break block even if it's not the dragged block (#4533) 2020-12-14 11:40:25 -08:00
Beka Westberg
04ea0f1397 Fixes mutators considering insertion markers during compose (#4449)
* Fix markers for lists, logic, and text

* Fix insertion markers in procedure mutators
2020-11-17 13:32:36 -08:00
Monica Kozbial
dd0d5aee53 Adding procedure tests and handling procedures instantiated without name (#4428)
* Expand procedure tests and fix bug with default ids

* Add tests

* Remove xml_procedures_test.js and add non-overlapping test cases into procedures_test.js
2020-11-06 11:48:48 -08:00
Rachel Fenichel
7288c66294 Rename connectionTypeChecker->connectionChecker 2020-07-16 17:40:13 -06:00
Rachel Fenichel
e24f3cef9b Add isDragging to canConnectWithReason and delete newly unused code paths. 2020-07-16 17:40:13 -06:00
Rachel Fenichel
bb8348befd Move to a single canConnect function, and update tests 2020-07-16 17:40:12 -06:00
Rachel Fenichel
c743a92bb9 Start work on connection type checker 2020-07-16 17:40:12 -06:00
Monica Kozbial
638ecf6023 Adding getter to procedures call for arguments_. (#3983) 2020-06-22 15:28:31 -07:00
Beka Westberg
79ce850cf8 Fix procedure callers accessing private vars 2020-04-11 16:16:25 -07:00
Monica Kozbial
a9223b0b22 Typo fixes. (#3769) 2020-03-25 15:47:27 -07:00
Jakub Vrána
00bb99e0ff Add non-nullable modifier to return type of functions never returning null (#3742) 2020-03-16 08:14:47 -07:00
Beka Westberg
fabb8c44b1 Fix procedure args handling case incorrectly 2020-02-23 10:12:08 -08:00
Beka Westberg
5445cf4cf8 Add comments to break block change listener. 2020-02-19 14:40:28 -08:00
Beka Westberg
392d25eb39 fix: Break breaking undo. 2020-02-18 16:01:18 -08:00