Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define a block that compiles to custom JavaScript? #7572

Open
ghost opened this issue Oct 30, 2020 · 2 comments
Open

How to define a block that compiles to custom JavaScript? #7572

ghost opened this issue Oct 30, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 30, 2020

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) {
}
@pelikhan
Copy link
Member

pelikhan commented Nov 6, 2020

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.

@ghost
Copy link
Author

ghost commented Nov 6, 2020

It looks like I can edit pxt-blockly instead of a target to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant