Skip to content

Make incomplete scanner APIs internalΒ #44250

@cubenoy22

Description

@cubenoy22

Suggestion

πŸ” Search Terms

  • scanner + label:API
  • SourceFileLike
  • getPositionOfLineAndCharacter
  • getLineAndCharacterOfPosition

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

  • ts.getPositionOfLineAndCharacter should be marked with /* @internal */
  • ts.getLineAndCharacterOfPosition should be marked with /* @internal */

These methods take an argument of SourceFileLike at first, and its type is defined as:

    /* @internal */
    /**
     * Subset of properties from SourceFile that are used in multiple utility functions
     */
    export interface SourceFileLike {
        readonly text: string;
        lineMap?: readonly number[];
        /* @internal */
        getPositionOfLineAndCharacter?(line: number, character: number, allowEdits?: true): number;
    }

in src/compiler/types.ts and also defined:

    export interface SourceFileLike {
        getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
    }

in src/services/types.ts. so, required implementation of SourceFileLike in public is only getLineAndCharacterOfPosition. But two exposed methods are uses all internal-marked members in actual (occurs runtime error).

πŸ’» Use Cases

After this changes, These methods in SourceFile is still available:

  • getLineAndCharacterOfPosition
  • getPositionOfLineAndCharacter

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: APIRelates to the public API for TypeScriptGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions