diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index 367f4de2e9d44aedc6db77bcacb466385c407728..aa1d2563dbf98f9522cfd343b1ce5a841fc3f126 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -606,6 +606,25 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex return Promise.resolve(false); } +/* +* Walks the tree rooted at root and apply function fn on each node. +* if fn return false at any node, the further processing of tree is stopped. +*/ +function walk(root: any, fn: ((node: any) => boolean)): boolean { + let ctx = root; + while (ctx) { + + let next = ctx.next; + if (fn(ctx) === false || walk(ctx.firstChild, fn) === false) { + return false; + } + + ctx = next; + } + + return true; +} + /** * Expands abbreviation as detailed in given input. */ @@ -648,6 +667,18 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined { wrappingNode.value = '\n\t' + wrappingNode.value + '\n'; } } + + // Below fixes https://github.com/microsoft/vscode/issues/78219 + // walk the tree and remove tags for empty values + walk(parsedAbbr, node => { + if (node.name !== null && node.value === '' && !node.isSelfClosing && node.children.length === 0) { + node.name = ''; + node.value = '\n'; + } + + return true; + }); + expandedText = helper.expandAbbreviation(parsedAbbr, expandOptions); // All $anyword would have been escaped by the emmet helper. // Remove the escaping backslash from $TM_SELECTED_TEXT so that VS Code Snippet controller can treat it as a variable