This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit 96ea15014627e6d5fbb0fef901d0e20ab6fff448 Author: Josh Tynjala <[email protected]> AuthorDate: Mon Sep 15 16:02:42 2025 -0700 MXMLClassDirectiveProcessor: allow fx:RegExp declaration in MXML when targeting SWF --- .../as/codegen/MXMLClassDirectiveProcessor.java | 32 ++++++++++- .../test/java/mxml/tags/MXMLRegExpTagTests.java | 64 ++++++++++++++++++++++ .../internal/tree/mxml/MXMLRegExpNodeTests.java | 33 +++++++++++ 3 files changed, 126 insertions(+), 3 deletions(-) diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java b/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java index 1d930102e..2cb350516 100644 --- a/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java +++ b/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/MXMLClassDirectiveProcessor.java @@ -3012,18 +3012,44 @@ public class MXMLClassDirectiveProcessor extends ClassDirectiveProcessor // by the expression node being null. if (isDataBindingNode(regexpNode)) return; + + boolean childrenAsDataCodeGen = isChildrenAsDataCodeGen(regexpNode, context); + + String id = null; + Context currentContext = context; + + if (getProject().getTargetSettings().getMxmlChildrenAsData() + && regexpNode.getParent() != null + && regexpNode.getParent().getNodeID() == ASTNodeID.MXMLDeclarationsID) + { + id = regexpNode.getEffectiveID(); + if (id != null) + { + currentContext = currentContext.parentContext; + currentContext.startUsing(IL.PROPERTIES); + currentContext.addInstruction(OP_pushstring, id); + } + } + + if (childrenAsDataCodeGen) + currentContext.addInstruction(OP_pushtrue); // simple type IExpressionNode expressionNode = (IExpressionNode)regexpNode.getExpressionNode(); if (expressionNode != null ) { InstructionList init_expression = classScope.getGenerator().generateInstructions( expressionNode, CmcEmitter.__expression_NT, this.classScope); - context.addAll(init_expression); + currentContext.addAll(init_expression); } else { - context.addInstruction(OP_findpropstrict, ABCGeneratingReducer.regexType); - context.addInstruction(OP_constructprop, new Object[] {ABCGeneratingReducer.regexType, 0}); + currentContext.addInstruction(OP_findpropstrict, ABCGeneratingReducer.regexType); + currentContext.addInstruction(OP_constructprop, new Object[] {ABCGeneratingReducer.regexType, 0}); + } + + if (id != null) + { + currentContext.stopUsing(IL.PROPERTIES, 1); } } diff --git a/compiler/src/test/java/mxml/tags/MXMLRegExpTagTests.java b/compiler/src/test/java/mxml/tags/MXMLRegExpTagTests.java new file mode 100644 index 000000000..079f764ec --- /dev/null +++ b/compiler/src/test/java/mxml/tags/MXMLRegExpTagTests.java @@ -0,0 +1,64 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package mxml.tags; + +import org.junit.Test; + +/** + * Feature tests for the MXML {@code <RegExp>} tag. + */ +public class MXMLRegExpTagTests extends MXMLInstanceTagTestsBase +{ + @Test + public void MXMLRegExpTag_basic() + { + String[] declarations = new String[] + { + "<fx:RegExp id='r1'>/abc123/</fx:RegExp>", + "<fx:RegExp id='r2'>/xyz987/sxgim</fx:RegExp>", + "<fx:RegExp id='r3'>/[a-z]{3,} \\d+(oz|g)/ig</fx:RegExp>", + }; + String[] asserts = new String[] + { + "assertEqual('r1', \"abc123\", r1.source);", + "assertEqual('r1', false, r1.dotall);", + "assertEqual('r1', false, r1.extended);", + "assertEqual('r1', false, r1.global);", + "assertEqual('r1', false, r1.ignoreCase);", + "assertEqual('r1', false, r1.multiline);", + + "assertEqual('r2', \"xyz987\", r2.source);", + "assertEqual('r2', true, r2.dotall);", + "assertEqual('r2', true, r2.extended);", + "assertEqual('r2', true, r2.global);", + "assertEqual('r2', true, r2.ignoreCase);", + "assertEqual('r2', true, r2.multiline);", + + "assertEqual('r3', \"[a-z]{3,} \\\\d+(oz|g)\", r3.source);", + "assertEqual('r3', false, r3.dotall);", + "assertEqual('r3', false, r3.extended);", + "assertEqual('r3', true, r3.global);", + "assertEqual('r3', true, r3.ignoreCase);", + "assertEqual('r3', false, r3.multiline);", + }; + String mxml = getMXML(declarations, asserts); + compileAndRun(mxml); + } +} diff --git a/compiler/src/test/java/org/apache/royale/compiler/internal/tree/mxml/MXMLRegExpNodeTests.java b/compiler/src/test/java/org/apache/royale/compiler/internal/tree/mxml/MXMLRegExpNodeTests.java index c5a7ea238..ce6572a51 100644 --- a/compiler/src/test/java/org/apache/royale/compiler/internal/tree/mxml/MXMLRegExpNodeTests.java +++ b/compiler/src/test/java/org/apache/royale/compiler/internal/tree/mxml/MXMLRegExpNodeTests.java @@ -24,6 +24,8 @@ import static org.junit.Assert.assertThat; import org.apache.royale.compiler.tree.ASTNodeID; import org.apache.royale.compiler.tree.as.IASNode; +import org.apache.royale.compiler.tree.as.IRegExpLiteralNode; +import org.apache.royale.compiler.tree.as.IRegExpLiteralNode.RegExpFlag; import org.apache.royale.compiler.tree.mxml.IMXMLFileNode; import org.apache.royale.compiler.tree.mxml.IMXMLRegExpNode; import org.junit.Ignore; @@ -78,6 +80,37 @@ public class MXMLRegExpNodeTests extends MXMLExpressionNodeBaseTests assertThat("getExpressionNode", node.getExpressionNode(), is((IASNode)null)); } + @Test + public void MXMLRegExpNode_empty4() + { + String[] code = new String[] + { + "<fx:RegExp>//</fx:RegExp>" + }; + IMXMLRegExpNode node = getMXMLRegExpNode(code); + assertThat("getExpressionNode", node.getExpressionNode(), is((IASNode)null)); + } + + @Test + public void MXMLRegExpNode_expression() + { + String[] code = new String[] + { + "<fx:RegExp>/[a-z]{3,} \\d+(oz|g)/ig</fx:RegExp>" + }; + IMXMLRegExpNode node = getMXMLRegExpNode(code); + assertThat("getExpressionNode", node.getExpressionNode().getNodeID(), is(ASTNodeID.LiteralRegexID)); + testExpressionLocation(node, 11, 34); + IRegExpLiteralNode literalNode = (IRegExpLiteralNode) node.getExpressionNode(); + assertThat("getValue", literalNode.getValue(), is("[a-z]{3,} \\d+(oz|g)")); + assertThat("getFlags().contains(s)", literalNode.getFlags().contains(RegExpFlag.DOTALL), is(false)); + assertThat("getFlags().contains(x)", literalNode.getFlags().contains(RegExpFlag.EXTENDED), is(false)); + assertThat("getFlags().contains(g)", literalNode.getFlags().contains(RegExpFlag.GLOBAL), is(true)); + assertThat("getFlags().contains(i)", literalNode.getFlags().contains(RegExpFlag.IGNORECASE), is(true)); + assertThat("getFlags().contains(m)", literalNode.getFlags().contains(RegExpFlag.MULTILINE), is(false)); + assertThat("getValue(raw)", literalNode.getValue(true), is("/[a-z]{3,} \\d+(oz|g)/ig")); + } + @Ignore @Test public void MXMLRegExpNode_with_databinding()
