Skip to content

Commit 91a50a0

Browse files
committed
Define can have more deps that callback has arguments.
1 parent aa7e836 commit 91a50a0

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

src/Helper/TypeScript/TypeScriptFixHelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,9 @@ private function fixReferences()
250250
$args = explode(',', $matches['args']);
251251

252252
$replace = [];
253-
foreach ($deps as $key => $dep)
253+
foreach ($args as $key => $arg)
254254
{
255-
$dep = trim($dep, '"');
256-
$arg = $args[$key];
255+
$dep = trim($deps[$key], '"');
257256

258257
if (!in_array($dep, ['require', 'exports']))
259258
{

test/Helper/TypeScript/TypeScriptFixHelperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,34 @@ public function testFixDefineDeps(): void
7272
unlink($jsPath);
7373
}
7474

75+
//--------------------------------------------------------------------------------------------------------------------
76+
/**
77+
* Test fixing defining deps list longer than arguments
78+
*/
79+
public function testMoreDepsThanArguments(): void
80+
{
81+
putenv(sprintf('PLAISIO_CONFIG_DIR=%s', Path::join(__DIR__, __FUNCTION__)));
82+
83+
$jsPath = Path::makeRelative(Path::join(__DIR__, __FUNCTION__, 'js', 'Test', 'Foo.js'), getcwd());
84+
$orgPath = Path::changeExtension($jsPath, 'org.js');
85+
$expectedPath = Path::changeExtension($jsPath, 'expected.js');
86+
copy($orgPath, $jsPath);
87+
88+
$application = new PlaisioApplication();
89+
$application->setAutoExit(false);
90+
91+
$tester = new ApplicationTester($application);
92+
$tester->run(['command' => 'plaisio:type-script-fixer',
93+
'path' => $jsPath]);
94+
95+
if ($tester->getStatusCode()!==0) echo $tester->getDisplay();
96+
97+
self::assertSame(0, $tester->getStatusCode());
98+
self::assertFileEquals($expectedPath, $jsPath);
99+
100+
unlink($jsPath);
101+
}
102+
75103
//--------------------------------------------------------------------------------------------------------------------
76104
}
77105

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define("Test/Foo", ["require", "exports", "Test/Foo", "Test/Bar", "Test/Eggs", "jquery", "jquery-ui"], function (require, exports, Foo_1, Bar_1, Eggs_1, $) {
2+
"use strict";
3+
4+
class Foo {
5+
// Nothing to do.
6+
}
7+
Foo.NahouwPage = Foo;
8+
9+
return Foo;
10+
});
11+
// Modified by Plaisio\Console\Helper\TypeScript\TypeScriptFixHelper
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define(["require", "exports", "./Foo", "./Bar", "./Eggs", "jquery", "jquery-ui"], function (require, exports, Foo_1, Bar_1, Eggs_1, $) {
2+
"use strict";
3+
Object.defineProperty(exports, "__esModule", { value: true });
4+
class Foo {
5+
// Nothing to do.
6+
}
7+
Foo.NahouwPage = Foo;
8+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<assets>
3+
<root>test/Helper/TypeScript/testMoreDepsThanArguments</root>
4+
</assets>

0 commit comments

Comments
 (0)