From 58639a0aa214ec930d07dada0afc1d1449c52a9e Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 4 May 2023 08:28:26 +0800 Subject: [PATCH] fix: jsx name could be namespace or member expression (#460) --- .changeset/eight-emus-lay.md | 5 + packages/eslint-mdx/src/worker.ts | 84 +- test/__snapshots__/fixtures.test.ts.snap | 16 + test/__snapshots__/parser.test.ts.snap | 1798 ++++++++++++++++++++++ test/fixtures/445.mdx | 9 + 5 files changed, 1894 insertions(+), 18 deletions(-) create mode 100644 .changeset/eight-emus-lay.md create mode 100644 test/fixtures/445.mdx diff --git a/.changeset/eight-emus-lay.md b/.changeset/eight-emus-lay.md new file mode 100644 index 00000000..a7e2ac78 --- /dev/null +++ b/.changeset/eight-emus-lay.md @@ -0,0 +1,5 @@ +--- +"eslint-mdx": patch +--- + +fix: jsx name could be namespace or member expression diff --git a/packages/eslint-mdx/src/worker.ts b/packages/eslint-mdx/src/worker.ts index 4417e823..4608728a 100644 --- a/packages/eslint-mdx/src/worker.ts +++ b/packages/eslint-mdx/src/worker.ts @@ -15,7 +15,14 @@ import type { Program, SpreadElement, } from 'estree' -import type { JSXClosingElement, JSXElement, JSXFragment } from 'estree-jsx' +import type { + JSXClosingElement, + JSXElement, + JSXFragment, + JSXIdentifier, + JSXMemberExpression, + JSXNamespacedName, +} from 'estree-jsx' import type { BlockContent, PhrasingContent, @@ -289,6 +296,58 @@ runAsWorker( raw: text.slice(start, end), }) + const handleJsxName = ( + nodeName: string, + start: number, + ): JSXIdentifier | JSXMemberExpression | JSXNamespacedName => { + const name = nodeName.trim() + const nameIndex = nodeName.indexOf(name) + + const colonIndex = nodeName.indexOf(':') + if (colonIndex !== -1) { + const [fullNamespace, fullName] = nodeName.split(':') + return { + ...normalizeNode( + start + nameIndex, + start + nameIndex + name.length, + ), + type: 'JSXNamespacedName', + namespace: handleJsxName(fullNamespace, start) as JSXIdentifier, + name: handleJsxName( + fullName, + start + colonIndex + 1, + ) as JSXIdentifier, + } + } + + const lastPointIndex = nodeName.lastIndexOf('.') + if (lastPointIndex === -1) { + return { + ...normalizeNode( + start + nameIndex, + start + nameIndex + name.length, + ), + type: 'JSXIdentifier', + name, + } + } + + const objectName = nodeName.slice(0, lastPointIndex) + const propertyName = nodeName.slice(lastPointIndex + 1) + + return { + ...normalizeNode(start + nameIndex, start + nameIndex + name.length), + type: 'JSXMemberExpression', + object: handleJsxName(objectName, start) as + | JSXIdentifier + | JSXMemberExpression, + property: handleJsxName( + propertyName, + start + lastPointIndex + 1, + ) as JSXIdentifier, + } + } + visit(root, node => { if ( processed.has(node) || @@ -374,20 +433,16 @@ runAsWorker( if (!selfClosing) { const prevOffset = prevCharOffset(lastCharOffset) const slashOffset = prevCharOffset(prevOffset - nodeNameLength) - assert(text[slashOffset] === '/') + assert( + text[slashOffset] === '/', + `expect \`${text[slashOffset]}\` to be \`/\`, the node is ${node.name}`, + ) const tagStartOffset = prevCharOffset(slashOffset - 1) assert(text[tagStartOffset] === '<') closingElement = { ...normalizeNode(tagStartOffset, nodeEnd), type: 'JSXClosingElement', - name: { - ...normalizeNode( - prevOffset + 1 - nodeNameLength, - prevOffset + 1, - ), - type: 'JSXIdentifier', - name: node.name, - }, + name: handleJsxName(node.name, prevOffset + 1 - nodeNameLength), } } @@ -396,14 +451,7 @@ runAsWorker( type: 'JSXElement', openingElement: { type: 'JSXOpeningElement', - name: { - ...normalizeNode( - nodeNameStart, - nodeNameStart + nodeNameLength, - ), - type: 'JSXIdentifier', - name: node.name, - }, + name: handleJsxName(node.name, nodeNameStart), attributes: node.attributes.map(attr => { if (attr.type === 'mdxJsxExpressionAttribute') { assert(attr.data) diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 906a2b2b..2f511a81 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -430,6 +430,22 @@ exports[`fixtures should match all snapshots: 429.mdx 1`] = ` ] `; +exports[`fixtures should match all snapshots: 445.mdx 1`] = ` +[ + { + "column": 2, + "endColumn": 3, + "endLine": 9, + "line": 9, + "message": "'A' is not defined.", + "messageId": "undefined", + "nodeType": "JSXIdentifier", + "ruleId": "react/jsx-no-undef", + "severity": 2, + }, +] +`; + exports[`fixtures should match all snapshots: 450.mdx 1`] = ` [ { diff --git a/test/__snapshots__/parser.test.ts.snap b/test/__snapshots__/parser.test.ts.snap index 8445d23a..f619c1f5 100644 --- a/test/__snapshots__/parser.test.ts.snap +++ b/test/__snapshots__/parser.test.ts.snap @@ -30627,6 +30627,1804 @@ exports[`parser should match all AST snapshots: 429.mdx 1`] = ` } `; +exports[`parser should match all AST snapshots: 445.mdx 1`] = ` +{ + "body": [ + { + "end": 49, + "loc": { + "end": { + "column": 49, + "line": 1, + "offset": 49, + }, + "start": { + "column": 0, + "line": 1, + "offset": 0, + }, + }, + "range": [ + 0, + 49, + ], + "source": { + "end": 49, + "loc": { + "end": { + "column": 49, + "line": 1, + "offset": 49, + }, + "start": { + "column": 31, + "line": 1, + "offset": 31, + }, + }, + "range": [ + 31, + 49, + ], + "raw": "'./DefinitionList'", + "start": 31, + "type": "Literal", + "value": "./DefinitionList", + }, + "specifiers": [ + { + "end": 23, + "imported": { + "end": 23, + "loc": { + "end": { + "column": 23, + "line": 1, + "offset": 23, + }, + "start": { + "column": 9, + "line": 1, + "offset": 9, + }, + }, + "name": "DefinitionList", + "range": [ + 9, + 23, + ], + "start": 9, + "type": "Identifier", + }, + "loc": { + "end": { + "column": 23, + "line": 1, + "offset": 23, + }, + "start": { + "column": 9, + "line": 1, + "offset": 9, + }, + }, + "local": { + "end": 23, + "loc": { + "end": { + "column": 23, + "line": 1, + "offset": 23, + }, + "start": { + "column": 9, + "line": 1, + "offset": 9, + }, + }, + "name": "DefinitionList", + "range": [ + 9, + 23, + ], + "start": 9, + "type": "Identifier", + }, + "range": [ + 9, + 23, + ], + "start": 9, + "type": "ImportSpecifier", + }, + ], + "start": 0, + "type": "ImportDeclaration", + }, + { + "end": 155, + "expression": { + "children": [], + "closingElement": { + "end": 155, + "loc": { + "end": { + "column": 17, + "line": 5, + "offset": 155, + }, + "start": { + "column": 0, + "line": 5, + "offset": 138, + }, + }, + "name": { + "end": 154, + "loc": { + "end": { + "column": 16, + "line": 5, + "offset": 154, + }, + "start": { + "column": 2, + "line": 5, + "offset": 140, + }, + }, + "name": "DefinitionList", + "range": [ + 140, + 154, + ], + "raw": "DefinitionList", + "start": 140, + "type": "JSXIdentifier", + }, + "range": [ + 138, + 155, + ], + "raw": "", + "start": 138, + "type": "JSXClosingElement", + }, + "end": 155, + "loc": { + "end": { + "column": 17, + "line": 5, + "offset": 155, + }, + "start": { + "column": 0, + "line": 3, + "offset": 51, + }, + }, + "openingElement": { + "attributes": [ + { + "end": 75, + "loc": { + "end": { + "column": 24, + "line": 3, + "offset": 75, + }, + "start": { + "column": 16, + "line": 3, + "offset": 67, + }, + }, + "name": { + "end": 75, + "loc": { + "end": { + "column": 24, + "line": 3, + "offset": 75, + }, + "start": { + "column": 16, + "line": 3, + "offset": 67, + }, + }, + "name": "disabled", + "range": [ + 67, + 75, + ], + "raw": "disabled", + "start": 67, + "type": "JSXIdentifier", + }, + "range": [ + 67, + 75, + ], + "raw": "disabled", + "start": 67, + "type": "JSXAttribute", + "value": null, + }, + ], + "end": 76, + "loc": { + "end": { + "column": 25, + "line": 3, + "offset": 76, + }, + "start": { + "column": 0, + "line": 3, + "offset": 51, + }, + }, + "name": { + "end": 66, + "loc": { + "end": { + "column": 15, + "line": 3, + "offset": 66, + }, + "start": { + "column": 1, + "line": 3, + "offset": 52, + }, + }, + "name": "DefinitionList", + "range": [ + 52, + 66, + ], + "raw": "DefinitionList", + "start": 52, + "type": "JSXIdentifier", + }, + "range": [ + 51, + 76, + ], + "raw": "", + "selfClosing": false, + "start": 51, + "type": "JSXOpeningElement", + }, + "range": [ + 51, + 155, + ], + "raw": " + Hello World ! +", + "start": 51, + "type": "JSXElement", + }, + "loc": { + "end": { + "column": 18, + "line": 5, + "offset": 155, + }, + "start": { + "column": 1, + "line": 3, + "offset": 51, + }, + }, + "range": [ + 51, + 155, + ], + "start": 51, + "type": "ExpressionStatement", + }, + { + "end": 137, + "expression": { + "children": [], + "closingElement": { + "end": 137, + "loc": { + "end": { + "column": 60, + "line": 4, + "offset": 137, + }, + "start": { + "column": 37, + "line": 4, + "offset": 114, + }, + }, + "name": { + "end": 136, + "loc": { + "end": { + "column": 59, + "line": 4, + "offset": 136, + }, + "start": { + "column": 39, + "line": 4, + "offset": 116, + }, + }, + "object": { + "end": 130, + "loc": { + "end": { + "column": 53, + "line": 4, + "offset": 130, + }, + "start": { + "column": 39, + "line": 4, + "offset": 116, + }, + }, + "name": "DefinitionList", + "range": [ + 116, + 130, + ], + "raw": "DefinitionList", + "start": 116, + "type": "JSXIdentifier", + }, + "property": { + "end": 136, + "loc": { + "end": { + "column": 59, + "line": 4, + "offset": 136, + }, + "start": { + "column": 54, + "line": 4, + "offset": 131, + }, + }, + "name": "Title", + "range": [ + 131, + 136, + ], + "raw": "Title", + "start": 131, + "type": "JSXIdentifier", + }, + "range": [ + 116, + 136, + ], + "raw": "DefinitionList.Title", + "start": 116, + "type": "JSXMemberExpression", + }, + "range": [ + 114, + 137, + ], + "raw": "", + "start": 114, + "type": "JSXClosingElement", + }, + "end": 137, + "loc": { + "end": { + "column": 60, + "line": 4, + "offset": 137, + }, + "start": { + "column": 2, + "line": 4, + "offset": 79, + }, + }, + "openingElement": { + "attributes": [], + "end": 101, + "loc": { + "end": { + "column": 24, + "line": 4, + "offset": 101, + }, + "start": { + "column": 2, + "line": 4, + "offset": 79, + }, + }, + "name": { + "end": 100, + "loc": { + "end": { + "column": 23, + "line": 4, + "offset": 100, + }, + "start": { + "column": 3, + "line": 4, + "offset": 80, + }, + }, + "object": { + "end": 94, + "loc": { + "end": { + "column": 17, + "line": 4, + "offset": 94, + }, + "start": { + "column": 3, + "line": 4, + "offset": 80, + }, + }, + "name": "DefinitionList", + "range": [ + 80, + 94, + ], + "raw": "DefinitionList", + "start": 80, + "type": "JSXIdentifier", + }, + "property": { + "end": 100, + "loc": { + "end": { + "column": 23, + "line": 4, + "offset": 100, + }, + "start": { + "column": 18, + "line": 4, + "offset": 95, + }, + }, + "name": "Title", + "range": [ + 95, + 100, + ], + "raw": "Title", + "start": 95, + "type": "JSXIdentifier", + }, + "range": [ + 80, + 100, + ], + "raw": "DefinitionList.Title", + "start": 80, + "type": "JSXMemberExpression", + }, + "range": [ + 79, + 101, + ], + "raw": "", + "selfClosing": false, + "start": 79, + "type": "JSXOpeningElement", + }, + "range": [ + 79, + 137, + ], + "raw": "Hello World !", + "start": 79, + "type": "JSXElement", + }, + "loc": { + "end": { + "column": 61, + "line": 4, + "offset": 137, + }, + "start": { + "column": 3, + "line": 4, + "offset": 79, + }, + }, + "range": [ + 79, + 137, + ], + "start": 79, + "type": "ExpressionStatement", + }, + { + "end": 170, + "expression": { + "children": [], + "closingElement": { + "end": 170, + "loc": { + "end": { + "column": 13, + "line": 7, + "offset": 170, + }, + "start": { + "column": 6, + "line": 7, + "offset": 163, + }, + }, + "name": { + "end": 168, + "loc": { + "end": { + "column": 11, + "line": 7, + "offset": 168, + }, + "start": { + "column": 8, + "line": 7, + "offset": 165, + }, + }, + "name": { + "end": 168, + "loc": { + "end": { + "column": 11, + "line": 7, + "offset": 168, + }, + "start": { + "column": 10, + "line": 7, + "offset": 167, + }, + }, + "name": "B", + "range": [ + 167, + 168, + ], + "raw": "B", + "start": 167, + "type": "JSXIdentifier", + }, + "namespace": { + "end": 166, + "loc": { + "end": { + "column": 9, + "line": 7, + "offset": 166, + }, + "start": { + "column": 8, + "line": 7, + "offset": 165, + }, + }, + "name": "A", + "range": [ + 165, + 166, + ], + "raw": "A", + "start": 165, + "type": "JSXIdentifier", + }, + "range": [ + 165, + 168, + ], + "raw": "A:B", + "start": 165, + "type": "JSXNamespacedName", + }, + "range": [ + 163, + 170, + ], + "raw": "", + "start": 163, + "type": "JSXClosingElement", + }, + "end": 170, + "loc": { + "end": { + "column": 13, + "line": 7, + "offset": 170, + }, + "start": { + "column": 0, + "line": 7, + "offset": 157, + }, + }, + "openingElement": { + "attributes": [], + "end": 163, + "loc": { + "end": { + "column": 6, + "line": 7, + "offset": 163, + }, + "start": { + "column": 0, + "line": 7, + "offset": 157, + }, + }, + "name": { + "end": 161, + "loc": { + "end": { + "column": 4, + "line": 7, + "offset": 161, + }, + "start": { + "column": 1, + "line": 7, + "offset": 158, + }, + }, + "name": { + "end": 161, + "loc": { + "end": { + "column": 4, + "line": 7, + "offset": 161, + }, + "start": { + "column": 3, + "line": 7, + "offset": 160, + }, + }, + "name": "B", + "range": [ + 160, + 161, + ], + "raw": "B", + "start": 160, + "type": "JSXIdentifier", + }, + "namespace": { + "end": 159, + "loc": { + "end": { + "column": 2, + "line": 7, + "offset": 159, + }, + "start": { + "column": 1, + "line": 7, + "offset": 158, + }, + }, + "name": "A", + "range": [ + 158, + 159, + ], + "raw": "A", + "start": 158, + "type": "JSXIdentifier", + }, + "range": [ + 158, + 161, + ], + "raw": "A:B", + "start": 158, + "type": "JSXNamespacedName", + }, + "range": [ + 157, + 163, + ], + "raw": "", + "selfClosing": false, + "start": 157, + "type": "JSXOpeningElement", + }, + "range": [ + 157, + 170, + ], + "raw": "", + "start": 157, + "type": "JSXElement", + }, + "loc": { + "end": { + "column": 14, + "line": 7, + "offset": 170, + }, + "start": { + "column": 1, + "line": 7, + "offset": 157, + }, + }, + "range": [ + 157, + 170, + ], + "start": 157, + "type": "ExpressionStatement", + }, + { + "end": 187, + "expression": { + "children": [], + "closingElement": { + "end": 187, + "loc": { + "end": { + "column": 15, + "line": 9, + "offset": 187, + }, + "start": { + "column": 7, + "line": 9, + "offset": 179, + }, + }, + "name": { + "end": 186, + "loc": { + "end": { + "column": 14, + "line": 9, + "offset": 186, + }, + "start": { + "column": 9, + "line": 9, + "offset": 181, + }, + }, + "object": { + "end": 184, + "loc": { + "end": { + "column": 12, + "line": 9, + "offset": 184, + }, + "start": { + "column": 9, + "line": 9, + "offset": 181, + }, + }, + "object": { + "end": 182, + "loc": { + "end": { + "column": 10, + "line": 9, + "offset": 182, + }, + "start": { + "column": 9, + "line": 9, + "offset": 181, + }, + }, + "name": "A", + "range": [ + 181, + 182, + ], + "raw": "A", + "start": 181, + "type": "JSXIdentifier", + }, + "property": { + "end": 184, + "loc": { + "end": { + "column": 12, + "line": 9, + "offset": 184, + }, + "start": { + "column": 11, + "line": 9, + "offset": 183, + }, + }, + "name": "B", + "range": [ + 183, + 184, + ], + "raw": "B", + "start": 183, + "type": "JSXIdentifier", + }, + "range": [ + 181, + 184, + ], + "raw": "A.B", + "start": 181, + "type": "JSXMemberExpression", + }, + "property": { + "end": 186, + "loc": { + "end": { + "column": 14, + "line": 9, + "offset": 186, + }, + "start": { + "column": 13, + "line": 9, + "offset": 185, + }, + }, + "name": "C", + "range": [ + 185, + 186, + ], + "raw": "C", + "start": 185, + "type": "JSXIdentifier", + }, + "range": [ + 181, + 186, + ], + "raw": "A.B.C", + "start": 181, + "type": "JSXMemberExpression", + }, + "range": [ + 179, + 187, + ], + "raw": "", + "start": 179, + "type": "JSXClosingElement", + }, + "end": 187, + "loc": { + "end": { + "column": 15, + "line": 9, + "offset": 187, + }, + "start": { + "column": 0, + "line": 9, + "offset": 172, + }, + }, + "openingElement": { + "attributes": [], + "end": 179, + "loc": { + "end": { + "column": 7, + "line": 9, + "offset": 179, + }, + "start": { + "column": 0, + "line": 9, + "offset": 172, + }, + }, + "name": { + "end": 178, + "loc": { + "end": { + "column": 6, + "line": 9, + "offset": 178, + }, + "start": { + "column": 1, + "line": 9, + "offset": 173, + }, + }, + "object": { + "end": 176, + "loc": { + "end": { + "column": 4, + "line": 9, + "offset": 176, + }, + "start": { + "column": 1, + "line": 9, + "offset": 173, + }, + }, + "object": { + "end": 174, + "loc": { + "end": { + "column": 2, + "line": 9, + "offset": 174, + }, + "start": { + "column": 1, + "line": 9, + "offset": 173, + }, + }, + "name": "A", + "range": [ + 173, + 174, + ], + "raw": "A", + "start": 173, + "type": "JSXIdentifier", + }, + "property": { + "end": 176, + "loc": { + "end": { + "column": 4, + "line": 9, + "offset": 176, + }, + "start": { + "column": 3, + "line": 9, + "offset": 175, + }, + }, + "name": "B", + "range": [ + 175, + 176, + ], + "raw": "B", + "start": 175, + "type": "JSXIdentifier", + }, + "range": [ + 173, + 176, + ], + "raw": "A.B", + "start": 173, + "type": "JSXMemberExpression", + }, + "property": { + "end": 178, + "loc": { + "end": { + "column": 6, + "line": 9, + "offset": 178, + }, + "start": { + "column": 5, + "line": 9, + "offset": 177, + }, + }, + "name": "C", + "range": [ + 177, + 178, + ], + "raw": "C", + "start": 177, + "type": "JSXIdentifier", + }, + "range": [ + 173, + 178, + ], + "raw": "A.B.C", + "start": 173, + "type": "JSXMemberExpression", + }, + "range": [ + 172, + 179, + ], + "raw": "", + "selfClosing": false, + "start": 172, + "type": "JSXOpeningElement", + }, + "range": [ + 172, + 187, + ], + "raw": "", + "start": 172, + "type": "JSXElement", + }, + "loc": { + "end": { + "column": 16, + "line": 9, + "offset": 187, + }, + "start": { + "column": 1, + "line": 9, + "offset": 172, + }, + }, + "range": [ + 172, + 187, + ], + "start": 172, + "type": "ExpressionStatement", + }, + ], + "comments": [], + "end": 188, + "loc": { + "end": { + "column": 1, + "line": 10, + "offset": 188, + }, + "start": { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "range": [ + 0, + 188, + ], + "sourceType": undefined, + "start": 0, + "tokens": [ + { + "end": 6, + "loc": { + "end": { + "column": 6, + "line": 1, + "offset": 6, + }, + "start": { + "column": 0, + "line": 1, + "offset": 0, + }, + }, + "range": [ + 0, + 6, + ], + "start": 0, + "type": "Keyword", + "value": "import", + }, + { + "end": 8, + "loc": { + "end": { + "column": 8, + "line": 1, + "offset": 8, + }, + "start": { + "column": 7, + "line": 1, + "offset": 7, + }, + }, + "range": [ + 7, + 8, + ], + "start": 7, + "type": "Punctuator", + "value": "{", + }, + { + "end": 23, + "loc": { + "end": { + "column": 23, + "line": 1, + "offset": 23, + }, + "start": { + "column": 9, + "line": 1, + "offset": 9, + }, + }, + "range": [ + 9, + 23, + ], + "start": 9, + "type": "Identifier", + "value": "DefinitionList", + }, + { + "end": 25, + "loc": { + "end": { + "column": 25, + "line": 1, + "offset": 25, + }, + "start": { + "column": 24, + "line": 1, + "offset": 24, + }, + }, + "range": [ + 24, + 25, + ], + "start": 24, + "type": "Punctuator", + "value": "}", + }, + { + "end": 30, + "loc": { + "end": { + "column": 30, + "line": 1, + "offset": 30, + }, + "start": { + "column": 26, + "line": 1, + "offset": 26, + }, + }, + "range": [ + 26, + 30, + ], + "start": 26, + "type": "Identifier", + "value": "from", + }, + { + "end": 49, + "loc": { + "end": { + "column": 49, + "line": 1, + "offset": 49, + }, + "start": { + "column": 31, + "line": 1, + "offset": 31, + }, + }, + "range": [ + 31, + 49, + ], + "start": 31, + "type": "String", + "value": "'./DefinitionList'", + }, + { + "end": 52, + "loc": { + "end": { + "column": 1, + "line": 3, + "offset": 52, + }, + "start": { + "column": 0, + "line": 3, + "offset": 51, + }, + }, + "range": [ + 51, + 52, + ], + "start": 51, + "type": "Punctuator", + "value": "<", + }, + { + "end": 66, + "loc": { + "end": { + "column": 15, + "line": 3, + "offset": 66, + }, + "start": { + "column": 1, + "line": 3, + "offset": 52, + }, + }, + "range": [ + 52, + 66, + ], + "start": 52, + "type": "JSXIdentifier", + "value": "DefinitionList", + }, + { + "end": 75, + "loc": { + "end": { + "column": 24, + "line": 3, + "offset": 75, + }, + "start": { + "column": 16, + "line": 3, + "offset": 67, + }, + }, + "range": [ + 67, + 75, + ], + "start": 67, + "type": "JSXIdentifier", + "value": "disabled", + }, + { + "end": 80, + "loc": { + "end": { + "column": 3, + "line": 4, + "offset": 80, + }, + "start": { + "column": 2, + "line": 4, + "offset": 79, + }, + }, + "range": [ + 79, + 80, + ], + "start": 79, + "type": "Punctuator", + "value": "<", + }, + { + "end": 100, + "loc": { + "end": { + "column": 23, + "line": 4, + "offset": 100, + }, + "start": { + "column": 3, + "line": 4, + "offset": 80, + }, + }, + "range": [ + 80, + 100, + ], + "start": 80, + "type": "JSXIdentifier", + "value": "DefinitionList.Title", + }, + { + "end": 114, + "loc": { + "end": { + "column": 37, + "line": 4, + "offset": 114, + }, + "start": { + "column": 24, + "line": 4, + "offset": 101, + }, + }, + "range": [ + 101, + 114, + ], + "start": 101, + "type": "JSXText", + "value": "Hello World !", + }, + { + "end": 115, + "loc": { + "end": { + "column": 38, + "line": 4, + "offset": 115, + }, + "start": { + "column": 37, + "line": 4, + "offset": 114, + }, + }, + "range": [ + 114, + 115, + ], + "start": 114, + "type": "Punctuator", + "value": "<", + }, + { + "end": 116, + "loc": { + "end": { + "column": 39, + "line": 4, + "offset": 116, + }, + "start": { + "column": 38, + "line": 4, + "offset": 115, + }, + }, + "range": [ + 115, + 116, + ], + "start": 115, + "type": "Punctuator", + "value": "/", + }, + { + "end": 136, + "loc": { + "end": { + "column": 59, + "line": 4, + "offset": 136, + }, + "start": { + "column": 39, + "line": 4, + "offset": 116, + }, + }, + "range": [ + 116, + 136, + ], + "start": 116, + "type": "JSXIdentifier", + "value": "DefinitionList.Title", + }, + { + "end": 137, + "loc": { + "end": { + "column": 60, + "line": 4, + "offset": 137, + }, + "start": { + "column": 59, + "line": 4, + "offset": 136, + }, + }, + "range": [ + 136, + 137, + ], + "start": 136, + "type": "Punctuator", + "value": ">", + }, + { + "end": 139, + "loc": { + "end": { + "column": 1, + "line": 5, + "offset": 139, + }, + "start": { + "column": 0, + "line": 5, + "offset": 138, + }, + }, + "range": [ + 138, + 139, + ], + "start": 138, + "type": "Punctuator", + "value": "<", + }, + { + "end": 140, + "loc": { + "end": { + "column": 2, + "line": 5, + "offset": 140, + }, + "start": { + "column": 1, + "line": 5, + "offset": 139, + }, + }, + "range": [ + 139, + 140, + ], + "start": 139, + "type": "Punctuator", + "value": "/", + }, + { + "end": 154, + "loc": { + "end": { + "column": 16, + "line": 5, + "offset": 154, + }, + "start": { + "column": 2, + "line": 5, + "offset": 140, + }, + }, + "range": [ + 140, + 154, + ], + "start": 140, + "type": "JSXIdentifier", + "value": "DefinitionList", + }, + { + "end": 155, + "loc": { + "end": { + "column": 17, + "line": 5, + "offset": 155, + }, + "start": { + "column": 16, + "line": 5, + "offset": 154, + }, + }, + "range": [ + 154, + 155, + ], + "start": 154, + "type": "Punctuator", + "value": ">", + }, + { + "end": 158, + "loc": { + "end": { + "column": 1, + "line": 7, + "offset": 158, + }, + "start": { + "column": 0, + "line": 7, + "offset": 157, + }, + }, + "range": [ + 157, + 158, + ], + "start": 157, + "type": "Punctuator", + "value": "<", + }, + { + "end": 161, + "loc": { + "end": { + "column": 4, + "line": 7, + "offset": 161, + }, + "start": { + "column": 1, + "line": 7, + "offset": 158, + }, + }, + "range": [ + 158, + 161, + ], + "start": 158, + "type": "JSXIdentifier", + "value": "A:B", + }, + { + "end": 164, + "loc": { + "end": { + "column": 7, + "line": 7, + "offset": 164, + }, + "start": { + "column": 6, + "line": 7, + "offset": 163, + }, + }, + "range": [ + 163, + 164, + ], + "start": 163, + "type": "Punctuator", + "value": "<", + }, + { + "end": 165, + "loc": { + "end": { + "column": 8, + "line": 7, + "offset": 165, + }, + "start": { + "column": 7, + "line": 7, + "offset": 164, + }, + }, + "range": [ + 164, + 165, + ], + "start": 164, + "type": "Punctuator", + "value": "/", + }, + { + "end": 168, + "loc": { + "end": { + "column": 11, + "line": 7, + "offset": 168, + }, + "start": { + "column": 8, + "line": 7, + "offset": 165, + }, + }, + "range": [ + 165, + 168, + ], + "start": 165, + "type": "JSXIdentifier", + "value": "A:B", + }, + { + "end": 170, + "loc": { + "end": { + "column": 13, + "line": 7, + "offset": 170, + }, + "start": { + "column": 12, + "line": 7, + "offset": 169, + }, + }, + "range": [ + 169, + 170, + ], + "start": 169, + "type": "Punctuator", + "value": ">", + }, + { + "end": 173, + "loc": { + "end": { + "column": 1, + "line": 9, + "offset": 173, + }, + "start": { + "column": 0, + "line": 9, + "offset": 172, + }, + }, + "range": [ + 172, + 173, + ], + "start": 172, + "type": "Punctuator", + "value": "<", + }, + { + "end": 178, + "loc": { + "end": { + "column": 6, + "line": 9, + "offset": 178, + }, + "start": { + "column": 1, + "line": 9, + "offset": 173, + }, + }, + "range": [ + 173, + 178, + ], + "start": 173, + "type": "JSXIdentifier", + "value": "A.B.C", + }, + { + "end": 180, + "loc": { + "end": { + "column": 8, + "line": 9, + "offset": 180, + }, + "start": { + "column": 7, + "line": 9, + "offset": 179, + }, + }, + "range": [ + 179, + 180, + ], + "start": 179, + "type": "Punctuator", + "value": "<", + }, + { + "end": 181, + "loc": { + "end": { + "column": 9, + "line": 9, + "offset": 181, + }, + "start": { + "column": 8, + "line": 9, + "offset": 180, + }, + }, + "range": [ + 180, + 181, + ], + "start": 180, + "type": "Punctuator", + "value": "/", + }, + { + "end": 186, + "loc": { + "end": { + "column": 14, + "line": 9, + "offset": 186, + }, + "start": { + "column": 9, + "line": 9, + "offset": 181, + }, + }, + "range": [ + 181, + 186, + ], + "start": 181, + "type": "JSXIdentifier", + "value": "A.B.C", + }, + { + "end": 187, + "loc": { + "end": { + "column": 15, + "line": 9, + "offset": 187, + }, + "start": { + "column": 14, + "line": 9, + "offset": 186, + }, + }, + "range": [ + 186, + 187, + ], + "start": 186, + "type": "Punctuator", + "value": ">", + }, + ], + "type": "Program", +} +`; + exports[`parser should match all AST snapshots: 450.mdx 1`] = ` { "body": [ diff --git a/test/fixtures/445.mdx b/test/fixtures/445.mdx new file mode 100644 index 00000000..bb756e7d --- /dev/null +++ b/test/fixtures/445.mdx @@ -0,0 +1,9 @@ +import { DefinitionList } from './DefinitionList' + + + Hello World ! + + + + +