forked from php-gettext/JS-Scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsFunctionsScanner.php
More file actions
40 lines (30 loc) · 964 Bytes
/
JsFunctionsScanner.php
File metadata and controls
40 lines (30 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types = 1);
namespace Gettext\Scanner;
use Peast\Peast;
use Peast\Traverser;
class JsFunctionsScanner implements FunctionsScannerInterface
{
protected $validFunctions;
protected $parser;
public function __construct(?array $validFunctions = null)
{
$this->validFunctions = $validFunctions;
$this->parser('latest');
}
public function parser(string $version, array $options = ['comments' => true]): self
{
$this->parser = [$version, $options];
return $this;
}
public function scan(string $code, string $filename): array
{
[$version, $options] = $this->parser;
$ast = Peast::$version($code, $options)->parse();
$traverser = new Traverser();
$visitor = new JsNodeVisitor($filename, $this->validFunctions);
$traverser->addFunction($visitor);
$traverser->traverse($ast);
return $visitor->getFunctions();
}
}