diff --git a/.travis.yml b/.travis.yml index b31d1f10da0..989924dc32c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,10 @@ node_js: - '0.10' sudo: false + +os: + - linux + - osx + +matrix: + fast_finish: true diff --git a/Gulpfile.ts b/Gulpfile.ts index 0305f754111..57da2b62aa8 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -694,6 +694,12 @@ gulp.task(nodeServerOutFile, false, [servicesFile], () => { .pipe(gulp.dest(path.dirname(nodeServerOutFile))); }); +import convertMap = require("convert-source-map"); +import sorcery = require("sorcery"); +declare module "convert-source-map" { + export function fromSource(source: string, largeSource?: boolean): SourceMapConverter; +} + gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => { const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "built/local/bundle.js" }, /*useBuiltCompiler*/ true)); return testProject.src() @@ -701,14 +707,37 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo .pipe(sourcemaps.init()) .pipe(tsc(testProject)) .pipe(through2.obj((file, enc, next) => { - browserify(intoStream(file.contents)) + const originalMap = file.sourceMap; + const prebundledContent = file.contents.toString(); + // Make paths absolute to help sorcery deal with all the terrible paths being thrown around + originalMap.sources = originalMap.sources.map(s => path.resolve(s)); + // intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap + originalMap.file = "built/local/_stream_0.js"; + + browserify(intoStream(file.contents), { debug: true }) .bundle((err, res) => { // assumes file.contents is a Buffer - file.contents = res; + const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/true).toJSON()); + delete maps.sourceRoot; + maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s)); + // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths) + file.contents = new Buffer(convertMap.removeComments(res.toString())); + const chain = sorcery.loadSync("built/local/bundle.js", { + content: { + "built/local/_stream_0.js": prebundledContent, + "built/local/bundle.js": file.contents.toString() + }, + sourcemaps: { + "built/local/_stream_0.js": originalMap, + "built/local/bundle.js": maps, + } + }); + const finalMap = chain.apply(); + file.sourceMap = finalMap; next(undefined, file); }); })) - .pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" })) + .pipe(sourcemaps.write(".", { includeContent: false })) .pipe(gulp.dest(".")); }); diff --git a/Jakefile.js b/Jakefile.js index eee9fe1370e..3ccca833333 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -34,6 +34,7 @@ if (process.env.path !== undefined) { var compilerSources = [ "core.ts", + "performance.ts", "sys.ts", "types.ts", "scanner.ts", @@ -54,6 +55,7 @@ var compilerSources = [ var servicesSources = [ "core.ts", + "performance.ts", "sys.ts", "types.ts", "scanner.ts", @@ -466,15 +468,6 @@ task("publish-nightly", ["configure-nightly", "LKG", "clean", "setDebugMode", "r exec(cmd); }); -var scriptsTsdJson = path.join(scriptsDirectory, "tsd.json"); -file(scriptsTsdJson); - -task("tsd-scripts", [scriptsTsdJson], function () { - var cmd = "tsd --config " + scriptsTsdJson + " install"; - console.log(cmd); - exec(cmd); -}, { async: true }); - var importDefinitelyTypedTestsDirectory = path.join(scriptsDirectory, "importDefinitelyTypedTests"); var importDefinitelyTypedTestsJs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.js"); var importDefinitelyTypedTestsTs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.ts"); diff --git a/lib/tsc.js b/lib/tsc.js index 0e3d7285ac3..05a903f9014 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -825,10 +825,17 @@ var ts; return true; } ts.containsPath = containsPath; + function startsWith(str, prefix) { + return str.lastIndexOf(prefix, 0) === 0; + } + ts.startsWith = startsWith; + function endsWith(str, suffix) { + var expectedPos = str.length - suffix.length; + return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; + } + ts.endsWith = endsWith; function fileExtensionIs(path, extension) { - var pathLen = path.length; - var extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; + return path.length > extension.length && endsWith(path, extension); } ts.fileExtensionIs = fileExtensionIs; function fileExtensionIsAny(path, extensions) { @@ -1093,6 +1100,8 @@ var ts; } ts.objectAllocator = { getNodeConstructor: function () { return Node; }, + getTokenConstructor: function () { return Node; }, + getIdentifierConstructor: function () { return Node; }, getSourceFileConstructor: function () { return Node; }, getSymbolConstructor: function () { return Symbol; }, getTypeConstructor: function () { return Type; }, @@ -1224,7 +1233,7 @@ var ts; function readDirectory(path, extensions, excludes, includes) { return ts.matchFiles(path, extensions, excludes, includes, false, shell.CurrentDirectory, getAccessibleFileSystemEntries); } - return { + var wscriptSystem = { args: args, newLine: "\r\n", useCaseSensitiveFileNames: false, @@ -1243,7 +1252,7 @@ var ts; return fso.FolderExists(path); }, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!wscriptSystem.directoryExists(directoryName)) { fso.CreateFolder(directoryName); } }, @@ -1263,6 +1272,7 @@ var ts; } } }; + return wscriptSystem; } function getNodeSystem() { var _fs = require("fs"); @@ -1435,7 +1445,7 @@ var ts; function getDirectories(path) { return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); } - return { + var nodeSystem = { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, @@ -1485,7 +1495,7 @@ var ts; fileExists: fileExists, directoryExists: directoryExists, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!nodeSystem.directoryExists(directoryName)) { _fs.mkdirSync(directoryName); } }, @@ -1533,6 +1543,7 @@ var ts; return _fs.realpathSync(path); } }; + return nodeSystem; } function getChakraSystem() { var realpath = ChakraHost.realpath && (function (path) { return ChakraHost.realpath(path); }); @@ -2282,8 +2293,8 @@ var ts; Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, - Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, - Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, + Report_errors_on_unused_locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_locals_6134", message: "Report errors on unused locals." }, + Report_errors_on_unused_parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_parameters_6135", message: "Report errors on unused parameters." }, The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files: { code: 6136, category: ts.DiagnosticCategory.Message, key: "The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files_6136", message: "The maximum dependency depth to search under node_modules and load JavaScript files" }, No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0: { code: 6137, category: ts.DiagnosticCategory.Message, key: "No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0_6137", message: "No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, @@ -4836,7 +4847,7 @@ var ts; } ts.isExpression = isExpression; function isExternalModuleNameRelative(moduleName) { - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + return /^\.\.?($|[\\/])/.test(moduleName); } ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { @@ -6344,25 +6355,24 @@ var ts; return node.flags & 92 && node.parent.kind === 148 && ts.isClassLike(node.parent.parent); } ts.isParameterPropertyDeclaration = isParameterPropertyDeclaration; - function startsWith(str, prefix) { - return str.lastIndexOf(prefix, 0) === 0; - } - ts.startsWith = startsWith; - function endsWith(str, suffix) { - var expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - ts.endsWith = endsWith; })(ts || (ts = {})); var ts; (function (ts) { ts.parseTime = 0; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; function createNode(kind, pos, end) { if (kind === 256) { return new (SourceFileConstructor || (SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor()))(kind, pos, end); } + else if (kind === 69) { + return new (IdentifierConstructor || (IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor()))(kind, pos, end); + } + else if (kind < 139) { + return new (TokenConstructor || (TokenConstructor = ts.objectAllocator.getTokenConstructor()))(kind, pos, end); + } else { return new (NodeConstructor || (NodeConstructor = ts.objectAllocator.getNodeConstructor()))(kind, pos, end); } @@ -6785,6 +6795,8 @@ var ts; var scanner = ts.createScanner(2, true); var disallowInAndDecoratorContext = 4194304 | 16777216; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; var sourceFile; var parseDiagnostics; @@ -6810,6 +6822,8 @@ var ts; } function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind) { NodeConstructor = ts.objectAllocator.getNodeConstructor(); + TokenConstructor = ts.objectAllocator.getTokenConstructor(); + IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor(); SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor(); sourceText = _sourceText; syntaxCursor = _syntaxCursor; @@ -7116,7 +7130,9 @@ var ts; if (!(pos >= 0)) { pos = scanner.getStartPos(); } - return new NodeConstructor(kind, pos, pos); + return kind >= 139 ? new NodeConstructor(kind, pos, pos) : + kind === 69 ? new IdentifierConstructor(kind, pos, pos) : + new TokenConstructor(kind, pos, pos); } function finishNode(node, end) { node.end = end === undefined ? scanner.getStartPos() : end; @@ -10892,6 +10908,9 @@ var ts; case 55: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); + if (!parentTagTerminated) { + resumePos = scanner.getStartPos(); + } } seenAsterisk = false; break; @@ -15418,17 +15437,18 @@ var ts; if (declaration.kind === 235) { return links.type = checkExpression(declaration.expression); } + if (declaration.flags & 134217728 && declaration.kind === 280 && declaration.typeExpression) { + return links.type = getTypeFromTypeNode(declaration.typeExpression.type); + } if (!pushTypeResolution(symbol, 0)) { return unknownType; } var type = undefined; - if (declaration.kind === 187) { - type = getUnionType(ts.map(symbol.declarations, function (decl) { return checkExpressionCached(decl.right); })); - } - else if (declaration.kind === 172) { - if (declaration.parent.kind === 187) { - type = checkExpressionCached(declaration.parent.right); - } + if (declaration.kind === 187 || + declaration.kind === 172 && declaration.parent.kind === 187) { + type = getUnionType(ts.map(symbol.declarations, function (decl) { return decl.kind === 187 ? + checkExpressionCached(decl.right) : + checkExpressionCached(decl.parent.right); })); } if (type === undefined) { type = getWidenedTypeForVariableLikeDeclaration(declaration, true); @@ -21935,7 +21955,7 @@ var ts; function getInferredClassType(symbol) { var links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, undefined, undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, undefined, undefined); } return links.inferredClassType; } @@ -23155,7 +23175,7 @@ var ts; checkAsyncFunctionReturnType(node); } } - if (!node.body) { + if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } @@ -24051,6 +24071,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -24066,6 +24087,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 && parameter.name.text.charCodeAt(0) === 95; } @@ -24094,9 +24118,14 @@ var ts; function checkUnusedTypeParameters(node) { if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { if (node.typeParameters) { + var symbol = getSymbolOfNode(node); + var lastDeclaration = symbol && symbol.declarations && ts.lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { var typeParameter = _a[_i]; - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -25173,7 +25202,7 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } function checkTypeAliasDeclaration(node) { @@ -29896,7 +29925,7 @@ var ts; writeLine(); var sourceMappingURL = sourceMap.getSourceMappingURL(); if (sourceMappingURL) { - write("//# sourceMappingURL=" + sourceMappingURL); + write("//# " + "sourceMappingURL" + "=" + sourceMappingURL); } writeEmittedFiles(writer.getText(), jsFilePath, sourceMapFilePath, compilerOptions.emitBOM, sourceFiles); sourceMap.reset(); @@ -33546,13 +33575,13 @@ var ts; if (isES6ExportedDeclaration(node) && !(node.flags & 512) && decoratedClassAlias === undefined) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write("" + decoratedClassAlias); + write("let " + decoratedClassAlias); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } write(" = "); @@ -35796,7 +35825,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "2.0.0"; + ts.version = "2.1.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -35876,12 +35905,7 @@ var ts; return { resolvedModule: resolvedFileName ? { resolvedFileName: resolvedFileName, isExternalLibraryImport: isExternalLibraryImport } : undefined, failedLookupLocations: failedLookupLocations }; } function moduleHasNonRelativeName(moduleName) { - if (ts.isRootedDiskPath(moduleName)) { - return false; - } - var i = moduleName.lastIndexOf("./", 1); - var startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === 46); - return !startsWithDotSlashOrDotDotSlash; + return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } function tryReadTypesSection(packageJsonPath, baseDirectory, state) { var jsonContent; @@ -36537,6 +36561,22 @@ var ts; return ts.sortAndDeduplicateDiagnostics(diagnostics); } ts.getPreEmitDiagnostics = getPreEmitDiagnostics; + function formatDiagnostics(diagnostics, host) { + var output = ""; + for (var _i = 0, diagnostics_1 = diagnostics; _i < diagnostics_1.length; _i++) { + var diagnostic = diagnostics_1[_i]; + if (diagnostic.file) { + var _a = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), line = _a.line, character = _a.character; + var fileName = diagnostic.file.fileName; + var relativeFileName = ts.convertToRelativePath(fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }); + output += relativeFileName + "(" + (line + 1) + "," + (character + 1) + "): "; + } + var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); + output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) + host.getNewLine(); + } + return output; + } + ts.formatDiagnostics = formatDiagnostics; function flattenDiagnosticMessageText(messageText, newLine) { if (typeof messageText === "string") { return messageText; @@ -36612,7 +36652,7 @@ var ts; var resolvedTypeReferenceDirectives = {}; var fileProcessingDiagnostics = ts.createDiagnosticCollection(); var maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2; - var currentNodeModulesJsDepth = 0; + var currentNodeModulesDepth = 0; var modulesWithElidedImports = {}; var sourceFilesFoundSearchingNodeModules = {}; var start = new Date().getTime(); @@ -36836,8 +36876,7 @@ var ts; return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, false)); } function emit(sourceFile, writeFileCallback, cancellationToken) { - var _this = this; - return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); }); + return runWithCancellationToken(function () { return emitWorker(program, sourceFile, writeFileCallback, cancellationToken); }); } function isEmitBlocked(emitFileName) { return hasEmitBlockingDiagnostics.contains(ts.toPath(emitFileName, currentDirectory, getCanonicalFileName)); @@ -37244,8 +37283,17 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { - if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) { + if (file_1 && ts.lookUp(sourceFilesFoundSearchingNodeModules, file_1.path) && currentNodeModulesDepth == 0) { + sourceFilesFoundSearchingNodeModules[file_1.path] = false; + if (!options.noResolve) { + processReferencedFiles(file_1, ts.getDirectoryPath(fileName), isDefaultLib); + processTypeReferenceDirectives(file_1); + } + modulesWithElidedImports[file_1.path] = false; + processImportedModules(file_1, ts.getDirectoryPath(fileName)); + } + else if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { + if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file_1.path] = false; processImportedModules(file_1, ts.getDirectoryPath(fileName)); } @@ -37262,6 +37310,7 @@ var ts; }); filesByName.set(path, file); if (file) { + sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0); file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -37362,12 +37411,9 @@ var ts; var isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport; var isJsFileFromNodeModules = isFromNodeModulesSearch && ts.hasJavaScriptFileExtension(resolution.resolvedFileName); if (isFromNodeModulesSearch) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; + currentNodeModulesDepth++; } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth++; - } - var elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth; + var elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; var shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; if (elideImport) { modulesWithElidedImports[file.path] = true; @@ -37375,8 +37421,8 @@ var ts; else if (shouldAddFile) { findSourceFile(resolution.resolvedFileName, resolvedPath, false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth--; + if (isFromNodeModulesSearch) { + currentNodeModulesDepth--; } } } @@ -37695,12 +37741,12 @@ var ts; { name: "noUnusedLocals", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Locals + description: ts.Diagnostics.Report_errors_on_unused_locals }, { name: "noUnusedParameters", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + description: ts.Diagnostics.Report_errors_on_unused_parameters }, { name: "noLib", @@ -38479,10 +38525,18 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - var reportDiagnostic = reportDiagnosticSimply; + var defaultFormatDiagnosticsHost = { + getCurrentDirectory: function () { return ts.sys.getCurrentDirectory(); }, + getNewLine: function () { return ts.sys.newLine; }, + getCanonicalFileName: ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames) + }; + var reportDiagnosticWorker = reportDiagnosticSimply; + function reportDiagnostic(diagnostic, host) { + reportDiagnosticWorker(diagnostic, host || defaultFormatDiagnosticsHost); + } function reportDiagnostics(diagnostics, host) { - for (var _i = 0, diagnostics_1 = diagnostics; _i < diagnostics_1.length; _i++) { - var diagnostic = diagnostics_1[_i]; + for (var _i = 0, diagnostics_2 = diagnostics; _i < diagnostics_2.length; _i++) { + var diagnostic = diagnostics_2[_i]; reportDiagnostic(diagnostic, host); } } @@ -38553,19 +38607,8 @@ var ts; var diagnostic = ts.createCompilerDiagnostic.apply(undefined, arguments); return diagnostic.messageText; } - function getRelativeFileName(fileName, host) { - return host ? ts.convertToRelativePath(fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }) : fileName; - } function reportDiagnosticSimply(diagnostic, host) { - var output = ""; - if (diagnostic.file) { - var _a = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), line = _a.line, character = _a.character; - var relativeFileName = getRelativeFileName(diagnostic.file.fileName, host); - output += relativeFileName + "(" + (line + 1) + "," + (character + 1) + "): "; - } - var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); - output += category + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine; - ts.sys.write(output); + ts.sys.write(ts.formatDiagnostics([diagnostic], host)); } var redForegroundEscapeSequence = "\u001b[91m"; var yellowForegroundEscapeSequence = "\u001b[93m"; @@ -38590,7 +38633,7 @@ var ts; var _a = ts.getLineAndCharacterOfPosition(file, start), firstLine = _a.line, firstLineChar = _a.character; var _b = ts.getLineAndCharacterOfPosition(file, start + length_3), lastLine = _b.line, lastLineChar = _b.character; var lastLineInFile = ts.getLineAndCharacterOfPosition(file, file.text.length).line; - var relativeFileName = getRelativeFileName(file.fileName, host); + var relativeFileName = host ? ts.convertToRelativePath(file.fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }) : file.fileName; var hasMoreThanFiveLines = (lastLine - firstLine) >= 4; var gutterWidth = (lastLine + 1 + "").length; if (hasMoreThanFiveLines) { @@ -38779,7 +38822,8 @@ var ts; ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); return; } - var configParseResult = ts.parseJsonConfigFileContent(configObject, ts.sys, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), ts.sys.getCurrentDirectory()), commandLine.options, configFileName); + var cwd = ts.sys.getCurrentDirectory(); + var configParseResult = ts.parseJsonConfigFileContent(configObject, ts.sys, ts.getNormalizedAbsolutePath(ts.getDirectoryPath(configFileName), cwd), commandLine.options, ts.getNormalizedAbsolutePath(configFileName, cwd)); if (configParseResult.errors.length > 0) { reportDiagnostics(configParseResult.errors, undefined); ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsSkipped); @@ -38816,7 +38860,7 @@ var ts; compilerHost.fileExists = cachedFileExists; } if (compilerOptions.pretty) { - reportDiagnostic = reportDiagnosticWithColorAndContext; + reportDiagnosticWorker = reportDiagnosticWithColorAndContext; } cachedExistingFiles = {}; var compileResult = compile(rootFileNames, compilerOptions, compilerHost); @@ -38979,7 +39023,7 @@ var ts; output += ts.sys.newLine + ts.sys.newLine; var padding = makePadding(marginLength); output += getDiagnosticText(ts.Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + ts.sys.newLine; - output += padding + "tsc --out file.js file.ts" + ts.sys.newLine; + output += padding + "tsc --outFile file.js file.ts" + ts.sys.newLine; output += padding + "tsc @args.txt" + ts.sys.newLine; output += ts.sys.newLine; output += getDiagnosticText(ts.Diagnostics.Options_Colon) + ts.sys.newLine; diff --git a/lib/tsserver.js b/lib/tsserver.js index af6ee897902..7e0dda1736e 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -830,10 +830,17 @@ var ts; return true; } ts.containsPath = containsPath; + function startsWith(str, prefix) { + return str.lastIndexOf(prefix, 0) === 0; + } + ts.startsWith = startsWith; + function endsWith(str, suffix) { + var expectedPos = str.length - suffix.length; + return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; + } + ts.endsWith = endsWith; function fileExtensionIs(path, extension) { - var pathLen = path.length; - var extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; + return path.length > extension.length && endsWith(path, extension); } ts.fileExtensionIs = fileExtensionIs; function fileExtensionIsAny(path, extensions) { @@ -1098,6 +1105,8 @@ var ts; } ts.objectAllocator = { getNodeConstructor: function () { return Node; }, + getTokenConstructor: function () { return Node; }, + getIdentifierConstructor: function () { return Node; }, getSourceFileConstructor: function () { return Node; }, getSymbolConstructor: function () { return Symbol; }, getTypeConstructor: function () { return Type; }, @@ -1229,7 +1238,7 @@ var ts; function readDirectory(path, extensions, excludes, includes) { return ts.matchFiles(path, extensions, excludes, includes, false, shell.CurrentDirectory, getAccessibleFileSystemEntries); } - return { + var wscriptSystem = { args: args, newLine: "\r\n", useCaseSensitiveFileNames: false, @@ -1248,7 +1257,7 @@ var ts; return fso.FolderExists(path); }, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!wscriptSystem.directoryExists(directoryName)) { fso.CreateFolder(directoryName); } }, @@ -1268,6 +1277,7 @@ var ts; } } }; + return wscriptSystem; } function getNodeSystem() { var _fs = require("fs"); @@ -1440,7 +1450,7 @@ var ts; function getDirectories(path) { return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); } - return { + var nodeSystem = { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, @@ -1490,7 +1500,7 @@ var ts; fileExists: fileExists, directoryExists: directoryExists, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!nodeSystem.directoryExists(directoryName)) { _fs.mkdirSync(directoryName); } }, @@ -1538,6 +1548,7 @@ var ts; return _fs.realpathSync(path); } }; + return nodeSystem; } function getChakraSystem() { var realpath = ChakraHost.realpath && (function (path) { return ChakraHost.realpath(path); }); @@ -2287,8 +2298,8 @@ var ts; Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, - Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, - Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, + Report_errors_on_unused_locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_locals_6134", message: "Report errors on unused locals." }, + Report_errors_on_unused_parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_parameters_6135", message: "Report errors on unused parameters." }, The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files: { code: 6136, category: ts.DiagnosticCategory.Message, key: "The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files_6136", message: "The maximum dependency depth to search under node_modules and load JavaScript files" }, No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0: { code: 6137, category: ts.DiagnosticCategory.Message, key: "No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0_6137", message: "No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, @@ -3966,12 +3977,12 @@ var ts; { name: "noUnusedLocals", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Locals + description: ts.Diagnostics.Report_errors_on_unused_locals }, { name: "noUnusedParameters", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + description: ts.Diagnostics.Report_errors_on_unused_parameters }, { name: "noLib", @@ -5754,7 +5765,7 @@ var ts; } ts.isExpression = isExpression; function isExternalModuleNameRelative(moduleName) { - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + return /^\.\.?($|[\\/])/.test(moduleName); } ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { @@ -7262,25 +7273,24 @@ var ts; return node.flags & 92 && node.parent.kind === 148 && ts.isClassLike(node.parent.parent); } ts.isParameterPropertyDeclaration = isParameterPropertyDeclaration; - function startsWith(str, prefix) { - return str.lastIndexOf(prefix, 0) === 0; - } - ts.startsWith = startsWith; - function endsWith(str, suffix) { - var expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - ts.endsWith = endsWith; })(ts || (ts = {})); var ts; (function (ts) { ts.parseTime = 0; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; function createNode(kind, pos, end) { if (kind === 256) { return new (SourceFileConstructor || (SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor()))(kind, pos, end); } + else if (kind === 69) { + return new (IdentifierConstructor || (IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor()))(kind, pos, end); + } + else if (kind < 139) { + return new (TokenConstructor || (TokenConstructor = ts.objectAllocator.getTokenConstructor()))(kind, pos, end); + } else { return new (NodeConstructor || (NodeConstructor = ts.objectAllocator.getNodeConstructor()))(kind, pos, end); } @@ -7703,6 +7713,8 @@ var ts; var scanner = ts.createScanner(2, true); var disallowInAndDecoratorContext = 4194304 | 16777216; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; var sourceFile; var parseDiagnostics; @@ -7728,6 +7740,8 @@ var ts; } function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind) { NodeConstructor = ts.objectAllocator.getNodeConstructor(); + TokenConstructor = ts.objectAllocator.getTokenConstructor(); + IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor(); SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor(); sourceText = _sourceText; syntaxCursor = _syntaxCursor; @@ -8034,7 +8048,9 @@ var ts; if (!(pos >= 0)) { pos = scanner.getStartPos(); } - return new NodeConstructor(kind, pos, pos); + return kind >= 139 ? new NodeConstructor(kind, pos, pos) : + kind === 69 ? new IdentifierConstructor(kind, pos, pos) : + new TokenConstructor(kind, pos, pos); } function finishNode(node, end) { node.end = end === undefined ? scanner.getStartPos() : end; @@ -11810,6 +11826,9 @@ var ts; case 55: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); + if (!parentTagTerminated) { + resumePos = scanner.getStartPos(); + } } seenAsterisk = false; break; @@ -16336,17 +16355,18 @@ var ts; if (declaration.kind === 235) { return links.type = checkExpression(declaration.expression); } + if (declaration.flags & 134217728 && declaration.kind === 280 && declaration.typeExpression) { + return links.type = getTypeFromTypeNode(declaration.typeExpression.type); + } if (!pushTypeResolution(symbol, 0)) { return unknownType; } var type = undefined; - if (declaration.kind === 187) { - type = getUnionType(ts.map(symbol.declarations, function (decl) { return checkExpressionCached(decl.right); })); - } - else if (declaration.kind === 172) { - if (declaration.parent.kind === 187) { - type = checkExpressionCached(declaration.parent.right); - } + if (declaration.kind === 187 || + declaration.kind === 172 && declaration.parent.kind === 187) { + type = getUnionType(ts.map(symbol.declarations, function (decl) { return decl.kind === 187 ? + checkExpressionCached(decl.right) : + checkExpressionCached(decl.parent.right); })); } if (type === undefined) { type = getWidenedTypeForVariableLikeDeclaration(declaration, true); @@ -22853,7 +22873,7 @@ var ts; function getInferredClassType(symbol) { var links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, undefined, undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, undefined, undefined); } return links.inferredClassType; } @@ -24073,7 +24093,7 @@ var ts; checkAsyncFunctionReturnType(node); } } - if (!node.body) { + if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } @@ -24969,6 +24989,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -24984,6 +25005,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 && parameter.name.text.charCodeAt(0) === 95; } @@ -25012,9 +25036,14 @@ var ts; function checkUnusedTypeParameters(node) { if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { if (node.typeParameters) { + var symbol = getSymbolOfNode(node); + var lastDeclaration = symbol && symbol.declarations && ts.lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { var typeParameter = _a[_i]; - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -26091,7 +26120,7 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } function checkTypeAliasDeclaration(node) { @@ -30814,7 +30843,7 @@ var ts; writeLine(); var sourceMappingURL = sourceMap.getSourceMappingURL(); if (sourceMappingURL) { - write("//# sourceMappingURL=" + sourceMappingURL); + write("//# " + "sourceMappingURL" + "=" + sourceMappingURL); } writeEmittedFiles(writer.getText(), jsFilePath, sourceMapFilePath, compilerOptions.emitBOM, sourceFiles); sourceMap.reset(); @@ -34464,13 +34493,13 @@ var ts; if (isES6ExportedDeclaration(node) && !(node.flags & 512) && decoratedClassAlias === undefined) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write("" + decoratedClassAlias); + write("let " + decoratedClassAlias); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } write(" = "); @@ -36714,7 +36743,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "2.0.0"; + ts.version = "2.1.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -36794,12 +36823,7 @@ var ts; return { resolvedModule: resolvedFileName ? { resolvedFileName: resolvedFileName, isExternalLibraryImport: isExternalLibraryImport } : undefined, failedLookupLocations: failedLookupLocations }; } function moduleHasNonRelativeName(moduleName) { - if (ts.isRootedDiskPath(moduleName)) { - return false; - } - var i = moduleName.lastIndexOf("./", 1); - var startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === 46); - return !startsWithDotSlashOrDotDotSlash; + return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } function tryReadTypesSection(packageJsonPath, baseDirectory, state) { var jsonContent; @@ -37455,6 +37479,22 @@ var ts; return ts.sortAndDeduplicateDiagnostics(diagnostics); } ts.getPreEmitDiagnostics = getPreEmitDiagnostics; + function formatDiagnostics(diagnostics, host) { + var output = ""; + for (var _i = 0, diagnostics_1 = diagnostics; _i < diagnostics_1.length; _i++) { + var diagnostic = diagnostics_1[_i]; + if (diagnostic.file) { + var _a = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), line = _a.line, character = _a.character; + var fileName = diagnostic.file.fileName; + var relativeFileName = ts.convertToRelativePath(fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }); + output += relativeFileName + "(" + (line + 1) + "," + (character + 1) + "): "; + } + var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); + output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) + host.getNewLine(); + } + return output; + } + ts.formatDiagnostics = formatDiagnostics; function flattenDiagnosticMessageText(messageText, newLine) { if (typeof messageText === "string") { return messageText; @@ -37530,7 +37570,7 @@ var ts; var resolvedTypeReferenceDirectives = {}; var fileProcessingDiagnostics = ts.createDiagnosticCollection(); var maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2; - var currentNodeModulesJsDepth = 0; + var currentNodeModulesDepth = 0; var modulesWithElidedImports = {}; var sourceFilesFoundSearchingNodeModules = {}; var start = new Date().getTime(); @@ -37754,8 +37794,7 @@ var ts; return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, false)); } function emit(sourceFile, writeFileCallback, cancellationToken) { - var _this = this; - return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); }); + return runWithCancellationToken(function () { return emitWorker(program, sourceFile, writeFileCallback, cancellationToken); }); } function isEmitBlocked(emitFileName) { return hasEmitBlockingDiagnostics.contains(ts.toPath(emitFileName, currentDirectory, getCanonicalFileName)); @@ -38162,8 +38201,17 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { - if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) { + if (file_1 && ts.lookUp(sourceFilesFoundSearchingNodeModules, file_1.path) && currentNodeModulesDepth == 0) { + sourceFilesFoundSearchingNodeModules[file_1.path] = false; + if (!options.noResolve) { + processReferencedFiles(file_1, ts.getDirectoryPath(fileName), isDefaultLib); + processTypeReferenceDirectives(file_1); + } + modulesWithElidedImports[file_1.path] = false; + processImportedModules(file_1, ts.getDirectoryPath(fileName)); + } + else if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { + if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file_1.path] = false; processImportedModules(file_1, ts.getDirectoryPath(fileName)); } @@ -38180,6 +38228,7 @@ var ts; }); filesByName.set(path, file); if (file) { + sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0); file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -38280,12 +38329,9 @@ var ts; var isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport; var isJsFileFromNodeModules = isFromNodeModulesSearch && ts.hasJavaScriptFileExtension(resolution.resolvedFileName); if (isFromNodeModulesSearch) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; + currentNodeModulesDepth++; } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth++; - } - var elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth; + var elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; var shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; if (elideImport) { modulesWithElidedImports[file.path] = true; @@ -38293,8 +38339,8 @@ var ts; else if (shouldAddFile) { findSourceFile(resolution.resolvedFileName, resolvedPath, false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth--; + if (isFromNodeModulesSearch) { + currentNodeModulesDepth--; } } } @@ -39887,7 +39933,7 @@ var ts; return createPatternMatch(PatternMatchKind.exact, punctuationStripped, candidate === chunk.text); } else { - return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, startsWith(candidate, chunk.text)); + return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, ts.startsWith(candidate, chunk.text)); } } var isLowercase = chunk.isLowerCase; @@ -40059,14 +40105,6 @@ var ts; var str = String.fromCharCode(ch); return str === str.toLowerCase(); } - function startsWith(string, search) { - for (var i = 0, n = search.length; i < n; i++) { - if (string.charCodeAt(i) !== search.charCodeAt(i)) { - return false; - } - } - return true; - } function indexOfIgnoringCase(string, value) { for (var i = 0, n = string.length - value.length; i <= n; i++) { if (startsWithIgnoringCase(string, value, i)) { @@ -41551,6 +41589,9 @@ var ts; } return false; } + function shouldRescanJsxText(node) { + return node && node.kind === 244; + } function shouldRescanSlashToken(container) { return container.kind === 10; } @@ -41578,7 +41619,9 @@ var ts; ? 3 : shouldRescanJsxIdentifier(n) ? 4 - : 0; + : shouldRescanJsxText(n) + ? 5 + : 0; if (lastTokenInfo && expectedScanAction === lastScanAction) { return fixTokenKind(lastTokenInfo, n); } @@ -41606,6 +41649,10 @@ var ts; currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4; } + else if (expectedScanAction === 5) { + currentToken = scanner.reScanJsxToken(); + lastScanAction = 5; + } else { lastScanAction = 0; } @@ -43854,19 +43901,20 @@ var ts; "version" ]; var jsDocCompletionEntries; - function createNode(kind, pos, end, flags, parent) { - var node = new NodeObject(kind, pos, end); - node.flags = flags; + function createNode(kind, pos, end, parent) { + var node = kind >= 139 ? new NodeObject(kind, pos, end) : + kind === 69 ? new IdentifierObject(kind, pos, end) : + new TokenObject(kind, pos, end); node.parent = parent; return node; } var NodeObject = (function () { function NodeObject(kind, pos, end) { - this.kind = kind; this.pos = pos; this.end = end; this.flags = 0; this.parent = undefined; + this.kind = kind; } NodeObject.prototype.getSourceFile = function () { return ts.getSourceFileOfNode(this); @@ -43901,14 +43949,14 @@ var ts; var token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); var textPos = scanner.getTextPos(); if (textPos <= end) { - nodes.push(createNode(token, pos, textPos, 0, this)); + nodes.push(createNode(token, pos, textPos, this)); } pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(282, nodes.pos, nodes.end, 0, this); + var list = createNode(282, nodes.pos, nodes.end, this); list._children = []; var pos = nodes.pos; for (var _i = 0, nodes_4 = nodes; _i < nodes_4.length; _i++) { @@ -43993,6 +44041,73 @@ var ts; }; return NodeObject; }()); + var TokenOrIdentifierObject = (function () { + function TokenOrIdentifierObject(pos, end) { + this.pos = pos; + this.end = end; + this.flags = 0; + this.parent = undefined; + } + TokenOrIdentifierObject.prototype.getSourceFile = function () { + return ts.getSourceFileOfNode(this); + }; + TokenOrIdentifierObject.prototype.getStart = function (sourceFile, includeJsDocComment) { + return ts.getTokenPosOfNode(this, sourceFile, includeJsDocComment); + }; + TokenOrIdentifierObject.prototype.getFullStart = function () { + return this.pos; + }; + TokenOrIdentifierObject.prototype.getEnd = function () { + return this.end; + }; + TokenOrIdentifierObject.prototype.getWidth = function (sourceFile) { + return this.getEnd() - this.getStart(sourceFile); + }; + TokenOrIdentifierObject.prototype.getFullWidth = function () { + return this.end - this.pos; + }; + TokenOrIdentifierObject.prototype.getLeadingTriviaWidth = function (sourceFile) { + return this.getStart(sourceFile) - this.pos; + }; + TokenOrIdentifierObject.prototype.getFullText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); + }; + TokenOrIdentifierObject.prototype.getText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + }; + TokenOrIdentifierObject.prototype.getChildCount = function (sourceFile) { + return 0; + }; + TokenOrIdentifierObject.prototype.getChildAt = function (index, sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getChildren = function (sourceFile) { + return emptyArray; + }; + TokenOrIdentifierObject.prototype.getFirstToken = function (sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getLastToken = function (sourceFile) { + return undefined; + }; + return TokenOrIdentifierObject; + }()); + var TokenObject = (function (_super) { + __extends(TokenObject, _super); + function TokenObject(kind, pos, end) { + _super.call(this, pos, end); + this.kind = kind; + } + return TokenObject; + }(TokenOrIdentifierObject)); + var IdentifierObject = (function (_super) { + __extends(IdentifierObject, _super); + function IdentifierObject(kind, pos, end) { + _super.call(this, pos, end); + } + return IdentifierObject; + }(TokenOrIdentifierObject)); + IdentifierObject.prototype.kind = 69; var SymbolObject = (function () { function SymbolObject(flags, name) { this.flags = flags; @@ -49673,6 +49788,8 @@ var ts; function initializeServices() { ts.objectAllocator = { getNodeConstructor: function () { return NodeObject; }, + getTokenConstructor: function () { return TokenObject; }, + getIdentifierConstructor: function () { return IdentifierObject; }, getSourceFileConstructor: function () { return SourceFileObject; }, getSymbolConstructor: function () { return SymbolObject; }, getTypeConstructor: function () { return TypeObject; }, @@ -50793,7 +50910,6 @@ var ts; if (isOpen === void 0) { isOpen = false; } this.host = host; this.fileName = fileName; - this.content = content; this.isOpen = isOpen; this.children = []; this.formatCodeOptions = ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)); @@ -52419,7 +52535,7 @@ var ts; done: false, leaf: function (relativeStart, relativeLength, ll) { if (!f(ll, relativeStart, relativeLength)) { - this.done = true; + walkFns.done = true; } } }; @@ -53069,7 +53185,7 @@ var ts; ioSession.listen(); })(server = ts.server || (ts.server = {})); })(ts || (ts = {})); -var debugObjectHost = this; +var debugObjectHost = new Function("return this")(); var ts; (function (ts) { function logInternalError(logger, err) { @@ -53197,7 +53313,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 2c9fffcfcfb..1821c212574 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -405,7 +405,10 @@ declare namespace ts { interface ModifiersArray extends NodeArray { flags: NodeFlags; } - interface Modifier extends Node { + interface Token extends Node { + __tokenTag: any; + } + interface Modifier extends Token { } interface Identifier extends PrimaryExpression { text: string; @@ -2050,7 +2053,6 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; - getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getDirectories(path: string): string[]; @@ -2156,6 +2158,8 @@ declare namespace ts { function ensureTrailingDirectorySeparator(path: string): string; function comparePaths(a: string, b: string, currentDirectory: string, ignoreCase?: boolean): Comparison; function containsPath(parent: string, child: string, currentDirectory: string, ignoreCase?: boolean): boolean; + function startsWith(str: string, prefix: string): boolean; + function endsWith(str: string, suffix: string): boolean; function fileExtensionIs(path: string, extension: string): boolean; function fileExtensionIsAny(path: string, extensions: string[]): boolean; function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude"): string; @@ -2193,6 +2197,8 @@ declare namespace ts { function changeExtension(path: T, newExtension: string): T; interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; + getTokenConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; + getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; @@ -6456,13 +6462,13 @@ declare namespace ts { key: string; message: string; }; - Report_Errors_on_Unused_Locals: { + Report_errors_on_unused_locals: { code: number; category: DiagnosticCategory; key: string; message: string; }; - Report_Errors_on_Unused_Parameters: { + Report_errors_on_unused_parameters: { code: number; category: DiagnosticCategory; key: string; @@ -7143,8 +7149,6 @@ declare namespace ts { function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; function getTypeParameterOwner(d: Declaration): Declaration; function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean; - function startsWith(str: string, prefix: string): boolean; - function endsWith(str: string, suffix: string): boolean; } declare namespace ts { let parseTime: number; @@ -7225,6 +7229,12 @@ declare namespace ts { const defaultInitCompilerOptions: CompilerOptions; function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; + interface FormatDiagnosticsHost { + getCurrentDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + } + function formatDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): string; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function getAutomaticTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[]; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; @@ -8388,7 +8398,6 @@ declare namespace ts.server { class ScriptInfo { private host; fileName: string; - content: string; isOpen: boolean; svc: ScriptVersionCache; children: ScriptInfo[]; @@ -8729,7 +8738,7 @@ declare namespace ts { getLocalizedDiagnosticMessages(): string; getCancellationToken(): HostCancellationToken; getCurrentDirectory(): string; - getDirectories(path: string): string[]; + getDirectories(path: string): string; getDefaultLibFileName(options: string): string; getNewLine?(): string; getProjectVersion?(): string; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 5dafd5528a8..8823d9ce98b 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -830,10 +830,17 @@ var ts; return true; } ts.containsPath = containsPath; + function startsWith(str, prefix) { + return str.lastIndexOf(prefix, 0) === 0; + } + ts.startsWith = startsWith; + function endsWith(str, suffix) { + var expectedPos = str.length - suffix.length; + return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; + } + ts.endsWith = endsWith; function fileExtensionIs(path, extension) { - var pathLen = path.length; - var extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; + return path.length > extension.length && endsWith(path, extension); } ts.fileExtensionIs = fileExtensionIs; function fileExtensionIsAny(path, extensions) { @@ -1098,6 +1105,8 @@ var ts; } ts.objectAllocator = { getNodeConstructor: function () { return Node; }, + getTokenConstructor: function () { return Node; }, + getIdentifierConstructor: function () { return Node; }, getSourceFileConstructor: function () { return Node; }, getSymbolConstructor: function () { return Symbol; }, getTypeConstructor: function () { return Type; }, @@ -1229,7 +1238,7 @@ var ts; function readDirectory(path, extensions, excludes, includes) { return ts.matchFiles(path, extensions, excludes, includes, false, shell.CurrentDirectory, getAccessibleFileSystemEntries); } - return { + var wscriptSystem = { args: args, newLine: "\r\n", useCaseSensitiveFileNames: false, @@ -1248,7 +1257,7 @@ var ts; return fso.FolderExists(path); }, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!wscriptSystem.directoryExists(directoryName)) { fso.CreateFolder(directoryName); } }, @@ -1268,6 +1277,7 @@ var ts; } } }; + return wscriptSystem; } function getNodeSystem() { var _fs = require("fs"); @@ -1440,7 +1450,7 @@ var ts; function getDirectories(path) { return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1); }); } - return { + var nodeSystem = { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, @@ -1490,7 +1500,7 @@ var ts; fileExists: fileExists, directoryExists: directoryExists, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!nodeSystem.directoryExists(directoryName)) { _fs.mkdirSync(directoryName); } }, @@ -1538,6 +1548,7 @@ var ts; return _fs.realpathSync(path); } }; + return nodeSystem; } function getChakraSystem() { var realpath = ChakraHost.realpath && (function (path) { return ChakraHost.realpath(path); }); @@ -2287,8 +2298,8 @@ var ts; Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, - Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, - Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, + Report_errors_on_unused_locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_locals_6134", message: "Report errors on unused locals." }, + Report_errors_on_unused_parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_parameters_6135", message: "Report errors on unused parameters." }, The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files: { code: 6136, category: ts.DiagnosticCategory.Message, key: "The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files_6136", message: "The maximum dependency depth to search under node_modules and load JavaScript files" }, No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0: { code: 6137, category: ts.DiagnosticCategory.Message, key: "No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0_6137", message: "No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, @@ -3966,12 +3977,12 @@ var ts; { name: "noUnusedLocals", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Locals + description: ts.Diagnostics.Report_errors_on_unused_locals }, { name: "noUnusedParameters", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + description: ts.Diagnostics.Report_errors_on_unused_parameters }, { name: "noLib", @@ -5754,7 +5765,7 @@ var ts; } ts.isExpression = isExpression; function isExternalModuleNameRelative(moduleName) { - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + return /^\.\.?($|[\\/])/.test(moduleName); } ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { @@ -7262,25 +7273,24 @@ var ts; return node.flags & 92 && node.parent.kind === 148 && ts.isClassLike(node.parent.parent); } ts.isParameterPropertyDeclaration = isParameterPropertyDeclaration; - function startsWith(str, prefix) { - return str.lastIndexOf(prefix, 0) === 0; - } - ts.startsWith = startsWith; - function endsWith(str, suffix) { - var expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - ts.endsWith = endsWith; })(ts || (ts = {})); var ts; (function (ts) { ts.parseTime = 0; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; function createNode(kind, pos, end) { if (kind === 256) { return new (SourceFileConstructor || (SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor()))(kind, pos, end); } + else if (kind === 69) { + return new (IdentifierConstructor || (IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor()))(kind, pos, end); + } + else if (kind < 139) { + return new (TokenConstructor || (TokenConstructor = ts.objectAllocator.getTokenConstructor()))(kind, pos, end); + } else { return new (NodeConstructor || (NodeConstructor = ts.objectAllocator.getNodeConstructor()))(kind, pos, end); } @@ -7703,6 +7713,8 @@ var ts; var scanner = ts.createScanner(2, true); var disallowInAndDecoratorContext = 4194304 | 16777216; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; var sourceFile; var parseDiagnostics; @@ -7728,6 +7740,8 @@ var ts; } function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind) { NodeConstructor = ts.objectAllocator.getNodeConstructor(); + TokenConstructor = ts.objectAllocator.getTokenConstructor(); + IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor(); SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor(); sourceText = _sourceText; syntaxCursor = _syntaxCursor; @@ -8034,7 +8048,9 @@ var ts; if (!(pos >= 0)) { pos = scanner.getStartPos(); } - return new NodeConstructor(kind, pos, pos); + return kind >= 139 ? new NodeConstructor(kind, pos, pos) : + kind === 69 ? new IdentifierConstructor(kind, pos, pos) : + new TokenConstructor(kind, pos, pos); } function finishNode(node, end) { node.end = end === undefined ? scanner.getStartPos() : end; @@ -11810,6 +11826,9 @@ var ts; case 55: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); + if (!parentTagTerminated) { + resumePos = scanner.getStartPos(); + } } seenAsterisk = false; break; @@ -16336,17 +16355,18 @@ var ts; if (declaration.kind === 235) { return links.type = checkExpression(declaration.expression); } + if (declaration.flags & 134217728 && declaration.kind === 280 && declaration.typeExpression) { + return links.type = getTypeFromTypeNode(declaration.typeExpression.type); + } if (!pushTypeResolution(symbol, 0)) { return unknownType; } var type = undefined; - if (declaration.kind === 187) { - type = getUnionType(ts.map(symbol.declarations, function (decl) { return checkExpressionCached(decl.right); })); - } - else if (declaration.kind === 172) { - if (declaration.parent.kind === 187) { - type = checkExpressionCached(declaration.parent.right); - } + if (declaration.kind === 187 || + declaration.kind === 172 && declaration.parent.kind === 187) { + type = getUnionType(ts.map(symbol.declarations, function (decl) { return decl.kind === 187 ? + checkExpressionCached(decl.right) : + checkExpressionCached(decl.parent.right); })); } if (type === undefined) { type = getWidenedTypeForVariableLikeDeclaration(declaration, true); @@ -22853,7 +22873,7 @@ var ts; function getInferredClassType(symbol) { var links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, undefined, undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, undefined, undefined); } return links.inferredClassType; } @@ -24073,7 +24093,7 @@ var ts; checkAsyncFunctionReturnType(node); } } - if (!node.body) { + if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } @@ -24969,6 +24989,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -24984,6 +25005,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 && parameter.name.text.charCodeAt(0) === 95; } @@ -25012,9 +25036,14 @@ var ts; function checkUnusedTypeParameters(node) { if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { if (node.typeParameters) { + var symbol = getSymbolOfNode(node); + var lastDeclaration = symbol && symbol.declarations && ts.lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { var typeParameter = _a[_i]; - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -26091,7 +26120,7 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } function checkTypeAliasDeclaration(node) { @@ -30814,7 +30843,7 @@ var ts; writeLine(); var sourceMappingURL = sourceMap.getSourceMappingURL(); if (sourceMappingURL) { - write("//# sourceMappingURL=" + sourceMappingURL); + write("//# " + "sourceMappingURL" + "=" + sourceMappingURL); } writeEmittedFiles(writer.getText(), jsFilePath, sourceMapFilePath, compilerOptions.emitBOM, sourceFiles); sourceMap.reset(); @@ -34464,13 +34493,13 @@ var ts; if (isES6ExportedDeclaration(node) && !(node.flags & 512) && decoratedClassAlias === undefined) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write("" + decoratedClassAlias); + write("let " + decoratedClassAlias); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } write(" = "); @@ -36714,7 +36743,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "2.0.0"; + ts.version = "2.1.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -36794,12 +36823,7 @@ var ts; return { resolvedModule: resolvedFileName ? { resolvedFileName: resolvedFileName, isExternalLibraryImport: isExternalLibraryImport } : undefined, failedLookupLocations: failedLookupLocations }; } function moduleHasNonRelativeName(moduleName) { - if (ts.isRootedDiskPath(moduleName)) { - return false; - } - var i = moduleName.lastIndexOf("./", 1); - var startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === 46); - return !startsWithDotSlashOrDotDotSlash; + return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } function tryReadTypesSection(packageJsonPath, baseDirectory, state) { var jsonContent; @@ -37455,6 +37479,22 @@ var ts; return ts.sortAndDeduplicateDiagnostics(diagnostics); } ts.getPreEmitDiagnostics = getPreEmitDiagnostics; + function formatDiagnostics(diagnostics, host) { + var output = ""; + for (var _i = 0, diagnostics_1 = diagnostics; _i < diagnostics_1.length; _i++) { + var diagnostic = diagnostics_1[_i]; + if (diagnostic.file) { + var _a = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), line = _a.line, character = _a.character; + var fileName = diagnostic.file.fileName; + var relativeFileName = ts.convertToRelativePath(fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }); + output += relativeFileName + "(" + (line + 1) + "," + (character + 1) + "): "; + } + var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); + output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) + host.getNewLine(); + } + return output; + } + ts.formatDiagnostics = formatDiagnostics; function flattenDiagnosticMessageText(messageText, newLine) { if (typeof messageText === "string") { return messageText; @@ -37530,7 +37570,7 @@ var ts; var resolvedTypeReferenceDirectives = {}; var fileProcessingDiagnostics = ts.createDiagnosticCollection(); var maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2; - var currentNodeModulesJsDepth = 0; + var currentNodeModulesDepth = 0; var modulesWithElidedImports = {}; var sourceFilesFoundSearchingNodeModules = {}; var start = new Date().getTime(); @@ -37754,8 +37794,7 @@ var ts; return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, false)); } function emit(sourceFile, writeFileCallback, cancellationToken) { - var _this = this; - return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); }); + return runWithCancellationToken(function () { return emitWorker(program, sourceFile, writeFileCallback, cancellationToken); }); } function isEmitBlocked(emitFileName) { return hasEmitBlockingDiagnostics.contains(ts.toPath(emitFileName, currentDirectory, getCanonicalFileName)); @@ -38162,8 +38201,17 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { - if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) { + if (file_1 && ts.lookUp(sourceFilesFoundSearchingNodeModules, file_1.path) && currentNodeModulesDepth == 0) { + sourceFilesFoundSearchingNodeModules[file_1.path] = false; + if (!options.noResolve) { + processReferencedFiles(file_1, ts.getDirectoryPath(fileName), isDefaultLib); + processTypeReferenceDirectives(file_1); + } + modulesWithElidedImports[file_1.path] = false; + processImportedModules(file_1, ts.getDirectoryPath(fileName)); + } + else if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { + if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file_1.path] = false; processImportedModules(file_1, ts.getDirectoryPath(fileName)); } @@ -38180,6 +38228,7 @@ var ts; }); filesByName.set(path, file); if (file) { + sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0); file.path = path; if (host.useCaseSensitiveFileNames()) { var existingFile = filesByNameIgnoreCase.get(path); @@ -38280,12 +38329,9 @@ var ts; var isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport; var isJsFileFromNodeModules = isFromNodeModulesSearch && ts.hasJavaScriptFileExtension(resolution.resolvedFileName); if (isFromNodeModulesSearch) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; + currentNodeModulesDepth++; } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth++; - } - var elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth; + var elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; var shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; if (elideImport) { modulesWithElidedImports[file.path] = true; @@ -38293,8 +38339,8 @@ var ts; else if (shouldAddFile) { findSourceFile(resolution.resolvedFileName, resolvedPath, false, false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth--; + if (isFromNodeModulesSearch) { + currentNodeModulesDepth--; } } } @@ -39887,7 +39933,7 @@ var ts; return createPatternMatch(PatternMatchKind.exact, punctuationStripped, candidate === chunk.text); } else { - return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, startsWith(candidate, chunk.text)); + return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, ts.startsWith(candidate, chunk.text)); } } var isLowercase = chunk.isLowerCase; @@ -40059,14 +40105,6 @@ var ts; var str = String.fromCharCode(ch); return str === str.toLowerCase(); } - function startsWith(string, search) { - for (var i = 0, n = search.length; i < n; i++) { - if (string.charCodeAt(i) !== search.charCodeAt(i)) { - return false; - } - } - return true; - } function indexOfIgnoringCase(string, value) { for (var i = 0, n = string.length - value.length; i <= n; i++) { if (startsWithIgnoringCase(string, value, i)) { @@ -41551,6 +41589,9 @@ var ts; } return false; } + function shouldRescanJsxText(node) { + return node && node.kind === 244; + } function shouldRescanSlashToken(container) { return container.kind === 10; } @@ -41578,7 +41619,9 @@ var ts; ? 3 : shouldRescanJsxIdentifier(n) ? 4 - : 0; + : shouldRescanJsxText(n) + ? 5 + : 0; if (lastTokenInfo && expectedScanAction === lastScanAction) { return fixTokenKind(lastTokenInfo, n); } @@ -41606,6 +41649,10 @@ var ts; currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4; } + else if (expectedScanAction === 5) { + currentToken = scanner.reScanJsxToken(); + lastScanAction = 5; + } else { lastScanAction = 0; } @@ -43854,19 +43901,20 @@ var ts; "version" ]; var jsDocCompletionEntries; - function createNode(kind, pos, end, flags, parent) { - var node = new NodeObject(kind, pos, end); - node.flags = flags; + function createNode(kind, pos, end, parent) { + var node = kind >= 139 ? new NodeObject(kind, pos, end) : + kind === 69 ? new IdentifierObject(kind, pos, end) : + new TokenObject(kind, pos, end); node.parent = parent; return node; } var NodeObject = (function () { function NodeObject(kind, pos, end) { - this.kind = kind; this.pos = pos; this.end = end; this.flags = 0; this.parent = undefined; + this.kind = kind; } NodeObject.prototype.getSourceFile = function () { return ts.getSourceFileOfNode(this); @@ -43901,14 +43949,14 @@ var ts; var token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); var textPos = scanner.getTextPos(); if (textPos <= end) { - nodes.push(createNode(token, pos, textPos, 0, this)); + nodes.push(createNode(token, pos, textPos, this)); } pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(282, nodes.pos, nodes.end, 0, this); + var list = createNode(282, nodes.pos, nodes.end, this); list._children = []; var pos = nodes.pos; for (var _i = 0, nodes_4 = nodes; _i < nodes_4.length; _i++) { @@ -43993,6 +44041,73 @@ var ts; }; return NodeObject; }()); + var TokenOrIdentifierObject = (function () { + function TokenOrIdentifierObject(pos, end) { + this.pos = pos; + this.end = end; + this.flags = 0; + this.parent = undefined; + } + TokenOrIdentifierObject.prototype.getSourceFile = function () { + return ts.getSourceFileOfNode(this); + }; + TokenOrIdentifierObject.prototype.getStart = function (sourceFile, includeJsDocComment) { + return ts.getTokenPosOfNode(this, sourceFile, includeJsDocComment); + }; + TokenOrIdentifierObject.prototype.getFullStart = function () { + return this.pos; + }; + TokenOrIdentifierObject.prototype.getEnd = function () { + return this.end; + }; + TokenOrIdentifierObject.prototype.getWidth = function (sourceFile) { + return this.getEnd() - this.getStart(sourceFile); + }; + TokenOrIdentifierObject.prototype.getFullWidth = function () { + return this.end - this.pos; + }; + TokenOrIdentifierObject.prototype.getLeadingTriviaWidth = function (sourceFile) { + return this.getStart(sourceFile) - this.pos; + }; + TokenOrIdentifierObject.prototype.getFullText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); + }; + TokenOrIdentifierObject.prototype.getText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + }; + TokenOrIdentifierObject.prototype.getChildCount = function (sourceFile) { + return 0; + }; + TokenOrIdentifierObject.prototype.getChildAt = function (index, sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getChildren = function (sourceFile) { + return emptyArray; + }; + TokenOrIdentifierObject.prototype.getFirstToken = function (sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getLastToken = function (sourceFile) { + return undefined; + }; + return TokenOrIdentifierObject; + }()); + var TokenObject = (function (_super) { + __extends(TokenObject, _super); + function TokenObject(kind, pos, end) { + _super.call(this, pos, end); + this.kind = kind; + } + return TokenObject; + }(TokenOrIdentifierObject)); + var IdentifierObject = (function (_super) { + __extends(IdentifierObject, _super); + function IdentifierObject(kind, pos, end) { + _super.call(this, pos, end); + } + return IdentifierObject; + }(TokenOrIdentifierObject)); + IdentifierObject.prototype.kind = 69; var SymbolObject = (function () { function SymbolObject(flags, name) { this.flags = flags; @@ -49673,6 +49788,8 @@ var ts; function initializeServices() { ts.objectAllocator = { getNodeConstructor: function () { return NodeObject; }, + getTokenConstructor: function () { return TokenObject; }, + getIdentifierConstructor: function () { return IdentifierObject; }, getSourceFileConstructor: function () { return SourceFileObject; }, getSymbolConstructor: function () { return SymbolObject; }, getTypeConstructor: function () { return TypeObject; }, @@ -50793,7 +50910,6 @@ var ts; if (isOpen === void 0) { isOpen = false; } this.host = host; this.fileName = fileName; - this.content = content; this.isOpen = isOpen; this.children = []; this.formatCodeOptions = ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)); @@ -52419,7 +52535,7 @@ var ts; done: false, leaf: function (relativeStart, relativeLength, ll) { if (!f(ll, relativeStart, relativeLength)) { - this.done = true; + walkFns.done = true; } } }; @@ -52835,7 +52951,7 @@ var ts; server.LineLeaf = LineLeaf; })(server = ts.server || (ts.server = {})); })(ts || (ts = {})); -var debugObjectHost = this; +var debugObjectHost = new Function("return this")(); var ts; (function (ts) { function logInternalError(logger, err) { @@ -52963,7 +53079,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index c322ba1dd0c..92937fecf99 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -409,7 +409,10 @@ declare namespace ts { interface ModifiersArray extends NodeArray { flags: NodeFlags; } - interface Modifier extends Node { + interface Token extends Node { + __tokenTag: any; + } + interface Modifier extends Token { } interface Identifier extends PrimaryExpression { text: string; @@ -1696,7 +1699,6 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; - getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getDirectories(path: string): string[]; @@ -1842,8 +1844,6 @@ declare namespace ts { function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; function getTypeParameterOwner(d: Declaration): Declaration; function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean; - function startsWith(str: string, prefix: string): boolean; - function endsWith(str: string, suffix: string): boolean; } declare namespace ts { function createNode(kind: SyntaxKind, pos?: number, end?: number): Node; @@ -1868,6 +1868,12 @@ declare namespace ts { function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; + interface FormatDiagnosticsHost { + getCurrentDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + } + function formatDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): string; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; /** * Given a set of options and a set of root files, returns the set of type directive names diff --git a/lib/typescript.js b/lib/typescript.js index 22cbe79129c..41d3676a415 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -1756,10 +1756,19 @@ var ts; return true; } ts.containsPath = containsPath; + /* @internal */ + function startsWith(str, prefix) { + return str.lastIndexOf(prefix, 0) === 0; + } + ts.startsWith = startsWith; + /* @internal */ + function endsWith(str, suffix) { + var expectedPos = str.length - suffix.length; + return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; + } + ts.endsWith = endsWith; function fileExtensionIs(path, extension) { - var pathLen = path.length; - var extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; + return path.length > extension.length && endsWith(path, extension); } ts.fileExtensionIs = fileExtensionIs; function fileExtensionIsAny(path, extensions) { @@ -2070,6 +2079,8 @@ var ts; } ts.objectAllocator = { getNodeConstructor: function () { return Node; }, + getTokenConstructor: function () { return Node; }, + getIdentifierConstructor: function () { return Node; }, getSourceFileConstructor: function () { return Node; }, getSymbolConstructor: function () { return Symbol; }, getTypeConstructor: function () { return Type; }, @@ -2216,7 +2227,7 @@ var ts; function readDirectory(path, extensions, excludes, includes) { return ts.matchFiles(path, extensions, excludes, includes, /*useCaseSensitiveFileNames*/ false, shell.CurrentDirectory, getAccessibleFileSystemEntries); } - return { + var wscriptSystem = { args: args, newLine: "\r\n", useCaseSensitiveFileNames: false, @@ -2235,7 +2246,7 @@ var ts; return fso.FolderExists(path); }, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!wscriptSystem.directoryExists(directoryName)) { fso.CreateFolder(directoryName); } }, @@ -2255,6 +2266,7 @@ var ts; } } }; + return wscriptSystem; } function getNodeSystem() { var _fs = require("fs"); @@ -2444,7 +2456,7 @@ var ts; function getDirectories(path) { return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1 /* Directory */); }); } - return { + var nodeSystem = { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, @@ -2500,7 +2512,7 @@ var ts; fileExists: fileExists, directoryExists: directoryExists, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!nodeSystem.directoryExists(directoryName)) { _fs.mkdirSync(directoryName); } }, @@ -2548,6 +2560,7 @@ var ts; return _fs.realpathSync(path); } }; + return nodeSystem; } function getChakraSystem() { var realpath = ChakraHost.realpath && (function (path) { return ChakraHost.realpath(path); }); @@ -3304,8 +3317,8 @@ var ts; Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, - Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, - Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, + Report_errors_on_unused_locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_locals_6134", message: "Report errors on unused locals." }, + Report_errors_on_unused_parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_parameters_6135", message: "Report errors on unused parameters." }, The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files: { code: 6136, category: ts.DiagnosticCategory.Message, key: "The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files_6136", message: "The maximum dependency depth to search under node_modules and load JavaScript files" }, No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0: { code: 6137, category: ts.DiagnosticCategory.Message, key: "No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0_6137", message: "No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, @@ -6153,7 +6166,7 @@ var ts; function isExternalModuleNameRelative(moduleName) { // TypeScript 1.0 spec (April 2014): 11.2.1 // An external module name is "relative" if the first term is "." or "..". - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + return /^\.\.?($|[\\/])/.test(moduleName); } ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { @@ -7916,15 +7929,6 @@ var ts; return node.flags & 92 /* ParameterPropertyModifier */ && node.parent.kind === 148 /* Constructor */ && ts.isClassLike(node.parent.parent); } ts.isParameterPropertyDeclaration = isParameterPropertyDeclaration; - function startsWith(str, prefix) { - return str.lastIndexOf(prefix, 0) === 0; - } - ts.startsWith = startsWith; - function endsWith(str, suffix) { - var expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - ts.endsWith = endsWith; })(ts || (ts = {})); /// /// @@ -7932,11 +7936,19 @@ var ts; (function (ts) { /* @internal */ ts.parseTime = 0; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; function createNode(kind, pos, end) { if (kind === 256 /* SourceFile */) { return new (SourceFileConstructor || (SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor()))(kind, pos, end); } + else if (kind === 69 /* Identifier */) { + return new (IdentifierConstructor || (IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor()))(kind, pos, end); + } + else if (kind < 139 /* FirstNode */) { + return new (TokenConstructor || (TokenConstructor = ts.objectAllocator.getTokenConstructor()))(kind, pos, end); + } else { return new (NodeConstructor || (NodeConstructor = ts.objectAllocator.getNodeConstructor()))(kind, pos, end); } @@ -8386,6 +8398,8 @@ var ts; var disallowInAndDecoratorContext = 4194304 /* DisallowInContext */ | 16777216 /* DecoratorContext */; // capture constructors in 'initializeState' to avoid null checks var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; var sourceFile; var parseDiagnostics; @@ -8485,6 +8499,8 @@ var ts; } function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind) { NodeConstructor = ts.objectAllocator.getNodeConstructor(); + TokenConstructor = ts.objectAllocator.getTokenConstructor(); + IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor(); SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor(); sourceText = _sourceText; syntaxCursor = _syntaxCursor; @@ -8855,7 +8871,9 @@ var ts; if (!(pos >= 0)) { pos = scanner.getStartPos(); } - return new NodeConstructor(kind, pos, pos); + return kind >= 139 /* FirstNode */ ? new NodeConstructor(kind, pos, pos) : + kind === 69 /* Identifier */ ? new IdentifierConstructor(kind, pos, pos) : + new TokenConstructor(kind, pos, pos); } function finishNode(node, end) { node.end = end === undefined ? scanner.getStartPos() : end; @@ -13524,6 +13542,9 @@ var ts; case 55 /* AtToken */: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); + if (!parentTagTerminated) { + resumePos = scanner.getStartPos(); + } } seenAsterisk = false; break; @@ -18991,22 +19012,24 @@ var ts; if (declaration.kind === 235 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } + if (declaration.flags & 134217728 /* JavaScriptFile */ && declaration.kind === 280 /* JSDocPropertyTag */ && declaration.typeExpression) { + return links.type = getTypeFromTypeNode(declaration.typeExpression.type); + } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = undefined; - // Handle module.exports = expr or this.p = expr - if (declaration.kind === 187 /* BinaryExpression */) { - type = getUnionType(ts.map(symbol.declarations, function (decl) { return checkExpressionCached(decl.right); })); - } - else if (declaration.kind === 172 /* PropertyAccessExpression */) { - // Declarations only exist for property access expressions for certain - // special assignment kinds - if (declaration.parent.kind === 187 /* BinaryExpression */) { - // Handle exports.p = expr or className.prototype.method = expr - type = checkExpressionCached(declaration.parent.right); - } + // Handle certain special assignment kinds, which happen to union across multiple declarations: + // * module.exports = expr + // * exports.p = expr + // * this.p = expr + // * className.prototype.method = expr + if (declaration.kind === 187 /* BinaryExpression */ || + declaration.kind === 172 /* PropertyAccessExpression */ && declaration.parent.kind === 187 /* BinaryExpression */) { + type = getUnionType(ts.map(symbol.declarations, function (decl) { return decl.kind === 187 /* BinaryExpression */ ? + checkExpressionCached(decl.right) : + checkExpressionCached(decl.parent.right); })); } if (type === undefined) { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); @@ -26761,7 +26784,7 @@ var ts; function getInferredClassType(symbol) { var links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); } return links.inferredClassType; } @@ -28202,7 +28225,7 @@ var ts; checkAsyncFunctionReturnType(node); } } - if (!node.body) { + if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } @@ -29341,6 +29364,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -29356,6 +29380,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97 /* ThisKeyword */; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 /* Identifier */ && parameter.name.text.charCodeAt(0) === 95 /* _ */; } @@ -29384,9 +29411,16 @@ var ts; function checkUnusedTypeParameters(node) { if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { if (node.typeParameters) { + // Only report errors on the last declaration for the type parameter container; + // this ensures that all uses have been accounted for. + var symbol = getSymbolOfNode(node); + var lastDeclaration = symbol && symbol.declarations && ts.lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { var typeParameter = _a[_i]; - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -30719,7 +30753,7 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } function checkTypeAliasDeclaration(node) { @@ -35983,7 +36017,7 @@ var ts; writeLine(); var sourceMappingURL = sourceMap.getSourceMappingURL(); if (sourceMappingURL) { - write("//# sourceMappingURL=" + sourceMappingURL); + write("//# " + "sourceMappingURL" + "=" + sourceMappingURL); // Sometimes tools can sometimes see this line as a source mapping url comment } writeEmittedFiles(writer.getText(), jsFilePath, sourceMapFilePath, /*writeByteOrderMark*/ compilerOptions.emitBOM, sourceFiles); // reset the state @@ -37880,7 +37914,7 @@ var ts; * if we should also export the value after its it changed * - check if node is a source level declaration to emit it differently, * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. + * when we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { if (!node || !isCurrentFileSystemExternalModule()) { @@ -40347,13 +40381,13 @@ var ts; if (isES6ExportedDeclaration(node) && !(node.flags & 512 /* Default */) && decoratedClassAlias === undefined) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write("" + decoratedClassAlias); + write("let " + decoratedClassAlias); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } write(" = "); @@ -40372,7 +40406,9 @@ var ts; // // We'll emit: // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // let C_1 = class C{}; + // C_1.a = 1; + // C_1.b = 2; // so forth and so on // // This keeps the expression as an expression, while ensuring that the static parts // of it have been initialized by the time it is used. @@ -42936,7 +42972,7 @@ var ts; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ - ts.version = "2.0.0"; + ts.version = "2.1.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -43025,12 +43061,7 @@ var ts; return { resolvedModule: resolvedFileName ? { resolvedFileName: resolvedFileName, isExternalLibraryImport: isExternalLibraryImport } : undefined, failedLookupLocations: failedLookupLocations }; } function moduleHasNonRelativeName(moduleName) { - if (ts.isRootedDiskPath(moduleName)) { - return false; - } - var i = moduleName.lastIndexOf("./", 1); - var startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === 46 /* dot */); - return !startsWithDotSlashOrDotDotSlash; + return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } function tryReadTypesSection(packageJsonPath, baseDirectory, state) { var jsonContent; @@ -43797,6 +43828,22 @@ var ts; return ts.sortAndDeduplicateDiagnostics(diagnostics); } ts.getPreEmitDiagnostics = getPreEmitDiagnostics; + function formatDiagnostics(diagnostics, host) { + var output = ""; + for (var _i = 0, diagnostics_1 = diagnostics; _i < diagnostics_1.length; _i++) { + var diagnostic = diagnostics_1[_i]; + if (diagnostic.file) { + var _a = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), line = _a.line, character = _a.character; + var fileName = diagnostic.file.fileName; + var relativeFileName = ts.convertToRelativePath(fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }); + output += relativeFileName + "(" + (line + 1) + "," + (character + 1) + "): "; + } + var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); + output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) + host.getNewLine(); + } + return output; + } + ts.formatDiagnostics = formatDiagnostics; function flattenDiagnosticMessageText(messageText, newLine) { if (typeof messageText === "string") { return messageText; @@ -43889,11 +43936,11 @@ var ts; // As all these operations happen - and are nested - within the createProgram call, they close over the below variables. // The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses. var maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2; - var currentNodeModulesJsDepth = 0; + var currentNodeModulesDepth = 0; // If a module has some of its imports skipped due to being at the depth limit under node_modules, then track // this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed. var modulesWithElidedImports = {}; - // Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled. + // Track source files that are source files found by searching under node_modules, as these shouldn't be compiled. var sourceFilesFoundSearchingNodeModules = {}; var start = new Date().getTime(); host = host || createCompilerHost(options); @@ -44150,8 +44197,7 @@ var ts; return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ false)); } function emit(sourceFile, writeFileCallback, cancellationToken) { - var _this = this; - return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); }); + return runWithCancellationToken(function () { return emitWorker(program, sourceFile, writeFileCallback, cancellationToken); }); } function isEmitBlocked(emitFileName) { return hasEmitBlockingDiagnostics.contains(ts.toPath(emitFileName, currentDirectory, getCanonicalFileName)); @@ -44603,9 +44649,19 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - // See if we need to reprocess the imports due to prior skipped imports - if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { - if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) { + // If the file was previously found via a node_modules search, but is now being processed as a root file, + // then everything it sucks in may also be marked incorrectly, and needs to be checked again. + if (file_1 && ts.lookUp(sourceFilesFoundSearchingNodeModules, file_1.path) && currentNodeModulesDepth == 0) { + sourceFilesFoundSearchingNodeModules[file_1.path] = false; + if (!options.noResolve) { + processReferencedFiles(file_1, ts.getDirectoryPath(fileName), isDefaultLib); + processTypeReferenceDirectives(file_1); + } + modulesWithElidedImports[file_1.path] = false; + processImportedModules(file_1, ts.getDirectoryPath(fileName)); + } + else if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { + if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file_1.path] = false; processImportedModules(file_1, ts.getDirectoryPath(fileName)); } @@ -44623,6 +44679,7 @@ var ts; }); filesByName.set(path, file); if (file) { + sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0); file.path = path; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case @@ -44737,12 +44794,9 @@ var ts; var isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport; var isJsFileFromNodeModules = isFromNodeModulesSearch && ts.hasJavaScriptFileExtension(resolution.resolvedFileName); if (isFromNodeModulesSearch) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; + currentNodeModulesDepth++; } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth++; - } - var elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth; + var elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; var shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; if (elideImport) { modulesWithElidedImports[file.path] = true; @@ -44751,8 +44805,8 @@ var ts; findSourceFile(resolution.resolvedFileName, resolvedPath, /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth--; + if (isFromNodeModulesSearch) { + currentNodeModulesDepth--; } } } @@ -45090,12 +45144,12 @@ var ts; { name: "noUnusedLocals", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Locals + description: ts.Diagnostics.Report_errors_on_unused_locals }, { name: "noUnusedParameters", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + description: ts.Diagnostics.Report_errors_on_unused_parameters }, { name: "noLib", @@ -47087,7 +47141,7 @@ var ts; else { // b) Check if the part is a prefix of the candidate, in a case insensitive or sensitive // manner. If it does, return that there was a prefix match. - return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ startsWith(candidate, chunk.text)); + return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ ts.startsWith(candidate, chunk.text)); } } var isLowercase = chunk.isLowerCase; @@ -47353,14 +47407,6 @@ var ts; var str = String.fromCharCode(ch); return str === str.toLowerCase(); } - function startsWith(string, search) { - for (var i = 0, n = search.length; i < n; i++) { - if (string.charCodeAt(i) !== search.charCodeAt(i)) { - return false; - } - } - return true; - } // Assumes 'value' is already lowercase. function indexOfIgnoringCase(string, value) { for (var i = 0, n = string.length - value.length; i <= n; i++) { @@ -49205,6 +49251,7 @@ var ts; ScanAction[ScanAction["RescanSlashToken"] = 2] = "RescanSlashToken"; ScanAction[ScanAction["RescanTemplateToken"] = 3] = "RescanTemplateToken"; ScanAction[ScanAction["RescanJsxIdentifier"] = 4] = "RescanJsxIdentifier"; + ScanAction[ScanAction["RescanJsxText"] = 5] = "RescanJsxText"; })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { ts.Debug.assert(scanner === undefined); @@ -49296,6 +49343,9 @@ var ts; } return false; } + function shouldRescanJsxText(node) { + return node && node.kind === 244 /* JsxText */; + } function shouldRescanSlashToken(container) { return container.kind === 10 /* RegularExpressionLiteral */; } @@ -49326,7 +49376,9 @@ var ts; ? 3 /* RescanTemplateToken */ : shouldRescanJsxIdentifier(n) ? 4 /* RescanJsxIdentifier */ - : 0 /* Scan */; + : shouldRescanJsxText(n) + ? 5 /* RescanJsxText */ + : 0 /* Scan */; if (lastTokenInfo && expectedScanAction === lastScanAction) { // readTokenInfo was called before with the same expected scan action. // No need to re-scan text, return existing 'lastTokenInfo' @@ -49361,6 +49413,10 @@ var ts; currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4 /* RescanJsxIdentifier */; } + else if (expectedScanAction === 5 /* RescanJsxText */) { + currentToken = scanner.reScanJsxToken(); + lastScanAction = 5 /* RescanJsxText */; + } else { lastScanAction = 0 /* Scan */; } @@ -52033,19 +52089,20 @@ var ts; "version" ]; var jsDocCompletionEntries; - function createNode(kind, pos, end, flags, parent) { - var node = new NodeObject(kind, pos, end); - node.flags = flags; + function createNode(kind, pos, end, parent) { + var node = kind >= 139 /* FirstNode */ ? new NodeObject(kind, pos, end) : + kind === 69 /* Identifier */ ? new IdentifierObject(kind, pos, end) : + new TokenObject(kind, pos, end); node.parent = parent; return node; } var NodeObject = (function () { function NodeObject(kind, pos, end) { - this.kind = kind; this.pos = pos; this.end = end; this.flags = 0 /* None */; this.parent = undefined; + this.kind = kind; } NodeObject.prototype.getSourceFile = function () { return ts.getSourceFileOfNode(this); @@ -52080,14 +52137,14 @@ var ts; var token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); var textPos = scanner.getTextPos(); if (textPos <= end) { - nodes.push(createNode(token, pos, textPos, 0, this)); + nodes.push(createNode(token, pos, textPos, this)); } pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(282 /* SyntaxList */, nodes.pos, nodes.end, 0, this); + var list = createNode(282 /* SyntaxList */, nodes.pos, nodes.end, this); list._children = []; var pos = nodes.pos; for (var _i = 0, nodes_4 = nodes; _i < nodes_4.length; _i++) { @@ -52173,6 +52230,74 @@ var ts; }; return NodeObject; }()); + var TokenOrIdentifierObject = (function () { + function TokenOrIdentifierObject(pos, end) { + // Set properties in same order as NodeObject + this.pos = pos; + this.end = end; + this.flags = 0 /* None */; + this.parent = undefined; + } + TokenOrIdentifierObject.prototype.getSourceFile = function () { + return ts.getSourceFileOfNode(this); + }; + TokenOrIdentifierObject.prototype.getStart = function (sourceFile, includeJsDocComment) { + return ts.getTokenPosOfNode(this, sourceFile, includeJsDocComment); + }; + TokenOrIdentifierObject.prototype.getFullStart = function () { + return this.pos; + }; + TokenOrIdentifierObject.prototype.getEnd = function () { + return this.end; + }; + TokenOrIdentifierObject.prototype.getWidth = function (sourceFile) { + return this.getEnd() - this.getStart(sourceFile); + }; + TokenOrIdentifierObject.prototype.getFullWidth = function () { + return this.end - this.pos; + }; + TokenOrIdentifierObject.prototype.getLeadingTriviaWidth = function (sourceFile) { + return this.getStart(sourceFile) - this.pos; + }; + TokenOrIdentifierObject.prototype.getFullText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); + }; + TokenOrIdentifierObject.prototype.getText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + }; + TokenOrIdentifierObject.prototype.getChildCount = function (sourceFile) { + return 0; + }; + TokenOrIdentifierObject.prototype.getChildAt = function (index, sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getChildren = function (sourceFile) { + return emptyArray; + }; + TokenOrIdentifierObject.prototype.getFirstToken = function (sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getLastToken = function (sourceFile) { + return undefined; + }; + return TokenOrIdentifierObject; + }()); + var TokenObject = (function (_super) { + __extends(TokenObject, _super); + function TokenObject(kind, pos, end) { + _super.call(this, pos, end); + this.kind = kind; + } + return TokenObject; + }(TokenOrIdentifierObject)); + var IdentifierObject = (function (_super) { + __extends(IdentifierObject, _super); + function IdentifierObject(kind, pos, end) { + _super.call(this, pos, end); + } + return IdentifierObject; + }(TokenOrIdentifierObject)); + IdentifierObject.prototype.kind = 69 /* Identifier */; var SymbolObject = (function () { function SymbolObject(flags, name) { this.flags = flags; @@ -58937,6 +59062,8 @@ var ts; function initializeServices() { ts.objectAllocator = { getNodeConstructor: function () { return NodeObject; }, + getTokenConstructor: function () { return TokenObject; }, + getIdentifierConstructor: function () { return IdentifierObject; }, getSourceFileConstructor: function () { return SourceFileObject; }, getSymbolConstructor: function () { return SymbolObject; }, getTypeConstructor: function () { return TypeObject; }, @@ -59562,7 +59689,7 @@ var ts; // /// /* @internal */ -var debugObjectHost = this; +var debugObjectHost = new Function("return this")(); // We need to use 'null' to interface with the managed side. /* tslint:disable:no-null-keyword */ /* tslint:disable:no-in-operator */ @@ -59701,7 +59828,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 4ffdd868f16..a14277d920b 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -409,7 +409,10 @@ declare namespace ts { interface ModifiersArray extends NodeArray { flags: NodeFlags; } - interface Modifier extends Node { + interface Token extends Node { + __tokenTag: any; + } + interface Modifier extends Token { } interface Identifier extends PrimaryExpression { text: string; @@ -1696,7 +1699,6 @@ declare namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; - getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getDirectories(path: string): string[]; @@ -1842,8 +1844,6 @@ declare namespace ts { function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; function getTypeParameterOwner(d: Declaration): Declaration; function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean; - function startsWith(str: string, prefix: string): boolean; - function endsWith(str: string, suffix: string): boolean; } declare namespace ts { function createNode(kind: SyntaxKind, pos?: number, end?: number): Node; @@ -1868,6 +1868,12 @@ declare namespace ts { function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations; function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[]; + interface FormatDiagnosticsHost { + getCurrentDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + } + function formatDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): string; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; /** * Given a set of options and a set of root files, returns the set of type directive names diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 22cbe79129c..41d3676a415 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -1756,10 +1756,19 @@ var ts; return true; } ts.containsPath = containsPath; + /* @internal */ + function startsWith(str, prefix) { + return str.lastIndexOf(prefix, 0) === 0; + } + ts.startsWith = startsWith; + /* @internal */ + function endsWith(str, suffix) { + var expectedPos = str.length - suffix.length; + return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; + } + ts.endsWith = endsWith; function fileExtensionIs(path, extension) { - var pathLen = path.length; - var extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; + return path.length > extension.length && endsWith(path, extension); } ts.fileExtensionIs = fileExtensionIs; function fileExtensionIsAny(path, extensions) { @@ -2070,6 +2079,8 @@ var ts; } ts.objectAllocator = { getNodeConstructor: function () { return Node; }, + getTokenConstructor: function () { return Node; }, + getIdentifierConstructor: function () { return Node; }, getSourceFileConstructor: function () { return Node; }, getSymbolConstructor: function () { return Symbol; }, getTypeConstructor: function () { return Type; }, @@ -2216,7 +2227,7 @@ var ts; function readDirectory(path, extensions, excludes, includes) { return ts.matchFiles(path, extensions, excludes, includes, /*useCaseSensitiveFileNames*/ false, shell.CurrentDirectory, getAccessibleFileSystemEntries); } - return { + var wscriptSystem = { args: args, newLine: "\r\n", useCaseSensitiveFileNames: false, @@ -2235,7 +2246,7 @@ var ts; return fso.FolderExists(path); }, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!wscriptSystem.directoryExists(directoryName)) { fso.CreateFolder(directoryName); } }, @@ -2255,6 +2266,7 @@ var ts; } } }; + return wscriptSystem; } function getNodeSystem() { var _fs = require("fs"); @@ -2444,7 +2456,7 @@ var ts; function getDirectories(path) { return ts.filter(_fs.readdirSync(path), function (p) { return fileSystemEntryExists(ts.combinePaths(path, p), 1 /* Directory */); }); } - return { + var nodeSystem = { args: process.argv.slice(2), newLine: _os.EOL, useCaseSensitiveFileNames: useCaseSensitiveFileNames, @@ -2500,7 +2512,7 @@ var ts; fileExists: fileExists, directoryExists: directoryExists, createDirectory: function (directoryName) { - if (!this.directoryExists(directoryName)) { + if (!nodeSystem.directoryExists(directoryName)) { _fs.mkdirSync(directoryName); } }, @@ -2548,6 +2560,7 @@ var ts; return _fs.realpathSync(path); } }; + return nodeSystem; } function getChakraSystem() { var realpath = ChakraHost.realpath && (function (path) { return ChakraHost.realpath(path); }); @@ -3304,8 +3317,8 @@ var ts; Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, - Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, - Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, + Report_errors_on_unused_locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_locals_6134", message: "Report errors on unused locals." }, + Report_errors_on_unused_parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_errors_on_unused_parameters_6135", message: "Report errors on unused parameters." }, The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files: { code: 6136, category: ts.DiagnosticCategory.Message, key: "The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files_6136", message: "The maximum dependency depth to search under node_modules and load JavaScript files" }, No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0: { code: 6137, category: ts.DiagnosticCategory.Message, key: "No_types_specified_in_package_json_but_allowJs_is_set_so_returning_main_value_of_0_6137", message: "No types specified in 'package.json' but 'allowJs' is set, so returning 'main' value of '{0}'" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, @@ -6153,7 +6166,7 @@ var ts; function isExternalModuleNameRelative(moduleName) { // TypeScript 1.0 spec (April 2014): 11.2.1 // An external module name is "relative" if the first term is "." or "..". - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + return /^\.\.?($|[\\/])/.test(moduleName); } ts.isExternalModuleNameRelative = isExternalModuleNameRelative; function isInstantiatedModule(node, preserveConstEnums) { @@ -7916,15 +7929,6 @@ var ts; return node.flags & 92 /* ParameterPropertyModifier */ && node.parent.kind === 148 /* Constructor */ && ts.isClassLike(node.parent.parent); } ts.isParameterPropertyDeclaration = isParameterPropertyDeclaration; - function startsWith(str, prefix) { - return str.lastIndexOf(prefix, 0) === 0; - } - ts.startsWith = startsWith; - function endsWith(str, suffix) { - var expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - ts.endsWith = endsWith; })(ts || (ts = {})); /// /// @@ -7932,11 +7936,19 @@ var ts; (function (ts) { /* @internal */ ts.parseTime = 0; var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; function createNode(kind, pos, end) { if (kind === 256 /* SourceFile */) { return new (SourceFileConstructor || (SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor()))(kind, pos, end); } + else if (kind === 69 /* Identifier */) { + return new (IdentifierConstructor || (IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor()))(kind, pos, end); + } + else if (kind < 139 /* FirstNode */) { + return new (TokenConstructor || (TokenConstructor = ts.objectAllocator.getTokenConstructor()))(kind, pos, end); + } else { return new (NodeConstructor || (NodeConstructor = ts.objectAllocator.getNodeConstructor()))(kind, pos, end); } @@ -8386,6 +8398,8 @@ var ts; var disallowInAndDecoratorContext = 4194304 /* DisallowInContext */ | 16777216 /* DecoratorContext */; // capture constructors in 'initializeState' to avoid null checks var NodeConstructor; + var TokenConstructor; + var IdentifierConstructor; var SourceFileConstructor; var sourceFile; var parseDiagnostics; @@ -8485,6 +8499,8 @@ var ts; } function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind) { NodeConstructor = ts.objectAllocator.getNodeConstructor(); + TokenConstructor = ts.objectAllocator.getTokenConstructor(); + IdentifierConstructor = ts.objectAllocator.getIdentifierConstructor(); SourceFileConstructor = ts.objectAllocator.getSourceFileConstructor(); sourceText = _sourceText; syntaxCursor = _syntaxCursor; @@ -8855,7 +8871,9 @@ var ts; if (!(pos >= 0)) { pos = scanner.getStartPos(); } - return new NodeConstructor(kind, pos, pos); + return kind >= 139 /* FirstNode */ ? new NodeConstructor(kind, pos, pos) : + kind === 69 /* Identifier */ ? new IdentifierConstructor(kind, pos, pos) : + new TokenConstructor(kind, pos, pos); } function finishNode(node, end) { node.end = end === undefined ? scanner.getStartPos() : end; @@ -13524,6 +13542,9 @@ var ts; case 55 /* AtToken */: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); + if (!parentTagTerminated) { + resumePos = scanner.getStartPos(); + } } seenAsterisk = false; break; @@ -18991,22 +19012,24 @@ var ts; if (declaration.kind === 235 /* ExportAssignment */) { return links.type = checkExpression(declaration.expression); } + if (declaration.flags & 134217728 /* JavaScriptFile */ && declaration.kind === 280 /* JSDocPropertyTag */ && declaration.typeExpression) { + return links.type = getTypeFromTypeNode(declaration.typeExpression.type); + } // Handle variable, parameter or property if (!pushTypeResolution(symbol, 0 /* Type */)) { return unknownType; } var type = undefined; - // Handle module.exports = expr or this.p = expr - if (declaration.kind === 187 /* BinaryExpression */) { - type = getUnionType(ts.map(symbol.declarations, function (decl) { return checkExpressionCached(decl.right); })); - } - else if (declaration.kind === 172 /* PropertyAccessExpression */) { - // Declarations only exist for property access expressions for certain - // special assignment kinds - if (declaration.parent.kind === 187 /* BinaryExpression */) { - // Handle exports.p = expr or className.prototype.method = expr - type = checkExpressionCached(declaration.parent.right); - } + // Handle certain special assignment kinds, which happen to union across multiple declarations: + // * module.exports = expr + // * exports.p = expr + // * this.p = expr + // * className.prototype.method = expr + if (declaration.kind === 187 /* BinaryExpression */ || + declaration.kind === 172 /* PropertyAccessExpression */ && declaration.parent.kind === 187 /* BinaryExpression */) { + type = getUnionType(ts.map(symbol.declarations, function (decl) { return decl.kind === 187 /* BinaryExpression */ ? + checkExpressionCached(decl.right) : + checkExpressionCached(decl.parent.right); })); } if (type === undefined) { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); @@ -26761,7 +26784,7 @@ var ts; function getInferredClassType(symbol) { var links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(undefined, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); } return links.inferredClassType; } @@ -28202,7 +28225,7 @@ var ts; checkAsyncFunctionReturnType(node); } } - if (!node.body) { + if (noUnusedIdentifiers && !node.body) { checkUnusedTypeParameters(node); } } @@ -29341,6 +29364,7 @@ var ts; var parameter = local_1.valueDeclaration; if (compilerOptions.noUnusedParameters && !ts.isParameterPropertyDeclaration(parameter) && + !parameterIsThisKeyword(parameter) && !parameterNameStartsWithUnderscore(parameter)) { error(local_1.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); } @@ -29356,6 +29380,9 @@ var ts; } } } + function parameterIsThisKeyword(parameter) { + return parameter.name && parameter.name.originalKeywordKind === 97 /* ThisKeyword */; + } function parameterNameStartsWithUnderscore(parameter) { return parameter.name && parameter.name.kind === 69 /* Identifier */ && parameter.name.text.charCodeAt(0) === 95 /* _ */; } @@ -29384,9 +29411,16 @@ var ts; function checkUnusedTypeParameters(node) { if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { if (node.typeParameters) { + // Only report errors on the last declaration for the type parameter container; + // this ensures that all uses have been accounted for. + var symbol = getSymbolOfNode(node); + var lastDeclaration = symbol && symbol.declarations && ts.lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { var typeParameter = _a[_i]; - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -30719,7 +30753,7 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } function checkTypeAliasDeclaration(node) { @@ -35983,7 +36017,7 @@ var ts; writeLine(); var sourceMappingURL = sourceMap.getSourceMappingURL(); if (sourceMappingURL) { - write("//# sourceMappingURL=" + sourceMappingURL); + write("//# " + "sourceMappingURL" + "=" + sourceMappingURL); // Sometimes tools can sometimes see this line as a source mapping url comment } writeEmittedFiles(writer.getText(), jsFilePath, sourceMapFilePath, /*writeByteOrderMark*/ compilerOptions.emitBOM, sourceFiles); // reset the state @@ -37880,7 +37914,7 @@ var ts; * if we should also export the value after its it changed * - check if node is a source level declaration to emit it differently, * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. + * when we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node, isExported) { if (!node || !isCurrentFileSystemExternalModule()) { @@ -40347,13 +40381,13 @@ var ts; if (isES6ExportedDeclaration(node) && !(node.flags & 512 /* Default */) && decoratedClassAlias === undefined) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write("" + decoratedClassAlias); + write("let " + decoratedClassAlias); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } write(" = "); @@ -40372,7 +40406,9 @@ var ts; // // We'll emit: // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // let C_1 = class C{}; + // C_1.a = 1; + // C_1.b = 2; // so forth and so on // // This keeps the expression as an expression, while ensuring that the static parts // of it have been initialized by the time it is used. @@ -42936,7 +42972,7 @@ var ts; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ - ts.version = "2.0.0"; + ts.version = "2.1.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -43025,12 +43061,7 @@ var ts; return { resolvedModule: resolvedFileName ? { resolvedFileName: resolvedFileName, isExternalLibraryImport: isExternalLibraryImport } : undefined, failedLookupLocations: failedLookupLocations }; } function moduleHasNonRelativeName(moduleName) { - if (ts.isRootedDiskPath(moduleName)) { - return false; - } - var i = moduleName.lastIndexOf("./", 1); - var startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === 46 /* dot */); - return !startsWithDotSlashOrDotDotSlash; + return !(ts.isRootedDiskPath(moduleName) || ts.isExternalModuleNameRelative(moduleName)); } function tryReadTypesSection(packageJsonPath, baseDirectory, state) { var jsonContent; @@ -43797,6 +43828,22 @@ var ts; return ts.sortAndDeduplicateDiagnostics(diagnostics); } ts.getPreEmitDiagnostics = getPreEmitDiagnostics; + function formatDiagnostics(diagnostics, host) { + var output = ""; + for (var _i = 0, diagnostics_1 = diagnostics; _i < diagnostics_1.length; _i++) { + var diagnostic = diagnostics_1[_i]; + if (diagnostic.file) { + var _a = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), line = _a.line, character = _a.character; + var fileName = diagnostic.file.fileName; + var relativeFileName = ts.convertToRelativePath(fileName, host.getCurrentDirectory(), function (fileName) { return host.getCanonicalFileName(fileName); }); + output += relativeFileName + "(" + (line + 1) + "," + (character + 1) + "): "; + } + var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase(); + output += category + " TS" + diagnostic.code + ": " + flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) + host.getNewLine(); + } + return output; + } + ts.formatDiagnostics = formatDiagnostics; function flattenDiagnosticMessageText(messageText, newLine) { if (typeof messageText === "string") { return messageText; @@ -43889,11 +43936,11 @@ var ts; // As all these operations happen - and are nested - within the createProgram call, they close over the below variables. // The current resolution depth is tracked by incrementing/decrementing as the depth first search progresses. var maxNodeModulesJsDepth = typeof options.maxNodeModuleJsDepth === "number" ? options.maxNodeModuleJsDepth : 2; - var currentNodeModulesJsDepth = 0; + var currentNodeModulesDepth = 0; // If a module has some of its imports skipped due to being at the depth limit under node_modules, then track // this, as it may be imported at a shallower depth later, and then it will need its skipped imports processed. var modulesWithElidedImports = {}; - // Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled. + // Track source files that are source files found by searching under node_modules, as these shouldn't be compiled. var sourceFilesFoundSearchingNodeModules = {}; var start = new Date().getTime(); host = host || createCompilerHost(options); @@ -44150,8 +44197,7 @@ var ts; return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = ts.createTypeChecker(program, /*produceDiagnostics:*/ false)); } function emit(sourceFile, writeFileCallback, cancellationToken) { - var _this = this; - return runWithCancellationToken(function () { return emitWorker(_this, sourceFile, writeFileCallback, cancellationToken); }); + return runWithCancellationToken(function () { return emitWorker(program, sourceFile, writeFileCallback, cancellationToken); }); } function isEmitBlocked(emitFileName) { return hasEmitBlockingDiagnostics.contains(ts.toPath(emitFileName, currentDirectory, getCanonicalFileName)); @@ -44603,9 +44649,19 @@ var ts; if (file_1 && options.forceConsistentCasingInFileNames && ts.getNormalizedAbsolutePath(file_1.fileName, currentDirectory) !== ts.getNormalizedAbsolutePath(fileName, currentDirectory)) { reportFileNamesDifferOnlyInCasingError(fileName, file_1.fileName, refFile, refPos, refEnd); } - // See if we need to reprocess the imports due to prior skipped imports - if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { - if (currentNodeModulesJsDepth < maxNodeModulesJsDepth) { + // If the file was previously found via a node_modules search, but is now being processed as a root file, + // then everything it sucks in may also be marked incorrectly, and needs to be checked again. + if (file_1 && ts.lookUp(sourceFilesFoundSearchingNodeModules, file_1.path) && currentNodeModulesDepth == 0) { + sourceFilesFoundSearchingNodeModules[file_1.path] = false; + if (!options.noResolve) { + processReferencedFiles(file_1, ts.getDirectoryPath(fileName), isDefaultLib); + processTypeReferenceDirectives(file_1); + } + modulesWithElidedImports[file_1.path] = false; + processImportedModules(file_1, ts.getDirectoryPath(fileName)); + } + else if (file_1 && ts.lookUp(modulesWithElidedImports, file_1.path)) { + if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file_1.path] = false; processImportedModules(file_1, ts.getDirectoryPath(fileName)); } @@ -44623,6 +44679,7 @@ var ts; }); filesByName.set(path, file); if (file) { + sourceFilesFoundSearchingNodeModules[path] = (currentNodeModulesDepth > 0); file.path = path; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case @@ -44737,12 +44794,9 @@ var ts; var isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport; var isJsFileFromNodeModules = isFromNodeModulesSearch && ts.hasJavaScriptFileExtension(resolution.resolvedFileName); if (isFromNodeModulesSearch) { - sourceFilesFoundSearchingNodeModules[resolvedPath] = true; + currentNodeModulesDepth++; } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth++; - } - var elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth; + var elideImport = isJsFileFromNodeModules && currentNodeModulesDepth > maxNodeModulesJsDepth; var shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport; if (elideImport) { modulesWithElidedImports[file.path] = true; @@ -44751,8 +44805,8 @@ var ts; findSourceFile(resolution.resolvedFileName, resolvedPath, /*isDefaultLib*/ false, /*isReference*/ false, file, ts.skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); } - if (isJsFileFromNodeModules) { - currentNodeModulesJsDepth--; + if (isFromNodeModulesSearch) { + currentNodeModulesDepth--; } } } @@ -45090,12 +45144,12 @@ var ts; { name: "noUnusedLocals", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Locals + description: ts.Diagnostics.Report_errors_on_unused_locals }, { name: "noUnusedParameters", type: "boolean", - description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + description: ts.Diagnostics.Report_errors_on_unused_parameters }, { name: "noLib", @@ -47087,7 +47141,7 @@ var ts; else { // b) Check if the part is a prefix of the candidate, in a case insensitive or sensitive // manner. If it does, return that there was a prefix match. - return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ startsWith(candidate, chunk.text)); + return createPatternMatch(PatternMatchKind.prefix, punctuationStripped, /*isCaseSensitive:*/ ts.startsWith(candidate, chunk.text)); } } var isLowercase = chunk.isLowerCase; @@ -47353,14 +47407,6 @@ var ts; var str = String.fromCharCode(ch); return str === str.toLowerCase(); } - function startsWith(string, search) { - for (var i = 0, n = search.length; i < n; i++) { - if (string.charCodeAt(i) !== search.charCodeAt(i)) { - return false; - } - } - return true; - } // Assumes 'value' is already lowercase. function indexOfIgnoringCase(string, value) { for (var i = 0, n = string.length - value.length; i <= n; i++) { @@ -49205,6 +49251,7 @@ var ts; ScanAction[ScanAction["RescanSlashToken"] = 2] = "RescanSlashToken"; ScanAction[ScanAction["RescanTemplateToken"] = 3] = "RescanTemplateToken"; ScanAction[ScanAction["RescanJsxIdentifier"] = 4] = "RescanJsxIdentifier"; + ScanAction[ScanAction["RescanJsxText"] = 5] = "RescanJsxText"; })(ScanAction || (ScanAction = {})); function getFormattingScanner(sourceFile, startPos, endPos) { ts.Debug.assert(scanner === undefined); @@ -49296,6 +49343,9 @@ var ts; } return false; } + function shouldRescanJsxText(node) { + return node && node.kind === 244 /* JsxText */; + } function shouldRescanSlashToken(container) { return container.kind === 10 /* RegularExpressionLiteral */; } @@ -49326,7 +49376,9 @@ var ts; ? 3 /* RescanTemplateToken */ : shouldRescanJsxIdentifier(n) ? 4 /* RescanJsxIdentifier */ - : 0 /* Scan */; + : shouldRescanJsxText(n) + ? 5 /* RescanJsxText */ + : 0 /* Scan */; if (lastTokenInfo && expectedScanAction === lastScanAction) { // readTokenInfo was called before with the same expected scan action. // No need to re-scan text, return existing 'lastTokenInfo' @@ -49361,6 +49413,10 @@ var ts; currentToken = scanner.scanJsxIdentifier(); lastScanAction = 4 /* RescanJsxIdentifier */; } + else if (expectedScanAction === 5 /* RescanJsxText */) { + currentToken = scanner.reScanJsxToken(); + lastScanAction = 5 /* RescanJsxText */; + } else { lastScanAction = 0 /* Scan */; } @@ -52033,19 +52089,20 @@ var ts; "version" ]; var jsDocCompletionEntries; - function createNode(kind, pos, end, flags, parent) { - var node = new NodeObject(kind, pos, end); - node.flags = flags; + function createNode(kind, pos, end, parent) { + var node = kind >= 139 /* FirstNode */ ? new NodeObject(kind, pos, end) : + kind === 69 /* Identifier */ ? new IdentifierObject(kind, pos, end) : + new TokenObject(kind, pos, end); node.parent = parent; return node; } var NodeObject = (function () { function NodeObject(kind, pos, end) { - this.kind = kind; this.pos = pos; this.end = end; this.flags = 0 /* None */; this.parent = undefined; + this.kind = kind; } NodeObject.prototype.getSourceFile = function () { return ts.getSourceFileOfNode(this); @@ -52080,14 +52137,14 @@ var ts; var token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); var textPos = scanner.getTextPos(); if (textPos <= end) { - nodes.push(createNode(token, pos, textPos, 0, this)); + nodes.push(createNode(token, pos, textPos, this)); } pos = textPos; } return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(282 /* SyntaxList */, nodes.pos, nodes.end, 0, this); + var list = createNode(282 /* SyntaxList */, nodes.pos, nodes.end, this); list._children = []; var pos = nodes.pos; for (var _i = 0, nodes_4 = nodes; _i < nodes_4.length; _i++) { @@ -52173,6 +52230,74 @@ var ts; }; return NodeObject; }()); + var TokenOrIdentifierObject = (function () { + function TokenOrIdentifierObject(pos, end) { + // Set properties in same order as NodeObject + this.pos = pos; + this.end = end; + this.flags = 0 /* None */; + this.parent = undefined; + } + TokenOrIdentifierObject.prototype.getSourceFile = function () { + return ts.getSourceFileOfNode(this); + }; + TokenOrIdentifierObject.prototype.getStart = function (sourceFile, includeJsDocComment) { + return ts.getTokenPosOfNode(this, sourceFile, includeJsDocComment); + }; + TokenOrIdentifierObject.prototype.getFullStart = function () { + return this.pos; + }; + TokenOrIdentifierObject.prototype.getEnd = function () { + return this.end; + }; + TokenOrIdentifierObject.prototype.getWidth = function (sourceFile) { + return this.getEnd() - this.getStart(sourceFile); + }; + TokenOrIdentifierObject.prototype.getFullWidth = function () { + return this.end - this.pos; + }; + TokenOrIdentifierObject.prototype.getLeadingTriviaWidth = function (sourceFile) { + return this.getStart(sourceFile) - this.pos; + }; + TokenOrIdentifierObject.prototype.getFullText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); + }; + TokenOrIdentifierObject.prototype.getText = function (sourceFile) { + return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + }; + TokenOrIdentifierObject.prototype.getChildCount = function (sourceFile) { + return 0; + }; + TokenOrIdentifierObject.prototype.getChildAt = function (index, sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getChildren = function (sourceFile) { + return emptyArray; + }; + TokenOrIdentifierObject.prototype.getFirstToken = function (sourceFile) { + return undefined; + }; + TokenOrIdentifierObject.prototype.getLastToken = function (sourceFile) { + return undefined; + }; + return TokenOrIdentifierObject; + }()); + var TokenObject = (function (_super) { + __extends(TokenObject, _super); + function TokenObject(kind, pos, end) { + _super.call(this, pos, end); + this.kind = kind; + } + return TokenObject; + }(TokenOrIdentifierObject)); + var IdentifierObject = (function (_super) { + __extends(IdentifierObject, _super); + function IdentifierObject(kind, pos, end) { + _super.call(this, pos, end); + } + return IdentifierObject; + }(TokenOrIdentifierObject)); + IdentifierObject.prototype.kind = 69 /* Identifier */; var SymbolObject = (function () { function SymbolObject(flags, name) { this.flags = flags; @@ -58937,6 +59062,8 @@ var ts; function initializeServices() { ts.objectAllocator = { getNodeConstructor: function () { return NodeObject; }, + getTokenConstructor: function () { return TokenObject; }, + getIdentifierConstructor: function () { return IdentifierObject; }, getSourceFileConstructor: function () { return SourceFileObject; }, getSymbolConstructor: function () { return SymbolObject; }, getTypeConstructor: function () { return TypeObject; }, @@ -59562,7 +59689,7 @@ var ts; // /// /* @internal */ -var debugObjectHost = this; +var debugObjectHost = new Function("return this")(); // We need to use 'null' to interface with the managed side. /* tslint:disable:no-null-keyword */ /* tslint:disable:no-in-operator */ @@ -59701,7 +59828,7 @@ var ts; return this.shimHost.getCurrentDirectory(); }; LanguageServiceShimHostAdapter.prototype.getDirectories = function (path) { - return this.shimHost.getDirectories(path); + return JSON.parse(this.shimHost.getDirectories(path)); }; LanguageServiceShimHostAdapter.prototype.getDefaultLibFileName = function (options) { return this.shimHost.getDefaultLibFileName(JSON.stringify(options)); diff --git a/package.json b/package.json index 3bbb96ee468..5606a423a0e 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ }, "devDependencies": { "@types/browserify": "latest", + "@types/convert-source-map": "latest", "@types/chai": "latest", "@types/del": "latest", "@types/glob": "latest", @@ -50,6 +51,7 @@ "@types/through2": "latest", "browserify": "latest", "chai": "latest", + "convert-source-map": "latest", "del": "latest", "gulp": "latest", "gulp-clone": "latest", @@ -68,9 +70,9 @@ "mocha": "latest", "mocha-fivemat-progress-reporter": "latest", "run-sequence": "latest", + "sorcery": "latest", "through2": "latest", "ts-node": "latest", - "tsd": "latest", "tslint": "next", "typescript": "next" }, diff --git a/scripts/tsd.json b/scripts/tsd.json deleted file mode 100644 index c2fc88a0b0f..00000000000 --- a/scripts/tsd.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "v4", - "repo": "borisyankov/DefinitelyTyped", - "ref": "master", - "path": "typings", - "bundle": "typings/tsd.d.ts", - "installed": { - "node/node.d.ts": { - "commit": "5f480287834a2615274eea31574b713e64decf17" - } - } -} diff --git a/scripts/types/ambient.d.ts b/scripts/types/ambient.d.ts index 8a86a290bee..e77e3fe8c5a 100644 --- a/scripts/types/ambient.d.ts +++ b/scripts/types/ambient.d.ts @@ -19,4 +19,6 @@ declare module "into-stream" { export function obj(content: any): NodeJS.ReadableStream } export = IntoStream; -} \ No newline at end of file +} + +declare module "sorcery"; diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b7852a64d04..6059cd1f86a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -3,8 +3,6 @@ /* @internal */ namespace ts { - export let bindTime = 0; - export const enum ModuleInstanceState { NonInstantiated = 0, Instantiated = 1, @@ -91,9 +89,9 @@ namespace ts { const binder = createBinder(); export function bindSourceFile(file: SourceFile, options: CompilerOptions) { - const start = new Date().getTime(); + const start = performance.mark(); binder(file, options); - bindTime += new Date().getTime() - start; + performance.measure("Bind", start); } function createBinder(): (file: SourceFile, options: CompilerOptions) => void { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index aea8c982a95..1cebd469388 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15,8 +15,6 @@ namespace ts { return node.id; } - export let checkTime = 0; - export function getSymbolId(symbol: Symbol): number { if (!symbol.id) { symbol.id = nextSymbolId; @@ -976,7 +974,7 @@ namespace ts { Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - if (!isBlockScopedNameDeclaredBeforeUse(getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) { + if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) { error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name)); } } @@ -3160,6 +3158,9 @@ namespace ts { if (declaration.kind === SyntaxKind.ExportAssignment) { return links.type = checkExpression((declaration).expression); } + if (declaration.flags & NodeFlags.JavaScriptFile && declaration.kind === SyntaxKind.JSDocPropertyTag && (declaration).typeExpression) { + return links.type = getTypeFromTypeNode((declaration).typeExpression.type); + } // Handle variable, parameter or property if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { return unknownType; @@ -13274,7 +13275,7 @@ namespace ts { checkAsyncFunctionReturnType(node); } } - if (!(node).body) { + if (noUnusedIdentifiers && !(node).body) { checkUnusedTypeParameters(node); } } @@ -14609,8 +14610,15 @@ namespace ts { function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) { if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) { if (node.typeParameters) { + // Only report errors on the last declaration for the type parameter container; + // this ensures that all uses have been accounted for. + const symbol = getSymbolOfNode(node); + const lastDeclaration = symbol && symbol.declarations && lastOrUndefined(symbol.declarations); + if (lastDeclaration !== node) { + return; + } for (const typeParameter of node.typeParameters) { - if (!typeParameter.symbol.isReferenced) { + if (!getMergedSymbol(typeParameter.symbol).isReferenced) { error(typeParameter.name, Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); } } @@ -16119,7 +16127,7 @@ namespace ts { if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); - checkUnusedTypeParameters(node); + registerForUnusedIdentifiersCheck(node); } } @@ -17016,11 +17024,11 @@ namespace ts { } function checkSourceFile(node: SourceFile) { - const start = new Date().getTime(); + const start = performance.mark(); checkSourceFileWorker(node); - checkTime += new Date().getTime() - start; + performance.measure("Check", start); } // Fully type check a source file and collect the relevant diagnostics. diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 72fd5ff6fd7..418584bd264 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -27,6 +27,10 @@ namespace ts { name: "diagnostics", type: "boolean", }, + { + name: "extendedDiagnostics", + type: "boolean", + }, { name: "emitBOM", type: "boolean" @@ -135,12 +139,12 @@ namespace ts { { name: "noUnusedLocals", type: "boolean", - description: Diagnostics.Report_Errors_on_Unused_Locals, + description: Diagnostics.Report_errors_on_unused_locals, }, { name: "noUnusedParameters", type: "boolean", - description: Diagnostics.Report_Errors_on_Unused_Parameters + description: Diagnostics.Report_errors_on_unused_parameters, }, { name: "noLib", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 5157f3e0b04..18c6a98991d 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1,4 +1,6 @@ /// +/// + /* @internal */ namespace ts { @@ -899,10 +901,19 @@ namespace ts { return true; } + /* @internal */ + export function startsWith(str: string, prefix: string): boolean { + return str.lastIndexOf(prefix, 0) === 0; + } + + /* @internal */ + export function endsWith(str: string, suffix: string): boolean { + const expectedPos = str.length - suffix.length; + return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos; + } + export function fileExtensionIs(path: string, extension: string): boolean { - const pathLen = path.length; - const extLen = extension.length; - return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension; + return path.length > extension.length && endsWith(path, extension); } export function fileExtensionIsAny(path: string, extensions: string[]): boolean { @@ -915,7 +926,6 @@ namespace ts { return false; } - // Reserved characters, forces escaping of any non-word (or digit), non-whitespace character. // It may be inefficient (we could just match (/[-[\]{}()*+?.,\\^$|#\s]/g), but this is future // proof. @@ -1271,6 +1281,8 @@ namespace ts { export interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; + getTokenConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; + getIdentifierConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Token; getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile; getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol; getTypeConstructor(): new (checker: TypeChecker, flags: TypeFlags) => Type; @@ -1300,6 +1312,8 @@ namespace ts { export let objectAllocator: ObjectAllocator = { getNodeConstructor: () => Node, + getTokenConstructor: () => Node, + getIdentifierConstructor: () => Node, getSourceFileConstructor: () => Node, getSymbolConstructor: () => Symbol, getTypeConstructor: () => Type, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7996f80bd91..8ffb02a8974 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2800,11 +2800,11 @@ "category": "Error", "code": 6133 }, - "Report Errors on Unused Locals.": { + "Report errors on unused locals.": { "category": "Message", "code": 6134 }, - "Report Errors on Unused Parameters.": { + "Report errors on unused parameters.": { "category": "Message", "code": 6135 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2d5acb3b486..9c36dff481f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -614,7 +614,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge const sourceMappingURL = sourceMap.getSourceMappingURL(); if (sourceMappingURL) { - write(`//# sourceMappingURL=${sourceMappingURL}`); + write(`//# ${"sourceMappingURL"}=${sourceMappingURL}`); // Sometimes tools can sometimes see this line as a source mapping url comment } writeEmittedFiles(writer.getText(), jsFilePath, sourceMapFilePath, /*writeByteOrderMark*/ compilerOptions.emitBOM, sourceFiles); @@ -2749,7 +2749,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge * if we should also export the value after its it changed * - check if node is a source level declaration to emit it differently, * i.e non-exported variable statement 'var x = 1' is hoisted so - * we we emit variable statement 'var' should be dropped. + * when we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean { if (!node || !isCurrentFileSystemExternalModule()) { @@ -4571,14 +4571,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function emitRestParameter(node: FunctionLikeDeclaration) { if (languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node)) { - const restIndex = node.parameters.length - 1; - const restParam = node.parameters[restIndex]; + const restParam = node.parameters[node.parameters.length - 1]; // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. if (isBindingPattern(restParam.name)) { return; } + const skipThisCount = node.parameters.length && (node.parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword ? 1 : 0; + const restIndex = node.parameters.length - 1 - skipThisCount; const tempName = createTempVariable(TempFlags._i).text; writeLine(); emitLeadingComments(restParam); @@ -4726,7 +4727,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge write("("); if (node) { const parameters = node.parameters; - const skipCount = node.parameters.length && (node.parameters[0].name).text === "this" ? 1 : 0; + const skipCount = node.parameters.length && (node.parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword ? 1 : 0; const omitCount = languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node) ? 1 : 0; emitList(parameters, skipCount, parameters.length - omitCount - skipCount, /*multiLine*/ false, /*trailingComma*/ false); } @@ -5503,16 +5504,15 @@ const _super = (function (geti, seti) { write("export "); } - if (!isHoistedDeclarationInSystemModule) { - write("let "); - } if (decoratedClassAlias !== undefined) { - write(`${decoratedClassAlias}`); + write(`let ${decoratedClassAlias}`); } else { + if (!isHoistedDeclarationInSystemModule) { + write("let "); + } emitDeclarationName(node); } - write(" = "); } else if (isES6ExportedDeclaration(node)) { @@ -5530,7 +5530,9 @@ const _super = (function (geti, seti) { // // We'll emit: // - // (_temp = class C { ... }, _temp.a = 1, _temp.b = 2, _temp) + // let C_1 = class C{}; + // C_1.a = 1; + // C_1.b = 2; // so forth and so on // // This keeps the expression as an expression, while ensuring that the static parts // of it have been initialized by the time it is used. @@ -6155,10 +6157,11 @@ const _super = (function (geti, seti) { if (valueDeclaration) { const parameters = valueDeclaration.parameters; + const skipThisCount = parameters.length && (parameters[0].name).originalKeywordKind === SyntaxKind.ThisKeyword ? 1 : 0; const parameterCount = parameters.length; - if (parameterCount > 0) { - for (let i = 0; i < parameterCount; i++) { - if (i > 0) { + if (parameterCount > skipThisCount) { + for (let i = skipThisCount; i < parameterCount; i++) { + if (i > skipThisCount) { write(", "); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e12ff7c87dc..774cea60e09 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2,15 +2,21 @@ /// namespace ts { - /* @internal */ export let parseTime = 0; - let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; + let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; + let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; export function createNode(kind: SyntaxKind, pos?: number, end?: number): Node { if (kind === SyntaxKind.SourceFile) { return new (SourceFileConstructor || (SourceFileConstructor = objectAllocator.getSourceFileConstructor()))(kind, pos, end); } + else if (kind === SyntaxKind.Identifier) { + return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, pos, end); + } + else if (kind < SyntaxKind.FirstNode) { + return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, pos, end); + } else { return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, pos, end); } @@ -413,10 +419,10 @@ namespace ts { } export function createSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, setParentNodes = false, scriptKind?: ScriptKind): SourceFile { - const start = new Date().getTime(); + const start = performance.mark(); const result = Parser.parseSourceFile(fileName, sourceText, languageVersion, /*syntaxCursor*/ undefined, setParentNodes, scriptKind); - parseTime += new Date().getTime() - start; + performance.measure("Parse", start); return result; } @@ -466,6 +472,8 @@ namespace ts { // capture constructors in 'initializeState' to avoid null checks let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; + let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; + let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node; let sourceFile: SourceFile; @@ -576,6 +584,8 @@ namespace ts { function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, scriptKind: ScriptKind) { NodeConstructor = objectAllocator.getNodeConstructor(); + TokenConstructor = objectAllocator.getTokenConstructor(); + IdentifierConstructor = objectAllocator.getIdentifierConstructor(); SourceFileConstructor = objectAllocator.getSourceFileConstructor(); sourceText = _sourceText; @@ -1018,13 +1028,15 @@ namespace ts { } // note: this function creates only node - function createNode(kind: SyntaxKind, pos?: number): Node { + function createNode(kind: SyntaxKind, pos?: number): Node | Token | Identifier { nodeCount++; if (!(pos >= 0)) { pos = scanner.getStartPos(); } - return new NodeConstructor(kind, pos, pos); + return kind >= SyntaxKind.FirstNode ? new NodeConstructor(kind, pos, pos) : + kind === SyntaxKind.Identifier ? new IdentifierConstructor(kind, pos, pos) : + new TokenConstructor(kind, pos, pos); } function finishNode(node: T, end?: number): T { @@ -5096,7 +5108,7 @@ namespace ts { } flags |= modifierToFlag(modifierKind); - modifiers.push(finishNode(createNode(modifierKind, modifierStart))); + modifiers.push(finishNode(createNode(modifierKind, modifierStart))); } if (modifiers) { modifiers.flags = flags; @@ -5115,7 +5127,7 @@ namespace ts { modifiers = []; modifiers.pos = modifierStart; flags |= modifierToFlag(modifierKind); - modifiers.push(finishNode(createNode(modifierKind, modifierStart))); + modifiers.push(finishNode(createNode(modifierKind, modifierStart))); modifiers.flags = flags; modifiers.end = scanner.getStartPos(); } diff --git a/src/compiler/performance.ts b/src/compiler/performance.ts new file mode 100644 index 00000000000..63f929c0a26 --- /dev/null +++ b/src/compiler/performance.ts @@ -0,0 +1,109 @@ +/*@internal*/ +namespace ts { + declare const performance: { now?(): number } | undefined; + /** Gets a timestamp with (at least) ms resolution */ + export const timestamp = typeof performance !== "undefined" && performance.now ? performance.now : Date.now ? Date.now : () => +(new Date()); +} + +/*@internal*/ +namespace ts.performance { + /** Performance measurements for the compiler. */ + declare const onProfilerEvent: { (markName: string): void; profiler: boolean; }; + let profilerEvent: (markName: string) => void; + let counters: Map; + let measures: Map; + + /** + * Emit a performance event if ts-profiler is connected. This is primarily used + * to generate heap snapshots. + * + * @param eventName A name for the event. + */ + export function emit(eventName: string) { + if (profilerEvent) { + profilerEvent(eventName); + } + } + + /** + * Increments a counter with the specified name. + * + * @param counterName The name of the counter. + */ + export function increment(counterName: string) { + if (counters) { + counters[counterName] = (getProperty(counters, counterName) || 0) + 1; + } + } + + /** + * Gets the value of the counter with the specified name. + * + * @param counterName The name of the counter. + */ + export function getCount(counterName: string) { + return counters && getProperty(counters, counterName) || 0; + } + + /** + * Marks the start of a performance measurement. + */ + export function mark() { + return measures ? timestamp() : 0; + } + + /** + * Adds a performance measurement with the specified name. + * + * @param measureName The name of the performance measurement. + * @param marker The timestamp of the starting mark. + */ + export function measure(measureName: string, marker: number) { + if (measures) { + measures[measureName] = (getProperty(measures, measureName) || 0) + (timestamp() - marker); + } + } + + /** + * Iterate over each measure, performing some action + * + * @param cb The action to perform for each measure + */ + export function forEachMeasure(cb: (measureName: string, duration: number) => void) { + return forEachKey(measures, key => cb(key, measures[key])); + } + + /** + * Gets the total duration of all measurements with the supplied name. + * + * @param measureName The name of the measure whose durations should be accumulated. + */ + export function getDuration(measureName: string) { + return measures && getProperty(measures, measureName) || 0; + } + + /** Enables (and resets) performance measurements for the compiler. */ + export function enable() { + counters = { }; + measures = { + "I/O Read": 0, + "I/O Write": 0, + "Program": 0, + "Parse": 0, + "Bind": 0, + "Check": 0, + "Emit": 0, + }; + + profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true + ? onProfilerEvent + : undefined; + } + + /** Disables (and clears) performance measurements for the compiler. */ + export function disable() { + counters = undefined; + measures = undefined; + profilerEvent = undefined; + } +} \ No newline at end of file diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 320b628c31a..988714be2ab 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3,11 +3,6 @@ /// namespace ts { - /* @internal */ export let programTime = 0; - /* @internal */ export let emitTime = 0; - /* @internal */ export let ioReadTime = 0; - /* @internal */ export let ioWriteTime = 0; - /** The version of the TypeScript compiler release */ export const version = "2.1.0"; @@ -112,13 +107,7 @@ namespace ts { } function moduleHasNonRelativeName(moduleName: string): boolean { - if (isRootedDiskPath(moduleName)) { - return false; - } - - const i = moduleName.lastIndexOf("./", 1); - const startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === CharacterCodes.dot); - return !startsWithDotSlashOrDotDotSlash; + return !(isRootedDiskPath(moduleName) || isExternalModuleNameRelative(moduleName)); } interface ModuleResolutionState { @@ -871,9 +860,9 @@ namespace ts { function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile { let text: string; try { - const start = new Date().getTime(); + const start = performance.mark(); text = sys.readFile(fileName, options.charset); - ioReadTime += new Date().getTime() - start; + performance.measure("I/O Read", start); } catch (e) { if (onError) { @@ -940,7 +929,7 @@ namespace ts { function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { - const start = new Date().getTime(); + const start = performance.mark(); ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); if (isWatchSet(options) && sys.createHash && sys.getModifiedTime) { @@ -950,7 +939,7 @@ namespace ts { sys.writeFile(fileName, data, writeByteOrderMark); } - ioWriteTime += new Date().getTime() - start; + performance.measure("I/O Write", start); } catch (e) { if (onError) { @@ -997,6 +986,29 @@ namespace ts { return sortAndDeduplicateDiagnostics(diagnostics); } + export interface FormatDiagnosticsHost { + getCurrentDirectory(): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + } + + export function formatDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): string { + let output = ""; + + for (const diagnostic of diagnostics) { + if (diagnostic.file) { + const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + const fileName = diagnostic.file.fileName; + const relativeFileName = convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)); + output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `; + } + + const category = DiagnosticCategory[diagnostic.category].toLowerCase(); + output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }${ host.getNewLine() }`; + } + return output; + } + export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string { if (typeof messageText === "string") { return messageText; @@ -1104,7 +1116,7 @@ namespace ts { // Track source files that are source files found by searching under node_modules, as these shouldn't be compiled. const sourceFilesFoundSearchingNodeModules: Map = {}; - const start = new Date().getTime(); + const start = performance.mark(); host = host || createCompilerHost(options); @@ -1203,7 +1215,7 @@ namespace ts { verifyCompilerOptions(); - programTime += new Date().getTime() - start; + performance.measure("Program", start); return program; @@ -1446,14 +1458,14 @@ namespace ts { // checked is to not pass the file to getEmitResolver. const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile); - const start = new Date().getTime(); + const start = performance.mark(); const emitResult = emitFiles( emitResolver, getEmitHost(writeFileCallback), sourceFile); - emitTime += new Date().getTime() - start; + performance.measure("Emit", start); return emitResult; } diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index cf7c3d1eaae..2d8c36a3d02 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -240,6 +240,8 @@ namespace ts { return; } + const start = performance.mark(); + const sourceLinePos = getLineAndCharacterOfPosition(currentSourceFile, pos); // Convert the location to be one-based. @@ -279,6 +281,8 @@ namespace ts { } updateLastEncodedAndRecordedSpans(); + + performance.measure("Source Map", start); } function getStartPos(range: TextRange) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e25ae37e21f..10538d0c009 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -6,9 +6,19 @@ namespace ts { fileWatcher?: FileWatcher; } - let reportDiagnostic = reportDiagnosticSimply; + const defaultFormatDiagnosticsHost: FormatDiagnosticsHost = { + getCurrentDirectory: () => sys.getCurrentDirectory(), + getNewLine: () => sys.newLine, + getCanonicalFileName: createGetCanonicalFileName(sys.useCaseSensitiveFileNames) + }; - function reportDiagnostics(diagnostics: Diagnostic[], host: CompilerHost): void { + let reportDiagnosticWorker = reportDiagnosticSimply; + + function reportDiagnostic(diagnostic: Diagnostic, host: FormatDiagnosticsHost) { + reportDiagnosticWorker(diagnostic, host || defaultFormatDiagnosticsHost); + } + + function reportDiagnostics(diagnostics: Diagnostic[], host: FormatDiagnosticsHost): void { for (const diagnostic of diagnostics) { reportDiagnostic(diagnostic, host); } @@ -101,23 +111,8 @@ namespace ts { return diagnostic.messageText; } - function getRelativeFileName(fileName: string, host: CompilerHost): string { - return host ? convertToRelativePath(fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : fileName; - } - - function reportDiagnosticSimply(diagnostic: Diagnostic, host: CompilerHost): void { - let output = ""; - - if (diagnostic.file) { - const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); - const relativeFileName = getRelativeFileName(diagnostic.file.fileName, host); - output += `${ relativeFileName }(${ line + 1 },${ character + 1 }): `; - } - - const category = DiagnosticCategory[diagnostic.category].toLowerCase(); - output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`; - - sys.write(output); + function reportDiagnosticSimply(diagnostic: Diagnostic, host: FormatDiagnosticsHost): void { + sys.write(ts.formatDiagnostics([diagnostic], host)); } const redForegroundEscapeSequence = "\u001b[91m"; @@ -137,7 +132,7 @@ namespace ts { return formatStyle + text + resetEscapeSequence; } - function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic, host: CompilerHost): void { + function reportDiagnosticWithColorAndContext(diagnostic: Diagnostic, host: FormatDiagnosticsHost): void { let output = ""; if (diagnostic.file) { @@ -145,7 +140,7 @@ namespace ts { const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); const lastLineInFile = getLineAndCharacterOfPosition(file, file.text.length).line; - const relativeFileName = getRelativeFileName(file.fileName, host); + const relativeFileName = host ? convertToRelativePath(file.fileName, host.getCurrentDirectory(), fileName => host.getCanonicalFileName(fileName)) : file.fileName; const hasMoreThanFiveLines = (lastLine - firstLine) >= 4; let gutterWidth = (lastLine + 1 + "").length; @@ -272,7 +267,7 @@ namespace ts { if (commandLine.options.locale) { if (!isJSONSupported()) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--locale"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } validateLocaleAndSetLanguage(commandLine.options.locale, commandLine.errors); @@ -303,11 +298,11 @@ namespace ts { if (commandLine.options.project) { if (!isJSONSupported()) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--project"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } if (commandLine.fileNames.length !== 0) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } @@ -315,14 +310,14 @@ namespace ts { if (!fileOrDirectory /* current directory "." */ || sys.directoryExists(fileOrDirectory)) { configFileName = combinePaths(fileOrDirectory, "tsconfig.json"); if (!sys.fileExists(configFileName)) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0, commandLine.options.project), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Cannot_find_a_tsconfig_json_file_at_the_specified_directory_Colon_0, commandLine.options.project), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } } else { configFileName = fileOrDirectory; if (!sys.fileExists(configFileName)) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, commandLine.options.project), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_specified_path_does_not_exist_Colon_0, commandLine.options.project), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } } @@ -340,7 +335,7 @@ namespace ts { if (isWatchSet(commandLine.options)) { if (!sys.watchFile) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* host */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } if (configFileName) { @@ -385,7 +380,8 @@ namespace ts { sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); return; } - const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), sys.getCurrentDirectory()), commandLine.options, configFileName); + const cwd = sys.getCurrentDirectory(); + const configParseResult = parseJsonConfigFileContent(configObject, sys, getNormalizedAbsolutePath(getDirectoryPath(configFileName), cwd), commandLine.options, getNormalizedAbsolutePath(configFileName, cwd)); if (configParseResult.errors.length > 0) { reportDiagnostics(configParseResult.errors, /* compilerHost */ undefined); sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); @@ -393,7 +389,7 @@ namespace ts { } if (isWatchSet(configParseResult.options)) { if (!sys.watchFile) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* host */ undefined); sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } @@ -432,7 +428,7 @@ namespace ts { } if (compilerOptions.pretty) { - reportDiagnostic = reportDiagnosticWithColorAndContext; + reportDiagnosticWorker = reportDiagnosticWithColorAndContext; } // reset the cache of existing files @@ -554,12 +550,8 @@ namespace ts { } function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) { - ioReadTime = 0; - ioWriteTime = 0; - programTime = 0; - bindTime = 0; - checkTime = 0; - emitTime = 0; + const hasDiagnostics = compilerOptions.diagnostics || compilerOptions.extendedDiagnostics; + if (hasDiagnostics) performance.enable(); const program = createProgram(fileNames, compilerOptions, compilerHost); const exitStatus = compileProgram(); @@ -570,7 +562,7 @@ namespace ts { }); } - if (compilerOptions.diagnostics) { + if (hasDiagnostics) { const memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); @@ -583,17 +575,28 @@ namespace ts { reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K"); } - // Individual component times. - // Note: To match the behavior of previous versions of the compiler, the reported parse time includes - // I/O read time and processing time for triple-slash references and module imports, and the reported - // emit time includes I/O write time. We preserve this behavior so we can accurately compare times. - reportTimeStatistic("I/O read", ioReadTime); - reportTimeStatistic("I/O write", ioWriteTime); - reportTimeStatistic("Parse time", programTime); - reportTimeStatistic("Bind time", bindTime); - reportTimeStatistic("Check time", checkTime); - reportTimeStatistic("Emit time", emitTime); + const programTime = performance.getDuration("Program"); + const bindTime = performance.getDuration("Bind"); + const checkTime = performance.getDuration("Check"); + const emitTime = performance.getDuration("Emit"); + if (compilerOptions.extendedDiagnostics) { + performance.forEachMeasure((name, duration) => reportTimeStatistic(`${name} time`, duration)); + } + else { + // Individual component times. + // Note: To match the behavior of previous versions of the compiler, the reported parse time includes + // I/O read time and processing time for triple-slash references and module imports, and the reported + // emit time includes I/O write time. We preserve this behavior so we can accurately compare times. + reportTimeStatistic("I/O read", performance.getDuration("I/O Read")); + reportTimeStatistic("I/O write", performance.getDuration("I/O Write")); + reportTimeStatistic("Parse time", programTime); + reportTimeStatistic("Bind time", bindTime); + reportTimeStatistic("Check time", checkTime); + reportTimeStatistic("Emit time", emitTime); + } reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime); + + performance.disable(); } return { program, exitStatus }; @@ -657,7 +660,7 @@ namespace ts { // Build up the list of examples. const padding = makePadding(marginLength); output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; - output += padding + "tsc --out file.js file.ts" + sys.newLine; + output += padding + "tsc --outFile file.js file.ts" + sys.newLine; output += padding + "tsc @args.txt" + sys.newLine; output += sys.newLine; @@ -757,7 +760,7 @@ namespace ts { const currentDirectory = sys.getCurrentDirectory(); const file = normalizePath(combinePaths(currentDirectory, "tsconfig.json")); if (sys.fileExists(file)) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.A_tsconfig_json_file_is_already_defined_at_Colon_0, file), /* host */ undefined); } else { const compilerOptions = extend(options, defaultInitCompilerOptions); @@ -777,7 +780,7 @@ namespace ts { } sys.writeFile(file, JSON.stringify(configurations, undefined, 4)); - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* compilerHost */ undefined); + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Successfully_created_a_tsconfig_json_file), /* host */ undefined); } return; diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index 827a9b81c4d..cc9bfddcece 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -12,6 +12,7 @@ }, "files": [ "core.ts", + "performance.ts", "sys.ts", "types.ts", "scanner.ts", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3a3a937ade7..dc332b24567 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -472,6 +472,10 @@ namespace ts { flags: NodeFlags; } + export interface Token extends Node { + __tokenTag: any; + } + // @kind(SyntaxKind.AbstractKeyword) // @kind(SyntaxKind.AsyncKeyword) // @kind(SyntaxKind.ConstKeyword) @@ -482,7 +486,7 @@ namespace ts { // @kind(SyntaxKind.PrivateKeyword) // @kind(SyntaxKind.ProtectedKeyword) // @kind(SyntaxKind.StaticKeyword) - export interface Modifier extends Node { } + export interface Modifier extends Token { } // @kind(SyntaxKind.Identifier) export interface Identifier extends PrimaryExpression { @@ -2535,6 +2539,7 @@ namespace ts { declaration?: boolean; declarationDir?: string; /* @internal */ diagnostics?: boolean; + /* @internal */ extendedDiagnostics?: boolean; disableSizeLimit?: boolean; emitBOM?: boolean; emitDecoratorMetadata?: boolean; @@ -2908,7 +2913,6 @@ namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; - getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; getDirectories(path: string): string[]; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6f3a1d6d813..7219a5bbd24 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1218,7 +1218,7 @@ namespace ts { export function isExternalModuleNameRelative(moduleName: string): boolean { // TypeScript 1.0 spec (April 2014): 11.2.1 // An external module name is "relative" if the first term is "." or "..". - return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\"; + return /^\.\.?($|[\\/])/.test(moduleName); } export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) { @@ -3113,13 +3113,4 @@ namespace ts { export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean { return node.flags & NodeFlags.ParameterPropertyModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); } - - export function startsWith(str: string, prefix: string): boolean { - return str.lastIndexOf(prefix, 0) === 0; - } - - export function endsWith(str: string, suffix: string): boolean { - const expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 1834b0b3bbc..ecdc18394b0 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -50,7 +50,9 @@ class CompilerBaselineRunner extends RunnerBase { } private makeUnitName(name: string, root: string) { - return ts.isRootedDiskPath(name) ? name : ts.combinePaths(root, name); + const path = ts.toPath(name, root, (fileName) => Harness.Compiler.getCanonicalFileName(fileName)); + const pathStart = ts.toPath(Harness.IO.getCurrentDirectory(), "", (fileName) => Harness.Compiler.getCanonicalFileName(fileName)); + return path.replace(pathStart, "/"); }; public checkTestCodeOutput(fileName: string) { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 6afb0cfccdb..534778fdab8 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1377,31 +1377,27 @@ namespace Harness { writeByteOrderMark: boolean; } - function stringEndsWith(str: string, end: string) { - return str.substr(str.length - end.length) === end; - } - export function isTS(fileName: string) { - return stringEndsWith(fileName, ".ts"); + return ts.endsWith(fileName, ".ts"); } export function isTSX(fileName: string) { - return stringEndsWith(fileName, ".tsx"); + return ts.endsWith(fileName, ".tsx"); } export function isDTS(fileName: string) { - return stringEndsWith(fileName, ".d.ts"); + return ts.endsWith(fileName, ".d.ts"); } export function isJS(fileName: string) { - return stringEndsWith(fileName, ".js"); + return ts.endsWith(fileName, ".js"); } export function isJSX(fileName: string) { - return stringEndsWith(fileName, ".jsx"); + return ts.endsWith(fileName, ".jsx"); } export function isJSMap(fileName: string) { - return stringEndsWith(fileName, ".js.map") || stringEndsWith(fileName, ".jsx.map"); + return ts.endsWith(fileName, ".js.map") || ts.endsWith(fileName, ".jsx.map"); } /** Contains the code and errors of a compilation and some helper methods to check its status. */ diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index cf3c78d8859..038b2dbe359 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -328,7 +328,7 @@ class ProjectRunner extends RunnerBase { if (Harness.Compiler.isJS(fileName)) { // Make sure if there is URl we have it cleaned up - const indexOfSourceMapUrl = data.lastIndexOf("//# sourceMappingURL="); + const indexOfSourceMapUrl = data.lastIndexOf(`//# ${"sourceMappingURL"}=`); // This line can be seen as a sourceMappingURL comment if (indexOfSourceMapUrl !== -1) { data = data.substring(0, indexOfSourceMapUrl + 21) + cleanProjectUrl(data.substring(indexOfSourceMapUrl + 21)); } diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 5853bee3274..3b9025c27c3 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -14,6 +14,7 @@ }, "files": [ "../compiler/core.ts", + "../compiler/performance.ts", "../compiler/sys.ts", "../compiler/types.ts", "../compiler/scanner.ts", diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 77b960409c2..6f017c8a343 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -513,8 +513,8 @@ interface NumberConstructor { /** An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers. */ declare const Number: NumberConstructor; -interface TemplateStringsArray extends Array { - readonly raw: string[]; +interface TemplateStringsArray extends ReadonlyArray { + readonly raw: ReadonlyArray } interface Math { diff --git a/src/services/patternMatcher.ts b/src/services/patternMatcher.ts index 93cc5130d72..3d20337eca7 100644 --- a/src/services/patternMatcher.ts +++ b/src/services/patternMatcher.ts @@ -514,16 +514,6 @@ namespace ts { return str === str.toLowerCase(); } - function startsWith(string: string, search: string) { - for (let i = 0, n = search.length; i < n; i++) { - if (string.charCodeAt(i) !== search.charCodeAt(i)) { - return false; - } - } - - return true; - } - // Assumes 'value' is already lowercase. function indexOfIgnoringCase(string: string, value: string): number { for (let i = 0, n = string.length - value.length; i <= n; i++) { diff --git a/src/services/services.ts b/src/services/services.ts index 8c69b66c7d8..3b8be487aba 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -94,7 +94,7 @@ namespace ts { * change range cannot be determined. However, in that case, incremental parsing will * not happen and the entire document will be re - parsed. */ - getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange; + getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; /** Releases all resources held by this script snapshot */ dispose?(): void; @@ -180,9 +180,10 @@ namespace ts { ]; let jsDocCompletionEntries: CompletionEntry[]; - function createNode(kind: SyntaxKind, pos: number, end: number, flags: NodeFlags, parent?: Node): NodeObject { - const node = new NodeObject(kind, pos, end); - node.flags = flags; + function createNode(kind: SyntaxKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject { + const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) : + kind === SyntaxKind.Identifier ? new IdentifierObject(kind, pos, end) : + new TokenObject(kind, pos, end); node.parent = parent; return node; } @@ -197,11 +198,11 @@ namespace ts { private _children: Node[]; constructor(kind: SyntaxKind, pos: number, end: number) { - this.kind = kind; this.pos = pos; this.end = end; this.flags = NodeFlags.None; this.parent = undefined; + this.kind = kind; } public getSourceFile(): SourceFile { @@ -246,7 +247,7 @@ namespace ts { const token = useJSDocScanner ? scanner.scanJSDocToken() : scanner.scan(); const textPos = scanner.getTextPos(); if (textPos <= end) { - nodes.push(createNode(token, pos, textPos, 0, this)); + nodes.push(createNode(token, pos, textPos, this)); } pos = textPos; } @@ -254,7 +255,7 @@ namespace ts { } private createSyntaxList(nodes: NodeArray): Node { - const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, 0, this); + const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, this); list._children = []; let pos = nodes.pos; @@ -345,6 +346,95 @@ namespace ts { } } + class TokenOrIdentifierObject implements Token { + public kind: SyntaxKind; + public pos: number; + public end: number; + public flags: NodeFlags; + public parent: Node; + public jsDocComments: JSDocComment[]; + public __tokenTag: any; + + constructor(pos: number, end: number) { + // Set properties in same order as NodeObject + this.pos = pos; + this.end = end; + this.flags = NodeFlags.None; + this.parent = undefined; + } + + public getSourceFile(): SourceFile { + return getSourceFileOfNode(this); + } + + public getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number { + return getTokenPosOfNode(this, sourceFile, includeJsDocComment); + } + + public getFullStart(): number { + return this.pos; + } + + public getEnd(): number { + return this.end; + } + + public getWidth(sourceFile?: SourceFile): number { + return this.getEnd() - this.getStart(sourceFile); + } + + public getFullWidth(): number { + return this.end - this.pos; + } + + public getLeadingTriviaWidth(sourceFile?: SourceFile): number { + return this.getStart(sourceFile) - this.pos; + } + + public getFullText(sourceFile?: SourceFile): string { + return (sourceFile || this.getSourceFile()).text.substring(this.pos, this.end); + } + + public getText(sourceFile?: SourceFile): string { + return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + } + + public getChildCount(sourceFile?: SourceFile): number { + return 0; + } + + public getChildAt(index: number, sourceFile?: SourceFile): Node { + return undefined; + } + + public getChildren(sourceFile?: SourceFile): Node[] { + return emptyArray; + } + + public getFirstToken(sourceFile?: SourceFile): Node { + return undefined; + } + + public getLastToken(sourceFile?: SourceFile): Node { + return undefined; + } + } + + class TokenObject extends TokenOrIdentifierObject { + public kind: SyntaxKind; + constructor(kind: SyntaxKind, pos: number, end: number) { + super(pos, end); + this.kind = kind; + } + } + + class IdentifierObject extends TokenOrIdentifierObject { + constructor(kind: SyntaxKind, pos: number, end: number) { + super(pos, end); + } + } + IdentifierObject.prototype.kind = SyntaxKind.Identifier; + class SymbolObject implements Symbol { flags: SymbolFlags; name: string; @@ -3259,14 +3349,14 @@ namespace ts { let isJsDocTagName = false; - let start = new Date().getTime(); + let start = timestamp(); const currentToken = getTokenAtPosition(sourceFile, position); - log("getCompletionData: Get current token: " + (new Date().getTime() - start)); + log("getCompletionData: Get current token: " + (timestamp() - start)); - start = new Date().getTime(); + start = timestamp(); // Completion not allowed inside comments, bail out if this is the case const insideComment = isInsideComment(sourceFile, currentToken, position); - log("getCompletionData: Is inside comment: " + (new Date().getTime() - start)); + log("getCompletionData: Is inside comment: " + (timestamp() - start)); if (insideComment) { // The current position is next to the '@' sign, when no tag name being provided yet. @@ -3309,9 +3399,9 @@ namespace ts { } } - start = new Date().getTime(); + start = timestamp(); const previousToken = findPrecedingToken(position, sourceFile); - log("getCompletionData: Get previous token 1: " + (new Date().getTime() - start)); + log("getCompletionData: Get previous token 1: " + (timestamp() - start)); // The decision to provide completion depends on the contextToken, which is determined through the previousToken. // Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file @@ -3320,9 +3410,9 @@ namespace ts { // Check if the caret is at the end of an identifier; this is a partial identifier that we want to complete: e.g. a.toS| // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && isWord(contextToken.kind)) { - const start = new Date().getTime(); + const start = timestamp(); contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile); - log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start)); + log("getCompletionData: Get previous token 2: " + (timestamp() - start)); } // Find the node where completion is requested on. @@ -3369,7 +3459,7 @@ namespace ts { } } - const semanticStart = new Date().getTime(); + const semanticStart = timestamp(); let isMemberCompletion: boolean; let isNewIdentifierLocation: boolean; let symbols: Symbol[] = []; @@ -3407,7 +3497,7 @@ namespace ts { } } - log("getCompletionData: Semantic work: " + (new Date().getTime() - semanticStart)); + log("getCompletionData: Semantic work: " + (timestamp() - semanticStart)); return { symbols, isMemberCompletion, isNewIdentifierLocation, location, isRightOfDot: (isRightOfDot || isRightOfOpenTag), isJsDocTagName }; @@ -3551,12 +3641,12 @@ namespace ts { } function isCompletionListBlocker(contextToken: Node): boolean { - const start = new Date().getTime(); + const start = timestamp(); const result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isSolelyIdentifierDefinitionLocation(contextToken) || isDotOfNumericLiteral(contextToken) || isInJsxText(contextToken); - log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); + log("getCompletionsAtPosition: isCompletionListBlocker: " + (timestamp() - start)); return result; } @@ -4206,10 +4296,11 @@ namespace ts { kindModifiers: getSymbolModifiers(symbol), sortText: "0", }; + } function getCompletionEntriesFromSymbols(symbols: Symbol[], entries: CompletionEntry[], location: Node, performCharacterChecks: boolean): Map { - const start = new Date().getTime(); + const start = timestamp(); const uniqueNames: Map = {}; if (symbols) { for (const symbol of symbols) { @@ -4224,7 +4315,7 @@ namespace ts { } } - log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (new Date().getTime() - start)); + log("getCompletionsAtPosition: getCompletionEntriesFromSymbols: " + (timestamp() - start)); return uniqueNames; } @@ -4234,22 +4325,58 @@ namespace ts { return undefined; } - const argumentInfo = SignatureHelp.getContainingArgumentInfo(node, position, sourceFile); - if (argumentInfo) { - // Get string literal completions from specialized signatures of the target - return getStringLiteralCompletionEntriesFromCallExpression(argumentInfo); + if (node.parent.kind === SyntaxKind.PropertyAssignment && node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression) { + // Get quoted name of properties of the object literal expression + // i.e. interface ConfigFiles { + // 'jspm:dev': string + // } + // let files: ConfigFiles = { + // '/*completion position*/' + // } + // + // function foo(c: ConfigFiles) {} + // foo({ + // '/*completion position*/' + // }); + return getStringLiteralCompletionEntriesFromPropertyAssignment(node.parent); } else if (isElementAccessExpression(node.parent) && node.parent.argumentExpression === node) { // Get all names of properties on the expression + // i.e. interface A { + // 'prop1': string + // } + // let a: A; + // a['/*completion position*/'] return getStringLiteralCompletionEntriesFromElementAccess(node.parent); } else { - // Otherwise, get the completions from the contextual type if one exists + const argumentInfo = SignatureHelp.getContainingArgumentInfo(node, position, sourceFile); + if (argumentInfo) { + // Get string literal completions from specialized signatures of the target + // i.e. declare function f(a: 'A'); + // f("/*completion position*/") + return getStringLiteralCompletionEntriesFromCallExpression(argumentInfo, node); + } + + // Get completion for string literal from string literal type + // i.e. var x: "hi" | "hello" = "/*completion position*/" return getStringLiteralCompletionEntriesFromContextualType(node); } } - function getStringLiteralCompletionEntriesFromCallExpression(argumentInfo: SignatureHelp.ArgumentListInfo) { + function getStringLiteralCompletionEntriesFromPropertyAssignment(element: ObjectLiteralElement) { + const typeChecker = program.getTypeChecker(); + const type = typeChecker.getContextualType((element.parent)); + const entries: CompletionEntry[] = []; + if (type) { + getCompletionEntriesFromSymbols(type.getApparentProperties(), entries, element, /*performCharacterChecks*/false); + if (entries.length) { + return { isMemberCompletion: true, isNewIdentifierLocation: true, entries }; + } + } + } + + function getStringLiteralCompletionEntriesFromCallExpression(argumentInfo: SignatureHelp.ArgumentListInfo, location: Node) { const typeChecker = program.getTypeChecker(); const candidates: Signature[] = []; const entries: CompletionEntry[] = []; @@ -7645,14 +7772,14 @@ namespace ts { } function getIndentationAtPosition(fileName: string, position: number, editorOptions: EditorOptions) { - let start = new Date().getTime(); + let start = timestamp(); const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - log("getIndentationAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start)); + log("getIndentationAtPosition: getCurrentSourceFile: " + (timestamp() - start)); - start = new Date().getTime(); + start = timestamp(); const result = formatting.SmartIndenter.getIndentation(position, sourceFile, editorOptions); - log("getIndentationAtPosition: computeIndentation : " + (new Date().getTime() - start)); + log("getIndentationAtPosition: computeIndentation : " + (timestamp() - start)); return result; } @@ -8694,6 +8821,8 @@ namespace ts { function initializeServices() { objectAllocator = { getNodeConstructor: () => NodeObject, + getTokenConstructor: () => TokenObject, + getIdentifierConstructor: () => IdentifierObject, getSourceFileConstructor: () => SourceFileObject, getSymbolConstructor: () => SymbolObject, getTypeConstructor: () => TypeObject, diff --git a/src/services/shims.ts b/src/services/shims.ts index e85bf537d30..271d6f2d6e2 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -423,7 +423,7 @@ namespace ts { } public isCancellationRequested(): boolean { - const time = Date.now(); + const time = timestamp(); const duration = Math.abs(time - this.lastCancellationCheckTime); if (duration > 10) { // Check no more than once every 10 ms. @@ -498,13 +498,13 @@ namespace ts { let start: number; if (logPerformance) { logger.log(actionDescription); - start = Date.now(); + start = timestamp(); } const result = action(); if (logPerformance) { - const end = Date.now(); + const end = timestamp(); logger.log(`${actionDescription} completed in ${end - start} msec`); if (typeof result === "string") { let str = result; diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 86efd254937..cfeb7c2fcd5 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -13,6 +13,7 @@ }, "files": [ "../compiler/core.ts", + "../compiler/performance.ts", "../compiler/sys.ts", "../compiler/types.ts", "../compiler/scanner.ts", diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.js b/tests/baselines/reference/decoratedClassExportsCommonJS1.js new file mode 100644 index 00000000000..4a04d724f0c --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.js @@ -0,0 +1,28 @@ +//// [decoratedClassExportsCommonJS1.ts] +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} + +//// [decoratedClassExportsCommonJS1.js] +"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; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +let Testing123_1 = class Testing123 { +}; +let Testing123 = Testing123_1; +Testing123.prop1 = Testing123.prop0; +Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) +], Testing123); +exports.Testing123 = Testing123; diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols b/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols new file mode 100644 index 00000000000..3381ef7c06a --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.symbols @@ -0,0 +1,21 @@ +=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts === +declare var Something: any; +>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11)) +>v : Symbol(v, Decl(decoratedClassExportsCommonJS1.ts, 1, 12)) +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) + +export class Testing123 { +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) + + static prop0: string; +>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) + + static prop1 = Testing123.prop0; +>prop1 : Symbol(Testing123.prop1, Decl(decoratedClassExportsCommonJS1.ts, 3, 25)) +>Testing123.prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) +>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27)) +>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25)) +} diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS1.types b/tests/baselines/reference/decoratedClassExportsCommonJS1.types new file mode 100644 index 00000000000..0142adb654f --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS1.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts === +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { +>Testing123 : Testing123 + + static prop0: string; +>prop0 : string + + static prop1 = Testing123.prop0; +>prop1 : string +>Testing123.prop0 : string +>Testing123 : typeof Testing123 +>prop0 : string +} diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.js b/tests/baselines/reference/decoratedClassExportsCommonJS2.js new file mode 100644 index 00000000000..c5e8eb9aa29 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.js @@ -0,0 +1,26 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } + +//// [a.js] +"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; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +let Testing123_1 = class Testing123 { +}; +let Testing123 = Testing123_1; +Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) +], Testing123); +exports.Testing123 = Testing123; diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols b/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols new file mode 100644 index 00000000000..8f587c1bff1 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { } +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + diff --git a/tests/baselines/reference/decoratedClassExportsCommonJS2.types b/tests/baselines/reference/decoratedClassExportsCommonJS2.types new file mode 100644 index 00000000000..eba793247de --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsCommonJS2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { } +>Testing123 : Testing123 + diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.js b/tests/baselines/reference/decoratedClassExportsSystem1.js new file mode 100644 index 00000000000..1730ba4460f --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.js @@ -0,0 +1,39 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} + +//// [a.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + 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; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + }; + var Testing123; + return { + setters:[], + execute: function() { + let Testing123_1 = class Testing123 { + }; + let Testing123 = Testing123_1; + Testing123.prop1 = Testing123.prop0; + Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) + ], Testing123); + exports_1("Testing123", Testing123); + } + } +}); diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.symbols b/tests/baselines/reference/decoratedClassExportsSystem1.symbols new file mode 100644 index 00000000000..559f78624e3 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + + static prop0: string; +>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) + + static prop1 = Testing123.prop0; +>prop1 : Symbol(Testing123.prop1, Decl(a.ts, 5, 25)) +>Testing123.prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) +>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 4, 25)) +} diff --git a/tests/baselines/reference/decoratedClassExportsSystem1.types b/tests/baselines/reference/decoratedClassExportsSystem1.types new file mode 100644 index 00000000000..1cc69e8b680 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem1.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { +>Testing123 : Testing123 + + static prop0: string; +>prop0 : string + + static prop1 = Testing123.prop0; +>prop1 : string +>Testing123.prop0 : string +>Testing123 : typeof Testing123 +>prop0 : string +} diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.js b/tests/baselines/reference/decoratedClassExportsSystem2.js new file mode 100644 index 00000000000..b4d34de2958 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.js @@ -0,0 +1,35 @@ +//// [a.ts] + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } + +//// [a.js] +System.register([], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + 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; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; + }; + var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); + }; + var Testing123; + return { + setters:[], + execute: function() { + let Testing123_1 = class Testing123 { + }; + let Testing123 = Testing123_1; + Testing123 = Testing123_1 = __decorate([ + Something({ v: () => Testing123 }), + __metadata('design:paramtypes', []) + ], Testing123); + exports_1("Testing123", Testing123); + } + } +}); diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.symbols b/tests/baselines/reference/decoratedClassExportsSystem2.symbols new file mode 100644 index 00000000000..8f587c1bff1 --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0)) +>x : Symbol(x, Decl(a.ts, 1, 28)) + +declare var Something: any; +>Something : Symbol(Something, Decl(a.ts, 2, 11)) + +@Something({ v: () => Testing123 }) +>Something : Symbol(Something, Decl(a.ts, 2, 11)) +>v : Symbol(v, Decl(a.ts, 3, 12)) +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + +export class Testing123 { } +>Testing123 : Symbol(Testing123, Decl(a.ts, 2, 27)) + diff --git a/tests/baselines/reference/decoratedClassExportsSystem2.types b/tests/baselines/reference/decoratedClassExportsSystem2.types new file mode 100644 index 00000000000..eba793247de --- /dev/null +++ b/tests/baselines/reference/decoratedClassExportsSystem2.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +declare function forwardRef(x: any): any; +>forwardRef : (x: any) => any +>x : any + +declare var Something: any; +>Something : any + +@Something({ v: () => Testing123 }) +>Something({ v: () => Testing123 }) : any +>Something : any +>{ v: () => Testing123 } : { v: () => typeof Testing123; } +>v : () => typeof Testing123 +>() => Testing123 : () => typeof Testing123 +>Testing123 : typeof Testing123 + +export class Testing123 { } +>Testing123 : Testing123 + diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js index 35350c54e0a..6ca7e40d413 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js @@ -14,7 +14,7 @@ class A { class B { constructor(...args: number[]) {} @MyMethodDecorator - method(...args: string[]) {} + method(this: this, ...args: string[]) {} } diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols b/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols index b665b778f86..29ccb8b2711 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols @@ -37,8 +37,9 @@ class B { @MyMethodDecorator >MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13)) - method(...args: string[]) {} + method(this: this, ...args: string[]) {} >method : Symbol(B.method, Decl(emitDecoratorMetadata_restArgs.ts, 13, 37)) ->args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11)) +>this : Symbol(this, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11)) +>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 22)) } diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types index 4820d3a7d8d..e08261e4503 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types @@ -37,8 +37,9 @@ class B { @MyMethodDecorator >MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void - method(...args: string[]) {} ->method : (...args: string[]) => void + method(this: this, ...args: string[]) {} +>method : (this: this, ...args: string[]) => void +>this : this >args : string[] } diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.js b/tests/baselines/reference/emitSkipsThisWithRestParameter.js new file mode 100644 index 00000000000..d1e99f9409d --- /dev/null +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.js @@ -0,0 +1,18 @@ +//// [emitSkipsThisWithRestParameter.ts] +function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any { + return function(this: any, ...args: any[]) { + return fn.apply(this, [ this ].concat(args)); + }; +} + + +//// [emitSkipsThisWithRestParameter.js] +function rebase(fn) { + return function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + return fn.apply(this, [this].concat(args)); + }; +} diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.symbols b/tests/baselines/reference/emitSkipsThisWithRestParameter.symbols new file mode 100644 index 00000000000..4f1e2bc1aec --- /dev/null +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/emitSkipsThisWithRestParameter.ts === +function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any { +>rebase : Symbol(rebase, Decl(emitSkipsThisWithRestParameter.ts, 0, 0)) +>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16)) +>base : Symbol(base, Decl(emitSkipsThisWithRestParameter.ts, 0, 21)) +>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 0, 31)) +>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 0, 58)) + + return function(this: any, ...args: any[]) { +>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20)) +>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30)) + + return fn.apply(this, [ this ].concat(args)); +>fn.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) +>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) +>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20)) +>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) +>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20)) +>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --)) +>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30)) + + }; +} + diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.types b/tests/baselines/reference/emitSkipsThisWithRestParameter.types new file mode 100644 index 00000000000..97276fa117d --- /dev/null +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/emitSkipsThisWithRestParameter.ts === +function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any { +>rebase : (fn: (base: any, ...args: any[]) => any) => (...args: any[]) => any +>fn : (base: any, ...args: any[]) => any +>base : any +>args : any[] +>args : any[] + + return function(this: any, ...args: any[]) { +>function(this: any, ...args: any[]) { return fn.apply(this, [ this ].concat(args)); } : (this: any, ...args: any[]) => any +>this : any +>args : any[] + + return fn.apply(this, [ this ].concat(args)); +>fn.apply(this, [ this ].concat(args)) : any +>fn.apply : (this: Function, thisArg: any, argArray?: any) => any +>fn : (base: any, ...args: any[]) => any +>apply : (this: Function, thisArg: any, argArray?: any) => any +>this : any +>[ this ].concat(args) : any[] +>[ this ].concat : (...items: any[]) => any[] +>[ this ] : any[] +>this : any +>concat : (...items: any[]) => any[] +>args : any[] + + }; +} + diff --git a/tests/baselines/reference/noUsedBeforeDefinedErrorInAmbientContext1.symbols b/tests/baselines/reference/noUsedBeforeDefinedErrorInAmbientContext1.symbols new file mode 100644 index 00000000000..690a19ef18f --- /dev/null +++ b/tests/baselines/reference/noUsedBeforeDefinedErrorInAmbientContext1.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/test.d.ts === + +declare var S: typeof A; // no error +>S : Symbol(S, Decl(test.d.ts, 1, 11)) +>A : Symbol(A, Decl(test.d.ts, 2, 13)) + +declare const A: number; +>A : Symbol(A, Decl(test.d.ts, 2, 13)) + diff --git a/tests/baselines/reference/noUsedBeforeDefinedErrorInAmbientContext1.types b/tests/baselines/reference/noUsedBeforeDefinedErrorInAmbientContext1.types new file mode 100644 index 00000000000..dfacda30915 --- /dev/null +++ b/tests/baselines/reference/noUsedBeforeDefinedErrorInAmbientContext1.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/test.d.ts === + +declare var S: typeof A; // no error +>S : number +>A : number + +declare const A: number; +>A : number + diff --git a/tests/baselines/reference/relativeModuleWithoutSlash.js b/tests/baselines/reference/relativeModuleWithoutSlash.js new file mode 100644 index 00000000000..f83406499d4 --- /dev/null +++ b/tests/baselines/reference/relativeModuleWithoutSlash.js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/relativeModuleWithoutSlash.ts] //// + +//// [a.ts] + +export default { a: 0 }; + +//// [index.ts] +export default { aIndex: 0 }; + +//// [test.ts] +import a from "."; +import aIndex from "./"; +a.a; +aIndex.a; //aIndex.aIndex; See GH#9690 + +//// [test.ts] +import a from ".."; +import aIndex from "../"; +a.a; +aIndex.a; //aIndex.aIndex; + + +//// [a.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { a: 0 }; +//// [index.js] +"use strict"; +exports.__esModule = true; +exports["default"] = { aIndex: 0 }; +//// [test.js] +"use strict"; +var _1 = require("."); +var _2 = require("./"); +_1["default"].a; +_2["default"].a; //aIndex.aIndex; See GH#9690 +//// [test.js] +"use strict"; +var __1 = require(".."); +var _1 = require("../"); +__1["default"].a; +_1["default"].a; //aIndex.aIndex; diff --git a/tests/baselines/reference/relativeModuleWithoutSlash.symbols b/tests/baselines/reference/relativeModuleWithoutSlash.symbols new file mode 100644 index 00000000000..8c54a0682c7 --- /dev/null +++ b/tests/baselines/reference/relativeModuleWithoutSlash.symbols @@ -0,0 +1,43 @@ +=== /a.ts === + +export default { a: 0 }; +>a : Symbol(a, Decl(a.ts, 1, 16)) + +=== /a/index.ts === +export default { aIndex: 0 }; +>aIndex : Symbol(aIndex, Decl(index.ts, 0, 16)) + +=== /a/test.ts === +import a from "."; +>a : Symbol(a, Decl(test.ts, 0, 6)) + +import aIndex from "./"; +>aIndex : Symbol(aIndex, Decl(test.ts, 1, 6)) + +a.a; +>a.a : Symbol(a, Decl(a.ts, 1, 16)) +>a : Symbol(a, Decl(test.ts, 0, 6)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + +aIndex.a; //aIndex.aIndex; See GH#9690 +>aIndex.a : Symbol(a, Decl(a.ts, 1, 16)) +>aIndex : Symbol(aIndex, Decl(test.ts, 1, 6)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + +=== /a/b/test.ts === +import a from ".."; +>a : Symbol(a, Decl(test.ts, 0, 6)) + +import aIndex from "../"; +>aIndex : Symbol(aIndex, Decl(test.ts, 1, 6)) + +a.a; +>a.a : Symbol(a, Decl(a.ts, 1, 16)) +>a : Symbol(a, Decl(test.ts, 0, 6)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + +aIndex.a; //aIndex.aIndex; +>aIndex.a : Symbol(a, Decl(a.ts, 1, 16)) +>aIndex : Symbol(aIndex, Decl(test.ts, 1, 6)) +>a : Symbol(a, Decl(a.ts, 1, 16)) + diff --git a/tests/baselines/reference/relativeModuleWithoutSlash.trace.json b/tests/baselines/reference/relativeModuleWithoutSlash.trace.json new file mode 100644 index 00000000000..cee5b060676 --- /dev/null +++ b/tests/baselines/reference/relativeModuleWithoutSlash.trace.json @@ -0,0 +1,26 @@ +[ + "======== Resolving module '.' from '/a/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/a'.", + "File '/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/a.ts', result '/a.ts'", + "======== Module name '.' was successfully resolved to '/a.ts'. ========", + "======== Resolving module './' from '/a/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/a'.", + "File '/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/a.ts', result '/a.ts'", + "======== Module name './' was successfully resolved to '/a.ts'. ========", + "======== Resolving module '..' from '/a/b/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/a'.", + "File '/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/a.ts', result '/a.ts'", + "======== Module name '..' was successfully resolved to '/a.ts'. ========", + "======== Resolving module '../' from '/a/b/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/a'.", + "File '/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/a.ts', result '/a.ts'", + "======== Module name '../' was successfully resolved to '/a.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/relativeModuleWithoutSlash.types b/tests/baselines/reference/relativeModuleWithoutSlash.types new file mode 100644 index 00000000000..796ef714dd9 --- /dev/null +++ b/tests/baselines/reference/relativeModuleWithoutSlash.types @@ -0,0 +1,47 @@ +=== /a.ts === + +export default { a: 0 }; +>{ a: 0 } : { a: number; } +>a : number +>0 : number + +=== /a/index.ts === +export default { aIndex: 0 }; +>{ aIndex: 0 } : { aIndex: number; } +>aIndex : number +>0 : number + +=== /a/test.ts === +import a from "."; +>a : { a: number; } + +import aIndex from "./"; +>aIndex : { a: number; } + +a.a; +>a.a : number +>a : { a: number; } +>a : number + +aIndex.a; //aIndex.aIndex; See GH#9690 +>aIndex.a : number +>aIndex : { a: number; } +>a : number + +=== /a/b/test.ts === +import a from ".."; +>a : { a: number; } + +import aIndex from "../"; +>aIndex : { a: number; } + +a.a; +>a.a : number +>a : { a: number; } +>a : number + +aIndex.a; //aIndex.aIndex; +>aIndex.a : number +>aIndex : { a: number; } +>a : number + diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt index be5c21f1a0b..b345e971ab2 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt @@ -13,60 +13,60 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference noParams ``; // Generic tag with parameter which does not use type parameter - function noGenericParams(n: string[]) { } + function noGenericParams(n: TemplateStringsArray) { } noGenericParams ``; // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; - function someGenerics1b(n: string[], m: U) { } + function someGenerics1b(n: TemplateStringsArray, m: U) { } someGenerics1b `${3}`; // Generic tag with argument of function type whose parameter is of type parameter type - function someGenerics2a(strs: string[], n: (x: T) => void) { } + function someGenerics2a(strs: TemplateStringsArray, n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; - function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } + function someGenerics2b(strs: TemplateStringsArray, n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter - function someGenerics3(strs: string[], producer: () => T) { } + function someGenerics3(strs: TemplateStringsArray, producer: () => T) { } someGenerics3 `${() => ''}`; someGenerics3 `${() => undefined}`; someGenerics3 `${() => 3}`; // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type - function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } + function someGenerics4(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; someGenerics4 `${''}${ () => 3 }`; someGenerics4 `${ null }${ null }`; // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type - function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } + function someGenerics5(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; someGenerics5 `${ '' }${ () => 3 }`; someGenerics5 `${null}${null}`; // Generic tag with multiple arguments of function types that each have parameters of the same generic type - function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } + function someGenerics6(strs: TemplateStringsArray, a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; // Generic tag with multiple arguments of function types that each have parameters of different generic type - function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } + function someGenerics7(strs: TemplateStringsArray, a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; // Generic tag with argument of generic function type - function someGenerics8(strs: string[], n: T): T { return n; } + function someGenerics8(strs: TemplateStringsArray, n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; x `${null}${null}${null}`; // Generic tag with multiple parameters of generic type passed arguments with no best common type - function someGenerics9(strs: string[], a: T, b: T, c: T): T { + function someGenerics9(strs: TemplateStringsArray, a: T, b: T, c: T): T { return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js index 1b6e3ab92c8..69dcd284183 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.js @@ -6,60 +6,60 @@ function noParams(n: T) { } noParams ``; // Generic tag with parameter which does not use type parameter -function noGenericParams(n: string[]) { } +function noGenericParams(n: TemplateStringsArray) { } noGenericParams ``; // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; -function someGenerics1b(n: string[], m: U) { } +function someGenerics1b(n: TemplateStringsArray, m: U) { } someGenerics1b `${3}`; // Generic tag with argument of function type whose parameter is of type parameter type -function someGenerics2a(strs: string[], n: (x: T) => void) { } +function someGenerics2a(strs: TemplateStringsArray, n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; -function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } +function someGenerics2b(strs: TemplateStringsArray, n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(strs: string[], producer: () => T) { } +function someGenerics3(strs: TemplateStringsArray, producer: () => T) { } someGenerics3 `${() => ''}`; someGenerics3 `${() => undefined}`; someGenerics3 `${() => 3}`; // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics4(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; someGenerics4 `${''}${ () => 3 }`; someGenerics4 `${ null }${ null }`; // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics5(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; someGenerics5 `${ '' }${ () => 3 }`; someGenerics5 `${null}${null}`; // Generic tag with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } +function someGenerics6(strs: TemplateStringsArray, a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; // Generic tag with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } +function someGenerics7(strs: TemplateStringsArray, a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; // Generic tag with argument of generic function type -function someGenerics8(strs: string[], n: T): T { return n; } +function someGenerics8(strs: TemplateStringsArray, n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; x `${null}${null}${null}`; // Generic tag with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(strs: string[], a: T, b: T, c: T): T { +function someGenerics9(strs: TemplateStringsArray, a: T, b: T, c: T): T { return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt index 63d04a42b3b..619e5081a3b 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt @@ -12,60 +12,60 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference noParams ``; // Generic tag with parameter which does not use type parameter - function noGenericParams(n: string[]) { } + function noGenericParams(n: TemplateStringsArray) { } noGenericParams ``; // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; - function someGenerics1b(n: string[], m: U) { } + function someGenerics1b(n: TemplateStringsArray, m: U) { } someGenerics1b `${3}`; // Generic tag with argument of function type whose parameter is of type parameter type - function someGenerics2a(strs: string[], n: (x: T) => void) { } + function someGenerics2a(strs: TemplateStringsArray, n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; - function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } + function someGenerics2b(strs: TemplateStringsArray, n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter - function someGenerics3(strs: string[], producer: () => T) { } + function someGenerics3(strs: TemplateStringsArray, producer: () => T) { } someGenerics3 `${() => ''}`; someGenerics3 `${() => undefined}`; someGenerics3 `${() => 3}`; // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type - function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } + function someGenerics4(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; someGenerics4 `${''}${ () => 3 }`; someGenerics4 `${ null }${ null }`; // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type - function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } + function someGenerics5(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; someGenerics5 `${ '' }${ () => 3 }`; someGenerics5 `${null}${null}`; // Generic tag with multiple arguments of function types that each have parameters of the same generic type - function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } + function someGenerics6(strs: TemplateStringsArray, a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; // Generic tag with multiple arguments of function types that each have parameters of different generic type - function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } + function someGenerics7(strs: TemplateStringsArray, a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; // Generic tag with argument of generic function type - function someGenerics8(strs: string[], n: T): T { return n; } + function someGenerics8(strs: TemplateStringsArray, n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; x `${null}${null}${null}`; // Generic tag with multiple parameters of generic type passed arguments with no best common type - function someGenerics9(strs: string[], a: T, b: T, c: T): T { + function someGenerics9(strs: TemplateStringsArray, a: T, b: T, c: T): T { return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.js b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.js index 2f57882b4b7..3097e40c9ad 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.js +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.js @@ -5,60 +5,60 @@ function noParams(n: T) { } noParams ``; // Generic tag with parameter which does not use type parameter -function noGenericParams(n: string[]) { } +function noGenericParams(n: TemplateStringsArray) { } noGenericParams ``; // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; -function someGenerics1b(n: string[], m: U) { } +function someGenerics1b(n: TemplateStringsArray, m: U) { } someGenerics1b `${3}`; // Generic tag with argument of function type whose parameter is of type parameter type -function someGenerics2a(strs: string[], n: (x: T) => void) { } +function someGenerics2a(strs: TemplateStringsArray, n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; -function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } +function someGenerics2b(strs: TemplateStringsArray, n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(strs: string[], producer: () => T) { } +function someGenerics3(strs: TemplateStringsArray, producer: () => T) { } someGenerics3 `${() => ''}`; someGenerics3 `${() => undefined}`; someGenerics3 `${() => 3}`; // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics4(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; someGenerics4 `${''}${ () => 3 }`; someGenerics4 `${ null }${ null }`; // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics5(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; someGenerics5 `${ '' }${ () => 3 }`; someGenerics5 `${null}${null}`; // Generic tag with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } +function someGenerics6(strs: TemplateStringsArray, a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; // Generic tag with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } +function someGenerics7(strs: TemplateStringsArray, a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; // Generic tag with argument of generic function type -function someGenerics8(strs: string[], n: T): T { return n; } +function someGenerics8(strs: TemplateStringsArray, n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; x `${null}${null}${null}`; // Generic tag with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(strs: string[], a: T, b: T, c: T): T { +function someGenerics9(strs: TemplateStringsArray, a: T, b: T, c: T): T { return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt index 166769fbbf5..44b30fb535f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.errors.txt @@ -8,7 +8,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts (6 errors) ==== interface I { - (stringParts: string[], ...rest: boolean[]): I; + (stringParts: TemplateStringsArray, ...rest: boolean[]): I; g: I; h: I; member: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js index 9d113793228..511928e1342 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTags.js @@ -1,6 +1,6 @@ //// [taggedTemplateStringsWithIncompatibleTypedTags.ts] interface I { - (stringParts: string[], ...rest: boolean[]): I; + (stringParts: TemplateStringsArray, ...rest: boolean[]): I; g: I; h: I; member: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.errors.txt index 89b48b0193c..c2825c19e63 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.errors.txt @@ -8,7 +8,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTyped ==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts (6 errors) ==== interface I { - (stringParts: string[], ...rest: boolean[]): I; + (stringParts: TemplateStringsArray, ...rest: boolean[]): I; g: I; h: I; member: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js index 8b636356068..99fa7c3d550 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js +++ b/tests/baselines/reference/taggedTemplateStringsWithIncompatibleTypedTagsES6.js @@ -1,6 +1,6 @@ //// [taggedTemplateStringsWithIncompatibleTypedTagsES6.ts] interface I { - (stringParts: string[], ...rest: boolean[]): I; + (stringParts: TemplateStringsArray, ...rest: boolean[]): I; g: I; h: I; member: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js index 1814816283b..a896a811ffb 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.js @@ -1,6 +1,6 @@ //// [taggedTemplateStringsWithManyCallAndMemberExpressions.ts] interface I { - (strs: string[], ...subs: number[]): I; + (strs: TemplateStringsArray, ...subs: number[]): I; member: { new (s: string): { new (n: number): { diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.symbols b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.symbols index 226729907de..c8883fda4fe 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.symbols +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.symbols @@ -2,13 +2,14 @@ interface I { >I : Symbol(I, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 0, 0)) - (strs: string[], ...subs: number[]): I; + (strs: TemplateStringsArray, ...subs: number[]): I; >strs : Symbol(strs, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 5)) ->subs : Symbol(subs, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 20)) +>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.d.ts, --, --)) +>subs : Symbol(subs, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 32)) >I : Symbol(I, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 0, 0)) member: { ->member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 43)) +>member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 55)) new (s: string): { >s : Symbol(s, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 3, 13)) @@ -27,8 +28,8 @@ var f: I; var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; >x : Symbol(x, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 12, 3)) ->f `abc${ 0 }def`.member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 43)) +>f `abc${ 0 }def`.member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 55)) >f : Symbol(f, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 10, 3)) ->member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 43)) +>member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressions.ts, 1, 55)) diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types index 83a0f2cf9f4..553cda2b2b9 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types @@ -2,8 +2,9 @@ interface I { >I : I - (strs: string[], ...subs: number[]): I; ->strs : string[] + (strs: TemplateStringsArray, ...subs: number[]): I; +>strs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray >subs : number[] >I : I diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js index b985860f065..f1acbaa1546 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.js @@ -1,6 +1,6 @@ //// [taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts] interface I { - (strs: string[], ...subs: number[]): I; + (strs: TemplateStringsArray, ...subs: number[]): I; member: { new (s: string): { new (n: number): { diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.symbols b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.symbols index 6535e998808..0d163daa640 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.symbols +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.symbols @@ -2,13 +2,14 @@ interface I { >I : Symbol(I, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 0, 0)) - (strs: string[], ...subs: number[]): I; + (strs: TemplateStringsArray, ...subs: number[]): I; >strs : Symbol(strs, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 5)) ->subs : Symbol(subs, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 20)) +>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.es5.d.ts, --, --)) +>subs : Symbol(subs, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 32)) >I : Symbol(I, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 0, 0)) member: { ->member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 43)) +>member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 55)) new (s: string): { >s : Symbol(s, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 3, 13)) @@ -27,8 +28,8 @@ var f: I; var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; >x : Symbol(x, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 12, 3)) ->f `abc${ 0 }def`.member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 43)) +>f `abc${ 0 }def`.member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 55)) >f : Symbol(f, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 10, 3)) ->member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 43)) +>member : Symbol(I.member, Decl(taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts, 1, 55)) diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types index c240b7ced11..f9d7c605f7f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types @@ -2,8 +2,9 @@ interface I { >I : I - (strs: string[], ...subs: number[]): I; ->strs : string[] + (strs: TemplateStringsArray, ...subs: number[]): I; +>strs : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray >subs : number[] >I : I diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt index 9e450cbb368..426eef8ce7f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.errors.txt @@ -1,25 +1,39 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(12,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(9,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type 'undefined[]'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(10,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(11,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(12,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(13,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(14,9): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(19,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts(21,9): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts (4 errors) ==== - function foo(strs: string[]): number; - function foo(strs: string[], x: number): string; - function foo(strs: string[], x: number, y: number): boolean; - function foo(strs: string[], x: number, y: string): {}; +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts (8 errors) ==== + function foo(strs: TemplateStringsArray): number; + function foo(strs: TemplateStringsArray, x: number): string; + function foo(strs: TemplateStringsArray, x: number, y: number): boolean; + function foo(strs: TemplateStringsArray, x: number, y: string): {}; function foo(...stuff: any[]): any { return undefined; } var a = foo([]); // number + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type 'undefined[]'. var b = foo([], 1); // string + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var c = foo([], 1, 2); // boolean + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var d = foo([], 1, true); // boolean (with error) - ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var e = foo([], 1, "2"); // {} + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var f = foo([], 1, 2, 3); // any (with error) ~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js index 431447df22e..4245b0cb0f4 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1.js @@ -1,8 +1,8 @@ //// [taggedTemplateStringsWithOverloadResolution1.ts] -function foo(strs: string[]): number; -function foo(strs: string[], x: number): string; -function foo(strs: string[], x: number, y: number): boolean; -function foo(strs: string[], x: number, y: string): {}; +function foo(strs: TemplateStringsArray): number; +function foo(strs: TemplateStringsArray, x: number): string; +function foo(strs: TemplateStringsArray, x: number, y: number): boolean; +function foo(strs: TemplateStringsArray, x: number, y: string): {}; function foo(...stuff: any[]): any { return undefined; } diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.errors.txt index 53361f2052d..73adc0c0302 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.errors.txt @@ -1,25 +1,39 @@ -tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(12,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(9,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. + Property 'raw' is missing in type 'undefined[]'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(10,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(11,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(12,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(13,13): error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(14,9): error TS2346: Supplied parameters do not match any signature of call target. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(19,20): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts(21,9): error TS2346: Supplied parameters do not match any signature of call target. -==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts (4 errors) ==== - function foo(strs: string[]): number; - function foo(strs: string[], x: number): string; - function foo(strs: string[], x: number, y: number): boolean; - function foo(strs: string[], x: number, y: string): {}; +==== tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts (8 errors) ==== + function foo(strs: TemplateStringsArray): number; + function foo(strs: TemplateStringsArray, x: number): string; + function foo(strs: TemplateStringsArray, x: number, y: number): boolean; + function foo(strs: TemplateStringsArray, x: number, y: string): {}; function foo(...stuff: any[]): any { return undefined; } var a = foo([]); // number + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. +!!! error TS2345: Property 'raw' is missing in type 'undefined[]'. var b = foo([], 1); // string + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var c = foo([], 1, 2); // boolean + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var d = foo([], 1, true); // boolean (with error) - ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string'. + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var e = foo([], 1, "2"); // {} + ~~ +!!! error TS2345: Argument of type 'undefined[]' is not assignable to parameter of type 'TemplateStringsArray'. var f = foo([], 1, 2, 3); // any (with error) ~~~~~~~~~~~~~~~~ !!! error TS2346: Supplied parameters do not match any signature of call target. diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.js index bd121933b32..b62671d33ac 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution1_ES6.js @@ -1,8 +1,8 @@ //// [taggedTemplateStringsWithOverloadResolution1_ES6.ts] -function foo(strs: string[]): number; -function foo(strs: string[], x: number): string; -function foo(strs: string[], x: number, y: number): boolean; -function foo(strs: string[], x: number, y: string): {}; +function foo(strs: TemplateStringsArray): number; +function foo(strs: TemplateStringsArray, x: number): string; +function foo(strs: TemplateStringsArray, x: number, y: number): boolean; +function foo(strs: TemplateStringsArray, x: number, y: string): {}; function foo(...stuff: any[]): any { return undefined; } diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js index f12008f9581..c16bfa5454f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.js @@ -6,8 +6,8 @@ function foo1(...stuff: any[]): any { return undefined; } -var a = foo1 `${1}`; // string -var b = foo1([], 1); // number +var a = foo1 `${1}`; +var b = foo1([], 1); function foo2(strs: string[], x: number): number; function foo2(strs: TemplateStringsArray, x: number): string; @@ -15,8 +15,8 @@ function foo2(...stuff: any[]): any { return undefined; } -var c = foo2 `${1}`; // number -var d = foo2([], 1); // number +var c = foo2 `${1}`; +var d = foo2([], 1); //// [taggedTemplateStringsWithOverloadResolution2.js] function foo1() { @@ -26,8 +26,8 @@ function foo1() { } return undefined; } -var a = (_a = ["", ""], _a.raw = ["", ""], foo1(_a, 1)); // string -var b = foo1([], 1); // number +var a = (_a = ["", ""], _a.raw = ["", ""], foo1(_a, 1)); +var b = foo1([], 1); function foo2() { var stuff = []; for (var _i = 0; _i < arguments.length; _i++) { @@ -35,6 +35,6 @@ function foo2() { } return undefined; } -var c = (_b = ["", ""], _b.raw = ["", ""], foo2(_b, 1)); // number -var d = foo2([], 1); // number +var c = (_b = ["", ""], _b.raw = ["", ""], foo2(_b, 1)); +var d = foo2([], 1); var _a, _b; diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.symbols b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.symbols index 52b8f3ab6f0..241c43c4d78 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.symbols +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.symbols @@ -19,11 +19,11 @@ function foo1(...stuff: any[]): any { >undefined : Symbol(undefined) } -var a = foo1 `${1}`; // string +var a = foo1 `${1}`; >a : Symbol(a, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 7, 3)) >foo1 : Symbol(foo1, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 0, 0), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 1, 61), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 2, 49)) -var b = foo1([], 1); // number +var b = foo1([], 1); >b : Symbol(b, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 8, 3)) >foo1 : Symbol(foo1, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 0, 0), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 1, 61), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 2, 49)) @@ -46,11 +46,11 @@ function foo2(...stuff: any[]): any { >undefined : Symbol(undefined) } -var c = foo2 `${1}`; // number +var c = foo2 `${1}`; >c : Symbol(c, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 16, 3)) >foo2 : Symbol(foo2, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 8, 20), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 10, 49), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 11, 61)) -var d = foo2([], 1); // number +var d = foo2([], 1); >d : Symbol(d, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 17, 3)) >foo2 : Symbol(foo2, Decl(taggedTemplateStringsWithOverloadResolution2.ts, 8, 20), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 10, 49), Decl(taggedTemplateStringsWithOverloadResolution2.ts, 11, 61)) diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types index 77353e9b3ce..3c35974ddec 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2.types @@ -19,14 +19,14 @@ function foo1(...stuff: any[]): any { >undefined : undefined } -var a = foo1 `${1}`; // string +var a = foo1 `${1}`; >a : string >foo1 `${1}` : string >foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } >`${1}` : string >1 : number -var b = foo1([], 1); // number +var b = foo1([], 1); >b : number >foo1([], 1) : number >foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } @@ -52,14 +52,14 @@ function foo2(...stuff: any[]): any { >undefined : undefined } -var c = foo2 `${1}`; // number ->c : number ->foo2 `${1}` : number +var c = foo2 `${1}`; +>c : string +>foo2 `${1}` : string >foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } >`${1}` : string >1 : number -var d = foo2([], 1); // number +var d = foo2([], 1); >d : number >foo2([], 1) : number >foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.js b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.js index f208a63354d..502fa4552a3 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.js +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.js @@ -5,8 +5,8 @@ function foo1(...stuff: any[]): any { return undefined; } -var a = foo1 `${1}`; // string -var b = foo1([], 1); // number +var a = foo1 `${1}`; +var b = foo1([], 1); function foo2(strs: string[], x: number): number; function foo2(strs: TemplateStringsArray, x: number): string; @@ -14,17 +14,17 @@ function foo2(...stuff: any[]): any { return undefined; } -var c = foo2 `${1}`; // number -var d = foo2([], 1); // number +var c = foo2 `${1}`; +var d = foo2([], 1); //// [taggedTemplateStringsWithOverloadResolution2_ES6.js] function foo1(...stuff) { return undefined; } -var a = foo1 `${1}`; // string -var b = foo1([], 1); // number +var a = foo1 `${1}`; +var b = foo1([], 1); function foo2(...stuff) { return undefined; } -var c = foo2 `${1}`; // number -var d = foo2([], 1); // number +var c = foo2 `${1}`; +var d = foo2([], 1); diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.symbols b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.symbols index cadfa135202..9cc79f2596f 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.symbols +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.symbols @@ -18,11 +18,11 @@ function foo1(...stuff: any[]): any { >undefined : Symbol(undefined) } -var a = foo1 `${1}`; // string +var a = foo1 `${1}`; >a : Symbol(a, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 6, 3)) >foo1 : Symbol(foo1, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 0, 0), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 0, 61), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 1, 49)) -var b = foo1([], 1); // number +var b = foo1([], 1); >b : Symbol(b, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 7, 3)) >foo1 : Symbol(foo1, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 0, 0), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 0, 61), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 1, 49)) @@ -45,11 +45,11 @@ function foo2(...stuff: any[]): any { >undefined : Symbol(undefined) } -var c = foo2 `${1}`; // number +var c = foo2 `${1}`; >c : Symbol(c, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 15, 3)) >foo2 : Symbol(foo2, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 7, 20), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 9, 49), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 10, 61)) -var d = foo2([], 1); // number +var d = foo2([], 1); >d : Symbol(d, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 16, 3)) >foo2 : Symbol(foo2, Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 7, 20), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 9, 49), Decl(taggedTemplateStringsWithOverloadResolution2_ES6.ts, 10, 61)) diff --git a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.types b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.types index 306bf38cac4..7faeec19c4a 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.types +++ b/tests/baselines/reference/taggedTemplateStringsWithOverloadResolution2_ES6.types @@ -18,14 +18,14 @@ function foo1(...stuff: any[]): any { >undefined : undefined } -var a = foo1 `${1}`; // string +var a = foo1 `${1}`; >a : string >foo1 `${1}` : string >foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } >`${1}` : string >1 : number -var b = foo1([], 1); // number +var b = foo1([], 1); >b : number >foo1([], 1) : number >foo1 : { (strs: TemplateStringsArray, x: number): string; (strs: string[], x: number): number; } @@ -51,14 +51,14 @@ function foo2(...stuff: any[]): any { >undefined : undefined } -var c = foo2 `${1}`; // number ->c : number ->foo2 `${1}` : number +var c = foo2 `${1}`; +>c : string +>foo2 `${1}` : string >foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } >`${1}` : string >1 : number -var d = foo2([], 1); // number +var d = foo2([], 1); >d : number >foo2([], 1) : number >foo2 : { (strs: string[], x: number): number; (strs: TemplateStringsArray, x: number): string; } diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js index fcc2cda86dc..d011c3048a7 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.js @@ -1,6 +1,6 @@ //// [taggedTemplateStringsWithTypedTags.ts] interface I { - (stringParts: string[], ...rest: number[]): I; + (stringParts: TemplateStringsArray, ...rest: number[]): I; g: I; h: I; member: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.symbols b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.symbols index d3f85d8375a..cd28177f587 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.symbols +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.symbols @@ -2,13 +2,14 @@ interface I { >I : Symbol(I, Decl(taggedTemplateStringsWithTypedTags.ts, 0, 0)) - (stringParts: string[], ...rest: number[]): I; + (stringParts: TemplateStringsArray, ...rest: number[]): I; >stringParts : Symbol(stringParts, Decl(taggedTemplateStringsWithTypedTags.ts, 1, 5)) ->rest : Symbol(rest, Decl(taggedTemplateStringsWithTypedTags.ts, 1, 27)) +>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.d.ts, --, --)) +>rest : Symbol(rest, Decl(taggedTemplateStringsWithTypedTags.ts, 1, 39)) >I : Symbol(I, Decl(taggedTemplateStringsWithTypedTags.ts, 0, 0)) g: I; ->g : Symbol(I.g, Decl(taggedTemplateStringsWithTypedTags.ts, 1, 50)) +>g : Symbol(I.g, Decl(taggedTemplateStringsWithTypedTags.ts, 1, 62)) >I : Symbol(I, Decl(taggedTemplateStringsWithTypedTags.ts, 0, 0)) h: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types index 2c992a2d233..c7c521154c7 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTags.types @@ -2,8 +2,9 @@ interface I { >I : I - (stringParts: string[], ...rest: number[]): I; ->stringParts : string[] + (stringParts: TemplateStringsArray, ...rest: number[]): I; +>stringParts : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray >rest : number[] >I : I diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js index 9eefc46ec30..35a616f05f4 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.js @@ -1,6 +1,6 @@ //// [taggedTemplateStringsWithTypedTagsES6.ts] interface I { - (stringParts: string[], ...rest: number[]): I; + (stringParts: TemplateStringsArray, ...rest: number[]): I; g: I; h: I; member: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.symbols b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.symbols index f0b088bd6f6..f7f9c62d492 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.symbols +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.symbols @@ -2,13 +2,14 @@ interface I { >I : Symbol(I, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 0, 0)) - (stringParts: string[], ...rest: number[]): I; + (stringParts: TemplateStringsArray, ...rest: number[]): I; >stringParts : Symbol(stringParts, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 1, 5)) ->rest : Symbol(rest, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 1, 27)) +>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.es5.d.ts, --, --)) +>rest : Symbol(rest, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 1, 39)) >I : Symbol(I, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 0, 0)) g: I; ->g : Symbol(I.g, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 1, 50)) +>g : Symbol(I.g, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 1, 62)) >I : Symbol(I, Decl(taggedTemplateStringsWithTypedTagsES6.ts, 0, 0)) h: I; diff --git a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types index 4bda0f3fbb0..bf45144c329 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types +++ b/tests/baselines/reference/taggedTemplateStringsWithTypedTagsES6.types @@ -2,8 +2,9 @@ interface I { >I : I - (stringParts: string[], ...rest: number[]): I; ->stringParts : string[] + (stringParts: TemplateStringsArray, ...rest: number[]): I; +>stringParts : TemplateStringsArray +>TemplateStringsArray : TemplateStringsArray >rest : number[] >I : I diff --git a/tests/baselines/reference/umdGlobalMerge.errors.txt b/tests/baselines/reference/umdGlobalMerge.errors.txt new file mode 100644 index 00000000000..eb4a116ef09 --- /dev/null +++ b/tests/baselines/reference/umdGlobalMerge.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/b.d.ts(2,20): error TS2305: Module '"tests/cases/compiler/a".ns' has no exported member 'IFoo'. + + +==== tests/cases/compiler/a.d.ts (0 errors) ==== + export = ns; + + export as namespace ns; + + declare namespace ns { + export var x: number; + export interface IFoo { } + } + +==== tests/cases/compiler/b.d.ts (1 errors) ==== + declare namespace ns.something { + export var p: ns.IFoo; + ~~~~ +!!! error TS2305: Module '"tests/cases/compiler/a".ns' has no exported member 'IFoo'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParameters6.js b/tests/baselines/reference/unusedTypeParameters6.js new file mode 100644 index 00000000000..4c2b3a9d0ba --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters6.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/unusedTypeParameters6.ts] //// + +//// [a.ts] + +class C { } + +//// [b.ts] +interface C { a: T; } + +//// [a.js] +var C = (function () { + function C() { + } + return C; +}()); +//// [b.js] diff --git a/tests/baselines/reference/unusedTypeParameters6.symbols b/tests/baselines/reference/unusedTypeParameters6.symbols new file mode 100644 index 00000000000..bf20b44d347 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters6.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + +=== tests/cases/compiler/b.ts === +interface C { a: T; } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) +>a : Symbol(C.a, Decl(b.ts, 0, 16)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + diff --git a/tests/baselines/reference/unusedTypeParameters6.types b/tests/baselines/reference/unusedTypeParameters6.types new file mode 100644 index 00000000000..165862c0080 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters6.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { } +>C : C +>T : T + +=== tests/cases/compiler/b.ts === +interface C { a: T; } +>C : C +>T : T +>a : T +>T : T + diff --git a/tests/baselines/reference/unusedTypeParameters7.js b/tests/baselines/reference/unusedTypeParameters7.js new file mode 100644 index 00000000000..d63f7a0edc3 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters7.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/unusedTypeParameters7.ts] //// + +//// [a.ts] + +class C { a: T; } + +//// [b.ts] +interface C { } + +//// [a.js] +var C = (function () { + function C() { + } + return C; +}()); +//// [b.js] diff --git a/tests/baselines/reference/unusedTypeParameters7.symbols b/tests/baselines/reference/unusedTypeParameters7.symbols new file mode 100644 index 00000000000..79704b437a6 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters7.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { a: T; } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) +>a : Symbol(C.a, Decl(a.ts, 1, 12)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + +=== tests/cases/compiler/b.ts === +interface C { } +>C : Symbol(C, Decl(a.ts, 0, 0), Decl(b.ts, 0, 0)) +>T : Symbol(T, Decl(a.ts, 1, 8), Decl(b.ts, 0, 12)) + diff --git a/tests/baselines/reference/unusedTypeParameters7.types b/tests/baselines/reference/unusedTypeParameters7.types new file mode 100644 index 00000000000..a52b4cee7ec --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters7.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/a.ts === + +class C { a: T; } +>C : C +>T : T +>a : T +>T : T + +=== tests/cases/compiler/b.ts === +interface C { } +>C : C +>T : T + diff --git a/tests/baselines/reference/unusedTypeParameters8.errors.txt b/tests/baselines/reference/unusedTypeParameters8.errors.txt new file mode 100644 index 00000000000..d7928d36900 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters8.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/b.ts(1,13): error TS6133: 'T' is declared but never used. + + +==== tests/cases/compiler/a.ts (0 errors) ==== + + class C { } + +==== tests/cases/compiler/b.ts (1 errors) ==== + interface C { } + ~ +!!! error TS6133: 'T' is declared but never used. \ No newline at end of file diff --git a/tests/baselines/reference/unusedTypeParameters8.js b/tests/baselines/reference/unusedTypeParameters8.js new file mode 100644 index 00000000000..0c34373d315 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters8.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/unusedTypeParameters8.ts] //// + +//// [a.ts] + +class C { } + +//// [b.ts] +interface C { } + +//// [a.js] +var C = (function () { + function C() { + } + return C; +}()); +//// [b.js] diff --git a/tests/baselines/reference/unusedTypeParameters9.js b/tests/baselines/reference/unusedTypeParameters9.js new file mode 100644 index 00000000000..8d82921b076 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters9.js @@ -0,0 +1,30 @@ +//// [unusedTypeParameters9.ts] + +// clas + interface +class C1 { } +interface C1 { a: T; } + +// interface + class +class C2 { a: T; } +interface C2 { } + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +interface C3 { b: string; } +interface C3 { c: number; } +interface C3 { d: boolean; } +interface C3 { e: any; } + +//// [unusedTypeParameters9.js] +// clas + interface +var C1 = (function () { + function C1() { + } + return C1; +}()); +// interface + class +var C2 = (function () { + function C2() { + } + return C2; +}()); diff --git a/tests/baselines/reference/unusedTypeParameters9.symbols b/tests/baselines/reference/unusedTypeParameters9.symbols new file mode 100644 index 00000000000..6c4f6aab71c --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters9.symbols @@ -0,0 +1,53 @@ +=== tests/cases/compiler/unusedTypeParameters9.ts === + +// clas + interface +class C1 { } +>C1 : Symbol(C1, Decl(unusedTypeParameters9.ts, 0, 0), Decl(unusedTypeParameters9.ts, 2, 15)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 2, 9), Decl(unusedTypeParameters9.ts, 3, 13)) + +interface C1 { a: T; } +>C1 : Symbol(C1, Decl(unusedTypeParameters9.ts, 0, 0), Decl(unusedTypeParameters9.ts, 2, 15)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 2, 9), Decl(unusedTypeParameters9.ts, 3, 13)) +>a : Symbol(C1.a, Decl(unusedTypeParameters9.ts, 3, 17)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 2, 9), Decl(unusedTypeParameters9.ts, 3, 13)) + +// interface + class +class C2 { a: T; } +>C2 : Symbol(C2, Decl(unusedTypeParameters9.ts, 3, 25), Decl(unusedTypeParameters9.ts, 6, 21)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 6, 9), Decl(unusedTypeParameters9.ts, 7, 13)) +>a : Symbol(C2.a, Decl(unusedTypeParameters9.ts, 6, 13)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 6, 9), Decl(unusedTypeParameters9.ts, 7, 13)) + +interface C2 { } +>C2 : Symbol(C2, Decl(unusedTypeParameters9.ts, 3, 25), Decl(unusedTypeParameters9.ts, 6, 21)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 6, 9), Decl(unusedTypeParameters9.ts, 7, 13)) + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>a : Symbol(C3.a, Decl(unusedTypeParameters9.ts, 10, 17)) +>c : Symbol(c, Decl(unusedTypeParameters9.ts, 10, 20)) +>p : Symbol(p, Decl(unusedTypeParameters9.ts, 10, 24)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) + +interface C3 { b: string; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>b : Symbol(C3.b, Decl(unusedTypeParameters9.ts, 11, 17)) + +interface C3 { c: number; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>c : Symbol(C3.c, Decl(unusedTypeParameters9.ts, 12, 17)) + +interface C3 { d: boolean; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>d : Symbol(C3.d, Decl(unusedTypeParameters9.ts, 13, 17)) + +interface C3 { e: any; } +>C3 : Symbol(C3, Decl(unusedTypeParameters9.ts, 7, 19), Decl(unusedTypeParameters9.ts, 10, 47), Decl(unusedTypeParameters9.ts, 11, 30), Decl(unusedTypeParameters9.ts, 12, 30), Decl(unusedTypeParameters9.ts, 13, 32)) +>T : Symbol(T, Decl(unusedTypeParameters9.ts, 10, 13), Decl(unusedTypeParameters9.ts, 11, 13), Decl(unusedTypeParameters9.ts, 12, 13), Decl(unusedTypeParameters9.ts, 13, 13), Decl(unusedTypeParameters9.ts, 14, 13)) +>e : Symbol(C3.e, Decl(unusedTypeParameters9.ts, 14, 17)) + diff --git a/tests/baselines/reference/unusedTypeParameters9.types b/tests/baselines/reference/unusedTypeParameters9.types new file mode 100644 index 00000000000..58a75e67297 --- /dev/null +++ b/tests/baselines/reference/unusedTypeParameters9.types @@ -0,0 +1,53 @@ +=== tests/cases/compiler/unusedTypeParameters9.ts === + +// clas + interface +class C1 { } +>C1 : C1 +>T : T + +interface C1 { a: T; } +>C1 : C1 +>T : T +>a : T +>T : T + +// interface + class +class C2 { a: T; } +>C2 : C2 +>T : T +>a : T +>T : T + +interface C2 { } +>C2 : C2 +>T : T + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +>C3 : C3 +>T : T +>a : (c: (p: T) => void) => void +>c : (p: T) => void +>p : T +>T : T + +interface C3 { b: string; } +>C3 : C3 +>T : T +>b : string + +interface C3 { c: number; } +>C3 : C3 +>T : T +>c : number + +interface C3 { d: boolean; } +>C3 : C3 +>T : T +>d : boolean + +interface C3 { e: any; } +>C3 : C3 +>T : T +>e : any + diff --git a/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts b/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts index 6b0741e2205..f58e9b704d4 100644 --- a/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts +++ b/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts @@ -16,5 +16,5 @@ class A { class B { constructor(...args: number[]) {} @MyMethodDecorator - method(...args: string[]) {} + method(this: this, ...args: string[]) {} } diff --git a/tests/cases/compiler/emitSkipsThisWithRestParameter.ts b/tests/cases/compiler/emitSkipsThisWithRestParameter.ts new file mode 100644 index 00000000000..09411a28cd2 --- /dev/null +++ b/tests/cases/compiler/emitSkipsThisWithRestParameter.ts @@ -0,0 +1,5 @@ +function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any { + return function(this: any, ...args: any[]) { + return fn.apply(this, [ this ].concat(args)); + }; +} diff --git a/tests/cases/compiler/noUsedBeforeDefinedErrorInAmbientContext1.ts b/tests/cases/compiler/noUsedBeforeDefinedErrorInAmbientContext1.ts new file mode 100644 index 00000000000..834356e88b4 --- /dev/null +++ b/tests/cases/compiler/noUsedBeforeDefinedErrorInAmbientContext1.ts @@ -0,0 +1,4 @@ +// @filename: test.d.ts + +declare var S: typeof A; // no error +declare const A: number; \ No newline at end of file diff --git a/tests/cases/compiler/relativeModuleWithoutSlash.ts b/tests/cases/compiler/relativeModuleWithoutSlash.ts new file mode 100644 index 00000000000..42b328e1175 --- /dev/null +++ b/tests/cases/compiler/relativeModuleWithoutSlash.ts @@ -0,0 +1,20 @@ +// @traceResolution: true +// @moduleResolution: node + +// @Filename: /a.ts +export default { a: 0 }; + +// @Filename: /a/index.ts +export default { aIndex: 0 }; + +// @Filename: /a/test.ts +import a from "."; +import aIndex from "./"; +a.a; +aIndex.a; //aIndex.aIndex; See GH#9690 + +// @Filename: /a/b/test.ts +import a from ".."; +import aIndex from "../"; +a.a; +aIndex.a; //aIndex.aIndex; diff --git a/tests/cases/compiler/umdGlobalMerge.ts b/tests/cases/compiler/umdGlobalMerge.ts new file mode 100644 index 00000000000..1f42e2fda71 --- /dev/null +++ b/tests/cases/compiler/umdGlobalMerge.ts @@ -0,0 +1,14 @@ +// @filename: a.d.ts +export = ns; + +export as namespace ns; + +declare namespace ns { + export var x: number; + export interface IFoo { } +} + +// @filename: b.d.ts +declare namespace ns.something { + export var p: ns.IFoo; +} diff --git a/tests/cases/compiler/unusedTypeParameters6.ts b/tests/cases/compiler/unusedTypeParameters6.ts new file mode 100644 index 00000000000..f445665f4ea --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters6.ts @@ -0,0 +1,8 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// @fileName: a.ts +class C { } + +// @fileName: b.ts +interface C { a: T; } \ No newline at end of file diff --git a/tests/cases/compiler/unusedTypeParameters7.ts b/tests/cases/compiler/unusedTypeParameters7.ts new file mode 100644 index 00000000000..87b42d97650 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters7.ts @@ -0,0 +1,8 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// @fileName: a.ts +class C { a: T; } + +// @fileName: b.ts +interface C { } \ No newline at end of file diff --git a/tests/cases/compiler/unusedTypeParameters8.ts b/tests/cases/compiler/unusedTypeParameters8.ts new file mode 100644 index 00000000000..4034ed04c72 --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters8.ts @@ -0,0 +1,8 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// @fileName: a.ts +class C { } + +// @fileName: b.ts +interface C { } \ No newline at end of file diff --git a/tests/cases/compiler/unusedTypeParameters9.ts b/tests/cases/compiler/unusedTypeParameters9.ts new file mode 100644 index 00000000000..48581d4ab2e --- /dev/null +++ b/tests/cases/compiler/unusedTypeParameters9.ts @@ -0,0 +1,17 @@ +//@noUnusedLocals:true +//@noUnusedParameters:true + +// clas + interface +class C1 { } +interface C1 { a: T; } + +// interface + class +class C2 { a: T; } +interface C2 { } + +// interfaces +interface C3 { a(c: (p: T) => void): void; } +interface C3 { b: string; } +interface C3 { c: number; } +interface C3 { d: boolean; } +interface C3 { e: any; } \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts new file mode 100644 index 00000000000..e00adf3d63b --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: commonjs +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts new file mode 100644 index 00000000000..38f6ce9f27d --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS2.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: commonjs +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts new file mode 100644 index 00000000000..1e2619ab89e --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem1.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: system +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { + static prop0: string; + static prop1 = Testing123.prop0; +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts new file mode 100644 index 00000000000..bf7c9a0ca2d --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratedClassExportsSystem2.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @experimentaldecorators: true +// @emitDecoratorMetadata: true +// @module: system +// @filename: a.ts + +declare function forwardRef(x: any): any; +declare var Something: any; +@Something({ v: () => Testing123 }) +export class Testing123 { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts index 961544f309a..17f2ea6b848 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts @@ -5,60 +5,60 @@ function noParams(n: T) { } noParams ``; // Generic tag with parameter which does not use type parameter -function noGenericParams(n: string[]) { } +function noGenericParams(n: TemplateStringsArray) { } noGenericParams ``; // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; -function someGenerics1b(n: string[], m: U) { } +function someGenerics1b(n: TemplateStringsArray, m: U) { } someGenerics1b `${3}`; // Generic tag with argument of function type whose parameter is of type parameter type -function someGenerics2a(strs: string[], n: (x: T) => void) { } +function someGenerics2a(strs: TemplateStringsArray, n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; -function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } +function someGenerics2b(strs: TemplateStringsArray, n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(strs: string[], producer: () => T) { } +function someGenerics3(strs: TemplateStringsArray, producer: () => T) { } someGenerics3 `${() => ''}`; someGenerics3 `${() => undefined}`; someGenerics3 `${() => 3}`; // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics4(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; someGenerics4 `${''}${ () => 3 }`; someGenerics4 `${ null }${ null }`; // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics5(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; someGenerics5 `${ '' }${ () => 3 }`; someGenerics5 `${null}${null}`; // Generic tag with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } +function someGenerics6(strs: TemplateStringsArray, a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; // Generic tag with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } +function someGenerics7(strs: TemplateStringsArray, a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; // Generic tag with argument of generic function type -function someGenerics8(strs: string[], n: T): T { return n; } +function someGenerics8(strs: TemplateStringsArray, n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; x `${null}${null}${null}`; // Generic tag with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(strs: string[], a: T, b: T, c: T): T { +function someGenerics9(strs: TemplateStringsArray, a: T, b: T, c: T): T { return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts index bc9fd75cac9..a0ca1aa67d6 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts @@ -5,60 +5,60 @@ function noParams(n: T) { } noParams ``; // Generic tag with parameter which does not use type parameter -function noGenericParams(n: string[]) { } +function noGenericParams(n: TemplateStringsArray) { } noGenericParams ``; // Generic tag with multiple type parameters and only one used in parameter type annotation function someGenerics1a(n: T, m: number) { } someGenerics1a `${3}`; -function someGenerics1b(n: string[], m: U) { } +function someGenerics1b(n: TemplateStringsArray, m: U) { } someGenerics1b `${3}`; // Generic tag with argument of function type whose parameter is of type parameter type -function someGenerics2a(strs: string[], n: (x: T) => void) { } +function someGenerics2a(strs: TemplateStringsArray, n: (x: T) => void) { } someGenerics2a `${(n: string) => n}`; -function someGenerics2b(strs: string[], n: (x: T, y: U) => void) { } +function someGenerics2b(strs: TemplateStringsArray, n: (x: T, y: U) => void) { } someGenerics2b `${ (n: string, x: number) => n }`; // Generic tag with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter -function someGenerics3(strs: string[], producer: () => T) { } +function someGenerics3(strs: TemplateStringsArray, producer: () => T) { } someGenerics3 `${() => ''}`; someGenerics3 `${() => undefined}`; someGenerics3 `${() => 3}`; // 2 parameter generic tag with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type -function someGenerics4(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics4(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics4 `${4}${ () => null }`; someGenerics4 `${''}${ () => 3 }`; someGenerics4 `${ null }${ null }`; // 2 parameter generic tag with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type -function someGenerics5(strs: string[], n: T, f: (x: U) => void) { } +function someGenerics5(strs: TemplateStringsArray, n: T, f: (x: U) => void) { } someGenerics5 `${ 4 } ${ () => null }`; someGenerics5 `${ '' }${ () => 3 }`; someGenerics5 `${null}${null}`; // Generic tag with multiple arguments of function types that each have parameters of the same generic type -function someGenerics6(strs: string[], a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } +function someGenerics6(strs: TemplateStringsArray, a: (a: A) => A, b: (b: A) => A, c: (c: A) => A) { } someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ n => n }${ n => n}${ n => n}`; someGenerics6 `${ (n: number) => n }${ (n: number) => n }${ (n: number) => n }`; // Generic tag with multiple arguments of function types that each have parameters of different generic type -function someGenerics7(strs: string[], a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } +function someGenerics7(strs: TemplateStringsArray, a: (a: A) => A, b: (b: B) => B, c: (c: C) => C) { } someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${ n => n }${ n => n }${ n => n }`; someGenerics7 `${(n: number) => n}${ (n: string) => n}${ (n: number) => n}`; // Generic tag with argument of generic function type -function someGenerics8(strs: string[], n: T): T { return n; } +function someGenerics8(strs: TemplateStringsArray, n: T): T { return n; } var x = someGenerics8 `${ someGenerics7 }`; x `${null}${null}${null}`; // Generic tag with multiple parameters of generic type passed arguments with no best common type -function someGenerics9(strs: string[], a: T, b: T, c: T): T { +function someGenerics9(strs: TemplateStringsArray, a: T, b: T, c: T): T { return null; } var a9a = someGenerics9 `${ '' }${ 0 }${ [] }`; diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts index 0f5d203d60b..d8be6cbd7c2 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTags.ts @@ -1,5 +1,5 @@ interface I { - (stringParts: string[], ...rest: boolean[]): I; + (stringParts: TemplateStringsArray, ...rest: boolean[]): I; g: I; h: I; member: I; diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts index 36dc249f672..dec483c1678 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithIncompatibleTypedTagsES6.ts @@ -1,6 +1,6 @@ // @target: ES6 interface I { - (stringParts: string[], ...rest: boolean[]): I; + (stringParts: TemplateStringsArray, ...rest: boolean[]): I; g: I; h: I; member: I; diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts index d96196ee26e..f86353e7dda 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressions.ts @@ -1,5 +1,5 @@ interface I { - (strs: string[], ...subs: number[]): I; + (strs: TemplateStringsArray, ...subs: number[]): I; member: { new (s: string): { new (n: number): { diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts index d0d6604cfde..914f7ca809f 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.ts @@ -1,6 +1,6 @@ // @target: ES6 interface I { - (strs: string[], ...subs: number[]): I; + (strs: TemplateStringsArray, ...subs: number[]): I; member: { new (s: string): { new (n: number): { diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts index 5b29beddd48..3743c1a7710 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1.ts @@ -1,7 +1,7 @@ -function foo(strs: string[]): number; -function foo(strs: string[], x: number): string; -function foo(strs: string[], x: number, y: number): boolean; -function foo(strs: string[], x: number, y: string): {}; +function foo(strs: TemplateStringsArray): number; +function foo(strs: TemplateStringsArray, x: number): string; +function foo(strs: TemplateStringsArray, x: number, y: number): boolean; +function foo(strs: TemplateStringsArray, x: number, y: string): {}; function foo(...stuff: any[]): any { return undefined; } diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts index f821d84fbdd..d681c6b98b0 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution1_ES6.ts @@ -1,8 +1,8 @@ //@target: es6 -function foo(strs: string[]): number; -function foo(strs: string[], x: number): string; -function foo(strs: string[], x: number, y: number): boolean; -function foo(strs: string[], x: number, y: string): {}; +function foo(strs: TemplateStringsArray): number; +function foo(strs: TemplateStringsArray, x: number): string; +function foo(strs: TemplateStringsArray, x: number, y: number): boolean; +function foo(strs: TemplateStringsArray, x: number, y: string): {}; function foo(...stuff: any[]): any { return undefined; } diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts index 0ed9b86128b..98799dd92df 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2.ts @@ -5,8 +5,8 @@ function foo1(...stuff: any[]): any { return undefined; } -var a = foo1 `${1}`; // string -var b = foo1([], 1); // number +var a = foo1 `${1}`; +var b = foo1([], 1); function foo2(strs: string[], x: number): number; function foo2(strs: TemplateStringsArray, x: number): string; @@ -14,5 +14,5 @@ function foo2(...stuff: any[]): any { return undefined; } -var c = foo2 `${1}`; // number -var d = foo2([], 1); // number \ No newline at end of file +var c = foo2 `${1}`; +var d = foo2([], 1); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2_ES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2_ES6.ts index 6c67de325e2..769c56e47a1 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2_ES6.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithOverloadResolution2_ES6.ts @@ -5,8 +5,8 @@ function foo1(...stuff: any[]): any { return undefined; } -var a = foo1 `${1}`; // string -var b = foo1([], 1); // number +var a = foo1 `${1}`; +var b = foo1([], 1); function foo2(strs: string[], x: number): number; function foo2(strs: TemplateStringsArray, x: number): string; @@ -14,5 +14,5 @@ function foo2(...stuff: any[]): any { return undefined; } -var c = foo2 `${1}`; // number -var d = foo2([], 1); // number \ No newline at end of file +var c = foo2 `${1}`; +var d = foo2([], 1); \ No newline at end of file diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts index 9b3852c2ddb..60f97104be3 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts @@ -1,5 +1,5 @@ interface I { - (stringParts: string[], ...rest: number[]): I; + (stringParts: TemplateStringsArray, ...rest: number[]): I; g: I; h: I; member: I; diff --git a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts index 0dc10820a98..19fb6a874cc 100644 --- a/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts +++ b/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts @@ -1,6 +1,6 @@ // @target: ES6 interface I { - (stringParts: string[], ...rest: number[]): I; + (stringParts: TemplateStringsArray, ...rest: number[]): I; g: I; h: I; member: I; diff --git a/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment1.ts b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment1.ts new file mode 100644 index 00000000000..7faebc1474b --- /dev/null +++ b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment1.ts @@ -0,0 +1,24 @@ +/// + +//// export interface Configfiles { +//// jspm: string; +//// 'jspm:browser': string; +//// 'jspm:dev': string; +//// 'jspm:node': string; +//// } + +//// let files: Configfiles; +//// files = { +//// /*0*/: '', +//// '/*1*/': '' +//// } + +goTo.marker('0'); +verify.completionListContains("jspm"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(1); + +goTo.marker('1'); +verify.completionListContains("jspm:dev"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(4); diff --git a/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment2.ts b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment2.ts new file mode 100644 index 00000000000..4ba88e7dd2a --- /dev/null +++ b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment2.ts @@ -0,0 +1,30 @@ +/// + +//// export interface Config { +//// files: ConfigFiles +//// } + +//// export interface ConfigFiles { +//// jspm: string; +//// 'jspm:browser': string; +//// 'jspm:dev': string; +//// 'jspm:node': string; +//// } + +//// let config: Config; +//// config = { +//// files: { +//// /*0*/: '', +//// '/*1*/': '' +//// } +//// } + +goTo.marker('0'); +verify.completionListContains("jspm"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(1); + +goTo.marker('1'); +verify.completionListContains("jspm:dev"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(4); diff --git a/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment3.ts b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment3.ts new file mode 100644 index 00000000000..238606520e3 --- /dev/null +++ b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment3.ts @@ -0,0 +1,26 @@ +/// + +//// let configFiles1: { +//// jspm: string; +//// 'jspm:browser': string; +//// } = { +//// /*0*/: "", +//// } + +//// let configFiles2: { +//// jspm: string; +//// 'jspm:browser': string; +//// } = { +//// jspm: "", +//// '/*1*/': "" +//// } + +goTo.marker('0'); +verify.completionListContains("jspm"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(1); + +goTo.marker('1'); +verify.completionListContains("jspm:browser"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(2); diff --git a/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment4.ts b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment4.ts new file mode 100644 index 00000000000..9855bb8c502 --- /dev/null +++ b/tests/cases/fourslash/completionForQuotedPropertyInPropertyAssignment4.ts @@ -0,0 +1,24 @@ +/// + +//// export interface ConfigFiles { +//// jspm: string; +//// 'jspm:browser': string; +//// 'jspm:dev': string; +//// 'jspm:node': string; +//// } + +//// function foo(c: ConfigFiles) {} +//// foo({ +//// j/*0*/: "", +//// "/*1*/": "", +//// }) + +goTo.marker('0'); +verify.completionListContains("jspm"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(1); + +goTo.marker('1'); +verify.completionListContains("jspm:dev"); +verify.completionListAllowsNewIdentifier(); +verify.memberListCount(4); diff --git a/tests/cases/fourslash/server/jsdocTypedefTag.ts b/tests/cases/fourslash/server/jsdocTypedefTag.ts index e645b518020..968e30a412d 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTag.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTag.ts @@ -32,16 +32,24 @@ //// var numberLike; numberLike./*numberLike*/ //// //// /** @type {Person} */ -//// var p;p./*person*/ +//// var p;p./*person*/; +//// p.personName./*personName*/; +//// p.personAge./*personAge*/; //// //// /** @type {Animal} */ -//// var a;a./*animal*/ +//// var a;a./*animal*/; +//// a.animalName./*animalName*/; +//// a.animalAge./*animalAge*/; //// //// /** @type {Cat} */ -//// var c;c./*cat*/ +//// var c;c./*cat*/; +//// c.catName./*catName*/; +//// c.catAge./*catAge*/; //// //// /** @type {Dog} */ -//// var d;d./*dog*/ +//// var d;d./*dog*/; +//// d.dogName./*dogName*/; +//// d.dogAge./*dogAge*/; goTo.marker('numberLike'); verify.memberListContains('charAt'); @@ -50,15 +58,31 @@ verify.memberListContains('toExponential'); goTo.marker('person'); verify.memberListContains('personName'); verify.memberListContains('personAge'); +goTo.marker('personName'); +verify.memberListContains('charAt'); +goTo.marker('personAge'); +verify.memberListContains('toExponential'); goTo.marker('animal'); verify.memberListContains('animalName'); verify.memberListContains('animalAge'); +goTo.marker('animalName'); +verify.memberListContains('charAt'); +goTo.marker('animalAge'); +verify.memberListContains('toExponential'); goTo.marker('dog'); verify.memberListContains('dogName'); verify.memberListContains('dogAge'); +goTo.marker('dogName'); +verify.memberListContains('charAt'); +goTo.marker('dogAge'); +verify.memberListContains('toExponential'); goTo.marker('cat'); verify.memberListContains('catName'); -verify.memberListContains('catAge'); \ No newline at end of file +verify.memberListContains('catAge'); +goTo.marker('catName'); +verify.memberListContains('charAt'); +goTo.marker('catAge'); +verify.memberListContains('toExponential'); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags3.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags3.ts index 3843ed34b16..b919afc7703 100644 --- a/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags3.ts +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags3.ts @@ -1,8 +1,8 @@ /// -//// function f(templateStrings: string[], p1_o1: string): number; -//// function f(templateStrings: string[], p1_o2: number, p2_o2: number, p3_o2: number): string; -//// function f(templateStrings: string[], p1_o3: string, p2_o3: boolean, p3_o3: number): boolean; +//// function f(templateStrings: TemplateStringsArray, p1_o1: string): number; +//// function f(templateStrings: TemplateStringsArray, p1_o2: number, p2_o2: number, p3_o2: number): string; +//// function f(templateStrings: TemplateStringsArray, p1_o3: string, p2_o3: boolean, p3_o3: number): boolean; //// function f(...foo[]: any) { return ""; } //// //// f `${/*1*/ "s/*2*/tring" /*3*/ } ${ @@ -14,7 +14,7 @@ test.markers().forEach(m => { verify.signatureHelpArgumentCountIs(3); verify.currentSignatureParameterCountIs(4); - verify.currentSignatureHelpIs('f(templateStrings: string[], p1_o3: string, p2_o3: boolean, p3_o3: number): boolean'); + verify.currentSignatureHelpIs('f(templateStrings: TemplateStringsArray, p1_o3: string, p2_o3: boolean, p3_o3: number): boolean'); verify.currentParameterHelpArgumentNameIs("p1_o3"); verify.currentParameterSpanIs("p1_o3: string"); }); \ No newline at end of file diff --git a/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags7.ts b/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags7.ts index 9a24aacf86b..5f706b8c0fa 100644 --- a/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags7.ts +++ b/tests/cases/fourslash/signatureHelpTaggedTemplatesWithOverloadedTags7.ts @@ -1,8 +1,8 @@ /// -//// function f(templateStrings: string[], p1_o1: string): number; -//// function f(templateStrings: string[], p1_o2: number, p2_o2: number, p3_o2: number): string; -//// function f(templateStrings: string[], p1_o3: string, p2_o3: boolean, p3_o3: number): boolean; +//// function f(templateStrings: TemplateStringsArray, p1_o1: string): number; +//// function f(templateStrings: TemplateStringsArray, p1_o2: number, p2_o2: number, p3_o2: number): string; +//// function f(templateStrings: TemplateStringsArray, p1_o3: string, p2_o3: boolean, p3_o3: number): boolean; //// function f(...foo[]: any) { return ""; } //// //// f `${ } ${/*1*/ fa/*2*/lse /*3*/} @@ -14,7 +14,7 @@ test.markers().forEach(m => { verify.signatureHelpArgumentCountIs(3); verify.currentSignatureParameterCountIs(4); - verify.currentSignatureHelpIs('f(templateStrings: string[], p1_o3: string, p2_o3: boolean, p3_o3: number): boolean'); + verify.currentSignatureHelpIs('f(templateStrings: TemplateStringsArray, p1_o3: string, p2_o3: boolean, p3_o3: number): boolean'); verify.currentParameterHelpArgumentNameIs("p2_o3"); verify.currentParameterSpanIs("p2_o3: boolean"); }); \ No newline at end of file diff --git a/tests/webTestServer.ts b/tests/webTestServer.ts index dab552e2619..9d28b4592ff 100644 --- a/tests/webTestServer.ts +++ b/tests/webTestServer.ts @@ -1,4 +1,4 @@ -/// +/// import http = require("http"); import fs = require("fs");