Commit Graph

80 Commits

Author SHA1 Message Date
Neil Fraser fa47c3c4a8 Normalize ++x to x++. (#5660)
There are only 10 instances of ++x in our codebase, compared with over 500 instances of x++.  The stlye guide has no opinion on which to use, nor do I.  But the lack of consistency was making regex searches for bugs more difficult.
2021-11-02 09:22:11 -07:00
Rachel Fenichel db78d9f280 chore: replace var with const and let in python block generators (#5650)
* chore: replace var with const and let in python block generators

* chore: update test deps

* chore: update bracket usage in switch statements
2021-10-29 11:02:58 -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
alschmiedt 5b1586ee1b test: update mocha tests to use goog_module (#5440)
* Use goog.module in mocha tests

* Fix compiler warnings

* Make test helpers a module

* Name test modules Blockly.test.*

This is to be more consistent with how non-test modules are named.

Also remove top-level goog.require of TestHelpers (now
Blockly.test.helpers) since requiring a side-effect-less module does
nothing.

* Convert block_test.js and comment_test.js to goog.module syntax

* Address PR comments

* Goog modulify tests

* Goog modulify toolbox helpers

* Fixes imports and moves common tests from workspace_test.js to a helper file.

* Update test deps after rebase

Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2021-09-16 13:00:38 -07:00
Neil Fraser cff7b359f4 Make comments more consistent. 2021-06-09 11:41:42 -07:00
Neil Fraser 76b5517008 Use null-prototype objects for maps
A {} has a bunch of names already defined on it (like ‘toString’).  When using an object as a map with arbitrary keys, it should not inherit from Object.prototype.
2021-06-09 11:41:42 -07:00
Neil Fraser d919b0af21 Update JSDoc from Array.<> to Array<>
Same with Object.
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
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
Monica Kozbial fcc3a09661 Fix python loop (#4007)
* Fix code generation for python controls_for

* Update python golden file.
2020-06-30 11:35:48 -07:00
Monica Kozbial df1508b547 Use getter for variables in procedure generator. (#3971) 2020-06-15 09:47:51 -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 72c6aa8699 Block generator warnings (#3353) 2019-10-28 16:20:25 -07:00
Sam El-Husseini 64c52efb5b Resolve warnings in generator code (#3350) 2019-10-28 09:35:40 -07:00
alschmiedt b19e6a5fbf Remove deprectaed use of Blockly.Procedures.NAME_TYPE (#3301) 2019-10-22 04:33:13 -05: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
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 e77a9b7e81 Change parseFloat() to Number()
Number() is a bit less forgiving than parseFloat() and is more likely to generate NaN rather than some random number.  An audit of each case shows nowhere that parseFloat()’s features are needed.
2019-08-01 11:36:58 -07:00
Neil Fraser 92c4d6d3a3 Fix colour injection vulnerability.
The new validators already solve this problem, but as a second layer of defence, the generators should also be secured.  Issue #2637
2019-07-15 16:03:55 -07:00
Neil Fraser 05253d0766 Add prefix/suffix to orphaned value blocks.
Also respect suppressPrefixSuffix on loops when generating prefix/suffix with continue/break blocks.
2019-05-17 15:04:39 -07:00
Neil Fraser e642a77f5d Use conventional prefix/suffix for function calls.
Previously a function call with no return value generated:

  prefix();
  suffix();
  function();

The intent was so the prefix and suffix calls in the function body wouldn’t overlap with the prefix and suffix calls of the function call.  However, this is doomed to be inconsistent with a function call with a return value:

  prefix();
  print(function());
  suffix();

Thus since overlaping must exist, both types of function calls should have consistent suffix locations.
2019-05-17 15:04:39 -07:00
Neil Fraser 04e39c20f8 Fix indentation bug if no xfix exists in function 2019-05-14 17:19:31 -07:00
Neil Fraser 585866a1b6 Revisit function block for return.
Visit (with prefix and suffix) function block when executed.  This commit adds a revisit at the end of the function body when evaluating the return value.
2019-05-14 17:19:31 -07:00
Neil Fraser c0e14c3a7c Add method to suppress prefix/suffix from blocks.
This allows generators to have more control over the placement of suffix.  Needed for ‘if’ blocks and function calls which require their suffix code to be somewhere other than the end.
Also, add loop’s prefix to ‘break’ blocks, since the loop’s suffix will be the next statement hit.
Also, reuse procedures_callreturn generator for procedures_callnoreturn.
2019-05-14 17:19:31 -07:00
Neil Fraser 25adb40e66 Prefix and suffix edge cases for flow statements.
Call suffix code on break/continue before executing the break/continue.
Call prefix code for enclosing loop before executing continue.
2019-05-14 17:19:31 -07:00
Neil Fraser 0259f8bb48 Add extra suffix when generating if/return block.
Also fix loops in Lua.
2019-05-14 17:19:31 -07:00
Neil Fraser ba18ae2159 Add STATEMENT_SUFFIX
Also remove need to manually indent INFINITE_LOOP_TRAP.  This is a breaking change for Python users of this property.  However, very few users of this property exist, given that the existing code breaks if the block ID has a $ in it (also fixed in this PR).
2019-05-14 17:19:31 -07:00
Nadya Febiana Djojosantoso d3deeedc02 Add math_atan2 Python generator 2018-10-11 14:34:26 -07:00
Neil Fraser f3a76cc288 Remove unneeded String() and str() calls.
String literals in JS and Python don’t need to be coerced to strings.
2018-09-25 14:00:00 -07:00
Neil Fraser c8bfc888c8 Throw errors instead of strings. (#1974)
Blocks and generators
2018-07-16 16:33:44 -07:00
Rachel Fenichel 6d96e4003b Merge pull request #1576 from rachel-fenichel/bugfix/1574
Add generators for dynamic variable blocks.
2018-01-29 16:20:28 -08:00
Rachel Fenichel bce24fef6b Add generators for dynamic variable blocks. 2018-01-26 17:10:45 -08:00
Rachel Fenichel 3b168f5370 Fix #1538 2018-01-26 15:20:19 -08:00
Rachel Fenichel 376b3c4b44 Update procedure generators for PHP and Python to declare developer variables as globals 2018-01-17 13:04:41 -08:00
Nicole Parrot 97ce5b3e4f Fix indentation for function blocks with return statements (#1362)
* fix indentation for the return statement in function blocks that return a value

* Fix hard-coded autoindent, and swap it for Blockly.PHP.INDENT

* Fix hard-coded 2 spaces indent and use language-appropriate global indent
2017-10-17 15:20:11 -07:00
Nicole Parrot 4df6f11f8a Do not assume an indentation of 2 spaces when writing the global variables at the top of a function declaration. (#1356) 2017-10-10 16:06:40 -07:00
Neil Fraser f34a2c2ed4 Properly escape IDs in procedure generators. (#1305)
Issue #251 and #1304.
2017-09-04 08:51:16 -07:00
marisaleung 47872b4ada Fix code generation for procedures (PHP, Python). 2017-07-17 11:42:36 -07:00
marisaleung 693bdbb10e Fix python and php procedures. 2017-06-26 11:51:32 -07:00
marisaleung d903b5e86b VariableMap and functions added. 2017-05-03 10:51:24 -07:00
Tim Dawborn 46316c7cea Add a block to reverse a list (#844) 2017-01-21 10:48:42 -08:00
Tim Dawborn 34750bccd8 New blocks text_count, text_replace, and text_reverse (#830)
Includes generators for all languages and units tests on those generators.
2017-01-20 16:08:27 -08:00
Neil Fraser 90b63f49cb Python false is False. Issue #828. 2017-01-16 09:33:02 -08:00
Andrew n marshall e5d25bb686 String reference in JSON string messages (#741)
* Adds message references to message string interpolation, in the form of %{BKY_STRING}.
 * Re-adding CONTROLS_IFELSE block using the new syntax, referencing to CONTROL_IF equivalents.
2016-11-15 15:51:51 -08:00
Rachel Fenichel 82261e3d68 Remove ifelse block and messages' 2016-11-11 17:21:29 -08:00
Andrew n marshall 72ff6d9ead Adding controls_ifelse block (#722)
Adding controls_ifelse, an if/else block that is loaded from JSON and does not use mutators. This gives "else" capability to Android & iOS implementations, which don't support JavaScript mutators.

Added this block to the playground simple toolbox and all generators.
2016-10-31 11:00:39 -07:00
RoboErikG 35d1fa575e Merge pull request #679 from drigz/bugfix/677
Don't modify workspace.variableList in generators
2016-10-11 12:31:13 -07:00
Neil Fraser 7928fac3ce Collapse the five 0/1-based index flags into one option. 2016-10-06 17:54:43 -07:00
Rodrigo Queiro 90082ef495 Don't modify workspace.variableList in generators
Fixes #677.
2016-10-06 16:38:06 +02:00