1 | const Program = require('./fs-elements/Program')
|
2 | const RenderContext = require('./RenderContext')
|
3 |
|
4 | /**
|
5 | * Transpiles an AST object into Firescript
|
6 | *
|
7 | * @class FirescriptTranspiler
|
8 | */
|
9 | class FirescriptTranspiler {
|
10 | // constructor (opts) {
|
11 | // this.config = new FSConfig()
|
12 | //
|
13 | // if (opts && opts.features) {
|
14 | // this.config.merge({
|
15 | // features: opts.features
|
16 | // })
|
17 | // }
|
18 | // }
|
19 |
|
20 | transpile (ast) {
|
21 | try {
|
22 | const fireScript = new Program(ast)
|
23 | const ctx = new RenderContext({}, 'fire')
|
24 | return fireScript.toFSString(ctx).trim() + '\n'
|
25 | } catch (err) {
|
26 | if (!err.token) {
|
27 | throw err
|
28 | }
|
29 | this.syntaxError(err)
|
30 | }
|
31 | }
|
32 | }
|
33 |
|
34 | module.exports = FirescriptTranspiler
|