microsoft / microsoft/vscode-textbuffer

DefaultEndOfLine enum not accessible in Javacript API

Open
#2 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
113
Forks
19
Avg merge
12h 46m
Merged PRs (30d)
2

Description

The following line from the README described API works in Typescript but not in Javascript or Coffeescript.

Piece Tree exports the DefaultEndOfLine enum as it is necessary for the API. Per the README:

const pieceTree = pieceTreeFactory.create(DefaultEndOfLine.LF);

This works in Typescript, but in plain Javascript or Coffeescript one gets the following:

TypeError: Cannot read property 'LF' of undefined`

I looked into it and learned that the Typescript compiler declares a const enum in the TS declaration files, but does not generate any JS code for it -- as constants they are completely erased (replaced with hardcoded underlying values) at compile time. Hence the error for any client that doesn't look at the TS declaration files, e.g. Javascript, Coffeescript, etc.

Removing the const keyword eliminates the error, but now there is a level of indirection when accessing Typescript values. Not sure what the ideal solution is.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the README example using DefaultEndOfLine.LF and inspect the TypeScript declaration and generated JavaScript for the Piece Tree API. Compare the TypeScript and JavaScript exports to determine how the enum is exposed at runtime. Done means the documented example works from plain JavaScript and CoffeeScript as well as TypeScript.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, javascript, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.