From 76168eadded25fdf1a66698c5cee722dac664be8 Mon Sep 17 00:00:00 2001 From: Andrew Seier Date: Thu, 26 Mar 2026 10:54:50 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20=E2=80=9CnoImplicitAny=E2=80=9D=20errors?= =?UTF-8?q?=20in=20=E2=80=9Cx-parser.js=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the change from TypeScript “5.x” to “6.x”, the “strict” config setting now defaults to “true”. We are simply working through the files one-by-one to be able to accept that new default change. It’s ultimately what we want, anyhow. --- CHANGELOG.md | 1 + test/test-parser.js | 4 + types/x-parser.d.ts | 361 +++++++++++++++++++++++++++++++---- types/x-parser.d.ts.map | 2 +- x-parser.js | 407 ++++++++++++++++++++++++++++++---------- 5 files changed, 638 insertions(+), 137 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f58d917..440eb4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed +- Fix `noImplicitAny` TypeScript errors in `x-parser.js` (#357). - Re-enable strict type errors for `strictNullChecks`, `useUnknownInCatchVariables`, and `strictFunctionTypes` (#357). - Bump devDependencies (eslint 10, typescript 6, eslint-plugin-jsdoc 62, etc.). diff --git a/test/test-parser.js b/test/test-parser.js index d7e9cbd..7b0b9f5 100644 --- a/test/test-parser.js +++ b/test/test-parser.js @@ -1654,6 +1654,8 @@ describe('validate', () => { `; }); + // The eslint-plugin-x-element package relies on error context to map + // parsing errors to source locations. These tests ensure the contract. it('errors contain context for debugging', () => { let error; try { @@ -1669,6 +1671,8 @@ describe('validate', () => { assert(context.end === 5); }); + // When an error occurs before character-level parsing begins (e.g., a raw + // string escape), start and end are null to signal no position is available. it('initial error contains context for debugging', () => { let error; try { diff --git a/types/x-parser.d.ts b/types/x-parser.d.ts index a89716e..d9a12ea 100644 --- a/types/x-parser.d.ts +++ b/types/x-parser.d.ts @@ -36,42 +36,323 @@ export class XParser { static #boundAttributeMalformed: RegExp; static #boundPropertyMalformed: RegExp; static #danglingQuoteMalformed: RegExp; - static #getErrorMessage(key: any): "Could not parse template markup (at template start)." | "Could not parse template markup (after text content)." | "Could not parse template markup (after a comment)." | "Could not parse template markup (after interpolated content)." | "Could not parse template markup (after a spacing within start tag)." | "Could not parse template markup (after a start tag)." | "Could not parse template markup (after a boolean attribute interpolation in a start tag)." | "Could not parse template markup (after a defined attribute interpolation in a start tag)." | "Could not parse template markup (after an attribute interpolation in a start tag)." | "Could not parse template markup (after a property interpolation in a start tag)." | "Could not parse template markup (after an end tag)." | "Invalid tag name - refer to https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names)." | "Invalid tag whitespace (extraneous whitespace in start tag)." | "Invalid start tag (extraneous whitespace at close of start tag)." | "Invalid end tag." | "Invalid tag attribute (must use kebab-case names and double-quoted values)." | "Invalid tag attribute interpolation (must use kebab-case names and double-quoted values)." | "Invalid tag property interpolation (must use kebab-case names and double-quoted values)." | "Invalid closing quote on tag attribute or property." | "CDATA sections are not supported. Use character references instead: https://developer.mozilla.org/en-US/docs/Glossary/Character_reference." | "Bad escape in tagged template string. Use “\” for “\\”, “$” for “\\$”, and “`” for “\\`”. All character references are supported: https://developer.mozilla.org/en-US/docs/Glossary/Character_reference." | "Ambiguous ampersand character or invalid hexadecimal character reference." | "Invalid comment. Comments cannot start with “>” or “->” characters, they cannot include a set of “--” characters, and they cannot end with a “-” character." | "Unsupported native tag - supported native tags are listed here: https://github.com/Netflix/x-element/blob/main/doc/TEMPLATES.md#supported-native-tags." | "Invalid end tag (all non-void start tags much have matching end tags)." | "Unsupported )." | "Unsupported declarative shadow root on