mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into asyncGenerators
This commit is contained in:
@@ -1180,7 +1180,6 @@ task("update-sublime", ["local", serverFile], function () {
|
||||
var tslintRuleDir = "scripts/tslint";
|
||||
var tslintRules = [
|
||||
"nextLineRule",
|
||||
"preferConstRule",
|
||||
"booleanTriviaRule",
|
||||
"typeOperatorSpacingRule",
|
||||
"noInOperatorRule",
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@
|
||||
"through2": "latest",
|
||||
"travis-fold": "latest",
|
||||
"ts-node": "latest",
|
||||
"tslint": "4.0.0-dev.3",
|
||||
"tslint": "next",
|
||||
"typescript": "next"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
import * as Lint from "tslint/lib";
|
||||
import * as ts from "typescript";
|
||||
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
public static FAILURE_STRING_FACTORY = (identifier: string) => `Identifier '${identifier}' never appears on the LHS of an assignment - use const instead of let for its declaration.`;
|
||||
|
||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithWalker(new PreferConstWalker(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
function isLet(node: ts.Node) {
|
||||
return !!(ts.getCombinedNodeFlags(node) & ts.NodeFlags.Let);
|
||||
}
|
||||
|
||||
function isExported(node: ts.Node) {
|
||||
return !!(ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Export);
|
||||
}
|
||||
|
||||
function isAssignmentOperator(token: ts.SyntaxKind): boolean {
|
||||
return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment;
|
||||
}
|
||||
|
||||
function isBindingLiteralExpression(node: ts.Node): node is (ts.ArrayLiteralExpression | ts.ObjectLiteralExpression) {
|
||||
return (!!node) && (node.kind === ts.SyntaxKind.ObjectLiteralExpression || node.kind === ts.SyntaxKind.ArrayLiteralExpression);
|
||||
}
|
||||
|
||||
interface DeclarationUsages {
|
||||
declaration: ts.VariableDeclaration;
|
||||
usages: number;
|
||||
}
|
||||
|
||||
class PreferConstWalker extends Lint.RuleWalker {
|
||||
private inScopeLetDeclarations: ts.MapLike<DeclarationUsages>[] = [];
|
||||
private errors: Lint.RuleFailure[] = [];
|
||||
private markAssignment(identifier: ts.Identifier) {
|
||||
const name = identifier.text;
|
||||
for (let i = this.inScopeLetDeclarations.length - 1; i >= 0; i--) {
|
||||
const declarations = this.inScopeLetDeclarations[i];
|
||||
if (declarations[name]) {
|
||||
declarations[name].usages++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitSourceFile(node: ts.SourceFile) {
|
||||
super.visitSourceFile(node);
|
||||
// Sort errors by position because tslint doesn't
|
||||
this.errors.sort((a, b) => a.getStartPosition().getPosition() - b.getStartPosition().getPosition()).forEach(e => this.addFailure(e));
|
||||
}
|
||||
|
||||
visitBinaryExpression(node: ts.BinaryExpression) {
|
||||
if (isAssignmentOperator(node.operatorToken.kind)) {
|
||||
this.visitLeftHandSideExpression(node.left);
|
||||
}
|
||||
super.visitBinaryExpression(node);
|
||||
}
|
||||
|
||||
private visitLeftHandSideExpression(node: ts.Expression) {
|
||||
while (node.kind === ts.SyntaxKind.ParenthesizedExpression) {
|
||||
node = (node as ts.ParenthesizedExpression).expression;
|
||||
}
|
||||
if (node.kind === ts.SyntaxKind.Identifier) {
|
||||
this.markAssignment(node as ts.Identifier);
|
||||
}
|
||||
else if (isBindingLiteralExpression(node)) {
|
||||
this.visitBindingLiteralExpression(node as (ts.ArrayLiteralExpression | ts.ObjectLiteralExpression));
|
||||
}
|
||||
}
|
||||
|
||||
private visitBindingLiteralExpression(node: ts.ArrayLiteralExpression | ts.ObjectLiteralExpression) {
|
||||
if (node.kind === ts.SyntaxKind.ObjectLiteralExpression) {
|
||||
const pattern = node as ts.ObjectLiteralExpression;
|
||||
for (const element of pattern.properties) {
|
||||
const kind = element.kind;
|
||||
|
||||
if (kind === ts.SyntaxKind.ShorthandPropertyAssignment) {
|
||||
this.markAssignment((element as ts.ShorthandPropertyAssignment).name);
|
||||
}
|
||||
else if (kind === ts.SyntaxKind.PropertyAssignment) {
|
||||
this.visitLeftHandSideExpression((element as ts.PropertyAssignment).initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (node.kind === ts.SyntaxKind.ArrayLiteralExpression) {
|
||||
const pattern = node as ts.ArrayLiteralExpression;
|
||||
for (const element of pattern.elements) {
|
||||
this.visitLeftHandSideExpression(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private visitBindingPatternIdentifiers(pattern: ts.BindingPattern) {
|
||||
for (const element of pattern.elements) {
|
||||
if (element.kind !== ts.SyntaxKind.BindingElement) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const name = (<ts.BindingElement>element).name;
|
||||
if (name.kind === ts.SyntaxKind.Identifier) {
|
||||
this.markAssignment(name as ts.Identifier);
|
||||
}
|
||||
else {
|
||||
this.visitBindingPatternIdentifiers(name as ts.BindingPattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression) {
|
||||
this.visitAnyUnaryExpression(node);
|
||||
super.visitPrefixUnaryExpression(node);
|
||||
}
|
||||
|
||||
visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression) {
|
||||
this.visitAnyUnaryExpression(node);
|
||||
super.visitPostfixUnaryExpression(node);
|
||||
}
|
||||
|
||||
private visitAnyUnaryExpression(node: ts.PrefixUnaryExpression | ts.PostfixUnaryExpression) {
|
||||
if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator === ts.SyntaxKind.MinusMinusToken) {
|
||||
this.visitLeftHandSideExpression(node.operand);
|
||||
}
|
||||
}
|
||||
|
||||
visitModuleDeclaration(node: ts.ModuleDeclaration) {
|
||||
if (node.body.kind === ts.SyntaxKind.ModuleBlock) {
|
||||
// For some reason module blocks are left out of the visit block traversal
|
||||
this.visitBlock(node.body as any as ts.Block);
|
||||
}
|
||||
super.visitModuleDeclaration(node);
|
||||
}
|
||||
|
||||
visitForOfStatement(node: ts.ForOfStatement) {
|
||||
this.visitAnyForStatement(node);
|
||||
super.visitForOfStatement(node);
|
||||
this.popDeclarations();
|
||||
}
|
||||
|
||||
visitForInStatement(node: ts.ForInStatement) {
|
||||
this.visitAnyForStatement(node);
|
||||
super.visitForInStatement(node);
|
||||
this.popDeclarations();
|
||||
}
|
||||
|
||||
private visitAnyForStatement(node: ts.ForOfStatement | ts.ForInStatement) {
|
||||
const names: ts.MapLike<DeclarationUsages> = {};
|
||||
if (isLet(node.initializer)) {
|
||||
if (node.initializer.kind === ts.SyntaxKind.VariableDeclarationList) {
|
||||
this.collectLetIdentifiers(node.initializer as ts.VariableDeclarationList, names);
|
||||
}
|
||||
}
|
||||
this.inScopeLetDeclarations.push(names);
|
||||
}
|
||||
|
||||
private popDeclarations() {
|
||||
const completed = this.inScopeLetDeclarations.pop();
|
||||
for (const name in completed) {
|
||||
if (Object.hasOwnProperty.call(completed, name)) {
|
||||
const element = completed[name];
|
||||
if (element.usages === 0) {
|
||||
this.errors.push(this.createFailure(element.declaration.getStart(this.getSourceFile()), element.declaration.getWidth(this.getSourceFile()), Rule.FAILURE_STRING_FACTORY(name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitBlock(node: ts.Block) {
|
||||
const names: ts.MapLike<DeclarationUsages> = {};
|
||||
for (const statement of node.statements) {
|
||||
if (statement.kind === ts.SyntaxKind.VariableStatement) {
|
||||
this.collectLetIdentifiers((statement as ts.VariableStatement).declarationList, names);
|
||||
}
|
||||
}
|
||||
this.inScopeLetDeclarations.push(names);
|
||||
super.visitBlock(node);
|
||||
this.popDeclarations();
|
||||
}
|
||||
|
||||
private collectLetIdentifiers(list: ts.VariableDeclarationList, ret: ts.MapLike<DeclarationUsages>) {
|
||||
for (const node of list.declarations) {
|
||||
if (isLet(node) && !isExported(node)) {
|
||||
this.collectNameIdentifiers(node, node.name, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private collectNameIdentifiers(declaration: ts.VariableDeclaration, node: ts.Identifier | ts.BindingPattern, table: ts.MapLike<DeclarationUsages>) {
|
||||
if (node.kind === ts.SyntaxKind.Identifier) {
|
||||
table[(node as ts.Identifier).text] = { declaration, usages: 0 };
|
||||
}
|
||||
else {
|
||||
this.collectBindingPatternIdentifiers(declaration, node as ts.BindingPattern, table);
|
||||
}
|
||||
}
|
||||
|
||||
private collectBindingPatternIdentifiers(value: ts.VariableDeclaration, pattern: ts.BindingPattern, table: ts.MapLike<DeclarationUsages>) {
|
||||
for (const element of pattern.elements) {
|
||||
if (element.kind === ts.SyntaxKind.BindingElement) {
|
||||
this.collectNameIdentifiers(value, (<ts.BindingElement>element).name, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,8 +283,8 @@ namespace ts {
|
||||
// Parameters with names are handled at the top of this function. Parameters
|
||||
// without names can only come from JSDocFunctionTypes.
|
||||
Debug.assert(node.parent.kind === SyntaxKind.JSDocFunctionType);
|
||||
let functionType = <JSDocFunctionType>node.parent;
|
||||
let index = indexOf(functionType.parameters, node);
|
||||
const functionType = <JSDocFunctionType>node.parent;
|
||||
const index = indexOf(functionType.parameters, node);
|
||||
return "arg" + index;
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
const parentNode = node.parent && node.parent.parent;
|
||||
@@ -3140,6 +3140,7 @@ namespace ts {
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
case SyntaxKind.MetaProperty:
|
||||
// These nodes are ES6 syntax.
|
||||
transformFlags |= TransformFlags.AssertES2015;
|
||||
break;
|
||||
|
||||
+164
-29
@@ -1,4 +1,4 @@
|
||||
/// <reference path="moduleNameResolver.ts"/>
|
||||
/// <reference path="moduleNameResolver.ts"/>
|
||||
/// <reference path="binder.ts"/>
|
||||
|
||||
/* @internal */
|
||||
@@ -231,6 +231,7 @@ namespace ts {
|
||||
const visitedFlowNodes: FlowNode[] = [];
|
||||
const visitedFlowTypes: FlowType[] = [];
|
||||
const potentialThisCollisions: Node[] = [];
|
||||
const potentialNewTargetCollisions: Node[] = [];
|
||||
const awaitedTypeStack: number[] = [];
|
||||
|
||||
const diagnostics = createDiagnosticCollection();
|
||||
@@ -626,11 +627,24 @@ namespace ts {
|
||||
|
||||
if (declaration.pos <= usage.pos) {
|
||||
// declaration is before usage
|
||||
// still might be illegal if usage is in the initializer of the variable declaration
|
||||
return declaration.kind !== SyntaxKind.VariableDeclaration ||
|
||||
!isImmediatelyUsedInInitializerOfBlockScopedVariable(<VariableDeclaration>declaration, usage);
|
||||
if (declaration.kind === SyntaxKind.BindingElement) {
|
||||
// still might be illegal if declaration and usage are both binding elements (eg var [a = b, b = b] = [1, 2])
|
||||
const errorBindingElement = getAncestor(usage, SyntaxKind.BindingElement) as BindingElement;
|
||||
if (errorBindingElement) {
|
||||
return getAncestorBindingPattern(errorBindingElement) !== getAncestorBindingPattern(declaration) ||
|
||||
declaration.pos < errorBindingElement.pos;
|
||||
}
|
||||
// or it might be illegal if usage happens before parent variable is declared (eg var [a] = a)
|
||||
return isBlockScopedNameDeclaredBeforeUse(getAncestor(declaration, SyntaxKind.VariableDeclaration) as Declaration, usage);
|
||||
}
|
||||
else if (declaration.kind === SyntaxKind.VariableDeclaration) {
|
||||
// still might be illegal if usage is in the initializer of the variable declaration (eg var a = a)
|
||||
return !isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration as VariableDeclaration, usage);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// declaration is after usage
|
||||
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
|
||||
const container = getEnclosingBlockScopeContainer(declaration);
|
||||
@@ -687,6 +701,16 @@ namespace ts {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getAncestorBindingPattern(node: Node): BindingPattern {
|
||||
while (node) {
|
||||
if (isBindingPattern(node)) {
|
||||
return node;
|
||||
}
|
||||
node = node.parent;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve a given name for a given meaning at a given location. An error is reported if the name was not found and
|
||||
@@ -1053,7 +1077,7 @@ namespace ts {
|
||||
|
||||
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
|
||||
|
||||
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
|
||||
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
|
||||
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
|
||||
}
|
||||
}
|
||||
@@ -4606,8 +4630,8 @@ namespace ts {
|
||||
// the modifiers type is T. Otherwise, the modifiers type is {}.
|
||||
const declaredType = <MappedType>getTypeFromMappedTypeNode(type.declaration);
|
||||
const constraint = getConstraintTypeFromMappedType(declaredType);
|
||||
const extendedConstraint = constraint.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>constraint) : constraint;
|
||||
type.modifiersType = extendedConstraint.flags & TypeFlags.Index ? instantiateType((<IndexType>extendedConstraint).type, type.mapper || identityMapper) : emptyObjectType;
|
||||
const extendedConstraint = constraint && constraint.flags & TypeFlags.TypeParameter ? getConstraintOfTypeParameter(<TypeParameter>constraint) : constraint;
|
||||
type.modifiersType = extendedConstraint && extendedConstraint.flags & TypeFlags.Index ? instantiateType((<IndexType>extendedConstraint).type, type.mapper || identityMapper) : emptyObjectType;
|
||||
}
|
||||
}
|
||||
return type.modifiersType;
|
||||
@@ -5013,7 +5037,7 @@ namespace ts {
|
||||
// If this is a JSDoc construct signature, then skip the first parameter in the
|
||||
// parameter list. The first parameter represents the return type of the construct
|
||||
// signature.
|
||||
for (let i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) {
|
||||
for (let i = isJSConstructSignature ? 1 : 0; i < declaration.parameters.length; i++) {
|
||||
const param = declaration.parameters[i];
|
||||
|
||||
let paramSymbol = param.symbol;
|
||||
@@ -5112,7 +5136,7 @@ namespace ts {
|
||||
function getSignaturesOfSymbol(symbol: Symbol): Signature[] {
|
||||
if (!symbol) return emptyArray;
|
||||
const result: Signature[] = [];
|
||||
for (let i = 0, len = symbol.declarations.length; i < len; i++) {
|
||||
for (let i = 0; i < symbol.declarations.length; i++) {
|
||||
const node = symbol.declarations[i];
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionType:
|
||||
@@ -5819,8 +5843,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isSubtypeOfAny(candidate: Type, types: Type[]): boolean {
|
||||
for (let i = 0, len = types.length; i < len; i++) {
|
||||
if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) {
|
||||
for (const type of types) {
|
||||
if (candidate !== type && isTypeSubtypeOf(candidate, type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -6100,7 +6124,7 @@ namespace ts {
|
||||
getIndexInfoOfType(objectType, IndexKind.String) ||
|
||||
undefined;
|
||||
if (indexInfo) {
|
||||
if (accessExpression && isAssignmentTarget(accessExpression) && indexInfo.isReadonly) {
|
||||
if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) {
|
||||
error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
|
||||
return unknownType;
|
||||
}
|
||||
@@ -6696,7 +6720,7 @@ namespace ts {
|
||||
// Starting with the parent of the symbol's declaration, check if the mapper maps any of
|
||||
// the type parameters introduced by enclosing declarations. We just pick the first
|
||||
// declaration since multiple declarations will all have the same parent anyway.
|
||||
let node = symbol.declarations[0].parent;
|
||||
let node: Node = symbol.declarations[0];
|
||||
while (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionType:
|
||||
@@ -6716,7 +6740,7 @@ namespace ts {
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
const declaration = <DeclarationWithTypeParameters>node;
|
||||
const declaration = node as DeclarationWithTypeParameters;
|
||||
if (declaration.typeParameters) {
|
||||
for (const d of declaration.typeParameters) {
|
||||
if (contains(mappedTypes, getDeclaredTypeOfTypeParameter(getSymbolOfNode(d)))) {
|
||||
@@ -6731,6 +6755,14 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
const func = node as JSDocFunctionType;
|
||||
for (const p of func.parameters) {
|
||||
if (contains(mappedTypes, getTypeOfNode(p))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.SourceFile:
|
||||
return false;
|
||||
@@ -7781,8 +7813,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (relation !== identityRelation && isEmptyObjectType(resolveStructuredTypeMembers(<ObjectType>target))) {
|
||||
return Ternary.True;
|
||||
else if (relation !== identityRelation) {
|
||||
const resolved = resolveStructuredTypeMembers(<ObjectType>target);
|
||||
if (isEmptyObjectType(resolved) || resolved.stringIndexInfo && resolved.stringIndexInfo.type.flags & TypeFlags.Any) {
|
||||
return Ternary.True;
|
||||
}
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
@@ -7962,7 +7997,7 @@ namespace ts {
|
||||
return Ternary.False;
|
||||
}
|
||||
let result = Ternary.True;
|
||||
for (let i = 0, len = sourceSignatures.length; i < len; i++) {
|
||||
for (let i = 0; i < sourceSignatures.length; i++) {
|
||||
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
|
||||
if (!related) {
|
||||
return Ternary.False;
|
||||
@@ -10352,6 +10387,7 @@ namespace ts {
|
||||
|
||||
checkCollisionWithCapturedSuperVariable(node, node);
|
||||
checkCollisionWithCapturedThisVariable(node, node);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, node);
|
||||
checkNestedBlockScopedBinding(node, symbol);
|
||||
|
||||
const type = getTypeOfSymbol(localOrExportSymbol);
|
||||
@@ -10393,7 +10429,7 @@ namespace ts {
|
||||
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
|
||||
// declaration container are the same).
|
||||
const assumeInitialized = isParameter || isOuterVariable ||
|
||||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0) ||
|
||||
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isInTypeQuery(node)) ||
|
||||
isInAmbientContext(declaration);
|
||||
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
|
||||
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
|
||||
@@ -12208,7 +12244,11 @@ namespace ts {
|
||||
|
||||
function checkJsxExpression(node: JsxExpression) {
|
||||
if (node.expression) {
|
||||
return checkExpression(node.expression);
|
||||
const type = checkExpression(node.expression);
|
||||
if (node.dotDotDotToken && type !== anyType && !isArrayType(type)) {
|
||||
error(node, Diagnostics.JSX_spread_child_must_be_an_array_type, node.toString(), typeToString(type));
|
||||
}
|
||||
return type;
|
||||
}
|
||||
else {
|
||||
return unknownType;
|
||||
@@ -13878,6 +13918,24 @@ namespace ts {
|
||||
return getNonNullableType(checkExpression(node.expression));
|
||||
}
|
||||
|
||||
function checkMetaProperty(node: MetaProperty) {
|
||||
checkGrammarMetaProperty(node);
|
||||
Debug.assert(node.keywordToken === SyntaxKind.NewKeyword && node.name.text === "target", "Unrecognized meta-property.");
|
||||
const container = getNewTargetContainer(node);
|
||||
if (!container) {
|
||||
error(node, Diagnostics.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, "new.target");
|
||||
return unknownType;
|
||||
}
|
||||
else if (container.kind === SyntaxKind.Constructor) {
|
||||
const symbol = getSymbolOfNode(container.parent);
|
||||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
else {
|
||||
const symbol = getSymbolOfNode(container);
|
||||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
function getTypeOfParameter(symbol: Symbol) {
|
||||
const type = getTypeOfSymbol(symbol);
|
||||
if (strictNullChecks) {
|
||||
@@ -14301,6 +14359,7 @@ namespace ts {
|
||||
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) {
|
||||
checkCollisionWithCapturedSuperVariable(node, (<FunctionExpression>node).name);
|
||||
checkCollisionWithCapturedThisVariable(node, (<FunctionExpression>node).name);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, (<FunctionExpression>node).name);
|
||||
}
|
||||
|
||||
return type;
|
||||
@@ -14422,6 +14481,16 @@ namespace ts {
|
||||
|
||||
function checkDeleteExpression(node: DeleteExpression): Type {
|
||||
checkExpression(node.expression);
|
||||
const expr = skipParentheses(node.expression);
|
||||
if (expr.kind !== SyntaxKind.PropertyAccessExpression && expr.kind !== SyntaxKind.ElementAccessExpression) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_a_property_reference);
|
||||
return booleanType;
|
||||
}
|
||||
const links = getNodeLinks(expr);
|
||||
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
|
||||
if (symbol && isReadonlySymbol(symbol)) {
|
||||
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
|
||||
}
|
||||
return booleanType;
|
||||
}
|
||||
|
||||
@@ -15350,6 +15419,8 @@ namespace ts {
|
||||
return checkAssertion(<AssertionExpression>node);
|
||||
case SyntaxKind.NonNullExpression:
|
||||
return checkNonNullAssertion(<NonNullExpression>node);
|
||||
case SyntaxKind.MetaProperty:
|
||||
return checkMetaProperty(<MetaProperty>node);
|
||||
case SyntaxKind.DeleteExpression:
|
||||
return checkDeleteExpression(<DeleteExpression>node);
|
||||
case SyntaxKind.VoidExpression:
|
||||
@@ -16367,7 +16438,8 @@ namespace ts {
|
||||
// }
|
||||
//
|
||||
|
||||
const thenFunction = !isTypeAny(type) && getTypeOfPropertyOfType(type, "then");
|
||||
// TODO(rbuckton): Verify whether we need to call getApparentType. See checkNonThenableType in master
|
||||
const thenFunction = getTypeOfPropertyOfType(type, "then");
|
||||
const thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, SignatureKind.Call) : emptyArray;
|
||||
if (thenSignatures.length > 0) {
|
||||
return true;
|
||||
@@ -16783,6 +16855,7 @@ namespace ts {
|
||||
|
||||
checkCollisionWithCapturedSuperVariable(node, node.name);
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
|
||||
}
|
||||
@@ -17012,7 +17085,7 @@ namespace ts {
|
||||
if (!local.isReferenced && !local.exportSymbol) {
|
||||
for (const declaration of local.declarations) {
|
||||
if (!isAmbientModule(declaration)) {
|
||||
error(declaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
|
||||
errorUnusedLocal(declaration.name, local.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17079,6 +17152,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkCollisionWithCapturedNewTargetVariable(node: Node, name: Identifier): void {
|
||||
if (needCollisionCheckForIdentifier(node, name, "_newTarget")) {
|
||||
potentialNewTargetCollisions.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
// this function will run after checking the source file so 'CaptureThis' is correct for all nodes
|
||||
function checkIfThisIsCapturedInEnclosingScope(node: Node): void {
|
||||
let current = node;
|
||||
@@ -17097,6 +17176,23 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkIfNewTargetIsCapturedInEnclosingScope(node: Node): void {
|
||||
let current = node;
|
||||
while (current) {
|
||||
if (getNodeCheckFlags(current) & NodeCheckFlags.CaptureNewTarget) {
|
||||
const isDeclaration = node.kind !== SyntaxKind.Identifier;
|
||||
if (isDeclaration) {
|
||||
error((<Declaration>node).name, Diagnostics.Duplicate_identifier_newTarget_Compiler_uses_variable_declaration_newTarget_to_capture_new_target_meta_property_reference);
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Expression_resolves_to_variable_declaration_newTarget_that_compiler_uses_to_capture_new_target_meta_property_reference);
|
||||
}
|
||||
return;
|
||||
}
|
||||
current = current.parent;
|
||||
}
|
||||
}
|
||||
|
||||
function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier) {
|
||||
if (!needCollisionCheckForIdentifier(node, name, "_super")) {
|
||||
return;
|
||||
@@ -17270,7 +17366,8 @@ namespace ts {
|
||||
// so we need to do a bit of extra work to check if reference is legal
|
||||
const enclosingContainer = getEnclosingBlockScopeContainer(symbol.valueDeclaration);
|
||||
if (enclosingContainer === func) {
|
||||
if (symbol.valueDeclaration.kind === SyntaxKind.Parameter) {
|
||||
if (symbol.valueDeclaration.kind === SyntaxKind.Parameter ||
|
||||
symbol.valueDeclaration.kind === SyntaxKind.BindingElement) {
|
||||
// it is ok to reference parameter in initializer if either
|
||||
// - parameter is located strictly on the left of current parameter declaration
|
||||
if (symbol.valueDeclaration.pos < node.pos) {
|
||||
@@ -17322,7 +17419,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext) {
|
||||
if (node.parent.kind === SyntaxKind.ObjectBindingPattern && languageVersion < ScriptTarget.ESNext && !isInAmbientContext(node)) {
|
||||
checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest);
|
||||
}
|
||||
// check computed properties inside property names of binding elements
|
||||
@@ -17396,6 +17493,7 @@ namespace ts {
|
||||
}
|
||||
checkCollisionWithCapturedSuperVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithCapturedThisVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, <Identifier>node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, <Identifier>node.name);
|
||||
}
|
||||
@@ -18371,7 +18469,7 @@ namespace ts {
|
||||
/** Check each type parameter and check that type parameters have no duplicate type parameter declarations */
|
||||
function checkTypeParameters(typeParameterDeclarations: TypeParameterDeclaration[]) {
|
||||
if (typeParameterDeclarations) {
|
||||
for (let i = 0, n = typeParameterDeclarations.length; i < n; i++) {
|
||||
for (let i = 0; i < typeParameterDeclarations.length; i++) {
|
||||
const node = typeParameterDeclarations[i];
|
||||
checkTypeParameter(node);
|
||||
|
||||
@@ -18431,6 +18529,7 @@ namespace ts {
|
||||
if (node.name) {
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
|
||||
}
|
||||
@@ -18651,7 +18750,7 @@ namespace ts {
|
||||
// TypeScript 1.0 spec (April 2014):
|
||||
// When a generic interface has multiple declarations, all declarations must have identical type parameter
|
||||
// lists, i.e. identical type parameter names with identical constraints in identical order.
|
||||
for (let i = 0, len = list1.length; i < len; i++) {
|
||||
for (let i = 0; i < list1.length; i++) {
|
||||
const tp1 = list1[i];
|
||||
const tp2 = list2[i];
|
||||
if (tp1.name.text !== tp2.name.text) {
|
||||
@@ -18874,6 +18973,7 @@ namespace ts {
|
||||
}
|
||||
return undefined;
|
||||
case SyntaxKind.NumericLiteral:
|
||||
checkGrammarNumericLiteral(<NumericLiteral>e);
|
||||
return +(<NumericLiteral>e).text;
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return evalConstant((<ParenthesizedExpression>e).expression);
|
||||
@@ -18965,6 +19065,7 @@ namespace ts {
|
||||
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
|
||||
checkCollisionWithCapturedThisVariable(node, node.name);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
|
||||
checkExportsOnMergedDeclarations(node);
|
||||
@@ -19398,7 +19499,13 @@ namespace ts {
|
||||
|
||||
const container = node.parent.kind === SyntaxKind.SourceFile ? <SourceFile>node.parent : <ModuleDeclaration>node.parent.parent;
|
||||
if (container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container)) {
|
||||
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
|
||||
if (node.isExportEquals) {
|
||||
error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.A_default_export_can_only_be_used_in_an_ECMAScript_style_module);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
// Grammar checking
|
||||
@@ -19670,6 +19777,7 @@ namespace ts {
|
||||
checkGrammarSourceFile(node);
|
||||
|
||||
potentialThisCollisions.length = 0;
|
||||
potentialNewTargetCollisions.length = 0;
|
||||
|
||||
deferredNodes = [];
|
||||
deferredUnusedIdentifierNodes = produceDiagnostics && noUnusedIdentifiers ? [] : undefined;
|
||||
@@ -19698,6 +19806,11 @@ namespace ts {
|
||||
potentialThisCollisions.length = 0;
|
||||
}
|
||||
|
||||
if (potentialNewTargetCollisions.length) {
|
||||
forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope)
|
||||
potentialNewTargetCollisions.length = 0;
|
||||
}
|
||||
|
||||
links.flags |= NodeCheckFlags.TypeChecked;
|
||||
}
|
||||
}
|
||||
@@ -21039,7 +21152,7 @@ namespace ts {
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
let text = visibilityToString(modifierToFlag(modifier.kind));
|
||||
const text = visibilityToString(modifierToFlag(modifier.kind));
|
||||
|
||||
if (modifier.kind === SyntaxKind.ProtectedKeyword) {
|
||||
lastProtected = modifier;
|
||||
@@ -21979,6 +22092,14 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarMetaProperty(node: MetaProperty) {
|
||||
if (node.keywordToken === SyntaxKind.NewKeyword) {
|
||||
if (node.name.text !== "target") {
|
||||
return grammarErrorOnNode(node.name, Diagnostics._0_is_not_a_valid_meta_property_for_keyword_1_Did_you_mean_0, node.name.text, tokenToString(node.keywordToken), "target");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
|
||||
return sourceFile.parseDiagnostics.length > 0;
|
||||
}
|
||||
@@ -22123,8 +22244,22 @@ namespace ts {
|
||||
|
||||
function checkGrammarNumericLiteral(node: NumericLiteral): boolean {
|
||||
// Grammar checking
|
||||
if (node.isOctalLiteral && languageVersion >= ScriptTarget.ES5) {
|
||||
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
|
||||
if (node.isOctalLiteral) {
|
||||
let diagnosticMessage: DiagnosticMessage | undefined;
|
||||
if (languageVersion >= ScriptTarget.ES5) {
|
||||
diagnosticMessage = Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher_Use_the_syntax_0;
|
||||
}
|
||||
else if (isChildOfNodeWithKind(node, SyntaxKind.LiteralType)) {
|
||||
diagnosticMessage = Diagnostics.Octal_literal_types_must_use_ES2015_syntax_Use_the_syntax_0;
|
||||
}
|
||||
else if (isChildOfNodeWithKind(node, SyntaxKind.EnumMember)) {
|
||||
diagnosticMessage = Diagnostics.Octal_literals_are_not_allowed_in_enums_members_initializer_Use_the_syntax_0;
|
||||
}
|
||||
if (diagnosticMessage) {
|
||||
const withMinus = isPrefixUnaryExpression(node.parent) && node.parent.operator === SyntaxKind.MinusToken;
|
||||
const literal = `${withMinus ? "-" : ""}0o${node.text}`;
|
||||
return grammarErrorOnNode(withMinus ? node.parent : node, diagnosticMessage, literal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -630,7 +630,7 @@ namespace ts {
|
||||
break;
|
||||
case "boolean":
|
||||
// boolean flag has optional value true, false, others
|
||||
let optValue = args[i];
|
||||
const optValue = args[i];
|
||||
options[opt.name] = optValue !== "false";
|
||||
// consume next argument as boolean flag value
|
||||
if (optValue === "false" || optValue === "true") {
|
||||
@@ -788,7 +788,7 @@ namespace ts {
|
||||
break;
|
||||
default:
|
||||
const value = options[name];
|
||||
let optionDefinition = optionsNameMap[name.toLowerCase()];
|
||||
const optionDefinition = optionsNameMap[name.toLowerCase()];
|
||||
if (optionDefinition) {
|
||||
const customTypeMap = getCustomTypeMapOfCommandLineOption(optionDefinition);
|
||||
if (!customTypeMap) {
|
||||
@@ -852,6 +852,7 @@ namespace ts {
|
||||
*/
|
||||
export function parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions: CompilerOptions = {}, configFileName?: string, resolutionStack: Path[] = [], extraFileExtensions: FileExtensionInfo[] = []): ParsedCommandLine {
|
||||
const errors: Diagnostic[] = [];
|
||||
basePath = normalizeSlashes(basePath);
|
||||
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
|
||||
const resolvedPath = toPath(configFileName || "", basePath, getCanonicalFileName);
|
||||
if (resolutionStack.indexOf(resolvedPath) >= 0) {
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace ts {
|
||||
*/
|
||||
export function forEach<T, U>(array: T[] | undefined, callback: (element: T, index: number) => U | undefined): U | undefined {
|
||||
if (array) {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const result = callback(array[i], i);
|
||||
if (result) {
|
||||
return result;
|
||||
@@ -143,7 +143,7 @@ namespace ts {
|
||||
*/
|
||||
export function every<T>(array: T[], callback: (element: T, index: number) => boolean): boolean {
|
||||
if (array) {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (!callback(array[i], i)) {
|
||||
return false;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ namespace ts {
|
||||
|
||||
/** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
|
||||
export function find<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const value = array[i];
|
||||
if (predicate(value, i)) {
|
||||
return value;
|
||||
@@ -169,7 +169,7 @@ namespace ts {
|
||||
* This is like `forEach`, but never returns undefined.
|
||||
*/
|
||||
export function findMap<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const result = callback(array[i], i);
|
||||
if (result) {
|
||||
return result;
|
||||
@@ -191,7 +191,7 @@ namespace ts {
|
||||
|
||||
export function indexOf<T>(array: T[], value: T): number {
|
||||
if (array) {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i] === value) {
|
||||
return i;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function indexOfAnyCharCode(text: string, charCodes: number[], start?: number): number {
|
||||
for (let i = start || 0, len = text.length; i < len; i++) {
|
||||
for (let i = start || 0; i < text.length; i++) {
|
||||
if (contains(charCodes, text.charCodeAt(i))) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
"category": "Error",
|
||||
"code": 1084
|
||||
},
|
||||
"Octal literals are not available when targeting ECMAScript 5 and higher.": {
|
||||
"Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 1085
|
||||
},
|
||||
@@ -859,6 +859,10 @@
|
||||
"category": "Error",
|
||||
"code": 1318
|
||||
},
|
||||
"A default export can only be used in an ECMAScript-style module.": {
|
||||
"category": "Error",
|
||||
"code": 1319
|
||||
},
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2300
|
||||
@@ -1783,18 +1787,26 @@
|
||||
"category": "Error",
|
||||
"code": 2542
|
||||
},
|
||||
"The type returned by the 'next()' method of an async iterator must be a promise for a type with a 'value' property.": {
|
||||
"Duplicate identifier '_newTarget'. Compiler uses variable declaration '_newTarget' to capture 'new.target' meta-property reference.": {
|
||||
"category": "Error",
|
||||
"code": 2543
|
||||
},
|
||||
"Type '{0}' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator.": {
|
||||
"Expression resolves to variable declaration '_newTarget' that compiler uses to capture 'new.target' meta-property reference.": {
|
||||
"category": "Error",
|
||||
"code": 2544
|
||||
},
|
||||
"Type '{0}' is not an array type or a string type or does not have a '[Symbol.iterator]()' method that returns an iterator.": {
|
||||
"The type returned by the 'next()' method of an async iterator must be a promise for a type with a 'value' property.": {
|
||||
"category": "Error",
|
||||
"code": 2545
|
||||
},
|
||||
"Type '{0}' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator.": {
|
||||
"category": "Error",
|
||||
"code": 2546
|
||||
},
|
||||
"Type '{0}' is not an array type or a string type or does not have a '[Symbol.iterator]()' method that returns an iterator.": {
|
||||
"category": "Error",
|
||||
"code": 2547
|
||||
},
|
||||
"JSX element attributes type '{0}' may not be a union type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
@@ -1831,6 +1843,10 @@
|
||||
"category": "Error",
|
||||
"code": 2608
|
||||
},
|
||||
"JSX spread child must be an array type.": {
|
||||
"category": "Error",
|
||||
"code": 2609
|
||||
},
|
||||
"Cannot emit namespaced JSX elements in React": {
|
||||
"category": "Error",
|
||||
"code": 2650
|
||||
@@ -2035,6 +2051,14 @@
|
||||
"category": "Error",
|
||||
"code": 2702
|
||||
},
|
||||
"The operand of a delete operator must be a property reference": {
|
||||
"category": "Error",
|
||||
"code": 2703
|
||||
},
|
||||
"The operand of a delete operator cannot be a read-only property": {
|
||||
"category": "Error",
|
||||
"code": 2704
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
@@ -2713,7 +2737,7 @@
|
||||
"category": "Message",
|
||||
"code": 6080
|
||||
},
|
||||
"Specify how to emit for-of, spread, and destructuring in ES5/3: 'array' (arrays only; default) or 'iterable' (support arrays and Symbol.iterator)": {
|
||||
"File '{0}' has an unsupported extension, so skipping it.": {
|
||||
"category": "Message",
|
||||
"code": 6081
|
||||
},
|
||||
@@ -2769,7 +2793,7 @@
|
||||
"category": "Message",
|
||||
"code": 6094
|
||||
},
|
||||
"Loading module as file / folder, candidate module location '{0}'.": {
|
||||
"Loading module as file / folder, candidate module location '{0}', target file type '{1}'.": {
|
||||
"category": "Message",
|
||||
"code": 6095
|
||||
},
|
||||
@@ -2781,7 +2805,7 @@
|
||||
"category": "Message",
|
||||
"code": 6097
|
||||
},
|
||||
"Loading module '{0}' from 'node_modules' folder.": {
|
||||
"Loading module '{0}' from 'node_modules' folder, target file type '{1}'.": {
|
||||
"category": "Message",
|
||||
"code": 6098
|
||||
},
|
||||
@@ -2977,6 +3001,18 @@
|
||||
"category": "Message",
|
||||
"code": 6146
|
||||
},
|
||||
"Resolution for module '{0}' was found in cache.": {
|
||||
"category": "Message",
|
||||
"code": 6147
|
||||
},
|
||||
"Directory '{0}' does not exist, skipping all lookups in it.": {
|
||||
"category": "Message",
|
||||
"code": 6148
|
||||
},
|
||||
"Specify how to emit for-of, spread, and destructuring in ES5/3: 'array' (arrays only; default) or 'iterable' (support arrays and Symbol.iterator)": {
|
||||
"category": "Message",
|
||||
"code": 6149
|
||||
},
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
"code": 7005
|
||||
@@ -3201,6 +3237,14 @@
|
||||
"category": "Error",
|
||||
"code": 17011
|
||||
},
|
||||
"'{0}' is not a valid meta-property for keyword '{1}'. Did you mean '{0}'?": {
|
||||
"category": "Error",
|
||||
"code": 17012
|
||||
},
|
||||
"Meta-property '{0}' is only allowed in the body of a function declaration, function expression, or constructor.": {
|
||||
"category": "Error",
|
||||
"code": 17013
|
||||
},
|
||||
|
||||
"Circularity detected while resolving configuration: {0}": {
|
||||
"category": "Error",
|
||||
@@ -3266,5 +3310,13 @@
|
||||
"Add {0} to existing import declaration from {1}": {
|
||||
"category": "Message",
|
||||
"code": 90015
|
||||
},
|
||||
"Octal literal types must use ES2015 syntax. Use the syntax '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 8017
|
||||
},
|
||||
"Octal literals are not allowed in enums members initializer. Use the syntax '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 8018
|
||||
}
|
||||
}
|
||||
|
||||
+28
-4
@@ -660,6 +660,8 @@ namespace ts {
|
||||
return emitAsExpression(<AsExpression>node);
|
||||
case SyntaxKind.NonNullExpression:
|
||||
return emitNonNullExpression(<NonNullExpression>node);
|
||||
case SyntaxKind.MetaProperty:
|
||||
return emitMetaProperty(<MetaProperty>node);
|
||||
|
||||
// JSX
|
||||
case SyntaxKind.JsxElement:
|
||||
@@ -670,8 +672,6 @@ namespace ts {
|
||||
// Transformation nodes
|
||||
case SyntaxKind.PartiallyEmittedExpression:
|
||||
return emitPartiallyEmittedExpression(<PartiallyEmittedExpression>node);
|
||||
case SyntaxKind.RawExpression:
|
||||
return writeLines((<RawExpression>node).text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1249,6 +1249,12 @@ namespace ts {
|
||||
write("!");
|
||||
}
|
||||
|
||||
function emitMetaProperty(node: MetaProperty) {
|
||||
writeToken(node.keywordToken, node.pos);
|
||||
write(".");
|
||||
emit(node.name);
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
@@ -1856,6 +1862,9 @@ namespace ts {
|
||||
function emitJsxExpression(node: JsxExpression) {
|
||||
if (node.expression) {
|
||||
write("{");
|
||||
if (node.dotDotDotToken) {
|
||||
write("...");
|
||||
}
|
||||
emitExpression(node.expression);
|
||||
write("}");
|
||||
}
|
||||
@@ -2582,6 +2591,13 @@ namespace ts {
|
||||
return makeUniqueName("class");
|
||||
}
|
||||
|
||||
function generateNameForMethodOrAccessor(node: MethodDeclaration | AccessorDeclaration) {
|
||||
if (isIdentifier(node.name)) {
|
||||
return generateNameForNodeCached(node.name);
|
||||
}
|
||||
return makeTempVariableName(TempFlags.Auto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique name from a node.
|
||||
*
|
||||
@@ -2603,6 +2619,10 @@ namespace ts {
|
||||
return generateNameForExportDefault();
|
||||
case SyntaxKind.ClassExpression:
|
||||
return generateNameForClassExpression();
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return generateNameForMethodOrAccessor(<MethodDeclaration | AccessorDeclaration>node);
|
||||
default:
|
||||
return makeTempVariableName(TempFlags.Auto);
|
||||
}
|
||||
@@ -2653,6 +2673,11 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
function generateNameForNodeCached(node: Node) {
|
||||
const nodeId = getNodeId(node);
|
||||
return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = unescapeIdentifier(generateNameForNode(node)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generated identifier text from a generated identifier.
|
||||
*
|
||||
@@ -2663,8 +2688,7 @@ namespace ts {
|
||||
// Generated names generate unique names based on their original node
|
||||
// and are cached based on that node's id
|
||||
const node = getNodeForGeneratedName(name);
|
||||
const nodeId = getNodeId(node);
|
||||
return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = unescapeIdentifier(generateNameForNode(node)));
|
||||
return generateNameForNodeCached(node);
|
||||
}
|
||||
else {
|
||||
// Auto, Loop, and Unique names are cached based on their unique
|
||||
|
||||
+3
-15
@@ -1320,15 +1320,16 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createJsxExpression(expression: Expression, location?: TextRange) {
|
||||
export function createJsxExpression(expression: Expression, dotDotDotToken: Token<SyntaxKind.DotDotDotToken>, location?: TextRange) {
|
||||
const node = <JsxExpression>createNode(SyntaxKind.JsxExpression, location);
|
||||
node.dotDotDotToken = dotDotDotToken;
|
||||
node.expression = expression;
|
||||
return node;
|
||||
}
|
||||
|
||||
export function updateJsxExpression(node: JsxExpression, expression: Expression) {
|
||||
if (node.expression !== expression) {
|
||||
return updateNode(createJsxExpression(expression, node), node);
|
||||
return updateNode(createJsxExpression(expression, node.dotDotDotToken, node), node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -1535,19 +1536,6 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node that emits a string of raw text in an expression position. Raw text is never
|
||||
* transformed, should be ES3 compliant, and should have the same precedence as
|
||||
* PrimaryExpression.
|
||||
*
|
||||
* @param text The raw text of the node.
|
||||
*/
|
||||
export function createRawExpression(text: string) {
|
||||
const node = <RawExpression>createNode(SyntaxKind.RawExpression);
|
||||
node.text = text;
|
||||
return node;
|
||||
}
|
||||
|
||||
// Compound nodes
|
||||
|
||||
export function createComma(left: Expression, right: Expression) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/// <reference path="core.ts" />
|
||||
/// <reference path="core.ts" />
|
||||
/// <reference path="diagnosticInformationMap.generated.ts" />
|
||||
|
||||
namespace ts {
|
||||
@@ -32,7 +32,7 @@ namespace ts {
|
||||
* Kinds of file that we are currently looking for.
|
||||
* Typically there is one pass with Extensions.TypeScript, then a second pass with Extensions.JavaScript.
|
||||
*/
|
||||
const enum Extensions {
|
||||
enum Extensions {
|
||||
TypeScript, /** '.ts', '.tsx', or '.d.ts' */
|
||||
JavaScript, /** '.js' or '.jsx' */
|
||||
DtsOnly /** Only '.d.ts' */
|
||||
@@ -47,11 +47,6 @@ namespace ts {
|
||||
return resolved.path;
|
||||
}
|
||||
|
||||
/** Create Resolved from a file with unknown extension. */
|
||||
function resolvedFromAnyFile(path: string): Resolved | undefined {
|
||||
return { path, extension: extensionFromPath(path) };
|
||||
}
|
||||
|
||||
/** Adds `isExernalLibraryImport` to a Resolved to get a ResolvedModule. */
|
||||
function resolvedModuleFromResolved({ path, extension }: Resolved, isExternalLibraryImport: boolean): ResolvedModuleFull {
|
||||
return { resolvedFileName: path, extension, isExternalLibraryImport };
|
||||
@@ -71,7 +66,8 @@ namespace ts {
|
||||
traceEnabled: boolean;
|
||||
}
|
||||
|
||||
function tryReadTypesSection(extensions: Extensions, packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string {
|
||||
/** Reads from "main" or "types"/"typings" depending on `extensions`. */
|
||||
function tryReadPackageJsonMainOrTypes(extensions: Extensions, packageJsonPath: string, baseDirectory: string, state: ModuleResolutionState): string {
|
||||
const jsonContent = readJson(packageJsonPath, state.host);
|
||||
|
||||
switch (extensions) {
|
||||
@@ -153,6 +149,7 @@ namespace ts {
|
||||
if (host.directoryExists(atTypes)) {
|
||||
(typeRoots || (typeRoots = [])).push(atTypes);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
return typeRoots;
|
||||
}
|
||||
@@ -220,9 +217,13 @@ namespace ts {
|
||||
return forEach(typeRoots, typeRoot => {
|
||||
const candidate = combinePaths(typeRoot, typeReferenceDirectiveName);
|
||||
const candidateDirectory = getDirectoryPath(candidate);
|
||||
const directoryExists = directoryProbablyExists(candidateDirectory, host);
|
||||
if (!directoryExists && traceEnabled) {
|
||||
trace(host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, candidateDirectory);
|
||||
}
|
||||
return resolvedTypeScriptOnly(
|
||||
loadNodeModuleFromDirectory(Extensions.DtsOnly, candidate, failedLookupLocations,
|
||||
!directoryProbablyExists(candidateDirectory, host), moduleResolutionState));
|
||||
!directoryExists, moduleResolutionState));
|
||||
});
|
||||
}
|
||||
else {
|
||||
@@ -241,7 +242,8 @@ namespace ts {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup);
|
||||
}
|
||||
resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState));
|
||||
const result = loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*cache*/ undefined);
|
||||
resolvedFile = resolvedTypeScriptOnly(result && result.value);
|
||||
if (!resolvedFile && traceEnabled) {
|
||||
trace(host, Diagnostics.Type_reference_directive_0_was_not_resolved, typeReferenceDirectiveName);
|
||||
}
|
||||
@@ -293,33 +295,171 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
/**
|
||||
* Cached module resolutions per containing directory.
|
||||
* This assumes that any module id will have the same resolution for sibling files located in the same folder.
|
||||
*/
|
||||
export interface ModuleResolutionCache extends NonRelativeModuleNameResolutionCache {
|
||||
getOrCreateCacheForDirectory(directoryName: string): Map<ResolvedModuleWithFailedLookupLocations>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored map from non-relative module name to a table: directory -> result of module lookup in this directory
|
||||
* We support only non-relative module names because resolution of relative module names is usually more deterministic and thus less expensive.
|
||||
*/
|
||||
export interface NonRelativeModuleNameResolutionCache {
|
||||
getOrCreateCacheForModuleName(nonRelativeModuleName: string): PerModuleNameCache;
|
||||
}
|
||||
|
||||
export interface PerModuleNameCache {
|
||||
get(directory: string): ResolvedModuleWithFailedLookupLocations;
|
||||
set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void;
|
||||
}
|
||||
|
||||
export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache {
|
||||
const directoryToModuleNameMap = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
|
||||
const moduleNameToDirectoryMap = createMap<PerModuleNameCache>();
|
||||
|
||||
return { getOrCreateCacheForDirectory, getOrCreateCacheForModuleName };
|
||||
|
||||
function getOrCreateCacheForDirectory(directoryName: string) {
|
||||
const path = toPath(directoryName, currentDirectory, getCanonicalFileName);
|
||||
let perFolderCache = directoryToModuleNameMap.get(path);
|
||||
if (!perFolderCache) {
|
||||
perFolderCache = createMap<ResolvedModuleWithFailedLookupLocations>();
|
||||
directoryToModuleNameMap.set(path, perFolderCache);
|
||||
}
|
||||
return perFolderCache;
|
||||
}
|
||||
|
||||
function getOrCreateCacheForModuleName(nonRelativeModuleName: string) {
|
||||
if (!moduleHasNonRelativeName(nonRelativeModuleName)) {
|
||||
return undefined;
|
||||
}
|
||||
let perModuleNameCache = moduleNameToDirectoryMap[nonRelativeModuleName];
|
||||
if (!perModuleNameCache) {
|
||||
moduleNameToDirectoryMap[nonRelativeModuleName] = perModuleNameCache = createPerModuleNameCache();
|
||||
}
|
||||
return perModuleNameCache;
|
||||
}
|
||||
|
||||
function createPerModuleNameCache(): PerModuleNameCache {
|
||||
const directoryPathMap = createFileMap<ResolvedModuleWithFailedLookupLocations>();
|
||||
|
||||
return { get, set };
|
||||
|
||||
function get(directory: string): ResolvedModuleWithFailedLookupLocations {
|
||||
return directoryPathMap.get(toPath(directory, currentDirectory, getCanonicalFileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* At first this function add entry directory -> module resolution result to the table.
|
||||
* Then it computes the set of parent folders for 'directory' that should have the same module resolution result
|
||||
* and for every parent folder in set it adds entry: parent -> module resolution. .
|
||||
* Lets say we first directory name: /a/b/c/d/e and resolution result is: /a/b/bar.ts.
|
||||
* Set of parent folders that should have the same result will be:
|
||||
* [
|
||||
* /a/b/c/d, /a/b/c, /a/b
|
||||
* ]
|
||||
* this means that request for module resolution from file in any of these folder will be immediately found in cache.
|
||||
*/
|
||||
function set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void {
|
||||
const path = toPath(directory, currentDirectory, getCanonicalFileName);
|
||||
// if entry is already in cache do nothing
|
||||
if (directoryPathMap.contains(path)) {
|
||||
return;
|
||||
}
|
||||
directoryPathMap.set(path, result);
|
||||
|
||||
const resolvedFileName = result.resolvedModule && result.resolvedModule.resolvedFileName;
|
||||
// find common prefix between directory and resolved file name
|
||||
// this common prefix should be the shorted path that has the same resolution
|
||||
// directory: /a/b/c/d/e
|
||||
// resolvedFileName: /a/b/foo.d.ts
|
||||
const commonPrefix = getCommonPrefix(path, resolvedFileName);
|
||||
let current = path;
|
||||
while (true) {
|
||||
const parent = getDirectoryPath(current);
|
||||
if (parent === current || directoryPathMap.contains(parent)) {
|
||||
break;
|
||||
}
|
||||
directoryPathMap.set(parent, result);
|
||||
current = parent;
|
||||
|
||||
if (current == commonPrefix) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getCommonPrefix(directory: Path, resolution: string) {
|
||||
if (resolution === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const resolutionDirectory = toPath(getDirectoryPath(resolution), currentDirectory, getCanonicalFileName);
|
||||
|
||||
// find first position where directory and resolution differs
|
||||
let i = 0;
|
||||
while (i < Math.min(directory.length, resolutionDirectory.length) && directory.charCodeAt(i) === resolutionDirectory.charCodeAt(i)) {
|
||||
i++;
|
||||
}
|
||||
|
||||
// find last directory separator before position i
|
||||
const sep = directory.lastIndexOf(directorySeparator, i);
|
||||
if (sep < 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return directory.substr(0, sep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolving_module_0_from_1, moduleName, containingFile);
|
||||
}
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
let perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory);
|
||||
let result = perFolderCache && perFolderCache[moduleName];
|
||||
|
||||
let moduleResolution = compilerOptions.moduleResolution;
|
||||
if (moduleResolution === undefined) {
|
||||
moduleResolution = getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic;
|
||||
if (result) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]);
|
||||
trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ModuleResolutionKind[moduleResolution]);
|
||||
let moduleResolution = compilerOptions.moduleResolution;
|
||||
if (moduleResolution === undefined) {
|
||||
moduleResolution = getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic;
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0, ModuleResolutionKind[moduleResolution]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let result: ResolvedModuleWithFailedLookupLocations;
|
||||
switch (moduleResolution) {
|
||||
case ModuleResolutionKind.NodeJs:
|
||||
result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host);
|
||||
break;
|
||||
case ModuleResolutionKind.Classic:
|
||||
result = classicNameResolver(moduleName, containingFile, compilerOptions, host);
|
||||
break;
|
||||
switch (moduleResolution) {
|
||||
case ModuleResolutionKind.NodeJs:
|
||||
result = nodeModuleNameResolver(moduleName, containingFile, compilerOptions, host, cache);
|
||||
break;
|
||||
case ModuleResolutionKind.Classic:
|
||||
result = classicNameResolver(moduleName, containingFile, compilerOptions, host, cache);
|
||||
break;
|
||||
}
|
||||
|
||||
if (perFolderCache) {
|
||||
perFolderCache[moduleName] = result;
|
||||
// put result in per-module name cache
|
||||
const perModuleNameCache = cache.getOrCreateCacheForModuleName(moduleName);
|
||||
if (perModuleNameCache) {
|
||||
perModuleNameCache.set(containingDirectory, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (traceEnabled) {
|
||||
@@ -542,7 +682,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations {
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
|
||||
@@ -550,30 +690,30 @@ namespace ts {
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
|
||||
const result = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
if (result) {
|
||||
const { resolved, isExternalLibraryImport } = result;
|
||||
if (result && result.value) {
|
||||
const { resolved, isExternalLibraryImport } = result.value;
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations);
|
||||
}
|
||||
return { resolvedModule: undefined, failedLookupLocations };
|
||||
|
||||
function tryResolve(extensions: Extensions): { resolved: Resolved, isExternalLibraryImport: boolean } | undefined {
|
||||
function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> {
|
||||
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, nodeLoadModuleByRelativeName, failedLookupLocations, state);
|
||||
if (resolved) {
|
||||
return { resolved, isExternalLibraryImport: false };
|
||||
return toSearchResult({ resolved, isExternalLibraryImport: false });
|
||||
}
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName);
|
||||
trace(host, Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);
|
||||
}
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state);
|
||||
const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, cache);
|
||||
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
|
||||
return resolved && { resolved: { path: realpath(resolved.path, host, traceEnabled), extension: resolved.extension }, isExternalLibraryImport: true };
|
||||
return resolved && { value: resolved.value && { resolved: { path: realpath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension }, isExternalLibraryImport: true } };
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
return resolved && { resolved, isExternalLibraryImport: false };
|
||||
return resolved && toSearchResult({ resolved, isExternalLibraryImport: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -592,11 +732,33 @@ namespace ts {
|
||||
|
||||
function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate);
|
||||
trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0_target_file_type_1, candidate, Extensions[extensions]);
|
||||
}
|
||||
|
||||
const resolvedFromFile = !pathEndsWithDirectorySeparator(candidate) && loadModuleFromFile(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
return resolvedFromFile || loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (!pathEndsWithDirectorySeparator(candidate)) {
|
||||
if (!onlyRecordFailures) {
|
||||
const parentOfCandidate = getDirectoryPath(candidate);
|
||||
if (!directoryProbablyExists(parentOfCandidate, state.host)) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, parentOfCandidate);
|
||||
}
|
||||
onlyRecordFailures = true;
|
||||
}
|
||||
}
|
||||
const resolvedFromFile = loadModuleFromFile(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (resolvedFromFile) {
|
||||
return resolvedFromFile;
|
||||
}
|
||||
}
|
||||
if (!onlyRecordFailures) {
|
||||
const candidateExists = directoryProbablyExists(candidate, state.host);
|
||||
if (!candidateExists) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, candidate);
|
||||
}
|
||||
onlyRecordFailures = true;
|
||||
}
|
||||
}
|
||||
return loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, onlyRecordFailures, state);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@@ -655,19 +817,21 @@ namespace ts {
|
||||
|
||||
/** Return the file if it exists. */
|
||||
function tryFile(fileName: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined {
|
||||
if (!onlyRecordFailures && state.host.fileExists(fileName)) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_exist_use_it_as_a_name_resolution_result, fileName);
|
||||
if (!onlyRecordFailures) {
|
||||
if (state.host.fileExists(fileName)) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_exist_use_it_as_a_name_resolution_result, fileName);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
else {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_does_not_exist, fileName);
|
||||
else {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_does_not_exist, fileName);
|
||||
}
|
||||
}
|
||||
failedLookupLocations.push(fileName);
|
||||
return undefined;
|
||||
}
|
||||
failedLookupLocations.push(fileName);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined {
|
||||
@@ -678,18 +842,23 @@ namespace ts {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Found_package_json_at_0, packageJsonPath);
|
||||
}
|
||||
const typesFile = tryReadTypesSection(extensions, packageJsonPath, candidate, state);
|
||||
if (typesFile) {
|
||||
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host);
|
||||
const mainOrTypesFile = tryReadPackageJsonMainOrTypes(extensions, packageJsonPath, candidate, state);
|
||||
if (mainOrTypesFile) {
|
||||
const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(mainOrTypesFile), state.host);
|
||||
// A package.json "typings" may specify an exact filename, or may choose to omit an extension.
|
||||
const fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (fromFile) {
|
||||
// Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden.
|
||||
return resolvedFromAnyFile(fromFile);
|
||||
const fromExactFile = tryFile(mainOrTypesFile, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (fromExactFile) {
|
||||
const resolved = fromExactFile && resolvedIfExtensionMatches(extensions, fromExactFile);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_has_an_unsupported_extension_so_skipping_it, fromExactFile);
|
||||
}
|
||||
}
|
||||
const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (x) {
|
||||
return x;
|
||||
const resolved = tryAddingExtensions(mainOrTypesFile, Extensions.TypeScript, failedLookupLocations, onlyRecordFailures, state);
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -699,7 +868,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (state.traceEnabled) {
|
||||
if (directoryExists && state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.File_0_does_not_exist, packageJsonPath);
|
||||
}
|
||||
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
|
||||
@@ -709,66 +878,116 @@ namespace ts {
|
||||
return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state);
|
||||
}
|
||||
|
||||
/** Resolve from an arbitrarily specified file. Return `undefined` if it has an unsupported extension. */
|
||||
function resolvedIfExtensionMatches(extensions: Extensions, path: string): Resolved | undefined {
|
||||
const extension = tryGetExtensionFromPath(path);
|
||||
return extension !== undefined && extensionIsOk(extensions, extension) ? { path, extension } : undefined;
|
||||
}
|
||||
|
||||
/** True if `extension` is one of the supported `extensions`. */
|
||||
function extensionIsOk(extensions: Extensions, extension: Extension): boolean {
|
||||
switch (extensions) {
|
||||
case Extensions.JavaScript:
|
||||
return extension === Extension.Js || extension === Extension.Jsx;
|
||||
case Extensions.TypeScript:
|
||||
return extension === Extension.Ts || extension === Extension.Tsx || extension === Extension.Dts;
|
||||
case Extensions.DtsOnly:
|
||||
return extension === Extension.Dts;
|
||||
}
|
||||
}
|
||||
|
||||
function pathToPackageJson(directory: string): string {
|
||||
return combinePaths(directory, "package.json");
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
const nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, nodeModulesFolder: string, nodeModulesFolderExists: boolean, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
|
||||
return loadModuleFromFile(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state) ||
|
||||
loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ false);
|
||||
function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, cache: NonRelativeModuleNameResolutionCache): SearchResult<Resolved> {
|
||||
return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ false, cache);
|
||||
}
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): SearchResult<Resolved> {
|
||||
// Extensions parameter here doesn't actually matter, because typesOnly ensures we're just doing @types lookup, which is always DtsOnly.
|
||||
return loadModuleFromNodeModulesWorker(Extensions.DtsOnly, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true);
|
||||
return loadModuleFromNodeModulesWorker(Extensions.DtsOnly, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true, /*cache*/ undefined);
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly: boolean): Resolved | undefined {
|
||||
function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly: boolean, cache: NonRelativeModuleNameResolutionCache): SearchResult<Resolved> {
|
||||
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
|
||||
return forEachAncestorDirectory(normalizeSlashes(directory), ancestorDirectory => {
|
||||
if (getBaseFileName(ancestorDirectory) !== "node_modules") {
|
||||
return loadModuleFromNodeModulesOneLevel(extensions, moduleName, ancestorDirectory, failedLookupLocations, state, typesOnly);
|
||||
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, ancestorDirectory, state.traceEnabled, state.host);
|
||||
if (resolutionFromCache) {
|
||||
return resolutionFromCache;
|
||||
}
|
||||
return toSearchResult(loadModuleFromNodeModulesOneLevel(extensions, moduleName, ancestorDirectory, failedLookupLocations, state, typesOnly));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Load a module from a single node_modules directory, but not from any ancestors' node_modules directories. */
|
||||
function loadModuleFromNodeModulesOneLevel(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push<string>, state: ModuleResolutionState, typesOnly = false): Resolved | undefined {
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state);
|
||||
const nodeModulesFolder = combinePaths(directory, "node_modules");
|
||||
const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host);
|
||||
if (!nodeModulesFolderExists && state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, nodeModulesFolder);
|
||||
}
|
||||
|
||||
const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, nodeModulesFolder, nodeModulesFolderExists, failedLookupLocations, state);
|
||||
if (packageResult) {
|
||||
return packageResult;
|
||||
}
|
||||
if (extensions !== Extensions.JavaScript) {
|
||||
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, combinePaths("@types", moduleName), directory, failedLookupLocations, state);
|
||||
const nodeModulesAtTypes = combinePaths(nodeModulesFolder, "@types");
|
||||
let nodeModulesAtTypesExists = nodeModulesFolderExists;
|
||||
if (nodeModulesFolderExists && !directoryProbablyExists(nodeModulesAtTypes, state.host)) {
|
||||
if (state.traceEnabled) {
|
||||
trace(state.host, Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it, nodeModulesAtTypes);
|
||||
}
|
||||
nodeModulesAtTypesExists = false;
|
||||
}
|
||||
return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, moduleName, nodeModulesAtTypes, nodeModulesAtTypesExists, failedLookupLocations, state);
|
||||
}
|
||||
}
|
||||
|
||||
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
function tryFindNonRelativeModuleNameInCache(cache: PerModuleNameCache | undefined, moduleName: string, containingDirectory: string, traceEnabled: boolean, host: ModuleResolutionHost): SearchResult<Resolved> {
|
||||
const result = cache && cache.get(containingDirectory);
|
||||
if (result) {
|
||||
if (traceEnabled) {
|
||||
trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName)
|
||||
}
|
||||
return { value: result.resolvedModule && { path: result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension } };
|
||||
}
|
||||
}
|
||||
|
||||
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache): ResolvedModuleWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
|
||||
const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ false, failedLookupLocations);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*isExternalLibraryImport*/ false, failedLookupLocations);
|
||||
|
||||
function tryResolve(extensions: Extensions): Resolved | undefined {
|
||||
function tryResolve(extensions: Extensions): SearchResult<Resolved> {
|
||||
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loadModuleFromFile, failedLookupLocations, state);
|
||||
if (resolvedUsingSettings) {
|
||||
return resolvedUsingSettings;
|
||||
return { value: resolvedUsingSettings };
|
||||
}
|
||||
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
|
||||
|
||||
if (moduleHasNonRelativeName(moduleName)) {
|
||||
// Climb up parent directories looking for a module.
|
||||
const resolved = forEachAncestorDirectory(containingDirectory, directory => {
|
||||
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, traceEnabled, host);
|
||||
if (resolutionFromCache) {
|
||||
return resolutionFromCache;
|
||||
}
|
||||
const searchName = normalizePath(combinePaths(directory, moduleName));
|
||||
return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
return toSearchResult(loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state));
|
||||
});
|
||||
if (resolved) {
|
||||
return resolved;
|
||||
@@ -780,7 +999,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
return loadModuleFromFile(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
return toSearchResult(loadModuleFromFile(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -801,8 +1020,28 @@ namespace ts {
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents result of search. Normally when searching among several alternatives we treat value `undefined` as indicator
|
||||
* that search fails and we should try another option.
|
||||
* However this does not allow us to represent final result that should be used instead of further searching (i.e. a final result that was found in cache).
|
||||
* SearchResult is used to deal with this issue, its values represents following outcomes:
|
||||
* - undefined - not found, continue searching
|
||||
* - { value: undefined } - not found - stop searching
|
||||
* - { value: <some-value> } - found - stop searching
|
||||
*/
|
||||
type SearchResult<T> = { value: T | undefined } | undefined;
|
||||
|
||||
/**
|
||||
* Wraps value to SearchResult.
|
||||
* @returns undefined if value is undefined or { value } otherwise
|
||||
*/
|
||||
function toSearchResult<T>(value: T | undefined): SearchResult<T> {
|
||||
return value !== undefined ? { value } : undefined;
|
||||
}
|
||||
|
||||
|
||||
/** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */
|
||||
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => T | undefined): T | undefined {
|
||||
function forEachAncestorDirectory<T>(directory: string, callback: (directory: string) => SearchResult<T>): SearchResult<T> {
|
||||
while (true) {
|
||||
const result = callback(directory);
|
||||
if (result !== undefined) {
|
||||
|
||||
+18
-7
@@ -198,6 +198,8 @@ namespace ts {
|
||||
visitNode(cbNode, (<AsExpression>node).type);
|
||||
case SyntaxKind.NonNullExpression:
|
||||
return visitNode(cbNode, (<NonNullExpression>node).expression);
|
||||
case SyntaxKind.MetaProperty:
|
||||
return visitNode(cbNode, (<MetaProperty>node).name);
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
return visitNode(cbNode, (<ConditionalExpression>node).condition) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).questionToken) ||
|
||||
@@ -374,7 +376,8 @@ namespace ts {
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
return visitNode(cbNode, (<JsxSpreadAttribute>node).expression);
|
||||
case SyntaxKind.JsxExpression:
|
||||
return visitNode(cbNode, (<JsxExpression>node).expression);
|
||||
return visitNode(cbNode, (node as JsxExpression).dotDotDotToken) ||
|
||||
visitNode(cbNode, (node as JsxExpression).expression);
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
return visitNode(cbNode, (<JsxClosingElement>node).tagName);
|
||||
|
||||
@@ -1679,8 +1682,8 @@ namespace ts {
|
||||
// Method declarations are not necessarily reusable. An object-literal
|
||||
// may have a method calls "constructor(...)" and we must reparse that
|
||||
// into an actual .ConstructorDeclaration.
|
||||
let methodDeclaration = <MethodDeclaration>node;
|
||||
let nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
|
||||
const methodDeclaration = <MethodDeclaration>node;
|
||||
const nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
|
||||
(<Identifier>methodDeclaration.name).originalKeywordKind === SyntaxKind.ConstructorKeyword;
|
||||
|
||||
return !nameIsConstructor;
|
||||
@@ -3915,6 +3918,7 @@ namespace ts {
|
||||
|
||||
parseExpected(SyntaxKind.OpenBraceToken);
|
||||
if (token() !== SyntaxKind.CloseBraceToken) {
|
||||
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
|
||||
node.expression = parseAssignmentExpressionOrHigher();
|
||||
}
|
||||
if (inExpressionContext) {
|
||||
@@ -4330,15 +4334,22 @@ namespace ts {
|
||||
return isIdentifier() ? parseIdentifier() : undefined;
|
||||
}
|
||||
|
||||
function parseNewExpression(): NewExpression {
|
||||
const node = <NewExpression>createNode(SyntaxKind.NewExpression);
|
||||
function parseNewExpression(): NewExpression | MetaProperty {
|
||||
const fullStart = scanner.getStartPos();
|
||||
parseExpected(SyntaxKind.NewKeyword);
|
||||
if (parseOptional(SyntaxKind.DotToken)) {
|
||||
const node = <MetaProperty>createNode(SyntaxKind.MetaProperty, fullStart);
|
||||
node.keywordToken = SyntaxKind.NewKeyword;
|
||||
node.name = parseIdentifierName();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
const node = <NewExpression>createNode(SyntaxKind.NewExpression, fullStart);
|
||||
node.expression = parseMemberExpressionOrHigher();
|
||||
node.typeArguments = tryParse(parseTypeArgumentsInExpression);
|
||||
if (node.typeArguments || token() === SyntaxKind.OpenParenToken) {
|
||||
node.arguments = parseArgumentList();
|
||||
}
|
||||
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -7407,7 +7418,7 @@ namespace ts {
|
||||
if (position >= array.pos && position < array.end) {
|
||||
// position was in this array. Search through this array to see if we find a
|
||||
// viable element.
|
||||
for (let i = 0, n = array.length; i < n; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const child = array[i];
|
||||
if (child) {
|
||||
if (child.pos === position) {
|
||||
|
||||
+12
-6
@@ -40,7 +40,8 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) {
|
||||
const n = Math.min(commonPathComponents.length, sourcePathComponents.length);
|
||||
for (let i = 0; i < n; i++) {
|
||||
if (getCanonicalFileName(commonPathComponents[i]) !== getCanonicalFileName(sourcePathComponents[i])) {
|
||||
if (i === 0) {
|
||||
// Failed to find any common path component
|
||||
@@ -325,6 +326,7 @@ namespace ts {
|
||||
// Map storing if there is emit blocking diagnostics for given input
|
||||
const hasEmitBlockingDiagnostics = createFileMap<boolean>(getCanonicalFileName);
|
||||
|
||||
let moduleResolutionCache: ModuleResolutionCache;
|
||||
let resolveModuleNamesWorker: (moduleNames: string[], containingFile: string) => ResolvedModuleFull[];
|
||||
if (host.resolveModuleNames) {
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile).map(resolved => {
|
||||
@@ -338,7 +340,8 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
else {
|
||||
const loader = (moduleName: string, containingFile: string) => resolveModuleName(moduleName, containingFile, options, host).resolvedModule;
|
||||
moduleResolutionCache = createModuleResolutionCache(currentDirectory, x => host.getCanonicalFileName(x));
|
||||
const loader = (moduleName: string, containingFile: string) => resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache).resolvedModule;
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile) => loadWithLocalCache(moduleNames, containingFile, loader);
|
||||
}
|
||||
|
||||
@@ -391,6 +394,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
// unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks
|
||||
moduleResolutionCache = undefined;
|
||||
|
||||
// unconditionally set oldProgram to undefined to prevent it from being captured in closure
|
||||
oldProgram = undefined;
|
||||
|
||||
@@ -695,7 +701,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// update fileName -> file mapping
|
||||
for (let i = 0, len = newSourceFiles.length; i < len; i++) {
|
||||
for (let i = 0; i < newSourceFiles.length; i++) {
|
||||
filesByName.set(filePaths[i], newSourceFiles[i]);
|
||||
}
|
||||
|
||||
@@ -952,7 +958,7 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.HeritageClause:
|
||||
let heritageClause = <HeritageClause>node;
|
||||
const heritageClause = <HeritageClause>node;
|
||||
if (heritageClause.token === SyntaxKind.ImplementsKeyword) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
@@ -971,7 +977,7 @@ namespace ts {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
let typeAssertionExpression = <TypeAssertion>node;
|
||||
const typeAssertionExpression = <TypeAssertion>node;
|
||||
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
|
||||
return;
|
||||
}
|
||||
@@ -1170,7 +1176,7 @@ namespace ts {
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
let moduleNameExpr = getExternalModuleName(node);
|
||||
const moduleNameExpr = getExternalModuleName(node);
|
||||
if (!moduleNameExpr || moduleNameExpr.kind !== SyntaxKind.StringLiteral) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -531,7 +531,7 @@ namespace ts {
|
||||
const ch = text.charCodeAt(pos);
|
||||
|
||||
if ((pos + mergeConflictMarkerLength) < text.length) {
|
||||
for (let i = 0, n = mergeConflictMarkerLength; i < n; i++) {
|
||||
for (let i = 0; i < mergeConflictMarkerLength; i++) {
|
||||
if (text.charCodeAt(pos + i) !== ch) {
|
||||
return false;
|
||||
}
|
||||
@@ -643,7 +643,7 @@ namespace ts {
|
||||
pos++;
|
||||
continue;
|
||||
case CharacterCodes.slash:
|
||||
let nextChar = text.charCodeAt(pos + 1);
|
||||
const nextChar = text.charCodeAt(pos + 1);
|
||||
let hasTrailingNewLine = false;
|
||||
if (nextChar === CharacterCodes.slash || nextChar === CharacterCodes.asterisk) {
|
||||
const kind = nextChar === CharacterCodes.slash ? SyntaxKind.SingleLineCommentTrivia : SyntaxKind.MultiLineCommentTrivia;
|
||||
@@ -766,7 +766,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 1, n = name.length; i < n; i++) {
|
||||
for (let i = 1; i < name.length; i++) {
|
||||
if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1563,7 +1563,7 @@ namespace ts {
|
||||
pos++;
|
||||
return token = SyntaxKind.AtToken;
|
||||
case CharacterCodes.backslash:
|
||||
let cookedChar = peekUnicodeEscape();
|
||||
const cookedChar = peekUnicodeEscape();
|
||||
if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) {
|
||||
pos += 6;
|
||||
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
|
||||
|
||||
+1
-1
@@ -160,7 +160,7 @@ namespace ts {
|
||||
|
||||
function getNames(collection: any): string[] {
|
||||
const result: string[] = [];
|
||||
for (let e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
|
||||
for (const e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
|
||||
result.push(e.item().Name);
|
||||
}
|
||||
return result.sort();
|
||||
|
||||
@@ -249,14 +249,16 @@ namespace ts {
|
||||
//
|
||||
// Subtree facts
|
||||
//
|
||||
NewTarget = 1 << 14, // Contains a 'new.target' meta-property
|
||||
NewTargetInComputedPropertyName = 1 << 15, // Contains a 'new.target' meta-property in a computed property name.
|
||||
|
||||
// NOTE: To be added in a later PR
|
||||
|
||||
//
|
||||
// Subtree masks
|
||||
//
|
||||
|
||||
SubtreeFactsMask = ~AncestorFactsMask,
|
||||
PropagateNewTargetMask = NewTarget | NewTargetInComputedPropertyName,
|
||||
}
|
||||
|
||||
export function transformES2015(context: TransformationContext) {
|
||||
@@ -483,6 +485,9 @@ namespace ts {
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return visitThisKeyword(node);
|
||||
|
||||
case SyntaxKind.MetaProperty:
|
||||
return visitMetaProperty(<MetaProperty>node);
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return visitMethodDeclaration(<MethodDeclaration>node);
|
||||
|
||||
@@ -567,7 +572,7 @@ namespace ts {
|
||||
function visitThisKeyword(node: Node): Node {
|
||||
if (convertedLoopState) {
|
||||
if (hierarchyFacts & HierarchyFacts.ArrowFunction) {
|
||||
// if the enclosing function is an ArrowFunction is then we use the captured 'this' keyword.
|
||||
// if the enclosing function is an ArrowFunction then we use the captured 'this' keyword.
|
||||
convertedLoopState.containsLexicalThis = true;
|
||||
return node;
|
||||
}
|
||||
@@ -870,7 +875,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
statements.push(constructorFunction);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
}
|
||||
|
||||
@@ -951,6 +956,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
addRange(statements, endLexicalEnvironment());
|
||||
|
||||
if (constructor) {
|
||||
prependCaptureNewTargetIfNeeded(statements, constructor, /*copyOnWrite*/ false);
|
||||
}
|
||||
|
||||
const block = createBlock(
|
||||
createNodeArray(
|
||||
statements,
|
||||
@@ -1394,6 +1404,77 @@ namespace ts {
|
||||
statements.push(captureThisStatement);
|
||||
}
|
||||
|
||||
function prependCaptureNewTargetIfNeeded(statements: Statement[], node: FunctionLikeDeclaration, copyOnWrite: boolean): Statement[] {
|
||||
if (hierarchyFacts & HierarchyFacts.NewTarget) {
|
||||
let newTarget: Expression;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return statements;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
// Methods and accessors cannot be constructors, so 'new.target' will
|
||||
// always return 'undefined'.
|
||||
newTarget = createVoidZero();
|
||||
break;
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
// Class constructors can only be called with `new`, so `this.constructor`
|
||||
// should be relatively safe to use.
|
||||
newTarget = createPropertyAccess(
|
||||
setEmitFlags(createThis(), EmitFlags.NoSubstitution),
|
||||
"constructor"
|
||||
);
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
// Functions can be called or constructed, and may have a `this` due to
|
||||
// being a member or when calling an imported function via `other_1.f()`.
|
||||
newTarget = createConditional(
|
||||
createLogicalAnd(
|
||||
setEmitFlags(createThis(), EmitFlags.NoSubstitution),
|
||||
createBinary(
|
||||
setEmitFlags(createThis(), EmitFlags.NoSubstitution),
|
||||
SyntaxKind.InstanceOfKeyword,
|
||||
getLocalName(node)
|
||||
)
|
||||
),
|
||||
createPropertyAccess(
|
||||
setEmitFlags(createThis(), EmitFlags.NoSubstitution),
|
||||
"constructor"
|
||||
),
|
||||
createVoidZero()
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.failBadSyntaxKind(node);
|
||||
break;
|
||||
}
|
||||
|
||||
const captureNewTargetStatement = createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
createVariableDeclarationList([
|
||||
createVariableDeclaration(
|
||||
"_newTarget",
|
||||
/*type*/ undefined,
|
||||
newTarget
|
||||
)
|
||||
])
|
||||
);
|
||||
|
||||
if (copyOnWrite) {
|
||||
return [captureNewTargetStatement, ...statements];
|
||||
}
|
||||
|
||||
statements.unshift(captureNewTargetStatement);
|
||||
}
|
||||
|
||||
return statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds statements to the class body function for a class to define the members of the
|
||||
* class.
|
||||
@@ -1469,7 +1550,7 @@ namespace ts {
|
||||
// old emitter.
|
||||
setEmitFlags(statement, EmitFlags.NoSourceMap);
|
||||
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, hierarchyFacts & HierarchyFacts.PropagateNewTargetMask ? HierarchyFacts.NewTarget : HierarchyFacts.None);
|
||||
return statement;
|
||||
}
|
||||
|
||||
@@ -1548,7 +1629,7 @@ namespace ts {
|
||||
call.startsOnNewLine = true;
|
||||
}
|
||||
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, hierarchyFacts & HierarchyFacts.PropagateNewTargetMask ? HierarchyFacts.NewTarget : HierarchyFacts.None);
|
||||
return call;
|
||||
}
|
||||
|
||||
@@ -1592,21 +1673,27 @@ namespace ts {
|
||||
: enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes);
|
||||
const savedConvertedLoopState = convertedLoopState;
|
||||
convertedLoopState = undefined;
|
||||
const updated = updateFunctionExpression(
|
||||
|
||||
const parameters = visitParameterList(node.parameters, visitor, context);
|
||||
const body = node.transformFlags & TransformFlags.ES2015
|
||||
? transformFunctionBody(node)
|
||||
: visitFunctionBodyDownLevel(node);
|
||||
const name = hierarchyFacts & HierarchyFacts.NewTarget
|
||||
? getLocalName(node)
|
||||
: node.name;
|
||||
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return updateFunctionExpression(
|
||||
node,
|
||||
/*modifiers*/ undefined,
|
||||
node.asteriskToken,
|
||||
node.name,
|
||||
name,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
parameters,
|
||||
/*type*/ undefined,
|
||||
node.transformFlags & TransformFlags.ES2015
|
||||
? transformFunctionBody(node)
|
||||
: visitFunctionBody(node.body, functionBodyVisitor, context)
|
||||
body
|
||||
);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1618,23 +1705,27 @@ namespace ts {
|
||||
const savedConvertedLoopState = convertedLoopState;
|
||||
convertedLoopState = undefined;
|
||||
const ancestorFacts = enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes);
|
||||
const updated = updateFunctionDeclaration(
|
||||
const parameters = visitParameterList(node.parameters, visitor, context);
|
||||
const body = node.transformFlags & TransformFlags.ES2015
|
||||
? transformFunctionBody(node)
|
||||
: visitFunctionBodyDownLevel(node);
|
||||
const name = hierarchyFacts & HierarchyFacts.NewTarget
|
||||
? getLocalName(node)
|
||||
: node.name;
|
||||
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return updateFunctionDeclaration(
|
||||
node,
|
||||
/*decorators*/ undefined,
|
||||
visitNodes(node.modifiers, visitor, isModifier),
|
||||
node.asteriskToken,
|
||||
node.name,
|
||||
name,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
parameters,
|
||||
/*type*/ undefined,
|
||||
node.transformFlags & TransformFlags.ES2015
|
||||
? transformFunctionBody(node)
|
||||
: visitFunctionBody(node.body, functionBodyVisitor, context)
|
||||
body
|
||||
);
|
||||
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1650,22 +1741,27 @@ namespace ts {
|
||||
const ancestorFacts = container && isClassLike(container) && !hasModifier(node, ModifierFlags.Static)
|
||||
? enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes | HierarchyFacts.NonStaticClassElement)
|
||||
: enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes);
|
||||
const expression = setOriginalNode(
|
||||
const parameters = visitParameterList(node.parameters, visitor, context);
|
||||
const body = transformFunctionBody(node);
|
||||
if (hierarchyFacts & HierarchyFacts.NewTarget && !name && (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.FunctionExpression)) {
|
||||
name = getGeneratedNameForNode(node);
|
||||
}
|
||||
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return setOriginalNode(
|
||||
createFunctionExpression(
|
||||
/*modifiers*/ undefined,
|
||||
node.asteriskToken,
|
||||
name,
|
||||
/*typeParameters*/ undefined,
|
||||
visitParameterList(node.parameters, visitor, context),
|
||||
parameters,
|
||||
/*type*/ undefined,
|
||||
transformFunctionBody(node),
|
||||
body,
|
||||
location
|
||||
),
|
||||
/*original*/ node
|
||||
);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1740,6 +1836,8 @@ namespace ts {
|
||||
const lexicalEnvironment = context.endLexicalEnvironment();
|
||||
addRange(statements, lexicalEnvironment);
|
||||
|
||||
prependCaptureNewTargetIfNeeded(statements, node, /*copyOnWrite*/ false);
|
||||
|
||||
// If we added any final generated statements, this must be a multi-line block
|
||||
if (!multiLine && lexicalEnvironment && lexicalEnvironment.length) {
|
||||
multiLine = true;
|
||||
@@ -1758,6 +1856,17 @@ namespace ts {
|
||||
return block;
|
||||
}
|
||||
|
||||
function visitFunctionBodyDownLevel(node: FunctionDeclaration | FunctionExpression) {
|
||||
const updated = visitFunctionBody(node.body, functionBodyVisitor, context);
|
||||
return updateBlock(
|
||||
updated,
|
||||
createNodeArray(
|
||||
prependCaptureNewTargetIfNeeded(updated.statements, node, /*copyOnWrite*/ true),
|
||||
/*location*/ updated.statements
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function visitBlock(node: Block, isFunctionBody: boolean): Block {
|
||||
if (isFunctionBody) {
|
||||
// A function body is not a block scope.
|
||||
@@ -2973,7 +3082,7 @@ namespace ts {
|
||||
if (startsOnNewLine) {
|
||||
expression.startsOnNewLine = true;
|
||||
}
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, hierarchyFacts & HierarchyFacts.PropagateNewTargetMask ? HierarchyFacts.NewTarget : HierarchyFacts.None);
|
||||
return expression;
|
||||
}
|
||||
|
||||
@@ -3038,7 +3147,7 @@ namespace ts {
|
||||
convertedLoopState = undefined;
|
||||
const ancestorFacts = enterSubtree(HierarchyFacts.FunctionExcludes, HierarchyFacts.FunctionIncludes);
|
||||
const updated = visitEachChild(node, visitor, context);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, HierarchyFacts.None);
|
||||
convertedLoopState = savedConvertedLoopState;
|
||||
return updated;
|
||||
}
|
||||
@@ -3059,7 +3168,7 @@ namespace ts {
|
||||
function visitComputedPropertyName(node: ComputedPropertyName) {
|
||||
const ancestorFacts = enterSubtree(HierarchyFacts.ComputedPropertyNameExcludes, HierarchyFacts.ComputedPropertyNameIncludes);
|
||||
const updated = visitEachChild(node, visitor, context);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
|
||||
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, hierarchyFacts & HierarchyFacts.PropagateNewTargetMask ? HierarchyFacts.NewTargetInComputedPropertyName : HierarchyFacts.None);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@@ -3453,6 +3562,19 @@ namespace ts {
|
||||
: createIdentifier("_super");
|
||||
}
|
||||
|
||||
function visitMetaProperty(node: MetaProperty) {
|
||||
if (node.keywordToken === SyntaxKind.NewKeyword && node.name.text === "target") {
|
||||
if (hierarchyFacts & HierarchyFacts.ComputedPropertyName) {
|
||||
hierarchyFacts |= HierarchyFacts.NewTargetInComputedPropertyName;
|
||||
}
|
||||
else {
|
||||
hierarchyFacts |= HierarchyFacts.NewTarget;
|
||||
}
|
||||
return createIdentifier("_newTarget");
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the printer just before a node is printed.
|
||||
*
|
||||
|
||||
@@ -938,7 +938,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
markLabel(resumeLabel);
|
||||
return createGeneratorResume();
|
||||
return createGeneratorResume(/*location*/ node);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1238,7 +1238,9 @@ namespace ts {
|
||||
|
||||
function transformAndEmitVariableDeclarationList(node: VariableDeclarationList): VariableDeclarationList {
|
||||
for (const variable of node.declarations) {
|
||||
hoistVariableDeclaration(<Identifier>variable.name);
|
||||
const name = getSynthesizedClone(<Identifier>variable.name);
|
||||
setCommentRange(name, variable.name);
|
||||
hoistVariableDeclaration(name);
|
||||
}
|
||||
|
||||
const variables = getInitializedVariables(node);
|
||||
@@ -1291,7 +1293,7 @@ namespace ts {
|
||||
if (containsYield(node.thenStatement) || containsYield(node.elseStatement)) {
|
||||
const endLabel = defineLabel();
|
||||
const elseLabel = node.elseStatement ? defineLabel() : undefined;
|
||||
emitBreakWhenFalse(node.elseStatement ? elseLabel : endLabel, visitNode(node.expression, visitor, isExpression));
|
||||
emitBreakWhenFalse(node.elseStatement ? elseLabel : endLabel, visitNode(node.expression, visitor, isExpression), /*location*/ node.expression);
|
||||
transformAndEmitEmbeddedStatement(node.thenStatement);
|
||||
if (node.elseStatement) {
|
||||
emitBreak(endLabel);
|
||||
@@ -2969,12 +2971,15 @@ namespace ts {
|
||||
lastOperationWasAbrupt = true;
|
||||
lastOperationWasCompletion = true;
|
||||
writeStatement(
|
||||
createReturn(
|
||||
createArrayLiteral(expression
|
||||
? [createInstruction(Instruction.Return), expression]
|
||||
: [createInstruction(Instruction.Return)]
|
||||
setEmitFlags(
|
||||
createReturn(
|
||||
createArrayLiteral(expression
|
||||
? [createInstruction(Instruction.Return), expression]
|
||||
: [createInstruction(Instruction.Return)]
|
||||
),
|
||||
operationLocation
|
||||
),
|
||||
operationLocation
|
||||
EmitFlags.NoTokenSourceMaps
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -2988,12 +2993,15 @@ namespace ts {
|
||||
function writeBreak(label: Label, operationLocation: TextRange): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
writeStatement(
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.Break),
|
||||
createLabel(label)
|
||||
]),
|
||||
operationLocation
|
||||
setEmitFlags(
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.Break),
|
||||
createLabel(label)
|
||||
]),
|
||||
operationLocation
|
||||
),
|
||||
EmitFlags.NoTokenSourceMaps
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -3007,15 +3015,21 @@ namespace ts {
|
||||
*/
|
||||
function writeBreakWhenTrue(label: Label, condition: Expression, operationLocation: TextRange): void {
|
||||
writeStatement(
|
||||
createIf(
|
||||
condition,
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.Break),
|
||||
createLabel(label)
|
||||
]),
|
||||
operationLocation
|
||||
)
|
||||
setEmitFlags(
|
||||
createIf(
|
||||
condition,
|
||||
setEmitFlags(
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.Break),
|
||||
createLabel(label)
|
||||
]),
|
||||
operationLocation
|
||||
),
|
||||
EmitFlags.NoTokenSourceMaps
|
||||
)
|
||||
),
|
||||
EmitFlags.SingleLine
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -3029,15 +3043,21 @@ namespace ts {
|
||||
*/
|
||||
function writeBreakWhenFalse(label: Label, condition: Expression, operationLocation: TextRange): void {
|
||||
writeStatement(
|
||||
createIf(
|
||||
createLogicalNot(condition),
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.Break),
|
||||
createLabel(label)
|
||||
]),
|
||||
operationLocation
|
||||
)
|
||||
setEmitFlags(
|
||||
createIf(
|
||||
createLogicalNot(condition),
|
||||
setEmitFlags(
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.Break),
|
||||
createLabel(label)
|
||||
]),
|
||||
operationLocation
|
||||
),
|
||||
EmitFlags.NoTokenSourceMaps
|
||||
)
|
||||
),
|
||||
EmitFlags.SingleLine
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -3051,13 +3071,16 @@ namespace ts {
|
||||
function writeYield(expression: Expression, operationLocation: TextRange): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
writeStatement(
|
||||
createReturn(
|
||||
createArrayLiteral(
|
||||
expression
|
||||
? [createInstruction(Instruction.Yield), expression]
|
||||
: [createInstruction(Instruction.Yield)]
|
||||
setEmitFlags(
|
||||
createReturn(
|
||||
createArrayLiteral(
|
||||
expression
|
||||
? [createInstruction(Instruction.Yield), expression]
|
||||
: [createInstruction(Instruction.Yield)]
|
||||
),
|
||||
operationLocation
|
||||
),
|
||||
operationLocation
|
||||
EmitFlags.NoTokenSourceMaps
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -3071,12 +3094,15 @@ namespace ts {
|
||||
function writeYieldStar(expression: Expression, operationLocation: TextRange): void {
|
||||
lastOperationWasAbrupt = true;
|
||||
writeStatement(
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.YieldStar),
|
||||
expression
|
||||
]),
|
||||
operationLocation
|
||||
setEmitFlags(
|
||||
createReturn(
|
||||
createArrayLiteral([
|
||||
createInstruction(Instruction.YieldStar),
|
||||
expression
|
||||
]),
|
||||
operationLocation
|
||||
),
|
||||
EmitFlags.NoTokenSourceMaps
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -105,28 +105,7 @@ namespace ts {
|
||||
function transformAMDModule(node: SourceFile) {
|
||||
const define = createIdentifier("define");
|
||||
const moduleName = tryGetModuleNameFromFile(node, host, compilerOptions);
|
||||
return transformAsynchronousModule(node, define, moduleName, /*includeNonAmdDependencies*/ true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a SourceFile into a UMD module.
|
||||
*
|
||||
* @param node The SourceFile node.
|
||||
*/
|
||||
function transformUMDModule(node: SourceFile) {
|
||||
const define = createRawExpression(umdHelper);
|
||||
return transformAsynchronousModule(node, define, /*moduleName*/ undefined, /*includeNonAmdDependencies*/ false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a SourceFile into an AMD or UMD module.
|
||||
*
|
||||
* @param node The SourceFile node.
|
||||
* @param define The expression used to define the module.
|
||||
* @param moduleName An expression for the module name, if available.
|
||||
* @param includeNonAmdDependencies A value indicating whether to incldue any non-AMD dependencies.
|
||||
*/
|
||||
function transformAsynchronousModule(node: SourceFile, define: Expression, moduleName: Expression, includeNonAmdDependencies: boolean) {
|
||||
// An AMD define function has the following shape:
|
||||
//
|
||||
// define(id?, dependencies?, factory);
|
||||
@@ -148,7 +127,7 @@ namespace ts {
|
||||
//
|
||||
// we need to add modules without alias names to the end of the dependencies list
|
||||
|
||||
const { aliasedModuleNames, unaliasedModuleNames, importAliasNames } = collectAsynchronousDependencies(node, includeNonAmdDependencies);
|
||||
const { aliasedModuleNames, unaliasedModuleNames, importAliasNames } = collectAsynchronousDependencies(node, /*includeNonAmdDependencies*/ true);
|
||||
|
||||
// Create an updated SourceFile:
|
||||
//
|
||||
@@ -197,6 +176,137 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a SourceFile into a UMD module.
|
||||
*
|
||||
* @param node The SourceFile node.
|
||||
*/
|
||||
function transformUMDModule(node: SourceFile) {
|
||||
const { aliasedModuleNames, unaliasedModuleNames, importAliasNames } = collectAsynchronousDependencies(node, /*includeNonAmdDependencies*/ false);
|
||||
const umdHeader = createFunctionExpression(
|
||||
/*modifiers*/ undefined,
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "factory")],
|
||||
/*type*/ undefined,
|
||||
createBlock(
|
||||
[
|
||||
createIf(
|
||||
createLogicalAnd(
|
||||
createTypeCheck(createIdentifier("module"), "object"),
|
||||
createTypeCheck(createPropertyAccess(createIdentifier("module"), "exports"), "object")
|
||||
),
|
||||
createBlock([
|
||||
createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
[
|
||||
createVariableDeclaration(
|
||||
"v",
|
||||
/*type*/ undefined,
|
||||
createCall(
|
||||
createIdentifier("factory"),
|
||||
/*typeArguments*/ undefined,
|
||||
[
|
||||
createIdentifier("require"),
|
||||
createIdentifier("exports")
|
||||
]
|
||||
)
|
||||
)
|
||||
]
|
||||
),
|
||||
setEmitFlags(
|
||||
createIf(
|
||||
createStrictInequality(
|
||||
createIdentifier("v"),
|
||||
createIdentifier("undefined")
|
||||
),
|
||||
createStatement(
|
||||
createAssignment(
|
||||
createPropertyAccess(createIdentifier("module"), "exports"),
|
||||
createIdentifier("v")
|
||||
)
|
||||
)
|
||||
),
|
||||
EmitFlags.SingleLine
|
||||
)
|
||||
]),
|
||||
createIf(
|
||||
createLogicalAnd(
|
||||
createTypeCheck(createIdentifier("define"), "function"),
|
||||
createPropertyAccess(createIdentifier("define"), "amd")
|
||||
),
|
||||
createBlock([
|
||||
createStatement(
|
||||
createCall(
|
||||
createIdentifier("define"),
|
||||
/*typeArguments*/ undefined,
|
||||
[
|
||||
createArrayLiteral([
|
||||
createLiteral("require"),
|
||||
createLiteral("exports"),
|
||||
...aliasedModuleNames,
|
||||
...unaliasedModuleNames
|
||||
]),
|
||||
createIdentifier("factory")
|
||||
]
|
||||
)
|
||||
)
|
||||
])
|
||||
)
|
||||
)
|
||||
],
|
||||
/*location*/ undefined,
|
||||
/*multiLine*/ true
|
||||
)
|
||||
);
|
||||
|
||||
// Create an updated SourceFile:
|
||||
//
|
||||
// (function (factory) {
|
||||
// if (typeof module === "object" && typeof module.exports === "object") {
|
||||
// var v = factory(require, exports);
|
||||
// if (v !== undefined) module.exports = v;
|
||||
// }
|
||||
// else if (typeof define === 'function' && define.amd) {
|
||||
// define(["require", "exports"], factory);
|
||||
// }
|
||||
// })(function ...)
|
||||
|
||||
return updateSourceFileNode(
|
||||
node,
|
||||
createNodeArray(
|
||||
[
|
||||
createStatement(
|
||||
createCall(
|
||||
umdHeader,
|
||||
/*typeArguments*/ undefined,
|
||||
[
|
||||
// Add the module body function argument:
|
||||
//
|
||||
// function (require, exports) ...
|
||||
createFunctionExpression(
|
||||
/*modifiers*/ undefined,
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
/*typeParameters*/ undefined,
|
||||
[
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "require"),
|
||||
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "exports"),
|
||||
...importAliasNames
|
||||
],
|
||||
/*type*/ undefined,
|
||||
transformAsynchronousModuleBody(node)
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
],
|
||||
/*location*/ node.statements
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the additional asynchronous dependencies for the module.
|
||||
*
|
||||
@@ -1337,15 +1447,4 @@ namespace ts {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}`
|
||||
};
|
||||
|
||||
// emit output for the UMD helper function.
|
||||
const umdHelper = `
|
||||
(function (dependencies, factory) {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
var v = factory(require, exports); if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
define(dependencies, factory);
|
||||
}
|
||||
})`;
|
||||
}
|
||||
|
||||
@@ -1555,12 +1555,15 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression;
|
||||
type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression;
|
||||
|
||||
/**
|
||||
* Serializes the type of a node for use with decorator type metadata.
|
||||
*
|
||||
* @param node The node that should have its type serialized.
|
||||
*/
|
||||
function serializeTypeOfNode(node: Node): Expression {
|
||||
function serializeTypeOfNode(node: Node): SerializedTypeNode {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
@@ -1582,7 +1585,7 @@ namespace ts {
|
||||
*
|
||||
* @param node The node that should have its parameter types serialized.
|
||||
*/
|
||||
function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): Expression {
|
||||
function serializeParameterTypesOfNode(node: Node, container: ClassLikeDeclaration): ArrayLiteralExpression {
|
||||
const valueDeclaration =
|
||||
isClassLike(node)
|
||||
? getFirstConstructorWithBody(node)
|
||||
@@ -1590,7 +1593,7 @@ namespace ts {
|
||||
? node
|
||||
: undefined;
|
||||
|
||||
const expressions: Expression[] = [];
|
||||
const expressions: SerializedTypeNode[] = [];
|
||||
if (valueDeclaration) {
|
||||
const parameters = getParametersOfDecoratedDeclaration(valueDeclaration, container);
|
||||
const numParameters = parameters.length;
|
||||
@@ -1626,7 +1629,7 @@ namespace ts {
|
||||
*
|
||||
* @param node The node that should have its return type serialized.
|
||||
*/
|
||||
function serializeReturnTypeOfNode(node: Node): Expression {
|
||||
function serializeReturnTypeOfNode(node: Node): SerializedTypeNode {
|
||||
if (isFunctionLike(node) && node.type) {
|
||||
return serializeTypeNode(node.type);
|
||||
}
|
||||
@@ -1655,13 +1658,16 @@ namespace ts {
|
||||
*
|
||||
* @param node The type node to serialize.
|
||||
*/
|
||||
function serializeTypeNode(node: TypeNode): Expression {
|
||||
function serializeTypeNode(node: TypeNode): SerializedTypeNode {
|
||||
if (node === undefined) {
|
||||
return createIdentifier("Object");
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.VoidKeyword:
|
||||
case SyntaxKind.UndefinedKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
case SyntaxKind.NeverKeyword:
|
||||
return createVoidZero();
|
||||
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
@@ -1713,37 +1719,8 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.IntersectionType:
|
||||
case SyntaxKind.UnionType:
|
||||
{
|
||||
const unionOrIntersection = <UnionOrIntersectionTypeNode>node;
|
||||
let serializedUnion: Identifier;
|
||||
for (const typeNode of unionOrIntersection.types) {
|
||||
const serializedIndividual = serializeTypeNode(typeNode) as Identifier;
|
||||
// Non identifier
|
||||
if (serializedIndividual.kind !== SyntaxKind.Identifier) {
|
||||
serializedUnion = undefined;
|
||||
break;
|
||||
}
|
||||
return serializeUnionOrIntersectionType(<UnionOrIntersectionTypeNode>node);
|
||||
|
||||
// One of the individual is global object, return immediately
|
||||
if (serializedIndividual.text === "Object") {
|
||||
return serializedIndividual;
|
||||
}
|
||||
|
||||
// Different types
|
||||
if (serializedUnion && serializedUnion.text !== serializedIndividual.text) {
|
||||
serializedUnion = undefined;
|
||||
break;
|
||||
}
|
||||
|
||||
serializedUnion = serializedIndividual;
|
||||
}
|
||||
|
||||
// If we were able to find common type
|
||||
if (serializedUnion) {
|
||||
return serializedUnion;
|
||||
}
|
||||
}
|
||||
// Fallthrough
|
||||
case SyntaxKind.TypeQuery:
|
||||
case SyntaxKind.TypeOperator:
|
||||
case SyntaxKind.IndexedAccessType:
|
||||
@@ -1761,13 +1738,48 @@ namespace ts {
|
||||
return createIdentifier("Object");
|
||||
}
|
||||
|
||||
function serializeUnionOrIntersectionType(node: UnionOrIntersectionTypeNode): SerializedTypeNode {
|
||||
let serializedUnion: SerializedTypeNode;
|
||||
for (const typeNode of node.types) {
|
||||
const serializedIndividual = serializeTypeNode(typeNode);
|
||||
|
||||
if (isVoidExpression(serializedIndividual)) {
|
||||
// If we dont have any other type already set, set the initial type
|
||||
if (!serializedUnion) {
|
||||
serializedUnion = serializedIndividual;
|
||||
}
|
||||
}
|
||||
else if (isIdentifier(serializedIndividual) && serializedIndividual.text === "Object") {
|
||||
// One of the individual is global object, return immediately
|
||||
return serializedIndividual;
|
||||
}
|
||||
// If there exists union that is not void 0 expression, check if the the common type is identifier.
|
||||
// anything more complex and we will just default to Object
|
||||
else if (serializedUnion && !isVoidExpression(serializedUnion)) {
|
||||
// Different types
|
||||
if (!isIdentifier(serializedUnion) ||
|
||||
!isIdentifier(serializedIndividual) ||
|
||||
serializedUnion.text !== serializedIndividual.text) {
|
||||
return createIdentifier("Object");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Initialize the union type
|
||||
serializedUnion = serializedIndividual;
|
||||
}
|
||||
}
|
||||
|
||||
// If we were able to find common type, use it
|
||||
return serializedUnion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes a TypeReferenceNode to an appropriate JS constructor value for use with
|
||||
* decorator type metadata.
|
||||
*
|
||||
* @param node The type reference node.
|
||||
*/
|
||||
function serializeTypeReferenceNode(node: TypeReferenceNode) {
|
||||
function serializeTypeReferenceNode(node: TypeReferenceNode): SerializedTypeNode {
|
||||
switch (resolver.getTypeReferenceSerializationKind(node.typeName, currentScope)) {
|
||||
case TypeReferenceSerializationKind.Unknown:
|
||||
const serialized = serializeEntityNameAsExpression(node.typeName, /*useFallback*/ true);
|
||||
@@ -1822,7 +1834,7 @@ namespace ts {
|
||||
* @param useFallback A value indicating whether to use logical operators to test for the
|
||||
* entity name at runtime.
|
||||
*/
|
||||
function serializeEntityNameAsExpression(node: EntityName, useFallback: boolean): Expression {
|
||||
function serializeEntityNameAsExpression(node: EntityName, useFallback: boolean): SerializedEntityNameAsExpression {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
// Create a clone of the name with a new parent, and treat it as if it were
|
||||
@@ -1855,8 +1867,8 @@ namespace ts {
|
||||
* @param useFallback A value indicating whether to use logical operators to test for the
|
||||
* qualified name at runtime.
|
||||
*/
|
||||
function serializeQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean): Expression {
|
||||
let left: Expression;
|
||||
function serializeQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean): PropertyAccessExpression {
|
||||
let left: SerializedEntityNameAsExpression;
|
||||
if (node.left.kind === SyntaxKind.Identifier) {
|
||||
left = serializeEntityNameAsExpression(node.left, useFallback);
|
||||
}
|
||||
@@ -1881,7 +1893,7 @@ namespace ts {
|
||||
* Gets an expression that points to the global "Symbol" constructor at runtime if it is
|
||||
* available.
|
||||
*/
|
||||
function getGlobalSymbolNameWithFallback(): Expression {
|
||||
function getGlobalSymbolNameWithFallback(): ConditionalExpression {
|
||||
return createConditional(
|
||||
createTypeCheck(createIdentifier("Symbol"), "function"),
|
||||
createIdentifier("Symbol"),
|
||||
@@ -2728,7 +2740,7 @@ namespace ts {
|
||||
let blockLocation: TextRange;
|
||||
const body = node.body;
|
||||
if (body.kind === SyntaxKind.ModuleBlock) {
|
||||
addRange(statements, visitNodes((<ModuleBlock>body).statements, namespaceElementVisitor, isStatement));
|
||||
saveStateAndInvoke(body, body => addRange(statements, visitNodes((<ModuleBlock>body).statements, namespaceElementVisitor, isStatement)));
|
||||
statementsLocation = (<ModuleBlock>body).statements;
|
||||
blockLocation = body;
|
||||
}
|
||||
|
||||
+12
-11
@@ -253,6 +253,7 @@ namespace ts {
|
||||
ExpressionWithTypeArguments,
|
||||
AsExpression,
|
||||
NonNullExpression,
|
||||
MetaProperty,
|
||||
|
||||
// Misc
|
||||
TemplateSpan,
|
||||
@@ -370,7 +371,6 @@ namespace ts {
|
||||
PartiallyEmittedExpression,
|
||||
MergeDeclarationMarker,
|
||||
EndOfDeclarationMarker,
|
||||
RawExpression,
|
||||
|
||||
// Enum value count
|
||||
Count,
|
||||
@@ -1451,6 +1451,14 @@ namespace ts {
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
// NOTE: MetaProperty is really a MemberExpression, but we consider it a PrimaryExpression
|
||||
// for the same reasons we treat NewExpression as a PrimaryExpression.
|
||||
export interface MetaProperty extends PrimaryExpression {
|
||||
kind: SyntaxKind.MetaProperty;
|
||||
keywordToken: SyntaxKind;
|
||||
name: Identifier;
|
||||
}
|
||||
|
||||
/// A JSX expression of the form <TagName attrs>...</TagName>
|
||||
export interface JsxElement extends PrimaryExpression {
|
||||
kind: SyntaxKind.JsxElement;
|
||||
@@ -1499,6 +1507,7 @@ namespace ts {
|
||||
|
||||
export interface JsxExpression extends Expression {
|
||||
kind: SyntaxKind.JsxExpression;
|
||||
dotDotDotToken?: Token<SyntaxKind.DotDotDotToken>;
|
||||
expression?: Expression;
|
||||
}
|
||||
|
||||
@@ -1527,16 +1536,6 @@ namespace ts {
|
||||
kind: SyntaxKind.EndOfDeclarationMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a string of raw text in an expression position. Raw text is never transformed, should
|
||||
* be ES3 compliant, and should have the same precedence as PrimaryExpression.
|
||||
*/
|
||||
/* @internal */
|
||||
export interface RawExpression extends PrimaryExpression {
|
||||
kind: SyntaxKind.RawExpression;
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the beginning of a merged transformed declaration.
|
||||
*/
|
||||
@@ -2721,6 +2720,7 @@ namespace ts {
|
||||
TypeChecked = 0x00000001, // Node has been type checked
|
||||
LexicalThis = 0x00000002, // Lexical 'this' reference
|
||||
CaptureThis = 0x00000004, // Lexical 'this' used in body
|
||||
CaptureNewTarget = 0x00000008, // Lexical 'new.target' used in body
|
||||
SuperInstance = 0x00000100, // Instance 'super' reference
|
||||
SuperStatic = 0x00000200, // Static 'super' reference
|
||||
ContextChecked = 0x00000400, // Contextual types have been assigned
|
||||
@@ -3566,6 +3566,7 @@ namespace ts {
|
||||
|
||||
export interface ResolvedModuleWithFailedLookupLocations {
|
||||
resolvedModule: ResolvedModuleFull | undefined;
|
||||
/* @internal */
|
||||
failedLookupLocations: string[];
|
||||
}
|
||||
|
||||
|
||||
+57
-16
@@ -1,4 +1,4 @@
|
||||
/// <reference path="sys.ts" />
|
||||
/// <reference path="sys.ts" />
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
@@ -550,7 +550,7 @@ namespace ts {
|
||||
let errorNode = node;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
let pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
|
||||
const pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
|
||||
if (pos === sourceFile.text.length) {
|
||||
// file is empty - return span for the beginning of the file
|
||||
return createTextSpan(0, 0);
|
||||
@@ -682,7 +682,7 @@ namespace ts {
|
||||
case SyntaxKind.QualifiedName:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
let parent = node.parent;
|
||||
const parent = node.parent;
|
||||
if (parent.kind === SyntaxKind.TypeQuery) {
|
||||
return false;
|
||||
}
|
||||
@@ -732,6 +732,20 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isChildOfNodeWithKind(node: Node, kind: SyntaxKind): boolean {
|
||||
while (node) {
|
||||
if (node.kind === kind) {
|
||||
return true;
|
||||
}
|
||||
node = node.parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isPrefixUnaryExpression(node: Node): node is PrefixUnaryExpression {
|
||||
return node.kind === SyntaxKind.PrefixUnaryExpression;
|
||||
}
|
||||
|
||||
// Warning: This has the same semantics as the forEach family of functions,
|
||||
// in that traversal terminates in the event that 'visitor' supplies a truthy value.
|
||||
export function forEachReturnStatement<T>(body: Block, visitor: (stmt: ReturnStatement) => T): T {
|
||||
@@ -770,7 +784,7 @@ namespace ts {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.YieldExpression:
|
||||
visitor(<YieldExpression>node);
|
||||
let operand = (<YieldExpression>node).expression;
|
||||
const operand = (<YieldExpression>node).expression;
|
||||
if (operand) {
|
||||
traverse(operand);
|
||||
}
|
||||
@@ -1012,6 +1026,20 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getNewTargetContainer(node: Node) {
|
||||
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
|
||||
if (container) {
|
||||
switch (container.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an super call/property node, returns the closest node where
|
||||
* - a super call/property access is legal in the node and not legal in the parent node the node.
|
||||
@@ -1219,6 +1247,7 @@ namespace ts {
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.MetaProperty:
|
||||
return true;
|
||||
case SyntaxKind.QualifiedName:
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
@@ -1233,7 +1262,7 @@ namespace ts {
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
let parent = node.parent;
|
||||
const parent = node.parent;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
@@ -1255,13 +1284,13 @@ namespace ts {
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return (<ExpressionStatement>parent).expression === node;
|
||||
case SyntaxKind.ForStatement:
|
||||
let forStatement = <ForStatement>parent;
|
||||
const forStatement = <ForStatement>parent;
|
||||
return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
|
||||
forStatement.condition === node ||
|
||||
forStatement.incrementor === node;
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForOfStatement:
|
||||
let forInStatement = <ForInStatement | ForOfStatement>parent;
|
||||
const forInStatement = <ForInStatement | ForOfStatement>parent;
|
||||
return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
|
||||
forInStatement.expression === node;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
@@ -1654,6 +1683,18 @@ namespace ts {
|
||||
return getAssignmentTargetKind(node) !== AssignmentKind.None;
|
||||
}
|
||||
|
||||
// a node is delete target iff. it is PropertyAccessExpression/ElementAccessExpression with parentheses skipped
|
||||
export function isDeleteTarget(node: Node): boolean {
|
||||
if (node.kind !== SyntaxKind.PropertyAccessExpression && node.kind !== SyntaxKind.ElementAccessExpression) {
|
||||
return false;
|
||||
}
|
||||
node = node.parent;
|
||||
while (node && node.kind === SyntaxKind.ParenthesizedExpression) {
|
||||
node = node.parent;
|
||||
}
|
||||
return node && node.kind === SyntaxKind.DeleteExpression;
|
||||
}
|
||||
|
||||
export function isNodeDescendantOf(node: Node, ancestor: Node): boolean {
|
||||
while (node) {
|
||||
if (node === ancestor) return true;
|
||||
@@ -2158,7 +2199,6 @@ namespace ts {
|
||||
case SyntaxKind.TemplateExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.RawExpression:
|
||||
return 19;
|
||||
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
@@ -2382,13 +2422,11 @@ namespace ts {
|
||||
* Note that this doesn't actually wrap the input in double quotes.
|
||||
*/
|
||||
export function escapeString(s: string): string {
|
||||
s = escapedCharsRegExp.test(s) ? s.replace(escapedCharsRegExp, getReplacement) : s;
|
||||
return s.replace(escapedCharsRegExp, getReplacement);
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
function getReplacement(c: string) {
|
||||
return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
|
||||
}
|
||||
function getReplacement(c: string) {
|
||||
return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
|
||||
}
|
||||
|
||||
export function isIntrinsicJsxName(name: string) {
|
||||
@@ -3635,6 +3673,10 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.Identifier;
|
||||
}
|
||||
|
||||
export function isVoidExpression(node: Node): node is VoidExpression {
|
||||
return node.kind === SyntaxKind.VoidExpression;
|
||||
}
|
||||
|
||||
export function isGeneratedIdentifier(node: Node): node is GeneratedIdentifier {
|
||||
// Using `>` here catches both `GeneratedIdentifierKind.None` and `undefined`.
|
||||
return isIdentifier(node) && node.autoGenerateKind > GeneratedIdentifierKind.None;
|
||||
@@ -3902,7 +3944,7 @@ namespace ts {
|
||||
|| kind === SyntaxKind.TrueKeyword
|
||||
|| kind === SyntaxKind.SuperKeyword
|
||||
|| kind === SyntaxKind.NonNullExpression
|
||||
|| kind === SyntaxKind.RawExpression;
|
||||
|| kind === SyntaxKind.MetaProperty;
|
||||
}
|
||||
|
||||
export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression {
|
||||
@@ -3932,7 +3974,6 @@ namespace ts {
|
||||
|| kind === SyntaxKind.SpreadElement
|
||||
|| kind === SyntaxKind.AsExpression
|
||||
|| kind === SyntaxKind.OmittedExpression
|
||||
|| kind === SyntaxKind.RawExpression
|
||||
|| isUnaryExpressionKind(kind);
|
||||
}
|
||||
|
||||
|
||||
@@ -1306,7 +1306,7 @@ namespace ts {
|
||||
function aggregateTransformFlagsForSubtree(node: Node): TransformFlags {
|
||||
// We do not transform ambient declarations or types, so there is no need to
|
||||
// recursively aggregate transform flags.
|
||||
if (hasModifier(node, ModifierFlags.Ambient) || isTypeNode(node)) {
|
||||
if (hasModifier(node, ModifierFlags.Ambient) || (isTypeNode(node) && node.kind !== SyntaxKind.ExpressionWithTypeArguments)) {
|
||||
return TransformFlags.None;
|
||||
}
|
||||
|
||||
|
||||
@@ -341,6 +341,7 @@ namespace FourSlash {
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
insertSpaceAfterSemicolonInForStatements: true,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
insertSpaceAfterConstructor: false,
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
@@ -478,7 +479,7 @@ namespace FourSlash {
|
||||
endPos = endMarker.position;
|
||||
}
|
||||
|
||||
errors.forEach(function(error: ts.Diagnostic) {
|
||||
errors.forEach(function (error: ts.Diagnostic) {
|
||||
if (predicate(error.start, error.start + error.length, startPos, endPos)) {
|
||||
exists = true;
|
||||
}
|
||||
@@ -495,7 +496,7 @@ namespace FourSlash {
|
||||
Harness.IO.log("Unexpected error(s) found. Error list is:");
|
||||
}
|
||||
|
||||
errors.forEach(function(error: ts.Diagnostic) {
|
||||
errors.forEach(function (error: ts.Diagnostic) {
|
||||
Harness.IO.log(" minChar: " + error.start +
|
||||
", limChar: " + (error.start + error.length) +
|
||||
", message: " + ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine()) + "\n");
|
||||
@@ -3523,11 +3524,8 @@ namespace FourSlashInterface {
|
||||
this.state.formatOnType(this.state.getMarkerByName(posMarker).position, key);
|
||||
}
|
||||
|
||||
public setOption(name: string, value: number): void;
|
||||
public setOption(name: string, value: string): void;
|
||||
public setOption(name: string, value: boolean): void;
|
||||
public setOption(name: string, value: any): void {
|
||||
(<any>this.state.formatCodeSettings)[name] = value;
|
||||
public setOption(name: keyof ts.FormatCodeSettings, value: number | string | boolean): void {
|
||||
this.state.formatCodeSettings[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Utils {
|
||||
eval(fileContents);
|
||||
break;
|
||||
case ExecutionEnvironment.Node:
|
||||
let vm = require("vm");
|
||||
const vm = require("vm");
|
||||
if (nodeContext) {
|
||||
vm.runInNewContext(fileContents, nodeContext, fileName);
|
||||
}
|
||||
@@ -175,9 +175,9 @@ namespace Utils {
|
||||
assert.isFalse(array.end > node.end, "array.end > node.end");
|
||||
assert.isFalse(array.pos < currentPos, "array.pos < currentPos");
|
||||
|
||||
for (let i = 0, n = array.length; i < n; i++) {
|
||||
assert.isFalse(array[i].pos < currentPos, "array[i].pos < currentPos");
|
||||
currentPos = array[i].end;
|
||||
for (const item of array) {
|
||||
assert.isFalse(item.pos < currentPos, "array[i].pos < currentPos");
|
||||
currentPos = item.end;
|
||||
}
|
||||
|
||||
currentPos = array.end;
|
||||
@@ -344,7 +344,7 @@ namespace Utils {
|
||||
|
||||
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
|
||||
|
||||
for (let i = 0, n = array1.length; i < n; i++) {
|
||||
for (let i = 0; i < array1.length; i++) {
|
||||
const d1 = array1[i];
|
||||
const d2 = array2[i];
|
||||
|
||||
@@ -400,7 +400,7 @@ namespace Utils {
|
||||
assert.equal(array1.end, array2.end, "array1.end !== array2.end");
|
||||
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
|
||||
|
||||
for (let i = 0, n = array1.length; i < n; i++) {
|
||||
for (let i = 0; i < array1.length; i++) {
|
||||
assertStructuralEquals(array1[i], array2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,6 +467,36 @@ namespace ts.projectSystem {
|
||||
});
|
||||
|
||||
describe("EmitFile test", () => {
|
||||
it("should respect line endings", () => {
|
||||
test("\n");
|
||||
test("\r\n");
|
||||
|
||||
function test(newLine: string) {
|
||||
const lines = ["var x = 1;", "var y = 2;"];
|
||||
const path = "/a/app";
|
||||
const f = {
|
||||
path: path + ".ts",
|
||||
content: lines.join(newLine)
|
||||
};
|
||||
const host = createServerHost([f], { newLine });
|
||||
const session = createSession(host);
|
||||
session.executeCommand(<server.protocol.OpenRequest>{
|
||||
seq: 1,
|
||||
type: "request",
|
||||
command: "open",
|
||||
arguments: { file: f.path }
|
||||
});
|
||||
session.executeCommand(<server.protocol.CompileOnSaveEmitFileRequest>{
|
||||
seq: 2,
|
||||
type: "request",
|
||||
command: "compileOnSaveEmitFile",
|
||||
arguments: { file: f.path }
|
||||
});
|
||||
const emitOutput = host.readFile(path + ".js");
|
||||
assert.equal(emitOutput, f.content + newLine, "content of emit output should be identical with the input + newline");
|
||||
}
|
||||
})
|
||||
|
||||
it("should emit specified file", () => {
|
||||
const file1 = {
|
||||
path: "/a/b/f1.ts",
|
||||
@@ -480,7 +510,7 @@ namespace ts.projectSystem {
|
||||
path: "/a/b/tsconfig.json",
|
||||
content: `{}`
|
||||
};
|
||||
const host = createServerHost([file1, file2, configFile, libFile]);
|
||||
const host = createServerHost([file1, file2, configFile, libFile], { newLine: "\r\n" });
|
||||
const typingsInstaller = createTestTypingsInstaller(host);
|
||||
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ts {
|
||||
const diagnostics2 = file2.parseDiagnostics;
|
||||
|
||||
assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length");
|
||||
for (let i = 0, n = diagnostics1.length; i < n; i++) {
|
||||
for (let i = 0; i < diagnostics1.length; i++) {
|
||||
const d1 = diagnostics1[i];
|
||||
const d2 = diagnostics2[i];
|
||||
|
||||
|
||||
@@ -13,8 +13,7 @@ describe("Colorization", function () {
|
||||
|
||||
function getEntryAtPosition(result: ts.ClassificationResult, position: number) {
|
||||
let entryPosition = 0;
|
||||
for (let i = 0, n = result.entries.length; i < n; i++) {
|
||||
const entry = result.entries[i];
|
||||
for (const entry of result.entries) {
|
||||
if (entryPosition === position) {
|
||||
return entry;
|
||||
}
|
||||
@@ -43,9 +42,7 @@ describe("Colorization", function () {
|
||||
function testLexicalClassification(text: string, initialEndOfLineState: ts.EndOfLineState, ...expectedEntries: ClassificationEntry[]): void {
|
||||
const result = classifier.getClassificationsForLine(text, initialEndOfLineState, /*syntacticClassifierAbsent*/ false);
|
||||
|
||||
for (let i = 0, n = expectedEntries.length; i < n; i++) {
|
||||
const expectedEntry = expectedEntries[i];
|
||||
|
||||
for (const expectedEntry of expectedEntries) {
|
||||
if (expectedEntry.classification === undefined) {
|
||||
assert.equal(result.finalLexState, expectedEntry.value, "final endOfLineState does not match expected.");
|
||||
}
|
||||
@@ -352,9 +349,9 @@ describe("Colorization", function () {
|
||||
// Adjusts 'pos' by accounting for the length of each portion of the string,
|
||||
// but only return the last given string
|
||||
function track(...vals: string[]): string {
|
||||
for (let i = 0, n = vals.length; i < n; i++) {
|
||||
for (const val of vals) {
|
||||
pos += lastLength;
|
||||
lastLength = vals[i].length;
|
||||
lastLength = val.length;
|
||||
}
|
||||
return ts.lastOrUndefined(vals);
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ describe("PatternMatcher", function () {
|
||||
function assertArrayEquals<T>(array1: T[], array2: T[]) {
|
||||
assert.equal(array1.length, array2.length);
|
||||
|
||||
for (let i = 0, n = array1.length; i < n; i++) {
|
||||
for (let i = 0; i < array1.length; i++) {
|
||||
assert.equal(array1[i], array2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ namespace ts.projectSystem {
|
||||
useCaseSensitiveFileNames?: boolean;
|
||||
executingFilePath?: string;
|
||||
currentDirectory?: string;
|
||||
newLine?: string;
|
||||
}
|
||||
|
||||
export function createServerHost(fileOrFolderList: FileOrFolder[], params?: TestServerHostCreationParameters): TestServerHost {
|
||||
@@ -151,7 +152,8 @@ namespace ts.projectSystem {
|
||||
params.useCaseSensitiveFileNames !== undefined ? params.useCaseSensitiveFileNames : false,
|
||||
params.executingFilePath || getExecutingFilePathFromLibFile(),
|
||||
params.currentDirectory || "/",
|
||||
fileOrFolderList);
|
||||
fileOrFolderList,
|
||||
params.newLine);
|
||||
return host;
|
||||
}
|
||||
|
||||
@@ -329,7 +331,6 @@ namespace ts.projectSystem {
|
||||
|
||||
export class TestServerHost implements server.ServerHost {
|
||||
args: string[] = [];
|
||||
newLine: "\n";
|
||||
|
||||
private fs: ts.FileMap<FSEntry>;
|
||||
private getCanonicalFileName: (s: string) => string;
|
||||
@@ -342,7 +343,7 @@ namespace ts.projectSystem {
|
||||
|
||||
private filesOrFolders: FileOrFolder[];
|
||||
|
||||
constructor(public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: FileOrFolder[]) {
|
||||
constructor(public useCaseSensitiveFileNames: boolean, private executingFilePath: string, private currentDirectory: string, fileOrFolderList: FileOrFolder[], public readonly newLine = "\n") {
|
||||
this.getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
|
||||
this.toPath = s => toPath(s, currentDirectory, this.getCanonicalFileName);
|
||||
|
||||
@@ -1840,6 +1841,41 @@ namespace ts.projectSystem {
|
||||
assert.isFalse(service.externalProjects[0].languageServiceEnabled, "language service should be disabled - 2");
|
||||
});
|
||||
|
||||
it("files are properly detached when language service is disabled", () => {
|
||||
const f1 = {
|
||||
path: "/a/app.js",
|
||||
content: "var x = 1"
|
||||
};
|
||||
const f2 = {
|
||||
path: "/a/largefile.js",
|
||||
content: ""
|
||||
};
|
||||
const f3 = {
|
||||
path: "/a/lib.js",
|
||||
content: "var x = 1"
|
||||
};
|
||||
const config = {
|
||||
path: "/a/tsconfig.json",
|
||||
content: JSON.stringify({ compilerOptions: { allowJs: true } })
|
||||
};
|
||||
const host = createServerHost([f1, f2, f3, config]);
|
||||
const originalGetFileSize = host.getFileSize;
|
||||
host.getFileSize = (filePath: string) =>
|
||||
filePath === f2.path ? server.maxProgramSizeForNonTsFiles + 1 : originalGetFileSize.call(host, filePath);
|
||||
|
||||
const projectService = createProjectService(host);
|
||||
projectService.openClientFile(f1.path);
|
||||
projectService.checkNumberOfProjects({ configuredProjects: 1 });
|
||||
|
||||
projectService.closeClientFile(f1.path);
|
||||
projectService.checkNumberOfProjects({});
|
||||
|
||||
for (const f of [f2, f3]) {
|
||||
const scriptInfo = projectService.getScriptInfoForNormalizedPath(server.toNormalizedPath(f.path));
|
||||
assert.equal(scriptInfo.containingProjects.length, 0, `expect 0 containing projects for '${f.path}'`)
|
||||
}
|
||||
});
|
||||
|
||||
it("language service disabled events are triggered", () => {
|
||||
const f1 = {
|
||||
path: "/a/app.js",
|
||||
@@ -2033,58 +2069,17 @@ namespace ts.projectSystem {
|
||||
assert.deepEqual(resolutionTrace, [
|
||||
"======== Resolving module 'lib' from '/a/b/app.js'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'lib' from 'node_modules' folder.",
|
||||
"File '/a/b/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/lib.ts' does not exist.",
|
||||
"File '/a/node_modules/lib.tsx' does not exist.",
|
||||
"File '/a/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/a/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/a/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"File '/node_modules/lib.ts' does not exist.",
|
||||
"File '/node_modules/lib.tsx' does not exist.",
|
||||
"File '/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/node_modules/lib/package.json' does not exist.",
|
||||
"File '/node_modules/lib/index.ts' does not exist.",
|
||||
"File '/node_modules/lib/index.tsx' does not exist.",
|
||||
"File '/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/node_modules/@types/lib/index.d.ts' does not exist.",
|
||||
"Loading module 'lib' from 'node_modules' folder.",
|
||||
"File '/a/b/node_modules/lib.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/b/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/b/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib.js' does not exist.",
|
||||
"File '/a/node_modules/lib.jsx' does not exist.",
|
||||
"File '/a/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/node_modules/lib/index.js' does not exist.",
|
||||
"File '/a/node_modules/lib/index.jsx' does not exist.",
|
||||
"File '/node_modules/lib.js' does not exist.",
|
||||
"File '/node_modules/lib.jsx' does not exist.",
|
||||
"File '/node_modules/lib/package.json' does not exist.",
|
||||
"File '/node_modules/lib/index.js' does not exist.",
|
||||
"File '/node_modules/lib/index.jsx' does not exist.",
|
||||
"Loading module 'lib' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Loading module 'lib' from 'node_modules' folder, target file type 'JavaScript'.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"======== Module name 'lib' was not resolved. ========",
|
||||
`Auto discovery for typings is enabled in project '${proj.getProjectName()}'. Running extra resolution pass for module 'lib' using cache location '/a/cache'.`,
|
||||
"File '/a/cache/node_modules/lib.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/package.json' does not exist.",
|
||||
"File '/a/cache/node_modules/lib/index.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib.d.ts' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/package.json' does not exist.",
|
||||
"File '/a/cache/node_modules/@types/lib/index.d.ts' exist - use it as a name resolution result.",
|
||||
|
||||
@@ -307,7 +307,7 @@ and grew 1cm per day`;
|
||||
|
||||
it("Start pos from line", () => {
|
||||
for (let i = 0; i < iterationCount; i++) {
|
||||
for (let j = 0, llen = lines.length; j < llen; j++) {
|
||||
for (let j = 0; j < lines.length; j++) {
|
||||
const lineInfo = lineIndex.lineNumberToInfo(j + 1);
|
||||
const lineIndexOffset = lineInfo.offset;
|
||||
const lineMapOffset = lineMap[j];
|
||||
|
||||
@@ -135,6 +135,10 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
getNewLine() {
|
||||
return this.host.newLine;
|
||||
}
|
||||
|
||||
getProjectVersion() {
|
||||
return this.project.getProjectVersion();
|
||||
}
|
||||
|
||||
@@ -257,8 +257,9 @@ namespace ts.server {
|
||||
info.detachFromProject(this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// release all root files
|
||||
if (!this.program || !this.languageServiceEnabled) {
|
||||
// release all root files either if there is no program or language service is disabled.
|
||||
// in the latter case set of root files can be larger than the set of files in program.
|
||||
for (const root of this.rootFiles) {
|
||||
root.detachFromProject(this);
|
||||
}
|
||||
|
||||
@@ -2194,12 +2194,14 @@ namespace ts.server.protocol {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterConstructor?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace ts.server {
|
||||
if (len > 1) {
|
||||
let insertedNodes = <LineCollection[]>new Array(len - 1);
|
||||
let startNode = <LineCollection>leafNode;
|
||||
for (let i = 1, len = lines.length; i < len; i++) {
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
insertedNodes[i - 1] = new LineLeaf(lines[i]);
|
||||
}
|
||||
let pathIndex = this.startPath.length - 2;
|
||||
@@ -341,8 +341,7 @@ namespace ts.server {
|
||||
let snap = this.versions[this.currentVersionToIndex()];
|
||||
if (this.changes.length > 0) {
|
||||
let snapIndex = snap.index;
|
||||
for (let i = 0, len = this.changes.length; i < len; i++) {
|
||||
const change = this.changes[i];
|
||||
for (const change of this.changes) {
|
||||
snapIndex = snapIndex.edit(change.pos, change.deleteLen, change.insertedText);
|
||||
}
|
||||
snap = new LineIndexSnapshot(this.currentVersion + 1, this);
|
||||
@@ -366,8 +365,7 @@ namespace ts.server {
|
||||
const textChangeRanges: ts.TextChangeRange[] = [];
|
||||
for (let i = oldVersion + 1; i <= newVersion; i++) {
|
||||
const snap = this.versions[this.versionToIndex(i)];
|
||||
for (let j = 0, len = snap.changesSincePreviousVersion.length; j < len; j++) {
|
||||
const textChange = snap.changesSincePreviousVersion[j];
|
||||
for (const textChange of snap.changesSincePreviousVersion) {
|
||||
textChangeRanges[textChangeRanges.length] = textChange.getTextChangeRange();
|
||||
}
|
||||
}
|
||||
@@ -471,7 +469,7 @@ namespace ts.server {
|
||||
load(lines: string[]) {
|
||||
if (lines.length > 0) {
|
||||
const leaves: LineLeaf[] = [];
|
||||
for (let i = 0, len = lines.length; i < len; i++) {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
leaves[i] = new LineLeaf(lines[i]);
|
||||
}
|
||||
this.root = LineIndex.buildTreeFromBottom(leaves);
|
||||
@@ -643,8 +641,7 @@ namespace ts.server {
|
||||
updateCounts() {
|
||||
this.totalChars = 0;
|
||||
this.totalLines = 0;
|
||||
for (let i = 0, len = this.children.length; i < len; i++) {
|
||||
const child = this.children[i];
|
||||
for (const child of this.children) {
|
||||
this.totalChars += child.charCount();
|
||||
this.totalLines += child.lineCount();
|
||||
}
|
||||
|
||||
@@ -409,7 +409,8 @@ namespace ts.server {
|
||||
function parseLoggingEnvironmentString(logEnvStr: string): LogOptions {
|
||||
const logEnv: LogOptions = { logToFile: true };
|
||||
const args = logEnvStr.split(" ");
|
||||
for (let i = 0, len = args.length; i < (len - 1); i += 2) {
|
||||
const len = args.length - 1;
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
const option = args[i];
|
||||
const value = args[i + 1];
|
||||
if (option && value) {
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace ts.server {
|
||||
newLineCharacter: host.newLine || "\n",
|
||||
convertTabsToSpaces: true,
|
||||
indentStyle: ts.IndentStyle.Smart,
|
||||
insertSpaceAfterConstructor: false,
|
||||
insertSpaceAfterCommaDelimiter: true,
|
||||
insertSpaceAfterSemicolonInForStatements: true,
|
||||
insertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
@@ -85,8 +86,10 @@ namespace ts.server {
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
|
||||
insertSpaceBeforeFunctionParenthesis: false,
|
||||
placeOpenBraceOnNewLineForFunctions: false,
|
||||
placeOpenBraceOnNewLineForControlBlocks: false,
|
||||
};
|
||||
|
||||
@@ -560,11 +560,11 @@ namespace ts.BreakpointResolver {
|
||||
function spanInOpenBraceToken(node: Node): TextSpan {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
let enumDeclaration = <EnumDeclaration>node.parent;
|
||||
const enumDeclaration = <EnumDeclaration>node.parent;
|
||||
return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile));
|
||||
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
let classDeclaration = <ClassDeclaration>node.parent;
|
||||
const classDeclaration = <ClassDeclaration>node.parent;
|
||||
return spanInNodeIfStartsOnSameLine(findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile));
|
||||
|
||||
case SyntaxKind.CaseBlock:
|
||||
@@ -600,8 +600,8 @@ namespace ts.BreakpointResolver {
|
||||
|
||||
case SyntaxKind.CaseBlock:
|
||||
// breakpoint in last statement of the last clause
|
||||
let caseBlock = <CaseBlock>node.parent;
|
||||
let lastClause = lastOrUndefined(caseBlock.clauses);
|
||||
const caseBlock = <CaseBlock>node.parent;
|
||||
const lastClause = lastOrUndefined(caseBlock.clauses);
|
||||
if (lastClause) {
|
||||
return spanInNode(lastOrUndefined(lastClause.statements));
|
||||
}
|
||||
@@ -609,7 +609,7 @@ namespace ts.BreakpointResolver {
|
||||
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
// Breakpoint in last binding element or binding pattern if it contains no elements
|
||||
let bindingPattern = <BindingPattern>node.parent;
|
||||
const bindingPattern = <BindingPattern>node.parent;
|
||||
return spanInNode(lastOrUndefined(bindingPattern.elements) || bindingPattern);
|
||||
|
||||
// Default to parent node
|
||||
@@ -627,7 +627,7 @@ namespace ts.BreakpointResolver {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
// Breakpoint in last binding element or binding pattern if it contains no elements
|
||||
let bindingPattern = <BindingPattern>node.parent;
|
||||
const bindingPattern = <BindingPattern>node.parent;
|
||||
return textSpan(lastOrUndefined(bindingPattern.elements) || bindingPattern);
|
||||
|
||||
default:
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace ts {
|
||||
const dense = classifications.spans;
|
||||
let lastEnd = 0;
|
||||
|
||||
for (let i = 0, n = dense.length; i < n; i += 3) {
|
||||
for (let i = 0; i < dense.length; i += 3) {
|
||||
const start = dense[i];
|
||||
const length = dense[i + 1];
|
||||
const type = <ClassificationType>dense[i + 2];
|
||||
@@ -605,7 +605,7 @@ namespace ts {
|
||||
Debug.assert(classifications.spans.length % 3 === 0);
|
||||
const dense = classifications.spans;
|
||||
const result: ClassifiedSpan[] = [];
|
||||
for (let i = 0, n = dense.length; i < n; i += 3) {
|
||||
for (let i = 0; i < dense.length; i += 3) {
|
||||
result.push({
|
||||
textSpan: createTextSpan(dense[i], dense[i + 1]),
|
||||
classificationType: getClassificationTypeName(dense[i + 2])
|
||||
@@ -972,9 +972,7 @@ namespace ts {
|
||||
if (decodedTextSpanIntersectsWith(spanStart, spanLength, element.pos, element.getFullWidth())) {
|
||||
checkForClassificationCancellation(cancellationToken, element.kind);
|
||||
|
||||
const children = element.getChildren(sourceFile);
|
||||
for (let i = 0, n = children.length; i < n; i++) {
|
||||
const child = children[i];
|
||||
for (const child of element.getChildren(sourceFile)) {
|
||||
if (!tryClassifyNode(child)) {
|
||||
// Recurse into our child nodes.
|
||||
processElement(child);
|
||||
|
||||
@@ -112,7 +112,10 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
registerCodeFix({
|
||||
errorCodes: [Diagnostics.Cannot_find_name_0.code],
|
||||
errorCodes: [
|
||||
Diagnostics.Cannot_find_name_0.code,
|
||||
Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
|
||||
],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const checker = context.program.getTypeChecker();
|
||||
@@ -127,6 +130,12 @@ namespace ts.codefix {
|
||||
const cachedImportDeclarations = createMap<(ImportDeclaration | ImportEqualsDeclaration)[]>();
|
||||
let cachedNewImportInsertPosition: number;
|
||||
|
||||
const currentTokenMeaning = getMeaningFromLocation(token);
|
||||
if (context.errorCode === Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) {
|
||||
const symbol = checker.getAliasedSymbol(checker.getSymbolAtLocation(token));
|
||||
return getCodeActionForImport(symbol, /*isDefault*/ false, /*isNamespaceImport*/ true);
|
||||
}
|
||||
|
||||
const allPotentialModules = checker.getAmbientModules();
|
||||
for (const otherSourceFile of allSourceFiles) {
|
||||
if (otherSourceFile !== sourceFile && isExternalOrCommonJsModule(otherSourceFile)) {
|
||||
@@ -134,7 +143,6 @@ namespace ts.codefix {
|
||||
}
|
||||
}
|
||||
|
||||
const currentTokenMeaning = getMeaningFromLocation(token);
|
||||
for (const moduleSymbol of allPotentialModules) {
|
||||
context.cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
@@ -203,7 +211,7 @@ namespace ts.codefix {
|
||||
return declarations ? some(symbol.declarations, decl => !!(getMeaningFromDeclaration(decl) & meaning)) : false;
|
||||
}
|
||||
|
||||
function getCodeActionForImport(moduleSymbol: Symbol, isDefault?: boolean): ImportCodeAction[] {
|
||||
function getCodeActionForImport(moduleSymbol: Symbol, isDefault?: boolean, isNamespaceImport?: boolean): ImportCodeAction[] {
|
||||
const existingDeclarations = getImportDeclarations(moduleSymbol);
|
||||
if (existingDeclarations.length > 0) {
|
||||
// With an existing import statement, there are more than one actions the user can do.
|
||||
@@ -213,8 +221,6 @@ namespace ts.codefix {
|
||||
return [getCodeActionForNewImport()];
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getCodeActionsForExistingImport(declarations: (ImportDeclaration | ImportEqualsDeclaration)[]): ImportCodeAction[] {
|
||||
const actions: ImportCodeAction[] = [];
|
||||
|
||||
@@ -262,7 +268,7 @@ namespace ts.codefix {
|
||||
actions.push(getCodeActionForNamespaceImport(namespaceImportDeclaration));
|
||||
}
|
||||
|
||||
if (namedImportDeclaration && namedImportDeclaration.importClause &&
|
||||
if (!isNamespaceImport && namedImportDeclaration && namedImportDeclaration.importClause &&
|
||||
(namedImportDeclaration.importClause.name || namedImportDeclaration.importClause.namedBindings)) {
|
||||
/**
|
||||
* If the existing import declaration already has a named import list, just
|
||||
@@ -386,7 +392,9 @@ namespace ts.codefix {
|
||||
const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier || getModuleSpecifierForNewImport());
|
||||
const importStatementText = isDefault
|
||||
? `import ${name} from "${moduleSpecifierWithoutQuotes}"`
|
||||
: `import { ${name} } from "${moduleSpecifierWithoutQuotes}"`;
|
||||
: isNamespaceImport
|
||||
? `import * as ${name} from "${moduleSpecifierWithoutQuotes}"`
|
||||
: `import { ${name} } from "${moduleSpecifierWithoutQuotes}"`;
|
||||
|
||||
// if this file doesn't have any import statements, insert an import statement and then insert a new line
|
||||
// between the only import statement and user code. Otherwise just insert the statement because chances
|
||||
|
||||
@@ -488,18 +488,32 @@ namespace ts.formatting {
|
||||
// open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
case SyntaxKind.CloseBraceToken:
|
||||
case SyntaxKind.OpenBracketToken:
|
||||
case SyntaxKind.CloseBracketToken:
|
||||
case SyntaxKind.OpenParenToken:
|
||||
case SyntaxKind.CloseParenToken:
|
||||
case SyntaxKind.ElseKeyword:
|
||||
case SyntaxKind.WhileKeyword:
|
||||
case SyntaxKind.AtToken:
|
||||
return indentation;
|
||||
default:
|
||||
// if token line equals to the line of containing node (this is a first token in the node) - use node indentation
|
||||
return nodeStartLine !== line ? indentation + getEffectiveDelta(delta, container) : indentation;
|
||||
case SyntaxKind.SlashToken:
|
||||
case SyntaxKind.GreaterThanToken: {
|
||||
if (container.kind === SyntaxKind.JsxOpeningElement ||
|
||||
container.kind === SyntaxKind.JsxClosingElement ||
|
||||
container.kind === SyntaxKind.JsxSelfClosingElement
|
||||
) {
|
||||
return indentation;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.OpenBracketToken:
|
||||
case SyntaxKind.CloseBracketToken: {
|
||||
if (container.kind !== SyntaxKind.MappedType) {
|
||||
return indentation;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if token line equals to the line of containing node (this is a first token in the node) - use node indentation
|
||||
return nodeStartLine !== line ? indentation + getEffectiveDelta(delta, container) : indentation;
|
||||
},
|
||||
getIndentation: () => indentation,
|
||||
getDelta: child => getEffectiveDelta(delta, child),
|
||||
@@ -566,7 +580,7 @@ namespace ts.formatting {
|
||||
if (tokenInfo.token.end > node.end) {
|
||||
break;
|
||||
}
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, node, nodeDynamicIndentation, node);
|
||||
}
|
||||
|
||||
function processChildNode(
|
||||
@@ -617,7 +631,7 @@ namespace ts.formatting {
|
||||
break;
|
||||
}
|
||||
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, node);
|
||||
}
|
||||
|
||||
if (!formattingScanner.isOnToken()) {
|
||||
@@ -673,11 +687,11 @@ namespace ts.formatting {
|
||||
computeIndentation(tokenInfo.token, startLine, Constants.Unknown, parent, parentDynamicIndentation, parentStartLine);
|
||||
|
||||
listDynamicIndentation = getDynamicIndentation(parent, parentStartLine, indentation.indentation, indentation.delta);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
|
||||
}
|
||||
else {
|
||||
// consume any tokens that precede the list as child elements of 'node' using its indentation scope
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, parent, parentDynamicIndentation);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, parent, parentDynamicIndentation, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -697,13 +711,13 @@ namespace ts.formatting {
|
||||
// without this check close paren will be interpreted as list end token for function expression which is wrong
|
||||
if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
|
||||
// consume list end token
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation);
|
||||
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function consumeTokenAndAdvanceScanner(currentTokenInfo: TokenInfo, parent: Node, dynamicIndentation: DynamicIndentation, container?: Node): void {
|
||||
function consumeTokenAndAdvanceScanner(currentTokenInfo: TokenInfo, parent: Node, dynamicIndentation: DynamicIndentation, container: Node): void {
|
||||
Debug.assert(rangeContainsRange(parent, currentTokenInfo.token));
|
||||
|
||||
const lastTriviaWasNewLine = formattingScanner.lastTrailingTriviaWasNewLine();
|
||||
@@ -950,7 +964,7 @@ namespace ts.formatting {
|
||||
|
||||
// shift all parts on the delta size
|
||||
const delta = indentation - nonWhitespaceColumnInFirstPart.column;
|
||||
for (let i = startIndex, len = parts.length; i < len; i++ , startLine++) {
|
||||
for (let i = startIndex; i < parts.length; i++ , startLine++) {
|
||||
const startLinePos = getStartPositionOfLine(startLine, sourceFile);
|
||||
const nonWhitespaceCharacterAndColumn =
|
||||
i === 0
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace ts.formatting {
|
||||
public SpaceAfterLetConstInVariableDeclaration: Rule;
|
||||
public NoSpaceBeforeOpenParenInFuncCall: Rule;
|
||||
public SpaceAfterFunctionInFuncDecl: Rule;
|
||||
public SpaceBeforeOpenParenInFuncDecl: Rule;
|
||||
public NoSpaceBeforeOpenParenInFuncDecl: Rule;
|
||||
public SpaceAfterVoidOperator: Rule;
|
||||
|
||||
@@ -112,6 +113,7 @@ namespace ts.formatting {
|
||||
// TypeScript-specific rules
|
||||
|
||||
// Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses
|
||||
public SpaceAfterConstructor: Rule;
|
||||
public NoSpaceAfterConstructor: Rule;
|
||||
|
||||
// Use of module as a function call. e.g.: import m2 = module("m2");
|
||||
@@ -243,6 +245,9 @@ namespace ts.formatting {
|
||||
public NoSpaceAfterTypeAssertion: Rule;
|
||||
public SpaceAfterTypeAssertion: Rule;
|
||||
|
||||
// No space before non-null assertion operator
|
||||
public NoSpaceBeforeNonNullAssertionOperator: Rule;
|
||||
|
||||
constructor() {
|
||||
///
|
||||
/// Common Rules
|
||||
@@ -262,12 +267,12 @@ namespace ts.formatting {
|
||||
this.SpaceAfterSemicolon = new Rule(RuleDescriptor.create3(SyntaxKind.SemicolonToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
|
||||
// Space after }.
|
||||
this.SpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsAfterCodeBlockContext), RuleAction.Space));
|
||||
this.SpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.FromRange(SyntaxKind.FirstToken, SyntaxKind.LastToken, [SyntaxKind.CloseParenToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsAfterCodeBlockContext), RuleAction.Space));
|
||||
|
||||
// Special case for (}, else) and (}, while) since else & while tokens are not part of the tree which makes SpaceAfterCloseBrace rule not applied
|
||||
this.SpaceBetweenCloseBraceAndElse = new Rule(RuleDescriptor.create1(SyntaxKind.CloseBraceToken, SyntaxKind.ElseKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.SpaceBetweenCloseBraceAndWhile = new Rule(RuleDescriptor.create1(SyntaxKind.CloseBraceToken, SyntaxKind.WhileKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken, SyntaxKind.CommaToken, SyntaxKind.SemicolonToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseBracketToken, SyntaxKind.CommaToken, SyntaxKind.SemicolonToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// No space for dot
|
||||
this.NoSpaceBeforeDot = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.DotToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
@@ -290,10 +295,10 @@ namespace ts.formatting {
|
||||
this.SpaceBeforeOpenBraceInControl = new Rule(RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), RuleAction.Space), RuleFlags.CanDeleteNewLines);
|
||||
|
||||
// Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}.
|
||||
this.SpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSingleLineBlockContext), RuleAction.Space));
|
||||
this.SpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSingleLineBlockContext), RuleAction.Space));
|
||||
this.NoSpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSingleLineBlockContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSingleLineBlockContext), RuleAction.Delete));
|
||||
this.SpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Space));
|
||||
this.SpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Space));
|
||||
this.NoSpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Delete));
|
||||
this.NoSpaceBetweenEmptyBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsObjectContext), RuleAction.Delete));
|
||||
|
||||
// Insert new line after { and before } in multi-line contexts.
|
||||
@@ -329,6 +334,7 @@ namespace ts.formatting {
|
||||
this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space));
|
||||
this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete));
|
||||
this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
|
||||
this.SpaceBeforeOpenParenInFuncDecl = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), RuleAction.Space));
|
||||
this.NoSpaceBeforeOpenParenInFuncDecl = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionDeclContext), RuleAction.Delete));
|
||||
this.SpaceAfterVoidOperator = new Rule(RuleDescriptor.create3(SyntaxKind.VoidKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsVoidOpContext), RuleAction.Space));
|
||||
|
||||
@@ -352,13 +358,14 @@ namespace ts.formatting {
|
||||
// TypeScript-specific higher priority rules
|
||||
|
||||
// Treat constructor as an identifier in a function declaration, and remove spaces between constructor and following left parentheses
|
||||
this.SpaceAfterConstructor = new Rule(RuleDescriptor.create1(SyntaxKind.ConstructorKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceAfterConstructor = new Rule(RuleDescriptor.create1(SyntaxKind.ConstructorKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// Use of module as a function call. e.g.: import m2 = module("m2");
|
||||
this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// Add a space around certain TypeScript keywords
|
||||
this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword, SyntaxKind.FromKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.AbstractKeyword, SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.ReadonlyKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword, SyntaxKind.TypeKeyword, SyntaxKind.FromKeyword, SyntaxKind.KeyOfKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.FromKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
|
||||
// Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" {
|
||||
@@ -406,6 +413,9 @@ namespace ts.formatting {
|
||||
this.NoSpaceBeforeEqualInJsxAttribute = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.EqualsToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterEqualInJsxAttribute = new Rule(RuleDescriptor.create3(SyntaxKind.EqualsToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxAttributeContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// No space before non-null assertion operator
|
||||
this.NoSpaceBeforeNonNullAssertionOperator = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.ExclamationToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonNullAssertionContext), RuleAction.Delete));
|
||||
|
||||
// These rules are higher in priority than user-configurable rules.
|
||||
this.HighPriorityCommonRules = [
|
||||
this.IgnoreBeforeComment, this.IgnoreAfterLineComment,
|
||||
@@ -437,7 +447,7 @@ namespace ts.formatting {
|
||||
this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute,
|
||||
|
||||
// TypeScript-specific rules
|
||||
this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport,
|
||||
this.NoSpaceAfterModuleImport,
|
||||
this.SpaceAfterCertainTypeScriptKeywords, this.SpaceBeforeCertainTypeScriptKeywords,
|
||||
this.SpaceAfterModuleName,
|
||||
this.SpaceBeforeArrow, this.SpaceAfterArrow,
|
||||
@@ -452,6 +462,7 @@ namespace ts.formatting {
|
||||
this.SpaceBeforeAt,
|
||||
this.NoSpaceAfterAt,
|
||||
this.SpaceAfterDecorator,
|
||||
this.NoSpaceBeforeNonNullAssertionOperator
|
||||
];
|
||||
|
||||
// These rules are lower in priority than user-configurable rules.
|
||||
@@ -462,7 +473,6 @@ namespace ts.formatting {
|
||||
this.NoSpaceBeforeOpenBracket,
|
||||
this.NoSpaceAfterCloseBracket,
|
||||
this.SpaceAfterSemicolon,
|
||||
this.NoSpaceBeforeOpenParenInFuncDecl,
|
||||
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
|
||||
];
|
||||
|
||||
@@ -575,6 +585,8 @@ namespace ts.formatting {
|
||||
return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken;
|
||||
// "in" keyword in for (let x in []) { }
|
||||
case SyntaxKind.ForInStatement:
|
||||
// "in" keyword in [P in keyof T]: T[P]
|
||||
case SyntaxKind.TypeParameter:
|
||||
return context.currentTokenSpan.kind === SyntaxKind.InKeyword || context.nextTokenSpan.kind === SyntaxKind.InKeyword;
|
||||
// Technically, "of" is not a binary operator, but format it the same way as "in"
|
||||
case SyntaxKind.ForOfStatement:
|
||||
@@ -612,6 +624,10 @@ namespace ts.formatting {
|
||||
return context.TokensAreOnSameLine() || Rules.IsBeforeMultilineBlockContext(context);
|
||||
}
|
||||
|
||||
static IsBraceWrappedContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.ObjectBindingPattern || Rules.IsSingleLineBlockContext(context);
|
||||
}
|
||||
|
||||
// This check is done before an open brace in a control construct, a function, or a typescript block declaration
|
||||
static IsBeforeMultilineBlockContext(context: FormattingContext): boolean {
|
||||
return Rules.IsBeforeBlockContext(context) && !(context.NextNodeAllOnSameLine() || context.NextNodeBlockIsOnOneLine());
|
||||
@@ -705,11 +721,18 @@ namespace ts.formatting {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.CatchClause:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.SwitchStatement:
|
||||
return true;
|
||||
case SyntaxKind.Block: {
|
||||
const blockParent = context.currentTokenParent.parent;
|
||||
if (blockParent.kind !== SyntaxKind.ArrowFunction &&
|
||||
blockParent.kind !== SyntaxKind.FunctionExpression
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -829,6 +852,7 @@ namespace ts.formatting {
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.TypeReference:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
@@ -865,5 +889,9 @@ namespace ts.formatting {
|
||||
static IsYieldOrYieldStarWithOperand(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.YieldExpression && (<YieldExpression>context.contextNode).expression !== undefined;
|
||||
}
|
||||
|
||||
static IsNonNullAssertionContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.NonNullExpression;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,13 @@ namespace ts.formatting {
|
||||
private createActiveRules(options: ts.FormatCodeSettings): Rule[] {
|
||||
let rules = this.globalRules.HighPriorityCommonRules.slice(0);
|
||||
|
||||
if (options.insertSpaceAfterConstructor) {
|
||||
rules.push(this.globalRules.SpaceAfterConstructor);
|
||||
}
|
||||
else {
|
||||
rules.push(this.globalRules.NoSpaceAfterConstructor);
|
||||
}
|
||||
|
||||
if (options.insertSpaceAfterCommaDelimiter) {
|
||||
rules.push(this.globalRules.SpaceAfterComma);
|
||||
}
|
||||
@@ -128,6 +135,13 @@ namespace ts.formatting {
|
||||
rules.push(this.globalRules.NoSpaceAfterBinaryOperator);
|
||||
}
|
||||
|
||||
if (options.insertSpaceBeforeFunctionParenthesis) {
|
||||
rules.push(this.globalRules.SpaceBeforeOpenParenInFuncDecl);
|
||||
}
|
||||
else {
|
||||
rules.push(this.globalRules.NoSpaceBeforeOpenParenInFuncDecl);
|
||||
}
|
||||
|
||||
if (options.placeOpenBraceOnNewLineForControlBlocks) {
|
||||
rules.push(this.globalRules.NewLineBeforeOpenBraceInControl);
|
||||
}
|
||||
|
||||
@@ -438,6 +438,7 @@ namespace ts.formatting {
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.TupleType:
|
||||
case SyntaxKind.CaseBlock:
|
||||
case SyntaxKind.DefaultClause:
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace ts.JsDoc {
|
||||
*/
|
||||
function forEachUnique<T, U>(array: T[], callback: (element: T, index: number) => U): U {
|
||||
if (array) {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (indexOf(array, array[i]) === i) {
|
||||
const result = callback(array[i], i);
|
||||
if (result) {
|
||||
@@ -170,7 +170,7 @@ namespace ts.JsDoc {
|
||||
const isJavaScriptFile = hasJavaScriptFileExtension(sourceFile.fileName);
|
||||
|
||||
let docParams = "";
|
||||
for (let i = 0, numParams = parameters.length; i < numParams; i++) {
|
||||
for (let i = 0; i < parameters.length; i++) {
|
||||
const currentName = parameters[i].name;
|
||||
const paramName = currentName.kind === SyntaxKind.Identifier ?
|
||||
(<Identifier>currentName).text :
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace ts.NavigationBar {
|
||||
break;
|
||||
|
||||
case SyntaxKind.ImportClause:
|
||||
let importClause = <ImportClause>node;
|
||||
const importClause = <ImportClause>node;
|
||||
// Handle default import case e.g.:
|
||||
// import d from "mod";
|
||||
if (importClause.name) {
|
||||
|
||||
@@ -516,7 +516,8 @@ namespace ts {
|
||||
|
||||
// Assumes 'value' is already lowercase.
|
||||
function indexOfIgnoringCase(string: string, value: string): number {
|
||||
for (let i = 0, n = string.length - value.length; i <= n; i++) {
|
||||
const n = string.length - value.length;
|
||||
for (let i = 0; i <= n; i++) {
|
||||
if (startsWithIgnoringCase(string, value, i)) {
|
||||
return i;
|
||||
}
|
||||
@@ -527,7 +528,7 @@ namespace ts {
|
||||
|
||||
// Assumes 'value' is already lowercase.
|
||||
function startsWithIgnoringCase(string: string, value: string, start: number): boolean {
|
||||
for (let i = 0, n = value.length; i < n; i++) {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const ch1 = toLowerCase(string.charCodeAt(i + start));
|
||||
const ch2 = value.charCodeAt(i);
|
||||
|
||||
@@ -613,7 +614,7 @@ namespace ts {
|
||||
const result: TextSpan[] = [];
|
||||
|
||||
let wordStart = 0;
|
||||
for (let i = 1, n = identifier.length; i < n; i++) {
|
||||
for (let i = 1; i < identifier.length; i++) {
|
||||
const lastIsDigit = isDigit(identifier.charCodeAt(i - 1));
|
||||
const currentIsDigit = isDigit(identifier.charCodeAt(i));
|
||||
|
||||
|
||||
@@ -1793,7 +1793,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
let descriptor: TodoCommentDescriptor = undefined;
|
||||
for (let i = 0, n = descriptors.length; i < n; i++) {
|
||||
for (let i = 0; i < descriptors.length; i++) {
|
||||
if (matchArray[i + firstDescriptorCaptureIndex]) {
|
||||
descriptor = descriptors[i];
|
||||
}
|
||||
|
||||
@@ -1239,7 +1239,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
public unregisterShim(shim: Shim): void {
|
||||
for (let i = 0, n = this._shims.length; i < n; i++) {
|
||||
for (let i = 0; i < this._shims.length; i++) {
|
||||
if (this._shims[i] === shim) {
|
||||
delete this._shims[i];
|
||||
return;
|
||||
|
||||
@@ -418,6 +418,7 @@ namespace ts {
|
||||
InsertSpaceAfterCommaDelimiter: boolean;
|
||||
InsertSpaceAfterSemicolonInForStatements: boolean;
|
||||
InsertSpaceBeforeAndAfterBinaryOperators: boolean;
|
||||
InsertSpaceAfterConstructor?: boolean;
|
||||
InsertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
||||
@@ -426,6 +427,7 @@ namespace ts {
|
||||
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean;
|
||||
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
InsertSpaceAfterTypeAssertion?: boolean;
|
||||
InsertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
PlaceOpenBraceOnNewLineForFunctions: boolean;
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
|
||||
}
|
||||
@@ -434,6 +436,7 @@ namespace ts {
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterConstructor?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
@@ -442,6 +445,7 @@ namespace ts {
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceAfterTypeAssertion?: boolean;
|
||||
insertSpaceBeforeFunctionParenthesis?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
}
|
||||
|
||||
@@ -675,8 +675,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// find the child that contains 'position'
|
||||
for (let i = 0, n = current.getChildCount(sourceFile); i < n; i++) {
|
||||
const child = current.getChildAt(i);
|
||||
for (const child of current.getChildren()) {
|
||||
// all jsDocComment nodes were already visited
|
||||
if (isJSDocNode(child)) {
|
||||
continue;
|
||||
@@ -766,7 +765,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const children = n.getChildren();
|
||||
for (let i = 0, len = children.length; i < len; i++) {
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const child = children[i];
|
||||
// condition 'position < child.end' checks if child node end after the position
|
||||
// in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc'
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts(1,10): error TS2544: Type 'number' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator.
|
||||
tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts(1,10): error TS2546: Type 'number' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator.
|
||||
|
||||
|
||||
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of36.ts (1 errors) ====
|
||||
for (let [a = 0, b = 1] of [2, 3]) {
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2544: Type 'number' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator.
|
||||
!!! error TS2546: Type 'number' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator.
|
||||
a;
|
||||
b;
|
||||
}
|
||||
@@ -7,14 +7,15 @@ export default class {}
|
||||
export default function() {}
|
||||
|
||||
//// [a.js]
|
||||
(function (dependencies, factory) {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
var v = factory(require, exports); if (v !== undefined) module.exports = v;
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
define(dependencies, factory);
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define(["require", "exports"], factory);
|
||||
}
|
||||
})(["require", "exports"], function (require, exports) {
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
class default_1 {
|
||||
}
|
||||
@@ -22,14 +23,15 @@ export default function() {}
|
||||
exports.default = default_1;
|
||||
});
|
||||
//// [b.js]
|
||||
(function (dependencies, factory) {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
var v = factory(require, exports); if (v !== undefined) module.exports = v;
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
define(dependencies, factory);
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define(["require", "exports"], factory);
|
||||
}
|
||||
})(["require", "exports"], function (require, exports) {
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
function default_1() { }
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
//// [asyncAwaitWithCapturedBlockScopeVar.ts]
|
||||
async function fn1() {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
}
|
||||
}
|
||||
|
||||
async function fn2() {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function fn3() {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
async function fn4(): Promise<number> {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
async function fn1() {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
}
|
||||
}
|
||||
|
||||
async function fn2() {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async function fn3() {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
async function fn4(): Promise<number> {
|
||||
let ar = [];
|
||||
for (let i = 0; i < 1; i++) {
|
||||
await 1;
|
||||
ar.push(() => i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [asyncAwaitWithCapturedBlockScopeVar.js]
|
||||
@@ -57,8 +57,7 @@ function fn1() {
|
||||
i = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(i < 1))
|
||||
return [3 /*break*/, 4];
|
||||
if (!(i < 1)) return [3 /*break*/, 4];
|
||||
return [5 /*yield**/, __values(_loop_1(i))];
|
||||
case 2:
|
||||
_a.sent();
|
||||
@@ -92,8 +91,7 @@ function fn2() {
|
||||
i = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(i < 1))
|
||||
return [3 /*break*/, 4];
|
||||
if (!(i < 1)) return [3 /*break*/, 4];
|
||||
return [5 /*yield**/, __values(_loop_2(i))];
|
||||
case 2:
|
||||
state_1 = _a.sent();
|
||||
@@ -129,8 +127,7 @@ function fn3() {
|
||||
i = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(i < 1))
|
||||
return [3 /*break*/, 4];
|
||||
if (!(i < 1)) return [3 /*break*/, 4];
|
||||
return [5 /*yield**/, __values(_loop_3(i))];
|
||||
case 2:
|
||||
_a.sent();
|
||||
@@ -164,8 +161,7 @@ function fn4() {
|
||||
i = 0;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(i < 1))
|
||||
return [3 /*break*/, 4];
|
||||
if (!(i < 1)) return [3 /*break*/, 4];
|
||||
return [5 /*yield**/, __values(_loop_4(i))];
|
||||
case 2:
|
||||
state_2 = _a.sent();
|
||||
|
||||
@@ -8,7 +8,72 @@ async function fAsyncExplicit(): Promise<[number, boolean]> {
|
||||
// This is contextually typed as a tuple.
|
||||
return [1, true];
|
||||
}
|
||||
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/13128
|
||||
interface Obj {
|
||||
stringProp: string;
|
||||
anyProp: any;
|
||||
}
|
||||
|
||||
async function fIndexedTypeForStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
return obj.stringProp;
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
return Promise.resolve<Obj["stringProp"]>(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fIndexedTypeForAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
return obj.anyProp;
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
return Promise.resolve<Obj["anyProp"]>(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
return obj.stringProp;
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
return Promise.resolve<TObj["stringProp"]>(obj.stringProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
return obj.anyProp;
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
return Promise.resolve<TObj["anyProp"]>(obj.anyProp);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
return obj[key];
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
return Promise.resolve(obj[key]);
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
return Promise.resolve<TObj[K]>(obj[key]);
|
||||
}
|
||||
|
||||
//// [asyncFunctionReturnType.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
@@ -31,3 +96,78 @@ function fAsyncExplicit() {
|
||||
return [1, true];
|
||||
});
|
||||
}
|
||||
function fIndexedTypeForStringProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return obj.stringProp;
|
||||
});
|
||||
}
|
||||
function fIndexedTypeForPromiseOfStringProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
});
|
||||
}
|
||||
function fIndexedTypeForExplicitPromiseOfStringProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
});
|
||||
}
|
||||
function fIndexedTypeForAnyProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return obj.anyProp;
|
||||
});
|
||||
}
|
||||
function fIndexedTypeForPromiseOfAnyProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
});
|
||||
}
|
||||
function fIndexedTypeForExplicitPromiseOfAnyProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForStringProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return obj.stringProp;
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForPromiseOfStringProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForExplicitPromiseOfStringProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.stringProp);
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForAnyProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return obj.anyProp;
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForPromiseOfAnyProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForExplicitPromiseOfAnyProp(obj) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj.anyProp);
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForKProp(obj, key) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return obj[key];
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForPromiseOfKProp(obj, key) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj[key]);
|
||||
});
|
||||
}
|
||||
function fGenericIndexedTypeForExplicitPromiseOfKProp(obj, key) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return Promise.resolve(obj[key]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,3 +14,274 @@ async function fAsyncExplicit(): Promise<[number, boolean]> {
|
||||
return [1, true];
|
||||
}
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/13128
|
||||
interface Obj {
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
stringProp: string;
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
|
||||
anyProp: any;
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fIndexedTypeForStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
>fIndexedTypeForStringProp : Symbol(fIndexedTypeForStringProp, Decl(asyncFunctionReturnType.ts, 14, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 16, 41))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
return obj.stringProp;
|
||||
>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 16, 41))
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
>fIndexedTypeForPromiseOfStringProp : Symbol(fIndexedTypeForPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 18, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 20, 50))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
return Promise.resolve(obj.stringProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 20, 50))
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
>fIndexedTypeForExplicitPromiseOfStringProp : Symbol(fIndexedTypeForExplicitPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 22, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 24, 58))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
return Promise.resolve<Obj["stringProp"]>(obj.stringProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 24, 58))
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
}
|
||||
|
||||
async function fIndexedTypeForAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
>fIndexedTypeForAnyProp : Symbol(fIndexedTypeForAnyProp, Decl(asyncFunctionReturnType.ts, 26, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 28, 38))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
return obj.anyProp;
|
||||
>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 28, 38))
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
>fIndexedTypeForPromiseOfAnyProp : Symbol(fIndexedTypeForPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 30, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 32, 47))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
return Promise.resolve(obj.anyProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 32, 47))
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
>fIndexedTypeForExplicitPromiseOfAnyProp : Symbol(fIndexedTypeForExplicitPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 34, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 36, 55))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
|
||||
return Promise.resolve<Obj["anyProp"]>(obj.anyProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 36, 55))
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
>fGenericIndexedTypeForStringProp : Symbol(fGenericIndexedTypeForStringProp, Decl(asyncFunctionReturnType.ts, 38, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 40, 48))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 40, 66))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 40, 48))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 40, 48))
|
||||
|
||||
return obj.stringProp;
|
||||
>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 40, 66))
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
>fGenericIndexedTypeForPromiseOfStringProp : Symbol(fGenericIndexedTypeForPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 42, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 44, 57))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 44, 75))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 44, 57))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 44, 57))
|
||||
|
||||
return Promise.resolve(obj.stringProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 44, 75))
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
>fGenericIndexedTypeForExplicitPromiseOfStringProp : Symbol(fGenericIndexedTypeForExplicitPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 46, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 48, 83))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65))
|
||||
|
||||
return Promise.resolve<TObj["stringProp"]>(obj.stringProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65))
|
||||
>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 48, 83))
|
||||
>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
>fGenericIndexedTypeForAnyProp : Symbol(fGenericIndexedTypeForAnyProp, Decl(asyncFunctionReturnType.ts, 50, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 52, 45))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 52, 63))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 52, 45))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 52, 45))
|
||||
|
||||
return obj.anyProp;
|
||||
>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 52, 63))
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
>fGenericIndexedTypeForPromiseOfAnyProp : Symbol(fGenericIndexedTypeForPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 54, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 56, 54))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 56, 72))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 56, 54))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 56, 54))
|
||||
|
||||
return Promise.resolve(obj.anyProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 56, 72))
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
>fGenericIndexedTypeForExplicitPromiseOfAnyProp : Symbol(fGenericIndexedTypeForExplicitPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 58, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 60, 80))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62))
|
||||
|
||||
return Promise.resolve<TObj["anyProp"]>(obj.anyProp);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62))
|
||||
>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 60, 80))
|
||||
>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
>fGenericIndexedTypeForKProp : Symbol(fGenericIndexedTypeForKProp, Decl(asyncFunctionReturnType.ts, 62, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 64, 60))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 64, 83))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43))
|
||||
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 64, 93))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 64, 60))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 64, 60))
|
||||
|
||||
return obj[key];
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 64, 83))
|
||||
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 64, 93))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
>fGenericIndexedTypeForPromiseOfKProp : Symbol(fGenericIndexedTypeForPromiseOfKProp, Decl(asyncFunctionReturnType.ts, 66, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 68, 69))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 68, 92))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52))
|
||||
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 68, 102))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 68, 69))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 68, 69))
|
||||
|
||||
return Promise.resolve(obj[key]);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 68, 92))
|
||||
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 68, 102))
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
>fGenericIndexedTypeForExplicitPromiseOfKProp : Symbol(fGenericIndexedTypeForExplicitPromiseOfKProp, Decl(asyncFunctionReturnType.ts, 70, 1))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60))
|
||||
>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 72, 100))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60))
|
||||
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77))
|
||||
|
||||
return Promise.resolve<TObj[K]>(obj[key]);
|
||||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
|
||||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
|
||||
>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60))
|
||||
>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77))
|
||||
>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 72, 100))
|
||||
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110))
|
||||
}
|
||||
|
||||
@@ -20,3 +20,287 @@ async function fAsyncExplicit(): Promise<[number, boolean]> {
|
||||
>true : true
|
||||
}
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/13128
|
||||
interface Obj {
|
||||
>Obj : Obj
|
||||
|
||||
stringProp: string;
|
||||
>stringProp : string
|
||||
|
||||
anyProp: any;
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fIndexedTypeForStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
>fIndexedTypeForStringProp : (obj: Obj) => Promise<string>
|
||||
>obj : Obj
|
||||
>Obj : Obj
|
||||
>Promise : Promise<T>
|
||||
>Obj : Obj
|
||||
|
||||
return obj.stringProp;
|
||||
>obj.stringProp : string
|
||||
>obj : Obj
|
||||
>stringProp : string
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
>fIndexedTypeForPromiseOfStringProp : (obj: Obj) => Promise<string>
|
||||
>obj : Obj
|
||||
>Obj : Obj
|
||||
>Promise : Promise<T>
|
||||
>Obj : Obj
|
||||
|
||||
return Promise.resolve(obj.stringProp);
|
||||
>Promise.resolve(obj.stringProp) : Promise<string>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>obj.stringProp : string
|
||||
>obj : Obj
|
||||
>stringProp : string
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise<Obj["stringProp"]> {
|
||||
>fIndexedTypeForExplicitPromiseOfStringProp : (obj: Obj) => Promise<string>
|
||||
>obj : Obj
|
||||
>Obj : Obj
|
||||
>Promise : Promise<T>
|
||||
>Obj : Obj
|
||||
|
||||
return Promise.resolve<Obj["stringProp"]>(obj.stringProp);
|
||||
>Promise.resolve<Obj["stringProp"]>(obj.stringProp) : Promise<string>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Obj : Obj
|
||||
>obj.stringProp : string
|
||||
>obj : Obj
|
||||
>stringProp : string
|
||||
}
|
||||
|
||||
async function fIndexedTypeForAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
>fIndexedTypeForAnyProp : (obj: Obj) => Promise<any>
|
||||
>obj : Obj
|
||||
>Obj : Obj
|
||||
>Promise : Promise<T>
|
||||
>Obj : Obj
|
||||
|
||||
return obj.anyProp;
|
||||
>obj.anyProp : any
|
||||
>obj : Obj
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
>fIndexedTypeForPromiseOfAnyProp : (obj: Obj) => Promise<any>
|
||||
>obj : Obj
|
||||
>Obj : Obj
|
||||
>Promise : Promise<T>
|
||||
>Obj : Obj
|
||||
|
||||
return Promise.resolve(obj.anyProp);
|
||||
>Promise.resolve(obj.anyProp) : Promise<any>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>obj.anyProp : any
|
||||
>obj : Obj
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise<Obj["anyProp"]> {
|
||||
>fIndexedTypeForExplicitPromiseOfAnyProp : (obj: Obj) => Promise<any>
|
||||
>obj : Obj
|
||||
>Obj : Obj
|
||||
>Promise : Promise<T>
|
||||
>Obj : Obj
|
||||
|
||||
return Promise.resolve<Obj["anyProp"]>(obj.anyProp);
|
||||
>Promise.resolve<Obj["anyProp"]>(obj.anyProp) : Promise<any>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Obj : Obj
|
||||
>obj.anyProp : any
|
||||
>obj : Obj
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
>fGenericIndexedTypeForStringProp : <TObj extends Obj>(obj: TObj) => Promise<TObj["stringProp"]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
|
||||
return obj.stringProp;
|
||||
>obj.stringProp : string
|
||||
>obj : TObj
|
||||
>stringProp : string
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
>fGenericIndexedTypeForPromiseOfStringProp : <TObj extends Obj>(obj: TObj) => Promise<TObj["stringProp"]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
|
||||
return Promise.resolve(obj.stringProp);
|
||||
>Promise.resolve(obj.stringProp) : Promise<string>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>obj.stringProp : string
|
||||
>obj : TObj
|
||||
>stringProp : string
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfStringProp<TObj extends Obj>(obj: TObj): Promise<TObj["stringProp"]> {
|
||||
>fGenericIndexedTypeForExplicitPromiseOfStringProp : <TObj extends Obj>(obj: TObj) => Promise<TObj["stringProp"]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
|
||||
return Promise.resolve<TObj["stringProp"]>(obj.stringProp);
|
||||
>Promise.resolve<TObj["stringProp"]>(obj.stringProp) : Promise<TObj["stringProp"]>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>TObj : TObj
|
||||
>obj.stringProp : string
|
||||
>obj : TObj
|
||||
>stringProp : string
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
>fGenericIndexedTypeForAnyProp : <TObj extends Obj>(obj: TObj) => Promise<TObj["anyProp"]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
|
||||
return obj.anyProp;
|
||||
>obj.anyProp : any
|
||||
>obj : TObj
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
>fGenericIndexedTypeForPromiseOfAnyProp : <TObj extends Obj>(obj: TObj) => Promise<TObj["anyProp"]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
|
||||
return Promise.resolve(obj.anyProp);
|
||||
>Promise.resolve(obj.anyProp) : Promise<any>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>obj.anyProp : any
|
||||
>obj : TObj
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfAnyProp<TObj extends Obj>(obj: TObj): Promise<TObj["anyProp"]> {
|
||||
>fGenericIndexedTypeForExplicitPromiseOfAnyProp : <TObj extends Obj>(obj: TObj) => Promise<TObj["anyProp"]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
|
||||
return Promise.resolve<TObj["anyProp"]>(obj.anyProp);
|
||||
>Promise.resolve<TObj["anyProp"]>(obj.anyProp) : Promise<TObj["anyProp"]>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>TObj : TObj
|
||||
>obj.anyProp : any
|
||||
>obj : TObj
|
||||
>anyProp : any
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
>fGenericIndexedTypeForKProp : <TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K) => Promise<TObj[K]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>K : K
|
||||
>TObj : TObj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>key : K
|
||||
>K : K
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
>K : K
|
||||
|
||||
return obj[key];
|
||||
>obj[key] : TObj[K]
|
||||
>obj : TObj
|
||||
>key : K
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
>fGenericIndexedTypeForPromiseOfKProp : <TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K) => Promise<TObj[K]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>K : K
|
||||
>TObj : TObj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>key : K
|
||||
>K : K
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
>K : K
|
||||
|
||||
return Promise.resolve(obj[key]);
|
||||
>Promise.resolve(obj[key]) : Promise<TObj[K]>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>obj[key] : TObj[K]
|
||||
>obj : TObj
|
||||
>key : K
|
||||
}
|
||||
|
||||
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
|
||||
>fGenericIndexedTypeForExplicitPromiseOfKProp : <TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K) => Promise<TObj[K]>
|
||||
>TObj : TObj
|
||||
>Obj : Obj
|
||||
>K : K
|
||||
>TObj : TObj
|
||||
>obj : TObj
|
||||
>TObj : TObj
|
||||
>key : K
|
||||
>K : K
|
||||
>Promise : Promise<T>
|
||||
>TObj : TObj
|
||||
>K : K
|
||||
|
||||
return Promise.resolve<TObj[K]>(obj[key]);
|
||||
>Promise.resolve<TObj[K]>(obj[key]) : Promise<TObj[K]>
|
||||
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>Promise : PromiseConstructor
|
||||
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
|
||||
>TObj : TObj
|
||||
>K : K
|
||||
>obj[key] : TObj[K]
|
||||
>obj : TObj
|
||||
>key : K
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_1.ts(7,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_1.ts(11,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es2017/await_unaryExpression_es2017_1.ts (2 errors) ====
|
||||
|
||||
async function bar() {
|
||||
!await 42; // OK
|
||||
}
|
||||
|
||||
async function bar1() {
|
||||
delete await 42; // OK
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar2() {
|
||||
delete await 42; // OK
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar3() {
|
||||
void await 42;
|
||||
}
|
||||
|
||||
async function bar4() {
|
||||
+await 42;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_2.ts(3,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_2.ts(7,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es2017/await_unaryExpression_es2017_2.ts (2 errors) ====
|
||||
|
||||
async function bar1() {
|
||||
delete await 42;
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar2() {
|
||||
delete await 42;
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar3() {
|
||||
void await 42;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
tests/cases/conformance/async/es6/await_unaryExpression_es6_1.ts(7,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
tests/cases/conformance/async/es6/await_unaryExpression_es6_1.ts(11,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/await_unaryExpression_es6_1.ts (2 errors) ====
|
||||
|
||||
async function bar() {
|
||||
!await 42; // OK
|
||||
}
|
||||
|
||||
async function bar1() {
|
||||
delete await 42; // OK
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar2() {
|
||||
delete await 42; // OK
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar3() {
|
||||
void await 42;
|
||||
}
|
||||
|
||||
async function bar4() {
|
||||
+await 42;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
tests/cases/conformance/async/es6/await_unaryExpression_es6_2.ts(3,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
tests/cases/conformance/async/es6/await_unaryExpression_es6_2.ts(7,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
|
||||
|
||||
==== tests/cases/conformance/async/es6/await_unaryExpression_es6_2.ts (2 errors) ====
|
||||
|
||||
async function bar1() {
|
||||
delete await 42;
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar2() {
|
||||
delete await 42;
|
||||
~~~~~~~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
}
|
||||
|
||||
async function bar3() {
|
||||
void await 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [tests/cases/compiler/cacheResolutions.ts] ////
|
||||
|
||||
//// [app.ts]
|
||||
|
||||
export let x = 1;
|
||||
|
||||
//// [lib1.ts]
|
||||
export let x = 1;
|
||||
|
||||
//// [lib2.ts]
|
||||
export let x = 1;
|
||||
|
||||
//// [app.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
exports.x = 1;
|
||||
});
|
||||
//// [lib1.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
exports.x = 1;
|
||||
});
|
||||
//// [lib2.js]
|
||||
define(["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
exports.x = 1;
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/c/app.ts ===
|
||||
|
||||
export let x = 1;
|
||||
>x : Symbol(x, Decl(app.ts, 1, 10))
|
||||
|
||||
=== /a/b/c/lib1.ts ===
|
||||
export let x = 1;
|
||||
>x : Symbol(x, Decl(lib1.ts, 0, 10))
|
||||
|
||||
=== /a/b/c/lib2.ts ===
|
||||
export let x = 1;
|
||||
>x : Symbol(x, Decl(lib2.ts, 0, 10))
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
[
|
||||
"======== Resolving module 'tslib' from '/a/b/c/app.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'Classic'.",
|
||||
"File '/a/b/c/tslib.ts' does not exist.",
|
||||
"File '/a/b/c/tslib.tsx' does not exist.",
|
||||
"File '/a/b/c/tslib.d.ts' does not exist.",
|
||||
"File '/a/b/tslib.ts' does not exist.",
|
||||
"File '/a/b/tslib.tsx' does not exist.",
|
||||
"File '/a/b/tslib.d.ts' does not exist.",
|
||||
"File '/a/tslib.ts' does not exist.",
|
||||
"File '/a/tslib.tsx' does not exist.",
|
||||
"File '/a/tslib.d.ts' does not exist.",
|
||||
"File '/tslib.ts' does not exist.",
|
||||
"File '/tslib.tsx' does not exist.",
|
||||
"File '/tslib.d.ts' does not exist.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/a/b/c/tslib.js' does not exist.",
|
||||
"File '/a/b/c/tslib.jsx' does not exist.",
|
||||
"File '/a/b/tslib.js' does not exist.",
|
||||
"File '/a/b/tslib.jsx' does not exist.",
|
||||
"File '/a/tslib.js' does not exist.",
|
||||
"File '/a/tslib.jsx' does not exist.",
|
||||
"File '/tslib.js' does not exist.",
|
||||
"File '/tslib.jsx' does not exist.",
|
||||
"======== Module name 'tslib' was not resolved. ========",
|
||||
"======== Resolving module 'tslib' from '/a/b/c/lib1.ts'. ========",
|
||||
"Resolution for module 'tslib' was found in cache.",
|
||||
"======== Module name 'tslib' was not resolved. ========",
|
||||
"======== Resolving module 'tslib' from '/a/b/c/lib2.ts'. ========",
|
||||
"Resolution for module 'tslib' was found in cache.",
|
||||
"======== Module name 'tslib' was not resolved. ========"
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
=== /a/b/c/app.ts ===
|
||||
|
||||
export let x = 1;
|
||||
>x : number
|
||||
>1 : 1
|
||||
|
||||
=== /a/b/c/lib1.ts ===
|
||||
export let x = 1;
|
||||
>x : number
|
||||
>1 : 1
|
||||
|
||||
=== /a/b/c/lib2.ts ===
|
||||
export let x = 1;
|
||||
>x : number
|
||||
>1 : 1
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution1.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export declare let x: number
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/node_modules/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(app.ts, 0, 8))
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(lib.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/a/b/node_modules/foo.ts' does not exist.",
|
||||
"File '/a/b/node_modules/foo.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/foo.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========"
|
||||
]
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/node_modules/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution2.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export declare let x: number
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/node_modules/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(lib.ts, 0, 8))
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(app.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/a/b/node_modules/foo.ts' does not exist.",
|
||||
"File '/a/b/node_modules/foo.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/foo.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========"
|
||||
]
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/node_modules/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution3.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export declare let x: number
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(app.ts, 0, 8))
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(lib.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/a/b/c/d/e/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/foo.d.ts' does not exist.",
|
||||
"File '/a/b/c/foo.ts' does not exist.",
|
||||
"File '/a/b/c/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/foo.d.ts' does not exist.",
|
||||
"File '/a/b/foo.ts' does not exist.",
|
||||
"File '/a/b/foo.tsx' does not exist.",
|
||||
"File '/a/b/foo.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========"
|
||||
]
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution4.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export declare let x: number
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(lib.ts, 0, 8))
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(app.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/a/b/c/foo.ts' does not exist.",
|
||||
"File '/a/b/c/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/foo.d.ts' does not exist.",
|
||||
"File '/a/b/foo.ts' does not exist.",
|
||||
"File '/a/b/foo.tsx' does not exist.",
|
||||
"File '/a/b/foo.d.ts' exist - use it as a name resolution result.",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/a/b/c/d/e/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/foo.d.ts' does not exist.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/foo.d.ts'. ========"
|
||||
]
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution5.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export declare let x: number
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/node_modules/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 18))
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(app.ts, 0, 8))
|
||||
|
||||
=== /a/b/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : Symbol(x, Decl(lib.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/a/b/node_modules/foo.ts' does not exist.",
|
||||
"File '/a/b/node_modules/foo.tsx' does not exist.",
|
||||
"File '/a/b/node_modules/foo.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"Resolving real path for '/a/b/node_modules/foo.d.ts', result '/a/b/node_modules/foo.d.ts'",
|
||||
"======== Module name 'foo' was successfully resolved to '/a/b/node_modules/foo.d.ts'. ========"
|
||||
]
|
||||
@@ -0,0 +1,13 @@
|
||||
=== /a/b/node_modules/foo.d.ts ===
|
||||
|
||||
export declare let x: number
|
||||
>x : number
|
||||
|
||||
=== /a/b/c/d/e/app.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
=== /a/b/lib.ts ===
|
||||
import {x} from "foo";
|
||||
>x : number
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/a/b/c/d/e/app.ts(2,17): error TS2307: Cannot find module 'foo'.
|
||||
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo'.
|
||||
|
||||
|
||||
==== /a/b/c/d/e/app.ts (1 errors) ====
|
||||
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
|
||||
==== /a/b/c/lib.ts (1 errors) ====
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution6.ts] ////
|
||||
|
||||
//// [app.ts]
|
||||
|
||||
import {x} from "foo";
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,24 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'JavaScript'.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"======== Module name 'foo' was not resolved. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo'.
|
||||
/a/b/c/lib.ts(2,17): error TS2307: Cannot find module 'foo'.
|
||||
|
||||
|
||||
==== /a/b/c/lib.ts (1 errors) ====
|
||||
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
|
||||
==== /a/b/c/d/e/app.ts (1 errors) ====
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution7.ts] ////
|
||||
|
||||
//// [lib.ts]
|
||||
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,22 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'JavaScript'.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"======== Module name 'foo' was not resolved. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'NodeJs'.",
|
||||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
||||
@@ -0,0 +1,14 @@
|
||||
/a/b/c/d/e/app.ts(2,17): error TS2307: Cannot find module 'foo'.
|
||||
/a/b/c/lib.ts(1,17): error TS2307: Cannot find module 'foo'.
|
||||
|
||||
|
||||
==== /a/b/c/d/e/app.ts (1 errors) ====
|
||||
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
|
||||
==== /a/b/c/lib.ts (1 errors) ====
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution8.ts] ////
|
||||
|
||||
//// [app.ts]
|
||||
|
||||
import {x} from "foo";
|
||||
|
||||
//// [lib.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,45 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/a/b/c/d/e/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/foo.d.ts' does not exist.",
|
||||
"File '/a/b/c/foo.ts' does not exist.",
|
||||
"File '/a/b/c/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/foo.d.ts' does not exist.",
|
||||
"File '/a/b/foo.ts' does not exist.",
|
||||
"File '/a/b/foo.tsx' does not exist.",
|
||||
"File '/a/b/foo.d.ts' does not exist.",
|
||||
"File '/a/foo.ts' does not exist.",
|
||||
"File '/a/foo.tsx' does not exist.",
|
||||
"File '/a/foo.d.ts' does not exist.",
|
||||
"File '/foo.ts' does not exist.",
|
||||
"File '/foo.tsx' does not exist.",
|
||||
"File '/foo.d.ts' does not exist.",
|
||||
"Directory '/a/b/c/d/e/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/d/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/a/b/c/d/e/foo.js' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.jsx' does not exist.",
|
||||
"File '/a/b/c/d/foo.js' does not exist.",
|
||||
"File '/a/b/c/d/foo.jsx' does not exist.",
|
||||
"File '/a/b/c/foo.js' does not exist.",
|
||||
"File '/a/b/c/foo.jsx' does not exist.",
|
||||
"File '/a/b/foo.js' does not exist.",
|
||||
"File '/a/b/foo.jsx' does not exist.",
|
||||
"File '/a/foo.js' does not exist.",
|
||||
"File '/a/foo.jsx' does not exist.",
|
||||
"File '/foo.js' does not exist.",
|
||||
"File '/foo.jsx' does not exist.",
|
||||
"======== Module name 'foo' was not resolved. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
||||
@@ -0,0 +1,16 @@
|
||||
/a/b/c/d/e/app.ts(1,17): error TS2307: Cannot find module 'foo'.
|
||||
/a/b/c/lib.ts(2,17): error TS2307: Cannot find module 'foo'.
|
||||
|
||||
|
||||
==== /a/b/c/lib.ts (1 errors) ====
|
||||
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
|
||||
|
||||
==== /a/b/c/d/e/app.ts (1 errors) ====
|
||||
import {x} from "foo";
|
||||
~~~~~
|
||||
!!! error TS2307: Cannot find module 'foo'.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [tests/cases/compiler/cachedModuleResolution9.ts] ////
|
||||
|
||||
//// [lib.ts]
|
||||
|
||||
import {x} from "foo";
|
||||
|
||||
|
||||
//// [app.ts]
|
||||
import {x} from "foo";
|
||||
|
||||
|
||||
//// [lib.js]
|
||||
"use strict";
|
||||
//// [app.js]
|
||||
"use strict";
|
||||
@@ -0,0 +1,39 @@
|
||||
[
|
||||
"======== Resolving module 'foo' from '/a/b/c/lib.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/a/b/c/foo.ts' does not exist.",
|
||||
"File '/a/b/c/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/foo.d.ts' does not exist.",
|
||||
"File '/a/b/foo.ts' does not exist.",
|
||||
"File '/a/b/foo.tsx' does not exist.",
|
||||
"File '/a/b/foo.d.ts' does not exist.",
|
||||
"File '/a/foo.ts' does not exist.",
|
||||
"File '/a/foo.tsx' does not exist.",
|
||||
"File '/a/foo.d.ts' does not exist.",
|
||||
"File '/foo.ts' does not exist.",
|
||||
"File '/foo.tsx' does not exist.",
|
||||
"File '/foo.d.ts' does not exist.",
|
||||
"Directory '/a/b/c/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/b/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/a/node_modules' does not exist, skipping all lookups in it.",
|
||||
"Directory '/node_modules' does not exist, skipping all lookups in it.",
|
||||
"File '/a/b/c/foo.js' does not exist.",
|
||||
"File '/a/b/c/foo.jsx' does not exist.",
|
||||
"File '/a/b/foo.js' does not exist.",
|
||||
"File '/a/b/foo.jsx' does not exist.",
|
||||
"File '/a/foo.js' does not exist.",
|
||||
"File '/a/foo.jsx' does not exist.",
|
||||
"File '/foo.js' does not exist.",
|
||||
"File '/foo.jsx' does not exist.",
|
||||
"======== Module name 'foo' was not resolved. ========",
|
||||
"======== Resolving module 'foo' from '/a/b/c/d/e/app.ts'. ========",
|
||||
"Explicitly specified module resolution kind: 'Classic'.",
|
||||
"File '/a/b/c/d/e/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/e/foo.d.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.ts' does not exist.",
|
||||
"File '/a/b/c/d/foo.tsx' does not exist.",
|
||||
"File '/a/b/c/d/foo.d.ts' does not exist.",
|
||||
"Resolution for module 'foo' was found in cache.",
|
||||
"======== Module name 'foo' was not resolved. ========"
|
||||
]
|
||||
@@ -2,12 +2,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(4,1
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,9): error TS2378: A 'get' accessor must return a value.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,17): error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(5,17): error TS2703: The operand of a delete operator must be a property reference
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(7,16): error TS2378: A 'get' accessor must return a value.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts (7 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts (8 errors) ====
|
||||
var id;
|
||||
class C {
|
||||
[0 + 1]() { }
|
||||
@@ -21,6 +22,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES5.ts(7,1
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
~~
|
||||
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
set [[0, 1]](v) { }
|
||||
~~~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
|
||||
@@ -2,12 +2,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(4,1
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2378: A 'get' accessor must return a value.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,17): error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,17): error TS2703: The operand of a delete operator must be a property reference
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2378: A 'get' accessor must return a value.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (7 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (8 errors) ====
|
||||
var id;
|
||||
class C {
|
||||
[0 + 1]() { }
|
||||
@@ -21,6 +22,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,1
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
~~
|
||||
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
|
||||
~~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
set [[0, 1]](v) { }
|
||||
~~~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(15,12): error TS2703: The operand of a delete operator must be a property reference
|
||||
|
||||
|
||||
==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (1 errors) ====
|
||||
|
||||
function f() {
|
||||
let x: { a?: number | string, b: number | string } = { b: 1 };
|
||||
x.a;
|
||||
x.b;
|
||||
x.a = 1;
|
||||
x.b = 1;
|
||||
x.a;
|
||||
x.b;
|
||||
delete x.a;
|
||||
delete x.b;
|
||||
x.a;
|
||||
x.b;
|
||||
x;
|
||||
delete x; // No effect
|
||||
~
|
||||
!!! error TS2703: The operand of a delete operator must be a property reference
|
||||
x;
|
||||
}
|
||||
@@ -20,14 +20,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
(function (dependencies, factory) {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
var v = factory(require, exports); if (v !== undefined) module.exports = v;
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
define(dependencies, factory);
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define(["require", "exports"], factory);
|
||||
}
|
||||
})(["require", "exports"], function (require, exports) {
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
var decorator;
|
||||
let Foo = class Foo {
|
||||
@@ -45,14 +46,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
(function (dependencies, factory) {
|
||||
if (typeof module === 'object' && typeof module.exports === 'object') {
|
||||
var v = factory(require, exports); if (v !== undefined) module.exports = v;
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === 'function' && define.amd) {
|
||||
define(dependencies, factory);
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define(["require", "exports"], factory);
|
||||
}
|
||||
})(["require", "exports"], function (require, exports) {
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
var decorator;
|
||||
let default_1 = class {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user