{"action":"created","issue":{"url":"https://api.github.com/repos/systemjs/systemjs/issues/1826","repository_url":"https://api.github.com/repos/systemjs/systemjs","labels_url":"https://api.github.com/repos/systemjs/systemjs/issues/1826/labels{/name}","comments_url":"https://api.github.com/repos/systemjs/systemjs/issues/1826/comments","events_url":"https://api.github.com/repos/systemjs/systemjs/issues/1826/events","html_url":"https://github.com/systemjs/systemjs/issues/1826","id":328638720,"node_id":"MDU6SXNzdWUzMjg2Mzg3MjA=","number":1826,"title":"Generator-based declarator phase in System format","user":{"login":"guybedford","id":598730,"node_id":"MDQ6VXNlcjU5ODczMA==","avatar_url":"https://avatars1.githubusercontent.com/u/598730?v=4","gravatar_id":"","url":"https://api.github.com/users/guybedford","html_url":"https://github.com/guybedford","followers_url":"https://api.github.com/users/guybedford/followers","following_url":"https://api.github.com/users/guybedford/following{/other_user}","gists_url":"https://api.github.com/users/guybedford/gists{/gist_id}","starred_url":"https://api.github.com/users/guybedford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guybedford/subscriptions","organizations_url":"https://api.github.com/users/guybedford/orgs","repos_url":"https://api.github.com/users/guybedford/repos","events_url":"https://api.github.com/users/guybedford/events{/privacy}","received_events_url":"https://api.github.com/users/guybedford/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-01T19:44:56Z","updated_at":"2018-06-01T20:12:46Z","closed_at":null,"author_association":"MEMBER","body":"From https://github.com/babel/proposals/issues/44#issuecomment-393986595, using generators as a baseline avoids the need for manual hoisting, while supporting better TDZ handling.\r\n\r\nThe example from there adjusted to separate into a two-phase \"declare\" and \"execute\" might look like:\r\n\r\n```js\r\n\r\nSystem.register([\"foo\"], function* (_export, _context) {\r\n  \"use strict\";\r\n\r\n  _export(0, function (_foo) {\r\n    var _exportObj = {};\r\n\r\n    for (var _key in _foo) {\r\n      if (_key !== \"default\" && _key !== \"__esModule\") _exportObj[_key] = _foo[_key];\r\n    }\r\n\r\n    _export(_exportObj);\r\n  });\r\n  _export(\"foo\", foo);\r\n\r\n  // indicates end of declaration phase\r\n  yield;\r\n\r\n  console.log(val);\r\n\r\n  let val = 4;\r\n  function foo() {\r\n    console.log(val);\r\n  }\r\n\r\n  // indicates end of execution phase, optionally returning execution promise\r\n  yield Promise.resolve().then(function () { ... })\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/systemjs/systemjs/issues/comments/393996440","html_url":"https://github.com/systemjs/systemjs/issues/1826#issuecomment-393996440","issue_url":"https://api.github.com/repos/systemjs/systemjs/issues/1826","id":393996440,"node_id":"MDEyOklzc3VlQ29tbWVudDM5Mzk5NjQ0MA==","user":{"login":"guybedford","id":598730,"node_id":"MDQ6VXNlcjU5ODczMA==","avatar_url":"https://avatars1.githubusercontent.com/u/598730?v=4","gravatar_id":"","url":"https://api.github.com/users/guybedford","html_url":"https://github.com/guybedford","followers_url":"https://api.github.com/users/guybedford/followers","following_url":"https://api.github.com/users/guybedford/following{/other_user}","gists_url":"https://api.github.com/users/guybedford/gists{/gist_id}","starred_url":"https://api.github.com/users/guybedford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guybedford/subscriptions","organizations_url":"https://api.github.com/users/guybedford/orgs","repos_url":"https://api.github.com/users/guybedford/repos","events_url":"https://api.github.com/users/guybedford/events{/privacy}","received_events_url":"https://api.github.com/users/guybedford/received_events","type":"User","site_admin":false},"created_at":"2018-06-01T20:12:46Z","updated_at":"2018-06-01T20:12:46Z","author_association":"MEMBER","body":"So with the top-level await support I just shared in https://github.com/babel/proposals/issues/44#issuecomment-393978818, for example the following:\r\n\r\n```js\r\nimport { x } from 'foo';\r\n\r\nexport function getValue () {\r\n  console.log(x);\r\n  console.log(p);\r\n}\r\n\r\nawait thing();\r\nlet p = 5;\r\n```\r\n\r\nwould become in the generator form:\r\n\r\n```js\r\nSystem.register(['foo'], function* (_export, _context) {\r\n  \"use strict\";\r\n\r\n  var x;\r\n  _export(0, function (_foo) {\r\n    x = _foo.x;\r\n  });\r\n\r\n  function getValue () {\r\n    console.log(x);\r\n    console.log(p);\r\n  }\r\n  _export('getValue', getValue);\r\n\r\n  // indicates end of declaration phase\r\n  yield;\r\n\r\n  // top-level await handled by returning a promise from execution yield\r\n  yield Promise.resolve()\r\n  .then(async function () {\r\n    await thing();\r\n\r\n    // BUG: Should have hoisted \"p\", using same hoisting logic we have currently\r\n    let p = 5;\r\n  });\r\n});\r\n```"}}
{"actor":{"display_login":"guybedford"}}