Transform static vars to `process.env` properties with Babel - babeljs

babel-plugin-dev-expression can be used to transform __DEV__ to process.env.NODE_ENV !== 'production'.
But is there a Babel transform plugin to convert other "code fence" symbols to process.env expressions?
For example, I'd like to be able to transform __DEBUG__ to process.env.DEBUG.
Before I try to write a plugin myself, does anyone know of one that already exists? Google is not turning up anything, but I'm sure it must exist as I won't be the first person who's wanted this.

I found a plugin that does this: babel-plugin-transform-replace-expressions
Initially I'd thought it was just doing a string-based search and replace, but actually it's more sophisticated than that, so it fulfils the use case.

Related

Is there a generally specification for references within a file?

I wanted writing an IDE plugin to simplify work with references to code in my documentation, but decided to first check the existence of a specification (like URI) so as not to reinvent the wheel.
I tried to find the answer to this on the internet but failed.
We know that such references work in different IDEs:
appRoot.folder.file.Class#method
appRoot.folder.file:35
appRoot/fodler/file.ext:35
But what if you need to get the path to the nested property JSON or XML?
I naively imagine that the sign # means the root and then for the JSON path I could use something like this:
appRoot/folder/jsonFile.json#oneLevelProp.twoLevelProp
But this of course does not work at the current moment in any IDE that I know of.

Remove Filter with Mapbox GL JS

Using Mapbox GL JS 0.39.1, I set a filter on my layer:
map.setFilter('myLayer', ['!=', 'myKey', 'myValue'])
I cannot find a way to remove the filter. I would have thought there would be a map.removeFilter... function but have found nothing in the docs or in web searches. I could apply a fake filter (>'') so that it always matches but that seems inefficient. Surely there is a way to remove a filter.
EDIT: I have found that using the following code will achieve what I am trying to accomplish. Not sure if this is the recommended approach.
map.setFilter('myLayer');
The docs were just updated, personally I would recommend using
map.setFilter('myLayer', null)
as it's more explicit and in my opinion makes the code more readable. Though your approach of just map.setFilter('myLayer'); is also acceptable.

Removing annotations from a Modelica model

I'm developing a Modelica library and need to produce a document with source code listings. I'd like to be able to include the source of the Modelica models without annotations.
I could manually edit them out, but I'm looking for a more automated strategy. I'm guessing the most convenient and straightforward approach is to use some tool to save .mo files with no annotations and include those in my document (I'm using \lstinputlisting in LaTeX).
Is it possible to do this? I have access to Dymola, OpenModelica and JModelica. Dymola is obviously capable of producing such a listing, as it's able to include it in the automatically generated documentation (File > Export > HTML...). I've been looking into scripting with Dymola and OpenModelica, but haven't found a way to do this either.
JModelica seems like it could be a good option, but I don't have experience working with Python. If this is possible and someone gives me some pointers, I'm willing to look into it myself. I found a mention to a prettyprint function that might do the job, but I'm not sure where to start. I can't even find reference to that function in the latest documentation.
It would also be more convenient for me to find a way of doing it with Dymola/OpenModelica (whether through the UI or by using a script). Have I missed something?
I think you could use saveTotalModel("total.mo", MyModelName) in OpenModelica. This will strip most annotations (not ones used for code generation if I remember correctly) and pretty-print the source code including all dependencies. Then you just copy-paste the models/packages that you want to include in the listing. Or if you prefer, you can do something like the following to only include code for a particular model:
loadModel(Modelica);
loadFile("MyModel.mo");
saveTotalModel("total.mo", MyModel.A.B);
clear();
loadFile(MyModel);
str := list(MyModel.A.B);
writeFile("MyModel.A.B.listing", str);

Auto fix common typo in eclipse

Lets say for example I write many times priavte instead private.
Is there a way to let Eclipse automatically fix my common typo?
Something like construct a map of my common typo to its desire fix,
and then just let Eclipse fix it without asking me about that.
Are there any other IDE\editors that have such support?
There is no builtin support for automatically changing strings. The closest to your request are the templates of the Java editor, but even those must explicitly be activated using CtrlSpace.
To get around your problem, I suggest simply not to write that much yourself. If you want to declare a private field, type just "pr" and hit CtrlSpace to invoke code completion. Eclipse can do code completion quite well, often even without any trigger characters (try it with an empty class file).

Javadoc on CoffeeScript?

I'm new to CoffeeScript and seems that I can't find any document generator for CoffeeScript using Javadoc syntax. The only one I could find is available as a patch to the CoffeeScript compiler.
So, what do you use to generate documentation from Javadoc comment on CoffeeScript or how do you document your function arguments and return values?
So, JavaDoc syntax has never really caught on with JavaScript developers. There are those who use something like it—notably Google—but it's kind of at odds with JS, which doesn't have static typing and allows any number of arguments to any function.
If you want to create beautiful documentation with CoffeeScript, the standard is Docco (its home page is an excellent example). If you want to create JavaDoc-style comments for every function... well, you'll have to create them by hand, and escape them with backticks.
Alternatively, you could work in CoffeeScript until your code is release-ready, then document the resulting JavaScript.
Docco is great for prozedural coding style. If you want to document an API, coffeedoc is for you.
People looking forward to using javadoc style documentation in coffeescript can checkout codo ( http://netzpirat.github.com/codo/ ) which provides support for a subset of javadoc and automatically infers class names, function names and parameters from source code.
I'm using YUIDoc. I can add comments using a syntax similar to Javadoc to my classes, methods and events. The documentation gets output as html/css files and you can even customize the page layout.
Check this documentation example: http://yui.github.com/yuidoc/api/
PS: It relies on Node.JS and you need to install the package yuidocjs
npm install yuidocjs -g