Commit Graph

188 Commits

Author SHA1 Message Date
Neil Fraser
1c3f4f0524 fix: isPrime block should cast str as num (#5680)
Fixes #5678
2021-11-05 11:12:25 -07:00
Rachel Fenichel
3746688ebd chore: update lua block generators to const and let (#5662) 2021-11-05 09:57:59 -07:00
Rachel Fenichel
1b29a00267 chore: update php block generators to const and let (#5663) 2021-11-03 10:34:27 -07:00
Rachel Fenichel
de95ffd133 chore: update javascript block generators to const and let (#5661) 2021-11-03 10:27:13 -07:00
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
f4e7249b1a chore: update var to const and let in dart block generators (#5654) 2021-10-29 12:35:15 -07:00
Rachel Fenichel
6c49d6c7e9 chore: update language generators to const and let (#5647)
* chore: update generators/javascript.js to const and let

* chore: update generators/lua.js to const and let

* chore: update generators/php.js to const and let

* chore: update generators/python.js to const and let
2021-10-29 11:05:16 -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
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
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
Christopher Allen
f9d0caa112 Migrate core.global.js to named exports (#5451)
This is part of #5153 but is being prioritised because we want remove
the declareLegacyNamespace calls from the core/utils/*.js modules and
then reexport them explicitly via utils.js, and it turns out that
doing so results in the exports object of this module being passed to
Object.freeze - which fails on the global object, which can't be made
non-extensible!

The new name chosen for the former default export is globalThis, since
it is intended to have the same value as the global variable of that
name; see:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
2021-09-14 14:39:29 +01:00
Neil Fraser
861a981cb6 Remove extra else clauses 2021-06-09 11:41:42 -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
37a1ee55b8 Remove useless variable declarations in PHP. (#4849) 2021-05-27 21:40: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
d919b0af21 Update JSDoc from Array.<> to Array<>
Same with Object.
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
9ef5c853b3 Remove ORDER_COMMA from PHP generator. (#4357) 2020-10-08 14:23:09 -07:00
Monica Kozbial
3f88a3f193 Replace incorrect usage of ORDER_COMMA with ORDER_NONE (#4354) 2020-10-07 11:22:26 -07:00
Monica Kozbial
ef6f3ebe8c Clean up some text generator logic (#4342) 2020-09-30 15:18:40 -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
Rachel Fenichel
0b423abd4d Merge pull request #4294 from rachel-fenichel/bugfix/dart_multiline
Fix dart multiline strings
2020-09-18 13:51:38 -07:00
Rachel Fenichel
1350604e93 Fix dart multiline strings 2020-09-18 13:37:54 -07:00
Rachel Fenichel
7da8d4abfe Fix PHP multiline string 2020-09-18 13:27:04 -07:00
Rachel Fenichel
afcbb7036e Fix python multiline string 2020-09-18 12:11:48 -07:00
Rachel Fenichel
773a4430e7 Fix lua multiline quote 2020-09-18 11:02:17 -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
Rachel Fenichel
99dc14c323 Avoid .includes 2020-06-24 17:43:47 -07:00
Monica Kozbial
df1508b547 Use getter for variables in procedure generator. (#3971) 2020-06-15 09:47:51 -07:00
Monica Kozbial
d6abf4798e Fixing operator precedence in Lua and and adding test. (#3765)
* Fixing operator precedence in Lua and and adding test.

* Updating golden files.
2020-03-25 14:34:07 -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
ce02665044 Replace static reserved word list with dynamic scan (#3269)
This change means the list is complete for every environment.  This makes evaling code more safe.  However it also means that code generated on one environment isn't guaranteed to be free of global collisions when executed on another environment (with the exception of the JS Interpreter).

So if you are generating code in Node, and then executing it with eval() in a user's browser a user's program could declare a variable named `location`, assign to it, and the browser will redirect to that URL.  Honestly, that's what you get for evaling untrusted code between users.  Use the JS Interpreter if you are doing anything other than just generating and executing in the same environment.
2019-10-17 11:17:37 -07:00
Sam El-Husseini
986e965be8 Private/protected visibility cleanup (#3263)
* Fix a number of private visibility issues
2019-10-16 11:48:09 -05:00
RoboErikG
e62c2a3f6b Remove multi-line comments to avoid escaping (#3231)
Fixes #3230 by removing multi-line comments for procedures.
2019-10-14 10:40:22 -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
939bbd072b Lint 2019-08-02 11:00:40 -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