16

I have a JS file where no matter what is put on the first line (comment or code), PHPStorm lists a syntax error. When I hover over the error, the description says "Statement Expected". What it looks like:

enter image description here

Is this a bug with the IDE or something that can be disabled?

EDIT

Sample file here

4
  • 1
    Please upload that file somewhere (yes, actual file, not just contents on its own) and share the link. But before that: 1) create another file anywhere in your project and copy-paste from this one -- see if error will remain there as well. if not -- compare file lengths. 2) Try "File | Invalidate Caches.." -- maybe some internal index corruption (sometimes happens for PHP files) Commented Feb 28, 2014 at 17:22
  • @LazyOne I created another file and the same error highlight appears. Tried the 'File' -> 'Invalidate Caches' route and still the same problem. I added a link to the sample file in the question Commented Mar 3, 2014 at 15:05
  • 1
    Seeing the same error on phpstorm 7.1.3. But the error goes away if you remove the leading space in front of var myApp. At second glance.. I don't think that's a space.. some other leading white-space character causing issues. Commented Mar 3, 2014 at 15:11
  • I think that character is ascii 239, not a space. Commented Mar 3, 2014 at 15:17

3 Answers 3

20

You have UTF-8 BOM signature (EF BB BF) just before var myApp= line (first code line in that file)

enter image description here

If you remove it IDE will stop complaining.

P.S.
Yes -- IDE should be smarter in such case and should provide better error message and error location. Feel free to submit new ticket to the Issue Tracker at http://youtrack.jetbrains.com/issues/WI

Sign up to request clarification or add additional context in comments.

3 Comments

This was good. I simply re-typed my function declaration, pasted the guts, and the issue went away. I agree JetBrains should be better at catching this one. I'll cross-post it over to their tracker.
@Imperative Please try "Zero Width Characters locator" plugin -- it has separate inspection and can detect such case (work OK with a file from your example).
Good to know. I linked this out of the issue but I'll mention this to them anyway. That makes it even easier to implement a fix.
4

In most of the cases this issue occurs due to copy paste. There may be some characters/line feed which may need to rewrite in your IDE.

In such cases simply copy your code to notepad and again copy it back to your IDE.

Comments

2

You can turn off "Properties > Languages & Frameworks > Template Data Languages" and error "statement expected" will go out. enter image description here

1 Comment

Because this syntax is not correct for setted template. In my example, in the project i use php and angularjs, but phpstorm does not make defferences between them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.