tanhauhau/svelte-json-tree

Unexpected token: punc (.) for minification

davy-blavette opened this issue · 3 comments

Hi,

With rollup tenser for prod, I have an error with plugin svelte-json-tree

 42503 |         const _newState = typeof newState === 'function' ? newState(currentState) : newState;
  42504 |         const nextState = { ...currentState, ..._newState };
> 42505 |         if (opts?.expandable)
        |                 ^ Unexpected token: punc (.)
  42506 |             nextState.isParentExpanded = nextState.expanded;
  42507 |         setContext(STATE, nextState);
  42508 |         return currentState;

Maybe here to the file _/utils/context.js

    if (opts?.expandable)
        nextState.isParentExpanded = nextState.expanded;
    setContext(STATE, nextState);

It's Ok if you replace
if (opts !== undefined)

Same problem with JSONFunctionNode.svelte :
const isAsync = match?.[1]; const isGenerator = match?.[2]; const fnName = match?.[3]; const args = match?.[4]; const isArrow = match?.[5]; const classMatch = str.match(/^class\s+([^\s]+)/); const isClass = classMatch?.[1];

replace, I don't think that the condition was necessary :

    const match = str.match(/^(?:(async)\s+)?(?:function)?(\*)?\s*([^(]+)?(\([^)]*\))\s*(=>)?/);
    const isAsync = match[1];
    const isGenerator = match[2];
    const fnName = match[3];
    const args = match[4];
    const isArrow = match[5];
    const classMatch = str.match(/^class\s+([^\s]+)/);
    const isClass = classMatch[1];

from the stack that you posted, i think the "unsupported syntax" by your terser is the optional chaining operator ?. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining)

the syntax is now supported in all major modern browsers, it should be supported by the latest terser, so i would suggest you to consider upgrade your terser version to fix this issue

123456

Hi,

With rollup tenser for prod, I have an error with plugin svelte-json-tree

 42503 |         const _newState = typeof newState === 'function' ? newState(currentState) : newState;
  42504 |         const nextState = { ...currentState, ..._newState };
> 42505 |         if (opts?.expandable)
        |                 ^ Unexpected token: punc (.)
  42506 |             nextState.isParentExpanded = nextState.expanded;
  42507 |         setContext(STATE, nextState);
  42508 |         return currentState;

Maybe here to the file _/utils/context.js

    if (opts?.expandable)
        nextState.isParentExpanded = nextState.expanded;
    setContext(STATE, nextState);

It's Ok if you replace
if (opts !== undefined)

Same problem with JSONFunctionNode.svelte :
const isAsync = match?.[1]; const isGenerator = match?.[2]; const fnName = match?.[3]; const args = match?.[4]; const isArrow = match?.[5]; const classMatch = str.match(/^class\s+([^\s]+)/); const isClass = classMatch?.[1];

replace, I don't think that the condition was necessary :

    const match = str.match(/^(?:(async)\s+)?(?:function)?(\*)?\s*([^(]+)?(\([^)]*\))\s*(=>)?/);
    const isAsync = match[1];
    const isGenerator = match[2];
    const fnName = match[3];
    const args = match[4];
    const isArrow = match[5];
    const classMatch = str.match(/^class\s+([^\s]+)/);
    const isClass = classMatch[1];

it will be beta to replaced and well security