-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
flow-remove-types produces invalid JS after non-latin characters #7779
Comments
This seems to be a bug in |
same root cause as #5793, I believe. the lexer reports its position in unicode codepoints, of which these are 1, but they are multibyte. |
@mroch I believe it's a recent regression, because https://astexplorer.net/ (which uses Flow v0.94.0) shows identical AST for both cases ( |
this appears to only be an issue with the it's a bit easier to see if you do it all on one line: https://flow.org/try/#0PQKk-CAsBmD2MNxA (see the AST tab). since it's all on line 1, the range should match the columns in |
@mroch ah, yeah, you're right. The link I commented earlier triggers the bug if you add a new line after the comment. |
hrm i think we intentionally made |
cc @nmote I think we should change |
flow/src/parser/offset_utils.mli Lines 8 to 30 in a05cbb2
... yup |
Thanks for looking into this @mroch! Agreed about bringing Flow AST more in line with other parsers. In the meantime, to fix the breaking bug with |
alternatively, if it could work with UTF8 bytes instead of JS strings, that would make the existing ranges correct. for example, perhaps changing flow-remove-types to use Buffers? I think the offsets of a Buffer are in bytes, not codepoints. modifying a buffer in place instead of lots of string concatenation could be a perf win too. flow/packages/flow-remove-types/index.js Line 107 in a05cbb2
|
@mroch yep, will do! |
We are running into the same problem, in our case with a ™ in a comment. // @flow
import React from 'react';
/*
This should Just Work™
*/
export const SomeComponent = (props: Object) => (
<div {...props}>
This breaks
</div>
); becomes import React from 'react';
/*
This should Just Work™
*/
export const SomeComponent = (props:=> (
<div {...props}>
This breaks
</div>
); Looks like it's been a few months now, and it shows up in all v2 releases of |
Flow version: 0.100.0
Expected behavior
Given the following input:
flow-remove-types
should produce:Actual behavior
It produces invalid JS:
The non-latin character is the trigger. Without it, it works correctly. This seems like quite a serious bug considering how common it is to use non-latin characters in comments (e.g. comment in other languages, draw arrows etc.).
cc @mroch @samwgoldman
The text was updated successfully, but these errors were encountered: