diff --git a/Gulpfile.ts b/Gulpfile.ts index 57da2b62aa8..8797f6d2ee1 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -710,7 +710,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo 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)); + originalMap.sources = originalMap.sources.map(s => path.resolve("src", 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"; diff --git a/Jakefile.js b/Jakefile.js index f245a1f3076..5b2c2bcfca4 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -491,15 +491,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/package.json b/package.json index efe3866b6db..770278d9976 100644 --- a/package.json +++ b/package.json @@ -72,8 +72,7 @@ "run-sequence": "latest", "sorcery": "latest", "through2": "latest", - "ts-node": "latest", - "tsd": "latest", + "ts-node": "~1.1.0", "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/src/compiler/checker.ts b/src/compiler/checker.ts index 1cebd469388..6da456afcbc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11544,8 +11544,20 @@ namespace ts { const declaringClassDeclaration = getClassLikeDeclarationOfSymbol(declaration.parent.symbol); const declaringClass = getDeclaredTypeOfSymbol(declaration.parent.symbol); - // A private or protected constructor can only be instantiated within it's own class + // A private or protected constructor can only be instantiated within its own class (or a subclass, for protected) if (!isNodeWithinClass(node, declaringClassDeclaration)) { + const containingClass = getContainingClass(node); + if (containingClass) { + const containingType = getTypeOfNode(containingClass); + const baseTypes = getBaseTypes(containingType); + if (baseTypes.length) { + const baseType = baseTypes[0]; + if (flags & NodeFlags.Protected && + baseType.symbol === declaration.parent.symbol) { + return true; + } + } + } if (flags & NodeFlags.Private) { error(node, Diagnostics.Constructor_of_class_0_is_private_and_only_accessible_within_the_class_declaration, typeToString(declaringClass)); } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b82cf6a094d..7e2c6eb8d33 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -139,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", @@ -693,9 +693,6 @@ namespace ts { return output; } - // Skip over any minified JavaScript files (ending in ".min.js") - // Skip over dotted files and folders as well - const ignoreFileNamePattern = /(\.min\.js$)|([\\/]\.[\w.])/; /** * Parse the contents of a config file (tsconfig.json). * @param json The contents of the config file to parse @@ -1007,10 +1004,6 @@ namespace ts { continue; } - if (ignoreFileNamePattern.test(file)) { - continue; - } - // We may have included a wildcard path with a lower priority // extension due to the user-defined order of entries in the // "include" array. If there is a lower priority extension in the diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 0dd95e4485d..55fc067b3fa 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -933,11 +933,29 @@ namespace ts { const reservedCharacterPattern = /[^\w\s\/]/g; const wildcardCharCodes = [CharacterCodes.asterisk, CharacterCodes.question]; + /** + * Matches any single directory segment unless it is the last segment and a .min.js file + * Breakdown: + * [^./] # matches everything up to the first . character (excluding directory seperators) + * (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension + */ + const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; + const singleAsteriskRegexFragmentOther = "[^/]*"; + export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") { if (specs === undefined || specs.length === 0) { return undefined; } + const replaceWildcardCharacter = usage === "files" ? replaceWildCardCharacterFiles : replaceWildCardCharacterOther; + const singleAsteriskRegexFragment = usage === "files" ? singleAsteriskRegexFragmentFiles : singleAsteriskRegexFragmentOther; + + /** + * Regex for the ** wildcard. Matches any number of subdirectories. When used for including + * files or directories, does not match subdirectories that start with a . character + */ + const doubleAsteriskRegexFragment = usage === "exclude" ? "(/.+?)?" : "(/[^/.][^/]*)*?"; + let pattern = ""; let hasWrittenSubpattern = false; spec: for (const spec of specs) { @@ -958,13 +976,13 @@ namespace ts { components[0] = removeTrailingDirectorySeparator(components[0]); let optionalCount = 0; - for (const component of components) { + for (let component of components) { if (component === "**") { if (hasRecursiveDirectoryWildcard) { continue spec; } - subpattern += "(/.+?)?"; + subpattern += doubleAsteriskRegexFragment; hasRecursiveDirectoryWildcard = true; hasWrittenComponent = true; } @@ -978,6 +996,20 @@ namespace ts { subpattern += directorySeparator; } + if (usage !== "exclude") { + // The * and ? wildcards should not match directories or files that start with . if they + // appear first in a component. Dotted directories and files can be included explicitly + // like so: **/.*/.* + if (component.charCodeAt(0) === CharacterCodes.asterisk) { + subpattern += "([^./]" + singleAsteriskRegexFragment + ")?"; + component = component.substr(1); + } + else if (component.charCodeAt(0) === CharacterCodes.question) { + subpattern += "[^./]"; + component = component.substr(1); + } + } + subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter); hasWrittenComponent = true; } @@ -1003,8 +1035,16 @@ namespace ts { return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$"); } - function replaceWildcardCharacter(match: string) { - return match === "*" ? "[^/]*" : match === "?" ? "[^/]" : "\\" + match; + function replaceWildCardCharacterFiles(match: string) { + return replaceWildcardCharacter(match, singleAsteriskRegexFragmentFiles); + } + + function replaceWildCardCharacterOther(match: string) { + return replaceWildcardCharacter(match, singleAsteriskRegexFragmentOther); + } + + function replaceWildcardCharacter(match: string, singleAsteriskRegexFragment: string) { + return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match; } export interface FileSystemEntries { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8ffb02a8974..23018f3ef11 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2336,6 +2336,10 @@ "category": "Error", "code": 5065 }, + "Substitutions for pattern '{0}' shouldn't be an empty array.": { + "category": "Error", + "code": 5066 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -2800,11 +2804,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/performance.ts b/src/compiler/performance.ts index 63f929c0a26..89db876ae5e 100644 --- a/src/compiler/performance.ts +++ b/src/compiler/performance.ts @@ -2,7 +2,7 @@ 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()); + export const timestamp = typeof performance !== "undefined" && performance.now ? () => performance.now() : Date.now ? Date.now : () => +(new Date()); } /*@internal*/ @@ -106,4 +106,4 @@ namespace ts.performance { measures = undefined; profilerEvent = undefined; } -} \ No newline at end of file +} diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 57a3c15c302..9b7fd84bc7b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2205,6 +2205,9 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key)); } if (isArray(options.paths[key])) { + if (options.paths[key].length === 0) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitutions_for_pattern_0_shouldn_t_be_an_empty_array, key)); + } for (const subst of options.paths[key]) { const typeOfSubst = typeof subst; if (typeOfSubst === "string") { @@ -2257,7 +2260,7 @@ namespace ts { const languageVersion = options.target || ScriptTarget.ES3; const outFile = options.outFile || options.out; - const firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); + const firstNonAmbientExternalModuleSourceFile = forEach(files, f => isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); if (options.isolatedModules) { if (options.module === ModuleKind.None && languageVersion < ScriptTarget.ES6) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher)); @@ -2269,10 +2272,10 @@ namespace ts { programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } - else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) { + else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && options.module === ModuleKind.None) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet - const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); + const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none)); } // Cannot specify module gen that isn't amd or system with --out @@ -2280,9 +2283,9 @@ namespace ts { if (options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile")); } - else if (options.module === undefined && firstExternalModuleSourceFile) { - const span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - programDiagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); + else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) { + const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, firstNonAmbientExternalModuleSourceFile.externalModuleIndicator); + programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile")); } } diff --git a/src/harness/unittests/matchFiles.ts b/src/harness/unittests/matchFiles.ts index ae856f40c17..6b499e56989 100644 --- a/src/harness/unittests/matchFiles.ts +++ b/src/harness/unittests/matchFiles.ts @@ -23,6 +23,8 @@ namespace ts { "c:/dev/x/y/b.ts", "c:/dev/js/a.js", "c:/dev/js/b.js", + "c:/dev/js/d.min.js", + "c:/dev/js/ab.min.js", "c:/ext/ext.ts", "c:/ext/b/a..b.ts" ]); @@ -75,6 +77,17 @@ namespace ts { "c:/dev/jspm_packages/a.ts" ]); + const caseInsensitiveDottedFoldersHost = new Utils.MockParseConfigHost(caseInsensitiveBasePath, /*useCaseSensitiveFileNames*/ false, [ + "c:/dev/x/d.ts", + "c:/dev/x/y/d.ts", + "c:/dev/x/y/.e.ts", + "c:/dev/x/.y/a.ts", + "c:/dev/.z/.b.ts", + "c:/dev/.z/c.ts", + "c:/dev/w/.u/e.ts", + "c:/dev/g.min.js/.g/g.ts" + ]); + describe("matchFiles", () => { describe("with literal file list", () => { it("without exclusions", () => { @@ -726,6 +739,33 @@ namespace ts { assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); assert.deepEqual(actual.errors, expected.errors); }); + it("include explicitly listed .min.js files when allowJs=true", () => { + const json = { + compilerOptions: { + allowJs: true + }, + include: [ + "js/*.min.js" + ] + }; + const expected: ts.ParsedCommandLine = { + options: { + allowJs: true + }, + errors: [], + fileNames: [ + "c:/dev/js/ab.min.js", + "c:/dev/js/d.min.js" + ], + wildcardDirectories: { + "c:/dev/js": ts.WatchDirectoryFlags.None + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); it("include paths outside of the project", () => { const json = { include: [ @@ -951,6 +991,35 @@ namespace ts { assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); assert.deepEqual(actual.errors, expected.errors); }); + it("exclude .min.js files using wildcards", () => { + const json = { + compilerOptions: { + allowJs: true + }, + include: [ + "js/*.min.js" + ], + exclude: [ + "js/a*" + ] + }; + const expected: ts.ParsedCommandLine = { + options: { + allowJs: true + }, + errors: [], + fileNames: [ + "c:/dev/js/d.min.js" + ], + wildcardDirectories: { + "c:/dev/js": ts.WatchDirectoryFlags.None + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); describe("with trailing recursive directory", () => { it("in includes", () => { const json = { @@ -1145,5 +1214,122 @@ namespace ts { }); }); }); + describe("with files or folders that begin with a .", () => { + it("that are not explicitly included", () => { + const json = { + include: [ + "x/**/*", + "w/*/*" + ] + }; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [ + "c:/dev/x/d.ts", + "c:/dev/x/y/d.ts", + ], + wildcardDirectories: { + "c:/dev/x": ts.WatchDirectoryFlags.Recursive, + "c:/dev/w": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); + describe("that are explicitly included", () => { + it("without wildcards", () => { + const json = { + include: [ + "x/.y/a.ts", + "c:/dev/.z/.b.ts" + ] + }; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [ + "c:/dev/.z/.b.ts", + "c:/dev/x/.y/a.ts" + ], + wildcardDirectories: {} + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); + it("with recursive wildcards that match directories", () => { + const json = { + include: [ + "**/.*/*" + ] + }; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [ + "c:/dev/.z/c.ts", + "c:/dev/g.min.js/.g/g.ts", + "c:/dev/w/.u/e.ts", + "c:/dev/x/.y/a.ts" + ], + wildcardDirectories: { + "c:/dev": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); + it("with recursive wildcards that match nothing", () => { + const json = { + include: [ + "x/**/.y/*", + ".z/**/.*" + ] + }; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [ + "c:/dev/.z/.b.ts", + "c:/dev/x/.y/a.ts" + ], + wildcardDirectories: { + "c:/dev/.z": ts.WatchDirectoryFlags.Recursive, + "c:/dev/x": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); + it("with wildcard excludes that implicitly exclude dotted files", () => { + const json = { + include: [ + "**/.*/*" + ], + exclude: [ + "**/*" + ] + }; + const expected: ts.ParsedCommandLine = { + options: {}, + errors: [], + fileNames: [], + wildcardDirectories: {} + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveDottedFoldersHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); + }); + }); }); } \ No newline at end of file diff --git a/src/harness/unittests/tsconfigParsing.ts b/src/harness/unittests/tsconfigParsing.ts index 736d567a33a..557379dff3b 100644 --- a/src/harness/unittests/tsconfigParsing.ts +++ b/src/harness/unittests/tsconfigParsing.ts @@ -1,185 +1,185 @@ -/// -/// - -namespace ts { - describe("parseConfigFileTextToJson", () => { - function assertParseResult(jsonText: string, expectedConfigObject: { config?: any; error?: Diagnostic }) { - const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); - assert.equal(JSON.stringify(parsed), JSON.stringify(expectedConfigObject)); - } - - function assertParseError(jsonText: string) { - const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); - assert.isTrue(undefined === parsed.config); - assert.isTrue(undefined !== parsed.error); - } - - function assertParseErrorWithExcludesKeyword(jsonText: string) { - const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); - const parsedCommand = ts.parseJsonConfigFileContent(parsed.config, ts.sys, "tests/cases/unittests"); - assert.isTrue(parsedCommand.errors && parsedCommand.errors.length === 1 && - parsedCommand.errors[0].code === ts.Diagnostics.Unknown_option_excludes_Did_you_mean_exclude.code); - } - - function assertParseFileList(jsonText: string, configFileName: string, basePath: string, allFileList: string[], expectedFileList: string[]) { - const json = JSON.parse(jsonText); - const host: ParseConfigHost = new Utils.MockParseConfigHost(basePath, true, allFileList); - const parsed = ts.parseJsonConfigFileContent(json, host, basePath, /*existingOptions*/ undefined, configFileName); - assert.isTrue(arrayIsEqualTo(parsed.fileNames.sort(), expectedFileList.sort())); - } - - it("returns empty config for file with only whitespaces", () => { - assertParseResult("", { config : {} }); - assertParseResult(" ", { config : {} }); - }); - - it("returns empty config for file with comments only", () => { - assertParseResult("// Comment", { config: {} }); - assertParseResult("/* Comment*/", { config: {} }); - }); - - it("returns empty config when config is empty object", () => { - assertParseResult("{}", { config: {} }); - }); - - it("returns config object without comments", () => { - assertParseResult( - `{ // Excluded files - "exclude": [ - // Exclude d.ts - "file.d.ts" - ] - }`, { config: { exclude: ["file.d.ts"] } }); - - assertParseResult( - `{ - /* Excluded - Files - */ - "exclude": [ - /* multiline comments can be in the middle of a line */"file.d.ts" - ] - }`, { config: { exclude: ["file.d.ts"] } }); - }); - - it("keeps string content untouched", () => { - assertParseResult( - `{ - "exclude": [ - "xx//file.d.ts" - ] - }`, { config: { exclude: ["xx//file.d.ts"] } }); - assertParseResult( - `{ - "exclude": [ - "xx/*file.d.ts*/" - ] - }`, { config: { exclude: ["xx/*file.d.ts*/"] } }); - }); - - it("handles escaped characters in strings correctly", () => { - assertParseResult( - `{ - "exclude": [ - "xx\\"//files" - ] - }`, { config: { exclude: ["xx\"//files"] } }); - - assertParseResult( - `{ - "exclude": [ - "xx\\\\" // end of line comment - ] - }`, { config: { exclude: ["xx\\"] } }); - }); - - it("returns object with error when json is invalid", () => { - assertParseError("invalid"); - }); - - it("returns object when users correctly specify library", () => { - assertParseResult( - `{ - "compilerOptions": { - "lib": ["es5"] - } - }`, { - config: { compilerOptions: { lib: ["es5"] } } - }); - - assertParseResult( - `{ - "compilerOptions": { - "lib": ["es5", "es6"] - } - }`, { - config: { compilerOptions: { lib: ["es5", "es6"] } } - }); - }); - - it("returns error when tsconfig have excludes", () => { - assertParseErrorWithExcludesKeyword( - `{ - "compilerOptions": { - "lib": ["es5"] - }, - "excludes": [ - "foge.ts" - ] - }`); - }); - - it("ignore dotted files and folders", () => { - assertParseFileList( - `{}`, - "tsconfig.json", - "/apath", - ["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"], - ["/apath/test.ts"] - ); - }); - - it("allow dotted files and folders when explicitly requested", () => { - assertParseFileList( - `{ - "files": ["/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"] - }`, - "tsconfig.json", - "/apath", - ["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"], - ["/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"] - ); - }); - - it("always exclude outDir", () => { - const tsconfigWithoutExclude = - `{ - "compilerOptions": { - "outDir": "bin" - } - }`; - const tsconfigWithExclude = - `{ - "compilerOptions": { - "outDir": "bin" - }, - "exclude": [ "obj" ] - }`; - const rootDir = "/"; - const allFiles = ["/bin/a.ts", "/b.ts"]; - const expectedFiles = ["/b.ts"]; - assertParseFileList(tsconfigWithoutExclude, "tsconfig.json", rootDir, allFiles, expectedFiles); - assertParseFileList(tsconfigWithExclude, "tsconfig.json", rootDir, allFiles, expectedFiles); - }); - - it("implicitly exclude common package folders", () => { - assertParseFileList( - `{}`, - "tsconfig.json", - "/", - ["/node_modules/a.ts", "/bower_components/b.ts", "/jspm_packages/c.ts", "/d.ts", "/folder/e.ts"], - ["/d.ts", "/folder/e.ts"] - ); - }); - }); -} +/// +/// + +namespace ts { + describe("parseConfigFileTextToJson", () => { + function assertParseResult(jsonText: string, expectedConfigObject: { config?: any; error?: Diagnostic }) { + const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); + assert.equal(JSON.stringify(parsed), JSON.stringify(expectedConfigObject)); + } + + function assertParseError(jsonText: string) { + const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); + assert.isTrue(undefined === parsed.config); + assert.isTrue(undefined !== parsed.error); + } + + function assertParseErrorWithExcludesKeyword(jsonText: string) { + const parsed = ts.parseConfigFileTextToJson("/apath/tsconfig.json", jsonText); + const parsedCommand = ts.parseJsonConfigFileContent(parsed.config, ts.sys, "tests/cases/unittests"); + assert.isTrue(parsedCommand.errors && parsedCommand.errors.length === 1 && + parsedCommand.errors[0].code === ts.Diagnostics.Unknown_option_excludes_Did_you_mean_exclude.code); + } + + function assertParseFileList(jsonText: string, configFileName: string, basePath: string, allFileList: string[], expectedFileList: string[]) { + const json = JSON.parse(jsonText); + const host: ParseConfigHost = new Utils.MockParseConfigHost(basePath, true, allFileList); + const parsed = ts.parseJsonConfigFileContent(json, host, basePath, /*existingOptions*/ undefined, configFileName); + assert.isTrue(arrayIsEqualTo(parsed.fileNames.sort(), expectedFileList.sort())); + } + + it("returns empty config for file with only whitespaces", () => { + assertParseResult("", { config : {} }); + assertParseResult(" ", { config : {} }); + }); + + it("returns empty config for file with comments only", () => { + assertParseResult("// Comment", { config: {} }); + assertParseResult("/* Comment*/", { config: {} }); + }); + + it("returns empty config when config is empty object", () => { + assertParseResult("{}", { config: {} }); + }); + + it("returns config object without comments", () => { + assertParseResult( + `{ // Excluded files + "exclude": [ + // Exclude d.ts + "file.d.ts" + ] + }`, { config: { exclude: ["file.d.ts"] } }); + + assertParseResult( + `{ + /* Excluded + Files + */ + "exclude": [ + /* multiline comments can be in the middle of a line */"file.d.ts" + ] + }`, { config: { exclude: ["file.d.ts"] } }); + }); + + it("keeps string content untouched", () => { + assertParseResult( + `{ + "exclude": [ + "xx//file.d.ts" + ] + }`, { config: { exclude: ["xx//file.d.ts"] } }); + assertParseResult( + `{ + "exclude": [ + "xx/*file.d.ts*/" + ] + }`, { config: { exclude: ["xx/*file.d.ts*/"] } }); + }); + + it("handles escaped characters in strings correctly", () => { + assertParseResult( + `{ + "exclude": [ + "xx\\"//files" + ] + }`, { config: { exclude: ["xx\"//files"] } }); + + assertParseResult( + `{ + "exclude": [ + "xx\\\\" // end of line comment + ] + }`, { config: { exclude: ["xx\\"] } }); + }); + + it("returns object with error when json is invalid", () => { + assertParseError("invalid"); + }); + + it("returns object when users correctly specify library", () => { + assertParseResult( + `{ + "compilerOptions": { + "lib": ["es5"] + } + }`, { + config: { compilerOptions: { lib: ["es5"] } } + }); + + assertParseResult( + `{ + "compilerOptions": { + "lib": ["es5", "es6"] + } + }`, { + config: { compilerOptions: { lib: ["es5", "es6"] } } + }); + }); + + it("returns error when tsconfig have excludes", () => { + assertParseErrorWithExcludesKeyword( + `{ + "compilerOptions": { + "lib": ["es5"] + }, + "excludes": [ + "foge.ts" + ] + }`); + }); + + it("ignore dotted files and folders", () => { + assertParseFileList( + `{}`, + "tsconfig.json", + "/apath", + ["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"], + ["/apath/test.ts"] + ); + }); + + it("allow dotted files and folders when explicitly requested", () => { + assertParseFileList( + `{ + "files": ["/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"] + }`, + "tsconfig.json", + "/apath", + ["/apath/test.ts", "/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"], + ["/apath/.git/a.ts", "/apath/.b.ts", "/apath/..c.ts"] + ); + }); + + it("always exclude outDir", () => { + const tsconfigWithoutExclude = + `{ + "compilerOptions": { + "outDir": "bin" + } + }`; + const tsconfigWithExclude = + `{ + "compilerOptions": { + "outDir": "bin" + }, + "exclude": [ "obj" ] + }`; + const rootDir = "/"; + const allFiles = ["/bin/a.ts", "/b.ts"]; + const expectedFiles = ["/b.ts"]; + assertParseFileList(tsconfigWithoutExclude, "tsconfig.json", rootDir, allFiles, expectedFiles); + assertParseFileList(tsconfigWithExclude, "tsconfig.json", rootDir, allFiles, expectedFiles); + }); + + it("implicitly exclude common package folders", () => { + assertParseFileList( + `{}`, + "tsconfig.json", + "/", + ["/node_modules/a.ts", "/bower_components/b.ts", "/jspm_packages/c.ts", "/d.ts", "/folder/e.ts"], + ["/d.ts", "/folder/e.ts"] + ); + }); + }); +} diff --git a/src/services/services.ts b/src/services/services.ts index 9505d44794c..a9aa3dc145d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4383,6 +4383,7 @@ namespace ts { kindModifiers: getSymbolModifiers(symbol), sortText: "0", }; + } function getCompletionEntriesFromSymbols(symbols: Symbol[], entries: CompletionEntry[], location: Node, performCharacterChecks: boolean): Map { @@ -4411,22 +4412,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[] = []; diff --git a/tests/baselines/reference/classConstructorAccessibility2.errors.txt b/tests/baselines/reference/classConstructorAccessibility2.errors.txt index 7bd784ac268..337e9787e5e 100644 --- a/tests/baselines/reference/classConstructorAccessibility2.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility2.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(26,28): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(29,24): error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,28): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,10): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(37,10): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(32,24): error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(35,28): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(36,35): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(40,10): error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts(41,10): error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. ==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts (5 errors) ==== @@ -14,35 +14,39 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib class BaseB { protected constructor(public x: number) { } - createInstance() { new BaseB(1); } + createInstance() { new BaseB(2); } } class BaseC { - private constructor(public x: number) { } - createInstance() { new BaseC(1); } + private constructor(public x: number) { } + createInstance() { new BaseC(3); } + static staticInstance() { new BaseC(4); } } class DerivedA extends BaseA { constructor(public x: number) { super(x); } - createInstance() { new DerivedA(1); } - createBaseInstance() { new BaseA(1); } + createInstance() { new DerivedA(5); } + createBaseInstance() { new BaseA(6); } + static staticBaseInstance() { new BaseA(7); } } class DerivedB extends BaseB { constructor(public x: number) { super(x); } - createInstance() { new DerivedB(1); } - createBaseInstance() { new BaseB(1); } // error - ~~~~~~~~~~~~ -!!! error TS2674: Constructor of class 'BaseB' is protected and only accessible within the class declaration. + createInstance() { new DerivedB(7); } + createBaseInstance() { new BaseB(8); } // ok + static staticBaseInstance() { new BaseB(9); } // ok } class DerivedC extends BaseC { // error ~~~~~ !!! error TS2675: Cannot extend a class 'BaseC'. Class constructor is marked as private. constructor(public x: number) { super(x); } - createInstance() { new DerivedC(1); } - createBaseInstance() { new BaseC(1); } // error - ~~~~~~~~~~~~ + createInstance() { new DerivedC(9); } + createBaseInstance() { new BaseC(10); } // error + ~~~~~~~~~~~~~ +!!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. + static staticBaseInstance() { new BaseC(11); } // error + ~~~~~~~~~~~~~ !!! error TS2673: Constructor of class 'BaseC' is private and only accessible within the class declaration. } @@ -56,4 +60,5 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib var da = new DerivedA(1); var db = new DerivedB(1); - var dc = new DerivedC(1); \ No newline at end of file + var dc = new DerivedC(1); + \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility2.js b/tests/baselines/reference/classConstructorAccessibility2.js index e19589ece45..03b7af3e716 100644 --- a/tests/baselines/reference/classConstructorAccessibility2.js +++ b/tests/baselines/reference/classConstructorAccessibility2.js @@ -7,30 +7,34 @@ class BaseA { class BaseB { protected constructor(public x: number) { } - createInstance() { new BaseB(1); } + createInstance() { new BaseB(2); } } class BaseC { - private constructor(public x: number) { } - createInstance() { new BaseC(1); } + private constructor(public x: number) { } + createInstance() { new BaseC(3); } + static staticInstance() { new BaseC(4); } } class DerivedA extends BaseA { constructor(public x: number) { super(x); } - createInstance() { new DerivedA(1); } - createBaseInstance() { new BaseA(1); } + createInstance() { new DerivedA(5); } + createBaseInstance() { new BaseA(6); } + static staticBaseInstance() { new BaseA(7); } } class DerivedB extends BaseB { constructor(public x: number) { super(x); } - createInstance() { new DerivedB(1); } - createBaseInstance() { new BaseB(1); } // error + createInstance() { new DerivedB(7); } + createBaseInstance() { new BaseB(8); } // ok + static staticBaseInstance() { new BaseB(9); } // ok } class DerivedC extends BaseC { // error constructor(public x: number) { super(x); } - createInstance() { new DerivedC(1); } - createBaseInstance() { new BaseC(1); } // error + createInstance() { new DerivedC(9); } + createBaseInstance() { new BaseC(10); } // error + static staticBaseInstance() { new BaseC(11); } // error } var ba = new BaseA(1); @@ -39,7 +43,8 @@ var bc = new BaseC(1); // error var da = new DerivedA(1); var db = new DerivedB(1); -var dc = new DerivedC(1); +var dc = new DerivedC(1); + //// [classConstructorAccessibility2.js] var __extends = (this && this.__extends) || function (d, b) { @@ -58,14 +63,15 @@ var BaseB = (function () { function BaseB(x) { this.x = x; } - BaseB.prototype.createInstance = function () { new BaseB(1); }; + BaseB.prototype.createInstance = function () { new BaseB(2); }; return BaseB; }()); var BaseC = (function () { function BaseC(x) { this.x = x; } - BaseC.prototype.createInstance = function () { new BaseC(1); }; + BaseC.prototype.createInstance = function () { new BaseC(3); }; + BaseC.staticInstance = function () { new BaseC(4); }; return BaseC; }()); var DerivedA = (function (_super) { @@ -74,8 +80,9 @@ var DerivedA = (function (_super) { _super.call(this, x); this.x = x; } - DerivedA.prototype.createInstance = function () { new DerivedA(1); }; - DerivedA.prototype.createBaseInstance = function () { new BaseA(1); }; + DerivedA.prototype.createInstance = function () { new DerivedA(5); }; + DerivedA.prototype.createBaseInstance = function () { new BaseA(6); }; + DerivedA.staticBaseInstance = function () { new BaseA(7); }; return DerivedA; }(BaseA)); var DerivedB = (function (_super) { @@ -84,8 +91,9 @@ var DerivedB = (function (_super) { _super.call(this, x); this.x = x; } - DerivedB.prototype.createInstance = function () { new DerivedB(1); }; - DerivedB.prototype.createBaseInstance = function () { new BaseB(1); }; // error + DerivedB.prototype.createInstance = function () { new DerivedB(7); }; + DerivedB.prototype.createBaseInstance = function () { new BaseB(8); }; // ok + DerivedB.staticBaseInstance = function () { new BaseB(9); }; // ok return DerivedB; }(BaseB)); var DerivedC = (function (_super) { @@ -94,8 +102,9 @@ var DerivedC = (function (_super) { _super.call(this, x); this.x = x; } - DerivedC.prototype.createInstance = function () { new DerivedC(1); }; - DerivedC.prototype.createBaseInstance = function () { new BaseC(1); }; // error + DerivedC.prototype.createInstance = function () { new DerivedC(9); }; + DerivedC.prototype.createBaseInstance = function () { new BaseC(10); }; // error + DerivedC.staticBaseInstance = function () { new BaseC(11); }; // error return DerivedC; }(BaseC)); var ba = new BaseA(1); @@ -121,24 +130,28 @@ declare class BaseC { x: number; private constructor(x); createInstance(): void; + static staticInstance(): void; } declare class DerivedA extends BaseA { x: number; constructor(x: number); createInstance(): void; createBaseInstance(): void; + static staticBaseInstance(): void; } declare class DerivedB extends BaseB { x: number; constructor(x: number); createInstance(): void; createBaseInstance(): void; + static staticBaseInstance(): void; } declare class DerivedC extends BaseC { x: number; constructor(x: number); createInstance(): void; createBaseInstance(): void; + static staticBaseInstance(): void; } declare var ba: BaseA; declare var bb: any; diff --git a/tests/baselines/reference/classConstructorAccessibility5.errors.txt b/tests/baselines/reference/classConstructorAccessibility5.errors.txt new file mode 100644 index 00000000000..f372bd5c10a --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility5.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility5.ts(9,21): error TS2674: Constructor of class 'Base' is protected and only accessible within the class declaration. + + +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility5.ts (1 errors) ==== + class Base { + protected constructor() { } + } + class Derived extends Base { + static make() { new Base() } // ok + } + + class Unrelated { + static fake() { new Base() } // error + ~~~~~~~~~~ +!!! error TS2674: Constructor of class 'Base' is protected and only accessible within the class declaration. + } + \ No newline at end of file diff --git a/tests/baselines/reference/classConstructorAccessibility5.js b/tests/baselines/reference/classConstructorAccessibility5.js new file mode 100644 index 00000000000..ec9e9f83a8e --- /dev/null +++ b/tests/baselines/reference/classConstructorAccessibility5.js @@ -0,0 +1,38 @@ +//// [classConstructorAccessibility5.ts] +class Base { + protected constructor() { } +} +class Derived extends Base { + static make() { new Base() } // ok +} + +class Unrelated { + static fake() { new Base() } // error +} + + +//// [classConstructorAccessibility5.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Base = (function () { + function Base() { + } + return Base; +}()); +var Derived = (function (_super) { + __extends(Derived, _super); + function Derived() { + _super.apply(this, arguments); + } + Derived.make = function () { new Base(); }; // ok + return Derived; +}(Base)); +var Unrelated = (function () { + function Unrelated() { + } + Unrelated.fake = function () { new Base(); }; // error + return Unrelated; +}()); diff --git a/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.symbols b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.symbols new file mode 100644 index 00000000000..d3d338e0d14 --- /dev/null +++ b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/0.d.ts === + +export = a; +>a : Symbol(a, Decl(0.d.ts, 2, 11)) + +declare var a: number; +>a : Symbol(a, Decl(0.d.ts, 2, 11)) + diff --git a/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.types b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.types new file mode 100644 index 00000000000..c5e2c0b80f8 --- /dev/null +++ b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/0.d.ts === + +export = a; +>a : number + +declare var a: number; +>a : number + diff --git a/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.errors.txt b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.errors.txt new file mode 100644 index 00000000000..bcf5d91c015 --- /dev/null +++ b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/1.ts(2,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. + + +==== tests/cases/compiler/1.ts (1 errors) ==== + + export var j = "hello"; // error + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. + +==== tests/cases/compiler/0.d.ts (0 errors) ==== + export = a; + declare var a: number; \ No newline at end of file diff --git a/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.js b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.js new file mode 100644 index 00000000000..b56988de44c --- /dev/null +++ b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.ts] //// + +//// [1.ts] + +export var j = "hello"; // error + +//// [0.d.ts] +export = a; +declare var a: number; + +//// [1.js] +"use strict"; +exports.j = "hello"; // error diff --git a/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.errors.txt b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.errors.txt new file mode 100644 index 00000000000..eb215693cd7 --- /dev/null +++ b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/1.ts(1,1): error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. + + +==== tests/cases/compiler/0.d.ts (0 errors) ==== + + export = a; + declare var a: number; + +==== tests/cases/compiler/1.ts (1 errors) ==== + export var j = "hello"; // error + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'. + \ No newline at end of file diff --git a/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.js b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.js new file mode 100644 index 00000000000..8c75af24034 --- /dev/null +++ b/tests/baselines/reference/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.ts] //// + +//// [0.d.ts] + +export = a; +declare var a: number; + +//// [1.ts] +export var j = "hello"; // error + + +//// [1.js] +"use strict"; +exports.j = "hello"; // error diff --git a/tests/baselines/reference/pathsValidation3.errors.txt b/tests/baselines/reference/pathsValidation3.errors.txt new file mode 100644 index 00000000000..3bb85203e6e --- /dev/null +++ b/tests/baselines/reference/pathsValidation3.errors.txt @@ -0,0 +1,6 @@ +error TS5066: Substitutions for pattern 'foo' shouldn't be an empty array. + + +!!! error TS5066: Substitutions for pattern 'foo' shouldn't be an empty array. +==== tests/cases/compiler/a.ts (0 errors) ==== + let x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathsValidation3.js b/tests/baselines/reference/pathsValidation3.js new file mode 100644 index 00000000000..bfffc647f63 --- /dev/null +++ b/tests/baselines/reference/pathsValidation3.js @@ -0,0 +1,5 @@ +//// [a.ts] +let x = 1; + +//// [a.js] +var x = 1; diff --git a/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.ts b/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.ts new file mode 100644 index 00000000000..71ec411a4f5 --- /dev/null +++ b/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile1.ts @@ -0,0 +1,5 @@ +// @module: none +// @filename: 0.d.ts + +export = a; +declare var a: number; \ No newline at end of file diff --git a/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.ts b/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.ts new file mode 100644 index 00000000000..160f80dba97 --- /dev/null +++ b/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile2.ts @@ -0,0 +1,8 @@ +// @module: none + +// @filename: 1.ts +export var j = "hello"; // error + +// @filename: 0.d.ts +export = a; +declare var a: number; \ No newline at end of file diff --git a/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.ts b/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.ts new file mode 100644 index 00000000000..e13933a13d0 --- /dev/null +++ b/tests/cases/compiler/noErrorUsingImportExportModuleAugmentationInDeclarationFile3.ts @@ -0,0 +1,8 @@ +// @module: none + +// @filename: 0.d.ts +export = a; +declare var a: number; + +// @filename: 1.ts +export var j = "hello"; // error diff --git a/tests/cases/compiler/pathsValidation3.ts b/tests/cases/compiler/pathsValidation3.ts new file mode 100644 index 00000000000..28db959a881 --- /dev/null +++ b/tests/cases/compiler/pathsValidation3.ts @@ -0,0 +1,12 @@ +// @filename: tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "foo": [] + } + } +} + +// @filename: a.ts +let x = 1; \ No newline at end of file diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts index 2a961e2c067..5e0ed2454df 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility2.ts @@ -7,30 +7,34 @@ class BaseA { class BaseB { protected constructor(public x: number) { } - createInstance() { new BaseB(1); } + createInstance() { new BaseB(2); } } class BaseC { - private constructor(public x: number) { } - createInstance() { new BaseC(1); } + private constructor(public x: number) { } + createInstance() { new BaseC(3); } + static staticInstance() { new BaseC(4); } } class DerivedA extends BaseA { constructor(public x: number) { super(x); } - createInstance() { new DerivedA(1); } - createBaseInstance() { new BaseA(1); } + createInstance() { new DerivedA(5); } + createBaseInstance() { new BaseA(6); } + static staticBaseInstance() { new BaseA(7); } } class DerivedB extends BaseB { constructor(public x: number) { super(x); } - createInstance() { new DerivedB(1); } - createBaseInstance() { new BaseB(1); } // error + createInstance() { new DerivedB(7); } + createBaseInstance() { new BaseB(8); } // ok + static staticBaseInstance() { new BaseB(9); } // ok } class DerivedC extends BaseC { // error constructor(public x: number) { super(x); } - createInstance() { new DerivedC(1); } - createBaseInstance() { new BaseC(1); } // error + createInstance() { new DerivedC(9); } + createBaseInstance() { new BaseC(10); } // error + static staticBaseInstance() { new BaseC(11); } // error } var ba = new BaseA(1); @@ -39,4 +43,4 @@ var bc = new BaseC(1); // error var da = new DerivedA(1); var db = new DerivedB(1); -var dc = new DerivedC(1); \ No newline at end of file +var dc = new DerivedC(1); diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility5.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility5.ts new file mode 100644 index 00000000000..ada5108a23a --- /dev/null +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility5.ts @@ -0,0 +1,10 @@ +class Base { + protected constructor() { } +} +class Derived extends Base { + static make() { new Base() } // ok +} + +class Unrelated { + static fake() { new Base() } // error +} 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/webTestResults.html b/tests/webTestResults.html index 2993681934e..9c403248f94 100644 --- a/tests/webTestResults.html +++ b/tests/webTestResults.html @@ -3,22 +3,23 @@ Mocha Tests + -
+
- - + +
- +
- +
- +