diff --git a/Jakefile.js b/Jakefile.js index 288472a697b..5a3348a61eb 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -108,17 +108,6 @@ var serverCoreSources = [ return path.join(serverDirectory, f); }); -var scriptSources = [ - "tslint/booleanTriviaRule.ts", - "tslint/nextLineRule.ts", - "tslint/noNullRule.ts", - "tslint/preferConstRule.ts", - "tslint/typeOperatorSpacingRule.ts", - "tslint/noInOperatorRule.ts" -].map(function (f) { - return path.join(scriptsDirectory, f); -}); - var serverSources = serverCoreSources.concat(servicesSources); var languageServiceLibrarySources = [ @@ -878,7 +867,8 @@ var tslintRules = ([ "preferConstRule", "booleanTriviaRule", "typeOperatorSpacingRule", - "noInOperatorRule" + "noInOperatorRule", + "noIncrementDecrementRule" ]); var tslintRulesFiles = tslintRules.map(function(p) { return path.join(tslintRuleDir, p + ".ts"); @@ -921,11 +911,19 @@ function lintFileAsync(options, path, cb) { }); } +var servicesLintTargets = [ + "services.ts", + "outliningElementsCollector.ts", + "navigateTo.ts", + "patternMatcher.ts", +].map(function (s) { + return path.join(servicesDirectory, s); +}); var lintTargets = compilerSources .concat(harnessCoreSources) .concat(serverCoreSources) - .concat(scriptSources) - .concat([path.join(servicesDirectory, "services.ts")]); + .concat(tslintRulesFiles) + .concat(servicesLintTargets); desc("Runs tslint on the compiler sources"); task("lint", ["build-rules"], function() { diff --git a/doc/TypeScript Language Specification.docx b/doc/TypeScript Language Specification.docx index 4eb94908b57..370e5e25d89 100644 Binary files a/doc/TypeScript Language Specification.docx and b/doc/TypeScript Language Specification.docx differ diff --git a/doc/images/image1.png b/doc/images/image1.png new file mode 100644 index 00000000000..e1db88fa4f8 Binary files /dev/null and b/doc/images/image1.png differ diff --git a/doc/images/image2.png b/doc/images/image2.png new file mode 100644 index 00000000000..c0321038057 Binary files /dev/null and b/doc/images/image2.png differ diff --git a/doc/images/image3.png b/doc/images/image3.png new file mode 100644 index 00000000000..5fe2ecb8f3e Binary files /dev/null and b/doc/images/image3.png differ diff --git a/doc/images/image4.png b/doc/images/image4.png new file mode 100644 index 00000000000..13a6d8fcfb6 Binary files /dev/null and b/doc/images/image4.png differ diff --git a/doc/spec.md b/doc/spec.md index a7947b19926..df3f4d90b0a 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -262,7 +262,7 @@ function f() { To benefit from this inference, a programmer can use the TypeScript language service. For example, a code editor can incorporate the TypeScript language service and use the service to find the members of a string object as in the following screen shot. -/ +  ![](images/image1.png) In this example, the programmer benefits from type inference without providing type annotations. Some beneficial tools, however, do require the programmer to provide type annotations. In TypeScript, we can express a parameter requirement as in the following code fragment. @@ -410,7 +410,7 @@ This signature denotes that a function may be passed as the parameter of the '$' A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screen shot. -/ +  ![](images/image2.png) Section [3.3](#3.3) provides additional information about object types. @@ -627,7 +627,7 @@ An important goal of TypeScript is to provide accurate and straightforward types JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method. -/ +  ![](images/image3.png) The following code fragment uses this feature. Because the 'span' variable is inferred to have the type 'HTMLSpanElement', the code can reference without static error the 'isMultiline' property of 'span'. @@ -638,7 +638,7 @@ span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property. -/ +  ![](images/image4.png) Section [3.9.2.4](#3.9.2.4) provides details on how to use string literals in function signatures. diff --git a/scripts/tslint/booleanTriviaRule.ts b/scripts/tslint/booleanTriviaRule.ts index 93c312ab870..756728a1a11 100644 --- a/scripts/tslint/booleanTriviaRule.ts +++ b/scripts/tslint/booleanTriviaRule.ts @@ -26,7 +26,9 @@ class BooleanTriviaWalker extends Lint.RuleWalker { for (let index = 0; index < targetParameters.length; index++) { const param = targetParameters[index]; const arg = node.arguments[index]; - if (!(arg && param)) continue; + if (!(arg && param)) { + continue; + } const argType = this.checker.getContextualType(arg); if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) { @@ -38,7 +40,9 @@ class BooleanTriviaWalker extends Lint.RuleWalker { if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) { triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/ } - if (triviaContent !== param.getName()) { + + const paramName = param.getName(); + if (triviaContent !== paramName && triviaContent !== paramName + ":") { this.addFailure(this.createFailure(arg.getStart(source), arg.getWidth(source), Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent))); } } diff --git a/scripts/tslint/noIncrementDecrementRule.ts b/scripts/tslint/noIncrementDecrementRule.ts new file mode 100644 index 00000000000..75f4d2f5c08 --- /dev/null +++ b/scripts/tslint/noIncrementDecrementRule.ts @@ -0,0 +1,37 @@ +import * as Lint from "tslint/lib/lint"; +import * as ts from "typescript"; + + +export class Rule extends Lint.Rules.AbstractRule { + public static POSTFIX_FAILURE_STRING = "Don't use '++' or '--' postfix operators outside statements or for loops."; + public static PREFIX_FAILURE_STRING = "Don't use '++' or '--' prefix operators."; + + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithWalker(new IncrementDecrementWalker(sourceFile, this.getOptions())); + } +} + +class IncrementDecrementWalker extends Lint.RuleWalker { + + visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression) { + super.visitPostfixUnaryExpression(node); + if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) { + this.visitIncrementDecrement(node); + } + } + + visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression) { + super.visitPrefixUnaryExpression(node); + if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) { + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.PREFIX_FAILURE_STRING)); + } + } + + visitIncrementDecrement(node: ts.UnaryExpression) { + if (node.parent && (node.parent.kind === ts.SyntaxKind.ExpressionStatement || + node.parent.kind === ts.SyntaxKind.ForStatement)) { + return; + } + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.POSTFIX_FAILURE_STRING)); + } +} diff --git a/scripts/word2md.js b/scripts/word2md.js deleted file mode 100644 index e80275d5b2d..00000000000 --- a/scripts/word2md.js +++ /dev/null @@ -1,235 +0,0 @@ -// word2md - Word to Markdown conversion tool -// -// word2md converts a Microsoft Word document to Markdown formatted text. The tool uses the -// Word Automation APIs to start an instance of Word and access the contents of the document -// being converted. The tool must be run using the cscript.exe script host and requires Word -// to be installed on the target machine. The name of the document to convert must be specified -// as a command line argument and the resulting Markdown is written to standard output. The -// tool recognizes the specific Word styles used in the TypeScript Language Specification. -var sys = (function () { - var fileStream = new ActiveXObject("ADODB.Stream"); - fileStream.Type = 2 /*text*/; - var binaryStream = new ActiveXObject("ADODB.Stream"); - binaryStream.Type = 1 /*binary*/; - var args = []; - for (var i = 0; i < WScript.Arguments.length; i++) { - args[i] = WScript.Arguments.Item(i); - } - return { - args: args, - createObject: function (typeName) { return new ActiveXObject(typeName); }, - write: function (s) { - WScript.StdOut.Write(s); - }, - writeFile: function (fileName, data) { - fileStream.Open(); - binaryStream.Open(); - try { - // Write characters in UTF-8 encoding - fileStream.Charset = "utf-8"; - fileStream.WriteText(data); - // We don't want the BOM, skip it by setting the starting location to 3 (size of BOM). - fileStream.Position = 3; - fileStream.CopyTo(binaryStream); - binaryStream.SaveToFile(fileName, 2 /*overwrite*/); - } - finally { - binaryStream.Close(); - fileStream.Close(); - } - } - }; -})(); -function convertDocumentToMarkdown(doc) { - var result = ""; - var lastStyle; - var lastInTable; - var tableColumnCount; - var tableCellIndex; - var columnAlignment = []; - function setProperties(target, properties) { - for (var name in properties) { - if (properties.hasOwnProperty(name)) { - var value = properties[name]; - if (typeof value === "object") { - setProperties(target[name], value); - } - else { - target[name] = value; - } - } - } - } - function findReplace(findText, findOptions, replaceText, replaceOptions) { - var find = doc.range().find; - find.clearFormatting(); - setProperties(find, findOptions); - var replace = find.replacement; - replace.clearFormatting(); - setProperties(replace, replaceOptions); - find.execute(findText, false, false, false, false, false, true, 0, true, replaceText, 2); - } - function fixHyperlinks() { - var count = doc.hyperlinks.count; - for (var i = 0; i < count; i++) { - var hyperlink = doc.hyperlinks.item(i + 1); - var address = hyperlink.address; - if (address && address.length > 0) { - var textToDisplay = hyperlink.textToDisplay; - hyperlink.textToDisplay = "[" + textToDisplay + "](" + address + ")"; - } - } - } - function write(s) { - result += s; - } - function writeTableHeader() { - for (var i = 0; i < tableColumnCount - 1; i++) { - switch (columnAlignment[i]) { - case 1: - write("|:---:"); - break; - case 2: - write("|---:"); - break; - default: - write("|---"); - } - } - write("|\n"); - } - function trimEndFormattingMarks(text) { - var i = text.length; - while (i > 0 && text.charCodeAt(i - 1) < 0x20) - i--; - return text.substr(0, i); - } - function writeBlockEnd() { - switch (lastStyle) { - case "Code": - write("```\n\n"); - break; - case "List Paragraph": - case "Table": - case "TOC": - write("\n"); - break; - } - } - function writeParagraph(p) { - var text = p.range.text; - var style = p.style.nameLocal; - var inTable = p.range.tables.count > 0; - var level = 1; - var sectionBreak = text.indexOf("\x0C") >= 0; - text = trimEndFormattingMarks(text); - if (inTable) { - style = "Table"; - } - else if (style.match(/\s\d$/)) { - level = +style.substr(style.length - 1); - style = style.substr(0, style.length - 2); - } - if (lastStyle && style !== lastStyle) { - writeBlockEnd(); - } - switch (style) { - case "Heading": - case "Appendix": - var section = p.range.listFormat.listString; - write("####".substr(0, level) + ' ' + section + " " + text + "\n\n"); - break; - case "Normal": - if (text.length) { - write(text + "\n\n"); - } - break; - case "List Paragraph": - write(" ".substr(0, p.range.listFormat.listLevelNumber * 2 - 2) + "* " + text + "\n"); - break; - case "Grammar": - write("  " + text.replace(/\s\s\s/g, " ").replace(/\x0B/g, " \n   ") + "\n\n"); - break; - case "Code": - if (lastStyle !== "Code") { - write("```TypeScript\n"); - } - else { - write("\n"); - } - write(text.replace(/\x0B/g, " \n") + "\n"); - break; - case "Table": - if (!lastInTable) { - tableColumnCount = p.range.tables.item(1).columns.count + 1; - tableCellIndex = 0; - } - if (tableCellIndex < tableColumnCount) { - columnAlignment[tableCellIndex] = p.alignment; - } - write("|" + text); - tableCellIndex++; - if (tableCellIndex % tableColumnCount === 0) { - write("\n"); - if (tableCellIndex === tableColumnCount) { - writeTableHeader(); - } - } - break; - case "TOC Heading": - write("## " + text + "\n\n"); - break; - case "TOC": - var strings = text.split("\t"); - write(" ".substr(0, level * 2 - 2) + "* [" + strings[0] + " " + strings[1] + "](#" + strings[0] + ")\n"); - break; - } - if (sectionBreak) { - write("
\n\n"); - } - lastStyle = style; - lastInTable = inTable; - } - function writeDocument() { - var title = doc.builtInDocumentProperties.item(1) + ""; - if (title.length) { - write("# " + title + "\n\n"); - } - for (var p = doc.paragraphs.first; p; p = p.next()) { - writeParagraph(p); - } - writeBlockEnd(); - } - findReplace("<", {}, "<", {}); - findReplace("<", { style: "Code" }, "<", {}); - findReplace("<", { style: "Code Fragment" }, "<", {}); - findReplace("<", { style: "Terminal" }, "<", {}); - findReplace("", { font: { subscript: true } }, "^&", { font: { subscript: false } }); - findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 /* default font */ }); - findReplace("", { style: "Production" }, "*^&*", { style: -66 /* default font */ }); - findReplace("", { style: "Terminal" }, "`^&`", { style: -66 /* default font */ }); - findReplace("", { font: { bold: true, italic: true } }, "***^&***", { font: { bold: false, italic: false } }); - findReplace("", { font: { italic: true } }, "*^&*", { font: { italic: false } }); - doc.fields.toggleShowCodes(); - findReplace("^19 REF", {}, "[^&](#^&)", {}); - doc.fields.toggleShowCodes(); - fixHyperlinks(); - writeDocument(); - result = result.replace(/\x85/g, "\u2026"); - result = result.replace(/\x96/g, "\u2013"); - result = result.replace(/\x97/g, "\u2014"); - return result; -} -function main(args) { - if (args.length !== 2) { - sys.write("Syntax: word2md \n"); - return; - } - var app = sys.createObject("Word.Application"); - var doc = app.documents.open(args[0]); - sys.writeFile(args[1], convertDocumentToMarkdown(doc)); - doc.close(false); - app.quit(); -} -main(sys.args); -//# sourceMappingURL=file:///c:/ts/scripts/word2md.js.map \ No newline at end of file diff --git a/scripts/word2md.ts b/scripts/word2md.ts index ec9ed634b3c..f602c700ff9 100644 --- a/scripts/word2md.ts +++ b/scripts/word2md.ts @@ -72,6 +72,9 @@ module Word { listFormat: ListFormat; tables: Tables; text: string; + textRetrievalMode: { + includeHiddenText: boolean; + } words: Ranges; } @@ -258,13 +261,27 @@ function convertDocumentToMarkdown(doc: Word.Document): string { function writeParagraph(p: Word.Paragraph) { - var text = p.range.text; + var range = p.range; + var text = range.text; var style = p.style.nameLocal; - var inTable = p.range.tables.count > 0; + var inTable = range.tables.count > 0; var level = 1; var sectionBreak = text.indexOf("\x0C") >= 0; text = trimEndFormattingMarks(text); + if (text === "/") { + // An inline image shows up in the text as a "/". When we see a paragraph + // consisting of nothing but "/", we check to see if the paragraph contains + // hidden text and, if so, emit that instead. The hidden text is assumed to + // contain an appropriate markdown image link. + range.textRetrievalMode.includeHiddenText = true; + var fullText = range.text; + range.textRetrievalMode.includeHiddenText = false; + if (text !== fullText) { + text = "  " + fullText.substr(1); + } + } + if (inTable) { style = "Table"; } @@ -280,7 +297,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { case "Heading": case "Appendix": - var section = p.range.listFormat.listString; + var section = range.listFormat.listString; write("####".substr(0, level) + '
' + section + " " + text + "\n\n"); break; @@ -291,7 +308,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { break; case "List Paragraph": - write(" ".substr(0, p.range.listFormat.listLevelNumber * 2 - 2) + "* " + text + "\n"); + write(" ".substr(0, range.listFormat.listLevelNumber * 2 - 2) + "* " + text + "\n"); break; case "Grammar": @@ -310,7 +327,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { case "Table": if (!lastInTable) { - tableColumnCount = p.range.tables.item(1).columns.count + 1; + tableColumnCount = range.tables.item(1).columns.count + 1; tableCellIndex = 0; } if (tableCellIndex < tableColumnCount) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d57e9d2028..eb0338c9f57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7,7 +7,10 @@ namespace ts { let nextMergeId = 1; export function getNodeId(node: Node): number { - if (!node.id) node.id = nextNodeId++; + if (!node.id) { + node.id = nextNodeId; + nextNodeId++; + } return node.id; } @@ -15,7 +18,8 @@ namespace ts { export function getSymbolId(symbol: Symbol): number { if (!symbol.id) { - symbol.id = nextSymbolId++; + symbol.id = nextSymbolId; + nextSymbolId++; } return symbol.id; @@ -287,7 +291,10 @@ namespace ts { } function recordMergedSymbol(target: Symbol, source: Symbol) { - if (!source.mergeId) source.mergeId = nextMergeId++; + if (!source.mergeId) { + source.mergeId = nextMergeId; + nextMergeId++; + } mergedSymbols[source.mergeId] = target; } @@ -1267,7 +1274,8 @@ namespace ts { function createType(flags: TypeFlags): Type { const result = new Type(checker, flags); - result.id = typeCount++; + result.id = typeCount; + typeCount++; return result; } @@ -1823,11 +1831,13 @@ namespace ts { } if (pos < end) { writePunctuation(writer, SyntaxKind.LessThanToken); - writeType(typeArguments[pos++], TypeFormatFlags.None); + writeType(typeArguments[pos], TypeFormatFlags.None); + pos++; while (pos < end) { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); - writeType(typeArguments[pos++], TypeFormatFlags.None); + writeType(typeArguments[pos], TypeFormatFlags.None); + pos++; } writePunctuation(writer, SyntaxKind.GreaterThanToken); } @@ -5676,7 +5686,7 @@ namespace ts { return Ternary.False; } let result = Ternary.True; - for (let i = 0, len = sourceSignatures.length; i < len; ++i) { + for (let i = 0, len = sourceSignatures.length; i < len; i++) { const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return Ternary.False; @@ -8363,14 +8373,12 @@ namespace ts { checkGrammarJsxElement(node); checkJsxPreconditions(node); - // If we're compiling under --jsx react, the symbol 'React' should - // be marked as 'used' so we don't incorrectly elide its import. And if there - // is no 'React' symbol in scope, we should issue an error. - if (compilerOptions.jsx === JsxEmit.React) { - const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, Diagnostics.Cannot_find_name_0, "React"); - if (reactSym) { - getSymbolLinks(reactSym).referenced = true; - } + // The symbol 'React' should be marked as 'used' so we don't incorrectly elide its import. And if there + // is no 'React' symbol in scope when targeting React emit, we should issue an error. + const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; + const reactSym = resolveName(node.tagName, "React", SymbolFlags.Value, reactRefErr, "React"); + if (reactSym) { + getSymbolLinks(reactSym).referenced = true; } const targetAttributesType = getJsxElementAttributesType(node); @@ -13841,7 +13849,8 @@ namespace ts { } if (autoValue !== undefined) { - getNodeLinks(member).enumMemberValue = autoValue++; + getNodeLinks(member).enumMemberValue = autoValue; + autoValue++; } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8066aff32d3..ae87f2e58c3 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -362,7 +362,8 @@ namespace ts { function parseStrings(args: string[]) { let i = 0; while (i < args.length) { - let s = args[i++]; + let s = args[i]; + i++; if (s.charCodeAt(0) === CharacterCodes.at) { parseResponseFile(s.slice(1)); } @@ -388,18 +389,21 @@ namespace ts { switch (opt.type) { case "number": - options[opt.name] = parseInt(args[i++]); + options[opt.name] = parseInt(args[i]); + i++; break; case "boolean": options[opt.name] = true; break; case "string": - options[opt.name] = args[i++] || ""; + options[opt.name] = args[i] || ""; + i++; break; // If not a primitive, the possible types are specified in what is effectively a map of options. default: let map = >opt.type; - let key = (args[i++] || "").toLowerCase(); + let key = (args[i] || "").toLowerCase(); + i++; if (hasProperty(map, key)) { options[opt.name] = map[key]; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 8b48d9fa9cb..0acd720ad8f 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -242,9 +242,11 @@ namespace ts { const count = array.length; if (count > 0) { let pos = 0; - let result = arguments.length <= 2 ? array[pos++] : initial; + let result = arguments.length <= 2 ? array[pos] : initial; + pos++; while (pos < count) { - result = f(result, array[pos++]); + result = f(result, array[pos]); + pos++; } return result; } @@ -258,9 +260,11 @@ namespace ts { if (array) { let pos = array.length - 1; if (pos >= 0) { - let result = arguments.length <= 2 ? array[pos--] : initial; + let result = arguments.length <= 2 ? array[pos] : initial; + pos--; while (pos >= 0) { - result = f(result, array[pos--]); + result = f(result, array[pos]); + pos--; } return result; } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index d0c5cbff48b..75319d0ab51 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -501,7 +501,8 @@ namespace ts { } let count = 0; while (true) { - const name = baseName + "_" + (++count); + count++; + const name = baseName + "_" + count; if (!hasProperty(currentIdentifiers, name)) { return name; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 996dac118ef..d412225cdf0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5464,7 +5464,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi }); leadingComma = true; } - ++parameterIndex; + parameterIndex++; } } return argumentsWritten; @@ -6488,7 +6488,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let started = false; if (exportedDeclarations) { - for (let i = 0; i < exportedDeclarations.length; ++i) { + for (let i = 0; i < exportedDeclarations.length; i++) { // write name of exported declaration, i.e 'export var x...' writeExportedName(exportedDeclarations[i]); } @@ -6604,7 +6604,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi writeLine(); write("var "); const seen: Map = {}; - for (let i = 0; i < hoistedVars.length; ++i) { + for (let i = 0; i < hoistedVars.length; i++) { const local = hoistedVars[i]; const name = local.kind === SyntaxKind.Identifier ? local @@ -6816,7 +6816,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitSetters(exportStarFunction: string, dependencyGroups: DependencyGroup[]) { write("setters:["); - for (let i = 0; i < dependencyGroups.length; ++i) { + for (let i = 0; i < dependencyGroups.length; i++) { if (i !== 0) { write(","); } @@ -6864,7 +6864,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(`${exportFunctionForFile}({`); writeLine(); increaseIndent(); - for (let i = 0, len = (entry).exportClause.elements.length; i < len; ++i) { + for (let i = 0, len = (entry).exportClause.elements.length; i < len; i++) { if (i !== 0) { write(","); writeLine(); @@ -6909,7 +6909,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("execute: function() {"); increaseIndent(); writeLine(); - for (let i = startIndex; i < node.statements.length; ++i) { + for (let i = startIndex; i < node.statements.length; i++) { const statement = node.statements[i]; switch (statement.kind) { // - function declarations are not emitted because they were already hoisted @@ -6971,7 +6971,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi const groupIndices: Map = {}; const dependencyGroups: DependencyGroup[] = []; - for (let i = 0; i < externalImports.length; ++i) { + for (let i = 0; i < externalImports.length; i++) { const text = getExternalModuleNameText(externalImports[i], emitRelativePathAsModuleName); if (hasProperty(groupIndices, text)) { // deduplicate/group entries in dependency list by the dependency name @@ -6990,7 +6990,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write(text); } - write(`], function(${exportFunctionForFile}) {`); + write(`], function(${exportFunctionForFile}, __moduleName) {`); writeLine(); increaseIndent(); const startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ true, /*ensureUseStrict*/ true); @@ -7221,7 +7221,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // Replace entities like   result = result.replace(/&(\w+);/g, function(s: any, m: string) { if (entities[m] !== undefined) { - return String.fromCharCode(entities[m]); + const ch = String.fromCharCode(entities[m]); + // " needs to be escaped + return ch === "\"" ? "\\\"" : ch; } else { return s; @@ -7294,7 +7296,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean, ensureUseStrict?: boolean): number { let foundUseStrict = false; - for (let i = 0; i < statements.length; ++i) { + for (let i = 0; i < statements.length; i++) { if (isPrologueDirective(statements[i])) { if (isUseStrictPrologue(statements[i] as ExpressionStatement)) { foundUseStrict = true; @@ -7316,7 +7318,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function writeLines(text: string): void { const lines = text.split(/\r\n|\r|\n/g); - for (let i = 0; i < lines.length; ++i) { + for (let i = 0; i < lines.length; i++) { const line = lines[i]; if (line.length) { writeLine(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 952208df967..9c82b670fbb 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -498,7 +498,7 @@ namespace ts { function hasZeroOrOneAsteriskCharacter(str: string): boolean { let seenAsterisk = false; - for (let i = 0; i < str.length; ++i) { + for (let i = 0; i < str.length; i++) { if (str.charCodeAt(i) === CharacterCodes.asterisk) { if (!seenAsterisk) { seenAsterisk = true; @@ -869,7 +869,7 @@ namespace ts { const moduleNames = map(newSourceFile.imports, name => name.text); const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory)); // ensure that module resolution results are still correct - for (let i = 0; i < moduleNames.length; ++i) { + for (let i = 0; i < moduleNames.length; i++) { const newResolution = resolutions[i]; const oldResolution = getResolvedModule(oldSourceFile, moduleNames[i]); const resolutionChanged = oldResolution @@ -897,7 +897,7 @@ namespace ts { } // update fileName -> file mapping - for (let i = 0, len = newSourceFiles.length; i < len; ++i) { + for (let i = 0, len = newSourceFiles.length; i < len; i++) { filesByName.set(filePaths[i], newSourceFiles[i]); } @@ -1447,7 +1447,7 @@ namespace ts { file.resolvedModules = {}; const moduleNames = map(file.imports, name => name.text); const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory)); - for (let i = 0; i < file.imports.length; ++i) { + for (let i = 0; i < file.imports.length; i++) { const resolution = resolutions[i]; setResolvedModule(file, moduleNames[i], resolution); if (resolution && !options.noResolve) { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 022d63fbe9d..6c0489ff1dc 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -288,7 +288,8 @@ namespace ts { let pos = 0; let lineStart = 0; while (pos < text.length) { - const ch = text.charCodeAt(pos++); + const ch = text.charCodeAt(pos); + pos++; switch (ch) { case CharacterCodes.carriageReturn: if (text.charCodeAt(pos) === CharacterCodes.lineFeed) { @@ -823,7 +824,8 @@ namespace ts { } function scanString(): string { - const quote = text.charCodeAt(pos++); + const quote = text.charCodeAt(pos); + pos++; let result = ""; let start = pos; while (true) { @@ -933,7 +935,8 @@ namespace ts { error(Diagnostics.Unexpected_end_of_text); return ""; } - const ch = text.charCodeAt(pos++); + const ch = text.charCodeAt(pos); + pos++; switch (ch) { case CharacterCodes._0: return "\0"; @@ -1182,7 +1185,8 @@ namespace ts { } return pos += 2, token = SyntaxKind.ExclamationEqualsToken; } - return pos++, token = SyntaxKind.ExclamationToken; + pos++; + return token = SyntaxKind.ExclamationToken; case CharacterCodes.doubleQuote: case CharacterCodes.singleQuote: tokenValue = scanString(); @@ -1193,7 +1197,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.PercentEqualsToken; } - return pos++, token = SyntaxKind.PercentToken; + pos++; + return token = SyntaxKind.PercentToken; case CharacterCodes.ampersand: if (text.charCodeAt(pos + 1) === CharacterCodes.ampersand) { return pos += 2, token = SyntaxKind.AmpersandAmpersandToken; @@ -1201,11 +1206,14 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.AmpersandEqualsToken; } - return pos++, token = SyntaxKind.AmpersandToken; + pos++; + return token = SyntaxKind.AmpersandToken; case CharacterCodes.openParen: - return pos++, token = SyntaxKind.OpenParenToken; + pos++; + return token = SyntaxKind.OpenParenToken; case CharacterCodes.closeParen: - return pos++, token = SyntaxKind.CloseParenToken; + pos++; + return token = SyntaxKind.CloseParenToken; case CharacterCodes.asterisk: if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.AsteriskEqualsToken; @@ -1216,7 +1224,8 @@ namespace ts { } return pos += 2, token = SyntaxKind.AsteriskAsteriskToken; } - return pos++, token = SyntaxKind.AsteriskToken; + pos++; + return token = SyntaxKind.AsteriskToken; case CharacterCodes.plus: if (text.charCodeAt(pos + 1) === CharacterCodes.plus) { return pos += 2, token = SyntaxKind.PlusPlusToken; @@ -1224,9 +1233,11 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.PlusEqualsToken; } - return pos++, token = SyntaxKind.PlusToken; + pos++; + return token = SyntaxKind.PlusToken; case CharacterCodes.comma: - return pos++, token = SyntaxKind.CommaToken; + pos++; + return token = SyntaxKind.CommaToken; case CharacterCodes.minus: if (text.charCodeAt(pos + 1) === CharacterCodes.minus) { return pos += 2, token = SyntaxKind.MinusMinusToken; @@ -1234,7 +1245,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.MinusEqualsToken; } - return pos++, token = SyntaxKind.MinusToken; + pos++; + return token = SyntaxKind.MinusToken; case CharacterCodes.dot: if (isDigit(text.charCodeAt(pos + 1))) { tokenValue = scanNumber(); @@ -1243,7 +1255,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.dot && text.charCodeAt(pos + 2) === CharacterCodes.dot) { return pos += 3, token = SyntaxKind.DotDotDotToken; } - return pos++, token = SyntaxKind.DotToken; + pos++; + return token = SyntaxKind.DotToken; case CharacterCodes.slash: // Single-line comment if (text.charCodeAt(pos + 1) === CharacterCodes.slash) { @@ -1301,7 +1314,8 @@ namespace ts { return pos += 2, token = SyntaxKind.SlashEqualsToken; } - return pos++, token = SyntaxKind.SlashToken; + pos++; + return token = SyntaxKind.SlashToken; case CharacterCodes._0: if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) { @@ -1354,9 +1368,11 @@ namespace ts { tokenValue = scanNumber(); return token = SyntaxKind.NumericLiteral; case CharacterCodes.colon: - return pos++, token = SyntaxKind.ColonToken; + pos++; + return token = SyntaxKind.ColonToken; case CharacterCodes.semicolon: - return pos++, token = SyntaxKind.SemicolonToken; + pos++; + return token = SyntaxKind.SemicolonToken; case CharacterCodes.lessThan: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -1382,7 +1398,8 @@ namespace ts { text.charCodeAt(pos + 2) !== CharacterCodes.asterisk) { return pos += 2, token = SyntaxKind.LessThanSlashToken; } - return pos++, token = SyntaxKind.LessThanToken; + pos++; + return token = SyntaxKind.LessThanToken; case CharacterCodes.equals: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -1403,7 +1420,8 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.greaterThan) { return pos += 2, token = SyntaxKind.EqualsGreaterThanToken; } - return pos++, token = SyntaxKind.EqualsToken; + pos++; + return token = SyntaxKind.EqualsToken; case CharacterCodes.greaterThan: if (isConflictMarkerTrivia(text, pos)) { pos = scanConflictMarkerTrivia(text, pos, error); @@ -1415,20 +1433,26 @@ namespace ts { } } - return pos++, token = SyntaxKind.GreaterThanToken; + pos++; + return token = SyntaxKind.GreaterThanToken; case CharacterCodes.question: - return pos++, token = SyntaxKind.QuestionToken; + pos++; + return token = SyntaxKind.QuestionToken; case CharacterCodes.openBracket: - return pos++, token = SyntaxKind.OpenBracketToken; + pos++; + return token = SyntaxKind.OpenBracketToken; case CharacterCodes.closeBracket: - return pos++, token = SyntaxKind.CloseBracketToken; + pos++; + return token = SyntaxKind.CloseBracketToken; case CharacterCodes.caret: if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.CaretEqualsToken; } - return pos++, token = SyntaxKind.CaretToken; + pos++; + return token = SyntaxKind.CaretToken; case CharacterCodes.openBrace: - return pos++, token = SyntaxKind.OpenBraceToken; + pos++; + return token = SyntaxKind.OpenBraceToken; case CharacterCodes.bar: if (text.charCodeAt(pos + 1) === CharacterCodes.bar) { return pos += 2, token = SyntaxKind.BarBarToken; @@ -1436,13 +1460,17 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.BarEqualsToken; } - return pos++, token = SyntaxKind.BarToken; + pos++; + return token = SyntaxKind.BarToken; case CharacterCodes.closeBrace: - return pos++, token = SyntaxKind.CloseBraceToken; + pos++; + return token = SyntaxKind.CloseBraceToken; case CharacterCodes.tilde: - return pos++, token = SyntaxKind.TildeToken; + pos++; + return token = SyntaxKind.TildeToken; case CharacterCodes.at: - return pos++, token = SyntaxKind.AtToken; + pos++; + return token = SyntaxKind.AtToken; case CharacterCodes.backslash: let cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) { @@ -1451,7 +1479,8 @@ namespace ts { return token = getIdentifierToken(); } error(Diagnostics.Invalid_character); - return pos++, token = SyntaxKind.Unknown; + pos++; + return token = SyntaxKind.Unknown; default: if (isIdentifierStart(ch, languageVersion)) { pos++; @@ -1472,7 +1501,8 @@ namespace ts { continue; } error(Diagnostics.Invalid_character); - return pos++, token = SyntaxKind.Unknown; + pos++; + return token = SyntaxKind.Unknown; } } } @@ -1489,10 +1519,12 @@ namespace ts { if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.GreaterThanGreaterThanEqualsToken; } - return pos++, token = SyntaxKind.GreaterThanGreaterThanToken; + pos++; + return token = SyntaxKind.GreaterThanGreaterThanToken; } if (text.charCodeAt(pos) === CharacterCodes.equals) { - return pos++, token = SyntaxKind.GreaterThanEqualsToken; + pos++; + return token = SyntaxKind.GreaterThanEqualsToken; } } return token; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c5a31992a80..7bc708c7178 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -92,7 +92,7 @@ namespace ts { return false; } - for (let i = 0; i < array1.length; ++i) { + for (let i = 0; i < array1.length; i++) { const equals = equaler ? equaler(array1[i], array2[i]) : array1[i] === array2[i]; if (!equals) { return false; @@ -1884,8 +1884,8 @@ namespace ts { writeTextOfNode, writeLiteral, writeLine, - increaseIndent: () => indent++, - decreaseIndent: () => indent--, + increaseIndent: () => { indent++; }, + decreaseIndent: () => { indent--; }, getIndent: () => indent, getTextPos: () => output.length, getLine: () => lineCount + 1, diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a078b64543b..8cd1bca876e 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -727,7 +727,7 @@ namespace FourSlash { // Count only the references in local files. Filter the ones in lib and other files. ts.forEach(references, entry => { if (localFiles.some((fileName) => fileName === entry.fileName)) { - ++referencesCount; + referencesCount++; } }); } @@ -1093,7 +1093,7 @@ namespace FourSlash { const emitFiles: FourSlashFile[] = []; // List of FourSlashFile that has emitThisFile flag on const allFourSlashFiles = this.testData.files; - for (let idx = 0; idx < allFourSlashFiles.length; ++idx) { + for (let idx = 0; idx < allFourSlashFiles.length; idx++) { const file = allFourSlashFiles[idx]; if (file.fileOptions[metadataOptionNames.emitThisFile] === "true") { // Find a file with the flag emitThisFile turned on @@ -1853,7 +1853,7 @@ namespace FourSlash { let item: ts.NavigateToItem = null; // Count only the match that match the same MatchKind - for (let i = 0; i < items.length; ++i) { + for (let i = 0; i < items.length; i++) { item = items[i]; if (!matchKind || item.matchKind === matchKind) { actual++; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 263f7cb72c5..31987030c2e 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1457,7 +1457,7 @@ namespace Harness { // check if project has tsconfig.json in the list of files let tsConfig: ts.ParsedCommandLine; - for (let i = 0; i < testUnitData.length; ++i) { + for (let i = 0; i < testUnitData.length; i++) { const data = testUnitData[i]; if (ts.getBaseFileName(data.name).toLowerCase() === "tsconfig.json") { const configJson = ts.parseConfigFileTextToJson(data.name, data.content); diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 52102663457..96fcfedc6b4 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -307,9 +307,10 @@ class ProjectRunner extends RunnerBase { // If the generated output file resides in the parent folder or is rooted path, // we need to instead create files that can live in the project reference folder // but make sure extension of these files matches with the fileName the compiler asked to write - diskRelativeName = "diskFile" + nonSubfolderDiskFiles++ + + diskRelativeName = "diskFile" + nonSubfolderDiskFiles + (Harness.Compiler.isDTS(fileName) ? ".d.ts" : Harness.Compiler.isJS(fileName) ? ".js" : ".js.map"); + nonSubfolderDiskFiles++; } if (Harness.Compiler.isJS(fileName)) { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 5a1c85fc13c..d78f7d40ef6 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -718,7 +718,8 @@ namespace ts.server { else { for (const directory of project.directoriesWatchedForTsconfig) { // if the ref count for this directory watcher drops to 0, it's time to close it - if (!(--project.projectService.directoryWatchersRefCount[directory])) { + project.projectService.directoryWatchersRefCount[directory]--; + if (!project.projectService.directoryWatchersRefCount[directory]) { this.log("Close directory watcher for: " + directory); project.projectService.directoryWatchersForTsconfig[directory].close(); delete project.projectService.directoryWatchersForTsconfig[directory]; @@ -1730,7 +1731,8 @@ namespace ts.server { let count = 1; let pos = 0; this.index.every((ll, s, len) => { - starts[count++] = pos; + starts[count] = pos; + count++; pos += ll.text.length; return true; }, 0); @@ -1996,7 +1998,8 @@ namespace ts.server { while (adjustedStart >= childCharCount) { this.skipChild(adjustedStart, rangeLength, childIndex, walkFns, CharRangeSection.PreStart); adjustedStart -= childCharCount; - child = this.children[++childIndex]; + childIndex++; + child = this.children[childIndex]; childCharCount = child.charCount(); } // Case I: both start and end of range in same subtree @@ -2011,14 +2014,16 @@ namespace ts.server { return; } let adjustedLength = rangeLength - (childCharCount - adjustedStart); - child = this.children[++childIndex]; + childIndex++; + child = this.children[childIndex]; childCharCount = child.charCount(); while (adjustedLength > childCharCount) { if (this.execWalk(0, childCharCount, walkFns, childIndex, CharRangeSection.Mid)) { return; } adjustedLength -= childCharCount; - child = this.children[++childIndex]; + childIndex++; + child = this.children[childIndex]; childCharCount = child.charCount(); } if (adjustedLength > 0) { @@ -2142,7 +2147,8 @@ namespace ts.server { if (childIndex < clen) { splitNode = new LineNode(); while (childIndex < clen) { - splitNode.add(this.children[childIndex++]); + splitNode.add(this.children[childIndex]); + childIndex++; } splitNode.updateCounts(); } @@ -2183,7 +2189,9 @@ namespace ts.server { let nodeIndex = 0; childIndex++; while ((childIndex < lineCollectionCapacity) && (nodeIndex < nodeCount)) { - this.children[childIndex++] = nodes[nodeIndex++]; + this.children[childIndex] = nodes[nodeIndex]; + childIndex++; + nodeIndex++; } let splitNodes: LineNode[] = []; let splitNodeCount = 0; @@ -2196,7 +2204,8 @@ namespace ts.server { } let splitNode = splitNodes[0]; while (nodeIndex < nodeCount) { - splitNode.add(nodes[nodeIndex++]); + splitNode.add(nodes[nodeIndex]); + nodeIndex++; if (splitNode.children.length === lineCollectionCapacity) { splitNodeIndex++; splitNode = splitNodes[splitNodeIndex]; diff --git a/src/server/session.ts b/src/server/session.ts index 78686b79118..9b9bf35a4a5 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -263,7 +263,8 @@ namespace ts.server { let index = 0; const checkOne = () => { if (matchSeq(seq)) { - const checkSpec = checkList[index++]; + const checkSpec = checkList[index]; + index++; if (checkSpec.project.getSourceFileFromName(checkSpec.fileName, requireOpen)) { this.syntacticCheck(checkSpec.fileName, checkSpec.project); this.immediateId = setImmediate(() => { diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 55adb7b7233..4e48a4bf4f2 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -360,7 +360,9 @@ namespace ts.formatting { range: TextRange, inheritedIndentation: number): number { - if (rangeOverlapsWithStartEnd(range, startPos, endPos)) { + if (rangeOverlapsWithStartEnd(range, startPos, endPos) || + rangeContainsStartEnd(range, startPos, endPos) /* Not to miss zero-range nodes e.g. JsxText */) { + if (inheritedIndentation !== Constants.Unknown) { return inheritedIndentation; } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 067118fd7a8..8e0fef884e7 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -450,8 +450,9 @@ namespace ts.formatting { case SyntaxKind.ConditionalExpression: case SyntaxKind.ArrayBindingPattern: case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.JsxElement: + case SyntaxKind.JsxOpeningElement: case SyntaxKind.JsxSelfClosingElement: + case SyntaxKind.JsxExpression: case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: @@ -467,6 +468,7 @@ namespace ts.formatting { return false; } + /* @internal */ export function nodeWillIndentChild(parent: TextRangeWithKind, child: TextRangeWithKind, indentByDefault: boolean) { let childKind = child ? child.kind : SyntaxKind.Unknown; switch (parent.kind) { @@ -484,6 +486,8 @@ namespace ts.formatting { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return childKind !== SyntaxKind.Block; + case SyntaxKind.JsxElement: + return childKind !== SyntaxKind.JsxClosingElement; } // No explicit rule for given nodes so the result will follow the default value argument return indentByDefault; diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index 2a0abba8695..8022e2fad7a 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -3,19 +3,19 @@ namespace ts.NavigateTo { type RawNavigateToItem = { name: string; fileName: string; matchKind: PatternMatchKind; isCaseSensitive: boolean; declaration: Declaration }; export function getNavigateToItems(program: Program, cancellationToken: CancellationToken, searchValue: string, maxResultCount: number): NavigateToItem[] { - let patternMatcher = createPatternMatcher(searchValue); + const patternMatcher = createPatternMatcher(searchValue); let rawItems: RawNavigateToItem[] = []; // This means "compare in a case insensitive manner." - let baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" }; + const baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" }; // Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[] forEach(program.getSourceFiles(), sourceFile => { cancellationToken.throwIfCancellationRequested(); - let nameToDeclarations = sourceFile.getNamedDeclarations(); - for (let name in nameToDeclarations) { - let declarations = getProperty(nameToDeclarations, name); + const nameToDeclarations = sourceFile.getNamedDeclarations(); + for (const name in nameToDeclarations) { + const declarations = getProperty(nameToDeclarations, name); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. @@ -25,11 +25,11 @@ namespace ts.NavigateTo { continue; } - for (let declaration of declarations) { + for (const declaration of declarations) { // It was a match! If the pattern has dots in it, then also see if the // declaration container matches as well. if (patternMatcher.patternContainsDots) { - let containers = getContainers(declaration); + const containers = getContainers(declaration); if (!containers) { return undefined; } @@ -41,8 +41,8 @@ namespace ts.NavigateTo { } } - let fileName = sourceFile.fileName; - let matchKind = bestMatchKind(matches); + const fileName = sourceFile.fileName; + const matchKind = bestMatchKind(matches); rawItems.push({ name, fileName, matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration }); } } @@ -54,7 +54,7 @@ namespace ts.NavigateTo { rawItems = rawItems.slice(0, maxResultCount); } - let items = map(rawItems, createNavigateToItem); + const items = map(rawItems, createNavigateToItem); return items; @@ -62,7 +62,7 @@ namespace ts.NavigateTo { Debug.assert(matches.length > 0); // This is a case sensitive match, only if all the submatches were case sensitive. - for (let match of matches) { + for (const match of matches) { if (!match.isCaseSensitive) { return false; } @@ -86,16 +86,16 @@ namespace ts.NavigateTo { function tryAddSingleDeclarationName(declaration: Declaration, containers: string[]) { if (declaration && declaration.name) { - let text = getTextOfIdentifierOrLiteral(declaration.name); + const text = getTextOfIdentifierOrLiteral(declaration.name); if (text !== undefined) { containers.unshift(text); } else if (declaration.name.kind === SyntaxKind.ComputedPropertyName) { - return tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion:*/ true); + return tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion*/ true); } else { // Don't know how to add this. - return false + return false; } } @@ -106,7 +106,7 @@ namespace ts.NavigateTo { // // [X.Y.Z]() { } function tryAddComputedPropertyName(expression: Expression, containers: string[], includeLastPortion: boolean): boolean { - let text = getTextOfIdentifierOrLiteral(expression); + const text = getTextOfIdentifierOrLiteral(expression); if (text !== undefined) { if (includeLastPortion) { containers.unshift(text); @@ -115,24 +115,24 @@ namespace ts.NavigateTo { } if (expression.kind === SyntaxKind.PropertyAccessExpression) { - let propertyAccess = expression; + const propertyAccess = expression; if (includeLastPortion) { containers.unshift(propertyAccess.name.text); } - return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion:*/ true); + return tryAddComputedPropertyName(propertyAccess.expression, containers, /*includeLastPortion*/ true); } return false; } function getContainers(declaration: Declaration) { - let containers: string[] = []; + const containers: string[] = []; // First, if we started with a computed property name, then add all but the last // portion into the container array. if (declaration.name.kind === SyntaxKind.ComputedPropertyName) { - if (!tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion:*/ false)) { + if (!tryAddComputedPropertyName((declaration.name).expression, containers, /*includeLastPortion*/ false)) { return undefined; } } @@ -155,8 +155,8 @@ namespace ts.NavigateTo { Debug.assert(matches.length > 0); let bestMatchKind = PatternMatchKind.camelCase; - for (let match of matches) { - let kind = match.kind; + for (const match of matches) { + const kind = match.kind; if (kind < bestMatchKind) { bestMatchKind = kind; } @@ -171,13 +171,13 @@ namespace ts.NavigateTo { // We first sort case insensitively. So "Aaa" will come before "bar". // Then we sort case sensitively, so "aaa" will come before "Aaa". return i1.matchKind - i2.matchKind || - i1.name.localeCompare(i2.name, undefined, baseSensitivity) || + i1.name.localeCompare(i2.name, undefined, baseSensitivity) || i1.name.localeCompare(i2.name); } function createNavigateToItem(rawItem: RawNavigateToItem): NavigateToItem { - let declaration = rawItem.declaration; - let container = getContainerNode(declaration); + const declaration = rawItem.declaration; + const container = getContainerNode(declaration); return { name: rawItem.name, kind: getNodeKind(declaration), diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 08b089cd75e..fa4f46b5010 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -1,180 +1,179 @@ /* @internal */ -namespace ts { - export module OutliningElementsCollector { - export function collectElements(sourceFile: SourceFile): OutliningSpan[] { - let elements: OutliningSpan[] = []; - let collapseText = "..."; +namespace ts.OutliningElementsCollector { + export function collectElements(sourceFile: SourceFile): OutliningSpan[] { + const elements: OutliningSpan[] = []; + const collapseText = "..."; - function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean) { - if (hintSpanNode && startElement && endElement) { - let span: OutliningSpan = { - textSpan: createTextSpanFromBounds(startElement.pos, endElement.end), - hintSpan: createTextSpanFromBounds(hintSpanNode.getStart(), hintSpanNode.end), - bannerText: collapseText, - autoCollapse: autoCollapse - }; - elements.push(span); - } + function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean) { + if (hintSpanNode && startElement && endElement) { + const span: OutliningSpan = { + textSpan: createTextSpanFromBounds(startElement.pos, endElement.end), + hintSpan: createTextSpanFromBounds(hintSpanNode.getStart(), hintSpanNode.end), + bannerText: collapseText, + autoCollapse: autoCollapse + }; + elements.push(span); } + } - function addOutliningSpanComments(commentSpan: CommentRange, autoCollapse: boolean) { - if (commentSpan) { - let span: OutliningSpan = { - textSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end), - hintSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end), - bannerText: collapseText, - autoCollapse: autoCollapse - }; - elements.push(span); - } + function addOutliningSpanComments(commentSpan: CommentRange, autoCollapse: boolean) { + if (commentSpan) { + const span: OutliningSpan = { + textSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end), + hintSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end), + bannerText: collapseText, + autoCollapse: autoCollapse + }; + elements.push(span); } + } - function addOutliningForLeadingCommentsForNode(n: Node) { - let comments = ts.getLeadingCommentRangesOfNode(n, sourceFile); + function addOutliningForLeadingCommentsForNode(n: Node) { + const comments = ts.getLeadingCommentRangesOfNode(n, sourceFile); - if (comments) { - let firstSingleLineCommentStart = -1; - let lastSingleLineCommentEnd = -1; - let isFirstSingleLineComment = true; - let singleLineCommentCount = 0; + if (comments) { + let firstSingleLineCommentStart = -1; + let lastSingleLineCommentEnd = -1; + let isFirstSingleLineComment = true; + let singleLineCommentCount = 0; - for (let currentComment of comments) { + for (const currentComment of comments) { - // For single line comments, combine consecutive ones (2 or more) into - // a single span from the start of the first till the end of the last - if (currentComment.kind === SyntaxKind.SingleLineCommentTrivia) { - if (isFirstSingleLineComment) { - firstSingleLineCommentStart = currentComment.pos; - } - isFirstSingleLineComment = false; - lastSingleLineCommentEnd = currentComment.end; - singleLineCommentCount++; + // For single line comments, combine consecutive ones (2 or more) into + // a single span from the start of the first till the end of the last + if (currentComment.kind === SyntaxKind.SingleLineCommentTrivia) { + if (isFirstSingleLineComment) { + firstSingleLineCommentStart = currentComment.pos; } - else if (currentComment.kind === SyntaxKind.MultiLineCommentTrivia) { - combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd); - addOutliningSpanComments(currentComment, /*autoCollapse*/ false); + isFirstSingleLineComment = false; + lastSingleLineCommentEnd = currentComment.end; + singleLineCommentCount++; + } + else if (currentComment.kind === SyntaxKind.MultiLineCommentTrivia) { + combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd); + addOutliningSpanComments(currentComment, /*autoCollapse*/ false); - singleLineCommentCount = 0; - lastSingleLineCommentEnd = -1; - isFirstSingleLineComment = true; + singleLineCommentCount = 0; + lastSingleLineCommentEnd = -1; + isFirstSingleLineComment = true; + } + } + + combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd); + } + } + + function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) { + + // Only outline spans of two or more consecutive single line comments + if (count > 1) { + const multipleSingleLineComments = { + pos: start, + end: end, + kind: SyntaxKind.SingleLineCommentTrivia + }; + + addOutliningSpanComments(multipleSingleLineComments, /*autoCollapse*/ false); + } + } + + function autoCollapse(node: Node) { + return isFunctionBlock(node) && node.parent.kind !== SyntaxKind.ArrowFunction; + } + + let depth = 0; + const maxDepth = 20; + function walk(n: Node): void { + if (depth > maxDepth) { + return; + } + + if (isDeclaration(n)) { + addOutliningForLeadingCommentsForNode(n); + } + + switch (n.kind) { + case SyntaxKind.Block: + if (!isFunctionBlock(n)) { + const parent = n.parent; + const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); + const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); + + // Check if the block is standalone, or 'attached' to some parent statement. + // If the latter, we want to collaps the block, but consider its hint span + // to be the entire span of the parent. + if (parent.kind === SyntaxKind.DoStatement || + parent.kind === SyntaxKind.ForInStatement || + parent.kind === SyntaxKind.ForOfStatement || + parent.kind === SyntaxKind.ForStatement || + parent.kind === SyntaxKind.IfStatement || + parent.kind === SyntaxKind.WhileStatement || + parent.kind === SyntaxKind.WithStatement || + parent.kind === SyntaxKind.CatchClause) { + + addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + break; } - } - - combineAndAddMultipleSingleLineComments(singleLineCommentCount, firstSingleLineCommentStart, lastSingleLineCommentEnd); - } - } - - function combineAndAddMultipleSingleLineComments(count: number, start: number, end: number) { - // Only outline spans of two or more consecutive single line comments - if (count > 1) { - let multipleSingleLineComments = { - pos: start, - end: end, - kind: SyntaxKind.SingleLineCommentTrivia - } - - addOutliningSpanComments(multipleSingleLineComments, /*autoCollapse*/ false); - } - } - - function autoCollapse(node: Node) { - return isFunctionBlock(node) && node.parent.kind !== SyntaxKind.ArrowFunction; - } - - let depth = 0; - let maxDepth = 20; - function walk(n: Node): void { - if (depth > maxDepth) { - return; - } - - if (isDeclaration(n)) { - addOutliningForLeadingCommentsForNode(n); - } - - switch (n.kind) { - case SyntaxKind.Block: - if (!isFunctionBlock(n)) { - let parent = n.parent; - let openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); - let closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); - - // Check if the block is standalone, or 'attached' to some parent statement. - // If the latter, we want to collaps the block, but consider its hint span - // to be the entire span of the parent. - if (parent.kind === SyntaxKind.DoStatement || - parent.kind === SyntaxKind.ForInStatement || - parent.kind === SyntaxKind.ForOfStatement || - parent.kind === SyntaxKind.ForStatement || - parent.kind === SyntaxKind.IfStatement || - parent.kind === SyntaxKind.WhileStatement || - parent.kind === SyntaxKind.WithStatement || - parent.kind === SyntaxKind.CatchClause) { + if (parent.kind === SyntaxKind.TryStatement) { + // Could be the try-block, or the finally-block. + const tryStatement = parent; + if (tryStatement.tryBlock === n) { addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); break; } - - if (parent.kind === SyntaxKind.TryStatement) { - // Could be the try-block, or the finally-block. - let tryStatement = parent; - if (tryStatement.tryBlock === n) { - addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n)); + else if (tryStatement.finallyBlock === n) { + const finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile); + if (finallyKeyword) { + addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n)); break; } - else if (tryStatement.finallyBlock === n) { - let finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile); - if (finallyKeyword) { - addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n)); - break; - } - } - - // fall through. } - // Block was a standalone block. In this case we want to only collapse - // the span of the block, independent of any parent span. - let span = createTextSpanFromBounds(n.getStart(), n.end); - elements.push({ - textSpan: span, - hintSpan: span, - bannerText: collapseText, - autoCollapse: autoCollapse(n) - }); - break; + // fall through. } - // Fallthrough. - case SyntaxKind.ModuleBlock: { - let openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); - let closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); - addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); + // Block was a standalone block. In this case we want to only collapse + // the span of the block, independent of any parent span. + const span = createTextSpanFromBounds(n.getStart(), n.end); + elements.push({ + textSpan: span, + hintSpan: span, + bannerText: collapseText, + autoCollapse: autoCollapse(n) + }); break; } - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.CaseBlock: { - let openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); - let closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); - addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); - break; - } - case SyntaxKind.ArrayLiteralExpression: - let openBracket = findChildOfKind(n, SyntaxKind.OpenBracketToken, sourceFile); - let closeBracket = findChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile); - addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); - break; + // Fallthrough. + + case SyntaxKind.ModuleBlock: { + const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); + const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); + addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n)); + break; } - depth++; - forEachChild(n, walk); - depth--; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.CaseBlock: { + const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile); + const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile); + addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n)); + break; + } + case SyntaxKind.ArrayLiteralExpression: + const openBracket = findChildOfKind(n, SyntaxKind.OpenBracketToken, sourceFile); + const closeBracket = findChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile); + addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n)); + break; } - - walk(sourceFile); - return elements; + depth++; + forEachChild(n, walk); + depth--; } + + walk(sourceFile); + return elements; } } \ No newline at end of file diff --git a/src/services/patternMatcher.ts b/src/services/patternMatcher.ts index ea433867c46..93cc5130d72 100644 --- a/src/services/patternMatcher.ts +++ b/src/services/patternMatcher.ts @@ -8,10 +8,10 @@ namespace ts { camelCase } - // Information about a match made by the pattern matcher between a candidate and the + // Information about a match made by the pattern matcher between a candidate and the // search pattern. export interface PatternMatch { - // What kind of match this was. Exact matches are better than prefix matches which are + // What kind of match this was. Exact matches are better than prefix matches which are // better than substring matches which are better than CamelCase matches. kind: PatternMatchKind; @@ -19,7 +19,7 @@ namespace ts { // it was a better match. camelCaseWeight?: number; - // If this was a match where all constituent parts of the candidate and search pattern + // If this was a match where all constituent parts of the candidate and search pattern // matched case sensitively or case insensitively. Case sensitive matches of the kind // are better matches than insensitive matches. isCaseSensitive: boolean; @@ -35,7 +35,7 @@ namespace ts { // once you no longer need it. export interface PatternMatcher { // Used to match a candidate against the last segment of a possibly dotted pattern. This - // is useful as a quick check to prevent having to compute a container before calling + // is useful as a quick check to prevent having to compute a container before calling // "getMatches". // // For example, if the search pattern is "ts.c.SK" and the candidate is "SyntaxKind", then @@ -55,8 +55,8 @@ namespace ts { } // First we break up the pattern given by dots. Each portion of the pattern between the - // dots is a 'Segment'. The 'Segment' contains information about the entire section of - // text between the dots, as well as information about any individual 'Words' that we + // dots is a 'Segment'. The 'Segment' contains information about the entire section of + // text between the dots, as well as information about any individual 'Words' that we // can break the segment into. A 'Word' is simply a contiguous sequence of characters // that can appear in a typescript identifier. So "GetKeyword" would be one word, while // "Get Keyword" would be two words. Once we have the individual 'words', we break those @@ -64,20 +64,20 @@ namespace ts { // word, it make character spans corresponding to "U", "I" and "Element". These spans // are then used when doing camel cased matches against candidate patterns. interface Segment { - // Information about the entire piece of text between the dots. For example, if the - // text between the dots is 'GetKeyword', then TotalTextChunk.Text will be 'GetKeyword' and + // Information about the entire piece of text between the dots. For example, if the + // text between the dots is 'GetKeyword', then TotalTextChunk.Text will be 'GetKeyword' and // TotalTextChunk.CharacterSpans will correspond to 'Get', 'Keyword'. totalTextChunk: TextChunk; - // Information about the subwords compromising the total word. For example, if the - // text between the dots is 'GetFoo KeywordBar', then the subwords will be 'GetFoo' - // and 'KeywordBar'. Those individual words will have CharacterSpans of ('Get' and - // 'Foo') and('Keyword' and 'Bar') respectively. + // Information about the subwords compromising the total word. For example, if the + // text between the dots is 'GetFoo KeywordBar', then the subwords will be 'GetFoo' + // and 'KeywordBar'. Those individual words will have CharacterSpans of ('Get' and + // 'Foo') and('Keyword' and 'Bar') respectively. subWordTextChunks: TextChunk[]; } - // Information about a chunk of text from the pattern. The chunk is a piece of text, with - // cached information about the character spans within in. Character spans are used for + // Information about a chunk of text from the pattern. The chunk is a piece of text, with + // cached information about the character spans within in. Character spans are used for // camel case matching. interface TextChunk { // The text of the chunk. This should be a contiguous sequence of character that could @@ -92,9 +92,9 @@ namespace ts { // for something entirely lowercase or not. isLowerCase: boolean; - // The spans in this text chunk that we think are of interest and should be matched + // The spans in this text chunk that we think are of interest and should be matched // independently. For example, if the chunk is for "UIElement" the the spans of interest - // correspond to "U", "I" and "Element". If "UIElement" isn't found as an exaxt, prefix. + // correspond to "U", "I" and "Element". If "UIElement" isn't found as an exact, prefix. // or substring match, then the character spans will be used to attempt a camel case match. characterSpans: TextSpan[]; } @@ -110,20 +110,19 @@ namespace ts { export function createPatternMatcher(pattern: string): PatternMatcher { // We'll often see the same candidate string many times when searching (For example, when - // we see the name of a module that is used everywhere, or the name of an overload). As - // such, we cache the information we compute about the candidate for the life of this + // we see the name of a module that is used everywhere, or the name of an overload). As + // such, we cache the information we compute about the candidate for the life of this // pattern matcher so we don't have to compute it multiple times. - let stringToWordSpans: Map = {}; + const stringToWordSpans: Map = {}; pattern = pattern.trim(); - let fullPatternSegment = createSegment(pattern); - let dotSeparatedSegments = pattern.split(".").map(p => createSegment(p.trim())); - let invalidPattern = dotSeparatedSegments.length === 0 || forEach(dotSeparatedSegments, segmentIsInvalid); + const dotSeparatedSegments = pattern.split(".").map(p => createSegment(p.trim())); + const invalidPattern = dotSeparatedSegments.length === 0 || forEach(dotSeparatedSegments, segmentIsInvalid); return { getMatches, - getMatchesForLastSegmentOfPattern, + getMatchesForLastSegmentOfPattern, patternContainsDots: dotSeparatedSegments.length > 1 }; @@ -131,7 +130,7 @@ namespace ts { function skipMatch(candidate: string) { return invalidPattern || !candidate; } - + function getMatchesForLastSegmentOfPattern(candidate: string): PatternMatch[] { if (skipMatch(candidate)) { return undefined; @@ -148,7 +147,7 @@ namespace ts { // First, check that the last part of the dot separated pattern matches the name of the // candidate. If not, then there's no point in proceeding and doing the more // expensive work. - let candidateMatch = matchSegment(candidate, lastOrUndefined(dotSeparatedSegments)); + const candidateMatch = matchSegment(candidate, lastOrUndefined(dotSeparatedSegments)); if (!candidateMatch) { return undefined; } @@ -165,16 +164,16 @@ namespace ts { // So far so good. Now break up the container for the candidate and check if all // the dotted parts match up correctly. - let totalMatch = candidateMatch; + const totalMatch = candidateMatch; for (let i = dotSeparatedSegments.length - 2, j = candidateContainers.length - 1; i >= 0; - i--, j--) { + i -= 1, j -= 1) { - let segment = dotSeparatedSegments[i]; - let containerName = candidateContainers[j]; + const segment = dotSeparatedSegments[i]; + const containerName = candidateContainers[j]; - let containerMatch = matchSegment(containerName, segment); + const containerMatch = matchSegment(containerName, segment); if (!containerMatch) { // This container didn't match the pattern piece. So there's no match at all. return undefined; @@ -197,7 +196,7 @@ namespace ts { } function matchTextChunk(candidate: string, chunk: TextChunk, punctuationStripped: boolean): PatternMatch { - let index = indexOfIgnoringCase(candidate, chunk.textLowerCase); + const index = indexOfIgnoringCase(candidate, chunk.textLowerCase); if (index === 0) { if (chunk.text.length === candidate.length) { // a) Check if the part matches the candidate entirely, in an case insensitive or @@ -211,18 +210,18 @@ namespace ts { } } - let isLowercase = chunk.isLowerCase; + const isLowercase = chunk.isLowerCase; if (isLowercase) { if (index > 0) { // c) If the part is entirely lowercase, then check if it is contained anywhere in the // candidate in a case insensitive manner. If so, return that there was a substring - // match. + // match. // // Note: We only have a substring match if the lowercase part is prefix match of some // word part. That way we don't match something like 'Class' when the user types 'a'. // But we would match 'FooAttribute' (since 'Attribute' starts with 'a'). - let wordSpans = getWordSpans(candidate); - for (let span of wordSpans) { + const wordSpans = getWordSpans(candidate); + for (const span of wordSpans) { if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) { return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false)); @@ -242,7 +241,7 @@ namespace ts { if (!isLowercase) { // e) If the part was not entirely lowercase, then attempt a camel cased match as well. if (chunk.characterSpans.length > 0) { - let candidateParts = getWordSpans(candidate); + const candidateParts = getWordSpans(candidate); let camelCaseWeight = tryCamelCaseMatch(candidate, candidateParts, chunk, /*ignoreCase:*/ false); if (camelCaseWeight !== undefined) { return createPatternMatch(PatternMatchKind.camelCase, punctuationStripped, /*isCaseSensitive:*/ true, /*camelCaseWeight:*/ camelCaseWeight); @@ -259,8 +258,8 @@ namespace ts { // f) Is the pattern a substring of the candidate starting on one of the candidate's word boundaries? // We could check every character boundary start of the candidate for the pattern. However, that's - // an m * n operation in the wost case. Instead, find the first instance of the pattern - // substring, and see if it starts on a capital letter. It seems unlikely that the user will try to + // an m * n operation in the wost case. Instead, find the first instance of the pattern + // substring, and see if it starts on a capital letter. It seems unlikely that the user will try to // filter the list based on a substring that starts on a capital letter and also with a lowercase one. // (Pattern: fogbar, Candidate: quuxfogbarFogBar). if (chunk.text.length < candidate.length) { @@ -275,7 +274,7 @@ namespace ts { function containsSpaceOrAsterisk(text: string): boolean { for (let i = 0; i < text.length; i++) { - let ch = text.charCodeAt(i); + const ch = text.charCodeAt(i); if (ch === CharacterCodes.space || ch === CharacterCodes.asterisk) { return true; } @@ -293,7 +292,7 @@ namespace ts { // Note: if the segment contains a space or an asterisk then we must assume that it's a // multi-word segment. if (!containsSpaceOrAsterisk(segment.totalTextChunk.text)) { - let match = matchTextChunk(candidate, segment.totalTextChunk, /*punctuationStripped:*/ false); + const match = matchTextChunk(candidate, segment.totalTextChunk, /*punctuationStripped:*/ false); if (match) { return [match]; } @@ -317,7 +316,7 @@ namespace ts { // // c) If the word is entirely lowercase, then check if it is contained anywhere in the // candidate in a case insensitive manner. If so, return that there was a substring - // match. + // match. // // Note: We only have a substring match if the lowercase part is prefix match of // some word part. That way we don't match something like 'Class' when the user @@ -331,17 +330,17 @@ namespace ts { // e) If the word was not entirely lowercase, then attempt a camel cased match as // well. // - // f) The word is all lower case. Is it a case insensitive substring of the candidate starting + // f) The word is all lower case. Is it a case insensitive substring of the candidate starting // on a part boundary of the candidate? // // Only if all words have some sort of match is the pattern considered matched. - let subWordTextChunks = segment.subWordTextChunks; + const subWordTextChunks = segment.subWordTextChunks; let matches: PatternMatch[] = undefined; - for (let subWordTextChunk of subWordTextChunks) { + for (const subWordTextChunk of subWordTextChunks) { // Try to match the candidate with this word - let result = matchTextChunk(candidate, subWordTextChunk, /*punctuationStripped:*/ true); + const result = matchTextChunk(candidate, subWordTextChunk, /*punctuationStripped:*/ true); if (!result) { return undefined; } @@ -354,18 +353,18 @@ namespace ts { } function partStartsWith(candidate: string, candidateSpan: TextSpan, pattern: string, ignoreCase: boolean, patternSpan?: TextSpan): boolean { - let patternPartStart = patternSpan ? patternSpan.start : 0; - let patternPartLength = patternSpan ? patternSpan.length : pattern.length; + const patternPartStart = patternSpan ? patternSpan.start : 0; + const patternPartLength = patternSpan ? patternSpan.length : pattern.length; if (patternPartLength > candidateSpan.length) { // Pattern part is longer than the candidate part. There can never be a match. return false; } - + if (ignoreCase) { for (let i = 0; i < patternPartLength; i++) { - let ch1 = pattern.charCodeAt(patternPartStart + i); - let ch2 = candidate.charCodeAt(candidateSpan.start + i); + const ch1 = pattern.charCodeAt(patternPartStart + i); + const ch2 = candidate.charCodeAt(candidateSpan.start + i); if (toLowerCase(ch1) !== toLowerCase(ch2)) { return false; } @@ -373,8 +372,8 @@ namespace ts { } else { for (let i = 0; i < patternPartLength; i++) { - let ch1 = pattern.charCodeAt(patternPartStart + i); - let ch2 = candidate.charCodeAt(candidateSpan.start + i); + const ch1 = pattern.charCodeAt(patternPartStart + i); + const ch2 = candidate.charCodeAt(candidateSpan.start + i); if (ch1 !== ch2) { return false; } @@ -385,12 +384,12 @@ namespace ts { } function tryCamelCaseMatch(candidate: string, candidateParts: TextSpan[], chunk: TextChunk, ignoreCase: boolean): number { - let chunkCharacterSpans = chunk.characterSpans; + const chunkCharacterSpans = chunk.characterSpans; // Note: we may have more pattern parts than candidate parts. This is because multiple // pattern parts may match a candidate part. For example "SiUI" against "SimpleUI". // We'll have 3 pattern parts Si/U/I against two candidate parts Simple/UI. However, U - // and I will both match in UI. + // and I will both match in UI. let currentCandidate = 0; let currentChunkSpan = 0; @@ -426,14 +425,14 @@ namespace ts { // Consider the case of matching SiUI against SimpleUIElement. The candidate parts // will be Simple/UI/Element, and the pattern parts will be Si/U/I. We'll match 'Si' // against 'Simple' first. Then we'll match 'U' against 'UI'. However, we want to - // still keep matching pattern parts against that candidate part. + // still keep matching pattern parts against that candidate part. for (; currentChunkSpan < chunkCharacterSpans.length; currentChunkSpan++) { - let chunkCharacterSpan = chunkCharacterSpans[currentChunkSpan]; + const chunkCharacterSpan = chunkCharacterSpans[currentChunkSpan]; if (gotOneMatchThisCandidate) { // We've already gotten one pattern part match in this candidate. We will // only continue trying to consumer pattern parts if the last part and this - // part are both upper case. + // part are both upper case. if (!isUpperCaseLetter(chunk.text.charCodeAt(chunkCharacterSpans[currentChunkSpan - 1].start)) || !isUpperCaseLetter(chunk.text.charCodeAt(chunkCharacterSpans[currentChunkSpan].start))) { break; @@ -470,55 +469,11 @@ namespace ts { } } - // Helper function to compare two matches to determine which is better. Matches are first - // ordered by kind (so all prefix matches always beat all substring matches). Then, if the - // match is a camel case match, the relative weights of the match are used to determine - // which is better (with a greater weight being better). Then if the match is of the same - // type, then a case sensitive match is considered better than an insensitive one. - function patternMatchCompareTo(match1: PatternMatch, match2: PatternMatch): number { - return compareType(match1, match2) || - compareCamelCase(match1, match2) || - compareCase(match1, match2) || - comparePunctuation(match1, match2); - } - - function comparePunctuation(result1: PatternMatch, result2: PatternMatch) { - // Consider a match to be better if it was successful without stripping punctuation - // versus a match that had to strip punctuation to succeed. - if (result1.punctuationStripped !== result2.punctuationStripped) { - return result1.punctuationStripped ? 1 : -1; - } - - return 0; - } - - function compareCase(result1: PatternMatch, result2: PatternMatch) { - if (result1.isCaseSensitive !== result2.isCaseSensitive) { - return result1.isCaseSensitive ? -1 : 1; - } - - return 0; - } - - function compareType(result1: PatternMatch, result2: PatternMatch) { - return result1.kind - result2.kind; - } - - function compareCamelCase(result1: PatternMatch, result2: PatternMatch) { - if (result1.kind === PatternMatchKind.camelCase && result2.kind === PatternMatchKind.camelCase) { - // Swap the values here. If result1 has a higher weight, then we want it to come - // first. - return result2.camelCaseWeight - result1.camelCaseWeight; - } - - return 0; - } - function createSegment(text: string): Segment { return { totalTextChunk: createTextChunk(text), subWordTextChunks: breakPatternIntoTextChunks(text) - } + }; } // A segment is considered invalid if we couldn't find any words in it. @@ -536,9 +491,9 @@ namespace ts { return false; } - // TODO: find a way to determine this for any unicode characters in a + // TODO: find a way to determine this for any unicode characters in a // non-allocating manner. - let str = String.fromCharCode(ch); + const str = String.fromCharCode(ch); return str === str.toUpperCase(); } @@ -553,22 +508,12 @@ namespace ts { } - // TODO: find a way to determine this for any unicode characters in a + // TODO: find a way to determine this for any unicode characters in a // non-allocating manner. - let str = String.fromCharCode(ch); + const str = String.fromCharCode(ch); return str === str.toLowerCase(); } - function containsUpperCaseLetter(string: string): boolean { - for (let i = 0, n = string.length; i < n; i++) { - if (isUpperCaseLetter(string.charCodeAt(i))) { - return true; - } - } - - return false; - } - function startsWith(string: string, search: string) { for (let i = 0, n = search.length; i < n; i++) { if (string.charCodeAt(i) !== search.charCodeAt(i)) { @@ -593,8 +538,8 @@ namespace ts { // Assumes 'value' is already lowercase. function startsWithIgnoringCase(string: string, value: string, start: number): boolean { for (let i = 0, n = value.length; i < n; i++) { - let ch1 = toLowerCase(string.charCodeAt(i + start)); - let ch2 = value.charCodeAt(i); + const ch1 = toLowerCase(string.charCodeAt(i + start)); + const ch2 = value.charCodeAt(i); if (ch1 !== ch2) { return false; @@ -614,7 +559,7 @@ namespace ts { return ch; } - // TODO: find a way to compute this for any unicode characters in a + // TODO: find a way to compute this for any unicode characters in a // non-allocating manner. return String.fromCharCode(ch).toLowerCase().charCodeAt(0); } @@ -629,16 +574,17 @@ namespace ts { } function breakPatternIntoTextChunks(pattern: string): TextChunk[] { - let result: TextChunk[] = []; + const result: TextChunk[] = []; let wordStart = 0; let wordLength = 0; for (let i = 0; i < pattern.length; i++) { - let ch = pattern.charCodeAt(i); + const ch = pattern.charCodeAt(i); if (isWordChar(ch)) { - if (wordLength++ === 0) { + if (wordLength === 0) { wordStart = i; } + wordLength++; } else { if (wordLength > 0) { @@ -656,13 +602,13 @@ namespace ts { } function createTextChunk(text: string): TextChunk { - let textLowerCase = text.toLowerCase(); + const textLowerCase = text.toLowerCase(); return { text, textLowerCase, isLowerCase: text === textLowerCase, characterSpans: breakIntoCharacterSpans(text) - } + }; } /* @internal */ export function breakIntoCharacterSpans(identifier: string): TextSpan[] { @@ -674,15 +620,15 @@ namespace ts { } function breakIntoSpans(identifier: string, word: boolean): TextSpan[] { - let result: TextSpan[] = []; + const result: TextSpan[] = []; let wordStart = 0; for (let i = 1, n = identifier.length; i < n; i++) { - let lastIsDigit = isDigit(identifier.charCodeAt(i - 1)); - let currentIsDigit = isDigit(identifier.charCodeAt(i)); + const lastIsDigit = isDigit(identifier.charCodeAt(i - 1)); + const currentIsDigit = isDigit(identifier.charCodeAt(i)); - let hasTransitionFromLowerToUpper = transitionFromLowerToUpper(identifier, word, i); - let hasTransitionFromUpperToLower = transitionFromUpperToLower(identifier, word, i, wordStart); + const hasTransitionFromLowerToUpper = transitionFromLowerToUpper(identifier, word, i); + const hasTransitionFromUpperToLower = transitionFromUpperToLower(identifier, word, i, wordStart); if (charIsPunctuation(identifier.charCodeAt(i - 1)) || charIsPunctuation(identifier.charCodeAt(i)) || @@ -738,7 +684,7 @@ namespace ts { function isAllPunctuation(identifier: string, start: number, end: number): boolean { for (let i = start; i < end; i++) { - let ch = identifier.charCodeAt(i); + const ch = identifier.charCodeAt(i); // We don't consider _ or $ as punctuation as there may be things with that name. if (!charIsPunctuation(ch) || ch === CharacterCodes._ || ch === CharacterCodes.$) { @@ -759,8 +705,8 @@ namespace ts { // etc. if (index !== wordStart && index + 1 < identifier.length) { - let currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); - let nextIsLower = isLowerCaseLetter(identifier.charCodeAt(index + 1)); + const currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); + const nextIsLower = isLowerCaseLetter(identifier.charCodeAt(index + 1)); if (currentIsUpper && nextIsLower) { // We have a transition from an upper to a lower letter here. But we only @@ -786,12 +732,12 @@ namespace ts { } function transitionFromLowerToUpper(identifier: string, word: boolean, index: number): boolean { - let lastIsUpper = isUpperCaseLetter(identifier.charCodeAt(index - 1)); - let currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); + const lastIsUpper = isUpperCaseLetter(identifier.charCodeAt(index - 1)); + const currentIsUpper = isUpperCaseLetter(identifier.charCodeAt(index)); // See if the casing indicates we're starting a new word. Note: if we're breaking on // words, then just seeing an upper case character isn't enough. Instead, it has to - // be uppercase and the previous character can't be uppercase. + // be uppercase and the previous character can't be uppercase. // // For example, breaking "AddMetadata" on words would make: Add Metadata // @@ -802,7 +748,7 @@ namespace ts { // on characters would be: A M // // We break the search string on characters. But we break the symbol name on words. - let transition = word + const transition = word ? (currentIsUpper && !lastIsUpper) : currentIsUpper; return transition; diff --git a/src/services/services.ts b/src/services/services.ts index 0ffd1138cba..0fd4df19907 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -469,7 +469,8 @@ namespace ts { function pushDocCommentLineText(docComments: SymbolDisplayPart[], text: string, blankLineCount: number) { // Add the empty lines in between texts - while (blankLineCount--) { + while (blankLineCount) { + blankLineCount--; docComments.push(textPart("")); } diff --git a/tests/baselines/reference/aliasesInSystemModule1.js b/tests/baselines/reference/aliasesInSystemModule1.js index 43037c7634c..11f02c18ea4 100644 --- a/tests/baselines/reference/aliasesInSystemModule1.js +++ b/tests/baselines/reference/aliasesInSystemModule1.js @@ -17,7 +17,7 @@ module M { //// [aliasesInSystemModule1.js] -System.register(['foo'], function(exports_1) { +System.register(['foo'], function(exports_1, __moduleName) { "use strict"; var alias; var cls, cls2, x, y, z, M; diff --git a/tests/baselines/reference/aliasesInSystemModule2.js b/tests/baselines/reference/aliasesInSystemModule2.js index 7effb2721be..7378536e2fd 100644 --- a/tests/baselines/reference/aliasesInSystemModule2.js +++ b/tests/baselines/reference/aliasesInSystemModule2.js @@ -16,7 +16,7 @@ module M { } //// [aliasesInSystemModule2.js] -System.register(["foo"], function(exports_1) { +System.register(["foo"], function(exports_1, __moduleName) { "use strict"; var foo_1; var cls, cls2, x, y, z, M; diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.js b/tests/baselines/reference/allowSyntheticDefaultImports2.js index fcc029415cf..0480250d71a 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.js @@ -10,7 +10,7 @@ export class Foo { } //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var Foo; return { @@ -26,7 +26,7 @@ System.register([], function(exports_1) { } }); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, __moduleName) { "use strict"; var b_1; var x; diff --git a/tests/baselines/reference/allowSyntheticDefaultImports3.js b/tests/baselines/reference/allowSyntheticDefaultImports3.js index b14d25dbd61..adf85792fd9 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports3.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports3.js @@ -11,7 +11,7 @@ export class Foo { //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var Foo; return { @@ -27,7 +27,7 @@ System.register([], function(exports_1) { } }); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, __moduleName) { "use strict"; var b_1; var x; diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.js b/tests/baselines/reference/allowSyntheticDefaultImports5.js index c9121512b61..d0dfdcb76d1 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports5.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.js @@ -12,7 +12,7 @@ export var x = new Foo(); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, __moduleName) { "use strict"; var b_1; var x; diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.js b/tests/baselines/reference/allowSyntheticDefaultImports6.js index 64d52e70af9..eaafb5ee276 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports6.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.js @@ -12,7 +12,7 @@ export var x = new Foo(); //// [a.js] -System.register(["./b"], function(exports_1) { +System.register(["./b"], function(exports_1, __moduleName) { "use strict"; var b_1; var x; diff --git a/tests/baselines/reference/anonymousDefaultExportsSystem.js b/tests/baselines/reference/anonymousDefaultExportsSystem.js index 74913a57a99..4ee7e2a11bc 100644 --- a/tests/baselines/reference/anonymousDefaultExportsSystem.js +++ b/tests/baselines/reference/anonymousDefaultExportsSystem.js @@ -7,7 +7,7 @@ export default class {} export default function() {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var default_1; return { @@ -20,7 +20,7 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function default_1() { } exports_1("default", default_1); diff --git a/tests/baselines/reference/capturedLetConstInLoop4.js b/tests/baselines/reference/capturedLetConstInLoop4.js index 724c84fe04f..c2d2c998616 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.js +++ b/tests/baselines/reference/capturedLetConstInLoop4.js @@ -144,7 +144,7 @@ for (const y = 0; y < 1;) { //// [capturedLetConstInLoop4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var v0, v00, v1, v2, v3, v4, v5, v6, v7, v8, v0_c, v00_c, v1_c, v2_c, v3_c, v4_c, v5_c, v6_c, v7_c, v8_c; //======let diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js index ed322374799..be20d5ffc12 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.js @@ -13,7 +13,7 @@ var decorator: ClassDecorator; export default class {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; @@ -35,7 +35,7 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; diff --git a/tests/baselines/reference/defaultExportsGetExportedSystem.js b/tests/baselines/reference/defaultExportsGetExportedSystem.js index 67dc47f4bd5..f67ccb6ee23 100644 --- a/tests/baselines/reference/defaultExportsGetExportedSystem.js +++ b/tests/baselines/reference/defaultExportsGetExportedSystem.js @@ -8,7 +8,7 @@ export default function foo() {} //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var Foo; return { @@ -21,7 +21,7 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function foo() { } exports_1("default", foo); diff --git a/tests/baselines/reference/es5-system.js b/tests/baselines/reference/es5-system.js index a9633352b8b..1cd1dac13d1 100644 --- a/tests/baselines/reference/es5-system.js +++ b/tests/baselines/reference/es5-system.js @@ -15,7 +15,7 @@ export default class A //// [es5-system.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var A; return { diff --git a/tests/baselines/reference/exportNonInitializedVariablesSystem.js b/tests/baselines/reference/exportNonInitializedVariablesSystem.js index b5674bf5ce3..53d8a5424ef 100644 --- a/tests/baselines/reference/exportNonInitializedVariablesSystem.js +++ b/tests/baselines/reference/exportNonInitializedVariablesSystem.js @@ -35,7 +35,7 @@ export let h1: D = new D; //// [exportNonInitializedVariablesSystem.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var a, b, c, d, A, e, f, B, C, a1, b1, c1, d1, D, e1, f1, g1, h1; return { diff --git a/tests/baselines/reference/exportStarForValues10.js b/tests/baselines/reference/exportStarForValues10.js index dca5dad9b7a..1149baf8b27 100644 --- a/tests/baselines/reference/exportStarForValues10.js +++ b/tests/baselines/reference/exportStarForValues10.js @@ -13,7 +13,7 @@ export * from "file1"; var x = 1; //// [file0.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var v; return { @@ -24,7 +24,7 @@ System.register([], function(exports_1) { } }); //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -33,7 +33,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register(["file0"], function(exports_1) { +System.register(["file0"], function(exports_1, __moduleName) { "use strict"; var x; function exportStar_1(m) { diff --git a/tests/baselines/reference/exportStarForValues6.js b/tests/baselines/reference/exportStarForValues6.js index 69357d87ee0..f2257277630 100644 --- a/tests/baselines/reference/exportStarForValues6.js +++ b/tests/baselines/reference/exportStarForValues6.js @@ -9,7 +9,7 @@ export * from "file1" export var x = 1; //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -18,7 +18,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x; return { diff --git a/tests/baselines/reference/exportStarForValuesInSystem.js b/tests/baselines/reference/exportStarForValuesInSystem.js index a33465f7e2e..33ca1f8b24d 100644 --- a/tests/baselines/reference/exportStarForValuesInSystem.js +++ b/tests/baselines/reference/exportStarForValuesInSystem.js @@ -9,7 +9,7 @@ export * from "file1" var x = 1; //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -18,7 +18,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x; return { diff --git a/tests/baselines/reference/isolatedModulesPlainFile-System.js b/tests/baselines/reference/isolatedModulesPlainFile-System.js index b66bd497810..44eec5161c0 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-System.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.js @@ -5,7 +5,7 @@ run(1); //// [isolatedModulesPlainFile-System.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], diff --git a/tests/baselines/reference/modulePrologueSystem.js b/tests/baselines/reference/modulePrologueSystem.js index 80a46fb27fc..04519898166 100644 --- a/tests/baselines/reference/modulePrologueSystem.js +++ b/tests/baselines/reference/modulePrologueSystem.js @@ -4,7 +4,7 @@ export class Foo {} //// [modulePrologueSystem.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var Foo; return { diff --git a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js index 298ad52689f..e6ac346dc7f 100644 --- a/tests/baselines/reference/outFilerootDirModuleNamesSystem.js +++ b/tests/baselines/reference/outFilerootDirModuleNamesSystem.js @@ -11,7 +11,7 @@ export default function foo() { new Foo(); } //// [output.js] -System.register("b", ["a"], function(exports_1) { +System.register("b", ["a"], function(exports_1, __moduleName) { "use strict"; var a_1; function foo() { new a_1.default(); } @@ -25,7 +25,7 @@ System.register("b", ["a"], function(exports_1) { } } }); -System.register("a", ["b"], function(exports_2) { +System.register("a", ["b"], function(exports_2, __moduleName) { "use strict"; var b_1; var Foo; diff --git a/tests/baselines/reference/outModuleConcatSystem.js b/tests/baselines/reference/outModuleConcatSystem.js index d4552d33167..bd2753c6d5f 100644 --- a/tests/baselines/reference/outModuleConcatSystem.js +++ b/tests/baselines/reference/outModuleConcatSystem.js @@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -System.register("ref/a", [], function(exports_1) { +System.register("ref/a", [], function(exports_1, __moduleName) { "use strict"; var A; return { @@ -29,7 +29,7 @@ System.register("ref/a", [], function(exports_1) { } } }); -System.register("b", ["ref/a"], function(exports_2) { +System.register("b", ["ref/a"], function(exports_2, __moduleName) { "use strict"; var a_1; var B; diff --git a/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt b/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt index e3f521c828c..0b1f9cc5294 100644 --- a/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt +++ b/tests/baselines/reference/outModuleConcatSystem.sourcemap.txt @@ -13,7 +13,7 @@ sourceFile:tests/cases/compiler/ref/a.ts >>> function __() { this.constructor = d; } >>> d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); >>>}; ->>>System.register("ref/a", [], function(exports_1) { +>>>System.register("ref/a", [], function(exports_1, __moduleName) { >>> "use strict"; >>> var A; >>> return { @@ -82,7 +82,7 @@ sourceFile:tests/cases/compiler/b.ts >>> } >>> } >>>}); ->>>System.register("b", ["ref/a"], function(exports_2) { +>>>System.register("b", ["ref/a"], function(exports_2, __moduleName) { >>> "use strict"; >>> var a_1; >>> var B; diff --git a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js index 5d414c97d05..a3b70bde6d5 100644 --- a/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js +++ b/tests/baselines/reference/prefixUnaryOperatorsOnExportedVariables.js @@ -31,7 +31,7 @@ if (++y) { } //// [prefixUnaryOperatorsOnExportedVariables.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x, y; return { diff --git a/tests/baselines/reference/systemExportAssignment.js b/tests/baselines/reference/systemExportAssignment.js index 72962cf835c..f8b50cb580f 100644 --- a/tests/baselines/reference/systemExportAssignment.js +++ b/tests/baselines/reference/systemExportAssignment.js @@ -10,7 +10,7 @@ import * as a from "a"; //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], diff --git a/tests/baselines/reference/systemExportAssignment2.js b/tests/baselines/reference/systemExportAssignment2.js index 0f4dd712493..6a5c0e8f397 100644 --- a/tests/baselines/reference/systemExportAssignment2.js +++ b/tests/baselines/reference/systemExportAssignment2.js @@ -10,7 +10,7 @@ import * as a from "a"; //// [a.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var a; return { @@ -21,7 +21,7 @@ System.register([], function(exports_1) { } }); //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], diff --git a/tests/baselines/reference/systemExportAssignment3.js b/tests/baselines/reference/systemExportAssignment3.js index ca2492a54e1..9c6d3cdbb2f 100644 --- a/tests/baselines/reference/systemExportAssignment3.js +++ b/tests/baselines/reference/systemExportAssignment3.js @@ -12,7 +12,7 @@ import * as a from "a"; //// [b.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], diff --git a/tests/baselines/reference/systemModule1.js b/tests/baselines/reference/systemModule1.js index 52f3b482069..749d8170dcb 100644 --- a/tests/baselines/reference/systemModule1.js +++ b/tests/baselines/reference/systemModule1.js @@ -3,7 +3,7 @@ export var x = 1; //// [systemModule1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x; return { diff --git a/tests/baselines/reference/systemModule10.js b/tests/baselines/reference/systemModule10.js index ac32c4948e7..f23e7ca1d76 100644 --- a/tests/baselines/reference/systemModule10.js +++ b/tests/baselines/reference/systemModule10.js @@ -10,7 +10,7 @@ export {n2} export {n2 as n3} //// [systemModule10.js] -System.register(['file1', 'file2'], function(exports_1) { +System.register(['file1', 'file2'], function(exports_1, __moduleName) { "use strict"; var file1_1, n2; return { diff --git a/tests/baselines/reference/systemModule10_ES5.js b/tests/baselines/reference/systemModule10_ES5.js index 0c98df6ba99..3d63e092df4 100644 --- a/tests/baselines/reference/systemModule10_ES5.js +++ b/tests/baselines/reference/systemModule10_ES5.js @@ -10,7 +10,7 @@ export {n2} export {n2 as n3} //// [systemModule10_ES5.js] -System.register(['file1', 'file2'], function(exports_1) { +System.register(['file1', 'file2'], function(exports_1, __moduleName) { "use strict"; var file1_1, n2; return { diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js index 92b0576b919..1e755a86541 100644 --- a/tests/baselines/reference/systemModule11.js +++ b/tests/baselines/reference/systemModule11.js @@ -42,7 +42,7 @@ export * from 'a'; //// [file1.js] // set of tests cases that checks generation of local storage for exported names -System.register(['bar'], function(exports_1) { +System.register(['bar'], function(exports_1, __moduleName) { "use strict"; var x; function foo() { } @@ -68,7 +68,7 @@ System.register(['bar'], function(exports_1) { } }); //// [file2.js] -System.register(['bar'], function(exports_1) { +System.register(['bar'], function(exports_1, __moduleName) { "use strict"; var x, y; var exportedNames_1 = { @@ -94,7 +94,7 @@ System.register(['bar'], function(exports_1) { } }); //// [file3.js] -System.register(['a', 'bar'], function(exports_1) { +System.register(['a', 'bar'], function(exports_1, __moduleName) { "use strict"; function foo() { } exports_1("default", foo); @@ -125,7 +125,7 @@ System.register(['a', 'bar'], function(exports_1) { } }); //// [file4.js] -System.register(['a'], function(exports_1) { +System.register(['a'], function(exports_1, __moduleName) { "use strict"; var x, z, z1; function foo() { } @@ -147,7 +147,7 @@ System.register(['a'], function(exports_1) { } }); //// [file5.js] -System.register(['a'], function(exports_1) { +System.register(['a'], function(exports_1, __moduleName) { "use strict"; function foo() { } function exportStar_1(m) { diff --git a/tests/baselines/reference/systemModule12.js b/tests/baselines/reference/systemModule12.js index d8961c3b001..04252396926 100644 --- a/tests/baselines/reference/systemModule12.js +++ b/tests/baselines/reference/systemModule12.js @@ -5,7 +5,7 @@ import n from 'file1' //// [systemModule12.js] -System.register("NamedModule", [], function(exports_1) { +System.register("NamedModule", [], function(exports_1, __moduleName) { "use strict"; return { setters:[], diff --git a/tests/baselines/reference/systemModule13.js b/tests/baselines/reference/systemModule13.js index 0b81a946de4..509534ee0fe 100644 --- a/tests/baselines/reference/systemModule13.js +++ b/tests/baselines/reference/systemModule13.js @@ -5,7 +5,7 @@ export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; for ([x] of [[1]]) {} //// [systemModule13.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x, y, z, z0, z1; return { diff --git a/tests/baselines/reference/systemModule14.js b/tests/baselines/reference/systemModule14.js index 2ec8fc600f4..af78af7f6b1 100644 --- a/tests/baselines/reference/systemModule14.js +++ b/tests/baselines/reference/systemModule14.js @@ -11,7 +11,7 @@ var x = 1; export {foo as b} //// [systemModule14.js] -System.register(["foo"], function(exports_1) { +System.register(["foo"], function(exports_1, __moduleName) { "use strict"; var foo_1; var x; diff --git a/tests/baselines/reference/systemModule15.js b/tests/baselines/reference/systemModule15.js index f8dc11b0ac7..f347ad59671 100644 --- a/tests/baselines/reference/systemModule15.js +++ b/tests/baselines/reference/systemModule15.js @@ -34,7 +34,7 @@ export default value; export var value2 = "v"; //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var value; return { @@ -46,7 +46,7 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var value2; return { @@ -57,7 +57,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register(["./file3"], function(exports_1) { +System.register(["./file3"], function(exports_1, __moduleName) { "use strict"; var moduleCStar, file3_1, file3_2; return { @@ -75,7 +75,7 @@ System.register(["./file3"], function(exports_1) { } }); //// [file1.js] -System.register(["./file2"], function(exports_1) { +System.register(["./file2"], function(exports_1, __moduleName) { "use strict"; var moduleB; return { diff --git a/tests/baselines/reference/systemModule16.js b/tests/baselines/reference/systemModule16.js index 76fb85cd3ae..0986218b65d 100644 --- a/tests/baselines/reference/systemModule16.js +++ b/tests/baselines/reference/systemModule16.js @@ -13,7 +13,7 @@ x,y,a1,b1,d1; //// [systemModule16.js] -System.register(["foo", "bar"], function(exports_1) { +System.register(["foo", "bar"], function(exports_1, __moduleName) { "use strict"; var x, y, foo_1; var exportedNames_1 = { diff --git a/tests/baselines/reference/systemModule17.js b/tests/baselines/reference/systemModule17.js index 6daa119d287..b441004408b 100644 --- a/tests/baselines/reference/systemModule17.js +++ b/tests/baselines/reference/systemModule17.js @@ -42,7 +42,7 @@ export {II}; export {II as II1}; //// [f1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var A; return { @@ -58,7 +58,7 @@ System.register([], function(exports_1) { } }); //// [f2.js] -System.register(["f1"], function(exports_1) { +System.register(["f1"], function(exports_1, __moduleName) { "use strict"; var f1_1; var x, N, IX; diff --git a/tests/baselines/reference/systemModule2.js b/tests/baselines/reference/systemModule2.js index ee3dfd327ec..78be2c008e4 100644 --- a/tests/baselines/reference/systemModule2.js +++ b/tests/baselines/reference/systemModule2.js @@ -4,7 +4,7 @@ var x = 1; export = x; //// [systemModule2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x; return { diff --git a/tests/baselines/reference/systemModule3.js b/tests/baselines/reference/systemModule3.js index dbef74f3036..9ccc5ea7894 100644 --- a/tests/baselines/reference/systemModule3.js +++ b/tests/baselines/reference/systemModule3.js @@ -18,7 +18,7 @@ export default class C {} export default class {} //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function default_1() { } exports_1("default", default_1); @@ -29,7 +29,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function f() { } exports_1("default", f); @@ -40,7 +40,7 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var C; return { @@ -56,7 +56,7 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var default_1; return { diff --git a/tests/baselines/reference/systemModule4.js b/tests/baselines/reference/systemModule4.js index 192c87d49ea..526ee5d2c3a 100644 --- a/tests/baselines/reference/systemModule4.js +++ b/tests/baselines/reference/systemModule4.js @@ -4,7 +4,7 @@ export var x = 1; export var y; //// [systemModule4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x, y; return { diff --git a/tests/baselines/reference/systemModule5.js b/tests/baselines/reference/systemModule5.js index 4a455f25b13..6d6a8e52823 100644 --- a/tests/baselines/reference/systemModule5.js +++ b/tests/baselines/reference/systemModule5.js @@ -4,7 +4,7 @@ export function foo() {} //// [systemModule5.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function foo() { } exports_1("foo", foo); diff --git a/tests/baselines/reference/systemModule6.js b/tests/baselines/reference/systemModule6.js index 51c8fbc68fb..d93b1b861e0 100644 --- a/tests/baselines/reference/systemModule6.js +++ b/tests/baselines/reference/systemModule6.js @@ -7,7 +7,7 @@ function foo() { //// [systemModule6.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var C; function foo() { diff --git a/tests/baselines/reference/systemModule7.js b/tests/baselines/reference/systemModule7.js index d76d86a3b0f..6abf76cf075 100644 --- a/tests/baselines/reference/systemModule7.js +++ b/tests/baselines/reference/systemModule7.js @@ -11,7 +11,7 @@ export module M { } //// [systemModule7.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var M; return { diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index b6cdd677f00..6d48a4a9d45 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -31,7 +31,7 @@ export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; for ([x] of [[1]]) {} //// [systemModule8.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var x, y, z0, z1; function foo() { diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index 137dd019a02..4804a08fd39 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -22,7 +22,7 @@ export {x}; export {y as z}; //// [systemModule9.js] -System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1) { +System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1, __moduleName) { "use strict"; var ns, file2_1, file3_1, file5_1, ns3; var x, y; diff --git a/tests/baselines/reference/systemModuleAmbientDeclarations.js b/tests/baselines/reference/systemModuleAmbientDeclarations.js index 9bdde23a842..35e48fe2aff 100644 --- a/tests/baselines/reference/systemModuleAmbientDeclarations.js +++ b/tests/baselines/reference/systemModuleAmbientDeclarations.js @@ -29,7 +29,7 @@ export declare module M { var v: number; } //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var promise, foo, c, e; return { @@ -44,7 +44,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -53,7 +53,7 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -62,7 +62,7 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -71,7 +71,7 @@ System.register([], function(exports_1) { } }); //// [file5.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], @@ -80,7 +80,7 @@ System.register([], function(exports_1) { } }); //// [file6.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; return { setters:[], diff --git a/tests/baselines/reference/systemModuleConstEnums.js b/tests/baselines/reference/systemModuleConstEnums.js index 8b8707768d9..abcd9ca5802 100644 --- a/tests/baselines/reference/systemModuleConstEnums.js +++ b/tests/baselines/reference/systemModuleConstEnums.js @@ -13,7 +13,7 @@ module M { } //// [systemModuleConstEnums.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function foo() { use(0 /* X */); diff --git a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js index 8466d399ac9..5eaa354bc2a 100644 --- a/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js +++ b/tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.js @@ -13,7 +13,7 @@ module M { } //// [systemModuleConstEnumsSeparateCompilation.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var TopLevelConstEnum, M; function foo() { diff --git a/tests/baselines/reference/systemModuleDeclarationMerging.js b/tests/baselines/reference/systemModuleDeclarationMerging.js index 5ed029a769a..68dec6f3805 100644 --- a/tests/baselines/reference/systemModuleDeclarationMerging.js +++ b/tests/baselines/reference/systemModuleDeclarationMerging.js @@ -10,7 +10,7 @@ export enum E {} export module E { var x; } //// [systemModuleDeclarationMerging.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var F, C, E; function F() { } diff --git a/tests/baselines/reference/systemModuleExportDefault.js b/tests/baselines/reference/systemModuleExportDefault.js index cf1a99a4ad7..05e23840a51 100644 --- a/tests/baselines/reference/systemModuleExportDefault.js +++ b/tests/baselines/reference/systemModuleExportDefault.js @@ -16,7 +16,7 @@ export default class C {} //// [file1.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function default_1() { } exports_1("default", default_1); @@ -27,7 +27,7 @@ System.register([], function(exports_1) { } }); //// [file2.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; function foo() { } exports_1("default", foo); @@ -38,7 +38,7 @@ System.register([], function(exports_1) { } }); //// [file3.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var default_1; return { @@ -54,7 +54,7 @@ System.register([], function(exports_1) { } }); //// [file4.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var C; return { diff --git a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js index ee9858a7fec..3bce3b662ae 100644 --- a/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js +++ b/tests/baselines/reference/systemModuleNonTopLevelModuleMembers.js @@ -13,7 +13,7 @@ export module TopLevelModule2 { } //// [systemModuleNonTopLevelModuleMembers.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var TopLevelClass, TopLevelModule, TopLevelEnum, TopLevelModule2; function TopLevelFunction() { } diff --git a/tests/baselines/reference/systemModuleWithSuperClass.js b/tests/baselines/reference/systemModuleWithSuperClass.js index fe9c2742f2d..21b262fd217 100644 --- a/tests/baselines/reference/systemModuleWithSuperClass.js +++ b/tests/baselines/reference/systemModuleWithSuperClass.js @@ -13,7 +13,7 @@ export class Bar extends Foo { } //// [foo.js] -System.register([], function(exports_1) { +System.register([], function(exports_1, __moduleName) { "use strict"; var Foo; return { @@ -29,7 +29,7 @@ System.register([], function(exports_1) { } }); //// [bar.js] -System.register(['./foo'], function(exports_1) { +System.register(['./foo'], function(exports_1, __moduleName) { "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; diff --git a/tests/baselines/reference/tsxPreserveEmit1.js b/tests/baselines/reference/tsxPreserveEmit1.js index 7ac6c18ebca..6d795c946c3 100644 --- a/tests/baselines/reference/tsxPreserveEmit1.js +++ b/tests/baselines/reference/tsxPreserveEmit1.js @@ -34,7 +34,7 @@ module M { //// [test.jsx] -define(["require", "exports", 'react-router'], function (require, exports, ReactRouter) { +define(["require", "exports", 'react', 'react-router'], function (require, exports, React, ReactRouter) { "use strict"; var Route = ReactRouter.Route; var routes1 = ; diff --git a/tests/baselines/reference/tsxPreserveEmit2.js b/tests/baselines/reference/tsxPreserveEmit2.js new file mode 100644 index 00000000000..6a87da7b285 --- /dev/null +++ b/tests/baselines/reference/tsxPreserveEmit2.js @@ -0,0 +1,10 @@ +//// [test.tsx] + + +var Route: any; +var routes1 = ; + + +//// [test.jsx] +var Route; +var routes1 = ; diff --git a/tests/baselines/reference/tsxPreserveEmit2.symbols b/tests/baselines/reference/tsxPreserveEmit2.symbols new file mode 100644 index 00000000000..4013b2e35ea --- /dev/null +++ b/tests/baselines/reference/tsxPreserveEmit2.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/jsx/test.tsx === + + +var Route: any; +>Route : Symbol(Route, Decl(test.tsx, 2, 3)) + +var routes1 = ; +>routes1 : Symbol(routes1, Decl(test.tsx, 3, 3)) +>Route : Symbol(Route, Decl(test.tsx, 2, 3)) + diff --git a/tests/baselines/reference/tsxPreserveEmit2.types b/tests/baselines/reference/tsxPreserveEmit2.types new file mode 100644 index 00000000000..c01f564ff53 --- /dev/null +++ b/tests/baselines/reference/tsxPreserveEmit2.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/jsx/test.tsx === + + +var Route: any; +>Route : any + +var routes1 = ; +>routes1 : any +> : any +>Route : any + diff --git a/tests/baselines/reference/tsxPreserveEmit3.js b/tests/baselines/reference/tsxPreserveEmit3.js new file mode 100644 index 00000000000..500b7d26c93 --- /dev/null +++ b/tests/baselines/reference/tsxPreserveEmit3.js @@ -0,0 +1,24 @@ +//// [tests/cases/conformance/jsx/tsxPreserveEmit3.tsx] //// + +//// [file.tsx] + +declare module JSX { + interface Element { } + interface IntrinsicElements { + [s: string]: any; + } +} + +//// [test.d.ts] +export var React; + +//// [react-consumer.tsx] +// This import should be elided +import {React} from "./test"; + + +//// [file.jsx] +//// [react-consumer.jsx] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); diff --git a/tests/baselines/reference/tsxPreserveEmit3.symbols b/tests/baselines/reference/tsxPreserveEmit3.symbols new file mode 100644 index 00000000000..ab534241049 --- /dev/null +++ b/tests/baselines/reference/tsxPreserveEmit3.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/jsx/file.tsx === + +declare module JSX { +>JSX : Symbol(JSX, Decl(file.tsx, 0, 0)) + + interface Element { } +>Element : Symbol(Element, Decl(file.tsx, 1, 20)) + + interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(file.tsx, 2, 22)) + + [s: string]: any; +>s : Symbol(s, Decl(file.tsx, 4, 3)) + } +} + +=== tests/cases/conformance/jsx/test.d.ts === +export var React; +>React : Symbol(React, Decl(test.d.ts, 0, 10)) + +=== tests/cases/conformance/jsx/react-consumer.tsx === +// This import should be elided +import {React} from "./test"; +>React : Symbol(React, Decl(react-consumer.tsx, 1, 8)) + diff --git a/tests/baselines/reference/tsxPreserveEmit3.types b/tests/baselines/reference/tsxPreserveEmit3.types new file mode 100644 index 00000000000..152f742a240 --- /dev/null +++ b/tests/baselines/reference/tsxPreserveEmit3.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/jsx/file.tsx === + +declare module JSX { +>JSX : any + + interface Element { } +>Element : Element + + interface IntrinsicElements { +>IntrinsicElements : IntrinsicElements + + [s: string]: any; +>s : string + } +} + +=== tests/cases/conformance/jsx/test.d.ts === +export var React; +>React : any + +=== tests/cases/conformance/jsx/react-consumer.tsx === +// This import should be elided +import {React} from "./test"; +>React : any + diff --git a/tests/baselines/reference/tsxReactEmitEntities.js b/tests/baselines/reference/tsxReactEmitEntities.js index c1fba50fd8f..a20f3380bf7 100644 --- a/tests/baselines/reference/tsxReactEmitEntities.js +++ b/tests/baselines/reference/tsxReactEmitEntities.js @@ -8,7 +8,9 @@ declare module JSX { declare var React: any;
Dot goes here: · ¬AnEntity;
; +
Be careful of "-ed strings!
; //// [file.js] React.createElement("div", null, "Dot goes here: ยท ¬AnEntity; "); +React.createElement("div", null, "Be careful of \"-ed strings!"); diff --git a/tests/baselines/reference/tsxReactEmitEntities.symbols b/tests/baselines/reference/tsxReactEmitEntities.symbols index b633f57ec13..5a0274029e4 100644 --- a/tests/baselines/reference/tsxReactEmitEntities.symbols +++ b/tests/baselines/reference/tsxReactEmitEntities.symbols @@ -19,3 +19,7 @@ declare var React: any; >div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 1, 22)) >div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 1, 22)) +
Be careful of "-ed strings!
; +>div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 1, 22)) +>div : Symbol(JSX.IntrinsicElements, Decl(file.tsx, 1, 22)) + diff --git a/tests/baselines/reference/tsxReactEmitEntities.types b/tests/baselines/reference/tsxReactEmitEntities.types index d6d6c285d79..111653ea140 100644 --- a/tests/baselines/reference/tsxReactEmitEntities.types +++ b/tests/baselines/reference/tsxReactEmitEntities.types @@ -20,3 +20,8 @@ declare var React: any; >div : any >div : any +
Be careful of "-ed strings!
; +>
Be careful of "-ed strings!
: JSX.Element +>div : any +>div : any + diff --git a/tests/cases/conformance/jsx/tsxPreserveEmit2.tsx b/tests/cases/conformance/jsx/tsxPreserveEmit2.tsx new file mode 100644 index 00000000000..978c96a2019 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxPreserveEmit2.tsx @@ -0,0 +1,8 @@ +//@module: amd +//@jsx: preserve +//@target: ES5 + +//@Filename: test.tsx + +var Route: any; +var routes1 = ; diff --git a/tests/cases/conformance/jsx/tsxPreserveEmit3.tsx b/tests/cases/conformance/jsx/tsxPreserveEmit3.tsx new file mode 100644 index 00000000000..d7565cacbe2 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxPreserveEmit3.tsx @@ -0,0 +1,17 @@ +//@jsx: preserve +//@module: amd + +//@filename: file.tsx +declare module JSX { + interface Element { } + interface IntrinsicElements { + [s: string]: any; + } +} + +//@filename: test.d.ts +export var React; + +//@filename: react-consumer.tsx +// This import should be elided +import {React} from "./test"; diff --git a/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx b/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx index 4b7dc5780f8..4726008d6be 100644 --- a/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx @@ -9,3 +9,4 @@ declare module JSX { declare var React: any;
Dot goes here: · ¬AnEntity;
; +
Be careful of "-ed strings!
; diff --git a/tests/cases/fourslash/formattingJsxElements.ts b/tests/cases/fourslash/formattingJsxElements.ts index fd4ccc504a4..fbe4bb5d29e 100644 --- a/tests/cases/fourslash/formattingJsxElements.ts +++ b/tests/cases/fourslash/formattingJsxElements.ts @@ -9,7 +9,7 @@ //// //// ) ////} -//// +//// ////function foo1() { //// return ( ////
@@ -45,8 +45,26 @@ //// class3= {/*5*/ //// }/>/*6*/ //// ) +////} +//// +////(function () { +//// return
/*danglingBracketAutoformat*/ +////
/*closingTagAutoformat*/ +////}) +//// +////let h5 =
+/////*childJsxElementAutoformat*/ +/////*childJsxElementIndent*/ +/////*grandchildJsxElementAutoformat*/ +/////*containedClosingTagAutoformat*/ +////
format.document(); goTo.marker("autoformat"); @@ -83,3 +101,28 @@ goTo.marker("5"); verify.currentLineContentIs(' class3= {'); goTo.marker("6"); verify.currentLineContentIs(' }/>'); + + +goTo.marker("attrAutoformat"); +verify.currentLineContentIs(' className=""'); +goTo.marker("attrIndent"); +verify.indentationIs(8); +goTo.marker("expressionAutoformat"); +verify.currentLineContentIs(' "abc" + "cde"'); +goTo.marker("expressionIndent"); +verify.indentationIs(12); + +goTo.marker("danglingBracketAutoformat") +// TODO: verify.currentLineContentIs(" >"); +verify.currentLineContentIs(" >"); +goTo.marker("closingTagAutoformat"); +verify.currentLineContentIs("
"); + +goTo.marker("childJsxElementAutoformat"); +verify.currentLineContentIs(" "); +goTo.marker("childJsxElementIndent"); +verify.indentationIs(8); +goTo.marker("grandchildJsxElementAutoformat"); +verify.currentLineContentIs(" "); +goTo.marker("containedClosingTagAutoformat"); +verify.currentLineContentIs(" "); \ No newline at end of file diff --git a/tests/cases/unittests/transpile.ts b/tests/cases/unittests/transpile.ts index 513d37673bb..882b4e2094b 100644 --- a/tests/cases/unittests/transpile.ts +++ b/tests/cases/unittests/transpile.ts @@ -134,7 +134,7 @@ var x = 0;`, it("Sets module name", () => { let output = - `System.register("NamedModule", [], function(exports_1) {\n "use strict";\n var x;\n` + + `System.register("NamedModule", [], function(exports_1, __moduleName) {\n "use strict";\n var x;\n` + ` return {\n` + ` setters:[],\n` + ` execute: function() {\n` + @@ -159,7 +159,7 @@ var x = 0;`, `declare function use(a: any);\n` + `use(foo);` let output = - `System.register(["SomeOtherName"], function(exports_1) {\n` + + `System.register(["SomeOtherName"], function(exports_1, __moduleName) {\n` + ` "use strict";\n` + ` var SomeName_1;\n` + ` return {\n` + diff --git a/tslint.json b/tslint.json index 71efb21ad7b..2d2e42d4383 100644 --- a/tslint.json +++ b/tslint.json @@ -42,6 +42,7 @@ "boolean-trivia": true, "type-operator-spacing": true, "prefer-const": true, - "no-in-operator": true + "no-in-operator": true, + "no-increment-decrement": true } }