From 3cb6c9cf4538ba2f4ff49de6060ae9ed248d6f54 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Oct 2014 14:19:36 -0700 Subject: [PATCH] Add isDeclarationFile and update similar all usage --- src/compiler/emitter.ts | 9 +-------- src/compiler/parser.ts | 6 +++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7d3537b4866..fdf9efaf38a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -25,13 +25,6 @@ module ts { return indentStrings[1].length; } - function isDeclarationFile(sourceFile: SourceFile): boolean { - if (sourceFile.flags & NodeFlags.DeclarationFile) { - return true; - } - return false; - } - export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { if (!isDeclarationFile(sourceFile)) { if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) { @@ -43,7 +36,7 @@ module ts { } export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { - return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0; + return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); } // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a43f31e583a..f67a54c17c1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -111,6 +111,10 @@ module ts { return file.externalModuleIndicator !== undefined; } + export function isDeclarationFile(file: SourceFile): boolean { + return (file.flags & NodeFlags.DeclarationFile) !== 0; + } + export function isPrologueDirective(node: Node): boolean { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; } @@ -4125,7 +4129,7 @@ module ts { } } } - else if (node.kind === SyntaxKind.ModuleDeclaration && (node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || file.flags & NodeFlags.DeclarationFile)) { + else if (node.kind === SyntaxKind.ModuleDeclaration && (node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) { // TypeScript 1.0 spec (April 2014): 12.1.6 // An AmbientExternalModuleDeclaration declares an external module. // This type of declaration is permitted only in the global module.