admin管理员组文章数量:1289496
Is there any way to get E4X(ECMAScript) to work with NodeJS?
It would really help to output slick html/xml without hassle/noise.
It works fine using SpiderMonkey since it is natively implemented, but it doesn't seem to work with NodeJS.
using node
$node
> var name = "World";
> var p = <p>Hello {name}</p>;
...
using spidermonkey
$js
js> var name = "World";
js> var p = <p>Hello {name}</p>;
Hello World
js>
thanks in advance
Is there any way to get E4X(ECMAScript) to work with NodeJS?
It would really help to output slick html/xml without hassle/noise.
It works fine using SpiderMonkey since it is natively implemented, but it doesn't seem to work with NodeJS.
using node
$node
> var name = "World";
> var p = <p>Hello {name}</p>;
...
using spidermonkey
$js
js> var name = "World";
js> var p = <p>Hello {name}</p>;
Hello World
js>
thanks in advance
Share Improve this question edited Feb 20, 2011 at 13:44 zanona asked Feb 20, 2011 at 12:40 zanonazanona 12.7k25 gold badges90 silver badges146 bronze badges 3-
1
Not really an answer to your question, but I like to write NodeJS scripts in CoffeeScript, because you can use heredocs, or something like
p = """Hello #{name}"""
. 3 quotation marks also allows you to have newlines inside strings. – Thai Commented Feb 20, 2011 at 14:11 - @Thai thanks for this it was good to know that there's something helpul like CoffeScript and actually is very clever, I like it a lot. – zanona Commented Feb 20, 2011 at 17:57
- You can use React & JSX in NodeJS. But it's not exactly what you want. – user1742529 Commented Dec 8, 2017 at 9:25
2 Answers
Reset to default 10Node uses V8, which does not implement E4X as of now.
There's a 2 year old issue, but still active issue on the topic. But it has no real "status" nor was it assigned to anyone.
So in short: The answer is no.
I have developed a babel plugin that adds E4X basic support to NodeJS.
https://www.npmjs./package/babel-plugin-transform-simple-e4x
You can also use the npm simple4x library to parse xml strings to a XML like object.
https://www.npmjs./package/simple4x
The plugin transpiles the following E4X:
var fooId = 'foo-id';
var barText = 'bar text';
var xml =
<xml>
<foo id={fooId}>
{barText}
</foo>
</xml>;
To the following JavaScript:
var XML = new require("simple4x");
var fooId = 'foo-id';
var barText = 'bar text';
var xml = new XML("<xml><foo id=\"" + fooId + "\">" + barText + "</foo></xml>");
本文标签: javascriptE4X with NodeJSStack Overflow
版权声明:本文标题:javascript - E4X with NodeJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741425583a2378057.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论