Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep getting ast children as Inline #89

Closed
b4dnewz opened this issue Sep 26, 2017 · 4 comments
Closed

Keep getting ast children as Inline #89

b4dnewz opened this issue Sep 26, 2017 · 4 comments
Assignees
Milestone

Comments

@b4dnewz
Copy link
Member

b4dnewz commented Sep 26, 2017

I'm trying for the first time this plugin that look awesome but I'm getting all the time the childrens as Inline and when I try to search for classes or else returns null.

<?php 
class Test {
  function foo() {
  }
}
?>
const contents = fs.readFileSync( './test.php' );
const ast = parser.parseCode(contents, {});
console.log('AST:', ast);
 kind: 'program',
  children:
   [ Inline {
       kind: 'inline',
       value: '60631121041123213101310991089711511532841011151164041321231310323213103232102117110991161051111103210211111140413212313103232323213103232125131032321310125131013106362' } 
  ],
  errors: []

Am I missing some option?

Many thanks in advance, awesome tool.

@b4dnewz
Copy link
Member Author

b4dnewz commented Sep 26, 2017

const contents = fs.readFileSync( './test.php', 'uft8' );

I've resolved it, the trick is to use utf8 as encoding to return a string instead of a buffer from fs.readFile function, but the documentation is tricky, here says it accepts a string buffer., it should be more precise I think.

By the way, I finally start using this great tool!

@b4dnewz b4dnewz closed this as completed Sep 26, 2017
@ichiriac
Copy link
Member

I've just saw it, confusing String buffer - ok, I'll add a check in order to see if you pass a buffer it will automatically be converted to a string

@ichiriac ichiriac reopened this Sep 27, 2017
@ichiriac ichiriac self-assigned this Sep 27, 2017
@ichiriac ichiriac added this to the 2.1.0 milestone Sep 27, 2017
@b4dnewz
Copy link
Member Author

b4dnewz commented Sep 30, 2017

@ichiriac I've forked all of the php-packages and applied some small changes and wrote a little bit of documentation, if you are interested I can make a PR for that.

I'm using php-writer, which depends on php-parser and php-unparser in a project.

@ichiriac
Copy link
Member

yes of course, any PR is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants