Merge remote-tracking branch 'origin/master' into tsserverVS-WIP-mixedcontent

This commit is contained in:
Vladimir Matveev 2016-07-26 12:03:52 -07:00
commit 91b0eea84e
39 changed files with 867 additions and 301 deletions

View File

@ -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";

View File

@ -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");

View File

@ -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"
},

View File

@ -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"
}
}
}

View File

@ -11544,8 +11544,20 @@ namespace ts {
const declaringClassDeclaration = <ClassLikeDeclaration>getClassLikeDeclarationOfSymbol(declaration.parent.symbol);
const declaringClass = <InterfaceType>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(<InterfaceType>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));
}

View File

@ -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

View File

@ -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 {

View File

@ -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
},

View File

@ -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;
}
}
}

View File

@ -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"));
}
}

View File

@ -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);
});
});
});
});
}

View File

@ -1,185 +1,185 @@
/// <reference path="..\harness.ts" />
/// <reference path="..\..\compiler\commandLineParser.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"]
);
});
});
}
/// <reference path="..\harness.ts" />
/// <reference path="..\..\compiler\commandLineParser.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"]
);
});
});
}

View File

@ -4383,6 +4383,7 @@ namespace ts {
kindModifiers: getSymbolModifiers(symbol),
sortText: "0",
};
}
function getCompletionEntriesFromSymbols(symbols: Symbol[], entries: CompletionEntry[], location: Node, performCharacterChecks: boolean): Map<string> {
@ -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(<ObjectLiteralElement>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(<StringLiteral>node);
}
}
function getStringLiteralCompletionEntriesFromCallExpression(argumentInfo: SignatureHelp.ArgumentListInfo) {
function getStringLiteralCompletionEntriesFromPropertyAssignment(element: ObjectLiteralElement) {
const typeChecker = program.getTypeChecker();
const type = typeChecker.getContextualType((<ObjectLiteralExpression>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[] = [];

View File

@ -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);
var dc = new DerivedC(1);

View File

@ -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;

View File

@ -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.
}

View File

@ -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;
}());

View File

@ -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))

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/0.d.ts ===
export = a;
>a : number
declare var a: number;
>a : number

View File

@ -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;

View File

@ -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

View File

@ -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'.

View File

@ -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

View File

@ -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;

View File

@ -0,0 +1,5 @@
//// [a.ts]
let x = 1;
//// [a.js]
var x = 1;

View File

@ -0,0 +1,5 @@
// @module: none
// @filename: 0.d.ts
export = a;
declare var a: number;

View File

@ -0,0 +1,8 @@
// @module: none
// @filename: 1.ts
export var j = "hello"; // error
// @filename: 0.d.ts
export = a;
declare var a: number;

View File

@ -0,0 +1,8 @@
// @module: none
// @filename: 0.d.ts
export = a;
declare var a: number;
// @filename: 1.ts
export var j = "hello"; // error

View File

@ -0,0 +1,12 @@
// @filename: tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"foo": []
}
}
}
// @filename: a.ts
let x = 1;

View File

@ -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);
var dc = new DerivedC(1);

View File

@ -0,0 +1,10 @@
class Base {
protected constructor() { }
}
class Derived extends Base {
static make() { new Base() } // ok
}
class Unrelated {
static fake() { new Base() } // error
}

View File

@ -0,0 +1,24 @@
/// <reference path='fourslash.ts'/>
//// 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);

View File

@ -0,0 +1,30 @@
/// <reference path='fourslash.ts'/>
//// 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);

View File

@ -0,0 +1,26 @@
/// <reference path='fourslash.ts'/>
//// 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);

View File

@ -0,0 +1,24 @@
/// <reference path='fourslash.ts'/>
//// 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);

View File

@ -3,22 +3,23 @@
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<link rel="icon" href="./webhost/favicon-32x32.png"/>
</head>
<body>
<div id='setup'>
<div id='setup'>
<div>
<button id='selectCompilerBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=compiler"'>Select Compiler Tests</button>
<button id='selectFourslashBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=fourslash"'>Select Fourslash Tests</button>
<button id='selectCompilerBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=compiler"'>Select Compiler Tests</button>
<button id='selectFourslashBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=fourslash"'>Select Fourslash Tests</button>
</div>
<button id='runTestBtn' onclick='runTests()'>Run Tests</button>
<button id='runTestBtn' onclick='runTests()'>Run Tests</button>
</div>
<div id="mocha"></div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../built/local/bundle.js"></script>
<script>
// mocha is going to call this on every test result and make the results page unusable for a long
// time after the tests are already done, doesn't seem necessary

View File

@ -111,7 +111,7 @@ function writeFile(path: string, data: any, opts: { recursive: boolean }) {
/// Request Handling ///
function handleResolutionRequest(filePath: string, res: http.ServerResponse) {
function handleResolutionRequest(filePath: string, res: http.ServerResponse) {
var resolvedPath = path.resolve(filePath, '');
resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests'));
resolvedPath = switchToForwardSlashes(resolvedPath);
@ -202,14 +202,13 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
break;
case RequestType.GetFile:
fs.readFile(reqPath, function (err, file) {
var ext = reqPath.substr(reqPath.lastIndexOf('.'));
var contentType = 'binary';
if (ext === '.js') contentType = 'text/javascript'
else if (ext === '.css') contentType = 'text/javascript'
else if (ext === '.html') contentType = 'text/html'
err
? send('fail', res, err.message, contentType)
: send('success', res, (<any>file), contentType);
const contentType = contentTypeForExtension(path.extname(reqPath));
if (err) {
send('fail', res, err.message, contentType);
}
else {
send('success', res, <any>file, contentType);
}
});
break;
case RequestType.ResolveFile:
@ -249,6 +248,15 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
send('unknown', res, null);
break;
}
function contentTypeForExtension(ext: string) {
switch (ext) {
case '.js': return 'text/javascript';
case '.css': return 'text/css';
case '.html': return 'text/html';
default: return 'binary';
}
}
}
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

View File

@ -7,6 +7,7 @@
"indent": [true,
"spaces"
],
"linebreak-style": [true, "CRLF"],
"one-line": [true,
"check-open-brace",
"check-whitespace"