-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (30 loc) · 988 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Dependencies
const AST = require("abstract-syntax-tree")
const Fs = require("fs")
//Variables
const Self_Args = process.argv.slice(2)
//Main
if(Self_Args.length == 0){
console.log(`node index.js <sjs_file>
Example: node index.js index.sjs`)
process.exit()
}
if(Self_Args[0].indexOf("sjs") != -1){
var file_data = Fs.readFileSync(Self_Args[0], "utf8")
file_data = file_data.replace(/gvar/g, "const")
file_data = file_data.replace(/(?<!")func\s(?!")/g, "function ")
const file_data_codes = Fs.readFileSync(Self_Args[0], "utf8").split("\n")
const file_data_tree = AST.parse(file_data)
AST.replace(file_data_tree, node =>{
if(node.type == "MemberExpression"){
if(node.property.name == "print"){
node.property.name = "log"
}
}
return node
})
eval(AST.generate(file_data_tree))
}else{
console.log("Invalid filetype, make sure the file extension is sjs.")
process.exit()
}