mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Apply 'variable-name' tslint rule (#19743)
This commit is contained in:
@@ -924,7 +924,7 @@ namespace ts.formatting {
|
||||
if (rule) {
|
||||
applyRuleEdits(rule, previousItem, previousStartLine, currentItem, currentStartLine);
|
||||
|
||||
if (rule.Operation.Action & (RuleAction.Space | RuleAction.Delete) && currentStartLine !== previousStartLine) {
|
||||
if (rule.operation.action & (RuleAction.Space | RuleAction.Delete) && currentStartLine !== previousStartLine) {
|
||||
lineAdded = false;
|
||||
// Handle the case where the next line is moved to be the end of this line.
|
||||
// In this case we don't indent the next line in the next pass.
|
||||
@@ -932,7 +932,7 @@ namespace ts.formatting {
|
||||
dynamicIndentation.recomputeIndentation(/*lineAddedByFormatting*/ false);
|
||||
}
|
||||
}
|
||||
else if (rule.Operation.Action & RuleAction.NewLine && currentStartLine === previousStartLine) {
|
||||
else if (rule.operation.action & RuleAction.NewLine && currentStartLine === previousStartLine) {
|
||||
lineAdded = true;
|
||||
// Handle the case where token2 is moved to the new line.
|
||||
// In this case we indent token2 in the next pass but we set
|
||||
@@ -943,7 +943,7 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
// We need to trim trailing whitespace between the tokens if they were on different lines, and no rule was applied to put them on the same line
|
||||
trimTrailingWhitespaces = !(rule.Operation.Action & RuleAction.Delete) && rule.Flag !== RuleFlags.CanDeleteNewLines;
|
||||
trimTrailingWhitespaces = !(rule.operation.action & RuleAction.Delete) && rule.flag !== RuleFlags.CanDeleteNewLines;
|
||||
}
|
||||
else {
|
||||
trimTrailingWhitespaces = true;
|
||||
@@ -1118,7 +1118,7 @@ namespace ts.formatting {
|
||||
currentRange: TextRangeWithKind,
|
||||
currentStartLine: number): void {
|
||||
|
||||
switch (rule.Operation.Action) {
|
||||
switch (rule.operation.action) {
|
||||
case RuleAction.Ignore:
|
||||
// no action required
|
||||
return;
|
||||
@@ -1132,7 +1132,7 @@ namespace ts.formatting {
|
||||
// exit early if we on different lines and rule cannot change number of newlines
|
||||
// if line1 and line2 are on subsequent lines then no edits are required - ok to exit
|
||||
// if line1 and line2 are separated with more than one newline - ok to exit since we cannot delete extra new lines
|
||||
if (rule.Flag !== RuleFlags.CanDeleteNewLines && previousStartLine !== currentStartLine) {
|
||||
if (rule.flag !== RuleFlags.CanDeleteNewLines && previousStartLine !== currentStartLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1144,7 +1144,7 @@ namespace ts.formatting {
|
||||
break;
|
||||
case RuleAction.Space:
|
||||
// exit early if we on different lines and rule cannot change number of newlines
|
||||
if (rule.Flag !== RuleFlags.CanDeleteNewLines && previousStartLine !== currentStartLine) {
|
||||
if (rule.flag !== RuleFlags.CanDeleteNewLines && previousStartLine !== currentStartLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace ts.formatting {
|
||||
// Used for debugging to identify each rule based on the property name it's assigned to.
|
||||
public debugName?: string;
|
||||
constructor(
|
||||
readonly Descriptor: RuleDescriptor,
|
||||
readonly Operation: RuleOperation,
|
||||
readonly Flag: RuleFlags = RuleFlags.None) {
|
||||
readonly descriptor: RuleDescriptor,
|
||||
readonly operation: RuleOperation,
|
||||
readonly flag: RuleFlags = RuleFlags.None) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@
|
||||
/* @internal */
|
||||
namespace ts.formatting {
|
||||
export class RuleDescriptor {
|
||||
constructor(public LeftTokenRange: Shared.TokenRange, public RightTokenRange: Shared.TokenRange) {
|
||||
constructor(public leftTokenRange: Shared.TokenRange, public rightTokenRange: Shared.TokenRange) {
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return "[leftRange=" + this.LeftTokenRange + "," +
|
||||
"rightRange=" + this.RightTokenRange + "]";
|
||||
return "[leftRange=" + this.leftTokenRange + "," +
|
||||
"rightRange=" + this.rightTokenRange + "]";
|
||||
}
|
||||
|
||||
static create1(left: SyntaxKind, right: SyntaxKind): RuleDescriptor {
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
/* @internal */
|
||||
namespace ts.formatting {
|
||||
export class RuleOperation {
|
||||
constructor(public Context: RuleOperationContext, public Action: RuleAction) {}
|
||||
constructor(readonly context: RuleOperationContext, readonly action: RuleAction) {}
|
||||
|
||||
public toString(): string {
|
||||
return "[context=" + this.Context + "," +
|
||||
"action=" + this.Action + "]";
|
||||
return "[context=" + this.context + "," +
|
||||
"action=" + this.action + "]";
|
||||
}
|
||||
|
||||
static create1(action: RuleAction) {
|
||||
return RuleOperation.create2(RuleOperationContext.Any, action);
|
||||
return RuleOperation.create2(RuleOperationContext.any, action);
|
||||
}
|
||||
|
||||
static create2(context: RuleOperationContext, action: RuleAction) {
|
||||
|
||||
@@ -10,10 +10,10 @@ namespace ts.formatting {
|
||||
this.customContextChecks = funcs;
|
||||
}
|
||||
|
||||
static readonly Any: RuleOperationContext = new RuleOperationContext();
|
||||
static readonly any: RuleOperationContext = new RuleOperationContext();
|
||||
|
||||
public IsAny(): boolean {
|
||||
return this === RuleOperationContext.Any;
|
||||
return this === RuleOperationContext.any;
|
||||
}
|
||||
|
||||
public InContext(context: FormattingContext): boolean {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
/* @internal */
|
||||
namespace ts.formatting {
|
||||
// tslint:disable variable-name (TODO)
|
||||
export class Rules {
|
||||
public IgnoreBeforeComment: Rule;
|
||||
public IgnoreAfterLineComment: Rule;
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
private FillRule(rule: Rule, rulesBucketConstructionStateList: RulesBucketConstructionState[]): void {
|
||||
const specificRule = rule.Descriptor.LeftTokenRange.isSpecific() && rule.Descriptor.RightTokenRange.isSpecific();
|
||||
const specificRule = rule.descriptor.leftTokenRange.isSpecific() && rule.descriptor.rightTokenRange.isSpecific();
|
||||
|
||||
rule.Descriptor.LeftTokenRange.GetTokens().forEach((left) => {
|
||||
rule.Descriptor.RightTokenRange.GetTokens().forEach((right) => {
|
||||
rule.descriptor.leftTokenRange.GetTokens().forEach((left) => {
|
||||
rule.descriptor.rightTokenRange.GetTokens().forEach((right) => {
|
||||
const rulesBucketIndex = this.GetRuleBucketIndex(left, right);
|
||||
|
||||
let rulesBucket = this.map[rulesBucketIndex];
|
||||
@@ -44,7 +44,7 @@ namespace ts.formatting {
|
||||
const bucket = this.map[bucketIndex];
|
||||
if (bucket) {
|
||||
for (const rule of bucket.Rules()) {
|
||||
if (rule.Operation.Context.InContext(context)) {
|
||||
if (rule.operation.context.InContext(context)) {
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
@@ -53,16 +53,16 @@ namespace ts.formatting {
|
||||
}
|
||||
}
|
||||
|
||||
const MaskBitSize = 5;
|
||||
const Mask = 0x1f;
|
||||
const maskBitSize = 5;
|
||||
const mask = 0x1f;
|
||||
|
||||
enum RulesPosition {
|
||||
IgnoreRulesSpecific = 0,
|
||||
IgnoreRulesAny = MaskBitSize * 1,
|
||||
ContextRulesSpecific = MaskBitSize * 2,
|
||||
ContextRulesAny = MaskBitSize * 3,
|
||||
NoContextRulesSpecific = MaskBitSize * 4,
|
||||
NoContextRulesAny = MaskBitSize * 5
|
||||
IgnoreRulesAny = maskBitSize * 1,
|
||||
ContextRulesSpecific = maskBitSize * 2,
|
||||
ContextRulesAny = maskBitSize * 3,
|
||||
NoContextRulesSpecific = maskBitSize * 4,
|
||||
NoContextRulesAny = maskBitSize * 5
|
||||
}
|
||||
|
||||
export class RulesBucketConstructionState {
|
||||
@@ -94,20 +94,20 @@ namespace ts.formatting {
|
||||
let indexBitmap = this.rulesInsertionIndexBitmap;
|
||||
|
||||
while (pos <= maskPosition) {
|
||||
index += (indexBitmap & Mask);
|
||||
indexBitmap >>= MaskBitSize;
|
||||
pos += MaskBitSize;
|
||||
index += (indexBitmap & mask);
|
||||
indexBitmap >>= maskBitSize;
|
||||
pos += maskBitSize;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public IncreaseInsertionIndex(maskPosition: RulesPosition): void {
|
||||
let value = (this.rulesInsertionIndexBitmap >> maskPosition) & Mask;
|
||||
let value = (this.rulesInsertionIndexBitmap >> maskPosition) & mask;
|
||||
value++;
|
||||
Debug.assert((value & Mask) === value, "Adding more rules into the sub-bucket than allowed. Maximum allowed is 32 rules.");
|
||||
Debug.assert((value & mask) === value, "Adding more rules into the sub-bucket than allowed. Maximum allowed is 32 rules.");
|
||||
|
||||
let temp = this.rulesInsertionIndexBitmap & ~(Mask << maskPosition);
|
||||
let temp = this.rulesInsertionIndexBitmap & ~(mask << maskPosition);
|
||||
temp |= value << maskPosition;
|
||||
|
||||
this.rulesInsertionIndexBitmap = temp;
|
||||
@@ -128,12 +128,12 @@ namespace ts.formatting {
|
||||
public AddRule(rule: Rule, specificTokens: boolean, constructionState: RulesBucketConstructionState[], rulesBucketIndex: number): void {
|
||||
let position: RulesPosition;
|
||||
|
||||
if (rule.Operation.Action === RuleAction.Ignore) {
|
||||
if (rule.operation.action === RuleAction.Ignore) {
|
||||
position = specificTokens ?
|
||||
RulesPosition.IgnoreRulesSpecific :
|
||||
RulesPosition.IgnoreRulesAny;
|
||||
}
|
||||
else if (!rule.Operation.Context.IsAny()) {
|
||||
else if (!rule.operation.context.IsAny()) {
|
||||
position = specificTokens ?
|
||||
RulesPosition.ContextRulesSpecific :
|
||||
RulesPosition.ContextRulesAny;
|
||||
|
||||
@@ -95,6 +95,7 @@ namespace ts.formatting {
|
||||
return new TokenAllExceptAccess(token);
|
||||
}
|
||||
|
||||
// tslint:disable variable-name (TODO)
|
||||
export const Any: TokenRange = new TokenAllAccess();
|
||||
export const AnyIncludingMultilineComments = TokenRange.FromTokens([...allTokens, SyntaxKind.MultiLineCommentTrivia]);
|
||||
export const Keywords = TokenRange.FromRange(SyntaxKind.FirstKeyword, SyntaxKind.LastKeyword);
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace ts.JsTyping {
|
||||
NameContainsNonURISafeCharacters
|
||||
}
|
||||
|
||||
const MaxPackageNameLength = 214;
|
||||
const maxPackageNameLength = 214;
|
||||
|
||||
/**
|
||||
* Validates package name using rules defined at https://docs.npmjs.com/files/package.json
|
||||
@@ -266,7 +266,7 @@ namespace ts.JsTyping {
|
||||
if (!packageName) {
|
||||
return PackageNameValidationResult.EmptyName;
|
||||
}
|
||||
if (packageName.length > MaxPackageNameLength) {
|
||||
if (packageName.length > maxPackageNameLength) {
|
||||
return PackageNameValidationResult.NameTooLong;
|
||||
}
|
||||
if (packageName.charCodeAt(0) === CharacterCodes.dot) {
|
||||
@@ -292,7 +292,7 @@ namespace ts.JsTyping {
|
||||
case PackageNameValidationResult.EmptyName:
|
||||
return `Package name '${typing}' cannot be empty`;
|
||||
case PackageNameValidationResult.NameTooLong:
|
||||
return `Package name '${typing}' should be less than ${MaxPackageNameLength} characters`;
|
||||
return `Package name '${typing}' should be less than ${maxPackageNameLength} characters`;
|
||||
case PackageNameValidationResult.NameStartsWithDot:
|
||||
return `Package name '${typing}' cannot start with '.'`;
|
||||
case PackageNameValidationResult.NameStartsWithUnderscore:
|
||||
|
||||
@@ -515,10 +515,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Assumes 'value' is already lowercase.
|
||||
function indexOfIgnoringCase(string: string, value: string): number {
|
||||
const n = string.length - value.length;
|
||||
function indexOfIgnoringCase(str: string, value: string): number {
|
||||
const n = str.length - value.length;
|
||||
for (let i = 0; i <= n; i++) {
|
||||
if (startsWithIgnoringCase(string, value, i)) {
|
||||
if (startsWithIgnoringCase(str, value, i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -527,9 +527,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Assumes 'value' is already lowercase.
|
||||
function startsWithIgnoringCase(string: string, value: string, start: number): boolean {
|
||||
function startsWithIgnoringCase(str: string, value: string, start: number): boolean {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const ch1 = toLowerCase(string.charCodeAt(i + start));
|
||||
const ch1 = toLowerCase(str.charCodeAt(i + start));
|
||||
const ch2 = value.charCodeAt(i);
|
||||
|
||||
if (ch1 !== ch2) {
|
||||
|
||||
@@ -122,28 +122,28 @@ namespace ts.refactor.extractSymbol {
|
||||
return { message, code: 0, category: DiagnosticCategory.Message, key: message };
|
||||
}
|
||||
|
||||
export const CannotExtractRange: DiagnosticMessage = createMessage("Cannot extract range.");
|
||||
export const CannotExtractImport: DiagnosticMessage = createMessage("Cannot extract import statement.");
|
||||
export const CannotExtractSuper: DiagnosticMessage = createMessage("Cannot extract super call.");
|
||||
export const CannotExtractEmpty: DiagnosticMessage = createMessage("Cannot extract empty range.");
|
||||
export const ExpressionExpected: DiagnosticMessage = createMessage("expression expected.");
|
||||
export const UselessConstantType: DiagnosticMessage = createMessage("No reason to extract constant of type.");
|
||||
export const StatementOrExpressionExpected: DiagnosticMessage = createMessage("Statement or expression expected.");
|
||||
export const CannotExtractRangeContainingConditionalBreakOrContinueStatements: DiagnosticMessage = createMessage("Cannot extract range containing conditional break or continue statements.");
|
||||
export const CannotExtractRangeContainingConditionalReturnStatement: DiagnosticMessage = createMessage("Cannot extract range containing conditional return statement.");
|
||||
export const CannotExtractRangeContainingLabeledBreakOrContinueStatementWithTargetOutsideOfTheRange: DiagnosticMessage = createMessage("Cannot extract range containing labeled break or continue with target outside of the range.");
|
||||
export const CannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators: DiagnosticMessage = createMessage("Cannot extract range containing writes to references located outside of the target range in generators.");
|
||||
export const TypeWillNotBeVisibleInTheNewScope = createMessage("Type will not visible in the new scope.");
|
||||
export const FunctionWillNotBeVisibleInTheNewScope = createMessage("Function will not visible in the new scope.");
|
||||
export const CannotExtractIdentifier = createMessage("Select more than a single identifier.");
|
||||
export const CannotExtractExportedEntity = createMessage("Cannot extract exported declaration");
|
||||
export const CannotWriteInExpression = createMessage("Cannot write back side-effects when extracting an expression");
|
||||
export const CannotExtractReadonlyPropertyInitializerOutsideConstructor = createMessage("Cannot move initialization of read-only class property outside of the constructor");
|
||||
export const CannotExtractAmbientBlock = createMessage("Cannot extract code from ambient contexts");
|
||||
export const CannotAccessVariablesFromNestedScopes = createMessage("Cannot access variables from nested scopes");
|
||||
export const CannotExtractToOtherFunctionLike = createMessage("Cannot extract method to a function-like scope that is not a function");
|
||||
export const CannotExtractToJSClass = createMessage("Cannot extract constant to a class scope in JS");
|
||||
export const CannotExtractToExpressionArrowFunction = createMessage("Cannot extract constant to an arrow function without a block");
|
||||
export const cannotExtractRange: DiagnosticMessage = createMessage("Cannot extract range.");
|
||||
export const cannotExtractImport: DiagnosticMessage = createMessage("Cannot extract import statement.");
|
||||
export const cannotExtractSuper: DiagnosticMessage = createMessage("Cannot extract super call.");
|
||||
export const cannotExtractEmpty: DiagnosticMessage = createMessage("Cannot extract empty range.");
|
||||
export const expressionExpected: DiagnosticMessage = createMessage("expression expected.");
|
||||
export const uselessConstantType: DiagnosticMessage = createMessage("No reason to extract constant of type.");
|
||||
export const statementOrExpressionExpected: DiagnosticMessage = createMessage("Statement or expression expected.");
|
||||
export const cannotExtractRangeContainingConditionalBreakOrContinueStatements: DiagnosticMessage = createMessage("Cannot extract range containing conditional break or continue statements.");
|
||||
export const cannotExtractRangeContainingConditionalReturnStatement: DiagnosticMessage = createMessage("Cannot extract range containing conditional return statement.");
|
||||
export const cannotExtractRangeContainingLabeledBreakOrContinueStatementWithTargetOutsideOfTheRange: DiagnosticMessage = createMessage("Cannot extract range containing labeled break or continue with target outside of the range.");
|
||||
export const cannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators: DiagnosticMessage = createMessage("Cannot extract range containing writes to references located outside of the target range in generators.");
|
||||
export const typeWillNotBeVisibleInTheNewScope = createMessage("Type will not visible in the new scope.");
|
||||
export const functionWillNotBeVisibleInTheNewScope = createMessage("Function will not visible in the new scope.");
|
||||
export const cannotExtractIdentifier = createMessage("Select more than a single identifier.");
|
||||
export const cannotExtractExportedEntity = createMessage("Cannot extract exported declaration");
|
||||
export const cannotWriteInExpression = createMessage("Cannot write back side-effects when extracting an expression");
|
||||
export const cannotExtractReadonlyPropertyInitializerOutsideConstructor = createMessage("Cannot move initialization of read-only class property outside of the constructor");
|
||||
export const cannotExtractAmbientBlock = createMessage("Cannot extract code from ambient contexts");
|
||||
export const cannotAccessVariablesFromNestedScopes = createMessage("Cannot access variables from nested scopes");
|
||||
export const cannotExtractToOtherFunctionLike = createMessage("Cannot extract method to a function-like scope that is not a function");
|
||||
export const cannotExtractToJSClass = createMessage("Cannot extract constant to a class scope in JS");
|
||||
export const cannotExtractToExpressionArrowFunction = createMessage("Cannot extract constant to an arrow function without a block");
|
||||
}
|
||||
|
||||
enum RangeFacts {
|
||||
@@ -198,7 +198,7 @@ namespace ts.refactor.extractSymbol {
|
||||
const { length } = span;
|
||||
|
||||
if (length === 0) {
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.CannotExtractEmpty)] };
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractEmpty)] };
|
||||
}
|
||||
|
||||
// Walk up starting from the the start position until we find a non-SourceFile node that subsumes the selected span.
|
||||
@@ -215,18 +215,18 @@ namespace ts.refactor.extractSymbol {
|
||||
|
||||
if (!start || !end) {
|
||||
// cannot find either start or end node
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.CannotExtractRange)] };
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
|
||||
}
|
||||
|
||||
if (start.parent !== end.parent) {
|
||||
// start and end nodes belong to different subtrees
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.CannotExtractRange)] };
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
|
||||
}
|
||||
|
||||
if (start !== end) {
|
||||
// start and end should be statements and parent should be either block or a source file
|
||||
if (!isBlockLike(start.parent)) {
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.CannotExtractRange)] };
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
|
||||
}
|
||||
const statements: Statement[] = [];
|
||||
for (const statement of (<BlockLike>start.parent).statements) {
|
||||
@@ -246,7 +246,7 @@ namespace ts.refactor.extractSymbol {
|
||||
|
||||
if (isReturnStatement(start) && !start.expression) {
|
||||
// Makes no sense to extract an expression-less return statement.
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.CannotExtractRange)] };
|
||||
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractRange)] };
|
||||
}
|
||||
|
||||
// We have a single node (start)
|
||||
@@ -293,7 +293,7 @@ namespace ts.refactor.extractSymbol {
|
||||
|
||||
function checkRootNode(node: Node): Diagnostic[] | undefined {
|
||||
if (isIdentifier(isExpressionStatement(node) ? node.expression : node)) {
|
||||
return [createDiagnosticForNode(node, Messages.CannotExtractIdentifier)];
|
||||
return [createDiagnosticForNode(node, Messages.cannotExtractIdentifier)];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -332,11 +332,11 @@ namespace ts.refactor.extractSymbol {
|
||||
Return = 1 << 2
|
||||
}
|
||||
if (!isStatement(nodeToCheck) && !(isExpressionNode(nodeToCheck) && isExtractableExpression(nodeToCheck))) {
|
||||
return [createDiagnosticForNode(nodeToCheck, Messages.StatementOrExpressionExpected)];
|
||||
return [createDiagnosticForNode(nodeToCheck, Messages.statementOrExpressionExpected)];
|
||||
}
|
||||
|
||||
if (nodeToCheck.flags & NodeFlags.Ambient) {
|
||||
return [createDiagnosticForNode(nodeToCheck, Messages.CannotExtractAmbientBlock)];
|
||||
return [createDiagnosticForNode(nodeToCheck, Messages.cannotExtractAmbientBlock)];
|
||||
}
|
||||
|
||||
// If we're in a class, see whether we're in a static region (static property initializer, static method, class constructor parameter default)
|
||||
@@ -362,7 +362,7 @@ namespace ts.refactor.extractSymbol {
|
||||
if (isDeclaration(node)) {
|
||||
const declaringNode = (node.kind === SyntaxKind.VariableDeclaration) ? node.parent.parent : node;
|
||||
if (hasModifier(declaringNode, ModifierFlags.Export)) {
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.CannotExtractExportedEntity));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.cannotExtractExportedEntity));
|
||||
return true;
|
||||
}
|
||||
declarations.push(node.symbol);
|
||||
@@ -371,7 +371,7 @@ namespace ts.refactor.extractSymbol {
|
||||
// Some things can't be extracted in certain situations
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.CannotExtractImport));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.cannotExtractImport));
|
||||
return true;
|
||||
case SyntaxKind.SuperKeyword:
|
||||
// For a super *constructor call*, we have to be extracting the entire class,
|
||||
@@ -380,7 +380,7 @@ namespace ts.refactor.extractSymbol {
|
||||
// Super constructor call
|
||||
const containingClass = getContainingClass(node);
|
||||
if (containingClass.pos < span.start || containingClass.end >= (span.start + span.length)) {
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.CannotExtractSuper));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.cannotExtractSuper));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ namespace ts.refactor.extractSymbol {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
if (node.parent.kind === SyntaxKind.SourceFile && (node.parent as ts.SourceFile).externalModuleIndicator === undefined) {
|
||||
// You cannot extract global declarations
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.FunctionWillNotBeVisibleInTheNewScope));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.functionWillNotBeVisibleInTheNewScope));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -452,13 +452,13 @@ namespace ts.refactor.extractSymbol {
|
||||
if (label) {
|
||||
if (!contains(seenLabels, label.escapedText)) {
|
||||
// attempts to jump to label that is not in range to be extracted
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.CannotExtractRangeContainingLabeledBreakOrContinueStatementWithTargetOutsideOfTheRange));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.cannotExtractRangeContainingLabeledBreakOrContinueStatementWithTargetOutsideOfTheRange));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!(permittedJumps & (node.kind === SyntaxKind.BreakStatement ? PermittedJumps.Break : PermittedJumps.Continue))) {
|
||||
// attempt to break or continue in a forbidden context
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.CannotExtractRangeContainingConditionalBreakOrContinueStatements));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.cannotExtractRangeContainingConditionalBreakOrContinueStatements));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -474,7 +474,7 @@ namespace ts.refactor.extractSymbol {
|
||||
rangeFacts |= RangeFacts.HasReturn;
|
||||
}
|
||||
else {
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.CannotExtractRangeContainingConditionalReturnStatement));
|
||||
(errors || (errors = [])).push(createDiagnosticForNode(node, Messages.cannotExtractRangeContainingConditionalReturnStatement));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -1455,10 +1455,10 @@ namespace ts.refactor.extractSymbol {
|
||||
const statements = targetRange.range as ReadonlyArray<Statement>;
|
||||
const start = first(statements).getStart();
|
||||
const end = last(statements).end;
|
||||
expressionDiagnostic = createFileDiagnostic(sourceFile, start, end - start, Messages.ExpressionExpected);
|
||||
expressionDiagnostic = createFileDiagnostic(sourceFile, start, end - start, Messages.expressionExpected);
|
||||
}
|
||||
else if (checker.getTypeAtLocation(expression).flags & (TypeFlags.Void | TypeFlags.Never)) {
|
||||
expressionDiagnostic = createDiagnosticForNode(expression, Messages.UselessConstantType);
|
||||
expressionDiagnostic = createDiagnosticForNode(expression, Messages.uselessConstantType);
|
||||
}
|
||||
|
||||
// initialize results
|
||||
@@ -1468,7 +1468,7 @@ namespace ts.refactor.extractSymbol {
|
||||
|
||||
functionErrorsPerScope.push(
|
||||
isFunctionLikeDeclaration(scope) && scope.kind !== SyntaxKind.FunctionDeclaration
|
||||
? [createDiagnosticForNode(scope, Messages.CannotExtractToOtherFunctionLike)]
|
||||
? [createDiagnosticForNode(scope, Messages.cannotExtractToOtherFunctionLike)]
|
||||
: []);
|
||||
|
||||
const constantErrors = [];
|
||||
@@ -1476,11 +1476,11 @@ namespace ts.refactor.extractSymbol {
|
||||
constantErrors.push(expressionDiagnostic);
|
||||
}
|
||||
if (isClassLike(scope) && isInJavaScriptFile(scope)) {
|
||||
constantErrors.push(createDiagnosticForNode(scope, Messages.CannotExtractToJSClass));
|
||||
constantErrors.push(createDiagnosticForNode(scope, Messages.cannotExtractToJSClass));
|
||||
}
|
||||
if (isArrowFunction(scope) && !isBlock(scope.body)) {
|
||||
// TODO (https://github.com/Microsoft/TypeScript/issues/18924): allow this
|
||||
constantErrors.push(createDiagnosticForNode(scope, Messages.CannotExtractToExpressionArrowFunction));
|
||||
constantErrors.push(createDiagnosticForNode(scope, Messages.cannotExtractToExpressionArrowFunction));
|
||||
}
|
||||
constantErrorsPerScope.push(constantErrors);
|
||||
}
|
||||
@@ -1548,7 +1548,7 @@ namespace ts.refactor.extractSymbol {
|
||||
// local will actually be declared at the same level as the extracted expression).
|
||||
if (i > 0 && (scopeUsages.usages.size > 0 || scopeUsages.typeParameterUsages.size > 0)) {
|
||||
const errorNode = isReadonlyArray(targetRange.range) ? targetRange.range[0] : targetRange.range;
|
||||
constantErrorsPerScope[i].push(createDiagnosticForNode(errorNode, Messages.CannotAccessVariablesFromNestedScopes));
|
||||
constantErrorsPerScope[i].push(createDiagnosticForNode(errorNode, Messages.cannotAccessVariablesFromNestedScopes));
|
||||
}
|
||||
|
||||
let hasWrite = false;
|
||||
@@ -1568,17 +1568,17 @@ namespace ts.refactor.extractSymbol {
|
||||
Debug.assert(isReadonlyArray(targetRange.range) || exposedVariableDeclarations.length === 0);
|
||||
|
||||
if (hasWrite && !isReadonlyArray(targetRange.range)) {
|
||||
const diag = createDiagnosticForNode(targetRange.range, Messages.CannotWriteInExpression);
|
||||
const diag = createDiagnosticForNode(targetRange.range, Messages.cannotWriteInExpression);
|
||||
functionErrorsPerScope[i].push(diag);
|
||||
constantErrorsPerScope[i].push(diag);
|
||||
}
|
||||
else if (readonlyClassPropertyWrite && i > 0) {
|
||||
const diag = createDiagnosticForNode(readonlyClassPropertyWrite, Messages.CannotExtractReadonlyPropertyInitializerOutsideConstructor);
|
||||
const diag = createDiagnosticForNode(readonlyClassPropertyWrite, Messages.cannotExtractReadonlyPropertyInitializerOutsideConstructor);
|
||||
functionErrorsPerScope[i].push(diag);
|
||||
constantErrorsPerScope[i].push(diag);
|
||||
}
|
||||
else if (firstExposedNonVariableDeclaration) {
|
||||
const diag = createDiagnosticForNode(firstExposedNonVariableDeclaration, Messages.CannotExtractExportedEntity);
|
||||
const diag = createDiagnosticForNode(firstExposedNonVariableDeclaration, Messages.cannotExtractExportedEntity);
|
||||
functionErrorsPerScope[i].push(diag);
|
||||
constantErrorsPerScope[i].push(diag);
|
||||
}
|
||||
@@ -1710,7 +1710,7 @@ namespace ts.refactor.extractSymbol {
|
||||
if (targetRange.facts & RangeFacts.IsGenerator && usage === Usage.Write) {
|
||||
// this is write to a reference located outside of the target scope and range is extracted into generator
|
||||
// currently this is unsupported scenario
|
||||
const diag = createDiagnosticForNode(identifier, Messages.CannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators);
|
||||
const diag = createDiagnosticForNode(identifier, Messages.cannotExtractRangeThatContainsWritesToReferencesLocatedOutsideOfTheTargetRangeInGenerators);
|
||||
for (const errors of functionErrorsPerScope) {
|
||||
errors.push(diag);
|
||||
}
|
||||
@@ -1733,7 +1733,7 @@ namespace ts.refactor.extractSymbol {
|
||||
// If the symbol is a type parameter that won't be in scope, we'll pass it as a type argument
|
||||
// so there's no problem.
|
||||
if (!(symbol.flags & SymbolFlags.TypeParameter)) {
|
||||
const diag = createDiagnosticForNode(identifier, Messages.TypeWillNotBeVisibleInTheNewScope);
|
||||
const diag = createDiagnosticForNode(identifier, Messages.typeWillNotBeVisibleInTheNewScope);
|
||||
functionErrorsPerScope[i].push(diag);
|
||||
constantErrorsPerScope[i].push(diag);
|
||||
}
|
||||
|
||||
@@ -1997,9 +1997,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isNodeModulesFile(path: string): boolean {
|
||||
const node_modulesFolderName = "/node_modules/";
|
||||
|
||||
return stringContains(path, node_modulesFolderName);
|
||||
return stringContains(path, "/node_modules/");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user