-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[String_] Add rawValue attribute #831
Conversation
Isn't use PhpParser\Lexer\Emulative;
use PhpParser\ParserFactory;
$options = ['usedAttributes' => ['comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos']];
$lexer = new Emulative($options);
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer);
$code = '<?php
Foo::bar("This is a string with escape sequence \x41");
';
$ast = $parser->parse($code);
$node = $ast[0]->expr->args[0]->value;
$startFilePos = $node->getStartFilePos();
$endFilePos = $node->getEndFilePos();
var_dump(substr($code, $startFilePos, $endFilePos - $startFilePos + 1)); |
Avoiding work with tokens to get original value is exactly point. During Rector upgrade it might be crutial to know the original value, not to replace something deprecated. |
But |
That seems like a work around. The change of value is the issue. |
b3649e5
to
79dda78
Compare
Added |
79dda78
to
1cdfe02
Compare
2aef98b
to
8c3d790
Compare
Updated and rebased 👍 Ready for review ✔️ |
Thanks 👍 |
Probably this should be added to EncapsedStringPart as well? |
What exactly do you mean? Have |
I mean having a rawValue attribute. It seems inconsistent to only add it to non-interpolated strings. |
I'm on it 😉 |
See #837 |
In Rector we have to hack around tokens to get the original value, because the
parse()
method flattens original information:PHP-Parser/lib/PhpParser/Node/Scalar/String_.php
Lines 55 to 72 in a6e3466
We could use also attribute value, but it would require more grammar changes.
Closes #577
Also fixes #576