@reckona/mreact-compiler 0.0.97 → 0.0.99
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/dist/diagnostics.d.ts +1 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +8 -0
- package/dist/diagnostics.js.map +1 -1
- package/dist/emit-client.js +14 -9
- package/dist/emit-client.js.map +1 -1
- package/dist/emit-compat.js +5 -1
- package/dist/emit-compat.js.map +1 -1
- package/dist/emit-server-stream.js +52 -3
- package/dist/emit-server-stream.js.map +1 -1
- package/dist/emit-server.js +51 -10
- package/dist/emit-server.js.map +1 -1
- package/dist/ir.d.ts +1 -0
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js.map +1 -1
- package/dist/oxc-child-analysis.d.ts.map +1 -1
- package/dist/oxc-child-analysis.js +41 -7
- package/dist/oxc-child-analysis.js.map +1 -1
- package/dist/oxc-component-detection.d.ts +5 -2
- package/dist/oxc-component-detection.d.ts.map +1 -1
- package/dist/oxc-component-detection.js +80 -3
- package/dist/oxc-component-detection.js.map +1 -1
- package/dist/oxc-component-props.d.ts +1 -1
- package/dist/oxc-component-props.d.ts.map +1 -1
- package/dist/oxc-component-props.js +1 -1
- package/dist/oxc-component-props.js.map +1 -1
- package/dist/oxc-component-references.js +2 -2
- package/dist/oxc-component-references.js.map +1 -1
- package/dist/oxc-runtime-emit.d.ts.map +1 -1
- package/dist/oxc-runtime-emit.js +10 -2
- package/dist/oxc-runtime-emit.js.map +1 -1
- package/dist/oxc.d.ts.map +1 -1
- package/dist/oxc.js +109 -20
- package/dist/oxc.js.map +1 -1
- package/dist/transform.js +29 -11
- package/dist/transform.js.map +1 -1
- package/package.json +2 -2
- package/src/diagnostics.ts +10 -0
- package/src/emit-client.ts +20 -10
- package/src/emit-compat.ts +6 -1
- package/src/emit-server-stream.ts +67 -3
- package/src/emit-server.ts +64 -12
- package/src/ir.ts +1 -0
- package/src/oxc-child-analysis.ts +63 -18
- package/src/oxc-component-detection.ts +145 -2
- package/src/oxc-component-props.ts +2 -1
- package/src/oxc-component-references.ts +2 -2
- package/src/oxc-runtime-emit.ts +12 -2
- package/src/oxc.ts +167 -5
- package/src/transform.ts +42 -10
package/src/transform.ts
CHANGED
|
@@ -207,10 +207,11 @@ function createSegmentMappings(outputCode: string, sourceCode: string): Generate
|
|
|
207
207
|
let previousSourceLine = 0;
|
|
208
208
|
let previousSourceColumn = 0;
|
|
209
209
|
let previousNameIndex = 0;
|
|
210
|
+
const searchState: SourceMapSearchState = { tokenOffsets: new Map() };
|
|
210
211
|
|
|
211
212
|
for (const [lineIndex, generatedLine] of generatedLines.entries()) {
|
|
212
213
|
let previousGeneratedColumn = 0;
|
|
213
|
-
const segments = collectSourceMapSegments(generatedLine, lineIndex, sourceLines);
|
|
214
|
+
const segments = collectSourceMapSegments(generatedLine, lineIndex, sourceLines, searchState);
|
|
214
215
|
|
|
215
216
|
lines.push(
|
|
216
217
|
segments
|
|
@@ -249,10 +250,15 @@ interface SourceMapSegment {
|
|
|
249
250
|
name?: string;
|
|
250
251
|
}
|
|
251
252
|
|
|
253
|
+
interface SourceMapSearchState {
|
|
254
|
+
tokenOffsets: Map<string, number>;
|
|
255
|
+
}
|
|
256
|
+
|
|
252
257
|
function collectSourceMapSegments(
|
|
253
258
|
generatedLine: string,
|
|
254
259
|
generatedLineIndex: number,
|
|
255
260
|
sourceLines: readonly string[],
|
|
261
|
+
searchState: SourceMapSearchState,
|
|
256
262
|
): SourceMapSegment[] {
|
|
257
263
|
const fallbackSourceLine = findFallbackSourceLine(generatedLine, generatedLineIndex, sourceLines);
|
|
258
264
|
const segments: SourceMapSegment[] = [
|
|
@@ -315,12 +321,12 @@ function collectSourceMapSegments(
|
|
|
315
321
|
const sourceLocation =
|
|
316
322
|
bindPropAttribute === undefined
|
|
317
323
|
? undefined
|
|
318
|
-
: (findSourceLocation(sourceLines, `${bindPropAttribute}={${dynamicExpression}}
|
|
319
|
-
findSourceLocation(sourceLines, `${bindPropAttribute}="${dynamicExpression}"
|
|
324
|
+
: (findSourceLocation(sourceLines, `${bindPropAttribute}={${dynamicExpression}}`, searchState) ??
|
|
325
|
+
findSourceLocation(sourceLines, `${bindPropAttribute}="${dynamicExpression}"`, searchState));
|
|
320
326
|
const fallbackSourceLocation =
|
|
321
|
-
findSourceLocation(sourceLines, `{${dynamicExpression}}
|
|
327
|
+
findSourceLocation(sourceLines, `{${dynamicExpression}}`, searchState) ??
|
|
322
328
|
findJsxExpressionTokenLocation(sourceLines, dynamicExpression) ??
|
|
323
|
-
findSourceLocation(sourceLines, dynamicExpression);
|
|
329
|
+
findSourceLocation(sourceLines, dynamicExpression, searchState);
|
|
324
330
|
const resolvedSourceLocation = sourceLocation ?? fallbackSourceLocation;
|
|
325
331
|
|
|
326
332
|
if (generatedColumn >= 0 && resolvedSourceLocation !== undefined) {
|
|
@@ -421,16 +427,42 @@ function findFallbackSourceLine(
|
|
|
421
427
|
function findSourceLocation(
|
|
422
428
|
sourceLines: readonly string[],
|
|
423
429
|
token: string,
|
|
430
|
+
searchState?: SourceMapSearchState,
|
|
424
431
|
): { line: number; column: number } | undefined {
|
|
425
|
-
|
|
426
|
-
|
|
432
|
+
const source = sourceLines.join("\n");
|
|
433
|
+
const start = searchState?.tokenOffsets.get(token) ?? 0;
|
|
434
|
+
let offset = source.indexOf(token, start);
|
|
435
|
+
|
|
436
|
+
if (offset < 0 && start > 0) {
|
|
437
|
+
offset = source.indexOf(token);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (offset < 0) {
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
searchState?.tokenOffsets.set(token, offset + token.length);
|
|
445
|
+
return sourceOffsetToLineColumn(sourceLines, offset);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function sourceOffsetToLineColumn(
|
|
449
|
+
sourceLines: readonly string[],
|
|
450
|
+
offset: number,
|
|
451
|
+
): { line: number; column: number } {
|
|
452
|
+
let remaining = offset;
|
|
427
453
|
|
|
428
|
-
|
|
429
|
-
|
|
454
|
+
for (const [line, sourceLine] of sourceLines.entries()) {
|
|
455
|
+
if (remaining <= sourceLine.length) {
|
|
456
|
+
return { line, column: remaining };
|
|
430
457
|
}
|
|
458
|
+
|
|
459
|
+
remaining -= sourceLine.length + 1;
|
|
431
460
|
}
|
|
432
461
|
|
|
433
|
-
return
|
|
462
|
+
return {
|
|
463
|
+
line: Math.max(0, sourceLines.length - 1),
|
|
464
|
+
column: sourceLines.at(-1)?.length ?? 0,
|
|
465
|
+
};
|
|
434
466
|
}
|
|
435
467
|
|
|
436
468
|
function findJsxExpressionTokenLocation(
|