Skip to content

Commit

Permalink
Support TypeScript 5.1 (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic authored Jun 21, 2023
1 parent 2422d55 commit 16935ef
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
21 changes: 21 additions & 0 deletions packages/lit-analyzer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/lit-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"typescript": "~4.4.4",
"typescript-4.8": "npm:typescript@~4.8.2",
"typescript-5.0": "npm:typescript@~5.0.4",
"typescript-5.1": "npm:typescript@~5.1.0",
"wireit": "^0.9.5"
},
"ava": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class HtmlDocument extends TextDocument {

htmlAttrAreaAtOffset(offset: DocumentOffset | DocumentRange): HtmlNode | undefined {
return this.mapFindOne(node => {
if (offset > node.location.name.end && intersects(offset, node.location.startTag)) {
const offsetNum = typeof offset === "number" ? offset : offset.end;
if (offsetNum > node.location.name.end && intersects(offset, node.location.startTag)) {
// Check if the position intersects any attributes. Break if so.
for (const htmlAttr of node.attributes) {
if (intersects(offset, htmlAttr.location)) {
Expand Down
11 changes: 7 additions & 4 deletions packages/lit-analyzer/src/test/helpers/ts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { setTypescriptModule } from "../../lib/analyze/ts-module.js";

type TestFunction = (title: string, implementation: Implementation) => void;

const TS_MODULES_ALL = ["current", "4.8", "5.0"] as const;
const TS_MODULES_ALL = ["current", "4.8", "5.0", "5.1"] as const;

type TsModuleKind = typeof TS_MODULES_ALL[number];

const TS_MODULES_DEFAULT: TsModuleKind[] = ["current", "4.8", "5.0"];
const TS_MODULES_DEFAULT: TsModuleKind[] = ["current", "4.8", "5.0", "5.1"];

/**
* Returns the name of the module to require for a specific ts module kind
Expand All @@ -20,14 +20,17 @@ function getTsModuleNameWithKind(kind: TsModuleKind | undefined): string {
switch (kind) {
case "4.8":
case "5.0":
case "5.1":
return `typescript-${kind}`;
case "current":
case undefined:
case null:
// Fall back to "default"
return "typescript";
default:
throw new Error(`Unknown ts module "${kind}"`);
default: {
const never: never = kind;
throw new Error(`Unknown ts module "${never}"`);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tsTest("Event binding: Callable value is bindable", t => {
});

tsTest("Event binding: Non callback value is not bindable", t => {
const { diagnostics } = getDiagnostics('html`<input @change="${(() => {})()}" />`');
const { diagnostics } = getDiagnostics('html`<input @change="${(():void => {})()}" />`');
hasDiagnostic(t, diagnostics, "no-noncallable-event-binding");
});

Expand Down

0 comments on commit 16935ef

Please sign in to comment.