{"name":"defs","version":"1.1.1","description":"Static scope analysis and transpilation of ES6 block scoped const and let variables, to ES3.","main":"build/es5/defs-main.js","repository":{"type":"git","url":"https://github.com/olov/defs.git"},"dependencies":{"alter":"~0.2.0","ast-traverse":"~0.1.1","breakable":"~1.0.0","esprima-fb":"~15001.1001.0-dev-harmony-fb","simple-fmt":"~0.1.0","simple-is":"~0.2.0","stringmap":"~0.2.2","stringset":"~0.2.1","tryor":"~0.1.2","yargs":"~3.27.0"},"devDependencies":{"diff":"~2.1.3"},"keywords":["defs","scope","blockscope","block-scope","let","const","var","es6","transpile","transpiler","lint","linter"],"scripts":{"test":"node --harmony run-tests"},"bin":{"defs":"./build/es5/defs"},"author":{"name":"Olov Lassus","email":"olov.lassus@gmail.com"},"license":"MIT","readme":"# SO LONG AND THANKS FOR ALL THE BITS\n**defs is done. I recommend migrating to the TypeScript `tsc` compiler because\nit does what defs does as good or better, and it does much more.**\n\n\n# defs.js\nStatic scope analysis and transpilation of ES6 block scoped `const` and `let`\nvariables, to ES3.\n\nNode already supports `const` and `let` so you can use that today\n(run `node --harmony` and `\"use strict\"`). `defs.js` enables you to do the same\nfor browser code. While developing you can rely on the experimental support\nin Chrome (chrome://flags, check Enable experimental JavaScript). `defs.js` is\nalso a pretty decent static scope analyzer/linter.\n\nThe talk\n[LET's CONST together, right now (with ES3)](http://vimeo.com/66501924)\nfrom Front-Trends 2013\n([slides](http://blog.lassus.se/files/lets_const_together_ft2013.pdf)) includes\nmore information about `let`, `const` and `defs.js`. See also the blog post\n[ES3 <3 block scoped const and let => defs.js](http://blog.lassus.se/2013/05/defsjs.html).\n\n\n## Installation and usage\n    npm install -g defs\n\nThen run it as `defs file.js`. The errors (if any) will go to stderr,\nthe transpiled source to `stdout`, so redirect it like `defs file.js > output.js`.\nMore command line options are coming.\n\nThere's also a [Grunt](http://gruntjs.com/) plugin, see [grunt-defs](https://npmjs.org/package/grunt-defs).\n\nSee [BUILD.md](BUILD.md) for a description of the self-build and the browser bundle.\n\n## License\n`MIT`, see [LICENSE](LICENSE) file.\n\n\n## Changes\nSee [CHANGES.md](CHANGES.md).\n\n\n## Configuration\n`defs` looks for a `defs-config.json` configuration file in your current\ndirectory. If not found there, it searches parent directories until it hits `/`.\nYou may instead pass a custom `defs-config.json` using `--config`, i.e.\n`defs --config path/to/defs-config.json file.js > output.js`.\n\nExample `defs-config.json`:\n\n    {\n        \"environments\": [\"node\", \"browser\"],\n\n        \"globals\": {\n            \"my\": false,\n            \"hat\": true\n        },\n        \"loopClosures\": \"iife\",\n        \"disallowVars\": false,\n        \"disallowDuplicated\": true,\n        \"disallowUnknownReferences\": true\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`loopClosures` (defaults to `false`) can be set to \"iife\" to enable transformation\nof loop-closures via immediately-invoked function expressions.\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`ast` (defaults to `false`) produces an AST instead of source code\n(experimental).\n\n`stats` (defaults to `false`) prints const/let statistics and renames\n(experimental).\n\n`parse` (defaults to `null`) lets you provide a custom parse function if you\nuse defs as an API. By default it will use `require(\"esprima\").parse`.\n\n\n## Example\n\nInput `example.js`:\n\n```javascript\n\"use strict\";\nfunction fn() {\n    const y = 0;\n    for (let x = 0; x < 10; x++) {\n        const y = x * 2;\n        const z = y;\n    }\n    console.log(y); // prints 0\n}\nfn();\n```\n\nOutput from running `defs example.js`:\n\n```javascript\n\"use strict\";\nfunction fn() {\n    var y = 0;\n    for (var x = 0; x < 10; x++) {\n        var y$0 = x * 2;\n        var z = y$0;\n    }\n    console.log(y); // prints 0\n}\nfn();\n```\n\n\n## defs.js used as a library\n`npm install defs`, then:\n\n```javascript\nconst defs = require(\"defs\");\nconst options = {};\nconst src = \"const x = 1\";\nconst res = defs(src, options);\nassert(res.src === \"var x = 1\");\n\n// you can also pass an AST (with loc and range) instead of a string to defs\nconst ast = require(\"esprima\").parse(src, {loc: true, range: true});\nconst res = defs(ast, {ast: true}); // AST-in, AST-out\n// inspect res.ast\n```\n\nres object:\n\n    {\n        src: string // on success\n        errors: array of error messages // on errors\n        stats: statistics object (toStringable)\n        ast: transformed ast // when options.ast is set\n    }\n\n\n## Compatibility\n`defs.js` strives to transpile your program as true to ES6 block scope semantics as\npossible while being as maximally non-intrusive as possible.\n\nIt can optionally transform loop closures via IIFE's (when possible), if you include\n`\"loopClosures\": \"iife\"` in your `defs-config.json`. More info in\n[loop-closures.md](loop-closures.md).\n\nSee [semantic-differences.md](semantic-differences.md) for other minor differences.\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/olov/defs/issues"},"homepage":"https://github.com/olov/defs","_id":"defs@1.1.1","_shasum":"b22609f2c7a11ba7a3db116805c139b1caffa9d2","_from":"https://registry.npmjs.org/defs/-/defs-1.1.1.tgz","_resolved":"https://registry.npmjs.org/defs/-/defs-1.1.1.tgz"}