Merge branch 'master' into resolve_entity_name
This commit is contained in:
commit
5b9bd82070
28
.travis.yml
28
.travis.yml
|
@ -7,19 +7,33 @@ node_js:
|
|||
|
||||
sudo: false
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
env:
|
||||
- workerCount=3
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
exclude:
|
||||
include:
|
||||
- os: osx
|
||||
node_js: '4'
|
||||
node_js: stable
|
||||
osx_image: xcode7.3
|
||||
env: workerCount=2
|
||||
allow_failures:
|
||||
- os: osx
|
||||
node_js: '0.10'
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- transforms
|
||||
- transforms
|
||||
|
||||
install:
|
||||
- npm uninstall typescript
|
||||
- npm uninstall tslint
|
||||
- npm install
|
||||
- npm update
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
|
||||
git:
|
||||
depth: 1
|
||||
|
|
|
@ -449,7 +449,7 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
|
|||
});
|
||||
|
||||
gulp.task("lssl", "Builds language service server library", [tsserverLibraryFile]);
|
||||
gulp.task("local", "Builds the full compiler and services", [builtLocalCompiler, servicesFile, serverFile, builtGeneratedDiagnosticMessagesJSON]);
|
||||
gulp.task("local", "Builds the full compiler and services", [builtLocalCompiler, servicesFile, serverFile, builtGeneratedDiagnosticMessagesJSON, tsserverLibraryFile]);
|
||||
gulp.task("tsc", "Builds only the compiler", [builtLocalCompiler]);
|
||||
|
||||
|
||||
|
@ -503,7 +503,7 @@ gulp.task("VerifyLKG", false, [], () => {
|
|||
return gulp.src(expectedFiles).pipe(gulp.dest(LKGDirectory));
|
||||
});
|
||||
|
||||
gulp.task("LKGInternal", false, ["lib", "local", "lssl"]);
|
||||
gulp.task("LKGInternal", false, ["lib", "local"]);
|
||||
|
||||
gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUseDebugMode"], () => {
|
||||
return runSequence("LKGInternal", "VerifyLKG");
|
||||
|
@ -956,6 +956,7 @@ const lintTargets = [
|
|||
"src/server/**/*.ts",
|
||||
"scripts/tslint/**/*.ts",
|
||||
"src/services/**/*.ts",
|
||||
"tests/*.ts", "tests/webhost/*.ts" // Note: does *not* descend recursively
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -551,7 +551,7 @@ var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibr
|
|||
compileFile(
|
||||
tsserverLibraryFile,
|
||||
languageServiceLibrarySources,
|
||||
[builtLocalDirectory, copyright].concat(languageServiceLibrarySources),
|
||||
[builtLocalDirectory, copyright, builtLocalCompiler].concat(languageServiceLibrarySources).concat(libraryTargets),
|
||||
/*prefixes*/ [copyright],
|
||||
/*useBuiltCompiler*/ true,
|
||||
{ noOutFile: false, generateDeclarations: true });
|
||||
|
@ -562,7 +562,7 @@ task("lssl", [tsserverLibraryFile, tsserverLibraryDefinitionFile]);
|
|||
|
||||
// Local target to build the compiler and services
|
||||
desc("Builds the full compiler and services");
|
||||
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile, builtGeneratedDiagnosticMessagesJSON]);
|
||||
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile, builtGeneratedDiagnosticMessagesJSON, "lssl"]);
|
||||
|
||||
// Local target to build only tsc.js
|
||||
desc("Builds only the compiler");
|
||||
|
@ -617,7 +617,7 @@ task("generate-spec", [specMd]);
|
|||
|
||||
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
|
||||
desc("Makes a new LKG out of the built js files");
|
||||
task("LKG", ["clean", "release", "local", "lssl"].concat(libraryTargets), function() {
|
||||
task("LKG", ["clean", "release", "local"].concat(libraryTargets), function() {
|
||||
var expectedFiles = [tscFile, servicesFile, serverFile, nodePackageFile, nodeDefinitionsFile, standaloneDefinitionsFile, tsserverLibraryFile, tsserverLibraryDefinitionFile].concat(libraryTargets);
|
||||
var missingFiles = expectedFiles.filter(function (f) {
|
||||
return !fs.existsSync(f);
|
||||
|
@ -1041,7 +1041,8 @@ var lintTargets = compilerSources
|
|||
.concat(serverCoreSources)
|
||||
.concat(tslintRulesFiles)
|
||||
.concat(servicesSources)
|
||||
.concat(["Gulpfile.ts"]);
|
||||
.concat(["Gulpfile.ts"])
|
||||
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath]);
|
||||
|
||||
|
||||
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"pretest": "jake tests",
|
||||
"test": "jake runtests",
|
||||
"test": "jake runtests-parallel",
|
||||
"build": "npm run build:compiler && npm run build:tests",
|
||||
"build:compiler": "jake local",
|
||||
"build:tests": "jake tests",
|
||||
|
|
|
@ -215,7 +215,7 @@ namespace ts {
|
|||
const flowLoopKeys: string[] = [];
|
||||
const flowLoopTypes: Type[][] = [];
|
||||
const visitedFlowNodes: FlowNode[] = [];
|
||||
const visitedFlowTypes: Type[] = [];
|
||||
const visitedFlowTypes: FlowType[] = [];
|
||||
const potentialThisCollisions: Node[] = [];
|
||||
const awaitedTypeStack: number[] = [];
|
||||
|
||||
|
@ -1138,6 +1138,10 @@ namespace ts {
|
|||
else {
|
||||
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
|
||||
}
|
||||
// If the export member we're looking for is default, and there is no real default but allowSyntheticDefaultImports is on, return the entire module as the default
|
||||
if (!symbolFromVariable && allowSyntheticDefaultImports && name.text === "default") {
|
||||
symbolFromVariable = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
|
||||
}
|
||||
// if symbolFromVariable is export - get its final target
|
||||
symbolFromVariable = resolveSymbol(symbolFromVariable);
|
||||
const symbolFromModule = getExportOfModule(targetSymbol, name.text);
|
||||
|
@ -4415,10 +4419,19 @@ namespace ts {
|
|||
}
|
||||
const propTypes: Type[] = [];
|
||||
const declarations: Declaration[] = [];
|
||||
let commonType: Type = undefined;
|
||||
let hasCommonType = true;
|
||||
for (const prop of props) {
|
||||
if (prop.declarations) {
|
||||
addRange(declarations, prop.declarations);
|
||||
}
|
||||
const type = getTypeOfSymbol(prop);
|
||||
if (!commonType) {
|
||||
commonType = type;
|
||||
}
|
||||
else if (type !== commonType) {
|
||||
hasCommonType = false;
|
||||
}
|
||||
propTypes.push(getTypeOfSymbol(prop));
|
||||
}
|
||||
const result = <TransientSymbol>createSymbol(
|
||||
|
@ -4428,6 +4441,7 @@ namespace ts {
|
|||
commonFlags,
|
||||
name);
|
||||
result.containingType = containingType;
|
||||
result.hasCommonType = hasCommonType;
|
||||
result.declarations = declarations;
|
||||
result.isReadonly = isReadonly;
|
||||
result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes);
|
||||
|
@ -4446,9 +4460,14 @@ namespace ts {
|
|||
return property;
|
||||
}
|
||||
|
||||
// Return the symbol for the property with the given name in the given type. Creates synthetic union properties when
|
||||
// necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from
|
||||
// Object and Function as appropriate.
|
||||
/**
|
||||
* Return the symbol for the property with the given name in the given type. Creates synthetic union properties when
|
||||
* necessary, maps primitive types and type parameters are to their apparent types, and augments with properties from
|
||||
* Object and Function as appropriate.
|
||||
*
|
||||
* @param type a type to look up property from
|
||||
* @param name a name of property to look up in a given type
|
||||
*/
|
||||
function getPropertyOfType(type: Type, name: string): Symbol {
|
||||
type = getApparentType(type);
|
||||
if (type.flags & TypeFlags.ObjectType) {
|
||||
|
@ -5908,6 +5927,13 @@ namespace ts {
|
|||
return isTypeRelatedTo(source, target, assignableRelation);
|
||||
}
|
||||
|
||||
// A type S is considered to be an instance of a type T if S and T are the same type or if S is a
|
||||
// subtype of T but not structurally identical to T. This specifically means that two distinct but
|
||||
// structurally identical types (such as two classes) are not considered instances of each other.
|
||||
function isTypeInstanceOf(source: Type, target: Type): boolean {
|
||||
return source === target || isTypeSubtypeOf(source, target) && !isTypeIdenticalTo(source, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is *not* a bi-directional relationship.
|
||||
* If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'.
|
||||
|
@ -7767,16 +7793,17 @@ namespace ts {
|
|||
}
|
||||
|
||||
function isMatchingReference(source: Node, target: Node): boolean {
|
||||
if (source.kind === target.kind) {
|
||||
switch (source.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return getResolvedSymbol(<Identifier>source) === getResolvedSymbol(<Identifier>target);
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return true;
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return (<PropertyAccessExpression>source).name.text === (<PropertyAccessExpression>target).name.text &&
|
||||
isMatchingReference((<PropertyAccessExpression>source).expression, (<PropertyAccessExpression>target).expression);
|
||||
}
|
||||
switch (source.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return target.kind === SyntaxKind.Identifier && getResolvedSymbol(<Identifier>source) === getResolvedSymbol(<Identifier>target) ||
|
||||
(target.kind === SyntaxKind.VariableDeclaration || target.kind === SyntaxKind.BindingElement) &&
|
||||
getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>source)) === getSymbolOfNode(target);
|
||||
case SyntaxKind.ThisKeyword:
|
||||
return target.kind === SyntaxKind.ThisKeyword;
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return target.kind === SyntaxKind.PropertyAccessExpression &&
|
||||
(<PropertyAccessExpression>source).name.text === (<PropertyAccessExpression>target).name.text &&
|
||||
isMatchingReference((<PropertyAccessExpression>source).expression, (<PropertyAccessExpression>target).expression);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -7791,6 +7818,44 @@ namespace ts {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Return true if target is a property access xxx.yyy, source is a property access xxx.zzz, the declared
|
||||
// type of xxx is a union type, and yyy is a property that is possibly a discriminant. We consider a property
|
||||
// a possible discriminant if its type differs in the constituents of containing union type, and if every
|
||||
// choice is a unit type or a union of unit types.
|
||||
function containsMatchingReferenceDiscriminant(source: Node, target: Node) {
|
||||
return target.kind === SyntaxKind.PropertyAccessExpression &&
|
||||
containsMatchingReference(source, (<PropertyAccessExpression>target).expression) &&
|
||||
isDiscriminantProperty(getDeclaredTypeOfReference((<PropertyAccessExpression>target).expression), (<PropertyAccessExpression>target).name.text);
|
||||
}
|
||||
|
||||
function getDeclaredTypeOfReference(expr: Node): Type {
|
||||
if (expr.kind === SyntaxKind.Identifier) {
|
||||
return getTypeOfSymbol(getResolvedSymbol(<Identifier>expr));
|
||||
}
|
||||
if (expr.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
const type = getDeclaredTypeOfReference((<PropertyAccessExpression>expr).expression);
|
||||
return type && getTypeOfPropertyOfType(type, (<PropertyAccessExpression>expr).name.text);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isDiscriminantProperty(type: Type, name: string) {
|
||||
if (type) {
|
||||
const nonNullType = getNonNullableType(type);
|
||||
if (nonNullType.flags & TypeFlags.Union) {
|
||||
const prop = getPropertyOfType(nonNullType, name);
|
||||
if (prop && prop.flags & SymbolFlags.SyntheticProperty) {
|
||||
if ((<TransientSymbol>prop).isDiscriminantProperty === undefined) {
|
||||
(<TransientSymbol>prop).isDiscriminantProperty = !(<TransientSymbol>prop).hasCommonType &&
|
||||
isUnitUnionType(getTypeOfSymbol(prop));
|
||||
}
|
||||
return (<TransientSymbol>prop).isDiscriminantProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isOrContainsMatchingReference(source: Node, target: Node) {
|
||||
return isMatchingReference(source, target) || containsMatchingReference(source, target);
|
||||
}
|
||||
|
@ -7895,7 +7960,7 @@ namespace ts {
|
|||
}
|
||||
if (flags & TypeFlags.TypeParameter) {
|
||||
const constraint = getConstraintOfTypeParameter(<TypeParameter>type);
|
||||
return constraint ? getTypeFacts(constraint) : TypeFacts.All;
|
||||
return getTypeFacts(constraint || emptyObjectType);
|
||||
}
|
||||
if (flags & TypeFlags.UnionOrIntersection) {
|
||||
return getTypeFactsOfTypes((<UnionOrIntersectionType>type).types);
|
||||
|
@ -7922,7 +7987,8 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
}
|
||||
return firstType ? types ? getUnionType(types) : firstType : neverType;
|
||||
return types ? getUnionType(types) :
|
||||
firstType ? firstType : neverType;
|
||||
}
|
||||
|
||||
function getTypeWithDefault(type: Type, defaultExpression: Expression) {
|
||||
|
@ -8034,6 +8100,12 @@ namespace ts {
|
|||
getInitialTypeOfBindingElement(<BindingElement>node);
|
||||
}
|
||||
|
||||
function getInitialOrAssignedType(node: VariableDeclaration | BindingElement | Expression) {
|
||||
return node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement ?
|
||||
getInitialType(<VariableDeclaration | BindingElement>node) :
|
||||
getAssignedType(<Expression>node);
|
||||
}
|
||||
|
||||
function getReferenceCandidate(node: Expression): Expression {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
|
@ -8072,12 +8144,43 @@ namespace ts {
|
|||
return source.flags & TypeFlags.Union ? !forEach((<UnionType>source).types, t => !contains(types, t)) : contains(types, source);
|
||||
}
|
||||
|
||||
function isTypeSubsetOf(source: Type, target: Type) {
|
||||
return source === target || target.flags & TypeFlags.Union && isTypeSubsetOfUnion(source, <UnionType>target);
|
||||
}
|
||||
|
||||
function isTypeSubsetOfUnion(source: Type, target: UnionType) {
|
||||
if (source.flags & TypeFlags.Union) {
|
||||
for (const t of (<UnionType>source).types) {
|
||||
if (!containsType(target.types, t)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (source.flags & TypeFlags.EnumLiteral && target.flags & TypeFlags.Enum && (<EnumLiteralType>source).baseType === target) {
|
||||
return true;
|
||||
}
|
||||
return containsType(target.types, source);
|
||||
}
|
||||
|
||||
function filterType(type: Type, f: (t: Type) => boolean): Type {
|
||||
return type.flags & TypeFlags.Union ?
|
||||
getUnionType(filter((<UnionType>type).types, f)) :
|
||||
f(type) ? type : neverType;
|
||||
}
|
||||
|
||||
function isIncomplete(flowType: FlowType) {
|
||||
return flowType.flags === 0;
|
||||
}
|
||||
|
||||
function getTypeFromFlowType(flowType: FlowType) {
|
||||
return flowType.flags === 0 ? (<IncompleteType>flowType).type : <Type>flowType;
|
||||
}
|
||||
|
||||
function createFlowType(type: Type, incomplete: boolean): FlowType {
|
||||
return incomplete ? { flags: 0, type } : type;
|
||||
}
|
||||
|
||||
function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, includeOuterFunctions: boolean) {
|
||||
let key: string;
|
||||
if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
|
||||
|
@ -8085,14 +8188,14 @@ namespace ts {
|
|||
}
|
||||
const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined);
|
||||
const visitedFlowStart = visitedFlowCount;
|
||||
const result = getTypeAtFlowNode(reference.flowNode);
|
||||
const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode));
|
||||
visitedFlowCount = visitedFlowStart;
|
||||
if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === neverType) {
|
||||
return declaredType;
|
||||
}
|
||||
return result;
|
||||
|
||||
function getTypeAtFlowNode(flow: FlowNode): Type {
|
||||
function getTypeAtFlowNode(flow: FlowNode): FlowType {
|
||||
while (true) {
|
||||
if (flow.flags & FlowFlags.Shared) {
|
||||
// We cache results of flow type resolution for shared nodes that were previously visited in
|
||||
|
@ -8104,7 +8207,7 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
}
|
||||
let type: Type;
|
||||
let type: FlowType;
|
||||
if (flow.flags & FlowFlags.Assignment) {
|
||||
type = getTypeAtFlowAssignment(<FlowAssignment>flow);
|
||||
if (!type) {
|
||||
|
@ -8156,19 +8259,9 @@ namespace ts {
|
|||
const node = flow.node;
|
||||
// Assignments only narrow the computed type if the declared type is a union type. Thus, we
|
||||
// only need to evaluate the assigned type if the declared type is a union type.
|
||||
if ((node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) &&
|
||||
reference.kind === SyntaxKind.Identifier &&
|
||||
getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>reference)) === getSymbolOfNode(node)) {
|
||||
return declaredType.flags & TypeFlags.Union ?
|
||||
getAssignmentReducedType(<UnionType>declaredType, getInitialType(<VariableDeclaration | BindingElement>node)) :
|
||||
declaredType;
|
||||
}
|
||||
// If the node is not a variable declaration or binding element, it is an identifier
|
||||
// or a dotted name that is the target of an assignment. If we have a match, reduce
|
||||
// the declared type by the assigned type.
|
||||
if (isMatchingReference(reference, node)) {
|
||||
return declaredType.flags & TypeFlags.Union ?
|
||||
getAssignmentReducedType(<UnionType>declaredType, getAssignedType(<Expression>node)) :
|
||||
getAssignmentReducedType(<UnionType>declaredType, getInitialOrAssignedType(node)) :
|
||||
declaredType;
|
||||
}
|
||||
// We didn't have a direct match. However, if the reference is a dotted name, this
|
||||
|
@ -8182,41 +8275,45 @@ namespace ts {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
function getTypeAtFlowCondition(flow: FlowCondition) {
|
||||
let type = getTypeAtFlowNode(flow.antecedent);
|
||||
function getTypeAtFlowCondition(flow: FlowCondition): FlowType {
|
||||
const flowType = getTypeAtFlowNode(flow.antecedent);
|
||||
let type = getTypeFromFlowType(flowType);
|
||||
if (type !== neverType) {
|
||||
// If we have an antecedent type (meaning we're reachable in some way), we first
|
||||
// attempt to narrow the antecedent type. If that produces the nothing type, then
|
||||
// we take the type guard as an indication that control could reach here in a
|
||||
// manner not understood by the control flow analyzer (e.g. a function argument
|
||||
// has an invalid type, or a nested function has possibly made an assignment to a
|
||||
// captured variable). We proceed by reverting to the declared type and then
|
||||
// attempt to narrow the antecedent type. If that produces the never type, and if
|
||||
// the antecedent type is incomplete (i.e. a transient type in a loop), then we
|
||||
// take the type guard as an indication that control *could* reach here once we
|
||||
// have the complete type. We proceed by reverting to the declared type and then
|
||||
// narrow that.
|
||||
const assumeTrue = (flow.flags & FlowFlags.TrueCondition) !== 0;
|
||||
type = narrowType(type, flow.expression, assumeTrue);
|
||||
if (type === neverType) {
|
||||
if (type === neverType && isIncomplete(flowType)) {
|
||||
type = narrowType(declaredType, flow.expression, assumeTrue);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
return createFlowType(type, isIncomplete(flowType));
|
||||
}
|
||||
|
||||
function getTypeAtSwitchClause(flow: FlowSwitchClause) {
|
||||
const type = getTypeAtFlowNode(flow.antecedent);
|
||||
function getTypeAtSwitchClause(flow: FlowSwitchClause): FlowType {
|
||||
const flowType = getTypeAtFlowNode(flow.antecedent);
|
||||
let type = getTypeFromFlowType(flowType);
|
||||
const expr = flow.switchStatement.expression;
|
||||
if (isMatchingReference(reference, expr)) {
|
||||
return narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
|
||||
type = narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
|
||||
}
|
||||
if (isMatchingPropertyAccess(expr)) {
|
||||
return narrowTypeByDiscriminant(type, <PropertyAccessExpression>expr, t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd));
|
||||
else if (isMatchingReferenceDiscriminant(expr)) {
|
||||
type = narrowTypeByDiscriminant(type, <PropertyAccessExpression>expr, t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd));
|
||||
}
|
||||
return type;
|
||||
return createFlowType(type, isIncomplete(flowType));
|
||||
}
|
||||
|
||||
function getTypeAtFlowBranchLabel(flow: FlowLabel) {
|
||||
function getTypeAtFlowBranchLabel(flow: FlowLabel): FlowType {
|
||||
const antecedentTypes: Type[] = [];
|
||||
let subtypeReduction = false;
|
||||
let seenIncomplete = false;
|
||||
for (const antecedent of flow.antecedents) {
|
||||
const type = getTypeAtFlowNode(antecedent);
|
||||
const flowType = getTypeAtFlowNode(antecedent);
|
||||
const type = getTypeFromFlowType(flowType);
|
||||
// If the type at a particular antecedent path is the declared type and the
|
||||
// reference is known to always be assigned (i.e. when declared and initial types
|
||||
// are the same), there is no reason to process more antecedents since the only
|
||||
|
@ -8227,11 +8324,20 @@ namespace ts {
|
|||
if (!contains(antecedentTypes, type)) {
|
||||
antecedentTypes.push(type);
|
||||
}
|
||||
// If an antecedent type is not a subset of the declared type, we need to perform
|
||||
// subtype reduction. This happens when a "foreign" type is injected into the control
|
||||
// flow using the instanceof operator or a user defined type predicate.
|
||||
if (!isTypeSubsetOf(type, declaredType)) {
|
||||
subtypeReduction = true;
|
||||
}
|
||||
if (isIncomplete(flowType)) {
|
||||
seenIncomplete = true;
|
||||
}
|
||||
}
|
||||
return getUnionType(antecedentTypes);
|
||||
return createFlowType(getUnionType(antecedentTypes, subtypeReduction), seenIncomplete);
|
||||
}
|
||||
|
||||
function getTypeAtFlowLoopLabel(flow: FlowLabel) {
|
||||
function getTypeAtFlowLoopLabel(flow: FlowLabel): FlowType {
|
||||
// If we have previously computed the control flow type for the reference at
|
||||
// this flow loop junction, return the cached type.
|
||||
const id = getFlowNodeId(flow);
|
||||
|
@ -8243,23 +8349,24 @@ namespace ts {
|
|||
return cache[key];
|
||||
}
|
||||
// If this flow loop junction and reference are already being processed, return
|
||||
// the union of the types computed for each branch so far. We should never see
|
||||
// an empty array here because the first antecedent of a loop junction is always
|
||||
// the non-looping control flow path that leads to the top.
|
||||
// the union of the types computed for each branch so far, marked as incomplete.
|
||||
// We should never see an empty array here because the first antecedent of a loop
|
||||
// junction is always the non-looping control flow path that leads to the top.
|
||||
for (let i = flowLoopStart; i < flowLoopCount; i++) {
|
||||
if (flowLoopNodes[i] === flow && flowLoopKeys[i] === key) {
|
||||
return getUnionType(flowLoopTypes[i]);
|
||||
return createFlowType(getUnionType(flowLoopTypes[i]), /*incomplete*/ true);
|
||||
}
|
||||
}
|
||||
// Add the flow loop junction and reference to the in-process stack and analyze
|
||||
// each antecedent code path.
|
||||
const antecedentTypes: Type[] = [];
|
||||
let subtypeReduction = false;
|
||||
flowLoopNodes[flowLoopCount] = flow;
|
||||
flowLoopKeys[flowLoopCount] = key;
|
||||
flowLoopTypes[flowLoopCount] = antecedentTypes;
|
||||
for (const antecedent of flow.antecedents) {
|
||||
flowLoopCount++;
|
||||
const type = getTypeAtFlowNode(antecedent);
|
||||
const type = getTypeFromFlowType(getTypeAtFlowNode(antecedent));
|
||||
flowLoopCount--;
|
||||
// If we see a value appear in the cache it is a sign that control flow analysis
|
||||
// was restarted and completed by checkExpressionCached. We can simply pick up
|
||||
|
@ -8270,6 +8377,12 @@ namespace ts {
|
|||
if (!contains(antecedentTypes, type)) {
|
||||
antecedentTypes.push(type);
|
||||
}
|
||||
// If an antecedent type is not a subset of the declared type, we need to perform
|
||||
// subtype reduction. This happens when a "foreign" type is injected into the control
|
||||
// flow using the instanceof operator or a user defined type predicate.
|
||||
if (!isTypeSubsetOf(type, declaredType)) {
|
||||
subtypeReduction = true;
|
||||
}
|
||||
// If the type at a particular antecedent path is the declared type there is no
|
||||
// reason to process more antecedents since the only possible outcome is subtypes
|
||||
// that will be removed in the final union type anyway.
|
||||
|
@ -8277,13 +8390,14 @@ namespace ts {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return cache[key] = getUnionType(antecedentTypes);
|
||||
return cache[key] = getUnionType(antecedentTypes, subtypeReduction);
|
||||
}
|
||||
|
||||
function isMatchingPropertyAccess(expr: Expression) {
|
||||
function isMatchingReferenceDiscriminant(expr: Expression) {
|
||||
return expr.kind === SyntaxKind.PropertyAccessExpression &&
|
||||
declaredType.flags & TypeFlags.Union &&
|
||||
isMatchingReference(reference, (<PropertyAccessExpression>expr).expression) &&
|
||||
(declaredType.flags & TypeFlags.Union) !== 0;
|
||||
isDiscriminantProperty(declaredType, (<PropertyAccessExpression>expr).name.text);
|
||||
}
|
||||
|
||||
function narrowTypeByDiscriminant(type: Type, propAccess: PropertyAccessExpression, narrowType: (t: Type) => Type): Type {
|
||||
|
@ -8297,9 +8411,12 @@ namespace ts {
|
|||
if (isMatchingReference(reference, expr)) {
|
||||
return getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy);
|
||||
}
|
||||
if (isMatchingPropertyAccess(expr)) {
|
||||
if (isMatchingReferenceDiscriminant(expr)) {
|
||||
return narrowTypeByDiscriminant(type, <PropertyAccessExpression>expr, t => getTypeWithFacts(t, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy));
|
||||
}
|
||||
if (containsMatchingReferenceDiscriminant(reference, expr)) {
|
||||
return declaredType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
|
@ -8326,12 +8443,15 @@ namespace ts {
|
|||
if (isMatchingReference(reference, right)) {
|
||||
return narrowTypeByEquality(type, operator, left, assumeTrue);
|
||||
}
|
||||
if (isMatchingPropertyAccess(left)) {
|
||||
if (isMatchingReferenceDiscriminant(left)) {
|
||||
return narrowTypeByDiscriminant(type, <PropertyAccessExpression>left, t => narrowTypeByEquality(t, operator, right, assumeTrue));
|
||||
}
|
||||
if (isMatchingPropertyAccess(right)) {
|
||||
if (isMatchingReferenceDiscriminant(right)) {
|
||||
return narrowTypeByDiscriminant(type, <PropertyAccessExpression>right, t => narrowTypeByEquality(t, operator, left, assumeTrue));
|
||||
}
|
||||
if (containsMatchingReferenceDiscriminant(reference, left) || containsMatchingReferenceDiscriminant(reference, right)) {
|
||||
return declaredType;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.InstanceOfKeyword:
|
||||
return narrowTypeByInstanceof(type, expr, assumeTrue);
|
||||
|
@ -8468,25 +8588,26 @@ namespace ts {
|
|||
|
||||
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) {
|
||||
if (!assumeTrue) {
|
||||
return type.flags & TypeFlags.Union ?
|
||||
getUnionType(filter((<UnionType>type).types, t => !isTypeSubtypeOf(t, candidate))) :
|
||||
type;
|
||||
return filterType(type, t => !isTypeInstanceOf(t, candidate));
|
||||
}
|
||||
// If the current type is a union type, remove all constituents that aren't assignable to
|
||||
// If the current type is a union type, remove all constituents that couldn't be instances of
|
||||
// the candidate type. If one or more constituents remain, return a union of those.
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
const assignableConstituents = filter((<UnionType>type).types, t => isTypeAssignableTo(t, candidate));
|
||||
const assignableConstituents = filter((<UnionType>type).types, t => isTypeInstanceOf(t, candidate));
|
||||
if (assignableConstituents.length) {
|
||||
return getUnionType(assignableConstituents);
|
||||
}
|
||||
}
|
||||
// If the candidate type is assignable to the target type, narrow to the candidate type.
|
||||
// Otherwise, if the current type is assignable to the candidate, keep the current type.
|
||||
// Otherwise, the types are completely unrelated, so narrow to the empty type.
|
||||
// If the candidate type is a subtype of the target type, narrow to the candidate type.
|
||||
// Otherwise, if the target type is assignable to the candidate type, keep the target type.
|
||||
// Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
|
||||
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
|
||||
// two types.
|
||||
const targetType = type.flags & TypeFlags.TypeParameter ? getApparentType(type) : type;
|
||||
return isTypeAssignableTo(candidate, targetType) ? candidate :
|
||||
return isTypeSubtypeOf(candidate, targetType) ? candidate :
|
||||
isTypeAssignableTo(type, candidate) ? type :
|
||||
getIntersectionType([type, candidate]);
|
||||
isTypeAssignableTo(candidate, targetType) ? candidate :
|
||||
getIntersectionType([type, candidate]);
|
||||
}
|
||||
|
||||
function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
|
||||
|
@ -10034,7 +10155,7 @@ namespace ts {
|
|||
for (const prop of props) {
|
||||
// Is there a corresponding property in the element attributes type? Skip checking of properties
|
||||
// that have already been assigned to, as these are not actually pushed into the resulting type
|
||||
if (!nameTable[prop.name]) {
|
||||
if (!hasProperty(nameTable, prop.name)) {
|
||||
const targetPropSym = getPropertyOfType(elementAttributesType, prop.name);
|
||||
if (targetPropSym) {
|
||||
const msg = chainDiagnosticMessages(undefined, Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property, prop.name);
|
||||
|
@ -10380,7 +10501,7 @@ namespace ts {
|
|||
const targetProperties = getPropertiesOfType(targetAttributesType);
|
||||
for (let i = 0; i < targetProperties.length; i++) {
|
||||
if (!(targetProperties[i].flags & SymbolFlags.Optional) &&
|
||||
nameTable[targetProperties[i].name] === undefined) {
|
||||
!hasProperty(nameTable, targetProperties[i].name)) {
|
||||
|
||||
error(node, Diagnostics.Property_0_is_missing_in_type_1, targetProperties[i].name, typeToString(targetAttributesType));
|
||||
}
|
||||
|
@ -12829,6 +12950,9 @@ namespace ts {
|
|||
return checkDestructuringAssignment(element, type, contextualMapper);
|
||||
}
|
||||
else {
|
||||
// We still need to check element expression here because we may need to set appropriate flag on the expression
|
||||
// such as NodeCheckFlags.LexicalThis on "this"expression.
|
||||
checkExpression(element);
|
||||
if (isTupleType(sourceType)) {
|
||||
error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), (<TupleType>sourceType).elementTypes.length, elements.length);
|
||||
}
|
||||
|
@ -12899,6 +13023,14 @@ namespace ts {
|
|||
return (target.flags & TypeFlags.Nullable) !== 0 || isTypeComparableTo(source, target);
|
||||
}
|
||||
|
||||
function getBestChoiceType(type1: Type, type2: Type): Type {
|
||||
const firstAssignableToSecond = isTypeAssignableTo(type1, type2);
|
||||
const secondAssignableToFirst = isTypeAssignableTo(type2, type1);
|
||||
return secondAssignableToFirst && !firstAssignableToSecond ? type1 :
|
||||
firstAssignableToSecond && !secondAssignableToFirst ? type2 :
|
||||
getUnionType([type1, type2], /*subtypeReduction*/ true);
|
||||
}
|
||||
|
||||
function checkBinaryExpression(node: BinaryExpression, contextualMapper?: TypeMapper) {
|
||||
return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, contextualMapper, node);
|
||||
}
|
||||
|
@ -13042,7 +13174,7 @@ namespace ts {
|
|||
leftType;
|
||||
case SyntaxKind.BarBarToken:
|
||||
return getTypeFacts(leftType) & TypeFacts.Falsy ?
|
||||
getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], /*subtypeReduction*/ true) :
|
||||
getBestChoiceType(removeDefinitelyFalsyTypes(leftType), rightType) :
|
||||
leftType;
|
||||
case SyntaxKind.EqualsToken:
|
||||
checkAssignmentOperator(rightType);
|
||||
|
@ -13169,7 +13301,7 @@ namespace ts {
|
|||
checkExpression(node.condition);
|
||||
const type1 = checkExpression(node.whenTrue, contextualMapper);
|
||||
const type2 = checkExpression(node.whenFalse, contextualMapper);
|
||||
return getUnionType([type1, type2], /*subtypeReduction*/ true);
|
||||
return getBestChoiceType(type1, type2);
|
||||
}
|
||||
|
||||
function typeContainsLiteralFromEnum(type: Type, enumType: EnumType) {
|
||||
|
@ -16230,6 +16362,12 @@ namespace ts {
|
|||
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node,
|
||||
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
|
||||
|
||||
if (baseType.symbol.valueDeclaration && !isInAmbientContext(baseType.symbol.valueDeclaration)) {
|
||||
if (!isBlockScopedNameDeclaredBeforeUse(baseType.symbol.valueDeclaration, node)) {
|
||||
error(baseTypeNode, Diagnostics.A_class_must_be_declared_after_its_base_class);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & SymbolFlags.Class)) {
|
||||
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
|
||||
// that all instantiated base constructor signatures return the same type. We can simply compare the type
|
||||
|
@ -19650,7 +19788,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean {
|
||||
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
|
||||
// A declare modifier is required for any top level .d.ts declaration except export=, export default, export as namespace
|
||||
// interfaces and imports categories:
|
||||
//
|
||||
// DeclarationElement:
|
||||
|
@ -19668,6 +19806,7 @@ namespace ts {
|
|||
node.kind === SyntaxKind.ImportEqualsDeclaration ||
|
||||
node.kind === SyntaxKind.ExportDeclaration ||
|
||||
node.kind === SyntaxKind.ExportAssignment ||
|
||||
node.kind === SyntaxKind.NamespaceExportDeclaration ||
|
||||
(node.flags & NodeFlags.Ambient) ||
|
||||
(node.flags & (NodeFlags.Export | NodeFlags.Default))) {
|
||||
|
||||
|
|
|
@ -334,8 +334,12 @@ namespace ts {
|
|||
return keys;
|
||||
}
|
||||
|
||||
export function getProperty<T>(map: Map<T>, key: string): T {
|
||||
return hasOwnProperty.call(map, key) ? map[key] : undefined;
|
||||
export function getProperty<T>(map: Map<T>, key: string): T | undefined {
|
||||
return hasProperty(map, key) ? map[key] : undefined;
|
||||
}
|
||||
|
||||
export function getOrUpdateProperty<T>(map: Map<T>, key: string, makeValue: () => T): T {
|
||||
return hasProperty(map, key) ? map[key] : map[key] = makeValue();
|
||||
}
|
||||
|
||||
export function isEmpty<T>(map: Map<T>) {
|
||||
|
|
|
@ -1947,6 +1947,10 @@
|
|||
"category": "Error",
|
||||
"code": 2689
|
||||
},
|
||||
"A class must be declared after its base class.": {
|
||||
"category": "Error",
|
||||
"code": 2690
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
|
|
@ -2578,7 +2578,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
operand = (<TypeAssertion | NonNullExpression>operand).expression;
|
||||
}
|
||||
|
||||
// We have an expression of the form: (<Type>SubExpr)
|
||||
// We have an expression of the form: (<Type>SubExpr) or (SubExpr as Type)
|
||||
// Emitting this as (SubExpr) is really not desirable. We would like to emit the subexpr as is.
|
||||
// Omitting the parentheses, however, could cause change in the semantics of the generated
|
||||
// code if the casted expression has a lower precedence than the rest of the expression, e.g.:
|
||||
|
@ -2592,6 +2592,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
operand.kind !== SyntaxKind.DeleteExpression &&
|
||||
operand.kind !== SyntaxKind.PostfixUnaryExpression &&
|
||||
operand.kind !== SyntaxKind.NewExpression &&
|
||||
!(operand.kind === SyntaxKind.BinaryExpression && node.expression.kind === SyntaxKind.AsExpression) &&
|
||||
!(operand.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.NewExpression) &&
|
||||
!(operand.kind === SyntaxKind.FunctionExpression && node.parent.kind === SyntaxKind.CallExpression) &&
|
||||
!(operand.kind === SyntaxKind.NumericLiteral && node.parent.kind === SyntaxKind.PropertyAccessExpression)) {
|
||||
|
@ -6841,7 +6842,7 @@ const _super = (function (geti, seti) {
|
|||
// export { x, y }
|
||||
for (const specifier of (<ExportDeclaration>node).exportClause.elements) {
|
||||
const name = (specifier.propertyName || specifier.name).text;
|
||||
(exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier);
|
||||
getOrUpdateProperty(exportSpecifiers, name, () => []).push(specifier);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1055,19 +1055,15 @@ namespace ts {
|
|||
return resolutions;
|
||||
}
|
||||
|
||||
function getInferredTypesRoot(options: CompilerOptions, rootFiles: string[], host: CompilerHost) {
|
||||
return computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), f => host.getCanonicalFileName(f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a set of options and a set of root files, returns the set of type directive names
|
||||
* Given a set of options, returns the set of type directive names
|
||||
* that should be included for this program automatically.
|
||||
* This list could either come from the config file,
|
||||
* or from enumerating the types root + initial secondary types lookup location.
|
||||
* More type directives might appear in the program later as a result of loading actual source files;
|
||||
* this list is only the set of defaults that are implicitly included.
|
||||
*/
|
||||
export function getAutomaticTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[] {
|
||||
export function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[] {
|
||||
// Use explicit type list from tsconfig.json
|
||||
if (options.types) {
|
||||
return options.types;
|
||||
|
@ -1080,7 +1076,10 @@ namespace ts {
|
|||
if (typeRoots) {
|
||||
for (const root of typeRoots) {
|
||||
if (host.directoryExists(root)) {
|
||||
result = result.concat(host.getDirectories(root));
|
||||
for (const typeDirectivePath of host.getDirectories(root)) {
|
||||
// Return just the type directive names
|
||||
result = result.concat(getBaseFileName(normalizePath(typeDirectivePath)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1155,11 +1154,11 @@ namespace ts {
|
|||
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
|
||||
|
||||
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
|
||||
const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, rootNames, host);
|
||||
const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, host);
|
||||
|
||||
if (typeReferences) {
|
||||
const inferredRoot = getInferredTypesRoot(options, rootNames, host);
|
||||
const containingFilename = combinePaths(inferredRoot, "__inferred type names__.ts");
|
||||
// This containingFilename needs to match with the one used in managed-side
|
||||
const containingFilename = combinePaths(host.getCurrentDirectory(), "__inferred type names__.ts");
|
||||
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
|
||||
for (let i = 0; i < typeReferences.length; i++) {
|
||||
processTypeReferenceDirective(typeReferences[i], resolutions[i]);
|
||||
|
|
|
@ -1612,6 +1612,16 @@ namespace ts {
|
|||
antecedent: FlowNode;
|
||||
}
|
||||
|
||||
export type FlowType = Type | IncompleteType;
|
||||
|
||||
// Incomplete types occur during control flow analysis of loops. An IncompleteType
|
||||
// is distinguished from a regular type by a flags value of zero. Incomplete type
|
||||
// objects are internal to the getFlowTypeOfRefecence function and never escape it.
|
||||
export interface IncompleteType {
|
||||
flags: TypeFlags; // No flags set
|
||||
type: Type; // The type marked incomplete
|
||||
}
|
||||
|
||||
export interface AmdDependency {
|
||||
path: string;
|
||||
name: string;
|
||||
|
@ -2156,6 +2166,8 @@ namespace ts {
|
|||
mapper?: TypeMapper; // Type mapper for instantiation alias
|
||||
referenced?: boolean; // True if alias symbol has been referenced as a value
|
||||
containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property
|
||||
hasCommonType?: boolean; // True if constituents of synthetic property all have same type
|
||||
isDiscriminantProperty?: boolean; // True if discriminant synthetic property
|
||||
resolvedExports?: SymbolTable; // Resolved exports of module
|
||||
exportsChecked?: boolean; // True if exports of external module have been checked
|
||||
isDeclarationWithCollidingName?: boolean; // True if symbol is block scoped redeclaration
|
||||
|
@ -2906,6 +2918,7 @@ namespace ts {
|
|||
directoryExists?(directoryName: string): boolean;
|
||||
realpath?(path: string): string;
|
||||
getCurrentDirectory?(): string;
|
||||
getDirectories?(path: string): string[];
|
||||
}
|
||||
|
||||
export interface ResolvedModule {
|
||||
|
|
|
@ -1569,6 +1569,7 @@ namespace ts {
|
|||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
case SyntaxKind.NamespaceExportDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
|
|
|
@ -750,7 +750,7 @@ namespace Harness {
|
|||
|
||||
export function readDirectory(path: string, extension?: string[], exclude?: string[], include?: string[]) {
|
||||
const fs = new Utils.VirtualFileSystem(path, useCaseSensitiveFileNames());
|
||||
for (const file in listFiles(path)) {
|
||||
for (const file of listFiles(path)) {
|
||||
fs.addFile(file);
|
||||
}
|
||||
return ts.matchFiles(path, extension, exclude, include, useCaseSensitiveFileNames(), getCurrentDirectory(), path => {
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace ts.server {
|
|||
describe("onMessage", () => {
|
||||
it("should not throw when commands are executed with invalid arguments", () => {
|
||||
let i = 0;
|
||||
for (name in CommandNames) {
|
||||
for (const name in CommandNames) {
|
||||
if (!Object.prototype.hasOwnProperty.call(CommandNames, name)) {
|
||||
continue;
|
||||
}
|
||||
|
|
26
src/lib/es2015.core.d.ts
vendored
26
src/lib/es2015.core.d.ts
vendored
|
@ -226,7 +226,7 @@ interface NumberConstructor {
|
|||
/**
|
||||
* The value of the largest integer n such that n and n + 1 are both exactly representable as
|
||||
* a Number value.
|
||||
* The value of Number.MIN_SAFE_INTEGER is 9007199254740991 2^53 − 1.
|
||||
* The value of Number.MAX_SAFE_INTEGER is 9007199254740991 2^53 − 1.
|
||||
*/
|
||||
readonly MAX_SAFE_INTEGER: number;
|
||||
|
||||
|
@ -343,6 +343,30 @@ interface ObjectConstructor {
|
|||
defineProperty(o: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): any;
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/**
|
||||
* Returns the value of the first element in the array where predicate is true, and undefined
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found, find
|
||||
* immediately returns that element value. Otherwise, find returns undefined.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
find(predicate: (value: T, index: number, obj: ReadonlyArray<T>) => boolean, thisArg?: any): T | undefined;
|
||||
|
||||
/**
|
||||
* Returns the index of the first element in the array where predicate is true, and undefined
|
||||
* otherwise.
|
||||
* @param predicate find calls predicate once for each element of the array, in ascending
|
||||
* order, until it finds one where predicate returns true. If such an element is found,
|
||||
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
||||
* @param thisArg If provided, it will be used as the this value for each invocation of
|
||||
* predicate. If it is not provided, undefined is used instead.
|
||||
*/
|
||||
findIndex(predicate: (value: T) => boolean, thisArg?: any): number;
|
||||
}
|
||||
|
||||
interface RegExp {
|
||||
/**
|
||||
* Returns a string indicating the flags of the regular expression in question. This field is read-only.
|
||||
|
|
20
src/lib/es2015.iterable.d.ts
vendored
20
src/lib/es2015.iterable.d.ts
vendored
|
@ -63,6 +63,26 @@ interface ArrayConstructor {
|
|||
from<T>(iterable: Iterable<T>): Array<T>;
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): IterableIterator<T>;
|
||||
|
||||
/**
|
||||
* Returns an array of key, value pairs for every entry in the array
|
||||
*/
|
||||
entries(): IterableIterator<[number, T]>;
|
||||
|
||||
/**
|
||||
* Returns an list of keys in the array
|
||||
*/
|
||||
keys(): IterableIterator<number>;
|
||||
|
||||
/**
|
||||
* Returns an list of values in the array
|
||||
*/
|
||||
values(): IterableIterator<T>;
|
||||
}
|
||||
|
||||
interface IArguments {
|
||||
/** Iterator */
|
||||
[Symbol.iterator](): IterableIterator<any>;
|
||||
|
|
5
src/lib/es5.d.ts
vendored
5
src/lib/es5.d.ts
vendored
|
@ -1108,6 +1108,11 @@ interface Array<T> {
|
|||
* Removes the last element from an array and returns it.
|
||||
*/
|
||||
pop(): T | undefined;
|
||||
/**
|
||||
* Combines two or more arrays.
|
||||
* @param items Additional items to add to the end of array1.
|
||||
*/
|
||||
concat(...items: T[][]): T[];
|
||||
/**
|
||||
* Combines two or more arrays.
|
||||
* @param items Additional items to add to the end of array1.
|
||||
|
|
|
@ -115,6 +115,9 @@ namespace ts.server {
|
|||
readFile: fileName => this.host.readFile(fileName),
|
||||
directoryExists: directoryName => this.host.directoryExists(directoryName)
|
||||
};
|
||||
if (this.host.realpath) {
|
||||
this.moduleResolutionHost.realpath = path => this.host.realpath(path);
|
||||
}
|
||||
}
|
||||
|
||||
private resolveNamesWithLocalCache<T extends Timestamped & { failedLookupLocations: string[] }, R>(
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
"types": []
|
||||
},
|
||||
"files": [
|
||||
"../services/shims.ts",
|
||||
"../services/utilities.ts",
|
||||
"editorServices.ts",
|
||||
"protocol.d.ts",
|
||||
"session.ts"
|
||||
|
|
|
@ -453,9 +453,9 @@ namespace ts.formatting {
|
|||
case SyntaxKind.MethodDeclaration:
|
||||
if ((<MethodDeclaration>node).asteriskToken) {
|
||||
return SyntaxKind.AsteriskToken;
|
||||
}
|
||||
// fall-through
|
||||
|
||||
}/*
|
||||
fall-through
|
||||
*/
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
return (<Declaration>node).name.kind;
|
||||
|
@ -732,7 +732,7 @@ namespace ts.formatting {
|
|||
else {
|
||||
// indent token only if end line of previous range does not match start line of the token
|
||||
const prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line;
|
||||
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
|
||||
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -892,7 +892,7 @@ namespace ts.formatting {
|
|||
}
|
||||
|
||||
function indentationIsDifferent(indentationString: string, startLinePosition: number): boolean {
|
||||
return indentationString !== sourceFile.text.substr(startLinePosition , indentationString.length);
|
||||
return indentationString !== sourceFile.text.substr(startLinePosition, indentationString.length);
|
||||
}
|
||||
|
||||
function indentMultilineComment(commentRange: TextRange, indentation: number, firstLineIsIndented: boolean) {
|
||||
|
@ -936,7 +936,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, len = parts.length; i < len; i++ , startLine++) {
|
||||
const startLinePos = getStartPositionOfLine(startLine, sourceFile);
|
||||
const nonWhitespaceCharacterAndColumn =
|
||||
i === 0
|
||||
|
|
|
@ -231,6 +231,13 @@ namespace ts.formatting {
|
|||
public NoSpaceBeforeCloseBraceInJsxExpression: Rule;
|
||||
public SpaceBeforeCloseBraceInJsxExpression: Rule;
|
||||
|
||||
// JSX opening elements
|
||||
public SpaceBeforeJsxAttribute: Rule;
|
||||
public SpaceBeforeSlashInJsxOpeningElement: Rule;
|
||||
public NoSpaceBeforeGreaterThanTokenInJsxOpeningElement: Rule;
|
||||
public NoSpaceBeforeEqualInJsxAttribute: Rule;
|
||||
public NoSpaceAfterEqualInJsxAttribute: Rule;
|
||||
|
||||
constructor() {
|
||||
///
|
||||
/// Common Rules
|
||||
|
@ -322,7 +329,7 @@ namespace ts.formatting {
|
|||
|
||||
// Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
|
||||
// So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
|
||||
this.SpaceBetweenStatements = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext, Rules.IsNotForContext), RuleAction.Space));
|
||||
this.SpaceBetweenStatements = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext, Rules.IsNotForContext), RuleAction.Space));
|
||||
|
||||
// This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
|
||||
this.SpaceAfterTryFinally = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword]), SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
|
@ -386,6 +393,13 @@ namespace ts.formatting {
|
|||
// template string
|
||||
this.NoSpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// jsx opening element
|
||||
this.SpaceBeforeJsxAttribute = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.Identifier), RuleOperation.create2(new RuleOperationContext(Rules.IsNextTokenParentJsxAttribute, Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.SpaceBeforeSlashInJsxOpeningElement = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.SlashToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxSelfClosingElementContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement = new Rule(RuleDescriptor.create1(SyntaxKind.SlashToken, SyntaxKind.GreaterThanToken), RuleOperation.create2(new RuleOperationContext(Rules.IsJsxSelfClosingElementContext, Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
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));
|
||||
|
||||
// These rules are higher in priority than user-configurable rules.
|
||||
this.HighPriorityCommonRules = [
|
||||
this.IgnoreBeforeComment, this.IgnoreAfterLineComment,
|
||||
|
@ -413,6 +427,8 @@ namespace ts.formatting {
|
|||
this.SpaceAfterVoidOperator,
|
||||
this.SpaceBetweenAsyncAndOpenParen, this.SpaceBetweenAsyncAndFunctionKeyword,
|
||||
this.NoSpaceBetweenTagAndTemplateString,
|
||||
this.SpaceBeforeJsxAttribute, this.SpaceBeforeSlashInJsxOpeningElement, this.NoSpaceBeforeGreaterThanTokenInJsxOpeningElement,
|
||||
this.NoSpaceBeforeEqualInJsxAttribute, this.NoSpaceAfterEqualInJsxAttribute,
|
||||
|
||||
// TypeScript-specific rules
|
||||
this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport,
|
||||
|
@ -450,8 +466,8 @@ namespace ts.formatting {
|
|||
///
|
||||
|
||||
// Insert space after comma delimiter
|
||||
this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space));
|
||||
this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isNonJsxElementContext), RuleAction.Delete));
|
||||
this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space));
|
||||
this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNonJsxElementContext), RuleAction.Delete));
|
||||
|
||||
// Insert space before and after binary operators
|
||||
this.SpaceBeforeBinaryOperator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.BinaryOperators), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), RuleAction.Space));
|
||||
|
@ -498,10 +514,10 @@ namespace ts.formatting {
|
|||
this.SpaceBeforeTemplateMiddleAndTail = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
|
||||
|
||||
// No space after { and before } in JSX expression
|
||||
this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete));
|
||||
this.SpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Space));
|
||||
this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Delete));
|
||||
this.SpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.isJsxExpressionContext), RuleAction.Space));
|
||||
this.NoSpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Delete));
|
||||
this.SpaceAfterOpenBraceInJsxExpression = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Space));
|
||||
this.NoSpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Delete));
|
||||
this.SpaceBeforeCloseBraceInJsxExpression = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsJsxExpressionContext), RuleAction.Space));
|
||||
|
||||
// Insert space after function keyword for anonymous functions
|
||||
this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
|
||||
|
@ -741,14 +757,26 @@ namespace ts.formatting {
|
|||
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
|
||||
}
|
||||
|
||||
static isNonJsxElementContext(context: FormattingContext): boolean {
|
||||
static IsNonJsxElementContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind !== SyntaxKind.JsxElement;
|
||||
}
|
||||
|
||||
static isJsxExpressionContext(context: FormattingContext): boolean {
|
||||
static IsJsxExpressionContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.JsxExpression;
|
||||
}
|
||||
|
||||
static IsNextTokenParentJsxAttribute(context: FormattingContext): boolean {
|
||||
return context.nextTokenParent.kind === SyntaxKind.JsxAttribute;
|
||||
}
|
||||
|
||||
static IsJsxAttributeContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.JsxAttribute;
|
||||
}
|
||||
|
||||
static IsJsxSelfClosingElementContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.JsxSelfClosingElement;
|
||||
}
|
||||
|
||||
static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean {
|
||||
return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context);
|
||||
}
|
||||
|
|
|
@ -506,7 +506,7 @@ namespace ts.NavigationBar {
|
|||
function convertToTopLevelItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: nodeKind(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: map(n.children, convertToChildItem) || emptyChildItemArray,
|
||||
|
@ -518,7 +518,7 @@ namespace ts.NavigationBar {
|
|||
function convertToChildItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: nodeKind(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: emptyChildItemArray,
|
||||
|
@ -539,57 +539,6 @@ namespace ts.NavigationBar {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: GH#9145: We should just use getNodeKind. No reason why navigationBar and navigateTo should have different behaviors.
|
||||
function nodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
return ScriptElementKind.moduleElement;
|
||||
|
||||
case SyntaxKind.EnumMember:
|
||||
return ScriptElementKind.memberVariableElement;
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.BindingElement:
|
||||
let variableDeclarationNode: Node;
|
||||
let name: Node;
|
||||
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
name = (<BindingElement>node).name;
|
||||
variableDeclarationNode = node;
|
||||
// binding elements are added only for variable declarations
|
||||
// bubble up to the containing variable declaration
|
||||
while (variableDeclarationNode && variableDeclarationNode.kind !== SyntaxKind.VariableDeclaration) {
|
||||
variableDeclarationNode = variableDeclarationNode.parent;
|
||||
}
|
||||
Debug.assert(!!variableDeclarationNode);
|
||||
}
|
||||
else {
|
||||
Debug.assert(!isBindingPattern((<VariableDeclaration>node).name));
|
||||
variableDeclarationNode = node;
|
||||
name = (<VariableDeclaration>node).name;
|
||||
}
|
||||
|
||||
if (isConst(variableDeclarationNode)) {
|
||||
return ts.ScriptElementKind.constElement;
|
||||
}
|
||||
else if (isLet(variableDeclarationNode)) {
|
||||
return ts.ScriptElementKind.letElement;
|
||||
}
|
||||
else {
|
||||
return ts.ScriptElementKind.variableElement;
|
||||
}
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return ts.ScriptElementKind.functionElement;
|
||||
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
|
||||
default:
|
||||
return getNodeKind(node);
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleName(moduleDeclaration: ModuleDeclaration): string {
|
||||
// We want to maintain quotation marks.
|
||||
if (isAmbientModule(moduleDeclaration)) {
|
||||
|
|
|
@ -1690,6 +1690,8 @@ namespace ts {
|
|||
|
||||
/** enum E */
|
||||
export const enumElement = "enum";
|
||||
// TODO: GH#9983
|
||||
export const enumMemberElement = "const";
|
||||
|
||||
/**
|
||||
* Inside module and script only
|
||||
|
@ -1884,7 +1886,7 @@ namespace ts {
|
|||
};
|
||||
}
|
||||
|
||||
// Cache host information about scrip Should be refreshed
|
||||
// Cache host information about script should be refreshed
|
||||
// at each language service public entry point, since we don't know when
|
||||
// set of scripts handled by the host changes.
|
||||
class HostCache {
|
||||
|
@ -2947,7 +2949,10 @@ namespace ts {
|
|||
|
||||
/* @internal */ export function getNodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ModuleDeclaration: return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.SourceFile:
|
||||
return isExternalModule(<SourceFile>node) ? ScriptElementKind.moduleElement : ScriptElementKind.scriptElement;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
return ScriptElementKind.classElement;
|
||||
|
@ -2955,11 +2960,10 @@ namespace ts {
|
|||
case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement;
|
||||
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return isConst(node)
|
||||
? ScriptElementKind.constElement
|
||||
: isLet(node)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
return getKindOfVariableDeclaration(<VariableDeclaration>node);
|
||||
case SyntaxKind.BindingElement:
|
||||
return getKindOfVariableDeclaration(<VariableDeclaration>getRootDeclaration(node));
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return ScriptElementKind.functionElement;
|
||||
|
@ -2976,7 +2980,7 @@ namespace ts {
|
|||
case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement;
|
||||
case SyntaxKind.Constructor: return ScriptElementKind.constructorImplementationElement;
|
||||
case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.variableElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.enumMemberElement;
|
||||
case SyntaxKind.Parameter: return (node.flags & NodeFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement;
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
|
@ -2984,8 +2988,19 @@ namespace ts {
|
|||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return ScriptElementKind.alias;
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
default:
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
||||
function getKindOfVariableDeclaration(v: VariableDeclaration): string {
|
||||
return isConst(v)
|
||||
? ScriptElementKind.constElement
|
||||
: isLet(v)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
}
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
||||
class CancellationTokenObject implements CancellationToken {
|
||||
|
@ -3075,14 +3090,16 @@ namespace ts {
|
|||
|
||||
const oldSettings = program && program.getCompilerOptions();
|
||||
const newSettings = hostCache.compilationSettings();
|
||||
const changesInCompilationSettingsAffectSyntax = oldSettings &&
|
||||
const shouldCreateNewSourceFiles = oldSettings &&
|
||||
(oldSettings.target !== newSettings.target ||
|
||||
oldSettings.module !== newSettings.module ||
|
||||
oldSettings.moduleResolution !== newSettings.moduleResolution ||
|
||||
oldSettings.noResolve !== newSettings.noResolve ||
|
||||
oldSettings.jsx !== newSettings.jsx ||
|
||||
oldSettings.allowJs !== newSettings.allowJs ||
|
||||
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit);
|
||||
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit ||
|
||||
oldSettings.baseUrl !== newSettings.baseUrl ||
|
||||
!mapIsEqualTo(oldSettings.paths, newSettings.paths));
|
||||
|
||||
// Now create a new compiler
|
||||
const compilerHost: CompilerHost = {
|
||||
|
@ -3134,7 +3151,7 @@ namespace ts {
|
|||
const oldSourceFiles = program.getSourceFiles();
|
||||
const oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldSettings);
|
||||
for (const oldSourceFile of oldSourceFiles) {
|
||||
if (!newProgram.getSourceFile(oldSourceFile.fileName) || changesInCompilationSettingsAffectSyntax) {
|
||||
if (!newProgram.getSourceFile(oldSourceFile.fileName) || shouldCreateNewSourceFiles) {
|
||||
documentRegistry.releaseDocumentWithKey(oldSourceFile.path, oldSettingsKey);
|
||||
}
|
||||
}
|
||||
|
@ -3168,7 +3185,7 @@ namespace ts {
|
|||
// Check if the language version has changed since we last created a program; if they are the same,
|
||||
// it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile
|
||||
// can not be reused. we have to dump all syntax trees and create new ones.
|
||||
if (!changesInCompilationSettingsAffectSyntax) {
|
||||
if (!shouldCreateNewSourceFiles) {
|
||||
// Check if the old program had this file already
|
||||
const oldSourceFile = program && program.getSourceFileByPath(path);
|
||||
if (oldSourceFile) {
|
||||
|
@ -4813,7 +4830,14 @@ namespace ts {
|
|||
}
|
||||
if (symbolFlags & SymbolFlags.Alias) {
|
||||
addNewLineIfDisplayPartsExist();
|
||||
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
|
||||
if (symbol.declarations[0].kind === SyntaxKind.NamespaceExportDeclaration) {
|
||||
displayParts.push(keywordPart(SyntaxKind.ExportKeyword));
|
||||
displayParts.push(spacePart());
|
||||
displayParts.push(keywordPart(SyntaxKind.NamespaceKeyword));
|
||||
}
|
||||
else {
|
||||
displayParts.push(keywordPart(SyntaxKind.ImportKeyword));
|
||||
}
|
||||
displayParts.push(spacePart());
|
||||
addFullSymbolName(symbol);
|
||||
ts.forEach(symbol.declarations, declaration => {
|
||||
|
|
|
@ -72,8 +72,13 @@ namespace ts {
|
|||
directoryExists(directoryName: string): boolean;
|
||||
}
|
||||
|
||||
/** Public interface of the the of a config service shim instance.*/
|
||||
export interface CoreServicesShimHost extends Logger, ModuleResolutionHost {
|
||||
/** Public interface of the core-services host instance used in managed side */
|
||||
export interface CoreServicesShimHost extends Logger {
|
||||
directoryExists(directoryName: string): boolean;
|
||||
fileExists(fileName: string): boolean;
|
||||
getCurrentDirectory(): string;
|
||||
getDirectories(path: string): string;
|
||||
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type: string[]
|
||||
*
|
||||
|
@ -81,9 +86,14 @@ namespace ts {
|
|||
* when enumerating the directory.
|
||||
*/
|
||||
readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string;
|
||||
useCaseSensitiveFileNames?(): boolean;
|
||||
getCurrentDirectory(): string;
|
||||
|
||||
/**
|
||||
* Read arbitary text files on disk, i.e. when resolution procedure needs the content of 'package.json' to determine location of bundled typings for node modules
|
||||
*/
|
||||
readFile(fileName: string): string;
|
||||
realpath?(path: string): string;
|
||||
trace(s: string): void;
|
||||
useCaseSensitiveFileNames?(): boolean;
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -240,6 +250,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
export interface CoreServicesShim extends Shim {
|
||||
getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string;
|
||||
getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
|
||||
getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
|
||||
getDefaultCompilationSettings(): string;
|
||||
|
@ -492,6 +503,10 @@ namespace ts {
|
|||
private readDirectoryFallback(rootDir: string, extension: string, exclude: string[]) {
|
||||
return JSON.parse(this.shimHost.readDirectory(rootDir, extension, JSON.stringify(exclude)));
|
||||
}
|
||||
|
||||
public getDirectories(path: string): string[] {
|
||||
return JSON.parse(this.shimHost.getDirectories(path));
|
||||
}
|
||||
}
|
||||
|
||||
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any {
|
||||
|
@ -1003,7 +1018,7 @@ namespace ts {
|
|||
|
||||
public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {
|
||||
return this.forwardJSONCall(
|
||||
"getPreProcessedFileInfo('" + fileName + "')",
|
||||
`getPreProcessedFileInfo('${fileName}')`,
|
||||
() => {
|
||||
// for now treat files as JavaScript
|
||||
const result = preProcessFile(sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()), /* readImportFiles */ true, /* detectJavaScriptImports */ true);
|
||||
|
@ -1017,6 +1032,16 @@ namespace ts {
|
|||
});
|
||||
}
|
||||
|
||||
public getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string {
|
||||
return this.forwardJSONCall(
|
||||
`getAutomaticTypeDirectiveNames('${compilerOptionsJson}')`,
|
||||
() => {
|
||||
const compilerOptions = <CompilerOptions>JSON.parse(compilerOptionsJson);
|
||||
return getAutomaticTypeDirectiveNames(compilerOptions, this.host);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private convertFileReferences(refs: FileReference[]): IFileReference[] {
|
||||
if (!refs) {
|
||||
return undefined;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
tests/cases/compiler/a.ts(2,5): error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
tests/cases/compiler/a.ts(3,5): error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.ts (2 errors) ====
|
||||
import Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
~~~~~~~
|
||||
!!! error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
Foo.default.default.foo();
|
||||
~~~~~~~
|
||||
!!! error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
==== tests/cases/compiler/b.d.ts (0 errors) ====
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
17
tests/baselines/reference/allowSyntheticDefaultImports10.js
Normal file
17
tests/baselines/reference/allowSyntheticDefaultImports10.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
//// [tests/cases/compiler/allowSyntheticDefaultImports10.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
Foo.default.default.foo();
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
Foo.default.default.foo();
|
28
tests/baselines/reference/allowSyntheticDefaultImports7.js
Normal file
28
tests/baselines/reference/allowSyntheticDefaultImports7.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
//// [tests/cases/compiler/allowSyntheticDefaultImports7.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
return {
|
||||
setters:[
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
b_1["default"].bar();
|
||||
b_1["default"].foo();
|
||||
}
|
||||
}
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : Symbol(foo, Decl(b.d.ts, 0, 0))
|
||||
|
||||
export function bar();
|
||||
>bar : Symbol(bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : () => any
|
||||
|
||||
export function bar();
|
||||
>bar : () => any
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : typeof Foo
|
||||
>Foo : typeof Foo
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar() : any
|
||||
>Foo.bar : () => any
|
||||
>Foo : typeof Foo
|
||||
>bar : () => any
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo() : any
|
||||
>Foo.foo : () => any
|
||||
>Foo : typeof Foo
|
||||
>foo : () => any
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
tests/cases/compiler/a.ts(1,10): error TS2305: Module '"tests/cases/compiler/b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.d.ts (0 errors) ====
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
import { default as Foo } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"tests/cases/compiler/b"' has no exported member 'default'.
|
||||
Foo.bar();
|
||||
Foo.foo();
|
28
tests/baselines/reference/allowSyntheticDefaultImports8.js
Normal file
28
tests/baselines/reference/allowSyntheticDefaultImports8.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
//// [tests/cases/compiler/allowSyntheticDefaultImports8.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
return {
|
||||
setters:[
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
b_1["default"].bar();
|
||||
b_1["default"].foo();
|
||||
}
|
||||
}
|
||||
});
|
17
tests/baselines/reference/allowSyntheticDefaultImports9.js
Normal file
17
tests/baselines/reference/allowSyntheticDefaultImports9.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
//// [tests/cases/compiler/allowSyntheticDefaultImports9.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var b_1 = require("./b");
|
||||
b_1["default"].bar();
|
||||
b_1["default"].foo();
|
|
@ -0,0 +1,22 @@
|
|||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : Symbol(foo, Decl(b.d.ts, 0, 0))
|
||||
|
||||
export function bar();
|
||||
>bar : Symbol(bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : () => any
|
||||
|
||||
export function bar();
|
||||
>bar : () => any
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : typeof Foo
|
||||
>Foo : typeof Foo
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar() : any
|
||||
>Foo.bar : () => any
|
||||
>Foo : typeof Foo
|
||||
>bar : () => any
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo() : any
|
||||
>Foo.foo : () => any
|
||||
>Foo : typeof Foo
|
||||
>foo : () => any
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/a.d.ts ===
|
||||
|
||||
declare namespace ns {
|
||||
>ns : Symbol(ns, Decl(a.d.ts, 0, 0))
|
||||
|
||||
class SecondNS extends FirstNS { }
|
||||
>SecondNS : Symbol(SecondNS, Decl(a.d.ts, 1, 22))
|
||||
>FirstNS : Symbol(FirstNS, Decl(a.d.ts, 2, 36))
|
||||
|
||||
class FirstNS { }
|
||||
>FirstNS : Symbol(FirstNS, Decl(a.d.ts, 2, 36))
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/a.d.ts ===
|
||||
|
||||
declare namespace ns {
|
||||
>ns : typeof ns
|
||||
|
||||
class SecondNS extends FirstNS { }
|
||||
>SecondNS : SecondNS
|
||||
>FirstNS : FirstNS
|
||||
|
||||
class FirstNS { }
|
||||
>FirstNS : FirstNS
|
||||
}
|
||||
|
|
@ -3,21 +3,21 @@ var a: string[] = [];
|
|||
>a : Symbol(a, Decl(arrayConcat2.ts, 0, 3))
|
||||
|
||||
a.concat("hello", 'world');
|
||||
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>a : Symbol(a, Decl(arrayConcat2.ts, 0, 3))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
a.concat('Hello');
|
||||
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>a.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>a : Symbol(a, Decl(arrayConcat2.ts, 0, 3))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
var b = new Array<string>();
|
||||
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
|
||||
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
b.concat('hello');
|
||||
>b.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>b.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
|
|
|
@ -5,17 +5,17 @@ var a: string[] = [];
|
|||
|
||||
a.concat("hello", 'world');
|
||||
>a.concat("hello", 'world') : string[]
|
||||
>a.concat : (...items: (string | string[])[]) => string[]
|
||||
>a.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
|
||||
>a : string[]
|
||||
>concat : (...items: (string | string[])[]) => string[]
|
||||
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
|
||||
>"hello" : string
|
||||
>'world' : string
|
||||
|
||||
a.concat('Hello');
|
||||
>a.concat('Hello') : string[]
|
||||
>a.concat : (...items: (string | string[])[]) => string[]
|
||||
>a.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
|
||||
>a : string[]
|
||||
>concat : (...items: (string | string[])[]) => string[]
|
||||
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
|
||||
>'Hello' : string
|
||||
|
||||
var b = new Array<string>();
|
||||
|
@ -25,8 +25,8 @@ var b = new Array<string>();
|
|||
|
||||
b.concat('hello');
|
||||
>b.concat('hello') : string[]
|
||||
>b.concat : (...items: (string | string[])[]) => string[]
|
||||
>b.concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
|
||||
>b : string[]
|
||||
>concat : (...items: (string | string[])[]) => string[]
|
||||
>concat : { (...items: string[][]): string[]; (...items: (string | string[])[]): string[]; }
|
||||
>'hello' : string
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
var x = [].concat([{ a: 1 }], [{ a: 2 }])
|
||||
>x : Symbol(x, Decl(arrayConcatMap.ts, 0, 3))
|
||||
>[].concat([{ a: 1 }], [{ a: 2 }]) .map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>[].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>[].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>a : Symbol(a, Decl(arrayConcatMap.ts, 0, 20))
|
||||
>a : Symbol(a, Decl(arrayConcatMap.ts, 0, 32))
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ var x = [].concat([{ a: 1 }], [{ a: 2 }])
|
|||
>[].concat([{ a: 1 }], [{ a: 2 }]) .map(b => b.a) : any[]
|
||||
>[].concat([{ a: 1 }], [{ a: 2 }]) .map : <U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]
|
||||
>[].concat([{ a: 1 }], [{ a: 2 }]) : any[]
|
||||
>[].concat : (...items: any[]) => any[]
|
||||
>[].concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
|
||||
>[] : undefined[]
|
||||
>concat : (...items: any[]) => any[]
|
||||
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
|
||||
>[{ a: 1 }] : { a: number; }[]
|
||||
>{ a: 1 } : { a: number; }
|
||||
>a : number
|
||||
|
|
19
tests/baselines/reference/asOpEmitParens.js
Normal file
19
tests/baselines/reference/asOpEmitParens.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
//// [asOpEmitParens.ts]
|
||||
declare var x;
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
|
||||
|
||||
//// [asOpEmitParens.js]
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1) * 3;
|
||||
// Should still emit as x.y
|
||||
x.y;
|
||||
// Emit as new (x())
|
||||
new (x());
|
16
tests/baselines/reference/asOpEmitParens.symbols
Normal file
16
tests/baselines/reference/asOpEmitParens.symbols
Normal file
|
@ -0,0 +1,16 @@
|
|||
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
|
||||
declare var x;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
>x : Symbol(x, Decl(asOpEmitParens.ts, 0, 11))
|
||||
|
30
tests/baselines/reference/asOpEmitParens.types
Normal file
30
tests/baselines/reference/asOpEmitParens.types
Normal file
|
@ -0,0 +1,30 @@
|
|||
=== tests/cases/conformance/expressions/asOperator/asOpEmitParens.ts ===
|
||||
declare var x;
|
||||
>x : any
|
||||
|
||||
// Must emit as (x + 1) * 3
|
||||
(x + 1 as number) * 3;
|
||||
>(x + 1 as number) * 3 : number
|
||||
>(x + 1 as number) : number
|
||||
>x + 1 as number : number
|
||||
>x + 1 : any
|
||||
>x : any
|
||||
>1 : number
|
||||
>3 : number
|
||||
|
||||
// Should still emit as x.y
|
||||
(x as any).y;
|
||||
>(x as any).y : any
|
||||
>(x as any) : any
|
||||
>x as any : any
|
||||
>x : any
|
||||
>y : any
|
||||
|
||||
// Emit as new (x())
|
||||
new (x() as any);
|
||||
>new (x() as any) : any
|
||||
>(x() as any) : any
|
||||
>x() as any : any
|
||||
>x() : any
|
||||
>x : any
|
||||
|
|
@ -1,4 +1,20 @@
|
|||
//// [baseTypeWrappingInstantiationChain.ts]
|
||||
class CBaseBase<T3> {
|
||||
constructor(x: Parameter<T3>) { }
|
||||
}
|
||||
|
||||
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
|
||||
|
||||
}
|
||||
|
||||
class Parameter<T4> {
|
||||
method(t: T4) { }
|
||||
}
|
||||
|
||||
class Wrapper<T5> {
|
||||
property: T5;
|
||||
}
|
||||
|
||||
class C<T1> extends CBase<T1> {
|
||||
public works() {
|
||||
new CBaseBase<Wrapper<T1>>(this);
|
||||
|
@ -9,22 +25,7 @@ class C<T1> extends CBase<T1> {
|
|||
|
||||
public method(t: Wrapper<T1>) { }
|
||||
}
|
||||
|
||||
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
|
||||
|
||||
}
|
||||
|
||||
class CBaseBase<T3> {
|
||||
constructor(x: Parameter<T3>) { }
|
||||
}
|
||||
|
||||
class Parameter<T4> {
|
||||
method(t: T4) { }
|
||||
}
|
||||
|
||||
class Wrapper<T5> {
|
||||
property: T5;
|
||||
}
|
||||
|
||||
|
||||
//// [baseTypeWrappingInstantiationChain.js]
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
|
@ -32,6 +33,29 @@ var __extends = (this && this.__extends) || function (d, b) {
|
|||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var CBaseBase = (function () {
|
||||
function CBaseBase(x) {
|
||||
}
|
||||
return CBaseBase;
|
||||
}());
|
||||
var CBase = (function (_super) {
|
||||
__extends(CBase, _super);
|
||||
function CBase() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
return CBase;
|
||||
}(CBaseBase));
|
||||
var Parameter = (function () {
|
||||
function Parameter() {
|
||||
}
|
||||
Parameter.prototype.method = function (t) { };
|
||||
return Parameter;
|
||||
}());
|
||||
var Wrapper = (function () {
|
||||
function Wrapper() {
|
||||
}
|
||||
return Wrapper;
|
||||
}());
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
|
@ -46,26 +70,3 @@ var C = (function (_super) {
|
|||
C.prototype.method = function (t) { };
|
||||
return C;
|
||||
}(CBase));
|
||||
var CBase = (function (_super) {
|
||||
__extends(CBase, _super);
|
||||
function CBase() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
return CBase;
|
||||
}(CBaseBase));
|
||||
var CBaseBase = (function () {
|
||||
function CBaseBase(x) {
|
||||
}
|
||||
return CBaseBase;
|
||||
}());
|
||||
var Parameter = (function () {
|
||||
function Parameter() {
|
||||
}
|
||||
Parameter.prototype.method = function (t) { };
|
||||
return Parameter;
|
||||
}());
|
||||
var Wrapper = (function () {
|
||||
function Wrapper() {
|
||||
}
|
||||
return Wrapper;
|
||||
}());
|
||||
|
|
|
@ -1,69 +1,70 @@
|
|||
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
|
||||
class C<T1> extends CBase<T1> {
|
||||
>C : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
|
||||
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
|
||||
class CBaseBase<T3> {
|
||||
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
|
||||
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 0, 16))
|
||||
|
||||
public works() {
|
||||
>works : Symbol(C.works, Decl(baseTypeWrappingInstantiationChain.ts, 0, 31))
|
||||
|
||||
new CBaseBase<Wrapper<T1>>(this);
|
||||
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
|
||||
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
|
||||
}
|
||||
public alsoWorks() {
|
||||
>alsoWorks : Symbol(C.alsoWorks, Decl(baseTypeWrappingInstantiationChain.ts, 3, 5))
|
||||
|
||||
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
|
||||
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
|
||||
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
|
||||
}
|
||||
|
||||
public method(t: Wrapper<T1>) { }
|
||||
>method : Symbol(C.method, Decl(baseTypeWrappingInstantiationChain.ts, 6, 5))
|
||||
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 8, 18))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
|
||||
constructor(x: Parameter<T3>) { }
|
||||
>x : Symbol(x, Decl(baseTypeWrappingInstantiationChain.ts, 1, 16))
|
||||
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 6, 1))
|
||||
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 0, 16))
|
||||
}
|
||||
|
||||
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
|
||||
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
|
||||
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12))
|
||||
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
|
||||
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12))
|
||||
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 2, 1))
|
||||
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 4, 12))
|
||||
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
|
||||
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 4, 12))
|
||||
|
||||
}
|
||||
|
||||
class CBaseBase<T3> {
|
||||
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
|
||||
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16))
|
||||
|
||||
constructor(x: Parameter<T3>) { }
|
||||
>x : Symbol(x, Decl(baseTypeWrappingInstantiationChain.ts, 16, 16))
|
||||
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1))
|
||||
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16))
|
||||
}
|
||||
|
||||
class Parameter<T4> {
|
||||
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1))
|
||||
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16))
|
||||
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 6, 1))
|
||||
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 8, 16))
|
||||
|
||||
method(t: T4) { }
|
||||
>method : Symbol(Parameter.method, Decl(baseTypeWrappingInstantiationChain.ts, 19, 21))
|
||||
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 20, 11))
|
||||
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16))
|
||||
>method : Symbol(Parameter.method, Decl(baseTypeWrappingInstantiationChain.ts, 8, 21))
|
||||
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 9, 11))
|
||||
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 8, 16))
|
||||
}
|
||||
|
||||
class Wrapper<T5> {
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
|
||||
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
|
||||
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 12, 14))
|
||||
|
||||
property: T5;
|
||||
>property : Symbol(Wrapper.property, Decl(baseTypeWrappingInstantiationChain.ts, 23, 19))
|
||||
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
|
||||
>property : Symbol(Wrapper.property, Decl(baseTypeWrappingInstantiationChain.ts, 12, 19))
|
||||
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 12, 14))
|
||||
}
|
||||
|
||||
class C<T1> extends CBase<T1> {
|
||||
>C : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 14, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
|
||||
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 2, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
|
||||
|
||||
public works() {
|
||||
>works : Symbol(C.works, Decl(baseTypeWrappingInstantiationChain.ts, 16, 31))
|
||||
|
||||
new CBaseBase<Wrapper<T1>>(this);
|
||||
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
|
||||
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 14, 1))
|
||||
}
|
||||
public alsoWorks() {
|
||||
>alsoWorks : Symbol(C.alsoWorks, Decl(baseTypeWrappingInstantiationChain.ts, 19, 5))
|
||||
|
||||
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
|
||||
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 2, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
|
||||
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 14, 1))
|
||||
}
|
||||
|
||||
public method(t: Wrapper<T1>) { }
|
||||
>method : Symbol(C.method, Decl(baseTypeWrappingInstantiationChain.ts, 22, 5))
|
||||
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 24, 18))
|
||||
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
|
||||
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,42 @@
|
|||
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
|
||||
class CBaseBase<T3> {
|
||||
>CBaseBase : CBaseBase<T3>
|
||||
>T3 : T3
|
||||
|
||||
constructor(x: Parameter<T3>) { }
|
||||
>x : Parameter<T3>
|
||||
>Parameter : Parameter<T4>
|
||||
>T3 : T3
|
||||
}
|
||||
|
||||
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
|
||||
>CBase : CBase<T2>
|
||||
>T2 : T2
|
||||
>CBaseBase : CBaseBase<Wrapper<T2>>
|
||||
>Wrapper : Wrapper<T5>
|
||||
>T2 : T2
|
||||
|
||||
}
|
||||
|
||||
class Parameter<T4> {
|
||||
>Parameter : Parameter<T4>
|
||||
>T4 : T4
|
||||
|
||||
method(t: T4) { }
|
||||
>method : (t: T4) => void
|
||||
>t : T4
|
||||
>T4 : T4
|
||||
}
|
||||
|
||||
class Wrapper<T5> {
|
||||
>Wrapper : Wrapper<T5>
|
||||
>T5 : T5
|
||||
|
||||
property: T5;
|
||||
>property : T5
|
||||
>T5 : T5
|
||||
}
|
||||
|
||||
class C<T1> extends CBase<T1> {
|
||||
>C : C<T1>
|
||||
>T1 : T1
|
||||
|
@ -32,40 +70,3 @@ class C<T1> extends CBase<T1> {
|
|||
>T1 : T1
|
||||
}
|
||||
|
||||
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
|
||||
>CBase : CBase<T2>
|
||||
>T2 : T2
|
||||
>CBaseBase : CBaseBase<Wrapper<T2>>
|
||||
>Wrapper : Wrapper<T5>
|
||||
>T2 : T2
|
||||
|
||||
}
|
||||
|
||||
class CBaseBase<T3> {
|
||||
>CBaseBase : CBaseBase<T3>
|
||||
>T3 : T3
|
||||
|
||||
constructor(x: Parameter<T3>) { }
|
||||
>x : Parameter<T3>
|
||||
>Parameter : Parameter<T4>
|
||||
>T3 : T3
|
||||
}
|
||||
|
||||
class Parameter<T4> {
|
||||
>Parameter : Parameter<T4>
|
||||
>T4 : T4
|
||||
|
||||
method(t: T4) { }
|
||||
>method : (t: T4) => void
|
||||
>t : T4
|
||||
>T4 : T4
|
||||
}
|
||||
|
||||
class Wrapper<T5> {
|
||||
>Wrapper : Wrapper<T5>
|
||||
>T5 : T5
|
||||
|
||||
property: T5;
|
||||
>property : T5
|
||||
>T5 : T5
|
||||
}
|
||||
|
|
35
tests/baselines/reference/bestChoiceType.js
Normal file
35
tests/baselines/reference/bestChoiceType.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
//// [bestChoiceType.ts]
|
||||
|
||||
// Repro from #10041
|
||||
|
||||
(''.match(/ /) || []).map(s => s.toLowerCase());
|
||||
|
||||
// Similar cases
|
||||
|
||||
function f1() {
|
||||
let x = ''.match(/ /);
|
||||
let y = x || [];
|
||||
let z = y.map(s => s.toLowerCase());
|
||||
}
|
||||
|
||||
function f2() {
|
||||
let x = ''.match(/ /);
|
||||
let y = x ? x : [];
|
||||
let z = y.map(s => s.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
//// [bestChoiceType.js]
|
||||
// Repro from #10041
|
||||
(''.match(/ /) || []).map(function (s) { return s.toLowerCase(); });
|
||||
// Similar cases
|
||||
function f1() {
|
||||
var x = ''.match(/ /);
|
||||
var y = x || [];
|
||||
var z = y.map(function (s) { return s.toLowerCase(); });
|
||||
}
|
||||
function f2() {
|
||||
var x = ''.match(/ /);
|
||||
var y = x ? x : [];
|
||||
var z = y.map(function (s) { return s.toLowerCase(); });
|
||||
}
|
63
tests/baselines/reference/bestChoiceType.symbols
Normal file
63
tests/baselines/reference/bestChoiceType.symbols
Normal file
|
@ -0,0 +1,63 @@
|
|||
=== tests/cases/compiler/bestChoiceType.ts ===
|
||||
|
||||
// Repro from #10041
|
||||
|
||||
(''.match(/ /) || []).map(s => s.toLowerCase());
|
||||
>(''.match(/ /) || []).map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26))
|
||||
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(bestChoiceType.ts, 3, 26))
|
||||
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
|
||||
|
||||
// Similar cases
|
||||
|
||||
function f1() {
|
||||
>f1 : Symbol(f1, Decl(bestChoiceType.ts, 3, 48))
|
||||
|
||||
let x = ''.match(/ /);
|
||||
>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7))
|
||||
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
let y = x || [];
|
||||
>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7))
|
||||
>x : Symbol(x, Decl(bestChoiceType.ts, 8, 7))
|
||||
|
||||
let z = y.map(s => s.toLowerCase());
|
||||
>z : Symbol(z, Decl(bestChoiceType.ts, 10, 7))
|
||||
>y.map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>y : Symbol(y, Decl(bestChoiceType.ts, 9, 7))
|
||||
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(bestChoiceType.ts, 10, 18))
|
||||
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(bestChoiceType.ts, 10, 18))
|
||||
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
|
||||
function f2() {
|
||||
>f2 : Symbol(f2, Decl(bestChoiceType.ts, 11, 1))
|
||||
|
||||
let x = ''.match(/ /);
|
||||
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
|
||||
>''.match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>match : Symbol(String.match, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
let y = x ? x : [];
|
||||
>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7))
|
||||
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
|
||||
>x : Symbol(x, Decl(bestChoiceType.ts, 14, 7))
|
||||
|
||||
let z = y.map(s => s.toLowerCase());
|
||||
>z : Symbol(z, Decl(bestChoiceType.ts, 16, 7))
|
||||
>y.map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>y : Symbol(y, Decl(bestChoiceType.ts, 15, 7))
|
||||
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(bestChoiceType.ts, 16, 18))
|
||||
>s.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(bestChoiceType.ts, 16, 18))
|
||||
>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --))
|
||||
}
|
||||
|
88
tests/baselines/reference/bestChoiceType.types
Normal file
88
tests/baselines/reference/bestChoiceType.types
Normal file
|
@ -0,0 +1,88 @@
|
|||
=== tests/cases/compiler/bestChoiceType.ts ===
|
||||
|
||||
// Repro from #10041
|
||||
|
||||
(''.match(/ /) || []).map(s => s.toLowerCase());
|
||||
>(''.match(/ /) || []).map(s => s.toLowerCase()) : string[]
|
||||
>(''.match(/ /) || []).map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
|
||||
>(''.match(/ /) || []) : RegExpMatchArray
|
||||
>''.match(/ /) || [] : RegExpMatchArray
|
||||
>''.match(/ /) : RegExpMatchArray | null
|
||||
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
|
||||
>'' : string
|
||||
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
|
||||
>/ / : RegExp
|
||||
>[] : never[]
|
||||
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
|
||||
>s => s.toLowerCase() : (s: string) => string
|
||||
>s : string
|
||||
>s.toLowerCase() : string
|
||||
>s.toLowerCase : () => string
|
||||
>s : string
|
||||
>toLowerCase : () => string
|
||||
|
||||
// Similar cases
|
||||
|
||||
function f1() {
|
||||
>f1 : () => void
|
||||
|
||||
let x = ''.match(/ /);
|
||||
>x : RegExpMatchArray | null
|
||||
>''.match(/ /) : RegExpMatchArray | null
|
||||
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
|
||||
>'' : string
|
||||
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
|
||||
>/ / : RegExp
|
||||
|
||||
let y = x || [];
|
||||
>y : RegExpMatchArray
|
||||
>x || [] : RegExpMatchArray
|
||||
>x : RegExpMatchArray | null
|
||||
>[] : never[]
|
||||
|
||||
let z = y.map(s => s.toLowerCase());
|
||||
>z : string[]
|
||||
>y.map(s => s.toLowerCase()) : string[]
|
||||
>y.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
|
||||
>y : RegExpMatchArray
|
||||
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
|
||||
>s => s.toLowerCase() : (s: string) => string
|
||||
>s : string
|
||||
>s.toLowerCase() : string
|
||||
>s.toLowerCase : () => string
|
||||
>s : string
|
||||
>toLowerCase : () => string
|
||||
}
|
||||
|
||||
function f2() {
|
||||
>f2 : () => void
|
||||
|
||||
let x = ''.match(/ /);
|
||||
>x : RegExpMatchArray | null
|
||||
>''.match(/ /) : RegExpMatchArray | null
|
||||
>''.match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
|
||||
>'' : string
|
||||
>match : { (regexp: string): RegExpMatchArray | null; (regexp: RegExp): RegExpMatchArray | null; }
|
||||
>/ / : RegExp
|
||||
|
||||
let y = x ? x : [];
|
||||
>y : RegExpMatchArray
|
||||
>x ? x : [] : RegExpMatchArray
|
||||
>x : RegExpMatchArray | null
|
||||
>x : RegExpMatchArray
|
||||
>[] : never[]
|
||||
|
||||
let z = y.map(s => s.toLowerCase());
|
||||
>z : string[]
|
||||
>y.map(s => s.toLowerCase()) : string[]
|
||||
>y.map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
|
||||
>y : RegExpMatchArray
|
||||
>map : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]
|
||||
>s => s.toLowerCase() : (s: string) => string
|
||||
>s : string
|
||||
>s.toLowerCase() : string
|
||||
>s.toLowerCase : () => string
|
||||
>s : string
|
||||
>toLowerCase : () => string
|
||||
}
|
||||
|
25
tests/baselines/reference/circularImportAlias.errors.txt
Normal file
25
tests/baselines/reference/circularImportAlias.errors.txt
Normal file
|
@ -0,0 +1,25 @@
|
|||
tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts(5,28): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts (1 errors) ====
|
||||
// expected no error
|
||||
|
||||
module B {
|
||||
export import a = A;
|
||||
export class D extends a.C {
|
||||
~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
id: number;
|
||||
}
|
||||
}
|
||||
|
||||
module A {
|
||||
export class C { name: string }
|
||||
export import b = B;
|
||||
}
|
||||
|
||||
var c: { name: string };
|
||||
var c = new B.a.C();
|
||||
|
||||
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
=== tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts ===
|
||||
// expected no error
|
||||
|
||||
module B {
|
||||
>B : Symbol(a.b, Decl(circularImportAlias.ts, 0, 0))
|
||||
|
||||
export import a = A;
|
||||
>a : Symbol(a, Decl(circularImportAlias.ts, 2, 10))
|
||||
>A : Symbol(a, Decl(circularImportAlias.ts, 7, 1))
|
||||
|
||||
export class D extends a.C {
|
||||
>D : Symbol(D, Decl(circularImportAlias.ts, 3, 24))
|
||||
>a.C : Symbol(a.C, Decl(circularImportAlias.ts, 9, 10))
|
||||
>a : Symbol(a, Decl(circularImportAlias.ts, 2, 10))
|
||||
>C : Symbol(a.C, Decl(circularImportAlias.ts, 9, 10))
|
||||
|
||||
id: number;
|
||||
>id : Symbol(D.id, Decl(circularImportAlias.ts, 4, 32))
|
||||
}
|
||||
}
|
||||
|
||||
module A {
|
||||
>A : Symbol(b.a, Decl(circularImportAlias.ts, 7, 1))
|
||||
|
||||
export class C { name: string }
|
||||
>C : Symbol(C, Decl(circularImportAlias.ts, 9, 10))
|
||||
>name : Symbol(C.name, Decl(circularImportAlias.ts, 10, 20))
|
||||
|
||||
export import b = B;
|
||||
>b : Symbol(b, Decl(circularImportAlias.ts, 10, 35))
|
||||
>B : Symbol(b, Decl(circularImportAlias.ts, 0, 0))
|
||||
}
|
||||
|
||||
var c: { name: string };
|
||||
>c : Symbol(c, Decl(circularImportAlias.ts, 14, 3), Decl(circularImportAlias.ts, 15, 3))
|
||||
>name : Symbol(name, Decl(circularImportAlias.ts, 14, 8))
|
||||
|
||||
var c = new B.a.C();
|
||||
>c : Symbol(c, Decl(circularImportAlias.ts, 14, 3), Decl(circularImportAlias.ts, 15, 3))
|
||||
>B.a.C : Symbol(A.C, Decl(circularImportAlias.ts, 9, 10))
|
||||
>B.a : Symbol(B.a, Decl(circularImportAlias.ts, 2, 10))
|
||||
>B : Symbol(B, Decl(circularImportAlias.ts, 0, 0))
|
||||
>a : Symbol(B.a, Decl(circularImportAlias.ts, 2, 10))
|
||||
>C : Symbol(A.C, Decl(circularImportAlias.ts, 9, 10))
|
||||
|
||||
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
=== tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts ===
|
||||
// expected no error
|
||||
|
||||
module B {
|
||||
>B : typeof a.b
|
||||
|
||||
export import a = A;
|
||||
>a : typeof a
|
||||
>A : typeof a
|
||||
|
||||
export class D extends a.C {
|
||||
>D : D
|
||||
>a.C : a.C
|
||||
>a : typeof a
|
||||
>C : typeof a.C
|
||||
|
||||
id: number;
|
||||
>id : number
|
||||
}
|
||||
}
|
||||
|
||||
module A {
|
||||
>A : typeof b.a
|
||||
|
||||
export class C { name: string }
|
||||
>C : C
|
||||
>name : string
|
||||
|
||||
export import b = B;
|
||||
>b : typeof b
|
||||
>B : typeof b
|
||||
}
|
||||
|
||||
var c: { name: string };
|
||||
>c : { name: string; }
|
||||
>name : string
|
||||
|
||||
var c = new B.a.C();
|
||||
>c : { name: string; }
|
||||
>new B.a.C() : A.C
|
||||
>B.a.C : typeof A.C
|
||||
>B.a : typeof A
|
||||
>B : typeof B
|
||||
>a : typeof A
|
||||
>C : typeof A.C
|
||||
|
||||
|
||||
|
15
tests/baselines/reference/classExpression3.errors.txt
Normal file
15
tests/baselines/reference/classExpression3.errors.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
tests/cases/conformance/classes/classExpressions/classExpression3.ts(1,23): error TS2690: A class must be declared after its base class.
|
||||
tests/cases/conformance/classes/classExpressions/classExpression3.ts(1,37): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/classes/classExpressions/classExpression3.ts (2 errors) ====
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
let c = new C();
|
||||
c.a;
|
||||
c.b;
|
||||
c.c;
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
=== tests/cases/conformance/classes/classExpressions/classExpression3.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : Symbol(C, Decl(classExpression3.ts, 0, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
|
||||
|
||||
let c = new C();
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>C : Symbol(C, Decl(classExpression3.ts, 0, 3))
|
||||
|
||||
c.a;
|
||||
>c.a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
|
||||
|
||||
c.b;
|
||||
>c.b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
|
||||
|
||||
c.c;
|
||||
>c.c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
|
||||
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
=== tests/cases/conformance/classes/classExpressions/classExpression3.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : typeof (Anonymous class)
|
||||
>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class)
|
||||
>class extends class { a = 1 } { b = 2 } : (Anonymous class)
|
||||
>class { a = 1 } : (Anonymous class)
|
||||
>a : number
|
||||
>1 : number
|
||||
>b : number
|
||||
>2 : number
|
||||
>c : number
|
||||
>3 : number
|
||||
|
||||
let c = new C();
|
||||
>c : (Anonymous class)
|
||||
>new C() : (Anonymous class)
|
||||
>C : typeof (Anonymous class)
|
||||
|
||||
c.a;
|
||||
>c.a : number
|
||||
>c : (Anonymous class)
|
||||
>a : number
|
||||
|
||||
c.b;
|
||||
>c.b : number
|
||||
>c : (Anonymous class)
|
||||
>b : number
|
||||
|
||||
c.c;
|
||||
>c.c : number
|
||||
>c : (Anonymous class)
|
||||
>c : number
|
||||
|
15
tests/baselines/reference/classExpressionES63.errors.txt
Normal file
15
tests/baselines/reference/classExpressionES63.errors.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
tests/cases/conformance/es6/classExpressions/classExpressionES63.ts(1,23): error TS2690: A class must be declared after its base class.
|
||||
tests/cases/conformance/es6/classExpressions/classExpressionES63.ts(1,37): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts (2 errors) ====
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
let c = new C();
|
||||
c.a;
|
||||
c.b;
|
||||
c.c;
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
|
||||
|
||||
let c = new C();
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3))
|
||||
|
||||
c.a;
|
||||
>c.a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
|
||||
|
||||
c.b;
|
||||
>c.b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
|
||||
|
||||
c.c;
|
||||
>c.c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
|
||||
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
|
||||
>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts ===
|
||||
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
|
||||
>C : typeof (Anonymous class)
|
||||
>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class)
|
||||
>class extends class { a = 1 } { b = 2 } : (Anonymous class)
|
||||
>class { a = 1 } : (Anonymous class)
|
||||
>a : number
|
||||
>1 : number
|
||||
>b : number
|
||||
>2 : number
|
||||
>c : number
|
||||
>3 : number
|
||||
|
||||
let c = new C();
|
||||
>c : (Anonymous class)
|
||||
>new C() : (Anonymous class)
|
||||
>C : typeof (Anonymous class)
|
||||
|
||||
c.a;
|
||||
>c.a : number
|
||||
>c : (Anonymous class)
|
||||
>a : number
|
||||
|
||||
c.b;
|
||||
>c.b : number
|
||||
>c : (Anonymous class)
|
||||
>b : number
|
||||
|
||||
c.c;
|
||||
>c.c : number
|
||||
>c : (Anonymous class)
|
||||
>c : number
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
tests/cases/compiler/classInheritence.ts(1,17): error TS2690: A class must be declared after its base class.
|
||||
tests/cases/compiler/classInheritence.ts(2,7): error TS2506: 'A' is referenced directly or indirectly in its own base expression.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classInheritence.ts (1 errors) ====
|
||||
==== tests/cases/compiler/classInheritence.ts (2 errors) ====
|
||||
class B extends A { }
|
||||
~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
class A extends A { }
|
||||
~
|
||||
!!! error TS2506: 'A' is referenced directly or indirectly in its own base expression.
|
25
tests/baselines/reference/classOrder2.errors.txt
Normal file
25
tests/baselines/reference/classOrder2.errors.txt
Normal file
|
@ -0,0 +1,25 @@
|
|||
tests/cases/compiler/classOrder2.ts(2,17): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classOrder2.ts (1 errors) ====
|
||||
|
||||
class A extends B {
|
||||
~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
|
||||
foo() { this.bar(); }
|
||||
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
bar() { }
|
||||
|
||||
}
|
||||
|
||||
|
||||
var a = new A();
|
||||
|
||||
a.foo();
|
||||
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
=== tests/cases/compiler/classOrder2.ts ===
|
||||
|
||||
class A extends B {
|
||||
>A : Symbol(A, Decl(classOrder2.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(classOrder2.ts, 5, 1))
|
||||
|
||||
foo() { this.bar(); }
|
||||
>foo : Symbol(A.foo, Decl(classOrder2.ts, 1, 19))
|
||||
>this.bar : Symbol(B.bar, Decl(classOrder2.ts, 7, 9))
|
||||
>this : Symbol(A, Decl(classOrder2.ts, 0, 0))
|
||||
>bar : Symbol(B.bar, Decl(classOrder2.ts, 7, 9))
|
||||
|
||||
}
|
||||
|
||||
class B {
|
||||
>B : Symbol(B, Decl(classOrder2.ts, 5, 1))
|
||||
|
||||
bar() { }
|
||||
>bar : Symbol(B.bar, Decl(classOrder2.ts, 7, 9))
|
||||
|
||||
}
|
||||
|
||||
|
||||
var a = new A();
|
||||
>a : Symbol(a, Decl(classOrder2.ts, 14, 3))
|
||||
>A : Symbol(A, Decl(classOrder2.ts, 0, 0))
|
||||
|
||||
a.foo();
|
||||
>a.foo : Symbol(A.foo, Decl(classOrder2.ts, 1, 19))
|
||||
>a : Symbol(a, Decl(classOrder2.ts, 14, 3))
|
||||
>foo : Symbol(A.foo, Decl(classOrder2.ts, 1, 19))
|
||||
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
=== tests/cases/compiler/classOrder2.ts ===
|
||||
|
||||
class A extends B {
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
foo() { this.bar(); }
|
||||
>foo : () => void
|
||||
>this.bar() : void
|
||||
>this.bar : () => void
|
||||
>this : this
|
||||
>bar : () => void
|
||||
|
||||
}
|
||||
|
||||
class B {
|
||||
>B : B
|
||||
|
||||
bar() { }
|
||||
>bar : () => void
|
||||
|
||||
}
|
||||
|
||||
|
||||
var a = new A();
|
||||
>a : A
|
||||
>new A() : A
|
||||
>A : typeof A
|
||||
|
||||
a.foo();
|
||||
>a.foo() : void
|
||||
>a.foo : () => void
|
||||
>a : A
|
||||
>foo : () => void
|
||||
|
||||
|
26
tests/baselines/reference/classSideInheritance2.errors.txt
Normal file
26
tests/baselines/reference/classSideInheritance2.errors.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
tests/cases/compiler/classSideInheritance2.ts(7,23): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classSideInheritance2.ts (1 errors) ====
|
||||
interface IText {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
interface TextSpan {}
|
||||
|
||||
class SubText extends TextBase {
|
||||
~~~~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
|
||||
constructor(text: IText, span: TextSpan) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
class TextBase implements IText {
|
||||
public foo: number;
|
||||
public subText(span: TextSpan): IText {
|
||||
|
||||
return new SubText(this, span);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
=== tests/cases/compiler/classSideInheritance2.ts ===
|
||||
interface IText {
|
||||
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
|
||||
|
||||
foo: number;
|
||||
>foo : Symbol(IText.foo, Decl(classSideInheritance2.ts, 0, 17))
|
||||
}
|
||||
|
||||
interface TextSpan {}
|
||||
>TextSpan : Symbol(TextSpan, Decl(classSideInheritance2.ts, 2, 1))
|
||||
|
||||
class SubText extends TextBase {
|
||||
>SubText : Symbol(SubText, Decl(classSideInheritance2.ts, 4, 21))
|
||||
>TextBase : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
|
||||
|
||||
constructor(text: IText, span: TextSpan) {
|
||||
>text : Symbol(text, Decl(classSideInheritance2.ts, 8, 20))
|
||||
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
|
||||
>span : Symbol(span, Decl(classSideInheritance2.ts, 8, 32))
|
||||
>TextSpan : Symbol(TextSpan, Decl(classSideInheritance2.ts, 2, 1))
|
||||
|
||||
super();
|
||||
>super : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
|
||||
}
|
||||
}
|
||||
|
||||
class TextBase implements IText {
|
||||
>TextBase : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
|
||||
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
|
||||
|
||||
public foo: number;
|
||||
>foo : Symbol(TextBase.foo, Decl(classSideInheritance2.ts, 13, 33))
|
||||
|
||||
public subText(span: TextSpan): IText {
|
||||
>subText : Symbol(TextBase.subText, Decl(classSideInheritance2.ts, 14, 27))
|
||||
>span : Symbol(span, Decl(classSideInheritance2.ts, 15, 23))
|
||||
>TextSpan : Symbol(TextSpan, Decl(classSideInheritance2.ts, 2, 1))
|
||||
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
|
||||
|
||||
return new SubText(this, span);
|
||||
>SubText : Symbol(SubText, Decl(classSideInheritance2.ts, 4, 21))
|
||||
>this : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
|
||||
>span : Symbol(span, Decl(classSideInheritance2.ts, 15, 23))
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
=== tests/cases/compiler/classSideInheritance2.ts ===
|
||||
interface IText {
|
||||
>IText : IText
|
||||
|
||||
foo: number;
|
||||
>foo : number
|
||||
}
|
||||
|
||||
interface TextSpan {}
|
||||
>TextSpan : TextSpan
|
||||
|
||||
class SubText extends TextBase {
|
||||
>SubText : SubText
|
||||
>TextBase : TextBase
|
||||
|
||||
constructor(text: IText, span: TextSpan) {
|
||||
>text : IText
|
||||
>IText : IText
|
||||
>span : TextSpan
|
||||
>TextSpan : TextSpan
|
||||
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof TextBase
|
||||
}
|
||||
}
|
||||
|
||||
class TextBase implements IText {
|
||||
>TextBase : TextBase
|
||||
>IText : IText
|
||||
|
||||
public foo: number;
|
||||
>foo : number
|
||||
|
||||
public subText(span: TextSpan): IText {
|
||||
>subText : (span: TextSpan) => IText
|
||||
>span : TextSpan
|
||||
>TextSpan : TextSpan
|
||||
>IText : IText
|
||||
|
||||
return new SubText(this, span);
|
||||
>new SubText(this, span) : SubText
|
||||
>SubText : typeof SubText
|
||||
>this : this
|
||||
>span : TextSpan
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
tests/cases/compiler/complexClassRelationships.ts(2,23): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/complexClassRelationships.ts (1 errors) ====
|
||||
// There should be no errors in this file
|
||||
class Derived extends Base {
|
||||
~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
public static createEmpty(): Derived {
|
||||
var item = new Derived();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
class BaseCollection<T extends Base> {
|
||||
constructor(f: () => T) {
|
||||
(item: Thing) => { return [item.Components]; };
|
||||
}
|
||||
}
|
||||
class Base {
|
||||
ownerCollection: BaseCollection<Base>;
|
||||
}
|
||||
|
||||
class Thing {
|
||||
public get Components(): ComponentCollection<any> { return null }
|
||||
}
|
||||
|
||||
class ComponentCollection<T> {
|
||||
private static sortComponents(p: Foo) {
|
||||
return p.prop1;
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
public get prop1() {
|
||||
return new GenericType<string>(this);
|
||||
}
|
||||
public populate() {
|
||||
this.prop2;
|
||||
}
|
||||
public get prop2(): BaseCollection<Derived> {
|
||||
return new BaseCollection<Derived>(Derived.createEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
class GenericType<T> {
|
||||
constructor(parent: FooBase) { }
|
||||
}
|
||||
|
||||
class FooBase {
|
||||
public populate() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
=== tests/cases/compiler/complexClassRelationships.ts ===
|
||||
// There should be no errors in this file
|
||||
class Derived extends Base {
|
||||
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
|
||||
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
|
||||
|
||||
public static createEmpty(): Derived {
|
||||
>createEmpty : Symbol(Derived.createEmpty, Decl(complexClassRelationships.ts, 1, 28))
|
||||
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
|
||||
|
||||
var item = new Derived();
|
||||
>item : Symbol(item, Decl(complexClassRelationships.ts, 3, 11))
|
||||
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
|
||||
|
||||
return item;
|
||||
>item : Symbol(item, Decl(complexClassRelationships.ts, 3, 11))
|
||||
}
|
||||
}
|
||||
class BaseCollection<T extends Base> {
|
||||
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
|
||||
>T : Symbol(T, Decl(complexClassRelationships.ts, 7, 21))
|
||||
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
|
||||
|
||||
constructor(f: () => T) {
|
||||
>f : Symbol(f, Decl(complexClassRelationships.ts, 8, 16))
|
||||
>T : Symbol(T, Decl(complexClassRelationships.ts, 7, 21))
|
||||
|
||||
(item: Thing) => { return [item.Components]; };
|
||||
>item : Symbol(item, Decl(complexClassRelationships.ts, 9, 9))
|
||||
>Thing : Symbol(Thing, Decl(complexClassRelationships.ts, 14, 1))
|
||||
>item.Components : Symbol(Thing.Components, Decl(complexClassRelationships.ts, 16, 13))
|
||||
>item : Symbol(item, Decl(complexClassRelationships.ts, 9, 9))
|
||||
>Components : Symbol(Thing.Components, Decl(complexClassRelationships.ts, 16, 13))
|
||||
}
|
||||
}
|
||||
class Base {
|
||||
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
|
||||
|
||||
ownerCollection: BaseCollection<Base>;
|
||||
>ownerCollection : Symbol(Base.ownerCollection, Decl(complexClassRelationships.ts, 12, 12))
|
||||
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
|
||||
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
|
||||
}
|
||||
|
||||
class Thing {
|
||||
>Thing : Symbol(Thing, Decl(complexClassRelationships.ts, 14, 1))
|
||||
|
||||
public get Components(): ComponentCollection<any> { return null }
|
||||
>Components : Symbol(Thing.Components, Decl(complexClassRelationships.ts, 16, 13))
|
||||
>ComponentCollection : Symbol(ComponentCollection, Decl(complexClassRelationships.ts, 18, 1))
|
||||
}
|
||||
|
||||
class ComponentCollection<T> {
|
||||
>ComponentCollection : Symbol(ComponentCollection, Decl(complexClassRelationships.ts, 18, 1))
|
||||
>T : Symbol(T, Decl(complexClassRelationships.ts, 20, 26))
|
||||
|
||||
private static sortComponents(p: Foo) {
|
||||
>sortComponents : Symbol(ComponentCollection.sortComponents, Decl(complexClassRelationships.ts, 20, 30))
|
||||
>p : Symbol(p, Decl(complexClassRelationships.ts, 21, 34))
|
||||
>Foo : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
|
||||
|
||||
return p.prop1;
|
||||
>p.prop1 : Symbol(Foo.prop1, Decl(complexClassRelationships.ts, 26, 11))
|
||||
>p : Symbol(p, Decl(complexClassRelationships.ts, 21, 34))
|
||||
>prop1 : Symbol(Foo.prop1, Decl(complexClassRelationships.ts, 26, 11))
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
|
||||
|
||||
public get prop1() {
|
||||
>prop1 : Symbol(Foo.prop1, Decl(complexClassRelationships.ts, 26, 11))
|
||||
|
||||
return new GenericType<string>(this);
|
||||
>GenericType : Symbol(GenericType, Decl(complexClassRelationships.ts, 36, 1))
|
||||
>this : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
|
||||
}
|
||||
public populate() {
|
||||
>populate : Symbol(Foo.populate, Decl(complexClassRelationships.ts, 29, 5))
|
||||
|
||||
this.prop2;
|
||||
>this.prop2 : Symbol(Foo.prop2, Decl(complexClassRelationships.ts, 32, 5))
|
||||
>this : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
|
||||
>prop2 : Symbol(Foo.prop2, Decl(complexClassRelationships.ts, 32, 5))
|
||||
}
|
||||
public get prop2(): BaseCollection<Derived> {
|
||||
>prop2 : Symbol(Foo.prop2, Decl(complexClassRelationships.ts, 32, 5))
|
||||
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
|
||||
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
|
||||
|
||||
return new BaseCollection<Derived>(Derived.createEmpty);
|
||||
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
|
||||
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
|
||||
>Derived.createEmpty : Symbol(Derived.createEmpty, Decl(complexClassRelationships.ts, 1, 28))
|
||||
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
|
||||
>createEmpty : Symbol(Derived.createEmpty, Decl(complexClassRelationships.ts, 1, 28))
|
||||
}
|
||||
}
|
||||
|
||||
class GenericType<T> {
|
||||
>GenericType : Symbol(GenericType, Decl(complexClassRelationships.ts, 36, 1))
|
||||
>T : Symbol(T, Decl(complexClassRelationships.ts, 38, 18))
|
||||
|
||||
constructor(parent: FooBase) { }
|
||||
>parent : Symbol(parent, Decl(complexClassRelationships.ts, 39, 16))
|
||||
>FooBase : Symbol(FooBase, Decl(complexClassRelationships.ts, 40, 1))
|
||||
}
|
||||
|
||||
class FooBase {
|
||||
>FooBase : Symbol(FooBase, Decl(complexClassRelationships.ts, 40, 1))
|
||||
|
||||
public populate() {
|
||||
>populate : Symbol(FooBase.populate, Decl(complexClassRelationships.ts, 42, 15))
|
||||
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
=== tests/cases/compiler/complexClassRelationships.ts ===
|
||||
// There should be no errors in this file
|
||||
class Derived extends Base {
|
||||
>Derived : Derived
|
||||
>Base : Base
|
||||
|
||||
public static createEmpty(): Derived {
|
||||
>createEmpty : () => Derived
|
||||
>Derived : Derived
|
||||
|
||||
var item = new Derived();
|
||||
>item : Derived
|
||||
>new Derived() : Derived
|
||||
>Derived : typeof Derived
|
||||
|
||||
return item;
|
||||
>item : Derived
|
||||
}
|
||||
}
|
||||
class BaseCollection<T extends Base> {
|
||||
>BaseCollection : BaseCollection<T>
|
||||
>T : T
|
||||
>Base : Base
|
||||
|
||||
constructor(f: () => T) {
|
||||
>f : () => T
|
||||
>T : T
|
||||
|
||||
(item: Thing) => { return [item.Components]; };
|
||||
>(item: Thing) => { return [item.Components]; } : (item: Thing) => ComponentCollection<any>[]
|
||||
>item : Thing
|
||||
>Thing : Thing
|
||||
>[item.Components] : ComponentCollection<any>[]
|
||||
>item.Components : ComponentCollection<any>
|
||||
>item : Thing
|
||||
>Components : ComponentCollection<any>
|
||||
}
|
||||
}
|
||||
class Base {
|
||||
>Base : Base
|
||||
|
||||
ownerCollection: BaseCollection<Base>;
|
||||
>ownerCollection : BaseCollection<Base>
|
||||
>BaseCollection : BaseCollection<T>
|
||||
>Base : Base
|
||||
}
|
||||
|
||||
class Thing {
|
||||
>Thing : Thing
|
||||
|
||||
public get Components(): ComponentCollection<any> { return null }
|
||||
>Components : ComponentCollection<any>
|
||||
>ComponentCollection : ComponentCollection<T>
|
||||
>null : null
|
||||
}
|
||||
|
||||
class ComponentCollection<T> {
|
||||
>ComponentCollection : ComponentCollection<T>
|
||||
>T : T
|
||||
|
||||
private static sortComponents(p: Foo) {
|
||||
>sortComponents : (p: Foo) => GenericType<string>
|
||||
>p : Foo
|
||||
>Foo : Foo
|
||||
|
||||
return p.prop1;
|
||||
>p.prop1 : GenericType<string>
|
||||
>p : Foo
|
||||
>prop1 : GenericType<string>
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
>Foo : Foo
|
||||
|
||||
public get prop1() {
|
||||
>prop1 : GenericType<string>
|
||||
|
||||
return new GenericType<string>(this);
|
||||
>new GenericType<string>(this) : GenericType<string>
|
||||
>GenericType : typeof GenericType
|
||||
>this : this
|
||||
}
|
||||
public populate() {
|
||||
>populate : () => void
|
||||
|
||||
this.prop2;
|
||||
>this.prop2 : BaseCollection<Derived>
|
||||
>this : this
|
||||
>prop2 : BaseCollection<Derived>
|
||||
}
|
||||
public get prop2(): BaseCollection<Derived> {
|
||||
>prop2 : BaseCollection<Derived>
|
||||
>BaseCollection : BaseCollection<T>
|
||||
>Derived : Derived
|
||||
|
||||
return new BaseCollection<Derived>(Derived.createEmpty);
|
||||
>new BaseCollection<Derived>(Derived.createEmpty) : BaseCollection<Derived>
|
||||
>BaseCollection : typeof BaseCollection
|
||||
>Derived : Derived
|
||||
>Derived.createEmpty : () => Derived
|
||||
>Derived : typeof Derived
|
||||
>createEmpty : () => Derived
|
||||
}
|
||||
}
|
||||
|
||||
class GenericType<T> {
|
||||
>GenericType : GenericType<T>
|
||||
>T : T
|
||||
|
||||
constructor(parent: FooBase) { }
|
||||
>parent : FooBase
|
||||
>FooBase : FooBase
|
||||
}
|
||||
|
||||
class FooBase {
|
||||
>FooBase : FooBase
|
||||
|
||||
public populate() {
|
||||
>populate : () => void
|
||||
|
||||
}
|
||||
}
|
|
@ -14,15 +14,15 @@ var fa: number[];
|
|||
|
||||
fa = fa.concat([0]);
|
||||
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
|
||||
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
fa = fa.concat(0);
|
||||
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
|
||||
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>fa.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>fa : Symbol(fa, Decl(concatError.ts, 8, 3))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ fa = fa.concat([0]);
|
|||
>fa = fa.concat([0]) : number[]
|
||||
>fa : number[]
|
||||
>fa.concat([0]) : number[]
|
||||
>fa.concat : (...items: (number | number[])[]) => number[]
|
||||
>fa.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
|
||||
>fa : number[]
|
||||
>concat : (...items: (number | number[])[]) => number[]
|
||||
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
|
||||
>[0] : number[]
|
||||
>0 : number
|
||||
|
||||
|
@ -26,9 +26,9 @@ fa = fa.concat(0);
|
|||
>fa = fa.concat(0) : number[]
|
||||
>fa : number[]
|
||||
>fa.concat(0) : number[]
|
||||
>fa.concat : (...items: (number | number[])[]) => number[]
|
||||
>fa.concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
|
||||
>fa : number[]
|
||||
>concat : (...items: (number | number[])[]) => number[]
|
||||
>concat : { (...items: number[][]): number[]; (...items: (number | number[])[]): number[]; }
|
||||
>0 : number
|
||||
|
||||
|
||||
|
|
8
tests/baselines/reference/concatTuples.js
Normal file
8
tests/baselines/reference/concatTuples.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
//// [concatTuples.ts]
|
||||
let ijs: [number, number][] = [[1, 2]];
|
||||
ijs = ijs.concat([[3, 4], [5, 6]]);
|
||||
|
||||
|
||||
//// [concatTuples.js]
|
||||
var ijs = [[1, 2]];
|
||||
ijs = ijs.concat([[3, 4], [5, 6]]);
|
10
tests/baselines/reference/concatTuples.symbols
Normal file
10
tests/baselines/reference/concatTuples.symbols
Normal file
|
@ -0,0 +1,10 @@
|
|||
=== tests/cases/compiler/concatTuples.ts ===
|
||||
let ijs: [number, number][] = [[1, 2]];
|
||||
>ijs : Symbol(ijs, Decl(concatTuples.ts, 0, 3))
|
||||
|
||||
ijs = ijs.concat([[3, 4], [5, 6]]);
|
||||
>ijs : Symbol(ijs, Decl(concatTuples.ts, 0, 3))
|
||||
>ijs.concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>ijs : Symbol(ijs, Decl(concatTuples.ts, 0, 3))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
|
23
tests/baselines/reference/concatTuples.types
Normal file
23
tests/baselines/reference/concatTuples.types
Normal file
|
@ -0,0 +1,23 @@
|
|||
=== tests/cases/compiler/concatTuples.ts ===
|
||||
let ijs: [number, number][] = [[1, 2]];
|
||||
>ijs : [number, number][]
|
||||
>[[1, 2]] : [number, number][]
|
||||
>[1, 2] : [number, number]
|
||||
>1 : number
|
||||
>2 : number
|
||||
|
||||
ijs = ijs.concat([[3, 4], [5, 6]]);
|
||||
>ijs = ijs.concat([[3, 4], [5, 6]]) : [number, number][]
|
||||
>ijs : [number, number][]
|
||||
>ijs.concat([[3, 4], [5, 6]]) : [number, number][]
|
||||
>ijs.concat : { (...items: [number, number][][]): [number, number][]; (...items: ([number, number] | [number, number][])[]): [number, number][]; }
|
||||
>ijs : [number, number][]
|
||||
>concat : { (...items: [number, number][][]): [number, number][]; (...items: ([number, number] | [number, number][])[]): [number, number][]; }
|
||||
>[[3, 4], [5, 6]] : [number, number][]
|
||||
>[3, 4] : [number, number]
|
||||
>3 : number
|
||||
>4 : number
|
||||
>[5, 6] : [number, number]
|
||||
>5 : number
|
||||
>6 : number
|
||||
|
|
@ -64,9 +64,9 @@ if (isNodeList(sourceObj)) {
|
|||
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
|
||||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
|
||||
>sourceObj.length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27))
|
||||
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
|
||||
>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
|
||||
>length : Symbol(NodeList.length, Decl(controlFlowBinaryOrExpression.ts, 10, 27))
|
||||
}
|
||||
|
||||
if (isHTMLCollection(sourceObj)) {
|
||||
|
@ -74,9 +74,9 @@ if (isHTMLCollection(sourceObj)) {
|
|||
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
|
||||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
|
||||
>sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33))
|
||||
>sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3))
|
||||
>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33))
|
||||
>length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33))
|
||||
}
|
||||
|
||||
if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
|
||||
|
|
|
@ -80,7 +80,7 @@ if (isNodeList(sourceObj)) {
|
|||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : number
|
||||
>sourceObj : NodeList | HTMLCollection
|
||||
>sourceObj : NodeList
|
||||
>length : number
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ if (isHTMLCollection(sourceObj)) {
|
|||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : number
|
||||
>sourceObj : NodeList | HTMLCollection
|
||||
>sourceObj : HTMLCollection
|
||||
>length : number
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,11 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
|
|||
>sourceObj : EventTargetLike
|
||||
>isHTMLCollection(sourceObj) : boolean
|
||||
>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection
|
||||
>sourceObj : { a: string; }
|
||||
>sourceObj : HTMLCollection | { a: string; }
|
||||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : number
|
||||
>sourceObj : NodeList | HTMLCollection | ({ a: string; } & HTMLCollection)
|
||||
>sourceObj : NodeList | HTMLCollection
|
||||
>length : number
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,22 @@ function b() {
|
|||
}
|
||||
x; // string
|
||||
}
|
||||
function c<T>(data: string | T): T {
|
||||
if (typeof data === 'string') {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
function d<T extends string>(data: string | T): never {
|
||||
if (typeof data === 'string') {
|
||||
throw new Error('will always happen');
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [controlFlowIfStatement.js]
|
||||
|
@ -72,3 +88,19 @@ function b() {
|
|||
}
|
||||
x; // string
|
||||
}
|
||||
function c(data) {
|
||||
if (typeof data === 'string') {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
function d(data) {
|
||||
if (typeof data === 'string') {
|
||||
throw new Error('will always happen');
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,4 +71,42 @@ function b() {
|
|||
x; // string
|
||||
>x : Symbol(x, Decl(controlFlowIfStatement.ts, 26, 7))
|
||||
}
|
||||
function c<T>(data: string | T): T {
|
||||
>c : Symbol(c, Decl(controlFlowIfStatement.ts, 35, 1))
|
||||
>T : Symbol(T, Decl(controlFlowIfStatement.ts, 36, 11))
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 36, 14))
|
||||
>T : Symbol(T, Decl(controlFlowIfStatement.ts, 36, 11))
|
||||
>T : Symbol(T, Decl(controlFlowIfStatement.ts, 36, 11))
|
||||
|
||||
if (typeof data === 'string') {
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 36, 14))
|
||||
|
||||
return JSON.parse(data);
|
||||
>JSON.parse : Symbol(JSON.parse, Decl(lib.d.ts, --, --))
|
||||
>JSON : Symbol(JSON, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>parse : Symbol(JSON.parse, Decl(lib.d.ts, --, --))
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 36, 14))
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 36, 14))
|
||||
}
|
||||
}
|
||||
function d<T extends string>(data: string | T): never {
|
||||
>d : Symbol(d, Decl(controlFlowIfStatement.ts, 43, 1))
|
||||
>T : Symbol(T, Decl(controlFlowIfStatement.ts, 44, 11))
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 44, 29))
|
||||
>T : Symbol(T, Decl(controlFlowIfStatement.ts, 44, 11))
|
||||
|
||||
if (typeof data === 'string') {
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 44, 29))
|
||||
|
||||
throw new Error('will always happen');
|
||||
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
>data : Symbol(data, Decl(controlFlowIfStatement.ts, 44, 29))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,4 +90,51 @@ function b() {
|
|||
x; // string
|
||||
>x : string
|
||||
}
|
||||
function c<T>(data: string | T): T {
|
||||
>c : <T>(data: string | T) => T
|
||||
>T : T
|
||||
>data : string | T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
if (typeof data === 'string') {
|
||||
>typeof data === 'string' : boolean
|
||||
>typeof data : string
|
||||
>data : string | T
|
||||
>'string' : "string"
|
||||
|
||||
return JSON.parse(data);
|
||||
>JSON.parse(data) : any
|
||||
>JSON.parse : (text: string, reviver?: (key: any, value: any) => any) => any
|
||||
>JSON : JSON
|
||||
>parse : (text: string, reviver?: (key: any, value: any) => any) => any
|
||||
>data : string
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
>data : T
|
||||
}
|
||||
}
|
||||
function d<T extends string>(data: string | T): never {
|
||||
>d : <T extends string>(data: string | T) => never
|
||||
>T : T
|
||||
>data : string | T
|
||||
>T : T
|
||||
|
||||
if (typeof data === 'string') {
|
||||
>typeof data === 'string' : boolean
|
||||
>typeof data : string
|
||||
>data : string | T
|
||||
>'string' : "string"
|
||||
|
||||
throw new Error('will always happen');
|
||||
>new Error('will always happen') : Error
|
||||
>Error : ErrorConstructor
|
||||
>'will always happen' : string
|
||||
}
|
||||
else {
|
||||
return data;
|
||||
>data : never
|
||||
}
|
||||
}
|
||||
|
||||
|
|
184
tests/baselines/reference/controlFlowInstanceof.js
Normal file
184
tests/baselines/reference/controlFlowInstanceof.js
Normal file
|
@ -0,0 +1,184 @@
|
|||
//// [controlFlowInstanceof.ts]
|
||||
|
||||
// Repros from #10167
|
||||
|
||||
function f1(s: Set<string> | Set<number>) {
|
||||
s = new Set<number>();
|
||||
s; // Set<number>
|
||||
if (s instanceof Set) {
|
||||
s; // Set<number>
|
||||
}
|
||||
s; // Set<number>
|
||||
s.add(42);
|
||||
}
|
||||
|
||||
function f2(s: Set<string> | Set<number>) {
|
||||
s = new Set<number>();
|
||||
s; // Set<number>
|
||||
if (s instanceof Promise) {
|
||||
s; // Set<number> & Promise<any>
|
||||
}
|
||||
s; // Set<number>
|
||||
s.add(42);
|
||||
}
|
||||
|
||||
function f3(s: Set<string> | Set<number>) {
|
||||
s; // Set<string> | Set<number>
|
||||
if (s instanceof Set) {
|
||||
s; // Set<string> | Set<number>
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
}
|
||||
}
|
||||
|
||||
function f4(s: Set<string> | Set<number>) {
|
||||
s = new Set<number>();
|
||||
s; // Set<number>
|
||||
if (s instanceof Set) {
|
||||
s; // Set<number>
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
}
|
||||
}
|
||||
|
||||
// More tests
|
||||
|
||||
class A { a: string }
|
||||
class B extends A { b: string }
|
||||
class C extends A { c: string }
|
||||
|
||||
function foo(x: A | undefined) {
|
||||
x; // A | undefined
|
||||
if (x instanceof B || x instanceof C) {
|
||||
x; // B | C
|
||||
}
|
||||
x; // A | undefined
|
||||
if (x instanceof B && x instanceof C) {
|
||||
x; // B & C
|
||||
}
|
||||
x; // A | undefined
|
||||
if (!x) {
|
||||
return;
|
||||
}
|
||||
x; // A
|
||||
if (x instanceof B) {
|
||||
x; // B
|
||||
if (x instanceof C) {
|
||||
x; // B & C
|
||||
}
|
||||
else {
|
||||
x; // B
|
||||
}
|
||||
x; // B
|
||||
}
|
||||
else {
|
||||
x; // A
|
||||
}
|
||||
x; // A
|
||||
}
|
||||
|
||||
// X is neither assignable to Y nor a subtype of Y
|
||||
// Y is assignable to X, but not a subtype of X
|
||||
|
||||
interface X {
|
||||
x?: string;
|
||||
}
|
||||
|
||||
class Y {
|
||||
y: string;
|
||||
}
|
||||
|
||||
function goo(x: X) {
|
||||
x;
|
||||
if (x instanceof Y) {
|
||||
x.y;
|
||||
}
|
||||
x;
|
||||
}
|
||||
|
||||
//// [controlFlowInstanceof.js]
|
||||
// Repros from #10167
|
||||
function f1(s) {
|
||||
s = new Set();
|
||||
s; // Set<number>
|
||||
if (s instanceof Set) {
|
||||
s; // Set<number>
|
||||
}
|
||||
s; // Set<number>
|
||||
s.add(42);
|
||||
}
|
||||
function f2(s) {
|
||||
s = new Set();
|
||||
s; // Set<number>
|
||||
if (s instanceof Promise) {
|
||||
s; // Set<number> & Promise<any>
|
||||
}
|
||||
s; // Set<number>
|
||||
s.add(42);
|
||||
}
|
||||
function f3(s) {
|
||||
s; // Set<string> | Set<number>
|
||||
if (s instanceof Set) {
|
||||
s; // Set<string> | Set<number>
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
}
|
||||
}
|
||||
function f4(s) {
|
||||
s = new Set();
|
||||
s; // Set<number>
|
||||
if (s instanceof Set) {
|
||||
s; // Set<number>
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
}
|
||||
}
|
||||
// More tests
|
||||
class A {
|
||||
}
|
||||
class B extends A {
|
||||
}
|
||||
class C extends A {
|
||||
}
|
||||
function foo(x) {
|
||||
x; // A | undefined
|
||||
if (x instanceof B || x instanceof C) {
|
||||
x; // B | C
|
||||
}
|
||||
x; // A | undefined
|
||||
if (x instanceof B && x instanceof C) {
|
||||
x; // B & C
|
||||
}
|
||||
x; // A | undefined
|
||||
if (!x) {
|
||||
return;
|
||||
}
|
||||
x; // A
|
||||
if (x instanceof B) {
|
||||
x; // B
|
||||
if (x instanceof C) {
|
||||
x; // B & C
|
||||
}
|
||||
else {
|
||||
x; // B
|
||||
}
|
||||
x; // B
|
||||
}
|
||||
else {
|
||||
x; // A
|
||||
}
|
||||
x; // A
|
||||
}
|
||||
class Y {
|
||||
}
|
||||
function goo(x) {
|
||||
x;
|
||||
if (x instanceof Y) {
|
||||
x.y;
|
||||
}
|
||||
x;
|
||||
}
|
232
tests/baselines/reference/controlFlowInstanceof.symbols
Normal file
232
tests/baselines/reference/controlFlowInstanceof.symbols
Normal file
|
@ -0,0 +1,232 @@
|
|||
=== tests/cases/compiler/controlFlowInstanceof.ts ===
|
||||
|
||||
// Repros from #10167
|
||||
|
||||
function f1(s: Set<string> | Set<number>) {
|
||||
>f1 : Symbol(f1, Decl(controlFlowInstanceof.ts, 0, 0))
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s = new Set<number>();
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
|
||||
if (s instanceof Set) {
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
}
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
|
||||
s.add(42);
|
||||
>s.add : Symbol(Set.add, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 3, 12))
|
||||
>add : Symbol(Set.add, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
}
|
||||
|
||||
function f2(s: Set<string> | Set<number>) {
|
||||
>f2 : Symbol(f2, Decl(controlFlowInstanceof.ts, 11, 1))
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s = new Set<number>();
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
|
||||
if (s instanceof Promise) {
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
>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, --, --))
|
||||
|
||||
s; // Set<number> & Promise<any>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
}
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
|
||||
s.add(42);
|
||||
>s.add : Symbol(Set.add, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 13, 12))
|
||||
>add : Symbol(Set.add, Decl(lib.es2015.collection.d.ts, --, --))
|
||||
}
|
||||
|
||||
function f3(s: Set<string> | Set<number>) {
|
||||
>f3 : Symbol(f3, Decl(controlFlowInstanceof.ts, 21, 1))
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 23, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<string> | Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 23, 12))
|
||||
|
||||
if (s instanceof Set) {
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 23, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<string> | Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 23, 12))
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 23, 12))
|
||||
}
|
||||
}
|
||||
|
||||
function f4(s: Set<string> | Set<number>) {
|
||||
>f4 : Symbol(f4, Decl(controlFlowInstanceof.ts, 31, 1))
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 33, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s = new Set<number>();
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 33, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 33, 12))
|
||||
|
||||
if (s instanceof Set) {
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 33, 12))
|
||||
>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --))
|
||||
|
||||
s; // Set<number>
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 33, 12))
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
>s : Symbol(s, Decl(controlFlowInstanceof.ts, 33, 12))
|
||||
}
|
||||
}
|
||||
|
||||
// More tests
|
||||
|
||||
class A { a: string }
|
||||
>A : Symbol(A, Decl(controlFlowInstanceof.ts, 42, 1))
|
||||
>a : Symbol(A.a, Decl(controlFlowInstanceof.ts, 46, 9))
|
||||
|
||||
class B extends A { b: string }
|
||||
>B : Symbol(B, Decl(controlFlowInstanceof.ts, 46, 21))
|
||||
>A : Symbol(A, Decl(controlFlowInstanceof.ts, 42, 1))
|
||||
>b : Symbol(B.b, Decl(controlFlowInstanceof.ts, 47, 19))
|
||||
|
||||
class C extends A { c: string }
|
||||
>C : Symbol(C, Decl(controlFlowInstanceof.ts, 47, 31))
|
||||
>A : Symbol(A, Decl(controlFlowInstanceof.ts, 42, 1))
|
||||
>c : Symbol(C.c, Decl(controlFlowInstanceof.ts, 48, 19))
|
||||
|
||||
function foo(x: A | undefined) {
|
||||
>foo : Symbol(foo, Decl(controlFlowInstanceof.ts, 48, 31))
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>A : Symbol(A, Decl(controlFlowInstanceof.ts, 42, 1))
|
||||
|
||||
x; // A | undefined
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
|
||||
if (x instanceof B || x instanceof C) {
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>B : Symbol(B, Decl(controlFlowInstanceof.ts, 46, 21))
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>C : Symbol(C, Decl(controlFlowInstanceof.ts, 47, 31))
|
||||
|
||||
x; // B | C
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
x; // A | undefined
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
|
||||
if (x instanceof B && x instanceof C) {
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>B : Symbol(B, Decl(controlFlowInstanceof.ts, 46, 21))
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>C : Symbol(C, Decl(controlFlowInstanceof.ts, 47, 31))
|
||||
|
||||
x; // B & C
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
x; // A | undefined
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
|
||||
if (!x) {
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
|
||||
return;
|
||||
}
|
||||
x; // A
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
|
||||
if (x instanceof B) {
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>B : Symbol(B, Decl(controlFlowInstanceof.ts, 46, 21))
|
||||
|
||||
x; // B
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
|
||||
if (x instanceof C) {
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
>C : Symbol(C, Decl(controlFlowInstanceof.ts, 47, 31))
|
||||
|
||||
x; // B & C
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
else {
|
||||
x; // B
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
x; // B
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
else {
|
||||
x; // A
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
x; // A
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 50, 13))
|
||||
}
|
||||
|
||||
// X is neither assignable to Y nor a subtype of Y
|
||||
// Y is assignable to X, but not a subtype of X
|
||||
|
||||
interface X {
|
||||
>X : Symbol(X, Decl(controlFlowInstanceof.ts, 78, 1))
|
||||
|
||||
x?: string;
|
||||
>x : Symbol(X.x, Decl(controlFlowInstanceof.ts, 83, 13))
|
||||
}
|
||||
|
||||
class Y {
|
||||
>Y : Symbol(Y, Decl(controlFlowInstanceof.ts, 85, 1))
|
||||
|
||||
y: string;
|
||||
>y : Symbol(Y.y, Decl(controlFlowInstanceof.ts, 87, 9))
|
||||
}
|
||||
|
||||
function goo(x: X) {
|
||||
>goo : Symbol(goo, Decl(controlFlowInstanceof.ts, 89, 1))
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
|
||||
>X : Symbol(X, Decl(controlFlowInstanceof.ts, 78, 1))
|
||||
|
||||
x;
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
|
||||
|
||||
if (x instanceof Y) {
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
|
||||
>Y : Symbol(Y, Decl(controlFlowInstanceof.ts, 85, 1))
|
||||
|
||||
x.y;
|
||||
>x.y : Symbol(Y.y, Decl(controlFlowInstanceof.ts, 87, 9))
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
|
||||
>y : Symbol(Y.y, Decl(controlFlowInstanceof.ts, 87, 9))
|
||||
}
|
||||
x;
|
||||
>x : Symbol(x, Decl(controlFlowInstanceof.ts, 91, 13))
|
||||
}
|
256
tests/baselines/reference/controlFlowInstanceof.types
Normal file
256
tests/baselines/reference/controlFlowInstanceof.types
Normal file
|
@ -0,0 +1,256 @@
|
|||
=== tests/cases/compiler/controlFlowInstanceof.ts ===
|
||||
|
||||
// Repros from #10167
|
||||
|
||||
function f1(s: Set<string> | Set<number>) {
|
||||
>f1 : (s: Set<string> | Set<number>) => void
|
||||
>s : Set<string> | Set<number>
|
||||
>Set : Set<T>
|
||||
>Set : Set<T>
|
||||
|
||||
s = new Set<number>();
|
||||
>s = new Set<number>() : Set<number>
|
||||
>s : Set<string> | Set<number>
|
||||
>new Set<number>() : Set<number>
|
||||
>Set : SetConstructor
|
||||
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
|
||||
if (s instanceof Set) {
|
||||
>s instanceof Set : boolean
|
||||
>s : Set<number>
|
||||
>Set : SetConstructor
|
||||
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
}
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
|
||||
s.add(42);
|
||||
>s.add(42) : Set<number>
|
||||
>s.add : (value: number) => Set<number>
|
||||
>s : Set<number>
|
||||
>add : (value: number) => Set<number>
|
||||
>42 : number
|
||||
}
|
||||
|
||||
function f2(s: Set<string> | Set<number>) {
|
||||
>f2 : (s: Set<string> | Set<number>) => void
|
||||
>s : Set<string> | Set<number>
|
||||
>Set : Set<T>
|
||||
>Set : Set<T>
|
||||
|
||||
s = new Set<number>();
|
||||
>s = new Set<number>() : Set<number>
|
||||
>s : Set<string> | Set<number>
|
||||
>new Set<number>() : Set<number>
|
||||
>Set : SetConstructor
|
||||
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
|
||||
if (s instanceof Promise) {
|
||||
>s instanceof Promise : boolean
|
||||
>s : Set<number>
|
||||
>Promise : PromiseConstructor
|
||||
|
||||
s; // Set<number> & Promise<any>
|
||||
>s : Set<number> & Promise<any>
|
||||
}
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
|
||||
s.add(42);
|
||||
>s.add(42) : Set<number>
|
||||
>s.add : (value: number) => Set<number>
|
||||
>s : Set<number>
|
||||
>add : (value: number) => Set<number>
|
||||
>42 : number
|
||||
}
|
||||
|
||||
function f3(s: Set<string> | Set<number>) {
|
||||
>f3 : (s: Set<string> | Set<number>) => void
|
||||
>s : Set<string> | Set<number>
|
||||
>Set : Set<T>
|
||||
>Set : Set<T>
|
||||
|
||||
s; // Set<string> | Set<number>
|
||||
>s : Set<string> | Set<number>
|
||||
|
||||
if (s instanceof Set) {
|
||||
>s instanceof Set : boolean
|
||||
>s : Set<string> | Set<number>
|
||||
>Set : SetConstructor
|
||||
|
||||
s; // Set<string> | Set<number>
|
||||
>s : Set<string> | Set<number>
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
>s : never
|
||||
}
|
||||
}
|
||||
|
||||
function f4(s: Set<string> | Set<number>) {
|
||||
>f4 : (s: Set<string> | Set<number>) => void
|
||||
>s : Set<string> | Set<number>
|
||||
>Set : Set<T>
|
||||
>Set : Set<T>
|
||||
|
||||
s = new Set<number>();
|
||||
>s = new Set<number>() : Set<number>
|
||||
>s : Set<string> | Set<number>
|
||||
>new Set<number>() : Set<number>
|
||||
>Set : SetConstructor
|
||||
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
|
||||
if (s instanceof Set) {
|
||||
>s instanceof Set : boolean
|
||||
>s : Set<number>
|
||||
>Set : SetConstructor
|
||||
|
||||
s; // Set<number>
|
||||
>s : Set<number>
|
||||
}
|
||||
else {
|
||||
s; // never
|
||||
>s : never
|
||||
}
|
||||
}
|
||||
|
||||
// More tests
|
||||
|
||||
class A { a: string }
|
||||
>A : A
|
||||
>a : string
|
||||
|
||||
class B extends A { b: string }
|
||||
>B : B
|
||||
>A : A
|
||||
>b : string
|
||||
|
||||
class C extends A { c: string }
|
||||
>C : C
|
||||
>A : A
|
||||
>c : string
|
||||
|
||||
function foo(x: A | undefined) {
|
||||
>foo : (x: A) => void
|
||||
>x : A
|
||||
>A : A
|
||||
|
||||
x; // A | undefined
|
||||
>x : A
|
||||
|
||||
if (x instanceof B || x instanceof C) {
|
||||
>x instanceof B || x instanceof C : boolean
|
||||
>x instanceof B : boolean
|
||||
>x : A
|
||||
>B : typeof B
|
||||
>x instanceof C : boolean
|
||||
>x : A
|
||||
>C : typeof C
|
||||
|
||||
x; // B | C
|
||||
>x : B | C
|
||||
}
|
||||
x; // A | undefined
|
||||
>x : A
|
||||
|
||||
if (x instanceof B && x instanceof C) {
|
||||
>x instanceof B && x instanceof C : boolean
|
||||
>x instanceof B : boolean
|
||||
>x : A
|
||||
>B : typeof B
|
||||
>x instanceof C : boolean
|
||||
>x : B
|
||||
>C : typeof C
|
||||
|
||||
x; // B & C
|
||||
>x : B & C
|
||||
}
|
||||
x; // A | undefined
|
||||
>x : A
|
||||
|
||||
if (!x) {
|
||||
>!x : boolean
|
||||
>x : A
|
||||
|
||||
return;
|
||||
}
|
||||
x; // A
|
||||
>x : A
|
||||
|
||||
if (x instanceof B) {
|
||||
>x instanceof B : boolean
|
||||
>x : A
|
||||
>B : typeof B
|
||||
|
||||
x; // B
|
||||
>x : B
|
||||
|
||||
if (x instanceof C) {
|
||||
>x instanceof C : boolean
|
||||
>x : B
|
||||
>C : typeof C
|
||||
|
||||
x; // B & C
|
||||
>x : B & C
|
||||
}
|
||||
else {
|
||||
x; // B
|
||||
>x : B
|
||||
}
|
||||
x; // B
|
||||
>x : B
|
||||
}
|
||||
else {
|
||||
x; // A
|
||||
>x : A
|
||||
}
|
||||
x; // A
|
||||
>x : A
|
||||
}
|
||||
|
||||
// X is neither assignable to Y nor a subtype of Y
|
||||
// Y is assignable to X, but not a subtype of X
|
||||
|
||||
interface X {
|
||||
>X : X
|
||||
|
||||
x?: string;
|
||||
>x : string
|
||||
}
|
||||
|
||||
class Y {
|
||||
>Y : Y
|
||||
|
||||
y: string;
|
||||
>y : string
|
||||
}
|
||||
|
||||
function goo(x: X) {
|
||||
>goo : (x: X) => void
|
||||
>x : X
|
||||
>X : X
|
||||
|
||||
x;
|
||||
>x : X
|
||||
|
||||
if (x instanceof Y) {
|
||||
>x instanceof Y : boolean
|
||||
>x : X
|
||||
>Y : typeof Y
|
||||
|
||||
x.y;
|
||||
>x.y : string
|
||||
>x : Y
|
||||
>y : string
|
||||
}
|
||||
x;
|
||||
>x : X
|
||||
}
|
36
tests/baselines/reference/derivedClasses.errors.txt
Normal file
36
tests/baselines/reference/derivedClasses.errors.txt
Normal file
|
@ -0,0 +1,36 @@
|
|||
tests/cases/compiler/derivedClasses.ts(1,19): error TS2690: A class must be declared after its base class.
|
||||
|
||||
|
||||
==== tests/cases/compiler/derivedClasses.ts (1 errors) ====
|
||||
class Red extends Color {
|
||||
~~~~~
|
||||
!!! error TS2690: A class must be declared after its base class.
|
||||
public shade() {
|
||||
var getHue = () => { return this.hue(); };
|
||||
return getHue() + " red";
|
||||
}
|
||||
}
|
||||
|
||||
class Color {
|
||||
public shade() { return "some shade"; }
|
||||
public hue() { return "some hue"; }
|
||||
}
|
||||
|
||||
class Blue extends Color {
|
||||
|
||||
public shade() {
|
||||
var getHue = () => { return this.hue(); };
|
||||
return getHue() + " blue";
|
||||
}
|
||||
}
|
||||
|
||||
var r = new Red();
|
||||
var b = new Blue();
|
||||
|
||||
r.shade();
|
||||
r.hue();
|
||||
b.shade();
|
||||
b.hue();
|
||||
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
=== tests/cases/compiler/derivedClasses.ts ===
|
||||
class Red extends Color {
|
||||
>Red : Symbol(Red, Decl(derivedClasses.ts, 0, 0))
|
||||
>Color : Symbol(Color, Decl(derivedClasses.ts, 5, 1))
|
||||
|
||||
public shade() {
|
||||
>shade : Symbol(Red.shade, Decl(derivedClasses.ts, 0, 25))
|
||||
|
||||
var getHue = () => { return this.hue(); };
|
||||
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 2, 8))
|
||||
>this.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
>this : Symbol(Red, Decl(derivedClasses.ts, 0, 0))
|
||||
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
|
||||
return getHue() + " red";
|
||||
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 2, 8))
|
||||
}
|
||||
}
|
||||
|
||||
class Color {
|
||||
>Color : Symbol(Color, Decl(derivedClasses.ts, 5, 1))
|
||||
|
||||
public shade() { return "some shade"; }
|
||||
>shade : Symbol(Color.shade, Decl(derivedClasses.ts, 7, 13))
|
||||
|
||||
public hue() { return "some hue"; }
|
||||
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
}
|
||||
|
||||
class Blue extends Color {
|
||||
>Blue : Symbol(Blue, Decl(derivedClasses.ts, 10, 1))
|
||||
>Color : Symbol(Color, Decl(derivedClasses.ts, 5, 1))
|
||||
|
||||
public shade() {
|
||||
>shade : Symbol(Blue.shade, Decl(derivedClasses.ts, 12, 26))
|
||||
|
||||
var getHue = () => { return this.hue(); };
|
||||
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 15, 8))
|
||||
>this.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
>this : Symbol(Blue, Decl(derivedClasses.ts, 10, 1))
|
||||
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
|
||||
return getHue() + " blue";
|
||||
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 15, 8))
|
||||
}
|
||||
}
|
||||
|
||||
var r = new Red();
|
||||
>r : Symbol(r, Decl(derivedClasses.ts, 20, 3))
|
||||
>Red : Symbol(Red, Decl(derivedClasses.ts, 0, 0))
|
||||
|
||||
var b = new Blue();
|
||||
>b : Symbol(b, Decl(derivedClasses.ts, 21, 3))
|
||||
>Blue : Symbol(Blue, Decl(derivedClasses.ts, 10, 1))
|
||||
|
||||
r.shade();
|
||||
>r.shade : Symbol(Red.shade, Decl(derivedClasses.ts, 0, 25))
|
||||
>r : Symbol(r, Decl(derivedClasses.ts, 20, 3))
|
||||
>shade : Symbol(Red.shade, Decl(derivedClasses.ts, 0, 25))
|
||||
|
||||
r.hue();
|
||||
>r.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
>r : Symbol(r, Decl(derivedClasses.ts, 20, 3))
|
||||
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
|
||||
b.shade();
|
||||
>b.shade : Symbol(Blue.shade, Decl(derivedClasses.ts, 12, 26))
|
||||
>b : Symbol(b, Decl(derivedClasses.ts, 21, 3))
|
||||
>shade : Symbol(Blue.shade, Decl(derivedClasses.ts, 12, 26))
|
||||
|
||||
b.hue();
|
||||
>b.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
>b : Symbol(b, Decl(derivedClasses.ts, 21, 3))
|
||||
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
|
||||
|
||||
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
=== tests/cases/compiler/derivedClasses.ts ===
|
||||
class Red extends Color {
|
||||
>Red : Red
|
||||
>Color : Color
|
||||
|
||||
public shade() {
|
||||
>shade : () => string
|
||||
|
||||
var getHue = () => { return this.hue(); };
|
||||
>getHue : () => string
|
||||
>() => { return this.hue(); } : () => string
|
||||
>this.hue() : string
|
||||
>this.hue : () => string
|
||||
>this : this
|
||||
>hue : () => string
|
||||
|
||||
return getHue() + " red";
|
||||
>getHue() + " red" : string
|
||||
>getHue() : string
|
||||
>getHue : () => string
|
||||
>" red" : string
|
||||
}
|
||||
}
|
||||
|
||||
class Color {
|
||||
>Color : Color
|
||||
|
||||
public shade() { return "some shade"; }
|
||||
>shade : () => string
|
||||
>"some shade" : string
|
||||
|
||||
public hue() { return "some hue"; }
|
||||
>hue : () => string
|
||||
>"some hue" : string
|
||||
}
|
||||
|
||||
class Blue extends Color {
|
||||
>Blue : Blue
|
||||
>Color : Color
|
||||
|
||||
public shade() {
|
||||
>shade : () => string
|
||||
|
||||
var getHue = () => { return this.hue(); };
|
||||
>getHue : () => string
|
||||
>() => { return this.hue(); } : () => string
|
||||
>this.hue() : string
|
||||
>this.hue : () => string
|
||||
>this : this
|
||||
>hue : () => string
|
||||
|
||||
return getHue() + " blue";
|
||||
>getHue() + " blue" : string
|
||||
>getHue() : string
|
||||
>getHue : () => string
|
||||
>" blue" : string
|
||||
}
|
||||
}
|
||||
|
||||
var r = new Red();
|
||||
>r : Red
|
||||
>new Red() : Red
|
||||
>Red : typeof Red
|
||||
|
||||
var b = new Blue();
|
||||
>b : Blue
|
||||
>new Blue() : Blue
|
||||
>Blue : typeof Blue
|
||||
|
||||
r.shade();
|
||||
>r.shade() : string
|
||||
>r.shade : () => string
|
||||
>r : Red
|
||||
>shade : () => string
|
||||
|
||||
r.hue();
|
||||
>r.hue() : string
|
||||
>r.hue : () => string
|
||||
>r : Red
|
||||
>hue : () => string
|
||||
|
||||
b.shade();
|
||||
>b.shade() : string
|
||||
>b.shade : () => string
|
||||
>b : Blue
|
||||
>shade : () => string
|
||||
|
||||
b.hue();
|
||||
>b.hue() : string
|
||||
>b.hue : () => string
|
||||
>b : Blue
|
||||
>hue : () => string
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
tests/cases/compiler/discriminantPropertyCheck.ts(30,9): error TS2532: Object is possibly 'undefined'.
|
||||
tests/cases/compiler/discriminantPropertyCheck.ts(66,9): error TS2532: Object is possibly 'undefined'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/discriminantPropertyCheck.ts (2 errors) ====
|
||||
|
||||
type Item = Item1 | Item2;
|
||||
|
||||
interface Base {
|
||||
bar: boolean;
|
||||
}
|
||||
|
||||
interface Item1 extends Base {
|
||||
kind: "A";
|
||||
foo: string | undefined;
|
||||
baz: boolean;
|
||||
qux: true;
|
||||
}
|
||||
|
||||
interface Item2 extends Base {
|
||||
kind: "B";
|
||||
foo: string | undefined;
|
||||
baz: boolean;
|
||||
qux: false;
|
||||
}
|
||||
|
||||
function goo1(x: Item) {
|
||||
if (x.kind === "A" && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function goo2(x: Item) {
|
||||
if (x.foo !== undefined && x.kind === "A") {
|
||||
x.foo.length; // Error, intervening discriminant guard
|
||||
~~~~~
|
||||
!!! error TS2532: Object is possibly 'undefined'.
|
||||
}
|
||||
}
|
||||
|
||||
function foo1(x: Item) {
|
||||
if (x.bar && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo2(x: Item) {
|
||||
if (x.foo !== undefined && x.bar) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo3(x: Item) {
|
||||
if (x.baz && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo4(x: Item) {
|
||||
if (x.foo !== undefined && x.baz) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo5(x: Item) {
|
||||
if (x.qux && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo6(x: Item) {
|
||||
if (x.foo !== undefined && x.qux) {
|
||||
x.foo.length; // Error, intervening discriminant guard
|
||||
~~~~~
|
||||
!!! error TS2532: Object is possibly 'undefined'.
|
||||
}
|
||||
}
|
111
tests/baselines/reference/discriminantPropertyCheck.js
Normal file
111
tests/baselines/reference/discriminantPropertyCheck.js
Normal file
|
@ -0,0 +1,111 @@
|
|||
//// [discriminantPropertyCheck.ts]
|
||||
|
||||
type Item = Item1 | Item2;
|
||||
|
||||
interface Base {
|
||||
bar: boolean;
|
||||
}
|
||||
|
||||
interface Item1 extends Base {
|
||||
kind: "A";
|
||||
foo: string | undefined;
|
||||
baz: boolean;
|
||||
qux: true;
|
||||
}
|
||||
|
||||
interface Item2 extends Base {
|
||||
kind: "B";
|
||||
foo: string | undefined;
|
||||
baz: boolean;
|
||||
qux: false;
|
||||
}
|
||||
|
||||
function goo1(x: Item) {
|
||||
if (x.kind === "A" && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function goo2(x: Item) {
|
||||
if (x.foo !== undefined && x.kind === "A") {
|
||||
x.foo.length; // Error, intervening discriminant guard
|
||||
}
|
||||
}
|
||||
|
||||
function foo1(x: Item) {
|
||||
if (x.bar && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo2(x: Item) {
|
||||
if (x.foo !== undefined && x.bar) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo3(x: Item) {
|
||||
if (x.baz && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo4(x: Item) {
|
||||
if (x.foo !== undefined && x.baz) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo5(x: Item) {
|
||||
if (x.qux && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
|
||||
function foo6(x: Item) {
|
||||
if (x.foo !== undefined && x.qux) {
|
||||
x.foo.length; // Error, intervening discriminant guard
|
||||
}
|
||||
}
|
||||
|
||||
//// [discriminantPropertyCheck.js]
|
||||
function goo1(x) {
|
||||
if (x.kind === "A" && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
function goo2(x) {
|
||||
if (x.foo !== undefined && x.kind === "A") {
|
||||
x.foo.length; // Error, intervening discriminant guard
|
||||
}
|
||||
}
|
||||
function foo1(x) {
|
||||
if (x.bar && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
function foo2(x) {
|
||||
if (x.foo !== undefined && x.bar) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
function foo3(x) {
|
||||
if (x.baz && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
function foo4(x) {
|
||||
if (x.foo !== undefined && x.baz) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
function foo5(x) {
|
||||
if (x.qux && x.foo !== undefined) {
|
||||
x.foo.length;
|
||||
}
|
||||
}
|
||||
function foo6(x) {
|
||||
if (x.foo !== undefined && x.qux) {
|
||||
x.foo.length; // Error, intervening discriminant guard
|
||||
}
|
||||
}
|
44
tests/baselines/reference/discriminantsAndNullOrUndefined.js
Normal file
44
tests/baselines/reference/discriminantsAndNullOrUndefined.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
//// [discriminantsAndNullOrUndefined.ts]
|
||||
|
||||
// Repro from #10228
|
||||
|
||||
interface A { kind: 'A'; }
|
||||
interface B { kind: 'B'; }
|
||||
|
||||
type C = A | B | undefined;
|
||||
|
||||
function never(_: never): never {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
function useA(_: A): void { }
|
||||
function useB(_: B): void { }
|
||||
|
||||
declare var c: C;
|
||||
|
||||
if (c !== undefined) {
|
||||
switch (c.kind) {
|
||||
case 'A': useA(c); break;
|
||||
case 'B': useB(c); break;
|
||||
default: never(c);
|
||||
}
|
||||
}
|
||||
|
||||
//// [discriminantsAndNullOrUndefined.js]
|
||||
// Repro from #10228
|
||||
function never(_) {
|
||||
throw new Error();
|
||||
}
|
||||
function useA(_) { }
|
||||
function useB(_) { }
|
||||
if (c !== undefined) {
|
||||
switch (c.kind) {
|
||||
case 'A':
|
||||
useA(c);
|
||||
break;
|
||||
case 'B':
|
||||
useB(c);
|
||||
break;
|
||||
default: never(c);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
=== tests/cases/compiler/discriminantsAndNullOrUndefined.ts ===
|
||||
|
||||
// Repro from #10228
|
||||
|
||||
interface A { kind: 'A'; }
|
||||
>A : Symbol(A, Decl(discriminantsAndNullOrUndefined.ts, 0, 0))
|
||||
>kind : Symbol(A.kind, Decl(discriminantsAndNullOrUndefined.ts, 3, 13))
|
||||
|
||||
interface B { kind: 'B'; }
|
||||
>B : Symbol(B, Decl(discriminantsAndNullOrUndefined.ts, 3, 26))
|
||||
>kind : Symbol(B.kind, Decl(discriminantsAndNullOrUndefined.ts, 4, 13))
|
||||
|
||||
type C = A | B | undefined;
|
||||
>C : Symbol(C, Decl(discriminantsAndNullOrUndefined.ts, 4, 26))
|
||||
>A : Symbol(A, Decl(discriminantsAndNullOrUndefined.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(discriminantsAndNullOrUndefined.ts, 3, 26))
|
||||
|
||||
function never(_: never): never {
|
||||
>never : Symbol(never, Decl(discriminantsAndNullOrUndefined.ts, 6, 27))
|
||||
>_ : Symbol(_, Decl(discriminantsAndNullOrUndefined.ts, 8, 15))
|
||||
|
||||
throw new Error();
|
||||
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
}
|
||||
|
||||
function useA(_: A): void { }
|
||||
>useA : Symbol(useA, Decl(discriminantsAndNullOrUndefined.ts, 10, 1))
|
||||
>_ : Symbol(_, Decl(discriminantsAndNullOrUndefined.ts, 12, 14))
|
||||
>A : Symbol(A, Decl(discriminantsAndNullOrUndefined.ts, 0, 0))
|
||||
|
||||
function useB(_: B): void { }
|
||||
>useB : Symbol(useB, Decl(discriminantsAndNullOrUndefined.ts, 12, 29))
|
||||
>_ : Symbol(_, Decl(discriminantsAndNullOrUndefined.ts, 13, 14))
|
||||
>B : Symbol(B, Decl(discriminantsAndNullOrUndefined.ts, 3, 26))
|
||||
|
||||
declare var c: C;
|
||||
>c : Symbol(c, Decl(discriminantsAndNullOrUndefined.ts, 15, 11))
|
||||
>C : Symbol(C, Decl(discriminantsAndNullOrUndefined.ts, 4, 26))
|
||||
|
||||
if (c !== undefined) {
|
||||
>c : Symbol(c, Decl(discriminantsAndNullOrUndefined.ts, 15, 11))
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
switch (c.kind) {
|
||||
>c.kind : Symbol(kind, Decl(discriminantsAndNullOrUndefined.ts, 3, 13), Decl(discriminantsAndNullOrUndefined.ts, 4, 13))
|
||||
>c : Symbol(c, Decl(discriminantsAndNullOrUndefined.ts, 15, 11))
|
||||
>kind : Symbol(kind, Decl(discriminantsAndNullOrUndefined.ts, 3, 13), Decl(discriminantsAndNullOrUndefined.ts, 4, 13))
|
||||
|
||||
case 'A': useA(c); break;
|
||||
>useA : Symbol(useA, Decl(discriminantsAndNullOrUndefined.ts, 10, 1))
|
||||
>c : Symbol(c, Decl(discriminantsAndNullOrUndefined.ts, 15, 11))
|
||||
|
||||
case 'B': useB(c); break;
|
||||
>useB : Symbol(useB, Decl(discriminantsAndNullOrUndefined.ts, 12, 29))
|
||||
>c : Symbol(c, Decl(discriminantsAndNullOrUndefined.ts, 15, 11))
|
||||
|
||||
default: never(c);
|
||||
>never : Symbol(never, Decl(discriminantsAndNullOrUndefined.ts, 6, 27))
|
||||
>c : Symbol(c, Decl(discriminantsAndNullOrUndefined.ts, 15, 11))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
=== tests/cases/compiler/discriminantsAndNullOrUndefined.ts ===
|
||||
|
||||
// Repro from #10228
|
||||
|
||||
interface A { kind: 'A'; }
|
||||
>A : A
|
||||
>kind : "A"
|
||||
|
||||
interface B { kind: 'B'; }
|
||||
>B : B
|
||||
>kind : "B"
|
||||
|
||||
type C = A | B | undefined;
|
||||
>C : C
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
function never(_: never): never {
|
||||
>never : (_: never) => never
|
||||
>_ : never
|
||||
|
||||
throw new Error();
|
||||
>new Error() : Error
|
||||
>Error : ErrorConstructor
|
||||
}
|
||||
|
||||
function useA(_: A): void { }
|
||||
>useA : (_: A) => void
|
||||
>_ : A
|
||||
>A : A
|
||||
|
||||
function useB(_: B): void { }
|
||||
>useB : (_: B) => void
|
||||
>_ : B
|
||||
>B : B
|
||||
|
||||
declare var c: C;
|
||||
>c : C
|
||||
>C : C
|
||||
|
||||
if (c !== undefined) {
|
||||
>c !== undefined : boolean
|
||||
>c : C
|
||||
>undefined : undefined
|
||||
|
||||
switch (c.kind) {
|
||||
>c.kind : "A" | "B"
|
||||
>c : A | B
|
||||
>kind : "A" | "B"
|
||||
|
||||
case 'A': useA(c); break;
|
||||
>'A' : "A"
|
||||
>useA(c) : void
|
||||
>useA : (_: A) => void
|
||||
>c : A
|
||||
|
||||
case 'B': useB(c); break;
|
||||
>'B' : "B"
|
||||
>useB(c) : void
|
||||
>useB : (_: B) => void
|
||||
>c : B
|
||||
|
||||
default: never(c);
|
||||
>never(c) : never
|
||||
>never : (_: never) => never
|
||||
>c : never
|
||||
}
|
||||
}
|
59
tests/baselines/reference/discriminantsAndTypePredicates.js
Normal file
59
tests/baselines/reference/discriminantsAndTypePredicates.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
//// [discriminantsAndTypePredicates.ts]
|
||||
// Repro from #10145
|
||||
|
||||
interface A { type: 'A' }
|
||||
interface B { type: 'B' }
|
||||
|
||||
function isA(x: A | B): x is A { return x.type === 'A'; }
|
||||
function isB(x: A | B): x is B { return x.type === 'B'; }
|
||||
|
||||
function foo1(x: A | B): any {
|
||||
x; // A | B
|
||||
if (isA(x)) {
|
||||
return x; // A
|
||||
}
|
||||
x; // B
|
||||
if (isB(x)) {
|
||||
return x; // B
|
||||
}
|
||||
x; // never
|
||||
}
|
||||
|
||||
function foo2(x: A | B): any {
|
||||
x; // A | B
|
||||
if (x.type === 'A') {
|
||||
return x; // A
|
||||
}
|
||||
x; // B
|
||||
if (x.type === 'B') {
|
||||
return x; // B
|
||||
}
|
||||
x; // never
|
||||
}
|
||||
|
||||
//// [discriminantsAndTypePredicates.js]
|
||||
// Repro from #10145
|
||||
function isA(x) { return x.type === 'A'; }
|
||||
function isB(x) { return x.type === 'B'; }
|
||||
function foo1(x) {
|
||||
x; // A | B
|
||||
if (isA(x)) {
|
||||
return x; // A
|
||||
}
|
||||
x; // B
|
||||
if (isB(x)) {
|
||||
return x; // B
|
||||
}
|
||||
x; // never
|
||||
}
|
||||
function foo2(x) {
|
||||
x; // A | B
|
||||
if (x.type === 'A') {
|
||||
return x; // A
|
||||
}
|
||||
x; // B
|
||||
if (x.type === 'B') {
|
||||
return x; // B
|
||||
}
|
||||
x; // never
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
=== tests/cases/compiler/discriminantsAndTypePredicates.ts ===
|
||||
// Repro from #10145
|
||||
|
||||
interface A { type: 'A' }
|
||||
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
|
||||
>type : Symbol(A.type, Decl(discriminantsAndTypePredicates.ts, 2, 13))
|
||||
|
||||
interface B { type: 'B' }
|
||||
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
|
||||
>type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
|
||||
function isA(x: A | B): x is A { return x.type === 'A'; }
|
||||
>isA : Symbol(isA, Decl(discriminantsAndTypePredicates.ts, 3, 25))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
|
||||
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
|
||||
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
|
||||
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 5, 13))
|
||||
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
|
||||
function isB(x: A | B): x is B { return x.type === 'B'; }
|
||||
>isB : Symbol(isB, Decl(discriminantsAndTypePredicates.ts, 5, 57))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
|
||||
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
|
||||
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
|
||||
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 6, 13))
|
||||
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
|
||||
function foo1(x: A | B): any {
|
||||
>foo1 : Symbol(foo1, Decl(discriminantsAndTypePredicates.ts, 6, 57))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
|
||||
|
||||
x; // A | B
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
|
||||
if (isA(x)) {
|
||||
>isA : Symbol(isA, Decl(discriminantsAndTypePredicates.ts, 3, 25))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
|
||||
return x; // A
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
}
|
||||
x; // B
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
|
||||
if (isB(x)) {
|
||||
>isB : Symbol(isB, Decl(discriminantsAndTypePredicates.ts, 5, 57))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
|
||||
return x; // B
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
}
|
||||
x; // never
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 8, 14))
|
||||
}
|
||||
|
||||
function foo2(x: A | B): any {
|
||||
>foo2 : Symbol(foo2, Decl(discriminantsAndTypePredicates.ts, 18, 1))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
>A : Symbol(A, Decl(discriminantsAndTypePredicates.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(discriminantsAndTypePredicates.ts, 2, 25))
|
||||
|
||||
x; // A | B
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
|
||||
if (x.type === 'A') {
|
||||
>x.type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
>type : Symbol(type, Decl(discriminantsAndTypePredicates.ts, 2, 13), Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
|
||||
return x; // A
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
}
|
||||
x; // B
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
|
||||
if (x.type === 'B') {
|
||||
>x.type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
>type : Symbol(B.type, Decl(discriminantsAndTypePredicates.ts, 3, 13))
|
||||
|
||||
return x; // B
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
}
|
||||
x; // never
|
||||
>x : Symbol(x, Decl(discriminantsAndTypePredicates.ts, 20, 14))
|
||||
}
|
104
tests/baselines/reference/discriminantsAndTypePredicates.types
Normal file
104
tests/baselines/reference/discriminantsAndTypePredicates.types
Normal file
|
@ -0,0 +1,104 @@
|
|||
=== tests/cases/compiler/discriminantsAndTypePredicates.ts ===
|
||||
// Repro from #10145
|
||||
|
||||
interface A { type: 'A' }
|
||||
>A : A
|
||||
>type : "A"
|
||||
|
||||
interface B { type: 'B' }
|
||||
>B : B
|
||||
>type : "B"
|
||||
|
||||
function isA(x: A | B): x is A { return x.type === 'A'; }
|
||||
>isA : (x: A | B) => x is A
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
>x : any
|
||||
>A : A
|
||||
>x.type === 'A' : boolean
|
||||
>x.type : "A" | "B"
|
||||
>x : A | B
|
||||
>type : "A" | "B"
|
||||
>'A' : "A"
|
||||
|
||||
function isB(x: A | B): x is B { return x.type === 'B'; }
|
||||
>isB : (x: A | B) => x is B
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
>x : any
|
||||
>B : B
|
||||
>x.type === 'B' : boolean
|
||||
>x.type : "A" | "B"
|
||||
>x : A | B
|
||||
>type : "A" | "B"
|
||||
>'B' : "B"
|
||||
|
||||
function foo1(x: A | B): any {
|
||||
>foo1 : (x: A | B) => any
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
x; // A | B
|
||||
>x : A | B
|
||||
|
||||
if (isA(x)) {
|
||||
>isA(x) : boolean
|
||||
>isA : (x: A | B) => x is A
|
||||
>x : A | B
|
||||
|
||||
return x; // A
|
||||
>x : A
|
||||
}
|
||||
x; // B
|
||||
>x : B
|
||||
|
||||
if (isB(x)) {
|
||||
>isB(x) : boolean
|
||||
>isB : (x: A | B) => x is B
|
||||
>x : B
|
||||
|
||||
return x; // B
|
||||
>x : B
|
||||
}
|
||||
x; // never
|
||||
>x : never
|
||||
}
|
||||
|
||||
function foo2(x: A | B): any {
|
||||
>foo2 : (x: A | B) => any
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
x; // A | B
|
||||
>x : A | B
|
||||
|
||||
if (x.type === 'A') {
|
||||
>x.type === 'A' : boolean
|
||||
>x.type : "A" | "B"
|
||||
>x : A | B
|
||||
>type : "A" | "B"
|
||||
>'A' : "A"
|
||||
|
||||
return x; // A
|
||||
>x : A
|
||||
}
|
||||
x; // B
|
||||
>x : B
|
||||
|
||||
if (x.type === 'B') {
|
||||
>x.type === 'B' : boolean
|
||||
>x.type : "B"
|
||||
>x : B
|
||||
>type : "B"
|
||||
>'B' : "B"
|
||||
|
||||
return x; // B
|
||||
>x : B
|
||||
}
|
||||
x; // never
|
||||
>x : never
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts(3,17): error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'.
|
||||
tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts(3,29): error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/emitCapturingThisInTupleDestructuring1.ts (2 errors) ====
|
||||
declare function wrapper(x: any);
|
||||
wrapper((array: [any]) => {
|
||||
[this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this"
|
||||
~~~~~~~~~~
|
||||
!!! error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2493: Tuple type '[any]' with length '1' cannot be assigned to tuple with length '3'.
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
//// [emitCapturingThisInTupleDestructuring1.ts]
|
||||
declare function wrapper(x: any);
|
||||
wrapper((array: [any]) => {
|
||||
[this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this"
|
||||
});
|
||||
|
||||
//// [emitCapturingThisInTupleDestructuring1.js]
|
||||
var _this = this;
|
||||
wrapper(function (array) {
|
||||
_this.test = array[0], _this.test1 = array[1], _this.test2 = array[2]; // even though there is a compiler error, we should still emit lexical capture for "this"
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts(8,39): error TS2493: Tuple type '[number, number]' with length '2' cannot be assigned to tuple with length '3'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/emitCapturingThisInTupleDestructuring2.ts (1 errors) ====
|
||||
var array1: [number, number] = [1, 2];
|
||||
|
||||
class B {
|
||||
test: number;
|
||||
test1: any;
|
||||
test2: any;
|
||||
method() {
|
||||
() => [this.test, this.test1, this.test2] = array1; // even though there is a compiler error, we should still emit lexical capture for "this"
|
||||
~~~~~~~~~~
|
||||
!!! error TS2493: Tuple type '[number, number]' with length '2' cannot be assigned to tuple with length '3'.
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//// [emitCapturingThisInTupleDestructuring2.ts]
|
||||
var array1: [number, number] = [1, 2];
|
||||
|
||||
class B {
|
||||
test: number;
|
||||
test1: any;
|
||||
test2: any;
|
||||
method() {
|
||||
() => [this.test, this.test1, this.test2] = array1; // even though there is a compiler error, we should still emit lexical capture for "this"
|
||||
}
|
||||
}
|
||||
|
||||
//// [emitCapturingThisInTupleDestructuring2.js]
|
||||
var array1 = [1, 2];
|
||||
var B = (function () {
|
||||
function B() {
|
||||
}
|
||||
B.prototype.method = function () {
|
||||
var _this = this;
|
||||
(function () { return (_this.test = array1[0], _this.test1 = array1[1], _this.test2 = array1[2], array1); }); // even though there is a compiler error, we should still emit lexical capture for "this"
|
||||
};
|
||||
return B;
|
||||
}());
|
|
@ -15,9 +15,9 @@ function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any
|
|||
>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16))
|
||||
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
|
||||
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
|
||||
>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
|
||||
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30))
|
||||
|
||||
};
|
||||
|
|
|
@ -18,10 +18,10 @@ function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any
|
|||
>apply : (this: Function, thisArg: any, argArray?: any) => any
|
||||
>this : any
|
||||
>[ this ].concat(args) : any[]
|
||||
>[ this ].concat : (...items: any[]) => any[]
|
||||
>[ this ].concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
|
||||
>[ this ] : any[]
|
||||
>this : any
|
||||
>concat : (...items: any[]) => any[]
|
||||
>concat : { (...items: any[][]): any[]; (...items: any[]): any[]; }
|
||||
>args : any[]
|
||||
|
||||
};
|
||||
|
|
9
tests/baselines/reference/exportToString.js
Normal file
9
tests/baselines/reference/exportToString.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
//// [exportToString.ts]
|
||||
const toString = 0;
|
||||
export { toString };
|
||||
|
||||
|
||||
//// [exportToString.js]
|
||||
"use strict";
|
||||
var toString = 0;
|
||||
exports.toString = toString;
|
7
tests/baselines/reference/exportToString.symbols
Normal file
7
tests/baselines/reference/exportToString.symbols
Normal file
|
@ -0,0 +1,7 @@
|
|||
=== tests/cases/compiler/exportToString.ts ===
|
||||
const toString = 0;
|
||||
>toString : Symbol(toString, Decl(exportToString.ts, 0, 5))
|
||||
|
||||
export { toString };
|
||||
>toString : Symbol(toString, Decl(exportToString.ts, 1, 8))
|
||||
|
8
tests/baselines/reference/exportToString.types
Normal file
8
tests/baselines/reference/exportToString.types
Normal file
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/exportToString.ts ===
|
||||
const toString = 0;
|
||||
>toString : number
|
||||
>0 : number
|
||||
|
||||
export { toString };
|
||||
>toString : number
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue