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

[tests] add test for #9388 #11976

Merged
merged 3 commits into from
Feb 5, 2025
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
50 changes: 37 additions & 13 deletions tests/optimization/src/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,24 @@ class Macro {
className = className.replace(".", "_");
#end
var fields = [];
function checkField(cf:ClassField) {
function checkField(cf:ClassField, isStatic:Bool) {
if (cf.meta.has(":js")) {
fields.push({name: cf.name, js: extractJs(cf.meta.get()), pos: cf.pos});
fields.push({
name: cf.name,
isStatic: isStatic,
js: extractJs(cf.meta.get()),
pos: cf.pos
});
}
}
for (cf in c.statics.get()) {
checkField(cf);
checkField(cf, true);
}
for (cf in c.fields.get()) {
checkField(cf, false);
}
for (field in fields) {
var name = '$className.${field.name}';
var output = getOutput(name);
var output = getOutput(className, field.name, field.isStatic);
++tests;
if (output != field.js) {
++failures;
Expand All @@ -90,19 +97,36 @@ class Macro {
throw false;
}

static function getOutput(identifier:String) {
static function getOutput(cls:String, field:String, isStatic:Bool) {
var buf = new StringBuf();
for (i in 0...lines.length) {
if (lines[i].startsWith(identifier)) {
for (k in (i + 1)...lines.length) {
if (lines[k].startsWith("\t")) {
buf.add(lines[k].trim());
} else {
return buf.toString();
if (isStatic) {
if (lines[i].startsWith('$cls.$field =')) {
for (k in (i + 1)...lines.length) {
if (lines[k].startsWith("\t")) {
buf.add(lines[k].trim());
} else {
return buf.toString();
}
}
}
} else {
if (lines[i].startsWith('$cls.prototype =')) {
for (k in (i + 1)...lines.length) {
if (lines[k].startsWith('\t$field: ') || lines[k].startsWith('\t,$field: ')) {
for (l in (k + 1)...lines.length) {
if (lines[l].startsWith("\t\t")) {
buf.add(lines[l].trim());
} else {
return buf.toString();
}
}
}
}
}
}
}
final identifier = isStatic ? '$cls.$field' : '$cls.prototype.$field';
return Context.error('Could not find $identifier in output', Context.currentPos());
}
}
}
26 changes: 0 additions & 26 deletions tests/optimization/src/TestTreGeneration.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,6 @@ class TestTreGeneration {
return s == null ? a : b;
}

@:js('
if(b == null) {
b = 10;
}
while(true) {
if(Std.random(2) == 0) {
var _gtmp1 = a;
a = b + a;
b = _gtmp1;
s += "?";
continue;
}
if(s == null) {
return a;
} else {
return b;
}
}
')
function testInstanceMethod(a:Int, b:Int = 10, ?s:String):Int {
if(Std.random(2) == 0) {
return testInstanceMethod(b + a, a, s + '?');
}
return s == null ? a : b;
}

@:js('
var local = null;
local = function(a,b,s) {
Expand Down
13 changes: 13 additions & 0 deletions tests/optimization/src/issues/Issue9388.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package issues;

class Issue9388 {
var x(default,set):Int;
function set_x(v) return v;

@:js('
this.set_x(this.x + 1);
')
function f() {
x++;
}
}
Loading