• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

reactjs / react-docgen / 12386142166

18 Dec 2024 04:04AM CUT coverage: 96.38%. Remained the same
12386142166

push

github

web-flow
chore(deps): update dependency tailwindcss to v3.4.17

1378 of 1478 branches covered (93.23%)

Branch coverage included in aggregate %.

7168 of 7389 relevant lines covered (97.01%)

435.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.0
/packages/react-docgen/src/FileState.ts
1
import type { HubInterface, Scope, Visitor } from '@babel/traverse';
3✔
2
import babelTraverse, { NodePath } from '@babel/traverse';
3✔
3
import type { File, Node, Program } from '@babel/types';
3✔
4
import type { Importer, ImportPath } from './importer/index.js';
3✔
5
import babelParse from './babelParser.js';
3✔
6
import type { TransformOptions } from '@babel/core';
3✔
7

3✔
8
// Workaround while babel is not a proper ES module
3✔
9
const traverse = babelTraverse.default ?? (babelTraverse as never);
3!
10

3✔
11
export default class FileState {
3✔
12
  opts: TransformOptions;
5,403✔
13
  path: NodePath<Program>;
5,403✔
14
  ast: File;
5,403✔
15
  scope: Scope;
5,403✔
16
  code: string;
5,403✔
17

5,403✔
18
  #importer: Importer;
5,403✔
19

5,403✔
20
  hub: HubInterface = {
5,403✔
21
    // keep it for the usage in babel-core, ex: path.hub.file.opts.filename
5,403✔
22
    file: this,
5,403✔
23
    parse: this.parse.bind(this),
5,403✔
24
    import: this.import.bind(this),
5,403✔
25
    getCode: () => this.code,
5,403✔
26
    getScope: () => this.scope,
5,403✔
27
    addHelper: () => undefined,
5,403✔
28
    buildError: <E extends Error>(
5,403✔
29
      node: Node,
×
30
      msg: string,
×
31
      Error: new (message?: string) => E,
×
32
    ): E & { node: Node } => {
×
33
      const err = new Error(msg);
×
34

×
35
      (err as E & { node: Node }).node = node;
×
36

×
37
      return err as E & { node: Node };
×
38
    },
×
39
  };
5,403✔
40

5,403✔
41
  constructor(
5,403✔
42
    options: TransformOptions,
5,403✔
43
    { code, ast, importer }: { code: string; ast: File; importer: Importer },
5,403✔
44
  ) {
5,403✔
45
    this.opts = options;
5,403✔
46
    this.code = code;
5,403✔
47
    this.ast = ast;
5,403✔
48
    this.#importer = importer;
5,403✔
49

5,403✔
50
    this.path = NodePath.get({
5,403✔
51
      hub: this.hub,
5,403✔
52
      parentPath: null,
5,403✔
53
      parent: this.ast,
5,403✔
54
      container: this.ast,
5,403✔
55
      key: 'program',
5,403✔
56
    }).setContext() as NodePath<Program>;
5,403✔
57
    this.scope = this.path.scope;
5,403✔
58
  }
5,403✔
59

5,403✔
60
  /**
5,403✔
61
   * Try to resolve and import the ImportPath with the `name`
5,403✔
62
   */
5,403✔
63
  import(path: ImportPath, name: string): NodePath | null {
5,403✔
64
    return this.#importer(path, name, this);
4,023✔
65
  }
4,023✔
66

5,403✔
67
  /**
5,403✔
68
   * Parse the content of a new file
5,403✔
69
   * The `filename` is required so that potential imports inside the content can be correctly resolved and
5,403✔
70
   * the correct babel config file could be loaded. `filename` needs to be an absolute path.
5,403✔
71
   */
5,403✔
72
  parse(code: string, filename: string): FileState {
5,403✔
73
    const newOptions = { ...this.opts, filename };
69✔
74
    // We need to build a new parser, because there might be a new
69✔
75
    // babel config file in effect, so we need to load it
69✔
76
    const ast = babelParse(code, newOptions);
69✔
77

69✔
78
    return new FileState(newOptions, {
69✔
79
      ast,
69✔
80
      code,
69✔
81
      importer: this.#importer,
69✔
82
    });
69✔
83
  }
69✔
84

5,403✔
85
  traverse<S>(visitors: Visitor<S>, state?: S): void;
5,403✔
86
  traverse(visitors: Visitor): void;
5,403✔
87
  /**
5,403✔
88
   * Traverse the current file
5,403✔
89
   */
5,403✔
90
  traverse(visitors: Visitor, state?: unknown): void {
5,403✔
91
    traverse(this.ast, visitors, this.scope, state);
2,838✔
92
  }
2,838✔
93
}
5,403✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc