Commit Graph

57 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
af2bf583af refactor: migrate generators/dart.js to goog.module syntax (#5749)
* chore: migrate generators/dart.js to goog.module

* chore: migrate generators/dart.js to named requires

* chore: Update generators/dart.js to alphabetize imports

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

Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>
2021-11-30 11:11:18 -08: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
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
Rachel Fenichel
a366daacd1 chore: update generators/dart.js to const and let (#5646) 2021-10-27 12:44:09 -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
Neil Fraser
43b65d2aa1 Factor out procedure population from generators
Also fix bug in Lua generator where variables were not populated in the nameDB (only language with no variable initialization).
2021-05-27 21:30:26 -07:00
Neil Fraser
9869269ce2 Add procedures to name DB in init
This enables the generator for any block to see all variable names and procedure names in the whole program, including those that haven’t generated yet.
2021-05-27 21:30:26 -07:00
Neil Fraser
ecca5bf274 Use Object.values rather than loop
Only for JS, Lua, and PHP.  Dart and Python need extra logic to split out import statements.

Also use ‘this’ instead of fully qualified names in generators.
2021-05-27 21:30:26 -07:00
Neil Fraser
b50cb5779f Set generator’s isInitialized to false in finish
Previously isInitialized would remain true after first generation.
Also move common init/finish code to parent class.
2021-05-27 21:30:26 -07:00
Neil Fraser
2f2252f588 Rename variableDB_ to nameDB_
There is significant confusion in names and comments with regards to variables and procedures.  `Blockly.Generator.prototype.variableDB_` is a Blockly.Names database, not a variable map.  This rename introduces a getter and setter so deprecated references still work.  This commit also fixes some comments which are either outright wrong or misleading regarding variable and procedure names.
2021-05-27 21:30:26 -07:00
Rachel Fenichel
750b62030b First pass at creating connectionTypes and inputTYpes 2021-03-04 10:22:24 -08:00
Monica Kozbial
6510e49162 Add warning to blockToCode (#4492)
* Add warning to blockToCode

* Address PR comments
2020-12-07 10:38:32 -08:00
Monica Kozbial
81d355f5fa Fix order errors in text generators (#4329)
* Fix dart text generator logic

* Fix Javascript text generator logic.

* Fix Lua text generator logic

* Fix php text generator logic

* Fix python text generator logic

* Fix error in substring logic

* Fix unit test block generators

* Update from ORDER_COMMA to ORDER_NONE

* Update golden files
2020-09-30 14:08:45 -07:00
Rachel Fenichel
1350604e93 Fix dart multiline strings 2020-09-18 13:37:54 -07:00
Neil Fraser
4e2f8e6e02 Use SPDX licences.
This is a followup to #3127.
At the time, SPDX licenses were pending approval by Google.
2020-02-11 13:27:20 -08:00
Sam El-Husseini
64c52efb5b Resolve warnings in generator code (#3350) 2019-10-28 09:35:40 -07:00
Neil Fraser
b46a4fe286 Bring our license format up to date (#3127)
* Google changed from an Inc to an LLC.

This happened back in 2017 but we didn’t notice.  Officially we should update files from Inc to LLC when they are changed as part of regular edits, but this is a nightmare to remember for the next decade.

* Remove project description/titles from licenses

This is no longer part of Google’s header requirements.  Our existing descriptions were useless (“Visual Blocks Editor”) or grossly obselete (“Visual Blocks Language”).

* License no longer requires URL.

* Fix license regexps.
2019-10-02 14:46:56 -07:00
Beka Westberg
9e5df6216a Fixed comment ownership. (#2923)
* Moved comment icons to use a model-based system. The block holds the model of the comment, and the comment icon holds a reference to it.
* Reorganized the setVisible function.
* Changed how xml.js serializes and deserializes comments.
2019-09-20 13:16:07 -07:00
Rachel Fenichel
6f4476c962 Textarea Field, Multiline Block (from acbart) (#2663)
* Field Textarea, text_multiline block, generators
2019-09-11 17:57:46 -07:00
Neil Fraser
d1a29739d8 Move utilities into own directory.
TODO: There are more functions which may be migrated into dom and string.
2019-06-07 10:32:57 -07:00
alschmiedt
f06bee4eca Fixes pull request comments 2018-11-27 09:55:15 -08:00
Abby Schmiedt
26a4774b35 Adds option to generate code for a single block 2018-11-21 09:00:29 -08:00
Rachel Fenichel
3b168f5370 Fix #1538 2018-01-26 15:20:19 -08:00
Rachel Fenichel
9a3dc70031 Declare developer variables before user variables. Rebuild generators. 2018-01-17 17:38:26 -08:00
Rachel Fenichel
9b091a8f9e Update procedure generators 2018-01-02 16:27:17 -08:00
Rachel Fenichel
3d0567fe46 JS and Dart generator tests pass 2017-12-20 15:14:37 -08:00
marisaleung
dc97909abd Edit generators to read in Variable Models. 2017-05-15 12:19:04 -07:00
marisaleung
d903b5e86b VariableMap and functions added. 2017-05-03 10:51:24 -07:00
Neil Fraser
7928fac3ce Collapse the five 0/1-based index flags into one option. 2016-10-06 17:54:43 -07:00
Rachel Fenichel
350e1ff2cc Merge remote-tracking branch 'upstream/develop' into feature/variable_management_merge_develop 2016-08-08 16:58:51 -07:00
Neil Fraser
a76635d352 Fix line wrapping in Dart comments. 2016-07-15 20:06:01 -07:00
Rachel Fenichel
f040929bd8 Merge remote-tracking branch 'upstream/develop' into feature/merge_develop 2016-07-15 13:07:07 -07:00
Monica Kozbial
2b191e897e Adding indexing settings, tests and fixing bugs (#464)
* Add indexing setting for JavaScript Generation

Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default.

* Updating js lists to do zero and one based index

Updated generated JavaScript to change depending on whether one based indexing is enabled or not.

* Updating js text to do zero and one based index

Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting.

* Start of python indexing

Start of work on allowing one and zero indexing for generated python for lists.

* Fixing bug and lint fixed

Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing

* Converting from if to switch statements

Comverting if statements to switch statements when appropriate and adding spacing.

* Modified sublist JavaScript generation

Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create).

* Stripping unecessary ids

Removing ids from xml file.

* Localisation updates from https://translatewiki.net.

* Fix typo in flyout.js (#403)

* Fix typo in flyout.js (#402)

* Localisation updates from https://translatewiki.net.

* Add indexing setting for JavaScript Generation

Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default.

* Updating js lists to do zero and one based index

Updated generated JavaScript to change depending on whether one based indexing is enabled or not.

* Updating js text to do zero and one based index

Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting.

* Fixing bug and lint fixed

Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing

* Converting from if to switch statements

Comverting if statements to switch statements when appropriate and adding spacing.

* Modified sublist JavaScript generation

Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create).

* Stripping unecessary ids

Removing ids from xml file.

* Updating generator test

Modifying sublist test and re-formatting spacing between blocks.

* Updating js lists to do zero and one based index

Updated generated JavaScript to change depending on whether one based indexing is enabled or not.

* Updating js text to do zero and one based index

Change so that JavaScript generated for text blocks either assumes blocks use zero or one based index based on setting.

* Fixing bug and lint fixed

Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing

* Converting from if to switch statements

Comverting if statements to switch statements when appropriate and adding spacing.

* Modified sublist JavaScript generation

Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create).

* Stripping unecessary ids

Removing ids from xml file.

* Localisation updates from https://translatewiki.net.

* Localisation updates from https://translatewiki.net.

* Updating js lists to do zero and one based index

Updated generated JavaScript to change depending on whether one based indexing is enabled or not.

* Fixing bug and lint fixed

Fixing bug caused by not setting the return of concat when concatenating lines for sublist and substring functions. Also renamed these functions to be getSubsequece. Fixed lint errors with spacing

* Modified sublist JavaScript generation

Added case so that helper function is not generated if not necessary. Helper function is not generated if list length is not needed or if list is a simple block (such as a variable, as oppossed to a function call or list create).

* Stripping unecessary ids

Removing ids from xml file.

* Updating generator test

Modifying sublist test and re-formatting spacing between blocks.

* Adding tests for indexing and extra cases

Adding tests for indexing with custom block to adjust number based on what indexing is being generated.

* Adding tests and renaming tests

Adding tests for sublist and renaming tests.

* Fixes for order for sublists

Fixes so that parenthesis are generated properly for index for sublist

* Cleaning up test generated code

Changing order returned for unit test adjust index function to generate less unecessary parenthesis.

* Adding tests for order

Adding tests for order, relevant for methods that use index from start (because 1 is added)

* Fixing JS order for getIndex and setIndex

Changing to the correct order type when calling valueToCode in JS generation for getIndex and setIndex.

* Fixed unittest adjustIndex

Fixed uninttest adjustindex to also check whether the ONE_BASED_INDEXING variable has been defined to ensure proper behaviour.

* Fixing lint and formatting for JS/lists

Making line fixes and changing an if/elseif to case statement.

* Tests added to include case for bug found

Added tests with sublist combinations of different where's for the two indices after bug for this found in python.

* Adding and renaming tests

Adding test case for creating a sublist that encompasses the whole list but uses # and #-end instead of first last (applicable for python). Also, renaming tests.

* Adding contant and fixing python lists bugs

Adding contant for ONE_BASED_INDEXING and fixing bugs in python for lists.

* Fixing test get random

Fixing test get random to take into account indexing for return value.

* Adding indexing checkbox to test page

Adding checkbos on test page so that code can be generated for one and zero based indexing. Languages that are generated with zero based indexing that do not have it implemented will fail tests as expected.

* Fixing unittest getremove random

Fixing unittest getremove random to take into account the return value based on indexing.

* Change comparison for getremove random test

Fixed comparison to equal for the return value for getremove random.

* Fixing bugs with lists zero-indexing

Fixing getIndex and getSublist methods to pass for zero-indexed tests.

* Adding test cases and formatting

Adding test cases to text tests, reordering a couple list test, and formatting block spacing.

* Fixing unittest expected value

Fixing expected value fore unit tests for sublist.

* Cleanup

Removing obvious comments, formatting fixes, and naming in generated code in JS.

* Helper function for Python lists

Adding helper function for casting to int for indices.

* Expanding helper to reduce duplicated code

Expanding helper method to also get the property with the correct order and check indexing to reduce duplicated code.

* Cleaning up JS indexing with helper function

Adding helper function for indexing and used it in lists and text.

* Moving helper function and formatting fixes

Moving helper function, formatting fixes, and changing some generated code variable names.

* Fixing python generation for text

Fixing all failinng tests for python and using new helper method.

* Lint fixes and order in indexOf

Making lint fixes and correcting returned order in indexOf.

* Python variable renaming

Renaming a few generated variables.

* Fixing comment and order

Fixing comment to list Blockly.Block type and fixing order because it could be higher.

* Switching back to if

Switching switch back to if statements because there weren't enough cases to warrant for a switch.

* Adding order and fixing lists for Dart

Adding if null operator to operator precedence for Dart. Also, fixing lists implementation to pass unit tests and adding zero-indexing functionality.

* Formatting and lint fixes

Formatting and lint fixes

* Dart text fixed

Fixing Dart text generation to pass unit tests.

* Changing back  to variable

Changing switch condition back to variable.

* Fixing ORDER_OVERRIDES

Inner and outer order was switched .

* Adding bug with order caused by generator change

Flooring order before comparision because of how the order constants were modified.

* Adding list tests

Adding tests for additional cases for lists/

* Adding comment for dart order

Adding comment for Dart ORDER_IF_NULL operator.

* Formatting fixes

Formatting fixes for line indentation.

* Fixing PHP order and lists generation

Fixing PHP order constants and fixing lists so that they pass unit tests.

* Fixing tests

Removing duplicate unit test

* Adding text tests

Adding tests for text.

* Renaming variable and removing unused variable

Renaming variables from exceptionIndex to errorIndex and removing unused at variable.

* Adding missing function call to test

Adding missing funciton call to test that was causing tests to fail when they shouldn't.

* Fixing PHP text generation

Fixing PHP text code generation so it passes unit tests.

* Formatting fixes

Cleaning up code, renamiing a variable.

* Fixing failing subsequence tests

Fixing JS code that failed for sublist/substring tests.

* Fixing intentation

Fixing indentation.

* Fixing Dart sublist/substring

Fixing sublist/substring to include condiiton where FROM_START  (and not throw error by mistake) when zero-indexed.

* Adding order subtraction test

Adding test for checking order for subtraction x- (y - z) x  - (y + z).

* Updating to new PHP power operator

Updating from pow function to ** operator to clean up code.

* Updating to new removeWhere

Updating removeMatching to removeWhere because new version of Dart now use removeWhere.

* Fix for lua rounding assertequals

Adding check for number in equlity check for comparing number for floats.

* Adding test for copy of list

Adding test that checks the list is copied when a sublist is made first-last.

* Formatting and order fixes

Fixing formatting such as indentation and order fixes.

* Adding comment for clarity

Adding comment about how Lua code generation is not supporting zero indexing.

* Changed variable names in code

Changed variable names to follow style guide and changed for loop variable from n to i as is typical.

* Reducing unecessarily generated functions and renaming variables

Reducing number of generated functions using gensym_ by adding parameters to provided function. Renaming variables to make functions more readble.

* Fixing sublist order and sort variable

Fixing order used for valueToCode for sublist and renaming list variable in sort to match rest of code..

* Fixing order constant order

Removing operator () that was incorrect and addiung ~,

* Fixing order and indentation

Fixing order return fro create lists blocks and fixing indentationn for string array.

* Fixing order and renaming variables

Fixing order to be the correct strength and renaming variables to be more readable/

* Changing assert blocks for unit tests

Changing assert blocks to have a value input instead of a field so there is more flexibility in writing tests.

* Cleaning up and adding missing order tests

Adding tests for order for paramters for list blocks that weren't being tested to uncover bugs. Test were also cleaned up/reorganized/renamed to be more readable and shorter vertically (but lines  wider horizontally).

* Compile error fix and order in Dart generation.

Fixing compile error in generated code and incorrect order in get sublist for Dart.

* Fixing typo in getIndex and invalid parameter name

Fixing type in getIndex where list code should have been appended but instead an undefined variable was added. The parameter in lists_sort was changed to my_list because list is a reserved word in python.

* Fixing order, parenthesis bug, and variable declaration in Lua

Fixing incorrect order in Lua. Fixing bug caused by missing parenthesis around ternary operator in code. Variable code was declared with JavaScript syntax, this was fixed to be valid in Lua.

* Adding tests and formatting tests

Adding missing test for order in text/lists. Changing spacing/order of tests and updating comments.

* Fixing error in code

Changing to correct function call in empy tests and changing test name that was duplicated to be more clear.

* Renamed test helper function

* Fixing order and renaming variable in JS generator

Fixing order for charAt and renaming variable in code list_sort from listCode to list to be consistent with rest of code.

* Fixing order for dart text

Fixing roder for dart charAt

* Cleaning up generated code for Dart getIndex

Cleaning up generated code for Dart getIndex so that helper functions aren't generated unecessarily and adding comments.

* Fixing Dart remove random error

Fixing error caused by remove random implementation in Dart. index should have been x but instead was length - x.

* Fixing unit test blocks

Fixing Lua unit test block that should have just returned the number and removing unecessary checks in other blocks because the constant was defined.

* Fixing Lua assert equals block

string.format was throwing an error if one of the values happened to be a boolean.

* Adding tests for create text with number

Adding test for create text with numbers as parameters

* Fixing lua unit test block

Lua unit test block should have added 1

* Removing indexing setting for Lua tests

Removing setting index setting for Lua generation because it is always one-indexed.

* Fixing order and create text

Fixing failing test caused by improper order and fixed create text to properly convert to string when there is one element.

* Running linter on generator code

Running linter on generator code and fixing spacing/indentation problems.

* Editing comments and removing uneeded parenthesis

Editing and adding comments and removing uneeded parenthesis around ternary operator condition.

* Fixing order and changing variable names

Fixing orders that were incorrect and changing variable names to be more descriptive and consistent across code.

* Adding comment about list support and fixes for PHP

Adding comment about how lists are not fully supported for PHP. Adding missing order to PHP and fixing order errors throughout. Fixing regex for variable matching in lists. Cleaning up variable names to be more readable and consistent with other parts of code.

* Reducing complexity for getremove/remove in JS

Reducing complexity in generated code for getremove/remove in JavaScript by replacing unecessary helper function.

* Fixing spacing before inline comments

Ensuring there are two spaces before inline comments.

* Changing JS list copy for clarity

Changing JavaScript list copy to use slice(0) instead of concat for clarity and to use the same pattern as the other sublist methods.

* Changing generated variable name tmp_x

Changing tmp_x to tmpX to follow closer to the correct style for JavaScript.

* Prefixing empy lines between comment text

Prior to this change, comments with an empty line between text did not have a comment prefix before it, resulting in comment blocks that seemed disjoined although they were for the same block. This change affects how the prefix line function works so that those lines will have the prefix (if applicable) while still taking into account the trailing newline character.

* Changing for loops variable names

Changing most for loops to use i as the variable name (or j if applicable) or changing name to be more readable.

* Simplifying provided subsequence function

Simplifying subsequence function to generate a simpler function depending on where combination instead of a larger complex function that works for all where combinations.

* Style fixes

Fixing indentation, comments, and other formatting-type changes based on pull request comments.

* Fixing indentation

Fixing indentation and removing an extra newline.

* Fixing PHP mode implementation

Fixing PHP mode implementation to properlyu return multiple modes if applicable.

* Fixing line too long

Wrapping lines in php/math.js with lines longer than 80 characters.

* Wrapping long lines

Wrapping lines that are too long.

* Changing boolean casing

Changing boolean casing to be lowercase.
2016-07-08 11:43:48 -07:00
Rachel Fenichel
4a81ecb601 Create variable list, and use it for add and rename 2016-07-07 14:38:56 -07:00
Neil Fraser
4ba2b1bea3 Use a comment block for function comments in generated JS, Python and Dart. 2016-06-06 00:19:36 -07:00
Neil Fraser
bfa842c9a8 Remove claim that good.string.quote should be used. 2016-06-02 16:31:49 -07:00
Neil Fraser
7d94a34984 Initialize generated JS and Dart variables in one line. 2016-05-17 10:13:37 -07:00
Neil Fraser
0274763beb Clean up temporary generator data. 2015-08-14 18:26:05 -07:00
Neil Fraser
e0f90e6e33 Adding more type documentation. 2015-07-13 15:03:22 -07:00
Neil Fraser
d8a72df17f Generalize PHP $ hack for variables. 2015-07-02 19:59:32 -07:00
Neil Fraser
315a5fc762 Remove global workspace references from variable and procedure utilities. 2015-01-12 14:57:00 -08:00