├── .coveralls.yml ├── .gitignore ├── .gitmodules ├── .npmignore ├── .travis.yml ├── Makefile ├── README.md ├── dist ├── php-unparser.js └── php-unparser.min.js ├── example └── index.js ├── index.js ├── node_translators ├── array.js ├── assign.js ├── bin.js ├── block.js ├── boolean.js ├── break.js ├── call.js ├── cast.js ├── class.js ├── classconstant.js ├── clone.js ├── closure.js ├── constant.js ├── constref.js ├── continue.js ├── declare.js ├── do.js ├── doc.js ├── echo.js ├── empty.js ├── encapsed.js ├── eval.js ├── exit.js ├── for.js ├── foreach.js ├── function.js ├── global.js ├── goto.js ├── helper │ ├── arguments.js │ ├── body.js │ ├── identifier.js │ └── parameters.js ├── identifier.js ├── if.js ├── include.js ├── index.js ├── inline.js ├── interface.js ├── isset.js ├── label.js ├── list.js ├── magic.js ├── method.js ├── namespace.js ├── new.js ├── nowdoc.js ├── number.js ├── offsetlookup.js ├── parenthesis.js ├── post.js ├── pre.js ├── print.js ├── program.js ├── property.js ├── propertylookup.js ├── retif.js ├── return.js ├── silent.js ├── static.js ├── staticlookup.js ├── string.js ├── switch.js ├── throw.js ├── trait.js ├── traituse.js ├── try.js ├── unary.js ├── unset.js ├── usegroup.js ├── variable.js ├── variadic.js ├── while.js ├── yield.js └── yieldfrom.js ├── npm-shrinkwrap.json ├── package.json └── test ├── helper.js ├── spec ├── acid1-parsed.php └── acid1.php └── tests.spec.js /.coveralls.yml: -------------------------------------------------------------------------------- 1 | repo_token: PgSqJ3NyXKBl1VbAkkBQSbQ0lvxCHC1Z5 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | node_modules/ 3 | coverage/ 4 | npm-debug.log 5 | test/magento2 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chris-l/php-unparser/fbff1c68d11e6d6b2b3d8f1cceaf537a3ca409ec/.gitmodules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /test/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | - "5" 5 | - "4" 6 | - "0.10" 7 | notifications: 8 | email: false 9 | script: make cover 10 | after_success: cat /home/travis/build/glayzzle/php-unparser/coverage/lcov.info | /home/travis/build/glayzzle/php-unparser/node_modules/coveralls/bin/coveralls.js 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | program: test lint index dist 2 | 3 | index: 4 | sed -i -n '1,/^\/\/ node translators/ p' node_translators/index.js 5 | ls node_translators/|sed -n '/index.js/ !{ s/\([^\.]*\)\.js/CodeGen.prototype.\1 = require(".\/\1\.js");/p }' >> node_translators/index.js 6 | 7 | dist: index 8 | node_modules/browserify/bin/cmd.js -s phpUnparser index.js | node_modules/uglifyjs/bin/uglifyjs > dist/php-unparser.min.js 9 | 10 | lint: 11 | node_modules/jslint/bin/jslint.js --indent 2 --color package.json index.js node_translators/*.js node_translators/**/*.js test/**/*.js 12 | 13 | test: index 14 | node_modules/jasmine-node/bin/jasmine-node test 15 | 16 | cover: index lint 17 | node --stack-size=5000 node_modules/istanbul/lib/cli.js cover -x \"**/test/**\" test/index.js 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | php-unparser 2 | ============ 3 | 4 | [![Build Status](https://travis-ci.org/glayzzle/php-unparser.svg?branch=master)](https://travis-ci.org/glayzzle/php-unparser) 5 | [![Coverage Status](https://coveralls.io/repos/github/glayzzle/php-unparser/badge.svg?branch=master)](https://coveralls.io/github/glayzzle/php-unparser?branch=master) 6 | 7 | This project is a JavaScript based [unparser](https://en.wikipedia.org/wiki/Unparser) for the AST produced by glayzzle's [php-parser](https://github.com/glayzzle/php-parser). 8 | 9 | It aims to produce code that uses the style format recommended by PSR-1 and PSR-2. 10 | 11 | It's at an early development stage, but it is already able to generate code for most of the produced AST. 12 | 13 | It has __no dependencies__. 14 | 15 | ## How to use 16 | 17 | ```javascript 18 | var unparse = require('php-unparser'); 19 | 20 | var options = { 21 | indent: true, 22 | dontUseWhitespaces: false, 23 | shortArray: true, 24 | bracketsNewLine: true, 25 | forceNamespaceBrackets: false, 26 | collapseEmptyLines: true 27 | }; 28 | 29 | var ast = { 30 | "kind": "program", 31 | "children": [ 32 | { 33 | "kind": "echo", 34 | "arguments": [ 35 | { 36 | "kind": "string", 37 | "value": "hello world", 38 | "isDoubleQuote": true 39 | } 40 | ] 41 | } 42 | ], 43 | "errors": [] 44 | }; 45 | 46 | // Will output -> echo "hello world"; 47 | console.log(unparse(ast, options)); 48 | ``` 49 | 50 | ## Options 51 | 52 | | option | value | default | description | 53 | |------------------------|---------|----------|-------------| 54 | | indent | string | | The indentation size, default is four white spaces. | 55 | | dontUseWhitespaces | boolean | `false` | If enabled removes all the whitespaces between stuff. | 56 | | shortArray | boolean | `false` | If enabled write arrays in short array syntax enabled since PHP 5.4.0 | 57 | | bracketsNewLine | boolean | `true` | If enabled will put brackets on new line. | 58 | | forceNamespaceBrackets | boolean | `false` | Force the namespace bracketed syntax (_recommended for combining namespaces_) | 59 | | collapseEmptyLines | boolean | `true` | If enabled it will remove all empty lines between sections and properties. | 60 | 61 | ## Demo 62 | 63 | [See it working](https://chris-l.github.io/php-unparser/) 64 | 65 | ## License 66 | 67 | MIT License, Copyright 2016 Christopher Luna 68 | -------------------------------------------------------------------------------- /dist/php-unparser.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.phpUnparser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o' + that.ws + value; 27 | } 28 | return value; 29 | }; 30 | } 31 | 32 | elements = node.items.map(processElement(indent)); 33 | 34 | if (elements.join().length > 80) { 35 | space = that.nl + indent + this.indent; 36 | elements = node.items.map(processElement(indent + this.indent)); 37 | body = space + elements.join(',' + space) + that.nl + indent; 38 | } else { 39 | body = elements.join(',' + that.ws); 40 | } 41 | 42 | if (node.shortForm || this.shortArray) { 43 | return '[' + body + ']'; 44 | } 45 | return 'array(' + body + ')'; 46 | }; 47 | 48 | },{}],3:[function(require,module,exports){ 49 | /*jslint node: true, indent: 2 */ 50 | 'use strict'; 51 | 52 | module.exports = function (node, indent) { 53 | var codegen = this.process.bind(this); 54 | return codegen(node.left, indent) + this.ws + node.operator + this.ws + codegen(node.right, indent); 55 | }; 56 | 57 | },{}],4:[function(require,module,exports){ 58 | /*jslint node: true, indent: 2 */ 59 | 'use strict'; 60 | 61 | module.exports = function (node, indent) { 62 | var codegen = this.process.bind(this); 63 | return codegen(node.left, indent) + 64 | this.ws + node.type + this.ws + 65 | codegen(node.right, indent); 66 | }; 67 | 68 | },{}],5:[function(require,module,exports){ 69 | /*jslint node: true, indent: 2 */ 70 | 'use strict'; 71 | 72 | var doBody = require('./helper/body'); 73 | 74 | // block 75 | module.exports = function (node, indent) { 76 | var codegen, str = ''; 77 | codegen = this.process.bind(this); 78 | 79 | str += this.nl + indent + '{' + this.nl; 80 | str += doBody.call(this, codegen, indent, node.children); 81 | str += indent + '}' + this.nl; 82 | 83 | return str; 84 | }; 85 | 86 | },{"./helper/body":31}],6:[function(require,module,exports){ 87 | /*jslint node: true, indent: 2 */ 88 | 'use strict'; 89 | 90 | module.exports = function (node) { 91 | return node.value ? 'true' : 'false'; 92 | }; 93 | 94 | },{}],7:[function(require,module,exports){ 95 | /*jslint node: true, indent: 2 */ 96 | 'use strict'; 97 | 98 | module.exports = function (node, indent) { 99 | if (node.level) { 100 | var codegen = this.process.bind(this); 101 | return 'break ' + codegen(node.level, indent); 102 | } 103 | return 'break'; 104 | }; 105 | 106 | },{}],8:[function(require,module,exports){ 107 | /*jslint node: true, indent: 2 */ 108 | 'use strict'; 109 | 110 | var params = require('./helper/parameters'); 111 | 112 | module.exports = function (node, indent) { 113 | var codegen = this.process.bind(this); 114 | return codegen(node.what, indent) + 115 | '(' + params(node.arguments, indent, this) + ')'; 116 | }; 117 | 118 | },{"./helper/parameters":33}],9:[function(require,module,exports){ 119 | /*jslint node: true, indent: 2 */ 120 | 'use strict'; 121 | 122 | module.exports = function (node, indent) { 123 | var codegen; 124 | codegen = this.process.bind(this); 125 | return '(' + node.type + ')' + codegen(node.what, indent); 126 | }; 127 | 128 | },{}],10:[function(require,module,exports){ 129 | /*jslint node: true, indent: 2 */ 130 | 'use strict'; 131 | 132 | var doBody = require('./helper/body'); 133 | 134 | module.exports = function (node, indent) { 135 | var codegen, str, that; 136 | codegen = this.process.bind(this); 137 | str = ''; 138 | that = this; 139 | 140 | // Start 141 | if (node.isAbstract) { 142 | str += 'abstract '; 143 | } else if (node.isFinal) { 144 | str += 'final '; 145 | } 146 | 147 | str += 'class'; 148 | if (node.name) { 149 | str += ' ' + node.name; 150 | } 151 | 152 | if (node.extends) { 153 | str += ' extends ' + codegen(node.extends, indent); 154 | } 155 | 156 | if (node.implements) { 157 | str += ' implements ' + node.implements.map(function (x) { 158 | return codegen(x, indent); 159 | }).join(',' + that.ws); 160 | } 161 | 162 | // begin curly brace 163 | if (node.name) { 164 | if (this.options.bracketsNewLine) { 165 | str += this.nl + indent + '{' + this.nl; 166 | } else { 167 | str += this.ws + '{' + this.nl; 168 | } 169 | } else { 170 | str += this.ws + '{' + this.nl; 171 | } 172 | 173 | 174 | // class body 175 | str += doBody.call(this, codegen, indent, node.body); 176 | 177 | // end curly brace 178 | str += indent + '}'; 179 | if (node.name) { 180 | str += this.nl; 181 | } 182 | 183 | return str; 184 | }; 185 | 186 | },{"./helper/body":31}],11:[function(require,module,exports){ 187 | /*jslint node: true, indent: 2 */ 188 | 'use strict'; 189 | 190 | /** 191 | * Constant declaration 192 | */ 193 | module.exports = function (node, indent) { 194 | var codegen, str = ''; 195 | codegen = this.process.bind(this); 196 | if (node.visibility) { 197 | str += node.visibility + ' '; 198 | } 199 | str += 'const '; 200 | str += node.name; 201 | if (node.value) { 202 | str += this.ws + '=' + this.ws; 203 | str += codegen(node.value, indent); 204 | } 205 | return str; 206 | }; 207 | 208 | },{}],12:[function(require,module,exports){ 209 | /*jslint node: true, indent: 2 */ 210 | 'use strict'; 211 | 212 | module.exports = function (node, indent) { 213 | var codegen; 214 | codegen = this.process.bind(this); 215 | return 'clone ' + codegen(node.what, indent); 216 | }; 217 | 218 | },{}],13:[function(require,module,exports){ 219 | /*jslint node: true, indent: 2 */ 220 | 'use strict'; 221 | 222 | var doBody = require('./helper/body'); 223 | var args = require('./helper/arguments'); 224 | var identifier = require('./helper/identifier'); 225 | 226 | // params, isRef, use, returnType 227 | module.exports = function (node, indent) { 228 | var codegen, str, useArgs; 229 | codegen = this.process.bind(this); 230 | 231 | // function header 232 | str = 'function' + this.ws; 233 | if (node.byref) { 234 | str += '&'; 235 | } 236 | str += args(node.arguments, indent, this); 237 | 238 | // use statement 239 | if (node.uses && node.uses.length > 0) { 240 | useArgs = node.uses.map(function (arg) { 241 | return '$' + arg.name; 242 | }); 243 | str += this.ws + 'use' + this.ws + '(' + useArgs.join(',' + this.ws) + ')'; 244 | } 245 | 246 | // php7 / return type 247 | if (node.type) { 248 | str += this.ws + ':' + this.ws; 249 | if (node.nullable) { 250 | str += '?'; 251 | } 252 | str += identifier(node.type); 253 | } 254 | 255 | str += this.ws + '{' + this.nl; 256 | str += doBody.call(this, codegen, indent, node.body.children); 257 | str += indent + '}'; 258 | return str; 259 | }; 260 | 261 | },{"./helper/arguments":30,"./helper/body":31,"./helper/identifier":32}],14:[function(require,module,exports){ 262 | /*jslint node: true, indent: 2 */ 263 | 'use strict'; 264 | 265 | /** 266 | * Constant declaration 267 | */ 268 | module.exports = function (node, indent) { 269 | var codegen, str; 270 | codegen = this.process.bind(this); 271 | 272 | // a namespace constant (name, value) 273 | str = 'const '; 274 | str += node.name; 275 | str += this.ws + '=' + this.ws; 276 | str += codegen(node.value, indent) + ';'; 277 | 278 | return str; 279 | }; 280 | 281 | },{}],15:[function(require,module,exports){ 282 | /*jslint node: true, indent: 2 */ 283 | 'use strict'; 284 | 285 | var identifier = require('./helper/identifier'); 286 | /** 287 | * Constant usage 288 | */ 289 | module.exports = function (node) { 290 | if (typeof node.name === 'string') { 291 | return identifier(node); 292 | } 293 | return identifier(node.name); 294 | }; 295 | 296 | },{"./helper/identifier":32}],16:[function(require,module,exports){ 297 | /*jslint node: true, indent: 2 */ 298 | 'use strict'; 299 | 300 | module.exports = function (node, indent) { 301 | var codegen = this.process.bind(this); 302 | if (node.level) { 303 | return 'continue ' + codegen(node.level, indent); 304 | } 305 | 306 | return 'continue'; 307 | }; 308 | 309 | },{}],17:[function(require,module,exports){ 310 | /*jslint node: true, indent: 2 */ 311 | 'use strict'; 312 | 313 | var doBody = require('./helper/body'); 314 | 315 | module.exports = function (node, indent) { 316 | var codegen, str, items = [], k; 317 | codegen = this.process.bind(this); 318 | for (k in node.what) { 319 | if (node.what.hasOwnProperty(k) && node.what[k]) { 320 | items.push(k + '=' + codegen(node.what[k])); 321 | } 322 | } 323 | str = 'declare(' + items.join(',') + ')'; 324 | if (node.mode !== 'none') { 325 | str += this.ws + '{' + this.nl; 326 | str += doBody.call(this, codegen, indent, node.children); 327 | str += indent + '}' + this.nl; 328 | } else { 329 | str += ';' + this.nl; 330 | str += doBody.call(this, codegen, indent, node.children); 331 | } 332 | return str; 333 | }; 334 | 335 | },{"./helper/body":31}],18:[function(require,module,exports){ 336 | /*jslint node: true, indent: 2 */ 337 | 'use strict'; 338 | 339 | var doBody = require('./helper/body'); 340 | 341 | module.exports = function (node, indent) { 342 | var codegen, str; 343 | codegen = this.process.bind(this); 344 | str = 'do' + this.ws + '{' + this.nl; 345 | str += doBody.call(this, codegen, indent, node.body.children); 346 | str += indent + '}' + this.ws + 'while' + this.ws + '(' + codegen(node.test, indent) + ')'; 347 | return str; 348 | }; 349 | 350 | },{"./helper/body":31}],19:[function(require,module,exports){ 351 | /*jslint node: true, indent: 2 */ 352 | 'use strict'; 353 | 354 | module.exports = function (node, indent) { 355 | if (node.isDoc) { 356 | var body = node.lines.join(this.nl + indent + ' * '); 357 | if (body.substring(body.length - 3) === ' * ') { 358 | body = body.substring(0, body.length - 3); 359 | } 360 | return this.nl + indent + '/** ' + body + ' */'; 361 | } 362 | return this.nl + indent + '// ' + node.lines.join(this.nl + indent + '// '); 363 | }; 364 | 365 | },{}],20:[function(require,module,exports){ 366 | /*jslint node: true, indent: 2 */ 367 | 'use strict'; 368 | 369 | var params = require('./helper/parameters'); 370 | 371 | module.exports = function (node, indent) { 372 | return 'echo ' + params(node.arguments, indent, this); 373 | }; 374 | 375 | },{"./helper/parameters":33}],21:[function(require,module,exports){ 376 | /*jslint node: true, indent: 2 */ 377 | 'use strict'; 378 | 379 | module.exports = function (node, indent) { 380 | var codegen = this.process.bind(this); 381 | return 'empty(' + codegen(node.arguments[0], indent) + ')'; 382 | }; 383 | 384 | },{}],22:[function(require,module,exports){ 385 | /*jslint node: true, indent: 2, unparam:true */ 386 | 'use strict'; 387 | 388 | module.exports = function (node, indent, opt) { 389 | var body = '', codegen = this.process.bind(this); 390 | 391 | node.value.forEach(function (item) { 392 | if (item.kind === 'string') { 393 | body += item.value; 394 | } else { 395 | body += '{' + codegen(item, indent) + '}'; 396 | } 397 | }); 398 | 399 | if (node.type === 'heredoc') { 400 | return '<<<' + node.label + this.nl + body + node.label; 401 | } 402 | 403 | if (node.type === 'nowdoc') { 404 | return '<<<\'' + node.label + '\'' + this.nl + body + node.label; 405 | } 406 | 407 | if (node.type === 'shell') { 408 | return '`' + body + '`'; 409 | } 410 | 411 | if (node.isDoubleQuote) { 412 | return '"' + body + '"'; 413 | } 414 | 415 | return '\'' + body + '\''; 416 | }; 417 | 418 | },{}],23:[function(require,module,exports){ 419 | /*jslint node: true, indent: 2 */ 420 | 'use strict'; 421 | 422 | module.exports = function (node, indent) { 423 | var codegen = this.process.bind(this); 424 | return 'eval(' + codegen(node.source, indent) + ')'; 425 | }; 426 | 427 | },{}],24:[function(require,module,exports){ 428 | /*jslint node: true, indent: 2 */ 429 | 'use strict'; 430 | 431 | /** 432 | * Exit statement 433 | */ 434 | module.exports = function (node, indent) { 435 | var codegen; 436 | codegen = this.process.bind(this); 437 | if (node.status === null) { 438 | return 'exit'; 439 | } 440 | return 'exit(' + codegen(node.status, indent) + ')'; 441 | }; 442 | 443 | },{}],25:[function(require,module,exports){ 444 | /*jslint node: true, indent: 2 */ 445 | 'use strict'; 446 | 447 | var doBody = require('./helper/body'); 448 | 449 | module.exports = function (node, indent) { 450 | var codegen, str; 451 | 452 | codegen = this.process.bind(this); 453 | str = 'for' + this.ws + '('; 454 | 455 | if (node.init) { 456 | str += node.init.map(function (x) { 457 | if (x) { 458 | return codegen(x, indent); 459 | } 460 | return ''; 461 | }).join(',' + this.ws); 462 | } 463 | str += ';' + this.ws; 464 | 465 | if (node.test) { 466 | str += node.test.map(function (x) { 467 | if (x) { 468 | return codegen(x, indent); 469 | } 470 | return ''; 471 | }).join(',' + this.ws); 472 | } 473 | str += ';' + this.ws; 474 | 475 | if (node.increment) { 476 | str += node.increment.map(function (x) { 477 | if (x) { 478 | return codegen(x, indent); 479 | } 480 | return ''; 481 | }).join(',' + this.ws); 482 | } 483 | str += ')'; 484 | if (this.shortForm) { 485 | str += ':' + this.nl; 486 | } else { 487 | str += this.ws + '{' + this.nl; 488 | } 489 | 490 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 491 | 492 | if (this.shortForm) { 493 | str += indent + 'endfor;'; 494 | } else { 495 | str += indent + '}'; 496 | } 497 | return str; 498 | }; 499 | 500 | },{"./helper/body":31}],26:[function(require,module,exports){ 501 | /*jslint node: true, indent: 2 */ 502 | 'use strict'; 503 | 504 | var doBody = require('./helper/body'); 505 | 506 | module.exports = function (node, indent) { 507 | var codegen, str; 508 | codegen = this.process.bind(this); 509 | 510 | str = 'foreach' + this.ws + '(' + codegen(node.source, indent) + this.ws + 'as' + this.ws; 511 | if (node.key) { 512 | str += codegen(node.key, indent) + this.ws + '=>' + this.ws; 513 | } 514 | str += codegen(node.value, indent) + ')'; 515 | if (node.shortForm) { 516 | str += ':' + this.nl; 517 | } else { 518 | str += this.ws + '{' + this.nl; 519 | } 520 | 521 | str += doBody.call(this, codegen, indent, node.body.children); 522 | if (node.shortForm) { 523 | str += indent + 'endforeach;'; 524 | } else { 525 | str += indent + '}'; 526 | } 527 | return str; 528 | }; 529 | 530 | },{"./helper/body":31}],27:[function(require,module,exports){ 531 | /*jslint node: true, indent: 2 */ 532 | 'use strict'; 533 | 534 | var doBody = require('./helper/body'); 535 | var args = require('./helper/arguments'); 536 | var identifier = require('./helper/identifier'); 537 | 538 | // name, params, isRef, returnType, body 539 | module.exports = function (node, indent) { 540 | var codegen, str; 541 | codegen = this.process.bind(this); 542 | 543 | str = 'function '; 544 | if (node.byref) { 545 | str += '&'; 546 | } 547 | str += node.name; 548 | str += args(node.arguments, indent, this); 549 | 550 | // php7 / return type 551 | if (node.type) { 552 | str += this.ws + ':' + this.ws; 553 | if (node.nullable) { 554 | str += '?'; 555 | } 556 | str += identifier(node.type); 557 | } 558 | 559 | if (this.options.bracketsNewLine) { 560 | str += this.nl + indent + '{' + this.nl; 561 | } else { 562 | str += this.ws + '{' + this.nl; 563 | } 564 | 565 | str += doBody.call(this, codegen, indent, node.body.children); 566 | str += indent + '}' + this.nl; 567 | 568 | return str; 569 | }; 570 | 571 | },{"./helper/arguments":30,"./helper/body":31,"./helper/identifier":32}],28:[function(require,module,exports){ 572 | /*jslint node: true, indent: 2 */ 573 | 'use strict'; 574 | 575 | module.exports = function (node, indent) { 576 | var codegen = this.process.bind(this); 577 | return 'global ' + node.items.map(function (x) { 578 | return codegen(x, indent); 579 | }).join(',' + this.ws); 580 | }; 581 | 582 | },{}],29:[function(require,module,exports){ 583 | /*jslint node: true, indent: 2 */ 584 | 'use strict'; 585 | 586 | module.exports = function (node) { 587 | return 'goto ' + node.label; 588 | }; 589 | 590 | },{}],30:[function(require,module,exports){ 591 | /*jslint node: true, indent: 2 */ 592 | 'use strict'; 593 | 594 | // name, type, value, isRef, isVariadic 595 | function processElement(indent, ws, codegen) { 596 | return function (arg) { 597 | var str = ''; 598 | 599 | if (arg.type) { // type hint 600 | str += codegen(arg.type, indent) + ws; 601 | } 602 | 603 | if (arg.byref) { // byref 604 | str += '&'; 605 | } 606 | 607 | if (arg.variadic) { // variadic 608 | str += '...'; 609 | } 610 | 611 | str += '$' + arg.name; // name 612 | 613 | if (arg.value) { // default value 614 | str += ws + '=' + ws + codegen(arg.value, indent); 615 | } 616 | 617 | return str; 618 | }; 619 | } 620 | 621 | module.exports = function (nodes, indent, self) { 622 | var codegen, args, space, listArgs; 623 | 624 | codegen = self.process.bind(self); 625 | args = nodes.map(processElement(indent, self.ws, codegen)); 626 | listArgs = args.join(',' + self.ws); 627 | 628 | if (listArgs.length > 80) { 629 | space = self.nl + indent + self.indent; 630 | args = nodes.map(processElement(indent + self.indent, self.ws, codegen)); 631 | listArgs = space + args.join(',' + space) + self.nl + indent; 632 | } 633 | 634 | return '(' + listArgs + ')'; 635 | }; 636 | 637 | },{}],31:[function(require,module,exports){ 638 | /*jslint node: true, indent: 2 */ 639 | 'use strict'; 640 | 641 | var noSemiColons = [ 642 | 'class', 'interface', 'trait', 'namespace', 'try', 643 | 'if', 'switch', 'for', 'foreach', 'function', 'method', 644 | 'while', 'doc', 'comment', 'label', 'declare', 645 | 'usegroup', 'traituse', 'inline', 'block' 646 | ]; 647 | 648 | module.exports = function (codegen, currentIndent, body, isProgram) { 649 | 650 | var str, indentation, delimiter, that = this; 651 | 652 | // Set the rows delimiter 653 | delimiter = that.options.collapseEmptyLines ? '' : '\n'; 654 | 655 | // Set the indentation 656 | indentation = isProgram ? '' : currentIndent + that.indent; 657 | 658 | // Force body as an array 659 | if (!Array.isArray(body)) { 660 | body = [body]; 661 | } 662 | 663 | // Map body values 664 | str = body.map(function (expr) { 665 | 666 | // Return empty string 667 | if (expr === null) { 668 | return ''; 669 | } 670 | 671 | var line; 672 | if (expr.kind === 'label') { 673 | line = codegen(expr, indentation); 674 | } else { 675 | line = indentation + codegen(expr, indentation); 676 | } 677 | 678 | // This expressions don't require semicolons 679 | if (noSemiColons.indexOf(expr.kind) === -1) { 680 | line += ';'; 681 | } 682 | 683 | return line + that.nl; 684 | 685 | }).join(delimiter); 686 | 687 | // Return the generated string 688 | return str; 689 | }; 690 | 691 | },{}],32:[function(require,module,exports){ 692 | /*jslint node: true, indent: 2 */ 693 | 'use strict'; 694 | 695 | module.exports = function identifier(id) { 696 | if (id.resolution === 'rn') { 697 | return 'namespace\\' + id.name; 698 | } 699 | return id.name; 700 | }; 701 | 702 | },{}],33:[function(require,module,exports){ 703 | /*jslint node: true, indent: 2 */ 704 | 'use strict'; 705 | 706 | module.exports = function (args, indent, self) { 707 | var codegen, useArgs = [], space, raw; 708 | 709 | codegen = self.process.bind(self); 710 | 711 | function processElement(indent) { 712 | return function (arg) { 713 | return codegen(arg, indent); 714 | }; 715 | } 716 | if (args && args.length > 0) { 717 | useArgs = args.map(processElement(indent)); 718 | } 719 | raw = useArgs.join(); 720 | if ((raw.indexOf("\n") > -1 && raw.substr(0, raw.indexOf("\n")).length > 80) || (raw.indexOf("\n") === -1 && raw.length > 80)) { 721 | useArgs = args.map(processElement(indent + self.indent)); 722 | space = self.nl + indent + self.indent; 723 | args = space + useArgs.join(',' + space) + self.nl + indent; 724 | } else { 725 | args = useArgs.join(',' + self.ws); 726 | } 727 | return args; 728 | }; 729 | 730 | },{}],34:[function(require,module,exports){ 731 | /*jslint node: true, indent: 2 */ 732 | 'use strict'; 733 | 734 | module.exports = function (node) { 735 | if (node.resolution === 'rn') { 736 | return 'namespace\\' + node.name; 737 | } 738 | return node.name; 739 | }; 740 | 741 | },{}],35:[function(require,module,exports){ 742 | /*jslint node: true, indent: 2 */ 743 | 'use strict'; 744 | 745 | var doBody = require('./helper/body'); 746 | 747 | module.exports = function processIf(node, indent, inner) { 748 | var codegen, str, that = this; 749 | 750 | codegen = this.process.bind(this); 751 | 752 | str = 'if' + this.ws + '(' + codegen(node.test, indent) + ')'; 753 | 754 | if (node.body) { 755 | if (node.shortForm) { 756 | str += ':' + this.nl; 757 | } else { 758 | str += this.ws + '{' + this.nl; 759 | } 760 | 761 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 762 | 763 | if (!node.shortForm) { 764 | str += indent + '}'; 765 | } 766 | } else if (!node.alternate) { 767 | return str + ';'; 768 | } 769 | 770 | if (node.alternate) { 771 | str += (function () { 772 | var out = ''; 773 | // is an "elseif" 774 | if (node.alternate.kind === 'if') { 775 | if (node.shortForm) { 776 | return indent + 'else' + processIf.call(that, node.alternate, indent, true); 777 | } 778 | return that.ws + 'else' + processIf.call(that, node.alternate, indent, true); 779 | } 780 | 781 | // is an "else" 782 | if (node.shortForm) { 783 | out += indent + 'else:' + that.nl; 784 | } else { 785 | out += that.ws + 'else' + that.ws + '{' + that.nl; 786 | } 787 | 788 | out += doBody.call(that, codegen, indent, node.alternate.children || [node.alternate]); 789 | 790 | if (!node.shortForm) { 791 | out += indent + '}' + that.nl; 792 | } 793 | return out; 794 | }()); 795 | } 796 | 797 | if (node.shortForm && !inner) { 798 | str += indent + 'endif;' + this.nl; 799 | } 800 | return str; 801 | }; 802 | 803 | },{"./helper/body":31}],36:[function(require,module,exports){ 804 | /*jslint node: true, indent: 2 */ 805 | 'use strict'; 806 | 807 | module.exports = function (node, indent) { 808 | var str, codegen; 809 | str = node.require ? 'require' : 'include'; 810 | if (node.once) { 811 | str += '_once'; 812 | } 813 | codegen = this.process.bind(this); 814 | return str + ' ' + codegen(node.target, indent); 815 | }; 816 | 817 | },{}],37:[function(require,module,exports){ 818 | /*jslint node: true, indent: 2, nomen:true, evil: true */ 819 | 'use strict'; 820 | 821 | var defaults = { 822 | indent: ' ', 823 | dontUseWhitespaces: false, 824 | shortArray: false, 825 | bracketsNewLine: true, 826 | forceNamespaceBrackets: false, 827 | collapseEmptyLines: true 828 | }; 829 | 830 | function CodeGen(options) { 831 | 832 | // Get options 833 | this.options = Object.assign({}, defaults, options); 834 | this.ws = this.options.dontUseWhitespaces ? '' : ' '; 835 | this.indent = typeof this.options.indent === 'string' ? this.options.indent : ' '; 836 | this.nl = this.indent !== '' ? '\n' : ''; 837 | this.shortArray = this.options.shortArray || false; 838 | this.forceNamespaceBrackets = this.options.forceNamespaceBrackets || false; 839 | 840 | this.process = function (node, indent) { 841 | var err; 842 | 843 | if (node === null) { 844 | return indent; 845 | } 846 | 847 | if (node && node.kind) { 848 | if (typeof this[node.kind] === 'function') { 849 | return this[node.kind](node, indent); 850 | } 851 | err = new Error( 852 | 'Unhandled node type [' + node.kind + ']' + ( 853 | node.loc ? ' at line ' + node.loc.start.line : '' 854 | ) 855 | ); 856 | } else { 857 | console.log('Node:', node); 858 | console.log('Node kind:', node.kind); 859 | err = new Error('Bad AST structure'); 860 | } 861 | err.node = node; 862 | throw err; 863 | }; 864 | } 865 | 866 | module.exports = CodeGen; 867 | 868 | // node translators 869 | CodeGen.prototype.array = require("./array.js"); 870 | CodeGen.prototype.assign = require("./assign.js"); 871 | CodeGen.prototype.bin = require("./bin.js"); 872 | CodeGen.prototype.block = require("./block.js"); 873 | CodeGen.prototype.boolean = require("./boolean.js"); 874 | CodeGen.prototype.break = require("./break.js"); 875 | CodeGen.prototype.call = require("./call.js"); 876 | CodeGen.prototype.cast = require("./cast.js"); 877 | CodeGen.prototype.classconstant = require("./classconstant.js"); 878 | CodeGen.prototype.class = require("./class.js"); 879 | CodeGen.prototype.clone = require("./clone.js"); 880 | CodeGen.prototype.closure = require("./closure.js"); 881 | CodeGen.prototype.constant = require("./constant.js"); 882 | CodeGen.prototype.constref = require("./constref.js"); 883 | CodeGen.prototype.continue = require("./continue.js"); 884 | CodeGen.prototype.declare = require("./declare.js"); 885 | CodeGen.prototype.doc = require("./doc.js"); 886 | CodeGen.prototype.do = require("./do.js"); 887 | CodeGen.prototype.echo = require("./echo.js"); 888 | CodeGen.prototype.empty = require("./empty.js"); 889 | CodeGen.prototype.encapsed = require("./encapsed.js"); 890 | CodeGen.prototype.eval = require("./eval.js"); 891 | CodeGen.prototype.exit = require("./exit.js"); 892 | CodeGen.prototype.foreach = require("./foreach.js"); 893 | CodeGen.prototype.for = require("./for.js"); 894 | CodeGen.prototype.function = require("./function.js"); 895 | CodeGen.prototype.global = require("./global.js"); 896 | CodeGen.prototype.goto = require("./goto.js"); 897 | CodeGen.prototype.identifier = require("./identifier.js"); 898 | CodeGen.prototype.if = require("./if.js"); 899 | CodeGen.prototype.include = require("./include.js"); 900 | CodeGen.prototype.inline = require("./inline.js"); 901 | CodeGen.prototype.interface = require("./interface.js"); 902 | CodeGen.prototype.isset = require("./isset.js"); 903 | CodeGen.prototype.label = require("./label.js"); 904 | CodeGen.prototype.list = require("./list.js"); 905 | CodeGen.prototype.magic = require("./magic.js"); 906 | CodeGen.prototype.method = require("./method.js"); 907 | CodeGen.prototype.namespace = require("./namespace.js"); 908 | CodeGen.prototype.new = require("./new.js"); 909 | CodeGen.prototype.nowdoc = require("./nowdoc.js"); 910 | CodeGen.prototype.number = require("./number.js"); 911 | CodeGen.prototype.offsetlookup = require("./offsetlookup.js"); 912 | CodeGen.prototype.parenthesis = require("./parenthesis.js"); 913 | CodeGen.prototype.post = require("./post.js"); 914 | CodeGen.prototype.pre = require("./pre.js"); 915 | CodeGen.prototype.print = require("./print.js"); 916 | CodeGen.prototype.program = require("./program.js"); 917 | CodeGen.prototype.property = require("./property.js"); 918 | CodeGen.prototype.propertylookup = require("./propertylookup.js"); 919 | CodeGen.prototype.retif = require("./retif.js"); 920 | CodeGen.prototype.return = require("./return.js"); 921 | CodeGen.prototype.silent = require("./silent.js"); 922 | CodeGen.prototype.static = require("./static.js"); 923 | CodeGen.prototype.staticlookup = require("./staticlookup.js"); 924 | CodeGen.prototype.string = require("./string.js"); 925 | CodeGen.prototype.switch = require("./switch.js"); 926 | CodeGen.prototype.throw = require("./throw.js"); 927 | CodeGen.prototype.trait = require("./trait.js"); 928 | CodeGen.prototype.traituse = require("./traituse.js"); 929 | CodeGen.prototype.try = require("./try.js"); 930 | CodeGen.prototype.unary = require("./unary.js"); 931 | CodeGen.prototype.unset = require("./unset.js"); 932 | CodeGen.prototype.usegroup = require("./usegroup.js"); 933 | CodeGen.prototype.variable = require("./variable.js"); 934 | CodeGen.prototype.variadic = require("./variadic.js"); 935 | CodeGen.prototype.while = require("./while.js"); 936 | CodeGen.prototype.yieldfrom = require("./yieldfrom.js"); 937 | CodeGen.prototype.yield = require("./yield.js"); 938 | 939 | },{"./array.js":2,"./assign.js":3,"./bin.js":4,"./block.js":5,"./boolean.js":6,"./break.js":7,"./call.js":8,"./cast.js":9,"./class.js":10,"./classconstant.js":11,"./clone.js":12,"./closure.js":13,"./constant.js":14,"./constref.js":15,"./continue.js":16,"./declare.js":17,"./do.js":18,"./doc.js":19,"./echo.js":20,"./empty.js":21,"./encapsed.js":22,"./eval.js":23,"./exit.js":24,"./for.js":25,"./foreach.js":26,"./function.js":27,"./global.js":28,"./goto.js":29,"./identifier.js":34,"./if.js":35,"./include.js":36,"./inline.js":38,"./interface.js":39,"./isset.js":40,"./label.js":41,"./list.js":42,"./magic.js":43,"./method.js":44,"./namespace.js":45,"./new.js":46,"./nowdoc.js":47,"./number.js":48,"./offsetlookup.js":49,"./parenthesis.js":50,"./post.js":51,"./pre.js":52,"./print.js":53,"./program.js":54,"./property.js":55,"./propertylookup.js":56,"./retif.js":57,"./return.js":58,"./silent.js":59,"./static.js":60,"./staticlookup.js":61,"./string.js":62,"./switch.js":63,"./throw.js":64,"./trait.js":65,"./traituse.js":66,"./try.js":67,"./unary.js":68,"./unset.js":69,"./usegroup.js":70,"./variable.js":71,"./variadic.js":72,"./while.js":73,"./yield.js":74,"./yieldfrom.js":75}],38:[function(require,module,exports){ 940 | /*jslint node: true, indent: 2 */ 941 | 'use strict'; 942 | 943 | module.exports = function (node) { 944 | return '?>' + node.value + ' 0) { 1106 | str += params(node.arguments, indent, this); 1107 | } 1108 | str += ')'; 1109 | return 'new ' + str; 1110 | }; 1111 | 1112 | },{"./helper/parameters":33}],47:[function(require,module,exports){ 1113 | /*jslint node: true, indent: 2, unparam:true */ 1114 | 'use strict'; 1115 | 1116 | module.exports = function (node) { 1117 | return '<<<\'' + node.label + '\'' + this.nl + node.value + this.nl + node.label; 1118 | }; 1119 | 1120 | },{}],48:[function(require,module,exports){ 1121 | /*jslint node: true, indent: 2 */ 1122 | 'use strict'; 1123 | 1124 | module.exports = function (node) { 1125 | return node.value.toString(); 1126 | }; 1127 | 1128 | },{}],49:[function(require,module,exports){ 1129 | /*jslint node: true, indent: 2 */ 1130 | 'use strict'; 1131 | 1132 | module.exports = function (node, indent) { 1133 | var codegen, offset; 1134 | codegen = this.process.bind(this); 1135 | offset = node.offset ? codegen(node.offset, indent) : ''; 1136 | return codegen(node.what, indent) + '[' + offset + ']'; 1137 | }; 1138 | 1139 | },{}],50:[function(require,module,exports){ 1140 | /*jslint node: true, indent: 2 */ 1141 | 'use strict'; 1142 | 1143 | module.exports = function (node, indent) { 1144 | var codegen = this.process.bind(this); 1145 | return '(' + codegen(node.inner, indent) + ')'; 1146 | }; 1147 | 1148 | },{}],51:[function(require,module,exports){ 1149 | /*jslint node: true, indent: 2 */ 1150 | 'use strict'; 1151 | 1152 | module.exports = function (node, indent) { 1153 | var codegen = this.process.bind(this); 1154 | return codegen(node.what, indent) + node.type + node.type; 1155 | }; 1156 | 1157 | },{}],52:[function(require,module,exports){ 1158 | /*jslint node: true, indent: 2 */ 1159 | 'use strict'; 1160 | 1161 | module.exports = function (node, indent) { 1162 | var codegen = this.process.bind(this); 1163 | return node.type + node.type + codegen(node.what, indent); 1164 | }; 1165 | 1166 | },{}],53:[function(require,module,exports){ 1167 | /*jslint node: true, indent: 2 */ 1168 | 'use strict'; 1169 | 1170 | module.exports = function (node, indent) { 1171 | var codegen = this.process.bind(this); 1172 | return 'print ' + codegen(node.arguments, indent); 1173 | }; 1174 | 1175 | },{}],54:[function(require,module,exports){ 1176 | /*jslint node: true, indent: 2 */ 1177 | 'use strict'; 1178 | 1179 | var doBody = require('./helper/body'); 1180 | 1181 | module.exports = function (node) { 1182 | 1183 | if (!node.children || node.children.length === 0) { 1184 | return ''; 1185 | } 1186 | 1187 | var codegen = this.process.bind(this), str = '' + prop; 1245 | }; 1246 | 1247 | },{}],57:[function(require,module,exports){ 1248 | /*jslint node: true, indent: 2 */ 1249 | 'use strict'; 1250 | 1251 | module.exports = function (node, indent) { 1252 | var codegen, left, right = ''; 1253 | codegen = this.process.bind(this); 1254 | if (node.trueExpr) { 1255 | left = codegen(node.trueExpr, indent); 1256 | } 1257 | if (node.falseExpr) { 1258 | right = codegen(node.falseExpr, indent); 1259 | } 1260 | return codegen(node.test, indent) + this.ws + '?' + 1261 | (left ? this.ws + left + this.ws : '') + ':' + 1262 | (right ? this.ws + right : ''); 1263 | }; 1264 | 1265 | },{}],58:[function(require,module,exports){ 1266 | /*jslint node: true, indent: 2 */ 1267 | 'use strict'; 1268 | 1269 | module.exports = function (node, indent) { 1270 | var codegen; 1271 | 1272 | if (!node.expr) { 1273 | return 'return'; 1274 | } 1275 | 1276 | codegen = this.process.bind(this); 1277 | return 'return ' + codegen(node.expr, indent); 1278 | }; 1279 | 1280 | },{}],59:[function(require,module,exports){ 1281 | /*jslint node: true, indent: 2 */ 1282 | 'use strict'; 1283 | 1284 | module.exports = function (node, indent) { 1285 | var codegen = this.process.bind(this); 1286 | 1287 | return '@' + codegen(node.expr, indent); 1288 | }; 1289 | 1290 | },{}],60:[function(require,module,exports){ 1291 | /*jslint node: true, indent: 2 */ 1292 | 'use strict'; 1293 | 1294 | module.exports = function (node, indent) { 1295 | var codegen = this.process.bind(this); 1296 | return 'static ' + node.items.map(function (x) { 1297 | return codegen(x, indent); 1298 | }).join(',' + this.ws); 1299 | }; 1300 | 1301 | },{}],61:[function(require,module,exports){ 1302 | /*jslint node: true, indent: 2 */ 1303 | 'use strict'; 1304 | 1305 | module.exports = function (node, indent) { 1306 | var codegen = this.process.bind(this); 1307 | return codegen(node.what, indent) + '::' + codegen(node.offset, indent); 1308 | }; 1309 | 1310 | },{}],62:[function(require,module,exports){ 1311 | /*jslint node: true, indent: 2, unparam:true */ 1312 | 'use strict'; 1313 | 1314 | module.exports = function (node, indent, opt) { 1315 | opt = opt || {}; 1316 | if (opt.raw) { 1317 | return node.value; 1318 | } 1319 | return JSON.stringify(node.value).replace(/\$/g, '\\$'); 1320 | }; 1321 | 1322 | },{}],63:[function(require,module,exports){ 1323 | /*jslint node: true, indent: 2 */ 1324 | 'use strict'; 1325 | 1326 | var doBody = require('./helper/body'); 1327 | 1328 | module.exports = function (node, indent) { 1329 | var codegen, str, that = this, cases; 1330 | 1331 | codegen = this.process.bind(this); 1332 | str = 'switch' + this.ws + '(' + codegen(node.test, indent) + ')'; 1333 | if (node.shortForm) { 1334 | str += ':' + this.nl; 1335 | } else { 1336 | str += this.ws + '{' + this.nl; 1337 | } 1338 | cases = node.body.children.map(function (item) { 1339 | var head; 1340 | if (item.test) { 1341 | head = indent + that.indent + 'case ' + codegen(item.test, indent) + ':' + that.nl; 1342 | } else { 1343 | head = indent + that.indent + 'default:' + that.nl; 1344 | } 1345 | if (item.body) { 1346 | head += doBody.call(that, codegen, indent + that.indent, item.body.children || [item.body]); 1347 | } 1348 | return head; 1349 | }); 1350 | str += cases.join(''); 1351 | if (node.shortForm) { 1352 | str += indent + 'endswitch;'; 1353 | } else { 1354 | str += indent + '}'; 1355 | } 1356 | return str; 1357 | }; 1358 | 1359 | },{"./helper/body":31}],64:[function(require,module,exports){ 1360 | /*jslint node: true, indent: 2 */ 1361 | 'use strict'; 1362 | 1363 | module.exports = function (node, indent) { 1364 | var codegen = this.process.bind(this); 1365 | return 'throw ' + codegen(node.what, indent); 1366 | }; 1367 | 1368 | },{}],65:[function(require,module,exports){ 1369 | /*jslint node: true, indent: 2 */ 1370 | 'use strict'; 1371 | var doBody = require('./helper/body'); 1372 | var identifier = require('./helper/identifier'); 1373 | 1374 | module.exports = function (node, indent) { 1375 | var codegen, str; 1376 | codegen = this.process.bind(this); 1377 | 1378 | str = 'trait ' + node.name; 1379 | 1380 | if (node.extends) { 1381 | str += ' extends ' + identifier(node.extends); 1382 | } 1383 | 1384 | if (node.implements) { 1385 | str += ' implements ' + node.implements.map(identifier).join(',' + this.ws); 1386 | } 1387 | 1388 | // begin curly brace 1389 | if (this.options.bracketsNewLine) { 1390 | str += this.nl + indent + '{' + this.nl; 1391 | } else { 1392 | str += this.ws + '{' + this.nl; 1393 | } 1394 | 1395 | // trait body 1396 | str += doBody.call(this, codegen, indent, node.body); 1397 | 1398 | // end curly brace 1399 | str += indent + '}\n'; 1400 | 1401 | return str; 1402 | }; 1403 | 1404 | },{"./helper/body":31,"./helper/identifier":32}],66:[function(require,module,exports){ 1405 | /*jslint node: true, indent: 2 */ 1406 | 'use strict'; 1407 | 1408 | var identifier = require('./helper/identifier'); 1409 | 1410 | /** 1411 | * Usage declaration 1412 | */ 1413 | module.exports = function (node, indent) { 1414 | var str = 'use' + this.ws, items = [], glue, codegen; 1415 | codegen = this.process.bind(this); 1416 | node.traits.forEach(function (item) { 1417 | items.push( 1418 | codegen(item, indent) 1419 | ); 1420 | }); 1421 | str += items.join(',' + this.ws); 1422 | if (node.adaptations) { 1423 | glue = this.nl + indent + this.indent; 1424 | str += this.ws + '{' + glue; 1425 | str += node.adaptations.map(function (item) { 1426 | var out = ''; 1427 | if (item.trait) { 1428 | out += codegen(item.trait, indent) + '::'; 1429 | } 1430 | if (item.method) { 1431 | out += item.method; 1432 | } 1433 | if (item.kind === 'traitprecedence') { 1434 | out += ' insteadof ';// + codegen(item.insteadof); 1435 | out += item.instead.map(identifier).join(', '); 1436 | } else { 1437 | out += ' as '; 1438 | if (item.visibility) { 1439 | out += item.visibility + ' '; 1440 | } 1441 | out += item.as; 1442 | } 1443 | return out + ';'; 1444 | }).join(glue) + this.nl; 1445 | str += indent + '}'; 1446 | } else { 1447 | str += ';'; 1448 | } 1449 | return str + this.nl; 1450 | }; 1451 | 1452 | },{"./helper/identifier":32}],67:[function(require,module,exports){ 1453 | /*jslint node: true, indent: 2 */ 1454 | 'use strict'; 1455 | 1456 | var doBody = require('./helper/body'); 1457 | var identifier = require('./helper/identifier'); 1458 | 1459 | function resolveExceptions(items) { 1460 | var result = [], i; 1461 | for (i = 0; i < items.length; i += 1) { 1462 | result.push(identifier(items[i])); 1463 | } 1464 | return result.join('|'); 1465 | } 1466 | 1467 | module.exports = function (node, indent) { 1468 | var codegen, str; 1469 | 1470 | 1471 | codegen = this.process.bind(this); 1472 | str = 'try' + this.ws + '{' + this.nl; 1473 | str += doBody.call(this, codegen, indent, node.body.children); 1474 | str += indent + '}'; 1475 | 1476 | str += node.catches.map(function (except) { 1477 | var out = this.ws + 'catch' + this.ws + '(' + resolveExceptions(except.what) + ' ' + codegen(except.variable) + ')' + this.ws + '{' + this.nl; 1478 | out += doBody.call(this, codegen, indent, except.body.children); 1479 | out += indent + '}'; 1480 | return out; 1481 | }, this).join(''); 1482 | 1483 | if (node.always) { 1484 | str += this.ws + 'finally' + this.ws + '{' + this.nl; 1485 | str += doBody.call(this, codegen, indent, node.always.children); 1486 | str += indent + '}'; 1487 | } 1488 | 1489 | return str; 1490 | }; 1491 | 1492 | },{"./helper/body":31,"./helper/identifier":32}],68:[function(require,module,exports){ 1493 | /*jslint node: true, indent: 2 */ 1494 | 'use strict'; 1495 | 1496 | module.exports = function (node, indent) { 1497 | var codegen = this.process.bind(this); 1498 | return node.type + codegen(node.what, indent); 1499 | }; 1500 | 1501 | },{}],69:[function(require,module,exports){ 1502 | /*jslint node: true, indent: 2 */ 1503 | 'use strict'; 1504 | 1505 | var params = require('./helper/parameters'); 1506 | 1507 | module.exports = function (node, indent) { 1508 | return 'unset(' + params(node.arguments, indent, this) + ')'; 1509 | }; 1510 | 1511 | },{"./helper/parameters":33}],70:[function(require,module,exports){ 1512 | /*jslint node: true, indent: 2 */ 1513 | 'use strict'; 1514 | 1515 | /** 1516 | * Usage declaration 1517 | */ 1518 | module.exports = function (node, indent) { 1519 | var str = 'use' + this.ws, items = [], glue; 1520 | if (node.type) { 1521 | str += node.type + this.ws; 1522 | } 1523 | node.items.forEach(function (item) { 1524 | var useItem = item.name; 1525 | if (item.alias) { 1526 | useItem += ' as ' + item.alias; 1527 | } 1528 | useItem += ';'; 1529 | items.push(useItem); 1530 | }); 1531 | if (node.items.length > 1) { 1532 | glue = this.nl + indent + this.indent; 1533 | str += node.name + this.ws + '{' + glue; 1534 | str += items.join(glue) + this.nl; 1535 | str += indent + '};' + this.nl; 1536 | } else { 1537 | str += items[0] + this.nl; 1538 | } 1539 | return str; 1540 | }; 1541 | 1542 | },{}],71:[function(require,module,exports){ 1543 | /*jslint node: true, indent: 2 */ 1544 | 'use strict'; 1545 | 1546 | module.exports = function (node, indent) { 1547 | if (typeof node.name !== 'string') { 1548 | var codegen = this.process.bind(this); 1549 | node.name = codegen(node.name, indent); 1550 | } 1551 | return (node.byref ? '&$' : '$') + node.name; 1552 | }; 1553 | 1554 | },{}],72:[function(require,module,exports){ 1555 | /*jslint node: true, indent: 2 */ 1556 | 'use strict'; 1557 | 1558 | module.exports = function (node, indent) { 1559 | var codegen = this.process.bind(this); 1560 | return '...' + codegen(node.what, indent); 1561 | }; 1562 | 1563 | },{}],73:[function(require,module,exports){ 1564 | /*jslint node: true, indent: 2 */ 1565 | 'use strict'; 1566 | 1567 | var doBody = require('./helper/body'); 1568 | 1569 | module.exports = function (node, indent) { 1570 | var codegen = this.process.bind(this), str; 1571 | 1572 | str = 'while' + this.ws + '(' + codegen(node.test, indent) + ')'; 1573 | if (node.shortForm) { 1574 | str += ':' + this.nl; 1575 | } else { 1576 | str += this.ws + '{' + this.nl; 1577 | } 1578 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 1579 | if (node.shortForm) { 1580 | str += indent + 'endwhile;'; 1581 | } else { 1582 | str += indent + '}'; 1583 | } 1584 | return str; 1585 | }; 1586 | 1587 | },{"./helper/body":31}],74:[function(require,module,exports){ 1588 | /*jslint node: true, indent: 2 */ 1589 | 'use strict'; 1590 | 1591 | module.exports = function (node, indent) { 1592 | var codegen, str; 1593 | str = 'yield'; 1594 | if (node.value) { 1595 | codegen = this.process.bind(this); 1596 | if (node.key) { 1597 | // yield $key => $value 1598 | str += ' ' + codegen(node.key, indent) + ' =>'; 1599 | } 1600 | // yield $value 1601 | str += ' ' + codegen(node.value, indent); 1602 | } 1603 | return str; 1604 | }; 1605 | 1606 | },{}],75:[function(require,module,exports){ 1607 | /*jslint node: true, indent: 2 */ 1608 | 'use strict'; 1609 | 1610 | module.exports = function (node, indent) { 1611 | var codegen = this.process.bind(this); 1612 | return 'yield from ' + codegen(node.value, indent); 1613 | }; 1614 | 1615 | },{}]},{},[1])(1) 1616 | }); -------------------------------------------------------------------------------- /dist/php-unparser.min.js: -------------------------------------------------------------------------------- 1 | (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.phpUnparser=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i"+that.ws+value}return value}}elements=node.items.map(processElement(indent));if(elements.join().length>80){space=that.nl+indent+this.indent;elements=node.items.map(processElement(indent+this.indent));body=space+elements.join(","+space)+that.nl+indent}else{body=elements.join(","+that.ws)}if(node.shortForm||this.shortArray){return"["+body+"]"}return"array("+body+")"}},{}],3:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return codegen(node.left,indent)+this.ws+node.operator+this.ws+codegen(node.right,indent)}},{}],4:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen,str,firstpart,secondpart;codegen=this.process.bind(this);firstpart=codegen(node.left,indent);secondpart=codegen(node.right,indent);str=firstpart+this.ws+node.type+this.ws+secondpart;if(str.length>80){str=firstpart+this.ws+node.type+this.nl+indent+this.indent+secondpart}return str}},{}],5:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str="";codegen=this.process.bind(this);str+=this.nl+indent+"{"+this.nl;str+=doBody.call(this,codegen,indent,node.children);str+=indent+"}"+this.nl;return str}},{"./helper/body":31}],6:[function(require,module,exports){"use strict";module.exports=function(node){return node.value?"true":"false"}},{}],7:[function(require,module,exports){"use strict";module.exports=function(node,indent){if(node.level){var codegen=this.process.bind(this);return"break "+codegen(node.level,indent)}return"break"}},{}],8:[function(require,module,exports){"use strict";var params=require("./helper/parameters");module.exports=function(node,indent){var codegen=this.process.bind(this);return codegen(node.what,indent)+"("+params(node.arguments,indent,this)+")"}},{"./helper/parameters":33}],9:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen;codegen=this.process.bind(this);return"("+node.type+")"+codegen(node.what,indent)}},{}],10:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str,that;codegen=this.process.bind(this);str="";that=this;if(node.isAbstract){str+="abstract "}else if(node.isFinal){str+="final "}str+="class";if(node.name){str+=" "+node.name}if(node.extends){str+=" extends "+codegen(node.extends,indent)}if(node.implements){str+=" implements "+node.implements.map(function(x){return codegen(x,indent)}).join(","+that.ws)}if(node.name){if(this.options.bracketsNewLine){str+=this.nl+indent+"{"+this.nl}else{str+=this.ws+"{"+this.nl}}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body);str+=indent+"}";if(node.name){str+=this.nl}return str}},{"./helper/body":31}],11:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen,str="";codegen=this.process.bind(this);if(node.visibility){str+=node.visibility+" "}str+="const ";str+=node.name;if(node.value){str+=this.ws+"="+this.ws;str+=codegen(node.value,indent)}return str}},{}],12:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen;codegen=this.process.bind(this);return"clone "+codegen(node.what,indent)}},{}],13:[function(require,module,exports){"use strict";var doBody=require("./helper/body");var args=require("./helper/arguments");var identifier=require("./helper/identifier");module.exports=function(node,indent){var codegen,str,useArgs;codegen=this.process.bind(this);str="function"+this.ws;if(node.byref){str+="&"}str+=args(node.arguments,indent,this);if(node.uses&&node.uses.length>0){useArgs=node.uses.map(function(arg){return"$"+arg.name});str+=this.ws+"use"+this.ws+"("+useArgs.join(","+this.ws)+")"}if(node.type){str+=this.ws+":"+this.ws;if(node.nullable){str+="?"}str+=identifier(node.type)}str+=this.ws+"{"+this.nl;str+=doBody.call(this,codegen,indent,node.body.children);str+=indent+"}";return str}},{"./helper/arguments":30,"./helper/body":31,"./helper/identifier":32}],14:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen,str;codegen=this.process.bind(this);str="const ";str+=node.name;str+=this.ws+"="+this.ws;str+=codegen(node.value,indent);return str}},{}],15:[function(require,module,exports){"use strict";var identifier=require("./helper/identifier");module.exports=function(node){if(typeof node.name==="string"){return identifier(node)}return identifier(node.name)}},{"./helper/identifier":32}],16:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);if(node.level){return"continue "+codegen(node.level,indent)}return"continue"}},{}],17:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str,items=[],k;codegen=this.process.bind(this);for(k in node.what){if(node.what.hasOwnProperty(k)&&node.what[k]){items.push(k+this.ws+"="+this.ws+codegen(node.what[k]))}}str="declare("+items.join(","+this.ws)+")";if(node.mode!=="none"){str+=this.ws+"{"+this.nl;str+=doBody.call(this,codegen,indent,node.children);str+=indent+"}"+this.nl}else{str+=";"+this.nl;str+=doBody.call(this,codegen,indent,node.children,true)}return str}},{"./helper/body":31}],18:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str;codegen=this.process.bind(this);str="do"+this.ws+"{"+this.nl;str+=doBody.call(this,codegen,indent,node.body.children);str+=indent+"}"+this.ws+"while"+this.ws+"("+codegen(node.test,indent)+")";return str}},{"./helper/body":31}],19:[function(require,module,exports){"use strict";module.exports=function(node,indent){var self=this,union,body;if(node.alreadyParsed){return""}if(node.isDoc){body=node.lines.join(this.nl+indent+" * ");if(body.substring(body.length-3)===" * "){body=body.substring(0,body.length-3)}return this.nl+indent+"/** "+body+" */"}union=self.nl+indent+self.ws+self.ws;return node.lines.reduce(function(acc,line){if(line.indexOf("\n")>-1){return acc.concat("/*"+line.split("\n").join(union)+"*/")}return acc.concat("// "+line)},[]).join(self.nl+indent)}},{}],20:[function(require,module,exports){"use strict";var params=require("./helper/parameters");module.exports=function(node,indent){var str=params(node.arguments,indent,this);if(node.isInlineEcho){return str+this.ws+"?>"}return"echo "+str}},{"./helper/parameters":33}],21:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"empty("+codegen(node.arguments[0],indent)+")"}},{}],22:[function(require,module,exports){"use strict";module.exports=function(node,indent,opt){var body="",codegen=this.process.bind(this);node.value.forEach(function(item){if(item.kind==="string"){body+=item.value}else{body+="{"+codegen(item,indent)+"}"}});if(node.type==="heredoc"){return"<<<"+node.label+this.nl+body+node.label}if(node.type==="nowdoc"){return"<<<'"+node.label+"'"+this.nl+body+node.label}if(node.type==="shell"){return"`"+body+"`"}if(node.isDoubleQuote){return'"'+body+'"'}return"'"+body+"'"}},{}],23:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"eval("+codegen(node.source,indent)+")"}},{}],24:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen;codegen=this.process.bind(this);if(node.status===null){return"exit"}return"exit("+codegen(node.status,indent)+")"}},{}],25:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str;codegen=this.process.bind(this);str="for"+this.ws+"(";if(node.init){str+=node.init.map(function(x){if(x){return codegen(x,indent)}return""}).join(","+this.ws)}str+=";"+this.ws;if(node.test){str+=node.test.map(function(x){if(x){return codegen(x,indent)}return""}).join(","+this.ws)}str+=";"+this.ws;if(node.increment){str+=node.increment.map(function(x){if(x){return codegen(x,indent)}return""}).join(","+this.ws)}str+=")";if(this.shortForm){str+=":"+this.nl}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body.children||[node.body]);if(this.shortForm){str+=indent+"endfor;"}else{str+=indent+"}"}return str}},{"./helper/body":31}],26:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str;codegen=this.process.bind(this);str="foreach"+this.ws+"("+codegen(node.source,indent)+this.ws+"as"+this.ws;if(node.key){str+=codegen(node.key,indent)+this.ws+"=>"+this.ws}str+=codegen(node.value,indent)+")";if(node.shortForm){str+=":"+this.nl}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body.children||[node.body]);if(node.shortForm){str+=indent+"endforeach;"}else{str+=indent+"}"}return str}},{"./helper/body":31}],27:[function(require,module,exports){"use strict";var doBody=require("./helper/body");var args=require("./helper/arguments");var identifier=require("./helper/identifier");module.exports=function(node,indent){var codegen,str;codegen=this.process.bind(this);str="function ";if(node.byref){str+="&"}str+=node.name;str+=args(node.arguments,indent,this);if(node.type){str+=this.ws+":"+this.ws;if(node.nullable){str+="?"}str+=identifier(node.type)}if(this.options.bracketsNewLine){str+=this.nl+indent+"{"+this.nl}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body.children);str+=indent+"}"+this.nl;return str}},{"./helper/arguments":30,"./helper/body":31,"./helper/identifier":32}],28:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"global "+node.items.map(function(x){return codegen(x,indent)}).join(","+this.ws)}},{}],29:[function(require,module,exports){"use strict";module.exports=function(node){return"goto "+node.label}},{}],30:[function(require,module,exports){"use strict";function processElement(indent,ws,codegen){return function(arg){var str="";if(arg.nullable){str+="?"}if(arg.type){str+=codegen(arg.type,indent)+ws}if(arg.byref){str+="&"}if(arg.variadic){str+="..."}str+="$"+arg.name;if(arg.value){str+=ws+"="+ws+codegen(arg.value,indent)}return str}}module.exports=function(nodes,indent,self){var codegen,args,space,listArgs;codegen=self.process.bind(self);args=nodes.map(processElement(indent,self.ws,codegen));listArgs=args.join(","+self.ws);if(listArgs.length>80){space=self.nl+indent+self.indent;args=nodes.map(processElement(indent+self.indent,self.ws,codegen));listArgs=space+args.join(","+space)+self.nl+indent}return"("+listArgs+")"}},{}],31:[function(require,module,exports){"use strict";var noSemiColons=["class","interface","trait","namespace","try","if","switch","for","foreach","function","method","while","doc","comment","label","declare","usegroup","traituse","inline","block"];module.exports=function(codegen,currentIndent,body,isProgram,dontIncreaseIndent){var str="",expr,i,indentation,delimiter,that=this,line,next,after,dontUseNewLine,isInlineEcho;delimiter=that.options.collapseEmptyLines?"":"\n";if(dontIncreaseIndent){indentation=currentIndent}else{indentation=isProgram?"":currentIndent+that.indent}if(!Array.isArray(body)){body=[body]}for(i=0;i0){useArgs=args.map(processElement(indent))}raw=useArgs.join();if(raw.indexOf("\n")>-1&&raw.substr(0,raw.indexOf("\n")).length>80||raw.indexOf("\n")===-1&&raw.length>80){useArgs=args.map(processElement(indent+self.indent));space=self.nl+indent+self.indent;args=space+useArgs.join(","+space)+self.nl+indent}else{args=useArgs.join(","+self.ws)}return args}},{}],34:[function(require,module,exports){"use strict";module.exports=function(node){if(node.resolution==="rn"){return"namespace\\"+node.name}return node.name}},{}],35:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function processIf(node,indent,inner){var codegen,str,that=this;codegen=this.process.bind(this);str="if"+this.ws+"("+codegen(node.test,indent)+")";if(node.body){if(node.shortForm){str+=":"+this.nl}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body.children||[node.body]);if(!node.shortForm){str+=indent+"}"}}else if(!node.alternate){return str+";"}if(node.alternate){str+=function(){var out="";if(node.alternate.kind==="if"){if(node.shortForm){return indent+"else"+processIf.call(that,node.alternate,indent,true)}return that.ws+"else"+processIf.call(that,node.alternate,indent,true)}if(node.shortForm){out+=indent+"else:"+that.nl}else{out+=that.ws+"else"+that.ws+"{"+that.nl}out+=doBody.call(that,codegen,indent,node.alternate.children||[node.alternate]);if(!node.shortForm){out+=indent+"}"+that.nl}return out}()}if(node.shortForm&&!inner){str+=indent+"endif;"+this.nl}return str}},{"./helper/body":31}],36:[function(require,module,exports){"use strict";module.exports=function(node,indent){var str,codegen;str=node.require?"require":"include";if(node.once){str+="_once"}codegen=this.process.bind(this);return str+" "+codegen(node.target,indent)}},{}],37:[function(require,module,exports){"use strict";var defaults={indent:" ",dontUseWhitespaces:false,shortArray:false,bracketsNewLine:true,forceNamespaceBrackets:false,collapseEmptyLines:true};function CodeGen(options){this.options=Object.assign({},defaults,options);this.ws=this.options.dontUseWhitespaces?"":" ";this.indent=typeof this.options.indent==="string"?this.options.indent:" ";this.nl=this.indent!==""?"\n":"";this.shortArray=this.options.shortArray||false;this.forceNamespaceBrackets=this.options.forceNamespaceBrackets||false;this.process=function(node,indent){var err;if(node===null){return indent}if(node&&node.kind){if(typeof this[node.kind]==="function"){return this[node.kind](node,indent)}err=new Error("Unhandled node type ["+node.kind+"]"+(node.loc?" at line "+node.loc.start.line:""))}else{console.log("Node:",node);console.log("Node kind:",node.kind);err=new Error("Bad AST structure")}err.node=node;throw err}}module.exports=CodeGen;CodeGen.prototype.array=require("./array.js");CodeGen.prototype.assign=require("./assign.js");CodeGen.prototype.bin=require("./bin.js");CodeGen.prototype.block=require("./block.js");CodeGen.prototype.boolean=require("./boolean.js");CodeGen.prototype.break=require("./break.js");CodeGen.prototype.call=require("./call.js");CodeGen.prototype.cast=require("./cast.js");CodeGen.prototype.classconstant=require("./classconstant.js");CodeGen.prototype.class=require("./class.js");CodeGen.prototype.clone=require("./clone.js");CodeGen.prototype.closure=require("./closure.js");CodeGen.prototype.constant=require("./constant.js");CodeGen.prototype.constref=require("./constref.js");CodeGen.prototype.continue=require("./continue.js");CodeGen.prototype.declare=require("./declare.js");CodeGen.prototype.doc=require("./doc.js");CodeGen.prototype.do=require("./do.js");CodeGen.prototype.echo=require("./echo.js");CodeGen.prototype.empty=require("./empty.js");CodeGen.prototype.encapsed=require("./encapsed.js");CodeGen.prototype.eval=require("./eval.js");CodeGen.prototype.exit=require("./exit.js");CodeGen.prototype.foreach=require("./foreach.js");CodeGen.prototype.for=require("./for.js");CodeGen.prototype.function=require("./function.js");CodeGen.prototype.global=require("./global.js");CodeGen.prototype.goto=require("./goto.js");CodeGen.prototype.identifier=require("./identifier.js");CodeGen.prototype.if=require("./if.js");CodeGen.prototype.include=require("./include.js");CodeGen.prototype.inline=require("./inline.js");CodeGen.prototype.interface=require("./interface.js");CodeGen.prototype.isset=require("./isset.js");CodeGen.prototype.label=require("./label.js");CodeGen.prototype.list=require("./list.js");CodeGen.prototype.magic=require("./magic.js");CodeGen.prototype.method=require("./method.js");CodeGen.prototype.namespace=require("./namespace.js");CodeGen.prototype.new=require("./new.js");CodeGen.prototype.nowdoc=require("./nowdoc.js");CodeGen.prototype.number=require("./number.js");CodeGen.prototype.offsetlookup=require("./offsetlookup.js");CodeGen.prototype.parenthesis=require("./parenthesis.js");CodeGen.prototype.post=require("./post.js");CodeGen.prototype.pre=require("./pre.js");CodeGen.prototype.print=require("./print.js");CodeGen.prototype.program=require("./program.js");CodeGen.prototype.property=require("./property.js");CodeGen.prototype.propertylookup=require("./propertylookup.js");CodeGen.prototype.retif=require("./retif.js");CodeGen.prototype.return=require("./return.js");CodeGen.prototype.silent=require("./silent.js");CodeGen.prototype.static=require("./static.js");CodeGen.prototype.staticlookup=require("./staticlookup.js");CodeGen.prototype.string=require("./string.js");CodeGen.prototype.switch=require("./switch.js");CodeGen.prototype.throw=require("./throw.js");CodeGen.prototype.trait=require("./trait.js");CodeGen.prototype.traituse=require("./traituse.js");CodeGen.prototype.try=require("./try.js");CodeGen.prototype.unary=require("./unary.js");CodeGen.prototype.unset=require("./unset.js");CodeGen.prototype.usegroup=require("./usegroup.js");CodeGen.prototype.variable=require("./variable.js");CodeGen.prototype.variadic=require("./variadic.js");CodeGen.prototype.while=require("./while.js");CodeGen.prototype.yieldfrom=require("./yieldfrom.js");CodeGen.prototype.yield=require("./yield.js")},{"./array.js":2,"./assign.js":3,"./bin.js":4,"./block.js":5,"./boolean.js":6,"./break.js":7,"./call.js":8,"./cast.js":9,"./class.js":10,"./classconstant.js":11,"./clone.js":12,"./closure.js":13,"./constant.js":14,"./constref.js":15,"./continue.js":16,"./declare.js":17,"./do.js":18,"./doc.js":19,"./echo.js":20,"./empty.js":21,"./encapsed.js":22,"./eval.js":23,"./exit.js":24,"./for.js":25,"./foreach.js":26,"./function.js":27,"./global.js":28,"./goto.js":29,"./identifier.js":34,"./if.js":35,"./include.js":36,"./inline.js":38,"./interface.js":39,"./isset.js":40,"./label.js":41,"./list.js":42,"./magic.js":43,"./method.js":44,"./namespace.js":45,"./new.js":46,"./nowdoc.js":47,"./number.js":48,"./offsetlookup.js":49,"./parenthesis.js":50,"./post.js":51,"./pre.js":52,"./print.js":53,"./program.js":54,"./property.js":55,"./propertylookup.js":56,"./retif.js":57,"./return.js":58,"./silent.js":59,"./static.js":60,"./staticlookup.js":61,"./string.js":62,"./switch.js":63,"./throw.js":64,"./trait.js":65,"./traituse.js":66,"./try.js":67,"./unary.js":68,"./unset.js":69,"./usegroup.js":70,"./variable.js":71,"./variadic.js":72,"./while.js":73,"./yield.js":74,"./yieldfrom.js":75}],38:[function(require,module,exports){"use strict";module.exports=function(node){var str;str=node.omitClosingTag?"":"?>";str+=node.value;if(node.isInlineEcho){return str+"0){str+=params(node.arguments,indent,this)}str+=")"}return"new "+str}},{"./helper/parameters":33}],47:[function(require,module,exports){"use strict";module.exports=function(node){return"<<<'"+node.label+"'"+this.nl+node.value+this.nl+node.label}},{}],48:[function(require,module,exports){"use strict";module.exports=function(node){return node.value.toString()}},{}],49:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen,offset;codegen=this.process.bind(this);offset=node.offset?codegen(node.offset,indent):"";return codegen(node.what,indent)+"["+offset+"]"}},{}],50:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"("+codegen(node.inner,indent)+")"}},{}],51:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return codegen(node.what,indent)+node.type+node.type}},{}],52:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return node.type+node.type+codegen(node.what,indent)}},{}],53:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"print "+codegen(node.arguments,indent)}},{}],54:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node){if(!node.children||node.children.length===0){return""}var codegen=this.process.bind(this),str=""+prop}},{}],57:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen,left,right="";codegen=this.process.bind(this);if(node.trueExpr){left=codegen(node.trueExpr,indent)}if(node.falseExpr){right=codegen(node.falseExpr,indent)}return codegen(node.test,indent)+this.ws+"?"+(left?this.ws+left+this.ws:"")+":"+(right?this.ws+right:"")}},{}],58:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen;if(!node.expr){return"return"}codegen=this.process.bind(this);return"return "+codegen(node.expr,indent)}},{}],59:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"@"+codegen(node.expr,indent)}},{}],60:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"static "+node.items.map(function(x){return codegen(x,indent)}).join(","+this.ws)}},{}],61:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return codegen(node.what,indent)+"::"+codegen(node.offset,indent)}},{}],62:[function(require,module,exports){"use strict";module.exports=function(node,indent,opt){opt=opt||{};if(opt.raw){return node.value}return JSON.stringify(node.value).replace(/\$/g,"\\$")}},{}],63:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen,str,that=this,cases;codegen=this.process.bind(this);str="switch"+this.ws+"("+codegen(node.test,indent)+")";if(node.shortForm){str+=":"+this.nl}else{str+=this.ws+"{"+this.nl}cases=node.body.children.map(function(item){var head;if(item.test){head=indent+that.indent+"case "+codegen(item.test,indent)+":"+that.nl}else{head=indent+that.indent+"default:"+that.nl}if(item.body){head+=doBody.call(that,codegen,indent+that.indent,item.body.children||[item.body])}return head});str+=cases.join("");if(node.shortForm){str+=indent+"endswitch;"}else{str+=indent+"}"}return str}},{"./helper/body":31}],64:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"throw "+codegen(node.what,indent)}},{}],65:[function(require,module,exports){"use strict";var doBody=require("./helper/body");var identifier=require("./helper/identifier");module.exports=function(node,indent){var codegen,str;codegen=this.process.bind(this);str="trait "+node.name;if(node.extends){str+=" extends "+identifier(node.extends)}if(node.implements){str+=" implements "+node.implements.map(identifier).join(","+this.ws)}if(this.options.bracketsNewLine){str+=this.nl+indent+"{"+this.nl}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body);str+=indent+"}\n";return str}},{"./helper/body":31,"./helper/identifier":32}],66:[function(require,module,exports){"use strict";var identifier=require("./helper/identifier");module.exports=function(node,indent){var str="use"+this.ws,items=[],glue,codegen;codegen=this.process.bind(this);node.traits.forEach(function(item){items.push(codegen(item,indent))});str+=items.join(","+this.ws);if(node.adaptations){glue=this.nl+indent+this.indent;str+=this.ws+"{"+glue;str+=node.adaptations.map(function(item){var out="";if(item.trait){out+=codegen(item.trait,indent)+"::"}if(item.method){out+=item.method}if(item.kind==="traitprecedence"){out+=" insteadof ";out+=item.instead.map(identifier).join(", ")}else{out+=" as ";if(item.visibility){out+=item.visibility+" "}out+=item.as}return out+";"}).join(glue)+this.nl;str+=indent+"}"}else{str+=";"}return str+this.nl}},{"./helper/identifier":32}],67:[function(require,module,exports){"use strict";var doBody=require("./helper/body");var identifier=require("./helper/identifier");function resolveExceptions(items){var result=[],i;for(i=0;i1){glue=this.nl+indent+this.indent;str+=node.name+this.ws+"{"+glue;str+=items.join(","+glue)+this.nl;str+=indent+"};"+this.nl}else{str+=items[0]+";"+this.nl}return str}},{}],71:[function(require,module,exports){"use strict";module.exports=function(node,indent){if(typeof node.name!=="string"){var codegen=this.process.bind(this);node.name=codegen(node.name,indent)}return(node.byref?"&$":"$")+node.name}},{}],72:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"..."+codegen(node.what,indent)}},{}],73:[function(require,module,exports){"use strict";var doBody=require("./helper/body");module.exports=function(node,indent){var codegen=this.process.bind(this),str;str="while"+this.ws+"("+codegen(node.test,indent)+")";if(!node.body){return str}if(node.shortForm){str+=":"+this.nl}else{str+=this.ws+"{"+this.nl}str+=doBody.call(this,codegen,indent,node.body.children||[node.body]);if(node.shortForm){str+=indent+"endwhile;"}else{str+=indent+"}"}return str}},{"./helper/body":31}],74:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen,str;str="yield";if(node.value){codegen=this.process.bind(this);if(node.key){str+=" "+codegen(node.key,indent)+" =>"}str+=" "+codegen(node.value,indent)}return str}},{}],75:[function(require,module,exports){"use strict";module.exports=function(node,indent){var codegen=this.process.bind(this);return"yield from "+codegen(node.value,indent)}},{}]},{},[1])(1)}); -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | var unparse = require('../index.js'); 2 | 3 | // The AST object to parse 4 | var astClass = { 5 | "kind": "program", 6 | "children": [ 7 | { 8 | "kind": "class", 9 | "name": "Test", 10 | "body": [ 11 | { 12 | kind: 'property', 13 | name: 'foo', 14 | value: { 15 | kind: 'string', 16 | value: 'bar', 17 | isDoubleQuote: false 18 | }, 19 | visibility: 'public' 20 | }, 21 | { 22 | kind: 'method', 23 | name: 'foo', 24 | arguments: [], 25 | byref: false, 26 | type: null, 27 | nullable: false, 28 | body: { 29 | kind: 'block', 30 | children: [] 31 | }, 32 | isAbstract: false, 33 | isFinal: false, 34 | visibility: 'public', 35 | isStatic: false 36 | } 37 | ] 38 | } 39 | ], 40 | "errors": [] 41 | }; 42 | 43 | console.log( unparse(astClass, { 44 | indent: false, 45 | dontUseWhitespaces: false, 46 | shortArray: false, 47 | bracketsNewLine: false, 48 | forceNamespaceBrackets: false 49 | }) ); -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var CodeGen = require('./node_translators'); 5 | 6 | module.exports = function (ast, opts) { 7 | opts = opts || {}; 8 | var codeGen = new CodeGen(opts); 9 | return codeGen.process(ast, ''); 10 | }; 11 | -------------------------------------------------------------------------------- /node_translators/array.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen, elements, that, body, space; 6 | codegen = this.process.bind(this); 7 | that = this; 8 | 9 | function processElement(indent) { 10 | return function (ele) { 11 | var value = codegen(ele.value, indent); 12 | if (ele.key) { 13 | return codegen(ele.key, indent) + that.ws + '=>' + that.ws + value; 14 | } 15 | return value; 16 | }; 17 | } 18 | 19 | elements = node.items.map(processElement(indent)); 20 | 21 | if (elements.join().length > 80) { 22 | space = that.nl + indent + this.indent; 23 | elements = node.items.map(processElement(indent + this.indent)); 24 | body = space + elements.join(',' + space) + that.nl + indent; 25 | } else { 26 | body = elements.join(',' + that.ws); 27 | } 28 | 29 | if (node.shortForm || this.shortArray) { 30 | return '[' + body + ']'; 31 | } 32 | return 'array(' + body + ')'; 33 | }; 34 | -------------------------------------------------------------------------------- /node_translators/assign.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return codegen(node.left, indent) + this.ws + node.operator + this.ws + codegen(node.right, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/bin.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen, str, firstpart, secondpart; 6 | codegen = this.process.bind(this); 7 | 8 | firstpart = codegen(node.left, indent); 9 | secondpart = codegen(node.right, indent); 10 | str = firstpart + this.ws + node.type + this.ws + secondpart; 11 | 12 | if (str.length > 80) { 13 | str = firstpart + this.ws + node.type + this.nl + indent + this.indent + secondpart; 14 | } 15 | 16 | return str; 17 | }; 18 | -------------------------------------------------------------------------------- /node_translators/block.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | // block 7 | module.exports = function (node, indent) { 8 | var codegen, str = ''; 9 | codegen = this.process.bind(this); 10 | 11 | str += this.nl + indent + '{' + this.nl; 12 | str += doBody.call(this, codegen, indent, node.children); 13 | str += indent + '}' + this.nl; 14 | 15 | return str; 16 | }; 17 | -------------------------------------------------------------------------------- /node_translators/boolean.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node) { 5 | return node.value ? 'true' : 'false'; 6 | }; 7 | -------------------------------------------------------------------------------- /node_translators/break.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | if (node.level) { 6 | var codegen = this.process.bind(this); 7 | return 'break ' + codegen(node.level, indent); 8 | } 9 | return 'break'; 10 | }; 11 | -------------------------------------------------------------------------------- /node_translators/call.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var params = require('./helper/parameters'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen = this.process.bind(this); 8 | return codegen(node.what, indent) + 9 | '(' + params(node.arguments, indent, this) + ')'; 10 | }; 11 | -------------------------------------------------------------------------------- /node_translators/cast.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen; 6 | codegen = this.process.bind(this); 7 | return '(' + node.type + ')' + codegen(node.what, indent); 8 | }; 9 | -------------------------------------------------------------------------------- /node_translators/class.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str, that; 8 | codegen = this.process.bind(this); 9 | str = ''; 10 | that = this; 11 | 12 | // Start 13 | if (node.isAbstract) { 14 | str += 'abstract '; 15 | } else if (node.isFinal) { 16 | str += 'final '; 17 | } 18 | 19 | str += 'class'; 20 | if (node.name) { 21 | str += ' ' + node.name; 22 | } 23 | 24 | if (node.extends) { 25 | str += ' extends ' + codegen(node.extends, indent); 26 | } 27 | 28 | if (node.implements) { 29 | str += ' implements ' + node.implements.map(function (x) { 30 | return codegen(x, indent); 31 | }).join(',' + that.ws); 32 | } 33 | 34 | // begin curly brace 35 | if (node.name) { 36 | if (this.options.bracketsNewLine) { 37 | str += this.nl + indent + '{' + this.nl; 38 | } else { 39 | str += this.ws + '{' + this.nl; 40 | } 41 | } else { 42 | str += this.ws + '{' + this.nl; 43 | } 44 | 45 | 46 | // class body 47 | str += doBody.call(this, codegen, indent, node.body); 48 | 49 | // end curly brace 50 | str += indent + '}'; 51 | if (node.name) { 52 | str += this.nl; 53 | } 54 | 55 | return str; 56 | }; 57 | -------------------------------------------------------------------------------- /node_translators/classconstant.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | /** 5 | * Constant declaration 6 | */ 7 | module.exports = function (node, indent) { 8 | var codegen, str = ''; 9 | codegen = this.process.bind(this); 10 | if (node.visibility) { 11 | str += node.visibility + ' '; 12 | } 13 | str += 'const '; 14 | str += node.name; 15 | if (node.value) { 16 | str += this.ws + '=' + this.ws; 17 | str += codegen(node.value, indent); 18 | } 19 | return str; 20 | }; 21 | -------------------------------------------------------------------------------- /node_translators/clone.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen; 6 | codegen = this.process.bind(this); 7 | return 'clone ' + codegen(node.what, indent); 8 | }; 9 | -------------------------------------------------------------------------------- /node_translators/closure.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | var args = require('./helper/arguments'); 6 | var identifier = require('./helper/identifier'); 7 | 8 | // params, isRef, use, returnType 9 | module.exports = function (node, indent) { 10 | var codegen, str, useArgs; 11 | codegen = this.process.bind(this); 12 | 13 | // function header 14 | str = 'function' + this.ws; 15 | if (node.byref) { 16 | str += '&'; 17 | } 18 | str += args(node.arguments, indent, this); 19 | 20 | // use statement 21 | if (node.uses && node.uses.length > 0) { 22 | useArgs = node.uses.map(function (arg) { 23 | return '$' + arg.name; 24 | }); 25 | str += this.ws + 'use' + this.ws + '(' + useArgs.join(',' + this.ws) + ')'; 26 | } 27 | 28 | // php7 / return type 29 | if (node.type) { 30 | str += this.ws + ':' + this.ws; 31 | if (node.nullable) { 32 | str += '?'; 33 | } 34 | str += identifier(node.type); 35 | } 36 | 37 | str += this.ws + '{' + this.nl; 38 | str += doBody.call(this, codegen, indent, node.body.children); 39 | str += indent + '}'; 40 | return str; 41 | }; 42 | -------------------------------------------------------------------------------- /node_translators/constant.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | /** 5 | * Constant declaration 6 | */ 7 | module.exports = function (node, indent) { 8 | var codegen, str; 9 | codegen = this.process.bind(this); 10 | 11 | // a namespace constant (name, value) 12 | str = 'const '; 13 | str += node.name; 14 | str += this.ws + '=' + this.ws; 15 | str += codegen(node.value, indent); 16 | 17 | return str; 18 | }; 19 | -------------------------------------------------------------------------------- /node_translators/constref.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var identifier = require('./helper/identifier'); 5 | /** 6 | * Constant usage 7 | */ 8 | module.exports = function (node) { 9 | if (typeof node.name === 'string') { 10 | return identifier(node); 11 | } 12 | return identifier(node.name); 13 | }; 14 | -------------------------------------------------------------------------------- /node_translators/continue.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | if (node.level) { 7 | return 'continue ' + codegen(node.level, indent); 8 | } 9 | 10 | return 'continue'; 11 | }; 12 | -------------------------------------------------------------------------------- /node_translators/declare.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str, items = [], k; 8 | codegen = this.process.bind(this); 9 | for (k in node.what) { 10 | if (node.what.hasOwnProperty(k) && node.what[k]) { 11 | items.push(k + this.ws + '=' + this.ws + codegen(node.what[k])); 12 | } 13 | } 14 | str = 'declare(' + items.join(',' + this.ws) + ')'; 15 | if (node.mode !== 'none') { 16 | str += this.ws + '{' + this.nl; 17 | str += doBody.call(this, codegen, indent, node.children); 18 | str += indent + '}' + this.nl; 19 | } else { 20 | str += ';' + this.nl; 21 | str += doBody.call(this, codegen, indent, node.children, true); 22 | } 23 | return str; 24 | }; 25 | -------------------------------------------------------------------------------- /node_translators/do.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str; 8 | codegen = this.process.bind(this); 9 | str = 'do' + this.ws + '{' + this.nl; 10 | str += doBody.call(this, codegen, indent, node.body.children); 11 | str += indent + '}' + this.ws + 'while' + this.ws + '(' + codegen(node.test, indent) + ')'; 12 | return str; 13 | }; 14 | -------------------------------------------------------------------------------- /node_translators/doc.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var self = this, union, body; 6 | 7 | if (node.alreadyParsed) { 8 | return ''; 9 | } 10 | 11 | if (node.isDoc) { 12 | body = node.lines.join(this.nl + indent + ' * '); 13 | if (body.substring(body.length - 3) === ' * ') { 14 | body = body.substring(0, body.length - 3); 15 | } 16 | return this.nl + indent + '/** ' + body + ' */'; 17 | } 18 | 19 | union = self.nl + indent + self.ws + self.ws; 20 | return node.lines.reduce(function (acc, line) { 21 | 22 | if (line.indexOf('\n') > -1) { 23 | return acc.concat('/*' + line.split("\n").join(union) + '*/'); 24 | } 25 | 26 | return acc.concat('// ' + line); 27 | }, []).join(self.nl + indent); 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /node_translators/echo.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var params = require('./helper/parameters'); 5 | 6 | module.exports = function (node, indent) { 7 | var str = params(node.arguments, indent, this); 8 | 9 | if (node.isInlineEcho) { 10 | return str + this.ws + '?>'; 11 | } 12 | 13 | return 'echo ' + str; 14 | }; 15 | -------------------------------------------------------------------------------- /node_translators/empty.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'empty(' + codegen(node.arguments[0], indent) + ')'; 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/encapsed.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2, unparam:true */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent, opt) { 5 | var body = '', codegen = this.process.bind(this); 6 | 7 | node.value.forEach(function (item) { 8 | if (item.kind === 'string') { 9 | body += item.value; 10 | } else { 11 | body += '{' + codegen(item, indent) + '}'; 12 | } 13 | }); 14 | 15 | if (node.type === 'heredoc') { 16 | return '<<<' + node.label + this.nl + body + node.label; 17 | } 18 | 19 | if (node.type === 'nowdoc') { 20 | return '<<<\'' + node.label + '\'' + this.nl + body + node.label; 21 | } 22 | 23 | if (node.type === 'shell') { 24 | return '`' + body + '`'; 25 | } 26 | 27 | if (node.isDoubleQuote) { 28 | return '"' + body + '"'; 29 | } 30 | 31 | return '\'' + body + '\''; 32 | }; 33 | -------------------------------------------------------------------------------- /node_translators/eval.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'eval(' + codegen(node.source, indent) + ')'; 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/exit.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | /** 5 | * Exit statement 6 | */ 7 | module.exports = function (node, indent) { 8 | var codegen; 9 | codegen = this.process.bind(this); 10 | if (node.status === null) { 11 | return 'exit'; 12 | } 13 | return 'exit(' + codegen(node.status, indent) + ')'; 14 | }; 15 | -------------------------------------------------------------------------------- /node_translators/for.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str; 8 | 9 | codegen = this.process.bind(this); 10 | str = 'for' + this.ws + '('; 11 | 12 | if (node.init) { 13 | str += node.init.map(function (x) { 14 | if (x) { 15 | return codegen(x, indent); 16 | } 17 | return ''; 18 | }).join(',' + this.ws); 19 | } 20 | str += ';' + this.ws; 21 | 22 | if (node.test) { 23 | str += node.test.map(function (x) { 24 | if (x) { 25 | return codegen(x, indent); 26 | } 27 | return ''; 28 | }).join(',' + this.ws); 29 | } 30 | str += ';' + this.ws; 31 | 32 | if (node.increment) { 33 | str += node.increment.map(function (x) { 34 | if (x) { 35 | return codegen(x, indent); 36 | } 37 | return ''; 38 | }).join(',' + this.ws); 39 | } 40 | str += ')'; 41 | if (this.shortForm) { 42 | str += ':' + this.nl; 43 | } else { 44 | str += this.ws + '{' + this.nl; 45 | } 46 | 47 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 48 | 49 | if (this.shortForm) { 50 | str += indent + 'endfor;'; 51 | } else { 52 | str += indent + '}'; 53 | } 54 | return str; 55 | }; 56 | -------------------------------------------------------------------------------- /node_translators/foreach.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str; 8 | codegen = this.process.bind(this); 9 | 10 | str = 'foreach' + this.ws + '(' + codegen(node.source, indent) + this.ws + 'as' + this.ws; 11 | if (node.key) { 12 | str += codegen(node.key, indent) + this.ws + '=>' + this.ws; 13 | } 14 | str += codegen(node.value, indent) + ')'; 15 | if (node.shortForm) { 16 | str += ':' + this.nl; 17 | } else { 18 | str += this.ws + '{' + this.nl; 19 | } 20 | 21 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 22 | if (node.shortForm) { 23 | str += indent + 'endforeach;'; 24 | } else { 25 | str += indent + '}'; 26 | } 27 | return str; 28 | }; 29 | -------------------------------------------------------------------------------- /node_translators/function.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | var args = require('./helper/arguments'); 6 | var identifier = require('./helper/identifier'); 7 | 8 | // name, params, isRef, returnType, body 9 | module.exports = function (node, indent) { 10 | var codegen, str; 11 | codegen = this.process.bind(this); 12 | 13 | str = 'function '; 14 | if (node.byref) { 15 | str += '&'; 16 | } 17 | str += node.name; 18 | str += args(node.arguments, indent, this); 19 | 20 | // php7 / return type 21 | if (node.type) { 22 | str += this.ws + ':' + this.ws; 23 | if (node.nullable) { 24 | str += '?'; 25 | } 26 | str += identifier(node.type); 27 | } 28 | 29 | if (this.options.bracketsNewLine) { 30 | str += this.nl + indent + '{' + this.nl; 31 | } else { 32 | str += this.ws + '{' + this.nl; 33 | } 34 | 35 | str += doBody.call(this, codegen, indent, node.body.children); 36 | str += indent + '}' + this.nl; 37 | 38 | return str; 39 | }; 40 | -------------------------------------------------------------------------------- /node_translators/global.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'global ' + node.items.map(function (x) { 7 | return codegen(x, indent); 8 | }).join(',' + this.ws); 9 | }; 10 | -------------------------------------------------------------------------------- /node_translators/goto.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node) { 5 | return 'goto ' + node.label; 6 | }; 7 | -------------------------------------------------------------------------------- /node_translators/helper/arguments.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | // name, type, value, isRef, isVariadic 5 | function processElement(indent, ws, codegen) { 6 | return function (arg) { 7 | var str = ''; 8 | 9 | if (arg.nullable) { 10 | str += '?'; 11 | } 12 | 13 | if (arg.type) { // type hint 14 | str += codegen(arg.type, indent) + ws; 15 | } 16 | 17 | if (arg.byref) { // byref 18 | str += '&'; 19 | } 20 | 21 | if (arg.variadic) { // variadic 22 | str += '...'; 23 | } 24 | 25 | str += '$' + arg.name; // name 26 | 27 | if (arg.value) { // default value 28 | str += ws + '=' + ws + codegen(arg.value, indent); 29 | } 30 | 31 | return str; 32 | }; 33 | } 34 | 35 | module.exports = function (nodes, indent, self) { 36 | var codegen, args, space, listArgs; 37 | 38 | codegen = self.process.bind(self); 39 | args = nodes.map(processElement(indent, self.ws, codegen)); 40 | listArgs = args.join(',' + self.ws); 41 | 42 | if (listArgs.length > 80) { 43 | space = self.nl + indent + self.indent; 44 | args = nodes.map(processElement(indent + self.indent, self.ws, codegen)); 45 | listArgs = space + args.join(',' + space) + self.nl + indent; 46 | } 47 | 48 | return '(' + listArgs + ')'; 49 | }; 50 | -------------------------------------------------------------------------------- /node_translators/helper/body.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var noSemiColons = [ 5 | 'class', 'interface', 'trait', 'namespace', 'try', 6 | 'if', 'switch', 'for', 'foreach', 'function', 'method', 7 | 'while', 'doc', 'comment', 'label', 'declare', 8 | 'usegroup', 'traituse', 'inline', 'block' 9 | ]; 10 | 11 | module.exports = function (codegen, currentIndent, body, isProgram, dontIncreaseIndent) { 12 | 13 | var str = '', expr, i, indentation, delimiter, that = this, line, next, after, dontUseNewLine, isInlineEcho; 14 | 15 | // Set the rows delimiter 16 | delimiter = that.options.collapseEmptyLines ? '' : '\n'; 17 | 18 | // Set the indentation 19 | if (dontIncreaseIndent) { 20 | indentation = currentIndent; 21 | } else { 22 | indentation = isProgram ? '' : currentIndent + that.indent; 23 | } 24 | 25 | // Force body as an array 26 | if (!Array.isArray(body)) { 27 | body = [body]; 28 | } 29 | 30 | for (i = 0; i < body.length; i += 1) { 31 | expr = body[i]; 32 | next = body[i + 1] || {}; 33 | after = body[i + 2] || {}; 34 | 35 | // Return empty string 36 | if (expr !== null) { 37 | 38 | 39 | /** 40 | * If this expression is an inline, the next is an echo, and the one after 41 | * is another expression inline, treat it as an inline echo 42 | */ 43 | if (expr.kind === 'inline' && next.kind === 'echo' && after.kind === 'inline') { 44 | expr.isInlineEcho = true; 45 | next.isInlineEcho = true; 46 | after.omitClosingTag = true; 47 | dontUseNewLine = true; 48 | } 49 | 50 | 51 | // Is this expr the echo of an inline echo? 52 | isInlineEcho = expr.kind === 'echo' && expr.isInlineEcho === true; 53 | 54 | if (expr.kind === 'label' || isInlineEcho || expr.omitClosingTag) { 55 | line = codegen(expr, indentation); 56 | } else { 57 | line = indentation + codegen(expr, indentation); 58 | } 59 | 60 | // This expressions don't require semicolons 61 | if (noSemiColons.indexOf(expr.kind) === -1 && !isInlineEcho) { 62 | line += ';'; 63 | } 64 | 65 | // Check if the next expression is a comment that should be 66 | // on the same line as this expression 67 | if (next.kind === 'doc' && next.loc && expr.loc && next.loc.start.line === expr.loc.start.line) { 68 | line += that.ws + codegen(next, '').trim(); 69 | next.alreadyParsed = true; // prevent to parse again the comment 70 | } 71 | 72 | 73 | str += line; 74 | if (!dontUseNewLine && !isInlineEcho) { 75 | str += that.nl + delimiter; 76 | } 77 | } 78 | } 79 | 80 | // Return the generated string 81 | return str; 82 | }; 83 | -------------------------------------------------------------------------------- /node_translators/helper/identifier.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function identifier(id) { 5 | if (id.resolution === 'rn') { 6 | return 'namespace\\' + id.name; 7 | } 8 | return id.name; 9 | }; 10 | -------------------------------------------------------------------------------- /node_translators/helper/parameters.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (args, indent, self) { 5 | var codegen, useArgs = [], space, raw; 6 | 7 | codegen = self.process.bind(self); 8 | 9 | function processElement(indent) { 10 | return function (arg) { 11 | return codegen(arg, indent); 12 | }; 13 | } 14 | if (args && args.length > 0) { 15 | useArgs = args.map(processElement(indent)); 16 | } 17 | raw = useArgs.join(); 18 | if ((raw.indexOf("\n") > -1 && raw.substr(0, raw.indexOf("\n")).length > 80) || (raw.indexOf("\n") === -1 && raw.length > 80)) { 19 | useArgs = args.map(processElement(indent + self.indent)); 20 | space = self.nl + indent + self.indent; 21 | args = space + useArgs.join(',' + space) + self.nl + indent; 22 | } else { 23 | args = useArgs.join(',' + self.ws); 24 | } 25 | return args; 26 | }; 27 | -------------------------------------------------------------------------------- /node_translators/identifier.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node) { 5 | if (node.resolution === 'rn') { 6 | return 'namespace\\' + node.name; 7 | } 8 | return node.name; 9 | }; 10 | -------------------------------------------------------------------------------- /node_translators/if.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function processIf(node, indent, inner) { 7 | var codegen, str, that = this; 8 | 9 | codegen = this.process.bind(this); 10 | 11 | str = 'if' + this.ws + '(' + codegen(node.test, indent) + ')'; 12 | 13 | if (node.body) { 14 | if (node.shortForm) { 15 | str += ':' + this.nl; 16 | } else { 17 | str += this.ws + '{' + this.nl; 18 | } 19 | 20 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 21 | 22 | if (!node.shortForm) { 23 | str += indent + '}'; 24 | } 25 | } else if (!node.alternate) { 26 | return str + ';'; 27 | } 28 | 29 | if (node.alternate) { 30 | str += (function () { 31 | var out = ''; 32 | // is an "elseif" 33 | if (node.alternate.kind === 'if') { 34 | if (node.shortForm) { 35 | return indent + 'else' + processIf.call(that, node.alternate, indent, true); 36 | } 37 | return that.ws + 'else' + processIf.call(that, node.alternate, indent, true); 38 | } 39 | 40 | // is an "else" 41 | if (node.shortForm) { 42 | out += indent + 'else:' + that.nl; 43 | } else { 44 | out += that.ws + 'else' + that.ws + '{' + that.nl; 45 | } 46 | 47 | out += doBody.call(that, codegen, indent, node.alternate.children || [node.alternate]); 48 | 49 | if (!node.shortForm) { 50 | out += indent + '}' + that.nl; 51 | } 52 | return out; 53 | }()); 54 | } 55 | 56 | if (node.shortForm && !inner) { 57 | str += indent + 'endif;' + this.nl; 58 | } 59 | return str; 60 | }; 61 | -------------------------------------------------------------------------------- /node_translators/include.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var str, codegen; 6 | str = node.require ? 'require' : 'include'; 7 | if (node.once) { 8 | str += '_once'; 9 | } 10 | codegen = this.process.bind(this); 11 | return str + ' ' + codegen(node.target, indent); 12 | }; 13 | -------------------------------------------------------------------------------- /node_translators/index.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2, nomen:true, evil: true */ 2 | 'use strict'; 3 | 4 | var defaults = { 5 | indent: ' ', 6 | dontUseWhitespaces: false, 7 | shortArray: false, 8 | bracketsNewLine: true, 9 | forceNamespaceBrackets: false, 10 | collapseEmptyLines: true 11 | }; 12 | 13 | function CodeGen(options) { 14 | 15 | // Get options 16 | this.options = Object.assign({}, defaults, options); 17 | this.ws = this.options.dontUseWhitespaces ? '' : ' '; 18 | this.indent = typeof this.options.indent === 'string' ? this.options.indent : ' '; 19 | this.nl = this.indent !== '' ? '\n' : ''; 20 | this.shortArray = this.options.shortArray || false; 21 | this.forceNamespaceBrackets = this.options.forceNamespaceBrackets || false; 22 | 23 | this.process = function (node, indent) { 24 | var err; 25 | 26 | if (node === null) { 27 | return indent; 28 | } 29 | 30 | if (node && node.kind) { 31 | if (typeof this[node.kind] === 'function') { 32 | return this[node.kind](node, indent); 33 | } 34 | err = new Error( 35 | 'Unhandled node type [' + node.kind + ']' + ( 36 | node.loc ? ' at line ' + node.loc.start.line : '' 37 | ) 38 | ); 39 | } else { 40 | console.log('Node:', node); 41 | console.log('Node kind:', node.kind); 42 | err = new Error('Bad AST structure'); 43 | } 44 | err.node = node; 45 | throw err; 46 | }; 47 | } 48 | 49 | module.exports = CodeGen; 50 | 51 | // node translators 52 | CodeGen.prototype.array = require("./array.js"); 53 | CodeGen.prototype.assign = require("./assign.js"); 54 | CodeGen.prototype.bin = require("./bin.js"); 55 | CodeGen.prototype.block = require("./block.js"); 56 | CodeGen.prototype.boolean = require("./boolean.js"); 57 | CodeGen.prototype.break = require("./break.js"); 58 | CodeGen.prototype.call = require("./call.js"); 59 | CodeGen.prototype.cast = require("./cast.js"); 60 | CodeGen.prototype.classconstant = require("./classconstant.js"); 61 | CodeGen.prototype.class = require("./class.js"); 62 | CodeGen.prototype.clone = require("./clone.js"); 63 | CodeGen.prototype.closure = require("./closure.js"); 64 | CodeGen.prototype.constant = require("./constant.js"); 65 | CodeGen.prototype.constref = require("./constref.js"); 66 | CodeGen.prototype.continue = require("./continue.js"); 67 | CodeGen.prototype.declare = require("./declare.js"); 68 | CodeGen.prototype.doc = require("./doc.js"); 69 | CodeGen.prototype.do = require("./do.js"); 70 | CodeGen.prototype.echo = require("./echo.js"); 71 | CodeGen.prototype.empty = require("./empty.js"); 72 | CodeGen.prototype.encapsed = require("./encapsed.js"); 73 | CodeGen.prototype.eval = require("./eval.js"); 74 | CodeGen.prototype.exit = require("./exit.js"); 75 | CodeGen.prototype.foreach = require("./foreach.js"); 76 | CodeGen.prototype.for = require("./for.js"); 77 | CodeGen.prototype.function = require("./function.js"); 78 | CodeGen.prototype.global = require("./global.js"); 79 | CodeGen.prototype.goto = require("./goto.js"); 80 | CodeGen.prototype.identifier = require("./identifier.js"); 81 | CodeGen.prototype.if = require("./if.js"); 82 | CodeGen.prototype.include = require("./include.js"); 83 | CodeGen.prototype.inline = require("./inline.js"); 84 | CodeGen.prototype.interface = require("./interface.js"); 85 | CodeGen.prototype.isset = require("./isset.js"); 86 | CodeGen.prototype.label = require("./label.js"); 87 | CodeGen.prototype.list = require("./list.js"); 88 | CodeGen.prototype.magic = require("./magic.js"); 89 | CodeGen.prototype.method = require("./method.js"); 90 | CodeGen.prototype.namespace = require("./namespace.js"); 91 | CodeGen.prototype.new = require("./new.js"); 92 | CodeGen.prototype.nowdoc = require("./nowdoc.js"); 93 | CodeGen.prototype.number = require("./number.js"); 94 | CodeGen.prototype.offsetlookup = require("./offsetlookup.js"); 95 | CodeGen.prototype.parenthesis = require("./parenthesis.js"); 96 | CodeGen.prototype.post = require("./post.js"); 97 | CodeGen.prototype.pre = require("./pre.js"); 98 | CodeGen.prototype.print = require("./print.js"); 99 | CodeGen.prototype.program = require("./program.js"); 100 | CodeGen.prototype.property = require("./property.js"); 101 | CodeGen.prototype.propertylookup = require("./propertylookup.js"); 102 | CodeGen.prototype.retif = require("./retif.js"); 103 | CodeGen.prototype.return = require("./return.js"); 104 | CodeGen.prototype.silent = require("./silent.js"); 105 | CodeGen.prototype.static = require("./static.js"); 106 | CodeGen.prototype.staticlookup = require("./staticlookup.js"); 107 | CodeGen.prototype.string = require("./string.js"); 108 | CodeGen.prototype.switch = require("./switch.js"); 109 | CodeGen.prototype.throw = require("./throw.js"); 110 | CodeGen.prototype.trait = require("./trait.js"); 111 | CodeGen.prototype.traituse = require("./traituse.js"); 112 | CodeGen.prototype.try = require("./try.js"); 113 | CodeGen.prototype.unary = require("./unary.js"); 114 | CodeGen.prototype.unset = require("./unset.js"); 115 | CodeGen.prototype.usegroup = require("./usegroup.js"); 116 | CodeGen.prototype.variable = require("./variable.js"); 117 | CodeGen.prototype.variadic = require("./variadic.js"); 118 | CodeGen.prototype.while = require("./while.js"); 119 | CodeGen.prototype.yieldfrom = require("./yieldfrom.js"); 120 | CodeGen.prototype.yield = require("./yield.js"); 121 | -------------------------------------------------------------------------------- /node_translators/inline.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node) { 5 | var str; 6 | 7 | str = node.omitClosingTag ? '' : '?>'; 8 | str += node.value; 9 | 10 | if (node.isInlineEcho) { 11 | return str + ' 0) { 12 | str += params(node.arguments, indent, this); 13 | } 14 | str += ')'; 15 | } 16 | return 'new ' + str; 17 | }; 18 | -------------------------------------------------------------------------------- /node_translators/nowdoc.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2, unparam:true */ 2 | 'use strict'; 3 | 4 | module.exports = function (node) { 5 | return '<<<\'' + node.label + '\'' + this.nl + node.value + this.nl + node.label; 6 | }; 7 | -------------------------------------------------------------------------------- /node_translators/number.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node) { 5 | return node.value.toString(); 6 | }; 7 | -------------------------------------------------------------------------------- /node_translators/offsetlookup.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen, offset; 6 | codegen = this.process.bind(this); 7 | offset = node.offset ? codegen(node.offset, indent) : ''; 8 | return codegen(node.what, indent) + '[' + offset + ']'; 9 | }; 10 | -------------------------------------------------------------------------------- /node_translators/parenthesis.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return '(' + codegen(node.inner, indent) + ')'; 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/post.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return codegen(node.what, indent) + node.type + node.type; 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/pre.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return node.type + node.type + codegen(node.what, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/print.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'print ' + codegen(node.arguments, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/program.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node) { 7 | 8 | if (!node.children || node.children.length === 0) { 9 | return ''; 10 | } 11 | 12 | var codegen = this.process.bind(this), str = '' + prop; 20 | }; 21 | -------------------------------------------------------------------------------- /node_translators/retif.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen, left, right = ''; 6 | codegen = this.process.bind(this); 7 | if (node.trueExpr) { 8 | left = codegen(node.trueExpr, indent); 9 | } 10 | if (node.falseExpr) { 11 | right = codegen(node.falseExpr, indent); 12 | } 13 | return codegen(node.test, indent) + this.ws + '?' + 14 | (left ? this.ws + left + this.ws : '') + ':' + 15 | (right ? this.ws + right : ''); 16 | }; 17 | -------------------------------------------------------------------------------- /node_translators/return.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen; 6 | 7 | if (!node.expr) { 8 | return 'return'; 9 | } 10 | 11 | codegen = this.process.bind(this); 12 | return 'return ' + codegen(node.expr, indent); 13 | }; 14 | -------------------------------------------------------------------------------- /node_translators/silent.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | 7 | return '@' + codegen(node.expr, indent); 8 | }; 9 | -------------------------------------------------------------------------------- /node_translators/static.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'static ' + node.items.map(function (x) { 7 | return codegen(x, indent); 8 | }).join(',' + this.ws); 9 | }; 10 | -------------------------------------------------------------------------------- /node_translators/staticlookup.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return codegen(node.what, indent) + '::' + codegen(node.offset, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/string.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2, unparam:true */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent, opt) { 5 | opt = opt || {}; 6 | if (opt.raw) { 7 | return node.value; 8 | } 9 | return JSON.stringify(node.value).replace(/\$/g, '\\$'); 10 | }; 11 | -------------------------------------------------------------------------------- /node_translators/switch.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str, that = this, cases; 8 | 9 | codegen = this.process.bind(this); 10 | str = 'switch' + this.ws + '(' + codegen(node.test, indent) + ')'; 11 | if (node.shortForm) { 12 | str += ':' + this.nl; 13 | } else { 14 | str += this.ws + '{' + this.nl; 15 | } 16 | cases = node.body.children.map(function (item) { 17 | var head; 18 | if (item.test) { 19 | head = indent + that.indent + 'case ' + codegen(item.test, indent) + ':' + that.nl; 20 | } else { 21 | head = indent + that.indent + 'default:' + that.nl; 22 | } 23 | if (item.body) { 24 | head += doBody.call(that, codegen, indent + that.indent, item.body.children || [item.body]); 25 | } 26 | return head; 27 | }); 28 | str += cases.join(''); 29 | if (node.shortForm) { 30 | str += indent + 'endswitch;'; 31 | } else { 32 | str += indent + '}'; 33 | } 34 | return str; 35 | }; 36 | -------------------------------------------------------------------------------- /node_translators/throw.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'throw ' + codegen(node.what, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/trait.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | var doBody = require('./helper/body'); 4 | var identifier = require('./helper/identifier'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen, str; 8 | codegen = this.process.bind(this); 9 | 10 | str = 'trait ' + node.name; 11 | 12 | if (node.extends) { 13 | str += ' extends ' + identifier(node.extends); 14 | } 15 | 16 | if (node.implements) { 17 | str += ' implements ' + node.implements.map(identifier).join(',' + this.ws); 18 | } 19 | 20 | // begin curly brace 21 | if (this.options.bracketsNewLine) { 22 | str += this.nl + indent + '{' + this.nl; 23 | } else { 24 | str += this.ws + '{' + this.nl; 25 | } 26 | 27 | // trait body 28 | str += doBody.call(this, codegen, indent, node.body); 29 | 30 | // end curly brace 31 | str += indent + '}\n'; 32 | 33 | return str; 34 | }; 35 | -------------------------------------------------------------------------------- /node_translators/traituse.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var identifier = require('./helper/identifier'); 5 | 6 | /** 7 | * Usage declaration 8 | */ 9 | module.exports = function (node, indent) { 10 | var str = 'use' + this.ws, items = [], glue, codegen; 11 | codegen = this.process.bind(this); 12 | node.traits.forEach(function (item) { 13 | items.push( 14 | codegen(item, indent) 15 | ); 16 | }); 17 | str += items.join(',' + this.ws); 18 | if (node.adaptations) { 19 | glue = this.nl + indent + this.indent; 20 | str += this.ws + '{' + glue; 21 | str += node.adaptations.map(function (item) { 22 | var out = ''; 23 | if (item.trait) { 24 | out += codegen(item.trait, indent) + '::'; 25 | } 26 | if (item.method) { 27 | out += item.method; 28 | } 29 | if (item.kind === 'traitprecedence') { 30 | out += ' insteadof ';// + codegen(item.insteadof); 31 | out += item.instead.map(identifier).join(', '); 32 | } else { 33 | out += ' as '; 34 | if (item.visibility) { 35 | out += item.visibility + ' '; 36 | } 37 | out += item.as; 38 | } 39 | return out + ';'; 40 | }).join(glue) + this.nl; 41 | str += indent + '}'; 42 | } else { 43 | str += ';'; 44 | } 45 | return str + this.nl; 46 | }; 47 | -------------------------------------------------------------------------------- /node_translators/try.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | var identifier = require('./helper/identifier'); 6 | 7 | function resolveExceptions(items) { 8 | var result = [], i; 9 | for (i = 0; i < items.length; i += 1) { 10 | result.push(identifier(items[i])); 11 | } 12 | return result.join('|'); 13 | } 14 | 15 | module.exports = function (node, indent) { 16 | var codegen, str; 17 | 18 | 19 | codegen = this.process.bind(this); 20 | str = 'try' + this.ws + '{' + this.nl; 21 | str += doBody.call(this, codegen, indent, node.body.children); 22 | str += indent + '}'; 23 | 24 | str += node.catches.map(function (except) { 25 | var out = this.ws + 'catch' + this.ws + '(' + resolveExceptions(except.what) + ' ' + codegen(except.variable) + ')' + this.ws + '{' + this.nl; 26 | out += doBody.call(this, codegen, indent, except.body.children); 27 | out += indent + '}'; 28 | return out; 29 | }, this).join(''); 30 | 31 | if (node.always) { 32 | str += this.ws + 'finally' + this.ws + '{' + this.nl; 33 | str += doBody.call(this, codegen, indent, node.always.children); 34 | str += indent + '}'; 35 | } 36 | 37 | return str; 38 | }; 39 | -------------------------------------------------------------------------------- /node_translators/unary.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return node.type + codegen(node.what, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/unset.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var params = require('./helper/parameters'); 5 | 6 | module.exports = function (node, indent) { 7 | return 'unset(' + params(node.arguments, indent, this) + ')'; 8 | }; 9 | -------------------------------------------------------------------------------- /node_translators/usegroup.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | /** 5 | * Usage declaration 6 | */ 7 | module.exports = function (node, indent) { 8 | var str = 'use' + this.ws, items, glue; 9 | if (node.type) { 10 | str += node.type + this.ws; 11 | } 12 | 13 | items = (node.items || []).map(function (item) { 14 | var useItem = item.name; 15 | if (item.alias) { 16 | useItem += ' as ' + item.alias; 17 | } 18 | return useItem; 19 | }); 20 | 21 | if (node.items.length > 1) { 22 | glue = this.nl + indent + this.indent; 23 | str += node.name + this.ws + '{' + glue; 24 | str += items.join(',' + glue) + this.nl; 25 | str += indent + '};' + this.nl; 26 | } else { 27 | str += items[0] + ';' + this.nl; 28 | } 29 | return str; 30 | }; 31 | -------------------------------------------------------------------------------- /node_translators/variable.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | if (typeof node.name !== 'string') { 6 | var codegen = this.process.bind(this); 7 | node.name = codegen(node.name, indent); 8 | } 9 | return (node.byref ? '&$' : '$') + node.name; 10 | }; 11 | -------------------------------------------------------------------------------- /node_translators/variadic.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return '...' + codegen(node.what, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /node_translators/while.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | var doBody = require('./helper/body'); 5 | 6 | module.exports = function (node, indent) { 7 | var codegen = this.process.bind(this), str; 8 | 9 | str = 'while' + this.ws + '(' + codegen(node.test, indent) + ')'; 10 | if (!node.body) { 11 | return str; 12 | } 13 | if (node.shortForm) { 14 | str += ':' + this.nl; 15 | } else { 16 | str += this.ws + '{' + this.nl; 17 | } 18 | str += doBody.call(this, codegen, indent, node.body.children || [node.body]); 19 | if (node.shortForm) { 20 | str += indent + 'endwhile;'; 21 | } else { 22 | str += indent + '}'; 23 | } 24 | return str; 25 | }; 26 | -------------------------------------------------------------------------------- /node_translators/yield.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen, str; 6 | str = 'yield'; 7 | if (node.value) { 8 | codegen = this.process.bind(this); 9 | if (node.key) { 10 | // yield $key => $value 11 | str += ' ' + codegen(node.key, indent) + ' =>'; 12 | } 13 | // yield $value 14 | str += ' ' + codegen(node.value, indent); 15 | } 16 | return str; 17 | }; 18 | -------------------------------------------------------------------------------- /node_translators/yieldfrom.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2 */ 2 | 'use strict'; 3 | 4 | module.exports = function (node, indent) { 5 | var codegen = this.process.bind(this); 6 | return 'yield from ' + codegen(node.value, indent); 7 | }; 8 | -------------------------------------------------------------------------------- /npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php-unparser", 3 | "version": "0.2.8", 4 | "dependencies": { 5 | "abbrev": { 6 | "version": "1.0.9", 7 | "from": "abbrev@>=1.0.0 <1.1.0", 8 | "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.9.tgz" 9 | }, 10 | "acorn": { 11 | "version": "4.0.13", 12 | "from": "acorn@>=4.0.3 <5.0.0", 13 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-4.0.13.tgz" 14 | }, 15 | "acorn-node": { 16 | "version": "1.3.0", 17 | "from": "acorn-node@>=1.2.0 <2.0.0", 18 | "resolved": "https://registry.npmjs.org/acorn-node/-/acorn-node-1.3.0.tgz", 19 | "dependencies": { 20 | "acorn": { 21 | "version": "5.5.3", 22 | "from": "acorn@>=5.4.1 <6.0.0", 23 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.3.tgz" 24 | } 25 | } 26 | }, 27 | "align-text": { 28 | "version": "0.1.4", 29 | "from": "align-text@>=0.1.3 <0.2.0", 30 | "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz" 31 | }, 32 | "amdefine": { 33 | "version": "1.0.1", 34 | "from": "amdefine@>=0.0.4", 35 | "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz" 36 | }, 37 | "ansi-regex": { 38 | "version": "2.1.1", 39 | "from": "ansi-regex@>=2.0.0 <3.0.0", 40 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz" 41 | }, 42 | "ansi-styles": { 43 | "version": "2.2.1", 44 | "from": "ansi-styles@>=2.2.1 <3.0.0", 45 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz" 46 | }, 47 | "argparse": { 48 | "version": "1.0.10", 49 | "from": "argparse@>=1.0.7 <2.0.0", 50 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz" 51 | }, 52 | "array-filter": { 53 | "version": "0.0.1", 54 | "from": "array-filter@>=0.0.0 <0.1.0", 55 | "resolved": "https://registry.npmjs.org/array-filter/-/array-filter-0.0.1.tgz" 56 | }, 57 | "array-map": { 58 | "version": "0.0.0", 59 | "from": "array-map@>=0.0.0 <0.1.0", 60 | "resolved": "https://registry.npmjs.org/array-map/-/array-map-0.0.0.tgz" 61 | }, 62 | "array-reduce": { 63 | "version": "0.0.0", 64 | "from": "array-reduce@>=0.0.0 <0.1.0", 65 | "resolved": "https://registry.npmjs.org/array-reduce/-/array-reduce-0.0.0.tgz" 66 | }, 67 | "asn1": { 68 | "version": "0.2.3", 69 | "from": "asn1@>=0.2.3 <0.3.0", 70 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz" 71 | }, 72 | "asn1.js": { 73 | "version": "4.10.1", 74 | "from": "asn1.js@>=4.0.0 <5.0.0", 75 | "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz" 76 | }, 77 | "assert": { 78 | "version": "1.3.0", 79 | "from": "assert@>=1.3.0 <1.4.0", 80 | "resolved": "https://registry.npmjs.org/assert/-/assert-1.3.0.tgz" 81 | }, 82 | "assert-plus": { 83 | "version": "0.2.0", 84 | "from": "assert-plus@>=0.2.0 <0.3.0", 85 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz" 86 | }, 87 | "astw": { 88 | "version": "2.2.0", 89 | "from": "astw@>=2.0.0 <3.0.0", 90 | "resolved": "https://registry.npmjs.org/astw/-/astw-2.2.0.tgz" 91 | }, 92 | "async": { 93 | "version": "1.5.2", 94 | "from": "async@>=1.0.0 <2.0.0", 95 | "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz" 96 | }, 97 | "asynckit": { 98 | "version": "0.4.0", 99 | "from": "asynckit@>=0.4.0 <0.5.0", 100 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz" 101 | }, 102 | "aws-sign2": { 103 | "version": "0.6.0", 104 | "from": "aws-sign2@>=0.6.0 <0.7.0", 105 | "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz" 106 | }, 107 | "aws4": { 108 | "version": "1.7.0", 109 | "from": "aws4@>=1.2.1 <2.0.0", 110 | "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.7.0.tgz" 111 | }, 112 | "balanced-match": { 113 | "version": "1.0.0", 114 | "from": "balanced-match@>=1.0.0 <2.0.0", 115 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz" 116 | }, 117 | "base64-js": { 118 | "version": "1.3.0", 119 | "from": "base64-js@>=1.0.2 <2.0.0", 120 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz" 121 | }, 122 | "bcrypt-pbkdf": { 123 | "version": "1.0.1", 124 | "from": "bcrypt-pbkdf@>=1.0.0 <2.0.0", 125 | "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz" 126 | }, 127 | "bn.js": { 128 | "version": "4.11.8", 129 | "from": "bn.js@>=4.1.1 <5.0.0", 130 | "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz" 131 | }, 132 | "boom": { 133 | "version": "2.10.1", 134 | "from": "boom@>=2.0.0 <3.0.0", 135 | "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", 136 | "dependencies": { 137 | "hoek": { 138 | "version": "2.16.3", 139 | "from": "hoek@>=2.0.0 <3.0.0", 140 | "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz" 141 | } 142 | } 143 | }, 144 | "brace-expansion": { 145 | "version": "1.1.11", 146 | "from": "brace-expansion@>=1.1.7 <2.0.0", 147 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz" 148 | }, 149 | "brorand": { 150 | "version": "1.1.0", 151 | "from": "brorand@>=1.0.1 <2.0.0", 152 | "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz" 153 | }, 154 | "browser-pack": { 155 | "version": "6.1.0", 156 | "from": "browser-pack@>=6.0.1 <7.0.0", 157 | "resolved": "https://registry.npmjs.org/browser-pack/-/browser-pack-6.1.0.tgz" 158 | }, 159 | "browser-resolve": { 160 | "version": "1.11.2", 161 | "from": "browser-resolve@>=1.11.0 <2.0.0", 162 | "resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.11.2.tgz", 163 | "dependencies": { 164 | "resolve": { 165 | "version": "1.1.7", 166 | "from": "resolve@1.1.7", 167 | "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz" 168 | } 169 | } 170 | }, 171 | "browserify-aes": { 172 | "version": "1.2.0", 173 | "from": "browserify-aes@>=1.0.4 <2.0.0", 174 | "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz" 175 | }, 176 | "browserify-cipher": { 177 | "version": "1.0.1", 178 | "from": "browserify-cipher@>=1.0.0 <2.0.0", 179 | "resolved": "https://registry.npmjs.org/browserify-cipher/-/browserify-cipher-1.0.1.tgz" 180 | }, 181 | "browserify-des": { 182 | "version": "1.0.1", 183 | "from": "browserify-des@>=1.0.0 <2.0.0", 184 | "resolved": "https://registry.npmjs.org/browserify-des/-/browserify-des-1.0.1.tgz" 185 | }, 186 | "browserify-rsa": { 187 | "version": "4.0.1", 188 | "from": "browserify-rsa@>=4.0.0 <5.0.0", 189 | "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz" 190 | }, 191 | "browserify-sign": { 192 | "version": "4.0.4", 193 | "from": "browserify-sign@>=4.0.0 <5.0.0", 194 | "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.0.4.tgz" 195 | }, 196 | "browserify-zlib": { 197 | "version": "0.1.4", 198 | "from": "browserify-zlib@>=0.1.2 <0.2.0", 199 | "resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.1.4.tgz" 200 | }, 201 | "buffer": { 202 | "version": "4.9.1", 203 | "from": "buffer@>=4.1.0 <5.0.0", 204 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz" 205 | }, 206 | "buffer-from": { 207 | "version": "1.0.0", 208 | "from": "buffer-from@>=1.0.0 <2.0.0", 209 | "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.0.0.tgz" 210 | }, 211 | "buffer-xor": { 212 | "version": "1.0.3", 213 | "from": "buffer-xor@>=1.0.3 <2.0.0", 214 | "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz" 215 | }, 216 | "builtin-status-codes": { 217 | "version": "3.0.0", 218 | "from": "builtin-status-codes@>=3.0.0 <4.0.0", 219 | "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz" 220 | }, 221 | "cached-path-relative": { 222 | "version": "1.0.1", 223 | "from": "cached-path-relative@>=1.0.0 <2.0.0", 224 | "resolved": "https://registry.npmjs.org/cached-path-relative/-/cached-path-relative-1.0.1.tgz" 225 | }, 226 | "camelcase": { 227 | "version": "1.2.1", 228 | "from": "camelcase@>=1.0.2 <2.0.0", 229 | "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz" 230 | }, 231 | "caseless": { 232 | "version": "0.11.0", 233 | "from": "caseless@>=0.11.0 <0.12.0", 234 | "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.11.0.tgz" 235 | }, 236 | "center-align": { 237 | "version": "0.1.3", 238 | "from": "center-align@>=0.1.1 <0.2.0", 239 | "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz" 240 | }, 241 | "chalk": { 242 | "version": "1.1.3", 243 | "from": "chalk@>=1.1.1 <2.0.0", 244 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz" 245 | }, 246 | "cipher-base": { 247 | "version": "1.0.4", 248 | "from": "cipher-base@>=1.0.0 <2.0.0", 249 | "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz" 250 | }, 251 | "cliui": { 252 | "version": "2.1.0", 253 | "from": "cliui@>=2.1.0 <3.0.0", 254 | "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", 255 | "dependencies": { 256 | "wordwrap": { 257 | "version": "0.0.2", 258 | "from": "wordwrap@0.0.2", 259 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz" 260 | } 261 | } 262 | }, 263 | "coffee-script": { 264 | "version": "1.12.7", 265 | "from": "coffee-script@>=1.0.1", 266 | "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz" 267 | }, 268 | "combine-source-map": { 269 | "version": "0.8.0", 270 | "from": "combine-source-map@>=0.8.0 <0.9.0", 271 | "resolved": "https://registry.npmjs.org/combine-source-map/-/combine-source-map-0.8.0.tgz" 272 | }, 273 | "combined-stream": { 274 | "version": "1.0.6", 275 | "from": "combined-stream@>=1.0.5 <1.1.0", 276 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.6.tgz" 277 | }, 278 | "commander": { 279 | "version": "2.15.1", 280 | "from": "commander@>=2.9.0 <3.0.0", 281 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz" 282 | }, 283 | "concat-map": { 284 | "version": "0.0.1", 285 | "from": "concat-map@0.0.1", 286 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz" 287 | }, 288 | "concat-stream": { 289 | "version": "1.5.2", 290 | "from": "concat-stream@>=1.5.1 <1.6.0", 291 | "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.5.2.tgz", 292 | "dependencies": { 293 | "process-nextick-args": { 294 | "version": "1.0.7", 295 | "from": "process-nextick-args@>=1.0.6 <1.1.0", 296 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz" 297 | }, 298 | "readable-stream": { 299 | "version": "2.0.6", 300 | "from": "readable-stream@>=2.0.0 <2.1.0", 301 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.0.6.tgz" 302 | } 303 | } 304 | }, 305 | "console-browserify": { 306 | "version": "1.1.0", 307 | "from": "console-browserify@>=1.1.0 <2.0.0", 308 | "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz" 309 | }, 310 | "constants-browserify": { 311 | "version": "1.0.0", 312 | "from": "constants-browserify@>=1.0.0 <1.1.0", 313 | "resolved": "https://registry.npmjs.org/constants-browserify/-/constants-browserify-1.0.0.tgz" 314 | }, 315 | "convert-source-map": { 316 | "version": "1.1.3", 317 | "from": "convert-source-map@>=1.1.0 <1.2.0", 318 | "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.1.3.tgz" 319 | }, 320 | "core-util-is": { 321 | "version": "1.0.2", 322 | "from": "core-util-is@>=1.0.0 <1.1.0", 323 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" 324 | }, 325 | "create-ecdh": { 326 | "version": "4.0.1", 327 | "from": "create-ecdh@>=4.0.0 <5.0.0", 328 | "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.1.tgz" 329 | }, 330 | "create-hash": { 331 | "version": "1.2.0", 332 | "from": "create-hash@>=1.1.0 <2.0.0", 333 | "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz" 334 | }, 335 | "create-hmac": { 336 | "version": "1.1.7", 337 | "from": "create-hmac@>=1.1.0 <2.0.0", 338 | "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz" 339 | }, 340 | "cryptiles": { 341 | "version": "2.0.5", 342 | "from": "cryptiles@>=2.0.0 <3.0.0", 343 | "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz" 344 | }, 345 | "crypto-browserify": { 346 | "version": "3.12.0", 347 | "from": "crypto-browserify@>=3.0.0 <4.0.0", 348 | "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz" 349 | }, 350 | "dashdash": { 351 | "version": "1.14.1", 352 | "from": "dashdash@>=1.12.0 <2.0.0", 353 | "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", 354 | "dependencies": { 355 | "assert-plus": { 356 | "version": "1.0.0", 357 | "from": "assert-plus@>=1.0.0 <2.0.0", 358 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" 359 | } 360 | } 361 | }, 362 | "date-now": { 363 | "version": "0.1.4", 364 | "from": "date-now@>=0.1.4 <0.2.0", 365 | "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz" 366 | }, 367 | "decamelize": { 368 | "version": "1.2.0", 369 | "from": "decamelize@>=1.0.0 <2.0.0", 370 | "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz" 371 | }, 372 | "deep-is": { 373 | "version": "0.1.3", 374 | "from": "deep-is@>=0.1.3 <0.2.0", 375 | "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz" 376 | }, 377 | "defined": { 378 | "version": "1.0.0", 379 | "from": "defined@>=1.0.0 <2.0.0", 380 | "resolved": "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz" 381 | }, 382 | "delayed-stream": { 383 | "version": "1.0.0", 384 | "from": "delayed-stream@>=1.0.0 <1.1.0", 385 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz" 386 | }, 387 | "deps-sort": { 388 | "version": "2.0.0", 389 | "from": "deps-sort@>=2.0.0 <3.0.0", 390 | "resolved": "https://registry.npmjs.org/deps-sort/-/deps-sort-2.0.0.tgz" 391 | }, 392 | "des.js": { 393 | "version": "1.0.0", 394 | "from": "des.js@>=1.0.0 <2.0.0", 395 | "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.0.tgz" 396 | }, 397 | "detective": { 398 | "version": "4.7.1", 399 | "from": "detective@>=4.0.0 <5.0.0", 400 | "resolved": "https://registry.npmjs.org/detective/-/detective-4.7.1.tgz", 401 | "dependencies": { 402 | "acorn": { 403 | "version": "5.5.3", 404 | "from": "acorn@>=5.2.1 <6.0.0", 405 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.3.tgz" 406 | } 407 | } 408 | }, 409 | "diffie-hellman": { 410 | "version": "5.0.3", 411 | "from": "diffie-hellman@>=5.0.0 <6.0.0", 412 | "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz" 413 | }, 414 | "domain-browser": { 415 | "version": "1.1.7", 416 | "from": "domain-browser@>=1.1.0 <1.2.0", 417 | "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.1.7.tgz" 418 | }, 419 | "duplexer2": { 420 | "version": "0.1.4", 421 | "from": "duplexer2@>=0.1.2 <0.2.0", 422 | "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz" 423 | }, 424 | "ecc-jsbn": { 425 | "version": "0.1.1", 426 | "from": "ecc-jsbn@>=0.1.1 <0.2.0", 427 | "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz" 428 | }, 429 | "elliptic": { 430 | "version": "6.4.0", 431 | "from": "elliptic@>=6.0.0 <7.0.0", 432 | "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz" 433 | }, 434 | "escape-string-regexp": { 435 | "version": "1.0.5", 436 | "from": "escape-string-regexp@>=1.0.2 <2.0.0", 437 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" 438 | }, 439 | "escodegen": { 440 | "version": "1.8.1", 441 | "from": "escodegen@>=1.8.0 <1.9.0", 442 | "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.8.1.tgz", 443 | "dependencies": { 444 | "source-map": { 445 | "version": "0.2.0", 446 | "from": "source-map@>=0.2.0 <0.3.0", 447 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz" 448 | } 449 | } 450 | }, 451 | "esprima": { 452 | "version": "2.7.3", 453 | "from": "esprima@>=2.6.0 <3.0.0", 454 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz" 455 | }, 456 | "estraverse": { 457 | "version": "1.9.3", 458 | "from": "estraverse@>=1.9.1 <2.0.0", 459 | "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.9.3.tgz" 460 | }, 461 | "esutils": { 462 | "version": "2.0.2", 463 | "from": "esutils@>=2.0.2 <3.0.0", 464 | "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz" 465 | }, 466 | "events": { 467 | "version": "1.1.1", 468 | "from": "events@>=1.1.0 <1.2.0", 469 | "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz" 470 | }, 471 | "evp_bytestokey": { 472 | "version": "1.0.3", 473 | "from": "evp_bytestokey@>=1.0.0 <2.0.0", 474 | "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz" 475 | }, 476 | "exit": { 477 | "version": "0.1.2", 478 | "from": "exit@>=0.1.2 <0.2.0", 479 | "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz" 480 | }, 481 | "extend": { 482 | "version": "3.0.1", 483 | "from": "extend@>=3.0.0 <3.1.0", 484 | "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz" 485 | }, 486 | "extsprintf": { 487 | "version": "1.3.0", 488 | "from": "extsprintf@1.3.0", 489 | "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz" 490 | }, 491 | "fast-levenshtein": { 492 | "version": "2.0.6", 493 | "from": "fast-levenshtein@>=2.0.4 <2.1.0", 494 | "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz" 495 | }, 496 | "fileset": { 497 | "version": "0.1.8", 498 | "from": "fileset@>=0.1.5 <0.2.0", 499 | "resolved": "https://registry.npmjs.org/fileset/-/fileset-0.1.8.tgz", 500 | "dependencies": { 501 | "glob": { 502 | "version": "3.2.11", 503 | "from": "glob@>=3.0.0 <4.0.0", 504 | "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", 505 | "dependencies": { 506 | "minimatch": { 507 | "version": "0.3.0", 508 | "from": "minimatch@>=0.3.0 <0.4.0", 509 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz" 510 | } 511 | } 512 | }, 513 | "minimatch": { 514 | "version": "0.4.0", 515 | "from": "minimatch@>=0.0.0 <1.0.0", 516 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.4.0.tgz" 517 | } 518 | } 519 | }, 520 | "forever-agent": { 521 | "version": "0.6.1", 522 | "from": "forever-agent@>=0.6.1 <0.7.0", 523 | "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz" 524 | }, 525 | "form-data": { 526 | "version": "2.1.4", 527 | "from": "form-data@>=2.1.1 <2.2.0", 528 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz" 529 | }, 530 | "function-bind": { 531 | "version": "1.1.1", 532 | "from": "function-bind@>=1.0.2 <2.0.0", 533 | "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" 534 | }, 535 | "gaze": { 536 | "version": "0.3.4", 537 | "from": "gaze@>=0.3.2 <0.4.0", 538 | "resolved": "https://registry.npmjs.org/gaze/-/gaze-0.3.4.tgz", 539 | "dependencies": { 540 | "minimatch": { 541 | "version": "0.2.14", 542 | "from": "minimatch@>=0.2.9 <0.3.0", 543 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz" 544 | } 545 | } 546 | }, 547 | "generate-function": { 548 | "version": "2.0.0", 549 | "from": "generate-function@>=2.0.0 <3.0.0", 550 | "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz" 551 | }, 552 | "generate-object-property": { 553 | "version": "1.2.0", 554 | "from": "generate-object-property@>=1.1.0 <2.0.0", 555 | "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz" 556 | }, 557 | "getpass": { 558 | "version": "0.1.7", 559 | "from": "getpass@>=0.1.1 <0.2.0", 560 | "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", 561 | "dependencies": { 562 | "assert-plus": { 563 | "version": "1.0.0", 564 | "from": "assert-plus@>=1.0.0 <2.0.0", 565 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" 566 | } 567 | } 568 | }, 569 | "glob": { 570 | "version": "5.0.15", 571 | "from": "glob@>=5.0.15 <6.0.0", 572 | "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz" 573 | }, 574 | "growl": { 575 | "version": "1.7.0", 576 | "from": "growl@>=1.7.0 <1.8.0", 577 | "resolved": "https://registry.npmjs.org/growl/-/growl-1.7.0.tgz" 578 | }, 579 | "handlebars": { 580 | "version": "4.0.11", 581 | "from": "handlebars@>=4.0.1 <5.0.0", 582 | "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", 583 | "dependencies": { 584 | "source-map": { 585 | "version": "0.4.4", 586 | "from": "source-map@>=0.4.4 <0.5.0", 587 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz" 588 | }, 589 | "uglify-js": { 590 | "version": "2.8.29", 591 | "from": "uglify-js@>=2.6.0 <3.0.0", 592 | "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", 593 | "dependencies": { 594 | "source-map": { 595 | "version": "0.5.7", 596 | "from": "source-map@>=0.5.1 <0.6.0" 597 | } 598 | } 599 | } 600 | } 601 | }, 602 | "har-validator": { 603 | "version": "2.0.6", 604 | "from": "har-validator@>=2.0.6 <2.1.0", 605 | "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-2.0.6.tgz" 606 | }, 607 | "has": { 608 | "version": "1.0.1", 609 | "from": "has@>=1.0.0 <2.0.0", 610 | "resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz" 611 | }, 612 | "has-ansi": { 613 | "version": "2.0.0", 614 | "from": "has-ansi@>=2.0.0 <3.0.0", 615 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz" 616 | }, 617 | "has-flag": { 618 | "version": "1.0.0", 619 | "from": "has-flag@>=1.0.0 <2.0.0", 620 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz" 621 | }, 622 | "hash-base": { 623 | "version": "3.0.4", 624 | "from": "hash-base@>=3.0.0 <4.0.0", 625 | "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz" 626 | }, 627 | "hash.js": { 628 | "version": "1.1.3", 629 | "from": "hash.js@>=1.0.0 <2.0.0", 630 | "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz" 631 | }, 632 | "hawk": { 633 | "version": "3.1.3", 634 | "from": "hawk@>=3.1.3 <3.2.0", 635 | "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", 636 | "dependencies": { 637 | "hoek": { 638 | "version": "2.16.3", 639 | "from": "hoek@>=2.0.0 <3.0.0", 640 | "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz" 641 | } 642 | } 643 | }, 644 | "hmac-drbg": { 645 | "version": "1.0.1", 646 | "from": "hmac-drbg@>=1.0.0 <2.0.0", 647 | "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz" 648 | }, 649 | "htmlescape": { 650 | "version": "1.1.1", 651 | "from": "htmlescape@>=1.1.0 <2.0.0", 652 | "resolved": "https://registry.npmjs.org/htmlescape/-/htmlescape-1.1.1.tgz" 653 | }, 654 | "http-signature": { 655 | "version": "1.1.1", 656 | "from": "http-signature@>=1.1.0 <1.2.0", 657 | "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz" 658 | }, 659 | "https-browserify": { 660 | "version": "0.0.1", 661 | "from": "https-browserify@>=0.0.0 <0.1.0", 662 | "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-0.0.1.tgz" 663 | }, 664 | "ieee754": { 665 | "version": "1.1.11", 666 | "from": "ieee754@>=1.1.4 <2.0.0", 667 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.11.tgz" 668 | }, 669 | "indexof": { 670 | "version": "0.0.1", 671 | "from": "indexof@0.0.1", 672 | "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz" 673 | }, 674 | "inflight": { 675 | "version": "1.0.6", 676 | "from": "inflight@>=1.0.4 <2.0.0", 677 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz" 678 | }, 679 | "inherits": { 680 | "version": "2.0.3", 681 | "from": "inherits@>=2.0.1 <2.1.0", 682 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" 683 | }, 684 | "inline-source-map": { 685 | "version": "0.6.2", 686 | "from": "inline-source-map@>=0.6.0 <0.7.0", 687 | "resolved": "https://registry.npmjs.org/inline-source-map/-/inline-source-map-0.6.2.tgz" 688 | }, 689 | "insert-module-globals": { 690 | "version": "7.0.6", 691 | "from": "insert-module-globals@>=7.0.0 <8.0.0", 692 | "resolved": "https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-7.0.6.tgz", 693 | "dependencies": { 694 | "concat-stream": { 695 | "version": "1.6.2", 696 | "from": "concat-stream@>=1.6.1 <2.0.0", 697 | "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz" 698 | } 699 | } 700 | }, 701 | "is-buffer": { 702 | "version": "1.1.6", 703 | "from": "is-buffer@>=1.1.0 <2.0.0", 704 | "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz" 705 | }, 706 | "is-my-ip-valid": { 707 | "version": "1.0.0", 708 | "from": "is-my-ip-valid@>=1.0.0 <2.0.0", 709 | "resolved": "https://registry.npmjs.org/is-my-ip-valid/-/is-my-ip-valid-1.0.0.tgz" 710 | }, 711 | "is-my-json-valid": { 712 | "version": "2.17.2", 713 | "from": "is-my-json-valid@>=2.12.4 <3.0.0", 714 | "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.17.2.tgz" 715 | }, 716 | "is-property": { 717 | "version": "1.0.2", 718 | "from": "is-property@>=1.0.0 <2.0.0", 719 | "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz" 720 | }, 721 | "is-typedarray": { 722 | "version": "1.0.0", 723 | "from": "is-typedarray@>=1.0.0 <1.1.0", 724 | "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz" 725 | }, 726 | "isarray": { 727 | "version": "1.0.0", 728 | "from": "isarray@>=1.0.0 <1.1.0", 729 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz" 730 | }, 731 | "isexe": { 732 | "version": "2.0.0", 733 | "from": "isexe@>=2.0.0 <3.0.0", 734 | "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" 735 | }, 736 | "isstream": { 737 | "version": "0.1.2", 738 | "from": "isstream@>=0.1.2 <0.2.0", 739 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz" 740 | }, 741 | "jasmine-growl-reporter": { 742 | "version": "0.0.3", 743 | "from": "jasmine-growl-reporter@>=0.0.2 <0.1.0", 744 | "resolved": "https://registry.npmjs.org/jasmine-growl-reporter/-/jasmine-growl-reporter-0.0.3.tgz" 745 | }, 746 | "jasmine-reporters": { 747 | "version": "1.0.2", 748 | "from": "jasmine-reporters@>=1.0.0 <1.1.0", 749 | "resolved": "https://registry.npmjs.org/jasmine-reporters/-/jasmine-reporters-1.0.2.tgz", 750 | "dependencies": { 751 | "mkdirp": { 752 | "version": "0.3.5", 753 | "from": "mkdirp@>=0.3.5 <0.4.0", 754 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz" 755 | } 756 | } 757 | }, 758 | "js-yaml": { 759 | "version": "3.6.1", 760 | "from": "js-yaml@3.6.1", 761 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.6.1.tgz" 762 | }, 763 | "jsbn": { 764 | "version": "0.1.1", 765 | "from": "jsbn@>=0.1.0 <0.2.0", 766 | "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz" 767 | }, 768 | "json-schema": { 769 | "version": "0.2.3", 770 | "from": "json-schema@0.2.3", 771 | "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz" 772 | }, 773 | "json-stable-stringify": { 774 | "version": "0.0.1", 775 | "from": "json-stable-stringify@>=0.0.0 <0.1.0", 776 | "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-0.0.1.tgz" 777 | }, 778 | "json-stringify-safe": { 779 | "version": "5.0.1", 780 | "from": "json-stringify-safe@>=5.0.1 <5.1.0", 781 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz" 782 | }, 783 | "jsonify": { 784 | "version": "0.0.0", 785 | "from": "jsonify@>=0.0.0 <0.1.0", 786 | "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz" 787 | }, 788 | "jsonparse": { 789 | "version": "1.3.1", 790 | "from": "jsonparse@>=1.2.0 <2.0.0", 791 | "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz" 792 | }, 793 | "jsonpointer": { 794 | "version": "4.0.1", 795 | "from": "jsonpointer@>=4.0.0 <5.0.0", 796 | "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz" 797 | }, 798 | "JSONStream": { 799 | "version": "1.3.2", 800 | "from": "JSONStream@>=1.0.3 <2.0.0", 801 | "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.2.tgz" 802 | }, 803 | "jsprim": { 804 | "version": "1.4.1", 805 | "from": "jsprim@>=1.2.2 <2.0.0", 806 | "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", 807 | "dependencies": { 808 | "assert-plus": { 809 | "version": "1.0.0", 810 | "from": "assert-plus@1.0.0", 811 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" 812 | } 813 | } 814 | }, 815 | "kind-of": { 816 | "version": "3.2.2", 817 | "from": "kind-of@>=3.0.2 <4.0.0", 818 | "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz" 819 | }, 820 | "labeled-stream-splicer": { 821 | "version": "2.0.1", 822 | "from": "labeled-stream-splicer@>=2.0.0 <3.0.0", 823 | "resolved": "https://registry.npmjs.org/labeled-stream-splicer/-/labeled-stream-splicer-2.0.1.tgz", 824 | "dependencies": { 825 | "isarray": { 826 | "version": "2.0.4", 827 | "from": "isarray@>=2.0.4 <3.0.0", 828 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.4.tgz" 829 | } 830 | } 831 | }, 832 | "lazy-cache": { 833 | "version": "1.0.4", 834 | "from": "lazy-cache@>=1.0.3 <2.0.0", 835 | "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz" 836 | }, 837 | "lcov-parse": { 838 | "version": "0.0.10", 839 | "from": "lcov-parse@0.0.10", 840 | "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-0.0.10.tgz" 841 | }, 842 | "levn": { 843 | "version": "0.3.0", 844 | "from": "levn@>=0.3.0 <0.4.0", 845 | "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz" 846 | }, 847 | "lexical-scope": { 848 | "version": "1.2.0", 849 | "from": "lexical-scope@>=1.2.0 <2.0.0", 850 | "resolved": "https://registry.npmjs.org/lexical-scope/-/lexical-scope-1.2.0.tgz" 851 | }, 852 | "lodash.memoize": { 853 | "version": "3.0.4", 854 | "from": "lodash.memoize@>=3.0.3 <3.1.0", 855 | "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-3.0.4.tgz" 856 | }, 857 | "log-driver": { 858 | "version": "1.2.5", 859 | "from": "log-driver@1.2.5", 860 | "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.5.tgz" 861 | }, 862 | "longest": { 863 | "version": "1.0.1", 864 | "from": "longest@>=1.0.1 <2.0.0", 865 | "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz" 866 | }, 867 | "lru-cache": { 868 | "version": "2.7.3", 869 | "from": "lru-cache@>=2.0.0 <3.0.0", 870 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz" 871 | }, 872 | "md5.js": { 873 | "version": "1.3.4", 874 | "from": "md5.js@>=1.3.4 <2.0.0", 875 | "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz" 876 | }, 877 | "miller-rabin": { 878 | "version": "4.0.1", 879 | "from": "miller-rabin@>=4.0.0 <5.0.0", 880 | "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz" 881 | }, 882 | "mime-db": { 883 | "version": "1.33.0", 884 | "from": "mime-db@>=1.33.0 <1.34.0", 885 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz" 886 | }, 887 | "mime-types": { 888 | "version": "2.1.18", 889 | "from": "mime-types@>=2.1.7 <2.2.0", 890 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz" 891 | }, 892 | "minimalistic-assert": { 893 | "version": "1.0.1", 894 | "from": "minimalistic-assert@>=1.0.0 <2.0.0", 895 | "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz" 896 | }, 897 | "minimalistic-crypto-utils": { 898 | "version": "1.0.1", 899 | "from": "minimalistic-crypto-utils@>=1.0.0 <2.0.0", 900 | "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz" 901 | }, 902 | "minimatch": { 903 | "version": "3.0.4", 904 | "from": "minimatch@>=2.0.0 <3.0.0||>=3.0.0 <4.0.0", 905 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz" 906 | }, 907 | "minimist": { 908 | "version": "1.2.0", 909 | "from": "minimist@>=1.1.0 <2.0.0", 910 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz" 911 | }, 912 | "mkdirp": { 913 | "version": "0.5.1", 914 | "from": "mkdirp@>=0.5.0 <0.6.0", 915 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", 916 | "dependencies": { 917 | "minimist": { 918 | "version": "0.0.8", 919 | "from": "minimist@0.0.8", 920 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" 921 | } 922 | } 923 | }, 924 | "module-deps": { 925 | "version": "4.1.1", 926 | "from": "module-deps@>=4.0.8 <5.0.0", 927 | "resolved": "https://registry.npmjs.org/module-deps/-/module-deps-4.1.1.tgz" 928 | }, 929 | "nopt": { 930 | "version": "3.0.6", 931 | "from": "nopt@>=3.0.0 <4.0.0", 932 | "resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz" 933 | }, 934 | "oauth-sign": { 935 | "version": "0.8.2", 936 | "from": "oauth-sign@>=0.8.1 <0.9.0", 937 | "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz" 938 | }, 939 | "once": { 940 | "version": "1.4.0", 941 | "from": "once@>=1.3.0 <2.0.0", 942 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz" 943 | }, 944 | "optimist": { 945 | "version": "0.6.1", 946 | "from": "optimist@>=0.6.1 <0.7.0", 947 | "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", 948 | "dependencies": { 949 | "minimist": { 950 | "version": "0.0.10", 951 | "from": "minimist@>=0.0.1 <0.1.0", 952 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz" 953 | }, 954 | "wordwrap": { 955 | "version": "0.0.3", 956 | "from": "wordwrap@>=0.0.2 <0.1.0", 957 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz" 958 | } 959 | } 960 | }, 961 | "optionator": { 962 | "version": "0.8.2", 963 | "from": "optionator@>=0.8.1 <0.9.0", 964 | "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz" 965 | }, 966 | "os-browserify": { 967 | "version": "0.1.2", 968 | "from": "os-browserify@>=0.1.1 <0.2.0", 969 | "resolved": "https://registry.npmjs.org/os-browserify/-/os-browserify-0.1.2.tgz" 970 | }, 971 | "pako": { 972 | "version": "0.2.9", 973 | "from": "pako@>=0.2.0 <0.3.0", 974 | "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz" 975 | }, 976 | "parents": { 977 | "version": "1.0.1", 978 | "from": "parents@>=1.0.1 <2.0.0", 979 | "resolved": "https://registry.npmjs.org/parents/-/parents-1.0.1.tgz" 980 | }, 981 | "parse-asn1": { 982 | "version": "5.1.1", 983 | "from": "parse-asn1@>=5.0.0 <6.0.0", 984 | "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz" 985 | }, 986 | "path-browserify": { 987 | "version": "0.0.0", 988 | "from": "path-browserify@>=0.0.0 <0.1.0", 989 | "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz" 990 | }, 991 | "path-is-absolute": { 992 | "version": "1.0.1", 993 | "from": "path-is-absolute@>=1.0.0 <2.0.0", 994 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz" 995 | }, 996 | "path-parse": { 997 | "version": "1.0.5", 998 | "from": "path-parse@>=1.0.5 <2.0.0", 999 | "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz" 1000 | }, 1001 | "path-platform": { 1002 | "version": "0.11.15", 1003 | "from": "path-platform@>=0.11.15 <0.12.0", 1004 | "resolved": "https://registry.npmjs.org/path-platform/-/path-platform-0.11.15.tgz" 1005 | }, 1006 | "pbkdf2": { 1007 | "version": "3.0.16", 1008 | "from": "pbkdf2@>=3.0.3 <4.0.0", 1009 | "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.16.tgz" 1010 | }, 1011 | "pinkie": { 1012 | "version": "2.0.4", 1013 | "from": "pinkie@>=2.0.0 <3.0.0", 1014 | "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz" 1015 | }, 1016 | "pinkie-promise": { 1017 | "version": "2.0.1", 1018 | "from": "pinkie-promise@>=2.0.0 <3.0.0", 1019 | "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz" 1020 | }, 1021 | "prelude-ls": { 1022 | "version": "1.1.2", 1023 | "from": "prelude-ls@>=1.1.2 <1.2.0", 1024 | "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz" 1025 | }, 1026 | "process": { 1027 | "version": "0.11.10", 1028 | "from": "process@>=0.11.0 <0.12.0", 1029 | "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz" 1030 | }, 1031 | "process-nextick-args": { 1032 | "version": "2.0.0", 1033 | "from": "process-nextick-args@>=2.0.0 <2.1.0", 1034 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz" 1035 | }, 1036 | "public-encrypt": { 1037 | "version": "4.0.2", 1038 | "from": "public-encrypt@>=4.0.0 <5.0.0", 1039 | "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.2.tgz" 1040 | }, 1041 | "punycode": { 1042 | "version": "1.4.1", 1043 | "from": "punycode@>=1.3.2 <2.0.0", 1044 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz" 1045 | }, 1046 | "qs": { 1047 | "version": "6.3.2", 1048 | "from": "qs@>=6.3.0 <6.4.0", 1049 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.3.2.tgz" 1050 | }, 1051 | "querystring": { 1052 | "version": "0.2.0", 1053 | "from": "querystring@0.2.0", 1054 | "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz" 1055 | }, 1056 | "querystring-es3": { 1057 | "version": "0.2.1", 1058 | "from": "querystring-es3@>=0.2.0 <0.3.0", 1059 | "resolved": "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz" 1060 | }, 1061 | "randombytes": { 1062 | "version": "2.0.6", 1063 | "from": "randombytes@>=2.0.0 <3.0.0", 1064 | "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz" 1065 | }, 1066 | "randomfill": { 1067 | "version": "1.0.4", 1068 | "from": "randomfill@>=1.0.3 <2.0.0", 1069 | "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.4.tgz" 1070 | }, 1071 | "read-only-stream": { 1072 | "version": "2.0.0", 1073 | "from": "read-only-stream@>=2.0.0 <3.0.0", 1074 | "resolved": "https://registry.npmjs.org/read-only-stream/-/read-only-stream-2.0.0.tgz" 1075 | }, 1076 | "readable-stream": { 1077 | "version": "2.3.6", 1078 | "from": "readable-stream@>=2.0.2 <3.0.0", 1079 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", 1080 | "dependencies": { 1081 | "string_decoder": { 1082 | "version": "1.1.1", 1083 | "from": "string_decoder@>=1.1.1 <1.2.0", 1084 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz" 1085 | } 1086 | } 1087 | }, 1088 | "repeat-string": { 1089 | "version": "1.6.1", 1090 | "from": "repeat-string@>=1.5.2 <2.0.0", 1091 | "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz" 1092 | }, 1093 | "request": { 1094 | "version": "2.79.0", 1095 | "from": "request@2.79.0", 1096 | "resolved": "https://registry.npmjs.org/request/-/request-2.79.0.tgz" 1097 | }, 1098 | "requirejs": { 1099 | "version": "2.3.5", 1100 | "from": "requirejs@>=0.27.1", 1101 | "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.3.5.tgz" 1102 | }, 1103 | "resolve": { 1104 | "version": "1.7.1", 1105 | "from": "resolve@>=1.1.4 <2.0.0", 1106 | "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.7.1.tgz" 1107 | }, 1108 | "right-align": { 1109 | "version": "0.1.3", 1110 | "from": "right-align@>=0.1.1 <0.2.0", 1111 | "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz" 1112 | }, 1113 | "ripemd160": { 1114 | "version": "2.0.2", 1115 | "from": "ripemd160@>=2.0.1 <3.0.0", 1116 | "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz" 1117 | }, 1118 | "safe-buffer": { 1119 | "version": "5.1.2", 1120 | "from": "safe-buffer@>=5.1.1 <6.0.0", 1121 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz" 1122 | }, 1123 | "sha.js": { 1124 | "version": "2.4.11", 1125 | "from": "sha.js@>=2.4.0 <3.0.0", 1126 | "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz" 1127 | }, 1128 | "shasum": { 1129 | "version": "1.0.2", 1130 | "from": "shasum@>=1.0.0 <2.0.0", 1131 | "resolved": "https://registry.npmjs.org/shasum/-/shasum-1.0.2.tgz" 1132 | }, 1133 | "shell-quote": { 1134 | "version": "1.6.1", 1135 | "from": "shell-quote@>=1.4.3 <2.0.0", 1136 | "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.6.1.tgz" 1137 | }, 1138 | "sigmund": { 1139 | "version": "1.0.1", 1140 | "from": "sigmund@>=1.0.0 <1.1.0", 1141 | "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz" 1142 | }, 1143 | "sntp": { 1144 | "version": "1.0.9", 1145 | "from": "sntp@>=1.0.0 <2.0.0", 1146 | "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", 1147 | "dependencies": { 1148 | "hoek": { 1149 | "version": "2.16.3", 1150 | "from": "hoek@>=2.0.0 <3.0.0", 1151 | "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz" 1152 | } 1153 | } 1154 | }, 1155 | "source-map": { 1156 | "version": "0.5.7", 1157 | "from": "source-map@>=0.5.3 <0.6.0", 1158 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz" 1159 | }, 1160 | "sprintf-js": { 1161 | "version": "1.0.3", 1162 | "from": "sprintf-js@>=1.0.2 <1.1.0", 1163 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz" 1164 | }, 1165 | "sshpk": { 1166 | "version": "1.14.1", 1167 | "from": "sshpk@>=1.7.0 <2.0.0", 1168 | "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.1.tgz", 1169 | "dependencies": { 1170 | "assert-plus": { 1171 | "version": "1.0.0", 1172 | "from": "assert-plus@>=1.0.0 <2.0.0", 1173 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" 1174 | } 1175 | } 1176 | }, 1177 | "stream-browserify": { 1178 | "version": "2.0.1", 1179 | "from": "stream-browserify@>=2.0.0 <3.0.0", 1180 | "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz" 1181 | }, 1182 | "stream-combiner2": { 1183 | "version": "1.1.1", 1184 | "from": "stream-combiner2@>=1.1.1 <2.0.0", 1185 | "resolved": "https://registry.npmjs.org/stream-combiner2/-/stream-combiner2-1.1.1.tgz" 1186 | }, 1187 | "stream-http": { 1188 | "version": "2.8.1", 1189 | "from": "stream-http@>=2.0.0 <3.0.0", 1190 | "resolved": "https://registry.npmjs.org/stream-http/-/stream-http-2.8.1.tgz" 1191 | }, 1192 | "stream-splicer": { 1193 | "version": "2.0.0", 1194 | "from": "stream-splicer@>=2.0.0 <3.0.0", 1195 | "resolved": "https://registry.npmjs.org/stream-splicer/-/stream-splicer-2.0.0.tgz" 1196 | }, 1197 | "string_decoder": { 1198 | "version": "0.10.31", 1199 | "from": "string_decoder@>=0.10.0 <0.11.0", 1200 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz" 1201 | }, 1202 | "stringstream": { 1203 | "version": "0.0.5", 1204 | "from": "stringstream@>=0.0.4 <0.1.0", 1205 | "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz" 1206 | }, 1207 | "strip-ansi": { 1208 | "version": "3.0.1", 1209 | "from": "strip-ansi@>=3.0.0 <4.0.0", 1210 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz" 1211 | }, 1212 | "subarg": { 1213 | "version": "1.0.0", 1214 | "from": "subarg@>=1.0.0 <2.0.0", 1215 | "resolved": "https://registry.npmjs.org/subarg/-/subarg-1.0.0.tgz" 1216 | }, 1217 | "supports-color": { 1218 | "version": "2.0.0", 1219 | "from": "supports-color@>=2.0.0 <3.0.0", 1220 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz" 1221 | }, 1222 | "syntax-error": { 1223 | "version": "1.4.0", 1224 | "from": "syntax-error@>=1.1.1 <2.0.0", 1225 | "resolved": "https://registry.npmjs.org/syntax-error/-/syntax-error-1.4.0.tgz" 1226 | }, 1227 | "through": { 1228 | "version": "2.3.8", 1229 | "from": "through@>=2.2.7 <3.0.0", 1230 | "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz" 1231 | }, 1232 | "through2": { 1233 | "version": "2.0.3", 1234 | "from": "through2@>=2.0.0 <3.0.0", 1235 | "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz" 1236 | }, 1237 | "timers-browserify": { 1238 | "version": "1.4.2", 1239 | "from": "timers-browserify@>=1.0.1 <2.0.0", 1240 | "resolved": "https://registry.npmjs.org/timers-browserify/-/timers-browserify-1.4.2.tgz" 1241 | }, 1242 | "to-arraybuffer": { 1243 | "version": "1.0.1", 1244 | "from": "to-arraybuffer@>=1.0.0 <2.0.0", 1245 | "resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz" 1246 | }, 1247 | "tough-cookie": { 1248 | "version": "2.3.4", 1249 | "from": "tough-cookie@>=2.3.0 <2.4.0", 1250 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.4.tgz" 1251 | }, 1252 | "tty-browserify": { 1253 | "version": "0.0.1", 1254 | "from": "tty-browserify@>=0.0.0 <0.1.0", 1255 | "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.1.tgz" 1256 | }, 1257 | "tunnel-agent": { 1258 | "version": "0.4.3", 1259 | "from": "tunnel-agent@>=0.4.1 <0.5.0", 1260 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.4.3.tgz" 1261 | }, 1262 | "tweetnacl": { 1263 | "version": "0.14.5", 1264 | "from": "tweetnacl@>=0.14.0 <0.15.0", 1265 | "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz" 1266 | }, 1267 | "type-check": { 1268 | "version": "0.3.2", 1269 | "from": "type-check@>=0.3.2 <0.4.0", 1270 | "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz" 1271 | }, 1272 | "typedarray": { 1273 | "version": "0.0.6", 1274 | "from": "typedarray@>=0.0.5 <0.1.0", 1275 | "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz" 1276 | }, 1277 | "uglify-to-browserify": { 1278 | "version": "1.0.2", 1279 | "from": "uglify-to-browserify@>=1.0.0 <1.1.0", 1280 | "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz" 1281 | }, 1282 | "umd": { 1283 | "version": "3.0.3", 1284 | "from": "umd@>=3.0.0 <4.0.0", 1285 | "resolved": "https://registry.npmjs.org/umd/-/umd-3.0.3.tgz" 1286 | }, 1287 | "underscore": { 1288 | "version": "1.9.0", 1289 | "from": "underscore@>=1.3.1", 1290 | "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.0.tgz" 1291 | }, 1292 | "url": { 1293 | "version": "0.11.0", 1294 | "from": "url@>=0.11.0 <0.12.0", 1295 | "resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz", 1296 | "dependencies": { 1297 | "punycode": { 1298 | "version": "1.3.2", 1299 | "from": "punycode@1.3.2", 1300 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz" 1301 | } 1302 | } 1303 | }, 1304 | "util": { 1305 | "version": "0.10.3", 1306 | "from": "util@>=0.10.1 <0.11.0", 1307 | "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", 1308 | "dependencies": { 1309 | "inherits": { 1310 | "version": "2.0.1", 1311 | "from": "inherits@2.0.1", 1312 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" 1313 | } 1314 | } 1315 | }, 1316 | "util-deprecate": { 1317 | "version": "1.0.2", 1318 | "from": "util-deprecate@>=1.0.1 <1.1.0", 1319 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz" 1320 | }, 1321 | "uuid": { 1322 | "version": "3.2.1", 1323 | "from": "uuid@>=3.0.0 <4.0.0", 1324 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz" 1325 | }, 1326 | "verror": { 1327 | "version": "1.10.0", 1328 | "from": "verror@1.10.0", 1329 | "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", 1330 | "dependencies": { 1331 | "assert-plus": { 1332 | "version": "1.0.0", 1333 | "from": "assert-plus@>=1.0.0 <2.0.0", 1334 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" 1335 | } 1336 | } 1337 | }, 1338 | "vm-browserify": { 1339 | "version": "0.0.4", 1340 | "from": "vm-browserify@>=0.0.1 <0.1.0", 1341 | "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.4.tgz" 1342 | }, 1343 | "walkdir": { 1344 | "version": "0.0.12", 1345 | "from": "walkdir@>=0.0.1", 1346 | "resolved": "https://registry.npmjs.org/walkdir/-/walkdir-0.0.12.tgz" 1347 | }, 1348 | "which": { 1349 | "version": "1.3.0", 1350 | "from": "which@>=1.1.1 <2.0.0", 1351 | "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz" 1352 | }, 1353 | "window-size": { 1354 | "version": "0.1.0", 1355 | "from": "window-size@0.1.0", 1356 | "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz" 1357 | }, 1358 | "wordwrap": { 1359 | "version": "1.0.0", 1360 | "from": "wordwrap@>=1.0.0 <2.0.0", 1361 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz" 1362 | }, 1363 | "wrappy": { 1364 | "version": "1.0.2", 1365 | "from": "wrappy@>=1.0.0 <2.0.0", 1366 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" 1367 | }, 1368 | "xtend": { 1369 | "version": "4.0.1", 1370 | "from": "xtend@>=4.0.0 <5.0.0", 1371 | "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz" 1372 | }, 1373 | "yargs": { 1374 | "version": "3.10.0", 1375 | "from": "yargs@>=3.10.0 <3.11.0", 1376 | "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz" 1377 | } 1378 | } 1379 | } 1380 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php-unparser", 3 | "version": "0.2.9", 4 | "description": "Unparse the AST produced by glayzzle/php-parser back to code.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "make test", 8 | "prebuild": "node node_modules/jslint/bin/jslint.js --indent 2 --color package.json index.js node_translators/*.js node_translators/**/*.js && node test/index.js", 9 | "build": "node node_modules/browserify/bin/cmd.js index.js -s phpUnparser -o ./dist/php-unparser.js", 10 | "postbuild": "node node_modules/uglifyjs/bin/uglifyjs ./dist/php-unparser.js -o ./dist/php-unparser.min.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git@github.com:chris-l/php-unparser.git" 15 | }, 16 | "keywords": [ 17 | "unparser", 18 | "php", 19 | "ast" 20 | ], 21 | "author": "Christopher Luna ", 22 | "license": "MIT", 23 | "devDependencies": { 24 | "browserify": "13.1.1", 25 | "coveralls": "^2.11.15", 26 | "istanbul": "^0.4.5", 27 | "jasmine-node": "1.14.5", 28 | "jslint": "0.9.6", 29 | "php-parser": "^2.2.0", 30 | "uglifyjs": "2.4.10" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/helper.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true, indent: 2, nomen:true, evil: true */ 2 | 'use strict'; 3 | 4 | var options, parser, unparser, file, fs; 5 | 6 | fs = require('fs'); 7 | parser = require('php-parser'); 8 | unparser = require('../index'); 9 | options = { 10 | parser: { 11 | extractDoc: true, 12 | php7: true 13 | }, 14 | ast: { 15 | withPositions: true 16 | } 17 | }; 18 | 19 | module.exports = function (str) { 20 | return unparser(parser.parseCode(str, options)); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /test/spec/acid1-parsed.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | Hello "achoum", "bashful" => "tadah"]; 38 | 39 | /** 40 | * Something is done here 41 | */ 42 | final public function doSomething() 43 | { 44 | // do not wanna do 45 | foreach ($this->dwarf as $name => $greeting) { 46 | echo 'Hey ho {$name}, {$greeting} !'; 47 | continue $foo; 48 | } 49 | throw new \ComeToHome("Thats it"); 50 | } 51 | } 52 | 53 | interface Miror extends Object 54 | { 55 | public function Am_I_Uggly() : bool; 56 | protected function broken() : bool; 57 | static protected function isWhiteSnowAlive() : bool; 58 | } 59 | 60 | function iter() 61 | { 62 | yield "ator" => $foo; 63 | yield from iter(50); 64 | } 65 | 66 | trait Line 67 | { 68 | public function draw(bool $arrow = false) : string 69 | { 70 | switch ($this->style) { 71 | case "dot": 72 | case "point": 73 | $body = "......"; 74 | break; 75 | default: 76 | $body = "-----"; 77 | break; 78 | } 79 | return $body . ($arrow ? ">" : ""); 80 | } 81 | private function shuut() 82 | { 83 | return __NAMESPACE__; 84 | } 85 | } 86 | 87 | // this is SPARTA ! 88 | function sparta() : ?int 89 | { 90 | global $persians; 91 | $index = -1; 92 | next: 93 | $guy = $persians[++$index]; 94 | if (rand(0, 10) > 5 || false) { 95 | @$guy->kill(); 96 | } else { 97 | $guy->kick(...$foo); 98 | } 99 | 100 | if ((int)$index < count($persians)) { 101 | goto next; 102 | } 103 | return 300 | 5; 104 | } 105 | 106 | $foo = function (?int $bar = 42) use ($something) : bool { 107 | static $banana; 108 | if ($bar > fooBar::NUMBAR) { 109 | while ($bar) { 110 | if ((int)calculateMeaningOfLife() === 42) { 111 | break foo; 112 | } else { 113 | continue; 114 | } 115 | 116 | } 117 | do { 118 | ?> Caesar: here I was 119 | crazy()->boom([1, 2, 3]); 126 | } catch (Coco|Nut $ex) { 127 | $ex->printStackTrace(); 128 | } finally { 129 | if (isset($bipbip, $ex)) { 130 | unset($bipbip, $ex); 131 | } 132 | return (new class extends fooBar { 133 | public function goatIt() 134 | { 135 | return "meeeh"; 136 | } 137 | })->goatIt(); 138 | } 139 | } else { 140 | for ($i = 0; $i < count($this->banana); $i++) { 141 | $x %= ($i * 2) / ($i - 1); 142 | $what = $this->$x[++$i] ? "yes!" : "noo!"; 143 | } 144 | // @todo $this->a_$foo 145 | return $$foo ?? false; 146 | } 147 | 148 | return empty(namespace\FOOBAR); 149 | }; 150 | if ($foo): 151 | echo `bar&`; 152 | elseif ($bar): 153 | echo `ls -larth`; 154 | endif; 155 | 156 | // list version 157 | list($a, list($b, $c)) = [1, [2, 3]]; 158 | print (<< 3 | Hello 'achoum', 34 | 'bashful' => 'tadah' 35 | ]; 36 | /** 37 | * Something is done here 38 | */ 39 | final public function doSomething() { 40 | // do not wanna do 41 | foreach($this->dwarf as $name => $greeting) { 42 | echo "Hey ho $name, $greeting !"; 43 | continue $foo; 44 | } 45 | throw new \ComeToHome('Thats it'); 46 | } 47 | } 48 | 49 | interface Miror extends Object { 50 | public function Am_I_Uggly() : bool; 51 | protected function broken() : bool; 52 | static protected function isWhiteSnowAlive() : bool; 53 | } 54 | 55 | function iter() { 56 | yield 'ator' => $foo; 57 | yield from iter(50); 58 | } 59 | 60 | trait Line { 61 | public function draw(bool $arrow = false) : string { 62 | switch($this->style) { 63 | case 'dot': 64 | case 'point': 65 | $body = '......'; 66 | break; 67 | default: 68 | $body = '-----'; 69 | break; 70 | } 71 | return $body . ($arrow ? '>' : ''); 72 | } 73 | private function shuut() { 74 | return __NAMESPACE__; 75 | } 76 | } 77 | 78 | // this is SPARTA ! 79 | function sparta() : ?int { 80 | global $persians; 81 | 82 | $index = -1; 83 | next: 84 | $guy = $persians[++$index]; 85 | if(rand(0, 10)>5 || false) { 86 | @$guy->kill(); 87 | } else { 88 | $guy->kick(...$foo); 89 | } 90 | if ((int)$index < count($persians)) goto next; 91 | 92 | return 300 | 5; 93 | } 94 | 95 | $foo = function(?int $bar = 42) use($something) : bool { 96 | static $banana; 97 | if($bar > fooBar::NUMBAR) { 98 | while($bar) { 99 | if ((int)calculateMeaningOfLife() === 42) { 100 | break foo; 101 | } else continue; 102 | } 103 | do { 104 | ?> 105 | Caesar: here I was 106 | crazy()->boom([1, 2, 3]); 112 | } catch(Coco|Nut $ex) { 113 | $ex->printStackTrace(); 114 | } finally { 115 | if (isset($bipbip, $ex)) unset($bipbip, $ex); 116 | return (new class extends fooBar { 117 | function goatIt() { 118 | return "meeeh"; 119 | } 120 | })->goatIt(); 121 | } 122 | } else { 123 | for($i = 0; $i < count($this->banana); $i++) { 124 | $x %= ($i * 2) / ($i - 1); 125 | $what = $this->$x[++$i] ? 'yes!': 'noo!'; 126 | } 127 | // @todo $this->a_$foo 128 | return $$foo ?? false; 129 | } 130 | return empty(namespace\FOOBAR); 131 | }; 132 | 133 | if ($foo): 134 | echo `bar&`; 135 | elseif ($bar): 136 | echo `ls -larth`; 137 | endif; 138 | 139 | // list version 140 | list($a, list($b, $c)) = [1, [2, 3]]; 141 | print(<<">')).toBe('
">'); 53 | }); 54 | }); 55 | 56 | describe('acid1.php', function () { 57 | it('must correcty convert nested blocks', function (done) { 58 | fs.readFile('./test/spec/acid1-parsed.php', function (err, strparsed) { 59 | expect(err).toBe(null); 60 | fs.readFile('./test/spec/acid1.php', function (err, str) { 61 | var output = null; 62 | 63 | expect(err).toBe(null); 64 | try { 65 | output = parseUnparse(str.toString()); 66 | } catch (e) { 67 | console.log(e); 68 | } 69 | expect(output === null).toBe(false); 70 | expect(output.trim()).toBe(strparsed.toString().trim()); 71 | done(); 72 | }); 73 | }); 74 | }); 75 | }); 76 | --------------------------------------------------------------------------------