Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
738 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 |
|
---|
| 2 | /**
|
---|
| 3 | * Expose `Compiler`.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | module.exports = Compiler;
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Initialize a compiler.
|
---|
| 10 | *
|
---|
| 11 | * @param {Type} name
|
---|
| 12 | * @return {Type}
|
---|
| 13 | * @api public
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | function Compiler(opts) {
|
---|
| 17 | this.options = opts || {};
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Emit `str`
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | Compiler.prototype.emit = function(str) {
|
---|
| 25 | return str;
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * Visit `node`.
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | Compiler.prototype.visit = function(node){
|
---|
| 33 | return this[node.type](node);
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * Map visit over array of `nodes`, optionally using a `delim`
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | Compiler.prototype.mapVisit = function(nodes, delim){
|
---|
| 41 | var buf = '';
|
---|
| 42 | delim = delim || '';
|
---|
| 43 |
|
---|
| 44 | for (var i = 0, length = nodes.length; i < length; i++) {
|
---|
| 45 | buf += this.visit(nodes[i]);
|
---|
| 46 | if (delim && i < length - 1) buf += this.emit(delim);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | return buf;
|
---|
| 50 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.