flake-monster 0.3.1 → 0.3.3
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
2
|
import { dirname, join, posix } from 'node:path';
|
|
3
3
|
import { parseSource } from './parser.js';
|
|
4
|
-
import { computeInjections, computeRuntimeImportInsertion, applyInsertions } from './injector.js';
|
|
4
|
+
import { computeInjections, computeRuntimeImportInsertion, applyInsertions, MARKER_PREFIX } from './injector.js';
|
|
5
5
|
import { recoverDelays, scanForRecovery } from './remover.js';
|
|
6
6
|
|
|
7
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -43,6 +43,11 @@ export function createJavaScriptAdapter() {
|
|
|
43
43
|
},
|
|
44
44
|
|
|
45
45
|
inject(source, options) {
|
|
46
|
+
if (source.includes(MARKER_PREFIX)) {
|
|
47
|
+
console.warn(` Skipping ${options.filePath}: already injected (restore first)`);
|
|
48
|
+
return { source, points: [], runtimeNeeded: false };
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
try {
|
|
47
52
|
const { ast } = parseSource(source);
|
|
48
53
|
const { insertions, points } = computeInjections(ast, source, options);
|
|
@@ -405,13 +405,20 @@ export function computeRuntimeImportInsertion(ast, source, runtimeImportPath) {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
408
|
+
let insertOffset;
|
|
409
|
+
if (lastImportEnd === 0) {
|
|
410
|
+
// No existing imports — insert at the very start of the file
|
|
411
|
+
// (not after the first line, which may be inside a block comment)
|
|
412
|
+
insertOffset = 0;
|
|
413
|
+
} else {
|
|
414
|
+
// Find the newline after the last import
|
|
415
|
+
insertOffset = lastImportEnd;
|
|
416
|
+
while (insertOffset < source.length && source[insertOffset] !== '\n') {
|
|
417
|
+
insertOffset++;
|
|
418
|
+
}
|
|
419
|
+
if (insertOffset < source.length) {
|
|
420
|
+
insertOffset++; // past the \n
|
|
421
|
+
}
|
|
415
422
|
}
|
|
416
423
|
|
|
417
424
|
const text = `import { ${DELAY_OBJECT} } from '${runtimeImportPath}';\n`;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import * as acorn from 'acorn';
|
|
2
|
-
import { attachComments } from 'astravel';
|
|
2
|
+
import { defaultTraveler, attachComments } from 'astravel';
|
|
3
|
+
|
|
4
|
+
// Patch astravel bug: PropertyDefinition reuses MethodDefinition handler which
|
|
5
|
+
// calls this.go(node.value) without a null guard. Uninitialized class fields
|
|
6
|
+
// (e.g. `bar;`) have value: null, crashing the traversal.
|
|
7
|
+
defaultTraveler.PropertyDefinition = function (node, state) {
|
|
8
|
+
this.go(node.key, state);
|
|
9
|
+
if (node.value != null) {
|
|
10
|
+
this.go(node.value, state);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
15
|
* Parse JS source to ESTree AST with comments attached to nodes.
|