Skip to content

Commit 4da2e5e

Browse files
committed
fix: do not match MySymbol.import("mod")
1 parent edcf087 commit 4da2e5e

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

lib/typescriptServices.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,6 +2929,7 @@ declare namespace ts {
29292929
getTokenText(): string;
29302930
getTokenValue(): string;
29312931
hasExtendedUnicodeEscape(): boolean;
2932+
hasPrecedingDot(): boolean;
29322933
hasPrecedingLineBreak(): boolean;
29332934
isIdentifier(): boolean;
29342935
isReservedWord(): boolean;

src/compiler/scanner.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ts {
2222
getTokenText(): string;
2323
getTokenValue(): string;
2424
hasExtendedUnicodeEscape(): boolean;
25+
hasPrecedingDot(): boolean;
2526
hasPrecedingLineBreak(): boolean;
2627
isIdentifier(): boolean;
2728
isReservedWord(): boolean;
@@ -833,6 +834,7 @@ namespace ts {
833834
getTokenText: () => text.substring(tokenPos, pos),
834835
getTokenValue: () => tokenValue,
835836
hasExtendedUnicodeEscape: () => (tokenFlags & TokenFlags.ExtendedUnicodeEscape) !== 0,
837+
hasPrecedingDot: () => (tokenFlags & TokenFlags.PrecedingDot) !== 0,
836838
hasPrecedingLineBreak: () => (tokenFlags & TokenFlags.PrecedingLineBreak) !== 0,
837839
isIdentifier: () => token === SyntaxKind.Identifier || token > SyntaxKind.LastReservedWord,
838840
isReservedWord: () => token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord,
@@ -1469,6 +1471,7 @@ namespace ts {
14691471
pos++;
14701472
return token = SyntaxKind.MinusToken;
14711473
case CharacterCodes.dot:
1474+
tokenFlags |= TokenFlags.PrecedingDot;
14721475
if (isDigit(text.charCodeAt(pos + 1))) {
14731476
tokenValue = scanNumber();
14741477
return token = SyntaxKind.NumericLiteral;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,7 @@ namespace ts {
15851585
BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000`
15861586
OctalSpecifier = 1 << 8, // e.g. `0o777`
15871587
ContainsSeparator = 1 << 9, // e.g. `0b1100_0101`
1588+
PrecedingDot = 1 << 10,
15881589
BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier,
15891590
NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinarySpecifier | OctalSpecifier | ContainsSeparator
15901591
}

src/harness/unittests/services/preProcessFile.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ describe("PreProcessFile:", () => {
5959
});
6060
}),
6161

62+
it("Do not return reference path of non-imports", () => {
63+
test("Quill.import('delta');",
64+
/*readImportFile*/ true,
65+
/*detectJavaScriptImports*/ false,
66+
{
67+
referencedFiles: <ts.FileReference[]>[],
68+
importedFiles: <ts.FileReference[]>[],
69+
typeReferenceDirectives: [],
70+
ambientExternalModules: undefined,
71+
isLibFile: false
72+
});
73+
}),
74+
6275
it("Correctly return imported files", () => {
6376
test("import i1 = require(\"r1.ts\"); import i2 =require(\"r2.ts\"); import i3= require(\"r3.ts\"); import i4=require(\"r4.ts\"); import i5 = require (\"r5.ts\");",
6477
/*readImportFile*/ true,

src/services/preProcess.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace ts {
7878
*/
7979
function tryConsumeImport(): boolean {
8080
let token = scanner.getToken();
81-
if (token === SyntaxKind.ImportKeyword) {
81+
if (token === SyntaxKind.ImportKeyword && !scanner.hasPrecedingDot()) {
8282
token = nextToken();
8383
if (token === SyntaxKind.OpenParenToken) {
8484
token = nextToken();
@@ -293,6 +293,9 @@ namespace ts {
293293
// export import i = require("mod")
294294
// (for JavaScript files) require("mod")
295295

296+
// Do not look for:
297+
// AnySymbol.import("mod")
298+
296299
while (true) {
297300
if (scanner.getToken() === SyntaxKind.EndOfFileToken) {
298301
break;

0 commit comments

Comments
 (0)