Parsing .aspx and .ascx files to use in a VSCode Prettier Plugin - javascript

I've searched with no luck to find a parser for .aspx and .ascx files that could be used to create a VSCode formatting plugin using the Prettier extension.
I've resorted to creating my own parser from scratch, which I have mostly done successfully but I have reached a point where the edge cases are causing the complexity to be difficult to manage.
I am using the Parser Generator called Jison https://github.com/zaach/jison
I am wondering if I am overcomplicating this issue and if it is possible to combine two parsers to return the Abstract Syntax Tree necessary to format the Grammar using Prettier. Does anyone know of a good way to achieve this? I am new to the concept of parsing so this may be simpler than I am making it out to be.
I need to be able to support all valid HTML with embedded C# (deliminated by tags such as <%, <%=, <%#, <%#). As well as Javascript that also has embedded C#, and Jquery.
Any help or idea is greatly appreciated.
I can include my code if needed for reference but I am looking more for ideas than specific code help.

Related

How to find all jquery methods used in a javascript file using regular expressions?

This may be dumb idea but here is what I am trying to achieve. A project I am working on has a legacy front-end code. Site is super slow and one of the contributing factor is jQuery. My idea is to write a utility that will tell me all the jQuery functions that were used on the final build. So that I can build jQuery from the source and remove what is unnecessary.
I've tried closure compiler by google with no luck. Even tree-shaking resulted in broken code.
I don't know if this dumb but this is what I could think right off the bat. All criticism, solutions are welcome.
Can you just search file by file for any instance of "$(" ? This indicates something is jQuery.

How to make "go to definition" work for my javascript webpage in vscode?

Whatever I do I'm unable to go to definition between functions defined in different *.js and index.html files.
I'm not even sure if is it supposed to work? Or is this feature working only if I do some node.js developemnt using some imports? (I'm new to javascript, I just wan't to make webpage with WebGL, not some server-side stuff)
I tried to read this but I don't see how is it relevant for me? I just made empty jsconfig.json which did not helped
https://code.visualstudio.com/Docs/languages/javascript#_javascript-project-jsconfigjson
https://code.visualstudio.com/docs/introvideos/quicktour
https://code.visualstudio.com/docs/languages/jsconfig
See simple example search for THREE.Screen call from index.html which is defined in ThreeJS_aux.js.
My javascript project is here
https://github.com/ProkopHapala/LearnWeb
did you tried adding a tsconfig.json file and set allowJs: true checkJs: true ? This way vscode will start a tsserver and you will have all its features / refactors. Remember that JavaScript IS TypeScript so you don't have to use anything strange just good old JavaScript. Typescript compiler supports that refactor and many others (or you could develop / install third party plugins with more). And if you want to start using Types,you could still do that using plain old JavaScript with jsdocs. My two cents. More info: https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
From the way you have your code laid out I would assume that you're going with a walkthrough or some kind of tutorial. Meaning, instead of splitting your JS into a separate file you're embedding it within the actual script tag in the HTML. Not a common practice is all unless someone is trying to maximize the development area, like a tutorial/walkthrough.
I think what you're really looking for here is design patterns. There is really no short answer to give you. There is also no single way to accomplish this. These design patterns are what puts JS together in a more readable fashion.
Try reading through this online book on design patterns Learning JS Design Patterns
This is a quick summary of your common design patterns AMD, commonJS, and Require. I recommend going through the book to get a more in depth understanding. Relation between CommonJS, AMD and RequireJS?

Code Assist for Javascript Canvas object

