@flint.fyi/typescript-language 0.18.0 → 0.18.1

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.
@@ -1,5 +1,6 @@
1
1
  import { normalizeRange } from "../normalizeRange.js";
2
2
  import { DirectivesCollector } from "@flint.fyi/core";
3
+ import ts from "typescript";
3
4
  import { nullThrows } from "@flint.fyi/utils";
4
5
  import * as tsutils from "ts-api-utils";
5
6
  //#region src/directives/parseDirectivesFromTypeScriptFile.ts
@@ -9,13 +10,14 @@ function extractDirectivesFromTypeScriptFile(sourceFile) {
9
10
  const commentText = fullText.slice(sourceRange.pos, sourceRange.end);
10
11
  const match = /^\/\/\s*flint-(\S+)(?:\s+(.+))?/.exec(commentText);
11
12
  if (!match) return;
12
- const range = normalizeRange({
13
+ let range = normalizeRange({
13
14
  begin: sourceRange.pos,
14
15
  end: sourceRange.end
15
16
  }, sourceFile);
16
17
  const matches = match.slice(1);
17
18
  const type = nullThrows(matches[0], "First match is expected to be present by the regex match");
18
19
  const selection = matches[1] ?? "";
20
+ if (type === "disable-next-line") range = extendRangeToNextCodeLine(sourceFile, range);
19
21
  directives.push({
20
22
  range,
21
23
  selection,
@@ -29,6 +31,35 @@ function parseDirectivesFromTypeScriptFile(sourceFile) {
29
31
  for (const { range, selection, type } of extractDirectivesFromTypeScriptFile(sourceFile)) collector.add(range, selection, type);
30
32
  return collector.collect();
31
33
  }
34
+ function computeNextCodeLine(sourceFile, directiveLine) {
35
+ const lineStarts = sourceFile.getLineStarts();
36
+ const nextLineStart = lineStarts[directiveLine + 1];
37
+ if (nextLineStart === void 0) return;
38
+ const scanner = ts.createScanner(sourceFile.languageVersion, true, sourceFile.languageVariant, sourceFile.text, void 0, nextLineStart);
39
+ if (scanner.scan() === ts.SyntaxKind.EndOfFileToken) return;
40
+ const tokenPos = scanner.getTokenStart();
41
+ const codeLine = sourceFile.getLineAndCharacterOfPosition(tokenPos).line;
42
+ for (let line = directiveLine + 1; line < codeLine; line++) {
43
+ const start = lineStarts[line];
44
+ const end = lineStarts[line + 1] ?? sourceFile.text.length;
45
+ if (sourceFile.text.slice(start, end).trim() === "") return;
46
+ }
47
+ return codeLine;
48
+ }
49
+ function extendRangeToNextCodeLine(sourceFile, range) {
50
+ const codeLine = computeNextCodeLine(sourceFile, range.begin.line);
51
+ if (codeLine === void 0 || codeLine <= range.end.line + 1) return range;
52
+ const endPosition = nullThrows(sourceFile.getLineStarts()[codeLine], "Code line start is expected to be present by the computed code line") - 1;
53
+ const { character, line } = sourceFile.getLineAndCharacterOfPosition(endPosition);
54
+ return {
55
+ ...range,
56
+ end: {
57
+ column: character,
58
+ line,
59
+ raw: endPosition
60
+ }
61
+ };
62
+ }
32
63
  //#endregion
33
64
  export { extractDirectivesFromTypeScriptFile, parseDirectivesFromTypeScriptFile };
34
65
 
package/lib/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
2
  var name = "@flint.fyi/typescript-language";
3
- var version = "0.18.0";
3
+ var version = "0.18.1";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flint.fyi/typescript-language",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "[Experimental] TypeScript language for Flint.",
5
5
  "homepage": "https://flint.fyi",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "debug-for-file": "^0.3.0",
28
28
  "ts-api-utils": "^2.4.0",
29
29
  "typescript": "^5.9.0 || ^6.0.0",
30
- "@flint.fyi/core": "^0.21.0",
30
+ "@flint.fyi/core": "^0.21.1",
31
31
  "@flint.fyi/utils": "^0.14.1"
32
32
  },
33
33
  "devDependencies": {