Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: support #line directive so we can use other tools and have sane line numbers for errors & outputs. #34608

Closed
5 tasks done
graph opened this issue Oct 21, 2019 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@graph
Copy link

graph commented Oct 21, 2019

Search Terms

#line preprocessing directive

Suggestion

the c++ preprocessor adds #line directives and some other preprocessing tools do similar as well. And it's a good way to have multiple preprecossors act on a single file in a pipeline.

This proposal is just only supporting the '#line` directive so that other tools can do the job of preprocessing. Other existing issues such as Preprocessor directives proposal propose more kinds of directives and a more complete set of directives.

Additionally this proposal would support the preprocessor output of clang/gcc for line changes in the form of

# 1 "some/path/file.ts 1

which is very similar to #line directive.

Use Cases

I want to run c preprocessor on my typescript file and feed it directly to tsc. By supporting this directive typescript will be able to give proper line numbers and generate a more sensible source mappings.

Examples

#line 33 "../../../somedir/myfile.ts"
code.logic = 7;

Now for error reporting and generation of source maps I expect it to map to respective file and line number.

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@nmain
Copy link

nmain commented Oct 21, 2019

#13944 seems like a more sensible solution; it allows the same result as #line, it doesn't require intrusive syntax changes in source files, and is already supported by many parts of the js ecosystem.

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript labels Oct 22, 2019
@RyanCavanaugh
Copy link
Member

Agree with @nmain - source maps are the standard for JS tooling so #13944 would be the preferred solution in this space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants