{"action":"opened","issue":{"url":"https://api.github.com/repos/Macmee/import-export/issues/1","repository_url":"https://api.github.com/repos/Macmee/import-export","labels_url":"https://api.github.com/repos/Macmee/import-export/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/Macmee/import-export/issues/1/comments","events_url":"https://api.github.com/repos/Macmee/import-export/issues/1/events","html_url":"https://github.com/Macmee/import-export/issues/1","id":160580246,"number":1,"title":"Can produce hard-to-understand bugs when it transforms imported modules","user":{"login":"yortus","id":1252361,"avatar_url":"https://avatars.githubusercontent.com/u/1252361?v=3","gravatar_id":"","url":"https://api.github.com/users/yortus","html_url":"https://github.com/yortus","followers_url":"https://api.github.com/users/yortus/followers","following_url":"https://api.github.com/users/yortus/following{/other_user}","gists_url":"https://api.github.com/users/yortus/gists{/gist_id}","starred_url":"https://api.github.com/users/yortus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yortus/subscriptions","organizations_url":"https://api.github.com/users/yortus/orgs","repos_url":"https://api.github.com/users/yortus/repos","events_url":"https://api.github.com/users/yortus/events{/privacy}","received_events_url":"https://api.github.com/users/yortus/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-06-16T05:26:57Z","updated_at":"2016-06-16T05:26:57Z","closed_at":null,"body":"Hi @Macmee, \r\n\r\nI saw this on /r/node and thought it seems useful. Thanks for making it!\r\n\r\nI wanted to suggest using a proper parser, rather than regex-based replacing, to rewrite the source modules as they are loaded. The reason is that the regexes will replace matching text even when not appropriate, such as inside strings, regexes, and comments. If you'd rather keep it simple, then perhaps put a warning in the README about this behaviour as it would be hard to debug for someone hit by it.\r\n\r\nAs an example of what I mean, if you use this library to import itself, it will make replacements in the  [`index.js`](https://github.com/Macmee/import-export/blob/19c950b2e114c483fdedd6ec6534ce0d1040a3ee/index.js) that mess up the regexes resulting in a mysteriously non-working module whose source becomes (note 4 out of 6 regexes are corrupted):\r\n\r\n```js\r\nvar hook = require('node-hook');\r\n\r\nvar hook = { hook(...args) { } };\r\nhook.hook('.js', (src, name) => {\r\n    src = src.replace(/import ([^{]*?) from '(.*?)'/g, 'const $1 = require(\"$2\")');\r\n    src = src.replace(/module.exports = ([^ ]*)/g, 'module.exports = $1');\r\n    src = src.replace(/export (var|let|const) ([a-zA-Z0-9_$]*)/g, '$1 $2 = module.exports.$2');\r\n    src = src.replace(/var  = module.exports. = function([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = function');\r\n    src = src.replace(/var  = module.exports. = class([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = class');\r\n    src = src.replace(/var (.*?)= require(\"(.*?)\").(.*?);/g, (all, $1, $2) => {\r\n        return $1.split(\",\")\r\n            .map(part => 'var ' + part + '= require(\"' + $2 + '\").' + part.trim() + ';')\r\n            .join('');\r\n    });\r\n    return src;\r\n});\r\n```\r\n\r\n"}}
{"actor":{"display_login":"yortus"}}