kopytko-formatter 1.1.6 → 1.1.7
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.
|
@@ -28,7 +28,8 @@ export type CstPass = (root: SyntaxNode, source: string) => TextEdit[];
|
|
|
28
28
|
export declare function applyEdits(source: string, edits: TextEdit[]): string;
|
|
29
29
|
/**
|
|
30
30
|
* Runs one or more CST passes on the source and returns the transformed text.
|
|
31
|
-
*
|
|
31
|
+
* Re-parses after each pass that modifies the source so subsequent passes use
|
|
32
|
+
* correct token positions (avoids position drift when a pass changes text length).
|
|
32
33
|
*/
|
|
33
34
|
export declare function runCstPasses(source: string, passes: CstPass[]): string;
|
|
34
35
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infrastructure.d.ts","sourceRoot":"","sources":["../../../src/cst-passes/infrastructure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAS,UAAU,EAAmB,MAAM,6BAA6B,CAAC;AACjF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAEzD,iEAAiE;AACjE,MAAM,WAAW,QAAQ;IACvB,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4EAA4E;AAC5E,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;AAEvE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAQpE;AAED
|
|
1
|
+
{"version":3,"file":"infrastructure.d.ts","sourceRoot":"","sources":["../../../src/cst-passes/infrastructure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAS,UAAU,EAAmB,MAAM,6BAA6B,CAAC;AACjF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAEzD,iEAAiE;AACjE,MAAM,WAAW,QAAQ;IACvB,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4EAA4E;AAC5E,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;AAEvE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAQpE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAmBtE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAQvG"}
|
|
@@ -29,10 +29,11 @@ function applyEdits(source, edits) {
|
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Runs one or more CST passes on the source and returns the transformed text.
|
|
32
|
-
*
|
|
32
|
+
* Re-parses after each pass that modifies the source so subsequent passes use
|
|
33
|
+
* correct token positions (avoids position drift when a pass changes text length).
|
|
33
34
|
*/
|
|
34
35
|
function runCstPasses(source, passes) {
|
|
35
|
-
|
|
36
|
+
let parseResult = (0, kopytko_brightscript_parser_1.parse)(source);
|
|
36
37
|
if (parseResult.diagnostics.length > 0) {
|
|
37
38
|
// Source has syntax errors — don't transform
|
|
38
39
|
return source;
|
|
@@ -42,6 +43,11 @@ function runCstPasses(source, passes) {
|
|
|
42
43
|
const edits = pass(parseResult.root, result);
|
|
43
44
|
if (edits.length > 0) {
|
|
44
45
|
result = applyEdits(result, edits);
|
|
46
|
+
const next = (0, kopytko_brightscript_parser_1.parse)(result);
|
|
47
|
+
// If a pass somehow introduced a syntax error, stop rather than corrupting further
|
|
48
|
+
if (next.diagnostics.length > 0)
|
|
49
|
+
break;
|
|
50
|
+
parseResult = next;
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infrastructure.js","sourceRoot":"","sources":["../../../src/cst-passes/infrastructure.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAsBH,gCAQC;
|
|
1
|
+
{"version":3,"file":"infrastructure.js","sourceRoot":"","sources":["../../../src/cst-passes/infrastructure.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAsBH,gCAQC;AAOD,oCAmBC;AAMD,gCAQC;AApED,6EAAiF;AAgBjF;;;GAGG;AACH,SAAgB,UAAU,CAAC,MAAc,EAAE,KAAiB;IAC1D,yEAAyE;IACzE,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,MAAc,EAAE,MAAiB;IAC5D,IAAI,WAAW,GAAG,IAAA,mCAAK,EAAC,MAAM,CAAC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