Skip to content

fix: write a JavaScript action's parameters the way mxbuild generates them - #1561

Open
stagknee wants to merge 1 commit into
mendixlabs:mainfrom
stagknee:fix/js-action-parameter-case
Open

stagknee wants to merge 1 commit into
mendixlabs:mainfrom
stagknee:fix/js-action-parameter-case

Conversation

@stagknee

Copy link
Copy Markdown
Contributor

Closes #1560.

What it fixes

mxcli wrote a JavaScript action's .js signature and JSDoc @param names exactly as declared, for example JS_Open(Url, ReadOnly). mxbuild and Studio Pro regenerate the signature with the first character lower-cased, JS_Open(url, readOnly), and keep the body. A body written against what exec produced therefore threw a ReferenceError at runtime, while check, exec and the build all stayed green.

The same mismatch broke Studio Pro-authored actions edited through mxcli: Geocode(address, …) became Geocode(Address, …) under a body that uses address.

How

  • sdk/javaactions/jssource.go gains JavaScriptParameterName, which lower-cases the first rune and leaves the rest untouched. It is used for the signature and the @param tags.
    • jssource.go is the only place a JS signature is generated, and nothing parses a signature back.
    • The model parameter names, describe javascript action, and the user body are unchanged.
  • Docs:
    • create-javascript-action.md has a new "Parameter names in the body" section;
    • the javascript-actions skill (with the regenerated skill index) and the syntax entry are updated;
    • four example scripts whose bodies used the declared case are corrected.
  • Also included: a CHANGELOG entry (Fixed), a finding in findings/sdk/, and the regression script mdl-examples/bug-tests/1560-js-action-parameter-case.mdl.

Evidence

  • The rule, measured with mxbuild 11.12.5:

    Declared Generated
    URL uRL
    MyID myID
    Some_Name some_Name
    A a
    XMLData xMLData
    _Lead _Lead
    Obj2Name obj2Name
    Eid eid

    It is encoded as a test table, and the golden files under sdk/javaactions/testdata/mxbuild/ hold what mxbuild left for two mxcli-created actions.

  • Control run:

    • With the helper reverted to identity, these fail: TestJavaScriptParameterName_MatchesMxbuild, …_ParameterNamesAreLowerFirst, …_SignatureMatchesMxbuild, TestWriteJavaScriptSourceFile_ParametersAreLowerFirst and …_RewriteKeepsStudioProSignature. They all pass with the fix.
    • TestCreateJavaScriptAction_ModelKeepsDeclaredParameterCase passes both ways on purpose: it pins the model names.
  • Real run (Mendix 11.12.5 scratch app):

    • Before: v0.26.0 writes JS_Open(Url, ReadOnly), and mxbuild then rewrites every name.
    • After:
      • this branch writes JS_Open(url, readOnly);
      • after mxbuild, the signature and @param names are unchanged, for JS_Open and for an 8-name action;
      • under node, the 8-name action as v0.26.0 wrote it throws ReferenceError: uRL is not defined, and as this branch writes it, it returns its value.
    • Studio Pro-authored NanoflowCommons.Geocode, describe → edit → exec:
      • v0.26.0 produces Geocode(Address, GeocodingProvider, ProviderApiKey);
      • this branch keeps Geocode(address, geocodingProvider, providerApiKey);
      • re-running the describe output is byte-identical.
  • Round trip: go test -tags integration ./mdl/roundtrip -run 'TestPedAppRoundTrip$/^javascript_action' passes 67 of 67.

  • Windows: the only failures in the touched packages are the pre-existing TempDir-lock ones, identical on main.

  • Linux (golang:1.26.6-bookworm, ANTLR 4.13.2): make grammar build test check-mdl check-findings check-conformance check-migration-reference lint-go all pass.

Follow-ups (not in this PR)

mxbuild also refuses two things that check and exec don't catch:

  • parameter names that become reserved words, such as ID, New or Default;
  • parameters that differ only in case (Url and url).

A check warning for a body that uses a parameter in its declared case would also help. I can open these separately.

🤖 Generated with Claude Code

…ild generates them

`create javascript action ... (Url: String, ReadOnly: Boolean)` wrote
`export async function JS_Open(Url, ReadOnly)`. mxbuild and Studio Pro
regenerate the signature and the JSDoc from the model with the first
character of each parameter name lower-cased and keep the body, so after a
build the signature read `JS_Open(url, readOnly)` and a body using `Url`
threw ReferenceError at run time. check, mx check and the build were all
clean. Rewriting a Studio Pro-authored action through MDL did the same in
reverse: `Geocode(address, ...)` became `Geocode(Address, ...)` over a body
that still read `address`.

JavaScriptParameterName lower-cases the first rune only, which is what
mxbuild 11.12.5 does (URL -> uRL, MyID -> myID, Some_Name -> some_Name,
XMLData -> xMLData, _Lead unchanged). GenerateJavaScriptSource uses it for
the signature and the @PARAM tags. The model parameter keeps its declared
name, so describe prints it as declared and describe -> exec is stable, and
bodies are not rewritten.

Tests: the measured table, the generated signature, a rewrite over a Studio
Pro-style file, and goldens of what mxbuild left for two actions. A check
warning for bodies that use the declared case is a separate change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

None found.

What Looks Good

  • The fix correctly addresses the core issue: mxcli now generates JavaScript action parameter names with first character lower-cased to match mxbuild/Studio Pro behavior
  • Comprehensive test coverage added including unit tests, golden files matching mxbuild output, and integration tests
  • Documentation updated in multiple places (skill, reference docs, changelog) to explain the parameter name behavior
  • Example scripts corrected to use proper parameter casing in function bodies
  • Regression test added (mdl-examples/bug-tests/1560-js-action-parameter-case.mdl)
  • Findings file added for bug tracking
  • Round-trip tests pass, confirming MDL functionality remains intact
  • The change is minimal and focused - only affects how parameter names are formatted in generated JavaScript
  • Clear evidence shows the fix works with actual mxbuild 11.12.5 behavior
  • No LSP or syntax changes needed as this is an implementation fix, not a new MDL feature

Recommendation

Approve - The PR correctly fixes the reported issue with appropriate tests, documentation, and follows contribution guidelines. The change is minimal, targeted, and addresses the root cause without introducing side effects. All verification steps pass as evidenced in the PR description.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript action: mxcli writes parameter names as declared, but mxbuild regenerates them lower-first, so the body breaks at runtime

1 participant