{"id":18989396,"url":"https://github.com/source-academy/js-slang","last_synced_at":"2025-04-08T09:08:10.691Z","repository":{"id":32717854,"uuid":"140231241","full_name":"source-academy/js-slang","owner":"source-academy","description":"Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python","archived":false,"fork":false,"pushed_at":"2024-10-29T17:52:58.000Z","size":11581,"stargazers_count":68,"open_issues_count":72,"forks_count":104,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T19:04:42.814Z","etag":null,"topics":["cadet-frontend","compiler","hacktoberfest","interpreter","javascript","source-academy","source-language","transpiler","typescript"],"latest_commit_sha":null,"homepage":"https://source-academy.github.io/source/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/source-academy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-09T04:28:50.000Z","updated_at":"2024-10-22T13:57:36.000Z","dependencies_parsed_at":"2023-11-20T18:30:48.427Z","dependency_job_id":"34c823ff-7d64-47ab-8b60-adad840134d2","html_url":"https://github.com/source-academy/js-slang","commit_stats":{"total_commits":879,"total_committers":77,"mean_commits":"11.415584415584416","dds":0.6916951080773606,"last_synced_commit":"2e4c010147c77fba2d4dff981561230c7f6713d1"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/source-academy%2Fjs-slang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/source-academy%2Fjs-slang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/source-academy%2Fjs-slang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/source-academy%2Fjs-slang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/source-academy","download_url":"https://codeload.github.com/source-academy/js-slang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cadet-frontend","compiler","hacktoberfest","interpreter","javascript","source-academy","source-language","transpiler","typescript"],"created_at":"2024-11-08T17:06:26.824Z","updated_at":"2025-04-08T09:08:10.668Z","avatar_url":"https://github.com/source-academy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-slang\n\nOpen-source implementations of the programming language _Source_. Source is a series of small subsets of JavaScript, designed for teaching university-level programming courses for computer science majors, following Structure and Interpretation of Computer Programs, JavaScript Adaptation (\u003chttps://sourceacademy.org/sicpjs/\u003e).\n\n## Table of Contents\n\n- [js-slang](#js-slang)\n  - [Table of Contents](#table-of-contents)\n  - [Prerequisites](#prerequisites)\n  - [Usage](#usage)\n  - [Documentation](#documentation)\n    - [Requirements](#requirements)\n  - [Testing](#testing)\n  - [Error messages](#error-messages)\n  - [Using your js-slang in Source Academy](#using-your-js-slang-in-source-academy)\n  - [Using your js-slang in your local Source Academy](#using-your-js-slang-in-your-local-source-academy)\n  - [Building and publishing SICP package](#building-and-publishing-sicp-package)\n  - [Talks and Presentations](#talks-and-presentations)\n  - [License](#license)\n\n## Prerequisites\n\n- NodeJS v20\n- Python: On MacBook Pro with chip Apple M1 Pro, use python 3.10.12. Here is [the correct way to set Python 3 as default on a Mac](https://opensource.com/article/19/5/python-3-default-mac).\n- yarn: use the version specified in `package.json`. On macos, you may need to run `corepack enable`.\n## Usage\n\nTo build,\n\n```bash\n$ git clone --recurse-submodules https://github.com/source-academy/js-slang.git\n$ cd js-slang\n$ yarn\n$ yarn build\n```\n\nThis repository uses git submodules. To update existing repositories with a submodule,\n\n```bash\n# Init is only required on the very first time.\n$ git submodule update --init --recursive\n# Required subsequently every time you want to update the submodules.\n$ git submodule update --recursive --remote\n```\n\nTo add \\\"js-slang\\\" to your PATH, build it as per the above instructions, then run\n\n```bash\n$ cd dist\n$ npm link\n```\n\nIf you do not wish to add \\\"js-slang\\\" to your PATH, replace \\\"js-slang\\\" with \\\"node dist/repl\\\" in the following examples.\n\nTo try out _Source_ in a REPL, run\n\n```bash\n$ js-slang -c [chapter] # default: 1\n```\n\nYou can set additional options:\n\n```{.}\nUsage: js-slang [PROGRAM_STRING] [OPTION]\n\n  -c, --chapter=CHAPTER set the Source chapter number (i.e., 1-4)                                                              (default: 1)\n  -v, --variant=VARIANT set the Source variant (i.e., default, interpreter, substituter, typed, concurrent, wasm) (default: default)\n  -h, --help            display this help\n  -e, --eval            don't show REPL, only display output of evaluation\n```\n\nCurrently, valid CHAPTER/VARIANT combinations are:\n\n- `--chapter=1 --variant=default`\n- `--chapter=1 --variant=wasm`\n- `--chapter=1 --variant=substituter`\n- `--chapter=1 --variant=interpreter`\n- `--chapter=1 --variant=typed`\n- `--chapter=2 --variant=default`\n- `--chapter=2 --variant=substituter`\n- `--chapter=2 --variant=interpreter`\n- `--chapter=2 --variant=typed`\n- `--chapter=3 --variant=default`\n- `--chapter=3 --variant=concurrent`\n- `--chapter=3 --variant=interpreter`\n- `--chapter=3 --variant=typed`\n- `--chapter=4 --variant=default`\n- `--chapter=4 --variant=interpreter`\n\nHint: In `bash` you can take the `PROGRAM_STRING` out of a file as follows:\n\n```bash\n$ js-slang -n --chapter=1 -e \"$(\u003c my_source_program.js)\"\n```\n\n## Documentation\n\nSource is documented here: \u003chttps://docs.sourceacademy.org/\u003e\n\n### Requirements\n\n- `bash`: known working version: GNU bash, version 5.0.16\n- `latexmk`: Version 4.52c\n- `pdflatex`: known working versions\n  - pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017)\n\nTo build the documentation, run\n\n```bash\n$ git clone https://github.com/source-academy/js-slang.git\n$ cd js-slang\n$ yarn\n$ yarn install\n$ yarn jsdoc  # to make the web pages in js-slang/docs/source\n$ cd docs/specs\n$ make        # to make the PDF documents using LaTeX\n```\n\n**Note:** The documentation may not build on Windows, depending on your bash setup, [see above](https://github.com/source-academy/js-slang#requirements).\n\nDocumentation on the Source libraries are generated from inline documentation in the library sources, a copy of which are kept in `docs/lib/*.js`. The command `yarn jsdoc` generates the documentation and places it in the folder `docs/source`. You can test the documentation using a local server:\n\n```bash\n$ cd docs/source;  python -m http.server 8000\n```\n\nDocumentation of libraries is displayed in autocomplete in the frontend. This documentation is generated by `./scripts/updateAutocompleteDocs.py` and placed in `src/editors/ace/docTooltip/*.json` files. This script is run by `yarn build`prior to`tsc`. To add a Source variant to the frontend autocomplete, edit `src/editors/ace/docTooltip/index.ts` and`./scripts/updateAutocompleteDocs.py`.\n\n## Testing\n\n`js-slang` comes with an extensive test suite. To run the tests after you made your modifications, run `yarn test`. Regression tests are run automatically when you want to push changes to this repository. The regression tests are generated using `jest` and stored as snapshots in `src/\\_\\_tests\\_\\_`. After modifying `js-slang`, carefully inspect any failing regression tests reported in red in the command line. If you are convinced that the regression tests and not your changes are at fault, you can update the regression tests as follows:\n\n```bash\n$ yarn test --updateSnapshot\n```\n\n## Error messages\n\nTo enable verbose messages, have the statement `\"enable verbose\";` as the first line of your program. This also causes the program to be run by the interpreter.\n\nThere are two main kinds of error messages: those that occur at runtime and those that occur at parse time. The first can be found in `interpreter-errors.ts`, while the second can be found in `rules/`.\n\nEach error subclass will have `explain()` and `elaborate()`. Displaying the error will always cause the first to be called; the second is only called when verbose mode is enabled. As such, `explain()` should be made to return a string containing the most basic information about what the error entails. Any additional details about the error message, including specifics and correction guides, should be left to `elaborate()`.\n\nPlease remember to write test cases to reflect your added functionalities. The god of this repository is self-professed to be very particular about test cases.\n\n## Using your js-slang in Source Academy\n\njs-slang is used by the [Source Academy](https://sourceacademy.org), the immersive online experiential environment for learning programming. For this, js-slang is [deployed as an NPM package](https://www.npmjs.com/package/js-slang). The frontend of the Source Academy then includes the js-slang package in its deployment bundle.\n\n## Using your js-slang in your local Source Academy\n\nA common issue when developing modifications to js-slang is how to test it using your own local frontend. Assume that you have built your own frontend locally, here is how you can make it use your own js-slang, instead of the one that the Source Academy team has deployed to npm.\n\nFirst, build and link your local js-slang:\n\n```bash\n$ cd js-slang\n$ yarn build\n$ yarn link\n```\n\nThen, from your local copy of frontend:\n\n```bash\n$ cd frontend\n$ yarn link \"js-slang\"\n```\n\nThen start the frontend and the new js-slang will be used.\n\n## Building and publishing SICP package\n\nTo build SICP package\n\n```bash\n$ cd js-slang\n$ yarn\n$ yarn build_sicp_package\n```\n\nTo publish SICP package, update version number in `sicp_publish/package.json`\n\n```bash\n$ cd js-slang/sicp_publish\n$ npm publish\n```\n\n## Talks and Presentations\n\n- **How `js-slang` works under the hood** (17th Jan 2023 – The Gathering) ([slides](https://docs.google.com/presentation/d/1GFR39iznBZxWv948zUsmcbCSSDasm4xYs3Jc5GF7A3I/edit?usp=sharing))\n\n## License\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nAll sources in this repository are licensed under the [Apache License Version 2][apache2].\n\n[apache2]: https://www.apache.org/licenses/LICENSE-2.0.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsource-academy%2Fjs-slang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsource-academy%2Fjs-slang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsource-academy%2Fjs-slang/lists"}