jbeard4 / SCION

SCXML/Statecharts in JavaScript, moved to gitlab: https://gitlab.com/scion-scxml/scion
https://scion.scxml.io
Apache License 2.0
149 stars 29 forks source link

foreach fails in strict mode due to undeclared shallow array name variable #369

Open mattoshry opened 8 years ago

mattoshry commented 8 years ago

This crops up when the app that hosts scion is run in use strict mode.

<datamodel>
  <data id="arr" expr="[10, 20, 30]"/>
  <data id="current"/>
  <data id="idx"/>
</datamodel>
 <foreach array="arr" item="current" index="idx">
        <log expr="'current: ' + current + ', idx: ' + idx" label="TEST"/>
 </foreach>
$scionArray_31 is not defined

The issue is here: https://github.com/jbeard4/SCION/blob/2424a0a4c7dd60ad15d7e574a8764ae976051fff/lib/compiler/scjson-to-module.js#L509

A fix:

         var forEachContents =
-            shallowArrayName + ' = ' + arr + ';\n'+
+            'var ' + shallowArrayName + ' = ' + arr + ';\n'+