Skip to content

⬅️ Back to Table of Contents

📄 createParserServices

📊 Analysis Summary

Metric Count
🔧 Functions 7
📦 Imports 2

📚 Table of Contents

🛠️ File Location:

📂 packages/typescript-estree/src/createParserServices.ts

📦 Imports

Name Source
ASTMaps ./convert
ParserServices ./parser-options

Functions

createParserServices(astMaps: ASTMaps, program: ts.Program | null): ParserServices

Parameters:

  • astMaps ASTMaps
  • program ts.Program | null

Returns: ParserServices

Calls:

  • program.getTypeChecker
  • program.getCompilerOptions
  • checker.getContextualType
  • astMaps.esTreeNodeToTSNodeMap.get
  • checker.getResolvedSignature
  • checker.getSymbolAtLocation
  • checker.getTypeAtLocation
  • checker.getTypeFromTypeNode
  • checker.getTypeOfSymbolAtLocation

Internal Comments:

// we always return the node maps because
// (a) they don't require type info and
// (b) they can be useful when using some of TS's internal non-type-aware AST utils
// not set in the config is the same as off (x2)

Code
export function createParserServices(
  astMaps: ASTMaps,
  program: ts.Program | null,
): ParserServices {
  if (!program) {
    return {
      emitDecoratorMetadata: undefined,
      experimentalDecorators: undefined,
      isolatedDeclarations: undefined,
      program,
      // we always return the node maps because
      // (a) they don't require type info and
      // (b) they can be useful when using some of TS's internal non-type-aware AST utils
      ...astMaps,
    };
  }

  const checker = program.getTypeChecker();
  const compilerOptions = program.getCompilerOptions();

  return {
    program,
    // not set in the config is the same as off
    emitDecoratorMetadata: compilerOptions.emitDecoratorMetadata ?? false,
    experimentalDecorators: compilerOptions.experimentalDecorators ?? false,
    isolatedDeclarations: compilerOptions.isolatedDeclarations ?? false,
    ...astMaps,
    getContextualType: node =>
      checker.getContextualType(
        astMaps.esTreeNodeToTSNodeMap.get(node) as ts.Expression,
      ),
    getResolvedSignature: node =>
      checker.getResolvedSignature(astMaps.esTreeNodeToTSNodeMap.get(node)),
    getSymbolAtLocation: node =>
      checker.getSymbolAtLocation(astMaps.esTreeNodeToTSNodeMap.get(node)),
    getTypeAtLocation: node =>
      checker.getTypeAtLocation(astMaps.esTreeNodeToTSNodeMap.get(node)),
    getTypeFromTypeNode: node =>
      checker.getTypeFromTypeNode(
        astMaps.esTreeNodeToTSNodeMap.get(node) as ts.TypeNode,
      ),
    getTypeOfSymbolAtLocation: (symbol, node) =>
      checker.getTypeOfSymbolAtLocation(
        symbol,
        astMaps.esTreeNodeToTSNodeMap.get(node),
      ),
  };
}

Internal helpers

Declared inside another function in this file.

getContextualType(node: TSESTree.Expression): any

Parameters:

  • node TSESTree.Expression

Returns: any

Calls:

  • checker.getContextualType
Code
node =>
      checker.getContextualType(
        astMaps.esTreeNodeToTSNodeMap.get(node) as ts.Expression,
      )

getResolvedSignature(node: any): any

Parameters:

  • node any

Returns: any

Calls:

  • checker.getResolvedSignature
Code
node =>
      checker.getResolvedSignature(astMaps.esTreeNodeToTSNodeMap.get(node))

getSymbolAtLocation(node: TSESTree.Node): any

Parameters:

  • node TSESTree.Node

Returns: any

Calls:

  • checker.getSymbolAtLocation
Code
node =>
      checker.getSymbolAtLocation(astMaps.esTreeNodeToTSNodeMap.get(node))

getTypeAtLocation(node: TSESTree.Node): any

Parameters:

  • node TSESTree.Node

Returns: any

Calls:

  • checker.getTypeAtLocation
Code
node =>
      checker.getTypeAtLocation(astMaps.esTreeNodeToTSNodeMap.get(node))

getTypeFromTypeNode(node: TSESTree.TypeNode): any

Parameters:

  • node TSESTree.TypeNode

Returns: any

Calls:

  • checker.getTypeFromTypeNode
Code
node =>
      checker.getTypeFromTypeNode(
        astMaps.esTreeNodeToTSNodeMap.get(node) as ts.TypeNode,
      )

getTypeOfSymbolAtLocation(symbol: ts.Symbol, node: TSESTree.Node): any

Parameters:

  • symbol ts.Symbol
  • node TSESTree.Node

Returns: any

Calls:

  • checker.getTypeOfSymbolAtLocation
Code
(symbol, node) =>
      checker.getTypeOfSymbolAtLocation(
        symbol,
        astMaps.esTreeNodeToTSNodeMap.get(node),
      )

Generated by Syntax Scribe