# encoding: cinje
: def testcase
: for i in ('hello', 'world')
${i}
Ignoring default imports, optimizations, and line mapping, the transformed result is currently:
def testcase():
for i in ('hello', 'world'):
_buffer = []
__w, __ws = _buffer.extend, _buffer.append
__w((
'\t\t',
_escape(i),
'\n'
))
yield "".join(_buffer)
Note the dangerous location of buffer construction. If the loop were empty, it would not be called, but the code transformer considers the buffer prepared after that point regardless. In the empty test case, the subsequent yield will explode as _buffer would be undefined. Additionally, the buffer is overwritten on each iteration here.
Temporary workaround: include some emitted content prior to a function's first iterator. An HTML comment works well.
Simple fix: force buffer construction after function declaration.
Simplest test case:
Ignoring default imports, optimizations, and line mapping, the transformed result is currently:
Note the dangerous location of buffer construction. If the loop were empty, it would not be called, but the code transformer considers the buffer prepared after that point regardless. In the empty test case, the subsequent
yield
will explode as_buffer
would be undefined. Additionally, the buffer is overwritten on each iteration here.Temporary workaround: include some emitted content prior to a function's first iterator. An HTML comment works well.
Simple fix: force buffer construction after function declaration.