-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
base: main
Are you sure you want to change the base?
Conversation
a36bf32
to
721ead6
Compare
}); | ||
|
||
if (foundImportMetaResolve) { | ||
sourceFlags |= NodeFlags.PossiblyContainsDynamicImport; |
There was a problem hiding this comment.
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(…)`. |
There was a problem hiding this comment.
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
!
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; |
There was a problem hiding this comment.
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`? |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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:
- this argument rewritten to
"./worker.js"
, and worker.ts
is included in the call graph and transpiled even if that file is removed fromtsconfig.json
.
Once I get this working, I'll remove .temp
and move it into a proper test.
This is a draft implementation of support for including
import.meta.resolve(…)
in the call graph, per #43759It includes code under
.temp
for testing purposes. This can be tested using: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.