From 82ecd5db9d556e716163753c81f12f2818f70d7c Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 25 Jun 2015 16:24:02 -0700 Subject: [PATCH 01/88] Basic tslint rules, non-final list --- package.json | 3 ++- tslint.json | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tslint.json diff --git a/package.json b/package.json index d6a8f538b78..82ab734d6f1 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "mocha": "latest", "chai": "latest", "browserify": "latest", - "istanbul": "latest" + "istanbul": "latest", + "tslint": "latest" }, "scripts": { "test": "jake runtests" diff --git a/tslint.json b/tslint.json new file mode 100644 index 00000000000..d7bdef8cc87 --- /dev/null +++ b/tslint.json @@ -0,0 +1,24 @@ +{ + "rules": { + "class-name": true, + "comment-format": [true, + "check-space" + ], + "curly": true, + "indent": true, + "no-trailing-comman": true, + "no-trailing-whitespace": true, + "no-unreachable": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "quotemark": true, + "semicolon": true, + "whitespace": [true, + "check-branch", + "check-operator", + "check-separator", + "check-type" + ] + } +} \ No newline at end of file From ed1ff3d57d699aad356ff444bf251480072620a7 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 25 Jun 2015 16:24:41 -0700 Subject: [PATCH 02/88] Fixing up whitespace and semicolons --- src/compiler/binder.ts | 18 +-- src/compiler/checker.ts | 178 ++++++++++++++--------------- src/compiler/core.ts | 10 +- src/compiler/declarationEmitter.ts | 10 +- src/compiler/emitter.ts | 114 +++++++++--------- src/compiler/parser.ts | 28 ++--- src/compiler/program.ts | 6 +- src/compiler/scanner.ts | 64 +++++------ src/compiler/types.ts | 38 +++--- src/compiler/utilities.ts | 32 +++--- 10 files changed, 248 insertions(+), 250 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e403ed994e5..9542f711753 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -96,7 +96,7 @@ namespace ts { let symbolCount = 0; let Symbol = objectAllocator.getSymbolConstructor(); - let classifiableNames: Map = {}; + let classifiableNames: Map = {}; if (!file.locals) { bind(file); @@ -202,10 +202,10 @@ namespace ts { symbol = hasProperty(symbolTable, name) ? symbolTable[name] : (symbolTable[name] = createSymbol(SymbolFlags.None, name)); - + if (name && (includes & SymbolFlags.Classifiable)) { - classifiableNames[name] = name; - } + classifiableNames[name] = name; + } if (symbol.flags & excludes) { if (node.name) { @@ -286,7 +286,7 @@ namespace ts { // This node will now be set as the parent of all of its children as we recurse into them. parent = node; - + // Depending on what kind of node this is, we may have to adjust the current container // and block-container. If the current node is a container, then it is automatically // considered the current block-container as well. Also, for containers that we know @@ -335,7 +335,7 @@ namespace ts { case SyntaxKind.TypeLiteral: case SyntaxKind.ObjectLiteralExpression: return ContainerFlags.IsContainer; - + case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: @@ -807,7 +807,7 @@ namespace ts { } } } - + /// Should be called only on prologue directives (isPrologueDirective(node) should be true) function isUseStrictPrologueDirective(node: ExpressionStatement): boolean { let nodeText = getTextOfNodeFromSourceText(file.text, node.expression); @@ -988,7 +988,7 @@ namespace ts { function bindVariableDeclarationOrBindingElement(node: VariableDeclaration | BindingElement) { if (inStrictMode) { - checkStrictModeEvalOrArguments(node, node.name) + checkStrictModeEvalOrArguments(node, node.name); } if (!isBindingPattern(node.name)) { @@ -1044,4 +1044,4 @@ namespace ts { : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } -} +} \ No newline at end of file diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efee668a24b..0367aa8292f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -365,7 +365,7 @@ namespace ts { let moduleExports = getSymbolOfNode(location).exports; if (location.kind === SyntaxKind.SourceFile || (location.kind === SyntaxKind.ModuleDeclaration && (location).name.kind === SyntaxKind.StringLiteral)) { - + // It's an external module. Because of module/namespace merging, a module's exports are in scope, // yet we never want to treat an export specifier as putting a member in scope. Therefore, // if the name we find is purely an export specifier, it is not actually considered in scope. @@ -540,7 +540,7 @@ namespace ts { } function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void { - Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0) + Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0); // Block-scoped variables cannot be used before their definition let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined); @@ -3794,11 +3794,11 @@ namespace ts { */ function createTypedPropertyDescriptorType(propertyType: Type): Type { let globalTypedPropertyDescriptorType = getGlobalTypedPropertyDescriptorType(); - return globalTypedPropertyDescriptorType !== emptyObjectType - ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) + return globalTypedPropertyDescriptorType !== emptyObjectType + ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) : emptyObjectType; } - + /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ @@ -4103,7 +4103,7 @@ namespace ts { } } return t; - } + }; } function identityMapper(type: Type): Type { @@ -4139,7 +4139,7 @@ namespace ts { parameterName: signature.typePredicate.parameterName, parameterIndex: signature.typePredicate.parameterIndex, type: instantiateType(signature.typePredicate.type, mapper) - } + }; } let result = createSignature(signature.declaration, freshTypeParameters, instantiateList(signature.parameters, mapper, instantiateSymbol), @@ -4780,7 +4780,7 @@ namespace ts { if (source.typePredicate && target.typePredicate) { let hasDifferentParameterIndex = source.typePredicate.parameterIndex !== target.typePredicate.parameterIndex; let hasDifferentTypes: boolean; - if (hasDifferentParameterIndex || + if (hasDifferentParameterIndex || (hasDifferentTypes = !isTypeIdenticalTo(source.typePredicate.type, target.typePredicate.type))) { if (reportErrors) { @@ -4790,12 +4790,12 @@ namespace ts { let targetTypeText = typeToString(target.typePredicate.type); if (hasDifferentParameterIndex) { - reportError(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, + reportError(Diagnostics.Parameter_0_is_not_in_the_same_position_as_parameter_1, sourceParamText, targetParamText); } else if (hasDifferentTypes) { - reportError(Diagnostics.Type_0_is_not_assignable_to_type_1, + reportError(Diagnostics.Type_0_is_not_assignable_to_type_1, sourceTypeText, targetTypeText); } @@ -5804,7 +5804,7 @@ namespace ts { if (!assumeTrue) { if (type.flags & TypeFlags.Union) { return getUnionType(filter((type).types, t => !isTypeSubtypeOf(t, signature.typePredicate.type))); - } + } return type; } return getNarrowedType(type, signature.typePredicate.type); @@ -6511,7 +6511,7 @@ namespace ts { let restArrayType = checkExpression((e).expression, contextualMapper); let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) || (languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined); - + if (restElementType) { elementTypes.push(restElementType); } @@ -7027,7 +7027,7 @@ namespace ts { let callIsIncomplete: boolean; // In incomplete call we want to be lenient when we have too few arguments let isDecorator: boolean; let spreadArgIndex = -1; - + if (node.kind === SyntaxKind.TaggedTemplateExpression) { let tagExpression = node; @@ -7208,17 +7208,17 @@ namespace ts { errorInfo = chainDiagnosticMessages(errorInfo, typeArgumentHeadMessage); typeArgumentHeadMessage = headMessage; } - + typeArgumentsAreAssignable = checkTypeAssignableTo( - typeArgument, - constraint, + typeArgument, + constraint, reportErrors ? typeArgNode : undefined, - typeArgumentHeadMessage, + typeArgumentHeadMessage, errorInfo); } } } - + return typeArgumentsAreAssignable; } @@ -7231,7 +7231,7 @@ namespace ts { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) let paramType = getTypeAtPosition(signature, i); let argType = getEffectiveArgumentType(node, i, arg); - + // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. if (argType === undefined) { @@ -7248,7 +7248,7 @@ namespace ts { } } } - + return true; } @@ -7285,7 +7285,6 @@ namespace ts { return args; } - /** * Returns the effective argument count for a node that works like a function invocation. * If 'node' is a Decorator, the number of arguments is derived from the decoration @@ -7332,7 +7331,7 @@ namespace ts { return args.length; } } - + /** * Returns the effective type of the first argument to a decorator. * If 'node' is a class declaration or class expression, the effective argument type @@ -7354,7 +7353,7 @@ namespace ts { // "static" or "constructor" side of the class) let classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); - + case SyntaxKind.Parameter: // For a parameter decorator, the `target` is the parent type of the // parameter's containing method. @@ -7363,9 +7362,9 @@ namespace ts { let classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); } - + // fall-through - + case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: @@ -7375,13 +7374,13 @@ namespace ts { // declared "static"; otherwise, it is the "instance"-side type of the // parent of the member. return getParentTypeOfClassElement(node); - + default: Debug.fail("Unsupported decorator target."); return unknownType; } } - + /** * Returns the effective type for the second argument to a decorator. * If 'node' is a parameter, its effective argument type is one of the following: @@ -7403,19 +7402,19 @@ namespace ts { case SyntaxKind.ClassDeclaration: Debug.fail("Class decorators should not have a second synthetic argument."); return unknownType; - + case SyntaxKind.Parameter: node = node.parent; if (node.kind === SyntaxKind.Constructor) { // For a constructor parameter decorator, the `propertyKey` will be `undefined`. return anyType; } - + // For a non-constructor parameter decorator, the `propertyKey` will be either // a string or a symbol, based on the name of the parameter's containing method. - + // fall-through - + case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: @@ -7430,7 +7429,7 @@ namespace ts { case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: return getStringLiteralType(element.name); - + case SyntaxKind.ComputedPropertyName: let nameType = checkComputedPropertyName(element.name); if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) { @@ -7439,19 +7438,18 @@ namespace ts { else { return stringType; } - + default: Debug.fail("Unsupported property name."); return unknownType; } - default: Debug.fail("Unsupported decorator target."); return unknownType; } } - + /** * Returns the effective argument type for the third argument to a decorator. * If 'node' is a parameter, the effective argument type is the number type. @@ -7482,13 +7480,13 @@ namespace ts { // for the type of the member. let propertyType = getTypeOfNode(node); return createTypedPropertyDescriptorType(propertyType); - + default: Debug.fail("Unsupported decorator target."); return unknownType; } } - + /** * Returns the effective argument type for the provided argument to a decorator. */ @@ -7506,7 +7504,7 @@ namespace ts { Debug.fail("Decorators should not have a fourth synthetic argument."); return unknownType; } - + /** * Gets the effective argument type for an argument in a call expression. */ @@ -7525,7 +7523,7 @@ namespace ts { // to signal that the caller needs to check the argument. return undefined; } - + /** * Gets the effective argument expression for an argument in a call expression. */ @@ -7535,7 +7533,7 @@ namespace ts { (argIndex === 0 && node.kind === SyntaxKind.TaggedTemplateExpression)) { return undefined; } - + return args[argIndex]; } @@ -7555,7 +7553,7 @@ namespace ts { return arg; } } - + function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[], headMessage?: DiagnosticMessage): Signature { let isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression; let isDecorator = node.kind === SyntaxKind.Decorator; @@ -7673,7 +7671,7 @@ namespace ts { } else if (candidateForTypeArgumentError) { if (!isTaggedTemplate && !isDecorator && typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, (node).typeArguments, [], /*reportErrors*/ true, headMessage) + checkTypeArguments(candidateForTypeArgumentError, (node).typeArguments, [], /*reportErrors*/ true, headMessage); } else { Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0); @@ -7683,7 +7681,7 @@ namespace ts { let diagnosticChainHead = chainDiagnosticMessages(/*details*/ undefined, // details will be provided by call to reportNoCommonSupertypeError Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly, typeToString(failedTypeParameter)); - + if (headMessage) { diagnosticChainHead = chainDiagnosticMessages(diagnosticChainHead, headMessage); } @@ -7709,7 +7707,7 @@ namespace ts { } return resolveErrorCall(node); - + function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { let errorInfo: DiagnosticMessageChain; errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); @@ -7725,7 +7723,7 @@ namespace ts { if (!hasCorrectArity(node, args, originalCandidate)) { continue; } - + let candidate: Signature; let typeArgumentsAreValid: boolean; let inferenceContext = originalCandidate.typeParameters @@ -7738,7 +7736,7 @@ namespace ts { let typeArgumentTypes: Type[]; if (typeArguments) { typeArgumentTypes = new Array(candidate.typeParameters.length); - typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false) + typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false); } else { inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext); @@ -7925,7 +7923,7 @@ namespace ts { return resolveCall(node, callSignatures, candidatesOutArray); } - + /** * Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression. */ @@ -7934,13 +7932,13 @@ namespace ts { case SyntaxKind.ClassDeclaration: case SyntaxKind.ClassExpression: return Diagnostics.Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression; - + case SyntaxKind.Parameter: return Diagnostics.Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression; - + case SyntaxKind.PropertyDeclaration: return Diagnostics.Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression; - + case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -7957,12 +7955,12 @@ namespace ts { if (apparentType === unknownType) { return resolveErrorCall(node); } - + let callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call); if (funcType === anyType || (!callSignatures.length && !(funcType.flags & TypeFlags.Union) && isTypeAssignableTo(funcType, globalFunctionType))) { return resolveUntypedCall(node); } - + let headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); if (!callSignatures.length) { let errorInfo: DiagnosticMessageChain; @@ -7971,7 +7969,7 @@ namespace ts { diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo)); return resolveErrorCall(node); } - + return resolveCall(node, callSignatures, candidatesOutArray, headMessage); } @@ -8768,9 +8766,9 @@ namespace ts { } function isYieldExpressionInClass(node: YieldExpression): boolean { - let current: Node = node + let current: Node = node; let parent = node.parent; - while (parent) { + while (parent) { if (isFunctionLike(parent) && current === (parent).body) { return false; } @@ -9044,7 +9042,7 @@ namespace ts { if (node.questionToken && isBindingPattern(node.name) && func.body) { error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } - + // Only check rest parameter type if it's not a binding pattern. Since binding patterns are // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { @@ -9128,12 +9126,12 @@ namespace ts { if (hasReportedError) { break; } - if (param.name.kind === SyntaxKind.ObjectBindingPattern || + if (param.name.kind === SyntaxKind.ObjectBindingPattern || param.name.kind === SyntaxKind.ArrayBindingPattern) { (function checkBindingPattern(pattern: BindingPattern) { for (let element of pattern.elements) { - if (element.name.kind === SyntaxKind.Identifier && + if (element.name.kind === SyntaxKind.Identifier && (element.name).text === typePredicate.parameterName) { error(typePredicateNode.parameterName, @@ -9798,8 +9796,8 @@ namespace ts { if (returnType.flags & TypeFlags.Any) { return; } - - let expectedReturnType: Type; + + let expectedReturnType: Type; let headMessage = getDiagnosticHeadMessageForDecoratorResolution(node); let errorInfo: DiagnosticMessageChain; switch (node.parent.kind) { @@ -9816,7 +9814,7 @@ namespace ts { Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any); break; - + case SyntaxKind.PropertyDeclaration: expectedReturnType = voidType; errorInfo = chainDiagnosticMessages( @@ -9832,15 +9830,15 @@ namespace ts { expectedReturnType = getUnionType([descriptorType, voidType]); break; } - + checkTypeAssignableTo( - returnType, - expectedReturnType, - node, - headMessage, + returnType, + expectedReturnType, + node, + headMessage, errorInfo); } - + /** Checks a type reference node as an expression. */ function checkTypeNodeAsExpression(node: TypeNode) { // When we are emitting type metadata for decorators, we need to try to check the type @@ -9881,7 +9879,7 @@ namespace ts { break; } } - + /** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */ function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) { // ensure all type annotations with a value declaration are checked as an expression @@ -9901,7 +9899,7 @@ namespace ts { if (!nodeCanBeDecorated(node)) { return; } - + if (!compilerOptions.experimentalDecorators) { error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); } @@ -10331,7 +10329,7 @@ namespace ts { function checkExpressionStatement(node: ExpressionStatement) { // Grammar checking - checkGrammarStatementInAmbientContext(node) + checkGrammarStatementInAmbientContext(node); checkExpression(node.expression); } @@ -10371,10 +10369,10 @@ namespace ts { if (node.initializer) { if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { - forEach((node.initializer).declarations, checkVariableDeclaration) + forEach((node.initializer).declarations, checkVariableDeclaration); } else { - checkExpression(node.initializer) + checkExpression(node.initializer); } } @@ -10384,7 +10382,7 @@ namespace ts { } function checkForOfStatement(node: ForOfStatement): void { - checkGrammarForInOrForOfStatement(node) + checkGrammarForInOrForOfStatement(node); // Check the LHS and RHS // If the LHS is a declaration, just check it as a variable declaration, which will in turn check the RHS @@ -10495,7 +10493,7 @@ namespace ts { if (allowStringInput) { return checkElementTypeOfArrayOrString(inputType, errorNode); } - + if (isArrayLikeType(inputType)) { let indexType = getIndexTypeOfType(inputType, IndexKind.Number); if (indexType) { @@ -10520,7 +10518,7 @@ namespace ts { return elementType || anyType; } - + /** * We want to treat type as an iterable, and get the type it is an iterable of. The iterable * must have the following structure (annotated with the names of the variables below): @@ -10865,7 +10863,7 @@ namespace ts { let identifierName = (catchClause.variableDeclaration.name).text; let locals = catchClause.block.locals; if (locals && hasProperty(locals, identifierName)) { - let localSymbol = locals[identifierName] + let localSymbol = locals[identifierName]; if (localSymbol && (localSymbol.flags & SymbolFlags.BlockScopedVariable) !== 0) { grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName); } @@ -11581,7 +11579,7 @@ namespace ts { // if the module merges with a class declaration in the same lexical scope, // we need to track this to ensure the correct emit. - let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration); + let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration); if (mergedClass && inSameLexicalScope(node, mergedClass)) { getNodeLinks(node).flags |= NodeCheckFlags.LexicalModuleMergesWithClass; @@ -11839,7 +11837,7 @@ namespace ts { } function checkTypePredicate(node: TypePredicateNode) { - if(!isInLegalTypePredicatePosition(node)) { + if (!isInLegalTypePredicatePosition(node)) { error(node, Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods); } } @@ -12479,11 +12477,11 @@ namespace ts { */ function getParentTypeOfClassElement(node: ClassElement) { let classSymbol = getSymbolOfNode(node.parent); - return node.flags & NodeFlags.Static + return node.flags & NodeFlags.Static ? getTypeOfSymbol(classSymbol) : getDeclaredTypeOfSymbol(classSymbol); } - + // Return the list of properties of the given type, augmented with properties from Function // if the type has call or construct signatures function getAugmentedPropertiesOfType(type: Type): Symbol[] { @@ -12807,7 +12805,7 @@ namespace ts { break; } } - + return "Object"; } @@ -12835,7 +12833,7 @@ namespace ts { } return "void 0"; } - + /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ function serializeParameterTypesOfNode(node: Node): (string | string[])[] { // serialization of parameter types uses the following rules: @@ -12933,7 +12931,7 @@ namespace ts { let isVariableDeclarationOrBindingElement = n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n); - let symbol = + let symbol = (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || getNodeLinks(n).resolvedSymbol || resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); @@ -12961,7 +12959,7 @@ namespace ts { if (!signature) { return unknownType; } - + let instantiatedSignature = getSignatureInstantiation(signature, typeArguments); return getOrCreateTypeFromSignature(instantiatedSignature); } @@ -13185,7 +13183,7 @@ namespace ts { return grammarErrorOnNode(modifier, Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context); } flags |= NodeFlags.Ambient; - lastDeclare = modifier + lastDeclare = modifier; break; } } @@ -13373,7 +13371,7 @@ namespace ts { if (types && types.length === 0) { let listType = tokenToString(node.token); let sourceFile = getSourceFileOfNode(node); - return grammarErrorAtPos(sourceFile, types.pos, 0, Diagnostics._0_list_cannot_be_empty, listType) + return grammarErrorAtPos(sourceFile, types.pos, 0, Diagnostics._0_list_cannot_be_empty, listType); } } @@ -13385,7 +13383,7 @@ namespace ts { for (let heritageClause of node.heritageClauses) { if (heritageClause.token === SyntaxKind.ExtendsKeyword) { if (seenExtendsClause) { - return grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_already_seen) + return grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_already_seen); } if (seenImplementsClause) { @@ -13723,13 +13721,13 @@ namespace ts { ? Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement; - return grammarErrorOnNode(node, message) + return grammarErrorOnNode(node, message); } else { let message = node.kind === SyntaxKind.BreakStatement ? Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement; - return grammarErrorOnNode(node, message) + return grammarErrorOnNode(node, message); } } @@ -14003,7 +14001,7 @@ namespace ts { // Find containing block which is either Block, ModuleBlock, SourceFile let links = getNodeLinks(node); if (!links.hasReportedStatementInAmbientContext && isFunctionLike(node.parent)) { - return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts) + return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts); } // We are either parented by another statement, or some sort of block. diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ced477eeeec..adc212d9dde 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -23,7 +23,7 @@ namespace ts { contains, remove, forEachValue: forEachValueInMap - } + }; function set(fileName: string, value: T) { files[normalizeKey(fileName)] = value; @@ -163,7 +163,7 @@ namespace ts { to.push(v); } } - } + } export function rangeEquals(array1: T[], array2: T[], pos: number, end: number) { while (pos < end) { @@ -365,7 +365,7 @@ namespace ts { } let text = getLocaleSpecificMessage(message.key); - + if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); } @@ -535,7 +535,7 @@ namespace ts { else { // A part may be an empty string (which is 'falsy') if the path had consecutive slashes, // e.g. "path//file.ts". Drop these before re-joining the parts. - if(part) { + if (part) { normalized.push(part); } } @@ -767,7 +767,7 @@ namespace ts { getSymbolConstructor: () => Symbol, getTypeConstructor: () => Type, getSignatureConstructor: () => Signature - } + }; export const enum AssertionLevel { None = 0, diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 54d0d6ff854..4f722fe12c4 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -188,7 +188,7 @@ namespace ts { if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) { moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); } - + // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration // then we don't need to write it at this point. We will write it when we actually see its declaration // Eg. @@ -755,7 +755,7 @@ namespace ts { emitJsDocComments(node); emitModuleElementDeclarationFlags(node); if (isConst(node)) { - write("const ") + write("const "); } write("enum "); writeTextOfNode(currentSourceFile, node.name); @@ -1330,7 +1330,7 @@ namespace ts { return { diagnosticMessage, - errorNode: node.name || node, + errorNode: node.name || node }; } } @@ -1504,7 +1504,7 @@ namespace ts { } } } - } + } } function emitNode(node: Node) { @@ -1564,7 +1564,7 @@ namespace ts { referencePathsOutput += "/// " + newLine; } } - + /* @internal */ export function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[]) { let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c2983594919..1a31cab2ede 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -9,9 +9,9 @@ namespace ts { // Flags enum to track count of temp variables and a few dedicated names const enum TempFlags { - Auto = 0x00000000, // No preferred name + Auto = 0x00000000, // No preferred name CountMask = 0x0FFFFFFF, // Temp variable counter - _i = 0x10000000, // Use/preference flag for '_i' + _i = 0x10000000, // Use/preference flag for '_i' } // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature @@ -148,10 +148,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { let emit = emitNodeWithoutSourceMap; /** Called just before starting emit of a node */ - let emitStart = function (node: Node) { }; + let emitStart = function(node: Node) { }; /** Called once the emit of the node is done */ - let emitEnd = function (node: Node) { }; + let emitEnd = function(node: Node) { }; /** Emit the text for the given token that comes after startPos * This by default writes the text provided with the given tokenKind @@ -164,10 +164,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { /** Called to before starting the lexical scopes as in function/class in the emitted code because of node * @param scopeDeclaration node that starts the lexical scope * @param scopeName Optional name of this scope instead of deducing one from the declaration node */ - let scopeEmitStart = function (scopeDeclaration: Node, scopeName?: string) { } + let scopeEmitStart = function(scopeDeclaration: Node, scopeName?: string) { }; /** Called after coming out of the scope */ - let scopeEmitEnd = function () { } + let scopeEmitEnd = function() { }; /** Sourcemap data that will get encoded */ let sourceMapData: SourceMapData; @@ -209,7 +209,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // Note that names generated by makeTempVariableName and makeUniqueName will never conflict. function makeTempVariableName(flags: TempFlags): string { if (flags && !(tempFlags & flags)) { - var name = flags === TempFlags._i ? "_i" : "_n" + var name = flags === TempFlags._i ? "_i" : "_n"; if (isUniqueName(name)) { tempFlags |= flags; return name; @@ -879,13 +879,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { if (languageVersion < ScriptTarget.ES6 && (isTemplateLiteralKind(node.kind) || node.hasExtendedUnicodeEscape)) { return getQuotedEscapedLiteralText('"', node.text, '"'); } - + // If we don't need to downlevel and we can reach the original source text using // the node's parent reference, then simply get the text as it was originally written. if (node.parent) { return getSourceTextOfNodeFromSourceFile(currentSourceFile, node); } - + // If we can't reach the original source text, use the canonical form if it's a number, // or an escaped quoted form of the original text if it's string-like. switch (node.kind) { @@ -915,14 +915,14 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), // thus we need to remove those characters. // First template piece starts with "`", others with "}" // Last template piece ends with "`", others with "${" let isLast = node.kind === SyntaxKind.NoSubstitutionTemplateLiteral || node.kind === SyntaxKind.TemplateTail; text = text.substring(1, text.length - (isLast ? 1 : 2)); - + // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's // and LineTerminatorSequences are normalized to for both TV and TRV. @@ -963,7 +963,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag)); write("("); emit(tempVariable); - + // Now we emit the expressions if (node.template.kind === SyntaxKind.TemplateExpression) { forEach((node.template).templateSpans, templateSpan => { @@ -1026,7 +1026,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // with the head will force the result up to this point to be a string. // Emitting a '+ ""' has no semantic effect for middles and tails. if (templateSpan.literal.text.length !== 0) { - write(" + ") + write(" + "); emitLiteral(templateSpan.literal); } } @@ -1421,7 +1421,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { group++; } if (group > 1) { - if(useConcat) { + if (useConcat) { write(")"); } } @@ -1504,7 +1504,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // Write out the first non-computed properties // (or all properties if none of them are computed), // then emit the rest through indexing on the temp variable. - emit(tempVar) + emit(tempVar); write(" = "); emitObjectLiteralBody(node, firstComputedPropertyIndex); @@ -1513,7 +1513,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { let property = properties[i]; - emitStart(property) + emitStart(property); if (property.kind === SyntaxKind.GetAccessor || property.kind === SyntaxKind.SetAccessor) { // TODO (drosen): Reconcile with 'emitMemberFunctions'. let accessors = getAllAccessorDeclarations(node.properties, property); @@ -1529,7 +1529,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write(", {"); increaseIndent(); if (accessors.getAccessor) { - writeLine() + writeLine(); emitLeadingComments(accessors.getAccessor); write("get: "); emitStart(accessors.getAccessor); @@ -1783,7 +1783,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emit(node.expression); let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - + // 1 .toString is a valid property access, emit a space after the literal let shouldEmitSpace: boolean; if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) { @@ -1792,7 +1792,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } if (shouldEmitSpace) { - write(" ."); + write(" ."); } else { write("."); @@ -2135,7 +2135,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { let current: Node = node; while (current) { if (current.kind === SyntaxKind.SourceFile) { - return !isExported || ((getCombinedNodeFlags(node) & NodeFlags.Export) !== 0) + return !isExported || ((getCombinedNodeFlags(node) & NodeFlags.Export) !== 0); } else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) { return false; @@ -2320,7 +2320,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { if (startPos !== undefined) { emitToken(tokenKind, startPos); - write(" ") + write(" "); } else { switch (tokenKind) { @@ -2435,13 +2435,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // all destructuring. // Note also that because an extra statement is needed to assign to the LHS, // for-of bodies are always emitted as blocks. - + let endPos = emitToken(SyntaxKind.ForKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); - + // Do not emit the LHS let declaration yet, because it might contain destructuring. - + // Do not call recordTempDeclaration because we are declaring the temps // right here. Recording means they will be declared later. // In the case where the user wrote an identifier as the RHS, like this: @@ -2457,7 +2457,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // the LHS will be emitted inside the body. emitStart(node.expression); write("var "); - + // _i = 0 emitNodeWithoutSourceMap(counter); write(" = 0"); @@ -2474,7 +2474,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } write("; "); - + // _i < _a.length; emitStart(node.initializer); emitNodeWithoutSourceMap(counter); @@ -2485,19 +2485,19 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitEnd(node.initializer); write("; "); - + // _i++) emitStart(node.initializer); emitNodeWithoutSourceMap(counter); write("++"); emitEnd(node.initializer); emitToken(SyntaxKind.CloseParenToken, node.expression.end); - + // Body write(" {"); writeLine(); increaseIndent(); - + // Initialize LHS // let v = _a[_i]; let rhsIterationValue = createElementAccessExpression(rhsReference, counter); @@ -2583,7 +2583,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emit(node.expression); endPos = emitToken(SyntaxKind.CloseParenToken, node.expression.end); write(" "); - emitCaseBlock(node.caseBlock, endPos) + emitCaseBlock(node.caseBlock, endPos); } function emitCaseBlock(node: CaseBlock, startPos: number): void { @@ -2724,7 +2724,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } write(`", `); emitDeclarationName(node); - write(")") + write(")"); } else { if (node.flags & NodeFlags.Default) { @@ -2755,7 +2755,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitNodeWithoutSourceMap(specifier.name); write(`", `); emitExpressionIdentifier(name); - write(")") + write(")"); emitEnd(specifier.name); } else { @@ -3045,7 +3045,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitOptional(" = ", initializer); if (exportChanged) { - write(")") + write(")"); } } } @@ -3671,8 +3671,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitOnlyPinnedOrTripleSlashComments(member); } else if (member.kind === SyntaxKind.MethodDeclaration || - member.kind === SyntaxKind.GetAccessor || - member.kind === SyntaxKind.SetAccessor) { + member.kind === SyntaxKind.GetAccessor || + member.kind === SyntaxKind.SetAccessor) { writeLine(); emitLeadingComments(member); emitStart(member); @@ -3842,7 +3842,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitClassLikeDeclarationForES6AndHigher(node); } } - + function emitClassLikeDeclarationForES6AndHigher(node: ClassLikeDeclaration) { let thisNodeIsDecorated = nodeIsDecorated(node); if (node.kind === SyntaxKind.ClassDeclaration) { @@ -3935,7 +3935,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("("); increaseIndent(); emit(tempVariable); - write(" = ") + write(" = "); } write("class"); @@ -3964,7 +3964,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { scopeEmitEnd(); // TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now. - + // For a decorated class, we need to assign its name (if it has one). This is because we emit // the class as a class expression to avoid the double-binding of the identifier: // @@ -4101,7 +4101,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write(".prototype"); } } - + function emitDecoratorsOfClass(node: ClassLikeDeclaration) { emitDecoratorsOfMembers(node, /*staticFlag*/ 0); emitDecoratorsOfMembers(node, NodeFlags.Static); @@ -5013,9 +5013,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { let started = false; for (let importNode of externalImports) { // do not create variable declaration for exports and imports that lack import clause - let skipNode = + let skipNode = importNode.kind === SyntaxKind.ExportDeclaration || - (importNode.kind === SyntaxKind.ImportDeclaration && !(importNode).importClause) + (importNode.kind === SyntaxKind.ImportDeclaration && !(importNode).importClause); if (skipNode) { continue; @@ -5110,7 +5110,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("};"); return emitExportStarFunction(exportedNamesStorageRef); - + function emitExportStarFunction(localNames: string): string { const exportStarFunction = makeUniqueName("exportStar"); @@ -5133,11 +5133,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("}"); decreaseIndent(); writeLine(); - write("}") + write("}"); return exportStarFunction; } - + function writeExportedName(node: Identifier | Declaration): void { // do not record default exports // they are local to module and never overwritten (explicitly skipped) by star export @@ -5221,7 +5221,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { exportedDeclarations.push(local); } } - write(";") + write(";"); } if (hoistedFunctionDeclarations) { @@ -5371,7 +5371,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitVariableDeclarationsForImports(); writeLine(); var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); - let exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations) + let exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); writeLine(); write("return {"); increaseIndent(); @@ -5433,7 +5433,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { if (importNode.kind === SyntaxKind.ImportDeclaration && (importNode).importClause.namedBindings) { - + let namedBindings = (importNode).importClause.namedBindings; if (namedBindings.kind === SyntaxKind.NamespaceImport) { // emit re-export for namespace @@ -5448,7 +5448,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // export {a, b as c} for (let element of (namedBindings).elements) { emitExportMemberAssignments(element.name || element.propertyName); - writeLine() + writeLine(); } } } @@ -5487,7 +5487,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { break; } - write("}") + write("}"); decreaseIndent(); } write("],"); @@ -5513,7 +5513,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } decreaseIndent(); writeLine(); - write("}") // execute + write("}"); // execute } function emitSystemModule(node: SourceFile, startIndex: number): void { @@ -5533,7 +5533,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { if (node.moduleName) { write(`"${node.moduleName}", `); } - write("[") + write("["); for (let i = 0; i < externalImports.length; ++i) { let text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -5565,12 +5565,12 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // we need to add modules without alias names to the end of the dependencies list let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the - // factory function. + // factory function. let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in - // factory function. + // factory function. let importAliasNames: string[] = []; // names of the parameters in the factory function; these - // parameters need to match the indexes of the corresponding - // module names in aliasedModuleNames. + // parameters need to match the indexes of the corresponding + // module names in aliasedModuleNames. // Fill in amd-dependency tags for (let amdDependency of node.amdDependencies) { @@ -5834,7 +5834,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { if (node.kind !== SyntaxKind.Block && node.parent && node.parent.kind === SyntaxKind.ArrowFunction && - (node.parent).body === node && + (node.parent).body === node && compilerOptions.target <= ScriptTarget.ES5) { return false; @@ -6173,4 +6173,4 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } } } -} +} \ No newline at end of file diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2c496b8c60d..ef61b77ba12 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -385,7 +385,7 @@ namespace ts { export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile { return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); } - + /* @internal */ export function parseIsolatedJSDocComment(content: string, start?: number, length?: number) { return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); @@ -1790,7 +1790,7 @@ namespace ts { do { templateSpans.push(parseTemplateSpan()); } - while (lastOrUndefined(templateSpans).literal.kind === SyntaxKind.TemplateMiddle) + while (lastOrUndefined(templateSpans).literal.kind === SyntaxKind.TemplateMiddle); templateSpans.end = getNodeEnd(); template.templateSpans = templateSpans; @@ -1805,7 +1805,7 @@ namespace ts { let literal: LiteralExpression; if (token === SyntaxKind.CloseBraceToken) { - reScanTemplateToken() + reScanTemplateToken(); literal = parseLiteralNode(); } else { @@ -2126,7 +2126,7 @@ namespace ts { node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); parseTypeMemberSemicolon(); - return finishNode(node) + return finishNode(node); } function parsePropertyOrMethodSignature(): Declaration { @@ -4209,7 +4209,7 @@ namespace ts { function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { let asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); let name = parsePropertyName(); - + // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); @@ -4651,7 +4651,7 @@ namespace ts { } function parseImportClause(identifier: Identifier, fullStart: number) { - //ImportClause: + // ImportClause: // ImportedDefaultBinding // NameSpaceImport // NamedImports @@ -4942,7 +4942,7 @@ namespace ts { /* @internal */ export function parseJSDocTypeExpression(start: number, length: number): JSDocTypeExpression { scanner.setText(sourceText, start, length); - + // Prime the first token for us to start processing. token = nextToken(); @@ -5279,7 +5279,7 @@ namespace ts { let tags: NodeArray; let pos: number; - + // NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I // considered using an actual Scanner, but this would complicate things. The // scanner would need to know it was in a Doc Comment. Otherwise, it would then @@ -5302,7 +5302,7 @@ namespace ts { if (ch === CharacterCodes.at && canParseTag) { parseTag(); - + // Once we parse out a tag, we cannot keep parsing out tags on this line. canParseTag = false; continue; @@ -5568,7 +5568,7 @@ namespace ts { if (sourceFile.statements.length === 0) { // If we don't have any statements in the current source file, then there's no real // way to incrementally parse. So just do a full parse instead. - return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true) + return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true); } // Make sure we're not trying to incrementally update a source file more than once. Once @@ -5632,7 +5632,7 @@ namespace ts { // inconsistent tree. Setting the parents on the new tree should be very fast. We // will immediately bail out of walking any subtrees when we can see that their parents // are already correct. - let result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true) + let result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true); return result; } @@ -5998,17 +5998,17 @@ namespace ts { interface IncrementalElement extends TextRange { parent?: Node; - intersectsChange: boolean + intersectsChange: boolean; length?: number; _children: Node[]; } export interface IncrementalNode extends Node, IncrementalElement { - hasBeenIncrementallyParsed: boolean + hasBeenIncrementallyParsed: boolean; } interface IncrementalNodeArray extends NodeArray, IncrementalElement { - length: number + length: number; } // Allows finding nodes in the source file at a certain position in an efficient manner. diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 09bd6fbdd28..501981e4ddf 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -35,7 +35,7 @@ namespace ts { // otherwise use toLowerCase as a canonical form. return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); } - + // returned by CScript sys environment let unsupportedFileEncodingErrorCode = -2147024809; @@ -458,7 +458,7 @@ namespace ts { let moduleNameText = (moduleNameExpr).text; if (moduleNameText) { let searchPath = basePath; - let searchName: string; + let searchName: string; while (true) { searchName = normalizePath(combinePaths(searchPath, moduleNameText)); if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) { @@ -669,7 +669,7 @@ namespace ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); } } - + if (options.emitDecoratorMetadata && !options.experimentalDecorators) { diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified)); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index bcc31c39002..a6fbf4e4466 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -267,7 +267,7 @@ namespace ts { return textToToken[s]; } - /* @internal */ + /* @internal */ export function computeLineStarts(text: string): number[] { let result: number[] = new Array(); let pos = 0; @@ -299,18 +299,18 @@ namespace ts { return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character); } - /* @internal */ + /* @internal */ export function computePositionOfLineAndCharacter(lineStarts: number[], line: number, character: number): number { Debug.assert(line >= 0 && line < lineStarts.length); return lineStarts[line] + character; } - /* @internal */ + /* @internal */ export function getLineStarts(sourceFile: SourceFile): number[] { return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text)); } - /* @internal */ + /* @internal */ export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) { let lineNumber = binarySearch(lineStarts, position); if (lineNumber < 0) { @@ -371,7 +371,7 @@ namespace ts { return ch >= CharacterCodes._0 && ch <= CharacterCodes._9; } - /* @internal */ + /* @internal */ export function isOctalDigit(ch: number): boolean { return ch >= CharacterCodes._0 && ch <= CharacterCodes._7; } @@ -398,7 +398,7 @@ namespace ts { } } - /* @internal */ + /* @internal */ export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean): number { // Keep in sync with couldStartTrivia while (true) { @@ -622,7 +622,7 @@ namespace ts { ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion); } - /* @internal */ + /* @internal */ // Creates a scanner over a (possibly unspecified) range of a piece of text. export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, @@ -631,16 +631,16 @@ namespace ts { start?: number, length?: number): Scanner { // Current position (end position of text of current token) - let pos: number; + let pos: number; // end of text - let end: number; + let end: number; // Start position of whitespace before current token - let startPos: number; + let startPos: number; // Start position of text of current token - let tokenPos: number; + let tokenPos: number; let token: SyntaxKind; let tokenValue: string; @@ -722,7 +722,7 @@ namespace ts { } return +(text.substring(start, pos)); } - + /** * Scans the given number of hexadecimal digits in the text, * returning -1 if the given number is unavailable. @@ -730,7 +730,7 @@ namespace ts { function scanExactNumberOfHexDigits(count: number): number { return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false); } - + /** * Scans as many hexadecimal digits as are available in the text, * returning -1 if the given number of digits was unavailable. @@ -808,7 +808,7 @@ namespace ts { pos++; let start = pos; - let contents = "" + let contents = ""; let resultingToken: SyntaxKind; while (true) { @@ -903,13 +903,13 @@ namespace ts { pos++; return scanExtendedUnicodeEscape(); } - + // '\uDDDD' - return scanHexadecimalEscape(/*numDigits*/ 4) - + return scanHexadecimalEscape(/*numDigits*/ 4); + case CharacterCodes.x: // '\xDD' - return scanHexadecimalEscape(/*numDigits*/ 2) + return scanHexadecimalEscape(/*numDigits*/ 2); // when encountering a LineContinuation (i.e. a backslash and a line terminator sequence), // the line terminator is interpreted to be "the empty code unit sequence". @@ -921,31 +921,31 @@ namespace ts { case CharacterCodes.lineFeed: case CharacterCodes.lineSeparator: case CharacterCodes.paragraphSeparator: - return "" + return ""; default: return String.fromCharCode(ch); } } - + function scanHexadecimalEscape(numDigits: number): string { let escapedValue = scanExactNumberOfHexDigits(numDigits); - + if (escapedValue >= 0) { return String.fromCharCode(escapedValue); } else { error(Diagnostics.Hexadecimal_digit_expected); - return "" + return ""; } } - + function scanExtendedUnicodeEscape(): string { let escapedValue = scanMinimumNumberOfHexDigits(1); let isInvalidExtendedEscape = false; // Validate the value of the digit if (escapedValue < 0) { - error(Diagnostics.Hexadecimal_digit_expected) + error(Diagnostics.Hexadecimal_digit_expected); isInvalidExtendedEscape = true; } else if (escapedValue > 0x10FFFF) { @@ -972,18 +972,18 @@ namespace ts { return utf16EncodeAsString(escapedValue); } - + // Derived from the 10.1.1 UTF16Encoding of the ES6 Spec. function utf16EncodeAsString(codePoint: number): string { Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF); - + if (codePoint <= 65535) { return String.fromCharCode(codePoint); } - + let codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800; let codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00; - + return String.fromCharCode(codeUnit1, codeUnit2); } @@ -1045,7 +1045,7 @@ namespace ts { let value = 0; // For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b. // Similarly valid octalIntegerLiteral must have at least one octal digit following o or O. - let numberOfDigits = 0; + let numberOfDigits = 0; while (true) { let ch = text.charCodeAt(pos); let valueOfCh = ch - CharacterCodes._0; @@ -1119,7 +1119,7 @@ namespace ts { tokenValue = scanString(); return token = SyntaxKind.StringLiteral; case CharacterCodes.backtick: - return token = scanTemplateAndSetTokenValue() + return token = scanTemplateAndSetTokenValue(); case CharacterCodes.percent: if (text.charCodeAt(pos + 1) === CharacterCodes.equals) { return pos += 2, token = SyntaxKind.PercentEqualsToken; @@ -1428,14 +1428,14 @@ namespace ts { // regex. Report error and return what we have so far. if (p >= end) { tokenIsUnterminated = true; - error(Diagnostics.Unterminated_regular_expression_literal) + error(Diagnostics.Unterminated_regular_expression_literal); break; } let ch = text.charCodeAt(p); if (isLineBreak(ch)) { tokenIsUnterminated = true; - error(Diagnostics.Unterminated_regular_expression_literal) + error(Diagnostics.Unterminated_regular_expression_literal); break; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f3f203d4e86..c30de7b32e6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -960,7 +960,7 @@ namespace ts { } export interface ModuleBlock extends Node, Statement { - statements: NodeArray + statements: NodeArray; } export interface ImportEqualsDeclaration extends Declaration, Statement { @@ -1076,7 +1076,7 @@ namespace ts { export interface JSDocTypeReference extends JSDocType { name: EntityName; - typeArguments: NodeArray + typeArguments: NodeArray; } export interface JSDocOptionalType extends JSDocType { @@ -1101,8 +1101,8 @@ namespace ts { } export interface JSDocRecordMember extends PropertyDeclaration { - name: Identifier | LiteralExpression, - type?: JSDocType + name: Identifier | LiteralExpression; + type?: JSDocType; } export interface JSDocComment extends Node { @@ -1239,15 +1239,15 @@ namespace ts { export interface SourceMapSpan { /** Line number in the .js file. */ - emittedLine: number; + emittedLine: number; /** Column number in the .js file. */ - emittedColumn: number; + emittedColumn: number; /** Line number in the .ts file. */ - sourceLine: number; + sourceLine: number; /** Column number in the .ts file. */ - sourceColumn: number; + sourceColumn: number; /** Optional name (index into names array) associated with this span. */ - nameIndex?: number; + nameIndex?: number; /** .ts file (index into sources array) associated with this span */ sourceIndex: number; } @@ -1398,7 +1398,7 @@ namespace ts { NotAccessible, CannotBeNamed } - + export interface TypePredicate { parameterName: string; parameterIndex: number; @@ -1418,7 +1418,7 @@ namespace ts { /* @internal */ export interface SymbolAccessiblityResult extends SymbolVisibilityResult { - errorModuleName?: string // If the symbol is not visible from module, module's name + errorModuleName?: string; // If the symbol is not visible from module, module's name } /* @internal */ @@ -1549,7 +1549,7 @@ namespace ts { /* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums } - /* @internal */ + /* @internal */ export interface SymbolLinks { target?: Symbol; // Resolved (non-alias) target of an alias type?: Type; // Type of value symbol @@ -1564,14 +1564,14 @@ namespace ts { isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration } - /* @internal */ + /* @internal */ export interface TransientSymbol extends Symbol, SymbolLinks { } export interface SymbolTable { [index: string]: Symbol; } - /* @internal */ + /* @internal */ export const enum NodeCheckFlags { TypeChecked = 0x00000001, // Node has been type checked LexicalThis = 0x00000002, // Lexical 'this' reference @@ -1589,7 +1589,7 @@ namespace ts { LexicalModuleMergesWithClass = 0x00000800, // Instantiated lexical module declaration is merged with a previous class declaration. } - /* @internal */ + /* @internal */ export interface NodeLinks { resolvedType?: Type; // Cached type of type node resolvedSignature?: Signature; // Cached signature of signature node or call expression @@ -1632,14 +1632,14 @@ namespace ts { ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6 - /* @internal */ + /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, - /* @internal */ + /* @internal */ Primitive = String | Number | Boolean | ESSymbol | Void | Undefined | Null | StringLiteral | Enum, StringLike = String | StringLiteral, NumberLike = Number | Enum, ObjectType = Class | Interface | Reference | Tuple | Anonymous, - /* @internal */ + /* @internal */ RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral } @@ -1650,7 +1650,7 @@ namespace ts { symbol?: Symbol; // Symbol associated with type (if any) } - /* @internal */ + /* @internal */ // Intrinsic types (TypeFlags.Intrinsic) export interface IntrinsicType extends Type { intrinsicName: string; // Name of intrinsic type diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ce166aa2f36..bdc04a6b1ee 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3,9 +3,9 @@ /* @internal */ namespace ts { export interface ReferencePathMatchResult { - fileReference?: FileReference - diagnosticMessage?: DiagnosticMessage - isNoDefaultLib?: boolean + fileReference?: FileReference; + diagnosticMessage?: DiagnosticMessage; + isNoDefaultLib?: boolean; } export interface SynthesizedNode extends Node { @@ -70,7 +70,7 @@ namespace ts { } export function releaseStringWriter(writer: StringSymbolWriter) { - writer.clear() + writer.clear(); stringWriters.push(writer); } @@ -81,7 +81,7 @@ namespace ts { // Returns true if this node contains a parse error anywhere underneath it. export function containsParseError(node: Node): boolean { aggregateChildData(node); - return (node.parserContextFlags & ParserContextFlags.ThisNodeOrAnySubNodesHasError) !== 0 + return (node.parserContextFlags & ParserContextFlags.ThisNodeOrAnySubNodesHasError) !== 0; } function aggregateChildData(node: Node): void { @@ -166,7 +166,7 @@ namespace ts { return getTokenPosOfNode(node, sourceFile); } - return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end); + return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end); } export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string { @@ -406,7 +406,7 @@ namespace ts { } } - export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/ + export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; export function isTypeNode(node: Node): boolean { if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { @@ -751,7 +751,7 @@ namespace ts { if (node.kind === SyntaxKind.TaggedTemplateExpression) { return (node).tag; } - + // Will either be a CallExpression, NewExpression, or Decorator. return (node).expression; } @@ -929,7 +929,7 @@ namespace ts { } export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) { - let moduleState = getModuleInstanceState(node) + let moduleState = getModuleInstanceState(node); return moduleState === ModuleInstanceState.Instantiated || (preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly); } @@ -1281,7 +1281,7 @@ namespace ts { if (isNoDefaultLibRegEx.exec(comment)) { return { isNoDefaultLib: true - } + }; } else { let matchResult = fullTripleSlashReferencePathRegEx.exec(comment); @@ -1391,7 +1391,7 @@ namespace ts { } return node; } - + export function nodeStartsNewLexicalEnvironment(n: Node): boolean { return isFunctionLike(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile; } @@ -1493,7 +1493,7 @@ namespace ts { } } } - + // This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator, // paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in // the language service. These characters should be escaped when printing, and if any characters are added, @@ -2036,7 +2036,7 @@ namespace ts { return lineFeed; } else if (sys) { - return sys.newLine + return sys.newLine; } return carriageReturnLineFeed; } @@ -2048,11 +2048,11 @@ namespace ts { } export function textSpanEnd(span: TextSpan) { - return span.start + span.length + return span.start + span.length; } export function textSpanIsEmpty(span: TextSpan) { - return span.length === 0 + return span.length === 0; } export function textSpanContainsPosition(span: TextSpan, position: number) { @@ -2080,7 +2080,7 @@ namespace ts { } export function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan) { - return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start + return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start; } export function textSpanIntersectsWith(span: TextSpan, start: number, length: number) { From d4403df35e80570c4764fe64981d8dc78bc68011 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 25 Jun 2015 17:36:19 -0700 Subject: [PATCH 03/88] var -> let --- src/compiler/binder.ts | 4 +- src/compiler/checker.ts | 52 +++++++++++++------------- src/compiler/commandLineParser.ts | 62 +++++++++++++++---------------- src/compiler/emitter.ts | 28 +++++++------- src/compiler/parser.ts | 12 +++--- src/compiler/program.ts | 10 ++--- src/compiler/tsc.ts | 2 +- src/compiler/utilities.ts | 4 +- 8 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 9542f711753..c4e93d359d1 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -474,7 +474,7 @@ namespace ts { } function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean { - var body = node.kind === SyntaxKind.SourceFile ? node : (node).body; + let body = node.kind === SyntaxKind.SourceFile ? node : (node).body; if (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock) { for (let stat of (body).statements) { if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { @@ -750,7 +750,7 @@ namespace ts { function bind(node: Node) { node.parent = parent; - var savedInStrictMode = inStrictMode; + let savedInStrictMode = inStrictMode; if (!savedInStrictMode) { updateStrictMode(node); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0367aa8292f..62b4cfb4d55 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -282,7 +282,7 @@ namespace ts { function getSymbolLinks(symbol: Symbol): SymbolLinks { if (symbol.flags & SymbolFlags.Transient) return symbol; - var id = getSymbolId(symbol); + let id = getSymbolId(symbol); return symbolLinks[id] || (symbolLinks[id] = {}); } @@ -630,7 +630,7 @@ namespace ts { } function getTargetOfNamespaceImport(node: NamespaceImport): Symbol { - var moduleSpecifier = (node.parent.parent).moduleSpecifier; + let moduleSpecifier = (node.parent.parent).moduleSpecifier; return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier); } @@ -685,7 +685,7 @@ namespace ts { function getPropertyOfVariable(symbol: Symbol, name: string): Symbol { if (symbol.flags & SymbolFlags.Variable) { - var typeAnnotation = (symbol.valueDeclaration).type; + let typeAnnotation = (symbol.valueDeclaration).type; if (typeAnnotation) { return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name)); } @@ -1305,7 +1305,7 @@ namespace ts { // Mark the unexported alias as visible if its parent is visible // because these kind of aliases can be used to name types in declaration file - var anyImportSyntax = getAnyImportSyntax(declaration); + let anyImportSyntax = getAnyImportSyntax(declaration); if (anyImportSyntax && !(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export isDeclarationVisible(anyImportSyntax.parent)) { @@ -2086,14 +2086,14 @@ namespace ts { } function collectLinkedAliases(node: Identifier): Node[] { - var exportSymbol: Symbol; + let exportSymbol: Symbol; if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); } else if (node.parent.kind === SyntaxKind.ExportSpecifier) { exportSymbol = getTargetOfExportSpecifier(node.parent); } - var result: Node[] = []; + let result: Node[] = []; if (exportSymbol) { buildVisibleNodeList(exportSymbol.declarations); } @@ -2102,16 +2102,16 @@ namespace ts { function buildVisibleNodeList(declarations: Declaration[]) { forEach(declarations, declaration => { getNodeLinks(declaration).isVisible = true; - var resultNode = getAnyImportSyntax(declaration) || declaration; + let resultNode = getAnyImportSyntax(declaration) || declaration; if (!contains(result, resultNode)) { result.push(resultNode); } if (isInternalModuleImportEqualsDeclaration(declaration)) { // Add the referenced top container visible - var internalModuleReference = (declaration).moduleReference; - var firstIdentifier = getFirstIdentifier(internalModuleReference); - var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, + let internalModuleReference = (declaration).moduleReference; + let firstIdentifier = getFirstIdentifier(internalModuleReference); + let importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, firstIdentifier); buildVisibleNodeList(importSymbol.declarations); } @@ -2606,7 +2606,7 @@ namespace ts { // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] { - var declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration); + let declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration); return appendOuterTypeParameters(undefined, declaration); } @@ -9908,7 +9908,7 @@ namespace ts { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. switch (node.kind) { case SyntaxKind.ClassDeclaration: - var constructor = getFirstConstructorWithBody(node); + let constructor = getFirstConstructorWithBody(node); if (constructor) { checkParameterTypeAnnotationsAsExpressions(constructor); } @@ -10159,7 +10159,7 @@ namespace ts { return; } - var symbol = getSymbolOfNode(node); + let symbol = getSymbolOfNode(node); if (symbol.flags & SymbolFlags.FunctionScopedVariable) { let localDeclarationSymbol = resolveName(node, (node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); if (localDeclarationSymbol && @@ -11404,7 +11404,7 @@ namespace ts { } // expression part in ElementAccess\PropertyAccess should be either identifier or dottedName - var current = expression; + let current = expression; while (current) { if (current.kind === SyntaxKind.Identifier) { break; @@ -12614,7 +12614,7 @@ namespace ts { return false; } - var isValue = isAliasResolvedToValue(getSymbolOfNode(node)); + let isValue = isAliasResolvedToValue(getSymbolOfNode(node)); return isValue && node.moduleReference && !nodeIsMissing(node.moduleReference); } @@ -12698,7 +12698,7 @@ namespace ts { // here has no effect anyway as an identifier in a type name is not an expression. // var substitution = getExpressionNameSubstitution(node, getGeneratedNameForNode); // var text = substitution || (node).text; - var text = (node).text; + let text = (node).text; if (fallbackPath) { fallbackPath.push(text); } @@ -12707,8 +12707,8 @@ namespace ts { } } else { - var left = serializeEntityName((node).left, fallbackPath); - var right = serializeEntityName((node).right, fallbackPath); + let left = serializeEntityName((node).left, fallbackPath); + let right = serializeEntityName((node).right, fallbackPath); if (!fallbackPath) { return left + "." + right; } @@ -12748,7 +12748,7 @@ namespace ts { return "Symbol"; } else if (type === unknownType) { - var fallbackPath: string[] = []; + let fallbackPath: string[] = []; serializeEntityName(node.typeName, fallbackPath); return fallbackPath; } @@ -12843,7 +12843,7 @@ namespace ts { // // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. if (node) { - var valueDeclaration: FunctionLikeDeclaration; + let valueDeclaration: FunctionLikeDeclaration; if (node.kind === SyntaxKind.ClassDeclaration) { valueDeclaration = getFirstConstructorWithBody(node); } @@ -12851,14 +12851,14 @@ namespace ts { valueDeclaration = node; } if (valueDeclaration) { - var result: (string | string[])[]; - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; + let result: (string | string[])[]; + let parameters = valueDeclaration.parameters; + let parameterCount = parameters.length; if (parameterCount > 0) { result = new Array(parameterCount); - for (var i = 0; i < parameterCount; i++) { + for (let i = 0; i < parameterCount; i++) { if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; + let parameterType = parameters[i].type; if (parameterType.kind === SyntaxKind.ArrayType) { parameterType = (parameterType).elementType; } @@ -12905,7 +12905,7 @@ namespace ts { } function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { - var type = getTypeOfExpression(expr); + let type = getTypeOfExpression(expr); getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4e401c5c9b3..8bdbdfaa8c9 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -5,7 +5,7 @@ namespace ts { /* @internal */ - export var optionDeclarations: CommandLineOption[] = [ + export let optionDeclarations: CommandLineOption[] = [ { name: "charset", type: "string", @@ -207,11 +207,11 @@ namespace ts { ]; export function parseCommandLine(commandLine: string[]): ParsedCommandLine { - var options: CompilerOptions = {}; - var fileNames: string[] = []; - var errors: Diagnostic[] = []; - var shortOptionNames: Map = {}; - var optionNameMap: Map = {}; + let options: CompilerOptions = {}; + let fileNames: string[] = []; + let errors: Diagnostic[] = []; + let shortOptionNames: Map = {}; + let optionNameMap: Map = {}; forEach(optionDeclarations, option => { optionNameMap[option.name.toLowerCase()] = option; @@ -227,9 +227,9 @@ namespace ts { }; function parseStrings(args: string[]) { - var i = 0; + let i = 0; while (i < args.length) { - var s = args[i++]; + let s = args[i++]; if (s.charCodeAt(0) === CharacterCodes.at) { parseResponseFile(s.slice(1)); } @@ -242,7 +242,7 @@ namespace ts { } if (hasProperty(optionNameMap, s)) { - var opt = optionNameMap[s]; + let opt = optionNameMap[s]; // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument). if (!args[i] && opt.type !== "boolean") { @@ -261,8 +261,8 @@ namespace ts { break; // If not a primitive, the possible types are specified in what is effectively a map of options. default: - var map = >opt.type; - var key = (args[i++] || "").toLowerCase(); + let map = >opt.type; + let key = (args[i++] || "").toLowerCase(); if (hasProperty(map, key)) { options[opt.name] = map[key]; } @@ -282,19 +282,19 @@ namespace ts { } function parseResponseFile(fileName: string) { - var text = sys.readFile(fileName); + let text = sys.readFile(fileName); if (!text) { errors.push(createCompilerDiagnostic(Diagnostics.File_0_not_found, fileName)); return; } - var args: string[] = []; - var pos = 0; + let args: string[] = []; + let pos = 0; while (true) { while (pos < text.length && text.charCodeAt(pos) <= CharacterCodes.space) pos++; if (pos >= text.length) break; - var start = pos; + let start = pos; if (text.charCodeAt(start) === CharacterCodes.doubleQuote) { pos++; while (pos < text.length && text.charCodeAt(pos) !== CharacterCodes.doubleQuote) pos++; @@ -321,7 +321,7 @@ namespace ts { */ export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { try { - var text = sys.readFile(fileName); + let text = sys.readFile(fileName); } catch (e) { return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; @@ -350,7 +350,7 @@ namespace ts { * file to. e.g. outDir */ export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine { - var errors: Diagnostic[] = []; + let errors: Diagnostic[] = []; return { options: getCompilerOptions(), @@ -359,22 +359,22 @@ namespace ts { }; function getCompilerOptions(): CompilerOptions { - var options: CompilerOptions = {}; - var optionNameMap: Map = {}; + let options: CompilerOptions = {}; + let optionNameMap: Map = {}; forEach(optionDeclarations, option => { optionNameMap[option.name] = option; }); - var jsonOptions = json["compilerOptions"]; + let jsonOptions = json["compilerOptions"]; if (jsonOptions) { - for (var id in jsonOptions) { + for (let id in jsonOptions) { if (hasProperty(optionNameMap, id)) { - var opt = optionNameMap[id]; - var optType = opt.type; - var value = jsonOptions[id]; - var expectedType = typeof optType === "string" ? optType : "string"; + let opt = optionNameMap[id]; + let optType = opt.type; + let value = jsonOptions[id]; + let expectedType = typeof optType === "string" ? optType : "string"; if (typeof value === expectedType) { if (typeof optType !== "string") { - var key = value.toLowerCase(); + let key = value.toLowerCase(); if (hasProperty(optType, key)) { value = optType[key]; } @@ -401,17 +401,17 @@ namespace ts { } function getFileNames(): string[] { - var fileNames: string[] = []; + let fileNames: string[] = []; if (hasProperty(json, "files")) { if (json["files"] instanceof Array) { fileNames = map(json["files"], s => combinePaths(basePath, s)); } } else { - var exclude = json["exclude"] instanceof Array ? map(json["exclude"], normalizeSlashes) : undefined; - var sysFiles = host.readDirectory(basePath, ".ts", exclude); - for (var i = 0; i < sysFiles.length; i++) { - var name = sysFiles[i]; + let exclude = json["exclude"] instanceof Array ? map(json["exclude"], normalizeSlashes) : undefined; + let sysFiles = host.readDirectory(basePath, ".ts", exclude); + for (let i = 0; i < sysFiles.length; i++) { + let name = sysFiles[i]; if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { fileNames.push(name); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1a31cab2ede..e71d3aea41b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -209,7 +209,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // Note that names generated by makeTempVariableName and makeUniqueName will never conflict. function makeTempVariableName(flags: TempFlags): string { if (flags && !(tempFlags & flags)) { - var name = flags === TempFlags._i ? "_i" : "_n"; + let name = flags === TempFlags._i ? "_i" : "_n"; if (isUniqueName(name)) { tempFlags |= flags; return name; @@ -1309,7 +1309,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("super"); } else { - var flags = resolver.getNodeCheckFlags(node); + let flags = resolver.getNodeCheckFlags(node); if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); } @@ -1456,7 +1456,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("{"); if (numElements > 0) { - var properties = node.properties; + let properties = node.properties; // If we are not doing a downlevel transformation for object literals, // then try to preserve the original shape of the object literal. @@ -2685,7 +2685,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitModuleMemberName(node: Declaration) { emitStart(node.name); if (getCombinedNodeFlags(node) & NodeFlags.Export) { - var container = getContainingModule(node); + let container = getContainingModule(node); if (container) { write(getGeneratedNameForNode(container)); write("."); @@ -3783,7 +3783,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDefaultValueAssignments(ctor); emitRestParameter(ctor); if (baseTypeElement) { - var superCall = findInitialSuperCall(ctor); + let superCall = findInitialSuperCall(ctor); if (superCall) { writeLine(); emit(superCall); @@ -3806,7 +3806,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } emitPropertyDeclarations(node, getInitializedProperties(node, /*static:*/ false)); if (ctor) { - var statements: Node[] = (ctor.body).statements; + let statements: Node[] = (ctor.body).statements; if (superCall) { statements = statements.slice(1); } @@ -3946,7 +3946,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDeclarationName(node); } - var baseTypeNode = getClassExtendsHeritageClauseElement(node); + let baseTypeNode = getClassExtendsHeritageClauseElement(node); if (baseTypeNode) { write(" extends "); emit(baseTypeNode.expression); @@ -4353,7 +4353,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { let argumentsWritten = 0; if (compilerOptions.emitDecoratorMetadata) { if (shouldEmitTypeMetadata(node)) { - var serializedType = resolver.serializeTypeOfNode(node); + let serializedType = resolver.serializeTypeOfNode(node); if (serializedType) { if (writeComma) { write(", "); @@ -4366,7 +4366,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } } if (shouldEmitParamTypesMetadata(node)) { - var serializedTypes = resolver.serializeParameterTypesOfNode(node); + let serializedTypes = resolver.serializeParameterTypesOfNode(node); if (serializedTypes) { if (writeComma || argumentsWritten) { write(", "); @@ -4384,7 +4384,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } } if (shouldEmitReturnTypeMetadata(node)) { - var serializedType = resolver.serializeReturnTypeOfNode(node); + let serializedType = resolver.serializeReturnTypeOfNode(node); if (serializedType) { if (writeComma || argumentsWritten) { write(", "); @@ -4885,7 +4885,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { writeLine(); emitStart(node); write("export default "); - var expression = node.expression; + let expression = node.expression; emit(expression); if (expression.kind !== SyntaxKind.FunctionDeclaration && expression.kind !== SyntaxKind.ClassDeclaration) { @@ -5370,7 +5370,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { // } emitVariableDeclarationsForImports(); writeLine(); - var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); + let exportedDeclarations = processTopLevelVariableAndFunctionDeclarations(node); let exportStarFunction = emitLocalStorageForExportedNamesIfNecessary(exportedDeclarations); writeLine(); write("return {"); @@ -5725,7 +5725,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDetachedComments(node); // emit prologue directives prior to __extends - var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); + let startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); // Only emit helpers if the user did not say otherwise. if (!compilerOptions.noEmitHelpers) { @@ -6081,7 +6081,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - var trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + let trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ef61b77ba12..8e062c647fa 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2709,7 +2709,7 @@ namespace ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - var lastToken = token; + let lastToken = token; arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>"); arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) ? parseArrowFunctionExpressionBody() @@ -4421,7 +4421,7 @@ namespace ts { } function parseClassDeclarationOrExpression(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, kind: SyntaxKind): ClassLikeDeclaration { - var node = createNode(kind, fullStart); + let node = createNode(kind, fullStart); node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); @@ -4957,15 +4957,15 @@ namespace ts { } function parseJSDocTopLevelType(): JSDocType { - var type = parseJSDocType(); + let type = parseJSDocType(); if (token === SyntaxKind.BarToken) { - var unionType = createNode(SyntaxKind.JSDocUnionType, type.pos); + let unionType = createNode(SyntaxKind.JSDocUnionType, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } if (token === SyntaxKind.EqualsToken) { - var optionalType = createNode(SyntaxKind.JSDocOptionalType, type.pos); + let optionalType = createNode(SyntaxKind.JSDocOptionalType, type.pos); nextToken(); optionalType.type = type; type = finishNode(optionalType); @@ -5648,7 +5648,7 @@ namespace ts { function visitNode(node: IncrementalNode) { if (aggressiveChecks && shouldCheckNode(node)) { - var text = oldText.substring(node.pos, node.end); + let text = oldText.substring(node.pos, node.end); } // Ditch any existing LS children we may have created. This way we can avoid diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 501981e4ddf..c780b8709ba 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -11,12 +11,12 @@ namespace ts { export const version = "1.5.3"; export function findConfigFile(searchPath: string): string { - var fileName = "tsconfig.json"; + let fileName = "tsconfig.json"; while (true) { if (sys.fileExists(fileName)) { return fileName; } - var parentPath = getDirectoryPath(searchPath); + let parentPath = getDirectoryPath(searchPath); if (parentPath === searchPath) { break; } @@ -79,7 +79,7 @@ namespace ts { function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { - var start = new Date().getTime(); + let start = new Date().getTime(); ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); sys.writeFile(fileName, data, writeByteOrderMark); ioWriteTime += new Date().getTime() - start; @@ -309,7 +309,7 @@ namespace ts { if (!isDeclarationFile(sourceFile)) { let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); // Don't actually write any files since we're just getting diagnostics. - var writeFile: WriteFileCallback = () => { }; + let writeFile: WriteFileCallback = () => { }; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } @@ -358,7 +358,7 @@ namespace ts { } } else { - var nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd); + let nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd); if (!nonTsFile) { if (options.allowNonTsExtensions) { diagnostic = Diagnostics.File_0_not_found; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 2903c3a31f4..017b5679d4b 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -82,7 +82,7 @@ namespace ts { function reportDiagnostic(diagnostic: Diagnostic) { var output = ""; - + if (diagnostic.file) { var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bdc04a6b1ee..bd785c7a817 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1409,7 +1409,7 @@ namespace ts { } export function createSynthesizedNodeArray(): NodeArray { - var array = >[]; + let array = >[]; array.pos = -1; array.end = -1; return array; @@ -1994,7 +1994,7 @@ namespace ts { * Converts a string to a base-64 encoded ASCII string. */ export function convertToBase64(input: string): string { - var result = ""; + let result = ""; let charCodes = getExpandedCharCodes(input); let i = 0; let length = charCodes.length; From aab210096bad1da8c8d0311dd2307b4723b76ec0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 24 Jun 2015 14:10:02 -0700 Subject: [PATCH 04/88] Add name of function expression into completion list --- src/compiler/checker.ts | 8 ++++++-- src/services/services.ts | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index efee668a24b..7312dd137a2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12182,8 +12182,12 @@ namespace ts { } break; case SyntaxKind.FunctionExpression: - if ((location).name) { - copySymbol(location.symbol, meaning); + let name = (location).name; + if (name) { + let symbol = location.symbol; + if (symbol.flags & meaning && !hasProperty(symbols, name.text)) { + symbols[name.text] = symbol; + } } break; } diff --git a/src/services/services.ts b/src/services/services.ts index e11fb32c73b..6a7661e0dfd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2807,6 +2807,22 @@ namespace ts { } } + // Special case for function expression because despite sometimes having a name, the binder + // binds them to a symbol with the name "__function". However, for completion entry, we want + // to display its declared name rather than "__function". + // var x = function foo () { + // fo$ <- completion list should contain local name "foo" + // } + // foo$ <- completion list should not contain "foo" + if (displayName === "__function") { + displayName = symbol.declarations[0].name.getText(); + + // At this point, we expect that all completion list entries have declared name including function expression + // because when we gather all relevant symbols, we check that the function expression must have declared name + // before adding the symbol into our symbols table. (see: getSymbolsInScope) + Debug.assert(displayName !== undefined,"Expected this function expression to have declared name"); + } + let firstCharCode = displayName.charCodeAt(0); // First check of the displayName is not external module; if it is an external module, it is not valid entry if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { From 9c9e29877d03691abe576d67b1b951aa31c6c71c Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 Jun 2015 18:21:52 -0700 Subject: [PATCH 05/88] Add test for completion in function expression --- ...ompletionListInNamedFunctionExpression1.ts | 8 ++++++++ ...tInNamedFunctionExpressionWithShadowing.ts | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/cases/fourslash/completionListInNamedFunctionExpression1.ts create mode 100644 tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts diff --git a/tests/cases/fourslash/completionListInNamedFunctionExpression1.ts b/tests/cases/fourslash/completionListInNamedFunctionExpression1.ts new file mode 100644 index 00000000000..bb64e04b93b --- /dev/null +++ b/tests/cases/fourslash/completionListInNamedFunctionExpression1.ts @@ -0,0 +1,8 @@ +/// + +//// var x = function foo() { +//// /*1*/ +//// } + +goTo.marker("1"); +verify.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts b/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts new file mode 100644 index 00000000000..7d441acb7d7 --- /dev/null +++ b/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts @@ -0,0 +1,19 @@ +/// + +//// function foo() {} +//// /*0*/ +//// var x = function foo() { +//// /*1*/ +//// } +//// var y = function () { +//// /*2*/ +//// } + +goTo.marker("0"); +verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function"); + +goTo.marker("1"); +verify.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function"); + +goTo.marker("2"); +verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function") \ No newline at end of file From 34489fa0e092598ddfd64a13eb756cf218b0d0f5 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 Jun 2015 18:22:33 -0700 Subject: [PATCH 06/88] Add test for completion in class expression --- .../completionListInNamedClassExpression.ts | 14 ++++++++ ...ListInNamedClassExpressionWithShadowing.ts | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/cases/fourslash/completionListInNamedClassExpression.ts create mode 100644 tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts diff --git a/tests/cases/fourslash/completionListInNamedClassExpression.ts b/tests/cases/fourslash/completionListInNamedClassExpression.ts new file mode 100644 index 00000000000..cf0d170f6a5 --- /dev/null +++ b/tests/cases/fourslash/completionListInNamedClassExpression.ts @@ -0,0 +1,14 @@ +/// + +//// var x = class myClass { +//// getClassName (){ +//// m/*0*/ +//// } +//// /*1*/ +//// } + +goTo.marker("0"); +verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); + +goTo.marker("1"); +verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts b/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts new file mode 100644 index 00000000000..b1f7f1ca3f0 --- /dev/null +++ b/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts @@ -0,0 +1,34 @@ +/// + +//// class myClass { /*0*/ } +//// /*1*/ +//// var x = class myClass { +//// getClassName (){ +//// m/*2*/ +//// } +//// /*3*/ +//// } +//// var y = class { +//// getSomeName() { +//// /*4*/ +//// } +//// /*5*/ +//// } + +goTo.marker("0"); +verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); + +goTo.marker("1"); +verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); + +goTo.marker("2"); +verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); + +goTo.marker("3"); +verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); + +goTo.marker("4"); +verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); + +goTo.marker("5"); +verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); From cd48d8181a907093a9d57982e30f48f8499c2c27 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 25 Jun 2015 18:23:28 -0700 Subject: [PATCH 07/88] Fix build errors due to naive var->let replacement --- src/compiler/commandLineParser.ts | 3 ++- src/compiler/emitter.ts | 2 +- src/compiler/parser.ts | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8bdbdfaa8c9..f0f71b4874e 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -320,8 +320,9 @@ namespace ts { * @param fileName The path to the config file */ export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { + let text = ''; try { - let text = sys.readFile(fileName); + text = sys.readFile(fileName); } catch (e) { return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e71d3aea41b..b9d7f664f80 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3783,7 +3783,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitDefaultValueAssignments(ctor); emitRestParameter(ctor); if (baseTypeElement) { - let superCall = findInitialSuperCall(ctor); + var superCall = findInitialSuperCall(ctor); if (superCall) { writeLine(); emit(superCall); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8e062c647fa..3144b6a1892 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5647,8 +5647,9 @@ namespace ts { return; function visitNode(node: IncrementalNode) { + let text = ''; if (aggressiveChecks && shouldCheckNode(node)) { - let text = oldText.substring(node.pos, node.end); + text = oldText.substring(node.pos, node.end); } // Ditch any existing LS children we may have created. This way we can avoid From 5467e1dfbd90d90f611fe7737a4a169673c7563b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 25 Jun 2015 18:35:01 -0700 Subject: [PATCH 08/88] Support completion in named class expression and named function expression --- src/compiler/checker.ts | 8 ++------ src/services/services.ts | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7312dd137a2..ef7f2f7c29b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12170,11 +12170,6 @@ namespace ts { case SyntaxKind.EnumDeclaration: copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember); break; - case SyntaxKind.ClassExpression: - if ((location).name) { - copySymbol(location.symbol, meaning); - } - // Fall through case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: if (!(memberFlags & NodeFlags.Static)) { @@ -12182,7 +12177,8 @@ namespace ts { } break; case SyntaxKind.FunctionExpression: - let name = (location).name; + case SyntaxKind.ClassExpression: + let name = (location).name; if (name) { let symbol = location.symbol; if (symbol.flags & meaning && !hasProperty(symbols, name.text)) { diff --git a/src/services/services.ts b/src/services/services.ts index 6a7661e0dfd..aedf6bac35d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1423,6 +1423,9 @@ namespace ts { // class X {} export const classElement = "class"; + // var x = class X {} + export const localClassElement = "local class"; + // interface Y {} export const interfaceElement = "interface"; @@ -2807,14 +2810,14 @@ namespace ts { } } - // Special case for function expression because despite sometimes having a name, the binder - // binds them to a symbol with the name "__function". However, for completion entry, we want - // to display its declared name rather than "__function". + // Special case for function expression and class expression because despite sometimes having a name, the binder + // binds them to a symbol with the name "__function" and "__class" respectively. However, for completion entry, we want + // to display its declared name rather than "__function" and "__class". // var x = function foo () { // fo$ <- completion list should contain local name "foo" // } // foo$ <- completion list should not contain "foo" - if (displayName === "__function") { + if (displayName === "__function" || displayName === "__class") { displayName = symbol.declarations[0].name.getText(); // At this point, we expect that all completion list entries have declared name including function expression @@ -3568,7 +3571,8 @@ namespace ts { function getSymbolKind(symbol: Symbol, location: Node): string { let flags = symbol.getFlags(); - if (flags & SymbolFlags.Class) return ScriptElementKind.classElement; + if (flags & SymbolFlags.Class) return symbol.declarations[0].kind === SyntaxKind.ClassExpression ? + ScriptElementKind.localClassElement : ScriptElementKind.classElement; if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement; if (flags & SymbolFlags.TypeAlias) return ScriptElementKind.typeElement; if (flags & SymbolFlags.Interface) return ScriptElementKind.interfaceElement; @@ -3777,7 +3781,16 @@ namespace ts { } } if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) { - displayParts.push(keywordPart(SyntaxKind.ClassKeyword)); + // Special case for class expressions because we would like to indicate that + // the class name is local to the class body (similar to function expression) + // (local class) class + if (symbol.getName() === "__class") { + pushTypePart(ScriptElementKind.localClassElement); + } + else { + // Class declaration has name which is not local. + displayParts.push(keywordPart(SyntaxKind.ClassKeyword)); + } displayParts.push(spacePart()); addFullSymbolName(symbol); writeTypeParametersOfSymbol(symbol, sourceFile); From 45182b88b0e9fcb14bf5a9d6cb9ff5cc2a4b402f Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 26 Jun 2015 10:36:39 -0700 Subject: [PATCH 09/88] Add todo comment to use getDeclaredName --- src/services/services.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/services.ts b/src/services/services.ts index aedf6bac35d..0367786d610 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2817,6 +2817,7 @@ namespace ts { // fo$ <- completion list should contain local name "foo" // } // foo$ <- completion list should not contain "foo" + // TODO (yuisu): Use getDeclaredName instead once the functions is rewritten if (displayName === "__function" || displayName === "__class") { displayName = symbol.declarations[0].name.getText(); From 5fc3099e25b6dfc9a9d6e83a828699b22a3082e9 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Mon, 29 Jun 2015 17:47:24 -0700 Subject: [PATCH 10/88] Rule changes --- tslint.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tslint.json b/tslint.json index d7bdef8cc87..74f80185a36 100644 --- a/tslint.json +++ b/tslint.json @@ -6,7 +6,10 @@ ], "curly": true, "indent": true, - "no-trailing-comman": true, + "one-line": [true, + "check-open-brace" + ], + "no-empty": true, "no-trailing-whitespace": true, "no-unreachable": true, "no-unused-variable": true, From 744f640f42cd8fc1411cf8556bcdf5e3d9b4c862 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 13:16:29 -0700 Subject: [PATCH 11/88] Add comment to clarify why we don't use copySymbol --- src/compiler/checker.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8df1f8bf808..e1f99882079 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12680,6 +12680,10 @@ namespace ts { break; case SyntaxKind.FunctionExpression: case SyntaxKind.ClassExpression: + // The reason we are not using copySymbol for function expression and class expression + // is that copySymbol will not copy a symbol into SymbolTable if the symbol has name prefix + // with "__". Therefore, if class expression or function expression have declared name, + // we will add the symbol into the table using its declared name let name = (location).name; if (name) { let symbol = location.symbol; From 514d054cac3955ef25f8e5c5e8153fdd54b05656 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 13:17:46 -0700 Subject: [PATCH 12/88] Address CR: Use getDeclaredName and getDeclarationOfKind --- src/compiler/utilities.ts | 8 ++++--- src/services/services.ts | 47 ++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 750482bc8b0..cee87a95f07 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -16,9 +16,11 @@ namespace ts { export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration { let declarations = symbol.declarations; - for (let declaration of declarations) { - if (declaration.kind === kind) { - return declaration; + if (declarations) { + for (let declaration of declarations) { + if (declaration.kind === kind) { + return declaration; + } } } diff --git a/src/services/services.ts b/src/services/services.ts index 099d83b7595..e1dfec82e12 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2801,34 +2801,25 @@ namespace ts { } /// Completion - function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean): string { - let displayName = symbol.getName(); - if (displayName) { - // If this is the default export, get the name of the declaration if it exists - if (displayName === "default") { - let localSymbol = getLocalSymbolForExportDefault(symbol); - if (localSymbol && localSymbol.name) { - displayName = symbol.valueDeclaration.localSymbol.name; - } - } + function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, location: Node): string { + let displayName: string; - // Special case for function expression and class expression because despite sometimes having a name, the binder - // binds them to a symbol with the name "__function" and "__class" respectively. However, for completion entry, we want - // to display its declared name rather than "__function" and "__class". - // var x = function foo () { - // fo$ <- completion list should contain local name "foo" - // } - // foo$ <- completion list should not contain "foo" - // TODO (yuisu): Use getDeclaredName instead once the functions is rewritten - if (displayName === "__function" || displayName === "__class") { - displayName = symbol.declarations[0].name.getText(); - - // At this point, we expect that all completion list entries have declared name including function expression - // because when we gather all relevant symbols, we check that the function expression must have declared name - // before adding the symbol into our symbols table. (see: getSymbolsInScope) - Debug.assert(displayName !== undefined,"Expected this function expression to have declared name"); - } + // In the case of default export, function expression and class expression, + // the binder bind them with "default", "__function", "__class" respectively. + // However, for completion entry, we want to display its declared name rather than binder name. + if (getLocalSymbolForExportDefault(symbol) || + getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression) || + getDeclarationOfKind(symbol, SyntaxKind.ClassExpression)) { + let typeChecker = program.getTypeChecker(); + displayName = getDeclaredName(typeChecker, symbol, location); + // At this point, we expect that all completion list entries have declared name including function expression and class expression + // because when we gather all relevant symbols, we check that the function expression and class expression must have declared name + // before adding the symbol into our symbols table. (see: getSymbolsInScope) + Debug.assert(displayName !== undefined, "Expected displayed name from declaration to existed in this symbol: " + symbol.getName()); + } + else { + displayName = symbol.getName(); let firstCharCode = displayName.charCodeAt(0); // First check of the displayName is not external module; if it is an external module, it is not valid entry if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { @@ -3534,7 +3525,7 @@ namespace ts { // Try to get a valid display name for this symbol, if we could not find one, then ignore it. // We would like to only show things that can be added after a dot, so for instance numeric properties can // not be accessed with a dot (a.1 <- invalid) - let displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, /*performCharacterChecks:*/ true); + let displayName = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, /*performCharacterChecks:*/ true, location); if (!displayName) { return undefined; } @@ -3591,7 +3582,7 @@ namespace ts { // We don't need to perform character checks here because we're only comparing the // name against 'entryName' (which is known to be good), not building a new // completion entry. - let symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(s, target, /*performCharacterChecks:*/ false) === entryName ? s : undefined); + let symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(s, target, /*performCharacterChecks:*/ false, location) === entryName ? s : undefined); if (symbol) { let { displayParts, documentation, symbolKind } = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, getValidSourceFile(fileName), location, location, SemanticMeaning.All); From 605ab0b1fce65dcf7bb87e6bbe3273e3ad34ddcc Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 13:55:02 -0700 Subject: [PATCH 13/88] Fix rename for class expression --- src/services/services.ts | 6 ++--- .../renameLocationsForClassExpression01.ts | 26 +++++++------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index e1dfec82e12..6e2698c9e6c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5117,10 +5117,10 @@ namespace ts { * a reference to a symbol can occur anywhere. */ function getSymbolScope(symbol: Symbol): Node { - // If this is the symbol of a function expression, then named references - // are limited to its own scope. + // If this is the symbol of a named function expression or named class expression, + // then named references are limited to its own scope. let valueDeclaration = symbol.valueDeclaration; - if (valueDeclaration && valueDeclaration.kind === SyntaxKind.FunctionExpression) { + if (valueDeclaration && (valueDeclaration.kind === SyntaxKind.FunctionExpression || valueDeclaration.kind === SyntaxKind.ClassExpression)) { return valueDeclaration; } diff --git a/tests/cases/fourslash/renameLocationsForClassExpression01.ts b/tests/cases/fourslash/renameLocationsForClassExpression01.ts index a1174d503ed..6bedc077d4d 100644 --- a/tests/cases/fourslash/renameLocationsForClassExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForClassExpression01.ts @@ -3,13 +3,14 @@ ////class Foo { ////} //// -////var x = class /**/Foo { +//////The class expression Foo +////var x = class [|Foo|] { //// doIt() { -//// return Foo; +//// return [|Foo|]; //// } //// //// static doItStatically() { -//// return Foo; +//// return [|Foo|].y; //// } ////} //// @@ -18,17 +19,10 @@ //// return Foo //// } ////} +////var z = class Foo {} - -// TODO (yuit): Fix up this test when class expressions are supported. -// Just uncomment the below, remove the marker, and add the -// appropriate ranges in the test itself. -goTo.marker(); -verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); - -////let ranges = test.ranges() -////for (let range of ranges) { -//// goTo.position(range.start); -//// -//// verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); -////} \ No newline at end of file +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file From 7747ad4aa586e56d463da389448480c9ec89ecdb Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 14:25:43 -0700 Subject: [PATCH 14/88] Clean up stripQuote and add comments --- src/services/services.ts | 36 ++++++++++++++++++++---------------- src/services/utilities.ts | 9 ++++++++- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 6e2698c9e6c..c1c0aee33af 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2800,7 +2800,11 @@ namespace ts { return program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics()); } - /// Completion + /** + * Get the name to be display in completion from a given symbol. + * + * @return undefined if the name is of external module otherwise a name with striped of any quote + */ function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, location: Node): string { let displayName: string; @@ -2832,37 +2836,37 @@ namespace ts { return getCompletionEntryDisplayName(displayName, target, performCharacterChecks); } - function getCompletionEntryDisplayName(displayName: string, target: ScriptTarget, performCharacterChecks: boolean): string { - if (!displayName) { + /** + * Get a displayName from a given for completion list, performing any necessary quotes stripping + * and checking whether the name is valid identifier name. + */ + function getCompletionEntryDisplayName(name: string, target: ScriptTarget, performCharacterChecks: boolean): string { + if (!name) { return undefined; } - let firstCharCode = displayName.charCodeAt(0); - if (displayName.length >= 2 && - firstCharCode === displayName.charCodeAt(displayName.length - 1) && - (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { - // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an - // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. - displayName = displayName.substring(1, displayName.length - 1); - } + name = stripQuotes(name); - if (!displayName) { + // We can simply return name with strip quotes because the name could be an invalid identifier name + // e.g "b a" is valid quoted name but when we strip off the quotes, it is invalid. + // We, thus, need to check if whatever was inside the quotes is actually a valid identifier name. + if (!name) { return undefined; } if (performCharacterChecks) { - if (!isIdentifierStart(displayName.charCodeAt(0), target)) { + if (!isIdentifierStart(name.charCodeAt(0), target)) { return undefined; } - for (let i = 1, n = displayName.length; i < n; i++) { - if (!isIdentifierPart(displayName.charCodeAt(i), target)) { + for (let i = 1, n = name.length; i < n; i++) { + if (!isIdentifierPart(name.charCodeAt(i), target)) { return undefined; } } } - return unescapeIdentifier(displayName); + return unescapeIdentifier(name); } function getCompletionData(fileName: string, position: number) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 0fd945caa7d..797cbee12cb 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -675,9 +675,16 @@ namespace ts { (location.parent).propertyName === location; } + /** + * Strip off existed single quotes or double quotes from a given string + * + * @return non-quoted string + */ export function stripQuotes(name: string) { let length = name.length; - if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) { + if (length >= 2 && + name.charCodeAt(0) === name.charCodeAt(length - 1) && + (name.charCodeAt(0) === CharacterCodes.doubleQuote || name.charCodeAt(0) === CharacterCodes.singleQuote)) { return name.substring(1, length - 1); }; return name; From 30796073b408b0d6a5440127fa62cc8832a8da8a Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 14:42:27 -0700 Subject: [PATCH 15/88] Update verification function to be able to test that the only symbol with certain kind, document, and text is the completion list --- src/harness/fourslash.ts | 48 +++++++++++++++++-- ...ListInNamedClassExpressionWithShadowing.ts | 6 +++ ...tInNamedFunctionExpressionWithShadowing.ts | 5 +- tests/cases/fourslash/fourslash.ts | 2 +- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0717ed68e83..9a07482e60d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -704,13 +704,55 @@ module FourSlash { } } - public verifyCompletionListDoesNotContain(symbol: string) { + /** + * Verfiy that the completion list does NOT contain the given symbol. If text, or documentation, or kind are provided, + * the list contains the symbol all given parameters must matched. When any parameter is omitted, the parameters is ignored during comparison. + */ + public verifyCompletionListDoesNotContain(symbol: string, expectedText?: string, expectedDocumentation?: string, expectedKind?: string) { + let that = this; + function filterByTextOrDocumentation(entry: ts.CompletionEntry) { + let details = that.getCompletionEntryDetails(entry.name); + let documentation = ts.displayPartsToString(details.documentation); + let text = ts.displayPartsToString(details.displayParts); + if (expectedText && expectedDocumentation) { + return (documentation === expectedDocumentation && text === expectedText) ? true : false; + } + else if (expectedText && !expectedDocumentation) { + return text === expectedText ? true : false; + } + else if (expectedDocumentation && !expectedText) { + return documentation === expectedDocumentation ? true : false; + } + // Because expectedText and expectedDocumentation are undefined, we assume that + // users don't care to compare them so we will treat that entry as if the entry has matching text and documentation + // and keep it in the list of filtered entry. + return true; + } this.scenarioActions.push(''); this.scenarioActions.push(''); var completions = this.getCompletionListAtCaret(); - if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) { - this.raiseError('Completion list did contain ' + symbol); + if (completions) { + let filterCompletions = completions.entries.filter(e => e.name === symbol); + filterCompletions = expectedKind ? filterCompletions.filter(e => e.kind === expectedKind) : filterCompletions; + filterCompletions = filterCompletions.filter(filterByTextOrDocumentation); + if (filterCompletions.length !== 0) { + // After filtered using all present criterion, if there are still symbol left in the list + // then these symbols must meet the criterion for Not supposed to be in the list. So we + // raise an error + let error = "Completion list did contain \'" + symbol + "\'."; + let details = this.getCompletionEntryDetails(filterCompletions[0].name); + if (expectedText) { + error += "Expected text: " + expectedText + " to equal: " + ts.displayPartsToString(details.displayParts) + "."; + } + if (expectedDocumentation) { + error += "Expected documentation: " + expectedDocumentation + " to equal: " + ts.displayPartsToString(details.documentation) + "."; + } + if (expectedKind) { + error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions[0].kind + "." + } + this.raiseError(error); + } } } diff --git a/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts b/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts index b1f7f1ca3f0..e1274e6f592 100644 --- a/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts +++ b/tests/cases/fourslash/completionListInNamedClassExpressionWithShadowing.ts @@ -17,18 +17,24 @@ goTo.marker("0"); verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); +verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); goTo.marker("1"); verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); +verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); goTo.marker("2"); verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); +verify.not.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); goTo.marker("3"); verify.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); +verify.not.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); goTo.marker("4"); verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); +verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); goTo.marker("5"); verify.completionListContains("myClass", "class myClass", /*documentation*/ undefined, "class"); +verify.not.completionListContains("myClass", "(local class) myClass", /*documentation*/ undefined, "local class"); diff --git a/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts b/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts index 7d441acb7d7..14965253e84 100644 --- a/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts +++ b/tests/cases/fourslash/completionListInNamedFunctionExpressionWithShadowing.ts @@ -11,9 +11,12 @@ goTo.marker("0"); verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function"); +verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");; goTo.marker("1"); verify.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function"); +verify.not.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function");; goTo.marker("2"); -verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function") \ No newline at end of file +verify.completionListContains("foo", "function foo(): void", /*documentation*/ undefined, "function") +verify.not.completionListContains("foo", "(local function) foo(): void", /*documentation*/ undefined, "local function");; \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 07a1fc4de40..a0463073d8c 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -169,7 +169,7 @@ module FourSlashInterface { // completion list is brought up if necessary public completionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { if (this.negative) { - FourSlash.currentTestState.verifyCompletionListDoesNotContain(symbol); + FourSlash.currentTestState.verifyCompletionListDoesNotContain(symbol, text, documentation, kind); } else { FourSlash.currentTestState.verifyCompletionListContains(symbol, text, documentation, kind); } From 2e0c3908ea94e89204ecee6f1f7f852b5bfb538b Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 14:59:07 -0700 Subject: [PATCH 16/88] Address code review --- src/services/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index c1c0aee33af..01500b23812 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3619,7 +3619,7 @@ namespace ts { function getSymbolKind(symbol: Symbol, location: Node): string { let flags = symbol.getFlags(); - if (flags & SymbolFlags.Class) return symbol.declarations[0].kind === SyntaxKind.ClassExpression ? + if (flags & SymbolFlags.Class) return getDeclarationOfKind(symbol, SyntaxKind.ClassExpression) ? ScriptElementKind.localClassElement : ScriptElementKind.classElement; if (flags & SymbolFlags.Enum) return ScriptElementKind.enumElement; if (flags & SymbolFlags.TypeAlias) return ScriptElementKind.typeElement; @@ -3832,7 +3832,7 @@ namespace ts { // Special case for class expressions because we would like to indicate that // the class name is local to the class body (similar to function expression) // (local class) class - if (symbol.getName() === "__class") { + if (getDeclarationOfKind(symbol, SyntaxKind.ClassExpression)) { pushTypePart(ScriptElementKind.localClassElement); } else { From 06c9876368a0466c47c322c7f8c153354844333f Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 1 Jul 2015 18:45:58 -0700 Subject: [PATCH 17/88] Address code review --- src/compiler/checker.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e1f99882079..25841884f19 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12686,10 +12686,7 @@ namespace ts { // we will add the symbol into the table using its declared name let name = (location).name; if (name) { - let symbol = location.symbol; - if (symbol.flags & meaning && !hasProperty(symbols, name.text)) { - symbols[name.text] = symbol; - } + copySymbol(location.symbol, meaning, name.text); } break; } @@ -12701,11 +12698,18 @@ namespace ts { copySymbols(globals, meaning); } - // Returns 'true' if we should stop processing symbols. - function copySymbol(symbol: Symbol, meaning: SymbolFlags): void { + /** + * Copy the given symbol into symbol tables if the symbol has the given meaning + * and it doesn't already existed in the symbol table + * + * @param symbol the symbol to be added into symbol table + * @param meaning meaning of symbol to filter by before adding to symbol table + * @param key a key for storing in symbol table; if null, use symbol.name + */ + function copySymbol(symbol: Symbol, meaning: SymbolFlags, key?: string): void { if (symbol.flags & meaning) { - let id = symbol.name; - if (!isReservedMemberName(id) && !hasProperty(symbols, id)) { + let id = key || symbol.name; + if (!hasProperty(symbols, id)) { symbols[id] = symbol; } } @@ -12714,9 +12718,7 @@ namespace ts { function copySymbols(source: SymbolTable, meaning: SymbolFlags): void { if (meaning) { for (let id in source) { - if (hasProperty(source, id)) { - copySymbol(source[id], meaning); - } + copySymbol(source[id], meaning); } } } From a61ec94501ccabae192415067101c58f4d916c5c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 2 Jul 2015 16:04:34 -0700 Subject: [PATCH 18/88] Remove unnecessary check. --- src/services/services.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 159b1b817b1..80fde22c73b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3359,7 +3359,6 @@ namespace ts { case SyntaxKind.DotDotDotToken: return containingNodeKind === SyntaxKind.Parameter || - containingNodeKind === SyntaxKind.Constructor || (previousToken.parent && previousToken.parent.parent && previousToken.parent.parent.kind === SyntaxKind.ArrayBindingPattern); // var [...z| From 4a53096171c9ad64b2517558718df9db72b002ed Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 2 Jul 2015 16:14:06 -0700 Subject: [PATCH 19/88] Added test. --- .../cases/fourslash/completionListAfterSpreadOperator01.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/cases/fourslash/completionListAfterSpreadOperator01.ts diff --git a/tests/cases/fourslash/completionListAfterSpreadOperator01.ts b/tests/cases/fourslash/completionListAfterSpreadOperator01.ts new file mode 100644 index 00000000000..48a50124daf --- /dev/null +++ b/tests/cases/fourslash/completionListAfterSpreadOperator01.ts @@ -0,0 +1,7 @@ +/// + +////let v = [1,2,3,4]; +////let x = [.../**/ + +goTo.marker(); +verify.completionListContains("v"); \ No newline at end of file From 935071f1c53bf042a62a7f9a5b4b0e6e853fc653 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 2 Jul 2015 16:21:09 -0700 Subject: [PATCH 20/88] Don't show completion with dots not part of property accesses and qualified names. --- src/services/services.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 80fde22c73b..71f92d0c4c8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2902,23 +2902,30 @@ namespace ts { let jsx = options.jsx !== JsxEmit.None; let target = options.target; - // Find the node where completion is requested on, in the case of a completion after - // a dot, it is the member access expression other wise, it is a request for all - // visible symbols in the scope, and the node is the current location. + // Find the node where completion is requested on. + // Also determine whether we are trying to complete with members of that node + // or attributes of a JSX tag. let node = currentToken; let isRightOfDot = false; let isRightOfOpenTag = false; let location = getTouchingPropertyName(sourceFile, position); - if(contextToken) { - let kind = contextToken.kind; - if (kind === SyntaxKind.DotToken && contextToken.parent.kind === SyntaxKind.PropertyAccessExpression) { - node = (contextToken.parent).expression; - isRightOfDot = true; - } - else if (kind === SyntaxKind.DotToken && contextToken.parent.kind === SyntaxKind.QualifiedName) { - node = (contextToken.parent).left; - isRightOfDot = true; + if (contextToken) { + let { parent, kind } = contextToken; + if (kind === SyntaxKind.DotToken) { + if (parent.kind === SyntaxKind.PropertyAccessExpression) { + node = (contextToken.parent).expression; + isRightOfDot = true; + } + else if (parent.kind === SyntaxKind.QualifiedName) { + node = (contextToken.parent).left; + isRightOfDot = true; + } + else { + // There is nothing that precedes the dot, so this likely just a stray character + // or leading into a '...' token. Just bail out instead. + return undefined; + } } else if (kind === SyntaxKind.LessThanToken && sourceFile.languageVariant === LanguageVariant.JSX) { isRightOfOpenTag = true; From d89c1d6586b79de7b0a8470b1b4f205cc4627e37 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 2 Jul 2015 17:08:03 -0700 Subject: [PATCH 21/88] Fixed/added test. --- .../fourslash/completionListBuilderLocations_Modules.ts | 3 +-- tests/cases/fourslash/memberListAfterDoubleDot.ts | 6 ++++++ tests/cases/fourslash/memberListAfterSingleDot.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/memberListAfterDoubleDot.ts diff --git a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts index eac7085ab66..8a136d0125c 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts @@ -8,6 +8,5 @@ test.markers().forEach((m) => { goTo.position(m.position, m.fileName); - verify.not.completionListIsEmpty(); - verify.completionListAllowsNewIdentifier(); + verify.completionListIsEmpty(); }); \ No newline at end of file diff --git a/tests/cases/fourslash/memberListAfterDoubleDot.ts b/tests/cases/fourslash/memberListAfterDoubleDot.ts new file mode 100644 index 00000000000..21a1ad913ea --- /dev/null +++ b/tests/cases/fourslash/memberListAfterDoubleDot.ts @@ -0,0 +1,6 @@ +/// + +////../**/ + +goTo.marker(); +verify.memberListIsEmpty(); \ No newline at end of file diff --git a/tests/cases/fourslash/memberListAfterSingleDot.ts b/tests/cases/fourslash/memberListAfterSingleDot.ts index 0bc5107f2c1..62edf3b8c9e 100644 --- a/tests/cases/fourslash/memberListAfterSingleDot.ts +++ b/tests/cases/fourslash/memberListAfterSingleDot.ts @@ -3,4 +3,4 @@ ////./**/ goTo.marker(); -verify.not.memberListIsEmpty(); \ No newline at end of file +verify.memberListIsEmpty(); \ No newline at end of file From 6da98ce897564ede1e83d7e29934035287887830 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 6 Jul 2015 10:51:43 -0700 Subject: [PATCH 22/88] Fix comments --- src/compiler/checker.ts | 4 ---- src/harness/fourslash.ts | 10 ++++++++-- src/services/services.ts | 13 +++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 25841884f19..14e2b889ede 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12680,10 +12680,6 @@ namespace ts { break; case SyntaxKind.FunctionExpression: case SyntaxKind.ClassExpression: - // The reason we are not using copySymbol for function expression and class expression - // is that copySymbol will not copy a symbol into SymbolTable if the symbol has name prefix - // with "__". Therefore, if class expression or function expression have declared name, - // we will add the symbol into the table using its declared name let name = (location).name; if (name) { copySymbol(location.symbol, meaning, name.text); diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 9a07482e60d..2454ebb26c9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -705,8 +705,14 @@ module FourSlash { } /** - * Verfiy that the completion list does NOT contain the given symbol. If text, or documentation, or kind are provided, - * the list contains the symbol all given parameters must matched. When any parameter is omitted, the parameters is ignored during comparison. + * Verify that the completion list does NOT contain the given symbol. + * The symbol is considered matched with the symbol in the list if and only if all given parameters must matched. + * When any parameter is omitted, the parameter is ignored during comparison and assumed that the parameter with + * that property of the symbol in the list. + * @param symbol the name of symbol + * @param expectedText the text associated with the symbol + * @param expectedDocumentation the documentation text associated with the symbol + * @param expectedKind the kind of symbol (see ScriptElementKind) */ public verifyCompletionListDoesNotContain(symbol: string, expectedText?: string, expectedDocumentation?: string, expectedKind?: string) { let that = this; diff --git a/src/services/services.ts b/src/services/services.ts index 01500b23812..cfbe8f4ee29 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2847,13 +2847,14 @@ namespace ts { name = stripQuotes(name); - // We can simply return name with strip quotes because the name could be an invalid identifier name - // e.g "b a" is valid quoted name but when we strip off the quotes, it is invalid. - // We, thus, need to check if whatever was inside the quotes is actually a valid identifier name. if (!name) { return undefined; } + // If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an + // invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name. + // e.g "b a" is valid quoted name but when we strip off the quotes, it is invalid. + // We, thus, need to check if whatever was inside the quotes is actually a valid identifier name. if (performCharacterChecks) { if (!isIdentifierStart(name.charCodeAt(0), target)) { return undefined; @@ -3829,10 +3830,10 @@ namespace ts { } } if (symbolFlags & SymbolFlags.Class && !hasAddedSymbolInfo) { - // Special case for class expressions because we would like to indicate that - // the class name is local to the class body (similar to function expression) - // (local class) class if (getDeclarationOfKind(symbol, SyntaxKind.ClassExpression)) { + // Special case for class expressions because we would like to indicate that + // the class name is local to the class body (similar to function expression) + // (local class) class pushTypePart(ScriptElementKind.localClassElement); } else { From 3fe0d3defe974a72382f22917486247644dea20e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 11:30:43 -0700 Subject: [PATCH 23/88] Updated test. --- .../fourslash/completionListBuilderLocations_Modules.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts index 8a136d0125c..0552e540a7e 100644 --- a/tests/cases/fourslash/completionListBuilderLocations_Modules.ts +++ b/tests/cases/fourslash/completionListBuilderLocations_Modules.ts @@ -5,8 +5,8 @@ ////module A./*moduleName2*/ +goTo.marker("moduleName1"); +verify.not.completionListIsEmpty(); -test.markers().forEach((m) => { - goTo.position(m.position, m.fileName); - verify.completionListIsEmpty(); -}); \ No newline at end of file +goTo.marker("moduleName2"); +verify.completionListIsEmpty(); From a7983a4f3e676cd75a971dc3d69e99f36f103b7c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 12:40:05 -0700 Subject: [PATCH 24/88] Added test for JSX spread properties. --- tests/cases/fourslash/tsxCompletion4.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/cases/fourslash/tsxCompletion4.ts diff --git a/tests/cases/fourslash/tsxCompletion4.ts b/tests/cases/fourslash/tsxCompletion4.ts new file mode 100644 index 00000000000..6a66c4a898f --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion4.ts @@ -0,0 +1,14 @@ +/// + +//@Filename: file.tsx +//// declare namespace JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { one; two; } +//// } +//// } +//// let bag = { x: 100, y: 200 }; +////
Date: Mon, 6 Jul 2015 13:00:10 -0700 Subject: [PATCH 25/88] previousToken -> contextToken --- src/services/services.ts | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 71f92d0c4c8..ac55e888c03 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3142,11 +3142,11 @@ namespace ts { return scope; } - function isCompletionListBlocker(previousToken: Node): boolean { + function isCompletionListBlocker(contextToken: Node): boolean { let start = new Date().getTime(); - let result = isInStringOrRegularExpressionOrTemplateLiteral(previousToken) || - isIdentifierDefinitionLocation(previousToken) || - isRightOfIllegalDot(previousToken); + let result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || + isIdentifierDefinitionLocation(contextToken) || + isRightOfIllegalDot(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } @@ -3225,12 +3225,12 @@ namespace ts { return false; } - function isInStringOrRegularExpressionOrTemplateLiteral(previousToken: Node): boolean { - if (previousToken.kind === SyntaxKind.StringLiteral - || previousToken.kind === SyntaxKind.RegularExpressionLiteral - || isTemplateLiteralKind(previousToken.kind)) { - let start = previousToken.getStart(); - let end = previousToken.getEnd(); + function isInStringOrRegularExpressionOrTemplateLiteral(contextToken: Node): boolean { + if (contextToken.kind === SyntaxKind.StringLiteral + || contextToken.kind === SyntaxKind.RegularExpressionLiteral + || isTemplateLiteralKind(contextToken.kind)) { + let start = contextToken.getStart(); + let end = contextToken.getEnd(); // To be "in" one of these literals, the position has to be: // 1. entirely within the token text. @@ -3241,8 +3241,8 @@ namespace ts { } if (position === end) { - return !!(previousToken).isUnterminated || - previousToken.kind === SyntaxKind.RegularExpressionLiteral; + return !!(contextToken).isUnterminated || + contextToken.kind === SyntaxKind.RegularExpressionLiteral; } } @@ -3316,10 +3316,10 @@ namespace ts { return false; } - function isIdentifierDefinitionLocation(previousToken: Node): boolean { - if (previousToken) { - let containingNodeKind = previousToken.parent.kind; - switch (previousToken.kind) { + function isIdentifierDefinitionLocation(contextToken: Node): boolean { + if (contextToken) { + let containingNodeKind = contextToken.parent.kind; + switch (contextToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.VariableDeclaration || containingNodeKind === SyntaxKind.VariableDeclarationList || @@ -3351,9 +3351,9 @@ namespace ts { case SyntaxKind.SemicolonToken: return containingNodeKind === SyntaxKind.PropertySignature && - previousToken.parent && previousToken.parent.parent && - (previousToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; | - previousToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; | + contextToken.parent && contextToken.parent.parent && + (contextToken.parent.parent.kind === SyntaxKind.InterfaceDeclaration || // interface a { f; | + contextToken.parent.parent.kind === SyntaxKind.TypeLiteral); // let x : { a; | case SyntaxKind.LessThanToken: return containingNodeKind === SyntaxKind.ClassDeclaration || // class A< | @@ -3366,8 +3366,8 @@ namespace ts { case SyntaxKind.DotDotDotToken: return containingNodeKind === SyntaxKind.Parameter || - (previousToken.parent && previousToken.parent.parent && - previousToken.parent.parent.kind === SyntaxKind.ArrayBindingPattern); // var [...z| + (contextToken.parent && contextToken.parent.parent && + contextToken.parent.parent.kind === SyntaxKind.ArrayBindingPattern); // var [...z| case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: @@ -3390,7 +3390,7 @@ namespace ts { } // Previous token may have been a keyword that was converted to an identifier. - switch (previousToken.getText()) { + switch (contextToken.getText()) { case "class": case "interface": case "enum": @@ -3407,9 +3407,9 @@ namespace ts { return false; } - function isRightOfIllegalDot(previousToken: Node): boolean { - if (previousToken && previousToken.kind === SyntaxKind.NumericLiteral) { - let text = previousToken.getFullText(); + function isRightOfIllegalDot(contextToken: Node): boolean { + if (contextToken && contextToken.kind === SyntaxKind.NumericLiteral) { + let text = contextToken.getFullText(); return text.charAt(text.length - 1) === "."; } From cacc366809294e6f6552688d9637c031944394b5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 13:27:00 -0700 Subject: [PATCH 26/88] Avoid unnecessary contextToken checking, addressed CR feedback. --- src/services/services.ts | 170 +++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 88 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index ac55e888c03..3d92bd5b476 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2892,16 +2892,6 @@ namespace ts { log("getCompletionData: Get previous token 2: " + (new Date().getTime() - start)); } - // Check if this is a valid completion location - if (contextToken && isCompletionListBlocker(contextToken)) { - log("Returning an empty list because completion was requested in an invalid position."); - return undefined; - } - - let options = program.getCompilerOptions(); - let jsx = options.jsx !== JsxEmit.None; - let target = options.target; - // Find the node where completion is requested on. // Also determine whether we are trying to complete with members of that node // or attributes of a JSX tag. @@ -2911,6 +2901,12 @@ namespace ts { let location = getTouchingPropertyName(sourceFile, position); if (contextToken) { + // Bail out if this is a known invalid completion location + if (isCompletionListBlocker(contextToken)) { + log("Returning an empty list because completion was requested in an invalid position."); + return undefined; + } + let { parent, kind } = contextToken; if (kind === SyntaxKind.DotToken) { if (parent.kind === SyntaxKind.PropertyAccessExpression) { @@ -3146,7 +3142,7 @@ namespace ts { let start = new Date().getTime(); let result = isInStringOrRegularExpressionOrTemplateLiteral(contextToken) || isIdentifierDefinitionLocation(contextToken) || - isRightOfIllegalDot(contextToken); + isDotOfNumericLiteral(contextToken); log("getCompletionsAtPosition: isCompletionListBlocker: " + (new Date().getTime() - start)); return result; } @@ -3241,8 +3237,8 @@ namespace ts { } if (position === end) { - return !!(contextToken).isUnterminated || - contextToken.kind === SyntaxKind.RegularExpressionLiteral; + return !!(contextToken).isUnterminated + || contextToken.kind === SyntaxKind.RegularExpressionLiteral; } } @@ -3317,98 +3313,96 @@ namespace ts { } function isIdentifierDefinitionLocation(contextToken: Node): boolean { - if (contextToken) { - let containingNodeKind = contextToken.parent.kind; - switch (contextToken.kind) { - case SyntaxKind.CommaToken: - return containingNodeKind === SyntaxKind.VariableDeclaration || - containingNodeKind === SyntaxKind.VariableDeclarationList || - containingNodeKind === SyntaxKind.VariableStatement || - containingNodeKind === SyntaxKind.EnumDeclaration || // enum a { foo, | - isFunction(containingNodeKind) || - containingNodeKind === SyntaxKind.ClassDeclaration || // class A Date: Mon, 6 Jul 2015 14:18:47 -0700 Subject: [PATCH 27/88] Address code review --- src/compiler/checker.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 45cd9a7f0c6..171b6eb1837 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13381,7 +13381,7 @@ namespace ts { case SyntaxKind.ClassExpression: let name = (location).name; if (name) { - copySymbol(location.symbol, meaning, name.text); + copySymbol(name.text, location.symbol, meaning); } break; } @@ -13396,12 +13396,11 @@ namespace ts { /** * Copy the given symbol into symbol tables if the symbol has the given meaning * and it doesn't already existed in the symbol table - * + * @param key a key for storing in symbol table; if null, use symbol.name * @param symbol the symbol to be added into symbol table * @param meaning meaning of symbol to filter by before adding to symbol table - * @param key a key for storing in symbol table; if null, use symbol.name */ - function copySymbol(symbol: Symbol, meaning: SymbolFlags, key?: string): void { + function copySymbol(key: string, symbol: Symbol, meaning: SymbolFlags): void { if (symbol.flags & meaning) { let id = key || symbol.name; if (!hasProperty(symbols, id)) { @@ -13413,7 +13412,8 @@ namespace ts { function copySymbols(source: SymbolTable, meaning: SymbolFlags): void { if (meaning) { for (let id in source) { - copySymbol(source[id], meaning); + let symbol = source[id]; + copySymbol(symbol.name, symbol, meaning); } } } From 276e7989aa414a7b6fdc50df21fe10fb15eb1d88 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 14:47:39 -0700 Subject: [PATCH 28/88] Use a more accurate test name. --- ...{completionForExports.ts => completionListInImportClause01.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{completionForExports.ts => completionListInImportClause01.ts} (100%) diff --git a/tests/cases/fourslash/completionForExports.ts b/tests/cases/fourslash/completionListInImportClause01.ts similarity index 100% rename from tests/cases/fourslash/completionForExports.ts rename to tests/cases/fourslash/completionListInImportClause01.ts From 03444a4d349c1d1b3b46cffa55ea096f479c1324 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 15:02:18 -0700 Subject: [PATCH 29/88] Verify builders. --- .../completionListInImportClause01.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/cases/fourslash/completionListInImportClause01.ts b/tests/cases/fourslash/completionListInImportClause01.ts index 57c0f75efc1..cf053868dd6 100644 --- a/tests/cases/fourslash/completionListInImportClause01.ts +++ b/tests/cases/fourslash/completionListInImportClause01.ts @@ -11,22 +11,29 @@ ////import {foo,/*4*/ from "m1" ////import {bar as /*5*/, /*6*/ from "m1" ////import {foo, bar, baz as b,/*7*/} from "m1" -function verifyCompletionAtMarker(marker: string, ...completions: string[]) { +function verifyCompletionAtMarker(marker: string, showBuilder: boolean, ...completions: string[]) { goTo.marker(marker); if (completions.length) { - for (var i = 0; i < completions.length; ++i) { + for (let i = 0; i < completions.length; ++i) { verify.completionListContains(completions[i]); } } else { verify.completionListIsEmpty(); } + + if (showBuilder) { + verify.completionListAllowsNewIdentifier(); + } + else { + verify.not.completionListAllowsNewIdentifier(); + } } -verifyCompletionAtMarker("1", "foo", "bar", "baz"); -verifyCompletionAtMarker("2", "foo", "bar", "baz"); -verifyCompletionAtMarker("3", "foo", "bar", "baz"); -verifyCompletionAtMarker("4", "bar", "baz"); -verifyCompletionAtMarker("5"); -verifyCompletionAtMarker("6", "foo", "baz"); -verifyCompletionAtMarker("7"); \ No newline at end of file +verifyCompletionAtMarker("1", /*showBuilder*/ false, "foo", "bar", "baz"); +verifyCompletionAtMarker("2", /*showBuilder*/ false, "foo", "bar", "baz"); +verifyCompletionAtMarker("3", /*showBuilder*/ false, "foo", "bar", "baz"); +verifyCompletionAtMarker("4", /*showBuilder*/ false, "bar", "baz"); +verifyCompletionAtMarker("5", /*showBuilder*/ true); +verifyCompletionAtMarker("6", /*showBuilder*/ false, "foo", "baz"); +verifyCompletionAtMarker("7", /*showBuilder*/ false); \ No newline at end of file From 52581678d4f8341d0c83c2ae6991fab82edc75b6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 15:05:47 -0700 Subject: [PATCH 30/88] Refactor completion code for object literals/bindings and import clauses. --- src/services/services.ts | 114 ++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index e401182fb11..6f7d233244e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3010,59 +3010,21 @@ namespace ts { } function tryGetGlobalSymbols(): boolean { - let objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken); - let jsxContainer = tryGetContainingJsxElement(contextToken); - if (objectLikeContainer) { - // Object literal expression, look up possible property names from contextual type - isMemberCompletion = true; - isNewIdentifierLocation = true; + let objectLikeContainer: ObjectLiteralExpression | BindingPattern; + let importClause: ImportClause; + let jsxContainer: JsxOpeningLikeElement; - let typeForObject: Type; - let existingMembers: Declaration[]; - - if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) { - typeForObject = typeChecker.getContextualType(objectLikeContainer); - existingMembers = (objectLikeContainer).properties; - } - else { - typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); - existingMembers = (objectLikeContainer).elements; - } - - if (!typeForObject) { - return false; - } - - let typeMembers = typeChecker.getPropertiesOfType(typeForObject); - if (typeMembers && typeMembers.length > 0) { - // Add filtered items to the completion list - symbols = filterObjectMembersList(typeMembers, existingMembers); - } - return true; + if (objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken)) { + return tryGetObjectLikeCompletionSymbols(objectLikeContainer); } - else if (getAncestor(contextToken, SyntaxKind.ImportClause)) { - // cursor is in import clause + + if (importClause = getAncestor(contextToken, SyntaxKind.ImportClause)) { + // cursor is in an import clause // try to show exported member for imported module - isMemberCompletion = true; - isNewIdentifierLocation = true; - if (showCompletionsInImportsClause(contextToken)) { - let importDeclaration = getAncestor(contextToken, SyntaxKind.ImportDeclaration); - Debug.assert(importDeclaration !== undefined); - - let exports: Symbol[]; - if (importDeclaration.moduleSpecifier) { - let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); - if (moduleSpecifierSymbol) { - exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); - } - } - - //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); - symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray; - } - return true; + return tryGetImportClauseCompletionSymbols(importClause); } - else if (jsxContainer) { + + if (jsxContainer = tryGetContainingJsxElement(contextToken)) { let attrsType: Type; if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) { // Cursor is inside a JSX self-closing element or opening element @@ -3144,7 +3106,7 @@ namespace ts { return result; } - function showCompletionsInImportsClause(node: Node): boolean { + function shouldShowCompletionsInImportsClause(node: Node): boolean { if (node) { // import {| // import {a,| @@ -3242,6 +3204,58 @@ namespace ts { return false; } + function tryGetObjectLikeCompletionSymbols(objectLikeContainer: ObjectLiteralExpression | BindingPattern): boolean { + // Object literal expression, look up possible property names from contextual type + isMemberCompletion = true; + isNewIdentifierLocation = true; + + let typeForObject: Type; + let existingMembers: Declaration[]; + + if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) { + typeForObject = typeChecker.getContextualType(objectLikeContainer); + existingMembers = (objectLikeContainer).properties; + } + else { + typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer); + existingMembers = (objectLikeContainer).elements; + } + + if (!typeForObject) { + return false; + } + + let typeMembers = typeChecker.getPropertiesOfType(typeForObject); + if (typeMembers && typeMembers.length > 0) { + // Add filtered items to the completion list + symbols = filterObjectMembersList(typeMembers, existingMembers); + } + return true; + } + + function tryGetImportClauseCompletionSymbols(importClause: ImportClause): boolean { + // cursor is in import clause + // try to show exported member for imported module + isMemberCompletion = true; + isNewIdentifierLocation = true; + if (shouldShowCompletionsInImportsClause(contextToken)) { + let importDeclaration = getAncestor(contextToken, SyntaxKind.ImportDeclaration); + Debug.assert(importDeclaration !== undefined); + + let exports: Symbol[]; + if (importDeclaration.moduleSpecifier) { + let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); + if (moduleSpecifierSymbol) { + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); + } + } + + //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); + symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray; + } + return true; + } + /** * Returns the immediate owning object literal or binding pattern of a context token, * on the condition that one exists and that the context implies completion should be given. From 4906f41f94cc7112a675699fc77c9b8ff085460a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 15:12:16 -0700 Subject: [PATCH 31/88] Remove builder from import clauses. --- src/services/services.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 6f7d233244e..5f2d1714482 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3236,9 +3236,10 @@ namespace ts { function tryGetImportClauseCompletionSymbols(importClause: ImportClause): boolean { // cursor is in import clause // try to show exported member for imported module - isMemberCompletion = true; - isNewIdentifierLocation = true; if (shouldShowCompletionsInImportsClause(contextToken)) { + isMemberCompletion = true; + isNewIdentifierLocation = false; + let importDeclaration = getAncestor(contextToken, SyntaxKind.ImportDeclaration); Debug.assert(importDeclaration !== undefined); @@ -3253,6 +3254,11 @@ namespace ts { //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); symbols = exports ? filterModuleExports(exports, importDeclaration) : emptyArray; } + else { + isMemberCompletion = false; + isNewIdentifierLocation = true; + } + return true; } From 40a6300e02de76eebc4ab35ae4c113dd23185555 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 15:15:04 -0700 Subject: [PATCH 32/88] Added original test case. --- .../completionListInImportClause02.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/cases/fourslash/completionListInImportClause02.ts diff --git a/tests/cases/fourslash/completionListInImportClause02.ts b/tests/cases/fourslash/completionListInImportClause02.ts new file mode 100644 index 00000000000..570dd452a7f --- /dev/null +++ b/tests/cases/fourslash/completionListInImportClause02.ts @@ -0,0 +1,18 @@ +/// + +// @Filename: m1.ts +////export var foo: number = 1; +////export function bar() { return 10; } +////export function baz() { return 10; } + +////declare module "M1" { +//// export var V; +////} +//// +////declare module "M2" { +//// import { /**/ } from "M1" +////} + +goTo.marker(); +verify.completionListContains("V"); +verify.not.completionListAllowsNewIdentifier(); From 97dd855663e48ee6d84e99869fc70c543dba5193 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 15:33:49 -0700 Subject: [PATCH 33/88] Fix test. --- tests/cases/fourslash/completionListInImportClause02.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/cases/fourslash/completionListInImportClause02.ts b/tests/cases/fourslash/completionListInImportClause02.ts index 570dd452a7f..9cf216f4578 100644 --- a/tests/cases/fourslash/completionListInImportClause02.ts +++ b/tests/cases/fourslash/completionListInImportClause02.ts @@ -1,10 +1,5 @@ /// -// @Filename: m1.ts -////export var foo: number = 1; -////export function bar() { return 10; } -////export function baz() { return 10; } - ////declare module "M1" { //// export var V; ////} From be183819269eb691f393b5fc0fbe668602e8e698 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 6 Jul 2015 15:34:44 -0700 Subject: [PATCH 34/88] Removed unnecessary check. --- src/services/services.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5f2d1714482..d2f9ca8b890 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3240,15 +3240,13 @@ namespace ts { isMemberCompletion = true; isNewIdentifierLocation = false; - let importDeclaration = getAncestor(contextToken, SyntaxKind.ImportDeclaration); - Debug.assert(importDeclaration !== undefined); + let importDeclaration = importClause.parent; + Debug.assert(importDeclaration !== undefined && importDeclaration.kind === SyntaxKind.ImportDeclaration); let exports: Symbol[]; - if (importDeclaration.moduleSpecifier) { - let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); - if (moduleSpecifierSymbol) { - exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); - } + let moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(importDeclaration.moduleSpecifier); + if (moduleSpecifierSymbol) { + exports = typeChecker.getExportsOfModule(moduleSpecifierSymbol); } //let exports = typeInfoResolver.getExportsOfImportDeclaration(importDeclaration); From f4cd1ac868ee76d4f7c6814be15a561b327a962c Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 6 Jul 2015 17:03:33 -0700 Subject: [PATCH 35/88] Address code review, handle type parameter in completion list inside class expression --- src/compiler/checker.ts | 18 ++++++++++++++---- src/harness/fourslash.ts | 2 +- ...onListInClassExpressionWithTypeParameter.ts | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 171b6eb1837..ca7df8d9810 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13371,17 +13371,27 @@ namespace ts { case SyntaxKind.EnumDeclaration: copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember); break; + case SyntaxKind.ClassExpression: + let className = (location).name; + if (className) { + copySymbol(className.text, location.symbol, meaning); + } + // fall through; this fall-through is necessary because we would like to handle + // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: + // If we didn't come from static member of class or interface, add the type parameters into the symbol table + // (type parameters of classDeclaration/classExpression and interface are in member property of the symbol. + // jNote: that the memberFlags come from previous iteration. if (!(memberFlags & NodeFlags.Static)) { copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type); } break; case SyntaxKind.FunctionExpression: case SyntaxKind.ClassExpression: - let name = (location).name; - if (name) { - copySymbol(name.text, location.symbol, meaning); + let funcName = (location).name; + if (funcName) { + copySymbol(funcName.text, location.symbol, meaning); } break; } @@ -13396,7 +13406,7 @@ namespace ts { /** * Copy the given symbol into symbol tables if the symbol has the given meaning * and it doesn't already existed in the symbol table - * @param key a key for storing in symbol table; if null, use symbol.name + * @param key a key for storing in symbol table; if undefined, use symbol.name * @param symbol the symbol to be added into symbol table * @param meaning meaning of symbol to filter by before adding to symbol table */ diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 2454ebb26c9..475a73ccd7c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2215,7 +2215,7 @@ module FourSlash { var itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n"); - this.raiseError('Expected "' + JSON.stringify({ name: name, text: text, documentation: documentation, kind: kind }) + '" to be in list [' + itemsString + ']'); + this.raiseError('Expected "' + JSON.stringify({ name, text, documentation, kind }) + '" to be in list [' + itemsString + ']'); } private findFile(indexOrName: any) { diff --git a/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts b/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts new file mode 100644 index 00000000000..6f016b73a76 --- /dev/null +++ b/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts @@ -0,0 +1,14 @@ +/// + +//// var x = class myClass { +//// getClassName (){ +//// /*0*/ +//// } +//// prop: Ty/*1*/ +//// } + +goTo.marker("0"); +verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass", /*documentation*/ undefined, "type parameter"); + +goTo.marker("1"); +verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass", /*documentation*/ undefined, "type parameter"); \ No newline at end of file From 0148915daf28d8a4117ffeb047198d72cb69b64b Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 09:18:08 -0700 Subject: [PATCH 36/88] Fix comment --- src/compiler/checker.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ca7df8d9810..df6796947fc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13380,9 +13380,10 @@ namespace ts { // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: - // If we didn't come from static member of class or interface, add the type parameters into the symbol table + // If we didn't come from static member of class or interface, + // add the type parameters into the symbol table // (type parameters of classDeclaration/classExpression and interface are in member property of the symbol. - // jNote: that the memberFlags come from previous iteration. + // Note: that the memberFlags come from previous iteration. if (!(memberFlags & NodeFlags.Static)) { copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type); } From 93a721cf1d54e701e5b9a0c2972465997f1d9560 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 09:57:58 -0700 Subject: [PATCH 37/88] Bind classExpression and functionExpression to its name if the expression is declared with name --- src/compiler/binder.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e30178e987b..5a39e96b119 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -892,7 +892,8 @@ namespace ts { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: checkStrictModeFunctionName(node); - return bindAnonymousDeclaration(node, SymbolFlags.Function, "__function"); + let bindingName = (node).name ? (node).name.text : "__function"; + return bindAnonymousDeclaration(node, SymbolFlags.Function, bindingName); case SyntaxKind.ClassExpression: case SyntaxKind.ClassDeclaration: return bindClassLikeDeclaration(node); @@ -964,7 +965,8 @@ namespace ts { bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); } else { - bindAnonymousDeclaration(node, SymbolFlags.Class, "__class"); + let bindingName = node.name ? node.name.text : "__class"; + bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName); } let symbol = node.symbol; From 92d2d1957d0e6badcad6a6af228dea1df158244a Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 09:58:13 -0700 Subject: [PATCH 38/88] Update tests --- .../reference/classExpressionTest2.types | 6 +++--- .../renameLocationsForClassExpression01.ts | 20 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/baselines/reference/classExpressionTest2.types b/tests/baselines/reference/classExpressionTest2.types index 5586b451d3a..2ff7d79bc5f 100644 --- a/tests/baselines/reference/classExpressionTest2.types +++ b/tests/baselines/reference/classExpressionTest2.types @@ -28,13 +28,13 @@ function M() { } var v = new m(); ->v : ->new m() : +>v : C +>new m() : C >m : typeof C return v.f(); >v.f() : { t: string; x: number; } >v.f : () => { t: T; x: number; } ->v : +>v : C >f : () => { t: T; x: number; } } diff --git a/tests/cases/fourslash/renameLocationsForClassExpression01.ts b/tests/cases/fourslash/renameLocationsForClassExpression01.ts index a1174d503ed..e7247f8e4ee 100644 --- a/tests/cases/fourslash/renameLocationsForClassExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForClassExpression01.ts @@ -3,13 +3,13 @@ ////class Foo { ////} //// -////var x = class /**/Foo { +////var x = class [|Foo|] { //// doIt() { -//// return Foo; +//// return [|Foo|]; //// } //// //// static doItStatically() { -//// return Foo; +//// return [|Foo|]; //// } ////} //// @@ -23,12 +23,10 @@ // TODO (yuit): Fix up this test when class expressions are supported. // Just uncomment the below, remove the marker, and add the // appropriate ranges in the test itself. -goTo.marker(); -verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); -////let ranges = test.ranges() -////for (let range of ranges) { -//// goTo.position(range.start); -//// -//// verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); -////} \ No newline at end of file +let ranges = test.ranges() +for (let range of ranges) { + goTo.position(range.start); + + verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); +} \ No newline at end of file From 1a8200fea7e084757ee7810f062bdb7ddcf030b3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 11:01:34 -0700 Subject: [PATCH 39/88] Add testcase for #3764 --- .../reference/tsxElementResolution19.js | 36 +++++++++++++++++++ .../reference/tsxElementResolution19.symbols | 28 +++++++++++++++ .../reference/tsxElementResolution19.types | 29 +++++++++++++++ .../jsx/tsxElementResolution19.tsx | 21 +++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tests/baselines/reference/tsxElementResolution19.js create mode 100644 tests/baselines/reference/tsxElementResolution19.symbols create mode 100644 tests/baselines/reference/tsxElementResolution19.types create mode 100644 tests/cases/conformance/jsx/tsxElementResolution19.tsx diff --git a/tests/baselines/reference/tsxElementResolution19.js b/tests/baselines/reference/tsxElementResolution19.js new file mode 100644 index 00000000000..ebcb66e536f --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution19.js @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/jsx/tsxElementResolution19.tsx] //// + +//// [react.d.ts] + +declare module "react" { + +} + +//// [file1.tsx] +declare module JSX { + interface Element { } +} +export class MyClass { } + +//// [file2.tsx] + +// Should not elide React import +import * as React from 'react'; +import {MyClass} from './file1'; + +; + + +//// [file1.js] +define(["require", "exports"], function (require, exports) { + var MyClass = (function () { + function MyClass() { + } + return MyClass; + })(); + exports.MyClass = MyClass; +}); +//// [file2.js] +define(["require", "exports", './file1'], function (require, exports, file1_1) { + React.createElement(file1_1.MyClass, null); +}); diff --git a/tests/baselines/reference/tsxElementResolution19.symbols b/tests/baselines/reference/tsxElementResolution19.symbols new file mode 100644 index 00000000000..48aa4f962b6 --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution19.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/jsx/react.d.ts === + +No type information for this code.declare module "react" { +No type information for this code. +No type information for this code.} +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsx/file1.tsx === +declare module JSX { +>JSX : Symbol(JSX, Decl(file1.tsx, 0, 0)) + + interface Element { } +>Element : Symbol(Element, Decl(file1.tsx, 0, 20)) +} +export class MyClass { } +>MyClass : Symbol(MyClass, Decl(file1.tsx, 2, 1)) + +=== tests/cases/conformance/jsx/file2.tsx === + +// Should not elide React import +import * as React from 'react'; +>React : Symbol(React, Decl(file2.tsx, 2, 6)) + +import {MyClass} from './file1'; +>MyClass : Symbol(MyClass, Decl(file2.tsx, 3, 8)) + +; +>MyClass : Symbol(MyClass, Decl(file2.tsx, 3, 8)) + diff --git a/tests/baselines/reference/tsxElementResolution19.types b/tests/baselines/reference/tsxElementResolution19.types new file mode 100644 index 00000000000..0fa1eefe5f6 --- /dev/null +++ b/tests/baselines/reference/tsxElementResolution19.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/jsx/react.d.ts === + +No type information for this code.declare module "react" { +No type information for this code. +No type information for this code.} +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsx/file1.tsx === +declare module JSX { +>JSX : any + + interface Element { } +>Element : Element +} +export class MyClass { } +>MyClass : MyClass + +=== tests/cases/conformance/jsx/file2.tsx === + +// Should not elide React import +import * as React from 'react'; +>React : typeof React + +import {MyClass} from './file1'; +>MyClass : typeof MyClass + +; +> : any +>MyClass : typeof MyClass + diff --git a/tests/cases/conformance/jsx/tsxElementResolution19.tsx b/tests/cases/conformance/jsx/tsxElementResolution19.tsx new file mode 100644 index 00000000000..23e503ae962 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxElementResolution19.tsx @@ -0,0 +1,21 @@ +//@jsx: react +//@module: amd + +//@filename: react.d.ts +declare module "react" { + +} + +//@filename: file1.tsx +declare module JSX { + interface Element { } +} +export class MyClass { } + +//@filename: file2.tsx + +// Should not elide React import +import * as React from 'react'; +import {MyClass} from './file1'; + +; From 1568bfd642cd778c30851d8cf53b33a542020443 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 11:32:57 -0700 Subject: [PATCH 40/88] Mark 'React' symbol as used and error if it doesn't exist --- src/compiler/checker.ts | 10 ++++++++++ tests/baselines/reference/tsxElementResolution19.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ef2c6ada2a..7a85a2f08b2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7299,6 +7299,16 @@ namespace ts { checkGrammarJsxElement(node); checkJsxPreconditions(node); + // If we're compiling under --jsx react, the symbol 'React' should + // be marked as 'used' so we don't incorrectly elide its import. And if there + // is no 'React' symbol in scope, we should issue an error. + if(compilerOptions.jsx === JsxEmit.React) { + let reactSym = resolveName(node.tagName, 'React', SymbolFlags.Value, Diagnostics.Cannot_find_name_0, 'React'); + if (reactSym) { + getSymbolLinks(reactSym).referenced = true; + } + } + let targetAttributesType = getJsxElementAttributesType(node); if (getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) { diff --git a/tests/baselines/reference/tsxElementResolution19.js b/tests/baselines/reference/tsxElementResolution19.js index ebcb66e536f..72612e8ce54 100644 --- a/tests/baselines/reference/tsxElementResolution19.js +++ b/tests/baselines/reference/tsxElementResolution19.js @@ -31,6 +31,6 @@ define(["require", "exports"], function (require, exports) { exports.MyClass = MyClass; }); //// [file2.js] -define(["require", "exports", './file1'], function (require, exports, file1_1) { +define(["require", "exports", 'react', './file1'], function (require, exports, React, file1_1) { React.createElement(file1_1.MyClass, null); }); From 1fa74c56a7eab52139ccfca0b858e9032ba473b7 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 11:37:55 -0700 Subject: [PATCH 41/88] Fix up other React tests --- tests/baselines/reference/tsxReactEmit1.js | 1 + .../baselines/reference/tsxReactEmit1.symbols | 78 ++++++++++--------- tests/baselines/reference/tsxReactEmit1.types | 2 + tests/baselines/reference/tsxReactEmit2.js | 1 + .../baselines/reference/tsxReactEmit2.symbols | 18 +++-- tests/baselines/reference/tsxReactEmit2.types | 2 + tests/baselines/reference/tsxReactEmit3.js | 1 + .../baselines/reference/tsxReactEmit3.symbols | 19 +++-- tests/baselines/reference/tsxReactEmit3.types | 3 + .../reference/tsxReactEmit4.errors.txt | 3 +- tests/baselines/reference/tsxReactEmit4.js | 1 + .../reference/tsxReactEmitWhitespace.js | 1 + .../reference/tsxReactEmitWhitespace.symbols | 4 +- .../reference/tsxReactEmitWhitespace.types | 2 + tests/cases/conformance/jsx/tsxReactEmit1.tsx | 1 + tests/cases/conformance/jsx/tsxReactEmit2.tsx | 1 + tests/cases/conformance/jsx/tsxReactEmit3.tsx | 1 + tests/cases/conformance/jsx/tsxReactEmit4.tsx | 1 + .../jsx/tsxReactEmitWhitespace.tsx | 1 + 19 files changed, 85 insertions(+), 56 deletions(-) diff --git a/tests/baselines/reference/tsxReactEmit1.js b/tests/baselines/reference/tsxReactEmit1.js index b6c5fd96183..f1799e5bb77 100644 --- a/tests/baselines/reference/tsxReactEmit1.js +++ b/tests/baselines/reference/tsxReactEmit1.js @@ -5,6 +5,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; var p; var selfClosed1 =
; diff --git a/tests/baselines/reference/tsxReactEmit1.symbols b/tests/baselines/reference/tsxReactEmit1.symbols index 60fa5e70b0a..c9e819c82d3 100644 --- a/tests/baselines/reference/tsxReactEmit1.symbols +++ b/tests/baselines/reference/tsxReactEmit1.symbols @@ -12,133 +12,135 @@ declare module JSX { >s : Symbol(s, Decl(tsxReactEmit1.tsx, 3, 3)) } } +declare var React: any; +>React : Symbol(React, Decl(tsxReactEmit1.tsx, 6, 11)) var p; ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) var selfClosed1 =
; ->selfClosed1 : Symbol(selfClosed1, Decl(tsxReactEmit1.tsx, 8, 3)) +>selfClosed1 : Symbol(selfClosed1, Decl(tsxReactEmit1.tsx, 9, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var selfClosed2 =
; ->selfClosed2 : Symbol(selfClosed2, Decl(tsxReactEmit1.tsx, 9, 3)) +>selfClosed2 : Symbol(selfClosed2, Decl(tsxReactEmit1.tsx, 10, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >x : Symbol(unknown) var selfClosed3 =
; ->selfClosed3 : Symbol(selfClosed3, Decl(tsxReactEmit1.tsx, 10, 3)) +>selfClosed3 : Symbol(selfClosed3, Decl(tsxReactEmit1.tsx, 11, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >x : Symbol(unknown) var selfClosed4 =
; ->selfClosed4 : Symbol(selfClosed4, Decl(tsxReactEmit1.tsx, 11, 3)) +>selfClosed4 : Symbol(selfClosed4, Decl(tsxReactEmit1.tsx, 12, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) var selfClosed5 =
; ->selfClosed5 : Symbol(selfClosed5, Decl(tsxReactEmit1.tsx, 12, 3)) +>selfClosed5 : Symbol(selfClosed5, Decl(tsxReactEmit1.tsx, 13, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) var selfClosed6 =
; ->selfClosed6 : Symbol(selfClosed6, Decl(tsxReactEmit1.tsx, 13, 3)) +>selfClosed6 : Symbol(selfClosed6, Decl(tsxReactEmit1.tsx, 14, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) var selfClosed7 =
; ->selfClosed7 : Symbol(selfClosed7, Decl(tsxReactEmit1.tsx, 14, 3)) +>selfClosed7 : Symbol(selfClosed7, Decl(tsxReactEmit1.tsx, 15, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) >b : Symbol(unknown) var openClosed1 =
; ->openClosed1 : Symbol(openClosed1, Decl(tsxReactEmit1.tsx, 16, 3)) +>openClosed1 : Symbol(openClosed1, Decl(tsxReactEmit1.tsx, 17, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var openClosed2 =
foo
; ->openClosed2 : Symbol(openClosed2, Decl(tsxReactEmit1.tsx, 17, 3)) +>openClosed2 : Symbol(openClosed2, Decl(tsxReactEmit1.tsx, 18, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >n : Symbol(unknown) var openClosed3 =
{p}
; ->openClosed3 : Symbol(openClosed3, Decl(tsxReactEmit1.tsx, 18, 3)) +>openClosed3 : Symbol(openClosed3, Decl(tsxReactEmit1.tsx, 19, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >n : Symbol(unknown) var openClosed4 =
{p < p}
; ->openClosed4 : Symbol(openClosed4, Decl(tsxReactEmit1.tsx, 19, 3)) +>openClosed4 : Symbol(openClosed4, Decl(tsxReactEmit1.tsx, 20, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >n : Symbol(unknown) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) var openClosed5 =
{p > p}
; ->openClosed5 : Symbol(openClosed5, Decl(tsxReactEmit1.tsx, 20, 3)) +>openClosed5 : Symbol(openClosed5, Decl(tsxReactEmit1.tsx, 21, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >n : Symbol(unknown) >b : Symbol(unknown) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) class SomeClass { ->SomeClass : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 20, 45)) +>SomeClass : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45)) f() { ->f : Symbol(f, Decl(tsxReactEmit1.tsx, 22, 17)) +>f : Symbol(f, Decl(tsxReactEmit1.tsx, 23, 17)) var rewrites1 =
{() => this}
; ->rewrites1 : Symbol(rewrites1, Decl(tsxReactEmit1.tsx, 24, 5)) +>rewrites1 : Symbol(rewrites1, Decl(tsxReactEmit1.tsx, 25, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) ->this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 20, 45)) +>this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45)) var rewrites2 =
{[p, ...p, p]}
; ->rewrites2 : Symbol(rewrites2, Decl(tsxReactEmit1.tsx, 25, 5)) +>rewrites2 : Symbol(rewrites2, Decl(tsxReactEmit1.tsx, 26, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) var rewrites3 =
{{p}}
; ->rewrites3 : Symbol(rewrites3, Decl(tsxReactEmit1.tsx, 26, 5)) +>rewrites3 : Symbol(rewrites3, Decl(tsxReactEmit1.tsx, 27, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 26, 25)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 27, 25)) var rewrites4 =
this}>
; ->rewrites4 : Symbol(rewrites4, Decl(tsxReactEmit1.tsx, 28, 5)) +>rewrites4 : Symbol(rewrites4, Decl(tsxReactEmit1.tsx, 29, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >a : Symbol(unknown) ->this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 20, 45)) +>this : Symbol(SomeClass, Decl(tsxReactEmit1.tsx, 21, 45)) var rewrites5 =
; ->rewrites5 : Symbol(rewrites5, Decl(tsxReactEmit1.tsx, 29, 5)) +>rewrites5 : Symbol(rewrites5, Decl(tsxReactEmit1.tsx, 30, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >a : Symbol(unknown) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 7, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 8, 3)) var rewrites6 =
; ->rewrites6 : Symbol(rewrites6, Decl(tsxReactEmit1.tsx, 30, 5)) +>rewrites6 : Symbol(rewrites6, Decl(tsxReactEmit1.tsx, 31, 5)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) >a : Symbol(unknown) ->p : Symbol(p, Decl(tsxReactEmit1.tsx, 30, 27)) +>p : Symbol(p, Decl(tsxReactEmit1.tsx, 31, 27)) } } var whitespace1 =
; ->whitespace1 : Symbol(whitespace1, Decl(tsxReactEmit1.tsx, 34, 3)) +>whitespace1 : Symbol(whitespace1, Decl(tsxReactEmit1.tsx, 35, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var whitespace2 =
{p}
; ->whitespace2 : Symbol(whitespace2, Decl(tsxReactEmit1.tsx, 35, 3)) +>whitespace2 : Symbol(whitespace2, Decl(tsxReactEmit1.tsx, 36, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) var whitespace3 =
->whitespace3 : Symbol(whitespace3, Decl(tsxReactEmit1.tsx, 36, 3)) +>whitespace3 : Symbol(whitespace3, Decl(tsxReactEmit1.tsx, 37, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit1.tsx, 1, 22)) {p} diff --git a/tests/baselines/reference/tsxReactEmit1.types b/tests/baselines/reference/tsxReactEmit1.types index d23cad4560a..0b6e03c5742 100644 --- a/tests/baselines/reference/tsxReactEmit1.types +++ b/tests/baselines/reference/tsxReactEmit1.types @@ -12,6 +12,8 @@ declare module JSX { >s : string } } +declare var React: any; +>React : any var p; >p : any diff --git a/tests/baselines/reference/tsxReactEmit2.js b/tests/baselines/reference/tsxReactEmit2.js index f4a12946ed9..4b2b4695561 100644 --- a/tests/baselines/reference/tsxReactEmit2.js +++ b/tests/baselines/reference/tsxReactEmit2.js @@ -5,6 +5,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; var p1, p2, p3; var spreads1 =
{p2}
; diff --git a/tests/baselines/reference/tsxReactEmit2.symbols b/tests/baselines/reference/tsxReactEmit2.symbols index 9607d9330da..9cf739c960c 100644 --- a/tests/baselines/reference/tsxReactEmit2.symbols +++ b/tests/baselines/reference/tsxReactEmit2.symbols @@ -12,32 +12,34 @@ declare module JSX { >s : Symbol(s, Decl(tsxReactEmit2.tsx, 3, 3)) } } +declare var React: any; +>React : Symbol(React, Decl(tsxReactEmit2.tsx, 6, 11)) var p1, p2, p3; ->p1 : Symbol(p1, Decl(tsxReactEmit2.tsx, 7, 3)) ->p2 : Symbol(p2, Decl(tsxReactEmit2.tsx, 7, 7)) ->p3 : Symbol(p3, Decl(tsxReactEmit2.tsx, 7, 11)) +>p1 : Symbol(p1, Decl(tsxReactEmit2.tsx, 8, 3)) +>p2 : Symbol(p2, Decl(tsxReactEmit2.tsx, 8, 7)) +>p3 : Symbol(p3, Decl(tsxReactEmit2.tsx, 8, 11)) var spreads1 =
{p2}
; ->spreads1 : Symbol(spreads1, Decl(tsxReactEmit2.tsx, 8, 3)) +>spreads1 : Symbol(spreads1, Decl(tsxReactEmit2.tsx, 9, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) var spreads2 =
{p2}
; ->spreads2 : Symbol(spreads2, Decl(tsxReactEmit2.tsx, 9, 3)) +>spreads2 : Symbol(spreads2, Decl(tsxReactEmit2.tsx, 10, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) var spreads3 =
{p2}
; ->spreads3 : Symbol(spreads3, Decl(tsxReactEmit2.tsx, 10, 3)) +>spreads3 : Symbol(spreads3, Decl(tsxReactEmit2.tsx, 11, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) >x : Symbol(unknown) var spreads4 =
{p2}
; ->spreads4 : Symbol(spreads4, Decl(tsxReactEmit2.tsx, 11, 3)) +>spreads4 : Symbol(spreads4, Decl(tsxReactEmit2.tsx, 12, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) >x : Symbol(unknown) var spreads5 =
{p2}
; ->spreads5 : Symbol(spreads5, Decl(tsxReactEmit2.tsx, 12, 3)) +>spreads5 : Symbol(spreads5, Decl(tsxReactEmit2.tsx, 13, 3)) >div : Symbol(JSX.IntrinsicElements, Decl(tsxReactEmit2.tsx, 1, 22)) >x : Symbol(unknown) >y : Symbol(unknown) diff --git a/tests/baselines/reference/tsxReactEmit2.types b/tests/baselines/reference/tsxReactEmit2.types index 9f8d6e494d0..e28910b62c7 100644 --- a/tests/baselines/reference/tsxReactEmit2.types +++ b/tests/baselines/reference/tsxReactEmit2.types @@ -12,6 +12,8 @@ declare module JSX { >s : string } } +declare var React: any; +>React : any var p1, p2, p3; >p1 : any diff --git a/tests/baselines/reference/tsxReactEmit3.js b/tests/baselines/reference/tsxReactEmit3.js index d31fec1c550..1a6ba037230 100644 --- a/tests/baselines/reference/tsxReactEmit3.js +++ b/tests/baselines/reference/tsxReactEmit3.js @@ -1,6 +1,7 @@ //// [tsxReactEmit3.tsx] declare module JSX { interface Element { } } +declare var React: any; declare var Foo, Bar, baz; diff --git a/tests/baselines/reference/tsxReactEmit3.symbols b/tests/baselines/reference/tsxReactEmit3.symbols index 8ef0ccab241..857647400a9 100644 --- a/tests/baselines/reference/tsxReactEmit3.symbols +++ b/tests/baselines/reference/tsxReactEmit3.symbols @@ -4,15 +4,18 @@ declare module JSX { interface Element { } } >JSX : Symbol(JSX, Decl(tsxReactEmit3.tsx, 0, 0)) >Element : Symbol(Element, Decl(tsxReactEmit3.tsx, 1, 20)) +declare var React: any; +>React : Symbol(React, Decl(tsxReactEmit3.tsx, 2, 11)) + declare var Foo, Bar, baz; ->Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 3, 11)) ->Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16)) ->baz : Symbol(baz, Decl(tsxReactEmit3.tsx, 3, 21)) +>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 4, 11)) +>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) +>baz : Symbol(baz, Decl(tsxReactEmit3.tsx, 4, 21)) q s ; ->Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 3, 11)) ->Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16)) ->Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16)) ->Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16)) ->Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 3, 16)) +>Foo : Symbol(Foo, Decl(tsxReactEmit3.tsx, 4, 11)) +>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) +>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) +>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) +>Bar : Symbol(Bar, Decl(tsxReactEmit3.tsx, 4, 16)) diff --git a/tests/baselines/reference/tsxReactEmit3.types b/tests/baselines/reference/tsxReactEmit3.types index 9e5d9fece56..8babe724fa1 100644 --- a/tests/baselines/reference/tsxReactEmit3.types +++ b/tests/baselines/reference/tsxReactEmit3.types @@ -4,6 +4,9 @@ declare module JSX { interface Element { } } >JSX : any >Element : Element +declare var React: any; +>React : any + declare var Foo, Bar, baz; >Foo : any >Bar : any diff --git a/tests/baselines/reference/tsxReactEmit4.errors.txt b/tests/baselines/reference/tsxReactEmit4.errors.txt index 00b7cb8d019..fca2b028237 100644 --- a/tests/baselines/reference/tsxReactEmit4.errors.txt +++ b/tests/baselines/reference/tsxReactEmit4.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/tsxReactEmit4.tsx(11,5): error TS2304: Cannot find name 'blah'. +tests/cases/conformance/jsx/tsxReactEmit4.tsx(12,5): error TS2304: Cannot find name 'blah'. ==== tests/cases/conformance/jsx/tsxReactEmit4.tsx (1 errors) ==== @@ -8,6 +8,7 @@ tests/cases/conformance/jsx/tsxReactEmit4.tsx(11,5): error TS2304: Cannot find n [s: string]: any; } } + declare var React: any; var p; var openClosed1 =
diff --git a/tests/baselines/reference/tsxReactEmit4.js b/tests/baselines/reference/tsxReactEmit4.js index 2254c4dd651..dcbfafcef2f 100644 --- a/tests/baselines/reference/tsxReactEmit4.js +++ b/tests/baselines/reference/tsxReactEmit4.js @@ -5,6 +5,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; var p; var openClosed1 =
diff --git a/tests/baselines/reference/tsxReactEmitWhitespace.js b/tests/baselines/reference/tsxReactEmitWhitespace.js index 2f32295c279..a124ce73312 100644 --- a/tests/baselines/reference/tsxReactEmitWhitespace.js +++ b/tests/baselines/reference/tsxReactEmitWhitespace.js @@ -5,6 +5,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; // THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING // WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT diff --git a/tests/baselines/reference/tsxReactEmitWhitespace.symbols b/tests/baselines/reference/tsxReactEmitWhitespace.symbols index afbb6944981..06c8258a2c2 100644 --- a/tests/baselines/reference/tsxReactEmitWhitespace.symbols +++ b/tests/baselines/reference/tsxReactEmitWhitespace.symbols @@ -12,12 +12,14 @@ declare module JSX { >s : Symbol(s, Decl(tsxReactEmitWhitespace.tsx, 3, 3)) } } +declare var React: any; +>React : Symbol(React, Decl(tsxReactEmitWhitespace.tsx, 6, 11)) // THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING // WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT var p = 0; ->p : Symbol(p, Decl(tsxReactEmitWhitespace.tsx, 10, 3)) +>p : Symbol(p, Decl(tsxReactEmitWhitespace.tsx, 11, 3)) // Emit " "
; diff --git a/tests/baselines/reference/tsxReactEmitWhitespace.types b/tests/baselines/reference/tsxReactEmitWhitespace.types index e0e3639fa9b..603dc4ca6c1 100644 --- a/tests/baselines/reference/tsxReactEmitWhitespace.types +++ b/tests/baselines/reference/tsxReactEmitWhitespace.types @@ -12,6 +12,8 @@ declare module JSX { >s : string } } +declare var React: any; +>React : any // THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING // WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT diff --git a/tests/cases/conformance/jsx/tsxReactEmit1.tsx b/tests/cases/conformance/jsx/tsxReactEmit1.tsx index b8f14b0ba22..15ece4153a8 100644 --- a/tests/cases/conformance/jsx/tsxReactEmit1.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmit1.tsx @@ -6,6 +6,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; var p; var selfClosed1 =
; diff --git a/tests/cases/conformance/jsx/tsxReactEmit2.tsx b/tests/cases/conformance/jsx/tsxReactEmit2.tsx index 39a78a7da87..96ab8c6046b 100644 --- a/tests/cases/conformance/jsx/tsxReactEmit2.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmit2.tsx @@ -6,6 +6,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; var p1, p2, p3; var spreads1 =
{p2}
; diff --git a/tests/cases/conformance/jsx/tsxReactEmit3.tsx b/tests/cases/conformance/jsx/tsxReactEmit3.tsx index eb63be44f3b..12adcd3c2b6 100644 --- a/tests/cases/conformance/jsx/tsxReactEmit3.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmit3.tsx @@ -2,6 +2,7 @@ //@filename: test.tsx declare module JSX { interface Element { } } +declare var React: any; declare var Foo, Bar, baz; diff --git a/tests/cases/conformance/jsx/tsxReactEmit4.tsx b/tests/cases/conformance/jsx/tsxReactEmit4.tsx index f007c35c24a..a032a5a3985 100644 --- a/tests/cases/conformance/jsx/tsxReactEmit4.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmit4.tsx @@ -6,6 +6,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; var p; var openClosed1 =
diff --git a/tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx b/tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx index 38c966fa700..34fd158eab1 100644 --- a/tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx +++ b/tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx @@ -6,6 +6,7 @@ declare module JSX { [s: string]: any; } } +declare var React: any; // THIS FILE HAS TEST-SIGNIFICANT LEADING/TRAILING // WHITESPACE, DO NOT RUN 'FORMAT DOCUMENT' ON IT From 311d20fa99a48eff5cff7f5d4ea311b95f7bd280 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 12:46:58 -0700 Subject: [PATCH 42/88] Fix bug #3737 (exported JSX classes props not validated) --- src/compiler/checker.ts | 18 +++---- .../tsxAttributeResolution9.errors.txt | 31 ++++++++++++ .../reference/tsxAttributeResolution9.js | 42 +++++++++++++++++ .../reference/tsxAttributeResolution9.symbols | 45 ++++++++++++++++++ .../reference/tsxAttributeResolution9.types | 47 +++++++++++++++++++ .../jsx/tsxAttributeResolution9.tsx | 27 +++++++++++ 6 files changed, 199 insertions(+), 11 deletions(-) create mode 100644 tests/baselines/reference/tsxAttributeResolution9.errors.txt create mode 100644 tests/baselines/reference/tsxAttributeResolution9.js create mode 100644 tests/baselines/reference/tsxAttributeResolution9.symbols create mode 100644 tests/baselines/reference/tsxAttributeResolution9.types create mode 100644 tests/cases/conformance/jsx/tsxAttributeResolution9.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ef2c6ada2a..b910dc3306b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7095,13 +7095,18 @@ namespace ts { // Look up the value in the current scope if (node.tagName.kind === SyntaxKind.Identifier) { - valueSymbol = getResolvedSymbol(node.tagName); + let tag = node.tagName; + valueSymbol = resolveName(tag, tag.text, SymbolFlags.Value, Diagnostics.Cannot_find_name_0, tag.text); } else { valueSymbol = checkQualifiedName(node.tagName).symbol; } - if (valueSymbol !== unknownSymbol) { + if (valueSymbol && valueSymbol !== unknownSymbol) { + let symbolLinks = getSymbolLinks(valueSymbol); + if (symbolLinks) { + symbolLinks.referenced = true; + } links.jsxFlags |= JsxFlags.ClassElement; } @@ -7301,15 +7306,6 @@ namespace ts { let targetAttributesType = getJsxElementAttributesType(node); - if (getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) { - if (node.tagName.kind === SyntaxKind.Identifier) { - checkIdentifier(node.tagName); - } - else { - checkQualifiedName(node.tagName); - } - } - let nameTable: Map = {}; // Process this array in right-to-left order so we know which // attributes (mostly from spreads) are being overwritten and diff --git a/tests/baselines/reference/tsxAttributeResolution9.errors.txt b/tests/baselines/reference/tsxAttributeResolution9.errors.txt new file mode 100644 index 00000000000..c25532eaa0a --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution9.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/jsx/file.tsx(9,14): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/jsx/react.d.ts (0 errors) ==== + + declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } + } + + interface Props { + foo: string; + } + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + export class MyComponent { + render() { + } + + props: { foo: string; } + } + + ; // ok + ; // should be an error + ~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/tsxAttributeResolution9.js b/tests/baselines/reference/tsxAttributeResolution9.js new file mode 100644 index 00000000000..bfc19a7ba4f --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution9.js @@ -0,0 +1,42 @@ +//// [tests/cases/conformance/jsx/tsxAttributeResolution9.tsx] //// + +//// [react.d.ts] + +declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } +} + +interface Props { + foo: string; +} + +//// [file.tsx] +export class MyComponent { + render() { + } + + props: { foo: string; } +} + +; // ok +; // should be an error + + +//// [file.jsx] +define(["require", "exports"], function (require, exports) { + var MyComponent = (function () { + function MyComponent() { + } + MyComponent.prototype.render = function () { + }; + return MyComponent; + })(); + exports.MyComponent = MyComponent; + ; // ok + ; // should be an error +}); diff --git a/tests/baselines/reference/tsxAttributeResolution9.symbols b/tests/baselines/reference/tsxAttributeResolution9.symbols new file mode 100644 index 00000000000..cbb30864c81 --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution9.symbols @@ -0,0 +1,45 @@ +=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx === +declare module JSX { +>JSX : Symbol(JSX, Decl(tsxAttributeResolution9.tsx, 0, 0)) + + interface Element { } +>Element : Symbol(Element, Decl(tsxAttributeResolution9.tsx, 0, 20)) + + interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxAttributeResolution9.tsx, 1, 22)) + } + interface ElementAttributesProperty { +>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(tsxAttributeResolution9.tsx, 3, 2)) + + props; +>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 4, 38)) + } +} + +interface Props { +>Props : Symbol(Props, Decl(tsxAttributeResolution9.tsx, 7, 1)) + + foo: string; +>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 9, 17)) +} + +export class MyComponent { +>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1)) + + render() { +>render : Symbol(render, Decl(tsxAttributeResolution9.tsx, 13, 26)) + } + + props: { foo: string; } +>props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 15, 3)) +>foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 17, 10)) +} + +; // ok +>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1)) +>foo : Symbol(unknown) + +; // should be an error +>MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1)) +>foo : Symbol(unknown) + diff --git a/tests/baselines/reference/tsxAttributeResolution9.types b/tests/baselines/reference/tsxAttributeResolution9.types new file mode 100644 index 00000000000..aab3806a5f0 --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution9.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx === +declare module JSX { +>JSX : any + + interface Element { } +>Element : Element + + interface IntrinsicElements { +>IntrinsicElements : IntrinsicElements + } + interface ElementAttributesProperty { +>ElementAttributesProperty : ElementAttributesProperty + + props; +>props : any + } +} + +interface Props { +>Props : Props + + foo: string; +>foo : string +} + +export class MyComponent { +>MyComponent : MyComponent + + render() { +>render : () => void + } + + props: { foo: string; } +>props : { foo: string; } +>foo : string +} + +; // ok +> : any +>MyComponent : typeof MyComponent +>foo : any + +; // should be an error +> : any +>MyComponent : typeof MyComponent +>foo : any + diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution9.tsx b/tests/cases/conformance/jsx/tsxAttributeResolution9.tsx new file mode 100644 index 00000000000..9768d65d000 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxAttributeResolution9.tsx @@ -0,0 +1,27 @@ +//@jsx: preserve +//@module: amd + +//@filename: react.d.ts +declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } +} + +interface Props { + foo: string; +} + +//@filename: file.tsx +export class MyComponent { + render() { + } + + props: { foo: string; } +} + +; // ok +; // should be an error From d353d624346d9372bf74792acacdf5d8cffb7f71 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 7 Jul 2015 12:48:17 -0700 Subject: [PATCH 43/88] Addressed CR feedback. --- src/services/services.ts | 15 +++++++++++++++ .../fourslash/completionListInImportClause01.ts | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 4149a7e786c..28c0b0ce239 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3204,6 +3204,12 @@ namespace ts { return false; } + /** + * Aggregates relevant symbols for completion in object literals and object binding patterns. + * Relevant symbols are stored in the captured 'symbols' variable. + * + * @returns true if 'symbols' was successfully populated; false otherwise. + */ function tryGetObjectLikeCompletionSymbols(objectLikeContainer: ObjectLiteralExpression | BindingPattern): boolean { // We're looking up possible property names from contextual/inferred/declared type. isMemberCompletion = true; @@ -3242,6 +3248,15 @@ namespace ts { return true; } + /** + * Aggregates relevant symbols for completion in import clauses; for instance, + * + * import { $ } from "moduleName"; + * + * Relevant symbols are stored in the captured 'symbols' variable. + * + * @returns true if 'symbols' was successfully populated; false otherwise. + */ function tryGetImportClauseCompletionSymbols(importClause: ImportClause): boolean { // cursor is in import clause // try to show exported member for imported module diff --git a/tests/cases/fourslash/completionListInImportClause01.ts b/tests/cases/fourslash/completionListInImportClause01.ts index cf053868dd6..1191216baf1 100644 --- a/tests/cases/fourslash/completionListInImportClause01.ts +++ b/tests/cases/fourslash/completionListInImportClause01.ts @@ -14,8 +14,8 @@ function verifyCompletionAtMarker(marker: string, showBuilder: boolean, ...completions: string[]) { goTo.marker(marker); if (completions.length) { - for (let i = 0; i < completions.length; ++i) { - verify.completionListContains(completions[i]); + for (let completion of completions) { + verify.completionListContains(completion); } } else { From 006356d2a3c010fa304be3e3d5b8c1c4c72ead3b Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 12:53:53 -0700 Subject: [PATCH 44/88] Whitespace --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7a85a2f08b2..6b59bd2df2b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7302,7 +7302,7 @@ namespace ts { // If we're compiling under --jsx react, the symbol 'React' should // be marked as 'used' so we don't incorrectly elide its import. And if there // is no 'React' symbol in scope, we should issue an error. - if(compilerOptions.jsx === JsxEmit.React) { + if (compilerOptions.jsx === JsxEmit.React) { let reactSym = resolveName(node.tagName, 'React', SymbolFlags.Value, Diagnostics.Cannot_find_name_0, 'React'); if (reactSym) { getSymbolLinks(reactSym).referenced = true; From 363dc03d8ee2ca670ca6047bafe9377726e34fb8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 12:54:20 -0700 Subject: [PATCH 45/88] Delete some files that shouldn't have existed --- .../jsx/tsxAttributeResolution1.jsx | 15 ------- .../jsx/tsxAttributeResolution2.jsx | 5 --- .../jsx/tsxAttributeResolution3.jsx | 21 ---------- .../jsx/tsxAttributeResolution4.jsx | 4 -- .../jsx/tsxAttributeResolution5.jsx | 11 ----- .../conformance/jsx/tsxElementResolution1.jsx | 4 -- .../jsx/tsxElementResolution11.jsx | 6 --- .../jsx/tsxElementResolution12.jsx | 9 ---- .../jsx/tsxElementResolution13.jsx | 2 - .../jsx/tsxElementResolution14.jsx | 2 - .../jsx/tsxElementResolution15.jsx | 2 - .../jsx/tsxElementResolution16.jsx | 2 - .../conformance/jsx/tsxElementResolution7.jsx | 14 ------- .../conformance/jsx/tsxElementResolution8.jsx | 15 ------- .../conformance/jsx/tsxElementResolution9.jsx | 6 --- tests/cases/conformance/jsx/tsxEmit1.jsx | 34 --------------- tests/cases/conformance/jsx/tsxEmit3.jsx | 41 ------------------- 17 files changed, 193 deletions(-) delete mode 100644 tests/cases/conformance/jsx/tsxAttributeResolution1.jsx delete mode 100644 tests/cases/conformance/jsx/tsxAttributeResolution2.jsx delete mode 100644 tests/cases/conformance/jsx/tsxAttributeResolution3.jsx delete mode 100644 tests/cases/conformance/jsx/tsxAttributeResolution4.jsx delete mode 100644 tests/cases/conformance/jsx/tsxAttributeResolution5.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution1.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution11.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution12.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution13.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution14.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution15.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution16.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution7.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution8.jsx delete mode 100644 tests/cases/conformance/jsx/tsxElementResolution9.jsx delete mode 100644 tests/cases/conformance/jsx/tsxEmit1.jsx delete mode 100644 tests/cases/conformance/jsx/tsxEmit3.jsx diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution1.jsx b/tests/cases/conformance/jsx/tsxAttributeResolution1.jsx deleted file mode 100644 index fb54f9d7c82..00000000000 --- a/tests/cases/conformance/jsx/tsxAttributeResolution1.jsx +++ /dev/null @@ -1,15 +0,0 @@ -// OK -; // OK -; // OK -; // OK -; // OK -; // OK -// Errors -; // Error, '0' is not number -; // Error, no property "y" -; // Error, no property "y" -; // Error, "32" is not number -// TODO attribute 'var' should be parseable -// ; // Error, no 'var' property -; // Error, missing reqd -; // Error, reqd is not string diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution2.jsx b/tests/cases/conformance/jsx/tsxAttributeResolution2.jsx deleted file mode 100644 index 7c47046dcde..00000000000 --- a/tests/cases/conformance/jsx/tsxAttributeResolution2.jsx +++ /dev/null @@ -1,5 +0,0 @@ -// OK -; // OK -; // OK -// Errors -; // Error, no leng on 'string' diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution3.jsx b/tests/cases/conformance/jsx/tsxAttributeResolution3.jsx deleted file mode 100644 index 46cb5d8ff69..00000000000 --- a/tests/cases/conformance/jsx/tsxAttributeResolution3.jsx +++ /dev/null @@ -1,21 +0,0 @@ -// OK -var obj1 = { x: 'foo' }; -; -// Error, x is not string -var obj2 = { x: 32 }; -; -// Error, x is missing -var obj3 = { y: 32 }; -; -// OK -var obj4 = { x: 32, y: 32 }; -; -// Error -var obj5 = { x: 32, y: 32 }; -; -// OK -var obj6 = { x: 'ok', y: 32, extra: 100 }; -; -// Error -var obj7 = { x: 'foo' }; -; diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution4.jsx b/tests/cases/conformance/jsx/tsxAttributeResolution4.jsx deleted file mode 100644 index da2e1d12038..00000000000 --- a/tests/cases/conformance/jsx/tsxAttributeResolution4.jsx +++ /dev/null @@ -1,4 +0,0 @@ -// OK -; -// Error, no member 'len' on 'string' -; diff --git a/tests/cases/conformance/jsx/tsxAttributeResolution5.jsx b/tests/cases/conformance/jsx/tsxAttributeResolution5.jsx deleted file mode 100644 index 3e4c89d06fb..00000000000 --- a/tests/cases/conformance/jsx/tsxAttributeResolution5.jsx +++ /dev/null @@ -1,11 +0,0 @@ -function make1(obj) { - return ; // OK -} -function make2(obj) { - return ; // Error (x is number, not string) -} -function make3(obj) { - return ; // Error, missing x -} -; // Error, missing x -; // OK diff --git a/tests/cases/conformance/jsx/tsxElementResolution1.jsx b/tests/cases/conformance/jsx/tsxElementResolution1.jsx deleted file mode 100644 index 97357dbba8e..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution1.jsx +++ /dev/null @@ -1,4 +0,0 @@ -// OK -
; -// Fail -; diff --git a/tests/cases/conformance/jsx/tsxElementResolution11.jsx b/tests/cases/conformance/jsx/tsxElementResolution11.jsx deleted file mode 100644 index 6349906508c..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution11.jsx +++ /dev/null @@ -1,6 +0,0 @@ -var Obj1; -; // OK -var Obj2; -; // Error -var Obj3; -; // OK diff --git a/tests/cases/conformance/jsx/tsxElementResolution12.jsx b/tests/cases/conformance/jsx/tsxElementResolution12.jsx deleted file mode 100644 index ef137fd0e29..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution12.jsx +++ /dev/null @@ -1,9 +0,0 @@ -var obj1; -; // OK -var obj2; -; // OK -var obj3; -; // Error -var obj4; -; // OK -; // Error diff --git a/tests/cases/conformance/jsx/tsxElementResolution13.jsx b/tests/cases/conformance/jsx/tsxElementResolution13.jsx deleted file mode 100644 index 6a55efa612d..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution13.jsx +++ /dev/null @@ -1,2 +0,0 @@ -var obj1; -; // Error diff --git a/tests/cases/conformance/jsx/tsxElementResolution14.jsx b/tests/cases/conformance/jsx/tsxElementResolution14.jsx deleted file mode 100644 index 29df7710af1..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution14.jsx +++ /dev/null @@ -1,2 +0,0 @@ -var obj1; -; // OK diff --git a/tests/cases/conformance/jsx/tsxElementResolution15.jsx b/tests/cases/conformance/jsx/tsxElementResolution15.jsx deleted file mode 100644 index 6a55efa612d..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution15.jsx +++ /dev/null @@ -1,2 +0,0 @@ -var obj1; -; // Error diff --git a/tests/cases/conformance/jsx/tsxElementResolution16.jsx b/tests/cases/conformance/jsx/tsxElementResolution16.jsx deleted file mode 100644 index e1987489bbb..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution16.jsx +++ /dev/null @@ -1,2 +0,0 @@ -var obj1; -; // Error (JSX.Element is missing) diff --git a/tests/cases/conformance/jsx/tsxElementResolution7.jsx b/tests/cases/conformance/jsx/tsxElementResolution7.jsx deleted file mode 100644 index e95505539ab..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution7.jsx +++ /dev/null @@ -1,14 +0,0 @@ -var my; -(function (my) { -})(my || (my = {})); -// OK -; -// Error -; -var q; -(function (q) { - // OK - ; - // Error - ; -})(q || (q = {})); diff --git a/tests/cases/conformance/jsx/tsxElementResolution8.jsx b/tests/cases/conformance/jsx/tsxElementResolution8.jsx deleted file mode 100644 index e0f95dc6d22..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution8.jsx +++ /dev/null @@ -1,15 +0,0 @@ -// Error -var div = 3; -
; -// OK -function fact() { return null; } -; -// Error -function fnum() { return 42; } -; -var obj1; -; // OK, prefer construct signatures -var obj2; -; // Error -var obj3; -; // Error diff --git a/tests/cases/conformance/jsx/tsxElementResolution9.jsx b/tests/cases/conformance/jsx/tsxElementResolution9.jsx deleted file mode 100644 index 2b62d86eac5..00000000000 --- a/tests/cases/conformance/jsx/tsxElementResolution9.jsx +++ /dev/null @@ -1,6 +0,0 @@ -var obj1; -; // Error, return type is not an object type -var obj2; -; // Error, return type is not an object type -var obj3; -; // OK diff --git a/tests/cases/conformance/jsx/tsxEmit1.jsx b/tests/cases/conformance/jsx/tsxEmit1.jsx deleted file mode 100644 index 45ca6e2469f..00000000000 --- a/tests/cases/conformance/jsx/tsxEmit1.jsx +++ /dev/null @@ -1,34 +0,0 @@ -var p; -/* -var selfClosed1 =
; -var selfClosed2 =
; -var selfClosed3 =
; -var selfClosed4 =
; -var selfClosed5 =
; -var selfClosed6 =
; -var selfClosed7 =
; - -var openClosed1 =
; -var openClosed2 =
foo
; -var openClosed3 =
{p}
; -var openClosed4 =
{p < p}
; -var openClosed5 =
{p > p}
; -*/ -var SomeClass = (function () { - function SomeClass() { - } - SomeClass.prototype.f = function () { - var _this = this; - var rewrites1 =
{function () { return _this; }}
; - var rewrites4 =
; - }; - return SomeClass; -})(); -/* -var q = () => this; -var rewrites2 =
{[p, ...p, p]}
; -var rewrites3 =
{{p}}
; - -var rewrites5 =
; -var rewrites6 =
; -*/ diff --git a/tests/cases/conformance/jsx/tsxEmit3.jsx b/tests/cases/conformance/jsx/tsxEmit3.jsx deleted file mode 100644 index 7c979051d00..00000000000 --- a/tests/cases/conformance/jsx/tsxEmit3.jsx +++ /dev/null @@ -1,41 +0,0 @@ -var M; -(function (M) { - var Foo = (function () { - function Foo() { - } - return Foo; - })(); - M.Foo = Foo; - var S; - (function (S) { - var Bar = (function () { - function Bar() { - } - return Bar; - })(); - S.Bar = Bar; - })(S = M.S || (M.S = {})); -})(M || (M = {})); -var M; -(function (M) { - // Emit M.Foo - M.Foo, ; - var S; - (function (S) { - // Emit M.Foo - M.Foo, ; - // Emit S.Bar - S.Bar, ; - })(S = M.S || (M.S = {})); -})(M || (M = {})); -var M; -(function (M) { - // Emit M.S.Bar - M.S.Bar, ; -})(M || (M = {})); -var M; -(function (M_1) { - var M = 100; - // Emit M_1.Foo - M_1.Foo, ; -})(M || (M = {})); From 48ae5ea6f87a0e22a57bea61db8f9d84669ba017 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 13:25:39 -0700 Subject: [PATCH 46/88] Remove check if node is a block --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ef2c6ada2a..7083feabb2c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11446,7 +11446,7 @@ namespace ts { function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node: Node) { if (node.modifiers) { - if (inBlockOrObjectLiteralExpression(node)) { + if (inObjectLiteralExpression(node)) { if (isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); @@ -11459,9 +11459,9 @@ namespace ts { } } - function inBlockOrObjectLiteralExpression(node: Node) { + function inObjectLiteralExpression(node: Node) { while (node) { - if (node.kind === SyntaxKind.Block || node.kind === SyntaxKind.ObjectLiteralExpression) { + if (node.kind === SyntaxKind.ObjectLiteralExpression) { return true; } From 9344bd0a397e74246e657ec466548067de7fe59d Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 13:25:53 -0700 Subject: [PATCH 47/88] Add tests --- ...ifierOnClassDeclarationMemberInFunction.js | 25 +++++++++++++++++++ ...OnClassDeclarationMemberInFunction.symbols | 18 +++++++++++++ ...erOnClassDeclarationMemberInFunction.types | 19 ++++++++++++++ ...difierOnClassExpressionMemberInFunction.js | 25 +++++++++++++++++++ ...rOnClassExpressionMemberInFunction.symbols | 19 ++++++++++++++ ...ierOnClassExpressionMemberInFunction.types | 22 ++++++++++++++++ ...ifierOnClassDeclarationMemberInFunction.ts | 9 +++++++ ...difierOnClassExpressionMemberInFunction.ts | 10 ++++++++ 8 files changed, 147 insertions(+) create mode 100644 tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.js create mode 100644 tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.symbols create mode 100644 tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.types create mode 100644 tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js create mode 100644 tests/baselines/reference/modifierOnClassExpressionMemberInFunction.symbols create mode 100644 tests/baselines/reference/modifierOnClassExpressionMemberInFunction.types create mode 100644 tests/cases/conformance/classes/classDeclarations/modifierOnClassDeclarationMemberInFunction.ts create mode 100644 tests/cases/conformance/classes/classExpressions/modifierOnClassExpressionMemberInFunction.ts diff --git a/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.js b/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.js new file mode 100644 index 00000000000..d571a4143ee --- /dev/null +++ b/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.js @@ -0,0 +1,25 @@ +//// [modifierOnClassDeclarationMemberInFunction.ts] + +function f() { + class C { + public baz = 1; + static foo() { } + public bar() { } + } +} + +//// [modifierOnClassDeclarationMemberInFunction.js] +function f() { + var C = (function () { + function C() { + this.baz = 1; + } + C.foo = function () { }; + C.prototype.bar = function () { }; + return C; + })(); +} + + +//// [modifierOnClassDeclarationMemberInFunction.d.ts] +declare function f(): void; diff --git a/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.symbols b/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.symbols new file mode 100644 index 00000000000..a411bee09cb --- /dev/null +++ b/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/classes/classDeclarations/modifierOnClassDeclarationMemberInFunction.ts === + +function f() { +>f : Symbol(f, Decl(modifierOnClassDeclarationMemberInFunction.ts, 0, 0)) + + class C { +>C : Symbol(C, Decl(modifierOnClassDeclarationMemberInFunction.ts, 1, 14)) + + public baz = 1; +>baz : Symbol(baz, Decl(modifierOnClassDeclarationMemberInFunction.ts, 2, 13)) + + static foo() { } +>foo : Symbol(C.foo, Decl(modifierOnClassDeclarationMemberInFunction.ts, 3, 23)) + + public bar() { } +>bar : Symbol(bar, Decl(modifierOnClassDeclarationMemberInFunction.ts, 4, 24)) + } +} diff --git a/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.types b/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.types new file mode 100644 index 00000000000..dfd482a6bc8 --- /dev/null +++ b/tests/baselines/reference/modifierOnClassDeclarationMemberInFunction.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/classDeclarations/modifierOnClassDeclarationMemberInFunction.ts === + +function f() { +>f : () => void + + class C { +>C : C + + public baz = 1; +>baz : number +>1 : number + + static foo() { } +>foo : () => void + + public bar() { } +>bar : () => void + } +} diff --git a/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js new file mode 100644 index 00000000000..e43e8dd8203 --- /dev/null +++ b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.js @@ -0,0 +1,25 @@ +//// [modifierOnClassExpressionMemberInFunction.ts] + +function g() { + var x = class C { + public prop1 = 1; + private foo() { } + static prop2 = 43; + } +} + +//// [modifierOnClassExpressionMemberInFunction.js] +function g() { + var x = (function () { + function C() { + this.prop1 = 1; + } + C.prototype.foo = function () { }; + C.prop2 = 43; + return C; + })(); +} + + +//// [modifierOnClassExpressionMemberInFunction.d.ts] +declare function g(): void; diff --git a/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.symbols b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.symbols new file mode 100644 index 00000000000..d603d96dcda --- /dev/null +++ b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/classes/classExpressions/modifierOnClassExpressionMemberInFunction.ts === + +function g() { +>g : Symbol(g, Decl(modifierOnClassExpressionMemberInFunction.ts, 0, 0)) + + var x = class C { +>x : Symbol(x, Decl(modifierOnClassExpressionMemberInFunction.ts, 2, 7)) +>C : Symbol(C, Decl(modifierOnClassExpressionMemberInFunction.ts, 2, 11)) + + public prop1 = 1; +>prop1 : Symbol(C.prop1, Decl(modifierOnClassExpressionMemberInFunction.ts, 2, 21)) + + private foo() { } +>foo : Symbol(C.foo, Decl(modifierOnClassExpressionMemberInFunction.ts, 3, 25)) + + static prop2 = 43; +>prop2 : Symbol(C.prop2, Decl(modifierOnClassExpressionMemberInFunction.ts, 4, 25)) + } +} diff --git a/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.types b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.types new file mode 100644 index 00000000000..87a200ee56e --- /dev/null +++ b/tests/baselines/reference/modifierOnClassExpressionMemberInFunction.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/classes/classExpressions/modifierOnClassExpressionMemberInFunction.ts === + +function g() { +>g : () => void + + var x = class C { +>x : typeof C +>class C { public prop1 = 1; private foo() { } static prop2 = 43; } : typeof C +>C : typeof C + + public prop1 = 1; +>prop1 : number +>1 : number + + private foo() { } +>foo : () => void + + static prop2 = 43; +>prop2 : number +>43 : number + } +} diff --git a/tests/cases/conformance/classes/classDeclarations/modifierOnClassDeclarationMemberInFunction.ts b/tests/cases/conformance/classes/classDeclarations/modifierOnClassDeclarationMemberInFunction.ts new file mode 100644 index 00000000000..f0d7c355e3b --- /dev/null +++ b/tests/cases/conformance/classes/classDeclarations/modifierOnClassDeclarationMemberInFunction.ts @@ -0,0 +1,9 @@ +// @declaration: true + +function f() { + class C { + public baz = 1; + static foo() { } + public bar() { } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/classes/classExpressions/modifierOnClassExpressionMemberInFunction.ts b/tests/cases/conformance/classes/classExpressions/modifierOnClassExpressionMemberInFunction.ts new file mode 100644 index 00000000000..100c04a1d31 --- /dev/null +++ b/tests/cases/conformance/classes/classExpressions/modifierOnClassExpressionMemberInFunction.ts @@ -0,0 +1,10 @@ +// @declaration: true +// @declaration: true + +function g() { + var x = class C { + public prop1 = 1; + private foo() { } + static prop2 = 43; + } +} \ No newline at end of file From d6dc67d38fbdf8a3184b3422b9ccf0c0cbd9967e Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 7 Jul 2015 14:11:18 -0700 Subject: [PATCH 48/88] Add window.URL --- src/lib/dom.generated.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 84e959caef8..f6a8471b925 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -11984,6 +11984,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window toolbar: BarProp; top: Window; window: Window; + URL: URL; alert(message?: any): void; blur(): void; cancelAnimationFrame(handle: number): void; @@ -12798,6 +12799,7 @@ declare var styleMedia: StyleMedia; declare var toolbar: BarProp; declare var top: Window; declare var window: Window; +declare var URL: URL; declare function alert(message?: any): void; declare function blur(): void; declare function cancelAnimationFrame(handle: number): void; From 99fc99f3bcbc123b7c37be05a4be7ac25e929fd7 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 14:27:57 -0700 Subject: [PATCH 49/88] Improved fix from @JsonFreeman --- src/compiler/checker.ts | 10 +++---- .../reference/tsxAttributeResolution9.symbols | 30 ++++++++++--------- .../reference/tsxAttributeResolution9.types | 8 +++-- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b910dc3306b..842b6dcd550 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7096,18 +7096,18 @@ namespace ts { // Look up the value in the current scope if (node.tagName.kind === SyntaxKind.Identifier) { let tag = node.tagName; - valueSymbol = resolveName(tag, tag.text, SymbolFlags.Value, Diagnostics.Cannot_find_name_0, tag.text); + let maybeExportSymbol = getResolvedSymbol(node.tagName); + let valueDecl = maybeExportSymbol.valueDeclaration; + + valueSymbol = (valueDecl && valueDecl.localSymbol) || maybeExportSymbol; } else { valueSymbol = checkQualifiedName(node.tagName).symbol; } if (valueSymbol && valueSymbol !== unknownSymbol) { - let symbolLinks = getSymbolLinks(valueSymbol); - if (symbolLinks) { - symbolLinks.referenced = true; - } links.jsxFlags |= JsxFlags.ClassElement; + getSymbolLinks(valueSymbol).referenced = true; } return valueSymbol || unknownSymbol; diff --git a/tests/baselines/reference/tsxAttributeResolution9.symbols b/tests/baselines/reference/tsxAttributeResolution9.symbols index cbb30864c81..081482d5d47 100644 --- a/tests/baselines/reference/tsxAttributeResolution9.symbols +++ b/tests/baselines/reference/tsxAttributeResolution9.symbols @@ -1,45 +1,47 @@ -=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx === +=== tests/cases/conformance/jsx/react.d.ts === + declare module JSX { ->JSX : Symbol(JSX, Decl(tsxAttributeResolution9.tsx, 0, 0)) +>JSX : Symbol(JSX, Decl(react.d.ts, 0, 0)) interface Element { } ->Element : Symbol(Element, Decl(tsxAttributeResolution9.tsx, 0, 20)) +>Element : Symbol(Element, Decl(react.d.ts, 1, 20)) interface IntrinsicElements { ->IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxAttributeResolution9.tsx, 1, 22)) +>IntrinsicElements : Symbol(IntrinsicElements, Decl(react.d.ts, 2, 22)) } interface ElementAttributesProperty { ->ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(tsxAttributeResolution9.tsx, 3, 2)) +>ElementAttributesProperty : Symbol(ElementAttributesProperty, Decl(react.d.ts, 4, 2)) props; ->props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 4, 38)) +>props : Symbol(props, Decl(react.d.ts, 5, 38)) } } interface Props { ->Props : Symbol(Props, Decl(tsxAttributeResolution9.tsx, 7, 1)) +>Props : Symbol(Props, Decl(react.d.ts, 8, 1)) foo: string; ->foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 9, 17)) +>foo : Symbol(foo, Decl(react.d.ts, 10, 17)) } +=== tests/cases/conformance/jsx/file.tsx === export class MyComponent { ->MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1)) +>MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) render() { ->render : Symbol(render, Decl(tsxAttributeResolution9.tsx, 13, 26)) +>render : Symbol(render, Decl(file.tsx, 0, 26)) } props: { foo: string; } ->props : Symbol(props, Decl(tsxAttributeResolution9.tsx, 15, 3)) ->foo : Symbol(foo, Decl(tsxAttributeResolution9.tsx, 17, 10)) +>props : Symbol(props, Decl(file.tsx, 2, 3)) +>foo : Symbol(foo, Decl(file.tsx, 4, 10)) } ; // ok ->MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1)) +>MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) >foo : Symbol(unknown) ; // should be an error ->MyComponent : Symbol(MyComponent, Decl(tsxAttributeResolution9.tsx, 11, 1)) +>MyComponent : Symbol(MyComponent, Decl(file.tsx, 0, 0)) >foo : Symbol(unknown) diff --git a/tests/baselines/reference/tsxAttributeResolution9.types b/tests/baselines/reference/tsxAttributeResolution9.types index aab3806a5f0..1b2c6d42389 100644 --- a/tests/baselines/reference/tsxAttributeResolution9.types +++ b/tests/baselines/reference/tsxAttributeResolution9.types @@ -1,4 +1,5 @@ -=== tests/cases/conformance/jsx/tsxAttributeResolution9.tsx === +=== tests/cases/conformance/jsx/react.d.ts === + declare module JSX { >JSX : any @@ -23,6 +24,7 @@ interface Props { >foo : string } +=== tests/cases/conformance/jsx/file.tsx === export class MyComponent { >MyComponent : MyComponent @@ -36,12 +38,12 @@ export class MyComponent { } ; // ok -> : any +> : JSX.Element >MyComponent : typeof MyComponent >foo : any ; // should be an error -> : any +> : JSX.Element >MyComponent : typeof MyComponent >foo : any From 70c4f08b10c93049d7ca131f2a24eccd9601c8ab Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 7 Jul 2015 14:30:38 -0700 Subject: [PATCH 50/88] Changed the return type of several well-known functions to NodeList --- src/lib/dom.generated.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 84e959caef8..36d1588636d 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -2254,12 +2254,12 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * @param elementId String that specifies the ID value. Case-insensitive. */ getElementById(elementId: string): HTMLElement; - getElementsByClassName(classNames: string): NodeList; + getElementsByClassName(classNames: string): NodeList; /** * Gets a collection of objects based on the value of the NAME or ID attribute. * @param elementName Gets a collection of objects based on the value of the NAME or ID attribute. */ - getElementsByName(elementName: string): NodeList; + getElementsByName(elementName: string): NodeList; /** * Retrieves a collection of objects based on the specified element name. * @param name Specifies the name of an element. @@ -2437,8 +2437,8 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven getElementsByTagName(tagname: "wbr"): NodeListOf; getElementsByTagName(tagname: "x-ms-webview"): NodeListOf; getElementsByTagName(tagname: "xmp"): NodeListOf; - getElementsByTagName(tagname: string): NodeList; - getElementsByTagNameNS(namespaceURI: string, localName: string): NodeList; + getElementsByTagName(tagname: string): NodeList; + getElementsByTagNameNS(namespaceURI: string, localName: string): NodeList; /** * Returns an object representing the current selection of the document that is loaded into the object displaying a webpage. */ @@ -2890,8 +2890,8 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec getElementsByTagName(name: "wbr"): NodeListOf; getElementsByTagName(name: "x-ms-webview"): NodeListOf; getElementsByTagName(name: "xmp"): NodeListOf; - getElementsByTagName(name: string): NodeList; - getElementsByTagNameNS(namespaceURI: string, localName: string): NodeList; + getElementsByTagName(name: string): NodeList; + getElementsByTagNameNS(namespaceURI: string, localName: string): NodeList; hasAttribute(name: string): boolean; hasAttributeNS(namespaceURI: string, localName: string): boolean; msGetRegionContent(): MSRangeCollection; @@ -3903,7 +3903,7 @@ interface HTMLElement extends Element { contains(child: HTMLElement): boolean; dragDrop(): boolean; focus(): void; - getElementsByClassName(classNames: string): NodeList; + getElementsByClassName(classNames: string): NodeList; insertAdjacentElement(position: string, insertedElement: Element): Element; insertAdjacentHTML(where: string, html: string): void; insertAdjacentText(where: string, text: string): void; @@ -12487,7 +12487,7 @@ interface NavigatorStorageUtils { interface NodeSelector { querySelector(selectors: string): Element; - querySelectorAll(selectors: string): NodeList; + querySelectorAll(selectors: string): NodeList; } interface RandomSource { From 3ccaa0ee261c70cd32e31af3e458c44a23fe6b10 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 14:33:59 -0700 Subject: [PATCH 51/88] Cleanup --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 842b6dcd550..da7ac5844b8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7096,9 +7096,8 @@ namespace ts { // Look up the value in the current scope if (node.tagName.kind === SyntaxKind.Identifier) { let tag = node.tagName; - let maybeExportSymbol = getResolvedSymbol(node.tagName); + let maybeExportSymbol = getResolvedSymbol(tag); let valueDecl = maybeExportSymbol.valueDeclaration; - valueSymbol = (valueDecl && valueDecl.localSymbol) || maybeExportSymbol; } else { From 33df79d11ec2d9ca5e8e0bb13ff29cf96c96888e Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 7 Jul 2015 14:40:08 -0700 Subject: [PATCH 52/88] Correct "NodeList" to "NodeListOf" --- src/lib/dom.generated.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 36d1588636d..8d5f8ac9254 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -2254,12 +2254,12 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven * @param elementId String that specifies the ID value. Case-insensitive. */ getElementById(elementId: string): HTMLElement; - getElementsByClassName(classNames: string): NodeList; + getElementsByClassName(classNames: string): NodeListOf; /** * Gets a collection of objects based on the value of the NAME or ID attribute. * @param elementName Gets a collection of objects based on the value of the NAME or ID attribute. */ - getElementsByName(elementName: string): NodeList; + getElementsByName(elementName: string): NodeListOf; /** * Retrieves a collection of objects based on the specified element name. * @param name Specifies the name of an element. @@ -2437,8 +2437,8 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven getElementsByTagName(tagname: "wbr"): NodeListOf; getElementsByTagName(tagname: "x-ms-webview"): NodeListOf; getElementsByTagName(tagname: "xmp"): NodeListOf; - getElementsByTagName(tagname: string): NodeList; - getElementsByTagNameNS(namespaceURI: string, localName: string): NodeList; + getElementsByTagName(tagname: string): NodeListOf; + getElementsByTagNameNS(namespaceURI: string, localName: string): NodeListOf; /** * Returns an object representing the current selection of the document that is loaded into the object displaying a webpage. */ @@ -2890,8 +2890,8 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec getElementsByTagName(name: "wbr"): NodeListOf; getElementsByTagName(name: "x-ms-webview"): NodeListOf; getElementsByTagName(name: "xmp"): NodeListOf; - getElementsByTagName(name: string): NodeList; - getElementsByTagNameNS(namespaceURI: string, localName: string): NodeList; + getElementsByTagName(name: string): NodeListOf; + getElementsByTagNameNS(namespaceURI: string, localName: string): NodeListOf; hasAttribute(name: string): boolean; hasAttributeNS(namespaceURI: string, localName: string): boolean; msGetRegionContent(): MSRangeCollection; @@ -3903,7 +3903,7 @@ interface HTMLElement extends Element { contains(child: HTMLElement): boolean; dragDrop(): boolean; focus(): void; - getElementsByClassName(classNames: string): NodeList; + getElementsByClassName(classNames: string): NodeListOf; insertAdjacentElement(position: string, insertedElement: Element): Element; insertAdjacentHTML(where: string, html: string): void; insertAdjacentText(where: string, text: string): void; @@ -12487,7 +12487,7 @@ interface NavigatorStorageUtils { interface NodeSelector { querySelector(selectors: string): Element; - querySelectorAll(selectors: string): NodeList; + querySelectorAll(selectors: string): NodeListOf; } interface RandomSource { From b5b1b7b5bb7155fe49e1de7f838258be52425fe0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 15:26:01 -0700 Subject: [PATCH 53/88] Use symbol.getName for classExpression and functionExpression since it now correctly represent declared-name. --- src/compiler/checker.ts | 13 ++++++++----- src/services/services.ts | 39 ++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 773f1e3f7d0..d18d0faba9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13414,7 +13414,7 @@ namespace ts { case SyntaxKind.ClassExpression: let className = (location).name; if (className) { - copySymbol(className.text, location.symbol, meaning); + copySymbol(location.symbol, meaning); } // fall through; this fall-through is necessary because we would like to handle // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration @@ -13432,7 +13432,7 @@ namespace ts { case SyntaxKind.ClassExpression: let funcName = (location).name; if (funcName) { - copySymbol(funcName.text, location.symbol, meaning); + copySymbol(location.symbol, meaning); } break; } @@ -13451,9 +13451,12 @@ namespace ts { * @param symbol the symbol to be added into symbol table * @param meaning meaning of symbol to filter by before adding to symbol table */ - function copySymbol(key: string, symbol: Symbol, meaning: SymbolFlags): void { + function copySymbol(symbol: Symbol, meaning: SymbolFlags): void { if (symbol.flags & meaning) { - let id = key || symbol.name; + let id = symbol.name; + // We will copy all symbol regardless of its reserved name because + // symbolsToArray will check whether the key is a reserved name and + // it will not copy symbol with reserved name to the array if (!hasProperty(symbols, id)) { symbols[id] = symbol; } @@ -13464,7 +13467,7 @@ namespace ts { if (meaning) { for (let id in source) { let symbol = source[id]; - copySymbol(symbol.name, symbol, meaning); + copySymbol(symbol, meaning); } } } diff --git a/src/services/services.ts b/src/services/services.ts index 8260d41c837..756bb200687 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2808,30 +2808,23 @@ namespace ts { * @return undefined if the name is of external module otherwise a name with striped of any quote */ function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, location: Node): string { - let displayName: string; + let displayName: string = symbol.getName(); - // In the case of default export, function expression and class expression, - // the binder bind them with "default", "__function", "__class" respectively. - // However, for completion entry, we want to display its declared name rather than binder name. - if (getLocalSymbolForExportDefault(symbol) || - getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression) || - getDeclarationOfKind(symbol, SyntaxKind.ClassExpression)) { - let typeChecker = program.getTypeChecker(); - displayName = getDeclaredName(typeChecker, symbol, location); - - // At this point, we expect that all completion list entries have declared name including function expression and class expression - // because when we gather all relevant symbols, we check that the function expression and class expression must have declared name - // before adding the symbol into our symbols table. (see: getSymbolsInScope) - Debug.assert(displayName !== undefined, "Expected displayed name from declaration to existed in this symbol: " + symbol.getName()); - } - else { - displayName = symbol.getName(); - let firstCharCode = displayName.charCodeAt(0); - // First check of the displayName is not external module; if it is an external module, it is not valid entry - if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { - // If the symbol is external module, don't show it in the completion list - // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) - return undefined; + if (displayName) { + if (displayName === "default") { + // In the case of default export, the binder bind them with "default". + // However, for completion entry, we want to display its declared name rather than binder name. + let typeChecker = program.getTypeChecker(); + displayName = getDeclaredName(typeChecker, symbol, location); + } + else { + let firstCharCode = displayName.charCodeAt(0); + // First check of the displayName is not external module; if it is an external module, it is not valid entry + if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { + // If the symbol is external module, don't show it in the completion list + // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) + return undefined; + } } } From 6e332cf26697f4dbb557ce2199ab88ac4b612b78 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 15:45:35 -0700 Subject: [PATCH 54/88] Remove file that shouldn't have been in this branch --- .../tsxAttributeResolution9.errors.txt | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 tests/baselines/reference/tsxAttributeResolution9.errors.txt diff --git a/tests/baselines/reference/tsxAttributeResolution9.errors.txt b/tests/baselines/reference/tsxAttributeResolution9.errors.txt deleted file mode 100644 index c25532eaa0a..00000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/jsx/file.tsx(9,14): error TS2322: Type 'number' is not assignable to type 'string'. - - -==== tests/cases/conformance/jsx/react.d.ts (0 errors) ==== - - declare module JSX { - interface Element { } - interface IntrinsicElements { - } - interface ElementAttributesProperty { - props; - } - } - - interface Props { - foo: string; - } - -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== - export class MyComponent { - render() { - } - - props: { foo: string; } - } - - ; // ok - ; // should be an error - ~~~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'string'. - \ No newline at end of file From 8f3bce121d6f429ea90b121346fe2dc39542a5d3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 16:22:04 -0700 Subject: [PATCH 55/88] Actually fix the bug this time. --- src/compiler/checker.ts | 5 ++- .../tsxAttributeResolution9.errors.txt | 31 ------------------- 2 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 tests/baselines/reference/tsxAttributeResolution9.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e631ff5bce..1edd2a7a920 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7096,9 +7096,8 @@ namespace ts { // Look up the value in the current scope if (node.tagName.kind === SyntaxKind.Identifier) { let tag = node.tagName; - let maybeExportSymbol = getResolvedSymbol(tag); - let valueDecl = maybeExportSymbol.valueDeclaration; - valueSymbol = (valueDecl && valueDecl.localSymbol) || maybeExportSymbol; + let sym = getResolvedSymbol(tag); + valueSymbol = sym.exportSymbol || sym; } else { valueSymbol = checkQualifiedName(node.tagName).symbol; diff --git a/tests/baselines/reference/tsxAttributeResolution9.errors.txt b/tests/baselines/reference/tsxAttributeResolution9.errors.txt deleted file mode 100644 index c25532eaa0a..00000000000 --- a/tests/baselines/reference/tsxAttributeResolution9.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/jsx/file.tsx(9,14): error TS2322: Type 'number' is not assignable to type 'string'. - - -==== tests/cases/conformance/jsx/react.d.ts (0 errors) ==== - - declare module JSX { - interface Element { } - interface IntrinsicElements { - } - interface ElementAttributesProperty { - props; - } - } - - interface Props { - foo: string; - } - -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== - export class MyComponent { - render() { - } - - props: { foo: string; } - } - - ; // ok - ; // should be an error - ~~~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'string'. - \ No newline at end of file From cdc999a6c51e819e7962f5acfd0c2bbf73f2814e Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 16:26:48 -0700 Subject: [PATCH 56/88] Only check if method declaration has modifier when method is declared in object literal expression --- src/compiler/checker.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7083feabb2c..f4bbc71793e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11444,9 +11444,10 @@ namespace ts { forEach(node.declarationList.declarations, checkSourceElement); } - function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node: Node) { + function checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node: Node) { if (node.modifiers) { - if (inObjectLiteralExpression(node)) { + if (node.parent.kind === SyntaxKind.ObjectLiteralExpression){ + // If this method declaration is a property of object-literal-expression if (isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); @@ -11459,18 +11460,6 @@ namespace ts { } } - function inObjectLiteralExpression(node: Node) { - while (node) { - if (node.kind === SyntaxKind.ObjectLiteralExpression) { - return true; - } - - node = node.parent; - } - - return false; - } - function checkExpressionStatement(node: ExpressionStatement) { // Grammar checking checkGrammarStatementInAmbientContext(node); @@ -15026,7 +15015,7 @@ namespace ts { } function checkGrammarMethod(node: MethodDeclaration) { - if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || + if (checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; From 91a138e395d547323dda6849634f800f3b4e129b Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 7 Jul 2015 16:49:00 -0700 Subject: [PATCH 57/88] Move className and id from HTMLElement to Element --- src/lib/dom.generated.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 84e959caef8..804568666af 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -2711,6 +2711,8 @@ interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelec scrollTop: number; scrollWidth: number; tagName: string; + id: string; + className: string; getAttribute(name?: string): string; getAttributeNS(namespaceURI: string, localName: string): string; getAttributeNode(name: string): Attr; @@ -3809,14 +3811,12 @@ declare var HTMLDocument: { interface HTMLElement extends Element { accessKey: string; children: HTMLCollection; - className: string; contentEditable: string; dataset: DOMStringMap; dir: string; draggable: boolean; hidden: boolean; hideFocus: boolean; - id: string; innerHTML: string; innerText: string; isContentEditable: boolean; @@ -12535,7 +12535,6 @@ interface SVGLocatable { } interface SVGStylable { - className: SVGAnimatedString; style: CSSStyleDeclaration; } From 3e57af13b93e082b05b3c1cbf21ef2e7516e5591 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 7 Jul 2015 17:04:03 -0700 Subject: [PATCH 58/88] Add missed file --- .../tsxAttributeResolution9.errors.txt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/baselines/reference/tsxAttributeResolution9.errors.txt diff --git a/tests/baselines/reference/tsxAttributeResolution9.errors.txt b/tests/baselines/reference/tsxAttributeResolution9.errors.txt new file mode 100644 index 00000000000..c25532eaa0a --- /dev/null +++ b/tests/baselines/reference/tsxAttributeResolution9.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/jsx/file.tsx(9,14): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/jsx/react.d.ts (0 errors) ==== + + declare module JSX { + interface Element { } + interface IntrinsicElements { + } + interface ElementAttributesProperty { + props; + } + } + + interface Props { + foo: string; + } + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + export class MyComponent { + render() { + } + + props: { foo: string; } + } + + ; // ok + ; // should be an error + ~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + \ No newline at end of file From 90779a9d87bd3f94a0c2c13dcc83487b28993f83 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 7 Jul 2015 17:13:52 -0700 Subject: [PATCH 59/88] Fix the definition of interface ErrorEventHandler --- src/lib/dom.generated.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 84e959caef8..e4e250a52ef 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -12622,7 +12622,7 @@ interface EventListenerObject { declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject; interface ErrorEventHandler { - (event: Event | string, source?: string, fileno?: number, columnNumber?: number): void; + (message: string, filename?: string, lineno?: number, colno?: number, error?:Error): void; } interface PositionCallback { (position: Position): void; From 869de7391ea1c5ed152aeb44314444cf19c8d254 Mon Sep 17 00:00:00 2001 From: Zhengbo Li Date: Tue, 7 Jul 2015 17:19:34 -0700 Subject: [PATCH 60/88] Fix FormData constructor --- src/lib/dom.generated.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 84e959caef8..4cff6e7f7b3 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -3072,7 +3072,7 @@ interface FormData { declare var FormData: { prototype: FormData; - new(): FormData; + new (form?: HTMLFormElement): FormData; } interface GainNode extends AudioNode { From e0e9bcff466b3cbb2cec920702e29f028b4a2cb7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 7 Jul 2015 17:44:22 -0700 Subject: [PATCH 61/88] Don't call push.apply, it can stack overflow with large arrays. --- src/compiler/checker.ts | 2 +- src/services/navigationBar.ts | 4 ++-- src/services/services.ts | 22 +++++++++++----------- src/services/signatureHelp.ts | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3ef2c6ada2a..e8ac59449d9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3305,7 +3305,7 @@ namespace ts { let declarations: Declaration[] = []; for (let prop of props) { if (prop.declarations) { - declarations.push.apply(declarations, prop.declarations); + addRange(declarations, prop.declarations); } propTypes.push(getTypeOfSymbol(prop)); } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index ead9bc519ce..e822052a5b2 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -228,7 +228,7 @@ namespace ts.NavigationBar { function merge(target: ts.NavigationBarItem, source: ts.NavigationBarItem) { // First, add any spans in the source to the target. - target.spans.push.apply(target.spans, source.spans); + addRange(target.spans, source.spans); if (source.childItems) { if (!target.childItems) { @@ -465,7 +465,7 @@ namespace ts.NavigationBar { // are not properties will be filtered out later by createChildItem. let nodes: Node[] = removeDynamicallyNamedProperties(node); if (constructor) { - nodes.push.apply(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name))); + addRange(nodes, filter(constructor.parameters, p => !isBindingPattern(p.name))); } childItems = getItemsWorker(sortNodes(nodes), createChildItem); diff --git a/src/services/services.ts b/src/services/services.ts index 9996a2ac5fa..fe4f376cbdf 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -345,7 +345,7 @@ namespace ts { ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => { let cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedParamJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment); + addRange(jsDocCommentParts, cleanedParamJsDocComment); } }); } @@ -365,7 +365,7 @@ namespace ts { declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => { let cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration); if (cleanedJsDocComment) { - jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment); + addRange(jsDocCommentParts, cleanedJsDocComment); } }); } @@ -3812,7 +3812,7 @@ namespace ts { displayParts.push(spacePart()); } if (!(type.flags & TypeFlags.Anonymous)) { - displayParts.push.apply(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); + addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments)); } addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature); break; @@ -3873,7 +3873,7 @@ namespace ts { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); - displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); } if (symbolFlags & SymbolFlags.Enum) { addNewLineIfDisplayPartsExist(); @@ -3919,7 +3919,7 @@ namespace ts { else if (signatureDeclaration.kind !== SyntaxKind.CallSignature && signatureDeclaration.name) { addFullSymbolName(signatureDeclaration.symbol); } - displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); + addRange(displayParts, signatureToDisplayParts(typeChecker, signature, sourceFile, TypeFormatFlags.WriteTypeArgumentsOfSignature)); } } if (symbolFlags & SymbolFlags.EnumMember) { @@ -3980,10 +3980,10 @@ namespace ts { let typeParameterParts = mapToDisplayParts(writer => { typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplay(type, writer, enclosingDeclaration); }); - displayParts.push.apply(displayParts, typeParameterParts); + addRange(displayParts, typeParameterParts); } else { - displayParts.push.apply(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration)); + addRange(displayParts, typeToDisplayParts(typeChecker, type, enclosingDeclaration)); } } else if (symbolFlags & SymbolFlags.Function || @@ -4017,7 +4017,7 @@ namespace ts { function addFullSymbolName(symbol: Symbol, enclosingDeclaration?: Node) { let fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbol, enclosingDeclaration || sourceFile, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing); - displayParts.push.apply(displayParts, fullSymbolDisplayParts); + addRange(displayParts, fullSymbolDisplayParts); } function addPrefixForAnyFunctionOrVar(symbol: Symbol, symbolKind: string) { @@ -4047,7 +4047,7 @@ namespace ts { } function addSignatureDisplayParts(signature: Signature, allSignatures: Signature[], flags?: TypeFormatFlags) { - displayParts.push.apply(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature)); + addRange(displayParts, signatureToDisplayParts(typeChecker, signature, enclosingDeclaration, flags | TypeFormatFlags.WriteTypeArgumentsOfSignature)); if (allSignatures.length > 1) { displayParts.push(spacePart()); displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); @@ -4064,7 +4064,7 @@ namespace ts { let typeParameterParts = mapToDisplayParts(writer => { typeChecker.getSymbolDisplayBuilder().buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaration); }); - displayParts.push.apply(displayParts, typeParameterParts); + addRange(displayParts, typeParameterParts); } } @@ -5578,7 +5578,7 @@ namespace ts { // type to the search set if (isNameOfPropertyAssignment(location)) { forEach(getPropertySymbolsFromContextualType(location), contextualSymbol => { - result.push.apply(result, typeChecker.getRootSymbols(contextualSymbol)); + addRange(result, typeChecker.getRootSymbols(contextualSymbol)); }); /* Because in short-hand property assignment, location has two meaning : property name and as value of the property diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 44b022a7b12..f44ebade2a7 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -550,7 +550,7 @@ namespace ts.SignatureHelp { let suffixDisplayParts: SymbolDisplayPart[] = []; if (callTargetDisplayParts) { - prefixDisplayParts.push.apply(prefixDisplayParts, callTargetDisplayParts); + addRange(prefixDisplayParts, callTargetDisplayParts); } if (isTypeParameterList) { @@ -560,12 +560,12 @@ namespace ts.SignatureHelp { suffixDisplayParts.push(punctuationPart(SyntaxKind.GreaterThanToken)); let parameterParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation)); - suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts); + addRange(suffixDisplayParts, parameterParts); } else { let typeParameterParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation)); - prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts); + addRange(prefixDisplayParts, typeParameterParts); prefixDisplayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); let parameters = candidateSignature.parameters; @@ -575,7 +575,7 @@ namespace ts.SignatureHelp { let returnTypeParts = mapToDisplayParts(writer => typeChecker.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation)); - suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts); + addRange(suffixDisplayParts, returnTypeParts); return { isVariadic: candidateSignature.hasRestParameter, From 8e15a42632aa68153b85632cff6678216eaab94d Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 8 Jul 2015 13:56:27 -0700 Subject: [PATCH 62/88] Address code review --- src/compiler/checker.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f4bbc71793e..0b577cc12fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11444,19 +11444,17 @@ namespace ts { forEach(node.declarationList.declarations, checkSourceElement); } - function checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node: Node) { - if (node.modifiers) { - if (node.parent.kind === SyntaxKind.ObjectLiteralExpression){ - // If this method declaration is a property of object-literal-expression - if (isAsyncFunctionLike(node)) { - if (node.modifiers.length > 1) { - return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); - } - } - else { + function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node: Node) { + // We only disallow modifier on a method declaration if it is a property of object-literal-expression + if (node.modifiers && node.parent.kind === SyntaxKind.ObjectLiteralExpression){ + if (isAsyncFunctionLike(node)) { + if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); } } + else { + return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); + } } } @@ -15015,7 +15013,7 @@ namespace ts { } function checkGrammarMethod(node: MethodDeclaration) { - if (checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node) || + if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true; From 5dfa6104f9256738218c01195a0923c69bf346ac Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Wed, 8 Jul 2015 17:42:26 -0700 Subject: [PATCH 63/88] Turn off a few rules and more cleanup post merge --- scripts/errorCheck.ts | 3 +- src/compiler/binder.ts | 54 ++++++------ src/compiler/checker.ts | 17 ++-- src/compiler/commandLineParser.ts | 2 +- src/compiler/core.ts | 12 +-- src/compiler/declarationEmitter.ts | 12 +-- src/compiler/parser.ts | 128 ++++++++++++++--------------- src/compiler/program.ts | 2 +- src/compiler/sys.ts | 44 +++++----- src/compiler/tsc.ts | 105 +++++++++++------------ src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 100 +++++++++++----------- tslint.json | 6 +- 13 files changed, 241 insertions(+), 246 deletions(-) diff --git a/scripts/errorCheck.ts b/scripts/errorCheck.ts index 36489c5f312..a5cb27417f1 100644 --- a/scripts/errorCheck.ts +++ b/scripts/errorCheck.ts @@ -74,7 +74,7 @@ fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, console.log('Consumed ' + allSrc.length + ' characters of source'); let count = 0; - console.log('== List of errors not used in source ==') + console.log('== List of errors not used in source =='); for (let errName of errorNames) { if (allSrc.indexOf(errName) < 0) { console.log(errName); @@ -84,4 +84,3 @@ fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, console.log(count + ' of ' + errorNames.length + ' errors are not used in source'); }); }); - diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d3333435d14..802bf6df358 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -11,7 +11,7 @@ namespace ts { } export function getModuleInstanceState(node: Node): ModuleInstanceState { - // A module is uninstantiated if it contains only + // A module is uninstantiated if it contains only // 1. interface declarations, type alias declarations if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) { return ModuleInstanceState.NonInstantiated; @@ -53,7 +53,7 @@ namespace ts { } const enum ContainerFlags { - // The current node is not a container, and no container manipulation should happen before + // The current node is not a container, and no container manipulation should happen before // recursing into it. None = 0, @@ -90,7 +90,7 @@ namespace ts { let lastContainer: Node; // If this file is an external module, then it is automatically in strict-mode according to - // ES6. If it is not an external module, then we'll determine if it is in strict mode or + // ES6. If it is not an external module, then we'll determine if it is in strict mode or // not depending on if we see "use strict" in certain places (or if we hit a class/namespace). let inStrictMode = !!file.externalModuleIndicator; @@ -179,7 +179,7 @@ namespace ts { * @param parent - node's parent declaration. * @param node - The declaration to be added to the symbol table * @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.) - * @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations. + * @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations. */ function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol { Debug.assert(!hasDynamicName(node)); @@ -192,13 +192,13 @@ namespace ts { // Check and see if the symbol table already has a symbol with this name. If not, // create a new symbol with this name and add it to the table. Note that we don't - // give the new symbol any flags *yet*. This ensures that it will not conflict + // give the new symbol any flags *yet*. This ensures that it will not conflict // with the 'excludes' flags we pass in. // // If we do get an existing symbol, see if it conflicts with the new symbol we're // creating. For example, a 'var' symbol and a 'class' symbol will conflict within - // the same symbol table. If we have a conflict, report the issue on each - // declaration we have for this symbol, and then create a new symbol for this + // the same symbol table. If we have a conflict, report the issue on each + // declaration we have for this symbol, and then create a new symbol for this // declaration. // // If we created a new symbol, either because we didn't have a symbol with this name @@ -259,7 +259,7 @@ namespace ts { // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set // on it. There are 2 main reasons: // - // 1. We treat locals and exports of the same name as mutually exclusive within a container. + // 1. We treat locals and exports of the same name as mutually exclusive within a container. // That means the binder will issue a Duplicate Identifier error if you mix locals and exports // with the same name in the same container. // TODO: Make this a more specific error and decouple it from the exclusion logic. @@ -282,11 +282,11 @@ namespace ts { } } - // All container nodes are kept on a linked list in declaration order. This list is used by - // the getLocalNameOfContainer function in the type checker to validate that the local name + // All container nodes are kept on a linked list in declaration order. This list is used by + // the getLocalNameOfContainer function in the type checker to validate that the local name // used for a container is unique. function bindChildren(node: Node) { - // Before we recurse into a node's chilren, we first save the existing parent, container + // Before we recurse into a node's chilren, we first save the existing parent, container // and block-container. Then after we pop out of processing the children, we restore // these saved values. let saveParent = parent; @@ -302,9 +302,9 @@ namespace ts { // may contain locals, we proactively initialize the .locals field. We do this because // it's highly likely that the .locals will be needed to place some child in (for example, // a parameter, or variable declaration). - // + // // However, we do not proactively create the .locals for block-containers because it's - // totally normal and common for block-containers to never actually have a block-scoped + // totally normal and common for block-containers to never actually have a block-scoped // variable in them. We don't want to end up allocating an object for every 'block' we // run into when most of them won't be necessary. // @@ -373,7 +373,7 @@ namespace ts { case SyntaxKind.Block: // do not treat blocks directly inside a function as a block-scoped-container. - // Locals that reside in this block should go to the function locals. Othewise 'x' + // Locals that reside in this block should go to the function locals. Othewise 'x' // would not appear to be a redeclaration of a block scoped local in the following // example: // @@ -386,7 +386,7 @@ namespace ts { // the block, then there would be no collision. // // By not creating a new block-scoped-container here, we ensure that both 'var x' - // and 'let x' go into the Function-container's locals, and we do get a collision + // and 'let x' go into the Function-container's locals, and we do get a collision // conflict. return isFunctionLike(node.parent) ? ContainerFlags.None : ContainerFlags.IsBlockScopedContainer; } @@ -490,7 +490,7 @@ namespace ts { if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { return true; } - } + }; } return false; } @@ -536,8 +536,8 @@ namespace ts { // For a given function symbol "<...>(...) => T" we want to generate a symbol identical // to the one we would get for: { <...>(...): T } // - // We do that by making an anonymous type literal symbol, and then setting the function - // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable + // We do that by making an anonymous type literal symbol, and then setting the function + // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable // from an actual type literal symbol you would have gotten had you used the long form. let symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, SymbolFlags.Signature); @@ -638,7 +638,7 @@ namespace ts { } function getStrictModeIdentifierMessage(node: Node) { - // Provide specialized messages to help the user understand why we think they're in + // Provide specialized messages to help the user understand why we think they're in // strict mode. if (getContainingClass(node)) { return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; @@ -696,7 +696,7 @@ namespace ts { } function getStrictModeEvalOrArgumentsMessage(node: Node) { - // Provide specialized messages to help the user understand why we think they're in + // Provide specialized messages to help the user understand why we think they're in // strict mode. if (getContainingClass(node)) { return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; @@ -766,18 +766,18 @@ namespace ts { } // First we bind declaration nodes to a symbol if possible. We'll both create a symbol - // and then potentially add the symbol to an appropriate symbol table. Possible + // and then potentially add the symbol to an appropriate symbol table. Possible // destination symbol tables are: - // + // // 1) The 'exports' table of the current container's symbol. // 2) The 'members' table of the current container's symbol. // 3) The 'locals' table of the current container. // - // However, not all symbols will end up in any of these tables. 'Anonymous' symbols + // However, not all symbols will end up in any of these tables. 'Anonymous' symbols // (like TypeLiterals for example) will not be put in any table. bindWorker(node); - // Then we recurse into the children of the node to bind them as well. For certain + // Then we recurse into the children of the node to bind them as well. For certain // symbols we do specialized work when we recurse. For example, we'll keep track of // the current 'container' node when it changes. This helps us know which symbol table // a local should go into for example. @@ -972,9 +972,9 @@ namespace ts { let symbol = node.symbol; // TypeScript 1.0 spec (April 2014): 8.4 - // Every class automatically contains a static property member named 'prototype', the + // Every class automatically contains a static property member named 'prototype', the // type of which is an instantiation of the class type with type Any supplied as a type - // argument for each type parameter. It is an error to explicitly declare a static + // argument for each type parameter. It is an error to explicitly declare a static // property member with the name 'prototype'. // // Note: we check for this here because this class may be merging into a module. The @@ -1039,7 +1039,7 @@ namespace ts { declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes); } - // If this is a property-parameter, then also declare the property symbol into the + // If this is a property-parameter, then also declare the property symbol into the // containing class. if (node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a380c6c9b84..1eccfd32af7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3874,8 +3874,8 @@ namespace ts { * getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type */ function getExportedTypeFromNamespace(namespace: string, name: string): Type { - var namespaceSymbol = getGlobalSymbol(namespace, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined); - var typeSymbol = namespaceSymbol && getSymbol(namespaceSymbol.exports, name, SymbolFlags.Type); + let namespaceSymbol = getGlobalSymbol(namespace, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined); + let typeSymbol = namespaceSymbol && getSymbol(namespaceSymbol.exports, name, SymbolFlags.Type); return typeSymbol && getDeclaredTypeOfSymbol(typeSymbol); } @@ -4697,7 +4697,6 @@ namespace ts { } let id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; let related = relation[id]; - //let related: RelationComparisonResult = undefined; // relation[id]; if (related !== undefined) { // If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate // errors, we can use the cached value. Otherwise, recompute the relation @@ -7214,7 +7213,7 @@ namespace ts { return links.resolvedJsxType = anyType; } - var propsName = getJsxElementPropertiesName(); + let propsName = getJsxElementPropertiesName(); if (propsName === undefined) { // There is no type ElementAttributesProperty, return 'any' return links.resolvedJsxType = anyType; @@ -7224,7 +7223,7 @@ namespace ts { return links.resolvedJsxType = elemInstanceType; } else { - var attributesType = getTypeOfPropertyOfType(elemInstanceType, propsName); + let attributesType = getTypeOfPropertyOfType(elemInstanceType, propsName); if (!attributesType) { // There is no property named 'props' on this instance type @@ -7381,7 +7380,7 @@ namespace ts { */ function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol): boolean { let flags = getDeclarationFlagsFromSymbol(prop); - let declaringClass = getDeclaredTypeOfSymbol(prop.parent);; + let declaringClass = getDeclaredTypeOfSymbol(prop.parent); if (left.kind === SyntaxKind.SuperKeyword) { let errorNode = node.kind === SyntaxKind.PropertyAccessExpression ? @@ -10121,7 +10120,7 @@ namespace ts { // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. - if(node.flags & NodeFlags.Abstract && node.body) { + if (node.flags & NodeFlags.Abstract && node.body) { error(node, Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, declarationNameToString(node.name)); } } @@ -10895,7 +10894,7 @@ namespace ts { let promiseConstructor = getMergedSymbol(promiseType.symbol); if (!promiseConstructor || !symbolIsValue(promiseConstructor)) { error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType)); - return unknownType + return unknownType; } // Validate the promise constructor type. @@ -12177,7 +12176,7 @@ namespace ts { // Interfaces cannot be merged with non-ambient classes. if (getSymbolOfNode(node).flags & SymbolFlags.Interface && !isInAmbientContext(node)) { - error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface) + error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface); } forEach(node.members, checkSourceElement); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d2eefc4ec9b..ba7d8ca9ce3 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -436,7 +436,7 @@ namespace ts { } else if (fileExtensionIs(name, ".ts")) { if (!contains(sysFiles, name + "x")) { - fileNames.push(name) + fileNames.push(name); } } else { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 322c5193936..ec171d4aee2 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -600,20 +600,20 @@ namespace ts { function getNormalizedPathComponentsOfUrl(url: string) { // Get root length of http://www.website.com/folder1/foler2/ - // In this example the root is: http://www.website.com/ + // In this example the root is: http://www.website.com/ // normalized path components should be ["http://www.website.com/", "folder1", "folder2"] let urlLength = url.length; // Initial root length is http:// part let rootLength = url.indexOf("://") + "://".length; while (rootLength < urlLength) { - // Consume all immediate slashes in the protocol + // Consume all immediate slashes in the protocol // eg.initial rootlength is just file:// but it needs to consume another "/" in file:/// if (url.charCodeAt(rootLength) === CharacterCodes.slash) { rootLength++; } else { - // non slash character means we continue proceeding to next component of root search + // non slash character means we continue proceeding to next component of root search break; } } @@ -626,15 +626,15 @@ namespace ts { // Find the index of "/" after website.com so the root can be http://www.website.com/ (from existing http://) let indexOfNextSlash = url.indexOf(directorySeparator, rootLength); if (indexOfNextSlash !== -1) { - // Found the "/" after the website.com so the root is length of http://www.website.com/ + // Found the "/" after the website.com so the root is length of http://www.website.com/ // and get components afetr the root normally like any other folder components rootLength = indexOfNextSlash + 1; return normalizedPathComponents(url, rootLength); } else { - // Can't find the host assume the rest of the string as component + // Can't find the host assume the rest of the string as component // but make sure we append "/" to it as root is not joined using "/" - // eg. if url passed in was http://website.com we want to use root as [http://website.com/] + // eg. if url passed in was http://website.com we want to use root as [http://website.com/] // so that other path manipulations will be correct and it can be merged with relative paths correctly return [url + directorySeparator]; } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 7eaf5cef2cd..36feaa515ff 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -130,7 +130,7 @@ namespace ts { moduleElementDeclarationEmitInfo, synchronousDeclarationOutput: writer.getText(), referencePathsOutput, - } + }; function hasInternalAnnotation(range: CommentRange) { let text = currentSourceFile.text; @@ -198,7 +198,7 @@ namespace ts { // we would write alias foo declaration when we visit it since it would now be marked as visible if (moduleElementEmitInfo) { if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) { - // we have to create asynchronous output only after we have collected complete information + // we have to create asynchronous output only after we have collected complete information // because it is possible to enable multiple bindings as asynchronously visible moduleElementEmitInfo.isVisible = true; } @@ -600,7 +600,7 @@ namespace ts { } function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // note usage of writer. methods instead of aliases created, just to make sure we are using + // note usage of writer. methods instead of aliases created, just to make sure we are using // correct writer especially to handle asynchronous alias writing emitJsDocComments(node); if (node.flags & NodeFlags.Export) { @@ -642,7 +642,7 @@ namespace ts { function writeImportDeclaration(node: ImportDeclaration) { if (!node.importClause && !(node.flags & NodeFlags.Export)) { - // do not write non-exported import declarations that don't have import clauses + // do not write non-exported import declarations that don't have import clauses return; } emitJsDocComments(node); @@ -1565,7 +1565,7 @@ namespace ts { ? referencedFile.fileName // Declaration file, use declaration file name : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file - : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file + : removeFileExtension(compilerOptions.out) + ".d.ts"; // Global out file declFileName = getRelativePathToDirectoryOrUrl( getDirectoryPath(normalizeSlashes(jsFilePath)), @@ -1604,4 +1604,4 @@ namespace ts { return declarationOutput; } } -} \ No newline at end of file +} diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 72c211cc3b5..fecff11b1b4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -585,7 +585,7 @@ namespace ts { fixupParentReferences(sourceFile); } - // If this is a javascript file, proactively see if we can get JSDoc comments for + // If this is a javascript file, proactively see if we can get JSDoc comments for // relevant nodes in the file. We'll use these to provide typing informaion if they're // available. if (isJavaScript(fileName)) { @@ -685,17 +685,17 @@ namespace ts { function setDecoratorContext(val: boolean) { setContextFlag(val, ParserContextFlags.Decorator); } - + function setAwaitContext(val: boolean) { setContextFlag(val, ParserContextFlags.Await); } - + function doOutsideOfContext(context: ParserContextFlags, func: () => T): T { - // contextFlagsToClear will contain only the context flags that are + // contextFlagsToClear will contain only the context flags that are // currently set that we need to temporarily clear // We don't just blindly reset to the previous flags to ensure // that we do not mutate cached flags for the incremental - // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and + // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and // HasAggregatedChildData). let contextFlagsToClear = context & contextFlags; if (contextFlagsToClear) { @@ -710,13 +710,13 @@ namespace ts { // no need to do anything special as we are not in any of the requested contexts return func(); } - + function doInsideOfContext(context: ParserContextFlags, func: () => T): T { // contextFlagsToSet will contain only the context flags that // are not currently set that we need to temporarily enable. // We don't just blindly reset to the previous flags to ensure // that we do not mutate cached flags for the incremental - // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and + // parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and // HasAggregatedChildData). let contextFlagsToSet = context & ~contextFlags; if (contextFlagsToSet) { @@ -727,11 +727,11 @@ namespace ts { setContextFlag(false, contextFlagsToSet); return result; } - + // no need to do anything special as we are already in all of the requested contexts return func(); } - + function allowInAnd(func: () => T): T { return doOutsideOfContext(ParserContextFlags.DisallowIn, func); } @@ -739,7 +739,7 @@ namespace ts { function disallowInAnd(func: () => T): T { return doInsideOfContext(ParserContextFlags.DisallowIn, func); } - + function doInYieldContext(func: () => T): T { return doInsideOfContext(ParserContextFlags.Yield, func); } @@ -751,23 +751,23 @@ namespace ts { function doInDecoratorContext(func: () => T): T { return doInsideOfContext(ParserContextFlags.Decorator, func); } - + function doInAwaitContext(func: () => T): T { return doInsideOfContext(ParserContextFlags.Await, func); } - + function doOutsideOfAwaitContext(func: () => T): T { return doOutsideOfContext(ParserContextFlags.Await, func); } - + function doInYieldAndAwaitContext(func: () => T): T { return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); } - + function doOutsideOfYieldAndAwaitContext(func: () => T): T { return doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func); } - + function inContext(flags: ParserContextFlags) { return (contextFlags & flags) !== 0; } @@ -787,7 +787,7 @@ namespace ts { function inAwaitContext() { return inContext(ParserContextFlags.Await); } - + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { let start = scanner.getTokenPos(); let length = scanner.getTextPos() - start; @@ -843,7 +843,7 @@ namespace ts { function scanJsxIdentifier(): SyntaxKind { return token = scanner.scanJsxIdentifier(); } - + function speculationHelper(callback: () => T, isLookAhead: boolean): T { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). @@ -903,7 +903,7 @@ namespace ts { if (token === SyntaxKind.YieldKeyword && inYieldContext()) { return false; } - + // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is // considered a keyword and is not an identifier. if (token === SyntaxKind.AwaitKeyword && inAwaitContext()) { @@ -1102,7 +1102,7 @@ namespace ts { function parseContextualModifier(t: SyntaxKind): boolean { return token === t && tryParse(nextTokenCanFollowModifier); } - + function nextTokenCanFollowModifier() { if (token === SyntaxKind.ConstKeyword) { // 'const' is only a modifier if followed by 'enum'. @@ -1121,7 +1121,7 @@ namespace ts { nextToken(); return canFollowModifier(); } - + function parseAnyContextualModifier(): boolean { return isModifier(token) && tryParse(nextTokenCanFollowModifier); } @@ -1229,7 +1229,7 @@ namespace ts { // if we see "extends {}" then only treat the {} as what we're extending (and not // the class body) if we have: // - // extends {} { + // extends {} { // extends {}, // extends {} extends // extends {} implements @@ -2019,7 +2019,7 @@ namespace ts { // ambient contexts. return finishNode(node); } - + function parseBindingElementInitializer(inParameter: boolean) { return inParameter ? parseParameterInitializer() : parseNonParameterInitializer(); } @@ -2027,7 +2027,7 @@ namespace ts { function parseParameterInitializer() { return parseInitializer(/*inParameter*/ true); } - + function fillSignature( returnToken: SyntaxKind, yieldContext: boolean, @@ -2065,15 +2065,15 @@ namespace ts { if (parseExpected(SyntaxKind.OpenParenToken)) { let savedYieldContext = inYieldContext(); let savedAwaitContext = inAwaitContext(); - + setYieldContext(yieldContext); setAwaitContext(awaitContext); - + let result = parseDelimitedList(ParsingContext.Parameters, parseParameter); - + setYieldContext(savedYieldContext); setAwaitContext(savedAwaitContext); - + if (!parseExpected(SyntaxKind.CloseParenToken) && requireCompleteParameterList) { // Caller insisted that we had to end with a ) We didn't. So just return // undefined here. @@ -2088,7 +2088,7 @@ namespace ts { // then just return an empty set of parameters. return requireCompleteParameterList ? undefined : createMissingList(); } - + function parseTypeMemberSemicolon() { // We allow type members to be separated by commas or (possibly ASI) semicolons. // First check if it was a comma. If so, we're done with the member. @@ -2471,7 +2471,7 @@ namespace ts { function parseType(): TypeNode { // The rules about 'yield' only apply to actual code/expression contexts. They don't - // apply to 'type' contexts. So we disable these parameters here before moving on. + // apply to 'type' contexts. So we disable these parameters here before moving on. return doOutsideOfContext(ParserContextFlags.TypeExcludesFlags, parseTypeWorker); } @@ -2559,7 +2559,7 @@ namespace ts { token !== SyntaxKind.AtToken && isStartOfExpression(); } - + function allowInAndParseExpression(): Expression { return allowInAnd(parseExpression); } @@ -2748,7 +2748,7 @@ namespace ts { // It's definitely not a parenthesized arrow function expression. return undefined; } - + // If we definitely have an arrow function, then we can just parse one, not requiring a // following => or { token. Otherwise, we *might* have an arrow function. Try to parse // it out, but don't allow any ambiguity, and return 'undefined' if this could be an @@ -2761,7 +2761,7 @@ namespace ts { // Didn't appear to actually be a parenthesized arrow function. Just bail out. return undefined; } - + let isAsync = !!(arrowFunction.flags & NodeFlags.Async); // If we have an arrow, then try to parse the body. Even if not, try to parse if we @@ -2804,7 +2804,7 @@ namespace ts { return Tristate.False; } } - + let first = token; let second = nextToken(); @@ -2892,7 +2892,7 @@ namespace ts { if (isArrowFunctionInJsx) { return Tristate.True; } - + return Tristate.False; } @@ -2909,7 +2909,7 @@ namespace ts { let node = createNode(SyntaxKind.ArrowFunction); setModifiers(node, parseModifiersForArrowFunction()); let isAsync = !!(node.flags & NodeFlags.Async); - + // Arrow functions are never generators. // // If we're speculatively parsing a signature for a parenthesized arrow function, then @@ -2966,7 +2966,7 @@ namespace ts { // Note: even when 'ignoreMissingOpenBrace' is passed as true, parseBody will still error. return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ true); } - + return isAsync ? doInAwaitContext(parseAssignmentExpressionOrHigher) : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher); @@ -3133,7 +3133,7 @@ namespace ts { node.expression = parseUnaryExpressionOrHigher(); return finishNode(node); } - + function isAwaitExpression(): boolean { if (token === SyntaxKind.AwaitKeyword) { if (inAwaitContext()) { @@ -3158,7 +3158,7 @@ namespace ts { if (isAwaitExpression()) { return parseAwaitExpression(); } - + switch (token) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: @@ -3177,7 +3177,7 @@ namespace ts { if (sourceFile.languageVariant !== LanguageVariant.JSX) { return parseTypeAssertion(); } - if(lookAhead(nextTokenIsIdentifierOrKeyword)) { + if (lookAhead(nextTokenIsIdentifierOrKeyword)) { return parseJsxElementOrSelfClosingElement(); } // Fall through @@ -3307,7 +3307,7 @@ namespace ts { node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); return finishNode(node); } - + function parseJsxElementOrSelfClosingElement(): JsxElement|JsxSelfClosingElement { let opening = parseJsxOpeningOrSelfClosingElement(); if (opening.kind === SyntaxKind.JsxOpeningElement) { @@ -3349,7 +3349,7 @@ namespace ts { let saveParsingContext = parsingContext; parsingContext |= 1 << ParsingContext.JsxChildren; - while(true) { + while (true) { token = scanner.reScanJsxToken(); if (token === SyntaxKind.LessThanSlashToken) { break; @@ -3367,7 +3367,7 @@ namespace ts { return result; } - + function parseJsxOpeningOrSelfClosingElement(): JsxOpeningElement|JsxSelfClosingElement { let fullStart = scanner.getStartPos(); @@ -3392,7 +3392,7 @@ namespace ts { return finishNode(node); } - + function parseJsxElementName(): EntityName { scanJsxIdentifier(); let elementName: EntityName = parseIdentifierName(); @@ -3477,7 +3477,7 @@ namespace ts { continue; } - // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName + // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName if (!inDecoratorContext() && parseOptional(SyntaxKind.OpenBracketToken)) { let indexedAccess = createNode(SyntaxKind.ElementAccessExpression, expression.pos); indexedAccess.expression = expression; @@ -3599,7 +3599,7 @@ namespace ts { case SyntaxKind.CommaToken: // foo, case SyntaxKind.OpenBraceToken: // foo { // We don't want to treat these as type arguments. Otherwise we'll parse this - // as an invocation expression. Instead, we want to parse out the expression + // as an invocation expression. Instead, we want to parse out the expression // in isolation from the type arguments. default: @@ -3627,7 +3627,7 @@ namespace ts { case SyntaxKind.OpenBraceToken: return parseObjectLiteralExpression(); case SyntaxKind.AsyncKeyword: - // Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher. + // Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher. // If we encounter `async [no LineTerminator here] function` then this is an async // function; otherwise, its an identifier. if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) { @@ -3759,12 +3759,12 @@ namespace ts { if (saveDecoratorContext) { setDecoratorContext(false); } - + let node = createNode(SyntaxKind.FunctionExpression); setModifiers(node, parseModifiers()); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); - + let isGenerator = !!node.asteriskToken; let isAsync = !!(node.flags & NodeFlags.Async); node.name = @@ -3772,14 +3772,14 @@ namespace ts { isGenerator ? doInYieldContext(parseOptionalIdentifier) : isAsync ? doInAwaitContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - + fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); - + if (saveDecoratorContext) { setDecoratorContext(true); } - + return finishNode(node); } @@ -3815,11 +3815,11 @@ namespace ts { function parseFunctionBlock(allowYield: boolean, allowAwait: boolean, ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block { let savedYieldContext = inYieldContext(); setYieldContext(allowYield); - + let savedAwaitContext = inAwaitContext(); setAwaitContext(allowAwait); - // We may be in a [Decorator] context when parsing a function expression or + // We may be in a [Decorator] context when parsing a function expression or // arrow function. The body of the function is not in [Decorator] context. let saveDecoratorContext = inDecoratorContext(); if (saveDecoratorContext) { @@ -4081,7 +4081,7 @@ namespace ts { nextToken(); return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); } - + function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); return token === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak(); @@ -4150,7 +4150,7 @@ namespace ts { return true; } continue; - + case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: @@ -4229,7 +4229,7 @@ namespace ts { } function isLetDeclaration() { - // In ES6 'let' always starts a lexical declaration if followed by an identifier or { + // In ES6 'let' always starts a lexical declaration if followed by an identifier or { // or [. return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring); } @@ -4335,7 +4335,7 @@ namespace ts { default: if (decorators || modifiers) { // We reached this point because we encountered decorators and/or modifiers and assumed a declaration - // would follow. For recovery and error reporting purposes, return an incomplete declaration. + // would follow. For recovery and error reporting purposes, return an incomplete declaration. let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; @@ -4694,7 +4694,7 @@ namespace ts { modifiers = []; modifiers.pos = modifierStart; } - + flags |= modifierToFlag(modifierKind); modifiers.push(finishNode(createNode(modifierKind, modifierStart))); } @@ -4719,7 +4719,7 @@ namespace ts { modifiers.flags = flags; modifiers.end = scanner.getStartPos(); } - + return modifiers; } @@ -4779,7 +4779,7 @@ namespace ts { function parseClassDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassDeclaration { return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, SyntaxKind.ClassDeclaration); } - + function parseClassDeclarationOrExpression(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, kind: SyntaxKind): ClassLikeDeclaration { let node = createNode(kind, fullStart); node.decorators = decorators; @@ -4791,7 +4791,7 @@ namespace ts { if (parseExpected(SyntaxKind.OpenBraceToken)) { // ClassTail[Yield,Await] : (Modified) See 14.5 - // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt } + // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt } node.members = parseClassMembers(); parseExpected(SyntaxKind.CloseBraceToken); } @@ -5639,8 +5639,8 @@ namespace ts { let tags: NodeArray; let pos: number; - // NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I - // considered using an actual Scanner, but this would complicate things. The + // NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I + // considered using an actual Scanner, but this would complicate things. The // scanner would need to know it was in a Doc Comment. Otherwise, it would then // produce comments *inside* the doc comment. In the end it was just easier to // write a simple scanner rather than go that route. @@ -5655,7 +5655,7 @@ namespace ts { let canParseTag = true; let seenAsterisk = true; - for (pos = start + "/**".length; pos < end;) { + for (pos = start + "/**".length; pos < end; ) { let ch = content.charCodeAt(pos); pos++; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2924b30114e..5ce4846b43b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -346,7 +346,7 @@ namespace ts { if (!isDeclarationFile(sourceFile)) { let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken); // Don't actually write any files since we're just getting diagnostics. - var writeFile: WriteFileCallback = () => { }; + let writeFile: WriteFileCallback = () => { }; return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } }); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index a47d6959ba8..443c1c4789c 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -41,16 +41,16 @@ namespace ts { function getWScriptSystem(): System { - var fso = new ActiveXObject("Scripting.FileSystemObject"); + let fso = new ActiveXObject("Scripting.FileSystemObject"); - var fileStream = new ActiveXObject("ADODB.Stream"); + let fileStream = new ActiveXObject("ADODB.Stream"); fileStream.Type = 2 /*text*/; - var binaryStream = new ActiveXObject("ADODB.Stream"); + let binaryStream = new ActiveXObject("ADODB.Stream"); binaryStream.Type = 1 /*binary*/; - var args: string[] = []; - for (var i = 0; i < WScript.Arguments.length; i++) { + let args: string[] = []; + for (let i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); } @@ -68,7 +68,7 @@ namespace ts { // Load file and read the first two bytes into a string with no interpretation fileStream.Charset = "x-ansi"; fileStream.LoadFromFile(fileName); - var bom = fileStream.ReadText(2) || ""; + let bom = fileStream.ReadText(2) || ""; // Position must be at 0 before encoding can be changed fileStream.Position = 0; // [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8 @@ -114,28 +114,28 @@ namespace ts { } function getNames(collection: any): string[]{ - var result: string[] = []; - for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { + let result: string[] = []; + for (let e = new Enumerator(collection); !e.atEnd(); e.moveNext()) { result.push(e.item().Name); } return result.sort(); } function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { - var result: string[] = []; + let result: string[] = []; exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s))); visitDirectory(path); return result; function visitDirectory(path: string) { - var folder = fso.GetFolder(path || "."); - var files = getNames(folder.files); + let folder = fso.GetFolder(path || "."); + let files = getNames(folder.files); for (let current of files) { let name = combinePaths(path, current); if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) { result.push(name); } } - var subfolders = getNames(folder.subfolders); + let subfolders = getNames(folder.subfolders); for (let current of subfolders) { let name = combinePaths(path, current); if (!contains(exclude, getCanonicalPath(name))) { @@ -197,14 +197,14 @@ namespace ts { if (!_fs.existsSync(fileName)) { return undefined; } - var buffer = _fs.readFileSync(fileName); - var len = buffer.length; + let buffer = _fs.readFileSync(fileName); + let len = buffer.length; if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) { // Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js, // flip all byte pairs and treat as little endian. len &= ~1; - for (var i = 0; i < len; i += 2) { - var temp = buffer[i]; + for (let i = 0; i < len; i += 2) { + let temp = buffer[i]; buffer[i] = buffer[i + 1]; buffer[i + 1] = temp; } @@ -236,17 +236,17 @@ namespace ts { } function readDirectory(path: string, extension?: string, exclude?: string[]): string[] { - var result: string[] = []; + let result: string[] = []; exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s))); visitDirectory(path); return result; function visitDirectory(path: string) { - var files = _fs.readdirSync(path || ".").sort(); - var directories: string[] = []; + let files = _fs.readdirSync(path || ".").sort(); + let directories: string[] = []; for (let current of files) { - var name = combinePaths(path, current); + let name = combinePaths(path, current); if (!contains(exclude, getCanonicalPath(name))) { - var stat = _fs.statSync(name); + let stat = _fs.statSync(name); if (stat.isFile()) { if (!extension || fileExtensionIs(name, extension)) { result.push(name); @@ -331,4 +331,4 @@ namespace ts { return undefined; // Unsupported host } })(); -} \ No newline at end of file +} diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 4d00e579677..a657cc8c314 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -11,15 +11,15 @@ namespace ts { * and if it is, attempts to set the appropriate language. */ function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean { - var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); + let matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase()); if (!matchResult) { errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, 'en', 'ja-jp')); return false; } - var language = matchResult[1]; - var territory = matchResult[3]; + let language = matchResult[1]; + let territory = matchResult[3]; // First try the entire locale, then fall back to just language if that's all we have. if (!trySetLanguageAndTerritory(language, territory, errors) && @@ -33,10 +33,10 @@ namespace ts { } function trySetLanguageAndTerritory(language: string, territory: string, errors: Diagnostic[]): boolean { - var compilerFilePath = normalizePath(sys.getExecutingFilePath()); - var containingDirectoryPath = getDirectoryPath(compilerFilePath); + let compilerFilePath = normalizePath(sys.getExecutingFilePath()); + let containingDirectoryPath = getDirectoryPath(compilerFilePath); - var filePath = combinePaths(containingDirectoryPath, language); + let filePath = combinePaths(containingDirectoryPath, language); if (territory) { filePath = filePath + "-" + territory; @@ -49,8 +49,9 @@ namespace ts { } // TODO: Add codePage support for readFile? + let fileContents = ''; try { - var fileContents = sys.readFile(filePath); + fileContents = sys.readFile(filePath); } catch (e) { errors.push(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, filePath)); @@ -68,7 +69,7 @@ namespace ts { } function countLines(program: Program): number { - var count = 0; + let count = 0; forEach(program.getSourceFiles(), file => { count += getLineStarts(file).length; }); @@ -76,27 +77,27 @@ namespace ts { } function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string { - var diagnostic = createCompilerDiagnostic.apply(undefined, arguments); + let diagnostic = createCompilerDiagnostic.apply(undefined, arguments); return diagnostic.messageText; } function reportDiagnostic(diagnostic: Diagnostic) { - var output = ""; + let output = ""; if (diagnostic.file) { - var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + let loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); output += `${ diagnostic.file.fileName }(${ loc.line + 1 },${ loc.character + 1 }): `; } - var category = DiagnosticCategory[diagnostic.category].toLowerCase(); + let category = DiagnosticCategory[diagnostic.category].toLowerCase(); output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`; sys.write(output); } function reportDiagnostics(diagnostics: Diagnostic[]) { - for (var i = 0; i < diagnostics.length; i++) { + for (let i = 0; i < diagnostics.length; i++) { reportDiagnostic(diagnostics[i]); } } @@ -133,15 +134,15 @@ namespace ts { } export function executeCommandLine(args: string[]): void { - var commandLine = parseCommandLine(args); - var configFileName: string; // Configuration file name (if any) - var configFileWatcher: FileWatcher; // Configuration file watcher - var cachedProgram: Program; // Program cached from last compilation - var rootFileNames: string[]; // Root fileNames for compilation - var compilerOptions: CompilerOptions; // Compiler options for compilation - var compilerHost: CompilerHost; // Compiler host - var hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host - var timerHandle: number; // Handle for 0.25s wait timer + let commandLine = parseCommandLine(args); + let configFileName: string; // Configuration file name (if any) + let configFileWatcher: FileWatcher; // Configuration file watcher + let cachedProgram: Program; // Program cached from last compilation + let rootFileNames: string[]; // Root fileNames for compilation + let compilerOptions: CompilerOptions; // Compiler options for compilation + let compilerHost: CompilerHost; // Compiler host + let hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host + let timerHandle: number; // Handle for 0.25s wait timer if (commandLine.options.locale) { if (!isJSONSupported()) { @@ -181,7 +182,7 @@ namespace ts { } } else if (commandLine.fileNames.length === 0 && isJSONSupported()) { - var searchPath = normalizePath(sys.getCurrentDirectory()); + let searchPath = normalizePath(sys.getCurrentDirectory()); configFileName = findConfigFile(searchPath); } @@ -247,14 +248,14 @@ namespace ts { function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) { // Return existing SourceFile object if one is available if (cachedProgram) { - var sourceFile = cachedProgram.getSourceFile(fileName); + let sourceFile = cachedProgram.getSourceFile(fileName); // A modified source file has no watcher and should not be reused if (sourceFile && sourceFile.fileWatcher) { return sourceFile; } } // Use default host function - var sourceFile = hostGetSourceFile(fileName, languageVersion, onError); + let sourceFile = hostGetSourceFile(fileName, languageVersion, onError); if (sourceFile && compilerOptions.watch) { // Attach a file watcher sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile)); @@ -265,7 +266,7 @@ namespace ts { // Change cached program to the given program function setCachedProgram(program: Program) { if (cachedProgram) { - var newSourceFiles = program ? program.getSourceFiles() : undefined; + let newSourceFiles = program ? program.getSourceFiles() : undefined; forEach(cachedProgram.getSourceFiles(), sourceFile => { if (!(newSourceFiles && contains(newSourceFiles, sourceFile))) { if (sourceFile.fileWatcher) { @@ -316,8 +317,8 @@ namespace ts { checkTime = 0; emitTime = 0; - var program = createProgram(fileNames, compilerOptions, compilerHost); - var exitStatus = compileProgram(); + let program = createProgram(fileNames, compilerOptions, compilerHost); + let exitStatus = compileProgram(); if (compilerOptions.listFiles) { forEach(program.getSourceFiles(), file => { @@ -326,7 +327,7 @@ namespace ts { } if (compilerOptions.diagnostics) { - var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; + let memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1; reportCountStatistic("Files", program.getSourceFiles().length); reportCountStatistic("Lines", countLines(program)); reportCountStatistic("Nodes", program.getNodeCount()); @@ -354,18 +355,18 @@ namespace ts { return { program, exitStatus }; function compileProgram(): ExitStatus { - // First get any syntactic errors. - var diagnostics = program.getSyntacticDiagnostics(); + // First get any syntactic errors. + let diagnostics = program.getSyntacticDiagnostics(); reportDiagnostics(diagnostics); - // If we didn't have any syntactic errors, then also try getting the global and + // If we didn't have any syntactic errors, then also try getting the global and // semantic errors. if (diagnostics.length === 0) { - var diagnostics = program.getGlobalDiagnostics(); + let diagnostics = program.getGlobalDiagnostics(); reportDiagnostics(diagnostics); if (diagnostics.length === 0) { - var diagnostics = program.getSemanticDiagnostics(); + let diagnostics = program.getSemanticDiagnostics(); reportDiagnostics(diagnostics); } } @@ -378,7 +379,7 @@ namespace ts { } // Otherwise, emit and report any errors we ran into. - var emitOutput = program.emit(); + let emitOutput = program.emit(); reportDiagnostics(emitOutput.diagnostics); // If the emitter didn't emit anything, then pass that value along. @@ -401,22 +402,22 @@ namespace ts { } function printHelp() { - var output = ""; + let output = ""; // We want to align our "syntax" and "examples" commands to a certain margin. - var syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length; - var examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length; - var marginLength = Math.max(syntaxLength, examplesLength); + let syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length; + let examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length; + let marginLength = Math.max(syntaxLength, examplesLength); // Build up the syntactic skeleton. - var syntax = makePadding(marginLength - syntaxLength); + let syntax = makePadding(marginLength - syntaxLength); syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]"; output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax); output += sys.newLine + sys.newLine; // Build up the list of examples. - var padding = makePadding(marginLength); + let padding = makePadding(marginLength); output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; output += padding + "tsc --out file.js file.ts" + sys.newLine; output += padding + "tsc @args.txt" + sys.newLine; @@ -425,17 +426,17 @@ namespace ts { output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") - var optsList = filter(optionDeclarations.slice(), v => !v.experimental); + let optsList = filter(optionDeclarations.slice(), v => !v.experimental); optsList.sort((a, b) => compareValues(a.name.toLowerCase(), b.name.toLowerCase())); // We want our descriptions to align at the same column in our output, // so we keep track of the longest option usage string. - var marginLength = 0; - var usageColumn: string[] = []; // Things like "-d, --declaration" go in here. - var descriptionColumn: string[] = []; + marginLength = 0; + let usageColumn: string[] = []; // Things like "-d, --declaration" go in here. + let descriptionColumn: string[] = []; - for (var i = 0; i < optsList.length; i++) { - var option = optsList[i]; + for (let i = 0; i < optsList.length; i++) { + let option = optsList[i]; // If an option lacks a description, // it is not officially supported. @@ -443,7 +444,7 @@ namespace ts { continue; } - var usageText = " "; + let usageText = " "; if (option.shortName) { usageText += "-" + option.shortName; usageText += getParamType(option); @@ -461,15 +462,15 @@ namespace ts { } // Special case that can't fit in the loop. - var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; + let usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">"; usageColumn.push(usageText); descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file)); marginLength = Math.max(usageText.length, marginLength); // Print out each row, aligning all the descriptions on the same column. - for (var i = 0; i < usageColumn.length; i++) { - var usage = usageColumn[i]; - var description = descriptionColumn[i]; + for (let i = 0; i < usageColumn.length; i++) { + let usage = usageColumn[i]; + let description = descriptionColumn[i]; output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b150b53349f..389eda4cced 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -273,7 +273,7 @@ namespace ts { // Module references ExternalModuleReference, - //JSX + // JSX JsxElement, JsxSelfClosingElement, JsxOpeningElement, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bec4ece0491..1750b7a5245 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -92,7 +92,7 @@ namespace ts { let thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & ParserContextFlags.ThisNodeHasError) !== 0) || forEachChild(node, containsParseError); - // If so, mark ourselves accordingly. + // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError; } @@ -129,13 +129,13 @@ namespace ts { // Returns true if this node is missing from the actual source code. 'missing' is different // from 'undefined/defined'. When a node is undefined (which can happen for optional nodes - // in the tree), it is definitel missing. HOwever, a node may be defined, but still be + // in the tree), it is definitel missing. HOwever, a node may be defined, but still be // missing. This happens whenever the parser knows it needs to parse something, but can't // get anything in the source code that it expects at that location. For example: // // let a: ; // - // Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source + // Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source // code). So the parser will attempt to parse out a type, and will create an actual node. // However, this node will be 'missing' in the sense that no actual source-code/tokens are // contained within it. @@ -211,7 +211,7 @@ namespace ts { isCatchClauseVariableDeclaration(declaration); } - // Gets the nearest enclosing block scope container that has the provided node + // Gets the nearest enclosing block scope container that has the provided node // as a descendant, that is not the provided node. export function getEnclosingBlockScopeContainer(node: Node): Node { let current = node.parent; @@ -307,7 +307,7 @@ namespace ts { } if (errorNode === undefined) { - // If we don't have a better node, then just set the error on the first token of + // If we don't have a better node, then just set the error on the first token of // construct. return getSpanOfTokenAtPosition(sourceFile, node.pos); } @@ -339,10 +339,10 @@ namespace ts { return node; } - // Returns the node flags for this node and all relevant parent nodes. This is done so that + // Returns the node flags for this node and all relevant parent nodes. This is done so that // nodes like variable declarations and binding elements can returned a view of their flags // that includes the modifiers from their container. i.e. flags like export/declare aren't - // stored on the variable declaration directly, but on the containing variable statement + // stored on the variable declaration directly, but on the containing variable statement // (if it has one). Similarly, flags for let/const are store on the variable declaration // list. By calling this function, all those flags are combined so that the client can treat // the node as if it actually had those flags. @@ -662,7 +662,7 @@ namespace ts { node = node.parent; break; case SyntaxKind.Decorator: - // Decorators are always applied outside of the body of a class or method. + // Decorators are always applied outside of the body of a class or method. if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. @@ -717,7 +717,7 @@ namespace ts { node = node.parent; break; case SyntaxKind.Decorator: - // Decorators are always applied outside of the body of a class or method. + // Decorators are always applied outside of the body of a class or method. if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) { // If the decorator's parent is a Parameter, we resolve the this container from // the grandparent class declaration. @@ -746,14 +746,14 @@ namespace ts { } } } - + export function getEntityNameFromTypeNode(node: TypeNode): EntityName | Expression { - if (node) { + if (node) { switch (node.kind) { case SyntaxKind.TypeReference: return (node).typeName; case SyntaxKind.ExpressionWithTypeArguments: - return (node).expression + return (node).expression; case SyntaxKind.Identifier: case SyntaxKind.QualifiedName: return (node); @@ -1031,7 +1031,7 @@ namespace ts { export function getCorrespondingJSDocParameterTag(parameter: ParameterDeclaration): JSDocParameterTag { if (parameter.name && parameter.name.kind === SyntaxKind.Identifier) { - // If it's a parameter, see if the parent has a jsdoc comment with an @param + // If it's a parameter, see if the parent has a jsdoc comment with an @param // annotation. let parameterName = (parameter.name).text; @@ -1969,7 +1969,7 @@ namespace ts { return false; } } - + export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) { return (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node) || (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).name === node); @@ -1988,7 +1988,7 @@ namespace ts { } /** - * Replace each instance of non-ascii characters by one, two, three, or four escape sequences + * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. */ function getExpandedCharCodes(input: string): number[] { @@ -2178,10 +2178,10 @@ namespace ts { export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); /** - * Called to merge all the changes that occurred across several versions of a script snapshot + * Called to merge all the changes that occurred across several versions of a script snapshot * into a single change. i.e. if a user keeps making successive edits to a script we will - * have a text change from V1 to V2, V2 to V3, ..., Vn. - * + * have a text change from V1 to V2, V2 to V3, ..., Vn. + * * This function will then merge those changes into a single change range valid between V1 and * Vn. */ @@ -2212,17 +2212,17 @@ namespace ts { // // 0 10 20 30 40 50 60 70 80 90 100 // ------------------------------------------------------------------------------------------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- // ------------------------------------------------------------------------------------------------------- - // | \ - // | \ - // T2 | \ - // | \ - // | \ + // | \ + // | \ + // T2 | \ + // | \ + // | \ // ------------------------------------------------------------------------------------------------------- // // Merging these turns out to not be too difficult. First, determining the new start of the change is trivial @@ -2230,17 +2230,17 @@ namespace ts { // // 0 10 20 30 40 50 60 70 80 90 100 // ------------------------------------------------------------*------------------------------------------ - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- // ----------------------------------------$-------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ // ----------------------------------------------------------------------*-------------------------------- // // (Note the dots represent the newly inferrred start. @@ -2251,22 +2251,22 @@ namespace ts { // // 0 10 20 30 40 50 60 70 80 90 100 // --------------------------------------------------------------------------------*---------------------- - // | / - // | /---- - // T1 | /---- - // | /---- - // | /---- + // | / + // | /---- + // T1 | /---- + // | /---- + // | /---- // ------------------------------------------------------------$------------------------------------------ - // . | \ - // . | \ - // T2 . | \ - // . | \ - // . | \ + // . | \ + // . | \ + // T2 . | \ + // . | \ + // . | \ // ----------------------------------------------------------------------*-------------------------------- // // In other words (in this case), we're recognizing that the second edit happened after where the first edit // ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started - // that's the same as if we started at char 80 instead of 60. + // that's the same as if we started at char 80 instead of 60. // // As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter // than pusing the first edit forward to match the second, we'll push the second edit forward to match the @@ -2276,7 +2276,7 @@ namespace ts { // semantics: { { start: 10, length: 70 }, newLength: 60 } // // The math then works out as follows. - // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the + // If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the // final result like so: // // { diff --git a/tslint.json b/tslint.json index 74f80185a36..16a69b81f83 100644 --- a/tslint.json +++ b/tslint.json @@ -4,15 +4,11 @@ "comment-format": [true, "check-space" ], - "curly": true, "indent": true, "one-line": [true, "check-open-brace" ], - "no-empty": true, - "no-trailing-whitespace": true, "no-unreachable": true, - "no-unused-variable": true, "no-use-before-declare": true, "no-var-keyword": true, "quotemark": true, @@ -24,4 +20,4 @@ "check-type" ] } -} \ No newline at end of file +} From 98e6db47982f9024e1a04cacc15ade7f31f49159 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Thu, 9 Jul 2015 11:16:36 +0800 Subject: [PATCH 64/88] Fixes fourslash code formatting --- src/harness/fourslashRunner.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/harness/fourslashRunner.ts b/src/harness/fourslashRunner.ts index d11c5e639e5..0db01c30f32 100644 --- a/src/harness/fourslashRunner.ts +++ b/src/harness/fourslashRunner.ts @@ -35,9 +35,9 @@ class FourSlashRunner extends RunnerBase { this.tests = this.enumerateFiles(this.basePath, /\.ts/i, { recursive: false }); } - this.tests.forEach((fn: string) => { - describe(fn, () => { - fn = ts.normalizeSlashes(fn); + this.tests.forEach((fn: string) => { + describe(fn, () => { + fn = ts.normalizeSlashes(fn); var justName = fn.replace(/^.*[\\\/]/, ''); // Convert to relative path @@ -45,7 +45,7 @@ class FourSlashRunner extends RunnerBase { if (testIndex >= 0) fn = fn.substr(testIndex); if (justName && !justName.match(/fourslash\.ts$/i) && !justName.match(/\.d\.ts$/i)) { - it(this.testSuiteName + ' test ' + justName + ' runs correctly',() => { + it(this.testSuiteName + ' test ' + justName + ' runs correctly', () => { FourSlash.runFourSlashTest(this.basePath, this.testType, fn); }); } From 951084fc853107b4d8e3dd616545fb34fba52ac3 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Tue, 7 Jul 2015 11:01:49 +0800 Subject: [PATCH 65/88] Fixes emit of type predicated in delcaration files --- src/compiler/declarationEmitter.ts | 46 +++++++++++++---------- tests/cases/compiler/declFileFunctions.ts | 4 ++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 8c012f2678e..3db032b8d0d 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -188,7 +188,7 @@ namespace ts { if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) { moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); } - + // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration // then we don't need to write it at this point. We will write it when we actually see its declaration // Eg. @@ -198,7 +198,7 @@ namespace ts { // we would write alias foo declaration when we visit it since it would now be marked as visible if (moduleElementEmitInfo) { if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) { - // we have to create asynchronous output only after we have collected complete information + // we have to create asynchronous output only after we have collected complete information // because it is possible to enable multiple bindings as asynchronously visible moduleElementEmitInfo.isVisible = true; } @@ -353,6 +353,21 @@ namespace ts { return emitEntityName(type); case SyntaxKind.QualifiedName: return emitEntityName(type); + case SyntaxKind.TypePredicate: + return emitTypePredicate(type); + } + + function writeEntityName(entityName: EntityName | Expression) { + if (entityName.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, entityName); + } + else { + let left = entityName.kind === SyntaxKind.QualifiedName ? (entityName).left : (entityName).expression; + let right = entityName.kind === SyntaxKind.QualifiedName ? (entityName).right : (entityName).name; + writeEntityName(left); + write("."); + writeTextOfNode(currentSourceFile, right); + } } function emitEntityName(entityName: EntityName | PropertyAccessExpression) { @@ -362,19 +377,6 @@ namespace ts { handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); - - function writeEntityName(entityName: EntityName | Expression) { - if (entityName.kind === SyntaxKind.Identifier) { - writeTextOfNode(currentSourceFile, entityName); - } - else { - let left = entityName.kind === SyntaxKind.QualifiedName ? (entityName).left : (entityName).expression; - let right = entityName.kind === SyntaxKind.QualifiedName ? (entityName).right : (entityName).name; - writeEntityName(left); - write("."); - writeTextOfNode(currentSourceFile, right); - } - } } function emitExpressionWithTypeArguments(node: ExpressionWithTypeArguments) { @@ -398,6 +400,12 @@ namespace ts { } } + function emitTypePredicate(type: TypePredicateNode) { + writeEntityName(type.parameterName); + write(" is "); + emitType(type.type); + } + function emitTypeQuery(type: TypeQueryNode) { write("typeof "); emitEntityName(type.exprName); @@ -600,7 +608,7 @@ namespace ts { } function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // note usage of writer. methods instead of aliases created, just to make sure we are using + // note usage of writer. methods instead of aliases created, just to make sure we are using // correct writer especially to handle asynchronous alias writing emitJsDocComments(node); if (node.flags & NodeFlags.Export) { @@ -642,7 +650,7 @@ namespace ts { function writeImportDeclaration(node: ImportDeclaration) { if (!node.importClause && !(node.flags & NodeFlags.Export)) { - // do not write non-exported import declarations that don't have import clauses + // do not write non-exported import declarations that don't have import clauses return; } emitJsDocComments(node); @@ -1517,7 +1525,7 @@ namespace ts { } } } - } + } } function emitNode(node: Node) { @@ -1577,7 +1585,7 @@ namespace ts { referencePathsOutput += "/// " + newLine; } } - + /* @internal */ export function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[]) { let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); diff --git a/tests/cases/compiler/declFileFunctions.ts b/tests/cases/compiler/declFileFunctions.ts index e7ce3d07f82..36972d427f0 100644 --- a/tests/cases/compiler/declFileFunctions.ts +++ b/tests/cases/compiler/declFileFunctions.ts @@ -28,6 +28,10 @@ export function fooWithSingleOverload(a: any) { return a; } +export function fooWithTypePredicate(a: any): a is number { + return true; +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { } From 08a774425452b7a24219fbdf3564b8642ce5f20c Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Tue, 7 Jul 2015 11:11:56 +0800 Subject: [PATCH 66/88] Accepts baselines --- .../baselines/reference/declFileFunctions.js | 9 ++++ .../reference/declFileFunctions.symbols | 44 +++++++++++-------- .../reference/declFileFunctions.types | 9 ++++ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/declFileFunctions.js b/tests/baselines/reference/declFileFunctions.js index da1917163e1..d3debf4d50c 100644 --- a/tests/baselines/reference/declFileFunctions.js +++ b/tests/baselines/reference/declFileFunctions.js @@ -26,6 +26,10 @@ export function fooWithSingleOverload(a: any) { return a; } +export function fooWithTypePredicate(a: any): a is number { + return true; +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { } @@ -92,6 +96,10 @@ function fooWithSingleOverload(a) { return a; } exports.fooWithSingleOverload = fooWithSingleOverload; +function fooWithTypePredicate(a) { + return true; +} +exports.fooWithTypePredicate = fooWithTypePredicate; /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { } @@ -144,6 +152,7 @@ export declare function fooWithRestParameters(a: string, ...rests: string[]): st export declare function fooWithOverloads(a: string): string; export declare function fooWithOverloads(a: number): number; export declare function fooWithSingleOverload(a: string): string; +export declare function fooWithTypePredicate(a: any): a is number; //// [declFileFunctions_1.d.ts] /** This comment should appear for foo*/ declare function globalfoo(): void; diff --git a/tests/baselines/reference/declFileFunctions.symbols b/tests/baselines/reference/declFileFunctions.symbols index ff04d211557..1d62cc29d28 100644 --- a/tests/baselines/reference/declFileFunctions.symbols +++ b/tests/baselines/reference/declFileFunctions.symbols @@ -57,49 +57,57 @@ export function fooWithSingleOverload(a: any) { >a : Symbol(a, Decl(declFileFunctions_0.ts, 21, 38)) } +export function fooWithTypePredicate(a: any): a is number { +>fooWithTypePredicate : Symbol(fooWithTypePredicate, Decl(declFileFunctions_0.ts, 23, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 25, 37)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 25, 37)) + + return true; +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { ->nonExportedFoo : Symbol(nonExportedFoo, Decl(declFileFunctions_0.ts, 23, 1)) +>nonExportedFoo : Symbol(nonExportedFoo, Decl(declFileFunctions_0.ts, 27, 1)) } /** This is comment for function signature*/ function nonExportedFooWithParameters(/** this is comment about a*/a: string, ->nonExportedFooWithParameters : Symbol(nonExportedFooWithParameters, Decl(declFileFunctions_0.ts, 27, 1)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 29, 38)) +>nonExportedFooWithParameters : Symbol(nonExportedFooWithParameters, Decl(declFileFunctions_0.ts, 31, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 33, 38)) /** this is comment for b*/ b: number) { ->b : Symbol(b, Decl(declFileFunctions_0.ts, 29, 77)) +>b : Symbol(b, Decl(declFileFunctions_0.ts, 33, 77)) var d = a; ->d : Symbol(d, Decl(declFileFunctions_0.ts, 32, 7)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 29, 38)) +>d : Symbol(d, Decl(declFileFunctions_0.ts, 36, 7)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 33, 38)) } function nonExportedFooWithRestParameters(a: string, ...rests: string[]) { ->nonExportedFooWithRestParameters : Symbol(nonExportedFooWithRestParameters, Decl(declFileFunctions_0.ts, 33, 1)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 34, 42)) ->rests : Symbol(rests, Decl(declFileFunctions_0.ts, 34, 52)) +>nonExportedFooWithRestParameters : Symbol(nonExportedFooWithRestParameters, Decl(declFileFunctions_0.ts, 37, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 38, 42)) +>rests : Symbol(rests, Decl(declFileFunctions_0.ts, 38, 52)) return a + rests.join(""); ->a : Symbol(a, Decl(declFileFunctions_0.ts, 34, 42)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 38, 42)) >rests.join : Symbol(Array.join, Decl(lib.d.ts, 1035, 31)) ->rests : Symbol(rests, Decl(declFileFunctions_0.ts, 34, 52)) +>rests : Symbol(rests, Decl(declFileFunctions_0.ts, 38, 52)) >join : Symbol(Array.join, Decl(lib.d.ts, 1035, 31)) } function nonExportedFooWithOverloads(a: string): string; ->nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 36, 1), Decl(declFileFunctions_0.ts, 38, 56), Decl(declFileFunctions_0.ts, 39, 56)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 38, 37)) +>nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 40, 1), Decl(declFileFunctions_0.ts, 42, 56), Decl(declFileFunctions_0.ts, 43, 56)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 42, 37)) function nonExportedFooWithOverloads(a: number): number; ->nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 36, 1), Decl(declFileFunctions_0.ts, 38, 56), Decl(declFileFunctions_0.ts, 39, 56)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 39, 37)) +>nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 40, 1), Decl(declFileFunctions_0.ts, 42, 56), Decl(declFileFunctions_0.ts, 43, 56)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 43, 37)) function nonExportedFooWithOverloads(a: any): any { ->nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 36, 1), Decl(declFileFunctions_0.ts, 38, 56), Decl(declFileFunctions_0.ts, 39, 56)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 40, 37)) +>nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 40, 1), Decl(declFileFunctions_0.ts, 42, 56), Decl(declFileFunctions_0.ts, 43, 56)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 44, 37)) return a; ->a : Symbol(a, Decl(declFileFunctions_0.ts, 40, 37)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 44, 37)) } === tests/cases/compiler/declFileFunctions_1.ts === diff --git a/tests/baselines/reference/declFileFunctions.types b/tests/baselines/reference/declFileFunctions.types index b9e94f7ffcd..e6ecc53b043 100644 --- a/tests/baselines/reference/declFileFunctions.types +++ b/tests/baselines/reference/declFileFunctions.types @@ -60,6 +60,15 @@ export function fooWithSingleOverload(a: any) { >a : any } +export function fooWithTypePredicate(a: any): a is number { +>fooWithTypePredicate : (a: any) => boolean +>a : any +>a : any + + return true; +>true : boolean +} + /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { >nonExportedFoo : () => void From 28976a0e344258605e777d4d75217084bcb9dc0d Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Thu, 9 Jul 2015 11:13:32 +0800 Subject: [PATCH 67/88] Adds type predicate signature display and addresses CR feedback --- src/compiler/checker.ts | 340 +++++++++--------- src/compiler/declarationEmitter.ts | 2 +- tests/cases/compiler/declFileFunctions.ts | 9 + .../signatureHelpOnTypePredicates.ts | 20 ++ 4 files changed, 206 insertions(+), 165 deletions(-) create mode 100644 tests/cases/fourslash/signatureHelpOnTypePredicates.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b34952f3ae..03a3f7efa9b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25,12 +25,12 @@ namespace ts { // Cancellation that controls whether or not we can cancel in the middle of type checking. // In general cancelling is *not* safe for the type checker. We might be in the middle of // computing something, and we will leave our internals in an inconsistent state. Callers - // who set the cancellation token should catch if a cancellation exception occurs, and + // who set the cancellation token should catch if a cancellation exception occurs, and // should throw away and create a new TypeChecker. // // Currently we only support setting the cancellation token when getting diagnostics. This // is because diagnostics can be quite expensive, and we want to allow hosts to bail out if - // they no longer need the information (for example, if the user started editing again). + // they no longer need the information (for example, if the user started editing again). let cancellationToken: CancellationToken; let Symbol = objectAllocator.getSymbolConstructor(); @@ -117,7 +117,7 @@ namespace ts { let globals: SymbolTable = {}; let globalESSymbolConstructorSymbol: Symbol; - + let getGlobalPromiseConstructorSymbol: () => Symbol; let globalObjectType: ObjectType; @@ -148,7 +148,7 @@ namespace ts { let getInstantiatedGlobalPromiseLikeType: () => ObjectType; let getGlobalPromiseConstructorLikeType: () => ObjectType; let getGlobalThenableType: () => ObjectType; - + let tupleTypes: Map = {}; let unionTypes: Map = {}; let intersectionTypes: Map = {}; @@ -158,7 +158,7 @@ namespace ts { let emitParam = false; let emitAwaiter = false; let emitGenerator = false; - + let resolutionTargets: Object[] = []; let resolutionResults: boolean[] = []; @@ -406,7 +406,7 @@ namespace ts { let moduleExports = getSymbolOfNode(location).exports; if (location.kind === SyntaxKind.SourceFile || (location.kind === SyntaxKind.ModuleDeclaration && (location).name.kind === SyntaxKind.StringLiteral)) { - + // It's an external module. Because of module/namespace merging, a module's exports are in scope, // yet we never want to treat an export specifier as putting a member in scope. Therefore, // if the name we find is purely an export specifier, it is not actually considered in scope. @@ -526,7 +526,7 @@ namespace ts { } break; case SyntaxKind.Decorator: - // Decorators are resolved at the class declaration. Resolving at the parameter + // Decorators are resolved at the class declaration. Resolving at the parameter // or member would result in looking up locals in the method. // // function y() {} @@ -1948,7 +1948,19 @@ namespace ts { writePunctuation(writer, SyntaxKind.ColonToken); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); + + let returnType: Type; + if (signature.typePredicate) { + writer.writeParameter(signature.typePredicate.parameterName); + writeSpace(writer); + writeKeyword(writer, SyntaxKind.IsKeyword); + writeSpace(writer); + returnType = signature.typePredicate.type; + } + else { + returnType = getReturnTypeOfSignature(signature); + } + buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack); } function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { @@ -2098,7 +2110,7 @@ namespace ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); - // Default binding, import specifier and namespace import is visible + // Default binding, import specifier and namespace import is visible // only on demand so by default it is not visible case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: @@ -3864,7 +3876,7 @@ namespace ts { function getGlobalType(name: string, arity = 0): ObjectType { return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity); } - + function tryGetGlobalType(name: string, arity = 0): ObjectType { return getTypeOfGlobalSymbol(getGlobalSymbol(name, SymbolFlags.Type, /*diagnostic*/ undefined), arity); } @@ -3892,7 +3904,7 @@ namespace ts { ? createTypeReference(globalTypedPropertyDescriptorType, [propertyType]) : emptyObjectType; } - + /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ @@ -4117,7 +4129,7 @@ namespace ts { } return links.resolvedType; } - + function getTypeFromTypeNode(node: TypeNode): Type { switch (node.kind) { case SyntaxKind.AnyKeyword: @@ -6053,7 +6065,7 @@ namespace ts { error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression); } } - + if (node.parserContextFlags & ParserContextFlags.Await) { getNodeLinks(container).flags |= NodeCheckFlags.CaptureArguments; getNodeLinks(node).flags |= NodeCheckFlags.LexicalArguments; @@ -6746,7 +6758,7 @@ namespace ts { // c is represented in the tree as a spread element in an array literal. // But c really functions as a rest element, and its purpose is to provide // a contextual type for the right hand side of the assignment. Therefore, - // instead of calling checkExpression on "...c", which will give an error + // instead of calling checkExpression on "...c", which will give an error // if c is not iterable/array-like, we need to act as if we are trying to // get the contextual element type from it. So we do something similar to // getContextualTypeForElementExpression, which will crucially not error @@ -7399,7 +7411,7 @@ namespace ts { if (flags & NodeFlags.Abstract) { // A method cannot be accessed in a super property access if the method is abstract. - // This error could mask a private property access error. But, a member + // This error could mask a private property access error. But, a member // cannot simultaneously be private and abstract, so this will trigger an // additional error elsewhere. @@ -7478,7 +7490,7 @@ namespace ts { } return unknownType; } - + getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & SymbolFlags.Class) { @@ -7875,7 +7887,7 @@ namespace ts { let paramType = getTypeAtPosition(signature, i); let argType = getEffectiveArgumentType(node, i, arg); - // If the effective argument type is 'undefined', there is no synthetic type + // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. if (argType === undefined) { // For context sensitive arguments we pass the identityMapper, which is a signal to treat all @@ -7947,8 +7959,8 @@ namespace ts { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) let paramType = getTypeAtPosition(signature, i); let argType = getEffectiveArgumentType(node, i, arg); - - // If the effective argument type is 'undefined', there is no synthetic type + + // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. if (argType === undefined) { argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors @@ -8001,18 +8013,18 @@ namespace ts { return args; } - + /** * Returns the effective argument count for a node that works like a function invocation. * If 'node' is a Decorator, the number of arguments is derived from the decoration * target and the signature: - * If 'node.target' is a class declaration or class expression, the effective argument + * If 'node.target' is a class declaration or class expression, the effective argument * count is 1. * If 'node.target' is a parameter declaration, the effective argument count is 3. * If 'node.target' is a property declaration, the effective argument count is 2. - * If 'node.target' is a method or accessor declaration, the effective argument count + * If 'node.target' is a method or accessor declaration, the effective argument count * is 3, although it can be 2 if the signature only accepts two arguments, allowing - * us to match a property decorator. + * us to match a property decorator. * Otherwise, the argument count is the length of the 'args' array. */ function getEffectiveArgumentCount(node: CallLikeExpression, args: Expression[], signature: Signature) { @@ -8024,7 +8036,7 @@ namespace ts { return 1; case SyntaxKind.PropertyDeclaration: - // A property declaration decorator will have two arguments (see + // A property declaration decorator will have two arguments (see // `PropertyDecorator` in core.d.ts) return 2; @@ -8033,12 +8045,12 @@ namespace ts { case SyntaxKind.SetAccessor: // A method or accessor declaration decorator will have two or three arguments (see // `PropertyDecorator` and `MethodDecorator` in core.d.ts) - // If the method decorator signature only accepts a target and a key, we will only + // If the method decorator signature only accepts a target and a key, we will only // type check those arguments. return signature.parameters.length >= 3 ? 3 : 2; case SyntaxKind.Parameter: - // A parameter declaration decorator will have three arguments (see + // A parameter declaration decorator will have three arguments (see // `ParameterDecorator` in core.d.ts) return 3; @@ -8048,47 +8060,47 @@ namespace ts { return args.length; } } - + /** * Returns the effective type of the first argument to a decorator. * If 'node' is a class declaration or class expression, the effective argument type * is the type of the static side of the class. * If 'node' is a parameter declaration, the effective argument type is either the type - * of the static or instance side of the class for the parameter's parent method, + * of the static or instance side of the class for the parameter's parent method, * depending on whether the method is declared static. * For a constructor, the type is always the type of the static side of the class. - * If 'node' is a property, method, or accessor declaration, the effective argument - * type is the type of the static or instance side of the parent class for class - * element, depending on whether the element is declared static. + * If 'node' is a property, method, or accessor declaration, the effective argument + * type is the type of the static or instance side of the parent class for class + * element, depending on whether the element is declared static. */ function getEffectiveDecoratorFirstArgumentType(node: Node): Type { // The first argument to a decorator is its `target`. switch (node.kind) { case SyntaxKind.ClassDeclaration: case SyntaxKind.ClassExpression: - // For a class decorator, the `target` is the type of the class (e.g. the + // For a class decorator, the `target` is the type of the class (e.g. the // "static" or "constructor" side of the class) let classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); case SyntaxKind.Parameter: - // For a parameter decorator, the `target` is the parent type of the - // parameter's containing method. + // For a parameter decorator, the `target` is the parent type of the + // parameter's containing method. node = node.parent; if (node.kind === SyntaxKind.Constructor) { let classSymbol = getSymbolOfNode(node); return getTypeOfSymbol(classSymbol); } - + // fall-through - + case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: // For a property or method decorator, the `target` is the // "static"-side type of the parent of the member if the member is - // declared "static"; otherwise, it is the "instance"-side type of the + // declared "static"; otherwise, it is the "instance"-side type of the // parent of the member. return getParentTypeOfClassElement(node); @@ -8097,19 +8109,19 @@ namespace ts { return unknownType; } } - + /** * Returns the effective type for the second argument to a decorator. * If 'node' is a parameter, its effective argument type is one of the following: - * If 'node.parent' is a constructor, the effective argument type is 'any', as we + * If 'node.parent' is a constructor, the effective argument type is 'any', as we * will emit `undefined`. - * If 'node.parent' is a member with an identifier, numeric, or string literal name, + * If 'node.parent' is a member with an identifier, numeric, or string literal name, * the effective argument type will be a string literal type for the member name. - * If 'node.parent' is a computed property name, the effective argument type will + * If 'node.parent' is a computed property name, the effective argument type will * either be a symbol type or the string type. - * If 'node' is a member with an identifier, numeric, or string literal name, the + * If 'node' is a member with an identifier, numeric, or string literal name, the * effective argument type will be a string literal type for the member name. - * If 'node' is a computed property name, the effective argument type will either + * If 'node' is a computed property name, the effective argument type will either * be a symbol type or the string type. * A class decorator does not have a second argument type. */ @@ -8126,18 +8138,18 @@ namespace ts { // For a constructor parameter decorator, the `propertyKey` will be `undefined`. return anyType; } - + // For a non-constructor parameter decorator, the `propertyKey` will be either // a string or a symbol, based on the name of the parameter's containing method. - + // fall-through - + case SyntaxKind.PropertyDeclaration: case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: // The `propertyKey` for a property or method decorator will be a - // string literal type if the member name is an identifier, number, or string; + // string literal type if the member name is an identifier, number, or string; // otherwise, if the member name is a computed property name it will // be either string or symbol. let element = node; @@ -8167,11 +8179,11 @@ namespace ts { return unknownType; } } - + /** * Returns the effective argument type for the third argument to a decorator. * If 'node' is a parameter, the effective argument type is the number type. - * If 'node' is a method or accessor, the effective argument type is a + * If 'node' is a method or accessor, the effective argument type is a * `TypedPropertyDescriptor` instantiated with the type of the member. * Class and property decorators do not have a third effective argument. */ @@ -8204,7 +8216,7 @@ namespace ts { return unknownType; } } - + /** * Returns the effective argument type for the provided argument to a decorator. */ @@ -8222,12 +8234,12 @@ namespace ts { Debug.fail("Decorators should not have a fourth synthetic argument."); return unknownType; } - + /** * Gets the effective argument type for an argument in a call expression. */ function getEffectiveArgumentType(node: CallLikeExpression, argIndex: number, arg: Expression): Type { - // Decorators provide special arguments, a tagged template expression provides + // Decorators provide special arguments, a tagged template expression provides // a special first argument, and string literals get string literal types // unless we're reporting errors if (node.kind === SyntaxKind.Decorator) { @@ -8238,12 +8250,12 @@ namespace ts { } // This is not a synthetic argument, so we return 'undefined' - // to signal that the caller needs to check the argument. + // to signal that the caller needs to check the argument. return undefined; } - + /** - * Gets the effective argument expression for an argument in a call expression. + * Gets the effective argument expression for an argument in a call expression. */ function getEffectiveArgument(node: CallLikeExpression, args: Expression[], argIndex: number) { // For a decorator or the first argument of a tagged template expression we return undefined. @@ -8309,7 +8321,7 @@ namespace ts { // For a tagged template, then the first argument be 'undefined' if necessary // because it represents a TemplateStringsArray. // - // For a decorator, no arguments are susceptible to contextual typing due to the fact + // For a decorator, no arguments are susceptible to contextual typing due to the fact // decorators are applied to a declaration by the emitter, and not to an expression. let excludeArgument: boolean[]; if (!isDecorator) { @@ -8651,7 +8663,7 @@ namespace ts { return resolveCall(node, callSignatures, candidatesOutArray); } - + /** * Gets the localized diagnostic head message to use for errors when resolving a decorator as a call expression. */ @@ -8797,7 +8809,7 @@ namespace ts { links.type = instantiateType(getTypeOfSymbol(lastOrUndefined(context.parameters)), mapper); } } - + function createPromiseType(promisedType: Type): Type { // creates a `Promise` type where `T` is the promisedType argument let globalPromiseType = getGlobalPromiseType(); @@ -8806,7 +8818,7 @@ namespace ts { promisedType = getAwaitedType(promisedType); return createTypeReference(globalPromiseType, [promisedType]); } - + return emptyObjectType; } @@ -8815,15 +8827,15 @@ namespace ts { if (!func.body) { return unknownType; } - + let isAsync = isAsyncFunctionLike(func); let type: Type; if (func.body.kind !== SyntaxKind.Block) { - type = checkExpressionCached(func.body, contextualMapper); + type = checkExpressionCached(func.body, contextualMapper); if (isAsync) { - // From within an async function you can return either a non-promise value or a promise. Any - // Promise/A+ compatible implementation will always assimilate any foreign promise, so the - // return type of the body should be unwrapped to its awaited type, which we will wrap in + // From within an async function you can return either a non-promise value or a promise. Any + // Promise/A+ compatible implementation will always assimilate any foreign promise, so the + // return type of the body should be unwrapped to its awaited type, which we will wrap in // the native Promise type later in this function. type = checkAwaitedType(type, func, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } @@ -8852,13 +8864,13 @@ namespace ts { error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); return unknownType; } - + return promiseType; } else { return voidType; } - } + } } // When yield/return statements are contextually typed we allow the return type to be a union type. // Otherwise we require the yield/return expressions to have a best common supertype. @@ -8881,19 +8893,19 @@ namespace ts { if (!contextualSignature) { reportErrorsFromWidening(func, type); } - + let widenedType = getWidenedType(type); if (isAsync) { - // From within an async function you can return either a non-promise value or a promise. Any - // Promise/A+ compatible implementation will always assimilate any foreign promise, so the + // From within an async function you can return either a non-promise value or a promise. Any + // Promise/A+ compatible implementation will always assimilate any foreign promise, so the // return type of the body is awaited type of the body, wrapped in a native Promise type. let promiseType = createPromiseType(widenedType); if (promiseType === emptyObjectType) { error(func, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); return unknownType; } - - return promiseType; + + return promiseType; } else { return widenedType; @@ -8928,13 +8940,13 @@ namespace ts { forEachReturnStatement(body, returnStatement => { let expr = returnStatement.expression; if (expr) { - let type = checkExpressionCached(expr, contextualMapper); + let type = checkExpressionCached(expr, contextualMapper); if (isAsync) { - // From within an async function you can return either a non-promise value or a promise. Any - // Promise/A+ compatible implementation will always assimilate any foreign promise, so the - // return type of the body should be unwrapped to its awaited type, which should be wrapped in + // From within an async function you can return either a non-promise value or a promise. Any + // Promise/A+ compatible implementation will always assimilate any foreign promise, so the + // return type of the body should be unwrapped to its awaited type, which should be wrapped in // the native Promise type by the caller. - type = checkAwaitedType(type, body.parent, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); + type = checkAwaitedType(type, body.parent, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } if (!contains(aggregatedTypes, type)) { @@ -9006,12 +9018,12 @@ namespace ts { if (contextualMapper === identityMapper && isContextSensitive(node)) { return anyFunctionType; } - + let isAsync = isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; } - + let links = getNodeLinks(node); let type = getTypeOfSymbol(node.symbol); // Check if function expression is contextually typed and assign parameter types if so @@ -9048,7 +9060,7 @@ namespace ts { function checkFunctionExpressionOrObjectLiteralMethodBody(node: FunctionExpression | MethodDeclaration) { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); - + let isAsync = isAsyncFunctionLike(node); if (isAsync) { emitAwaiter = true; @@ -9059,7 +9071,7 @@ namespace ts { if (returnType && isAsync) { promisedType = checkAsyncFunctionReturnType(node); } - + if (returnType && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType); } @@ -9078,10 +9090,10 @@ namespace ts { checkSourceElement(node.body); } else { - // From within an async function you can return either a non-promise value or a promise. Any - // Promise/A+ compatible implementation will always assimilate any foreign promise, so we - // should not be checking assignability of a promise to the return type. Instead, we need to - // check assignability of the awaited type of the expression body against the promised type of + // From within an async function you can return either a non-promise value or a promise. Any + // Promise/A+ compatible implementation will always assimilate any foreign promise, so we + // should not be checking assignability of a promise to the return type. Instead, we need to + // check assignability of the awaited type of the expression body against the promised type of // its return type annotation. let exprType = checkExpression(node.body); if (returnType) { @@ -9093,7 +9105,7 @@ namespace ts { checkTypeAssignableTo(exprType, returnType, node.body); } } - + checkFunctionAndClassExpressionBodies(node.body); } } @@ -9215,7 +9227,7 @@ namespace ts { let operandType = checkExpression(node.expression); return checkAwaitedType(operandType, node); } - + function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type { let operandType = checkExpression(node.operand); switch (node.operator) { @@ -9688,7 +9700,7 @@ namespace ts { node.contextualType = saveContextualType; return result; } - + function checkExpressionCached(node: Expression, contextualMapper?: TypeMapper): Type { let links = getNodeLinks(node); if (!links.resolvedType) { @@ -9895,7 +9907,7 @@ namespace ts { if (node.questionToken && isBindingPattern(node.name) && func.body) { error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature); } - + // Only check rest parameter type if it's not a binding pattern. Since binding patterns are // not allowed in a rest parameter, we already have an error from checkGrammarParameterList. if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) { @@ -10113,7 +10125,7 @@ namespace ts { // Grammar checking for modifiers is done inside the function checkGrammarFunctionLikeDeclaration checkFunctionLikeDeclaration(node); - + // Abstract methods cannot have an implementation. // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. if(node.flags & NodeFlags.Abstract && node.body) { @@ -10548,7 +10560,7 @@ namespace ts { } // Abstract methods can't have an implementation -- in particular, they don't need one. - if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && + if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body && !(lastSeenNonAmbientDeclaration.flags & NodeFlags.Abstract) ) { reportImplementationExpectedError(lastSeenNonAmbientDeclaration); } @@ -10666,13 +10678,13 @@ namespace ts { if (!message) { message = Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member; } - + error(location, message); } - + return unknownType; } - + return type; } @@ -10690,16 +10702,16 @@ namespace ts { // ) => any // ): any; // } - // - + // + if (promise.flags & TypeFlags.Any) { return undefined; } - + if ((promise.flags & TypeFlags.Reference) && (promise).target === tryGetGlobalPromiseType()) { return (promise).typeArguments[0]; } - + let globalPromiseLikeType = getInstantiatedGlobalPromiseLikeType(); if (globalPromiseLikeType === emptyObjectType || !isTypeAssignableTo(promise, globalPromiseLikeType)) { return undefined; @@ -10709,58 +10721,58 @@ namespace ts { if (thenFunction && (thenFunction.flags & TypeFlags.Any)) { return undefined; } - + let thenSignatures = thenFunction ? getSignaturesOfType(thenFunction, SignatureKind.Call) : emptyArray; if (thenSignatures.length === 0) { return undefined; } - + let onfulfilledParameterType = getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)); if (onfulfilledParameterType.flags & TypeFlags.Any) { return undefined; } - + let onfulfilledParameterSignatures = getSignaturesOfType(onfulfilledParameterType, SignatureKind.Call); if (onfulfilledParameterSignatures.length === 0) { return undefined; } - + let valueParameterType = getUnionType(map(onfulfilledParameterSignatures, getTypeOfFirstParameterOfSignature)); return valueParameterType; } - + function getTypeOfFirstParameterOfSignature(signature: Signature) { return getTypeAtPosition(signature, 0); } - + /** * Gets the "awaited type" of a type. * @param type The type to await. - * @remarks The "awaited type" of an expression is its "promised type" if the expression is a + * @remarks The "awaited type" of an expression is its "promised type" if the expression is a * Promise-like type; otherwise, it is the type of the expression. This is used to reflect * The runtime behavior of the `await` keyword. */ function getAwaitedType(type: Type) { return checkAwaitedType(type, /*location*/ undefined, /*message*/ undefined); } - + function checkAwaitedType(type: Type, location?: Node, message?: DiagnosticMessage) { return checkAwaitedTypeWorker(type); - + function checkAwaitedTypeWorker(type: Type): Type { if (type.flags & TypeFlags.Union) { let types: Type[] = []; for (let constituentType of (type).types) { types.push(checkAwaitedTypeWorker(constituentType)); } - + return getUnionType(types); } else { let promisedType = getPromisedType(type); if (promisedType === undefined) { // The type was not a PromiseLike, so it could not be unwrapped any further. - // As long as the type does not have a callable "then" property, it is + // As long as the type does not have a callable "then" property, it is // safe to return the type; otherwise, an error will have been reported in // the call to checkNonThenableType and we will return unknownType. // @@ -10771,7 +10783,7 @@ namespace ts { // The "thenable" does not match the minimal definition for a PromiseLike. When // a Promise/A+-compatible or ES6 promise tries to adopt this value, the promise // will never settle. We treat this as an error to help flag an early indicator - // of a runtime problem. If the user wants to return this value from an async + // of a runtime problem. If the user wants to return this value from an async // function, they would need to wrap it in some other value. If they want it to // be treated as a promise, they can cast to . return checkNonThenableType(type, location, message); @@ -10779,70 +10791,70 @@ namespace ts { else { if (type.id === promisedType.id || awaitedTypeStack.indexOf(promisedType.id) >= 0) { // We have a bad actor in the form of a promise whose promised type is - // the same promise type, or a mutually recursive promise. Return the - // unknown type as we cannot guess the shape. If this were the actual + // the same promise type, or a mutually recursive promise. Return the + // unknown type as we cannot guess the shape. If this were the actual // case in the JavaScript, this Promise would never resolve. // - // An example of a bad actor with a singly-recursive promise type might + // An example of a bad actor with a singly-recursive promise type might // be: // // interface BadPromise { // then( - // onfulfilled: (value: BadPromise) => any, + // onfulfilled: (value: BadPromise) => any, // onrejected: (error: any) => any): BadPromise; // } // - // The above interface will pass the PromiseLike check, and return a - // promised type of `BadPromise`. Since this is a self reference, we + // The above interface will pass the PromiseLike check, and return a + // promised type of `BadPromise`. Since this is a self reference, we // don't want to keep recursing ad infinitum. // - // An example of a bad actor in the form of a mutually-recursive + // An example of a bad actor in the form of a mutually-recursive // promise type might be: // // interface BadPromiseA { // then( - // onfulfilled: (value: BadPromiseB) => any, + // onfulfilled: (value: BadPromiseB) => any, // onrejected: (error: any) => any): BadPromiseB; // } // // interface BadPromiseB { // then( - // onfulfilled: (value: BadPromiseA) => any, + // onfulfilled: (value: BadPromiseA) => any, // onrejected: (error: any) => any): BadPromiseA; // } // if (location) { error( - location, - Diagnostics._0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method, + location, + Diagnostics._0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method, symbolToString(type.symbol)); } - + return unknownType; } - + // Keep track of the type we're about to unwrap to avoid bad recursive promise types. // See the comments above for more information. awaitedTypeStack.push(type.id); let awaitedType = checkAwaitedTypeWorker(promisedType); awaitedTypeStack.pop(); - return awaitedType; + return awaitedType; } } } } /** - * Checks the return type of an async function to ensure it is a compatible + * Checks the return type of an async function to ensure it is a compatible * Promise implementation. * @param node The signature to check * @param returnType The return type for the function - * @remarks - * This checks that an async function has a valid Promise-compatible return type, - * and returns the *awaited type* of the promise. An async function has a valid - * Promise-compatible return type if the resolved value of the return type has a + * @remarks + * This checks that an async function has a valid Promise-compatible return type, + * and returns the *awaited type* of the promise. An async function has a valid + * Promise-compatible return type if the resolved value of the return type has a * construct signature that takes in an `initializer` function that in turn supplies - * a `resolve` function as one of its arguments and results in an object with a + * a `resolve` function as one of its arguments and results in an object with a * callable `then` signature. */ function checkAsyncFunctionReturnType(node: FunctionLikeDeclaration): Type { @@ -10855,7 +10867,7 @@ namespace ts { // As part of our emit for an async function, we will need to emit the entity name of // the return type annotation as an expression. To meet the necessary runtime semantics - // for __awaiter, we must also check that the type of the declaration (e.g. the static + // for __awaiter, we must also check that the type of the declaration (e.g. the static // side or "constructor" of the promise type) is compatible `PromiseConstructorLike`. // // An example might be (from lib.es6.d.ts): @@ -10863,11 +10875,11 @@ namespace ts { // interface Promise { ... } // interface PromiseConstructor { // new (...): Promise; - // } + // } // declare var Promise: PromiseConstructor; // - // When an async function declares a return type annotation of `Promise`, we - // need to get the type of the `Promise` variable declaration above, which would + // When an async function declares a return type annotation of `Promise`, we + // need to get the type of the `Promise` variable declaration above, which would // be `PromiseConstructor`. // // The same case applies to a class: @@ -10879,20 +10891,20 @@ namespace ts { // // When we get the type of the `Promise` symbol here, we get the type of the static // side of the `Promise` class, which would be `{ new (...): Promise }`. - + let promiseType = getTypeFromTypeNode(node.type); if (promiseType === unknownType && compilerOptions.isolatedModules) { - // If we are compiling with isolatedModules, we may not be able to resolve the + // If we are compiling with isolatedModules, we may not be able to resolve the // type as a value. As such, we will just return unknownType; return unknownType; } - + let promiseConstructor = getMergedSymbol(promiseType.symbol); if (!promiseConstructor || !symbolIsValue(promiseConstructor)) { error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType)); return unknownType } - + // Validate the promise constructor type. let promiseConstructorType = getTypeOfSymbol(promiseConstructor); if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) { @@ -10913,7 +10925,7 @@ namespace ts { // Get and return the awaited type of the return type. return checkAwaitedType(promiseType, node, Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type); } - + /** Check a decorator */ function checkDecorator(node: Decorator): void { let signature = getResolvedSignature(node); @@ -10963,11 +10975,11 @@ namespace ts { headMessage, errorInfo); } - + /** Checks a type reference node as an expression. */ function checkTypeNodeAsExpression(node: TypeNode) { // When we are emitting type metadata for decorators, we need to try to check the type - // as if it were an expression so that we can emit the type in a value position when we + // as if it were an expression so that we can emit the type in a value position when we // serialize the type metadata. if (node && node.kind === SyntaxKind.TypeReference) { let type = getTypeFromTypeNode(node); @@ -10982,7 +10994,7 @@ namespace ts { } /** - * Checks the type annotation of an accessor declaration or property declaration as + * Checks the type annotation of an accessor declaration or property declaration as * an expression if it is a type reference to a type with a value declaration. */ function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration | ParameterDeclaration | MethodDeclaration) { @@ -11004,7 +11016,7 @@ namespace ts { break; } } - + /** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */ function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) { // ensure all type annotations with a value declaration are checked as an expression @@ -11078,9 +11090,9 @@ namespace ts { if (!compilerOptions.experimentalAsyncFunctions) { error(node, Diagnostics.Experimental_support_for_async_functions_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalAsyncFunctions_to_remove_this_warning); } - + emitAwaiter = true; - } + } // Do not use hasDynamicName here, because that returns false for well known symbols. // We want to perform checkComputedPropertyName for all computed properties, including @@ -11120,7 +11132,7 @@ namespace ts { if (isAsync) { promisedType = checkAsyncFunctionReturnType(node); } - + checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, isAsync ? promisedType : returnType); } @@ -11332,7 +11344,7 @@ namespace ts { } } } - + // Check that a parameter initializer contains no references to parameters declared to the right of itself function checkParameterInitializer(node: VariableLikeDeclaration): void { if (getRootDeclaration(node).kind !== SyntaxKind.Parameter) { @@ -11653,7 +11665,7 @@ namespace ts { return elementType || anyType; } - + /** * We want to treat type as an iterable, and get the type it is an iterable of. The iterable * must have the following structure (annotated with the names of the variables below): @@ -12280,20 +12292,20 @@ namespace ts { // In order to resolve whether the inherited method was overriden in the base class or not, // we compare the Symbols obtained. Since getTargetSymbol returns the symbol on the *uninstantiated* // type declaration, derived and base resolve to the same symbol even in the case of generic classes. - if (derived === base) { + if (derived === base) { // derived class inherits base without override/redeclaration let derivedClassDecl = getDeclarationOfKind(type.symbol, SyntaxKind.ClassDeclaration); // It is an error to inherit an abstract member without implementing it or being declared abstract. - // If there is no declaration for the derived class (as in the case of class expressions), - // then the class cannot be declared abstract. + // If there is no declaration for the derived class (as in the case of class expressions), + // then the class cannot be declared abstract. if ( baseDeclarationFlags & NodeFlags.Abstract && (!derivedClassDecl || !(derivedClassDecl.flags & NodeFlags.Abstract))) { error(derivedClassDecl, Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2, typeToString(type), symbolToString(baseProperty), typeToString(baseType)); } } - else { + else { // derived overrides base. let derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); if ((baseDeclarationFlags & NodeFlags.Private) || (derivedDeclarationFlags & NodeFlags.Private)) { @@ -12764,7 +12776,7 @@ namespace ts { } } - // if the module merges with a class declaration in the same lexical scope, + // if the module merges with a class declaration in the same lexical scope, // we need to track this to ensure the correct emit. let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration); if (mergedClass && @@ -13298,7 +13310,7 @@ namespace ts { forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope); potentialThisCollisions.length = 0; } - + if (emitExtends) { links.flags |= NodeCheckFlags.EmitExtends; } @@ -13310,11 +13322,11 @@ namespace ts { if (emitParam) { links.flags |= NodeCheckFlags.EmitParam; } - + if (emitAwaiter) { links.flags |= NodeCheckFlags.EmitAwaiter; } - + if (emitGenerator || (emitAwaiter && languageVersion < ScriptTarget.ES6)) { links.flags |= NodeCheckFlags.EmitGenerator; } @@ -13713,7 +13725,7 @@ namespace ts { } /** - * Gets either the static or instance type of a class element, based on + * Gets either the static or instance type of a class element, based on * whether the element is declared as "static". */ function getParentTypeOfClassElement(node: ClassElement) { @@ -13722,7 +13734,7 @@ namespace ts { ? getTypeOfSymbol(classSymbol) : getDeclaredTypeOfSymbol(classSymbol); } - + // Return the list of properties of the given type, augmented with properties from Function // if the type has call or construct signatures function getAugmentedPropertiesOfType(type: Type): Symbol[] { @@ -14061,7 +14073,7 @@ namespace ts { // * The serialized type of an AccessorDeclaration is the serialized type of the return type annotation of its getter or parameter type annotation of its setter. // * The serialized type of any other FunctionLikeDeclaration is "Function". // * The serialized type of any other node is "void 0". - // + // // For rules on serializing type annotations, see `serializeTypeNode`. switch (node.kind) { case SyntaxKind.ClassDeclaration: return "Function"; @@ -14075,14 +14087,14 @@ namespace ts { } return "void 0"; } - + /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ function serializeParameterTypesOfNode(node: Node): (string | string[])[] { // serialization of parameter types uses the following rules: // // * If the declaration is a class, the parameters of the first constructor with a body are used. // * If the declaration is function-like and has a body, the parameters of the function are used. - // + // // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. if (node) { var valueDeclaration: FunctionLikeDeclaration; @@ -14299,21 +14311,21 @@ namespace ts { anyArrayType = createArrayType(anyType); } - + function createInstantiatedPromiseLikeType(): ObjectType { let promiseLikeType = getGlobalPromiseLikeType(); if (promiseLikeType !== emptyObjectType) { return createTypeReference(promiseLikeType, [anyType]); } - + return emptyObjectType; } - + function createThenableType() { // build the thenable type that is used to verify against a non-promise "thenable" operand to `await`. let thenPropertySymbol = createSymbol(SymbolFlags.Transient | SymbolFlags.Property, "then"); getSymbolLinks(thenPropertySymbol).type = globalFunctionType; - + let thenableType = createObjectType(TypeFlags.Anonymous); thenableType.properties = [thenPropertySymbol]; thenableType.members = createSymbolTable(thenableType.properties); diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 3db032b8d0d..97c85c70de1 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -401,7 +401,7 @@ namespace ts { } function emitTypePredicate(type: TypePredicateNode) { - writeEntityName(type.parameterName); + writeTextOfNode(currentSourceFile, type.parameterName); write(" is "); emitType(type.type); } diff --git a/tests/cases/compiler/declFileFunctions.ts b/tests/cases/compiler/declFileFunctions.ts index 36972d427f0..7b9c55e9214 100644 --- a/tests/cases/compiler/declFileFunctions.ts +++ b/tests/cases/compiler/declFileFunctions.ts @@ -31,6 +31,15 @@ export function fooWithSingleOverload(a: any) { export function fooWithTypePredicate(a: any): a is number { return true; } +export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number { + return true; +} +export function fooWithTypeTypePredicateAndGeneric(a: any): a is T { + return true; +} +export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number { + return true; +} /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { diff --git a/tests/cases/fourslash/signatureHelpOnTypePredicates.ts b/tests/cases/fourslash/signatureHelpOnTypePredicates.ts new file mode 100644 index 00000000000..bfaa7df2502 --- /dev/null +++ b/tests/cases/fourslash/signatureHelpOnTypePredicates.ts @@ -0,0 +1,20 @@ +/// + +//// function f1(a: any): a is number {} +//// function f2(a: any): a is T {} +//// function f3(a: any, ...b): a is number {} +//// f1(/*1*/) +//// f2(/*2*/) +//// f3(/*3*/) + +goTo.marker("1"); +verify.signatureHelpCountIs(1); +verify.currentSignatureHelpIs("f1(a: any): a is number"); + +goTo.marker("2"); +verify.signatureHelpCountIs(1); +verify.currentSignatureHelpIs("f2(a: any): a is T"); + +goTo.marker("3"); +verify.signatureHelpCountIs(1); +verify.currentSignatureHelpIs("f3(a: any, ...b: any[]): a is number"); \ No newline at end of file From 52b1496a64d0e2ece12834668b295e519b2d9e25 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Thu, 9 Jul 2015 11:48:42 +0800 Subject: [PATCH 68/88] Accepts baselines --- .../baselines/reference/declFileFunctions.js | 28 +++++++++ .../reference/declFileFunctions.symbols | 62 +++++++++++++------ .../reference/declFileFunctions.types | 31 +++++++++- tests/baselines/reference/isArray.types | 4 +- .../reference/typeGuardFunction.types | 46 +++++++------- .../typeGuardFunctionErrors.errors.txt | 16 ++--- .../reference/typeGuardFunctionGenerics.types | 34 +++++----- .../reference/typeGuardOfFormIsType.types | 22 +++---- .../typeGuardOfFormIsTypeOnInterfaces.types | 22 +++---- 9 files changed, 174 insertions(+), 91 deletions(-) diff --git a/tests/baselines/reference/declFileFunctions.js b/tests/baselines/reference/declFileFunctions.js index d3debf4d50c..163fa1905c8 100644 --- a/tests/baselines/reference/declFileFunctions.js +++ b/tests/baselines/reference/declFileFunctions.js @@ -29,6 +29,15 @@ export function fooWithSingleOverload(a: any) { export function fooWithTypePredicate(a: any): a is number { return true; } +export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number { + return true; +} +export function fooWithTypeTypePredicateAndGeneric(a: any): a is T { + return true; +} +export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number { + return true; +} /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { @@ -100,6 +109,22 @@ function fooWithTypePredicate(a) { return true; } exports.fooWithTypePredicate = fooWithTypePredicate; +function fooWithTypePredicateAndMulitpleParams(a, b, c) { + return true; +} +exports.fooWithTypePredicateAndMulitpleParams = fooWithTypePredicateAndMulitpleParams; +function fooWithTypeTypePredicateAndGeneric(a) { + return true; +} +exports.fooWithTypeTypePredicateAndGeneric = fooWithTypeTypePredicateAndGeneric; +function fooWithTypeTypePredicateAndRestParam(a) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + return true; +} +exports.fooWithTypeTypePredicateAndRestParam = fooWithTypeTypePredicateAndRestParam; /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { } @@ -153,6 +178,9 @@ export declare function fooWithOverloads(a: string): string; export declare function fooWithOverloads(a: number): number; export declare function fooWithSingleOverload(a: string): string; export declare function fooWithTypePredicate(a: any): a is number; +export declare function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number; +export declare function fooWithTypeTypePredicateAndGeneric(a: any): a is T; +export declare function fooWithTypeTypePredicateAndRestParam(a: any, ...rest: any[]): a is number; //// [declFileFunctions_1.d.ts] /** This comment should appear for foo*/ declare function globalfoo(): void; diff --git a/tests/baselines/reference/declFileFunctions.symbols b/tests/baselines/reference/declFileFunctions.symbols index 1d62cc29d28..1853da94a46 100644 --- a/tests/baselines/reference/declFileFunctions.symbols +++ b/tests/baselines/reference/declFileFunctions.symbols @@ -64,50 +64,76 @@ export function fooWithTypePredicate(a: any): a is number { return true; } +export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number { +>fooWithTypePredicateAndMulitpleParams : Symbol(fooWithTypePredicateAndMulitpleParams, Decl(declFileFunctions_0.ts, 27, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 28, 54)) +>b : Symbol(b, Decl(declFileFunctions_0.ts, 28, 61)) +>c : Symbol(c, Decl(declFileFunctions_0.ts, 28, 69)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 28, 54)) + + return true; +} +export function fooWithTypeTypePredicateAndGeneric(a: any): a is T { +>fooWithTypeTypePredicateAndGeneric : Symbol(fooWithTypeTypePredicateAndGeneric, Decl(declFileFunctions_0.ts, 30, 1)) +>T : Symbol(T, Decl(declFileFunctions_0.ts, 31, 51)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 31, 54)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 31, 54)) +>T : Symbol(T, Decl(declFileFunctions_0.ts, 31, 51)) + + return true; +} +export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number { +>fooWithTypeTypePredicateAndRestParam : Symbol(fooWithTypeTypePredicateAndRestParam, Decl(declFileFunctions_0.ts, 33, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 34, 53)) +>rest : Symbol(rest, Decl(declFileFunctions_0.ts, 34, 60)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 34, 53)) + + return true; +} /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { ->nonExportedFoo : Symbol(nonExportedFoo, Decl(declFileFunctions_0.ts, 27, 1)) +>nonExportedFoo : Symbol(nonExportedFoo, Decl(declFileFunctions_0.ts, 36, 1)) } /** This is comment for function signature*/ function nonExportedFooWithParameters(/** this is comment about a*/a: string, ->nonExportedFooWithParameters : Symbol(nonExportedFooWithParameters, Decl(declFileFunctions_0.ts, 31, 1)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 33, 38)) +>nonExportedFooWithParameters : Symbol(nonExportedFooWithParameters, Decl(declFileFunctions_0.ts, 40, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 42, 38)) /** this is comment for b*/ b: number) { ->b : Symbol(b, Decl(declFileFunctions_0.ts, 33, 77)) +>b : Symbol(b, Decl(declFileFunctions_0.ts, 42, 77)) var d = a; ->d : Symbol(d, Decl(declFileFunctions_0.ts, 36, 7)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 33, 38)) +>d : Symbol(d, Decl(declFileFunctions_0.ts, 45, 7)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 42, 38)) } function nonExportedFooWithRestParameters(a: string, ...rests: string[]) { ->nonExportedFooWithRestParameters : Symbol(nonExportedFooWithRestParameters, Decl(declFileFunctions_0.ts, 37, 1)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 38, 42)) ->rests : Symbol(rests, Decl(declFileFunctions_0.ts, 38, 52)) +>nonExportedFooWithRestParameters : Symbol(nonExportedFooWithRestParameters, Decl(declFileFunctions_0.ts, 46, 1)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 47, 42)) +>rests : Symbol(rests, Decl(declFileFunctions_0.ts, 47, 52)) return a + rests.join(""); ->a : Symbol(a, Decl(declFileFunctions_0.ts, 38, 42)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 47, 42)) >rests.join : Symbol(Array.join, Decl(lib.d.ts, 1035, 31)) ->rests : Symbol(rests, Decl(declFileFunctions_0.ts, 38, 52)) +>rests : Symbol(rests, Decl(declFileFunctions_0.ts, 47, 52)) >join : Symbol(Array.join, Decl(lib.d.ts, 1035, 31)) } function nonExportedFooWithOverloads(a: string): string; ->nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 40, 1), Decl(declFileFunctions_0.ts, 42, 56), Decl(declFileFunctions_0.ts, 43, 56)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 42, 37)) +>nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 49, 1), Decl(declFileFunctions_0.ts, 51, 56), Decl(declFileFunctions_0.ts, 52, 56)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 51, 37)) function nonExportedFooWithOverloads(a: number): number; ->nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 40, 1), Decl(declFileFunctions_0.ts, 42, 56), Decl(declFileFunctions_0.ts, 43, 56)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 43, 37)) +>nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 49, 1), Decl(declFileFunctions_0.ts, 51, 56), Decl(declFileFunctions_0.ts, 52, 56)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 52, 37)) function nonExportedFooWithOverloads(a: any): any { ->nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 40, 1), Decl(declFileFunctions_0.ts, 42, 56), Decl(declFileFunctions_0.ts, 43, 56)) ->a : Symbol(a, Decl(declFileFunctions_0.ts, 44, 37)) +>nonExportedFooWithOverloads : Symbol(nonExportedFooWithOverloads, Decl(declFileFunctions_0.ts, 49, 1), Decl(declFileFunctions_0.ts, 51, 56), Decl(declFileFunctions_0.ts, 52, 56)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 53, 37)) return a; ->a : Symbol(a, Decl(declFileFunctions_0.ts, 44, 37)) +>a : Symbol(a, Decl(declFileFunctions_0.ts, 53, 37)) } === tests/cases/compiler/declFileFunctions_1.ts === diff --git a/tests/baselines/reference/declFileFunctions.types b/tests/baselines/reference/declFileFunctions.types index e6ecc53b043..9ad974463b7 100644 --- a/tests/baselines/reference/declFileFunctions.types +++ b/tests/baselines/reference/declFileFunctions.types @@ -61,13 +61,42 @@ export function fooWithSingleOverload(a: any) { } export function fooWithTypePredicate(a: any): a is number { ->fooWithTypePredicate : (a: any) => boolean +>fooWithTypePredicate : (a: any) => a is number >a : any >a : any return true; >true : boolean } +export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number { +>fooWithTypePredicateAndMulitpleParams : (a: any, b: any, c: any) => a is number +>a : any +>b : any +>c : any +>a : any + + return true; +>true : boolean +} +export function fooWithTypeTypePredicateAndGeneric(a: any): a is T { +>fooWithTypeTypePredicateAndGeneric : (a: any) => a is T +>T : T +>a : any +>a : any +>T : T + + return true; +>true : boolean +} +export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number { +>fooWithTypeTypePredicateAndRestParam : (a: any, ...rest: any[]) => a is number +>a : any +>rest : any[] +>a : any + + return true; +>true : boolean +} /** This comment should appear for nonExportedFoo*/ function nonExportedFoo() { diff --git a/tests/baselines/reference/isArray.types b/tests/baselines/reference/isArray.types index 8865ff73bc0..bc452b12bef 100644 --- a/tests/baselines/reference/isArray.types +++ b/tests/baselines/reference/isArray.types @@ -5,9 +5,9 @@ var maybeArray: number | number[]; if (Array.isArray(maybeArray)) { >Array.isArray(maybeArray) : boolean ->Array.isArray : (arg: any) => boolean +>Array.isArray : (arg: any) => arg is any[] >Array : ArrayConstructor ->isArray : (arg: any) => boolean +>isArray : (arg: any) => arg is any[] >maybeArray : number | number[] maybeArray.length; // OK diff --git a/tests/baselines/reference/typeGuardFunction.types b/tests/baselines/reference/typeGuardFunction.types index cf673f965f9..6cc278f122f 100644 --- a/tests/baselines/reference/typeGuardFunction.types +++ b/tests/baselines/reference/typeGuardFunction.types @@ -23,19 +23,19 @@ class C extends A { } declare function isA(p1: any): p1 is A; ->isA : (p1: any) => boolean +>isA : (p1: any) => p1 is A >p1 : any >p1 : any >A : A declare function isB(p1: any): p1 is B; ->isB : (p1: any) => boolean +>isB : (p1: any) => p1 is B >p1 : any >p1 : any >B : B declare function isC(p1: any): p1 is C; ->isC : (p1: any) => boolean +>isC : (p1: any) => p1 is C >p1 : any >p1 : any >C : C @@ -55,7 +55,7 @@ var b: B; // Basic if (isC(a)) { >isC(a) : boolean ->isC : (p1: any) => boolean +>isC : (p1: any) => p1 is C >a : A a.propC; @@ -71,7 +71,7 @@ var subType: C; if(isA(subType)) { >isA(subType) : boolean ->isA : (p1: any) => boolean +>isA : (p1: any) => p1 is A >subType : C subType.propC; @@ -88,7 +88,7 @@ var union: A | B; if(isA(union)) { >isA(union) : boolean ->isA : (p1: any) => boolean +>isA : (p1: any) => p1 is A >union : A | B union.propA; @@ -111,7 +111,7 @@ interface I1 { // The parameter index and argument index for the type guard target is matching. // The type predicate type is assignable to the parameter type. declare function isC_multipleParams(p1, p2): p1 is C; ->isC_multipleParams : (p1: any, p2: any) => boolean +>isC_multipleParams : (p1: any, p2: any) => p1 is C >p1 : any >p2 : any >p1 : any @@ -119,7 +119,7 @@ declare function isC_multipleParams(p1, p2): p1 is C; if (isC_multipleParams(a, 0)) { >isC_multipleParams(a, 0) : boolean ->isC_multipleParams : (p1: any, p2: any) => boolean +>isC_multipleParams : (p1: any, p2: any) => p1 is C >a : A >0 : number @@ -131,10 +131,10 @@ if (isC_multipleParams(a, 0)) { // Methods var obj: { ->obj : { func1(p1: A): boolean; } +>obj : { func1(p1: A): p1 is C; } func1(p1: A): p1 is C; ->func1 : (p1: A) => boolean +>func1 : (p1: A) => p1 is C >p1 : A >A : A >p1 : any @@ -144,7 +144,7 @@ class D { >D : D method1(p1: A): p1 is C { ->method1 : (p1: A) => boolean +>method1 : (p1: A) => p1 is C >p1 : A >A : A >p1 : any @@ -157,8 +157,8 @@ class D { // Arrow function let f1 = (p1: A): p1 is C => false; ->f1 : (p1: A) => boolean ->(p1: A): p1 is C => false : (p1: A) => boolean +>f1 : (p1: A) => p1 is C +>(p1: A): p1 is C => false : (p1: A) => p1 is C >p1 : A >A : A >p1 : any @@ -167,8 +167,8 @@ let f1 = (p1: A): p1 is C => false; // Function type declare function f2(p1: (p1: A) => p1 is C); ->f2 : (p1: (p1: A) => boolean) => any ->p1 : (p1: A) => boolean +>f2 : (p1: (p1: A) => p1 is C) => any +>p1 : (p1: A) => p1 is C >p1 : A >A : A >p1 : any @@ -177,8 +177,8 @@ declare function f2(p1: (p1: A) => p1 is C); // Function expressions f2(function(p1: A): p1 is C { >f2(function(p1: A): p1 is C { return true;}) : any ->f2 : (p1: (p1: A) => boolean) => any ->function(p1: A): p1 is C { return true;} : (p1: A) => boolean +>f2 : (p1: (p1: A) => p1 is C) => any +>function(p1: A): p1 is C { return true;} : (p1: A) => p1 is C >p1 : A >A : A >p1 : any @@ -198,21 +198,21 @@ acceptingBoolean(isA(a)); >acceptingBoolean(isA(a)) : any >acceptingBoolean : (a: boolean) => any >isA(a) : boolean ->isA : (p1: any) => boolean +>isA : (p1: any) => p1 is A >a : A // Type predicates with different parameter name. declare function acceptingTypeGuardFunction(p1: (item) => item is A); ->acceptingTypeGuardFunction : (p1: (item: any) => boolean) => any ->p1 : (item: any) => boolean +>acceptingTypeGuardFunction : (p1: (item: any) => item is A) => any +>p1 : (item: any) => item is A >item : any >item : any >A : A acceptingTypeGuardFunction(isA); >acceptingTypeGuardFunction(isA) : any ->acceptingTypeGuardFunction : (p1: (item: any) => boolean) => any ->isA : (p1: any) => boolean +>acceptingTypeGuardFunction : (p1: (item: any) => item is A) => any +>isA : (p1: any) => p1 is A // Binary expressions let union2: C | B; @@ -225,7 +225,7 @@ let union3: boolean | B = isA(union2) || union2; >B : B >isA(union2) || union2 : boolean | B >isA(union2) : boolean ->isA : (p1: any) => boolean +>isA : (p1: any) => p1 is A >union2 : B | C >union2 : B diff --git a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt index 499a51035f2..b178b02c6b4 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt +++ b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt @@ -12,15 +12,15 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(46,56) tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(60,7): error TS2339: Property 'propB' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(65,7): error TS2339: Property 'propB' does not exist on type 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(70,7): error TS2339: Property 'propB' does not exist on type 'A'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(75,46): error TS2345: Argument of type '(p1: any) => boolean' is not assignable to parameter of type '(p1: any) => boolean'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(75,46): error TS2345: Argument of type '(p1: any) => p1 is C' is not assignable to parameter of type '(p1: any) => p1 is B'. Type predicate 'p1 is C' is not assignable to 'p1 is B'. Type 'C' is not assignable to type 'B'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(79,1): error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(79,1): error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => p1 is A'. Signature '(p1: any, p2: any): boolean' must have a type predicate. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(85,1): error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(85,1): error TS2322: Type '(p1: any, p2: any) => p2 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'. Type predicate 'p2 is A' is not assignable to 'p1 is A'. Parameter 'p2' is not in the same position as parameter 'p1'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(91,1): error TS2322: Type '(p1: any, p2: any, p3: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(91,1): error TS2322: Type '(p1: any, p2: any, p3: any) => p1 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,9): error TS1228: A type predicate is only allowed in return type position for functions and methods. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,16): error TS1228: A type predicate is only allowed in return type position for functions and methods. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(98,20): error TS1228: A type predicate is only allowed in return type position for functions and methods. @@ -141,7 +141,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 declare function acceptingDifferentSignatureTypeGuardFunction(p1: (p1) => p1 is B); acceptingDifferentSignatureTypeGuardFunction(isC); ~~~ -!!! error TS2345: Argument of type '(p1: any) => boolean' is not assignable to parameter of type '(p1: any) => boolean'. +!!! error TS2345: Argument of type '(p1: any) => p1 is C' is not assignable to parameter of type '(p1: any) => p1 is B'. !!! error TS2345: Type predicate 'p1 is C' is not assignable to 'p1 is B'. !!! error TS2345: Type 'C' is not assignable to type 'B'. @@ -149,7 +149,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 var assign1: (p1, p2) => p1 is A; assign1 = function(p1, p2): boolean { ~~~~~~~ -!!! error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. +!!! error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => p1 is A'. !!! error TS2322: Signature '(p1: any, p2: any): boolean' must have a type predicate. return true; }; @@ -158,7 +158,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 var assign2: (p1, p2) => p1 is A; assign2 = function(p1, p2): p2 is A { ~~~~~~~ -!!! error TS2322: Type '(p1: any, p2: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. +!!! error TS2322: Type '(p1: any, p2: any) => p2 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'. !!! error TS2322: Type predicate 'p2 is A' is not assignable to 'p1 is A'. !!! error TS2322: Parameter 'p2' is not in the same position as parameter 'p1'. return true; @@ -168,7 +168,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(137,39 var assign3: (p1, p2) => p1 is A; assign3 = function(p1, p2, p3): p1 is A { ~~~~~~~ -!!! error TS2322: Type '(p1: any, p2: any, p3: any) => boolean' is not assignable to type '(p1: any, p2: any) => boolean'. +!!! error TS2322: Type '(p1: any, p2: any, p3: any) => p1 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'. return true; }; diff --git a/tests/baselines/reference/typeGuardFunctionGenerics.types b/tests/baselines/reference/typeGuardFunctionGenerics.types index 77162e55a40..c4655e71f0c 100644 --- a/tests/baselines/reference/typeGuardFunctionGenerics.types +++ b/tests/baselines/reference/typeGuardFunctionGenerics.types @@ -23,13 +23,13 @@ class C extends A { } declare function isB(p1): p1 is B; ->isB : (p1: any) => boolean +>isB : (p1: any) => p1 is B >p1 : any >p1 : any >B : B declare function isC(p1): p1 is C; ->isC : (p1: any) => boolean +>isC : (p1: any) => p1 is C >p1 : any >p1 : any >C : C @@ -48,7 +48,7 @@ declare function funA(p1: (p1) => T): T; >T : T declare function funB(p1: (p1) => T, p2: any): p2 is T; ->funB : (p1: (p1: any) => T, p2: any) => boolean +>funB : (p1: (p1: any) => T, p2: any) => p2 is T >T : T >p1 : (p1: any) => T >p1 : any @@ -58,18 +58,18 @@ declare function funB(p1: (p1) => T, p2: any): p2 is T; >T : T declare function funC(p1: (p1) => p1 is T): T; ->funC : (p1: (p1: any) => boolean) => T +>funC : (p1: (p1: any) => p1 is T) => T >T : T ->p1 : (p1: any) => boolean +>p1 : (p1: any) => p1 is T >p1 : any >p1 : any >T : T >T : T declare function funD(p1: (p1) => p1 is T, p2: any): p2 is T; ->funD : (p1: (p1: any) => boolean, p2: any) => boolean +>funD : (p1: (p1: any) => p1 is T, p2: any) => p2 is T >T : T ->p1 : (p1: any) => boolean +>p1 : (p1: any) => p1 is T >p1 : any >p1 : any >T : T @@ -78,10 +78,10 @@ declare function funD(p1: (p1) => p1 is T, p2: any): p2 is T; >T : T declare function funE(p1: (p1) => p1 is T, p2: U): T; ->funE : (p1: (p1: any) => boolean, p2: U) => T +>funE : (p1: (p1: any) => p1 is T, p2: U) => T >T : T >U : U ->p1 : (p1: any) => boolean +>p1 : (p1: any) => p1 is T >p1 : any >p1 : any >T : T @@ -97,11 +97,11 @@ let test1: boolean = funA(isB); >test1 : boolean >funA(isB) : boolean >funA : (p1: (p1: any) => T) => T ->isB : (p1: any) => boolean +>isB : (p1: any) => p1 is B if (funB(retC, a)) { >funB(retC, a) : boolean ->funB : (p1: (p1: any) => T, p2: any) => boolean +>funB : (p1: (p1: any) => T, p2: any) => p2 is T >retC : (x: any) => C >a : A @@ -114,13 +114,13 @@ let test2: B = funC(isB); >test2 : B >B : B >funC(isB) : B ->funC : (p1: (p1: any) => boolean) => T ->isB : (p1: any) => boolean +>funC : (p1: (p1: any) => p1 is T) => T +>isB : (p1: any) => p1 is B if (funD(isC, a)) { >funD(isC, a) : boolean ->funD : (p1: (p1: any) => boolean, p2: any) => boolean ->isC : (p1: any) => boolean +>funD : (p1: (p1: any) => p1 is T, p2: any) => p2 is T +>isC : (p1: any) => p1 is C >a : A a.propC; @@ -132,7 +132,7 @@ let test3: B = funE(isB, 1); >test3 : B >B : B >funE(isB, 1) : B ->funE : (p1: (p1: any) => boolean, p2: U) => T ->isB : (p1: any) => boolean +>funE : (p1: (p1: any) => p1 is T, p2: U) => T +>isB : (p1: any) => p1 is B >1 : number diff --git a/tests/baselines/reference/typeGuardOfFormIsType.types b/tests/baselines/reference/typeGuardOfFormIsType.types index b14e5e22910..e2059be7b63 100644 --- a/tests/baselines/reference/typeGuardOfFormIsType.types +++ b/tests/baselines/reference/typeGuardOfFormIsType.types @@ -29,7 +29,7 @@ var strOrNum: string | number; >strOrNum : string | number function isC1(x: any): x is C1 { ->isC1 : (x: any) => boolean +>isC1 : (x: any) => x is C1 >x : any >x : any >C1 : C1 @@ -39,7 +39,7 @@ function isC1(x: any): x is C1 { } function isC2(x: any): x is C2 { ->isC2 : (x: any) => boolean +>isC2 : (x: any) => x is C2 >x : any >x : any >C2 : C2 @@ -49,7 +49,7 @@ function isC2(x: any): x is C2 { } function isD1(x: any): x is D1 { ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >x : any >x : any >D1 : D1 @@ -68,7 +68,7 @@ str = isC1(c1Orc2) && c1Orc2.p1; // C1 >str : string >isC1(c1Orc2) && c1Orc2.p1 : string >isC1(c1Orc2) : boolean ->isC1 : (x: any) => boolean +>isC1 : (x: any) => x is C1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string >c1Orc2 : C1 @@ -79,7 +79,7 @@ num = isC2(c1Orc2) && c1Orc2.p2; // C2 >num : number >isC2(c1Orc2) && c1Orc2.p2 : number >isC2(c1Orc2) : boolean ->isC2 : (x: any) => boolean +>isC2 : (x: any) => x is C2 >c1Orc2 : C1 | C2 >c1Orc2.p2 : number >c1Orc2 : C2 @@ -90,7 +90,7 @@ str = isD1(c1Orc2) && c1Orc2.p1; // D1 >str : string >isD1(c1Orc2) && c1Orc2.p1 : string >isD1(c1Orc2) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string >c1Orc2 : D1 @@ -101,7 +101,7 @@ num = isD1(c1Orc2) && c1Orc2.p3; // D1 >num : number >isD1(c1Orc2) && c1Orc2.p3 : number >isD1(c1Orc2) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p3 : number >c1Orc2 : D1 @@ -117,7 +117,7 @@ num = isC2(c2Ord1) && c2Ord1.p2; // C2 >num : number >isC2(c2Ord1) && c2Ord1.p2 : number >isC2(c2Ord1) : boolean ->isC2 : (x: any) => boolean +>isC2 : (x: any) => x is C2 >c2Ord1 : C2 | D1 >c2Ord1.p2 : number >c2Ord1 : C2 @@ -128,7 +128,7 @@ num = isD1(c2Ord1) && c2Ord1.p3; // D1 >num : number >isD1(c2Ord1) && c2Ord1.p3 : number >isD1(c2Ord1) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p3 : number >c2Ord1 : D1 @@ -139,7 +139,7 @@ str = isD1(c2Ord1) && c2Ord1.p1; // D1 >str : string >isD1(c2Ord1) && c2Ord1.p1 : string >isD1(c2Ord1) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p1 : string >c2Ord1 : D1 @@ -151,7 +151,7 @@ var r2: C2 | D1 = isC1(c2Ord1) && c2Ord1; // C2 | D1 >D1 : D1 >isC1(c2Ord1) && c2Ord1 : D1 >isC1(c2Ord1) : boolean ->isC1 : (x: any) => boolean +>isC1 : (x: any) => x is C1 >c2Ord1 : C2 | D1 >c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types index 3a659d71163..ea169e95413 100644 --- a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types +++ b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types @@ -48,7 +48,7 @@ var strOrNum: string | number; function isC1(x: any): x is C1 { ->isC1 : (x: any) => boolean +>isC1 : (x: any) => x is C1 >x : any >x : any >C1 : C1 @@ -58,7 +58,7 @@ function isC1(x: any): x is C1 { } function isC2(x: any): x is C2 { ->isC2 : (x: any) => boolean +>isC2 : (x: any) => x is C2 >x : any >x : any >C2 : C2 @@ -68,7 +68,7 @@ function isC2(x: any): x is C2 { } function isD1(x: any): x is D1 { ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >x : any >x : any >D1 : D1 @@ -99,7 +99,7 @@ str = isC1(c1Orc2) && c1Orc2.p1; // C1 >str : string >isC1(c1Orc2) && c1Orc2.p1 : string >isC1(c1Orc2) : boolean ->isC1 : (x: any) => boolean +>isC1 : (x: any) => x is C1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string >c1Orc2 : C1 @@ -110,7 +110,7 @@ num = isC2(c1Orc2) && c1Orc2.p2; // C2 >num : number >isC2(c1Orc2) && c1Orc2.p2 : number >isC2(c1Orc2) : boolean ->isC2 : (x: any) => boolean +>isC2 : (x: any) => x is C2 >c1Orc2 : C1 | C2 >c1Orc2.p2 : number >c1Orc2 : C2 @@ -121,7 +121,7 @@ str = isD1(c1Orc2) && c1Orc2.p1; // D1 >str : string >isD1(c1Orc2) && c1Orc2.p1 : string >isD1(c1Orc2) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p1 : string >c1Orc2 : D1 @@ -132,7 +132,7 @@ num = isD1(c1Orc2) && c1Orc2.p3; // D1 >num : number >isD1(c1Orc2) && c1Orc2.p3 : number >isD1(c1Orc2) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c1Orc2 : C1 | C2 >c1Orc2.p3 : number >c1Orc2 : D1 @@ -148,7 +148,7 @@ num = isC2(c2Ord1) && c2Ord1.p2; // C2 >num : number >isC2(c2Ord1) && c2Ord1.p2 : number >isC2(c2Ord1) : boolean ->isC2 : (x: any) => boolean +>isC2 : (x: any) => x is C2 >c2Ord1 : C2 | D1 >c2Ord1.p2 : number >c2Ord1 : C2 @@ -159,7 +159,7 @@ num = isD1(c2Ord1) && c2Ord1.p3; // D1 >num : number >isD1(c2Ord1) && c2Ord1.p3 : number >isD1(c2Ord1) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p3 : number >c2Ord1 : D1 @@ -170,7 +170,7 @@ str = isD1(c2Ord1) && c2Ord1.p1; // D1 >str : string >isD1(c2Ord1) && c2Ord1.p1 : string >isD1(c2Ord1) : boolean ->isD1 : (x: any) => boolean +>isD1 : (x: any) => x is D1 >c2Ord1 : C2 | D1 >c2Ord1.p1 : string >c2Ord1 : D1 @@ -182,7 +182,7 @@ var r2: C2 | D1 = isC1(c2Ord1) && c2Ord1; // C2 | D1 >D1 : D1 >isC1(c2Ord1) && c2Ord1 : D1 >isC1(c2Ord1) : boolean ->isC1 : (x: any) => boolean +>isC1 : (x: any) => x is C1 >c2Ord1 : C2 | D1 >c2Ord1 : D1 From 43307edd4a8c97ca329a1175bf1a7150750c86fc Mon Sep 17 00:00:00 2001 From: "shyyko.serhiy@gmail.com" Date: Thu, 9 Jul 2015 20:27:05 +0300 Subject: [PATCH 69/88] fixed issue https://github.com/Microsoft/TypeScript/issues/3486 --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b34952f3ae..d64a294cebf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14718,10 +14718,10 @@ namespace ts { checkGrammarForAtLeastOneTypeArgument(node, typeArguments); } - function checkGrammarForOmittedArgument(node: CallExpression, arguments: NodeArray): boolean { - if (arguments) { + function checkGrammarForOmittedArgument(node: CallExpression, args: NodeArray): boolean { + if (args) { let sourceFile = getSourceFileOfNode(node); - for (let arg of arguments) { + for (let arg of args) { if (arg.kind === SyntaxKind.OmittedExpression) { return grammarErrorAtPos(sourceFile, arg.pos, 0, Diagnostics.Argument_expression_expected); } @@ -14729,9 +14729,9 @@ namespace ts { } } - function checkGrammarArguments(node: CallExpression, arguments: NodeArray): boolean { - return checkGrammarForDisallowedTrailingComma(arguments) || - checkGrammarForOmittedArgument(node, arguments); + function checkGrammarArguments(node: CallExpression, args: NodeArray): boolean { + return checkGrammarForDisallowedTrailingComma(args) || + checkGrammarForOmittedArgument(node, args); } function checkGrammarHeritageClause(node: HeritageClause): boolean { From f37fc1d42ef7805ba029bbca201299863d49c050 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 9 Jul 2015 11:31:08 -0700 Subject: [PATCH 70/88] Infer types to statics in a class expression --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b34952f3ae..6c0b74c0b48 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5491,7 +5491,7 @@ namespace ts { } } else if (source.flags & TypeFlags.ObjectType && (target.flags & (TypeFlags.Reference | TypeFlags.Tuple) || - (target.flags & TypeFlags.Anonymous) && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral))) { + (target.flags & TypeFlags.Anonymous) && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class))) { // If source is an object type, and target is a type reference, a tuple type, the type of a method, or a type literal, infer from members if (isInProcess(source, target)) { return; From f56298a0cd231905172fcdeb7bc62f16c8632ed2 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 9 Jul 2015 11:31:24 -0700 Subject: [PATCH 71/88] Add a test --- ...ypeArgumentInferenceWithClassExpression.js | 22 ++++++++++++++++++ ...gumentInferenceWithClassExpression.symbols | 19 +++++++++++++++ ...ArgumentInferenceWithClassExpression.types | 23 +++++++++++++++++++ ...ypeArgumentInferenceWithClassExpression.ts | 5 ++++ 4 files changed, 69 insertions(+) create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression.js create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression.types create mode 100644 tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.js b/tests/baselines/reference/typeArgumentInferenceWithClassExpression.js new file mode 100644 index 00000000000..cc0bf971473 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression.js @@ -0,0 +1,22 @@ +//// [typeArgumentInferenceWithClassExpression.ts] +function foo(x = class { static prop: T }): T { + return undefined; +} + +foo(class { static prop = "hello" }).length; + +//// [typeArgumentInferenceWithClassExpression.js] +function foo(x) { + if (x === void 0) { x = (function () { + function class_1() { + } + return class_1; + })(); } + return undefined; +} +foo((function () { + function class_2() { + } + class_2.prop = "hello"; + return class_2; +})()).length; diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols b/tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols new file mode 100644 index 00000000000..dac982595cb --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts === +function foo(x = class { static prop: T }): T { +>foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 0)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 13)) +>x : Symbol(x, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 16)) +>prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 27)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 13)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 13)) + + return undefined; +>undefined : Symbol(undefined) +} + +foo(class { static prop = "hello" }).length; +>foo(class { static prop = "hello" }).length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 0)) +>prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression.ts, 4, 11)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) + diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.types b/tests/baselines/reference/typeArgumentInferenceWithClassExpression.types new file mode 100644 index 00000000000..3eab8a4ab62 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts === +function foo(x = class { static prop: T }): T { +>foo : (x?: typeof (Anonymous class)) => T +>T : T +>x : typeof (Anonymous class) +>class { static prop: T } : typeof (Anonymous class) +>prop : T +>T : T +>T : T + + return undefined; +>undefined : undefined +} + +foo(class { static prop = "hello" }).length; +>foo(class { static prop = "hello" }).length : number +>foo(class { static prop = "hello" }) : string +>foo : (x?: typeof (Anonymous class)) => T +>class { static prop = "hello" } : typeof (Anonymous class) +>prop : string +>"hello" : string +>length : number + diff --git a/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts new file mode 100644 index 00000000000..21ca07ea2a2 --- /dev/null +++ b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts @@ -0,0 +1,5 @@ +function foo(x = class { static prop: T }): T { + return undefined; +} + +foo(class { static prop = "hello" }).length; \ No newline at end of file From 4e644e5ab849e98da526f733b2ce938d981d2719 Mon Sep 17 00:00:00 2001 From: Tingan Ho Date: Fri, 10 Jul 2015 03:27:31 +0800 Subject: [PATCH 72/88] Fixes spacing issue --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 03a3f7efa9b..08f4605ebe2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1958,7 +1958,7 @@ namespace ts { returnType = signature.typePredicate.type; } else { - returnType = getReturnTypeOfSignature(signature); + returnType = getReturnTypeOfSignature(signature); } buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack); } From 8bb956eb917c07058773b01d77c7e586b7fa8571 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Thu, 9 Jul 2015 14:41:08 -0700 Subject: [PATCH 73/88] More tests --- ...eArgumentInferenceWithClassExpression1.js} | 4 ++-- ...mentInferenceWithClassExpression1.symbols} | 18 +++++++------- ...gumentInferenceWithClassExpression1.types} | 2 +- ...ntInferenceWithClassExpression2.errors.txt | 16 +++++++++++++ ...peArgumentInferenceWithClassExpression2.js | 24 +++++++++++++++++++ ...peArgumentInferenceWithClassExpression3.js | 22 +++++++++++++++++ ...umentInferenceWithClassExpression3.symbols | 19 +++++++++++++++ ...rgumentInferenceWithClassExpression3.types | 23 ++++++++++++++++++ ...eArgumentInferenceWithClassExpression1.ts} | 0 ...peArgumentInferenceWithClassExpression2.ts | 6 +++++ ...peArgumentInferenceWithClassExpression3.ts | 5 ++++ 11 files changed, 127 insertions(+), 12 deletions(-) rename tests/baselines/reference/{typeArgumentInferenceWithClassExpression.js => typeArgumentInferenceWithClassExpression1.js} (76%) rename tests/baselines/reference/{typeArgumentInferenceWithClassExpression.symbols => typeArgumentInferenceWithClassExpression1.symbols} (58%) rename tests/baselines/reference/{typeArgumentInferenceWithClassExpression.types => typeArgumentInferenceWithClassExpression1.types} (91%) create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression2.errors.txt create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression3.js create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression3.symbols create mode 100644 tests/baselines/reference/typeArgumentInferenceWithClassExpression3.types rename tests/cases/conformance/es6/classExpressions/{typeArgumentInferenceWithClassExpression.ts => typeArgumentInferenceWithClassExpression1.ts} (100%) create mode 100644 tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression2.ts create mode 100644 tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression3.ts diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.js b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js similarity index 76% rename from tests/baselines/reference/typeArgumentInferenceWithClassExpression.js rename to tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js index cc0bf971473..25ce3743fa2 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.js +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.js @@ -1,11 +1,11 @@ -//// [typeArgumentInferenceWithClassExpression.ts] +//// [typeArgumentInferenceWithClassExpression1.ts] function foo(x = class { static prop: T }): T { return undefined; } foo(class { static prop = "hello" }).length; -//// [typeArgumentInferenceWithClassExpression.js] +//// [typeArgumentInferenceWithClassExpression1.js] function foo(x) { if (x === void 0) { x = (function () { function class_1() { diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.symbols similarity index 58% rename from tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols rename to tests/baselines/reference/typeArgumentInferenceWithClassExpression1.symbols index dac982595cb..ceb97a73af8 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.symbols +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts === +=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression1.ts === function foo(x = class { static prop: T }): T { ->foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 0)) ->T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 13)) ->x : Symbol(x, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 16)) ->prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 27)) ->T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 13)) ->T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 13)) +>foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 0)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 13)) +>x : Symbol(x, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 16)) +>prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 27)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 13)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 13)) return undefined; >undefined : Symbol(undefined) @@ -13,7 +13,7 @@ function foo(x = class { static prop: T }): T { foo(class { static prop = "hello" }).length; >foo(class { static prop = "hello" }).length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) ->foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression.ts, 0, 0)) ->prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression.ts, 4, 11)) +>foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression1.ts, 0, 0)) +>prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression1.ts, 4, 11)) >length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.types b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.types similarity index 91% rename from tests/baselines/reference/typeArgumentInferenceWithClassExpression.types rename to tests/baselines/reference/typeArgumentInferenceWithClassExpression1.types index 3eab8a4ab62..63ee1309383 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithClassExpression.types +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression1.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts === +=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression1.ts === function foo(x = class { static prop: T }): T { >foo : (x?: typeof (Anonymous class)) => T >T : T diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.errors.txt new file mode 100644 index 00000000000..c630944306b --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression2.ts(6,5): error TS2345: Argument of type 'typeof (Anonymous class)' is not assignable to parameter of type 'typeof (Anonymous class)'. + Type '(Anonymous class)' is not assignable to type 'foo<{}>.'. + Property 'prop' is missing in type '(Anonymous class)'. + + +==== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression2.ts (1 errors) ==== + function foo(x = class { prop: T }): T { + return undefined; + } + + // Should not infer string because it is a static property + foo(class { static prop = "hello" }).length; + ~~~~~ +!!! error TS2345: Argument of type 'typeof (Anonymous class)' is not assignable to parameter of type 'typeof (Anonymous class)'. +!!! error TS2345: Type '(Anonymous class)' is not assignable to type 'foo<{}>.'. +!!! error TS2345: Property 'prop' is missing in type '(Anonymous class)'. \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js b/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js new file mode 100644 index 00000000000..c4a7872b016 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression2.js @@ -0,0 +1,24 @@ +//// [typeArgumentInferenceWithClassExpression2.ts] +function foo(x = class { prop: T }): T { + return undefined; +} + +// Should not infer string because it is a static property +foo(class { static prop = "hello" }).length; + +//// [typeArgumentInferenceWithClassExpression2.js] +function foo(x) { + if (x === void 0) { x = (function () { + function class_1() { + } + return class_1; + })(); } + return undefined; +} +// Should not infer string because it is a static property +foo((function () { + function class_2() { + } + class_2.prop = "hello"; + return class_2; +})()).length; diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.js b/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.js new file mode 100644 index 00000000000..f3a3470e1c3 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.js @@ -0,0 +1,22 @@ +//// [typeArgumentInferenceWithClassExpression3.ts] +function foo(x = class { prop: T }): T { + return undefined; +} + +foo(class { prop = "hello" }).length; + +//// [typeArgumentInferenceWithClassExpression3.js] +function foo(x) { + if (x === void 0) { x = (function () { + function class_1() { + } + return class_1; + })(); } + return undefined; +} +foo((function () { + function class_2() { + this.prop = "hello"; + } + return class_2; +})()).length; diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.symbols b/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.symbols new file mode 100644 index 00000000000..aedb0230fd6 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression3.ts === +function foo(x = class { prop: T }): T { +>foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 0)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 13)) +>x : Symbol(x, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 16)) +>prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 27)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 13)) +>T : Symbol(T, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 13)) + + return undefined; +>undefined : Symbol(undefined) +} + +foo(class { prop = "hello" }).length; +>foo(class { prop = "hello" }).length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>foo : Symbol(foo, Decl(typeArgumentInferenceWithClassExpression3.ts, 0, 0)) +>prop : Symbol((Anonymous class).prop, Decl(typeArgumentInferenceWithClassExpression3.ts, 4, 11)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) + diff --git a/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.types b/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.types new file mode 100644 index 00000000000..9a2bddd9296 --- /dev/null +++ b/tests/baselines/reference/typeArgumentInferenceWithClassExpression3.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression3.ts === +function foo(x = class { prop: T }): T { +>foo : (x?: typeof (Anonymous class)) => T +>T : T +>x : typeof (Anonymous class) +>class { prop: T } : typeof (Anonymous class) +>prop : T +>T : T +>T : T + + return undefined; +>undefined : undefined +} + +foo(class { prop = "hello" }).length; +>foo(class { prop = "hello" }).length : number +>foo(class { prop = "hello" }) : string +>foo : (x?: typeof (Anonymous class)) => T +>class { prop = "hello" } : typeof (Anonymous class) +>prop : string +>"hello" : string +>length : number + diff --git a/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression1.ts similarity index 100% rename from tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression.ts rename to tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression1.ts diff --git a/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression2.ts b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression2.ts new file mode 100644 index 00000000000..d7a901ae951 --- /dev/null +++ b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression2.ts @@ -0,0 +1,6 @@ +function foo(x = class { prop: T }): T { + return undefined; +} + +// Should not infer string because it is a static property +foo(class { static prop = "hello" }).length; \ No newline at end of file diff --git a/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression3.ts b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression3.ts new file mode 100644 index 00000000000..d29b7007664 --- /dev/null +++ b/tests/cases/conformance/es6/classExpressions/typeArgumentInferenceWithClassExpression3.ts @@ -0,0 +1,5 @@ +function foo(x = class { prop: T }): T { + return undefined; +} + +foo(class { prop = "hello" }).length; \ No newline at end of file From 27f5bf10deb4cc4518f2693a478833104720292d Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 9 Jul 2015 14:44:47 -0700 Subject: [PATCH 74/88] CR feedback --- src/compiler/emitter.ts | 106 ++++---- src/compiler/scanner.ts | 556 ++++++++++++++++++++-------------------- 2 files changed, 331 insertions(+), 331 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 024af715948..69f8c25a147 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -9,9 +9,9 @@ namespace ts { // Flags enum to track count of temp variables and a few dedicated names const enum TempFlags { - Auto = 0x00000000, // No preferred name + Auto = 0x00000000, // No preferred name CountMask = 0x0FFFFFFF, // Temp variable counter - _i = 0x10000000, // Use/preference flag for '_i' + _i = 0x10000000, // Use/preference flag for '_i' } // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature @@ -129,7 +129,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let writeLine = writer.writeLine; let increaseIndent = writer.increaseIndent; let decreaseIndent = writer.decreaseIndent; - + let currentSourceFile: SourceFile; // name of an exporter function if file is a System external module // System.register([...], function () {...}) @@ -166,10 +166,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi let emit = emitNodeWithoutSourceMap; /** Called just before starting emit of a node */ - let emitStart = function(node: Node) { }; + let emitStart = function (node: Node) { }; /** Called once the emit of the node is done */ - let emitEnd = function(node: Node) { }; + let emitEnd = function (node: Node) { }; /** Emit the text for the given token that comes after startPos * This by default writes the text provided with the given tokenKind @@ -1358,7 +1358,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } else if (node.kind === SyntaxKind.ComputedPropertyName) { // if this is a decorated computed property, we will need to capture the result - // of the property expression so that we can apply decorators later. This is to ensure + // of the property expression so that we can apply decorators later. This is to ensure // we don't introduce unintended side effects: // // class C { @@ -1468,7 +1468,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("_arguments"); return; } - + let container = resolver.getReferencedExportContainer(node); if (container) { if (container.kind === SyntaxKind.SourceFile) { @@ -1608,7 +1608,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emit(node.expression); } } - + function emitAwaitExpression(node: AwaitExpression) { let needsParenthesis = needsParenthesisForAwaitExpressionAsYield(node); if (needsParenthesis) { @@ -2021,8 +2021,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return false; } - // Returns 'true' if the code was actually indented, false otherwise. - // If the code is not indented, an optional valueToWriteWhenNotIndenting will be + // Returns 'true' if the code was actually indented, false otherwise. + // If the code is not indented, an optional valueToWriteWhenNotIndenting will be // emitted instead. function indentIfOnDifferentLines(parent: Node, node1: Node, node2: Node, valueToWriteWhenNotIndenting?: string): boolean { let realNodesAreOnDifferentLines = !nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2); @@ -2051,7 +2051,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emit(node.expression); let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); - // 1 .toString is a valid property access, emit a space after the literal + // 1 .toString is a valid property access, emit a space after the literal let shouldEmitSpace: boolean; if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) { let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression); @@ -2384,14 +2384,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return isSourceFileLevelDeclarationInSystemJsModule(node, /*isExported*/ false); } - /* + /* * Checks if given node is a source file level declaration (not nested in module/function). * If 'isExported' is true - then declaration must also be exported. * This function is used in two cases: - * - check if node is a exported source file level value to determine + * - check if node is a exported source file level value to determine * if we should also export the value after its it changed - * - check if node is a source level declaration to emit it differently, - * i.e non-exported variable statement 'var x = 1' is hoisted so + * - check if node is a source level declaration to emit it differently, + * i.e non-exported variable statement 'var x = 1' is hoisted so * we we emit variable statement 'var' should be dropped. */ function isSourceFileLevelDeclarationInSystemJsModule(node: Node, isExported: boolean): boolean { @@ -2460,7 +2460,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi decreaseIndentIf(indentedBeforeColon, indentedAfterColon); } - // Helper function to decrease the indent if we previously indented. Allows multiple + // Helper function to decrease the indent if we previously indented. Allows multiple // previous indent values to be considered at a time. This also allows caller to just // call this once, passing in all their appropriate indent values, instead of needing // to call this helper function multiple times. @@ -3612,10 +3612,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emit(node.parameters[0]); return; } - + emitSignatureParameters(node); } - + function emitAsyncFunctionBodyForES6(node: FunctionLikeDeclaration) { let promiseConstructor = getEntityNameFromTypeNode(node.type); let isArrowFunction = node.kind === SyntaxKind.ArrowFunction; @@ -3625,7 +3625,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // An async function is emit as an outer function that calls an inner // generator function. To preserve lexical bindings, we pass the current // `this` and `arguments` objects to `__awaiter`. The generator function - // passed to `__awaiter` is executed inside of the callback to the + // passed to `__awaiter` is executed inside of the callback to the // promise constructor. // // The emit for an async arrow without a lexical `arguments` binding might be: @@ -3693,7 +3693,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // }); // } // - + // If this is not an async arrow, emit the opening brace of the function body // and the start of the return statement. if (!isArrowFunction) { @@ -3702,7 +3702,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi writeLine(); write("return"); } - + write(" __awaiter(this"); if (hasLexicalArguments) { write(", arguments"); @@ -3718,7 +3718,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi else { write(", Promise"); } - + // Emit the call to __awaiter. if (hasLexicalArguments) { write(", function* (_arguments)"); @@ -3726,11 +3726,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi else { write(", function* ()"); } - + // Emit the signature and body for the inner generator function. emitFunctionBody(node); write(")"); - + // If this is not an async arrow, emit the closing brace of the outer function body. if (!isArrowFunction) { write(";"); @@ -3739,10 +3739,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi write("}"); } } - + function emitFunctionBody(node: FunctionLikeDeclaration) { if (!node.body) { - // There can be no body when there are parse errors. Just emit an empty block + // There can be no body when there are parse errors. Just emit an empty block // in that case. write(" { }"); } @@ -3753,7 +3753,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi else { emitExpressionFunctionBody(node, node.body); } - } + } } function emitSignatureAndBody(node: FunctionLikeDeclaration) { @@ -3772,7 +3772,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi else { emitSignatureParameters(node); } - + let isAsync = isAsyncFunctionLike(node); if (isAsync && languageVersion === ScriptTarget.ES6) { emitAsyncFunctionBodyForES6(node); @@ -3780,7 +3780,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi else { emitFunctionBody(node); } - + if (!isES6ExportedDeclaration(node)) { emitExportMemberAssignment(node); } @@ -3803,7 +3803,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return; } - // For es6 and higher we can emit the expression as is. However, in the case + // For es6 and higher we can emit the expression as is. However, in the case // where the expression might end up looking like a block when emitted, we'll // also wrap it in parentheses first. For example if you have: a => {} // then we need to generate: a => ({}) @@ -4320,9 +4320,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } // If the class has static properties, and it's a class expression, then we'll need - // to specialize the emit a bit. for a class expression of the form: + // to specialize the emit a bit. for a class expression of the form: // - // class C { static a = 1; static b = 2; ... } + // class C { static a = 1; static b = 2; ... } // // We'll emit: // @@ -4613,7 +4613,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // // The emit for a method is: // - // Object.defineProperty(C.prototype, "method", + // Object.defineProperty(C.prototype, "method", // __decorate([ // dec, // __param(0, dec2), @@ -4621,10 +4621,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // __metadata("design:paramtypes", [Object]), // __metadata("design:returntype", void 0) // ], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); - // + // // The emit for an accessor is: // - // Object.defineProperty(C.prototype, "accessor", + // Object.defineProperty(C.prototype, "accessor", // __decorate([ // dec // ], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); @@ -4714,7 +4714,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function shouldEmitTypeMetadata(node: Declaration): boolean { // This method determines whether to emit the "design:type" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata // compiler option is set. switch (node.kind) { case SyntaxKind.MethodDeclaration: @@ -4729,7 +4729,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function shouldEmitReturnTypeMetadata(node: Declaration): boolean { // This method determines whether to emit the "design:returntype" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata // compiler option is set. switch (node.kind) { case SyntaxKind.MethodDeclaration: @@ -4740,7 +4740,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function shouldEmitParamTypesMetadata(node: Declaration): boolean { // This method determines whether to emit the "design:paramtypes" metadata based on the node's kind. - // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata + // The caller should have already tested whether the node has decorators and whether the emitDecoratorMetadata // compiler option is set. switch (node.kind) { case SyntaxKind.ClassDeclaration: @@ -5544,7 +5544,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi function writeExportedName(node: Identifier | Declaration): void { // do not record default exports - // they are local to module and never overwritten (explicitly skipped) by star export + // they are local to module and never overwritten (explicitly skipped) by star export if (node.kind !== SyntaxKind.Identifier && node.flags & NodeFlags.Default) { return; } @@ -5570,7 +5570,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } function processTopLevelVariableAndFunctionDeclarations(node: SourceFile): (Identifier | Declaration)[] { - // per ES6 spec: + // per ES6 spec: // 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method // - var declarations are initialized to undefined - 14.a.ii // - function/generator declarations are instantiated - 16.a.iv @@ -5725,7 +5725,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // hoist variable if // - it is not block scoped // - it is top level block scoped - // if block scoped variables are nested in some another block then + // if block scoped variables are nested in some another block then // no other functions can use them except ones that are defined at least in the same block return (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0 || getEnclosingBlockScopeContainer(node).kind === SyntaxKind.SourceFile; @@ -5925,10 +5925,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // System modules has the following shape // System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) // 'exports' here is a function 'exports(name: string, value: T): T' that is used to publish exported values. - // 'exports' returns its 'value' argument so in most cases expressions + // 'exports' returns its 'value' argument so in most cases expressions // that mutate exported values can be rewritten as: - // expr -> exports('name', expr). - // The only exception in this rule is postfix unary operators, + // expr -> exports('name', expr). + // The only exception in this rule is postfix unary operators, // see comment to 'emitPostfixUnaryExpression' for more details Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers @@ -5968,12 +5968,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi // `import "module"` or `` // we need to add modules without alias names to the end of the dependencies list - let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the - // factory function. - let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in - // factory function. - let importAliasNames: string[] = []; // names of the parameters in the factory function; these - // parameters need to match the indexes of the corresponding + // names of modules with corresponding parameter in the factory function + let aliasedModuleNames: string[] = []; + // names of modules with no corresponding parameters in factory function + let unaliasedModuleNames: string[] = []; + let importAliasNames: string[] = []; // names of the parameters in the factory function; these + // parameters need to match the indexes of the corresponding // module names in aliasedModuleNames. // Fill in amd-dependency tags @@ -6081,7 +6081,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); - // Emit exportDefault if it exists will happen as part + // Emit exportDefault if it exists will happen as part // or normal statement emit. } @@ -6245,7 +6245,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi writeLines(paramHelper); paramEmitted = true; } - + if (!awaiterEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitAwaiter) { writeLines(awaiterHelper); awaiterEmitted = true; @@ -6329,7 +6329,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi return shouldEmitEnumDeclaration(node); } - // If this is the expression body of an arrow function that we're down-leveling, + // If this is the expression body of an arrow function that we're down-leveling, // then we don't want to emit comments when we emit the body. It will have already // been taken care of when we emitted the 'return' statement for the function // expression body. diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 024326440ef..d52f96c912b 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -54,307 +54,307 @@ namespace ts { "catch": SyntaxKind.CatchKeyword, "class": SyntaxKind.ClassKeyword, "continue": SyntaxKind.ContinueKeyword, - "const": SyntaxKind.ConstKeyword, - "constructor": SyntaxKind.ConstructorKeyword, - "debugger": SyntaxKind.DebuggerKeyword, - "declare": SyntaxKind.DeclareKeyword, - "default": SyntaxKind.DefaultKeyword, - "delete": SyntaxKind.DeleteKeyword, - "do": SyntaxKind.DoKeyword, - "else": SyntaxKind.ElseKeyword, - "enum": SyntaxKind.EnumKeyword, - "export": SyntaxKind.ExportKeyword, - "extends": SyntaxKind.ExtendsKeyword, - "false": SyntaxKind.FalseKeyword, - "finally": SyntaxKind.FinallyKeyword, - "for": SyntaxKind.ForKeyword, - "from": SyntaxKind.FromKeyword, - "function": SyntaxKind.FunctionKeyword, - "get": SyntaxKind.GetKeyword, - "if": SyntaxKind.IfKeyword, - "implements": SyntaxKind.ImplementsKeyword, - "import": SyntaxKind.ImportKeyword, - "in": SyntaxKind.InKeyword, - "instanceof": SyntaxKind.InstanceOfKeyword, - "interface": SyntaxKind.InterfaceKeyword, - "is": SyntaxKind.IsKeyword, - "let": SyntaxKind.LetKeyword, - "module": SyntaxKind.ModuleKeyword, - "namespace": SyntaxKind.NamespaceKeyword, - "new": SyntaxKind.NewKeyword, - "null": SyntaxKind.NullKeyword, - "number": SyntaxKind.NumberKeyword, - "package": SyntaxKind.PackageKeyword, - "private": SyntaxKind.PrivateKeyword, - "protected": SyntaxKind.ProtectedKeyword, - "public": SyntaxKind.PublicKeyword, - "require": SyntaxKind.RequireKeyword, - "return": SyntaxKind.ReturnKeyword, - "set": SyntaxKind.SetKeyword, - "static": SyntaxKind.StaticKeyword, - "string": SyntaxKind.StringKeyword, - "super": SyntaxKind.SuperKeyword, - "switch": SyntaxKind.SwitchKeyword, - "symbol": SyntaxKind.SymbolKeyword, - "this": SyntaxKind.ThisKeyword, - "throw": SyntaxKind.ThrowKeyword, - "true": SyntaxKind.TrueKeyword, - "try": SyntaxKind.TryKeyword, - "type": SyntaxKind.TypeKeyword, - "typeof": SyntaxKind.TypeOfKeyword, - "var": SyntaxKind.VarKeyword, - "void": SyntaxKind.VoidKeyword, - "while": SyntaxKind.WhileKeyword, - "with": SyntaxKind.WithKeyword, - "yield": SyntaxKind.YieldKeyword, - "async": SyntaxKind.AsyncKeyword, - "await": SyntaxKind.AwaitKeyword, - "of": SyntaxKind.OfKeyword, - "{": SyntaxKind.OpenBraceToken, - "}": SyntaxKind.CloseBraceToken, - "(": SyntaxKind.OpenParenToken, - ")": SyntaxKind.CloseParenToken, - "[": SyntaxKind.OpenBracketToken, - "]": SyntaxKind.CloseBracketToken, - ".": SyntaxKind.DotToken, - "...": SyntaxKind.DotDotDotToken, - ";": SyntaxKind.SemicolonToken, - ",": SyntaxKind.CommaToken, - "<": SyntaxKind.LessThanToken, - ">": SyntaxKind.GreaterThanToken, - "<=": SyntaxKind.LessThanEqualsToken, - ">=": SyntaxKind.GreaterThanEqualsToken, - "==": SyntaxKind.EqualsEqualsToken, - "!=": SyntaxKind.ExclamationEqualsToken, - "===": SyntaxKind.EqualsEqualsEqualsToken, - "!==": SyntaxKind.ExclamationEqualsEqualsToken, - "=>": SyntaxKind.EqualsGreaterThanToken, - "+": SyntaxKind.PlusToken, - "-": SyntaxKind.MinusToken, - "*": SyntaxKind.AsteriskToken, - "/": SyntaxKind.SlashToken, - "%": SyntaxKind.PercentToken, - "++": SyntaxKind.PlusPlusToken, - "--": SyntaxKind.MinusMinusToken, - "<<": SyntaxKind.LessThanLessThanToken, - ">": SyntaxKind.GreaterThanGreaterThanToken, - ">>>": SyntaxKind.GreaterThanGreaterThanGreaterThanToken, - "&": SyntaxKind.AmpersandToken, - "|": SyntaxKind.BarToken, - "^": SyntaxKind.CaretToken, - "!": SyntaxKind.ExclamationToken, - "~": SyntaxKind.TildeToken, - "&&": SyntaxKind.AmpersandAmpersandToken, - "||": SyntaxKind.BarBarToken, - "?": SyntaxKind.QuestionToken, - ":": SyntaxKind.ColonToken, - "=": SyntaxKind.EqualsToken, - "+=": SyntaxKind.PlusEqualsToken, - "-=": SyntaxKind.MinusEqualsToken, - "*=": SyntaxKind.AsteriskEqualsToken, - "/=": SyntaxKind.SlashEqualsToken, - "%=": SyntaxKind.PercentEqualsToken, - "<<=": SyntaxKind.LessThanLessThanEqualsToken, - ">>=": SyntaxKind.GreaterThanGreaterThanEqualsToken, - ">>>=": SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, - "&=": SyntaxKind.AmpersandEqualsToken, - "|=": SyntaxKind.BarEqualsToken, - "^=": SyntaxKind.CaretEqualsToken, - "@": SyntaxKind.AtToken, - }; + "const": SyntaxKind.ConstKeyword, + "constructor": SyntaxKind.ConstructorKeyword, + "debugger": SyntaxKind.DebuggerKeyword, + "declare": SyntaxKind.DeclareKeyword, + "default": SyntaxKind.DefaultKeyword, + "delete": SyntaxKind.DeleteKeyword, + "do": SyntaxKind.DoKeyword, + "else": SyntaxKind.ElseKeyword, + "enum": SyntaxKind.EnumKeyword, + "export": SyntaxKind.ExportKeyword, + "extends": SyntaxKind.ExtendsKeyword, + "false": SyntaxKind.FalseKeyword, + "finally": SyntaxKind.FinallyKeyword, + "for": SyntaxKind.ForKeyword, + "from": SyntaxKind.FromKeyword, + "function": SyntaxKind.FunctionKeyword, + "get": SyntaxKind.GetKeyword, + "if": SyntaxKind.IfKeyword, + "implements": SyntaxKind.ImplementsKeyword, + "import": SyntaxKind.ImportKeyword, + "in": SyntaxKind.InKeyword, + "instanceof": SyntaxKind.InstanceOfKeyword, + "interface": SyntaxKind.InterfaceKeyword, + "is": SyntaxKind.IsKeyword, + "let": SyntaxKind.LetKeyword, + "module": SyntaxKind.ModuleKeyword, + "namespace": SyntaxKind.NamespaceKeyword, + "new": SyntaxKind.NewKeyword, + "null": SyntaxKind.NullKeyword, + "number": SyntaxKind.NumberKeyword, + "package": SyntaxKind.PackageKeyword, + "private": SyntaxKind.PrivateKeyword, + "protected": SyntaxKind.ProtectedKeyword, + "public": SyntaxKind.PublicKeyword, + "require": SyntaxKind.RequireKeyword, + "return": SyntaxKind.ReturnKeyword, + "set": SyntaxKind.SetKeyword, + "static": SyntaxKind.StaticKeyword, + "string": SyntaxKind.StringKeyword, + "super": SyntaxKind.SuperKeyword, + "switch": SyntaxKind.SwitchKeyword, + "symbol": SyntaxKind.SymbolKeyword, + "this": SyntaxKind.ThisKeyword, + "throw": SyntaxKind.ThrowKeyword, + "true": SyntaxKind.TrueKeyword, + "try": SyntaxKind.TryKeyword, + "type": SyntaxKind.TypeKeyword, + "typeof": SyntaxKind.TypeOfKeyword, + "var": SyntaxKind.VarKeyword, + "void": SyntaxKind.VoidKeyword, + "while": SyntaxKind.WhileKeyword, + "with": SyntaxKind.WithKeyword, + "yield": SyntaxKind.YieldKeyword, + "async": SyntaxKind.AsyncKeyword, + "await": SyntaxKind.AwaitKeyword, + "of": SyntaxKind.OfKeyword, + "{": SyntaxKind.OpenBraceToken, + "}": SyntaxKind.CloseBraceToken, + "(": SyntaxKind.OpenParenToken, + ")": SyntaxKind.CloseParenToken, + "[": SyntaxKind.OpenBracketToken, + "]": SyntaxKind.CloseBracketToken, + ".": SyntaxKind.DotToken, + "...": SyntaxKind.DotDotDotToken, + ";": SyntaxKind.SemicolonToken, + ",": SyntaxKind.CommaToken, + "<": SyntaxKind.LessThanToken, + ">": SyntaxKind.GreaterThanToken, + "<=": SyntaxKind.LessThanEqualsToken, + ">=": SyntaxKind.GreaterThanEqualsToken, + "==": SyntaxKind.EqualsEqualsToken, + "!=": SyntaxKind.ExclamationEqualsToken, + "===": SyntaxKind.EqualsEqualsEqualsToken, + "!==": SyntaxKind.ExclamationEqualsEqualsToken, + "=>": SyntaxKind.EqualsGreaterThanToken, + "+": SyntaxKind.PlusToken, + "-": SyntaxKind.MinusToken, + "*": SyntaxKind.AsteriskToken, + "/": SyntaxKind.SlashToken, + "%": SyntaxKind.PercentToken, + "++": SyntaxKind.PlusPlusToken, + "--": SyntaxKind.MinusMinusToken, + "<<": SyntaxKind.LessThanLessThanToken, + ">": SyntaxKind.GreaterThanGreaterThanToken, + ">>>": SyntaxKind.GreaterThanGreaterThanGreaterThanToken, + "&": SyntaxKind.AmpersandToken, + "|": SyntaxKind.BarToken, + "^": SyntaxKind.CaretToken, + "!": SyntaxKind.ExclamationToken, + "~": SyntaxKind.TildeToken, + "&&": SyntaxKind.AmpersandAmpersandToken, + "||": SyntaxKind.BarBarToken, + "?": SyntaxKind.QuestionToken, + ":": SyntaxKind.ColonToken, + "=": SyntaxKind.EqualsToken, + "+=": SyntaxKind.PlusEqualsToken, + "-=": SyntaxKind.MinusEqualsToken, + "*=": SyntaxKind.AsteriskEqualsToken, + "/=": SyntaxKind.SlashEqualsToken, + "%=": SyntaxKind.PercentEqualsToken, + "<<=": SyntaxKind.LessThanLessThanEqualsToken, + ">>=": SyntaxKind.GreaterThanGreaterThanEqualsToken, + ">>>=": SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, + "&=": SyntaxKind.AmpersandEqualsToken, + "|=": SyntaxKind.BarEqualsToken, + "^=": SyntaxKind.CaretEqualsToken, + "@": SyntaxKind.AtToken, + }; - /* - As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers - IdentifierStart :: - Can contain Unicode 3.0.0 categories: - Uppercase letter (Lu), - Lowercase letter (Ll), - Titlecase letter (Lt), - Modifier letter (Lm), - Other letter (Lo), or - Letter number (Nl). - IdentifierPart :: = - Can contain IdentifierStart + Unicode 3.0.0 categories: - Non-spacing mark (Mn), - Combining spacing mark (Mc), - Decimal number (Nd), or - Connector punctuation (Pc). + /* + As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers + IdentifierStart :: + Can contain Unicode 3.0.0 categories: + Uppercase letter (Lu), + Lowercase letter (Ll), + Titlecase letter (Lt), + Modifier letter (Lm), + Other letter (Lo), or + Letter number (Nl). + IdentifierPart :: = + Can contain IdentifierStart + Unicode 3.0.0 categories: + Non-spacing mark (Mn), + Combining spacing mark (Mc), + Decimal number (Nd), or + Connector punctuation (Pc). - Codepoint ranges for ES3 Identifiers are extracted from the Unicode 3.0.0 specification at: - http://www.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.txt - */ - let unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - let unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + Codepoint ranges for ES3 Identifiers are extracted from the Unicode 3.0.0 specification at: + http://www.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.txt + */ + let unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + let unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - /* - As per ECMAScript Language Specification 5th Edition, Section 7.6: ISyntaxToken Names and Identifiers - IdentifierStart :: - Can contain Unicode 6.2 categories: - Uppercase letter (Lu), - Lowercase letter (Ll), - Titlecase letter (Lt), - Modifier letter (Lm), - Other letter (Lo), or - Letter number (Nl). - IdentifierPart :: - Can contain IdentifierStart + Unicode 6.2 categories: - Non-spacing mark (Mn), - Combining spacing mark (Mc), - Decimal number (Nd), - Connector punctuation (Pc), - , or - . + /* + As per ECMAScript Language Specification 5th Edition, Section 7.6: ISyntaxToken Names and Identifiers + IdentifierStart :: + Can contain Unicode 6.2 categories: + Uppercase letter (Lu), + Lowercase letter (Ll), + Titlecase letter (Lt), + Modifier letter (Lm), + Other letter (Lo), or + Letter number (Nl). + IdentifierPart :: + Can contain IdentifierStart + Unicode 6.2 categories: + Non-spacing mark (Mn), + Combining spacing mark (Mc), + Decimal number (Nd), + Connector punctuation (Pc), + , or + . - Codepoint ranges for ES5 Identifiers are extracted from the Unicode 6.2 specification at: - http://www.unicode.org/Public/6.2.0/ucd/UnicodeData.txt - */ - let unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - let unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + Codepoint ranges for ES5 Identifiers are extracted from the Unicode 6.2 specification at: + http://www.unicode.org/Public/6.2.0/ucd/UnicodeData.txt + */ + let unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; + let unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, ]; - function lookupInUnicodeMap(code: number, map: number[]): boolean { - // Bail out quickly if it couldn't possibly be in the map. - if (code < map[0]) { - return false; - } + function lookupInUnicodeMap(code: number, map: number[]): boolean { + // Bail out quickly if it couldn't possibly be in the map. + if (code < map[0]) { + return false; + } - // Perform binary search in one of the Unicode range maps - let lo: number = 0; - let hi: number = map.length; - let mid: number; + // Perform binary search in one of the Unicode range maps + let lo: number = 0; + let hi: number = map.length; + let mid: number; - while (lo + 1 < hi) { - mid = lo + (hi - lo) / 2; - // mid has to be even to catch a range's beginning - mid -= mid % 2; - if (map[mid] <= code && code <= map[mid + 1]) { - return true; - } + while (lo + 1 < hi) { + mid = lo + (hi - lo) / 2; + // mid has to be even to catch a range's beginning + mid -= mid % 2; + if (map[mid] <= code && code <= map[mid + 1]) { + return true; + } - if (code < map[mid]) { - hi = mid; - } - else { - lo = mid + 2; - } - } + if (code < map[mid]) { + hi = mid; + } + else { + lo = mid + 2; + } + } - return false; - } + return false; + } - /* @internal */ export function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget) { - return languageVersion >= ScriptTarget.ES5 ? - lookupInUnicodeMap(code, unicodeES5IdentifierStart) : - lookupInUnicodeMap(code, unicodeES3IdentifierStart); - } + /* @internal */ export function isUnicodeIdentifierStart(code: number, languageVersion: ScriptTarget) { + return languageVersion >= ScriptTarget.ES5 ? + lookupInUnicodeMap(code, unicodeES5IdentifierStart) : + lookupInUnicodeMap(code, unicodeES3IdentifierStart); + } - function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget) { - return languageVersion >= ScriptTarget.ES5 ? - lookupInUnicodeMap(code, unicodeES5IdentifierPart) : - lookupInUnicodeMap(code, unicodeES3IdentifierPart); - } + function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget) { + return languageVersion >= ScriptTarget.ES5 ? + lookupInUnicodeMap(code, unicodeES5IdentifierPart) : + lookupInUnicodeMap(code, unicodeES3IdentifierPart); + } - function makeReverseMap(source: Map): string[] { - let result: string[] = []; - for (let name in source) { - if (source.hasOwnProperty(name)) { - result[source[name]] = name; - } - } - return result; - } + function makeReverseMap(source: Map): string[] { + let result: string[] = []; + for (let name in source) { + if (source.hasOwnProperty(name)) { + result[source[name]] = name; + } + } + return result; + } - let tokenStrings = makeReverseMap(textToToken); + let tokenStrings = makeReverseMap(textToToken); - export function tokenToString(t: SyntaxKind): string { - return tokenStrings[t]; - } + export function tokenToString(t: SyntaxKind): string { + return tokenStrings[t]; + } - /* @internal */ - export function stringToToken(s: string): SyntaxKind { - return textToToken[s]; - } + /* @internal */ + export function stringToToken(s: string): SyntaxKind { + return textToToken[s]; + } - /* @internal */ - export function computeLineStarts(text: string): number[] { - let result: number[] = new Array(); - let pos = 0; - let lineStart = 0; - while (pos < text.length) { - let ch = text.charCodeAt(pos++); - switch (ch) { - case CharacterCodes.carriageReturn: - if (text.charCodeAt(pos) === CharacterCodes.lineFeed) { - pos++; - } - case CharacterCodes.lineFeed: - result.push(lineStart); - lineStart = pos; - break; - default: - if (ch > CharacterCodes.maxAsciiCharacter && isLineBreak(ch)) { - result.push(lineStart); - lineStart = pos; - } - break; - } - } - result.push(lineStart); - return result; - } + /* @internal */ + export function computeLineStarts(text: string): number[] { + let result: number[] = new Array(); + let pos = 0; + let lineStart = 0; + while (pos < text.length) { + let ch = text.charCodeAt(pos++); + switch (ch) { + case CharacterCodes.carriageReturn: + if (text.charCodeAt(pos) === CharacterCodes.lineFeed) { + pos++; + } + case CharacterCodes.lineFeed: + result.push(lineStart); + lineStart = pos; + break; + default: + if (ch > CharacterCodes.maxAsciiCharacter && isLineBreak(ch)) { + result.push(lineStart); + lineStart = pos; + } + break; + } + } + result.push(lineStart); + return result; + } - export function getPositionOfLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number { - return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character); - } + export function getPositionOfLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number { + return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character); + } - /* @internal */ - export function computePositionOfLineAndCharacter(lineStarts: number[], line: number, character: number): number { - Debug.assert(line >= 0 && line < lineStarts.length); - return lineStarts[line] + character; - } + /* @internal */ + export function computePositionOfLineAndCharacter(lineStarts: number[], line: number, character: number): number { + Debug.assert(line >= 0 && line < lineStarts.length); + return lineStarts[line] + character; + } - /* @internal */ - export function getLineStarts(sourceFile: SourceFile): number[] { - return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text)); - } + /* @internal */ + export function getLineStarts(sourceFile: SourceFile): number[] { + return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text)); + } - /* @internal */ - export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) { - let lineNumber = binarySearch(lineStarts, position); - if (lineNumber < 0) { - // If the actual position was not found, - // the binary search returns the negative value of the next line start - // e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20 - // then the search will return -2 - lineNumber = ~lineNumber - 1; - } - return { - line: lineNumber, - character: position - lineStarts[lineNumber] - }; - } + /* @internal */ + export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) { + let lineNumber = binarySearch(lineStarts, position); + if (lineNumber < 0) { + // If the actual position was not found, + // the binary search returns the negative value of the next line start + // e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20 + // then the search will return -2 + lineNumber = ~lineNumber - 1; + } + return { + line: lineNumber, + character: position - lineStarts[lineNumber] + }; + } - export function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter { - return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position); - } + export function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter { + return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position); + } - let hasOwnProperty = Object.prototype.hasOwnProperty; + let hasOwnProperty = Object.prototype.hasOwnProperty; - export function isWhiteSpace(ch: number): boolean { - // Note: nextLine is in the Zs space, and should be considered to be a whitespace. - // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript. - return ch === CharacterCodes.space || - ch === CharacterCodes.tab || - ch === CharacterCodes.verticalTab || - ch === CharacterCodes.formFeed || - ch === CharacterCodes.nonBreakingSpace || - ch === CharacterCodes.nextLine || - ch === CharacterCodes.ogham || - ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || - ch === CharacterCodes.narrowNoBreakSpace || - ch === CharacterCodes.mathematicalSpace || - ch === CharacterCodes.ideographicSpace || - ch === CharacterCodes.byteOrderMark; + export function isWhiteSpace(ch: number): boolean { + // Note: nextLine is in the Zs space, and should be considered to be a whitespace. + // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript. + return ch === CharacterCodes.space || + ch === CharacterCodes.tab || + ch === CharacterCodes.verticalTab || + ch === CharacterCodes.formFeed || + ch === CharacterCodes.nonBreakingSpace || + ch === CharacterCodes.nextLine || + ch === CharacterCodes.ogham || + ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || + ch === CharacterCodes.narrowNoBreakSpace || + ch === CharacterCodes.mathematicalSpace || + ch === CharacterCodes.ideographicSpace || + ch === CharacterCodes.byteOrderMark; } export function isLineBreak(ch: number): boolean { From 9353a60cffd16d79125712eac31b81340cd01c7b Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 9 Jul 2015 16:09:50 -0700 Subject: [PATCH 75/88] Readd className to SVGStylable for compatibility --- src/lib/dom.generated.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 53e086a9dc4..19133b68b4c 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -12536,6 +12536,7 @@ interface SVGLocatable { } interface SVGStylable { + className: any; style: CSSStyleDeclaration; } From d0b8002701495f4f0fbfb4afc34d3f170f519fff Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Jul 2015 16:34:30 -0700 Subject: [PATCH 76/88] Address code review --- src/compiler/checker.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d18d0faba9b..198827c32d4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13429,7 +13429,6 @@ namespace ts { } break; case SyntaxKind.FunctionExpression: - case SyntaxKind.ClassExpression: let funcName = (location).name; if (funcName) { copySymbol(location.symbol, meaning); From a80a4ba0a42eec068ccf703743f44568f5f4f72f Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 9 Jul 2015 16:39:58 -0700 Subject: [PATCH 77/88] Add jake task for linting the compiler sources --- Jakefile.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 517f5e862d5..99d5d86ccd8 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -361,7 +361,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca /*keepComments*/ true, /*noResolve*/ false, /*stripInternal*/ true, - /*callback*/ function () { + /*callback*/ function () { jake.cpR(servicesFile, nodePackageFile, {silent: true}); prependFile(copyright, standaloneDefinitionsFile); @@ -379,12 +379,12 @@ compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(se var lsslFile = path.join(builtLocalDirectory, "tslssl.js"); compileFile( - lsslFile, - languageServiceLibrarySources, + lsslFile, + languageServiceLibrarySources, [builtLocalDirectory, copyright].concat(languageServiceLibrarySources), - /*prefixes*/ [copyright], - /*useBuiltCompiler*/ true, - /*noOutFile*/ false, + /*prefixes*/ [copyright], + /*useBuiltCompiler*/ true, + /*noOutFile*/ false, /*generateDeclarations*/ true); // Local target to build the language service server library @@ -488,7 +488,7 @@ var refTest262Baseline = path.join(internalTests, "baselines/test262/reference") desc("Builds the test infrastructure using the built compiler"); task("tests", ["local", run].concat(libraryTargets)); -function exec(cmd, completeHandler) { +function exec(cmd, completeHandler, errorHandler) { var ex = jake.createExec([cmd], {windowsVerbatimArguments: true}); // Add listeners for output and error ex.addListener("stdout", function(output) { @@ -504,8 +504,12 @@ function exec(cmd, completeHandler) { complete(); }); ex.addListener("error", function(e, status) { - fail("Process exited with code " + status); - }) + if(errorHandler) { + errorHandler(e, status); + } else { + fail("Process exited with code " + status); + } + }); ex.run(); } @@ -721,3 +725,16 @@ task("update-sublime", [serverFile], function() { jake.cpR(serverFile, "../TypeScript-Sublime-Plugin/tsserver/"); jake.cpR(serverFile + ".map", "../TypeScript-Sublime-Plugin/tsserver/"); }); + +// if the codebase were free of linter errors we could make jake runtests +// run this task automatically +desc("Runs tslint on the compiler sources"); +task("lint", [], function() { + for(var f of compilerSources) { + var cmd = 'tslint -f ' + f; + exec(cmd, + function() { console.log('SUCCESS: No linter errors'); }, + function() { console.log('FAILURE: Please fix linting errors in ' + f + '\n'); + }); + } +}, { async: true }); From c363dec9af72fe8397105e9704052b121e87795c Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 9 Jul 2015 16:43:33 -0700 Subject: [PATCH 78/88] for...in not for...of --- Jakefile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jakefile.js b/Jakefile.js index 99d5d86ccd8..d91e04bc015 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -730,7 +730,8 @@ task("update-sublime", [serverFile], function() { // run this task automatically desc("Runs tslint on the compiler sources"); task("lint", [], function() { - for(var f of compilerSources) { + for(var i in compilerSources) { + var f = compilerSources[i]; var cmd = 'tslint -f ' + f; exec(cmd, function() { console.log('SUCCESS: No linter errors'); }, From 89c44f52a34e3dd72f7e12ec40dbff5c16ed89b8 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Thu, 9 Jul 2015 16:48:39 -0700 Subject: [PATCH 79/88] Add className property in SVGElement --- src/lib/dom.generated.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 19133b68b4c..32e8fb45ce4 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -8715,6 +8715,7 @@ declare var SVGDescElement: { interface SVGElement extends Element { id: string; + className: any; onclick: (ev: MouseEvent) => any; ondblclick: (ev: MouseEvent) => any; onfocusin: (ev: FocusEvent) => any; From 41bedd2768d1c47e901525b0a9c30911a375e70e Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Jul 2015 17:05:57 -0700 Subject: [PATCH 80/88] Use getDecalredName in service layer instead of symbol.getName --- src/services/services.ts | 28 +++++++------------ src/services/utilities.ts | 2 +- .../completionListInvalidMemberNames.ts | 3 +- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 756bb200687..5dc5f8a46db 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2808,23 +2808,15 @@ namespace ts { * @return undefined if the name is of external module otherwise a name with striped of any quote */ function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, location: Node): string { - let displayName: string = symbol.getName(); + let displayName: string = getDeclaredName(program.getTypeChecker(), symbol, location); if (displayName) { - if (displayName === "default") { - // In the case of default export, the binder bind them with "default". - // However, for completion entry, we want to display its declared name rather than binder name. - let typeChecker = program.getTypeChecker(); - displayName = getDeclaredName(typeChecker, symbol, location); - } - else { - let firstCharCode = displayName.charCodeAt(0); - // First check of the displayName is not external module; if it is an external module, it is not valid entry - if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { - // If the symbol is external module, don't show it in the completion list - // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) - return undefined; - } + let firstCharCode = displayName.charCodeAt(0); + // First check of the displayName is not external module; if it is an external module, it is not valid entry + if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) { + // If the symbol is external module, don't show it in the completion list + // (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there) + return undefined; } } @@ -2862,7 +2854,7 @@ namespace ts { } } - return unescapeIdentifier(name); + return name; } function getCompletionData(fileName: string, position: number) { @@ -5087,7 +5079,7 @@ namespace ts { // Get the text to search for. // Note: if this is an external module symbol, the name doesn't include quotes. - let declaredName = getDeclaredName(typeChecker, symbol, node); + let declaredName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); // Try to get the smallest valid scope that we can limit our search to; // otherwise we'll need to search globally (i.e. include each file). @@ -6838,7 +6830,7 @@ namespace ts { } } - let displayName = getDeclaredName(typeChecker, symbol, node); + let displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); let kind = getSymbolKind(symbol, node); if (kind) { return { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 5c3091000f7..5f8859c815e 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -667,7 +667,7 @@ namespace ts { let name = typeChecker.symbolToString(localExportDefaultSymbol || symbol); - return stripQuotes(name); + return name; } export function isImportOrExportSpecifierName(location: Node): boolean { diff --git a/tests/cases/fourslash/completionListInvalidMemberNames.ts b/tests/cases/fourslash/completionListInvalidMemberNames.ts index 7fff46e2a81..0928f8b9d8c 100644 --- a/tests/cases/fourslash/completionListInvalidMemberNames.ts +++ b/tests/cases/fourslash/completionListInvalidMemberNames.ts @@ -19,7 +19,6 @@ verify.completionListContains("bar"); verify.completionListContains("break"); verify.completionListContains("any"); verify.completionListContains("$"); -verify.completionListContains("b"); // Nothing else should show up -verify.memberListCount(5); +verify.memberListCount(4); From 1a3dbc0a5f54d3654a76efb3654fe095d4abca3d Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 9 Jul 2015 18:07:48 -0700 Subject: [PATCH 81/88] Final CR feedback fixes --- src/compiler/binder.ts | 2 +- src/compiler/emitter.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 802bf6df358..e839d6d6c9a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -490,7 +490,7 @@ namespace ts { if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { return true; } - }; + } } return false; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 69f8c25a147..70d7ef60472 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -9,9 +9,9 @@ namespace ts { // Flags enum to track count of temp variables and a few dedicated names const enum TempFlags { - Auto = 0x00000000, // No preferred name + Auto = 0x00000000, // No preferred name CountMask = 0x0FFFFFFF, // Temp variable counter - _i = 0x10000000, // Use/preference flag for '_i' + _i = 0x10000000, // Use/preference flag for '_i' } // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature From 5de728d8ac93687ba676369d8c9062ab8ba00f30 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Jul 2015 19:06:21 -0700 Subject: [PATCH 82/88] Added failing test. --- .../fourslash/completionListInImportClause03.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/cases/fourslash/completionListInImportClause03.ts diff --git a/tests/cases/fourslash/completionListInImportClause03.ts b/tests/cases/fourslash/completionListInImportClause03.ts new file mode 100644 index 00000000000..7461c83022b --- /dev/null +++ b/tests/cases/fourslash/completionListInImportClause03.ts @@ -0,0 +1,16 @@ +/// + +////declare module "M1" { +//// export var abc: number; +//// export var def: string; +////} +//// +////declare module "M2" { +//// import { abc/**/ } from "M1"; +////} + +// Ensure we don't filter out the current item. +goTo.marker(); +verify.completionListContains("abc"); +verify.completionListContains("def"); +verify.not.completionListAllowsNewIdentifier(); \ No newline at end of file From 1b0b4344229a32d72d528b661edcf8a792ecec86 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Jul 2015 19:22:28 -0700 Subject: [PATCH 83/88] Don't filter out the current item. --- src/services/services.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/services.ts b/src/services/services.ts index 3f656fe75ff..7675b310715 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3463,6 +3463,11 @@ namespace ts { importDeclaration.importClause.namedBindings.kind === SyntaxKind.NamedImports) { forEach((importDeclaration.importClause.namedBindings).elements, el => { + // If this is the current item we are editing right now, do not filter it out + if (el.getStart() <= position && position <= el.getEnd()) { + return; + } + let name = el.propertyName || el.name; exisingImports[name.text] = true; }); From fc4521905863faa67b5fddfb9541eb02b7334da7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Jul 2015 19:50:17 -0700 Subject: [PATCH 84/88] Spacing. --- src/services/services.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 7675b310715..e5a5266e116 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3524,16 +3524,16 @@ namespace ts { } } - function filterJsxAttributes(attributes: NodeArray, symbols: Symbol[]): Symbol[] { + function filterJsxAttributes(attributes: NodeArray, symbols: Symbol[]): Symbol[] { let seenNames: Map = {}; - for(let attr of attributes) { - if(attr.kind === SyntaxKind.JsxAttribute) { + for (let attr of attributes) { + if (attr.kind === SyntaxKind.JsxAttribute) { seenNames[(attr).name.text] = true; } } let result: Symbol[] = []; - for(let sym of symbols) { - if(!seenNames[sym.name]) { + for (let sym of symbols) { + if (!seenNames[sym.name]) { result.push(sym); } } From fdc504a19ff236733b5e10a3197ff662dd3727f8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Jul 2015 19:57:56 -0700 Subject: [PATCH 85/88] Added failing test. --- tests/cases/fourslash/tsxCompletion5.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/tsxCompletion5.ts diff --git a/tests/cases/fourslash/tsxCompletion5.ts b/tests/cases/fourslash/tsxCompletion5.ts new file mode 100644 index 00000000000..2de6d9a4132 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion5.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// var x =
; + +goTo.marker(); +verify.completionListContains("ONE"); +verify.completionListContains("TWO"); +verify.not.completionListAllowsNewIdentifier(); \ No newline at end of file From 1daf49c0674c622d9723be46d1f30a80c36425d0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 9 Jul 2015 20:02:51 -0700 Subject: [PATCH 86/88] Don't filter out JSX attributes. --- src/services/services.ts | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index e5a5266e116..94a3345af1f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3522,23 +3522,29 @@ namespace ts { return filteredMembers; } + + function filterJsxAttributes(attributes: NodeArray, symbols: Symbol[]): Symbol[] { + let seenNames: Map = {}; + for (let attr of attributes) { + // If this is the current item we are editing right now, do not filter it out + if (attr.getStart() <= position && position <= attr.getEnd()) { + continue; + } + + if (attr.kind === SyntaxKind.JsxAttribute) { + seenNames[(attr).name.text] = true; + } + } + let result: Symbol[] = []; + for (let sym of symbols) { + if (!seenNames[sym.name]) { + result.push(sym); + } + } + return result; + } } - function filterJsxAttributes(attributes: NodeArray, symbols: Symbol[]): Symbol[] { - let seenNames: Map = {}; - for (let attr of attributes) { - if (attr.kind === SyntaxKind.JsxAttribute) { - seenNames[(attr).name.text] = true; - } - } - let result: Symbol[] = []; - for (let sym of symbols) { - if (!seenNames[sym.name]) { - result.push(sym); - } - } - return result; - } function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { synchronizeHostData(); From d0d1ee918ff4e5ba72c6b350741f57fa723fdbea Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Jul 2015 10:15:40 -0700 Subject: [PATCH 87/88] Add test for using unicode escape as function name --- .../completionListForUnicodeEscapeName.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/cases/fourslash/completionListForUnicodeEscapeName.ts diff --git a/tests/cases/fourslash/completionListForUnicodeEscapeName.ts b/tests/cases/fourslash/completionListForUnicodeEscapeName.ts new file mode 100644 index 00000000000..afafd18a58b --- /dev/null +++ b/tests/cases/fourslash/completionListForUnicodeEscapeName.ts @@ -0,0 +1,27 @@ +/// + +////function \u0042 () { /*0*/ } +////export default function \u0043 () { /*1*/ } +////class \u0041 { /*2*/ } +/////*3*/ + +goTo.marker("0"); +verify.not.completionListContains("B"); +verify.not.completionListContains("\u0042"); + +goTo.marker("2"); +verify.not.completionListContains("C"); +verify.not.completionListContains("\u0043"); + +goTo.marker("2"); +verify.not.completionListContains("A"); +verify.not.completionListContains("\u0041"); + +goTo.marker("3"); +verify.not.completionListContains("B"); +verify.not.completionListContains("\u0042"); +verify.not.completionListContains("A"); +verify.not.completionListContains("\u0041"); +verify.not.completionListContains("C"); +verify.not.completionListContains("\u0043"); + From 5cfba6b4f2b9bd4f2d75eb953e332c929133649d Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Fri, 10 Jul 2015 11:09:22 -0700 Subject: [PATCH 88/88] Make update-sublime depend on local task --- Jakefile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile.js b/Jakefile.js index d91e04bc015..33ad46c8b58 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -721,7 +721,7 @@ task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function }, { async: true }); desc("Updates the sublime plugin's tsserver"); -task("update-sublime", [serverFile], function() { +task("update-sublime", ["local", serverFile], function() { jake.cpR(serverFile, "../TypeScript-Sublime-Plugin/tsserver/"); jake.cpR(serverFile + ".map", "../TypeScript-Sublime-Plugin/tsserver/"); });