Skip to content

Commit

Permalink
Fix issue microsoft#15230
Browse files Browse the repository at this point in the history
  • Loading branch information
hami9x committed May 15, 2017
1 parent 1becbf4 commit a5bd742
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/compiler/parser.ts
Expand Up @@ -463,6 +463,10 @@ namespace ts {
return file.externalModuleIndicator !== undefined;
}

export function isInternalModule(file: SourceFile): boolean {
return file.internalModuleIndicator !== undefined;
}

// Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter
// indicates what changed between the 'text' that this SourceFile has and the 'newText'.
// The SourceFile will be created with the compiler attempting to reuse as many nodes from
Expand Down Expand Up @@ -675,7 +679,7 @@ namespace ts {
Debug.assert(token() === SyntaxKind.EndOfFileToken);
sourceFile.endOfFileToken = <EndOfFileToken>parseTokenNode();

setExternalModuleIndicator(sourceFile);
setInternalExternalModuleIndicators(sourceFile)

sourceFile.nodeCount = nodeCount;
sourceFile.identifierCount = identifierCount;
Expand Down Expand Up @@ -5912,15 +5916,20 @@ namespace ts {
sourceFile.checkJsDirective = checkJsDirective;
}

function setExternalModuleIndicator(sourceFile: SourceFile) {
sourceFile.externalModuleIndicator = forEach(sourceFile.statements, node =>
hasModifier(node, ModifierFlags.Export)
function setInternalExternalModuleIndicators(sourceFile: SourceFile) {
forEach(sourceFile.statements, node => {
if (hasModifier(node, ModifierFlags.Export)
|| node.kind === SyntaxKind.ImportEqualsDeclaration && (<ImportEqualsDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference
|| node.kind === SyntaxKind.ImportDeclaration
|| node.kind === SyntaxKind.ExportAssignment
|| node.kind === SyntaxKind.ExportDeclaration
? node
: undefined);
) {
sourceFile.externalModuleIndicator = node
}
else if (node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.NamespaceImport) {
sourceFile.internalModuleIndicator = node
}
})
}

const enum ParsingContext {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Expand Up @@ -1754,7 +1754,7 @@ namespace ts {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher));
}

const firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined);
const firstNonExternalModuleSourceFile = forEach(files, f => isInternalModule(f) && !isDeclarationFile(f) ? f : undefined);
if (firstNonExternalModuleSourceFile) {
const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile);
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided));
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/types.ts
Expand Up @@ -2288,6 +2288,8 @@ namespace ts {

// The first node that causes this file to be an external module
/* @internal */ externalModuleIndicator: Node;
// The first node that causes this file to be an internal module
/* @internal */ internalModuleIndicator: Node;
// The first node that causes this file to be a CommonJS module
/* @internal */ commonJsModuleIndicator: Node;

Expand Down

0 comments on commit a5bd742

Please sign in to comment.