Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vue,ng): do not normalize tag names #5526

Merged
merged 4 commits into from Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/language-html/parser-html.js
Expand Up @@ -7,7 +7,7 @@ const createError = require("../common/parser-create-error");
const { Node } = require("./ast");
const { parseIeConditionalComment } = require("./conditional-comment");

function ngHtmlParser(input, canSelfClose) {
function ngHtmlParser(input, { recognizeSelfClosing, normalizeTagName }) {
const parser = require("angular-html-parser");
const {
RecursiveVisitor,
Expand All @@ -26,7 +26,9 @@ function ngHtmlParser(input, canSelfClose) {
getHtmlTagDefinition
} = require("angular-html-parser/lib/compiler/src/ml_parser/html_tags");

const { rootNodes, errors } = parser.parse(input, { canSelfClose });
const { rootNodes, errors } = parser.parse(input, {
canSelfClose: recognizeSelfClosing
});

if (errors.length !== 0) {
const { msg, span } = errors[0];
Expand Down Expand Up @@ -97,8 +99,9 @@ function ngHtmlParser(input, canSelfClose) {
const normalizeName = node => {
if (node instanceof Element) {
if (
!node.namespace ||
node.namespace === node.tagDefinition.implicitNamespacePrefix
normalizeTagName &&
(!node.namespace ||
node.namespace === node.tagDefinition.implicitNamespacePrefix)
) {
node.name = lowerCaseIfFn(
node.name,
Expand Down Expand Up @@ -161,20 +164,15 @@ function ngHtmlParser(input, canSelfClose) {
return rootNodes;
}

function _parse(
text,
options,
recognizeSelfClosing = false,
shouldParseFrontMatter = true
) {
function _parse(text, options, parserOptions, shouldParseFrontMatter = true) {
const { frontMatter, content } = shouldParseFrontMatter
? parseFrontMatter(text)
: { frontMatter: null, content: text };

const rawAst = {
type: "root",
sourceSpan: { start: { offset: 0 }, end: { offset: text.length } },
children: ngHtmlParser(content, recognizeSelfClosing)
children: ngHtmlParser(content, parserOptions)
};

if (frontMatter) {
Expand All @@ -190,7 +188,7 @@ function _parse(
const subAst = _parse(
fakeContent + realContent,
options,
recognizeSelfClosing,
parserOptions,
false
);
const ParseSourceSpan = subAst.children[0].sourceSpan.constructor;
Expand Down Expand Up @@ -249,11 +247,17 @@ function locEnd(node) {
return node.sourceSpan.end.offset;
}

function createParser({ recognizeSelfClosing }) {
function createParser({
recognizeSelfClosing = false,
normalizeTagName = false
} = {}) {
return {
preprocess: text => text.replace(/\r\n?/g, "\n"),
parse: (text, parsers, options) =>
_parse(text, options, recognizeSelfClosing),
_parse(text, options, {
recognizeSelfClosing,
normalizeTagName
}),
hasPragma,
astFormat: "html",
locStart,
Expand All @@ -263,8 +267,8 @@ function createParser({ recognizeSelfClosing }) {

module.exports = {
parsers: {
html: createParser({ recognizeSelfClosing: false }),
angular: createParser({ recognizeSelfClosing: false }),
html: createParser({ normalizeTagName: true }),
angular: createParser(),
vue: createParser({ recognizeSelfClosing: true })
}
};
28 changes: 28 additions & 0 deletions tests/html_angular/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -10550,3 +10550,31 @@ bindon-ngModel
-->

`;

exports[`tag-name.component.html - angular-verify 1`] = `
<Table></Table>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<Table></Table>

`;

exports[`tag-name.component.html - angular-verify 2`] = `
<Table></Table>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<Table></Table>

`;

exports[`tag-name.component.html - angular-verify 3`] = `
<Table></Table>
~
<Table></Table>

`;

exports[`tag-name.component.html - angular-verify 4`] = `
<Table></Table>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<Table></Table>

`;
1 change: 1 addition & 0 deletions tests/html_angular/tag-name.component.html
@@ -0,0 +1 @@
<Table></Table>
22 changes: 22 additions & 0 deletions tests/html_vue/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -1146,6 +1146,28 @@ exports[`self_closing_style.vue - vue-verify 2`] = `

`;

exports[`tag-name.vue - vue-verify 1`] = `
<template>
<Table></Table>
</template>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<template>
<Table></Table>
</template>

`;

exports[`tag-name.vue - vue-verify 2`] = `
<template>
<Table></Table>
</template>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<template>
<Table></Table>
</template>

`;

exports[`template.vue - vue-verify 1`] = `
<!--copied from https://github.com/gitlabhq/gitlabhq/blob/master/app/assets/javascripts/vue_shared/components/content_viewer/viewers/image_viewer.vue-->
<template>
Expand Down
3 changes: 3 additions & 0 deletions tests/html_vue/tag-name.vue
@@ -0,0 +1,3 @@
<template>
<Table></Table>
</template>