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

Exceptions when parsing javascript files #2083

Closed
spacegangster opened this issue Nov 13, 2018 · 3 comments
Closed

Exceptions when parsing javascript files #2083

spacegangster opened this issue Nov 13, 2018 · 3 comments
Labels
bug Marks issues describing bugs released Marks issues which have had the fixes released in a stable build
Milestone

Comments

@spacegangster
Copy link

spacegangster commented Nov 13, 2018

Hello to Cursive team!
First of all – thanks for the good work and keep it up, you're really making my life easier.

I've found a few a issues with javascript parsing though.
The following is an example, however I get five of them like the one below for different .js files.

Idea data

IntelliJ IDEA 2018.2.5 (Ultimate Edition)
Build #IU-182.4892.20, built on October 16, 2018
JRE: 1.8.0_152-release-1248-b19 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

Cursive plugin

Version: 1.8.0-eap9-2018.2

The bad file – https://gist.github.com/spacegangster/59e81791cce11cc909534273e97f656

Exception trace

java.lang.Throwable: Exception parsing /Users/spacegangster/clj/lightpad/website/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js
java.lang.IllegalArgumentException: Unmatched braces in the pattern.
 at java.text.MessageFormat.applyPattern (MessageFormat.java:508)
    java.text.MessageFormat.<init> (MessageFormat.java:362)
    org.mozilla.javascript.ScriptRuntime$DefaultMessageProvider.getMessage (ScriptRuntime.java:3920)
    org.mozilla.javascript.ScriptRuntime.getMessage (ScriptRuntime.java:3889)
    org.mozilla.javascript.ScriptRuntime.getMessage0 (ScriptRuntime.java:3837)
    org.mozilla.javascript.Parser.lookupMessage (Parser.java:230)
    org.mozilla.javascript.Parser.addError (Parser.java:177)
    org.mozilla.javascript.Parser.addError (Parser.java:166)
    org.mozilla.javascript.Parser.reportError (Parser.java:256)
    org.mozilla.javascript.Parser.reportError (Parser.java:243)
    org.mozilla.javascript.Parser.reportError (Parser.java:236)
    org.mozilla.javascript.Parser.parseFunctionBody (Parser.java:630)
    org.mozilla.javascript.Parser.function (Parser.java:828)
    org.mozilla.javascript.Parser.methodDefinition (Parser.java:3367)
    org.mozilla.javascript.Parser.objectLiteral (Parser.java:3252)
    org.mozilla.javascript.Parser.primaryExpr (Parser.java:2812)
    org.mozilla.javascript.Parser.destructuringPrimaryExpr (Parser.java:2792)
    org.mozilla.javascript.Parser.variables (Parser.java:1877)
    org.mozilla.javascript.Parser.statementHelper (Parser.java:1019)
    org.mozilla.javascript.Parser.statement (Parser.java:934)
    org.mozilla.javascript.Parser.statements (Parser.java:889)
    org.mozilla.javascript.Parser.block (Parser.java:1721)
    org.mozilla.javascript.Parser.statementHelper (Parser.java:1043)
    org.mozilla.javascript.Parser.statement (Parser.java:934)
    org.mozilla.javascript.Parser.parse (Parser.java:573)
    org.mozilla.javascript.Parser.parse (Parser.java:511)
    org.mozilla.javascript.Parser.parse (Parser.java:530)
    cursive.index.js$parse.invoke (js.clj:29)
    cursive.index.js$index$fn__4909.invoke (js.clj:188)
    cursive.index.js$index.invoke (js.clj:187)
    cursive.index.js$index_javascript.invoke (js.clj:228)
    clojure.lang.Var.invoke (Var.java:379)
    cursive.api.DelayedFn.invoke (DelayedFn.java:31)
    cursive.index.PsiDependentIndexExtension.lambda$getIndexer$0 (PsiDependentIndexExtension.java:50)
    com.intellij.util.indexing.impl.MapReduceIndex.mapInput (MapReduceIndex.java:273)
    com.intellij.util.indexing.VfsAwareMapReduceIndex.calculateUpdateData (VfsAwareMapReduceIndex.java:97)
    com.intellij.util.indexing.impl.MapReduceIndex.update (MapReduceIndex.java:213)
    com.intellij.util.indexing.FileBasedIndexImpl.updateSingleIndex (FileBasedIndexImpl.java:1668)
    com.intellij.util.indexing.FileBasedIndexImpl.lambda$doIndexFileContent$25 (FileBasedIndexImpl.java:1596)
    com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn (FileTypeManagerImpl.java:519)
    com.intellij.util.indexing.FileBasedIndexImpl.doIndexFileContent (FileBasedIndexImpl.java:1555)
    com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent (FileBasedIndexImpl.java:1543)
    com.intellij.util.indexing.UnindexedFilesUpdater.lambda$indexFiles$0 (UnindexedFilesUpdater.java:110)
    com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.lambda$run$0 (CacheUpdateRunner.java:230)
    com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction (ApplicationImpl.java:1161)
    com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.lambda$run$1 (CacheUpdateRunner.java:246)
    com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1 (CoreProgressManager.java:157)
    com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun (CoreProgressManager.java:580)
    com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress (CoreProgressManager.java:525)
    com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress (ProgressManagerImpl.java:85)
    com.intellij.openapi.progress.impl.CoreProgressManager.runProcess (CoreProgressManager.java:144)
    com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.run (CacheUpdateRunner.java:243)
    com.intellij.openapi.application.impl.ApplicationImpl$1.run (ApplicationImpl.java:314)
    java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    java.util.concurrent.FutureTask.run (FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    java.lang.Thread.run (Thread.java:745)

	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:123)
	at cursive.logging$do_error.invoke(logging.clj:61)
	at cursive.logging$do_log.doInvoke(logging.clj:46)
	at clojure.lang.RestFn.invoke(RestFn.java:490)
	at cursive.index.js$index$fn__4909.invoke(js.clj:190)
	at cursive.index.js$index.invoke(js.clj:187)
	at cursive.index.js$index_javascript.invoke(js.clj:228)
	at clojure.lang.Var.invoke(Var.java:379)
	at cursive.api.DelayedFn.invoke(DelayedFn.java:31)
	at cursive.index.PsiDependentIndexExtension.lambda$getIndexer$0(PsiDependentIndexExtension.java:50)
	at com.intellij.util.indexing.impl.MapReduceIndex.mapInput(MapReduceIndex.java:273)
	at com.intellij.util.indexing.VfsAwareMapReduceIndex.calculateUpdateData(VfsAwareMapReduceIndex.java:97)
	at com.intellij.util.indexing.impl.MapReduceIndex.update(MapReduceIndex.java:213)
	at com.intellij.util.indexing.FileBasedIndexImpl.updateSingleIndex(FileBasedIndexImpl.java:1668)
	at com.intellij.util.indexing.FileBasedIndexImpl.lambda$doIndexFileContent$25(FileBasedIndexImpl.java:1596)
	at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:519)
	at com.intellij.util.indexing.FileBasedIndexImpl.doIndexFileContent(FileBasedIndexImpl.java:1555)
	at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1543)
	at com.intellij.util.indexing.UnindexedFilesUpdater.lambda$indexFiles$0(UnindexedFilesUpdater.java:110)
	at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.lambda$run$0(CacheUpdateRunner.java:230)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1161)
	at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.lambda$run$1(CacheUpdateRunner.java:246)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
	at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.run(CacheUpdateRunner.java:243)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Regards,

