Conversation
| import jsTokens, { matchToToken } from "js-tokens"; | ||
| import esutils from "esutils"; | ||
| import Chalk from "chalk"; | ||
| import repeat from "lodash/repeat"; |
There was a problem hiding this comment.
This seemed to be the way lodash was used
8abe3dd to
4e0d2a7
Compare
| ): string { | ||
| colNumber = Math.max(colNumber, 0); | ||
|
|
||
| if (typeof colRange === "object") { |
There was a problem hiding this comment.
This is the part that can be dropped if a breaking change is acceptable
Codecov Report
@@ Coverage Diff @@
## 7.0 #5646 +/- ##
=========================================
- Coverage 84.63% 84.6% -0.03%
=========================================
Files 282 282
Lines 9857 9899 +42
Branches 2766 2777 +11
=========================================
+ Hits 8342 8375 +33
- Misses 995 1002 +7
- Partials 520 522 +2
Continue to review full report at Codecov.
|
|
I failed searching apparently... If the approach in #5515 is preferred this can be closed, but that PR seems stalled. Maybe not though 😄 It might have stalled because of lack of feedback for all I know. |
|
Hi @SimenB, I can't find time to learn Flow and finish that PR. I'll close it in favor of this. I'm in favor of the new API I proposed in #5064. This need to cover
|
|
@mohsen1 Sure, I can do that 😄 |
|
Let's keep it targeting 7.0 |
4e0d2a7 to
07ef1e4
Compare
07ef1e4 to
f769b98
Compare
|
Rebased on 7.0, and now taking in @mohsen1 How did you imagine multiple lines would look? |
| ].join("\n")); | ||
| }); | ||
|
|
||
| it("optional column number", function () { |
There was a problem hiding this comment.
this test is duplicated right above it (which meant mocha didn't run it)
9c54350 to
9a30d3a
Compare
|
I added some stuff for multiple lines. Not sure how useful it is, but it's there at least 😄 @existentialism, ready for review. Not really happy about all the EDIT:got away from most of them, so OK now |
213bc49 to
9e1635e
Compare
|
Based on how TSLint test runner marks ranges this is what I would expect: single positionsingle line with no columnsingle line range (from and to positions)multi line range from and to specific positionmulti line range with no column data |
9e1635e to
635ec5d
Compare
|
Thanks! Then I think the current implementation was correct, except for multi lines without column data. Fixed that now though. Can you take a look at the tests and see if you agree everything is covered? EDIT: Should probably check out tslint's implementation, figure out why they wrote their own instead of reusing babel-code-frame. EDIT2: They already use this module: https://github.com/palantir/tslint/blob/master/src/formatters/codeFrameFormatter.ts |
635ec5d to
84407b5
Compare
|
Sorry for the wait! Can we add a section to the readme about how to upgrade to the new format? |
|
@hzoo No probs, glad it wasn't forgotten 😄 Readme updated (and I rebased) |
| if (!deprecationWarningShown) { | ||
| deprecationWarningShown = true; | ||
|
|
||
| console.warn(new Error( |
There was a problem hiding this comment.
Not sure how I feel about this
|
@hzoo Sorry for the noise, but is there anything that needs changing? Would hate for you to circle back and want changes whenever you're ready to merge this, much rather it was good to go. |
| colNumber: ?number, | ||
| opts: Object = {}, | ||
| ): string { | ||
| if (!deprecationWarningShown) { |
There was a problem hiding this comment.
Do we want to print a deprecation, or just let it be?
hzoo
left a comment
There was a problem hiding this comment.
lgtm, sorry been a long time for this PR 😅
|
I'm ok without the deprecation too, or we can make a simple codemod for this too |
|
We can turn on flow for these files later :) |
|
@SimenB thanks again! |
|
Added in v7.0.0-alpha.12 (Example PR to update #5808) - dono if we want the deprecation message or not still if it's going to cause other tools to error but maybe it's ok |
|
I'm all for just removing the old API and throwing :) |
|
@hzoo This is a breaking change for |
|
Can fix off by one at the same time? |
|
also from @rwjblue on slack
|
|
Not sure I understand that one. Just do Or is a very pretty stakctrace wanted? If so, why? And if you really want it, could you provide a sample of the wanted output? |
|
We just need to know the file that the import/use of babel-code-frame is at - we could even use babel-code-frame to do it 😛 . Just saying the current output is not helpful because it only tells you to change it but not where. Just check our travis tests: https://travis-ci.org/babel/babel/jobs/240419278 |
|
Yeah, but if you start node with |
|
I think in general we should strive to make the default console output have enough information so that folks can track this down. Having the filename, column, and line info would do that. I doubt that most users know about |
|
I definetely didn't know about it 😛 |
|
It's the official way to deprecate stuff in node. Maybe we could print a hint about it? If you use node 4 it's a normal stacktrace, though. |
|
Sure just thinking about the end-user - they are going to see this in their output and wonder what to do. It might not even be their own code so we should update the main consumers to be updated beforehand (prettier which you did, eslint, css-loader, create-react-app, etc) |
|
I can go through an send a PR to them. Should we try to fix the off by one first, though? And should we just remove the bridge and throw? That way we don't have to deal with the trace at all |
|
Since this is 7.x I guess we could just throw if it makes it easier, shouldn't be hard to do together? Clearly it didn't work since we didn't fix all the places in babel itself 😛 so unlikely the case for others too |
|
We already create an
True story! |

Inspired by flow errors, this allows us to highlight a whole word or phrase, not just a single character.
I can make this out to the
7.0branch instead, and not make the argument optional? As in, same ascolNumber, but handlenulland don't try to support both 4 and 5 args.If accepted, I can update babel's own usage of
babel-code-frameto use this new option. I didn't do it yet in case you don't want this 😄