@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 +210 -0
- package/dist/authored-input.cjs +11 -0
- package/dist/authored-input.cjs.map +1 -0
- package/dist/index.cjs +203906 -0
- package/dist/index.cjs.map +1 -0
- package/dist/shared/authored-input-QenSVW8t.cjs +325 -0
- package/dist/shared/authored-input-QenSVW8t.cjs.map +1 -0
- package/package.json +61 -0
- package/src/authored-input.d.ts +28 -0
- package/src/authored-input.js +236 -0
- package/src/index.d.ts +64 -0
- package/src/index.js +438 -0
- package/src/warnings.js +66 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var babelParser = require('@babel/parser');
|
|
4
|
+
var parser = require('@litsx/jsx-authoring/parser');
|
|
5
|
+
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var babelParser__namespace = /*#__PURE__*/_interopNamespaceDefault(babelParser);
|
|
24
|
+
|
|
25
|
+
function normalizeLocationNumber(value) {
|
|
26
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function normalizeLitsxWarning(warning, context = {}) {
|
|
30
|
+
const normalized = warning && typeof warning === "object" ? { ...warning } : {};
|
|
31
|
+
|
|
32
|
+
normalized.code =
|
|
33
|
+
(typeof normalized.code === "string" && normalized.code !== "") ||
|
|
34
|
+
(typeof normalized.code === "number" && Number.isFinite(normalized.code))
|
|
35
|
+
? normalized.code
|
|
36
|
+
: null;
|
|
37
|
+
normalized.message =
|
|
38
|
+
typeof normalized.message === "string" && normalized.message !== ""
|
|
39
|
+
? normalized.message
|
|
40
|
+
: "LitSX emitted a warning during compilation.";
|
|
41
|
+
normalized.filename =
|
|
42
|
+
typeof normalized.filename === "string" && normalized.filename !== ""
|
|
43
|
+
? normalized.filename
|
|
44
|
+
: typeof context.filename === "string" && context.filename !== ""
|
|
45
|
+
? context.filename
|
|
46
|
+
: null;
|
|
47
|
+
normalized.line = normalizeLocationNumber(normalized.line);
|
|
48
|
+
normalized.column = normalizeLocationNumber(normalized.column);
|
|
49
|
+
normalized.attributeName =
|
|
50
|
+
typeof normalized.attributeName === "string" && normalized.attributeName !== ""
|
|
51
|
+
? normalized.attributeName
|
|
52
|
+
: null;
|
|
53
|
+
normalized.tagName =
|
|
54
|
+
typeof normalized.tagName === "string" && normalized.tagName !== ""
|
|
55
|
+
? normalized.tagName
|
|
56
|
+
: null;
|
|
57
|
+
normalized.propName =
|
|
58
|
+
typeof normalized.propName === "string" && normalized.propName !== ""
|
|
59
|
+
? normalized.propName
|
|
60
|
+
: null;
|
|
61
|
+
|
|
62
|
+
return normalized;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function mergeLitsxWarnings(existingWarnings = [], additionalWarnings = [], context = {}) {
|
|
66
|
+
const merged = [];
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
|
|
69
|
+
for (const rawWarning of [...existingWarnings, ...additionalWarnings]) {
|
|
70
|
+
const warning = normalizeLitsxWarning(rawWarning, context);
|
|
71
|
+
const key = [
|
|
72
|
+
warning.code ?? "",
|
|
73
|
+
warning.attributeName ?? "",
|
|
74
|
+
warning.tagName ?? "",
|
|
75
|
+
warning.propName ?? "",
|
|
76
|
+
warning.line ?? "",
|
|
77
|
+
warning.column ?? "",
|
|
78
|
+
warning.message ?? "",
|
|
79
|
+
].join(":");
|
|
80
|
+
|
|
81
|
+
if (seen.has(key)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
seen.add(key);
|
|
86
|
+
merged.push(warning);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return merged;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function isNativeIntrinsicJsxName(nameNode) {
|
|
93
|
+
return nameNode?.type === "JSXIdentifier" && /^[a-z]/.test(nameNode.name);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function collectNativeClassNameWarnings(ast) {
|
|
97
|
+
const warnings = [];
|
|
98
|
+
|
|
99
|
+
function visit(node, currentTagName = null) {
|
|
100
|
+
if (!node || typeof node !== "object") {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let nextTagName = currentTagName;
|
|
105
|
+
if (node.type === "JSXOpeningElement" && isNativeIntrinsicJsxName(node.name)) {
|
|
106
|
+
nextTagName = node.name.name;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
node.type === "JSXAttribute" &&
|
|
111
|
+
nextTagName &&
|
|
112
|
+
node.name?.type === "JSXIdentifier" &&
|
|
113
|
+
node.name.name === "className"
|
|
114
|
+
) {
|
|
115
|
+
warnings.push({
|
|
116
|
+
code: "LITSX_NATIVE_CLASSNAME",
|
|
117
|
+
message:
|
|
118
|
+
'`className` is not native LitSX syntax. Use `class` in native LitSX, or add the React compatibility layer to rewrite `className`.',
|
|
119
|
+
attributeName: "className",
|
|
120
|
+
tagName: nextTagName,
|
|
121
|
+
line: node.name.loc?.start?.line ?? null,
|
|
122
|
+
column: node.name.loc?.start?.column ?? null,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
for (const value of Object.values(node)) {
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
value.forEach((child) => visit(child, nextTagName));
|
|
129
|
+
} else {
|
|
130
|
+
visit(value, nextTagName);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
visit(ast.program ?? ast, null);
|
|
136
|
+
return warnings;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function collectReactMemoWarnings(ast) {
|
|
140
|
+
const warnings = [];
|
|
141
|
+
const reactMemoLocalNames = new Set();
|
|
142
|
+
const reactNamespaceNames = new Set();
|
|
143
|
+
|
|
144
|
+
const body = ast?.program?.body ?? ast?.body ?? [];
|
|
145
|
+
for (const node of body) {
|
|
146
|
+
if (node?.type !== "ImportDeclaration" || node.source?.value !== "react") {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (const specifier of node.specifiers || []) {
|
|
151
|
+
if (
|
|
152
|
+
specifier?.type === "ImportSpecifier" &&
|
|
153
|
+
specifier.imported?.type === "Identifier" &&
|
|
154
|
+
specifier.imported.name === "memo" &&
|
|
155
|
+
specifier.local?.type === "Identifier"
|
|
156
|
+
) {
|
|
157
|
+
reactMemoLocalNames.add(specifier.local.name);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
(specifier?.type === "ImportDefaultSpecifier" ||
|
|
162
|
+
specifier?.type === "ImportNamespaceSpecifier") &&
|
|
163
|
+
specifier.local?.type === "Identifier"
|
|
164
|
+
) {
|
|
165
|
+
reactNamespaceNames.add(specifier.local.name);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function addMemoWarnings(node) {
|
|
171
|
+
const line = node.loc?.start?.line ?? null;
|
|
172
|
+
const column = node.loc?.start?.column ?? null;
|
|
173
|
+
|
|
174
|
+
warnings.push({
|
|
175
|
+
code: 91016,
|
|
176
|
+
message:
|
|
177
|
+
"`memo(...)` is removed during LitSX lowering. LitSX does not use React-style parent re-render bailout semantics, so `memo` is treated as a migration wrapper only.",
|
|
178
|
+
line,
|
|
179
|
+
column,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if ((node.arguments || []).length > 1) {
|
|
183
|
+
warnings.push({
|
|
184
|
+
code: 91017,
|
|
185
|
+
message:
|
|
186
|
+
"`memo(Component, areEqual)` ignores the comparator during LitSX lowering because LitSX does not use React-style parent re-render bailout semantics.",
|
|
187
|
+
line,
|
|
188
|
+
column,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function visit(node) {
|
|
194
|
+
if (!node || typeof node !== "object") {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (node.type === "CallExpression") {
|
|
199
|
+
const callee = node.callee;
|
|
200
|
+
const isImportedMemo =
|
|
201
|
+
callee?.type === "Identifier" && reactMemoLocalNames.has(callee.name);
|
|
202
|
+
const isNamespacedMemo =
|
|
203
|
+
callee?.type === "MemberExpression" &&
|
|
204
|
+
callee.computed === false &&
|
|
205
|
+
callee.object?.type === "Identifier" &&
|
|
206
|
+
reactNamespaceNames.has(callee.object.name) &&
|
|
207
|
+
callee.property?.type === "Identifier" &&
|
|
208
|
+
callee.property.name === "memo";
|
|
209
|
+
|
|
210
|
+
if (isImportedMemo || isNamespacedMemo) {
|
|
211
|
+
addMemoWarnings(node);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
for (const value of Object.values(node)) {
|
|
216
|
+
if (Array.isArray(value)) {
|
|
217
|
+
value.forEach((child) => visit(child));
|
|
218
|
+
} else {
|
|
219
|
+
visit(value);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
visit(ast.program ?? ast);
|
|
225
|
+
return warnings;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function normalizeParserPlugins(filename, parserPlugins = []) {
|
|
229
|
+
if (Array.isArray(parserPlugins) && parserPlugins.length > 0) {
|
|
230
|
+
return parserPlugins;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (typeof filename === "string" && (
|
|
234
|
+
filename.endsWith(".tsx") ||
|
|
235
|
+
filename.endsWith(".litsx")
|
|
236
|
+
)) {
|
|
237
|
+
return ["typescript"];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function normalizePluginList(plugins) {
|
|
244
|
+
return Array.isArray(plugins) ? plugins : [];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function ensureLitsxParserPlugins(filename, parserPlugins = [], { requireJsx = false } = {}) {
|
|
248
|
+
const normalized = normalizeParserPlugins(filename, parserPlugins);
|
|
249
|
+
if (!requireJsx) {
|
|
250
|
+
return normalized;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const hasJsx = normalized.some((plugin) => {
|
|
254
|
+
if (typeof plugin === "string") {
|
|
255
|
+
return plugin === "jsx";
|
|
256
|
+
}
|
|
257
|
+
return Array.isArray(plugin) && plugin[0] === "jsx";
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
return hasJsx ? normalized : [...normalized, "jsx"];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function prepareLitsxAuthoredInput(
|
|
264
|
+
source,
|
|
265
|
+
options = {},
|
|
266
|
+
runtime = {}
|
|
267
|
+
) {
|
|
268
|
+
const runtimeImpl = {
|
|
269
|
+
parse: babelParser__namespace.parse,
|
|
270
|
+
transformFromAstSync: null,
|
|
271
|
+
...runtime,
|
|
272
|
+
};
|
|
273
|
+
const filename = options.filename;
|
|
274
|
+
const sourceMaps = options.sourceMaps === true;
|
|
275
|
+
const parserPlugins = ensureLitsxParserPlugins(filename, options.parserPlugins, {
|
|
276
|
+
requireJsx: options.requireJsx === true,
|
|
277
|
+
});
|
|
278
|
+
const virtualizedAst = parser.parseWithLitsxVirtualization(runtimeImpl.parse, source, {
|
|
279
|
+
sourceType: "module",
|
|
280
|
+
plugins: parserPlugins,
|
|
281
|
+
sourceFileName: filename,
|
|
282
|
+
litsxSourceMap: sourceMaps,
|
|
283
|
+
});
|
|
284
|
+
const virtualization = parser.getLitsxVirtualizationMetadata(virtualizedAst);
|
|
285
|
+
const authoredWarnings = mergeLitsxWarnings(
|
|
286
|
+
collectNativeClassNameWarnings(virtualizedAst),
|
|
287
|
+
collectReactMemoWarnings(virtualizedAst),
|
|
288
|
+
{ filename }
|
|
289
|
+
);
|
|
290
|
+
const authoringPlugins = normalizePluginList(options.authoringPlugins);
|
|
291
|
+
|
|
292
|
+
let inputAst = virtualizedAst;
|
|
293
|
+
if (authoringPlugins.length > 0) {
|
|
294
|
+
if (typeof runtimeImpl.transformFromAstSync !== "function") {
|
|
295
|
+
throw new Error(
|
|
296
|
+
"prepareLitsxAuthoredInput(...) requires runtime.transformFromAstSync when authoringPlugins are provided."
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const authoringPass = runtimeImpl.transformFromAstSync(virtualizedAst, source, {
|
|
301
|
+
filename,
|
|
302
|
+
sourceFileName: filename,
|
|
303
|
+
configFile: false,
|
|
304
|
+
babelrc: false,
|
|
305
|
+
ast: true,
|
|
306
|
+
code: false,
|
|
307
|
+
sourceMaps: false,
|
|
308
|
+
plugins: authoringPlugins,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
inputAst = authoringPass?.ast ?? virtualizedAst;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
filename,
|
|
316
|
+
virtualization,
|
|
317
|
+
inputAst,
|
|
318
|
+
authoredWarnings,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
exports.ensureLitsxParserPlugins = ensureLitsxParserPlugins;
|
|
323
|
+
exports.mergeLitsxWarnings = mergeLitsxWarnings;
|
|
324
|
+
exports.prepareLitsxAuthoredInput = prepareLitsxAuthoredInput;
|
|
325
|
+
//# sourceMappingURL=authored-input-QenSVW8t.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authored-input-QenSVW8t.cjs","sources":["../../src/warnings.js","../../src/authored-input.js"],"sourcesContent":["function normalizeLocationNumber(value) {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null;\n}\n\nexport function normalizeLitsxWarning(warning, context = {}) {\n const normalized = warning && typeof warning === \"object\" ? { ...warning } : {};\n\n normalized.code =\n (typeof normalized.code === \"string\" && normalized.code !== \"\") ||\n (typeof normalized.code === \"number\" && Number.isFinite(normalized.code))\n ? normalized.code\n : null;\n normalized.message =\n typeof normalized.message === \"string\" && normalized.message !== \"\"\n ? normalized.message\n : \"LitSX emitted a warning during compilation.\";\n normalized.filename =\n typeof normalized.filename === \"string\" && normalized.filename !== \"\"\n ? normalized.filename\n : typeof context.filename === \"string\" && context.filename !== \"\"\n ? context.filename\n : null;\n normalized.line = normalizeLocationNumber(normalized.line);\n normalized.column = normalizeLocationNumber(normalized.column);\n normalized.attributeName =\n typeof normalized.attributeName === \"string\" && normalized.attributeName !== \"\"\n ? normalized.attributeName\n : null;\n normalized.tagName =\n typeof normalized.tagName === \"string\" && normalized.tagName !== \"\"\n ? normalized.tagName\n : null;\n normalized.propName =\n typeof normalized.propName === \"string\" && normalized.propName !== \"\"\n ? normalized.propName\n : null;\n\n return normalized;\n}\n\nexport function mergeLitsxWarnings(existingWarnings = [], additionalWarnings = [], context = {}) {\n const merged = [];\n const seen = new Set();\n\n for (const rawWarning of [...existingWarnings, ...additionalWarnings]) {\n const warning = normalizeLitsxWarning(rawWarning, context);\n const key = [\n warning.code ?? \"\",\n warning.attributeName ?? \"\",\n warning.tagName ?? \"\",\n warning.propName ?? \"\",\n warning.line ?? \"\",\n warning.column ?? \"\",\n warning.message ?? \"\",\n ].join(\":\");\n\n if (seen.has(key)) {\n continue;\n }\n\n seen.add(key);\n merged.push(warning);\n }\n\n return merged;\n}\n","import * as babelParser from \"@babel/parser\";\nimport {\n getLitsxVirtualizationMetadata,\n parseWithLitsxVirtualization,\n} from \"@litsx/jsx-authoring/parser\";\nimport { mergeLitsxWarnings } from \"./warnings.js\";\n\nfunction isNativeIntrinsicJsxName(nameNode) {\n return nameNode?.type === \"JSXIdentifier\" && /^[a-z]/.test(nameNode.name);\n}\n\nfunction collectNativeClassNameWarnings(ast) {\n const warnings = [];\n\n function visit(node, currentTagName = null) {\n if (!node || typeof node !== \"object\") {\n return;\n }\n\n let nextTagName = currentTagName;\n if (node.type === \"JSXOpeningElement\" && isNativeIntrinsicJsxName(node.name)) {\n nextTagName = node.name.name;\n }\n\n if (\n node.type === \"JSXAttribute\" &&\n nextTagName &&\n node.name?.type === \"JSXIdentifier\" &&\n node.name.name === \"className\"\n ) {\n warnings.push({\n code: \"LITSX_NATIVE_CLASSNAME\",\n message:\n '`className` is not native LitSX syntax. Use `class` in native LitSX, or add the React compatibility layer to rewrite `className`.',\n attributeName: \"className\",\n tagName: nextTagName,\n line: node.name.loc?.start?.line ?? null,\n column: node.name.loc?.start?.column ?? null,\n });\n }\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n value.forEach((child) => visit(child, nextTagName));\n } else {\n visit(value, nextTagName);\n }\n }\n }\n\n visit(ast.program ?? ast, null);\n return warnings;\n}\n\nfunction collectReactMemoWarnings(ast) {\n const warnings = [];\n const reactMemoLocalNames = new Set();\n const reactNamespaceNames = new Set();\n\n const body = ast?.program?.body ?? ast?.body ?? [];\n for (const node of body) {\n if (node?.type !== \"ImportDeclaration\" || node.source?.value !== \"react\") {\n continue;\n }\n\n for (const specifier of node.specifiers || []) {\n if (\n specifier?.type === \"ImportSpecifier\" &&\n specifier.imported?.type === \"Identifier\" &&\n specifier.imported.name === \"memo\" &&\n specifier.local?.type === \"Identifier\"\n ) {\n reactMemoLocalNames.add(specifier.local.name);\n }\n\n if (\n (specifier?.type === \"ImportDefaultSpecifier\" ||\n specifier?.type === \"ImportNamespaceSpecifier\") &&\n specifier.local?.type === \"Identifier\"\n ) {\n reactNamespaceNames.add(specifier.local.name);\n }\n }\n }\n\n function addMemoWarnings(node) {\n const line = node.loc?.start?.line ?? null;\n const column = node.loc?.start?.column ?? null;\n\n warnings.push({\n code: 91016,\n message:\n \"`memo(...)` is removed during LitSX lowering. LitSX does not use React-style parent re-render bailout semantics, so `memo` is treated as a migration wrapper only.\",\n line,\n column,\n });\n\n if ((node.arguments || []).length > 1) {\n warnings.push({\n code: 91017,\n message:\n \"`memo(Component, areEqual)` ignores the comparator during LitSX lowering because LitSX does not use React-style parent re-render bailout semantics.\",\n line,\n column,\n });\n }\n }\n\n function visit(node) {\n if (!node || typeof node !== \"object\") {\n return;\n }\n\n if (node.type === \"CallExpression\") {\n const callee = node.callee;\n const isImportedMemo =\n callee?.type === \"Identifier\" && reactMemoLocalNames.has(callee.name);\n const isNamespacedMemo =\n callee?.type === \"MemberExpression\" &&\n callee.computed === false &&\n callee.object?.type === \"Identifier\" &&\n reactNamespaceNames.has(callee.object.name) &&\n callee.property?.type === \"Identifier\" &&\n callee.property.name === \"memo\";\n\n if (isImportedMemo || isNamespacedMemo) {\n addMemoWarnings(node);\n }\n }\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n value.forEach((child) => visit(child));\n } else {\n visit(value);\n }\n }\n }\n\n visit(ast.program ?? ast);\n return warnings;\n}\n\nfunction normalizeParserPlugins(filename, parserPlugins = []) {\n if (Array.isArray(parserPlugins) && parserPlugins.length > 0) {\n return parserPlugins;\n }\n\n if (typeof filename === \"string\" && (\n filename.endsWith(\".tsx\") ||\n filename.endsWith(\".litsx\")\n )) {\n return [\"typescript\"];\n }\n\n return [];\n}\n\nfunction normalizePluginList(plugins) {\n return Array.isArray(plugins) ? plugins : [];\n}\n\nexport function ensureLitsxParserPlugins(filename, parserPlugins = [], { requireJsx = false } = {}) {\n const normalized = normalizeParserPlugins(filename, parserPlugins);\n if (!requireJsx) {\n return normalized;\n }\n\n const hasJsx = normalized.some((plugin) => {\n if (typeof plugin === \"string\") {\n return plugin === \"jsx\";\n }\n return Array.isArray(plugin) && plugin[0] === \"jsx\";\n });\n\n return hasJsx ? normalized : [...normalized, \"jsx\"];\n}\n\nexport function prepareLitsxAuthoredInput(\n source,\n options = {},\n runtime = {}\n) {\n const runtimeImpl = {\n parse: babelParser.parse,\n transformFromAstSync: null,\n ...runtime,\n };\n const filename = options.filename;\n const sourceMaps = options.sourceMaps === true;\n const parserPlugins = ensureLitsxParserPlugins(filename, options.parserPlugins, {\n requireJsx: options.requireJsx === true,\n });\n const virtualizedAst = parseWithLitsxVirtualization(runtimeImpl.parse, source, {\n sourceType: \"module\",\n plugins: parserPlugins,\n sourceFileName: filename,\n litsxSourceMap: sourceMaps,\n });\n const virtualization = getLitsxVirtualizationMetadata(virtualizedAst);\n const authoredWarnings = mergeLitsxWarnings(\n collectNativeClassNameWarnings(virtualizedAst),\n collectReactMemoWarnings(virtualizedAst),\n { filename }\n );\n const authoringPlugins = normalizePluginList(options.authoringPlugins);\n\n let inputAst = virtualizedAst;\n if (authoringPlugins.length > 0) {\n if (typeof runtimeImpl.transformFromAstSync !== \"function\") {\n throw new Error(\n \"prepareLitsxAuthoredInput(...) requires runtime.transformFromAstSync when authoringPlugins are provided.\"\n );\n }\n\n const authoringPass = runtimeImpl.transformFromAstSync(virtualizedAst, source, {\n filename,\n sourceFileName: filename,\n configFile: false,\n babelrc: false,\n ast: true,\n code: false,\n sourceMaps: false,\n plugins: authoringPlugins,\n });\n\n inputAst = authoringPass?.ast ?? virtualizedAst;\n }\n\n return {\n filename,\n virtualization,\n inputAst,\n authoredWarnings,\n };\n}\n"],"names":["babelParser","parseWithLitsxVirtualization","getLitsxVirtualizationMetadata"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB,CAAC,KAAK,EAAE;AACxC,EAAE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI;AAC3E;;AAEO,SAAS,qBAAqB,CAAC,OAAO,EA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AAC/B,KAAK,CAAC;;AAEN,IAAI,QAAQ,GAAG,aAAa,EAAE,GAAG,IAAI,cAAc;AACnD,EAAE;;AAEF,EAAE,OAAO;AACT,IAAI,QAAQ;AACZ,IAAI,cAAc;AAClB,IAAI,QAAQ;AACZ,IAAI,gBAAgB;AACpB,GAAG;AACH;;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@litsx/compiler",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Build-facing LitSX compilation facade with correct parser and sourcemap handling",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./src/index.js",
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.d.ts",
|
|
12
|
+
"import": "./src/index.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./src/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./authored-input": {
|
|
17
|
+
"types": "./src/authored-input.d.ts",
|
|
18
|
+
"import": "./src/authored-input.js",
|
|
19
|
+
"require": "./dist/authored-input.cjs",
|
|
20
|
+
"default": "./src/authored-input.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"litsx",
|
|
30
|
+
"compiler",
|
|
31
|
+
"babel",
|
|
32
|
+
"vite",
|
|
33
|
+
"jsx"
|
|
34
|
+
],
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"homepage": "https://github.com/litsxdev/litsx/tree/main/packages/compiler",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/litsxdev/litsx/issues"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/litsxdev/litsx.git",
|
|
47
|
+
"directory": "packages/compiler"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@babel/core": "^7.29.0",
|
|
51
|
+
"@babel/parser": "^7.29.3",
|
|
52
|
+
"@litsx/babel-plugin-transform-jsx-html-template": "workspace:^",
|
|
53
|
+
"@litsx/babel-preset-litsx": "workspace:^",
|
|
54
|
+
"@litsx/jsx-authoring": "workspace:^",
|
|
55
|
+
"@litsx/typescript-session": "workspace:^"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "../../node_modules/.bin/rollup --config rollup.config.mjs",
|
|
59
|
+
"prepack": "yarn build"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function ensureLitsxParserPlugins(
|
|
2
|
+
filename?: string,
|
|
3
|
+
parserPlugins?: string[],
|
|
4
|
+
options?: { requireJsx?: boolean }
|
|
5
|
+
): string[];
|
|
6
|
+
|
|
7
|
+
export function prepareLitsxAuthoredInput(
|
|
8
|
+
source: string,
|
|
9
|
+
options?: {
|
|
10
|
+
filename?: string;
|
|
11
|
+
parserPlugins?: string[];
|
|
12
|
+
sourceMaps?: boolean;
|
|
13
|
+
authoringPlugins?: unknown[];
|
|
14
|
+
requireJsx?: boolean;
|
|
15
|
+
},
|
|
16
|
+
runtime?: {
|
|
17
|
+
parse: (...args: unknown[]) => object;
|
|
18
|
+
transformFromAstSync?: (...args: unknown[]) => { ast?: object } | null | undefined;
|
|
19
|
+
}
|
|
20
|
+
): {
|
|
21
|
+
filename?: string;
|
|
22
|
+
virtualization: {
|
|
23
|
+
code?: string;
|
|
24
|
+
map?: object | null;
|
|
25
|
+
} | null;
|
|
26
|
+
inputAst: object;
|
|
27
|
+
authoredWarnings: unknown[];
|
|
28
|
+
};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import * as babelParser from "@babel/parser";
|
|
2
|
+
import {
|
|
3
|
+
getLitsxVirtualizationMetadata,
|
|
4
|
+
parseWithLitsxVirtualization,
|
|
5
|
+
} from "@litsx/jsx-authoring/parser";
|
|
6
|
+
import { mergeLitsxWarnings } from "./warnings.js";
|
|
7
|
+
|
|
8
|
+
function isNativeIntrinsicJsxName(nameNode) {
|
|
9
|
+
return nameNode?.type === "JSXIdentifier" && /^[a-z]/.test(nameNode.name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function collectNativeClassNameWarnings(ast) {
|
|
13
|
+
const warnings = [];
|
|
14
|
+
|
|
15
|
+
function visit(node, currentTagName = null) {
|
|
16
|
+
if (!node || typeof node !== "object") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let nextTagName = currentTagName;
|
|
21
|
+
if (node.type === "JSXOpeningElement" && isNativeIntrinsicJsxName(node.name)) {
|
|
22
|
+
nextTagName = node.name.name;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
node.type === "JSXAttribute" &&
|
|
27
|
+
nextTagName &&
|
|
28
|
+
node.name?.type === "JSXIdentifier" &&
|
|
29
|
+
node.name.name === "className"
|
|
30
|
+
) {
|
|
31
|
+
warnings.push({
|
|
32
|
+
code: "LITSX_NATIVE_CLASSNAME",
|
|
33
|
+
message:
|
|
34
|
+
'`className` is not native LitSX syntax. Use `class` in native LitSX, or add the React compatibility layer to rewrite `className`.',
|
|
35
|
+
attributeName: "className",
|
|
36
|
+
tagName: nextTagName,
|
|
37
|
+
line: node.name.loc?.start?.line ?? null,
|
|
38
|
+
column: node.name.loc?.start?.column ?? null,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
for (const value of Object.values(node)) {
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
value.forEach((child) => visit(child, nextTagName));
|
|
45
|
+
} else {
|
|
46
|
+
visit(value, nextTagName);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
visit(ast.program ?? ast, null);
|
|
52
|
+
return warnings;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function collectReactMemoWarnings(ast) {
|
|
56
|
+
const warnings = [];
|
|
57
|
+
const reactMemoLocalNames = new Set();
|
|
58
|
+
const reactNamespaceNames = new Set();
|
|
59
|
+
|
|
60
|
+
const body = ast?.program?.body ?? ast?.body ?? [];
|
|
61
|
+
for (const node of body) {
|
|
62
|
+
if (node?.type !== "ImportDeclaration" || node.source?.value !== "react") {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const specifier of node.specifiers || []) {
|
|
67
|
+
if (
|
|
68
|
+
specifier?.type === "ImportSpecifier" &&
|
|
69
|
+
specifier.imported?.type === "Identifier" &&
|
|
70
|
+
specifier.imported.name === "memo" &&
|
|
71
|
+
specifier.local?.type === "Identifier"
|
|
72
|
+
) {
|
|
73
|
+
reactMemoLocalNames.add(specifier.local.name);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (
|
|
77
|
+
(specifier?.type === "ImportDefaultSpecifier" ||
|
|
78
|
+
specifier?.type === "ImportNamespaceSpecifier") &&
|
|
79
|
+
specifier.local?.type === "Identifier"
|
|
80
|
+
) {
|
|
81
|
+
reactNamespaceNames.add(specifier.local.name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function addMemoWarnings(node) {
|
|
87
|
+
const line = node.loc?.start?.line ?? null;
|
|
88
|
+
const column = node.loc?.start?.column ?? null;
|
|
89
|
+
|
|
90
|
+
warnings.push({
|
|
91
|
+
code: 91016,
|
|
92
|
+
message:
|
|
93
|
+
"`memo(...)` is removed during LitSX lowering. LitSX does not use React-style parent re-render bailout semantics, so `memo` is treated as a migration wrapper only.",
|
|
94
|
+
line,
|
|
95
|
+
column,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if ((node.arguments || []).length > 1) {
|
|
99
|
+
warnings.push({
|
|
100
|
+
code: 91017,
|
|
101
|
+
message:
|
|
102
|
+
"`memo(Component, areEqual)` ignores the comparator during LitSX lowering because LitSX does not use React-style parent re-render bailout semantics.",
|
|
103
|
+
line,
|
|
104
|
+
column,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function visit(node) {
|
|
110
|
+
if (!node || typeof node !== "object") {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (node.type === "CallExpression") {
|
|
115
|
+
const callee = node.callee;
|
|
116
|
+
const isImportedMemo =
|
|
117
|
+
callee?.type === "Identifier" && reactMemoLocalNames.has(callee.name);
|
|
118
|
+
const isNamespacedMemo =
|
|
119
|
+
callee?.type === "MemberExpression" &&
|
|
120
|
+
callee.computed === false &&
|
|
121
|
+
callee.object?.type === "Identifier" &&
|
|
122
|
+
reactNamespaceNames.has(callee.object.name) &&
|
|
123
|
+
callee.property?.type === "Identifier" &&
|
|
124
|
+
callee.property.name === "memo";
|
|
125
|
+
|
|
126
|
+
if (isImportedMemo || isNamespacedMemo) {
|
|
127
|
+
addMemoWarnings(node);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const value of Object.values(node)) {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
value.forEach((child) => visit(child));
|
|
134
|
+
} else {
|
|
135
|
+
visit(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
visit(ast.program ?? ast);
|
|
141
|
+
return warnings;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function normalizeParserPlugins(filename, parserPlugins = []) {
|
|
145
|
+
if (Array.isArray(parserPlugins) && parserPlugins.length > 0) {
|
|
146
|
+
return parserPlugins;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (typeof filename === "string" && (
|
|
150
|
+
filename.endsWith(".tsx") ||
|
|
151
|
+
filename.endsWith(".litsx")
|
|
152
|
+
)) {
|
|
153
|
+
return ["typescript"];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function normalizePluginList(plugins) {
|
|
160
|
+
return Array.isArray(plugins) ? plugins : [];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function ensureLitsxParserPlugins(filename, parserPlugins = [], { requireJsx = false } = {}) {
|
|
164
|
+
const normalized = normalizeParserPlugins(filename, parserPlugins);
|
|
165
|
+
if (!requireJsx) {
|
|
166
|
+
return normalized;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const hasJsx = normalized.some((plugin) => {
|
|
170
|
+
if (typeof plugin === "string") {
|
|
171
|
+
return plugin === "jsx";
|
|
172
|
+
}
|
|
173
|
+
return Array.isArray(plugin) && plugin[0] === "jsx";
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return hasJsx ? normalized : [...normalized, "jsx"];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function prepareLitsxAuthoredInput(
|
|
180
|
+
source,
|
|
181
|
+
options = {},
|
|
182
|
+
runtime = {}
|
|
183
|
+
) {
|
|
184
|
+
const runtimeImpl = {
|
|
185
|
+
parse: babelParser.parse,
|
|
186
|
+
transformFromAstSync: null,
|
|
187
|
+
...runtime,
|
|
188
|
+
};
|
|
189
|
+
const filename = options.filename;
|
|
190
|
+
const sourceMaps = options.sourceMaps === true;
|
|
191
|
+
const parserPlugins = ensureLitsxParserPlugins(filename, options.parserPlugins, {
|
|
192
|
+
requireJsx: options.requireJsx === true,
|
|
193
|
+
});
|
|
194
|
+
const virtualizedAst = parseWithLitsxVirtualization(runtimeImpl.parse, source, {
|
|
195
|
+
sourceType: "module",
|
|
196
|
+
plugins: parserPlugins,
|
|
197
|
+
sourceFileName: filename,
|
|
198
|
+
litsxSourceMap: sourceMaps,
|
|
199
|
+
});
|
|
200
|
+
const virtualization = getLitsxVirtualizationMetadata(virtualizedAst);
|
|
201
|
+
const authoredWarnings = mergeLitsxWarnings(
|
|
202
|
+
collectNativeClassNameWarnings(virtualizedAst),
|
|
203
|
+
collectReactMemoWarnings(virtualizedAst),
|
|
204
|
+
{ filename }
|
|
205
|
+
);
|
|
206
|
+
const authoringPlugins = normalizePluginList(options.authoringPlugins);
|
|
207
|
+
|
|
208
|
+
let inputAst = virtualizedAst;
|
|
209
|
+
if (authoringPlugins.length > 0) {
|
|
210
|
+
if (typeof runtimeImpl.transformFromAstSync !== "function") {
|
|
211
|
+
throw new Error(
|
|
212
|
+
"prepareLitsxAuthoredInput(...) requires runtime.transformFromAstSync when authoringPlugins are provided."
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const authoringPass = runtimeImpl.transformFromAstSync(virtualizedAst, source, {
|
|
217
|
+
filename,
|
|
218
|
+
sourceFileName: filename,
|
|
219
|
+
configFile: false,
|
|
220
|
+
babelrc: false,
|
|
221
|
+
ast: true,
|
|
222
|
+
code: false,
|
|
223
|
+
sourceMaps: false,
|
|
224
|
+
plugins: authoringPlugins,
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
inputAst = authoringPass?.ast ?? virtualizedAst;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
filename,
|
|
232
|
+
virtualization,
|
|
233
|
+
inputAst,
|
|
234
|
+
authoredWarnings,
|
|
235
|
+
};
|
|
236
|
+
}
|