cem-tools
cem-tools copied to clipboard
cem-plugin-expanded-types: Error when analyzing types with index signatures
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:
https://github.com/break-stuff/cem-tools/blob/8187639d731c8bcfe0df13b65f1ada8c4db397a4/packages/expanded-types/src/cem-plugin.ts#L133
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' }
Do you have a repro I can test? Preliminary tests seem to work fine:
"{ [key: string]: any }".replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, '')
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.
Same error hit with an { [key: string]: string } type.
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.
It looks like this is also working in my new package: https://wc-toolkit.com/documentation/type-parser/
@break-stuff does the new package supercede this one? Should i remove it?
Yes, this will be deprecated and replaced with the WC Toolkit version.
Yes, this will be deprecated and replaced with the WC Toolkit version.
Excellent! Looking forward to the official deprecation :)
It has officially been deprecated. 😁
@certainlyakey did the new package fix the issue for you?
@certainlyakey closing as these have been moved to the WC Toolkit. Please let me know if you are experiencing issues with the new package.