babel/packages/babel-plugin-transform-react-jsx-source
Logan Smyth 69cca412eb
Make the filename option, as exposed to the plugins, consistently relative to the working directory (#7956)
| Q                        | A <!--(Can use an emoji 👍) -->
| ------------------------ | ---
| Fixed Issues?            | 
| Patch: Bug Fix?          | Y
| Major: Breaking Change?  | N
| Minor: New Feature?      |
| Tests Added + Pass?      | Yes
| Documentation PR         | <!-- If so, add `[skip ci]` to your commit message to skip CI -->
| Any Dependency Changes?  |
| License                  | MIT

Currently the `opts.filename` value exposed to plugins is just whatever the user passed. While it _could_ be relative to the working directory, if Babel was passed an absolute URL, it'll be absolute.

This PR explicitly ensures the filename is a relative path based on the working directory. This also exposes an officially endorsed API for reading the working directory path.
2018-05-21 17:10:57 -07:00
..
2017-03-25 21:46:16 -04:00
2018-05-14 17:15:44 -07:00

@babel/plugin-transform-react-jsx-source

Adds source file and line number to JSX elements.

Example

In

<sometag />

Out

<sometag __source={ { fileName: 'this/file.js', lineNumber: 10 } } />

Installation

npm install --save-dev @babel/plugin-transform-react-jsx-source

Usage

.babelrc

{
  "plugins": ["@babel/plugin-transform-react-jsx-source"]
}

Via CLI

babel --plugins @babel/plugin-transform-react-jsx-source script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/plugin-transform-react-jsx-source"]
});