Stillat / vscode-antlers-language-server

Provides rich language features for Statamic's Antlers templating language, including code completions, syntax highlighting, and more.
https://antlers.dev
MIT License
36 stars 3 forks source link

Antlers Prettier Plugin Formatting Error "Unexpected closing tag" #53

Closed pdipatrizio closed 1 year ago

pdipatrizio commented 1 year ago

Describe the bug My Antlers file is failing to format with the Antlers Prettier plugin. The full, original code is fairly complex, but I was able to reproduce the same error with the simplified code below.

Impacted Products Which Antlers Toolbox products does this bug apply to?

Versions and Other Plugins/Extensions Antlers Toolbox v2.4.1 Antlers Prettier Plugin v1.1.18 Prettier Plugin Tailwindcss v0.1.13 Prettier v2.7.1

Steps to reproduce Paste template into antlers.html file. Format document with "Prettier Code Formatter."

Template contents

<{{ as or 'a' }}
    {{ slot:attributes }}
    class="font-bold">
</{{ as or 'a' }}>

Prettier log output:

["INFO" - 10:56:44 AM] Formatting file:///Users/redacted/Sites/redacted/resources/views/components/_test.antlers.html
["INFO" - 10:56:44 AM] Using config file at '/Users/redacted/Sites/redacted/.prettierrc'
["INFO" - 10:56:44 AM] Using ignore file (if present) at /Users/redacted/Sites/redacted/.prettierignore
["INFO" - 10:56:44 AM] File Info:
{
  "ignored": false,
  "inferredParser": "antlers"
}
["INFO" - 10:56:44 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 10:56:44 AM] Prettier Options:
{
  "filepath": "/Users/redacted/Sites/redacted/resources/views/components/_test.antlers.html",
  "parser": "antlers",
  "useTabs": false,
  "tabWidth": 4,
  "endOfLine": "lf",
  "editorconfig": true,
  "bracketSameLine": true,
  "arrowParens": "always",
  "bracketSpacing": true,
  "embeddedLanguageFormatting": "auto",
  "htmlWhitespaceSensitivity": "css",
  "printWidth": 120,
  "proseWrap": "preserve",
  "quoteProps": "consistent",
  "semi": false,
  "trailingComma": "es5",
  "singleAttributePerLine": false,
  "singleQuote": false
}
["ERROR" - 10:56:44 AM] Error formatting document.
["ERROR" - 10:56:44 AM] Unexpected closing tag "A8LeVzgQ45ZA". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (4:1)
  2 |     <As3mqxLQO0Iv68tlBIxrUA />
  3 |     class="font-bold">
> 4 | </A8LeVzgQ45ZA>
    | ^^^^^^^^^^^^^^^
SyntaxError: Unexpected closing tag "A8LeVzgQ45ZA". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags (4:1)
  2 |     <As3mqxLQO0Iv68tlBIxrUA />
  3 |     class="font-bold">
> 4 | </A8LeVzgQ45ZA>
    | ^^^^^^^^^^^^^^^
    at t (/Users/redacted/Sites/redacted/node_modules/prettier/parser-html.js:4:2359)
    at al (/Users/redacted/Sites/redacted/node_modules/prettier/parser-html.js:36:6425)
    at Ts (/Users/redacted/Sites/redacted/node_modules/prettier/parser-html.js:36:7938)
    at Object.parse (/Users/redacted/Sites/redacted/node_modules/prettier/parser-html.js:36:8710)
    at Object.parse (/Users/redacted/Sites/redacted/node_modules/prettier-plugin-tailwindcss/dist/index.js:146:3902)
    at Object.parse (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:7334:23)
    at coreFormat (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8645:18)
    at formatWithCursor2 (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8837:18)
    at /Users/redacted/Sites/redacted/node_modules/prettier/index.js:37229:12
    at Object.format (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:37243:12)
    at JT.bk [as htmlFormatter] (/Users/redacted/Sites/redacted/node_modules/prettier-plugin-antlers/plugin.js:397:1503)
    at JT.formatDocument (/Users/redacted/Sites/redacted/node_modules/prettier-plugin-antlers/plugin.js:344:8892)
    at Object.print (/Users/redacted/Sites/redacted/node_modules/prettier-plugin-antlers/plugin.js:432:1201)
    at callPluginPrintFunction (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8420:26)
    at mainPrintInternal (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8369:22)
    at mainPrint (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8356:18)
    at printAstToDoc (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8348:18)
    at coreFormat (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8653:20)
    at formatWithCursor2 (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:8837:18)
    at /Users/redacted/Sites/redacted/node_modules/prettier/index.js:37229:12
    at Object.format (/Users/redacted/Sites/redacted/node_modules/prettier/index.js:37243:12)
    at t.default.format (/Users/redacted/.vscode/extensions/esbenp.prettier-vscode-9.10.3/dist/extension.js:1:14731)
    at async t.PrettierEditProvider.provideEdits (/Users/redacted/.vscode/extensions/esbenp.prettier-vscode-9.10.3/dist/extension.js:1:11417)
    at async B.provideDocumentFormattingEdits (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:96:39719)
["INFO" - 10:56:44 AM] Formatting completed in 18ms.

Interestingly... the error doesn't occur when using this nearly identical template:

<{{ as or 'a' }} {{ slot:attributes }} class="font-bold">
</{{ as or 'a' }}>
JohnathonKoster commented 1 year ago

Resolved in the following versions: