diff --git a/.settings/tasks.json b/.vscode/tasks.json similarity index 100% rename from .settings/tasks.json rename to .vscode/tasks.json diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 48ad97ad4f9..c49ff726ed4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4640,7 +4640,9 @@ namespace ts { // and intersection types are further deconstructed on the target side, we don't want to // make the check again (as it might fail for a partial target type). Therefore we obtain // the regular source type and proceed with that. - source = getRegularTypeOfObjectLiteral(source); + if (target.flags & TypeFlags.UnionOrIntersection) { + source = getRegularTypeOfObjectLiteral(source); + } } let saveErrorInfo = errorInfo; @@ -5511,6 +5513,7 @@ namespace ts { regularType.constructSignatures = (type).constructSignatures; regularType.stringIndexType = (type).stringIndexType; regularType.numberIndexType = (type).numberIndexType; + (type).regularType = regularType; } return regularType; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d84b7b70ada..4fa14e775ac 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -186,6 +186,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi /** Sourcemap data that will get encoded */ let sourceMapData: SourceMapData; + /** If removeComments is true, no leading-comments needed to be emitted **/ + let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? function (pos: number) { } : emitLeadingCommentsOfPositionWorker; + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { initializeEmitterWithSourceMaps(); } @@ -1292,8 +1295,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function jsxEmitPreserve(node: JsxElement|JsxSelfClosingElement) { function emitJsxAttribute(node: JsxAttribute) { emit(node.name); - write("="); - emit(node.initializer); + if (node.initializer) { + write("="); + emit(node.initializer); + } } function emitJsxSpreadAttribute(node: JsxSpreadAttribute) { @@ -2352,7 +2357,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi operand.kind !== SyntaxKind.PostfixUnaryExpression && operand.kind !== SyntaxKind.NewExpression && !(operand.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.NewExpression) && - !(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression)) { + !(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression) && + !(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression)) { emit(operand); return; } @@ -3666,7 +3672,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { - return emitOnlyPinnedOrTripleSlashComments(node); + return emitCommentsOnNotEmittedNode(node); } // TODO (yuisu) : we should not have special cases to condition emitting comments @@ -4143,7 +4149,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { - return emitOnlyPinnedOrTripleSlashComments(member); + return emitCommentsOnNotEmittedNode(member); } writeLine(); @@ -4210,7 +4216,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitMemberFunctionsForES6AndHigher(node: ClassLikeDeclaration) { for (let member of node.members) { if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { - emitOnlyPinnedOrTripleSlashComments(member); + emitCommentsOnNotEmittedNode(member); } else if (member.kind === SyntaxKind.MethodDeclaration || member.kind === SyntaxKind.GetAccessor || @@ -4267,7 +4273,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitOnlyPinnedOrTripleSlashComments(member); + emitCommentsOnNotEmittedNode(member); } // Check if there is any non-static property assignment if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { @@ -5166,7 +5172,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitInterfaceDeclaration(node: InterfaceDeclaration) { - emitOnlyPinnedOrTripleSlashComments(node); + emitCommentsOnNotEmittedNode(node); } function shouldEmitEnumDeclaration(node: EnumDeclaration) { @@ -5288,7 +5294,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { - return emitOnlyPinnedOrTripleSlashComments(node); + return emitCommentsOnNotEmittedNode(node); } let hoistedInDeclarationScope = shouldHoistDeclarationInSystemJsModule(node); let emitVarForModule = !hoistedInDeclarationScope && !isModuleMergedWithES6Class(node); @@ -6718,7 +6724,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitNodeConsideringCommentsOption(node: Node, emitNodeConsideringSourcemap: (node: Node) => void): void { if (node) { if (node.flags & NodeFlags.Ambient) { - return emitOnlyPinnedOrTripleSlashComments(node); + return emitCommentsOnNotEmittedNode(node); } if (isSpecializedCommentHandling(node)) { @@ -6985,22 +6991,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return leadingComments; } - /** - * Removes all but the pinned or triple slash comments. - * @param ranges The array to be filtered - * @param onlyPinnedOrTripleSlashComments whether the filtering should be performed. - */ - function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { - // If we're removing comments, then we want to strip out all but the pinned or - // triple slash comments. - if (ranges && onlyPinnedOrTripleSlashComments) { - ranges = filter(ranges, isPinnedOrTripleSlashComment); - if (ranges.length === 0) { - return undefined; - } - } + function isPinnedComments(comment: CommentRange) { + return currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; + } - return ranges; + /** + * Determine if the given comment is a triple-slash + * + * @return true if the comment is a triple-slash comment else false + **/ + function isTripleSlashComment(comment: CommentRange) { + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash) { + let textSubStr = currentSourceFile.text.substring(comment.pos, comment.end); + return textSubStr.match(fullTripleSlashReferencePathRegEx) || + textSubStr.match(fullTripleSlashAMDReferencePathRegEx) ? + true : false; + } + return false; } function getLeadingCommentsToEmit(node: Node) { @@ -7028,28 +7040,53 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } } - function emitOnlyPinnedOrTripleSlashComments(node: Node) { - emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ true); + /** + * Emit comments associated with node that will not be emitted into JS file + */ + function emitCommentsOnNotEmittedNode(node: Node) { + emitLeadingCommentsWorker(node, /*isEmittedNode:*/ false); } function emitLeadingComments(node: Node) { - return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + return emitLeadingCommentsWorker(node, /*isEmittedNode:*/ true); } - function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { - // If the caller only wants pinned or triple slash comments, then always filter - // down to that set. Otherwise, filter based on the current compiler options. - let leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments); + function emitLeadingCommentsWorker(node: Node, isEmittedNode: boolean) { + if (compilerOptions.removeComments) { + return; + } + + let leadingComments: CommentRange[]; + if (isEmittedNode) { + leadingComments = getLeadingCommentsToEmit(node); + } + else { + // If the node will not be emitted in JS, remove all the comments(normal, pinned and ///) associated with the node, + // unless it is a triple slash comment at the top of the file. + // For Example: + // /// + // declare var x; + // /// + // interface F {} + // The first /// will NOT be removed while the second one will be removed eventhough both node will not be emitted + if (node.pos === 0) { + leadingComments = filter(getLeadingCommentsToEmit(node), isTripleSlashComment); + } + } emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); + emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator:*/ true, newLine, writeComment); } function emitTrailingComments(node: Node) { + if (compilerOptions.removeComments) { + return; + } + // Emit the trailing comments only if the parent's end doesn't match - let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + let trailingComments = getTrailingCommentsToEmit(node); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); @@ -7061,13 +7098,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi * ^ => pos; the function will emit "comment1" in the emitJS */ function emitTrailingCommentsOfPosition(pos: number) { - let trailingComments = filterComments(getTrailingCommentRanges(currentSourceFile.text, pos), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + if (compilerOptions.removeComments) { + return; + } + + let trailingComments = getTrailingCommentRanges(currentSourceFile.text, pos); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitLeadingCommentsOfPosition(pos: number) { + function emitLeadingCommentsOfPositionWorker(pos: number) { + if (compilerOptions.removeComments) { + return; + } + let leadingComments: CommentRange[]; if (hasDetachedComments(pos)) { // get comments without detached comments @@ -7078,7 +7123,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } - leadingComments = filterComments(leadingComments, compilerOptions.removeComments); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space @@ -7086,7 +7130,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function emitDetachedComments(node: TextRange) { - let leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); + let leadingComments: CommentRange[]; + if (compilerOptions.removeComments) { + // removeComments is true, only reserve pinned comment at the top of file + // For example: + // /*! Pinned Comment */ + // + // var x = 10; + if (node.pos === 0) { + leadingComments = filter(getLeadingCommentRanges(currentSourceFile.text, node.pos), isPinnedComments); + } + } + else { + // removeComments is false, just get detached as normal and bypass the process to filter comment + leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); + } + if (leadingComments) { let detachedComments: CommentRange[] = []; let lastComment: CommentRange; @@ -7136,20 +7195,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(shebang); } } - - function isPinnedOrTripleSlashComment(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { - return true; - } - } } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 350b9d450b8..330ad05518b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1058,11 +1058,11 @@ namespace ts { } function parseIdentifierName(): Identifier { - return createIdentifier(isIdentifierOrKeyword()); + return createIdentifier(tokenIsIdentifierOrKeyword(token)); } function isLiteralPropertyName(): boolean { - return isIdentifierOrKeyword() || + return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral; } @@ -1086,7 +1086,7 @@ namespace ts { } function isSimplePropertyName() { - return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || isIdentifierOrKeyword(); + return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token); } function parseComputedPropertyName(): ComputedPropertyName { @@ -1213,9 +1213,9 @@ namespace ts { case ParsingContext.HeritageClauses: return isHeritageClause(); case ParsingContext.ImportOrExportSpecifiers: - return isIdentifierOrKeyword(); + return tokenIsIdentifierOrKeyword(token); case ParsingContext.JsxAttributes: - return isIdentifierOrKeyword() || token === SyntaxKind.OpenBraceToken; + return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.OpenBraceToken; case ParsingContext.JsxChildren: return true; case ParsingContext.JSDocFunctionParameters: @@ -1254,7 +1254,7 @@ namespace ts { function nextTokenIsIdentifierOrKeyword() { nextToken(); - return isIdentifierOrKeyword(); + return tokenIsIdentifierOrKeyword(token); } function isHeritageClauseExtendsOrImplementsKeyword(): boolean { @@ -1824,7 +1824,7 @@ namespace ts { // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword". // In the first case though, ASI will not take effect because there is not a // line terminator after the identifier or keyword. - if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) { + if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) { let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { @@ -2282,7 +2282,7 @@ namespace ts { } } - if (isIdentifierOrKeyword()) { + if (tokenIsIdentifierOrKeyword(token)) { return parsePropertyOrMethodSignature(); } } @@ -4101,13 +4101,9 @@ namespace ts { } } - function isIdentifierOrKeyword() { - return token >= SyntaxKind.Identifier; - } - function nextTokenIsIdentifierOrKeywordOnSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak(); } function nextTokenIsFunctionKeywordOnSameLine() { @@ -4117,7 +4113,7 @@ namespace ts { function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); - return (isIdentifierOrKeyword() || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); + return (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); } function isDeclaration(): boolean { @@ -4170,7 +4166,7 @@ namespace ts { case SyntaxKind.ImportKeyword: nextToken(); return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword(); + token === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token); case SyntaxKind.ExportKeyword: nextToken(); if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || @@ -4777,7 +4773,7 @@ namespace ts { // It is very important that we check this *after* checking indexers because // the [ token can start an index signature or a computed property name - if (isIdentifierOrKeyword() || + if (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || token === SyntaxKind.AsteriskToken || @@ -5320,7 +5316,7 @@ namespace ts { return true; } - return isIdentifierOrKeyword(); + return tokenIsIdentifierOrKeyword(token); } export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 790d121d135..92fbfebce6c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -334,7 +334,8 @@ namespace ts { export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program { let program: Program; let files: SourceFile[] = []; - let diagnostics = createDiagnosticCollection(); + let fileProcessingDiagnostics = createDiagnosticCollection(); + let programDiagnostics = createDiagnosticCollection(); let commonSourceDirectory: string; let diagnosticsProducingTypeChecker: TypeChecker; @@ -404,6 +405,7 @@ namespace ts { getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(), getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(), getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(), + getFileProcessingDiagnostics: () => fileProcessingDiagnostics }; return program; @@ -436,6 +438,7 @@ namespace ts { // check if program source files has changed in the way that can affect structure of the program let newSourceFiles: SourceFile[] = []; + let modifiedSourceFiles: SourceFile[] = []; for (let oldSourceFile of oldProgram.getSourceFiles()) { let newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target); if (!newSourceFile) { @@ -482,6 +485,7 @@ namespace ts { } // pass the cache of module resolutions from the old source file newSourceFile.resolvedModules = oldSourceFile.resolvedModules; + modifiedSourceFiles.push(newSourceFile); } else { // file has no changes - use it as is @@ -498,7 +502,11 @@ namespace ts { } files = newSourceFiles; + fileProcessingDiagnostics = oldProgram.getFileProcessingDiagnostics(); + for (let modifiedFile of modifiedSourceFiles) { + fileProcessingDiagnostics.reattachFileDiagnostics(modifiedFile); + } oldProgram.structureIsReused = true; return true; @@ -628,9 +636,10 @@ namespace ts { Debug.assert(!!sourceFile.bindDiagnostics); let bindDiagnostics = sourceFile.bindDiagnostics; let checkDiagnostics = typeChecker.getDiagnostics(sourceFile, cancellationToken); - let programDiagnostics = diagnostics.getDiagnostics(sourceFile.fileName); + let fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); + let programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); + return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); }); } @@ -647,7 +656,8 @@ namespace ts { function getOptionsDiagnostics(): Diagnostic[] { let allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, diagnostics.getGlobalDiagnostics()); + addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()) + addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); return sortAndDeduplicateDiagnostics(allDiagnostics); } @@ -755,10 +765,10 @@ namespace ts { if (diagnostic) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument)); + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument)); } else { - diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument)); } } } @@ -780,11 +790,11 @@ namespace ts { // We haven't looked for this file, do so now and cache result let file = host.getSourceFile(fileName, options.target, hostErrorMessage => { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } else { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); filesByName.set(canonicalName, file); @@ -820,11 +830,11 @@ namespace ts { let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { - diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, + fileProcessingDiagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } else { - diagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); + fileProcessingDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName)); } } } @@ -874,7 +884,7 @@ namespace ts { return; function findModuleSourceFile(fileName: string, nameLiteral: Expression) { - return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end); + return findSourceFile(fileName, /* isDefaultLib */ false, file, skipTrivia(file.text, nameLiteral.pos), nameLiteral.end); } } @@ -899,7 +909,7 @@ namespace ts { for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { if (commonPathComponents[i] !== sourcePathComponents[i]) { if (i === 0) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); return; } @@ -928,7 +938,7 @@ namespace ts { if (!isDeclarationFile(sourceFile)) { let absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); allFilesBelongToPath = false; } } @@ -941,52 +951,52 @@ namespace ts { function verifyCompilerOptions() { if (options.isolatedModules) { if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules")); } if (options.noEmitOnError) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules")); } if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules")); } if (options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules")); } } if (options.inlineSourceMap) { if (options.sourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap")); } if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap")); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap")); } } if (options.inlineSources) { if (!options.sourceMap && !options.inlineSourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } if (options.out && options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile")); } if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap")); } if (options.sourceRoot) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap")); } return; } @@ -997,24 +1007,24 @@ namespace ts { let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (options.isolatedModules) { if (!options.module && languageVersion < ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); if (firstNonExternalModuleSourceFile) { let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided)); } // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_modules_into_commonjs_amd_system_or_umd_when_targeting_ES6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot @@ -1043,30 +1053,30 @@ namespace ts { if (options.noEmit) { if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out")); } if (options.outFile) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile")); } if (options.outDir) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir")); } if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration")); } } if (options.emitDecoratorMetadata && !options.experimentalDecorators) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } if (options.experimentalAsyncFunctions && options.target !== ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower)); } } } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 199e7e9b638..82fbc8c2a59 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -6,6 +6,11 @@ namespace ts { (message: DiagnosticMessage, length: number): void; } + /* @internal */ + export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean { + return token >= SyntaxKind.Identifier; + } + export interface Scanner { getStartPos(): number; getToken(): SyntaxKind; @@ -1590,7 +1595,7 @@ namespace ts { // Scans a JSX identifier; these differ from normal identifiers in that // they allow dashes function scanJsxIdentifier(): SyntaxKind { - if (token === SyntaxKind.Identifier) { + if (tokenIsIdentifierOrKeyword(token)) { let firstCharPosition = pos; while (pos < end) { let ch = text.charCodeAt(pos); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fd21cc79ab6..40773b4fc23 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1359,6 +1359,7 @@ namespace ts { /* @internal */ getSymbolCount(): number; /* @internal */ getTypeCount(): number; + /* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection; // For testing purposes only. /* @internal */ structureIsReused?: boolean; } @@ -2331,5 +2332,7 @@ namespace ts { // operation caused diagnostics to be returned by storing and comparing the return value // of this method before/after the operation is performed. getModificationCount(): number; + + /* @internal */ reattachFileDiagnostics(newFile: SourceFile): void; } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 096907cef62..ed8b516b7f3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -435,6 +435,7 @@ namespace ts { } export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; + export let fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; export function isTypeNode(node: Node): boolean { if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { @@ -1507,12 +1508,23 @@ namespace ts { add, getGlobalDiagnostics, getDiagnostics, - getModificationCount + getModificationCount, + reattachFileDiagnostics }; function getModificationCount() { return modificationCount; } + + function reattachFileDiagnostics(newFile: SourceFile): void { + if (!hasProperty(fileDiagnostics, newFile.fileName)) { + return; + } + + for (let diagnostic of fileDiagnostics[newFile.fileName]) { + diagnostic.file = newFile; + } + } function add(diagnostic: Diagnostic): void { let diagnostics: Diagnostic[]; diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 876efa3a9e1..02e785f6b3e 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -213,27 +213,11 @@ namespace ts.formatting { public NoSpaceBetweenYieldKeywordAndStar: Rule; public SpaceBetweenYieldOrYieldStarAndOperand: Rule; - // Async-await + // Async functions public SpaceBetweenAsyncAndFunctionKeyword: Rule; - public NoSpaceBetweenAsyncAndFunctionKeyword: Rule; - public SpaceAfterAwaitKeyword: Rule; - public NoSpaceAfterAwaitKeyword: Rule; - - // Type alias declaration - public SpaceAfterTypeKeyword: Rule; - public NoSpaceAfterTypeKeyword: Rule; // Tagged template string public SpaceBetweenTagAndTemplateString: Rule; - public NoSpaceBetweenTagAndTemplateString: Rule; - - // Type operation - public SpaceBeforeBar: Rule; - public NoSpaceBeforeBar: Rule; - public SpaceAfterBar: Rule; - public NoSpaceAfterBar: Rule; - public SpaceBeforeAmpersand: Rule; - public SpaceAfterAmpersand: Rule; constructor() { /// @@ -315,7 +299,7 @@ namespace ts.formatting { this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.AwaitKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space)); this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete)); this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space)); @@ -348,7 +332,7 @@ namespace ts.formatting { this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { @@ -384,25 +368,9 @@ namespace ts.formatting { // Async-await this.SpaceBetweenAsyncAndFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBetweenAsyncAndFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.SpaceAfterAwaitKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.AwaitKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceAfterAwaitKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.AwaitKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - - // Type alias declaration - this.SpaceAfterTypeKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.TypeKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceAfterTypeKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.TypeKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // template string this.SpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - - // type operation - this.SpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.SpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.NoSpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.SpaceBeforeAmpersand = new Rule(RuleDescriptor.create3(SyntaxKind.AmpersandToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - this.SpaceAfterAmpersand = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.AmpersandToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = @@ -430,12 +398,8 @@ namespace ts.formatting { this.NoSpaceBeforeOpenParenInFuncCall, this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator, this.SpaceAfterVoidOperator, - this.SpaceBetweenAsyncAndFunctionKeyword, this.NoSpaceBetweenAsyncAndFunctionKeyword, - this.SpaceAfterAwaitKeyword, this.NoSpaceAfterAwaitKeyword, - this.SpaceAfterTypeKeyword, this.NoSpaceAfterTypeKeyword, - this.SpaceBetweenTagAndTemplateString, this.NoSpaceBetweenTagAndTemplateString, - this.SpaceBeforeBar, this.NoSpaceBeforeBar, this.SpaceAfterBar, this.NoSpaceAfterBar, - this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand, + this.SpaceBetweenAsyncAndFunctionKeyword, + this.SpaceBetweenTagAndTemplateString, // TypeScript-specific rules this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport, @@ -539,6 +503,8 @@ namespace ts.formatting { case SyntaxKind.ConditionalExpression: case SyntaxKind.AsExpression: case SyntaxKind.TypePredicate: + case SyntaxKind.UnionType: + case SyntaxKind.IntersectionType: return true; // equals in binding elements: function foo([[x, y] = [1, 2]]) diff --git a/tests/baselines/reference/castExpressionParentheses.js b/tests/baselines/reference/castExpressionParentheses.js index ec18d6e373e..b4754d0ad41 100644 --- a/tests/baselines/reference/castExpressionParentheses.js +++ b/tests/baselines/reference/castExpressionParentheses.js @@ -7,6 +7,11 @@ declare var a; ([1,3,]); ("string"); (23.0); +(1); +(1.); +(1.0); +(12e+34); +(0xff); (/regexp/g); (false); (true); @@ -23,6 +28,12 @@ declare var a; declare var A; // should keep the parentheses in emit +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +((1.0)); (new A).foo; (typeof A).x; (-A).x; @@ -46,6 +57,11 @@ new (A()); [1, 3,]; "string"; 23.0; +1; +1.; +1.0; +12e+34; +0xff; /regexp/g; false; true; @@ -59,6 +75,12 @@ a[0]; a.b["0"]; a().x; // should keep the parentheses in emit +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +(1.0); (new A).foo; (typeof A).x; (-A).x; diff --git a/tests/baselines/reference/castExpressionParentheses.symbols b/tests/baselines/reference/castExpressionParentheses.symbols index 7bc8169e40f..ef31ee0f226 100644 --- a/tests/baselines/reference/castExpressionParentheses.symbols +++ b/tests/baselines/reference/castExpressionParentheses.symbols @@ -10,6 +10,11 @@ declare var a; ([1,3,]); ("string"); (23.0); +(1); +(1.); +(1.0); +(12e+34); +(0xff); (/regexp/g); (false); (true); @@ -33,36 +38,42 @@ declare var a; >a : Symbol(a, Decl(castExpressionParentheses.ts, 0, 11)) declare var A; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // should keep the parentheses in emit +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +((1.0)); (new A).foo; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (typeof A).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (-A).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) new (A()); ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) (()=> {})(); ->Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 28, 2)) +>Tany : Symbol(Tany, Decl(castExpressionParentheses.ts, 39, 2)) (function foo() { })(); ->foo : Symbol(foo, Decl(castExpressionParentheses.ts, 29, 6)) +>foo : Symbol(foo, Decl(castExpressionParentheses.ts, 40, 6)) (-A).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // nested cast, should keep one pair of parenthese ((-A)).x; ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) // nested parenthesized expression, should keep one pair of parenthese ((A)) ->A : Symbol(A, Decl(castExpressionParentheses.ts, 21, 11)) +>A : Symbol(A, Decl(castExpressionParentheses.ts, 26, 11)) diff --git a/tests/baselines/reference/castExpressionParentheses.types b/tests/baselines/reference/castExpressionParentheses.types index ab563a4e8b7..cdfbf4f7db2 100644 --- a/tests/baselines/reference/castExpressionParentheses.types +++ b/tests/baselines/reference/castExpressionParentheses.types @@ -28,6 +28,31 @@ declare var a; >23.0 : any >23.0 : number +(1); +>(1) : any +>1 : any +>1 : number + +(1.); +>(1.) : any +>1. : any +>1. : number + +(1.0); +>(1.0) : any +>1.0 : any +>1.0 : number + +(12e+34); +>(12e+34) : any +>12e+34 : any +>12e+34 : number + +(0xff); +>(0xff) : any +>0xff : any +>0xff : number + (/regexp/g); >(/regexp/g) : any >/regexp/g : any @@ -104,6 +129,47 @@ declare var A; >A : any // should keep the parentheses in emit +(1).foo; +>(1).foo : any +>(1) : any +>1 : any +>1 : number +>foo : any + +(1.).foo; +>(1.).foo : any +>(1.) : any +>1. : any +>1. : number +>foo : any + +(1.0).foo; +>(1.0).foo : any +>(1.0) : any +>1.0 : any +>1.0 : number +>foo : any + +(12e+34).foo; +>(12e+34).foo : any +>(12e+34) : any +>12e+34 : any +>12e+34 : number +>foo : any + +(0xff).foo; +>(0xff).foo : any +>(0xff) : any +>0xff : any +>0xff : number +>foo : any + +((1.0)); +>((1.0)) : any +>(1.0) : any +>(1.0) : number +>1.0 : number + (new A).foo; >(new A).foo : any >(new A) : any diff --git a/tests/baselines/reference/commentOnAmbientClass1.js b/tests/baselines/reference/commentOnAmbientClass1.js index beacc71335c..9837da4c371 100644 --- a/tests/baselines/reference/commentOnAmbientClass1.js +++ b/tests/baselines/reference/commentOnAmbientClass1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientClass1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { } @@ -15,6 +20,9 @@ declare class E extends C { } //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientClass1.symbols b/tests/baselines/reference/commentOnAmbientClass1.symbols index 899c5f19a24..a08bb744df4 100644 --- a/tests/baselines/reference/commentOnAmbientClass1.symbols +++ b/tests/baselines/reference/commentOnAmbientClass1.symbols @@ -5,13 +5,18 @@ declare class E extends C { >C : Symbol(C, Decl(a.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { >C : Symbol(C, Decl(a.ts, 0, 0)) } // Don't keep this comment. declare class D { ->D : Symbol(D, Decl(a.ts, 2, 1)) +>D : Symbol(D, Decl(a.ts, 7, 1)) } diff --git a/tests/baselines/reference/commentOnAmbientClass1.types b/tests/baselines/reference/commentOnAmbientClass1.types index 44c0334ef6c..b0212056505 100644 --- a/tests/baselines/reference/commentOnAmbientClass1.types +++ b/tests/baselines/reference/commentOnAmbientClass1.types @@ -5,7 +5,12 @@ declare class E extends C { >C : C } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { >C : C } diff --git a/tests/baselines/reference/commentOnAmbientEnum.js b/tests/baselines/reference/commentOnAmbientEnum.js index d602c68a0e5..f6c9d92ebff 100644 --- a/tests/baselines/reference/commentOnAmbientEnum.js +++ b/tests/baselines/reference/commentOnAmbientEnum.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientEnum.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { a, b, @@ -18,6 +23,9 @@ declare enum E { } //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientEnum.symbols b/tests/baselines/reference/commentOnAmbientEnum.symbols index d86d490113d..3a6e8089d4b 100644 --- a/tests/baselines/reference/commentOnAmbientEnum.symbols +++ b/tests/baselines/reference/commentOnAmbientEnum.symbols @@ -4,22 +4,27 @@ declare enum E { >E : Symbol(E, Decl(b.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { >C : Symbol(C, Decl(a.ts, 0, 0)) a, ->a : Symbol(C.a, Decl(a.ts, 1, 16)) +>a : Symbol(C.a, Decl(a.ts, 6, 16)) b, ->b : Symbol(C.b, Decl(a.ts, 2, 6)) +>b : Symbol(C.b, Decl(a.ts, 7, 6)) c ->c : Symbol(C.c, Decl(a.ts, 3, 6)) +>c : Symbol(C.c, Decl(a.ts, 8, 6)) } // Don't keep this comment. declare enum D { ->D : Symbol(D, Decl(a.ts, 5, 1)) +>D : Symbol(D, Decl(a.ts, 10, 1)) } diff --git a/tests/baselines/reference/commentOnAmbientEnum.types b/tests/baselines/reference/commentOnAmbientEnum.types index 4a0193b7937..95f3d61b75f 100644 --- a/tests/baselines/reference/commentOnAmbientEnum.types +++ b/tests/baselines/reference/commentOnAmbientEnum.types @@ -4,7 +4,12 @@ declare enum E { >E : E } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { >C : C diff --git a/tests/baselines/reference/commentOnAmbientModule.js b/tests/baselines/reference/commentOnAmbientModule.js index d5a536302b5..2d43b502f29 100644 --- a/tests/baselines/reference/commentOnAmbientModule.js +++ b/tests/baselines/reference/commentOnAmbientModule.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientModule.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { function foo(); } @@ -20,6 +25,9 @@ declare module E { } //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientModule.symbols b/tests/baselines/reference/commentOnAmbientModule.symbols index c1412c17880..e7525e6306f 100644 --- a/tests/baselines/reference/commentOnAmbientModule.symbols +++ b/tests/baselines/reference/commentOnAmbientModule.symbols @@ -5,28 +5,33 @@ declare module E { class foobar extends D.bar { >foobar : Symbol(foobar, Decl(b.ts, 1, 18)) ->D.bar : Symbol(D.bar, Decl(a.ts, 6, 18)) ->D : Symbol(D, Decl(a.ts, 3, 1)) ->bar : Symbol(D.bar, Decl(a.ts, 6, 18)) +>D.bar : Symbol(D.bar, Decl(a.ts, 11, 18)) +>D : Symbol(D, Decl(a.ts, 8, 1)) +>bar : Symbol(D.bar, Decl(a.ts, 11, 18)) foo(); >foo : Symbol(foo, Decl(b.ts, 2, 32)) } } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { >C : Symbol(C, Decl(a.ts, 0, 0)) function foo(); ->foo : Symbol(foo, Decl(a.ts, 1, 18)) +>foo : Symbol(foo, Decl(a.ts, 6, 18)) } // Don't keep this comment. declare module D { ->D : Symbol(D, Decl(a.ts, 3, 1)) +>D : Symbol(D, Decl(a.ts, 8, 1)) class bar { } ->bar : Symbol(bar, Decl(a.ts, 6, 18)) +>bar : Symbol(bar, Decl(a.ts, 11, 18)) } diff --git a/tests/baselines/reference/commentOnAmbientModule.types b/tests/baselines/reference/commentOnAmbientModule.types index 629395a4e80..f54d248b461 100644 --- a/tests/baselines/reference/commentOnAmbientModule.types +++ b/tests/baselines/reference/commentOnAmbientModule.types @@ -14,7 +14,12 @@ declare module E { } } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { >C : typeof C diff --git a/tests/baselines/reference/commentOnAmbientVariable1.js b/tests/baselines/reference/commentOnAmbientVariable1.js index b76fd3345b5..79c5dc85f23 100644 --- a/tests/baselines/reference/commentOnAmbientVariable1.js +++ b/tests/baselines/reference/commentOnAmbientVariable1.js @@ -1,9 +1,17 @@ //// [commentOnAmbientVariable1.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; // Don't keep this comment. declare var y: number; //// [commentOnAmbientVariable1.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ diff --git a/tests/baselines/reference/commentOnAmbientVariable1.symbols b/tests/baselines/reference/commentOnAmbientVariable1.symbols index 153653e7827..7847b4b85ad 100644 --- a/tests/baselines/reference/commentOnAmbientVariable1.symbols +++ b/tests/baselines/reference/commentOnAmbientVariable1.symbols @@ -1,9 +1,14 @@ === tests/cases/compiler/commentOnAmbientVariable1.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; ->v : Symbol(v, Decl(commentOnAmbientVariable1.ts, 1, 11)) +>v : Symbol(v, Decl(commentOnAmbientVariable1.ts, 6, 11)) // Don't keep this comment. declare var y: number; ->y : Symbol(y, Decl(commentOnAmbientVariable1.ts, 4, 11)) +>y : Symbol(y, Decl(commentOnAmbientVariable1.ts, 9, 11)) diff --git a/tests/baselines/reference/commentOnAmbientVariable1.types b/tests/baselines/reference/commentOnAmbientVariable1.types index feff50f4293..645e1f099d4 100644 --- a/tests/baselines/reference/commentOnAmbientVariable1.types +++ b/tests/baselines/reference/commentOnAmbientVariable1.types @@ -1,5 +1,10 @@ === tests/cases/compiler/commentOnAmbientVariable1.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; >v : number diff --git a/tests/baselines/reference/commentOnAmbientfunction.js b/tests/baselines/reference/commentOnAmbientfunction.js index 6290d407727..22613236941 100644 --- a/tests/baselines/reference/commentOnAmbientfunction.js +++ b/tests/baselines/reference/commentOnAmbientfunction.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnAmbientfunction.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); // Don't keep this comment. @@ -12,6 +17,9 @@ declare function bar(); declare function foobar(a: typeof foo): typeof bar; //// [a.js] -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnAmbientfunction.symbols b/tests/baselines/reference/commentOnAmbientfunction.symbols index c6afb72eb9c..4d83d2794a0 100644 --- a/tests/baselines/reference/commentOnAmbientfunction.symbols +++ b/tests/baselines/reference/commentOnAmbientfunction.symbols @@ -4,14 +4,19 @@ declare function foobar(a: typeof foo): typeof bar; >foobar : Symbol(foobar, Decl(b.ts, 0, 0)) >a : Symbol(a, Decl(b.ts, 1, 24)) >foo : Symbol(foo, Decl(a.ts, 0, 0)) ->bar : Symbol(bar, Decl(a.ts, 1, 23)) +>bar : Symbol(bar, Decl(a.ts, 6, 23)) === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); >foo : Symbol(foo, Decl(a.ts, 0, 0)) // Don't keep this comment. declare function bar(); ->bar : Symbol(bar, Decl(a.ts, 1, 23)) +>bar : Symbol(bar, Decl(a.ts, 6, 23)) diff --git a/tests/baselines/reference/commentOnAmbientfunction.types b/tests/baselines/reference/commentOnAmbientfunction.types index f75f7b377fb..3347a55bf68 100644 --- a/tests/baselines/reference/commentOnAmbientfunction.types +++ b/tests/baselines/reference/commentOnAmbientfunction.types @@ -7,7 +7,12 @@ declare function foobar(a: typeof foo): typeof bar; >bar : () => any === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); >foo : () => any diff --git a/tests/baselines/reference/commentOnElidedModule1.js b/tests/baselines/reference/commentOnElidedModule1.js index 8a7b8d91b4c..72585e6a9e8 100644 --- a/tests/baselines/reference/commentOnElidedModule1.js +++ b/tests/baselines/reference/commentOnElidedModule1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnElidedModule1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { } @@ -15,6 +20,9 @@ module ElidedModule3 { } //// [a.js] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnElidedModule1.symbols b/tests/baselines/reference/commentOnElidedModule1.symbols index 63ce4dadf97..57b55adeee4 100644 --- a/tests/baselines/reference/commentOnElidedModule1.symbols +++ b/tests/baselines/reference/commentOnElidedModule1.symbols @@ -4,13 +4,18 @@ module ElidedModule3 { >ElidedModule3 : Symbol(ElidedModule3, Decl(b.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { >ElidedModule : Symbol(ElidedModule, Decl(a.ts, 0, 0)) } // Don't keep this comment. module ElidedModule2 { ->ElidedModule2 : Symbol(ElidedModule2, Decl(a.ts, 2, 1)) +>ElidedModule2 : Symbol(ElidedModule2, Decl(a.ts, 7, 1)) } diff --git a/tests/baselines/reference/commentOnElidedModule1.types b/tests/baselines/reference/commentOnElidedModule1.types index 8e095b8102f..d028b62519a 100644 --- a/tests/baselines/reference/commentOnElidedModule1.types +++ b/tests/baselines/reference/commentOnElidedModule1.types @@ -4,7 +4,12 @@ module ElidedModule3 { >ElidedModule3 : any } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { >ElidedModule : any } diff --git a/tests/baselines/reference/commentOnInterface1.js b/tests/baselines/reference/commentOnInterface1.js index bde6202f03f..c51658e2dfa 100644 --- a/tests/baselines/reference/commentOnInterface1.js +++ b/tests/baselines/reference/commentOnInterface1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnInterface1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { } @@ -15,6 +20,9 @@ interface I3 { } //// [a.js] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ //// [b.js] /// diff --git a/tests/baselines/reference/commentOnInterface1.symbols b/tests/baselines/reference/commentOnInterface1.symbols index 9564d9b4cfa..8ed7e020712 100644 --- a/tests/baselines/reference/commentOnInterface1.symbols +++ b/tests/baselines/reference/commentOnInterface1.symbols @@ -4,13 +4,18 @@ interface I3 { >I3 : Symbol(I3, Decl(b.ts, 0, 0)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { >I : Symbol(I, Decl(a.ts, 0, 0)) } // Don't keep this comment. interface I2 { ->I2 : Symbol(I2, Decl(a.ts, 2, 1)) +>I2 : Symbol(I2, Decl(a.ts, 7, 1)) } diff --git a/tests/baselines/reference/commentOnInterface1.types b/tests/baselines/reference/commentOnInterface1.types index d03b1939026..34b0e0ce14f 100644 --- a/tests/baselines/reference/commentOnInterface1.types +++ b/tests/baselines/reference/commentOnInterface1.types @@ -4,7 +4,12 @@ interface I3 { >I3 : I3 } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { >I : I } diff --git a/tests/baselines/reference/commentOnSignature1.js b/tests/baselines/reference/commentOnSignature1.js index 1b2327f9861..d29710c631c 100644 --- a/tests/baselines/reference/commentOnSignature1.js +++ b/tests/baselines/reference/commentOnSignature1.js @@ -1,7 +1,12 @@ //// [tests/cases/compiler/commentOnSignature1.ts] //// //// [a.ts] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; // Don't keep this comment. function foo(s: string): void; @@ -33,14 +38,15 @@ function foo2(a: any): void { } //// [a.js] -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ function foo(a) { } var c = (function () { - /*! keep this pinned comment */ function c(a) { } - /*! keep this pinned comment */ c.prototype.foo = function (a) { }; return c; diff --git a/tests/baselines/reference/commentOnSignature1.symbols b/tests/baselines/reference/commentOnSignature1.symbols index 0d39565fb61..7f0d48401cd 100644 --- a/tests/baselines/reference/commentOnSignature1.symbols +++ b/tests/baselines/reference/commentOnSignature1.symbols @@ -14,49 +14,54 @@ function foo2(a: any): void { >a : Symbol(a, Decl(b.ts, 4, 14)) } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; ->foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 1, 30), Decl(a.ts, 3, 30)) ->n : Symbol(n, Decl(a.ts, 1, 13)) +>foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 30), Decl(a.ts, 8, 30)) +>n : Symbol(n, Decl(a.ts, 6, 13)) // Don't keep this comment. function foo(s: string): void; ->foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 1, 30), Decl(a.ts, 3, 30)) ->s : Symbol(s, Decl(a.ts, 3, 13)) +>foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 30), Decl(a.ts, 8, 30)) +>s : Symbol(s, Decl(a.ts, 8, 13)) function foo(a: any): void { ->foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 1, 30), Decl(a.ts, 3, 30)) ->a : Symbol(a, Decl(a.ts, 4, 13)) +>foo : Symbol(foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 30), Decl(a.ts, 8, 30)) +>a : Symbol(a, Decl(a.ts, 9, 13)) } class c { ->c : Symbol(c, Decl(a.ts, 5, 1)) +>c : Symbol(c, Decl(a.ts, 10, 1)) // dont keep this comment constructor(a: string); ->a : Symbol(a, Decl(a.ts, 9, 16)) +>a : Symbol(a, Decl(a.ts, 14, 16)) /*! keep this pinned comment */ constructor(a: number); ->a : Symbol(a, Decl(a.ts, 11, 16)) +>a : Symbol(a, Decl(a.ts, 16, 16)) constructor(a: any) { ->a : Symbol(a, Decl(a.ts, 12, 16)) +>a : Symbol(a, Decl(a.ts, 17, 16)) } // dont keep this comment foo(a: string); ->foo : Symbol(foo, Decl(a.ts, 13, 5), Decl(a.ts, 16, 19), Decl(a.ts, 18, 19)) ->a : Symbol(a, Decl(a.ts, 16, 8)) +>foo : Symbol(foo, Decl(a.ts, 18, 5), Decl(a.ts, 21, 19), Decl(a.ts, 23, 19)) +>a : Symbol(a, Decl(a.ts, 21, 8)) /*! keep this pinned comment */ foo(a: number); ->foo : Symbol(foo, Decl(a.ts, 13, 5), Decl(a.ts, 16, 19), Decl(a.ts, 18, 19)) ->a : Symbol(a, Decl(a.ts, 18, 8)) +>foo : Symbol(foo, Decl(a.ts, 18, 5), Decl(a.ts, 21, 19), Decl(a.ts, 23, 19)) +>a : Symbol(a, Decl(a.ts, 23, 8)) foo(a: any) { ->foo : Symbol(foo, Decl(a.ts, 13, 5), Decl(a.ts, 16, 19), Decl(a.ts, 18, 19)) ->a : Symbol(a, Decl(a.ts, 19, 8)) +>foo : Symbol(foo, Decl(a.ts, 18, 5), Decl(a.ts, 21, 19), Decl(a.ts, 23, 19)) +>a : Symbol(a, Decl(a.ts, 24, 8)) } } diff --git a/tests/baselines/reference/commentOnSignature1.types b/tests/baselines/reference/commentOnSignature1.types index 790aaaf7523..30898e22851 100644 --- a/tests/baselines/reference/commentOnSignature1.types +++ b/tests/baselines/reference/commentOnSignature1.types @@ -14,7 +14,12 @@ function foo2(a: any): void { >a : any } === tests/cases/compiler/a.ts === -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; >foo : { (n: number): void; (s: string): void; } >n : number diff --git a/tests/baselines/reference/doNotEmitDetachedComments.js b/tests/baselines/reference/doNotEmitDetachedComments.js new file mode 100644 index 00000000000..74acb537fa8 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedComments.js @@ -0,0 +1,33 @@ +//// [doNotEmitDetachedComments.ts] +/* + + multi line + comment +*/ + +var x = 10; + +// Single Line comment + +function foo() { } + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } + + +//======================== + + +//// [doNotEmitDetachedComments.js] +var x = 10; +function foo() { } +function bar() { } diff --git a/tests/baselines/reference/doNotEmitDetachedComments.symbols b/tests/baselines/reference/doNotEmitDetachedComments.symbols new file mode 100644 index 00000000000..c718da7bb9a --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedComments.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/doNotEmitDetachedComments.ts === +/* + + multi line + comment +*/ + +var x = 10; +>x : Symbol(x, Decl(doNotEmitDetachedComments.ts, 6, 3)) + +// Single Line comment + +function foo() { } +>foo : Symbol(foo, Decl(doNotEmitDetachedComments.ts, 6, 11)) + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } +>bar : Symbol(bar, Decl(doNotEmitDetachedComments.ts, 10, 18)) + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitDetachedComments.types b/tests/baselines/reference/doNotEmitDetachedComments.types new file mode 100644 index 00000000000..d9b5f0634c2 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedComments.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/doNotEmitDetachedComments.ts === +/* + + multi line + comment +*/ + +var x = 10; +>x : number +>10 : number + +// Single Line comment + +function foo() { } +>foo : () => void + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } +>bar : () => void + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js new file mode 100644 index 00000000000..ba6dbf8b743 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.js @@ -0,0 +1,64 @@ +//// [doNotEmitDetachedCommentsAtStartOfConstructor.ts] +class A { + constructor() { + // Single Line Comment + + var x = 10; + } +} + +class B { + constructor() { + /* + Multi-line comment + */ + + var y = 10; + } +} + +class C { + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; + } +} + +class D { + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; + } +} + +//// [doNotEmitDetachedCommentsAtStartOfConstructor.js] +var A = (function () { + function A() { + var x = 10; + } + return A; +})(); +var B = (function () { + function B() { + var y = 10; + } + return B; +})(); +var C = (function () { + function C() { + var x = 10; + } + return C; +})(); +var D = (function () { + function D() { + var y = 10; + } + return D; +})(); diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols new file mode 100644 index 00000000000..d7c4f5b2ca9 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.symbols @@ -0,0 +1,50 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts === +class A { +>A : Symbol(A, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 0, 0)) + + constructor() { + // Single Line Comment + + var x = 10; +>x : Symbol(x, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 4, 11)) + } +} + +class B { +>B : Symbol(B, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 6, 1)) + + constructor() { + /* + Multi-line comment + */ + + var y = 10; +>y : Symbol(y, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 14, 11)) + } +} + +class C { +>C : Symbol(C, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 16, 1)) + + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; +>x : Symbol(x, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 23, 11)) + } +} + +class D { +>D : Symbol(D, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 25, 1)) + + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; +>y : Symbol(y, Decl(doNotEmitDetachedCommentsAtStartOfConstructor.ts, 34, 11)) + } +} diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types new file mode 100644 index 00000000000..c316c6403c0 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfConstructor.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts === +class A { +>A : A + + constructor() { + // Single Line Comment + + var x = 10; +>x : number +>10 : number + } +} + +class B { +>B : B + + constructor() { + /* + Multi-line comment + */ + + var y = 10; +>y : number +>10 : number + } +} + +class C { +>C : C + + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; +>x : number +>10 : number + } +} + +class D { +>D : D + + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; +>y : number +>10 : number + } +} diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js new file mode 100644 index 00000000000..dbd0f0be783 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.js @@ -0,0 +1,48 @@ +//// [doNotEmitDetachedCommentsAtStartOfFunctionBody.ts] +function foo1() { + // Single line comment + + return 42; +} + +function foo2() { + /* + + multi line + comment + */ + + return 42; +} + +function foo3() { + // Single line comment with more than one blank line + + + return 42; +} + +function foo4() { + /* + + multi line comment with more than one blank line + */ + + return 42; +} + + + +//// [doNotEmitDetachedCommentsAtStartOfFunctionBody.js] +function foo1() { + return 42; +} +function foo2() { + return 42; +} +function foo3() { + return 42; +} +function foo4() { + return 42; +} diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols new file mode 100644 index 00000000000..c1680100369 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.symbols @@ -0,0 +1,42 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts === +function foo1() { +>foo1 : Symbol(foo1, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 0, 0)) + + // Single line comment + + return 42; +} + +function foo2() { +>foo2 : Symbol(foo2, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 4, 1)) + + /* + + multi line + comment + */ + + return 42; +} + +function foo3() { +>foo3 : Symbol(foo3, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 14, 1)) + + // Single line comment with more than one blank line + + + return 42; +} + +function foo4() { +>foo4 : Symbol(foo4, Decl(doNotEmitDetachedCommentsAtStartOfFunctionBody.ts, 21, 1)) + + /* + + multi line comment with more than one blank line + */ + + return 42; +} + + diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types new file mode 100644 index 00000000000..3b4814bbbb2 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfFunctionBody.types @@ -0,0 +1,46 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts === +function foo1() { +>foo1 : () => number + + // Single line comment + + return 42; +>42 : number +} + +function foo2() { +>foo2 : () => number + + /* + + multi line + comment + */ + + return 42; +>42 : number +} + +function foo3() { +>foo3 : () => number + + // Single line comment with more than one blank line + + + return 42; +>42 : number +} + +function foo4() { +>foo4 : () => number + + /* + + multi line comment with more than one blank line + */ + + return 42; +>42 : number +} + + diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js new file mode 100644 index 00000000000..7fd5c2b8f8e --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.js @@ -0,0 +1,45 @@ +//// [doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts] +() => { + // Single line comment + + return 0; +} + +() => { + /* + multi-line comment + */ + + return 0; +} + +() => { + // Single line comment with more than one blank line + + + return 0; +} + +() => { + /* + multi-line comment with more than one blank line + */ + + + return 0; +} + + +//// [doNotEmitDetachedCommentsAtStartOfLambdaFunction.js] +(function () { + return 0; +}); +(function () { + return 0; +}); +(function () { + return 0; +}); +(function () { + return 0; +}); diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols new file mode 100644 index 00000000000..e57fc793920 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts === +() => { +No type information for this code. // Single line comment +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code.() => { +No type information for this code. /* +No type information for this code. multi-line comment +No type information for this code. */ +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code.() => { +No type information for this code. // Single line comment with more than one blank line +No type information for this code. +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code.() => { +No type information for this code. /* +No type information for this code. multi-line comment with more than one blank line +No type information for this code. */ +No type information for this code. +No type information for this code. +No type information for this code. return 0; +No type information for this code.} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types new file mode 100644 index 00000000000..d90e93d84c5 --- /dev/null +++ b/tests/baselines/reference/doNotEmitDetachedCommentsAtStartOfLambdaFunction.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts === +() => { +>() => { // Single line comment return 0;} : () => number + + // Single line comment + + return 0; +>0 : number +} + +() => { +>() => { /* multi-line comment */ return 0;} : () => number + + /* + multi-line comment + */ + + return 0; +>0 : number +} + +() => { +>() => { // Single line comment with more than one blank line return 0;} : () => number + + // Single line comment with more than one blank line + + + return 0; +>0 : number +} + +() => { +>() => { /* multi-line comment with more than one blank line */ return 0;} : () => number + + /* + multi-line comment with more than one blank line + */ + + + return 0; +>0 : number +} + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js new file mode 100644 index 00000000000..8232ad66ef5 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.js @@ -0,0 +1,14 @@ +//// [doNotEmitPinnedCommentNotOnTopOfFile.ts] +var x = 10; + +/*! + + multi line + comment +*/ + +var x = 10; + +//// [doNotEmitPinnedCommentNotOnTopOfFile.js] +var x = 10; +var x = 10; diff --git a/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols new file mode 100644 index 00000000000..97cfb5df214 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts === +var x = 10; +>x : Symbol(x, Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 0, 3), Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 8, 3)) + +/*! + + multi line + comment +*/ + +var x = 10; +>x : Symbol(x, Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 0, 3), Decl(doNotEmitPinnedCommentNotOnTopOfFile.ts, 8, 3)) + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types new file mode 100644 index 00000000000..3426c70dfb9 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentNotOnTopOfFile.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts === +var x = 10; +>x : number +>10 : number + +/*! + + multi line + comment +*/ + +var x = 10; +>x : number +>10 : number + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js new file mode 100644 index 00000000000..99e50801d50 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.js @@ -0,0 +1,21 @@ +//// [doNotEmitPinnedCommentOnNotEmittedNode.ts] + +class C { + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) + public foo(x: string, y: number) { } +} + +var x = 10; + +/*! remove pinned comment anywhere else */ +declare var OData: any; + +//// [doNotEmitPinnedCommentOnNotEmittedNode.js] +var C = (function () { + function C() { + } + C.prototype.foo = function (x, y) { }; + return C; +})(); +var x = 10; diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols new file mode 100644 index 00000000000..64609266044 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts === + +class C { +>C : Symbol(C, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 0, 0)) + + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) +>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 33)) +>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 15)) +>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 25)) + + public foo(x: string, y: number) { } +>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 3, 33)) +>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 4, 15)) +>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 4, 25)) +} + +var x = 10; +>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 7, 3)) + +/*! remove pinned comment anywhere else */ +declare var OData: any; +>OData : Symbol(OData, Decl(doNotEmitPinnedCommentOnNotEmittedNode.ts, 10, 11)) + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types new file mode 100644 index 00000000000..b0f71137c2d --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNode.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts === + +class C { +>C : C + + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) +>foo : (x: string, y: any) => any +>x : string +>y : any + + public foo(x: string, y: number) { } +>foo : (x: string, y: any) => any +>x : string +>y : number +} + +var x = 10; +>x : number +>10 : number + +/*! remove pinned comment anywhere else */ +declare var OData: any; +>OData : any + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js new file mode 100644 index 00000000000..66896350e6d --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.js @@ -0,0 +1,18 @@ +//// [doNotEmitPinnedCommentOnNotEmittedNodets.ts] + +class C { + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) + public foo(x: string, y: number) { } +} + +/*! remove pinned comment anywhere else */ +declare var OData: any; + +//// [doNotEmitPinnedCommentOnNotEmittedNodets.js] +var C = (function () { + function C() { + } + C.prototype.foo = function (x, y) { }; + return C; +})(); diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols new file mode 100644 index 00000000000..dcd27478115 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts === + +class C { +>C : Symbol(C, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 0, 0)) + + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) +>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 33)) +>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 15)) +>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 25)) + + public foo(x: string, y: number) { } +>foo : Symbol(foo, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 1, 9), Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 3, 33)) +>x : Symbol(x, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 4, 15)) +>y : Symbol(y, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 4, 25)) +} + +/*! remove pinned comment anywhere else */ +declare var OData: any; +>OData : Symbol(OData, Decl(doNotEmitPinnedCommentOnNotEmittedNodets.ts, 8, 11)) + diff --git a/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types new file mode 100644 index 00000000000..4369af63f53 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedCommentOnNotEmittedNodets.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts === + +class C { +>C : C + + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) +>foo : (x: string, y: any) => any +>x : string +>y : any + + public foo(x: string, y: number) { } +>foo : (x: string, y: any) => any +>x : string +>y : number +} + +/*! remove pinned comment anywhere else */ +declare var OData: any; +>OData : any + diff --git a/tests/baselines/reference/doNotEmitPinnedDetachedComments.js b/tests/baselines/reference/doNotEmitPinnedDetachedComments.js new file mode 100644 index 00000000000..5f5a3b19aaa --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedDetachedComments.js @@ -0,0 +1,42 @@ +//// [doNotEmitPinnedDetachedComments.ts] +var x = 10; + +/*! Single Line comment */ + +function baz() { } + + +/*! + multi-line comment + +*/ + + +//======================== + + +function bar() { + /*! + Remove this comment + */ + +} + +function foo() { + /*! Remove this */ + + return 0; +} + + +//======================== + + +//// [doNotEmitPinnedDetachedComments.js] +var x = 10; +function baz() { } +function bar() { +} +function foo() { + return 0; +} diff --git a/tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols b/tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols new file mode 100644 index 00000000000..2be35804b38 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedDetachedComments.symbols @@ -0,0 +1,39 @@ +=== tests/cases/compiler/doNotEmitPinnedDetachedComments.ts === +var x = 10; +>x : Symbol(x, Decl(doNotEmitPinnedDetachedComments.ts, 0, 3)) + +/*! Single Line comment */ + +function baz() { } +>baz : Symbol(baz, Decl(doNotEmitPinnedDetachedComments.ts, 0, 11)) + + +/*! + multi-line comment + +*/ + + +//======================== + + +function bar() { +>bar : Symbol(bar, Decl(doNotEmitPinnedDetachedComments.ts, 4, 18)) + + /*! + Remove this comment + */ + +} + +function foo() { +>foo : Symbol(foo, Decl(doNotEmitPinnedDetachedComments.ts, 21, 1)) + + /*! Remove this */ + + return 0; +} + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitPinnedDetachedComments.types b/tests/baselines/reference/doNotEmitPinnedDetachedComments.types new file mode 100644 index 00000000000..d9e78e2f980 --- /dev/null +++ b/tests/baselines/reference/doNotEmitPinnedDetachedComments.types @@ -0,0 +1,41 @@ +=== tests/cases/compiler/doNotEmitPinnedDetachedComments.ts === +var x = 10; +>x : number +>10 : number + +/*! Single Line comment */ + +function baz() { } +>baz : () => void + + +/*! + multi-line comment + +*/ + + +//======================== + + +function bar() { +>bar : () => void + + /*! + Remove this comment + */ + +} + +function foo() { +>foo : () => number + + /*! Remove this */ + + return 0; +>0 : number +} + + +//======================== + diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js new file mode 100644 index 00000000000..f3b0888a78f --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts] //// + +//// [file0.ts] + + +//// [file1.ts] + +//// [file2.ts] +/// +/// +/// + +//// [file0.js] +//// [file1.js] +//// [file2.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols new file mode 100644 index 00000000000..d18810db280 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/file2.ts === +/// +No type information for this code./// +No type information for this code./// +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code.=== tests/cases/compiler/file1.ts === + +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types new file mode 100644 index 00000000000..d18810db280 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsInEmptyFile.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/file2.ts === +/// +No type information for this code./// +No type information for this code./// +No type information for this code.=== tests/cases/compiler/file0.ts === + +No type information for this code. +No type information for this code.=== tests/cases/compiler/file1.ts === + +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js new file mode 100644 index 00000000000..9067b5b80a9 --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts] //// + +//// [file0.ts] + +/// +declare var OData: any; + +//// [file1.ts] +/// +interface F { } + + + +//// [file0.js] +//// [file1.js] diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols new file mode 100644 index 00000000000..bb920d2ee1c --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/file1.ts === +/// +interface F { } +>F : Symbol(F, Decl(file1.ts, 0, 0)) + + +=== tests/cases/compiler/file0.ts === + +/// +declare var OData: any; +>OData : Symbol(OData, Decl(file0.ts, 2, 11)) + diff --git a/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.types b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.types new file mode 100644 index 00000000000..59b63ea1a2f --- /dev/null +++ b/tests/baselines/reference/doNotEmitTripleSlashCommentsOnNotEmittedNode.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/file1.ts === +/// +interface F { } +>F : F + + +=== tests/cases/compiler/file0.ts === + +/// +declare var OData: any; +>OData : any + diff --git a/tests/baselines/reference/doNotemitTripleSlashComments.js b/tests/baselines/reference/doNotemitTripleSlashComments.js new file mode 100644 index 00000000000..fe17db54cb1 --- /dev/null +++ b/tests/baselines/reference/doNotemitTripleSlashComments.js @@ -0,0 +1,46 @@ +//// [tests/cases/compiler/doNotemitTripleSlashComments.ts] //// + +//// [file0.ts] + +/// +/// +/// +var x = 10; + +/// +var y = "hello"; + + +/// + +//// [file1.ts] +/// + +function foo() { } + + +/// + + +var z = "world"; + +//// [file2.ts] +/// + + +/// ==================================== + + +function bar() { } + + + + +//// [file0.js] +var x = 10; +var y = "hello"; +//// [file1.js] +function foo() { } +var z = "world"; +//// [file2.js] +function bar() { } diff --git a/tests/baselines/reference/doNotemitTripleSlashComments.symbols b/tests/baselines/reference/doNotemitTripleSlashComments.symbols new file mode 100644 index 00000000000..36b31842f8b --- /dev/null +++ b/tests/baselines/reference/doNotemitTripleSlashComments.symbols @@ -0,0 +1,40 @@ +=== tests/cases/compiler/file2.ts === +/// + + +/// ==================================== + + +function bar() { } +>bar : Symbol(bar, Decl(file2.ts, 0, 0)) + + + +=== tests/cases/compiler/file0.ts === + +/// +/// +/// +var x = 10; +>x : Symbol(x, Decl(file0.ts, 4, 3)) + +/// +var y = "hello"; +>y : Symbol(y, Decl(file0.ts, 7, 3)) + + +/// + +=== tests/cases/compiler/file1.ts === +/// + +function foo() { } +>foo : Symbol(foo, Decl(file1.ts, 0, 0)) + + +/// + + +var z = "world"; +>z : Symbol(z, Decl(file1.ts, 8, 3)) + diff --git a/tests/baselines/reference/doNotemitTripleSlashComments.types b/tests/baselines/reference/doNotemitTripleSlashComments.types new file mode 100644 index 00000000000..edebe5687f6 --- /dev/null +++ b/tests/baselines/reference/doNotemitTripleSlashComments.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/file2.ts === +/// + + +/// ==================================== + + +function bar() { } +>bar : () => void + + + +=== tests/cases/compiler/file0.ts === + +/// +/// +/// +var x = 10; +>x : number +>10 : number + +/// +var y = "hello"; +>y : string +>"hello" : string + + +/// + +=== tests/cases/compiler/file1.ts === +/// + +function foo() { } +>foo : () => void + + +/// + + +var z = "world"; +>z : string +>"world" : string + diff --git a/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js new file mode 100644 index 00000000000..a30fcbf045d --- /dev/null +++ b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.js @@ -0,0 +1,16 @@ +//// [emitPinnedCommentsOnTopOfFile.ts] +/*! + + multi line + comment +*/ + +var x = 10; + +//// [emitPinnedCommentsOnTopOfFile.js] +/*! + + multi line + comment +*/ +var x = 10; diff --git a/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols new file mode 100644 index 00000000000..c9eb5905303 --- /dev/null +++ b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts === +/*! + + multi line + comment +*/ + +var x = 10; +>x : Symbol(x, Decl(emitPinnedCommentsOnTopOfFile.ts, 6, 3)) + diff --git a/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types new file mode 100644 index 00000000000..0ada89e2802 --- /dev/null +++ b/tests/baselines/reference/emitPinnedCommentsOnTopOfFile.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts === +/*! + + multi line + comment +*/ + +var x = 10; +>x : number +>10 : number + diff --git a/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js new file mode 100644 index 00000000000..ff358518568 --- /dev/null +++ b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts] //// + +//// [file0.ts] + +var x = 10 + +//// [file1.ts] +/// +declare var OData: any; + +/// +interface F { } + + + + +//// [file0.js] +var x = 10; +//// [file1.js] +/// diff --git a/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols new file mode 100644 index 00000000000..1c0e48e00f2 --- /dev/null +++ b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/file1.ts === +/// +declare var OData: any; +>OData : Symbol(OData, Decl(file1.ts, 1, 11)) + +/// +interface F { } +>F : Symbol(F, Decl(file1.ts, 1, 23)) + + + +=== tests/cases/compiler/file0.ts === + +var x = 10 +>x : Symbol(x, Decl(file0.ts, 1, 3)) + diff --git a/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types new file mode 100644 index 00000000000..637196fdc22 --- /dev/null +++ b/tests/baselines/reference/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/file1.ts === +/// +declare var OData: any; +>OData : any + +/// +interface F { } +>F : F + + + +=== tests/cases/compiler/file0.ts === + +var x = 10 +>x : number +>10 : number + diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.js b/tests/baselines/reference/jsxEmitAttributeWithPreserve.js new file mode 100644 index 00000000000..07cb0dee485 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.js @@ -0,0 +1,7 @@ +//// [jsxEmitAttributeWithPreserve.tsx] + +declare var React: any; + + +//// [jsxEmitAttributeWithPreserve.jsx] +; diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols b/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols new file mode 100644 index 00000000000..4ffadb8e888 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx === + +declare var React: any; +>React : Symbol(React, Decl(jsxEmitAttributeWithPreserve.tsx, 1, 11)) + + +>data : Symbol(unknown) + diff --git a/tests/baselines/reference/jsxEmitAttributeWithPreserve.types b/tests/baselines/reference/jsxEmitAttributeWithPreserve.types new file mode 100644 index 00000000000..972ca1c3d88 --- /dev/null +++ b/tests/baselines/reference/jsxEmitAttributeWithPreserve.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx === + +declare var React: any; +>React : any + + +> : any +>foo : any +>data : any + diff --git a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js index daf344b08da..d623e127be7 100644 --- a/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js +++ b/tests/baselines/reference/jsxInvalidEsprimaTestSuite.js @@ -47,9 +47,9 @@ a / > ; < a; b > ; b > ; -; +; b.c > ; -; +; c > ; ; < .a > ; @@ -67,7 +67,7 @@ var x =
one
two
;; var x =
one
/* intervening comment */ /* intervening comment */
two
;; {"str"}}; id="b" />; -
>; +
>;
;
stuff
...props}>; diff --git a/tests/baselines/reference/jsxReactTestSuite.js b/tests/baselines/reference/jsxReactTestSuite.js index 300274a1614..18013d4be9b 100644 --- a/tests/baselines/reference/jsxReactTestSuite.js +++ b/tests/baselines/reference/jsxReactTestSuite.js @@ -158,14 +158,14 @@ var x =
; ; ; -; +; ; ; ; ; ; ; -; +; ; ; Text; diff --git a/tests/baselines/reference/keywordInJsxIdentifier.js b/tests/baselines/reference/keywordInJsxIdentifier.js new file mode 100644 index 00000000000..677a79138e6 --- /dev/null +++ b/tests/baselines/reference/keywordInJsxIdentifier.js @@ -0,0 +1,14 @@ +//// [keywordInJsxIdentifier.tsx] + +declare var React: any; +; +; +; +; + + +//// [keywordInJsxIdentifier.js] +React.createElement("foo", {"class-id": true}); +React.createElement("foo", {"class": true}); +React.createElement("foo", {"class-id": "1"}); +React.createElement("foo", {"class": "1"}); diff --git a/tests/baselines/reference/keywordInJsxIdentifier.symbols b/tests/baselines/reference/keywordInJsxIdentifier.symbols new file mode 100644 index 00000000000..874d7801a7f --- /dev/null +++ b/tests/baselines/reference/keywordInJsxIdentifier.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/keywordInJsxIdentifier.tsx === + +declare var React: any; +>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11)) + +; +>class-id : Symbol(unknown) + +; +>class : Symbol(unknown) + +; +>class-id : Symbol(unknown) + +; +>class : Symbol(unknown) + diff --git a/tests/baselines/reference/keywordInJsxIdentifier.types b/tests/baselines/reference/keywordInJsxIdentifier.types new file mode 100644 index 00000000000..745fa5998b5 --- /dev/null +++ b/tests/baselines/reference/keywordInJsxIdentifier.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/keywordInJsxIdentifier.tsx === + +declare var React: any; +>React : any + +; +> : any +>foo : any +>class-id : any + +; +> : any +>foo : any +>class : any + +; +> : any +>foo : any +>class-id : any + +; +> : any +>foo : any +>class : any + diff --git a/tests/baselines/reference/pinnedComments1.js b/tests/baselines/reference/pinnedComments1.js index c4b8b41fbd7..9ab2a147e6a 100644 --- a/tests/baselines/reference/pinnedComments1.js +++ b/tests/baselines/reference/pinnedComments1.js @@ -1,12 +1,19 @@ //// [pinnedComments1.ts] +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { } //// [pinnedComments1.js] -/*! pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ var C = (function () { function C() { } diff --git a/tests/baselines/reference/pinnedComments1.symbols b/tests/baselines/reference/pinnedComments1.symbols index 53d46ecbaf6..6ee37435dfa 100644 --- a/tests/baselines/reference/pinnedComments1.symbols +++ b/tests/baselines/reference/pinnedComments1.symbols @@ -1,7 +1,11 @@ === tests/cases/compiler/pinnedComments1.ts === +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { >C : Symbol(C, Decl(pinnedComments1.ts, 0, 0)) } diff --git a/tests/baselines/reference/pinnedComments1.types b/tests/baselines/reference/pinnedComments1.types index d55feb67659..df97cbdbec9 100644 --- a/tests/baselines/reference/pinnedComments1.types +++ b/tests/baselines/reference/pinnedComments1.types @@ -1,7 +1,11 @@ === tests/cases/compiler/pinnedComments1.ts === +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { >C : C } diff --git a/tests/baselines/reference/tsxAttributeResolution6.js b/tests/baselines/reference/tsxAttributeResolution6.js index f4af0ba875a..5d6ad1e20c6 100644 --- a/tests/baselines/reference/tsxAttributeResolution6.js +++ b/tests/baselines/reference/tsxAttributeResolution6.js @@ -20,10 +20,10 @@ declare module JSX { //// [tsxAttributeResolution6.jsx] // Error -; +; ; ; // OK -; +; ; -; +; diff --git a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js index f493347ca9c..ece48831f8e 100644 --- a/tests/baselines/reference/tsxGenericArrowFunctionParsing.js +++ b/tests/baselines/reference/tsxGenericArrowFunctionParsing.js @@ -42,5 +42,5 @@ x3(); var x4 = () => ; x4.isElement; // This is an element -var x5 = () => ; +var x5 = () => ; x5.isElement; diff --git a/tests/cases/compiler/castExpressionParentheses.ts b/tests/cases/compiler/castExpressionParentheses.ts index 93b26ebaf4e..06908f39936 100644 --- a/tests/cases/compiler/castExpressionParentheses.ts +++ b/tests/cases/compiler/castExpressionParentheses.ts @@ -6,6 +6,11 @@ declare var a; ([1,3,]); ("string"); (23.0); +(1); +(1.); +(1.0); +(12e+34); +(0xff); (/regexp/g); (false); (true); @@ -22,6 +27,12 @@ declare var a; declare var A; // should keep the parentheses in emit +(1).foo; +(1.).foo; +(1.0).foo; +(12e+34).foo; +(0xff).foo; +((1.0)); (new A).foo; (typeof A).x; (-A).x; diff --git a/tests/cases/compiler/commentOnAmbientClass1.ts b/tests/cases/compiler/commentOnAmbientClass1.ts index c13e4193512..1c153e86bf2 100644 --- a/tests/cases/compiler/commentOnAmbientClass1.ts +++ b/tests/cases/compiler/commentOnAmbientClass1.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare class C { } diff --git a/tests/cases/compiler/commentOnAmbientEnum.ts b/tests/cases/compiler/commentOnAmbientEnum.ts index a9ebe107c98..20d89c1b70d 100644 --- a/tests/cases/compiler/commentOnAmbientEnum.ts +++ b/tests/cases/compiler/commentOnAmbientEnum.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare enum C { a, b, diff --git a/tests/cases/compiler/commentOnAmbientModule.ts b/tests/cases/compiler/commentOnAmbientModule.ts index 41e12a61902..a8aeab7efba 100644 --- a/tests/cases/compiler/commentOnAmbientModule.ts +++ b/tests/cases/compiler/commentOnAmbientModule.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare module C { function foo(); } diff --git a/tests/cases/compiler/commentOnAmbientVariable1.ts b/tests/cases/compiler/commentOnAmbientVariable1.ts index 0124be05053..ef539441bd2 100644 --- a/tests/cases/compiler/commentOnAmbientVariable1.ts +++ b/tests/cases/compiler/commentOnAmbientVariable1.ts @@ -1,4 +1,9 @@ -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare var v: number; // Don't keep this comment. diff --git a/tests/cases/compiler/commentOnAmbientfunction.ts b/tests/cases/compiler/commentOnAmbientfunction.ts index d549303fc4f..51f3b6194b5 100644 --- a/tests/cases/compiler/commentOnAmbientfunction.ts +++ b/tests/cases/compiler/commentOnAmbientfunction.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!========= + Keep this pinned comment + ========= +*/ + +/*! Don't keep this pinned comment */ declare function foo(); // Don't keep this comment. diff --git a/tests/cases/compiler/commentOnElidedModule1.ts b/tests/cases/compiler/commentOnElidedModule1.ts index 22014a86f5b..0cdb7694273 100644 --- a/tests/cases/compiler/commentOnElidedModule1.ts +++ b/tests/cases/compiler/commentOnElidedModule1.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ module ElidedModule { } diff --git a/tests/cases/compiler/commentOnInterface1.ts b/tests/cases/compiler/commentOnInterface1.ts index a394da0dd2c..c22229b7ccf 100644 --- a/tests/cases/compiler/commentOnInterface1.ts +++ b/tests/cases/compiler/commentOnInterface1.ts @@ -1,5 +1,10 @@ //@filename: a.ts -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ interface I { } diff --git a/tests/cases/compiler/commentOnSignature1.ts b/tests/cases/compiler/commentOnSignature1.ts index 770c103a9fc..e8d2d831e8b 100644 --- a/tests/cases/compiler/commentOnSignature1.ts +++ b/tests/cases/compiler/commentOnSignature1.ts @@ -1,5 +1,10 @@ // @filename: a.ts -/*! Keep this pinned comment */ +/*!================= + Keep this pinned + ================= +*/ + +/*! Don't keep this pinned comment */ function foo(n: number): void; // Don't keep this comment. function foo(s: string): void; diff --git a/tests/cases/compiler/doNotEmitDetachedComments.ts b/tests/cases/compiler/doNotEmitDetachedComments.ts new file mode 100644 index 00000000000..412dbeac19b --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedComments.ts @@ -0,0 +1,27 @@ +// @comments: false +/* + + multi line + comment +*/ + +var x = 10; + +// Single Line comment + +function foo() { } + + +/* + multi-line comment + +*/ + + +//======================== + + +function bar() { } + + +//======================== diff --git a/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts new file mode 100644 index 00000000000..1ea96993a5e --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfConstructor.ts @@ -0,0 +1,38 @@ +// @comments: false +class A { + constructor() { + // Single Line Comment + + var x = 10; + } +} + +class B { + constructor() { + /* + Multi-line comment + */ + + var y = 10; + } +} + +class C { + constructor() { + // Single Line Comment with more than one blank line + + + var x = 10; + } +} + +class D { + constructor() { + /* + Multi-line comment with more than one blank line + */ + + + var y = 10; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts new file mode 100644 index 00000000000..31adbc18de8 --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfFunctionBody.ts @@ -0,0 +1,33 @@ +// @comments: false +function foo1() { + // Single line comment + + return 42; +} + +function foo2() { + /* + + multi line + comment + */ + + return 42; +} + +function foo3() { + // Single line comment with more than one blank line + + + return 42; +} + +function foo4() { + /* + + multi line comment with more than one blank line + */ + + return 42; +} + diff --git a/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts new file mode 100644 index 00000000000..c6a9cfc9e25 --- /dev/null +++ b/tests/cases/compiler/doNotEmitDetachedCommentsAtStartOfLambdaFunction.ts @@ -0,0 +1,30 @@ +// @comments: false +() => { + // Single line comment + + return 0; +} + +() => { + /* + multi-line comment + */ + + return 0; +} + +() => { + // Single line comment with more than one blank line + + + return 0; +} + +() => { + /* + multi-line comment with more than one blank line + */ + + + return 0; +} diff --git a/tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts b/tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts new file mode 100644 index 00000000000..0fbb1fddd81 --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedCommentNotOnTopOfFile.ts @@ -0,0 +1,10 @@ +// @comments: false +var x = 10; + +/*! + + multi line + comment +*/ + +var x = 10; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts new file mode 100644 index 00000000000..48e02a372f7 --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNode.ts @@ -0,0 +1,13 @@ +// @comments: false + +class C { + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) + public foo(x: string, y: number) { } +} + +// @Filename: file1.ts +var x = 10; + +/*! remove pinned comment anywhere else */ +declare var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts new file mode 100644 index 00000000000..a59e13df55c --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedCommentOnNotEmittedNodets.ts @@ -0,0 +1,10 @@ +// @comments: false + +class C { + /*! remove pinned comment anywhere else */ + public foo(x: string, y: any) + public foo(x: string, y: number) { } +} + +/*! remove pinned comment anywhere else */ +declare var OData: any; \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitPinnedDetachedComments.ts b/tests/cases/compiler/doNotEmitPinnedDetachedComments.ts new file mode 100644 index 00000000000..534963cf4b7 --- /dev/null +++ b/tests/cases/compiler/doNotEmitPinnedDetachedComments.ts @@ -0,0 +1,32 @@ +// @comments: false +var x = 10; + +/*! Single Line comment */ + +function baz() { } + + +/*! + multi-line comment + +*/ + + +//======================== + + +function bar() { + /*! + Remove this comment + */ + +} + +function foo() { + /*! Remove this */ + + return 0; +} + + +//======================== diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts new file mode 100644 index 00000000000..047510e2ec9 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsInEmptyFile.ts @@ -0,0 +1,10 @@ +// @comments: false + +// @Filename: file0.ts + +// @Filename: file1.ts + +// @Filename: file2.ts +/// +/// +/// \ No newline at end of file diff --git a/tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts b/tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts new file mode 100644 index 00000000000..91941a6cf81 --- /dev/null +++ b/tests/cases/compiler/doNotEmitTripleSlashCommentsOnNotEmittedNode.ts @@ -0,0 +1,10 @@ +// @comments: false + +// @Filename: file0.ts +/// +declare var OData: any; + +// @Filename: file1.ts +/// +interface F { } + diff --git a/tests/cases/compiler/doNotemitTripleSlashComments.ts b/tests/cases/compiler/doNotemitTripleSlashComments.ts new file mode 100644 index 00000000000..f3b90662159 --- /dev/null +++ b/tests/cases/compiler/doNotemitTripleSlashComments.ts @@ -0,0 +1,35 @@ +// @comments: false + +// @Filename: file0.ts +/// +/// +/// +var x = 10; + +/// +var y = "hello"; + + +/// + +// @Filename: file1.ts +/// + +function foo() { } + + +/// + + +var z = "world"; + +// @Filename: file2.ts +/// + + +/// ==================================== + + +function bar() { } + + diff --git a/tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts b/tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts new file mode 100644 index 00000000000..bbe6c400601 --- /dev/null +++ b/tests/cases/compiler/emitPinnedCommentsOnTopOfFile.ts @@ -0,0 +1,8 @@ +// @comments: false +/*! + + multi line + comment +*/ + +var x = 10; \ No newline at end of file diff --git a/tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts b/tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts new file mode 100644 index 00000000000..20c04702544 --- /dev/null +++ b/tests/cases/compiler/emitTopOfFileTripleSlashCommentOnNotEmittedNodeIfRemoveCommentsIsFalse.ts @@ -0,0 +1,13 @@ +// @comments: true + +// @Filename: file0.ts +var x = 10 + +// @Filename: file1.ts +/// +declare var OData: any; + +/// +interface F { } + + diff --git a/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx b/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx new file mode 100644 index 00000000000..dc32ef7a0ca --- /dev/null +++ b/tests/cases/compiler/jsxEmitAttributeWithPreserve.tsx @@ -0,0 +1,4 @@ +//@jsx: preserve + +declare var React: any; + \ No newline at end of file diff --git a/tests/cases/compiler/keywordInJsxIdentifier.tsx b/tests/cases/compiler/keywordInJsxIdentifier.tsx new file mode 100644 index 00000000000..ce858edae5d --- /dev/null +++ b/tests/cases/compiler/keywordInJsxIdentifier.tsx @@ -0,0 +1,7 @@ +//@jsx: react + +declare var React: any; +; +; +; +; diff --git a/tests/cases/compiler/pinnedComments1.ts b/tests/cases/compiler/pinnedComments1.ts index 474769e9b20..4de91b33e56 100644 --- a/tests/cases/compiler/pinnedComments1.ts +++ b/tests/cases/compiler/pinnedComments1.ts @@ -1,6 +1,10 @@ // @comments: false +/*!========= + Keep this pinned comment + ========= +*/ /* unpinned comment */ -/*! pinned comment */ +/*! pinned comment that need to be removed */ class C { } \ No newline at end of file diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 14bf09d6db8..4d167cb1bb0 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -193,7 +193,11 @@ module ts { describe("Reuse program structure", () => { let target = ScriptTarget.Latest; let files = [ - { name: "a.ts", text: SourceText.New(`/// `, "", `var x = 1`) }, + { name: "a.ts", text: SourceText.New( + ` +/// +/// +`, "",`var x = 1`) }, { name: "b.ts", text: SourceText.New(`/// `, "", `var y = 2`) }, { name: "c.ts", text: SourceText.New("", "", `var z = 1;`) }, ] @@ -204,6 +208,9 @@ module ts { files[0].text = files[0].text.updateProgram("var x = 100"); }); assert.isTrue(program_1.structureIsReused); + let program1Diagnostics = program_1.getSemanticDiagnostics(program_1.getSourceFile("a.ts")) + let program2Diagnostics = program_2.getSemanticDiagnostics(program_1.getSourceFile("a.ts")) + assert.equal(program1Diagnostics.length, program2Diagnostics.length); }); it("fails if change affects tripleslash references", () => {