@backtickjs/language-plugin 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jean-François Bisson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @backtickjs/language-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The [Volar](https://volarjs.dev) language plugin that shows TypeScript what a [Backtick](https://backtickjs.com) client script means.
4
+
5
+ ## Internal
6
+
7
+ You don't install this package directly. It is used by [`@backtickjs/tsc`](https://github.com/backtickjs/backtick/tree/main/packages/tsc) (`backtick-tsc`), [`@backtickjs/language-service`](https://github.com/backtickjs/backtick/tree/main/packages/language-service), [`@backtickjs/typescript-plugin`](https://github.com/backtickjs/backtick/tree/main/packages/typescript-plugin) and [`@backtickjs/language-server`](https://github.com/backtickjs/backtick/tree/main/packages/language-server).
8
+
9
+ ## What it does
10
+
11
+ For every `.ts`, `.tsx`, `.js` and `.jsx` file (declaration files excepted), it runs the compiler's `virtualize` and hands TypeScript the result: a virtual copy of the file in which each `` cs`…` `` script is real code, with its splices typed against the host values they refer to. Source mappings tie the virtual code back to the original file, so errors, hovers, completions and go-to-definition land on the script you wrote. It also keeps Backtick's own compiler diagnostics, such as unsupported syntax in a script, for [`@backtickjs/language-service`](https://github.com/backtickjs/backtick/tree/main/packages/language-service) to report.
12
+
13
+ The package exports `getBacktickLanguagePlugin(ts, getFileName)` and the `BacktickVirtualCode` class.
14
+
15
+ ## Related
16
+
17
+ - [`@backtickjs/compiler`](https://github.com/backtickjs/backtick/tree/main/packages/compiler): produces the virtual code
18
+ - [Backtick for VS Code](https://marketplace.visualstudio.com/items?itemName=backtickjs.backtick-vscode)
19
+ - [Documentation](https://backtickjs.com/docs)
20
+
21
+ ## License
22
+
23
+ MIT
@@ -0,0 +1,12 @@
1
+ import type { Diagnostic } from "@backtickjs/compiler";
2
+ import type { CodeMapping, VirtualCode } from "@volar/language-core";
3
+ import type ts from "typescript";
4
+ export declare class BacktickVirtualCode implements VirtualCode {
5
+ id: string;
6
+ languageId: string;
7
+ mappings: CodeMapping[];
8
+ snapshot: ts.IScriptSnapshot;
9
+ embeddedCodes: VirtualCode[];
10
+ diagnostics: Diagnostic[];
11
+ constructor(ts: typeof import("typescript"), fileName: string, languageId: string, snapshot: ts.IScriptSnapshot);
12
+ }
@@ -0,0 +1,51 @@
1
+ import { virtualize } from "@backtickjs/compiler";
2
+ export class BacktickVirtualCode {
3
+ id = "backtick-source";
4
+ languageId;
5
+ mappings;
6
+ snapshot;
7
+ embeddedCodes;
8
+ diagnostics;
9
+ constructor(ts, fileName, languageId, snapshot) {
10
+ const sourceText = snapshot.getText(0, snapshot.getLength());
11
+ const { virtualCode, mappings, diagnostics } = virtualize(ts, fileName, sourceText);
12
+ this.languageId = languageId;
13
+ this.diagnostics = diagnostics;
14
+ this.snapshot = snapshot;
15
+ this.mappings = [
16
+ {
17
+ sourceOffsets: [0],
18
+ generatedOffsets: [0],
19
+ lengths: [sourceText.length],
20
+ data: { format: false, verification: true },
21
+ },
22
+ ];
23
+ this.embeddedCodes = [
24
+ {
25
+ id: "backtick-virtual",
26
+ languageId,
27
+ snapshot: {
28
+ getText: (start, end) => virtualCode.substring(start, end),
29
+ getLength: () => virtualCode.length,
30
+ getChangeRange: () => undefined,
31
+ },
32
+ mappings: mappings.map((mapping) => ({
33
+ ...mapping,
34
+ // The compiler's own flags (e.g. `semantic: false` on a
35
+ // `cs.splice(...)` wrapper, so hover doesn't resolve through it)
36
+ // override the defaults.
37
+ data: {
38
+ completion: true,
39
+ format: false,
40
+ navigation: true,
41
+ semantic: true,
42
+ structure: true,
43
+ verification: true,
44
+ ...mapping.data,
45
+ },
46
+ })),
47
+ },
48
+ ];
49
+ }
50
+ }
51
+ //# sourceMappingURL=BacktickVirtualCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BacktickVirtualCode.js","sourceRoot":"","sources":["../src/BacktickVirtualCode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,MAAM,OAAO,mBAAmB;IAC9B,EAAE,GAAG,iBAAiB,CAAC;IACvB,UAAU,CAAS;IACnB,QAAQ,CAAgB;IACxB,QAAQ,CAAqB;IAC7B,aAAa,CAAgB;IAC7B,WAAW,CAAe;IAE1B,YACE,EAA+B,EAC/B,QAAgB,EAChB,UAAkB,EAClB,QAA4B;QAE5B,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7D,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,UAAU,CACvD,EAAE,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 export declare function getBacktickLanguagePlugin<T>(ts: typeof import("typescript"), getFileName: (uri: T) => string): LanguagePlugin<T, BacktickVirtualCode>;
@@ -0,0 +1,63 @@
1
+ import { BacktickVirtualCode } from "./BacktickVirtualCode.js";
2
+ export function getBacktickLanguagePlugin(ts, getFileName) {
3
+ return {
4
+ getLanguageId() {
5
+ // Keep as-is
6
+ },
7
+ createVirtualCode(uri, languageId, snapshot) {
8
+ switch (languageId) {
9
+ case "javascript":
10
+ case "javascriptreact":
11
+ case "typescript":
12
+ case "typescriptreact": {
13
+ const fileName = getFileName(uri);
14
+ if (fileName.endsWith(".d.ts")) {
15
+ return;
16
+ }
17
+ return new BacktickVirtualCode(ts, fileName, languageId, snapshot);
18
+ }
19
+ default:
20
+ return;
21
+ }
22
+ },
23
+ typescript: {
24
+ extraFileExtensions: [],
25
+ getServiceScript(root) {
26
+ // TypeScript reads the compiled embedded code, not the source root.
27
+ const code = root.embeddedCodes?.[0];
28
+ if (!code) {
29
+ return;
30
+ }
31
+ switch (root.languageId) {
32
+ case "javascript":
33
+ return {
34
+ code,
35
+ extension: ".js",
36
+ scriptKind: 1,
37
+ };
38
+ case "javascriptreact":
39
+ return {
40
+ code,
41
+ extension: ".jsx",
42
+ scriptKind: 2,
43
+ };
44
+ case "typescript":
45
+ return {
46
+ code,
47
+ extension: ".ts",
48
+ scriptKind: 3,
49
+ };
50
+ case "typescriptreact":
51
+ return {
52
+ code,
53
+ extension: ".tsx",
54
+ scriptKind: 4,
55
+ };
56
+ default:
57
+ return;
58
+ }
59
+ },
60
+ },
61
+ };
62
+ }
63
+ //# sourceMappingURL=getBacktickLanguagePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBacktickLanguagePlugin.js","sourceRoot":"","sources":["../src/getBacktickLanguagePlugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,UAAU,yBAAyB,CACvC,EAA+B,EAC/B,WAA+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1C,CAAC;oBACJ;wBACE,OAAO;gBACX,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { BacktickVirtualCode } from "./BacktickVirtualCode.js";
2
+ export { getBacktickLanguagePlugin } from "./getBacktickLanguagePlugin.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { BacktickVirtualCode } from "./BacktickVirtualCode.js";
2
+ export { getBacktickLanguagePlugin } from "./getBacktickLanguagePlugin.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@backtickjs/language-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Internal: the Volar language plugin that shows TypeScript what a Backtick client script means",
5
+ "keywords": [
6
+ "backtick",
7
+ "react-native",
8
+ "server-driven-ui",
9
+ "server-components",
10
+ "volar",
11
+ "typescript",
12
+ "language-tools"
13
+ ],
14
+ "homepage": "https://backtickjs.com",
15
+ "bugs": {
16
+ "url": "https://github.com/backtickjs/backtick/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/backtickjs/backtick.git",
21
+ "directory": "packages/language-plugin"
22
+ },
23
+ "license": "MIT",
24
+ "author": "Jean-François Bisson <jf@backtickjs.com>",
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "!dist/._cache",
36
+ "src"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@volar/language-core": "^2.4.28",
43
+ "@backtickjs/compiler": "0.1.1"
44
+ },
45
+ "devDependencies": {
46
+ "@volar/typescript": "^2.4.28",
47
+ "prettier": "^3.6.2",
48
+ "typescript": "^6.0.3"
49
+ },
50
+ "peerDependencies": {
51
+ "typescript": "^6.0.3"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -b",
55
+ "dev": "tsc -b --watch",
56
+ "format": "prettier --write --ignore-unknown .",
57
+ "format:check": "prettier --check --ignore-unknown .",
58
+ "clean": "rm -rf node_modules dist .turbo"
59
+ }
6
60
  }
@@ -0,0 +1,67 @@
1
+ import type { Diagnostic } from "@backtickjs/compiler";
2
+ import { virtualize } from "@backtickjs/compiler";
3
+ import type { CodeMapping, VirtualCode } from "@volar/language-core";
4
+ import type ts from "typescript";
5
+
6
+ export class BacktickVirtualCode implements VirtualCode {
7
+ id = "backtick-source";
8
+ languageId: string;
9
+ mappings: CodeMapping[];
10
+ snapshot: ts.IScriptSnapshot;
11
+ embeddedCodes: VirtualCode[];
12
+ diagnostics: Diagnostic[];
13
+
14
+ constructor(
15
+ ts: typeof import("typescript"),
16
+ fileName: string,
17
+ languageId: string,
18
+ snapshot: ts.IScriptSnapshot,
19
+ ) {
20
+ const sourceText = snapshot.getText(0, snapshot.getLength());
21
+ const { virtualCode, mappings, diagnostics } = virtualize(
22
+ ts,
23
+ fileName,
24
+ sourceText,
25
+ );
26
+
27
+ this.languageId = languageId;
28
+ this.diagnostics = diagnostics;
29
+
30
+ this.snapshot = snapshot;
31
+ this.mappings = [
32
+ {
33
+ sourceOffsets: [0],
34
+ generatedOffsets: [0],
35
+ lengths: [sourceText.length],
36
+ data: { format: false, verification: true },
37
+ },
38
+ ];
39
+
40
+ this.embeddedCodes = [
41
+ {
42
+ id: "backtick-virtual",
43
+ languageId,
44
+ snapshot: {
45
+ getText: (start, end) => virtualCode.substring(start, end),
46
+ getLength: () => virtualCode.length,
47
+ getChangeRange: () => undefined,
48
+ },
49
+ mappings: mappings.map((mapping) => ({
50
+ ...mapping,
51
+ // The compiler's own flags (e.g. `semantic: false` on a
52
+ // `cs.splice(...)` wrapper, so hover doesn't resolve through it)
53
+ // override the defaults.
54
+ data: {
55
+ completion: true,
56
+ format: false,
57
+ navigation: true,
58
+ semantic: true,
59
+ structure: true,
60
+ verification: true,
61
+ ...mapping.data,
62
+ },
63
+ })),
64
+ },
65
+ ];
66
+ }
67
+ }
@@ -0,0 +1,69 @@
1
+ /// <reference types="@volar/typescript" />
2
+ import type { LanguagePlugin } from "@volar/language-core";
3
+ import type ts from "typescript";
4
+ import { BacktickVirtualCode } from "./BacktickVirtualCode.js";
5
+
6
+ export function getBacktickLanguagePlugin<T>(
7
+ ts: typeof import("typescript"),
8
+ getFileName: (uri: T) => string,
9
+ ): LanguagePlugin<T, BacktickVirtualCode> {
10
+ return {
11
+ getLanguageId() {
12
+ // Keep as-is
13
+ },
14
+ createVirtualCode(uri, languageId, snapshot) {
15
+ switch (languageId) {
16
+ case "javascript":
17
+ case "javascriptreact":
18
+ case "typescript":
19
+ case "typescriptreact": {
20
+ const fileName = getFileName(uri);
21
+ if (fileName.endsWith(".d.ts")) {
22
+ return;
23
+ }
24
+ return new BacktickVirtualCode(ts, fileName, languageId, snapshot);
25
+ }
26
+ default:
27
+ return;
28
+ }
29
+ },
30
+ typescript: {
31
+ extraFileExtensions: [],
32
+ getServiceScript(root) {
33
+ // TypeScript reads the compiled embedded code, not the source root.
34
+ const code = root.embeddedCodes?.[0];
35
+ if (!code) {
36
+ return;
37
+ }
38
+ switch (root.languageId) {
39
+ case "javascript":
40
+ return {
41
+ code,
42
+ extension: ".js",
43
+ scriptKind: 1 satisfies ts.ScriptKind.JS,
44
+ };
45
+ case "javascriptreact":
46
+ return {
47
+ code,
48
+ extension: ".jsx",
49
+ scriptKind: 2 satisfies ts.ScriptKind.JSX,
50
+ };
51
+ case "typescript":
52
+ return {
53
+ code,
54
+ extension: ".ts",
55
+ scriptKind: 3 satisfies ts.ScriptKind.TS,
56
+ };
57
+ case "typescriptreact":
58
+ return {
59
+ code,
60
+ extension: ".tsx",
61
+ scriptKind: 4 satisfies ts.ScriptKind.TSX,
62
+ };
63
+ default:
64
+ return;
65
+ }
66
+ },
67
+ },
68
+ };
69
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { BacktickVirtualCode } from "./BacktickVirtualCode.js";
2
+ export { getBacktickLanguagePlugin } from "./getBacktickLanguagePlugin.js";