-
-
Notifications
You must be signed in to change notification settings - Fork 200
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
(feat) basic rename #172
(feat) basic rename #172
Conversation
Found an issue. if I rename a props that is html attribute like disabled. It would do a rename on the html attribute no matter that props exist on the component or not. |
Good catch, thank you. There is also a prop rename problem. I think I need to enhance |
To show a message early that rename is not allowed in certain locations
I ended up using |
We cannot handle it at the moment
For that svelte2tsx needs to write out the props as {prop: prop}
@jasonlyu123 could you take one more look? 😃 Also code-wise, I had to jump through some hoops to get it working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the source map of export { className as class }
is wrong. This could be done in another PR
// First find out if it's really the "rename prop inside component with that prop" case | ||
// Use original document for that because only there the `export` is present. | ||
const regex = new RegExp( | ||
`export\\s+(const|let)\\s+${getVariableAtPosition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class and function can also be exported. Though I never used it myself, I don't know what it can do 😂
There's also export { className as class }
this probably is tricky because it could be multiple lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sw-yx do you know about export const, function, class? I only found it to be available in the component instance, if so it probably doesn't needs to be checked.
return getVariableAtOffset(offsetAt(position, text), text); | ||
} | ||
|
||
export function getVariableAtOffset(offset: number, text: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also variable.b, variable) and operators without space in between.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a hack that can be used to find the identifier/symbol in the generated tsx:
const offset = fragment.offsetAt(fragment.getGeneratedPosition(position));
const { start, length } = lang.getSmartSelectionRange(tsDoc.filePath, offset).textSpan;
const identifier = tsDoc.getText(start, start + length);
<input bind:value /> would be renamed to <input bind:valuvalues /> Some shorthand attributes would have a problem, maybe it can all be handle in another PR. |
This is a source map problem, seems like |
#110
Out of scope for this PR: