{"action":"created","comment":{"url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/comments/172658593","pull_request_review_id":101714503,"id":172658593,"diff_hunk":"@@ -54,8 +59,19 @@ function getAttributes(\n \n       const expr = parseExpression(val === true ? 'true' : val, context);\n \n-      if (!mustEscape && (!t.isStringLiteral(expr) || /(\\<\\>\\&)/.test(val))) {\n-        throw new Error('Unescaped attributes are not supported in react-pug');\n+      if (!mustEscape) {\n+        const isStringViaAliases =\n+          t.isStringLiteral(expr) && name !== 'className' && name !== 'id';\n+\n+        const isNotStringOrBoolean =\n+          !t.isStringLiteral(expr) && !t.isBooleanLiteral(expr);","path":"src/visitors/Tag.js","position":47,"original_position":47,"commit_id":"5f9c7610f8a9d74c432efcb9853ff06cbe341b96","original_commit_id":"5f9c7610f8a9d74c432efcb9853ff06cbe341b96","user":{"login":"ezhlobo","id":974552,"avatar_url":"https://avatars2.githubusercontent.com/u/974552?v=4","gravatar_id":"","url":"https://api.github.com/users/ezhlobo","html_url":"https://github.com/ezhlobo","followers_url":"https://api.github.com/users/ezhlobo/followers","following_url":"https://api.github.com/users/ezhlobo/following{/other_user}","gists_url":"https://api.github.com/users/ezhlobo/gists{/gist_id}","starred_url":"https://api.github.com/users/ezhlobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezhlobo/subscriptions","organizations_url":"https://api.github.com/users/ezhlobo/orgs","repos_url":"https://api.github.com/users/ezhlobo/repos","events_url":"https://api.github.com/users/ezhlobo/events{/privacy}","received_events_url":"https://api.github.com/users/ezhlobo/received_events","type":"User","site_admin":false},"body":"@ForbesLindesay I agree that my naming can confuse, but it was created with following reason in mind: all not obvious conditions should be commented. Variables are more convenient than just comments, so I used them.\r\n\r\n`isAllowedUnescapedAttribute` sounds not obvious because we don't use such naming through this plugin and pug (I mean it does not respect spirit of `mustEscape`). It's better to keep `shouldBeEscaped`, `allowedToBeEscaped`.\r\n\r\n### Let me show how did I achieve my code:\r\n\r\nWhen attribute is marked that we can skip its escaping, we should always show a message about unsupported feature. Two exceptions, where we should not show a message: \r\n\r\n1. if attribute is a string not from aliases (not from `className` and `id`)\r\n2. if attribute is not primitive (in pug it's everything besides string and booleans)\r\n\r\nIf I convert it to the code:\r\n\r\n```js\r\nif (!mustEscape) {\r\n  const isStringNotFromAliases = \r\n    t.isStringLiteral(expr) && name !== 'className' && name !== 'id';\r\n\r\n  const isNotPrimitive =\r\n    !t.isStringLiteral(expr) && !t.isBooleanLiteral(expr);\r\n\r\n  if (isStringNotFromAliases || isNotPrimitive) {\r\n    throw context.error(\r\n      'INVALID_EXPRESSION',\r\n      'Unescaped attributes are not supported in react-pug',\r\n    );\r\n  }\r\n}\r\n```\r\n\r\nThis snippet is what I suggest to leave. But I don't mind to make it much more compact by refactoring javascript, not the logic. If this is the case, then could you suggest any concrete solution that I can use? Maybe you can help me with optimizing the logic?","created_at":"2018-03-06T21:02:43Z","updated_at":"2018-03-06T21:02:43Z","html_url":"https://github.com/pugjs/babel-plugin-transform-react-pug/pull/33#discussion_r172658593","pull_request_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/comments/172658593"},"html":{"href":"https://github.com/pugjs/babel-plugin-transform-react-pug/pull/33#discussion_r172658593"},"pull_request":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33"}},"in_reply_to_id":172579475},"pull_request":{"url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33","id":168682005,"html_url":"https://github.com/pugjs/babel-plugin-transform-react-pug/pull/33","diff_url":"https://github.com/pugjs/babel-plugin-transform-react-pug/pull/33.diff","patch_url":"https://github.com/pugjs/babel-plugin-transform-react-pug/pull/33.patch","issue_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues/33","number":33,"state":"open","locked":false,"title":"Handle shorthands in attributes correctly","user":{"login":"ezhlobo","id":974552,"avatar_url":"https://avatars2.githubusercontent.com/u/974552?v=4","gravatar_id":"","url":"https://api.github.com/users/ezhlobo","html_url":"https://github.com/ezhlobo","followers_url":"https://api.github.com/users/ezhlobo/followers","following_url":"https://api.github.com/users/ezhlobo/following{/other_user}","gists_url":"https://api.github.com/users/ezhlobo/gists{/gist_id}","starred_url":"https://api.github.com/users/ezhlobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezhlobo/subscriptions","organizations_url":"https://api.github.com/users/ezhlobo/orgs","repos_url":"https://api.github.com/users/ezhlobo/repos","events_url":"https://api.github.com/users/ezhlobo/events{/privacy}","received_events_url":"https://api.github.com/users/ezhlobo/received_events","type":"User","site_admin":false},"body":"It adds supporting of shorthands in attributes. Initial issue [#1 (Fails on boolean attributes)](https://github.com/pugjs/babel-plugin-transform-react-pug/issues/1).\r\n\r\nNow following syntax won't throw an error:\r\n\r\n```pug\r\ndiv(first second third)\r\n```\r\n\r\nBut this one will throw:\r\n\r\n```pug\r\ndiv(\r\n  first!=\"stirng\" \r\n  second!=variable\r\n)\r\n```\r\n\r\nChecklist:\r\n\r\n- [x] Use `context.error` instead of `new Error` to keep well-described errors\r\n- [ ] Update `pug-lexer` and remove workaround to keep `mustEscape` correct","created_at":"2018-02-12T20:38:33Z","updated_at":"2018-03-06T21:02:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d61e4ad483d434ed3effea9e073474c7e404dfe","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33/commits","review_comments_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33/comments","review_comment_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues/33/comments","statuses_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/statuses/5f9c7610f8a9d74c432efcb9853ff06cbe341b96","head":{"label":"ezhlobo:attr-shorthands","ref":"attr-shorthands","sha":"5f9c7610f8a9d74c432efcb9853ff06cbe341b96","user":{"login":"ezhlobo","id":974552,"avatar_url":"https://avatars2.githubusercontent.com/u/974552?v=4","gravatar_id":"","url":"https://api.github.com/users/ezhlobo","html_url":"https://github.com/ezhlobo","followers_url":"https://api.github.com/users/ezhlobo/followers","following_url":"https://api.github.com/users/ezhlobo/following{/other_user}","gists_url":"https://api.github.com/users/ezhlobo/gists{/gist_id}","starred_url":"https://api.github.com/users/ezhlobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezhlobo/subscriptions","organizations_url":"https://api.github.com/users/ezhlobo/orgs","repos_url":"https://api.github.com/users/ezhlobo/repos","events_url":"https://api.github.com/users/ezhlobo/events{/privacy}","received_events_url":"https://api.github.com/users/ezhlobo/received_events","type":"User","site_admin":false},"repo":{"id":104320995,"name":"babel-plugin-transform-react-pug","full_name":"ezhlobo/babel-plugin-transform-react-pug","owner":{"login":"ezhlobo","id":974552,"avatar_url":"https://avatars2.githubusercontent.com/u/974552?v=4","gravatar_id":"","url":"https://api.github.com/users/ezhlobo","html_url":"https://github.com/ezhlobo","followers_url":"https://api.github.com/users/ezhlobo/followers","following_url":"https://api.github.com/users/ezhlobo/following{/other_user}","gists_url":"https://api.github.com/users/ezhlobo/gists{/gist_id}","starred_url":"https://api.github.com/users/ezhlobo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezhlobo/subscriptions","organizations_url":"https://api.github.com/users/ezhlobo/orgs","repos_url":"https://api.github.com/users/ezhlobo/repos","events_url":"https://api.github.com/users/ezhlobo/events{/privacy}","received_events_url":"https://api.github.com/users/ezhlobo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ezhlobo/babel-plugin-transform-react-pug","description":"A plugin for transpiling pug templates to jsx","fork":true,"url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug","forks_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/forks","keys_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/teams","hooks_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/hooks","issue_events_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/issues/events{/number}","events_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/events","assignees_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/assignees{/user}","branches_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/branches{/branch}","tags_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/tags","blobs_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/git/refs{/sha}","trees_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/statuses/{sha}","languages_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/languages","stargazers_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/stargazers","contributors_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/contributors","subscribers_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/subscribers","subscription_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/subscription","commits_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/commits{/sha}","git_commits_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/git/commits{/sha}","comments_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/comments{/number}","issue_comment_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/issues/comments{/number}","contents_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/contents/{+path}","compare_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/merges","archive_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/downloads","issues_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/issues{/number}","pulls_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/pulls{/number}","milestones_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/milestones{/number}","notifications_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/labels{/name}","releases_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/releases{/id}","deployments_url":"https://api.github.com/repos/ezhlobo/babel-plugin-transform-react-pug/deployments","created_at":"2017-09-21T08:19:44Z","updated_at":"2017-09-21T08:19:45Z","pushed_at":"2018-03-06T15:45:41Z","git_url":"git://github.com/ezhlobo/babel-plugin-transform-react-pug.git","ssh_url":"git@github.com:ezhlobo/babel-plugin-transform-react-pug.git","clone_url":"https://github.com/ezhlobo/babel-plugin-transform-react-pug.git","svn_url":"https://github.com/ezhlobo/babel-plugin-transform-react-pug","homepage":null,"size":440,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pugjs:master","ref":"master","sha":"83d33508d56d296d592af141a73529bc91c267f9","user":{"login":"pugjs","id":9338635,"avatar_url":"https://avatars1.githubusercontent.com/u/9338635?v=4","gravatar_id":"","url":"https://api.github.com/users/pugjs","html_url":"https://github.com/pugjs","followers_url":"https://api.github.com/users/pugjs/followers","following_url":"https://api.github.com/users/pugjs/following{/other_user}","gists_url":"https://api.github.com/users/pugjs/gists{/gist_id}","starred_url":"https://api.github.com/users/pugjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pugjs/subscriptions","organizations_url":"https://api.github.com/users/pugjs/orgs","repos_url":"https://api.github.com/users/pugjs/repos","events_url":"https://api.github.com/users/pugjs/events{/privacy}","received_events_url":"https://api.github.com/users/pugjs/received_events","type":"Organization","site_admin":false},"repo":{"id":48664679,"name":"babel-plugin-transform-react-pug","full_name":"pugjs/babel-plugin-transform-react-pug","owner":{"login":"pugjs","id":9338635,"avatar_url":"https://avatars1.githubusercontent.com/u/9338635?v=4","gravatar_id":"","url":"https://api.github.com/users/pugjs","html_url":"https://github.com/pugjs","followers_url":"https://api.github.com/users/pugjs/followers","following_url":"https://api.github.com/users/pugjs/following{/other_user}","gists_url":"https://api.github.com/users/pugjs/gists{/gist_id}","starred_url":"https://api.github.com/users/pugjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pugjs/subscriptions","organizations_url":"https://api.github.com/users/pugjs/orgs","repos_url":"https://api.github.com/users/pugjs/repos","events_url":"https://api.github.com/users/pugjs/events{/privacy}","received_events_url":"https://api.github.com/users/pugjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pugjs/babel-plugin-transform-react-pug","description":"A plugin for transpiling pug templates to jsx","fork":false,"url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug","forks_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/forks","keys_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/teams","hooks_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/hooks","issue_events_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues/events{/number}","events_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/events","assignees_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/assignees{/user}","branches_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/branches{/branch}","tags_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/tags","blobs_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/git/refs{/sha}","trees_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/statuses/{sha}","languages_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/languages","stargazers_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/stargazers","contributors_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/contributors","subscribers_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/subscribers","subscription_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/subscription","commits_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/commits{/sha}","git_commits_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/git/commits{/sha}","comments_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/comments{/number}","issue_comment_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues/comments{/number}","contents_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/contents/{+path}","compare_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/merges","archive_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/downloads","issues_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues{/number}","pulls_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls{/number}","milestones_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/milestones{/number}","notifications_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/labels{/name}","releases_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/releases{/id}","deployments_url":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/deployments","created_at":"2015-12-27T23:37:08Z","updated_at":"2018-03-06T20:07:00Z","pushed_at":"2018-03-06T15:45:42Z","git_url":"git://github.com/pugjs/babel-plugin-transform-react-pug.git","ssh_url":"git@github.com:pugjs/babel-plugin-transform-react-pug.git","clone_url":"https://github.com/pugjs/babel-plugin-transform-react-pug.git","svn_url":"https://github.com/pugjs/babel-plugin-transform-react-pug","homepage":null,"size":192,"stargazers_count":144,"watchers_count":144,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"archived":false,"open_issues_count":14,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":13,"open_issues":14,"watchers":144,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33"},"html":{"href":"https://github.com/pugjs/babel-plugin-transform-react-pug/pull/33"},"issue":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues/33"},"comments":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/pugjs/babel-plugin-transform-react-pug/statuses/5f9c7610f8a9d74c432efcb9853ff06cbe341b96"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"ezhlobo"}}