{"action":"created","issue":{"url":"https://api.github.com/repos/radi-js/radi/issues/4","repository_url":"https://api.github.com/repos/radi-js/radi","labels_url":"https://api.github.com/repos/radi-js/radi/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/radi-js/radi/issues/4/comments","events_url":"https://api.github.com/repos/radi-js/radi/issues/4/events","html_url":"https://github.com/radi-js/radi/issues/4","id":303459606,"number":4,"title":"Suggestion to improve the view parser","user":{"login":"pygy","id":54515,"avatar_url":"https://avatars1.githubusercontent.com/u/54515?v=4","gravatar_id":"","url":"https://api.github.com/users/pygy","html_url":"https://github.com/pygy","followers_url":"https://api.github.com/users/pygy/followers","following_url":"https://api.github.com/users/pygy/following{/other_user}","gists_url":"https://api.github.com/users/pygy/gists{/gist_id}","starred_url":"https://api.github.com/users/pygy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pygy/subscriptions","organizations_url":"https://api.github.com/users/pygy/orgs","repos_url":"https://api.github.com/users/pygy/repos","events_url":"https://api.github.com/users/pygy/events{/privacy}","received_events_url":"https://api.github.com/users/pygy/received_events","type":"User","site_admin":false},"labels":[{"id":799649265,"url":"https://api.github.com/repos/radi-js/radi/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":799649267,"url":"https://api.github.com/repos/radi-js/radi/labels/good%20first%20issue","name":"good first issue","color":"7057ff","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-08T12:15:42Z","updated_at":"2018-03-08T17:18:54Z","closed_at":null,"author_association":"NONE","body":"The way you parse the views currently is quite buggy, it can fail if comments or parens are present in strings.\r\n\r\nA better strategy would be to use a single regex that matches strings, comments and the `/l\\s*(/`, and ignore the strings/comment matches.\r\n\r\nSomething like this would do:\r\n\r\n```JS\r\nL_MATCHER = /((?:^|[^\\w\\d$])l\\s*\\()|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*?\\n/g\r\n\r\nfunction findL(str, i) {\r\n  var match;\r\n  L_MATCHER.lastIndex = i;\r\n  while (match = L_MATCHER.exec(str)) if(match[1] != null) {\r\n    return match.index + match[1].length;\r\n  }\r\n}\r\n```\r\n\r\nYou could also use a similar strategy to match parentheses.\r\n\r\n`PAREN_MATCHER = /[()]|\"(?:\\\\.|[^\"\\n])*\"|'(?:\\\\.|[^'\\n])*'|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*?\\n/g`\r\nthen ignore cases where `match[0]` is not a parenthesis."},"comment":{"url":"https://api.github.com/repos/radi-js/radi/issues/comments/371557600","html_url":"https://github.com/radi-js/radi/issues/4#issuecomment-371557600","issue_url":"https://api.github.com/repos/radi-js/radi/issues/4","id":371557600,"user":{"login":"lhorie","id":1637573,"avatar_url":"https://avatars3.githubusercontent.com/u/1637573?v=4","gravatar_id":"","url":"https://api.github.com/users/lhorie","html_url":"https://github.com/lhorie","followers_url":"https://api.github.com/users/lhorie/followers","following_url":"https://api.github.com/users/lhorie/following{/other_user}","gists_url":"https://api.github.com/users/lhorie/gists{/gist_id}","starred_url":"https://api.github.com/users/lhorie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lhorie/subscriptions","organizations_url":"https://api.github.com/users/lhorie/orgs","repos_url":"https://api.github.com/users/lhorie/repos","events_url":"https://api.github.com/users/lhorie/events{/privacy}","received_events_url":"https://api.github.com/users/lhorie/received_events","type":"User","site_admin":false},"created_at":"2018-03-08T17:18:54Z","updated_at":"2018-03-08T17:18:54Z","author_association":"NONE","body":"I'm not sure this approach is worth pursuing further at all. The function call regex/replace will break non-local variable references. Here's a simple test case:\r\n\r\n```js\r\nconst { r, l: x, mount, component } = radi;\r\n \r\nconst counter = component({\r\n  view: function() {\r\n    return (\r\n      r('button', {onclick: this.up}, 'Click me ', x(this.counter))\r\n    )\r\n  },\r\n  state: {\r\n    counter: 0\r\n  },\r\n  actions: {\r\n    up() {\r\n      this.counter += 1;\r\n    },\r\n  }\r\n});\r\n \r\nmount(new counter(), document.body);\r\n\r\nconst input = document.getElementById('0');\r\n```\r\n\r\nSo if `l` is renamed (which may happen, for example, if a bundler or a minifier renames it), things break.\r\n\r\nUsing any library will also break:\r\n\r\n```js\r\nconst { r, l, mount, component } = radi;\r\n\r\nfunction format(date) {return date.toString();}\r\n \r\nconst counter = component({\r\n  view: function() {\r\n    format(new Date());\r\n    return (\r\n      r('div', format(new Date))\r\n    )\r\n  },\r\n  state: {\r\n    counter: 0\r\n  },\r\n  actions: {\r\n    up() {\r\n      this.counter += 1;\r\n    },\r\n  }\r\n});\r\n \r\nmount(new counter(), document.body);\r\n\r\nconst input = document.getElementById('0');\r\n```"}}
{"actor":{"display_login":"lhorie"}}