Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
638221a
Add template parser to analyzer
justinfagnani Oct 5, 2023
0f5faa5
WIP
justinfagnani Feb 1, 2024
547fd74
WIP
justinfagnani Feb 2, 2024
bd804ff
Merge branch 'main' into analyzer-template-2
justinfagnani Oct 20, 2024
2c46c7d
Update implementation and add tests
justinfagnani Oct 20, 2024
1bc88a2
Get initial rule and test working
justinfagnani Oct 20, 2024
32797f7
Merge branch 'main' into analyzer-template-2
justinfagnani Mar 10, 2025
31f99bb
Fix tests
justinfagnani Mar 10, 2025
297ed62
Move modules to a /lib/lit/ folder
justinfagnani Mar 10, 2025
6bbef05
Adjust line and col positions on parse5 nodes
justinfagnani Mar 13, 2025
3d19d22
Fix newlines for windows
justinfagnani Mar 13, 2025
7e68b13
Merge branch 'main' into analyzer-template-2
justinfagnani Mar 21, 2025
f9eecdc
Adjust startTag and endTag offsets too
justinfagnani Mar 22, 2025
af96b02
Merge branch 'main' into analyzer-template-2
justinfagnani Aug 19, 2025
1603bb5
Fix compiler error
justinfagnani Aug 19, 2025
827075b
Merge branch 'analyzer-template-2' into tsserver-plugin-next
justinfagnani Aug 19, 2025
4ce888c
Fix offsets on windows
justinfagnani Aug 20, 2025
66f47c5
Merge branch 'analyzer-template-2' into tsserver-plugin-next
justinfagnani Aug 20, 2025
7e42b54
Update deps, address some comments
justinfagnani Aug 20, 2025
e15fa8d
Merge branch 'analyzer-template-2' into tsserver-plugin-next
justinfagnani Aug 20, 2025
ed9b399
Fix import
justinfagnani Aug 20, 2025
6318a70
Merge branch 'main' into analyzer-template-2
justinfagnani Aug 20, 2025
4ef1933
Merge branch 'analyzer-template-2' into tsserver-plugin-next
justinfagnani Aug 21, 2025
9e4c08c
Merge branch 'main' into tsserver-plugin-next
justinfagnani Aug 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-cats-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-labs/analyzer': minor
---

Add template parser to analyzer
5 changes: 1 addition & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,7 @@ packages/labs/tsserver-plugin/example/node_modules/
packages/labs/tsserver-plugin/lib/
packages/labs/tsserver-plugin/test/

packages/labs/tsserver-plugin/**/index.js
packages/labs/tsserver-plugin/**/index.js.map
packages/labs/tsserver-plugin/**/index.d.ts
packages/labs/tsserver-plugin/**/index.d.ts.map
packages/labs/tsserver-plugin/index.*

packages/labs/virtualizer/polyfills/resize-observer-polyfill/ResizeObserver.js
packages/labs/virtualizer/src/polyfills/resize-observer-polyfill/ResizeObserver.js
Expand Down
5 changes: 1 addition & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,7 @@ packages/labs/testing/**/.tsbuildinfo-utils
packages/labs/tsserver-plugin/lib/
packages/labs/tsserver-plugin/test/

packages/labs/tsserver-plugin/**/index.js
packages/labs/tsserver-plugin/**/index.js.map
packages/labs/tsserver-plugin/**/index.d.ts
packages/labs/tsserver-plugin/**/index.d.ts.map
packages/labs/tsserver-plugin/index.*

packages/labs/virtualizer/layouts/
packages/labs/virtualizer/polyfillLoaders/
Expand Down
43 changes: 43 additions & 0 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions packages/labs/analyzer/src/lib/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/

import type ts from 'typescript';
import {Package, PackageJson, AnalyzerInterface, Module} from './model.js';
import {AbsolutePath} from './paths.js';
import {getModule} from './javascript/modules.js';
export {PackageJson};
import {
getPackageInfo,
getPackageRootForModulePath,
} from './javascript/packages.js';
import {AnalyzerInterface, Module, Package, PackageJson} from './model.js';
import {AbsolutePath} from './paths.js';
export {PackageJson};

export type TypeScript = typeof ts;

Expand Down
5 changes: 1 addition & 4 deletions packages/labs/tsserver-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/lib/
/test/

index.js
index.js.map
index.d.ts
index.d.ts.map
/index.*
63 changes: 56 additions & 7 deletions packages/labs/tsserver-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@ A new TypeScript Language Service Plugin for Lit living in the Lit monorepo.

### Goals

This plugin will provide additional type-checking, syntax checking, and better errors for Lit constructs (like lit-html templates) that the TypeScript compiler can't check natively.

