fix(register): skip hook for ignored files#17928
Conversation
| @@ -109,8 +119,22 @@ async function transform(input: string, filename: string) { | |||
| return await store({ code, map }); | |||
| } | |||
|
|
|||
| async function isFileIgnored(filename: string) { | |||
There was a problem hiding this comment.
This helper can potentially be reused by the babel-cli: See #17878
Do you think we should make it an API of @babel/core?
There was a problem hiding this comment.
It seems small enough that it's fine to just copy&paste it.
There was a problem hiding this comment.
OK, let's leave it as-is.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61377 |
|
commit: |
|
https://babeljs.io/docs/babel-register#specifying-options |
Thanks, as is said in the docs, |
I looked into this issue a bit, if we want to completely remove the If performance is your concern, I think what we can do is to disable |
|
It appears that we don't support patterns in the documentation, but only regular expressions and functions. |
I believe this is a doc issue. In somewhere we mentioned that it supports regex / glob, elsewhere regex / function. I have updated the register docs to reflect on the current implementation: babel/website#3190 |
6167bbd to
fdc36b2
Compare
| browserslistConfigFile: false, | ||
| plugins: [], | ||
| presets: [], | ||
| targets: { browsers: undefined }, |
There was a problem hiding this comment.
Currently, babel-core still has to resolve the browser targets, even though it does not determine whether an input file is ignored or not. In the future we should optimize it and resolve targets after the file ignoring logic.
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Sorry, I had this review in my draft and forgot to send it
| @@ -109,8 +119,22 @@ async function transform(input: string, filename: string) { | |||
| return await store({ code, map }); | |||
| } | |||
|
|
|||
| async function isFileIgnored(filename: string) { | |||
There was a problem hiding this comment.
It seems small enough that it's fine to just copy&paste it.
| ); | ||
| expect(output).toContain(path.join("ignored", "ignored-throw.ts")); | ||
| expect(output).toContain( | ||
| "SyntaxError: TypeScript enum is not supported in strip-only mode", |
There was a problem hiding this comment.
This could be thrown also by the non-ignored file if we accidentally ignore it. Could we instead try/catch the require that we expect to throw, and log something that then we check here?
fdc36b2 to
ab65f64
Compare
In this PR we skip the babel-register hook for ignored files in programmatic options. Previously the hook was still registered for ignored files and therefore an ignored
.tsfile may throw syntax error because the original JS loader, where the builtin TS type stripping happens, was skipped aspirateshas no knowledge that Babel does not handle this ignored file.