Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@ namespace ts {
//
// export * from "mod"
// export {a as b} from "mod"
// export import i = require("mod")

while (token !== SyntaxKind.EndOfFileToken) {
if (token === SyntaxKind.DeclareKeyword) {
Expand Down Expand Up @@ -2276,6 +2277,25 @@ namespace ts {
}
}
}
else if (token === SyntaxKind.ImportKeyword) {
token = scanner.scan();
if (token === SyntaxKind.Identifier || isKeyword(token)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isKeyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contextual keyword. export import of = require..

token = scanner.scan();
if (token === SyntaxKind.EqualsToken) {
token = scanner.scan();
if (token === SyntaxKind.RequireKeyword) {
token = scanner.scan();
if (token === SyntaxKind.OpenParenToken) {
token = scanner.scan();
if (token === SyntaxKind.StringLiteral) {
// export import i = require("mod");
recordModuleName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you had a helper function like

function scanYieldsSequence(scanner: Scanner, seq: (SyntaxKind | ((kind: SyntaxKind) => boolean))[]) {
    for (let item of seq) {
        let passes = item instanceof Function ?
            item(scanner.scan()) :
            item === scanner.scan()
        if (!passes) {
            return false;
        }
    }

    return true;
}

but it might be overkill

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, and yes :)

}
}
}
}
}
}
}
token = scanner.scan();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/cases/unittests/services/preProcessFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ describe('PreProcessFile:', function () {
isLibFile: false
})
});

it("Correctly handeles export import declarations", function () {
test("export import a = require(\"m1\");",
true,
{
referencedFiles: [],
importedFiles: [
{ fileName: "m1", pos: 26, end: 28 }
],
ambientExternalModules: undefined,
isLibFile: false
})
});

});
});