Merge branch 'master' into tsbuild

This commit is contained in:
Ryan Cavanaugh
2018-06-05 14:55:51 -07:00
1932 changed files with 64966 additions and 53048 deletions
+52 -31
View File
@@ -1698,6 +1698,7 @@ namespace ts {
symbol.parent = container.symbol;
}
addDeclarationToSymbol(symbol, node, symbolFlags);
return symbol;
}
function bindBlockScopedDeclaration(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
@@ -2317,13 +2318,11 @@ namespace ts {
// expression is the declaration
setCommonJsModuleIndicator(node);
const lhs = node.left as PropertyAccessEntityNameExpression;
const symbol = forEachIdentifierInEntityName(lhs.expression, (id, original) => {
if (!original) {
return undefined;
const symbol = forEachIdentifierInEntityName(lhs.expression, /*parent*/ undefined, (id, symbol) => {
if (symbol) {
addDeclarationToSymbol(symbol, id, SymbolFlags.Module | SymbolFlags.JSContainer);
}
const s = getJSInitializerSymbol(original)!;
addDeclarationToSymbol(s, id, SymbolFlags.Module | SymbolFlags.JSContainer);
return s;
return symbol;
});
if (symbol) {
const flags = isClassExpression(node.right) ?
@@ -2359,12 +2358,12 @@ namespace ts {
switch (thisContainer.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
let constructorSymbol = thisContainer.symbol;
let constructorSymbol: Symbol | undefined = thisContainer.symbol;
// For `f.prototype.m = function() { this.x = 0; }`, `this.x = 0` should modify `f`'s members, not the function expression.
if (isBinaryExpression(thisContainer.parent) && thisContainer.parent.operatorToken.kind === SyntaxKind.EqualsToken) {
const l = thisContainer.parent.left;
if (isPropertyAccessEntityNameExpression(l) && isPrototypeAccess(l.expression)) {
constructorSymbol = getJSInitializerSymbolFromName(l.expression.expression, thisParentContainer)!;
constructorSymbol = lookupSymbolForPropertyAccess(l.expression.expression, thisParentContainer);
}
}
@@ -2463,46 +2462,68 @@ namespace ts {
bindPropertyAssignment(node.expression, node, /*isPrototypeProperty*/ false);
}
function getJSInitializerSymbolFromName(name: EntityNameExpression, lookupContainer?: Node): Symbol | undefined {
return getJSInitializerSymbol(lookupSymbolForPropertyAccess(name, lookupContainer));
}
function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
let symbol = getJSInitializerSymbolFromName(name);
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
const isToplevelNamespaceableInitializer = isBinaryExpression(propertyAccess.parent)
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile &&
!!getJavascriptInitializer(getInitializerOfBinaryExpression(propertyAccess.parent), isPrototypeAccess(propertyAccess.parent.left))
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
if (!isPrototypeProperty && (!symbol || !(symbol.flags & SymbolFlags.Namespace)) && isToplevelNamespaceableInitializer) {
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevelNamespaceableInitializer) {
// make symbols or add declarations for intermediate containers
const flags = SymbolFlags.Module | SymbolFlags.JSContainer;
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.JSContainer;
forEachIdentifierInEntityName(propertyAccess.expression, (id, original) => {
if (original) {
// Note: add declaration to original symbol, not the special-syntax's symbol, so that namespaces work for type lookup
addDeclarationToSymbol(original, id, flags);
return original;
namespaceSymbol = forEachIdentifierInEntityName(propertyAccess.expression, namespaceSymbol, (id, symbol, parent) => {
if (symbol) {
addDeclarationToSymbol(symbol, id, flags);
return symbol;
}
else {
return symbol = declareSymbol(symbol ? symbol.exports! : container.locals!, symbol, id, flags, excludeFlags);
return declareSymbol(parent ? parent.exports! : container.locals!, parent, id, flags, excludeFlags);
}
});
}
if (!symbol || !(symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule | SymbolFlags.ObjectLiteral))) {
if (!namespaceSymbol || !isJavascriptContainer(namespaceSymbol)) {
return;
}
// Set up the members collection if it doesn't exist already
const symbolTable = isPrototypeProperty ?
(symbol.members || (symbol.members = createSymbolTable())) :
(symbol.exports || (symbol.exports = createSymbolTable()));
(namespaceSymbol.members || (namespaceSymbol.members = createSymbolTable())) :
(namespaceSymbol.exports || (namespaceSymbol.exports = createSymbolTable()));
// Declare the method/property
const jsContainerFlag = isToplevelNamespaceableInitializer ? SymbolFlags.JSContainer : 0;
const isMethod = isFunctionLikeDeclaration(getAssignedJavascriptInitializer(propertyAccess)!); // TODO: GH#18217
const isMethod = isFunctionLikeDeclaration(getAssignedJavascriptInitializer(propertyAccess)!);
const symbolFlags = (isMethod ? SymbolFlags.Method : SymbolFlags.Property) | jsContainerFlag;
const symbolExcludes = (isMethod ? SymbolFlags.MethodExcludes : SymbolFlags.PropertyExcludes) & ~jsContainerFlag;
declareSymbol(symbolTable, symbol, propertyAccess, symbolFlags, symbolExcludes);
declareSymbol(symbolTable, namespaceSymbol, propertyAccess, symbolFlags, symbolExcludes);
}
/**
* Javascript containers are:
* - Functions
* - classes
* - namespaces
* - variables initialized with function expressions
* - with class expressions
* - with empty object literals
* - with non-empty object literals if assigned to the prototype property
*/
function isJavascriptContainer(symbol: Symbol): boolean {
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule)) {
return true;
}
const node = symbol.valueDeclaration;
const init = !node ? undefined :
isVariableDeclaration(node) ? node.initializer :
isBinaryExpression(node) ? node.right :
isPropertyAccessExpression(node) && isBinaryExpression(node.parent) ? node.parent.right :
undefined;
if (init) {
const isPrototypeAssignment = isPrototypeAccess(isVariableDeclaration(node) ? node.name : isBinaryExpression(node) ? node.left : node);
return !!getJavascriptInitializer(isBinaryExpression(init) && init.operatorToken.kind === SyntaxKind.BarBarToken ? init.right : init, isPrototypeAssignment);
}
return false;
}
function getParentOfBinaryExpression(expr: BinaryExpression) {
@@ -2517,22 +2538,22 @@ namespace ts {
return lookupSymbolForNameWorker(lookupContainer, node.escapedText);
}
else {
const symbol = getJSInitializerSymbol(lookupSymbolForPropertyAccess(node.expression));
const symbol = lookupSymbolForPropertyAccess(node.expression);
return symbol && symbol.exports && symbol.exports.get(node.name.escapedText);
}
}
function forEachIdentifierInEntityName(e: EntityNameExpression, action: (e: Identifier, symbol: Symbol | undefined) => Symbol | undefined): Symbol | undefined {
function forEachIdentifierInEntityName(e: EntityNameExpression, parent: Symbol | undefined, action: (e: Identifier, symbol: Symbol | undefined, parent: Symbol | undefined) => Symbol | undefined): Symbol | undefined {
if (isExportsOrModuleExportsOrAlias(file, e)) {
return file.symbol;
}
else if (isIdentifier(e)) {
return action(e, lookupSymbolForPropertyAccess(e));
return action(e, lookupSymbolForPropertyAccess(e), parent);
}
else {
const s = getJSInitializerSymbol(forEachIdentifierInEntityName(e.expression, action));
const s = forEachIdentifierInEntityName(e.expression, parent, action);
if (!s || !s.exports) return Debug.fail();
return action(e.name, s.exports.get(e.name.escapedText));
return action(e.name, s.exports.get(e.name.escapedText), s);
}
}
@@ -2596,7 +2617,7 @@ namespace ts {
bindBlockScopedVariableDeclaration(node);
}
else if (isParameterDeclaration(node)) {
// It is safe to walk up parent chain to find whether the node is a destructing parameter declaration
// It is safe to walk up parent chain to find whether the node is a destructuring parameter declaration
// because its parent chain has already been set up, since parents are set before descending into children.
//
// If node is a binding element in parameter declaration, we need to use ParameterExcludes.
+6 -6
View File
@@ -549,8 +549,8 @@ namespace ts {
* Create the builder to manage semantic diagnostics and cache them
*/
export function createSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): SemanticDiagnosticsBuilderProgram;
export function createSemanticDiagnosticsBuilderProgram(rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): SemanticDiagnosticsBuilderProgram;
export function createSemanticDiagnosticsBuilderProgram(newProgramOrRootNames: Program | ReadonlyArray<string>, hostOrOptions: BuilderProgramHost | CompilerOptions, oldProgramOrHost?: CompilerHost | SemanticDiagnosticsBuilderProgram, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray<Diagnostic> | SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>) {
export function createSemanticDiagnosticsBuilderProgram(rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): SemanticDiagnosticsBuilderProgram;
export function createSemanticDiagnosticsBuilderProgram(newProgramOrRootNames: Program | ReadonlyArray<string> | undefined, hostOrOptions: BuilderProgramHost | CompilerOptions | undefined, oldProgramOrHost?: CompilerHost | SemanticDiagnosticsBuilderProgram, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray<Diagnostic> | SemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>) {
return createBuilderProgram(BuilderProgramKind.SemanticDiagnosticsBuilderProgram, getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics));
}
@@ -559,8 +559,8 @@ namespace ts {
* to emit the those files and manage semantic diagnostics cache as well
*/
export function createEmitAndSemanticDiagnosticsBuilderProgram(newProgram: Program, host: BuilderProgramHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): EmitAndSemanticDiagnosticsBuilderProgram;
export function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): EmitAndSemanticDiagnosticsBuilderProgram;
export function createEmitAndSemanticDiagnosticsBuilderProgram(newProgramOrRootNames: Program | ReadonlyArray<string>, hostOrOptions: BuilderProgramHost | CompilerOptions, oldProgramOrHost?: CompilerHost | EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray<Diagnostic> | EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>) {
export function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): EmitAndSemanticDiagnosticsBuilderProgram;
export function createEmitAndSemanticDiagnosticsBuilderProgram(newProgramOrRootNames: Program | ReadonlyArray<string> | undefined, hostOrOptions: BuilderProgramHost | CompilerOptions | undefined, oldProgramOrHost?: CompilerHost | EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray<Diagnostic> | EmitAndSemanticDiagnosticsBuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>) {
return createBuilderProgram(BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram, getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics));
}
@@ -568,8 +568,8 @@ namespace ts {
* Creates a builder thats just abstraction over program and can be used with watch
*/
export function createAbstractBuilder(newProgram: Program, host: BuilderProgramHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): BuilderProgram;
export function createAbstractBuilder(rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): BuilderProgram;
export function createAbstractBuilder(newProgramOrRootNames: Program | ReadonlyArray<string>, hostOrOptions: BuilderProgramHost | CompilerOptions, oldProgramOrHost?: CompilerHost | BuilderProgram, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray<Diagnostic> | BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): BuilderProgram {
export function createAbstractBuilder(rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): BuilderProgram;
export function createAbstractBuilder(newProgramOrRootNames: Program | ReadonlyArray<string> | undefined, hostOrOptions: BuilderProgramHost | CompilerOptions | undefined, oldProgramOrHost?: CompilerHost | BuilderProgram, configFileParsingDiagnosticsOrOldProgram?: ReadonlyArray<Diagnostic> | BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): BuilderProgram {
const { newProgram: program } = getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics);
return {
// Only return program, all other methods are not implemented
+155 -178
View File
@@ -310,21 +310,34 @@ namespace ts {
const node = getParseTreeNode(nodeIn, isTypeNode);
return node && getTypeArgumentConstraint(node);
},
getSuggestionDiagnostics: (file, ct) => {
let diagnostics: DiagnosticWithLocation[] | undefined;
try {
// Record the cancellation token so it can be checked later on during checkSourceElement.
// Do this in a finally block so we can ensure that it gets reset back to nothing after
// this call is done.
cancellationToken = ct;
getSuggestionDiagnostics: file => {
return (suggestionDiagnostics.get(file.fileName) || emptyArray).concat(getUnusedDiagnostics());
function getUnusedDiagnostics(): ReadonlyArray<DiagnosticWithLocation> {
if (file.isDeclarationFile) return emptyArray;
// Ensure file is type checked
checkSourceFile(file);
const diagnostics: DiagnosticWithLocation[] = [];
Debug.assert(!!(getNodeLinks(file).flags & NodeCheckFlags.TypeChecked));
diagnostics = addRange(diagnostics, suggestionDiagnostics.get(file.fileName));
if (!file.isDeclarationFile && (!unusedIsError(UnusedKind.Local) || !unusedIsError(UnusedKind.Parameter))) {
addUnusedDiagnostics();
}
return diagnostics || emptyArray;
}
finally {
cancellationToken = undefined;
}
function addUnusedDiagnostics() {
checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), (kind, diag) => {
if (!unusedIsError(kind)) {
diagnostics.push({ ...diag, category: DiagnosticCategory.Suggestion });
(diagnostics || (diagnostics = [])).push({ ...diag, category: DiagnosticCategory.Suggestion });
}
});
return diagnostics;
}
},
@@ -889,11 +902,17 @@ namespace ts {
return result;
}
function mergeSymbol(target: Symbol, source: Symbol) {
/**
* Note: if target is transient, then it is mutable, and mergeSymbol with both mutate and return it.
* If target is not transient, mergeSymbol will produce a transient clone, mutate that and return it.
*/
function mergeSymbol(target: Symbol, source: Symbol): Symbol {
if (!(target.flags & getExcludedSymbolFlags(source.flags)) ||
(source.flags | target.flags) & SymbolFlags.JSContainer) {
const targetValueDeclaration = target.valueDeclaration;
Debug.assert(!!(target.flags & SymbolFlags.Transient));
Debug.assert(source !== target);
if (!(target.flags & SymbolFlags.Transient)) {
target = cloneSymbol(target);
}
// Javascript static-property-assignment declarations always merge, even though they are also values
if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) {
// reset flag when merging instantiated module into value module that has only const enums
@@ -915,18 +934,6 @@ namespace ts {
if (!target.exports) target.exports = createSymbolTable();
mergeSymbolTable(target.exports, source.exports);
}
if ((source.flags | target.flags) & SymbolFlags.JSContainer) {
const sourceInitializer = getJSInitializerSymbol(source)!;
const init = getDeclaredJavascriptInitializer(targetValueDeclaration) || getAssignedJavascriptInitializer(targetValueDeclaration);
let targetInitializer = init && init.symbol ? init.symbol : target;
if (!(targetInitializer.flags & SymbolFlags.Transient)) {
const mergedInitializer = getMergedSymbol(targetInitializer);
targetInitializer = mergedInitializer === targetInitializer ? cloneSymbol(targetInitializer) : mergedInitializer;
}
if (sourceInitializer !== source || targetInitializer !== target) {
mergeSymbol(targetInitializer, sourceInitializer);
}
}
recordMergedSymbol(target, source);
}
else if (target.flags & SymbolFlags.NamespaceModule) {
@@ -947,11 +954,12 @@ namespace ts {
error(errorNode, message, symbolToString(source));
});
}
return target;
}
function combineSymbolTables(first: SymbolTable | undefined, second: SymbolTable | undefined): SymbolTable | undefined {
if (!first || first.size === 0) return second;
if (!second || second.size === 0) return first;
if (!hasEntries(first)) return second;
if (!hasEntries(second)) return first;
const combined = createSymbolTable();
mergeSymbolTable(combined, first);
mergeSymbolTable(combined, second);
@@ -960,17 +968,7 @@ namespace ts {
function mergeSymbolTable(target: SymbolTable, source: SymbolTable) {
source.forEach((sourceSymbol, id) => {
let targetSymbol = target.get(id);
if (!targetSymbol) {
target.set(id, sourceSymbol);
}
else {
if (!(targetSymbol.flags & SymbolFlags.Transient)) {
targetSymbol = cloneSymbol(targetSymbol);
target.set(id, targetSymbol);
}
mergeSymbol(targetSymbol, sourceSymbol);
}
target.set(id, target.has(id) ? mergeSymbol(target.get(id)!, sourceSymbol) : sourceSymbol);
});
}
@@ -1000,10 +998,7 @@ namespace ts {
// obtain item referenced by 'export='
mainModule = resolveExternalModuleSymbol(mainModule);
if (mainModule.flags & SymbolFlags.Namespace) {
// if module symbol has already been merged - it is safe to use it.
// otherwise clone it
mainModule = mainModule.flags & SymbolFlags.Transient ? mainModule : cloneSymbol(mainModule);
mergeSymbol(mainModule, moduleAugmentation.symbol);
mainModule = mergeSymbol(mainModule, moduleAugmentation.symbol);
}
else {
// moduleName will be a StringLiteral since this is not `declare global`.
@@ -1463,9 +1458,8 @@ namespace ts {
case SyntaxKind.JSDocTypedefTag:
case SyntaxKind.JSDocCallbackTag:
// js type aliases do not resolve names from their host, so skip past it
lastLocation = location;
location = getJSDocHost(location).parent;
continue;
location = getJSDocHost(location);
break;
}
if (isSelfReferenceLocation(location)) {
lastSelfReferenceLocation = location;
@@ -1789,7 +1783,7 @@ namespace ts {
}
function isSyntacticDefault(node: Node) {
return ((isExportAssignment(node) && !node.isExportEquals) || hasModifier(node, ModifierFlags.Default));
return ((isExportAssignment(node) && !node.isExportEquals) || hasModifier(node, ModifierFlags.Default) || isExportSpecifier(node));
}
function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean) {
@@ -2124,14 +2118,6 @@ namespace ts {
return namespace;
}
if (isInJavaScriptFile(name)) {
const initializer = getDeclaredJavascriptInitializer(namespace.valueDeclaration) || getAssignedJavascriptInitializer(namespace.valueDeclaration);
if (initializer) {
namespace = getSymbolOfNode(initializer)!;
}
// Currently, IIFEs may not have a symbol and we don't know about their contents. Give up in this case.
if (!namespace) {
return undefined;
}
if (namespace.valueDeclaration &&
isVariableDeclaration(namespace.valueDeclaration) &&
namespace.valueDeclaration.initializer &&
@@ -2324,14 +2310,7 @@ namespace ts {
}
moduleSymbol.exports!.forEach((s, name) => {
if (name === InternalSymbolName.ExportEquals) return;
if (!merged.exports!.has(name)) {
merged.exports!.set(name, s);
}
else {
const ms = cloneSymbol(merged.exports!.get(name)!);
mergeSymbol(ms, s);
merged.exports!.set(name, ms);
}
merged.exports!.set(name, merged.exports!.has(name) ? mergeSymbol(merged.exports!.get(name)!, s) : s);
});
return merged;
}
@@ -2533,6 +2512,46 @@ namespace ts {
return getMergedSymbol(symbol.parent && getLateBoundSymbol(symbol.parent));
}
/**
* Attempts to find the symbol corresponding to the container a symbol is in - usually this
* is just its' `.parent`, but for locals, this value is `undefined`
*/
function getContainerOfSymbol(symbol: Symbol): Symbol | undefined {
const container = getParentOfSymbol(symbol);
if (container) {
return container;
}
const candidate = forEach(symbol.declarations, d => !isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined);
if (!candidate) {
return undefined;
}
const alias = getAliasForSymbolInContainer(candidate, symbol);
return alias ? candidate : undefined;
}
function getAliasForSymbolInContainer(container: Symbol, symbol: Symbol) {
if (container === getParentOfSymbol(symbol)) {
// fast path, `symbol` is either already the alias or isn't aliased
return symbol;
}
const exports = getExportsOfSymbol(container);
const quick = exports.get(symbol.escapedName);
if (quick && symbolRefersToTarget(quick)) {
return quick;
}
return forEachEntry(exports, exported => {
if (symbolRefersToTarget(exported)) {
return exported;
}
});
function symbolRefersToTarget(s: Symbol) {
if (s === symbol || resolveSymbol(s) === symbol || resolveSymbol(s) === resolveSymbol(symbol)) {
return s;
}
}
}
function getExportSymbolOfValueSymbolIfExported(symbol: Symbol): Symbol;
function getExportSymbolOfValueSymbolIfExported(symbol: Symbol | undefined): Symbol | undefined;
function getExportSymbolOfValueSymbolIfExported(symbol: Symbol | undefined): Symbol | undefined {
@@ -2838,7 +2857,7 @@ namespace ts {
// But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
meaningToLook = getQualifiedLeftMeaning(meaning);
symbol = getParentOfSymbol(symbol);
symbol = getContainerOfSymbol(symbol);
}
// This could be a symbol that is not exported in the external module
@@ -3729,12 +3748,12 @@ namespace ts {
needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
// Go up and add our parent.
const parent = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol);
const parent = getContainerOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol);
if (parent) {
const parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false);
if (parentChain) {
parentSymbol = parent;
accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [symbol]);
accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]);
}
}
}
@@ -4065,7 +4084,8 @@ namespace ts {
// ambient module, just use declaration/symbol name (fallthrough)
}
else {
return `"${getResolvedExternalModuleName(context!.tracker.moduleResolverHost!, file, getSourceFileOfNode(getOriginalNode(context!.enclosingDeclaration)))}"`;
const contextFile = getSourceFileOfNode(getOriginalNode(context!.enclosingDeclaration))!;
return `"${file.moduleName || moduleSpecifiers.getModuleSpecifier(compilerOptions, contextFile, contextFile.path, file.path, context!.tracker.moduleResolverHost!)}"`;
}
}
const declaration = symbol.declarations[0];
@@ -4926,6 +4946,8 @@ namespace ts {
else if (isJSDocPropertyLikeTag(declaration)
|| isPropertyAccessExpression(declaration)
|| isIdentifier(declaration)
|| isClassDeclaration(declaration)
|| isFunctionDeclaration(declaration)
|| (isMethodDeclaration(declaration) && !isObjectLiteralMethod(declaration))
|| isMethodSignature(declaration)) {
@@ -4955,7 +4977,7 @@ namespace ts {
type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true);
}
else {
return Debug.fail("Unhandled declaration kind! " + Debug.showSyntaxKind(declaration));
return Debug.fail("Unhandled declaration kind! " + Debug.showSyntaxKind(declaration) + " for " + Debug.showSymbol(symbol));
}
if (!popTypeResolution()) {
@@ -5057,8 +5079,25 @@ namespace ts {
}
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
const links = getSymbolLinks(symbol);
let links = getSymbolLinks(symbol);
if (!links.type) {
const jsDeclaration = getDeclarationOfJSInitializer(symbol.valueDeclaration);
if (jsDeclaration) {
const jsSymbol = getSymbolOfNode(jsDeclaration);
if (jsSymbol && (hasEntries(jsSymbol.exports) || hasEntries(jsSymbol.members))) {
symbol = cloneSymbol(symbol);
// note:we overwrite links because we just cloned the symbol
links = symbol as TransientSymbol;
if (hasEntries(jsSymbol.exports)) {
symbol.exports = symbol.exports || createSymbolTable();
mergeSymbolTable(symbol.exports, jsSymbol.exports);
}
if (hasEntries(jsSymbol.members)) {
symbol.members = symbol.members || createSymbolTable();
mergeSymbolTable(symbol.members, jsSymbol.members);
}
}
}
if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol(symbol)) {
links.type = anyType;
}
@@ -7406,18 +7445,17 @@ namespace ts {
const result: Signature[] = [];
for (let i = 0; i < symbol.declarations.length; i++) {
const decl = symbol.declarations[i];
const node = isPropertyAccessExpression(decl) ? getAssignedJavascriptInitializer(decl)! : decl; // TODO: GH#18217
if (!isFunctionLike(node)) continue;
if (!isFunctionLike(decl)) continue;
// Don't include signature if node is the implementation of an overloaded function. A node is considered
// an implementation node if it has a body and the previous node is of the same kind and immediately
// precedes the implementation node (i.e. has the same parent and ends where the implementation starts).
if (i > 0 && (node as FunctionLikeDeclaration).body) {
if (i > 0 && (decl as FunctionLikeDeclaration).body) {
const previous = symbol.declarations[i - 1];
if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) {
if (decl.parent === previous.parent && decl.kind === previous.kind && decl.pos === previous.end) {
continue;
}
}
result.push(getSignatureFromDeclaration(node));
result.push(getSignatureFromDeclaration(decl));
}
return result;
}
@@ -8844,7 +8882,9 @@ namespace ts {
return type.simplified === circularConstraintType ? type : type.simplified;
}
type.simplified = circularConstraintType;
const objectType = type.objectType;
// We recursively simplify the object type as it may in turn be an indexed access type. For example, with
// '{ [P in T]: { [Q in U]: number } }[T][U]' we want to first simplify the inner indexed access type.
const objectType = getSimplifiedType(type.objectType);
if (objectType.flags & TypeFlags.Intersection && isGenericObjectType(objectType)) {
// Given an indexed access type T[K], if T is an intersection containing one or more generic types and one or
// more object types with only a string index signature, e.g. '(U & V & { [x: string]: D })[K]', return a
@@ -9165,12 +9205,13 @@ namespace ts {
}
function resolveImportSymbolType(node: ImportTypeNode, links: NodeLinks, symbol: Symbol, meaning: SymbolFlags) {
links.resolvedSymbol = symbol;
const resolvedSymbol = resolveSymbol(symbol);
links.resolvedSymbol = resolvedSymbol;
if (meaning === SymbolFlags.Value) {
return links.resolvedType = getTypeOfSymbol(symbol);
return links.resolvedType = getTypeOfSymbol(symbol); // intentionally doesn't use resolved symbol so type is cached as expected on the alias
}
else {
return links.resolvedType = getTypeReferenceType(node, symbol);
return links.resolvedType = getTypeReferenceType(node, resolvedSymbol); // getTypeReferenceType doesn't handle aliases - it must get the resolved symbol
}
}
@@ -14075,11 +14116,14 @@ namespace ts {
if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) {
assumeTrue = !assumeTrue;
}
if (type.flags & TypeFlags.Any && literal.text === "function") {
return type;
}
if (assumeTrue && !(type.flags & TypeFlags.Union)) {
// We narrow a non-union type to an exact primitive type if the non-union type
// is a supertype of that primitive type. For example, type 'any' can be narrowed
// to one of the primitive types.
const targetType = typeofTypesByName.get(literal.text);
const targetType = literal.text === "function" ? globalFunctionType : typeofTypesByName.get(literal.text);
if (targetType) {
if (isTypeSubtypeOf(targetType, type)) {
return targetType;
@@ -15259,7 +15303,7 @@ namespace ts {
// expression has no contextual type, the right operand is contextually typed by the type of the left operand,
// except for the special case of Javascript declarations of the form `namespace.prop = namespace.prop || {}`
const type = getContextualType(binaryExpression);
return !type && node === right && !getDeclaredJavascriptInitializer(binaryExpression.parent) && !getAssignedJavascriptInitializer(binaryExpression) ?
return !type && node === right && !isDefaultedJavascriptInitializer(binaryExpression) ?
getTypeOfExpression(left) : type;
case SyntaxKind.AmpersandAmpersandToken:
case SyntaxKind.CommaToken:
@@ -15268,6 +15312,7 @@ namespace ts {
return undefined;
}
}
// In an assignment expression, the right operand is contextually typed by the type of the left operand.
// Don't do this for special property assignments to avoid circularity.
function isContextSensitiveAssignment(binaryExpression: BinaryExpression): boolean {
@@ -15935,13 +15980,16 @@ namespace ts {
let hasComputedStringProperty = false;
let hasComputedNumberProperty = false;
if (isInJSFile && node.properties.length === 0) {
// an empty JS object literal that nonetheless has members is a JS namespace
const symbol = getSymbolOfNode(node);
if (symbol.exports) {
propertiesTable = symbol.exports;
symbol.exports.forEach(symbol => propertiesArray.push(getMergedSymbol(symbol)));
return createObjectLiteralType();
if (isInJSFile) {
const decl = getDeclarationOfJSInitializer(node);
if (decl) {
// a JS object literal whose declaration's symbol has exports is a JS namespace
const symbol = getMergedSymbol(decl.symbol);
if (symbol && hasEntries(symbol.exports)) {
propertiesTable = symbol.exports;
symbol.exports.forEach(symbol => propertiesArray.push(getMergedSymbol(symbol)));
return createObjectLiteralType();
}
}
}
propertiesTable = createSymbolTable();
@@ -17335,88 +17383,11 @@ namespace ts {
* and 1 insertion/deletion at 3 characters)
*/
function getSpellingSuggestionForName(name: string, symbols: Symbol[], meaning: SymbolFlags): Symbol | undefined {
const maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
let bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result isn't better than this, don't bother.
let bestCandidate: Symbol | undefined;
let justCheckExactMatches = false;
const nameLowerCase = name.toLowerCase();
for (const candidate of symbols) {
return getSpellingSuggestion(name, symbols, getCandidateName);
function getCandidateName(candidate: Symbol) {
const candidateName = symbolName(candidate);
if (candidateName.charCodeAt(0) === CharacterCodes.doubleQuote
|| !(candidate.flags & meaning && Math.abs(candidateName.length - nameLowerCase.length) <= maximumLengthDifference)) {
continue;
}
const candidateNameLowerCase = candidateName.toLowerCase();
if (candidateNameLowerCase === nameLowerCase) {
return candidate;
}
if (justCheckExactMatches) {
continue;
}
if (candidateName.length < 3) {
// Don't bother, user would have noticed a 2-character name having an extra character
continue;
}
// Only care about a result better than the best so far.
const distance = levenshteinWithMax(nameLowerCase, candidateNameLowerCase, bestDistance - 1);
if (distance === undefined) {
continue;
}
if (distance < 3) {
justCheckExactMatches = true;
bestCandidate = candidate;
}
else {
Debug.assert(distance < bestDistance); // Else `levenshteinWithMax` should return undefined
bestDistance = distance;
bestCandidate = candidate;
}
return !startsWith(candidateName, "\"") && candidate.flags & meaning ? candidateName : undefined;
}
return bestCandidate;
}
function levenshteinWithMax(s1: string, s2: string, max: number): number | undefined {
let previous = new Array(s2.length + 1);
let current = new Array(s2.length + 1);
/** Represents any value > max. We don't care about the particular value. */
const big = max + 1;
for (let i = 0; i <= s2.length; i++) {
previous[i] = i;
}
for (let i = 1; i <= s1.length; i++) {
const c1 = s1.charCodeAt(i - 1);
const minJ = i > max ? i - max : 1;
const maxJ = s2.length > max + i ? max + i : s2.length;
current[0] = i;
/** Smallest value of the matrix in the ith column. */
let colMin = i;
for (let j = 1; j < minJ; j++) {
current[j] = big;
}
for (let j = minJ; j <= maxJ; j++) {
const dist = c1 === s2.charCodeAt(j - 1)
? previous[j - 1]
: Math.min(/*delete*/ previous[j] + 1, /*insert*/ current[j - 1] + 1, /*substitute*/ previous[j - 1] + 2);
current[j] = dist;
colMin = Math.min(colMin, dist);
}
for (let j = maxJ + 1; j <= s2.length; j++) {
current[j] = big;
}
if (colMin > max) {
// Give up -- everything in this column is > max and it can't get better in future columns.
return undefined;
}
const temp = previous;
previous = current;
current = temp;
}
const res = previous[s2.length];
return res > max ? undefined : res;
}
function markPropertyAsReferenced(prop: Symbol, nodeForCheckWriteOnly: Node | undefined, isThisAccess: boolean) {
@@ -18636,6 +18607,7 @@ namespace ts {
if (node.expression.kind === SyntaxKind.SuperKeyword) {
const superType = checkSuperExpression(node.expression);
if (isTypeAny(superType)) {
forEach(node.arguments, checkExpression); // Still visit arguments so they get marked for visibility, etc
return anySignature;
}
if (superType !== errorType) {
@@ -19043,10 +19015,6 @@ namespace ts {
}
function getJavaScriptClassType(symbol: Symbol): Type | undefined {
const initializer = getDeclaredJavascriptInitializer(symbol.valueDeclaration);
if (initializer) {
symbol = getSymbolOfNode(initializer)!;
}
let inferred: Type | undefined;
if (isJavaScriptConstructor(symbol.valueDeclaration)) {
inferred = getInferredClassType(symbol);
@@ -19157,7 +19125,17 @@ namespace ts {
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) {
return getESSymbolLikeTypeForNode(walkUpParenthesizedExpressions(node.parent));
}
return returnType;
let jsAssignmentType: Type | undefined;
if (isInJavaScriptFile(node)) {
const decl = getDeclarationOfJSInitializer(node);
if (decl) {
const jsSymbol = getSymbolOfNode(decl);
if (jsSymbol && hasEntries(jsSymbol.exports)) {
jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, jsObjectLiteralIndexInfo, undefined);
}
}
}
return jsAssignmentType ? getIntersectionType([returnType, jsAssignmentType]) : returnType;
}
function isSymbolOrSymbolForCall(node: Node) {
@@ -20653,13 +20631,12 @@ namespace ts {
}
function checkDeclarationInitializer(declaration: HasExpressionInitializer) {
const inJs = isInJavaScriptFile(declaration);
const initializer = inJs && getDeclaredJavascriptInitializer(declaration) || declaration.initializer!;
const initializer = getEffectiveInitializer(declaration)!;
const type = getTypeOfExpression(initializer, /*cache*/ true);
const widened = getCombinedNodeFlags(declaration) & NodeFlags.Const ||
(getCombinedModifierFlags(declaration) & ModifierFlags.Readonly && !isParameterPropertyDeclaration(declaration)) ||
isTypeAssertion(initializer) ? type : getWidenedLiteralType(type);
if (inJs) {
if (isInJavaScriptFile(declaration)) {
if (widened.flags & TypeFlags.Nullable) {
if (noImplicitAny) {
reportImplicitAnyError(declaration, anyType);
@@ -22737,7 +22714,7 @@ namespace ts {
function errorUnusedLocal(declaration: Declaration, name: string, addDiagnostic: AddUnusedDiagnostic) {
const node = getNameOfDeclaration(declaration) || declaration;
const message = isTypeDeclaration(declaration) ? Diagnostics._0_is_declared_but_never_used : Diagnostics._0_is_declared_but_its_value_is_never_read;
addDiagnostic(UnusedKind.Local, createDiagnosticForNodeSpan(getSourceFileOfNode(declaration), declaration, node, message, name));
addDiagnostic(UnusedKind.Local, createDiagnosticForNode(node, message, name));
}
function parameterNameStartsWithUnderscore(parameterName: DeclarationName) {
@@ -23285,8 +23262,8 @@ namespace ts {
if (node === symbol.valueDeclaration) {
// Node is the primary declaration of the symbol, just validate the initializer
// Don't validate for-in initializer as it is already an error
if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) {
const initializer = isInJavaScriptFile(node) && getDeclaredJavascriptInitializer(node) || node.initializer;
const initializer = getEffectiveInitializer(node);
if (initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) {
checkTypeAssignableTo(checkExpressionCached(initializer), type, node, /*headMessage*/ undefined);
checkParameterInitializer(node);
}
@@ -28369,9 +28346,9 @@ namespace ts {
}
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
const typeParameters = getEffectiveTypeParameterDeclarations(node);
if (isNodeArray(typeParameters)) {
const { pos, end } = typeParameters;
const jsdocTypeParameters = isInJavaScriptFile(node) && getJSDocTypeParameterDeclarations(node);
if (node.typeParameters || jsdocTypeParameters && jsdocTypeParameters.length) {
const { pos, end } = node.typeParameters || jsdocTypeParameters && jsdocTypeParameters[0] || node;
return grammarErrorAtPos(node, pos, end - pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
}
}
+63 -38
View File
@@ -1,6 +1,66 @@
namespace ts {
/* @internal */
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };
// NOTE: The order here is important to default lib ordering as entries will have the same
// order in the generated program (see `getDefaultLibPriority` in program.ts). This
// order also affects overload resolution when a type declared in one lib is
// augmented in another lib.
const libEntries: [string, string][] = [
// JavaScript only
["es5", "lib.es5.d.ts"],
["es6", "lib.es2015.d.ts"],
["es2015", "lib.es2015.d.ts"],
["es7", "lib.es2016.d.ts"],
["es2016", "lib.es2016.d.ts"],
["es2017", "lib.es2017.d.ts"],
["es2018", "lib.es2018.d.ts"],
["esnext", "lib.esnext.d.ts"],
// Host only
["dom", "lib.dom.d.ts"],
["dom.iterable", "lib.dom.iterable.d.ts"],
["webworker", "lib.webworker.d.ts"],
["webworker.importscripts", "lib.webworker.importscripts.d.ts"],
["scripthost", "lib.scripthost.d.ts"],
// ES2015 Or ESNext By-feature options
["es2015.core", "lib.es2015.core.d.ts"],
["es2015.collection", "lib.es2015.collection.d.ts"],
["es2015.generator", "lib.es2015.generator.d.ts"],
["es2015.iterable", "lib.es2015.iterable.d.ts"],
["es2015.promise", "lib.es2015.promise.d.ts"],
["es2015.proxy", "lib.es2015.proxy.d.ts"],
["es2015.reflect", "lib.es2015.reflect.d.ts"],
["es2015.symbol", "lib.es2015.symbol.d.ts"],
["es2015.symbol.wellknown", "lib.es2015.symbol.wellknown.d.ts"],
["es2016.array.include", "lib.es2016.array.include.d.ts"],
["es2017.object", "lib.es2017.object.d.ts"],
["es2017.sharedmemory", "lib.es2017.sharedmemory.d.ts"],
["es2017.string", "lib.es2017.string.d.ts"],
["es2017.intl", "lib.es2017.intl.d.ts"],
["es2017.typedarrays", "lib.es2017.typedarrays.d.ts"],
["es2018.intl", "lib.es2018.intl.d.ts"],
["es2018.promise", "lib.es2018.promise.d.ts"],
["es2018.regexp", "lib.es2018.regexp.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.symbol", "lib.esnext.symbol.d.ts"],
["esnext.asynciterable", "lib.esnext.asynciterable.d.ts"],
];
/**
* An array of supported "lib" reference file names used to determine the order for inclusion
* when referenced, as well as for spelling suggestions. This ensures the correct ordering for
* overload resolution when a type declared in one lib is extended by another.
*/
/* @internal */
export const libs = libEntries.map(entry => entry[0]);
/**
* A map of lib names to lib files. This map is used both for parsing the "lib" command line
* option as well as for resolving lib reference directives.
*/
/* @internal */
export const libMap = createMapFromEntries(libEntries);
/* @internal */
export const optionDeclarations: CommandLineOption[] = [
// CommandLine only options
@@ -122,43 +182,7 @@ namespace ts {
type: "list",
element: {
name: "lib",
type: createMapFromTemplate({
// JavaScript only
"es5": "lib.es5.d.ts",
"es6": "lib.es2015.d.ts",
"es2015": "lib.es2015.d.ts",
"es7": "lib.es2016.d.ts",
"es2016": "lib.es2016.d.ts",
"es2017": "lib.es2017.d.ts",
"es2018": "lib.es2018.d.ts",
"esnext": "lib.esnext.d.ts",
// Host only
"dom": "lib.dom.d.ts",
"dom.iterable": "lib.dom.iterable.d.ts",
"webworker": "lib.webworker.d.ts",
"scripthost": "lib.scripthost.d.ts",
// ES2015 Or ESNext By-feature options
"es2015.core": "lib.es2015.core.d.ts",
"es2015.collection": "lib.es2015.collection.d.ts",
"es2015.generator": "lib.es2015.generator.d.ts",
"es2015.iterable": "lib.es2015.iterable.d.ts",
"es2015.promise": "lib.es2015.promise.d.ts",
"es2015.proxy": "lib.es2015.proxy.d.ts",
"es2015.reflect": "lib.es2015.reflect.d.ts",
"es2015.symbol": "lib.es2015.symbol.d.ts",
"es2015.symbol.wellknown": "lib.es2015.symbol.wellknown.d.ts",
"es2016.array.include": "lib.es2016.array.include.d.ts",
"es2017.object": "lib.es2017.object.d.ts",
"es2017.sharedmemory": "lib.es2017.sharedmemory.d.ts",
"es2017.string": "lib.es2017.string.d.ts",
"es2017.intl": "lib.es2017.intl.d.ts",
"es2017.typedarrays": "lib.es2017.typedarrays.d.ts",
"es2018.intl": "lib.es2018.intl.d.ts",
"es2018.promise": "lib.es2018.promise.d.ts",
"es2018.regexp": "lib.es2018.regexp.d.ts",
"esnext.array": "lib.esnext.array.d.ts",
"esnext.asynciterable": "lib.esnext.asynciterable.d.ts",
}),
type: libMap
},
showInSimplifiedHelpView: true,
category: Diagnostics.Basic_Options,
@@ -937,7 +961,8 @@ namespace ts {
}
}
function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
/** @internal */
export function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
optionName = optionName.toLowerCase();
const { optionNameMap, shortOptionNames } = getOptionNameMap();
// Try to translate short option names to their full equivalents.
+140 -6
View File
@@ -59,6 +59,14 @@ namespace ts {
return result;
}
export function createMapFromEntries<T>(entries: [string, T][]): Map<T> {
const map = createMap<T>();
for (const [key, value] of entries) {
map.set(key, value);
}
return map;
}
export function createMapFromTemplate<T>(template: MapLike<T>): Map<T> {
const map: Map<T> = new MapCtr<T>();
@@ -169,6 +177,10 @@ namespace ts {
return array ? array.length : 0;
}
export function hasEntries(map: ReadonlyUnderscoreEscapedMap<any> | undefined): map is ReadonlyUnderscoreEscapedMap<any> {
return !!map && !!map.size;
}
/**
* Iterates through 'array' by index and performs the callback on each element of array until the callback
* returns a truthy value, then returns that value.
@@ -1792,7 +1804,7 @@ namespace ts {
* Case-insensitive comparisons compare both strings one code-point at a time using the integer
* value of each code-point after applying `toUpperCase` to each string. We always map both
* strings to their upper-case form as some unicode characters do not properly round-trip to
* lowercase (such as `` (German sharp capital s)).
* lowercase (such as `ẞ` (German sharp capital s)).
*/
export function compareStringsCaseInsensitive(a: string, b: string) {
if (a === b) return Comparison.EqualTo;
@@ -1864,7 +1876,7 @@ namespace ts {
//
// For case insensitive comparisons we always map both strings to their
// upper-case form as some unicode characters do not properly round-trip to
// lowercase (such as `` (German sharp capital s)).
// lowercase (such as `ẞ` (German sharp capital s)).
return (a, b) => compareWithCallback(a, b, compareDictionaryOrder);
function compareDictionaryOrder(a: string, b: string) {
@@ -1989,6 +2001,103 @@ namespace ts {
return text1 ? Comparison.GreaterThan : Comparison.LessThan;
}
/**
* Given a name and a list of names that are *not* equal to the name, return a spelling suggestion if there is one that is close enough.
* Names less than length 3 only check for case-insensitive equality, not Levenshtein distance.
*
* If there is a candidate that's the same except for case, return that.
* If there is a candidate that's within one edit of the name, return that.
* Otherwise, return the candidate with the smallest Levenshtein distance,
* except for candidates:
* * With no name
* * Whose length differs from the target name by more than 0.34 of the length of the name.
* * Whose levenshtein distance is more than 0.4 of the length of the name
* (0.4 allows 1 substitution/transposition for every 5 characters,
* and 1 insertion/deletion at 3 characters)
*/
export function getSpellingSuggestion<T>(name: string, candidates: T[], getName: (candidate: T) => string | undefined): T | undefined {
const maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
let bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result isn't better than this, don't bother.
let bestCandidate: T | undefined;
let justCheckExactMatches = false;
const nameLowerCase = name.toLowerCase();
for (const candidate of candidates) {
const candidateName = getName(candidate);
if (candidateName !== undefined && Math.abs(candidateName.length - nameLowerCase.length) <= maximumLengthDifference) {
const candidateNameLowerCase = candidateName.toLowerCase();
if (candidateNameLowerCase === nameLowerCase) {
return candidate;
}
if (justCheckExactMatches) {
continue;
}
if (candidateName.length < 3) {
// Don't bother, user would have noticed a 2-character name having an extra character
continue;
}
// Only care about a result better than the best so far.
const distance = levenshteinWithMax(nameLowerCase, candidateNameLowerCase, bestDistance - 1);
if (distance === undefined) {
continue;
}
if (distance < 3) {
justCheckExactMatches = true;
bestCandidate = candidate;
}
else {
Debug.assert(distance < bestDistance); // Else `levenshteinWithMax` should return undefined
bestDistance = distance;
bestCandidate = candidate;
}
}
}
return bestCandidate;
}
function levenshteinWithMax(s1: string, s2: string, max: number): number | undefined {
let previous = new Array(s2.length + 1);
let current = new Array(s2.length + 1);
/** Represents any value > max. We don't care about the particular value. */
const big = max + 1;
for (let i = 0; i <= s2.length; i++) {
previous[i] = i;
}
for (let i = 1; i <= s1.length; i++) {
const c1 = s1.charCodeAt(i - 1);
const minJ = i > max ? i - max : 1;
const maxJ = s2.length > max + i ? max + i : s2.length;
current[0] = i;
/** Smallest value of the matrix in the ith column. */
let colMin = i;
for (let j = 1; j < minJ; j++) {
current[j] = big;
}
for (let j = minJ; j <= maxJ; j++) {
const dist = c1 === s2.charCodeAt(j - 1)
? previous[j - 1]
: Math.min(/*delete*/ previous[j] + 1, /*insert*/ current[j - 1] + 1, /*substitute*/ previous[j - 1] + 2);
current[j] = dist;
colMin = Math.min(colMin, dist);
}
for (let j = maxJ + 1; j <= s2.length; j++) {
current[j] = big;
}
if (colMin > max) {
// Give up -- everything in this column is > max and it can't get better in future columns.
return undefined;
}
const temp = previous;
previous = current;
current = temp;
}
const res = previous[s2.length];
return res > max ? undefined : res;
}
export function getEmitScriptTarget(compilerOptions: CompilerOptions) {
return compilerOptions.target || ScriptTarget.ES3;
}
@@ -2588,6 +2697,22 @@ namespace ts {
return startsWith(str, prefix) ? str.substr(prefix.length) : str;
}
export function tryRemovePrefix(str: string, prefix: string): string | undefined {
return startsWith(str, prefix) ? str.substring(prefix.length) : undefined;
}
export function tryRemoveDirectoryPrefix(path: string, dirPath: string): string | undefined {
const a = tryRemovePrefix(path, dirPath);
if (a === undefined) return undefined;
switch (a.charCodeAt(0)) {
case CharacterCodes.slash:
case CharacterCodes.backslash:
return a.slice(1);
default:
return undefined;
}
}
export function endsWith(str: string, suffix: string): boolean {
const expectedPos = str.length - suffix.length;
return expectedPos >= 0 && str.indexOf(suffix, expectedPos) === expectedPos;
@@ -2597,6 +2722,10 @@ namespace ts {
return endsWith(str, suffix) ? str.slice(0, str.length - suffix.length) : str;
}
export function tryRemoveSuffix(str: string, suffix: string): string | undefined {
return endsWith(str, suffix) ? str.slice(0, str.length - suffix.length) : undefined;
}
export function stringContains(str: string, substring: string): boolean {
return str.indexOf(substring) !== -1;
}
@@ -2797,6 +2926,7 @@ namespace ts {
basePaths: ReadonlyArray<string>;
}
/** @param path directory of the tsconfig.json */
export function getFileMatcherPatterns(path: string, excludes: ReadonlyArray<string> | undefined, includes: ReadonlyArray<string> | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string): FileMatcherPatterns {
path = normalizePath(path);
currentDirectory = normalizePath(currentDirectory);
@@ -2811,16 +2941,20 @@ namespace ts {
};
}
export function getRegexFromPattern(pattern: string, useCaseSensitiveFileNames: boolean): RegExp {
return new RegExp(pattern, useCaseSensitiveFileNames ? "" : "i");
}
/** @param path directory of the tsconfig.json */
export function matchFiles(path: string, extensions: ReadonlyArray<string> | undefined, excludes: ReadonlyArray<string> | undefined, includes: ReadonlyArray<string> | undefined, useCaseSensitiveFileNames: boolean, currentDirectory: string, depth: number | undefined, getFileSystemEntries: (path: string) => FileSystemEntries): string[] {
path = normalizePath(path);
currentDirectory = normalizePath(currentDirectory);
const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
const regexFlag = useCaseSensitiveFileNames ? "" : "i";
const includeFileRegexes = patterns.includeFilePatterns && patterns.includeFilePatterns.map(pattern => new RegExp(pattern, regexFlag));
const includeDirectoryRegex = patterns.includeDirectoryPattern && new RegExp(patterns.includeDirectoryPattern, regexFlag);
const excludeRegex = patterns.excludePattern && new RegExp(patterns.excludePattern, regexFlag);
const includeFileRegexes = patterns.includeFilePatterns && patterns.includeFilePatterns.map(pattern => getRegexFromPattern(pattern, useCaseSensitiveFileNames));
const includeDirectoryRegex = patterns.includeDirectoryPattern && getRegexFromPattern(patterns.includeDirectoryPattern, useCaseSensitiveFileNames);
const excludeRegex = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, useCaseSensitiveFileNames);
// Associate an array of results with each include regex. This keeps results in order of the "include" order.
// If there are no "includes", then just put everything in results[0].
+12
View File
@@ -219,6 +219,10 @@
"category": "Error",
"code": 1068
},
"Unexpected token. A type parameter name was expected without curly braces.": {
"category": "Error",
"code": 1069
},
"'{0}' modifier cannot appear on a type member.": {
"category": "Error",
"code": 1070
@@ -2365,6 +2369,14 @@
"category": "Error",
"code": 2725
},
"Cannot find lib definition for '{0}'.": {
"category": "Error",
"code": 2726
},
"Cannot find lib definition for '{0}'. Did you mean '{1}'?": {
"category": "Error",
"code": 2727
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
+2 -2
View File
@@ -50,7 +50,7 @@ namespace ts {
}
else {
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
const sourceMapFilePath = isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
// For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error
const isJs = isSourceFileJavaScript(sourceFile);
const declarationFilePath = ((forceDtsPaths || options.declaration) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
@@ -1458,7 +1458,7 @@ namespace ts {
}
const preferNewLine = node.multiLine ? ListFormat.PreferNewLine : ListFormat.None;
const allowTrailingComma = currentSourceFile.languageVersion >= ScriptTarget.ES5 ? ListFormat.AllowTrailingComma : ListFormat.None;
const allowTrailingComma = currentSourceFile.languageVersion >= ScriptTarget.ES5 && !isJsonSourceFile(currentSourceFile) ? ListFormat.AllowTrailingComma : ListFormat.None;
emitList(node, node.properties, ListFormat.ObjectLiteralExpressionProperties | allowTrailingComma | preferNewLine);
if (indentedFlag) {
+3 -1
View File
@@ -2432,12 +2432,13 @@ namespace ts {
// Top-level nodes
export function updateSourceFileNode(node: SourceFile, statements: ReadonlyArray<Statement>, isDeclarationFile?: boolean, referencedFiles?: SourceFile["referencedFiles"], typeReferences?: SourceFile["typeReferenceDirectives"], hasNoDefaultLib?: boolean) {
export function updateSourceFileNode(node: SourceFile, statements: ReadonlyArray<Statement>, isDeclarationFile?: boolean, referencedFiles?: SourceFile["referencedFiles"], typeReferences?: SourceFile["typeReferenceDirectives"], hasNoDefaultLib?: boolean, libReferences?: SourceFile["libReferenceDirectives"]) {
if (
node.statements !== statements ||
(isDeclarationFile !== undefined && node.isDeclarationFile !== isDeclarationFile) ||
(referencedFiles !== undefined && node.referencedFiles !== referencedFiles) ||
(typeReferences !== undefined && node.typeReferenceDirectives !== typeReferences) ||
(libReferences !== undefined && node.libReferenceDirectives !== libReferences) ||
(hasNoDefaultLib !== undefined && node.hasNoDefaultLib !== hasNoDefaultLib)
) {
const updated = <SourceFile>createSynthesizedNode(SyntaxKind.SourceFile);
@@ -2451,6 +2452,7 @@ namespace ts {
updated.referencedFiles = referencedFiles === undefined ? node.referencedFiles : referencedFiles;
updated.typeReferenceDirectives = typeReferences === undefined ? node.typeReferenceDirectives : typeReferences;
updated.hasNoDefaultLib = hasNoDefaultLib === undefined ? node.hasNoDefaultLib : hasNoDefaultLib;
updated.libReferenceDirectives = libReferences === undefined ? node.libReferenceDirectives : libReferences;
if (node.amdDependencies !== undefined) updated.amdDependencies = node.amdDependencies;
if (node.moduleName !== undefined) updated.moduleName = node.moduleName;
if (node.languageVariant !== undefined) updated.languageVariant = node.languageVariant;
-4
View File
@@ -132,10 +132,6 @@ namespace ts {
}
}
export interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined {
if (options.typeRoots) {
return options.typeRoots;
@@ -1,92 +1,129 @@
// Used by importFixes to synthesize import module specifiers.
/* @internal */
namespace ts.moduleSpecifiers {
export interface ModuleSpecifierPreferences {
importModuleSpecifierPreference?: "relative" | "non-relative";
}
// Note: fromSourceFile is just for usesJsExtensionOnImports
export function getModuleSpecifier(compilerOptions: CompilerOptions, fromSourceFile: SourceFile, fromSourceFileName: string, toFileName: string, host: ModuleSpecifierResolutionHost, preferences: ModuleSpecifierPreferences = {}) {
const info = getInfo(compilerOptions, fromSourceFile, fromSourceFileName, host);
return getGlobalModuleSpecifier(toFileName, info, host, compilerOptions) ||
first(getLocalModuleSpecifiers(toFileName, info, compilerOptions, preferences));
}
// For each symlink/original for a module, returns a list of ways to import that file.
export function getModuleSpecifiers(
moduleSymbol: Symbol,
program: Program,
importingSourceFile: SourceFile,
host: LanguageServiceHost,
preferences: UserPreferences,
host: ModuleSpecifierResolutionHost,
preferences: ModuleSpecifierPreferences,
): ReadonlyArray<ReadonlyArray<string>> {
const compilerOptions = program.getCompilerOptions();
const { baseUrl, paths, rootDirs } = compilerOptions;
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
const addJsExtension = usesJsExtensionOnImports(importingSourceFile);
const getCanonicalFileName = hostGetCanonicalFileName(host);
const sourceDirectory = getDirectoryPath(importingSourceFile.fileName);
const ambient = tryGetModuleNameFromAmbientModule(moduleSymbol);
if (ambient) return [[ambient]];
const modulePaths = getAllModulePaths(program, moduleSymbol.valueDeclaration.getSourceFile());
const compilerOptions = program.getCompilerOptions();
const info = getInfo(compilerOptions, importingSourceFile, importingSourceFile.fileName, host);
const modulePaths = getAllModulePaths(program, getSourceFileOfNode(moduleSymbol.valueDeclaration));
const global = mapDefined(modulePaths, moduleFileName =>
tryGetModuleNameFromTypeRoots(compilerOptions, host, getCanonicalFileName, moduleFileName, addJsExtension) ||
tryGetModuleNameAsNodeModule(compilerOptions, moduleFileName, host, getCanonicalFileName, sourceDirectory) ||
rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName));
if (global.length) return global.map(g => [g]);
const global = mapDefined(modulePaths, moduleFileName => getGlobalModuleSpecifier(moduleFileName, info, host, compilerOptions));
return global.length ? global.map(g => [g]) : modulePaths.map(moduleFileName =>
getLocalModuleSpecifiers(moduleFileName, info, compilerOptions, preferences));
}
return modulePaths.map(moduleFileName => {
const relativePath = removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), moduleResolutionKind, addJsExtension);
if (!baseUrl || preferences.importModuleSpecifierPreference === "relative") {
return [relativePath];
interface Info {
readonly moduleResolutionKind: ModuleResolutionKind;
readonly addJsExtension: boolean;
readonly getCanonicalFileName: GetCanonicalFileName;
readonly sourceDirectory: string;
}
// importingSourceFileName is separate because getEditsForFileRename may need to specify an updated path
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: string, host: ModuleSpecifierResolutionHost): Info {
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
const addJsExtension = usesJsExtensionOnImports(importingSourceFile);
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : true);
const sourceDirectory = getDirectoryPath(importingSourceFileName);
return { moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory };
}
function getGlobalModuleSpecifier(
moduleFileName: string,
{ addJsExtension, getCanonicalFileName, sourceDirectory }: Info,
host: ModuleSpecifierResolutionHost,
compilerOptions: CompilerOptions,
) {
return tryGetModuleNameFromTypeRoots(compilerOptions, host, getCanonicalFileName, moduleFileName, addJsExtension)
|| tryGetModuleNameAsNodeModule(compilerOptions, moduleFileName, host, getCanonicalFileName, sourceDirectory)
|| compilerOptions.rootDirs && tryGetModuleNameFromRootDirs(compilerOptions.rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName);
}
function getLocalModuleSpecifiers(
moduleFileName: string,
{ moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory }: Info,
compilerOptions: CompilerOptions,
preferences: ModuleSpecifierPreferences,
) {
const { baseUrl, paths } = compilerOptions;
const relativePath = removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), moduleResolutionKind, addJsExtension);
if (!baseUrl || preferences.importModuleSpecifierPreference === "relative") {
return [relativePath];
}
const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseUrl, getCanonicalFileName);
if (!relativeToBaseUrl) {
return [relativePath];
}
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, moduleResolutionKind, addJsExtension);
if (paths) {
const fromPaths = tryGetModuleNameFromPaths(removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
if (fromPaths) {
return [fromPaths];
}
}
const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseUrl, getCanonicalFileName);
if (!relativeToBaseUrl) {
return [relativePath];
}
if (preferences.importModuleSpecifierPreference === "non-relative") {
return [importRelativeToBaseUrl];
}
const importRelativeToBaseUrl = removeExtensionAndIndexPostFix(relativeToBaseUrl, moduleResolutionKind, addJsExtension);
if (paths) {
const fromPaths = tryGetModuleNameFromPaths(removeFileExtension(relativeToBaseUrl), importRelativeToBaseUrl, paths);
if (fromPaths) {
return [fromPaths];
}
}
if (preferences.importModuleSpecifierPreference !== undefined) Debug.assertNever(preferences.importModuleSpecifierPreference);
if (preferences.importModuleSpecifierPreference === "non-relative") {
return [importRelativeToBaseUrl];
}
if (isPathRelativeToParent(relativeToBaseUrl)) {
return [relativePath];
}
if (preferences.importModuleSpecifierPreference !== undefined) Debug.assertNever(preferences.importModuleSpecifierPreference);
/*
Prefer a relative import over a baseUrl import if it doesn't traverse up to baseUrl.
if (isPathRelativeToParent(relativeToBaseUrl)) {
return [relativePath];
}
Suppose we have:
baseUrl = /base
sourceDirectory = /base/a/b
moduleFileName = /base/foo/bar
Then:
relativePath = ../../foo/bar
getRelativePathNParents(relativePath) = 2
pathFromSourceToBaseUrl = ../../
getRelativePathNParents(pathFromSourceToBaseUrl) = 2
2 < 2 = false
In this case we should prefer using the baseUrl path "/a/b" instead of the relative path "../../foo/bar".
/*
Prefer a relative import over a baseUrl import if it doesn't traverse up to baseUrl.
Suppose we have:
baseUrl = /base
sourceDirectory = /base/a/b
moduleFileName = /base/foo/bar
Then:
relativePath = ../../foo/bar
getRelativePathNParents(relativePath) = 2
pathFromSourceToBaseUrl = ../../
getRelativePathNParents(pathFromSourceToBaseUrl) = 2
2 < 2 = false
In this case we should prefer using the baseUrl path "/a/b" instead of the relative path "../../foo/bar".
Suppose we have:
baseUrl = /base
sourceDirectory = /base/foo/a
moduleFileName = /base/foo/bar
Then:
relativePath = ../a
getRelativePathNParents(relativePath) = 1
pathFromSourceToBaseUrl = ../../
getRelativePathNParents(pathFromSourceToBaseUrl) = 2
1 < 2 = true
In this case we should prefer using the relative path "../a" instead of the baseUrl path "foo/a".
*/
const pathFromSourceToBaseUrl = ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, baseUrl, getCanonicalFileName));
const relativeFirst = getRelativePathNParents(relativePath) < getRelativePathNParents(pathFromSourceToBaseUrl);
return relativeFirst ? [relativePath, importRelativeToBaseUrl] : [importRelativeToBaseUrl, relativePath];
});
Suppose we have:
baseUrl = /base
sourceDirectory = /base/foo/a
moduleFileName = /base/foo/bar
Then:
relativePath = ../a
getRelativePathNParents(relativePath) = 1
pathFromSourceToBaseUrl = ../../
getRelativePathNParents(pathFromSourceToBaseUrl) = 2
1 < 2 = true
In this case we should prefer using the relative path "../a" instead of the baseUrl path "foo/a".
*/
const pathFromSourceToBaseUrl = ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, baseUrl, getCanonicalFileName));
const relativeFirst = getRelativePathNParents(relativePath) < getRelativePathNParents(pathFromSourceToBaseUrl);
return relativeFirst ? [relativePath, importRelativeToBaseUrl] : [importRelativeToBaseUrl, relativePath];
}
function usesJsExtensionOnImports({ imports }: SourceFile): boolean {
@@ -176,7 +213,7 @@ namespace ts.moduleSpecifiers {
function tryGetModuleNameAsNodeModule(
options: CompilerOptions,
moduleFileName: string,
host: LanguageServiceHost,
host: ModuleSpecifierResolutionHost,
getCanonicalFileName: (file: string) => string,
sourceDirectory: string,
): string | undefined {
@@ -222,7 +259,8 @@ namespace ts.moduleSpecifiers {
const fullModulePathWithoutExtension = removeFileExtension(path);
// If the file is /index, it can be imported by its directory name
if (getCanonicalFileName(fullModulePathWithoutExtension.substring(parts.fileNameIndex)) === "/index") {
// IFF there is not _also_ a file by the same name
if (getCanonicalFileName(fullModulePathWithoutExtension.substring(parts.fileNameIndex)) === "/index" && !tryGetAnyFileFromPath(host, fullModulePathWithoutExtension.substring(0, parts.fileNameIndex))) {
return fullModulePathWithoutExtension.substring(0, parts.fileNameIndex);
}
@@ -230,6 +268,17 @@ namespace ts.moduleSpecifiers {
}
}
function tryGetAnyFileFromPath(host: ModuleSpecifierResolutionHost, path: string) {
// We check all js, `node` and `json` extensions in addition to TS, since node module resolution would also choose those over the directory
const extensions = getSupportedExtensions({ allowJs: true }, [{ extension: "node", isMixedContent: false }, { extension: "json", isMixedContent: false, scriptKind: ScriptKind.JSON }]);
for (const e of extensions) {
const fullPath = path + e;
if (host.fileExists!(fullPath)) { // TODO: GH#18217
return fullPath;
}
}
}
interface NodeModulePathParts {
readonly topLevelNodeModulesIndex: number;
readonly topLevelPackageNameIndex: number;
+148 -184
View File
@@ -4,7 +4,6 @@ namespace ts {
Yield = 1 << 0,
Await = 1 << 1,
Type = 1 << 2,
RequireCompleteParameterList = 1 << 3,
IgnoreMissingOpenBrace = 1 << 4,
JSDoc = 1 << 5,
}
@@ -717,6 +716,7 @@ namespace ts {
initializeState(sourceText, languageVersion, syntaxCursor, ScriptKind.JSON);
// Set source file so that errors will be reported with this file name
sourceFile = createSourceFile(fileName, ScriptTarget.ES2015, ScriptKind.JSON, /*isDeclaration*/ false);
sourceFile.flags = contextFlags;
// Prime the scanner.
nextToken();
@@ -1256,8 +1256,8 @@ namespace ts {
new TokenConstructor(kind, p, p);
}
function createNodeWithJSDoc(kind: SyntaxKind): Node {
const node = createNode(kind);
function createNodeWithJSDoc(kind: SyntaxKind, pos?: number): Node {
const node = createNode(kind, pos);
if (scanner.getTokenFlags() & TokenFlags.PrecedingJSDocComment) {
addJSDocComment(<HasJSDoc>node);
}
@@ -2256,6 +2256,24 @@ namespace ts {
return finishNode(node);
}
// If true, we should abort parsing an error function.
function typeHasArrowFunctionBlockingParseError(node: TypeNode): boolean {
switch (node.kind) {
case SyntaxKind.TypeReference:
return nodeIsMissing((node as TypeReferenceNode).typeName);
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType: {
const { parameters, type } = node as FunctionOrConstructorTypeNode;
// parameters.pos === parameters.end only if we used parseMissingList, else should contain at least `()`
return parameters.pos === parameters.end || typeHasArrowFunctionBlockingParseError(type);
}
case SyntaxKind.ParenthesizedType:
return typeHasArrowFunctionBlockingParseError((node as ParenthesizedTypeNode).type);
default:
return false;
}
}
function parseThisTypePredicate(lhs: ThisTypeNode): TypePredicateNode {
nextToken();
const node = createNode(SyntaxKind.TypePredicate, lhs.pos) as TypePredicateNode;
@@ -2342,7 +2360,7 @@ namespace ts {
return finishNode(parameter);
}
function parseJSDocType() {
function parseJSDocType(): TypeNode {
const dotdotdot = parseOptionalToken(SyntaxKind.DotDotDotToken);
let type = parseType();
if (dotdotdot) {
@@ -2450,6 +2468,7 @@ namespace ts {
}
/**
* Note: If returnToken is EqualsGreaterThanToken, `signature.type` will always be defined.
* @returns If return type parsing succeeds
*/
function fillSignature(
@@ -2459,12 +2478,12 @@ namespace ts {
if (!(flags & SignatureFlags.JSDoc)) {
signature.typeParameters = parseTypeParameters();
}
signature.parameters = parseParameterList(flags)!; // TODO: GH#18217
const parametersParsedSuccessfully = parseParameterList(signature, flags);
if (shouldParseReturnType(returnToken, !!(flags & SignatureFlags.Type))) {
signature.type = parseTypeOrTypePredicate();
return signature.type !== undefined;
if (typeHasArrowFunctionBlockingParseError(signature.type)) return false;
}
return true;
return parametersParsedSuccessfully;
}
function shouldParseReturnType(returnToken: SyntaxKind.ColonToken | SyntaxKind.EqualsGreaterThanToken, isType: boolean): boolean {
@@ -2484,7 +2503,8 @@ namespace ts {
return false;
}
function parseParameterList(flags: SignatureFlags) {
// Returns true on success.
function parseParameterList(signature: SignatureDeclaration, flags: SignatureFlags): boolean {
// FormalParameters [Yield,Await]: (modified)
// [empty]
// FormalParameterList[?Yield,Await]
@@ -2498,31 +2518,23 @@ namespace ts {
//
// SingleNameBinding [Yield,Await]:
// BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt
if (parseExpected(SyntaxKind.OpenParenToken)) {
const savedYieldContext = inYieldContext();
const savedAwaitContext = inAwaitContext();
setYieldContext(!!(flags & SignatureFlags.Yield));
setAwaitContext(!!(flags & SignatureFlags.Await));
const result = parseDelimitedList(ParsingContext.Parameters, flags & SignatureFlags.JSDoc ? parseJSDocParameter : parseParameter);
setYieldContext(savedYieldContext);
setAwaitContext(savedAwaitContext);
if (!parseExpected(SyntaxKind.CloseParenToken) && (flags & SignatureFlags.RequireCompleteParameterList)) {
// Caller insisted that we had to end with a ) We didn't. So just return
// undefined here.
return undefined;
}
return result;
if (!parseExpected(SyntaxKind.OpenParenToken)) {
signature.parameters = createMissingList<ParameterDeclaration>();
return false;
}
// We didn't even have an open paren. If the caller requires a complete parameter list,
// we definitely can't provide that. However, if they're ok with an incomplete one,
// then just return an empty set of parameters.
return (flags & SignatureFlags.RequireCompleteParameterList) ? undefined : createMissingList<ParameterDeclaration>();
const savedYieldContext = inYieldContext();
const savedAwaitContext = inAwaitContext();
setYieldContext(!!(flags & SignatureFlags.Yield));
setAwaitContext(!!(flags & SignatureFlags.Await));
signature.parameters = parseDelimitedList(ParsingContext.Parameters, flags & SignatureFlags.JSDoc ? parseJSDocParameter : parseParameter);
setYieldContext(savedYieldContext);
setAwaitContext(savedAwaitContext);
return parseExpected(SyntaxKind.CloseParenToken);
}
function parseTypeMemberSemicolon() {
@@ -2771,28 +2783,19 @@ namespace ts {
return finishNode(node);
}
function parseParenthesizedType(): ParenthesizedTypeNode {
function parseParenthesizedType(): TypeNode {
const node = <ParenthesizedTypeNode>createNode(SyntaxKind.ParenthesizedType);
parseExpected(SyntaxKind.OpenParenToken);
node.type = parseType();
if (!node.type) {
return undefined!; // TODO: GH#18217
}
parseExpected(SyntaxKind.CloseParenToken);
return finishNode(node);
}
function parseFunctionOrConstructorType(kind: SyntaxKind): FunctionOrConstructorTypeNode | undefined {
const node = <FunctionOrConstructorTypeNode>createNodeWithJSDoc(kind);
if (kind === SyntaxKind.ConstructorType) {
parseExpected(SyntaxKind.NewKeyword);
}
if (!fillSignature(SyntaxKind.EqualsGreaterThanToken, SignatureFlags.Type | (sourceFile.languageVariant === LanguageVariant.JSX ? SignatureFlags.RequireCompleteParameterList : 0), node)) {
return undefined;
}
if (!node.parameters) {
return undefined;
}
function parseFunctionOrConstructorType(): TypeNode {
const pos = getNodePos();
const kind = parseOptional(SyntaxKind.NewKeyword) ? SyntaxKind.ConstructorType : SyntaxKind.FunctionType;
const node = <FunctionOrConstructorTypeNode>createNodeWithJSDoc(kind, pos);
fillSignature(SyntaxKind.EqualsGreaterThanToken, SignatureFlags.Type, node);
return finishNode(node);
}
@@ -3133,11 +3136,8 @@ namespace ts {
}
function parseTypeWorker(noConditionalTypes?: boolean): TypeNode {
if (isStartOfFunctionType()) {
return parseFunctionOrConstructorType(SyntaxKind.FunctionType)!; // TODO: GH#18217
}
if (token() === SyntaxKind.NewKeyword) {
return parseFunctionOrConstructorType(SyntaxKind.ConstructorType)!;
if (isStartOfFunctionType() || token() === SyntaxKind.NewKeyword) {
return parseFunctionOrConstructorType();
}
const type = parseUnionTypeOrHigher();
if (!noConditionalTypes && !scanner.hasPrecedingLineBreak() && parseOptional(SyntaxKind.ExtendsKeyword)) {
@@ -3625,12 +3625,7 @@ namespace ts {
// a => (b => c)
// And think that "(b =>" was actually a parenthesized arrow function with a missing
// close paren.
if (!fillSignature(SyntaxKind.ColonToken, isAsync | (allowAmbiguity ? SignatureFlags.None : SignatureFlags.RequireCompleteParameterList), node)) {
return undefined;
}
// If we couldn't get parameters, we definitely could not parse out an arrow function.
if (!node.parameters) {
if (!fillSignature(SyntaxKind.ColonToken, isAsync, node) && !allowAmbiguity) {
return undefined;
}
@@ -4147,27 +4142,6 @@ namespace ts {
return finishNode(node);
}
function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean {
if (lhs.kind !== rhs.kind) {
return false;
}
if (lhs.kind === SyntaxKind.Identifier) {
return (<Identifier>lhs).escapedText === (<Identifier>rhs).escapedText;
}
if (lhs.kind === SyntaxKind.ThisKeyword) {
return true;
}
// If we are at this statement then we must have PropertyAccessExpression and because tag name in Jsx element can only
// take forms of JsxTagNameExpression which includes an identifier, "this" expression, or another propertyAccessExpression
// it is safe to case the expression property as such. See parseJsxElementName for how we parse tag name in Jsx element
return (<PropertyAccessExpression>lhs).name.escapedText === (<PropertyAccessExpression>rhs).name.escapedText &&
tagNamesAreEquivalent((<PropertyAccessExpression>lhs).expression as JsxTagNameExpression, (<PropertyAccessExpression>rhs).expression as JsxTagNameExpression);
}
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement | JsxFragment {
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
@@ -6385,17 +6359,14 @@ namespace ts {
indent += text.length;
}
let t = nextJSDocToken();
while (t === SyntaxKind.WhitespaceTrivia) {
t = nextJSDocToken();
}
if (t === SyntaxKind.NewLineTrivia) {
nextJSDocToken();
while (parseOptionalJsdoc(SyntaxKind.WhitespaceTrivia));
if (parseOptionalJsdoc(SyntaxKind.NewLineTrivia)) {
state = JSDocState.BeginningOfLine;
indent = 0;
t = nextJSDocToken();
}
loop: while (true) {
switch (t) {
switch (token()) {
case SyntaxKind.AtToken:
if (state === JSDocState.BeginningOfLine || state === JSDocState.SawAsterisk) {
removeTrailingNewlines(comments);
@@ -6455,12 +6426,11 @@ namespace ts {
pushComment(scanner.getTokenText());
break;
}
t = nextJSDocToken();
nextJSDocToken();
}
removeLeadingNewlines(comments);
removeTrailingNewlines(comments);
result = createJSDocComment();
});
return result;
@@ -6516,54 +6486,42 @@ namespace ts {
const tagName = parseJSDocIdentifierName();
skipWhitespace();
if (!tagName) {
return;
}
let tag: JSDocTag | undefined;
if (tagName) {
switch (tagName.escapedText) {
case "augments":
case "extends":
tag = parseAugmentsTag(atToken, tagName);
break;
case "class":
case "constructor":
tag = parseClassTag(atToken, tagName);
break;
case "arg":
case "argument":
case "param":
return parseParameterOrPropertyTag(atToken, tagName, PropertyLikeParse.Parameter, indent);
case "return":
case "returns":
tag = parseReturnTag(atToken, tagName);
break;
case "template":
tag = parseTemplateTag(atToken, tagName);
break;
case "type":
tag = parseTypeTag(atToken, tagName);
break;
case "typedef":
tag = parseTypedefTag(atToken, tagName, indent);
break;
case "callback":
tag = parseCallbackTag(atToken, tagName, indent);
break;
default:
tag = parseUnknownTag(atToken, tagName);
break;
}
}
else {
tag = parseUnknownTag(atToken, tagName);
switch (tagName.escapedText) {
case "augments":
case "extends":
tag = parseAugmentsTag(atToken, tagName);
break;
case "class":
case "constructor":
tag = parseClassTag(atToken, tagName);
break;
case "arg":
case "argument":
case "param":
return parseParameterOrPropertyTag(atToken, tagName, PropertyLikeParse.Parameter, indent);
case "return":
case "returns":
tag = parseReturnTag(atToken, tagName);
break;
case "template":
tag = parseTemplateTag(atToken, tagName);
break;
case "type":
tag = parseTypeTag(atToken, tagName);
break;
case "typedef":
tag = parseTypedefTag(atToken, tagName, indent);
break;
case "callback":
tag = parseCallbackTag(atToken, tagName, indent);
break;
default:
tag = parseUnknownTag(atToken, tagName);
break;
}
if (!tag) {
// a badly malformed tag should not be added to the list of tags
return;
}
if (!tag.comment) {
// some tags, like typedef and callback, have already parsed their comments earlier
tag.comment = parseTagComments(indent + tag.end - tag.pos);
@@ -6793,11 +6751,11 @@ namespace ts {
}
function parsePropertyAccessEntityNameExpression() {
let node: Identifier | PropertyAccessEntityNameExpression = parseJSDocIdentifierName(/*createIfMissing*/ true);
let node: Identifier | PropertyAccessEntityNameExpression = parseJSDocIdentifierName();
while (parseOptional(SyntaxKind.DotToken)) {
const prop: PropertyAccessEntityNameExpression = createNode(SyntaxKind.PropertyAccessExpression, node.pos) as PropertyAccessEntityNameExpression;
prop.expression = node;
prop.name = parseJSDocIdentifierName()!; // TODO: GH#18217
prop.name = parseJSDocIdentifierName();
node = finishNode(prop);
}
return node;
@@ -6862,9 +6820,11 @@ namespace ts {
function parseJSDocTypeNameWithNamespace(nested?: boolean) {
const pos = scanner.getTokenPos();
if (!tokenIsIdentifierOrKeyword(token())) {
return undefined;
}
const typeNameOrNamespaceName = parseJSDocIdentifierName();
if (typeNameOrNamespaceName && parseOptional(SyntaxKind.DotToken)) {
if (parseOptional(SyntaxKind.DotToken)) {
const jsDocNamespaceNode = <JSDocNamespaceDeclaration>createNode(SyntaxKind.ModuleDeclaration, pos);
if (nested) {
jsDocNamespaceNode.flags |= NodeFlags.NestedNamespace;
@@ -6874,7 +6834,7 @@ namespace ts {
return finishNode(jsDocNamespaceNode);
}
if (typeNameOrNamespaceName && nested) {
if (nested) {
typeNameOrNamespaceName.isInJSDocNamespace = true;
}
return typeNameOrNamespaceName;
@@ -6897,8 +6857,7 @@ namespace ts {
jsdocSignature.parameters = append(jsdocSignature.parameters as MutableNodeArray<JSDocParameterTag>, child);
}
const returnTag = tryParse(() => {
if (token() === SyntaxKind.AtToken) {
nextJSDocToken();
if (parseOptionalJsdoc(SyntaxKind.AtToken)) {
const tag = parseTag(indent);
if (tag && tag.kind === SyntaxKind.JSDocReturnTag) {
return tag as JSDocReturnTag;
@@ -6985,9 +6944,6 @@ namespace ts {
const tagName = parseJSDocIdentifierName();
skipWhitespace();
if (!tagName) {
return false;
}
let t: PropertyLikeParse;
switch (tagName.escapedText) {
case "type":
@@ -7012,36 +6968,26 @@ namespace ts {
return tag;
}
function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag | undefined {
if (some(tags, isJSDocTemplateTag)) {
parseErrorAt(tagName.pos, scanner.getTokenPos(), Diagnostics._0_tag_already_specified, tagName.escapedText);
function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag {
// the template tag looks like '@template {Constraint} T,U,V'
let constraint: JSDocTypeExpression | undefined;
if (token() === SyntaxKind.OpenBraceToken) {
constraint = parseJSDocTypeExpression();
}
// Type parameter list looks like '@template T,U,V'
const typeParameters = [];
const typeParametersPos = getNodePos();
while (true) {
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
const name = parseJSDocIdentifierNameWithOptionalBraces();
do {
skipWhitespace();
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
typeParameter.name = parseJSDocIdentifierName(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces);
skipWhitespace();
if (!name) {
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
return undefined;
}
typeParameter.name = name;
finishNode(typeParameter);
typeParameters.push(typeParameter);
} while (parseOptionalJsdoc(SyntaxKind.CommaToken));
if (token() === SyntaxKind.CommaToken) {
nextJSDocToken();
skipWhitespace();
}
else {
break;
}
if (constraint) {
first(typeParameters).constraint = constraint.type;
}
const result = <JSDocTemplateTag>createNode(SyntaxKind.JSDocTemplateTag, atToken.pos);
@@ -7052,21 +6998,20 @@ namespace ts {
return result;
}
function parseJSDocIdentifierNameWithOptionalBraces(): Identifier | undefined {
const parsedBrace = parseOptional(SyntaxKind.OpenBraceToken);
const res = parseJSDocIdentifierName();
if (parsedBrace) {
parseExpected(SyntaxKind.CloseBraceToken);
}
return res;
}
function nextJSDocToken(): JsDocSyntaxKind {
return currentToken = scanner.scanJSDocToken();
}
function parseOptionalJsdoc(t: JsDocSyntaxKind): boolean {
if (token() === t) {
nextJSDocToken();
return true;
}
return false;
}
function parseJSDocEntityName(): EntityName {
let entity: EntityName = parseJSDocIdentifierName(/*createIfMissing*/ true);
let entity: EntityName = parseJSDocIdentifierName();
if (parseOptional(SyntaxKind.OpenBracketToken)) {
parseExpected(SyntaxKind.CloseBracketToken);
// Note that y[] is accepted as an entity name, but the postfix brackets are not saved for checking.
@@ -7074,7 +7019,7 @@ namespace ts {
// but it's not worth it to enforce that restriction.
}
while (parseOptional(SyntaxKind.DotToken)) {
const name = parseJSDocIdentifierName(/*createIfMissing*/ true);
const name = parseJSDocIdentifierName();
if (parseOptional(SyntaxKind.OpenBracketToken)) {
parseExpected(SyntaxKind.CloseBracketToken);
}
@@ -7083,17 +7028,9 @@ namespace ts {
return entity;
}
function parseJSDocIdentifierName(): Identifier | undefined;
function parseJSDocIdentifierName(createIfMissing: true): Identifier;
function parseJSDocIdentifierName(createIfMissing = false): Identifier | undefined {
function parseJSDocIdentifierName(message?: DiagnosticMessage): Identifier {
if (!tokenIsIdentifierOrKeyword(token())) {
if (createIfMissing) {
return createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Identifier_expected);
}
else {
parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
return undefined;
}
return createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ !message, message || Diagnostics.Identifier_expected);
}
const pos = scanner.getTokenPos();
@@ -7691,6 +7628,7 @@ namespace ts {
checkJsDirective?: CheckJsDirective;
referencedFiles: FileReference[];
typeReferenceDirectives: FileReference[];
libReferenceDirectives: FileReference[];
amdDependencies: AmdDependency[];
hasNoDefaultLib?: boolean;
moduleName?: string;
@@ -7744,6 +7682,7 @@ namespace ts {
context.checkJsDirective = undefined;
context.referencedFiles = [];
context.typeReferenceDirectives = [];
context.libReferenceDirectives = [];
context.amdDependencies = [];
context.hasNoDefaultLib = false;
context.pragmas!.forEach((entryOrList, key) => { // TODO: GH#18217
@@ -7753,6 +7692,7 @@ namespace ts {
case "reference": {
const referencedFiles = context.referencedFiles;
const typeReferenceDirectives = context.typeReferenceDirectives;
const libReferenceDirectives = context.libReferenceDirectives;
forEach(toArray(entryOrList), (arg: PragmaPsuedoMap["reference"]) => {
// TODO: GH#18217
if (arg!.arguments["no-default-lib"]) {
@@ -7761,6 +7701,9 @@ namespace ts {
else if (arg!.arguments.types) {
typeReferenceDirectives.push({ pos: arg!.arguments.types!.pos, end: arg!.arguments.types!.end, fileName: arg!.arguments.types!.value });
}
else if (arg!.arguments.lib) {
libReferenceDirectives.push({ pos: arg!.arguments.lib!.pos, end: arg!.arguments.lib!.end, fileName: arg!.arguments.lib!.value });
}
else if (arg!.arguments.path) {
referencedFiles.push({ pos: arg!.arguments.path!.pos, end: arg!.arguments.path!.end, fileName: arg!.arguments.path!.value });
}
@@ -7906,4 +7849,25 @@ namespace ts {
}
return argMap;
}
/** @internal */
export function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean {
if (lhs.kind !== rhs.kind) {
return false;
}
if (lhs.kind === SyntaxKind.Identifier) {
return (<Identifier>lhs).escapedText === (<Identifier>rhs).escapedText;
}
if (lhs.kind === SyntaxKind.ThisKeyword) {
return true;
}
// If we are at this statement then we must have PropertyAccessExpression and because tag name in Jsx element can only
// take forms of JsxTagNameExpression which includes an identifier, "this" expression, or another propertyAccessExpression
// it is safe to case the expression property as such. See parseJsxElementName for how we parse tag name in Jsx element
return (<PropertyAccessExpression>lhs).name.escapedText === (<PropertyAccessExpression>rhs).name.escapedText &&
tagNamesAreEquivalent((<PropertyAccessExpression>lhs).expression as JsxTagNameExpression, (<PropertyAccessExpression>rhs).expression as JsxTagNameExpression);
}
}
Executable → Regular
+99 -24
View File
@@ -491,6 +491,17 @@ namespace ts {
};
}
/**
* Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions'
* that represent a compilation unit.
*
* Creating a program proceeds from a set of root files, expanding the set of inputs by following imports and
* triple-slash-reference-path directives transitively. '@types' and triple-slash-reference-types are also pulled in.
*
* @param createProgramOptions - The options for creating a program.
* @returns A 'Program' object.
*/
export function createProgram(createProgramOptions: CreateProgramOptions): Program;
/**
* Create a new 'Program' instance. A Program is an immutable collection of 'SourceFile's and a 'CompilerOptions'
* that represent a compilation unit.
@@ -505,7 +516,6 @@ namespace ts {
* @param configFileParsingDiagnostics - error during config file parsing
* @returns A 'Program' object.
*/
export function createProgram(createProgramOptions: CreateProgramOptions): Program;
export function createProgram(rootNames: ReadonlyArray<string>, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): Program;
export function createProgram(rootNamesOrOptions: ReadonlyArray<string> | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>): Program {
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
@@ -513,7 +523,9 @@ namespace ts {
let { oldProgram } = createProgramOptions;
let program: Program;
let files: SourceFile[] = [];
let processingDefaultLibFiles: SourceFile[] | undefined;
let processingOtherFiles: SourceFile[] | undefined;
let files: SourceFile[];
let commonSourceDirectory: string;
let diagnosticsProducingTypeChecker: TypeChecker;
let noDiagnosticsTypeChecker: TypeChecker;
@@ -613,7 +625,7 @@ namespace ts {
if (parsedRef) {
if (parsedRef.commandLine.options.outFile) {
const dtsOutfile = changeExtension(parsedRef.commandLine.options.outFile, ".d.ts");
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*packageId*/ undefined);
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
}
addProjectReferenceRedirects(parsedRef.commandLine, projectReferenceRedirects);
}
@@ -623,7 +635,9 @@ namespace ts {
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
const structuralIsReused = tryReuseStructureFromOldProgram();
if (structuralIsReused !== StructureIsReused.Completely) {
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
processingDefaultLibFiles = [];
processingOtherFiles = [];
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false));
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, host);
@@ -647,16 +661,19 @@ namespace ts {
// otherwise, using options specified in '--lib' instead of '--target' default library file
const defaultLibraryFileName = getDefaultLibraryFileName();
if (!options.lib && defaultLibraryFileName) {
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true);
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false);
}
else {
forEach(options.lib, libFileName => {
processRootFile(combinePaths(defaultLibraryPath, libFileName), /*isDefaultLib*/ true);
processRootFile(combinePaths(defaultLibraryPath, libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false);
});
}
}
missingFilePaths = arrayFrom(filesByName.keys(), p => <Path>p).filter(p => !filesByName.get(p));
files = stableSort(processingDefaultLibFiles, compareDefaultLibFiles).concat(processingOtherFiles);
processingDefaultLibFiles = undefined;
processingOtherFiles = undefined;
}
Debug.assert(!!missingFilePaths);
@@ -686,6 +703,7 @@ namespace ts {
getOptionsDiagnostics,
getGlobalDiagnostics,
getSemanticDiagnostics,
getSuggestionDiagnostics,
getDeclarationDiagnostics,
getTypeChecker,
getClassifiableNames,
@@ -703,6 +721,7 @@ namespace ts {
isSourceFileDefaultLibrary,
dropDiagnosticsProducingTypeChecker,
getSourceFileFromReference,
getLibFileFromReference,
sourceFileToPackageName,
redirectTargetsSet,
isEmittedFile,
@@ -717,6 +736,21 @@ namespace ts {
return program;
function compareDefaultLibFiles(a: SourceFile, b: SourceFile) {
return compareValues(getDefaultLibFilePriority(a), getDefaultLibFilePriority(b));
}
function getDefaultLibFilePriority(a: SourceFile) {
if (containsPath(defaultLibraryPath, a.fileName, /*ignoreCase*/ false)) {
const basename = getBaseFileName(a.fileName);
if (basename === "lib.d.ts" || basename === "lib.es6.d.ts") return 0;
const name = removeSuffix(removePrefix(basename, "lib."), ".d.ts");
const index = libs.indexOf(name);
if (index !== -1) return index + 1;
}
return libs.length + 2;
}
function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined {
return moduleResolutionCache && resolveModuleNameFromCache(moduleName, containingFile, moduleResolutionCache);
}
@@ -1039,6 +1073,11 @@ namespace ts {
if (fileChanged) {
// The `newSourceFile` object was created for the new program.
if (!arrayIsEqualTo(oldSourceFile.libReferenceDirectives, newSourceFile.libReferenceDirectives, fileReferenceIsEqualTo)) {
// 'lib' references has changed. Matches behavior in changesAffectModuleResolution
return oldProgram.structureIsReused = StructureIsReused.Not;
}
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
@@ -1171,6 +1210,9 @@ namespace ts {
writeFile: writeFileCallback || (
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
isEmitBlocked,
readFile: f => host.readFile(f),
fileExists: f => host.fileExists(f),
...(host.directoryExists ? { directoryExists: f => host.directoryExists!(f) } : {}),
};
}
@@ -1427,6 +1469,12 @@ namespace ts {
});
}
function getSuggestionDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): ReadonlyArray<DiagnosticWithLocation> {
return runWithCancellationToken(() => {
return getDiagnosticsProducingTypeChecker().getSuggestionDiagnostics(sourceFile, cancellationToken);
});
}
/**
* Skip errors if previous line start with '// @ts-ignore' comment, not counting non-empty non-comment lines
*/
@@ -1696,8 +1744,8 @@ namespace ts {
return configFileParsingDiagnostics || emptyArray;
}
function processRootFile(fileName: string, isDefaultLib: boolean) {
processSourceFile(normalizePath(fileName), isDefaultLib, /*packageId*/ undefined);
function processRootFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean) {
processSourceFile(normalizePath(fileName), isDefaultLib, ignoreNoDefaultLib, /*packageId*/ undefined);
}
function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean {
@@ -1807,11 +1855,9 @@ namespace ts {
else if (isLiteralImportTypeNode(node)) {
imports = append(imports, node.argument.literal);
}
else {
collectDynamicImportOrRequireCallsForEachChild(node);
if (hasJSDocNodes(node)) {
forEach(node.jsDoc, collectDynamicImportOrRequireCallsForEachChild);
}
collectDynamicImportOrRequireCallsForEachChild(node);
if (hasJSDocNodes(node)) {
forEach(node.jsDoc, collectDynamicImportOrRequireCallsForEachChild);
}
}
@@ -1820,6 +1866,14 @@ namespace ts {
}
}
function getLibFileFromReference(ref: FileReference) {
const libName = ref.fileName.toLocaleLowerCase();
const libFileName = libMap.get(libName);
if (libFileName) {
return getSourceFile(combinePaths(defaultLibraryPath, libFileName));
}
}
/** This should have similar behavior to 'processSourceFile' without diagnostics or mutation. */
function getSourceFileFromReference(referencingFile: SourceFile, ref: FileReference): SourceFile | undefined {
return getSourceFileFromReferenceWorker(resolveTripleslashReference(ref.fileName, referencingFile.fileName), fileName => filesByName.get(toPath(fileName)));
@@ -1870,9 +1924,9 @@ namespace ts {
}
/** This has side effects through `findSourceFile`. */
function processSourceFile(fileName: string, isDefaultLib: boolean, packageId: PackageId | undefined, refFile?: SourceFile, refPos?: number, refEnd?: number): void {
function processSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, packageId: PackageId | undefined, refFile?: SourceFile, refPos?: number, refEnd?: number): void {
getSourceFileFromReferenceWorker(fileName,
fileName => findSourceFile(fileName, toPath(fileName), isDefaultLib, refFile!, refPos!, refEnd!, packageId), // TODO: GH#18217
fileName => findSourceFile(fileName, toPath(fileName), isDefaultLib, ignoreNoDefaultLib, refFile!, refPos!, refEnd!, packageId), // TODO: GH#18217
(diagnostic, ...args) => {
fileProcessingDiagnostics.add(refFile !== undefined && refEnd !== undefined && refPos !== undefined
? createFileDiagnostic(refFile, refPos, refEnd - refPos, diagnostic, ...args)
@@ -1910,7 +1964,7 @@ namespace ts {
}
// Get source file from normalized fileName
function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, refFile: SourceFile, refPos: number, refEnd: number, packageId: PackageId | undefined): SourceFile | undefined {
function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, refFile: SourceFile, refPos: number, refEnd: number, packageId: PackageId | undefined): SourceFile | undefined {
if (filesByName.has(path)) {
const file = filesByName.get(path);
// try to check if we've already seen this file but with a different casing in path
@@ -1928,6 +1982,8 @@ namespace ts {
processTypeReferenceDirectives(file);
}
processLibReferenceDirectives(file);
modulesWithElidedImports.set(file.path, false);
processImportedModules(file);
}
@@ -1978,7 +2034,7 @@ namespace ts {
redirectTargetsSet.set(fileFromPackageId.path, true);
filesByName.set(path, dupFile);
sourceFileToPackageName.set(path, packageId.name);
files.push(dupFile);
processingOtherFiles!.push(dupFile);
return dupFile;
}
else if (file) {
@@ -2010,21 +2066,23 @@ namespace ts {
}
}
skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib;
skipDefaultLib = skipDefaultLib || (file.hasNoDefaultLib && !ignoreNoDefaultLib);
if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
processTypeReferenceDirectives(file);
}
processLibReferenceDirectives(file);
// always process imported modules to record module name resolutions
processImportedModules(file);
if (isDefaultLib) {
files.unshift(file);
processingDefaultLibFiles!.push(file);
}
else {
files.push(file);
processingOtherFiles!.push(file);
}
}
@@ -2051,7 +2109,7 @@ namespace ts {
function processReferencedFiles(file: SourceFile, isDefaultLib: boolean) {
forEach(file.referencedFiles, ref => {
const referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
processSourceFile(referencedFileName, isDefaultLib, /*packageId*/ undefined, file, ref.pos, ref.end);
processSourceFile(referencedFileName, isDefaultLib, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined, file, ref.pos, ref.end);
});
}
@@ -2086,7 +2144,7 @@ namespace ts {
if (resolvedTypeReferenceDirective) {
if (resolvedTypeReferenceDirective.primary) {
// resolved from the primary path
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile, refPos, refEnd); // TODO: GH#18217
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile, refPos, refEnd); // TODO: GH#18217
}
else {
// If we already resolved to this file, it must have been a secondary reference. Check file contents
@@ -2109,7 +2167,7 @@ namespace ts {
}
else {
// First resolution of this library
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile, refPos, refEnd);
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, refFile, refPos, refEnd);
}
}
}
@@ -2122,6 +2180,23 @@ namespace ts {
}
}
function processLibReferenceDirectives(file: SourceFile) {
forEach(file.libReferenceDirectives, libReference => {
const libName = libReference.fileName.toLocaleLowerCase();
const libFileName = libMap.get(libName);
if (libFileName) {
// we ignore any 'no-default-lib' reference set on this file.
processRootFile(combinePaths(defaultLibraryPath, libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ true);
}
else {
const unqualifiedLibName = removeSuffix(removePrefix(libName, "lib."), ".d.ts");
const suggestion = getSpellingSuggestion(unqualifiedLibName, libs, identity);
const message = suggestion ? Diagnostics.Cannot_find_lib_definition_for_0_Did_you_mean_1 : Diagnostics.Cannot_find_lib_definition_for_0;
fileProcessingDiagnostics.add(createDiagnostic(file, libReference.pos, libReference.end, message, libName, suggestion));
}
});
}
function createDiagnostic(refFile: SourceFile, refPos: number, refEnd: number, message: DiagnosticMessage, ...args: any[]): Diagnostic {
if (refFile === undefined || refPos === undefined || refEnd === undefined) {
return createCompilerDiagnostic(message, ...args);
@@ -2182,7 +2257,7 @@ namespace ts {
else if (shouldAddFile) {
const path = toPath(resolvedFileName);
const pos = skipTrivia(file.text, file.imports[i].pos);
findSourceFile(resolvedFileName, path, /*isDefaultLib*/ false, file, pos, file.imports[i].end, resolution.packageId);
findSourceFile(resolvedFileName, path, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, file, pos, file.imports[i].end, resolution.packageId);
}
if (isFromNodeModulesSearch) {
+15 -7
View File
@@ -129,7 +129,7 @@ namespace ts {
* @param sourceFileOrBundle The input source file or bundle for the program.
*/
function initialize(filePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle, outputSourceMapDataList?: SourceMapData[]) {
if (disabled) {
if (disabled || fileExtensionIs(filePath, Extension.Json)) {
return;
}
@@ -336,7 +336,7 @@ namespace ts {
* @param pos The position.
*/
function emitPos(pos: number) {
if (disabled || positionIsSynthesized(pos)) {
if (disabled || positionIsSynthesized(pos) || isJsonSourceMapSource(currentSource)) {
return;
}
@@ -403,7 +403,7 @@ namespace ts {
* @param emitCallback The callback used to emit the node.
*/
function emitNodeWithSourceMap(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) {
if (disabled) {
if (disabled || isInJsonFile(node)) {
return emitCallback(hint, node);
}
@@ -485,7 +485,7 @@ namespace ts {
* @param emitCallback The callback used to emit the token.
*/
function emitTokenWithSourceMap(node: Node, token: SyntaxKind, writer: (s: string) => void, tokenPos: number, emitCallback: (token: SyntaxKind, writer: (s: string) => void, tokenStartPos: number) => number) {
if (disabled) {
if (disabled || isInJsonFile(node)) {
return emitCallback(token, writer, tokenPos);
}
@@ -508,6 +508,10 @@ namespace ts {
return tokenPos;
}
function isJsonSourceMapSource(sourceFile: SourceMapSource) {
return fileExtensionIs(sourceFile.fileName, Extension.Json);
}
/**
* Set the current source file.
*
@@ -521,6 +525,10 @@ namespace ts {
currentSource = sourceFile;
currentSourceText = currentSource.text;
if (isJsonSourceMapSource(sourceFile)) {
return;
}
// Add the file to tsFilePaths
// If sourceroot option: Use the relative path corresponding to the common directory path
// otherwise source locations relative to map file location
@@ -550,7 +558,7 @@ namespace ts {
* Gets the text for the source map.
*/
function getText() {
if (disabled) {
if (disabled || isJsonSourceMapSource(currentSource)) {
return undefined!; // TODO: GH#18217
}
@@ -563,7 +571,7 @@ namespace ts {
* Gets the SourceMappingURL for the source map.
*/
function getSourceMappingURL() {
if (disabled) {
if (disabled || isJsonSourceMapSource(currentSource)) {
return undefined!; // TODO: GH#18217
}
@@ -615,4 +623,4 @@ namespace ts {
return encodedStr;
}
}
}
+2 -2
View File
@@ -171,12 +171,12 @@ namespace ts {
[createModifier(SyntaxKind.DeclareKeyword)],
createLiteral(getResolvedExternalModuleName(context.getEmitHost(), sourceFile)),
createModuleBlock(setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), sourceFile.statements))
)], /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false);
)], /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
return newFile;
}
needsDeclare = true;
const updated = visitNodes(sourceFile.statements, visitDeclarationStatements);
return updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false);
return updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
}
), mapDefined(node.prepends, prepend => {
if (prepend.kind === SyntaxKind.InputFiles) {
+3 -1
View File
@@ -552,7 +552,9 @@ namespace ts {
function visitSourceFile(node: SourceFile) {
const alwaysStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") &&
!(isExternalModule(node) && moduleKind >= ModuleKind.ES2015);
!(isExternalModule(node) && moduleKind >= ModuleKind.ES2015) &&
!isJsonSourceFile(node);
return updateSourceFileNode(
node,
visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict));
+1
View File
@@ -44,6 +44,7 @@
"builderState.ts",
"builder.ts",
"resolutionCache.ts",
"moduleSpecifiers.ts",
"watch.ts",
"commandLineParser.ts",
"tsbuild.ts",
+40 -20
View File
@@ -1098,11 +1098,16 @@ namespace ts {
export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode;
export interface FunctionTypeNode extends TypeNode, SignatureDeclarationBase {
export interface FunctionOrConstructorTypeNodeBase extends TypeNode, SignatureDeclarationBase {
kind: SyntaxKind.FunctionType | SyntaxKind.ConstructorType;
type: TypeNode;
}
export interface FunctionTypeNode extends FunctionOrConstructorTypeNodeBase {
kind: SyntaxKind.FunctionType;
}
export interface ConstructorTypeNode extends TypeNode, SignatureDeclarationBase {
export interface ConstructorTypeNode extends FunctionOrConstructorTypeNodeBase {
kind: SyntaxKind.ConstructorType;
}
@@ -2566,6 +2571,7 @@ namespace ts {
moduleName?: string;
referencedFiles: ReadonlyArray<FileReference>;
typeReferenceDirectives: ReadonlyArray<FileReference>;
libReferenceDirectives: ReadonlyArray<FileReference>;
languageVariant: LanguageVariant;
isDeclarationFile: boolean;
@@ -2759,6 +2765,7 @@ namespace ts {
getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;
getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<DiagnosticWithLocation>;
getConfigFileParsingDiagnostics(): ReadonlyArray<Diagnostic>;
/* @internal */ getSuggestionDiagnostics(sourceFile: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<DiagnosticWithLocation>;
/**
* Gets a type checker that can be used to semantically analyze source files in the program.
@@ -2788,6 +2795,7 @@ namespace ts {
/* @internal */ structureIsReused?: StructureIsReused;
/* @internal */ getSourceFileFromReference(referencingFile: SourceFile, ref: FileReference): SourceFile | undefined;
/* @internal */ getLibFileFromReference(ref: FileReference): SourceFile | undefined;
/** Given a source file, get the name of the package it was imported from. */
/* @internal */ sourceFileToPackageName: Map<string>;
@@ -3080,7 +3088,7 @@ namespace ts {
* Does *not* get *all* suggestion diagnostics, just the ones that were convenient to report in the checker.
* Others are added in computeSuggestionDiagnostics.
*/
/* @internal */ getSuggestionDiagnostics(file: SourceFile): ReadonlyArray<DiagnosticWithLocation>;
/* @internal */ getSuggestionDiagnostics(file: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<DiagnosticWithLocation>;
/**
* Depending on the operation performed, it may be appropriate to throw away the checker
@@ -5029,8 +5037,9 @@ namespace ts {
}
/* @internal */
export interface EmitHost extends ScriptReferenceHost {
export interface EmitHost extends ScriptReferenceHost, ModuleSpecifierResolutionHost {
getSourceFiles(): ReadonlyArray<SourceFile>;
getCurrentDirectory(): string;
/* @internal */
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
@@ -5292,11 +5301,15 @@ namespace ts {
isAtStartOfLine(): boolean;
}
/* @internal */
export interface ModuleNameResolverHost {
getCanonicalFileName(f: string): string;
getCommonSourceDirectory(): string;
getCurrentDirectory(): string;
export interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
/** @internal */
export interface ModuleSpecifierResolutionHost extends GetEffectiveTypeRootsHost {
useCaseSensitiveFileNames?(): boolean;
fileExists?(path: string): boolean;
readFile?(path: string): string | undefined;
}
/** @deprecated See comment on SymbolWriter */
@@ -5310,7 +5323,7 @@ namespace ts {
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
reportInaccessibleUniqueSymbolError?(): void;
/* @internal */
moduleResolverHost?: ModuleNameResolverHost;
moduleResolverHost?: ModuleSpecifierResolutionHost;
/* @internal */
trackReferencedAmbientModule?(decl: ModuleDeclaration): void;
}
@@ -5464,8 +5477,12 @@ namespace ts {
}
/* @internal */
export interface PragmaDefinition<T1 extends string = string, T2 extends string = string, T3 extends string = string> {
args?: [PragmaArgumentSpecification<T1>] | [PragmaArgumentSpecification<T1>, PragmaArgumentSpecification<T2>] | [PragmaArgumentSpecification<T1>, PragmaArgumentSpecification<T2>, PragmaArgumentSpecification<T3>];
export interface PragmaDefinition<T1 extends string = string, T2 extends string = string, T3 extends string = string, T4 extends string = string> {
args?:
| [PragmaArgumentSpecification<T1>]
| [PragmaArgumentSpecification<T1>, PragmaArgumentSpecification<T2>]
| [PragmaArgumentSpecification<T1>, PragmaArgumentSpecification<T2>, PragmaArgumentSpecification<T3>]
| [PragmaArgumentSpecification<T1>, PragmaArgumentSpecification<T2>, PragmaArgumentSpecification<T3>, PragmaArgumentSpecification<T4>];
// If not present, defaults to PragmaKindFlags.Default
kind?: PragmaKindFlags;
}
@@ -5474,7 +5491,7 @@ namespace ts {
* This function only exists to cause exact types to be inferred for all the literals within `commentPragmas`
*/
/* @internal */
function _contextuallyTypePragmas<T extends {[name: string]: PragmaDefinition<K1, K2, K3>}, K1 extends string, K2 extends string, K3 extends string>(args: T): T {
function _contextuallyTypePragmas<T extends {[name: string]: PragmaDefinition<K1, K2, K3, K4>}, K1 extends string, K2 extends string, K3 extends string, K4 extends string>(args: T): T {
return args;
}
@@ -5485,6 +5502,7 @@ namespace ts {
"reference": {
args: [
{ name: "types", optional: true, captureSpan: true },
{ name: "lib", optional: true, captureSpan: true },
{ name: "path", optional: true, captureSpan: true },
{ name: "no-default-lib", optional: true }
],
@@ -5525,13 +5543,15 @@ namespace ts {
*/
/* @internal */
type PragmaArgumentType<T extends PragmaDefinition> =
T extends { args: [PragmaArgumentSpecification<infer TName1>, PragmaArgumentSpecification<infer TName2>, PragmaArgumentSpecification<infer TName3>] }
? PragmaArgTypeOptional<T["args"][0], TName1> & PragmaArgTypeOptional<T["args"][1], TName2> & PragmaArgTypeOptional<T["args"][2], TName3>
: T extends { args: [PragmaArgumentSpecification<infer TName1>, PragmaArgumentSpecification<infer TName2>] }
? PragmaArgTypeOptional<T["args"][0], TName1> & PragmaArgTypeOptional<T["args"][1], TName2>
: T extends { args: [PragmaArgumentSpecification<infer TName>] }
? PragmaArgTypeOptional<T["args"][0], TName>
: object;
T extends { args: [PragmaArgumentSpecification<infer TName1>, PragmaArgumentSpecification<infer TName2>, PragmaArgumentSpecification<infer TName3>, PragmaArgumentSpecification<infer TName4>] }
? PragmaArgTypeOptional<T["args"][0], TName1> & PragmaArgTypeOptional<T["args"][1], TName2> & PragmaArgTypeOptional<T["args"][2], TName3> & PragmaArgTypeOptional<T["args"][2], TName4>
: T extends { args: [PragmaArgumentSpecification<infer TName1>, PragmaArgumentSpecification<infer TName2>, PragmaArgumentSpecification<infer TName3>] }
? PragmaArgTypeOptional<T["args"][0], TName1> & PragmaArgTypeOptional<T["args"][1], TName2> & PragmaArgTypeOptional<T["args"][2], TName3>
: T extends { args: [PragmaArgumentSpecification<infer TName1>, PragmaArgumentSpecification<infer TName2>] }
? PragmaArgTypeOptional<T["args"][0], TName1> & PragmaArgTypeOptional<T["args"][1], TName2>
: T extends { args: [PragmaArgumentSpecification<infer TName>] }
? PragmaArgTypeOptional<T["args"][0], TName>
: object;
// The above fallback to `object` when there's no args to allow `{}` (as intended), but not the number 2, for example
// TODO: Swap to `undefined` for a cleaner API once strictNullChecks is enabled
+70 -47
View File
@@ -641,11 +641,6 @@ namespace ts {
return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2, arg3);
}
export function createDiagnosticForNodeSpan(sourceFile: SourceFile, startNode: Node, endNode: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number, arg3?: string | number): DiagnosticWithLocation {
const start = skipTrivia(sourceFile.text, startNode.pos);
return createFileDiagnostic(sourceFile, start, endNode.end - start, message, arg0, arg1, arg2, arg3);
}
export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): DiagnosticWithLocation {
const sourceFile = getSourceFileOfNode(node);
const span = getErrorSpanForNode(sourceFile, node);
@@ -1088,7 +1083,7 @@ namespace ts {
}
export function getPropertyAssignment(objectLiteral: ObjectLiteralExpression, key: string, key2?: string): ReadonlyArray<PropertyAssignment> {
return filter(objectLiteral.properties, (property): property is PropertyAssignment => {
return objectLiteral.properties.filter((property): property is PropertyAssignment => {
if (property.kind === SyntaxKind.PropertyAssignment) {
const propName = getTextOfPropertyName(property.name);
return key === propName || (!!key2 && key2 === propName);
@@ -1105,12 +1100,15 @@ namespace ts {
}
export function getTsConfigPropArrayElementValue(tsConfigSourceFile: TsConfigSourceFile | undefined, propKey: string, elementValue: string): StringLiteral | undefined {
return firstDefined(getTsConfigPropArray(tsConfigSourceFile, propKey), property =>
isArrayLiteralExpression(property.initializer) ?
find(property.initializer.elements, (element): element is StringLiteral => isStringLiteral(element) && element.text === elementValue) :
undefined);
}
export function getTsConfigPropArray(tsConfigSourceFile: TsConfigSourceFile | undefined, propKey: string): ReadonlyArray<PropertyAssignment> {
const jsonObjectLiteral = getTsConfigObjectLiteralExpression(tsConfigSourceFile);
return jsonObjectLiteral &&
firstDefined(getPropertyAssignment(jsonObjectLiteral, propKey), property =>
isArrayLiteralExpression(property.initializer) ?
find(property.initializer.elements, (element): element is StringLiteral => isStringLiteral(element) && element.text === elementValue) :
undefined);
return jsonObjectLiteral ? getPropertyAssignment(jsonObjectLiteral, propKey) : emptyArray;
}
export function getContainingFunction(node: Node): SignatureDeclaration | undefined {
@@ -1560,28 +1558,49 @@ namespace ts {
return getSourceTextOfNodeFromSourceFile(sourceFile, str).charCodeAt(0) === CharacterCodes.doubleQuote;
}
/**
* Given the symbol of a declaration, find the symbol of its Javascript container-like initializer,
* if it has one. Otherwise just return the original symbol.
*
* Container-like initializer behave like namespaces, so the binder needs to add contained symbols
* to their exports. An example is a function with assignments to `this` inside.
*/
export function getJSInitializerSymbol(symbol: Symbol | undefined) {
if (!symbol || !symbol.valueDeclaration) {
return symbol;
export function getDeclarationOfJSInitializer(node: Node): Node | undefined {
if (!isInJavaScriptFile(node) || !node.parent) {
return undefined;
}
const declaration = symbol.valueDeclaration;
const e = getDeclaredJavascriptInitializer(declaration) || getAssignedJavascriptInitializer(declaration);
return e && e.symbol ? e.symbol : symbol;
let name: Expression | BindingName | undefined;
let decl: Node | undefined;
if (isVariableDeclaration(node.parent) && node.parent.initializer === node) {
name = node.parent.name;
decl = node.parent;
}
else if (isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.EqualsToken && node.parent.right === node) {
name = node.parent.left;
decl = name;
}
else if (isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.BarBarToken) {
if (isVariableDeclaration(node.parent.parent) && node.parent.parent.initializer === node.parent) {
name = node.parent.parent.name;
decl = node.parent.parent;
}
else if (isBinaryExpression(node.parent.parent) && node.parent.parent.operatorToken.kind === SyntaxKind.EqualsToken && node.parent.parent.right === node.parent) {
name = node.parent.parent.left;
decl = name;
}
if (!name || !isEntityNameExpression(name) || !isSameEntityName(name, node.parent.left)) {
return undefined;
}
}
if (!name || !getJavascriptInitializer(node, isPrototypeAccess(name))) {
return undefined;
}
return decl;
}
/** Get the declaration initializer, when the initializer is container-like (See getJavascriptInitializer) */
export function getDeclaredJavascriptInitializer(node: Node) {
if (node && isVariableDeclaration(node) && node.initializer) {
return getJavascriptInitializer(node.initializer, /*isPrototypeAssignment*/ false) ||
isIdentifier(node.name) && getDefaultedJavascriptInitializer(node.name, node.initializer, /*isPrototypeAssignment*/ false);
/** Get the initializer, taking into account defaulted Javascript initializers */
export function getEffectiveInitializer(node: HasExpressionInitializer) {
if (isInJavaScriptFile(node) && node.initializer &&
isBinaryExpression(node.initializer) && node.initializer.operatorToken.kind === SyntaxKind.BarBarToken &&
node.name && isEntityNameExpression(node.name) && isSameEntityName(node.name, node.initializer.left)) {
return node.initializer.right;
}
return node.initializer;
}
/**
@@ -1636,6 +1655,13 @@ namespace ts {
}
}
export function isDefaultedJavascriptInitializer(node: BinaryExpression) {
const name = isVariableDeclaration(node.parent) ? node.parent.name :
isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.EqualsToken ? node.parent.left :
undefined;
return name && getJavascriptInitializer(node.right, isPrototypeAccess(name)) && isEntityNameExpression(name) && isSameEntityName(name, node.left);
}
/** Given a Javascript initializer, return the outer name. That is, the lhs of the assignment or the declaration name. */
export function getOuterNameOfJsInitializer(node: Declaration): DeclarationName | undefined {
if (isBinaryExpression(node.parent)) {
@@ -1658,7 +1684,7 @@ namespace ts {
* var min = window.min || {}
* my.app = self.my.app || class { }
*/
function isSameEntityName(name: EntityNameExpression, initializer: EntityNameExpression): boolean {
function isSameEntityName(name: Expression, initializer: Expression): boolean {
if (isIdentifier(name) && isIdentifier(initializer)) {
return name.escapedText === initializer.escapedText;
}
@@ -2916,11 +2942,11 @@ namespace ts {
};
}
export function getResolvedExternalModuleName(host: ModuleNameResolverHost, file: SourceFile, referenceFile?: SourceFile): string {
export function getResolvedExternalModuleName(host: EmitHost, file: SourceFile, referenceFile?: SourceFile): string {
return file.moduleName || getExternalModuleNameFromPath(host, file.fileName, referenceFile && referenceFile.fileName);
}
export function getExternalModuleNameFromDeclaration(host: ModuleNameResolverHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined {
export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined {
const file = resolver.getExternalModuleFileFromDeclaration(declaration);
if (!file || file.isDeclarationFile) {
return undefined;
@@ -2931,7 +2957,7 @@ namespace ts {
/**
* Resolves a local path to a path which is absolute to the base of the emit
*/
export function getExternalModuleNameFromPath(host: ModuleNameResolverHost, fileName: string, referencePath?: string): string {
export function getExternalModuleNameFromPath(host: EmitHost, fileName: string, referencePath?: string): string {
const getCanonicalFileName = (f: string) => host.getCanonicalFileName(f);
const dir = toPath(referencePath ? getDirectoryPath(referencePath) : host.getCommonSourceDirectory(), host.getCurrentDirectory(), getCanonicalFileName);
const filePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
@@ -3146,21 +3172,18 @@ namespace ts {
}
if (isJSDocTypeAlias(node)) {
Debug.assert(node.parent.kind === SyntaxKind.JSDocComment);
const templateTags = flatMap(filter(node.parent.tags, isJSDocTemplateTag), tag => tag.typeParameters) as ReadonlyArray<TypeParameterDeclaration>;
const templateTagNodes = templateTags as NodeArray<TypeParameterDeclaration>;
templateTagNodes.pos = templateTagNodes.length > 0 ? first(templateTagNodes).pos : node.pos;
templateTagNodes.end = templateTagNodes.length > 0 ? last(templateTagNodes).end : node.end;
templateTagNodes.hasTrailingComma = false;
return templateTagNodes;
return flatMap(node.parent.tags, tag => isJSDocTemplateTag(tag) ? tag.typeParameters : undefined) as ReadonlyArray<TypeParameterDeclaration>;
}
return node.typeParameters || (isInJavaScriptFile(node) ? getJSDocTypeParameterDeclarations(node) : emptyArray);
}
export function getJSDocTypeParameterDeclarations(node: DeclarationWithTypeParameters): ReadonlyArray<TypeParameterDeclaration> {
// template tags are only available when a typedef isn't already using them
const tag = find(getJSDocTags(node), (tag): tag is JSDocTemplateTag =>
isJSDocTemplateTag(tag) && !(tag.parent.kind === SyntaxKind.JSDocComment && tag.parent.tags!.some(isJSDocTypeAlias)));
return (tag && tag.typeParameters) || emptyArray;
return flatMap(getJSDocTags(node), tag => isNonTypeAliasTemplate(tag) ? tag.typeParameters : undefined);
}
/** template tags are only available when a typedef isn't already using them */
function isNonTypeAliasTemplate(tag: JSDocTag): tag is JSDocTemplateTag {
return isJSDocTemplateTag(tag) && !(tag.parent.kind === SyntaxKind.JSDocComment && tag.parent.tags!.some(isJSDocTypeAlias));
}
/**
@@ -3656,15 +3679,15 @@ namespace ts {
return output;
}
export function base64encode(host: { base64encode?(input: string): string }, input: string): string {
if (host.base64encode) {
export function base64encode(host: { base64encode?(input: string): string } | undefined, input: string): string {
if (host && host.base64encode) {
return host.base64encode(input);
}
return convertToBase64(input);
}
export function base64decode(host: { base64decode?(input: string): string }, input: string): string {
if (host.base64decode) {
export function base64decode(host: { base64decode?(input: string): string } | undefined, input: string): string {
if (host && host.base64decode) {
return host.base64decode(input);
}
const length = input.length;
+1 -1
View File
@@ -1468,7 +1468,7 @@ namespace ts {
}
return isNodeArray(statements)
? setTextRange(createNodeArray(concatenate(declarations, statements)), statements)
? setTextRange(createNodeArray(prependStatements(statements.slice(), declarations)), statements)
: prependStatements(statements, declarations);
}
+11 -1
View File
@@ -183,7 +183,7 @@ namespace compiler {
public getSourceMapRecord(): string | undefined {
if (this.result!.sourceMaps && this.result!.sourceMaps!.length > 0) {
return Harness.SourceMapRecorder.getSourceMapRecord(this.result!.sourceMaps!, this.program!, Array.from(this.js.values()), Array.from(this.dts.values()));
return Harness.SourceMapRecorder.getSourceMapRecord(this.result!.sourceMaps!, this.program!, Array.from(this.js.values()).filter(d => !ts.fileExtensionIs(d.file, ts.Extension.Json)), Array.from(this.dts.values()));
}
}
@@ -216,6 +216,16 @@ namespace compiler {
}
return vpath.changeExtension(path, ext);
}
public getNumberOfJsFiles() {
let count = this.js.size;
this.js.forEach(document => {
if (ts.fileExtensionIs(document.file, ts.Extension.Json)) {
count--;
}
});
return count;
}
}
export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | undefined, compilerOptions: ts.CompilerOptions): CompilationResult {
+23 -11
View File
@@ -1090,7 +1090,7 @@ namespace FourSlash {
}
private getNode(): ts.Node {
return ts.getTouchingPropertyName(this.getSourceFile(), this.currentCaretPosition, /*includeJsDocComment*/ false);
return ts.getTouchingPropertyName(this.getSourceFile(), this.currentCaretPosition);
}
private goToAndGetNode(range: Range): ts.Node {
@@ -2743,6 +2743,14 @@ Actual: ${stringify(fullActual)}`);
}
}
public verifyJsxClosingTag(map: { [markerName: string]: ts.JsxClosingTagInfo | undefined }): void {
for (const markerName in map) {
this.goToMarker(markerName);
const actual = this.languageService.getJsxClosingTagAtPosition(this.activeFile.fileName, this.currentCaretPosition);
assert.deepEqual(actual, map[markerName]);
}
}
public verifyMatchingBracePosition(bracePosition: number, expectedMatchPosition: number) {
const actual = this.languageService.getBraceMatchingAtPosition(this.activeFile.fileName, bracePosition);
@@ -3131,8 +3139,12 @@ Actual: ${stringify(fullActual)}`);
assert(action.name === "Move to a new file" && action.description === "Move to a new file");
const editInfo = this.languageService.getEditsForRefactor(this.activeFile.fileName, this.formatCodeSettings, range, refactor.name, action.name, options.preferences || ts.defaultPreferences)!;
for (const edit of editInfo.edits) {
const newContent = options.newFileContents[edit.fileName];
this.testNewFileContents(editInfo.edits, options.newFileContents);
}
private testNewFileContents(edits: ReadonlyArray<ts.FileTextChanges>, newFileContents: { [fileName: string]: string }): void {
for (const edit of edits) {
const newContent = newFileContents[edit.fileName];
if (newContent === undefined) {
this.raiseError(`There was an edit in ${edit.fileName} but new content was not specified.`);
}
@@ -3149,8 +3161,8 @@ Actual: ${stringify(fullActual)}`);
}
}
for (const fileName in options.newFileContents) {
assert(editInfo.edits.some(e => e.fileName === fileName));
for (const fileName in newFileContents) {
assert(edits.some(e => e.fileName === fileName));
}
}
@@ -3360,12 +3372,8 @@ Actual: ${stringify(fullActual)}`);
}
public getEditsForFileRename(options: FourSlashInterface.GetEditsForFileRenameOptions): void {
const changes = this.languageService.getEditsForFileRename(options.oldPath, options.newPath, this.formatCodeSettings);
this.applyChanges(changes);
for (const fileName in options.newFileContents) {
this.openFile(fileName);
this.verifyCurrentFileContent(options.newFileContents[fileName]);
}
const changes = this.languageService.getEditsForFileRename(options.oldPath, options.newPath, this.formatCodeSettings, ts.defaultPreferences);
this.testNewFileContents(changes, options.newFileContents);
}
private getApplicableRefactors(positionOrRange: number | ts.TextRange, preferences = ts.defaultPreferences): ReadonlyArray<ts.ApplicableRefactorInfo> {
@@ -4079,6 +4087,10 @@ namespace FourSlashInterface {
this.state.verifyBraceCompletionAtPosition(this.negative, openingBrace);
}
public jsxClosingTag(map: { [markerName: string]: ts.JsxClosingTagInfo | undefined }): void {
this.state.verifyJsxClosingTag(map);
}
public isInCommentAtPosition(onlyMultiLineDiverges?: boolean) {
this.state.verifySpanOfEnclosingComment(this.negative, onlyMultiLineDiverges);
}
+2 -2
View File
@@ -1270,7 +1270,7 @@ namespace Harness {
throw new Error("Only declaration files should be generated when emitDeclarationOnly:true");
}
}
else if (result.dts.size !== result.js.size) {
else if (result.dts.size !== result.getNumberOfJsFiles()) {
throw new Error("There were no errors and declFiles generated did not match number of js files generated");
}
}
@@ -1645,7 +1645,7 @@ namespace Harness {
return;
}
else if (options.sourceMap || declMaps) {
if (result.maps.size !== (result.js.size * (declMaps && options.sourceMap ? 2 : 1))) {
if (result.maps.size !== (result.getNumberOfJsFiles() * (declMaps && options.sourceMap ? 2 : 1))) {
throw new Error("Number of sourcemap files should be same as js files.");
}
+6 -2
View File
@@ -509,6 +509,9 @@ namespace Harness.LanguageService {
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));
}
getJsxClosingTagAtPosition(): never {
throw new Error("Not supported on the shim.");
}
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): ts.TextSpan {
return unwrapJSONCallResult(this.shim.getSpanOfEnclosingComment(fileName, position, onlyMultiLine));
}
@@ -573,7 +576,8 @@ namespace Harness.LanguageService {
importedFiles: [],
ambientExternalModules: [],
isLibFile: shimResult.isLibFile,
typeReferenceDirectives: []
typeReferenceDirectives: [],
libReferenceDirectives: []
};
ts.forEach(shimResult.referencedFiles, refFile => {
@@ -794,7 +798,7 @@ namespace Harness.LanguageService {
const proxy = makeDefaultProxy(info);
proxy.getSemanticDiagnostics = filename => {
const prev = info.languageService.getSemanticDiagnostics(filename);
const sourceFile: ts.SourceFile = info.languageService.getSourceFile(filename);
const sourceFile: ts.SourceFile = info.project.getSourceFile(ts.toPath(filename, /*basePath*/ undefined, ts.createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
prev.push({
category: ts.DiagnosticCategory.Warning,
file: sourceFile,
+1 -1
View File
@@ -51,6 +51,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/tsbuild.ts",
"../compiler/commandLineParser.ts",
@@ -116,7 +117,6 @@
"../services/codefixes/inferFromUsage.ts",
"../services/codefixes/fixInvalidImportSyntax.ts",
"../services/codefixes/fixStrictClassInitialization.ts",
"../services/codefixes/moduleSpecifiers.ts",
"../services/codefixes/requireInTs.ts",
"../services/codefixes/useDefaultImport.ts",
"../services/codefixes/fixAddModuleReferTypeMissingTypeof.ts",
@@ -56,9 +56,19 @@ namespace ts {
r => assert.exists(r.displayParts)
);
});
it("can cancel suggestion diagnostics mid-request", () => {
verifyOperationCancelledAfter(file, 1, service => // The LS doesn't do any top-level checks on the token for suggestion diagnostics, so the first check is within the checker
service.getSuggestionDiagnostics("file.js"),
r => assert.notEqual(r.length, 0),
"file.js",
"function foo() { let a = 10; }",
{ allowJs: true }
);
});
});
function verifyOperationCancelledAfter<T>(content: string, cancelAfter: number, operation: (service: LanguageService) => T, validator: (arg: T) => void) {
function verifyOperationCancelledAfter<T>(content: string, cancelAfter: number, operation: (service: LanguageService) => T, validator: (arg: T) => void, fileName?: string, fileContent?: string, options?: CompilerOptions) {
let checks = 0;
const token: HostCancellationToken = {
isCancellationRequested() {
@@ -70,9 +80,9 @@ namespace ts {
return result;
}
};
const adapter = new Harness.LanguageService.NativeLanguageServiceAdapter(token);
const adapter = new Harness.LanguageService.NativeLanguageServiceAdapter(token, options);
const host = adapter.getHost();
host.addScript("file.ts", content, /*isRootFile*/ true);
host.addScript(fileName || "file.ts", fileContent || content, /*isRootFile*/ true);
const service = adapter.getLanguageService();
assertCancelled(() => operation(service));
validator(operation(service));
@@ -92,4 +102,4 @@ namespace ts {
assert.exists(caught, "Expected operation to be cancelled, but was not");
assert.instanceOf(caught, OperationCanceledException);
}
}
}
+3 -3
View File
@@ -60,7 +60,7 @@ namespace ts {
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
@@ -262,7 +262,7 @@ namespace ts {
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
@@ -281,7 +281,7 @@ namespace ts {
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
{
errors: [{
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
file: undefined,
@@ -268,7 +268,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -299,7 +299,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -330,7 +330,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -361,7 +361,7 @@ namespace ts {
file: undefined,
start: 0,
length: 0,
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.asynciterable'.",
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'webworker.importscripts', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'esnext.array', 'esnext.symbol', 'esnext.asynciterable'.",
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category
}]
@@ -9,7 +9,7 @@ describe("forAwaitOfEvaluation", () => {
case 0: return { value: 1, done: false };
case 1: return { value: Promise.resolve(2), done: false };
case 2: return { value: new Promise<number>(resolve => setTimeout(resolve, 100, 3)), done: false };
default: return { value: undefined: done: true };
default: return { value: undefined, done: true };
}
}
};
@@ -35,7 +35,7 @@ describe("forAwaitOfEvaluation", () => {
case 0: return { value: 1, done: false };
case 1: return { value: Promise.resolve(2), done: false };
case 2: return { value: new Promise<number>(resolve => setTimeout(resolve, 100, 3)), done: false };
default: return { value: undefined: done: true };
default: return { value: undefined, done: true };
}
}
};
@@ -61,7 +61,7 @@ describe("forAwaitOfEvaluation", () => {
case 0: return { value: 1, done: false };
case 1: return { value: Promise.resolve(2), done: false };
case 2: return { value: new Promise<number>(resolve => setTimeout(resolve, 100, 3)), done: false };
default: return { value: undefined: done: true };
default: return { value: undefined, done: true };
}
}
};
@@ -87,7 +87,7 @@ describe("forAwaitOfEvaluation", () => {
case 0: return { value: 1, done: false };
case 1: return { value: Promise.resolve(2), done: false };
case 2: return { value: new Promise<number>(resolve => setTimeout(resolve, 100, 3)), done: false };
default: return { value: undefined: done: true };
default: return { value: undefined, done: true };
}
}
};
@@ -102,4 +102,4 @@ describe("forAwaitOfEvaluation", () => {
assert.instanceOf(result.output[1], Promise);
assert.instanceOf(result.output[2], Promise);
});
});
});
@@ -9,6 +9,7 @@ describe("PreProcessFile:", () => {
checkFileReferenceList("Imported files", expectedPreProcess.importedFiles, resultPreProcess.importedFiles);
checkFileReferenceList("Referenced files", expectedPreProcess.referencedFiles, resultPreProcess.referencedFiles);
checkFileReferenceList("Type reference directives", expectedPreProcess.typeReferenceDirectives, resultPreProcess.typeReferenceDirectives);
checkFileReferenceList("Lib reference directives", expectedPreProcess.libReferenceDirectives, resultPreProcess.libReferenceDirectives);
assert.deepEqual(resultPreProcess.ambientExternalModules, expectedPreProcess.ambientExternalModules);
}
@@ -41,6 +42,7 @@ describe("PreProcessFile:", () => {
{ fileName: "refFile3.ts", pos: 94, end: 105 }, { fileName: "..\\refFile4d.ts", pos: 131, end: 146 }],
importedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
ambientExternalModules: undefined,
isLibFile: false
});
@@ -54,6 +56,7 @@ describe("PreProcessFile:", () => {
referencedFiles: <ts.FileReference[]>[],
importedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
ambientExternalModules: undefined,
isLibFile: false
});
@@ -67,6 +70,7 @@ describe("PreProcessFile:", () => {
referencedFiles: <ts.FileReference[]>[],
importedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
ambientExternalModules: undefined,
isLibFile: false
});
@@ -80,6 +84,7 @@ describe("PreProcessFile:", () => {
referencedFiles: <ts.FileReference[]>[],
importedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
ambientExternalModules: undefined,
isLibFile: false
});
@@ -92,6 +97,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [{ fileName: "r1.ts", pos: 20, end: 25 }, { fileName: "r2.ts", pos: 49, end: 54 }, { fileName: "r3.ts", pos: 78, end: 83 },
{ fileName: "r4.ts", pos: 106, end: 111 }, { fileName: "r5.ts", pos: 138, end: 143 }],
ambientExternalModules: undefined,
@@ -106,6 +112,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: <ts.FileReference[]>[],
ambientExternalModules: undefined,
isLibFile: false
@@ -119,6 +126,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: <ts.FileReference[]>[],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [{ fileName: "r3.ts", pos: 73, end: 78 }],
ambientExternalModules: undefined,
isLibFile: false
@@ -132,6 +140,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [{ fileName: "refFile1.ts", pos: 20, end: 31 }, { fileName: "refFile2.ts", pos: 57, end: 68 }],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [{ fileName: "r1.ts", pos: 92, end: 97 }, { fileName: "r2.ts", pos: 121, end: 126 }],
ambientExternalModules: undefined,
isLibFile: false
@@ -145,6 +154,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [{ fileName: "refFile1.ts", pos: 20, end: 31 }],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [{ fileName: "r1.ts", pos: 91, end: 96 }, { fileName: "r3.ts", pos: 148, end: 153 }],
ambientExternalModules: undefined,
isLibFile: false
@@ -164,6 +174,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m1", pos: 20, end: 22 },
{ fileName: "m2", pos: 51, end: 53 },
@@ -188,6 +199,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m1", pos: 14, end: 16 },
{ fileName: "m2", pos: 36, end: 38 },
@@ -212,6 +224,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [],
ambientExternalModules: ["B"],
isLibFile: false
@@ -225,6 +238,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m1", pos: 26, end: 28 }
],
@@ -244,6 +258,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m1", pos: 39, end: 41 },
{ fileName: "m2", pos: 74, end: 76 },
@@ -264,6 +279,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "mod1", pos: 21, end: 25 },
{ fileName: "mod2", pos: 29, end: 33 },
@@ -282,6 +298,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "mod1", pos: 28, end: 32 },
{ fileName: "mod2", pos: 36, end: 40 },
@@ -303,6 +320,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "../Observable", pos: 28, end: 41 }
],
@@ -323,6 +341,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m", pos: 123, end: 124 },
{ fileName: "../Observable", pos: 28, end: 41 }
@@ -344,6 +363,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m", pos: 123, end: 124 },
{ fileName: "../Observable", pos: 28, end: 41 }
@@ -365,6 +385,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "../Observable", pos: 28, end: 41 }
],
@@ -385,6 +406,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "../Observable", pos: 28, end: 41 }
],
@@ -404,6 +426,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "../Observable", pos: 28, end: 41 }
],
@@ -425,6 +448,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m2", pos: 65, end: 67 },
{ fileName: "augmentation", pos: 102, end: 114 }
@@ -449,6 +473,7 @@ describe("PreProcessFile:", () => {
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [
{ fileName: "m2", pos: 127, end: 129 },
{ fileName: "augmentation", pos: 164, end: 176 }
@@ -475,6 +500,32 @@ describe("PreProcessFile:", () => {
{ pos: 73, end: 75, fileName: "a1" },
{ pos: 152, end: 154, fileName: "a3" }
],
libReferenceDirectives: [],
importedFiles: [],
ambientExternalModules: undefined,
isLibFile: false
});
});
it ("correctly recognizes lib reference directives", () => {
test(`
/// <reference path="a"/>
/// <reference lib="a1"/>
/// <reference path="a2"/>
/// <reference lib="a3"/>
`,
/*readImportFile*/ true,
/*detectJavaScriptImports*/ false,
{
referencedFiles: [
{ pos: 34, end: 35, fileName: "a" },
{ pos: 110, end: 112, fileName: "a2" }
],
typeReferenceDirectives: [
],
libReferenceDirectives: [
{ pos: 71, end: 73, fileName: "a1" },
{ pos: 148, end: 150, fileName: "a3" }
],
importedFiles: [],
ambientExternalModules: undefined,
isLibFile: false
+1
View File
@@ -224,6 +224,7 @@ namespace ts.server {
CommandNames.Occurrences,
CommandNames.DocumentHighlights,
CommandNames.DocumentHighlightsFull,
CommandNames.JsxClosingTag,
CommandNames.Open,
CommandNames.Quickinfo,
CommandNames.QuickinfoFull,
+1 -1
View File
@@ -267,7 +267,7 @@ namespace ts {
const fs = vfs.createFromFileSystem(Harness.IO, /*caseSensitive*/ true, { documents: [new documents.TextDocument("/.src/index.ts", text)] });
const host = new fakes.CompilerHost(fs, opts.compilerOptions);
const program = createProgram(["/.src/index.ts"], opts.compilerOptions!, host);
program.emit(program.getSourceFiles()[1], (p, s, bom) => host.writeFile(p, s, bom), /*cancellationToken*/ undefined, /*onlyDts*/ true, opts.transformers);
program.emit(program.getSourceFile("/.src/index.ts"), (p, s, bom) => host.writeFile(p, s, bom), /*cancellationToken*/ undefined, /*onlyDts*/ true, opts.transformers);
return fs.readFileSync("/.src/index.d.ts").toString();
}
+11 -3
View File
@@ -8400,15 +8400,23 @@ new C();`
path: "/user.ts",
content: 'import { x } from "./old";',
};
const newTs: File = {
path: "/new.ts",
content: "export const x = 0;",
};
const tsconfig: File = {
path: "/tsconfig.json",
content: "{}",
};
const host = createServerHost([userTs]);
const host = createServerHost([userTs, newTs, tsconfig]);
const projectService = createProjectService(host);
projectService.openClientFile(userTs.path);
const project = first(projectService.inferredProjects);
const project = projectService.configuredProjects.get(tsconfig.path)!;
Debug.assert(!!project.resolveModuleNames);
const edits = project.getLanguageService().getEditsForFileRename("/old.ts", "/new.ts", testFormatOptions);
const edits = project.getLanguageService().getEditsForFileRename("/old.ts", "/new.ts", testFormatOptions, defaultPreferences);
assert.deepEqual<ReadonlyArray<FileTextChanges>>(edits, [{
fileName: "/user.ts",
textChanges: [{
+21
View File
@@ -1340,6 +1340,27 @@ namespace ts.projectSystem {
assert.deepEqual(result.newTypingNames, ["bar"]);
});
it("should gracefully handle packages that have been removed from the types-registry", () => {
const f = {
path: "/a/b/app.js",
content: ""
};
const node = {
path: "/a/b/node.d.ts",
content: ""
};
const host = createServerHost([f, node]);
const cache = createMapFromTemplate<JsTyping.CachedTyping>({ node: { typingLocation: node.path, version: Semver.parse("1.3.0") } });
const logger = trackingLogger();
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, ["fs", "bar"], emptyMap);
assert.deepEqual(logger.finish(), [
'Inferred typings from unresolved imports: ["node","bar"]',
'Result: {"cachedTypingPaths":[],"newTypingNames":["node","bar"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
]);
assert.deepEqual(result.cachedTypingPaths, []);
assert.deepEqual(result.newTypingNames, ["node", "bar"]);
});
it("should search only 2 levels deep", () => {
const app = {
path: "/app.js",
+2147 -929
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
/// <reference path="lib.dom.d.ts" />
/// <reference lib="dom" />
interface DOMTokenList {
[Symbol.iterator](): IterableIterator<string>;
+188
View File
@@ -0,0 +1,188 @@
/////////////////////////////
/// DOM Iterable APIs
/////////////////////////////
interface AudioParamMap extends ReadonlyMap<string, AudioParam> {
}
interface AudioTrackList {
[Symbol.iterator](): IterableIterator<AudioTrack>;
}
interface CSSRuleList {
[Symbol.iterator](): IterableIterator<CSSRule>;
}
interface CSSStyleDeclaration {
[Symbol.iterator](): IterableIterator<string>;
}
interface ClientRectList {
[Symbol.iterator](): IterableIterator<ClientRect>;
}
interface DOMRectList {
[Symbol.iterator](): IterableIterator<DOMRect>;
}
interface DOMStringList {
[Symbol.iterator](): IterableIterator<string>;
}
interface DOMTokenList {
[Symbol.iterator](): IterableIterator<string>;
}
interface DataTransferItemList {
[Symbol.iterator](): IterableIterator<File>;
}
interface FileList {
[Symbol.iterator](): IterableIterator<File>;
}
interface FormData {
[Symbol.iterator](): IterableIterator<[string, FormDataEntryValue]>;
/**
* Returns an array of key, value pairs for every entry in the list.
*/
entries(): IterableIterator<[string, FormDataEntryValue]>;
/**
* Returns a list of keys in the list.
*/
keys(): IterableIterator<string>;
/**
* Returns a list of values in the list.
*/
values(): IterableIterator<FormDataEntryValue>;
}
interface HTMLAllCollection {
[Symbol.iterator](): IterableIterator<Element>;
}
interface HTMLCollectionBase {
[Symbol.iterator](): IterableIterator<Element>;
}
interface HTMLCollectionOf<T extends Element> {
[Symbol.iterator](): IterableIterator<T>;
entries(): IterableIterator<[number, T]>;
keys(): IterableIterator<number>;
values(): IterableIterator<T>;
}
interface HTMLSelectElement {
[Symbol.iterator](): IterableIterator<Element>;
}
interface Headers {
[Symbol.iterator](): IterableIterator<[string, string]>;
/**
* Returns an iterator allowing to go through all key/value pairs contained in this object.
*/
entries(): IterableIterator<[string, string]>;
/**
* Returns an iterator allowing to go through all keys of the key/value pairs contained in this object.
*/
keys(): IterableIterator<string>;
/**
* Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
*/
values(): IterableIterator<string>;
}
interface MediaList {
[Symbol.iterator](): IterableIterator<string>;
}
interface MimeTypeArray {
[Symbol.iterator](): IterableIterator<Plugin>;
}
interface NamedNodeMap {
[Symbol.iterator](): IterableIterator<Attr>;
}
interface NodeList {
[Symbol.iterator](): IterableIterator<Node>;
/**
* Returns an array of key, value pairs for every entry in the list.
*/
entries(): IterableIterator<[number, Node]>;
/**
* Returns an list of keys in the list.
*/
keys(): IterableIterator<number>;
/**
* Returns an list of values in the list.
*/
values(): IterableIterator<Node>;
}
interface NodeListOf<TNode extends Node> {
[Symbol.iterator](): IterableIterator<TNode>;
/**
* Returns an array of key, value pairs for every entry in the list.
*/
entries(): IterableIterator<[number, TNode]>;
/**
* Returns an list of keys in the list.
*/
keys(): IterableIterator<number>;
/**
* Returns an list of values in the list.
*/
values(): IterableIterator<TNode>;
}
interface Plugin {
[Symbol.iterator](): IterableIterator<MimeType>;
}
interface PluginArray {
[Symbol.iterator](): IterableIterator<Plugin>;
}
interface RTCStatsReport extends ReadonlyMap<string, any> {
}
interface SourceBufferList {
[Symbol.iterator](): IterableIterator<SourceBuffer>;
}
interface StyleSheetList {
[Symbol.iterator](): IterableIterator<StyleSheet>;
}
interface TextTrackCueList {
[Symbol.iterator](): IterableIterator<TextTrackCue>;
}
interface TextTrackList {
[Symbol.iterator](): IterableIterator<TextTrack>;
}
interface TouchList {
[Symbol.iterator](): IterableIterator<Touch>;
}
interface URLSearchParams {
[Symbol.iterator](): IterableIterator<[string, string]>;
/**
* Returns an array of key, value pairs for every entry in the search params.
*/
entries(): IterableIterator<[string, string]>;
/**
* Returns a list of keys in the search params.
*/
keys(): IterableIterator<string>;
/**
* Returns a list of values in the search params.
*/
values(): IterableIterator<string>;
}
interface VideoTrackList {
[Symbol.iterator](): IterableIterator<VideoTrack>;
}
+10 -10
View File
@@ -1,10 +1,10 @@
/// <reference path="lib.es2015.core.d.ts" />
/// <reference path="lib.es2015.collection.d.ts" />
/// <reference path="lib.es2015.generator.d.ts" />
/// <reference path="lib.es2015.promise.d.ts" />
/// <reference path="lib.es2015.iterable.d.ts" />
/// <reference path="lib.es2015.proxy.d.ts" />
/// <reference path="lib.es2015.reflect.d.ts" />
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.symbol.wellknown.d.ts" />
/// <reference path="lib.es5.d.ts" />
/// <reference lib="es5" />
/// <reference lib="es2015.core" />
/// <reference lib="es2015.collection" />
/// <reference lib="es2015.generator" />
/// <reference lib="es2015.promise" />
/// <reference lib="es2015.iterable" />
/// <reference lib="es2015.proxy" />
/// <reference lib="es2015.reflect" />
/// <reference lib="es2015.symbol" />
/// <reference lib="es2015.symbol.wellknown" />
+5
View File
@@ -0,0 +1,5 @@
/// <reference lib="es2015" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
+1 -1
View File
@@ -1,4 +1,4 @@
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference lib="es2015.symbol" />
interface SymbolConstructor {
/**
+1 -1
View File
@@ -1,4 +1,4 @@
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference lib="es2015.symbol" />
interface SymbolConstructor {
/**
+2 -2
View File
@@ -1,2 +1,2 @@
/// <reference path="lib.es2015.d.ts" />
/// <reference path="lib.es2016.array.include.d.ts" />
/// <reference lib="es2015" />
/// <reference lib="es2016.array.include" />
+5
View File
@@ -0,0 +1,5 @@
/// <reference lib="es2016" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
+6 -6
View File
@@ -1,6 +1,6 @@
/// <reference path="lib.es2016.d.ts" />
/// <reference path="lib.es2017.object.d.ts" />
/// <reference path="lib.es2017.sharedmemory.d.ts" />
/// <reference path="lib.es2017.string.d.ts" />
/// <reference path="lib.es2017.intl.d.ts" />
/// <reference path="lib.es2017.typedarrays.d.ts" />
/// <reference lib="es2016" />
/// <reference lib="es2017.object" />
/// <reference lib="es2017.sharedmemory" />
/// <reference lib="es2017.string" />
/// <reference lib="es2017.intl" />
/// <reference lib="es2017.typedarrays" />
+5
View File
@@ -0,0 +1,5 @@
/// <reference lib="es2017" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
+2 -2
View File
@@ -1,5 +1,5 @@
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.symbol.wellknown.d.ts" />
/// <reference lib="es2015.symbol" />
/// <reference lib="es2015.symbol.wellknown" />
interface SharedArrayBuffer {
/**
+4 -4
View File
@@ -1,4 +1,4 @@
/// <reference path="lib.es2017.d.ts" />
/// <reference path="lib.es2018.promise.d.ts" />
/// <reference path="lib.es2018.regexp.d.ts" />
/// <reference path="lib.es2018.intl.d.ts" />
/// <reference lib="es2017" />
/// <reference lib="es2018.promise" />
/// <reference lib="es2018.regexp" />
/// <reference lib="es2018.intl" />
+5
View File
@@ -0,0 +1,5 @@
/// <reference lib="es2018" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
+4
View File
@@ -0,0 +1,4 @@
/// <reference lib="es5" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
+19 -19
View File
@@ -3,7 +3,7 @@ interface ReadonlyArray<T> {
/**
* Calls a defined callback function on each element of an array. Then, flattens the result into
* a new array.
* This is identical to a map followed by a flatten of depth 1.
* This is identical to a map followed by flat with depth 1.
*
* @param callback A function that accepts up to three arguments. The flatMap method calls the
* callback function one time for each element in the array.
@@ -22,7 +22,7 @@ interface ReadonlyArray<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this:
flat<U>(this:
ReadonlyArray<U[][][][]> |
ReadonlyArray<ReadonlyArray<U[][][]>> |
@@ -51,7 +51,7 @@ interface ReadonlyArray<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this:
flat<U>(this:
ReadonlyArray<U[][][]> |
ReadonlyArray<ReadonlyArray<U>[][]> |
@@ -71,7 +71,7 @@ interface ReadonlyArray<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this:
flat<U>(this:
ReadonlyArray<U[][]> |
ReadonlyArray<ReadonlyArray<U[]>> |
@@ -86,7 +86,7 @@ interface ReadonlyArray<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this:
flat<U>(this:
ReadonlyArray<U[]> |
ReadonlyArray<ReadonlyArray<U>>,
depth?: 1
@@ -98,18 +98,18 @@ interface ReadonlyArray<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this:
flat<U>(this:
ReadonlyArray<U>,
depth: 0
): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth. If no depth is provided, flatten method defaults to the depth of 1.
* specified depth. If no depth is provided, flat method defaults to the depth of 1.
*
* @param depth The maximum recursion depth
*/
flatten<U>(depth?: number): any[];
flat<U>(depth?: number): any[];
}
interface Array<T> {
@@ -117,7 +117,7 @@ interface Array<T> {
/**
* Calls a defined callback function on each element of an array. Then, flattens the result into
* a new array.
* This is identical to a map followed by a flatten of depth 1.
* This is identical to a map followed by flat with depth 1.
*
* @param callback A function that accepts up to three arguments. The flatMap method calls the
* callback function one time for each element in the array.
@@ -135,7 +135,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][][][][][][][], depth: 7): U[];
flat<U>(this: U[][][][][][][][], depth: 7): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -143,7 +143,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][][][][][][], depth: 6): U[];
flat<U>(this: U[][][][][][][], depth: 6): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -151,7 +151,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][][][][][], depth: 5): U[];
flat<U>(this: U[][][][][][], depth: 5): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -159,7 +159,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][][][][], depth: 4): U[];
flat<U>(this: U[][][][][], depth: 4): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -167,7 +167,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][][][], depth: 3): U[];
flat<U>(this: U[][][][], depth: 3): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -175,7 +175,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][][], depth: 2): U[];
flat<U>(this: U[][][], depth: 2): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -183,7 +183,7 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[][], depth?: 1): U[];
flat<U>(this: U[][], depth?: 1): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
@@ -191,13 +191,13 @@ interface Array<T> {
*
* @param depth The maximum recursion depth
*/
flatten<U>(this: U[], depth: 0): U[];
flat<U>(this: U[], depth: 0): U[];
/**
* Returns a new array with all sub-array elements concatenated into it recursively up to the
* specified depth. If no depth is provided, flatten method defaults to the depth of 1.
* specified depth. If no depth is provided, flat method defaults to the depth of 1.
*
* @param depth The maximum recursion depth
*/
flatten<U>(depth?: number): any[];
flat<U>(depth?: number): any[];
}
+2 -2
View File
@@ -1,5 +1,5 @@
/// <reference path="lib.es2015.symbol.d.ts" />
/// <reference path="lib.es2015.iterable.d.ts" />
/// <reference lib="es2015.symbol" />
/// <reference lib="es2015.iterable" />
interface SymbolConstructor {
/**
+4 -3
View File
@@ -1,3 +1,4 @@
/// <reference path="lib.es2018.d.ts" />
/// <reference path="lib.esnext.asynciterable.d.ts" />
/// <reference path="lib.esnext.array.d.ts" />
/// <reference lib="es2018" />
/// <reference lib="esnext.asynciterable" />
/// <reference lib="esnext.array" />
/// <reference lib="esnext.symbol" />
+5
View File
@@ -0,0 +1,5 @@
/// <reference lib="esnext" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
+6
View File
@@ -0,0 +1,6 @@
interface Symbol {
/**
* expose the [[Description]] internal slot of a symbol directly
*/
readonly description: string;
}
+4 -53
View File
@@ -9,8 +9,9 @@
"esnext",
// Host only
"dom.generated",
"dom.iterable",
"dom.iterable.generated",
"webworker.generated",
"webworker.importscripts",
"scripthost",
// By-feature options
"es2015.core",
@@ -33,6 +34,7 @@
"es2018.intl",
"esnext.asynciterable",
"esnext.array",
"esnext.symbol",
// Default libraries
"es5.full",
"es2015.full",
@@ -43,60 +45,9 @@
],
"paths": {
"dom.generated": "lib.dom.d.ts",
"dom.iterable.generated": "lib.dom.iterable.d.ts",
"webworker.generated": "lib.webworker.d.ts",
"es5.full": "lib.d.ts",
"es2015.full": "lib.es6.d.ts"
},
"sources": {
"es5.full": [
"es5.d.ts",
"dom.generated.d.ts",
"webworker.importscripts.d.ts",
"scripthost.d.ts"
],
"es2015.full": [
"es5.d.ts",
"es2015.core.d.ts",
"es2015.collection.d.ts",
"es2015.generator.d.ts",
"es2015.iterable.d.ts",
"es2015.promise.d.ts",
"es2015.proxy.d.ts",
"es2015.reflect.d.ts",
"es2015.symbol.d.ts",
"es2015.symbol.wellknown.d.ts",
"dom.generated.d.ts",
"webworker.importscripts.d.ts",
"scripthost.d.ts",
"dom.iterable.d.ts"
],
"es2016.full": [
"es2016.d.ts",
"dom.generated.d.ts",
"webworker.importscripts.d.ts",
"scripthost.d.ts",
"dom.iterable.d.ts"
],
"es2017.full": [
"es2017.d.ts",
"dom.generated.d.ts",
"webworker.importscripts.d.ts",
"scripthost.d.ts",
"dom.iterable.d.ts"
],
"es2018.full": [
"es2018.d.ts",
"dom.generated.d.ts",
"webworker.importscripts.d.ts",
"scripthost.d.ts",
"dom.iterable.d.ts"
],
"esnext.full": [
"esnext.d.ts",
"dom.generated.d.ts",
"webworker.importscripts.d.ts",
"scripthost.d.ts",
"dom.iterable.d.ts"
]
}
}
+1159 -327
View File
File diff suppressed because it is too large Load Diff
@@ -2619,6 +2619,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[将命名导入转换为命名空间导入]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[将命名空间导入转换为命名导入]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5433,6 +5451,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[对象的类型为 "unknown"。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2619,6 +2619,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[將具名匯入轉換為命名空間匯入]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[將命名空間匯入轉換為具名匯入]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5433,6 +5451,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[物件的類型為 '未知'。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2628,6 +2628,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Převést pojmenované importy na import oboru názvů]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Převést import oboru názvů na pojmenované importy]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5442,6 +5460,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Objekt je typu Neznámý.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2616,6 +2616,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Benannte Importe in Namespaceimport konvertieren]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Namespaceimport in benannte Importe konvertieren]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5430,6 +5448,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Das Objekt ist vom Typ "Unbekannt".]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -8676,6 +8703,12 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces_1069" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Unexpected token. A type parameter name was expected without curly braces.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Unexpected_token_expected_1179" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Unexpected token. '{' expected.]]></Val>
@@ -2406,6 +2406,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Class_name_cannot_be_Object_when_targeting_ES5_with_module_0_2725" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Class name cannot be 'Object' when targeting ES5 with module {0}.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[El nombre de clase no puede ser "Object" cuando el destino es ES5 con un módulo {0}.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Class_static_side_0_incorrectly_extends_base_class_static_side_1_2417" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Class static side '{0}' incorrectly extends base class static side '{1}'.]]></Val>
@@ -2571,6 +2580,9 @@
<Item ItemId=";Convert_0_to_mapped_object_type_95055" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert '{0}' to mapped object type]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertir "{0}" en el tipo de objeto asignado]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
@@ -2619,6 +2631,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertir importaciones con nombre en una importación de espacio de nombres]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertir una importación de espacio de nombres en importaciones con nombre]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5433,6 +5463,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[El objeto es de tipo "desconocido".]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2631,6 +2631,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertir les importations nommées en importation d'espace de noms]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertir l'importation d'espace de noms en importations nommées]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5445,6 +5463,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[L'objet est de type 'unknown'.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2619,6 +2619,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertire le importazioni denominate in importazione spazi dei nomi]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Convertire l'importazione spazi dei nomi in importazioni denominate]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5433,6 +5451,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[L'oggetto è di tipo 'unknown'.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2619,6 +2619,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[名前付きインポートを名前空間インポートに変換します]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[名前空間インポートを名前付きインポートに変換します]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5433,6 +5451,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[オブジェクト型は 'unknown' です。]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -8682,6 +8709,12 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces_1069" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Unexpected token. A type parameter name was expected without curly braces.]]></Val>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Unexpected_token_expected_1179" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Unexpected token. '{' expected.]]></Val>
@@ -2619,6 +2619,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[명명된 가져오기를 네임스페이스 가져오기로 변환]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[네임스페이스 가져오기를 명명된 가져오기로 변환]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5433,6 +5451,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[개체가 '알 수 없는' 형식입니다.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2609,6 +2609,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Konwertuj importy nazwane na import przestrzeni nazw]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Konwertuj import przestrzeni nazw na importy nazwane]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5423,6 +5441,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Obiekt jest typu „nieznany”.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2612,6 +2612,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Converter importações nomeadas em importação de namespace]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Converter importação de namespace em importações nomeadas]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5426,6 +5444,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[O objeto é do tipo 'desconhecido'.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2618,6 +2618,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Преобразовать операции импорта имен в импорт пространства имен]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Преобразовать импорт пространства имен в операции импорта имен]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5432,6 +5450,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Объект имеет тип "Неизвестный".]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
@@ -2612,6 +2612,24 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_named_imports_to_namespace_import_95057" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert named imports to namespace import]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Adlandırılmış içeri aktarmaları ad alanı içeri aktarmasına dönüştür]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_namespace_import_to_named_imports_95056" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert namespace import to named imports]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Ad alanı içeri aktarmasını adlandırılmış içeri aktarmalara dönüştür]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Convert_require_to_import_95047" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Convert 'require' to 'import']]></Val>
@@ -5426,6 +5444,15 @@
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_of_type_unknown_2571" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is of type 'unknown'.]]></Val>
<Tgt Cat="Text" Stat="Loc" Orig="New">
<Val><![CDATA[Nesne 'unknown' türünde.]]></Val>
</Tgt>
</Str>
<Disp Icon="Str" />
</Item>
<Item ItemId=";Object_is_possibly_null_2531" ItemType="0" PsrId="306" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Object is possibly 'null'.]]></Val>
+4
View File
@@ -552,6 +552,10 @@ namespace ts.server {
return notImplemented();
}
getJsxClosingTagAtPosition(_fileName: string, _position: number): never {
return notImplemented();
}
getSpanOfEnclosingComment(_fileName: string, _position: number, _onlyMultiLine: boolean): TextSpan {
return notImplemented();
}
+12
View File
@@ -6,6 +6,7 @@
namespace ts.server.protocol {
// NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`.
export const enum CommandTypes {
JsxClosingTag = "jsxClosingTag",
Brace = "brace",
/* @internal */
BraceFull = "brace-full",
@@ -890,6 +891,17 @@ namespace ts.server.protocol {
openingBrace: string;
}
export interface JsxClosingTagRequest extends FileLocationRequest {
readonly command: CommandTypes.JsxClosingTag;
readonly arguments: JsxClosingTagRequestArgs;
}
export interface JsxClosingTagRequestArgs extends FileLocationRequestArgs {}
export interface JsxClosingTagResponse extends Response {
readonly body: TextInsertion;
}
/**
* @deprecated
* Get occurrences request; value of command field is
+11 -1
View File
@@ -818,6 +818,13 @@ namespace ts.server {
return this.getDiagnosticsWorker(args, /*isSemantic*/ true, (project, file) => project.getLanguageService().getSuggestionDiagnostics(file), !!args.includeLinePosition);
}
private getJsxClosingTag(args: protocol.JsxClosingTagRequestArgs): TextInsertion | undefined {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const tag = project.getLanguageService().getJsxClosingTagAtPosition(file, position);
return tag === undefined ? undefined : { newText: tag.newText, caretOffset: 0 };
}
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.DocumentHighlightsItem> | ReadonlyArray<DocumentHighlights> {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
@@ -1692,7 +1699,7 @@ namespace ts.server {
private getEditsForFileRename(args: protocol.GetEditsForFileRenameRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.FileCodeEdits> | ReadonlyArray<FileTextChanges> {
const { file, project } = this.getFileAndProject(args);
const changes = project.getLanguageService().getEditsForFileRename(args.oldFilePath, args.newFilePath, this.getFormatOptions(file));
const changes = project.getLanguageService().getEditsForFileRename(args.oldFilePath, args.newFilePath, this.getFormatOptions(file), this.getPreferences(file));
return simplifiedResult ? this.mapTextChangesToCodeEdits(project, changes) : changes;
}
@@ -2130,6 +2137,9 @@ namespace ts.server {
this.projectService.reloadProjects();
return this.notRequired();
},
[CommandNames.JsxClosingTag]: (request: protocol.JsxClosingTagRequest) => {
return this.requiredResponse(this.getJsxClosingTag(request.arguments));
},
[CommandNames.GetCodeFixes]: (request: protocol.CodeFixRequest) => {
return this.requiredResponse(this.getCodeFixes(request.arguments, /*simplifiedResult*/ true));
},
+1 -1
View File
@@ -47,6 +47,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@@ -111,7 +112,6 @@
"../services/codefixes/inferFromUsage.ts",
"../services/codefixes/fixInvalidImportSyntax.ts",
"../services/codefixes/fixStrictClassInitialization.ts",
"../services/codefixes/moduleSpecifiers.ts",
"../services/codefixes/requireInTs.ts",
"../services/codefixes/useDefaultImport.ts",
"../services/codefixes/fixAddModuleReferTypeMissingTypeof.ts",
+1 -1
View File
@@ -53,6 +53,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@@ -117,7 +118,6 @@
"../services/codefixes/inferFromUsage.ts",
"../services/codefixes/fixInvalidImportSyntax.ts",
"../services/codefixes/fixStrictClassInitialization.ts",
"../services/codefixes/moduleSpecifiers.ts",
"../services/codefixes/requireInTs.ts",
"../services/codefixes/useDefaultImport.ts",
"../services/codefixes/fixAddModuleReferTypeMissingTypeof.ts",
@@ -106,7 +106,7 @@ namespace ts.server.typingsInstaller {
if (this.log.isEnabled()) {
this.log.writeLine(`Updating ${typesRegistryPackageName} npm package...`);
}
this.execSyncAndLog(`${this.npmPath} install --ignore-scripts ${typesRegistryPackageName}`, { cwd: globalTypingsCacheLocation });
this.execSyncAndLog(`${this.npmPath} install --ignore-scripts ${typesRegistryPackageName}@${this.latestDistTag}`, { cwd: globalTypingsCacheLocation });
if (this.log.isEnabled()) {
this.log.writeLine(`Updated ${typesRegistryPackageName} npm package`);
}
@@ -350,7 +350,7 @@ namespace ts.server.typingsInstaller {
// packageName is guaranteed to exist in typesRegistry by filterTypings
const distTags = this.typesRegistry.get(packageName)!;
const newVersion = Semver.parse(distTags[`ts${versionMajorMinor}`] || distTags[latestDistTag]);
const newVersion = Semver.parse(distTags[`ts${versionMajorMinor}`] || distTags[this.latestDistTag]);
const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, version: newVersion };
this.packageNameToTypingLocation.set(packageName, newTyping);
installedTypingFiles.push(typingFile);
@@ -523,12 +523,12 @@ namespace ts.server.typingsInstaller {
protected abstract installWorker(requestId: number, packageNames: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void;
protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes): void;
protected readonly latestDistTag = "latest";
}
/* @internal */
export function typingsName(packageName: string): string {
return `@types/${packageName}@ts${versionMajorMinor}`;
}
const latestDistTag = "latest";
}
+2 -2
View File
@@ -86,8 +86,8 @@ namespace ts {
return createCombinedCodeActions(changes, commands.length === 0 ? undefined : commands);
}
function eachDiagnostic({ program, sourceFile }: CodeFixAllContext, errorCodes: number[], cb: (diag: DiagnosticWithLocation) => void): void {
for (const diag of program.getSemanticDiagnostics(sourceFile).concat(computeSuggestionDiagnostics(sourceFile, program))) {
function eachDiagnostic({ program, sourceFile, cancellationToken }: CodeFixAllContext, errorCodes: number[], cb: (diag: DiagnosticWithLocation) => void): void {
for (const diag of program.getSemanticDiagnostics(sourceFile, cancellationToken).concat(computeSuggestionDiagnostics(sourceFile, program, cancellationToken))) {
if (contains(errorCodes, diag.code)) {
cb(diag as DiagnosticWithLocation);
}
@@ -176,7 +176,7 @@ namespace ts.codefix {
return undefined;
}
const memberElements = createClassElementsFromSymbol(initializer.symbol);
const memberElements = createClassElementsFromSymbol(node.symbol);
if (initializer.body) {
memberElements.unshift(createConstructor(/*decorators*/ undefined, /*modifiers*/ undefined, initializer.parameters, initializer.body));
}
+2 -2
View File
@@ -633,7 +633,7 @@ namespace ts.Completions {
}
const { moduleSymbol } = symbolOriginInfo;
const exportedSymbol = skipAlias(symbol.exportSymbol || symbol, checker);
const exportedSymbol = checker.getMergedSymbol(skipAlias(symbol.exportSymbol || symbol, checker));
const { moduleSpecifier, codeAction } = codefix.getImportCompletionAction(
exportedSymbol,
moduleSymbol,
@@ -875,7 +875,7 @@ namespace ts.Completions {
let isStartingCloseTag = false;
let isJsxInitializer: IsJsxInitializer = false;
let location = getTouchingPropertyName(sourceFile, position, insideJsDocTagTypeExpression); // TODO: GH#15853
let location = getTouchingPropertyName(sourceFile, position);
if (contextToken) {
// Bail out if this is a known invalid completion location
if (isCompletionListBlocker(contextToken)) {
+38 -12
View File
@@ -1,7 +1,7 @@
/* @internal */
namespace ts.DocumentHighlights {
export function getDocumentHighlights(program: Program, cancellationToken: CancellationToken, sourceFile: SourceFile, position: number, sourceFilesToSearch: ReadonlyArray<SourceFile>): DocumentHighlights[] | undefined {
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
if (node.parent && (isJsxOpeningElement(node.parent) && node.parent.tagName === node || isJsxClosingElement(node.parent))) {
// For a JSX element, just highlight the matching tag, not all references.
@@ -78,6 +78,8 @@ namespace ts.DocumentHighlights {
return useParent(node.parent, isAwaitExpression, getAsyncAndAwaitOccurrences);
case SyntaxKind.AsyncKeyword:
return highlightSpans(getAsyncAndAwaitOccurrences(node));
case SyntaxKind.YieldKeyword:
return highlightSpans(getYieldOccurrences(node));
default:
return isModifierKind(node.kind) && (isDeclaration(node.parent) || isVariableStatement(node.parent))
? highlightSpans(getModifierOccurrences(node.kind, node.parent))
@@ -170,7 +172,7 @@ namespace ts.DocumentHighlights {
if (statement.kind === SyntaxKind.ContinueStatement) {
return false;
}
// falls through
// falls through
case SyntaxKind.ForStatement:
case SyntaxKind.ForInStatement:
case SyntaxKind.ForOfStatement:
@@ -237,7 +239,7 @@ namespace ts.DocumentHighlights {
}
}
function pushKeywordIf(keywordList: Push<Node>, token: Node, ...expected: SyntaxKind[]): boolean {
function pushKeywordIf(keywordList: Push<Node>, token: Node | undefined, ...expected: SyntaxKind[]): boolean {
if (token && contains(expected, token.kind)) {
keywordList.push(token);
return true;
@@ -384,18 +386,42 @@ namespace ts.DocumentHighlights {
});
}
forEachChild(func, aggregate);
forEachChild(func, child => {
traverseWithoutCrossingFunction(child, node => {
if (isAwaitExpression(node)) {
pushKeywordIf(keywords, node.getFirstToken(), SyntaxKind.AwaitKeyword);
}
});
});
return keywords;
}
function aggregate(node: Node): void {
if (isAwaitExpression(node)) {
pushKeywordIf(keywords, node.getFirstToken()!, SyntaxKind.AwaitKeyword);
}
// Do not cross function boundaries.
if (!isFunctionLike(node) && !isClassLike(node) && !isInterfaceDeclaration(node) && !isModuleDeclaration(node) && !isTypeAliasDeclaration(node) && !isTypeNode(node)) {
forEachChild(node, aggregate);
}
function getYieldOccurrences(node: Node): Node[] | undefined {
const func = getContainingFunction(node) as FunctionDeclaration;
if (!func) {
return undefined;
}
const keywords: Node[] = [];
forEachChild(func, child => {
traverseWithoutCrossingFunction(child, node => {
if (isYieldExpression(node)) {
pushKeywordIf(keywords, node.getFirstToken(), SyntaxKind.YieldKeyword);
}
});
});
return keywords;
}
// Do not cross function/class/interface/module/type boundaries.
function traverseWithoutCrossingFunction(node: Node, cb: (node: Node) => void) {
cb(node);
if (!isFunctionLike(node) && !isClassLike(node) && !isInterfaceDeclaration(node) && !isModuleDeclaration(node) && !isTypeAliasDeclaration(node) && !isTypeNode(node)) {
forEachChild(node, child => traverseWithoutCrossingFunction(child, cb));
}
}
+7 -8
View File
@@ -24,7 +24,7 @@ namespace ts.FindAllReferences {
textSpan: TextSpan;
}
export function nodeEntry(node: Node, isInString?: true): NodeEntry {
return { type: "node", node, isInString };
return { type: "node", node: (node as NamedDeclaration).name || node, isInString };
}
export interface Options {
@@ -40,7 +40,7 @@ namespace ts.FindAllReferences {
}
export function findReferencedSymbols(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number): ReferencedSymbol[] | undefined {
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
const referencedSymbols = Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken);
const checker = program.getTypeChecker();
return !referencedSymbols || !referencedSymbols.length ? undefined : mapDefined<SymbolAndEntries, ReferencedSymbol>(referencedSymbols, ({ definition, references }) =>
@@ -52,8 +52,7 @@ namespace ts.FindAllReferences {
}
export function getImplementationsAtPosition(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number): ImplementationLocation[] | undefined {
// A node in a JSDoc comment can't have an implementation anyway.
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ false);
const node = getTouchingPropertyName(sourceFile, position);
const referenceEntries = getImplementationReferenceEntries(program, cancellationToken, sourceFiles, node, position);
const checker = program.getTypeChecker();
return map(referenceEntries, entry => toImplementationLocation(entry, checker));
@@ -85,7 +84,7 @@ namespace ts.FindAllReferences {
}
export function findReferencedEntries(program: Program, cancellationToken: CancellationToken, sourceFiles: ReadonlyArray<SourceFile>, sourceFile: SourceFile, position: number, options?: Options): ReferenceEntry[] | undefined {
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
return map(flattenEntries(Core.getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options)), toReferenceEntry);
}
@@ -732,7 +731,7 @@ namespace ts.FindAllReferences.Core {
}
function getPossibleSymbolReferenceNodes(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile): ReadonlyArray<Node> {
return getPossibleSymbolReferencePositions(sourceFile, symbolName, container).map(pos => getTouchingPropertyName(sourceFile, pos, /*includeJsDocComment*/ true));
return getPossibleSymbolReferencePositions(sourceFile, symbolName, container).map(pos => getTouchingPropertyName(sourceFile, pos));
}
function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile): ReadonlyArray<number> {
@@ -836,7 +835,7 @@ namespace ts.FindAllReferences.Core {
}
function getReferencesAtLocation(sourceFile: SourceFile, position: number, search: Search, state: State, addReferencesHere: boolean): void {
const referenceLocation = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const referenceLocation = getTouchingPropertyName(sourceFile, position);
if (!isValidReferencePosition(referenceLocation, search.text)) {
// This wasn't the start of a token. Check to see if it might be a
@@ -1096,7 +1095,7 @@ namespace ts.FindAllReferences.Core {
function addImplementationReferences(refNode: Node, addReference: (node: Node) => void, state: State): void {
// Check if we found a function/propertyAssignment/method with an implementation or initializer
if (isDeclarationName(refNode) && isImplementation(refNode.parent)) {
addReference(refNode.parent);
addReference(refNode);
return;
}
+176 -55
View File
@@ -1,68 +1,189 @@
/* @internal */
namespace ts {
export function getEditsForFileRename(program: Program, oldFilePath: string, newFilePath: string, host: LanguageServiceHost, formatContext: formatting.FormatContext): ReadonlyArray<FileTextChanges> {
const pathUpdater = getPathUpdater(oldFilePath, newFilePath, host);
export function getEditsForFileRename(program: Program, oldFileOrDirPath: string, newFileOrDirPath: string, host: LanguageServiceHost, formatContext: formatting.FormatContext, preferences: UserPreferences): ReadonlyArray<FileTextChanges> {
const useCaseSensitiveFileNames = hostUsesCaseSensitiveFileNames(host);
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
const oldToNew = getPathUpdater(oldFileOrDirPath, newFileOrDirPath, getCanonicalFileName);
const newToOld = getPathUpdater(newFileOrDirPath, oldFileOrDirPath, getCanonicalFileName);
return textChanges.ChangeTracker.with({ host, formatContext }, changeTracker => {
updateTsconfigFiles(program, changeTracker, oldFilePath, newFilePath);
for (const { sourceFile, toUpdate } of getImportsToUpdate(program, oldFilePath, host)) {
const newPath = pathUpdater(isRef(toUpdate) ? toUpdate.fileName : toUpdate.text);
if (newPath !== undefined) {
const range = isRef(toUpdate) ? toUpdate : createStringRange(toUpdate, sourceFile);
changeTracker.replaceRangeWithText(sourceFile, range, isRef(toUpdate) ? newPath : removeFileExtension(newPath));
}
}
updateTsconfigFiles(program, changeTracker, oldToNew, newFileOrDirPath, host.getCurrentDirectory(), useCaseSensitiveFileNames);
updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName, preferences);
});
}
function updateTsconfigFiles(program: Program, changeTracker: textChanges.ChangeTracker, oldFilePath: string, newFilePath: string): void {
const configFile = program.getCompilerOptions().configFile;
if (!configFile) return;
const oldFile = getTsConfigPropArrayElementValue(configFile, "files", oldFilePath);
if (oldFile) {
changeTracker.replaceRangeWithText(configFile, createStringRange(oldFile, configFile), newFilePath);
}
}
interface ToUpdate {
readonly sourceFile: SourceFile;
readonly toUpdate: StringLiteralLike | FileReference;
}
function isRef(toUpdate: StringLiteralLike | FileReference): toUpdate is FileReference {
return "fileName" in toUpdate;
}
function getImportsToUpdate(program: Program, oldFilePath: string, host: LanguageServiceHost): ReadonlyArray<ToUpdate> {
const result: ToUpdate[] = [];
for (const sourceFile of program.getSourceFiles()) {
for (const ref of sourceFile.referencedFiles) {
if (resolveTripleslashReference(ref.fileName, sourceFile.fileName) === oldFilePath) {
result.push({ sourceFile, toUpdate: ref });
}
}
for (const importStringLiteral of sourceFile.imports) {
const resolved = host.resolveModuleNames
? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importStringLiteral.text, sourceFile.fileName)
: program.getResolvedModuleWithFailedLookupLocationsFromCache(importStringLiteral.text, sourceFile.fileName);
// We may or may not have picked up on the file being renamed, so maybe successfully resolved to oldFilePath, or maybe that's in failedLookupLocations
if (resolved && contains(resolved.resolvedModule ? [resolved.resolvedModule.resolvedFileName] : resolved.failedLookupLocations, oldFilePath)) {
result.push({ sourceFile, toUpdate: importStringLiteral });
}
}
}
return result;
}
function getPathUpdater(oldFilePath: string, newFilePath: string, host: LanguageServiceHost): (oldPath: string) => string | undefined {
// Get the relative path from old to new location, and append it on to the end of imports and normalize.
const rel = getRelativePathFromFile(oldFilePath, newFilePath, createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(host)));
return oldPath => {
if (!pathIsRelative(oldPath)) return;
return ensurePathIsNonModuleName(normalizePath(combinePaths(getDirectoryPath(oldPath), rel)));
/** If 'path' refers to an old directory, returns path in the new directory. */
type PathUpdater = (path: string) => string | undefined;
function getPathUpdater(oldFileOrDirPath: string, newFileOrDirPath: string, getCanonicalFileName: GetCanonicalFileName): PathUpdater {
const canonicalOldPath = getCanonicalFileName(oldFileOrDirPath);
return path => {
const canonicalPath = getCanonicalFileName(path);
if (canonicalPath === canonicalOldPath) return newFileOrDirPath;
const suffix = tryRemoveDirectoryPrefix(canonicalPath, canonicalOldPath);
return suffix === undefined ? undefined : newFileOrDirPath + "/" + suffix;
};
}
function updateTsconfigFiles(program: Program, changeTracker: textChanges.ChangeTracker, oldToNew: PathUpdater, newFileOrDirPath: string, currentDirectory: string, useCaseSensitiveFileNames: boolean): void {
const { configFile } = program.getCompilerOptions();
if (!configFile) return;
const configDir = getDirectoryPath(configFile.fileName);
const jsonObjectLiteral = getTsConfigObjectLiteralExpression(configFile);
if (!jsonObjectLiteral) return;
forEachProperty(jsonObjectLiteral, (property, propertyName) => {
switch (propertyName) {
case "files":
case "include":
case "exclude": {
const foundExactMatch = updatePaths(property);
if (!foundExactMatch && propertyName === "include" && isArrayLiteralExpression(property.initializer)) {
const includes = mapDefined(property.initializer.elements, e => isStringLiteral(e) ? e.text : undefined);
const matchers = getFileMatcherPatterns(configDir, /*excludes*/ [], includes, useCaseSensitiveFileNames, currentDirectory);
// If there isn't some include for this, add a new one.
if (!getRegexFromPattern(Debug.assertDefined(matchers.includeFilePattern), useCaseSensitiveFileNames).test(newFileOrDirPath)) {
changeTracker.insertNodeAfter(configFile, last(property.initializer.elements), createStringLiteral(relativePath(newFileOrDirPath)));
}
}
break;
}
case "compilerOptions":
forEachProperty(property.initializer, (property, propertyName) => {
const option = getOptionFromName(propertyName);
if (option && (option.isFilePath || option.type === "list" && (option as CommandLineOptionOfListType).element.isFilePath)) {
updatePaths(property);
}
else if (propertyName === "paths") {
forEachProperty(property.initializer, (pathsProperty) => {
if (!isArrayLiteralExpression(pathsProperty.initializer)) return;
for (const e of pathsProperty.initializer.elements) {
tryUpdateString(e);
}
});
}
});
break;
}
});
function updatePaths(property: PropertyAssignment): boolean {
// Type annotation needed due to #7294
const elements: ReadonlyArray<Expression> = isArrayLiteralExpression(property.initializer) ? property.initializer.elements : [property.initializer];
let foundExactMatch = false;
for (const element of elements) {
foundExactMatch = tryUpdateString(element) || foundExactMatch;
}
return foundExactMatch;
}
function tryUpdateString(element: Expression): boolean {
if (!isStringLiteral(element)) return false;
const elementFileName = combinePathsSafe(configDir, element.text);
const updated = oldToNew(elementFileName);
if (updated !== undefined) {
changeTracker.replaceRangeWithText(configFile!, createStringRange(element, configFile!), relativePath(updated));
return true;
}
return false;
}
function relativePath(path: string): string {
return getRelativePathFromDirectory(configDir, path, /*ignoreCase*/ !useCaseSensitiveFileNames);
}
}
function updateImports(
program: Program,
changeTracker: textChanges.ChangeTracker,
oldToNew: PathUpdater,
newToOld: PathUpdater,
host: LanguageServiceHost,
getCanonicalFileName: GetCanonicalFileName,
preferences: UserPreferences,
): void {
for (const sourceFile of program.getSourceFiles()) {
const newImportFromPath = oldToNew(sourceFile.fileName) || sourceFile.fileName;
const newImportFromDirectory = getDirectoryPath(newImportFromPath);
const oldFromNew: string | undefined = newToOld(sourceFile.fileName);
const oldImportFromPath: string = oldFromNew || sourceFile.fileName;
const oldImportFromDirectory = getDirectoryPath(oldImportFromPath);
updateImportsWorker(sourceFile, changeTracker,
referenceText => {
if (!pathIsRelative(referenceText)) return undefined;
const oldAbsolute = combinePathsSafe(oldImportFromDirectory, referenceText);
const newAbsolute = oldToNew(oldAbsolute);
return newAbsolute === undefined ? undefined : ensurePathIsNonModuleName(getRelativePathFromDirectory(newImportFromDirectory, newAbsolute, getCanonicalFileName));
},
importLiteral => {
const toImport = oldFromNew !== undefined
// If we're at the new location (file was already renamed), need to redo module resolution starting from the old location.
// TODO:GH#18217
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, program)
: getSourceFileToImport(importLiteral, sourceFile, program, host, oldToNew);
return toImport === undefined ? undefined : moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport, host, preferences);
});
}
}
function combineNormal(pathA: string, pathB: string): string {
return normalizePath(combinePaths(pathA, pathB));
}
function combinePathsSafe(pathA: string, pathB: string): string {
return ensurePathIsNonModuleName(combineNormal(pathA, pathB));
}
function getSourceFileToImport(importLiteral: StringLiteralLike, importingSourceFile: SourceFile, program: Program, host: LanguageServiceHost, oldToNew: PathUpdater): string | undefined {
const symbol = program.getTypeChecker().getSymbolAtLocation(importLiteral);
if (symbol) {
if (symbol.declarations.some(d => isAmbientModule(d))) return undefined; // No need to update if it's an ambient module
const oldFileName = find(symbol.declarations, isSourceFile)!.fileName;
return oldToNew(oldFileName) || oldFileName;
}
else {
const resolved = host.resolveModuleNames
? host.getResolvedModuleWithFailedLookupLocationsFromCache && host.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName)
: program.getResolvedModuleWithFailedLookupLocationsFromCache(importLiteral.text, importingSourceFile.fileName);
return getSourceFileToImportFromResolved(resolved, oldToNew, program);
}
}
function getSourceFileToImportFromResolved(resolved: ResolvedModuleWithFailedLookupLocations | undefined, oldToNew: PathUpdater, program: Program): string | undefined {
return resolved && (
(resolved.resolvedModule && getIfInProgram(resolved.resolvedModule.resolvedFileName)) || firstDefined(resolved.failedLookupLocations, getIfInProgram));
function getIfInProgram(oldLocation: string): string | undefined {
const newLocation = oldToNew(oldLocation);
return program.getSourceFile(oldLocation) || newLocation !== undefined && program.getSourceFile(newLocation)
? newLocation || oldLocation
: undefined;
}
}
function updateImportsWorker(sourceFile: SourceFile, changeTracker: textChanges.ChangeTracker, updateRef: (refText: string) => string | undefined, updateImport: (importLiteral: StringLiteralLike) => string | undefined) {
for (const ref of sourceFile.referencedFiles) {
const updated = updateRef(ref.fileName);
if (updated !== undefined && updated !== sourceFile.text.slice(ref.pos, ref.end)) changeTracker.replaceRangeWithText(sourceFile, ref, updated);
}
for (const importStringLiteral of sourceFile.imports) {
const updated = updateImport(importStringLiteral);
if (updated !== undefined && updated !== importStringLiteral.text) changeTracker.replaceRangeWithText(sourceFile, createStringRange(importStringLiteral, sourceFile), updated);
}
}
function createStringRange(node: StringLiteralLike, sourceFile: SourceFileLike): TextRange {
return createTextRange(node.getStart(sourceFile) + 1, node.end - 1);
}
function forEachProperty(objectLiteral: Expression, cb: (property: PropertyAssignment, propertyName: string) => void) {
if (!isObjectLiteralExpression(objectLiteral)) return;
for (const property of objectLiteral.properties) {
if (isPropertyAssignment(property) && isStringLiteral(property.name)) {
cb(property, property.name.text);
}
}
}
}
+22 -8
View File
@@ -6,7 +6,7 @@ namespace ts.GoToDefinition {
return [getDefinitionInfoForFileReference(reference.fileName, reference.file.fileName)];
}
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
if (node === sourceFile) {
return undefined;
}
@@ -32,11 +32,16 @@ namespace ts.GoToDefinition {
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
// For a function, if this is the original function definition, return just sigInfo.
// If this is the original constructor definition, parent is the class.
return typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
if (typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
// TODO: GH#23742 Following check shouldn't be necessary if 'require' is an alias
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))
? [sigInfo]
: [sigInfo, ...getDefinitionFromSymbol(typeChecker, symbol, node)!];
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))) {
return [sigInfo];
}
else {
const defs = getDefinitionFromSymbol(typeChecker, symbol, node)!;
// For a 'super()' call, put the signature first, else put the variable first.
return node.kind === SyntaxKind.SuperKeyword ? [sigInfo, ...defs] : [...defs, sigInfo];
}
}
// Because name in short-hand property assignment has two different meanings: property name and property value,
@@ -102,12 +107,18 @@ namespace ts.GoToDefinition {
return file && { fileName: typeReferenceDirective.fileName, file };
}
const libReferenceDirective = findReferenceInPosition(sourceFile.libReferenceDirectives, position);
if (libReferenceDirective) {
const file = program.getLibFileFromReference(libReferenceDirective);
return file && { fileName: libReferenceDirective.fileName, file };
}
return undefined;
}
/// Goto type
export function getTypeDefinitionAtPosition(typeChecker: TypeChecker, sourceFile: SourceFile, position: number): DefinitionInfo[] | undefined {
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
if (node === sourceFile) {
return undefined;
}
@@ -133,12 +144,15 @@ namespace ts.GoToDefinition {
}
// Check if position is on triple slash reference.
const comment = findReferenceInPosition(sourceFile.referencedFiles, position) || findReferenceInPosition(sourceFile.typeReferenceDirectives, position);
const comment = findReferenceInPosition(sourceFile.referencedFiles, position) ||
findReferenceInPosition(sourceFile.typeReferenceDirectives, position) ||
findReferenceInPosition(sourceFile.libReferenceDirectives, position);
if (comment) {
return { definitions, textSpan: createTextSpanFromRange(comment) };
}
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
const textSpan = createTextSpan(node.getStart(), node.getWidth());
return { definitions, textSpan };
+2 -1
View File
@@ -160,7 +160,8 @@ namespace ts.JsTyping {
}
// Add the cached typing locations for inferred typings that are already installed
packageNameToTypingLocation.forEach((typing, name) => {
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && isTypingUpToDate(typing, typesRegistry.get(name)!)) {
const registryEntry = typesRegistry.get(name);
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
inferredTypings.set(name, typing.typingLocation);
}
});
+3 -2
View File
@@ -6,6 +6,7 @@ namespace ts {
checkJsDirective: undefined,
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
amdDependencies: [],
hasNoDefaultLib: undefined,
moduleName: undefined
@@ -336,7 +337,7 @@ namespace ts {
importedFiles.push(decl.ref);
}
}
return { referencedFiles: pragmaContext.referencedFiles, typeReferenceDirectives: pragmaContext.typeReferenceDirectives, importedFiles, isLibFile: !!pragmaContext.hasNoDefaultLib, ambientExternalModules: undefined };
return { referencedFiles: pragmaContext.referencedFiles, typeReferenceDirectives: pragmaContext.typeReferenceDirectives, libReferenceDirectives: pragmaContext.libReferenceDirectives, importedFiles, isLibFile: !!pragmaContext.hasNoDefaultLib, ambientExternalModules: undefined };
}
else {
// for global scripts ambient modules still can have augmentations - look for ambient modules with depth > 0
@@ -354,7 +355,7 @@ namespace ts {
}
}
}
return { referencedFiles: pragmaContext.referencedFiles, typeReferenceDirectives: pragmaContext.typeReferenceDirectives, importedFiles, isLibFile: !!pragmaContext.hasNoDefaultLib, ambientExternalModules: ambientModuleNames };
return { referencedFiles: pragmaContext.referencedFiles, typeReferenceDirectives: pragmaContext.typeReferenceDirectives, libReferenceDirectives: pragmaContext.libReferenceDirectives, importedFiles, isLibFile: !!pragmaContext.hasNoDefaultLib, ambientExternalModules: ambientModuleNames };
}
}
}
+73 -2
View File
@@ -153,6 +153,8 @@ namespace ts.refactor {
if (sourceFile === oldFile) continue;
for (const statement of sourceFile.statements) {
forEachImportInStatement(statement, importNode => {
if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol) return;
const shouldMove = (name: Identifier): boolean => {
const symbol = isBindingElement(name.parent)
? getPropertySymbolFromBindingElement(checker, name.parent as BindingElement & { name: Identifier })
@@ -163,11 +165,76 @@ namespace ts.refactor {
const newModuleSpecifier = combinePaths(getDirectoryPath(moduleSpecifierFromImport(importNode).text), newModuleName);
const newImportDeclaration = filterImport(importNode, createLiteral(newModuleSpecifier), shouldMove);
if (newImportDeclaration) changes.insertNodeAfter(sourceFile, statement, newImportDeclaration);
const ns = getNamespaceLikeImport(importNode);
if (ns) updateNamespaceLikeImport(changes, sourceFile, checker, movedSymbols, newModuleName, newModuleSpecifier, ns, importNode);
});
}
}
}
function getNamespaceLikeImport(node: SupportedImport): Identifier | undefined {
switch (node.kind) {
case SyntaxKind.ImportDeclaration:
return node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport ?
node.importClause.namedBindings.name : undefined;
case SyntaxKind.ImportEqualsDeclaration:
return node.name;
case SyntaxKind.VariableDeclaration:
return tryCast(node.name, isIdentifier);
default:
return Debug.assertNever(node);
}
}
function updateNamespaceLikeImport(
changes: textChanges.ChangeTracker,
sourceFile: SourceFile,
checker: TypeChecker,
movedSymbols: ReadonlySymbolSet,
newModuleName: string,
newModuleSpecifier: string,
oldImportId: Identifier,
oldImportNode: SupportedImport,
): void {
const preferredNewNamespaceName = codefix.moduleSpecifierToValidIdentifier(newModuleName, ScriptTarget.ESNext);
let needUniqueName = false;
const toChange: Identifier[] = [];
FindAllReferences.Core.eachSymbolReferenceInFile(oldImportId, checker, sourceFile, ref => {
if (!isPropertyAccessExpression(ref.parent)) return;
needUniqueName = needUniqueName || !!checker.resolveName(preferredNewNamespaceName, ref, SymbolFlags.All, /*excludeGlobals*/ true);
if (movedSymbols.has(checker.getSymbolAtLocation(ref.parent.name)!)) {
toChange.push(ref);
}
});
if (toChange.length) {
const newNamespaceName = needUniqueName ? getUniqueName(preferredNewNamespaceName, sourceFile) : preferredNewNamespaceName;
for (const ref of toChange) {
changes.replaceNode(sourceFile, ref, createIdentifier(newNamespaceName));
}
changes.insertNodeAfter(sourceFile, oldImportNode, updateNamespaceLikeImportNode(oldImportNode, newModuleName, newModuleSpecifier));
}
}
function updateNamespaceLikeImportNode(node: SupportedImport, newNamespaceName: string, newModuleSpecifier: string): Node {
const newNamespaceId = createIdentifier(newNamespaceName);
const newModuleString = createLiteral(newModuleSpecifier);
switch (node.kind) {
case SyntaxKind.ImportDeclaration:
return createImportDeclaration(
/*decorators*/ undefined, /*modifiers*/ undefined,
createImportClause(/*name*/ undefined, createNamespaceImport(newNamespaceId)),
newModuleString);
case SyntaxKind.ImportEqualsDeclaration:
return createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, newNamespaceId, createExternalModuleReference(newModuleString));
case SyntaxKind.VariableDeclaration:
return createVariableDeclaration(newNamespaceId, /*type*/ undefined, createRequireCall(newModuleString));
default:
return Debug.assertNever(node);
}
}
function moduleSpecifierFromImport(i: SupportedImport): StringLiteralLike {
return (i.kind === SyntaxKind.ImportDeclaration ? i.moduleSpecifier
: i.kind === SyntaxKind.ImportEqualsDeclaration ? i.moduleReference.expression
@@ -404,7 +471,7 @@ namespace ts.refactor {
if (isInImport(decl)) {
oldImportsNeededByNewFile.add(symbol);
}
else if (isTopLevelDeclaration(decl) && !movedSymbols.has(symbol)) {
else if (isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile && !movedSymbols.has(symbol)) {
newFileImportsFromOldFile.add(symbol);
}
}
@@ -546,7 +613,11 @@ namespace ts.refactor {
interface TopLevelVariableDeclaration extends VariableDeclaration { parent: VariableDeclarationList & { parent: VariableStatement; }; }
type TopLevelDeclaration = NonVariableTopLevelDeclaration | TopLevelVariableDeclaration;
function isTopLevelDeclaration(node: Node): node is TopLevelDeclaration {
return isNonVariableTopLevelDeclaration(node) || isVariableDeclaration(node) && isSourceFile(node.parent.parent.parent);
return isNonVariableTopLevelDeclaration(node) && isSourceFile(node.parent) || isVariableDeclaration(node) && isSourceFile(node.parent.parent.parent);
}
function sourceFileOfTopLevelDeclaration(node: TopLevelDeclaration): Node {
return isVariableDeclaration(node) ? node.parent.parent.parent : node.parent;
}
function isTopLevelDeclarationStatement(node: Node): node is TopLevelDeclarationStatement {
+1 -1
View File
@@ -2,7 +2,7 @@
namespace ts.Rename {
export function getRenameInfo(typeChecker: TypeChecker, defaultLibFileName: string, getCanonicalFileName: GetCanonicalFileName, sourceFile: SourceFile, position: number): RenameInfo {
const getCanonicalDefaultLibName = memoize(() => getCanonicalFileName(normalizePath(defaultLibFileName)));
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
const renameInfo = node && nodeIsEligibleForRename(node)
? getRenameInfoForNode(node, typeChecker, sourceFile, isDefinedInLibraryFile)
: undefined;
+18 -10
View File
@@ -552,6 +552,7 @@ namespace ts {
public moduleName: string;
public referencedFiles: FileReference[];
public typeReferenceDirectives: FileReference[];
public libReferenceDirectives: FileReference[];
public syntacticDiagnostics: DiagnosticWithLocation[];
public parseDiagnostics: DiagnosticWithLocation[];
@@ -1416,7 +1417,7 @@ namespace ts {
function getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[] {
synchronizeHostData();
return computeSuggestionDiagnostics(getValidSourceFile(fileName), program);
return computeSuggestionDiagnostics(getValidSourceFile(fileName), program, cancellationToken);
}
function getCompilerOptionsDiagnostics() {
@@ -1467,7 +1468,7 @@ namespace ts {
synchronizeHostData();
const sourceFile = getValidSourceFile(fileName);
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
const node = getTouchingPropertyName(sourceFile, position);
if (node === sourceFile) {
// Avoid giving quickInfo for the sourceFile as a whole.
return undefined;
@@ -1781,15 +1782,11 @@ namespace ts {
return syntaxTreeCache.getCurrentSourceFile(fileName);
}
function getSourceFile(fileName: string): SourceFile {
return getNonBoundSourceFile(fileName);
}
function getNameOrDottedNameSpan(fileName: string, startPos: number, _endPos: number): TextSpan | undefined {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
// Get node at the location
const node = getTouchingPropertyName(sourceFile, startPos, /*includeJsDocComment*/ false);
const node = getTouchingPropertyName(sourceFile, startPos);
if (node === sourceFile) {
return undefined;
@@ -1986,8 +1983,8 @@ namespace ts {
return OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences);
}
function getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray<FileTextChanges> {
return ts.getEditsForFileRename(getProgram()!, oldFilePath, newFilePath, host, formatting.getFormatContext(formatOptions));
function getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences = defaultPreferences): ReadonlyArray<FileTextChanges> {
return ts.getEditsForFileRename(getProgram()!, oldFilePath, newFilePath, host, formatting.getFormatContext(formatOptions), preferences);
}
function applyCodeActionCommand(action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
@@ -2052,6 +2049,17 @@ namespace ts {
return true;
}
function getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
const token = findPrecedingToken(position, sourceFile);
if (!token) return undefined;
const element = token.kind === SyntaxKind.GreaterThanToken && isJsxOpeningElement(token.parent) ? token.parent.parent
: isJsxText(token) ? token.parent : undefined;
if (element && !tagNamesAreEquivalent(element.openingElement.tagName, element.closingElement.tagName)) {
return { newText: `</${element.openingElement.tagName.getText(sourceFile)}>` };
}
}
function getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
const range = formatting.getRangeOfEnclosingComment(sourceFile, position, onlyMultiLine);
@@ -2284,6 +2292,7 @@ namespace ts {
getFormattingEditsAfterKeystroke,
getDocCommentTemplateAtPosition,
isValidBraceCompletionAtPosition,
getJsxClosingTagAtPosition,
getSpanOfEnclosingComment,
getCodeFixesAtPosition,
getCombinedCodeFix,
@@ -2292,7 +2301,6 @@ namespace ts {
getEditsForFileRename,
getEmitOutput,
getNonBoundSourceFile,
getSourceFile,
getProgram,
getApplicableRefactors,
getEditsForRefactor,
+2 -1
View File
@@ -1104,7 +1104,8 @@ namespace ts {
importedFiles: this.convertFileReferences(result.importedFiles),
ambientExternalModules: result.ambientExternalModules,
isLibFile: result.isLibFile,
typeReferenceDirectives: this.convertFileReferences(result.typeReferenceDirectives)
typeReferenceDirectives: this.convertFileReferences(result.typeReferenceDirectives),
libReferenceDirectives: this.convertFileReferences(result.libReferenceDirectives)
};
});
}
+44 -35
View File
@@ -1,8 +1,7 @@
/* @internal */
namespace ts {
export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Program): DiagnosticWithLocation[] {
program.getSemanticDiagnostics(sourceFile);
const checker = program.getDiagnosticsProducingTypeChecker();
export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Program, cancellationToken: CancellationToken): DiagnosticWithLocation[] {
program.getSemanticDiagnostics(sourceFile, cancellationToken);
const diags: DiagnosticWithLocation[] = [];
if (sourceFile.commonJsModuleIndicator &&
@@ -13,39 +12,8 @@ namespace ts {
const isJsFile = isSourceFileJavaScript(sourceFile);
function check(node: Node) {
switch (node.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
if (isJsFile) {
if (node.symbol.members && (node.symbol.members.size > 0)) {
diags.push(createDiagnosticForNode(isVariableDeclaration(node.parent) ? node.parent.name : node, Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration));
}
}
break;
}
if (!isJsFile && codefix.parameterShouldGetTypeFromJSDoc(node)) {
diags.push(createDiagnosticForNode(node.name || node, Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types));
}
node.forEachChild(check);
}
check(sourceFile);
if (!isJsFile) {
for (const statement of sourceFile.statements) {
if (isVariableStatement(statement) &&
statement.declarationList.flags & NodeFlags.Const &&
statement.declarationList.declarations.length === 1) {
const init = statement.declarationList.declarations[0].initializer;
if (init && isRequireCall(init, /*checkArgumentIsStringLiteralLike*/ true)) {
diags.push(createDiagnosticForNode(init, Diagnostics.require_call_may_be_converted_to_an_import));
}
}
}
}
if (getAllowSyntheticDefaultImports(program.getCompilerOptions())) {
for (const moduleSpecifier of sourceFile.imports) {
const importNode = importFromModuleSpecifier(moduleSpecifier);
@@ -60,7 +28,48 @@ namespace ts {
}
addRange(diags, sourceFile.bindSuggestionDiagnostics);
return diags.concat(checker.getSuggestionDiagnostics(sourceFile)).sort((d1, d2) => d1.start - d2.start);
addRange(diags, program.getSuggestionDiagnostics(sourceFile, cancellationToken));
return diags.sort((d1, d2) => d1.start - d2.start);
function check(node: Node) {
if (isJsFile) {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
const decl = getDeclarationOfJSInitializer(node);
if (decl) {
const symbol = decl.symbol;
if (symbol && (symbol.exports && symbol.exports.size || symbol.members && symbol.members.size)) {
diags.push(createDiagnosticForNode(isVariableDeclaration(node.parent) ? node.parent.name : node, Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration));
break;
}
}
// falls through if no diagnostic was created
case SyntaxKind.FunctionDeclaration:
const symbol = node.symbol;
if (symbol.members && (symbol.members.size > 0)) {
diags.push(createDiagnosticForNode(isVariableDeclaration(node.parent) ? node.parent.name : node, Diagnostics.This_constructor_function_may_be_converted_to_a_class_declaration));
}
break;
}
}
else {
if (isVariableStatement(node) &&
node.parent === sourceFile &&
node.declarationList.flags & NodeFlags.Const &&
node.declarationList.declarations.length === 1) {
const init = node.declarationList.declarations[0].initializer;
if (init && isRequireCall(init, /*checkArgumentIsStringLiteralLike*/ true)) {
diags.push(createDiagnosticForNode(init, Diagnostics.require_call_may_be_converted_to_an_import));
}
}
if (codefix.parameterShouldGetTypeFromJSDoc(node)) {
diags.push(createDiagnosticForNode(node.name || node, Diagnostics.JSDoc_types_may_be_moved_to_TypeScript_types));
}
}
node.forEachChild(check);
}
}
// convertToEs6Module only works on top-level, so don't trigger it if commonjs code only appears in nested scopes.
+1 -1
View File
@@ -496,7 +496,7 @@ namespace ts.textChanges {
else if (isStatement(node) || isClassOrTypeElement(node)) {
return { suffix: this.newLineCharacter };
}
else if (isVariableDeclaration(node)) {
else if (isVariableDeclaration(node) || isStringLiteral(node)) {
return { prefix: ", " };
}
else if (isPropertyAssignment(node)) {
+1 -1
View File
@@ -44,6 +44,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@@ -108,7 +109,6 @@
"codefixes/inferFromUsage.ts",
"codefixes/fixInvalidImportSyntax.ts",
"codefixes/fixStrictClassInitialization.ts",
"codefixes/moduleSpecifiers.ts",
"codefixes/requireInTs.ts",
"codefixes/useDefaultImport.ts",
"codefixes/fixAddModuleReferTypeMissingTypeof.ts",
+12 -7
View File
@@ -151,9 +151,11 @@ namespace ts {
return new StringScriptSnapshot(text);
}
}
export interface PreProcessedFileInfo {
referencedFiles: FileReference[];
typeReferenceDirectives: FileReference[];
libReferenceDirectives: FileReference[];
importedFiles: FileReference[];
ambientExternalModules?: string[];
isLibFile: boolean;
@@ -323,6 +325,11 @@ namespace ts {
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion | undefined;
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
/**
* This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag.
* Editors should call this after `>` is typed.
*/
getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined;
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined;
@@ -342,7 +349,7 @@ namespace ts {
getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined): ApplicableRefactorInfo[];
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined;
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray<FileTextChanges>;
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray<FileTextChanges>;
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray<FileTextChanges>;
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;
@@ -350,15 +357,13 @@ namespace ts {
/* @internal */ getNonBoundSourceFile(fileName: string): SourceFile;
/**
* @internal
* @deprecated Use ts.createSourceFile instead.
*/
getSourceFile(fileName: string): SourceFile;
dispose(): void;
}
export interface JsxClosingTagInfo {
readonly newText: string;
}
export interface CombinedCodeFixScope { type: "file"; fileName: string; }
export type OrganizeImportsScope = CombinedCodeFixScope;
+3 -2
View File
@@ -648,8 +648,8 @@ namespace ts {
* Gets the token whose text has range [start, end) and
* position >= start and (position < end or (position === end && token is literal or keyword or identifier))
*/
export function getTouchingPropertyName(sourceFile: SourceFile, position: number, includeJsDocComment: boolean): Node {
return getTouchingToken(sourceFile, position, includeJsDocComment, n => isPropertyNameLiteral(n) || isKeyword(n.kind));
export function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node {
return getTouchingToken(sourceFile, position, /*includeJsDocComment*/ true, n => isPropertyNameLiteral(n) || isKeyword(n.kind));
}
/**
@@ -1196,6 +1196,7 @@ namespace ts {
SyntaxKind.VoidKeyword,
SyntaxKind.UndefinedKeyword,
SyntaxKind.UniqueKeyword,
SyntaxKind.UnknownKeyword,
];
export function isTypeKeyword(kind: SyntaxKind): boolean {