Skip to content

Commit 44f08d3

Browse files
committed
Slight cleanup from code review feedback
1 parent 4c639b8 commit 44f08d3

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

src/compiler/comments.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,9 @@ namespace ts {
260260
}
261261
}
262262

263-
function isJSDocLikeText(text: string, start: number) {
264-
return text.charCodeAt(start + 1) === CharacterCodes.asterisk &&
265-
text.charCodeAt(start + 2) === CharacterCodes.asterisk &&
266-
text.charCodeAt(start + 3) !== CharacterCodes.slash;
267-
}
268-
269263
function shouldWriteComment(text: string, pos: number) {
270264
if (printerOptions.onlyPrintJsDocStyle) {
271-
return (isJSDocLikeText(text, pos) || isPinnedComment(text, pos));
265+
return (isJsDocStart(text, pos) || isPinnedComment(text, pos));
272266
}
273267
return true;
274268
}

src/compiler/emitter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts {
4343
}
4444

4545
/*@internal*/
46-
export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths?: boolean) {
46+
export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean) {
4747
const options = host.getCompilerOptions();
4848
if (sourceFile.kind === SyntaxKind.Bundle) {
4949
const jsFilePath = options.outFile || options.out;
@@ -129,7 +129,8 @@ namespace ts {
129129
let declarationPrinter: Printer;
130130
if (emitOnlyDtsFiles || compilerOptions.declaration) {
131131
const nonJsFiles = filter(sourceFiles, isSourceFileNotJavaScript);
132-
declarationTransform = transformNodes(resolver, host, compilerOptions, (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles, [transformDeclarations], /*allowDtsFiles*/ false);
132+
const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles;
133+
declarationTransform = transformNodes(resolver, host, compilerOptions, inputListOrBundle, [transformDeclarations], /*allowDtsFiles*/ false);
133134
declarationPrinter = createPrinter({ ...compilerOptions, onlyPrintJsDocStyle: true } as PrinterOptions, {
134135
// resolver hooks
135136
hasGlobalName: resolver.hasGlobalName,
@@ -182,9 +183,9 @@ namespace ts {
182183
return getOriginalNode(n) === getOriginalNode(sourceFileOrBundle);
183184
});
184185
if (associatedDeclarationTree) {
185-
const previousState = sourceMap.setDisabled(true);
186+
const previousState = sourceMap.setState(/*disabled*/ true);
186187
printSourceFileOrBundle(declarationFilePath, /*sourceMapFilePath*/ undefined, associatedDeclarationTree, declarationPrinter, /*shouldSkipSourcemap*/ true);
187-
sourceMap.setDisabled(previousState);
188+
sourceMap.setState(previousState);
188189
}
189190
else {
190191
Debug.fail(`No declaration output found for path "${declarationFilePath}" for js output file: "${jsFilePath}".`);

src/compiler/parser.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6416,13 +6416,6 @@ namespace ts {
64166416
}
64176417
}
64186418

6419-
function isJsDocStart(content: string, start: number) {
6420-
return content.charCodeAt(start) === CharacterCodes.slash &&
6421-
content.charCodeAt(start + 1) === CharacterCodes.asterisk &&
6422-
content.charCodeAt(start + 2) === CharacterCodes.asterisk &&
6423-
content.charCodeAt(start + 3) !== CharacterCodes.asterisk;
6424-
}
6425-
64266419
function createJSDocComment(): JSDoc {
64276420
const result = <JSDoc>createNode(SyntaxKind.JSDocComment, start);
64286421
result.tags = tags && createNodeArray(tags, tagsPos, tagsEnd);

src/compiler/sourcemap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace ts {
7171
/**
7272
* @returns the previous disabled state
7373
*/
74-
setDisabled(state: boolean): boolean;
74+
setState(disabled: boolean): boolean;
7575
}
7676

7777
// Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans
@@ -112,10 +112,10 @@ namespace ts {
112112
emitTokenWithSourceMap,
113113
getText,
114114
getSourceMappingURL,
115-
setDisabled,
115+
setState,
116116
};
117117

118-
function setDisabled(state: boolean) {
118+
function setState(state: boolean) {
119119
const last = disabled;
120120
disabled = state;
121121
return last;

src/compiler/transformers/declarations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace ts {
184184
possibleImports = undefined;
185185
importDeclarationMap = createMap();
186186
necessaryTypeRefernces = undefined;
187-
const refs = collectReferences(currentSourceFile);
187+
const refs = collectReferences(currentSourceFile, createMap());
188188
const references: FileReference[] = [];
189189
const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath));
190190
const referenceVisitor = mapReferencesIntoArray(references, outputFilePath);
@@ -234,7 +234,7 @@ namespace ts {
234234
}
235235
}
236236

237-
function collectReferences(sourceFile: SourceFile, ret = createMap<SourceFile>()) {
237+
function collectReferences(sourceFile: SourceFile, ret: Map<SourceFile>) {
238238
if (noResolve || isSourceFileJavaScript(sourceFile)) return ret;
239239
forEach(sourceFile.referencedFiles, f => {
240240
const elem = tryResolveScriptReference(host, sourceFile, f);
@@ -797,7 +797,7 @@ namespace ts {
797797

798798
switch (input.kind) {
799799
case SyntaxKind.ExportDeclaration: {
800-
if (!resultHasExternalModuleIndicator && isSourceFile(input.parent)) {
800+
if (isSourceFile(input.parent)) {
801801
resultHasExternalModuleIndicator = true;
802802
}
803803
// Always visible if the parent node isn't dropped for being not visible
@@ -806,7 +806,7 @@ namespace ts {
806806
}
807807
case SyntaxKind.ExportAssignment: {
808808
// Always visible if the parent node isn't dropped for being not visible
809-
if (!resultHasExternalModuleIndicator && isSourceFile(input.parent)) {
809+
if (isSourceFile(input.parent)) {
810810
resultHasExternalModuleIndicator = true;
811811
}
812812
if (input.expression.kind === SyntaxKind.Identifier) {

src/compiler/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ namespace ts {
274274
return false;
275275
}
276276

277+
export function isJsDocStart(content: string, start: number) {
278+
return content.charCodeAt(start) === CharacterCodes.slash &&
279+
content.charCodeAt(start + 1) === CharacterCodes.asterisk &&
280+
content.charCodeAt(start + 2) === CharacterCodes.asterisk &&
281+
content.charCodeAt(start + 3) !== CharacterCodes.asterisk;
282+
}
283+
277284
export function isPinnedComment(text: string, start: number) {
278285
return text.charCodeAt(start + 1) === CharacterCodes.asterisk &&
279286
text.charCodeAt(start + 2) === CharacterCodes.exclamation;

0 commit comments

Comments
 (0)