Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot extend pipeline operator #6176

Closed
willin opened this issue Aug 31, 2017 · 15 comments
Closed

cannot extend pipeline operator #6176

willin opened this issue Aug 31, 2017 · 15 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@willin
Copy link

willin commented Aug 31, 2017

Choose one: is this a bug report or feature request?

Input Code

https://unpkg.com/babel-plugin-transform-pipeline-operator@1.0.2/lib/index.js

'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

exports.
default = function(_ref) {
    var t = _ref.types;

    return {
        visitor: {
            BinaryExpression: function BinaryExpression(path) {
                var _path$node = path.node,
                    operator = _path$node.operator,
                    left = _path$node.left,
                    right = _path$node.right;

                if (operator !== '|>') return;

                path.replaceWith(t.callExpression(right, [left]));
            }
        }
    };
};

Babel Configuration (.babelrc, package.json, cli command)

{
  "plugins": ["transform-pipeline-operator"]
}

Current Behavior

65 |> console.log;
SyntaxError: /Users/willin/Desktop/transform/index.js: Unexpected token (1:4)
> 1 | 65 |> console.log
    |     ^
  2 |
    at Parser.pp$5.raise (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp$3.parseExprAtom (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3750:12)
    at Parser.pp$3.parseExprSubscripts (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3494:19)
    at Parser.pp$3.parseMaybeUnary (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3474:19)
    at Parser.pp$3.parseExprOp (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3435:42)
    at Parser.pp$3.parseExprOps (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3408:17)
    at Parser.pp$3.parseMaybeConditional (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3381:19)
    at Parser.pp$3.parseMaybeAssign (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3344:19)
    at Parser.pp$3.parseExpression (/Users/willin/Desktop/transform/node_modules/babylon/lib/index.js:3306:19)
error Command failed with exit code 1.
@babel-bot
Copy link
Collaborator

Hey @willin! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@jridgewell
Copy link
Member

We don't support custom syntaxes in babylon. You'll need to fork it and add support yourself, or wait till the pipeline operator has been officially accepted as a stage 0 proposal.

@willin
Copy link
Author

willin commented Aug 31, 2017

how to???? there is no doc

@loganfsmyth
Copy link
Member

Until the proposed pipeline syntax is accepted Stage 0 proposal, we will not implement support for it. The babel-plugin-transform-pipeline-operator plugin that you linked to is not one the Babel team maintains.

@willin
Copy link
Author

willin commented Aug 31, 2017

how to implement by myself for private study?

@jridgewell
Copy link
Member

@willin
Copy link
Author

willin commented Aug 31, 2017

.babelrc:

{
  "parserOpts": {
    "parser": "transform-pipeline-operator"
  }
}

still no use

TypeError: /Users/willin/Documents/w2fs/esnext-pipeline-biolerplate/src/index.js: parseCode is not a function

@jridgewell
Copy link
Member

You have to fork the babylon parser, implement the features in your fork, then use that fork in your .babelrc. We don't support people who do this.

@willin
Copy link
Author

willin commented Aug 31, 2017

thanks,
wx20170831-155535

it works now.

{
  "parserOpts": {
    "parser": "@airdwing/babylon"
  },
  "plugins": [
    "transform-pipeline-operator"
  ]
}

here's my eslint config

module.exports = {
  root: true,
  extends: 'dwing',
  parser: 'babel-eslint'
};
file: 'file:///Users/willin/Desktop/pipeline/code.js'
severity: '错误'
message: 'Parsing error: Unexpected token

> 1 | 63 |> console.log;
    |     ^
  2 |'
at: '1,5'
source: 'eslint'

how to fix this?

@nicolo-ribaudo
Copy link
Member

I think you also have to fork babel-eslint an replace Babylon there

@loganfsmyth
Copy link
Member

@willin Keep in mind, the point of this feature is to allow people to experiment with new features, not to officially support them. As stated, we don't officially aim to support extra syntax until it's accepted as a proposal.

@lijialiang
Copy link

babel-plugin-proposal-pipeline-operator will support await ?

const hello = function ( name ) {
    return new Promise(( resolve, reject ) => {
        setTimeout(() => {
            console.log( `hello, ${ name }` );
            resolve( name );
        }, 1000);
    });
}

const world = function ( name ) {
    console.log( `world, ${ name }` );
}

const foo = async () => {
    'foo' |> hello |> await |> world;
};

foo();

@xtuc
Copy link
Member

xtuc commented Nov 24, 2017

@lilijialiang Babel follows the spec/proposal, it isn't part of the spec atm. We can open an issue there if you want.

@lijialiang
Copy link

@xtuc I see. but I think if it can support await is a good thing, just like proposal-pipeline-operator.

@xtuc
Copy link
Member

xtuc commented Nov 24, 2017

ah sorry, I was wrong. it is actually part of the spec.

I created #6889 to keeping track of that.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

7 participants