fix(vue,ng): do not normalize tag names (#5526)
parent
b2eadd234b
commit
cdac9552ef
|
@ -7,7 +7,7 @@ const createError = require("../common/parser-create-error");
|
||||||
const { Node } = require("./ast");
|
const { Node } = require("./ast");
|
||||||
const { parseIeConditionalComment } = require("./conditional-comment");
|
const { parseIeConditionalComment } = require("./conditional-comment");
|
||||||
|
|
||||||
function ngHtmlParser(input, canSelfClose) {
|
function ngHtmlParser(input, { recognizeSelfClosing, normalizeTagName }) {
|
||||||
const parser = require("angular-html-parser");
|
const parser = require("angular-html-parser");
|
||||||
const {
|
const {
|
||||||
RecursiveVisitor,
|
RecursiveVisitor,
|
||||||
|
@ -26,7 +26,9 @@ function ngHtmlParser(input, canSelfClose) {
|
||||||
getHtmlTagDefinition
|
getHtmlTagDefinition
|
||||||
} = require("angular-html-parser/lib/compiler/src/ml_parser/html_tags");
|
} = 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) {
|
if (errors.length !== 0) {
|
||||||
const { msg, span } = errors[0];
|
const { msg, span } = errors[0];
|
||||||
|
@ -97,8 +99,9 @@ function ngHtmlParser(input, canSelfClose) {
|
||||||
const normalizeName = node => {
|
const normalizeName = node => {
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element) {
|
||||||
if (
|
if (
|
||||||
!node.namespace ||
|
normalizeTagName &&
|
||||||
node.namespace === node.tagDefinition.implicitNamespacePrefix
|
(!node.namespace ||
|
||||||
|
node.namespace === node.tagDefinition.implicitNamespacePrefix)
|
||||||
) {
|
) {
|
||||||
node.name = lowerCaseIfFn(
|
node.name = lowerCaseIfFn(
|
||||||
node.name,
|
node.name,
|
||||||
|
@ -161,12 +164,7 @@ function ngHtmlParser(input, canSelfClose) {
|
||||||
return rootNodes;
|
return rootNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _parse(
|
function _parse(text, options, parserOptions, shouldParseFrontMatter = true) {
|
||||||
text,
|
|
||||||
options,
|
|
||||||
recognizeSelfClosing = false,
|
|
||||||
shouldParseFrontMatter = true
|
|
||||||
) {
|
|
||||||
const { frontMatter, content } = shouldParseFrontMatter
|
const { frontMatter, content } = shouldParseFrontMatter
|
||||||
? parseFrontMatter(text)
|
? parseFrontMatter(text)
|
||||||
: { frontMatter: null, content: text };
|
: { frontMatter: null, content: text };
|
||||||
|
@ -174,7 +172,7 @@ function _parse(
|
||||||
const rawAst = {
|
const rawAst = {
|
||||||
type: "root",
|
type: "root",
|
||||||
sourceSpan: { start: { offset: 0 }, end: { offset: text.length } },
|
sourceSpan: { start: { offset: 0 }, end: { offset: text.length } },
|
||||||
children: ngHtmlParser(content, recognizeSelfClosing)
|
children: ngHtmlParser(content, parserOptions)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (frontMatter) {
|
if (frontMatter) {
|
||||||
|
@ -190,7 +188,7 @@ function _parse(
|
||||||
const subAst = _parse(
|
const subAst = _parse(
|
||||||
fakeContent + realContent,
|
fakeContent + realContent,
|
||||||
options,
|
options,
|
||||||
recognizeSelfClosing,
|
parserOptions,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
const ParseSourceSpan = subAst.children[0].sourceSpan.constructor;
|
const ParseSourceSpan = subAst.children[0].sourceSpan.constructor;
|
||||||
|
@ -249,11 +247,17 @@ function locEnd(node) {
|
||||||
return node.sourceSpan.end.offset;
|
return node.sourceSpan.end.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createParser({ recognizeSelfClosing }) {
|
function createParser({
|
||||||
|
recognizeSelfClosing = false,
|
||||||
|
normalizeTagName = false
|
||||||
|
} = {}) {
|
||||||
return {
|
return {
|
||||||
preprocess: text => text.replace(/\r\n?/g, "\n"),
|
preprocess: text => text.replace(/\r\n?/g, "\n"),
|
||||||
parse: (text, parsers, options) =>
|
parse: (text, parsers, options) =>
|
||||||
_parse(text, options, recognizeSelfClosing),
|
_parse(text, options, {
|
||||||
|
recognizeSelfClosing,
|
||||||
|
normalizeTagName
|
||||||
|
}),
|
||||||
hasPragma,
|
hasPragma,
|
||||||
astFormat: "html",
|
astFormat: "html",
|
||||||
locStart,
|
locStart,
|
||||||
|
@ -263,8 +267,8 @@ function createParser({ recognizeSelfClosing }) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parsers: {
|
parsers: {
|
||||||
html: createParser({ recognizeSelfClosing: false }),
|
html: createParser({ normalizeTagName: true }),
|
||||||
angular: createParser({ recognizeSelfClosing: false }),
|
angular: createParser(),
|
||||||
vue: createParser({ recognizeSelfClosing: true })
|
vue: createParser({ recognizeSelfClosing: true })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<Table></Table>
|
|
@ -1222,6 +1222,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`] = `
|
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-->
|
<!--copied from https://github.com/gitlabhq/gitlabhq/blob/master/app/assets/javascripts/vue_shared/components/content_viewer/viewers/image_viewer.vue-->
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<template>
|
||||||
|
<Table></Table>
|
||||||
|
</template>
|
Loading…
Reference in New Issue