diff --git a/tests/optimization/src/Macro.hx b/tests/optimization/src/Macro.hx index e8d5f740067..5aacca3c2a5 100644 --- a/tests/optimization/src/Macro.hx +++ b/tests/optimization/src/Macro.hx @@ -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; @@ -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()); } -} \ No newline at end of file +} diff --git a/tests/optimization/src/TestTreGeneration.hx b/tests/optimization/src/TestTreGeneration.hx index 040d41e9f93..b29f4a35b26 100644 --- a/tests/optimization/src/TestTreGeneration.hx +++ b/tests/optimization/src/TestTreGeneration.hx @@ -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) { diff --git a/tests/optimization/src/issues/Issue9388.hx b/tests/optimization/src/issues/Issue9388.hx new file mode 100644 index 00000000000..0fb0b5dedf3 --- /dev/null +++ b/tests/optimization/src/issues/Issue9388.hx @@ -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++; + } +}