{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/5236","repository_url":"https://api.github.com/repos/Microsoft/ChakraCore","labels_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/5236/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/5236/comments","events_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/5236/events","html_url":"https://github.com/Microsoft/ChakraCore/issues/5236","id":326726607,"node_id":"MDU6SXNzdWUzMjY3MjY2MDc=","number":5236,"title":"Module function exports not hoisted","user":{"login":"rhuanjl","id":30090552,"node_id":"MDQ6VXNlcjMwMDkwNTUy","avatar_url":"https://avatars3.githubusercontent.com/u/30090552?v=4","gravatar_id":"","url":"https://api.github.com/users/rhuanjl","html_url":"https://github.com/rhuanjl","followers_url":"https://api.github.com/users/rhuanjl/followers","following_url":"https://api.github.com/users/rhuanjl/following{/other_user}","gists_url":"https://api.github.com/users/rhuanjl/gists{/gist_id}","starred_url":"https://api.github.com/users/rhuanjl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhuanjl/subscriptions","organizations_url":"https://api.github.com/users/rhuanjl/orgs","repos_url":"https://api.github.com/users/rhuanjl/repos","events_url":"https://api.github.com/users/rhuanjl/events{/privacy}","received_events_url":"https://api.github.com/users/rhuanjl/received_events","type":"User","site_admin":false},"labels":[{"id":307793022,"node_id":"MDU6TGFiZWwzMDc3OTMwMjI=","url":"https://api.github.com/repos/Microsoft/ChakraCore/labels/Bug","name":"Bug","color":"dd2020","default":false},{"id":794389608,"node_id":"MDU6TGFiZWw3OTQzODk2MDg=","url":"https://api.github.com/repos/Microsoft/ChakraCore/labels/Severity:%203","name":"Severity: 3","color":"b99695","default":false}],"state":"open","locked":false,"assignee":{"login":"boingoing","id":1569843,"node_id":"MDQ6VXNlcjE1Njk4NDM=","avatar_url":"https://avatars3.githubusercontent.com/u/1569843?v=4","gravatar_id":"","url":"https://api.github.com/users/boingoing","html_url":"https://github.com/boingoing","followers_url":"https://api.github.com/users/boingoing/followers","following_url":"https://api.github.com/users/boingoing/following{/other_user}","gists_url":"https://api.github.com/users/boingoing/gists{/gist_id}","starred_url":"https://api.github.com/users/boingoing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boingoing/subscriptions","organizations_url":"https://api.github.com/users/boingoing/orgs","repos_url":"https://api.github.com/users/boingoing/repos","events_url":"https://api.github.com/users/boingoing/events{/privacy}","received_events_url":"https://api.github.com/users/boingoing/received_events","type":"User","site_admin":false},"assignees":[{"login":"boingoing","id":1569843,"node_id":"MDQ6VXNlcjE1Njk4NDM=","avatar_url":"https://avatars3.githubusercontent.com/u/1569843?v=4","gravatar_id":"","url":"https://api.github.com/users/boingoing","html_url":"https://github.com/boingoing","followers_url":"https://api.github.com/users/boingoing/followers","following_url":"https://api.github.com/users/boingoing/following{/other_user}","gists_url":"https://api.github.com/users/boingoing/gists{/gist_id}","starred_url":"https://api.github.com/users/boingoing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boingoing/subscriptions","organizations_url":"https://api.github.com/users/boingoing/orgs","repos_url":"https://api.github.com/users/boingoing/repos","events_url":"https://api.github.com/users/boingoing/events{/privacy}","received_events_url":"https://api.github.com/users/boingoing/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/Microsoft/ChakraCore/milestones/8","html_url":"https://github.com/Microsoft/ChakraCore/milestone/8","labels_url":"https://api.github.com/repos/Microsoft/ChakraCore/milestones/8/labels","id":2206099,"node_id":"MDk6TWlsZXN0b25lMjIwNjA5OQ==","number":8,"title":"vNext","description":"Issues targeted for the next release of ChakraCore.","creator":{"login":"dilijev","id":494055,"node_id":"MDQ6VXNlcjQ5NDA1NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/494055?v=4","gravatar_id":"","url":"https://api.github.com/users/dilijev","html_url":"https://github.com/dilijev","followers_url":"https://api.github.com/users/dilijev/followers","following_url":"https://api.github.com/users/dilijev/following{/other_user}","gists_url":"https://api.github.com/users/dilijev/gists{/gist_id}","starred_url":"https://api.github.com/users/dilijev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dilijev/subscriptions","organizations_url":"https://api.github.com/users/dilijev/orgs","repos_url":"https://api.github.com/users/dilijev/repos","events_url":"https://api.github.com/users/dilijev/events{/privacy}","received_events_url":"https://api.github.com/users/dilijev/received_events","type":"User","site_admin":false},"open_issues":120,"closed_issues":127,"state":"open","created_at":"2016-12-19T23:56:06Z","updated_at":"2018-11-01T19:05:48Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2018-05-26T10:05:56Z","updated_at":"2018-11-23T14:15:37Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Raising this as a separate issue from #5171 though it's related. #5171 was specifically talking about a regression - the only change having been module load order.\r\n\r\nBut this is the reason why the load order mattered in that case - in CC module function exports are not treated as hoistable exports. (In fact I don't think CC has a concept of a hoistable export)\r\n\r\nIllustration:\r\n```js\r\n//a.js\r\nimport \"./b.js\";\r\nconsole.log(\"a.js\");\r\nexport function func(){}\r\n\r\n//b.js\r\nimport {func} from \"./a.js\";\r\nconsole.log(\"b.js\");\r\nconsole.log(func);\r\n```\r\nResults\r\n1. Load a.js:\r\n```\r\nb.js\r\nundefined\r\na.js\r\n```\r\n2. Load b.js\r\n```\r\na.js\r\nb.js\r\nfunction func(){}\r\n```\r\nConversely if you change them to .mjs and run with node:\r\nResults\r\n1. Load a.mjs:\r\n```\r\nb.mjs\r\n[Function: func]\r\na.mjs\r\n```\r\n2. Load b.mjs\r\n```\r\na.mjs\r\nb.mjs\r\n[Function: func]\r\n```\r\nThe function export from a.js gets hoisted under v8 so the function is available at run time whichever way around you load the modules whereas under CC it is not hoisted and so you have to get your load order right in circular cases to avoid it being undefined."},"comment":{"url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/comments/441251450","html_url":"https://github.com/Microsoft/ChakraCore/issues/5236#issuecomment-441251450","issue_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/5236","id":441251450,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MTI1MTQ1MA==","user":{"login":"rhuanjl","id":30090552,"node_id":"MDQ6VXNlcjMwMDkwNTUy","avatar_url":"https://avatars3.githubusercontent.com/u/30090552?v=4","gravatar_id":"","url":"https://api.github.com/users/rhuanjl","html_url":"https://github.com/rhuanjl","followers_url":"https://api.github.com/users/rhuanjl/followers","following_url":"https://api.github.com/users/rhuanjl/following{/other_user}","gists_url":"https://api.github.com/users/rhuanjl/gists{/gist_id}","starred_url":"https://api.github.com/users/rhuanjl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhuanjl/subscriptions","organizations_url":"https://api.github.com/users/rhuanjl/orgs","repos_url":"https://api.github.com/users/rhuanjl/repos","events_url":"https://api.github.com/users/rhuanjl/events{/privacy}","received_events_url":"https://api.github.com/users/rhuanjl/received_events","type":"User","site_admin":false},"created_at":"2018-11-23T14:15:37Z","updated_at":"2018-11-23T14:15:37Z","author_association":"CONTRIBUTOR","body":"I figure this should actually be a relatively simple fix:\r\n1. Optionally add some code to detect circularities so the fix is only applied when it's relevant\r\n2. Create an edited GenerateRootFunction method that tells the bytecodeemitter that the function is a generator - it will automatically insert a yield at the top of the function body https://github.com/Microsoft/ChakraCore/blob/master/lib/Runtime/ByteCode/ByteCodeEmitter.cpp#L3035-L3045\r\n3. Split the module execution loop into two loops so that each function gets called once (to hit that first yield and define variables) and again to actually execute\r\n\r\nWith the points I've picked up on how generators work from the piece I've been doing on async generators I could likely do this."}}
{"actor":{"display_login":"rhuanjl"}}