It is intended to include much of the functionality from [ts-lit-plugin](https://github.com/runem/lit-analyzer/tree/master/packages/ts-lit-plugin) and [eslint-plugin-lit](https://github.com/43081j/eslint-plugin-lit) but maintained within the Lit monorepo and based on the analysis of the [Lit team's first-party analyzer](https://github.com/lit/lit/tree/main/packages/labs/analyzer).

This plugin is also intended to be used with and be coherent with the new type-aware version of the `eslint-plugin-lit` library that's being developed (also int he Lit monorepo).

This means that additional checks should ideally live in either the linter or the type-checker, and rarely both. That may be hard as there is a blurry line between type-checking and type-aware linting, and not all users may want to run both tools. If there are cases where a rule exists in booth tools they should share an implementation, name, and ideally a controlling configuration.
This plugin will provide additional type-checking, syntax checking, and better
errors for Lit constructs (like lit-html templates) that the TypeScript compiler
can't check natively.

It is intended to include much of the functionality from
[ts-lit-plugin](https://github.com/runem/lit-analyzer/tree/master/packages/ts-lit-plugin)
and [eslint-plugin-lit](https://github.com/43081j/eslint-plugin-lit) but
maintained within the Lit monorepo and based on the analysis of the [Lit team's
first-party
analyzer](https://github.com/lit/lit/tree/main/packages/labs/analyzer).

This plugin is also intended to be used with and be coherent with the new
type-aware version of the `eslint-plugin-lit` library that's being developed
(also int he Lit monorepo).

This means that additional checks should ideally live in either the linter or
the type-checker, and rarely both. That may be hard as there is a blurry line
between type-checking and type-aware linting, and not all users may want to run
both tools. If there are cases where a rule exists in booth tools they should
share an implementation, name, and ideally a controlling configuration.

### Features to include

Expand All @@ -41,6 +54,42 @@ Aside from linting / type-checking:

Please see [CONTRIBUTING.md](../../../CONTRIBUTING.md).

### Running locally

There is an example project in `example/` that should be setup to run the plugin
locally for development.

The example project has a dependency on the plugin with a `file:..` version, and
a tsconfig that adds the plugin.

#### Install example project dependencies

```sh
cd packages/labs/tsserver-plugin/example
npm i
```

#### Open example project

```sh
cd packages/labs/tsserver-plugin
code example
```

#### Setup VS Code

Do these in the window that has the example project open:

- Make sure are using the TypeScript version from the example workspace. Click
the `{}` from the status bar to select a version.
- The logs from the plugin are written to the TS Server logs. To see logs those,
open a TypeScript file and run the command "TypeScript: Open TS SErver log".
You may have to enable the logs.
- Disable othet Lit plugins. VS Code can not save disabled extensions to a
workspace settings file, so you have to do this yourself. Go to the Extensions
activity, cliekt the gear icon next to `lit-plugin`, and select
"Disable (Worksapce)".

### Debugging

```sh
Expand Down
59 changes: 59 additions & 0 deletions packages/labs/tsserver-plugin/example/package-lock.json

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

5 changes: 4 additions & 1 deletion packages/labs/tsserver-plugin/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"private": true,
"type": "module",
"devDependencies": {
"@lit-labs/tsserver-plugin": "file:..",
"@lit-labs/tsserver-plugin": "file:.."
},
"dependencies": {
"lit": "^3.2.1",
"typescript": "~5.9.0"
}
}
21 changes: 17 additions & 4 deletions packages/labs/tsserver-plugin/example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Edit this file to trigger the TSServer commands.
import {LitElement, html, css} from 'lit';
import {customElement, property} from 'lit/decorators.js';

const anExampleVariable = 'Hello World';
console.log(anExampleVariable);
a;
@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
:host {
color: blue;
}
`;

@property({type: String})
name = 'World';

render() {
return html`<p>Hello, ${this.name}!</p>`;
}
}
4 changes: 2 additions & 2 deletions packages/labs/tsserver-plugin/example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
// This matches the package name given in this package.json
"plugins": [
{
"name": "@lit-labs/tsserver-plugin"
Expand All @@ -17,13 +16,14 @@
"outDir": "./",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"useDefineForClassFields": false,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"],
Expand Down
18 changes: 14 additions & 4 deletions packages/labs/tsserver-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"url": "git+https://github.com/lit/lit.git",
"directory": "packages/labs/tsserver-plugin"
},
"main": "index.js",
"type": "commonjs",
"main": "index.cjs",
"type": "module",
"scripts": {
"build": "wireit",
"test": "wireit"
Expand All @@ -30,14 +30,19 @@
"index.{js,js.map,d.ts,d.ts.map}",
"tsconfig.tsbuildinfo"
],
"dependencies": [
"../analyzer:build"
],
"clean": "if-file-deleted"
},
"test": {
"command": "node --enable-sourcemaps --test-reporter=spec --test test/**/*_test.js",
"command": "node --enable-source-maps --test-reporter=spec --test test/**/*_test.js",
"dependencies": [
"build"
],
"files": [],
"files": [
"test-files/**/*"
],
"output": []
}
},
Expand All @@ -49,6 +54,11 @@
".": "./index.js"
},
"devDependencies": {
"@types/node": "^22.7.7"
},
"dependencies": {
"@lit-labs/analyzer": "^0.13.1",
"@parse5/tools": "^0.5.0",
"typescript": "~5.9.0"
}
}
Loading
Loading