salesforce / utam-java

UTAM Java implementation
MIT License
25 stars 16 forks source link

[Bug] Invalid Java function signature output #195

Closed 0xtr closed 1 year ago

0xtr commented 1 year ago

Actual behavior

A specific piece of markup in a LWC causes Java compilation of the utam.json file for that LWC to fail, and no Java class is compiled for that component. The compiler outputs an error relating to the generated function's signature.

The compiler error is not particularly clear, but this is what it prints: 46 > /* 47 > method getFailure.id 48 > @return idElement 49 > @param index Integer 50 > */ 51 > 52 > idElement getFailure.id(Integer index);

It's trying to create a function name of getFailure.id.

What is your expected behavior?

The code that's output is valid Java and the file generates.

Steps to reproduce

Have a LWC with this piece of markup inside. In the markup, this is a list of errors. An individual error can be clicked to go to an associated element on the page (via the id value).

`
                <ul class="slds-list_dotted">
                    <template for:each={failures} for:item="failure">
                        <li key={failure.id}>
                            <a data-position={failure.position} onclick={handleFailureClick} id={failure.id}
                                >{failure.message}</a
                            >
                        </li>
                    </template>
                </ul>
`

On the command line in the repo, run utam-compile.js to generate a utam.json file for the LWC. Compile the utam.json file into Java. I'm using the utam-compiler .jar for this.

Environment

jimevans commented 1 year ago

@0xtr When you say "in the repo, run utam-compile.js," to which repo are you referring? There is no utam-compile.js in this repo that I'm aware of. Also, what is the structure of the JSON file that you are attempting to compile with the UTAM compiler?

It sounds like you're using a generator of some sort to parse the LWC markup into JSON, which is then passed to the JSON compiler. If that's the case, the bug may be in the generator, and not the UTAM compiler. Can you share the information about how you're generating the JSON input?

lizaiv77 commented 1 year ago

@0xtr I see what you mean - in generated JSON element name is "failure.id" hence the error as it's not valid.

"elements": [
                {
                    "public": true,
                    "name": "failure.id",

We might fix it sometime, but it's definitely not high on priority list because generated content is usually edited before using it. Please manually replace generated element name to whatever is appropriate, for example to "failureId"

0xtr commented 1 year ago

@0xtr When you say "in the repo, run utam-compile.js," to which repo are you referring? There is no utam-compile.js in this repo that I'm aware of. Also, what is the structure of the JSON file that you are attempting to compile with the UTAM compiler?

It sounds like you're using a generator of some sort to parse the LWC markup into JSON, which is then passed to the JSON compiler. If that's the case, the bug may be in the generator, and not the UTAM compiler. Can you share the information about how you're generating the JSON input?

Sorry, poor phrasing by myself there - in the same directory, that should be. I'm running it in one of my company's repos. I'm using the generator from https://www.npmjs.com/package/utam. Unless I've misunderstood the documentation there's no equivalent tooling for generating LWC->JSON that fits into the Java toolchain similarly?

This is the JSON file structure with other unrelated elements removed:

{
    "description": {
        "author": "UTAM generator",
        "text": [
            "Page Object: comp_name"
        ]
    },
    "shadow": {
        "elements": [
            <cut>
            {
                "name": "list",
                "type": [],
                "selector": {
                    "css": "ul"
                },
                "elements": [
                    {
                        "public": true,
                        "name": "listItems",
                        "type": [
                            "actionable",
                            "clickable"
                        ],
                        "selector": {
                            "css": "li",
                            "returnAll": true
                        }
                    },
                    {
                        "public": true,
                        "name": "listItemByIndex",
                        "type": [
                            "actionable",
                            "clickable"
                        ],
                        "selector": {
                            "css": "li:nth-of-type(%d)",
                            "args": [
                                {
                                    "name": "index",
                                    "type": "number"
                                }
                            ]
                        },
                        "elements": [
                            {
                                "public": true,
                                "name": "failure.id",
                                "type": [
                                    "actionable",
                                    "clickable"
                                ],
                                "selector": {
                                    "css": "a"
                                }
                            }
                        ]
                    }
                ]
            },
            <cut>
        ]
    }
}
0xtr commented 1 year ago

@0xtr I see what you mean - in generated JSON element name is "failure.id" hence the error as it's not valid.

"elements": [
                {
                    "public": true,
                    "name": "failure.id",

We might fix it sometime, but it's definitely not high on priority list because generated content is usually edited before using it. Please manually replace generated element name to whatever is appropriate, for example to "failureId"

Will do, thank you. Is there a goal to make the tooling output usable immediately after generation? Having to edit the files manually means I am unlikely to update them very often unless something breaks; as an example, in this single repo I have 183 utam.json files generated via the utam npm command, and there are other repos.

lizaiv77 commented 1 year ago

@0xtr

Is there a goal to make the tooling output usable immediately after generation? Generator does not know anything about use cases implemented by a component, it does not know how to give meaningful names to elements, what methods it needs etc. So we always assumed that whatever is generated is later adjusted manually or with generator config next to a Page Object, see docs https://utam.dev/tools/generator-content if development pipeline means to generate every time you build code. We currently explore AI driven generation for Lightning Components, but we first release it internally for our engineers, we do not know yet if/when it will be available outside Salesforce.

0xtr commented 1 year ago

@lizaiv77 Good to know, thanks. I'll close this then if the intention is to edit compiler output for now.