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
The following commit(s) were added to refs/heads/develop by this push:
new 2f14d6d5e compiler: strict-flex-css compiler option
2f14d6d5e is described below
commit 2f14d6d5ea113c209220eef39bb6cf5de880b9e5
Author: Josh Tynjala <[email protected]>
AuthorDate: Tue May 28 12:54:42 2024 -0700
compiler: strict-flex-css compiler option
Optionally enables CSS syntax limitations that match Flex. Mainly intended
to be used by tooling to support legacy Flex projects so that correct problems
are reported.
---
RELEASE_NOTES.md | 1 +
.../royale/compiler/config/Configuration.java | 24 ++++++++++++++++++++++
.../royale/compiler/projects/ICompilerProject.java | 5 +++++
.../royale/compiler/clients/JSConfiguration.java | 1 +
.../royale/compiler/internal/css/CSSDocument.java | 15 ++++++++++++++
.../internal/parsing/as/ConfigProcessor.java | 6 ++++++
.../compiler/internal/projects/ASCProject.java | 6 ++++++
.../compiler/internal/projects/RoyaleProject.java | 15 ++++++++++++++
.../projects/RoyaleProjectConfigurator.java | 1 +
.../compiler/internal/tree/mxml/MXMLStyleNode.java | 14 ++++++++++++-
.../internal/units/StyleModuleCompilationUnit.java | 9 +++++++-
11 files changed, 95 insertions(+), 2 deletions(-)
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 43ad7023e..977cf428b 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -5,6 +5,7 @@ Apache Royale Compiler 0.9.11
- compiler: Added new `--infer-types` compiler option that allows the compiler
to automatically detect an appropriate type for both variables and function
signatures that have omitted their declared types. Type inference is based on
either the initializer or return values.
- compiler: Abstract classes now support abstract getter and setter methods.
+- compiler: Added `--strict-flex-css` compiler option to optionally enable CSS
syntax limitations that match Flex.
- compiler: Improved type checking for `&&` and `||` binary operators and `?:`
ternary operator.
- compiler: Removed obsolete "AMD" and "Goog" JavaScript backends, and
finished some refactoring to make codebase easier to maintain.
- compiler: Now requires Java 11 or newer to run. Previously required Java 8
minimum.
diff --git
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
index aa1e2ab15..0e1a8c83f 100644
---
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
+++
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
@@ -1593,6 +1593,30 @@ public class Configuration
this.allowPrivateConstructors = allow;
}
+ //
+ // 'compiler.strict-flex-css' option
+ //
+
+ private boolean strictFlexCSS = true;
+
+ public boolean getCompilerStrictFlexCSS()
+ {
+ return strictFlexCSS;
+ }
+
+ /**
+ * Whether the compiler will require only CSS syntax that not supported by
+ * the Flex SDK. When enabled, if newer CSS syntax is used, a problem will
+ * be reported.
+ */
+ @Config
+ @Mapping({ "compiler", "strict-flex-css" })
+ @RoyaleOnly
+ public void setCompilerStrictFlexCSS(ConfigurationValue cv, boolean strict)
+ {
+ this.strictFlexCSS = strict;
+ }
+
//
// 'compiler.strict-identifier-names' option
//
diff --git
a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
index ada13a305..72bbf334d 100644
---
a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
+++
b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
@@ -292,6 +292,11 @@ public interface ICompilerProject
*/
boolean getStrictIdentifierNames();
+ /**
+ * @return True if strict Flex CSS syntax is enforced.
+ */
+ boolean getStrictFlexCSS();
+
/**
* @return True if type inference is enabled.
*/
diff --git
a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/JSConfiguration.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/JSConfiguration.java
index 13c257ec2..9eb72978d 100644
---
a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/JSConfiguration.java
+++
b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/JSConfiguration.java
@@ -69,6 +69,7 @@ public class JSConfiguration extends Configuration
setCompilerAllowPrivateConstructors(null, true);
setCompilerAllowImportAliases(null, true);
setCompilerStrictIdentifierNames(null, false);
+ setCompilerStrictFlexCSS(null, false);
}
//
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
index cdf1da24e..9e08a7454 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/css/CSSDocument.java
@@ -64,6 +64,20 @@ public class CSSDocument extends CSSNodeBase implements
ICSSDocument
* @return CSS DOM object.
*/
public static CSSDocument parse(final CharStream input, final
Collection<ICompilerProblem> problems)
+ {
+ return parse(input, false, problems);
+ }
+
+ /**
+ * Parse a CSS document into {@link ICSSDocument} model.
+ *
+ * @param input ANTLR input stream. The {@code CharStream#getSourceName()}
+ * must be implemented in order to make source location work.
+ * @param strictFlexCSS Enables Flex CSS compatibility mode, which is more
limited.
+ * @param problems Parsing problems will be aggregated in this collection.
+ * @return CSS DOM object.
+ */
+ public static CSSDocument parse(final CharStream input, final boolean
strictFlexCSS, final Collection<ICompilerProblem> problems)
{
assert input != null : "CSS input can't be null";
assert problems != null : "Problem collection can't be null";
@@ -93,6 +107,7 @@ public class CSSDocument extends CSSNodeBase implements
ICSSDocument
// walk the tree and build definitions
final CSSTree treeWalker = new CSSTree(nodes);
+ treeWalker.setStrictFlexCSS(strictFlexCSS);
treeWalker.stylesheet();
problems.addAll(treeWalker.problems);
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
index 0236cb84b..b7b993b5a 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
@@ -189,6 +189,12 @@ public class ConfigProcessor
return false;
}
+ @Override
+ public boolean getStrictFlexCSS() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
@Override
public boolean getInferTypes() {
// TODO Auto-generated method stub
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
index 8d2becd82..a41b7588a 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
@@ -111,6 +111,12 @@ public class ASCProject extends CompilerProject implements
IASCProject
return false;
}
+ @Override
+ public boolean getStrictFlexCSS() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
@Override
public boolean getInferTypes() {
// TODO Auto-generated method stub
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
index 3bf7a6139..287b8ddcb 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
@@ -2556,6 +2556,21 @@ public class RoyaleProject extends ASProject implements
IRoyaleProject, ICompile
strictIdentifierNames = enabled;
}
+ private boolean strictFlexCSS = false;
+
+ /**
+ * Indicates if strict Flex CSS syntax is enforced.
+ */
+ @Override
+ public boolean getStrictFlexCSS()
+ {
+ return strictFlexCSS;
+ }
+ public void setStrictFlexCSS(boolean enabled)
+ {
+ strictFlexCSS = enabled;
+ }
+
private boolean inferTypes = false;
/**
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
index 8c0625a74..6cbe7cb00 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
@@ -274,6 +274,7 @@ public class RoyaleProjectConfigurator extends Configurator
project.setAllowStrictFunctionTypes(configuration.getAllowStrictFunctionTypes());
project.setStrictIdentifierNames(configuration.getCompilerStrictIdentifierNames());
+ project.setStrictFlexCSS(configuration.getCompilerStrictFlexCSS());
project.setInferTypes(configuration.getInferTypes());
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
index 554071270..9f0a325fe 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLStyleNode.java
@@ -33,7 +33,9 @@ import org.apache.royale.compiler.mxml.IMXMLTagData;
import org.apache.royale.compiler.mxml.IMXMLTextData;
import org.apache.royale.compiler.problems.ICompilerProblem;
import org.apache.royale.compiler.problems.MXMLDualContentProblem;
+import org.apache.royale.compiler.projects.ICompilerProject;
import org.apache.royale.compiler.tree.ASTNodeID;
+import org.apache.royale.compiler.tree.mxml.IMXMLFileNode;
import org.apache.royale.compiler.tree.mxml.IMXMLStyleNode;
import static org.apache.royale.compiler.mxml.IMXMLLanguageConstants.*;
@@ -98,11 +100,21 @@ class MXMLStyleNode extends MXMLNodeBase implements
IMXMLStyleNode
{
if (cssText != null && !cssText.isEmpty() &&
!cssText.trim().isEmpty())
{
+ boolean strictFlexCSS = false;
+ IMXMLFileNode fileNode = getFileNode();
+ if (fileNode != null)
+ {
+ ICompilerProject project = fileNode.getCompilerProject();
+ if (project != null)
+ {
+ strictFlexCSS = project.getStrictFlexCSS();
+ }
+ }
ANTLRStringStream stream = new ANTLRStringStream(cssText);
stream.name = cssSourcePath != null ? cssSourcePath :
getSourcePath();
stream.setLine(getLine());
stream.setCharPositionInLine(cssCharPos);
- cssDocument = CSSDocument.parse(stream, problems);
+ cssDocument = CSSDocument.parse(stream, strictFlexCSS,
problems);
if (cssDocument == null)
{
cssDocument = CSSDocumentCache.EMPTY_CSS_DOCUMENT;
diff --git
a/compiler/src/main/java/org/apache/royale/compiler/internal/units/StyleModuleCompilationUnit.java
b/compiler/src/main/java/org/apache/royale/compiler/internal/units/StyleModuleCompilationUnit.java
index cffd56212..227177d7b 100644
---
a/compiler/src/main/java/org/apache/royale/compiler/internal/units/StyleModuleCompilationUnit.java
+++
b/compiler/src/main/java/org/apache/royale/compiler/internal/units/StyleModuleCompilationUnit.java
@@ -53,6 +53,7 @@ import
org.apache.royale.compiler.internal.units.requests.SyntaxTreeRequestResul
import org.apache.royale.compiler.problems.CSSCodeGenProblem;
import org.apache.royale.compiler.problems.FileNotFoundProblem;
import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.projects.ICompilerProject;
import org.apache.royale.compiler.scopes.IASScope;
import org.apache.royale.compiler.units.requests.IABCBytesRequestResult;
import org.apache.royale.compiler.units.requests.IFileScopeRequestResult;
@@ -158,7 +159,13 @@ public class StyleModuleCompilationUnit extends
CompilationUnitBase
try
{
final ANTLRFileStream fileStream = new
ANTLRFileStream(cssFile.getPath());
- css = CSSDocument.parse(fileStream, syntaxErrors);
+ boolean strictFlexCSS = false;
+ ICompilerProject project = getProject();
+ if (project != null)
+ {
+ strictFlexCSS = project.getStrictFlexCSS();
+ }
+ css = CSSDocument.parse(fileStream, strictFlexCSS, syntaxErrors);
}
catch (IOException e)
{