Skip to content
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

[DRAFT] Support import references for import.meta.resolve(…). #59945

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lgarron
Copy link

@lgarron lgarron commented Sep 12, 2024

This is a draft implementation of support for including import.meta.resolve(…) in the call graph, per #43759

It includes code under .temp for testing purposes. This can be tested using:

hereby local
node ./built/local/tsc.js --project ".temp/test/tsconfig.json"

As of right now, the compiler crashes because I need help figuring out how to construct an appropriate call expression; I've created this draft PR both to ask for this help and to solicit feedback on the approach in general.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 12, 2024
});

if (foundImportMetaResolve) {
sourceFlags |= NodeFlags.PossiblyContainsDynamicImport;
Copy link
Author

Choose a reason for hiding this comment

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

I think it makes sense to reuse this flag, but I could introduce a new flag specific to import.meta.resolve(…) if that's preferable.


// TODO: use `parseRightSideOfDot`?
const foundImportMetaResolve = tryParse(() => {
// `meta` and `resolve` are not JavaScript keywords, so we attempt to look for the direct string identifiers to recognizer `import.meta.resolve(…)`.
Copy link
Author

Choose a reason for hiding this comment

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

I think this is the right choice, please let me know if I should add more keywords to SyntaxKind!

Comment on lines +5947 to +5950
expression = {} as any; // TODO: calculate the expression. Here are some failed attempts:
// expression = finishNode(factoryCreateCallExpression(factoryCreateExpressionStatement(), undefined, parseArgumentList()), pos) as any;
// expression = parseTokenNode<PrimaryExpression>();
// expression = finishNode(factoryCreateToken(SyntaxKind.ImportMetaResolveExpression), getNodePos()) as PrimaryExpression;
Copy link
Author

Choose a reason for hiding this comment

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

I need help constructing expression to be an ImportCall matching the ImportMetaResolveExpression interface (i.e. with a kind type/value of SyntaxKind.ImportMetaResolveExpression).

I can't figure out how to do this based off of existing code, as the left-hand expression import.meta.resolve is not a token and the expression-related code in types.ts and parser.ts all see. Should this be an identifier? A PropertyAccessExpression? I'd appreciate any help in figuring out what to do.

sourceFlags |= NodeFlags.PossiblyContainsImportMeta;
const identifierName = parseIdentifierName();

// TODO: use `parseRightSideOfDot`?
Copy link
Author

Choose a reason for hiding this comment

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

Would this be a better idiom?

@@ -0,0 +1,3 @@
const entry = import.meta.resolve("./worker")
Copy link
Author

Choose a reason for hiding this comment

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

The main result of this PR should be that:

  1. this argument rewritten to "./worker.js", and
  2. worker.ts is included in the call graph and transpiled even if that file is removed from tsconfig.json.

Once I get this working, I'll remove .temp and move it into a proper test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants