Skip to content

Conversation

@wagenet
Copy link
Contributor

@wagenet wagenet commented Aug 27, 2025

We already fixed types for extension-less imports but this fixes explicit extensions.

@wagenet wagenet marked this pull request as ready for review August 29, 2025 20:12
);
return multiValueResolver(values, 'project');
} else {
// For allowArbitraryExtensions - return first found value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this comment here? the code doesn't do anything with any specific option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like something that got left behind on accident.

if (tsconfigPaths.length > 0) {
const allowJsValues = tsconfigPaths.map((cfg) => parseAllowJsFromTsconfig(cfg, rootDir));
return resolveAllowJs(allowJsValues, 'project');
if (multiValueResolver) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this multi-value resolver feels a bit silly.
It's only used by getAllowJs, and no other code cares - so this makes the factoring of this function feel a bit wierd.

Like, the tasks of collecting tsconfigs feels different from getting the value from a collection of tsconfigs.

at the same time, I almost think having a whole control from for multiValueResolver is silly, and we should get rid of it, but instead have a different mechanism for warning when tsconfigs have conflicting values.

atm, this feels like its trying to be too generic, but is actually a very specific use case, so it's an unneeded abstraction (so far).

I would get rid of the multiValueResolver entirely.

And instead, have a hard-coded list of properties that we want to warn about conflicting values for.

Then, in the (currently) else branch below, do:

if (WARN_ON_CONFLICT.has(property)) {
  printWarnIfConflict(tsconfigPaths, rootDir, property);
}

for (const tsconfigPath of tsconfigPaths) {
      const result = parseCompilerOptionFromTsconfig(tsconfigPath, rootDir, property);
      if (result !== undefined) return result;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was probably the AI over optimizing.

const programAllowArbitraryExtensions =
result.services.program.getCompilerOptions?.()?.allowArbitraryExtensions;
if (
!allowArbitraryExtensionsWasSet &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this situation happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I wish I knew! I've seen it actually happen with allowGjs.

}
if (fileName.endsWith('.gts') || (allowGjs && fileName.endsWith('.gjs'))) {
// Only transform template files, not declaration files
if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to account for .d.gjs.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but we should clean it up. Since a file can't both end with .gts and also end with .d.ts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a relevant test file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose ts importing gjs is good, ya

Allow importing files with arbitrary extensions like .d.gjs.ts
*/
"allowArbitraryExtensions": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should flat-ts actually be duplicated to a different folder (flat-ts-arbitrary-extensions) -- since we have control flows that run when this is false, I think we should retain that, and create a separate test project for this use case -- all the new files can be moved in to that new project

@@ -1,2 +1,2 @@
const Bar = () => <template></template>;
const Bar = () => {return <template></template>};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI! :shakes-fist:

expect(importDeclarations[1].specifiers[0].imported.name).toBe('ApiClient');
expect(importDeclarations[1].specifiers[1].imported.name).toBe('DefaultClient');

// Verify that our extension replacement transforms .gjs to .mjs for TypeScript processing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why combine these assertions with the import verification assertions in this test?

feels like testing replaceExtensions is sort of a different thing altogether than the importDeclarations testing above

const { patchTs, replaceExtensions } = require('../src/parser/ts-patch');
patchTs({ allowGjs: true });

const transformedCode = replaceExtensions(codeWithComplexGjsImports);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

(!fileName.endsWith('.d.ts') && fileName.endsWith('.ts')) ||
fileName.endsWith('.gts') ||
(allowGjs && fileName.endsWith('.gjs'))
(fileName.endsWith('.gts') && !fileName.endsWith('.d.ts')) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should clean this up too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants