-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[@swc/core@1.3.7 + ] index out of bounds: the len is 1 but the index is 1 #6255
Comments
I'm also seeing this in our formatjs swc plugin |
@longlho Can you provide a repro case? |
It's a little hard to isolate it because our plugin does a bunch of transformations, but specifically this test fail: In the fixture our plugin basically tries to find all When I run with
Hope that helps. Also this is the only test that failed and the other tests seem ok, so this might be some edge case. The code snippet that @mizi-lin posted seems a lot simpler and also crapped out? |
I got this error also |
Does it work on |
@IWANABETHATGUY I think #6019 is the cause, thoughts? |
@aelbore Can you try 1.3.4 and 1.3.5? |
@kdy1 works on import { transformSync, plugins } from '@swc/core'
import { Visitor } from '@swc/core/Visitor.js'
const content = `
const store = () => {
}
export default store;
`
class MyPlugin extends Visitor {
visitModule(e) {
return e;
}
}
const myPlugin = () => {
return (p) => new MyPlugin().visitProgram(p)
}
const { code } = transformSync(content, {
filename: 'abc.ts',
jsc: {
parser: {
syntax: 'typescript',
tsx: true
}
},
plugin: plugins([
myPlugin()
])
})
console.log(code) |
if you change the content to this const content = `
export default () => {
}
` it works |
I expected this will not cause issues, i will try to revert the code and see if we could fix this issue. |
Oh, nevermind. Your plugin was based on js, so it was an identical issue. |
That's fine, hhhh |
another thing, empty plugin cause error also plugin: plugins([]) |
For formatjs, please use https://github.com/kwonoj/swc-plugin-formatjs instead |
Just want to ask if theres any plan to fix this? though version <=1.3.6 works Many thanks |
that's not maintained but us btw |
@aelbore Not sure. Fix would be trivial but I don't want to use my time for this |
Thanks no worries for now i will use version <= 1.3.6 👍 |
Just to add also this cause the error import { display } from './display'
const randomId = () => {
return display()
}
export { display }
export { randomId } Solution import { display } from './display'
export const randomId = () => {
return display()
}
export { display } from './display' |
I'm not going to fix this by myself as fixing this encourages wrong usage |
I didn't close it because I would accept PR |
So what is actually the issue here? I'm seeing the "index out of bounds" in my build and came here to find a fix or at least a workaround. I read "this encourages wrong usage", so I would like to know what I'm doing wrong. I also read "Fix would be trivial" so I assume a root cause is found, but I don't see it, is is the default exports? How would a PR to fix this look like? |
I'm encountering the same issue. I don't understand the wrong usage... EDIT I was having same issue here: #6255 (comment) Crash
Fix
Is this syntax not valid in TS? An error would be nice indeed. |
For anyone still encountering the issue: it may not be the issue from I tried the Then I removed all plugins in my project and found it worked... After several tries, I found that both I'm not familiar with Rust so I didn't find the root cause, but removing all SWC plugins is an acceptable solution for me. |
I get this with a blank plugin in JS just extending Visitor ( |
So, I comment as well to say that I have a similar error with this parsed code myGlob = function () {
let a = 42;
};
myGlob(); I can't remove the plugins because I use them to transform code for a specific parser. I don't know rust as well in order to make a PR. |
There is a bug when using a plugin: swc-project/swc#6255
I also encountered this now with completely unrelated code to be transformed (see #7570) and the use of a plugin that merely returns the module/program. In my case, it's not possible to adjust the code, as that's provided by third parties.
@kdy1, would you mind elaborating why the wrong usage is in this case? The use of the plugin hook? As the removal of the plugin fixes the issue in all instances, it means that the issue lies with calling the transform function with an swc-generated AST for those code snippets. In other words, const module = parseSync('fn((obj) => obj?.method());');
transformSync(module); fails, but transformSync('fn((obj) => obj?.method());'); succeeds. Shouldn't this be fixed? |
@rene-leanix |
I have this issue when just using transform(string), when using a blank JS plugin. |
JS plugins will be removed in v2, and it's deprecated. |
Thanks for the quick response and clarification, @kdy1! Is there any place I can read up about the major (especially breaking) changes planned for v2? If JS plugins are removed, could there be a way to register a (published or local) Rust plugin from within the JS code for a particular transformation? |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
env: typescript v4.8.4
in @swc/core v1.3.6 ok
Input code
The text was updated successfully, but these errors were encountered: