@codemirror/lang-javascript
Advanced tools
Comparing version 6.1.1 to 6.1.2
@@ -0,1 +1,7 @@ | ||
## 6.1.2 (2022-12-07) | ||
### Bug fixes | ||
Automatic tag closing in JSX now works for namespaced and member-expression tag names. | ||
## 6.1.1 (2022-10-24) | ||
@@ -2,0 +8,0 @@ |
@@ -338,7 +338,18 @@ import { parser } from '@lezer/javascript'; | ||
} | ||
function findOpenTag(node) { | ||
for (;;) { | ||
if (node.name == "JSXOpenTag" || node.name == "JSXSelfClosingTag" || node.name == "JSXFragmentTag") | ||
return node; | ||
if (!node.parent) | ||
return null; | ||
node = node.parent; | ||
} | ||
} | ||
function elementName(doc, tree, max = doc.length) { | ||
if (!tree) | ||
return ""; | ||
let name = tree.getChild("JSXIdentifier"); | ||
return name ? doc.sliceString(name.from, Math.min(name.to, max)) : ""; | ||
for (let ch = tree === null || tree === void 0 ? void 0 : tree.firstChild; ch; ch = ch.nextSibling) { | ||
if (ch.name == "JSXIdentifier" || ch.name == "JSXBuiltin" || ch.name == "JSXNamespacedName" || | ||
ch.name == "JSXMemberExpression") | ||
return doc.sliceString(ch.from, Math.min(ch.to, max)); | ||
} | ||
return ""; | ||
} | ||
@@ -357,3 +368,3 @@ const android = typeof navigator == "object" && /*@__PURE__*//Android\b/.test(navigator.userAgent); | ||
let changes = state.changeByRange(range => { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
let { head } = range, around = syntaxTree(state).resolveInner(head, -1), name; | ||
@@ -365,9 +376,6 @@ if (around.name == "JSXStartTag") | ||
} | ||
else if (text == ">" && around.name == "JSXIdentifier") { | ||
if (((_b = (_a = around.parent) === null || _a === void 0 ? void 0 : _a.lastChild) === null || _b === void 0 ? void 0 : _b.name) != "JSXEndTag" && (name = elementName(state.doc, around.parent, head))) | ||
return { range: EditorSelection.cursor(head + 1), changes: { from: head, insert: `></${name}>` } }; | ||
} | ||
else if (text == "/" && around.name == "JSXFragmentTag") { | ||
let empty = around.parent, base = empty === null || empty === void 0 ? void 0 : empty.parent; | ||
if (empty.from == head - 1 && ((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != "JSXEndTag" && (name = elementName(state.doc, base === null || base === void 0 ? void 0 : base.firstChild, head))) { | ||
if (empty.from == head - 1 && ((_a = base.lastChild) === null || _a === void 0 ? void 0 : _a.name) != "JSXEndTag" && | ||
(name = elementName(state.doc, base === null || base === void 0 ? void 0 : base.firstChild, head))) { | ||
let insert = `/${name}>`; | ||
@@ -377,2 +385,9 @@ return { range: EditorSelection.cursor(head + insert.length), changes: { from: head, insert } }; | ||
} | ||
else if (text == ">") { | ||
let openTag = findOpenTag(around); | ||
if (openTag && ((_b = openTag.lastChild) === null || _b === void 0 ? void 0 : _b.name) != "JSXEndTag" && | ||
state.sliceDoc(head, head + 2) != "</" && | ||
(name = elementName(state.doc, openTag, head))) | ||
return { range: EditorSelection.cursor(head + 1), changes: { from: head, insert: `></${name}>` } }; | ||
} | ||
return { range }; | ||
@@ -379,0 +394,0 @@ }); |
{ | ||
"name": "@codemirror/lang-javascript", | ||
"version": "6.1.1", | ||
"version": "6.1.2", | ||
"description": "JavaScript language support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52892
996