Title: Recent change in compiler-cli breaks jest-preset-angular · Issue #48448 · angular/angular · GitHub
Open Graph Title: Recent change in compiler-cli breaks jest-preset-angular · Issue #48448 · angular/angular
X Title: Recent change in compiler-cli breaks jest-preset-angular · Issue #48448 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? compiler-cli Is this a regression? Yes Description I'm currently investigating an error that occurs in certain situations when running tests with jest-preset-angular and typescript 4...
Open Graph Description: Which @angular/* package(s) are the source of the bug? compiler-cli Is this a regression? Yes Description I'm currently investigating an error that occurs in certain situations when running tests w...
X Description: Which @angular/* package(s) are the source of the bug? compiler-cli Is this a regression? Yes Description I'm currently investigating an error that occurs in certain situations when running tes...
Opengraph URL: https://github.com/angular/angular/issues/48448
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Recent change in compiler-cli breaks jest-preset-angular ","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncompiler-cli\n\n### Is this a regression?\n\nYes\n\n### Description\n\nI'm currently investigating an error that occurs in certain situations when running tests with jest-preset-angular and typescript 4.8. There are several issue reports over at jest-preset-angular, nrwl/nx and possibly others.\r\n\r\n### Error description\r\n\r\nIn short, this code will break jest / jest-preset-angular, throwing `ReferenceError: anywhere_1 is not defined`, when running typescript 4.8.\r\n\r\n```ts\r\nimport {InterfaceFromInterfaceOnlyModule } from './anywhere' ;\r\nclass X {\r\n\t@MyDecorator() test():InterfaceFromInterfaceOnlyModule { ... }\r\n}\r\n```\r\n\r\nA reproduction is available at https://github.com/jbjhjm/jest28-bug .\r\n\r\nThe error occurs when following circumstances are given:\r\n\r\n- use angular with typescript 4.8 (so ng 15) and jest with jest-preset-angular\r\n- Import nothing but an interface or type from a module\r\n- Use it on a method that is being decorated\r\n- Have emitDecoratorMetadata enabled\r\n\r\nIt seems like response type of a decorated method somehow \"bleeds\" into compiled javascript, where it causes an error because the type-only module does not exist anymore, ending up in a ReferenceError.\r\n\r\n### Origin of error\r\n\r\njest-preset-angular uses the downlevel_decorators_transform.ts from compiler-cli.\r\nWe managed to hunt the error down to a recent change in there.\r\n\r\nhttps://github.com/angular/angular/pull/47167 modified that file in L565, replacing updateClassDeclaration by createClassDeclaration. \r\n\r\nHere https://github.com/thymikee/jest-preset-angular/issues/1199#issuecomment-1345445251 , @n9niwas has shown a patch reverting that change to make it work as desired again, stating: \"Idk for sure, but suspect that calling create* methods instead of update* makes TS program to forget information about whether a particular import is type-only or not.\"\r\n\r\n@crisbeto , your insights might help here a lot.\r\nI am not sure if downlevel_decorators_transform currently generates unexpected code, or if jest-preset-angular needs to update its own implementation to work correctly with the new code.\r\nWhat's your estimation? Can you explain why `createClassDeclaration` is used now?\r\n\r\n---\r\n\r\nRelated issues:\r\n\r\nhttps://github.com/thymikee/jest-preset-angular/issues/1199\r\nhttps://github.com/thymikee/jest-preset-angular/issues/1810\r\nhttps://github.com/nrwl/nx/issues/10660\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://github.com/jbjhjm/jest28-bug\n\n### Please provide the exception or error you saw\n\n```true\njest will throw `ReferenceError: xxx is not defined`\n```\n\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 15.0.2\r\nNode: 16.17.0\r\nPackage Manager: npm 8.15.0\r\nOS: win32 x64\r\n\r\nAngular: 15.0.2\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... language-service, platform-browser, platform-browser-dynamic\r\n... router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1500.2\r\n@angular-devkit/build-angular 15.0.2\r\n@angular-devkit/core 15.0.2\r\n@angular-devkit/schematics 15.0.2\r\n@schematics/angular 15.0.2\r\nrxjs 7.5.7\r\ntypescript 4.8.4\n```\n\n\n### Anything else?\n\n_No response_","author":{"url":"https://github.com/jbjhjm","@type":"Person","name":"jbjhjm"},"datePublished":"2022-12-12T11:13:53Z","url":"https://github.com/angular/angular/issues/48448"}
| 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:3c1b000a-71e3-9ea3-706f-83782616241e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A184:2564F:92B5A5:C3AE92:6B00E253 |
| html-safe-nonce | 431f2efd2d18d7987b5c5675886b958f96b61f928ec364c2af622fc57e4112d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTg0OjI1NjRGOjkyQjVBNTpDM0FFOTI6NkIwMEUyNTMiLCJ2aXNpdG9yX2lkIjoiNzkzNDQ2OTI3MDk5NjU3NDgwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a5d46b1f37b8482502e1b0b48a5bdd001f2fe34406d65d01db8e1c34560e06ca |
| hovercard-subject-tag | issue:1491611161 |
| 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/angular/angular/48448/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1fca49cfbcf26069a6d6a4420061cfc710dc4568043eab22e5ddc1542cdee89a/angular/angular/issues/48448 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1fca49cfbcf26069a6d6a4420061cfc710dc4568043eab22e5ddc1542cdee89a/angular/angular/issues/48448 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? compiler-cli Is this a regression? Yes Description I'm currently investigating an error that occurs in certain situations when running tests w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jbjhjm |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width