codemodsquad / astx

Super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
MIT License
92 stars 6 forks source link

'import { Button, ...$rest } from "blah"' causes errors #13

Closed alexgorbatchev closed 2 years ago

alexgorbatchev commented 2 years ago
$ npx astx@2.0.0-beta.6 -f 'import { Button, ...$rest } from "blah"' **/*.tsx
SyntaxError: `import` can only be used in `import()` or `import.meta`. (1:1)
    at instantiate (.../@babel/parser/lib/index.js:72:32)
    at constructor (.../@babel/parser/lib/index.js:366:12)
    at TypeScriptParserMixin.raise (.../@babel/parser/lib/index.js:3453:19)
    at TypeScriptParserMixin.parseExprAtom (.../@babel/parser/lib/index.js:13065:16)
    at TypeScriptParserMixin.parseExprAtom (.../@babel/parser/lib/index.js:8174:20)
    at TypeScriptParserMixin.parseExprSubscripts (.../@babel/parser/lib/index.js:12785:23)
    at TypeScriptParserMixin.parseUpdate (.../@babel/parser/lib/index.js:12764:21)
    at TypeScriptParserMixin.parseMaybeUnary (.../@babel/parser/lib/index.js:12734:23)
    at TypeScriptParserMixin.parseMaybeUnary (.../@babel/parser/lib/index.js:10933:20)
    at TypeScriptParserMixin.parseMaybeUnaryOrPrivate (.../@babel/parser/lib/index.js:12525:61)
jedwards1211 commented 2 years ago

Afaik JS syntax doesn't support rest spread inside import statements. Instead you can use import { $$before, Button, $$after } from 'blah'

jedwards1211 commented 2 years ago

Maybe I should make triple dollar sign be an unordered "rest" capture 🤔

So for example, import { Button, $$$rest } from 'blah'

alexgorbatchev commented 2 years ago

Maybe I should make triple dollar sign be an unordered "rest" capture 🤔

I think this would cover the use case :)

jedwards1211 commented 2 years ago

:tada: This issue has been resolved in version 2.0.0-beta.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

jedwards1211 commented 2 years ago

$$$rest capture works now in the 2.0.0-beta.7 release! And you can use $$$rest variables in replacement expressions too.

jedwards1211 commented 1 year ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: