Commaaa2
This commit is contained in:
62
vendor/psy/psysh/src/CodeCleaner.php
vendored
62
vendor/psy/psysh/src/CodeCleaner.php
vendored
@@ -94,10 +94,6 @@ class CodeCleaner
|
||||
*/
|
||||
private function getDefaultPasses(): array
|
||||
{
|
||||
if ($this->yolo) {
|
||||
return $this->getYoloPasses();
|
||||
}
|
||||
|
||||
$useStatementPass = new UseStatementPass();
|
||||
$namespacePass = new NamespacePass($this);
|
||||
|
||||
@@ -105,6 +101,25 @@ class CodeCleaner
|
||||
// based on the file in which the `debug` call was made.
|
||||
$this->addImplicitDebugContext([$useStatementPass, $namespacePass]);
|
||||
|
||||
// A set of code cleaner passes that don't try to do any validation, and
|
||||
// only do minimal rewriting to make things work inside the REPL.
|
||||
//
|
||||
// When in --yolo mode, these are the only code cleaner passes used.
|
||||
$rewritePasses = [
|
||||
new LeavePsyshAlonePass(),
|
||||
$useStatementPass, // must run before the namespace pass
|
||||
new ExitPass(),
|
||||
new ImplicitReturnPass(),
|
||||
new MagicConstantsPass(),
|
||||
$namespacePass, // must run after the implicit return pass
|
||||
new RequirePass(),
|
||||
new StrictTypesPass($this->strictTypes),
|
||||
];
|
||||
|
||||
if ($this->yolo) {
|
||||
return $rewritePasses;
|
||||
}
|
||||
|
||||
return [
|
||||
// Validation passes
|
||||
new AbstractClassPass(),
|
||||
@@ -116,7 +131,6 @@ class CodeCleaner
|
||||
new FunctionReturnInWriteContextPass(),
|
||||
new IssetPass(),
|
||||
new LabelContextPass(),
|
||||
new LeavePsyshAlonePass(),
|
||||
new ListPass(),
|
||||
new LoopContextPass(),
|
||||
new PassableByReferencePass(),
|
||||
@@ -125,13 +139,7 @@ class CodeCleaner
|
||||
new ValidConstructorPass(),
|
||||
|
||||
// Rewriting shenanigans
|
||||
$useStatementPass, // must run before the namespace pass
|
||||
new ExitPass(),
|
||||
new ImplicitReturnPass(),
|
||||
new MagicConstantsPass(),
|
||||
$namespacePass, // must run after the implicit return pass
|
||||
new RequirePass(),
|
||||
new StrictTypesPass($this->strictTypes),
|
||||
...$rewritePasses,
|
||||
|
||||
// Namespace-aware validation (which depends on aforementioned shenanigans)
|
||||
new ValidClassNamePass(),
|
||||
@@ -139,36 +147,6 @@ class CodeCleaner
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* A set of code cleaner passes that don't try to do any validation, and
|
||||
* only do minimal rewriting to make things work inside the REPL.
|
||||
*
|
||||
* This list should stay in sync with the "rewriting shenanigans" in
|
||||
* getDefaultPasses above.
|
||||
*
|
||||
* @return CodeCleanerPass[]
|
||||
*/
|
||||
private function getYoloPasses(): array
|
||||
{
|
||||
$useStatementPass = new UseStatementPass();
|
||||
$namespacePass = new NamespacePass($this);
|
||||
|
||||
// Try to add implicit `use` statements and an implicit namespace,
|
||||
// based on the file in which the `debug` call was made.
|
||||
$this->addImplicitDebugContext([$useStatementPass, $namespacePass]);
|
||||
|
||||
return [
|
||||
new LeavePsyshAlonePass(),
|
||||
$useStatementPass, // must run before the namespace pass
|
||||
new ExitPass(),
|
||||
new ImplicitReturnPass(),
|
||||
new MagicConstantsPass(),
|
||||
$namespacePass, // must run after the implicit return pass
|
||||
new RequirePass(),
|
||||
new StrictTypesPass($this->strictTypes),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* "Warm up" code cleaner passes when we're coming from a debug call.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user