-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix: do not match MySymbol.import("mod") #23358
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
fix: do not match MySymbol.import("mod") #23358
Conversation
src/compiler/scanner.ts
Outdated
@@ -1469,6 +1471,7 @@ namespace ts { | |||
pos++; | |||
return token = SyntaxKind.MinusToken; | |||
case CharacterCodes.dot: | |||
tokenFlags |= TokenFlags.PrecedingDot; |
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 might need to move right before the return
if we understand the flag to denote a single dot.
src/services/preProcess.ts
Outdated
@@ -78,7 +78,7 @@ namespace ts { | |||
*/ | |||
function tryConsumeImport(): boolean { | |||
let token = scanner.getToken(); | |||
if (token === SyntaxKind.ImportKeyword) { | |||
if (token === SyntaxKind.ImportKeyword && !scanner.hasPrecedingDot()) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. it is already keeping state, one more flag should not harm anyone.
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.
Ok, will give it a spin 👍
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jake runtests-browser
should run the tests int he browser, you can use the browser dev tools to debug.
src/services/preProcess.ts
Outdated
@@ -25,6 +26,7 @@ namespace ts { | |||
else if (token === SyntaxKind.CloseBraceToken) { | |||
braceNesting--; | |||
} | |||
lastTokenWasDot = token === SyntaxKind.DotToken; |
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.
should not this be before we consume the next token? this just says token === SyntaxKind.DotToken
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.
Of course, fixed up in 02b8160
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 |
src/services/preProcess.ts
Outdated
@@ -13,20 +13,20 @@ namespace ts { | |||
const importedFiles: FileReference[] = []; | |||
let ambientExternalModules: { ref: FileReference, depth: number }[]; | |||
let braceNesting = 0; | |||
let lastTokenWasDot = false; | |||
let lastToken: SyntaxKind = null; |
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.
do not use null
. undefined
(or unintialized) is what we have used throughout the code base.
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.
Yep, I saw, the linter yelled at me :)
src/services/preProcess.ts
Outdated
break; | ||
} | ||
if (token === SyntaxKind.DotToken) { |
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.
what about a.b.import
?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I see what you mean now. Will fix.
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.
src/services/preProcess.ts
Outdated
let braceNesting = 0; | ||
// assume that text represent an external module if it contains at least one top level import/export | ||
// ambient modules that are found inside external modules are interpreted as module augmentations | ||
let externalModule = false; | ||
|
||
function nextToken() { | ||
const token = scanner.scan(); | ||
if (token === SyntaxKind.OpenBraceToken) { | ||
if (currentToken) { |
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.
do not think you need this check.
thanks @joscha! |
The quill library has a static method called
import
on it's exported symbol, which is used like this:These dependencies are not actually imports, they are strings in a map. Unfortunately
ts.preProcessFile
thinks 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
master
branchjake runtests
locally[But the code fails, and I am unsure why]
Fixes #23359