Skip to content

Commit

Permalink
don't decompile non-shadow blocks within shadows (#10371)
Browse files Browse the repository at this point in the history
* don't decompile non-shadow blocks within shadows

* fix decompiler test
  • Loading branch information
riknoll authored Feb 5, 2025
1 parent 7bb54a3 commit ab46892
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 17 additions & 1 deletion pxtcompiler/emitter/decompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace ts.pxtc.decompiler {
value: OutputNode;
shadowType?: string;
shadowMutation?: pxt.Map<string>;
emitShadowOnly?: boolean;
}

interface MutationChild {
Expand Down Expand Up @@ -3929,6 +3930,10 @@ ${output}</xml>`;
}

function shouldEmitShadowOnly(n: ValueNode) {
if (n.emitShadowOnly !== undefined) {
return n.emitShadowOnly;
}

let emitShadowOnly = false;

if (n.value.kind === "expr") {
Expand All @@ -3948,11 +3953,22 @@ ${output}</xml>`;
case "logic_boolean":
case "text":
emitShadowOnly = !n.shadowType;
break
break;
}
}

if (emitShadowOnly && value.inputs) {
for (const input of value.inputs) {
if (!shouldEmitShadowOnly(input)) {
emitShadowOnly = false;
break;
}
}
}
}

n.emitShadowOnly = emitShadowOnly;

return emitShadowOnly;
}
}
10 changes: 6 additions & 4 deletions tests/decompile-test/baselines/compile_hidden_arguments.blocks
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
<block type="soundExpression_playSoundEffect">
<field name="mode">SoundExpressionPlayMode.UntilDone</field>
<value name="sound">
<shadow type="soundExpression_createSoundEffect">
<shadow type="soundExpression_createSoundEffect"/>
<block type="soundExpression_createSoundEffect">
<mutation _expanded="5" />
<field name="waveShape">WaveShape.Sine</field>
<field name="effect">SoundExpressionEffect.None</field>
Expand Down Expand Up @@ -92,13 +93,14 @@
<field name="SLIDER">50</field>
</shadow>
</value>
</shadow>
</block>
</value>
<next>
<block type="soundExpression_playSoundEffect">
<field name="mode">SoundExpressionPlayMode.UntilDone</field>
<value name="sound">
<shadow type="soundExpression_createSoundEffect">
<shadow type="soundExpression_createSoundEffect"/>
<block type="soundExpression_createSoundEffect">
<mutation _expanded="3" />
<field name="waveShape">WaveShape.Sine</field>
<field name="effect">SoundExpressionEffect.None</field>
Expand Down Expand Up @@ -145,7 +147,7 @@
</value>
</block>
</value>
</shadow>
</block>
</value>
</block>
</next>
Expand Down

0 comments on commit ab46892

Please sign in to comment.