From 8b0bdf52be1eb4e6062f0a8cfd168abd3fe17536 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Thu, 13 Sep 2018 16:06:49 +0300 Subject: [PATCH] [WIP] feat: html support (#4753) * feat: html support * fix: support empty lines between children * refactor: isScriptTagNode util * refactor: rename `glimmer` and `handlebars` tests * fix don't add newline after `directive` node * fix: support `pre` tag * fix: don't trim comments content * fix: `script` and `style` tags output * feat: indent `head` and `body` inside `html` * fix: better handle quotes around attribute value * feat: better handle embed * tests: svg into html * fix: better handle boolean and empty attributes * chore(deps): update `parse5` to latest version * fix: better handle empty attribute * tests: fix * fix: extra newline in multiline node * fix: print `pre` and `textarea` in right way * tests: xhtml doctype * fix: use `>` instead `/>` * tests: case * refactor: remove `toLowerCase()` * feat: support `prettier-ignore` * tests: empty `script` and `style` tags * fix: clean * tests: refactor and more --- package.json | 3 +- src/language-html/clean.js | 2 +- src/language-html/embed.js | 6 +- src/language-html/parser-parse5.js | 11 +- src/language-html/printer-htmlparser2.js | 364 +++++++++++++--- .../__snapshots__/jsfmt.spec.js.snap | 0 .../block-statement.hbs | 0 tests/{html_glimmer => glimmer}/component.hbs | 0 .../concat-statement.hbs | 0 .../element-modifier-statement.hbs | 0 .../element-node.hbs | 0 tests/{html_glimmer => glimmer}/else-if.hbs | 0 tests/{html_glimmer => glimmer}/jsfmt.spec.js | 0 tests/{html_glimmer => glimmer}/literals.hbs | 0 tests/{html_glimmer => glimmer}/loop.hbs | 0 .../sub-expressions.hbs | 0 .../__snapshots__/jsfmt.spec.js.snap | 0 .../basic-handlebars.hbs | 0 .../comments.hbs | 0 .../{html_handlebars => handlebars}/each.hbs | 0 .../if-else.hbs | 0 tests/{html_handlebars => handlebars}/if.hbs | 0 .../jsfmt.spec.js | 0 .../nested-path.hbs | 0 tests/{html_handlebars => handlebars}/raw.hbs | 0 .../__snapshots__/jsfmt.spec.js.snap | 216 ++++++++++ tests/html_attributes/attributes.html | 60 +++ tests/html_attributes/boolean.html | 17 + tests/html_attributes/dobule-quotes.html | 1 + tests/html_attributes/jsfmt.spec.js | 1 + tests/html_attributes/single-quotes.html | 1 + tests/html_attributes/without-quotes.html | 1 + .../__snapshots__/jsfmt.spec.js.snap | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 400 ++++++++++++++--- tests/html_basics/empty-doc.html | 5 + tests/html_basics/empty.html | 0 tests/html_basics/form.html | 68 +++ tests/html_basics/html5-boilerplate.html | 40 ++ tests/html_basics/more-html.html | 1 + .../__snapshots__/jsfmt.spec.js.snap | 50 +++ tests/html_case/case.html | 16 + tests/html_case/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 99 +++++ tests/html_comments/conditional.html | 12 + tests/html_comments/for_debugging.html | 18 + tests/html_comments/hidden.html | 13 + tests/html_comments/jsfmt.spec.js | 1 + .../html_css/__snapshots__/jsfmt.spec.js.snap | 170 ++++++++ tests/html_css/empty.html | 1 + tests/html_css/jsfmt.spec.js | 1 + tests/html_css/less.html | 17 + tests/html_css/postcss.html | 7 + tests/html_css/scss.html | 19 + tests/html_css/simple.html | 14 + tests/html_css/single-style.html | 8 + .../__snapshots__/jsfmt.spec.js.snap | 163 +++++++ .../html4.01_frameset.html | 11 + .../html4.01_strict.html | 11 + .../html4.01_transitional.html | 11 + tests/html_doctype_declarations/html5.html | 10 + tests/html_doctype_declarations/jsfmt.spec.js | 1 + tests/html_doctype_declarations/xhtml1.1.html | 22 + .../html_js/__snapshots__/jsfmt.spec.js.snap | 207 +++++++++ tests/html_js/empty.html | 1 + tests/html_js/js.html | 15 + tests/html_js/jsfmt.spec.js | 1 + tests/html_js/simple.html | 16 + tests/html_js/single-script.html | 4 + tests/html_js/typescript.html | 78 ++++ .../__snapshots__/jsfmt.spec.js.snap | 92 ++++ tests/html_prettier_ignore/document.html | 43 ++ tests/html_prettier_ignore/jsfmt.spec.js | 1 + .../html_svg/__snapshots__/jsfmt.spec.js.snap | 35 ++ tests/html_svg/jsfmt.spec.js | 1 + tests/html_svg/svg.html | 11 + .../__snapshots__/jsfmt.spec.js.snap | 12 + tests/html_symbol_entities/jsfmt.spec.js | 1 + .../symbol_entitites.html | 3 + .../__snapshots__/jsfmt.spec.js.snap | 404 ++++++++++++++++++ tests/html_tags/jsfmt.spec.js | 1 + tests/html_tags/pre.html | 78 ++++ tests/html_tags/tags.html | 49 +++ tests/html_tags/textarea.html | 28 ++ tests/html_tags/unsupported.html | 1 + .../__snapshots__/jsfmt.spec.js.snap | 20 +- .../__snapshots__/jsfmt.spec.js.snap | 20 +- .../__snapshots__/jsfmt.spec.js.snap | 20 +- yarn.lock | 16 +- 88 files changed, 2846 insertions(+), 191 deletions(-) rename tests/{html_glimmer => glimmer}/__snapshots__/jsfmt.spec.js.snap (100%) rename tests/{html_glimmer => glimmer}/block-statement.hbs (100%) rename tests/{html_glimmer => glimmer}/component.hbs (100%) rename tests/{html_glimmer => glimmer}/concat-statement.hbs (100%) rename tests/{html_glimmer => glimmer}/element-modifier-statement.hbs (100%) rename tests/{html_glimmer => glimmer}/element-node.hbs (100%) rename tests/{html_glimmer => glimmer}/else-if.hbs (100%) rename tests/{html_glimmer => glimmer}/jsfmt.spec.js (100%) rename tests/{html_glimmer => glimmer}/literals.hbs (100%) rename tests/{html_glimmer => glimmer}/loop.hbs (100%) rename tests/{html_glimmer => glimmer}/sub-expressions.hbs (100%) rename tests/{html_handlebars => handlebars}/__snapshots__/jsfmt.spec.js.snap (100%) rename tests/{html_handlebars => handlebars}/basic-handlebars.hbs (100%) rename tests/{html_handlebars => handlebars}/comments.hbs (100%) rename tests/{html_handlebars => handlebars}/each.hbs (100%) rename tests/{html_handlebars => handlebars}/if-else.hbs (100%) rename tests/{html_handlebars => handlebars}/if.hbs (100%) rename tests/{html_handlebars => handlebars}/jsfmt.spec.js (100%) rename tests/{html_handlebars => handlebars}/nested-path.hbs (100%) rename tests/{html_handlebars => handlebars}/raw.hbs (100%) create mode 100644 tests/html_attributes/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_attributes/attributes.html create mode 100644 tests/html_attributes/boolean.html create mode 100644 tests/html_attributes/dobule-quotes.html create mode 100644 tests/html_attributes/jsfmt.spec.js create mode 100644 tests/html_attributes/single-quotes.html create mode 100644 tests/html_attributes/without-quotes.html create mode 100644 tests/html_basics/empty-doc.html create mode 100644 tests/html_basics/empty.html create mode 100644 tests/html_basics/form.html create mode 100644 tests/html_basics/html5-boilerplate.html create mode 100644 tests/html_case/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_case/case.html create mode 100644 tests/html_case/jsfmt.spec.js create mode 100644 tests/html_comments/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_comments/conditional.html create mode 100644 tests/html_comments/for_debugging.html create mode 100644 tests/html_comments/hidden.html create mode 100644 tests/html_comments/jsfmt.spec.js create mode 100644 tests/html_css/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_css/empty.html create mode 100644 tests/html_css/jsfmt.spec.js create mode 100644 tests/html_css/less.html create mode 100644 tests/html_css/postcss.html create mode 100644 tests/html_css/scss.html create mode 100644 tests/html_css/simple.html create mode 100644 tests/html_css/single-style.html create mode 100644 tests/html_doctype_declarations/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_doctype_declarations/html4.01_frameset.html create mode 100644 tests/html_doctype_declarations/html4.01_strict.html create mode 100644 tests/html_doctype_declarations/html4.01_transitional.html create mode 100644 tests/html_doctype_declarations/html5.html create mode 100644 tests/html_doctype_declarations/jsfmt.spec.js create mode 100644 tests/html_doctype_declarations/xhtml1.1.html create mode 100644 tests/html_js/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_js/empty.html create mode 100644 tests/html_js/js.html create mode 100644 tests/html_js/jsfmt.spec.js create mode 100644 tests/html_js/simple.html create mode 100644 tests/html_js/single-script.html create mode 100644 tests/html_js/typescript.html create mode 100644 tests/html_prettier_ignore/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_prettier_ignore/document.html create mode 100644 tests/html_prettier_ignore/jsfmt.spec.js create mode 100644 tests/html_svg/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_svg/jsfmt.spec.js create mode 100644 tests/html_svg/svg.html create mode 100644 tests/html_symbol_entities/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_symbol_entities/jsfmt.spec.js create mode 100644 tests/html_symbol_entities/symbol_entitites.html create mode 100644 tests/html_tags/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/html_tags/jsfmt.spec.js create mode 100644 tests/html_tags/pre.html create mode 100644 tests/html_tags/tags.html create mode 100644 tests/html_tags/textarea.html create mode 100644 tests/html_tags/unsupported.html diff --git a/package.json b/package.json index d4b22c38a..48cab48f4 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "minimatch": "3.0.4", "minimist": "1.2.0", "normalize-path": "3.0.0", - "parse5": "3.0.3", + "parse5": "5.0.0", + "parse5-htmlparser2-tree-adapter": "5.0.0", "postcss-less": "1.1.5", "postcss-media-query-parser": "0.2.3", "postcss-scss": "1.0.6", diff --git a/src/language-html/clean.js b/src/language-html/clean.js index 0103c35cf..40b35e249 100644 --- a/src/language-html/clean.js +++ b/src/language-html/clean.js @@ -1,7 +1,7 @@ "use strict"; module.exports = function(ast, newNode) { - delete newNode.__location; + delete newNode.sourceCodeLocation; if (ast.type === "text") { return null; diff --git a/src/language-html/embed.js b/src/language-html/embed.js index 7b8a14125..44e16ec66 100644 --- a/src/language-html/embed.js +++ b/src/language-html/embed.js @@ -21,7 +21,7 @@ function embed(path, print, textToDoc, options) { ) { const parser = options.parser === "flow" ? "flow" : "babylon"; const doc = textToDoc(getText(options, node), { parser }); - return concat([hardline, doc]); + return concat([hardline, stripTrailingHardline(doc)]); } // Inline TypeScript @@ -35,7 +35,7 @@ function embed(path, print, textToDoc, options) { { parser: "typescript" }, options ); - return concat([hardline, doc]); + return concat([hardline, stripTrailingHardline(doc)]); } // Inline Styles @@ -49,7 +49,7 @@ function embed(path, print, textToDoc, options) { case "attribute": { /* - * Vue binding sytax: JS expressions + * Vue binding syntax: JS expressions * :class="{ 'some-key': value }" * v-bind:id="'list-' + id" * v-if="foo && !bar" diff --git a/src/language-html/parser-parse5.js b/src/language-html/parser-parse5.js index 84ab96aa0..a799b9d02 100644 --- a/src/language-html/parser-parse5.js +++ b/src/language-html/parser-parse5.js @@ -3,12 +3,15 @@ function parse(text /*, parsers, opts*/) { // Inline the require to avoid loading all the JS if we don't use it const parse5 = require("parse5"); + const htmlparser2TreeAdapter = require("parse5-htmlparser2-tree-adapter"); + try { const isFragment = !/^\s*<(!doctype|html|head|body|!--)/i.test(text); const ast = (isFragment ? parse5.parseFragment : parse5.parse)(text, { - treeAdapter: parse5.treeAdapters.htmlparser2, - locationInfo: true + treeAdapter: htmlparser2TreeAdapter, + sourceCodeLocationInfo: true }); + return normalize(extendAst(ast)); } catch (error) { throw error; @@ -64,10 +67,10 @@ module.exports = { parse, astFormat: "htmlparser2", locStart(node) { - return node.__location && node.__location.startOffset; + return node.sourceCodeLocation && node.sourceCodeLocation.startOffset; }, locEnd(node) { - return node.__location && node.__location.endOffset; + return node.sourceCodeLocation && node.sourceCodeLocation.endOffset; } } } diff --git a/src/language-html/printer-htmlparser2.js b/src/language-html/printer-htmlparser2.js index 1b40f2d41..21e2a491c 100644 --- a/src/language-html/printer-htmlparser2.js +++ b/src/language-html/printer-htmlparser2.js @@ -2,34 +2,21 @@ const embed = require("./embed"); const clean = require("./clean"); -const { hasNewlineInRange, hasIgnoreComment } = require("../common/util"); +const { getLast, hasIgnoreComment } = require("../common/util"); +const { isNextLineEmpty } = require("../common/util-shared"); const { - concat, - join, - hardline, - line, - softline, - group, - indent -} = require("../doc").builders; - -// http://w3c.github.io/html/single-page.html#void-elements -const voidTags = { - area: true, - base: true, - br: true, - col: true, - embed: true, - hr: true, - img: true, - input: true, - link: true, - meta: true, - param: true, - source: true, - track: true, - wbr: true -}; + builders: { + concat, + line, + hardline, + softline, + group, + indent, + conditionalGroup, + dedentToRoot + }, + utils: { willBreak, isLineNext, isEmpty } +} = require("../doc"); function genericPrint(path, options, print) { const n = path.getValue(); @@ -43,50 +30,170 @@ function genericPrint(path, options, print) { switch (n.type) { case "root": { - return printChildren(path, print); + return concat(printChildren(path, print, options)); } case "directive": { - return concat(["<", n.data, ">", hardline]); + return concat([ + "<", + n.data.replace('!DOCTYPE html ""', "!DOCTYPE html"), + ">", + hardline + ]); } case "text": { + const parentNode = path.getParentNode(); + + if ( + parentNode && + (isPreTagNode(parentNode) || isTextAreaTagNode(parentNode)) + ) { + return n.data; + } + return n.data.replace(/\s+/g, " ").trim(); } case "script": case "style": case "tag": { - const selfClose = voidTags[n.name] ? ">" : " />"; - const children = printChildren(path, print); + const isVoid = isVoidTagNode(n); + const openingPrinted = printOpeningPart(path, print); - const hasNewline = hasNewlineInRange( - options.originalText, - options.locStart(n), - options.locEnd(n) - ); + // Print self closing tag + if (isVoid) { + return concat([openingPrinted]); + } - return group( + const closingPrinted = printClosingPart(path, print); + const hasChildren = n.children.length > 0; + + // Print tags without children + if (!hasChildren) { + return concat([openingPrinted, closingPrinted]); + } + + const children = printChildren(path, print, options); + + // NOTE: If the next token is a U+000A LINE FEED (LF) character token, then ignore that token and move + // on to the next one. (Newlines at the start of textarea elements are ignored as an authoring convenience.) + if (isPreTagNode(n) || isTextAreaTagNode(n)) { + const originalTagContent = options.originalText.slice( + n.sourceCodeLocation.startTag.endOffset, + n.sourceCodeLocation.endTag.startOffset + ); + const hasNewlineAfterTag = /^(\r\n|\r|\n)/.test(originalTagContent); + + return dedentToRoot( + group( + concat([ + openingPrinted, + hasNewlineAfterTag ? hardline : "", + concat(children), + closingPrinted + ]) + ) + ); + } + + const isScriptTag = isScriptTagNode(n); + + if (isScriptTag) { + return group( + concat([openingPrinted, concat(children), closingPrinted]) + ); + } + + const containsTag = + n.children.filter( + node => ["script", "style", "tag"].indexOf(node.type) !== -1 + ).length > 0; + const containsMultipleAttributes = n.attributes.length > 1; + + let forcedBreak = + willBreak(openingPrinted) || containsTag || containsMultipleAttributes; + + // Trim trailing lines (or empty strings) + while ( + children.length && + (isLineNext(getLast(children)) || isEmpty(getLast(children))) + ) { + children.pop(); + } + + // Trim leading lines (or empty strings) + while ( + children.length && + (isLineNext(children[0]) || isEmpty(children[0])) && + (isLineNext(children[1]) || isEmpty(children[1])) + ) { + children.shift(); + children.shift(); + } + + // Detect whether we will force this element to output over multiple lines. + const multilineChildren = []; + + children.forEach(child => { + multilineChildren.push(child); + + if (willBreak(child)) { + forcedBreak = true; + } + }); + + const containsOnlyEmptyTextNodes = n.children.every(node => { + return node.type === "text" && /^\s+$/.test(node.data); + }); + + const printedMultilineChildren = concat([ + !isScriptTag && !containsOnlyEmptyTextNodes ? hardline : "", + group(concat(multilineChildren), { shouldBreak: true }) + ]); + + const multiLineElem = group( concat([ - hasNewline ? hardline : "", - "<", - n.name, - printAttributes(path, print), - - n.children.length ? ">" : selfClose, - - n.name.toLowerCase() === "html" - ? concat([hardline, children]) - : indent(children), - n.children.length ? concat([softline, ""]) : hardline + openingPrinted, + indent(printedMultilineChildren), + hardline, + closingPrinted ]) ); + + if (forcedBreak) { + return multiLineElem; + } + + return conditionalGroup([ + group(concat([openingPrinted, concat(children), closingPrinted])), + multiLineElem + ]); } case "comment": { - return concat([""]); + return concat([""]); } case "attribute": { if (!n.value) { - return n.key; + if (isBooleanAttributeNode(n)) { + return n.key; + } + + const parentNode = path.getParentNode(); + + if (!parentNode || !parentNode.sourceCodeLocation) { + return n.key; + } + + const attributeSourceCodeLocation = + parentNode.sourceCodeLocation.attrs[n.key]; + const originalAttributeSourceCode = options.originalText.slice( + attributeSourceCodeLocation.startOffset, + attributeSourceCodeLocation.endOffset + ); + const hasEqualSign = originalAttributeSourceCode.indexOf("=") !== -1; + + return hasEqualSign ? concat([n.key, '=""']) : n.key; } - return concat([n.key, '="', n.value, '"']); + + return concat([n.key, '="', n.value.replace(/"/g, """), '"']); } default: @@ -95,25 +202,152 @@ function genericPrint(path, options, print) { } } -function printAttributes(path, print) { - const node = path.getValue(); - - return concat([ - node.attributes.length ? " " : "", - indent(join(line, path.map(print, "attributes"))) - ]); +function isBooleanAttributeNode(node) { + return ( + node.type === "attribute" && + [ + "allowfullscreen", + "allowpaymentrequest", + "async", + "autofocus", + "autoplay", + "checked", + "controls", + "default", + "defer", + "disabled", + "formnovalidate", + "hidden", + "ismap", + "itemscope", + "loop", + "multiple", + "muted", + "nomodule", + "novalidate", + "open", + "readonly", + "required", + "reversed", + "selected", + "typemustmatch" + ].indexOf(node.key) !== -1 + ); } -function printChildren(path, print) { - const children = []; - path.each(childPath => { +// http://w3c.github.io/html/single-page.html#void-elements +function isVoidTagNode(node) { + return ( + node.type === "tag" && + [ + "area", + "base", + "br", + "col", + "embed", + "hr", + "img", + "input", + "link", + "meta", + "param", + "source", + "track", + "wbr" + ].indexOf(node.name) !== -1 + ); +} + +function isPreTagNode(node) { + return node.type === "tag" && node.name === "pre"; +} + +function isTextAreaTagNode(node) { + return node.type === "tag" && node.name === "textarea"; +} + +function isScriptTagNode(node) { + return ( + (node.type === "script" || node.type === "style") && + ["script", "style"].indexOf(node.name) !== -1 + ); +} + +function printOpeningPart(path, print) { + const n = path.getValue(); + const isVoid = isVoidTagNode(n); + + // Don't break self-closing elements with no attributes + if (isVoid && !n.attributes.length) { + return concat(["<", n.name, ">"]); + } + + // Don't break up opening elements with a single long text attribute + if (n.attributes && n.attributes.length === 1 && n.attributes[0].value) { + return group( + concat([ + "<", + path.call(print, "name"), + " ", + concat(path.map(print, "attributes")), + ">" + ]) + ); + } + + return group( + concat([ + "<", + n.name, + concat([ + indent( + concat(path.map(attr => concat([line, print(attr)]), "attributes")) + ), + softline + ]), + ">" + ]) + ); +} + +function printClosingPart(path, print) { + return concat([""]); +} + +function printChildren(path, print, options) { + const parts = []; + + path.map((childPath, i) => { + const parentNode = childPath.getParentNode(); const child = childPath.getValue(); - if (child.type !== "text") { - children.push(hardline); + const printedChild = print(childPath); + + if ( + parentNode && + parentNode.children[i - 2] && + parentNode.children[i - 2].type === "comment" && + parentNode.children[i - 2].data.trim() === "prettier-ignore" + ) { + parts.push( + options.originalText.slice( + options.locStart(child), + options.locEnd(child) + ) + ); + } else { + parts.push(printedChild); + } + + if (child.type !== "text" && child.type !== "directive") { + parts.push(hardline); + } + + if (isNextLineEmpty(options.originalText, childPath.getValue(), options)) { + parts.push(hardline); } - children.push(childPath.call(print)); }, "children"); - return concat(children); + + return parts; } module.exports = { diff --git a/tests/html_glimmer/__snapshots__/jsfmt.spec.js.snap b/tests/glimmer/__snapshots__/jsfmt.spec.js.snap similarity index 100% rename from tests/html_glimmer/__snapshots__/jsfmt.spec.js.snap rename to tests/glimmer/__snapshots__/jsfmt.spec.js.snap diff --git a/tests/html_glimmer/block-statement.hbs b/tests/glimmer/block-statement.hbs similarity index 100% rename from tests/html_glimmer/block-statement.hbs rename to tests/glimmer/block-statement.hbs diff --git a/tests/html_glimmer/component.hbs b/tests/glimmer/component.hbs similarity index 100% rename from tests/html_glimmer/component.hbs rename to tests/glimmer/component.hbs diff --git a/tests/html_glimmer/concat-statement.hbs b/tests/glimmer/concat-statement.hbs similarity index 100% rename from tests/html_glimmer/concat-statement.hbs rename to tests/glimmer/concat-statement.hbs diff --git a/tests/html_glimmer/element-modifier-statement.hbs b/tests/glimmer/element-modifier-statement.hbs similarity index 100% rename from tests/html_glimmer/element-modifier-statement.hbs rename to tests/glimmer/element-modifier-statement.hbs diff --git a/tests/html_glimmer/element-node.hbs b/tests/glimmer/element-node.hbs similarity index 100% rename from tests/html_glimmer/element-node.hbs rename to tests/glimmer/element-node.hbs diff --git a/tests/html_glimmer/else-if.hbs b/tests/glimmer/else-if.hbs similarity index 100% rename from tests/html_glimmer/else-if.hbs rename to tests/glimmer/else-if.hbs diff --git a/tests/html_glimmer/jsfmt.spec.js b/tests/glimmer/jsfmt.spec.js similarity index 100% rename from tests/html_glimmer/jsfmt.spec.js rename to tests/glimmer/jsfmt.spec.js diff --git a/tests/html_glimmer/literals.hbs b/tests/glimmer/literals.hbs similarity index 100% rename from tests/html_glimmer/literals.hbs rename to tests/glimmer/literals.hbs diff --git a/tests/html_glimmer/loop.hbs b/tests/glimmer/loop.hbs similarity index 100% rename from tests/html_glimmer/loop.hbs rename to tests/glimmer/loop.hbs diff --git a/tests/html_glimmer/sub-expressions.hbs b/tests/glimmer/sub-expressions.hbs similarity index 100% rename from tests/html_glimmer/sub-expressions.hbs rename to tests/glimmer/sub-expressions.hbs diff --git a/tests/html_handlebars/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars/__snapshots__/jsfmt.spec.js.snap similarity index 100% rename from tests/html_handlebars/__snapshots__/jsfmt.spec.js.snap rename to tests/handlebars/__snapshots__/jsfmt.spec.js.snap diff --git a/tests/html_handlebars/basic-handlebars.hbs b/tests/handlebars/basic-handlebars.hbs similarity index 100% rename from tests/html_handlebars/basic-handlebars.hbs rename to tests/handlebars/basic-handlebars.hbs diff --git a/tests/html_handlebars/comments.hbs b/tests/handlebars/comments.hbs similarity index 100% rename from tests/html_handlebars/comments.hbs rename to tests/handlebars/comments.hbs diff --git a/tests/html_handlebars/each.hbs b/tests/handlebars/each.hbs similarity index 100% rename from tests/html_handlebars/each.hbs rename to tests/handlebars/each.hbs diff --git a/tests/html_handlebars/if-else.hbs b/tests/handlebars/if-else.hbs similarity index 100% rename from tests/html_handlebars/if-else.hbs rename to tests/handlebars/if-else.hbs diff --git a/tests/html_handlebars/if.hbs b/tests/handlebars/if.hbs similarity index 100% rename from tests/html_handlebars/if.hbs rename to tests/handlebars/if.hbs diff --git a/tests/html_handlebars/jsfmt.spec.js b/tests/handlebars/jsfmt.spec.js similarity index 100% rename from tests/html_handlebars/jsfmt.spec.js rename to tests/handlebars/jsfmt.spec.js diff --git a/tests/html_handlebars/nested-path.hbs b/tests/handlebars/nested-path.hbs similarity index 100% rename from tests/html_handlebars/nested-path.hbs rename to tests/handlebars/nested-path.hbs diff --git a/tests/html_handlebars/raw.hbs b/tests/handlebars/raw.hbs similarity index 100% rename from tests/html_handlebars/raw.hbs rename to tests/handlebars/raw.hbs diff --git a/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap b/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..030640caf --- /dev/null +++ b/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,216 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`attributes.html - parse5-verify 1`] = ` + + + +
+
+
+ + +
+
+ +
String
+
String
+
String
+
String
+
String
+
String
+
String
+
String
+
String
+
+
String
+
String
+
String
+
+
+
...
+
+ ... +
+
+ +
+
+ + + +
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + +
+
+
+ + +
+
+ +
String
+
String
+
String
+
String
+
String
+
String
+
String
+
String
+
String
+
+
String
+
String
+
String
+
+
+
+ ... +
+
+ ... +
+
+
+
+
+ +`; + +exports[`boolean.html - parse5-verify 1`] = ` + + + + + + + + + + + + + + + + +
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + + + + + + + + + + + + + +
+ +`; + +exports[`dobule-quotes.html - parse5-verify 1`] = ` +John 'ShotGun' Nelson +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +John 'ShotGun' Nelson + +`; + +exports[`single-quotes.html - parse5-verify 1`] = ` +John "ShotGun" Nelson +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +John "ShotGun" Nelson + +`; + +exports[`without-quotes.html - parse5-verify 1`] = ` +

String

+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +

String

+ +`; diff --git a/tests/html_attributes/attributes.html b/tests/html_attributes/attributes.html new file mode 100644 index 000000000..a1950c3f8 --- /dev/null +++ b/tests/html_attributes/attributes.html @@ -0,0 +1,60 @@ + + + +
+
+
+ + +
+
+ +
String
+
String
+
String
+
String
+
String
+
String
+
String
+
String
+
String
+
+
String
+
String
+
String
+
+
+
...
+
+ ... +
+
+ +
+
+ + + +
diff --git a/tests/html_attributes/boolean.html b/tests/html_attributes/boolean.html new file mode 100644 index 000000000..9d6ae14d7 --- /dev/null +++ b/tests/html_attributes/boolean.html @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + +
diff --git a/tests/html_attributes/dobule-quotes.html b/tests/html_attributes/dobule-quotes.html new file mode 100644 index 000000000..aab2364d8 --- /dev/null +++ b/tests/html_attributes/dobule-quotes.html @@ -0,0 +1 @@ +John 'ShotGun' Nelson diff --git a/tests/html_attributes/jsfmt.spec.js b/tests/html_attributes/jsfmt.spec.js new file mode 100644 index 000000000..3ebd9a9e3 --- /dev/null +++ b/tests/html_attributes/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["parse5"]); diff --git a/tests/html_attributes/single-quotes.html b/tests/html_attributes/single-quotes.html new file mode 100644 index 000000000..8a360f103 --- /dev/null +++ b/tests/html_attributes/single-quotes.html @@ -0,0 +1 @@ +John "ShotGun" Nelson diff --git a/tests/html_attributes/without-quotes.html b/tests/html_attributes/without-quotes.html new file mode 100644 index 000000000..845e140d4 --- /dev/null +++ b/tests/html_attributes/without-quotes.html @@ -0,0 +1 @@ +

String

diff --git a/tests/html_aurelia/__snapshots__/jsfmt.spec.js.snap b/tests/html_aurelia/__snapshots__/jsfmt.spec.js.snap index 97f98b63c..c54c58dcd 100644 --- a/tests/html_aurelia/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_aurelia/__snapshots__/jsfmt.spec.js.snap @@ -5,11 +5,9 @@ exports[`basic.html - parse5-verify 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - + `; diff --git a/tests/html_basics/__snapshots__/jsfmt.spec.js.snap b/tests/html_basics/__snapshots__/jsfmt.spec.js.snap index 6f40c76e5..4c0f88b5a 100644 --- a/tests/html_basics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_basics/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,208 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`empty.html - parse5-verify 1`] = ` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +`; + +exports[`empty-doc.html - parse5-verify 1`] = ` + + + + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + + + + +`; + +exports[`form.html - parse5-verify 1`] = ` +
+
+ + + We'll never share your email with anyone else. +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line. +
+
+ Radio buttons +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
+
+ + + + We'll never share your email with anyone else. + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line. + +
+
+ Radio buttons +
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+ +`; + exports[`hello-world.html - parse5-verify 1`] = ` @@ -16,30 +219,20 @@ exports[`hello-world.html - parse5-verify 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - - - - - - - - Document - - - - -

Hello World

- + + + + + Document + + + +

Hello World

+ + `; exports[`html-comments.html - parse5-verify 1`] = ` @@ -51,22 +244,15 @@ exports[`html-comments.html - parse5-verify 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - - - Anchor -