-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Visitor throws Cannot read property 'kind' of undefined
using [email protected]
#38558
Comments
I managed to reduce the reproduction code down to: const f = (props: any) => (...args: any) => '';
f({
background: `${1} anything`,
...{ test: 1 },
})`` The issue is in the es2015 transformer so any target above es2015 will be fine. In fact, the issue is in the object literal visitor when the node contains "es2015 features (eg. template literals, arrow functions, ...)" that need to be transformed. So you can reproduce the same crash with this code using arrow functions: const f = (props: any) => (...args: any) => '';
f({
background: (() => 1)(),
...{ test: 1 },
})`` This code, for instance does not crash because the object literal doesn't have any es2015 features in it. const f = (props: any) => (...args: any) => '';
f({
background: 'anything',
...{ test: 1 },
})`` I'll try to fix this. Until the bug is fixed, @lukaskl you can use a string instead of a template literal for the background variable or use an external variable to store the template literal outside of the object literal like that: export interface ColorProps {
style?: CSSProperties
}
const Color = styled(({ style }: ColorProps) => {
const background = `${1 + 1}`;
return (
<div
style={{
...style,
background,
}}
/>
);
})`` |
Thank you @lissein for investigating this! To add another workaround, it is also possible to split this into two definitions, e.g.: const ColorUnstyled = ({ style }: ColorProps) => (
<div
style={{
...style,
background: `anything`,
}}
/>
)
const Color = styled(ColorUnstyled)`` |
After more investigations, I confirmed that the code crashing is in the es2015 transformer but the root cause is not in here. The bug is actually in the es2018 transformer. const f = (props: any) => (...args: any) => '';
f({
background: (() => 1)(),
...{ test: 1 },
})``
const a = {
...{ test: 1 },
} "use strict";
const f = (props) => (...args) => '';
f({
background: (() => 1)(),
...{ test: 1 },
}) ``;
const a = Object.assign({ test: 1 }); As you can see, the second spread is transpiled correctly but the first one isn't. |
(This is most likely very unrelated to #38383...) |
This problem was introduced in 70399e1 (from PR microsoft#23801), which added a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`, before that, it would fallback to the default of `visitNode`. So re-add that happen in `processTaggedTemplateExpression`. Since it doesn't hurt, I left a `Debug.checkDefined(property.name)` instead of `!`-ing it. Fixes microsoft#38558.
This problem was introduced in 70399e1 (from PR microsoft#23801), which added a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`, before that, it would fallback to the default of `visitNode`. So re-add that happen in `processTaggedTemplateExpression`. Since it doesn't hurt, I left a `Debug.checkDefined(property.name)` instead of `!`-ing it. Fixes microsoft#38558.
This problem was introduced in 70399e1 (from PR #23801), which added a `visitTaggedTemplateExpression` case for `TaggedTemplateExpression`, before that, it would fallback to the default of `visitNode`. So re-add that happen in `processTaggedTemplateExpression`. Since it doesn't hurt, I left a `Debug.checkDefined(property.name)` instead of `!`-ing it. Fixes #38558.
My project is quite large. I don't know which code Edit: This happens when I try to upgrade directly from typescript version 3.7.3 to 3.9.7. Version 3.7.3 works for me. |
Why has this issue been closed, what is the resolution without having to make manual code changes? I'm facing the same issue on 3.9.10, targetting ES5 |
TypeScript Version:
3.9.2
3.9.1-rc
3.9.0-beta
3.8.3
(it work with previous versions)Search Terms:
Visitor TypeError kind undefined 85032
Code
Unknown (Error is thrown at
node_modules/typescript/lib/typescript.js:85032:35
)But this part triggers it
Expected behavior:
It compiles
Actual behavior:
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: