diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index d44b3c9d80257..d926107d62bec 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -260,15 +260,9 @@ namespace ts { } } - function isJSDocLikeText(text: string, start: number) { - return text.charCodeAt(start + 1) === CharacterCodes.asterisk && - text.charCodeAt(start + 2) === CharacterCodes.asterisk && - text.charCodeAt(start + 3) !== CharacterCodes.slash; - } - function shouldWriteComment(text: string, pos: number) { if (printerOptions.onlyPrintJsDocStyle) { - return (isJSDocLikeText(text, pos) || isPinnedComment(text, pos)); + return (isJsDocStart(text, pos) || isPinnedComment(text, pos)); } return true; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 52e4d5acf6a06..0d4f87744f5ba 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -43,7 +43,7 @@ namespace ts { } /*@internal*/ - export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths?: boolean) { + export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean) { const options = host.getCompilerOptions(); if (sourceFile.kind === SyntaxKind.Bundle) { const jsFilePath = options.outFile || options.out; @@ -129,7 +129,8 @@ namespace ts { let declarationPrinter: Printer; if (emitOnlyDtsFiles || compilerOptions.declaration) { const nonJsFiles = filter(sourceFiles, isSourceFileNotJavaScript); - declarationTransform = transformNodes(resolver, host, compilerOptions, (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles, [transformDeclarations], /*allowDtsFiles*/ false); + const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles; + declarationTransform = transformNodes(resolver, host, compilerOptions, inputListOrBundle, [transformDeclarations], /*allowDtsFiles*/ false); declarationPrinter = createPrinter({ ...compilerOptions, onlyPrintJsDocStyle: true } as PrinterOptions, { // resolver hooks hasGlobalName: resolver.hasGlobalName, @@ -182,9 +183,9 @@ namespace ts { return getOriginalNode(n) === getOriginalNode(sourceFileOrBundle); }); if (associatedDeclarationTree) { - const previousState = sourceMap.setDisabled(true); + const previousState = sourceMap.setState(/*disabled*/ true); printSourceFileOrBundle(declarationFilePath, /*sourceMapFilePath*/ undefined, associatedDeclarationTree, declarationPrinter, /*shouldSkipSourcemap*/ true); - sourceMap.setDisabled(previousState); + sourceMap.setState(previousState); } else { Debug.fail(`No declaration output found for path "${declarationFilePath}" for js output file: "${jsFilePath}".`); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 70ddb7b791df1..147ac6f12a4c9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6416,13 +6416,6 @@ namespace ts { } } - function isJsDocStart(content: string, start: number) { - return content.charCodeAt(start) === CharacterCodes.slash && - content.charCodeAt(start + 1) === CharacterCodes.asterisk && - content.charCodeAt(start + 2) === CharacterCodes.asterisk && - content.charCodeAt(start + 3) !== CharacterCodes.asterisk; - } - function createJSDocComment(): JSDoc { const result = createNode(SyntaxKind.JSDocComment, start); result.tags = tags && createNodeArray(tags, tagsPos, tagsEnd); diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 76656f9235375..14ecbce997cb0 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -71,7 +71,7 @@ namespace ts { /** * @returns the previous disabled state */ - setDisabled(state: boolean): boolean; + setState(disabled: boolean): boolean; } // Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans @@ -112,10 +112,10 @@ namespace ts { emitTokenWithSourceMap, getText, getSourceMappingURL, - setDisabled, + setState, }; - function setDisabled(state: boolean) { + function setState(state: boolean) { const last = disabled; disabled = state; return last; diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index c970dbc08b9d8..d715bed1924e1 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -184,7 +184,7 @@ namespace ts { possibleImports = undefined; importDeclarationMap = createMap(); necessaryTypeRefernces = undefined; - const refs = collectReferences(currentSourceFile); + const refs = collectReferences(currentSourceFile, createMap()); const references: FileReference[] = []; const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath)); const referenceVisitor = mapReferencesIntoArray(references, outputFilePath); @@ -234,7 +234,7 @@ namespace ts { } } - function collectReferences(sourceFile: SourceFile, ret = createMap()) { + function collectReferences(sourceFile: SourceFile, ret: Map) { if (noResolve || isSourceFileJavaScript(sourceFile)) return ret; forEach(sourceFile.referencedFiles, f => { const elem = tryResolveScriptReference(host, sourceFile, f); @@ -797,7 +797,7 @@ namespace ts { switch (input.kind) { case SyntaxKind.ExportDeclaration: { - if (!resultHasExternalModuleIndicator && isSourceFile(input.parent)) { + if (isSourceFile(input.parent)) { resultHasExternalModuleIndicator = true; } // Always visible if the parent node isn't dropped for being not visible @@ -806,7 +806,7 @@ namespace ts { } case SyntaxKind.ExportAssignment: { // Always visible if the parent node isn't dropped for being not visible - if (!resultHasExternalModuleIndicator && isSourceFile(input.parent)) { + if (isSourceFile(input.parent)) { resultHasExternalModuleIndicator = true; } if (input.expression.kind === SyntaxKind.Identifier) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e3518fdc196b2..6b9eef0202951 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -274,6 +274,13 @@ namespace ts { return false; } + export function isJsDocStart(content: string, start: number) { + return content.charCodeAt(start) === CharacterCodes.slash && + content.charCodeAt(start + 1) === CharacterCodes.asterisk && + content.charCodeAt(start + 2) === CharacterCodes.asterisk && + content.charCodeAt(start + 3) !== CharacterCodes.asterisk; + } + export function isPinnedComment(text: string, start: number) { return text.charCodeAt(start + 1) === CharacterCodes.asterisk && text.charCodeAt(start + 2) === CharacterCodes.exclamation;