I'm stuck (after hours of trying to get unstuck). Main problem is that I would like to have class-specific code assist for javascript objects I retrieve from the DOM. For example,
if I retrieve a element using document.getElementById("theCanvas"), I only get code assist for a generic DOM object (which is logical). I would like to be able to "tell" the javascript editor that this object is actually a Canvas, so that I could then get code assist for the Canvas object.
I've installed Aptana and JSEclipse. With Aptana, I can't even find an Aptana (or Django) editor to associate with .js files. In the JSEclipse documentation (what of it there is), it mentions that you can enable this with JSDoc, but I have been unable to make this work. Also, JSEclipse doesn't seem to support formatting, which seems really odd.
Does anyone know if it is possible to get code assist for this case and/or how to access the Aptana js editor and/or how to get JSEclipse to format? I was thinking maybe you could cast the element object (a la Java), but the only documentation I could find on this says you can only do 3 casts in Javascript (Number, Boolean and String).
Platform: Eclipse Indigo for Java EE Developers (including WTP), Aptana 3.0.8, jdk 1.6.25, JSEclipse 1.5.5
Thanks in advance.
Well, Javascript isn`t strongly-typed and not compilated, this way is more difficult to IDEs to understand what are you meaning while you are writing.
But fortunately, you can use the Console of Google Chrome to help you with that. It knows the attributes and methods of the objects you are using

Break up JavaScript file into more manageable, or using different IDE

I use Dreamweaver for development, mostly PHP, html, css, javascript. Is there anyway to break up JavaScript files? or maybe a better IDE that makes it easier to work with? It just becomes quickly difficult to read and find what I'm looking for.
Thank you!
Intellij and/or Webstorm by Jetbrains has the best JS tools I have found. It has very good (as good as it gets, for JS) intellisense (autocomplete for variables and methods) as well as refactoring for variables and methods. You can cmd+click into method definitions from anywhere, as well. Unfortunately you need to pay for them, but if you are using Dreamweaver you had to pay for that. If you are only doing html/css/javascript Webstorm is the way to go.
Yes, you should break up your javascript files into relevant parts just like you break up your php files into relevant parts. The one key factor here is they should be combined and minified before being served up to the browser so the user does not have to make several network calls to your server for each .js file.
Check out Google Minify for an easy solution to that issue.
Take a look at the JQuery source to see how they divvy up their files. Now look at their combined framework, and of course their minified framework. What is actually served up to the user looks nothing like the source.
Uh, Dreamweaver?
Definitely use a different IDE. Aptana won the poll here :)

Is there a Java byte code reader implemented in javascript?

I know there are lots of libraries that read byte codes that are written in Java. Does someone know of a byte code library that is implemented in Javascript?
Since javascript is typically run inside a browser, it generally cannot read the actual bytes out of files, which makes it less-than-ideal for reading java bytes. If you somehow got the byte codes encoded in a form that the javascript could read, what would you expect the library to do with it? Can you provide more details about what you're trying to do?
If you're looking to be able to write code in Java, and have it run inside a browser, take a look at GWT. It uses Java to recompile your byte-code into optimized javascript.
Edit
Based on your added comment, that you are hoping to "find out the classes and methods used in a jar file on my local disk":
Since javascript is unable to access files on a local disk (at least, without using ActiveX), the technology simply won't allow for this sort of thing. Is there a reason you wanted to use javascript for this, rather than java?
And please accept my apologies if it sounded like I was questioning your motives. I really just wanted to get enough information to be able to adequately answer your question.
Update:
It looks like the Japanese project I tried to link to below is long gone.
In any case, time has passed and now there are a couple of hits for "jvm in javascript" on Google. Namely:
Doppio
BicaVM
Look what I found:
http://ejohn.org/blog/running-java-in-javascript/
Does this help?
Edit: unfortunately it looks like the original project's site is dead.
You could try through the Web Archive, here (in Japanese, tried to Google translate it, but I guess it was too much indirection :))
For goodness sake, if you follow that link, run your download through an anti-virus.
I don't know if it's trustworhty.
There are compilers which can compile Java to JavaScript. As a last resort, you can use one of those compilers to take a JVML bytecode disassembler written in Java and compile it to JavaScript. One example of such a compiler is GWT.
Similarly, there are compilers which can compile JVML bytecode to JavaScript. Again, you can take one of the above JVML bytecode disassemblers written in Java, use any Java-to-JVML compiler (javac, ecj, gcj, …) to compile it to JVML (i.e. .class files), then compile those .class files to JavaScript.

Categories