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

@Property decorators throw "Parsing error: Unexpected token" #380

Closed
evanplaice opened this issue Jan 11, 2016 · 13 comments

Comments

@evanplaice
Copy link

commented Jan 11, 2016

I'm using Angular2+ES6 which requires both @Class and @Property decorators.

With the parser set to 'babel-eslint' the class decorators aren't throwing any style errors. Property decorators (ex @input, @Inject) are.

FYI. I'm using Traceur with annotations enabled, so this could just be a shortcoming of the Babel parser.

@bcomnes

This comment has been minimized.

Copy link
Member

commented Jan 11, 2016

Can you please provide a code example thats causing the issue?

@bcomnes

This comment has been minimized.

Copy link
Member

commented Jan 11, 2016

You mentioned angular 2, are you trying to run typescript through standard?

@evanplaice

This comment has been minimized.

Copy link
Author

commented Jan 11, 2016

Of course, here you go.

I'm running Traceur (ie ES6 not Typescript) with the following config:

  traceurOptions: {
    "annotations": true,
    "types": true,
    "memberVariables": true
  },

Here's a sample:

@Component({
  selector: 'designs',
  providers: [ DesignService ],
  injectables: [ DesignService ]
})
@View({
  templateUrl: 'app/components/designs/designs.html',
  directives: [ DesignComponent ]
})
export class DesignsComponent {
  constructor (@Inject(DesignService) designService) {
    // console.log('designs');

    // fetch the design data
    this.designs = designService.getDesigns();
  }
}

In this case the @Inject is the cause of the error. @Component and @View don't throw errors.

@JeremyBYU

This comment has been minimized.

Copy link

commented Jan 13, 2016

Same issue using es6 Decorators with the atom standardjs library.

To be more specific I am using react-mixin package

Maybe this issue from eslint issues

@rstacruz

This comment has been minimized.

Copy link
Member

commented Jan 15, 2016

@rstacruz rstacruz closed this Jan 15, 2016

@evanplaice

This comment has been minimized.

Copy link
Author

commented Jan 15, 2016

@rstacruz I already had babel-eslint enabled. This is a separate issue.

It looks like types and member variables may be a Typescript specific (read non-standard) thing. The same is probably true for react-mixins.

The ES7 spec includes property decorators, but in a different format.

@rstacruz rstacruz reopened this Jan 15, 2016

@feross feross closed this Feb 4, 2016

@dhax

This comment has been minimized.

Copy link

commented Feb 12, 2016

I'm having the same problem right now using aurelia framework and after searching issues here and for babel-eslint I can't figure out where the actual problem lies in. Linting breaks with Parsing error: Unexpected token Illegal for the '@'

import {Router} from 'aurelia-router';

@inject(Router)
export class App {
  constructor(router) {
    this.router = router;
  }
}

I have babel-eslint set as standard parser in package.json. Do I need to add additional settings maybe?

@AndreiBelokopytov

This comment has been minimized.

Copy link

commented Nov 28, 2016

Same problem for me: "Parsing error: Unexpected character '@'". I am using React and React DnD with ES7 decorators style.

@DragSource(DnDTypes.CARD, cardSource, collectSource)
@DropTarget(DnDTypes.CARD, cardTarget, collectTarget)
export default class TaskItemDnD extends React.Component {
  componentDidMount () {
    // Use empty image as a drag preview so browsers don't draw it
    // and we can draw whatever we want on the custom drag layer instead.
    this.props.connectDragPreview(getEmptyImage(), {
      // IE fallback: specify that we'd rather screenshot the node
      // when it already knows it's being dragged so we can hide it with CSS.
      captureDraggingState: true
    })
  }
  render () {
    const {connectDragSource, connectDropTarget, isDragging, task} = this.props
    return connectDropTarget(
      connectDragSource(
        <div>
          <TaskItem task={task} />
        </div>
      )
    )
  }
}
@bcomnes

This comment has been minimized.

@AndreiBelokopytov

This comment has been minimized.

Copy link

commented Nov 28, 2016

@bcomnes thanks, your solution works for me.

@schtauffen

This comment has been minimized.

Copy link

commented May 26, 2017

@bcomnes @AndreiBelokopytov that section seems to have been removed.
Do you recall the fix? I've tried just about everything

@schtauffen

This comment has been minimized.

Copy link

commented May 26, 2017

I was able to find it using the way back machine.

Can I use a custom JS parser for bleeding-edge ES next support?

Before you use a custom parser, consider whether the added complexity in your build process is worth it.

standard supports custom JS parsers. To use a custom parser, install it from npm (example: npm install >babel-eslint) and add this to your package.json:

{
"standard":{
"parser":"babel-eslint"
}
}
If you're using standard globally (you installed it with -g), then you also need to install babel-eslint >globally with npm install babel-eslint -g.

@Rachomir

This comment has been minimized.

Copy link

commented Jan 24, 2018

does anyone found a solution? I am also receiving

error 'somethingWithDecoratort' is defined but never used no-unused-vars

@lock lock bot locked as resolved and limited conversation to collaborators May 25, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
9 participants
You can’t perform that action at this time.