[ 
https://issues.apache.org/jira/browse/TINKERPOP-3241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18078801#comment-18078801
 ] 

Cole Greer commented on TINKERPOP-3241:
---------------------------------------

Following the upgrade of docs/gremlator to use Vite 8, esbuild is now 
deprecated and disabled by default. The new equivalent workaround for this 
issue is to add the following config to the build:

{code:javascript}
build: {
  rolldownOptions: {
    output: {
      minify: {
        mangle: {
          keepNames: true,
        },
      },
    },
  },
{code}


> Improve javascript translator behavior for web applications
> -----------------------------------------------------------
>
>                 Key: TINKERPOP-3241
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3241
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: javascript
>    Affects Versions: 3.8.1
>            Reporter: Stephen Mallette
>            Assignee: Stephen Mallette
>            Priority: Major
>
> A finding from the PR that created gremlator: 
> The TranslateVisitor.visit() method dispatches to the correct visitor method 
> (e.g. visitStringLiteral, visitIntegerLiteral) by inspecting 
> tree.constructor.name at runtime — it expects names like StringLiteralContext 
> and strips the Context suffix to find the method.
> Vite's production build minifies class names, so StringLiteralContext becomes 
> something like Qh. The className.endsWith('Context') check fails, the 
> dispatch never matches any specific visitor method, and every rule context 
> falls through to the generic visitChildren() path, which just walks down to 
> terminal
> tokens and outputs raw text.
> That's why step names translate correctly (they're terminal tokens handled by 
> visitTerminal) but all arguments — strings, numbers, booleans, collections — 
> pass through unmodified. The language-specific visitor overrides for those 
> literal types never get called.
> The fix is adding esbuild: { keepNames: true } to vite.config.ts so class 
> names survive minification. But the deeper issue is in gremlin-js itself: the 
> visit() dispatch relies on runtime class name reflection, which is inherently 
> fragile under minification. A more robust approach would be to dispatch on
> ruleIndex (a stable integer) rather than the class name string.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to