How to define a block that compiles to custom JavaScript?
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 641
- Avg merge
- 12h 4m
- Merged PRs (30d)
- 57
Description
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) {
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the shown pxsim.myblocks namespace, the //% block annotation, and the generated myblocks.forEach output. Read the PXT block-definition and transpilation entry points to determine whether custom JavaScript output is supported and how it is configured. Done means documenting the supported approach, or clearly stating the limitation and any required constraints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers, tooling
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100