-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from CodeReviewerAi/avoid-tempjs
avoided using temp.js
- Loading branch information
Showing
2 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
const babel = require('@babel/parser'); | ||
const fs = require('fs'); | ||
|
||
const code = fs.readFileSync(process.argv[2], 'utf8'); | ||
|
||
try { | ||
const ast = babel.parse(code, { | ||
sourceType: "module", | ||
plugins: [], | ||
}); | ||
console.log(JSON.stringify(ast)); | ||
} catch (error) { | ||
console.error("Parsing error:", error); | ||
} | ||
|
||
process.stdin.setEncoding('utf8'); | ||
|
||
let code = ''; | ||
|
||
process.stdin.on('readable', () => { | ||
let chunk; | ||
while ((chunk = process.stdin.read()) !== null) { | ||
code += chunk; | ||
} | ||
}); | ||
|
||
process.stdin.on('end', () => { | ||
try { | ||
const ast = babel.parse(code, { | ||
sourceType: "module", | ||
plugins: [], | ||
}); | ||
console.log(JSON.stringify(ast)); | ||
} catch (error) { | ||
console.error("Parsing error:", error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters