├── test ├── fixtures │ ├── simple │ │ ├── expected.js │ │ ├── input.js │ │ ├── expected-with-unicode-flag.js │ │ └── .babelrc │ ├── unicode-10 │ │ ├── input.js │ │ ├── expected.js │ │ ├── expected-with-unicode-flag.js │ │ └── .babelrc │ ├── script-extensions │ │ ├── expected.js │ │ ├── expected-with-unicode-flag.js │ │ ├── input.js │ │ └── .babelrc │ └── emoji │ │ ├── .babelrc │ │ ├── input.js │ │ ├── expected.js │ │ └── expected-with-unicode-flag.js └── index.js ├── .babelrc ├── .gitattributes ├── .travis.yml ├── README.md ├── .editorconfig ├── .gitignore ├── src └── index.js ├── LICENSE-MIT.txt └── package.json /test/fixtures/simple/expected.js: -------------------------------------------------------------------------------- 1 | var regex = /[0-9A-Fa-f]/; 2 | -------------------------------------------------------------------------------- /test/fixtures/simple/input.js: -------------------------------------------------------------------------------- 1 | var regex = /\p{ASCII_Hex_Digit}/u; 2 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/unicode-10/input.js: -------------------------------------------------------------------------------- 1 | var regex = /\p{Regional_Indicator}/u; 2 | -------------------------------------------------------------------------------- /test/fixtures/simple/expected-with-unicode-flag.js: -------------------------------------------------------------------------------- 1 | var regex = /[0-9A-Fa-f]/u; 2 | -------------------------------------------------------------------------------- /test/fixtures/unicode-10/expected.js: -------------------------------------------------------------------------------- 1 | var regex = /(?:\uD83C[\uDDE6-\uDDFF])/; 2 | -------------------------------------------------------------------------------- /test/fixtures/script-extensions/expected.js: -------------------------------------------------------------------------------- 1 | var regex = /(?:\uD811[\uDC00-\uDE46])/; 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Automatically normalize line endings for all text-based files 2 | * text=auto 3 | -------------------------------------------------------------------------------- /test/fixtures/unicode-10/expected-with-unicode-flag.js: -------------------------------------------------------------------------------- 1 | var regex = /[\u{1F1E6}-\u{1F1FF}]/u; 2 | -------------------------------------------------------------------------------- /test/fixtures/script-extensions/expected-with-unicode-flag.js: -------------------------------------------------------------------------------- 1 | var regex = /[\u{14400}-\u{14646}]/u; 2 | -------------------------------------------------------------------------------- /test/fixtures/script-extensions/input.js: -------------------------------------------------------------------------------- 1 | var regex = /\p{Script_Extensions=Anatolian_Hieroglyphs}/u; 2 | -------------------------------------------------------------------------------- /test/fixtures/emoji/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "../../../src" 5 | ] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/simple/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "../../../src" 5 | ] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '4' 4 | - '5' 5 | - '6' 6 | - '7' 7 | git: 8 | depth: 1 9 | -------------------------------------------------------------------------------- /test/fixtures/unicode-10/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "../../../src" 5 | ] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/script-extensions/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "../../../src" 5 | ] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/emoji/input.js: -------------------------------------------------------------------------------- 1 | var regexEmojiModifier = /\p{Emoji_Modifier}/u; 2 | var regexEmojiComponent = /\p{Emoji_Component}/u; 3 | -------------------------------------------------------------------------------- /test/fixtures/emoji/expected.js: -------------------------------------------------------------------------------- 1 | var regexEmojiModifier = /(?:\uD83C[\uDFFB-\uDFFF])/; 2 | var regexEmojiComponent = /(?:[#\*0-9\u200D\u20E3\uFE0F]|\uD83C[\uDDE6-\uDDFF\uDFFB-\uDFFF]|\uDB40[\uDC20-\uDC7F])/; 3 | -------------------------------------------------------------------------------- /test/fixtures/emoji/expected-with-unicode-flag.js: -------------------------------------------------------------------------------- 1 | var regexEmojiModifier = /[\u{1F3FB}-\u{1F3FF}]/u; 2 | var regexEmojiComponent = /[#\*0-9\u200D\u20E3\uFE0F\u{1F1E6}-\u{1F1FF}\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]/u; 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # babel-plugin-transform-unicode-property-regex 2 | 3 | This plugin was [moved into the main Babel repository](https://github.com/babel/babel/blob/master/packages/babel-plugin-proposal-unicode-property-regex/README.md). 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = tab 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [{README.md,package.json,.babelrc,.travis.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | 3 | # Coverage report 4 | coverage 5 | 6 | # Installed npm modules 7 | node_modules 8 | 9 | # Folder view configuration files 10 | .DS_Store 11 | Desktop.ini 12 | 13 | # Thumbnail cache files 14 | ._* 15 | Thumbs.db 16 | 17 | # Files that might appear on external disks 18 | .Spotlight-V100 19 | .Trashes 20 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import rewritePattern from 'regexpu-core'; 2 | import * as regex from '@babel/helper-regex'; 3 | 4 | export default function() { 5 | return { 6 | 'visitor': { 7 | RegExpLiteral(path, state) { 8 | const node = path.node; 9 | if (!regex.is(node, 'u')) { 10 | return; 11 | } 12 | const useUnicodeFlag = state.opts.useUnicodeFlag || false; 13 | node.pattern = rewritePattern(node.pattern, node.flags, { 14 | 'unicodePropertyEscape': true, 15 | 'useUnicodeFlag': useUnicodeFlag 16 | }); 17 | if (!useUnicodeFlag) { 18 | regex.pullFlag(node, 'u'); 19 | } 20 | } 21 | } 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE-MIT.txt: -------------------------------------------------------------------------------- 1 | Copyright Mathias Bynens 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-transform-unicode-property-regex", 3 | "version": "2.0.5", 4 | "description": "Compile Unicode property escapes in Unicode regular expressions to ES5.", 5 | "homepage": "https://github.com/mathiasbynens/babel-plugin-transform-unicode-property-regex", 6 | "main": "dist/index.js", 7 | "engines": { 8 | "node": ">=4" 9 | }, 10 | "keywords": [ 11 | "babel-plugin", 12 | "regex", 13 | "regexp", 14 | "regular expressions", 15 | "unicode properties", 16 | "unicode" 17 | ], 18 | "license": "MIT", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/mathiasbynens/babel-plugin-transform-unicode-property-regex.git" 22 | }, 23 | "bugs": "https://github.com/mathiasbynens/babel-plugin-transform-unicode-property-regex/issues", 24 | "files": [ 25 | "dist" 26 | ], 27 | "scripts": { 28 | "build": "babel src -d dist", 29 | "clean": "rm -rf dist", 30 | "prepublish": "npm run clean && npm run build", 31 | "test": "mocha --compilers js:@babel/register", 32 | "test:watch": "npm run test -- --watch" 33 | }, 34 | "dependencies": { 35 | "@babel/helper-regex": "^7.0.0", 36 | "regexpu-core": "^4.1.3" 37 | }, 38 | "devDependencies": { 39 | "@babel/cli": "^7.0.0", 40 | "@babel/core": "^7.0.0", 41 | "@babel/preset-env": "^7.0.0", 42 | "@babel/register": "^7.0.0", 43 | "istanbul": "^0.4.5", 44 | "mocha": "^3.5.3" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import assert from 'assert'; 4 | import { transform, transformFileSync } from '@babel/core'; 5 | import plugin from '../src'; 6 | 7 | describe('babel-plugin-transform-unicode-property-regex', () => { 8 | const fixturesDir = path.join(__dirname, 'fixtures'); 9 | fs.readdirSync(fixturesDir).map((caseName) => { 10 | it(`${caseName.split('-').join(' ')}`, () => { 11 | const fixtureDir = path.join(fixturesDir, caseName); 12 | const inputPath = path.join(fixtureDir, 'input.js'); 13 | const actual = transformFileSync(inputPath, { 14 | 'plugins': [ 15 | plugin 16 | ] 17 | }).code; 18 | const expected = fs.readFileSync( 19 | path.join(fixtureDir, 'expected.js') 20 | ).toString(); 21 | assert.equal(actual.trim(), expected.trim()); 22 | // Note: the following causes the plugin to be applied twice, the second 23 | // time without options, resulting in failing tests. Seems like a bug in 24 | // babel-core. 25 | // const actualWithUnicodeFlag = transformFileSync( 26 | // inputPath, 27 | // { 28 | // 'plugins': [ 29 | // [ plugin, { 'useUnicodeFlag': true } ] 30 | // ] 31 | // } 32 | // ).code; 33 | // Workaround: 34 | const actualWithUnicodeFlag = transform( 35 | fs.readFileSync(inputPath).toString(), 36 | { 37 | 'plugins': [ 38 | [ plugin, { 'useUnicodeFlag': true } ] 39 | ] 40 | } 41 | ).code; 42 | const expectedWithUnicodeFlag = fs.readFileSync( 43 | path.join(fixtureDir, 'expected-with-unicode-flag.js') 44 | ).toString(); 45 | assert.equal(actualWithUnicodeFlag.trim(), expectedWithUnicodeFlag.trim()); 46 | }); 47 | }); 48 | }); 49 | --------------------------------------------------------------------------------