pax_global_header00006660000000000000000000000064131265273550014523gustar00rootroot0000000000000052 comment=b0a742019d28c422492a086d1f6fdc2bd44a68e7 babel-plugin-precompile-charcodes-1.1.0/000077500000000000000000000000001312652735500201515ustar00rootroot00000000000000babel-plugin-precompile-charcodes-1.1.0/.all-contributorsrc000066400000000000000000000007121312652735500240020ustar00rootroot00000000000000{ "projectName": "babel-plugin-precompile-charcodes", "projectOwner": "ben-eb", "files": [ "README.md" ], "imageSize": 100, "commit": false, "contributors": [ { "login": "ben-eb", "name": "Ben Briggs", "avatar_url": "https://avatars.githubusercontent.com/u/1282980?v=3", "profile": "http://beneb.info", "contributions": [ "code", "doc", "review", "test" ] } ] } babel-plugin-precompile-charcodes-1.1.0/.babelrc000066400000000000000000000002321312652735500215410ustar00rootroot00000000000000{ "presets": ["es2015-loose", "stage-0"], "plugins": ["add-module-exports"], "env": { "development": { "sourceMaps": "inline" } } } babel-plugin-precompile-charcodes-1.1.0/.editorconfig000066400000000000000000000003261312652735500226270ustar00rootroot00000000000000root = true [*] indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false [*.json] indent_size = 2 babel-plugin-precompile-charcodes-1.1.0/.gitignore000066400000000000000000000000651312652735500221420ustar00rootroot00000000000000.nyc_output coverage node_modules npm-debug.log dist babel-plugin-precompile-charcodes-1.1.0/.travis.yml000066400000000000000000000004661312652735500222700ustar00rootroot00000000000000sudo: false language: node_js matrix: include: - node_js: '5' - node_js: '4' - node_js: '0.12' env: NO_ESLINT=true script: "[[ $NO_ESLINT == true ]] && npm run test-012 || npm test" after_success: - './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls' babel-plugin-precompile-charcodes-1.1.0/CHANGELOG.md000066400000000000000000000002111312652735500217540ustar00rootroot00000000000000# 1.1.0 * Added support for compiling template literals, as long as they do not contain any expressions. # 1.0.0 * Initial release. babel-plugin-precompile-charcodes-1.1.0/LICENSE-MIT000066400000000000000000000021041312652735500216020ustar00rootroot00000000000000Copyright (c) Ben Briggs (http://beneb.info) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. babel-plugin-precompile-charcodes-1.1.0/README.md000066400000000000000000000035711312652735500214360ustar00rootroot00000000000000# babel-plugin-precompile-charcodes [![Build Status](https://travis-ci.org/ben-eb/babel-plugin-precompile-charcodes.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/babel-plugin-precompile-charcodes.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/babel-plugin-precompile-charcodes.svg)][deps] > Convert character code getters into plain integers. ## Install With [npm](https://npmjs.org/package/babel-plugin-precompile-charcodes) do: ``` npm install babel-plugin-precompile-charcodes --save-dev ``` ## Example Convert `str.charCodeAt(0)` to a plain integer, useful for parsers/tokenizers. ### Input ```js const at = '@'.charCodeAt(0); ``` ### Output ```js const at = 64; ``` ## Usage In your Babel configuration: ```json { "plugins": ["precompile-charcodes"] } ``` ## Contributors Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | [
Ben Briggs](http://beneb.info)
[💻](https://github.com/ben-eb/babel-plugin-precompile-charcodes/commits?author=ben-eb) [📖](https://github.com/ben-eb/babel-plugin-precompile-charcodes/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/babel-plugin-precompile-charcodes/commits?author=ben-eb) | | :---: | This project follows the [all-contributors] specification. Contributions of any kind welcome! ## License MIT © [Ben Briggs](http://beneb.info) [all-contributors]: https://github.com/kentcdodds/all-contributors [ci]: https://travis-ci.org/ben-eb/babel-plugin-precompile-charcodes [deps]: https://gemnasium.com/ben-eb/babel-plugin-precompile-charcodes [npm]: http://badge.fury.io/js/babel-plugin-precompile-charcodes babel-plugin-precompile-charcodes-1.1.0/package.json000066400000000000000000000031241312652735500224370ustar00rootroot00000000000000{ "name": "babel-plugin-precompile-charcodes", "version": "1.1.0", "description": "Convert character code getters into plain integers", "main": "dist/index.js", "license": "MIT", "scripts": { "contributorAdd": "all-contributors add", "contributorGenerate": "all-contributors generate", "pretest": "eslint src", "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", "report": "nyc report --reporter=html", "test": "nyc ava src/__tests__", "test-012": "nyc ava src/__tests__" }, "files": [ "LICENSE-MIT", "dist" ], "keywords": [ "babel", "babel-plugin", "charcode", "precompile", "optimization" ], "homepage": "https://github.com/ben-eb/babel-plugin-precompile-charcodes", "repository": "ben-eb/babel-plugin-precompile-charcodes", "author": { "name": "Ben Briggs", "email": "beneb.info@gmail.com", "url": "http://beneb.info" }, "devDependencies": { "all-contributors-cli": "^3.0.5", "ava": "^0.17.0", "babel-cli": "^6.5.1", "babel-core": "^6.5.2", "babel-plugin-add-module-exports": "^0.2.0", "babel-preset-es2015": "^6.5.0", "babel-preset-es2015-loose": "^7.0.0", "babel-preset-stage-0": "^6.5.0", "babel-register": "^6.5.2", "coveralls": "^2.11.6", "del-cli": "^0.2.0", "eslint": "^3.0.0", "eslint-config-cssnano": "^3.0.0", "eslint-plugin-babel": "^3.3.0", "eslint-plugin-import": "^2.0.1", "nyc": "^10.0.0" }, "ava": { "require": "babel-register" }, "eslintConfig": { "extends": "cssnano" } } babel-plugin-precompile-charcodes-1.1.0/src/000077500000000000000000000000001312652735500207405ustar00rootroot00000000000000babel-plugin-precompile-charcodes-1.1.0/src/__tests__/000077500000000000000000000000001312652735500226765ustar00rootroot00000000000000babel-plugin-precompile-charcodes-1.1.0/src/__tests__/index.js000066400000000000000000000022761312652735500243520ustar00rootroot00000000000000import test from 'ava'; import {transform} from 'babel-core'; import plugin from '..'; function isEqual (t, fixture, expected) { t.deepEqual(transform(fixture, {plugins: [plugin]}).code, expected); } function passthrough (t, fixture) { return isEqual(t, fixture, fixture); } test( 'object property', isEqual, 'const code = {at: "@".charCodeAt(0)};', 'const code = { at: 64 };' ); test( 'variable declaration', isEqual, 'const at = "@".charCodeAt(0);', 'const at = 64;' ); test( 'template literal', isEqual, 'const at = `@`.charCodeAt(0);', 'const at = 64;' ); test( 'multiple variable declarations', isEqual, [ 'var minus = "-".charCodeAt(0);', 'var plus = "+".charCodeAt(0);', 'var dot = ".".charCodeAt(0);', ].join('\n'), 'var minus = 45;\nvar plus = 43;\nvar dot = 46;' ); test( 'pass through template literals containing vars', passthrough, 'const at = `${someVar}`.charCodeAt(0);' ); test( 'pass through other identifiers', passthrough, 'const add = plus.charCodeAt(0);' ); test( 'pass through other member expressions', passthrough, 'const at = "@".slice(0);' ); babel-plugin-precompile-charcodes-1.1.0/src/index.js000066400000000000000000000015151312652735500224070ustar00rootroot00000000000000function isCharCode (path) { return ( path.node.property.name === 'charCodeAt' && path.parent.arguments[0].value === 0 ); } function replaceNode (t, path) { if (!isCharCode(path)) { return; } const {object} = path.node; if (object.type === 'StringLiteral') { return path.parentPath.replaceWith( t.numericLiteral(path.node.object.value.charCodeAt(0)) ); } if (object.type === 'TemplateLiteral' && !object.expressions.length) { return path.parentPath.replaceWith( t.numericLiteral(path.node.object.quasis[0].value.raw.charCodeAt(0)) ); } } export default function ({types: t}) { return { visitor: { MemberExpression (path) { return replaceNode(t, path); }, }, }; }