babel / babylon

PSA: moved into babel/babel as @babel/parser -->

Home Page:https://github.com/babel/babel/tree/master/packages/babel-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyntaxError: Unexpected token at Parser.pp$5.raise

willin opened this issue · comments

Input Code

ref project: https://github.com/willin/esnext-pipeline-biolerplate

function doubleSay(str) {
  return `${str}, ${str}`;
}
function capitalize(str) {
  return str[0].toUpperCase() + str.substring(1);
}
function exclaim(str) {
  return `${str}!`;
}

let result = "hello" |> doubleSay |> capitalize |> exclaim;

result |> console.log;
//=> "Hello, hello!"

Babylon/Babel Configuration

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

https://github.com/SuperPaintman/babel-plugin-syntax-pipeline/blob/master/src/index.js

Expected Behavior

transform pipeline operators

Current Behavior

ref: SuperPaintman/babel-plugin-transform-pipeline#1

/Users/willin/.config/yarn/global/node_modules/babel-core/lib/transformation/file/index.js:590
      throw err;
      ^

SyntaxError: /Users/willin/Desktop/b2/index.js: Unexpected token (11:22)
   9 | }
  10 |
> 11 | let result = "hello" |> doubleSay |> capitalize |> exclaim;
     |                       ^
  12 |
  13 | result |> console.log;
  14 | //=> "Hello, hello!"
    at Parser.pp$5.raise (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:4452:13)
    at Parser.pp.unexpected (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp$3.parseExprAtom (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3748:12)
    at Parser.pp$3.parseExprSubscripts (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3492:19)
    at Parser.pp$3.parseMaybeUnary (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3472:19)
    at Parser.pp$3.parseExprOp (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3433:42)
    at Parser.pp$3.parseExprOps (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3406:17)
    at Parser.pp$3.parseMaybeConditional (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3379:19)
    at Parser.pp$3.parseMaybeAssign (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:3342:19)
    at Parser.pp$1.parseVar (/Users/willin/.config/yarn/global/node_modules/babylon/lib/index.js:2340:24)

Your Environment

software version
Babylon 6.18.0
node 8.4.0
npm 5.3.0
Operating System os x 10.12.6
commented

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.

commented

This is expected since it's not in babylon itself: https://github.com/babel/babylon#faq

If pipeline is at least a Stage 0 proposal we would accept a PR to babylon

Babylon only supports standard JavaScript, official proposals, and some popular JavaScript extensions (JSX, Flow and TypeScript).
The pipeline operator isn't in an official proposal yet (it is not listed at https://github.com/tc39/proposals), so Babylon doesn't handle it.

Anyway, probably it will be discussed at the next TC39 meeting, so it could become official soon!
I'm closing this issue for now, I'll reopen it if the proposals gets accepted.

commented

Yeah it hasn't been proposed at the last meeting and will be at the next one (I'l be there), so we would accept a PR https://github.com/babel/proposals

Babel/Babylon only supports stage 0+ proposal.
The fact that that proposal lives in the TC39 org doesn't mean it is a stage 0 proposal*. You can find the full list here: https://github.com/tc39/proposals/blob/master/stage-0-proposals.md

* I may be wrong, but that is the repo where officials proposals are listed and the pipeline operator isn't there*

Didn't see @hzoo's response 😅

commented

All good, you weren't at the meeting or know about it. It was supposed to be presented here but no time https://github.com/tc39/agendas/blob/master/2017/07.md

minor version update should be compatible, this plugin written in 6.13.0

extends babylon like https://github.com/SuperPaintman/babel-plugin-syntax-pipeline/blob/master/src/index.js

cannot work for 6.13.0+ versions? how to make it work, is there any docs to ref? @hzoo