Skip to content

Commit 3cb6c9c

Browse files
author
Yui T
committed
Add isDeclarationFile and update similar all usage
1 parent 6cb7ffb commit 3cb6c9c

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ module ts {
2525
return indentStrings[1].length;
2626
}
2727

28-
function isDeclarationFile(sourceFile: SourceFile): boolean {
29-
if (sourceFile.flags & NodeFlags.DeclarationFile) {
30-
return true;
31-
}
32-
return false;
33-
}
34-
3528
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
3629
if (!isDeclarationFile(sourceFile)) {
3730
if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.filename, ".js")) {
@@ -43,7 +36,7 @@ module ts {
4336
}
4437

4538
export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
46-
return isExternalModule(sourceFile) || (sourceFile.flags & NodeFlags.DeclarationFile) !== 0;
39+
return isExternalModule(sourceFile) || isDeclarationFile(sourceFile);
4740
}
4841

4942
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature

src/compiler/parser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ module ts {
111111
return file.externalModuleIndicator !== undefined;
112112
}
113113

114+
export function isDeclarationFile(file: SourceFile): boolean {
115+
return (file.flags & NodeFlags.DeclarationFile) !== 0;
116+
}
117+
114118
export function isPrologueDirective(node: Node): boolean {
115119
return node.kind === SyntaxKind.ExpressionStatement && (<ExpressionStatement>node).expression.kind === SyntaxKind.StringLiteral;
116120
}
@@ -4125,7 +4129,7 @@ module ts {
41254129
}
41264130
}
41274131
}
4128-
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || file.flags & NodeFlags.DeclarationFile)) {
4132+
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) {
41294133
// TypeScript 1.0 spec (April 2014): 12.1.6
41304134
// An AmbientExternalModuleDeclaration declares an external module.
41314135
// This type of declaration is permitted only in the global module.

0 commit comments

Comments
 (0)