From ed1ff3d57d699aad356ff444bf251480072620a7 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Thu, 25 Jun 2015 16:24:41 -0700 Subject: [PATCH] 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) {