Skip to content

Commit 6ba1961

Browse files
committed
Fixes elision of import declarations in ES6 modules.
1 parent 816467c commit 6ba1961

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

Jakefile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,15 @@ function runTestsAndWriteOutput(file) {
727727
var tapNotOk = /^not\sok/;
728728
var tapComment = /^#/;
729729
var typeError = /^\s+TypeError:/;
730+
var debugError = /^\s+Error:\sDebug\sFailure\./;
730731
var progress = new ProgressBar("Running tests...");
731732
var expectedTestCount = 0;
732733
var testCount = 0;
733734
var failureCount = 0;
734735
var successCount = 0;
735736
var comments = [];
736737
var typeErrorCount = 0;
738+
var debugErrorCount = 0;
737739

738740
ex.addListener("stdout", function (output) {
739741
var m = tapRange.exec(output);
@@ -757,6 +759,9 @@ function runTestsAndWriteOutput(file) {
757759
else if (typeError.test(output)) {
758760
typeErrorCount++;
759761
}
762+
else if (debugError.test(output)) {
763+
debugErrorCount++;
764+
}
760765
return;
761766
}
762767

@@ -806,6 +811,10 @@ function runTestsAndWriteOutput(file) {
806811
console.log("# type errors: %s", typeErrorCount);
807812
}
808813

814+
if (debugErrorCount) {
815+
console.log("# debug errors: %s", debugErrorCount);
816+
}
817+
809818
deleteTemporaryProjectOutput();
810819
if (beep) process.stdout.write("\u0007");
811820
fail("Process exited with code " + status);

src/compiler/transformers/module/es6.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,35 @@
44
/*@internal*/
55
namespace ts {
66
export function transformES6Module(context: TransformationContext) {
7+
const compilerOptions = context.getCompilerOptions();
8+
const resolver = context.getEmitResolver();
9+
10+
let currentSourceFile: SourceFile;
11+
712
return transformSourceFile;
813

914
function transformSourceFile(node: SourceFile) {
15+
if (isExternalModule(node) || compilerOptions.isolatedModules) {
16+
currentSourceFile = node;
17+
return visitEachChild(node, visitor, context);
18+
}
19+
return node;
20+
}
21+
22+
function visitor(node: Node) {
23+
switch (node.kind) {
24+
case SyntaxKind.ImportDeclaration:
25+
return visitImportDeclaration(<ImportDeclaration>node);
26+
}
27+
28+
return node;
29+
}
30+
31+
function visitImportDeclaration(node: ImportDeclaration) {
32+
if (node.importClause && !resolver.isReferencedAliasDeclaration(node.importClause, /*checkChildren*/ true)) {
33+
return undefined;
34+
}
35+
1036
return node;
1137
}
1238
}

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,7 @@ namespace ts {
34053405
|| kind === SyntaxKind.TypeAliasDeclaration
34063406
|| kind === SyntaxKind.EnumDeclaration
34073407
|| kind === SyntaxKind.ModuleDeclaration
3408+
|| kind === SyntaxKind.ImportDeclaration
34083409
|| kind === SyntaxKind.ImportEqualsDeclaration
34093410
|| kind === SyntaxKind.ExportDeclaration
34103411
|| kind === SyntaxKind.ExportAssignment;

0 commit comments

Comments
 (0)