pxt
pxt copied to clipboard
How to define a block that compiles to custom JavaScript?
I can define blocks like this:
namespace pxsim.myblocks {
//% block="for $item in $list"
//% draggableParameters
export function forEach(list: any[], handler: (item: any) => void): void {
for (let _item of list) {
handler(_item);
}
}
}
This block transpiles to
myblocks.forEach(null, function (item) {
})
How can I create a custom block that transpiles to
for (let item of list) {
}
Language constructs like for
require specific handling in the blocks->TypeScript and TypeScript->Blocks compiler so those blocks are "baked into the compiler". So the answer is no, unless you integrate your changes in pxt itself as a pull request.
It looks like I can edit pxt-blockly instead of a target to do this