mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into omitComments
Conflicts: src/compiler/emitter.ts
This commit is contained in:
+88
-66
@@ -388,7 +388,7 @@ namespace ts {
|
||||
return node1.pos <= node2.pos;
|
||||
}
|
||||
|
||||
if (!compilerOptions.out) {
|
||||
if (!compilerOptions.outFile && !compilerOptions.out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -965,7 +965,9 @@ namespace ts {
|
||||
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
|
||||
let moduleName = escapeIdentifier(moduleReferenceLiteral.text);
|
||||
|
||||
if (!moduleName) return;
|
||||
if (!moduleName) {
|
||||
return;
|
||||
}
|
||||
let isRelative = isExternalModuleNameRelative(moduleName);
|
||||
if (!isRelative) {
|
||||
let symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule);
|
||||
@@ -973,20 +975,9 @@ namespace ts {
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
let fileName: string;
|
||||
let sourceFile: SourceFile;
|
||||
while (true) {
|
||||
fileName = normalizePath(combinePaths(searchPath, moduleName));
|
||||
sourceFile = forEach(supportedExtensions, extension => host.getSourceFile(fileName + extension));
|
||||
if (sourceFile || isRelative) {
|
||||
break;
|
||||
}
|
||||
let parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
searchPath = parentPath;
|
||||
}
|
||||
|
||||
let fileName = getResolvedModuleFileName(getSourceFile(location), moduleReferenceLiteral.text);
|
||||
let sourceFile = fileName && host.getSourceFile(fileName);
|
||||
if (sourceFile) {
|
||||
if (sourceFile.symbol) {
|
||||
return sourceFile.symbol;
|
||||
@@ -2175,10 +2166,13 @@ namespace ts {
|
||||
function collectLinkedAliases(node: Identifier): Node[] {
|
||||
let exportSymbol: Symbol;
|
||||
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
|
||||
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node);
|
||||
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
|
||||
}
|
||||
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
|
||||
exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent);
|
||||
let exportSpecifier = <ExportSpecifier>node.parent;
|
||||
exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
|
||||
getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
|
||||
resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
|
||||
}
|
||||
let result: Node[] = [];
|
||||
if (exportSymbol) {
|
||||
@@ -3131,52 +3125,66 @@ namespace ts {
|
||||
setObjectTypeMembers(type, members, arrayType.callSignatures, arrayType.constructSignatures, arrayType.stringIndexType, arrayType.numberIndexType);
|
||||
}
|
||||
|
||||
function findMatchingSignature(signature: Signature, signatureList: Signature[]): Signature {
|
||||
for (let s of signatureList) {
|
||||
// Only signatures with no type parameters may differ in return types
|
||||
if (compareSignatures(signature, s, /*compareReturnTypes*/ !!signature.typeParameters, compareTypes)) {
|
||||
function findMatchingSignature(signatureList: Signature[], signature: Signature, partialMatch: boolean, ignoreReturnTypes: boolean): Signature {
|
||||
for (let s of signatureList) {
|
||||
if (compareSignatures(s, signature, partialMatch, ignoreReturnTypes, compareTypes)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findMatchingSignatures(signature: Signature, signatureLists: Signature[][]): Signature[] {
|
||||
function findMatchingSignatures(signatureLists: Signature[][], signature: Signature, listIndex: number): Signature[] {
|
||||
if (signature.typeParameters) {
|
||||
// We require an exact match for generic signatures, so we only return signatures from the first
|
||||
// signature list and only if they have exact matches in the other signature lists.
|
||||
if (listIndex > 0) {
|
||||
return undefined;
|
||||
}
|
||||
for (let i = 1; i < signatureLists.length; i++) {
|
||||
if (!findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ false)) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return [signature];
|
||||
}
|
||||
let result: Signature[] = undefined;
|
||||
for (let i = 1; i < signatureLists.length; i++) {
|
||||
let match = findMatchingSignature(signature, signatureLists[i]);
|
||||
for (let i = 0; i < signatureLists.length; i++) {
|
||||
// Allow matching non-generic signatures to have excess parameters and different return types
|
||||
let match = i === listIndex ? signature : findMatchingSignature(signatureLists[i], signature, /*partialMatch*/ true, /*ignoreReturnTypes*/ true);
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
if (!result) {
|
||||
result = [signature];
|
||||
}
|
||||
if (match !== signature) {
|
||||
result.push(match);
|
||||
if (!contains(result, match)) {
|
||||
(result || (result = [])).push(match);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// The signatures of a union type are those signatures that are present and identical in each of the
|
||||
// constituent types, except that non-generic signatures may differ in return types. When signatures
|
||||
// differ in return types, the resulting return type is the union of the constituent return types.
|
||||
// The signatures of a union type are those signatures that are present in each of the constituent types.
|
||||
// Generic signatures must match exactly, but non-generic signatures are allowed to have extra optional
|
||||
// parameters and may differ in return types. When signatures differ in return types, the resulting return
|
||||
// type is the union of the constituent return types.
|
||||
function getUnionSignatures(types: Type[], kind: SignatureKind): Signature[] {
|
||||
let signatureLists = map(types, t => getSignaturesOfType(t, kind));
|
||||
let result: Signature[] = undefined;
|
||||
for (let source of signatureLists[0]) {
|
||||
let unionSignatures = findMatchingSignatures(source, signatureLists);
|
||||
if (unionSignatures) {
|
||||
let signature: Signature = undefined;
|
||||
if (unionSignatures.length === 1 || source.typeParameters) {
|
||||
signature = source;
|
||||
for (let i = 0; i < signatureLists.length; i++) {
|
||||
for (let signature of signatureLists[i]) {
|
||||
// Only process signatures with parameter lists that aren't already in the result list
|
||||
if (!result || !findMatchingSignature(result, signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true)) {
|
||||
let unionSignatures = findMatchingSignatures(signatureLists, signature, i);
|
||||
if (unionSignatures) {
|
||||
let s = signature;
|
||||
// Union the result types when more than one signature matches
|
||||
if (unionSignatures.length > 1) {
|
||||
s = cloneSignature(signature);
|
||||
// Clear resolved return type we possibly got from cloneSignature
|
||||
s.resolvedReturnType = undefined;
|
||||
s.unionSignatures = unionSignatures;
|
||||
}
|
||||
(result || (result = [])).push(s);
|
||||
}
|
||||
}
|
||||
else {
|
||||
signature = cloneSignature(source);
|
||||
// Clear resolved return type we possibly got from cloneSignature
|
||||
signature.resolvedReturnType = undefined;
|
||||
signature.unionSignatures = unionSignatures;
|
||||
}
|
||||
(result || (result = [])).push(signature);
|
||||
}
|
||||
}
|
||||
return result || emptyArray;
|
||||
@@ -5272,7 +5280,7 @@ namespace ts {
|
||||
}
|
||||
let result = Ternary.True;
|
||||
for (let i = 0, len = sourceSignatures.length; i < len; ++i) {
|
||||
let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*compareReturnTypes*/ true, isRelatedTo);
|
||||
let related = compareSignatures(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
|
||||
if (!related) {
|
||||
return Ternary.False;
|
||||
}
|
||||
@@ -5402,14 +5410,18 @@ namespace ts {
|
||||
return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp));
|
||||
}
|
||||
|
||||
function compareSignatures(source: Signature, target: Signature, compareReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
|
||||
function compareSignatures(source: Signature, target: Signature, partialMatch: boolean, ignoreReturnTypes: boolean, compareTypes: (s: Type, t: Type) => Ternary): Ternary {
|
||||
if (source === target) {
|
||||
return Ternary.True;
|
||||
}
|
||||
if (source.parameters.length !== target.parameters.length ||
|
||||
source.minArgumentCount !== target.minArgumentCount ||
|
||||
source.hasRestParameter !== target.hasRestParameter) {
|
||||
return Ternary.False;
|
||||
if (!partialMatch ||
|
||||
source.parameters.length < target.parameters.length && !source.hasRestParameter ||
|
||||
source.minArgumentCount > target.minArgumentCount) {
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
let result = Ternary.True;
|
||||
if (source.typeParameters && target.typeParameters) {
|
||||
@@ -5431,16 +5443,18 @@ namespace ts {
|
||||
// M and N (the signatures) are instantiated using type Any as the type argument for all type parameters declared by M and N
|
||||
source = getErasedSignature(source);
|
||||
target = getErasedSignature(target);
|
||||
for (let i = 0, len = source.parameters.length; i < len; i++) {
|
||||
let s = source.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
|
||||
let t = target.hasRestParameter && i === len - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
|
||||
let sourceLen = source.parameters.length;
|
||||
let targetLen = target.parameters.length;
|
||||
for (let i = 0; i < targetLen; i++) {
|
||||
let s = source.hasRestParameter && i === sourceLen - 1 ? getRestTypeOfSignature(source) : getTypeOfSymbol(source.parameters[i]);
|
||||
let t = target.hasRestParameter && i === targetLen - 1 ? getRestTypeOfSignature(target) : getTypeOfSymbol(target.parameters[i]);
|
||||
let related = compareTypes(s, t);
|
||||
if (!related) {
|
||||
return Ternary.False;
|
||||
}
|
||||
result &= related;
|
||||
}
|
||||
if (compareReturnTypes) {
|
||||
if (!ignoreReturnTypes) {
|
||||
result &= compareTypes(getReturnTypeOfSignature(source), getReturnTypeOfSignature(target));
|
||||
}
|
||||
return result;
|
||||
@@ -6954,20 +6968,13 @@ namespace ts {
|
||||
let signatureList: Signature[];
|
||||
let types = (<UnionType>type).types;
|
||||
for (let current of types) {
|
||||
// The signature set of all constituent type with call signatures should match
|
||||
// So number of signatures allowed is either 0 or 1
|
||||
if (signatureList &&
|
||||
getSignaturesOfStructuredType(current, SignatureKind.Call).length > 1) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let signature = getNonGenericSignature(current);
|
||||
if (signature) {
|
||||
if (!signatureList) {
|
||||
// This signature will contribute to contextual union signature
|
||||
signatureList = [signature];
|
||||
}
|
||||
else if (!compareSignatures(signatureList[0], signature, /*compareReturnTypes*/ false, compareTypes)) {
|
||||
else if (!compareSignatures(signatureList[0], signature, /*partialMatch*/ false, /*ignoreReturnTypes*/ true, compareTypes)) {
|
||||
// Signatures aren't identical, do not use
|
||||
return undefined;
|
||||
}
|
||||
@@ -11377,9 +11384,16 @@ namespace ts {
|
||||
// serialize the type metadata.
|
||||
if (node && node.kind === SyntaxKind.TypeReference) {
|
||||
let root = getFirstIdentifier((<TypeReferenceNode>node).typeName);
|
||||
let rootSymbol = resolveName(root, root.text, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
|
||||
if (rootSymbol && rootSymbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) {
|
||||
markAliasSymbolAsReferenced(rootSymbol);
|
||||
let meaning = root.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace;
|
||||
// Resolve type so we know which symbol is referenced
|
||||
let rootSymbol = resolveName(root, root.text, meaning | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
|
||||
// Resolved symbol is alias
|
||||
if (rootSymbol && rootSymbol.flags & SymbolFlags.Alias) {
|
||||
let aliasTarget = resolveAlias(rootSymbol);
|
||||
// If alias has value symbol - mark alias as referenced
|
||||
if (aliasTarget.flags & SymbolFlags.Value && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) {
|
||||
markAliasSymbolAsReferenced(rootSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13315,7 +13329,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
if (languageVersion >= ScriptTarget.ES6 && !isInAmbientContext(node)) {
|
||||
// Import equals declaration is deprecated in es6 or above
|
||||
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead);
|
||||
}
|
||||
@@ -13838,7 +13852,11 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (introducesArgumentsExoticObject(location)) {
|
||||
copySymbol(argumentsSymbol, meaning);
|
||||
}
|
||||
|
||||
memberFlags = location.flags;
|
||||
location = location.parent;
|
||||
}
|
||||
@@ -14391,6 +14409,10 @@ namespace ts {
|
||||
|
||||
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
|
||||
let typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true);
|
||||
// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
|
||||
if (!typeSymbol) {
|
||||
return TypeReferenceSerializationKind.ObjectType;
|
||||
}
|
||||
let type = getDeclaredTypeOfSymbol(typeSymbol);
|
||||
if (type === unknownType) {
|
||||
return TypeReferenceSerializationKind.Unknown;
|
||||
|
||||
@@ -120,6 +120,13 @@ namespace ts {
|
||||
{
|
||||
name: "out",
|
||||
type: "string",
|
||||
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
|
||||
// for correct behaviour, please use outFile
|
||||
paramType: Diagnostics.FILE,
|
||||
},
|
||||
{
|
||||
name: "outFile",
|
||||
type: "string",
|
||||
isFilePath: true,
|
||||
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
|
||||
paramType: Diagnostics.FILE,
|
||||
@@ -218,7 +225,16 @@ namespace ts {
|
||||
type: "boolean",
|
||||
experimental: true,
|
||||
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "moduleResolution",
|
||||
type: {
|
||||
"node": ModuleResolutionKind.NodeJs,
|
||||
"classic": ModuleResolutionKind.Classic
|
||||
},
|
||||
experimental: true,
|
||||
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6
|
||||
}
|
||||
];
|
||||
|
||||
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace ts {
|
||||
set,
|
||||
contains,
|
||||
remove,
|
||||
clear,
|
||||
forEachValue: forEachValueInMap
|
||||
};
|
||||
|
||||
@@ -51,6 +52,10 @@ namespace ts {
|
||||
function normalizeKey(key: string) {
|
||||
return getCanonicalFileName(normalizeSlashes(key));
|
||||
}
|
||||
|
||||
function clear() {
|
||||
files = {};
|
||||
}
|
||||
}
|
||||
|
||||
export const enum Comparison {
|
||||
@@ -716,7 +721,7 @@ namespace ts {
|
||||
/**
|
||||
* List of supported extensions in order of file resolution precedence.
|
||||
*/
|
||||
export const supportedExtensions = [".tsx", ".ts", ".d.ts"];
|
||||
export const supportedExtensions = [".ts", ".tsx", ".d.ts"];
|
||||
|
||||
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
|
||||
export function removeFileExtension(path: string): string {
|
||||
|
||||
@@ -1574,7 +1574,7 @@ namespace ts {
|
||||
? referencedFile.fileName // Declaration file, use declaration file name
|
||||
: shouldEmitToOwnFile(referencedFile, compilerOptions)
|
||||
? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
|
||||
: removeFileExtension(compilerOptions.out) + ".d.ts"; // Global out file
|
||||
: removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts"; // Global out file
|
||||
|
||||
declFileName = getRelativePathToDirectoryOrUrl(
|
||||
getDirectoryPath(normalizeSlashes(jsFilePath)),
|
||||
|
||||
@@ -506,19 +506,11 @@ namespace ts {
|
||||
Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." },
|
||||
Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." },
|
||||
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
|
||||
Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified without specifying 'sourceMap' option." },
|
||||
Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option." },
|
||||
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." },
|
||||
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." },
|
||||
Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." },
|
||||
Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." },
|
||||
Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." },
|
||||
Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." },
|
||||
Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." },
|
||||
Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." },
|
||||
Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." },
|
||||
Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." },
|
||||
Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." },
|
||||
Option_0_cannot_be_specified_without_specifying_option_1: { code: 5052, category: DiagnosticCategory.Error, key: "Option '{0}' cannot be specified without specifying option '{1}'." },
|
||||
Option_0_cannot_be_specified_with_option_1: { code: 5053, category: DiagnosticCategory.Error, key: "Option '{0}' cannot be specified with option '{1}'." },
|
||||
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
|
||||
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
|
||||
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
|
||||
@@ -569,11 +561,11 @@ namespace ts {
|
||||
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
|
||||
Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
|
||||
Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
|
||||
Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." },
|
||||
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
|
||||
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
|
||||
Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower: { code: 6067, category: DiagnosticCategory.Message, key: "Option 'experimentalAsyncFunctions' cannot be specified when targeting ES5 or lower." },
|
||||
Enables_experimental_support_for_ES7_async_functions: { code: 6068, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 async functions." },
|
||||
Specifies_module_resolution_strategy_Colon_node_Node_or_classic_TypeScript_pre_1_6: { code: 6069, category: DiagnosticCategory.Message, key: "Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) ." },
|
||||
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
|
||||
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
|
||||
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },
|
||||
|
||||
@@ -2013,59 +2013,27 @@
|
||||
"category": "Error",
|
||||
"code": 5033
|
||||
},
|
||||
"Option 'mapRoot' cannot be specified without specifying 'sourceMap' option.": {
|
||||
"category": "Error",
|
||||
"code": 5038
|
||||
},
|
||||
"Option 'sourceRoot' cannot be specified without specifying 'sourceMap' option.": {
|
||||
"category": "Error",
|
||||
"code": 5039
|
||||
},
|
||||
"Option 'noEmit' cannot be specified with option 'out' or 'outDir'.": {
|
||||
"category": "Error",
|
||||
"code": 5040
|
||||
},
|
||||
"Option 'noEmit' cannot be specified with option 'declaration'.": {
|
||||
"category": "Error",
|
||||
"code": 5041
|
||||
},
|
||||
"Option 'project' cannot be mixed with source files on a command line.": {
|
||||
"category": "Error",
|
||||
"code": 5042
|
||||
},
|
||||
"Option 'declaration' cannot be specified with option 'isolatedModules'.": {
|
||||
"category": "Error",
|
||||
"code": 5044
|
||||
},
|
||||
"Option 'noEmitOnError' cannot be specified with option 'isolatedModules'.": {
|
||||
"category": "Error",
|
||||
"code": 5045
|
||||
},
|
||||
"Option 'out' cannot be specified with option 'isolatedModules'.": {
|
||||
"category": "Error",
|
||||
"code": 5046
|
||||
},
|
||||
"Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": {
|
||||
"category": "Error",
|
||||
"code": 5047
|
||||
},
|
||||
"Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.": {
|
||||
"category": "Error",
|
||||
"code": 5048
|
||||
},
|
||||
"Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.": {
|
||||
"category": "Error",
|
||||
"code": 5049
|
||||
},
|
||||
"Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.": {
|
||||
"category": "Error",
|
||||
"code": 5050
|
||||
},
|
||||
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
|
||||
"category": "Error",
|
||||
"code": 5051
|
||||
},
|
||||
|
||||
"Option '{0}' cannot be specified without specifying option '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 5052
|
||||
},
|
||||
"Option '{0}' cannot be specified with option '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 5053
|
||||
},
|
||||
|
||||
"Concatenate and emit output to single file.": {
|
||||
"category": "Message",
|
||||
"code": 6001
|
||||
@@ -2266,10 +2234,6 @@
|
||||
"category": "Message",
|
||||
"code": 6081
|
||||
},
|
||||
"Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified.": {
|
||||
"category": "Error",
|
||||
"code": 6064
|
||||
},
|
||||
"Enables experimental support for ES7 decorators.": {
|
||||
"category": "Message",
|
||||
"code": 6065
|
||||
@@ -2286,6 +2250,10 @@
|
||||
"category": "Message",
|
||||
"code": 6068
|
||||
},
|
||||
"Specifies module resolution strategy: 'node' (Node) or 'classic' (TypeScript pre 1.6) .": {
|
||||
"category": "Message",
|
||||
"code": 6069
|
||||
},
|
||||
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
|
||||
+388
-69
@@ -78,18 +78,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
});
|
||||
|
||||
if (compilerOptions.out) {
|
||||
emitFile(compilerOptions.out);
|
||||
if (compilerOptions.outFile || compilerOptions.out) {
|
||||
emitFile(compilerOptions.outFile || compilerOptions.out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
|
||||
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
|
||||
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, forEach(host.getSourceFiles(), shouldEmitJsx) ? ".jsx" : ".js");
|
||||
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js");
|
||||
emitFile(jsFilePath, targetSourceFile);
|
||||
}
|
||||
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
|
||||
emitFile(compilerOptions.out);
|
||||
else if (!isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
|
||||
emitFile(compilerOptions.outFile || compilerOptions.out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
let writeComment = writeCommentRange;
|
||||
|
||||
/** Emit a node */
|
||||
let emit = emitNodeWithoutSourceMap;
|
||||
let emit = emitNodeWithCommentsAndWithoutSourcemap;
|
||||
|
||||
/** Called just before starting emit of a node */
|
||||
let emitStart = function (node: Node) { };
|
||||
@@ -687,9 +687,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitNodeWithCommentsAndWithSourcemap(node: Node) {
|
||||
emitNodeConsideringCommentsOption(node, emitNodeWithSourceMap);
|
||||
}
|
||||
|
||||
writeEmittedFiles = writeJavaScriptAndSourceMapFile;
|
||||
emit = emitNodeWithSourceMap;
|
||||
emit = emitNodeWithCommentsAndWithSourcemap;
|
||||
emitStart = recordEmitNodeStartSpan;
|
||||
emitEnd = recordEmitNodeEndSpan;
|
||||
emitToken = writeTextWithSpanRecord;
|
||||
@@ -1515,7 +1519,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return;
|
||||
}
|
||||
}
|
||||
writeTextOfNode(currentSourceFile, node);
|
||||
|
||||
if (nodeIsSynthesized(node)) {
|
||||
write(node.text);
|
||||
}
|
||||
else {
|
||||
writeTextOfNode(currentSourceFile, node);
|
||||
}
|
||||
}
|
||||
|
||||
function isNameOfNestedRedeclaration(node: Identifier) {
|
||||
@@ -1542,6 +1552,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
else if (isNameOfNestedRedeclaration(node)) {
|
||||
write(getGeneratedNameForNode(node));
|
||||
}
|
||||
else if (nodeIsSynthesized(node)) {
|
||||
write(node.text);
|
||||
}
|
||||
else {
|
||||
writeTextOfNode(currentSourceFile, node);
|
||||
}
|
||||
@@ -2126,7 +2139,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(node.right);
|
||||
emit(node.right);
|
||||
}
|
||||
|
||||
function emitEntityNameAsExpression(node: EntityName, useFallback: boolean) {
|
||||
@@ -2818,7 +2831,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitNodeWithoutSourceMap(counter);
|
||||
write(" < ");
|
||||
|
||||
emitNodeWithoutSourceMap(rhsReference);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(rhsReference);
|
||||
write(".length");
|
||||
|
||||
emitEnd(node.initializer);
|
||||
@@ -2853,7 +2866,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
else {
|
||||
// The following call does not include the initializer, so we have
|
||||
// to emit it separately.
|
||||
emitNodeWithoutSourceMap(declaration);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(declaration);
|
||||
write(" = ");
|
||||
emitNodeWithoutSourceMap(rhsIterationValue);
|
||||
}
|
||||
@@ -2876,7 +2889,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitDestructuring(assignmentExpression, /*isAssignmentExpressionStatement*/ true, /*value*/ undefined);
|
||||
}
|
||||
else {
|
||||
emitNodeWithoutSourceMap(assignmentExpression);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(assignmentExpression);
|
||||
}
|
||||
}
|
||||
emitEnd(node.initializer);
|
||||
@@ -3032,7 +3045,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
write("exports.");
|
||||
}
|
||||
}
|
||||
emitNodeWithoutSourceMap(node.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(node.name);
|
||||
emitEnd(node.name);
|
||||
}
|
||||
|
||||
@@ -3078,7 +3091,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
write("default");
|
||||
}
|
||||
else {
|
||||
emitNodeWithoutSourceMap(node.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(node.name);
|
||||
}
|
||||
write(`", `);
|
||||
emitDeclarationName(node);
|
||||
@@ -3116,7 +3129,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitStart(specifier.name);
|
||||
emitContainingModuleName(specifier);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
|
||||
emitEnd(specifier.name);
|
||||
write(" = ");
|
||||
emitExpressionIdentifier(name);
|
||||
@@ -3131,7 +3144,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
writeLine();
|
||||
emitStart(specifier.name);
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
|
||||
write(`", `);
|
||||
emitExpressionIdentifier(specifier.propertyName || specifier.name);
|
||||
write(")");
|
||||
@@ -3176,7 +3189,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
if (exportChanged) {
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(name);
|
||||
write(`", `);
|
||||
}
|
||||
|
||||
@@ -3408,7 +3421,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
if (exportChanged) {
|
||||
write(`${exportFunctionForFile}("`);
|
||||
emitNodeWithoutSourceMap(node.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(node.name);
|
||||
write(`", `);
|
||||
}
|
||||
|
||||
@@ -3564,9 +3577,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitEnd(parameter);
|
||||
write(" { ");
|
||||
emitStart(parameter);
|
||||
emitNodeWithoutSourceMap(paramName);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(paramName);
|
||||
write(" = ");
|
||||
emitNodeWithoutSourceMap(initializer);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(initializer);
|
||||
emitEnd(parameter);
|
||||
write("; }");
|
||||
}
|
||||
@@ -3589,7 +3602,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitLeadingComments(restParam);
|
||||
emitStart(restParam);
|
||||
write("var ");
|
||||
emitNodeWithoutSourceMap(restParam.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
|
||||
write(" = [];");
|
||||
emitEnd(restParam);
|
||||
emitTrailingComments(restParam);
|
||||
@@ -3610,7 +3623,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
increaseIndent();
|
||||
writeLine();
|
||||
emitStart(restParam);
|
||||
emitNodeWithoutSourceMap(restParam.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(restParam.name);
|
||||
write("[" + tempName + " - " + restIndex + "] = arguments[" + tempName + "];");
|
||||
emitEnd(restParam);
|
||||
decreaseIndent();
|
||||
@@ -3631,7 +3644,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
function emitDeclarationName(node: Declaration) {
|
||||
if (node.name) {
|
||||
emitNodeWithoutSourceMap(node.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(node.name);
|
||||
}
|
||||
else {
|
||||
write(getGeneratedNameForNode(node));
|
||||
@@ -3675,6 +3688,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
||||
emitStart(node);
|
||||
// For targeting below es6, emit functions-like declaration including arrow function using function keyword.
|
||||
// When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead
|
||||
if (!shouldEmitAsArrowFunction(node)) {
|
||||
@@ -3700,6 +3714,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) {
|
||||
emitExportMemberAssignments((<FunctionDeclaration>node).name);
|
||||
}
|
||||
|
||||
emitEnd(node);
|
||||
if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) {
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
@@ -4055,10 +4071,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
function emitMemberAccessForPropertyName(memberName: DeclarationName) {
|
||||
// TODO: (jfreeman,drosen): comment on why this is emitNodeWithoutSourceMap instead of emit here.
|
||||
// This does not emit source map because it is emitted by caller as caller
|
||||
// is aware how the property name changes to the property access
|
||||
// eg. public x = 10; becomes this.x and static x = 10 becomes className.x
|
||||
if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) {
|
||||
write("[");
|
||||
emitNodeWithoutSourceMap(memberName);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(memberName);
|
||||
write("]");
|
||||
}
|
||||
else if (memberName.kind === SyntaxKind.ComputedPropertyName) {
|
||||
@@ -4066,7 +4084,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
else {
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(memberName);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(memberName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4134,10 +4152,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitMemberAccessForPropertyName((<MethodDeclaration>member).name);
|
||||
emitEnd((<MethodDeclaration>member).name);
|
||||
write(" = ");
|
||||
emitStart(member);
|
||||
emitFunctionDeclaration(<MethodDeclaration>member);
|
||||
emitEnd(member);
|
||||
emitEnd(member);
|
||||
write(";");
|
||||
emitTrailingComments(member);
|
||||
}
|
||||
@@ -5124,7 +5140,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
argumentsWritten++;
|
||||
}
|
||||
if (shouldEmitParamTypesMetadata(node)) {
|
||||
debugger;
|
||||
if (writeComma || argumentsWritten) {
|
||||
write(", ");
|
||||
}
|
||||
@@ -5343,13 +5358,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitExportMemberAssignments(<Identifier>node.name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Some bundlers (SystemJS builder) sometimes want to rename dependencies.
|
||||
* Here we check if alternative name was provided for a given moduleName and return it if possible.
|
||||
*/
|
||||
function tryRenameExternalModule(moduleName: LiteralExpression): string {
|
||||
if (currentSourceFile.renamedDependencies && hasProperty(currentSourceFile.renamedDependencies, moduleName.text)) {
|
||||
return `"${currentSourceFile.renamedDependencies[moduleName.text]}"`
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function emitRequire(moduleName: Expression) {
|
||||
if (moduleName.kind === SyntaxKind.StringLiteral) {
|
||||
write("require(");
|
||||
emitStart(moduleName);
|
||||
emitLiteral(<LiteralExpression>moduleName);
|
||||
emitEnd(moduleName);
|
||||
let text = tryRenameExternalModule(<LiteralExpression>moduleName);
|
||||
if (text) {
|
||||
write(text);
|
||||
}
|
||||
else {
|
||||
emitStart(moduleName);
|
||||
emitLiteral(<LiteralExpression>moduleName);
|
||||
emitEnd(moduleName);
|
||||
}
|
||||
emitToken(SyntaxKind.CloseParenToken, moduleName.end);
|
||||
}
|
||||
else {
|
||||
@@ -5563,11 +5595,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitStart(specifier);
|
||||
emitContainingModuleName(specifier);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(specifier.name);
|
||||
write(" = ");
|
||||
write(generatedName);
|
||||
write(".");
|
||||
emitNodeWithoutSourceMap(specifier.propertyName || specifier.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(specifier.propertyName || specifier.name);
|
||||
write(";");
|
||||
emitEnd(specifier);
|
||||
}
|
||||
@@ -5590,7 +5622,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
else {
|
||||
if (!node.exportClause || resolver.isValueAliasDeclaration(node)) {
|
||||
emitStart(node);
|
||||
write("export ");
|
||||
if (node.exportClause) {
|
||||
// export { x, y, ... }
|
||||
@@ -5603,10 +5634,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
if (node.moduleSpecifier) {
|
||||
write(" from ");
|
||||
emitNodeWithoutSourceMap(node.moduleSpecifier);
|
||||
emit(node.moduleSpecifier);
|
||||
}
|
||||
write(";");
|
||||
emitEnd(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5620,13 +5650,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
if (needsComma) {
|
||||
write(", ");
|
||||
}
|
||||
emitStart(specifier);
|
||||
if (specifier.propertyName) {
|
||||
emitNodeWithoutSourceMap(specifier.propertyName);
|
||||
emit(specifier.propertyName);
|
||||
write(" as ");
|
||||
}
|
||||
emitNodeWithoutSourceMap(specifier.name);
|
||||
emitEnd(specifier);
|
||||
emit(specifier.name);
|
||||
needsComma = true;
|
||||
}
|
||||
}
|
||||
@@ -5752,7 +5780,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
function getExternalModuleNameText(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): string {
|
||||
let moduleName = getExternalModuleName(importNode);
|
||||
if (moduleName.kind === SyntaxKind.StringLiteral) {
|
||||
return getLiteralText(<LiteralExpression>moduleName);
|
||||
return tryRenameExternalModule(<LiteralExpression>moduleName) || getLiteralText(<LiteralExpression>moduleName);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@@ -5913,7 +5941,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
writeLine();
|
||||
write("'");
|
||||
if (node.kind === SyntaxKind.Identifier) {
|
||||
emitNodeWithoutSourceMap(node);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(node);
|
||||
}
|
||||
else {
|
||||
emitDeclarationName(<Declaration>node);
|
||||
@@ -6211,9 +6239,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
let e = (<ExportDeclaration>entry).exportClause.elements[i];
|
||||
write(`"`);
|
||||
emitNodeWithoutSourceMap(e.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(e.name);
|
||||
write(`": ${parameterName}["`);
|
||||
emitNodeWithoutSourceMap(e.propertyName || e.name);
|
||||
emitNodeWithCommentsAndWithoutSourcemap(e.propertyName || e.name);
|
||||
write(`"]`);
|
||||
}
|
||||
decreaseIndent();
|
||||
@@ -6317,10 +6345,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
groupIndices[text] = dependencyGroups.length;
|
||||
dependencyGroups.push([externalImports[i]]);
|
||||
}
|
||||
|
||||
|
||||
if (i !== 0) {
|
||||
write(", ");
|
||||
}
|
||||
|
||||
write(text);
|
||||
}
|
||||
write(`], function(${exportFunctionForFile}) {`);
|
||||
@@ -6492,9 +6521,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function trimReactWhitespace(node: JsxText): string {
|
||||
function trimReactWhitespaceAndApplyEntities(node: JsxText): string {
|
||||
let result: string = undefined;
|
||||
let text = getTextOfNode(node);
|
||||
let text = getTextOfNode(node, /*includeTrivia*/ true);
|
||||
let firstNonWhitespace = 0;
|
||||
let lastNonWhitespace = -1;
|
||||
|
||||
@@ -6517,19 +6546,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (firstNonWhitespace !== -1) {
|
||||
let part = text.substr(firstNonWhitespace);
|
||||
result = (result ? result + "\" + ' ' + \"" : "") + part;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
// Replace entities like
|
||||
result = result.replace(/&(\w+);/g, function(s: any, m: string) {
|
||||
if (entities[m] !== undefined) {
|
||||
return String.fromCharCode(entities[m]);
|
||||
}
|
||||
else {
|
||||
return s;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function getTextToEmit(node: JsxText) {
|
||||
switch (compilerOptions.jsx) {
|
||||
case JsxEmit.React:
|
||||
let text = trimReactWhitespace(node);
|
||||
if (text.length === 0) {
|
||||
let text = trimReactWhitespaceAndApplyEntities(node);
|
||||
if (text === undefined || text.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
@@ -6537,7 +6579,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
case JsxEmit.Preserve:
|
||||
default:
|
||||
return getTextOfNode(node, true);
|
||||
return getTextOfNode(node, /*includeTrivia*/ true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6545,13 +6587,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
switch (compilerOptions.jsx) {
|
||||
case JsxEmit.React:
|
||||
write("\"");
|
||||
write(trimReactWhitespace(node));
|
||||
write(trimReactWhitespaceAndApplyEntities(node));
|
||||
write("\"");
|
||||
break;
|
||||
|
||||
case JsxEmit.Preserve:
|
||||
default: // Emit JSX-preserve as default when no --jsx flag is specified
|
||||
writer.writeLiteral(getTextOfNode(node, true));
|
||||
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -6669,28 +6711,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitLeadingComments(node.endOfFileToken);
|
||||
}
|
||||
|
||||
function emitNodeWithoutSourceMap(node: Node): void {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
function emitNodeWithCommentsAndWithoutSourcemap(node: Node): void {
|
||||
emitNodeConsideringCommentsOption(node, emitNodeWithoutSourceMap);
|
||||
}
|
||||
|
||||
if (node.flags & NodeFlags.Ambient) {
|
||||
return emitCommentsOnNotEmittedNode(node);
|
||||
}
|
||||
function emitNodeConsideringCommentsOption(node: Node, emitNodeConsideringSourcemap: (node: Node) => void): void {
|
||||
if (node) {
|
||||
if (node.flags & NodeFlags.Ambient) {
|
||||
return emitCommentsOnNotEmittedNode(node);
|
||||
}
|
||||
|
||||
let emitComments = shouldEmitLeadingAndTrailingComments(node);
|
||||
if (emitComments) {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
if (isSpecializedCommentHandling(node)) {
|
||||
// This is the node that will handle its own comments and sourcemap
|
||||
return emitNodeWithoutSourceMap(node);
|
||||
}
|
||||
|
||||
emitJavaScriptWorker(node);
|
||||
let emitComments = shouldEmitLeadingAndTrailingComments(node);
|
||||
if (emitComments) {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
||||
if (emitComments) {
|
||||
emitTrailingComments(node);
|
||||
emitNodeConsideringSourcemap(node);
|
||||
|
||||
if (emitComments) {
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitLeadingAndTrailingComments(node: Node) {
|
||||
function emitNodeWithoutSourceMap(node: Node): void {
|
||||
if (node) {
|
||||
emitJavaScriptWorker(node);
|
||||
}
|
||||
}
|
||||
|
||||
function isSpecializedCommentHandling(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
// All of these entities are emitted in a specialized fashion. As such, we allow
|
||||
// the specialized methods for each to handle the comments on the nodes.
|
||||
@@ -6700,8 +6755,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitLeadingAndTrailingComments(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.VariableStatement:
|
||||
return shouldEmitLeadingAndTrailingCommentsForVariableStatement(<VariableStatement>node);
|
||||
|
||||
@@ -6716,6 +6775,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return shouldEmitEnumDeclaration(<EnumDeclaration>node);
|
||||
}
|
||||
|
||||
// If the node is emitted in specialized fashion, dont emit comments as this node will handle
|
||||
// emitting comments when emitting itself
|
||||
Debug.assert(!isSpecializedCommentHandling(node));
|
||||
|
||||
// If this is the expression body of an arrow function that we're down-leveling,
|
||||
// then we don't want to emit comments when we emit the body. It will have already
|
||||
// been taken care of when we emitted the 'return' statement for the function
|
||||
@@ -7123,4 +7186,260 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var entities: Map<number> = {
|
||||
"quot": 0x0022,
|
||||
"amp": 0x0026,
|
||||
"apos": 0x0027,
|
||||
"lt": 0x003C,
|
||||
"gt": 0x003E,
|
||||
"nbsp": 0x00A0,
|
||||
"iexcl": 0x00A1,
|
||||
"cent": 0x00A2,
|
||||
"pound": 0x00A3,
|
||||
"curren": 0x00A4,
|
||||
"yen": 0x00A5,
|
||||
"brvbar": 0x00A6,
|
||||
"sect": 0x00A7,
|
||||
"uml": 0x00A8,
|
||||
"copy": 0x00A9,
|
||||
"ordf": 0x00AA,
|
||||
"laquo": 0x00AB,
|
||||
"not": 0x00AC,
|
||||
"shy": 0x00AD,
|
||||
"reg": 0x00AE,
|
||||
"macr": 0x00AF,
|
||||
"deg": 0x00B0,
|
||||
"plusmn": 0x00B1,
|
||||
"sup2": 0x00B2,
|
||||
"sup3": 0x00B3,
|
||||
"acute": 0x00B4,
|
||||
"micro": 0x00B5,
|
||||
"para": 0x00B6,
|
||||
"middot": 0x00B7,
|
||||
"cedil": 0x00B8,
|
||||
"sup1": 0x00B9,
|
||||
"ordm": 0x00BA,
|
||||
"raquo": 0x00BB,
|
||||
"frac14": 0x00BC,
|
||||
"frac12": 0x00BD,
|
||||
"frac34": 0x00BE,
|
||||
"iquest": 0x00BF,
|
||||
"Agrave": 0x00C0,
|
||||
"Aacute": 0x00C1,
|
||||
"Acirc": 0x00C2,
|
||||
"Atilde": 0x00C3,
|
||||
"Auml": 0x00C4,
|
||||
"Aring": 0x00C5,
|
||||
"AElig": 0x00C6,
|
||||
"Ccedil": 0x00C7,
|
||||
"Egrave": 0x00C8,
|
||||
"Eacute": 0x00C9,
|
||||
"Ecirc": 0x00CA,
|
||||
"Euml": 0x00CB,
|
||||
"Igrave": 0x00CC,
|
||||
"Iacute": 0x00CD,
|
||||
"Icirc": 0x00CE,
|
||||
"Iuml": 0x00CF,
|
||||
"ETH": 0x00D0,
|
||||
"Ntilde": 0x00D1,
|
||||
"Ograve": 0x00D2,
|
||||
"Oacute": 0x00D3,
|
||||
"Ocirc": 0x00D4,
|
||||
"Otilde": 0x00D5,
|
||||
"Ouml": 0x00D6,
|
||||
"times": 0x00D7,
|
||||
"Oslash": 0x00D8,
|
||||
"Ugrave": 0x00D9,
|
||||
"Uacute": 0x00DA,
|
||||
"Ucirc": 0x00DB,
|
||||
"Uuml": 0x00DC,
|
||||
"Yacute": 0x00DD,
|
||||
"THORN": 0x00DE,
|
||||
"szlig": 0x00DF,
|
||||
"agrave": 0x00E0,
|
||||
"aacute": 0x00E1,
|
||||
"acirc": 0x00E2,
|
||||
"atilde": 0x00E3,
|
||||
"auml": 0x00E4,
|
||||
"aring": 0x00E5,
|
||||
"aelig": 0x00E6,
|
||||
"ccedil": 0x00E7,
|
||||
"egrave": 0x00E8,
|
||||
"eacute": 0x00E9,
|
||||
"ecirc": 0x00EA,
|
||||
"euml": 0x00EB,
|
||||
"igrave": 0x00EC,
|
||||
"iacute": 0x00ED,
|
||||
"icirc": 0x00EE,
|
||||
"iuml": 0x00EF,
|
||||
"eth": 0x00F0,
|
||||
"ntilde": 0x00F1,
|
||||
"ograve": 0x00F2,
|
||||
"oacute": 0x00F3,
|
||||
"ocirc": 0x00F4,
|
||||
"otilde": 0x00F5,
|
||||
"ouml": 0x00F6,
|
||||
"divide": 0x00F7,
|
||||
"oslash": 0x00F8,
|
||||
"ugrave": 0x00F9,
|
||||
"uacute": 0x00FA,
|
||||
"ucirc": 0x00FB,
|
||||
"uuml": 0x00FC,
|
||||
"yacute": 0x00FD,
|
||||
"thorn": 0x00FE,
|
||||
"yuml": 0x00FF,
|
||||
"OElig": 0x0152,
|
||||
"oelig": 0x0153,
|
||||
"Scaron": 0x0160,
|
||||
"scaron": 0x0161,
|
||||
"Yuml": 0x0178,
|
||||
"fnof": 0x0192,
|
||||
"circ": 0x02C6,
|
||||
"tilde": 0x02DC,
|
||||
"Alpha": 0x0391,
|
||||
"Beta": 0x0392,
|
||||
"Gamma": 0x0393,
|
||||
"Delta": 0x0394,
|
||||
"Epsilon": 0x0395,
|
||||
"Zeta": 0x0396,
|
||||
"Eta": 0x0397,
|
||||
"Theta": 0x0398,
|
||||
"Iota": 0x0399,
|
||||
"Kappa": 0x039A,
|
||||
"Lambda": 0x039B,
|
||||
"Mu": 0x039C,
|
||||
"Nu": 0x039D,
|
||||
"Xi": 0x039E,
|
||||
"Omicron": 0x039F,
|
||||
"Pi": 0x03A0,
|
||||
"Rho": 0x03A1,
|
||||
"Sigma": 0x03A3,
|
||||
"Tau": 0x03A4,
|
||||
"Upsilon": 0x03A5,
|
||||
"Phi": 0x03A6,
|
||||
"Chi": 0x03A7,
|
||||
"Psi": 0x03A8,
|
||||
"Omega": 0x03A9,
|
||||
"alpha": 0x03B1,
|
||||
"beta": 0x03B2,
|
||||
"gamma": 0x03B3,
|
||||
"delta": 0x03B4,
|
||||
"epsilon": 0x03B5,
|
||||
"zeta": 0x03B6,
|
||||
"eta": 0x03B7,
|
||||
"theta": 0x03B8,
|
||||
"iota": 0x03B9,
|
||||
"kappa": 0x03BA,
|
||||
"lambda": 0x03BB,
|
||||
"mu": 0x03BC,
|
||||
"nu": 0x03BD,
|
||||
"xi": 0x03BE,
|
||||
"omicron": 0x03BF,
|
||||
"pi": 0x03C0,
|
||||
"rho": 0x03C1,
|
||||
"sigmaf": 0x03C2,
|
||||
"sigma": 0x03C3,
|
||||
"tau": 0x03C4,
|
||||
"upsilon": 0x03C5,
|
||||
"phi": 0x03C6,
|
||||
"chi": 0x03C7,
|
||||
"psi": 0x03C8,
|
||||
"omega": 0x03C9,
|
||||
"thetasym": 0x03D1,
|
||||
"upsih": 0x03D2,
|
||||
"piv": 0x03D6,
|
||||
"ensp": 0x2002,
|
||||
"emsp": 0x2003,
|
||||
"thinsp": 0x2009,
|
||||
"zwnj": 0x200C,
|
||||
"zwj": 0x200D,
|
||||
"lrm": 0x200E,
|
||||
"rlm": 0x200F,
|
||||
"ndash": 0x2013,
|
||||
"mdash": 0x2014,
|
||||
"lsquo": 0x2018,
|
||||
"rsquo": 0x2019,
|
||||
"sbquo": 0x201A,
|
||||
"ldquo": 0x201C,
|
||||
"rdquo": 0x201D,
|
||||
"bdquo": 0x201E,
|
||||
"dagger": 0x2020,
|
||||
"Dagger": 0x2021,
|
||||
"bull": 0x2022,
|
||||
"hellip": 0x2026,
|
||||
"permil": 0x2030,
|
||||
"prime": 0x2032,
|
||||
"Prime": 0x2033,
|
||||
"lsaquo": 0x2039,
|
||||
"rsaquo": 0x203A,
|
||||
"oline": 0x203E,
|
||||
"frasl": 0x2044,
|
||||
"euro": 0x20AC,
|
||||
"image": 0x2111,
|
||||
"weierp": 0x2118,
|
||||
"real": 0x211C,
|
||||
"trade": 0x2122,
|
||||
"alefsym": 0x2135,
|
||||
"larr": 0x2190,
|
||||
"uarr": 0x2191,
|
||||
"rarr": 0x2192,
|
||||
"darr": 0x2193,
|
||||
"harr": 0x2194,
|
||||
"crarr": 0x21B5,
|
||||
"lArr": 0x21D0,
|
||||
"uArr": 0x21D1,
|
||||
"rArr": 0x21D2,
|
||||
"dArr": 0x21D3,
|
||||
"hArr": 0x21D4,
|
||||
"forall": 0x2200,
|
||||
"part": 0x2202,
|
||||
"exist": 0x2203,
|
||||
"empty": 0x2205,
|
||||
"nabla": 0x2207,
|
||||
"isin": 0x2208,
|
||||
"notin": 0x2209,
|
||||
"ni": 0x220B,
|
||||
"prod": 0x220F,
|
||||
"sum": 0x2211,
|
||||
"minus": 0x2212,
|
||||
"lowast": 0x2217,
|
||||
"radic": 0x221A,
|
||||
"prop": 0x221D,
|
||||
"infin": 0x221E,
|
||||
"ang": 0x2220,
|
||||
"and": 0x2227,
|
||||
"or": 0x2228,
|
||||
"cap": 0x2229,
|
||||
"cup": 0x222A,
|
||||
"int": 0x222B,
|
||||
"there4": 0x2234,
|
||||
"sim": 0x223C,
|
||||
"cong": 0x2245,
|
||||
"asymp": 0x2248,
|
||||
"ne": 0x2260,
|
||||
"equiv": 0x2261,
|
||||
"le": 0x2264,
|
||||
"ge": 0x2265,
|
||||
"sub": 0x2282,
|
||||
"sup": 0x2283,
|
||||
"nsub": 0x2284,
|
||||
"sube": 0x2286,
|
||||
"supe": 0x2287,
|
||||
"oplus": 0x2295,
|
||||
"otimes": 0x2297,
|
||||
"perp": 0x22A5,
|
||||
"sdot": 0x22C5,
|
||||
"lceil": 0x2308,
|
||||
"rceil": 0x2309,
|
||||
"lfloor": 0x230A,
|
||||
"rfloor": 0x230B,
|
||||
"lang": 0x2329,
|
||||
"rang": 0x232A,
|
||||
"loz": 0x25CA,
|
||||
"spades": 0x2660,
|
||||
"clubs": 0x2663,
|
||||
"hearts": 0x2665,
|
||||
"diams": 0x2666
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5831,7 +5831,6 @@ namespace ts {
|
||||
|
||||
if (!name) {
|
||||
parseErrorAtPosition(pos, 0, Diagnostics.Identifier_expected);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let preName: Identifier, postName: Identifier;
|
||||
|
||||
+436
-89
@@ -8,6 +8,9 @@ namespace ts {
|
||||
/* @internal */ export let ioWriteTime = 0;
|
||||
|
||||
/** The version of the TypeScript compiler release */
|
||||
|
||||
let emptyArray: any[] = [];
|
||||
|
||||
export const version = "1.6.0";
|
||||
|
||||
export function findConfigFile(searchPath: string): string {
|
||||
@@ -25,6 +28,201 @@ namespace ts {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveTripleslashReference(moduleName: string, containingFile: string): string {
|
||||
let basePath = getDirectoryPath(containingFile);
|
||||
let referencedFileName = isRootedDiskPath(moduleName) ? moduleName : combinePaths(basePath, moduleName);
|
||||
return normalizePath(referencedFileName);
|
||||
}
|
||||
|
||||
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule {
|
||||
let moduleResolution = compilerOptions.moduleResolution !== undefined
|
||||
? compilerOptions.moduleResolution
|
||||
: compilerOptions.module === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic;
|
||||
|
||||
switch (moduleResolution) {
|
||||
case ModuleResolutionKind.NodeJs: return nodeModuleNameResolver(moduleName, containingFile, host);
|
||||
case ModuleResolutionKind.Classic: return classicNameResolver(moduleName, containingFile, compilerOptions, host);
|
||||
}
|
||||
}
|
||||
|
||||
export function nodeModuleNameResolver(moduleName: string, containingFile: string, host: ModuleResolutionHost): ResolvedModule {
|
||||
let containingDirectory = getDirectoryPath(containingFile);
|
||||
|
||||
if (getRootLength(moduleName) !== 0 || nameStartsWithDotSlashOrDotDotSlash(moduleName)) {
|
||||
let failedLookupLocations: string[] = [];
|
||||
let candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
let resolvedFileName = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ false, failedLookupLocations, host);
|
||||
|
||||
if (resolvedFileName) {
|
||||
return { resolvedFileName, failedLookupLocations };
|
||||
}
|
||||
|
||||
resolvedFileName = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ false, failedLookupLocations, host);
|
||||
return { resolvedFileName, failedLookupLocations };
|
||||
}
|
||||
else {
|
||||
return loadModuleFromNodeModules(moduleName, containingDirectory, host);
|
||||
}
|
||||
}
|
||||
|
||||
function loadNodeModuleFromFile(candidate: string, loadOnlyDts: boolean, failedLookupLocation: string[], host: ModuleResolutionHost): string {
|
||||
if (loadOnlyDts) {
|
||||
return tryLoad(".d.ts");
|
||||
}
|
||||
else {
|
||||
return forEach(supportedExtensions, tryLoad);
|
||||
}
|
||||
|
||||
function tryLoad(ext: string): string {
|
||||
let fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
|
||||
if (host.fileExists(fileName)) {
|
||||
return fileName;
|
||||
}
|
||||
else {
|
||||
failedLookupLocation.push(fileName);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadNodeModuleFromDirectory(candidate: string, loadOnlyDts: boolean, failedLookupLocation: string[], host: ModuleResolutionHost): string {
|
||||
let packageJsonPath = combinePaths(candidate, "package.json");
|
||||
if (host.fileExists(packageJsonPath)) {
|
||||
|
||||
let jsonContent: { typings?: string };
|
||||
|
||||
try {
|
||||
let jsonText = host.readFile(packageJsonPath);
|
||||
jsonContent = jsonText ? <{ typings?: string }>JSON.parse(jsonText) : { typings: undefined };
|
||||
}
|
||||
catch (e) {
|
||||
// gracefully handle if readFile fails or returns not JSON
|
||||
jsonContent = { typings: undefined };
|
||||
}
|
||||
|
||||
if (jsonContent.typings) {
|
||||
let result = loadNodeModuleFromFile(normalizePath(combinePaths(candidate, jsonContent.typings)), loadOnlyDts, failedLookupLocation, host);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
|
||||
failedLookupLocation.push(packageJsonPath);
|
||||
}
|
||||
|
||||
return loadNodeModuleFromFile(combinePaths(candidate, "index"), loadOnlyDts, failedLookupLocation, host);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost): ResolvedModule {
|
||||
let failedLookupLocations: string[] = [];
|
||||
directory = normalizeSlashes(directory);
|
||||
while (true) {
|
||||
let baseName = getBaseFileName(directory);
|
||||
if (baseName !== "node_modules") {
|
||||
let nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
let candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
let result = loadNodeModuleFromFile(candidate, /* loadOnlyDts */ true, failedLookupLocations, host);
|
||||
if (result) {
|
||||
return { resolvedFileName: result, failedLookupLocations };
|
||||
}
|
||||
|
||||
result = loadNodeModuleFromDirectory(candidate, /* loadOnlyDts */ true, failedLookupLocations, host);
|
||||
if (result) {
|
||||
return { resolvedFileName: result, failedLookupLocations };
|
||||
}
|
||||
}
|
||||
|
||||
let parentPath = getDirectoryPath(directory);
|
||||
if (parentPath === directory) {
|
||||
break;
|
||||
}
|
||||
|
||||
directory = parentPath;
|
||||
}
|
||||
|
||||
return { resolvedFileName: undefined, failedLookupLocations };
|
||||
}
|
||||
|
||||
export function baseUrlModuleNameResolver(moduleName: string, containingFile: string, baseUrl: string, host: ModuleResolutionHost): ResolvedModule {
|
||||
Debug.assert(baseUrl !== undefined);
|
||||
|
||||
let normalizedModuleName = normalizeSlashes(moduleName);
|
||||
let basePart = useBaseUrl(moduleName) ? baseUrl : getDirectoryPath(containingFile);
|
||||
let candidate = normalizePath(combinePaths(basePart, moduleName));
|
||||
|
||||
let failedLookupLocations: string[] = [];
|
||||
|
||||
return forEach(supportedExtensions, ext => tryLoadFile(candidate + ext)) || { resolvedFileName: undefined, failedLookupLocations };
|
||||
|
||||
function tryLoadFile(location: string): ResolvedModule {
|
||||
if (host.fileExists(location)) {
|
||||
return { resolvedFileName: location, failedLookupLocations };
|
||||
}
|
||||
else {
|
||||
failedLookupLocations.push(location);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function nameStartsWithDotSlashOrDotDotSlash(name: string) {
|
||||
let i = name.lastIndexOf("./", 1);
|
||||
return i === 0 || (i === 1 && name.charCodeAt(0) === CharacterCodes.dot);
|
||||
}
|
||||
|
||||
function useBaseUrl(moduleName: string): boolean {
|
||||
// path is not rooted
|
||||
// module name does not start with './' or '../'
|
||||
return getRootLength(moduleName) === 0 && !nameStartsWithDotSlashOrDotDotSlash(moduleName);
|
||||
}
|
||||
|
||||
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModule {
|
||||
|
||||
// module names that contain '!' are used to reference resources and are not resolved to actual files on disk
|
||||
if (moduleName.indexOf('!') != -1) {
|
||||
return { resolvedFileName: undefined, failedLookupLocations: [] };
|
||||
}
|
||||
|
||||
let searchPath = getDirectoryPath(containingFile);
|
||||
let searchName: string;
|
||||
|
||||
let failedLookupLocations: string[] = [];
|
||||
|
||||
let referencedSourceFile: string;
|
||||
while (true) {
|
||||
searchName = normalizePath(combinePaths(searchPath, moduleName));
|
||||
referencedSourceFile = forEach(supportedExtensions, extension => {
|
||||
if (extension === ".tsx" && !compilerOptions.jsx) {
|
||||
// resolve .tsx files only if jsx support is enabled
|
||||
// 'logical not' handles both undefined and None cases
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let candidate = searchName + extension;
|
||||
if (host.fileExists(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
else {
|
||||
failedLookupLocations.push(candidate);
|
||||
}
|
||||
});
|
||||
|
||||
if (referencedSourceFile) {
|
||||
break;
|
||||
}
|
||||
|
||||
let parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
searchPath = parentPath;
|
||||
}
|
||||
|
||||
return { resolvedFileName: referencedSourceFile, failedLookupLocations };
|
||||
}
|
||||
|
||||
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
|
||||
let currentDirectory: string;
|
||||
@@ -92,7 +290,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
const newLine = getNewLineCharacter(options);
|
||||
|
||||
|
||||
|
||||
return {
|
||||
getSourceFile,
|
||||
getDefaultLibFileName: options => combinePaths(getDirectoryPath(normalizePath(sys.getExecutingFilePath())), getDefaultLibFileName(options)),
|
||||
@@ -100,7 +299,9 @@ namespace ts {
|
||||
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
getCanonicalFileName,
|
||||
getNewLine: () => newLine
|
||||
getNewLine: () => newLine,
|
||||
fileExists: fileName => sys.fileExists(fileName),
|
||||
readFile: fileName => sys.readFile(fileName)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -143,7 +344,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program {
|
||||
export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program {
|
||||
let program: Program;
|
||||
let files: SourceFile[] = [];
|
||||
let diagnostics = createDiagnosticCollection();
|
||||
@@ -158,24 +359,46 @@ namespace ts {
|
||||
let start = new Date().getTime();
|
||||
|
||||
host = host || createCompilerHost(options);
|
||||
|
||||
const resolveModuleNamesWorker =
|
||||
host.resolveModuleNames ||
|
||||
((moduleNames, containingFile) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedFileName));
|
||||
|
||||
let filesByName = createFileMap<SourceFile>(fileName => host.getCanonicalFileName(fileName));
|
||||
|
||||
forEach(rootNames, name => processRootFile(name, /*isDefaultLib:*/ false));
|
||||
|
||||
// Do not process the default library if:
|
||||
// - The '--noLib' flag is used.
|
||||
// - A 'no-default-lib' reference comment is encountered in
|
||||
// processing the root files.
|
||||
if (!skipDefaultLib) {
|
||||
processRootFile(host.getDefaultLibFileName(options), /*isDefaultLib:*/ true);
|
||||
|
||||
if (oldProgram) {
|
||||
// check properties that can affect structure of the program or module resolution strategy
|
||||
// if any of these properties has changed - structure cannot be reused
|
||||
let oldOptions = oldProgram.getCompilerOptions();
|
||||
if ((oldOptions.module !== options.module) ||
|
||||
(oldOptions.noResolve !== options.noResolve) ||
|
||||
(oldOptions.target !== options.target) ||
|
||||
(oldOptions.noLib !== options.noLib) ||
|
||||
(oldOptions.jsx !== options.jsx)) {
|
||||
oldProgram = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tryReuseStructureFromOldProgram()) {
|
||||
forEach(rootNames, name => processRootFile(name, false));
|
||||
// Do not process the default library if:
|
||||
// - The '--noLib' flag is used.
|
||||
// - A 'no-default-lib' reference comment is encountered in
|
||||
// processing the root files.
|
||||
if (!skipDefaultLib) {
|
||||
processRootFile(host.getDefaultLibFileName(options), true);
|
||||
}
|
||||
}
|
||||
|
||||
verifyCompilerOptions();
|
||||
|
||||
// unconditionally set oldProgram to undefined to prevent it from being captured in closure
|
||||
oldProgram = undefined;
|
||||
|
||||
programTime += new Date().getTime() - start;
|
||||
|
||||
program = {
|
||||
getRootFileNames: () => rootNames,
|
||||
getSourceFile: getSourceFile,
|
||||
getSourceFiles: () => files,
|
||||
getCompilerOptions: () => options,
|
||||
@@ -211,6 +434,82 @@ namespace ts {
|
||||
return classifiableNames;
|
||||
}
|
||||
|
||||
function tryReuseStructureFromOldProgram(): boolean {
|
||||
if (!oldProgram) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Debug.assert(!oldProgram.structureIsReused);
|
||||
|
||||
// there is an old program, check if we can reuse its structure
|
||||
let oldRootNames = oldProgram.getRootFileNames();
|
||||
if (!arrayIsEqualTo(oldRootNames, rootNames)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if program source files has changed in the way that can affect structure of the program
|
||||
let newSourceFiles: SourceFile[] = [];
|
||||
for (let oldSourceFile of oldProgram.getSourceFiles()) {
|
||||
let newSourceFile = host.getSourceFile(oldSourceFile.fileName, options.target);
|
||||
if (!newSourceFile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (oldSourceFile !== newSourceFile) {
|
||||
if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
|
||||
// value of no-default-lib has changed
|
||||
// this will affect if default library is injected into the list of files
|
||||
return false;
|
||||
}
|
||||
|
||||
// check tripleslash references
|
||||
if (!arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
|
||||
// tripleslash references has changed
|
||||
return false;
|
||||
}
|
||||
|
||||
// check imports
|
||||
collectExternalModuleReferences(newSourceFile);
|
||||
if (!arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
|
||||
// imports has changed
|
||||
return false;
|
||||
}
|
||||
|
||||
if (resolveModuleNamesWorker) {
|
||||
let moduleNames = map(newSourceFile.imports, name => name.text);
|
||||
let resolutions = resolveModuleNamesWorker(moduleNames, newSourceFile.fileName);
|
||||
// ensure that module resolution results are still correct
|
||||
for (let i = 0; i < moduleNames.length; ++i) {
|
||||
let oldResolution = getResolvedModuleFileName(oldSourceFile, moduleNames[i]);
|
||||
if (oldResolution !== resolutions[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// pass the cache of module resolutions from the old source file
|
||||
newSourceFile.resolvedModules = oldSourceFile.resolvedModules;
|
||||
}
|
||||
else {
|
||||
// file has no changes - use it as is
|
||||
newSourceFile = oldSourceFile;
|
||||
}
|
||||
|
||||
// if file has passed all checks it should be safe to reuse it
|
||||
newSourceFiles.push(newSourceFile);
|
||||
}
|
||||
|
||||
// update fileName -> file mapping
|
||||
for (let file of newSourceFiles) {
|
||||
filesByName.set(file.fileName, file);
|
||||
}
|
||||
|
||||
files = newSourceFiles;
|
||||
|
||||
oldProgram.structureIsReused = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
|
||||
return {
|
||||
getCanonicalFileName: fileName => host.getCanonicalFileName(fileName),
|
||||
@@ -253,7 +552,7 @@ namespace ts {
|
||||
// This is because in the -out scenario all files need to be emitted, and therefore all
|
||||
// files need to be type checked. And the way to specify that all files need to be type
|
||||
// checked is to not pass the file to getEmitResolver.
|
||||
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(options.out ? undefined : sourceFile);
|
||||
let emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out)? undefined : sourceFile);
|
||||
|
||||
let start = new Date().getTime();
|
||||
|
||||
@@ -370,16 +669,66 @@ namespace ts {
|
||||
|
||||
function processRootFile(fileName: string, isDefaultLib: boolean) {
|
||||
processSourceFile(normalizePath(fileName), isDefaultLib);
|
||||
}
|
||||
|
||||
function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean {
|
||||
return a.fileName === b.fileName;
|
||||
}
|
||||
|
||||
function moduleNameIsEqualTo(a: LiteralExpression, b: LiteralExpression): boolean {
|
||||
return a.text === b.text;
|
||||
}
|
||||
|
||||
function collectExternalModuleReferences(file: SourceFile): void {
|
||||
if (file.imports) {
|
||||
return;
|
||||
}
|
||||
|
||||
let imports: LiteralExpression[];
|
||||
for (let node of file.statements) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
let moduleNameExpr = getExternalModuleName(node);
|
||||
if (!moduleNameExpr || moduleNameExpr.kind !== SyntaxKind.StringLiteral) {
|
||||
break;
|
||||
}
|
||||
if (!(<LiteralExpression>moduleNameExpr).text) {
|
||||
break;
|
||||
}
|
||||
|
||||
(imports || (imports = [])).push(<LiteralExpression>moduleNameExpr);
|
||||
break;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
if ((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) {
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An AmbientExternalModuleDeclaration declares an external module.
|
||||
// This type of declaration is permitted only in the global module.
|
||||
// The StringLiteral must specify a top - level external module name.
|
||||
// Relative external module names are not permitted
|
||||
forEachChild((<ModuleDeclaration>node).body, node => {
|
||||
if (isExternalModuleImportEqualsDeclaration(node) &&
|
||||
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
|
||||
let moduleName = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
|
||||
// only through top - level external module names. Relative external module names are not permitted.
|
||||
if (moduleName) {
|
||||
(imports || (imports = [])).push(moduleName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
file.imports = imports || emptyArray;
|
||||
}
|
||||
|
||||
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
let start: number;
|
||||
let length: number;
|
||||
let diagnosticArgument: string[];
|
||||
if (refEnd !== undefined && refPos !== undefined) {
|
||||
start = refPos;
|
||||
length = refEnd - refPos;
|
||||
}
|
||||
let diagnostic: DiagnosticMessage;
|
||||
if (hasExtension(fileName)) {
|
||||
if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) {
|
||||
@@ -411,8 +760,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (diagnostic) {
|
||||
if (refFile) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, start, length, diagnostic, ...diagnosticArgument));
|
||||
if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...diagnosticArgument));
|
||||
}
|
||||
else {
|
||||
diagnostics.add(createCompilerDiagnostic(diagnostic, ...diagnosticArgument));
|
||||
@@ -421,7 +770,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Get source file from normalized fileName
|
||||
function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refStart?: number, refLength?: number): SourceFile {
|
||||
function findSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
|
||||
let canonicalName = host.getCanonicalFileName(normalizeSlashes(fileName));
|
||||
if (filesByName.contains(canonicalName)) {
|
||||
// We've already looked for this file, use cached result
|
||||
@@ -436,8 +785,8 @@ namespace ts {
|
||||
|
||||
// We haven't looked for this file, do so now and cache result
|
||||
let file = host.getSourceFile(fileName, options.target, hostErrorMessage => {
|
||||
if (refFile) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
|
||||
if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos,
|
||||
Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage));
|
||||
}
|
||||
else {
|
||||
@@ -450,12 +799,15 @@ namespace ts {
|
||||
|
||||
// Set the source file for normalized absolute path
|
||||
filesByName.set(canonicalAbsolutePath, file);
|
||||
|
||||
|
||||
let basePath = getDirectoryPath(fileName);
|
||||
if (!options.noResolve) {
|
||||
let basePath = getDirectoryPath(fileName);
|
||||
processReferencedFiles(file, basePath);
|
||||
processImportedModules(file, basePath);
|
||||
}
|
||||
|
||||
// always process imported modules to record module name resolutions
|
||||
processImportedModules(file, basePath);
|
||||
|
||||
if (isDefaultLib) {
|
||||
file.isDefaultLib = true;
|
||||
files.unshift(file);
|
||||
@@ -473,8 +825,13 @@ namespace ts {
|
||||
if (file && host.useCaseSensitiveFileNames()) {
|
||||
let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName;
|
||||
if (canonicalName !== sourceFileName) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refStart, refLength,
|
||||
Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
|
||||
if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) {
|
||||
diagnostics.add(createFileDiagnostic(refFile, refPos, refEnd - refPos,
|
||||
Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
|
||||
}
|
||||
else {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, fileName, sourceFileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return file;
|
||||
@@ -483,60 +840,33 @@ namespace ts {
|
||||
|
||||
function processReferencedFiles(file: SourceFile, basePath: string) {
|
||||
forEach(file.referencedFiles, ref => {
|
||||
let referencedFileName = isRootedDiskPath(ref.fileName) ? ref.fileName : combinePaths(basePath, ref.fileName);
|
||||
processSourceFile(normalizePath(referencedFileName), /* isDefaultLib */ false, file, ref.pos, ref.end);
|
||||
let referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
|
||||
processSourceFile(referencedFileName, /* isDefaultLib */ false, file, ref.pos, ref.end);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function processImportedModules(file: SourceFile, basePath: string) {
|
||||
forEach(file.statements, node => {
|
||||
if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration) {
|
||||
let moduleNameExpr = getExternalModuleName(node);
|
||||
if (moduleNameExpr && moduleNameExpr.kind === SyntaxKind.StringLiteral) {
|
||||
let moduleNameText = (<LiteralExpression>moduleNameExpr).text;
|
||||
if (moduleNameText) {
|
||||
let searchPath = basePath;
|
||||
let searchName: string;
|
||||
while (true) {
|
||||
searchName = normalizePath(combinePaths(searchPath, moduleNameText));
|
||||
if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) {
|
||||
break;
|
||||
}
|
||||
let parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
searchPath = parentPath;
|
||||
}
|
||||
}
|
||||
collectExternalModuleReferences(file);
|
||||
if (file.imports.length) {
|
||||
file.resolvedModules = {};
|
||||
let moduleNames = map(file.imports, name => name.text);
|
||||
let resolutions = resolveModuleNamesWorker(moduleNames, file.fileName);
|
||||
for (let i = 0; i < file.imports.length; ++i) {
|
||||
let resolution = resolutions[i];
|
||||
setResolvedModuleName(file, moduleNames[i], resolution);
|
||||
if (resolution && !options.noResolve) {
|
||||
findModuleSourceFile(resolution, file.imports[i]);
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) {
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An AmbientExternalModuleDeclaration declares an external module.
|
||||
// This type of declaration is permitted only in the global module.
|
||||
// The StringLiteral must specify a top - level external module name.
|
||||
// Relative external module names are not permitted
|
||||
forEachChild((<ModuleDeclaration>node).body, node => {
|
||||
if (isExternalModuleImportEqualsDeclaration(node) &&
|
||||
getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) {
|
||||
|
||||
let nameLiteral = <LiteralExpression>getExternalModuleImportEqualsDeclarationExpression(node);
|
||||
let moduleName = nameLiteral.text;
|
||||
if (moduleName) {
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
|
||||
// only through top - level external module names. Relative external module names are not permitted.
|
||||
let searchName = normalizePath(combinePaths(basePath, moduleName));
|
||||
forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, nameLiteral));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// no imports - drop cached module resolutions
|
||||
file.resolvedModules = undefined;
|
||||
}
|
||||
return;
|
||||
|
||||
function findModuleSourceFile(fileName: string, nameLiteral: Expression) {
|
||||
return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos);
|
||||
return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -603,27 +933,31 @@ namespace ts {
|
||||
function verifyCompilerOptions() {
|
||||
if (options.isolatedModules) {
|
||||
if (options.declaration) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declaration", "isolatedModules"));
|
||||
}
|
||||
|
||||
if (options.noEmitOnError) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmitOnError", "isolatedModules"));
|
||||
}
|
||||
|
||||
if (options.out) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "isolatedModules"));
|
||||
}
|
||||
|
||||
if (options.outFile) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", "isolatedModules"));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.inlineSourceMap) {
|
||||
if (options.sourceMap) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceMap", "inlineSourceMap"));
|
||||
}
|
||||
if (options.mapRoot) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap"));
|
||||
}
|
||||
if (options.sourceRoot) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "sourceRoot", "inlineSourceMap"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -634,18 +968,23 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.out && options.outFile) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile"));
|
||||
}
|
||||
|
||||
if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) {
|
||||
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
|
||||
if (options.mapRoot) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_without_specifying_sourceMap_option));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "mapRoot", "sourceMap"));
|
||||
}
|
||||
if (options.sourceRoot) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_without_specifying_sourceMap_option));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "sourceRoot", "sourceMap"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let languageVersion = options.target || ScriptTarget.ES3;
|
||||
let outFile = options.outFile || options.out;
|
||||
|
||||
let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined);
|
||||
if (options.isolatedModules) {
|
||||
@@ -675,7 +1014,7 @@ namespace ts {
|
||||
if (options.outDir || // there is --outDir specified
|
||||
options.sourceRoot || // there is --sourceRoot specified
|
||||
(options.mapRoot && // there is --mapRoot specified and there would be multiple js files generated
|
||||
(!options.out || firstExternalModuleSourceFile !== undefined))) {
|
||||
(!outFile || firstExternalModuleSourceFile !== undefined))) {
|
||||
|
||||
if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) {
|
||||
// If a rootDir is specified and is valid use it as the commonSourceDirectory
|
||||
@@ -695,18 +1034,26 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (options.noEmit) {
|
||||
if (options.out || options.outDir) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
|
||||
if (options.out) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "out"));
|
||||
}
|
||||
|
||||
if (options.outFile) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outFile"));
|
||||
}
|
||||
|
||||
if (options.outDir) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "outDir"));
|
||||
}
|
||||
|
||||
if (options.declaration) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", "declaration"));
|
||||
}
|
||||
}
|
||||
|
||||
if (options.emitDecoratorMetadata &&
|
||||
!options.experimentalDecorators) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
|
||||
}
|
||||
|
||||
if (options.experimentalAsyncFunctions &&
|
||||
|
||||
@@ -472,7 +472,7 @@ namespace ts {
|
||||
break;
|
||||
|
||||
case CharacterCodes.hash:
|
||||
if (isShebangTrivia(text, pos)) {
|
||||
if (pos === 0 && isShebangTrivia(text, pos)) {
|
||||
pos = scanShebangTrivia(text, pos);
|
||||
continue;
|
||||
}
|
||||
@@ -672,7 +672,6 @@ namespace ts {
|
||||
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
// Creates a scanner over a (possibly unspecified) range of a piece of text.
|
||||
export function createScanner(languageVersion: ScriptTarget,
|
||||
skipTrivia: boolean,
|
||||
|
||||
+3
-1
@@ -334,7 +334,9 @@ namespace ts {
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
|
||||
return getWScriptSystem();
|
||||
}
|
||||
else if (typeof module !== "undefined" && module.exports) {
|
||||
else if (typeof process !== "undefined" && process.nextTick && !process.browser && typeof require !== "undefined") {
|
||||
// process and process.nextTick checks if current environment is node-like
|
||||
// process.browser check excludes webpack and browserify
|
||||
return getNodeSystem();
|
||||
}
|
||||
else {
|
||||
|
||||
+53
-4
@@ -9,6 +9,7 @@ namespace ts {
|
||||
contains(fileName: string): boolean;
|
||||
remove(fileName: string): void;
|
||||
forEachValue(f: (v: T) => void): void;
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
export interface TextRange {
|
||||
@@ -1243,6 +1244,10 @@ namespace ts {
|
||||
moduleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
languageVariant: LanguageVariant;
|
||||
|
||||
// this map is used by transpiler to supply alternative names for dependencies (i.e. in case of bundling)
|
||||
/* @internal */
|
||||
renamedDependencies?: Map<string>;
|
||||
|
||||
/**
|
||||
* lib.d.ts should have a reference comment like
|
||||
@@ -1275,8 +1280,12 @@ namespace ts {
|
||||
// Stores a line map for the file.
|
||||
// This field should never be used directly to obtain line map, use getLineMap function instead.
|
||||
/* @internal */ lineMap: number[];
|
||||
|
||||
/* @internal */ classifiableNames?: Map<string>;
|
||||
// Stores a mapping 'external module reference text' -> 'resolved file name' | undefined
|
||||
// It is used to resolve module names in the checker.
|
||||
// Content of this fiels should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead
|
||||
/* @internal */ resolvedModules: Map<string>;
|
||||
/* @internal */ imports: LiteralExpression[];
|
||||
}
|
||||
|
||||
export interface ScriptReferenceHost {
|
||||
@@ -1285,7 +1294,7 @@ namespace ts {
|
||||
getCurrentDirectory(): string;
|
||||
}
|
||||
|
||||
export interface ParseConfigHost {
|
||||
export interface ParseConfigHost extends ModuleResolutionHost {
|
||||
readDirectory(rootDir: string, extension: string, exclude: string[]): string[];
|
||||
}
|
||||
|
||||
@@ -1303,6 +1312,12 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface Program extends ScriptReferenceHost {
|
||||
|
||||
/**
|
||||
* Get a list of root file names that were passed to a 'createProgram'
|
||||
*/
|
||||
getRootFileNames(): string[]
|
||||
|
||||
/**
|
||||
* Get a list of files in the program
|
||||
*/
|
||||
@@ -1343,6 +1358,9 @@ namespace ts {
|
||||
/* @internal */ getIdentifierCount(): number;
|
||||
/* @internal */ getSymbolCount(): number;
|
||||
/* @internal */ getTypeCount(): number;
|
||||
|
||||
// For testing purposes only.
|
||||
/* @internal */ structureIsReused?: boolean;
|
||||
}
|
||||
|
||||
export interface SourceMapSpan {
|
||||
@@ -1393,6 +1411,7 @@ namespace ts {
|
||||
/* @internal */ sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export interface TypeCheckerHost {
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
|
||||
@@ -1990,7 +2009,12 @@ namespace ts {
|
||||
Error,
|
||||
Message,
|
||||
}
|
||||
|
||||
|
||||
export const enum ModuleResolutionKind {
|
||||
Classic = 1,
|
||||
NodeJs = 2
|
||||
}
|
||||
|
||||
export interface CompilerOptions {
|
||||
allowNonTsExtensions?: boolean;
|
||||
charset?: string;
|
||||
@@ -2014,6 +2038,7 @@ namespace ts {
|
||||
noLib?: boolean;
|
||||
noResolve?: boolean;
|
||||
out?: string;
|
||||
outFile?: string;
|
||||
outDir?: string;
|
||||
preserveConstEnums?: boolean;
|
||||
project?: string;
|
||||
@@ -2029,6 +2054,7 @@ namespace ts {
|
||||
experimentalDecorators?: boolean;
|
||||
experimentalAsyncFunctions?: boolean;
|
||||
emitDecoratorMetadata?: boolean;
|
||||
moduleResolution?: ModuleResolutionKind
|
||||
/* @internal */ stripInternal?: boolean;
|
||||
|
||||
// Skip checking lib.d.ts to help speed up tests.
|
||||
@@ -2229,9 +2255,23 @@ namespace ts {
|
||||
byteOrderMark = 0xFEFF,
|
||||
tab = 0x09, // \t
|
||||
verticalTab = 0x0B, // \v
|
||||
}
|
||||
|
||||
export interface ModuleResolutionHost {
|
||||
fileExists(fileName: string): boolean;
|
||||
// readFile function is used to read arbitrary text files on disk, i.e. when resolution procedure needs the content of 'package.json'
|
||||
// to determine location of bundled typings for node module
|
||||
readFile(fileName: string): string;
|
||||
}
|
||||
|
||||
export interface ResolvedModule {
|
||||
resolvedFileName: string;
|
||||
failedLookupLocations: string[];
|
||||
}
|
||||
|
||||
export type ModuleNameResolver = (moduleName: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => ResolvedModule;
|
||||
|
||||
export interface CompilerHost {
|
||||
export interface CompilerHost extends ModuleResolutionHost {
|
||||
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;
|
||||
getCancellationToken?(): CancellationToken;
|
||||
getDefaultLibFileName(options: CompilerOptions): string;
|
||||
@@ -2240,6 +2280,15 @@ namespace ts {
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getNewLine(): string;
|
||||
|
||||
/*
|
||||
* CompilerHost must either implement resolveModuleNames (in case if it wants to be completely in charge of
|
||||
* module name resolution) or provide implementation for methods from ModuleResolutionHost (in this case compiler
|
||||
* will appply built-in module resolution logic and use members of ModuleResolutionHost to ask host specific questions).
|
||||
* If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just
|
||||
* 'throw new Error("NotImplemented")'
|
||||
*/
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string): string[];
|
||||
}
|
||||
|
||||
export interface TextSpan {
|
||||
|
||||
@@ -80,6 +80,41 @@ namespace ts {
|
||||
return node.end - node.pos;
|
||||
}
|
||||
|
||||
export function arrayIsEqualTo<T>(arr1: T[], arr2: T[], comparer?: (a: T, b: T) => boolean): boolean {
|
||||
if (!arr1 || !arr2) {
|
||||
return arr1 === arr2;
|
||||
}
|
||||
|
||||
if (arr1.length !== arr2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < arr1.length; ++i) {
|
||||
let equals = comparer ? comparer(arr1[i], arr2[i]) : arr1[i] === arr2[i];
|
||||
if (!equals) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function hasResolvedModuleName(sourceFile: SourceFile, moduleNameText: string): boolean {
|
||||
return sourceFile.resolvedModules && hasProperty(sourceFile.resolvedModules, moduleNameText);
|
||||
}
|
||||
|
||||
export function getResolvedModuleFileName(sourceFile: SourceFile, moduleNameText: string): string {
|
||||
return hasResolvedModuleName(sourceFile, moduleNameText) ? sourceFile.resolvedModules[moduleNameText] : undefined;
|
||||
}
|
||||
|
||||
export function setResolvedModuleName(sourceFile: SourceFile, moduleNameText: string, resolvedFileName: string): void {
|
||||
if (!sourceFile.resolvedModules) {
|
||||
sourceFile.resolvedModules = {};
|
||||
}
|
||||
|
||||
sourceFile.resolvedModules[moduleNameText] = resolvedFileName;
|
||||
}
|
||||
|
||||
// Returns true if this node contains a parse error anywhere underneath it.
|
||||
export function containsParseError(node: Node): boolean {
|
||||
aggregateChildData(node);
|
||||
@@ -205,7 +240,7 @@ namespace ts {
|
||||
// Make an identifier from an external module name by extracting the string after the last "/" and replacing
|
||||
// all non-alphanumeric characters with underscores
|
||||
export function makeIdentifierFromModuleName(moduleName: string): string {
|
||||
return getBaseFileName(moduleName).replace(/\W/g, "_");
|
||||
return getBaseFileName(moduleName).replace(/^(\d)/, "_$1").replace(/\W/g, "_");
|
||||
}
|
||||
|
||||
export function isBlockOrCatchScoped(declaration: Declaration) {
|
||||
@@ -385,7 +420,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function getJsDocComments(node: Node, sourceFileOfNode: SourceFile) {
|
||||
let commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter) ?␍ concatenate(getTrailingCommentRanges(sourceFileOfNode.text, node.pos),␍ getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) :␍ getLeadingCommentRangesOfNode(node, sourceFileOfNode);
|
||||
let commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter) ?
|
||||
concatenate(getTrailingCommentRanges(sourceFileOfNode.text, node.pos),
|
||||
getLeadingCommentRanges(sourceFileOfNode.text, node.pos)) :
|
||||
getLeadingCommentRangesOfNode(node, sourceFileOfNode);
|
||||
return filter(commentRanges, isJsDocComment);
|
||||
|
||||
function isJsDocComment(comment: CommentRange) {
|
||||
@@ -604,6 +642,20 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function introducesArgumentsExoticObject(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isFunctionBlock(node: Node) {
|
||||
return node && node.kind === SyntaxKind.Block && isFunctionLike(node.parent);
|
||||
}
|
||||
@@ -927,6 +979,7 @@ namespace ts {
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return node === (<ComputedPropertyName>parent).expression;
|
||||
case SyntaxKind.Decorator:
|
||||
case SyntaxKind.JsxExpression:
|
||||
return true;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return (<ExpressionWithTypeArguments>parent).expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent);
|
||||
@@ -1715,7 +1768,7 @@ namespace ts {
|
||||
|
||||
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
|
||||
if (!isDeclarationFile(sourceFile)) {
|
||||
if ((isExternalModule(sourceFile) || !compilerOptions.out)) {
|
||||
if ((isExternalModule(sourceFile) || !(compilerOptions.outFile || compilerOptions.out))) {
|
||||
// 1. in-browser single file compilation scenario
|
||||
// 2. non .js file
|
||||
return compilerOptions.isolatedModules || !fileExtensionIs(sourceFile.fileName, ".js");
|
||||
|
||||
+40
-18
@@ -123,18 +123,20 @@ module FourSlash {
|
||||
mapRoot: "mapRoot",
|
||||
module: "module",
|
||||
out: "out",
|
||||
outFile: "outFile",
|
||||
outDir: "outDir",
|
||||
sourceMap: "sourceMap",
|
||||
sourceRoot: "sourceRoot",
|
||||
allowNonTsExtensions: "allowNonTsExtensions",
|
||||
resolveReference: "ResolveReference", // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file
|
||||
jsx: "jsx",
|
||||
};
|
||||
|
||||
// List of allowed metadata names
|
||||
let fileMetadataNames = [metadataOptionNames.fileName, metadataOptionNames.emitThisFile, metadataOptionNames.resolveReference];
|
||||
let globalMetadataNames = [metadataOptionNames.allowNonTsExtensions, metadataOptionNames.baselineFile, metadataOptionNames.declaration,
|
||||
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out,
|
||||
metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot];
|
||||
metadataOptionNames.mapRoot, metadataOptionNames.module, metadataOptionNames.out,metadataOptionNames.outFile,
|
||||
metadataOptionNames.outDir, metadataOptionNames.sourceMap, metadataOptionNames.sourceRoot, metadataOptionNames.jsx];
|
||||
|
||||
function convertGlobalOptionsToCompilerOptions(globalOptions: { [idx: string]: string }): ts.CompilerOptions {
|
||||
let settings: ts.CompilerOptions = { target: ts.ScriptTarget.ES5 };
|
||||
@@ -169,6 +171,9 @@ module FourSlash {
|
||||
case metadataOptionNames.out:
|
||||
settings.out = globalOptions[prop];
|
||||
break;
|
||||
case metadataOptionNames.outFile:
|
||||
settings.outFile = globalOptions[prop];
|
||||
break;
|
||||
case metadataOptionNames.outDir:
|
||||
settings.outDir = globalOptions[prop];
|
||||
break;
|
||||
@@ -178,6 +183,20 @@ module FourSlash {
|
||||
case metadataOptionNames.sourceRoot:
|
||||
settings.sourceRoot = globalOptions[prop];
|
||||
break;
|
||||
case metadataOptionNames.jsx:
|
||||
switch (globalOptions[prop].toLowerCase()) {
|
||||
case "react":
|
||||
settings.jsx = ts.JsxEmit.React;
|
||||
break;
|
||||
case "preserve":
|
||||
settings.jsx = ts.JsxEmit.Preserve;
|
||||
break;
|
||||
default:
|
||||
ts.Debug.assert(globalOptions[prop] === undefined || globalOptions[prop] === "None");
|
||||
settings.jsx = ts.JsxEmit.None;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,7 +304,9 @@ module FourSlash {
|
||||
case FourSlashTestType.Native:
|
||||
return new Harness.LanguageService.NativeLanugageServiceAdapter(cancellationToken, compilationOptions);
|
||||
case FourSlashTestType.Shims:
|
||||
return new Harness.LanguageService.ShimLanugageServiceAdapter(cancellationToken, compilationOptions);
|
||||
return new Harness.LanguageService.ShimLanugageServiceAdapter(/*preprocessToResolve*/ false, cancellationToken, compilationOptions);
|
||||
case FourSlashTestType.ShimsWithPreprocess:
|
||||
return new Harness.LanguageService.ShimLanugageServiceAdapter(/*preprocessToResolve*/ true, cancellationToken, compilationOptions);
|
||||
case FourSlashTestType.Server:
|
||||
return new Harness.LanguageService.ServerLanugageServiceAdapter(cancellationToken, compilationOptions);
|
||||
default:
|
||||
@@ -356,7 +377,7 @@ module FourSlash {
|
||||
this.formatCodeOptions = {
|
||||
IndentSize: 4,
|
||||
TabSize: 4,
|
||||
NewLineCharacter: ts.sys.newLine,
|
||||
NewLineCharacter: Harness.IO.newLine(),
|
||||
ConvertTabsToSpaces: true,
|
||||
InsertSpaceAfterCommaDelimiter: true,
|
||||
InsertSpaceAfterSemicolonInForStatements: true,
|
||||
@@ -364,6 +385,7 @@ module FourSlash {
|
||||
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
PlaceOpenBraceOnNewLineForFunctions: false,
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
||||
};
|
||||
@@ -533,7 +555,7 @@ module FourSlash {
|
||||
errors.forEach(function (error: ts.Diagnostic) {
|
||||
Harness.IO.log(" minChar: " + error.start +
|
||||
", limChar: " + (error.start + error.length) +
|
||||
", message: " + ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine) + "\n");
|
||||
", message: " + ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine()) + "\n");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1244,21 +1266,21 @@ module FourSlash {
|
||||
emitFiles.forEach(emitFile => {
|
||||
let emitOutput = this.languageService.getEmitOutput(emitFile.fileName);
|
||||
// Print emitOutputStatus in readable format
|
||||
resultString += "EmitSkipped: " + emitOutput.emitSkipped + ts.sys.newLine;
|
||||
resultString += "EmitSkipped: " + emitOutput.emitSkipped + Harness.IO.newLine();
|
||||
|
||||
if (emitOutput.emitSkipped) {
|
||||
resultString += "Diagnostics:" + ts.sys.newLine;
|
||||
resultString += "Diagnostics:" + Harness.IO.newLine();
|
||||
let diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram());
|
||||
for (let i = 0, n = diagnostics.length; i < n; i++) {
|
||||
resultString += " " + diagnostics[0].messageText + ts.sys.newLine;
|
||||
resultString += " " + diagnostics[0].messageText + Harness.IO.newLine();
|
||||
}
|
||||
}
|
||||
|
||||
emitOutput.outputFiles.forEach((outputFile, idx, array) => {
|
||||
let fileName = "FileName : " + outputFile.name + ts.sys.newLine;
|
||||
let fileName = "FileName : " + outputFile.name + Harness.IO.newLine();
|
||||
resultString = resultString + fileName + outputFile.text;
|
||||
});
|
||||
resultString += ts.sys.newLine;
|
||||
resultString += Harness.IO.newLine();
|
||||
});
|
||||
|
||||
return resultString;
|
||||
@@ -1295,7 +1317,7 @@ module FourSlash {
|
||||
Harness.IO.log(
|
||||
"start: " + err.start +
|
||||
", length: " + err.length +
|
||||
", message: " + ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine));
|
||||
", message: " + ts.flattenDiagnosticMessageText(err.messageText, Harness.IO.newLine()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1869,9 +1891,9 @@ module FourSlash {
|
||||
}
|
||||
|
||||
function jsonMismatchString() {
|
||||
return ts.sys.newLine +
|
||||
"expected: '" + ts.sys.newLine + JSON.stringify(expected, (k, v) => v, 2) + "'" + ts.sys.newLine +
|
||||
"actual: '" + ts.sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'";
|
||||
return Harness.IO.newLine() +
|
||||
"expected: '" + Harness.IO.newLine() + JSON.stringify(expected, (k, v) => v, 2) + "'" + Harness.IO.newLine() +
|
||||
"actual: '" + Harness.IO.newLine() + JSON.stringify(actual, (k, v) => v, 2) + "'";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2380,7 +2402,7 @@ module FourSlash {
|
||||
let host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined }],
|
||||
(fn, contents) => fourslashJsOutput = contents,
|
||||
ts.ScriptTarget.Latest,
|
||||
ts.sys.useCaseSensitiveFileNames);
|
||||
Harness.IO.useCaseSensitiveFileNames());
|
||||
|
||||
let program = ts.createProgram([Harness.Compiler.fourslashFileName], { noResolve: true, target: ts.ScriptTarget.ES3 }, host);
|
||||
|
||||
@@ -2402,16 +2424,16 @@ module FourSlash {
|
||||
],
|
||||
(fn, contents) => result = contents,
|
||||
ts.ScriptTarget.Latest,
|
||||
ts.sys.useCaseSensitiveFileNames);
|
||||
Harness.IO.useCaseSensitiveFileNames());
|
||||
|
||||
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
|
||||
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { outFile: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
|
||||
|
||||
let sourceFile = host.getSourceFile(fileName, ts.ScriptTarget.ES3);
|
||||
|
||||
let diagnostics = ts.getPreEmitDiagnostics(program, sourceFile);
|
||||
if (diagnostics.length > 0) {
|
||||
throw new Error(`Error compiling ${fileName}: ` +
|
||||
diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join("\r\n"));
|
||||
diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, Harness.IO.newLine())).join("\r\n"));
|
||||
}
|
||||
|
||||
program.emit(sourceFile);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
const enum FourSlashTestType {
|
||||
Native,
|
||||
Shims,
|
||||
ShimsWithPreprocess,
|
||||
Server
|
||||
}
|
||||
|
||||
@@ -23,6 +24,10 @@ class FourSlashRunner extends RunnerBase {
|
||||
this.basePath = "tests/cases/fourslash/shims";
|
||||
this.testSuiteName = "fourslash-shims";
|
||||
break;
|
||||
case FourSlashTestType.ShimsWithPreprocess:
|
||||
this.basePath = 'tests/cases/fourslash/shims-pp';
|
||||
this.testSuiteName = 'fourslash-shims-pp';
|
||||
break;
|
||||
case FourSlashTestType.Server:
|
||||
this.basePath = "tests/cases/fourslash/server";
|
||||
this.testSuiteName = "fourslash-server";
|
||||
|
||||
+106
-57
@@ -26,7 +26,6 @@
|
||||
|
||||
// Block scoped definitions work poorly for global variables, temporarily enable var
|
||||
/* tslint:disable:no-var-keyword */
|
||||
var Buffer: BufferConstructor = require("buffer").Buffer;
|
||||
|
||||
// this will work in the browser via browserify
|
||||
var _chai: typeof chai = require("chai");
|
||||
@@ -55,9 +54,17 @@ module Utils {
|
||||
return ExecutionEnvironment.Node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export let currentExecutionEnvironment = getExecutionEnvironment();
|
||||
|
||||
const Buffer: BufferConstructor = currentExecutionEnvironment !== ExecutionEnvironment.Browser
|
||||
? require("buffer").Buffer
|
||||
: undefined;
|
||||
|
||||
export function encodeString(s: string): string {
|
||||
return Buffer ? (new Buffer(s)).toString("utf8") : s;
|
||||
}
|
||||
|
||||
export function evalFile(fileContents: string, fileName: string, nodeContext?: any) {
|
||||
let environment = getExecutionEnvironment();
|
||||
switch (environment) {
|
||||
@@ -102,7 +109,7 @@ module Utils {
|
||||
|
||||
let content: string = undefined;
|
||||
try {
|
||||
content = ts.sys.readFile(Harness.userSpecifiedRoot + path);
|
||||
content = Harness.IO.readFile(Harness.userSpecifiedRoot + path);
|
||||
}
|
||||
catch (err) {
|
||||
return undefined;
|
||||
@@ -190,7 +197,7 @@ module Utils {
|
||||
return {
|
||||
start: diagnostic.start,
|
||||
length: diagnostic.length,
|
||||
messageText: ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine),
|
||||
messageText: ts.flattenDiagnosticMessageText(diagnostic.messageText, Harness.IO.newLine()),
|
||||
category: (<any>ts).DiagnosticCategory[diagnostic.category],
|
||||
code: diagnostic.code
|
||||
};
|
||||
@@ -323,8 +330,8 @@ module Utils {
|
||||
assert.equal(d1.start, d2.start, "d1.start !== d2.start");
|
||||
assert.equal(d1.length, d2.length, "d1.length !== d2.length");
|
||||
assert.equal(
|
||||
ts.flattenDiagnosticMessageText(d1.messageText, ts.sys.newLine),
|
||||
ts.flattenDiagnosticMessageText(d2.messageText, ts.sys.newLine), "d1.messageText !== d2.messageText");
|
||||
ts.flattenDiagnosticMessageText(d1.messageText, Harness.IO.newLine()),
|
||||
ts.flattenDiagnosticMessageText(d2.messageText, Harness.IO.newLine()), "d1.messageText !== d2.messageText");
|
||||
assert.equal(d1.category, d2.category, "d1.category !== d2.category");
|
||||
assert.equal(d1.code, d2.code, "d1.code !== d2.code");
|
||||
}
|
||||
@@ -404,6 +411,10 @@ module Harness.Path {
|
||||
|
||||
module Harness {
|
||||
export interface IO {
|
||||
newLine(): string;
|
||||
getCurrentDirectory(): string;
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
resolvePath(path: string): string;
|
||||
readFile(path: string): string;
|
||||
writeFile(path: string, contents: string): void;
|
||||
directoryName(path: string): string;
|
||||
@@ -416,7 +427,10 @@ module Harness {
|
||||
getMemoryUsage?(): number;
|
||||
}
|
||||
export var IO: IO;
|
||||
|
||||
|
||||
// harness always uses one kind of new line
|
||||
const harnessNewLine = "\r\n";
|
||||
|
||||
module IOImpl {
|
||||
declare class Enumerator {
|
||||
public atEnd(): boolean;
|
||||
@@ -433,12 +447,17 @@ module Harness {
|
||||
fso = {};
|
||||
}
|
||||
|
||||
export let readFile: typeof IO.readFile = ts.sys.readFile;
|
||||
export let writeFile: typeof IO.writeFile = ts.sys.writeFile;
|
||||
export let directoryName: typeof IO.directoryName = fso.GetParentFolderName;
|
||||
export let directoryExists: typeof IO.directoryExists = fso.FolderExists;
|
||||
export let fileExists: typeof IO.fileExists = fso.FileExists;
|
||||
export let log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine;
|
||||
export const resolvePath = (path: string) => ts.sys.resolvePath(path);
|
||||
export const getCurrentDirectory = () => ts.sys.getCurrentDirectory();
|
||||
export const newLine = () => harnessNewLine;
|
||||
export const useCaseSensitiveFileNames = () => ts.sys.useCaseSensitiveFileNames;
|
||||
|
||||
export const readFile: typeof IO.readFile = path => ts.sys.readFile(path);
|
||||
export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content);
|
||||
export const directoryName: typeof IO.directoryName = fso.GetParentFolderName;
|
||||
export const directoryExists: typeof IO.directoryExists = fso.FolderExists;
|
||||
export const fileExists: typeof IO.fileExists = fso.FileExists;
|
||||
export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine;
|
||||
|
||||
export function createDirectory(path: string) {
|
||||
if (directoryExists(path)) {
|
||||
@@ -493,11 +512,16 @@ module Harness {
|
||||
} else {
|
||||
fs = pathModule = {};
|
||||
}
|
||||
|
||||
export const resolvePath = (path: string) => ts.sys.resolvePath(path);
|
||||
export const getCurrentDirectory = () => ts.sys.getCurrentDirectory();
|
||||
export const newLine = () => harnessNewLine;
|
||||
export const useCaseSensitiveFileNames = () => ts.sys.useCaseSensitiveFileNames;
|
||||
|
||||
export let readFile: typeof IO.readFile = ts.sys.readFile;
|
||||
export let writeFile: typeof IO.writeFile = ts.sys.writeFile;
|
||||
export let fileExists: typeof IO.fileExists = fs.existsSync;
|
||||
export let log: typeof IO.log = s => console.log(s);
|
||||
export const readFile: typeof IO.readFile = path => ts.sys.readFile(path);
|
||||
export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content);
|
||||
export const fileExists: typeof IO.fileExists = fs.existsSync;
|
||||
export const log: typeof IO.log = s => console.log(s);
|
||||
|
||||
export function createDirectory(path: string) {
|
||||
if (!directoryExists(path)) {
|
||||
@@ -562,9 +586,9 @@ module Harness {
|
||||
export module Network {
|
||||
let serverRoot = "http://localhost:8888/";
|
||||
|
||||
// Unused?
|
||||
let newLine = "\r\n";
|
||||
let currentDirectory = () => "";
|
||||
export const newLine = () => harnessNewLine;
|
||||
export const useCaseSensitiveFileNames = () => false;
|
||||
export const getCurrentDirectory = () => "";
|
||||
let supportsCodePage = () => false;
|
||||
|
||||
module Http {
|
||||
@@ -616,6 +640,7 @@ module Harness {
|
||||
xhr.send(contents);
|
||||
}
|
||||
catch (e) {
|
||||
log(`XHR Error: ${e}`);
|
||||
return { status: 500, responseText: null };
|
||||
}
|
||||
|
||||
@@ -655,6 +680,7 @@ module Harness {
|
||||
return dirPath;
|
||||
}
|
||||
export let directoryName: typeof IO.directoryName = Utils.memoize(directoryNameImpl);
|
||||
export const resolvePath = (path: string) => directoryName(path);
|
||||
|
||||
export function fileExists(path: string): boolean {
|
||||
let response = Http.getFileFromServerSync(serverRoot + path);
|
||||
@@ -840,7 +866,7 @@ module Harness {
|
||||
export let fourslashSourceFile: ts.SourceFile;
|
||||
|
||||
export function getCanonicalFileName(fileName: string): string {
|
||||
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
return Harness.IO.useCaseSensitiveFileNames() ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
export function createCompilerHost(
|
||||
@@ -858,7 +884,7 @@ module Harness {
|
||||
}
|
||||
|
||||
let filemap: { [fileName: string]: ts.SourceFile; } = {};
|
||||
let getCurrentDirectory = currentDirectory === undefined ? ts.sys.getCurrentDirectory : () => currentDirectory;
|
||||
let getCurrentDirectory = currentDirectory === undefined ? Harness.IO.getCurrentDirectory : () => currentDirectory;
|
||||
|
||||
// Register input files
|
||||
function register(file: { unitName: string; content: string; }) {
|
||||
@@ -868,41 +894,45 @@ module Harness {
|
||||
}
|
||||
};
|
||||
inputFiles.forEach(register);
|
||||
|
||||
function getSourceFile(fn: string, languageVersion: ts.ScriptTarget) {
|
||||
fn = ts.normalizePath(fn);
|
||||
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
|
||||
return filemap[getCanonicalFileName(fn)];
|
||||
}
|
||||
else if (currentDirectory) {
|
||||
let canonicalAbsolutePath = getCanonicalFileName(ts.getNormalizedAbsolutePath(fn, currentDirectory));
|
||||
return Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(canonicalAbsolutePath)) ? filemap[canonicalAbsolutePath] : undefined;
|
||||
}
|
||||
else if (fn === fourslashFileName) {
|
||||
let tsFn = "tests/cases/fourslash/" + fourslashFileName;
|
||||
fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget);
|
||||
return fourslashSourceFile;
|
||||
}
|
||||
else {
|
||||
if (fn === defaultLibFileName) {
|
||||
return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile;
|
||||
}
|
||||
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
let newLine =
|
||||
newLineKind === ts.NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed :
|
||||
newLineKind === ts.NewLineKind.LineFeed ? lineFeed :
|
||||
ts.sys.newLine;
|
||||
Harness.IO.newLine();
|
||||
|
||||
return {
|
||||
getCurrentDirectory,
|
||||
getSourceFile: (fn, languageVersion) => {
|
||||
fn = ts.normalizePath(fn);
|
||||
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
|
||||
return filemap[getCanonicalFileName(fn)];
|
||||
}
|
||||
else if (currentDirectory) {
|
||||
let canonicalAbsolutePath = getCanonicalFileName(ts.getNormalizedAbsolutePath(fn, currentDirectory));
|
||||
return Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(canonicalAbsolutePath)) ? filemap[canonicalAbsolutePath] : undefined;
|
||||
}
|
||||
else if (fn === fourslashFileName) {
|
||||
let tsFn = "tests/cases/fourslash/" + fourslashFileName;
|
||||
fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants(tsFn, Harness.IO.readFile(tsFn), scriptTarget);
|
||||
return fourslashSourceFile;
|
||||
}
|
||||
else {
|
||||
if (fn === defaultLibFileName) {
|
||||
return languageVersion === ts.ScriptTarget.ES6 ? defaultES6LibSourceFile : defaultLibSourceFile;
|
||||
}
|
||||
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
getSourceFile,
|
||||
getDefaultLibFileName: options => defaultLibFileName,
|
||||
writeFile,
|
||||
getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
|
||||
getNewLine: () => newLine
|
||||
getNewLine: () => newLine,
|
||||
fileExists: fileName => getSourceFile(fileName, ts.ScriptTarget.ES5) !== undefined,
|
||||
readFile: (fileName: string): string => { throw new Error("NotYetImplemented"); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -984,7 +1014,7 @@ module Harness {
|
||||
// Treat them as library files, so include them in build, but not in baselines.
|
||||
let includeBuiltFiles: { unitName: string; content: string }[] = [];
|
||||
|
||||
let useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
|
||||
let useCaseSensitiveFileNames = Harness.IO.useCaseSensitiveFileNames();
|
||||
this.settings.forEach(setCompilerOptionForSetting);
|
||||
|
||||
let fileOutputs: GeneratedFile[] = [];
|
||||
@@ -1002,11 +1032,9 @@ module Harness {
|
||||
let errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
||||
this.lastErrors = errors;
|
||||
|
||||
let result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps);
|
||||
let result = new CompilerResult(fileOutputs, errors, program, Harness.IO.getCurrentDirectory(), emitResult.sourceMaps);
|
||||
onComplete(result, program);
|
||||
|
||||
// reset what newline means in case the last test changed it
|
||||
ts.sys.newLine = newLine;
|
||||
return options;
|
||||
|
||||
function setCompilerOptionForSetting(setting: Harness.TestCaseParser.CompilerSetting) {
|
||||
@@ -1021,6 +1049,13 @@ module Harness {
|
||||
options.module = ts.ModuleKind.UMD;
|
||||
} else if (setting.value.toLowerCase() === "commonjs") {
|
||||
options.module = ts.ModuleKind.CommonJS;
|
||||
if (options.moduleResolution === undefined) {
|
||||
// TODO: currently we have relative module names pretty much in all tests that use CommonJS module target.
|
||||
// Such names could never be resolved in Node however classic resolution strategy still can handle them.
|
||||
// Changing all module names to relative will be a major overhaul in code (but we'll do this anyway) so as a temporary measure
|
||||
// we'll use ts.ModuleResolutionKind.Classic for CommonJS modules.
|
||||
options.moduleResolution = ts.ModuleResolutionKind.Classic;
|
||||
}
|
||||
} else if (setting.value.toLowerCase() === "system") {
|
||||
options.module = ts.ModuleKind.System;
|
||||
} else if (setting.value.toLowerCase() === "unspecified") {
|
||||
@@ -1032,7 +1067,16 @@ module Harness {
|
||||
options.module = <any>setting.value;
|
||||
}
|
||||
break;
|
||||
|
||||
case "moduleresolution":
|
||||
switch((setting.value || "").toLowerCase()) {
|
||||
case "classic":
|
||||
options.moduleResolution = ts.ModuleResolutionKind.Classic;
|
||||
break;
|
||||
case "node":
|
||||
options.moduleResolution = ts.ModuleResolutionKind.NodeJs;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "target":
|
||||
case "codegentarget":
|
||||
if (typeof setting.value === "string") {
|
||||
@@ -1087,6 +1131,10 @@ module Harness {
|
||||
options.out = setting.value;
|
||||
break;
|
||||
|
||||
case "outfile":
|
||||
options.outFile = setting.value;
|
||||
break;
|
||||
|
||||
case "outdiroption":
|
||||
case "outdir":
|
||||
options.outDir = setting.value;
|
||||
@@ -1225,7 +1273,8 @@ module Harness {
|
||||
assert(sourceFile, "Program has no source file with name '" + fileName + "'");
|
||||
// Is this file going to be emitted separately
|
||||
let sourceFileName: string;
|
||||
if (ts.isExternalModule(sourceFile) || !options.out) {
|
||||
let outFile = options.outFile || options.out;
|
||||
if (ts.isExternalModule(sourceFile) || !outFile) {
|
||||
if (options.outDir) {
|
||||
let sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.fileName, result.currentDirectoryForProgram);
|
||||
sourceFilePath = sourceFilePath.replace(result.program.getCommonSourceDirectory(), "");
|
||||
@@ -1237,7 +1286,7 @@ module Harness {
|
||||
}
|
||||
else {
|
||||
// Goes to single --out file
|
||||
sourceFileName = options.out;
|
||||
sourceFileName = outFile;
|
||||
}
|
||||
|
||||
let dTsFileName = ts.removeFileExtension(sourceFileName) + ".d.ts";
|
||||
@@ -1269,7 +1318,7 @@ module Harness {
|
||||
errorOutput += diagnostic.file.fileName + "(" + (lineAndCharacter.line + 1) + "," + (lineAndCharacter.character + 1) + "): ";
|
||||
}
|
||||
|
||||
errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
|
||||
errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, Harness.IO.newLine()) + Harness.IO.newLine();
|
||||
});
|
||||
|
||||
return errorOutput;
|
||||
@@ -1282,7 +1331,7 @@ module Harness {
|
||||
let totalErrorsReported = 0;
|
||||
|
||||
function outputErrorText(error: ts.Diagnostic) {
|
||||
let message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine);
|
||||
let message = ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine());
|
||||
|
||||
let errLines = RunnerBase.removeFullPaths(message)
|
||||
.split("\n")
|
||||
@@ -1379,7 +1428,7 @@ module Harness {
|
||||
assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, "total number of errors");
|
||||
|
||||
return minimalDiagnosticsToString(diagnostics) +
|
||||
ts.sys.newLine + ts.sys.newLine + outputLines.join("\r\n");
|
||||
Harness.IO.newLine() + Harness.IO.newLine() + outputLines.join("\r\n");
|
||||
}
|
||||
|
||||
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string {
|
||||
@@ -1715,7 +1764,7 @@ module Harness {
|
||||
}
|
||||
|
||||
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, descriptionForDescribe: string) {
|
||||
let encoded_actual = (new Buffer(actual)).toString("utf8");
|
||||
let encoded_actual = Utils.encodeString(actual);
|
||||
if (expected != encoded_actual) {
|
||||
// Overwrite & issue error
|
||||
let errMsg = "The baseline file " + relativeFileName + " has changed";
|
||||
|
||||
@@ -203,9 +203,35 @@ module Harness.LanguageService {
|
||||
/// Shim adapter
|
||||
class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost, ts.CoreServicesShimHost {
|
||||
private nativeHost: NativeLanguageServiceHost;
|
||||
constructor(cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
|
||||
|
||||
public getModuleResolutionsForFile: (fileName: string)=> string;
|
||||
|
||||
constructor(preprocessToResolve: boolean, cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
|
||||
super(cancellationToken, options);
|
||||
this.nativeHost = new NativeLanguageServiceHost(cancellationToken, options);
|
||||
|
||||
if (preprocessToResolve) {
|
||||
let compilerOptions = this.nativeHost.getCompilationSettings()
|
||||
let moduleResolutionHost: ts.ModuleResolutionHost = {
|
||||
fileExists: fileName => this.getScriptInfo(fileName) !== undefined,
|
||||
readFile: fileName => {
|
||||
let scriptInfo = this.getScriptInfo(fileName);
|
||||
return scriptInfo && scriptInfo.content;
|
||||
}
|
||||
};
|
||||
this.getModuleResolutionsForFile = (fileName) => {
|
||||
let scriptInfo = this.getScriptInfo(fileName);
|
||||
let preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ true);
|
||||
let imports: ts.Map<string> = {};
|
||||
for (let module of preprocessInfo.importedFiles) {
|
||||
let resolutionInfo = ts.resolveModuleName(module.fileName, fileName, compilerOptions, moduleResolutionHost);
|
||||
if (resolutionInfo.resolvedFileName) {
|
||||
imports[module.fileName] = resolutionInfo.resolvedFileName;
|
||||
}
|
||||
}
|
||||
return JSON.stringify(imports);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getFilenames(): string[] { return this.nativeHost.getFilenames(); }
|
||||
@@ -229,7 +255,11 @@ module Harness.LanguageService {
|
||||
readDirectory(rootDir: string, extension: string): string {
|
||||
throw new Error("NYI");
|
||||
}
|
||||
|
||||
fileExists(fileName: string) { return this.getScriptInfo(fileName) !== undefined; }
|
||||
readFile(fileName: string) {
|
||||
let snapshot = this.nativeHost.getScriptSnapshot(fileName);
|
||||
return snapshot && snapshot.getText(0, snapshot.getLength());
|
||||
}
|
||||
log(s: string): void { this.nativeHost.log(s); }
|
||||
trace(s: string): void { this.nativeHost.trace(s); }
|
||||
error(s: string): void { this.nativeHost.error(s); }
|
||||
@@ -399,8 +429,8 @@ module Harness.LanguageService {
|
||||
export class ShimLanugageServiceAdapter implements LanguageServiceAdapter {
|
||||
private host: ShimLanguageServiceHost;
|
||||
private factory: ts.TypeScriptServicesFactory;
|
||||
constructor(cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
|
||||
this.host = new ShimLanguageServiceHost(cancellationToken, options);
|
||||
constructor(preprocessToResolve: boolean, cancellationToken?: ts.HostCancellationToken, options?: ts.CompilerOptions) {
|
||||
this.host = new ShimLanguageServiceHost(preprocessToResolve, cancellationToken, options);
|
||||
this.factory = new TypeScript.Services.TypeScriptServicesFactory();
|
||||
}
|
||||
getHost() { return this.host; }
|
||||
@@ -419,6 +449,7 @@ module Harness.LanguageService {
|
||||
let convertResult: ts.PreProcessedFileInfo = {
|
||||
referencedFiles: [],
|
||||
importedFiles: [],
|
||||
ambientExternalModules: [],
|
||||
isLibFile: shimResult.isLibFile
|
||||
};
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class ProjectRunner extends RunnerBase {
|
||||
|
||||
let testFileText: string = null;
|
||||
try {
|
||||
testFileText = ts.sys.readFile(testCaseFileName);
|
||||
testFileText = Harness.IO.readFile(testCaseFileName);
|
||||
}
|
||||
catch (e) {
|
||||
assert(false, "Unable to open testcase file: " + testCaseFileName + ": " + e.message);
|
||||
@@ -98,7 +98,7 @@ class ProjectRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
function cleanProjectUrl(url: string) {
|
||||
let diskProjectPath = ts.normalizeSlashes(ts.sys.resolvePath(testCase.projectRoot));
|
||||
let diskProjectPath = ts.normalizeSlashes(Harness.IO.resolvePath(testCase.projectRoot));
|
||||
let projectRootUrl = "file:///" + diskProjectPath;
|
||||
let normalizedProjectRoot = ts.normalizeSlashes(testCase.projectRoot);
|
||||
diskProjectPath = diskProjectPath.substr(0, diskProjectPath.lastIndexOf(normalizedProjectRoot));
|
||||
@@ -122,7 +122,7 @@ class ProjectRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
function getCurrentDirectory() {
|
||||
return ts.sys.resolvePath(testCase.projectRoot);
|
||||
return Harness.IO.resolvePath(testCase.projectRoot);
|
||||
}
|
||||
|
||||
function compileProjectFiles(moduleKind: ts.ModuleKind, getInputFiles: () => string[],
|
||||
@@ -158,11 +158,12 @@ class ProjectRunner extends RunnerBase {
|
||||
return {
|
||||
declaration: !!testCase.declaration,
|
||||
sourceMap: !!testCase.sourceMap,
|
||||
out: testCase.out,
|
||||
outFile: testCase.out,
|
||||
outDir: testCase.outDir,
|
||||
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? ts.sys.resolvePath(testCase.mapRoot) : testCase.mapRoot,
|
||||
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? ts.sys.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
|
||||
mapRoot: testCase.resolveMapRoot && testCase.mapRoot ? Harness.IO.resolvePath(testCase.mapRoot) : testCase.mapRoot,
|
||||
sourceRoot: testCase.resolveSourceRoot && testCase.sourceRoot ? Harness.IO.resolvePath(testCase.sourceRoot) : testCase.sourceRoot,
|
||||
module: moduleKind,
|
||||
moduleResolution: ts.ModuleResolutionKind.Classic, // currently all tests use classic module resolution kind, this will change in the future
|
||||
noResolve: testCase.noResolve,
|
||||
rootDir: testCase.rootDir
|
||||
};
|
||||
@@ -190,8 +191,10 @@ class ProjectRunner extends RunnerBase {
|
||||
writeFile,
|
||||
getCurrentDirectory,
|
||||
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
||||
getNewLine: () => ts.sys.newLine
|
||||
useCaseSensitiveFileNames: () => Harness.IO.useCaseSensitiveFileNames(),
|
||||
getNewLine: () => Harness.IO.newLine(),
|
||||
fileExists: fileName => getSourceFile(fileName, ts.ScriptTarget.ES5) !== undefined,
|
||||
readFile: fileName => Harness.IO.readFile(fileName)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -214,7 +217,7 @@ class ProjectRunner extends RunnerBase {
|
||||
function getSourceFileText(fileName: string): string {
|
||||
let text: string = undefined;
|
||||
try {
|
||||
text = ts.sys.readFile(ts.isRootedDiskPath(fileName)
|
||||
text = Harness.IO.readFile(ts.isRootedDiskPath(fileName)
|
||||
? fileName
|
||||
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(fileName));
|
||||
}
|
||||
@@ -261,14 +264,14 @@ class ProjectRunner extends RunnerBase {
|
||||
// Actual writing of file as in tc.ts
|
||||
function ensureDirectoryStructure(directoryname: string) {
|
||||
if (directoryname) {
|
||||
if (!ts.sys.directoryExists(directoryname)) {
|
||||
if (!Harness.IO.directoryExists(directoryname)) {
|
||||
ensureDirectoryStructure(ts.getDirectoryPath(directoryname));
|
||||
ts.sys.createDirectory(directoryname);
|
||||
Harness.IO.createDirectory(directoryname);
|
||||
}
|
||||
}
|
||||
}
|
||||
ensureDirectoryStructure(ts.getDirectoryPath(ts.normalizePath(outputFilePath)));
|
||||
ts.sys.writeFile(outputFilePath, data, writeByteOrderMark);
|
||||
Harness.IO.writeFile(outputFilePath, data);
|
||||
|
||||
outputFiles.push({ emittedFileName: fileName, code: data, fileName: diskRelativeName, writeByteOrderMark: writeByteOrderMark });
|
||||
}
|
||||
@@ -297,7 +300,7 @@ class ProjectRunner extends RunnerBase {
|
||||
allInputFiles.unshift(findOutpuDtsFile(outputDtsFileName));
|
||||
}
|
||||
else {
|
||||
let outputDtsFileName = ts.removeFileExtension(compilerOptions.out) + ".d.ts";
|
||||
let outputDtsFileName = ts.removeFileExtension(compilerOptions.outFile|| compilerOptions.out) + ".d.ts";
|
||||
let outputDtsFile = findOutpuDtsFile(outputDtsFileName);
|
||||
if (!ts.contains(allInputFiles, outputDtsFile)) {
|
||||
allInputFiles.unshift(outputDtsFile);
|
||||
@@ -389,7 +392,7 @@ class ProjectRunner extends RunnerBase {
|
||||
|
||||
Harness.Baseline.runBaseline("Baseline of emitted result (" + moduleNameToString(compilerResult.moduleKind) + "): " + testCaseFileName, getBaselineFolder(compilerResult.moduleKind) + outputFile.fileName, () => {
|
||||
try {
|
||||
return ts.sys.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
|
||||
return Harness.IO.readFile(getProjectOutputFolder(outputFile.fileName, compilerResult.moduleKind));
|
||||
}
|
||||
catch (e) {
|
||||
return undefined;
|
||||
|
||||
@@ -68,7 +68,10 @@ if (testConfigFile !== "") {
|
||||
case "fourslash-shims":
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
|
||||
break;
|
||||
case "fourslash-server":
|
||||
case 'fourslash-shims-pp':
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.ShimsWithPreprocess));
|
||||
break;
|
||||
case 'fourslash-server':
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Server));
|
||||
break;
|
||||
case "fourslash-generated":
|
||||
@@ -98,10 +101,9 @@ if (runners.length === 0) {
|
||||
// language services
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Native));
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Shims));
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.ShimsWithPreprocess));
|
||||
runners.push(new FourSlashRunner(FourSlashTestType.Server));
|
||||
// runners.push(new GeneratedFourslashRunner());
|
||||
}
|
||||
|
||||
ts.sys.newLine = "\r\n";
|
||||
|
||||
runTests(runners);
|
||||
|
||||
Vendored
+2650
-9
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
@@ -8,4 +8,4 @@ interface NodeList {
|
||||
|
||||
interface NodeListOf<TNode extends Node> {
|
||||
[Symbol.iterator](): IterableIterator<TNode>
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+20
-11
@@ -2459,7 +2459,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
|
||||
* @param features Contains a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (for example, "fullscreen=yes, toolbar=yes"). The following values are supported.
|
||||
* @param replace Specifies whether the existing entry for the document is replaced in the history list.
|
||||
*/
|
||||
open(url?: string, name?: string, features?: string, replace?: boolean): Document | Window;
|
||||
open(url?: string, name?: string, features?: string, replace?: boolean): Document;
|
||||
/**
|
||||
* Returns a Boolean value that indicates whether a specified command can be successfully executed using execCommand, given the current state of the document.
|
||||
* @param commandId Specifies a command identifier.
|
||||
@@ -2916,6 +2916,7 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec
|
||||
webkitMatchesSelector(selectors: string): boolean;
|
||||
webkitRequestFullScreen(): void;
|
||||
webkitRequestFullscreen(): void;
|
||||
getElementsByClassName(classNames: string): NodeListOf<Element>;
|
||||
addEventListener(type: "MSGestureChange", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "MSGestureDoubleTap", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "MSGestureEnd", listener: (ev: MSGestureEvent) => any, useCapture?: boolean): void;
|
||||
@@ -3030,7 +3031,7 @@ interface File extends Blob {
|
||||
|
||||
declare var File: {
|
||||
prototype: File;
|
||||
new(): File;
|
||||
new (parts: (ArrayBuffer | ArrayBufferView | Blob | string)[], filename: string, properties?: FilePropertyBag): File;
|
||||
}
|
||||
|
||||
interface FileList {
|
||||
@@ -3903,7 +3904,6 @@ interface HTMLElement extends Element {
|
||||
contains(child: HTMLElement): boolean;
|
||||
dragDrop(): boolean;
|
||||
focus(): void;
|
||||
getElementsByClassName(classNames: string): NodeListOf<Element>;
|
||||
insertAdjacentElement(position: string, insertedElement: Element): Element;
|
||||
insertAdjacentHTML(where: string, html: string): void;
|
||||
insertAdjacentText(where: string, text: string): void;
|
||||
@@ -6865,7 +6865,7 @@ interface IDBDatabase extends EventTarget {
|
||||
createObjectStore(name: string, optionalParameters?: any): IDBObjectStore;
|
||||
deleteObjectStore(name: string): void;
|
||||
transaction(storeNames: any, mode?: string): IDBTransaction;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
}
|
||||
@@ -6986,7 +6986,7 @@ interface IDBTransaction extends EventTarget {
|
||||
READ_ONLY: string;
|
||||
READ_WRITE: string;
|
||||
VERSION_CHANGE: string;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "complete", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
@@ -7016,11 +7016,14 @@ interface ImageData {
|
||||
width: number;
|
||||
}
|
||||
|
||||
declare var ImageData: {
|
||||
interface ImageDataConstructor {
|
||||
prototype: ImageData;
|
||||
new(): ImageData;
|
||||
new(width: number, height: number): ImageData;
|
||||
new(array: Uint8ClampedArray, width: number, height: number): ImageData;
|
||||
}
|
||||
|
||||
declare var ImageData: ImageDataConstructor;
|
||||
|
||||
interface KeyboardEvent extends UIEvent {
|
||||
altKey: boolean;
|
||||
char: string;
|
||||
@@ -12169,7 +12172,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
|
||||
LOADING: number;
|
||||
OPENED: number;
|
||||
UNSENT: number;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
|
||||
@@ -12439,7 +12442,7 @@ interface MSBaseReader {
|
||||
DONE: number;
|
||||
EMPTY: number;
|
||||
LOADING: number;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
|
||||
@@ -12595,7 +12598,7 @@ interface XMLHttpRequestEventTarget {
|
||||
onloadstart: (ev: Event) => any;
|
||||
onprogress: (ev: ProgressEvent) => any;
|
||||
ontimeout: (ev: ProgressEvent) => any;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
|
||||
@@ -12612,11 +12615,17 @@ interface NodeListOf<TNode extends Node> extends NodeList {
|
||||
[index: number]: TNode;
|
||||
}
|
||||
|
||||
|
||||
interface BlobPropertyBag {
|
||||
type?: string;
|
||||
endings?: string;
|
||||
}
|
||||
|
||||
interface FilePropertyBag {
|
||||
type?: string;
|
||||
lastModified?: number;
|
||||
}
|
||||
|
||||
interface EventListenerObject {
|
||||
handleEvent(evt: Event): void;
|
||||
}
|
||||
@@ -12952,4 +12961,4 @@ declare function addEventListener(type: "unload", listener: (ev: Event) => any,
|
||||
declare function addEventListener(type: "volumechange", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
declare function addEventListener(type: "waiting", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
declare function addEventListener(type: "wheel", listener: (ev: WheelEvent) => any, useCapture?: boolean): void;
|
||||
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
declare function addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
Vendored
+146
-2535
File diff suppressed because it is too large
Load Diff
Vendored
-2305
File diff suppressed because it is too large
Load Diff
Vendored
+124
-18
@@ -3,10 +3,28 @@
|
||||
/// IE Worker APIs
|
||||
/////////////////////////////
|
||||
|
||||
interface EventInit {
|
||||
bubbles?: boolean;
|
||||
cancelable?: boolean;
|
||||
}
|
||||
|
||||
interface EventListener {
|
||||
(evt: Event): void;
|
||||
}
|
||||
|
||||
interface AudioBuffer {
|
||||
duration: number;
|
||||
length: number;
|
||||
numberOfChannels: number;
|
||||
sampleRate: number;
|
||||
getChannelData(channel: number): any;
|
||||
}
|
||||
|
||||
declare var AudioBuffer: {
|
||||
prototype: AudioBuffer;
|
||||
new(): AudioBuffer;
|
||||
}
|
||||
|
||||
interface Blob {
|
||||
size: number;
|
||||
type: string;
|
||||
@@ -60,6 +78,21 @@ declare var Console: {
|
||||
new(): Console;
|
||||
}
|
||||
|
||||
interface Coordinates {
|
||||
accuracy: number;
|
||||
altitude: number;
|
||||
altitudeAccuracy: number;
|
||||
heading: number;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
speed: number;
|
||||
}
|
||||
|
||||
declare var Coordinates: {
|
||||
prototype: Coordinates;
|
||||
new(): Coordinates;
|
||||
}
|
||||
|
||||
interface DOMError {
|
||||
name: string;
|
||||
toString(): string;
|
||||
@@ -210,7 +243,7 @@ interface File extends Blob {
|
||||
|
||||
declare var File: {
|
||||
prototype: File;
|
||||
new(): File;
|
||||
new (parts: (ArrayBuffer | ArrayBufferView | Blob | string)[], filename: string, properties?: FilePropertyBag): File;
|
||||
}
|
||||
|
||||
interface FileList {
|
||||
@@ -281,7 +314,7 @@ interface IDBDatabase extends EventTarget {
|
||||
createObjectStore(name: string, optionalParameters?: any): IDBObjectStore;
|
||||
deleteObjectStore(name: string): void;
|
||||
transaction(storeNames: any, mode?: string): IDBTransaction;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
}
|
||||
@@ -402,7 +435,7 @@ interface IDBTransaction extends EventTarget {
|
||||
READ_ONLY: string;
|
||||
READ_WRITE: string;
|
||||
VERSION_CHANGE: string;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "complete", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
@@ -432,11 +465,14 @@ interface ImageData {
|
||||
width: number;
|
||||
}
|
||||
|
||||
declare var ImageData: {
|
||||
interface ImageDataConstructor {
|
||||
prototype: ImageData;
|
||||
new(): ImageData;
|
||||
new(width: number, height: number): ImageData;
|
||||
new(array: Uint8ClampedArray, width: number, height: number): ImageData;
|
||||
}
|
||||
|
||||
declare var ImageData: ImageDataConstructor;
|
||||
|
||||
interface MSApp {
|
||||
clearTemporaryWebDataAsync(): MSAppAsyncOperation;
|
||||
createBlobFromRandomAccessStream(type: string, seeker: any): Blob;
|
||||
@@ -460,6 +496,29 @@ interface MSApp {
|
||||
}
|
||||
declare var MSApp: MSApp;
|
||||
|
||||
interface MSAppAsyncOperation extends EventTarget {
|
||||
error: DOMError;
|
||||
oncomplete: (ev: Event) => any;
|
||||
onerror: (ev: Event) => any;
|
||||
readyState: number;
|
||||
result: any;
|
||||
start(): void;
|
||||
COMPLETED: number;
|
||||
ERROR: number;
|
||||
STARTED: number;
|
||||
addEventListener(type: "complete", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
}
|
||||
|
||||
declare var MSAppAsyncOperation: {
|
||||
prototype: MSAppAsyncOperation;
|
||||
new(): MSAppAsyncOperation;
|
||||
COMPLETED: number;
|
||||
ERROR: number;
|
||||
STARTED: number;
|
||||
}
|
||||
|
||||
interface MSBlobBuilder {
|
||||
append(data: any, endings?: string): void;
|
||||
getBlob(contentType?: string): Blob;
|
||||
@@ -496,6 +555,18 @@ declare var MSStreamReader: {
|
||||
new(): MSStreamReader;
|
||||
}
|
||||
|
||||
interface MediaQueryList {
|
||||
matches: boolean;
|
||||
media: string;
|
||||
addListener(listener: MediaQueryListListener): void;
|
||||
removeListener(listener: MediaQueryListListener): void;
|
||||
}
|
||||
|
||||
declare var MediaQueryList: {
|
||||
prototype: MediaQueryList;
|
||||
new(): MediaQueryList;
|
||||
}
|
||||
|
||||
interface MessageChannel {
|
||||
port1: MessagePort;
|
||||
port2: MessagePort;
|
||||
@@ -533,6 +604,33 @@ declare var MessagePort: {
|
||||
new(): MessagePort;
|
||||
}
|
||||
|
||||
interface Position {
|
||||
coords: Coordinates;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
declare var Position: {
|
||||
prototype: Position;
|
||||
new(): Position;
|
||||
}
|
||||
|
||||
interface PositionError {
|
||||
code: number;
|
||||
message: string;
|
||||
toString(): string;
|
||||
PERMISSION_DENIED: number;
|
||||
POSITION_UNAVAILABLE: number;
|
||||
TIMEOUT: number;
|
||||
}
|
||||
|
||||
declare var PositionError: {
|
||||
prototype: PositionError;
|
||||
new(): PositionError;
|
||||
PERMISSION_DENIED: number;
|
||||
POSITION_UNAVAILABLE: number;
|
||||
TIMEOUT: number;
|
||||
}
|
||||
|
||||
interface ProgressEvent extends Event {
|
||||
lengthComputable: boolean;
|
||||
loaded: number;
|
||||
@@ -620,7 +718,7 @@ interface XMLHttpRequest extends EventTarget, XMLHttpRequestEventTarget {
|
||||
LOADING: number;
|
||||
OPENED: number;
|
||||
UNSENT: number;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
|
||||
@@ -642,6 +740,15 @@ declare var XMLHttpRequest: {
|
||||
create(): XMLHttpRequest;
|
||||
}
|
||||
|
||||
interface XMLHttpRequestUpload extends EventTarget, XMLHttpRequestEventTarget {
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
}
|
||||
|
||||
declare var XMLHttpRequestUpload: {
|
||||
prototype: XMLHttpRequestUpload;
|
||||
new(): XMLHttpRequestUpload;
|
||||
}
|
||||
|
||||
interface AbstractWorker {
|
||||
onerror: (ev: Event) => any;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
@@ -661,7 +768,7 @@ interface MSBaseReader {
|
||||
DONE: number;
|
||||
EMPTY: number;
|
||||
LOADING: number;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
|
||||
@@ -702,7 +809,7 @@ interface XMLHttpRequestEventTarget {
|
||||
onloadstart: (ev: Event) => any;
|
||||
onprogress: (ev: ProgressEvent) => any;
|
||||
ontimeout: (ev: ProgressEvent) => any;
|
||||
addEventListener(type: "abort", listener: (ev: UIEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "abort", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "error", listener: (ev: ErrorEvent) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "load", listener: (ev: Event) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: "loadend", listener: (ev: ProgressEvent) => any, useCapture?: boolean): void;
|
||||
@@ -788,17 +895,16 @@ interface WorkerUtils extends Object, WindowBase64 {
|
||||
}
|
||||
|
||||
|
||||
interface NodeListOf<TNode extends Node> extends NodeList {
|
||||
length: number;
|
||||
item(index: number): TNode;
|
||||
[index: number]: TNode;
|
||||
}
|
||||
|
||||
interface BlobPropertyBag {
|
||||
type?: string;
|
||||
endings?: string;
|
||||
}
|
||||
|
||||
interface FilePropertyBag {
|
||||
type?: string;
|
||||
lastModified?: number;
|
||||
}
|
||||
|
||||
interface EventListenerObject {
|
||||
handleEvent(evt: Event): void;
|
||||
}
|
||||
@@ -820,11 +926,11 @@ interface MediaQueryListListener {
|
||||
interface MSLaunchUriCallback {
|
||||
(): void;
|
||||
}
|
||||
interface FrameRequestCallback {
|
||||
(time: number): void;
|
||||
interface MSUnsafeFunctionCallback {
|
||||
(): any;
|
||||
}
|
||||
interface MutationCallback {
|
||||
(mutations: MutationRecord[], observer: MutationObserver): void;
|
||||
interface MSExecAtPriorityFunctionCallback {
|
||||
(...args: any[]): any;
|
||||
}
|
||||
interface DecodeSuccessCallback {
|
||||
(decodedData: AudioBuffer): void;
|
||||
|
||||
+243
-49
@@ -78,15 +78,76 @@ namespace ts.server {
|
||||
return this.snap().getChangeRange(oldSnapshot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface TimestampedResolvedModule extends ResolvedModule {
|
||||
lastCheckTime: number;
|
||||
}
|
||||
|
||||
export class LSHost implements ts.LanguageServiceHost {
|
||||
ls: ts.LanguageService = null;
|
||||
compilationSettings: ts.CompilerOptions;
|
||||
filenameToScript: ts.Map<ScriptInfo> = {};
|
||||
roots: ScriptInfo[] = [];
|
||||
|
||||
private resolvedModuleNames: ts.FileMap<Map<TimestampedResolvedModule>>;
|
||||
private moduleResolutionHost: ts.ModuleResolutionHost;
|
||||
|
||||
constructor(public host: ServerHost, public project: Project) {
|
||||
this.resolvedModuleNames = ts.createFileMap<Map<TimestampedResolvedModule>>(ts.createGetCanonicalFileName(host.useCaseSensitiveFileNames))
|
||||
this.moduleResolutionHost = {
|
||||
fileExists: fileName => this.fileExists(fileName),
|
||||
readFile: fileName => this.host.readFile(fileName)
|
||||
}
|
||||
}
|
||||
|
||||
resolveModuleNames(moduleNames: string[], containingFile: string): string[] {
|
||||
let currentResolutionsInFile = this.resolvedModuleNames.get(containingFile);
|
||||
|
||||
let newResolutions: Map<TimestampedResolvedModule> = {};
|
||||
let resolvedFileNames: string[] = [];
|
||||
|
||||
let compilerOptions = this.getCompilationSettings();
|
||||
|
||||
for (let moduleName of moduleNames) {
|
||||
// check if this is a duplicate entry in the list
|
||||
let resolution = lookUp(newResolutions, moduleName);
|
||||
if (!resolution) {
|
||||
let existingResolution = currentResolutionsInFile && ts.lookUp(currentResolutionsInFile, moduleName);
|
||||
if (moduleResolutionIsValid(existingResolution)) {
|
||||
// ok, it is safe to use existing module resolution results
|
||||
resolution = existingResolution;
|
||||
}
|
||||
else {
|
||||
resolution = <TimestampedResolvedModule>resolveModuleName(moduleName, containingFile, compilerOptions, this.moduleResolutionHost);
|
||||
resolution.lastCheckTime = Date.now();
|
||||
newResolutions[moduleName] = resolution;
|
||||
}
|
||||
}
|
||||
|
||||
ts.Debug.assert(resolution !== undefined);
|
||||
|
||||
resolvedFileNames.push(resolution.resolvedFileName);
|
||||
}
|
||||
|
||||
// replace old results with a new one
|
||||
this.resolvedModuleNames.set(containingFile, newResolutions);
|
||||
return resolvedFileNames;
|
||||
|
||||
function moduleResolutionIsValid(resolution: TimestampedResolvedModule): boolean {
|
||||
if (!resolution) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (resolution.resolvedFileName) {
|
||||
// TODO: consider checking failedLookupLocations
|
||||
// TODO: use lastCheckTime to track expiration for module name resolution
|
||||
return true;
|
||||
}
|
||||
|
||||
// consider situation if we have no candidate locations as valid resolution.
|
||||
// after all there is no point to invalidate it if we have no idea where to look for the module.
|
||||
return resolution.failedLookupLocations.length === 0;
|
||||
}
|
||||
}
|
||||
|
||||
getDefaultLibFileName() {
|
||||
var nodeModuleBinDir = ts.getDirectoryPath(ts.normalizePath(this.host.getExecutingFilePath()));
|
||||
@@ -102,6 +163,8 @@ namespace ts.server {
|
||||
|
||||
setCompilationSettings(opt: ts.CompilerOptions) {
|
||||
this.compilationSettings = opt;
|
||||
// conservatively assume that changing compiler options might affect module resolution strategy
|
||||
this.resolvedModuleNames.clear();
|
||||
}
|
||||
|
||||
lineAffectsRefs(filename: string, line: number) {
|
||||
@@ -137,6 +200,7 @@ namespace ts.server {
|
||||
removeReferencedFile(info: ScriptInfo) {
|
||||
if (!info.isOpen) {
|
||||
this.filenameToScript[info.fileName] = undefined;
|
||||
this.resolvedModuleNames.remove(info.fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +224,14 @@ namespace ts.server {
|
||||
this.roots.push(info);
|
||||
}
|
||||
}
|
||||
|
||||
removeRoot(info: ScriptInfo) {
|
||||
var scriptInfo = ts.lookUp(this.filenameToScript, info.fileName);
|
||||
if (scriptInfo) {
|
||||
this.filenameToScript[info.fileName] = undefined;
|
||||
this.roots = copyListRemovingItem(info, this.roots);
|
||||
}
|
||||
}
|
||||
|
||||
saveTo(filename: string, tmpfilename: string) {
|
||||
var script = this.getScriptInfo(filename);
|
||||
@@ -281,6 +353,7 @@ namespace ts.server {
|
||||
export class Project {
|
||||
compilerService: CompilerService;
|
||||
projectFilename: string;
|
||||
projectFileWatcher: FileWatcher;
|
||||
program: ts.Program;
|
||||
filenameToSourceFile: ts.Map<ts.SourceFile> = {};
|
||||
updateGraphSeq = 0;
|
||||
@@ -288,7 +361,7 @@ namespace ts.server {
|
||||
openRefCount = 0;
|
||||
|
||||
constructor(public projectService: ProjectService, public projectOptions?: ProjectOptions) {
|
||||
this.compilerService = new CompilerService(this,projectOptions && projectOptions.compilerOptions);
|
||||
this.compilerService = new CompilerService(this, projectOptions && projectOptions.compilerOptions);
|
||||
}
|
||||
|
||||
addOpenRef() {
|
||||
@@ -359,6 +432,12 @@ namespace ts.server {
|
||||
info.defaultProject = this;
|
||||
this.compilerService.host.addRoot(info);
|
||||
}
|
||||
|
||||
// remove a root file from project
|
||||
removeRoot(info: ScriptInfo) {
|
||||
info.defaultProject = undefined;
|
||||
this.compilerService.host.removeRoot(info);
|
||||
}
|
||||
|
||||
filesToString() {
|
||||
var strBuilder = "";
|
||||
@@ -453,6 +532,12 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
watchedProjectConfigFileChanged(project: Project) {
|
||||
this.log("Config File Changed: " + project.projectFilename);
|
||||
this.updateConfiguredProject(project);
|
||||
this.updateProjectStructure();
|
||||
}
|
||||
|
||||
log(msg: string, type = "Err") {
|
||||
this.psLogger.msg(msg, type);
|
||||
}
|
||||
@@ -529,6 +614,19 @@ namespace ts.server {
|
||||
}
|
||||
this.configuredProjects = configuredProjects;
|
||||
}
|
||||
|
||||
removeConfiguredProject(project: Project) {
|
||||
project.projectFileWatcher.close();
|
||||
this.configuredProjects = copyListRemovingItem(project, this.configuredProjects);
|
||||
|
||||
let fileNames = project.getFileNames();
|
||||
for (let fileName of fileNames) {
|
||||
let info = this.getScriptInfo(fileName);
|
||||
if (info.defaultProject == project){
|
||||
info.defaultProject = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setConfiguredProjectRoot(info: ScriptInfo) {
|
||||
for (var i = 0, len = this.configuredProjects.length; i < len; i++) {
|
||||
@@ -583,7 +681,6 @@ namespace ts.server {
|
||||
/**
|
||||
* Remove this file from the set of open, non-configured files.
|
||||
* @param info The file that has been closed or newly configured
|
||||
* @param openedByConfig True if info has become a root of a configured project
|
||||
*/
|
||||
closeOpenFile(info: ScriptInfo) {
|
||||
var openFileRoots: ScriptInfo[] = [];
|
||||
@@ -672,18 +769,42 @@ namespace ts.server {
|
||||
return referencingProjects;
|
||||
}
|
||||
|
||||
reloadProjects() {
|
||||
// First check if there is new tsconfig file added for inferred project roots
|
||||
for (let info of this.openFileRoots) {
|
||||
this.openOrUpdateConfiguredProjectForFile(info.fileName);
|
||||
}
|
||||
this.updateProjectStructure();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is to update the project structure for every projects.
|
||||
* It is called on the premise that all the configured projects are
|
||||
* up to date.
|
||||
*/
|
||||
updateProjectStructure() {
|
||||
this.log("updating project structure from ...", "Info");
|
||||
this.printProjects();
|
||||
|
||||
let unattachedOpenFiles: ScriptInfo[] = [];
|
||||
let openFileRootsConfigured: ScriptInfo[] = [];
|
||||
for (let info of this.openFileRootsConfigured) {
|
||||
let project = info.defaultProject;
|
||||
if (!project || !(project.getSourceFile(info))) {
|
||||
info.defaultProject = undefined;
|
||||
unattachedOpenFiles.push(info);
|
||||
}
|
||||
else {
|
||||
openFileRootsConfigured.push(info);
|
||||
}
|
||||
}
|
||||
this.openFileRootsConfigured = openFileRootsConfigured;
|
||||
|
||||
// First loop through all open files that are referenced by projects but are not
|
||||
// project roots. For each referenced file, see if the default project still
|
||||
// references that file. If so, then just keep the file in the referenced list.
|
||||
// If not, add the file to an unattached list, to be rechecked later.
|
||||
|
||||
var openFilesReferenced: ScriptInfo[] = [];
|
||||
var unattachedOpenFiles: ScriptInfo[] = [];
|
||||
|
||||
for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) {
|
||||
var referencedFile = this.openFilesReferenced[i];
|
||||
referencedFile.defaultProject.updateGraph();
|
||||
@@ -793,31 +914,39 @@ namespace ts.server {
|
||||
* Open file whose contents is managed by the client
|
||||
* @param filename is absolute pathname
|
||||
*/
|
||||
|
||||
openClientFile(fileName: string) {
|
||||
var searchPath = ts.normalizePath(getDirectoryPath(fileName));
|
||||
this.log("Search path: " + searchPath,"Info");
|
||||
var configFileName = this.findConfigFile(searchPath);
|
||||
if (configFileName) {
|
||||
this.log("Config file name: " + configFileName, "Info");
|
||||
} else {
|
||||
this.log("no config file");
|
||||
}
|
||||
if (configFileName && (!this.configProjectIsActive(configFileName))) {
|
||||
var configResult = this.openConfigFile(configFileName, fileName);
|
||||
if (!configResult.success) {
|
||||
this.log("Error opening config file " + configFileName + " " + configResult.errorMsg);
|
||||
}
|
||||
else {
|
||||
this.log("Opened configuration file " + configFileName,"Info");
|
||||
this.configuredProjects.push(configResult.project);
|
||||
}
|
||||
}
|
||||
this.openOrUpdateConfiguredProjectForFile(fileName);
|
||||
var info = this.openFile(fileName, true);
|
||||
this.addOpenFile(info);
|
||||
this.printProjects();
|
||||
return info;
|
||||
}
|
||||
|
||||
openOrUpdateConfiguredProjectForFile(fileName: string) {
|
||||
let searchPath = ts.normalizePath(getDirectoryPath(fileName));
|
||||
this.log("Search path: " + searchPath,"Info");
|
||||
let configFileName = this.findConfigFile(searchPath);
|
||||
if (configFileName) {
|
||||
this.log("Config file name: " + configFileName, "Info");
|
||||
let project = this.findConfiguredProjectByConfigFile(configFileName);
|
||||
if (!project) {
|
||||
var configResult = this.openConfigFile(configFileName, fileName);
|
||||
if (!configResult.success) {
|
||||
this.log("Error opening config file " + configFileName + " " + configResult.errorMsg);
|
||||
}
|
||||
else {
|
||||
this.log("Opened configuration file " + configFileName,"Info");
|
||||
this.configuredProjects.push(configResult.project);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.updateConfiguredProject(project);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.log("No config files found.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close file whose contents is managed by the client
|
||||
@@ -895,49 +1024,113 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
configProjectIsActive(fileName: string) {
|
||||
for (var i = 0, len = this.configuredProjects.length; i < len; i++) {
|
||||
if (this.configuredProjects[i].projectFilename == fileName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return this.findConfiguredProjectByConfigFile(fileName) === undefined;
|
||||
}
|
||||
|
||||
openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult {
|
||||
findConfiguredProjectByConfigFile(configFileName: string) {
|
||||
for (var i = 0, len = this.configuredProjects.length; i < len; i++) {
|
||||
if (this.configuredProjects[i].projectFilename == configFileName) {
|
||||
return this.configuredProjects[i];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
configFileToProjectOptions(configFilename: string): { succeeded: boolean, projectOptions?: ProjectOptions, error?: ProjectOpenResult } {
|
||||
configFilename = ts.normalizePath(configFilename);
|
||||
// file references will be relative to dirPath (or absolute)
|
||||
var dirPath = ts.getDirectoryPath(configFilename);
|
||||
var contents = this.host.readFile(configFilename)
|
||||
var rawConfig: { config?: ProjectOptions; error?: Diagnostic; } = ts.parseConfigFileText(configFilename, contents);
|
||||
if (rawConfig.error) {
|
||||
return rawConfig.error;
|
||||
return { succeeded: false, error: rawConfig.error };
|
||||
}
|
||||
else {
|
||||
var parsedCommandLine = ts.parseConfigFile(rawConfig.config, this.host, dirPath);
|
||||
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {
|
||||
return { errorMsg: "tsconfig option errors" };
|
||||
return { succeeded: false, error: { errorMsg: "tsconfig option errors" }};
|
||||
}
|
||||
else if (parsedCommandLine.fileNames) {
|
||||
else if (parsedCommandLine.fileNames == null) {
|
||||
return { succeeded: false, error: { errorMsg: "no files found" }}
|
||||
}
|
||||
else {
|
||||
var projectOptions: ProjectOptions = {
|
||||
files: parsedCommandLine.fileNames,
|
||||
compilerOptions: parsedCommandLine.options
|
||||
};
|
||||
var proj = this.createProject(configFilename, projectOptions);
|
||||
for (var i = 0, len = parsedCommandLine.fileNames.length; i < len; i++) {
|
||||
var rootFilename = parsedCommandLine.fileNames[i];
|
||||
if (this.host.fileExists(rootFilename)) {
|
||||
var info = this.openFile(rootFilename, clientFileName == rootFilename);
|
||||
proj.addRoot(info);
|
||||
}
|
||||
else {
|
||||
return { errorMsg: "specified file " + rootFilename + " not found" };
|
||||
}
|
||||
return { succeeded: true, projectOptions };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult {
|
||||
let { succeeded, projectOptions, error } = this.configFileToProjectOptions(configFilename);
|
||||
if (!succeeded) {
|
||||
return error;
|
||||
}
|
||||
else {
|
||||
let proj = this.createProject(configFilename, projectOptions);
|
||||
for (let i = 0, len = projectOptions.files.length; i < len; i++) {
|
||||
let rootFilename = projectOptions.files[i];
|
||||
if (this.host.fileExists(rootFilename)) {
|
||||
let info = this.openFile(rootFilename, /*openedByClient*/ clientFileName == rootFilename);
|
||||
proj.addRoot(info);
|
||||
}
|
||||
proj.finishGraph();
|
||||
return { success: true, project: proj };
|
||||
else {
|
||||
return { errorMsg: "specified file " + rootFilename + " not found" };
|
||||
}
|
||||
}
|
||||
proj.finishGraph();
|
||||
proj.projectFileWatcher = this.host.watchFile(configFilename, _ => this.watchedProjectConfigFileChanged(proj));
|
||||
return { success: true, project: proj };
|
||||
}
|
||||
}
|
||||
|
||||
updateConfiguredProject(project: Project) {
|
||||
if (!this.host.fileExists(project.projectFilename)) {
|
||||
this.log("Config file deleted");
|
||||
this.removeConfiguredProject(project);
|
||||
}
|
||||
else {
|
||||
let { succeeded, projectOptions, error } = this.configFileToProjectOptions(project.projectFilename);
|
||||
if (!succeeded) {
|
||||
return error;
|
||||
}
|
||||
else {
|
||||
return { errorMsg: "no files found" };
|
||||
let oldFileNames = project.compilerService.host.roots.map(info => info.fileName);
|
||||
let newFileNames = projectOptions.files;
|
||||
let fileNamesToRemove = oldFileNames.filter(f => newFileNames.indexOf(f) < 0);
|
||||
let fileNamesToAdd = newFileNames.filter(f => oldFileNames.indexOf(f) < 0);
|
||||
|
||||
for (let fileName of fileNamesToRemove) {
|
||||
let info = this.getScriptInfo(fileName);
|
||||
project.removeRoot(info);
|
||||
}
|
||||
|
||||
for (let fileName of fileNamesToAdd) {
|
||||
let info = this.getScriptInfo(fileName);
|
||||
if (!info) {
|
||||
info = this.openFile(fileName, false);
|
||||
}
|
||||
else {
|
||||
// if the root file was opened by client, it would belong to either
|
||||
// openFileRoots or openFileReferenced.
|
||||
if (info.isOpen) {
|
||||
if (this.openFileRoots.indexOf(info) >= 0) {
|
||||
this.openFileRoots = copyListRemovingItem(info, this.openFileRoots);
|
||||
}
|
||||
if (this.openFilesReferenced.indexOf(info) >= 0) {
|
||||
this.openFilesReferenced = copyListRemovingItem(info, this.openFilesReferenced);
|
||||
}
|
||||
this.openFileRootsConfigured.push(info);
|
||||
}
|
||||
}
|
||||
project.addRoot(info);
|
||||
}
|
||||
|
||||
project.setProjectOptions(projectOptions);
|
||||
project.finishGraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -990,6 +1183,7 @@ namespace ts.server {
|
||||
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
PlaceOpenBraceOnNewLineForFunctions: false,
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
||||
}
|
||||
|
||||
Vendored
+9
@@ -31,6 +31,12 @@ declare namespace ts.server.protocol {
|
||||
*/
|
||||
arguments?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to reload the project structure for all the opened files
|
||||
*/
|
||||
export interface ReloadProjectsRequest extends Message {
|
||||
}
|
||||
|
||||
/**
|
||||
* Server-initiated event message
|
||||
@@ -452,6 +458,9 @@ declare namespace ts.server.protocol {
|
||||
|
||||
/** Defines space handling after opening and before closing non empty parenthesis. Default value is false. */
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
|
||||
/** Defines space handling after opening and before closing non empty brackets. Default value is false. */
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
|
||||
/** Defines whether an open brace is put onto a new line for functions or not. Default value is false. */
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace ts.server {
|
||||
export const SignatureHelp = "signatureHelp";
|
||||
export const TypeDefinition = "typeDefinition";
|
||||
export const ProjectInfo = "projectInfo";
|
||||
export const ReloadProjects = "reloadProjects";
|
||||
export const Unknown = "unknown";
|
||||
}
|
||||
|
||||
@@ -226,6 +227,10 @@ namespace ts.server {
|
||||
this.syntacticCheck(file, project);
|
||||
this.semanticCheck(file, project);
|
||||
}
|
||||
|
||||
private reloadProjects() {
|
||||
this.projectService.reloadProjects();
|
||||
}
|
||||
|
||||
private updateProjectStructure(seq: number, matchSeq: (seq: number) => boolean, ms = 1500) {
|
||||
setTimeout(() => {
|
||||
@@ -1033,6 +1038,10 @@ namespace ts.server {
|
||||
var { file, needFileNameList } = <protocol.ProjectInfoRequestArgs>request.arguments;
|
||||
return {response: this.getProjectInfo(file, needFileNameList), responseRequired: true};
|
||||
},
|
||||
[CommandNames.ReloadProjects]: (request: protocol.ReloadProjectsRequest) => {
|
||||
this.reloadProjects();
|
||||
return {responseRequired: false};
|
||||
}
|
||||
};
|
||||
public addProtocolHandler(command: string, handler: (request: protocol.Request) => {response?: any, responseRequired: boolean}) {
|
||||
if (this.handlers[command]) {
|
||||
|
||||
@@ -39,12 +39,12 @@ namespace ts.formatting {
|
||||
public SpaceBetweenCloseBraceAndWhile: Rule;
|
||||
public NoSpaceAfterCloseBrace: Rule;
|
||||
|
||||
// No space for indexer and dot
|
||||
// No space for dot
|
||||
public NoSpaceBeforeDot: Rule;
|
||||
public NoSpaceAfterDot: Rule;
|
||||
|
||||
// No space before and after indexer
|
||||
public NoSpaceBeforeOpenBracket: Rule;
|
||||
public NoSpaceAfterOpenBracket: Rule;
|
||||
public NoSpaceBeforeCloseBracket: Rule;
|
||||
public NoSpaceAfterCloseBracket: Rule;
|
||||
|
||||
// Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}.
|
||||
@@ -191,6 +191,13 @@ namespace ts.formatting {
|
||||
public NoSpaceAfterOpenParen: Rule;
|
||||
public NoSpaceBeforeCloseParen: Rule;
|
||||
|
||||
// Insert space after opening and before closing nonempty brackets
|
||||
public SpaceAfterOpenBracket: Rule;
|
||||
public SpaceBeforeCloseBracket: Rule;
|
||||
public NoSpaceBetweenBrackets: Rule;
|
||||
public NoSpaceAfterOpenBracket: Rule;
|
||||
public NoSpaceBeforeCloseBracket: Rule;
|
||||
|
||||
// Insert space after function keyword for anonymous functions
|
||||
public SpaceAfterAnonymousFunctionKeyword: Rule;
|
||||
public NoSpaceAfterAnonymousFunctionKeyword: Rule;
|
||||
@@ -232,13 +239,13 @@ namespace ts.formatting {
|
||||
this.SpaceBetweenCloseBraceAndWhile = new Rule(RuleDescriptor.create1(SyntaxKind.CloseBraceToken, SyntaxKind.WhileKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken, SyntaxKind.CommaToken, SyntaxKind.SemicolonToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// No space for indexer and dot
|
||||
// No space for dot
|
||||
this.NoSpaceBeforeDot = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.DotToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterDot = new Rule(RuleDescriptor.create3(SyntaxKind.DotToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// No space before and after indexer
|
||||
this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext ), RuleAction.Delete));
|
||||
|
||||
// Place a space before open brace in a function declaration
|
||||
this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments;
|
||||
@@ -405,8 +412,8 @@ namespace ts.formatting {
|
||||
this.NoSpaceBeforeSemicolon,
|
||||
this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock,
|
||||
this.NoSpaceBeforeComma,
|
||||
this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket,
|
||||
this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket,
|
||||
this.NoSpaceBeforeOpenBracket,
|
||||
this.NoSpaceAfterCloseBracket,
|
||||
this.SpaceAfterSemicolon,
|
||||
this.NoSpaceBeforeOpenParenInFuncDecl,
|
||||
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
|
||||
@@ -451,6 +458,13 @@ namespace ts.formatting {
|
||||
this.NoSpaceAfterOpenParen = new Rule(RuleDescriptor.create3(SyntaxKind.OpenParenToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseParen = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// Insert space after opening and before closing nonempty brackets
|
||||
this.SpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.SpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceBetweenBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// Insert space after function keyword for anonymous functions
|
||||
this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
|
||||
this.NoSpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Delete));
|
||||
@@ -715,6 +729,7 @@ namespace ts.formatting {
|
||||
case SyntaxKind.TypeReference:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
@@ -725,6 +740,7 @@ namespace ts.formatting {
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -71,6 +71,17 @@ namespace ts.formatting {
|
||||
rules.push(this.globalRules.NoSpaceBetweenParens);
|
||||
}
|
||||
|
||||
if ( options.InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ) {
|
||||
rules.push( this.globalRules.SpaceAfterOpenBracket );
|
||||
rules.push( this.globalRules.SpaceBeforeCloseBracket );
|
||||
rules.push( this.globalRules.NoSpaceBetweenBrackets );
|
||||
}
|
||||
else {
|
||||
rules.push( this.globalRules.NoSpaceAfterOpenBracket );
|
||||
rules.push( this.globalRules.NoSpaceBeforeCloseBracket );
|
||||
rules.push( this.globalRules.NoSpaceBetweenBrackets );
|
||||
}
|
||||
|
||||
if (options.InsertSpaceAfterSemicolonInForStatements) {
|
||||
rules.push(this.globalRules.SpaceAfterSemicolonInFor);
|
||||
}
|
||||
|
||||
@@ -428,6 +428,7 @@ namespace ts.formatting {
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.JsxElement:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
+280
-134
File diff suppressed because it is too large
Load Diff
+31
-3
@@ -60,10 +60,12 @@ namespace ts {
|
||||
getNewLine?(): string;
|
||||
getProjectVersion?(): string;
|
||||
useCaseSensitiveFileNames?(): boolean;
|
||||
|
||||
getModuleResolutionsForFile?(fileName: string): string;
|
||||
}
|
||||
|
||||
/** Public interface of the the of a config service shim instance.*/
|
||||
export interface CoreServicesShimHost extends Logger {
|
||||
export interface CoreServicesShimHost extends Logger, ModuleResolutionHost {
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type: string[]
|
||||
*
|
||||
@@ -270,8 +272,18 @@ namespace ts {
|
||||
private files: string[];
|
||||
private loggingEnabled = false;
|
||||
private tracingEnabled = false;
|
||||
|
||||
|
||||
public resolveModuleNames: (moduleName: string[], containingFile: string) => string[];
|
||||
|
||||
constructor(private shimHost: LanguageServiceShimHost) {
|
||||
// if shimHost is a COM object then property check will become method call with no arguments.
|
||||
// 'in' does not have this effect.
|
||||
if ("getModuleResolutionsForFile" in this.shimHost) {
|
||||
this.resolveModuleNames = (moduleNames: string[], containingFile: string) => {
|
||||
let resolutionsInFile = <Map<string>>JSON.parse(this.shimHost.getModuleResolutionsForFile(containingFile));
|
||||
return map(moduleNames, name => lookUp(resolutionsInFile, name));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public log(s: string): void {
|
||||
@@ -410,6 +422,14 @@ namespace ts {
|
||||
}
|
||||
return JSON.parse(encoded);
|
||||
}
|
||||
|
||||
public fileExists(fileName: string): boolean {
|
||||
return this.shimHost.fileExists(fileName);
|
||||
}
|
||||
|
||||
public readFile(fileName: string): string {
|
||||
return this.shimHost.readFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any {
|
||||
@@ -918,6 +938,13 @@ namespace ts {
|
||||
private forwardJSONCall(actionDescription: string, action: () => any): any {
|
||||
return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance);
|
||||
}
|
||||
|
||||
public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string {
|
||||
return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => {
|
||||
let compilerOptions = <CompilerOptions>JSON.parse(compilerOptionsJson);
|
||||
return resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host);
|
||||
});
|
||||
}
|
||||
|
||||
public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {
|
||||
return this.forwardJSONCall(
|
||||
@@ -927,6 +954,7 @@ namespace ts {
|
||||
var convertResult = {
|
||||
referencedFiles: <IFileReference[]>[],
|
||||
importedFiles: <IFileReference[]>[],
|
||||
ambientExternalModules: result.ambientExternalModules,
|
||||
isLibFile: result.isLibFile
|
||||
};
|
||||
|
||||
@@ -1069,4 +1097,4 @@ module TypeScript.Services {
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
let toolsVersion = "1.5";
|
||||
const toolsVersion = "1.6";
|
||||
|
||||
@@ -469,6 +469,39 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the corresponding JSDocTag node if the position is in a jsDoc comment
|
||||
*/
|
||||
export function getJsDocTagAtPosition(sourceFile: SourceFile, position: number): JSDocTag {
|
||||
let node = ts.getTokenAtPosition(sourceFile, position);
|
||||
if (isToken(node)) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.VarKeyword:
|
||||
case SyntaxKind.LetKeyword:
|
||||
case SyntaxKind.ConstKeyword:
|
||||
// if the current token is var, let or const, skip the VariableDeclarationList
|
||||
node = node.parent === undefined ? undefined : node.parent.parent;
|
||||
break;
|
||||
default:
|
||||
node = node.parent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (node) {
|
||||
let jsDocComment = node.jsDocComment;
|
||||
if (jsDocComment) {
|
||||
for (let tag of jsDocComment.tags) {
|
||||
if (tag.pos <= position && position <= tag.end) {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function nodeHasTokens(n: Node): boolean {
|
||||
// If we have a token or node that has a non-zero width, it must have tokens.
|
||||
// Note, that getWidth() does not take trivia into account.
|
||||
@@ -640,7 +673,6 @@ namespace ts {
|
||||
else if (flags & SymbolFlags.TypeAlias) { return SymbolDisplayPartKind.aliasName; }
|
||||
else if (flags & SymbolFlags.Alias) { return SymbolDisplayPartKind.aliasName; }
|
||||
|
||||
|
||||
return SymbolDisplayPartKind.text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user