Title: Transforming class member with decorators throws · Issue #17384 · microsoft/TypeScript · GitHub
Open Graph Title: Transforming class member with decorators throws · Issue #17384 · microsoft/TypeScript
X Title: Transforming class member with decorators throws · Issue #17384 · microsoft/TypeScript
Description: TypeScript Version: 2.4.0 Code Can't use something that runs from "tsc" since it does not support transformers In a PropertyDeclaration visitor return ts.updateProperty( node, node.decorators[0], // assume we have 2 or more decorators......
Open Graph Description: TypeScript Version: 2.4.0 Code Can't use something that runs from "tsc" since it does not support transformers In a PropertyDeclaration visitor return ts.updateProperty( node, node.decorators[0], /...
X Description: TypeScript Version: 2.4.0 Code Can't use something that runs from "tsc" since it does not support transformers In a PropertyDeclaration visitor return ts.updateProperty( node, node.de...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/17384
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Transforming class member with decorators throws","articleBody":"**TypeScript Version:** 2.4.0 \r\n\r\n**Code**\r\n\r\n> Can't use something that runs from \"tsc\" since it does not support transformers\r\n\r\nIn a `PropertyDeclaration` visitor\r\n```ts\r\nreturn ts.updateProperty(\r\n node,\r\n node.decorators[0], // assume we have 2 or more decorators...\r\n node.modifiers,\r\n node.name,\r\n node.type,\r\n node.initializer\r\n );\r\n```\r\n\r\n**Expected behavior:**\r\nShould compile.\r\n\r\n**Actual behavior:**\r\nException is thrown `TypeError: Cannot read property 'kind' of undefined`\r\n\r\nThe exception is throw from [here](https://github.com/Microsoft/TypeScript/blob/194c2bc2ca806f5f1014113329e33207f683037c/src/compiler/utilities.ts#L1121)\r\n\r\n```ts\r\n export function nodeCanBeDecorated(node: Node): boolean {\r\n switch (node.kind) {\r\n case SyntaxKind.ClassDeclaration:\r\n // classes are valid targets\r\n return true;\r\n\r\n case SyntaxKind.PropertyDeclaration:\r\n // property declarations are valid if their parent is a class declaration.\r\n return node.parent.kind === SyntaxKind.ClassDeclaration;\r\n\r\n case SyntaxKind.GetAccessor:\r\n case SyntaxKind.SetAccessor:\r\n case SyntaxKind.MethodDeclaration:\r\n // if this method has a body and its parent is a class declaration, this is a valid target.\r\n return (\u003cFunctionLikeDeclaration>node).body !== undefined\r\n && node.parent.kind === SyntaxKind.ClassDeclaration;\r\n\r\n case SyntaxKind.Parameter:\r\n // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target;\r\n return (\u003cFunctionLikeDeclaration>node.parent).body !== undefined\r\n && (node.parent.kind === SyntaxKind.Constructor\r\n || node.parent.kind === SyntaxKind.MethodDeclaration\r\n || node.parent.kind === SyntaxKind.SetAccessor)\r\n && node.parent.parent.kind === SyntaxKind.ClassDeclaration;\r\n }\r\n\r\n return false;\r\n }\r\n```\r\n\r\nTrying to reach `node.parent.kind` while `node.parent` is undefined, which is common to all \"synthesized\" nodes, i.e. transforming nodes.\r\n\r\n#### This is true to all other members... Parameter, MethodDeclaration, GetAccessor and SetAccessor\r\n\r\n","author":{"url":"https://github.com/shlomiassaf","@type":"Person","name":"shlomiassaf"},"datePublished":"2017-07-25T00:42:18Z","url":"https://github.com/microsoft/TypeScript/issues/17384"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:03dc04c4-7a57-6ebc-e19d-57632cb8ae5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E9FA:1F65:18271C0:1EAD650:6B019BA2 |
| html-safe-nonce | 0b5f26bdb125d3d1552be51b0072b8420718c8c12f6c64f41f9449fce987224d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUZBOjFGNjU6MTgyNzFDMDoxRUFENjUwOjZCMDE5QkEyIiwidmlzaXRvcl9pZCI6IjkxMzE0NTM5NTMxOTQ2OTU1ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7ea1d869ffabd0f67590df59b5bad4d0ce7d35546f974a7e7112cb149923f3b2 |
| hovercard-subject-tag | issue:245254010 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/17384/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e1dd66c2d05d80e487b4dd00705644520b26cd63a79b6c5709944c8b8a92f0b0/microsoft/TypeScript/issues/17384 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e1dd66c2d05d80e487b4dd00705644520b26cd63a79b6c5709944c8b8a92f0b0/microsoft/TypeScript/issues/17384 |
| og:image:alt | TypeScript Version: 2.4.0 Code Can't use something that runs from "tsc" since it does not support transformers In a PropertyDeclaration visitor return ts.updateProperty( node, node.decorators[0], /... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shlomiassaf |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width