Commit Graph

246 Commits

Author SHA1 Message Date
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
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
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
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
ed0b5adcd1 Wrong language. 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
tojimjiang
25b883d920 Remove Python references in Dart math generator
Resolves #2329
Commit in develop branch
2019-03-27 15:48:03 -07:00
Rachel Fenichel
e4690902de Merge pull request #2179 from DubeySandeep/PHP-text-outerOrder
Fix #2161: Changes outerOrder for PHP/text component.
2018-12-17 13:28:20 -08:00
Sandeep Dubey
8d09419afc Changes outerOrder for PHP/text component. 2018-12-16 22:32:19 +05:30
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
Andrew n marshall
9252c947bc Add new atan2 block (PR #2079)
Merge pull request from nadyafebi/add-atan2-support-1835
2018-10-16 11:27:00 -07:00
Andrew n marshall
58bfab7c6c Math.PI => Math.pi
The Dart test was failing prior to this.
2018-10-16 11:25:10 -07:00
Neil Fraser
4f714716a5 Upgrade to dart 2.0 2018-10-15 16:17:50 -07:00
Nadya Febiana Djojosantoso
d3deeedc02 Add math_atan2 Python generator 2018-10-11 14:34:26 -07:00
Nadya Febiana Djojosantoso
c61822befa Add math_atan2 PHP generator 2018-10-11 14:20:27 -07:00
Nadya Febiana Djojosantoso
683a738166 Add math_atan2 Lua generator 2018-10-11 14:19:40 -07:00
Nadya Febiana Djojosantoso
fd0bcabacd Add math_atan2 Dart generator 2018-10-11 14:19:01 -07:00
Nadya Febiana Djojosantoso
23bb0e00d9 Add math_atan2 JavaScript generator 2018-10-11 14:18:25 -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
Andrew n marshall
f42291ea64 Do not escape % in python strings. (#1982)
Rebase of PR-1890, commit 793055… from Ellipsis753:patch-1
2018-07-20 15:54:11 -07:00
Neil Fraser
c8bfc888c8 Throw errors instead of strings. (#1974)
Blocks and generators
2018-07-16 16:33:44 -07:00
Neil Fraser
6203cadcae Move away from math.log10 and math.pow in Lua generators.
Fixes #1695
2018-03-12 11:35:29 -07:00
Neil Fraser
10dbf2cc6d Random typos.
@rachel-fenichel LGTMs in person.
2018-02-21 17:47:01 -08: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
Neil Fraser
a4ec65d85d Improve support >ES5 and Node.
Adds ‘yield’ and ‘**’ to JS order list.
Build generates files (more) parsable by Node.
This PR should have no effect on existing code.
2018-01-25 11:47:11 -08:00
jschanker
f0b68fad66 Fixed JS/PHP generators for math_number
It was returning ORDER_ATOMIC for the block for any number; changed it so that it now returns ORDER_UNARY_NEGATION for negative numbers.
2018-01-25 09:02:38 -08:00
Nat Zimmermann
9ce13d8883 Add ORDER_AWAIT constant to JavaScript generator 2018-01-25 09:02:18 -08:00
Rachel Fenichel
dc5267da65 Merge pull request #1547 from rachel-fenichel/feature/dev_var_ordering
Declare developer variables before user variables.  Rebuild generators.
2018-01-18 10:24:37 -08:00
Rachel Fenichel
9a3dc70031 Declare developer variables before user variables. Rebuild generators. 2018-01-17 17:38:26 -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
Rachel Fenichel
9b091a8f9e Update procedure generators 2018-01-02 16:27:17 -08:00
Rachel Fenichel
24cf1cf7dd Remove TODO and get rid of unnecessary wrapper call. 2017-12-21 10:54:54 -08:00
Rachel Fenichel
0a0b6f3848 Add error; python and php tests pass. 2017-12-20 16:28:14 -08:00
Rachel Fenichel
fced496d28 Lua generator tests pass with new variables 2017-12-20 15:23:05 -08:00