Title: ES6 module variables are copied when re-exported · Issue #6366 · microsoft/TypeScript · GitHub
Open Graph Title: ES6 module variables are copied when re-exported · Issue #6366 · microsoft/TypeScript
X Title: ES6 module variables are copied when re-exported · Issue #6366 · microsoft/TypeScript
Description: Given this example: a.ts export var a = 1; export function changeA() { a = 2; } b.ts export * from './a'; c.ts import { a, changeA } from './b'; console.log(a); // 1 changeA(); console.log(a); // Expected 2 but get 1 tsconfig.json { "com...
Open Graph Description: Given this example: a.ts export var a = 1; export function changeA() { a = 2; } b.ts export * from './a'; c.ts import { a, changeA } from './b'; console.log(a); // 1 changeA(); console.log(a); // E...
X Description: Given this example: a.ts export var a = 1; export function changeA() { a = 2; } b.ts export * from './a'; c.ts import { a, changeA } from './b'; console.log(a); // 1 changeA(); cons...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6366
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ES6 module variables are copied when re-exported","articleBody":"Given this example:\n\na.ts\n\n``` js\nexport var a = 1;\nexport function changeA() { a = 2; }\n```\n\nb.ts\n\n``` js\nexport * from './a';\n```\n\nc.ts\n\n``` js\nimport { a, changeA } from './b';\nconsole.log(a); // 1\nchangeA();\nconsole.log(a); // Expected 2 but get 1\n```\n\ntsconfig.json\n\n``` json\n{\n \"compilerOptions\": {\n \"target\": \"es5\",\n \"module\": \"commonjs\",\n \"outDir\": \"out\"\n }\n}\n```\n\nResult of runing c.js:\n\n```\n$ node out/c.js\n1\n1\n```\n\nThis happens because in b.ts this:\n\n``` js\nexport * from './a';\n```\n\ntranspiles to\n\n``` js\nfunction __export(m) {\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\n}\n__export(require('./a'));\n```\n\nand the value of variable a is copied and not referenced.\n\nIf I run the same example through babel it works because it generates getters that references the original variable. This was also proposed [here](https://github.com/Microsoft/TypeScript/issues/1215#issuecomment-63756746).\n\nI propose that if the target is set to es5 then the generated code for commonjs modules uses getters instead to make sure that re-exported variables are referenced instead of copied.\n","author":{"url":"https://github.com/jonaskello","@type":"Person","name":"jonaskello"},"datePublished":"2016-01-05T21:35:56Z","url":"https://github.com/microsoft/TypeScript/issues/6366"}
| 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:e789c640-7bb1-db24-5244-ea5612fabf96 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CE28:134361:E33EF0:12BE46C:6B00FE81 |
| html-safe-nonce | cb0e19457ec18bce5baf37717f9ea712bc228b185fd5434a6dd9282f3e60f1d0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTI4OjEzNDM2MTpFMzNFRjA6MTJCRTQ2Qzo2QjAwRkU4MSIsInZpc2l0b3JfaWQiOiI2Mjg1NzIyMzM2NDE5MTg0MjU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3287fed5f689a58a266c27bd290cb12ffbee3db0dd95af792de5610791495022 |
| hovercard-subject-tag | issue:125056555 |
| 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/6366/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b98bad8fd61d11b42f63e55eb55dd4f1108c5ae682d422cb4096dbe217b7bb17/microsoft/TypeScript/issues/6366 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b98bad8fd61d11b42f63e55eb55dd4f1108c5ae682d422cb4096dbe217b7bb17/microsoft/TypeScript/issues/6366 |
| og:image:alt | Given this example: a.ts export var a = 1; export function changeA() { a = 2; } b.ts export * from './a'; c.ts import { a, changeA } from './b'; console.log(a); // 1 changeA(); console.log(a); // E... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jonaskello |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width