fix: do not match MySymbol.import("mod")#23358
Conversation
| pos++; | ||
| return token = SyntaxKind.MinusToken; | ||
| case CharacterCodes.dot: | ||
| tokenFlags |= TokenFlags.PrecedingDot; |
There was a problem hiding this comment.
this might need to move right before the return if we understand the flag to denote a single dot.
| function tryConsumeImport(): boolean { | ||
| let token = scanner.getToken(); | ||
| if (token === SyntaxKind.ImportKeyword) { | ||
| if (token === SyntaxKind.ImportKeyword && !scanner.hasPrecedingDot()) { |
There was a problem hiding this comment.
do not think you need to change the scanner API to do this. this whole function is just a mini parser. it advances the scanner each time it needs to consume a token, so you can do it here, no need to change the scanner implementation. for instance, you could have a flag for lastTokenWasDot in nextToken
There was a problem hiding this comment.
I was trying to avoid putting state into the parser, as I saw we had https://github.com/Microsoft/TypeScript/blob/7631ad03a330511418f5cad421b9b876002fcca3/src/compiler/types.ts#L1578-L1579 already. If you are happy for me to store that in a local var, then I will adapt the pull request?
There was a problem hiding this comment.
that is not the parser.. this is just a small parser-like function that tries to speculatively find import/export/require statements.
There was a problem hiding this comment.
Okay, sorry for my wording, I used parser, because you called it a mini parser. So flag in nextToken SGTY?
There was a problem hiding this comment.
yeah. it is already keeping state, one more flag should not harm anyone.
There was a problem hiding this comment.
Ok, will give it a spin 👍
There was a problem hiding this comment.
changes in ee429ef, but for some reason it doesn't work as expected. I am not even sure if the code is run, as I can't figure out from the docs on how to debug the tests or use the watch mode. Plus, process.stdout.write and console.log are not available either, so I am unsure on how to debug this - any pointers @mhegazy?
There was a problem hiding this comment.
jake runtests-browser should run the tests int he browser, you can use the browser dev tools to debug.
| else if (token === SyntaxKind.CloseBraceToken) { | ||
| braceNesting--; | ||
| } | ||
| lastTokenWasDot = token === SyntaxKind.DotToken; |
There was a problem hiding this comment.
should not this be before we consume the next token? this just says token === SyntaxKind.DotToken
|
For debugging, I just use |
That works like a charm, thank you! |
|
|
|
didn't need to introduce more state after all @mhegazy - tests pass locally after a fresh build via |
| let ambientExternalModules: { ref: FileReference, depth: number }[]; | ||
| let braceNesting = 0; | ||
| let lastTokenWasDot = false; | ||
| let lastToken: SyntaxKind = null; |
There was a problem hiding this comment.
do not use null. undefined (or unintialized) is what we have used throughout the code base.
There was a problem hiding this comment.
Yep, I saw, the linter yelled at me :)
| if (token === SyntaxKind.EndOfFileToken) { | ||
| break; | ||
| } | ||
| if (token === SyntaxKind.DotToken) { |
There was a problem hiding this comment.
Should still work, because the next token is a literal, which means that it will go into the else came - I will add a test!
There was a problem hiding this comment.
ah, I see what you mean now. Will fix.
| function nextToken() { | ||
| const token = scanner.scan(); | ||
| if (token === SyntaxKind.OpenBraceToken) { | ||
| if (currentToken) { |
There was a problem hiding this comment.
do not think you need this check.
|
thanks @joscha! |


The quill library has a static method called
importon it's exported symbol, which is used like this:These dependencies are not actually imports, they are strings in a map. Unfortunately
ts.preProcessFilethinks they are valid imports.I tried fixing the issue, but there is some logic missing and I am unsure how to debug the test I added properly with me being able to look at the scanner state. Maybe someone can give me a hint on how to complete my fix, please?
'Bug' or 'help wanted' or is in the Community milestone
masterbranchjake runtestslocally[But the code fails, and I am unsure why]Fixes #23359