{"id":24896764,"url":"https://github.com/gdenisc/jsc","last_synced_at":"2026-02-20T01:31:52.261Z","repository":{"id":270825296,"uuid":"911514077","full_name":"GDenisC/jsc","owner":"GDenisC","description":"JavaScript Compiler (babel plugin)","archived":false,"fork":false,"pushed_at":"2025-03-18T18:54:42.000Z","size":84,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T02:02:02.644Z","etag":null,"topics":["babel","babel-plugin","javascript","js"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GDenisC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-01-03T07:39:10.000Z","updated_at":"2025-03-18T18:54:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"966ed466-5db3-4b8f-90a0-84194b9038bc","html_url":"https://github.com/GDenisC/jsc","commit_stats":null,"previous_names":["gdenisc/jsc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GDenisC/jsc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GDenisC%2Fjsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GDenisC%2Fjsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GDenisC%2Fjsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GDenisC%2Fjsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GDenisC","download_url":"https://codeload.github.com/GDenisC/jsc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GDenisC%2Fjsc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279183671,"owners_count":26121446,"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","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["babel","babel-plugin","javascript","js"],"created_at":"2025-02-01T20:15:08.795Z","updated_at":"2025-10-16T11:31:13.762Z","avatar_url":"https://github.com/GDenisC.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript Compiler\n\n## Checklist\n\n- [x] JavaScript reader - babel\n\n- [ ] [Class Destructuring (WIP)](https://github.com/GDenisC/jsc/issues/1)\n\n- [ ] Precalculation\n\n- [ ] Unglobalization\n\n- [ ] `@inline`\n\n- [ ] `@macro`\n\n- [ ] `@const`\n\n- [ ] Stack\n\n- [ ] Registers\n\n- [ ] Bytecode\n\n- [ ] ASM.js\n\n- [ ] WASM\n\n## [Class Destructuring](https://github.com/GDenisC/jsc/issues/1)\n\nConverts a Class declaration into a series of equivalent function declarations.\nOnly works with top-level classes.\n\n- V8 optimizations\n- Better code compression results\n\n### Example 1\n\n```js\nclass Foo {\n    constructor() {\n        this.x = 1;\n    }\n\n    get x() {\n        return this.x;\n    }\n}\n\nconsole.log(new Foo().x);\n```\n\n```js\nfunction Foo_constructor() {\n    /* or just return { x: 1 } */\n    var self = {};\n    self.x = 1;\n    return self;\n}\n\nfunction Foo_get_x(self) {\n    return self.x;\n}\n\nconsole.log(Foo_get_x(Foo_constructor()));\n```\n\n### Example 2\n\n```js\nclass Foo {\n    getHelloString() {\n        return 'hello';\n    }\n}\n\nclass Bar extends Foo {\n    getHelloString() {\n        return super.getHelloString() + ' world';\n    }\n}\n\nconsole.log(new Bar().getHelloString());\n```\n\n```js\nfunction Foo_getHelloString(self) {\n    return 'hello';\n}\nfunction Bar_getHelloString(self) {\n    return Foo_getHelloString(self) + ' world';\n}\n\nconsole.log(Bar_getHelloString({}));\n```\n\n## Precalculation\n\n```js\nfunction foo(x) {\n    return Math.sqrt(x * x + x * x) + 60 * 2 - 20;\n}\n```\n\n```js\nfunction foo(x) {\n    var _0 = x * x;\n    return Math.sqrt(_0 + _0) + 100;\n}\n```\n\n## Unglobalization\n\n- Patches some hooking techniques (replacing a function/method with a malicious version)\n- Better code compression results\n\n```js\nfunction randomInt(x) {\n    return Math.floor(Math.random() * x);\n}\n```\n\n```js\nvar Math_floor = Math.floor,\n    Math_random = Math.random;\nfunction randomInt(x) {\n    return Math_floor(Math_random() * x);\n}\n```\n\n## `@inline`\n\nfunctions and class methods\n\n```js\n/** @inline */\nfunction randomInt(x) {\n    return Math.floor(Math.random() * x);\n}\n\nrandomInt(10);\nrandomInt(20);\n```\n\n```js\nMath.floor(Math.random() * 10);\nMath.floor(Math.random() * 20);\n```\n\n## `@macro`\n\n```js\n//@macro if DEBUG\nfunction log(message) {\n    console.log(message);\n}\n//@macro else\nfunction log(_) {}\n//@macro endif\n\nlog('Hello!');\n```\n\n\u003e ```js\n\u003e //@macro set DEBUG 1\n\u003e ```\n\n```js\nfunction log(message) {\n    console.log(message);\n}\n\nlog('Hello!');\n```\n\n\u003e ```js\n\u003e //@macro set DEBUG 0\n\u003e ```\n\n```js\nfunction log(_) {}\n\nlog('Hello!');\n```\n\n## `@const`\n\nVariable that will be evaluated at compile time\n\n```js\n/** @const */\nconst ARR = [1, 10, 100, 1000];\n\n/** @const */\nconst WORD = (() =\u003e {\n    let words = ['answer is ', 'answer = ', 'hello, '];\n    return words[Math.floor(Math.random() * words.length)];\n})();\n\nconsole.log(WORD + ARR[2] * ARR[3]);\n```\n\nif i run the program 3 times:\n\n```js\nconsole.log('answer is ' + 100 * 1000);\n```\n\n```js\nconsole.log('answer = ' + 100 * 1000);\n```\n\n```js\nconsole.log('hello, ' + 100 * 1000);\n```\n\n## Stack\n\n```js\nfunction random(min, max) {\n    return min + Math.random() * (max - min);\n}\n\nconsole.log(random(10, 20));\n```\n\n```js\nvar __stack = [];\nfunction random() {\n    __stack.push(__stack[__stack.length - 1] + Math.random() * (__stack[__stack.length - 2] - __stack.pop()));\n    __stack.pop();\n}\n__stack.push(10 /* min */, 20 /* max */);\nrandom();\nconsole.log(__stack.pop());\n```\n\n## Registers\n\nRecursion is not supported\n\n```js\nfunction random(min, max) {\n    return min + Math.random() * (max - min);\n}\n\nconsole.log(random(10, 20));\n```\n\n```js\nvar reg0, reg1;\nfunction random() {\n    reg0 = reg0 + Math.random() * (reg1 - reg0);\n}\nreg0 = 10 /* min */;\nreg1 = 20 /* max */;\nrandom();\n// reg1 is \"released\"\nconsole.log(reg0);\n```\n\n## Bytecode build\n\n- less size\n- can be slower than js\n- fast build\n\n## ASM.js build\n\n- more size\n- a bit faster than js\n- fast build\n\n## WASM build\n\n- less size\n- much faster than js\n- slow build\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdenisc%2Fjsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgdenisc%2Fjsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgdenisc%2Fjsc/lists"}