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

cem-plugin-expanded-types: Error when analyzing types with index signatures #92

Open
h4de5 opened this issue Feb 27, 2024 · 9 comments
Open

Comments

@h4de5
Copy link

h4de5 commented Feb 27, 2024

When trying to analyze types like:

  @property({ type: Object })
  foobar: { [key: string]: any } = { foo: 'bar' }

I get the following error:

Error: 

[expand-types-plugin]: Looks like you've hit an error in third party plugin: expand-types-plugin. Please try to create a minimal reproduction and inform the author of the expand-types-plugin plugin.

 SyntaxError: Invalid regular expression: /[key/: Unterminated character class
    at new RegExp (<anonymous>)
    at file:///workspace/node_modules/cem-plugin-expanded-types/dist/index.js:84:7
    at Array.forEach (<anonymous>)
    at getObjectTypes (file:///workspace/node_modules/cem-plugin-expanded-types/dist/index.js:77:9)
    at getExpandedType (file:///workspace/node_modules/cem-plugin-expanded-types/dist/index.js:54:12)
    at getTypeValue (file:///workspace/node_modules/cem-plugin-expanded-types/dist/index.js:193:12)

the problematic regexp seems to be this:

/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g,

when run, the cleanPart variable holds the string [key which will not produce a valid regexp.

when creating a dedicated type or interface for that, it works:

  type FooBar = { [key: string]: any };

...

  @property({ type: Object })
  foobar: FooBar = { foo: 'bar' }
@break-stuff
Copy link
Owner

Do you have a repro I can test? Preliminary tests seem to work fine:

"{ [key: string]: any }".replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, '')

@MartinaeyNL
Copy link

MartinaeyNL commented Aug 5, 2024

I'm having this issue here as well.
In my case, the type is specified as {[name: string]: any} without spaces, causing the same Regex error.

And as @h4de5 described, creating a dedicated type fixes this indeed.

@certainlyakey
Copy link

Same error hit with an { [key: string]: string } type.

@break-stuff
Copy link
Owner

I'm sorry for the delay on this! The patch for it has gone out in version 1.3.3. Let me know if you run into any issues.

@break-stuff
Copy link
Owner

It looks like this is also working in my new package: https://wc-toolkit.com/documentation/type-parser/

@certainlyakey
Copy link

@break-stuff does the new package supercede this one? Should i remove it?

@break-stuff
Copy link
Owner

Yes, this will be deprecated and replaced with the WC Toolkit version.

@certainlyakey
Copy link

Yes, this will be deprecated and replaced with the WC Toolkit version.

Excellent! Looking forward to the official deprecation :)

@break-stuff
Copy link
Owner

It has officially been deprecated. 😁

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

4 participants