Skip to content

Commit 3c5ccca

Browse files
committed
Fix CoffeeScript run
Always run in the context of this package, to utilise the preconfigured Babel setup, but without altering the CWD. Builds on #1426.
1 parent f02d0ef commit 3c5ccca

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

examples/v2.litcoffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This is a [_literate_] CoffeeScript file, written in Markdown.
1111
setTimeout resolve, s * 1000 # ms
1212
1313
sleep = (s, message) =>
14-
console.log "Awaiting Promise…" # This selected line should run.
14+
console.log "Awaiting Promise…" # This [whole] selected line should run.
1515
await timeout s
1616
console.log message
1717

lib/grammars/coffeescript.coffee

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
module.exports =
1+
path = require 'path'
2+
GrammarUtils = require '../grammar-utils'
23

3-
CoffeeScript:
4-
'Selection Based':
5-
command: 'coffee'
6-
args: (context) -> ['--transpile', '-e', context.getCode()]
4+
bin = path.join __dirname, '../..', 'node_modules', '.bin'
5+
coffee = path.join bin, 'coffee'
6+
babel = path.join bin, 'babel'
77

8-
'File Based':
9-
command: 'coffee'
10-
args: ({filepath}) -> ['-t', filepath]
8+
args = ({filepath}) -> ['-c', "'#{coffee}' -p '#{filepath}'|'#{babel}' --filename '#{bin}'| node"]
119

12-
'CoffeeScript (Literate)':
10+
exports.CoffeeScript =
11+
'Selection Based':
12+
command: 'bash'
13+
args: (context) ->
14+
{scopeName} = atom.workspace.getActiveTextEditor()?.getGrammar()
15+
lit = if scopeName?.includes 'lit' then 'lit' else ''
16+
code = context.getCode()
17+
filepath = GrammarUtils.createTempFileWithCode(code, ".#{lit}coffee")
18+
return args({filepath})
1319

14-
'Selection Based':
15-
command: 'coffee'
16-
args: (context) -> ['-t', '-e', context.getCode()]
20+
'File Based': { command: 'bash', args }
1721

18-
'File Based':
19-
command: 'coffee'
20-
args: ({filepath}) -> ['-t', filepath]
22+
exports['CoffeeScript (Literate)'] = exports.CoffeeScript
2123

22-
IcedCoffeeScript:
23-
'Selection Based':
24-
command: 'iced'
25-
args: (context) -> ['-e', context.getCode()]
24+
exports.IcedCoffeeScript =
25+
'Selection Based':
26+
command: 'iced'
27+
args: (context) -> ['-e', context.getCode()]
2628

27-
'File Based':
28-
command: 'iced'
29-
args: ({filepath}) -> [filepath]
29+
'File Based':
30+
command: 'iced'
31+
args: ({filepath}) -> [filepath]

0 commit comments

Comments
 (0)