-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eval): support coffeescript (#230)
- Loading branch information
Anillc
authored
Apr 17, 2021
1 parent
722f343
commit 61e5ea9
Showing
6 changed files
with
44 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { compile } = require('coffeescript') | ||
|
||
export const name = 'coffeescript' | ||
|
||
export function extractScript(expr: string) { | ||
try { | ||
compile(expr) | ||
} catch (e) { | ||
if (e.message !== 'unmatched }') throw e | ||
const location = e.location | ||
const sLines = expr.split('\n') | ||
const row = location.first_line | ||
const column = location.first_column - 1 | ||
return [...sLines.slice(0, row - 1), sLines[row].slice(0, column + 1)].join('\n') | ||
} | ||
} | ||
|
||
export async function transformScript(expr: string) { | ||
return compile(expr, { bare: true }) | ||
} | ||
|
||
export const transformModule = transformScript |
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import bar from './bar.yml' | ||
|
||
export default (index = 1) -> bar[index] |
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,8 +1,9 @@ | ||
import { registerCommand } from 'koishi/addons' | ||
import { foo } from './foo' | ||
import foobar from './foobar' | ||
|
||
export * from './foo' | ||
|
||
registerCommand('test', () => { | ||
return foo() | ||
return foo() + foobar() | ||
}) |
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