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

Verify that files are .ts/.tsx before treating as Typescript files. #7955

Merged
merged 4 commits into from May 23, 2018

Conversation

@loganfsmyth
Copy link
Member

loganfsmyth commented May 17, 2018

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change? Y
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes?
License MIT

I think this is mergeable, but I'm also very interested to hear what people would think of this approach.

This PR makes means:

  • For preset-typescript, it needs to be used in a context where Babel is given a filename, so it will error if called without a filename.
    • BUT if there is no filename, the user could set allExtensions: true to force-enable TS parsing without extensions taken into account. Then they could set isTSX: true to parse with JSX.
  • For plugin-typescript, when enabled things will automatically be parsed as .ts, with the isTSX: true option to enable parsing as .tsx.

This essentially means that the preset tries to auto-configure the plugin based on the file path.

We could also consider making the preset always expect a filename (delete allExtensions), and just tell people to use the plugin if there is no filename.

@loganfsmyth loganfsmyth force-pushed the loganfsmyth:typescript-filename-required branch from 55a9a39 to 762a687 May 17, 2018
@babel-bot

This comment has been minimized.

Copy link
Collaborator

babel-bot commented May 17, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8122/

@xtuc
xtuc approved these changes May 21, 2018
@loganfsmyth loganfsmyth force-pushed the loganfsmyth:typescript-filename-required branch from 762a687 to 43aa61d May 22, 2018
@loganfsmyth loganfsmyth merged commit eb3334a into babel:master May 23, 2018
4 checks passed
4 checks passed
babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 80.82% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@loganfsmyth loganfsmyth deleted the loganfsmyth:typescript-filename-required branch May 23, 2018
throw new Error(".allExtensions must be a boolean, or undefined");
}
if (typeof isTSX !== "boolean") {
throw new Error(".allExtensions must be a boolean, or undefined");

This comment has been minimized.

Copy link
@Jessidhia

Jessidhia Jun 7, 2018

Member

typo 🙊

This comment has been minimized.

Copy link
@xtuc

xtuc Jun 8, 2018

Member

Has been changed 06e5c46

@lock lock bot added the outdated label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.