fix: do not match MySymbol.import("mod")

This commit is contained in:
Joscha Feth 2018-04-12 19:31:07 +10:00
parent edcf087145
commit 4da2e5eda3
5 changed files with 22 additions and 1 deletions

View File

@ -2929,6 +2929,7 @@ declare namespace ts {
getTokenText(): string;
getTokenValue(): string;
hasExtendedUnicodeEscape(): boolean;
hasPrecedingDot(): boolean;
hasPrecedingLineBreak(): boolean;
isIdentifier(): boolean;
isReservedWord(): boolean;

View File

@ -22,6 +22,7 @@ namespace ts {
getTokenText(): string;
getTokenValue(): string;
hasExtendedUnicodeEscape(): boolean;
hasPrecedingDot(): boolean;
hasPrecedingLineBreak(): boolean;
isIdentifier(): boolean;
isReservedWord(): boolean;
@ -833,6 +834,7 @@ namespace ts {
getTokenText: () => text.substring(tokenPos, pos),
getTokenValue: () => tokenValue,
hasExtendedUnicodeEscape: () => (tokenFlags & TokenFlags.ExtendedUnicodeEscape) !== 0,
hasPrecedingDot: () => (tokenFlags & TokenFlags.PrecedingDot) !== 0,
hasPrecedingLineBreak: () => (tokenFlags & TokenFlags.PrecedingLineBreak) !== 0,
isIdentifier: () => token === SyntaxKind.Identifier || token > SyntaxKind.LastReservedWord,
isReservedWord: () => token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord,
@ -1469,6 +1471,7 @@ namespace ts {
pos++;
return token = SyntaxKind.MinusToken;
case CharacterCodes.dot:
tokenFlags |= TokenFlags.PrecedingDot;
if (isDigit(text.charCodeAt(pos + 1))) {
tokenValue = scanNumber();
return token = SyntaxKind.NumericLiteral;

View File

@ -1585,6 +1585,7 @@ namespace ts {
BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000`
OctalSpecifier = 1 << 8, // e.g. `0o777`
ContainsSeparator = 1 << 9, // e.g. `0b1100_0101`
PrecedingDot = 1 << 10,
BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier,
NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinarySpecifier | OctalSpecifier | ContainsSeparator
}

View File

@ -59,6 +59,19 @@ describe("PreProcessFile:", () => {
});
}),
it("Do not return reference path of non-imports", () => {
test("Quill.import('delta');",
/*readImportFile*/ true,
/*detectJavaScriptImports*/ false,
{
referencedFiles: <ts.FileReference[]>[],
importedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
ambientExternalModules: undefined,
isLibFile: false
});
}),
it("Correctly return imported files", () => {
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\");",
/*readImportFile*/ true,

View File

@ -78,7 +78,7 @@ namespace ts {
*/
function tryConsumeImport(): boolean {
let token = scanner.getToken();
if (token === SyntaxKind.ImportKeyword) {
if (token === SyntaxKind.ImportKeyword && !scanner.hasPrecedingDot()) {
token = nextToken();
if (token === SyntaxKind.OpenParenToken) {
token = nextToken();
@ -293,6 +293,9 @@ namespace ts {
// export import i = require("mod")
// (for JavaScript files) require("mod")
// Do not look for:
// AnySymbol.import("mod")
while (true) {
if (scanner.getToken() === SyntaxKind.EndOfFileToken) {
break;