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

Unexpected token (2:9) #11

Open
ghost opened this issue May 7, 2019 · 2 comments
Open

Unexpected token (2:9) #11

ghost opened this issue May 7, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented May 7, 2019

Hello,

I used to use contracts in Racket of all languages, so glad to see something similar exists for JS!

Anyway, every time I try to compile anything with the contracts plugin, I get Unexpected token (2:9). It doesn't matter what is at position 2:9, even comments will trigger the same error.

.babelrc

{
  "plugins": [
    ["contracts", {
      "names": {
        "assert": "assert",
        "precondition": "pre",
        "postcondition": "post",
        "invariant": "invariant",
        "return": "it",
        "old": "old"
      }
    }]
  ]
}

test.js

const add1 = n => {
	pre: typeof n === 'number';
	return n + 1
}

babel --version

6.26.0 (babel-core 6.26.3)

Do I need babel 7 for this? 6.26.3 is the latest version in npm.

https://www.npmjs.com/package/babel-core

@phpnode
Copy link
Member

phpnode commented May 13, 2019

@LewisAndrewCampbell yes please test with babel 7, if it doesn't work let me know.

@ghost
Copy link
Author

ghost commented May 19, 2019

Hi,

No luck with 7 either. Can I get a minimal working example?

$ cat test.js 
const add1 = n => {
	
	pre: typeof n === 'number';
	return n + 1
}
$ cat .babelrc 
{
  "plugins": [
    ["@babel/plugin-transform-react-jsx", { "pragma":"h" }],
    ["contracts", {
      "env": {
        "production": {
          "strip": true
        }
      },
      "names": {
        "assert": "assert",
        "precondition": "pre",
        "postcondition": "post",
        "invariant": "invariant",
        "return": "it",
        "old": "old"
      }
    }]
  ]
}
$ babel --version
7.4.4 (@babel/core 7.2.2)
$ babel test.js
{ SyntaxError: Unexpected token (3:9)
  1 | /* @babel/template */;
  2 | 
> 3 |     if (!%%condition%%) {
    |         ^
  4 |       throw new Error(%%message%%);
  5 |     }
  6 |   
    at Parser.raise (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:4051:15)
    at Parser.unexpected (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5382:16)
    at Parser.parseExprAtom (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:6541:20)
    at Parser.parseExprSubscripts (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:6104:21)
    at Parser.parseMaybeUnary (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:6083:21)
    at Parser.parseMaybeUnary (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:6060:30)
    at Parser.parseExprOps (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5968:21)
    at Parser.parseMaybeConditional (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5940:21)
    at Parser.parseMaybeAssign (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5887:21)
    at Parser.parseExpression (/home/lewis/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5840:21)
    =============
    at _default (/home/lewis/code/lingo-engine/node_modules/babel-plugin-contracts/lib/index.js:36:15)
    at loadDescriptor (/home/lewis/.config/yarn/global/node_modules/@babel/core/lib/config/full.js:165:14)
    at cachedFunction (/home/lewis/.config/yarn/global/node_modules/@babel/core/lib/config/caching.js:33:19)
    at loadPluginDescriptor (/home/lewis/.config/yarn/global/node_modules/@babel/core/lib/config/full.js:200:28)
    at config.plugins.reduce (/home/lewis/.config/yarn/global/node_modules/@babel/core/lib/config/full.js:69:20)
    at Array.reduce (<anonymous>)
    at recurseDescriptors (/home/lewis/.config/yarn/global/node_modules/@babel/core/lib/config/full.js:67:38)
    at loadFullConfig (/home/lewis/.config/yarn/global/node_modules/@babel/core/lib/config/full.js:108:6)
  pos: 33,
  loc: Position { line: 3, column: 9 },
  code: 'BABEL_TEMPLATE_PARSE_ERROR' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant