diff --git a/Gulpfile.ts b/Gulpfile.ts index ebedfd43c23..d7e20a557fd 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -128,7 +128,8 @@ const es2016LibrarySourceMap = es2016LibrarySource.map(function(source) { const es2017LibrarySource = [ "es2017.object.d.ts", - "es2017.sharedmemory.d.ts" + "es2017.sharedmemory.d.ts", + "es2017.string.d.ts", ]; const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) { diff --git a/Jakefile.js b/Jakefile.js index fc2b6359355..2e5d660c4f1 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -71,6 +71,7 @@ var compilerSources = [ "transformers/destructuring.ts", "transformers/ts.ts", "transformers/jsx.ts", + "transformers/esnext.ts", "transformers/es2017.ts", "transformers/es2016.ts", "transformers/es2015.ts", @@ -107,6 +108,7 @@ var servicesSources = [ "transformers/destructuring.ts", "transformers/ts.ts", "transformers/jsx.ts", + "transformers/esnext.ts", "transformers/es2017.ts", "transformers/es2016.ts", "transformers/es2015.ts", @@ -301,7 +303,8 @@ var es2016LibrarySourceMap = es2016LibrarySource.map(function (source) { var es2017LibrarySource = [ "es2017.object.d.ts", - "es2017.sharedmemory.d.ts" + "es2017.sharedmemory.d.ts", + "es2017.string.d.ts", ]; var es2017LibrarySourceMap = es2017LibrarySource.map(function (source) { diff --git a/package.json b/package.json index 3bf9dbcff7b..ed77c9bd35f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "2.1.0", + "version": "2.2.0", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 112a53e88ec..3e65b547d5b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1139,8 +1139,8 @@ namespace ts { } else if (node.kind === SyntaxKind.ArrayLiteralExpression) { for (const e of (node).elements) { - if (e.kind === SyntaxKind.SpreadElementExpression) { - bindAssignmentTargetFlow((e).expression); + if (e.kind === SyntaxKind.SpreadElement) { + bindAssignmentTargetFlow((e).expression); } else { bindDestructuringTargetFlow(e); @@ -1155,6 +1155,9 @@ namespace ts { else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) { bindAssignmentTargetFlow((p).name); } + else if (p.kind === SyntaxKind.SpreadAssignment) { + bindAssignmentTargetFlow((p).expression); + } } } } @@ -1550,7 +1553,7 @@ namespace ts { const seen = createMap(); for (const prop of node.properties) { - if (prop.name.kind !== SyntaxKind.Identifier) { + if (prop.kind === SyntaxKind.SpreadAssignment || prop.name.kind !== SyntaxKind.Identifier) { continue; } @@ -1916,6 +1919,9 @@ namespace ts { return bindParameter(node); case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: + if ((node as BindingElement).dotDotDotToken && node.parent.kind === SyntaxKind.ObjectBindingPattern) { + emitFlags |= NodeFlags.HasRestAttribute; + } return bindVariableDeclarationOrBindingElement(node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -1929,8 +1935,21 @@ namespace ts { case SyntaxKind.EnumMember: return bindPropertyOrMethodOrAccessor(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); + case SyntaxKind.SpreadAssignment: case SyntaxKind.JsxSpreadAttribute: - emitFlags |= NodeFlags.HasJsxSpreadAttributes; + let root = container; + let hasRest = false; + while (root.parent) { + if (root.kind === SyntaxKind.ObjectLiteralExpression && + root.parent.kind === SyntaxKind.BinaryExpression && + (root.parent as BinaryExpression).operatorToken.kind === SyntaxKind.EqualsToken && + (root.parent as BinaryExpression).left === root) { + hasRest = true; + break; + } + root = root.parent; + } + emitFlags |= hasRest ? NodeFlags.HasRestAttribute : NodeFlags.HasSpreadAttribute; return; case SyntaxKind.CallSignature: @@ -2495,9 +2514,9 @@ namespace ts { transformFlags |= TransformFlags.AssertTypeScript; } - if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression + if (subtreeFlags & TransformFlags.ContainsSpreadExpression || isSuperOrSuperProperty(expression, expressionKind)) { - // If the this node contains a SpreadElementExpression, or is a super call, then it is an ES6 + // If the this node contains a SpreadExpression, or is a super call, then it is an ES6 // node. transformFlags |= TransformFlags.AssertES2015; } @@ -2526,7 +2545,7 @@ namespace ts { if (node.typeArguments) { transformFlags |= TransformFlags.AssertTypeScript; } - if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression) { + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { // If the this node contains a SpreadElementExpression then it is an ES6 // node. transformFlags |= TransformFlags.AssertES2015; @@ -2541,10 +2560,13 @@ namespace ts { const operatorTokenKind = node.operatorToken.kind; const leftKind = node.left.kind; - if (operatorTokenKind === SyntaxKind.EqualsToken - && (leftKind === SyntaxKind.ObjectLiteralExpression - || leftKind === SyntaxKind.ArrayLiteralExpression)) { - // Destructuring assignments are ES6 syntax. + if (operatorTokenKind === SyntaxKind.EqualsToken && leftKind === SyntaxKind.ObjectLiteralExpression) { + // Destructuring object assignments with are ES2015 syntax + // and possibly ESNext if they contain rest + transformFlags |= TransformFlags.AssertESNext | TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment; + } + else if (operatorTokenKind === SyntaxKind.EqualsToken && leftKind === SyntaxKind.ArrayLiteralExpression) { + // Destructuring assignments are ES2015 syntax. transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment; } else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken @@ -2578,6 +2600,11 @@ namespace ts { transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.ContainsParameterPropertyAssignments; } + // parameters with object rest destructuring are ES Next syntax + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + transformFlags |= TransformFlags.AssertESNext; + } + // If a parameter has an initializer, a binding pattern or a dotDotDot token, then // it is ES6 syntax and its container must emit default value assignments or parameter destructuring downlevel. if (subtreeFlags & TransformFlags.ContainsBindingPattern || initializer || dotDotDotToken) { @@ -2811,6 +2838,11 @@ namespace ts { transformFlags |= TransformFlags.AssertES2017; } + // function declarations with object rest destructuring are ES Next syntax + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + transformFlags |= TransformFlags.AssertESNext; + } + // If a FunctionDeclaration's subtree has marked the container as needing to capture the // lexical this, or the function contains parameters with initializers, then this node is // ES6 syntax. @@ -2848,6 +2880,12 @@ namespace ts { transformFlags |= TransformFlags.AssertES2017; } + // function expressions with object rest destructuring are ES Next syntax + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + transformFlags |= TransformFlags.AssertESNext; + } + + // If a FunctionExpression's subtree has marked the container as needing to capture the // lexical this, or the function contains parameters with initializers, then this node is // ES6 syntax. @@ -2885,6 +2923,11 @@ namespace ts { transformFlags |= TransformFlags.AssertES2017; } + // arrow functions with object rest destructuring are ES Next syntax + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + transformFlags |= TransformFlags.AssertESNext; + } + // If an ArrowFunction contains a lexical this, its container must capture the lexical this. if (subtreeFlags & TransformFlags.ContainsLexicalThis) { transformFlags |= TransformFlags.ContainsCapturedLexicalThis; @@ -2913,8 +2956,13 @@ namespace ts { let transformFlags = subtreeFlags; const nameKind = node.name.kind; - // A VariableDeclaration with a binding pattern is ES6 syntax. - if (nameKind === SyntaxKind.ObjectBindingPattern || nameKind === SyntaxKind.ArrayBindingPattern) { + // A VariableDeclaration with an object binding pattern is ES2015 syntax + // and possibly ESNext syntax if it contains an object binding pattern + if (nameKind === SyntaxKind.ObjectBindingPattern) { + transformFlags |= TransformFlags.AssertESNext | TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern; + } + // A VariableDeclaration with an object binding pattern is ES2015 syntax. + else if (nameKind === SyntaxKind.ArrayBindingPattern) { transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern; } @@ -3055,6 +3103,10 @@ namespace ts { transformFlags |= TransformFlags.AssertJsx; break; + case SyntaxKind.ForOfStatement: + // for-of might be ESNext if it has a rest destructuring + transformFlags |= TransformFlags.AssertESNext; + // FALLTHROUGH case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.TemplateHead: case SyntaxKind.TemplateMiddle: @@ -3062,7 +3114,6 @@ namespace ts { case SyntaxKind.TemplateExpression: case SyntaxKind.TaggedTemplateExpression: case SyntaxKind.ShorthandPropertyAssignment: - case SyntaxKind.ForOfStatement: case SyntaxKind.StaticKeyword: // These nodes are ES6 syntax. transformFlags |= TransformFlags.AssertES2015; @@ -3126,11 +3177,18 @@ namespace ts { } break; - case SyntaxKind.SpreadElementExpression: - // This node is ES6 syntax, but is handled by a containing node. - transformFlags |= TransformFlags.ContainsSpreadElementExpression; + case SyntaxKind.SpreadElement: + case SyntaxKind.SpreadAssignment: + // This node is ES6 or ES next syntax, but is handled by a containing node. + transformFlags |= TransformFlags.ContainsSpreadExpression; break; + case SyntaxKind.BindingElement: + if ((node as BindingElement).dotDotDotToken) { + // this node is ES2015 or ES next syntax, but is handled by a containing node. + transformFlags |= TransformFlags.ContainsSpreadExpression; + } + case SyntaxKind.SuperKeyword: // This node is ES6 syntax. transformFlags |= TransformFlags.AssertES2015; @@ -3143,8 +3201,13 @@ namespace ts { case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: - // These nodes are ES6 syntax. - transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern; + // These nodes are ES2015 or ES Next syntax. + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + transformFlags |= TransformFlags.AssertESNext | TransformFlags.ContainsBindingPattern; + } + else { + transformFlags |= TransformFlags.AssertES2015 | TransformFlags.ContainsBindingPattern; + } break; case SyntaxKind.Decorator: @@ -3166,13 +3229,19 @@ namespace ts { transformFlags |= TransformFlags.ContainsLexicalThis; } + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + // If an ObjectLiteralExpression contains a spread element, then it + // is an ES next node. + transformFlags |= TransformFlags.AssertESNext; + } + break; case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.NewExpression: excludeFlags = TransformFlags.ArrayLiteralOrCallOrNewExcludes; - if (subtreeFlags & TransformFlags.ContainsSpreadElementExpression) { - // If the this node contains a SpreadElementExpression, then it is an ES6 + if (subtreeFlags & TransformFlags.ContainsSpreadExpression) { + // If the this node contains a SpreadExpression, then it is an ES6 // node. transformFlags |= TransformFlags.AssertES2015; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 878323a41b8..789f2bd8104 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -335,6 +335,9 @@ namespace ts { }); let jsxElementType: Type; + let _jsxNamespace: string; + let _jsxFactoryEntity: EntityName; + /** Things we lazy load from the JSX namespace */ const jsxTypes = createMap(); const JsxNames = { @@ -372,6 +375,22 @@ namespace ts { return checker; + function getJsxNamespace(): string { + if (_jsxNamespace === undefined) { + _jsxNamespace = "React"; + if (compilerOptions.jsxFactory) { + _jsxFactoryEntity = parseIsolatedEntityName(compilerOptions.jsxFactory, languageVersion); + if (_jsxFactoryEntity) { + _jsxNamespace = getFirstIdentifier(_jsxFactoryEntity).text; + } + } + else if (compilerOptions.reactNamespace) { + _jsxNamespace = compilerOptions.reactNamespace; + } + } + return _jsxNamespace; + } + function getEmitResolver(sourceFile: SourceFile, cancellationToken: CancellationToken) { // Ensure we have all the type information in place for this file so that all the // emitter questions of this resolver will return the right information. @@ -2494,6 +2513,13 @@ namespace ts { writePunctuation(writer, SyntaxKind.OpenBraceToken); writer.writeLine(); writer.increaseIndent(); + writeObjectLiteralType(resolved); + writer.decreaseIndent(); + writePunctuation(writer, SyntaxKind.CloseBraceToken); + inObjectTypeLiteral = saveInObjectTypeLiteral; + } + + function writeObjectLiteralType(resolved: ResolvedType) { for (const signature of resolved.callSignatures) { buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, /*kind*/ undefined, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); @@ -2526,11 +2552,8 @@ namespace ts { writer.writeLine(); } } - writer.decreaseIndent(); - writePunctuation(writer, SyntaxKind.CloseBraceToken); - inObjectTypeLiteral = saveInObjectTypeLiteral; } - } + } function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags) { const targetSymbol = getTargetSymbol(symbol); @@ -2972,26 +2995,31 @@ namespace ts { return symbol && getSymbolLinks(symbol).type || getTypeForVariableLikeDeclaration(node, /*includeOptionality*/ false); } - function getTextOfPropertyName(name: PropertyName): string { - switch (name.kind) { - case SyntaxKind.Identifier: - return (name).text; - case SyntaxKind.StringLiteral: - case SyntaxKind.NumericLiteral: - return (name).text; - case SyntaxKind.ComputedPropertyName: - if (isStringOrNumericLiteral((name).expression.kind)) { - return ((name).expression).text; - } - } - - return undefined; - } - function isComputedNonLiteralName(name: PropertyName): boolean { return name.kind === SyntaxKind.ComputedPropertyName && !isStringOrNumericLiteral((name).expression.kind); } + function getRestType(source: Type, properties: PropertyName[], symbol: Symbol): Type { + Debug.assert(!!(source.flags & TypeFlags.Object), "Rest types only support object types right now."); + const members = createMap(); + const names = createMap(); + for (const name of properties) { + names[getTextOfPropertyName(name)] = true; + } + for (const prop of getPropertiesOfType(source)) { + const inNamesToRemove = prop.name in names; + const isPrivate = getDeclarationModifierFlagsFromSymbol(prop) & (ModifierFlags.Private | ModifierFlags.Protected); + const isMethod = prop.flags & SymbolFlags.Method; + const isSetOnlyAccessor = prop.flags & SymbolFlags.SetAccessor && !(prop.flags & SymbolFlags.GetAccessor); + if (!inNamesToRemove && !isPrivate && !isMethod && !isSetOnlyAccessor) { + members[prop.name] = prop; + } + } + const stringIndexInfo = getIndexInfoOfType(source, IndexKind.String); + const numberIndexInfo = getIndexInfoOfType(source, IndexKind.Number); + return createAnonymousType(symbol, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + } + /** Return the inferred type for a binding element */ function getTypeForBindingElement(declaration: BindingElement): Type { const pattern = declaration.parent; @@ -3012,26 +3040,41 @@ namespace ts { let type: Type; if (pattern.kind === SyntaxKind.ObjectBindingPattern) { - // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - const name = declaration.propertyName || declaration.name; - if (isComputedNonLiteralName(name)) { - // computed properties with non-literal names are treated as 'any' - return anyType; - } - if (declaration.initializer) { - getContextualType(declaration.initializer); + if (declaration.dotDotDotToken) { + if (!(parentType.flags & TypeFlags.Object)) { + error(declaration, Diagnostics.Rest_types_may_only_be_created_from_object_types); + return unknownType; + } + const literalMembers: PropertyName[] = []; + for (const element of pattern.elements) { + if (element.kind !== SyntaxKind.OmittedExpression && !(element as BindingElement).dotDotDotToken) { + literalMembers.push(element.propertyName || element.name as Identifier); + } + } + type = getRestType(parentType, literalMembers, declaration.symbol); } + else { + // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) + const name = declaration.propertyName || declaration.name; + if (isComputedNonLiteralName(name)) { + // computed properties with non-literal names are treated as 'any' + return anyType; + } + if (declaration.initializer) { + getContextualType(declaration.initializer); + } - // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, - // or otherwise the type of the string index signature. - const text = getTextOfPropertyName(name); + // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, + // or otherwise the type of the string index signature. + const text = getTextOfPropertyName(name); - type = getTypeOfPropertyOfType(parentType, text) || - isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) || - getIndexTypeOfType(parentType, IndexKind.String); - if (!type) { - error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); - return unknownType; + type = getTypeOfPropertyOfType(parentType, text) || + isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) || + getIndexTypeOfType(parentType, IndexKind.String); + if (!type) { + error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); + return unknownType; + } } } else { @@ -3039,7 +3082,11 @@ namespace ts { // present (aka the tuple element property). This call also checks that the parentType is in // fact an iterable or array (depending on target language). const elementType = checkIteratedTypeOrElementType(parentType, pattern, /*allowStringInput*/ false); - if (!declaration.dotDotDotToken) { + if (declaration.dotDotDotToken) { + // Rest element has an array type with the same element type as the parent type + type = createArrayType(elementType); + } + else { // Use specific property type when parent is a tuple or numeric index type when parent is an array const propName = "" + indexOf(pattern.elements, declaration); type = isTupleLikeType(parentType) @@ -3055,10 +3102,6 @@ namespace ts { return unknownType; } } - else { - // Rest element has an array type with the same element type as the parent type - type = createArrayType(elementType); - } } // In strict null checking mode, if a default value of a non-undefined type is specified, remove // undefined from the final type. @@ -3239,8 +3282,8 @@ namespace ts { let hasComputedProperties = false; forEach(pattern.elements, e => { const name = e.propertyName || e.name; - if (isComputedNonLiteralName(name)) { - // do not include computed properties in the implied type + if (isComputedNonLiteralName(name) || e.dotDotDotToken) { + // do not include computed properties or rests in the implied type hasComputedProperties = true; return; } @@ -4337,6 +4380,11 @@ namespace ts { getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly); } + function unionSpreadIndexInfos(info1: IndexInfo, info2: IndexInfo): IndexInfo { + return info1 && info2 && createIndexInfo( + getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly); + } + function resolveIntersectionTypeMembers(type: IntersectionType) { // The members and properties collections are empty for intersection types. To get all properties of an // intersection type use getPropertiesOfType (only the language service uses this). @@ -4473,7 +4521,9 @@ namespace ts { function getPropertiesOfType(type: Type): Symbol[] { type = getApparentType(type); - return type.flags & TypeFlags.UnionOrIntersection ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); + return type.flags & TypeFlags.UnionOrIntersection ? + getPropertiesOfUnionOrIntersectionType(type) : + getPropertiesOfObjectType(type); } /** @@ -4528,6 +4578,7 @@ namespace ts { if (isReadonlySymbol(prop)) { isReadonly = true; } + } else if (containingType.flags & TypeFlags.Union) { isPartial = true; @@ -5860,6 +5911,68 @@ namespace ts { return links.resolvedType; } + /** + * Since the source of spread types are object literals, which are not binary, + * this function should be called in a left folding style, with left = previous result of getSpreadType + * and right = the new element to be spread. + */ + function getSpreadType(left: Type, right: Type, isFromObjectLiteral: boolean): ResolvedType | IntrinsicType { + Debug.assert(!!(left.flags & (TypeFlags.Object | TypeFlags.Any)) && !!(right.flags & (TypeFlags.Object | TypeFlags.Any)), "Only object types may be spread."); + if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) { + return anyType; + } + const members = createMap(); + const skippedPrivateMembers = createMap(); + let stringIndexInfo: IndexInfo; + let numberIndexInfo: IndexInfo; + if (left === emptyObjectType) { + // for the first spread element, left === emptyObjectType, so take the right's string indexer + stringIndexInfo = getIndexInfoOfType(right, IndexKind.String); + numberIndexInfo = getIndexInfoOfType(right, IndexKind.Number); + } + else { + stringIndexInfo = unionSpreadIndexInfos(getIndexInfoOfType(left, IndexKind.String), getIndexInfoOfType(right, IndexKind.String)); + numberIndexInfo = unionSpreadIndexInfos(getIndexInfoOfType(left, IndexKind.Number), getIndexInfoOfType(right, IndexKind.Number)); + } + + for (const rightProp of getPropertiesOfType(right)) { + // we approximate own properties as non-methods plus methods that are inside the object literal + const isOwnProperty = !(rightProp.flags & SymbolFlags.Method) || isFromObjectLiteral; + const isSetterWithoutGetter = rightProp.flags & SymbolFlags.SetAccessor && !(rightProp.flags & SymbolFlags.GetAccessor); + if (getDeclarationModifierFlagsFromSymbol(rightProp) & (ModifierFlags.Private | ModifierFlags.Protected)) { + skippedPrivateMembers[rightProp.name] = true; + } + else if (isOwnProperty && !isSetterWithoutGetter) { + members[rightProp.name] = rightProp; + } + } + for (const leftProp of getPropertiesOfType(left)) { + if (leftProp.flags & SymbolFlags.SetAccessor && !(leftProp.flags & SymbolFlags.GetAccessor) + || leftProp.name in skippedPrivateMembers) { + continue; + } + if (leftProp.name in members) { + const rightProp = members[leftProp.name]; + const rightType = getTypeOfSymbol(rightProp); + if (maybeTypeOfKind(rightType, TypeFlags.Undefined) || rightProp.flags & SymbolFlags.Optional) { + const declarations: Declaration[] = concatenate(leftProp.declarations, rightProp.declarations); + const flags = SymbolFlags.Property | SymbolFlags.Transient | (leftProp.flags & SymbolFlags.Optional); + const result = createSymbol(flags, leftProp.name); + result.type = getUnionType([getTypeOfSymbol(leftProp), getTypeWithFacts(rightType, TypeFacts.NEUndefined)]); + result.leftSpread = leftProp; + result.rightSpread = rightProp; + result.declarations = declarations; + result.isReadonly = isReadonlySymbol(leftProp) || isReadonlySymbol(rightProp); + members[leftProp.name] = result; + } + } + else { + members[leftProp.name] = leftProp; + } + } + return createAnonymousType(undefined, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + } + function createLiteralType(flags: TypeFlags, text: string) { const type = createType(flags); type.text = text; @@ -6730,9 +6843,15 @@ namespace ts { } if (!message) { - message = relation === comparableRelation ? - Diagnostics.Type_0_is_not_comparable_to_type_1 : - Diagnostics.Type_0_is_not_assignable_to_type_1; + if (relation === comparableRelation) { + message = Diagnostics.Type_0_is_not_comparable_to_type_1; + } + else if (sourceType === targetType) { + message = Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated; + } + else { + message = Diagnostics.Type_0_is_not_assignable_to_type_1; + } } reportError(message, sourceType, targetType); @@ -8571,7 +8690,7 @@ namespace ts { unknownType; } - function getTypeOfDestructuredSpreadElement(type: Type) { + function getTypeOfDestructuredSpreadExpression(type: Type) { return createArrayType(checkIteratedTypeOrElementType(type, /*errorNode*/ undefined, /*allowStringInput*/ false) || unknownType); } @@ -8585,8 +8704,8 @@ namespace ts { return getTypeOfDestructuredArrayElement(getAssignedType(node), indexOf(node.elements, element)); } - function getAssignedTypeOfSpreadElement(node: SpreadElementExpression): Type { - return getTypeOfDestructuredSpreadElement(getAssignedType(node.parent)); + function getAssignedTypeOfSpreadExpression(node: SpreadElement): Type { + return getTypeOfDestructuredSpreadExpression(getAssignedType(node.parent)); } function getAssignedTypeOfPropertyAssignment(node: PropertyAssignment | ShorthandPropertyAssignment): Type { @@ -8610,8 +8729,8 @@ namespace ts { return undefinedType; case SyntaxKind.ArrayLiteralExpression: return getAssignedTypeOfArrayLiteralElement(parent, node); - case SyntaxKind.SpreadElementExpression: - return getAssignedTypeOfSpreadElement(parent); + case SyntaxKind.SpreadElement: + return getAssignedTypeOfSpreadExpression(parent); case SyntaxKind.PropertyAssignment: return getAssignedTypeOfPropertyAssignment(parent); case SyntaxKind.ShorthandPropertyAssignment: @@ -8627,7 +8746,7 @@ namespace ts { getTypeOfDestructuredProperty(parentType, node.propertyName || node.name) : !node.dotDotDotToken ? getTypeOfDestructuredArrayElement(parentType, indexOf(pattern.elements, node)) : - getTypeOfDestructuredSpreadElement(parentType); + getTypeOfDestructuredSpreadExpression(parentType); return getTypeWithDefault(type, node.initializer); } @@ -10642,7 +10761,7 @@ namespace ts { return mapper && mapper.context; } - function checkSpreadElementExpression(node: SpreadElementExpression, contextualMapper?: TypeMapper): Type { + function checkSpreadExpression(node: SpreadElement, contextualMapper?: TypeMapper): Type { // It is usually not safe to call checkExpressionCached if we can be contextually typing. // You can tell that we are contextually typing because of the contextualMapper parameter. // While it is true that a spread element can have a contextual type, it does not do anything @@ -10664,7 +10783,7 @@ namespace ts { const elementTypes: Type[] = []; const inDestructuringPattern = isAssignmentTarget(node); for (const e of elements) { - if (inDestructuringPattern && e.kind === SyntaxKind.SpreadElementExpression) { + if (inDestructuringPattern && e.kind === SyntaxKind.SpreadElement) { // Given the following situation: // var c: {}; // [...c] = ["", 0]; @@ -10677,7 +10796,7 @@ namespace ts { // get the contextual element type from it. So we do something similar to // getContextualTypeForElementExpression, which will crucially not error // if there is no index type / iterated type. - const restArrayType = checkExpression((e).expression, contextualMapper); + const restArrayType = checkExpression((e).expression, contextualMapper); const restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) || (languageVersion >= ScriptTarget.ES2015 ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined); if (restElementType) { @@ -10688,7 +10807,7 @@ namespace ts { const type = checkExpressionForMutableLocation(e, contextualMapper); elementTypes.push(type); } - hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElementExpression; + hasSpreadElement = hasSpreadElement || e.kind === SyntaxKind.SpreadElement; } if (!hasSpreadElement) { // If array literal is actually a destructuring pattern, mark it as an implied type. We do this such @@ -10805,8 +10924,11 @@ namespace ts { // Grammar checking checkGrammarObjectLiteralExpression(node, inDestructuringPattern); - const propertiesTable = createMap(); - const propertiesArray: Symbol[] = []; + let propertiesTable = createMap(); + let propertiesArray: Symbol[] = []; + let spread: Type = emptyObjectType; + let propagatedFlags: TypeFlags = 0; + const contextualType = getApparentTypeOfContextualType(node); const contextualTypeHasPattern = contextualType && contextualType.pattern && (contextualType.pattern.kind === SyntaxKind.ObjectBindingPattern || contextualType.pattern.kind === SyntaxKind.ObjectLiteralExpression); @@ -10831,6 +10953,7 @@ namespace ts { Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); type = checkExpressionForMutableLocation((memberDecl).name, contextualMapper); } + typeFlags |= type.flags; const prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name); if (inDestructuringPattern) { @@ -10868,6 +10991,23 @@ namespace ts { prop.target = member; member = prop; } + else if (memberDecl.kind === SyntaxKind.SpreadAssignment) { + if (propertiesArray.length > 0) { + spread = getSpreadType(spread, createObjectLiteralType(), /*isFromObjectLiteral*/ true); + propertiesArray = []; + propertiesTable = createMap(); + hasComputedStringProperty = false; + hasComputedNumberProperty = false; + typeFlags = 0; + } + const type = checkExpression((memberDecl as SpreadAssignment).expression); + if (!(type.flags & (TypeFlags.Object | TypeFlags.Any))) { + error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types); + return unknownType; + } + spread = getSpreadType(spread, type, /*isFromObjectLiteral*/ false); + continue; + } else { // TypeScript 1.0 spec (April 2014) // A get accessor declaration is processed in the same manner as @@ -10907,20 +11047,36 @@ namespace ts { } } - const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined; - const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined; - const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); - const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral; - result.flags |= TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags); - result.objectFlags |= ObjectFlags.ObjectLiteral; - if (patternWithComputedProperties) { - result.objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties; + if (spread !== emptyObjectType) { + if (propertiesArray.length > 0) { + spread = getSpreadType(spread, createObjectLiteralType(), /*isFromObjectLiteral*/ true); + } + spread.flags |= propagatedFlags; + spread.symbol = node.symbol; + return spread; } - if (inDestructuringPattern) { - result.pattern = node; + + return createObjectLiteralType(); + + function createObjectLiteralType() { + const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined; + const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined; + const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral; + result.flags |= TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags); + result.objectFlags |= ObjectFlags.ObjectLiteral; + if (patternWithComputedProperties) { + result.objectFlags |= ObjectFlags.ObjectLiteralPatternWithComputedProperties; + } + if (inDestructuringPattern) { + result.pattern = node; + } + if (!(result.flags & TypeFlags.Nullable)) { + propagatedFlags |= (result.flags & TypeFlags.PropagatingFlags); + } + return result; } - return result; - } + } function checkJsxSelfClosingElement(node: JsxSelfClosingElement) { checkJsxOpeningLikeElement(node); @@ -11337,10 +11493,10 @@ namespace ts { function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) { checkGrammarJsxElement(node); checkJsxPreconditions(node); - // The reactNamespace symbol should be marked as 'used' so we don't incorrectly elide its import. And if there - // is no reactNamespace symbol in scope when targeting React emit, we should issue an error. + // The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import. + // And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error. const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; - const reactNamespace = compilerOptions.reactNamespace ? compilerOptions.reactNamespace : "React"; + const reactNamespace = getJsxNamespace(); const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace); if (reactSym) { // Mark local symbol as referenced here because it might not have been marked @@ -11819,7 +11975,7 @@ namespace ts { function getSpreadArgumentIndex(args: Expression[]): number { for (let i = 0; i < args.length; i++) { const arg = args[i]; - if (arg && arg.kind === SyntaxKind.SpreadElementExpression) { + if (arg && arg.kind === SyntaxKind.SpreadElement) { return i; } } @@ -13785,6 +13941,11 @@ namespace ts { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(objectLiteralType), declarationNameToString(name)); } } + else if (property.kind === SyntaxKind.SpreadAssignment) { + if (property.expression.kind !== SyntaxKind.Identifier) { + error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier); + } + } else { error(property, Diagnostics.Property_assignment_expected); } @@ -13807,7 +13968,7 @@ namespace ts { const elements = node.elements; const element = elements[elementIndex]; if (element.kind !== SyntaxKind.OmittedExpression) { - if (element.kind !== SyntaxKind.SpreadElementExpression) { + if (element.kind !== SyntaxKind.SpreadElement) { const propName = "" + elementIndex; const type = isTypeAny(sourceType) ? sourceType @@ -13831,10 +13992,10 @@ namespace ts { } else { if (elementIndex < elements.length - 1) { - error(element, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + error(element, Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern); } else { - const restExpression = (element).expression; + const restExpression = (element).expression; if (restExpression.kind === SyntaxKind.BinaryExpression && (restExpression).operatorToken.kind === SyntaxKind.EqualsToken) { error((restExpression).operatorToken, Diagnostics.A_rest_element_cannot_have_an_initializer); } @@ -14467,8 +14628,8 @@ namespace ts { return checkBinaryExpression(node, contextualMapper); case SyntaxKind.ConditionalExpression: return checkConditionalExpression(node, contextualMapper); - case SyntaxKind.SpreadElementExpression: - return checkSpreadElementExpression(node, contextualMapper); + case SyntaxKind.SpreadElement: + return checkSpreadExpression(node, contextualMapper); case SyntaxKind.OmittedExpression: return undefinedWideningType; case SyntaxKind.YieldExpression: @@ -16980,6 +17141,7 @@ namespace ts { let hasDuplicateDefaultClause = false; const expressionType = checkExpression(node.expression); + const expressionIsLiteral = isLiteralType(expressionType); forEach(node.caseBlock.clauses, clause => { // Grammar check for duplicate default clauses, skip if we already report duplicate default clause if (clause.kind === SyntaxKind.DefaultClause && !hasDuplicateDefaultClause) { @@ -17000,10 +17162,16 @@ namespace ts { // TypeScript 1.0 spec (April 2014): 5.9 // In a 'switch' statement, each 'case' expression must be of a type that is comparable // to or from the type of the 'switch' expression. - const caseType = checkExpression(caseClause.expression); - if (!isTypeEqualityComparableTo(expressionType, caseType)) { + let caseType = checkExpression(caseClause.expression); + const caseIsLiteral = isLiteralType(caseType); + let comparedExpressionType = expressionType; + if (!caseIsLiteral || !expressionIsLiteral) { + caseType = caseIsLiteral ? getBaseTypeOfLiteralType(caseType) : caseType; + comparedExpressionType = getBaseTypeOfLiteralType(expressionType); + } + if (!isTypeEqualityComparableTo(comparedExpressionType, caseType)) { // expressionType is not comparable to caseType, try the reversed check and report errors if it fails - checkTypeComparableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); + checkTypeComparableTo(caseType, comparedExpressionType, caseClause.expression, /*headMessage*/ undefined); } } forEach(clause.statements, checkSourceElement); @@ -19108,6 +19276,10 @@ namespace ts { return symbols; } else if (symbol.flags & SymbolFlags.Transient) { + if ((symbol as SymbolLinks).leftSpread) { + const links = symbol as SymbolLinks; + return [links.leftSpread, links.rightSpread]; + } let target: Symbol; let next = symbol; while (next = getSymbolLinks(next).target) { @@ -19596,7 +19768,8 @@ namespace ts { getTypeReferenceDirectivesForEntityName, getTypeReferenceDirectivesForSymbol, isLiteralConstDeclaration, - writeLiteralConstValue + writeLiteralConstValue, + getJsxFactoryEntity: () => _jsxFactoryEntity }; // defined here to avoid outer scope pollution @@ -19808,9 +19981,13 @@ namespace ts { if (requestedExternalEmitHelpers & NodeFlags.HasClassExtends && languageVersion < ScriptTarget.ES2015) { verifyHelperSymbol(exports, "__extends", SymbolFlags.Value); } - if (requestedExternalEmitHelpers & NodeFlags.HasJsxSpreadAttributes && compilerOptions.jsx !== JsxEmit.Preserve) { + if (requestedExternalEmitHelpers & NodeFlags.HasSpreadAttribute && + (languageVersion < ScriptTarget.ESNext || compilerOptions.jsx === JsxEmit.React)) { verifyHelperSymbol(exports, "__assign", SymbolFlags.Value); } + if (languageVersion < ScriptTarget.ESNext && requestedExternalEmitHelpers & NodeFlags.HasRestAttribute) { + verifyHelperSymbol(exports, "__rest", SymbolFlags.Value); + } if (requestedExternalEmitHelpers & NodeFlags.HasDecorators) { verifyHelperSymbol(exports, "__decorate", SymbolFlags.Value); if (compilerOptions.emitDecoratorMetadata) { @@ -20371,7 +20548,6 @@ namespace ts { checkGrammarHeritageClause(heritageClause); } } - return false; } @@ -20419,6 +20595,9 @@ namespace ts { const GetOrSetAccessor = GetAccessor | SetAccessor; for (const prop of node.properties) { + if (prop.kind === SyntaxKind.SpreadAssignment) { + continue; + } const name = prop.name; if (name.kind === SyntaxKind.ComputedPropertyName) { // If the name is not a ComputedPropertyName, the grammar checking will skip it @@ -20722,7 +20901,7 @@ namespace ts { if (node.dotDotDotToken) { const elements = (node.parent).elements; if (node !== lastOrUndefined(elements)) { - return grammarErrorOnNode(node, Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern); + return grammarErrorOnNode(node, Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern); } if (node.name.kind === SyntaxKind.ArrayBindingPattern || node.name.kind === SyntaxKind.ObjectBindingPattern) { @@ -20730,7 +20909,7 @@ namespace ts { } if (node.initializer) { - // Error on equals token which immediate precedes the initializer + // Error on equals token which immediately precedes the initializer return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer); } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 50399fd5c38..df9c3c4abdd 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -77,6 +77,11 @@ namespace ts { type: "string", description: Diagnostics.Specify_the_object_invoked_for_createElement_and_spread_when_targeting_react_JSX_emit }, + { + name: "jsxFactory", + type: "string", + description: Diagnostics.Specify_the_JSX_factory_function_to_use_when_targeting_react_JSX_emit_e_g_React_createElement_or_h + }, { name: "listFiles", type: "boolean", @@ -265,6 +270,7 @@ namespace ts { "es2015": ScriptTarget.ES2015, "es2016": ScriptTarget.ES2016, "es2017": ScriptTarget.ES2017, + "esnext": ScriptTarget.ESNext, }), description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015, paramType: Diagnostics.VERSION, @@ -428,7 +434,8 @@ namespace ts { "es2015.symbol.wellknown": "lib.es2015.symbol.wellknown.d.ts", "es2016.array.include": "lib.es2016.array.include.d.ts", "es2017.object": "lib.es2017.object.d.ts", - "es2017.sharedmemory": "lib.es2017.sharedmemory.d.ts" + "es2017.sharedmemory": "lib.es2017.sharedmemory.d.ts", + "es2017.string": "lib.es2017.string.d.ts", }), }, description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9a353e6fb36..ce5e59e509c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1455,7 +1455,7 @@ "category": "Error", "code": 2461 }, - "A rest element must be last in an array destructuring pattern": { + "A rest element must be last in a destructuring pattern": { "category": "Error", "code": 2462 }, @@ -1983,6 +1983,18 @@ "category": "Error", "code": 2697 }, + "Spread types may only be created from object types.": { + "category": "Error", + "code": 2698 + }, + "Rest types may only be created from object types.": { + "category": "Error", + "code": 2700 + }, + "An object rest element must be an identifier.": { + "category": "Error", + "code": 2701 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -2381,6 +2393,10 @@ "category": "Error", "code": 5066 }, + "Invalid value for 'jsxFactory'. '{0}' is not a valid identifier or qualified-name.": { + "category": "Error", + "code": 5067 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -2897,6 +2913,10 @@ "category": "Message", "code": 6145 }, + "Specify the JSX factory function to use when targeting 'react' JSX emit, e.g. 'React.createElement' or 'h'.": { + "category": "Message", + "code": 6146 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 @@ -3162,5 +3182,9 @@ "Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": { "category": "Error", "code": 90009 + }, + "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated.": { + "category": "Error", + "code": 90010 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f29ef0f4cf1..fa0d44a695f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -42,6 +42,14 @@ var __assign = (this && this.__assign) || Object.assign || function(t) { return t; };`; + const restHelper = ` +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p)) + t[p] = s[p]; + return t; +};`; + // emit output for the __decorate helper function const decorateHelper = ` var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { @@ -226,6 +234,7 @@ const _super = (function (geti, seti) { let currentFileIdentifiers: Map; let extendsEmitted: boolean; let assignEmitted: boolean; + let restEmitted: boolean; let decorateEmitted: boolean; let paramEmitted: boolean; let awaiterEmitted: boolean; @@ -732,6 +741,8 @@ const _super = (function (geti, seti) { return emitPropertyAssignment(node); case SyntaxKind.ShorthandPropertyAssignment: return emitShorthandPropertyAssignment(node); + case SyntaxKind.SpreadAssignment: + return emitSpreadAssignment(node as SpreadAssignment); // Enum case SyntaxKind.EnumMember: @@ -822,8 +833,8 @@ const _super = (function (geti, seti) { return emitTemplateExpression(node); case SyntaxKind.YieldExpression: return emitYieldExpression(node); - case SyntaxKind.SpreadElementExpression: - return emitSpreadElementExpression(node); + case SyntaxKind.SpreadElement: + return emitSpreadExpression(node); case SyntaxKind.ClassExpression: return emitClassExpression(node); case SyntaxKind.OmittedExpression: @@ -1374,7 +1385,7 @@ const _super = (function (geti, seti) { emitExpressionWithPrefix(" ", node.expression); } - function emitSpreadElementExpression(node: SpreadElementExpression) { + function emitSpreadExpression(node: SpreadElement) { write("..."); emitExpression(node.expression); } @@ -2102,6 +2113,13 @@ const _super = (function (geti, seti) { } } + function emitSpreadAssignment(node: SpreadAssignment) { + if (node.expression) { + write("..."); + emitExpression(node.expression); + } + } + // // Enum // @@ -2205,11 +2223,19 @@ const _super = (function (geti, seti) { helpersEmitted = true; } - if (compilerOptions.jsx !== JsxEmit.Preserve && !assignEmitted && (node.flags & NodeFlags.HasJsxSpreadAttributes)) { + if ((languageVersion < ScriptTarget.ESNext || currentSourceFile.scriptKind === ScriptKind.JSX || currentSourceFile.scriptKind === ScriptKind.TSX) && + compilerOptions.jsx !== JsxEmit.Preserve && + !assignEmitted && + node.flags & NodeFlags.HasSpreadAttribute) { writeLines(assignHelper); assignEmitted = true; } + if (languageVersion < ScriptTarget.ESNext && !restEmitted && node.flags & NodeFlags.HasRestAttribute) { + writeLines(restHelper); + restEmitted = true; + } + if (!decorateEmitted && node.flags & NodeFlags.HasDecorators) { writeLines(decorateHelper); if (compilerOptions.emitDecoratorMetadata) { diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index c557e3514a5..e9935668676 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -692,12 +692,12 @@ namespace ts { } export function createSpread(expression: Expression, location?: TextRange) { - const node = createNode(SyntaxKind.SpreadElementExpression, location); + const node = createNode(SyntaxKind.SpreadElement, location); node.expression = parenthesizeExpressionForList(expression); return node; } - export function updateSpread(node: SpreadElementExpression, expression: Expression) { + export function updateSpread(node: SpreadElement, expression: Expression) { if (node.expression !== expression) { return updateNode(createSpread(expression, node), node); } @@ -1399,14 +1399,27 @@ namespace ts { return node; } - export function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression) { + export function createSpreadAssignment(expression: Expression, location?: TextRange) { + const node = createNode(SyntaxKind.SpreadAssignment, location); + node.expression = expression !== undefined ? parenthesizeExpressionForList(expression) : undefined; + return node; + } + + export function updateShorthandPropertyAssignment(node: ShorthandPropertyAssignment, name: Identifier, objectAssignmentInitializer: Expression) { if (node.name !== name || node.objectAssignmentInitializer !== objectAssignmentInitializer) { return updateNode(createShorthandPropertyAssignment(name, objectAssignmentInitializer, node), node); } return node; } - // Top-level nodes + export function updateSpreadAssignment(node: SpreadAssignment, expression: Expression) { + if (node.expression !== expression) { + return updateNode(createSpreadAssignment(expression, node), node); + } + return node; + } + + // Top-level nodes export function updateSourceFileNode(node: SourceFile, statements: Statement[]) { if (node.statements !== statements) { @@ -1628,7 +1641,34 @@ namespace ts { return react; } - export function createReactCreateElement(reactNamespace: string, tagName: Expression, props: Expression, children: Expression[], parentElement: JsxOpeningLikeElement, location: TextRange): LeftHandSideExpression { + function createJsxFactoryExpressionFromEntityName(jsxFactory: EntityName, parent: JsxOpeningLikeElement): Expression { + if (isQualifiedName(jsxFactory)) { + return createPropertyAccess( + createJsxFactoryExpressionFromEntityName( + jsxFactory.left, + parent + ), + setEmitFlags( + getMutableClone(jsxFactory.right), + EmitFlags.NoSourceMap + ) + ); + } + else { + return createReactNamespace(jsxFactory.text, parent); + } + } + + function createJsxFactoryExpression(jsxFactoryEntity: EntityName, reactNamespace: string, parent: JsxOpeningLikeElement): Expression { + return jsxFactoryEntity ? + createJsxFactoryExpressionFromEntityName(jsxFactoryEntity, parent) : + createPropertyAccess( + createReactNamespace(reactNamespace, parent), + "createElement" + ); + } + + export function createExpressionForJsxElement(jsxFactoryEntity: EntityName, reactNamespace: string, tagName: Expression, props: Expression, children: Expression[], parentElement: JsxOpeningLikeElement, location: TextRange): LeftHandSideExpression { const argumentsList = [tagName]; if (props) { argumentsList.push(props); @@ -1651,10 +1691,7 @@ namespace ts { } return createCall( - createPropertyAccess( - createReactNamespace(reactNamespace, parentElement), - "createElement" - ), + createJsxFactoryExpression(jsxFactoryEntity, reactNamespace, parentElement), /*typeArguments*/ undefined, argumentsList, location @@ -3055,4 +3092,538 @@ namespace ts { function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) { return tryGetModuleNameFromFile(resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions); } + + /** + * Transforms the body of a function-like node. + * + * @param node A function-like node. + */ + export function transformFunctionBody(node: FunctionLikeDeclaration, + visitor: (node: Node) => VisitResult, + currentSourceFile: SourceFile, + context: TransformationContext, + enableSubstitutionsForCapturedThis: () => void, + convertObjectRest?: boolean) { + let multiLine = false; // indicates whether the block *must* be emitted as multiple lines + let singleLine = false; // indicates whether the block *may* be emitted as a single line + let statementsLocation: TextRange; + let closeBraceLocation: TextRange; + + const statements: Statement[] = []; + const body = node.body; + let statementOffset: number; + + context.startLexicalEnvironment(); + if (isBlock(body)) { + // ensureUseStrict is false because no new prologue-directive should be added. + // addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array + statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor); + } + + addCaptureThisForNodeIfNeeded(statements, node, enableSubstitutionsForCapturedThis); + addDefaultValueAssignmentsIfNeeded(statements, node, visitor, convertObjectRest); + addRestParameterIfNeeded(statements, node, /*inConstructorWithSynthesizedSuper*/ false); + + // If we added any generated statements, this must be a multi-line block. + if (!multiLine && statements.length > 0) { + multiLine = true; + } + + if (isBlock(body)) { + statementsLocation = body.statements; + addRange(statements, visitNodes(body.statements, visitor, isStatement, statementOffset)); + + // If the original body was a multi-line block, this must be a multi-line block. + if (!multiLine && body.multiLine) { + multiLine = true; + } + } + else { + Debug.assert(node.kind === SyntaxKind.ArrowFunction); + + // To align with the old emitter, we use a synthetic end position on the location + // for the statement list we synthesize when we down-level an arrow function with + // an expression function body. This prevents both comments and source maps from + // being emitted for the end position only. + statementsLocation = moveRangeEnd(body, -1); + + const equalsGreaterThanToken = (node).equalsGreaterThanToken; + if (!nodeIsSynthesized(equalsGreaterThanToken) && !nodeIsSynthesized(body)) { + if (rangeEndIsOnSameLineAsRangeStart(equalsGreaterThanToken, body, currentSourceFile)) { + singleLine = true; + } + else { + multiLine = true; + } + } + + const expression = visitNode(body, visitor, isExpression); + const returnStatement = createReturn(expression, /*location*/ body); + setEmitFlags(returnStatement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTrailingComments); + statements.push(returnStatement); + + // To align with the source map emit for the old emitter, we set a custom + // source map location for the close brace. + closeBraceLocation = body; + } + + const lexicalEnvironment = context.endLexicalEnvironment(); + addRange(statements, lexicalEnvironment); + + // If we added any final generated statements, this must be a multi-line block + if (!multiLine && lexicalEnvironment && lexicalEnvironment.length) { + multiLine = true; + } + + const block = createBlock(createNodeArray(statements, statementsLocation), node.body, multiLine); + if (!multiLine && singleLine) { + setEmitFlags(block, EmitFlags.SingleLine); + } + + if (closeBraceLocation) { + setTokenSourceMapRange(block, SyntaxKind.CloseBraceToken, closeBraceLocation); + } + + setOriginalNode(block, node.body); + return block; + } + + /** + * Adds a statement to capture the `this` of a function declaration if it is needed. + * + * @param statements The statements for the new function body. + * @param node A node. + */ + export function addCaptureThisForNodeIfNeeded(statements: Statement[], node: Node, enableSubstitutionsForCapturedThis: () => void): void { + if (node.transformFlags & TransformFlags.ContainsCapturedLexicalThis && node.kind !== SyntaxKind.ArrowFunction) { + captureThisForNode(statements, node, createThis(), enableSubstitutionsForCapturedThis); + } + } + + export function captureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined, enableSubstitutionsForCapturedThis?: () => void, originalStatement?: Statement): void { + enableSubstitutionsForCapturedThis(); + const captureThisStatement = createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + "_this", + /*type*/ undefined, + initializer + ) + ]), + originalStatement + ); + + setEmitFlags(captureThisStatement, EmitFlags.NoComments | EmitFlags.CustomPrologue); + setSourceMapRange(captureThisStatement, node); + statements.push(captureThisStatement); + } + + /** + * Gets a value indicating whether we need to add default value assignments for a + * function-like node. + * + * @param node A function-like node. + */ + function shouldAddDefaultValueAssignments(node: FunctionLikeDeclaration): boolean { + return (node.transformFlags & TransformFlags.ContainsDefaultValueAssignments) !== 0; + } + + /** + * Adds statements to the body of a function-like node if it contains parameters with + * binding patterns or initializers. + * + * @param statements The statements for the new function body. + * @param node A function-like node. + */ + export function addDefaultValueAssignmentsIfNeeded(statements: Statement[], + node: FunctionLikeDeclaration, + visitor: (node: Node) => VisitResult, + convertObjectRest: boolean): void { + if (!shouldAddDefaultValueAssignments(node)) { + return; + } + + for (const parameter of node.parameters) { + const { name, initializer, dotDotDotToken } = parameter; + + // A rest parameter cannot have a binding pattern or an initializer, + // so let's just ignore it. + if (dotDotDotToken) { + continue; + } + + if (isBindingPattern(name)) { + addDefaultValueAssignmentForBindingPattern(statements, parameter, name, initializer, visitor, convertObjectRest); + } + else if (initializer) { + addDefaultValueAssignmentForInitializer(statements, parameter, name, initializer, visitor); + } + } + } + + /** + * Adds statements to the body of a function-like node for parameters with binding patterns + * + * @param statements The statements for the new function body. + * @param parameter The parameter for the function. + * @param name The name of the parameter. + * @param initializer The initializer for the parameter. + */ + function addDefaultValueAssignmentForBindingPattern(statements: Statement[], + parameter: ParameterDeclaration, + name: BindingPattern, initializer: Expression, + visitor: (node: Node) => VisitResult, + convertObjectRest: boolean): void { + const temp = getGeneratedNameForNode(parameter); + + // In cases where a binding pattern is simply '[]' or '{}', + // we usually don't want to emit a var declaration; however, in the presence + // of an initializer, we must emit that expression to preserve side effects. + if (name.elements.length > 0) { + statements.push( + setEmitFlags( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList( + flattenParameterDestructuring(parameter, temp, visitor, convertObjectRest) + ) + ), + EmitFlags.CustomPrologue + ) + ); + } + else if (initializer) { + statements.push( + setEmitFlags( + createStatement( + createAssignment( + temp, + visitNode(initializer, visitor, isExpression) + ) + ), + EmitFlags.CustomPrologue + ) + ); + } + } + + /** + * Adds statements to the body of a function-like node for parameters with initializers. + * + * @param statements The statements for the new function body. + * @param parameter The parameter for the function. + * @param name The name of the parameter. + * @param initializer The initializer for the parameter. + */ + function addDefaultValueAssignmentForInitializer(statements: Statement[], + parameter: ParameterDeclaration, + name: Identifier, + initializer: Expression, + visitor: (node: Node) => VisitResult): void { + initializer = visitNode(initializer, visitor, isExpression); + const statement = createIf( + createStrictEquality( + getSynthesizedClone(name), + createVoidZero() + ), + setEmitFlags( + createBlock([ + createStatement( + createAssignment( + setEmitFlags(getMutableClone(name), EmitFlags.NoSourceMap), + setEmitFlags(initializer, EmitFlags.NoSourceMap | getEmitFlags(initializer)), + /*location*/ parameter + ) + ) + ], /*location*/ parameter), + EmitFlags.SingleLine | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTokenSourceMaps + ), + /*elseStatement*/ undefined, + /*location*/ parameter + ); + statement.startsOnNewLine = true; + setEmitFlags(statement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoTrailingSourceMap | EmitFlags.CustomPrologue); + statements.push(statement); + } + + /** + * Gets a value indicating whether we need to add statements to handle a rest parameter. + * + * @param node A ParameterDeclaration node. + * @param inConstructorWithSynthesizedSuper A value indicating whether the parameter is + * part of a constructor declaration with a + * synthesized call to `super` + */ + function shouldAddRestParameter(node: ParameterDeclaration, inConstructorWithSynthesizedSuper: boolean) { + return node && node.dotDotDotToken && node.name.kind === SyntaxKind.Identifier && !inConstructorWithSynthesizedSuper; + } + + /** + * Adds statements to the body of a function-like node if it contains a rest parameter. + * + * @param statements The statements for the new function body. + * @param node A function-like node. + * @param inConstructorWithSynthesizedSuper A value indicating whether the parameter is + * part of a constructor declaration with a + * synthesized call to `super` + */ + export function addRestParameterIfNeeded(statements: Statement[], node: FunctionLikeDeclaration, inConstructorWithSynthesizedSuper: boolean): void { + const parameter = lastOrUndefined(node.parameters); + if (!shouldAddRestParameter(parameter, inConstructorWithSynthesizedSuper)) { + return; + } + + // `declarationName` is the name of the local declaration for the parameter. + const declarationName = getMutableClone(parameter.name); + setEmitFlags(declarationName, EmitFlags.NoSourceMap); + + // `expressionName` is the name of the parameter used in expressions. + const expressionName = getSynthesizedClone(parameter.name); + const restIndex = node.parameters.length - 1; + const temp = createLoopVariable(); + + // var param = []; + statements.push( + setEmitFlags( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + declarationName, + /*type*/ undefined, + createArrayLiteral([]) + ) + ]), + /*location*/ parameter + ), + EmitFlags.CustomPrologue + ) + ); + + // for (var _i = restIndex; _i < arguments.length; _i++) { + // param[_i - restIndex] = arguments[_i]; + // } + const forStatement = createFor( + createVariableDeclarationList([ + createVariableDeclaration(temp, /*type*/ undefined, createLiteral(restIndex)) + ], /*location*/ parameter), + createLessThan( + temp, + createPropertyAccess(createIdentifier("arguments"), "length"), + /*location*/ parameter + ), + createPostfixIncrement(temp, /*location*/ parameter), + createBlock([ + startOnNewLine( + createStatement( + createAssignment( + createElementAccess( + expressionName, + createSubtract(temp, createLiteral(restIndex)) + ), + createElementAccess(createIdentifier("arguments"), temp) + ), + /*location*/ parameter + ) + ) + ]) + ); + + setEmitFlags(forStatement, EmitFlags.CustomPrologue); + startOnNewLine(forStatement); + statements.push(forStatement); + } + + + + + export function convertForOf(node: ForOfStatement, convertedLoopBodyStatements: Statement[], + visitor: (node: Node) => VisitResult, + enableSubstitutionsForBlockScopedBindings: () => void, + context: TransformationContext, + convertObjectRest?: boolean): ForStatement | ForOfStatement { + // The following ES6 code: + // + // for (let v of expr) { } + // + // should be emitted as + // + // for (var _i = 0, _a = expr; _i < _a.length; _i++) { + // var v = _a[_i]; + // } + // + // where _a and _i are temps emitted to capture the RHS and the counter, + // respectively. + // When the left hand side is an expression instead of a let declaration, + // the "let v" is not emitted. + // When the left hand side is a let/const, the v is renamed if there is + // another v in scope. + // Note that all assignments to the LHS are emitted in the body, including + // all destructuring. + // Note also that because an extra statement is needed to assign to the LHS, + // for-of bodies are always emitted as blocks. + + const expression = visitNode(node.expression, visitor, isExpression); + const initializer = node.initializer; + const statements: Statement[] = []; + + // In the case where the user wrote an identifier as the RHS, like this: + // + // for (let v of arr) { } + // + // we don't want to emit a temporary variable for the RHS, just use it directly. + const counter = convertObjectRest ? undefined : createLoopVariable(); + const rhsReference = expression.kind === SyntaxKind.Identifier + ? createUniqueName((expression).text) + : createTempVariable(/*recordTempVariable*/ undefined); + const elementAccess = convertObjectRest ? rhsReference : createElementAccess(rhsReference, counter); + + // Initialize LHS + // var v = _a[_i]; + if (isVariableDeclarationList(initializer)) { + if (initializer.flags & NodeFlags.BlockScoped) { + enableSubstitutionsForBlockScopedBindings(); + } + + const firstOriginalDeclaration = firstOrUndefined(initializer.declarations); + if (firstOriginalDeclaration && isBindingPattern(firstOriginalDeclaration.name)) { + // This works whether the declaration is a var, let, or const. + // It will use rhsIterationValue _a[_i] as the initializer. + const declarations = flattenVariableDestructuring( + firstOriginalDeclaration, + elementAccess, + visitor, + /*recordTempVariable*/ undefined, + convertObjectRest + ); + + const declarationList = createVariableDeclarationList(declarations, /*location*/ initializer); + setOriginalNode(declarationList, initializer); + + // Adjust the source map range for the first declaration to align with the old + // emitter. + const firstDeclaration = declarations[0]; + const lastDeclaration = lastOrUndefined(declarations); + setSourceMapRange(declarationList, createRange(firstDeclaration.pos, lastDeclaration.end)); + + statements.push( + createVariableStatement( + /*modifiers*/ undefined, + declarationList + ) + ); + } + else { + // The following call does not include the initializer, so we have + // to emit it separately. + statements.push( + createVariableStatement( + /*modifiers*/ undefined, + setOriginalNode( + createVariableDeclarationList([ + createVariableDeclaration( + firstOriginalDeclaration ? firstOriginalDeclaration.name : createTempVariable(/*recordTempVariable*/ undefined), + /*type*/ undefined, + createElementAccess(rhsReference, counter) + ) + ], /*location*/ moveRangePos(initializer, -1)), + initializer + ), + /*location*/ moveRangeEnd(initializer, -1) + ) + ); + } + } + else { + // Initializer is an expression. Emit the expression in the body, so that it's + // evaluated on every iteration. + const assignment = createAssignment(initializer, elementAccess); + if (isDestructuringAssignment(assignment)) { + // This is a destructuring pattern, so we flatten the destructuring instead. + statements.push( + createStatement( + flattenDestructuringAssignment( + context, + assignment, + /*needsValue*/ false, + context.hoistVariableDeclaration, + visitor, + convertObjectRest + ) + ) + ); + } + else { + // Currently there is not way to check that assignment is binary expression of destructing assignment + // so we have to cast never type to binaryExpression + (assignment).end = initializer.end; + statements.push(createStatement(assignment, /*location*/ moveRangeEnd(initializer, -1))); + } + } + + let bodyLocation: TextRange; + let statementsLocation: TextRange; + if (convertedLoopBodyStatements) { + addRange(statements, convertedLoopBodyStatements); + } + else { + const statement = visitNode(node.statement, visitor, isStatement); + if (isBlock(statement)) { + addRange(statements, statement.statements); + bodyLocation = statement; + statementsLocation = statement.statements; + } + else { + statements.push(statement); + } + } + + // The old emitter does not emit source maps for the expression + setEmitFlags(expression, EmitFlags.NoSourceMap | getEmitFlags(expression)); + + // The old emitter does not emit source maps for the block. + // We add the location to preserve comments. + const body = createBlock( + createNodeArray(statements, /*location*/ statementsLocation), + /*location*/ bodyLocation + ); + + setEmitFlags(body, EmitFlags.NoSourceMap | EmitFlags.NoTokenSourceMaps); + + let forStatement: ForStatement | ForOfStatement; + if (convertObjectRest) { + forStatement = createForOf( + createVariableDeclarationList([ + createVariableDeclaration(rhsReference, /*type*/ undefined, /*initializer*/ undefined, /*location*/ node.expression) + ], /*location*/ node.expression), + node.expression, + body, + /*location*/ node + ); + } + else { + forStatement = createFor( + setEmitFlags( + createVariableDeclarationList([ + createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0), /*location*/ moveRangePos(node.expression, -1)), + createVariableDeclaration(rhsReference, /*type*/ undefined, expression, /*location*/ node.expression) + ], /*location*/ node.expression), + EmitFlags.NoHoisting + ), + createLessThan( + counter, + createPropertyAccess(rhsReference, "length"), + /*location*/ node.expression + ), + createPostfixIncrement(counter, /*location*/ node.expression), + body, + /*location*/ node + ); + } + + // Disable trailing source maps for the OpenParenToken to align source map emit with the old emitter. + setEmitFlags(forStatement, EmitFlags.NoTokenTrailingSourceMaps); + return forStatement; + } } diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 831a19c4000..045e90a6add 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -14,6 +14,11 @@ namespace ts { return compilerOptions.traceResolution && host.trace !== undefined; } + /** Array that is only intended to be pushed to, never read. */ + interface Push { + push(value: T): void; + } + /** * Result of trying to resolve a module. * At least one of `ts` and `js` should be defined, or the whole thing should be `undefined`. @@ -62,8 +67,7 @@ namespace ts { interface ModuleResolutionState { host: ModuleResolutionHost; - // We only use this subset of the compiler options. - compilerOptions: { rootDirs?: string[], baseUrl?: string, paths?: MapLike }; + compilerOptions: CompilerOptions; traceEnabled: boolean; } @@ -128,7 +132,9 @@ namespace ts { currentDirectory = host.getCurrentDirectory(); } - return currentDirectory !== undefined && getDefaultTypeRoots(currentDirectory, host); + if (currentDirectory !== undefined) { + return getDefaultTypeRoots(currentDirectory, host); + } } /** @@ -142,20 +148,12 @@ namespace ts { } let typeRoots: string[]; - - while (true) { - const atTypes = combinePaths(currentDirectory, nodeModulesAtTypes); + forEachAncestorDirectory(currentDirectory, directory => { + const atTypes = combinePaths(directory, nodeModulesAtTypes); if (host.directoryExists(atTypes)) { (typeRoots || (typeRoots = [])).push(atTypes); } - - const parent = getDirectoryPath(currentDirectory); - if (parent === currentDirectory) { - break; - } - currentDirectory = parent; - } - + }); return typeRoots; } const nodeModulesAtTypes = combinePaths("node_modules", "@types"); @@ -233,7 +231,7 @@ namespace ts { if (traceEnabled) { trace(host, Diagnostics.Looking_up_in_node_modules_folder_initial_location_0, initialLocationForSecondaryLookup); } - resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState, /*checkOneLevel*/ false)); + resolvedFile = resolvedTypeScriptOnly(loadModuleFromNodeModules(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, failedLookupLocations, moduleResolutionState)); if (traceEnabled) { if (resolvedFile) { trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFile, false); @@ -341,7 +339,7 @@ namespace ts { * 'typings' entry or file 'index' with some supported extension * - Classic loader will only try to interpret '/a/b/c' as file. */ - type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState) => Resolved | undefined; + type ResolutionKindSpecificLoader = (extensions: Extensions, candidate: string, failedLookupLocations: Push, onlyRecordFailures: boolean, state: ModuleResolutionState) => Resolved | undefined; /** * Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to @@ -404,7 +402,7 @@ namespace ts { * entries in 'rootDirs', use them to build absolute path out of (*) and try to resolve module from this location. */ function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, - failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined { + failedLookupLocations: Push, state: ModuleResolutionState): Resolved | undefined { if (moduleHasNonRelativeName(moduleName)) { return tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, failedLookupLocations, state); @@ -415,7 +413,7 @@ namespace ts { } function tryLoadModuleUsingRootDirs(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, - failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined { + failedLookupLocations: Push, state: ModuleResolutionState): Resolved | undefined { if (!state.compilerOptions.rootDirs) { return undefined; @@ -491,7 +489,7 @@ namespace ts { return undefined; } - function tryLoadModuleUsingBaseUrl(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined { + function tryLoadModuleUsingBaseUrl(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: Push, state: ModuleResolutionState): Resolved | undefined { if (!state.compilerOptions.baseUrl) { return undefined; } @@ -565,7 +563,7 @@ namespace ts { if (traceEnabled) { trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName); } - const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state, /*checkOneLevel*/ false); + const resolved = loadModuleFromNodeModules(extensions, moduleName, containingDirectory, failedLookupLocations, state); return resolved && { resolved, isExternalLibraryImport: true }; } else { @@ -588,7 +586,7 @@ namespace ts { return { path: real, extension: resolved.extension }; } - function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { + function nodeLoadModuleByRelativeName(extensions: Extensions, candidate: string, failedLookupLocations: Push, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { if (state.traceEnabled) { trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate); } @@ -607,7 +605,7 @@ namespace ts { * @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations. */ - function loadModuleFromFile(extensions: Extensions, candidate: string, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { + function loadModuleFromFile(extensions: Extensions, candidate: string, failedLookupLocations: Push, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { // First, try adding an extension. An import of "foo" could be matched by a file "foo.ts", or "foo.js" by "foo.js.ts" const resolvedByAddingExtension = tryAddingExtensions(candidate, extensions, failedLookupLocations, onlyRecordFailures, state); if (resolvedByAddingExtension) { @@ -627,7 +625,7 @@ namespace ts { } /** Try to return an existing file that adds one of the `extensions` to `candidate`. */ - function tryAddingExtensions(candidate: string, extensions: Extensions, failedLookupLocations: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { + function tryAddingExtensions(candidate: string, extensions: Extensions, failedLookupLocations: Push, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { if (!onlyRecordFailures) { // check if containing folder exists - if it doesn't then just record failures for all supported extensions without disk probing const directory = getDirectoryPath(candidate); @@ -652,7 +650,7 @@ namespace ts { } /** Return the file if it exists. */ - function tryFile(fileName: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { + function tryFile(fileName: string, failedLookupLocations: Push, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { if (!onlyRecordFailures && state.host.fileExists(fileName)) { if (state.traceEnabled) { trace(state.host, Diagnostics.File_0_exist_use_it_as_a_name_resolution_result, fileName); @@ -663,12 +661,12 @@ namespace ts { if (state.traceEnabled) { trace(state.host, Diagnostics.File_0_does_not_exist, fileName); } - failedLookupLocation.push(fileName); + failedLookupLocations.push(fileName); return undefined; } } - function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { + function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, failedLookupLocations: Push, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { const packageJsonPath = pathToPackageJson(candidate); const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host); @@ -680,12 +678,12 @@ namespace ts { if (typesFile) { const onlyRecordFailures = !directoryProbablyExists(getDirectoryPath(typesFile), state.host); // A package.json "typings" may specify an exact filename, or may choose to omit an extension. - const fromFile = tryFile(typesFile, failedLookupLocation, onlyRecordFailures, state); + const fromFile = tryFile(typesFile, failedLookupLocations, onlyRecordFailures, state); if (fromFile) { // Note: this would allow a package.json to specify a ".js" file as typings. Maybe that should be forbidden. return resolvedFromAnyFile(fromFile); } - const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocation, onlyRecordFailures, state); + const x = tryAddingExtensions(typesFile, Extensions.TypeScript, failedLookupLocations, onlyRecordFailures, state); if (x) { return x; } @@ -701,17 +699,17 @@ namespace ts { trace(state.host, Diagnostics.File_0_does_not_exist, packageJsonPath); } // record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results - failedLookupLocation.push(packageJsonPath); + failedLookupLocations.push(packageJsonPath); } - return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, state); + return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocations, !directoryExists, state); } function pathToPackageJson(directory: string): string { return combinePaths(directory, "package.json"); } - function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined { + function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push, state: ModuleResolutionState): Resolved | undefined { const nodeModulesFolder = combinePaths(directory, "node_modules"); const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host); const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); @@ -720,34 +718,30 @@ namespace ts { loadNodeModuleFromDirectory(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state); } - function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean): Resolved | undefined { - return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, checkOneLevel, /*typesOnly*/ false); + function loadModuleFromNodeModules(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push, state: ModuleResolutionState): Resolved | undefined { + return loadModuleFromNodeModulesWorker(extensions, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ false); } - function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined { - return loadModuleFromNodeModulesWorker(Extensions.TypeScript, moduleName, directory, failedLookupLocations, state, /*checkOneLevel*/ false, /*typesOnly*/ true); + function loadModuleFromNodeModulesAtTypes(moduleName: string, directory: string, failedLookupLocations: Push, state: ModuleResolutionState): Resolved | undefined { + // Extensions parameter here doesn't actually matter, because typesOnly ensures we're just doing @types lookup, which is always DtsOnly. + return loadModuleFromNodeModulesWorker(Extensions.DtsOnly, moduleName, directory, failedLookupLocations, state, /*typesOnly*/ true); } - function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState, checkOneLevel: boolean, typesOnly: boolean): Resolved | undefined { - directory = normalizeSlashes(directory); - while (true) { - if (getBaseFileName(directory) !== "node_modules") { - const resolved = tryInDirectory(); - if (resolved) { - return resolved; - } + function loadModuleFromNodeModulesWorker(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push, state: ModuleResolutionState, typesOnly: boolean): Resolved | undefined { + return forEachAncestorDirectory(normalizeSlashes(directory), ancestorDirectory => { + if (getBaseFileName(ancestorDirectory) !== "node_modules") { + return loadModuleFromNodeModulesOneLevel(extensions, moduleName, ancestorDirectory, failedLookupLocations, state, typesOnly); } + }); + } - const parentPath = getDirectoryPath(directory); - if (parentPath === directory || checkOneLevel) { - return undefined; - } - - directory = parentPath; + /** Load a module from a single node_modules directory, but not from any ancestors' node_modules directories. */ + function loadModuleFromNodeModulesOneLevel(extensions: Extensions, moduleName: string, directory: string, failedLookupLocations: Push, state: ModuleResolutionState, typesOnly = false): Resolved | undefined { + const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state); + if (packageResult) { + return packageResult; } - - function tryInDirectory(): Resolved | undefined { - const packageResult = typesOnly ? undefined : loadModuleFromNodeModulesFolder(extensions, moduleName, directory, failedLookupLocations, state); - return packageResult || loadModuleFromNodeModulesFolder(extensions, combinePaths("@types", moduleName), directory, failedLookupLocations, state); + if (extensions !== Extensions.JavaScript) { + return loadModuleFromNodeModulesFolder(Extensions.DtsOnly, combinePaths("@types", moduleName), directory, failedLookupLocations, state); } } @@ -767,7 +761,11 @@ namespace ts { } if (moduleHasNonRelativeName(moduleName)) { - const resolved = loadModuleFromAncestorDirectories(extensions, moduleName, containingDirectory, failedLookupLocations, state); + // Climb up parent directories looking for a module. + const resolved = forEachAncestorDirectory(containingDirectory, directory => { + const searchName = normalizePath(combinePaths(directory, moduleName)); + return loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state); + }); if (resolved) { return resolved; } @@ -783,22 +781,6 @@ namespace ts { } } - /** Climb up parent directories looking for a module. */ - function loadModuleFromAncestorDirectories(extensions: Extensions, moduleName: string, containingDirectory: string, failedLookupLocations: string[], state: ModuleResolutionState): Resolved | undefined { - while (true) { - const searchName = normalizePath(combinePaths(containingDirectory, moduleName)); - const referencedSourceFile = loadModuleFromFile(extensions, searchName, failedLookupLocations, /*onlyRecordFailures*/ false, state); - if (referencedSourceFile) { - return referencedSourceFile; - } - const parentPath = getDirectoryPath(containingDirectory); - if (parentPath === containingDirectory) { - return undefined; - } - containingDirectory = parentPath; - } - } - /** * LSHost may load a module from a global cache of typings. * This is the minumum code needed to expose that functionality; the rest is in LSHost. @@ -811,8 +793,24 @@ namespace ts { } const state: ModuleResolutionState = { compilerOptions, host, traceEnabled }; const failedLookupLocations: string[] = []; - const resolved = loadModuleFromNodeModules(Extensions.TypeScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true) || - loadModuleFromNodeModules(Extensions.JavaScript, moduleName, globalCache, failedLookupLocations, state, /*checkOneLevel*/ true); + const resolved = loadModuleFromNodeModulesOneLevel(Extensions.DtsOnly, moduleName, globalCache, failedLookupLocations, state); return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations); } + + /** Calls `callback` on `directory` and every ancestor directory it has, returning the first defined result. */ + function forEachAncestorDirectory(directory: string, callback: (directory: string) => T | undefined): T | undefined { + while (true) { + const result = callback(directory); + if (result !== undefined) { + return result; + } + + const parentPath = getDirectoryPath(directory); + if (parentPath === directory) { + return undefined; + } + + directory = parentPath; + } + } } \ No newline at end of file diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 92a3dcbef11..943a677ef5d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -74,6 +74,8 @@ namespace ts { visitNode(cbNode, (node).questionToken) || visitNode(cbNode, (node).equalsToken) || visitNode(cbNode, (node).objectAssignmentInitializer); + case SyntaxKind.SpreadAssignment: + return visitNode(cbNode, (node).expression); case SyntaxKind.Parameter: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -197,8 +199,8 @@ namespace ts { visitNode(cbNode, (node).whenTrue) || visitNode(cbNode, (node).colonToken) || visitNode(cbNode, (node).whenFalse); - case SyntaxKind.SpreadElementExpression: - return visitNode(cbNode, (node).expression); + case SyntaxKind.SpreadElement: + return visitNode(cbNode, (node).expression); case SyntaxKind.Block: case SyntaxKind.ModuleBlock: return visitNodes(cbNodes, (node).statements); @@ -438,6 +440,10 @@ namespace ts { return result; } + export function parseIsolatedEntityName(text: string, languageVersion: ScriptTarget): EntityName { + return Parser.parseIsolatedEntityName(text, languageVersion); + } + export function isExternalModule(file: SourceFile): boolean { return file.externalModuleIndicator !== undefined; } @@ -589,6 +595,16 @@ namespace ts { return result; } + export function parseIsolatedEntityName(content: string, languageVersion: ScriptTarget): EntityName { + initializeState(content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS); + // Prime the scanner. + nextToken(); + const entityName = parseEntityName(/*allowReservedWords*/ true); + const isInvalid = token() === SyntaxKind.EndOfFileToken && !parseDiagnostics.length; + clearState(); + return isInvalid ? entityName : undefined; + } + function getLanguageVariant(scriptKind: ScriptKind) { // .tsx and .jsx files are treated as jsx language variant. return scriptKind === ScriptKind.TSX || scriptKind === ScriptKind.JSX || scriptKind === ScriptKind.JS ? LanguageVariant.JSX : LanguageVariant.Standard; @@ -1269,9 +1285,11 @@ namespace ts { // which would be a candidate for improved error reporting. return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); case ParsingContext.ObjectLiteralMembers: - return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName(); + case ParsingContext.RestProperties: + return isLiteralPropertyName(); case ParsingContext.ObjectBindingElements: - return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName(); case ParsingContext.HeritageClauseElement: // If we see { } then only consume it as an expression if it is followed by , or { // That way we won't consume the body of a class in its heritage clause. @@ -1398,6 +1416,7 @@ namespace ts { case ParsingContext.ArrayBindingElements: return token() === SyntaxKind.CloseBracketToken; case ParsingContext.Parameters: + case ParsingContext.RestProperties: // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/; case ParsingContext.TypeArguments: @@ -1583,6 +1602,9 @@ namespace ts { case ParsingContext.Parameters: return isReusableParameter(node); + case ParsingContext.RestProperties: + return false; + // Any other lists we do not care about reusing nodes in. But feel free to add if // you can do so safely. Danger areas involve nodes that may involve speculative // parsing. If speculative parsing is involved with the node, then the range the @@ -1780,6 +1802,7 @@ namespace ts { case ParsingContext.BlockStatements: return Diagnostics.Declaration_or_statement_expected; case ParsingContext.SwitchClauses: return Diagnostics.case_or_default_expected; case ParsingContext.SwitchClauseStatements: return Diagnostics.Statement_expected; + case ParsingContext.RestProperties: // fallthrough case ParsingContext.TypeMembers: return Diagnostics.Property_or_signature_expected; case ParsingContext.ClassMembers: return Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected; case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected; @@ -4122,7 +4145,7 @@ namespace ts { } function parseSpreadElement(): Expression { - const node = createNode(SyntaxKind.SpreadElementExpression); + const node = createNode(SyntaxKind.SpreadElement); parseExpected(SyntaxKind.DotDotDotToken); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); @@ -4162,6 +4185,12 @@ namespace ts { function parseObjectLiteralElement(): ObjectLiteralElementLike { const fullStart = scanner.getStartPos(); + const dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); + if (dotDotDotToken) { + const spreadElement = createNode(SyntaxKind.SpreadAssignment, fullStart); + spreadElement.expression = parseAssignmentExpressionOrHigher(); + return addJSDocComment(finishNode(spreadElement)); + } const decorators = parseDecorators(); const modifiers = parseModifiers(); @@ -4865,6 +4894,7 @@ namespace ts { function parseObjectBindingElement(): BindingElement { const node = createNode(SyntaxKind.BindingElement); + node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); const tokenIsIdentifier = isIdentifier(); const propertyName = parsePropertyName(); if (tokenIsIdentifier && token() !== SyntaxKind.ColonToken) { @@ -5809,6 +5839,7 @@ namespace ts { JsxChildren, // Things between opening and closing JSX tags ArrayLiteralMembers, // Members in array literal Parameters, // Parameters in parameter list + RestProperties, // Property names in a rest type list TypeParameters, // Type parameters in type parameter list TypeArguments, // Type arguments in type argument list TupleElementTypes, // Element types in tuple element type list diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 1b36d99d7c9..cf62a6fc7fa 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -5,7 +5,7 @@ namespace ts { /** The version of the TypeScript compiler release */ - export const version = "2.1.0"; + export const version = "2.2.0"; const emptyArray: any[] = []; @@ -431,13 +431,14 @@ namespace ts { return program; function getCommonSourceDirectory() { - if (typeof commonSourceDirectory === "undefined") { - if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { + if (commonSourceDirectory === undefined) { + const emittedFiles = filterSourceFilesInDirectory(files, isSourceFileFromExternalLibrary); + if (options.rootDir && checkSourceFilesBelongToPath(emittedFiles, options.rootDir)) { // If a rootDir is specified and is valid use it as the commonSourceDirectory commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory); } else { - commonSourceDirectory = computeCommonSourceDirectory(files); + commonSourceDirectory = computeCommonSourceDirectory(emittedFiles); } if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) { // Make sure directory path ends with directory separator so this string can directly @@ -476,7 +477,7 @@ namespace ts { return resolveModuleNamesWorker(moduleNames, containingFile); } - // at this point we know that either + // at this point we know that either // - file has local declarations for ambient modules // OR // - old program state is available @@ -670,7 +671,7 @@ namespace ts { } const modifiedFilePaths = modifiedSourceFiles.map(f => f.newFile.path); - // try to verify results of module resolution + // try to verify results of module resolution for (const { oldFile: oldSourceFile, newFile: newSourceFile } of modifiedSourceFiles) { const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory); if (resolveModuleNamesWorker) { @@ -908,48 +909,24 @@ namespace ts { function getJavaScriptSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return runWithCancellationToken(() => { const diagnostics: Diagnostic[] = []; + let parent: Node = sourceFile; walk(sourceFile); return diagnostics; - function walk(node: Node): boolean { - if (!node) { - return false; - } + function walk(node: Node) { + // Return directly from the case if the given node doesnt want to visit each child + // Otherwise break to visit each child - switch (node.kind) { - case SyntaxKind.ImportEqualsDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file)); - return true; - case SyntaxKind.ExportAssignment: - if ((node).isExportEquals) { - diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file)); - return true; + switch (parent.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.PropertyDeclaration: + if ((parent).questionToken === node) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?")); + return; } - break; - case SyntaxKind.ClassDeclaration: - let classDeclaration = node; - if (checkModifiers(classDeclaration.modifiers) || - checkTypeParameters(classDeclaration.typeParameters)) { - return true; - } - break; - case SyntaxKind.HeritageClause: - let heritageClause = node; - if (heritageClause.token === SyntaxKind.ImplementsKeyword) { - diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); - return true; - } - break; - case SyntaxKind.InterfaceDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file)); - return true; - case SyntaxKind.ModuleDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_a_ts_file)); - return true; - case SyntaxKind.TypeAliasDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_a_ts_file)); - return true; + + // Pass through case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.Constructor: @@ -959,124 +936,151 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: case SyntaxKind.FunctionDeclaration: - const functionDeclaration = node; - if (checkModifiers(functionDeclaration.modifiers) || - checkTypeParameters(functionDeclaration.typeParameters) || - checkTypeAnnotation(functionDeclaration.type)) { - return true; - } - break; - case SyntaxKind.VariableStatement: - const variableStatement = node; - if (checkModifiers(variableStatement.modifiers)) { - return true; - } - break; case SyntaxKind.VariableDeclaration: - const variableDeclaration = node; - if (checkTypeAnnotation(variableDeclaration.type)) { - return true; + // type annotation + if ((parent).type === node) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics.types_can_only_be_used_in_a_ts_file)); + return; + } + } + + switch (node.kind) { + case SyntaxKind.ImportEqualsDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file)); + return; + case SyntaxKind.ExportAssignment: + if ((node).isExportEquals) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file)); + return; + } + break; + case SyntaxKind.HeritageClause: + let heritageClause = node; + if (heritageClause.token === SyntaxKind.ImplementsKeyword) { + diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file)); + return; + } + break; + case SyntaxKind.InterfaceDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file)); + return; + case SyntaxKind.ModuleDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_a_ts_file)); + return; + case SyntaxKind.TypeAliasDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_a_ts_file)); + return; + case SyntaxKind.EnumDeclaration: + diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file)); + return; + case SyntaxKind.TypeAssertionExpression: + let typeAssertionExpression = node; + diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); + return; + } + + const prevParent = parent; + parent = node; + forEachChild(node, walk, walkArray); + parent = prevParent; + } + + function walkArray(nodes: NodeArray) { + if (parent.decorators === nodes && !options.experimentalDecorators) { + diagnostics.push(createDiagnosticForNode(parent, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning)); + } + + switch (parent.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionExpression: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ArrowFunction: + case SyntaxKind.FunctionDeclaration: + // Check type parameters + if (nodes === (parent).typeParameters) { + diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); + return; + } + // pass through + case SyntaxKind.VariableStatement: + // Check modifiers + if (nodes === (parent).modifiers) { + return checkModifiers(>nodes, parent.kind === SyntaxKind.VariableStatement); + } + break; + case SyntaxKind.PropertyDeclaration: + // Check modifiers of property declaration + if (nodes === (parent).modifiers) { + for (const modifier of >nodes) { + if (modifier.kind !== SyntaxKind.StaticKeyword) { + diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); + } + } + return; + } + break; + case SyntaxKind.Parameter: + // Check modifiers of parameter declaration + if (nodes === (parent).modifiers) { + diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.parameter_modifiers_can_only_be_used_in_a_ts_file)); + return; } break; case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: - const expression = node; - if (expression.typeArguments && expression.typeArguments.length > 0) { - const start = expression.typeArguments.pos; - diagnostics.push(createFileDiagnostic(sourceFile, start, expression.typeArguments.end - start, - Diagnostics.type_arguments_can_only_be_used_in_a_ts_file)); - return true; + case SyntaxKind.ExpressionWithTypeArguments: + // Check type arguments + if (nodes === (parent).typeArguments) { + diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_arguments_can_only_be_used_in_a_ts_file)); + return; } break; - case SyntaxKind.Parameter: - const parameter = node; - if (parameter.modifiers) { - const start = parameter.modifiers.pos; - diagnostics.push(createFileDiagnostic(sourceFile, start, parameter.modifiers.end - start, - Diagnostics.parameter_modifiers_can_only_be_used_in_a_ts_file)); - return true; - } - if (parameter.questionToken) { - diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics._0_can_only_be_used_in_a_ts_file, "?")); - return true; - } - if (parameter.type) { - diagnostics.push(createDiagnosticForNode(parameter.type, Diagnostics.types_can_only_be_used_in_a_ts_file)); - return true; - } - break; - case SyntaxKind.PropertyDeclaration: - const propertyDeclaration = node; - if (propertyDeclaration.modifiers) { - for (const modifier of propertyDeclaration.modifiers) { - if (modifier.kind !== SyntaxKind.StaticKeyword) { - diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); - return true; - } + } + + for (const node of nodes) { + walk(node); + } + } + + function checkModifiers(modifiers: NodeArray, isConstValid: boolean) { + for (const modifier of modifiers) { + switch (modifier.kind) { + case SyntaxKind.ConstKeyword: + if (isConstValid) { + continue; } - } - if (checkTypeAnnotation((node).type)) { - return true; - } - break; - case SyntaxKind.EnumDeclaration: - diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file)); - return true; - case SyntaxKind.TypeAssertionExpression: - let typeAssertionExpression = node; - diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file)); - return true; - case SyntaxKind.Decorator: - if (!options.experimentalDecorators) { - diagnostics.push(createDiagnosticForNode(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning)); - } - return true; - } + // Fallthrough to report error + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.ReadonlyKeyword: + case SyntaxKind.DeclareKeyword: + case SyntaxKind.AbstractKeyword: + diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); + break; - return forEachChild(node, walk); - } - - function checkTypeParameters(typeParameters: NodeArray): boolean { - if (typeParameters) { - const start = typeParameters.pos; - diagnostics.push(createFileDiagnostic(sourceFile, start, typeParameters.end - start, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file)); - return true; - } - return false; - } - - function checkTypeAnnotation(type: TypeNode): boolean { - if (type) { - diagnostics.push(createDiagnosticForNode(type, Diagnostics.types_can_only_be_used_in_a_ts_file)); - return true; - } - - return false; - } - - function checkModifiers(modifiers: NodeArray): boolean { - if (modifiers) { - for (const modifier of modifiers) { - switch (modifier.kind) { - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.ReadonlyKeyword: - case SyntaxKind.DeclareKeyword: - diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind))); - return true; - - // These are all legal modifiers. - case SyntaxKind.StaticKeyword: - case SyntaxKind.ExportKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.DefaultKeyword: - case SyntaxKind.AbstractKeyword: - } + // These are all legal modifiers. + case SyntaxKind.StaticKeyword: + case SyntaxKind.ExportKeyword: + case SyntaxKind.DefaultKeyword: } } + } - return false; + function createDiagnosticForNodeArray(nodes: NodeArray, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { + const start = nodes.pos; + return createFileDiagnostic(sourceFile, start, nodes.end - start, message, arg0, arg1, arg2); + } + + // Since these are syntactic diagnostics, parent might not have been set + // this means the sourceFile cannot be infered from the node + function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { + return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2); } }); } @@ -1140,9 +1144,14 @@ namespace ts { if (options.importHelpers && (options.isolatedModules || isExternalModuleFile) && !file.isDeclarationFile) { - const externalHelpersModuleReference = createNode(SyntaxKind.StringLiteral); + // synthesize 'import "tslib"' declaration + const externalHelpersModuleReference = createSynthesizedNode(SyntaxKind.StringLiteral); externalHelpersModuleReference.text = externalHelpersModuleNameText; - externalHelpersModuleReference.parent = file; + const importDecl = createSynthesizedNode(SyntaxKind.ImportDeclaration); + + importDecl.parent = file; + externalHelpersModuleReference.parent = importDecl; + imports = [externalHelpersModuleReference]; } @@ -1439,7 +1448,9 @@ namespace ts { collectExternalModuleReferences(file); if (file.imports.length || file.moduleAugmentations.length) { file.resolvedModules = createMap(); - const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral); + // Because global augmentation doesn't have string literal name, we can check for global augmentation as such. + const nonGlobalAugmentation = filter(file.moduleAugmentations, (moduleAugmentation) => moduleAugmentation.kind === SyntaxKind.StringLiteral); + const moduleNames = map(concatenate(file.imports, nonGlobalAugmentation), getTextOfLiteral); const resolutions = resolveModuleNamesReusingOldState(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory), file); Debug.assert(resolutions.length === moduleNames.length); for (let i = 0; i < moduleNames.length; i++) { @@ -1670,7 +1681,15 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); } - if (options.reactNamespace && !isIdentifierText(options.reactNamespace, languageVersion)) { + if (options.jsxFactory) { + if (options.reactNamespace) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory")); + } + if (!parseIsolatedEntityName(options.jsxFactory, languageVersion)) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_jsxFactory_0_is_not_a_valid_identifier_or_qualified_name, options.jsxFactory)); + } + } + else if (options.reactNamespace && !isIdentifierText(options.reactNamespace, languageVersion)) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Invalid_value_for_reactNamespace_0_is_not_a_valid_identifier, options.reactNamespace)); } @@ -1690,18 +1709,13 @@ namespace ts { const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName); // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { - if (options.noEmitOverwritenFiles && !options.out && !options.outDir && !options.outFile) { - blockEmittingOfFile(emitFileName); - } - else { - let chain: DiagnosticMessageChain; - if (!options.configFilePath) { - // The program is from either an inferred project or an external project - chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig); - } - chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName); - blockEmittingOfFile(emitFileName, createCompilerDiagnosticFromMessageChain(chain)); + let chain: DiagnosticMessageChain; + if (!options.configFilePath) { + // The program is from either an inferred project or an external project + chain = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Adding_a_tsconfig_json_file_will_help_organize_projects_that_contain_both_TypeScript_and_JavaScript_files_Learn_more_at_https_Colon_Slash_Slashaka_ms_Slashtsconfig); } + chain = chainDiagnosticMessages(chain, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file, emitFileName); + blockEmittingOfFile(emitFileName, createCompilerDiagnosticFromMessageChain(chain)); } // Report error if multiple files write into same file @@ -1716,11 +1730,9 @@ namespace ts { } } - function blockEmittingOfFile(emitFileName: string, diag?: Diagnostic) { + function blockEmittingOfFile(emitFileName: string, diag: Diagnostic) { hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); - if (diag) { - programDiagnostics.add(diag); - } + programDiagnostics.add(diag); } } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index ee9c081e6eb..b005b1906f6 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -1,6 +1,7 @@ /// /// /// +/// /// /// /// @@ -116,6 +117,10 @@ namespace ts { transformers.push(transformJsx); } + if (languageVersion < ScriptTarget.ESNext) { + transformers.push(transformESNext); + } + if (languageVersion < ScriptTarget.ES2017) { transformers.push(transformES2017); } diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index ab5c4629e95..a8c00776741 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -17,7 +17,8 @@ namespace ts { node: BinaryExpression, needsValue: boolean, recordTempVariable: (node: Identifier) => void, - visitor?: (node: Node) => VisitResult): Expression { + visitor?: (node: Node) => VisitResult, + transformRest?: boolean): Expression { if (isEmptyObjectLiteralOrArrayLiteral(node.left)) { const right = node.right; @@ -51,7 +52,7 @@ namespace ts { location = value; } - flattenDestructuring(node, value, location, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, value, location, emitAssignment, emitTempVariableAssignment, recordTempVariable, emitRestAssignment, transformRest, visitor); if (needsValue) { expressions.push(value); @@ -61,7 +62,7 @@ namespace ts { aggregateTransformFlags(expression); return expression; - function emitAssignment(name: Identifier, value: Expression, location: TextRange) { + function emitAssignment(name: Identifier | ObjectLiteralExpression, value: Expression, location: TextRange) { const expression = createAssignment(name, value, location); // NOTE: this completely disables source maps, but aligns with the behavior of @@ -77,6 +78,10 @@ namespace ts { emitAssignment(name, value, location); return name; } + + function emitRestAssignment(elements: ObjectLiteralElementLike[], value: Expression, location: TextRange) { + emitAssignment(createObjectLiteral(elements), value, location); + } } /** @@ -89,14 +94,15 @@ namespace ts { export function flattenParameterDestructuring( node: ParameterDeclaration, value: Expression, - visitor?: (node: Node) => VisitResult) { + visitor?: (node: Node) => VisitResult, + transformRest?: boolean) { const declarations: VariableDeclaration[] = []; - flattenDestructuring(node, value, node, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, value, node, emitAssignment, emitTempVariableAssignment, noop, emitRestAssignment, transformRest, visitor); return declarations; - function emitAssignment(name: Identifier, value: Expression, location: TextRange) { + function emitAssignment(name: Identifier | BindingPattern, value: Expression, location: TextRange) { const declaration = createVariableDeclaration(name, /*type*/ undefined, value, location); // NOTE: this completely disables source maps, but aligns with the behavior of @@ -112,6 +118,10 @@ namespace ts { emitAssignment(name, value, location); return name; } + + function emitRestAssignment(elements: BindingElement[], value: Expression, location: TextRange) { + emitAssignment(createObjectBindingPattern(elements), value, location); + } } /** @@ -125,15 +135,16 @@ namespace ts { node: VariableDeclaration, value?: Expression, visitor?: (node: Node) => VisitResult, - recordTempVariable?: (node: Identifier) => void) { + recordTempVariable?: (node: Identifier) => void, + transformRest?: boolean) { const declarations: VariableDeclaration[] = []; let pendingAssignments: Expression[]; - flattenDestructuring(node, value, node, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, value, node, emitAssignment, emitTempVariableAssignment, recordTempVariable, emitRestAssignment, transformRest, visitor); return declarations; - function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) { + function emitAssignment(name: Identifier | BindingPattern, value: Expression, location: TextRange, original: Node) { if (pendingAssignments) { pendingAssignments.push(value); value = inlineExpressions(pendingAssignments); @@ -167,6 +178,10 @@ namespace ts { } return name; } + + function emitRestAssignment(elements: BindingElement[], value: Expression, location: TextRange, original: Node) { + emitAssignment(createObjectBindingPattern(elements), value, location, original); + } } /** @@ -186,15 +201,17 @@ namespace ts { const pendingAssignments: Expression[] = []; - flattenDestructuring(node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment, noop, emitRestAssignment, /*transformRest*/ false, visitor); const expression = inlineExpressions(pendingAssignments); aggregateTransformFlags(expression); return expression; - function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) { + function emitAssignment(name: Identifier | ObjectLiteralExpression, value: Expression, location: TextRange, original: Node) { const expression = createAssignmentCallback - ? createAssignmentCallback(name, value, location) + ? createAssignmentCallback(name.kind === SyntaxKind.Identifier ? name : emitTempVariableAssignment(name, location), + value, + location) : createAssignment(name, value, location); emitPendingAssignment(expression, original); @@ -206,6 +223,10 @@ namespace ts { return name; } + function emitRestAssignment(elements: ObjectLiteralElementLike[], value: Expression, location: TextRange, original: Node) { + emitAssignment(createObjectLiteral(elements), value, location, original); + } + function emitPendingAssignment(expression: Expression, original: Node) { expression.original = original; @@ -223,6 +244,9 @@ namespace ts { location: TextRange, emitAssignment: (name: Identifier, value: Expression, location: TextRange, original: Node) => void, emitTempVariableAssignment: (value: Expression, location: TextRange) => Identifier, + recordTempVariable: (node: Identifier) => void, + emitRestAssignment: (elements: (ObjectLiteralElementLike[] | BindingElement[]), value: Expression, location: TextRange, original: Node) => void, + transformRest: boolean, visitor?: (node: Node) => VisitResult) { if (value && visitor) { value = visitNode(value, visitor, isExpression); @@ -284,23 +308,92 @@ namespace ts { value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true, location, emitTempVariableAssignment); } - for (const p of properties) { + let bindingElements: ObjectLiteralElementLike[] = []; + for (let i = 0; i < properties.length; i++) { + const p = properties[i]; if (p.kind === SyntaxKind.PropertyAssignment || p.kind === SyntaxKind.ShorthandPropertyAssignment) { - const propName = (p).name; - const target = p.kind === SyntaxKind.ShorthandPropertyAssignment ? p : (p).initializer || propName; - // Assignment for target = value.propName should highligh whole property, hence use p as source map node - emitDestructuringAssignment(target, createDestructuringPropertyAccess(value, propName), p); + if (!transformRest || + p.transformFlags & TransformFlags.ContainsSpreadExpression || + (p.kind === SyntaxKind.PropertyAssignment && p.initializer.transformFlags & TransformFlags.ContainsSpreadExpression)) { + if (bindingElements.length) { + emitRestAssignment(bindingElements, value, location, target); + bindingElements = []; + } + const propName = (p).name; + const bindingTarget = p.kind === SyntaxKind.ShorthandPropertyAssignment ? p : (p).initializer || propName; + // Assignment for bindingTarget = value.propName should highlight whole property, hence use p as source map node + emitDestructuringAssignment(bindingTarget, createDestructuringPropertyAccess(value, propName), p); + } + else { + bindingElements.push(p); + } } + else if (i === properties.length - 1 && + p.kind === SyntaxKind.SpreadAssignment && + p.expression.kind === SyntaxKind.Identifier) { + if (bindingElements.length) { + emitRestAssignment(bindingElements, value, location, target); + bindingElements = []; + } + const propName = (p as SpreadAssignment).expression as Identifier; + const restCall = createRestCall(value, target.properties, p => p.name, target); + emitDestructuringAssignment(propName, restCall, p); + } + } + if (bindingElements.length) { + emitRestAssignment(bindingElements, value, location, target); + bindingElements = []; } } function emitArrayLiteralAssignment(target: ArrayLiteralExpression, value: Expression, location: TextRange) { + if (transformRest) { + emitESNextArrayLiteralAssignment(target, value, location); + } + else { + emitES2015ArrayLiteralAssignment(target, value, location); + } + } + + function emitESNextArrayLiteralAssignment(target: ArrayLiteralExpression, value: Expression, location: TextRange) { const elements = target.elements; const numElements = elements.length; if (numElements !== 1) { // For anything but a single element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. - // When doing so we want to hightlight the passed in source map node since thats the one needing this temp assignment + // When doing so we want to highlight the passed-in source map node since thats the one needing this temp assignment + value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true, location, emitTempVariableAssignment); + } + + const expressions: Expression[] = []; + const spreadContainingExpressions: [Expression, Identifier][] = []; + for (let i = 0; i < numElements; i++) { + const e = elements[i]; + if (e.kind === SyntaxKind.OmittedExpression) { + continue; + } + if (e.transformFlags & TransformFlags.ContainsSpreadExpression && i < numElements - 1) { + const tmp = createTempVariable(recordTempVariable); + spreadContainingExpressions.push([e, tmp]); + expressions.push(tmp); + } + else { + expressions.push(e); + } + } + emitAssignment(updateArrayLiteral(target, expressions) as any as Identifier, value, undefined, undefined); + for (const [e, tmp] of spreadContainingExpressions) { + emitDestructuringAssignment(e, tmp, e); + } + } + + function emitES2015ArrayLiteralAssignment(target: ArrayLiteralExpression, value: Expression, location: TextRange) { + const elements = target.elements; + const numElements = elements.length; + if (numElements !== 1) { + // For anything but a single element destructuring we need to generate a temporary + // to ensure value is evaluated exactly once. + // When doing so we want to highlight the passed-in source map node since thats the one needing this temp assignment value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ true, location, emitTempVariableAssignment); } @@ -308,20 +401,41 @@ namespace ts { const e = elements[i]; if (e.kind !== SyntaxKind.OmittedExpression) { // Assignment for target = value.propName should highligh whole property, hence use e as source map node - if (e.kind !== SyntaxKind.SpreadElementExpression) { + if (e.kind !== SyntaxKind.SpreadElement) { emitDestructuringAssignment(e, createElementAccess(value, createLiteral(i)), e); } else if (i === numElements - 1) { - emitDestructuringAssignment((e).expression, createArraySlice(value, i), e); + emitDestructuringAssignment((e).expression, createArraySlice(value, i), e); } } } } + /** Given value: o, propName: p, pattern: { a, b, ...p } from the original statement + * `{ a, b, ...p } = o`, create `p = __rest(o, ["a", "b"]);`*/ + function createRestCall(value: Expression, elements: T[], getPropertyName: (element: T) => PropertyName, location: TextRange): Expression { + const propertyNames: LiteralExpression[] = []; + for (let i = 0; i < elements.length - 1; i++) { + if (isOmittedExpression(elements[i])) { + continue; + } + const str = createSynthesizedNode(SyntaxKind.StringLiteral); + str.pos = location.pos; + str.end = location.end; + str.text = getTextOfPropertyName(getPropertyName(elements[i])); + propertyNames.push(str); + } + const args = createSynthesizedNodeArray([value, createArrayLiteral(propertyNames, location)]); + return createCall(createIdentifier("__rest"), undefined, args); + } + function emitBindingElement(target: VariableDeclaration | ParameterDeclaration | BindingElement, value: Expression) { // Any temporary assignments needed to emit target = value should point to target const initializer = visitor ? visitNode(target.initializer, visitor, isExpression) : target.initializer; - if (initializer) { + if (transformRest) { + value = value || initializer; + } + else if (initializer) { // Combine value and initializer value = value ? createDefaultValueCheck(value, initializer, target) : initializer; } @@ -331,9 +445,11 @@ namespace ts { } const name = target.name; - if (isBindingPattern(name)) { - const elements = name.elements; - const numElements = elements.length; + if (!isBindingPattern(name)) { + emitAssignment(name, value, target, target); + } + else { + const numElements = name.elements.length; if (numElements !== 1) { // For anything other than a single-element destructuring we need to generate a temporary // to ensure value is evaluated exactly once. Additionally, if we have zero elements @@ -341,29 +457,104 @@ namespace ts { // so in that case, we'll intentionally create that temporary. value = ensureIdentifier(value, /*reuseIdentifierExpressions*/ numElements !== 0, target, emitTempVariableAssignment); } - for (let i = 0; i < numElements; i++) { - const element = elements[i]; - if (isOmittedExpression(element)) { - continue; - } - else if (name.kind === SyntaxKind.ObjectBindingPattern) { - // Rewrite element to a declaration with an initializer that fetches property - const propName = element.propertyName || element.name; - emitBindingElement(element, createDestructuringPropertyAccess(value, propName)); - } - else { - if (!element.dotDotDotToken) { - // Rewrite element to a declaration that accesses array element at index i - emitBindingElement(element, createElementAccess(value, i)); - } - else if (i === numElements - 1) { - emitBindingElement(element, createArraySlice(value, i)); - } - } + if (name.kind === SyntaxKind.ArrayBindingPattern) { + emitArrayBindingElement(name as ArrayBindingPattern, value); + } + else { + emitObjectBindingElement(target, value); } } + } + + function emitArrayBindingElement(name: ArrayBindingPattern, value: Expression) { + if (transformRest) { + emitESNextArrayBindingElement(name, value); + } else { - emitAssignment(name, value, target, target); + emitES2015ArrayBindingElement(name, value); + } + } + + function emitES2015ArrayBindingElement(name: ArrayBindingPattern, value: Expression) { + const elements = name.elements; + const numElements = elements.length; + for (let i = 0; i < numElements; i++) { + const element = elements[i]; + if (isOmittedExpression(element)) { + continue; + } + if (!element.dotDotDotToken) { + // Rewrite element to a declaration that accesses array element at index i + emitBindingElement(element, createElementAccess(value, i)); + } + else if (i === numElements - 1) { + emitBindingElement(element, createArraySlice(value, i)); + } + } + } + + function emitESNextArrayBindingElement(name: ArrayBindingPattern, value: Expression) { + const elements = name.elements; + const numElements = elements.length; + const bindingElements: BindingElement[] = []; + const spreadContainingElements: BindingElement[] = []; + for (let i = 0; i < numElements; i++) { + const element = elements[i]; + if (isOmittedExpression(element)) { + continue; + } + if (element.transformFlags & TransformFlags.ContainsSpreadExpression && i < numElements - 1) { + spreadContainingElements.push(element); + bindingElements.push(createBindingElement(undefined, undefined, getGeneratedNameForNode(element), undefined, value)); + } + else { + bindingElements.push(element); + } + } + emitAssignment(updateArrayBindingPattern(name, bindingElements) as any as Identifier, value, undefined, undefined); + for (const element of spreadContainingElements) { + emitBindingElement(element, getGeneratedNameForNode(element)); + } + } + + function emitObjectBindingElement(target: VariableDeclaration | ParameterDeclaration | BindingElement, value: Expression) { + const name = target.name as BindingPattern; + const elements = name.elements; + const numElements = elements.length; + let bindingElements: BindingElement[] = []; + for (let i = 0; i < numElements; i++) { + const element = elements[i]; + if (isOmittedExpression(element)) { + continue; + } + if (i === numElements - 1 && element.dotDotDotToken) { + if (bindingElements.length) { + emitRestAssignment(bindingElements, value, target, target); + bindingElements = []; + } + const restCall = createRestCall(value, + name.elements, + element => (element as BindingElement).propertyName || (element as BindingElement).name, + name); + emitBindingElement(element, restCall); + } + else if (transformRest && !(element.transformFlags & TransformFlags.ContainsSpreadExpression)) { + // do not emit until we have a complete bundle of ES2015 syntax + bindingElements.push(element); + } + else { + if (bindingElements.length) { + emitRestAssignment(bindingElements, value, target, target); + bindingElements = []; + } + // Rewrite element to a declaration with an initializer that fetches property + const propName = element.propertyName || element.name; + emitBindingElement(element, createDestructuringPropertyAccess(value, propName)); + } + } + if (bindingElements.length) { + emitRestAssignment(bindingElements, value, target, target); + bindingElements = []; } } diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 25c15305c4a..e4fb8a0aaf0 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -861,7 +861,7 @@ namespace ts { } if (constructor) { - addDefaultValueAssignmentsIfNeeded(statements, constructor); + addDefaultValueAssignmentsIfNeeded(statements, constructor, visitor, /*convertObjectRest*/ false); addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper); Debug.assert(statementOffset >= 0, "statementOffset not initialized correctly!"); @@ -954,7 +954,7 @@ namespace ts { // If this isn't a derived class, just capture 'this' for arrow functions if necessary. if (!hasExtendsClause) { if (ctor) { - addCaptureThisForNodeIfNeeded(statements, ctor); + addCaptureThisForNodeIfNeeded(statements, ctor, enableSubstitutionsForCapturedThis); } return SuperCaptureResult.NoReplacement; } @@ -1016,7 +1016,7 @@ namespace ts { } // Perform the capture. - captureThisForNode(statements, ctor, superCallExpression, firstStatement); + captureThisForNode(statements, ctor, superCallExpression, enableSubstitutionsForCapturedThis, firstStatement); // If we're actually replacing the original statement, we need to signal this to the caller. if (superCallExpression) { @@ -1085,242 +1085,6 @@ namespace ts { } } - /** - * Gets a value indicating whether we need to add default value assignments for a - * function-like node. - * - * @param node A function-like node. - */ - function shouldAddDefaultValueAssignments(node: FunctionLikeDeclaration): boolean { - return (node.transformFlags & TransformFlags.ContainsDefaultValueAssignments) !== 0; - } - - /** - * Adds statements to the body of a function-like node if it contains parameters with - * binding patterns or initializers. - * - * @param statements The statements for the new function body. - * @param node A function-like node. - */ - function addDefaultValueAssignmentsIfNeeded(statements: Statement[], node: FunctionLikeDeclaration): void { - if (!shouldAddDefaultValueAssignments(node)) { - return; - } - - for (const parameter of node.parameters) { - const { name, initializer, dotDotDotToken } = parameter; - - // A rest parameter cannot have a binding pattern or an initializer, - // so let's just ignore it. - if (dotDotDotToken) { - continue; - } - - if (isBindingPattern(name)) { - addDefaultValueAssignmentForBindingPattern(statements, parameter, name, initializer); - } - else if (initializer) { - addDefaultValueAssignmentForInitializer(statements, parameter, name, initializer); - } - } - } - - /** - * Adds statements to the body of a function-like node for parameters with binding patterns - * - * @param statements The statements for the new function body. - * @param parameter The parameter for the function. - * @param name The name of the parameter. - * @param initializer The initializer for the parameter. - */ - function addDefaultValueAssignmentForBindingPattern(statements: Statement[], parameter: ParameterDeclaration, name: BindingPattern, initializer: Expression): void { - const temp = getGeneratedNameForNode(parameter); - - // In cases where a binding pattern is simply '[]' or '{}', - // we usually don't want to emit a var declaration; however, in the presence - // of an initializer, we must emit that expression to preserve side effects. - if (name.elements.length > 0) { - statements.push( - setEmitFlags( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList( - flattenParameterDestructuring(parameter, temp, visitor) - ) - ), - EmitFlags.CustomPrologue - ) - ); - } - else if (initializer) { - statements.push( - setEmitFlags( - createStatement( - createAssignment( - temp, - visitNode(initializer, visitor, isExpression) - ) - ), - EmitFlags.CustomPrologue - ) - ); - } - } - - /** - * Adds statements to the body of a function-like node for parameters with initializers. - * - * @param statements The statements for the new function body. - * @param parameter The parameter for the function. - * @param name The name of the parameter. - * @param initializer The initializer for the parameter. - */ - function addDefaultValueAssignmentForInitializer(statements: Statement[], parameter: ParameterDeclaration, name: Identifier, initializer: Expression): void { - initializer = visitNode(initializer, visitor, isExpression); - const statement = createIf( - createStrictEquality( - getSynthesizedClone(name), - createVoidZero() - ), - setEmitFlags( - createBlock([ - createStatement( - createAssignment( - setEmitFlags(getMutableClone(name), EmitFlags.NoSourceMap), - setEmitFlags(initializer, EmitFlags.NoSourceMap | getEmitFlags(initializer)), - /*location*/ parameter - ) - ) - ], /*location*/ parameter), - EmitFlags.SingleLine | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTokenSourceMaps - ), - /*elseStatement*/ undefined, - /*location*/ parameter - ); - statement.startsOnNewLine = true; - setEmitFlags(statement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoTrailingSourceMap | EmitFlags.CustomPrologue); - statements.push(statement); - } - - /** - * Gets a value indicating whether we need to add statements to handle a rest parameter. - * - * @param node A ParameterDeclaration node. - * @param inConstructorWithSynthesizedSuper A value indicating whether the parameter is - * part of a constructor declaration with a - * synthesized call to `super` - */ - function shouldAddRestParameter(node: ParameterDeclaration, inConstructorWithSynthesizedSuper: boolean) { - return node && node.dotDotDotToken && node.name.kind === SyntaxKind.Identifier && !inConstructorWithSynthesizedSuper; - } - - /** - * Adds statements to the body of a function-like node if it contains a rest parameter. - * - * @param statements The statements for the new function body. - * @param node A function-like node. - * @param inConstructorWithSynthesizedSuper A value indicating whether the parameter is - * part of a constructor declaration with a - * synthesized call to `super` - */ - function addRestParameterIfNeeded(statements: Statement[], node: FunctionLikeDeclaration, inConstructorWithSynthesizedSuper: boolean): void { - const parameter = lastOrUndefined(node.parameters); - if (!shouldAddRestParameter(parameter, inConstructorWithSynthesizedSuper)) { - return; - } - - // `declarationName` is the name of the local declaration for the parameter. - const declarationName = getMutableClone(parameter.name); - setEmitFlags(declarationName, EmitFlags.NoSourceMap); - - // `expressionName` is the name of the parameter used in expressions. - const expressionName = getSynthesizedClone(parameter.name); - const restIndex = node.parameters.length - 1; - const temp = createLoopVariable(); - - // var param = []; - statements.push( - setEmitFlags( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - declarationName, - /*type*/ undefined, - createArrayLiteral([]) - ) - ]), - /*location*/ parameter - ), - EmitFlags.CustomPrologue - ) - ); - - // for (var _i = restIndex; _i < arguments.length; _i++) { - // param[_i - restIndex] = arguments[_i]; - // } - const forStatement = createFor( - createVariableDeclarationList([ - createVariableDeclaration(temp, /*type*/ undefined, createLiteral(restIndex)) - ], /*location*/ parameter), - createLessThan( - temp, - createPropertyAccess(createIdentifier("arguments"), "length"), - /*location*/ parameter - ), - createPostfixIncrement(temp, /*location*/ parameter), - createBlock([ - startOnNewLine( - createStatement( - createAssignment( - createElementAccess( - expressionName, - createSubtract(temp, createLiteral(restIndex)) - ), - createElementAccess(createIdentifier("arguments"), temp) - ), - /*location*/ parameter - ) - ) - ]) - ); - - setEmitFlags(forStatement, EmitFlags.CustomPrologue); - startOnNewLine(forStatement); - statements.push(forStatement); - } - - /** - * Adds a statement to capture the `this` of a function declaration if it is needed. - * - * @param statements The statements for the new function body. - * @param node A node. - */ - function addCaptureThisForNodeIfNeeded(statements: Statement[], node: Node): void { - if (node.transformFlags & TransformFlags.ContainsCapturedLexicalThis && node.kind !== SyntaxKind.ArrowFunction) { - captureThisForNode(statements, node, createThis()); - } - } - - function captureThisForNode(statements: Statement[], node: Node, initializer: Expression | undefined, originalStatement?: Statement): void { - enableSubstitutionsForCapturedThis(); - const captureThisStatement = createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - "_this", - /*type*/ undefined, - initializer - ) - ]), - originalStatement - ); - - setEmitFlags(captureThisStatement, EmitFlags.NoComments | EmitFlags.CustomPrologue); - setSourceMapRange(captureThisStatement, node); - statements.push(captureThisStatement); - } - /** * Adds statements to the class body function for a class to define the members of the * class. @@ -1518,7 +1282,7 @@ namespace ts { /*typeParameters*/ undefined, visitNodes(node.parameters, visitor, isParameter), /*type*/ undefined, - transformFunctionBody(node), + transformFunctionBody(node, visitor, currentSourceFile, context, enableSubstitutionsForCapturedThis), /*location*/ node ), /*original*/ node); @@ -1545,7 +1309,7 @@ namespace ts { /*typeParameters*/ undefined, visitNodes(node.parameters, visitor, isParameter), /*type*/ undefined, - saveStateAndInvoke(node, transformFunctionBody), + saveStateAndInvoke(node, node => transformFunctionBody(node, visitor, currentSourceFile, context, enableSubstitutionsForCapturedThis)), location ), /*original*/ node @@ -1555,96 +1319,6 @@ namespace ts { return expression; } - /** - * Transforms the body of a function-like node. - * - * @param node A function-like node. - */ - function transformFunctionBody(node: FunctionLikeDeclaration) { - let multiLine = false; // indicates whether the block *must* be emitted as multiple lines - let singleLine = false; // indicates whether the block *may* be emitted as a single line - let statementsLocation: TextRange; - let closeBraceLocation: TextRange; - - const statements: Statement[] = []; - const body = node.body; - let statementOffset: number; - - startLexicalEnvironment(); - if (isBlock(body)) { - // ensureUseStrict is false because no new prologue-directive should be added. - // addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array - statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor); - } - - addCaptureThisForNodeIfNeeded(statements, node); - addDefaultValueAssignmentsIfNeeded(statements, node); - addRestParameterIfNeeded(statements, node, /*inConstructorWithSynthesizedSuper*/ false); - - // If we added any generated statements, this must be a multi-line block. - if (!multiLine && statements.length > 0) { - multiLine = true; - } - - if (isBlock(body)) { - statementsLocation = body.statements; - addRange(statements, visitNodes(body.statements, visitor, isStatement, statementOffset)); - - // If the original body was a multi-line block, this must be a multi-line block. - if (!multiLine && body.multiLine) { - multiLine = true; - } - } - else { - Debug.assert(node.kind === SyntaxKind.ArrowFunction); - - // To align with the old emitter, we use a synthetic end position on the location - // for the statement list we synthesize when we down-level an arrow function with - // an expression function body. This prevents both comments and source maps from - // being emitted for the end position only. - statementsLocation = moveRangeEnd(body, -1); - - const equalsGreaterThanToken = (node).equalsGreaterThanToken; - if (!nodeIsSynthesized(equalsGreaterThanToken) && !nodeIsSynthesized(body)) { - if (rangeEndIsOnSameLineAsRangeStart(equalsGreaterThanToken, body, currentSourceFile)) { - singleLine = true; - } - else { - multiLine = true; - } - } - - const expression = visitNode(body, visitor, isExpression); - const returnStatement = createReturn(expression, /*location*/ body); - setEmitFlags(returnStatement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTrailingComments); - statements.push(returnStatement); - - // To align with the source map emit for the old emitter, we set a custom - // source map location for the close brace. - closeBraceLocation = body; - } - - const lexicalEnvironment = endLexicalEnvironment(); - addRange(statements, lexicalEnvironment); - - // If we added any final generated statements, this must be a multi-line block - if (!multiLine && lexicalEnvironment && lexicalEnvironment.length) { - multiLine = true; - } - - const block = createBlock(createNodeArray(statements, statementsLocation), node.body, multiLine); - if (!multiLine && singleLine) { - setEmitFlags(block, EmitFlags.SingleLine); - } - - if (closeBraceLocation) { - setTokenSourceMapRange(block, SyntaxKind.CloseBraceToken, closeBraceLocation); - } - - setOriginalNode(block, node.body); - return block; - } - /** * Visits an ExpressionStatement that contains a destructuring assignment. * @@ -1926,171 +1600,7 @@ namespace ts { } function convertForOfToFor(node: ForOfStatement, convertedLoopBodyStatements: Statement[]): ForStatement { - // The following ES6 code: - // - // for (let v of expr) { } - // - // should be emitted as - // - // for (var _i = 0, _a = expr; _i < _a.length; _i++) { - // var v = _a[_i]; - // } - // - // where _a and _i are temps emitted to capture the RHS and the counter, - // respectively. - // When the left hand side is an expression instead of a let declaration, - // the "let v" is not emitted. - // When the left hand side is a let/const, the v is renamed if there is - // another v in scope. - // Note that all assignments to the LHS are emitted in the body, including - // all destructuring. - // Note also that because an extra statement is needed to assign to the LHS, - // for-of bodies are always emitted as blocks. - - const expression = visitNode(node.expression, visitor, isExpression); - const initializer = node.initializer; - const statements: Statement[] = []; - - // In the case where the user wrote an identifier as the RHS, like this: - // - // for (let v of arr) { } - // - // we don't want to emit a temporary variable for the RHS, just use it directly. - const counter = createLoopVariable(); - const rhsReference = expression.kind === SyntaxKind.Identifier - ? createUniqueName((expression).text) - : createTempVariable(/*recordTempVariable*/ undefined); - - // Initialize LHS - // var v = _a[_i]; - if (isVariableDeclarationList(initializer)) { - if (initializer.flags & NodeFlags.BlockScoped) { - enableSubstitutionsForBlockScopedBindings(); - } - - const firstOriginalDeclaration = firstOrUndefined(initializer.declarations); - if (firstOriginalDeclaration && isBindingPattern(firstOriginalDeclaration.name)) { - // This works whether the declaration is a var, let, or const. - // It will use rhsIterationValue _a[_i] as the initializer. - const declarations = flattenVariableDestructuring( - firstOriginalDeclaration, - createElementAccess(rhsReference, counter), - visitor - ); - - const declarationList = createVariableDeclarationList(declarations, /*location*/ initializer); - setOriginalNode(declarationList, initializer); - - // Adjust the source map range for the first declaration to align with the old - // emitter. - const firstDeclaration = declarations[0]; - const lastDeclaration = lastOrUndefined(declarations); - setSourceMapRange(declarationList, createRange(firstDeclaration.pos, lastDeclaration.end)); - - statements.push( - createVariableStatement( - /*modifiers*/ undefined, - declarationList - ) - ); - } - else { - // The following call does not include the initializer, so we have - // to emit it separately. - statements.push( - createVariableStatement( - /*modifiers*/ undefined, - setOriginalNode( - createVariableDeclarationList([ - createVariableDeclaration( - firstOriginalDeclaration ? firstOriginalDeclaration.name : createTempVariable(/*recordTempVariable*/ undefined), - /*type*/ undefined, - createElementAccess(rhsReference, counter) - ) - ], /*location*/ moveRangePos(initializer, -1)), - initializer - ), - /*location*/ moveRangeEnd(initializer, -1) - ) - ); - } - } - else { - // Initializer is an expression. Emit the expression in the body, so that it's - // evaluated on every iteration. - const assignment = createAssignment(initializer, createElementAccess(rhsReference, counter)); - if (isDestructuringAssignment(assignment)) { - // This is a destructuring pattern, so we flatten the destructuring instead. - statements.push( - createStatement( - flattenDestructuringAssignment( - context, - assignment, - /*needsValue*/ false, - hoistVariableDeclaration, - visitor - ) - ) - ); - } - else { - // Currently there is not way to check that assignment is binary expression of destructing assignment - // so we have to cast never type to binaryExpression - (assignment).end = initializer.end; - statements.push(createStatement(assignment, /*location*/ moveRangeEnd(initializer, -1))); - } - } - - let bodyLocation: TextRange; - let statementsLocation: TextRange; - if (convertedLoopBodyStatements) { - addRange(statements, convertedLoopBodyStatements); - } - else { - const statement = visitNode(node.statement, visitor, isStatement); - if (isBlock(statement)) { - addRange(statements, statement.statements); - bodyLocation = statement; - statementsLocation = statement.statements; - } - else { - statements.push(statement); - } - } - - // The old emitter does not emit source maps for the expression - setEmitFlags(expression, EmitFlags.NoSourceMap | getEmitFlags(expression)); - - // The old emitter does not emit source maps for the block. - // We add the location to preserve comments. - const body = createBlock( - createNodeArray(statements, /*location*/ statementsLocation), - /*location*/ bodyLocation - ); - - setEmitFlags(body, EmitFlags.NoSourceMap | EmitFlags.NoTokenSourceMaps); - - const forStatement = createFor( - setEmitFlags( - createVariableDeclarationList([ - createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0), /*location*/ moveRangePos(node.expression, -1)), - createVariableDeclaration(rhsReference, /*type*/ undefined, expression, /*location*/ node.expression) - ], /*location*/ node.expression), - EmitFlags.NoHoisting - ), - createLessThan( - counter, - createPropertyAccess(rhsReference, "length"), - /*location*/ node.expression - ), - createPostfixIncrement(counter, /*location*/ node.expression), - body, - /*location*/ node - ); - - // Disable trailing source maps for the OpenParenToken to align source map emit with the old emitter. - setEmitFlags(forStatement, EmitFlags.NoTokenTrailingSourceMaps); - return forStatement; + return convertForOf(node, convertedLoopBodyStatements, visitor, enableSubstitutionsForBlockScopedBindings, context, /*transformRest*/ false); } /** @@ -2751,7 +2261,7 @@ namespace ts { setEmitFlags(thisArg, EmitFlags.NoSubstitution); } let resultingCall: CallExpression | BinaryExpression; - if (node.transformFlags & TransformFlags.ContainsSpreadElementExpression) { + if (node.transformFlags & TransformFlags.ContainsSpreadExpression) { // [source] // f(...a, b) // x.m(...a, b) @@ -2813,7 +2323,7 @@ namespace ts { */ function visitNewExpression(node: NewExpression): LeftHandSideExpression { // We are here because we contain a SpreadElementExpression. - Debug.assert((node.transformFlags & TransformFlags.ContainsSpreadElementExpression) !== 0); + Debug.assert((node.transformFlags & TransformFlags.ContainsSpreadExpression) !== 0); // [source] // new C(...a) @@ -2834,7 +2344,7 @@ namespace ts { } /** - * Transforms an array of Expression nodes that contains a SpreadElementExpression. + * Transforms an array of Expression nodes that contains a SpreadExpression. * * @param elements The array of Expression nodes. * @param needsUniqueCopy A value indicating whether to ensure that the result is a fresh array. @@ -2851,14 +2361,14 @@ namespace ts { // expressions into an array literal. const numElements = elements.length; const segments = flatten( - spanMap(elements, partitionSpreadElement, (partition, visitPartition, _start, end) => + spanMap(elements, partitionSpread, (partition, visitPartition, _start, end) => visitPartition(partition, multiLine, hasTrailingComma && end === numElements) ) ); if (segments.length === 1) { const firstElement = elements[0]; - return needsUniqueCopy && isSpreadElementExpression(firstElement) && firstElement.expression.kind !== SyntaxKind.ArrayLiteralExpression + return needsUniqueCopy && isSpreadExpression(firstElement) && firstElement.expression.kind !== SyntaxKind.ArrayLiteralExpression ? createArraySlice(segments[0]) : segments[0]; } @@ -2867,17 +2377,17 @@ namespace ts { return createArrayConcat(segments.shift(), segments); } - function partitionSpreadElement(node: Expression) { - return isSpreadElementExpression(node) - ? visitSpanOfSpreadElements - : visitSpanOfNonSpreadElements; + function partitionSpread(node: Expression) { + return isSpreadExpression(node) + ? visitSpanOfSpreads + : visitSpanOfNonSpreads; } - function visitSpanOfSpreadElements(chunk: Expression[]): VisitResult { - return map(chunk, visitExpressionOfSpreadElement); + function visitSpanOfSpreads(chunk: Expression[]): VisitResult { + return map(chunk, visitExpressionOfSpread); } - function visitSpanOfNonSpreadElements(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): VisitResult { + function visitSpanOfNonSpreads(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): VisitResult { return createArrayLiteral( visitNodes(createNodeArray(chunk, /*location*/ undefined, hasTrailingComma), visitor, isExpression), /*location*/ undefined, @@ -2886,11 +2396,11 @@ namespace ts { } /** - * Transforms the expression of a SpreadElementExpression node. + * Transforms the expression of a SpreadExpression node. * - * @param node A SpreadElementExpression node. + * @param node A SpreadExpression node. */ - function visitExpressionOfSpreadElement(node: SpreadElementExpression) { + function visitExpressionOfSpread(node: SpreadElement) { return visitNode(node.expression, visitor, isExpression); } @@ -3076,7 +2586,7 @@ namespace ts { const statements: Statement[] = []; startLexicalEnvironment(); addRange(statements, prologue); - addCaptureThisForNodeIfNeeded(statements, node); + addCaptureThisForNodeIfNeeded(statements, node, enableSubstitutionsForCapturedThis); addRange(statements, visitNodes(createNodeArray(remaining), visitor, isStatement)); addRange(statements, endLexicalEnvironment()); const clone = getMutableClone(node); @@ -3266,11 +2776,11 @@ namespace ts { } const callArgument = singleOrUndefined((statementExpression).arguments); - if (!callArgument || !nodeIsSynthesized(callArgument) || callArgument.kind !== SyntaxKind.SpreadElementExpression) { + if (!callArgument || !nodeIsSynthesized(callArgument) || callArgument.kind !== SyntaxKind.SpreadElement) { return false; } - const expression = (callArgument).expression; + const expression = (callArgument).expression; return isIdentifier(expression) && expression === parameter.name; } } diff --git a/src/compiler/transformers/es2016.ts b/src/compiler/transformers/es2016.ts index fba1d300903..56d7fb0249a 100644 --- a/src/compiler/transformers/es2016.ts +++ b/src/compiler/transformers/es2016.ts @@ -32,7 +32,6 @@ namespace ts { switch (node.kind) { case SyntaxKind.BinaryExpression: return visitBinaryExpression(node); - default: Debug.failBadSyntaxKind(node); return visitEachChild(node, visitor, context); diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts new file mode 100644 index 00000000000..1fad209bdb3 --- /dev/null +++ b/src/compiler/transformers/esnext.ts @@ -0,0 +1,272 @@ +/// +/// + +/*@internal*/ +namespace ts { + export function transformESNext(context: TransformationContext) { + const { + hoistVariableDeclaration, + } = context; + let currentSourceFile: SourceFile; + return transformSourceFile; + + function transformSourceFile(node: SourceFile) { + currentSourceFile = node; + return visitEachChild(node, visitor, context); + } + + function visitor(node: Node): VisitResult { + if (node.transformFlags & TransformFlags.ESNext) { + return visitorWorker(node); + } + else if (node.transformFlags & TransformFlags.ContainsESNext) { + return visitEachChild(node, visitor, context); + } + else { + return node; + } + } + + function visitorWorker(node: Node): VisitResult { + switch (node.kind) { + case SyntaxKind.ObjectLiteralExpression: + return visitObjectLiteralExpression(node as ObjectLiteralExpression); + case SyntaxKind.BinaryExpression: + return visitBinaryExpression(node as BinaryExpression); + case SyntaxKind.VariableDeclaration: + return visitVariableDeclaration(node as VariableDeclaration); + case SyntaxKind.ForOfStatement: + return visitForOfStatement(node as ForOfStatement); + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.ArrayBindingPattern: + return node; + case SyntaxKind.FunctionDeclaration: + return visitFunctionDeclaration(node as FunctionDeclaration); + case SyntaxKind.FunctionExpression: + return visitFunctionExpression(node as FunctionExpression); + case SyntaxKind.ArrowFunction: + return visitArrowFunction(node as ArrowFunction); + case SyntaxKind.Parameter: + return visitParameter(node as ParameterDeclaration); + default: + Debug.failBadSyntaxKind(node); + return visitEachChild(node, visitor, context); + } + } + + function chunkObjectLiteralElements(elements: ObjectLiteralElement[]): Expression[] { + let chunkObject: (ShorthandPropertyAssignment | PropertyAssignment)[]; + const objects: Expression[] = []; + for (const e of elements) { + if (e.kind === SyntaxKind.SpreadAssignment) { + if (chunkObject) { + objects.push(createObjectLiteral(chunkObject)); + chunkObject = undefined; + } + const target = (e as SpreadAssignment).expression; + objects.push(visitNode(target, visitor, isExpression)); + } + else { + if (!chunkObject) { + chunkObject = []; + } + if (e.kind === SyntaxKind.PropertyAssignment) { + const p = e as PropertyAssignment; + chunkObject.push(createPropertyAssignment(p.name, visitNode(p.initializer, visitor, isExpression))); + } + else { + chunkObject.push(e as ShorthandPropertyAssignment); + } + } + } + if (chunkObject) { + objects.push(createObjectLiteral(chunkObject)); + } + + return objects; + } + + function visitObjectLiteralExpression(node: ObjectLiteralExpression): Expression { + // spread elements emit like so: + // non-spread elements are chunked together into object literals, and then all are passed to __assign: + // { a, ...o, b } => __assign({a}, o, {b}); + // If the first element is a spread element, then the first argument to __assign is {}: + // { ...o, a, b, ...o2 } => __assign({}, o, {a, b}, o2) + const objects = chunkObjectLiteralElements(node.properties); + if (objects.length && objects[0].kind !== SyntaxKind.ObjectLiteralExpression) { + objects.unshift(createObjectLiteral()); + } + return createCall(createIdentifier("__assign"), undefined, objects); + } + + /** + * Visits a BinaryExpression that contains a destructuring assignment. + * + * @param node A BinaryExpression node. + */ + function visitBinaryExpression(node: BinaryExpression): Expression { + if (isDestructuringAssignment(node) && node.left.transformFlags & TransformFlags.AssertESNext) { + return flattenDestructuringAssignment(context, node, /*needsDestructuringValue*/ true, hoistVariableDeclaration, visitor, /*transformRest*/ true); + } + + return visitEachChild(node, visitor, context); + } + + /** + * Visits a VariableDeclaration node with a binding pattern. + * + * @param node A VariableDeclaration node. + */ + function visitVariableDeclaration(node: VariableDeclaration): VisitResult { + // If we are here it is because the name contains a binding pattern with a rest somewhere in it. + if (isBindingPattern(node.name) && node.name.transformFlags & TransformFlags.AssertESNext) { + const result = flattenVariableDestructuring(node, /*value*/ undefined, visitor, /*recordTempVariable*/ undefined, /*transformRest*/ true); + return result; + } + + return visitEachChild(node, visitor, context); + } + + /** + * Visits a ForOfStatement and converts it into a ES2015-compatible ForOfStatement. + * + * @param node A ForOfStatement. + */ + function visitForOfStatement(node: ForOfStatement): VisitResult { + // The following ESNext code: + // + // for (let { x, y, ...rest } of expr) { } + // + // should be emitted as + // + // for (var _a of expr) { + // let { x, y } = _a, rest = __rest(_a, ["x", "y"]); + // } + // + // where _a is a temp emitted to capture the RHS. + // When the left hand side is an expression instead of a let declaration, + // the `let` before the `{ x, y }` is not emitted. + // When the left hand side is a let/const, the v is renamed if there is + // another v in scope. + // Note that all assignments to the LHS are emitted in the body, including + // all destructuring. + // Note also that because an extra statement is needed to assign to the LHS, + // for-of bodies are always emitted as blocks. + + // for ( of ) + // where is [let] variabledeclarationlist | expression + const initializer = node.initializer; + if (!isRestBindingPattern(initializer) && !isRestAssignment(initializer)) { + return visitEachChild(node, visitor, context); + } + + return convertForOf(node, undefined, visitor, noop, context, /*transformRest*/ true); + } + + function isRestBindingPattern(initializer: ForInitializer) { + if (isVariableDeclarationList(initializer)) { + const declaration = firstOrUndefined(initializer.declarations); + return declaration && declaration.name && + declaration.name.kind === SyntaxKind.ObjectBindingPattern && + !!(declaration.name.transformFlags & TransformFlags.ContainsSpreadExpression); + } + return false; + } + + function isRestAssignment(initializer: ForInitializer) { + return initializer.kind === SyntaxKind.ObjectLiteralExpression && + initializer.transformFlags & TransformFlags.ContainsSpreadExpression; + } + + function visitParameter(node: ParameterDeclaration): ParameterDeclaration { + if (isObjectRestParameter(node)) { + // Binding patterns are converted into a generated name and are + // evaluated inside the function body. + return setOriginalNode( + createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + getGeneratedNameForNode(node), + /*questionToken*/ undefined, + /*type*/ undefined, + node.initializer, + /*location*/ node + ), + /*original*/ node + ); + } + else { + return node; + } + } + + function isObjectRestParameter(node: ParameterDeclaration) { + return node.name && + node.name.kind === SyntaxKind.ObjectBindingPattern && + !!(node.name.transformFlags & TransformFlags.ContainsSpreadExpression); + } + + function visitFunctionDeclaration(node: FunctionDeclaration): FunctionDeclaration { + const hasRest = forEach(node.parameters, isObjectRestParameter); + const body = hasRest ? + transformFunctionBody(node, visitor, currentSourceFile, context, noop, /*convertObjectRest*/ true) as Block : + visitEachChild(node.body, visitor, context); + + return setOriginalNode( + createFunctionDeclaration( + /*decorators*/ undefined, + node.modifiers, + node.asteriskToken, + node.name, + /*typeParameters*/ undefined, + visitNodes(node.parameters, visitor, isParameter), + /*type*/ undefined, + body, + /*location*/ node + ), + /*original*/ node); + } + + function visitArrowFunction(node: ArrowFunction) { + const hasRest = forEach(node.parameters, isObjectRestParameter); + const body = hasRest ? + transformFunctionBody(node, visitor, currentSourceFile, context, noop, /*convertObjectRest*/ true) as Block : + visitEachChild(node.body, visitor, context); + const func = setOriginalNode( + createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + visitNodes(node.parameters, visitor, isParameter), + /*type*/ undefined, + node.equalsGreaterThanToken, + body, + /*location*/ node + ), + /*original*/ node + ); + setEmitFlags(func, EmitFlags.CapturesThis); + return func; + } + + function visitFunctionExpression(node: FunctionExpression): Expression { + const hasRest = forEach(node.parameters, isObjectRestParameter); + const body = hasRest ? + transformFunctionBody(node, visitor, currentSourceFile, context, noop, /*convertObjectRest*/ true) as Block : + visitEachChild(node.body, visitor, context); + return setOriginalNode( + createFunctionExpression( + /*modifiers*/ undefined, + node.asteriskToken, + name, + /*typeParameters*/ undefined, + visitNodes(node.parameters, visitor, isParameter), + /*type*/ undefined, + body, + /*location*/ node + ), + /*original*/ node + ); + } + } +} diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 95a4016bb0a..ba762cc5f12 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -113,7 +113,8 @@ namespace ts { || createAssignHelper(currentSourceFile.externalHelpersModuleName, segments); } - const element = createReactCreateElement( + const element = createExpressionForJsxElement( + context.getEmitResolver().getJsxFactoryEntity(), compilerOptions.reactNamespace, tagName, objectProperties, diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index adc9385935b..0524b9354d2 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1474,7 +1474,7 @@ namespace ts { if (isAssignmentExpression(node)) { return hasExportedReferenceInDestructuringTarget(node.left); } - else if (isSpreadElementExpression(node)) { + else if (isSpreadExpression(node)) { return hasExportedReferenceInDestructuringTarget(node.expression); } else if (isObjectLiteralExpression(node)) { diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 1362746ba57..89fa039100a 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -471,7 +471,11 @@ namespace ts { currentSourceFile = node; // ensure "use strict" is emitted in all scenarios in alwaysStrict mode - if (compilerOptions.alwaysStrict) { + // There is no need to emit "use strict" in the following cases: + // 1. The file is an external module and target is es2015 or higher + // or 2. The file is an external module and module-kind is es6 or es2015 as such value is not allowed when targeting es5 or lower + if (compilerOptions.alwaysStrict && + !(isExternalModule(node) && (compilerOptions.target >= ScriptTarget.ES2015 || compilerOptions.module === ModuleKind.ES2015))) { node = ensureUseStrict(node); } diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index f63bdf20e34..bd70a0afb10 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -27,6 +27,7 @@ "visitor.ts", "transformers/ts.ts", "transformers/jsx.ts", + "transformers/esnext.ts", "transformers/es2017.ts", "transformers/es2016.ts", "transformers/es2015.ts", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fb1dffad87d..c814a2b1d46 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -246,7 +246,7 @@ namespace ts { ConditionalExpression, TemplateExpression, YieldExpression, - SpreadElementExpression, + SpreadElement, ClassExpression, OmittedExpression, ExpressionWithTypeArguments, @@ -320,6 +320,7 @@ namespace ts { // Property assignments PropertyAssignment, ShorthandPropertyAssignment, + SpreadAssignment, // Enum EnumMember, @@ -418,20 +419,21 @@ namespace ts { HasDecorators = 1 << 11, // If the file has decorators (initialized by binding) HasParamDecorators = 1 << 12, // If the file has parameter decorators (initialized by binding) HasAsyncFunctions = 1 << 13, // If the file has async functions (initialized by binding) - HasJsxSpreadAttributes = 1 << 14, // If the file as JSX spread attributes (initialized by binding) - DisallowInContext = 1 << 15, // If node was parsed in a context where 'in-expressions' are not allowed - YieldContext = 1 << 16, // If node was parsed in the 'yield' context created when parsing a generator - DecoratorContext = 1 << 17, // If node was parsed as part of a decorator - AwaitContext = 1 << 18, // If node was parsed in the 'await' context created when parsing an async function - ThisNodeHasError = 1 << 19, // If the parser encountered an error when parsing the code that created this node - JavaScriptFile = 1 << 20, // If node was parsed in a JavaScript - ThisNodeOrAnySubNodesHasError = 1 << 21, // If this node or any of its children had an error - HasAggregatedChildData = 1 << 22, // If we've computed data from children and cached it in this node + HasSpreadAttribute = 1 << 14, // If the file as JSX spread attributes (initialized by binding) + HasRestAttribute = 1 << 15, // If the file has object destructure elements + DisallowInContext = 1 << 16, // If node was parsed in a context where 'in-expressions' are not allowed + YieldContext = 1 << 17, // If node was parsed in the 'yield' context created when parsing a generator + DecoratorContext = 1 << 18, // If node was parsed as part of a decorator + AwaitContext = 1 << 19, // If node was parsed in the 'await' context created when parsing an async function + ThisNodeHasError = 1 << 20, // If the parser encountered an error when parsing the code that created this node + JavaScriptFile = 1 << 21, // If node was parsed in a JavaScript + ThisNodeOrAnySubNodesHasError = 1 << 22, // If this node or any of its children had an error + HasAggregatedChildData = 1 << 23, // If we've computed data from children and cached it in this node BlockScoped = Let | Const, ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, - EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasJsxSpreadAttributes, + EmitHelperFlags = HasClassExtends | HasDecorators | HasParamDecorators | HasAsyncFunctions | HasSpreadAttribute | HasRestAttribute, ReachabilityAndEmitFlags = ReachabilityCheckFlags | EmitHelperFlags, // Parsing context flags @@ -454,7 +456,6 @@ namespace ts { Async = 1 << 8, // Property/Method/Function Default = 1 << 9, // Function/Class (export default declaration) Const = 1 << 11, // Variable declaration - HasComputedFlags = 1 << 29, // Modifier flags have been computed AccessibilityModifier = Public | Private | Protected, @@ -649,7 +650,7 @@ namespace ts { export interface BindingElement extends Declaration { kind: SyntaxKind.BindingElement; propertyName?: PropertyName; // Binding property name (in object binding pattern) - dotDotDotToken?: DotDotDotToken; // Present on rest binding element + dotDotDotToken?: DotDotDotToken; // Present on rest element (in object binding pattern) name: BindingName; // Declared binding element name initializer?: Expression; // Optional initializer } @@ -675,7 +676,7 @@ namespace ts { name?: PropertyName; } - export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration; + export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration | SpreadAssignment; export interface PropertyAssignment extends ObjectLiteralElement { kind: SyntaxKind.PropertyAssignment; @@ -694,6 +695,11 @@ namespace ts { objectAssignmentInitializer?: Expression; } + export interface SpreadAssignment extends ObjectLiteralElement { + kind: SyntaxKind.SpreadAssignment; + expression: Expression; + } + // SyntaxKind.VariableDeclaration // SyntaxKind.Parameter // SyntaxKind.BindingElement @@ -1279,8 +1285,8 @@ namespace ts { multiLine?: boolean; } - export interface SpreadElementExpression extends Expression { - kind: SyntaxKind.SpreadElementExpression; + export interface SpreadElement extends Expression { + kind: SyntaxKind.SpreadElement; expression: Expression; } @@ -2381,6 +2387,12 @@ namespace ts { CannotBeNamed } + /* @internal */ + export const enum SyntheticSymbolKind { + UnionOrIntersection, + Spread + } + export const enum TypePredicateKind { This, Identifier @@ -2473,6 +2485,7 @@ namespace ts { getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[]; isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: SymbolWriter): void; + getJsxFactoryEntity(): EntityName; } export const enum SymbolFlags { @@ -2592,7 +2605,9 @@ namespace ts { instantiations?: Map; // Instantiations of generic type alias (undefined if non-generic) 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 + containingType?: UnionOrIntersectionType; // Containing union or intersection type for synthetic property + leftSpread?: Symbol; // Left source for synthetic spread property + rightSpread?: Symbol; // Right source for synthetic spread property hasNonUniformType?: boolean; // True if constituents have non-uniform types isPartial?: boolean; // True if syntheric property of union type occurs in some but not all constituents isDiscriminantProperty?: boolean; // True if discriminant synthetic property @@ -3060,7 +3075,7 @@ namespace ts { moduleResolution?: ModuleResolutionKind; newLine?: NewLineKind; noEmit?: boolean; - /*@internal*/noEmitOverwritenFiles?: boolean; + /*@internal*/noEmitForJsFiles?: boolean; noEmitHelpers?: boolean; noEmitOnError?: boolean; noErrorTruncation?: boolean; @@ -3081,6 +3096,7 @@ namespace ts { project?: string; /* @internal */ pretty?: DiagnosticStyle; reactNamespace?: string; + jsxFactory?: string; removeComments?: boolean; rootDir?: string; rootDirs?: string[]; @@ -3163,7 +3179,8 @@ namespace ts { ES2015 = 2, ES2016 = 3, ES2017 = 4, - Latest = ES2017, + ESNext = 5, + Latest = ESNext, } export const enum LanguageVariant { @@ -3478,32 +3495,34 @@ namespace ts { ContainsTypeScript = 1 << 1, Jsx = 1 << 2, ContainsJsx = 1 << 3, - ES2017 = 1 << 4, - ContainsES2017 = 1 << 5, - ES2016 = 1 << 6, - ContainsES2016 = 1 << 7, - ES2015 = 1 << 8, - ContainsES2015 = 1 << 9, - Generator = 1 << 10, - ContainsGenerator = 1 << 11, - DestructuringAssignment = 1 << 12, - ContainsDestructuringAssignment = 1 << 13, + ESNext = 1 << 4, + ContainsESNext = 1 << 5, + ES2017 = 1 << 6, + ContainsES2017 = 1 << 7, + ES2016 = 1 << 8, + ContainsES2016 = 1 << 9, + ES2015 = 1 << 10, + ContainsES2015 = 1 << 11, + Generator = 1 << 12, + ContainsGenerator = 1 << 13, + DestructuringAssignment = 1 << 14, + ContainsDestructuringAssignment = 1 << 15, // Markers // - Flags used to indicate that a subtree contains a specific transformation. - ContainsDecorators = 1 << 14, - ContainsPropertyInitializer = 1 << 15, - ContainsLexicalThis = 1 << 16, - ContainsCapturedLexicalThis = 1 << 17, - ContainsLexicalThisInComputedPropertyName = 1 << 18, - ContainsDefaultValueAssignments = 1 << 19, - ContainsParameterPropertyAssignments = 1 << 20, - ContainsSpreadElementExpression = 1 << 21, - ContainsComputedPropertyName = 1 << 22, - ContainsBlockScopedBinding = 1 << 23, - ContainsBindingPattern = 1 << 24, - ContainsYield = 1 << 25, - ContainsHoistedDeclarationOrCompletion = 1 << 26, + ContainsDecorators = 1 << 16, + ContainsPropertyInitializer = 1 << 17, + ContainsLexicalThis = 1 << 18, + ContainsCapturedLexicalThis = 1 << 19, + ContainsLexicalThisInComputedPropertyName = 1 << 20, + ContainsDefaultValueAssignments = 1 << 21, + ContainsParameterPropertyAssignments = 1 << 22, + ContainsSpreadExpression = 1 << 23, + ContainsComputedPropertyName = 1 << 24, + ContainsBlockScopedBinding = 1 << 25, + ContainsBindingPattern = 1 << 26, + ContainsYield = 1 << 27, + ContainsHoistedDeclarationOrCompletion = 1 << 28, HasComputedFlags = 1 << 29, // Transform flags have been computed. @@ -3511,6 +3530,7 @@ namespace ts { // - Bitmasks that are used to assert facts about the syntax of a node and its subtree. AssertTypeScript = TypeScript | ContainsTypeScript, AssertJsx = Jsx | ContainsJsx, + AssertESNext = ESNext | ContainsESNext, AssertES2017 = ES2017 | ContainsES2017, AssertES2016 = ES2016 | ContainsES2016, AssertES2015 = ES2015 | ContainsES2015, @@ -3520,7 +3540,7 @@ namespace ts { // Scope Exclusions // - Bitmasks that exclude flags from propagating out of a specific context // into the subtree flags of their container. - NodeExcludes = TypeScript | Jsx | ES2017 | ES2016 | ES2015 | DestructuringAssignment | Generator | HasComputedFlags, + NodeExcludes = TypeScript | Jsx | ESNext | ES2017 | ES2016 | ES2015 | DestructuringAssignment | Generator | HasComputedFlags, ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion, FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion, ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclarationOrCompletion, @@ -3529,7 +3549,7 @@ namespace ts { ModuleExcludes = NodeExcludes | ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion, TypeExcludes = ~ContainsTypeScript, ObjectLiteralExcludes = NodeExcludes | ContainsDecorators | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName, - ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsSpreadElementExpression, + ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsSpreadExpression, VariableDeclarationListExcludes = NodeExcludes | ContainsBindingPattern, ParameterExcludes = NodeExcludes | ContainsBindingPattern, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 299f91be662..a9f2429d376 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -192,7 +192,7 @@ namespace ts { export function nodePosToString(node: Node): string { const file = getSourceFileOfNode(node); const loc = getLineAndCharacterOfPosition(file, node.pos); - return `${ file.fileName }(${ loc.line + 1 },${ loc.character + 1 })`; + return `${file.fileName}(${loc.line + 1},${loc.character + 1})`; } export function getStartPosOfNode(node: Node): number { @@ -439,7 +439,7 @@ namespace ts { } export function isBlockScope(node: Node, parentNode: Node) { - switch (node.kind) { + switch (node.kind) { case SyntaxKind.SourceFile: case SyntaxKind.CaseBlock: case SyntaxKind.CatchClause: @@ -485,6 +485,22 @@ namespace ts { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } + export function getTextOfPropertyName(name: PropertyName): string { + switch (name.kind) { + case SyntaxKind.Identifier: + return (name).text; + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + return (name).text; + case SyntaxKind.ComputedPropertyName: + if (isStringOrNumericLiteral((name).expression.kind)) { + return ((name).expression).text; + } + } + + return undefined; + } + export function entityNameToString(name: EntityNameOrEntityNameExpression): string { switch (name.kind) { case SyntaxKind.Identifier: @@ -498,6 +514,10 @@ namespace ts { export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { const sourceFile = getSourceFileOfNode(node); + return createDiagnosticForNodeInSourceFile(sourceFile, node, message, arg0, arg1, arg2); + } + + export function createDiagnosticForNodeInSourceFile(sourceFile: SourceFile, node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { const span = getErrorSpanForNode(sourceFile, node); return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); } @@ -624,9 +644,9 @@ namespace ts { export function getJsDocCommentsFromText(node: Node, text: string) { const commentRanges = (node.kind === SyntaxKind.Parameter || - node.kind === SyntaxKind.TypeParameter || - node.kind === SyntaxKind.FunctionExpression || - node.kind === SyntaxKind.ArrowFunction) ? + node.kind === SyntaxKind.TypeParameter || + node.kind === SyntaxKind.FunctionExpression || + node.kind === SyntaxKind.ArrowFunction) ? concatenate(getTrailingCommentRanges(text, node.pos), getLeadingCommentRanges(text, node.pos)) : getLeadingCommentRangesOfNodeFromText(node, text); return filter(commentRanges, isJsDocComment); @@ -891,7 +911,7 @@ namespace ts { export function isObjectLiteralOrClassExpressionMethod(node: Node): node is MethodDeclaration { return node.kind === SyntaxKind.MethodDeclaration && (node.parent.kind === SyntaxKind.ObjectLiteralExpression || - node.parent.kind === SyntaxKind.ClassExpression); + node.parent.kind === SyntaxKind.ClassExpression); } export function isIdentifierTypePredicate(predicate: TypePredicate): predicate is IdentifierTypePredicate { @@ -1113,8 +1133,8 @@ namespace ts { // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target; return (node.parent).body !== undefined && (node.parent.kind === SyntaxKind.Constructor - || node.parent.kind === SyntaxKind.MethodDeclaration - || node.parent.kind === SyntaxKind.SetAccessor) + || node.parent.kind === SyntaxKind.MethodDeclaration + || node.parent.kind === SyntaxKind.SetAccessor) && node.parent.parent.kind === SyntaxKind.ClassDeclaration; } @@ -1179,7 +1199,7 @@ namespace ts { case SyntaxKind.PostfixUnaryExpression: case SyntaxKind.BinaryExpression: case SyntaxKind.ConditionalExpression: - case SyntaxKind.SpreadElementExpression: + case SyntaxKind.SpreadElement: case SyntaxKind.TemplateExpression: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.OmittedExpression: @@ -1461,7 +1481,7 @@ namespace ts { }, tags => tags); } - function getJSDocs(node: Node, checkParentVariableStatement: boolean, getDocs: (docs: JSDoc[]) => T[], getTags: (tags: JSDocTag[]) => T[]): T[] { + function getJSDocs(node: Node, checkParentVariableStatement: boolean, getDocs: (docs: JSDoc[]) => T[], getTags: (tags: JSDocTag[]) => T[]): T[] { // TODO: Get rid of getJsDocComments and friends (note the lowercase 's' in Js) // TODO: A lot of this work should be cached, maybe. I guess it's only used in services right now... let result: T[] = undefined; @@ -1482,8 +1502,8 @@ namespace ts { const variableStatementNode = isInitializerOfVariableDeclarationInStatement ? node.parent.parent.parent : - isVariableOfVariableDeclarationStatement ? node.parent.parent : - undefined; + isVariableOfVariableDeclarationStatement ? node.parent.parent : + undefined; if (variableStatementNode) { result = append(result, getJSDocs(variableStatementNode, checkParentVariableStatement, getDocs, getTags)); } @@ -1641,14 +1661,14 @@ namespace ts { return (parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None; case SyntaxKind.ParenthesizedExpression: case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.SpreadElementExpression: + case SyntaxKind.SpreadElement: node = parent; break; case SyntaxKind.ShorthandPropertyAssignment: if ((parent).name !== node) { return AssignmentKind.None; } - // Fall through + // Fall through case SyntaxKind.PropertyAssignment: node = parent.parent; break; @@ -2226,7 +2246,7 @@ namespace ts { case SyntaxKind.YieldExpression: return 2; - case SyntaxKind.SpreadElementExpression: + case SyntaxKind.SpreadElement: return 1; default: @@ -2550,22 +2570,39 @@ namespace ts { if (options.outFile || options.out) { const moduleKind = getEmitModuleKind(options); const moduleEmitEnabled = moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.System; - const sourceFiles = host.getSourceFiles(); + const sourceFiles = getAllEmittableSourceFiles(); // Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified return filter(sourceFiles, moduleEmitEnabled ? isNonDeclarationFile : isBundleEmitNonExternalModule); } else { - const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile]; - return filter(sourceFiles, isNonDeclarationFile); + const sourceFiles = targetSourceFile === undefined ? getAllEmittableSourceFiles() : [targetSourceFile]; + return filterSourceFilesInDirectory(sourceFiles, file => host.isSourceFileFromExternalLibrary(file)); } + + function getAllEmittableSourceFiles() { + return options.noEmitForJsFiles ? filter(host.getSourceFiles(), sourceFile => !isSourceFileJavaScript(sourceFile)) : host.getSourceFiles(); + } + } + + /** Don't call this for `--outFile`, just for `--outDir` or plain emit. */ + export function filterSourceFilesInDirectory(sourceFiles: SourceFile[], isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): SourceFile[] { + return filter(sourceFiles, file => shouldEmitInDirectory(file, isSourceFileFromExternalLibrary)); } function isNonDeclarationFile(sourceFile: SourceFile) { return !isDeclarationFile(sourceFile); } + /** + * Whether a file should be emitted in a non-`--outFile` case. + * Don't emit if source file is a declaration file, or was located under node_modules + */ + function shouldEmitInDirectory(sourceFile: SourceFile, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean): boolean { + return isNonDeclarationFile(sourceFile) && !isSourceFileFromExternalLibrary(sourceFile); + } + function isBundleEmitNonExternalModule(sourceFile: SourceFile) { - return !isDeclarationFile(sourceFile) && !isExternalModule(sourceFile); + return isNonDeclarationFile(sourceFile) && !isExternalModule(sourceFile); } /** @@ -2589,7 +2626,7 @@ namespace ts { } else { for (const sourceFile of sourceFiles) { - // Don't emit if source file is a declaration file, or was located under node_modules + // Don't emit if source file is a declaration file, or was located under node_modules if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) { onSingleFileEmit(host, sourceFile); } @@ -2651,10 +2688,9 @@ namespace ts { onBundledEmit(host); } else { - const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile]; + const sourceFiles = targetSourceFile === undefined ? getSourceFilesToEmit(host) : [targetSourceFile]; for (const sourceFile of sourceFiles) { - // Don't emit if source file is a declaration file, or was located under node_modules - if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) { + if (shouldEmitInDirectory(sourceFile, file => host.isSourceFileFromExternalLibrary(file))) { onSingleFileEmit(host, sourceFile); } } @@ -2689,11 +2725,11 @@ namespace ts { function onBundledEmit(host: EmitHost) { // Can emit only sources that are not declaration file and are either non module code or module with // --module or --target es6 specified. Files included by searching under node_modules are also not emitted. - const bundledSources = filter(host.getSourceFiles(), + const bundledSources = filter(getSourceFilesToEmit(host), sourceFile => !isDeclarationFile(sourceFile) && - !host.isSourceFileFromExternalLibrary(sourceFile) && - (!isExternalModule(sourceFile) || - !!getEmitModuleKind(options))); + !host.isSourceFileFromExternalLibrary(sourceFile) && + (!isExternalModule(sourceFile) || + !!getEmitModuleKind(options))); if (bundledSources.length) { const jsFilePath = options.outFile || options.out; const emitFileNames: EmitFileNames = { @@ -2879,7 +2915,7 @@ namespace ts { writeComment: (text: string, lineMap: number[], writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) => void, node: TextRange, newLine: string, removeComments: boolean) { let leadingComments: CommentRange[]; - let currentDetachedCommentInfo: {nodePos: number, detachedCommentEndPos: number}; + let currentDetachedCommentInfo: { nodePos: number, detachedCommentEndPos: number }; if (removeComments) { // removeComments is true, only reserve pinned comment at the top of file // For example: @@ -3226,10 +3262,10 @@ namespace ts { function stringifyValue(value: any): string { return typeof value === "string" ? `"${escapeString(value)}"` - : typeof value === "number" ? isFinite(value) ? String(value) : "null" - : typeof value === "boolean" ? value ? "true" : "false" - : typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value) - : /*fallback*/ "null"; + : typeof value === "number" ? isFinite(value) ? String(value) : "null" + : typeof value === "boolean" ? value ? "true" : "false" + : typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value) + : /*fallback*/ "null"; } function cycleCheck(cb: (value: any) => string, value: any) { @@ -3254,7 +3290,7 @@ namespace ts { function stringifyProperty(memo: string, value: any, key: string) { return value === undefined || typeof value === "function" || key === "__cycle" ? memo - : (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`; + : (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`; } const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; @@ -3499,7 +3535,7 @@ namespace ts { * @param token The token. */ export function createTokenRange(pos: number, token: SyntaxKind): TextRange { - return createRange(pos, pos + tokenToString(token).length); + return createRange(pos, pos + tokenToString(token).length); } export function rangeIsOnSingleLine(range: TextRange, sourceFile: SourceFile) { @@ -3862,6 +3898,7 @@ namespace ts { const kind = node.kind; return kind === SyntaxKind.PropertyAssignment || kind === SyntaxKind.ShorthandPropertyAssignment + || kind === SyntaxKind.SpreadAssignment || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.GetAccessor || kind === SyntaxKind.SetAccessor @@ -3949,8 +3986,8 @@ namespace ts { || kind === SyntaxKind.NoSubstitutionTemplateLiteral; } - export function isSpreadElementExpression(node: Node): node is SpreadElementExpression { - return node.kind === SyntaxKind.SpreadElementExpression; + export function isSpreadExpression(node: Node): node is SpreadElement { + return node.kind === SyntaxKind.SpreadElement; } export function isExpressionWithTypeArguments(node: Node): node is ExpressionWithTypeArguments { @@ -4008,7 +4045,7 @@ namespace ts { || kind === SyntaxKind.YieldExpression || kind === SyntaxKind.ArrowFunction || kind === SyntaxKind.BinaryExpression - || kind === SyntaxKind.SpreadElementExpression + || kind === SyntaxKind.SpreadElement || kind === SyntaxKind.AsExpression || kind === SyntaxKind.OmittedExpression || isUnaryExpressionKind(kind); @@ -4310,6 +4347,7 @@ namespace ts { namespace ts { export function getDefaultLibFileName(options: CompilerOptions): string { switch (options.target) { + case ScriptTarget.ESNext: case ScriptTarget.ES2017: return "lib.es2017.d.ts"; case ScriptTarget.ES2016: diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 34cc2e07436..cc27d5c9ddf 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -267,9 +267,9 @@ namespace ts { case SyntaxKind.VoidExpression: case SyntaxKind.AwaitExpression: case SyntaxKind.YieldExpression: - case SyntaxKind.SpreadElementExpression: + case SyntaxKind.SpreadElement: case SyntaxKind.NonNullExpression: - result = reduceNode((node).expression, f, result); + result = reduceNode((node).expression, f, result); break; case SyntaxKind.PrefixUnaryExpression: @@ -510,6 +510,10 @@ namespace ts { result = reduceNode((node).objectAssignmentInitializer, f, result); break; + case SyntaxKind.SpreadAssignment: + result = reduceNode((node as SpreadAssignment).expression, f, result); + break; + // Top-level nodes case SyntaxKind.SourceFile: result = reduceLeft((node).statements, f, result); @@ -872,9 +876,9 @@ namespace ts { return updateYield(node, visitNode((node).expression, visitor, isExpression)); - case SyntaxKind.SpreadElementExpression: - return updateSpread(node, - visitNode((node).expression, visitor, isExpression)); + case SyntaxKind.SpreadElement: + return updateSpread(node, + visitNode((node).expression, visitor, isExpression)); case SyntaxKind.ClassExpression: return updateClassExpression(node, @@ -1127,7 +1131,11 @@ namespace ts { visitNode((node).name, visitor, isIdentifier), visitNode((node).objectAssignmentInitializer, visitor, isExpression)); - // Top-level nodes + case SyntaxKind.SpreadAssignment: + return updateSpreadAssignment(node as SpreadAssignment, + visitNode((node as SpreadAssignment).expression, visitor, isExpression)); + + // Top-level nodes case SyntaxKind.SourceFile: context.startLexicalEnvironment(); return updateSourceFileNode(node, diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 70c6fdac329..327932f3667 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -170,7 +170,7 @@ class CompilerBaselineRunner extends RunnerBase { }); it("Correct Sourcemap output for " + fileName, () => { - Harness.Compiler.doSourcemapBaseline(justName, options, result); + Harness.Compiler.doSourcemapBaseline(justName, options, result, harnessSettings); }); it("Correct type/symbol baselines for " + fileName, () => { diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ae32fe3db16..6ff4dccdee3 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1026,7 +1026,7 @@ namespace FourSlash { ts.displayPartsToString(help.suffixDisplayParts), expected); } - public verifyCurrentParameterIsletiable(isVariable: boolean) { + public verifyCurrentParameterIsVariable(isVariable: boolean) { const signature = this.getActiveSignatureHelpItem(); assert.isOk(signature); assert.equal(isVariable, signature.isVariadic); @@ -1053,6 +1053,10 @@ namespace FourSlash { assert.equal(this.getActiveSignatureHelpItem().parameters.length, expectedCount); } + public verifyCurrentSignatureHelpIsVariadic(expected: boolean) { + assert.equal(this.getActiveSignatureHelpItem().isVariadic, expected); + } + public verifyCurrentSignatureHelpDocComment(docComment: string) { const actualDocComment = this.getActiveSignatureHelpItem().documentation; assert.equal(ts.displayPartsToString(actualDocComment), docComment, this.assertionMessageAtLastKnownMarker("current signature help doc comment")); @@ -3231,6 +3235,10 @@ namespace FourSlashInterface { this.state.verifySignatureHelpCount(expected); } + public signatureHelpCurrentArgumentListIsVariadic(expected: boolean) { + this.state.verifyCurrentSignatureHelpIsVariadic(expected); + } + public signatureHelpArgumentCountIs(expected: number) { this.state.verifySignatureHelpArgumentCount(expected); } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index a6e1ffad7f7..6c5e49a70d7 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -470,19 +470,6 @@ namespace Utils { } } -namespace Harness.Path { - export function getFileName(fullPath: string) { - return fullPath.replace(/^.*[\\\/]/, ""); - } - - export function filePath(fullPath: string) { - fullPath = ts.normalizeSlashes(fullPath); - const components = fullPath.split("/"); - const path: string[] = components.slice(0, components.length - 1); - return path.join("/") + "/"; - } -} - namespace Harness { export interface IO { newLine(): string; @@ -1090,7 +1077,9 @@ namespace Harness { { name: "suppressOutputPathCheck", type: "boolean" }, { name: "noImplicitReferences", type: "boolean" }, { name: "currentDirectory", type: "string" }, - { name: "symlink", type: "string" } + { name: "symlink", type: "string" }, + // Emitted js baseline will print full paths for every output file + { name: "fullEmitPaths", type: "boolean" } ]; let optionsIndex: ts.Map; @@ -1483,7 +1472,7 @@ namespace Harness { } if (typesError && symbolsError) { - throw new Error(typesError.message + ts.sys.newLine + symbolsError.message); + throw new Error(typesError.message + Harness.IO.newLine() + symbolsError.message); } if (typesError) { @@ -1565,7 +1554,7 @@ namespace Harness { return file.writeByteOrderMark ? "\u00EF\u00BB\u00BF" : ""; } - export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult) { + export function doSourcemapBaseline(baselinePath: string, options: ts.CompilerOptions, result: CompilerResult, harnessSettings: Harness.TestCaseParser.CompilerSettings) { if (options.inlineSourceMap) { if (result.sourceMaps.length > 0) { throw new Error("No sourcemap files should be generated if inlineSourceMaps was set."); @@ -1587,10 +1576,8 @@ namespace Harness { } let sourceMapCode = ""; - for (let i = 0; i < result.sourceMaps.length; i++) { - sourceMapCode += "//// [" + Harness.Path.getFileName(result.sourceMaps[i].fileName) + "]\r\n"; - sourceMapCode += getByteOrderMarkText(result.sourceMaps[i]); - sourceMapCode += result.sourceMaps[i].code; + for (const sourceMap of result.sourceMaps) { + sourceMapCode += fileOutput(sourceMap, harnessSettings); } return sourceMapCode; @@ -1611,23 +1598,19 @@ namespace Harness { tsCode += "//// [" + header + "] ////\r\n\r\n"; } for (let i = 0; i < tsSources.length; i++) { - tsCode += "//// [" + Harness.Path.getFileName(tsSources[i].unitName) + "]\r\n"; + tsCode += "//// [" + ts.getBaseFileName(tsSources[i].unitName) + "]\r\n"; tsCode += tsSources[i].content + (i < (tsSources.length - 1) ? "\r\n" : ""); } let jsCode = ""; - for (let i = 0; i < result.files.length; i++) { - jsCode += "//// [" + Harness.Path.getFileName(result.files[i].fileName) + "]\r\n"; - jsCode += getByteOrderMarkText(result.files[i]); - jsCode += result.files[i].code; + for (const file of result.files) { + jsCode += fileOutput(file, harnessSettings); } if (result.declFilesCode.length > 0) { jsCode += "\r\n\r\n"; - for (let i = 0; i < result.declFilesCode.length; i++) { - jsCode += "//// [" + Harness.Path.getFileName(result.declFilesCode[i].fileName) + "]\r\n"; - jsCode += getByteOrderMarkText(result.declFilesCode[i]); - jsCode += result.declFilesCode[i].code; + for (const declFile of result.declFilesCode) { + jsCode += fileOutput(declFile, harnessSettings); } } @@ -1652,6 +1635,11 @@ namespace Harness { }); } + function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string { + const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName); + return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code; + } + export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string { // Collect, test, and sort the fileNames outputFiles.sort((a, b) => ts.compareStrings(cleanName(a.fileName), cleanName(b.fileName))); @@ -1768,7 +1756,7 @@ namespace Harness { } // Regex for parsing options in the format "@Alpha: Value of any sort" - const optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*(\S*)/gm; // multiple matches on multiple lines + const optionRegex = /^[\/]{2}\s*@(\w+)\s*:\s*([^\r\n]*)/gm; // multiple matches on multiple lines function extractCompilerSettings(content: string): CompilerSettings { const opts: CompilerSettings = {}; @@ -1777,7 +1765,7 @@ namespace Harness { /* tslint:disable:no-null-keyword */ while ((match = optionRegex.exec(content)) !== null) { /* tslint:enable:no-null-keyword */ - opts[match[1]] = match[2]; + opts[match[1]] = match[2].trim(); } return opts; @@ -1805,7 +1793,7 @@ namespace Harness { // Comment line, check for global/file @options and record them optionRegex.lastIndex = 0; const metaDataName = testMetaData[1].toLowerCase(); - currentFileOptions[testMetaData[1]] = testMetaData[2]; + currentFileOptions[testMetaData[1]] = testMetaData[2].trim(); if (metaDataName !== "filename") { continue; } @@ -1825,12 +1813,12 @@ namespace Harness { // Reset local data currentFileContent = undefined; currentFileOptions = {}; - currentFileName = testMetaData[2]; + currentFileName = testMetaData[2].trim(); refs = []; } else { // First metadata marker in the file - currentFileName = testMetaData[2]; + currentFileName = testMetaData[2].trim(); } } else { @@ -1848,7 +1836,7 @@ namespace Harness { } // normalize the fileName for the single file case - currentFileName = testUnitData.length > 0 || currentFileName ? currentFileName : Path.getFileName(fileName); + currentFileName = testUnitData.length > 0 || currentFileName ? currentFileName : ts.getBaseFileName(fileName); // EOF, push whatever remains const newTestFile2 = { @@ -2012,7 +2000,7 @@ namespace Harness { export function isDefaultLibraryFile(filePath: string): boolean { // We need to make sure that the filePath is prefixed with "lib." not just containing "lib." and end with ".d.ts" - const fileName = Path.getFileName(filePath); + const fileName = ts.getBaseFileName(filePath); return ts.startsWith(fileName, "lib.") && ts.endsWith(fileName, ".d.ts"); } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 889d4f28ce9..a49f8926729 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -720,6 +720,10 @@ namespace Harness.LanguageService { clearImmediate(timeoutId: any): void { clearImmediate(timeoutId); } + + createHash(s: string) { + return s; + } } export class ServerLanguageServiceAdapter implements LanguageServiceAdapter { diff --git a/src/harness/runnerbase.ts b/src/harness/runnerbase.ts index 346382b7a57..d50604803ed 100644 --- a/src/harness/runnerbase.ts +++ b/src/harness/runnerbase.ts @@ -32,7 +32,7 @@ abstract class RunnerBase { /** Replaces instances of full paths with fileNames only */ static removeFullPaths(path: string) { // If its a full path (starts with "C:" or "/") replace with just the filename - let fixedPath = /^(\w:|\/)/.test(path) ? Harness.Path.getFileName(path) : path; + let fixedPath = /^(\w:|\/)/.test(path) ? ts.getBaseFileName(path) : path; // when running in the browser the 'full path' is the host name, shows up in error baselines const localHost = /http:\/localhost:\d+/g; diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 8bf3139b9de..d3a814f26ca 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -29,6 +29,7 @@ "../compiler/visitor.ts", "../compiler/transformers/ts.ts", "../compiler/transformers/jsx.ts", + "../compiler/transformers/esnext.ts", "../compiler/transformers/es2017.ts", "../compiler/transformers/es2016.ts", "../compiler/transformers/es2015.ts", diff --git a/src/harness/unittests/cachingInServerLSHost.ts b/src/harness/unittests/cachingInServerLSHost.ts index 1100bb3663b..4286d3555d8 100644 --- a/src/harness/unittests/cachingInServerLSHost.ts +++ b/src/harness/unittests/cachingInServerLSHost.ts @@ -43,7 +43,8 @@ namespace ts { setTimeout, clearTimeout, setImmediate: typeof setImmediate !== "undefined" ? setImmediate : action => setTimeout(action, 0), - clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : clearTimeout + clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : clearTimeout, + createHash: s => s }; } diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index c15490738fa..8c691992043 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -60,7 +60,7 @@ namespace ts { assertParseResult(["--lib", "es5,invalidOption", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -165,7 +165,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'esnext'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -263,7 +263,7 @@ namespace ts { assertParseResult(["--lib", "es5,", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -283,7 +283,7 @@ namespace ts { assertParseResult(["--lib", "es5, ", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/compileOnSave.ts b/src/harness/unittests/compileOnSave.ts index 797268000eb..d7731a625fe 100644 --- a/src/harness/unittests/compileOnSave.ts +++ b/src/harness/unittests/compileOnSave.ts @@ -492,5 +492,45 @@ namespace ts.projectSystem { assert.isTrue(host.fileExists(expectedEmittedFileName)); assert.equal(host.readFile(expectedEmittedFileName), `"use strict";\r\nfunction Foo() { return 10; }\r\nexports.Foo = Foo;\r\n`); }); + + it("shoud not emit js files in external projects", () => { + const file1 = { + path: "/a/b/file1.ts", + content: "consonle.log('file1');" + }; + // file2 has errors. The emitting should not be blocked. + const file2 = { + path: "/a/b/file2.js", + content: "console.log'file2');" + }; + const file3 = { + path: "/a/b/file3.js", + content: "console.log('file3');" + }; + const externalProjectName = "externalproject"; + const host = createServerHost([file1, file2, file3, libFile]); + const session = createSession(host); + const projectService = session.getProjectService(); + + projectService.openExternalProject({ + rootFiles: toExternalFiles([file1.path, file2.path]), + options: { + allowJs: true, + outFile: "dist.js", + compileOnSave: true + }, + projectFileName: externalProjectName + }); + + const emitRequest = makeSessionRequest(CommandNames.CompileOnSaveEmitFile, { file: file1.path }); + session.executeCommand(emitRequest); + + const expectedOutFileName = "/a/b/dist.js"; + assert.isTrue(host.fileExists(expectedOutFileName)); + const outFileContent = host.readFile(expectedOutFileName); + assert.isTrue(outFileContent.indexOf(file1.content) !== -1); + assert.isTrue(outFileContent.indexOf(file2.content) === -1); + assert.isTrue(outFileContent.indexOf(file3.content) === -1); + }); }); } \ No newline at end of file diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index 2942675f0ac..f44dc259710 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -176,7 +176,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'esnext'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -233,7 +233,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -264,7 +264,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -295,7 +295,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -326,7 +326,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/src/harness/unittests/moduleResolution.ts b/src/harness/unittests/moduleResolution.ts index 0e391445eba..35313e15308 100644 --- a/src/harness/unittests/moduleResolution.ts +++ b/src/harness/unittests/moduleResolution.ts @@ -197,13 +197,9 @@ namespace ts { "/a/b/c/d/node_modules/foo/index.tsx", "/a/b/c/d/node_modules/foo/index.d.ts", - "/a/b/c/d/node_modules/@types/foo.ts", - "/a/b/c/d/node_modules/@types/foo.tsx", "/a/b/c/d/node_modules/@types/foo.d.ts", "/a/b/c/d/node_modules/@types/foo/package.json", - "/a/b/c/d/node_modules/@types/foo/index.ts", - "/a/b/c/d/node_modules/@types/foo/index.tsx", "/a/b/c/d/node_modules/@types/foo/index.d.ts", "/a/b/c/node_modules/foo.ts", @@ -215,13 +211,9 @@ namespace ts { "/a/b/c/node_modules/foo/index.tsx", "/a/b/c/node_modules/foo/index.d.ts", - "/a/b/c/node_modules/@types/foo.ts", - "/a/b/c/node_modules/@types/foo.tsx", "/a/b/c/node_modules/@types/foo.d.ts", "/a/b/c/node_modules/@types/foo/package.json", - "/a/b/c/node_modules/@types/foo/index.ts", - "/a/b/c/node_modules/@types/foo/index.tsx", "/a/b/c/node_modules/@types/foo/index.d.ts", ]); } @@ -257,13 +249,9 @@ namespace ts { "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.tsx", "/a/node_modules/b/c/node_modules/d/node_modules/foo/index.d.ts", - "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.ts", - "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.tsx", "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo.d.ts", "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/package.json", - "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.ts", - "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.tsx", "/a/node_modules/b/c/node_modules/d/node_modules/@types/foo/index.d.ts", "/a/node_modules/b/c/node_modules/foo.ts", @@ -275,13 +263,9 @@ namespace ts { "/a/node_modules/b/c/node_modules/foo/index.tsx", "/a/node_modules/b/c/node_modules/foo/index.d.ts", - "/a/node_modules/b/c/node_modules/@types/foo.ts", - "/a/node_modules/b/c/node_modules/@types/foo.tsx", "/a/node_modules/b/c/node_modules/@types/foo.d.ts", "/a/node_modules/b/c/node_modules/@types/foo/package.json", - "/a/node_modules/b/c/node_modules/@types/foo/index.ts", - "/a/node_modules/b/c/node_modules/@types/foo/index.tsx", "/a/node_modules/b/c/node_modules/@types/foo/index.d.ts", "/a/node_modules/b/node_modules/foo.ts", @@ -293,13 +277,9 @@ namespace ts { "/a/node_modules/b/node_modules/foo/index.tsx", "/a/node_modules/b/node_modules/foo/index.d.ts", - "/a/node_modules/b/node_modules/@types/foo.ts", - "/a/node_modules/b/node_modules/@types/foo.tsx", "/a/node_modules/b/node_modules/@types/foo.d.ts", "/a/node_modules/b/node_modules/@types/foo/package.json", - "/a/node_modules/b/node_modules/@types/foo/index.ts", - "/a/node_modules/b/node_modules/@types/foo/index.tsx", "/a/node_modules/b/node_modules/@types/foo/index.d.ts", "/a/node_modules/foo.ts", @@ -709,13 +689,9 @@ import b = require("./moduleB"); "/root/folder1/node_modules/file6/index.tsx", "/root/folder1/node_modules/file6/index.d.ts", - "/root/folder1/node_modules/@types/file6.ts", - "/root/folder1/node_modules/@types/file6.tsx", "/root/folder1/node_modules/@types/file6.d.ts", "/root/folder1/node_modules/@types/file6/package.json", - "/root/folder1/node_modules/@types/file6/index.ts", - "/root/folder1/node_modules/@types/file6/index.tsx", "/root/folder1/node_modules/@types/file6/index.d.ts", // success on /root/node_modules/file6.ts ], /*isExternalLibraryImport*/ true); diff --git a/src/harness/unittests/reuseProgramStructure.ts b/src/harness/unittests/reuseProgramStructure.ts index 386e02e2450..6dbd74e71d2 100644 --- a/src/harness/unittests/reuseProgramStructure.ts +++ b/src/harness/unittests/reuseProgramStructure.ts @@ -394,26 +394,14 @@ namespace ts { "File '/fs.ts' does not exist.", "File '/fs.tsx' does not exist.", "File '/fs.d.ts' does not exist.", - "File '/a/b/node_modules/@types/fs.ts' does not exist.", - "File '/a/b/node_modules/@types/fs.tsx' does not exist.", "File '/a/b/node_modules/@types/fs.d.ts' does not exist.", "File '/a/b/node_modules/@types/fs/package.json' does not exist.", - "File '/a/b/node_modules/@types/fs/index.ts' does not exist.", - "File '/a/b/node_modules/@types/fs/index.tsx' does not exist.", "File '/a/b/node_modules/@types/fs/index.d.ts' does not exist.", - "File '/a/node_modules/@types/fs.ts' does not exist.", - "File '/a/node_modules/@types/fs.tsx' does not exist.", "File '/a/node_modules/@types/fs.d.ts' does not exist.", "File '/a/node_modules/@types/fs/package.json' does not exist.", - "File '/a/node_modules/@types/fs/index.ts' does not exist.", - "File '/a/node_modules/@types/fs/index.tsx' does not exist.", "File '/a/node_modules/@types/fs/index.d.ts' does not exist.", - "File '/node_modules/@types/fs.ts' does not exist.", - "File '/node_modules/@types/fs.tsx' does not exist.", "File '/node_modules/@types/fs.d.ts' does not exist.", "File '/node_modules/@types/fs/package.json' does not exist.", - "File '/node_modules/@types/fs/index.ts' does not exist.", - "File '/node_modules/@types/fs/index.tsx' does not exist.", "File '/node_modules/@types/fs/index.d.ts' does not exist.", "File '/a/b/fs.js' does not exist.", "File '/a/b/fs.jsx' does not exist.", @@ -448,26 +436,14 @@ namespace ts { "File '/fs.ts' does not exist.", "File '/fs.tsx' does not exist.", "File '/fs.d.ts' does not exist.", - "File '/a/b/node_modules/@types/fs.ts' does not exist.", - "File '/a/b/node_modules/@types/fs.tsx' does not exist.", "File '/a/b/node_modules/@types/fs.d.ts' does not exist.", "File '/a/b/node_modules/@types/fs/package.json' does not exist.", - "File '/a/b/node_modules/@types/fs/index.ts' does not exist.", - "File '/a/b/node_modules/@types/fs/index.tsx' does not exist.", "File '/a/b/node_modules/@types/fs/index.d.ts' does not exist.", - "File '/a/node_modules/@types/fs.ts' does not exist.", - "File '/a/node_modules/@types/fs.tsx' does not exist.", "File '/a/node_modules/@types/fs.d.ts' does not exist.", "File '/a/node_modules/@types/fs/package.json' does not exist.", - "File '/a/node_modules/@types/fs/index.ts' does not exist.", - "File '/a/node_modules/@types/fs/index.tsx' does not exist.", "File '/a/node_modules/@types/fs/index.d.ts' does not exist.", - "File '/node_modules/@types/fs.ts' does not exist.", - "File '/node_modules/@types/fs.tsx' does not exist.", "File '/node_modules/@types/fs.d.ts' does not exist.", "File '/node_modules/@types/fs/package.json' does not exist.", - "File '/node_modules/@types/fs/index.ts' does not exist.", - "File '/node_modules/@types/fs/index.tsx' does not exist.", "File '/node_modules/@types/fs/index.d.ts' does not exist.", "File '/a/b/fs.js' does not exist.", "File '/a/b/fs.jsx' does not exist.", diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index 05f62c4b9f6..8800e84474b 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -24,7 +24,8 @@ namespace ts.server { setTimeout() { return 0; }, clearTimeout: noop, setImmediate: () => 0, - clearImmediate: noop + clearImmediate: noop, + createHash: s => s }; const nullCancellationToken: HostCancellationToken = { isCancellationRequested: () => false }; const mockLogger: Logger = { diff --git a/src/harness/unittests/transpile.ts b/src/harness/unittests/transpile.ts index 35b4f808350..20552ab9c2e 100644 --- a/src/harness/unittests/transpile.ts +++ b/src/harness/unittests/transpile.ts @@ -385,6 +385,10 @@ var x = 0;`, { options: { compilerOptions: { reactNamespace: "react" }, fileName: "input.js", reportDiagnostics: true } }); + transpilesCorrectly("Supports setting 'jsxFactory'", "x;", { + options: { compilerOptions: { jsxFactory: "createElement" }, fileName: "input.js", reportDiagnostics: true } + }); + transpilesCorrectly("Supports setting 'removeComments'", "x;", { options: { compilerOptions: { removeComments: true }, fileName: "input.js", reportDiagnostics: true } }); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 62c0957d6a3..9c3c7a4cd5b 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -434,6 +434,10 @@ namespace ts.projectSystem { }; } + createHash(s: string): string { + return s; + } + triggerDirectoryWatcherCallback(directoryName: string, fileName: string): void { const path = this.toPath(directoryName); const callbacks = this.watchedDirectories[path]; @@ -1658,12 +1662,8 @@ namespace ts.projectSystem { "File '/a/b/node_modules/lib/index.ts' does not exist.", "File '/a/b/node_modules/lib/index.tsx' does not exist.", "File '/a/b/node_modules/lib/index.d.ts' does not exist.", - "File '/a/b/node_modules/@types/lib.ts' does not exist.", - "File '/a/b/node_modules/@types/lib.tsx' does not exist.", "File '/a/b/node_modules/@types/lib.d.ts' does not exist.", "File '/a/b/node_modules/@types/lib/package.json' does not exist.", - "File '/a/b/node_modules/@types/lib/index.ts' does not exist.", - "File '/a/b/node_modules/@types/lib/index.tsx' does not exist.", "File '/a/b/node_modules/@types/lib/index.d.ts' does not exist.", "File '/a/node_modules/lib.ts' does not exist.", "File '/a/node_modules/lib.tsx' does not exist.", @@ -1672,12 +1672,8 @@ namespace ts.projectSystem { "File '/a/node_modules/lib/index.ts' does not exist.", "File '/a/node_modules/lib/index.tsx' does not exist.", "File '/a/node_modules/lib/index.d.ts' does not exist.", - "File '/a/node_modules/@types/lib.ts' does not exist.", - "File '/a/node_modules/@types/lib.tsx' does not exist.", "File '/a/node_modules/@types/lib.d.ts' does not exist.", "File '/a/node_modules/@types/lib/package.json' does not exist.", - "File '/a/node_modules/@types/lib/index.ts' does not exist.", - "File '/a/node_modules/@types/lib/index.tsx' does not exist.", "File '/a/node_modules/@types/lib/index.d.ts' does not exist.", "File '/node_modules/lib.ts' does not exist.", "File '/node_modules/lib.tsx' does not exist.", @@ -1686,12 +1682,8 @@ namespace ts.projectSystem { "File '/node_modules/lib/index.ts' does not exist.", "File '/node_modules/lib/index.tsx' does not exist.", "File '/node_modules/lib/index.d.ts' does not exist.", - "File '/node_modules/@types/lib.ts' does not exist.", - "File '/node_modules/@types/lib.tsx' does not exist.", "File '/node_modules/@types/lib.d.ts' does not exist.", "File '/node_modules/@types/lib/package.json' does not exist.", - "File '/node_modules/@types/lib/index.ts' does not exist.", - "File '/node_modules/@types/lib/index.tsx' does not exist.", "File '/node_modules/@types/lib/index.d.ts' does not exist.", "Loading module 'lib' from 'node_modules' folder.", "File '/a/b/node_modules/lib.js' does not exist.", @@ -1699,46 +1691,23 @@ namespace ts.projectSystem { "File '/a/b/node_modules/lib/package.json' does not exist.", "File '/a/b/node_modules/lib/index.js' does not exist.", "File '/a/b/node_modules/lib/index.jsx' does not exist.", - "File '/a/b/node_modules/@types/lib.js' does not exist.", - "File '/a/b/node_modules/@types/lib.jsx' does not exist.", - "File '/a/b/node_modules/@types/lib/package.json' does not exist.", - "File '/a/b/node_modules/@types/lib/index.js' does not exist.", - "File '/a/b/node_modules/@types/lib/index.jsx' does not exist.", "File '/a/node_modules/lib.js' does not exist.", "File '/a/node_modules/lib.jsx' does not exist.", "File '/a/node_modules/lib/package.json' does not exist.", "File '/a/node_modules/lib/index.js' does not exist.", "File '/a/node_modules/lib/index.jsx' does not exist.", - "File '/a/node_modules/@types/lib.js' does not exist.", - "File '/a/node_modules/@types/lib.jsx' does not exist.", - "File '/a/node_modules/@types/lib/package.json' does not exist.", - "File '/a/node_modules/@types/lib/index.js' does not exist.", - "File '/a/node_modules/@types/lib/index.jsx' does not exist.", "File '/node_modules/lib.js' does not exist.", "File '/node_modules/lib.jsx' does not exist.", "File '/node_modules/lib/package.json' does not exist.", "File '/node_modules/lib/index.js' does not exist.", "File '/node_modules/lib/index.jsx' does not exist.", - "File '/node_modules/@types/lib.js' does not exist.", - "File '/node_modules/@types/lib.jsx' does not exist.", - "File '/node_modules/@types/lib/package.json' does not exist.", - "File '/node_modules/@types/lib/index.js' does not exist.", - "File '/node_modules/@types/lib/index.jsx' does not exist.", "======== Module name 'lib' was not resolved. ========", `Auto discovery for typings is enabled in project '${proj.getProjectName()}'. Running extra resolution pass for module 'lib' using cache location '/a/cache'.`, - "File '/a/cache/node_modules/lib.ts' does not exist.", - "File '/a/cache/node_modules/lib.tsx' does not exist.", "File '/a/cache/node_modules/lib.d.ts' does not exist.", "File '/a/cache/node_modules/lib/package.json' does not exist.", - "File '/a/cache/node_modules/lib/index.ts' does not exist.", - "File '/a/cache/node_modules/lib/index.tsx' does not exist.", "File '/a/cache/node_modules/lib/index.d.ts' does not exist.", - "File '/a/cache/node_modules/@types/lib.ts' does not exist.", - "File '/a/cache/node_modules/@types/lib.tsx' does not exist.", "File '/a/cache/node_modules/@types/lib.d.ts' does not exist.", "File '/a/cache/node_modules/@types/lib/package.json' does not exist.", - "File '/a/cache/node_modules/@types/lib/index.ts' does not exist.", - "File '/a/cache/node_modules/@types/lib/index.tsx' does not exist.", "File '/a/cache/node_modules/@types/lib/index.d.ts' exist - use it as a name resolution result.", ]); checkProjectActualFiles(proj, [file1.path, lib.path]); @@ -2572,4 +2541,21 @@ namespace ts.projectSystem { assert.isTrue(diags.length === 0); }); }); + + describe("import helpers", () => { + it("should not crash in tsserver", () => { + const f1 = { + path: "/a/app.ts", + content: "export async function foo() { return 100; }" + }; + const tslib = { + path: "/a/node_modules/tslib/index.d.ts", + content: "" + }; + const host = createServerHost([f1, tslib]); + const service = createProjectService(host); + service.openExternalProject({ projectFileName: "p", rootFiles: [toExternalFile(f1.path)], options: { importHelpers: true } }); + service.checkNumberOfProjects({ externalProjects: 1 }); + }); + }); } \ No newline at end of file diff --git a/src/lib/es2017.d.ts b/src/lib/es2017.d.ts index 13f9d93f444..c234a9edb24 100644 --- a/src/lib/es2017.d.ts +++ b/src/lib/es2017.d.ts @@ -1,3 +1,4 @@ /// /// -/// \ No newline at end of file +/// +/// diff --git a/src/lib/es2017.string.d.ts b/src/lib/es2017.string.d.ts new file mode 100644 index 00000000000..51f8e410ecf --- /dev/null +++ b/src/lib/es2017.string.d.ts @@ -0,0 +1,27 @@ +interface String { + /** + * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. + * The padding is applied from the start (left) of the current string. + * + * @param maxLength The length of the resulting string once the current string has been padded. + * If this parameter is smaller than the current string's length, the current string will be returned as it is. + * + * @param fillString The string to pad the current string with. + * If this string is too long, it will be truncated and the left-most part will be applied. + * The default value for this parameter is " " (U+0020). + */ + padStart(maxLength: number, fillString?: string): string; + + /** + * Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. + * The padding is applied from the end (right) of the current string. + * + * @param maxLength The length of the resulting string once the current string has been padded. + * If this parameter is smaller than the current string's length, the current string will be returned as it is. + * + * @param fillString The string to pad the current string with. + * If this string is too long, it will be truncated and the left-most part will be applied. + * The default value for this parameter is " " (U+0020). + */ + padEnd(maxLength: number, fillString?: string): string; +} diff --git a/src/server/builder.ts b/src/server/builder.ts index 548a3ac854c..5354e7ed508 100644 --- a/src/server/builder.ts +++ b/src/server/builder.ts @@ -5,15 +5,6 @@ namespace ts.server { - interface Hash { - update(data: any, input_encoding?: string): Hash; - digest(encoding: string): any; - } - - const crypto: { - createHash(algorithm: string): Hash - } = require("crypto"); - export function shouldEmitFile(scriptInfo: ScriptInfo) { return !scriptInfo.hasMixedContent; } @@ -49,9 +40,7 @@ namespace ts.server { } private computeHash(text: string): string { - return crypto.createHash("md5") - .update(text) - .digest("base64"); + return this.project.projectService.host.createHash(text); } private getSourceFile(): SourceFile { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 269eea06464..d7dcfc810b4 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -250,6 +250,8 @@ namespace ts.server { readonly typingsInstaller: ITypingsInstaller = nullTypingsInstaller, private readonly eventHandler?: ProjectServiceEventHandler) { + Debug.assert(!!host.createHash, "'ServerHost.createHash' is required for ProjectService"); + this.toCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames); this.directoryWatchers = new DirectoryWatchers(this); this.throttledOperations = new ThrottledOperations(host); diff --git a/src/server/project.ts b/src/server/project.ts index d01df728248..db862af7e0d 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -161,8 +161,8 @@ namespace ts.server { this.compilerOptions.allowNonTsExtensions = true; } - if (this.projectKind === ProjectKind.Inferred) { - this.compilerOptions.noEmitOverwritenFiles = true; + if (this.projectKind === ProjectKind.Inferred || this.projectKind === ProjectKind.External) { + this.compilerOptions.noEmitForJsFiles = true; } if (languageServiceEnabled) { diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index da97dbcd194..0873d5c328b 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -69,7 +69,7 @@ namespace ts.server.typingsInstaller { requestId: number; args: string[]; cwd: string; - onRequestCompleted: RequestCompletedAction + onRequestCompleted: RequestCompletedAction; }; export abstract class TypingsInstaller { @@ -380,7 +380,7 @@ namespace ts.server.typingsInstaller { compilerOptions: request.compilerOptions, typings, unresolvedImports: request.unresolvedImports, - kind: server.ActionSet + kind: ActionSet }; } diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index bf7fb981daa..6825ccb6371 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -264,7 +264,7 @@ namespace ts.BreakpointResolver { // a or ...c or d: x from // [a, b, ...c] or { a, b } or { d: x } from destructuring pattern if ((node.kind === SyntaxKind.Identifier || - node.kind == SyntaxKind.SpreadElementExpression || + node.kind == SyntaxKind.SpreadElement || node.kind === SyntaxKind.PropertyAssignment || node.kind === SyntaxKind.ShorthandPropertyAssignment) && isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent)) { diff --git a/src/services/shims.ts b/src/services/shims.ts index b1fac14674c..f2984186790 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -1266,6 +1266,6 @@ namespace TypeScript.Services { // TODO: it should be moved into a namespace though. /* @internal */ -const toolsVersion = "2.1"; +const toolsVersion = "2.2"; /* tslint:enable:no-unused-variable */ diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 211e55b23ba..44c2ede9fbb 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -557,7 +557,9 @@ namespace ts.SignatureHelp { addRange(prefixDisplayParts, callTargetDisplayParts); } + let isVariadic: boolean; if (isTypeParameterList) { + isVariadic = false; // type parameter lists are not variadic prefixDisplayParts.push(punctuationPart(SyntaxKind.LessThanToken)); const typeParameters = candidateSignature.typeParameters; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; @@ -567,6 +569,7 @@ namespace ts.SignatureHelp { addRange(suffixDisplayParts, parameterParts); } else { + isVariadic = candidateSignature.hasRestParameter; const typeParameterParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation)); addRange(prefixDisplayParts, typeParameterParts); @@ -582,7 +585,7 @@ namespace ts.SignatureHelp { addRange(suffixDisplayParts, returnTypeParts); return { - isVariadic: candidateSignature.hasRestParameter, + isVariadic, prefixDisplayParts, suffixDisplayParts, separatorDisplayParts: [punctuationPart(SyntaxKind.CommaToken), spacePart()], diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index a585236c666..9c3e068918d 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -28,6 +28,7 @@ "../compiler/visitor.ts", "../compiler/transformers/ts.ts", "../compiler/transformers/jsx.ts", + "../compiler/transformers/esnext.ts", "../compiler/transformers/es2017.ts", "../compiler/transformers/es2016.ts", "../compiler/transformers/es2015.ts", diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 8fd5f510be0..cfb6aae010b 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -530,8 +530,8 @@ namespace ts { case SyntaxKind.DeleteExpression: case SyntaxKind.VoidExpression: case SyntaxKind.YieldExpression: - case SyntaxKind.SpreadElementExpression: - const unaryWordExpression = (n); + case SyntaxKind.SpreadElement: + const unaryWordExpression = n as (TypeOfExpression | DeleteExpression | VoidExpression | YieldExpression | SpreadElement); return isCompletedNode(unaryWordExpression.expression, sourceFile); case SyntaxKind.TaggedTemplateExpression: diff --git a/tests/baselines/reference/alwaysStrictModule3.js b/tests/baselines/reference/alwaysStrictModule3.js new file mode 100644 index 00000000000..894bad25143 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule3.js @@ -0,0 +1,8 @@ +//// [alwaysStrictModule3.ts] + +// module ES2015 +export const a = 1; + +//// [alwaysStrictModule3.js] +// module ES2015 +export var a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule3.symbols b/tests/baselines/reference/alwaysStrictModule3.symbols new file mode 100644 index 00000000000..6f053673f0e --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule3.ts === + +// module ES2015 +export const a = 1; +>a : Symbol(a, Decl(alwaysStrictModule3.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule3.types b/tests/baselines/reference/alwaysStrictModule3.types new file mode 100644 index 00000000000..75b11206a4f --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule3.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule3.ts === + +// module ES2015 +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/alwaysStrictModule4.js b/tests/baselines/reference/alwaysStrictModule4.js new file mode 100644 index 00000000000..1444f351bbd --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule4.js @@ -0,0 +1,9 @@ +//// [alwaysStrictModule4.ts] + +// Module commonjs +export const a = 1 + +//// [alwaysStrictModule4.js] +"use strict"; +// Module commonjs +exports.a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule4.symbols b/tests/baselines/reference/alwaysStrictModule4.symbols new file mode 100644 index 00000000000..4b8a968ae16 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule4.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule4.ts === + +// Module commonjs +export const a = 1 +>a : Symbol(a, Decl(alwaysStrictModule4.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule4.types b/tests/baselines/reference/alwaysStrictModule4.types new file mode 100644 index 00000000000..fff87967605 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule4.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule4.ts === + +// Module commonjs +export const a = 1 +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/alwaysStrictModule5.js b/tests/baselines/reference/alwaysStrictModule5.js new file mode 100644 index 00000000000..74b9d72263c --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule5.js @@ -0,0 +1,8 @@ +//// [alwaysStrictModule5.ts] + +// Targeting ES6 +export const a = 1; + +//// [alwaysStrictModule5.js] +// Targeting ES6 +export const a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule5.symbols b/tests/baselines/reference/alwaysStrictModule5.symbols new file mode 100644 index 00000000000..903bf3c5c98 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule5.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule5.ts === + +// Targeting ES6 +export const a = 1; +>a : Symbol(a, Decl(alwaysStrictModule5.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule5.types b/tests/baselines/reference/alwaysStrictModule5.types new file mode 100644 index 00000000000..2bfa329ad7e --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule5.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule5.ts === + +// Targeting ES6 +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/alwaysStrictModule6.js b/tests/baselines/reference/alwaysStrictModule6.js new file mode 100644 index 00000000000..9a603926169 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule6.js @@ -0,0 +1,9 @@ +//// [alwaysStrictModule6.ts] + +// Targeting ES5 +export const a = 1; + +//// [alwaysStrictModule6.js] +"use strict"; +// Targeting ES5 +exports.a = 1; diff --git a/tests/baselines/reference/alwaysStrictModule6.symbols b/tests/baselines/reference/alwaysStrictModule6.symbols new file mode 100644 index 00000000000..59a70f3e5b5 --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/alwaysStrictModule6.ts === + +// Targeting ES5 +export const a = 1; +>a : Symbol(a, Decl(alwaysStrictModule6.ts, 2, 12)) + diff --git a/tests/baselines/reference/alwaysStrictModule6.types b/tests/baselines/reference/alwaysStrictModule6.types new file mode 100644 index 00000000000..0970380911e --- /dev/null +++ b/tests/baselines/reference/alwaysStrictModule6.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/alwaysStrictModule6.ts === + +// Targeting ES5 +export const a = 1; +>a : 1 +>1 : 1 + diff --git a/tests/baselines/reference/commonSourceDirectory.js b/tests/baselines/reference/commonSourceDirectory.js new file mode 100644 index 00000000000..1a863dbecbd --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/commonSourceDirectory.ts] //// + +//// [index.ts] +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +export const x = 0; + +//// [bar.d.ts] +declare module "bar" { + export const y = 0; +} + +//// [index.ts] +/// +import { x } from "foo"; +import { y } from "bar"; +x + y; + + +//// [/app/bin/index.js] +"use strict"; +/// +var foo_1 = require("foo"); +var bar_1 = require("bar"); +foo_1.x + bar_1.y; +//# sourceMappingURL=/app/myMapRoot/index.js.map + +//// [/app/bin/index.d.ts] +/// diff --git a/tests/baselines/reference/commonSourceDirectory.js.map b/tests/baselines/reference/commonSourceDirectory.js.map new file mode 100644 index 00000000000..8e3f925eee9 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.js.map @@ -0,0 +1,2 @@ +//// [/app/bin/index.js.map] +{"version":3,"file":"index.js","sourceRoot":"/app/mySourceRoot/","sources":["index.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,2BAAwB;AACxB,2BAAwB;AACxB,OAAC,GAAG,OAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory.sourcemap.txt b/tests/baselines/reference/commonSourceDirectory.sourcemap.txt new file mode 100644 index 00000000000..ac198eaf02c --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.sourcemap.txt @@ -0,0 +1,58 @@ +=================================================================== +JsFile: index.js +mapUrl: /app/myMapRoot/index.js.map +sourceRoot: /app/mySourceRoot/ +sources: index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:/app/bin/index.js +sourceFile:index.ts +------------------------------------------------------------------- +>>>"use strict"; +>>>/// +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 >/// +1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 42) Source(1, 42) + SourceIndex(0) +--- +>>>var foo_1 = require("foo"); +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^-> +1 > + > +2 >import { x } from "foo"; +1 >Emitted(3, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(3, 28) Source(2, 25) + SourceIndex(0) +--- +>>>var bar_1 = require("bar"); +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > +2 >import { y } from "bar"; +1->Emitted(4, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(4, 28) Source(3, 25) + SourceIndex(0) +--- +>>>foo_1.x + bar_1.y; +1 > +2 >^^^^^^^ +3 > ^^^ +4 > ^^^^^^^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >x +3 > + +4 > y +5 > ; +1 >Emitted(5, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(5, 8) Source(4, 2) + SourceIndex(0) +3 >Emitted(5, 11) Source(4, 5) + SourceIndex(0) +4 >Emitted(5, 18) Source(4, 6) + SourceIndex(0) +5 >Emitted(5, 19) Source(4, 7) + SourceIndex(0) +--- +>>>//# sourceMappingURL=/app/myMapRoot/index.js.map \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory.symbols b/tests/baselines/reference/commonSourceDirectory.symbols new file mode 100644 index 00000000000..5409286ede5 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.symbols @@ -0,0 +1,24 @@ +=== /app/index.ts === +/// +import { x } from "foo"; +>x : Symbol(x, Decl(index.ts, 1, 8)) + +import { y } from "bar"; +>y : Symbol(y, Decl(index.ts, 2, 8)) + +x + y; +>x : Symbol(x, Decl(index.ts, 1, 8)) +>y : Symbol(y, Decl(index.ts, 2, 8)) + +=== /node_modules/foo/index.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +export const x = 0; +>x : Symbol(x, Decl(index.ts, 2, 12)) + +=== /types/bar.d.ts === +declare module "bar" { + export const y = 0; +>y : Symbol(y, Decl(bar.d.ts, 1, 16)) +} + diff --git a/tests/baselines/reference/commonSourceDirectory.types b/tests/baselines/reference/commonSourceDirectory.types new file mode 100644 index 00000000000..ce0169582d7 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory.types @@ -0,0 +1,27 @@ +=== /app/index.ts === +/// +import { x } from "foo"; +>x : 0 + +import { y } from "bar"; +>y : 0 + +x + y; +>x + y : number +>x : 0 +>y : 0 + +=== /node_modules/foo/index.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +export const x = 0; +>x : 0 +>0 : 0 + +=== /types/bar.d.ts === +declare module "bar" { + export const y = 0; +>y : 0 +>0 : 0 +} + diff --git a/tests/baselines/reference/commonSourceDirectory_dts.js b/tests/baselines/reference/commonSourceDirectory_dts.js new file mode 100644 index 00000000000..8aa0bd04e11 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/commonSourceDirectory_dts.ts] //// + +//// [bar.d.ts] +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +declare const y: number; + +//// [index.ts] +/// +export const x = y; + + +//// [/app/bin/index.js] +"use strict"; +/// +exports.x = y; +//# sourceMappingURL=/app/myMapRoot/index.js.map + +//// [/app/bin/index.d.ts] +/// +export declare const x: number; diff --git a/tests/baselines/reference/commonSourceDirectory_dts.js.map b/tests/baselines/reference/commonSourceDirectory_dts.js.map new file mode 100644 index 00000000000..b33518dd04c --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.js.map @@ -0,0 +1,2 @@ +//// [/app/bin/index.js.map] +{"version":3,"file":"index.js","sourceRoot":"/app/mySourceRoot/","sources":["index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AAC3B,QAAA,CAAC,GAAG,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt b/tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt new file mode 100644 index 00000000000..90603ae3652 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.sourcemap.txt @@ -0,0 +1,42 @@ +=================================================================== +JsFile: index.js +mapUrl: /app/myMapRoot/index.js.map +sourceRoot: /app/mySourceRoot/ +sources: index.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:/app/bin/index.js +sourceFile:index.ts +------------------------------------------------------------------- +>>>"use strict"; +>>>/// +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 >/// +1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 41) Source(1, 41) + SourceIndex(0) +--- +>>>exports.x = y; +1 > +2 >^^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >export const +2 > +3 > x +4 > = +5 > y +6 > ; +1 >Emitted(3, 1) Source(2, 14) + SourceIndex(0) +2 >Emitted(3, 9) Source(2, 14) + SourceIndex(0) +3 >Emitted(3, 10) Source(2, 15) + SourceIndex(0) +4 >Emitted(3, 13) Source(2, 18) + SourceIndex(0) +5 >Emitted(3, 14) Source(2, 19) + SourceIndex(0) +6 >Emitted(3, 15) Source(2, 20) + SourceIndex(0) +--- +>>>//# sourceMappingURL=/app/myMapRoot/index.js.map \ No newline at end of file diff --git a/tests/baselines/reference/commonSourceDirectory_dts.symbols b/tests/baselines/reference/commonSourceDirectory_dts.symbols new file mode 100644 index 00000000000..740a8aef921 --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.symbols @@ -0,0 +1,12 @@ +=== /app/src/index.ts === +/// +export const x = y; +>x : Symbol(x, Decl(index.ts, 1, 12)) +>y : Symbol(y, Decl(bar.d.ts, 2, 13)) + +=== /app/lib/bar.d.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +declare const y: number; +>y : Symbol(y, Decl(bar.d.ts, 2, 13)) + diff --git a/tests/baselines/reference/commonSourceDirectory_dts.types b/tests/baselines/reference/commonSourceDirectory_dts.types new file mode 100644 index 00000000000..b41b91c978f --- /dev/null +++ b/tests/baselines/reference/commonSourceDirectory_dts.types @@ -0,0 +1,12 @@ +=== /app/src/index.ts === +/// +export const x = y; +>x : number +>y : number + +=== /app/lib/bar.d.ts === +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. + +declare const y: number; +>y : number + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js new file mode 100644 index 00000000000..d5bf31bd755 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.js @@ -0,0 +1,17 @@ +//// [declarationEmitTypeAliasWithTypeParameters2.ts] + +export type Bar = () => [X, Y, Z]; +export type Baz = Bar; +export type Baa = Baz; +export const y = (x: Baa) => 1 + +//// [declarationEmitTypeAliasWithTypeParameters2.js] +"use strict"; +exports.y = function (x) { return 1; }; + + +//// [declarationEmitTypeAliasWithTypeParameters2.d.ts] +export declare type Bar = () => [X, Y, Z]; +export declare type Baz = Bar; +export declare type Baa = Baz; +export declare const y: (x: Bar) => number; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols new file mode 100644 index 00000000000..cc13e9fd30b --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts === + +export type Bar = () => [X, Y, Z]; +>Bar : Symbol(Bar, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 0, 0)) +>X : Symbol(X, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 16)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 18)) +>Z : Symbol(Z, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 21)) +>X : Symbol(X, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 16)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 18)) +>Z : Symbol(Z, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 21)) + +export type Baz = Bar; +>Baz : Symbol(Baz, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 43)) +>M : Symbol(M, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 16)) +>N : Symbol(N, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 18)) +>Bar : Symbol(Bar, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 0, 0)) +>M : Symbol(M, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 16)) +>N : Symbol(N, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 18)) + +export type Baa = Baz; +>Baa : Symbol(Baa, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 42)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 3, 16)) +>Baz : Symbol(Baz, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 1, 43)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 3, 16)) + +export const y = (x: Baa) => 1 +>y : Symbol(y, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 4, 12)) +>x : Symbol(x, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 4, 18)) +>Baa : Symbol(Baa, Decl(declarationEmitTypeAliasWithTypeParameters2.ts, 2, 42)) + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types new file mode 100644 index 00000000000..74becc49765 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters2.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts === + +export type Bar = () => [X, Y, Z]; +>Bar : Bar +>X : X +>Y : Y +>Z : Z +>X : X +>Y : Y +>Z : Z + +export type Baz = Bar; +>Baz : Bar +>M : M +>N : N +>Bar : Bar +>M : M +>N : N + +export type Baa = Baz; +>Baa : Bar +>Y : Y +>Baz : Bar +>Y : Y + +export const y = (x: Baa) => 1 +>y : (x: Bar) => number +>(x: Baa) => 1 : (x: Bar) => number +>x : Bar +>Baa : Bar +>1 : 1 + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js new file mode 100644 index 00000000000..9e2a366a685 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.js @@ -0,0 +1,21 @@ +//// [declarationEmitTypeAliasWithTypeParameters3.ts] + +type Foo = { + foo(): Foo +}; +function bar() { + return {} as Foo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters3.js] +function bar() { + return {}; +} + + +//// [declarationEmitTypeAliasWithTypeParameters3.d.ts] +declare type Foo = { + foo(): Foo; +}; +declare function bar(): Foo; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols new file mode 100644 index 00000000000..a18b1372cf1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts === + +type Foo = { +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 1, 9)) + + foo(): Foo +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 1, 15)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 2, 8)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 2, 8)) + +}; +function bar() { +>bar : Symbol(bar, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 3, 2)) + + return {} as Foo; +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters3.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types new file mode 100644 index 00000000000..1b2ff140178 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters3.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts === + +type Foo = { +>Foo : Foo +>T : T + + foo(): Foo +>foo : () => Foo +>U : U +>Foo : Foo +>U : U + +}; +function bar() { +>bar : () => Foo + + return {} as Foo; +>{} as Foo : Foo +>{} : {} +>Foo : Foo +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js new file mode 100644 index 00000000000..26908d915e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.js @@ -0,0 +1,24 @@ +//// [declarationEmitTypeAliasWithTypeParameters4.ts] + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters4.js] +function foo() { + return {}; +} + + +//// [declarationEmitTypeAliasWithTypeParameters4.d.ts] +declare type Foo = { + foo(): Foo; +}; +declare type SubFoo = Foo; +declare function foo(): Foo; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols new file mode 100644 index 00000000000..de73f544645 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts === + +type Foo = { +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 9)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 11)) + + foo(): Foo +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 1, 18)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 10)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 2, 10)) + +}; +type SubFoo = Foo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 3, 2)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 12)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 0, 0)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 12)) + +function foo() { +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 4, 32)) + + return {} as SubFoo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters4.ts, 3, 2)) +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types new file mode 100644 index 00000000000..c545ac6bb05 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters4.types @@ -0,0 +1,31 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts === + +type Foo = { +>Foo : Foo +>T : T +>Y : Y + + foo(): Foo +>foo : () => Foo +>U : U +>J : J +>Foo : Foo +>U : U +>J : J + +}; +type SubFoo = Foo; +>SubFoo : Foo +>R : R +>Foo : Foo +>R : R + +function foo() { +>foo : () => Foo + + return {} as SubFoo; +>{} as SubFoo : Foo +>{} : {} +>SubFoo : Foo +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt new file mode 100644 index 00000000000..7f683dcc7b7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts(5,25): error TS4081: Exported type alias 'SubFoo' has or is using private name 'Foo'. + + +==== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts (1 errors) ==== + + type Foo = { + foo(): Foo + }; + export type SubFoo = Foo; + ~~~ +!!! error TS4081: Exported type alias 'SubFoo' has or is using private name 'Foo'. + + function foo() { + return {} as SubFoo; + } + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js new file mode 100644 index 00000000000..2f4fff7d72c --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js @@ -0,0 +1,17 @@ +//// [declarationEmitTypeAliasWithTypeParameters5.ts] + +type Foo = { + foo(): Foo +}; +export type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters5.js] +"use strict"; +function foo() { + return {}; +} diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js new file mode 100644 index 00000000000..c8001446e3e --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.js @@ -0,0 +1,24 @@ +//// [declarationEmitTypeAliasWithTypeParameters6.ts] + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} + + +//// [declarationEmitTypeAliasWithTypeParameters6.js] +function foo() { + return {}; +} + + +//// [declarationEmitTypeAliasWithTypeParameters6.d.ts] +declare type Foo = { + foo(): Foo; +}; +declare type SubFoo = Foo; +declare function foo(): Foo; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols new file mode 100644 index 00000000000..ec29989f078 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts === + +type Foo = { +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 0, 0)) +>T : Symbol(T, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 1, 9)) +>Y : Symbol(Y, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 1, 11)) + + foo(): Foo +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 1, 18)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 10)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 0, 0)) +>U : Symbol(U, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 8)) +>J : Symbol(J, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 2, 10)) + +}; +type SubFoo = Foo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 3, 2)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 12)) +>S : Symbol(S, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 14)) +>Foo : Symbol(Foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 0, 0)) +>S : Symbol(S, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 14)) +>R : Symbol(R, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 12)) + +function foo() { +>foo : Symbol(foo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 4, 30)) + + return {} as SubFoo; +>SubFoo : Symbol(SubFoo, Decl(declarationEmitTypeAliasWithTypeParameters6.ts, 3, 2)) +} + diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types new file mode 100644 index 00000000000..b02ccbc2be7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters6.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts === + +type Foo = { +>Foo : Foo +>T : T +>Y : Y + + foo(): Foo +>foo : () => Foo +>U : U +>J : J +>Foo : Foo +>U : U +>J : J + +}; +type SubFoo = Foo; +>SubFoo : Foo +>R : R +>S : S +>Foo : Foo +>S : S +>R : R + +function foo() { +>foo : () => Foo + + return {} as SubFoo; +>{} as SubFoo : Foo +>{} : {} +>SubFoo : Foo +} + diff --git a/tests/baselines/reference/decoratorInJsFile.errors.txt b/tests/baselines/reference/decoratorInJsFile.errors.txt new file mode 100644 index 00000000000..93bd5143b74 --- /dev/null +++ b/tests/baselines/reference/decoratorInJsFile.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/a.js(4,12): error TS8010: 'types' can only be used in a .ts file. + + +==== tests/cases/compiler/a.js (1 errors) ==== + + @SomeDecorator + class SomeClass { + foo(x: number) { + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorInJsFile1.errors.txt b/tests/baselines/reference/decoratorInJsFile1.errors.txt new file mode 100644 index 00000000000..f4422c0c2d9 --- /dev/null +++ b/tests/baselines/reference/decoratorInJsFile1.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/a.js(3,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. +tests/cases/compiler/a.js(4,12): error TS8010: 'types' can only be used in a .ts file. + + +==== tests/cases/compiler/a.js (2 errors) ==== + + @SomeDecorator + class SomeClass { + ~~~~~~~~~ +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning. + foo(x: number) { + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index bb4b79987e3..33344b9b5eb 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -5,16 +5,12 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2525: Initializer provides no value for this binding element and the binding element has no default value. tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,21): error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,5): error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,11): error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{ d1: any; }'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,24): error TS2353: Object literal may only specify known properties, and 'e' does not exist in type '{ d1: any; }'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,7): error TS1005: ':' expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,15): error TS1005: ':' expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,12): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,15): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,12): error TS1005: ':' expected. -==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (13 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== // Error var {h?} = { h?: 1 }; ~ @@ -33,17 +29,6 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs !!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~~~~ !!! error TS2353: Object literal may only specify known properties, and 'f212' does not exist in type '{ f21: any; }'. - var { ...d1 } = { - ~~~ -!!! error TS1180: Property destructuring pattern expected. - a: 1, b: 1, d1: 9, e: 10 - ~ -!!! error TS2353: Object literal may only specify known properties, and 'a' does not exist in type '{ d1: any; }'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'b' does not exist in type '{ d1: any; }'. - ~ -!!! error TS2353: Object literal may only specify known properties, and 'e' does not exist in type '{ d1: any; }'. - } var {1} = { 1 }; ~ !!! error TS1005: ':' expected. @@ -51,4 +36,5 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs !!! error TS1005: ':' expected. var {"prop"} = { "prop": 1 }; ~ -!!! error TS1005: ':' expected. \ No newline at end of file +!!! error TS1005: ':' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js index 77288e6a542..0872a71c73b 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -4,11 +4,9 @@ var {h?} = { h?: 1 }; var {i}: string | number = { i: 2 }; var {i1}: string | number| {} = { i1: 2 }; var { f2: {f21} = { f212: "string" } }: any = undefined; -var { ...d1 } = { - a: 1, b: 1, d1: 9, e: 10 -} var {1} = { 1 }; -var {"prop"} = { "prop": 1 }; +var {"prop"} = { "prop": 1 }; + //// [destructuringObjectBindingPatternAndAssignment3.js] // Error @@ -16,8 +14,5 @@ var h = { h: 1 }.h; var i = { i: 2 }.i; var i1 = { i1: 2 }.i1; var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; -var d1 = { - a: 1, b: 1, d1: 9, e: 10 -}.d1; var = { 1: }[1]; var = { "prop": 1 }["prop"]; diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.js b/tests/baselines/reference/globalAugmentationModuleResolution.js new file mode 100644 index 00000000000..e1a4ebce8c5 --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.js @@ -0,0 +1,10 @@ +//// [a.ts] + +export { }; + +declare global { + var x: number; +} + +//// [a.js] +"use strict"; diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.symbols b/tests/baselines/reference/globalAugmentationModuleResolution.symbols new file mode 100644 index 00000000000..614860d654e --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/a.ts === + +export { }; + +declare global { +>global : Symbol(global, Decl(a.ts, 1, 11)) + + var x: number; +>x : Symbol(x, Decl(a.ts, 4, 5)) +} diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.trace.json b/tests/baselines/reference/globalAugmentationModuleResolution.trace.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/globalAugmentationModuleResolution.types b/tests/baselines/reference/globalAugmentationModuleResolution.types new file mode 100644 index 00000000000..c057ea2943d --- /dev/null +++ b/tests/baselines/reference/globalAugmentationModuleResolution.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/a.ts === + +export { }; + +declare global { +>global : any + + var x: number; +>x : number +} diff --git a/tests/baselines/reference/importHelpersNoHelpers.errors.txt b/tests/baselines/reference/importHelpersNoHelpers.errors.txt index ebb25dbd7c9..fa9a935c8d8 100644 --- a/tests/baselines/reference/importHelpersNoHelpers.errors.txt +++ b/tests/baselines/reference/importHelpersNoHelpers.errors.txt @@ -1,13 +1,17 @@ +error TS2305: Module 'tslib' has no exported member '__assign'. error TS2305: Module 'tslib' has no exported member '__decorate'. error TS2305: Module 'tslib' has no exported member '__extends'. error TS2305: Module 'tslib' has no exported member '__metadata'. error TS2305: Module 'tslib' has no exported member '__param'. +error TS2305: Module 'tslib' has no exported member '__rest'. +!!! error TS2305: Module 'tslib' has no exported member '__assign'. !!! error TS2305: Module 'tslib' has no exported member '__decorate'. !!! error TS2305: Module 'tslib' has no exported member '__extends'. !!! error TS2305: Module 'tslib' has no exported member '__metadata'. !!! error TS2305: Module 'tslib' has no exported member '__param'. +!!! error TS2305: Module 'tslib' has no exported member '__rest'. ==== tests/cases/compiler/external.ts (0 errors) ==== export class A { } export class B extends A { } @@ -20,6 +24,10 @@ error TS2305: Module 'tslib' has no exported member '__param'. } } + const o = { a: 1 }; + const y = { ...o }; + const { ...x } = y; + ==== tests/cases/compiler/script.ts (0 errors) ==== class A { } class B extends A { } @@ -33,4 +41,5 @@ error TS2305: Module 'tslib' has no exported member '__param'. } ==== tests/cases/compiler/tslib.d.ts (0 errors) ==== - export {} \ No newline at end of file + export {} + \ No newline at end of file diff --git a/tests/baselines/reference/importHelpersNoHelpers.js b/tests/baselines/reference/importHelpersNoHelpers.js index e22d1f4353d..690a6c05f17 100644 --- a/tests/baselines/reference/importHelpersNoHelpers.js +++ b/tests/baselines/reference/importHelpersNoHelpers.js @@ -11,6 +11,10 @@ class C { method(@dec x: number) { } } + +const o = { a: 1 }; +const y = { ...o }; +const { ...x } = y; //// [script.ts] class A { } @@ -25,7 +29,8 @@ class C { } //// [tslib.d.ts] -export {} +export {} + //// [external.js] "use strict"; @@ -61,6 +66,9 @@ C = tslib_1.__decorate([ dec, tslib_1.__metadata("design:paramtypes", []) ], C); +var o = { a: 1 }; +var y = __assign({}, o); +var x = __rest(y, []); //// [script.js] var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; diff --git a/tests/baselines/reference/incompatibleAssignmentOfIdenticallyNamedTypes.errors.txt b/tests/baselines/reference/incompatibleAssignmentOfIdenticallyNamedTypes.errors.txt new file mode 100644 index 00000000000..3f1de47c347 --- /dev/null +++ b/tests/baselines/reference/incompatibleAssignmentOfIdenticallyNamedTypes.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts(6,9): error TS90010: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + + +==== tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts (1 errors) ==== + interface T { } + declare const a: T; + class Foo { + x: T; + fn() { + this.x = a; + ~~~~~~ +!!! error TS90010: Type 'T' is not assignable to type 'T'. Two different types with this name exist, but they are unrelated. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/incompatibleAssignmentOfIdenticallyNamedTypes.js b/tests/baselines/reference/incompatibleAssignmentOfIdenticallyNamedTypes.js new file mode 100644 index 00000000000..677d177a4d0 --- /dev/null +++ b/tests/baselines/reference/incompatibleAssignmentOfIdenticallyNamedTypes.js @@ -0,0 +1,20 @@ +//// [incompatibleAssignmentOfIdenticallyNamedTypes.ts] +interface T { } +declare const a: T; +class Foo { + x: T; + fn() { + this.x = a; + } +} + + +//// [incompatibleAssignmentOfIdenticallyNamedTypes.js] +var Foo = (function () { + function Foo() { + } + Foo.prototype.fn = function () { + this.x = a; + }; + return Foo; +}()); diff --git a/tests/baselines/reference/interfaceSpread.errors.txt b/tests/baselines/reference/interfaceSpread.errors.txt new file mode 100644 index 00000000000..c6acc633912 --- /dev/null +++ b/tests/baselines/reference/interfaceSpread.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/types/spread/interfaceSpread.ts(2,5): error TS2698: Interface declaration cannot contain a spread property. +tests/cases/conformance/types/spread/interfaceSpread.ts(7,10): error TS2339: Property 'jam' does not exist on type 'Congealed<{ jam: number; }, { peanutButter: number; }>'. +tests/cases/conformance/types/spread/interfaceSpread.ts(8,10): error TS2339: Property 'peanutButter' does not exist on type 'Congealed<{ jam: number; }, { peanutButter: number; }>'. + + +==== tests/cases/conformance/types/spread/interfaceSpread.ts (3 errors) ==== + interface Congealed { + ...T + ~~~~ +!!! error TS2698: Interface declaration cannot contain a spread property. + ...U + } + + let sandwich: Congealed<{jam: number }, { peanutButter: number }>; + sandwich.jam; + ~~~ +!!! error TS2339: Property 'jam' does not exist on type 'Congealed<{ jam: number; }, { peanutButter: number; }>'. + sandwich.peanutButter; + ~~~~~~~~~~~~ +!!! error TS2339: Property 'peanutButter' does not exist on type 'Congealed<{ jam: number; }, { peanutButter: number; }>'. + \ No newline at end of file diff --git a/tests/baselines/reference/interfaceSpread.js b/tests/baselines/reference/interfaceSpread.js new file mode 100644 index 00000000000..89f25314366 --- /dev/null +++ b/tests/baselines/reference/interfaceSpread.js @@ -0,0 +1,15 @@ +//// [interfaceSpread.ts] +interface Congealed { + ...T + ...U +} + +let sandwich: Congealed<{jam: number }, { peanutButter: number }>; +sandwich.jam; +sandwich.peanutButter; + + +//// [interfaceSpread.js] +var sandwich; +sandwich.jam; +sandwich.peanutButter; diff --git a/tests/baselines/reference/jsFileCompilationAbstractModifier.errors.txt b/tests/baselines/reference/jsFileCompilationAbstractModifier.errors.txt new file mode 100644 index 00000000000..c7d2ad270be --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationAbstractModifier.errors.txt @@ -0,0 +1,16 @@ +error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. + Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig +tests/cases/compiler/a.js(1,1): error TS8009: 'abstract' can only be used in a .ts file. +tests/cases/compiler/a.js(2,5): error TS8009: 'abstract' can only be used in a .ts file. + + +!!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. +!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig +==== tests/cases/compiler/a.js (2 errors) ==== + abstract class c { + ~~~~~~~~ +!!! error TS8009: 'abstract' can only be used in a .ts file. + abstract x; + ~~~~~~~~ +!!! error TS8009: 'abstract' can only be used in a .ts file. + } \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationConstModifier.symbols b/tests/baselines/reference/jsFileCompilationConstModifier.symbols new file mode 100644 index 00000000000..137dafd3473 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationConstModifier.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/a.js === +const c = 10; +>c : Symbol(c, Decl(a.js, 0, 5)) + diff --git a/tests/baselines/reference/jsFileCompilationConstModifier.types b/tests/baselines/reference/jsFileCompilationConstModifier.types new file mode 100644 index 00000000000..8e74679f2a5 --- /dev/null +++ b/tests/baselines/reference/jsFileCompilationConstModifier.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/a.js === +const c = 10; +>c : 10 +>10 : 10 + diff --git a/tests/baselines/reference/jsxFactoryAndReactNamespace.errors.txt b/tests/baselines/reference/jsxFactoryAndReactNamespace.errors.txt new file mode 100644 index 00000000000..c4859fd534c --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndReactNamespace.errors.txt @@ -0,0 +1,53 @@ +error TS5053: Option 'reactNamespace' cannot be specified with option 'jsxFactory'. + + +!!! error TS5053: Option 'reactNamespace' cannot be specified with option 'jsxFactory'. +==== tests/cases/compiler/Element.ts (0 errors) ==== + + declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } + } + export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } + } + + export let createElement = Element.createElement; + + function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); + } + +==== tests/cases/compiler/test.tsx (0 errors) ==== + import { Element} from './Element'; + + let c: { + a?: { + b: string + } + }; + + class A { + view() { + return [ + , + + ]; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryAndReactNamespace.js b/tests/baselines/reference/jsxFactoryAndReactNamespace.js new file mode 100644 index 00000000000..0a6402ca70c --- /dev/null +++ b/tests/baselines/reference/jsxFactoryAndReactNamespace.js @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/jsxFactoryAndReactNamespace.ts] //// + +//// [Element.ts] + +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +//// [test.tsx] +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} + +//// [Element.js] +"use strict"; +var Element; +(function (Element) { + function isElement(el) { + return el.markAsChildOfRootElement !== undefined; + } + Element.isElement = isElement; + function createElement(args) { + return {}; + } + Element.createElement = createElement; +})(Element = exports.Element || (exports.Element = {})); +exports.createElement = Element.createElement; +function toCamelCase(text) { + return text[0].toLowerCase() + text.substring(1); +} +//// [test.js] +"use strict"; +const Element_1 = require("./Element"); +let c; +class A { + view() { + return [ + Element_1.Element.createElement("meta", { content: "helloworld" }), + Element_1.Element.createElement("meta", { content: c.a.b }) + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryIdentifier.js b/tests/baselines/reference/jsxFactoryIdentifier.js new file mode 100644 index 00000000000..82c8f6410e6 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifier.js @@ -0,0 +1,83 @@ +//// [tests/cases/compiler/jsxFactoryIdentifier.ts] //// + +//// [Element.ts] + +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +//// [test.tsx] +import { Element} from './Element'; +let createElement = Element.createElement; +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} + +//// [Element.js] +"use strict"; +var Element; +(function (Element) { + function isElement(el) { + return el.markAsChildOfRootElement !== undefined; + } + Element.isElement = isElement; + function createElement(args) { + return {}; + } + Element.createElement = createElement; +})(Element = exports.Element || (exports.Element = {})); +exports.createElement = Element.createElement; +function toCamelCase(text) { + return text[0].toLowerCase() + text.substring(1); +} +//# sourceMappingURL=Element.js.map//// [test.js] +"use strict"; +const Element_1 = require("./Element"); +let createElement = Element_1.Element.createElement; +let c; +class A { + view() { + return [ + createElement("meta", { content: "helloworld" }), + createElement("meta", { content: c.a.b }) + ]; + } +} +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifier.js.map b/tests/baselines/reference/jsxFactoryIdentifier.js.map new file mode 100644 index 00000000000..cad196b8ba5 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifier.js.map @@ -0,0 +1,3 @@ +//// [Element.js.map] +{"version":3,"file":"Element.js","sourceRoot":"","sources":["Element.ts"],"names":[],"mappings":";AAaA,IAAiB,OAAO,CAUvB;AAVD,WAAiB,OAAO;IACpB,mBAA0B,EAAO;QAC7B,MAAM,CAAC,EAAE,CAAC,wBAAwB,KAAK,SAAS,CAAC;IACrD,CAAC;IAFe,iBAAS,YAExB,CAAA;IAED,uBAA8B,IAAW;QAErC,MAAM,CAAC,EACN,CAAA;IACL,CAAC;IAJe,qBAAa,gBAI5B,CAAA;AACL,CAAC,EAVgB,OAAO,GAAP,eAAO,KAAP,eAAO,QAUvB;AAEU,QAAA,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAEjD,qBAAqB,IAAY;IAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC"}//// [test.js.map] +{"version":3,"file":"test.js","sourceRoot":"","sources":["test.tsx"],"names":[],"mappings":";AAAA,uCAAmC;AACnC,IAAI,aAAa,GAAG,iBAAO,CAAC,aAAa,CAAC;AAC1C,IAAI,CAIH,CAAC;AAEF;IACC,IAAI;QACH,MAAM,CAAC;YACN,wBAAM,OAAO,EAAC,YAAY,GAAQ;YAClC,wBAAM,OAAO,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC,GAAS;SAC9B,CAAC;IACH,CAAC;CACD"} \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifier.sourcemap.txt b/tests/baselines/reference/jsxFactoryIdentifier.sourcemap.txt new file mode 100644 index 00000000000..a4ddc8c050b --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifier.sourcemap.txt @@ -0,0 +1,520 @@ +=================================================================== +JsFile: Element.js +mapUrl: Element.js.map +sourceRoot: +sources: Element.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/Element.js +sourceFile:Element.ts +------------------------------------------------------------------- +>>>"use strict"; +>>>var Element; +1 > +2 >^^^^ +3 > ^^^^^^^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + >declare namespace JSX { + > interface Element { + > name: string; + > isIntrinsic: boolean; + > isCustomElement: boolean; + > toString(renderId?: number): string; + > bindDOM(renderId?: number): number; + > resetComponent(): void; + > instantiateComponents(renderId?: number): number; + > props: any; + > } + >} + > +2 >export namespace +3 > Element +4 > { + > export function isElement(el: any): el is JSX.Element { + > return el.markAsChildOfRootElement !== undefined; + > } + > + > export function createElement(args: any[]) { + > + > return { + > } + > } + > } +1 >Emitted(2, 1) Source(14, 1) + SourceIndex(0) +2 >Emitted(2, 5) Source(14, 18) + SourceIndex(0) +3 >Emitted(2, 12) Source(14, 25) + SourceIndex(0) +4 >Emitted(2, 13) Source(24, 2) + SourceIndex(0) +--- +>>>(function (Element) { +1-> +2 >^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^^^^^^^^^^^-> +1-> +2 >export namespace +3 > Element +1->Emitted(3, 1) Source(14, 1) + SourceIndex(0) +2 >Emitted(3, 12) Source(14, 18) + SourceIndex(0) +3 >Emitted(3, 19) Source(14, 25) + SourceIndex(0) +--- +>>> function isElement(el) { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> { + > +2 > export function isElement( +3 > el: any +1->Emitted(4, 5) Source(15, 5) + SourceIndex(0) +2 >Emitted(4, 24) Source(15, 31) + SourceIndex(0) +3 >Emitted(4, 26) Source(15, 38) + SourceIndex(0) +--- +>>> return el.markAsChildOfRootElement !== undefined; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^ +7 > ^^^^^ +8 > ^^^^^^^^^ +9 > ^ +1->): el is JSX.Element { + > +2 > return +3 > +4 > el +5 > . +6 > markAsChildOfRootElement +7 > !== +8 > undefined +9 > ; +1->Emitted(5, 9) Source(16, 9) + SourceIndex(0) +2 >Emitted(5, 15) Source(16, 15) + SourceIndex(0) +3 >Emitted(5, 16) Source(16, 16) + SourceIndex(0) +4 >Emitted(5, 18) Source(16, 18) + SourceIndex(0) +5 >Emitted(5, 19) Source(16, 19) + SourceIndex(0) +6 >Emitted(5, 43) Source(16, 43) + SourceIndex(0) +7 >Emitted(5, 48) Source(16, 48) + SourceIndex(0) +8 >Emitted(5, 57) Source(16, 57) + SourceIndex(0) +9 >Emitted(5, 58) Source(16, 58) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(17, 5) + SourceIndex(0) +2 >Emitted(6, 6) Source(17, 6) + SourceIndex(0) +--- +>>> Element.isElement = isElement; +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^ +4 > ^ +5 > ^-> +1-> +2 > isElement +3 > (el: any): el is JSX.Element { + > return el.markAsChildOfRootElement !== undefined; + > } +4 > +1->Emitted(7, 5) Source(15, 21) + SourceIndex(0) +2 >Emitted(7, 22) Source(15, 30) + SourceIndex(0) +3 >Emitted(7, 34) Source(17, 6) + SourceIndex(0) +4 >Emitted(7, 35) Source(17, 6) + SourceIndex(0) +--- +>>> function createElement(args) { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^ +1-> + > + > +2 > export function createElement( +3 > args: any[] +1->Emitted(8, 5) Source(19, 5) + SourceIndex(0) +2 >Emitted(8, 28) Source(19, 35) + SourceIndex(0) +3 >Emitted(8, 32) Source(19, 46) + SourceIndex(0) +--- +>>> return {}; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >) { + > + > +2 > return +3 > +4 > { + > } +5 > +1 >Emitted(9, 9) Source(21, 9) + SourceIndex(0) +2 >Emitted(9, 15) Source(21, 15) + SourceIndex(0) +3 >Emitted(9, 16) Source(21, 16) + SourceIndex(0) +4 >Emitted(9, 18) Source(22, 10) + SourceIndex(0) +5 >Emitted(9, 19) Source(22, 10) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(10, 5) Source(23, 5) + SourceIndex(0) +2 >Emitted(10, 6) Source(23, 6) + SourceIndex(0) +--- +>>> Element.createElement = createElement; +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^ +4 > ^ +5 > ^^^^^^^^^^^^^^^-> +1-> +2 > createElement +3 > (args: any[]) { + > + > return { + > } + > } +4 > +1->Emitted(11, 5) Source(19, 21) + SourceIndex(0) +2 >Emitted(11, 26) Source(19, 34) + SourceIndex(0) +3 >Emitted(11, 42) Source(23, 6) + SourceIndex(0) +4 >Emitted(11, 43) Source(23, 6) + SourceIndex(0) +--- +>>>})(Element = exports.Element || (exports.Element = {})); +1-> +2 >^ +3 > ^^ +4 > ^^^^^^^ +5 > ^^^ +6 > ^^^^^^^^^^^^^^^ +7 > ^^^^^ +8 > ^^^^^^^^^^^^^^^ +9 > ^^^^^^^^ +1-> + > +2 >} +3 > +4 > Element +5 > +6 > Element +7 > +8 > Element +9 > { + > export function isElement(el: any): el is JSX.Element { + > return el.markAsChildOfRootElement !== undefined; + > } + > + > export function createElement(args: any[]) { + > + > return { + > } + > } + > } +1->Emitted(12, 1) Source(24, 1) + SourceIndex(0) +2 >Emitted(12, 2) Source(24, 2) + SourceIndex(0) +3 >Emitted(12, 4) Source(14, 18) + SourceIndex(0) +4 >Emitted(12, 11) Source(14, 25) + SourceIndex(0) +5 >Emitted(12, 14) Source(14, 18) + SourceIndex(0) +6 >Emitted(12, 29) Source(14, 25) + SourceIndex(0) +7 >Emitted(12, 34) Source(14, 18) + SourceIndex(0) +8 >Emitted(12, 49) Source(14, 25) + SourceIndex(0) +9 >Emitted(12, 57) Source(24, 2) + SourceIndex(0) +--- +>>>exports.createElement = Element.createElement; +1 > +2 >^^^^^^^^ +3 > ^^^^^^^^^^^^^ +4 > ^^^ +5 > ^^^^^^^ +6 > ^ +7 > ^^^^^^^^^^^^^ +8 > ^ +1 > + > + >export let +2 > +3 > createElement +4 > = +5 > Element +6 > . +7 > createElement +8 > ; +1 >Emitted(13, 1) Source(26, 12) + SourceIndex(0) +2 >Emitted(13, 9) Source(26, 12) + SourceIndex(0) +3 >Emitted(13, 22) Source(26, 25) + SourceIndex(0) +4 >Emitted(13, 25) Source(26, 28) + SourceIndex(0) +5 >Emitted(13, 32) Source(26, 35) + SourceIndex(0) +6 >Emitted(13, 33) Source(26, 36) + SourceIndex(0) +7 >Emitted(13, 46) Source(26, 49) + SourceIndex(0) +8 >Emitted(13, 47) Source(26, 50) + SourceIndex(0) +--- +>>>function toCamelCase(text) { +1 > +2 >^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > + > +2 >function toCamelCase( +3 > text: string +1 >Emitted(14, 1) Source(28, 1) + SourceIndex(0) +2 >Emitted(14, 22) Source(28, 22) + SourceIndex(0) +3 >Emitted(14, 26) Source(28, 34) + SourceIndex(0) +--- +>>> return text[0].toLowerCase() + text.substring(1); +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^ +10> ^^ +11> ^^^ +12> ^^^^ +13> ^ +14> ^^^^^^^^^ +15> ^ +16> ^ +17> ^ +18> ^ +1->): string { + > +2 > return +3 > +4 > text +5 > [ +6 > 0 +7 > ] +8 > . +9 > toLowerCase +10> () +11> + +12> text +13> . +14> substring +15> ( +16> 1 +17> ) +18> ; +1->Emitted(15, 5) Source(29, 5) + SourceIndex(0) +2 >Emitted(15, 11) Source(29, 11) + SourceIndex(0) +3 >Emitted(15, 12) Source(29, 12) + SourceIndex(0) +4 >Emitted(15, 16) Source(29, 16) + SourceIndex(0) +5 >Emitted(15, 17) Source(29, 17) + SourceIndex(0) +6 >Emitted(15, 18) Source(29, 18) + SourceIndex(0) +7 >Emitted(15, 19) Source(29, 19) + SourceIndex(0) +8 >Emitted(15, 20) Source(29, 20) + SourceIndex(0) +9 >Emitted(15, 31) Source(29, 31) + SourceIndex(0) +10>Emitted(15, 33) Source(29, 33) + SourceIndex(0) +11>Emitted(15, 36) Source(29, 36) + SourceIndex(0) +12>Emitted(15, 40) Source(29, 40) + SourceIndex(0) +13>Emitted(15, 41) Source(29, 41) + SourceIndex(0) +14>Emitted(15, 50) Source(29, 50) + SourceIndex(0) +15>Emitted(15, 51) Source(29, 51) + SourceIndex(0) +16>Emitted(15, 52) Source(29, 52) + SourceIndex(0) +17>Emitted(15, 53) Source(29, 53) + SourceIndex(0) +18>Emitted(15, 54) Source(29, 54) + SourceIndex(0) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +1 >Emitted(16, 1) Source(30, 1) + SourceIndex(0) +2 >Emitted(16, 2) Source(30, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=Element.js.map=================================================================== +JsFile: test.js +mapUrl: test.js.map +sourceRoot: +sources: test.tsx +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/test.js +sourceFile:test.tsx +------------------------------------------------------------------- +>>>"use strict"; +>>>const Element_1 = require("./Element"); +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^-> +1 > +2 >import { Element} from './Element'; +1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 40) Source(1, 36) + SourceIndex(0) +--- +>>>let createElement = Element_1.Element.createElement; +1-> +2 >^^^^ +3 > ^^^^^^^^^^^^^ +4 > ^^^ +5 > ^^^^^^^^^^^^^^^^^ +6 > ^ +7 > ^^^^^^^^^^^^^ +8 > ^ +1-> + > +2 >let +3 > createElement +4 > = +5 > Element +6 > . +7 > createElement +8 > ; +1->Emitted(3, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(3, 5) Source(2, 5) + SourceIndex(0) +3 >Emitted(3, 18) Source(2, 18) + SourceIndex(0) +4 >Emitted(3, 21) Source(2, 21) + SourceIndex(0) +5 >Emitted(3, 38) Source(2, 28) + SourceIndex(0) +6 >Emitted(3, 39) Source(2, 29) + SourceIndex(0) +7 >Emitted(3, 52) Source(2, 42) + SourceIndex(0) +8 >Emitted(3, 53) Source(2, 43) + SourceIndex(0) +--- +>>>let c; +1 > +2 >^^^^ +3 > ^ +4 > ^ +5 > ^^^^-> +1 > + > +2 >let +3 > c: { + > a?: { + > b: string + > } + > } +4 > ; +1 >Emitted(4, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(4, 5) Source(3, 5) + SourceIndex(0) +3 >Emitted(4, 6) Source(7, 2) + SourceIndex(0) +4 >Emitted(4, 7) Source(7, 3) + SourceIndex(0) +--- +>>>class A { +1-> +2 >^^^^^^^^^^^^^-> +1-> + > + > +1->Emitted(5, 1) Source(9, 1) + SourceIndex(0) +--- +>>> view() { +1->^^^^ +2 > ^^^^ +3 > ^^^^^^^^^-> +1->class A { + > +2 > view +1->Emitted(6, 5) Source(10, 2) + SourceIndex(0) +2 >Emitted(6, 9) Source(10, 6) + SourceIndex(0) +--- +>>> return [ +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->() { + > +2 > return +3 > +1->Emitted(7, 9) Source(11, 3) + SourceIndex(0) +2 >Emitted(7, 15) Source(11, 9) + SourceIndex(0) +3 >Emitted(7, 16) Source(11, 10) + SourceIndex(0) +--- +>>> createElement("meta", { content: "helloworld" }), +1->^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^^^^ +6 > ^^^ +1->[ + > +2 > content +4 > = +5 > "helloworld" +6 > > +1->Emitted(8, 13) Source(12, 4) + SourceIndex(0) +2 >Emitted(8, 37) Source(12, 10) + SourceIndex(0) +3 >Emitted(8, 44) Source(12, 17) + SourceIndex(0) +4 >Emitted(8, 46) Source(12, 18) + SourceIndex(0) +5 >Emitted(8, 58) Source(12, 30) + SourceIndex(0) +6 >Emitted(8, 61) Source(12, 38) + SourceIndex(0) +--- +>>> createElement("meta", { content: c.a.b }) +1 >^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^ +10> ^^^ +1 >, + > +2 > content +4 > ={ +5 > c +6 > . +7 > a! +8 > . +9 > b +10> }> +1 >Emitted(9, 13) Source(13, 4) + SourceIndex(0) +2 >Emitted(9, 37) Source(13, 10) + SourceIndex(0) +3 >Emitted(9, 44) Source(13, 17) + SourceIndex(0) +4 >Emitted(9, 46) Source(13, 19) + SourceIndex(0) +5 >Emitted(9, 47) Source(13, 20) + SourceIndex(0) +6 >Emitted(9, 48) Source(13, 21) + SourceIndex(0) +7 >Emitted(9, 49) Source(13, 23) + SourceIndex(0) +8 >Emitted(9, 50) Source(13, 24) + SourceIndex(0) +9 >Emitted(9, 51) Source(13, 25) + SourceIndex(0) +10>Emitted(9, 54) Source(13, 34) + SourceIndex(0) +--- +>>> ]; +1 >^^^^^^^^^ +2 > ^ +1 > + > ] +2 > ; +1 >Emitted(10, 10) Source(14, 4) + SourceIndex(0) +2 >Emitted(10, 11) Source(14, 5) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(11, 5) Source(15, 2) + SourceIndex(0) +2 >Emitted(11, 6) Source(15, 3) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +1 >Emitted(12, 2) Source(16, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifier.symbols b/tests/baselines/reference/jsxFactoryIdentifier.symbols new file mode 100644 index 00000000000..0d0f1e80490 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifier.symbols @@ -0,0 +1,125 @@ +=== tests/cases/compiler/Element.ts === + +declare namespace JSX { +>JSX : Symbol(JSX, Decl(Element.ts, 0, 0)) + + interface Element { +>Element : Symbol(Element, Decl(Element.ts, 1, 23)) + + name: string; +>name : Symbol(Element.name, Decl(Element.ts, 2, 23)) + + isIntrinsic: boolean; +>isIntrinsic : Symbol(Element.isIntrinsic, Decl(Element.ts, 3, 21)) + + isCustomElement: boolean; +>isCustomElement : Symbol(Element.isCustomElement, Decl(Element.ts, 4, 29)) + + toString(renderId?: number): string; +>toString : Symbol(Element.toString, Decl(Element.ts, 5, 33)) +>renderId : Symbol(renderId, Decl(Element.ts, 6, 17)) + + bindDOM(renderId?: number): number; +>bindDOM : Symbol(Element.bindDOM, Decl(Element.ts, 6, 44)) +>renderId : Symbol(renderId, Decl(Element.ts, 7, 16)) + + resetComponent(): void; +>resetComponent : Symbol(Element.resetComponent, Decl(Element.ts, 7, 43)) + + instantiateComponents(renderId?: number): number; +>instantiateComponents : Symbol(Element.instantiateComponents, Decl(Element.ts, 8, 31)) +>renderId : Symbol(renderId, Decl(Element.ts, 9, 30)) + + props: any; +>props : Symbol(Element.props, Decl(Element.ts, 9, 57)) + } +} +export namespace Element { +>Element : Symbol(Element, Decl(Element.ts, 12, 1)) + + export function isElement(el: any): el is JSX.Element { +>isElement : Symbol(isElement, Decl(Element.ts, 13, 26)) +>el : Symbol(el, Decl(Element.ts, 14, 30)) +>el : Symbol(el, Decl(Element.ts, 14, 30)) +>JSX : Symbol(JSX, Decl(Element.ts, 0, 0)) +>Element : Symbol(JSX.Element, Decl(Element.ts, 1, 23)) + + return el.markAsChildOfRootElement !== undefined; +>el : Symbol(el, Decl(Element.ts, 14, 30)) +>undefined : Symbol(undefined) + } + + export function createElement(args: any[]) { +>createElement : Symbol(createElement, Decl(Element.ts, 16, 5)) +>args : Symbol(args, Decl(Element.ts, 18, 34)) + + return { + } + } +} + +export let createElement = Element.createElement; +>createElement : Symbol(createElement, Decl(Element.ts, 25, 10)) +>Element.createElement : Symbol(Element.createElement, Decl(Element.ts, 16, 5)) +>Element : Symbol(Element, Decl(Element.ts, 12, 1)) +>createElement : Symbol(Element.createElement, Decl(Element.ts, 16, 5)) + +function toCamelCase(text: string): string { +>toCamelCase : Symbol(toCamelCase, Decl(Element.ts, 25, 49)) +>text : Symbol(text, Decl(Element.ts, 27, 21)) + + return text[0].toLowerCase() + text.substring(1); +>text[0].toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) +>text : Symbol(text, Decl(Element.ts, 27, 21)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) +>text.substring : Symbol(String.substring, Decl(lib.es5.d.ts, --, --)) +>text : Symbol(text, Decl(Element.ts, 27, 21)) +>substring : Symbol(String.substring, Decl(lib.es5.d.ts, --, --)) +} + +=== tests/cases/compiler/test.tsx === +import { Element} from './Element'; +>Element : Symbol(Element, Decl(test.tsx, 0, 8)) + +let createElement = Element.createElement; +>createElement : Symbol(createElement, Decl(test.tsx, 1, 3)) +>Element.createElement : Symbol(Element.createElement, Decl(Element.ts, 16, 5)) +>Element : Symbol(Element, Decl(test.tsx, 0, 8)) +>createElement : Symbol(Element.createElement, Decl(Element.ts, 16, 5)) + +let c: { +>c : Symbol(c, Decl(test.tsx, 2, 3)) + + a?: { +>a : Symbol(a, Decl(test.tsx, 2, 8)) + + b: string +>b : Symbol(b, Decl(test.tsx, 3, 6)) + } +}; + +class A { +>A : Symbol(A, Decl(test.tsx, 6, 2)) + + view() { +>view : Symbol(A.view, Decl(test.tsx, 8, 9)) + + return [ + , +>meta : Symbol(unknown) +>content : Symbol(unknown) +>meta : Symbol(unknown) + + +>meta : Symbol(unknown) +>content : Symbol(unknown) +>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6)) +>c.a : Symbol(a, Decl(test.tsx, 2, 8)) +>c : Symbol(c, Decl(test.tsx, 2, 3)) +>a : Symbol(a, Decl(test.tsx, 2, 8)) +>b : Symbol(b, Decl(test.tsx, 3, 6)) +>meta : Symbol(unknown) + + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryIdentifier.types b/tests/baselines/reference/jsxFactoryIdentifier.types new file mode 100644 index 00000000000..c946c90559d --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifier.types @@ -0,0 +1,140 @@ +=== tests/cases/compiler/Element.ts === + +declare namespace JSX { +>JSX : any + + interface Element { +>Element : Element + + name: string; +>name : string + + isIntrinsic: boolean; +>isIntrinsic : boolean + + isCustomElement: boolean; +>isCustomElement : boolean + + toString(renderId?: number): string; +>toString : (renderId?: number) => string +>renderId : number + + bindDOM(renderId?: number): number; +>bindDOM : (renderId?: number) => number +>renderId : number + + resetComponent(): void; +>resetComponent : () => void + + instantiateComponents(renderId?: number): number; +>instantiateComponents : (renderId?: number) => number +>renderId : number + + props: any; +>props : any + } +} +export namespace Element { +>Element : typeof Element + + export function isElement(el: any): el is JSX.Element { +>isElement : (el: any) => el is JSX.Element +>el : any +>el : any +>JSX : any +>Element : JSX.Element + + return el.markAsChildOfRootElement !== undefined; +>el.markAsChildOfRootElement !== undefined : boolean +>el.markAsChildOfRootElement : any +>el : any +>markAsChildOfRootElement : any +>undefined : undefined + } + + export function createElement(args: any[]) { +>createElement : (args: any[]) => {} +>args : any[] + + return { +>{ } : {} + } + } +} + +export let createElement = Element.createElement; +>createElement : (args: any[]) => {} +>Element.createElement : (args: any[]) => {} +>Element : typeof Element +>createElement : (args: any[]) => {} + +function toCamelCase(text: string): string { +>toCamelCase : (text: string) => string +>text : string + + return text[0].toLowerCase() + text.substring(1); +>text[0].toLowerCase() + text.substring(1) : string +>text[0].toLowerCase() : string +>text[0].toLowerCase : () => string +>text[0] : string +>text : string +>0 : 0 +>toLowerCase : () => string +>text.substring(1) : string +>text.substring : (start: number, end?: number) => string +>text : string +>substring : (start: number, end?: number) => string +>1 : 1 +} + +=== tests/cases/compiler/test.tsx === +import { Element} from './Element'; +>Element : typeof Element + +let createElement = Element.createElement; +>createElement : (args: any[]) => {} +>Element.createElement : (args: any[]) => {} +>Element : typeof Element +>createElement : (args: any[]) => {} + +let c: { +>c : { a?: { b: string; }; } + + a?: { +>a : { b: string; } + + b: string +>b : string + } +}; + +class A { +>A : A + + view() { +>view : () => any[] + + return [ +>[ , ] : any[] + + , +> : any +>meta : any +>content : any +>meta : any + + +> : any +>meta : any +>content : any +>c.a!.b : string +>c.a! : { b: string; } +>c.a : { b: string; } +>c : { a?: { b: string; }; } +>a : { b: string; } +>b : string +>meta : any + + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryIdentifierAsParameter.js b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.js new file mode 100644 index 00000000000..ffec40ff7b6 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.js @@ -0,0 +1,24 @@ +//// [test.tsx] + +declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } +} + +export class AppComponent { + render(createElement) { + return
; + } +} + + +//// [test.js] +"use strict"; +class AppComponent { + render(createElement) { + return createElement("div", null); + } +} +exports.AppComponent = AppComponent; +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifierAsParameter.js.map b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.js.map new file mode 100644 index 00000000000..c108b93a913 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.js.map @@ -0,0 +1,2 @@ +//// [test.js.map] +{"version":3,"file":"test.js","sourceRoot":"","sources":["test.tsx"],"names":[],"mappings":";AAOA;IACI,MAAM,CAAC,aAAa;QAChB,MAAM,CAAC,0BAAO,CAAC;IACnB,CAAC;CACJ;AAJD,oCAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifierAsParameter.sourcemap.txt b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.sourcemap.txt new file mode 100644 index 00000000000..c7867fc54e0 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.sourcemap.txt @@ -0,0 +1,87 @@ +=================================================================== +JsFile: test.js +mapUrl: test.js.map +sourceRoot: +sources: test.tsx +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/test.js +sourceFile:test.tsx +------------------------------------------------------------------- +>>>"use strict"; +>>>class AppComponent { +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >declare module JSX { + > interface IntrinsicElements { + > [s: string]: any; + > } + >} + > + > +1 >Emitted(2, 1) Source(8, 1) + SourceIndex(0) +--- +>>> render(createElement) { +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^ +5 > ^^^^^^^^^^^^^^^^^^^-> +1->export class AppComponent { + > +2 > render +3 > ( +4 > createElement +1->Emitted(3, 5) Source(9, 5) + SourceIndex(0) +2 >Emitted(3, 11) Source(9, 11) + SourceIndex(0) +3 >Emitted(3, 12) Source(9, 12) + SourceIndex(0) +4 >Emitted(3, 25) Source(9, 25) + SourceIndex(0) +--- +>>> return createElement("div", null); +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 > ^ +1->) { + > +2 > return +3 > +4 >
+5 > ; +1->Emitted(4, 9) Source(10, 9) + SourceIndex(0) +2 >Emitted(4, 15) Source(10, 15) + SourceIndex(0) +3 >Emitted(4, 16) Source(10, 16) + SourceIndex(0) +4 >Emitted(4, 42) Source(10, 23) + SourceIndex(0) +5 >Emitted(4, 43) Source(10, 24) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(5, 5) Source(11, 5) + SourceIndex(0) +2 >Emitted(5, 6) Source(11, 6) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +1 >Emitted(6, 2) Source(12, 2) + SourceIndex(0) +--- +>>>exports.AppComponent = AppComponent; +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> +2 >export class AppComponent { + > render(createElement) { + > return
; + > } + >} +1->Emitted(7, 1) Source(8, 1) + SourceIndex(0) +2 >Emitted(7, 37) Source(12, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifierAsParameter.symbols b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.symbols new file mode 100644 index 00000000000..865292092a5 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/test.tsx === + +declare module JSX { +>JSX : Symbol(JSX, Decl(test.tsx, 0, 0)) + + interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(test.tsx, 1, 20)) + + [s: string]: any; +>s : Symbol(s, Decl(test.tsx, 3, 9)) + } +} + +export class AppComponent { +>AppComponent : Symbol(AppComponent, Decl(test.tsx, 5, 1)) + + render(createElement) { +>render : Symbol(AppComponent.render, Decl(test.tsx, 7, 27)) +>createElement : Symbol(createElement, Decl(test.tsx, 8, 11)) + + return
; +>div : Symbol(unknown) + } +} + diff --git a/tests/baselines/reference/jsxFactoryIdentifierAsParameter.types b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.types new file mode 100644 index 00000000000..d55737d98ae --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierAsParameter.types @@ -0,0 +1,26 @@ +=== tests/cases/compiler/test.tsx === + +declare module JSX { +>JSX : any + + interface IntrinsicElements { +>IntrinsicElements : IntrinsicElements + + [s: string]: any; +>s : string + } +} + +export class AppComponent { +>AppComponent : AppComponent + + render(createElement) { +>render : (createElement: any) => any +>createElement : any + + return
; +>
: any +>div : any + } +} + diff --git a/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.errors.txt b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.errors.txt new file mode 100644 index 00000000000..99e039a045f --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.errors.txt @@ -0,0 +1,19 @@ +tests/cases/compiler/test.tsx(10,17): error TS2304: Cannot find name 'createElement'. + + +==== tests/cases/compiler/test.tsx (1 errors) ==== + + declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } + } + + export class AppComponent { + render() { + return
; + ~~~ +!!! error TS2304: Cannot find name 'createElement'. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.js b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.js new file mode 100644 index 00000000000..23f6f44e0c7 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.js @@ -0,0 +1,24 @@ +//// [test.tsx] + +declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } +} + +export class AppComponent { + render() { + return
; + } +} + + +//// [test.js] +"use strict"; +class AppComponent { + render() { + return createElement("div", null); + } +} +exports.AppComponent = AppComponent; +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.js.map b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.js.map new file mode 100644 index 00000000000..715014ff53f --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.js.map @@ -0,0 +1,2 @@ +//// [test.js.map] +{"version":3,"file":"test.js","sourceRoot":"","sources":["test.tsx"],"names":[],"mappings":";AAOA;IACI,MAAM;QACF,MAAM,CAAC,0BAAO,CAAC;IACnB,CAAC;CACJ;AAJD,oCAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.sourcemap.txt b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.sourcemap.txt new file mode 100644 index 00000000000..f1ebaf49870 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.sourcemap.txt @@ -0,0 +1,81 @@ +=================================================================== +JsFile: test.js +mapUrl: test.js.map +sourceRoot: +sources: test.tsx +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/test.js +sourceFile:test.tsx +------------------------------------------------------------------- +>>>"use strict"; +>>>class AppComponent { +1 > +2 >^^^^^^^^^^^^^^^-> +1 > + >declare module JSX { + > interface IntrinsicElements { + > [s: string]: any; + > } + >} + > + > +1 >Emitted(2, 1) Source(8, 1) + SourceIndex(0) +--- +>>> render() { +1->^^^^ +2 > ^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->export class AppComponent { + > +2 > render +1->Emitted(3, 5) Source(9, 5) + SourceIndex(0) +2 >Emitted(3, 11) Source(9, 11) + SourceIndex(0) +--- +>>> return createElement("div", null); +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 > ^ +1->() { + > +2 > return +3 > +4 >
+5 > ; +1->Emitted(4, 9) Source(10, 9) + SourceIndex(0) +2 >Emitted(4, 15) Source(10, 15) + SourceIndex(0) +3 >Emitted(4, 16) Source(10, 16) + SourceIndex(0) +4 >Emitted(4, 42) Source(10, 23) + SourceIndex(0) +5 >Emitted(4, 43) Source(10, 24) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(5, 5) Source(11, 5) + SourceIndex(0) +2 >Emitted(5, 6) Source(11, 6) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +1 >Emitted(6, 2) Source(12, 2) + SourceIndex(0) +--- +>>>exports.AppComponent = AppComponent; +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> +2 >export class AppComponent { + > render() { + > return
; + > } + >} +1->Emitted(7, 1) Source(8, 1) + SourceIndex(0) +2 >Emitted(7, 37) Source(12, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.errors.txt b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.errors.txt new file mode 100644 index 00000000000..e14f5f988f8 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.errors.txt @@ -0,0 +1,59 @@ +error TS5067: Invalid value for 'jsxFactory'. 'Element.createElement=' is not a valid identifier or qualified-name. +tests/cases/compiler/test.tsx(12,5): error TS2304: Cannot find name 'React'. +tests/cases/compiler/test.tsx(13,5): error TS2304: Cannot find name 'React'. + + +!!! error TS5067: Invalid value for 'jsxFactory'. 'Element.createElement=' is not a valid identifier or qualified-name. +==== tests/cases/compiler/Element.ts (0 errors) ==== + + declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } + } + export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } + } + + export let createElement = Element.createElement; + + function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); + } + +==== tests/cases/compiler/test.tsx (2 errors) ==== + import { Element} from './Element'; + + let c: { + a?: { + b: string + } + }; + + class A { + view() { + return [ + , + ~~~~ +!!! error TS2304: Cannot find name 'React'. + + ~~~~ +!!! error TS2304: Cannot find name 'React'. + ]; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.js b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.js new file mode 100644 index 00000000000..90bb675442a --- /dev/null +++ b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.js @@ -0,0 +1,80 @@ +//// [tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName.ts] //// + +//// [Element.ts] + +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +//// [test.tsx] +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} + +//// [Element.js] +"use strict"; +var Element; +(function (Element) { + function isElement(el) { + return el.markAsChildOfRootElement !== undefined; + } + Element.isElement = isElement; + function createElement(args) { + return {}; + } + Element.createElement = createElement; +})(Element = exports.Element || (exports.Element = {})); +exports.createElement = Element.createElement; +function toCamelCase(text) { + return text[0].toLowerCase() + text.substring(1); +} +//// [test.js] +"use strict"; +let c; +class A { + view() { + return [ + React.createElement("meta", { content: "helloworld" }), + React.createElement("meta", { content: c.a.b }) + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.errors.txt b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.errors.txt new file mode 100644 index 00000000000..1c33f3a7a51 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.errors.txt @@ -0,0 +1,59 @@ +error TS5067: Invalid value for 'jsxFactory'. 'id1 id2' is not a valid identifier or qualified-name. +tests/cases/compiler/test.tsx(12,5): error TS2304: Cannot find name 'React'. +tests/cases/compiler/test.tsx(13,5): error TS2304: Cannot find name 'React'. + + +!!! error TS5067: Invalid value for 'jsxFactory'. 'id1 id2' is not a valid identifier or qualified-name. +==== tests/cases/compiler/Element.ts (0 errors) ==== + + declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } + } + export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } + } + + export let createElement = Element.createElement; + + function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); + } + +==== tests/cases/compiler/test.tsx (2 errors) ==== + import { Element} from './Element'; + + let c: { + a?: { + b: string + } + }; + + class A { + view() { + return [ + , + ~~~~ +!!! error TS2304: Cannot find name 'React'. + + ~~~~ +!!! error TS2304: Cannot find name 'React'. + ]; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.js b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.js new file mode 100644 index 00000000000..0bc0c6e57c5 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.js @@ -0,0 +1,80 @@ +//// [tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName2.ts] //// + +//// [Element.ts] + +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +//// [test.tsx] +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} + +//// [Element.js] +"use strict"; +var Element; +(function (Element) { + function isElement(el) { + return el.markAsChildOfRootElement !== undefined; + } + Element.isElement = isElement; + function createElement(args) { + return {}; + } + Element.createElement = createElement; +})(Element = exports.Element || (exports.Element = {})); +exports.createElement = Element.createElement; +function toCamelCase(text) { + return text[0].toLowerCase() + text.substring(1); +} +//// [test.js] +"use strict"; +let c; +class A { + view() { + return [ + React.createElement("meta", { content: "helloworld" }), + React.createElement("meta", { content: c.a.b }) + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryQualifiedName.js b/tests/baselines/reference/jsxFactoryQualifiedName.js new file mode 100644 index 00000000000..80a77d35302 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedName.js @@ -0,0 +1,82 @@ +//// [tests/cases/compiler/jsxFactoryQualifiedName.ts] //// + +//// [Element.ts] + +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +//// [test.tsx] +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} + +//// [Element.js] +"use strict"; +var Element; +(function (Element) { + function isElement(el) { + return el.markAsChildOfRootElement !== undefined; + } + Element.isElement = isElement; + function createElement(args) { + return {}; + } + Element.createElement = createElement; +})(Element = exports.Element || (exports.Element = {})); +exports.createElement = Element.createElement; +function toCamelCase(text) { + return text[0].toLowerCase() + text.substring(1); +} +//# sourceMappingURL=Element.js.map//// [test.js] +"use strict"; +const Element_1 = require("./Element"); +let c; +class A { + view() { + return [ + Element_1.Element.createElement("meta", { content: "helloworld" }), + Element_1.Element.createElement("meta", { content: c.a.b }) + ]; + } +} +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedName.js.map b/tests/baselines/reference/jsxFactoryQualifiedName.js.map new file mode 100644 index 00000000000..f8cef24a0f0 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedName.js.map @@ -0,0 +1,3 @@ +//// [Element.js.map] +{"version":3,"file":"Element.js","sourceRoot":"","sources":["Element.ts"],"names":[],"mappings":";AAaA,IAAiB,OAAO,CAUvB;AAVD,WAAiB,OAAO;IACpB,mBAA0B,EAAO;QAC7B,MAAM,CAAC,EAAE,CAAC,wBAAwB,KAAK,SAAS,CAAC;IACrD,CAAC;IAFe,iBAAS,YAExB,CAAA;IAED,uBAA8B,IAAW;QAErC,MAAM,CAAC,EACN,CAAA;IACL,CAAC;IAJe,qBAAa,gBAI5B,CAAA;AACL,CAAC,EAVgB,OAAO,GAAP,eAAO,KAAP,eAAO,QAUvB;AAEU,QAAA,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAEjD,qBAAqB,IAAY;IAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACrD,CAAC"}//// [test.js.map] +{"version":3,"file":"test.js","sourceRoot":"","sources":["test.tsx"],"names":[],"mappings":";AAAA,uCAAmC;AAEnC,IAAI,CAIH,CAAC;AAEF;IACC,IAAI;QACH,MAAM,CAAC;YACN,0CAAM,OAAO,EAAC,YAAY,GAAQ;YAClC,0CAAM,OAAO,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC,GAAS;SAC9B,CAAC;IACH,CAAC;CACD"} \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedName.sourcemap.txt b/tests/baselines/reference/jsxFactoryQualifiedName.sourcemap.txt new file mode 100644 index 00000000000..98517620c73 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedName.sourcemap.txt @@ -0,0 +1,493 @@ +=================================================================== +JsFile: Element.js +mapUrl: Element.js.map +sourceRoot: +sources: Element.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/Element.js +sourceFile:Element.ts +------------------------------------------------------------------- +>>>"use strict"; +>>>var Element; +1 > +2 >^^^^ +3 > ^^^^^^^ +4 > ^ +5 > ^^^^^^^^^^-> +1 > + >declare namespace JSX { + > interface Element { + > name: string; + > isIntrinsic: boolean; + > isCustomElement: boolean; + > toString(renderId?: number): string; + > bindDOM(renderId?: number): number; + > resetComponent(): void; + > instantiateComponents(renderId?: number): number; + > props: any; + > } + >} + > +2 >export namespace +3 > Element +4 > { + > export function isElement(el: any): el is JSX.Element { + > return el.markAsChildOfRootElement !== undefined; + > } + > + > export function createElement(args: any[]) { + > + > return { + > } + > } + > } +1 >Emitted(2, 1) Source(14, 1) + SourceIndex(0) +2 >Emitted(2, 5) Source(14, 18) + SourceIndex(0) +3 >Emitted(2, 12) Source(14, 25) + SourceIndex(0) +4 >Emitted(2, 13) Source(24, 2) + SourceIndex(0) +--- +>>>(function (Element) { +1-> +2 >^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^^^^^^^^^^^-> +1-> +2 >export namespace +3 > Element +1->Emitted(3, 1) Source(14, 1) + SourceIndex(0) +2 >Emitted(3, 12) Source(14, 18) + SourceIndex(0) +3 >Emitted(3, 19) Source(14, 25) + SourceIndex(0) +--- +>>> function isElement(el) { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> { + > +2 > export function isElement( +3 > el: any +1->Emitted(4, 5) Source(15, 5) + SourceIndex(0) +2 >Emitted(4, 24) Source(15, 31) + SourceIndex(0) +3 >Emitted(4, 26) Source(15, 38) + SourceIndex(0) +--- +>>> return el.markAsChildOfRootElement !== undefined; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +6 > ^^^^^^^^^^^^^^^^^^^^^^^^ +7 > ^^^^^ +8 > ^^^^^^^^^ +9 > ^ +1->): el is JSX.Element { + > +2 > return +3 > +4 > el +5 > . +6 > markAsChildOfRootElement +7 > !== +8 > undefined +9 > ; +1->Emitted(5, 9) Source(16, 9) + SourceIndex(0) +2 >Emitted(5, 15) Source(16, 15) + SourceIndex(0) +3 >Emitted(5, 16) Source(16, 16) + SourceIndex(0) +4 >Emitted(5, 18) Source(16, 18) + SourceIndex(0) +5 >Emitted(5, 19) Source(16, 19) + SourceIndex(0) +6 >Emitted(5, 43) Source(16, 43) + SourceIndex(0) +7 >Emitted(5, 48) Source(16, 48) + SourceIndex(0) +8 >Emitted(5, 57) Source(16, 57) + SourceIndex(0) +9 >Emitted(5, 58) Source(16, 58) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(6, 5) Source(17, 5) + SourceIndex(0) +2 >Emitted(6, 6) Source(17, 6) + SourceIndex(0) +--- +>>> Element.isElement = isElement; +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^ +4 > ^ +5 > ^-> +1-> +2 > isElement +3 > (el: any): el is JSX.Element { + > return el.markAsChildOfRootElement !== undefined; + > } +4 > +1->Emitted(7, 5) Source(15, 21) + SourceIndex(0) +2 >Emitted(7, 22) Source(15, 30) + SourceIndex(0) +3 >Emitted(7, 34) Source(17, 6) + SourceIndex(0) +4 >Emitted(7, 35) Source(17, 6) + SourceIndex(0) +--- +>>> function createElement(args) { +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^ +1-> + > + > +2 > export function createElement( +3 > args: any[] +1->Emitted(8, 5) Source(19, 5) + SourceIndex(0) +2 >Emitted(8, 28) Source(19, 35) + SourceIndex(0) +3 >Emitted(8, 32) Source(19, 46) + SourceIndex(0) +--- +>>> return {}; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >) { + > + > +2 > return +3 > +4 > { + > } +5 > +1 >Emitted(9, 9) Source(21, 9) + SourceIndex(0) +2 >Emitted(9, 15) Source(21, 15) + SourceIndex(0) +3 >Emitted(9, 16) Source(21, 16) + SourceIndex(0) +4 >Emitted(9, 18) Source(22, 10) + SourceIndex(0) +5 >Emitted(9, 19) Source(22, 10) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(10, 5) Source(23, 5) + SourceIndex(0) +2 >Emitted(10, 6) Source(23, 6) + SourceIndex(0) +--- +>>> Element.createElement = createElement; +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^ +4 > ^ +5 > ^^^^^^^^^^^^^^^-> +1-> +2 > createElement +3 > (args: any[]) { + > + > return { + > } + > } +4 > +1->Emitted(11, 5) Source(19, 21) + SourceIndex(0) +2 >Emitted(11, 26) Source(19, 34) + SourceIndex(0) +3 >Emitted(11, 42) Source(23, 6) + SourceIndex(0) +4 >Emitted(11, 43) Source(23, 6) + SourceIndex(0) +--- +>>>})(Element = exports.Element || (exports.Element = {})); +1-> +2 >^ +3 > ^^ +4 > ^^^^^^^ +5 > ^^^ +6 > ^^^^^^^^^^^^^^^ +7 > ^^^^^ +8 > ^^^^^^^^^^^^^^^ +9 > ^^^^^^^^ +1-> + > +2 >} +3 > +4 > Element +5 > +6 > Element +7 > +8 > Element +9 > { + > export function isElement(el: any): el is JSX.Element { + > return el.markAsChildOfRootElement !== undefined; + > } + > + > export function createElement(args: any[]) { + > + > return { + > } + > } + > } +1->Emitted(12, 1) Source(24, 1) + SourceIndex(0) +2 >Emitted(12, 2) Source(24, 2) + SourceIndex(0) +3 >Emitted(12, 4) Source(14, 18) + SourceIndex(0) +4 >Emitted(12, 11) Source(14, 25) + SourceIndex(0) +5 >Emitted(12, 14) Source(14, 18) + SourceIndex(0) +6 >Emitted(12, 29) Source(14, 25) + SourceIndex(0) +7 >Emitted(12, 34) Source(14, 18) + SourceIndex(0) +8 >Emitted(12, 49) Source(14, 25) + SourceIndex(0) +9 >Emitted(12, 57) Source(24, 2) + SourceIndex(0) +--- +>>>exports.createElement = Element.createElement; +1 > +2 >^^^^^^^^ +3 > ^^^^^^^^^^^^^ +4 > ^^^ +5 > ^^^^^^^ +6 > ^ +7 > ^^^^^^^^^^^^^ +8 > ^ +1 > + > + >export let +2 > +3 > createElement +4 > = +5 > Element +6 > . +7 > createElement +8 > ; +1 >Emitted(13, 1) Source(26, 12) + SourceIndex(0) +2 >Emitted(13, 9) Source(26, 12) + SourceIndex(0) +3 >Emitted(13, 22) Source(26, 25) + SourceIndex(0) +4 >Emitted(13, 25) Source(26, 28) + SourceIndex(0) +5 >Emitted(13, 32) Source(26, 35) + SourceIndex(0) +6 >Emitted(13, 33) Source(26, 36) + SourceIndex(0) +7 >Emitted(13, 46) Source(26, 49) + SourceIndex(0) +8 >Emitted(13, 47) Source(26, 50) + SourceIndex(0) +--- +>>>function toCamelCase(text) { +1 > +2 >^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > + > +2 >function toCamelCase( +3 > text: string +1 >Emitted(14, 1) Source(28, 1) + SourceIndex(0) +2 >Emitted(14, 22) Source(28, 22) + SourceIndex(0) +3 >Emitted(14, 26) Source(28, 34) + SourceIndex(0) +--- +>>> return text[0].toLowerCase() + text.substring(1); +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^ +10> ^^ +11> ^^^ +12> ^^^^ +13> ^ +14> ^^^^^^^^^ +15> ^ +16> ^ +17> ^ +18> ^ +1->): string { + > +2 > return +3 > +4 > text +5 > [ +6 > 0 +7 > ] +8 > . +9 > toLowerCase +10> () +11> + +12> text +13> . +14> substring +15> ( +16> 1 +17> ) +18> ; +1->Emitted(15, 5) Source(29, 5) + SourceIndex(0) +2 >Emitted(15, 11) Source(29, 11) + SourceIndex(0) +3 >Emitted(15, 12) Source(29, 12) + SourceIndex(0) +4 >Emitted(15, 16) Source(29, 16) + SourceIndex(0) +5 >Emitted(15, 17) Source(29, 17) + SourceIndex(0) +6 >Emitted(15, 18) Source(29, 18) + SourceIndex(0) +7 >Emitted(15, 19) Source(29, 19) + SourceIndex(0) +8 >Emitted(15, 20) Source(29, 20) + SourceIndex(0) +9 >Emitted(15, 31) Source(29, 31) + SourceIndex(0) +10>Emitted(15, 33) Source(29, 33) + SourceIndex(0) +11>Emitted(15, 36) Source(29, 36) + SourceIndex(0) +12>Emitted(15, 40) Source(29, 40) + SourceIndex(0) +13>Emitted(15, 41) Source(29, 41) + SourceIndex(0) +14>Emitted(15, 50) Source(29, 50) + SourceIndex(0) +15>Emitted(15, 51) Source(29, 51) + SourceIndex(0) +16>Emitted(15, 52) Source(29, 52) + SourceIndex(0) +17>Emitted(15, 53) Source(29, 53) + SourceIndex(0) +18>Emitted(15, 54) Source(29, 54) + SourceIndex(0) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +1 >Emitted(16, 1) Source(30, 1) + SourceIndex(0) +2 >Emitted(16, 2) Source(30, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=Element.js.map=================================================================== +JsFile: test.js +mapUrl: test.js.map +sourceRoot: +sources: test.tsx +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/test.js +sourceFile:test.tsx +------------------------------------------------------------------- +>>>"use strict"; +>>>const Element_1 = require("./Element"); +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1 > +2 >import { Element} from './Element'; +1 >Emitted(2, 1) Source(1, 1) + SourceIndex(0) +2 >Emitted(2, 40) Source(1, 36) + SourceIndex(0) +--- +>>>let c; +1 > +2 >^^^^ +3 > ^ +4 > ^ +5 > ^^^^-> +1 > + > + > +2 >let +3 > c: { + > a?: { + > b: string + > } + > } +4 > ; +1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(3, 5) Source(3, 5) + SourceIndex(0) +3 >Emitted(3, 6) Source(7, 2) + SourceIndex(0) +4 >Emitted(3, 7) Source(7, 3) + SourceIndex(0) +--- +>>>class A { +1-> +2 >^^^^^^^^^^^^^-> +1-> + > + > +1->Emitted(4, 1) Source(9, 1) + SourceIndex(0) +--- +>>> view() { +1->^^^^ +2 > ^^^^ +3 > ^^^^^^^^^-> +1->class A { + > +2 > view +1->Emitted(5, 5) Source(10, 2) + SourceIndex(0) +2 >Emitted(5, 9) Source(10, 6) + SourceIndex(0) +--- +>>> return [ +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->() { + > +2 > return +3 > +1->Emitted(6, 9) Source(11, 3) + SourceIndex(0) +2 >Emitted(6, 15) Source(11, 9) + SourceIndex(0) +3 >Emitted(6, 16) Source(11, 10) + SourceIndex(0) +--- +>>> Element_1.Element.createElement("meta", { content: "helloworld" }), +1->^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^^^^ +6 > ^^^ +1->[ + > +2 > content +4 > = +5 > "helloworld" +6 > > +1->Emitted(7, 13) Source(12, 4) + SourceIndex(0) +2 >Emitted(7, 55) Source(12, 10) + SourceIndex(0) +3 >Emitted(7, 62) Source(12, 17) + SourceIndex(0) +4 >Emitted(7, 64) Source(12, 18) + SourceIndex(0) +5 >Emitted(7, 76) Source(12, 30) + SourceIndex(0) +6 >Emitted(7, 79) Source(12, 38) + SourceIndex(0) +--- +>>> Element_1.Element.createElement("meta", { content: c.a.b }) +1 >^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^ +4 > ^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^ +10> ^^^ +1 >, + > +2 > content +4 > ={ +5 > c +6 > . +7 > a! +8 > . +9 > b +10> }> +1 >Emitted(8, 13) Source(13, 4) + SourceIndex(0) +2 >Emitted(8, 55) Source(13, 10) + SourceIndex(0) +3 >Emitted(8, 62) Source(13, 17) + SourceIndex(0) +4 >Emitted(8, 64) Source(13, 19) + SourceIndex(0) +5 >Emitted(8, 65) Source(13, 20) + SourceIndex(0) +6 >Emitted(8, 66) Source(13, 21) + SourceIndex(0) +7 >Emitted(8, 67) Source(13, 23) + SourceIndex(0) +8 >Emitted(8, 68) Source(13, 24) + SourceIndex(0) +9 >Emitted(8, 69) Source(13, 25) + SourceIndex(0) +10>Emitted(8, 72) Source(13, 34) + SourceIndex(0) +--- +>>> ]; +1 >^^^^^^^^^ +2 > ^ +1 > + > ] +2 > ; +1 >Emitted(9, 10) Source(14, 4) + SourceIndex(0) +2 >Emitted(9, 11) Source(14, 5) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(10, 5) Source(15, 2) + SourceIndex(0) +2 >Emitted(10, 6) Source(15, 3) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +1 >Emitted(11, 2) Source(16, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedName.symbols b/tests/baselines/reference/jsxFactoryQualifiedName.symbols new file mode 100644 index 00000000000..16cd35d1ca3 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedName.symbols @@ -0,0 +1,119 @@ +=== tests/cases/compiler/Element.ts === + +declare namespace JSX { +>JSX : Symbol(JSX, Decl(Element.ts, 0, 0)) + + interface Element { +>Element : Symbol(Element, Decl(Element.ts, 1, 23)) + + name: string; +>name : Symbol(Element.name, Decl(Element.ts, 2, 23)) + + isIntrinsic: boolean; +>isIntrinsic : Symbol(Element.isIntrinsic, Decl(Element.ts, 3, 21)) + + isCustomElement: boolean; +>isCustomElement : Symbol(Element.isCustomElement, Decl(Element.ts, 4, 29)) + + toString(renderId?: number): string; +>toString : Symbol(Element.toString, Decl(Element.ts, 5, 33)) +>renderId : Symbol(renderId, Decl(Element.ts, 6, 17)) + + bindDOM(renderId?: number): number; +>bindDOM : Symbol(Element.bindDOM, Decl(Element.ts, 6, 44)) +>renderId : Symbol(renderId, Decl(Element.ts, 7, 16)) + + resetComponent(): void; +>resetComponent : Symbol(Element.resetComponent, Decl(Element.ts, 7, 43)) + + instantiateComponents(renderId?: number): number; +>instantiateComponents : Symbol(Element.instantiateComponents, Decl(Element.ts, 8, 31)) +>renderId : Symbol(renderId, Decl(Element.ts, 9, 30)) + + props: any; +>props : Symbol(Element.props, Decl(Element.ts, 9, 57)) + } +} +export namespace Element { +>Element : Symbol(Element, Decl(Element.ts, 12, 1)) + + export function isElement(el: any): el is JSX.Element { +>isElement : Symbol(isElement, Decl(Element.ts, 13, 26)) +>el : Symbol(el, Decl(Element.ts, 14, 30)) +>el : Symbol(el, Decl(Element.ts, 14, 30)) +>JSX : Symbol(JSX, Decl(Element.ts, 0, 0)) +>Element : Symbol(JSX.Element, Decl(Element.ts, 1, 23)) + + return el.markAsChildOfRootElement !== undefined; +>el : Symbol(el, Decl(Element.ts, 14, 30)) +>undefined : Symbol(undefined) + } + + export function createElement(args: any[]) { +>createElement : Symbol(createElement, Decl(Element.ts, 16, 5)) +>args : Symbol(args, Decl(Element.ts, 18, 34)) + + return { + } + } +} + +export let createElement = Element.createElement; +>createElement : Symbol(createElement, Decl(Element.ts, 25, 10)) +>Element.createElement : Symbol(Element.createElement, Decl(Element.ts, 16, 5)) +>Element : Symbol(Element, Decl(Element.ts, 12, 1)) +>createElement : Symbol(Element.createElement, Decl(Element.ts, 16, 5)) + +function toCamelCase(text: string): string { +>toCamelCase : Symbol(toCamelCase, Decl(Element.ts, 25, 49)) +>text : Symbol(text, Decl(Element.ts, 27, 21)) + + return text[0].toLowerCase() + text.substring(1); +>text[0].toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) +>text : Symbol(text, Decl(Element.ts, 27, 21)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.es5.d.ts, --, --)) +>text.substring : Symbol(String.substring, Decl(lib.es5.d.ts, --, --)) +>text : Symbol(text, Decl(Element.ts, 27, 21)) +>substring : Symbol(String.substring, Decl(lib.es5.d.ts, --, --)) +} + +=== tests/cases/compiler/test.tsx === +import { Element} from './Element'; +>Element : Symbol(Element, Decl(test.tsx, 0, 8)) + +let c: { +>c : Symbol(c, Decl(test.tsx, 2, 3)) + + a?: { +>a : Symbol(a, Decl(test.tsx, 2, 8)) + + b: string +>b : Symbol(b, Decl(test.tsx, 3, 6)) + } +}; + +class A { +>A : Symbol(A, Decl(test.tsx, 6, 2)) + + view() { +>view : Symbol(A.view, Decl(test.tsx, 8, 9)) + + return [ + , +>meta : Symbol(unknown) +>content : Symbol(unknown) +>meta : Symbol(unknown) + + +>meta : Symbol(unknown) +>content : Symbol(unknown) +>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6)) +>c.a : Symbol(a, Decl(test.tsx, 2, 8)) +>c : Symbol(c, Decl(test.tsx, 2, 3)) +>a : Symbol(a, Decl(test.tsx, 2, 8)) +>b : Symbol(b, Decl(test.tsx, 3, 6)) +>meta : Symbol(unknown) + + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryQualifiedName.types b/tests/baselines/reference/jsxFactoryQualifiedName.types new file mode 100644 index 00000000000..663ba4b5bfc --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedName.types @@ -0,0 +1,134 @@ +=== tests/cases/compiler/Element.ts === + +declare namespace JSX { +>JSX : any + + interface Element { +>Element : Element + + name: string; +>name : string + + isIntrinsic: boolean; +>isIntrinsic : boolean + + isCustomElement: boolean; +>isCustomElement : boolean + + toString(renderId?: number): string; +>toString : (renderId?: number) => string +>renderId : number + + bindDOM(renderId?: number): number; +>bindDOM : (renderId?: number) => number +>renderId : number + + resetComponent(): void; +>resetComponent : () => void + + instantiateComponents(renderId?: number): number; +>instantiateComponents : (renderId?: number) => number +>renderId : number + + props: any; +>props : any + } +} +export namespace Element { +>Element : typeof Element + + export function isElement(el: any): el is JSX.Element { +>isElement : (el: any) => el is JSX.Element +>el : any +>el : any +>JSX : any +>Element : JSX.Element + + return el.markAsChildOfRootElement !== undefined; +>el.markAsChildOfRootElement !== undefined : boolean +>el.markAsChildOfRootElement : any +>el : any +>markAsChildOfRootElement : any +>undefined : undefined + } + + export function createElement(args: any[]) { +>createElement : (args: any[]) => {} +>args : any[] + + return { +>{ } : {} + } + } +} + +export let createElement = Element.createElement; +>createElement : (args: any[]) => {} +>Element.createElement : (args: any[]) => {} +>Element : typeof Element +>createElement : (args: any[]) => {} + +function toCamelCase(text: string): string { +>toCamelCase : (text: string) => string +>text : string + + return text[0].toLowerCase() + text.substring(1); +>text[0].toLowerCase() + text.substring(1) : string +>text[0].toLowerCase() : string +>text[0].toLowerCase : () => string +>text[0] : string +>text : string +>0 : 0 +>toLowerCase : () => string +>text.substring(1) : string +>text.substring : (start: number, end?: number) => string +>text : string +>substring : (start: number, end?: number) => string +>1 : 1 +} + +=== tests/cases/compiler/test.tsx === +import { Element} from './Element'; +>Element : typeof Element + +let c: { +>c : { a?: { b: string; }; } + + a?: { +>a : { b: string; } + + b: string +>b : string + } +}; + +class A { +>A : A + + view() { +>view : () => any[] + + return [ +>[ , ] : any[] + + , +> : any +>meta : any +>content : any +>meta : any + + +> : any +>meta : any +>content : any +>c.a!.b : string +>c.a! : { b: string; } +>c.a : { b: string; } +>c : { a?: { b: string; }; } +>a : { b: string; } +>b : string +>meta : any + + ]; + } +} diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.errors.txt b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.errors.txt new file mode 100644 index 00000000000..97a05d840f0 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/test.tsx(10,17): error TS2304: Cannot find name 'MyElement'. + + +==== tests/cases/compiler/test.tsx (1 errors) ==== + + declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } + } + + export class AppComponent { + render(createElement) { + return
; + ~~~ +!!! error TS2304: Cannot find name 'MyElement'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.js b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.js new file mode 100644 index 00000000000..6714b68a093 --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.js @@ -0,0 +1,23 @@ +//// [test.tsx] + +declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } +} + +export class AppComponent { + render(createElement) { + return
; + } +} + +//// [test.js] +"use strict"; +class AppComponent { + render(createElement) { + return MyElement.createElement("div", null); + } +} +exports.AppComponent = AppComponent; +//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.js.map b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.js.map new file mode 100644 index 00000000000..ac54c9638cd --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.js.map @@ -0,0 +1,2 @@ +//// [test.js.map] +{"version":3,"file":"test.js","sourceRoot":"","sources":["test.tsx"],"names":[],"mappings":";AAOA;IACI,MAAM,CAAC,aAAa;QAChB,MAAM,CAAC,oCAAO,CAAC;IACnB,CAAC;CACJ;AAJD,oCAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.sourcemap.txt b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.sourcemap.txt new file mode 100644 index 00000000000..2616efcf63b --- /dev/null +++ b/tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.sourcemap.txt @@ -0,0 +1,87 @@ +=================================================================== +JsFile: test.js +mapUrl: test.js.map +sourceRoot: +sources: test.tsx +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/test.js +sourceFile:test.tsx +------------------------------------------------------------------- +>>>"use strict"; +>>>class AppComponent { +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >declare module JSX { + > interface IntrinsicElements { + > [s: string]: any; + > } + >} + > + > +1 >Emitted(2, 1) Source(8, 1) + SourceIndex(0) +--- +>>> render(createElement) { +1->^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^ +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->export class AppComponent { + > +2 > render +3 > ( +4 > createElement +1->Emitted(3, 5) Source(9, 5) + SourceIndex(0) +2 >Emitted(3, 11) Source(9, 11) + SourceIndex(0) +3 >Emitted(3, 12) Source(9, 12) + SourceIndex(0) +4 >Emitted(3, 25) Source(9, 25) + SourceIndex(0) +--- +>>> return MyElement.createElement("div", null); +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 > ^ +1->) { + > +2 > return +3 > +4 >
+5 > ; +1->Emitted(4, 9) Source(10, 9) + SourceIndex(0) +2 >Emitted(4, 15) Source(10, 15) + SourceIndex(0) +3 >Emitted(4, 16) Source(10, 16) + SourceIndex(0) +4 >Emitted(4, 52) Source(10, 23) + SourceIndex(0) +5 >Emitted(4, 53) Source(10, 24) + SourceIndex(0) +--- +>>> } +1 >^^^^ +2 > ^ +1 > + > +2 > } +1 >Emitted(5, 5) Source(11, 5) + SourceIndex(0) +2 >Emitted(5, 6) Source(11, 6) + SourceIndex(0) +--- +>>>} +1 >^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + >} +1 >Emitted(6, 2) Source(12, 2) + SourceIndex(0) +--- +>>>exports.AppComponent = AppComponent; +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +1-> +2 >export class AppComponent { + > render(createElement) { + > return
; + > } + >} +1->Emitted(7, 1) Source(8, 1) + SourceIndex(0) +2 >Emitted(7, 37) Source(12, 2) + SourceIndex(0) +--- +>>>//# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/tests/baselines/reference/maxNodeModuleJsDepthDefaultsToZero.trace.json b/tests/baselines/reference/maxNodeModuleJsDepthDefaultsToZero.trace.json index 3a9d8c4ea79..f6df1476088 100644 --- a/tests/baselines/reference/maxNodeModuleJsDepthDefaultsToZero.trace.json +++ b/tests/baselines/reference/maxNodeModuleJsDepthDefaultsToZero.trace.json @@ -9,12 +9,8 @@ "File '/node_modules/shortid/index.ts' does not exist.", "File '/node_modules/shortid/index.tsx' does not exist.", "File '/node_modules/shortid/index.d.ts' does not exist.", - "File '/node_modules/@types/shortid.ts' does not exist.", - "File '/node_modules/@types/shortid.tsx' does not exist.", "File '/node_modules/@types/shortid.d.ts' does not exist.", "File '/node_modules/@types/shortid/package.json' does not exist.", - "File '/node_modules/@types/shortid/index.ts' does not exist.", - "File '/node_modules/@types/shortid/index.tsx' does not exist.", "File '/node_modules/@types/shortid/index.d.ts' does not exist.", "Loading module 'shortid' from 'node_modules' folder.", "File '/node_modules/shortid.js' does not exist.", diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_withAmbientPresent.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_withAmbientPresent.trace.json index 9c6d96fc190..8d4217a92bd 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_withAmbientPresent.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_withAmbientPresent.trace.json @@ -9,12 +9,8 @@ "File '/node_modules/js/index.ts' does not exist.", "File '/node_modules/js/index.tsx' does not exist.", "File '/node_modules/js/index.d.ts' does not exist.", - "File '/node_modules/@types/js.ts' does not exist.", - "File '/node_modules/@types/js.tsx' does not exist.", "File '/node_modules/@types/js.d.ts' does not exist.", "File '/node_modules/@types/js/package.json' does not exist.", - "File '/node_modules/@types/js/index.ts' does not exist.", - "File '/node_modules/@types/js/index.tsx' does not exist.", "File '/node_modules/@types/js/index.d.ts' does not exist.", "Loading module 'js' from 'node_modules' folder.", "File '/node_modules/js.js' does not exist.", diff --git a/tests/baselines/reference/objectRest.js b/tests/baselines/reference/objectRest.js new file mode 100644 index 00000000000..a295ff7b9f1 --- /dev/null +++ b/tests/baselines/reference/objectRest.js @@ -0,0 +1,67 @@ +//// [objectRest.ts] +let o = { a: 1, b: 'no' } +var { ...clone } = o; +var { a, ...justB } = o; +var { a, b: renamed, ...empty } = o; +var { ['b']: renamed, ...justA } = o; +var { 'b': renamed, ...justA } = o; +var { b: { '0': n, '1': oooo }, ...justA } = o; + +let o2 = { c: 'terrible idea?', d: 'yes' }; +var { d: renamed, ...d } = o2; + +let nestedrest: { x: number, n1: { y: number, n2: { z: number, n3: { n4: number } } }, rest: number, restrest: number }; +var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest; + +let complex: { x: { ka, ki }, y: number }; +var { x: { ka, ...nested }, y: other, ...rest } = complex; +({x: { ka, ...nested }, y: other, ...rest} = complex); +var { x, ...fresh } = { x: 1, y: 2 }; +({ x, ...fresh } = { x: 1, y: 2 }); + +class Removable { + private x: number; + protected y: number; + set z(value: number) { } + get both(): number { return 12 } + set both(value: number) { } + m() { } + removed: string; + remainder: string; +} +var removable = new Removable(); +var { removed, ...removableRest } = removable; + + +//// [objectRest.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p)) + t[p] = s[p]; + return t; +}; +let o = { a: 1, b: 'no' }; +var clone = __rest(o, []); +var { a } = o, justB = __rest(o, ["a"]); +var { a, b: renamed } = o, empty = __rest(o, ["a", "b"]); +var { ['b']: renamed } = o, justA = __rest(o, ["b"]); +var { 'b': renamed } = o, justA = __rest(o, ["b"]); +var { b: { '0': n, '1': oooo } } = o, justA = __rest(o, ["b"]); +let o2 = { c: 'terrible idea?', d: 'yes' }; +var { d: renamed } = o2, d = __rest(o2, ["d"]); +let nestedrest; +var { x } = nestedrest, _a = nestedrest.n1, { y } = _a, _b = _a.n2, { z } = _b, nr = __rest(_b.n3, []), restrest = __rest(nestedrest, ["x", "n1"]); +let complex; +var _c = complex.x, { ka } = _c, nested = __rest(_c, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"]); +(_d = complex.x, { ka } = _d, nested = __rest(_d, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"]), complex); +var _e = { x: 1, y: 2 }, { x } = _e, fresh = __rest(_e, ["x"]); +(_f = { x: 1, y: 2 }, { x } = _f, fresh = __rest(_f, ["x"]), _f); +class Removable { + set z(value) { } + get both() { return 12; } + set both(value) { } + m() { } +} +var removable = new Removable(); +var { removed } = removable, removableRest = __rest(removable, ["removed"]); +var _d, _f; diff --git a/tests/baselines/reference/objectRest.symbols b/tests/baselines/reference/objectRest.symbols new file mode 100644 index 00000000000..427656248ee --- /dev/null +++ b/tests/baselines/reference/objectRest.symbols @@ -0,0 +1,146 @@ +=== tests/cases/conformance/types/rest/objectRest.ts === +let o = { a: 1, b: 'no' } +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) +>a : Symbol(a, Decl(objectRest.ts, 0, 9)) +>b : Symbol(b, Decl(objectRest.ts, 0, 15)) + +var { ...clone } = o; +>clone : Symbol(clone, Decl(objectRest.ts, 1, 5)) +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) + +var { a, ...justB } = o; +>a : Symbol(a, Decl(objectRest.ts, 2, 5), Decl(objectRest.ts, 3, 5)) +>justB : Symbol(justB, Decl(objectRest.ts, 2, 8)) +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) + +var { a, b: renamed, ...empty } = o; +>a : Symbol(a, Decl(objectRest.ts, 2, 5), Decl(objectRest.ts, 3, 5)) +>b : Symbol(b, Decl(objectRest.ts, 0, 15)) +>renamed : Symbol(renamed, Decl(objectRest.ts, 3, 8), Decl(objectRest.ts, 4, 5), Decl(objectRest.ts, 5, 5), Decl(objectRest.ts, 9, 5)) +>empty : Symbol(empty, Decl(objectRest.ts, 3, 20)) +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) + +var { ['b']: renamed, ...justA } = o; +>'b' : Symbol(renamed, Decl(objectRest.ts, 3, 8), Decl(objectRest.ts, 4, 5), Decl(objectRest.ts, 5, 5), Decl(objectRest.ts, 9, 5)) +>renamed : Symbol(renamed, Decl(objectRest.ts, 3, 8), Decl(objectRest.ts, 4, 5), Decl(objectRest.ts, 5, 5), Decl(objectRest.ts, 9, 5)) +>justA : Symbol(justA, Decl(objectRest.ts, 4, 21), Decl(objectRest.ts, 5, 19), Decl(objectRest.ts, 6, 31)) +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) + +var { 'b': renamed, ...justA } = o; +>renamed : Symbol(renamed, Decl(objectRest.ts, 3, 8), Decl(objectRest.ts, 4, 5), Decl(objectRest.ts, 5, 5), Decl(objectRest.ts, 9, 5)) +>justA : Symbol(justA, Decl(objectRest.ts, 4, 21), Decl(objectRest.ts, 5, 19), Decl(objectRest.ts, 6, 31)) +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) + +var { b: { '0': n, '1': oooo }, ...justA } = o; +>b : Symbol(b, Decl(objectRest.ts, 0, 15)) +>n : Symbol(n, Decl(objectRest.ts, 6, 10)) +>oooo : Symbol(oooo, Decl(objectRest.ts, 6, 18)) +>justA : Symbol(justA, Decl(objectRest.ts, 4, 21), Decl(objectRest.ts, 5, 19), Decl(objectRest.ts, 6, 31)) +>o : Symbol(o, Decl(objectRest.ts, 0, 3)) + +let o2 = { c: 'terrible idea?', d: 'yes' }; +>o2 : Symbol(o2, Decl(objectRest.ts, 8, 3)) +>c : Symbol(c, Decl(objectRest.ts, 8, 10)) +>d : Symbol(d, Decl(objectRest.ts, 8, 31)) + +var { d: renamed, ...d } = o2; +>d : Symbol(d, Decl(objectRest.ts, 8, 31)) +>renamed : Symbol(renamed, Decl(objectRest.ts, 3, 8), Decl(objectRest.ts, 4, 5), Decl(objectRest.ts, 5, 5), Decl(objectRest.ts, 9, 5)) +>d : Symbol(d, Decl(objectRest.ts, 9, 17)) +>o2 : Symbol(o2, Decl(objectRest.ts, 8, 3)) + +let nestedrest: { x: number, n1: { y: number, n2: { z: number, n3: { n4: number } } }, rest: number, restrest: number }; +>nestedrest : Symbol(nestedrest, Decl(objectRest.ts, 11, 3)) +>x : Symbol(x, Decl(objectRest.ts, 11, 17)) +>n1 : Symbol(n1, Decl(objectRest.ts, 11, 28)) +>y : Symbol(y, Decl(objectRest.ts, 11, 34)) +>n2 : Symbol(n2, Decl(objectRest.ts, 11, 45)) +>z : Symbol(z, Decl(objectRest.ts, 11, 51)) +>n3 : Symbol(n3, Decl(objectRest.ts, 11, 62)) +>n4 : Symbol(n4, Decl(objectRest.ts, 11, 68)) +>rest : Symbol(rest, Decl(objectRest.ts, 11, 86)) +>restrest : Symbol(restrest, Decl(objectRest.ts, 11, 100)) + +var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest; +>x : Symbol(x, Decl(objectRest.ts, 12, 5), Decl(objectRest.ts, 17, 5)) +>n1 : Symbol(n1, Decl(objectRest.ts, 11, 28)) +>y : Symbol(y, Decl(objectRest.ts, 12, 14)) +>n2 : Symbol(n2, Decl(objectRest.ts, 11, 45)) +>z : Symbol(z, Decl(objectRest.ts, 12, 23)) +>n3 : Symbol(n3, Decl(objectRest.ts, 11, 62)) +>nr : Symbol(nr, Decl(objectRest.ts, 12, 32)) +>restrest : Symbol(restrest, Decl(objectRest.ts, 12, 45)) +>nestedrest : Symbol(nestedrest, Decl(objectRest.ts, 11, 3)) + +let complex: { x: { ka, ki }, y: number }; +>complex : Symbol(complex, Decl(objectRest.ts, 14, 3)) +>x : Symbol(x, Decl(objectRest.ts, 14, 14)) +>ka : Symbol(ka, Decl(objectRest.ts, 14, 19)) +>ki : Symbol(ki, Decl(objectRest.ts, 14, 23)) +>y : Symbol(y, Decl(objectRest.ts, 14, 29)) + +var { x: { ka, ...nested }, y: other, ...rest } = complex; +>x : Symbol(x, Decl(objectRest.ts, 14, 14)) +>ka : Symbol(ka, Decl(objectRest.ts, 15, 10)) +>nested : Symbol(nested, Decl(objectRest.ts, 15, 14)) +>y : Symbol(y, Decl(objectRest.ts, 14, 29)) +>other : Symbol(other, Decl(objectRest.ts, 15, 27)) +>rest : Symbol(rest, Decl(objectRest.ts, 15, 37)) +>complex : Symbol(complex, Decl(objectRest.ts, 14, 3)) + +({x: { ka, ...nested }, y: other, ...rest} = complex); +>x : Symbol(x, Decl(objectRest.ts, 16, 2)) +>ka : Symbol(ka, Decl(objectRest.ts, 16, 6)) +>y : Symbol(y, Decl(objectRest.ts, 16, 23)) +>other : Symbol(other, Decl(objectRest.ts, 15, 27)) +>complex : Symbol(complex, Decl(objectRest.ts, 14, 3)) + +var { x, ...fresh } = { x: 1, y: 2 }; +>x : Symbol(x, Decl(objectRest.ts, 12, 5), Decl(objectRest.ts, 17, 5)) +>fresh : Symbol(fresh, Decl(objectRest.ts, 17, 8)) +>x : Symbol(x, Decl(objectRest.ts, 17, 23)) +>y : Symbol(y, Decl(objectRest.ts, 17, 29)) + +({ x, ...fresh } = { x: 1, y: 2 }); +>x : Symbol(x, Decl(objectRest.ts, 18, 2)) +>x : Symbol(x, Decl(objectRest.ts, 18, 20)) +>y : Symbol(y, Decl(objectRest.ts, 18, 26)) + +class Removable { +>Removable : Symbol(Removable, Decl(objectRest.ts, 18, 35)) + + private x: number; +>x : Symbol(Removable.x, Decl(objectRest.ts, 20, 17)) + + protected y: number; +>y : Symbol(Removable.y, Decl(objectRest.ts, 21, 22)) + + set z(value: number) { } +>z : Symbol(Removable.z, Decl(objectRest.ts, 22, 24)) +>value : Symbol(value, Decl(objectRest.ts, 23, 10)) + + get both(): number { return 12 } +>both : Symbol(Removable.both, Decl(objectRest.ts, 23, 28), Decl(objectRest.ts, 24, 36)) + + set both(value: number) { } +>both : Symbol(Removable.both, Decl(objectRest.ts, 23, 28), Decl(objectRest.ts, 24, 36)) +>value : Symbol(value, Decl(objectRest.ts, 25, 13)) + + m() { } +>m : Symbol(Removable.m, Decl(objectRest.ts, 25, 31)) + + removed: string; +>removed : Symbol(Removable.removed, Decl(objectRest.ts, 26, 11)) + + remainder: string; +>remainder : Symbol(Removable.remainder, Decl(objectRest.ts, 27, 20)) +} +var removable = new Removable(); +>removable : Symbol(removable, Decl(objectRest.ts, 30, 3)) +>Removable : Symbol(Removable, Decl(objectRest.ts, 18, 35)) + +var { removed, ...removableRest } = removable; +>removed : Symbol(removed, Decl(objectRest.ts, 31, 5)) +>removableRest : Symbol(removableRest, Decl(objectRest.ts, 31, 14)) +>removable : Symbol(removable, Decl(objectRest.ts, 30, 3)) + diff --git a/tests/baselines/reference/objectRest.types b/tests/baselines/reference/objectRest.types new file mode 100644 index 00000000000..95e378359c8 --- /dev/null +++ b/tests/baselines/reference/objectRest.types @@ -0,0 +1,170 @@ +=== tests/cases/conformance/types/rest/objectRest.ts === +let o = { a: 1, b: 'no' } +>o : { a: number; b: string; } +>{ a: 1, b: 'no' } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>'no' : "no" + +var { ...clone } = o; +>clone : { a: number; b: string; } +>o : { a: number; b: string; } + +var { a, ...justB } = o; +>a : number +>justB : { b: string; } +>o : { a: number; b: string; } + +var { a, b: renamed, ...empty } = o; +>a : number +>b : any +>renamed : string +>empty : {} +>o : { a: number; b: string; } + +var { ['b']: renamed, ...justA } = o; +>'b' : "b" +>renamed : string +>justA : { a: number; } +>o : { a: number; b: string; } + +var { 'b': renamed, ...justA } = o; +>renamed : string +>justA : { a: number; } +>o : { a: number; b: string; } + +var { b: { '0': n, '1': oooo }, ...justA } = o; +>b : any +>n : string +>oooo : string +>justA : { a: number; } +>o : { a: number; b: string; } + +let o2 = { c: 'terrible idea?', d: 'yes' }; +>o2 : { c: string; d: string; } +>{ c: 'terrible idea?', d: 'yes' } : { c: string; d: string; } +>c : string +>'terrible idea?' : "terrible idea?" +>d : string +>'yes' : "yes" + +var { d: renamed, ...d } = o2; +>d : any +>renamed : string +>d : { c: string; } +>o2 : { c: string; d: string; } + +let nestedrest: { x: number, n1: { y: number, n2: { z: number, n3: { n4: number } } }, rest: number, restrest: number }; +>nestedrest : { x: number; n1: { y: number; n2: { z: number; n3: { n4: number; }; }; }; rest: number; restrest: number; } +>x : number +>n1 : { y: number; n2: { z: number; n3: { n4: number; }; }; } +>y : number +>n2 : { z: number; n3: { n4: number; }; } +>z : number +>n3 : { n4: number; } +>n4 : number +>rest : number +>restrest : number + +var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest; +>x : number +>n1 : any +>y : number +>n2 : any +>z : number +>n3 : any +>nr : { n4: number; } +>restrest : { rest: number; restrest: number; } +>nestedrest : { x: number; n1: { y: number; n2: { z: number; n3: { n4: number; }; }; }; rest: number; restrest: number; } + +let complex: { x: { ka, ki }, y: number }; +>complex : { x: { ka: any; ki: any; }; y: number; } +>x : { ka: any; ki: any; } +>ka : any +>ki : any +>y : number + +var { x: { ka, ...nested }, y: other, ...rest } = complex; +>x : any +>ka : any +>nested : { ki: any; } +>y : any +>other : number +>rest : {} +>complex : { x: { ka: any; ki: any; }; y: number; } + +({x: { ka, ...nested }, y: other, ...rest} = complex); +>({x: { ka, ...nested }, y: other, ...rest} = complex) : { x: { ka: any; ki: any; }; y: number; } +>{x: { ka, ...nested }, y: other, ...rest} = complex : { x: { ka: any; ki: any; }; y: number; } +>{x: { ka, ...nested }, y: other, ...rest} : { x: { ki: any; ka: any; }; y: number; } +>x : { ki: any; ka: any; } +>{ ka, ...nested } : { ki: any; ka: any; } +>ka : any +>nested : any +>y : number +>other : number +>rest : any +>complex : { x: { ka: any; ki: any; }; y: number; } + +var { x, ...fresh } = { x: 1, y: 2 }; +>x : number +>fresh : { y: number; } +>{ x: 1, y: 2 } : { x: number; y: number; } +>x : number +>1 : 1 +>y : number +>2 : 2 + +({ x, ...fresh } = { x: 1, y: 2 }); +>({ x, ...fresh } = { x: 1, y: 2 }) : { x: number; y: number; } +>{ x, ...fresh } = { x: 1, y: 2 } : { x: number; y: number; } +>{ x, ...fresh } : { y: number; x: number; } +>x : number +>fresh : any +>{ x: 1, y: 2 } : { x: number; y: number; } +>x : number +>1 : 1 +>y : number +>2 : 2 + +class Removable { +>Removable : Removable + + private x: number; +>x : number + + protected y: number; +>y : number + + set z(value: number) { } +>z : number +>value : number + + get both(): number { return 12 } +>both : number +>12 : 12 + + set both(value: number) { } +>both : number +>value : number + + m() { } +>m : () => void + + removed: string; +>removed : string + + remainder: string; +>remainder : string +} +var removable = new Removable(); +>removable : Removable +>new Removable() : Removable +>Removable : typeof Removable + +var { removed, ...removableRest } = removable; +>removed : string +>removableRest : { both: number; remainder: string; } +>removable : Removable + diff --git a/tests/baselines/reference/objectRestAssignment.js b/tests/baselines/reference/objectRestAssignment.js new file mode 100644 index 00000000000..41620d59b58 --- /dev/null +++ b/tests/baselines/reference/objectRestAssignment.js @@ -0,0 +1,35 @@ +//// [objectRestAssignment.ts] +let ka: any; +let nested: { ki }; +let other: number; +let rest: { }; +let complex: { x: { ka, ki }, y: number }; +({x: { ka, ...nested }, y: other, ...rest} = complex); + +// should be: +let overEmit: { a: { ka: string, x: string }[], b: { z: string, ki: string, ku: string }, ke: string, ko: string }; + +// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; +({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); + + +//// [objectRestAssignment.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p)) + t[p] = s[p]; + return t; +}; +let ka; +let nested; +let other; +let rest; +let complex; +(_a = complex.x, { ka } = _a, nested = __rest(_a, ["ka"]), { y: other } = complex, rest = __rest(complex, ["x", "y"]), complex); +// should be: +let overEmit; +// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +var _b = overEmit.a, [_c, ...y] = _b, nested2 = __rest(_c, []), _d = overEmit.b, { z } = _d, c = __rest(_d, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +(_e = overEmit.a, [_f, ...y] = _e, nested2 = __rest(_f, []), _g = overEmit.b, { z } = _g, c = __rest(_g, ["z"]), rest2 = __rest(overEmit, ["a", "b"]), overEmit); +var _a, _e, _f, _g; diff --git a/tests/baselines/reference/objectRestAssignment.symbols b/tests/baselines/reference/objectRestAssignment.symbols new file mode 100644 index 00000000000..4cb27e6e7ec --- /dev/null +++ b/tests/baselines/reference/objectRestAssignment.symbols @@ -0,0 +1,59 @@ +=== tests/cases/conformance/types/rest/objectRestAssignment.ts === +let ka: any; +>ka : Symbol(ka, Decl(objectRestAssignment.ts, 0, 3)) + +let nested: { ki }; +>nested : Symbol(nested, Decl(objectRestAssignment.ts, 1, 3)) +>ki : Symbol(ki, Decl(objectRestAssignment.ts, 1, 13)) + +let other: number; +>other : Symbol(other, Decl(objectRestAssignment.ts, 2, 3)) + +let rest: { }; +>rest : Symbol(rest, Decl(objectRestAssignment.ts, 3, 3)) + +let complex: { x: { ka, ki }, y: number }; +>complex : Symbol(complex, Decl(objectRestAssignment.ts, 4, 3)) +>x : Symbol(x, Decl(objectRestAssignment.ts, 4, 14)) +>ka : Symbol(ka, Decl(objectRestAssignment.ts, 4, 19)) +>ki : Symbol(ki, Decl(objectRestAssignment.ts, 4, 23)) +>y : Symbol(y, Decl(objectRestAssignment.ts, 4, 29)) + +({x: { ka, ...nested }, y: other, ...rest} = complex); +>x : Symbol(x, Decl(objectRestAssignment.ts, 5, 2)) +>ka : Symbol(ka, Decl(objectRestAssignment.ts, 5, 6)) +>y : Symbol(y, Decl(objectRestAssignment.ts, 5, 23)) +>other : Symbol(other, Decl(objectRestAssignment.ts, 2, 3)) +>complex : Symbol(complex, Decl(objectRestAssignment.ts, 4, 3)) + +// should be: +let overEmit: { a: { ka: string, x: string }[], b: { z: string, ki: string, ku: string }, ke: string, ko: string }; +>overEmit : Symbol(overEmit, Decl(objectRestAssignment.ts, 8, 3)) +>a : Symbol(a, Decl(objectRestAssignment.ts, 8, 15)) +>ka : Symbol(ka, Decl(objectRestAssignment.ts, 8, 20)) +>x : Symbol(x, Decl(objectRestAssignment.ts, 8, 32)) +>b : Symbol(b, Decl(objectRestAssignment.ts, 8, 47)) +>z : Symbol(z, Decl(objectRestAssignment.ts, 8, 52)) +>ki : Symbol(ki, Decl(objectRestAssignment.ts, 8, 63)) +>ku : Symbol(ku, Decl(objectRestAssignment.ts, 8, 75)) +>ke : Symbol(ke, Decl(objectRestAssignment.ts, 8, 89)) +>ko : Symbol(ko, Decl(objectRestAssignment.ts, 8, 101)) + +// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; +>a : Symbol(a, Decl(objectRestAssignment.ts, 8, 15)) +>nested2 : Symbol(nested2, Decl(objectRestAssignment.ts, 11, 11)) +>y : Symbol(y, Decl(objectRestAssignment.ts, 11, 25)) +>b : Symbol(b, Decl(objectRestAssignment.ts, 8, 47)) +>z : Symbol(z, Decl(objectRestAssignment.ts, 11, 37)) +>c : Symbol(c, Decl(objectRestAssignment.ts, 11, 40)) +>rest2 : Symbol(rest2, Decl(objectRestAssignment.ts, 11, 48)) +>overEmit : Symbol(overEmit, Decl(objectRestAssignment.ts, 8, 3)) + +({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); +>a : Symbol(a, Decl(objectRestAssignment.ts, 12, 2)) +>y : Symbol(y, Decl(objectRestAssignment.ts, 11, 25)) +>b : Symbol(b, Decl(objectRestAssignment.ts, 12, 29)) +>z : Symbol(z, Decl(objectRestAssignment.ts, 12, 34)) +>overEmit : Symbol(overEmit, Decl(objectRestAssignment.ts, 8, 3)) + diff --git a/tests/baselines/reference/objectRestAssignment.types b/tests/baselines/reference/objectRestAssignment.types new file mode 100644 index 00000000000..38aa00ce61d --- /dev/null +++ b/tests/baselines/reference/objectRestAssignment.types @@ -0,0 +1,75 @@ +=== tests/cases/conformance/types/rest/objectRestAssignment.ts === +let ka: any; +>ka : any + +let nested: { ki }; +>nested : { ki: any; } +>ki : any + +let other: number; +>other : number + +let rest: { }; +>rest : {} + +let complex: { x: { ka, ki }, y: number }; +>complex : { x: { ka: any; ki: any; }; y: number; } +>x : { ka: any; ki: any; } +>ka : any +>ki : any +>y : number + +({x: { ka, ...nested }, y: other, ...rest} = complex); +>({x: { ka, ...nested }, y: other, ...rest} = complex) : { x: { ka: any; ki: any; }; y: number; } +>{x: { ka, ...nested }, y: other, ...rest} = complex : { x: { ka: any; ki: any; }; y: number; } +>{x: { ka, ...nested }, y: other, ...rest} : { x: { ki: any; ka: any; }; y: number; } +>x : { ki: any; ka: any; } +>{ ka, ...nested } : { ki: any; ka: any; } +>ka : any +>nested : any +>y : number +>other : number +>rest : any +>complex : { x: { ka: any; ki: any; }; y: number; } + +// should be: +let overEmit: { a: { ka: string, x: string }[], b: { z: string, ki: string, ku: string }, ke: string, ko: string }; +>overEmit : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } +>a : { ka: string; x: string; }[] +>ka : string +>x : string +>b : { z: string; ki: string; ku: string; } +>z : string +>ki : string +>ku : string +>ke : string +>ko : string + +// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; +>a : any +>nested2 : { ka: string; x: string; } +>y : { ka: string; x: string; }[] +>b : any +>z : string +>c : { ki: string; ku: string; } +>rest2 : { ke: string; ko: string; } +>overEmit : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } + +({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); +>({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit) : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } +>{ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } +>{ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } : { ke: string; ko: string; a: { ka: string; x: string; }[]; b: { ki: string; ku: string; z: string; }; } +>a : { ka: string; x: string; }[] +>[{ ...nested2 }, ...y] : { ka: string; x: string; }[] +>{ ...nested2 } : { ka: string; x: string; } +>nested2 : any +>...y : { ka: string; x: string; } +>y : { ka: string; x: string; }[] +>b : { ki: string; ku: string; z: string; } +>{ z, ...c } : { ki: string; ku: string; z: string; } +>z : string +>c : any +>rest2 : any +>overEmit : { a: { ka: string; x: string; }[]; b: { z: string; ki: string; ku: string; }; ke: string; ko: string; } + diff --git a/tests/baselines/reference/objectRestForOf.js b/tests/baselines/reference/objectRestForOf.js new file mode 100644 index 00000000000..26ebd8f8229 --- /dev/null +++ b/tests/baselines/reference/objectRestForOf.js @@ -0,0 +1,45 @@ +//// [objectRestForOf.ts] +let array: { x: number, y: string }[]; +for (let { x, ...restOf } of array) { + [x, restOf]; +} +let xx: number; +let rrestOff: { y: string }; +for ({ x: xx, ...rrestOff } of array ) { + [xx, rrestOff]; +} +for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { + [norest.x, norest.y]; + // x is now a string. who knows why. +} + + +//// [objectRestForOf.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p)) + t[p] = s[p]; + return t; +}; +let array; +for (var array_1 of array) { + var { x } = array_1, restOf = __rest(array_1, ["x"]); + [x, restOf]; +} +let xx; +let rrestOff; +for (var array_2 of array) { + ({ x: xx } = array_2, rrestOff = __rest(array_2, ["x"])); + [xx, rrestOff]; +} +for (const norest of array.map(a => (__assign({}, a, { x: 'a string' })))) { + [norest.x, norest.y]; +} diff --git a/tests/baselines/reference/objectRestForOf.symbols b/tests/baselines/reference/objectRestForOf.symbols new file mode 100644 index 00000000000..ec0ccde740d --- /dev/null +++ b/tests/baselines/reference/objectRestForOf.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/types/rest/objectRestForOf.ts === +let array: { x: number, y: string }[]; +>array : Symbol(array, Decl(objectRestForOf.ts, 0, 3)) +>x : Symbol(x, Decl(objectRestForOf.ts, 0, 12)) +>y : Symbol(y, Decl(objectRestForOf.ts, 0, 23)) + +for (let { x, ...restOf } of array) { +>x : Symbol(x, Decl(objectRestForOf.ts, 1, 10)) +>restOf : Symbol(restOf, Decl(objectRestForOf.ts, 1, 13)) +>array : Symbol(array, Decl(objectRestForOf.ts, 0, 3)) + + [x, restOf]; +>x : Symbol(x, Decl(objectRestForOf.ts, 1, 10)) +>restOf : Symbol(restOf, Decl(objectRestForOf.ts, 1, 13)) +} +let xx: number; +>xx : Symbol(xx, Decl(objectRestForOf.ts, 4, 3)) + +let rrestOff: { y: string }; +>rrestOff : Symbol(rrestOff, Decl(objectRestForOf.ts, 5, 3)) +>y : Symbol(y, Decl(objectRestForOf.ts, 5, 15)) + +for ({ x: xx, ...rrestOff } of array ) { +>x : Symbol(x, Decl(objectRestForOf.ts, 6, 6)) +>xx : Symbol(xx, Decl(objectRestForOf.ts, 4, 3)) +>array : Symbol(array, Decl(objectRestForOf.ts, 0, 3)) + + [xx, rrestOff]; +>xx : Symbol(xx, Decl(objectRestForOf.ts, 4, 3)) +>rrestOff : Symbol(rrestOff, Decl(objectRestForOf.ts, 5, 3)) +} +for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { +>norest : Symbol(norest, Decl(objectRestForOf.ts, 9, 10)) +>array.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>array : Symbol(array, Decl(objectRestForOf.ts, 0, 3)) +>map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(objectRestForOf.ts, 9, 31)) +>x : Symbol(x, Decl(objectRestForOf.ts, 9, 44)) + + [norest.x, norest.y]; +>norest.x : Symbol(x, Decl(objectRestForOf.ts, 9, 44)) +>norest : Symbol(norest, Decl(objectRestForOf.ts, 9, 10)) +>x : Symbol(x, Decl(objectRestForOf.ts, 9, 44)) +>norest.y : Symbol(y, Decl(objectRestForOf.ts, 0, 23)) +>norest : Symbol(norest, Decl(objectRestForOf.ts, 9, 10)) +>y : Symbol(y, Decl(objectRestForOf.ts, 0, 23)) + + // x is now a string. who knows why. +} + diff --git a/tests/baselines/reference/objectRestForOf.types b/tests/baselines/reference/objectRestForOf.types new file mode 100644 index 00000000000..e8c3b4a82ab --- /dev/null +++ b/tests/baselines/reference/objectRestForOf.types @@ -0,0 +1,61 @@ +=== tests/cases/conformance/types/rest/objectRestForOf.ts === +let array: { x: number, y: string }[]; +>array : { x: number; y: string; }[] +>x : number +>y : string + +for (let { x, ...restOf } of array) { +>x : number +>restOf : { y: string; } +>array : { x: number; y: string; }[] + + [x, restOf]; +>[x, restOf] : (number | { y: string; })[] +>x : number +>restOf : { y: string; } +} +let xx: number; +>xx : number + +let rrestOff: { y: string }; +>rrestOff : { y: string; } +>y : string + +for ({ x: xx, ...rrestOff } of array ) { +>{ x: xx, ...rrestOff } : { y: string; x: number; } +>x : { x: number; y: string; } +>xx : number +>rrestOff : any +>array : { x: number; y: string; }[] + + [xx, rrestOff]; +>[xx, rrestOff] : (number | { y: string; })[] +>xx : number +>rrestOff : { y: string; } +} +for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { +>norest : { x: string; y: string; } +>array.map(a => ({ ...a, x: 'a string' })) : { x: string; y: string; }[] +>array.map : { (this: [{ x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [{ x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U, U, U]; (this: [{ x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U, U]; (this: [{ x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): U[]; } +>array : { x: number; y: string; }[] +>map : { (this: [{ x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U, U, U, U]; (this: [{ x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U, U, U]; (this: [{ x: number; y: string; }, { x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U, U]; (this: [{ x: number; y: string; }, { x: number; y: string; }], callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): [U, U]; (callbackfn: (value: { x: number; y: string; }, index: number, array: { x: number; y: string; }[]) => U, thisArg?: any): U[]; } +>a => ({ ...a, x: 'a string' }) : (a: { x: number; y: string; }) => { x: string; y: string; } +>a : { x: number; y: string; } +>({ ...a, x: 'a string' }) : { x: string; y: string; } +>{ ...a, x: 'a string' } : { x: string; y: string; } +>a : any +>x : string +>'a string' : "a string" + + [norest.x, norest.y]; +>[norest.x, norest.y] : string[] +>norest.x : string +>norest : { x: string; y: string; } +>x : string +>norest.y : string +>norest : { x: string; y: string; } +>y : string + + // x is now a string. who knows why. +} + diff --git a/tests/baselines/reference/objectRestNegative.errors.txt b/tests/baselines/reference/objectRestNegative.errors.txt new file mode 100644 index 00000000000..b8144e3209b --- /dev/null +++ b/tests/baselines/reference/objectRestNegative.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/rest/objectRestNegative.ts(2,10): error TS2462: A rest element must be last in a destructuring pattern +tests/cases/conformance/types/rest/objectRestNegative.ts(3,31): error TS2462: A rest element must be last in a destructuring pattern +tests/cases/conformance/types/rest/objectRestNegative.ts(6,17): error TS2700: Rest types may only be created from object types. +tests/cases/conformance/types/rest/objectRestNegative.ts(11,9): error TS2701: An object rest element must be an identifier. + + +==== tests/cases/conformance/types/rest/objectRestNegative.ts (4 errors) ==== + let o = { a: 1, b: 'no' }; + var { ...mustBeLast, a } = o; + ~~~~~~~~~~ +!!! error TS2462: A rest element must be last in a destructuring pattern + function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void { + ~~~~~~~~~~ +!!! error TS2462: A rest element must be last in a destructuring pattern + } + function generic(t: T) { + let { x, ...rest } = t; + ~~~~ +!!! error TS2700: Rest types may only be created from object types. + return rest; + } + + let rest: { b: string } + ({a, ...rest.b + rest.b} = o); + ~~~~~~~~~~~~~~~ +!!! error TS2701: An object rest element must be an identifier. + \ No newline at end of file diff --git a/tests/baselines/reference/objectRestNegative.js b/tests/baselines/reference/objectRestNegative.js new file mode 100644 index 00000000000..8692850dbdd --- /dev/null +++ b/tests/baselines/reference/objectRestNegative.js @@ -0,0 +1,32 @@ +//// [objectRestNegative.ts] +let o = { a: 1, b: 'no' }; +var { ...mustBeLast, a } = o; +function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void { +} +function generic(t: T) { + let { x, ...rest } = t; + return rest; +} + +let rest: { b: string } +({a, ...rest.b + rest.b} = o); + + +//// [objectRestNegative.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p)) + t[p] = s[p]; + return t; +}; +var o = { a: 1, b: 'no' }; +var mustBeLast = o.mustBeLast, a = o.a; +function stillMustBeLast(_a) { + var mustBeLast = _a.mustBeLast, a = _a.a; +} +function generic(t) { + var x = t.x, rest = __rest(t, ["x"]); + return rest; +} +var rest; +(a = o.a, o, o); diff --git a/tests/baselines/reference/objectRestParameter.js b/tests/baselines/reference/objectRestParameter.js new file mode 100644 index 00000000000..49434f24eec --- /dev/null +++ b/tests/baselines/reference/objectRestParameter.js @@ -0,0 +1,28 @@ +//// [objectRestParameter.ts] +function cloneAgain({ a, ...clone }: { a: number, b: string }): void { +} + +declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void); +suddenly(({ x: a, ...rest }) => rest.y); +suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); + + + +//// [objectRestParameter.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p)) + t[p] = s[p]; + return t; +}; +function cloneAgain(_a) { + var { a } = _a, clone = __rest(_a, ["a"]); +} +suddenly((_a) => { + var { x: a } = _a, rest = __rest(_a, ["x"]); + return rest.y; +}); +suddenly((_a = { x: { z: 1, ka: 1 }, y: 'noo' }) => { + var _b = _a.x, { z = 12 } = _b, nested = __rest(_b, ["z"]), rest = __rest(_a, ["x"]); + return rest.y + nested.ka; +}); diff --git a/tests/baselines/reference/objectRestParameter.symbols b/tests/baselines/reference/objectRestParameter.symbols new file mode 100644 index 00000000000..9569dc53d3a --- /dev/null +++ b/tests/baselines/reference/objectRestParameter.symbols @@ -0,0 +1,45 @@ +=== tests/cases/conformance/types/rest/objectRestParameter.ts === +function cloneAgain({ a, ...clone }: { a: number, b: string }): void { +>cloneAgain : Symbol(cloneAgain, Decl(objectRestParameter.ts, 0, 0)) +>a : Symbol(a, Decl(objectRestParameter.ts, 0, 21)) +>clone : Symbol(clone, Decl(objectRestParameter.ts, 0, 24)) +>a : Symbol(a, Decl(objectRestParameter.ts, 0, 38)) +>b : Symbol(b, Decl(objectRestParameter.ts, 0, 49)) +} + +declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void); +>suddenly : Symbol(suddenly, Decl(objectRestParameter.ts, 1, 1)) +>f : Symbol(f, Decl(objectRestParameter.ts, 3, 26)) +>a : Symbol(a, Decl(objectRestParameter.ts, 3, 30)) +>x : Symbol(x, Decl(objectRestParameter.ts, 3, 34)) +>z : Symbol(z, Decl(objectRestParameter.ts, 3, 39)) +>ka : Symbol(ka, Decl(objectRestParameter.ts, 3, 42)) +>y : Symbol(y, Decl(objectRestParameter.ts, 3, 48)) + +suddenly(({ x: a, ...rest }) => rest.y); +>suddenly : Symbol(suddenly, Decl(objectRestParameter.ts, 1, 1)) +>x : Symbol(x, Decl(objectRestParameter.ts, 3, 34)) +>a : Symbol(a, Decl(objectRestParameter.ts, 4, 11)) +>rest : Symbol(rest, Decl(objectRestParameter.ts, 4, 17)) +>rest.y : Symbol(y, Decl(objectRestParameter.ts, 3, 48)) +>rest : Symbol(rest, Decl(objectRestParameter.ts, 4, 17)) +>y : Symbol(y, Decl(objectRestParameter.ts, 3, 48)) + +suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); +>suddenly : Symbol(suddenly, Decl(objectRestParameter.ts, 1, 1)) +>x : Symbol(x, Decl(objectRestParameter.ts, 3, 34)) +>z : Symbol(z, Decl(objectRestParameter.ts, 5, 16)) +>nested : Symbol(nested, Decl(objectRestParameter.ts, 5, 24)) +>rest : Symbol(rest, Decl(objectRestParameter.ts, 5, 37)) +>x : Symbol(x, Decl(objectRestParameter.ts, 5, 51)) +>z : Symbol(z, Decl(objectRestParameter.ts, 5, 56)) +>ka : Symbol(ka, Decl(objectRestParameter.ts, 5, 62)) +>y : Symbol(y, Decl(objectRestParameter.ts, 5, 71)) +>rest.y : Symbol(y, Decl(objectRestParameter.ts, 3, 48)) +>rest : Symbol(rest, Decl(objectRestParameter.ts, 5, 37)) +>y : Symbol(y, Decl(objectRestParameter.ts, 3, 48)) +>nested.ka : Symbol(ka, Decl(objectRestParameter.ts, 3, 42)) +>nested : Symbol(nested, Decl(objectRestParameter.ts, 5, 24)) +>ka : Symbol(ka, Decl(objectRestParameter.ts, 3, 42)) + + diff --git a/tests/baselines/reference/objectRestParameter.types b/tests/baselines/reference/objectRestParameter.types new file mode 100644 index 00000000000..c634c9c5cd5 --- /dev/null +++ b/tests/baselines/reference/objectRestParameter.types @@ -0,0 +1,56 @@ +=== tests/cases/conformance/types/rest/objectRestParameter.ts === +function cloneAgain({ a, ...clone }: { a: number, b: string }): void { +>cloneAgain : ({a, ...clone}: { a: number; b: string; }) => void +>a : number +>clone : { b: string; } +>a : number +>b : string +} + +declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void); +>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any +>f : (a: { x: { z: any; ka: any; }; y: string; }) => void +>a : { x: { z: any; ka: any; }; y: string; } +>x : { z: any; ka: any; } +>z : any +>ka : any +>y : string + +suddenly(({ x: a, ...rest }) => rest.y); +>suddenly(({ x: a, ...rest }) => rest.y) : any +>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any +>({ x: a, ...rest }) => rest.y : ({x: a, ...rest}: { x: { z: any; ka: any; }; y: string; }) => string +>x : any +>a : { z: any; ka: any; } +>rest : { y: string; } +>rest.y : string +>rest : { y: string; } +>y : string + +suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); +>suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka) : any +>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any +>({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka : ({x: {z, ...nested}, ...rest}?: { x: { z: any; ka: any; }; y: string; }) => string +>x : any +>z : any +>12 : 12 +>nested : { ka: any; } +>rest : { y: string; } +>{ x: { z: 1, ka: 1 }, y: 'noo' } : { x: { z: number; ka: number; }; y: string; } +>x : { z: number; ka: number; } +>{ z: 1, ka: 1 } : { z: number; ka: number; } +>z : number +>1 : 1 +>ka : number +>1 : 1 +>y : string +>'noo' : "noo" +>rest.y + nested.ka : string +>rest.y : string +>rest : { y: string; } +>y : string +>nested.ka : any +>nested : { ka: any; } +>ka : any + + diff --git a/tests/baselines/reference/objectSpread.js b/tests/baselines/reference/objectSpread.js new file mode 100644 index 00000000000..d1de48c5cab --- /dev/null +++ b/tests/baselines/reference/objectSpread.js @@ -0,0 +1,151 @@ +//// [objectSpread.ts] +let o = { a: 1, b: 'no' } +let o2 = { b: 'yes', c: true } +let swap = { a: 'yes', b: -1 }; + +let addAfter: { a: number, b: string, c: boolean } = + { ...o, c: false } +let addBefore: { a: number, b: string, c: boolean } = + { c: false, ...o } +// Note: ignore still changes the order that properties are printed +let ignore: { a: number, b: string } = + { b: 'ignored', ...o } +let override: { a: number, b: string } = + { ...o, b: 'override' } +let nested: { a: number, b: boolean, c: string } = + { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } +let combined: { a: number, b: string, c: boolean } = + { ...o, ...o2 } +let combinedBefore: { a: number, b: string, c: boolean } = + { b: 'ok', ...o, ...o2 } +let combinedMid: { a: number, b: string, c: boolean } = + { ...o, b: 'ok', ...o2 } +let combinedAfter: { a: number, b: string, c: boolean } = + { ...o, ...o2, b: 'ok' } +let combinedNested: { a: number, b: boolean, c: string, d: string } = + { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } +let combinedNestedChangeType: { a: number, b: boolean, c: number } = + { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } +let propertyNested: { a: { a: number, b: string } } = + { a: { ... o } } +// accessors don't copy the descriptor +// (which means that readonly getters become read/write properties) +let op = { get a () { return 6 } }; +let getter: { a: number, c: number } = + { ...op, c: 7 } +getter.a = 12; + +// functions result in { } +let spreadFunc = { ...(function () { }) }; + +// any results in any +let anything: any; +let spreadAny = { ...anything }; + +// methods are not enumerable +class C { p = 1; m() { } } +let c: C = new C() +let spreadC: { p: number } = { ...c } + +// own methods are enumerable +let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } }; +cplus.plus(); + +// new field's type conflicting with existing field is OK +let changeTypeAfter: { a: string, b: string } = + { ...o, a: 'wrong type?' } +let changeTypeBefore: { a: number, b: string } = + { a: 'wrong type?', ...o }; +let changeTypeBoth: { a: string, b: number } = + { ...o, ...swap }; + +// optional +let definiteBoolean: { sn: boolean }; +let definiteString: { sn: string }; +let optionalString: { sn?: string }; +let optionalNumber: { sn?: number }; +let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; +let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; +let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; + +// computed property +let computedFirst: { a: number, b: string, "before everything": number } = + { ['before everything']: 12, ...o, b: 'yes' } +let computedMiddle: { a: number, b: string, c: boolean, "in the middle": number } = + { ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } +let computedAfter: { a: number, b: string, "at the end": number } = + { ...o, b: 'yeah', ['at the end']: 14 } +// shortcut syntax +let a = 12; +let shortCutted: { a: number, b: string } = { ...o, a } + + + +//// [objectSpread.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var o = { a: 1, b: 'no' }; +var o2 = { b: 'yes', c: true }; +var swap = { a: 'yes', b: -1 }; +var addAfter = __assign({}, o, { c: false }); +var addBefore = __assign({ c: false }, o); +// Note: ignore still changes the order that properties are printed +var ignore = __assign({ b: 'ignored' }, o); +var override = __assign({}, o, { b: 'override' }); +var nested = __assign({}, __assign({ a: 3 }, { b: false, c: 'overriden' }), { c: 'whatever' }); +var combined = __assign({}, o, o2); +var combinedBefore = __assign({ b: 'ok' }, o, o2); +var combinedMid = __assign({}, o, { b: 'ok' }, o2); +var combinedAfter = __assign({}, o, o2, { b: 'ok' }); +var combinedNested = __assign({}, __assign({ a: 4 }, { b: false, c: 'overriden' }), { d: 'actually new' }, { a: 5, d: 'maybe new' }); +var combinedNestedChangeType = __assign({}, __assign({ a: 1 }, { b: false, c: 'overriden' }), { c: -1 }); +var propertyNested = __assign({ a: __assign({}, o) }); +// accessors don't copy the descriptor +// (which means that readonly getters become read/write properties) +var op = { get a() { return 6; } }; +var getter = __assign({}, op, { c: 7 }); +getter.a = 12; +// functions result in { } +var spreadFunc = __assign({}, (function () { })); +// any results in any +var anything; +var spreadAny = __assign({}, anything); +// methods are not enumerable +var C = (function () { + function C() { + this.p = 1; + } + C.prototype.m = function () { }; + return C; +}()); +var c = new C(); +var spreadC = __assign({}, c); +// own methods are enumerable +var cplus = __assign({}, c, { plus: function () { return this.p + 1; } }); +cplus.plus(); +// new field's type conflicting with existing field is OK +var changeTypeAfter = __assign({}, o, { a: 'wrong type?' }); +var changeTypeBefore = __assign({ a: 'wrong type?' }, o); +var changeTypeBoth = __assign({}, o, swap); +// optional +var definiteBoolean; +var definiteString; +var optionalString; +var optionalNumber; +var optionalUnionStops = __assign({}, definiteBoolean, definiteString, optionalNumber); +var optionalUnionDuplicates = __assign({}, definiteBoolean, definiteString, optionalString, optionalNumber); +var allOptional = __assign({}, optionalString, optionalNumber); +// computed property +var computedFirst = __assign((_a = {}, _a['before everything'] = 12, _a), o, { b: 'yes' }); +var computedMiddle = __assign({}, o, (_b = {}, _b['in the middle'] = 13, _b.b = 'maybe?', _b), o2); +var computedAfter = __assign({}, o, (_c = { b: 'yeah' }, _c['at the end'] = 14, _c)); +// shortcut syntax +var a = 12; +var shortCutted = __assign({}, o, { a: a }); +var _a, _b, _c; diff --git a/tests/baselines/reference/objectSpread.symbols b/tests/baselines/reference/objectSpread.symbols new file mode 100644 index 00000000000..9946b313f52 --- /dev/null +++ b/tests/baselines/reference/objectSpread.symbols @@ -0,0 +1,284 @@ +=== tests/cases/conformance/types/spread/objectSpread.ts === +let o = { a: 1, b: 'no' } +>o : Symbol(o, Decl(objectSpread.ts, 0, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 0, 9)) +>b : Symbol(b, Decl(objectSpread.ts, 0, 15)) + +let o2 = { b: 'yes', c: true } +>o2 : Symbol(o2, Decl(objectSpread.ts, 1, 3)) +>b : Symbol(b, Decl(objectSpread.ts, 1, 10)) +>c : Symbol(c, Decl(objectSpread.ts, 1, 20)) + +let swap = { a: 'yes', b: -1 }; +>swap : Symbol(swap, Decl(objectSpread.ts, 2, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 2, 12)) +>b : Symbol(b, Decl(objectSpread.ts, 2, 22)) + +let addAfter: { a: number, b: string, c: boolean } = +>addAfter : Symbol(addAfter, Decl(objectSpread.ts, 4, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 4, 15)) +>b : Symbol(b, Decl(objectSpread.ts, 4, 26)) +>c : Symbol(c, Decl(objectSpread.ts, 4, 37)) + + { ...o, c: false } +>c : Symbol(c, Decl(objectSpread.ts, 5, 11)) + +let addBefore: { a: number, b: string, c: boolean } = +>addBefore : Symbol(addBefore, Decl(objectSpread.ts, 6, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 6, 16)) +>b : Symbol(b, Decl(objectSpread.ts, 6, 27)) +>c : Symbol(c, Decl(objectSpread.ts, 6, 38)) + + { c: false, ...o } +>c : Symbol(c, Decl(objectSpread.ts, 7, 5)) + +// Note: ignore still changes the order that properties are printed +let ignore: { a: number, b: string } = +>ignore : Symbol(ignore, Decl(objectSpread.ts, 9, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 9, 13)) +>b : Symbol(b, Decl(objectSpread.ts, 9, 24)) + + { b: 'ignored', ...o } +>b : Symbol(b, Decl(objectSpread.ts, 10, 5)) + +let override: { a: number, b: string } = +>override : Symbol(override, Decl(objectSpread.ts, 11, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 11, 15)) +>b : Symbol(b, Decl(objectSpread.ts, 11, 26)) + + { ...o, b: 'override' } +>b : Symbol(b, Decl(objectSpread.ts, 12, 11)) + +let nested: { a: number, b: boolean, c: string } = +>nested : Symbol(nested, Decl(objectSpread.ts, 13, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 13, 13)) +>b : Symbol(b, Decl(objectSpread.ts, 13, 24)) +>c : Symbol(c, Decl(objectSpread.ts, 13, 36)) + + { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } +>a : Symbol(a, Decl(objectSpread.ts, 14, 10)) +>b : Symbol(b, Decl(objectSpread.ts, 14, 21)) +>c : Symbol(c, Decl(objectSpread.ts, 14, 31)) +>c : Symbol(c, Decl(objectSpread.ts, 14, 51)) + +let combined: { a: number, b: string, c: boolean } = +>combined : Symbol(combined, Decl(objectSpread.ts, 15, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 15, 15)) +>b : Symbol(b, Decl(objectSpread.ts, 15, 26)) +>c : Symbol(c, Decl(objectSpread.ts, 15, 37)) + + { ...o, ...o2 } +let combinedBefore: { a: number, b: string, c: boolean } = +>combinedBefore : Symbol(combinedBefore, Decl(objectSpread.ts, 17, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 17, 21)) +>b : Symbol(b, Decl(objectSpread.ts, 17, 32)) +>c : Symbol(c, Decl(objectSpread.ts, 17, 43)) + + { b: 'ok', ...o, ...o2 } +>b : Symbol(b, Decl(objectSpread.ts, 18, 5)) + +let combinedMid: { a: number, b: string, c: boolean } = +>combinedMid : Symbol(combinedMid, Decl(objectSpread.ts, 19, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 19, 18)) +>b : Symbol(b, Decl(objectSpread.ts, 19, 29)) +>c : Symbol(c, Decl(objectSpread.ts, 19, 40)) + + { ...o, b: 'ok', ...o2 } +>b : Symbol(b, Decl(objectSpread.ts, 20, 11)) + +let combinedAfter: { a: number, b: string, c: boolean } = +>combinedAfter : Symbol(combinedAfter, Decl(objectSpread.ts, 21, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 21, 20)) +>b : Symbol(b, Decl(objectSpread.ts, 21, 31)) +>c : Symbol(c, Decl(objectSpread.ts, 21, 42)) + + { ...o, ...o2, b: 'ok' } +>b : Symbol(b, Decl(objectSpread.ts, 22, 18)) + +let combinedNested: { a: number, b: boolean, c: string, d: string } = +>combinedNested : Symbol(combinedNested, Decl(objectSpread.ts, 23, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 23, 21)) +>b : Symbol(b, Decl(objectSpread.ts, 23, 32)) +>c : Symbol(c, Decl(objectSpread.ts, 23, 44)) +>d : Symbol(d, Decl(objectSpread.ts, 23, 55)) + + { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } +>a : Symbol(a, Decl(objectSpread.ts, 24, 10)) +>b : Symbol(b, Decl(objectSpread.ts, 24, 21)) +>c : Symbol(c, Decl(objectSpread.ts, 24, 31)) +>d : Symbol(d, Decl(objectSpread.ts, 24, 51)) +>a : Symbol(a, Decl(objectSpread.ts, 24, 75)) +>d : Symbol(d, Decl(objectSpread.ts, 24, 81)) + +let combinedNestedChangeType: { a: number, b: boolean, c: number } = +>combinedNestedChangeType : Symbol(combinedNestedChangeType, Decl(objectSpread.ts, 25, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 25, 31)) +>b : Symbol(b, Decl(objectSpread.ts, 25, 42)) +>c : Symbol(c, Decl(objectSpread.ts, 25, 54)) + + { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } +>a : Symbol(a, Decl(objectSpread.ts, 26, 10)) +>b : Symbol(b, Decl(objectSpread.ts, 26, 21)) +>c : Symbol(c, Decl(objectSpread.ts, 26, 31)) +>c : Symbol(c, Decl(objectSpread.ts, 26, 51)) + +let propertyNested: { a: { a: number, b: string } } = +>propertyNested : Symbol(propertyNested, Decl(objectSpread.ts, 27, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 27, 21)) +>a : Symbol(a, Decl(objectSpread.ts, 27, 26)) +>b : Symbol(b, Decl(objectSpread.ts, 27, 37)) + + { a: { ... o } } +>a : Symbol(a, Decl(objectSpread.ts, 28, 5)) + +// accessors don't copy the descriptor +// (which means that readonly getters become read/write properties) +let op = { get a () { return 6 } }; +>op : Symbol(op, Decl(objectSpread.ts, 31, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 31, 10)) + +let getter: { a: number, c: number } = +>getter : Symbol(getter, Decl(objectSpread.ts, 32, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 32, 13)) +>c : Symbol(c, Decl(objectSpread.ts, 32, 24)) + + { ...op, c: 7 } +>c : Symbol(c, Decl(objectSpread.ts, 33, 12)) + +getter.a = 12; +>getter.a : Symbol(a, Decl(objectSpread.ts, 32, 13)) +>getter : Symbol(getter, Decl(objectSpread.ts, 32, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 32, 13)) + +// functions result in { } +let spreadFunc = { ...(function () { }) }; +>spreadFunc : Symbol(spreadFunc, Decl(objectSpread.ts, 37, 3)) + +// any results in any +let anything: any; +>anything : Symbol(anything, Decl(objectSpread.ts, 40, 3)) + +let spreadAny = { ...anything }; +>spreadAny : Symbol(spreadAny, Decl(objectSpread.ts, 41, 3)) + +// methods are not enumerable +class C { p = 1; m() { } } +>C : Symbol(C, Decl(objectSpread.ts, 41, 32)) +>p : Symbol(C.p, Decl(objectSpread.ts, 44, 9)) +>m : Symbol(C.m, Decl(objectSpread.ts, 44, 16)) + +let c: C = new C() +>c : Symbol(c, Decl(objectSpread.ts, 45, 3)) +>C : Symbol(C, Decl(objectSpread.ts, 41, 32)) +>C : Symbol(C, Decl(objectSpread.ts, 41, 32)) + +let spreadC: { p: number } = { ...c } +>spreadC : Symbol(spreadC, Decl(objectSpread.ts, 46, 3)) +>p : Symbol(p, Decl(objectSpread.ts, 46, 14)) + +// own methods are enumerable +let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } }; +>cplus : Symbol(cplus, Decl(objectSpread.ts, 49, 3)) +>p : Symbol(p, Decl(objectSpread.ts, 49, 12)) +>plus : Symbol(plus, Decl(objectSpread.ts, 49, 23)) +>plus : Symbol(plus, Decl(objectSpread.ts, 49, 48)) +>this : Symbol(__object, Decl(objectSpread.ts, 41, 15)) + +cplus.plus(); +>cplus.plus : Symbol(plus, Decl(objectSpread.ts, 49, 23)) +>cplus : Symbol(cplus, Decl(objectSpread.ts, 49, 3)) +>plus : Symbol(plus, Decl(objectSpread.ts, 49, 23)) + +// new field's type conflicting with existing field is OK +let changeTypeAfter: { a: string, b: string } = +>changeTypeAfter : Symbol(changeTypeAfter, Decl(objectSpread.ts, 53, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 53, 22)) +>b : Symbol(b, Decl(objectSpread.ts, 53, 33)) + + { ...o, a: 'wrong type?' } +>a : Symbol(a, Decl(objectSpread.ts, 54, 11)) + +let changeTypeBefore: { a: number, b: string } = +>changeTypeBefore : Symbol(changeTypeBefore, Decl(objectSpread.ts, 55, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 55, 23)) +>b : Symbol(b, Decl(objectSpread.ts, 55, 34)) + + { a: 'wrong type?', ...o }; +>a : Symbol(a, Decl(objectSpread.ts, 56, 5)) + +let changeTypeBoth: { a: string, b: number } = +>changeTypeBoth : Symbol(changeTypeBoth, Decl(objectSpread.ts, 57, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 57, 21)) +>b : Symbol(b, Decl(objectSpread.ts, 57, 32)) + + { ...o, ...swap }; + +// optional +let definiteBoolean: { sn: boolean }; +>definiteBoolean : Symbol(definiteBoolean, Decl(objectSpread.ts, 61, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 61, 22)) + +let definiteString: { sn: string }; +>definiteString : Symbol(definiteString, Decl(objectSpread.ts, 62, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 62, 21)) + +let optionalString: { sn?: string }; +>optionalString : Symbol(optionalString, Decl(objectSpread.ts, 63, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 63, 21)) + +let optionalNumber: { sn?: number }; +>optionalNumber : Symbol(optionalNumber, Decl(objectSpread.ts, 64, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 64, 21)) + +let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; +>optionalUnionStops : Symbol(optionalUnionStops, Decl(objectSpread.ts, 65, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 65, 25)) + +let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; +>optionalUnionDuplicates : Symbol(optionalUnionDuplicates, Decl(objectSpread.ts, 66, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 66, 30)) + +let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; +>allOptional : Symbol(allOptional, Decl(objectSpread.ts, 67, 3)) +>sn : Symbol(sn, Decl(objectSpread.ts, 67, 18)) + +// computed property +let computedFirst: { a: number, b: string, "before everything": number } = +>computedFirst : Symbol(computedFirst, Decl(objectSpread.ts, 70, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 70, 20)) +>b : Symbol(b, Decl(objectSpread.ts, 70, 31)) + + { ['before everything']: 12, ...o, b: 'yes' } +>'before everything' : Symbol(['before everything'], Decl(objectSpread.ts, 71, 5)) +>b : Symbol(b, Decl(objectSpread.ts, 71, 38)) + +let computedMiddle: { a: number, b: string, c: boolean, "in the middle": number } = +>computedMiddle : Symbol(computedMiddle, Decl(objectSpread.ts, 72, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 72, 21)) +>b : Symbol(b, Decl(objectSpread.ts, 72, 32)) +>c : Symbol(c, Decl(objectSpread.ts, 72, 43)) + + { ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } +>'in the middle' : Symbol(['in the middle'], Decl(objectSpread.ts, 73, 11)) +>b : Symbol(b, Decl(objectSpread.ts, 73, 34)) + +let computedAfter: { a: number, b: string, "at the end": number } = +>computedAfter : Symbol(computedAfter, Decl(objectSpread.ts, 74, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 74, 20)) +>b : Symbol(b, Decl(objectSpread.ts, 74, 31)) + + { ...o, b: 'yeah', ['at the end']: 14 } +>b : Symbol(b, Decl(objectSpread.ts, 75, 11)) +>'at the end' : Symbol(['at the end'], Decl(objectSpread.ts, 75, 22)) + +// shortcut syntax +let a = 12; +>a : Symbol(a, Decl(objectSpread.ts, 77, 3)) + +let shortCutted: { a: number, b: string } = { ...o, a } +>shortCutted : Symbol(shortCutted, Decl(objectSpread.ts, 78, 3)) +>a : Symbol(a, Decl(objectSpread.ts, 78, 18)) +>b : Symbol(b, Decl(objectSpread.ts, 78, 29)) +>a : Symbol(a, Decl(objectSpread.ts, 78, 51)) + + diff --git a/tests/baselines/reference/objectSpread.types b/tests/baselines/reference/objectSpread.types new file mode 100644 index 00000000000..a1c70720d12 --- /dev/null +++ b/tests/baselines/reference/objectSpread.types @@ -0,0 +1,410 @@ +=== tests/cases/conformance/types/spread/objectSpread.ts === +let o = { a: 1, b: 'no' } +>o : { a: number; b: string; } +>{ a: 1, b: 'no' } : { a: number; b: string; } +>a : number +>1 : 1 +>b : string +>'no' : "no" + +let o2 = { b: 'yes', c: true } +>o2 : { b: string; c: boolean; } +>{ b: 'yes', c: true } : { b: string; c: boolean; } +>b : string +>'yes' : "yes" +>c : boolean +>true : true + +let swap = { a: 'yes', b: -1 }; +>swap : { a: string; b: number; } +>{ a: 'yes', b: -1 } : { a: string; b: number; } +>a : string +>'yes' : "yes" +>b : number +>-1 : -1 +>1 : 1 + +let addAfter: { a: number, b: string, c: boolean } = +>addAfter : { a: number; b: string; c: boolean; } +>a : number +>b : string +>c : boolean + + { ...o, c: false } +>{ ...o, c: false } : { c: false; a: number; b: string; } +>o : any +>c : boolean +>false : false + +let addBefore: { a: number, b: string, c: boolean } = +>addBefore : { a: number; b: string; c: boolean; } +>a : number +>b : string +>c : boolean + + { c: false, ...o } +>{ c: false, ...o } : { a: number; b: string; c: false; } +>c : boolean +>false : false +>o : any + +// Note: ignore still changes the order that properties are printed +let ignore: { a: number, b: string } = +>ignore : { a: number; b: string; } +>a : number +>b : string + + { b: 'ignored', ...o } +>{ b: 'ignored', ...o } : { a: number; b: string; } +>b : string +>'ignored' : "ignored" +>o : any + +let override: { a: number, b: string } = +>override : { a: number; b: string; } +>a : number +>b : string + + { ...o, b: 'override' } +>{ ...o, b: 'override' } : { b: string; a: number; } +>o : any +>b : string +>'override' : "override" + +let nested: { a: number, b: boolean, c: string } = +>nested : { a: number; b: boolean; c: string; } +>a : number +>b : boolean +>c : string + + { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } +>{ ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } : { c: string; b: boolean; a: number; } +>{ a: 3, ...{ b: false, c: 'overriden' } } : { b: boolean; c: string; a: number; } +>a : number +>3 : 3 +>{ b: false, c: 'overriden' } : { b: boolean; c: string; } +>b : boolean +>false : false +>c : string +>'overriden' : "overriden" +>c : string +>'whatever' : "whatever" + +let combined: { a: number, b: string, c: boolean } = +>combined : { a: number; b: string; c: boolean; } +>a : number +>b : string +>c : boolean + + { ...o, ...o2 } +>{ ...o, ...o2 } : { b: string; c: boolean; a: number; } +>o : any +>o2 : any + +let combinedBefore: { a: number, b: string, c: boolean } = +>combinedBefore : { a: number; b: string; c: boolean; } +>a : number +>b : string +>c : boolean + + { b: 'ok', ...o, ...o2 } +>{ b: 'ok', ...o, ...o2 } : { b: string; c: boolean; a: number; } +>b : string +>'ok' : "ok" +>o : any +>o2 : any + +let combinedMid: { a: number, b: string, c: boolean } = +>combinedMid : { a: number; b: string; c: boolean; } +>a : number +>b : string +>c : boolean + + { ...o, b: 'ok', ...o2 } +>{ ...o, b: 'ok', ...o2 } : { b: string; c: boolean; a: number; } +>o : any +>b : string +>'ok' : "ok" +>o2 : any + +let combinedAfter: { a: number, b: string, c: boolean } = +>combinedAfter : { a: number; b: string; c: boolean; } +>a : number +>b : string +>c : boolean + + { ...o, ...o2, b: 'ok' } +>{ ...o, ...o2, b: 'ok' } : { b: string; c: boolean; a: number; } +>o : any +>o2 : any +>b : string +>'ok' : "ok" + +let combinedNested: { a: number, b: boolean, c: string, d: string } = +>combinedNested : { a: number; b: boolean; c: string; d: string; } +>a : number +>b : boolean +>c : string +>d : string + + { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } +>{ ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } : { a: number; d: string; b: boolean; c: string; } +>{ a: 4, ...{ b: false, c: 'overriden' } } : { b: boolean; c: string; a: number; } +>a : number +>4 : 4 +>{ b: false, c: 'overriden' } : { b: boolean; c: string; } +>b : boolean +>false : false +>c : string +>'overriden' : "overriden" +>d : string +>'actually new' : "actually new" +>{ a: 5, d: 'maybe new' } : { a: number; d: string; } +>a : number +>5 : 5 +>d : string +>'maybe new' : "maybe new" + +let combinedNestedChangeType: { a: number, b: boolean, c: number } = +>combinedNestedChangeType : { a: number; b: boolean; c: number; } +>a : number +>b : boolean +>c : number + + { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } +>{ ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } : { c: number; b: boolean; a: number; } +>{ a: 1, ...{ b: false, c: 'overriden' } } : { b: boolean; c: string; a: number; } +>a : number +>1 : 1 +>{ b: false, c: 'overriden' } : { b: boolean; c: string; } +>b : boolean +>false : false +>c : string +>'overriden' : "overriden" +>c : number +>-1 : -1 +>1 : 1 + +let propertyNested: { a: { a: number, b: string } } = +>propertyNested : { a: { a: number; b: string; }; } +>a : { a: number; b: string; } +>a : number +>b : string + + { a: { ... o } } +>{ a: { ... o } } : { a: { a: number; b: string; }; } +>a : { a: number; b: string; } +>{ ... o } : { a: number; b: string; } +>o : any + +// accessors don't copy the descriptor +// (which means that readonly getters become read/write properties) +let op = { get a () { return 6 } }; +>op : { readonly a: number; } +>{ get a () { return 6 } } : { readonly a: number; } +>a : number +>6 : 6 + +let getter: { a: number, c: number } = +>getter : { a: number; c: number; } +>a : number +>c : number + + { ...op, c: 7 } +>{ ...op, c: 7 } : { c: number; readonly a: number; } +>op : any +>c : number +>7 : 7 + +getter.a = 12; +>getter.a = 12 : 12 +>getter.a : number +>getter : { a: number; c: number; } +>a : number +>12 : 12 + +// functions result in { } +let spreadFunc = { ...(function () { }) }; +>spreadFunc : {} +>{ ...(function () { }) } : {} +>(function () { }) : () => void +>function () { } : () => void + +// any results in any +let anything: any; +>anything : any + +let spreadAny = { ...anything }; +>spreadAny : any +>{ ...anything } : any +>anything : any + +// methods are not enumerable +class C { p = 1; m() { } } +>C : C +>p : number +>1 : 1 +>m : () => void + +let c: C = new C() +>c : C +>C : C +>new C() : C +>C : typeof C + +let spreadC: { p: number } = { ...c } +>spreadC : { p: number; } +>p : number +>{ ...c } : { p: number; } +>c : any + +// own methods are enumerable +let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } }; +>cplus : { p: number; plus(): void; } +>p : number +>plus : () => void +>{ ...c, plus() { return this.p + 1; } } : { plus(): any; p: number; } +>c : any +>plus : () => any +>this.p + 1 : any +>this.p : any +>this : any +>p : any +>1 : 1 + +cplus.plus(); +>cplus.plus() : void +>cplus.plus : () => void +>cplus : { p: number; plus(): void; } +>plus : () => void + +// new field's type conflicting with existing field is OK +let changeTypeAfter: { a: string, b: string } = +>changeTypeAfter : { a: string; b: string; } +>a : string +>b : string + + { ...o, a: 'wrong type?' } +>{ ...o, a: 'wrong type?' } : { a: string; b: string; } +>o : any +>a : string +>'wrong type?' : "wrong type?" + +let changeTypeBefore: { a: number, b: string } = +>changeTypeBefore : { a: number; b: string; } +>a : number +>b : string + + { a: 'wrong type?', ...o }; +>{ a: 'wrong type?', ...o } : { a: number; b: string; } +>a : string +>'wrong type?' : "wrong type?" +>o : any + +let changeTypeBoth: { a: string, b: number } = +>changeTypeBoth : { a: string; b: number; } +>a : string +>b : number + + { ...o, ...swap }; +>{ ...o, ...swap } : { a: string; b: number; } +>o : any +>swap : any + +// optional +let definiteBoolean: { sn: boolean }; +>definiteBoolean : { sn: boolean; } +>sn : boolean + +let definiteString: { sn: string }; +>definiteString : { sn: string; } +>sn : string + +let optionalString: { sn?: string }; +>optionalString : { sn?: string; } +>sn : string + +let optionalNumber: { sn?: number }; +>optionalNumber : { sn?: number; } +>sn : number + +let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; +>optionalUnionStops : { sn: string | number | boolean; } +>sn : string | number | boolean +>{ ...definiteBoolean, ...definiteString, ...optionalNumber } : { sn: string | number; } +>definiteBoolean : any +>definiteString : any +>optionalNumber : any + +let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; +>optionalUnionDuplicates : { sn: string | number; } +>sn : string | number +>{ ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber } : { sn: string | number; } +>definiteBoolean : any +>definiteString : any +>optionalString : any +>optionalNumber : any + +let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; +>allOptional : { sn?: string | number; } +>sn : string | number +>{ ...optionalString, ...optionalNumber } : { sn?: string | number; } +>optionalString : any +>optionalNumber : any + +// computed property +let computedFirst: { a: number, b: string, "before everything": number } = +>computedFirst : { a: number; b: string; "before everything": number; } +>a : number +>b : string + + { ['before everything']: 12, ...o, b: 'yes' } +>{ ['before everything']: 12, ...o, b: 'yes' } : { b: string; a: number; ['before everything']: number; } +>'before everything' : "before everything" +>12 : 12 +>o : any +>b : string +>'yes' : "yes" + +let computedMiddle: { a: number, b: string, c: boolean, "in the middle": number } = +>computedMiddle : { a: number; b: string; c: boolean; "in the middle": number; } +>a : number +>b : string +>c : boolean + + { ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } +>{ ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } : { b: string; c: boolean; ['in the middle']: number; a: number; } +>o : any +>'in the middle' : "in the middle" +>13 : 13 +>b : string +>'maybe?' : "maybe?" +>o2 : any + +let computedAfter: { a: number, b: string, "at the end": number } = +>computedAfter : { a: number; b: string; "at the end": number; } +>a : number +>b : string + + { ...o, b: 'yeah', ['at the end']: 14 } +>{ ...o, b: 'yeah', ['at the end']: 14 } : { b: string; ['at the end']: number; a: number; } +>o : any +>b : string +>'yeah' : "yeah" +>'at the end' : "at the end" +>14 : 14 + +// shortcut syntax +let a = 12; +>a : number +>12 : 12 + +let shortCutted: { a: number, b: string } = { ...o, a } +>shortCutted : { a: number; b: string; } +>a : number +>b : string +>{ ...o, a } : { a: number; b: string; } +>o : any +>a : number + + diff --git a/tests/baselines/reference/objectSpreadIndexSignature.js b/tests/baselines/reference/objectSpreadIndexSignature.js new file mode 100644 index 00000000000..22e92e6a844 --- /dev/null +++ b/tests/baselines/reference/objectSpreadIndexSignature.js @@ -0,0 +1,36 @@ +//// [objectSpreadIndexSignature.ts] +interface Indexed { + [n: string]: number; + a: number; +} +interface Indexed2 { + [n: string]: boolean; + c: boolean; +} +let indexed: Indexed; +let indexed2: Indexed2; +let i = { ...indexed, b: 11 }; +// only indexed has indexer, so i[101]: any +i[101]; +let ii = { ...indexed, ...indexed2 }; +// both have indexer, so i[1001]: number | boolean +ii[1001]; + + +//// [objectSpreadIndexSignature.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var indexed; +var indexed2; +var i = __assign({}, indexed, { b: 11 }); +// only indexed has indexer, so i[101]: any +i[101]; +var ii = __assign({}, indexed, indexed2); +// both have indexer, so i[1001]: number | boolean +ii[1001]; diff --git a/tests/baselines/reference/objectSpreadIndexSignature.symbols b/tests/baselines/reference/objectSpreadIndexSignature.symbols new file mode 100644 index 00000000000..c51e7f4532f --- /dev/null +++ b/tests/baselines/reference/objectSpreadIndexSignature.symbols @@ -0,0 +1,42 @@ +=== tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts === +interface Indexed { +>Indexed : Symbol(Indexed, Decl(objectSpreadIndexSignature.ts, 0, 0)) + + [n: string]: number; +>n : Symbol(n, Decl(objectSpreadIndexSignature.ts, 1, 5)) + + a: number; +>a : Symbol(Indexed.a, Decl(objectSpreadIndexSignature.ts, 1, 24)) +} +interface Indexed2 { +>Indexed2 : Symbol(Indexed2, Decl(objectSpreadIndexSignature.ts, 3, 1)) + + [n: string]: boolean; +>n : Symbol(n, Decl(objectSpreadIndexSignature.ts, 5, 5)) + + c: boolean; +>c : Symbol(Indexed2.c, Decl(objectSpreadIndexSignature.ts, 5, 25)) +} +let indexed: Indexed; +>indexed : Symbol(indexed, Decl(objectSpreadIndexSignature.ts, 8, 3)) +>Indexed : Symbol(Indexed, Decl(objectSpreadIndexSignature.ts, 0, 0)) + +let indexed2: Indexed2; +>indexed2 : Symbol(indexed2, Decl(objectSpreadIndexSignature.ts, 9, 3)) +>Indexed2 : Symbol(Indexed2, Decl(objectSpreadIndexSignature.ts, 3, 1)) + +let i = { ...indexed, b: 11 }; +>i : Symbol(i, Decl(objectSpreadIndexSignature.ts, 10, 3)) +>b : Symbol(b, Decl(objectSpreadIndexSignature.ts, 10, 21)) + +// only indexed has indexer, so i[101]: any +i[101]; +>i : Symbol(i, Decl(objectSpreadIndexSignature.ts, 10, 3)) + +let ii = { ...indexed, ...indexed2 }; +>ii : Symbol(ii, Decl(objectSpreadIndexSignature.ts, 13, 3)) + +// both have indexer, so i[1001]: number | boolean +ii[1001]; +>ii : Symbol(ii, Decl(objectSpreadIndexSignature.ts, 13, 3)) + diff --git a/tests/baselines/reference/objectSpreadIndexSignature.types b/tests/baselines/reference/objectSpreadIndexSignature.types new file mode 100644 index 00000000000..79a515e7374 --- /dev/null +++ b/tests/baselines/reference/objectSpreadIndexSignature.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts === +interface Indexed { +>Indexed : Indexed + + [n: string]: number; +>n : string + + a: number; +>a : number +} +interface Indexed2 { +>Indexed2 : Indexed2 + + [n: string]: boolean; +>n : string + + c: boolean; +>c : boolean +} +let indexed: Indexed; +>indexed : Indexed +>Indexed : Indexed + +let indexed2: Indexed2; +>indexed2 : Indexed2 +>Indexed2 : Indexed2 + +let i = { ...indexed, b: 11 }; +>i : { b: number; a: number; } +>{ ...indexed, b: 11 } : { b: number; a: number; } +>indexed : any +>b : number +>11 : 11 + +// only indexed has indexer, so i[101]: any +i[101]; +>i[101] : any +>i : { b: number; a: number; } +>101 : 101 + +let ii = { ...indexed, ...indexed2 }; +>ii : { [x: string]: number | boolean; c: boolean; a: number; } +>{ ...indexed, ...indexed2 } : { [x: string]: number | boolean; c: boolean; a: number; } +>indexed : any +>indexed2 : any + +// both have indexer, so i[1001]: number | boolean +ii[1001]; +>ii[1001] : number | boolean +>ii : { [x: string]: number | boolean; c: boolean; a: number; } +>1001 : 1001 + diff --git a/tests/baselines/reference/objectSpreadInference.js b/tests/baselines/reference/objectSpreadInference.js new file mode 100644 index 00000000000..77930e56511 --- /dev/null +++ b/tests/baselines/reference/objectSpreadInference.js @@ -0,0 +1,43 @@ +//// [objectSpreadInference.ts] +interface Result { + t: T; + u: U; + v: V; +} +declare function infer(tuv: { ...T, ...U, a: V }): { t: T, u: U, v: V }; +declare function infer2(utv: { ...U, a: V, ...T }): { t: T, u: U, v: V }; +function generic(w: W, x: X, y: Y) { + // should infer { t: {}, u: {}, v: {} } because there is no trailing type parameter + return infer({ ...w, ...x, a: y, b: "different type" }); +} +let b: { b: number }; +let c: { c: number }; +// can only infer { t: {}, u: {}, v: {} } +let i1 = infer({ ...b, ...c, a: 12 }); +// can only infer { t: {}, u: {}, v: {} } +let i2 = infer2({ ...b, ...c, a: 12 }); +// can only infer { t: {}, u: {}, v: {} } +let i3 = generic(b, c, { a: 12 }); + + +//// [objectSpreadInference.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +function generic(w, x, y) { + // should infer { t: {}, u: {}, v: {} } because there is no trailing type parameter + return infer(__assign({}, w, x, { a: y, b: "different type" })); +} +var b; +var c; +// can only infer { t: {}, u: {}, v: {} } +var i1 = infer(__assign({}, b, c, { a: 12 })); +// can only infer { t: {}, u: {}, v: {} } +var i2 = infer2(__assign({}, b, c, { a: 12 })); +// can only infer { t: {}, u: {}, v: {} } +var i3 = generic(b, c, { a: 12 }); diff --git a/tests/baselines/reference/objectSpreadInference.symbols b/tests/baselines/reference/objectSpreadInference.symbols new file mode 100644 index 00000000000..ddecc4d7e5d --- /dev/null +++ b/tests/baselines/reference/objectSpreadInference.symbols @@ -0,0 +1,100 @@ +=== tests/cases/conformance/types/spread/objectSpreadInference.ts === +interface Result { +>Result : Symbol(Result, Decl(objectSpreadInference.ts, 0, 0)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 0, 17)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 0, 19)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 0, 21)) + + t: T; +>t : Symbol(Result.t, Decl(objectSpreadInference.ts, 0, 25)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 0, 17)) + + u: U; +>u : Symbol(Result.u, Decl(objectSpreadInference.ts, 1, 9)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 0, 19)) + + v: V; +>v : Symbol(Result.v, Decl(objectSpreadInference.ts, 2, 9)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 0, 21)) +} +declare function infer(tuv: { ...T, ...U, a: V }): { t: T, u: U, v: V }; +>infer : Symbol(infer, Decl(objectSpreadInference.ts, 4, 1)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 5, 23)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 5, 25)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 5, 27)) +>tuv : Symbol(tuv, Decl(objectSpreadInference.ts, 5, 30)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 5, 23)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 5, 25)) +>a : Symbol(a, Decl(objectSpreadInference.ts, 5, 48)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 5, 27)) +>t : Symbol(t, Decl(objectSpreadInference.ts, 5, 59)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 5, 23)) +>u : Symbol(u, Decl(objectSpreadInference.ts, 5, 65)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 5, 25)) +>v : Symbol(v, Decl(objectSpreadInference.ts, 5, 71)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 5, 27)) + +declare function infer2(utv: { ...U, a: V, ...T }): { t: T, u: U, v: V }; +>infer2 : Symbol(infer2, Decl(objectSpreadInference.ts, 5, 79)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 6, 24)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 6, 26)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 6, 28)) +>utv : Symbol(utv, Decl(objectSpreadInference.ts, 6, 31)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 6, 26)) +>a : Symbol(a, Decl(objectSpreadInference.ts, 6, 43)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 6, 28)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 6, 24)) +>t : Symbol(t, Decl(objectSpreadInference.ts, 6, 60)) +>T : Symbol(T, Decl(objectSpreadInference.ts, 6, 24)) +>u : Symbol(u, Decl(objectSpreadInference.ts, 6, 66)) +>U : Symbol(U, Decl(objectSpreadInference.ts, 6, 26)) +>v : Symbol(v, Decl(objectSpreadInference.ts, 6, 72)) +>V : Symbol(V, Decl(objectSpreadInference.ts, 6, 28)) + +function generic(w: W, x: X, y: Y) { +>generic : Symbol(generic, Decl(objectSpreadInference.ts, 6, 80)) +>W : Symbol(W, Decl(objectSpreadInference.ts, 7, 17)) +>X : Symbol(X, Decl(objectSpreadInference.ts, 7, 19)) +>Y : Symbol(Y, Decl(objectSpreadInference.ts, 7, 22)) +>w : Symbol(w, Decl(objectSpreadInference.ts, 7, 26)) +>W : Symbol(W, Decl(objectSpreadInference.ts, 7, 17)) +>x : Symbol(x, Decl(objectSpreadInference.ts, 7, 31)) +>X : Symbol(X, Decl(objectSpreadInference.ts, 7, 19)) +>y : Symbol(y, Decl(objectSpreadInference.ts, 7, 37)) +>Y : Symbol(Y, Decl(objectSpreadInference.ts, 7, 22)) + + // should infer { t: {}, u: {}, v: {} } because there is no trailing type parameter + return infer({ ...w, ...x, a: y, b: "different type" }); +>infer : Symbol(infer, Decl(objectSpreadInference.ts, 4, 1)) +>a : Symbol(a, Decl(objectSpreadInference.ts, 9, 30)) +>y : Symbol(y, Decl(objectSpreadInference.ts, 7, 37)) +>b : Symbol(b, Decl(objectSpreadInference.ts, 9, 36)) +} +let b: { b: number }; +>b : Symbol(b, Decl(objectSpreadInference.ts, 11, 3)) +>b : Symbol(b, Decl(objectSpreadInference.ts, 11, 8)) + +let c: { c: number }; +>c : Symbol(c, Decl(objectSpreadInference.ts, 12, 3)) +>c : Symbol(c, Decl(objectSpreadInference.ts, 12, 8)) + +// can only infer { t: {}, u: {}, v: {} } +let i1 = infer({ ...b, ...c, a: 12 }); +>i1 : Symbol(i1, Decl(objectSpreadInference.ts, 14, 3)) +>infer : Symbol(infer, Decl(objectSpreadInference.ts, 4, 1)) +>a : Symbol(a, Decl(objectSpreadInference.ts, 14, 28)) + +// can only infer { t: {}, u: {}, v: {} } +let i2 = infer2({ ...b, ...c, a: 12 }); +>i2 : Symbol(i2, Decl(objectSpreadInference.ts, 16, 3)) +>infer2 : Symbol(infer2, Decl(objectSpreadInference.ts, 5, 79)) +>a : Symbol(a, Decl(objectSpreadInference.ts, 16, 29)) + +// can only infer { t: {}, u: {}, v: {} } +let i3 = generic(b, c, { a: 12 }); +>i3 : Symbol(i3, Decl(objectSpreadInference.ts, 18, 3)) +>generic : Symbol(generic, Decl(objectSpreadInference.ts, 6, 80)) +>b : Symbol(b, Decl(objectSpreadInference.ts, 11, 3)) +>c : Symbol(c, Decl(objectSpreadInference.ts, 12, 3)) +>a : Symbol(a, Decl(objectSpreadInference.ts, 18, 24)) + diff --git a/tests/baselines/reference/objectSpreadInference.types b/tests/baselines/reference/objectSpreadInference.types new file mode 100644 index 00000000000..3e71e29b83c --- /dev/null +++ b/tests/baselines/reference/objectSpreadInference.types @@ -0,0 +1,118 @@ +=== tests/cases/conformance/types/spread/objectSpreadInference.ts === +interface Result { +>Result : Result +>T : T +>U : U +>V : V + + t: T; +>t : T +>T : T + + u: U; +>u : U +>U : U + + v: V; +>v : V +>V : V +} +declare function infer(tuv: { ...T, ...U, a: V }): { t: T, u: U, v: V }; +>infer : (tuv: { ...T; ...U; a: V; }) => { t: T; u: U; v: V; } +>T : T +>U : U +>V : V +>tuv : { ...T; ...U; a: V; } +>T : T +>U : U +>a : V +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + +declare function infer2(utv: { ...U, a: V, ...T }): { t: T, u: U, v: V }; +>infer2 : (utv: { ...U; a: V; ...T }) => { t: T; u: U; v: V; } +>T : T +>U : U +>V : V +>utv : { ...U; a: V; ...T } +>U : U +>a : V +>V : V +>T : T +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + +function generic(w: W, x: X, y: Y) { +>generic : (w: W, x: X, y: Y) => { t: {}; u: {}; v: {}; } +>W : W +>X : X +>Y : Y +>w : W +>W : W +>x : X +>X : X +>y : Y +>Y : Y + + // should infer { t: {}, u: {}, v: {} } because there is no trailing type parameter + return infer({ ...w, ...x, a: y, b: "different type" }); +>infer({ ...w, ...x, a: y, b: "different type" }) : { t: {}; u: {}; v: {}; } +>infer : (tuv: { ...T; ...U; a: V; }) => { t: T; u: U; v: V; } +>{ ...w, ...x, a: y, b: "different type" } : { ...W; ...X; a: Y; b: string; } +>w : any +>x : any +>a : Y +>y : Y +>b : string +>"different type" : "different type" +} +let b: { b: number }; +>b : { b: number; } +>b : number + +let c: { c: number }; +>c : { c: number; } +>c : number + +// can only infer { t: {}, u: {}, v: {} } +let i1 = infer({ ...b, ...c, a: 12 }); +>i1 : { t: {}; u: {}; v: {}; } +>infer({ ...b, ...c, a: 12 }) : { t: {}; u: {}; v: {}; } +>infer : (tuv: { ...T; ...U; a: V; }) => { t: T; u: U; v: V; } +>{ ...b, ...c, a: 12 } : { a: number; c: number; b: number; } +>b : any +>c : any +>a : number +>12 : 12 + +// can only infer { t: {}, u: {}, v: {} } +let i2 = infer2({ ...b, ...c, a: 12 }); +>i2 : { t: {}; u: {}; v: {}; } +>infer2({ ...b, ...c, a: 12 }) : { t: {}; u: {}; v: {}; } +>infer2 : (utv: { ...U; a: V; ...T }) => { t: T; u: U; v: V; } +>{ ...b, ...c, a: 12 } : { a: number; c: number; b: number; } +>b : any +>c : any +>a : number +>12 : 12 + +// can only infer { t: {}, u: {}, v: {} } +let i3 = generic(b, c, { a: 12 }); +>i3 : { t: {}; u: {}; v: {}; } +>generic(b, c, { a: 12 }) : { t: {}; u: {}; v: {}; } +>generic : (w: W, x: X, y: Y) => { t: {}; u: {}; v: {}; } +>b : { b: number; } +>c : { c: number; } +>{ a: 12 } : { a: number; } +>a : number +>12 : 12 + diff --git a/tests/baselines/reference/objectSpreadIntersection.js b/tests/baselines/reference/objectSpreadIntersection.js new file mode 100644 index 00000000000..2ec6ad35413 --- /dev/null +++ b/tests/baselines/reference/objectSpreadIntersection.js @@ -0,0 +1,77 @@ +//// [objectSpreadIntersection.ts] +function iteratedUnionIntersection(t: T, u: U, v: V): void { + let tu: T | U; + let uv: U & V; + let result = { ...tu, ...uv, id: 'foo' }; + let assignable: { ...(T | U), ...(U & V), id: string } = result; +} +// concrete types work +interface A1 { a: number } +interface A2 { a: string } +interface B1 { b: number } +interface B2 { b: string } +let a12: A1 & A2; +let b12: B1 & B2; +let result = { ...a12, ...b12 }; +let sn: number & string = result.a; +sn = result.b; +let assignable: { ...(A1 & A2), ...(B1 & B2) } = result; + +function tripleIntersection(t: T, u: U, v: V): void { + let tuv: T & U & V; + let result = { ...tuv, id: 'bar' }; + let assignable: { ...(T & U & V), id: string } = result; +} +function iteratedDoubleIntersection(t: T, u: U, v: V): void { + let tu: T & U; + let uv: U & V; + let result = { ...tu, ...uv, id: 'baz' }; + let assignable: { ...(T & U), ...(U & V), id: string } = result; +} +function iteratedIntersectionUnion(t: T, u: U, v: V): void { + let tu: T & U; + let uv: U | V; + let result = { ...tu, ...uv, id: 'qux' }; + let assignable: { ...(T & U), ...(U | V), id: string } = result; +} + + + +//// [objectSpreadIntersection.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +function iteratedUnionIntersection(t, u, v) { + var tu; + var uv; + var result = __assign({}, tu, uv, { id: 'foo' }); + var assignable = result; +} +var a12; +var b12; +var result = __assign({}, a12, b12); +var sn = result.a; +sn = result.b; +var assignable = result; +function tripleIntersection(t, u, v) { + var tuv; + var result = __assign({}, tuv, { id: 'bar' }); + var assignable = result; +} +function iteratedDoubleIntersection(t, u, v) { + var tu; + var uv; + var result = __assign({}, tu, uv, { id: 'baz' }); + var assignable = result; +} +function iteratedIntersectionUnion(t, u, v) { + var tu; + var uv; + var result = __assign({}, tu, uv, { id: 'qux' }); + var assignable = result; +} diff --git a/tests/baselines/reference/objectSpreadIntersection.symbols b/tests/baselines/reference/objectSpreadIntersection.symbols new file mode 100644 index 00000000000..bc63cb11348 --- /dev/null +++ b/tests/baselines/reference/objectSpreadIntersection.symbols @@ -0,0 +1,188 @@ +=== tests/cases/conformance/types/spread/objectSpreadIntersection.ts === +function iteratedUnionIntersection(t: T, u: U, v: V): void { +>iteratedUnionIntersection : Symbol(iteratedUnionIntersection, Decl(objectSpreadIntersection.ts, 0, 0)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 0, 35)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 0, 37)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 0, 40)) +>t : Symbol(t, Decl(objectSpreadIntersection.ts, 0, 44)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 0, 35)) +>u : Symbol(u, Decl(objectSpreadIntersection.ts, 0, 49)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 0, 37)) +>v : Symbol(v, Decl(objectSpreadIntersection.ts, 0, 55)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 0, 40)) + + let tu: T | U; +>tu : Symbol(tu, Decl(objectSpreadIntersection.ts, 1, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 0, 35)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 0, 37)) + + let uv: U & V; +>uv : Symbol(uv, Decl(objectSpreadIntersection.ts, 2, 7)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 0, 37)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 0, 40)) + + let result = { ...tu, ...uv, id: 'foo' }; +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 3, 7)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 3, 32)) + + let assignable: { ...(T | U), ...(U & V), id: string } = result; +>assignable : Symbol(assignable, Decl(objectSpreadIntersection.ts, 4, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 0, 35)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 0, 37)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 0, 37)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 0, 40)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 4, 45)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 3, 7)) +} +// concrete types work +interface A1 { a: number } +>A1 : Symbol(A1, Decl(objectSpreadIntersection.ts, 5, 1)) +>a : Symbol(A1.a, Decl(objectSpreadIntersection.ts, 7, 14)) + +interface A2 { a: string } +>A2 : Symbol(A2, Decl(objectSpreadIntersection.ts, 7, 26)) +>a : Symbol(A2.a, Decl(objectSpreadIntersection.ts, 8, 14)) + +interface B1 { b: number } +>B1 : Symbol(B1, Decl(objectSpreadIntersection.ts, 8, 26)) +>b : Symbol(B1.b, Decl(objectSpreadIntersection.ts, 9, 14)) + +interface B2 { b: string } +>B2 : Symbol(B2, Decl(objectSpreadIntersection.ts, 9, 26)) +>b : Symbol(B2.b, Decl(objectSpreadIntersection.ts, 10, 14)) + +let a12: A1 & A2; +>a12 : Symbol(a12, Decl(objectSpreadIntersection.ts, 11, 3)) +>A1 : Symbol(A1, Decl(objectSpreadIntersection.ts, 5, 1)) +>A2 : Symbol(A2, Decl(objectSpreadIntersection.ts, 7, 26)) + +let b12: B1 & B2; +>b12 : Symbol(b12, Decl(objectSpreadIntersection.ts, 12, 3)) +>B1 : Symbol(B1, Decl(objectSpreadIntersection.ts, 8, 26)) +>B2 : Symbol(B2, Decl(objectSpreadIntersection.ts, 9, 26)) + +let result = { ...a12, ...b12 }; +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 13, 3)) + +let sn: number & string = result.a; +>sn : Symbol(sn, Decl(objectSpreadIntersection.ts, 14, 3)) +>result.a : Symbol(a, Decl(objectSpreadIntersection.ts, 7, 14), Decl(objectSpreadIntersection.ts, 8, 14)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 13, 3)) +>a : Symbol(a, Decl(objectSpreadIntersection.ts, 7, 14), Decl(objectSpreadIntersection.ts, 8, 14)) + +sn = result.b; +>sn : Symbol(sn, Decl(objectSpreadIntersection.ts, 14, 3)) +>result.b : Symbol(b, Decl(objectSpreadIntersection.ts, 9, 14), Decl(objectSpreadIntersection.ts, 10, 14)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 13, 3)) +>b : Symbol(b, Decl(objectSpreadIntersection.ts, 9, 14), Decl(objectSpreadIntersection.ts, 10, 14)) + +let assignable: { ...(A1 & A2), ...(B1 & B2) } = result; +>assignable : Symbol(assignable, Decl(objectSpreadIntersection.ts, 16, 3)) +>A1 : Symbol(A1, Decl(objectSpreadIntersection.ts, 5, 1)) +>A2 : Symbol(A2, Decl(objectSpreadIntersection.ts, 7, 26)) +>B1 : Symbol(B1, Decl(objectSpreadIntersection.ts, 8, 26)) +>B2 : Symbol(B2, Decl(objectSpreadIntersection.ts, 9, 26)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 13, 3)) + +function tripleIntersection(t: T, u: U, v: V): void { +>tripleIntersection : Symbol(tripleIntersection, Decl(objectSpreadIntersection.ts, 16, 56)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 18, 28)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 18, 30)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 18, 33)) +>t : Symbol(t, Decl(objectSpreadIntersection.ts, 18, 37)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 18, 28)) +>u : Symbol(u, Decl(objectSpreadIntersection.ts, 18, 42)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 18, 30)) +>v : Symbol(v, Decl(objectSpreadIntersection.ts, 18, 48)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 18, 33)) + + let tuv: T & U & V; +>tuv : Symbol(tuv, Decl(objectSpreadIntersection.ts, 19, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 18, 28)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 18, 30)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 18, 33)) + + let result = { ...tuv, id: 'bar' }; +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 20, 7)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 20, 26)) + + let assignable: { ...(T & U & V), id: string } = result; +>assignable : Symbol(assignable, Decl(objectSpreadIntersection.ts, 21, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 18, 28)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 18, 30)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 18, 33)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 21, 37)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 20, 7)) +} +function iteratedDoubleIntersection(t: T, u: U, v: V): void { +>iteratedDoubleIntersection : Symbol(iteratedDoubleIntersection, Decl(objectSpreadIntersection.ts, 22, 1)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 23, 36)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 23, 38)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 23, 41)) +>t : Symbol(t, Decl(objectSpreadIntersection.ts, 23, 45)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 23, 36)) +>u : Symbol(u, Decl(objectSpreadIntersection.ts, 23, 50)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 23, 38)) +>v : Symbol(v, Decl(objectSpreadIntersection.ts, 23, 56)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 23, 41)) + + let tu: T & U; +>tu : Symbol(tu, Decl(objectSpreadIntersection.ts, 24, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 23, 36)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 23, 38)) + + let uv: U & V; +>uv : Symbol(uv, Decl(objectSpreadIntersection.ts, 25, 7)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 23, 38)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 23, 41)) + + let result = { ...tu, ...uv, id: 'baz' }; +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 26, 7)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 26, 32)) + + let assignable: { ...(T & U), ...(U & V), id: string } = result; +>assignable : Symbol(assignable, Decl(objectSpreadIntersection.ts, 27, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 23, 36)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 23, 38)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 23, 38)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 23, 41)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 27, 45)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 26, 7)) +} +function iteratedIntersectionUnion(t: T, u: U, v: V): void { +>iteratedIntersectionUnion : Symbol(iteratedIntersectionUnion, Decl(objectSpreadIntersection.ts, 28, 1)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 29, 35)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 29, 37)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 29, 40)) +>t : Symbol(t, Decl(objectSpreadIntersection.ts, 29, 44)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 29, 35)) +>u : Symbol(u, Decl(objectSpreadIntersection.ts, 29, 49)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 29, 37)) +>v : Symbol(v, Decl(objectSpreadIntersection.ts, 29, 55)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 29, 40)) + + let tu: T & U; +>tu : Symbol(tu, Decl(objectSpreadIntersection.ts, 30, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 29, 35)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 29, 37)) + + let uv: U | V; +>uv : Symbol(uv, Decl(objectSpreadIntersection.ts, 31, 7)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 29, 37)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 29, 40)) + + let result = { ...tu, ...uv, id: 'qux' }; +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 32, 7)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 32, 32)) + + let assignable: { ...(T & U), ...(U | V), id: string } = result; +>assignable : Symbol(assignable, Decl(objectSpreadIntersection.ts, 33, 7)) +>T : Symbol(T, Decl(objectSpreadIntersection.ts, 29, 35)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 29, 37)) +>U : Symbol(U, Decl(objectSpreadIntersection.ts, 29, 37)) +>V : Symbol(V, Decl(objectSpreadIntersection.ts, 29, 40)) +>id : Symbol(id, Decl(objectSpreadIntersection.ts, 33, 45)) +>result : Symbol(result, Decl(objectSpreadIntersection.ts, 32, 7)) +} + + diff --git a/tests/baselines/reference/objectSpreadIntersection.types b/tests/baselines/reference/objectSpreadIntersection.types new file mode 100644 index 00000000000..e6a7b7c19ee --- /dev/null +++ b/tests/baselines/reference/objectSpreadIntersection.types @@ -0,0 +1,207 @@ +=== tests/cases/conformance/types/spread/objectSpreadIntersection.ts === +function iteratedUnionIntersection(t: T, u: U, v: V): void { +>iteratedUnionIntersection : (t: T, u: U, v: V) => void +>T : T +>U : U +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + + let tu: T | U; +>tu : T | U +>T : T +>U : U + + let uv: U & V; +>uv : U & V +>U : U +>V : V + + let result = { ...tu, ...uv, id: 'foo' }; +>result : { ...T; ...U & V; id: string; } | { ...U; ...U & V; id: string; } +>{ ...tu, ...uv, id: 'foo' } : { ...T; ...U & V; id: string; } | { ...U; ...U & V; id: string; } +>tu : any +>uv : any +>id : string +>'foo' : "foo" + + let assignable: { ...(T | U), ...(U & V), id: string } = result; +>assignable : { ...T; ...U & V; id: string; } | { ...U; ...U & V; id: string; } +>T : T +>U : U +>U : U +>V : V +>id : string +>result : { ...T; ...U & V; id: string; } | { ...U; ...U & V; id: string; } +} +// concrete types work +interface A1 { a: number } +>A1 : A1 +>a : number + +interface A2 { a: string } +>A2 : A2 +>a : string + +interface B1 { b: number } +>B1 : B1 +>b : number + +interface B2 { b: string } +>B2 : B2 +>b : string + +let a12: A1 & A2; +>a12 : A1 & A2 +>A1 : A1 +>A2 : A2 + +let b12: B1 & B2; +>b12 : B1 & B2 +>B1 : B1 +>B2 : B2 + +let result = { ...a12, ...b12 }; +>result : { b: number & string; a: number & string; } +>{ ...a12, ...b12 } : { b: number & string; a: number & string; } +>a12 : any +>b12 : any + +let sn: number & string = result.a; +>sn : number & string +>result.a : number & string +>result : { b: number & string; a: number & string; } +>a : number & string + +sn = result.b; +>sn = result.b : number & string +>sn : number & string +>result.b : number & string +>result : { b: number & string; a: number & string; } +>b : number & string + +let assignable: { ...(A1 & A2), ...(B1 & B2) } = result; +>assignable : { b: number & string; a: number & string; } +>A1 : A1 +>A2 : A2 +>B1 : B1 +>B2 : B2 +>result : { b: number & string; a: number & string; } + +function tripleIntersection(t: T, u: U, v: V): void { +>tripleIntersection : (t: T, u: U, v: V) => void +>T : T +>U : U +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + + let tuv: T & U & V; +>tuv : T & U & V +>T : T +>U : U +>V : V + + let result = { ...tuv, id: 'bar' }; +>result : { ...T & U & V; id: string; } +>{ ...tuv, id: 'bar' } : { ...T & U & V; id: string; } +>tuv : any +>id : string +>'bar' : "bar" + + let assignable: { ...(T & U & V), id: string } = result; +>assignable : { ...T & U & V; id: string; } +>T : T +>U : U +>V : V +>id : string +>result : { ...T & U & V; id: string; } +} +function iteratedDoubleIntersection(t: T, u: U, v: V): void { +>iteratedDoubleIntersection : (t: T, u: U, v: V) => void +>T : T +>U : U +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + + let tu: T & U; +>tu : T & U +>T : T +>U : U + + let uv: U & V; +>uv : U & V +>U : U +>V : V + + let result = { ...tu, ...uv, id: 'baz' }; +>result : { ...T & U; ...U & V; id: string; } +>{ ...tu, ...uv, id: 'baz' } : { ...T & U; ...U & V; id: string; } +>tu : any +>uv : any +>id : string +>'baz' : "baz" + + let assignable: { ...(T & U), ...(U & V), id: string } = result; +>assignable : { ...T & U; ...U & V; id: string; } +>T : T +>U : U +>U : U +>V : V +>id : string +>result : { ...T & U; ...U & V; id: string; } +} +function iteratedIntersectionUnion(t: T, u: U, v: V): void { +>iteratedIntersectionUnion : (t: T, u: U, v: V) => void +>T : T +>U : U +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + + let tu: T & U; +>tu : T & U +>T : T +>U : U + + let uv: U | V; +>uv : U | V +>U : U +>V : V + + let result = { ...tu, ...uv, id: 'qux' }; +>result : { ...T & U; ...U; id: string; } | { ...T & U; ...V; id: string; } +>{ ...tu, ...uv, id: 'qux' } : { ...T & U; ...U; id: string; } | { ...T & U; ...V; id: string; } +>tu : any +>uv : any +>id : string +>'qux' : "qux" + + let assignable: { ...(T & U), ...(U | V), id: string } = result; +>assignable : { ...T & U; ...U; id: string; } | { ...T & U; ...V; id: string; } +>T : T +>U : U +>U : U +>V : V +>id : string +>result : { ...T & U; ...U; id: string; } | { ...T & U; ...V; id: string; } +} + + diff --git a/tests/baselines/reference/objectSpreadNegative.errors.txt b/tests/baselines/reference/objectSpreadNegative.errors.txt new file mode 100644 index 00000000000..dc6a356708f --- /dev/null +++ b/tests/baselines/reference/objectSpreadNegative.errors.txt @@ -0,0 +1,131 @@ +tests/cases/conformance/types/spread/objectSpreadNegative.ts(13,21): error TS2339: Property 'x' does not exist on type '{}'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(16,5): error TS2322: Type '{ sn?: string | number; }' is not assignable to type '{ sn: string | number; }'. + Property 'sn' is optional in type '{ sn?: string | number; }' but required in type '{ sn: string | number; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(23,1): error TS2322: Type '{ s: string; }' is not assignable to type '{ s: string; b: boolean; }'. + Property 'b' is missing in type '{ s: string; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(25,1): error TS2322: Type '{ b: boolean; }' is not assignable to type '{ s: string; b: boolean; }'. + Property 's' is missing in type '{ b: boolean; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,36): error TS2300: Duplicate identifier 'b'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(28,53): error TS2300: Duplicate identifier 'b'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(32,20): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(33,24): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(34,19): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(35,19): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(37,20): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(39,19): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(44,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{}' has no compatible call signatures. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(48,12): error TS2339: Property 'b' does not exist on type '{}'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(54,9): error TS2339: Property 'm' does not exist on type '{ p: number; }'. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(58,14): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegative.ts(61,14): error TS2698: Spread types may only be created from object types. + + +==== tests/cases/conformance/types/spread/objectSpreadNegative.ts (17 errors) ==== + let o = { a: 1, b: 'no' } + + /// private propagates + class PrivateOptionalX { + private x?: number; + } + class PublicX { + public x: number; + } + let publicX: PublicX; + let privateOptionalX: PrivateOptionalX; + let o2 = { ...publicX, ...privateOptionalX }; + let sn: number = o2.x; // error, x is private + ~ +!!! error TS2339: Property 'x' does not exist on type '{}'. + let optionalString: { sn?: string }; + let optionalNumber: { sn?: number }; + let allOptional: { sn: string | number } = { ...optionalString, ...optionalNumber }; + ~~~~~~~~~~~ +!!! error TS2322: Type '{ sn?: string | number; }' is not assignable to type '{ sn: string | number; }'. +!!! error TS2322: Property 'sn' is optional in type '{ sn?: string | number; }' but required in type '{ sn: string | number; }'. + // error, 'sn' is optional in source, required in target + + // assignability as target + interface Bool { b: boolean }; + interface Str { s: string }; + let spread = { ...{ b: true }, ...{s: "foo" } }; + spread = { s: "foo" }; // error, missing 'b' + ~~~~~~ +!!! error TS2322: Type '{ s: string; }' is not assignable to type '{ s: string; b: boolean; }'. +!!! error TS2322: Property 'b' is missing in type '{ s: string; }'. + let b = { b: false }; + spread = b; // error, missing 's' + ~~~~~~ +!!! error TS2322: Type '{ b: boolean; }' is not assignable to type '{ s: string; b: boolean; }'. +!!! error TS2322: Property 's' is missing in type '{ b: boolean; }'. + + // literal repeats are not allowed, but spread repeats are fine + let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' } + ~ +!!! error TS2300: Duplicate identifier 'b'. + ~ +!!! error TS2300: Duplicate identifier 'b'. + let duplicatedSpread = { ...o, ...o } + + // null, undefined and primitives are not allowed + let spreadNull = { ...null }; + ~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + let spreadUndefind = { ...undefined }; + ~~~~~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + let spreadNum = { ...12 }; + ~~~~~ +!!! error TS2698: Spread types may only be created from object types. + let spreadSum = { ...1 + 1 }; + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + spreadSum.toFixed(); // error, no methods from number + let spreadBool = { ...false }; + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + spreadBool.valueOf(); // error, what were you thinking? + let spreadStr = { ...'foo' }; + ~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + spreadStr.length; // error, no 'length' + spreadStr.charAt(1); // error, no methods either + // functions are skipped + let spreadFunc = { ...function () { } } + spreadFunc(); // error, no call signature + ~~~~~~~~~~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{}' has no compatible call signatures. + + // write-only properties get skipped + let setterOnly = { ...{ set b (bad: number) { } } }; + setterOnly.b = 12; // error, 'b' does not exist + ~ +!!! error TS2339: Property 'b' does not exist on type '{}'. + + // methods are skipped because they aren't enumerable + class C { p = 1; m() { } } + let c: C = new C() + let spreadC = { ...c } + spreadC.m(); // error 'm' is not in '{ ... c }' + ~ +!!! error TS2339: Property 'm' does not exist on type '{ p: number; }'. + + // generics + function f(t: T, u: U) { + return { ...t, ...u, id: 'id' }; + ~~~~ +!!! error TS2698: Spread types may only be created from object types. + } + function override(initial: U, override: U): U { + return { ...initial, ...override }; + ~~~~~~~~~~ +!!! error TS2698: Spread types may only be created from object types. + } + let exclusive: { id: string, a: number, b: string, c: string, d: boolean } = + f({ a: 1, b: 'yes' }, { c: 'no', d: false }) + let overlap: { id: string, a: number, b: string } = + f({ a: 1 }, { a: 2, b: 'extra' }) + let overlapConflict: { id:string, a: string } = + f({ a: 1 }, { a: 'mismatch' }) + let overwriteId: { id: string, a: number, c: number, d: string } = + f({ a: 1, id: true }, { c: 1, d: 'no' }) + \ No newline at end of file diff --git a/tests/baselines/reference/objectSpreadNegative.js b/tests/baselines/reference/objectSpreadNegative.js new file mode 100644 index 00000000000..6287f4559a7 --- /dev/null +++ b/tests/baselines/reference/objectSpreadNegative.js @@ -0,0 +1,149 @@ +//// [objectSpreadNegative.ts] +let o = { a: 1, b: 'no' } + +/// private propagates +class PrivateOptionalX { + private x?: number; +} +class PublicX { + public x: number; +} +let publicX: PublicX; +let privateOptionalX: PrivateOptionalX; +let o2 = { ...publicX, ...privateOptionalX }; +let sn: number = o2.x; // error, x is private +let optionalString: { sn?: string }; +let optionalNumber: { sn?: number }; +let allOptional: { sn: string | number } = { ...optionalString, ...optionalNumber }; +// error, 'sn' is optional in source, required in target + +// assignability as target +interface Bool { b: boolean }; +interface Str { s: string }; +let spread = { ...{ b: true }, ...{s: "foo" } }; +spread = { s: "foo" }; // error, missing 'b' +let b = { b: false }; +spread = b; // error, missing 's' + +// literal repeats are not allowed, but spread repeats are fine +let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' } +let duplicatedSpread = { ...o, ...o } + +// null, undefined and primitives are not allowed +let spreadNull = { ...null }; +let spreadUndefind = { ...undefined }; +let spreadNum = { ...12 }; +let spreadSum = { ...1 + 1 }; +spreadSum.toFixed(); // error, no methods from number +let spreadBool = { ...false }; +spreadBool.valueOf(); // error, what were you thinking? +let spreadStr = { ...'foo' }; +spreadStr.length; // error, no 'length' +spreadStr.charAt(1); // error, no methods either +// functions are skipped +let spreadFunc = { ...function () { } } +spreadFunc(); // error, no call signature + +// write-only properties get skipped +let setterOnly = { ...{ set b (bad: number) { } } }; +setterOnly.b = 12; // error, 'b' does not exist + +// methods are skipped because they aren't enumerable +class C { p = 1; m() { } } +let c: C = new C() +let spreadC = { ...c } +spreadC.m(); // error 'm' is not in '{ ... c }' + +// generics +function f(t: T, u: U) { + return { ...t, ...u, id: 'id' }; +} +function override(initial: U, override: U): U { + return { ...initial, ...override }; +} +let exclusive: { id: string, a: number, b: string, c: string, d: boolean } = + f({ a: 1, b: 'yes' }, { c: 'no', d: false }) +let overlap: { id: string, a: number, b: string } = + f({ a: 1 }, { a: 2, b: 'extra' }) +let overlapConflict: { id:string, a: string } = + f({ a: 1 }, { a: 'mismatch' }) +let overwriteId: { id: string, a: number, c: number, d: string } = + f({ a: 1, id: true }, { c: 1, d: 'no' }) + + +//// [objectSpreadNegative.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var o = { a: 1, b: 'no' }; +/// private propagates +var PrivateOptionalX = (function () { + function PrivateOptionalX() { + } + return PrivateOptionalX; +}()); +var PublicX = (function () { + function PublicX() { + } + return PublicX; +}()); +var publicX; +var privateOptionalX; +var o2 = __assign({}, publicX, privateOptionalX); +var sn = o2.x; // error, x is private +var optionalString; +var optionalNumber; +var allOptional = __assign({}, optionalString, optionalNumber); +; +; +var spread = __assign({ b: true }, { s: "foo" }); +spread = { s: "foo" }; // error, missing 'b' +var b = { b: false }; +spread = b; // error, missing 's' +// literal repeats are not allowed, but spread repeats are fine +var duplicated = __assign({ b: 'bad' }, o, { b: 'bad' }, o2, { b: 'bad' }); +var duplicatedSpread = __assign({}, o, o); +// null, undefined and primitives are not allowed +var spreadNull = __assign({}, null); +var spreadUndefind = __assign({}, undefined); +var spreadNum = __assign({}, 12); +var spreadSum = __assign({}, 1 + 1); +spreadSum.toFixed(); // error, no methods from number +var spreadBool = __assign({}, false); +spreadBool.valueOf(); // error, what were you thinking? +var spreadStr = __assign({}, 'foo'); +spreadStr.length; // error, no 'length' +spreadStr.charAt(1); // error, no methods either +// functions are skipped +var spreadFunc = __assign({}, function () { }); +spreadFunc(); // error, no call signature +// write-only properties get skipped +var setterOnly = __assign({ set b(bad) { } }); +setterOnly.b = 12; // error, 'b' does not exist +// methods are skipped because they aren't enumerable +var C = (function () { + function C() { + this.p = 1; + } + C.prototype.m = function () { }; + return C; +}()); +var c = new C(); +var spreadC = __assign({}, c); +spreadC.m(); // error 'm' is not in '{ ... c }' +// generics +function f(t, u) { + return __assign({}, t, u, { id: 'id' }); +} +function override(initial, override) { + return __assign({}, initial, override); +} +var exclusive = f({ a: 1, b: 'yes' }, { c: 'no', d: false }); +var overlap = f({ a: 1 }, { a: 2, b: 'extra' }); +var overlapConflict = f({ a: 1 }, { a: 'mismatch' }); +var overwriteId = f({ a: 1, id: true }, { c: 1, d: 'no' }); diff --git a/tests/baselines/reference/objectSpreadNegativeParse.errors.txt b/tests/baselines/reference/objectSpreadNegativeParse.errors.txt new file mode 100644 index 00000000000..b37200c4f02 --- /dev/null +++ b/tests/baselines/reference/objectSpreadNegativeParse.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(1,15): error TS2304: Cannot find name 'o'. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(1,18): error TS1109: Expression expected. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(2,12): error TS2698: Spread types may only be created from object types. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(2,15): error TS1109: Expression expected. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(2,16): error TS2304: Cannot find name 'o'. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(3,15): error TS2304: Cannot find name 'matchMedia'. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(3,28): error TS1005: ',' expected. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(3,31): error TS1128: Declaration or statement expected. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(4,16): error TS2304: Cannot find name 'get'. +tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts(4,20): error TS1005: ',' expected. + + +==== tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts (10 errors) ==== + let o7 = { ...o? }; + ~ +!!! error TS2304: Cannot find name 'o'. + ~ +!!! error TS1109: Expression expected. + let o8 = { ...*o }; + ~~~~~ +!!! error TS2698: Spread types may only be created from object types. + ~ +!!! error TS1109: Expression expected. + ~ +!!! error TS2304: Cannot find name 'o'. + let o9 = { ...matchMedia() { }}; + ~~~~~~~~~~ +!!! error TS2304: Cannot find name 'matchMedia'. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1128: Declaration or statement expected. + let o10 = { ...get x() { return 12; }}; + ~~~ +!!! error TS2304: Cannot find name 'get'. + ~ +!!! error TS1005: ',' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/objectSpreadNegativeParse.js b/tests/baselines/reference/objectSpreadNegativeParse.js new file mode 100644 index 00000000000..297c56c3e62 --- /dev/null +++ b/tests/baselines/reference/objectSpreadNegativeParse.js @@ -0,0 +1,21 @@ +//// [objectSpreadNegativeParse.ts] +let o7 = { ...o? }; +let o8 = { ...*o }; +let o9 = { ...matchMedia() { }}; +let o10 = { ...get x() { return 12; }}; + + +//// [objectSpreadNegativeParse.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var o7 = __assign({}, o ? : ); +var o8 = __assign({}, * o); +var o9 = __assign({}, matchMedia()), _a = void 0; +; +var o10 = __assign({}, get, { x: function () { return 12; } }); diff --git a/tests/baselines/reference/objectSpreadNoTransform.js b/tests/baselines/reference/objectSpreadNoTransform.js new file mode 100644 index 00000000000..3442d086409 --- /dev/null +++ b/tests/baselines/reference/objectSpreadNoTransform.js @@ -0,0 +1,14 @@ +//// [objectSpreadNoTransform.ts] +const y = { a: 'yes', b: 'no' }; +const o = { x: 1, ...y }; +var b; +var rest; +({ b, ...rest } = o); + + +//// [objectSpreadNoTransform.js] +const y = { a: 'yes', b: 'no' }; +const o = { x: 1, ...y }; +var b; +var rest; +({ b, ...rest } = o); diff --git a/tests/baselines/reference/objectSpreadNoTransform.symbols b/tests/baselines/reference/objectSpreadNoTransform.symbols new file mode 100644 index 00000000000..d7dac11a530 --- /dev/null +++ b/tests/baselines/reference/objectSpreadNoTransform.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/types/spread/objectSpreadNoTransform.ts === +const y = { a: 'yes', b: 'no' }; +>y : Symbol(y, Decl(objectSpreadNoTransform.ts, 0, 5)) +>a : Symbol(a, Decl(objectSpreadNoTransform.ts, 0, 11)) +>b : Symbol(b, Decl(objectSpreadNoTransform.ts, 0, 21)) + +const o = { x: 1, ...y }; +>o : Symbol(o, Decl(objectSpreadNoTransform.ts, 1, 5)) +>x : Symbol(x, Decl(objectSpreadNoTransform.ts, 1, 11)) + +var b; +>b : Symbol(b, Decl(objectSpreadNoTransform.ts, 2, 3)) + +var rest; +>rest : Symbol(rest, Decl(objectSpreadNoTransform.ts, 3, 3)) + +({ b, ...rest } = o); +>b : Symbol(b, Decl(objectSpreadNoTransform.ts, 4, 2)) +>o : Symbol(o, Decl(objectSpreadNoTransform.ts, 1, 5)) + diff --git a/tests/baselines/reference/objectSpreadNoTransform.types b/tests/baselines/reference/objectSpreadNoTransform.types new file mode 100644 index 00000000000..0a6c867e8fe --- /dev/null +++ b/tests/baselines/reference/objectSpreadNoTransform.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/types/spread/objectSpreadNoTransform.ts === +const y = { a: 'yes', b: 'no' }; +>y : { a: string; b: string; } +>{ a: 'yes', b: 'no' } : { a: string; b: string; } +>a : string +>'yes' : "yes" +>b : string +>'no' : "no" + +const o = { x: 1, ...y }; +>o : { a: string; b: string; x: number; } +>{ x: 1, ...y } : { a: string; b: string; x: number; } +>x : number +>1 : 1 +>y : any + +var b; +>b : any + +var rest; +>rest : any + +({ b, ...rest } = o); +>({ b, ...rest } = o) : { a: string; b: string; x: number; } +>{ b, ...rest } = o : { a: string; b: string; x: number; } +>{ b, ...rest } : any +>b : any +>rest : any +>o : { a: string; b: string; x: number; } + diff --git a/tests/baselines/reference/objectSpreadScenarios.js b/tests/baselines/reference/objectSpreadScenarios.js new file mode 100644 index 00000000000..96ac98d2d35 --- /dev/null +++ b/tests/baselines/reference/objectSpreadScenarios.js @@ -0,0 +1,45 @@ +//// [objectSpreadScenarios.ts] +interface A1 { a: boolean } +interface B1 { b: number }; +function override(initial: U, override: U): { ...U, ...U } { + return { ...initial, ...override }; +} +function update(this: { u: { ...U } }, override: U): void { + this.u = { ...this.u, ...override }; +} +function mixin(one: T, two: U): { ...T, ...U } { + return { ...one, ...two }; +} +let a1: A1 = { a: true }; +let b1: B1 = { b: 101 }; +a1 = override(a1, { a: false }); +let host = { u: a1, update }; +host.update({ a: false }); +let mixed = mixin(a1, b1); + + +//// [objectSpreadScenarios.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +; +function override(initial, override) { + return __assign({}, initial, override); +} +function update(override) { + this.u = __assign({}, this.u, override); +} +function mixin(one, two) { + return __assign({}, one, two); +} +var a1 = { a: true }; +var b1 = { b: 101 }; +a1 = override(a1, { a: false }); +var host = { u: a1, update: update }; +host.update({ a: false }); +var mixed = mixin(a1, b1); diff --git a/tests/baselines/reference/objectSpreadScenarios.symbols b/tests/baselines/reference/objectSpreadScenarios.symbols new file mode 100644 index 00000000000..cf1e1833ac9 --- /dev/null +++ b/tests/baselines/reference/objectSpreadScenarios.symbols @@ -0,0 +1,85 @@ +=== tests/cases/conformance/types/spread/objectSpreadScenarios.ts === +interface A1 { a: boolean } +>A1 : Symbol(A1, Decl(objectSpreadScenarios.ts, 0, 0)) +>a : Symbol(A1.a, Decl(objectSpreadScenarios.ts, 0, 14)) + +interface B1 { b: number }; +>B1 : Symbol(B1, Decl(objectSpreadScenarios.ts, 0, 27)) +>b : Symbol(B1.b, Decl(objectSpreadScenarios.ts, 1, 14)) + +function override(initial: U, override: U): { ...U, ...U } { +>override : Symbol(override, Decl(objectSpreadScenarios.ts, 1, 27)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 2, 18)) +>initial : Symbol(initial, Decl(objectSpreadScenarios.ts, 2, 21)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 2, 18)) +>override : Symbol(override, Decl(objectSpreadScenarios.ts, 2, 32)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 2, 18)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 2, 18)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 2, 18)) + + return { ...initial, ...override }; +} +function update(this: { u: { ...U } }, override: U): void { +>update : Symbol(update, Decl(objectSpreadScenarios.ts, 4, 1)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 5, 16)) +>this : Symbol(this, Decl(objectSpreadScenarios.ts, 5, 19)) +>u : Symbol(u, Decl(objectSpreadScenarios.ts, 5, 26)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 5, 16)) +>override : Symbol(override, Decl(objectSpreadScenarios.ts, 5, 41)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 5, 16)) + + this.u = { ...this.u, ...override }; +>this.u : Symbol(u, Decl(objectSpreadScenarios.ts, 5, 26)) +>this : Symbol(this, Decl(objectSpreadScenarios.ts, 5, 19)) +>u : Symbol(u, Decl(objectSpreadScenarios.ts, 5, 26)) +>this.u : Symbol(u, Decl(objectSpreadScenarios.ts, 5, 26)) +>this : Symbol(this, Decl(objectSpreadScenarios.ts, 5, 19)) +>u : Symbol(u, Decl(objectSpreadScenarios.ts, 5, 26)) +} +function mixin(one: T, two: U): { ...T, ...U } { +>mixin : Symbol(mixin, Decl(objectSpreadScenarios.ts, 7, 1)) +>T : Symbol(T, Decl(objectSpreadScenarios.ts, 8, 15)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 8, 17)) +>one : Symbol(one, Decl(objectSpreadScenarios.ts, 8, 21)) +>T : Symbol(T, Decl(objectSpreadScenarios.ts, 8, 15)) +>two : Symbol(two, Decl(objectSpreadScenarios.ts, 8, 28)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 8, 17)) +>T : Symbol(T, Decl(objectSpreadScenarios.ts, 8, 15)) +>U : Symbol(U, Decl(objectSpreadScenarios.ts, 8, 17)) + + return { ...one, ...two }; +} +let a1: A1 = { a: true }; +>a1 : Symbol(a1, Decl(objectSpreadScenarios.ts, 11, 3)) +>A1 : Symbol(A1, Decl(objectSpreadScenarios.ts, 0, 0)) +>a : Symbol(a, Decl(objectSpreadScenarios.ts, 11, 14)) + +let b1: B1 = { b: 101 }; +>b1 : Symbol(b1, Decl(objectSpreadScenarios.ts, 12, 3)) +>B1 : Symbol(B1, Decl(objectSpreadScenarios.ts, 0, 27)) +>b : Symbol(b, Decl(objectSpreadScenarios.ts, 12, 14)) + +a1 = override(a1, { a: false }); +>a1 : Symbol(a1, Decl(objectSpreadScenarios.ts, 11, 3)) +>override : Symbol(override, Decl(objectSpreadScenarios.ts, 1, 27)) +>a1 : Symbol(a1, Decl(objectSpreadScenarios.ts, 11, 3)) +>a : Symbol(a, Decl(objectSpreadScenarios.ts, 13, 19)) + +let host = { u: a1, update }; +>host : Symbol(host, Decl(objectSpreadScenarios.ts, 14, 3)) +>u : Symbol(u, Decl(objectSpreadScenarios.ts, 14, 12)) +>a1 : Symbol(a1, Decl(objectSpreadScenarios.ts, 11, 3)) +>update : Symbol(update, Decl(objectSpreadScenarios.ts, 14, 19)) + +host.update({ a: false }); +>host.update : Symbol(update, Decl(objectSpreadScenarios.ts, 14, 19)) +>host : Symbol(host, Decl(objectSpreadScenarios.ts, 14, 3)) +>update : Symbol(update, Decl(objectSpreadScenarios.ts, 14, 19)) +>a : Symbol(a, Decl(objectSpreadScenarios.ts, 15, 13)) + +let mixed = mixin(a1, b1); +>mixed : Symbol(mixed, Decl(objectSpreadScenarios.ts, 16, 3)) +>mixin : Symbol(mixin, Decl(objectSpreadScenarios.ts, 7, 1)) +>a1 : Symbol(a1, Decl(objectSpreadScenarios.ts, 11, 3)) +>b1 : Symbol(b1, Decl(objectSpreadScenarios.ts, 12, 3)) + diff --git a/tests/baselines/reference/objectSpreadScenarios.types b/tests/baselines/reference/objectSpreadScenarios.types new file mode 100644 index 00000000000..2d1aa47bd50 --- /dev/null +++ b/tests/baselines/reference/objectSpreadScenarios.types @@ -0,0 +1,107 @@ +=== tests/cases/conformance/types/spread/objectSpreadScenarios.ts === +interface A1 { a: boolean } +>A1 : A1 +>a : boolean + +interface B1 { b: number }; +>B1 : B1 +>b : number + +function override(initial: U, override: U): { ...U, ...U } { +>override : (initial: U, override: U) => { ...U } +>U : U +>initial : U +>U : U +>override : U +>U : U +>U : U +>U : U + + return { ...initial, ...override }; +>{ ...initial, ...override } : { ...U } +>initial : any +>override : any +} +function update(this: { u: { ...U } }, override: U): void { +>update : (this: { u: { ...U }; }, override: U) => void +>U : U +>this : { u: { ...U }; } +>u : { ...U } +>U : U +>override : U +>U : U + + this.u = { ...this.u, ...override }; +>this.u = { ...this.u, ...override } : { ...U } +>this.u : { ...U } +>this : { u: { ...U }; } +>u : { ...U } +>{ ...this.u, ...override } : { ...U } +>this.u : { ...U } +>this : { u: { ...U }; } +>u : { ...U } +>override : any +} +function mixin(one: T, two: U): { ...T, ...U } { +>mixin : (one: T, two: U) => { ...T; ...U } +>T : T +>U : U +>one : T +>T : T +>two : U +>U : U +>T : T +>U : U + + return { ...one, ...two }; +>{ ...one, ...two } : { ...T; ...U } +>one : any +>two : any +} +let a1: A1 = { a: true }; +>a1 : A1 +>A1 : A1 +>{ a: true } : { a: true; } +>a : boolean +>true : true + +let b1: B1 = { b: 101 }; +>b1 : B1 +>B1 : B1 +>{ b: 101 } : { b: number; } +>b : number +>101 : 101 + +a1 = override(a1, { a: false }); +>a1 = override(a1, { a: false }) : { a: boolean; } +>a1 : A1 +>override(a1, { a: false }) : { a: boolean; } +>override : (initial: U, override: U) => { ...U } +>a1 : A1 +>{ a: false } : { a: false; } +>a : boolean +>false : false + +let host = { u: a1, update }; +>host : { u: A1; update: (this: { u: { ...U }; }, override: U) => void; } +>{ u: a1, update } : { u: A1; update: (this: { u: { ...U }; }, override: U) => void; } +>u : A1 +>a1 : A1 +>update : (this: { u: { ...U }; }, override: U) => void + +host.update({ a: false }); +>host.update({ a: false }) : void +>host.update : (this: { u: { ...U }; }, override: U) => void +>host : { u: A1; update: (this: { u: { ...U }; }, override: U) => void; } +>update : (this: { u: { ...U }; }, override: U) => void +>{ a: false } : { a: false; } +>a : boolean +>false : false + +let mixed = mixin(a1, b1); +>mixed : { b: number; a: boolean; } +>mixin(a1, b1) : { b: number; a: boolean; } +>mixin : (one: T, two: U) => { ...T; ...U } +>a1 : A1 +>b1 : B1 + diff --git a/tests/baselines/reference/objectSpreadStrictNull.js b/tests/baselines/reference/objectSpreadStrictNull.js new file mode 100644 index 00000000000..84604d728cd --- /dev/null +++ b/tests/baselines/reference/objectSpreadStrictNull.js @@ -0,0 +1,43 @@ +//// [objectSpreadStrictNull.ts] + +function f( + definiteBoolean: { sn: boolean }, + definiteString: { sn: string }, + optionalString: { sn?: string }, + optionalNumber: { sn?: number }, + undefinedString: { sn: string | undefined }, + undefinedNumber: { sn: number | undefined }) { + // optional + let optionalUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; + let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; + let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; + + // undefined + let undefinedUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedNumber }; + let undefinedUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber }; + let allUndefined: { sn: string | number | undefined } = { ...undefinedString, ...undefinedNumber }; + + let undefinedWithOptionalContinues: { sn: string | number | boolean } = { ...definiteBoolean, ...undefinedString, ...optionalNumber }; +} + + +//// [objectSpreadStrictNull.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +function f(definiteBoolean, definiteString, optionalString, optionalNumber, undefinedString, undefinedNumber) { + // optional + var optionalUnionStops = __assign({}, definiteBoolean, definiteString, optionalNumber); + var optionalUnionDuplicates = __assign({}, definiteBoolean, definiteString, optionalString, optionalNumber); + var allOptional = __assign({}, optionalString, optionalNumber); + // undefined + var undefinedUnionStops = __assign({}, definiteBoolean, definiteString, undefinedNumber); + var undefinedUnionDuplicates = __assign({}, definiteBoolean, definiteString, undefinedString, undefinedNumber); + var allUndefined = __assign({}, undefinedString, undefinedNumber); + var undefinedWithOptionalContinues = __assign({}, definiteBoolean, undefinedString, optionalNumber); +} diff --git a/tests/baselines/reference/objectSpreadStrictNull.symbols b/tests/baselines/reference/objectSpreadStrictNull.symbols new file mode 100644 index 00000000000..85def473ce4 --- /dev/null +++ b/tests/baselines/reference/objectSpreadStrictNull.symbols @@ -0,0 +1,60 @@ +=== tests/cases/conformance/types/spread/objectSpreadStrictNull.ts === + +function f( +>f : Symbol(f, Decl(objectSpreadStrictNull.ts, 0, 0)) + + definiteBoolean: { sn: boolean }, +>definiteBoolean : Symbol(definiteBoolean, Decl(objectSpreadStrictNull.ts, 1, 11)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 2, 22)) + + definiteString: { sn: string }, +>definiteString : Symbol(definiteString, Decl(objectSpreadStrictNull.ts, 2, 37)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 3, 21)) + + optionalString: { sn?: string }, +>optionalString : Symbol(optionalString, Decl(objectSpreadStrictNull.ts, 3, 35)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 4, 21)) + + optionalNumber: { sn?: number }, +>optionalNumber : Symbol(optionalNumber, Decl(objectSpreadStrictNull.ts, 4, 36)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 5, 21)) + + undefinedString: { sn: string | undefined }, +>undefinedString : Symbol(undefinedString, Decl(objectSpreadStrictNull.ts, 5, 36)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 6, 22)) + + undefinedNumber: { sn: number | undefined }) { +>undefinedNumber : Symbol(undefinedNumber, Decl(objectSpreadStrictNull.ts, 6, 48)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 7, 22)) + + // optional + let optionalUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; +>optionalUnionStops : Symbol(optionalUnionStops, Decl(objectSpreadStrictNull.ts, 9, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 9, 29)) + + let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; +>optionalUnionDuplicates : Symbol(optionalUnionDuplicates, Decl(objectSpreadStrictNull.ts, 10, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 10, 34)) + + let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; +>allOptional : Symbol(allOptional, Decl(objectSpreadStrictNull.ts, 11, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 11, 22)) + + // undefined + let undefinedUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedNumber }; +>undefinedUnionStops : Symbol(undefinedUnionStops, Decl(objectSpreadStrictNull.ts, 14, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 14, 30)) + + let undefinedUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber }; +>undefinedUnionDuplicates : Symbol(undefinedUnionDuplicates, Decl(objectSpreadStrictNull.ts, 15, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 15, 35)) + + let allUndefined: { sn: string | number | undefined } = { ...undefinedString, ...undefinedNumber }; +>allUndefined : Symbol(allUndefined, Decl(objectSpreadStrictNull.ts, 16, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 16, 23)) + + let undefinedWithOptionalContinues: { sn: string | number | boolean } = { ...definiteBoolean, ...undefinedString, ...optionalNumber }; +>undefinedWithOptionalContinues : Symbol(undefinedWithOptionalContinues, Decl(objectSpreadStrictNull.ts, 18, 7)) +>sn : Symbol(sn, Decl(objectSpreadStrictNull.ts, 18, 41)) +} + diff --git a/tests/baselines/reference/objectSpreadStrictNull.types b/tests/baselines/reference/objectSpreadStrictNull.types new file mode 100644 index 00000000000..a91295b2bca --- /dev/null +++ b/tests/baselines/reference/objectSpreadStrictNull.types @@ -0,0 +1,88 @@ +=== tests/cases/conformance/types/spread/objectSpreadStrictNull.ts === + +function f( +>f : (definiteBoolean: { sn: boolean; }, definiteString: { sn: string; }, optionalString: { sn?: string | undefined; }, optionalNumber: { sn?: number | undefined; }, undefinedString: { sn: string | undefined; }, undefinedNumber: { sn: number | undefined; }) => void + + definiteBoolean: { sn: boolean }, +>definiteBoolean : { sn: boolean; } +>sn : boolean + + definiteString: { sn: string }, +>definiteString : { sn: string; } +>sn : string + + optionalString: { sn?: string }, +>optionalString : { sn?: string | undefined; } +>sn : string | undefined + + optionalNumber: { sn?: number }, +>optionalNumber : { sn?: number | undefined; } +>sn : number | undefined + + undefinedString: { sn: string | undefined }, +>undefinedString : { sn: string | undefined; } +>sn : string | undefined + + undefinedNumber: { sn: number | undefined }) { +>undefinedNumber : { sn: number | undefined; } +>sn : number | undefined + + // optional + let optionalUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; +>optionalUnionStops : { sn: string | number; } +>sn : string | number +>{ ...definiteBoolean, ...definiteString, ...optionalNumber } : { sn: string | number; } +>definiteBoolean : any +>definiteString : any +>optionalNumber : any + + let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; +>optionalUnionDuplicates : { sn: string | number; } +>sn : string | number +>{ ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber } : { sn: string | number; } +>definiteBoolean : any +>definiteString : any +>optionalString : any +>optionalNumber : any + + let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; +>allOptional : { sn?: string | number | undefined; } +>sn : string | number | undefined +>{ ...optionalString, ...optionalNumber } : { sn?: string | number | undefined; } +>optionalString : any +>optionalNumber : any + + // undefined + let undefinedUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedNumber }; +>undefinedUnionStops : { sn: string | number; } +>sn : string | number +>{ ...definiteBoolean, ...definiteString, ...undefinedNumber } : { sn: string | number; } +>definiteBoolean : any +>definiteString : any +>undefinedNumber : any + + let undefinedUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber }; +>undefinedUnionDuplicates : { sn: string | number; } +>sn : string | number +>{ ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber } : { sn: string | number; } +>definiteBoolean : any +>definiteString : any +>undefinedString : any +>undefinedNumber : any + + let allUndefined: { sn: string | number | undefined } = { ...undefinedString, ...undefinedNumber }; +>allUndefined : { sn: string | number | undefined; } +>sn : string | number | undefined +>{ ...undefinedString, ...undefinedNumber } : { sn: string | number | undefined; } +>undefinedString : any +>undefinedNumber : any + + let undefinedWithOptionalContinues: { sn: string | number | boolean } = { ...definiteBoolean, ...undefinedString, ...optionalNumber }; +>undefinedWithOptionalContinues : { sn: string | number | boolean; } +>sn : string | number | boolean +>{ ...definiteBoolean, ...undefinedString, ...optionalNumber } : { sn: string | number | boolean; } +>definiteBoolean : any +>undefinedString : any +>optionalNumber : any +} + diff --git a/tests/baselines/reference/objectSpreadUnion.js b/tests/baselines/reference/objectSpreadUnion.js new file mode 100644 index 00000000000..b3a114c7722 --- /dev/null +++ b/tests/baselines/reference/objectSpreadUnion.js @@ -0,0 +1,52 @@ +//// [objectSpreadUnion.ts] +// concrete types work +interface A1 { a: number } +interface A2 { a: string } +let a12: A1 | A2; +let result = { ...a12 }; +let sn: number | string = result.a; +let assignable: { ...(A1 | A2) } = result; + +function tripleUnion(t: T, u: U, v: V): void { + let tuv: T | U | V; + let result = { ...tuv, id: 'foo' }; + let expected: { ...T, id: string } | { ...U, id: string } | { ...V, id: string } = result; + let assignable: { ...(T | U | V), id: string } = result; +} +function iteratedDoubleUnion(t: T, u: U, v: V): void { + let tu: T | U; + let uv: U | V; + let result = { ...tu, ...uv, id: 'bar' }; + let expected: { ...T, ...U, id: string } | { ...T, ...V, id: string } | { ...U, id: string } | { ...U, ...V, id: string }; + let assignable: { ...(T | U), ...(U | V), id: string } = result; +} + + + + +//// [objectSpreadUnion.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +var a12; +var result = __assign({}, a12); +var sn = result.a; +var assignable = result; +function tripleUnion(t, u, v) { + var tuv; + var result = __assign({}, tuv, { id: 'foo' }); + var expected = result; + var assignable = result; +} +function iteratedDoubleUnion(t, u, v) { + var tu; + var uv; + var result = __assign({}, tu, uv, { id: 'bar' }); + var expected; + var assignable = result; +} diff --git a/tests/baselines/reference/objectSpreadUnion.symbols b/tests/baselines/reference/objectSpreadUnion.symbols new file mode 100644 index 00000000000..d630fde518b --- /dev/null +++ b/tests/baselines/reference/objectSpreadUnion.symbols @@ -0,0 +1,122 @@ +=== tests/cases/conformance/types/spread/objectSpreadUnion.ts === +// concrete types work +interface A1 { a: number } +>A1 : Symbol(A1, Decl(objectSpreadUnion.ts, 0, 0)) +>a : Symbol(A1.a, Decl(objectSpreadUnion.ts, 1, 14)) + +interface A2 { a: string } +>A2 : Symbol(A2, Decl(objectSpreadUnion.ts, 1, 26)) +>a : Symbol(A2.a, Decl(objectSpreadUnion.ts, 2, 14)) + +let a12: A1 | A2; +>a12 : Symbol(a12, Decl(objectSpreadUnion.ts, 3, 3)) +>A1 : Symbol(A1, Decl(objectSpreadUnion.ts, 0, 0)) +>A2 : Symbol(A2, Decl(objectSpreadUnion.ts, 1, 26)) + +let result = { ...a12 }; +>result : Symbol(result, Decl(objectSpreadUnion.ts, 4, 3)) + +let sn: number | string = result.a; +>sn : Symbol(sn, Decl(objectSpreadUnion.ts, 5, 3)) +>result.a : Symbol(a, Decl(objectSpreadUnion.ts, 1, 14), Decl(objectSpreadUnion.ts, 2, 14)) +>result : Symbol(result, Decl(objectSpreadUnion.ts, 4, 3)) +>a : Symbol(a, Decl(objectSpreadUnion.ts, 1, 14), Decl(objectSpreadUnion.ts, 2, 14)) + +let assignable: { ...(A1 | A2) } = result; +>assignable : Symbol(assignable, Decl(objectSpreadUnion.ts, 6, 3)) +>A1 : Symbol(A1, Decl(objectSpreadUnion.ts, 0, 0)) +>A2 : Symbol(A2, Decl(objectSpreadUnion.ts, 1, 26)) +>result : Symbol(result, Decl(objectSpreadUnion.ts, 4, 3)) + +function tripleUnion(t: T, u: U, v: V): void { +>tripleUnion : Symbol(tripleUnion, Decl(objectSpreadUnion.ts, 6, 42)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 8, 21)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 8, 23)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 8, 26)) +>t : Symbol(t, Decl(objectSpreadUnion.ts, 8, 30)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 8, 21)) +>u : Symbol(u, Decl(objectSpreadUnion.ts, 8, 35)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 8, 23)) +>v : Symbol(v, Decl(objectSpreadUnion.ts, 8, 41)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 8, 26)) + + let tuv: T | U | V; +>tuv : Symbol(tuv, Decl(objectSpreadUnion.ts, 9, 7)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 8, 21)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 8, 23)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 8, 26)) + + let result = { ...tuv, id: 'foo' }; +>result : Symbol(result, Decl(objectSpreadUnion.ts, 10, 7)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 10, 26)) + + let expected: { ...T, id: string } | { ...U, id: string } | { ...V, id: string } = result; +>expected : Symbol(expected, Decl(objectSpreadUnion.ts, 11, 7)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 8, 21)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 11, 25)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 8, 23)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 11, 48)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 8, 26)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 11, 71)) +>result : Symbol(result, Decl(objectSpreadUnion.ts, 10, 7)) + + let assignable: { ...(T | U | V), id: string } = result; +>assignable : Symbol(assignable, Decl(objectSpreadUnion.ts, 12, 7)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 8, 21)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 8, 23)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 8, 26)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 12, 37)) +>result : Symbol(result, Decl(objectSpreadUnion.ts, 10, 7)) +} +function iteratedDoubleUnion(t: T, u: U, v: V): void { +>iteratedDoubleUnion : Symbol(iteratedDoubleUnion, Decl(objectSpreadUnion.ts, 13, 1)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 14, 29)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 14, 34)) +>t : Symbol(t, Decl(objectSpreadUnion.ts, 14, 38)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 14, 29)) +>u : Symbol(u, Decl(objectSpreadUnion.ts, 14, 43)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>v : Symbol(v, Decl(objectSpreadUnion.ts, 14, 49)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 14, 34)) + + let tu: T | U; +>tu : Symbol(tu, Decl(objectSpreadUnion.ts, 15, 7)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 14, 29)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) + + let uv: U | V; +>uv : Symbol(uv, Decl(objectSpreadUnion.ts, 16, 7)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 14, 34)) + + let result = { ...tu, ...uv, id: 'bar' }; +>result : Symbol(result, Decl(objectSpreadUnion.ts, 17, 7)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 17, 32)) + + let expected: { ...T, ...U, id: string } | { ...T, ...V, id: string } | { ...U, id: string } | { ...U, ...V, id: string }; +>expected : Symbol(expected, Decl(objectSpreadUnion.ts, 18, 7)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 14, 29)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 18, 31)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 14, 29)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 14, 34)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 18, 60)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 18, 83)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 14, 34)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 18, 112)) + + let assignable: { ...(T | U), ...(U | V), id: string } = result; +>assignable : Symbol(assignable, Decl(objectSpreadUnion.ts, 19, 7)) +>T : Symbol(T, Decl(objectSpreadUnion.ts, 14, 29)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>U : Symbol(U, Decl(objectSpreadUnion.ts, 14, 31)) +>V : Symbol(V, Decl(objectSpreadUnion.ts, 14, 34)) +>id : Symbol(id, Decl(objectSpreadUnion.ts, 19, 45)) +>result : Symbol(result, Decl(objectSpreadUnion.ts, 17, 7)) +} + + + diff --git a/tests/baselines/reference/objectSpreadUnion.types b/tests/baselines/reference/objectSpreadUnion.types new file mode 100644 index 00000000000..20633295acb --- /dev/null +++ b/tests/baselines/reference/objectSpreadUnion.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/types/spread/objectSpreadUnion.ts === +// concrete types work +interface A1 { a: number } +>A1 : A1 +>a : number + +interface A2 { a: string } +>A2 : A2 +>a : string + +let a12: A1 | A2; +>a12 : A1 | A2 +>A1 : A1 +>A2 : A2 + +let result = { ...a12 }; +>result : { a: number; } | { a: string; } +>{ ...a12 } : { a: number; } | { a: string; } +>a12 : any + +let sn: number | string = result.a; +>sn : string | number +>result.a : string | number +>result : { a: number; } | { a: string; } +>a : string | number + +let assignable: { ...(A1 | A2) } = result; +>assignable : { a: number; } | { a: string; } +>A1 : A1 +>A2 : A2 +>result : { a: number; } | { a: string; } + +function tripleUnion(t: T, u: U, v: V): void { +>tripleUnion : (t: T, u: U, v: V) => void +>T : T +>U : U +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + + let tuv: T | U | V; +>tuv : T | U | V +>T : T +>U : U +>V : V + + let result = { ...tuv, id: 'foo' }; +>result : { ...T; id: string; } | { ...U; id: string; } | { ...V; id: string; } +>{ ...tuv, id: 'foo' } : { ...T; id: string; } | { ...U; id: string; } | { ...V; id: string; } +>tuv : any +>id : string +>'foo' : "foo" + + let expected: { ...T, id: string } | { ...U, id: string } | { ...V, id: string } = result; +>expected : { ...T; id: string; } | { ...U; id: string; } | { ...V; id: string; } +>T : T +>id : string +>U : U +>id : string +>V : V +>id : string +>result : { ...T; id: string; } | { ...U; id: string; } | { ...V; id: string; } + + let assignable: { ...(T | U | V), id: string } = result; +>assignable : { ...T; id: string; } | { ...U; id: string; } | { ...V; id: string; } +>T : T +>U : U +>V : V +>id : string +>result : { ...T; id: string; } | { ...U; id: string; } | { ...V; id: string; } +} +function iteratedDoubleUnion(t: T, u: U, v: V): void { +>iteratedDoubleUnion : (t: T, u: U, v: V) => void +>T : T +>U : U +>V : V +>t : T +>T : T +>u : U +>U : U +>v : V +>V : V + + let tu: T | U; +>tu : T | U +>T : T +>U : U + + let uv: U | V; +>uv : U | V +>U : U +>V : V + + let result = { ...tu, ...uv, id: 'bar' }; +>result : { ...U; id: string; } | { ...T; ...U; id: string; } | { ...T; ...V; id: string; } | { ...U; ...V; id: string; } +>{ ...tu, ...uv, id: 'bar' } : { ...U; id: string; } | { ...T; ...U; id: string; } | { ...T; ...V; id: string; } | { ...U; ...V; id: string; } +>tu : any +>uv : any +>id : string +>'bar' : "bar" + + let expected: { ...T, ...U, id: string } | { ...T, ...V, id: string } | { ...U, id: string } | { ...U, ...V, id: string }; +>expected : { ...T; ...U; id: string; } | { ...T; ...V; id: string; } | { ...U; id: string; } | { ...U; ...V; id: string; } +>T : T +>U : U +>id : string +>T : T +>V : V +>id : string +>U : U +>id : string +>U : U +>V : V +>id : string + + let assignable: { ...(T | U), ...(U | V), id: string } = result; +>assignable : { ...U; id: string; } | { ...T; ...U; id: string; } | { ...T; ...V; id: string; } | { ...U; ...V; id: string; } +>T : T +>U : U +>U : U +>V : V +>id : string +>result : { ...U; id: string; } | { ...T; ...U; id: string; } | { ...T; ...V; id: string; } | { ...U; ...V; id: string; } +} + + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json index ab7210d7d02..f468d864eef 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json @@ -33,12 +33,8 @@ "File 'c:/root/folder2/node_modules/file4/index.ts' does not exist.", "File 'c:/root/folder2/node_modules/file4/index.tsx' does not exist.", "File 'c:/root/folder2/node_modules/file4/index.d.ts' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4.ts' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4.tsx' does not exist.", "File 'c:/root/folder2/node_modules/@types/file4.d.ts' does not exist.", "File 'c:/root/folder2/node_modules/@types/file4/package.json' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4/index.ts' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/folder2/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/root/node_modules/file4.ts' does not exist.", "File 'c:/root/node_modules/file4.tsx' does not exist.", @@ -47,12 +43,8 @@ "File 'c:/root/node_modules/file4/index.ts' does not exist.", "File 'c:/root/node_modules/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4.d.ts' does not exist.", "File 'c:/root/node_modules/@types/file4/package.json' does not exist.", - "File 'c:/root/node_modules/@types/file4/index.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/node_modules/file4.ts' does not exist.", "File 'c:/node_modules/file4.tsx' does not exist.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json index ab7210d7d02..f468d864eef 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json @@ -33,12 +33,8 @@ "File 'c:/root/folder2/node_modules/file4/index.ts' does not exist.", "File 'c:/root/folder2/node_modules/file4/index.tsx' does not exist.", "File 'c:/root/folder2/node_modules/file4/index.d.ts' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4.ts' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4.tsx' does not exist.", "File 'c:/root/folder2/node_modules/@types/file4.d.ts' does not exist.", "File 'c:/root/folder2/node_modules/@types/file4/package.json' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4/index.ts' does not exist.", - "File 'c:/root/folder2/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/folder2/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/root/node_modules/file4.ts' does not exist.", "File 'c:/root/node_modules/file4.tsx' does not exist.", @@ -47,12 +43,8 @@ "File 'c:/root/node_modules/file4/index.ts' does not exist.", "File 'c:/root/node_modules/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4.d.ts' does not exist.", "File 'c:/root/node_modules/@types/file4/package.json' does not exist.", - "File 'c:/root/node_modules/@types/file4/index.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/node_modules/file4.ts' does not exist.", "File 'c:/node_modules/file4.tsx' does not exist.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json index 2efeefa24e5..92a98a1067c 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json @@ -75,12 +75,8 @@ "File 'c:/root/folder1/node_modules/file4/index.ts' does not exist.", "File 'c:/root/folder1/node_modules/file4/index.tsx' does not exist.", "File 'c:/root/folder1/node_modules/file4/index.d.ts' does not exist.", - "File 'c:/root/folder1/node_modules/@types/file4.ts' does not exist.", - "File 'c:/root/folder1/node_modules/@types/file4.tsx' does not exist.", "File 'c:/root/folder1/node_modules/@types/file4.d.ts' does not exist.", "File 'c:/root/folder1/node_modules/@types/file4/package.json' does not exist.", - "File 'c:/root/folder1/node_modules/@types/file4/index.ts' does not exist.", - "File 'c:/root/folder1/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/folder1/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/root/node_modules/file4.ts' does not exist.", "File 'c:/root/node_modules/file4.tsx' does not exist.", @@ -89,12 +85,8 @@ "File 'c:/root/node_modules/file4/index.ts' does not exist.", "File 'c:/root/node_modules/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4.d.ts' does not exist.", "File 'c:/root/node_modules/@types/file4/package.json' does not exist.", - "File 'c:/root/node_modules/@types/file4/index.ts' does not exist.", - "File 'c:/root/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/node_modules/file4.ts' exist - use it as a name resolution result.", "Resolving real path for 'c:/node_modules/file4.ts', result 'c:/node_modules/file4.ts'", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json index 48633c85e3b..cc33d8d1c37 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json @@ -51,12 +51,8 @@ "File 'c:/root/src/node_modules/module3/index.ts' does not exist.", "File 'c:/root/src/node_modules/module3/index.tsx' does not exist.", "File 'c:/root/src/node_modules/module3/index.d.ts' does not exist.", - "File 'c:/root/src/node_modules/@types/module3.ts' does not exist.", - "File 'c:/root/src/node_modules/@types/module3.tsx' does not exist.", "File 'c:/root/src/node_modules/@types/module3.d.ts' does not exist.", "File 'c:/root/src/node_modules/@types/module3/package.json' does not exist.", - "File 'c:/root/src/node_modules/@types/module3/index.ts' does not exist.", - "File 'c:/root/src/node_modules/@types/module3/index.tsx' does not exist.", "File 'c:/root/src/node_modules/@types/module3/index.d.ts' does not exist.", "File 'c:/root/node_modules/module3.ts' does not exist.", "File 'c:/root/node_modules/module3.tsx' does not exist.", @@ -65,12 +61,8 @@ "File 'c:/root/node_modules/module3/index.ts' does not exist.", "File 'c:/root/node_modules/module3/index.tsx' does not exist.", "File 'c:/root/node_modules/module3/index.d.ts' does not exist.", - "File 'c:/root/node_modules/@types/module3.ts' does not exist.", - "File 'c:/root/node_modules/@types/module3.tsx' does not exist.", "File 'c:/root/node_modules/@types/module3.d.ts' does not exist.", "File 'c:/root/node_modules/@types/module3/package.json' does not exist.", - "File 'c:/root/node_modules/@types/module3/index.ts' does not exist.", - "File 'c:/root/node_modules/@types/module3/index.tsx' does not exist.", "File 'c:/root/node_modules/@types/module3/index.d.ts' does not exist.", "File 'c:/node_modules/module3.ts' does not exist.", "File 'c:/node_modules/module3.tsx' does not exist.", diff --git a/tests/baselines/reference/restElementMustBeLast.errors.txt b/tests/baselines/reference/restElementMustBeLast.errors.txt index 269d984bc00..5eb5a4cd208 100644 --- a/tests/baselines/reference/restElementMustBeLast.errors.txt +++ b/tests/baselines/reference/restElementMustBeLast.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/destructuring/restElementMustBeLast.ts(1,9): error TS2462: A rest element must be last in an array destructuring pattern -tests/cases/conformance/es6/destructuring/restElementMustBeLast.ts(2,2): error TS2462: A rest element must be last in an array destructuring pattern +tests/cases/conformance/types/rest/restElementMustBeLast.ts(1,9): error TS2462: A rest element must be last in a destructuring pattern +tests/cases/conformance/types/rest/restElementMustBeLast.ts(2,2): error TS2462: A rest element must be last in a destructuring pattern -==== tests/cases/conformance/es6/destructuring/restElementMustBeLast.ts (2 errors) ==== +==== tests/cases/conformance/types/rest/restElementMustBeLast.ts (2 errors) ==== var [...a, x] = [1, 2, 3]; // Error, rest must be last element ~ -!!! error TS2462: A rest element must be last in an array destructuring pattern +!!! error TS2462: A rest element must be last in a destructuring pattern [...a, x] = [1, 2, 3]; // Error, rest must be last element ~~~~ -!!! error TS2462: A rest element must be last in an array destructuring pattern +!!! error TS2462: A rest element must be last in a destructuring pattern \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js index 9f7a70699bd..8355d61d9c3 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js +++ b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js @@ -194,13 +194,13 @@ for (_b = getRobot(), _c = _b.name, nameA = _c === void 0 ? "noName" : _c, _b, i for (_d = { name: "trimmer", skill: "trimming" }, _e = _d.name, nameA = _e === void 0 ? "noName" : _e, _d, i = 0; i < 1; i++) { console.log(nameA); } -for (_f = multiRobot.skills, _g = _f === void 0 ? { primary: "none", secondary: "none" } : _f, _h = _g.primary, primaryA = _h === void 0 ? "primary" : _h, _j = _g.secondary, secondaryA = _j === void 0 ? "secondary" : _j, multiRobot, i = 0; i < 1; i++) { +for (_f = multiRobot.skills, _g = _f === void 0 ? { primary: "none", secondary: "none" } : _f, _h = _g.primary, primaryA = _h === void 0 ? "primary" : _h, _j = _g.secondary, secondaryA = _j === void 0 ? "secondary" : _j, multiRobot, multiRobot, i = 0; i < 1; i++) { console.log(primaryA); } -for (_k = getMultiRobot(), _l = _k.skills, _m = _l === void 0 ? { primary: "none", secondary: "none" } : _l, _o = _m.primary, primaryA = _o === void 0 ? "primary" : _o, _p = _m.secondary, secondaryA = _p === void 0 ? "secondary" : _p, _k, i = 0; i < 1; i++) { +for (_k = getMultiRobot(), (_l = _k.skills, _m = _l === void 0 ? { primary: "none", secondary: "none" } : _l, _o = _m.primary, primaryA = _o === void 0 ? "primary" : _o, _p = _m.secondary, secondaryA = _p === void 0 ? "secondary" : _p, _k), _k, i = 0; i < 1; i++) { console.log(primaryA); } -for (_q = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _r = _q.skills, _s = _r === void 0 ? { primary: "none", secondary: "none" } : _r, _t = _s.primary, primaryA = _t === void 0 ? "primary" : _t, _u = _s.secondary, secondaryA = _u === void 0 ? "secondary" : _u, _q, +for (_q = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_r = _q.skills, _s = _r === void 0 ? { primary: "none", secondary: "none" } : _r, _t = _s.primary, primaryA = _t === void 0 ? "primary" : _t, _u = _s.secondary, secondaryA = _u === void 0 ? "secondary" : _u, _q), _q, i = 0; i < 1; i++) { console.log(primaryA); } @@ -213,13 +213,13 @@ for (_w = getRobot(), _x = _w.name, name = _x === void 0 ? "noName" : _x, _w, i for (_y = { name: "trimmer", skill: "trimming" }, _z = _y.name, name = _z === void 0 ? "noName" : _z, _y, i = 0; i < 1; i++) { console.log(nameA); } -for (_0 = multiRobot.skills, _1 = _0 === void 0 ? { primary: "none", secondary: "none" } : _0, _2 = _1.primary, primary = _2 === void 0 ? "primary" : _2, _3 = _1.secondary, secondary = _3 === void 0 ? "secondary" : _3, multiRobot, i = 0; i < 1; i++) { +for (_0 = multiRobot.skills, _1 = _0 === void 0 ? { primary: "none", secondary: "none" } : _0, _2 = _1.primary, primary = _2 === void 0 ? "primary" : _2, _3 = _1.secondary, secondary = _3 === void 0 ? "secondary" : _3, multiRobot, multiRobot, i = 0; i < 1; i++) { console.log(primaryA); } -for (_4 = getMultiRobot(), _5 = _4.skills, _6 = _5 === void 0 ? { primary: "none", secondary: "none" } : _5, _7 = _6.primary, primary = _7 === void 0 ? "primary" : _7, _8 = _6.secondary, secondary = _8 === void 0 ? "secondary" : _8, _4, i = 0; i < 1; i++) { +for (_4 = getMultiRobot(), (_5 = _4.skills, _6 = _5 === void 0 ? { primary: "none", secondary: "none" } : _5, _7 = _6.primary, primary = _7 === void 0 ? "primary" : _7, _8 = _6.secondary, secondary = _8 === void 0 ? "secondary" : _8, _4), _4, i = 0; i < 1; i++) { console.log(primaryA); } -for (_9 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _10 = _9.skills, _11 = _10 === void 0 ? { primary: "none", secondary: "none" } : _10, _12 = _11.primary, primary = _12 === void 0 ? "primary" : _12, _13 = _11.secondary, secondary = _13 === void 0 ? "secondary" : _13, _9, +for (_9 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_10 = _9.skills, _11 = _10 === void 0 ? { primary: "none", secondary: "none" } : _10, _12 = _11.primary, primary = _12 === void 0 ? "primary" : _12, _13 = _11.secondary, secondary = _13 === void 0 ? "secondary" : _13, _9), _9, i = 0; i < 1; i++) { console.log(primaryA); } @@ -232,13 +232,13 @@ for (_16 = getRobot(), _17 = _16.name, nameA = _17 === void 0 ? "noName" : _17, for (_19 = { name: "trimmer", skill: "trimming" }, _20 = _19.name, nameA = _20 === void 0 ? "noName" : _20, _21 = _19.skill, skillA = _21 === void 0 ? "skill" : _21, _19, i = 0; i < 1; i++) { console.log(nameA); } -for (_22 = multiRobot.name, nameA = _22 === void 0 ? "noName" : _22, _23 = multiRobot.skills, _24 = _23 === void 0 ? { primary: "none", secondary: "none" } : _23, _25 = _24.primary, primaryA = _25 === void 0 ? "primary" : _25, _26 = _24.secondary, secondaryA = _26 === void 0 ? "secondary" : _26, multiRobot, i = 0; i < 1; i++) { +for (_22 = multiRobot.name, nameA = _22 === void 0 ? "noName" : _22, _23 = multiRobot.skills, _24 = _23 === void 0 ? { primary: "none", secondary: "none" } : _23, _25 = _24.primary, primaryA = _25 === void 0 ? "primary" : _25, _26 = _24.secondary, secondaryA = _26 === void 0 ? "secondary" : _26, multiRobot, multiRobot, i = 0; i < 1; i++) { console.log(primaryA); } -for (_27 = getMultiRobot(), _28 = _27.name, nameA = _28 === void 0 ? "noName" : _28, _29 = _27.skills, _30 = _29 === void 0 ? { primary: "none", secondary: "none" } : _29, _31 = _30.primary, primaryA = _31 === void 0 ? "primary" : _31, _32 = _30.secondary, secondaryA = _32 === void 0 ? "secondary" : _32, _27, i = 0; i < 1; i++) { +for (_27 = getMultiRobot(), (_28 = _27.name, nameA = _28 === void 0 ? "noName" : _28, _29 = _27.skills, _30 = _29 === void 0 ? { primary: "none", secondary: "none" } : _29, _31 = _30.primary, primaryA = _31 === void 0 ? "primary" : _31, _32 = _30.secondary, secondaryA = _32 === void 0 ? "secondary" : _32, _27), _27, i = 0; i < 1; i++) { console.log(primaryA); } -for (_33 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _34 = _33.name, nameA = _34 === void 0 ? "noName" : _34, _35 = _33.skills, _36 = _35 === void 0 ? { primary: "none", secondary: "none" } : _35, _37 = _36.primary, primaryA = _37 === void 0 ? "primary" : _37, _38 = _36.secondary, secondaryA = _38 === void 0 ? "secondary" : _38, _33, +for (_33 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_34 = _33.name, nameA = _34 === void 0 ? "noName" : _34, _35 = _33.skills, _36 = _35 === void 0 ? { primary: "none", secondary: "none" } : _35, _37 = _36.primary, primaryA = _37 === void 0 ? "primary" : _37, _38 = _36.secondary, secondaryA = _38 === void 0 ? "secondary" : _38, _33), _33, i = 0; i < 1; i++) { console.log(primaryA); } @@ -251,15 +251,16 @@ for (_41 = getRobot(), _42 = _41.name, name = _42 === void 0 ? "noName" : _42, _ for (_44 = { name: "trimmer", skill: "trimming" }, _45 = _44.name, name = _45 === void 0 ? "noName" : _45, _46 = _44.skill, skill = _46 === void 0 ? "skill" : _46, _44, i = 0; i < 1; i++) { console.log(nameA); } -for (_47 = multiRobot.name, name = _47 === void 0 ? "noName" : _47, _48 = multiRobot.skills, _49 = _48 === void 0 ? { primary: "none", secondary: "none" } : _48, _50 = _49.primary, primary = _50 === void 0 ? "primary" : _50, _51 = _49.secondary, secondary = _51 === void 0 ? "secondary" : _51, multiRobot, i = 0; i < 1; i++) { +for (_47 = multiRobot.name, name = _47 === void 0 ? "noName" : _47, _48 = multiRobot.skills, _49 = _48 === void 0 ? { primary: "none", secondary: "none" } : _48, _50 = _49.primary, primary = _50 === void 0 ? "primary" : _50, _51 = _49.secondary, secondary = _51 === void 0 ? "secondary" : _51, multiRobot, multiRobot, i = 0; i < 1; i++) { console.log(primaryA); } -for (_52 = getMultiRobot(), _53 = _52.name, name = _53 === void 0 ? "noName" : _53, _54 = _52.skills, _55 = _54 === void 0 ? { primary: "none", secondary: "none" } : _54, _56 = _55.primary, primary = _56 === void 0 ? "primary" : _56, _57 = _55.secondary, secondary = _57 === void 0 ? "secondary" : _57, _52, i = 0; i < 1; i++) { +for (_52 = getMultiRobot(), (_53 = _52.name, name = _53 === void 0 ? "noName" : _53, _54 = _52.skills, _55 = _54 === void 0 ? { primary: "none", secondary: "none" } : _54, _56 = _55.primary, primary = _56 === void 0 ? "primary" : _56, _57 = _55.secondary, secondary = _57 === void 0 ? "secondary" : _57, _52), _52, i = 0; i < 1; i++) { console.log(primaryA); } -for (_58 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _59 = _58.name, name = _59 === void 0 ? "noName" : _59, _60 = _58.skills, _61 = _60 === void 0 ? { primary: "none", secondary: "none" } : _60, _62 = _61.primary, primary = _62 === void 0 ? "primary" : _62, _63 = _61.secondary, secondary = _63 === void 0 ? "secondary" : _63, _58, +for (_58 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_59 = _58.name, name = _59 === void 0 ? "noName" : _59, _60 = _58.skills, _61 = _60 === void 0 ? { primary: "none", secondary: "none" } : _60, _62 = _61.primary, primary = _62 === void 0 ? "primary" : _62, _63 = _61.secondary, secondary = _63 === void 0 ? "secondary" : _63, _58), _58, i = 0; i < 1; i++) { console.log(primaryA); } -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; +var _k, _q, _4, _9, _27, _33, _52, _58; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _l, _m, _o, _p, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _5, _6, _7, _8, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _28, _29, _30, _31, _32, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _53, _54, _55, _56, _57, _59, _60, _61, _62, _63; //# sourceMappingURL=sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map index dd248e89944..56f8aa0f607 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map +++ b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map] -{"version":3,"file":"sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js","sourceRoot":"","sources":["sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts"],"names":[],"mappings":"AAgBA,IAAI,KAAK,GAAU,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACtD,IAAI,UAAU,GAAe,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;AACjG;IACI,MAAM,CAAC,KAAK,CAAC;AACjB,CAAC;AACD;IACI,MAAM,CAAC,UAAU,CAAC;AACtB,CAAC;AAED,IAAI,KAAa,EAAE,QAAgB,EAAE,UAAkB,EAAE,CAAS,EAAE,MAAc,CAAC;AACnF,IAAI,IAAY,EAAE,OAAe,EAAE,SAAiB,EAAE,KAAa,CAAC;AAEpE,GAAG,CAAC,CAAE,eAAsB,EAAtB,qCAAsB,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,eAAsC,EAArC,YAAsB,EAAtB,qCAAsB,MAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,2CAAyE,EAAxE,YAAsB,EAAtB,qCAAsB,MAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,sBAG0C,EAH1C,gEAG0C,EAFtC,eAA6B,EAA7B,yCAA6B,EAC7B,iBAAmC,EAAnC,6CAAmC,EAEvC,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,oBAKc,EAJf,cAG0C,EAH1C,gEAG0C,EAFtC,eAA6B,EAA7B,yCAA6B,EAC7B,iBAAmC,EAAnC,6CAAmC,MAEtB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,8EAKoF,EAJrF,cAG0C,EAH1C,gEAG0C,EAFtC,eAA6B,EAA7B,yCAA6B,EAC7B,iBAAmC,EAAnC,6CAAmC;IAGvC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,GAAG,CAAC,CAAG,eAAe,EAAf,oCAAe,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,eAAgC,EAA9B,YAAe,EAAf,oCAAe,MAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,2CAAmE,EAAjE,YAAe,EAAf,oCAAe,MAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC1F,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,sBAG0C,EAH1C,gEAG0C,EAFtC,eAAmB,EAAnB,wCAAmB,EACnB,iBAAuB,EAAvB,4CAAuB,EAE3B,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,oBAKc,EAJf,cAG0C,EAH1C,gEAG0C,EAFtC,eAAmB,EAAnB,wCAAmB,EACnB,iBAAuB,EAAvB,4CAAuB,MAEV,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,8EAKoF,EAJrF,eAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB;IAG3B,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAGD,GAAG,CAAC,CAAE,gBAAsB,EAAtB,uCAAsB,EAAE,iBAAuB,EAAvB,uCAAuB,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,gBAA+D,EAA9D,cAAsB,EAAtB,uCAAsB,EAAE,eAAuB,EAAvB,uCAAuB,OAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACtF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,4CAAkG,EAAjG,cAAsB,EAAtB,uCAAsB,EAAE,eAAuB,EAAvB,uCAAuB,OAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACzH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,qBAAsB,EAAtB,uCAAsB,EACtB,uBAG0C,EAH1C,mEAG0C,EAFtC,iBAA6B,EAA7B,2CAA6B,EAC7B,mBAAmC,EAAnC,+CAAmC,EAEvC,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,qBAMc,EALf,cAAsB,EAAtB,uCAAsB,EACtB,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAA6B,EAA7B,2CAA6B,EAC7B,mBAAmC,EAAnC,+CAAmC,OAEtB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,+EAMoF,EALrF,cAAsB,EAAtB,uCAAsB,EACtB,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAA6B,EAA7B,2CAA6B,EAC7B,mBAAmC,EAAnC,+CAAmC;IAGvC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,GAAG,CAAC,CAAG,gBAAe,EAAf,sCAAe,EAAE,iBAAe,EAAf,sCAAe,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,gBAAiD,EAA/C,cAAe,EAAf,sCAAe,EAAE,eAAe,EAAf,sCAAe,OAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,4CAAoF,EAAlF,cAAe,EAAf,sCAAe,EAAE,eAAe,EAAf,sCAAe,OAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC3G,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,qBAAe,EAAf,sCAAe,EACf,uBAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB,EAE3B,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,qBAMc,EALf,cAAe,EAAf,sCAAe,EACf,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB,OAEV,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,+EAMoF,EALrF,cAAe,EAAf,sCAAe,EACf,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB;IAG3B,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js","sourceRoot":"","sources":["sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts"],"names":[],"mappings":"AAgBA,IAAI,KAAK,GAAU,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACtD,IAAI,UAAU,GAAe,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;AACjG;IACI,MAAM,CAAC,KAAK,CAAC;AACjB,CAAC;AACD;IACI,MAAM,CAAC,UAAU,CAAC;AACtB,CAAC;AAED,IAAI,KAAa,EAAE,QAAgB,EAAE,UAAkB,EAAE,CAAS,EAAE,MAAc,CAAC;AACnF,IAAI,IAAY,EAAE,OAAe,EAAE,SAAiB,EAAE,KAAa,CAAC;AAEpE,GAAG,CAAC,CAAE,eAAsB,EAAtB,qCAAsB,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,eAAsC,EAArC,YAAsB,EAAtB,qCAAsB,MAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,2CAAyE,EAAxE,YAAsB,EAAtB,qCAAsB,MAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,sBAG0C,EAH1C,gEAG0C,EAFtC,eAA6B,EAA7B,yCAA6B,EAC7B,iBAAmC,EAAnC,6CAAmC,EAEvC,UAAU,EAAV,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,oBAKc,GAJf,cAG0C,EAH1C,gEAG0C,EAFtC,eAA6B,EAA7B,yCAA6B,EAC7B,iBAAmC,EAAnC,6CAAmC,WAEtB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,8EAKoF,GAJrF,cAG0C,EAH1C,gEAG0C,EAFtC,eAA6B,EAA7B,yCAA6B,EAC7B,iBAAmC,EAAnC,6CAAmC;IAGvC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,GAAG,CAAC,CAAG,eAAe,EAAf,oCAAe,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAClD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,eAAgC,EAA9B,YAAe,EAAf,oCAAe,MAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,2CAAmE,EAAjE,YAAe,EAAf,oCAAe,MAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC1F,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,sBAG0C,EAH1C,gEAG0C,EAFtC,eAAmB,EAAnB,wCAAmB,EACnB,iBAAuB,EAAvB,4CAAuB,EAE3B,UAAU,EAAV,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,oBAKc,GAJf,cAG0C,EAH1C,gEAG0C,EAFtC,eAAmB,EAAnB,wCAAmB,EACnB,iBAAuB,EAAvB,4CAAuB,WAEV,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,8EAKoF,GAJrF,eAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB;IAG3B,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAGD,GAAG,CAAC,CAAE,gBAAsB,EAAtB,uCAAsB,EAAE,iBAAuB,EAAvB,uCAAuB,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACjF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,gBAA+D,EAA9D,cAAsB,EAAtB,uCAAsB,EAAE,eAAuB,EAAvB,uCAAuB,OAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACtF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,4CAAkG,EAAjG,cAAsB,EAAtB,uCAAsB,EAAE,eAAuB,EAAvB,uCAAuB,OAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACzH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,qBAAsB,EAAtB,uCAAsB,EACtB,uBAG0C,EAH1C,mEAG0C,EAFtC,iBAA6B,EAA7B,2CAA6B,EAC7B,mBAAmC,EAAnC,+CAAmC,EAEvC,UAAU,EAAV,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,qBAMc,GALf,cAAsB,EAAtB,uCAAsB,EACtB,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAA6B,EAA7B,2CAA6B,EAC7B,mBAAmC,EAAnC,+CAAmC,aAEtB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,+EAMoF,GALrF,cAAsB,EAAtB,uCAAsB,EACtB,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAA6B,EAA7B,2CAA6B,EAC7B,mBAAmC,EAAnC,+CAAmC;IAGvC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,GAAG,CAAC,CAAG,gBAAe,EAAf,sCAAe,EAAE,iBAAe,EAAf,sCAAe,EAAK,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,gBAAiD,EAA/C,cAAe,EAAf,sCAAe,EAAE,eAAe,EAAf,sCAAe,OAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CAAC,4CAAoF,EAAlF,cAAe,EAAf,sCAAe,EAAE,eAAe,EAAf,sCAAe,OAAoD,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAC3G,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,GAAG,CAAC,CACA,qBAAe,EAAf,sCAAe,EACf,uBAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB,EAE3B,UAAU,EAAV,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,qBAMc,GALf,cAAe,EAAf,sCAAe,EACf,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB,aAEV,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AACD,GAAG,CAAC,CAAC,+EAMoF,GALrF,cAAe,EAAf,sCAAe,EACf,gBAG0C,EAH1C,mEAG0C,EAFtC,iBAAmB,EAAnB,0CAAmB,EACnB,mBAAuB,EAAvB,8CAAuB;IAG3B,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.sourcemap.txt index 97271e8f3d0..9e0e92d4a68 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.sourcemap.txt @@ -594,14 +594,14 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(19, 1) Source(37, 1) + SourceIndex(0) 2 >Emitted(19, 2) Source(37, 2) + SourceIndex(0) --- ->>>for (_f = multiRobot.skills, _g = _f === void 0 ? { primary: "none", secondary: "none" } : _f, _h = _g.primary, primaryA = _h === void 0 ? "primary" : _h, _j = _g.secondary, secondaryA = _j === void 0 ? "secondary" : _j, multiRobot, i = 0; i < 1; i++) { +>>>for (_f = multiRobot.skills, _g = _f === void 0 ? { primary: "none", secondary: "none" } : _f, _h = _g.primary, primaryA = _h === void 0 ? "primary" : _h, _j = _g.secondary, secondaryA = _j === void 0 ? "secondary" : _j, multiRobot, multiRobot, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ @@ -620,18 +620,20 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 16> ^^ 17> ^^^^^^^^^^ 18> ^^ -19> ^ -20> ^^^ -21> ^ -22> ^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^ -29> ^^ -30> ^ +19> ^^^^^^^^^^ +20> ^^ +21> ^ +22> ^^^ +23> ^ +24> ^^ +25> ^ +26> ^^^ +27> ^ +28> ^^ +29> ^ +30> ^^ +31> ^^ +32> ^ 1-> > 2 >for @@ -660,19 +662,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = 17> multiRobot -18> , -19> i -20> = -21> 0 -22> ; -23> i -24> < -25> 1 -26> ; -27> i -28> ++ -29> ) -30> { +18> +19> multiRobot +20> , +21> i +22> = +23> 0 +24> ; +25> i +26> < +27> 1 +28> ; +29> i +30> ++ +31> ) +32> { 1->Emitted(20, 1) Source(38, 1) + SourceIndex(0) 2 >Emitted(20, 4) Source(38, 4) + SourceIndex(0) 3 >Emitted(20, 5) Source(38, 5) + SourceIndex(0) @@ -690,19 +694,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 15>Emitted(20, 220) Source(41, 44) + SourceIndex(0) 16>Emitted(20, 222) Source(43, 5) + SourceIndex(0) 17>Emitted(20, 232) Source(43, 15) + SourceIndex(0) -18>Emitted(20, 234) Source(43, 17) + SourceIndex(0) -19>Emitted(20, 235) Source(43, 18) + SourceIndex(0) -20>Emitted(20, 238) Source(43, 21) + SourceIndex(0) -21>Emitted(20, 239) Source(43, 22) + SourceIndex(0) -22>Emitted(20, 241) Source(43, 24) + SourceIndex(0) -23>Emitted(20, 242) Source(43, 25) + SourceIndex(0) -24>Emitted(20, 245) Source(43, 28) + SourceIndex(0) -25>Emitted(20, 246) Source(43, 29) + SourceIndex(0) -26>Emitted(20, 248) Source(43, 31) + SourceIndex(0) -27>Emitted(20, 249) Source(43, 32) + SourceIndex(0) -28>Emitted(20, 251) Source(43, 34) + SourceIndex(0) -29>Emitted(20, 253) Source(43, 36) + SourceIndex(0) -30>Emitted(20, 254) Source(43, 37) + SourceIndex(0) +18>Emitted(20, 234) Source(43, 5) + SourceIndex(0) +19>Emitted(20, 244) Source(43, 15) + SourceIndex(0) +20>Emitted(20, 246) Source(43, 17) + SourceIndex(0) +21>Emitted(20, 247) Source(43, 18) + SourceIndex(0) +22>Emitted(20, 250) Source(43, 21) + SourceIndex(0) +23>Emitted(20, 251) Source(43, 22) + SourceIndex(0) +24>Emitted(20, 253) Source(43, 24) + SourceIndex(0) +25>Emitted(20, 254) Source(43, 25) + SourceIndex(0) +26>Emitted(20, 257) Source(43, 28) + SourceIndex(0) +27>Emitted(20, 258) Source(43, 29) + SourceIndex(0) +28>Emitted(20, 260) Source(43, 31) + SourceIndex(0) +29>Emitted(20, 261) Source(43, 32) + SourceIndex(0) +30>Emitted(20, 263) Source(43, 34) + SourceIndex(0) +31>Emitted(20, 265) Source(43, 36) + SourceIndex(0) +32>Emitted(20, 266) Source(43, 37) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -734,44 +740,44 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(22, 1) Source(45, 1) + SourceIndex(0) 2 >Emitted(22, 2) Source(45, 2) + SourceIndex(0) --- ->>>for (_k = getMultiRobot(), _l = _k.skills, _m = _l === void 0 ? { primary: "none", secondary: "none" } : _l, _o = _m.primary, primaryA = _o === void 0 ? "primary" : _o, _p = _m.secondary, secondaryA = _p === void 0 ? "secondary" : _p, _k, i = 0; i < 1; i++) { +>>>for (_k = getMultiRobot(), (_l = _k.skills, _m = _l === void 0 ? { primary: "none", secondary: "none" } : _l, _o = _m.primary, primaryA = _o === void 0 ? "primary" : _o, _p = _m.secondary, secondaryA = _p === void 0 ? "secondary" : _p, _k), _k, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -18> ^^^^^^ -19> ^ -20> ^^^ -21> ^ -22> ^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^ -29> ^^ -30> ^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +18> ^^^^^^^^^^^ +19> ^ +20> ^^^ +21> ^ +22> ^^ +23> ^ +24> ^^^ +25> ^ +26> ^^ +27> ^ +28> ^^ +29> ^^ +30> ^ 1-> > 2 >for @@ -784,69 +790,69 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = getMultiRobot() 6 > -7 > skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -8 > -9 > skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -10> -11> primary: primaryA = "primary" -12> -13> primary: primaryA = "primary" -14> , - > -15> secondary: secondaryA = "secondary" -16> -17> secondary: secondaryA = "secondary" -18> - > } = { primary: "none", secondary: "none" } - > } = getMultiRobot(), -19> i -20> = -21> 0 -22> ; -23> i -24> < -25> 1 -26> ; -27> i -28> ++ -29> ) -30> { +7 > skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +8 > +9 > skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +10> +11> primary: primaryA = "primary" +12> +13> primary: primaryA = "primary" +14> , + > +15> secondary: secondaryA = "secondary" +16> +17> secondary: secondaryA = "secondary" +18> + > } = { primary: "none", secondary: "none" } + > } = getMultiRobot(), +19> i +20> = +21> 0 +22> ; +23> i +24> < +25> 1 +26> ; +27> i +28> ++ +29> ) +30> { 1->Emitted(23, 1) Source(46, 1) + SourceIndex(0) 2 >Emitted(23, 4) Source(46, 4) + SourceIndex(0) 3 >Emitted(23, 5) Source(46, 5) + SourceIndex(0) 4 >Emitted(23, 6) Source(46, 6) + SourceIndex(0) 5 >Emitted(23, 26) Source(51, 20) + SourceIndex(0) -6 >Emitted(23, 28) Source(47, 5) + SourceIndex(0) -7 >Emitted(23, 42) Source(50, 47) + SourceIndex(0) -8 >Emitted(23, 44) Source(47, 5) + SourceIndex(0) -9 >Emitted(23, 108) Source(50, 47) + SourceIndex(0) -10>Emitted(23, 110) Source(48, 9) + SourceIndex(0) -11>Emitted(23, 125) Source(48, 38) + SourceIndex(0) -12>Emitted(23, 127) Source(48, 9) + SourceIndex(0) -13>Emitted(23, 168) Source(48, 38) + SourceIndex(0) -14>Emitted(23, 170) Source(49, 9) + SourceIndex(0) -15>Emitted(23, 187) Source(49, 44) + SourceIndex(0) -16>Emitted(23, 189) Source(49, 9) + SourceIndex(0) -17>Emitted(23, 234) Source(49, 44) + SourceIndex(0) -18>Emitted(23, 240) Source(51, 22) + SourceIndex(0) -19>Emitted(23, 241) Source(51, 23) + SourceIndex(0) -20>Emitted(23, 244) Source(51, 26) + SourceIndex(0) -21>Emitted(23, 245) Source(51, 27) + SourceIndex(0) -22>Emitted(23, 247) Source(51, 29) + SourceIndex(0) -23>Emitted(23, 248) Source(51, 30) + SourceIndex(0) -24>Emitted(23, 251) Source(51, 33) + SourceIndex(0) -25>Emitted(23, 252) Source(51, 34) + SourceIndex(0) -26>Emitted(23, 254) Source(51, 36) + SourceIndex(0) -27>Emitted(23, 255) Source(51, 37) + SourceIndex(0) -28>Emitted(23, 257) Source(51, 39) + SourceIndex(0) -29>Emitted(23, 259) Source(51, 41) + SourceIndex(0) -30>Emitted(23, 260) Source(51, 42) + SourceIndex(0) +6 >Emitted(23, 29) Source(47, 5) + SourceIndex(0) +7 >Emitted(23, 43) Source(50, 47) + SourceIndex(0) +8 >Emitted(23, 45) Source(47, 5) + SourceIndex(0) +9 >Emitted(23, 109) Source(50, 47) + SourceIndex(0) +10>Emitted(23, 111) Source(48, 9) + SourceIndex(0) +11>Emitted(23, 126) Source(48, 38) + SourceIndex(0) +12>Emitted(23, 128) Source(48, 9) + SourceIndex(0) +13>Emitted(23, 169) Source(48, 38) + SourceIndex(0) +14>Emitted(23, 171) Source(49, 9) + SourceIndex(0) +15>Emitted(23, 188) Source(49, 44) + SourceIndex(0) +16>Emitted(23, 190) Source(49, 9) + SourceIndex(0) +17>Emitted(23, 235) Source(49, 44) + SourceIndex(0) +18>Emitted(23, 246) Source(51, 22) + SourceIndex(0) +19>Emitted(23, 247) Source(51, 23) + SourceIndex(0) +20>Emitted(23, 250) Source(51, 26) + SourceIndex(0) +21>Emitted(23, 251) Source(51, 27) + SourceIndex(0) +22>Emitted(23, 253) Source(51, 29) + SourceIndex(0) +23>Emitted(23, 254) Source(51, 30) + SourceIndex(0) +24>Emitted(23, 257) Source(51, 33) + SourceIndex(0) +25>Emitted(23, 258) Source(51, 34) + SourceIndex(0) +26>Emitted(23, 260) Source(51, 36) + SourceIndex(0) +27>Emitted(23, 261) Source(51, 37) + SourceIndex(0) +28>Emitted(23, 263) Source(51, 39) + SourceIndex(0) +29>Emitted(23, 265) Source(51, 41) + SourceIndex(0) +30>Emitted(23, 266) Source(51, 42) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -878,31 +884,31 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(25, 1) Source(53, 1) + SourceIndex(0) 2 >Emitted(25, 2) Source(53, 2) + SourceIndex(0) --- ->>>for (_q = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _r = _q.skills, _s = _r === void 0 ? { primary: "none", secondary: "none" } : _r, _t = _s.primary, primaryA = _t === void 0 ? "primary" : _t, _u = _s.secondary, secondaryA = _u === void 0 ? "secondary" : _u, _q, +>>>for (_q = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_r = _q.skills, _s = _r === void 0 ? { primary: "none", secondary: "none" } : _r, _t = _s.primary, primaryA = _t === void 0 ? "primary" : _t, _u = _s.secondary, secondaryA = _u === void 0 ? "secondary" : _u, _q), _q, 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> > 2 >for @@ -915,41 +921,41 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } } 6 > -7 > skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -8 > -9 > skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -10> -11> primary: primaryA = "primary" -12> -13> primary: primaryA = "primary" -14> , - > -15> secondary: secondaryA = "secondary" -16> -17> secondary: secondaryA = "secondary" +7 > skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +8 > +9 > skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +10> +11> primary: primaryA = "primary" +12> +13> primary: primaryA = "primary" +14> , + > +15> secondary: secondaryA = "secondary" +16> +17> secondary: secondaryA = "secondary" 1->Emitted(26, 1) Source(54, 1) + SourceIndex(0) 2 >Emitted(26, 4) Source(54, 4) + SourceIndex(0) 3 >Emitted(26, 5) Source(54, 5) + SourceIndex(0) 4 >Emitted(26, 6) Source(54, 6) + SourceIndex(0) 5 >Emitted(26, 84) Source(59, 90) + SourceIndex(0) -6 >Emitted(26, 86) Source(55, 5) + SourceIndex(0) -7 >Emitted(26, 100) Source(58, 47) + SourceIndex(0) -8 >Emitted(26, 102) Source(55, 5) + SourceIndex(0) -9 >Emitted(26, 166) Source(58, 47) + SourceIndex(0) -10>Emitted(26, 168) Source(56, 9) + SourceIndex(0) -11>Emitted(26, 183) Source(56, 38) + SourceIndex(0) -12>Emitted(26, 185) Source(56, 9) + SourceIndex(0) -13>Emitted(26, 226) Source(56, 38) + SourceIndex(0) -14>Emitted(26, 228) Source(57, 9) + SourceIndex(0) -15>Emitted(26, 245) Source(57, 44) + SourceIndex(0) -16>Emitted(26, 247) Source(57, 9) + SourceIndex(0) -17>Emitted(26, 292) Source(57, 44) + SourceIndex(0) +6 >Emitted(26, 87) Source(55, 5) + SourceIndex(0) +7 >Emitted(26, 101) Source(58, 47) + SourceIndex(0) +8 >Emitted(26, 103) Source(55, 5) + SourceIndex(0) +9 >Emitted(26, 167) Source(58, 47) + SourceIndex(0) +10>Emitted(26, 169) Source(56, 9) + SourceIndex(0) +11>Emitted(26, 184) Source(56, 38) + SourceIndex(0) +12>Emitted(26, 186) Source(56, 9) + SourceIndex(0) +13>Emitted(26, 227) Source(56, 38) + SourceIndex(0) +14>Emitted(26, 229) Source(57, 9) + SourceIndex(0) +15>Emitted(26, 246) Source(57, 44) + SourceIndex(0) +16>Emitted(26, 248) Source(57, 9) + SourceIndex(0) +17>Emitted(26, 293) Source(57, 44) + SourceIndex(0) --- >>> i = 0; i < 1; i++) { 1 >^^^^ @@ -1345,14 +1351,14 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(38, 1) Source(72, 1) + SourceIndex(0) 2 >Emitted(38, 2) Source(72, 2) + SourceIndex(0) --- ->>>for (_0 = multiRobot.skills, _1 = _0 === void 0 ? { primary: "none", secondary: "none" } : _0, _2 = _1.primary, primary = _2 === void 0 ? "primary" : _2, _3 = _1.secondary, secondary = _3 === void 0 ? "secondary" : _3, multiRobot, i = 0; i < 1; i++) { +>>>for (_0 = multiRobot.skills, _1 = _0 === void 0 ? { primary: "none", secondary: "none" } : _0, _2 = _1.primary, primary = _2 === void 0 ? "primary" : _2, _3 = _1.secondary, secondary = _3 === void 0 ? "secondary" : _3, multiRobot, multiRobot, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ @@ -1371,18 +1377,20 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 16> ^^ 17> ^^^^^^^^^^ 18> ^^ -19> ^ -20> ^^^ -21> ^ -22> ^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^ -29> ^^ -30> ^ +19> ^^^^^^^^^^ +20> ^^ +21> ^ +22> ^^^ +23> ^ +24> ^^ +25> ^ +26> ^^^ +27> ^ +28> ^^ +29> ^ +30> ^^ +31> ^^ +32> ^ 1-> > 2 >for @@ -1411,19 +1419,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = 17> multiRobot -18> , -19> i -20> = -21> 0 -22> ; -23> i -24> < -25> 1 -26> ; -27> i -28> ++ -29> ) -30> { +18> +19> multiRobot +20> , +21> i +22> = +23> 0 +24> ; +25> i +26> < +27> 1 +28> ; +29> i +30> ++ +31> ) +32> { 1->Emitted(39, 1) Source(73, 1) + SourceIndex(0) 2 >Emitted(39, 4) Source(73, 4) + SourceIndex(0) 3 >Emitted(39, 5) Source(73, 5) + SourceIndex(0) @@ -1441,19 +1451,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 15>Emitted(39, 218) Source(76, 32) + SourceIndex(0) 16>Emitted(39, 220) Source(78, 5) + SourceIndex(0) 17>Emitted(39, 230) Source(78, 15) + SourceIndex(0) -18>Emitted(39, 232) Source(78, 17) + SourceIndex(0) -19>Emitted(39, 233) Source(78, 18) + SourceIndex(0) -20>Emitted(39, 236) Source(78, 21) + SourceIndex(0) -21>Emitted(39, 237) Source(78, 22) + SourceIndex(0) -22>Emitted(39, 239) Source(78, 24) + SourceIndex(0) -23>Emitted(39, 240) Source(78, 25) + SourceIndex(0) -24>Emitted(39, 243) Source(78, 28) + SourceIndex(0) -25>Emitted(39, 244) Source(78, 29) + SourceIndex(0) -26>Emitted(39, 246) Source(78, 31) + SourceIndex(0) -27>Emitted(39, 247) Source(78, 32) + SourceIndex(0) -28>Emitted(39, 249) Source(78, 34) + SourceIndex(0) -29>Emitted(39, 251) Source(78, 36) + SourceIndex(0) -30>Emitted(39, 252) Source(78, 37) + SourceIndex(0) +18>Emitted(39, 232) Source(78, 5) + SourceIndex(0) +19>Emitted(39, 242) Source(78, 15) + SourceIndex(0) +20>Emitted(39, 244) Source(78, 17) + SourceIndex(0) +21>Emitted(39, 245) Source(78, 18) + SourceIndex(0) +22>Emitted(39, 248) Source(78, 21) + SourceIndex(0) +23>Emitted(39, 249) Source(78, 22) + SourceIndex(0) +24>Emitted(39, 251) Source(78, 24) + SourceIndex(0) +25>Emitted(39, 252) Source(78, 25) + SourceIndex(0) +26>Emitted(39, 255) Source(78, 28) + SourceIndex(0) +27>Emitted(39, 256) Source(78, 29) + SourceIndex(0) +28>Emitted(39, 258) Source(78, 31) + SourceIndex(0) +29>Emitted(39, 259) Source(78, 32) + SourceIndex(0) +30>Emitted(39, 261) Source(78, 34) + SourceIndex(0) +31>Emitted(39, 263) Source(78, 36) + SourceIndex(0) +32>Emitted(39, 264) Source(78, 37) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -1485,44 +1497,44 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(41, 1) Source(80, 1) + SourceIndex(0) 2 >Emitted(41, 2) Source(80, 2) + SourceIndex(0) --- ->>>for (_4 = getMultiRobot(), _5 = _4.skills, _6 = _5 === void 0 ? { primary: "none", secondary: "none" } : _5, _7 = _6.primary, primary = _7 === void 0 ? "primary" : _7, _8 = _6.secondary, secondary = _8 === void 0 ? "secondary" : _8, _4, i = 0; i < 1; i++) { +>>>for (_4 = getMultiRobot(), (_5 = _4.skills, _6 = _5 === void 0 ? { primary: "none", secondary: "none" } : _5, _7 = _6.primary, primary = _7 === void 0 ? "primary" : _7, _8 = _6.secondary, secondary = _8 === void 0 ? "secondary" : _8, _4), _4, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -18> ^^^^^^ -19> ^ -20> ^^^ -21> ^ -22> ^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^ -29> ^^ -30> ^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +18> ^^^^^^^^^^^ +19> ^ +20> ^^^ +21> ^ +22> ^^ +23> ^ +24> ^^^ +25> ^ +26> ^^ +27> ^ +28> ^^ +29> ^^ +30> ^ 1-> > 2 >for @@ -1535,69 +1547,69 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = getMultiRobot() 6 > -7 > skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -8 > -9 > skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -10> -11> primary = "primary" -12> -13> primary = "primary" -14> , - > -15> secondary = "secondary" -16> -17> secondary = "secondary" -18> - > } = { primary: "none", secondary: "none" } - > } = getMultiRobot(), -19> i -20> = -21> 0 -22> ; -23> i -24> < -25> 1 -26> ; -27> i -28> ++ -29> ) -30> { +7 > skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +8 > +9 > skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +10> +11> primary = "primary" +12> +13> primary = "primary" +14> , + > +15> secondary = "secondary" +16> +17> secondary = "secondary" +18> + > } = { primary: "none", secondary: "none" } + > } = getMultiRobot(), +19> i +20> = +21> 0 +22> ; +23> i +24> < +25> 1 +26> ; +27> i +28> ++ +29> ) +30> { 1->Emitted(42, 1) Source(81, 1) + SourceIndex(0) 2 >Emitted(42, 4) Source(81, 4) + SourceIndex(0) 3 >Emitted(42, 5) Source(81, 5) + SourceIndex(0) 4 >Emitted(42, 6) Source(81, 6) + SourceIndex(0) 5 >Emitted(42, 26) Source(86, 20) + SourceIndex(0) -6 >Emitted(42, 28) Source(82, 5) + SourceIndex(0) -7 >Emitted(42, 42) Source(85, 47) + SourceIndex(0) -8 >Emitted(42, 44) Source(82, 5) + SourceIndex(0) -9 >Emitted(42, 108) Source(85, 47) + SourceIndex(0) -10>Emitted(42, 110) Source(83, 9) + SourceIndex(0) -11>Emitted(42, 125) Source(83, 28) + SourceIndex(0) -12>Emitted(42, 127) Source(83, 9) + SourceIndex(0) -13>Emitted(42, 167) Source(83, 28) + SourceIndex(0) -14>Emitted(42, 169) Source(84, 9) + SourceIndex(0) -15>Emitted(42, 186) Source(84, 32) + SourceIndex(0) -16>Emitted(42, 188) Source(84, 9) + SourceIndex(0) -17>Emitted(42, 232) Source(84, 32) + SourceIndex(0) -18>Emitted(42, 238) Source(86, 22) + SourceIndex(0) -19>Emitted(42, 239) Source(86, 23) + SourceIndex(0) -20>Emitted(42, 242) Source(86, 26) + SourceIndex(0) -21>Emitted(42, 243) Source(86, 27) + SourceIndex(0) -22>Emitted(42, 245) Source(86, 29) + SourceIndex(0) -23>Emitted(42, 246) Source(86, 30) + SourceIndex(0) -24>Emitted(42, 249) Source(86, 33) + SourceIndex(0) -25>Emitted(42, 250) Source(86, 34) + SourceIndex(0) -26>Emitted(42, 252) Source(86, 36) + SourceIndex(0) -27>Emitted(42, 253) Source(86, 37) + SourceIndex(0) -28>Emitted(42, 255) Source(86, 39) + SourceIndex(0) -29>Emitted(42, 257) Source(86, 41) + SourceIndex(0) -30>Emitted(42, 258) Source(86, 42) + SourceIndex(0) +6 >Emitted(42, 29) Source(82, 5) + SourceIndex(0) +7 >Emitted(42, 43) Source(85, 47) + SourceIndex(0) +8 >Emitted(42, 45) Source(82, 5) + SourceIndex(0) +9 >Emitted(42, 109) Source(85, 47) + SourceIndex(0) +10>Emitted(42, 111) Source(83, 9) + SourceIndex(0) +11>Emitted(42, 126) Source(83, 28) + SourceIndex(0) +12>Emitted(42, 128) Source(83, 9) + SourceIndex(0) +13>Emitted(42, 168) Source(83, 28) + SourceIndex(0) +14>Emitted(42, 170) Source(84, 9) + SourceIndex(0) +15>Emitted(42, 187) Source(84, 32) + SourceIndex(0) +16>Emitted(42, 189) Source(84, 9) + SourceIndex(0) +17>Emitted(42, 233) Source(84, 32) + SourceIndex(0) +18>Emitted(42, 244) Source(86, 22) + SourceIndex(0) +19>Emitted(42, 245) Source(86, 23) + SourceIndex(0) +20>Emitted(42, 248) Source(86, 26) + SourceIndex(0) +21>Emitted(42, 249) Source(86, 27) + SourceIndex(0) +22>Emitted(42, 251) Source(86, 29) + SourceIndex(0) +23>Emitted(42, 252) Source(86, 30) + SourceIndex(0) +24>Emitted(42, 255) Source(86, 33) + SourceIndex(0) +25>Emitted(42, 256) Source(86, 34) + SourceIndex(0) +26>Emitted(42, 258) Source(86, 36) + SourceIndex(0) +27>Emitted(42, 259) Source(86, 37) + SourceIndex(0) +28>Emitted(42, 261) Source(86, 39) + SourceIndex(0) +29>Emitted(42, 263) Source(86, 41) + SourceIndex(0) +30>Emitted(42, 264) Source(86, 42) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -1629,31 +1641,31 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(44, 1) Source(88, 1) + SourceIndex(0) 2 >Emitted(44, 2) Source(88, 2) + SourceIndex(0) --- ->>>for (_9 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _10 = _9.skills, _11 = _10 === void 0 ? { primary: "none", secondary: "none" } : _10, _12 = _11.primary, primary = _12 === void 0 ? "primary" : _12, _13 = _11.secondary, secondary = _13 === void 0 ? "secondary" : _13, _9, +>>>for (_9 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_10 = _9.skills, _11 = _10 === void 0 ? { primary: "none", secondary: "none" } : _10, _12 = _11.primary, primary = _12 === void 0 ? "primary" : _12, _13 = _11.secondary, secondary = _13 === void 0 ? "secondary" : _13, _9), _9, 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> > 2 >for @@ -1666,41 +1678,41 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } } 6 > -7 > skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -8 > -9 > skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -10> -11> primary = "primary" -12> -13> primary = "primary" -14> , - > -15> secondary = "secondary" -16> -17> secondary = "secondary" +7 > skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +8 > +9 > skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +10> +11> primary = "primary" +12> +13> primary = "primary" +14> , + > +15> secondary = "secondary" +16> +17> secondary = "secondary" 1->Emitted(45, 1) Source(89, 1) + SourceIndex(0) 2 >Emitted(45, 4) Source(89, 4) + SourceIndex(0) 3 >Emitted(45, 5) Source(89, 5) + SourceIndex(0) 4 >Emitted(45, 6) Source(89, 6) + SourceIndex(0) 5 >Emitted(45, 84) Source(94, 90) + SourceIndex(0) -6 >Emitted(45, 86) Source(90, 5) + SourceIndex(0) -7 >Emitted(45, 101) Source(93, 47) + SourceIndex(0) -8 >Emitted(45, 103) Source(90, 5) + SourceIndex(0) -9 >Emitted(45, 170) Source(93, 47) + SourceIndex(0) -10>Emitted(45, 172) Source(91, 9) + SourceIndex(0) -11>Emitted(45, 189) Source(91, 28) + SourceIndex(0) -12>Emitted(45, 191) Source(91, 9) + SourceIndex(0) -13>Emitted(45, 233) Source(91, 28) + SourceIndex(0) -14>Emitted(45, 235) Source(92, 9) + SourceIndex(0) -15>Emitted(45, 254) Source(92, 32) + SourceIndex(0) -16>Emitted(45, 256) Source(92, 9) + SourceIndex(0) -17>Emitted(45, 302) Source(92, 32) + SourceIndex(0) +6 >Emitted(45, 87) Source(90, 5) + SourceIndex(0) +7 >Emitted(45, 102) Source(93, 47) + SourceIndex(0) +8 >Emitted(45, 104) Source(90, 5) + SourceIndex(0) +9 >Emitted(45, 171) Source(93, 47) + SourceIndex(0) +10>Emitted(45, 173) Source(91, 9) + SourceIndex(0) +11>Emitted(45, 190) Source(91, 28) + SourceIndex(0) +12>Emitted(45, 192) Source(91, 9) + SourceIndex(0) +13>Emitted(45, 234) Source(91, 28) + SourceIndex(0) +14>Emitted(45, 236) Source(92, 9) + SourceIndex(0) +15>Emitted(45, 255) Source(92, 32) + SourceIndex(0) +16>Emitted(45, 257) Source(92, 9) + SourceIndex(0) +17>Emitted(45, 303) Source(92, 32) + SourceIndex(0) --- >>> i = 0; i < 1; i++) { 1 >^^^^ @@ -2133,14 +2145,14 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(57, 1) Source(108, 1) + SourceIndex(0) 2 >Emitted(57, 2) Source(108, 2) + SourceIndex(0) --- ->>>for (_22 = multiRobot.name, nameA = _22 === void 0 ? "noName" : _22, _23 = multiRobot.skills, _24 = _23 === void 0 ? { primary: "none", secondary: "none" } : _23, _25 = _24.primary, primaryA = _25 === void 0 ? "primary" : _25, _26 = _24.secondary, secondaryA = _26 === void 0 ? "secondary" : _26, multiRobot, i = 0; i < 1; i++) { +>>>for (_22 = multiRobot.name, nameA = _22 === void 0 ? "noName" : _22, _23 = multiRobot.skills, _24 = _23 === void 0 ? { primary: "none", secondary: "none" } : _23, _25 = _24.primary, primaryA = _25 === void 0 ? "primary" : _25, _26 = _24.secondary, secondaryA = _26 === void 0 ? "secondary" : _26, multiRobot, multiRobot, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ @@ -2163,18 +2175,20 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 20> ^^ 21> ^^^^^^^^^^ 22> ^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^^ -29> ^ -30> ^^ -31> ^ -32> ^^ -33> ^^ -34> ^ +23> ^^^^^^^^^^ +24> ^^ +25> ^ +26> ^^^ +27> ^ +28> ^^ +29> ^ +30> ^^^ +31> ^ +32> ^^ +33> ^ +34> ^^ +35> ^^ +36> ^ 1-> > 2 >for @@ -2208,19 +2222,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = 21> multiRobot -22> , -23> i -24> = -25> 0 -26> ; -27> i -28> < -29> 1 -30> ; -31> i -32> ++ -33> ) -34> { +22> +23> multiRobot +24> , +25> i +26> = +27> 0 +28> ; +29> i +30> < +31> 1 +32> ; +33> i +34> ++ +35> ) +36> { 1->Emitted(58, 1) Source(109, 1) + SourceIndex(0) 2 >Emitted(58, 4) Source(109, 4) + SourceIndex(0) 3 >Emitted(58, 5) Source(109, 5) + SourceIndex(0) @@ -2242,19 +2258,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 19>Emitted(58, 296) Source(113, 44) + SourceIndex(0) 20>Emitted(58, 298) Source(115, 5) + SourceIndex(0) 21>Emitted(58, 308) Source(115, 15) + SourceIndex(0) -22>Emitted(58, 310) Source(115, 17) + SourceIndex(0) -23>Emitted(58, 311) Source(115, 18) + SourceIndex(0) -24>Emitted(58, 314) Source(115, 21) + SourceIndex(0) -25>Emitted(58, 315) Source(115, 22) + SourceIndex(0) -26>Emitted(58, 317) Source(115, 24) + SourceIndex(0) -27>Emitted(58, 318) Source(115, 25) + SourceIndex(0) -28>Emitted(58, 321) Source(115, 28) + SourceIndex(0) -29>Emitted(58, 322) Source(115, 29) + SourceIndex(0) -30>Emitted(58, 324) Source(115, 31) + SourceIndex(0) -31>Emitted(58, 325) Source(115, 32) + SourceIndex(0) -32>Emitted(58, 327) Source(115, 34) + SourceIndex(0) -33>Emitted(58, 329) Source(115, 36) + SourceIndex(0) -34>Emitted(58, 330) Source(115, 37) + SourceIndex(0) +22>Emitted(58, 310) Source(115, 5) + SourceIndex(0) +23>Emitted(58, 320) Source(115, 15) + SourceIndex(0) +24>Emitted(58, 322) Source(115, 17) + SourceIndex(0) +25>Emitted(58, 323) Source(115, 18) + SourceIndex(0) +26>Emitted(58, 326) Source(115, 21) + SourceIndex(0) +27>Emitted(58, 327) Source(115, 22) + SourceIndex(0) +28>Emitted(58, 329) Source(115, 24) + SourceIndex(0) +29>Emitted(58, 330) Source(115, 25) + SourceIndex(0) +30>Emitted(58, 333) Source(115, 28) + SourceIndex(0) +31>Emitted(58, 334) Source(115, 29) + SourceIndex(0) +32>Emitted(58, 336) Source(115, 31) + SourceIndex(0) +33>Emitted(58, 337) Source(115, 32) + SourceIndex(0) +34>Emitted(58, 339) Source(115, 34) + SourceIndex(0) +35>Emitted(58, 341) Source(115, 36) + SourceIndex(0) +36>Emitted(58, 342) Source(115, 37) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -2286,48 +2304,48 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(60, 1) Source(117, 1) + SourceIndex(0) 2 >Emitted(60, 2) Source(117, 2) + SourceIndex(0) --- ->>>for (_27 = getMultiRobot(), _28 = _27.name, nameA = _28 === void 0 ? "noName" : _28, _29 = _27.skills, _30 = _29 === void 0 ? { primary: "none", secondary: "none" } : _29, _31 = _30.primary, primaryA = _31 === void 0 ? "primary" : _31, _32 = _30.secondary, secondaryA = _32 === void 0 ? "secondary" : _32, _27, i = 0; i < 1; i++) { +>>>for (_27 = getMultiRobot(), (_28 = _27.name, nameA = _28 === void 0 ? "noName" : _28, _29 = _27.skills, _30 = _29 === void 0 ? { primary: "none", secondary: "none" } : _29, _31 = _30.primary, primaryA = _31 === void 0 ? "primary" : _31, _32 = _30.secondary, secondaryA = _32 === void 0 ? "secondary" : _32, _27), _27, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -18> ^^ -19> ^^^^^^^^^^^^^^^^^^^ -20> ^^ -21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -22> ^^^^^^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^^ -29> ^ -30> ^^ -31> ^ -32> ^^ -33> ^^ -34> ^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +18> ^^ +19> ^^^^^^^^^^^^^^^^^^^ +20> ^^ +21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22> ^^^^^^^^^^^^^ +23> ^ +24> ^^^ +25> ^ +26> ^^ +27> ^ +28> ^^^ +29> ^ +30> ^^ +31> ^ +32> ^^ +33> ^^ +34> ^ 1-> > 2 >for @@ -2341,78 +2359,78 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = getMultiRobot() 6 > -7 > name: nameA = "noName" -8 > -9 > name: nameA = "noName" -10> , - > -11> skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -12> -13> skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -14> -15> primary: primaryA = "primary" -16> -17> primary: primaryA = "primary" -18> , - > -19> secondary: secondaryA = "secondary" -20> -21> secondary: secondaryA = "secondary" -22> - > } = { primary: "none", secondary: "none" } - > } = getMultiRobot(), -23> i -24> = -25> 0 -26> ; -27> i -28> < -29> 1 -30> ; -31> i -32> ++ -33> ) -34> { +7 > name: nameA = "noName" +8 > +9 > name: nameA = "noName" +10> , + > +11> skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +12> +13> skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +14> +15> primary: primaryA = "primary" +16> +17> primary: primaryA = "primary" +18> , + > +19> secondary: secondaryA = "secondary" +20> +21> secondary: secondaryA = "secondary" +22> + > } = { primary: "none", secondary: "none" } + > } = getMultiRobot(), +23> i +24> = +25> 0 +26> ; +27> i +28> < +29> 1 +30> ; +31> i +32> ++ +33> ) +34> { 1->Emitted(61, 1) Source(118, 1) + SourceIndex(0) 2 >Emitted(61, 4) Source(118, 4) + SourceIndex(0) 3 >Emitted(61, 5) Source(118, 5) + SourceIndex(0) 4 >Emitted(61, 6) Source(118, 6) + SourceIndex(0) 5 >Emitted(61, 27) Source(124, 20) + SourceIndex(0) -6 >Emitted(61, 29) Source(119, 5) + SourceIndex(0) -7 >Emitted(61, 43) Source(119, 27) + SourceIndex(0) -8 >Emitted(61, 45) Source(119, 5) + SourceIndex(0) -9 >Emitted(61, 84) Source(119, 27) + SourceIndex(0) -10>Emitted(61, 86) Source(120, 5) + SourceIndex(0) -11>Emitted(61, 102) Source(123, 47) + SourceIndex(0) -12>Emitted(61, 104) Source(120, 5) + SourceIndex(0) -13>Emitted(61, 171) Source(123, 47) + SourceIndex(0) -14>Emitted(61, 173) Source(121, 9) + SourceIndex(0) -15>Emitted(61, 190) Source(121, 38) + SourceIndex(0) -16>Emitted(61, 192) Source(121, 9) + SourceIndex(0) -17>Emitted(61, 235) Source(121, 38) + SourceIndex(0) -18>Emitted(61, 237) Source(122, 9) + SourceIndex(0) -19>Emitted(61, 256) Source(122, 44) + SourceIndex(0) -20>Emitted(61, 258) Source(122, 9) + SourceIndex(0) -21>Emitted(61, 305) Source(122, 44) + SourceIndex(0) -22>Emitted(61, 312) Source(124, 22) + SourceIndex(0) -23>Emitted(61, 313) Source(124, 23) + SourceIndex(0) -24>Emitted(61, 316) Source(124, 26) + SourceIndex(0) -25>Emitted(61, 317) Source(124, 27) + SourceIndex(0) -26>Emitted(61, 319) Source(124, 29) + SourceIndex(0) -27>Emitted(61, 320) Source(124, 30) + SourceIndex(0) -28>Emitted(61, 323) Source(124, 33) + SourceIndex(0) -29>Emitted(61, 324) Source(124, 34) + SourceIndex(0) -30>Emitted(61, 326) Source(124, 36) + SourceIndex(0) -31>Emitted(61, 327) Source(124, 37) + SourceIndex(0) -32>Emitted(61, 329) Source(124, 39) + SourceIndex(0) -33>Emitted(61, 331) Source(124, 41) + SourceIndex(0) -34>Emitted(61, 332) Source(124, 42) + SourceIndex(0) +6 >Emitted(61, 30) Source(119, 5) + SourceIndex(0) +7 >Emitted(61, 44) Source(119, 27) + SourceIndex(0) +8 >Emitted(61, 46) Source(119, 5) + SourceIndex(0) +9 >Emitted(61, 85) Source(119, 27) + SourceIndex(0) +10>Emitted(61, 87) Source(120, 5) + SourceIndex(0) +11>Emitted(61, 103) Source(123, 47) + SourceIndex(0) +12>Emitted(61, 105) Source(120, 5) + SourceIndex(0) +13>Emitted(61, 172) Source(123, 47) + SourceIndex(0) +14>Emitted(61, 174) Source(121, 9) + SourceIndex(0) +15>Emitted(61, 191) Source(121, 38) + SourceIndex(0) +16>Emitted(61, 193) Source(121, 9) + SourceIndex(0) +17>Emitted(61, 236) Source(121, 38) + SourceIndex(0) +18>Emitted(61, 238) Source(122, 9) + SourceIndex(0) +19>Emitted(61, 257) Source(122, 44) + SourceIndex(0) +20>Emitted(61, 259) Source(122, 9) + SourceIndex(0) +21>Emitted(61, 306) Source(122, 44) + SourceIndex(0) +22>Emitted(61, 319) Source(124, 22) + SourceIndex(0) +23>Emitted(61, 320) Source(124, 23) + SourceIndex(0) +24>Emitted(61, 323) Source(124, 26) + SourceIndex(0) +25>Emitted(61, 324) Source(124, 27) + SourceIndex(0) +26>Emitted(61, 326) Source(124, 29) + SourceIndex(0) +27>Emitted(61, 327) Source(124, 30) + SourceIndex(0) +28>Emitted(61, 330) Source(124, 33) + SourceIndex(0) +29>Emitted(61, 331) Source(124, 34) + SourceIndex(0) +30>Emitted(61, 333) Source(124, 36) + SourceIndex(0) +31>Emitted(61, 334) Source(124, 37) + SourceIndex(0) +32>Emitted(61, 336) Source(124, 39) + SourceIndex(0) +33>Emitted(61, 338) Source(124, 41) + SourceIndex(0) +34>Emitted(61, 339) Source(124, 42) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -2444,35 +2462,35 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(63, 1) Source(126, 1) + SourceIndex(0) 2 >Emitted(63, 2) Source(126, 2) + SourceIndex(0) --- ->>>for (_33 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _34 = _33.name, nameA = _34 === void 0 ? "noName" : _34, _35 = _33.skills, _36 = _35 === void 0 ? { primary: "none", secondary: "none" } : _35, _37 = _36.primary, primaryA = _37 === void 0 ? "primary" : _37, _38 = _36.secondary, secondaryA = _38 === void 0 ? "secondary" : _38, _33, +>>>for (_33 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_34 = _33.name, nameA = _34 === void 0 ? "noName" : _34, _35 = _33.skills, _36 = _35 === void 0 ? { primary: "none", secondary: "none" } : _35, _37 = _36.primary, primaryA = _37 === void 0 ? "primary" : _37, _38 = _36.secondary, secondaryA = _38 === void 0 ? "secondary" : _38, _33), _33, 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -18> ^^ -19> ^^^^^^^^^^^^^^^^^^^ -20> ^^ -21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +18> ^^ +19> ^^^^^^^^^^^^^^^^^^^ +20> ^^ +21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> > 2 >for @@ -2486,50 +2504,50 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } } 6 > -7 > name: nameA = "noName" -8 > -9 > name: nameA = "noName" -10> , - > -11> skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -12> -13> skills: { - > primary: primaryA = "primary", - > secondary: secondaryA = "secondary" - > } = { primary: "none", secondary: "none" } -14> -15> primary: primaryA = "primary" -16> -17> primary: primaryA = "primary" -18> , - > -19> secondary: secondaryA = "secondary" -20> -21> secondary: secondaryA = "secondary" +7 > name: nameA = "noName" +8 > +9 > name: nameA = "noName" +10> , + > +11> skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +12> +13> skills: { + > primary: primaryA = "primary", + > secondary: secondaryA = "secondary" + > } = { primary: "none", secondary: "none" } +14> +15> primary: primaryA = "primary" +16> +17> primary: primaryA = "primary" +18> , + > +19> secondary: secondaryA = "secondary" +20> +21> secondary: secondaryA = "secondary" 1->Emitted(64, 1) Source(127, 1) + SourceIndex(0) 2 >Emitted(64, 4) Source(127, 4) + SourceIndex(0) 3 >Emitted(64, 5) Source(127, 5) + SourceIndex(0) 4 >Emitted(64, 6) Source(127, 6) + SourceIndex(0) 5 >Emitted(64, 85) Source(133, 90) + SourceIndex(0) -6 >Emitted(64, 87) Source(128, 5) + SourceIndex(0) -7 >Emitted(64, 101) Source(128, 27) + SourceIndex(0) -8 >Emitted(64, 103) Source(128, 5) + SourceIndex(0) -9 >Emitted(64, 142) Source(128, 27) + SourceIndex(0) -10>Emitted(64, 144) Source(129, 5) + SourceIndex(0) -11>Emitted(64, 160) Source(132, 47) + SourceIndex(0) -12>Emitted(64, 162) Source(129, 5) + SourceIndex(0) -13>Emitted(64, 229) Source(132, 47) + SourceIndex(0) -14>Emitted(64, 231) Source(130, 9) + SourceIndex(0) -15>Emitted(64, 248) Source(130, 38) + SourceIndex(0) -16>Emitted(64, 250) Source(130, 9) + SourceIndex(0) -17>Emitted(64, 293) Source(130, 38) + SourceIndex(0) -18>Emitted(64, 295) Source(131, 9) + SourceIndex(0) -19>Emitted(64, 314) Source(131, 44) + SourceIndex(0) -20>Emitted(64, 316) Source(131, 9) + SourceIndex(0) -21>Emitted(64, 363) Source(131, 44) + SourceIndex(0) +6 >Emitted(64, 88) Source(128, 5) + SourceIndex(0) +7 >Emitted(64, 102) Source(128, 27) + SourceIndex(0) +8 >Emitted(64, 104) Source(128, 5) + SourceIndex(0) +9 >Emitted(64, 143) Source(128, 27) + SourceIndex(0) +10>Emitted(64, 145) Source(129, 5) + SourceIndex(0) +11>Emitted(64, 161) Source(132, 47) + SourceIndex(0) +12>Emitted(64, 163) Source(129, 5) + SourceIndex(0) +13>Emitted(64, 230) Source(132, 47) + SourceIndex(0) +14>Emitted(64, 232) Source(130, 9) + SourceIndex(0) +15>Emitted(64, 249) Source(130, 38) + SourceIndex(0) +16>Emitted(64, 251) Source(130, 9) + SourceIndex(0) +17>Emitted(64, 294) Source(130, 38) + SourceIndex(0) +18>Emitted(64, 296) Source(131, 9) + SourceIndex(0) +19>Emitted(64, 315) Source(131, 44) + SourceIndex(0) +20>Emitted(64, 317) Source(131, 9) + SourceIndex(0) +21>Emitted(64, 364) Source(131, 44) + SourceIndex(0) --- >>> i = 0; i < 1; i++) { 1 >^^^^ @@ -2961,14 +2979,14 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(76, 1) Source(146, 1) + SourceIndex(0) 2 >Emitted(76, 2) Source(146, 2) + SourceIndex(0) --- ->>>for (_47 = multiRobot.name, name = _47 === void 0 ? "noName" : _47, _48 = multiRobot.skills, _49 = _48 === void 0 ? { primary: "none", secondary: "none" } : _48, _50 = _49.primary, primary = _50 === void 0 ? "primary" : _50, _51 = _49.secondary, secondary = _51 === void 0 ? "secondary" : _51, multiRobot, i = 0; i < 1; i++) { +>>>for (_47 = multiRobot.name, name = _47 === void 0 ? "noName" : _47, _48 = multiRobot.skills, _49 = _48 === void 0 ? { primary: "none", secondary: "none" } : _48, _50 = _49.primary, primary = _50 === void 0 ? "primary" : _50, _51 = _49.secondary, secondary = _51 === void 0 ? "secondary" : _51, multiRobot, multiRobot, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ @@ -2991,18 +3009,20 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 20> ^^ 21> ^^^^^^^^^^ 22> ^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^^ -29> ^ -30> ^^ -31> ^ -32> ^^ -33> ^^ -34> ^ +23> ^^^^^^^^^^ +24> ^^ +25> ^ +26> ^^^ +27> ^ +28> ^^ +29> ^ +30> ^^^ +31> ^ +32> ^^ +33> ^ +34> ^^ +35> ^^ +36> ^ 1-> > 2 >for @@ -3036,19 +3056,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = 21> multiRobot -22> , -23> i -24> = -25> 0 -26> ; -27> i -28> < -29> 1 -30> ; -31> i -32> ++ -33> ) -34> { +22> +23> multiRobot +24> , +25> i +26> = +27> 0 +28> ; +29> i +30> < +31> 1 +32> ; +33> i +34> ++ +35> ) +36> { 1->Emitted(77, 1) Source(147, 1) + SourceIndex(0) 2 >Emitted(77, 4) Source(147, 4) + SourceIndex(0) 3 >Emitted(77, 5) Source(147, 5) + SourceIndex(0) @@ -3070,19 +3092,21 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 19>Emitted(77, 293) Source(151, 32) + SourceIndex(0) 20>Emitted(77, 295) Source(153, 5) + SourceIndex(0) 21>Emitted(77, 305) Source(153, 15) + SourceIndex(0) -22>Emitted(77, 307) Source(153, 17) + SourceIndex(0) -23>Emitted(77, 308) Source(153, 18) + SourceIndex(0) -24>Emitted(77, 311) Source(153, 21) + SourceIndex(0) -25>Emitted(77, 312) Source(153, 22) + SourceIndex(0) -26>Emitted(77, 314) Source(153, 24) + SourceIndex(0) -27>Emitted(77, 315) Source(153, 25) + SourceIndex(0) -28>Emitted(77, 318) Source(153, 28) + SourceIndex(0) -29>Emitted(77, 319) Source(153, 29) + SourceIndex(0) -30>Emitted(77, 321) Source(153, 31) + SourceIndex(0) -31>Emitted(77, 322) Source(153, 32) + SourceIndex(0) -32>Emitted(77, 324) Source(153, 34) + SourceIndex(0) -33>Emitted(77, 326) Source(153, 36) + SourceIndex(0) -34>Emitted(77, 327) Source(153, 37) + SourceIndex(0) +22>Emitted(77, 307) Source(153, 5) + SourceIndex(0) +23>Emitted(77, 317) Source(153, 15) + SourceIndex(0) +24>Emitted(77, 319) Source(153, 17) + SourceIndex(0) +25>Emitted(77, 320) Source(153, 18) + SourceIndex(0) +26>Emitted(77, 323) Source(153, 21) + SourceIndex(0) +27>Emitted(77, 324) Source(153, 22) + SourceIndex(0) +28>Emitted(77, 326) Source(153, 24) + SourceIndex(0) +29>Emitted(77, 327) Source(153, 25) + SourceIndex(0) +30>Emitted(77, 330) Source(153, 28) + SourceIndex(0) +31>Emitted(77, 331) Source(153, 29) + SourceIndex(0) +32>Emitted(77, 333) Source(153, 31) + SourceIndex(0) +33>Emitted(77, 334) Source(153, 32) + SourceIndex(0) +34>Emitted(77, 336) Source(153, 34) + SourceIndex(0) +35>Emitted(77, 338) Source(153, 36) + SourceIndex(0) +36>Emitted(77, 339) Source(153, 37) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -3114,48 +3138,48 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(79, 1) Source(155, 1) + SourceIndex(0) 2 >Emitted(79, 2) Source(155, 2) + SourceIndex(0) --- ->>>for (_52 = getMultiRobot(), _53 = _52.name, name = _53 === void 0 ? "noName" : _53, _54 = _52.skills, _55 = _54 === void 0 ? { primary: "none", secondary: "none" } : _54, _56 = _55.primary, primary = _56 === void 0 ? "primary" : _56, _57 = _55.secondary, secondary = _57 === void 0 ? "secondary" : _57, _52, i = 0; i < 1; i++) { +>>>for (_52 = getMultiRobot(), (_53 = _52.name, name = _53 === void 0 ? "noName" : _53, _54 = _52.skills, _55 = _54 === void 0 ? { primary: "none", secondary: "none" } : _54, _56 = _55.primary, primary = _56 === void 0 ? "primary" : _56, _57 = _55.secondary, secondary = _57 === void 0 ? "secondary" : _57, _52), _52, i = 0; i < 1; i++) { 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -18> ^^ -19> ^^^^^^^^^^^^^^^^^^^ -20> ^^ -21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -22> ^^^^^^^ -23> ^ -24> ^^^ -25> ^ -26> ^^ -27> ^ -28> ^^^ -29> ^ -30> ^^ -31> ^ -32> ^^ -33> ^^ -34> ^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +18> ^^ +19> ^^^^^^^^^^^^^^^^^^^ +20> ^^ +21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22> ^^^^^^^^^^^^^ +23> ^ +24> ^^^ +25> ^ +26> ^^ +27> ^ +28> ^^^ +29> ^ +30> ^^ +31> ^ +32> ^^ +33> ^^ +34> ^ 1-> > 2 >for @@ -3169,78 +3193,78 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = getMultiRobot() 6 > -7 > name = "noName" -8 > -9 > name = "noName" -10> , - > -11> skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -12> -13> skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -14> -15> primary = "primary" -16> -17> primary = "primary" -18> , - > -19> secondary = "secondary" -20> -21> secondary = "secondary" -22> - > } = { primary: "none", secondary: "none" } - > } = getMultiRobot(), -23> i -24> = -25> 0 -26> ; -27> i -28> < -29> 1 -30> ; -31> i -32> ++ -33> ) -34> { +7 > name = "noName" +8 > +9 > name = "noName" +10> , + > +11> skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +12> +13> skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +14> +15> primary = "primary" +16> +17> primary = "primary" +18> , + > +19> secondary = "secondary" +20> +21> secondary = "secondary" +22> + > } = { primary: "none", secondary: "none" } + > } = getMultiRobot(), +23> i +24> = +25> 0 +26> ; +27> i +28> < +29> 1 +30> ; +31> i +32> ++ +33> ) +34> { 1->Emitted(80, 1) Source(156, 1) + SourceIndex(0) 2 >Emitted(80, 4) Source(156, 4) + SourceIndex(0) 3 >Emitted(80, 5) Source(156, 5) + SourceIndex(0) 4 >Emitted(80, 6) Source(156, 6) + SourceIndex(0) 5 >Emitted(80, 27) Source(162, 20) + SourceIndex(0) -6 >Emitted(80, 29) Source(157, 5) + SourceIndex(0) -7 >Emitted(80, 43) Source(157, 20) + SourceIndex(0) -8 >Emitted(80, 45) Source(157, 5) + SourceIndex(0) -9 >Emitted(80, 83) Source(157, 20) + SourceIndex(0) -10>Emitted(80, 85) Source(158, 5) + SourceIndex(0) -11>Emitted(80, 101) Source(161, 47) + SourceIndex(0) -12>Emitted(80, 103) Source(158, 5) + SourceIndex(0) -13>Emitted(80, 170) Source(161, 47) + SourceIndex(0) -14>Emitted(80, 172) Source(159, 9) + SourceIndex(0) -15>Emitted(80, 189) Source(159, 28) + SourceIndex(0) -16>Emitted(80, 191) Source(159, 9) + SourceIndex(0) -17>Emitted(80, 233) Source(159, 28) + SourceIndex(0) -18>Emitted(80, 235) Source(160, 9) + SourceIndex(0) -19>Emitted(80, 254) Source(160, 32) + SourceIndex(0) -20>Emitted(80, 256) Source(160, 9) + SourceIndex(0) -21>Emitted(80, 302) Source(160, 32) + SourceIndex(0) -22>Emitted(80, 309) Source(162, 22) + SourceIndex(0) -23>Emitted(80, 310) Source(162, 23) + SourceIndex(0) -24>Emitted(80, 313) Source(162, 26) + SourceIndex(0) -25>Emitted(80, 314) Source(162, 27) + SourceIndex(0) -26>Emitted(80, 316) Source(162, 29) + SourceIndex(0) -27>Emitted(80, 317) Source(162, 30) + SourceIndex(0) -28>Emitted(80, 320) Source(162, 33) + SourceIndex(0) -29>Emitted(80, 321) Source(162, 34) + SourceIndex(0) -30>Emitted(80, 323) Source(162, 36) + SourceIndex(0) -31>Emitted(80, 324) Source(162, 37) + SourceIndex(0) -32>Emitted(80, 326) Source(162, 39) + SourceIndex(0) -33>Emitted(80, 328) Source(162, 41) + SourceIndex(0) -34>Emitted(80, 329) Source(162, 42) + SourceIndex(0) +6 >Emitted(80, 30) Source(157, 5) + SourceIndex(0) +7 >Emitted(80, 44) Source(157, 20) + SourceIndex(0) +8 >Emitted(80, 46) Source(157, 5) + SourceIndex(0) +9 >Emitted(80, 84) Source(157, 20) + SourceIndex(0) +10>Emitted(80, 86) Source(158, 5) + SourceIndex(0) +11>Emitted(80, 102) Source(161, 47) + SourceIndex(0) +12>Emitted(80, 104) Source(158, 5) + SourceIndex(0) +13>Emitted(80, 171) Source(161, 47) + SourceIndex(0) +14>Emitted(80, 173) Source(159, 9) + SourceIndex(0) +15>Emitted(80, 190) Source(159, 28) + SourceIndex(0) +16>Emitted(80, 192) Source(159, 9) + SourceIndex(0) +17>Emitted(80, 234) Source(159, 28) + SourceIndex(0) +18>Emitted(80, 236) Source(160, 9) + SourceIndex(0) +19>Emitted(80, 255) Source(160, 32) + SourceIndex(0) +20>Emitted(80, 257) Source(160, 9) + SourceIndex(0) +21>Emitted(80, 303) Source(160, 32) + SourceIndex(0) +22>Emitted(80, 316) Source(162, 22) + SourceIndex(0) +23>Emitted(80, 317) Source(162, 23) + SourceIndex(0) +24>Emitted(80, 320) Source(162, 26) + SourceIndex(0) +25>Emitted(80, 321) Source(162, 27) + SourceIndex(0) +26>Emitted(80, 323) Source(162, 29) + SourceIndex(0) +27>Emitted(80, 324) Source(162, 30) + SourceIndex(0) +28>Emitted(80, 327) Source(162, 33) + SourceIndex(0) +29>Emitted(80, 328) Source(162, 34) + SourceIndex(0) +30>Emitted(80, 330) Source(162, 36) + SourceIndex(0) +31>Emitted(80, 331) Source(162, 37) + SourceIndex(0) +32>Emitted(80, 333) Source(162, 39) + SourceIndex(0) +33>Emitted(80, 335) Source(162, 41) + SourceIndex(0) +34>Emitted(80, 336) Source(162, 42) + SourceIndex(0) --- >>> console.log(primaryA); 1 >^^^^ @@ -3272,35 +3296,35 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(82, 1) Source(164, 1) + SourceIndex(0) 2 >Emitted(82, 2) Source(164, 2) + SourceIndex(0) --- ->>>for (_58 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, _59 = _58.name, name = _59 === void 0 ? "noName" : _59, _60 = _58.skills, _61 = _60 === void 0 ? { primary: "none", secondary: "none" } : _60, _62 = _61.primary, primary = _62 === void 0 ? "primary" : _62, _63 = _61.secondary, secondary = _63 === void 0 ? "secondary" : _63, _58, +>>>for (_58 = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } }, (_59 = _58.name, name = _59 === void 0 ? "noName" : _59, _60 = _58.skills, _61 = _60 === void 0 ? { primary: "none", secondary: "none" } : _60, _62 = _61.primary, primary = _62 === void 0 ? "primary" : _62, _63 = _61.secondary, secondary = _63 === void 0 ? "secondary" : _63, _58), _58, 1-> 2 >^^^ 3 > ^ 4 > ^ 5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -6 > ^^ -7 > ^^^^^^^^^^^^^^ -8 > ^^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -10> ^^ -11> ^^^^^^^^^^^^^^^^ -12> ^^ -13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -14> ^^ -15> ^^^^^^^^^^^^^^^^^ -16> ^^ -17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -18> ^^ -19> ^^^^^^^^^^^^^^^^^^^ -20> ^^ -21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +6 > ^^^ +7 > ^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^ +12> ^^ +13> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +14> ^^ +15> ^^^^^^^^^^^^^^^^^ +16> ^^ +17> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +18> ^^ +19> ^^^^^^^^^^^^^^^^^^^ +20> ^^ +21> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> > 2 >for @@ -3314,50 +3338,50 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 > } = { primary: "none", secondary: "none" } > } = { name: "trimmer", skills: { primary: "trimming", secondary: "edging" } } 6 > -7 > name = "noName" -8 > -9 > name = "noName" -10> , - > -11> skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -12> -13> skills: { - > primary = "primary", - > secondary = "secondary" - > } = { primary: "none", secondary: "none" } -14> -15> primary = "primary" -16> -17> primary = "primary" -18> , - > -19> secondary = "secondary" -20> -21> secondary = "secondary" +7 > name = "noName" +8 > +9 > name = "noName" +10> , + > +11> skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +12> +13> skills: { + > primary = "primary", + > secondary = "secondary" + > } = { primary: "none", secondary: "none" } +14> +15> primary = "primary" +16> +17> primary = "primary" +18> , + > +19> secondary = "secondary" +20> +21> secondary = "secondary" 1->Emitted(83, 1) Source(165, 1) + SourceIndex(0) 2 >Emitted(83, 4) Source(165, 4) + SourceIndex(0) 3 >Emitted(83, 5) Source(165, 5) + SourceIndex(0) 4 >Emitted(83, 6) Source(165, 6) + SourceIndex(0) 5 >Emitted(83, 85) Source(171, 90) + SourceIndex(0) -6 >Emitted(83, 87) Source(166, 5) + SourceIndex(0) -7 >Emitted(83, 101) Source(166, 20) + SourceIndex(0) -8 >Emitted(83, 103) Source(166, 5) + SourceIndex(0) -9 >Emitted(83, 141) Source(166, 20) + SourceIndex(0) -10>Emitted(83, 143) Source(167, 5) + SourceIndex(0) -11>Emitted(83, 159) Source(170, 47) + SourceIndex(0) -12>Emitted(83, 161) Source(167, 5) + SourceIndex(0) -13>Emitted(83, 228) Source(170, 47) + SourceIndex(0) -14>Emitted(83, 230) Source(168, 9) + SourceIndex(0) -15>Emitted(83, 247) Source(168, 28) + SourceIndex(0) -16>Emitted(83, 249) Source(168, 9) + SourceIndex(0) -17>Emitted(83, 291) Source(168, 28) + SourceIndex(0) -18>Emitted(83, 293) Source(169, 9) + SourceIndex(0) -19>Emitted(83, 312) Source(169, 32) + SourceIndex(0) -20>Emitted(83, 314) Source(169, 9) + SourceIndex(0) -21>Emitted(83, 360) Source(169, 32) + SourceIndex(0) +6 >Emitted(83, 88) Source(166, 5) + SourceIndex(0) +7 >Emitted(83, 102) Source(166, 20) + SourceIndex(0) +8 >Emitted(83, 104) Source(166, 5) + SourceIndex(0) +9 >Emitted(83, 142) Source(166, 20) + SourceIndex(0) +10>Emitted(83, 144) Source(167, 5) + SourceIndex(0) +11>Emitted(83, 160) Source(170, 47) + SourceIndex(0) +12>Emitted(83, 162) Source(167, 5) + SourceIndex(0) +13>Emitted(83, 229) Source(170, 47) + SourceIndex(0) +14>Emitted(83, 231) Source(168, 9) + SourceIndex(0) +15>Emitted(83, 248) Source(168, 28) + SourceIndex(0) +16>Emitted(83, 250) Source(168, 9) + SourceIndex(0) +17>Emitted(83, 292) Source(168, 28) + SourceIndex(0) +18>Emitted(83, 294) Source(169, 9) + SourceIndex(0) +19>Emitted(83, 313) Source(169, 32) + SourceIndex(0) +20>Emitted(83, 315) Source(169, 9) + SourceIndex(0) +21>Emitted(83, 361) Source(169, 32) + SourceIndex(0) --- >>> i = 0; i < 1; i++) { 1 >^^^^ @@ -3434,12 +3458,13 @@ sourceFile:sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2 >>>} 1 > 2 >^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >} 1 >Emitted(86, 1) Source(174, 1) + SourceIndex(0) 2 >Emitted(86, 2) Source(174, 2) + SourceIndex(0) --- ->>>var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63; +>>>var _k, _q, _4, _9, _27, _33, _52, _58; +>>>var _a, _b, _c, _d, _e, _f, _g, _h, _j, _l, _m, _o, _p, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _5, _6, _7, _8, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _28, _29, _30, _31, _32, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _53, _54, _55, _56, _57, _59, _60, _61, _62, _63; >>>//# sourceMappingURL=sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/switchAssignmentCompat.errors.txt b/tests/baselines/reference/switchAssignmentCompat.errors.txt index 46c89fa5b52..747a1035b68 100644 --- a/tests/baselines/reference/switchAssignmentCompat.errors.txt +++ b/tests/baselines/reference/switchAssignmentCompat.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type '0'. +tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'. ==== tests/cases/compiler/switchAssignmentCompat.ts (1 errors) ==== @@ -7,6 +7,6 @@ tests/cases/compiler/switchAssignmentCompat.ts(4,10): error TS2678: Type 'typeof switch (0) { case Foo: break; // Error expected ~~~ -!!! error TS2678: Type 'typeof Foo' is not comparable to type '0'. +!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/switchCaseCircularRefeference.errors.txt b/tests/baselines/reference/switchCaseCircularRefeference.errors.txt index 9ee571de468..bc576f8e723 100644 --- a/tests/baselines/reference/switchCaseCircularRefeference.errors.txt +++ b/tests/baselines/reference/switchCaseCircularRefeference.errors.txt @@ -1,6 +1,5 @@ -tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'. - Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'. - Type '{ a: "C"; e: any; }' is not comparable to type '"C"'. +tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type 'string'. + Type '{ a: "C"; e: any; }' is not comparable to type 'string'. ==== tests/cases/compiler/switchCaseCircularRefeference.ts (1 errors) ==== @@ -10,9 +9,8 @@ tests/cases/compiler/switchCaseCircularRefeference.ts(5,10): error TS2678: Type switch (x.a) { case x: ~ -!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type '"A" | "C"'. -!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"A" | "C"'. -!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type '"C"'. +!!! error TS2678: Type '{ a: "A"; b: any; } | { a: "C"; e: any; }' is not comparable to type 'string'. +!!! error TS2678: Type '{ a: "C"; e: any; }' is not comparable to type 'string'. break; } } \ No newline at end of file diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt index 3ea12e2460f..7a5fd12182e 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type '0'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'. tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type '"sss"' is not comparable to type '0'. tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(6,10): error TS2678: Type '123' is not comparable to type '0'. tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'true' is not comparable to type '0'. @@ -10,11 +10,11 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: T switch (0) { case Foo: break; // Error ~~~ -!!! error TS2678: Type 'typeof Foo' is not comparable to type '0'. +!!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'. case "sss": break; // Error ~~~~~ !!! error TS2678: Type '"sss"' is not comparable to type '0'. - case 123: break; // No Error + case 123: break; // Error ~~~ !!! error TS2678: Type '123' is not comparable to type '0'. case true: break; // Error @@ -30,4 +30,5 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: T case "sss": break; case 123: break; case true: break; - } \ No newline at end of file + } + \ No newline at end of file diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.js b/tests/baselines/reference/switchCasesExpressionTypeMismatch.js index ba929691d25..43a43224579 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.js +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.js @@ -4,7 +4,7 @@ class Foo { } switch (0) { case Foo: break; // Error case "sss": break; // Error - case 123: break; // No Error + case 123: break; // Error case true: break; // Error } @@ -16,7 +16,8 @@ switch (s) { case "sss": break; case 123: break; case true: break; -} +} + //// [switchCasesExpressionTypeMismatch.js] var Foo = (function () { @@ -27,7 +28,7 @@ var Foo = (function () { switch (0) { case Foo: break; // Error case "sss": break; // Error - case 123: break; // No Error + case 123: break; // Error case true: break; // Error } var s = 0; diff --git a/tests/baselines/reference/switchComparableCompatForBrands.js b/tests/baselines/reference/switchComparableCompatForBrands.js new file mode 100644 index 00000000000..316edfc9c31 --- /dev/null +++ b/tests/baselines/reference/switchComparableCompatForBrands.js @@ -0,0 +1,29 @@ +//// [switchComparableCompatForBrands.ts] +class MyBrand +{ + private _a: number; +} + +function test(strInput: string & MyBrand) { + switch(strInput) + { + case "a": + return 1; + } + return 0; +} + + +//// [switchComparableCompatForBrands.js] +var MyBrand = (function () { + function MyBrand() { + } + return MyBrand; +}()); +function test(strInput) { + switch (strInput) { + case "a": + return 1; + } + return 0; +} diff --git a/tests/baselines/reference/switchComparableCompatForBrands.symbols b/tests/baselines/reference/switchComparableCompatForBrands.symbols new file mode 100644 index 00000000000..adf6a5174ad --- /dev/null +++ b/tests/baselines/reference/switchComparableCompatForBrands.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/switchComparableCompatForBrands.ts === +class MyBrand +>MyBrand : Symbol(MyBrand, Decl(switchComparableCompatForBrands.ts, 0, 0)) +{ + private _a: number; +>_a : Symbol(MyBrand._a, Decl(switchComparableCompatForBrands.ts, 1, 1)) +} + +function test(strInput: string & MyBrand) { +>test : Symbol(test, Decl(switchComparableCompatForBrands.ts, 3, 1)) +>strInput : Symbol(strInput, Decl(switchComparableCompatForBrands.ts, 5, 14)) +>MyBrand : Symbol(MyBrand, Decl(switchComparableCompatForBrands.ts, 0, 0)) + + switch(strInput) +>strInput : Symbol(strInput, Decl(switchComparableCompatForBrands.ts, 5, 14)) + { + case "a": + return 1; + } + return 0; +} + diff --git a/tests/baselines/reference/switchComparableCompatForBrands.types b/tests/baselines/reference/switchComparableCompatForBrands.types new file mode 100644 index 00000000000..5e479ee29dc --- /dev/null +++ b/tests/baselines/reference/switchComparableCompatForBrands.types @@ -0,0 +1,26 @@ +=== tests/cases/compiler/switchComparableCompatForBrands.ts === +class MyBrand +>MyBrand : MyBrand +{ + private _a: number; +>_a : number +} + +function test(strInput: string & MyBrand) { +>test : (strInput: string & MyBrand) => 1 | 0 +>strInput : string & MyBrand +>MyBrand : MyBrand + + switch(strInput) +>strInput : string & MyBrand + { + case "a": +>"a" : "a" + + return 1; +>1 : 1 + } + return 0; +>0 : 0 +} + diff --git a/tests/baselines/reference/transpile/Supports setting jsxFactory.js b/tests/baselines/reference/transpile/Supports setting jsxFactory.js new file mode 100644 index 00000000000..8d91090453b --- /dev/null +++ b/tests/baselines/reference/transpile/Supports setting jsxFactory.js @@ -0,0 +1,3 @@ +"use strict"; +x; +//# sourceMappingURL=input.js.map \ No newline at end of file diff --git a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json index eec78e40192..2befbbde729 100644 --- a/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json +++ b/tests/baselines/reference/typeRootsFromMultipleNodeModulesDirectories.trace.json @@ -9,12 +9,8 @@ "File '/foo/bar/node_modules/xyz/index.ts' does not exist.", "File '/foo/bar/node_modules/xyz/index.tsx' does not exist.", "File '/foo/bar/node_modules/xyz/index.d.ts' does not exist.", - "File '/foo/bar/node_modules/@types/xyz.ts' does not exist.", - "File '/foo/bar/node_modules/@types/xyz.tsx' does not exist.", "File '/foo/bar/node_modules/@types/xyz.d.ts' does not exist.", "File '/foo/bar/node_modules/@types/xyz/package.json' does not exist.", - "File '/foo/bar/node_modules/@types/xyz/index.ts' does not exist.", - "File '/foo/bar/node_modules/@types/xyz/index.tsx' does not exist.", "File '/foo/bar/node_modules/@types/xyz/index.d.ts' does not exist.", "File '/foo/node_modules/xyz.ts' does not exist.", "File '/foo/node_modules/xyz.tsx' does not exist.", @@ -23,12 +19,8 @@ "File '/foo/node_modules/xyz/index.ts' does not exist.", "File '/foo/node_modules/xyz/index.tsx' does not exist.", "File '/foo/node_modules/xyz/index.d.ts' does not exist.", - "File '/foo/node_modules/@types/xyz.ts' does not exist.", - "File '/foo/node_modules/@types/xyz.tsx' does not exist.", "File '/foo/node_modules/@types/xyz.d.ts' does not exist.", "File '/foo/node_modules/@types/xyz/package.json' does not exist.", - "File '/foo/node_modules/@types/xyz/index.ts' does not exist.", - "File '/foo/node_modules/@types/xyz/index.tsx' does not exist.", "File '/foo/node_modules/@types/xyz/index.d.ts' does not exist.", "File '/node_modules/xyz.ts' does not exist.", "File '/node_modules/xyz.tsx' does not exist.", @@ -37,12 +29,8 @@ "File '/node_modules/xyz/index.ts' does not exist.", "File '/node_modules/xyz/index.tsx' does not exist.", "File '/node_modules/xyz/index.d.ts' does not exist.", - "File '/node_modules/@types/xyz.ts' does not exist.", - "File '/node_modules/@types/xyz.tsx' does not exist.", "File '/node_modules/@types/xyz.d.ts' does not exist.", "File '/node_modules/@types/xyz/package.json' does not exist.", - "File '/node_modules/@types/xyz/index.ts' does not exist.", - "File '/node_modules/@types/xyz/index.tsx' does not exist.", "File '/node_modules/@types/xyz/index.d.ts' does not exist.", "Loading module 'xyz' from 'node_modules' folder.", "File '/foo/bar/node_modules/xyz.js' does not exist.", @@ -50,31 +38,16 @@ "File '/foo/bar/node_modules/xyz/package.json' does not exist.", "File '/foo/bar/node_modules/xyz/index.js' does not exist.", "File '/foo/bar/node_modules/xyz/index.jsx' does not exist.", - "File '/foo/bar/node_modules/@types/xyz.js' does not exist.", - "File '/foo/bar/node_modules/@types/xyz.jsx' does not exist.", - "File '/foo/bar/node_modules/@types/xyz/package.json' does not exist.", - "File '/foo/bar/node_modules/@types/xyz/index.js' does not exist.", - "File '/foo/bar/node_modules/@types/xyz/index.jsx' does not exist.", "File '/foo/node_modules/xyz.js' does not exist.", "File '/foo/node_modules/xyz.jsx' does not exist.", "File '/foo/node_modules/xyz/package.json' does not exist.", "File '/foo/node_modules/xyz/index.js' does not exist.", "File '/foo/node_modules/xyz/index.jsx' does not exist.", - "File '/foo/node_modules/@types/xyz.js' does not exist.", - "File '/foo/node_modules/@types/xyz.jsx' does not exist.", - "File '/foo/node_modules/@types/xyz/package.json' does not exist.", - "File '/foo/node_modules/@types/xyz/index.js' does not exist.", - "File '/foo/node_modules/@types/xyz/index.jsx' does not exist.", "File '/node_modules/xyz.js' does not exist.", "File '/node_modules/xyz.jsx' does not exist.", "File '/node_modules/xyz/package.json' does not exist.", "File '/node_modules/xyz/index.js' does not exist.", "File '/node_modules/xyz/index.jsx' does not exist.", - "File '/node_modules/@types/xyz.js' does not exist.", - "File '/node_modules/@types/xyz.jsx' does not exist.", - "File '/node_modules/@types/xyz/package.json' does not exist.", - "File '/node_modules/@types/xyz/index.js' does not exist.", - "File '/node_modules/@types/xyz/index.jsx' does not exist.", "======== Module name 'xyz' was not resolved. ========", "======== Resolving module 'pdq' from '/foo/bar/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -86,12 +59,8 @@ "File '/foo/bar/node_modules/pdq/index.ts' does not exist.", "File '/foo/bar/node_modules/pdq/index.tsx' does not exist.", "File '/foo/bar/node_modules/pdq/index.d.ts' does not exist.", - "File '/foo/bar/node_modules/@types/pdq.ts' does not exist.", - "File '/foo/bar/node_modules/@types/pdq.tsx' does not exist.", "File '/foo/bar/node_modules/@types/pdq.d.ts' does not exist.", "File '/foo/bar/node_modules/@types/pdq/package.json' does not exist.", - "File '/foo/bar/node_modules/@types/pdq/index.ts' does not exist.", - "File '/foo/bar/node_modules/@types/pdq/index.tsx' does not exist.", "File '/foo/bar/node_modules/@types/pdq/index.d.ts' does not exist.", "File '/foo/node_modules/pdq.ts' does not exist.", "File '/foo/node_modules/pdq.tsx' does not exist.", @@ -100,12 +69,8 @@ "File '/foo/node_modules/pdq/index.ts' does not exist.", "File '/foo/node_modules/pdq/index.tsx' does not exist.", "File '/foo/node_modules/pdq/index.d.ts' does not exist.", - "File '/foo/node_modules/@types/pdq.ts' does not exist.", - "File '/foo/node_modules/@types/pdq.tsx' does not exist.", "File '/foo/node_modules/@types/pdq.d.ts' does not exist.", "File '/foo/node_modules/@types/pdq/package.json' does not exist.", - "File '/foo/node_modules/@types/pdq/index.ts' does not exist.", - "File '/foo/node_modules/@types/pdq/index.tsx' does not exist.", "File '/foo/node_modules/@types/pdq/index.d.ts' does not exist.", "File '/node_modules/pdq.ts' does not exist.", "File '/node_modules/pdq.tsx' does not exist.", @@ -114,12 +79,8 @@ "File '/node_modules/pdq/index.ts' does not exist.", "File '/node_modules/pdq/index.tsx' does not exist.", "File '/node_modules/pdq/index.d.ts' does not exist.", - "File '/node_modules/@types/pdq.ts' does not exist.", - "File '/node_modules/@types/pdq.tsx' does not exist.", "File '/node_modules/@types/pdq.d.ts' does not exist.", "File '/node_modules/@types/pdq/package.json' does not exist.", - "File '/node_modules/@types/pdq/index.ts' does not exist.", - "File '/node_modules/@types/pdq/index.tsx' does not exist.", "File '/node_modules/@types/pdq/index.d.ts' does not exist.", "Loading module 'pdq' from 'node_modules' folder.", "File '/foo/bar/node_modules/pdq.js' does not exist.", @@ -127,31 +88,16 @@ "File '/foo/bar/node_modules/pdq/package.json' does not exist.", "File '/foo/bar/node_modules/pdq/index.js' does not exist.", "File '/foo/bar/node_modules/pdq/index.jsx' does not exist.", - "File '/foo/bar/node_modules/@types/pdq.js' does not exist.", - "File '/foo/bar/node_modules/@types/pdq.jsx' does not exist.", - "File '/foo/bar/node_modules/@types/pdq/package.json' does not exist.", - "File '/foo/bar/node_modules/@types/pdq/index.js' does not exist.", - "File '/foo/bar/node_modules/@types/pdq/index.jsx' does not exist.", "File '/foo/node_modules/pdq.js' does not exist.", "File '/foo/node_modules/pdq.jsx' does not exist.", "File '/foo/node_modules/pdq/package.json' does not exist.", "File '/foo/node_modules/pdq/index.js' does not exist.", "File '/foo/node_modules/pdq/index.jsx' does not exist.", - "File '/foo/node_modules/@types/pdq.js' does not exist.", - "File '/foo/node_modules/@types/pdq.jsx' does not exist.", - "File '/foo/node_modules/@types/pdq/package.json' does not exist.", - "File '/foo/node_modules/@types/pdq/index.js' does not exist.", - "File '/foo/node_modules/@types/pdq/index.jsx' does not exist.", "File '/node_modules/pdq.js' does not exist.", "File '/node_modules/pdq.jsx' does not exist.", "File '/node_modules/pdq/package.json' does not exist.", "File '/node_modules/pdq/index.js' does not exist.", "File '/node_modules/pdq/index.jsx' does not exist.", - "File '/node_modules/@types/pdq.js' does not exist.", - "File '/node_modules/@types/pdq.jsx' does not exist.", - "File '/node_modules/@types/pdq/package.json' does not exist.", - "File '/node_modules/@types/pdq/index.js' does not exist.", - "File '/node_modules/@types/pdq/index.jsx' does not exist.", "======== Module name 'pdq' was not resolved. ========", "======== Resolving module 'abc' from '/foo/bar/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -163,12 +109,8 @@ "File '/foo/bar/node_modules/abc/index.ts' does not exist.", "File '/foo/bar/node_modules/abc/index.tsx' does not exist.", "File '/foo/bar/node_modules/abc/index.d.ts' does not exist.", - "File '/foo/bar/node_modules/@types/abc.ts' does not exist.", - "File '/foo/bar/node_modules/@types/abc.tsx' does not exist.", "File '/foo/bar/node_modules/@types/abc.d.ts' does not exist.", "File '/foo/bar/node_modules/@types/abc/package.json' does not exist.", - "File '/foo/bar/node_modules/@types/abc/index.ts' does not exist.", - "File '/foo/bar/node_modules/@types/abc/index.tsx' does not exist.", "File '/foo/bar/node_modules/@types/abc/index.d.ts' does not exist.", "File '/foo/node_modules/abc.ts' does not exist.", "File '/foo/node_modules/abc.tsx' does not exist.", @@ -177,12 +119,8 @@ "File '/foo/node_modules/abc/index.ts' does not exist.", "File '/foo/node_modules/abc/index.tsx' does not exist.", "File '/foo/node_modules/abc/index.d.ts' does not exist.", - "File '/foo/node_modules/@types/abc.ts' does not exist.", - "File '/foo/node_modules/@types/abc.tsx' does not exist.", "File '/foo/node_modules/@types/abc.d.ts' does not exist.", "File '/foo/node_modules/@types/abc/package.json' does not exist.", - "File '/foo/node_modules/@types/abc/index.ts' does not exist.", - "File '/foo/node_modules/@types/abc/index.tsx' does not exist.", "File '/foo/node_modules/@types/abc/index.d.ts' does not exist.", "File '/node_modules/abc.ts' does not exist.", "File '/node_modules/abc.tsx' does not exist.", @@ -191,12 +129,8 @@ "File '/node_modules/abc/index.ts' does not exist.", "File '/node_modules/abc/index.tsx' does not exist.", "File '/node_modules/abc/index.d.ts' does not exist.", - "File '/node_modules/@types/abc.ts' does not exist.", - "File '/node_modules/@types/abc.tsx' does not exist.", "File '/node_modules/@types/abc.d.ts' does not exist.", "File '/node_modules/@types/abc/package.json' does not exist.", - "File '/node_modules/@types/abc/index.ts' does not exist.", - "File '/node_modules/@types/abc/index.tsx' does not exist.", "File '/node_modules/@types/abc/index.d.ts' does not exist.", "Loading module 'abc' from 'node_modules' folder.", "File '/foo/bar/node_modules/abc.js' does not exist.", @@ -204,31 +138,16 @@ "File '/foo/bar/node_modules/abc/package.json' does not exist.", "File '/foo/bar/node_modules/abc/index.js' does not exist.", "File '/foo/bar/node_modules/abc/index.jsx' does not exist.", - "File '/foo/bar/node_modules/@types/abc.js' does not exist.", - "File '/foo/bar/node_modules/@types/abc.jsx' does not exist.", - "File '/foo/bar/node_modules/@types/abc/package.json' does not exist.", - "File '/foo/bar/node_modules/@types/abc/index.js' does not exist.", - "File '/foo/bar/node_modules/@types/abc/index.jsx' does not exist.", "File '/foo/node_modules/abc.js' does not exist.", "File '/foo/node_modules/abc.jsx' does not exist.", "File '/foo/node_modules/abc/package.json' does not exist.", "File '/foo/node_modules/abc/index.js' does not exist.", "File '/foo/node_modules/abc/index.jsx' does not exist.", - "File '/foo/node_modules/@types/abc.js' does not exist.", - "File '/foo/node_modules/@types/abc.jsx' does not exist.", - "File '/foo/node_modules/@types/abc/package.json' does not exist.", - "File '/foo/node_modules/@types/abc/index.js' does not exist.", - "File '/foo/node_modules/@types/abc/index.jsx' does not exist.", "File '/node_modules/abc.js' does not exist.", "File '/node_modules/abc.jsx' does not exist.", "File '/node_modules/abc/package.json' does not exist.", "File '/node_modules/abc/index.js' does not exist.", "File '/node_modules/abc/index.jsx' does not exist.", - "File '/node_modules/@types/abc.js' does not exist.", - "File '/node_modules/@types/abc.jsx' does not exist.", - "File '/node_modules/@types/abc/package.json' does not exist.", - "File '/node_modules/@types/abc/index.js' does not exist.", - "File '/node_modules/@types/abc/index.jsx' does not exist.", "======== Module name 'abc' was not resolved. ========", "======== Resolving type reference directive 'grumpy', containing file '/src/__inferred type names__.ts', root directory '/foo/node_modules/@types,/node_modules/@types'. ========", "Resolving with primary search path '/foo/node_modules/@types, /node_modules/@types'", diff --git a/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json b/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json index 4bb62bc255a..421c47d30ec 100644 --- a/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json +++ b/tests/baselines/reference/typeRootsFromNodeModulesInParentDirectory.trace.json @@ -9,12 +9,8 @@ "File '/src/node_modules/xyz/index.ts' does not exist.", "File '/src/node_modules/xyz/index.tsx' does not exist.", "File '/src/node_modules/xyz/index.d.ts' does not exist.", - "File '/src/node_modules/@types/xyz.ts' does not exist.", - "File '/src/node_modules/@types/xyz.tsx' does not exist.", "File '/src/node_modules/@types/xyz.d.ts' does not exist.", "File '/src/node_modules/@types/xyz/package.json' does not exist.", - "File '/src/node_modules/@types/xyz/index.ts' does not exist.", - "File '/src/node_modules/@types/xyz/index.tsx' does not exist.", "File '/src/node_modules/@types/xyz/index.d.ts' does not exist.", "File '/node_modules/xyz.ts' does not exist.", "File '/node_modules/xyz.tsx' does not exist.", @@ -23,12 +19,8 @@ "File '/node_modules/xyz/index.ts' does not exist.", "File '/node_modules/xyz/index.tsx' does not exist.", "File '/node_modules/xyz/index.d.ts' does not exist.", - "File '/node_modules/@types/xyz.ts' does not exist.", - "File '/node_modules/@types/xyz.tsx' does not exist.", "File '/node_modules/@types/xyz.d.ts' does not exist.", "File '/node_modules/@types/xyz/package.json' does not exist.", - "File '/node_modules/@types/xyz/index.ts' does not exist.", - "File '/node_modules/@types/xyz/index.tsx' does not exist.", "File '/node_modules/@types/xyz/index.d.ts' does not exist.", "Loading module 'xyz' from 'node_modules' folder.", "File '/src/node_modules/xyz.js' does not exist.", @@ -36,21 +28,11 @@ "File '/src/node_modules/xyz/package.json' does not exist.", "File '/src/node_modules/xyz/index.js' does not exist.", "File '/src/node_modules/xyz/index.jsx' does not exist.", - "File '/src/node_modules/@types/xyz.js' does not exist.", - "File '/src/node_modules/@types/xyz.jsx' does not exist.", - "File '/src/node_modules/@types/xyz/package.json' does not exist.", - "File '/src/node_modules/@types/xyz/index.js' does not exist.", - "File '/src/node_modules/@types/xyz/index.jsx' does not exist.", "File '/node_modules/xyz.js' does not exist.", "File '/node_modules/xyz.jsx' does not exist.", "File '/node_modules/xyz/package.json' does not exist.", "File '/node_modules/xyz/index.js' does not exist.", "File '/node_modules/xyz/index.jsx' does not exist.", - "File '/node_modules/@types/xyz.js' does not exist.", - "File '/node_modules/@types/xyz.jsx' does not exist.", - "File '/node_modules/@types/xyz/package.json' does not exist.", - "File '/node_modules/@types/xyz/index.js' does not exist.", - "File '/node_modules/@types/xyz/index.jsx' does not exist.", "======== Module name 'xyz' was not resolved. ========", "======== Resolving type reference directive 'foo', containing file '/src/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'", diff --git a/tests/baselines/reference/typingsLookup4.trace.json b/tests/baselines/reference/typingsLookup4.trace.json index bb9d94f43b5..d1c29b1f11b 100644 --- a/tests/baselines/reference/typingsLookup4.trace.json +++ b/tests/baselines/reference/typingsLookup4.trace.json @@ -9,8 +9,6 @@ "File '/node_modules/jquery/index.ts' does not exist.", "File '/node_modules/jquery/index.tsx' does not exist.", "File '/node_modules/jquery/index.d.ts' does not exist.", - "File '/node_modules/@types/jquery.ts' does not exist.", - "File '/node_modules/@types/jquery.tsx' does not exist.", "File '/node_modules/@types/jquery.d.ts' does not exist.", "Found 'package.json' at '/node_modules/@types/jquery/package.json'.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.", @@ -27,8 +25,6 @@ "File '/node_modules/kquery/index.ts' does not exist.", "File '/node_modules/kquery/index.tsx' does not exist.", "File '/node_modules/kquery/index.d.ts' does not exist.", - "File '/node_modules/@types/kquery.ts' does not exist.", - "File '/node_modules/@types/kquery.tsx' does not exist.", "File '/node_modules/@types/kquery.d.ts' does not exist.", "Found 'package.json' at '/node_modules/@types/kquery/package.json'.", "'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.", @@ -48,8 +44,6 @@ "File '/node_modules/lquery/index.ts' does not exist.", "File '/node_modules/lquery/index.tsx' does not exist.", "File '/node_modules/lquery/index.d.ts' does not exist.", - "File '/node_modules/@types/lquery.ts' does not exist.", - "File '/node_modules/@types/lquery.tsx' does not exist.", "File '/node_modules/@types/lquery.d.ts' does not exist.", "Found 'package.json' at '/node_modules/@types/lquery/package.json'.", "'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.", diff --git a/tests/baselines/reference/typingsLookupAmd.trace.json b/tests/baselines/reference/typingsLookupAmd.trace.json index 496166926a8..843f16fe8c6 100644 --- a/tests/baselines/reference/typingsLookupAmd.trace.json +++ b/tests/baselines/reference/typingsLookupAmd.trace.json @@ -10,19 +10,11 @@ "File '/b.ts' does not exist.", "File '/b.tsx' does not exist.", "File '/b.d.ts' does not exist.", - "File '/x/y/node_modules/@types/b.ts' does not exist.", - "File '/x/y/node_modules/@types/b.tsx' does not exist.", "File '/x/y/node_modules/@types/b.d.ts' does not exist.", "File '/x/y/node_modules/@types/b/package.json' does not exist.", - "File '/x/y/node_modules/@types/b/index.ts' does not exist.", - "File '/x/y/node_modules/@types/b/index.tsx' does not exist.", "File '/x/y/node_modules/@types/b/index.d.ts' does not exist.", - "File '/x/node_modules/@types/b.ts' does not exist.", - "File '/x/node_modules/@types/b.tsx' does not exist.", "File '/x/node_modules/@types/b.d.ts' does not exist.", "File '/x/node_modules/@types/b/package.json' does not exist.", - "File '/x/node_modules/@types/b/index.ts' does not exist.", - "File '/x/node_modules/@types/b/index.tsx' does not exist.", "File '/x/node_modules/@types/b/index.d.ts' exist - use it as a name resolution result.", "======== Module name 'b' was successfully resolved to '/x/node_modules/@types/b/index.d.ts'. ========", "======== Resolving module 'a' from '/x/node_modules/@types/b/index.d.ts'. ========", @@ -42,33 +34,17 @@ "File '/a.ts' does not exist.", "File '/a.tsx' does not exist.", "File '/a.d.ts' does not exist.", - "File '/x/node_modules/@types/b/node_modules/@types/a.ts' does not exist.", - "File '/x/node_modules/@types/b/node_modules/@types/a.tsx' does not exist.", "File '/x/node_modules/@types/b/node_modules/@types/a.d.ts' does not exist.", "File '/x/node_modules/@types/b/node_modules/@types/a/package.json' does not exist.", - "File '/x/node_modules/@types/b/node_modules/@types/a/index.ts' does not exist.", - "File '/x/node_modules/@types/b/node_modules/@types/a/index.tsx' does not exist.", "File '/x/node_modules/@types/b/node_modules/@types/a/index.d.ts' does not exist.", - "File '/x/node_modules/@types/node_modules/@types/a.ts' does not exist.", - "File '/x/node_modules/@types/node_modules/@types/a.tsx' does not exist.", "File '/x/node_modules/@types/node_modules/@types/a.d.ts' does not exist.", "File '/x/node_modules/@types/node_modules/@types/a/package.json' does not exist.", - "File '/x/node_modules/@types/node_modules/@types/a/index.ts' does not exist.", - "File '/x/node_modules/@types/node_modules/@types/a/index.tsx' does not exist.", "File '/x/node_modules/@types/node_modules/@types/a/index.d.ts' does not exist.", - "File '/x/node_modules/@types/a.ts' does not exist.", - "File '/x/node_modules/@types/a.tsx' does not exist.", "File '/x/node_modules/@types/a.d.ts' does not exist.", "File '/x/node_modules/@types/a/package.json' does not exist.", - "File '/x/node_modules/@types/a/index.ts' does not exist.", - "File '/x/node_modules/@types/a/index.tsx' does not exist.", "File '/x/node_modules/@types/a/index.d.ts' does not exist.", - "File '/node_modules/@types/a.ts' does not exist.", - "File '/node_modules/@types/a.tsx' does not exist.", "File '/node_modules/@types/a.d.ts' does not exist.", "File '/node_modules/@types/a/package.json' does not exist.", - "File '/node_modules/@types/a/index.ts' does not exist.", - "File '/node_modules/@types/a/index.tsx' does not exist.", "File '/node_modules/@types/a/index.d.ts' exist - use it as a name resolution result.", "======== Module name 'a' was successfully resolved to '/node_modules/@types/a/index.d.ts'. ========", "======== Resolving type reference directive 'a', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", diff --git a/tests/cases/compiler/alwaysStrictModule3.ts b/tests/cases/compiler/alwaysStrictModule3.ts new file mode 100644 index 00000000000..adb93cede36 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule3.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @module: es2015 + +// module ES2015 +export const a = 1; \ No newline at end of file diff --git a/tests/cases/compiler/alwaysStrictModule4.ts b/tests/cases/compiler/alwaysStrictModule4.ts new file mode 100644 index 00000000000..f731e6dd734 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule4.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @module: commonjs + +// Module commonjs +export const a = 1 \ No newline at end of file diff --git a/tests/cases/compiler/alwaysStrictModule5.ts b/tests/cases/compiler/alwaysStrictModule5.ts new file mode 100644 index 00000000000..d1ac5288370 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule5.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @target: es6 + +// Targeting ES6 +export const a = 1; \ No newline at end of file diff --git a/tests/cases/compiler/alwaysStrictModule6.ts b/tests/cases/compiler/alwaysStrictModule6.ts new file mode 100644 index 00000000000..064ece1a4e1 --- /dev/null +++ b/tests/cases/compiler/alwaysStrictModule6.ts @@ -0,0 +1,5 @@ +// @alwaysStrict: true +// @target: es5 + +// Targeting ES5 +export const a = 1; \ No newline at end of file diff --git a/tests/cases/compiler/commonSourceDirectory.ts b/tests/cases/compiler/commonSourceDirectory.ts new file mode 100644 index 00000000000..9baa27431a3 --- /dev/null +++ b/tests/cases/compiler/commonSourceDirectory.ts @@ -0,0 +1,30 @@ +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. +// @noImplicitReferences: true +// @moduleResolution: node +// @fullEmitPaths: true + +// @filename: /node_modules/foo/index.ts +export const x = 0; + +// @filename: /types/bar.d.ts +declare module "bar" { + export const y = 0; +} + +// @filename: /app/index.ts +/// +import { x } from "foo"; +import { y } from "bar"; +x + y; + +// @filename: /app/tsconfig.json +{ + "compilerOptions": { + "outDir": "bin", + "typeRoots": ["../types"], + "sourceMap": true, + "mapRoot": "myMapRoot", + "sourceRoot": "mySourceRoot", + "declaration": true + } +} diff --git a/tests/cases/compiler/commonSourceDirectory_dts.ts b/tests/cases/compiler/commonSourceDirectory_dts.ts new file mode 100644 index 00000000000..3a3dfea1772 --- /dev/null +++ b/tests/cases/compiler/commonSourceDirectory_dts.ts @@ -0,0 +1,22 @@ +// Test that importing a file from `node_modules` does not affect calculation of the common source directory. +// @noImplicitReferences: true +// @moduleResolution: node +// @fullEmitPaths: true + +// @filename: /app/lib/bar.d.ts +declare const y: number; + +// @filename: /app/src/index.ts +/// +export const x = y; + +// @filename: /app/tsconfig.json +{ + "compilerOptions": { + "outDir": "bin", + "sourceMap": true, + "mapRoot": "myMapRoot", + "sourceRoot": "mySourceRoot", + "declaration": true + } +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts new file mode 100644 index 00000000000..de94ad4998d --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters2.ts @@ -0,0 +1,6 @@ +// @declaration: true + +export type Bar = () => [X, Y, Z]; +export type Baz = Bar; +export type Baa = Baz; +export const y = (x: Baa) => 1 \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts new file mode 100644 index 00000000000..6c7d4799abc --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters3.ts @@ -0,0 +1,8 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +function bar() { + return {} as Foo; +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts new file mode 100644 index 00000000000..42bb8097997 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters4.ts @@ -0,0 +1,10 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts new file mode 100644 index 00000000000..b6334e76337 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts @@ -0,0 +1,10 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +export type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} diff --git a/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts new file mode 100644 index 00000000000..9b313027021 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters6.ts @@ -0,0 +1,10 @@ +// @declaration: true + +type Foo = { + foo(): Foo +}; +type SubFoo = Foo; + +function foo() { + return {} as SubFoo; +} diff --git a/tests/cases/compiler/decoratorInJsFile.ts b/tests/cases/compiler/decoratorInJsFile.ts new file mode 100644 index 00000000000..611be319209 --- /dev/null +++ b/tests/cases/compiler/decoratorInJsFile.ts @@ -0,0 +1,12 @@ +// @experimentaldecorators: true +// @emitdecoratormetadata: true +// @allowjs: true +// @noEmit: true + +// @filename: a.js +@SomeDecorator +class SomeClass { + foo(x: number) { + + } +} \ No newline at end of file diff --git a/tests/cases/compiler/decoratorInJsFile1.ts b/tests/cases/compiler/decoratorInJsFile1.ts new file mode 100644 index 00000000000..6bbe38cb835 --- /dev/null +++ b/tests/cases/compiler/decoratorInJsFile1.ts @@ -0,0 +1,10 @@ +// @allowjs: true +// @noEmit: true + +// @filename: a.js +@SomeDecorator +class SomeClass { + foo(x: number) { + + } +} \ No newline at end of file diff --git a/tests/cases/compiler/importHelpersNoHelpers.ts b/tests/cases/compiler/importHelpersNoHelpers.ts index 82428552548..4ab48aba7df 100644 --- a/tests/cases/compiler/importHelpersNoHelpers.ts +++ b/tests/cases/compiler/importHelpersNoHelpers.ts @@ -16,6 +16,10 @@ class C { } } +const o = { a: 1 }; +const y = { ...o }; +const { ...x } = y; + // @filename: script.ts class A { } class B extends A { } @@ -29,4 +33,4 @@ class C { } // @filename: tslib.d.ts -export {} \ No newline at end of file +export {} diff --git a/tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts b/tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts new file mode 100644 index 00000000000..493feef1fd7 --- /dev/null +++ b/tests/cases/compiler/incompatibleAssignmentOfIdenticallyNamedTypes.ts @@ -0,0 +1,8 @@ +interface T { } +declare const a: T; +class Foo { + x: T; + fn() { + this.x = a; + } +} diff --git a/tests/cases/compiler/jsFileCompilationAbstractModifier.ts b/tests/cases/compiler/jsFileCompilationAbstractModifier.ts new file mode 100644 index 00000000000..ebd021e05a1 --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationAbstractModifier.ts @@ -0,0 +1,5 @@ +// @allowJs: true +// @filename: a.js +abstract class c { + abstract x; +} \ No newline at end of file diff --git a/tests/cases/compiler/jsFileCompilationConstModifier.ts b/tests/cases/compiler/jsFileCompilationConstModifier.ts new file mode 100644 index 00000000000..4ffa62bb6a2 --- /dev/null +++ b/tests/cases/compiler/jsFileCompilationConstModifier.ts @@ -0,0 +1,4 @@ +// @allowJs: true +// @filename: a.js +// @noEmit: true +const c = 10; \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryAndReactNamespace.ts b/tests/cases/compiler/jsxFactoryAndReactNamespace.ts new file mode 100644 index 00000000000..2bdc954da3a --- /dev/null +++ b/tests/cases/compiler/jsxFactoryAndReactNamespace.ts @@ -0,0 +1,54 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@reactNamespace: Element +//@jsxFactory: Element.createElement + +// @filename: Element.ts +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +// @filename: test.tsx +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryIdentifier.ts b/tests/cases/compiler/jsxFactoryIdentifier.ts new file mode 100644 index 00000000000..88caf27482e --- /dev/null +++ b/tests/cases/compiler/jsxFactoryIdentifier.ts @@ -0,0 +1,54 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: createElement +//@sourcemap: true + +// @filename: Element.ts +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +// @filename: test.tsx +import { Element} from './Element'; +let createElement = Element.createElement; +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryIdentifierAsParameter.ts b/tests/cases/compiler/jsxFactoryIdentifierAsParameter.ts new file mode 100644 index 00000000000..bd92a473428 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryIdentifierAsParameter.ts @@ -0,0 +1,18 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: createElement +//@sourcemap: true + +// @filename: test.tsx +declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } +} + +export class AppComponent { + render(createElement) { + return
; + } +} diff --git a/tests/cases/compiler/jsxFactoryIdentifierWithAbsentParameter.ts b/tests/cases/compiler/jsxFactoryIdentifierWithAbsentParameter.ts new file mode 100644 index 00000000000..49e485a1085 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryIdentifierWithAbsentParameter.ts @@ -0,0 +1,18 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: createElement +//@sourcemap: true + +// @filename: test.tsx +declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } +} + +export class AppComponent { + render() { + return
; + } +} diff --git a/tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName.ts b/tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName.ts new file mode 100644 index 00000000000..6f7c584d232 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName.ts @@ -0,0 +1,53 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: Element.createElement= + +// @filename: Element.ts +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +// @filename: test.tsx +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName2.ts b/tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName2.ts new file mode 100644 index 00000000000..610063f7d34 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryNotIdentifierOrQualifiedName2.ts @@ -0,0 +1,53 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: id1 id2 + +// @filename: Element.ts +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +// @filename: test.tsx +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryQualifiedName.ts b/tests/cases/compiler/jsxFactoryQualifiedName.ts new file mode 100644 index 00000000000..769b7cd566d --- /dev/null +++ b/tests/cases/compiler/jsxFactoryQualifiedName.ts @@ -0,0 +1,54 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: Element.createElement +//@sourcemap: true + +// @filename: Element.ts +declare namespace JSX { + interface Element { + name: string; + isIntrinsic: boolean; + isCustomElement: boolean; + toString(renderId?: number): string; + bindDOM(renderId?: number): number; + resetComponent(): void; + instantiateComponents(renderId?: number): number; + props: any; + } +} +export namespace Element { + export function isElement(el: any): el is JSX.Element { + return el.markAsChildOfRootElement !== undefined; + } + + export function createElement(args: any[]) { + + return { + } + } +} + +export let createElement = Element.createElement; + +function toCamelCase(text: string): string { + return text[0].toLowerCase() + text.substring(1); +} + +// @filename: test.tsx +import { Element} from './Element'; + +let c: { + a?: { + b: string + } +}; + +class A { + view() { + return [ + , + + ]; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/jsxFactoryQualifiedNameResolutionError.ts b/tests/cases/compiler/jsxFactoryQualifiedNameResolutionError.ts new file mode 100644 index 00000000000..a8996245138 --- /dev/null +++ b/tests/cases/compiler/jsxFactoryQualifiedNameResolutionError.ts @@ -0,0 +1,18 @@ +//@jsx: react +//@target: es6 +//@module: commonjs +//@jsxFactory: MyElement.createElement +//@sourcemap: true + +// @filename: test.tsx +declare module JSX { + interface IntrinsicElements { + [s: string]: any; + } +} + +export class AppComponent { + render(createElement) { + return
; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/switchCasesExpressionTypeMismatch.ts b/tests/cases/compiler/switchCasesExpressionTypeMismatch.ts index 4de01ebba17..ee547705b84 100644 --- a/tests/cases/compiler/switchCasesExpressionTypeMismatch.ts +++ b/tests/cases/compiler/switchCasesExpressionTypeMismatch.ts @@ -3,7 +3,7 @@ class Foo { } switch (0) { case Foo: break; // Error case "sss": break; // Error - case 123: break; // No Error + case 123: break; // Error case true: break; // Error } @@ -15,4 +15,4 @@ switch (s) { case "sss": break; case 123: break; case true: break; -} \ No newline at end of file +} diff --git a/tests/cases/compiler/switchComparableCompatForBrands.ts b/tests/cases/compiler/switchComparableCompatForBrands.ts new file mode 100644 index 00000000000..4b90db40e1d --- /dev/null +++ b/tests/cases/compiler/switchComparableCompatForBrands.ts @@ -0,0 +1,13 @@ +class MyBrand +{ + private _a: number; +} + +function test(strInput: string & MyBrand) { + switch(strInput) + { + case "a": + return 1; + } + return 0; +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts index 2b3192bc9a2..1e2bc1e68b4 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts @@ -3,8 +3,5 @@ var {h?} = { h?: 1 }; var {i}: string | number = { i: 2 }; var {i1}: string | number| {} = { i1: 2 }; var { f2: {f21} = { f212: "string" } }: any = undefined; -var { ...d1 } = { - a: 1, b: 1, d1: 9, e: 10 -} var {1} = { 1 }; -var {"prop"} = { "prop": 1 }; \ No newline at end of file +var {"prop"} = { "prop": 1 }; diff --git a/tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts b/tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts new file mode 100644 index 00000000000..4d87ffcab13 --- /dev/null +++ b/tests/cases/conformance/externalModules/globalAugmentationModuleResolution.ts @@ -0,0 +1,8 @@ +// @traceResolution: true + +// @fileName: a.ts +export { }; + +declare global { + var x: number; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/rest/objectRest.ts b/tests/cases/conformance/types/rest/objectRest.ts new file mode 100644 index 00000000000..f1a77b1c129 --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRest.ts @@ -0,0 +1,33 @@ +// @target: es2015 +let o = { a: 1, b: 'no' } +var { ...clone } = o; +var { a, ...justB } = o; +var { a, b: renamed, ...empty } = o; +var { ['b']: renamed, ...justA } = o; +var { 'b': renamed, ...justA } = o; +var { b: { '0': n, '1': oooo }, ...justA } = o; + +let o2 = { c: 'terrible idea?', d: 'yes' }; +var { d: renamed, ...d } = o2; + +let nestedrest: { x: number, n1: { y: number, n2: { z: number, n3: { n4: number } } }, rest: number, restrest: number }; +var { x, n1: { y, n2: { z, n3: { ...nr } } }, ...restrest } = nestedrest; + +let complex: { x: { ka, ki }, y: number }; +var { x: { ka, ...nested }, y: other, ...rest } = complex; +({x: { ka, ...nested }, y: other, ...rest} = complex); +var { x, ...fresh } = { x: 1, y: 2 }; +({ x, ...fresh } = { x: 1, y: 2 }); + +class Removable { + private x: number; + protected y: number; + set z(value: number) { } + get both(): number { return 12 } + set both(value: number) { } + m() { } + removed: string; + remainder: string; +} +var removable = new Removable(); +var { removed, ...removableRest } = removable; diff --git a/tests/cases/conformance/types/rest/objectRestAssignment.ts b/tests/cases/conformance/types/rest/objectRestAssignment.ts new file mode 100644 index 00000000000..dedc99b1f71 --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRestAssignment.ts @@ -0,0 +1,14 @@ +// @target: es2015 +let ka: any; +let nested: { ki }; +let other: number; +let rest: { }; +let complex: { x: { ka, ki }, y: number }; +({x: { ka, ...nested }, y: other, ...rest} = complex); + +// should be: +let overEmit: { a: { ka: string, x: string }[], b: { z: string, ki: string, ku: string }, ke: string, ko: string }; + +// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]); +var { a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit; +({ a: [{ ...nested2 }, ...y], b: { z, ...c }, ...rest2 } = overEmit); diff --git a/tests/cases/conformance/types/rest/objectRestForOf.ts b/tests/cases/conformance/types/rest/objectRestForOf.ts new file mode 100644 index 00000000000..4f675b1f15b --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRestForOf.ts @@ -0,0 +1,14 @@ +// @target: es2015 +let array: { x: number, y: string }[]; +for (let { x, ...restOf } of array) { + [x, restOf]; +} +let xx: number; +let rrestOff: { y: string }; +for ({ x: xx, ...rrestOff } of array ) { + [xx, rrestOff]; +} +for (const norest of array.map(a => ({ ...a, x: 'a string' }))) { + [norest.x, norest.y]; + // x is now a string. who knows why. +} diff --git a/tests/cases/conformance/types/rest/objectRestNegative.ts b/tests/cases/conformance/types/rest/objectRestNegative.ts new file mode 100644 index 00000000000..75cbe9a55e4 --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRestNegative.ts @@ -0,0 +1,11 @@ +let o = { a: 1, b: 'no' }; +var { ...mustBeLast, a } = o; +function stillMustBeLast({ ...mustBeLast, a }: { a: number, b: string }): void { +} +function generic(t: T) { + let { x, ...rest } = t; + return rest; +} + +let rest: { b: string } +({a, ...rest.b + rest.b} = o); diff --git a/tests/cases/conformance/types/rest/objectRestParameter.ts b/tests/cases/conformance/types/rest/objectRestParameter.ts new file mode 100644 index 00000000000..5b47442f047 --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRestParameter.ts @@ -0,0 +1,8 @@ +// @target: es2015 +function cloneAgain({ a, ...clone }: { a: number, b: string }): void { +} + +declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void); +suddenly(({ x: a, ...rest }) => rest.y); +suddenly(({ x: { z = 12, ...nested }, ...rest } = { x: { z: 1, ka: 1 }, y: 'noo' }) => rest.y + nested.ka); + diff --git a/tests/cases/conformance/es6/destructuring/restElementMustBeLast.ts b/tests/cases/conformance/types/rest/restElementMustBeLast.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/restElementMustBeLast.ts rename to tests/cases/conformance/types/rest/restElementMustBeLast.ts diff --git a/tests/cases/conformance/types/spread/objectSpread.ts b/tests/cases/conformance/types/spread/objectSpread.ts new file mode 100644 index 00000000000..ebf2bdb2ade --- /dev/null +++ b/tests/cases/conformance/types/spread/objectSpread.ts @@ -0,0 +1,81 @@ +// @target: es5 +let o = { a: 1, b: 'no' } +let o2 = { b: 'yes', c: true } +let swap = { a: 'yes', b: -1 }; + +let addAfter: { a: number, b: string, c: boolean } = + { ...o, c: false } +let addBefore: { a: number, b: string, c: boolean } = + { c: false, ...o } +// Note: ignore still changes the order that properties are printed +let ignore: { a: number, b: string } = + { b: 'ignored', ...o } +let override: { a: number, b: string } = + { ...o, b: 'override' } +let nested: { a: number, b: boolean, c: string } = + { ...{ a: 3, ...{ b: false, c: 'overriden' } }, c: 'whatever' } +let combined: { a: number, b: string, c: boolean } = + { ...o, ...o2 } +let combinedBefore: { a: number, b: string, c: boolean } = + { b: 'ok', ...o, ...o2 } +let combinedMid: { a: number, b: string, c: boolean } = + { ...o, b: 'ok', ...o2 } +let combinedAfter: { a: number, b: string, c: boolean } = + { ...o, ...o2, b: 'ok' } +let combinedNested: { a: number, b: boolean, c: string, d: string } = + { ...{ a: 4, ...{ b: false, c: 'overriden' } }, d: 'actually new', ...{ a: 5, d: 'maybe new' } } +let combinedNestedChangeType: { a: number, b: boolean, c: number } = + { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } +let propertyNested: { a: { a: number, b: string } } = + { a: { ... o } } +// accessors don't copy the descriptor +// (which means that readonly getters become read/write properties) +let op = { get a () { return 6 } }; +let getter: { a: number, c: number } = + { ...op, c: 7 } +getter.a = 12; + +// functions result in { } +let spreadFunc = { ...(function () { }) }; + +// any results in any +let anything: any; +let spreadAny = { ...anything }; + +// methods are not enumerable +class C { p = 1; m() { } } +let c: C = new C() +let spreadC: { p: number } = { ...c } + +// own methods are enumerable +let cplus: { p: number, plus(): void } = { ...c, plus() { return this.p + 1; } }; +cplus.plus(); + +// new field's type conflicting with existing field is OK +let changeTypeAfter: { a: string, b: string } = + { ...o, a: 'wrong type?' } +let changeTypeBefore: { a: number, b: string } = + { a: 'wrong type?', ...o }; +let changeTypeBoth: { a: string, b: number } = + { ...o, ...swap }; + +// optional +let definiteBoolean: { sn: boolean }; +let definiteString: { sn: string }; +let optionalString: { sn?: string }; +let optionalNumber: { sn?: number }; +let optionalUnionStops: { sn: string | number | boolean } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; +let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; +let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; + +// computed property +let computedFirst: { a: number, b: string, "before everything": number } = + { ['before everything']: 12, ...o, b: 'yes' } +let computedMiddle: { a: number, b: string, c: boolean, "in the middle": number } = + { ...o, ['in the middle']: 13, b: 'maybe?', ...o2 } +let computedAfter: { a: number, b: string, "at the end": number } = + { ...o, b: 'yeah', ['at the end']: 14 } +// shortcut syntax +let a = 12; +let shortCutted: { a: number, b: string } = { ...o, a } + diff --git a/tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts b/tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts new file mode 100644 index 00000000000..ae46f2547d5 --- /dev/null +++ b/tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts @@ -0,0 +1,16 @@ +interface Indexed { + [n: string]: number; + a: number; +} +interface Indexed2 { + [n: string]: boolean; + c: boolean; +} +let indexed: Indexed; +let indexed2: Indexed2; +let i = { ...indexed, b: 11 }; +// only indexed has indexer, so i[101]: any +i[101]; +let ii = { ...indexed, ...indexed2 }; +// both have indexer, so i[1001]: number | boolean +ii[1001]; diff --git a/tests/cases/conformance/types/spread/objectSpreadNegative.ts b/tests/cases/conformance/types/spread/objectSpreadNegative.ts new file mode 100644 index 00000000000..3cd819d0613 --- /dev/null +++ b/tests/cases/conformance/types/spread/objectSpreadNegative.ts @@ -0,0 +1,71 @@ +// @target: es5 +let o = { a: 1, b: 'no' } + +/// private propagates +class PrivateOptionalX { + private x?: number; +} +class PublicX { + public x: number; +} +let publicX: PublicX; +let privateOptionalX: PrivateOptionalX; +let o2 = { ...publicX, ...privateOptionalX }; +let sn: number = o2.x; // error, x is private +let optionalString: { sn?: string }; +let optionalNumber: { sn?: number }; +let allOptional: { sn: string | number } = { ...optionalString, ...optionalNumber }; +// error, 'sn' is optional in source, required in target + +// assignability as target +interface Bool { b: boolean }; +interface Str { s: string }; +let spread = { ...{ b: true }, ...{s: "foo" } }; +spread = { s: "foo" }; // error, missing 'b' +let b = { b: false }; +spread = b; // error, missing 's' + +// literal repeats are not allowed, but spread repeats are fine +let duplicated = { b: 'bad', ...o, b: 'bad', ...o2, b: 'bad' } +let duplicatedSpread = { ...o, ...o } + +// null, undefined and primitives are not allowed +let spreadNull = { ...null }; +let spreadUndefind = { ...undefined }; +let spreadNum = { ...12 }; +let spreadSum = { ...1 + 1 }; +spreadSum.toFixed(); // error, no methods from number +let spreadBool = { ...false }; +spreadBool.valueOf(); // error, what were you thinking? +let spreadStr = { ...'foo' }; +spreadStr.length; // error, no 'length' +spreadStr.charAt(1); // error, no methods either +// functions are skipped +let spreadFunc = { ...function () { } } +spreadFunc(); // error, no call signature + +// write-only properties get skipped +let setterOnly = { ...{ set b (bad: number) { } } }; +setterOnly.b = 12; // error, 'b' does not exist + +// methods are skipped because they aren't enumerable +class C { p = 1; m() { } } +let c: C = new C() +let spreadC = { ...c } +spreadC.m(); // error 'm' is not in '{ ... c }' + +// generics +function f(t: T, u: U) { + return { ...t, ...u, id: 'id' }; +} +function override(initial: U, override: U): U { + return { ...initial, ...override }; +} +let exclusive: { id: string, a: number, b: string, c: string, d: boolean } = + f({ a: 1, b: 'yes' }, { c: 'no', d: false }) +let overlap: { id: string, a: number, b: string } = + f({ a: 1 }, { a: 2, b: 'extra' }) +let overlapConflict: { id:string, a: string } = + f({ a: 1 }, { a: 'mismatch' }) +let overwriteId: { id: string, a: number, c: number, d: string } = + f({ a: 1, id: true }, { c: 1, d: 'no' }) diff --git a/tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts b/tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts new file mode 100644 index 00000000000..47fd787ec9a --- /dev/null +++ b/tests/cases/conformance/types/spread/objectSpreadNegativeParse.ts @@ -0,0 +1,4 @@ +let o7 = { ...o? }; +let o8 = { ...*o }; +let o9 = { ...matchMedia() { }}; +let o10 = { ...get x() { return 12; }}; diff --git a/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts b/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts new file mode 100644 index 00000000000..36c75e70887 --- /dev/null +++ b/tests/cases/conformance/types/spread/objectSpreadNoTransform.ts @@ -0,0 +1,6 @@ +// @target: esnext +const y = { a: 'yes', b: 'no' }; +const o = { x: 1, ...y }; +var b; +var rest; +({ b, ...rest } = o); diff --git a/tests/cases/conformance/types/spread/objectSpreadStrictNull.ts b/tests/cases/conformance/types/spread/objectSpreadStrictNull.ts new file mode 100644 index 00000000000..087d47df26c --- /dev/null +++ b/tests/cases/conformance/types/spread/objectSpreadStrictNull.ts @@ -0,0 +1,21 @@ +// @strictNullChecks: true + +function f( + definiteBoolean: { sn: boolean }, + definiteString: { sn: string }, + optionalString: { sn?: string }, + optionalNumber: { sn?: number }, + undefinedString: { sn: string | undefined }, + undefinedNumber: { sn: number | undefined }) { + // optional + let optionalUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalNumber }; + let optionalUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...optionalString, ...optionalNumber }; + let allOptional: { sn?: string | number } = { ...optionalString, ...optionalNumber }; + + // undefined + let undefinedUnionStops: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedNumber }; + let undefinedUnionDuplicates: { sn: string | number } = { ...definiteBoolean, ...definiteString, ...undefinedString, ...undefinedNumber }; + let allUndefined: { sn: string | number | undefined } = { ...undefinedString, ...undefinedNumber }; + + let undefinedWithOptionalContinues: { sn: string | number | boolean } = { ...definiteBoolean, ...undefinedString, ...optionalNumber }; +} diff --git a/tests/cases/fourslash/completionListForObjectSpread.ts b/tests/cases/fourslash/completionListForObjectSpread.ts new file mode 100644 index 00000000000..ca96797195c --- /dev/null +++ b/tests/cases/fourslash/completionListForObjectSpread.ts @@ -0,0 +1,35 @@ +/// +////let o = { a: 1, b: 'no' } +////let o2 = { b: 'yes', c: true } +////let swap = { a: 'yes', b: -1 }; +////let addAfter: { a: number, b: string, c: boolean } = +//// { ...o, c: false } +////let addBefore: { a: number, b: string, c: boolean } = +//// { c: false, ...o } +////let ignore: { a: number, b: string } = +//// { b: 'ignored', ...o } +////ignore./*1*/a; +////let combinedNestedChangeType: { a: number, b: boolean, c: number } = +//// { ...{ a: 1, ...{ b: false, c: 'overriden' } }, c: -1 } +////combinedNestedChangeType./*2*/a; +////let spreadNull: { a: number } = +//// { a: 7, ...null } +////let spreadUndefined: { a: number } = +//// { a: 7, ...undefined } +////spreadNull./*3*/a; +////spreadUndefined./*4*/a; +goTo.marker('1'); +verify.memberListContains('a', '(property) a: number'); +verify.memberListContains('b', '(property) b: string'); +verify.memberListCount(2); +goTo.marker('2'); +verify.memberListContains('a', '(property) a: number'); +verify.memberListContains('b', '(property) b: boolean'); +verify.memberListContains('c', '(property) c: number'); +verify.memberListCount(3); +goTo.marker('3'); +verify.memberListContains('a', '(property) a: number'); +verify.memberListCount(1); +goTo.marker('4'); +verify.memberListContains('a', '(property) a: number'); +verify.memberListCount(1); diff --git a/tests/cases/fourslash/completionListForRest.ts b/tests/cases/fourslash/completionListForRest.ts new file mode 100644 index 00000000000..b880a90b3df --- /dev/null +++ b/tests/cases/fourslash/completionListForRest.ts @@ -0,0 +1,13 @@ +/// +////interface Gen { +//// x: number; +//// parent: Gen; +//// millenial: string; +////} +////let t: Gen; +////var { x, ...rest } = t; +////rest./*1*/x; +goTo.marker('1'); +verify.memberListContains('parent', '(property) Gen.parent: Gen'); +verify.memberListContains('millenial', '(property) Gen.millenial: string'); +verify.memberListCount(2); diff --git a/tests/cases/fourslash/findAllRefsForObjectSpread.ts b/tests/cases/fourslash/findAllRefsForObjectSpread.ts new file mode 100644 index 00000000000..05c83491f66 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForObjectSpread.ts @@ -0,0 +1,14 @@ +/// + +////interface A1 { [|a|]: string }; +////interface A2 { [|a|]?: number }; +////let a1: A1; +////let a2: A2; +////let a12 = { ...a1, ...a2 }; +////a12.[|a|]; +const ranges = test.ranges(); +// members of spread types only refer to themselves and the resulting property +verify.referencesOf(ranges[0], [ranges[0], ranges[2]]); +verify.referencesOf(ranges[1], [ranges[1], ranges[2]]); +// but the resulting property refers to everything +verify.referencesOf(ranges[2], ranges); diff --git a/tests/cases/fourslash/findAllRefsForRest.ts b/tests/cases/fourslash/findAllRefsForRest.ts new file mode 100644 index 00000000000..c3a970e9e73 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsForRest.ts @@ -0,0 +1,12 @@ +/// +////interface Gen { +//// x: number +//// [|parent|]: Gen; +//// millenial: string; +////} +////let t: Gen; +////var { x, ...rest } = t; +////rest.[|parent|]; +const ranges = test.ranges(); +verify.referencesOf(ranges[0], ranges); +verify.referencesOf(ranges[1], ranges); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 0a72d295295..295b8e422b9 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -194,6 +194,7 @@ declare namespace FourSlashInterface { currentSignatureHelpDocCommentIs(docComment: string): void; signatureHelpCountIs(expected: number): void; signatureHelpArgumentCountIs(expected: number): void; + signatureHelpCurrentArgumentListIsVariadic(expected: boolean); currentSignatureParameterCountIs(expected: number): void; currentSignatureTypeParameterCountIs(expected: number): void; currentSignatureHelpIs(expected: string): void; diff --git a/tests/cases/fourslash/goToDefinitionObjectSpread.ts b/tests/cases/fourslash/goToDefinitionObjectSpread.ts new file mode 100644 index 00000000000..b23d0a80448 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionObjectSpread.ts @@ -0,0 +1,9 @@ +/// + +////interface A1 { /*1*/a: number }; +////interface A2 { /*2*/a?: number }; +////let a1: A1; +////let a2: A2; +////let a12 = { ...a1, ...a2 }; +////a12.a/*3*/; +verify.goToDefinition('3', [ '1', '2' ]); diff --git a/tests/cases/fourslash/goToDefinitionRest.ts b/tests/cases/fourslash/goToDefinitionRest.ts new file mode 100644 index 00000000000..1459b9ffa88 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionRest.ts @@ -0,0 +1,12 @@ + +/// +////interface Gen { +//// x: number; +//// /*1*/parent: Gen; +//// millenial: string; +////} +////let t: Gen; +////var { x, ...rest } = t; +////rest./*2*/parent; +const ranges = test.ranges(); +verify.goToDefinition('2', [ '1' ]); diff --git a/tests/cases/fourslash/renameObjectSpread.ts b/tests/cases/fourslash/renameObjectSpread.ts new file mode 100644 index 00000000000..eba148c0e39 --- /dev/null +++ b/tests/cases/fourslash/renameObjectSpread.ts @@ -0,0 +1,20 @@ +/// + +////interface A1 { [|a|]: number }; +////interface A2 { [|a|]?: number }; +////let a1: A1; +////let a2: A2; +////let a12 = { ...a1, ...a2 }; +////a12.[|a|]; +const ranges = test.ranges(); +verify.assertHasRanges(ranges); + +// A1 unions with A2, so rename A1.a and a12.a +goTo.position(ranges[0].start); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [ranges[0], ranges[2]]); +// A1 unions with A2, so rename A2.a and a12.a +goTo.position(ranges[1].start); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [ranges[1], ranges[2]]); +// a12.a unions A1.a and A2.a, so rename A1.a, A2.a and a12.a +goTo.position(ranges[2].start); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [ranges[0], ranges[1], ranges[2]]); diff --git a/tests/cases/fourslash/renameRest.ts b/tests/cases/fourslash/renameRest.ts new file mode 100644 index 00000000000..a5cc2c38683 --- /dev/null +++ b/tests/cases/fourslash/renameRest.ts @@ -0,0 +1,15 @@ +/// +////interface Gen { +//// x: number; +//// [|parent|]: Gen; +//// millenial: string; +////} +////let t: Gen; +////var { x, ...rest } = t; +////rest.[|parent|]; +const ranges = test.ranges(); +verify.assertHasRanges(ranges); +goTo.position(ranges[0].start); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, ranges); +goTo.position(ranges[1].start); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, ranges); diff --git a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts index dd9becad10b..a19d170217c 100644 --- a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts +++ b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts @@ -15,6 +15,13 @@ verify.getSyntacticDiagnostics(`[ "category": "error", "code": 8010 }, + { + "message": "\'types\' can only be used in a .ts file.", + "start": 52, + "length": 6, + "category": "error", + "code": 8010 + }, { "message": "Variable declaration expected.", "start": 67, diff --git a/tests/cases/fourslash/signatureHelpTypeParametersNotVariadic.ts b/tests/cases/fourslash/signatureHelpTypeParametersNotVariadic.ts new file mode 100644 index 00000000000..30b0bac7e71 --- /dev/null +++ b/tests/cases/fourslash/signatureHelpTypeParametersNotVariadic.ts @@ -0,0 +1,8 @@ +/// + +//// declare function f(a: any, ...b: any[]): any; +//// f(1, 2); + +goTo.marker("1"); +verify.signatureHelpArgumentCountIs(0); +verify.signatureHelpCurrentArgumentListIsVariadic(false); \ No newline at end of file