Skip to content
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

fix: reslove list access with variable key #95

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/langs/php/combinator.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,10 @@ class Combinator extends CombinatorBase {
pre += `["${pathName}"]`;
}
} else if (path.type === 'list') {
if (path.isVar) {
pre += `[$${pathName}]`;
} else if (path.name instanceof Grammer) {
if (path.name instanceof Grammer) {
pre += `[${pathName}]`;
} else if (path.isVar) {
pre += `[$${pathName}]`;
} else {
pre += `[${pathName}]`;
}
Expand Down
3 changes: 0 additions & 3 deletions src/resolver/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,6 @@ class ClientResolver extends BaseResolver {
if (object.inferred) {
valGrammer.dataType = this.resolveTypeItem(object.inferred);
}
if (!valGrammer.dataType) {
debug.stack('Invalid GrammerValue.dataType', valGrammer, object);
}

return valGrammer;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/expected/complex/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ public static function arrayAccess2(){
]
];
$config = @$data["configs"][0];
$i = 0;
$config = @$data["configs"][$i];
return $config;
}

Expand All @@ -249,6 +251,8 @@ public static function arrayAccess3($request){
*/
public static function arrayAccess4($request, $config, $index){
@$request->configs->value[$index] = $config;
$i = 1;
@$request->configs->value[$i] = $config;
}

/**
Expand Down Expand Up @@ -328,6 +332,8 @@ public static function mapAccess3(){
*/
public static function mapAssign($request, $name){
$request->configs->extra["name"] = $name;
$key = "name";
$request->configs->extra[$key] = $name;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/complex/main.dara
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ static function arrayAccess2(): string {
configs = ['a', 'b', 'c']
};
var config = data.configs[0];
var i : integer = 0;
config = data.configs[i];
return config;
}

Expand All @@ -153,6 +155,8 @@ static function arrayAccess3(request: ComplexRequest): string {

static function arrayAccess4(request: ComplexRequest, config: string, index: int16): void {
request.configs.value[index] = config;
var i : integer = 1;
request.configs.value[i] = config;
}

static function arrayAssign(config: string): [ string ] {
Expand Down Expand Up @@ -195,6 +199,8 @@ static function mapAccess3(): string {

static function mapAssign(request: ComplexRequest, name: string): void {
request.configs.extra['name'] = name;
var key = 'name';
request.configs.extra[key] = name;
}

async function TemplateString(): string {
Expand Down