{"id":13659839,"url":"https://github.com/termi/es6-transpiler","last_synced_at":"2025-04-06T07:12:38.725Z","repository":{"id":9549483,"uuid":"11456310","full_name":"termi/es6-transpiler","owner":"termi","description":" Tomorrow's JavaScript syntax today","archived":false,"fork":false,"pushed_at":"2015-07-19T10:54:16.000Z","size":1416,"stargazers_count":216,"open_issues_count":38,"forks_count":18,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-10-20T02:52:57.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/termi.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}},"created_at":"2013-07-16T18:01:09.000Z","updated_at":"2023-10-24T18:45:13.000Z","dependencies_parsed_at":"2022-09-19T16:20:24.759Z","dependency_job_id":null,"html_url":"https://github.com/termi/es6-transpiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termi%2Fes6-transpiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termi%2Fes6-transpiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termi%2Fes6-transpiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/termi%2Fes6-transpiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/termi","download_url":"https://codeload.github.com/termi/es6-transpiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247237817,"owners_count":20906348,"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":[],"created_at":"2024-08-02T05:01:12.869Z","updated_at":"2025-04-06T07:12:38.702Z","avatar_url":"https://github.com/termi.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Transpilers"],"sub_categories":[],"readme":"# es6-transpiler.js\nes6 -\u003e es5\n\n## status\n\nBeta\n\n## Goal\n\n * different output than [traceur-compiler](https://github.com/google/traceur-compiler):\n     1. no runtime library (only polyfills if needed)\n     1. no try/catch for block binding\n     1. spread:\n       * via `.concat`\n       * should respect Iterator protocol\n       * spread is operator, not a function\n     1. minimal count of temporary variables\n     1. termination stage for temporary variables\n     1. es6 RegExp support\n     1. and others\n * output should support [Closure Compiler](https://code.google.com/p/closure-compiler/)\n * line-to-line input/output mapping\n\n## Supported\n\n * classes\n * generator comprehensions\n * destructuring (with default values)\n * block binding (let / const)\n   * loops: fresh lexical environment per iteration\n * function default parameters and rest\n * arrow functions\n * spread (with iterator protocol)\n * for-of (with iterator protocol)\n * array comprehensions (with iterator protocol)\n * string templates (with tags support)\n * object literals:\n   * methods\n   * shorthands\n   * computed properties\n * binary/octal numericLiteral\n * unicode code point escapes\n * RegExp:\n   * 'y' flag support (in runtime via polyfill)\n   * 'u' flag support:\n     * full transpiler-time support: [negative] astral symbols (surrogate pairs) ranges, \\D, \\W, '.' etc captures astral symbols\n     * partial runtime support see: [Not supported](#not-supported)\n\nStatic scope analysis and transpilation of ES6 block scoped `const` and `let` variables to ES3 based on [olov/defs](https://github.com/olov/defs).\n\n## Not supported\n\n * modules\n * generators\n * symbols\n * RegExp:\n   * 'u' flag in runtime (via polyfill) for the newly generated patterns:\n     1. \\D, \\W, '.' etc not supported\n     1. negative astral symbols (surrogate pairs) ranges\n\n## Supported iterator protocol\n\n```javascript\nvar obj = {a: 1, b: 2, c: 3};\nvar Symbol_iterator = typeof Symbol !== 'undefined' \u0026\u0026 Symbol.iterator || \"@@iterator\";\nobj[Symbol_iterator] = function() {\n\tvar iterableObject = this;\n\tvar keys = [\"a\", \"b\", \"c\"];\n\n\treturn {\n\t\tnext: function() {\n\t\t\tvar currentKey = keys.shift();\n\n\t\t\treturn {\n\t\t\t\tvalue: currentKey ? iterableObject[currentKey] : void 0\n\t\t\t\t, done: !currentKey\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n## Installation\n\nInstall using npm\n\n\tnpm install es6-transpiler\n\nOr just using [Grunt task](https://github.com/termi/grunt-es6-transpiler) (see below).\n\n## Usage\n\nFor the output code works you need an implementation of Object.create in the target browser.\nYou can get it here: [es5-shim](https://github.com/kriskowal/es5-shim/) or copy and past this code:\n```\nif(!Object.create)Object.create = function(_prototype) {//[Warning!!!]This is PURE and UNSAFE implementation of Object.create\n\tvar Type = function () {};\n\tType.prototype = _prototype;\n\tvar _object = new Type();\n\t_object.__proto__ = _prototype;\n\n\treturn _object;\n};\n```\n\n### Grunt task\n\n[Grunt](http://gruntjs.com/) task can be fount here: https://github.com/termi/grunt-es6-transpiler\n\nInstall:\n`npm install grunt-es6-transpiler`\n\nUsage:\n```javascript\ngrunt.loadNpmTasks('grunt-es6-transpiler');\n\ngrunt.initConfig({\n  \"es6-transpiler\": {\n    test: {\n        src: 'test.js'\n        , dest: 'test.es5.js'\n    }\n  },\n})\n```\n\n### Gulp task\n\n[Gulp](http://gulpjs.com/) task can be fount here: https://github.com/sindresorhus/gulp-es6-transpiler\n\nInstall:\n`npm install --save-dev gulp-es6-transpiler`\n\nUsage:\n```javascript\nvar gulp = require('gulp');\nvar es6transpiler = require('gulp-es6-transpiler');\n\ngulp.task('default', function () {\n    gulp.src('src/app.js')\n        .pipe(es6transpiler())\n        .pipe(gulp.dest('dist'));\n});\n```\n\n### In console\n\nRun it as `es6toes5 \u003cinput file\u003e`. Or `node --harmony es6toes5 \u003cinput file\u003e`. Also you can run a compiled es5 version `node build/es5/es6toes5 \u003cinput file\u003e`.\nThe errors (if any) will go to stderr, the transpiled source to `stdout`, so redirect it like `es6toes5 file.js \u003e output.js`.\n\n### Node.js / Using as a library\n\nrequire(\"es6-transpiler\").run(\\\u003cOptions\\\u003e)\n\nOptions is:\n\n\t{\n\t\tfilename: string // input file\n\t\tsrc: string // input source if not filename\n\t\toutputToConsole: boolean // if true -\u003e result would be outputted to console\n\t\toutputFilename: string // if specific -\u003e result would be written to file\n\t}\nOther options below in \"Options\" section.\n\n```javascript\nvar es6tr = require(\"./es6-transpiler\");\nvar result = es6tr.run({filename: \"test.js\"});\nconsole.log(result.src);//result\n```\nresult object is:\n\n    {\n        src: string or \"\" // on success\n        errors: array of error messages or [] // on errors\n        stats: statistics object\n        ast: transformed ast // ast tree from esprima\n        getNeedfulList: \u003cfunction: Array.\u003cstring\u003e\u003e // list of necessary polyfills\n        getNeedfulLib: \u003cfunction: string\u003e // text of necessary polyfills\n        getFullLib: \u003cfunction: string\u003e // text of all available polyfills\n    }\n\n## Options\n\nExample of `options` object:\n\n    {\n    \t//described above:\n    \t//\"filename\" or \"src\": \"string\"\n    \t//outputToConsole: false\n    \t//outputFilename: true\n\n        \"environments\": [\"node\", \"browser\"],\n\n        \"globals\": {\n            \"my\": false,\n            \"hat\": true\n        },\n        \"disallowVars\": false,\n        \"disallowDuplicated\": true,\n        \"disallowUnknownReferences\": true,\n        \"includePolyfills\": \u003cboolean\u003e | \u003c\"full\"\u003e,\n        \"polyfillsSeparator\": \u003cstring\u003e\n    }\n\n`globals` lets you list your program's globals, and indicate whether they are\nwritable (`true`) or read-only (`false`), just like `jshint`.\n\n`environments` lets you import a set of pre-defined globals, here `node` and\n`browser`. These default environments are borrowed from `jshint` (see\n[jshint_globals/vars.js](https://github.com/olov/defs/blob/master/jshint_globals/vars.js)).\n\n`disallowVars` (defaults to `false`) can be enabled to make\nusage of `var` an error.\n\n`disallowDuplicated` (defaults to `true`) errors on duplicated\n`var` definitions in the same function scope.\n\n`disallowUnknownReferences` (defaults to `true`) errors on references to\nunknown global variables.\n\n`includePolyfills` (defaults to `false`) insert polyfills in the output file.\n`true` - insert only the necessary polyfills. `\"full\"` -  insert all available polyfills.\n\n`polyfillsSeparator` (default - empty string) any string that should be inserted before polyfills library.\n\n## License\n`MIT`, see [LICENSE](LICENSE) file.\n\n\n## Example\n\nSee tests\n\n\n## Compatibility\n`es6-transpiler.js` strives to transpile your program as true to the ES6 semantics as\npossible, while being as maximally non-intrusive as possible.\n\n\n### Referenced (inside closure) before declaration\n`es6-transpiler.js` detects the vast majority of cases where a variable is referenced prior to\nits declaration. The one case it cannot detect is the following:\n\n```javascript\nfunction printx() { console.log(x); }\nprintx(); // illegal\nlet x = 1;\nprintx(); // legal\n```\n\nThe first call to `printx` is not legal because `x` hasn't been initialized at that point\nof *time*, which is impossible to catch reliably with statical analysis.\n`v8 --harmony` will detect and error on this via run-time checking. `es6-transpiler.js` will\nhappily transpile this example (`let` =\u003e `var` and that's it), and the transpiled code\nwill print `undefined` on the first call to `printx`. This difference should be a very\nminor problem in practice.\n\n## TODO\n 1. Generators support\n 1. Modules support\n 1. 'pre-es6-node10', 'pre-es6-chrome20' and 'pre-es6-ff24' output modes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftermi%2Fes6-transpiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftermi%2Fes6-transpiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftermi%2Fes6-transpiler/lists"}