Code Monkey home page Code Monkey logo

php-unparser's People

Contributors

bbtgp avatar chris-l avatar ichiriac avatar sevavietl avatar wimpheling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-unparser's Issues

Rebuild PHP code with comments

Hi @chris-l

I would like to use your unparser to generate php code for this project : https://github.com/ichiriac/pdoMap and I would like to also support comment blocks.

I've releases php-parser under 0.1.4 and it's now handling comment blocks :
https://github.com/glayzzle/php-parser/blob/master/src/parser/comment.js

But be aware, into the class body, comments decorate properties, constants, and methods : https://github.com/glayzzle/php-parser/blob/master/src/parser/class.js#L135

How much is this module support nodejs version

I use nodejs v6.1.0,The following error occurred
`C:\Users\Administrator\Desktop\php-test>node index.js
C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\node_translators\index.js:26
throw new Error(
^

Error: Unhandled node type [use]
at CodeGen.process (C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\node_translators\index.js:26:13)
at C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\node_translators\helper\body.js:15:30
at Array.map (native)
at module.exports (C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\node_translators\helper\body.js:11:14)
at CodeGen.module.exports [as program] (C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\node_translators\program.js:10:7)
at CodeGen.process (C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\node_translators\index.js:24:29)
at module.exports (C:\Users\Administrator\Desktop\php-test\node_modules\php-unparser\index.js:8:18)
at Object. (C:\Users\Administrator\Desktop\php-test\index.js:6:13)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)

`

Compatability with php-parser 3.0

It looks like there are some breaking changes in the coming php-parser 3.0 that results in php-unparser being unable to use its output to unparse. Specifically I had problems with simple string arrays.

<?

return [
  "xzczxc",
  "qweqweqwe"
];
Node: xzczxc
Node kind: undefined
{ Error: Bad AST structure
    at CodeGen.process (/home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/index.js:42:13)
    at /home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/array.js:11:19
    at Array.map (<anonymous>)
    at CodeGen.module.exports [as array] (/home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/array.js:19:25)
    at CodeGen.process (/home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/index.js:32:31)
    at /home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/array.js:11:19
    at Array.map (<anonymous>)
    at CodeGen.module.exports [as array] (/home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/array.js:19:25)
    at CodeGen.process (/home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/index.js:32:31)
    at CodeGen.module.exports [as return] (/home/vagrant/apps/translation-scripts/node_modules/php-unparser/node_translators/return.js:12:22) node: 'xzczxc' }

Supporting the leadingComments array

Hello!
First off, thank you for your work here. It's saved me many hours of figuring out how to do this myself ๐Ÿ˜„

I am trying to build a small program to generate PHPUnit tests based off of the class, right now the only thing really preventing me from implementing anything is having the leadingComments supported

"leadingComments": [
    {
        "kind": "commentblock",
        "value": "/**\n * Class " + classObject.name + 'Test' + "\n * @package Tests\\Unit\\Console\\Commands\\ADFRequest\n */"
    }
],

My company uses declare(strict_types=1); and has a comment above it for a file comment and right now the unparser doesn't support any kind of leading comments.

Here is what the parser generates:

{
        "kind": "program",
        "children": [
                {
                    "kind": "declare",
                    "leadingComments": [
                        {
                            "kind": "commentblock",
                            "value": "/**\n * Tests the class\n */"
                        }
                    ],
                    "children": [],
                    "what": {
                        "strict_types": {
                            "kind": "number",
                            "value": "1"
                        }
                    },
                    "mode": "none"
                },
                // Other class item
       ]
}

And in PHP it would look like this:

<?php
/**
 * Tests the class
 */
 declare(strict_types=1);

Adding support for the leading comments would be deeply appreciated.

Bad AST structure, expects array

The example from the documentation throws this error:

var unparse = require('php-unparser');
var ast = {
  "kind": "program",
  "children": [
    {
      "kind": "echo",
      "arguments": [
        {
          "kind": "string",
          "value": "hello world",
          "isDoubleQuote": true
        }
      ]
    }
  ],
  "errors": []
};

console.log(unparse(ast));
Error: Bad AST structure, expects array
    at CodeGen.process (C:\Users\winflop\Desktop\test\php-parse\node_modules\php-unparser\node_translators\index.js:34:11)
    at module.exports (C:\Users\winflop\Desktop\test\php-parse\node_modules\php-unparser\index.js:14:18)

Support for php-parser @ 2.0.0

Hi @chris-l & wish you a happy new year,

I wish to implement the support of the new version of php-parser based on object nodes. There will be a lot of files changed (almost every file), so how would you like to proceed ?

I could open a new branch named version 0.1.5 for example ?

dangerous process.exit

in NPM version 0.1.3, php-unparser/node_translators/index.js has a process.exit(), which is quite dangerous. Could you change it to exceptions as in github version?

Improve tests in order to validate resulting code

As explained here : #12 (comment)

Tests are actually just testing that the library executes writers, but does not check output.

One thing could make the test more robust, I should do something like this :

  • parse a file
  • unparse a file
  • parse again the unparser code
  • test matching around both codes
    (maybe ignore comments from initial parsing in order to avoid edge case problems)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.