Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperPaintman committed Mar 19, 2017
0 parents commit 3d8bcb1
Show file tree
Hide file tree
Showing 12 changed files with 2,529 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"es2015",
"stage-0"
]
}
31 changes: 31 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
root = true

[*]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true

[*.js]
indent_style = space
indent_size = 2

[*.json]
indent_style = space
indent_size = 2
insert_final_newline = false

[.babelrc]
indent_style = space
indent_size = 2
insert_final_newline = false

[*.yml]
indent_style = space
indent_size = 2
insert_final_newline = false

[*.md]
indent_style = space
indent_size = 2
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Git
.git/

# NPM
node_modules/

# Lib
lib/

# Coverage
coverage/
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
language: node_js
node_js: "6"

cache:
yarn: true

env:
global:
- "NODE_ENV=test"
- "YARN_VERSION=0.18.1"

before_install:
# Instal deps
- "npm install -g yarn@${YARN_VERSION}"
- "yarn global add coveralls --no-progress"
- "(NODE_ENV=development && yarn install --ignore-scripts --no-progress)"
- "yarn list"

script:
# Lint
- "npm run lint"
# Build
- "npm run build"
# Test
- "npm run test-ci"

after_script:
# coveralls
- "cat ./coverage/lcov.info | coveralls"

branches:
except:
- gh-pages
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Alexander Krivoshhekov <SuperPaintmanDeveloper@gmail.com>

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.
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# babel-plugin-syntax-pipeline

[![Build][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]


> Allow parsing of pipeline operator `|>`

**Proposal**: [mindeavor/es-pipeline-operator][proposal-url]


--------------------------------------------------------------------------------


## Installation

```sh
npm install --save-dev babel-plugin-syntax-pipeline

# or

yarn add --dev babel-plugin-syntax-pipeline
```


--------------------------------------------------------------------------------


## Usage
### Via `.babelrc` (Recommended)

**.babelrc**

```json
{
"plugins": ["syntax-pipeline"]
}
```


### Via CLI

```sh
babel --plugins syntax-pipeline script.js
```

### Via Node API

```javascript
require("babel-core").transform("code", {
plugins: ["syntax-pipeline"]
});
```


--------------------------------------------------------------------------------

## Build

```sh
npm run build
```


--------------------------------------------------------------------------------

## Test

```sh
npm run test
```


--------------------------------------------------------------------------------


## Contributing

1. Fork it (<https://github.com/SuperPaintman/babel-plugin-syntax-pipeline/fork>)
2. Create your feature branch (`git checkout -b feature/<feature_name>`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin feature/<feature_name>`)
5. Create a new Pull Request



--------------------------------------------------------------------------------


## Contributors

- [SuperPaintman](https://github.com/SuperPaintman) SuperPaintman - creator, maintainer


--------------------------------------------------------------------------------


## License

[MIT][license-url]


[license-url]: LICENSE
[travis-image]: https://img.shields.io/travis/SuperPaintman/babel-plugin-syntax-pipeline/master.svg?label=linux
[travis-url]: https://travis-ci.org/SuperPaintman/babel-plugin-syntax-pipeline
[coveralls-image]: https://img.shields.io/coveralls/SuperPaintman/babel-plugin-syntax-pipeline/master.svg
[coveralls-url]: https://coveralls.io/r/SuperPaintman/babel-plugin-syntax-pipeline?branch=master
[proposal-url]: https://github.com/mindeavor/es-pipeline-operator
3 changes: 3 additions & 0 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--reporter spec
--timeout 10000
--slow 2000
52 changes: 52 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "babel-plugin-syntax-pipeline",
"version": "0.1.0",
"description": "Allow parsing of pipeline operator",
"main": "lib/index.js",
"scripts": {
"build": "babel src -d lib -s",
"build:watch": "babel src -d lib -s -w",
"lint": "echo 'TODO add linter'",
"test": "mocha --opts ./mocha.opts ./lib/**/test.js",
"test:watch": "mocha --opts ./mocha.opts --watch ./lib/**/test.js",
"test-ci": "istanbul cover ./node_modules/mocha/bin/_mocha -- --opts ./mocha.opts ./lib/**/test.js",
"prepublish": "npm run lint && npm run build && npm run test",
"prepush": "npm run prepublish",
"precommit": "npm run lint"
},
"author": {
"name": "SuperPaintman",
"email": "SuperPaintmanDeveloper@gmail.com",
"url": "https://superpaintman.com/"
},
"license": "MIT",
"keywords": [
"babel",
"babel-plugin",
"pipeline",
"pipeline-operator"
],
"files": [
"LICENSE",
"README.md",
"lib/"
],
"dependencies": {
"babylon": "6.13.0"
},
"devDependencies": {
"babel-cli": "6.24.0",
"babel-core": "6.24.0",
"babel-preset-es2015": "6.24.0",
"babel-preset-stage-0": "6.22.0",
"chai": "3.5.0",
"husky": "0.13.2",
"istanbul": "0.4.5",
"mocha": "3.2.0",
"source-map-support": "0.4.14"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SuperPaintman/babel-plugin-syntax-pipeline.git"
}
}
49 changes: 49 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';
/** Imports */
import Parser, { plugins } from 'babylon/lib/parser';
import { TokenType, types as tt } from 'babylon/lib/tokenizer/types';

/** Constants */
const CHAR_CODES = '|>'.split('').map((c) => c.charCodeAt(0));
const PLUGIN_NAME = 'pipeline';

const beforeExpr = true;


/** Types */
tt.pipeline = new TokenType('|>', { beforeExpr, binop: 12 });


/** Parser */
const pp = Parser.prototype;

pp.readToken_pipeline = function readToken_pipeline(code) {
return this.finishOp(tt.pipeline, 2);
};



/** Plugin */
function plugin(instance) {
instance.extend('readToken', (inner) => function readToken(code) {
const next = this.input.charCodeAt(this.state.pos + 1);

if (!(code === CHAR_CODES[0] && next === CHAR_CODES[1])) {
return inner.call(this, code);
}

return this.readToken_pipeline(code);
});
}


/** Export */
plugins[PLUGIN_NAME] = plugin;

export default function () {
return {
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push(PLUGIN_NAME);
}
};
};
5 changes: 5 additions & 0 deletions src/test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
/** Imports */
import 'source-map-support/register';

process.env.NODE_ENV = 'test';

0 comments on commit 3d8bcb1

Please sign in to comment.