Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions containing dollar signs ($) are incorrectly fixed #28

Closed
renato-bohler opened this issue Jan 24, 2024 · 1 comment
Closed

Comments

@renato-bohler
Copy link
Contributor

Description

While validating this plugin against a big codebase, I found an edge case where it auto-fixes incorrectly.

If the function has a dollar sign ($) on its body, it gets incorrectly transformed somehow.

Example 1

export function foo() {
  const bar = '$';
  return bar
};

Gets transformed into an invalid syntax. Notice the lack of the dollar sign, the missing single quote, and the extra semicolon at the end:

export const foo = () => {
  const bar = ';
  return bar
};;

Example 2

If the dollar sign is in backticks:

export function foo() {
  const bar = `$`;
  return bar
};

Then this happens:

export const foo = () => {
  const bar = `(PARAMS)RETURN_TYPE => ;
  return bar
};;

(PARAMS)RETURN_TYPE => is leaking from the writeArrowFunction function somehow

const writeArrowFunction = (node) => {
const { body, isAsync, isGeneric, generic, params, returnType } =
getFunctionDescriptor(node);
return 'ASYNC<GENERIC>(PARAMS)RETURN_TYPE => BODY'
.replace('ASYNC', isAsync ? 'async ' : '')
.replace('<GENERIC>', isGeneric ? generic : '')
.replace('BODY', body)
.replace('RETURN_TYPE', returnType ? returnType : '')
.replace('PARAMS', params.join(', '));
};

Example 3

If there are two dollar signs, then the transformation is different, but still incorrect:

export function foo() {
  const bar = `$$`;
  return bar
};

And this happens:

export const foo = () => {
  const bar = `const foo = ;
  return bar
};;

Suggested Solution

No idea why that happens, so I'd have to investigate. Probably need to escape $ when replacing or something?

Help Needed

I just need time to look into that.

@JamieMason
Copy link
Owner

haha wow, this is an interesting one.

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

No branches or pull requests

2 participants