-
Notifications
You must be signed in to change notification settings - Fork 309
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
test: add failing test cases with single file transpilation for JIT transformers #2615
Draft
ahnpnl
wants to merge
1
commit into
main
Choose a base branch
from
infra/add-transformer-unit-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If
type
is expected to beundefined
, then why are we trying to resolve theimport *
? It doesn't seem like we shouldn't need that type? I wonder if the correct behavior on resolution error would just be to fall back toany
as the type (and emitundefined
)?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.
This case produces very interesting output
I saw that the
type
was resolved correctly when using import name or default import but fail with import namespace.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.
Hmm, any of these could be an interface which wouldn't be valid in
type
though. I wonder if the type system is falling back toany
because it can't be resolved and then we're assuming the import is a valid value reference. I wonder if the safer assumption would be to fall back totype: undefined
in that scenario?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.
You were right. When I do
typeChecker.getTypeOfSymbol(symbol)
, it gave meany
.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.
In retrospect,
any
might not necessarily be a problem. Both type references and value references can be typedany
, so that might be fine. I wonder if it's possible to ask TS whether or not each import is a value reference or a type reference. I'm guessing it's assuming imported symbols are a value reference when it can't resolve the import and we'd probably want to reduce that assumption to a type reference in this scenario.Unfortunately I'm not very familiar with the TS API and docs are pretty lacking, so I'm not sure about the best way to verify that.
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.
We could probably work around this problem a different way. Since this is the Angular decorator transform, we know a few things:
@Inject
must reference a type declaration that's also a value (and thus it's fine to "assume" when transpiling).@Inject
don't need atype
output at all, and we can unconditionally generatetype: undefined
.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.
For the 2nd case, can we unconditionally NOT generating
undefined
so that it’s possible to run tests and leave it up to Jest runtime to validate if that is valid runtime value?For example:
import foo from ‘./foo’
would resolve intype
astype: foo.<something>
And the same applies to
import * as foo from ‘./foo’
If we set
type: undefined
, it will break all existing tests and it makes it not possible to run tests in transpilation mode because there will be error likeCan't resolve all parameters for AppComponent: (?)
which I observe when debugging this issue #963