diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 23bbba5c6ca..a46f9168644 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -134,6 +134,12 @@ module ts { type: "boolean", description: Diagnostics.Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures, }, + { + name: "stripInternal", + type: "boolean", + description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation, + experimental: true + }, { name: "target", shortName: "t", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dc7ef322c9b..4b10b50e31e 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -433,6 +433,7 @@ module ts { File_0_not_found: { code: 6053, category: DiagnosticCategory.Error, key: "File '{0}' not found." }, File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, + Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5ee826812f2..456c97a7c77 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1725,6 +1725,10 @@ "category": "Message", "code": 6055 }, + "Do not emit declarations for code that has an '@internal' annotation.": { + "category": "Message", + "code": 6056 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b15a493de92..086a402efb2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -134,7 +134,7 @@ module ts { } function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { - return currentSourceFile.getLineAndCharacterFromPosition(pos).line; + return getLineAndCharacterOfPosition(currentSourceFile, pos).line; } function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { @@ -169,16 +169,16 @@ module ts { function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos); - var lastLine = currentSourceFile.getLineStarts().length; + var firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); + var lastLine = getLineStarts(currentSourceFile).length; var firstCommentLineIndent: number; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentLine === lastLine ? (comment.end + 1) : currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1); + var nextLineStart = currentLine === lastLine ? (comment.end + 1) : getPositionFromLineAndCharacter(currentSourceFile, currentLine + 1, /*character*/1); if (pos !== comment.pos) { // If we are not emitting first line, we need to write the spaces to adjust the alignment if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, /*character*/1), + firstCommentLineIndent = calculateIndent(getPositionFromLineAndCharacter(currentSourceFile, firstCommentLineAndCharacter.line, /*character*/1), comment.pos); } @@ -355,9 +355,86 @@ module ts { var reportedDeclarationError = false; var emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; + var emit = compilerOptions.stripInternal ? stripInternal : emitNode; var aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[] = []; + // Contains the reference paths that needs to go in the declaration file. + // Collecting this separately because reference paths need to be first thing in the declaration file + // and we could be collecting these paths from multiple files into single one with --out option + var referencePathsOutput = ""; + + if (root) { + // Emitting just a single file, so emit references in this file only + if (!compilerOptions.noResolve) { + var addedGlobalFileReference = false; + forEach(root.referencedFiles, fileReference => { + var referencedFile = tryResolveScriptReference(host, root, fileReference); + + // All the references that are not going to be part of same file + if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference + shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file + !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added + + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } + } + }); + } + + emitSourceFile(root); + } + else { + // Emit references corresponding to this file + var emittedReferencedFiles: SourceFile[] = []; + forEach(host.getSourceFiles(), sourceFile => { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + // Check what references need to be added + if (!compilerOptions.noResolve) { + forEach(sourceFile.referencedFiles, fileReference => { + var referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); + + // If the reference file is a declaration file or an external module, emit that reference + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && + !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted + + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } + + emitSourceFile(sourceFile); + } + }); + } + + return { + reportedDeclarationError, + aliasDeclarationEmitInfo, + synchronousDeclarationOutput: writer.getText(), + referencePathsOutput, + } + + function hasInternalAnnotation(range: CommentRange) { + var text = currentSourceFile.text; + var comment = text.substring(range.pos, range.end); + return comment.indexOf("@internal") >= 0; + } + + function stripInternal(node: Node) { + if (node) { + var leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); + if (forEach(leadingCommentRanges, hasInternalAnnotation)) { + return; + } + + emitNode(node); + } + } + function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { var writer = createTextWriter(newLine); writer.trackSymbol = trackSymbol; @@ -463,7 +540,7 @@ module ts { function emitLines(nodes: Node[]) { for (var i = 0, n = nodes.length; i < n; i++) { - emitNode(nodes[i]); + emit(nodes[i]); } } @@ -1402,10 +1479,6 @@ module ts { } } - // Contains the reference paths that needs to go in the declaration file. - // Collecting this separately because reference paths need to be first thing in the declaration file - // and we could be collecting these paths from multiple files into single one with --out option - var referencePathsOutput = ""; function writeReferencePath(referencedFile: SourceFile) { var declFileName = referencedFile.flags & NodeFlags.DeclarationFile ? referencedFile.filename // Declaration file, use declaration file name @@ -1422,60 +1495,6 @@ module ts { referencePathsOutput += "/// " + newLine; } - - if (root) { - // Emitting just a single file, so emit references in this file only - if (!compilerOptions.noResolve) { - var addedGlobalFileReference = false; - forEach(root.referencedFiles, fileReference => { - var referencedFile = tryResolveScriptReference(host, root, fileReference); - - // All the references that are not going to be part of same file - if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference - shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file - !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added - - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; - } - } - }); - } - - emitNode(root); - } - else { - // Emit references corresponding to this file - var emittedReferencedFiles: SourceFile[] = []; - forEach(host.getSourceFiles(), sourceFile => { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - // Check what references need to be added - if (!compilerOptions.noResolve) { - forEach(sourceFile.referencedFiles, fileReference => { - var referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); - - // If the reference file is a declaration file or an external module, emit that reference - if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && - !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted - - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); - } - - emitNode(sourceFile); - } - }); - } - - return { - reportedDeclarationError, - aliasDeclarationEmitInfo, - synchronousDeclarationOutput: writer.getText(), - referencePathsOutput, - } } export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { @@ -1660,7 +1679,7 @@ module ts { } function recordSourceMapSpan(pos: number) { - var sourceLinePos = currentSourceFile.getLineAndCharacterFromPosition(pos); + var sourceLinePos = getLineAndCharacterOfPosition(currentSourceFile, pos); var emittedLine = writer.getLine(); var emittedColumn = writer.getColumn(); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5ae44e5ff39..9ad9067d6fa 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -356,6 +356,368 @@ module ts { forEachChild(sourceFile, walk); } + export function getSyntacticDiagnostics(sourceFile: SourceFile) { + if (!sourceFile.syntacticDiagnostics) { + // Don't bother doing any grammar checks if there are already parser errors. + // Otherwise we may end up with too many cascading errors. + sourceFile.syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); + } + return sourceFile.syntacticDiagnostics; + } + + function moveElementEntirelyPastChangeRange(element: IncrementalElement, delta: number) { + if (element.length) { + visitArray(element); + } + else { + visitNode(element); + } + + function visitNode(node: IncrementalNode) { + // Ditch any existing LS children we may have created. This way we can avoid + // moving them forward. + node._children = undefined; + node.pos += delta; + node.end += delta; + + forEachChild(node, visitNode, visitArray); + } + + function visitArray(array: IncrementalNodeArray) { + array.pos += delta; + array.end += delta; + + for (var i = 0, n = array.length; i < n; i++) { + visitNode(array[i]); + } + } + } + + function adjustIntersectingElement(element: IncrementalElement, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number) { + Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range"); + Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range"); + + // We have an element that intersects the change range in some way. It may have its + // start, or its end (or both) in the changed range. We want to adjust any part + // that intersects such that the final tree is in a consistent state. i.e. all + // chlidren have spans within the span of their parent, and all siblings are ordered + // properly. + + // We may need to update both the 'pos' and the 'end' of the element. + + // If the 'pos' is before the start of the change, then we don't need to touch it. + // If it isn't, then the 'pos' must be inside the change. How we update it will + // depend if delta is positive or negative. If delta is positive then we have + // something like: + // + // -------------------AAA----------------- + // -------------------BBBCCCCCCC----------------- + // + // In this case, we consider any node that started in the change range to still be + // starting at the same position. + // + // however, if the delta is negative, then we instead have something like this: + // + // -------------------XXXYYYYYYY----------------- + // -------------------ZZZ----------------- + // + // In this case, any element that started in the 'X' range will keep its position. + // However any element htat started after that will have their pos adjusted to be + // at the end of the new range. i.e. any node that started in the 'Y' range will + // be adjusted to have their start at the end of the 'Z' range. + // + // The element will keep its position if possible. Or Move backward to the new-end + // if it's in the 'Y' range. + element.pos = Math.min(element.pos, changeRangeNewEnd); + + // If the 'end' is after the change range, then we always adjust it by the delta + // amount. However, if the end is in the change range, then how we adjust it + // will depend on if delta is positive or negative. If delta is positive then we + // have something like: + // + // -------------------AAA----------------- + // -------------------BBBCCCCCCC----------------- + // + // In this case, we consider any node that ended inside the change range to keep its + // end position. + // + // however, if the delta is negative, then we instead have something like this: + // + // -------------------XXXYYYYYYY----------------- + // -------------------ZZZ----------------- + // + // In this case, any element that ended in the 'X' range will keep its position. + // However any element htat ended after that will have their pos adjusted to be + // at the end of the new range. i.e. any node that ended in the 'Y' range will + // be adjusted to have their end at the end of the 'Z' range. + if (element.end >= changeRangeOldEnd) { + // Element ends after the change range. Always adjust the end pos. + element.end += delta; + } + else { + // Element ends in the change range. The element will keep its position if + // possible. Or Move backward to the new-end if it's in the 'Y' range. + element.end = Math.min(element.end, changeRangeNewEnd); + } + + Debug.assert(element.pos <= element.end); + if (element.parent) { + Debug.assert(element.pos >= element.parent.pos); + Debug.assert(element.end <= element.parent.end); + } + } + + function updateTokenPositionsAndMarkElements(node: IncrementalNode, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number): void { + visitNode(node); + + function visitNode(child: IncrementalNode) { + if (child.pos > changeRangeOldEnd) { + // Node is entirely past the change range. We need to move both its pos and + // end, forward or backward appropriately. + moveElementEntirelyPastChangeRange(child, delta); + return; + } + + // Check if the element intersects the change range. If it does, then it is not + // reusable. Also, we'll need to recurse to see what constituent portions we may + // be able to use. + var fullEnd = child.end; + if (fullEnd >= changeStart) { + child.intersectsChange = true; + + // Adjust the pos or end (or both) of the intersecting element accordingly. + adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); + forEachChild(child, visitNode, visitArray); + return; + } + + // Otherwise, the node is entirely before the change range. No need to do anything with it. + } + + function visitArray(array: IncrementalNodeArray) { + if (array.pos > changeRangeOldEnd) { + // Array is entirely after the change range. We need to move it, and move any of + // its children. + moveElementEntirelyPastChangeRange(array, delta); + } + else { + // Check if the element intersects the change range. If it does, then it is not + // reusable. Also, we'll need to recurse to see what constituent portions we may + // be able to use. + var fullEnd = array.end; + if (fullEnd >= changeStart) { + array.intersectsChange = true; + + // Adjust the pos or end (or both) of the intersecting array accordingly. + adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); + for (var i = 0, n = array.length; i < n; i++) { + visitNode(array[i]); + } + } + // else { + // Otherwise, the array is entirely before the change range. No need to do anything with it. + // } + } + } + } + + + function extendToAffectedRange(sourceFile: SourceFile, changeRange: TextChangeRange): TextChangeRange { + // Consider the following code: + // void foo() { /; } + // + // If the text changes with an insertion of / just before the semicolon then we end up with: + // void foo() { //; } + // + // If we were to just use the changeRange a is, then we would not rescan the { token + // (as it does not intersect the actual original change range). Because an edit may + // change the token touching it, we actually need to look back *at least* one token so + // that the prior token sees that change. + var maxLookahead = 1; + + var start = changeRange.span.start; + + // the first iteration aligns us with the change start. subsequent iteration move us to + // the left by maxLookahead tokens. We only need to do this as long as we're not at the + // start of the tree. + for (var i = 0; start > 0 && i <= maxLookahead; i++) { + var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start); + var position = nearestNode.pos; + + start = Math.max(0, position - 1); + } + + var finalSpan = createTextSpanFromBounds(start, textSpanEnd(changeRange.span)); + var finalLength = changeRange.newLength + (changeRange.span.start - start); + + return createTextChangeRange(finalSpan, finalLength); + } + + function findNearestNodeStartingBeforeOrAtPosition(sourceFile: SourceFile, position: number): Node { + var bestResult: Node = sourceFile; + var lastNodeEntirelyBeforePosition: Node; + + forEachChild(sourceFile, visit); + + if (lastNodeEntirelyBeforePosition) { + var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition); + if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) { + bestResult = lastChildOfLastEntireNodeBeforePosition; + } + } + + return bestResult; + + function getLastChild(node: Node): Node { + while (true) { + var lastChild = getLastChildWorker(node); + if (lastChild) { + node = lastChild; + } + else { + return node; + } + } + } + + function getLastChildWorker(node: Node): Node { + var last: Node = undefined; + forEachChild(node, child => { + if (nodeIsPresent(child)) { + last = child; + } + }); + return last; + } + + function visit(child: Node) { + if (nodeIsMissing(child)) { + // Missing nodes are effectively invisible to us. We never even consider them + // When trying to find the nearest node before us. + return; + } + + // If the child intersects this position, then this node is currently the nearest + // node that starts before the position. + if (child.pos <= position) { + if (child.pos >= bestResult.pos) { + // This node starts before the position, and is closer to the position than + // the previous best node we found. It is now the new best node. + bestResult = child; + } + + // Now, the node may overlap the position, or it may end entirely before the + // position. If it overlaps with the position, then either it, or one of its + // children must be the nearest node before the position. So we can just + // recurse into this child to see if we can find something better. + if (position < child.end) { + // The nearest node is either this child, or one of the children inside + // of it. We've already marked this child as the best so far. Recurse + // in case one of the children is better. + forEachChild(child, visit); + + // Once we look at the children of this node, then there's no need to + // continue any further. + return true; + } + else { + Debug.assert(child.end <= position); + // The child ends entirely before this position. Say you have the following + // (where $ is the position) + // + // ? $ : <...> <...> + // + // We would want to find the nearest preceding node in "complex expr 2". + // To support that, we keep track of this node, and once we're done searching + // for a best node, we recurse down this node to see if we can find a good + // result in it. + // + // This approach allows us to quickly skip over nodes that are entirely + // before the position, while still allowing us to find any nodes in the + // last one that might be what we want. + lastNodeEntirelyBeforePosition = child; + } + } + else { + Debug.assert(child.pos > position); + // We're now at a node that is entirely past the position we're searching for. + // This node (and all following nodes) could never contribute to the result, + // so just skip them by returning 'true' here. + return true; + } + } + } + + + // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter + // indicates what changed between the 'text' that this SourceFile has and the 'newText'. + // The SourceFile will be created with the compiler attempting to reuse as many nodes from + // this file as possible. + // + // Note: this function mutates nodes from this SourceFile. That means any existing nodes + // from this SourceFile that are being held onto may change as a result (including + // becoming detached from any SourceFile). It is recommended that this SourceFile not + // be used once 'update' is called on it. + export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile { + if (textChangeRangeIsUnchanged(textChangeRange)) { + // if the text didn't change, then we can just return our current source file as-is. + return sourceFile; + } + + if (sourceFile.statements.length === 0) { + // If we don't have any statements in the current source file, then there's no real + // way to incrementally parse. So just do a full parse instead. + return parseSourceFile(sourceFile.filename, newText, sourceFile.languageVersion,/*syntaxCursor*/ undefined, /*setNodeParents*/ true) + } + + var syntaxCursor = createSyntaxCursor(sourceFile); + + // Make the actual change larger so that we know to reparse anything whose lookahead + // might have intersected the change. + var changeRange = extendToAffectedRange(sourceFile, textChangeRange); + + // The is the amount the nodes after the edit range need to be adjusted. It can be + // positive (if the edit added characters), negative (if the edit deleted characters) + // or zero (if this was a pure overwrite with nothing added/removed). + var delta = textChangeRangeNewSpan(changeRange).length - changeRange.span.length; + + // If we added or removed characters during the edit, then we need to go and adjust all + // the nodes after the edit. Those nodes may move forward down (if we inserted chars) + // or they may move backward (if we deleted chars). + // + // Doing this helps us out in two ways. First, it means that any nodes/tokens we want + // to reuse are already at the appropriate position in the new text. That way when we + // reuse them, we don't have to figure out if they need to be adjusted. Second, it makes + // it very easy to determine if we can reuse a node. If the node's position is at where + // we are in the text, then we can reuse it. Otherwise we can't. If hte node's position + // is ahead of us, then we'll need to rescan tokens. If the node's position is behind + // us, then we'll need to skip it or crumble it as appropriate + // + // We will also adjust the positions of nodes that intersect the change range as well. + // By doing this, we ensure that all the positions in the old tree are consistent, not + // just the positions of nodes entirely before/after the change range. By being + // consistent, we can then easily map from positions to nodes in the old tree easily. + // + // Also, mark any syntax elements that intersect the changed span. We know, up front, + // that we cannot reuse these elements. + updateTokenPositionsAndMarkElements(sourceFile, + changeRange.span.start, textSpanEnd(changeRange.span), textSpanEnd(textChangeRangeNewSpan(changeRange)), delta); + + // Now that we've set up our internal incremental state just proceed and parse the + // source file in the normal fashion. When possible the parser will retrieve and + // reuse nodes from the old tree. + // + // Note: passing in 'true' for setNodeParents is very important. When incrementally + // parsing, we will be reusing nodes from the old tree, and placing it into new + // parents. If we don't set the parents now, we'll end up with an observably + // inconsistent tree. Setting the parents on the new tree should be very fast. We + // will immediately bail out of walking any subtrees when we can see that their parents + // are already correct. + var result = parseSourceFile(sourceFile.filename, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true) + + return result; + } + export function isEvalOrArgumentsIdentifier(node: Node): boolean { return node.kind === SyntaxKind.Identifier && ((node).text === "eval" || (node).text === "arguments"); @@ -495,17 +857,27 @@ module ts { } } } - export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false): SourceFile { - var parsingContext: ParsingContext; - var identifiers: Map; + return parseSourceFile(filename, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes); + } + + function parseSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile { + var parsingContext: ParsingContext = 0; + var identifiers: Map = {}; var identifierCount = 0; var nodeCount = 0; - var lineStarts: number[]; - var syntacticDiagnostics: Diagnostic[]; var scanner: Scanner; var token: SyntaxKind; - var syntaxCursor: SyntaxCursor; + + var sourceFile = createNode(SyntaxKind.SourceFile, /*pos*/ 0); + + sourceFile.pos = sourceFile.end = 0; + sourceFile.referenceDiagnostics = []; + sourceFile.parseDiagnostics = []; + sourceFile.semanticDiagnostics = []; + sourceFile.languageVersion = languageVersion; + sourceFile.filename = normalizePath(filename); + sourceFile.flags = fileExtensionIs(sourceFile.filename, ".d.ts") ? NodeFlags.DeclarationFile : 0; // Flags that dictate what parsing context we're in. For example: // Whether or not we are in strict parsing mode. All that changes in strict parsing mode is @@ -553,7 +925,7 @@ module ts { // Note: it should not be necessary to save/restore these flags during speculative/lookahead // parsing. These context flags are naturally stored and restored through normal recursive // descent parsing and unwinding. - var contextFlags: ParserContextFlags; + var contextFlags: ParserContextFlags = 0; // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors @@ -582,406 +954,36 @@ module ts { // // Note: any errors at the end of the file that do not precede a regular node, should get // attached to the EOF token. - var parseErrorBeforeNextFinishedNode: boolean; + var parseErrorBeforeNextFinishedNode: boolean = false; - var sourceFile: SourceFile; + sourceFile.syntacticDiagnostics = undefined; + sourceFile.referenceDiagnostics = []; + sourceFile.parseDiagnostics = []; + sourceFile.semanticDiagnostics = []; + sourceFile.end = sourceText.length; + sourceFile.text = sourceText; - return parseSourceFile(sourceText, setParentNodes); + // Create and prime the scanner before parsing the source elements. + scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError); + token = nextToken(); - function parseSourceFile(text: string, setParentNodes: boolean): SourceFile { - // Set our initial state before parsing. - sourceText = text; - parsingContext = 0; - identifiers = {}; - lineStarts = undefined; - syntacticDiagnostics = undefined; - contextFlags = 0; - parseErrorBeforeNextFinishedNode = false; + processReferenceComments(sourceFile); - sourceFile = createNode(SyntaxKind.SourceFile, 0); - sourceFile.referenceDiagnostics = []; - sourceFile.parseDiagnostics = []; - sourceFile.semanticDiagnostics = []; + sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); + Debug.assert(token === SyntaxKind.EndOfFileToken); + sourceFile.endOfFileToken = parseTokenNode(); - // Create and prime the scanner before parsing the source elements. - scanner = createScanner(languageVersion, /*skipTrivia*/ true, sourceText, scanError); - token = nextToken(); + setExternalModuleIndicator(sourceFile); - sourceFile.flags = fileExtensionIs(filename, ".d.ts") ? NodeFlags.DeclarationFile : 0; - sourceFile.end = sourceText.length; - sourceFile.filename = normalizePath(filename); - sourceFile.text = sourceText; + sourceFile.nodeCount = nodeCount; + sourceFile.identifierCount = identifierCount; + sourceFile.identifiers = identifiers; - sourceFile.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition; - sourceFile.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter; - sourceFile.getLineStarts = getLineStarts; - sourceFile.getSyntacticDiagnostics = getSyntacticDiagnostics; - sourceFile.update = update; - - processReferenceComments(sourceFile); - - sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); - Debug.assert(token === SyntaxKind.EndOfFileToken); - sourceFile.endOfFileToken = parseTokenNode(); - - setExternalModuleIndicator(sourceFile); - - sourceFile.nodeCount = nodeCount; - sourceFile.identifierCount = identifierCount; - sourceFile.languageVersion = languageVersion; - sourceFile.identifiers = identifiers; - - if (setParentNodes) { - fixupParentReferences(sourceFile); - } - - return sourceFile; + if (setParentNodes) { + fixupParentReferences(sourceFile); } - function update(newText: string, textChangeRange: TextChangeRange) { - if (textChangeRangeIsUnchanged(textChangeRange)) { - // if the text didn't change, then we can just return our current source file as-is. - return sourceFile; - } - - if (sourceFile.statements.length === 0) { - // If we don't have any statements in the current source file, then there's no real - // way to incrementally parse. So just do a full parse instead. - return parseSourceFile(newText, /*setNodeParents*/ true); - } - - syntaxCursor = createSyntaxCursor(sourceFile); - - // Make the actual change larger so that we know to reparse anything whose lookahead - // might have intersected the change. - var changeRange = extendToAffectedRange(textChangeRange); - - // The is the amount the nodes after the edit range need to be adjusted. It can be - // positive (if the edit added characters), negative (if the edit deleted characters) - // or zero (if this was a pure overwrite with nothing added/removed). - var delta = textChangeRangeNewSpan(changeRange).length - changeRange.span.length; - - // If we added or removed characters during the edit, then we need to go and adjust all - // the nodes after the edit. Those nodes may move forward down (if we inserted chars) - // or they may move backward (if we deleted chars). - // - // Doing this helps us out in two ways. First, it means that any nodes/tokens we want - // to reuse are already at the appropriate position in the new text. That way when we - // reuse them, we don't have to figure out if they need to be adjusted. Second, it makes - // it very easy to determine if we can reuse a node. If the node's position is at where - // we are in the text, then we can reuse it. Otherwise we can't. If hte node's position - // is ahead of us, then we'll need to rescan tokens. If the node's position is behind - // us, then we'll need to skip it or crumble it as appropriate - // - // We will also adjust the positions of nodes that intersect the change range as well. - // By doing this, we ensure that all the positions in the old tree are consistent, not - // just the positions of nodes entirely before/after the change range. By being - // consistent, we can then easily map from positions to nodes in the old tree easily. - // - // Also, mark any syntax elements that intersect the changed span. We know, up front, - // that we cannot reuse these elements. - updateTokenPositionsAndMarkElements(sourceFile, - changeRange.span.start, textSpanEnd(changeRange.span), textSpanEnd(textChangeRangeNewSpan(changeRange)), delta); - - // Now that we've set up our internal incremental state just proceed and parse the - // source file in the normal fashion. When possible the parser will retrieve and - // reuse nodes from the old tree. - // - // Note: passing in 'true' for setNodeParents is very important. When incrementally - // parsing, we will be reusing nodes from the old tree, and placing it into new - // parents. If we don't set the parents now, we'll end up with an observably - // inconsistent tree. Setting the parents on the new tree should be very fast. We - // will immediately bail out of walking any subtrees when we can see that their parents - // are already correct. - var result = parseSourceFile(newText, /*setNodeParents*/ true); - - // Clear out the syntax cursor so it doesn't keep anything alive longer than it should. - syntaxCursor = undefined; - - return result; - } - - function updateTokenPositionsAndMarkElements(node: IncrementalNode, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number): void { - visitNode(node); - - function visitNode(child: IncrementalNode) { - if (child.pos > changeRangeOldEnd) { - // Node is entirely past the change range. We need to move both its pos and - // end, forward or backward appropriately. - moveElementEntirelyPastChangeRange(child, delta); - return; - } - - // Check if the element intersects the change range. If it does, then it is not - // reusable. Also, we'll need to recurse to see what constituent portions we may - // be able to use. - var fullEnd = child.end; - if (fullEnd >= changeStart) { - child.intersectsChange = true; - - // Adjust the pos or end (or both) of the intersecting element accordingly. - adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); - forEachChild(child, visitNode, visitArray); - return; - } - - // Otherwise, the node is entirely before the change range. No need to do anything with it. - } - - function visitArray(array: IncrementalNodeArray) { - if (array.pos > changeRangeOldEnd) { - // Array is entirely after the change range. We need to move it, and move any of - // its children. - moveElementEntirelyPastChangeRange(array, delta); - } - else { - // Check if the element intersects the change range. If it does, then it is not - // reusable. Also, we'll need to recurse to see what constituent portions we may - // be able to use. - var fullEnd = array.end; - if (fullEnd >= changeStart) { - array.intersectsChange = true; - - // Adjust the pos or end (or both) of the intersecting array accordingly. - adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); - for (var i = 0, n = array.length; i < n; i++) { - visitNode(array[i]); - } - } - // else { - // Otherwise, the array is entirely before the change range. No need to do anything with it. - // } - } - } - } - - function adjustIntersectingElement(element: IncrementalElement, changeStart: number, changeRangeOldEnd: number, changeRangeNewEnd: number, delta: number) { - Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range"); - Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range"); - - // We have an element that intersects the change range in some way. It may have its - // start, or its end (or both) in the changed range. We want to adjust any part - // that intersects such that the final tree is in a consistent state. i.e. all - // chlidren have spans within the span of their parent, and all siblings are ordered - // properly. - - // We may need to update both the 'pos' and the 'end' of the element. - - // If the 'pos' is before the start of the change, then we don't need to touch it. - // If it isn't, then the 'pos' must be inside the change. How we update it will - // depend if delta is positive or negative. If delta is positive then we have - // something like: - // - // -------------------AAA----------------- - // -------------------BBBCCCCCCC----------------- - // - // In this case, we consider any node that started in the change range to still be - // starting at the same position. - // - // however, if the delta is negative, then we instead have something like this: - // - // -------------------XXXYYYYYYY----------------- - // -------------------ZZZ----------------- - // - // In this case, any element that started in the 'X' range will keep its position. - // However any element htat started after that will have their pos adjusted to be - // at the end of the new range. i.e. any node that started in the 'Y' range will - // be adjusted to have their start at the end of the 'Z' range. - // - // The element will keep its position if possible. Or Move backward to the new-end - // if it's in the 'Y' range. - element.pos = Math.min(element.pos, changeRangeNewEnd); - - // If the 'end' is after the change range, then we always adjust it by the delta - // amount. However, if the end is in the change range, then how we adjust it - // will depend on if delta is positive or negative. If delta is positive then we - // have something like: - // - // -------------------AAA----------------- - // -------------------BBBCCCCCCC----------------- - // - // In this case, we consider any node that ended inside the change range to keep its - // end position. - // - // however, if the delta is negative, then we instead have something like this: - // - // -------------------XXXYYYYYYY----------------- - // -------------------ZZZ----------------- - // - // In this case, any element that ended in the 'X' range will keep its position. - // However any element htat ended after that will have their pos adjusted to be - // at the end of the new range. i.e. any node that ended in the 'Y' range will - // be adjusted to have their end at the end of the 'Z' range. - if (element.end >= changeRangeOldEnd) { - // Element ends after the change range. Always adjust the end pos. - element.end += delta; - } - else { - // Element ends in the change range. The element will keep its position if - // possible. Or Move backward to the new-end if it's in the 'Y' range. - element.end = Math.min(element.end, changeRangeNewEnd); - } - - Debug.assert(element.pos <= element.end); - if (element.parent) { - Debug.assert(element.pos >= element.parent.pos); - Debug.assert(element.end <= element.parent.end); - } - } - - function moveElementEntirelyPastChangeRange(element: IncrementalElement, delta: number) { - if (element.length) { - visitArray(element); - } - else { - visitNode(element); - } - - function visitNode(node: IncrementalNode) { - // Ditch any existing LS children we may have created. This way we can avoid - // moving them forward. - node._children = undefined; - node.pos += delta; - node.end += delta; - - forEachChild(node, visitNode, visitArray); - } - - function visitArray(array: IncrementalNodeArray) { - array.pos += delta; - array.end += delta; - - for (var i = 0, n = array.length; i < n; i++) { - visitNode(array[i]); - } - } - } - - function extendToAffectedRange(changeRange: TextChangeRange): TextChangeRange { - // Consider the following code: - // void foo() { /; } - // - // If the text changes with an insertion of / just before the semicolon then we end up with: - // void foo() { //; } - // - // If we were to just use the changeRange a is, then we would not rescan the { token - // (as it does not intersect the actual original change range). Because an edit may - // change the token touching it, we actually need to look back *at least* one token so - // that the prior token sees that change. - var maxLookahead = 1; - - var start = changeRange.span.start; - - // the first iteration aligns us with the change start. subsequent iteration move us to - // the left by maxLookahead tokens. We only need to do this as long as we're not at the - // start of the tree. - for (var i = 0; start > 0 && i <= maxLookahead; i++) { - var nearestNode = findNearestNodeStartingBeforeOrAtPosition(start); - var position = nearestNode.pos; - - start = Math.max(0, position - 1); - } - - var finalSpan = createTextSpanFromBounds(start, textSpanEnd(changeRange.span)); - var finalLength = changeRange.newLength + (changeRange.span.start - start); - - return createTextChangeRange(finalSpan, finalLength); - } - - function findNearestNodeStartingBeforeOrAtPosition(position: number): Node { - var bestResult: Node = sourceFile; - var lastNodeEntirelyBeforePosition: Node; - - forEachChild(sourceFile, visit); - - if (lastNodeEntirelyBeforePosition) { - var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition); - if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) { - bestResult = lastChildOfLastEntireNodeBeforePosition; - } - } - - return bestResult; - - function getLastChild(node: Node): Node { - while (true) { - var lastChild = getLastChildWorker(node); - if (lastChild) { - node = lastChild; - } - else { - return node; - } - } - } - - function getLastChildWorker(node: Node): Node { - var last:Node = undefined; - forEachChild(node, child => { - if (nodeIsPresent(child)) { - last = child; - } - }); - return last; - } - - function visit(child: Node) { - if (nodeIsMissing(child)) { - // Missing nodes are effectively invisible to us. We never even consider them - // When trying to find the nearest node before us. - return; - } - - // If the child intersects this position, then this node is currently the nearest - // node that starts before the position. - if (child.pos <= position) { - if (child.pos >= bestResult.pos) { - // This node starts before the position, and is closer to the position than - // the previous best node we found. It is now the new best node. - bestResult = child; - } - - // Now, the node may overlap the position, or it may end entirely before the - // position. If it overlaps with the position, then either it, or one of its - // children must be the nearest node before the position. So we can just - // recurse into this child to see if we can find something better. - if (position < child.end) { - // The nearest node is either this child, or one of the children inside - // of it. We've already marked this child as the best so far. Recurse - // in case one of the children is better. - forEachChild(child, visit); - - // Once we look at the children of this node, then there's no need to - // continue any further. - return true; - } - else { - Debug.assert(child.end <= position); - // The child ends entirely before this position. Say you have the following - // (where $ is the position) - // - // ? $ : <...> <...> - // - // We would want to find the nearest preceding node in "complex expr 2". - // To support that, we keep track of this node, and once we're done searching - // for a best node, we recurse down this node to see if we can find a good - // result in it. - // - // This approach allows us to quickly skip over nodes that are entirely - // before the position, while still allowing us to find any nodes in the - // last one that might be what we want. - lastNodeEntirelyBeforePosition = child; - } - } - else { - Debug.assert(child.pos > position); - // We're now at a node that is entirely past the position we're searching for. - // This node (and all following nodes) could never contribute to the result, - // so just skip them by returning 'true' here. - return true; - } - } - } + return sourceFile; function setContextFlag(val: Boolean, flag: ParserContextFlags) { if (val) { @@ -1072,18 +1074,6 @@ module ts { return (contextFlags & ParserContextFlags.DisallowIn) !== 0; } - function getLineStarts(): number[] { - return lineStarts || (lineStarts = computeLineStarts(sourceText)); - } - - function getLineAndCharacterFromSourcePosition(position: number) { - return getLineAndCharacterOfPosition(getLineStarts(), position); - } - - function getPositionFromSourceLineAndCharacter(line: number, character: number): number { - return getPositionFromLineAndCharacter(getLineStarts(), line, character); - } - function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { var start = scanner.getTokenPos(); var length = scanner.getTextPos() - start; @@ -4678,7 +4668,7 @@ module ts { } function processReferenceComments(sourceFile: SourceFile): void { - var triviaScanner = createScanner(languageVersion, /*skipTrivia*/false, sourceText); + var triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText); var referencedFiles: FileReference[] = []; var amdDependencies: string[] = []; var amdModuleName: string; @@ -4741,17 +4731,6 @@ module ts { ? node : undefined); } - - function getSyntacticDiagnostics() { - if (syntacticDiagnostics === undefined) { - // Don't bother doing any grammar checks if there are already parser errors. - // Otherwise we may end up with too many cascading errors. - syntacticDiagnostics = sourceFile.referenceDiagnostics.concat(sourceFile.parseDiagnostics); - } - - Debug.assert(syntacticDiagnostics !== undefined); - return syntacticDiagnostics; - } } export function isLeftHandSideExpression(expr: Expression): boolean { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 262a86ebff3..dde63394b94 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -245,7 +245,7 @@ module ts { else { files.push(file); } - forEach(file.getSyntacticDiagnostics(), e => { + forEach(getSyntacticDiagnostics(file), e => { errors.push(e); }); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 4aef773004b..fbbd69bbd69 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -278,12 +278,20 @@ module ts { return result; } - export function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number { - Debug.assert(line > 0 && line <= lineStarts.length ); + export function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number { + return computePositionFromLineAndCharacter(getLineStarts(sourceFile), line, character); + } + + export function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number { + Debug.assert(line > 0 && line <= lineStarts.length); return lineStarts[line - 1] + character - 1; } - export function getLineAndCharacterOfPosition(lineStarts: number[], position: number) { + export function getLineStarts(sourceFile: SourceFile): number[] { + return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text)); + } + + export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) { var lineNumber = binarySearch(lineStarts, position); if (lineNumber < 0) { // If the actual position was not found, @@ -298,9 +306,8 @@ module ts { }; } - export function positionToLineAndCharacter(text: string, pos: number) { - var lineStarts = computeLineStarts(text); - return getLineAndCharacterOfPosition(lineStarts, pos); + export function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter { + return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position); } var hasOwnProperty = Object.prototype.hasOwnProperty; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 52a9fb110db..5a7bd2ba913 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -72,7 +72,7 @@ module ts { function countLines(program: Program): number { var count = 0; forEach(program.getSourceFiles(), file => { - count += file.getLineAndCharacterFromPosition(file.end).line; + count += getLineAndCharacterOfPosition(file, file.end).line; }); return count; } @@ -86,7 +86,7 @@ module ts { var output = ""; if (diagnostic.file) { - var loc = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); + var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); output += diagnostic.file.filename + "(" + loc.line + "," + loc.character + "): "; } @@ -413,7 +413,7 @@ module ts { output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") - var optsList = optionDeclarations.slice(); + var optsList = filter(optionDeclarations.slice(), v => !v.experimental); optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); // We want our descriptions to align at the same column in our output, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c8572c6b5c1..eb68bab7b74 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -887,21 +887,6 @@ module ts { filename: string; text: string; - getLineAndCharacterFromPosition(position: number): LineAndCharacter; - getPositionFromLineAndCharacter(line: number, character: number): number; - getLineStarts(): number[]; - - // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter - // indicates what changed between the 'text' that this SourceFile has and the 'newText'. - // The SourceFile will be created with the compiler attempting to reuse as many nodes from - // this file as possible. - // - // Note: this function mutates nodes from this SourceFile. That means any existing nodes - // from this SourceFile that are being held onto may change as a result (including - // becoming detached from any SourceFile). It is recommended that this SourceFile not - // be used once 'update' is called on it. - update(newText: string, textChangeRange: TextChangeRange): SourceFile; - amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; @@ -913,12 +898,15 @@ module ts { // missing tokens, or tokens it didn't know how to deal with). parseDiagnostics: Diagnostic[]; - // Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics). - getSyntacticDiagnostics(): Diagnostic[]; + //getSyntacticDiagnostics(): Diagnostic[]; // File level diagnostics reported by the binder. semanticDiagnostics: Diagnostic[]; + // Returns all syntactic diagnostics (i.e. the reference, parser and grammar diagnostics). + // This field should never be used directly, use getSyntacticDiagnostics function instead. + syntacticDiagnostics: Diagnostic[]; + hasNoDefaultLib: boolean; externalModuleIndicator: Node; // The first node that causes this file to be an external module nodeCount: number; @@ -926,6 +914,10 @@ module ts { symbolCount: number; languageVersion: ScriptTarget; identifiers: Map; + + // Stores a line map for the file. + // This field should never be used directly to obtain line map, use getLineMap function instead. + lineMap: number[]; } export interface ScriptReferenceHost { @@ -1476,6 +1468,7 @@ module ts { target?: ScriptTarget; version?: boolean; watch?: boolean; + stripInternal?: boolean; [option: string]: string | number | boolean; } @@ -1514,6 +1507,7 @@ module ts { description?: DiagnosticMessage; // The message describing what the command line switch does paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type' + experimental?: boolean; } export const enum CharacterCodes { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6c894ad7d9c..a333af5f383 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -109,7 +109,7 @@ module ts { // This is a useful function for debugging purposes. export function nodePosToString(node: Node): string { var file = getSourceFileOfNode(node); - var loc = file.getLineAndCharacterFromPosition(node.pos); + var loc = getLineAndCharacterOfPosition(file, node.pos); return file.filename + "(" + loc.line + "," + loc.character + ")"; } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index e0b74318e26..f0804b414be 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -388,7 +388,7 @@ module FourSlash { this.currentCaretPosition = pos; var lineStarts = ts.computeLineStarts(this.getCurrentFileContent()); - var lineCharPos = ts.getLineAndCharacterOfPosition(lineStarts, pos); + var lineCharPos = ts.computeLineAndCharacterOfPosition(lineStarts, pos); this.scenarioActions.push(''); } @@ -1393,7 +1393,7 @@ module FourSlash { var incrementalSourceFile = this.languageService.getSourceFile(this.activeFile.fileName); Utils.assertInvariants(incrementalSourceFile, /*parent:*/ undefined); - var incrementalSyntaxDiagnostics = incrementalSourceFile.getSyntacticDiagnostics(); + var incrementalSyntaxDiagnostics = ts.getSyntacticDiagnostics(incrementalSourceFile); // Check syntactic structure var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName); @@ -1401,7 +1401,7 @@ module FourSlash { var referenceSourceFile = ts.createLanguageServiceSourceFile( this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*setNodeParents:*/ false); - var referenceSyntaxDiagnostics = referenceSourceFile.getSyntacticDiagnostics(); + var referenceSyntaxDiagnostics = ts.getSyntacticDiagnostics(referenceSourceFile); Utils.assertDiagnosticsEquals(incrementalSyntaxDiagnostics, referenceSyntaxDiagnostics); Utils.assertStructuralEquals(incrementalSourceFile, referenceSourceFile); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 525e7c413e2..dc984aaf60d 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1017,6 +1017,9 @@ module Harness { options.removeComments = setting.value === 'false'; break; + case 'stripinternal': + options.stripInternal = !!setting.value; + case 'usecasesensitivefilenames': useCaseSensitiveFileNames = setting.value === 'true'; break; @@ -1464,7 +1467,7 @@ module Harness { var optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines // List of allowed metadata names - var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors"]; + var fileMetadataNames = ["filename", "comments", "declaration", "module", "nolib", "sourcemap", "target", "out", "outdir", "noemitonerror", "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 1d442822866..5c6b0ff35b3 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -286,7 +286,7 @@ module Harness.LanguageService { assert.isTrue(line >= 1); assert.isTrue(col >= 1); - return ts.getPositionFromLineAndCharacter(script.lineMap, line, col); + return ts.computePositionFromLineAndCharacter(script.lineMap, line, col); } /** @@ -297,7 +297,7 @@ module Harness.LanguageService { var script: ScriptInfo = this.fileNameToScript[fileName]; assert.isNotNull(script); - var result = ts.getLineAndCharacterOfPosition(script.lineMap, position); + var result = ts.computeLineAndCharacterOfPosition(script.lineMap, position); assert.isTrue(result.line >= 1); assert.isTrue(result.character >= 1); diff --git a/src/services/services.ts b/src/services/services.ts index 978bc2ad36b..a7525709a05 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -61,6 +61,11 @@ module ts { scriptSnapshot: IScriptSnapshot; nameTable: Map; getNamedDeclarations(): Declaration[]; + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; + getLineStarts(): number[]; + getPositionFromLineAndCharacter(line: number, character: number): number; + getSyntacticDiagnostics(): Diagnostic[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** @@ -716,22 +721,16 @@ module ts { public filename: string; public text: string; public scriptSnapshot: IScriptSnapshot; + public lineMap: number[]; public statements: NodeArray; public endOfFileToken: Node; - // These methods will have their implementation provided by the implementation the - // compiler actually exports off of SourceFile. - public getLineAndCharacterFromPosition: (position: number) => LineAndCharacter; - public getPositionFromLineAndCharacter: (line: number, character: number) => number; - public getLineStarts: () => number[]; - public getSyntacticDiagnostics: () => Diagnostic[]; - public update: (newText: string, textChangeRange: TextChangeRange) => SourceFile; - public amdDependencies: string[]; public amdModuleName: string; public referencedFiles: FileReference[]; + public syntacticDiagnostics: Diagnostic[]; public referenceDiagnostics: Diagnostic[]; public parseDiagnostics: Diagnostic[]; public semanticDiagnostics: Diagnostic[]; @@ -748,6 +747,26 @@ module ts { private namedDeclarations: Declaration[]; + public getSyntacticDiagnostics(): Diagnostic[]{ + return getSyntacticDiagnostics(this); + } + + public update(newText: string, textChangeRange: TextChangeRange): SourceFile { + return updateSourceFile(this, newText, textChangeRange); + } + + public getLineAndCharacterFromPosition(position: number): LineAndCharacter { + return getLineAndCharacterOfPosition(this, position); + } + + public getLineStarts(): number[] { + return getLineStarts(this); + } + + public getPositionFromLineAndCharacter(line: number, character: number): number { + return getPositionFromLineAndCharacter(this, line, character); + } + public getNamedDeclarations() { if (!this.namedDeclarations) { var sourceFile = this; @@ -1633,7 +1652,7 @@ module ts { if (version !== sourceFile.version) { // Once incremental parsing is ready, then just call into this function. if (!disableIncrementalParsing) { - var newSourceFile = sourceFile.update(scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange); + var newSourceFile = updateSourceFile(sourceFile, scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange); setSourceFileFields(newSourceFile, scriptSnapshot, version); // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index f70ee02415a..f6a86d4c245 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -725,17 +725,13 @@ declare module "typescript" { endOfFileToken: Node; filename: string; text: string; - getLineAndCharacterFromPosition(position: number): LineAndCharacter; - getPositionFromLineAndCharacter(line: number, character: number): number; - getLineStarts(): number[]; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; referenceDiagnostics: Diagnostic[]; parseDiagnostics: Diagnostic[]; - getSyntacticDiagnostics(): Diagnostic[]; semanticDiagnostics: Diagnostic[]; + syntacticDiagnostics: Diagnostic[]; hasNoDefaultLib: boolean; externalModuleIndicator: Node; nodeCount: number; @@ -743,6 +739,7 @@ declare module "typescript" { symbolCount: number; languageVersion: ScriptTarget; identifiers: Map; + lineMap: number[]; } interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; @@ -1393,15 +1390,14 @@ declare module "typescript" { } function tokenToString(t: SyntaxKind): string; function computeLineStarts(text: string): number[]; - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { - line: number; - character: number; - }; - function positionToLineAndCharacter(text: string, pos: number): { + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; + function getLineStarts(sourceFile: SourceFile): number[]; + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { line: number; character: number; }; + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; @@ -1417,6 +1413,8 @@ declare module "typescript" { function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function modifierToFlag(token: SyntaxKind): NodeFlags; + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function isLeftHandSideExpression(expr: Expression): boolean; @@ -1476,6 +1474,11 @@ declare module "typescript" { scriptSnapshot: IScriptSnapshot; nameTable: Map; getNamedDeclarations(): Declaration[]; + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; + getLineStarts(): number[]; + getPositionFromLineAndCharacter(line: number, character: number): number; + getSyntacticDiagnostics(): Diagnostic[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 090c42a7216..4ef90c6d114 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -90,11 +90,11 @@ export function compile(filenames: string[], options: ts.CompilerOptions): void var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); >lineChar : ts.LineAndCharacter >diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start) : ts.LineAndCharacter ->diagnostic.file.getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>diagnostic.file.getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >diagnostic.file : ts.SourceFile >diagnostic : ts.Diagnostic >file : ts.SourceFile ->getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >diagnostic.start : number >diagnostic : ts.Diagnostic >start : number @@ -2209,26 +2209,6 @@ declare module "typescript" { text: string; >text : string - getLineAndCharacterFromPosition(position: number): LineAndCharacter; ->getLineAndCharacterFromPosition : (position: number) => LineAndCharacter ->position : number ->LineAndCharacter : LineAndCharacter - - getPositionFromLineAndCharacter(line: number, character: number): number; ->getPositionFromLineAndCharacter : (line: number, character: number) => number ->line : number ->character : number - - getLineStarts(): number[]; ->getLineStarts : () => number[] - - update(newText: string, textChangeRange: TextChangeRange): SourceFile; ->update : (newText: string, textChangeRange: TextChangeRange) => SourceFile ->newText : string ->textChangeRange : TextChangeRange ->TextChangeRange : TextChangeRange ->SourceFile : SourceFile - amdDependencies: string[]; >amdDependencies : string[] @@ -2245,14 +2225,14 @@ declare module "typescript" { parseDiagnostics: Diagnostic[]; >parseDiagnostics : Diagnostic[] ->Diagnostic : Diagnostic - - getSyntacticDiagnostics(): Diagnostic[]; ->getSyntacticDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic semanticDiagnostics: Diagnostic[]; >semanticDiagnostics : Diagnostic[] +>Diagnostic : Diagnostic + + syntacticDiagnostics: Diagnostic[]; +>syntacticDiagnostics : Diagnostic[] >Diagnostic : Diagnostic hasNoDefaultLib: boolean; @@ -2278,6 +2258,9 @@ declare module "typescript" { identifiers: Map; >identifiers : Map >Map : Map + + lineMap: number[]; +>lineMap : number[] } interface ScriptReferenceHost { >ScriptReferenceHost : ScriptReferenceHost @@ -4446,14 +4429,26 @@ declare module "typescript" { >computeLineStarts : (text: string) => number[] >text : string - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; ->getPositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; +>getPositionFromLineAndCharacter : (sourceFile: SourceFile, line: number, character: number) => number +>sourceFile : SourceFile +>SourceFile : SourceFile +>line : number +>character : number + + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; +>computePositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number >lineStarts : number[] >line : number >character : number - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { ->getLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } + function getLineStarts(sourceFile: SourceFile): number[]; +>getLineStarts : (sourceFile: SourceFile) => number[] +>sourceFile : SourceFile +>SourceFile : SourceFile + + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { +>computeLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } >lineStarts : number[] >position : number @@ -4464,18 +4459,13 @@ declare module "typescript" { >character : number }; - function positionToLineAndCharacter(text: string, pos: number): { ->positionToLineAndCharacter : (text: string, pos: number) => { line: number; character: number; } ->text : string ->pos : number + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; +>getLineAndCharacterOfPosition : (sourceFile: SourceFile, position: number) => LineAndCharacter +>sourceFile : SourceFile +>SourceFile : SourceFile +>position : number +>LineAndCharacter : LineAndCharacter - line: number; ->line : number - - character: number; ->character : number - - }; function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number @@ -4562,6 +4552,21 @@ declare module "typescript" { >SyntaxKind : SyntaxKind >NodeFlags : NodeFlags + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; +>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile +>sourceFile : SourceFile +>SourceFile : SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile + function isEvalOrArgumentsIdentifier(node: Node): boolean; >isEvalOrArgumentsIdentifier : (node: Node) => boolean >node : Node @@ -4783,6 +4788,30 @@ declare module "typescript" { getNamedDeclarations(): Declaration[]; >getNamedDeclarations : () => Declaration[] >Declaration : Declaration + + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; +>getLineAndCharacterFromPosition : (pos: number) => LineAndCharacter +>pos : number +>LineAndCharacter : LineAndCharacter + + getLineStarts(): number[]; +>getLineStarts : () => number[] + + getPositionFromLineAndCharacter(line: number, character: number): number; +>getPositionFromLineAndCharacter : (line: number, character: number) => number +>line : number +>character : number + + getSyntacticDiagnostics(): Diagnostic[]; +>getSyntacticDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + + update(newText: string, textChangeRange: TextChangeRange): SourceFile; +>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b3905862c67..aef5c70349b 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -754,17 +754,13 @@ declare module "typescript" { endOfFileToken: Node; filename: string; text: string; - getLineAndCharacterFromPosition(position: number): LineAndCharacter; - getPositionFromLineAndCharacter(line: number, character: number): number; - getLineStarts(): number[]; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; referenceDiagnostics: Diagnostic[]; parseDiagnostics: Diagnostic[]; - getSyntacticDiagnostics(): Diagnostic[]; semanticDiagnostics: Diagnostic[]; + syntacticDiagnostics: Diagnostic[]; hasNoDefaultLib: boolean; externalModuleIndicator: Node; nodeCount: number; @@ -772,6 +768,7 @@ declare module "typescript" { symbolCount: number; languageVersion: ScriptTarget; identifiers: Map; + lineMap: number[]; } interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; @@ -1422,15 +1419,14 @@ declare module "typescript" { } function tokenToString(t: SyntaxKind): string; function computeLineStarts(text: string): number[]; - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { - line: number; - character: number; - }; - function positionToLineAndCharacter(text: string, pos: number): { + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; + function getLineStarts(sourceFile: SourceFile): number[]; + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { line: number; character: number; }; + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; @@ -1446,6 +1442,8 @@ declare module "typescript" { function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function modifierToFlag(token: SyntaxKind): NodeFlags; + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function isLeftHandSideExpression(expr: Expression): boolean; @@ -1505,6 +1503,11 @@ declare module "typescript" { scriptSnapshot: IScriptSnapshot; nameTable: Map; getNamedDeclarations(): Declaration[]; + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; + getLineStarts(): number[]; + getPositionFromLineAndCharacter(line: number, character: number): number; + getSyntacticDiagnostics(): Diagnostic[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 5f613ec140c..957ccd3c01e 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -227,9 +227,9 @@ export function delint(sourceFile: ts.SourceFile) { var lineChar = sourceFile.getLineAndCharacterFromPosition(node.getStart()); >lineChar : ts.LineAndCharacter >sourceFile.getLineAndCharacterFromPosition(node.getStart()) : ts.LineAndCharacter ->sourceFile.getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>sourceFile.getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >sourceFile : ts.SourceFile ->getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >node.getStart() : number >node.getStart : (sourceFile?: ts.SourceFile) => number >node : ts.Node @@ -2339,26 +2339,6 @@ declare module "typescript" { text: string; >text : string - getLineAndCharacterFromPosition(position: number): LineAndCharacter; ->getLineAndCharacterFromPosition : (position: number) => LineAndCharacter ->position : number ->LineAndCharacter : LineAndCharacter - - getPositionFromLineAndCharacter(line: number, character: number): number; ->getPositionFromLineAndCharacter : (line: number, character: number) => number ->line : number ->character : number - - getLineStarts(): number[]; ->getLineStarts : () => number[] - - update(newText: string, textChangeRange: TextChangeRange): SourceFile; ->update : (newText: string, textChangeRange: TextChangeRange) => SourceFile ->newText : string ->textChangeRange : TextChangeRange ->TextChangeRange : TextChangeRange ->SourceFile : SourceFile - amdDependencies: string[]; >amdDependencies : string[] @@ -2375,14 +2355,14 @@ declare module "typescript" { parseDiagnostics: Diagnostic[]; >parseDiagnostics : Diagnostic[] ->Diagnostic : Diagnostic - - getSyntacticDiagnostics(): Diagnostic[]; ->getSyntacticDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic semanticDiagnostics: Diagnostic[]; >semanticDiagnostics : Diagnostic[] +>Diagnostic : Diagnostic + + syntacticDiagnostics: Diagnostic[]; +>syntacticDiagnostics : Diagnostic[] >Diagnostic : Diagnostic hasNoDefaultLib: boolean; @@ -2408,6 +2388,9 @@ declare module "typescript" { identifiers: Map; >identifiers : Map >Map : Map + + lineMap: number[]; +>lineMap : number[] } interface ScriptReferenceHost { >ScriptReferenceHost : ScriptReferenceHost @@ -4576,14 +4559,26 @@ declare module "typescript" { >computeLineStarts : (text: string) => number[] >text : string - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; ->getPositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; +>getPositionFromLineAndCharacter : (sourceFile: SourceFile, line: number, character: number) => number +>sourceFile : SourceFile +>SourceFile : SourceFile +>line : number +>character : number + + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; +>computePositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number >lineStarts : number[] >line : number >character : number - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { ->getLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } + function getLineStarts(sourceFile: SourceFile): number[]; +>getLineStarts : (sourceFile: SourceFile) => number[] +>sourceFile : SourceFile +>SourceFile : SourceFile + + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { +>computeLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } >lineStarts : number[] >position : number @@ -4594,18 +4589,13 @@ declare module "typescript" { >character : number }; - function positionToLineAndCharacter(text: string, pos: number): { ->positionToLineAndCharacter : (text: string, pos: number) => { line: number; character: number; } ->text : string ->pos : number + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; +>getLineAndCharacterOfPosition : (sourceFile: SourceFile, position: number) => LineAndCharacter +>sourceFile : SourceFile +>SourceFile : SourceFile +>position : number +>LineAndCharacter : LineAndCharacter - line: number; ->line : number - - character: number; ->character : number - - }; function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number @@ -4692,6 +4682,21 @@ declare module "typescript" { >SyntaxKind : SyntaxKind >NodeFlags : NodeFlags + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; +>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile +>sourceFile : SourceFile +>SourceFile : SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile + function isEvalOrArgumentsIdentifier(node: Node): boolean; >isEvalOrArgumentsIdentifier : (node: Node) => boolean >node : Node @@ -4913,6 +4918,30 @@ declare module "typescript" { getNamedDeclarations(): Declaration[]; >getNamedDeclarations : () => Declaration[] >Declaration : Declaration + + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; +>getLineAndCharacterFromPosition : (pos: number) => LineAndCharacter +>pos : number +>LineAndCharacter : LineAndCharacter + + getLineStarts(): number[]; +>getLineStarts : () => number[] + + getPositionFromLineAndCharacter(line: number, character: number): number; +>getPositionFromLineAndCharacter : (line: number, character: number) => number +>line : number +>character : number + + getSyntacticDiagnostics(): Diagnostic[]; +>getSyntacticDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + + update(newText: string, textChangeRange: TextChangeRange): SourceFile; +>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 06546d2fdbc..33cea1ea0af 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -755,17 +755,13 @@ declare module "typescript" { endOfFileToken: Node; filename: string; text: string; - getLineAndCharacterFromPosition(position: number): LineAndCharacter; - getPositionFromLineAndCharacter(line: number, character: number): number; - getLineStarts(): number[]; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; referenceDiagnostics: Diagnostic[]; parseDiagnostics: Diagnostic[]; - getSyntacticDiagnostics(): Diagnostic[]; semanticDiagnostics: Diagnostic[]; + syntacticDiagnostics: Diagnostic[]; hasNoDefaultLib: boolean; externalModuleIndicator: Node; nodeCount: number; @@ -773,6 +769,7 @@ declare module "typescript" { symbolCount: number; languageVersion: ScriptTarget; identifiers: Map; + lineMap: number[]; } interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; @@ -1423,15 +1420,14 @@ declare module "typescript" { } function tokenToString(t: SyntaxKind): string; function computeLineStarts(text: string): number[]; - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { - line: number; - character: number; - }; - function positionToLineAndCharacter(text: string, pos: number): { + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; + function getLineStarts(sourceFile: SourceFile): number[]; + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { line: number; character: number; }; + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; @@ -1447,6 +1443,8 @@ declare module "typescript" { function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function modifierToFlag(token: SyntaxKind): NodeFlags; + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function isLeftHandSideExpression(expr: Expression): boolean; @@ -1506,6 +1504,11 @@ declare module "typescript" { scriptSnapshot: IScriptSnapshot; nameTable: Map; getNamedDeclarations(): Declaration[]; + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; + getLineStarts(): number[]; + getPositionFromLineAndCharacter(line: number, character: number): number; + getSyntacticDiagnostics(): Diagnostic[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index f92c2f36774..c091af5effb 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -210,11 +210,11 @@ function transform(contents: string, compilerOptions: ts.CompilerOptions = {}) { >filename : string >e.file.getLineAndCharacterFromPosition(e.start).line : number >e.file.getLineAndCharacterFromPosition(e.start) : ts.LineAndCharacter ->e.file.getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>e.file.getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >e.file : ts.SourceFile >e : ts.Diagnostic >file : ts.SourceFile ->getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >e.start : number >e : ts.Diagnostic >start : number @@ -2287,26 +2287,6 @@ declare module "typescript" { text: string; >text : string - getLineAndCharacterFromPosition(position: number): LineAndCharacter; ->getLineAndCharacterFromPosition : (position: number) => LineAndCharacter ->position : number ->LineAndCharacter : LineAndCharacter - - getPositionFromLineAndCharacter(line: number, character: number): number; ->getPositionFromLineAndCharacter : (line: number, character: number) => number ->line : number ->character : number - - getLineStarts(): number[]; ->getLineStarts : () => number[] - - update(newText: string, textChangeRange: TextChangeRange): SourceFile; ->update : (newText: string, textChangeRange: TextChangeRange) => SourceFile ->newText : string ->textChangeRange : TextChangeRange ->TextChangeRange : TextChangeRange ->SourceFile : SourceFile - amdDependencies: string[]; >amdDependencies : string[] @@ -2323,14 +2303,14 @@ declare module "typescript" { parseDiagnostics: Diagnostic[]; >parseDiagnostics : Diagnostic[] ->Diagnostic : Diagnostic - - getSyntacticDiagnostics(): Diagnostic[]; ->getSyntacticDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic semanticDiagnostics: Diagnostic[]; >semanticDiagnostics : Diagnostic[] +>Diagnostic : Diagnostic + + syntacticDiagnostics: Diagnostic[]; +>syntacticDiagnostics : Diagnostic[] >Diagnostic : Diagnostic hasNoDefaultLib: boolean; @@ -2356,6 +2336,9 @@ declare module "typescript" { identifiers: Map; >identifiers : Map >Map : Map + + lineMap: number[]; +>lineMap : number[] } interface ScriptReferenceHost { >ScriptReferenceHost : ScriptReferenceHost @@ -4524,14 +4507,26 @@ declare module "typescript" { >computeLineStarts : (text: string) => number[] >text : string - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; ->getPositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; +>getPositionFromLineAndCharacter : (sourceFile: SourceFile, line: number, character: number) => number +>sourceFile : SourceFile +>SourceFile : SourceFile +>line : number +>character : number + + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; +>computePositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number >lineStarts : number[] >line : number >character : number - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { ->getLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } + function getLineStarts(sourceFile: SourceFile): number[]; +>getLineStarts : (sourceFile: SourceFile) => number[] +>sourceFile : SourceFile +>SourceFile : SourceFile + + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { +>computeLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } >lineStarts : number[] >position : number @@ -4542,18 +4537,13 @@ declare module "typescript" { >character : number }; - function positionToLineAndCharacter(text: string, pos: number): { ->positionToLineAndCharacter : (text: string, pos: number) => { line: number; character: number; } ->text : string ->pos : number + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; +>getLineAndCharacterOfPosition : (sourceFile: SourceFile, position: number) => LineAndCharacter +>sourceFile : SourceFile +>SourceFile : SourceFile +>position : number +>LineAndCharacter : LineAndCharacter - line: number; ->line : number - - character: number; ->character : number - - }; function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number @@ -4640,6 +4630,21 @@ declare module "typescript" { >SyntaxKind : SyntaxKind >NodeFlags : NodeFlags + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; +>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile +>sourceFile : SourceFile +>SourceFile : SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile + function isEvalOrArgumentsIdentifier(node: Node): boolean; >isEvalOrArgumentsIdentifier : (node: Node) => boolean >node : Node @@ -4861,6 +4866,30 @@ declare module "typescript" { getNamedDeclarations(): Declaration[]; >getNamedDeclarations : () => Declaration[] >Declaration : Declaration + + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; +>getLineAndCharacterFromPosition : (pos: number) => LineAndCharacter +>pos : number +>LineAndCharacter : LineAndCharacter + + getLineStarts(): number[]; +>getLineStarts : () => number[] + + getPositionFromLineAndCharacter(line: number, character: number): number; +>getPositionFromLineAndCharacter : (line: number, character: number) => number +>line : number +>character : number + + getSyntacticDiagnostics(): Diagnostic[]; +>getSyntacticDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + + update(newText: string, textChangeRange: TextChangeRange): SourceFile; +>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 9a7064117bf..7c70ee1532e 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -792,17 +792,13 @@ declare module "typescript" { endOfFileToken: Node; filename: string; text: string; - getLineAndCharacterFromPosition(position: number): LineAndCharacter; - getPositionFromLineAndCharacter(line: number, character: number): number; - getLineStarts(): number[]; - update(newText: string, textChangeRange: TextChangeRange): SourceFile; amdDependencies: string[]; amdModuleName: string; referencedFiles: FileReference[]; referenceDiagnostics: Diagnostic[]; parseDiagnostics: Diagnostic[]; - getSyntacticDiagnostics(): Diagnostic[]; semanticDiagnostics: Diagnostic[]; + syntacticDiagnostics: Diagnostic[]; hasNoDefaultLib: boolean; externalModuleIndicator: Node; nodeCount: number; @@ -810,6 +806,7 @@ declare module "typescript" { symbolCount: number; languageVersion: ScriptTarget; identifiers: Map; + lineMap: number[]; } interface ScriptReferenceHost { getCompilerOptions(): CompilerOptions; @@ -1460,15 +1457,14 @@ declare module "typescript" { } function tokenToString(t: SyntaxKind): string; function computeLineStarts(text: string): number[]; - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { - line: number; - character: number; - }; - function positionToLineAndCharacter(text: string, pos: number): { + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; + function getLineStarts(sourceFile: SourceFile): number[]; + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { line: number; character: number; }; + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; @@ -1484,6 +1480,8 @@ declare module "typescript" { function createNode(kind: SyntaxKind): Node; function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T; function modifierToFlag(token: SyntaxKind): NodeFlags; + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; function isEvalOrArgumentsIdentifier(node: Node): boolean; function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes?: boolean): SourceFile; function isLeftHandSideExpression(expr: Expression): boolean; @@ -1543,6 +1541,11 @@ declare module "typescript" { scriptSnapshot: IScriptSnapshot; nameTable: Map; getNamedDeclarations(): Declaration[]; + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; + getLineStarts(): number[]; + getPositionFromLineAndCharacter(line: number, character: number): number; + getSyntacticDiagnostics(): Diagnostic[]; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 938db86d09e..c3d03259385 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -337,11 +337,11 @@ function watch(rootFilenames: string[], options: ts.CompilerOptions) { var lineChar = diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start); >lineChar : ts.LineAndCharacter >diagnostic.file.getLineAndCharacterFromPosition(diagnostic.start) : ts.LineAndCharacter ->diagnostic.file.getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>diagnostic.file.getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >diagnostic.file : ts.SourceFile >diagnostic : ts.Diagnostic >file : ts.SourceFile ->getLineAndCharacterFromPosition : (position: number) => ts.LineAndCharacter +>getLineAndCharacterFromPosition : (pos: number) => ts.LineAndCharacter >diagnostic.start : number >diagnostic : ts.Diagnostic >start : number @@ -2465,26 +2465,6 @@ declare module "typescript" { text: string; >text : string - getLineAndCharacterFromPosition(position: number): LineAndCharacter; ->getLineAndCharacterFromPosition : (position: number) => LineAndCharacter ->position : number ->LineAndCharacter : LineAndCharacter - - getPositionFromLineAndCharacter(line: number, character: number): number; ->getPositionFromLineAndCharacter : (line: number, character: number) => number ->line : number ->character : number - - getLineStarts(): number[]; ->getLineStarts : () => number[] - - update(newText: string, textChangeRange: TextChangeRange): SourceFile; ->update : (newText: string, textChangeRange: TextChangeRange) => SourceFile ->newText : string ->textChangeRange : TextChangeRange ->TextChangeRange : TextChangeRange ->SourceFile : SourceFile - amdDependencies: string[]; >amdDependencies : string[] @@ -2501,14 +2481,14 @@ declare module "typescript" { parseDiagnostics: Diagnostic[]; >parseDiagnostics : Diagnostic[] ->Diagnostic : Diagnostic - - getSyntacticDiagnostics(): Diagnostic[]; ->getSyntacticDiagnostics : () => Diagnostic[] >Diagnostic : Diagnostic semanticDiagnostics: Diagnostic[]; >semanticDiagnostics : Diagnostic[] +>Diagnostic : Diagnostic + + syntacticDiagnostics: Diagnostic[]; +>syntacticDiagnostics : Diagnostic[] >Diagnostic : Diagnostic hasNoDefaultLib: boolean; @@ -2534,6 +2514,9 @@ declare module "typescript" { identifiers: Map; >identifiers : Map >Map : Map + + lineMap: number[]; +>lineMap : number[] } interface ScriptReferenceHost { >ScriptReferenceHost : ScriptReferenceHost @@ -4702,14 +4685,26 @@ declare module "typescript" { >computeLineStarts : (text: string) => number[] >text : string - function getPositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; ->getPositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number + function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number; +>getPositionFromLineAndCharacter : (sourceFile: SourceFile, line: number, character: number) => number +>sourceFile : SourceFile +>SourceFile : SourceFile +>line : number +>character : number + + function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number; +>computePositionFromLineAndCharacter : (lineStarts: number[], line: number, character: number) => number >lineStarts : number[] >line : number >character : number - function getLineAndCharacterOfPosition(lineStarts: number[], position: number): { ->getLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } + function getLineStarts(sourceFile: SourceFile): number[]; +>getLineStarts : (sourceFile: SourceFile) => number[] +>sourceFile : SourceFile +>SourceFile : SourceFile + + function computeLineAndCharacterOfPosition(lineStarts: number[], position: number): { +>computeLineAndCharacterOfPosition : (lineStarts: number[], position: number) => { line: number; character: number; } >lineStarts : number[] >position : number @@ -4720,18 +4715,13 @@ declare module "typescript" { >character : number }; - function positionToLineAndCharacter(text: string, pos: number): { ->positionToLineAndCharacter : (text: string, pos: number) => { line: number; character: number; } ->text : string ->pos : number + function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; +>getLineAndCharacterOfPosition : (sourceFile: SourceFile, position: number) => LineAndCharacter +>sourceFile : SourceFile +>SourceFile : SourceFile +>position : number +>LineAndCharacter : LineAndCharacter - line: number; ->line : number - - character: number; ->character : number - - }; function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number @@ -4818,6 +4808,21 @@ declare module "typescript" { >SyntaxKind : SyntaxKind >NodeFlags : NodeFlags + function getSyntacticDiagnostics(sourceFile: SourceFile): Diagnostic[]; +>getSyntacticDiagnostics : (sourceFile: SourceFile) => Diagnostic[] +>sourceFile : SourceFile +>SourceFile : SourceFile +>Diagnostic : Diagnostic + + function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange): SourceFile; +>updateSourceFile : (sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange) => SourceFile +>sourceFile : SourceFile +>SourceFile : SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile + function isEvalOrArgumentsIdentifier(node: Node): boolean; >isEvalOrArgumentsIdentifier : (node: Node) => boolean >node : Node @@ -5039,6 +5044,30 @@ declare module "typescript" { getNamedDeclarations(): Declaration[]; >getNamedDeclarations : () => Declaration[] >Declaration : Declaration + + getLineAndCharacterFromPosition(pos: number): LineAndCharacter; +>getLineAndCharacterFromPosition : (pos: number) => LineAndCharacter +>pos : number +>LineAndCharacter : LineAndCharacter + + getLineStarts(): number[]; +>getLineStarts : () => number[] + + getPositionFromLineAndCharacter(line: number, character: number): number; +>getPositionFromLineAndCharacter : (line: number, character: number) => number +>line : number +>character : number + + getSyntacticDiagnostics(): Diagnostic[]; +>getSyntacticDiagnostics : () => Diagnostic[] +>Diagnostic : Diagnostic + + update(newText: string, textChangeRange: TextChangeRange): SourceFile; +>update : (newText: string, textChangeRange: TextChangeRange) => SourceFile +>newText : string +>textChangeRange : TextChangeRange +>TextChangeRange : TextChangeRange +>SourceFile : SourceFile } /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the diff --git a/tests/baselines/reference/stripInternal1.js b/tests/baselines/reference/stripInternal1.js new file mode 100644 index 00000000000..9deadf1fc31 --- /dev/null +++ b/tests/baselines/reference/stripInternal1.js @@ -0,0 +1,25 @@ +//// [stripInternal1.ts] + +class C { + foo(): void { } + // @internal + bar(): void { } +} + +//// [stripInternal1.js] +var C = (function () { + function C() { + } + C.prototype.foo = function () { + }; + // @internal + C.prototype.bar = function () { + }; + return C; +})(); + + +//// [stripInternal1.d.ts] +declare class C { + foo(): void; +} diff --git a/tests/baselines/reference/stripInternal1.types b/tests/baselines/reference/stripInternal1.types new file mode 100644 index 00000000000..8452de45596 --- /dev/null +++ b/tests/baselines/reference/stripInternal1.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/stripInternal1.ts === + +class C { +>C : C + + foo(): void { } +>foo : () => void + + // @internal + bar(): void { } +>bar : () => void +} diff --git a/tests/cases/compiler/stripInternal1.ts b/tests/cases/compiler/stripInternal1.ts new file mode 100644 index 00000000000..77f65e6119c --- /dev/null +++ b/tests/cases/compiler/stripInternal1.ts @@ -0,0 +1,8 @@ +// @declaration:true +// @stripInternal:true + +class C { + foo(): void { } + // @internal + bar(): void { } +} \ No newline at end of file diff --git a/tests/cases/unittests/incrementalParser.ts b/tests/cases/unittests/incrementalParser.ts index 6db3d70128c..97809b86dae 100644 --- a/tests/cases/unittests/incrementalParser.ts +++ b/tests/cases/unittests/incrementalParser.ts @@ -24,8 +24,8 @@ module ts { } function assertSameDiagnostics(file1: SourceFile, file2: SourceFile) { - var diagnostics1 = file1.getSyntacticDiagnostics(); - var diagnostics2 = file2.getSyntacticDiagnostics(); + var diagnostics1 = getSyntacticDiagnostics(file1); + var diagnostics2 = getSyntacticDiagnostics(file2); assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length"); for (var i = 0, n = diagnostics1.length; i < n; i++) {