Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Allow special names in use statements
Browse files Browse the repository at this point in the history
fixes #2
  • Loading branch information
fredemmott committed Jun 23, 2017
1 parent ed8c88b commit b94f265
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/consumers/ScopeConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ private function consumeUseStatement(): ImmMap<string, string> {
$this->consumeWhitespace();
list($token, $type) = $this->tq->shift();

if ($type === T_STRING) {
if (StringishTokens::isValid($type)) {
$parts[] = $token;
continue;
} else if ($type === T_NS_SEPARATOR) {
Expand Down Expand Up @@ -641,7 +641,7 @@ private function consumeAlias(): string {
}

list($name, $type) = $this->tq->shift();
if($type !== T_STRING) {
if (!StringishTokens::isValid($type)) {
invariant_violation(
'Unexpected token %s',
var_export($name, true),
Expand Down
16 changes: 16 additions & 0 deletions tests/NamingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ public function testSpecialNameAsNamespaceName(string $type): void {
$this->assertNotNull($class);
}

/** @dataProvider specialNameProvider */
public function testSpecialNameAsUsedName(string $type): void {
$data = '<?hh use Foo\\'.$type.'; class Herp extends '.$type.' { }';
$parser = FileParser::FromData($data);
$class = $parser->getClass('Herp');
$this->assertNotNull($class);
}

/** @dataProvider specialNameProvider */
public function testSpecialNameAsUsedAsName(string $type): void {
$data = '<?hh use Foo\\Bar as '.$type.'; class Herp extends '.$type.' { }';
$parser = FileParser::FromData($data);
$class = $parser->getClass('Herp');
$this->assertNotNull($class);
}

public function testConstantCalledOn(): void {
$data = '<?hh class Foo { const ON = 0; }';

Expand Down

0 comments on commit b94f265

Please sign in to comment.