Skip to content

Commit bcc5d39

Browse files
committed
Initial commit
1 parent 2ec1768 commit bcc5d39

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/*
2+
node_modules/*

index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var recast = require("recast");
2+
3+
var code = "var foo = {template: <div>\n</div>, str: 'hejhej'}";
4+
5+
// Parse the code using an interface similar to require("esprima").parse.
6+
var ast = recast.parse(code);
7+
var b = recast.types.builders;
8+
9+
recast.visit(ast, {
10+
visitObjectExpression: function (path) {
11+
var obj = path.value;
12+
for (var i = 0; i < obj.properties.length; i++) {
13+
var property = obj.properties[i];
14+
//console.log(property);
15+
if (property.key.name === "template") {
16+
var templateStr = recast.print(property.value).code;
17+
18+
console.log("'" + templateStr + "'");
19+
property.value = b.literal(templateStr);
20+
}
21+
}
22+
this.traverse(path);
23+
}
24+
}
25+
);
26+
27+
var output = recast.print(ast).code;
28+
console.log(output);

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "angular-jsx",
3+
"version": "0.0.0",
4+
"description": "JSX support for Angular",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Samuel Moritz <samuel.moritz@gmail.com>",
10+
"license": "MIT",
11+
"dependencies": {
12+
"recast": "^0.10.32"
13+
}
14+
}

0 commit comments

Comments
 (0)