Skip to content

Commit 8581f8e

Browse files
committed
fix: use babel-node for JavaScript
1 parent d7fa525 commit 8581f8e

File tree

3 files changed

+174
-28
lines changed

3 files changed

+174
-28
lines changed

lib/grammars/javascript.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@ const babel = path.join(
88
"../..",
99
"node_modules",
1010
".bin",
11-
GrammarUtils.OperatingSystem.isWindows() ? "babel.cmd" : "babel"
11+
GrammarUtils.OperatingSystem.isWindows() ? "babel-node.cmd" : "babel-node"
1212
)
1313
const babelConfig = path.join(__dirname, "babel.config.js")
1414

15-
function JavaScriptArgs({ filepath }) {
16-
const cmd = `'${babel}' --filename '${filepath}' --config-file ${babelConfig} < '${filepath}'| node`
17-
return GrammarUtils.formatArgs(cmd)
18-
}
19-
2015
const JavaScript = {
2116
"Selection Based": {
22-
command: GrammarUtils.command,
17+
command: babel,
2318
args: (context) => {
2419
const code = context.getCode()
2520
const filepath = GrammarUtils.createTempFileWithCode(code, ".js")
26-
return JavaScriptArgs({ filepath })
21+
return [filepath, "--config-file", babelConfig]
2722
},
2823
},
29-
"File Based": { command: GrammarUtils.command, args: JavaScriptArgs },
24+
"File Based": {
25+
command: babel,
26+
args: ({ filepath }) => [filepath, "--config-file", babelConfig],
27+
},
3028
}
3129
const Babel = JavaScript
3230
const JSX = JavaScript

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"@babel/cli": "^7.13.10",
2323
"@babel/core": "^7.13.10",
24+
"@babel/node": "^7.13.12",
2425
"@babel/preset-env": "^7.13.10",
2526
"@babel/preset-react": "^7.12.13",
2627
"ansi-to-html": "^0.6.14",

0 commit comments

Comments
 (0)