Commit Graph

242 Commits

Author SHA1 Message Date
Christopher Allen
46df7d132d refactor(tests): Revise tests/playgrounds/prepare.js as tests/bootstrap.js to improve support for ES modules and post-bootstrap scripts (#6214)
* refactor(tests): Move and rename prepare.js, blockly.mjs

  Since prepare.js and blockly.mjs are going to be needed for running
  all tests in uncompiled mode (not just the playgrounds), move them
  tests/.  Further, rename prepare.js to bootstrap.js to better reflect
  its purpose.

* feat(tests): Introduce BLOCKLY_BOOTSTRAP_OPTIONS

  Provide a mechanism for web pages that use bootstrap.js to control
  what is loaded and how.

* fix(tests): Use the blockly repository path for all script src= URLs

  Previously the (non-advanced) playground was only correctly loadging
  on localhost because you can put an arbitrary number of "../"s in front
  of a relative URL and it just takes you to the root directory.

* fix(tests): Don't use template literals in bootstrap.js

  This is necessary (but not necessarily sufficient) to be able to
  load the file in IE 11.

* fix(tests): Throw error if attempting to bootstrap in node.js

* feat(tests): Make bootstrap.js more configurable.

* Terminology change: use "compressed" and "uncompressed" to describe
  what Closure Compiler calls "compiled" and "uncompiled", to reduce
  confusion with the compilation that will be done by tsc.

* Get the list of modules to bootstrap (in compressed mode), or
  scripts to load (in compressed mode) from BLOCKLY_BOOTSTRAP_OPTIONS,
  to allow calling scripts to to specify exactly what to load.

* feat(tests): Use a proper quote function

  We need to generate string literals.  Best to use a quote function
  instead of concatenating on quote marks withou escaping.  Copy a
  well-tested one from Code City.

* feat(tests): Support an additionalScripts option

  This is a list of scripts to load (in order) once the required modules
  have been bootstrapped.

  We do this using goog.addDependency to make the first script depend
  on the required modules, then each subsequent script depend on the
  previous one, and then finally goog.bootstrapping the last such script.

* refactor(tests): Remove special handling of msg/messages.js

* refactor(tests): Use additionalScripts for all script loading

  Use additionalScripts option for all script loading in
  playground.html and advanced_playground.html.

* refactor(tests): Use bootstrap instead of uncompressed in Mocha tests

  Use tests/bootstrap.js instead of blockly_uncompressed.js to load
  blockly in uncompressed mode in the Mocha tests.

  This entails adding a new item, despFiles, to BLOCKLY_BOOTSTRAP_OPTIONS,
  to allow tests/deps.mocha.js to be loaded at the appropriate point.

  Mention of blockly_uncompressed.js is removed from
  tests/mocah/.mocharc.js; it's not clear to me what effect the "file:"
  directive in this file might have previously had and I was not able to
  find documentation for it on mochajs.org, but in any case removing it
  appears to have had no ill effect.

* refactor(tests): Use bootstrap instead of uncompressed in generator tests

  This entails adding an additional check in bootstrap so as to load
  uncompressed when loading from a file: URL, since these are not
  localhost URLs - though in fact the generator tests run equally well
  in compressed mode, albeit against (for now) the previously-check-in
  build products rather than the live code.

* refactor(test): Use bootstrap.js in multi_playground.html

  This removes the last use of load_all.js, so remove it.

* chore(tests): Delete blockly_uncompressed.js

  Its function has now been entirely subsumed by tests/bootstrap.js,
  so remove it and update any remaining mentions of it.

  Also fix formatting and positions of some comments in playground.html.

* fix(tests): Rewrite bootstrap sequencing code

  An earlier commit modified the generated <script> to use
  goog.addDependency to trick the debug module loader into loading
  .additionalScripts (via goog.bootstrap), but it turns out there is
  a small problem: scripts like msg/messages.js have undeclared
  dependencies on the Blockly module, and without a call to
  goog.require('Blockly') in them they can end up being run before
  the Blockly module is fully loaded.

  (This problem only occurs when there are ES Modules, rather than
  merely goog.modules, in the mix.)

  Fix this by adding a script, bootstrap_helper.js, to be loaded
  options.requires and any options.additionalScripts that makes an
  explicit call to goog.require for each of option.requires.

  Also refactor the code so that instead of generating a loop which
  calls goog.addDependency, we generate the addDependency calls
  directly.  This makes debugging a bit easer as we can use the browser's
  dev tools to inspect the generated calls in the DOM tree.

* fix(tests): Prevent spurious transpilation warnings

  For some reason when the debug module loader encounters ES modules
  it starts to complain about being unable to transpile some ES202x
  features in other (non-ESM) modules, even though it doesn't normally
  try to transpile those.

  Since uncompressed-mode testing is almost exclusively on modern
  browsers we don't care about transpiling these features, so suppress
  the warnings instead.

* refactor(tests): Rename blockly.mjs to bootstrap_done.mjs; simplify

  Since blockly.mjs is no longer returning just the exports object
  from core/blockly.js (see PR #5995), it might be better named after
  its actual purpose: to wait for bootstrapping to be done.

  Remove all the code that was used to pass the blockly.js exports
  object along from the bootstrap callback to the blockly.mjs export,
  since there's no reason to go to a lot of trouble to set a local
  variable named Blockly to the same value as a global variable named
  Blockly.

  (Something like this may be needed again in future, but certainly in
  a different form.)

* chore(tests): Use freshly-build files in compressed mode.

  Use the freshly-built build/*_compresssed.js files when bootstrapping
  in compressed mode, rather than using the checked-in files in the
  repository root.

  This helps ensure that compressed and uncompressed mode will be
  testing (as closely as possible) the same code.

* chore(tests): Rename BlocklyLoader to blocklyLoader; record compressed

  - Rename the BlocklyLoader global to blocklyLoader (since it is not
    a class constructor).
  - Create it regardless of whether we are bootstrapping in
    uncompressed or loading compressed via <script> tags.
  - Record which we are doing as .compressed, and use this property
    to choose playground background colour.

* chore(tests): Resolve comments for PR #6214

  Mostly documentation changes, but notably renaming blocklyLoader to
  bootstrapInfo.

* Revert "chore(tests): Use freshly-build files in compressed mode."

  This reverts commit de8d356838.
2022-06-15 19:35:01 +01:00
Christopher Allen
307ff71c21 refactor(build): Preparation for building TypeScript (#6205)
* chore(deps): Update closure/goog/base.js, add goog.js

  - Update base.js from the latest version (20220502.0.0).
  - Also copy over goog.js, which provides access to a suitable subset
    of goog.* via an importable module).

* chore(build): Split gulpfiles/config.js exports object

  This makes it possible for entries to depend on each other.

* chore(build): build config consistency

  - Reorder entries in gulpfiles.config.js to better match order they
    are used.
  - Have update_metadata.sh reference config.js and vice versa.

* refactor(build): Move deps.js (+ deps.mocha.js) from test/ to build/

  Once we start using tsc, deps.js will be created based on the ouptut
  of tsc rather than the raw source in core/.  Since tsc will need to
  be run before running closure-make-deps and also before trying to
  load blockly_uncompressed.js, it doesn't really make sense to check
  in deps.js; it's better to re-create as needed.

  To reduce inconvenience, a new "prepare" script is added to
  package.json which will run the buildDeps gulp target automaticaly
  when one runs npm install.

* refactor(build): Always build from TypeScript sources

  - Add buildJavaScript gulp task to use tsc to compile any .ts files
    in core/ into build/src/core/ (and also copy any .js files that
    are not yet migrated to TypeScript, which for now is all of them.
  - Remove closure/goog from explicit inputs to tsc; it will find
    the files it needs (e.g., goog.js) automatically.
  - Have buildDeps, the playground, and all the tests that run in
    uncompiled mode use build/src/core/ instead of core/ as their
    input directory.

* feat(build): Add buildJavaScriptAndDeps gulp task

  Have npm run build:deps (and npm run prepare) use a new gulp task,
  buildJavaScriptAndDeps, to run tsc followed by closure-make-deps,
  ensuring that deps.js is calculated based on the most recent code
  in core/.

* fix(build): Fix implementation of flattenCorePaths

  Even though this function is going away I want to remove it in
  a separate PR so that we can revert easily if desired.  But the
  previous checked-in code was totally wrong.  This version works.

* fix(build): Don't let checkinBuilt copy build/src/**

  Now that we are putting a lot more stuff in build/ (specifically,
  all the tsc output in build/src/), modify checkinBuilt so that it
  only copies the specific things we want to check in (for now):

  - _compressed.js build artifacts and their accompanying .js.maps
  - the generated build/msg/js/*.js language files.

  Unrelatedly, also fix safety-quoting of arguments for one execSync
  call.
2022-06-14 22:20:42 +01:00
Beka Westberg
2a7d6b08b5 fix: loading messages from script tags. (#6184)
* fix: loading messages in the browser

* chore: fix comment

* fix: change unwrapped message files to write to a new object, rather than Blockly.Msg

* fix: fixup exports

* fix: PR comments

* fix: change to use for-in loop

* fix: ES6 compatibility and formatting
2022-06-13 14:13:54 -07:00
Beka Westberg
2f734f7f17 chore!: properly add the removal of utils.global to the renamings file. (#6204)
* chore!: properly add the removal of utils.global to the renamings file.

* fix: add missing commma
2022-06-10 11:20:26 -07:00
Beka Westberg
b1750b8545 Revert "fix: fix message loading from script tags (#6060)" (#6182)
This reverts commit 44edbb89c3.
2022-06-06 08:59:09 -07: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
63ca83b545 chore: Make startsWith faster (#6118)
by using built-in function (polyfill will handle IE).
2022-04-27 15:25:07 -07:00
Beka Westberg
964fb43f9a chore: update renamings file for new release (#6063) 2022-04-04 15:40:50 -07:00
Maribeth Bottorff
44edbb89c3 fix: fix message loading from script tags (#6060) 2022-04-04 12:18:44 -07:00
Christopher Allen
9d62f92a2f refactor(build): Prepare UMD wrapper generation for transition to ES modules (#5993)
* fix(build): Correctly handle out-of-order chunks

It turns out that closure-calculate-chunks does not guarantee that
calculated chunks will be output in the same order as the
entrypoints, so modify getChunkOptions so that it no longer makes
that assumption.

* refactor(build): Introduce NAMESPACE_PROPERTY; rename NAMESPACE_OBJECT

Rename the constant NAMESPACE_OBJECT to NAMESPACE_VARIABLE to
better explain its actual meaning, and introduce
NAMESPACE_PROPERTY to specify what property the namespace object
will be stored in (and change the previous value, "internal_",
to "__namespace__" to reduce the chance of conflicts with
properties created by the output of Closure Compiler).

* refactor(build): Always save namespace object on chunk exports object

This is so that chunks whose parent chunk is not the root chunk
(chunks[0]) can obtain the namespace object.  (See following commit.)

* fix(build): Correct handling of chunk dependencies

Previously getChunkOptions and chunkWrapper incorrectly assumed
that a chunk could have more than one dependency.

In fact, each chunk can have only a single dependency, which is
its parent chunk.  It is used only to retrieve the namespace
object, which is saved on to the exports object for the chunk so
that any child chunk(s) can obtain it.

Update getChunkOptions and chunkWrapper (making the latter
longer but more readable) accordingly.

* refactor(build): Rename/repurpose chunk.exports -> .reexport

And remove chunk.importAs, since it was no longer being used
anywhere.

* fix: remove unnecessary s from reexports

Co-authored-by: alschmiedt <aschmiedt@google.com>
2022-03-21 13:10:48 -07:00
Beka Westberg
e502eaa6e1 fix: incorrect module for event data in renamings database (#6012) 2022-03-18 11:06:24 -07:00
Beka Westberg
20f1475afc fix!: change paste to return the pasted thing to support keyboard nav (#5996)
* fix: change paste to return the pasted thing

* fix: format

* fix: build

* fix: update the API for duplicate as well

* fix: change types to ICopyable
2022-03-15 11:58:14 -07:00
Aaron Dodson
5f822fdbd7 chore: Update to latest Closure compiler and remove our SVG externs (#5991) 2022-03-10 11:50:43 -08:00
Christopher Allen
3c723f0199 feat(tests): Add a test to validate scripts/migration/renamings.js (#5980)
* feat(tests): Add a test script for the renamings file

* Make scripts/migration/renamings.js a valid JSON5 file.
* Add a schema for it in tests/migration/renamings-schema.json.
* Add a script to test one against the other, as
  tests/migration/validate-renamings.  It is a node.js script
  that will exit 0 if the renamings file is valid, or 1 if it
  is not (and print a not-very-helpful error message from which
  is possible, with some effort, to deduce what the error is.)

* fix: convert to JSON5 and refactor example

* fix: convert keys to new key names

* fix: change versions to arrays instead of objects

* fix: fix version numbers

* fix: associate renames with the version where they were added

* fix: fixup example

* fix: put older renames at the bottom, and newer renames at the top

* fix: enable renamings test in run_all_tests

* fix: put newer renames back at the bottom

This reverts commit efe070e344.

* fix(tests): add missing additionalProperties: false to schema

And fix the resulting validation error in the example entry.

* chore(tests): Improve wording of example entry; add extra examples

Tweaked line wrapping of some existing entries (example and
acutal) that were otherwise untouched.

* feat: add dropDownDiv renaming to new database

* feat(tests): Check for duplicate entries for the same module

Also fixed extraneous whitespace in run_all_tests.sh

* fix(tests): Make validate-renamings.js compatible with node.js v12

Also remove success message, to adhere to usual unix convention
(silence implies success) as eslint does, and reduce unecessary
npm test output clutter.

* fix(tests): Fixes for PR #5980

* Fix typos.
* Remove redundant check.

Co-authored-by: Beka Westberg <bwestberg@google.com>
2022-03-09 11:29:43 -08:00
Christopher Allen
e11b5834e5 fix(tests): Enable --debug for test:compile:advanced; fix some errors (and demote the rest to warnings) (#5983)
* refactor(tests): Migrate tests/compile/main.js to goog.module

* feat(tests): Enable --debug for test:compile:advanced; demote errors

  * Enable the --debug flag when running the
    buildAdvancedCompilationTest gulp task.
  * Remove partialAlias diagnostic group from `JSC_ERROR`, demoting
    JSC_PARTIAL_NAMESPACE to warning.

  Reverts "Revert 'fix(tests): Enable --debug for test:compile:advanced;
  fix some errors (#5959)'".
2022-03-08 23:20:19 +00:00
Beka Westberg
543cb8e1b1 fix: move the dropdown div to a namespace instead of a class with only static properties (#5979)
* fix: remove drop down div class

* fix: change name and export for drop down div

* fix: make module-local variables conform to styleguide

* fix: format

* fix: shadowing
2022-03-07 13:29:23 -08:00
Beka Westberg
fa14e9d6de refactor: convert blocksvg and block to ES6 classes (#5952)
* refact: move super call to top of block svg

* refact: run conversion script on block svg and block

* fix: make debug build happy

* fix: tests

* style: format

* fix: cleanup from rebase

* fix: use new.target instead of a new parameter

* fix: add more overridden casted methods to BlockSvg

* style: fix typos

* style: move override tags to the end of JSDoc

* fix: cleanup from rebase
2022-02-28 09:48:37 -08:00
Beka Westberg
cb4521b645 refactor: Convert fields to ES6 classes (#5943)
* refactor: Initial test at refactoring fields to ES6

* refact: reorganize text input and descendants to call super first

* refact: run conversion script on text input field and subclasses

* clean: cleanup fields post-conversion script

* refact: reorganize dropdown and variable fields to call super first

* refact: run class conversion script on dropdown and variable

* clean: clean fields post conversion script

* refact: reorganize misc fields to call super first

* refact: run conversion script on misc fields

* clean: cleanup misc fields after conversion

* fix: add setting the value and whatnot back to the base field. Pass sentinel conistently

* format

* refact: work on making debug compiler happy

* clean: finish making debug build happy

* fix: work on making tests happy

* fix: finish making tests happy

* Fix: fixup angle and multiline fields

* clean: format

* fix: move default value back to DEFAULT_VALUE

* fix: change SENTINEL to SKIP_SETUP

* fix: inline docs

* fix: some misc PR comments

* fix: format

* fix: make compiler hapy with new.target

* fix: types in FieldDropdown

* fix: add @final annotations to Field

* feat: move Sentinel to a utils file

* fix: remove ImageProperties from external API

* clean: cleanup chunks and deps
2022-02-28 08:59:33 -08:00
Beka Westberg
237e66cf29 refactor: convert row.js and base.js to ES6 classes (#5957)
* fix: remove unnecessary properties from rows

* refactor: run conversion script on measurables

* clean: cleanup from conversion

* fix: make debug build happy

* clean: format

* fix: remove widthWithConnectedBlocks assignment on element

* fix: add inline docs for statementEdge
2022-02-25 11:06:12 -08:00
Christopher Allen
00e1dade3a chore(build): Disable visibility warnings (#5958)
Because of our mis-use of @package, and the removal of the hack
that made it work reasonably (in PR #5918), compilation was
generating a large number of JSC_BAD_PACKAGE_PROPERTY_ACCESS
warnings, making it hard to see any other warnings/errors that
might be generated.

To make compiler diagnostics more useful, disable the visibility
diagnostic group entirely for the time being.

Also improve the documentation for JSCOMP_ERROR and the newly-
-introduced JSCOMP_WARNING and JSCOMP_OFF.
2022-02-24 00:04:32 +00:00
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
Beka Westberg
be9ca98cdc refactor: convert toolbox items to ES6 classes (#5947)
* refact: convert toolbox items to ES6 classes

* fix: and SENTINEL so that contents can be parsed properly

* fix: fix types and whatnot related to new SENTINEL

* clean: format

* refactor: reorganize overridable calls into the init function, and remove sentinel

* clean: format

* fix: inline docs and organization
2022-02-22 15:21:23 -08:00
Christopher Allen
71ab146bc2 fix(build): Correctly handle deep export paths in UMD wrapper (#5945)
* fix(build): Correctly handle deep export paths

A problem can occur when loading chunks in a browser: although
factory() will create the full exported path on $, and thus the
assignment

    root.<path> = factory(...) { ...; return $.<path> }

will normally be a do-nothing in every chunk except the first, if
the exported path (e.g. Blockly.blocks.all) is more than one level
deeper than any previously-existing path (e.g. Blockly), this will
fail because root.<path> is evaluated before calling factory(), and
so the left hand side will will evaluate to a undefined reference
(e.g. undefined.all) and TypeError will be thrown before the call
to factory is evaluated.

To fix this, call factory first and store the exports object in a
variable before assigning it to the exported path.

Fixes #5932.
2022-02-22 22:04:49 +00:00
alschmiedt
4b5733e7c8 refactor!: allows previously internal constants to be configurable (#5897) 2022-02-09 09:46:34 -08:00
Rachel Fenichel
9e8c5ea8ed refactor: convert some files to es classes (#5917)
* refactor: update several files to es6 classes

* refactor: update several files to es6 classes

* chore: add some type casts for specificity about event types

* chore: run formatter

* chore: rebuild
2022-02-09 08:29:39 -08:00
Aaron Dodson
e3f40a6abc refactor(build): Stop flattening Blockly sources during compilation in preparation for move to ES modules (#5918)
* refactor: Stop flattening Blockly sources during compilation in preparation for move to ES modules

* fix: Remove obsolete accessControls and add comment about visibility changes
2022-02-08 10:35:13 -08:00
Aaron Dodson
328cd35d10 refactor: Migrate Blockly.Events.Abstract to named exports (#5916) 2022-02-04 15:32:33 -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
Rachel Fenichel
f68043d3eb chore(build): add a script to run the ts compiler and send the new files to closure compiler (#5894)
* chore(build): add a script to run the ts compiler and send the new files to closure compiler

* chore(build): clean up tsconfig

* chore: apply suggestions from code review

Cleanup from Chris

Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>

Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>
2022-01-25 15:33:34 -08:00
Rachel Fenichel
f5caf964aa refactor: convert renderer classes to es6 classes (#5874)
* refactor: convert zelos renderer classes to es6 classes

* refactor: convert zelos measurables to es6 classes

* refactor: convert thrasos classes to es6 classes

* refactor: convert minimalist classes to es6 classes

* refactor: update geras classes to es6 classes

* chore: rebuild and format

* chore: fix indentation in comments
2022-01-14 12:43:13 -08:00
Rachel Fenichel
df2eafb8dd refactor: move properties into constructors and convert to classes (#5822)
* refactor: move properties to constructor in block_drag_surface.js

* refactor: move properties to constructor in block_svg.js

* refactor: move properties to constructor in block.js

* refactor: move properties to constructor in bubble.js

* refactor: move properties to constructor in connection.js

* refactor: move properties to constructor in flyout_base.js

* refactor: move properties to constructor in flyout_button.js

* refactor: move properties to constructor in generator.js

* refactor: move properties to constructor in grid.js

* refactor: move properties to constructor in input.js

* refactor: move properties to constructor in mutator.js

* refactor: move properties to constructor in scrollbar.js

* refactor: move properties to constructor in trashcan.js

* refactor: move properties to constructor in warning.js

* refactor: move properties to constructor in workspace_audio.js

* refactor: move properties to constructor in workspace_drag_surface_svg.js

* refactor: move properties to constructor in workspace_svg.js

* refactor: move properties to constructor in workspace.js

* refactor: move properties to constructor in zoom_controls.js

* chore: rebuild

* refactor: convert zoom_controls.js to es6 class and format

* refactor: convert workspace_audio.js to es6 class and format

* refactor: convert workspace_dragger.js to es6 class and format

* refactor: convert workspace_drag_surface_svg.js to es6 class and format

* refactor: convert variable_model.js to es6 class and format

* refactor: convert variable_map.js to es6 class and format

* refactor: convert theme.js to es6 class and format

* chore: remove bad comment
2022-01-06 13:13:40 -08:00
Christopher Allen
10cfc11809 chore: Remove core/requires.js (#5718)
* chore: Remove requires that duplicate those in blockly.js

* refactor: Remove core/requires.js, make blockly.js be entry point

It sort of makes sense, doesn't it?

The only remaining require not duplicated in `blockly.js` was that for
`Blockly.themes.Classic`, but it is already required by
`Blockly.themes` (itself required by `Blockly`).
2021-12-06 08:46:14 -08:00
Rachel Fenichel
3770f20448 chore(deps): remove dependency on typescript-closure-tools (#5776)
* build: remove typings tasks from build and test

* chore(deps): remove typescript-closure-tools

* chore(deps): update package-lock.json
2021-12-03 10:47:24 -08: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
8b3635ab75 chore: Simplify NPM package wrappers, improve chunk wrapper generator (#5777)
* chore: Clean up NPM package module wrappers

  - Slightly improve documentation for each file based on helpful
    explanations given by @samelhusseini.

  - Removed redundant code---e.g., loading `javascript_compressed.js`
    creates and sets Blockly.JavaScript as a side effect, so there is
    no need to set `Blockly.JavaScript = BlocklyJavaScript` in
    `dist/javascript.js` (generated from `scripts/package/javascript.js`).
  - Remove possibly harmful code---e.g., `Blockly.Msg` is initialised
    with a null-prototype object in `blockly_compressed.js` and that
    initial object should under no circumstances be replaced.
  - Remvoe downright misleading code---e.g., `dist/blocks.js` previously
    _appeared_ to replace Blockly.Blocks with an empty object, but in
    fact the `Blockly` name referred at that point to the exports object
    from `blocks_compressed.js`, which would randomly get a useless
    `{}`-valued `.Blocks` property tacked on to it; similarly, code in
    `dist/browser.js` (generated from `scripts/package/browser/index.js`)
    appeared to copy definitions from `BlocklyBlocks` to `Blockly.Blocks`,
    but the former would always be (the aforementioned) empty object,
    making this code ineffective.

* chore: Improve chunk definition / UMD generation

  Make several improvements to the chunks global and chunkWrapper
  function:

  - Document chunk definition format (and improve the names of
    of the documented properties).

  - Replace the chunk `.namespace` property with two others:
    - `.exports` names the variable/property to be returned by the
      factory function, and which will be set on the global object if
      the module is loaded in a browser.
    - `.importAs` names the parameter that this chunk's exports value
      is to be passed to the factory function of other chunks which
      depend on this one.  (This needs to be different because e.g.
      `Blockly.blocks` is not a valid parameter name.)

  - Change the definition for the blocks chunk to export Blockly.Blocks
    (i.e., the block definition dictionary) as blocks_compressed.js
    did previous to PR #5721 (chunked compilation), rather than the
    (empty and soon to vanish) Blockly.blocks namespace object.

    This is a win for backwards compatibility, though it does mean that
    if we want to expose the `loopTypes` export from `blocks/loops.js`
    we will need to find a different way to do so.
2021-12-03 02:21:01 +00:00
alschmiedt
5515afc708 chore: Remove declareLegacyNamespace from serialization folder (#5757) 2021-12-02 10:21:58 -08:00
Christopher Allen
da16a66f33 refactor: msg.js: use named export, remove declareLegacyNamespace (#5768) 2021-12-02 16:47:27 +00:00
alschmiedt
35279eb8b7 chore: correctly updates the compiled flag (#5767) 2021-12-02 08:29:53 -08: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
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
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
Rachel Fenichel
4db047ff32 chore: fix missing requires in generators (#5744)
* chore: fix some missing requires in generators

* chore: fix missing requires in dart block generators

* chore: replace Blockly.isNumber with Blockly.utils.string.isNumber in generators

* chore: fix more missing requires in block generators
2021-11-30 08:51:21 -08: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
3e9878169b chore(build): Update compiler & linter input language to ES2020 (#5745)
Also:

- Ensure that the `comma-dangle` rule will not be applied to
function parameter lists (even when multi-line).

- Update tests/node/.eslintrc.json to make the environment
node-specific and not pinned to es6.
2021-11-30 01:31:03 +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
c0d22f2002 refactor: Rename ALIGN to Align and move from constants.js to input.js (#5742)
This constant is used to specify the alignment of
an Input, so it should live in the same file as the Input class.

I've done this as a separate named export, but it could alternatively
be made a static member of Input (i.e., Input.Align with only Input
being exported by name).

Where mocha tests were referring to Blockly.constants.ALIGN.*
without actually requiring Blockly.constants, I have reverted
them to refer to Blockly.ALIGN_* instead (pending conversion
to named requries).

Part of #5073.
2021-11-29 21:59:48 +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