@litsx/compiler 0.1.0

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/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # `@litsx/compiler`
2
+
3
+ [![npm](https://img.shields.io/badge/npm-@litsx%2Fcompiler-CB3837)](https://www.npmjs.com/package/@litsx/compiler)
4
+ [![Release](https://img.shields.io/badge/release-public-2ea44f)](../../RELEASING.md)
5
+ [![Module](https://img.shields.io/badge/module-ESM%20%2B%20CJS-0366d6)](./package.json)
6
+ [![Provenance](https://img.shields.io/badge/npm_provenance-enabled-2ea44f)](../../RELEASING.md)
7
+
8
+ Build-facing LitSX compilation facade.
9
+
10
+ Use this package when you need to compile authored LitSX source programmatically and want the correct compilation pipeline applied by default:
11
+
12
+ - LitSX-authored source virtualization and AST remapping
13
+ - LitSX Babel transforms in the supported order
14
+ - virtualization sourcemap chaining
15
+ - final Lit template sourcemap patching
16
+
17
+ For Vite apps and Storybook setups using the Vite builder, prefer [`@litsx/vite-plugin`](../vite-plugin/README.md).
18
+
19
+ For raw Babel-native integration without the compiler facade, prefer [`@litsx/babel-preset-litsx`](../babel-preset-litsx/README.md).
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @litsx/compiler
25
+ ```
26
+
27
+ Typical consumers also need the runtime packages used by their compiled output, such as `lit`, `litsx`, and `@open-wc/scoped-elements`, depending on which LitSX features they use.
28
+
29
+ ## What It Solves
30
+
31
+ LitSX authored JSX is not plain JSX. The compilation path needs to handle:
32
+
33
+ - Lit-style attributes such as `@click`, `.value`, and `?disabled`
34
+ - LitSX macros and authored syntax that are virtualized before parsing
35
+ - Babel plugin ordering
36
+ - sourcemap composition across virtualization and template lowering
37
+
38
+ You can wire those pieces together manually, but this package exists so callers do not need to know about:
39
+
40
+ - `getLitsxVirtualizationMetadata(...)`
41
+ - `inputSourceMap` chaining
42
+ - `patchLitAttributeSourcemap(...)`
43
+
44
+ If you do want to wire Babel directly, `@litsx/babel-preset-litsx` is the canonical source of truth for the native LitSX plugin order.
45
+
46
+ For advanced integrations that need to share LitSX virtualization and authored-input preparation without using the full compiler facade, `@litsx/compiler` also exports low-level helpers such as `prepareLitsxAuthoredInput(...)` and `ensureLitsxParserPlugins(...)`.
47
+
48
+ ## Basic Usage
49
+
50
+ ```js
51
+ import { transformLitsx } from "@litsx/compiler";
52
+
53
+ const source = `
54
+ export const Counter = ({ label = "Save" }) => {
55
+ return <button @click={save}>{label}</button>;
56
+ };
57
+ `;
58
+
59
+ const result = await transformLitsx(source, {
60
+ filename: "/src/Counter.jsx",
61
+ sourceMaps: true,
62
+ });
63
+
64
+ console.log(result.code);
65
+ console.log(result.map);
66
+ console.log(result.metadata);
67
+ ```
68
+
69
+ Synchronous usage is also available:
70
+
71
+ ```js
72
+ import { transformLitsxSync } from "@litsx/compiler";
73
+
74
+ const result = transformLitsxSync(source, {
75
+ filename: "/src/Counter.jsx",
76
+ });
77
+ ```
78
+
79
+ ## API
80
+
81
+ ### `transformLitsx(source, options?)`
82
+
83
+ Asynchronously compiles authored LitSX source and returns:
84
+
85
+ ```ts
86
+ type TransformLitsxResult = {
87
+ code: string;
88
+ map: object | null;
89
+ metadata: Record<string, unknown>;
90
+ };
91
+ ```
92
+
93
+ ### `transformLitsxSync(source, options?)`
94
+
95
+ Synchronous equivalent of `transformLitsx(...)`.
96
+
97
+ ## Options
98
+
99
+ ### `filename?: string`
100
+
101
+ Filename used for Babel metadata and sourcemaps. Provide this whenever possible.
102
+
103
+ ### `parserPlugins?: string[]`
104
+
105
+ Additional Babel parser plugins. If omitted, `.tsx` filenames automatically enable the `typescript` parser plugin.
106
+
107
+ ### `sourceMaps?: boolean`
108
+
109
+ When `true`, emits a final sourcemap aligned to the original authored source.
110
+
111
+ When `false` or omitted:
112
+
113
+ - `map` is `null`
114
+ - no sourcemap chaining work is performed
115
+
116
+ ### `jsxTemplate?: boolean`
117
+
118
+ Controls whether JSX is lowered to Lit template literals through `@litsx/babel-plugin-transform-jsx-html-template`.
119
+
120
+ Default: `true`
121
+
122
+ Set this to `false` only if you need the LitSX class/property transform stages without the final JSX-to-template lowering.
123
+
124
+ ### `jsxTemplateOptions?: object`
125
+
126
+ Options passed directly to `@litsx/babel-plugin-transform-jsx-html-template`.
127
+
128
+ Example:
129
+
130
+ ```js
131
+ const result = await transformLitsx(source, {
132
+ filename: "/src/icon.jsx",
133
+ jsxTemplateOptions: {
134
+ tag: "svg",
135
+ },
136
+ });
137
+ ```
138
+
139
+ ### `authoringPlugins?: unknown[]`
140
+
141
+ Additional Babel plugins applied after LitSX virtualization/parsing and before the built-in LitSX lowering pipeline.
142
+
143
+ Use this when you need to introduce extra authored syntax or conventions on top of LitSX source without patching the core preset ordering.
144
+
145
+ ### `outputPlugins?: unknown[]`
146
+
147
+ Additional Babel plugins appended after the default LitSX pipeline.
148
+
149
+ Use this for bounded, consumer-specific post-processing on already-lowered output. Do not use it to replace the core LitSX transforms.
150
+
151
+ ## Output Contract
152
+
153
+ The compiler always parses authored source through the standard Babel parser plus LitSX's virtualization/remap layer, and always applies the supported LitSX transform chain internally.
154
+
155
+ When `sourceMaps: true`, the returned map includes:
156
+
157
+ - the authored-to-virtual sourcemap from attribute virtualization
158
+ - the transform chain sourcemap from Babel
159
+ - the final patching needed for Lit-style attributes after JSX has been lowered to `html\`\``
160
+
161
+ `metadata` is the raw Babel metadata object from the transform run. It is returned for advanced integrations, but consumers should not depend on private LitSX metadata keys unless they control the full toolchain.
162
+
163
+ ## Example: Build Tool Integration
164
+
165
+ ```js
166
+ import { transformLitsx } from "@litsx/compiler";
167
+
168
+ export async function compile(id, source) {
169
+ if (!/\.(jsx|tsx)$/.test(id)) {
170
+ return null;
171
+ }
172
+
173
+ const result = await transformLitsx(source, {
174
+ filename: id,
175
+ sourceMaps: true,
176
+ });
177
+
178
+ return {
179
+ code: result.code,
180
+ map: result.map,
181
+ };
182
+ }
183
+ ```
184
+
185
+ ## Scope
186
+
187
+ This package is the low-level public facade for LitSX compilation.
188
+
189
+ It does not:
190
+
191
+ - provide a dev server
192
+ - register a Vite plugin by itself
193
+ - add non-Vite build system integrations
194
+
195
+ If you are integrating with Vite, the recommended entrypoint is `@litsx/vite-plugin`.
196
+
197
+ ## Versioning and Stability
198
+
199
+ `@litsx/compiler` is intended to be the stable public entrypoint for third-party build integration.
200
+
201
+ The canonical raw-Babel entrypoint for native authored source is:
202
+
203
+ - `@litsx/babel-preset-litsx`
204
+
205
+ Lower-level packages such as:
206
+
207
+ - `@litsx/babel-preset-litsx`
208
+ - `@litsx/babel-plugin-transform-jsx-html-template`
209
+
210
+ remain usable, but they expose more internal detail and require more setup knowledge.
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ require('@babel/parser');
4
+ require('@litsx/jsx-authoring/parser');
5
+ var authoredInput = require('./shared/authored-input-QenSVW8t.cjs');
6
+
7
+
8
+
9
+ exports.ensureLitsxParserPlugins = authoredInput.ensureLitsxParserPlugins;
10
+ exports.prepareLitsxAuthoredInput = authoredInput.prepareLitsxAuthoredInput;
11
+ //# sourceMappingURL=authored-input.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authored-input.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}