From 5fe2c55aeaf38895380a08498bbba2263366c3a1 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 4 Jan 2023 19:16:45 +0800 Subject: [PATCH 1/8] Handlebars: Remove HTML void element check --- package.json | 1 - scripts/vendors/vendor-meta.json | 24 --- scripts/vendors/vendors.mjs | 1 - src/language-handlebars/utils.js | 3 - .../__snapshots__/jsfmt.spec.js.snap | 84 ++++++++ .../handlebars/element-node/jsfmt.spec.js | 23 ++- .../__snapshots__/jsfmt.spec.js.snap | 192 ++++++++++++++++++ .../misc/errors/handlebars/jsfmt.spec.js | 32 ++- vendors/html-void-elements.json | 27 --- yarn.lock | 5 - 10 files changed, 329 insertions(+), 63 deletions(-) delete mode 100644 vendors/html-void-elements.json diff --git a/package.json b/package.json index 1b770a75e410..b13432e150bd 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "html-element-attributes": "3.1.0", "html-styles": "1.0.0", "html-tag-names": "2.0.1", - "html-void-elements": "2.0.1", "ignore": "5.2.0", "jest-docblock": "28.1.1", "json5": "2.2.2", diff --git a/scripts/vendors/vendor-meta.json b/scripts/vendors/vendor-meta.json index a54ea4607ba1..0f2a7d6f7651 100644 --- a/scripts/vendors/vendor-meta.json +++ b/scripts/vendors/vendor-meta.json @@ -6,7 +6,6 @@ "execa": "execa.js", "html-element-attributes": "html-element-attributes.json", "html-tag-names": "html-tag-names.json", - "html-void-elements": "html-void-elements.json", "leven": "leven.js", "mem": "mem.js", "sdbm": "sdbm.js", @@ -396,29 +395,6 @@ } ] }, - { - "name": "html-void-elements", - "maintainers": [], - "version": "2.0.1", - "description": "List of HTML void tag names", - "repository": "wooorm/html-void-elements", - "homepage": null, - "private": false, - "license": "MIT", - "licenseText": "(The MIT License)\n\nCopyright (c) 2016 Titus Wormer \n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", - "author": { - "name": "Titus Wormer", - "email": "tituswormer@gmail.com", - "url": "https://wooorm.com" - }, - "contributors": [ - { - "name": "Titus Wormer", - "email": "tituswormer@gmail.com", - "url": "https://wooorm.com" - } - ] - }, { "name": "leven", "maintainers": [], diff --git a/scripts/vendors/vendors.mjs b/scripts/vendors/vendors.mjs index 0473e0daa5e3..888fb6345c94 100644 --- a/scripts/vendors/vendors.mjs +++ b/scripts/vendors/vendors.mjs @@ -5,7 +5,6 @@ const vendors = [ "execa", "html-element-attributes", "html-tag-names", - "html-void-elements", "leven", "mem", "sdbm", diff --git a/src/language-handlebars/utils.js b/src/language-handlebars/utils.js index aef7f46f813f..04e846d2be02 100644 --- a/src/language-handlebars/utils.js +++ b/src/language-handlebars/utils.js @@ -1,6 +1,5 @@ "use strict"; -const { htmlVoidElements } = require("../../vendors/html-void-elements.json"); const getLast = require("../utils/get-last.js"); function isLastNodeOfSiblings(path) { @@ -37,10 +36,8 @@ function isGlimmerComponent(node) { ); } -const voidTags = new Set(htmlVoidElements); function isVoid(node) { return ( - voidTags.has(node.tag) || node.selfClosing === true || (isGlimmerComponent(node) && node.children.every((node) => isWhitespaceNode(node))) diff --git a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap index c1aeb2e785b0..37ad4c7e7116 100644 --- a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap @@ -111,3 +111,87 @@ printWidth: 80 ================================================================================ `; + +exports[`snippet: basefont format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; + +exports[`snippet: bgsound format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; + +exports[`snippet: frame format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; + +exports[`snippet: image format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; + +exports[`snippet: isindex format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; + +exports[`snippet: menuitem format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; + +exports[`snippet: nextid format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + text +=====================================output===================================== + text +================================================================================ +`; diff --git a/tests/format/handlebars/element-node/jsfmt.spec.js b/tests/format/handlebars/element-node/jsfmt.spec.js index da9b88409539..0210e45899e8 100644 --- a/tests/format/handlebars/element-node/jsfmt.spec.js +++ b/tests/format/handlebars/element-node/jsfmt.spec.js @@ -1 +1,22 @@ -run_spec(__dirname, ["glimmer"]); +run_spec( + { + dirname: __dirname, + /* + Missed html void tags in glimmer parser + https://github.com/glimmerjs/glimmer-vm/blob/ec5648f3895b9ab8d085523be001553746221449/packages/%40glimmer/syntax/lib/parser/tokenizer-event-handlers.ts#LL7C13-L7C13 + https://github.com/glimmerjs/glimmer-vm/blob/ec5648f3895b9ab8d085523be001553746221449/packages/%40glimmer/syntax/lib/generation/printer.ts#L8-L9 + Please move tags to `tests/format/misc/errors/handlebars/jsfmt.spec.js` + when removing from this list + */ + snippets: [ + "basefont", + "bgsound", + "frame", + "image", + "isindex", + "menuitem", + "nextid", + ].map((tag) => ({ name: tag, code: `<${tag}> text ` })), + }, + ["glimmer"] +); diff --git a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap index 7d7866680077..5f9ff13aa623 100644 --- a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap @@ -38,6 +38,198 @@ Expecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL' 4 |" `; +exports[`snippet: area [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 6) (1:6) +> 1 | + | ^^^^^^^" +`; + +exports[`snippet: base [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 6) (1:6) +> 1 | + | ^^^^^^^" +`; + +exports[`snippet: br [glimmer] format 1`] = ` +"
elements do not need end tags. You should remove it: + +| +|
+| + +(error occurred in 'an unknown module' @ line 1 : column 4) (1:4) +> 1 |

+ | ^^^^^" +`; + +exports[`snippet: col [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 5) (1:5) +> 1 | + | ^^^^^^" +`; + +exports[`snippet: command [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 9) (1:9) +> 1 | + | ^^^^^^^^^^" +`; + +exports[`snippet: embed [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 7) (1:7) +> 1 | + | ^^^^^^^^" +`; + +exports[`snippet: hr [glimmer] format 1`] = ` +"
elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 4) (1:4) +> 1 |
+ | ^^^^^" +`; + +exports[`snippet: img [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 5) (1:5) +> 1 | + | ^^^^^^" +`; + +exports[`snippet: input [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 7) (1:7) +> 1 | + | ^^^^^^^^" +`; + +exports[`snippet: keygen [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 8) (1:8) +> 1 | + | ^^^^^^^^^" +`; + +exports[`snippet: link [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 6) (1:6) +> 1 | + | ^^^^^^^" +`; + +exports[`snippet: meta [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 6) (1:6) +> 1 | + | ^^^^^^^" +`; + +exports[`snippet: param [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 7) (1:7) +> 1 | + | ^^^^^^^^" +`; + +exports[`snippet: source [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 8) (1:8) +> 1 | + | ^^^^^^^^^" +`; + +exports[`snippet: track [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 7) (1:7) +> 1 | + | ^^^^^^^^" +`; + +exports[`snippet: wbr [glimmer] format 1`] = ` +" elements do not need end tags. You should remove it: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 5) (1:5) +> 1 | + | ^^^^^^" +`; + exports[`tilde-comments-1.hbs [glimmer] format 1`] = ` "Parse error on line 1: {{~}} diff --git a/tests/format/misc/errors/handlebars/jsfmt.spec.js b/tests/format/misc/errors/handlebars/jsfmt.spec.js index da9b88409539..685341867ab0 100644 --- a/tests/format/misc/errors/handlebars/jsfmt.spec.js +++ b/tests/format/misc/errors/handlebars/jsfmt.spec.js @@ -1 +1,31 @@ -run_spec(__dirname, ["glimmer"]); +run_spec( + { + dirname: __dirname, + snippets: [ + "area", + "base", + // "basefont", + // "bgsound", + "br", + "col", + "command", + "embed", + // "frame", + "hr", + // "image", + "img", + "input", + // "isindex", + "keygen", + "link", + // "menuitem", + "meta", + // "nextid", + "param", + "source", + "track", + "wbr", + ].map((tag) => ({ name: tag, code: `<${tag}>` })), + }, + ["glimmer"] +); diff --git a/vendors/html-void-elements.json b/vendors/html-void-elements.json deleted file mode 100644 index f20eebfdfb6b..000000000000 --- a/vendors/html-void-elements.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "htmlVoidElements": [ - "area", - "base", - "basefont", - "bgsound", - "br", - "col", - "command", - "embed", - "frame", - "hr", - "image", - "img", - "input", - "isindex", - "keygen", - "link", - "menuitem", - "meta", - "nextid", - "param", - "source", - "track", - "wbr" - ] -} diff --git a/yarn.lock b/yarn.lock index b2e313328089..8d9a37121eb7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3802,11 +3802,6 @@ html-tag-names@2.0.1: resolved "https://registry.yarnpkg.com/html-tag-names/-/html-tag-names-2.0.1.tgz#5626263e7d7b15789fa35a9f816234156901adc6" integrity sha512-PX8KyLG7dwsjis3NPj1u+/EJf2CgH2d+qzekQpnlCOPQ6Uu6T8+F2ZqQg+wtsP+WKhxK3QMN9Garcwr7fCRhxA== -html-void-elements@2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/html-void-elements/-/html-void-elements-2.0.1.tgz#29459b8b05c200b6c5ee98743c41b979d577549f" - integrity sha512-0quDb7s97CfemeJAnW9wC0hw78MtW7NU3hqtCD75g2vFlDLt36llsYD7uB7SUzojLMP24N5IatXf7ylGXiGG9A== - http-proxy-agent@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" From 2be302435bceb6a9a3797e9d3f12d6f51cc66ebd Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 4 Jan 2023 19:30:21 +0800 Subject: [PATCH 2/8] spellcheck --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index d2cb167bf4b4..bd8c7e7d4a94 100644 --- a/cspell.json +++ b/cspell.json @@ -33,6 +33,7 @@ "Bekkelund", "Bento", "bfnrt", + "bgsound", "binaryish", "bindon", "bitshift", From ea0750365456325386ea742a87b3404df19079e4 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 4 Jan 2023 19:40:09 +0800 Subject: [PATCH 3/8] Add test for void elements --- .../element-node/__snapshots__/jsfmt.spec.js.snap | 15 +++++++++++++++ .../handlebars/element-node/void-elements.hbs | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 tests/format/handlebars/element-node/void-elements.hbs diff --git a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap index 37ad4c7e7116..3a289f54b767 100644 --- a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap @@ -195,3 +195,18 @@ printWidth: 80 text ================================================================================ `; + +exports[`void-elements.hbs format 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + + + +=====================================output===================================== + + +================================================================================ +`; diff --git a/tests/format/handlebars/element-node/void-elements.hbs b/tests/format/handlebars/element-node/void-elements.hbs new file mode 100644 index 000000000000..1dd3d97e4767 --- /dev/null +++ b/tests/format/handlebars/element-node/void-elements.hbs @@ -0,0 +1,2 @@ + + From 28c9372de9dae37d6fe807c5b4a7373f36bdc5a5 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 4 Jan 2023 19:46:58 +0800 Subject: [PATCH 4/8] Bring check back --- package.json | 1 + scripts/vendors/vendor-meta.json | 24 +++++ scripts/vendors/vendors.mjs | 1 + src/language-handlebars/utils.js | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- .../handlebars/element-node/jsfmt.spec.js | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 96 +++++++++++++++++++ .../misc/errors/handlebars/jsfmt.spec.js | 61 +++++++----- vendors/html-void-elements.json | 27 ++++++ yarn.lock | 5 + 10 files changed, 197 insertions(+), 28 deletions(-) create mode 100644 vendors/html-void-elements.json diff --git a/package.json b/package.json index b13432e150bd..1b770a75e410 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "html-element-attributes": "3.1.0", "html-styles": "1.0.0", "html-tag-names": "2.0.1", + "html-void-elements": "2.0.1", "ignore": "5.2.0", "jest-docblock": "28.1.1", "json5": "2.2.2", diff --git a/scripts/vendors/vendor-meta.json b/scripts/vendors/vendor-meta.json index 0f2a7d6f7651..a54ea4607ba1 100644 --- a/scripts/vendors/vendor-meta.json +++ b/scripts/vendors/vendor-meta.json @@ -6,6 +6,7 @@ "execa": "execa.js", "html-element-attributes": "html-element-attributes.json", "html-tag-names": "html-tag-names.json", + "html-void-elements": "html-void-elements.json", "leven": "leven.js", "mem": "mem.js", "sdbm": "sdbm.js", @@ -395,6 +396,29 @@ } ] }, + { + "name": "html-void-elements", + "maintainers": [], + "version": "2.0.1", + "description": "List of HTML void tag names", + "repository": "wooorm/html-void-elements", + "homepage": null, + "private": false, + "license": "MIT", + "licenseText": "(The MIT License)\n\nCopyright (c) 2016 Titus Wormer \n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", + "author": { + "name": "Titus Wormer", + "email": "tituswormer@gmail.com", + "url": "https://wooorm.com" + }, + "contributors": [ + { + "name": "Titus Wormer", + "email": "tituswormer@gmail.com", + "url": "https://wooorm.com" + } + ] + }, { "name": "leven", "maintainers": [], diff --git a/scripts/vendors/vendors.mjs b/scripts/vendors/vendors.mjs index 888fb6345c94..0473e0daa5e3 100644 --- a/scripts/vendors/vendors.mjs +++ b/scripts/vendors/vendors.mjs @@ -5,6 +5,7 @@ const vendors = [ "execa", "html-element-attributes", "html-tag-names", + "html-void-elements", "leven", "mem", "sdbm", diff --git a/src/language-handlebars/utils.js b/src/language-handlebars/utils.js index 04e846d2be02..70a0e55842bf 100644 --- a/src/language-handlebars/utils.js +++ b/src/language-handlebars/utils.js @@ -1,5 +1,6 @@ "use strict"; +const { htmlVoidElements } = require("../../vendors/html-void-elements.json"); const getLast = require("../utils/get-last.js"); function isLastNodeOfSiblings(path) { @@ -36,10 +37,11 @@ function isGlimmerComponent(node) { ); } +const voidTags = new Set(htmlVoidElements); function isVoid(node) { return ( node.selfClosing === true || - (isGlimmerComponent(node) && + ((voidTags.has(node.tag) || isGlimmerComponent(node)) && node.children.every((node) => isWhitespaceNode(node))) ); } diff --git a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap index 3a289f54b767..f8f84e4a7105 100644 --- a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap @@ -206,7 +206,7 @@ printWidth: 80 =====================================output===================================== - - + + ================================================================================ `; diff --git a/tests/format/handlebars/element-node/jsfmt.spec.js b/tests/format/handlebars/element-node/jsfmt.spec.js index 0210e45899e8..b52fc9c8b9c3 100644 --- a/tests/format/handlebars/element-node/jsfmt.spec.js +++ b/tests/format/handlebars/element-node/jsfmt.spec.js @@ -2,7 +2,7 @@ run_spec( { dirname: __dirname, /* - Missed html void tags in glimmer parser + Missed HTML void tags in glimmer parser https://github.com/glimmerjs/glimmer-vm/blob/ec5648f3895b9ab8d085523be001553746221449/packages/%40glimmer/syntax/lib/parser/tokenizer-event-handlers.ts#LL7C13-L7C13 https://github.com/glimmerjs/glimmer-vm/blob/ec5648f3895b9ab8d085523be001553746221449/packages/%40glimmer/syntax/lib/generation/printer.ts#L8-L9 Please move tags to `tests/format/misc/errors/handlebars/jsfmt.spec.js` diff --git a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap index 5f9ff13aa623..6871f612c998 100644 --- a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap @@ -62,6 +62,30 @@ exports[`snippet: base [glimmer] format 1`] = ` | ^^^^^^^" `; +exports[`snippet: basefont [glimmer] format 1`] = ` +"Unclosed element \`basefont\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^^^^" +`; + +exports[`snippet: bgsound [glimmer] format 1`] = ` +"Unclosed element \`bgsound\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^^^" +`; + exports[`snippet: br [glimmer] format 1`] = ` "
elements do not need end tags. You should remove it: @@ -98,6 +122,18 @@ exports[`snippet: command [glimmer] format 1`] = ` | ^^^^^^^^^^" `; +exports[`snippet: div [glimmer] format 1`] = ` +"Unclosed element \`div\`: + +| +|
+| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 |
+ | ^^^^^" +`; + exports[`snippet: embed [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: @@ -110,6 +146,18 @@ exports[`snippet: embed [glimmer] format 1`] = ` | ^^^^^^^^" `; +exports[`snippet: frame [glimmer] format 1`] = ` +"Unclosed element \`frame\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^" +`; + exports[`snippet: hr [glimmer] format 1`] = ` "
elements do not need end tags. You should remove it: @@ -122,6 +170,18 @@ exports[`snippet: hr [glimmer] format 1`] = ` | ^^^^^" `; +exports[`snippet: image [glimmer] format 1`] = ` +"Unclosed element \`image\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^" +`; + exports[`snippet: img [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: @@ -146,6 +206,18 @@ exports[`snippet: input [glimmer] format 1`] = ` | ^^^^^^^^" `; +exports[`snippet: isindex [glimmer] format 1`] = ` +"Unclosed element \`isindex\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^^^" +`; + exports[`snippet: keygen [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: @@ -170,6 +242,18 @@ exports[`snippet: link [glimmer] format 1`] = ` | ^^^^^^^" `; +exports[`snippet: menuitem [glimmer] format 1`] = ` +"Unclosed element \`menuitem\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^^^^" +`; + exports[`snippet: meta [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: @@ -182,6 +266,18 @@ exports[`snippet: meta [glimmer] format 1`] = ` | ^^^^^^^" `; +exports[`snippet: nextid [glimmer] format 1`] = ` +"Unclosed element \`nextid\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^^" +`; + exports[`snippet: param [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: diff --git a/tests/format/misc/errors/handlebars/jsfmt.spec.js b/tests/format/misc/errors/handlebars/jsfmt.spec.js index 685341867ab0..eb0fcd9e7380 100644 --- a/tests/format/misc/errors/handlebars/jsfmt.spec.js +++ b/tests/format/misc/errors/handlebars/jsfmt.spec.js @@ -2,30 +2,43 @@ run_spec( { dirname: __dirname, snippets: [ - "area", - "base", - // "basefont", - // "bgsound", - "br", - "col", - "command", - "embed", - // "frame", - "hr", - // "image", - "img", - "input", - // "isindex", - "keygen", - "link", - // "menuitem", - "meta", - // "nextid", - "param", - "source", - "track", - "wbr", - ].map((tag) => ({ name: tag, code: `<${tag}>` })), + ...[ + "area", + "base", + // "basefont", + // "bgsound", + "br", + "col", + "command", + "embed", + // "frame", + "hr", + // "image", + "img", + "input", + // "isindex", + "keygen", + "link", + // "menuitem", + "meta", + // "nextid", + "param", + "source", + "track", + "wbr", + ].map((tag) => ({ name: tag, code: `<${tag}>` })), + ...[ + "div", + // Missed HTML void tags + "basefont", + "bgsound", + "frame", + "image", + "isindex", + "menuitem", + "nextid", + ].map((tag) => ({ name: tag, code: `<${tag}>` })), + ], }, ["glimmer"] ); diff --git a/vendors/html-void-elements.json b/vendors/html-void-elements.json new file mode 100644 index 000000000000..f20eebfdfb6b --- /dev/null +++ b/vendors/html-void-elements.json @@ -0,0 +1,27 @@ +{ + "htmlVoidElements": [ + "area", + "base", + "basefont", + "bgsound", + "br", + "col", + "command", + "embed", + "frame", + "hr", + "image", + "img", + "input", + "isindex", + "keygen", + "link", + "menuitem", + "meta", + "nextid", + "param", + "source", + "track", + "wbr" + ] +} diff --git a/yarn.lock b/yarn.lock index 8d9a37121eb7..b2e313328089 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3802,6 +3802,11 @@ html-tag-names@2.0.1: resolved "https://registry.yarnpkg.com/html-tag-names/-/html-tag-names-2.0.1.tgz#5626263e7d7b15789fa35a9f816234156901adc6" integrity sha512-PX8KyLG7dwsjis3NPj1u+/EJf2CgH2d+qzekQpnlCOPQ6Uu6T8+F2ZqQg+wtsP+WKhxK3QMN9Garcwr7fCRhxA== +html-void-elements@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/html-void-elements/-/html-void-elements-2.0.1.tgz#29459b8b05c200b6c5ee98743c41b979d577549f" + integrity sha512-0quDb7s97CfemeJAnW9wC0hw78MtW7NU3hqtCD75g2vFlDLt36llsYD7uB7SUzojLMP24N5IatXf7ylGXiGG9A== + http-proxy-agent@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" From 8899433b84c1d31a1e561af87c9427a6ca7c2598 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 4 Jan 2023 19:55:51 +0800 Subject: [PATCH 5/8] Use tags from glimmer package to avoid checking children --- package.json | 1 - scripts/vendors/vendor-meta.json | 24 ----------------- scripts/vendors/vendors.mjs | 1 - .../html-void-elements.evaluate.js | 7 +++++ src/language-handlebars/utils.js | 5 ++-- vendors/html-void-elements.json | 27 ------------------- yarn.lock | 5 ---- 7 files changed, 10 insertions(+), 60 deletions(-) create mode 100644 src/language-handlebars/html-void-elements.evaluate.js delete mode 100644 vendors/html-void-elements.json diff --git a/package.json b/package.json index 1b770a75e410..b13432e150bd 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "html-element-attributes": "3.1.0", "html-styles": "1.0.0", "html-tag-names": "2.0.1", - "html-void-elements": "2.0.1", "ignore": "5.2.0", "jest-docblock": "28.1.1", "json5": "2.2.2", diff --git a/scripts/vendors/vendor-meta.json b/scripts/vendors/vendor-meta.json index a54ea4607ba1..0f2a7d6f7651 100644 --- a/scripts/vendors/vendor-meta.json +++ b/scripts/vendors/vendor-meta.json @@ -6,7 +6,6 @@ "execa": "execa.js", "html-element-attributes": "html-element-attributes.json", "html-tag-names": "html-tag-names.json", - "html-void-elements": "html-void-elements.json", "leven": "leven.js", "mem": "mem.js", "sdbm": "sdbm.js", @@ -396,29 +395,6 @@ } ] }, - { - "name": "html-void-elements", - "maintainers": [], - "version": "2.0.1", - "description": "List of HTML void tag names", - "repository": "wooorm/html-void-elements", - "homepage": null, - "private": false, - "license": "MIT", - "licenseText": "(The MIT License)\n\nCopyright (c) 2016 Titus Wormer \n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", - "author": { - "name": "Titus Wormer", - "email": "tituswormer@gmail.com", - "url": "https://wooorm.com" - }, - "contributors": [ - { - "name": "Titus Wormer", - "email": "tituswormer@gmail.com", - "url": "https://wooorm.com" - } - ] - }, { "name": "leven", "maintainers": [], diff --git a/scripts/vendors/vendors.mjs b/scripts/vendors/vendors.mjs index 0473e0daa5e3..888fb6345c94 100644 --- a/scripts/vendors/vendors.mjs +++ b/scripts/vendors/vendors.mjs @@ -5,7 +5,6 @@ const vendors = [ "execa", "html-element-attributes", "html-tag-names", - "html-void-elements", "leven", "mem", "sdbm", diff --git a/src/language-handlebars/html-void-elements.evaluate.js b/src/language-handlebars/html-void-elements.evaluate.js new file mode 100644 index 000000000000..f1aae217d9cf --- /dev/null +++ b/src/language-handlebars/html-void-elements.evaluate.js @@ -0,0 +1,7 @@ +"use strict"; + +const { + voidMap, +} = require("@glimmer/syntax/dist/commonjs/es2017/lib/generation/printer.js"); + +module.exports = Object.keys(voidMap); diff --git a/src/language-handlebars/utils.js b/src/language-handlebars/utils.js index 70a0e55842bf..79a59fcca049 100644 --- a/src/language-handlebars/utils.js +++ b/src/language-handlebars/utils.js @@ -1,7 +1,7 @@ "use strict"; -const { htmlVoidElements } = require("../../vendors/html-void-elements.json"); const getLast = require("../utils/get-last.js"); +const htmlVoidElements = require("./html-void-elements.evaluate.js"); function isLastNodeOfSiblings(path) { const node = path.getValue(); @@ -40,8 +40,9 @@ function isGlimmerComponent(node) { const voidTags = new Set(htmlVoidElements); function isVoid(node) { return ( + voidTags.has(node.tag) || node.selfClosing === true || - ((voidTags.has(node.tag) || isGlimmerComponent(node)) && + (isGlimmerComponent(node) && node.children.every((node) => isWhitespaceNode(node))) ); } diff --git a/vendors/html-void-elements.json b/vendors/html-void-elements.json deleted file mode 100644 index f20eebfdfb6b..000000000000 --- a/vendors/html-void-elements.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "htmlVoidElements": [ - "area", - "base", - "basefont", - "bgsound", - "br", - "col", - "command", - "embed", - "frame", - "hr", - "image", - "img", - "input", - "isindex", - "keygen", - "link", - "menuitem", - "meta", - "nextid", - "param", - "source", - "track", - "wbr" - ] -} diff --git a/yarn.lock b/yarn.lock index b2e313328089..8d9a37121eb7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3802,11 +3802,6 @@ html-tag-names@2.0.1: resolved "https://registry.yarnpkg.com/html-tag-names/-/html-tag-names-2.0.1.tgz#5626263e7d7b15789fa35a9f816234156901adc6" integrity sha512-PX8KyLG7dwsjis3NPj1u+/EJf2CgH2d+qzekQpnlCOPQ6Uu6T8+F2ZqQg+wtsP+WKhxK3QMN9Garcwr7fCRhxA== -html-void-elements@2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/html-void-elements/-/html-void-elements-2.0.1.tgz#29459b8b05c200b6c5ee98743c41b979d577549f" - integrity sha512-0quDb7s97CfemeJAnW9wC0hw78MtW7NU3hqtCD75g2vFlDLt36llsYD7uB7SUzojLMP24N5IatXf7ylGXiGG9A== - http-proxy-agent@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" From 1b18d8e89404a7aeb285f253628673e733e087c8 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 4 Jan 2023 20:03:02 +0800 Subject: [PATCH 6/8] Test upper cased tags --- .../__snapshots__/jsfmt.spec.js.snap | 24 +++++++++++++++++++ .../misc/errors/handlebars/jsfmt.spec.js | 3 +++ 2 files changed, 27 insertions(+) diff --git a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap index 6871f612c998..299bbbb812ff 100644 --- a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap @@ -38,6 +38,30 @@ Expecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL' 4 |" `; +exports[`snippet: IMG [glimmer] format 1`] = ` +"Unclosed element \`IMG\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^" +`; + +exports[`snippet: INPUT [glimmer] format 1`] = ` +"Unclosed element \`INPUT\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^^" +`; + exports[`snippet: area [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: diff --git a/tests/format/misc/errors/handlebars/jsfmt.spec.js b/tests/format/misc/errors/handlebars/jsfmt.spec.js index eb0fcd9e7380..0ef53eab33e9 100644 --- a/tests/format/misc/errors/handlebars/jsfmt.spec.js +++ b/tests/format/misc/errors/handlebars/jsfmt.spec.js @@ -37,6 +37,9 @@ run_spec( "isindex", "menuitem", "nextid", + // Upper case + "IMG", + "INPUT", ].map((tag) => ({ name: tag, code: `<${tag}>` })), ], }, From a8d60e76a10437a1641a86c8d0ae33874d9e1ff5 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 5 Jan 2023 10:40:25 +0800 Subject: [PATCH 7/8] Use same logic from glimmer --- src/language-handlebars/utils.js | 7 +++++- .../__snapshots__/jsfmt.spec.js.snap | 24 +++++++++++++++++++ .../misc/errors/handlebars/jsfmt.spec.js | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/language-handlebars/utils.js b/src/language-handlebars/utils.js index 79a59fcca049..10565beb7edc 100644 --- a/src/language-handlebars/utils.js +++ b/src/language-handlebars/utils.js @@ -38,10 +38,15 @@ function isGlimmerComponent(node) { } const voidTags = new Set(htmlVoidElements); +// https://github.com/glimmerjs/glimmer-vm/blob/ec5648f3895b9ab8d085523be001553746221449/packages/%40glimmer/syntax/lib/generation/printer.ts#L44-L46 +function isVoidTag(tag) { + return voidTags.has(tag.toLowerCase()) && !isUppercase(tag[0]); +} + function isVoid(node) { return ( - voidTags.has(node.tag) || node.selfClosing === true || + isVoidTag(node.tag) || (isGlimmerComponent(node) && node.children.every((node) => isWhitespaceNode(node))) ); diff --git a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap index 299bbbb812ff..d712ff17901b 100644 --- a/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/handlebars/__snapshots__/jsfmt.spec.js.snap @@ -194,6 +194,18 @@ exports[`snippet: hr [glimmer] format 1`] = ` | ^^^^^" `; +exports[`snippet: imG [glimmer] format 1`] = ` +"Unclosed element \`imG\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^" +`; + exports[`snippet: image [glimmer] format 1`] = ` "Unclosed element \`image\`: @@ -254,6 +266,18 @@ exports[`snippet: keygen [glimmer] format 1`] = ` | ^^^^^^^^^" `; +exports[`snippet: lINk [glimmer] format 1`] = ` +"Unclosed element \`lINk\`: + +| +| +| + +(error occurred in 'an unknown module' @ line 1 : column 0) (1:0) +> 1 | + | ^^^^^^" +`; + exports[`snippet: link [glimmer] format 1`] = ` " elements do not need end tags. You should remove it: diff --git a/tests/format/misc/errors/handlebars/jsfmt.spec.js b/tests/format/misc/errors/handlebars/jsfmt.spec.js index 0ef53eab33e9..1ec77a7066ff 100644 --- a/tests/format/misc/errors/handlebars/jsfmt.spec.js +++ b/tests/format/misc/errors/handlebars/jsfmt.spec.js @@ -40,6 +40,8 @@ run_spec( // Upper case "IMG", "INPUT", + "imG", + "lINk" ].map((tag) => ({ name: tag, code: `<${tag}>` })), ], }, From d7780a2a29e7d339d0f9fb2f2d4b58629d965ee1 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 5 Jan 2023 10:50:15 +0800 Subject: [PATCH 8/8] linting --- tests/format/misc/errors/handlebars/jsfmt.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/format/misc/errors/handlebars/jsfmt.spec.js b/tests/format/misc/errors/handlebars/jsfmt.spec.js index 1ec77a7066ff..96e9fba026d7 100644 --- a/tests/format/misc/errors/handlebars/jsfmt.spec.js +++ b/tests/format/misc/errors/handlebars/jsfmt.spec.js @@ -41,7 +41,7 @@ run_spec( "IMG", "INPUT", "imG", - "lINk" + "lINk", ].map((tag) => ({ name: tag, code: `<${tag}>` })), ], },