Ivan

@spacegangster
Copy link
Author

Anything I can help with? More details or precision?

@cursive-ide cursive-ide added this to the 1.8.1 milestone Dec 4, 2018
@cursive-ide
Copy link
Owner

This actually looks to be a problem in Rhino. I can't figure it out exactly though. Do you have your locale set to French, by any chance?

The issue is that Rhino is trying to print a parsing error when it encounters an anonymous function without braces around the body, like path => path.isObjectProperty(). This is because I haven't set the language level correctly on the parser. It gets the errors from a message bundle using the current locale and then calls new MessageFormat(formatString) on them. There are only two resource bundles in Rhino, one is English (and the default): missing '{' before function body, and the other is in French: il manque ''{'' avant le corps d''une fonction. The French message does indeed throw that error when calling new MessageFormat(formatString) - I guess the double quotes are invalid, but I'm very surprised that no-one has ever had a Javascript parsing error in France :-)

I've fixed the language level issue and now parse JS as ES6 - hopefully that won't give spurious errors on older JS.

@spacegangster
Copy link
Author

Yep, my locale is French indeed, hahaha))

@cursive-ide cursive-ide modified the milestones: 1.8.1, 1.8.1-eap1 Jan 10, 2019
@cursive-ide cursive-ide added the bug Marks issues describing bugs label Sep 22, 2020
@cursive-ide cursive-ide added the released Marks issues which have had the fixes released in a stable build label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Marks issues describing bugs released Marks issues which have had the fixes released in a stable build
Projects
None yet
Development

No branches or pull requests

2 participants