Skip to content

Commit

Permalink
fix: use babel-node for JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 22, 2021
1 parent d7fa525 commit 8581f8e
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 28 deletions.
16 changes: 7 additions & 9 deletions lib/grammars/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ const babel = path.join(
"../..",
"node_modules",
".bin",
GrammarUtils.OperatingSystem.isWindows() ? "babel.cmd" : "babel"
GrammarUtils.OperatingSystem.isWindows() ? "babel-node.cmd" : "babel-node"
)
const babelConfig = path.join(__dirname, "babel.config.js")

function JavaScriptArgs({ filepath }) {
const cmd = `'${babel}' --filename '${filepath}' --config-file ${babelConfig} < '${filepath}'| node`
return GrammarUtils.formatArgs(cmd)
}

const JavaScript = {
"Selection Based": {
command: GrammarUtils.command,
command: babel,
args: (context) => {
const code = context.getCode()
const filepath = GrammarUtils.createTempFileWithCode(code, ".js")
return JavaScriptArgs({ filepath })
return [filepath, "--config-file", babelConfig]
},
},
"File Based": { command: GrammarUtils.command, args: JavaScriptArgs },
"File Based": {
command: babel,
args: ({ filepath }) => [filepath, "--config-file", babelConfig],
},
}
const Babel = JavaScript
const JSX = JavaScript
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"@babel/cli": "^7.13.10",
"@babel/core": "^7.13.10",
"@babel/node": "^7.13.12",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.12.13",
"ansi-to-html": "^0.6.14",
Expand Down
Loading

0 comments on commit 8581f8e

Please sign in to comment.