chushihua
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
*.log
|
||||
src
|
||||
test
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
# babel-plugin-transform-es2015-literals
|
||||
|
||||
> Compile ES2015 unicode string and number literals to ES5
|
||||
|
||||
## Example
|
||||
|
||||
**In**
|
||||
|
||||
```js
|
||||
var b = 0b11; // binary integer literal
|
||||
var o = 0o7; // octal integer literal
|
||||
const u = 'Hello\u{000A}\u{0009}!'; // unicode string literals, newline and tab
|
||||
```
|
||||
|
||||
**Out**
|
||||
|
||||
```js
|
||||
var b = 3; // binary integer literal
|
||||
var o = 7; // octal integer literal
|
||||
const u = 'Hello\n\t!'; // unicode string literals, newline and tab
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install --save-dev babel-plugin-transform-es2015-literals
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Via `.babelrc` (Recommended)
|
||||
|
||||
**.babelrc**
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["transform-es2015-literals"]
|
||||
}
|
||||
```
|
||||
|
||||
### Via CLI
|
||||
|
||||
```sh
|
||||
babel --plugins transform-es2015-literals script.js
|
||||
```
|
||||
|
||||
### Via Node API
|
||||
|
||||
```javascript
|
||||
require("babel-core").transform("code", {
|
||||
plugins: ["transform-es2015-literals"]
|
||||
});
|
||||
```
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
exports.default = function () {
|
||||
return {
|
||||
visitor: {
|
||||
NumericLiteral: function NumericLiteral(_ref) {
|
||||
var node = _ref.node;
|
||||
|
||||
if (node.extra && /^0[ob]/i.test(node.extra.raw)) {
|
||||
node.extra = undefined;
|
||||
}
|
||||
},
|
||||
StringLiteral: function StringLiteral(_ref2) {
|
||||
var node = _ref2.node;
|
||||
|
||||
if (node.extra && /\\[u]/gi.test(node.extra.raw)) {
|
||||
node.extra = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = exports["default"];
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "babel-plugin-transform-es2015-literals",
|
||||
"version": "6.22.0",
|
||||
"description": "Compile ES2015 unicode string and number literals to ES5",
|
||||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-literals",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.22.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-helper-plugin-test-runner": "^6.22.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user