package/package.json000644 000765 000024 0000001361 12726351320013017 0ustar00000000 000000 { "name": "rollup-plugin-ascii", "version": "0.0.3", "description": "Rewrite JavaScript to escape any non-ASCII characters in string literals.", "keywords": [ "rollup-plugin", "ascii" ], "homepage": "https://github.com/mbostock/rollup-plugin-ascii", "license": "BSD-3-Clause", "author": { "name": "Mike Bostock", "url": "https://bost.ocks.org/mike" }, "repository": { "type": "git", "url": "https://github.com/mbostock/rollup-plugin-ascii.git" }, "main": "index.js", "scripts": { "postpublish": "git push && git push --tags" }, "dependencies": { "acorn": "^3.2.0", "estree-walker": "^0.2.1", "jsesc": "^2.2.0", "magic-string": "^0.15.1", "rollup-pluginutils": "^1.5.0" } } package/.npmignore000644 000765 000024 0000000045 12726341007012527 0ustar00000000 000000 .DS_Store node_modules npm-debug.log package/README.md000644 000765 000024 0000000564 12726341027012017 0ustar00000000 000000 # rollup-plugin-ascii Rewrite JavaScript to escape any non-ASCII characters in string literals. For example, the following input: ```js console.log("Ich ♥ Bücher"); ``` Becomes the following output: ```js console.log("Ich \u2665 B\xFCcher"); ``` Only string literals are escaped! If you want to escape Unicode symbols, too, you’ll need something like UglifyJS2. package/LICENSE000644 000765 000024 0000002676 12726341002011544 0ustar00000000 000000 Copyright 2016 Mike Bostock All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package/index.js000644 000765 000024 0000002664 12726351174012214 0ustar00000000 000000 var acorn = require("acorn"), jsesc = require("jsesc"), walk = require("estree-walker").walk, MagicString = require("magic-string"), createFilter = require("rollup-pluginutils").createFilter, extname = require("path").extname; module.exports = function(options) { if (options == null) options = {}; var filter = createFilter(options.include, options.exclude), map = options.sourceMap !== false; return { transform: function(code, id) { if (!filter(id) || extname(id) !== ".js") return; var ast, magic = new MagicString(code), modified; try { ast = acorn.parse(code, {ecmaVersion: 6, sourceType: "module"}); } catch (error) { error.message += " in " + id; throw error; } walk(ast, { enter: function(node, parent) { if (map) { magic.addSourcemapLocation(node.start); magic.addSourcemapLocation(node.end); } if (node.type === "Literal" && typeof node.value === "string") { var raw0 = node.raw, raw1 = jsesc(node.value, {wrap: true, quotes: raw0[0] === "'" ? "single" : "double"}); if (raw0 !== raw1) { modified = true; magic.overwrite(node.start, node.end, raw1); } } } }); return modified && { code: magic.toString(), map: map && magic.generateMap() }; } }; };